[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:
SND\kernelnet_cp 2011-11-02 08:01:11 +00:00 committed by Mikhail I. Izmestev
parent 10e12fc6b6
commit 2dda9580b2
3 changed files with 67 additions and 23 deletions

View File

@ -1,23 +1,63 @@
#include "stdafx.h"
#include "typedvar.h"
#include "dbgclient.h"
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
TypedVar::getField( const std::string &fieldName )
{
TypeInfo fieldType = m_typeInfo.getField( fieldName );
TypedVarPtr tv;
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" );
throw DbgException( "can not get field" );
return tv;
}
///////////////////////////////////////////////////////////////////////////////////
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;
}
///////////////////////////////////////////////////////////////////////////////////

View File

@ -2,6 +2,7 @@
#include "typeinfo.h"
#include "intbase.h"
#include "dbgobj.h"
namespace pykd {
@ -12,21 +13,21 @@ typedef boost::shared_ptr<TypedVar> TypedVarPtr;
///////////////////////////////////////////////////////////////////////////////////
class TypedVar : public intBase {
class TypedVar : public intBase, protected DbgObject {
public:
TypedVar ( const TypeInfo& typeInfo, ULONG64 offset ) :
m_typeInfo( typeInfo ),
m_offset( offset )
{}
TypedVar ( const TypeInfo& typeInfo, ULONG64 offset );
TypedVar ( IDebugClient4 *client, const TypeInfo& typeInfo, ULONG64 offset );
ULONG64 getAddress() const {
return m_offset;
}
ULONG getSize() {
return m_typeInfo.getSize();
ULONG getSize() const {
return m_size;
}
TypeInfo
@ -47,14 +48,14 @@ protected:
}
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:
BasicTypedVar ( const TypeInfo& typeInfo, ULONG64 offset ) : TypedVar(typeInfo, offset){}
BasicTypedVar ( IDebugClient4 *client, const TypeInfo& typeInfo, ULONG64 offset ) : TypedVar(client, typeInfo, offset){}
TypedVarPtr
virtual getField( const std::string &fieldName ) {
@ -74,8 +75,10 @@ public:
return "BasicTypedVar";
}
virtual ULONG64 getValue() const;
};
///////////////////////////////////////////////////////////////////////////////////
}; // namespace pykd
} // namespace pykd

View File

@ -9,12 +9,6 @@ import pykd
class TypedVarTest( unittest.TestCase ):
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( "g_structTest" )
@ -25,5 +19,12 @@ class TypedVarTest( unittest.TestCase ):
def testGetSize( self ):
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )
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() )
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 )