[0.1.x] added : sizeof() routine ( return size of type or variable )

git-svn-id: https://pykd.svn.codeplex.com/svn@77433 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-06-20 10:13:47 +00:00 committed by Mikhail I. Izmestev
parent 6a71eb41e1
commit f225f3905e
8 changed files with 64 additions and 5 deletions

View File

@ -497,6 +497,25 @@ void DebugClient::splitSymName( const std::string &fullName, std::string &module
///////////////////////////////////////////////////////////////////////////////////
ULONG64 DebugClient::getSymbolSize( const std::string &fullName )
{
std::string moduleName;
std::string symName;
splitSymName( fullName, moduleName, symName );
ModulePtr module = loadModuleByName( moduleName );
return module->getSymbolSize(symName);
}
ULONG64 getSymbolSize( const std::string &symName )
{
return g_dbgClient->getSymbolSize(symName);
}
///////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr DebugClient::getTypeInfoByName( const std::string &typeName )
{
std::string moduleName;

View File

@ -352,6 +352,8 @@ public:
python::list getTypedVarArrayByType( ULONG64 addr, const TypeInfoPtr &typeInfo, ULONG number );
ULONG64 getSymbolSize( const std::string &symName );
private:
HRESULT safeWaitForEvent(ULONG timeout = INFINITE, ULONG flags = DEBUG_WAIT_DEFAULT);
@ -422,6 +424,8 @@ python::list getTypedVarArrayByTypeName( ULONG64 addr, const std::string &typeN
python::list getTypedVarArrayByType( ULONG64 addr, const TypeInfoPtr &typeInfo, ULONG number );
ULONG64 getSymbolSize( const std::string &symName );
/////////////////////////////////////////////////////////////////////////////////
// Synthetic symbols global finctions:

View File

@ -203,6 +203,25 @@ Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr )
///////////////////////////////////////////////////////////////////////////////////
ULONG64
Module::getSymbolSize( const std::string &symName )
{
try {
pyDia::SymbolPtr symVar = getDia()->getChildByName( symName );
if ( symVar->getSymTag() == SymTagData )
return symVar->getSize();
} catch( const SymbolException& )
{
}
return getTypeByName(symName)->getSize();
}
///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr
Module::getTypedVarByName( const std::string &symName )
{

View File

@ -93,6 +93,8 @@ public:
python::list getTypedVarArrayByType( ULONG64 addr, const TypeInfoPtr &typeInfo, ULONG number );
ULONG64 getSymbolSize( const std::string &symName );
pyDia::GlobalScopePtr& getDia() {
if (!m_dia)
{

View File

@ -290,6 +290,8 @@ BOOST_PYTHON_MODULE( pykd )
"Set implicit thread for current process" )
.def( "setProcessorMode", &DebugClient::setProcessorMode,
"Set current processor mode by string (X86, ARM, IA64 or X64)" )
.def( "sizeof", &DebugClient::getSymbolSize,
"Return a size of the type or variable" )
.def( "step", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>,
"Change debugger status to DEBUG_STATUS_STEP_OVER" )
.def( "symbolsPath", &DebugClient::dbgSymPath,
@ -489,6 +491,8 @@ BOOST_PYTHON_MODULE( pykd )
"Set implicit thread for current process" );
python::def( "setProcessorMode", &setProcessorMode,
"Set current processor mode by string (X86, ARM, IA64 or X64)" );
python::def( "sizeof", &getSymbolSize,
"Return a size of the type or variable" );
python::def( "step", &changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>,
"Change debugger status to DEBUG_STATUS_STEP_OVER" );
python::def( "symbolsPath", &dbgSymPath,
@ -594,6 +598,8 @@ BOOST_PYTHON_MODULE( pykd )
"Return offset of the symbol" )
.def("rva", &Module::getSymbolRva,
"Return rva of the symbol" )
.def( "sizeof", &Module::getSymbolSize,
"Return a size of the type or variable" )
.def("type", &Module::getTypeByName,
"Return typeInfo class by type name" )
.def("typedVar", &Module::getTypedVarByAddr,

View File

@ -75,6 +75,7 @@ class BaseTest( unittest.TestCase ):
self.assertTrue( hasattr(pykd, 'setCurrentProcess') )
self.assertTrue( hasattr(pykd, 'setImplicitThread') )
self.assertTrue( hasattr(pykd, 'setProcessorMode') )
self.assertTrue( hasattr(pykd, 'sizeof') )
self.assertTrue( hasattr(pykd, 'startProcess') )
self.assertTrue( hasattr(pykd, 'step') )
self.assertTrue( hasattr(pykd, 'symbolsPath') )
@ -104,8 +105,7 @@ class BaseTest( unittest.TestCase ):
self.assertFalse( hasattr(pykd, 'debugEvent') )
self.assertFalse( hasattr(pykd, 'findModule') )
self.assertFalse( hasattr(pykd, 'loadLinkedList') )
self.assertFalse( hasattr(pykd, 'reloadModule') )
self.assertFalse( hasattr(pykd, 'sizeof') )
self.assertFalse( hasattr(pykd, 'reloadModule') )
self.assertFalse( hasattr(pykd, 'windbgIn') )
self.assertFalse( hasattr(pykd, 'windbgOut') )
self.assertFalse( hasattr(pykd, 'bp') )

View File

@ -47,6 +47,10 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( 16 + pykd.ptrSize(), tv1.sizeof() )
tv2 = target.module.typedVar( "structTest[2]", target.module.g_testArray )
self.assertEqual( tv1.sizeof()*2, tv2.sizeof() )
self.assertEqual( pykd.sizeof("g_structTest"), tv1.sizeof() )
self.assertEqual( pykd.sizeof("g_testArray"), tv2.sizeof() )
self.assertEqual( pykd.sizeof("g_ucharValue"), 1 )
def testByAddress( self ):
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
@ -263,3 +267,4 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( fieldVal, tv.m_baseField )
for field in tv:
str( field )

View File

@ -12,7 +12,8 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( "structTest", pykd.typeInfo( "structTest" ).name() )
self.assertEqual( "structTest", pykd.typeInfo( target.moduleName + "!structTest" ).name() )
self.assertEqual( "structTest", pykd.typeInfo( "g_structTest" ).name() )
self.assertEqual( "structTest", pykd.typeInfo( target.moduleName + "!g_structTest" ).name() )
self.assertEqual( "structTest", pykd.typeInfo( target.moduleName + "!g_structTest" ).name() )
self.assertEqual( "Int1B", pykd.typeInfo( "Int1B" ) )
def testCreateByName( self ):
""" creating typeInfo by the type name """
@ -100,7 +101,11 @@ class TypeInfoTest( unittest.TestCase ):
def testSize( self ):
ti1 = target.module.type( "structTest" )
self.assertEqual( 16 + pykd.ptrSize(), ti1.size() )
self.assertEqual( pykd.ptrSize(), target.module.type("structTest**").size() )
self.assertEqual( pykd.ptrSize(), target.module.type("structTest**").size() )
self.assertEqual( pykd.sizeof("structTest"), target.module.type("structTest").size() )
self.assertEqual( pykd.sizeof("structTest**"), target.module.type("structTest**").size() )
self.assertEqual( pykd.sizeof("Int1B"), target.module.type("Int1B").size() )
def testBitField( self ):
ti = target.module.type( "g_structWithBits" )
@ -190,4 +195,3 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( 5, len(tv) )
for field in tv:
str( field )