Skip to content

Commit

Permalink
[lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call lines
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dstenb committed Mar 6, 2023
1 parent 33a13f3 commit 98c3dc3
Show file tree
Hide file tree
Showing 8 changed files with 780 additions and 40 deletions.
19 changes: 10 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2394,12 +2394,12 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
DWARFRangeList func_ranges;
const char *name = nullptr;
const char *mangled = nullptr;
int decl_file = 0;
int decl_line = 0;
int decl_column = 0;
int call_file = 0;
int call_line = 0;
int call_column = 0;
std::optional<int> decl_file;
std::optional<int> decl_line;
std::optional<int> decl_column;
std::optional<int> call_file;
std::optional<int> call_line;
std::optional<int> call_column;
DWARFExpressionList frame_base;

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

FunctionSP func_sp;
std::unique_ptr<Declaration> decl_up;
if (decl_file != 0 || decl_line != 0 || decl_column != 0)
decl_up = std::make_unique<Declaration>(die.GetCU()->GetFile(decl_file),
decl_line, decl_column);
if (decl_file || decl_line || decl_column)
decl_up = std::make_unique<Declaration>(
die.GetCU()->GetFile(decl_file ? *decl_file : 0),
decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);

SymbolFileDWARF *dwarf = die.GetDWARF();
// Supply the type _only_ if it has already been parsed
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ bool DWARFDIE::IsMethod() const {

bool DWARFDIE::GetDIENamesAndRanges(
const char *&name, const char *&mangled, DWARFRangeList &ranges,
int &decl_file, int &decl_line, int &decl_column, int &call_file,
int &call_line, int &call_column,
std::optional<int> &decl_file, std::optional<int> &decl_line,
std::optional<int> &decl_column, std::optional<int> &call_file,
std::optional<int> &call_line, std::optional<int> &call_column,
lldb_private::DWARFExpressionList *frame_base) const {
if (IsValid()) {
return m_die->GetDIENamesAndRanges(
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ class DWARFDIE : public DWARFBaseDIE {
DWARFDIE
GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;

bool
GetDIENamesAndRanges(const char *&name, const char *&mangled,
DWARFRangeList &ranges, int &decl_file, int &decl_line,
int &decl_column, int &call_file, int &call_line,
int &call_column,
lldb_private::DWARFExpressionList *frame_base) const;
bool GetDIENamesAndRanges(
const char *&name, const char *&mangled, DWARFRangeList &ranges,
std::optional<int> &decl_file, std::optional<int> &decl_line,
std::optional<int> &decl_column, std::optional<int> &call_file,
std::optional<int> &call_line, std::optional<int> &call_column,
lldb_private::DWARFExpressionList *frame_base) const;

/// The range of all the children of this DIE.
llvm::iterator_range<child_iterator> children() const;
Expand Down
19 changes: 10 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ static DWARFRangeList GetRangesOrReportError(DWARFUnit &unit,
// DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges attributes.
bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
DWARFUnit *cu, const char *&name, const char *&mangled,
DWARFRangeList &ranges, int &decl_file, int &decl_line, int &decl_column,
int &call_file, int &call_line, int &call_column,
DWARFExpressionList *frame_base) const {
DWARFRangeList &ranges, std::optional<int> &decl_file,
std::optional<int> &decl_line, std::optional<int> &decl_column,
std::optional<int> &call_file, std::optional<int> &call_line,
std::optional<int> &call_column, DWARFExpressionList *frame_base) const {
dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
std::vector<DWARFDIE> dies;
Expand Down Expand Up @@ -315,32 +316,32 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
break;

case DW_AT_decl_file:
if (decl_file == 0)
if (!decl_file)
decl_file = form_value.Unsigned();
break;

case DW_AT_decl_line:
if (decl_line == 0)
if (!decl_line)
decl_line = form_value.Unsigned();
break;

case DW_AT_decl_column:
if (decl_column == 0)
if (!decl_column)
decl_column = form_value.Unsigned();
break;

case DW_AT_call_file:
if (call_file == 0)
if (!call_file)
call_file = form_value.Unsigned();
break;

case DW_AT_call_line:
if (call_line == 0)
if (!call_line)
call_line = form_value.Unsigned();
break;

case DW_AT_call_column:
if (call_column == 0)
if (!call_column)
call_column = form_value.Unsigned();
break;

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class DWARFDebugInfoEntry {

bool GetDIENamesAndRanges(
DWARFUnit *cu, const char *&name, const char *&mangled,
DWARFRangeList &rangeList, int &decl_file, int &decl_line,
int &decl_column, int &call_file, int &call_line, int &call_column,
DWARFRangeList &rangeList, std::optional<int> &decl_file,
std::optional<int> &decl_line, std::optional<int> &decl_column,
std::optional<int> &call_file, std::optional<int> &call_line,
std::optional<int> &call_column,
lldb_private::DWARFExpressionList *frame_base = nullptr) const;

const DWARFAbbreviationDeclaration *
Expand Down
26 changes: 14 additions & 12 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,12 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(
const char *name = nullptr;
const char *mangled_name = nullptr;

int decl_file = 0;
int decl_line = 0;
int decl_column = 0;
int call_file = 0;
int call_line = 0;
int call_column = 0;
std::optional<int> decl_file;
std::optional<int> decl_line;
std::optional<int> decl_column;
std::optional<int> call_file;
std::optional<int> call_line;
std::optional<int> call_column;
if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
decl_line, decl_column, call_file, call_line,
call_column, nullptr)) {
Expand Down Expand Up @@ -1332,16 +1332,18 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(
if (tag != DW_TAG_subprogram &&
(name != nullptr || mangled_name != nullptr)) {
std::unique_ptr<Declaration> decl_up;
if (decl_file != 0 || decl_line != 0 || decl_column != 0)
if (decl_file || decl_line || decl_column)
decl_up = std::make_unique<Declaration>(
comp_unit.GetSupportFiles().GetFileSpecAtIndex(decl_file),
decl_line, decl_column);
comp_unit.GetSupportFiles().GetFileSpecAtIndex(
decl_file ? *decl_file : 0),
decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);

std::unique_ptr<Declaration> call_up;
if (call_file != 0 || call_line != 0 || call_column != 0)
if (call_file || call_line || call_column)
call_up = std::make_unique<Declaration>(
comp_unit.GetSupportFiles().GetFileSpecAtIndex(call_file),
call_line, call_column);
comp_unit.GetSupportFiles().GetFileSpecAtIndex(
call_file ? *call_file : 0),
call_line ? *call_line : 0, call_column ? *call_column : 0);

block->SetInlinedFunctionInfo(name, mangled_name, decl_up.get(),
call_up.get());
Expand Down
Loading

0 comments on commit 98c3dc3

Please sign in to comment.