mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.1.x] added : typeInfo.name(), typeInfo.offset()
git-svn-id: https://pykd.svn.codeplex.com/svn@70197 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
804dc17443
commit
0d7d746778
@ -88,9 +88,10 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
python::def( "dprintln", &pykd::dprintln,
|
python::def( "dprintln", &pykd::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::class_<pykd::TypeInfo>("typeInfo", "Class representing typeInfo", python::no_init )
|
||||||
|
.def( "name", &pykd::TypeInfo::getName )
|
||||||
python::class_<pykd::TypeInfo>("typeInfo", "Class representing typeInfo", python::no_init );
|
.def( "offset", &pykd::TypeInfo::getOffset )
|
||||||
|
.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 )
|
||||||
.def("begin", &pykd::Module::getBase,
|
.def("begin", &pykd::Module::getBase,
|
||||||
@ -116,12 +117,6 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def("__getattr__", &pykd::Module::getSymbol,
|
.def("__getattr__", &pykd::Module::getSymbol,
|
||||||
"Return address of the symbol" );
|
"Return address of the symbol" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//.def("symbols", &pykd::Module::getSymbols,
|
|
||||||
// "Return list of all symbols of the module" );
|
|
||||||
|
|
||||||
|
|
||||||
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
|
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
|
||||||
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope");
|
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope");
|
||||||
|
|
||||||
|
@ -88,6 +88,21 @@ const Symbol::ValueNameEntry Symbol::basicTypeName[] = {
|
|||||||
|
|
||||||
const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName);
|
const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName);
|
||||||
|
|
||||||
|
std::string Symbol::getBasicTypeName( ULONG basicType )
|
||||||
|
{
|
||||||
|
for ( size_t i = 0; i < Symbol::cntBasicTypeName; ++i )
|
||||||
|
{
|
||||||
|
if ( basicType == Symbol::basicTypeName[i].first )
|
||||||
|
return std::string( Symbol::basicTypeName[i].second );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream sstr;
|
||||||
|
|
||||||
|
sstr << "faild to find basic type with index %d" << basicType;
|
||||||
|
|
||||||
|
throw Exception( sstr.str() );
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x)
|
#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x)
|
||||||
|
@ -100,6 +100,9 @@ std::string Symbol::getName()
|
|||||||
return retValue.asStr();
|
return retValue.asStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getBasicName();
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SymbolPtr Symbol::getType()
|
SymbolPtr Symbol::getType()
|
||||||
|
@ -160,6 +160,8 @@ public:
|
|||||||
static const ValueNameEntry amd64RegName[];
|
static const ValueNameEntry amd64RegName[];
|
||||||
static const size_t cntAmd64RegName;
|
static const size_t cntAmd64RegName;
|
||||||
|
|
||||||
|
static std::string getBasicTypeName( ULONG basicType );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Check symbols loop
|
// Check symbols loop
|
||||||
|
@ -12,13 +12,35 @@ class TypeInfo {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
TypeInfo( pyDia::SymbolPtr dia ) :
|
TypeInfo( pyDia::SymbolPtr dia ) :
|
||||||
m_dia( dia )
|
m_dia( dia ),
|
||||||
|
m_offset( 0 )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
TypeInfo
|
||||||
|
getField( const std::string &fieldName ) {
|
||||||
|
pyDia::SymbolPtr field = m_dia->getChildByName( fieldName );
|
||||||
|
TypeInfo ti( field->getType() );
|
||||||
|
ti.m_offset = field->getOffset();
|
||||||
|
return ti;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getName() {
|
||||||
|
return m_dia->isBasicType() ?
|
||||||
|
m_dia->getBasicTypeName( m_dia->getBaseType() ) :
|
||||||
|
m_dia->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONG
|
||||||
|
getOffset() {
|
||||||
|
return m_offset;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
pyDia::SymbolPtr m_dia;
|
pyDia::SymbolPtr m_dia;
|
||||||
|
|
||||||
|
ULONG m_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -102,10 +102,31 @@ class DiaTest( unittest.TestCase ):
|
|||||||
gScope["g_constBoolValue"].type().baseType() )
|
gScope["g_constBoolValue"].type().baseType() )
|
||||||
self.assertEqual( pykd.btULong,
|
self.assertEqual( pykd.btULong,
|
||||||
gScope["g_ulongValue"].type().baseType() )
|
gScope["g_ulongValue"].type().baseType() )
|
||||||
|
|
||||||
except pykd.DiaException as diaExcept:
|
except pykd.DiaException as diaExcept:
|
||||||
print diaExcept
|
print diaExcept
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
def testBasicName(self):
|
||||||
|
self.assertEqual( "NoType", pykd.diaBasicType[ pykd.btNoType ] )
|
||||||
|
self.assertEqual( "Void", pykd.diaBasicType[ pykd.btVoid ] )
|
||||||
|
self.assertEqual( "Char", pykd.diaBasicType[ pykd.btChar ] )
|
||||||
|
self.assertEqual( "WChar", pykd.diaBasicType[ pykd.btWChar ] )
|
||||||
|
self.assertEqual( "Int", pykd.diaBasicType[ pykd.btInt ] )
|
||||||
|
self.assertEqual( "UInt", pykd.diaBasicType[ pykd.btUInt ] )
|
||||||
|
self.assertEqual( "Float", pykd.diaBasicType[ pykd.btFloat ] )
|
||||||
|
self.assertEqual( "BCD", pykd.diaBasicType[ pykd.btBCD ] )
|
||||||
|
self.assertEqual( "Bool", pykd.diaBasicType[ pykd.btBool ] )
|
||||||
|
self.assertEqual( "Long", pykd.diaBasicType[ pykd.btLong ] )
|
||||||
|
self.assertEqual( "ULong", pykd.diaBasicType[ pykd.btULong ] )
|
||||||
|
self.assertEqual( "Currency", pykd.diaBasicType[ pykd.btCurrency ] )
|
||||||
|
self.assertEqual( "Date", pykd.diaBasicType[ pykd.btDate ] )
|
||||||
|
self.assertEqual( "Variant", pykd.diaBasicType[ pykd.btVariant ] )
|
||||||
|
self.assertEqual( "Complex", pykd.diaBasicType[ pykd.btComplex ] )
|
||||||
|
self.assertEqual( "Bit", pykd.diaBasicType[ pykd.btBit ] )
|
||||||
|
self.assertEqual( "BSTR", pykd.diaBasicType[ pykd.btBSTR ] )
|
||||||
|
self.assertEqual( "Hresult", pykd.diaBasicType[ pykd.btHresult ] )
|
||||||
|
|
||||||
def testBits(self):
|
def testBits(self):
|
||||||
try:
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
|
@ -18,3 +18,23 @@ class TypeInfoTest( unittest.TestCase ):
|
|||||||
ti1 = target.module.type( "structTest" )
|
ti1 = target.module.type( "structTest" )
|
||||||
ti2 = target.module.type( "classChild" )
|
ti2 = target.module.type( "classChild" )
|
||||||
|
|
||||||
|
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
|
||||||
|
except pykd.DiaException: pass
|
||||||
|
|
||||||
|
def testName( self ):
|
||||||
|
ti1 = target.module.type( "classChild" )
|
||||||
|
self.assertEqual( "classChild", ti1.name() )
|
||||||
|
self.assertEqual( "Int", ti1.m_childField.name() )
|
||||||
|
self.assertEqual( "structTest", ti1.m_childField3.name() )
|
||||||
|
|
||||||
|
def testOffset( self ):
|
||||||
|
ti1 = target.module.type( "structTest" )
|
||||||
|
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() )
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#pragma pack( push, 4 )
|
||||||
|
|
||||||
const ULONG g_constNumValue = 0x5555;
|
const ULONG g_constNumValue = 0x5555;
|
||||||
const bool g_constBoolValue = true;
|
const bool g_constBoolValue = true;
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ class classChild : public classBase {
|
|||||||
public:
|
public:
|
||||||
int m_childField;
|
int m_childField;
|
||||||
int m_childField2;
|
int m_childField2;
|
||||||
|
structTest m_childField3;
|
||||||
void childMethod() const {}
|
void childMethod() const {}
|
||||||
virtual void virtFunc() {}
|
virtual void virtFunc() {}
|
||||||
virtual void virtFunc2() {}
|
virtual void virtFunc2() {}
|
||||||
@ -89,6 +92,8 @@ void FuncWithName1(int a)
|
|||||||
std::cout << g_string;
|
std::cout << g_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma pack( pop )
|
||||||
|
|
||||||
int _tmain(int argc, _TCHAR* argv[])
|
int _tmain(int argc, _TCHAR* argv[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="windows-1251"?>
|
<?xml version="1.0" encoding="windows-1251"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9.00"
|
Version="9,00"
|
||||||
Name="targetapp"
|
Name="targetapp"
|
||||||
ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}"
|
ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}"
|
||||||
RootNamespace="targetapp"
|
RootNamespace="targetapp"
|
||||||
|
Loading…
Reference in New Issue
Block a user