[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,
"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,
// "create a new instance of the dbgClient class" );
python::def( "loadDump", &pykd::loadDump,
@ -90,7 +89,9 @@ BOOST_PYTHON_MODULE( pykd )
python::class_<pykd::TypeInfo>("typeInfo", "Class representing typeInfo", python::no_init )
.def( "name", &pykd::TypeInfo::getName )
.def( "size", &pykd::TypeInfo::getSize )
.def( "offset", &pykd::TypeInfo::getOffset )
.def( "field", &pykd::TypeInfo::getField )
.def( "__getattr__", &pykd::TypeInfo::getField );
python::class_<pykd::Module>("module", "Class representing executable module", python::no_init )
@ -328,7 +329,9 @@ WindbgGlobalSession::WindbgGlobalSession() {
std::string key = boost::python::extract<std::string>(iterkeys[i]);
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 oldClient = DebugClient::setDbgClientCurrent( dbgClient );
WindbgGlobalSession::RestorePyState();
PyThreadState *globalInterpreter = PyThreadState_Swap( NULL );
PyThreadState *localInterpreter = Py_NewInterpreter();
@ -385,6 +390,8 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
Py_EndInterpreter( localInterpreter );
PyThreadState_Swap( globalInterpreter );
WindbgGlobalSession::SavePyState();
DebugClient::setDbgClientCurrent( oldClient );
return S_OK;
@ -399,6 +406,8 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
DebugClientPtr dbgClient = DebugClient::createDbgClient( client );
DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient );
WindbgGlobalSession::RestorePyState();
try {
@ -408,9 +417,9 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
dbgClient->eprintln( "unexpected error" );
}
DebugClient::setDbgClientCurrent( oldClient );
WindbgGlobalSession::SavePyState();
return S_OK;
DebugClient::setDbgClientCurrent( oldClient );
return S_OK;
}

View File

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

View File

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

View File

@ -35,12 +35,17 @@ public:
getOffset() {
return m_offset;
}
ULONG64
getSize() {
return m_dia->getSize();
}
private:
pyDia::SymbolPtr m_dia;
ULONG m_offset;
ULONG m_offset;
};
///////////////////////////////////////////////////////////////////////////////////

View File

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

View File

@ -49,3 +49,7 @@ class ModuleTest( unittest.TestCase ):
def testSymbol( self ):
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() )
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 ):
""" get field of the complex type """
ti1 = target.module.type( "structTest" )
self.assertNotEqual( None, ti1.m_field0 ) # exsisting field
try: ti1.m_field4 # non-exsisting field
self.assertTrue( hasattr( ti1, "m_field0" ) )
try: hasattr(ti1, "m_field4" ) # non-exsisting field
except pykd.DiaException: pass
def testName( self ):
@ -36,5 +36,9 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( 0, ti1.m_field0.offset() )
self.assertEqual( 4, ti1.m_field1.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;
};
structTest g_structTest = { 0, 500, true, 1 };
class classChild : public classBase {
public:
int m_childField;
@ -75,6 +77,8 @@ void FuncWithName0()
std::cout << g_ushortValue;
std::cout << g_ulongValue;
std::cout << g_ulonglongValue;
std::cout << g_structTest.m_field0;
}
void FuncWithName1(int a)