Skip to content

Commit 19a3c30

Browse files
committed
Simplify GetName+AppendTypeName by DWARFDIE
In D61502#1503247 @clayborg suggested that DWARFUnit *+dw_offset_t can be now replaced by DWARFDIE. It is moved from DWARFDebugInfoEntry to DWARFDIE as noted by @clayborg. I have also removed return type as (1) it was wrong in one case and (2) no existing caller used the return type. I also refactored the deep nesting noted by @JDevlieghere. Differential Revision: https://reviews.llvm.org/D62211 llvm-svn: 361463
1 parent 617cdc5 commit 19a3c30

File tree

4 files changed

+131
-168
lines changed

4 files changed

+131
-168
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,130 @@ const char *DWARFDIE::GetQualifiedName(std::string &storage) const {
182182
return nullptr;
183183
}
184184

185+
// GetName
186+
//
187+
// Get value of the DW_AT_name attribute and place that value into the supplied
188+
// stream object. If the DIE is a NULL object "NULL" is placed into the stream,
189+
// and if no DW_AT_name attribute exists for the DIE then nothing is printed.
190+
void DWARFDIE::GetName(Stream &s) const {
191+
if (!IsValid())
192+
return;
193+
if (GetDIE()->IsNULL()) {
194+
s.PutCString("NULL");
195+
return;
196+
}
197+
const char *name = GetDIE()->GetAttributeValueAsString(GetCU(), DW_AT_name, nullptr, true);
198+
if (!name)
199+
return;
200+
s.PutCString(name);
201+
}
202+
203+
// AppendTypeName
204+
//
205+
// Follows the type name definition down through all needed tags to end up with
206+
// a fully qualified type name and dump the results to the supplied stream.
207+
// This is used to show the name of types given a type identifier.
208+
void DWARFDIE::AppendTypeName(Stream &s) const {
209+
if (!IsValid())
210+
return;
211+
if (GetDIE()->IsNULL()) {
212+
s.PutCString("NULL");
213+
return;
214+
}
215+
if (const char *name = GetPubname()) {
216+
s.PutCString(name);
217+
return;
218+
}
219+
switch (Tag()) {
220+
case DW_TAG_array_type:
221+
break; // print out a "[]" after printing the full type of the element
222+
// below
223+
case DW_TAG_base_type:
224+
s.PutCString("base ");
225+
break;
226+
case DW_TAG_class_type:
227+
s.PutCString("class ");
228+
break;
229+
case DW_TAG_const_type:
230+
s.PutCString("const ");
231+
break;
232+
case DW_TAG_enumeration_type:
233+
s.PutCString("enum ");
234+
break;
235+
case DW_TAG_file_type:
236+
s.PutCString("file ");
237+
break;
238+
case DW_TAG_interface_type:
239+
s.PutCString("interface ");
240+
break;
241+
case DW_TAG_packed_type:
242+
s.PutCString("packed ");
243+
break;
244+
case DW_TAG_pointer_type:
245+
break; // print out a '*' after printing the full type below
246+
case DW_TAG_ptr_to_member_type:
247+
break; // print out a '*' after printing the full type below
248+
case DW_TAG_reference_type:
249+
break; // print out a '&' after printing the full type below
250+
case DW_TAG_restrict_type:
251+
s.PutCString("restrict ");
252+
break;
253+
case DW_TAG_set_type:
254+
s.PutCString("set ");
255+
break;
256+
case DW_TAG_shared_type:
257+
s.PutCString("shared ");
258+
break;
259+
case DW_TAG_string_type:
260+
s.PutCString("string ");
261+
break;
262+
case DW_TAG_structure_type:
263+
s.PutCString("struct ");
264+
break;
265+
case DW_TAG_subrange_type:
266+
s.PutCString("subrange ");
267+
break;
268+
case DW_TAG_subroutine_type:
269+
s.PutCString("function ");
270+
break;
271+
case DW_TAG_thrown_type:
272+
s.PutCString("thrown ");
273+
break;
274+
case DW_TAG_union_type:
275+
s.PutCString("union ");
276+
break;
277+
case DW_TAG_unspecified_type:
278+
s.PutCString("unspecified ");
279+
break;
280+
case DW_TAG_volatile_type:
281+
s.PutCString("volatile ");
282+
break;
283+
default:
284+
return;
285+
}
286+
287+
// Follow the DW_AT_type if possible
288+
if (DWARFDIE next_die = GetAttributeValueAsReferenceDIE(DW_AT_type))
289+
next_die.AppendTypeName(s);
290+
291+
switch (Tag()) {
292+
case DW_TAG_array_type:
293+
s.PutCString("[]");
294+
break;
295+
case DW_TAG_pointer_type:
296+
s.PutChar('*');
297+
break;
298+
case DW_TAG_ptr_to_member_type:
299+
s.PutChar('*');
300+
break;
301+
case DW_TAG_reference_type:
302+
s.PutChar('&');
303+
break;
304+
default:
305+
break;
306+
}
307+
}
308+
185309
lldb_private::Type *DWARFDIE::ResolveType() const {
186310
if (IsValid())
187311
return GetDWARF()->ResolveType(*this, true);

lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class DWARFDIE : public DWARFBaseDIE {
3434

3535
const char *GetQualifiedName(std::string &storage) const;
3636

37+
using DWARFBaseDIE::GetName;
38+
void GetName(lldb_private::Stream &s) const;
39+
40+
void AppendTypeName(lldb_private::Stream &s) const;
41+
3742
lldb_private::Type *ResolveType() const;
3843

3944
// Resolve a type by UID using this DIE's DWARF file

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp

Lines changed: 2 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,13 @@ void DWARFDebugInfoEntry::DumpAttribute(
693693
DWARFDIE abstract_die = form_value.Reference();
694694
form_value.Dump(s);
695695
// *ostrm_ptr << HEX32 << abstract_die.GetOffset() << " ( ";
696-
GetName(abstract_die.GetCU(), abstract_die.GetOffset(), s);
696+
abstract_die.GetName(s);
697697
} break;
698698

699699
case DW_AT_type: {
700700
DWARFDIE type_die = form_value.Reference();
701701
s.PutCString(" ( ");
702-
AppendTypeName(type_die.GetCU(), type_die.GetOffset(), s);
702+
type_die.AppendTypeName(s);
703703
s.PutCString(" )");
704704
} break;
705705

@@ -1038,166 +1038,6 @@ const char *DWARFDebugInfoEntry::GetPubname(const DWARFUnit *cu) const {
10381038
return name;
10391039
}
10401040

1041-
// GetName
1042-
//
1043-
// Get value of the DW_AT_name attribute for a debug information entry that
1044-
// exists at offset "die_offset" and place that value into the supplied stream
1045-
// object. If the DIE is a NULL object "NULL" is placed into the stream, and if
1046-
// no DW_AT_name attribute exists for the DIE then nothing is printed.
1047-
bool DWARFDebugInfoEntry::GetName(const DWARFUnit *cu,
1048-
const dw_offset_t die_offset, Stream &s) {
1049-
if (cu == NULL) {
1050-
s.PutCString("NULL");
1051-
return false;
1052-
}
1053-
1054-
DWARFDebugInfoEntry die;
1055-
lldb::offset_t offset = die_offset;
1056-
if (die.Extract(cu, &offset)) {
1057-
if (die.IsNULL()) {
1058-
s.PutCString("NULL");
1059-
return true;
1060-
} else {
1061-
const char *name =
1062-
die.GetAttributeValueAsString(cu, DW_AT_name, nullptr, true);
1063-
if (name) {
1064-
s.PutCString(name);
1065-
return true;
1066-
}
1067-
}
1068-
}
1069-
return false;
1070-
}
1071-
1072-
// AppendTypeName
1073-
//
1074-
// Follows the type name definition down through all needed tags to end up with
1075-
// a fully qualified type name and dump the results to the supplied stream.
1076-
// This is used to show the name of types given a type identifier.
1077-
bool DWARFDebugInfoEntry::AppendTypeName(const DWARFUnit *cu,
1078-
const dw_offset_t die_offset,
1079-
Stream &s) {
1080-
if (cu == NULL) {
1081-
s.PutCString("NULL");
1082-
return false;
1083-
}
1084-
1085-
DWARFDebugInfoEntry die;
1086-
lldb::offset_t offset = die_offset;
1087-
if (die.Extract(cu, &offset)) {
1088-
if (die.IsNULL()) {
1089-
s.PutCString("NULL");
1090-
return true;
1091-
} else {
1092-
const char *name = die.GetPubname(cu);
1093-
if (name)
1094-
s.PutCString(name);
1095-
else {
1096-
bool result = true;
1097-
const DWARFAbbreviationDeclaration *abbrevDecl =
1098-
die.GetAbbreviationDeclarationPtr(cu, offset);
1099-
1100-
if (abbrevDecl == NULL)
1101-
return false;
1102-
1103-
switch (abbrevDecl->Tag()) {
1104-
case DW_TAG_array_type:
1105-
break; // print out a "[]" after printing the full type of the element
1106-
// below
1107-
case DW_TAG_base_type:
1108-
s.PutCString("base ");
1109-
break;
1110-
case DW_TAG_class_type:
1111-
s.PutCString("class ");
1112-
break;
1113-
case DW_TAG_const_type:
1114-
s.PutCString("const ");
1115-
break;
1116-
case DW_TAG_enumeration_type:
1117-
s.PutCString("enum ");
1118-
break;
1119-
case DW_TAG_file_type:
1120-
s.PutCString("file ");
1121-
break;
1122-
case DW_TAG_interface_type:
1123-
s.PutCString("interface ");
1124-
break;
1125-
case DW_TAG_packed_type:
1126-
s.PutCString("packed ");
1127-
break;
1128-
case DW_TAG_pointer_type:
1129-
break; // print out a '*' after printing the full type below
1130-
case DW_TAG_ptr_to_member_type:
1131-
break; // print out a '*' after printing the full type below
1132-
case DW_TAG_reference_type:
1133-
break; // print out a '&' after printing the full type below
1134-
case DW_TAG_restrict_type:
1135-
s.PutCString("restrict ");
1136-
break;
1137-
case DW_TAG_set_type:
1138-
s.PutCString("set ");
1139-
break;
1140-
case DW_TAG_shared_type:
1141-
s.PutCString("shared ");
1142-
break;
1143-
case DW_TAG_string_type:
1144-
s.PutCString("string ");
1145-
break;
1146-
case DW_TAG_structure_type:
1147-
s.PutCString("struct ");
1148-
break;
1149-
case DW_TAG_subrange_type:
1150-
s.PutCString("subrange ");
1151-
break;
1152-
case DW_TAG_subroutine_type:
1153-
s.PutCString("function ");
1154-
break;
1155-
case DW_TAG_thrown_type:
1156-
s.PutCString("thrown ");
1157-
break;
1158-
case DW_TAG_union_type:
1159-
s.PutCString("union ");
1160-
break;
1161-
case DW_TAG_unspecified_type:
1162-
s.PutCString("unspecified ");
1163-
break;
1164-
case DW_TAG_volatile_type:
1165-
s.PutCString("volatile ");
1166-
break;
1167-
default:
1168-
return false;
1169-
}
1170-
1171-
// Follow the DW_AT_type if possible
1172-
DWARFFormValue form_value;
1173-
if (die.GetAttributeValue(cu, DW_AT_type, form_value)) {
1174-
DWARFDIE next_die = form_value.Reference();
1175-
result = AppendTypeName(next_die.GetCU(), next_die.GetOffset(), s);
1176-
}
1177-
1178-
switch (abbrevDecl->Tag()) {
1179-
case DW_TAG_array_type:
1180-
s.PutCString("[]");
1181-
break;
1182-
case DW_TAG_pointer_type:
1183-
s.PutChar('*');
1184-
break;
1185-
case DW_TAG_ptr_to_member_type:
1186-
s.PutChar('*');
1187-
break;
1188-
case DW_TAG_reference_type:
1189-
s.PutChar('&');
1190-
break;
1191-
default:
1192-
break;
1193-
}
1194-
return result;
1195-
}
1196-
}
1197-
}
1198-
return false;
1199-
}
1200-
12011041
// BuildAddressRangeTable
12021042
void DWARFDebugInfoEntry::BuildAddressRangeTable(
12031043
const DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const {

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ class DWARFDebugInfoEntry {
126126

127127
const char *GetPubname(const DWARFUnit *cu) const;
128128

129-
static bool GetName(const DWARFUnit *cu, const dw_offset_t die_offset,
130-
lldb_private::Stream &s);
131-
132-
static bool AppendTypeName(const DWARFUnit *cu, const dw_offset_t die_offset,
133-
lldb_private::Stream &s);
134-
135129
const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const;
136130

137131
const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes,

0 commit comments

Comments
 (0)