mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.1.x] added : integer fields output for typedVar class
git-svn-id: https://pykd.svn.codeplex.com/svn@70965 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
10e12fc6b6
commit
2dda9580b2
@ -1,23 +1,63 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include "typedvar.h"
|
#include "typedvar.h"
|
||||||
|
#include "dbgclient.h"
|
||||||
|
|
||||||
namespace pykd {
|
namespace pykd {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
TypedVar::TypedVar ( IDebugClient4 *client, const TypeInfo& typeInfo, ULONG64 offset ) :
|
||||||
|
DbgObject( client ),
|
||||||
|
m_typeInfo( typeInfo ),
|
||||||
|
m_offset( offset )
|
||||||
|
{
|
||||||
|
m_size = m_typeInfo.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
TypedVar::TypedVar( const TypeInfo& typeInfo, ULONG64 offset ) :
|
||||||
|
DbgObject( g_dbgClient->client() ),
|
||||||
|
m_typeInfo( typeInfo ),
|
||||||
|
m_offset( offset )
|
||||||
|
{
|
||||||
|
m_size = m_typeInfo.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TypedVarPtr
|
TypedVarPtr
|
||||||
TypedVar::getField( const std::string &fieldName )
|
TypedVar::getField( const std::string &fieldName )
|
||||||
{
|
{
|
||||||
TypeInfo fieldType = m_typeInfo.getField( fieldName );
|
TypeInfo fieldType = m_typeInfo.getField( fieldName );
|
||||||
|
|
||||||
|
TypedVarPtr tv;
|
||||||
|
|
||||||
if ( fieldType.isBasicType() )
|
if ( fieldType.isBasicType() )
|
||||||
{
|
{
|
||||||
return TypedVarPtr( new BasicTypedVar( fieldType, 0 ) );
|
tv.reset( new BasicTypedVar( m_client, fieldType, m_offset + fieldType.getOffset() ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw DbgException( "can not get field" );
|
||||||
|
|
||||||
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw DbgException( "can not get field" );
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG64
|
||||||
|
BasicTypedVar::getValue() const
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
ULONG64 val = 0;
|
||||||
|
|
||||||
|
hres = m_dataSpaces->ReadVirtual( m_offset, &val, getSize(), NULL );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw MemoryException( m_offset, false );
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "typeinfo.h"
|
#include "typeinfo.h"
|
||||||
#include "intbase.h"
|
#include "intbase.h"
|
||||||
|
#include "dbgobj.h"
|
||||||
|
|
||||||
namespace pykd {
|
namespace pykd {
|
||||||
|
|
||||||
@ -12,21 +13,21 @@ typedef boost::shared_ptr<TypedVar> TypedVarPtr;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class TypedVar : public intBase {
|
class TypedVar : public intBase, protected DbgObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TypedVar ( const TypeInfo& typeInfo, ULONG64 offset ) :
|
TypedVar ( const TypeInfo& typeInfo, ULONG64 offset );
|
||||||
m_typeInfo( typeInfo ),
|
|
||||||
m_offset( offset )
|
|
||||||
{}
|
TypedVar ( IDebugClient4 *client, const TypeInfo& typeInfo, ULONG64 offset );
|
||||||
|
|
||||||
ULONG64 getAddress() const {
|
ULONG64 getAddress() const {
|
||||||
return m_offset;
|
return m_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG getSize() {
|
ULONG getSize() const {
|
||||||
return m_typeInfo.getSize();
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeInfo
|
TypeInfo
|
||||||
@ -47,14 +48,14 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void setValue( ULONG64 value) {
|
virtual void setValue( ULONG64 value) {
|
||||||
m_offset = value;
|
throw DbgException("can not change");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
TypeInfo m_typeInfo;
|
TypeInfo m_typeInfo;
|
||||||
|
|
||||||
ULONG64 m_offset;
|
ULONG64 m_offset;
|
||||||
|
|
||||||
|
ULONG m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -63,7 +64,7 @@ class BasicTypedVar : public TypedVar {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BasicTypedVar ( const TypeInfo& typeInfo, ULONG64 offset ) : TypedVar(typeInfo, offset){}
|
BasicTypedVar ( IDebugClient4 *client, const TypeInfo& typeInfo, ULONG64 offset ) : TypedVar(client, typeInfo, offset){}
|
||||||
|
|
||||||
TypedVarPtr
|
TypedVarPtr
|
||||||
virtual getField( const std::string &fieldName ) {
|
virtual getField( const std::string &fieldName ) {
|
||||||
@ -74,8 +75,10 @@ public:
|
|||||||
return "BasicTypedVar";
|
return "BasicTypedVar";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG64 getValue() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}; // namespace pykd
|
} // namespace pykd
|
||||||
|
@ -9,12 +9,6 @@ import pykd
|
|||||||
class TypedVarTest( unittest.TestCase ):
|
class TypedVarTest( unittest.TestCase ):
|
||||||
|
|
||||||
def testCtor( self ):
|
def testCtor( self ):
|
||||||
try: pykd.typedVar()
|
|
||||||
except RuntimeError: pass
|
|
||||||
|
|
||||||
try: pykd.typedVar( "structTest", target.module.g_structTest )
|
|
||||||
except RuntimeError: pass
|
|
||||||
|
|
||||||
tv = target.module.typedVar( "structTest", target.module.g_structTest )
|
tv = target.module.typedVar( "structTest", target.module.g_structTest )
|
||||||
tv = target.module.typedVar( "g_structTest" )
|
tv = target.module.typedVar( "g_structTest" )
|
||||||
|
|
||||||
@ -25,5 +19,12 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
def testGetSize( self ):
|
def testGetSize( self ):
|
||||||
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
|
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
|
||||||
self.assertEqual( 16, tv1.sizeof() )
|
self.assertEqual( 16, tv1.sizeof() )
|
||||||
#tv2 = target.module.typedVar( "structTest[]", target.module.g_testArray )
|
#tv2 = target.module.typedVar( "structTest[2]", target.module.g_testArray )
|
||||||
#self.assertEqual( tv1.sizeof()*2, tv2.sizeof() )
|
#self.assertEqual( tv1.sizeof()*2, tv2.sizeof() )
|
||||||
|
|
||||||
|
def testStruct(self):
|
||||||
|
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
|
||||||
|
self.assertEqual( 0, tv1.m_field0 + 0 )
|
||||||
|
self.assertEqual( 500, tv1.m_field1 )
|
||||||
|
self.assertEqual( True, tv1.m_field2 )
|
||||||
|
self.assertEqual( 1, tv1.m_field3 )
|
Loading…
Reference in New Issue
Block a user