[0.1.x] added : typeInfo.size()

git-svn-id: https://pykd.svn.codeplex.com/svn@70223 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-10-06 06:26:25 +00:00 committed by Mikhail I. Izmestev
parent 0d7d746778
commit a8ff8e9f84
8 changed files with 58 additions and 10 deletions

View File

@ -68,7 +68,6 @@ BOOST_PYTHON_MODULE( pykd )
.def( "dprintln", &pykd::DebugClient::dprintln, .def( "dprintln", &pykd::DebugClient::dprintln,
"Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ); "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" );
// python::def( "createDbgClient", pykd::DebugClient::createDbgClient, // python::def( "createDbgClient", pykd::DebugClient::createDbgClient,
// "create a new instance of the dbgClient class" ); // "create a new instance of the dbgClient class" );
python::def( "loadDump", &pykd::loadDump, python::def( "loadDump", &pykd::loadDump,
@ -90,7 +89,9 @@ BOOST_PYTHON_MODULE( pykd )
python::class_<pykd::TypeInfo>("typeInfo", "Class representing typeInfo", python::no_init ) python::class_<pykd::TypeInfo>("typeInfo", "Class representing typeInfo", python::no_init )
.def( "name", &pykd::TypeInfo::getName ) .def( "name", &pykd::TypeInfo::getName )
.def( "size", &pykd::TypeInfo::getSize )
.def( "offset", &pykd::TypeInfo::getOffset ) .def( "offset", &pykd::TypeInfo::getOffset )
.def( "field", &pykd::TypeInfo::getField )
.def( "__getattr__", &pykd::TypeInfo::getField ); .def( "__getattr__", &pykd::TypeInfo::getField );
python::class_<pykd::Module>("module", "Class representing executable module", python::no_init ) python::class_<pykd::Module>("module", "Class representing executable module", python::no_init )
@ -329,6 +330,8 @@ WindbgGlobalSession::WindbgGlobalSession() {
main_namespace[ key ] = pykd_namespace[ key ]; main_namespace[ key ] = pykd_namespace[ key ];
} }
pyState = PyEval_SaveThread();
} }
@ -370,6 +373,8 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); DebugClientPtr dbgClient = DebugClient::createDbgClient( client );
DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient ); DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient );
WindbgGlobalSession::RestorePyState();
PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); PyThreadState *globalInterpreter = PyThreadState_Swap( NULL );
PyThreadState *localInterpreter = Py_NewInterpreter(); PyThreadState *localInterpreter = Py_NewInterpreter();
@ -385,6 +390,8 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
Py_EndInterpreter( localInterpreter ); Py_EndInterpreter( localInterpreter );
PyThreadState_Swap( globalInterpreter ); PyThreadState_Swap( globalInterpreter );
WindbgGlobalSession::SavePyState();
DebugClient::setDbgClientCurrent( oldClient ); DebugClient::setDbgClientCurrent( oldClient );
return S_OK; return S_OK;
@ -399,6 +406,8 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); DebugClientPtr dbgClient = DebugClient::createDbgClient( client );
DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient ); DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient );
WindbgGlobalSession::RestorePyState();
try { try {
@ -408,9 +417,9 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
dbgClient->eprintln( "unexpected error" ); dbgClient->eprintln( "unexpected error" );
} }
DebugClient::setDbgClientCurrent( oldClient ); WindbgGlobalSession::SavePyState();
return S_OK; DebugClient::setDbgClientCurrent( oldClient );
return S_OK; return S_OK;
} }

View File

@ -157,6 +157,9 @@ Module::getTypeByName( const std::string typeName )
{ {
pyDia::SymbolPtr typeSym = m_dia->getChildByName( typeName ); pyDia::SymbolPtr typeSym = m_dia->getChildByName( typeName );
if ( typeSym->getSymTag() == SymTagData )
return TypeInfo( typeSym->getType() );
else
return TypeInfo( typeSym ); return TypeInfo( typeSym );
} }

View File

@ -88,6 +88,11 @@ private:
//#include <string> //#include <string>
//#include <map> //#include <map>
// //

View File

@ -36,6 +36,11 @@ public:
return m_offset; return m_offset;
} }
ULONG64
getSize() {
return m_dia->getSize();
}
private: private:
pyDia::SymbolPtr m_dia; pyDia::SymbolPtr m_dia;

View File

@ -40,6 +40,18 @@ public:
return windbgGlobalSession != NULL; return windbgGlobalSession != NULL;
} }
static
VOID
RestorePyState() {
PyEval_RestoreThread( windbgGlobalSession->pyState );
}
static
VOID
SavePyState() {
windbgGlobalSession->pyState = PyEval_SaveThread();
}
private: private:
@ -50,6 +62,8 @@ private:
python::object main; python::object main;
PyThreadState *pyState;
static volatile LONG sessionCount; static volatile LONG sessionCount;
static WindbgGlobalSession *windbgGlobalSession; static WindbgGlobalSession *windbgGlobalSession;

View File

@ -49,3 +49,7 @@ class ModuleTest( unittest.TestCase ):
def testSymbol( self ): def testSymbol( self ):
self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() ) self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() )
self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() ) self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() )
def testType( self ):
self.assertEqual( "structTest", target.module.type("structTest").name() );
self.assertEqual( "structTest", target.module.type("g_structTest").name() );

View File

@ -21,8 +21,8 @@ class TypeInfoTest( unittest.TestCase ):
def testGetField( self ): def testGetField( self ):
""" get field of the complex type """ """ get field of the complex type """
ti1 = target.module.type( "structTest" ) ti1 = target.module.type( "structTest" )
self.assertNotEqual( None, ti1.m_field0 ) # exsisting field self.assertTrue( hasattr( ti1, "m_field0" ) )
try: ti1.m_field4 # non-exsisting field try: hasattr(ti1, "m_field4" ) # non-exsisting field
except pykd.DiaException: pass except pykd.DiaException: pass
def testName( self ): def testName( self ):
@ -38,3 +38,7 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( 12, ti1.m_field2.offset() ) self.assertEqual( 12, ti1.m_field2.offset() )
self.assertEqual( 14, ti1.m_field3.offset() ) self.assertEqual( 14, ti1.m_field3.offset() )
def testSize( self ):
ti1 = target.module.type( "structTest" )
self.assertEqual( 16, ti1.size() )

View File

@ -46,6 +46,8 @@ struct structTest {
USHORT m_field3; USHORT m_field3;
}; };
structTest g_structTest = { 0, 500, true, 1 };
class classChild : public classBase { class classChild : public classBase {
public: public:
int m_childField; int m_childField;
@ -75,6 +77,8 @@ void FuncWithName0()
std::cout << g_ushortValue; std::cout << g_ushortValue;
std::cout << g_ulongValue; std::cout << g_ulongValue;
std::cout << g_ulonglongValue; std::cout << g_ulonglongValue;
std::cout << g_structTest.m_field0;
} }
void FuncWithName1(int a) void FuncWithName1(int a)