mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[0.2.x]:
+ 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:
parent
70747aac37
commit
5fc53c3310
@ -42,7 +42,7 @@ void CustomStruct::appendField(const std::string &fieldName, TypeInfoPtr fieldTy
|
|||||||
throw TypeException(getName(), "duplicate field name: " + fieldName);
|
throw TypeException(getName(), "duplicate field name: " + fieldName);
|
||||||
|
|
||||||
ULONG offset = getSize();
|
ULONG offset = getSize();
|
||||||
offset += (offset % m_alignReq);
|
offset += offset % (m_align ? m_align : fieldType->getAlignReq());
|
||||||
UdtFieldColl::push_back(
|
UdtFieldColl::push_back(
|
||||||
UdtUtils::Field(offset, fieldName, fieldType)
|
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
|
} // namespace pykd
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -15,11 +15,11 @@ namespace pykd {
|
|||||||
class CustomStruct : public UdtFieldColl
|
class CustomStruct : public UdtFieldColl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static TypeInfoPtr create(const std::string &name, ULONG alignReq = 0);
|
static TypeInfoPtr create(const std::string &name, ULONG align = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CustomStruct(const std::string &name, ULONG alignReq)
|
CustomStruct(const std::string &name, ULONG align)
|
||||||
: UdtFieldColl(name), m_name(name), m_alignReq(alignReq ? alignReq : ptrSize())
|
: UdtFieldColl(name), m_name(name), m_align(align)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
ULONG m_alignReq;
|
ULONG m_align;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -64,6 +64,10 @@ private:
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
TypeInfoPtr PtrToVoid();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
} // namespace pykd
|
} // namespace pykd
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -235,10 +235,12 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Remove all breapoints" );
|
"Remove all breapoints" );
|
||||||
|
|
||||||
// custom types
|
// 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" ) );
|
"Create empty structure. Use append() method for building" ) );
|
||||||
python::def( "createUnion", &CustomUnion::create,
|
python::def( "createUnion", &CustomUnion::create,
|
||||||
"Create empty union. Use append() method for building" );
|
"Create empty union. Use append() method for building" );
|
||||||
|
python::def( "pVoid", &PtrToVoid,
|
||||||
|
"Create \"Void *\" type" );
|
||||||
|
|
||||||
python::class_<intBase>( "intBase", "intBase", python::no_init )
|
python::class_<intBase>( "intBase", "intBase", python::no_init )
|
||||||
.def( python::init<python::object&>() )
|
.def( python::init<python::object&>() )
|
||||||
|
@ -306,6 +306,10 @@ BitFieldTypeInfo::BitFieldTypeInfo( SymbolPtr &symbol )
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string PointerTypeInfo::VoidTypeName( "Void" );
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol )
|
PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol )
|
||||||
{
|
{
|
||||||
SymbolPtr pointTo = symbol->getType();
|
SymbolPtr pointTo = symbol->getType();
|
||||||
@ -331,7 +335,7 @@ PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol )
|
|||||||
case SymTagBaseType:
|
case SymTagBaseType:
|
||||||
// * pointer to Void
|
// * pointer to Void
|
||||||
if (btVoid == static_cast<BasicType>(pointTo->getBaseType()))
|
if (btVoid == static_cast<BasicType>(pointTo->getBaseType()))
|
||||||
m_derefName = "Void";
|
m_derefName = VoidTypeName;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SymTagVTableShape:
|
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()
|
std::string PointerTypeInfo::getName()
|
||||||
{
|
{
|
||||||
return getComplexName();
|
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(
|
void UdtTypeInfo::getFields(
|
||||||
SymbolPtr &rootSym,
|
SymbolPtr &rootSym,
|
||||||
SymbolPtr &baseVirtualSym,
|
SymbolPtr &baseVirtualSym,
|
||||||
|
@ -161,6 +161,10 @@ public:
|
|||||||
throw TypeException( getName(), "type is not is not extensible" );
|
throw TypeException( getName(), "type is not is not extensible" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void setConstant( const BaseTypeVariant& var )
|
void setConstant( const BaseTypeVariant& var )
|
||||||
{
|
{
|
||||||
m_constant = true;
|
m_constant = true;
|
||||||
@ -292,6 +296,10 @@ public:
|
|||||||
return m_bitWidth;
|
return m_bitWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() override {
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ULONG m_size;
|
ULONG m_size;
|
||||||
@ -352,6 +360,8 @@ protected:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UdtFieldColl(const std::string &typeName) : m_fields(typeName) {}
|
UdtFieldColl(const std::string &typeName) : m_fields(typeName) {}
|
||||||
|
|
||||||
@ -453,6 +463,10 @@ protected:
|
|||||||
|
|
||||||
virtual std::string print();
|
virtual std::string print();
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() override {
|
||||||
|
return getSize();
|
||||||
|
}
|
||||||
|
|
||||||
SymbolPtr m_dia;
|
SymbolPtr m_dia;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -471,6 +485,9 @@ public:
|
|||||||
|
|
||||||
PointerTypeInfo( SymbolPtr &symScope, const std::string &symName );
|
PointerTypeInfo( SymbolPtr &symScope, const std::string &symName );
|
||||||
|
|
||||||
|
// void *
|
||||||
|
PointerTypeInfo( ULONG size );
|
||||||
|
|
||||||
virtual std::string getName();
|
virtual std::string getName();
|
||||||
|
|
||||||
virtual ULONG getSize();
|
virtual ULONG getSize();
|
||||||
@ -483,6 +500,10 @@ public:
|
|||||||
return getDerefType();
|
return getDerefType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() override {
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
TypeInfoPtr getDerefType() {
|
TypeInfoPtr getDerefType() {
|
||||||
if (!m_derefType)
|
if (!m_derefType)
|
||||||
throw TypeException("<ptr>", "this pointer can not be dereferenced");
|
throw TypeException("<ptr>", "this pointer can not be dereferenced");
|
||||||
@ -500,6 +521,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static std::string VoidTypeName;
|
||||||
|
|
||||||
TypeInfoPtr m_derefType;
|
TypeInfoPtr m_derefType;
|
||||||
ULONG m_size;
|
ULONG m_size;
|
||||||
@ -537,6 +559,10 @@ public:
|
|||||||
return m_derefType;
|
return m_derefType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ULONG getAlignReq() override {
|
||||||
|
return m_derefType->getAlignReq();
|
||||||
|
}
|
||||||
|
|
||||||
TypeInfoPtr getDerefType() {
|
TypeInfoPtr getDerefType() {
|
||||||
return m_derefType;
|
return m_derefType;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user