+ PVOID factory
 ~ fixed align of custom structs

git-svn-id: https://pykd.svn.codeplex.com/svn@79569 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2012-09-14 08:06:00 +00:00 committed by Mikhail I. Izmestev
parent 70747aac37
commit 5fc53c3310
5 changed files with 70 additions and 7 deletions

View File

@ -42,7 +42,7 @@ void CustomStruct::appendField(const std::string &fieldName, TypeInfoPtr fieldTy
throw TypeException(getName(), "duplicate field name: " + fieldName);
ULONG offset = getSize();
offset += (offset % m_alignReq);
offset += offset % (m_align ? m_align : fieldType->getAlignReq());
UdtFieldColl::push_back(
UdtUtils::Field(offset, fieldName, fieldType)
);
@ -93,6 +93,13 @@ void CustomUnion::appendField(const std::string &fieldName, TypeInfoPtr fieldTyp
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr PtrToVoid()
{
return TypeInfoPtr( new PointerTypeInfo(ptrSize()) );
}
////////////////////////////////////////////////////////////////////////////////
} // namespace pykd
////////////////////////////////////////////////////////////////////////////////

View File

@ -15,11 +15,11 @@ namespace pykd {
class CustomStruct : public UdtFieldColl
{
public:
static TypeInfoPtr create(const std::string &name, ULONG alignReq = 0);
static TypeInfoPtr create(const std::string &name, ULONG align = 0);
protected:
CustomStruct(const std::string &name, ULONG alignReq)
: UdtFieldColl(name), m_name(name), m_alignReq(alignReq ? alignReq : ptrSize())
CustomStruct(const std::string &name, ULONG align)
: UdtFieldColl(name), m_name(name), m_align(align)
{
}
@ -37,7 +37,7 @@ protected:
private:
std::string m_name;
ULONG m_alignReq;
ULONG m_align;
};
////////////////////////////////////////////////////////////////////////////////
@ -64,6 +64,10 @@ private:
////////////////////////////////////////////////////////////////////////////////
TypeInfoPtr PtrToVoid();
////////////////////////////////////////////////////////////////////////////////
} // namespace pykd
////////////////////////////////////////////////////////////////////////////////

View File

@ -235,10 +235,12 @@ BOOST_PYTHON_MODULE( pykd )
"Remove all breapoints" );
// custom types
python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "alignReq" ),
python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align" ),
"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::class_<intBase>( "intBase", "intBase", python::no_init )
.def( python::init<python::object&>() )

View File

@ -306,6 +306,10 @@ BitFieldTypeInfo::BitFieldTypeInfo( SymbolPtr &symbol )
///////////////////////////////////////////////////////////////////////////////////
std::string PointerTypeInfo::VoidTypeName( "Void" );
///////////////////////////////////////////////////////////////////////////////////
PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol )
{
SymbolPtr pointTo = symbol->getType();
@ -331,7 +335,7 @@ PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol )
case SymTagBaseType:
// * pointer to Void
if (btVoid == static_cast<BasicType>(pointTo->getBaseType()))
m_derefName = "Void";
m_derefName = VoidTypeName;
break;
case SymTagVTableShape:
@ -359,6 +363,14 @@ PointerTypeInfo::PointerTypeInfo( SymbolPtr &symScope, const std::string &symNam
/////////////////////////////////////////////////////////////////////////////////////
PointerTypeInfo::PointerTypeInfo( ULONG size )
: m_size(size)
, m_derefName(VoidTypeName)
{
}
/////////////////////////////////////////////////////////////////////////////////////
std::string PointerTypeInfo::getName()
{
return getComplexName();
@ -600,6 +612,18 @@ std::string UdtFieldColl::print()
/////////////////////////////////////////////////////////////////////////////////////
ULONG UdtFieldColl::getAlignReq()
{
ULONG alignReq = 1;
const ULONG fieldCount = getFieldCount();
for ( ULONG i = 0; i < fieldCount; ++i )
alignReq = max(alignReq, lookupField(i).m_type->getAlignReq());
return alignReq;
}
/////////////////////////////////////////////////////////////////////////////////////
void UdtTypeInfo::getFields(
SymbolPtr &rootSym,
SymbolPtr &baseVirtualSym,

View File

@ -161,6 +161,10 @@ public:
throw TypeException( getName(), "type is not is not extensible" );
}
virtual ULONG getAlignReq() {
return 1;
}
void setConstant( const BaseTypeVariant& var )
{
m_constant = true;
@ -292,6 +296,10 @@ public:
return m_bitWidth;
}
virtual ULONG getAlignReq() override {
return m_size;
}
private:
ULONG m_size;
@ -352,6 +360,8 @@ protected:
return true;
}
virtual ULONG getAlignReq() override;
protected:
UdtFieldColl(const std::string &typeName) : m_fields(typeName) {}
@ -453,6 +463,10 @@ protected:
virtual std::string print();
virtual ULONG getAlignReq() override {
return getSize();
}
SymbolPtr m_dia;
};
@ -471,6 +485,9 @@ public:
PointerTypeInfo( SymbolPtr &symScope, const std::string &symName );
// void *
PointerTypeInfo( ULONG size );
virtual std::string getName();
virtual ULONG getSize();
@ -483,6 +500,10 @@ public:
return getDerefType();
}
virtual ULONG getAlignReq() override {
return m_size;
}
TypeInfoPtr getDerefType() {
if (!m_derefType)
throw TypeException("<ptr>", "this pointer can not be dereferenced");
@ -500,6 +521,7 @@ public:
}
private:
static std::string VoidTypeName;
TypeInfoPtr m_derefType;
ULONG m_size;
@ -537,6 +559,10 @@ public:
return m_derefType;
}
virtual ULONG getAlignReq() override {
return m_derefType->getAlignReq();
}
TypeInfoPtr getDerefType() {
return m_derefType;
}