Skip to content

Commit 539ec56

Browse files
Merge pull request #8088 from felipepiovezan/felipe/cherry-picks-debugnames1
[Cherry-pick] Upstream patches related to DWARF5 and debug_names
2 parents 333e312 + 136879a commit 539ec56

File tree

6 files changed

+115
-251
lines changed

6 files changed

+115
-251
lines changed

lldb/source/Interpreter/OptionArgParser.cpp

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ lldb::addr_t OptionArgParser::ToAddress(const ExecutionContext *exe_ctx,
168168
std::optional<lldb::addr_t>
169169
OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
170170
Status *error_ptr) {
171-
bool error_set = false;
172171
if (s.empty()) {
173172
if (error_ptr)
174173
error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
@@ -223,52 +222,40 @@ OptionArgParser::DoToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s,
223222
if (error_ptr)
224223
error_ptr->Clear();
225224
return addr;
226-
} else {
227-
if (error_ptr) {
228-
error_set = true;
229-
error_ptr->SetErrorStringWithFormat(
230-
"address expression \"%s\" resulted in a value whose type "
231-
"can't be converted to an address: %s",
232-
s.str().c_str(), valobj_sp->GetTypeName().GetCString());
233-
}
234225
}
226+
if (error_ptr)
227+
error_ptr->SetErrorStringWithFormat(
228+
"address expression \"%s\" resulted in a value whose type "
229+
"can't be converted to an address: %s",
230+
s.str().c_str(), valobj_sp->GetTypeName().GetCString());
231+
return {};
232+
}
235233

236-
} else {
237-
// Since the compiler can't handle things like "main + 12" we should try to
238-
// do this for now. The compiler doesn't like adding offsets to function
239-
// pointer types.
240-
static RegularExpression g_symbol_plus_offset_regex(
241-
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
242-
243-
llvm::SmallVector<llvm::StringRef, 4> matches;
244-
if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
245-
uint64_t offset = 0;
246-
std::string name = matches[1].str();
247-
std::string sign = matches[2].str();
248-
std::string str_offset = matches[3].str();
249-
if (!llvm::StringRef(str_offset).getAsInteger(0, offset)) {
250-
Status error;
251-
addr = ToAddress(exe_ctx, name.c_str(), LLDB_INVALID_ADDRESS, &error);
252-
if (addr != LLDB_INVALID_ADDRESS) {
253-
if (sign[0] == '+')
254-
return addr + offset;
255-
else
256-
return addr - offset;
257-
}
234+
// Since the compiler can't handle things like "main + 12" we should try to
235+
// do this for now. The compiler doesn't like adding offsets to function
236+
// pointer types.
237+
static RegularExpression g_symbol_plus_offset_regex(
238+
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
239+
240+
llvm::SmallVector<llvm::StringRef, 4> matches;
241+
if (g_symbol_plus_offset_regex.Execute(sref, &matches)) {
242+
uint64_t offset = 0;
243+
llvm::StringRef name = matches[1];
244+
llvm::StringRef sign = matches[2];
245+
llvm::StringRef str_offset = matches[3];
246+
if (!str_offset.getAsInteger(0, offset)) {
247+
Status error;
248+
addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
249+
if (addr != LLDB_INVALID_ADDRESS) {
250+
if (sign[0] == '+')
251+
return addr + offset;
252+
return addr - offset;
258253
}
259254
}
260-
261-
if (error_ptr) {
262-
error_set = true;
263-
error_ptr->SetErrorStringWithFormat(
264-
"address expression \"%s\" evaluation failed", s.str().c_str());
265-
}
266255
}
267256

268-
if (error_ptr) {
269-
if (!error_set)
270-
error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
271-
s.str().c_str());
272-
}
257+
if (error_ptr)
258+
error_ptr->SetErrorStringWithFormat(
259+
"address expression \"%s\" evaluation failed", s.str().c_str());
273260
return {};
274261
}

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

Lines changed: 9 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &data,
5050
lldbassert(abbr_idx <= UINT16_MAX);
5151
m_abbr_idx = abbr_idx;
5252

53-
// assert (fixed_form_sizes); // For best performance this should be
54-
// specified!
55-
5653
if (m_abbr_idx == 0) {
5754
m_tag = llvm::dwarf::DW_TAG_null;
5855
m_has_children = false;
5956
return true; // NULL debug tag entry
6057
}
6158

62-
lldb::offset_t offset = *offset_ptr;
6359
const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
6460
if (abbrevDecl == nullptr) {
6561
cu->GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
@@ -74,137 +70,18 @@ bool DWARFDebugInfoEntry::Extract(const DWARFDataExtractor &data,
7470
m_tag = abbrevDecl->getTag();
7571
m_has_children = abbrevDecl->hasChildren();
7672
// Skip all data in the .debug_info or .debug_types for the attributes
77-
dw_form_t form;
7873
for (const auto &attribute : abbrevDecl->attributes()) {
79-
form = attribute.Form;
80-
std::optional<uint8_t> fixed_skip_size =
81-
DWARFFormValue::GetFixedSize(form, cu);
82-
if (fixed_skip_size)
83-
offset += *fixed_skip_size;
84-
else {
85-
bool form_is_indirect = false;
86-
do {
87-
form_is_indirect = false;
88-
uint32_t form_size = 0;
89-
switch (form) {
90-
// Blocks if inlined data that have a length field and the data bytes
91-
// inlined in the .debug_info/.debug_types
92-
case DW_FORM_exprloc:
93-
case DW_FORM_block:
94-
form_size = data.GetULEB128(&offset);
95-
break;
96-
case DW_FORM_block1:
97-
form_size = data.GetU8_unchecked(&offset);
98-
break;
99-
case DW_FORM_block2:
100-
form_size = data.GetU16_unchecked(&offset);
101-
break;
102-
case DW_FORM_block4:
103-
form_size = data.GetU32_unchecked(&offset);
104-
break;
105-
106-
// Inlined NULL terminated C-strings
107-
case DW_FORM_string:
108-
data.GetCStr(&offset);
109-
break;
110-
111-
// Compile unit address sized values
112-
case DW_FORM_addr:
113-
form_size = cu->GetAddressByteSize();
114-
break;
115-
case DW_FORM_ref_addr:
116-
if (cu->GetVersion() <= 2)
117-
form_size = cu->GetAddressByteSize();
118-
else
119-
form_size = 4;
120-
break;
74+
if (DWARFFormValue::SkipValue(attribute.Form, data, offset_ptr, cu))
75+
continue;
12176

122-
// 0 sized form
123-
case DW_FORM_flag_present:
124-
form_size = 0;
125-
break;
126-
127-
// 1 byte values
128-
case DW_FORM_addrx1:
129-
case DW_FORM_data1:
130-
case DW_FORM_flag:
131-
case DW_FORM_ref1:
132-
case DW_FORM_strx1:
133-
form_size = 1;
134-
break;
135-
136-
// 2 byte values
137-
case DW_FORM_addrx2:
138-
case DW_FORM_data2:
139-
case DW_FORM_ref2:
140-
case DW_FORM_strx2:
141-
form_size = 2;
142-
break;
143-
144-
// 3 byte values
145-
case DW_FORM_addrx3:
146-
case DW_FORM_strx3:
147-
form_size = 3;
148-
break;
149-
150-
// 4 byte values
151-
case DW_FORM_addrx4:
152-
case DW_FORM_data4:
153-
case DW_FORM_ref4:
154-
case DW_FORM_strx4:
155-
form_size = 4;
156-
break;
157-
158-
// 8 byte values
159-
case DW_FORM_data8:
160-
case DW_FORM_ref8:
161-
case DW_FORM_ref_sig8:
162-
form_size = 8;
163-
break;
164-
165-
// signed or unsigned LEB 128 values
166-
case DW_FORM_addrx:
167-
case DW_FORM_loclistx:
168-
case DW_FORM_rnglistx:
169-
case DW_FORM_sdata:
170-
case DW_FORM_udata:
171-
case DW_FORM_ref_udata:
172-
case DW_FORM_GNU_addr_index:
173-
case DW_FORM_GNU_str_index:
174-
case DW_FORM_strx:
175-
data.Skip_LEB128(&offset);
176-
break;
177-
178-
case DW_FORM_indirect:
179-
form_is_indirect = true;
180-
form = static_cast<dw_form_t>(data.GetULEB128(&offset));
181-
break;
182-
183-
case DW_FORM_strp:
184-
case DW_FORM_line_strp:
185-
case DW_FORM_sec_offset:
186-
data.GetU32(&offset);
187-
break;
188-
189-
case DW_FORM_implicit_const:
190-
form_size = 0;
191-
break;
192-
193-
default:
194-
cu->GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
195-
"[{0:x16}]: Unsupported DW_FORM_{1:x}, please file a bug "
196-
"and "
197-
"attach the file at the start of this error message",
198-
(uint64_t)m_offset, (unsigned)form);
199-
*offset_ptr = m_offset;
200-
return false;
201-
}
202-
offset += form_size;
203-
204-
} while (form_is_indirect);
205-
}
77+
cu->GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
78+
"[{0:x16}]: Unsupported DW_FORM_{1:x}, please file a bug "
79+
"and "
80+
"attach the file at the start of this error message",
81+
(uint64_t)m_offset, (unsigned)attribute.Form);
82+
*offset_ptr = m_offset;
83+
return false;
20684
}
207-
*offset_ptr = offset;
20885
return true;
20986
}
21087

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DWARFDeclContext.h"
10+
#include "llvm/Support/raw_ostream.h"
1011

1112
using namespace lldb_private::dwarf;
1213
using namespace lldb_private::plugin::dwarf;
1314

15+
/// Returns the name of `entry` if it has one, or the appropriate "anonymous
16+
/// {namespace, class, struct, union}".
17+
static const char *GetName(DWARFDeclContext::Entry entry) {
18+
if (entry.name != nullptr)
19+
return entry.name;
20+
if (entry.tag == DW_TAG_namespace)
21+
return "(anonymous namespace)";
22+
if (entry.tag == DW_TAG_class_type)
23+
return "(anonymous class)";
24+
if (entry.tag == DW_TAG_structure_type)
25+
return "(anonymous struct)";
26+
if (entry.tag == DW_TAG_union_type)
27+
return "(anonymous union)";
28+
return "(anonymous)";
29+
}
30+
1431
const char *DWARFDeclContext::GetQualifiedName() const {
1532
if (m_qualified_name.empty()) {
1633
// The declaration context array for a class named "foo" in namespace
@@ -26,26 +43,10 @@ const char *DWARFDeclContext::GetQualifiedName() const {
2643
m_qualified_name.append(m_entries[0].name);
2744
}
2845
} else {
29-
collection::const_reverse_iterator pos;
30-
collection::const_reverse_iterator begin = m_entries.rbegin();
31-
collection::const_reverse_iterator end = m_entries.rend();
32-
for (pos = begin; pos != end; ++pos) {
33-
if (pos != begin)
34-
m_qualified_name.append("::");
35-
if (pos->name == nullptr) {
36-
if (pos->tag == DW_TAG_namespace)
37-
m_qualified_name.append("(anonymous namespace)");
38-
else if (pos->tag == DW_TAG_class_type)
39-
m_qualified_name.append("(anonymous class)");
40-
else if (pos->tag == DW_TAG_structure_type)
41-
m_qualified_name.append("(anonymous struct)");
42-
else if (pos->tag == DW_TAG_union_type)
43-
m_qualified_name.append("(anonymous union)");
44-
else
45-
m_qualified_name.append("(anonymous)");
46-
} else
47-
m_qualified_name.append(pos->name);
48-
}
46+
llvm::raw_string_ostream string_stream(m_qualified_name);
47+
llvm::interleave(
48+
llvm::reverse(m_entries), string_stream,
49+
[&](auto entry) { string_stream << GetName(entry); }, "::");
4950
}
5051
}
5152
}

0 commit comments

Comments
 (0)