[0.2.x] ~ ptrTo is method of typeInfo

git-svn-id: https://pykd.svn.codeplex.com/svn@81387 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2012-11-23 09:45:21 +00:00 committed by Mikhail I. Izmestev
parent 305acde46f
commit 689ce0ae42
6 changed files with 54 additions and 40 deletions

View File

@ -8,6 +8,14 @@ namespace pykd {
////////////////////////////////////////////////////////////////////////////////
CustomTypeBase::CustomTypeBase(const std::string &name, ULONG pointerSize)
: UdtFieldColl(name)
{
m_ptrSize = pointerSize ? pointerSize : ptrSize();
}
////////////////////////////////////////////////////////////////////////////////
void CustomTypeBase::throwIfFiledExist(const std::string &fieldName)
{
bool fieldExist = false;
@ -61,9 +69,12 @@ void CustomTypeBase::throwIfTypeRecursiveImpl(TypeInfoPtr type)
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr CustomStruct::create(const std::string &name, ULONG alignReq /*= 0*/)
TypeInfoPtr CustomStruct::create(
const std::string &name,
ULONG alignReq /*= 0*/,
ULONG pointerSize /*= 0*/)
{
return TypeInfoPtr( new CustomStruct(name, alignReq) );
return TypeInfoPtr( new CustomStruct(name, alignReq, pointerSize) );
}
////////////////////////////////////////////////////////////////////////////////
@ -93,9 +104,9 @@ void CustomStruct::appendField(const std::string &fieldName, TypeInfoPtr fieldTy
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr CustomUnion::create(const std::string &name)
TypeInfoPtr CustomUnion::create(const std::string &name, ULONG pointerSize /*= 0*/)
{
return TypeInfoPtr( new CustomUnion(name) );
return TypeInfoPtr( new CustomUnion(name, pointerSize) );
}
////////////////////////////////////////////////////////////////////////////////
@ -133,13 +144,6 @@ TypeInfoPtr PtrToVoid()
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr PtrTo(TypeInfoPtr type)
{
return TypeInfoPtr( new PointerTypeInfo(type, ptrSize()) );
}
////////////////////////////////////////////////////////////////////////////////
} // namespace pykd
////////////////////////////////////////////////////////////////////////////////

View File

@ -16,7 +16,7 @@ class CustomTypeBase : public UdtFieldColl
{
typedef UdtFieldColl Base;
protected:
CustomTypeBase(const std::string &name) : UdtFieldColl(name) {}
CustomTypeBase(const std::string &name, ULONG pointerSize);
void throwIfFiledExist(const std::string &fieldName);
void throwIfTypeRecursive(TypeInfoPtr type);
@ -31,11 +31,11 @@ class CustomStruct : public CustomTypeBase
{
typedef CustomTypeBase Base;
public:
static TypeInfoPtr create(const std::string &name, ULONG align = 0);
static TypeInfoPtr create(const std::string &name, ULONG align = 0, ULONG pointerSize = 0);
protected:
CustomStruct(const std::string &name, ULONG align)
: Base(name), m_name(name), m_align(align)
CustomStruct(const std::string &name, ULONG align, ULONG pointerSize)
: Base(name, pointerSize), m_name(name), m_align(align)
{
}
@ -62,10 +62,13 @@ class CustomUnion : public CustomTypeBase
{
typedef CustomTypeBase Base;
public:
static TypeInfoPtr create(const std::string &name);
static TypeInfoPtr create(const std::string &name, ULONG pointerSize = 0);
protected:
CustomUnion(const std::string &name) : Base(name) {}
CustomUnion(const std::string &name, ULONG pointerSize)
: Base(name, pointerSize)
{
}
virtual ULONG getSize() override;
@ -85,10 +88,6 @@ TypeInfoPtr PtrToVoid();
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr PtrTo(TypeInfoPtr type);
////////////////////////////////////////////////////////////////////////////////
} // namespace pykd
////////////////////////////////////////////////////////////////////////////////

View File

@ -60,7 +60,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFile_, getSourceFile, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 );
BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( CustomUnion_create, CustomUnion::create, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 );
@ -274,14 +275,11 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "appendSymbolPath", &appendSymbolPath, "Append current symbol path");
// custom types
python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align" ),
python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align", "ptrSize" ),
"Create empty structure. Use append() method for building" ) );
python::def( "createUnion", &CustomUnion::create,
"Create empty union. Use append() method for building" );
python::def( "pVoid", &PtrToVoid,
"Create \"Void *\" type" );
python::def( "ptrTo", &PtrTo,
"Create pointer to target type" );
python::def( "createUnion", &CustomUnion::create, CustomUnion_create( python::args( "name", "ptrSize" ),
"Create empty union. Use append() method for building" ) );
python::def( "pVoid", &PtrToVoid, "Create \"Void*\" type" );
python::class_<intBase>( "intBase", "intBase", python::no_init )
.def( python::init<python::object&>() )
@ -391,6 +389,7 @@ BOOST_PYTHON_MODULE( pykd )
.def( "asMap", &TypeInfo::asMap )
.def( "deref", &TypeInfo::deref )
.def( "append", &TypeInfo::appendField )
.def( "ptrTo", &TypeInfo::ptrTo )
.def( "__str__", &TypeInfo::print )
.def( "__getattr__", &TypeInfo::getField )
.def("__len__", &TypeInfo::getElementCount )

View File

@ -602,6 +602,13 @@ TypeInfoPtr TypeInfo::getRecurciveComplexType( TypeInfoPtr &lowestType, std::str
/////////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr TypeInfo::ptrTo()
{
return TypeInfoPtr( new PointerTypeInfo(shared_from_this(), m_ptrSize) );
}
/////////////////////////////////////////////////////////////////////////////////////
ULONG64 TypeInfo::getStaticOffset()
{
if ( !m_staticMember )

View File

@ -162,6 +162,8 @@ public:
throw TypeException( getName(), "type is not is not extensible" );
}
TypeInfoPtr ptrTo();
virtual ULONG getAlignReq() {
return 1;
}

View File

@ -32,18 +32,21 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( -8, target.module.typedVar( "g_longlongValue" ) )
def testPtrTo(self):
tv1 = target.module.typedVar( "g_ulonglongValue" )
tv2 = pykd.typedVar( pykd.ptrTo(tv1.type()),
target.module.offset("g_pUlonglongValue") )
self.assertEqual( tv1, tv2.deref() )
tvBaseType = pykd.typedVar( pykd.typeInfo("UInt8B").ptrTo(),
target.module.offset("g_pUlonglongValue") )
self.assertEqual( target.module.typedVar( "g_ulonglongValue" ),
tvBaseType.deref() )
tv3 = pykd.typedVar( pykd.ptrTo( target.module.type("structTest") ).deref(),
target.module.offset("g_structTest") )
self.assertEqual( 500, tv3.m_field1 )
tvDiaStruct = pykd.typedVar( target.module.type("structTest").ptrTo(),
target.module.offset("g_structTestPtr") )
self.assertEqual( 500, tvDiaStruct.deref().m_field1 )
tv4 = pykd.typedVar( pykd.ptrTo( target.module.type("structTest") ),
target.module.offset("g_structTestPtr") )
self.assertEqual( 500, tv4.deref().m_field1 )
customStructTest = pykd.createStruct("customStructTest")
customStructTest.append("m_field0", pykd.typeInfo("UInt4B"))
customStructTest.append("m_field1", pykd.typeInfo("UInt8B"))
tvCustomStruct = pykd.typedVar( customStructTest.ptrTo(),
target.module.offset("g_structTestPtr") )
self.assertEqual( 500, tvCustomStruct.deref().m_field1 )
def testConst(self):
self.assertEqual( True, target.module.typedVar( "g_constBoolValue" ) )
@ -64,7 +67,7 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( pykd.sizeof("g_structTest"), tv1.sizeof() )
self.assertEqual( pykd.sizeof("g_testArray"), tv2.sizeof() )
self.assertEqual( pykd.sizeof("g_ucharValue"), 1 )
self.assertEqual( pykd.sizeof("g_ucharValue"), 1 )
def testByAddress( self ):
tv1 = target.module.typedVar( "structTest", target.module.g_structTest )