[haiku-commits] haiku: hrev44954 - in src/apps/debugger: debug_info value/value_nodes model dwarf

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 4 Dec 2012 04:03:11 +0100 (CET)

hrev44954 adds 2 changesets to branch 'master'
old head: ce6b908edbf2f14dd8299ead51de1cc67c014e26
new head: ede21af844389d40efca832b1f49b02a84d77ad8
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=ede21af+%5Ece6b908

----------------------------------------------------------------------------

ada60b4: Rework handling of template parameters.
  
  - Keep a unified list in DIEClassBaseType so that the order
    of template parameters is preserved in cases when type and
    value parameters are mixed. Thanks Ingo for the hint.
  
  - Introduce new base Type TemplateParameter, which represents either
    a template type or template value parameter, a list of which is
    attached to CompoundType.
  
  - Add DwarfTemplateParameter implementing subclass of TemplateParameter
    and adjust DwarfTypeFactory accordingly for the above changes.

ede21af: Implement special handling for BObjectList.
  
  - BListValueNode now also handles BObjectLists. In the latter's case
    however, it uses the template type parameters to map the array
    elements to their actual type. As before, this requires a debug
    libbe to function.

                                      [ Rene Gollent <anevilyak@xxxxxxxxx> ]

----------------------------------------------------------------------------

9 files changed, 178 insertions(+), 68 deletions(-)
.../debugger/debug_info/DwarfTypeFactory.cpp     | 40 +++++++---
src/apps/debugger/debug_info/DwarfTypes.cpp      | 77 +++++++++++++-------
src/apps/debugger/debug_info/DwarfTypes.h        | 34 +++++++--
src/apps/debugger/dwarf/DebugInfoEntries.cpp     |  4 +-
src/apps/debugger/dwarf/DebugInfoEntries.h       |  9 +--
src/apps/debugger/model/Type.cpp                 |  8 ++
src/apps/debugger/model/Type.h                   | 23 ++++--
.../value/type_handlers/BListTypeHandler.cpp     |  3 +-
.../value/value_nodes/BListValueNode.cpp         | 48 ++++++++++--

############################################################################

Commit:      ada60b4e3d16007f477fd198bc304f2965359d5d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ada60b4
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Tue Dec  4 01:58:09 2012 UTC

Rework handling of template parameters.

- Keep a unified list in DIEClassBaseType so that the order
  of template parameters is preserved in cases when type and
  value parameters are mixed. Thanks Ingo for the hint.

- Introduce new base Type TemplateParameter, which represents either
  a template type or template value parameter, a list of which is
  attached to CompoundType.

- Add DwarfTemplateParameter implementing subclass of TemplateParameter
  and adjust DwarfTypeFactory accordingly for the above changes.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/debug_info/DwarfTypeFactory.cpp 
b/src/apps/debugger/debug_info/DwarfTypeFactory.cpp
index 594d7ed..76d2e16 100644
--- a/src/apps/debugger/debug_info/DwarfTypeFactory.cpp
+++ b/src/apps/debugger/debug_info/DwarfTypeFactory.cpp
@@ -102,13 +102,13 @@ struct HasBaseTypesPredicate {
 };
 
 
-// #pragma mark - HasTemplateTypeParametersPredicate
+// #pragma mark - HasTemplateParametersPredicate
 
 
-struct HasTemplateTypeParametersPredicate {
+struct HasTemplateParametersPredicate {
        inline bool operator()(DIEClassBaseType* entry) const
        {
-               return !entry->TemplateTypeParameters().IsEmpty();
+               return !entry->TemplateParameters().IsEmpty();
        }
 };
 
@@ -565,23 +565,41 @@ printf("  -> failed to add type to cache\n");
                // parameters
                classTypeEntry = DwarfUtils::GetDIEByPredicate(
                        dynamic_cast<DIEClassBaseType*>(typeEntry),
-                       HasTemplateTypeParametersPredicate());
+                       HasTemplateParametersPredicate());
 
                if (classTypeEntry != NULL) {
                        for (DebugInfoEntryList::ConstIterator it
-                                               = 
classTypeEntry->TemplateTypeParameters()
+                                               = 
classTypeEntry->TemplateParameters()
                                                        .GetIterator();
                                        DebugInfoEntry* _typeEntry = 
it.Next();) {
-                               DIETemplateTypeParameter* templateTypeEntry =
-                                       
dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
+                               DIETemplateTypeParameter* templateTypeEntry
+                                       = 
dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
                                DwarfType* templateType;
-                               if (CreateType(templateTypeEntry->GetType(), 
templateType)
-                                       != B_OK) {
-                                       continue;
+                               if (templateTypeEntry != NULL) {
+                                       if 
(CreateType(templateTypeEntry->GetType(), templateType)
+                                               != B_OK) {
+                                               continue;
+                                       }
+                               } else {
+                                       DIETemplateValueParameter* 
templateValueEntry
+                                               = 
dynamic_cast<DIETemplateValueParameter*>(_typeEntry);
+                                       if 
(CreateType(templateValueEntry->GetType(), templateType)
+                                               != B_OK) {
+                                               continue;
+                                       }
                                }
                                BReference<DwarfType> 
templateTypeReference(templateType,
                                        true);
-                               if 
(!type->AddTemplateTypeParameter(templateType)) {
+                               DwarfTemplateParameter* parameter
+                                       = new(std::nothrow) 
DwarfTemplateParameter(_typeEntry,
+                                               templateType);
+                               if (parameter == NULL) {
+                                       cacheLocker.Lock();
+                                       fTypeCache->RemoveType(type);
+                                       return B_NO_MEMORY;
+                               }
+
+                               if (!type->AddTemplateParameter(parameter)) {
                                        cacheLocker.Lock();
                                        fTypeCache->RemoveType(type);
                                        return B_NO_MEMORY;
diff --git a/src/apps/debugger/debug_info/DwarfTypes.cpp 
b/src/apps/debugger/debug_info/DwarfTypes.cpp
index 96b1a57..3c85e4b 100644
--- a/src/apps/debugger/debug_info/DwarfTypes.cpp
+++ b/src/apps/debugger/debug_info/DwarfTypes.cpp
@@ -518,6 +518,45 @@ DwarfFunctionParameter::GetType() const
 }
 
 
+// #pragma mark - DwarfTemplateParameter
+
+
+DwarfTemplateParameter::DwarfTemplateParameter(DebugInfoEntry* entry,
+       DwarfType* type)
+       :
+       fEntry(entry),
+       fType(type)
+{
+       fType->AcquireReference();
+       DIETemplateTypeParameter* typeParameter
+               = dynamic_cast<DIETemplateTypeParameter *>(entry);
+       if (typeParameter != NULL)
+               fTemplateKind = TEMPLATE_TYPE_TYPE;
+       else {
+               DIETemplateValueParameter* valueParameter
+                       = dynamic_cast<DIETemplateValueParameter *>(entry);
+               fTemplateKind = TEMPLATE_TYPE_VALUE;
+               const ConstantAttributeValue* constValue = valueParameter
+                       ->ConstValue();
+               switch (constValue->attributeClass) {
+                       case ATTRIBUTE_CLASS_CONSTANT:
+                               fValue.SetTo(constValue->constant);
+                               break;
+                       case ATTRIBUTE_CLASS_STRING:
+                               fValue.SetTo(constValue->string);
+                               break;
+                       // TODO: ATTRIBUTE_CLASS_BLOCK_DATA
+               }
+       }
+}
+
+
+DwarfTemplateParameter::~DwarfTemplateParameter()
+{
+       fType->ReleaseReference();
+}
+
+
 // #pragma mark - DwarfPrimitiveType
 
 
@@ -568,8 +607,10 @@ DwarfCompoundType::~DwarfCompoundType()
        for (int32 i = 0; DwarfDataMember* member = fDataMembers.ItemAt(i); i++)
                member->ReleaseReference();
 
-       for (int32 i = 0; DwarfType* type = fTemplateTypeParameters.ItemAt(i); 
i++)
-               type->ReleaseReference();
+       for (int32 i = 0; DwarfTemplateParameter* parameter
+               = fTemplateParameters.ItemAt(i); i++) {
+               parameter->ReleaseReference();
+       }
 }
 
 
@@ -609,32 +650,16 @@ DwarfCompoundType::DataMemberAt(int32 index) const
 
 
 int32
-DwarfCompoundType::CountTemplateTypeParameters() const
-{
-       return fTemplateTypeParameters.CountItems();
-}
-
-
-Type*
-DwarfCompoundType::TemplateTypeParameterAt(int32 index) const
-{
-       return fTemplateTypeParameters.ItemAt(index);
-}
-
-
-int32
-DwarfCompoundType::CountTemplateValueParameters() const
+DwarfCompoundType::CountTemplateParameters() const
 {
-       // TODO: implement
-       return 0;
+       return fTemplateParameters.CountItems();
 }
 
 
-Type*
-DwarfCompoundType::TemplateValueParameterAt(int32 index) const
+TemplateParameter*
+DwarfCompoundType::TemplateParameterAt(int32 index) const
 {
-       // TODO: implement
-       return NULL;
+       return fTemplateParameters.ItemAt(index);
 }
 
 
@@ -770,12 +795,12 @@ DwarfCompoundType::AddDataMember(DwarfDataMember* member)
 
 
 bool
-DwarfCompoundType::AddTemplateTypeParameter(DwarfType* type)
+DwarfCompoundType::AddTemplateParameter(DwarfTemplateParameter* parameter)
 {
-       if (!fTemplateTypeParameters.AddItem(type))
+       if (!fTemplateParameters.AddItem(parameter))
                return false;
 
-       type->AcquireReference();
+       parameter->AcquireReference();
        return true;
 }
 
diff --git a/src/apps/debugger/debug_info/DwarfTypes.h 
b/src/apps/debugger/debug_info/DwarfTypes.h
index b718e38..50983cc 100644
--- a/src/apps/debugger/debug_info/DwarfTypes.h
+++ b/src/apps/debugger/debug_info/DwarfTypes.h
@@ -17,6 +17,7 @@
 
 class Architecture;
 class CompilationUnit;
+class DebugInfoEntry;
 class DIEAddressingType;
 class DIEArrayType;
 class DIEBaseType;
@@ -237,6 +238,25 @@ private:
 };
 
 
+class DwarfTemplateParameter : public TemplateParameter {
+public:
+                                                               
DwarfTemplateParameter(
+                                                                       
DebugInfoEntry* entry,
+                                                                       
DwarfType* type);
+                                                               
~DwarfTemplateParameter();
+
+       virtual template_type_kind      Kind() const { return fTemplateKind; }
+       virtual Type*                           GetType() const { return fType; 
}
+       virtual BVariant                        Value() const { return fValue; }
+
+private:
+                       DebugInfoEntry*         fEntry;
+                       template_type_kind      fTemplateKind;
+                       Type*                           fType;
+                       BVariant                        fValue;
+};
+
+
 class DwarfPrimitiveType : public PrimitiveType, public DwarfType {
 public:
                                                                
DwarfPrimitiveType(
@@ -271,11 +291,8 @@ public:
        virtual int32                           CountDataMembers() const;
        virtual DataMember*                     DataMemberAt(int32 index) const;
 
-       virtual int32                           CountTemplateTypeParameters() 
const;
-       virtual Type*                           TemplateTypeParameterAt(int32 
index) const;
-
-       virtual int32                           CountTemplateValueParameters() 
const;
-       virtual Type*                           TemplateValueParameterAt(int32 
index) const;
+       virtual int32                           CountTemplateParameters() const;
+       virtual TemplateParameter*      TemplateParameterAt(int32 index) const;
 
        virtual status_t                        
ResolveBaseTypeLocation(BaseType* _baseType,
                                                                        const 
ValueLocation& parentLocation,
@@ -291,12 +308,13 @@ public:
 
                        bool                            
AddInheritance(DwarfInheritance* inheritance);
                        bool                            
AddDataMember(DwarfDataMember* member);
-                       bool                            
AddTemplateTypeParameter(DwarfType* type);
+                       bool                            AddTemplateParameter(
+                                                                       
DwarfTemplateParameter* parameter);
 
 private:
                        typedef BObjectList<DwarfDataMember> DataMemberList;
                        typedef BObjectList<DwarfInheritance> InheritanceList;
-                       typedef BObjectList<DwarfType> TemplateTypeList;
+                       typedef BObjectList<DwarfTemplateParameter> 
TemplateParameterList;
 
 private:
                        status_t                        
_ResolveDataMemberLocation(
@@ -310,7 +328,7 @@ private:
                        DIECompoundType*        fEntry;
                        InheritanceList         fInheritances;
                        DataMemberList          fDataMembers;
-                       TemplateTypeList        fTemplateTypeParameters;
+                       TemplateParameterList fTemplateParameters;
 };
 
 
diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.cpp 
b/src/apps/debugger/dwarf/DebugInfoEntries.cpp
index 0579ae3..d4643a4 100644
--- a/src/apps/debugger/dwarf/DebugInfoEntries.cpp
+++ b/src/apps/debugger/dwarf/DebugInfoEntries.cpp
@@ -478,10 +478,8 @@ DIEClassBaseType::AddChild(DebugInfoEntry* child)
                        fMemberFunctions.Add(child);
                        return B_OK;
                case DW_TAG_template_type_parameter:
-                       fTemplateTypeParameters.Add(child);
-                       return B_OK;
                case DW_TAG_template_value_parameter:
-                       fTemplateValueParameters.Add(child);
+                       fTemplateParameters.Add(child);
                        return B_OK;
 // TODO: Variants!
                default:
diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.h 
b/src/apps/debugger/dwarf/DebugInfoEntries.h
index 9e1399b..757007f 100644
--- a/src/apps/debugger/dwarf/DebugInfoEntries.h
+++ b/src/apps/debugger/dwarf/DebugInfoEntries.h
@@ -353,10 +353,8 @@ public:
 
                        const DebugInfoEntryList& BaseTypes() const
                                                                        { 
return fBaseTypes; }
-                       const DebugInfoEntryList& TemplateTypeParameters() const
-                                                                       { 
return fTemplateTypeParameters; }
-                       const DebugInfoEntryList& TemplateValueParameters() 
const
-                                                                       { 
return fTemplateValueParameters; }
+                       const DebugInfoEntryList& TemplateParameters() const
+                                                                       { 
return fTemplateParameters; }
 
        virtual status_t                        AddChild(DebugInfoEntry* child);
 
@@ -366,8 +364,7 @@ protected:
                        DebugInfoEntryList      fAccessDeclarations;
                        DebugInfoEntryList      fMemberFunctions;
                        DebugInfoEntryList      fInnerTypes;
-                       DebugInfoEntryList      fTemplateTypeParameters;
-                       DebugInfoEntryList      fTemplateValueParameters;
+                       DebugInfoEntryList      fTemplateParameters;
 };
 
 
diff --git a/src/apps/debugger/model/Type.cpp b/src/apps/debugger/model/Type.cpp
index 83f098f..cf81243 100644
--- a/src/apps/debugger/model/Type.cpp
+++ b/src/apps/debugger/model/Type.cpp
@@ -72,6 +72,14 @@ FunctionParameter::~FunctionParameter()
 }
 
 
+// #pragma mark - TemplateParameter
+
+
+TemplateParameter::~TemplateParameter()
+{
+}
+
+
 // #pragma mark - Type
 
 
diff --git a/src/apps/debugger/model/Type.h b/src/apps/debugger/model/Type.h
index c7abc78..5c097da 100644
--- a/src/apps/debugger/model/Type.h
+++ b/src/apps/debugger/model/Type.h
@@ -43,6 +43,12 @@ enum address_type_kind {
 };
 
 
+enum template_type_kind {
+       TEMPLATE_TYPE_TYPE,
+       TEMPLATE_TYPE_VALUE
+};
+
+
 enum {
        TYPE_MODIFIER_CONST             = 0x01,
        TYPE_MODIFIER_VOLATILE  = 0x02,
@@ -105,6 +111,16 @@ public:
 };
 
 
+class TemplateParameter : public BReferenceable {
+public:
+       virtual                                         ~TemplateParameter();
+
+       virtual template_type_kind      Kind() const = 0;
+       virtual Type*                           GetType() const = 0;
+       virtual BVariant                        Value() const = 0;
+};
+
+
 class Type : public BReferenceable {
 public:
        virtual                                         ~Type();
@@ -158,12 +174,9 @@ public:
        virtual int32                           CountDataMembers() const = 0;
        virtual DataMember*                     DataMemberAt(int32 index) const 
= 0;
 
-       virtual int32                           CountTemplateTypeParameters() 
const = 0;
-       virtual Type*                           TemplateTypeParameterAt(int32 
index) const = 0;
+       virtual int32                           CountTemplateParameters() const 
= 0;
+       virtual TemplateParameter*      TemplateParameterAt(int32 index) const 
= 0;
 
-       virtual int32                           CountTemplateValueParameters() 
const = 0;
-       virtual Type*                           TemplateValueParameterAt(int32 
index) const
-                                                                       = 0;
 
        virtual status_t                        
ResolveBaseTypeLocation(BaseType* baseType,
                                                                        const 
ValueLocation& parentLocation,

############################################################################

Revision:    hrev44954
Commit:      ede21af844389d40efca832b1f49b02a84d77ad8
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ede21af
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Tue Dec  4 03:00:54 2012 UTC

Implement special handling for BObjectList.

- BListValueNode now also handles BObjectLists. In the latter's case
  however, it uses the template type parameters to map the array
  elements to their actual type. As before, this requires a debug
  libbe to function.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/value/type_handlers/BListTypeHandler.cpp 
b/src/apps/debugger/value/type_handlers/BListTypeHandler.cpp
index c5918ed..961d3a3 100644
--- a/src/apps/debugger/value/type_handlers/BListTypeHandler.cpp
+++ b/src/apps/debugger/value/type_handlers/BListTypeHandler.cpp
@@ -21,7 +21,8 @@ float
 BListTypeHandler::SupportsType(Type* type)
 {
        if (dynamic_cast<CompoundType*>(type) != NULL
-               && type->Name() == "BList")
+               && (type->Name() == "BList"
+                       || type->Name().Compare("BObjectList", 11) == 0))
                return 1.0f;
 
        return 0.0f;
diff --git a/src/apps/debugger/value/value_nodes/BListValueNode.cpp 
b/src/apps/debugger/value/value_nodes/BListValueNode.cpp
index 167c888..697b651 100644
--- a/src/apps/debugger/value/value_nodes/BListValueNode.cpp
+++ b/src/apps/debugger/value/value_nodes/BListValueNode.cpp
@@ -101,7 +101,8 @@ BListValueNode::BListValueNode(ValueNodeChild* nodeChild,
        :
        ValueNode(nodeChild),
        fType(type),
-       fLoader(NULL)
+       fLoader(NULL),
+       fItemCount(0)
 {
        fType->AcquireReference();
 }
@@ -153,6 +154,21 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* 
valueLoader,
        ValueLocation* memberLocation = NULL;
        CompoundType* baseType = dynamic_cast<CompoundType*>(fType);
 
+       if (baseType->CountTemplateParameters()) {
+               // for BObjectList we need to walk up
+               // the hierarchy: BObjectList -> _PointerList_ -> BList
+               baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0)
+                       ->GetType());
+               if (baseType == NULL || baseType->Name() != "_PointerList_")
+                       return B_BAD_DATA;
+
+               baseType = dynamic_cast<CompoundType*>(baseType->BaseTypeAt(0)
+                       ->GetType());
+               if (baseType == NULL || baseType->Name() != "BList")
+                       return B_BAD_DATA;
+
+       }
+
        for (int32 i = 0; i < baseType->CountDataMembers(); i++) {
                DataMember* member = baseType->DataMemberAt(i);
                if (strcmp(member->Name(), "fObjectList") == 0) {
@@ -213,14 +229,30 @@ BListValueNode::ResolvedLocationAndValue(ValueLoader* 
valueLoader,
 status_t
 BListValueNode::CreateChildren()
 {
-       BString typeName;
-       TypeLookupConstraints constraints;
-       constraints.SetTypeKind(TYPE_ADDRESS);
-       constraints.SetBaseTypeName("void");
+       if (fItemCount == 0 || fChildrenCreated) {
+               fChildrenCreated = true;
+               return B_OK;
+       }
+
        Type* type = NULL;
-       status_t result = fLoader->LookupTypeByName(typeName, constraints, 
type);
-       if (result != B_OK)
-               return result;
+       CompoundType* objectType = dynamic_cast<CompoundType*>(fType);
+       if (objectType->CountTemplateParameters() != 0) {
+               AddressType* addressType = NULL;
+               status_t result = objectType->TemplateParameterAt(0)->GetType()
+                       ->CreateDerivedAddressType(DERIVED_TYPE_POINTER, 
addressType);
+               if (result != B_OK)
+                       return result;
+
+               type = addressType;
+       } else {
+               BString typeName;
+               TypeLookupConstraints constraints;
+               constraints.SetTypeKind(TYPE_ADDRESS);
+               constraints.SetBaseTypeName("void");
+               status_t result = fLoader->LookupTypeByName(typeName, 
constraints, type);
+               if (result != B_OK)
+                       return result;
+       }
 
        for (int32 i = 0; i < fItemCount && i < kMaxArrayElementCount; i++)
        {


Other related posts:

  • » [haiku-commits] haiku: hrev44954 - in src/apps/debugger: debug_info value/value_nodes model dwarf - anevilyak