mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[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:
parent
fbec5c4e5e
commit
aaf35eb2da
@ -280,7 +280,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
eprintln( L"unexpected error" );
|
eprintln( L"unexpected error" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_EndInterpreter( localInterpreter );
|
Py_EndInterpreter( localInterpreter );
|
||||||
@ -308,17 +308,17 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
python::exec(
|
python::exec(
|
||||||
"try:\n"
|
"__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n",
|
||||||
" __import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n"
|
|
||||||
"except SystemExit:\n"
|
|
||||||
" print 'Ctrl+Break'\n",
|
|
||||||
WindbgGlobalSession::global(),
|
WindbgGlobalSession::global(),
|
||||||
WindbgGlobalSession::global()
|
WindbgGlobalSession::global()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
eprintln( L"unexpected error" );
|
if ( !PyErr_ExceptionMatches( PyExc_SystemExit ) )
|
||||||
|
{
|
||||||
|
eprintln( L"unexpected error" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
|
// âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
|
||||||
|
@ -206,7 +206,7 @@ SymbolPtrList DiaSymbol::findChildren(
|
|||||||
hres = m_symbol->findChildren(
|
hres = m_symbol->findChildren(
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
static_cast<enum ::SymTagEnum>(symTag),
|
||||||
NULL,
|
NULL,
|
||||||
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName,
|
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression,
|
||||||
&symbols);
|
&symbols);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ SymbolPtrList DiaSymbol::findChildren(
|
|||||||
hres = m_symbol->findChildren(
|
hres = m_symbol->findChildren(
|
||||||
static_cast<enum ::SymTagEnum>(symTag),
|
static_cast<enum ::SymTagEnum>(symTag),
|
||||||
toWStr(name),
|
toWStr(name),
|
||||||
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName,
|
(caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression,
|
||||||
&symbols);
|
&symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +652,14 @@ bool DiaSymbol::isBasicType()
|
|||||||
|
|
||||||
bool DiaSymbol::isConstant()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -196,7 +196,7 @@ TypedVarPtr Module::containingRecordByName( ULONG64 offset, const std::string &t
|
|||||||
return containingRecordByType( offset, typeInfo, fieldName );
|
return containingRecordByType( offset, typeInfo, fieldName );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
python::list Module::getTypedVarArrayByTypeName( ULONG64 offset, const std::string &typeName, ULONG number )
|
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
|
}; // end of namespace pykd
|
||||||
|
@ -103,6 +103,8 @@ public:
|
|||||||
|
|
||||||
std::string getSourceFile( ULONG64 offset );
|
std::string getSourceFile( ULONG64 offset );
|
||||||
|
|
||||||
|
python::list enumSymbols( const std::string &mask = "*" );
|
||||||
|
|
||||||
std::string print();
|
std::string print();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define PYKD_VERSION_MAJOR 0
|
#define PYKD_VERSION_MAJOR 0
|
||||||
#define PYKD_VERSION_MINOR 2
|
#define PYKD_VERSION_MINOR 2
|
||||||
#define PYKD_VERSION_SUBVERSION 0
|
#define PYKD_VERSION_SUBVERSION 0
|
||||||
#define PYKD_VERSION_BUILDNO 2
|
#define PYKD_VERSION_BUILDNO 3
|
||||||
|
|
||||||
|
|
||||||
#define __VER_STR2__(x) #x
|
#define __VER_STR2__(x) #x
|
||||||
|
@ -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_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 );
|
||||||
|
|
||||||
|
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_enumSymbols, Module::enumSymbols, 0, 1 );
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE( pykd )
|
BOOST_PYTHON_MODULE( pykd )
|
||||||
{
|
{
|
||||||
python::scope().attr("version") = pykdVersion;
|
python::scope().attr("version") = pykdVersion;
|
||||||
@ -359,6 +361,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def("containingRecord", &Module::containingRecordByName,
|
.def("containingRecord", &Module::containingRecordByName,
|
||||||
"Return instance of the typedVar class. It's value are loaded from the target memory."
|
"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" )
|
"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,
|
.def("checksum",&Module::getCheckSum,
|
||||||
"Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" )
|
"Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" )
|
||||||
.def("timestamp",&Module::getTimeDataStamp,
|
.def("timestamp",&Module::getTimeDataStamp,
|
||||||
|
@ -52,6 +52,7 @@ class ModuleTest( unittest.TestCase ):
|
|||||||
def testFindSymbol( self ):
|
def testFindSymbol( self ):
|
||||||
self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) )
|
self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) )
|
||||||
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) )
|
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) )
|
||||||
|
# self.assertEqual( "", typed)
|
||||||
|
|
||||||
|
|
||||||
def testType( self ):
|
def testType( self ):
|
||||||
@ -67,5 +68,13 @@ class ModuleTest( unittest.TestCase ):
|
|||||||
self.assertEqual( 2, displacement )
|
self.assertEqual( 2, displacement )
|
||||||
fileName, lineNo, displacement = pykd.getSourceLine()
|
fileName, lineNo, displacement = pykd.getSourceLine()
|
||||||
self.assertEqual( 624, lineNo )
|
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*") ) )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user