Refactor DIE name resolution.
Factor out DwarfUtils::GetDIETypeName(). Make use of it for both Subprogram parameters and modified types in general. Resolves TODO.
This commit is contained in:
@@ -301,7 +301,6 @@ DwarfTypeFactory::CreateType(DIEType* typeEntry, DwarfType*& _type)
|
|||||||
// try the type cache first
|
// try the type cache first
|
||||||
BString name;
|
BString name;
|
||||||
DwarfUtils::GetFullyQualifiedDIEName(typeEntry, name);
|
DwarfUtils::GetFullyQualifiedDIEName(typeEntry, name);
|
||||||
// TODO: The DIE may not have a name (e.g. pointer and reference types don't).
|
|
||||||
|
|
||||||
TypeLookupConstraints constraints(
|
TypeLookupConstraints constraints(
|
||||||
dwarf_tag_to_type_kind(typeEntry->Tag()));
|
dwarf_tag_to_type_kind(typeEntry->Tag()));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
* Copyright 2011-2012, Rene Gollent, [email protected].
|
* Copyright 2011-2013, Rene Gollent, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -39,6 +39,67 @@ DwarfUtils::GetDIEName(const DebugInfoEntry* entry, BString& _name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
DwarfUtils::GetDIETypeName(const DebugInfoEntry* entry, BString& _name)
|
||||||
|
{
|
||||||
|
const DIEType* type = dynamic_cast<const DIEType*>(entry);
|
||||||
|
if (type == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const DIEModifiedType* modifiedType = dynamic_cast<const DIEModifiedType*>(
|
||||||
|
type);
|
||||||
|
BString typeName;
|
||||||
|
BString modifier;
|
||||||
|
|
||||||
|
if (modifiedType != NULL) {
|
||||||
|
const DIEType* baseType = type;
|
||||||
|
while ((modifiedType = dynamic_cast<const DIEModifiedType*>(
|
||||||
|
baseType)) != NULL) {
|
||||||
|
switch (modifiedType->Tag()) {
|
||||||
|
case DW_TAG_pointer_type:
|
||||||
|
modifier.Prepend("*");
|
||||||
|
break;
|
||||||
|
case DW_TAG_reference_type:
|
||||||
|
modifier.Prepend("&");
|
||||||
|
break;
|
||||||
|
case DW_TAG_const_type:
|
||||||
|
modifier.Prepend(" const ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
baseType = modifiedType->GetType();
|
||||||
|
}
|
||||||
|
type = baseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the parameter has no type associated,
|
||||||
|
// then it's the unspecified type.
|
||||||
|
if (type == NULL)
|
||||||
|
typeName = "void";
|
||||||
|
else
|
||||||
|
GetFullyQualifiedDIEName(type, typeName);
|
||||||
|
|
||||||
|
if (modifier.Length() > 0) {
|
||||||
|
if (modifier[modifier.Length() - 1] == ' ')
|
||||||
|
modifier.Truncate(modifier.Length() - 1);
|
||||||
|
|
||||||
|
// if the modifier has a leading const, treat it
|
||||||
|
// as the degenerate case and prepend it to the
|
||||||
|
// type name since that's the more typically used
|
||||||
|
// representation in source
|
||||||
|
if (modifier[0] == ' ') {
|
||||||
|
typeName.Prepend("const ");
|
||||||
|
modifier.Remove(0, 7);
|
||||||
|
}
|
||||||
|
typeName += modifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
_name = typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ void
|
/*static*/ void
|
||||||
DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name)
|
DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name)
|
||||||
{
|
{
|
||||||
@@ -62,9 +123,13 @@ DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we found no name for this entry whatsoever, abort.
|
if (name == NULL) {
|
||||||
if (name == NULL)
|
if (dynamic_cast<const DIEModifiedType*>(entry) != NULL)
|
||||||
|
GetDIETypeName(entry, _name);
|
||||||
|
|
||||||
|
// we found no name for this entry whatsoever, abort.
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
generatedName = name;
|
generatedName = name;
|
||||||
|
|
||||||
@@ -98,51 +163,7 @@ DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name)
|
|||||||
BString paramName;
|
BString paramName;
|
||||||
BString modifier;
|
BString modifier;
|
||||||
DIEType* type = parameter->GetType();
|
DIEType* type = parameter->GetType();
|
||||||
if (DIEModifiedType* modifiedType = dynamic_cast<DIEModifiedType*>(
|
GetDIETypeName(type, paramName);
|
||||||
type)) {
|
|
||||||
DIEType* baseType = type;
|
|
||||||
while ((modifiedType = dynamic_cast<DIEModifiedType*>(
|
|
||||||
baseType)) != NULL) {
|
|
||||||
switch (modifiedType->Tag()) {
|
|
||||||
case DW_TAG_pointer_type:
|
|
||||||
modifier.Prepend("*");
|
|
||||||
break;
|
|
||||||
case DW_TAG_reference_type:
|
|
||||||
modifier.Prepend("&");
|
|
||||||
break;
|
|
||||||
case DW_TAG_const_type:
|
|
||||||
modifier.Prepend(" const ");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
baseType = modifiedType->GetType();
|
|
||||||
}
|
|
||||||
type = baseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the parameter has no type associated,
|
|
||||||
// then it's the unspecified type.
|
|
||||||
if (type == NULL)
|
|
||||||
paramName = "void";
|
|
||||||
else
|
|
||||||
GetFullyQualifiedDIEName(type, paramName);
|
|
||||||
|
|
||||||
if (modifier.Length() > 0) {
|
|
||||||
if (modifier[modifier.Length() - 1] == ' ')
|
|
||||||
modifier.Truncate(modifier.Length() - 1);
|
|
||||||
|
|
||||||
// if the modifier has a leading const, treat it
|
|
||||||
// as the degenerate case and prepend it to the
|
|
||||||
// type name since that's the more typically used
|
|
||||||
// representation in source
|
|
||||||
if (modifier[0] == ' ') {
|
|
||||||
paramName.Prepend("const ");
|
|
||||||
modifier.Remove(0, 7);
|
|
||||||
}
|
|
||||||
paramName += modifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstParameter)
|
if (firstParameter)
|
||||||
firstParameter = false;
|
firstParameter = false;
|
||||||
@@ -158,7 +179,6 @@ DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name)
|
|||||||
generatedName += "void";
|
generatedName += "void";
|
||||||
generatedName += ")";
|
generatedName += ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
_name = generatedName;
|
_name = generatedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Copyright 2013, Rene Gollent, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef DWARF_UTILS_H
|
#ifndef DWARF_UTILS_H
|
||||||
@@ -17,6 +18,8 @@ class DwarfUtils {
|
|||||||
public:
|
public:
|
||||||
static void GetDIEName(const DebugInfoEntry* entry,
|
static void GetDIEName(const DebugInfoEntry* entry,
|
||||||
BString& _name);
|
BString& _name);
|
||||||
|
static void GetDIETypeName(const DebugInfoEntry* entry,
|
||||||
|
BString& _name);
|
||||||
static void GetFullDIEName(const DebugInfoEntry* entry,
|
static void GetFullDIEName(const DebugInfoEntry* entry,
|
||||||
BString& _name);
|
BString& _name);
|
||||||
static void GetFullyQualifiedDIEName(
|
static void GetFullyQualifiedDIEName(
|
||||||
|
|||||||
Reference in New Issue
Block a user