[+, 0.1.x] get symbol by address from module

git-svn-id: https://pykd.svn.codeplex.com/svn@71164 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-11-08 10:53:07 +00:00 committed by Mikhail I. Izmestev
parent 2d239171a3
commit 82a744d1be
6 changed files with 54 additions and 56 deletions

View File

@ -334,8 +334,8 @@ BOOST_PYTHON_MODULE( pykd )
"Return rva of the symbol" ) "Return rva of the symbol" )
.def("type", &pykd::Module::getTypeByName, .def("type", &pykd::Module::getTypeByName,
"Return typeInfo class by type name" ) "Return typeInfo class by type name" )
//.def("typedVar", &pykd::Module::getTypedVarByAddr, .def("typedVar", &pykd::Module::getTypedVarByAddr,
// "Return a typedVar class instance" ) "Return a typedVar class instance" )
.def("typedVar",&pykd::Module::getTypedVarByName, .def("typedVar",&pykd::Module::getTypedVarByName,
"Return a typedVar class instance" ) "Return a typedVar class instance" )
.def("typedVar",&pykd::Module::getTypedVarByType, .def("typedVar",&pykd::Module::getTypedVarByType,

View File

@ -147,6 +147,7 @@ Module::reloadSymbols()
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException("IDebugSymbols::Reload failed" ); throw DbgException("IDebugSymbols::Reload failed" );
m_dia.reset();
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() ); m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
} }
@ -155,7 +156,7 @@ Module::reloadSymbols()
TypeInfo TypeInfo
Module::getTypeByName( const std::string &typeName ) Module::getTypeByName( const std::string &typeName )
{ {
return TypeInfo( m_dia, typeName ); return TypeInfo( getDia(), typeName );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -163,7 +164,7 @@ Module::getTypeByName( const std::string &typeName )
TypedVar TypedVar
Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr )
{ {
return TypedVar( TypeInfo( m_dia, typeName ), addr ); return TypedVar( TypeInfo( getDia(), typeName ), addr );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -179,37 +180,29 @@ Module::getTypedVarByType( const TypeInfo &typeInfo, ULONG64 addr )
TypedVar TypedVar
Module::getTypedVarByName( const std::string &symName ) Module::getTypedVarByName( const std::string &symName )
{ {
pyDia::SymbolPtr typeSym = m_dia->getChildByName( symName ); pyDia::SymbolPtr typeSym = getDia()->getChildByName( symName );
return TypedVar( TypeInfo( typeSym->getType() ), typeSym->getRva() + m_base ); return TypedVar( TypeInfo( typeSym->getType() ), typeSym->getRva() + m_base );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
//TypedVar TypedVar
//Module::getTypedVarByAddr( ULONG64 addr ) Module::getTypedVarByAddr( ULONG64 addr )
//{ {
// addr = addr64(addr); addr = addr64(addr);
//
// if ( addr < m_base || addr > getEnd() ) if ( addr < m_base || addr > getEnd() )
// throw DbgException("address is out of the module space" ); throw DbgException( "address is out of the module space" );
//
// ULONG rva = (ULONG)(addr - m_base); LONG displacement;
// pyDia::SymbolPtr diaSym =
// for( ULONG i = 0; i < m_dia->getChildCount(); i++ ) getDia()->findByRvaImpl((ULONG)(addr - m_base), SymTagData, displacement);
// { if (displacement)
// pyDia::SymbolPtr typeSym = m_dia->getChildByIndex(i); throw DbgException( "not exactly match by RVA" );
//
// std::string name = m_dia->getName(); return TypedVar( TypeInfo( diaSym->getType() ), addr );
// }
// if ( typeSym->getSymTag() == SymTagData && typeSym->getRva() == rva )
// {
// return TypedVar( TypeInfo( typeSym->getType() ), typeSym->getRva() + m_base );
// }
// }
//
// throw DbgException("failed to find type info for this offset" );
//}
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -47,22 +47,14 @@ public:
ULONG64 ULONG64
getSymbol( const std::string &symbolname ) { getSymbol( const std::string &symbolname ) {
pyDia::SymbolPtr sym = getDia()->getChildByName( symbolname );
if ( !m_dia )
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
pyDia::SymbolPtr sym = m_dia->getChildByName( symbolname );
return m_base + sym->getRva(); return m_base + sym->getRva();
} }
ULONG ULONG
getSymbolRva( const std::string &symbolname ) { getSymbolRva( const std::string &symbolname ) {
pyDia::SymbolPtr sym = getDia()->getChildByName( symbolname );
if ( !m_dia )
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
pyDia::SymbolPtr sym = m_dia->getChildByName( symbolname );
return sym->getRva(); return sym->getRva();
} }
@ -79,6 +71,13 @@ public:
private: private:
pyDia::GlobalScopePtr getDia() {
if (!m_dia)
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
return m_dia;
}
std::string m_name; std::string m_name;
std::string m_imageName; std::string m_imageName;
ULONG64 m_base; ULONG64 m_base;

View File

@ -22,6 +22,11 @@ class TypedVarTest( unittest.TestCase ):
#tv2 = target.module.typedVar( "structTest[2]", target.module.g_testArray ) #tv2 = target.module.typedVar( "structTest[2]", target.module.g_testArray )
#self.assertEqual( tv1.sizeof()*2, tv2.sizeof() ) #self.assertEqual( tv1.sizeof()*2, tv2.sizeof() )
def testByAddress( self ):
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
tv2 = target.module.typedVar( tv1.getAddress() )
self.assertEqual( tv2.getAddress(), tv1.getAddress() )
def testStruct(self): def testStruct(self):
tv1 = target.module.typedVar( "structTest", target.module.g_structTest ) tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
self.assertEqual( 0, tv1.m_field0 ) self.assertEqual( 0, tv1.m_field0 )

View File

@ -24,7 +24,6 @@ struct structWithBits {
ULONG m_bit5 : 1; ULONG m_bit5 : 1;
ULONG m_bit6_7 : 2; ULONG m_bit6_7 : 2;
}; };
structWithBits g_structWithBits = {0};
union unionTest { union unionTest {
ULONG m_value; ULONG m_value;
@ -47,6 +46,8 @@ struct structTest {
structTest* m_field4; structTest* m_field4;
}; };
structWithBits g_structWithBits = {0};
structTest g_structTest = { 0, 500, true, 1, NULL }; structTest g_structTest = { 0, 500, true, 1, NULL };
structTest g_structTest1 = { 0, 500, true, 1, &g_structTest }; structTest g_structTest1 = { 0, 500, true, 1, &g_structTest };