Author: anevilyak Date: 2011-07-01 00:30:48 +0200 (Fri, 01 Jul 2011) New Revision: 42348 Changeset: https://dev.haiku-os.org/changeset/42348 Ticket: https://dev.haiku-os.org/ticket/5495 Added: haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.cpp haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.h Modified: haiku/trunk/src/apps/debugger/Jamfile haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h haiku/trunk/src/apps/debugger/debug_info/DwarfTypeFactory.cpp haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.cpp haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.h haiku/trunk/src/apps/debugger/debug_info/GlobalTypeLookup.h haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h haiku/trunk/src/apps/debugger/debug_info/SpecificImageDebugInfo.h haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.cpp haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.h haiku/trunk/src/apps/debugger/model/Type.h Log: * Add model class TypeLookupConstraints. * Create and pass constraints to type lookup requests to ensure that the type we get back is in fact the one we wanted, and not a different one that happened to have a similar name. Resolves ticket #5495. Modified: haiku/trunk/src/apps/debugger/Jamfile =================================================================== --- haiku/trunk/src/apps/debugger/Jamfile 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/Jamfile 2011-06-30 22:30:48 UTC (rev 42348) @@ -134,6 +134,7 @@ ThreadInfo.cpp Type.cpp TypeComponentPath.cpp + TypeLookupConstraints.cpp Variable.cpp # settings Modified: haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -80,7 +80,8 @@ status_t DebuggerImageDebugInfo::GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type) + const BString& name, const TypeLookupConstraints& constraints, + Type*& _type) { return B_UNSUPPORTED; } Modified: haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -28,7 +28,9 @@ virtual status_t GetFunctions( BObjectList<FunctionDebugInfo>& functions); virtual status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type); + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type); virtual AddressSectionType GetAddressSectionType(target_addr_t address); virtual status_t CreateFrame(Image* image, FunctionInstance* functionInstance, Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -46,6 +46,7 @@ #include "TargetAddressRangeList.h" #include "TeamMemory.h" #include "Tracing.h" +#include "TypeLookupConstraints.h" #include "UnsupportedLanguage.h" #include "Variable.h" @@ -383,7 +384,8 @@ status_t DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type) + const BString& name, const TypeLookupConstraints& constraints, + Type*& _type) { int32 registerCount = fArchitecture->CountRegisters(); const Register* registers = fArchitecture->Registers(); @@ -412,6 +414,15 @@ if (typeEntry->IsDeclaration()) continue; + if (constraints.HasTypeKind() + && dwarf_tag_to_type_kind(typeEntry->Tag()) + != constraints.TypeKind()) + continue; + if (constraints.HasSubtypeKind() + && dwarf_tag_to_subtype_kind(typeEntry->Tag()) + != constraints.SubtypeKind()) + continue; + BString typeEntryName; DwarfUtils::GetFullyQualifiedDIEName(typeEntry, typeEntryName); if (typeEntryName != name) Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -51,7 +51,9 @@ virtual status_t GetFunctions( BObjectList<FunctionDebugInfo>& functions); virtual status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type); + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type); virtual AddressSectionType GetAddressSectionType(target_addr_t address); Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfTypeFactory.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfTypeFactory.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfTypeFactory.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -27,6 +27,7 @@ #include "SourceLanguageInfo.h" #include "StringUtils.h" #include "Tracing.h" +#include "TypeLookupConstraints.h" #include "ValueLocation.h" @@ -314,8 +315,14 @@ // If the type entry indicates a declaration only, we try to look the // type up globally first. + TypeLookupConstraints constraints( + dwarf_tag_to_type_kind(typeEntry->Tag())); + int32 subtypeKind = dwarf_tag_to_subtype_kind(typeEntry->Tag()); + if (subtypeKind >= 0) + constraints.SetSubtypeKind(subtypeKind); if (typeEntry->IsDeclaration() && name.Length() > 0 - && fTypeLookup->GetType(fTypeCache, name, globalType) + && fTypeLookup->GetType(fTypeCache, name, + constraints, globalType) == B_OK) { DwarfType* globalDwarfType = dynamic_cast<DwarfType*>(globalType); Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -50,6 +50,84 @@ } // unnamed namespace +type_kind +dwarf_tag_to_type_kind(int32 tag) +{ + switch (tag) { + case DW_TAG_class_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: + case DW_TAG_interface_type: + return TYPE_COMPOUND; + + case DW_TAG_base_type: + return TYPE_PRIMITIVE; + + case DW_TAG_pointer_type: + case DW_TAG_reference_type: + return TYPE_ADDRESS; + + case DW_TAG_const_type: + case DW_TAG_packed_type: + case DW_TAG_volatile_type: + case DW_TAG_restrict_type: + case DW_TAG_shared_type: + return TYPE_MODIFIED; + + case DW_TAG_typedef: + return TYPE_TYPEDEF; + + case DW_TAG_array_type: + return TYPE_ARRAY; + + case DW_TAG_enumeration_type: + return TYPE_ENUMERATION; + + case DW_TAG_subrange_type: + return TYPE_SUBRANGE; + + case DW_TAG_unspecified_type: + return TYPE_UNSPECIFIED; + + case DW_TAG_subroutine_type: + return TYPE_FUNCTION; + + case DW_TAG_ptr_to_member_type: + return TYPE_POINTER_TO_MEMBER; + + } + + return TYPE_UNSPECIFIED; +} + + +int32 +dwarf_tag_to_subtype_kind(int32 tag) +{ + switch (tag) { + case DW_TAG_class_type: + return COMPOUND_TYPE_CLASS; + + case DW_TAG_structure_type: + return COMPOUND_TYPE_STRUCT; + + case DW_TAG_union_type: + return COMPOUND_TYPE_UNION; + + case DW_TAG_interface_type: + return COMPOUND_TYPE_INTERFACE; + + case DW_TAG_pointer_type: + return DERIVED_TYPE_POINTER; + + case DW_TAG_reference_type: + return DERIVED_TYPE_REFERENCE; + } + + return -1; +} + + // #pragma mark - DwarfTypeContext Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfTypes.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -41,6 +41,11 @@ class ValueLocation; +// conversion functions between model types and dwarf types +type_kind dwarf_tag_to_type_kind(int32 tag); +int32 dwarf_tag_to_subtype_kind(int32 tag); + + class DwarfTypeContext : public BReferenceable { public: DwarfTypeContext(Architecture* architecture, Modified: haiku/trunk/src/apps/debugger/debug_info/GlobalTypeLookup.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/GlobalTypeLookup.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/GlobalTypeLookup.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -15,6 +15,7 @@ class BString; class Type; +class TypeLookupConstraints; enum global_type_cache_scope { @@ -62,7 +63,9 @@ virtual ~GlobalTypeLookup(); virtual status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type) = 0; + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type) = 0; // returns a reference }; Modified: haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -78,11 +78,12 @@ status_t ImageDebugInfo::GetType(GlobalTypeCache* cache, const BString& name, - Type*& _type) + const TypeLookupConstraints& constraints, Type*& _type) { for (int32 i = 0; SpecificImageDebugInfo* specificInfo = fSpecificInfos.ItemAt(i); i++) { - status_t error = specificInfo->GetType(cache, name, _type); + status_t error = specificInfo->GetType(cache, name, constraints, + _type); if (error == B_OK || error == B_NO_MEMORY) return error; } Modified: haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -26,6 +26,7 @@ class LocatableFile; class SpecificImageDebugInfo; class Type; +class TypeLookupConstraints; class ImageDebugInfo : public BReferenceable { @@ -39,7 +40,9 @@ status_t FinishInit(); status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type); + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type); // returns a reference AddressSectionType GetAddressSectionType(target_addr_t address) const; Modified: haiku/trunk/src/apps/debugger/debug_info/SpecificImageDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/SpecificImageDebugInfo.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/SpecificImageDebugInfo.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -29,6 +29,7 @@ class StackFrame; class Statement; class Type; +class TypeLookupConstraints; class ValueLocation; @@ -42,7 +43,9 @@ // returns references virtual status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type) = 0; + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type) = 0; // returns a reference virtual AddressSectionType GetAddressSectionType(target_addr_t address) = 0; Modified: haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.cpp 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -29,6 +29,7 @@ #include "SpecificImageDebugInfo.h" #include "StringUtils.h" #include "Type.h" +#include "TypeLookupConstraints.h" // #pragma mark - FunctionHashDefinition @@ -362,7 +363,7 @@ status_t TeamDebugInfo::GetType(GlobalTypeCache* cache, const BString& name, - Type*& _type) + const TypeLookupConstraints& constraints, Type*& _type) { // maybe the type is already cached AutoLocker<GlobalTypeCache> cacheLocker(cache); @@ -390,7 +391,7 @@ // get the type status_t error = B_ENTRY_NOT_FOUND; for (int32 i = 0; ImageDebugInfo* imageDebugInfo = images.ItemAt(i); i++) { - error = imageDebugInfo->GetType(cache, name, type); + error = imageDebugInfo->GetType(cache, name, constraints, type); if (error == B_OK) { _type = type; break; Modified: haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/debug_info/TeamDebugInfo.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -43,7 +43,9 @@ status_t Init(); virtual status_t GetType(GlobalTypeCache* cache, - const BString& name, Type*& _type); + const BString& name, + const TypeLookupConstraints& constraints, + Type*& _type); status_t LoadImageDebugInfo(const ImageInfo& imageInfo, LocatableFile* imageFile, Modified: haiku/trunk/src/apps/debugger/model/Type.h =================================================================== --- haiku/trunk/src/apps/debugger/model/Type.h 2011-06-30 21:57:39 UTC (rev 42347) +++ haiku/trunk/src/apps/debugger/model/Type.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -29,6 +29,14 @@ }; +enum compound_type_kind { + COMPOUND_TYPE_CLASS, + COMPOUND_TYPE_STRUCT, + COMPOUND_TYPE_UNION, + COMPOUND_TYPE_INTERFACE +}; + + enum address_type_kind { DERIVED_TYPE_POINTER, DERIVED_TYPE_REFERENCE Added: haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.cpp =================================================================== --- haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.cpp (rev 0) +++ haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.cpp 2011-06-30 22:30:48 UTC (rev 42348) @@ -0,0 +1,79 @@ +/* + * Copyright 2011, Rene Gollent, rene@xxxxxxxxxxxx + * Distributed under the terms of the MIT License. + */ + + +#include "TypeLookupConstraints.h" + + +TypeLookupConstraints::TypeLookupConstraints() + : + fTypeKindGiven(false), + fSubtypeKindGiven(false) +{ +} + + +TypeLookupConstraints::TypeLookupConstraints(type_kind typeKind) + : + fTypeKind(typeKind), + fTypeKindGiven(true), + fSubtypeKindGiven(false) +{ +} + + +TypeLookupConstraints::TypeLookupConstraints(type_kind typeKind, + int32 subTypeKind) + : + fTypeKind(typeKind), + fSubtypeKind(subTypeKind), + fTypeKindGiven(true), + fSubtypeKindGiven(true) +{ +} + + +bool +TypeLookupConstraints::HasTypeKind() const +{ + return fTypeKindGiven; +} + + +bool +TypeLookupConstraints::HasSubtypeKind() const +{ + return fSubtypeKindGiven; +} + + +type_kind +TypeLookupConstraints::TypeKind() const +{ + return fTypeKind; +} + + +int32 +TypeLookupConstraints::SubtypeKind() const +{ + return fSubtypeKind; +} + + +void +TypeLookupConstraints::SetTypeKind(type_kind typeKind) +{ + fTypeKind = typeKind; + fTypeKindGiven = true; +} + + +void +TypeLookupConstraints::SetSubtypeKind(int32 subtypeKind) +{ + fSubtypeKind = subtypeKind; + fSubtypeKindGiven = true; +} Added: haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.h =================================================================== --- haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.h (rev 0) +++ haiku/trunk/src/apps/debugger/model/TypeLookupConstraints.h 2011-06-30 22:30:48 UTC (rev 42348) @@ -0,0 +1,36 @@ +/* + * Copyright 2011, Rene Gollent, rene@xxxxxxxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef TYPE_LOOKUP_CONSTRAINTS_H +#define TYPE_LOOKUP_CONSTRAINTS_H + + +#include "Type.h" + + +class TypeLookupConstraints { +public: + TypeLookupConstraints(); + // no constraints + TypeLookupConstraints(type_kind typeKind); + // constrain on type only + TypeLookupConstraints(type_kind typeKind, + int32 subtypeKind); + + bool HasTypeKind() const; + bool HasSubtypeKind() const; + type_kind TypeKind() const; + int32 SubtypeKind() const; + + void SetTypeKind(type_kind typeKind); + void SetSubtypeKind(int32 subtypeKind); + +private: + type_kind fTypeKind; + int32 fSubtypeKind; + bool fTypeKindGiven; + bool fSubtypeKindGiven; +}; + +#endif // TYPE_LOOKUP_CONSTRAINTS_H