Skip to content

Commit b7af1bf

Browse files
committed
[lldb/DWARF] Simplify DWARFDebugInfoEntry::LookupAddress
Summary: This method was doing a lot more than it's only caller needed (DWARFDIE::LookupDeepestBlock) needed, so I inline it into the caller, and remove any code which is not actually used. This includes code for searching for the deepest function, and the code for working around incomplete DW_AT_low_pc/high_pc attributes on a compile unit DIE (modern compiler get this right, and this method is called on function DIEs anyway). This also improves our llvm consistency, as llvm::DWARFDebugInfoEntry is just a very simple struct with no nontrivial logic. Reviewers: JDevlieghere, aprantl Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D72920
1 parent 8248190 commit b7af1bf

File tree

3 files changed

+55
-223
lines changed

3 files changed

+55
-223
lines changed

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

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,64 @@ DWARFDIE::GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const {
140140
}
141141

142142
DWARFDIE
143-
DWARFDIE::LookupDeepestBlock(lldb::addr_t file_addr) const {
144-
if (IsValid()) {
145-
SymbolFileDWARF *dwarf = GetDWARF();
146-
DWARFUnit *cu = GetCU();
147-
DWARFDebugInfoEntry *function_die = nullptr;
148-
DWARFDebugInfoEntry *block_die = nullptr;
149-
if (m_die->LookupAddress(file_addr, cu, &function_die, &block_die)) {
150-
if (block_die && block_die != function_die) {
151-
if (cu->ContainsDIEOffset(block_die->GetOffset()))
152-
return DWARFDIE(cu, block_die);
153-
else
154-
return DWARFDIE(dwarf->DebugInfo()->GetUnit(DIERef(
155-
cu->GetSymbolFileDWARF().GetDwoNum(),
156-
cu->GetDebugSection(), block_die->GetOffset())),
157-
block_die);
143+
DWARFDIE::LookupDeepestBlock(lldb::addr_t address) const {
144+
if (!IsValid())
145+
return DWARFDIE();
146+
147+
DWARFDIE result;
148+
bool check_children = false;
149+
bool match_addr_range = false;
150+
switch (Tag()) {
151+
case DW_TAG_class_type:
152+
case DW_TAG_namespace:
153+
case DW_TAG_structure_type:
154+
case DW_TAG_common_block:
155+
check_children = true;
156+
break;
157+
case DW_TAG_compile_unit:
158+
case DW_TAG_module:
159+
case DW_TAG_catch_block:
160+
case DW_TAG_subprogram:
161+
case DW_TAG_try_block:
162+
case DW_TAG_partial_unit:
163+
match_addr_range = true;
164+
break;
165+
case DW_TAG_lexical_block:
166+
case DW_TAG_inlined_subroutine:
167+
check_children = true;
168+
match_addr_range = true;
169+
break;
170+
default:
171+
break;
172+
}
173+
174+
if (match_addr_range) {
175+
DWARFRangeList ranges;
176+
if (m_die->GetAttributeAddressRanges(m_cu, ranges,
177+
/*check_hi_lo_pc=*/true) &&
178+
ranges.FindEntryThatContains(address)) {
179+
check_children = true;
180+
switch (Tag()) {
181+
default:
182+
break;
183+
184+
case DW_TAG_inlined_subroutine: // Inlined Function
185+
case DW_TAG_lexical_block: // Block { } in code
186+
result = *this;
187+
break;
158188
}
189+
} else {
190+
check_children = false;
159191
}
160192
}
161-
return DWARFDIE();
193+
194+
if (check_children) {
195+
for (DWARFDIE child = GetFirstChild(); child; child = child.GetSibling()) {
196+
if (DWARFDIE child_result = child.LookupDeepestBlock(address))
197+
return child_result;
198+
}
199+
}
200+
return result;
162201
}
163202

164203
const char *DWARFDIE::GetMangledName() const {

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

Lines changed: 0 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -993,209 +993,6 @@ DWARFDebugInfoEntry::GetQualifiedName(DWARFUnit *cu,
993993
return storage.c_str();
994994
}
995995

996-
bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address, DWARFUnit *cu,
997-
DWARFDebugInfoEntry **function_die,
998-
DWARFDebugInfoEntry **block_die) {
999-
bool found_address = false;
1000-
if (m_tag) {
1001-
bool check_children = false;
1002-
bool match_addr_range = false;
1003-
// printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset,
1004-
// DW_TAG_value_to_name(tag), address);
1005-
switch (m_tag) {
1006-
case DW_TAG_array_type:
1007-
break;
1008-
case DW_TAG_class_type:
1009-
check_children = true;
1010-
break;
1011-
case DW_TAG_entry_point:
1012-
case DW_TAG_enumeration_type:
1013-
case DW_TAG_formal_parameter:
1014-
case DW_TAG_imported_declaration:
1015-
case DW_TAG_label:
1016-
break;
1017-
case DW_TAG_lexical_block:
1018-
check_children = true;
1019-
match_addr_range = true;
1020-
break;
1021-
case DW_TAG_member:
1022-
case DW_TAG_pointer_type:
1023-
case DW_TAG_reference_type:
1024-
break;
1025-
case DW_TAG_compile_unit:
1026-
match_addr_range = true;
1027-
break;
1028-
case DW_TAG_string_type:
1029-
break;
1030-
case DW_TAG_structure_type:
1031-
check_children = true;
1032-
break;
1033-
case DW_TAG_subroutine_type:
1034-
case DW_TAG_typedef:
1035-
case DW_TAG_union_type:
1036-
case DW_TAG_unspecified_parameters:
1037-
case DW_TAG_variant:
1038-
break;
1039-
case DW_TAG_common_block:
1040-
check_children = true;
1041-
break;
1042-
case DW_TAG_common_inclusion:
1043-
case DW_TAG_inheritance:
1044-
break;
1045-
case DW_TAG_inlined_subroutine:
1046-
check_children = true;
1047-
match_addr_range = true;
1048-
break;
1049-
case DW_TAG_module:
1050-
match_addr_range = true;
1051-
break;
1052-
case DW_TAG_ptr_to_member_type:
1053-
case DW_TAG_set_type:
1054-
case DW_TAG_subrange_type:
1055-
case DW_TAG_with_stmt:
1056-
case DW_TAG_access_declaration:
1057-
case DW_TAG_base_type:
1058-
break;
1059-
case DW_TAG_catch_block:
1060-
match_addr_range = true;
1061-
break;
1062-
case DW_TAG_const_type:
1063-
case DW_TAG_constant:
1064-
case DW_TAG_enumerator:
1065-
case DW_TAG_file_type:
1066-
case DW_TAG_friend:
1067-
case DW_TAG_namelist:
1068-
case DW_TAG_namelist_item:
1069-
case DW_TAG_packed_type:
1070-
break;
1071-
case DW_TAG_subprogram:
1072-
match_addr_range = true;
1073-
break;
1074-
case DW_TAG_template_type_parameter:
1075-
case DW_TAG_template_value_parameter:
1076-
case DW_TAG_GNU_template_parameter_pack:
1077-
case DW_TAG_thrown_type:
1078-
break;
1079-
case DW_TAG_try_block:
1080-
match_addr_range = true;
1081-
break;
1082-
case DW_TAG_variant_part:
1083-
case DW_TAG_variable:
1084-
case DW_TAG_volatile_type:
1085-
case DW_TAG_dwarf_procedure:
1086-
case DW_TAG_restrict_type:
1087-
case DW_TAG_interface_type:
1088-
break;
1089-
case DW_TAG_namespace:
1090-
check_children = true;
1091-
break;
1092-
case DW_TAG_imported_module:
1093-
case DW_TAG_unspecified_type:
1094-
break;
1095-
case DW_TAG_partial_unit:
1096-
match_addr_range = true;
1097-
break;
1098-
case DW_TAG_imported_unit:
1099-
case DW_TAG_shared_type:
1100-
default:
1101-
break;
1102-
}
1103-
1104-
if (match_addr_range) {
1105-
dw_addr_t lo_pc =
1106-
GetAttributeValueAsAddress(cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
1107-
if (lo_pc != LLDB_INVALID_ADDRESS) {
1108-
dw_addr_t hi_pc = GetAttributeHighPC(cu, lo_pc, LLDB_INVALID_ADDRESS);
1109-
if (hi_pc != LLDB_INVALID_ADDRESS) {
1110-
// printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ",
1111-
// m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1112-
if ((lo_pc <= address) && (address < hi_pc)) {
1113-
found_address = true;
1114-
// puts("***MATCH***");
1115-
switch (m_tag) {
1116-
case DW_TAG_compile_unit: // File
1117-
case DW_TAG_partial_unit: // File
1118-
check_children =
1119-
((function_die != nullptr) || (block_die != nullptr));
1120-
break;
1121-
1122-
case DW_TAG_subprogram: // Function
1123-
if (function_die)
1124-
*function_die = this;
1125-
check_children = (block_die != nullptr);
1126-
break;
1127-
1128-
case DW_TAG_inlined_subroutine: // Inlined Function
1129-
case DW_TAG_lexical_block: // Block { } in code
1130-
if (block_die) {
1131-
*block_die = this;
1132-
check_children = true;
1133-
}
1134-
break;
1135-
1136-
default:
1137-
check_children = true;
1138-
break;
1139-
}
1140-
}
1141-
} else {
1142-
// Compile units may not have a valid high/low pc when there
1143-
// are address gaps in subroutines so we must always search
1144-
// if there is no valid high and low PC.
1145-
check_children =
1146-
(m_tag == DW_TAG_compile_unit || m_tag == DW_TAG_partial_unit) &&
1147-
((function_die != nullptr) || (block_die != nullptr));
1148-
}
1149-
} else {
1150-
DWARFRangeList ranges;
1151-
if (GetAttributeAddressRanges(cu, ranges, /*check_hi_lo_pc*/ false) &&
1152-
ranges.FindEntryThatContains(address)) {
1153-
found_address = true;
1154-
// puts("***MATCH***");
1155-
switch (m_tag) {
1156-
case DW_TAG_compile_unit: // File
1157-
case DW_TAG_partial_unit: // File
1158-
check_children =
1159-
((function_die != nullptr) || (block_die != nullptr));
1160-
break;
1161-
1162-
case DW_TAG_subprogram: // Function
1163-
if (function_die)
1164-
*function_die = this;
1165-
check_children = (block_die != nullptr);
1166-
break;
1167-
1168-
case DW_TAG_inlined_subroutine: // Inlined Function
1169-
case DW_TAG_lexical_block: // Block { } in code
1170-
if (block_die) {
1171-
*block_die = this;
1172-
check_children = true;
1173-
}
1174-
break;
1175-
1176-
default:
1177-
check_children = true;
1178-
break;
1179-
}
1180-
} else {
1181-
check_children = false;
1182-
}
1183-
}
1184-
}
1185-
1186-
if (check_children) {
1187-
// printf("checking children\n");
1188-
DWARFDebugInfoEntry *child = GetFirstChild();
1189-
while (child) {
1190-
if (child->LookupAddress(address, cu, function_die, block_die))
1191-
return true;
1192-
child = child->GetSibling();
1193-
}
1194-
}
1195-
}
1196-
return found_address;
1197-
}
1198-
1199996
lldb::offset_t DWARFDebugInfoEntry::GetFirstAttributeOffset() const {
1200997
return GetOffset() + llvm::getULEB128Size(m_abbr_idx);
1201998
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ class DWARFDebugInfoEntry {
5050
bool Extract(const lldb_private::DWARFDataExtractor &data,
5151
const DWARFUnit *cu, lldb::offset_t *offset_ptr);
5252

53-
bool LookupAddress(const dw_addr_t address, DWARFUnit *cu,
54-
DWARFDebugInfoEntry **function_die,
55-
DWARFDebugInfoEntry **block_die);
56-
5753
size_t GetAttributes(const DWARFUnit *cu,
5854
DWARFAttributes &attrs,
5955
uint32_t curr_depth = 0)

0 commit comments

Comments
 (0)