[lldb/DWARF] Add support for pre-standard GNU call site attributes

Summary:
The code changes are very straight-forward -- just handle both DW_AT_GNU
and DW_AT_call versions of all tags and attributes. There is just one
small gotcha: in the GNU version, DW_AT_low_pc was used both for the
"return pc" and the "call pc" values, depending on whether the tag was
describing a tail call, while the official scheme uses different
attributes for the two things.

Reviewers: vsk, dblaikie

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D80519
This commit is contained in:
Pavel Labath 2020-05-25 14:37:04 +02:00
parent c3902b62e6
commit bddd288826
32 changed files with 123 additions and 96 deletions

View File

@ -396,6 +396,7 @@ static offset_t GetOpcodeDataSize(const DataExtractor &data,
return offset - data_offset;
}
case DW_OP_GNU_entry_value:
case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block
{
uint64_t subexpr_len = data.GetULEB128(&offset);
@ -2522,6 +2523,7 @@ bool DWARFExpression::Evaluate(
stack.push_back(Scalar(value));
} break;
case DW_OP_GNU_entry_value:
case DW_OP_entry_value: {
if (!Evaluate_DW_OP_entry_value(stack, exe_ctx, reg_ctx, opcodes, offset,
error_ptr, log)) {

View File

@ -3601,7 +3601,8 @@ CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) {
CallSiteParameterArray parameters;
for (DWARFDIE child = call_site_die.GetFirstChild(); child.IsValid();
child = child.GetSibling()) {
if (child.Tag() != DW_TAG_call_site_parameter)
if (child.Tag() != DW_TAG_call_site_parameter &&
child.Tag() != DW_TAG_GNU_call_site_parameter)
continue;
llvm::Optional<DWARFExpression> LocationInCallee;
@ -3631,7 +3632,7 @@ CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) {
dw_attr_t attr = attributes.AttributeAtIndex(i);
if (attr == DW_AT_location)
LocationInCallee = parse_simple_location(i);
if (attr == DW_AT_call_value)
if (attr == DW_AT_call_value || attr == DW_AT_GNU_call_site_value)
LocationInCaller = parse_simple_location(i);
}
@ -3648,8 +3649,9 @@ std::vector<std::unique_ptr<lldb_private::CallEdge>>
SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
// Check if the function has a supported call site-related attribute.
// TODO: In the future it may be worthwhile to support call_all_source_calls.
uint64_t has_call_edges =
function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0);
bool has_call_edges =
function_die.GetAttributeValueAsUnsigned(DW_AT_call_all_calls, 0) ||
function_die.GetAttributeValueAsUnsigned(DW_AT_GNU_all_call_sites, 0);
if (!has_call_edges)
return {};
@ -3665,13 +3667,15 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
std::vector<std::unique_ptr<CallEdge>> call_edges;
for (DWARFDIE child = function_die.GetFirstChild(); child.IsValid();
child = child.GetSibling()) {
if (child.Tag() != DW_TAG_call_site)
if (child.Tag() != DW_TAG_call_site && child.Tag() != DW_TAG_GNU_call_site)
continue;
llvm::Optional<DWARFDIE> call_origin;
llvm::Optional<DWARFExpression> call_target;
addr_t return_pc = LLDB_INVALID_ADDRESS;
addr_t call_inst_pc = LLDB_INVALID_ADDRESS;
addr_t low_pc = LLDB_INVALID_ADDRESS;
bool tail_call = false;
DWARFAttributes attributes;
const size_t num_attributes = child.GetAttributes(attributes);
@ -3684,8 +3688,11 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
dw_attr_t attr = attributes.AttributeAtIndex(i);
if (attr == DW_AT_call_tail_call || attr == DW_AT_GNU_tail_call)
tail_call = form_value.Boolean();
// Extract DW_AT_call_origin (the call target's DIE).
if (attr == DW_AT_call_origin) {
if (attr == DW_AT_call_origin || attr == DW_AT_abstract_origin) {
call_origin = form_value.Reference();
if (!call_origin->IsValid()) {
LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}",
@ -3694,6 +3701,9 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
}
}
if (attr == DW_AT_low_pc)
low_pc = form_value.Address();
// Extract DW_AT_call_return_pc (the PC the call returns to) if it's
// available. It should only ever be unavailable for tail call edges, in
// which case use LLDB_INVALID_ADDRESS.
@ -3708,7 +3718,7 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
// Extract DW_AT_call_target (the location of the address of the indirect
// call).
if (attr == DW_AT_call_target) {
if (attr == DW_AT_call_target || attr == DW_AT_GNU_call_site_target) {
if (!DWARFFormValue::IsBlockForm(form_value.Form())) {
LLDB_LOG(log,
"CollectCallEdges: AT_call_target does not have block form");
@ -3723,6 +3733,16 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
child.GetCU());
}
}
if (child.Tag() == DW_TAG_GNU_call_site) {
// In DWARF v4 DW_AT_low_pc is always the address of the instruction after
// the call. For tail calls, approximate the address of the call
// instruction by subtracting 1.
if (tail_call)
call_inst_pc = low_pc - 1;
else
return_pc = low_pc;
}
if (!call_origin && !call_target) {
LLDB_LOG(log, "CollectCallEdges: call site without any call target");
continue;

View File

@ -11,3 +11,7 @@ decorators = [skipIf(archs=no_match(supported_archs)),
lldbinline.MakeInlineTest(__file__, globals(), decorators=decorators,
name="BasicEntryValues_V5",
build_dict=dict(CXXFLAGS_EXTRAS="-O2 -glldb"))
lldbinline.MakeInlineTest(__file__, globals(), decorators=decorators,
name="BasicEntryValues_GNU",
build_dict=dict(CXXFLAGS_EXTRAS="-O2 -ggdb"))

View File

@ -18,8 +18,10 @@ __attribute__((noinline)) void func1(int &sink) {
use<int &>(dummy);
++global;
//% self.filecheck("image lookup -v -a $pc", "main.cpp", "-check-prefix=FUNC1-DESC")
// FUNC1-DESC: name = "sink", type = "int &", location = DW_OP_entry_value
//% prefix = "FUNC1-GNU" if "GNU" in self.name else "FUNC1-V5"
//% self.filecheck("image lookup -v -a $pc", "main.cpp", "-check-prefix="+prefix)
// FUNC1-GNU: name = "sink", type = "int &", location = DW_OP_GNU_entry_value
// FUNC1-V5: name = "sink", type = "int &", location = DW_OP_entry_value
}
__attribute__((noinline)) void func2(int &sink, int x) {

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="AmbiguousTailCallSeq1_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="AmbiguousTailCallSeq1_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="AmbiguousTailCallSeq2_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="AmbiguousTailCallSeq2_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -1,6 +1,6 @@
LD_EXTRAS := -L. -l$(LIB_PREFIX)One -l$(LIB_PREFIX)Two
C_SOURCES := main.c
CFLAGS_EXTRAS := -g -O2 -glldb
CFLAGS_EXTRAS := -O2
include Makefile.rules

View File

@ -1,7 +1,7 @@
DYLIB_NAME := One
DYLIB_C_SOURCES := One.c
DYLIB_ONLY := YES
CFLAGS_EXTRAS := -g -O2 -glldb
CFLAGS_EXTRAS := -O2
LD_EXTRAS := -L. -lTwo
include Makefile.rules

View File

@ -1,6 +1,6 @@
DYLIB_NAME := Two
DYLIB_C_SOURCES := Two.c
DYLIB_ONLY := YES
CFLAGS_EXTRAS := -g -O2 -glldb
CFLAGS_EXTRAS := -O2
include Makefile.rules

View File

@ -1,4 +1,4 @@
C_SOURCES := main.c One.c Two.c
CFLAGS_EXTRAS := -g -O2 -glldb
CFLAGS_EXTRAS := -O2
include Makefile.rules

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="DisambiguateCallSite_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="DisambiguateCallSite_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -2,9 +2,9 @@ volatile int x;
void __attribute__((noinline)) sink() {
x++; //% self.filecheck("bt", "main.cpp", "-implicit-check-not=artificial")
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4 [opt]
// CHECK-NEXT: func2{{.*}} [opt] [artificial]
// CHECK-NEXT: main{{.*}} [opt]
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4
// CHECK-NEXT: func2{{.*}} [artificial]
// CHECK-NEXT: main{{.*}}
}
void __attribute__((noinline)) func2() {

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,11 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
name="DisambiguatePathsToCommonSink_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(),
name="DisambiguatePathsToCommonSink_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -2,17 +2,18 @@ volatile int x;
void __attribute__((noinline)) sink2() {
x++; //% self.filecheck("bt", "main.cpp", "-check-prefix=FROM-FUNC1")
// FROM-FUNC1: frame #0: 0x{{[0-9a-f]+}} a.out`sink{{.*}} at main.cpp:[[@LINE-1]]:{{.*}} [opt]
// FROM-FUNC1-NEXT: sink({{.*}} [opt]
// FROM-FUNC1-NEXT: func1{{.*}} [opt] [artificial]
// FROM-FUNC1-NEXT: main{{.*}} [opt]
// FROM-FUNC1: frame #0: 0x{{[0-9a-f]+}} a.out`sink{{.*}} at main.cpp:[[@LINE-1]]
// FROM-FUNC1-NEXT: sink
// FROM-FUNC1-NEXT: func1
// FROM-FUNC1-SAME: [artificial]
// FROM-FUNC1-NEXT: main
}
void __attribute__((noinline)) sink(bool called_from_main) {
if (called_from_main) {
x++; //% self.filecheck("bt", "main.cpp", "-check-prefix=FROM-MAIN")
// FROM-MAIN: frame #0: 0x{{[0-9a-f]+}} a.out`sink{{.*}} at main.cpp:[[@LINE-1]]:{{.*}} [opt]
// FROM-MAIN-NEXT: main{{.*}} [opt]
// FROM-MAIN: frame #0: 0x{{[0-9a-f]+}} a.out`sink{{.*}} at main.cpp:[[@LINE-1]]
// FROM-MAIN-NEXT: main
} else {
sink2();
}

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="DisambiguateTailCallSeq_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="DisambiguateTailCallSeq_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -2,10 +2,10 @@ volatile int x;
void __attribute__((noinline)) sink() {
x++; //% self.filecheck("bt", "main.cpp", "-implicit-check-not=artificial")
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4 [opt]
// CHECK-NEXT: func3{{.*}} [opt] [artificial]
// CHECK-NEXT: func1{{.*}} [opt] [artificial]
// CHECK-NEXT: main{{.*}} [opt]
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4
// CHECK-NEXT: func3{{.*}} [artificial]
// CHECK-NEXT: func1{{.*}} [artificial]
// CHECK-NEXT: main{{.*}}
}
void __attribute__((noinline)) func3() { sink(); /* tail */ }

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="InliningAndTailCalls_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="InliningAndTailCalls_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -2,9 +2,9 @@ volatile int x;
void __attribute__((noinline)) tail_call_sink() {
x++; //% self.filecheck("bt", "main.cpp", "-check-prefix=TAIL-CALL-SINK")
// TAIL-CALL-SINK: frame #0: 0x{{[0-9a-f]+}} a.out`tail_call_sink() at main.cpp:[[@LINE-1]]:4 [opt]
// TAIL-CALL-SINK-NEXT: func3{{.*}} [opt] [artificial]
// TAIL-CALL-SINK-NEXT: main{{.*}} [opt]
// TAIL-CALL-SINK: frame #0: 0x{{[0-9a-f]+}} a.out`tail_call_sink() at main.cpp:[[@LINE-1]]:4
// TAIL-CALL-SINK-NEXT: func3{{.*}} [artificial]
// TAIL-CALL-SINK-NEXT: main{{.*}}
// TODO: The backtrace should include inlinable_function_which_tail_calls.
}
@ -19,10 +19,10 @@ void __attribute__((noinline)) func3() {
void __attribute__((always_inline)) inline_sink() {
x++; //% self.filecheck("bt", "main.cpp", "-check-prefix=INLINE-SINK")
// INLINE-SINK: frame #0: 0x{{[0-9a-f]+}} a.out`func2() [inlined] inline_sink() at main.cpp:[[@LINE-1]]:4 [opt]
// INLINE-SINK-NEXT: func2{{.*}} [opt]
// INLINE-SINK-NEXT: func1{{.*}} [opt] [artificial]
// INLINE-SINK-NEXT: main{{.*}} [opt]
// INLINE-SINK: frame #0: 0x{{[0-9a-f]+}} a.out`func2() [inlined] inline_sink() at main.cpp:[[@LINE-1]]:4
// INLINE-SINK-NEXT: func2{{.*}}
// INLINE-SINK-NEXT: func1{{.*}} [artificial]
// INLINE-SINK-NEXT: main{{.*}}
}
void __attribute__((noinline)) func2() { inline_sink(); /* inlined */ }

View File

@ -1,4 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
CXXFLAGS_EXTRAS := -O2
include Makefile.rules

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,11 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
name="ArtificialFrameStepOutMessage_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(),
name="ArtificialFrameStepOutMessage_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -3,8 +3,8 @@ volatile int x;
void __attribute__((noinline)) sink() {
x++; //% self.filecheck("finish", "main.cpp", "-implicit-check-not=artificial")
// CHECK: stop reason = step out
// CHECK-NEXT: Stepped out past: frame #1: 0x{{[0-9a-f]+}} a.out`func3{{.*}} [opt] [artificial]
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`func2{{.*}} [opt]
// CHECK-NEXT: Stepped out past: frame #1: 0x{{[0-9a-f]+}} a.out`func3{{.*}} [artificial]
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`func2{{.*}}
}
void __attribute__((noinline)) func3() { sink(); /* tail */ }

View File

@ -1,4 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
CXXFLAGS_EXTRAS := -O2
include Makefile.rules

View File

@ -1,4 +0,0 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -g -O2 -glldb
include Makefile.rules

View File

@ -1,6 +1,9 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators
lldbinline.MakeInlineTest(__file__, globals(),
[decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])])
decorators = [decorators.skipUnlessHasCallSiteInfo,
decorators.skipIf(dwarf_version=['<', '4'])]
lldbinline.MakeInlineTest(__file__, globals(), name="UnambiguousTailCalls_V5",
build_dict=dict(CFLAGS_EXTRAS="-O2 -glldb"), decorators=decorators)
lldbinline.MakeInlineTest(__file__, globals(), name="UnambiguousTailCalls_GNU",
build_dict=dict(CFLAGS_EXTRAS="-O2 -ggdb"), decorators=decorators)

View File

@ -2,11 +2,13 @@ volatile int x;
void __attribute__((noinline)) sink() {
x++; //% self.filecheck("bt", "main.cpp", "-implicit-check-not=artificial")
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4 [opt]
// CHECK-NEXT: frame #1: 0x{{[0-9a-f]+}} a.out`func3() at main.cpp:14:3 [opt] [artificial]
// CHECK-NEXT: frame #2: 0x{{[0-9a-f]+}} a.out`func2() {{.*}} [opt]
// CHECK-NEXT: frame #3: 0x{{[0-9a-f]+}} a.out`func1() at main.cpp:23:3 [opt] [artificial]
// CHECK-NEXT: frame #4: 0x{{[0-9a-f]+}} a.out`main{{.*}} [opt]
// CHECK: frame #0: 0x{{[0-9a-f]+}} a.out`sink() at main.cpp:[[@LINE-1]]:4
// CHECK-NEXT: frame #1: 0x{{[0-9a-f]+}} a.out`func3() at main.cpp:16:3
// CHECK-SAME: [artificial]
// CHECK-NEXT: frame #2: 0x{{[0-9a-f]+}} a.out`func2()
// CHECK-NEXT: frame #3: 0x{{[0-9a-f]+}} a.out`func1() at main.cpp:25:3
// CHECK-SAME: [artificial]
// CHECK-NEXT: frame #4: 0x{{[0-9a-f]+}} a.out`main
}
void __attribute__((noinline)) func3() {