[0.1.x] updated : typedVar

git-svn-id: https://pykd.svn.codeplex.com/svn@71478 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-11-18 17:20:23 +00:00 committed by Mikhail I. Izmestev
parent 859cfaae3e
commit e3900c02a5
9 changed files with 67 additions and 81 deletions

View File

@ -372,10 +372,10 @@ BOOST_PYTHON_MODULE( pykd )
.def( "field", &pykd::TypeInfo::getField ) .def( "field", &pykd::TypeInfo::getField )
.def( "__getattr__", &pykd::TypeInfo::getField ); .def( "__getattr__", &pykd::TypeInfo::getField );
python::class_<TypedVar, TypedVarPtr, python::bases<intBase> >("typedVar", python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar",
"Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance",
python::no_init ) python::no_init )
.def( python::init<const TypeInfoPtr&, ULONG64>() ) //.def( python::init<const TypeInfoPtr&, ULONG64>() )
.def("getAddress", &TypedVar::getAddress, .def("getAddress", &TypedVar::getAddress,
"Return virtual address" ) "Return virtual address" )
.def("sizeof", &TypedVar::getSize, .def("sizeof", &TypedVar::getSize,

View File

@ -153,33 +153,33 @@ Module::reloadSymbols()
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVar TypedVarPtr
Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr )
{ {
return TypedVar( getTypeByName(typeName), addr ); return TypedVar::getTypedVar( m_client, getTypeByName(typeName), addr );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVar TypedVarPtr
Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ) Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr )
{ {
return TypedVar( typeInfo, addr ); return TypedVar::getTypedVar( m_client, typeInfo, addr );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVar TypedVarPtr
Module::getTypedVarByName( const std::string &symName ) Module::getTypedVarByName( const std::string &symName )
{ {
pyDia::SymbolPtr typeSym = getDia()->getChildByName( symName ); pyDia::SymbolPtr typeSym = getDia()->getChildByName( symName );
return TypedVar( TypeInfo::getTypeInfo( typeSym->getType() ), typeSym->getRva() + m_base ); return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( typeSym->getType() ), typeSym->getRva() + m_base );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVar TypedVarPtr
Module::getTypedVarByAddr( ULONG64 addr ) Module::getTypedVarByAddr( ULONG64 addr )
{ {
addr = addr64(addr); addr = addr64(addr);
@ -193,7 +193,7 @@ Module::getTypedVarByAddr( ULONG64 addr )
if (displacement) if (displacement)
throw DbgException( "not exactly match by RVA" ); throw DbgException( "not exactly match by RVA" );
return TypedVar( TypeInfo::getTypeInfo( diaSym->getType() ), addr ); return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( diaSym->getType() ), addr );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -63,13 +63,13 @@ public:
return TypeInfo::getTypeInfo( boost::static_pointer_cast<pyDia::Symbol>( getDia() ), typeName); return TypeInfo::getTypeInfo( boost::static_pointer_cast<pyDia::Symbol>( getDia() ), typeName);
} }
TypedVar getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ); TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr );
TypedVar getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ); TypedVarPtr getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr );
TypedVar getTypedVarByAddr( ULONG64 addr ); TypedVarPtr getTypedVarByAddr( ULONG64 addr );
TypedVar getTypedVarByName( const std::string &symName ); TypedVarPtr getTypedVarByName( const std::string &symName );
private: private:

View File

@ -31,7 +31,7 @@ TypedVarPtr TypedVar::getTypedVar( IDebugClient4 *client, const TypeInfoPtr& t
if ( typeInfo->isUserDefined() ) if ( typeInfo->isUserDefined() )
{ {
tv.reset( new TypedVar( client, typeInfo, offset ) ); tv.reset( new UdtTypedVar( client, typeInfo, offset ) );
return tv; return tv;
} }
@ -49,55 +49,6 @@ TypedVar::TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64
{ {
m_size = m_typeInfo->getSize(); m_size = m_typeInfo->getSize();
} }
///////////////////////////////////////////////////////////////////////////////////
TypedVar::TypedVar( const TypeInfoPtr& typeInfo, ULONG64 offset ) :
DbgObject( g_dbgClient->client() ),
m_typeInfo( typeInfo ),
m_offset( offset )
{
m_size = m_typeInfo->getSize();
}
///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr
TypedVar::getField( const std::string &fieldName )
{
TypeInfoPtr fieldType = m_typeInfo->getField( fieldName );
TypedVarPtr tv;
if ( fieldType->isBasicType() )
{
tv.reset( new BasicTypedVar( m_client, fieldType, m_offset + fieldType->getOffset() ) );
return tv;
}
if ( fieldType->isPointer() )
{
tv.reset( new PtrTypedVar( m_client, fieldType, m_offset + fieldType->getOffset() ) );
return tv;
}
if ( fieldType->isArray() )
{
tv.reset( new ArrayTypedVar( m_client, fieldType, m_offset + fieldType->getOffset() ) );
return tv;
}
if ( fieldType->isUserDefined() )
{
tv.reset( new TypedVar( m_client, fieldType, m_offset + fieldType->getOffset() ) );
return tv;
}
throw DbgException( "can not get field" );
return tv;
}
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ULONG64 ULONG64
@ -131,4 +82,14 @@ PtrTypedVar::getValue() const
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr
UdtTypedVar::getField( const std::string &fieldName )
{
TypeInfoPtr fieldType = m_typeInfo->getField( fieldName );
return TypedVar::getTypedVar( m_client, fieldType, m_offset + fieldType->getOffset() );
}
///////////////////////////////////////////////////////////////////////////////////
} // end pykd namespace } // end pykd namespace

View File

@ -20,11 +20,6 @@ public:
static TypedVarPtr getTypedVar( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset ); static TypedVarPtr getTypedVar( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
TypedVar ( const TypeInfoPtr& typeInfo, ULONG64 offset );
TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
ULONG64 getAddress() const { ULONG64 getAddress() const {
return m_offset; return m_offset;
} }
@ -42,7 +37,9 @@ public:
return m_typeInfo; return m_typeInfo;
} }
virtual TypedVarPtr getField( const std::string &fieldName ); virtual TypedVarPtr getField( const std::string &fieldName ) {
throw DbgException("no fields");
}
virtual std::string print() { virtual std::string print() {
return "TypeVar"; return "TypeVar";
@ -58,6 +55,10 @@ public:
protected: protected:
//TypedVar ( const TypeInfoPtr& typeInfo, ULONG64 offset );
TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
virtual ULONG64 getValue() const { virtual ULONG64 getValue() const {
return m_offset; return m_offset;
} }
@ -81,13 +82,9 @@ public:
BasicTypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset ) : TypedVar(client, typeInfo, offset){} BasicTypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset ) : TypedVar(client, typeInfo, offset){}
TypedVarPtr
virtual getField( const std::string &fieldName ) {
throw DbgException("no fields");
}
virtual std::string print() { virtual std::string print() {
return "BasicTypedVar"; return intBase::str();
} }
virtual ULONG64 getValue() const; virtual ULONG64 getValue() const;
@ -142,4 +139,15 @@ public:
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
class UdtTypedVar : public TypedVar {
public:
UdtTypedVar( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset ) : TypedVar(client, typeInfo, offset){}
virtual TypedVarPtr getField( const std::string &fieldName );
};
///////////////////////////////////////////////////////////////////////////////////
} // namespace pykd } // namespace pykd

View File

@ -140,18 +140,24 @@ private:
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
class UdtTypeInfo : public BaseTypeInfo class UdtTypeInfo : public TypeInfo
{ {
public: public:
UdtTypeInfo ( pyDia::SymbolPtr &symbol ) : UdtTypeInfo ( pyDia::SymbolPtr &symbol ) :
BaseTypeInfo( symbol ) m_dia( symbol )
{} {}
protected:
virtual std::string getName() { virtual std::string getName() {
return m_dia->getName(); return m_dia->getName();
} }
virtual ULONG getSize() {
return (ULONG)m_dia->getSize();
}
virtual TypeInfoPtr getField( const std::string &fieldName ) { virtual TypeInfoPtr getField( const std::string &fieldName ) {
pyDia::SymbolPtr field = m_dia->getChildByName( fieldName ); pyDia::SymbolPtr field = m_dia->getChildByName( fieldName );
TypeInfoPtr ti = TypeInfo::getTypeInfo( m_dia, fieldName ); TypeInfoPtr ti = TypeInfo::getTypeInfo( m_dia, fieldName );
@ -162,6 +168,8 @@ public:
virtual bool isUserDefined() { virtual bool isUserDefined() {
return true; return true;
} }
pyDia::SymbolPtr m_dia;
}; };
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -51,8 +51,8 @@ if __name__ == "__main__":
target.module = pykd.loadModule( target.moduleName ) target.module = pykd.loadModule( target.moduleName )
target.module.reload(); target.module.reload();
suite = getTestSuite() #suite = getTestSuite()
#suite = getTestSuite( "typedvar.TypedVarTest" ) suite = getTestSuite( "typedvar.TypedVarTest.testGlobalVar" )
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite )

View File

@ -55,3 +55,11 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( 3, tv.m_noArrayField ) self.assertEqual( 3, tv.m_noArrayField )
self.assertNotEqual( -1, tv.m_arrayField[0] ) self.assertNotEqual( -1, tv.m_arrayField[0] )
self.assertNotEqual( 0, tv.m_noArrayField ) self.assertNotEqual( 0, tv.m_noArrayField )
def testGlobalVar(self):
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
self.assertEqual( -100000, target.module.typedVar( "longArray" )[3] )
self.assertEqual( 0x80000000, target.module.typedVar( "ulongArray" )[3] )
self.assertEqual( 0x8000000000000000, target.module.typedVar( "ulonglongArray" )[3] )
self.assertEqual( target.module.g_structTest, target.module.typedVar( "g_structTestPtr" ) )

View File

@ -62,6 +62,7 @@ wchar_t helloWStr[] = L"Hello";
unsigned char ucharArray[] = {0, 10, 0x78, 128, 0xFF }; unsigned char ucharArray[] = {0, 10, 0x78, 128, 0xFF };
unsigned short ushortArray[] = {0, 10, 0xFF, 0x8000, 0xFFFF }; unsigned short ushortArray[] = {0, 10, 0xFF, 0x8000, 0xFFFF };
unsigned long ulongArray[] = {0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF }; unsigned long ulongArray[] = {0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF };
long longArray[] = {0, -10, -2000, -100000, 0xFFFFFFFF };
unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF }; unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF };
int intMatrix[2][3] = { { 0, 1, 2}, { 3, 4, 5 } }; int intMatrix[2][3] = { { 0, 1, 2}, { 3, 4, 5 } };