Skip to content

Commit 98c3dc3

Browse files
committed
[lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines
In an upcoming patch, D142556, Clang is proposed to be changed to emit line locations that are inlined at line 0. This clashed with the behavior of GetDIENamesAndRanges() which used 0 as a default value to determine if file, line or column numbers had been set. Users of that function then checked for any non-0 values when setting up the call site: if (call_file != 0 || call_line != 0 || call_column != 0) [...] which did not work with the Clang change since all three values then could be 0. This changes the function to use std::optional to catch non-set values instead. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D142552
1 parent 33a13f3 commit 98c3dc3

File tree

8 files changed

+780
-40
lines changed

8 files changed

+780
-40
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,12 +2394,12 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
23942394
DWARFRangeList func_ranges;
23952395
const char *name = nullptr;
23962396
const char *mangled = nullptr;
2397-
int decl_file = 0;
2398-
int decl_line = 0;
2399-
int decl_column = 0;
2400-
int call_file = 0;
2401-
int call_line = 0;
2402-
int call_column = 0;
2397+
std::optional<int> decl_file;
2398+
std::optional<int> decl_line;
2399+
std::optional<int> decl_column;
2400+
std::optional<int> call_file;
2401+
std::optional<int> call_line;
2402+
std::optional<int> call_column;
24032403
DWARFExpressionList frame_base;
24042404

24052405
const dw_tag_t tag = die.Tag();
@@ -2429,9 +2429,10 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
24292429

24302430
FunctionSP func_sp;
24312431
std::unique_ptr<Declaration> decl_up;
2432-
if (decl_file != 0 || decl_line != 0 || decl_column != 0)
2433-
decl_up = std::make_unique<Declaration>(die.GetCU()->GetFile(decl_file),
2434-
decl_line, decl_column);
2432+
if (decl_file || decl_line || decl_column)
2433+
decl_up = std::make_unique<Declaration>(
2434+
die.GetCU()->GetFile(decl_file ? *decl_file : 0),
2435+
decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);
24352436

24362437
SymbolFileDWARF *dwarf = die.GetDWARF();
24372438
// Supply the type _only_ if it has already been parsed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,9 @@ bool DWARFDIE::IsMethod() const {
439439

440440
bool DWARFDIE::GetDIENamesAndRanges(
441441
const char *&name, const char *&mangled, DWARFRangeList &ranges,
442-
int &decl_file, int &decl_line, int &decl_column, int &call_file,
443-
int &call_line, int &call_column,
442+
std::optional<int> &decl_file, std::optional<int> &decl_line,
443+
std::optional<int> &decl_column, std::optional<int> &call_file,
444+
std::optional<int> &call_line, std::optional<int> &call_column,
444445
lldb_private::DWARFExpressionList *frame_base) const {
445446
if (IsValid()) {
446447
return m_die->GetDIENamesAndRanges(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ class DWARFDIE : public DWARFBaseDIE {
8383
DWARFDIE
8484
GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;
8585

86-
bool
87-
GetDIENamesAndRanges(const char *&name, const char *&mangled,
88-
DWARFRangeList &ranges, int &decl_file, int &decl_line,
89-
int &decl_column, int &call_file, int &call_line,
90-
int &call_column,
91-
lldb_private::DWARFExpressionList *frame_base) const;
86+
bool GetDIENamesAndRanges(
87+
const char *&name, const char *&mangled, DWARFRangeList &ranges,
88+
std::optional<int> &decl_file, std::optional<int> &decl_line,
89+
std::optional<int> &decl_column, std::optional<int> &call_file,
90+
std::optional<int> &call_line, std::optional<int> &call_column,
91+
lldb_private::DWARFExpressionList *frame_base) const;
9292

9393
/// The range of all the children of this DIE.
9494
llvm::iterator_range<child_iterator> children() const;

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ static DWARFRangeList GetRangesOrReportError(DWARFUnit &unit,
234234
// DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges attributes.
235235
bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
236236
DWARFUnit *cu, const char *&name, const char *&mangled,
237-
DWARFRangeList &ranges, int &decl_file, int &decl_line, int &decl_column,
238-
int &call_file, int &call_line, int &call_column,
239-
DWARFExpressionList *frame_base) const {
237+
DWARFRangeList &ranges, std::optional<int> &decl_file,
238+
std::optional<int> &decl_line, std::optional<int> &decl_column,
239+
std::optional<int> &call_file, std::optional<int> &call_line,
240+
std::optional<int> &call_column, DWARFExpressionList *frame_base) const {
240241
dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
241242
dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
242243
std::vector<DWARFDIE> dies;
@@ -315,32 +316,32 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
315316
break;
316317

317318
case DW_AT_decl_file:
318-
if (decl_file == 0)
319+
if (!decl_file)
319320
decl_file = form_value.Unsigned();
320321
break;
321322

322323
case DW_AT_decl_line:
323-
if (decl_line == 0)
324+
if (!decl_line)
324325
decl_line = form_value.Unsigned();
325326
break;
326327

327328
case DW_AT_decl_column:
328-
if (decl_column == 0)
329+
if (!decl_column)
329330
decl_column = form_value.Unsigned();
330331
break;
331332

332333
case DW_AT_call_file:
333-
if (call_file == 0)
334+
if (!call_file)
334335
call_file = form_value.Unsigned();
335336
break;
336337

337338
case DW_AT_call_line:
338-
if (call_line == 0)
339+
if (!call_line)
339340
call_line = form_value.Unsigned();
340341
break;
341342

342343
case DW_AT_call_column:
343-
if (call_column == 0)
344+
if (!call_column)
344345
call_column = form_value.Unsigned();
345346
break;
346347

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ class DWARFDebugInfoEntry {
103103

104104
bool GetDIENamesAndRanges(
105105
DWARFUnit *cu, const char *&name, const char *&mangled,
106-
DWARFRangeList &rangeList, int &decl_file, int &decl_line,
107-
int &decl_column, int &call_file, int &call_line, int &call_column,
106+
DWARFRangeList &rangeList, std::optional<int> &decl_file,
107+
std::optional<int> &decl_line, std::optional<int> &decl_column,
108+
std::optional<int> &call_file, std::optional<int> &call_line,
109+
std::optional<int> &call_column,
108110
lldb_private::DWARFExpressionList *frame_base = nullptr) const;
109111

110112
const DWARFAbbreviationDeclaration *

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,12 +1284,12 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(
12841284
const char *name = nullptr;
12851285
const char *mangled_name = nullptr;
12861286

1287-
int decl_file = 0;
1288-
int decl_line = 0;
1289-
int decl_column = 0;
1290-
int call_file = 0;
1291-
int call_line = 0;
1292-
int call_column = 0;
1287+
std::optional<int> decl_file;
1288+
std::optional<int> decl_line;
1289+
std::optional<int> decl_column;
1290+
std::optional<int> call_file;
1291+
std::optional<int> call_line;
1292+
std::optional<int> call_column;
12931293
if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
12941294
decl_line, decl_column, call_file, call_line,
12951295
call_column, nullptr)) {
@@ -1332,16 +1332,18 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(
13321332
if (tag != DW_TAG_subprogram &&
13331333
(name != nullptr || mangled_name != nullptr)) {
13341334
std::unique_ptr<Declaration> decl_up;
1335-
if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1335+
if (decl_file || decl_line || decl_column)
13361336
decl_up = std::make_unique<Declaration>(
1337-
comp_unit.GetSupportFiles().GetFileSpecAtIndex(decl_file),
1338-
decl_line, decl_column);
1337+
comp_unit.GetSupportFiles().GetFileSpecAtIndex(
1338+
decl_file ? *decl_file : 0),
1339+
decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);
13391340

13401341
std::unique_ptr<Declaration> call_up;
1341-
if (call_file != 0 || call_line != 0 || call_column != 0)
1342+
if (call_file || call_line || call_column)
13421343
call_up = std::make_unique<Declaration>(
1343-
comp_unit.GetSupportFiles().GetFileSpecAtIndex(call_file),
1344-
call_line, call_column);
1344+
comp_unit.GetSupportFiles().GetFileSpecAtIndex(
1345+
call_file ? *call_file : 0),
1346+
call_line ? *call_line : 0, call_column ? *call_column : 0);
13451347

13461348
block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(),
13471349
call_up.get());

0 commit comments

Comments
 (0)