[0.2.x] added : module::enumSymbols method ( return list of symbols )

git-svn-id: https://pykd.svn.codeplex.com/svn@80732 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-10-31 07:27:51 +00:00 committed by Mikhail I. Izmestev
parent fbec5c4e5e
commit aaf35eb2da
7 changed files with 64 additions and 12 deletions

View File

@ -308,18 +308,18 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
try {
python::exec(
"try:\n"
" __import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n"
"except SystemExit:\n"
" print 'Ctrl+Break'\n",
"__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n",
WindbgGlobalSession::global(),
WindbgGlobalSession::global()
);
}
catch(...)
{
if ( !PyErr_ExceptionMatches( PyExc_SystemExit ) )
{
eprintln( L"unexpected error" );
}
}
// выход из интерпретатора происходит через исключение raise SystemExit(code)
// которое потом может помешать исполнению callback ов

View File

@ -206,7 +206,7 @@ SymbolPtrList DiaSymbol::findChildren(
hres = m_symbol->findChildren(
static_cast<enum ::SymTagEnum>(symTag),
NULL,
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName,
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression,
&symbols);
}
@ -215,7 +215,7 @@ SymbolPtrList DiaSymbol::findChildren(
hres = m_symbol->findChildren(
static_cast<enum ::SymTagEnum>(symTag),
toWStr(name),
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName,
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression,
&symbols);
}
@ -652,7 +652,14 @@ bool DiaSymbol::isBasicType()
bool DiaSymbol::isConstant()
{
return !!callSymbol(get_constType);
HRESULT hres;
BOOL retBool = FALSE;
hres = m_symbol->get_constType( &retBool );
if ( FAILED( hres ) )
throw DiaException("Call IDiaSymbol::get_constType", hres, m_symbol);
return !!retBool;
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -196,7 +196,7 @@ TypedVarPtr Module::containingRecordByName( ULONG64 offset, const std::string &t
return containingRecordByType( offset, typeInfo, fieldName );
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
python::list Module::getTypedVarArrayByTypeName( ULONG64 offset, const std::string &typeName, ULONG number )
{
@ -281,4 +281,34 @@ void Module::prepareSymbolFile()
///////////////////////////////////////////////////////////////////////////////////
python::list Module::enumSymbols( const std::string &mask)
{
python::list lst;
SymbolPtrList symlst = getSymScope()->findChildren( SymTagData, mask, true );
for ( SymbolPtrList::iterator it = symlst.begin(); it != symlst.end(); ++it )
{
if ( (*it)->getDataKind() == DataIsConstant )
{
lst.append( python::make_tuple( (*it)->getName(), python::object() ) );
}
else
{
lst.append( python::make_tuple( (*it)->getName(), (*it)->getVa() ) );
}
}
symlst = getSymScope()->findChildren( SymTagFunction, mask, true );
for ( SymbolPtrList::iterator it = symlst.begin(); it != symlst.end(); ++it )
{
lst.append( python::make_tuple( (*it)->getName(), (*it)->getVa() ) );
}
return lst;
}
///////////////////////////////////////////////////////////////////////////////////
}; // end of namespace pykd

View File

@ -103,6 +103,8 @@ public:
std::string getSourceFile( ULONG64 offset );
python::list enumSymbols( const std::string &mask = "*" );
std::string print();
private:

View File

@ -2,7 +2,7 @@
#define PYKD_VERSION_MAJOR 0
#define PYKD_VERSION_MINOR 2
#define PYKD_VERSION_SUBVERSION 0
#define PYKD_VERSION_BUILDNO 2
#define PYKD_VERSION_BUILDNO 3
#define __VER_STR2__(x) #x

View File

@ -64,6 +64,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 2
BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 );
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_enumSymbols, Module::enumSymbols, 0, 1 );
BOOST_PYTHON_MODULE( pykd )
{
python::scope().attr("version") = pykdVersion;
@ -359,6 +361,8 @@ BOOST_PYTHON_MODULE( pykd )
.def("containingRecord", &Module::containingRecordByName,
"Return instance of the typedVar class. It's value are loaded from the target memory."
"The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" )
.def("enumSymbols", &Module::enumSymbols, Module_enumSymbols( python::args("mask"),
"Return list of tuple ( symbolname, offset )" ) )
.def("checksum",&Module::getCheckSum,
"Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" )
.def("timestamp",&Module::getTimeDataStamp,

View File

@ -52,6 +52,7 @@ class ModuleTest( unittest.TestCase ):
def testFindSymbol( self ):
self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) )
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) )
# self.assertEqual( "", typed)
def testType( self ):
@ -68,4 +69,12 @@ class ModuleTest( unittest.TestCase ):
fileName, lineNo, displacement = pykd.getSourceLine()
self.assertEqual( 624, lineNo )
def testEnumSymbols( self ):
lst = target.module.enumSymbols("hello*Str")
self.assertEqual( 2, len(lst) )
lst = target.module.enumSymbols( "g_const*Value")
self.assertEqual( 2, len(lst) )
lst = target.module.enumSymbols( "*FuncWithName*")
self.assertEqual( 3, len(lst) )
self.assertNotEqual( 0, len(target.module.enumSymbols( "*virtFunc*") ) )