* 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42348 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -134,6 +134,7 @@ Application Debugger :
|
|||||||
ThreadInfo.cpp
|
ThreadInfo.cpp
|
||||||
Type.cpp
|
Type.cpp
|
||||||
TypeComponentPath.cpp
|
TypeComponentPath.cpp
|
||||||
|
TypeLookupConstraints.cpp
|
||||||
Variable.cpp
|
Variable.cpp
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ DebuggerImageDebugInfo::GetFunctions(BObjectList<FunctionDebugInfo>& functions)
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
DebuggerImageDebugInfo::GetType(GlobalTypeCache* cache,
|
DebuggerImageDebugInfo::GetType(GlobalTypeCache* cache,
|
||||||
const BString& name, Type*& _type)
|
const BString& name, const TypeLookupConstraints& constraints,
|
||||||
|
Type*& _type)
|
||||||
{
|
{
|
||||||
return B_UNSUPPORTED;
|
return B_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ public:
|
|||||||
virtual status_t GetFunctions(
|
virtual status_t GetFunctions(
|
||||||
BObjectList<FunctionDebugInfo>& functions);
|
BObjectList<FunctionDebugInfo>& functions);
|
||||||
virtual status_t GetType(GlobalTypeCache* cache,
|
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 AddressSectionType GetAddressSectionType(target_addr_t address);
|
||||||
virtual status_t CreateFrame(Image* image,
|
virtual status_t CreateFrame(Image* image,
|
||||||
FunctionInstance* functionInstance,
|
FunctionInstance* functionInstance,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include "TargetAddressRangeList.h"
|
#include "TargetAddressRangeList.h"
|
||||||
#include "TeamMemory.h"
|
#include "TeamMemory.h"
|
||||||
#include "Tracing.h"
|
#include "Tracing.h"
|
||||||
|
#include "TypeLookupConstraints.h"
|
||||||
#include "UnsupportedLanguage.h"
|
#include "UnsupportedLanguage.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
|
|
||||||
@@ -383,7 +384,8 @@ DwarfImageDebugInfo::GetFunctions(BObjectList<FunctionDebugInfo>& functions)
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
DwarfImageDebugInfo::GetType(GlobalTypeCache* cache,
|
DwarfImageDebugInfo::GetType(GlobalTypeCache* cache,
|
||||||
const BString& name, Type*& _type)
|
const BString& name, const TypeLookupConstraints& constraints,
|
||||||
|
Type*& _type)
|
||||||
{
|
{
|
||||||
int32 registerCount = fArchitecture->CountRegisters();
|
int32 registerCount = fArchitecture->CountRegisters();
|
||||||
const Register* registers = fArchitecture->Registers();
|
const Register* registers = fArchitecture->Registers();
|
||||||
@@ -412,6 +414,15 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache,
|
|||||||
if (typeEntry->IsDeclaration())
|
if (typeEntry->IsDeclaration())
|
||||||
continue;
|
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;
|
BString typeEntryName;
|
||||||
DwarfUtils::GetFullyQualifiedDIEName(typeEntry, typeEntryName);
|
DwarfUtils::GetFullyQualifiedDIEName(typeEntry, typeEntryName);
|
||||||
if (typeEntryName != name)
|
if (typeEntryName != name)
|
||||||
|
|||||||
@@ -51,7 +51,9 @@ public:
|
|||||||
virtual status_t GetFunctions(
|
virtual status_t GetFunctions(
|
||||||
BObjectList<FunctionDebugInfo>& functions);
|
BObjectList<FunctionDebugInfo>& functions);
|
||||||
virtual status_t GetType(GlobalTypeCache* cache,
|
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 AddressSectionType GetAddressSectionType(target_addr_t address);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "SourceLanguageInfo.h"
|
#include "SourceLanguageInfo.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "Tracing.h"
|
#include "Tracing.h"
|
||||||
|
#include "TypeLookupConstraints.h"
|
||||||
#include "ValueLocation.h"
|
#include "ValueLocation.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -314,8 +315,14 @@ DwarfTypeFactory::CreateType(DIEType* typeEntry, DwarfType*& _type)
|
|||||||
|
|
||||||
// If the type entry indicates a declaration only, we try to look the
|
// If the type entry indicates a declaration only, we try to look the
|
||||||
// type up globally first.
|
// 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
|
if (typeEntry->IsDeclaration() && name.Length() > 0
|
||||||
&& fTypeLookup->GetType(fTypeCache, name, globalType)
|
&& fTypeLookup->GetType(fTypeCache, name,
|
||||||
|
constraints, globalType)
|
||||||
== B_OK) {
|
== B_OK) {
|
||||||
DwarfType* globalDwarfType
|
DwarfType* globalDwarfType
|
||||||
= dynamic_cast<DwarfType*>(globalType);
|
= dynamic_cast<DwarfType*>(globalType);
|
||||||
|
|||||||
@@ -50,6 +50,84 @@ struct HasByteStridePredicate {
|
|||||||
} // unnamed namespace
|
} // 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
|
// #pragma mark - DwarfTypeContext
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ class RegisterMap;
|
|||||||
class ValueLocation;
|
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 {
|
class DwarfTypeContext : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
DwarfTypeContext(Architecture* architecture,
|
DwarfTypeContext(Architecture* architecture,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
class BString;
|
class BString;
|
||||||
class Type;
|
class Type;
|
||||||
|
class TypeLookupConstraints;
|
||||||
|
|
||||||
|
|
||||||
enum global_type_cache_scope {
|
enum global_type_cache_scope {
|
||||||
@@ -62,7 +63,9 @@ public:
|
|||||||
virtual ~GlobalTypeLookup();
|
virtual ~GlobalTypeLookup();
|
||||||
|
|
||||||
virtual status_t GetType(GlobalTypeCache* cache,
|
virtual status_t GetType(GlobalTypeCache* cache,
|
||||||
const BString& name, Type*& _type) = 0;
|
const BString& name,
|
||||||
|
const TypeLookupConstraints& constraints,
|
||||||
|
Type*& _type) = 0;
|
||||||
// returns a reference
|
// returns a reference
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -78,11 +78,12 @@ ImageDebugInfo::FinishInit()
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
ImageDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
|
ImageDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
|
||||||
Type*& _type)
|
const TypeLookupConstraints& constraints, Type*& _type)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; SpecificImageDebugInfo* specificInfo
|
for (int32 i = 0; SpecificImageDebugInfo* specificInfo
|
||||||
= fSpecificInfos.ItemAt(i); i++) {
|
= 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)
|
if (error == B_OK || error == B_NO_MEMORY)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class GlobalTypeCache;
|
|||||||
class LocatableFile;
|
class LocatableFile;
|
||||||
class SpecificImageDebugInfo;
|
class SpecificImageDebugInfo;
|
||||||
class Type;
|
class Type;
|
||||||
|
class TypeLookupConstraints;
|
||||||
|
|
||||||
|
|
||||||
class ImageDebugInfo : public BReferenceable {
|
class ImageDebugInfo : public BReferenceable {
|
||||||
@@ -39,7 +40,9 @@ public:
|
|||||||
status_t FinishInit();
|
status_t FinishInit();
|
||||||
|
|
||||||
status_t GetType(GlobalTypeCache* cache,
|
status_t GetType(GlobalTypeCache* cache,
|
||||||
const BString& name, Type*& _type);
|
const BString& name,
|
||||||
|
const TypeLookupConstraints& constraints,
|
||||||
|
Type*& _type);
|
||||||
// returns a reference
|
// returns a reference
|
||||||
AddressSectionType GetAddressSectionType(target_addr_t address)
|
AddressSectionType GetAddressSectionType(target_addr_t address)
|
||||||
const;
|
const;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class SourceLocation;
|
|||||||
class StackFrame;
|
class StackFrame;
|
||||||
class Statement;
|
class Statement;
|
||||||
class Type;
|
class Type;
|
||||||
|
class TypeLookupConstraints;
|
||||||
class ValueLocation;
|
class ValueLocation;
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +43,9 @@ public:
|
|||||||
// returns references
|
// returns references
|
||||||
|
|
||||||
virtual status_t GetType(GlobalTypeCache* cache,
|
virtual status_t GetType(GlobalTypeCache* cache,
|
||||||
const BString& name, Type*& _type) = 0;
|
const BString& name,
|
||||||
|
const TypeLookupConstraints& constraints,
|
||||||
|
Type*& _type) = 0;
|
||||||
// returns a reference
|
// returns a reference
|
||||||
virtual AddressSectionType GetAddressSectionType(target_addr_t address)
|
virtual AddressSectionType GetAddressSectionType(target_addr_t address)
|
||||||
= 0;
|
= 0;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "SpecificImageDebugInfo.h"
|
#include "SpecificImageDebugInfo.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
#include "TypeLookupConstraints.h"
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - FunctionHashDefinition
|
// #pragma mark - FunctionHashDefinition
|
||||||
@@ -362,7 +363,7 @@ TeamDebugInfo::Init()
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
TeamDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
|
TeamDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
|
||||||
Type*& _type)
|
const TypeLookupConstraints& constraints, Type*& _type)
|
||||||
{
|
{
|
||||||
// maybe the type is already cached
|
// maybe the type is already cached
|
||||||
AutoLocker<GlobalTypeCache> cacheLocker(cache);
|
AutoLocker<GlobalTypeCache> cacheLocker(cache);
|
||||||
@@ -390,7 +391,7 @@ TeamDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
|
|||||||
// get the type
|
// get the type
|
||||||
status_t error = B_ENTRY_NOT_FOUND;
|
status_t error = B_ENTRY_NOT_FOUND;
|
||||||
for (int32 i = 0; ImageDebugInfo* imageDebugInfo = images.ItemAt(i); i++) {
|
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) {
|
if (error == B_OK) {
|
||||||
_type = type;
|
_type = type;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ public:
|
|||||||
status_t Init();
|
status_t Init();
|
||||||
|
|
||||||
virtual status_t GetType(GlobalTypeCache* cache,
|
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,
|
status_t LoadImageDebugInfo(const ImageInfo& imageInfo,
|
||||||
LocatableFile* imageFile,
|
LocatableFile* imageFile,
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ enum type_kind {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum compound_type_kind {
|
||||||
|
COMPOUND_TYPE_CLASS,
|
||||||
|
COMPOUND_TYPE_STRUCT,
|
||||||
|
COMPOUND_TYPE_UNION,
|
||||||
|
COMPOUND_TYPE_INTERFACE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum address_type_kind {
|
enum address_type_kind {
|
||||||
DERIVED_TYPE_POINTER,
|
DERIVED_TYPE_POINTER,
|
||||||
DERIVED_TYPE_REFERENCE
|
DERIVED_TYPE_REFERENCE
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Rene Gollent, rene@gollent.com.
|
||||||
|
* 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
|
||||||
Reference in New Issue
Block a user