[BOLT][NFC] Fix debug info printouts for inlined functions
Summary: While printing debug info for instructions, we should use line tables from the corresponding DWARF CU which could be different from the containing function CU in case of inlined instructions. (cherry picked from FBD28908324)
This commit is contained in:
parent
65d227c035
commit
7bccf8d25d
|
@ -1689,25 +1689,31 @@ void BinaryContext::printInstruction(raw_ostream &OS,
|
|||
|
||||
MIB->printAnnotations(Instruction, OS);
|
||||
|
||||
const DWARFDebugLine::LineTable *LineTable =
|
||||
Function && opts::PrintDebugInfo ? Function->getDWARFLineTable()
|
||||
: nullptr;
|
||||
|
||||
if (LineTable) {
|
||||
if (opts::PrintDebugInfo) {
|
||||
DebugLineTableRowRef RowRef =
|
||||
DebugLineTableRowRef::fromSMLoc(Instruction.getLoc());
|
||||
|
||||
if (RowRef != DebugLineTableRowRef::NULL_ROW) {
|
||||
const DWARFDebugLine::LineTable *LineTable;
|
||||
if (Function && Function->getDWARFUnit() &&
|
||||
Function->getDWARFUnit()->getOffset() == RowRef.DwCompileUnitIndex) {
|
||||
LineTable = Function->getDWARFLineTable();
|
||||
} else {
|
||||
LineTable = DwCtx->getLineTableForUnit(
|
||||
DwCtx->getCompileUnitForOffset(RowRef.DwCompileUnitIndex));
|
||||
}
|
||||
assert(LineTable &&
|
||||
"line table expected for instruction with debug info");
|
||||
|
||||
const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
|
||||
StringRef FileName = "";
|
||||
if (Optional<const char *> FName =
|
||||
dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
|
||||
FileName = *FName;
|
||||
OS << " # debug line " << FileName << ":" << Row.Line;
|
||||
|
||||
if (Row.Column) {
|
||||
if (Row.Column)
|
||||
OS << ":" << Row.Column;
|
||||
}
|
||||
if (Row.Discriminator)
|
||||
OS << " discriminator:" << Row.Discriminator;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
5
bolt/test/X86/Inputs/inline-foo.c
Normal file
5
bolt/test/X86/Inputs/inline-foo.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void foo() {
|
||||
puts("Hello world!\n");
|
||||
}
|
5
bolt/test/X86/Inputs/inline-main.c
Normal file
5
bolt/test/X86/Inputs/inline-main.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
extern void foo();
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
19
bolt/test/X86/inline-debug-info.test
Normal file
19
bolt/test/X86/inline-debug-info.test
Normal file
|
@ -0,0 +1,19 @@
|
|||
## Check that BOLT correctly prints and updates debug info for inlined
|
||||
## functions.
|
||||
|
||||
# REQUIRES: system-linux
|
||||
|
||||
# RUN: %host_cc %cflags -O1 -g %p/Inputs/inline-main.c %p/Inputs/inline-foo.c \
|
||||
# RUN: -o %t.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.exe -update-debug-sections -print-debug-info \
|
||||
# RUN: -print-only=main -print-after-lowering -force-inline=foo -o %t.bolt \
|
||||
# RUN: | FileCheck %s
|
||||
|
||||
## The call to puts() should come from inline-foo.c:
|
||||
# CHECK: callq puts@PLT # debug line {{.*}}inline-foo.c:4:3
|
||||
|
||||
# RUN: llvm-objdump --disassemble-symbols=main -d --line-numbers %t.bolt \
|
||||
# RUN: | FileCheck %s -check-prefix=CHECK-OBJDUMP
|
||||
|
||||
## Dump of main() should include debug info from inline-foo.c after inlining:
|
||||
# CHECK-OBJDUMP: inline-foo.c:4
|
|
@ -57,6 +57,7 @@ tools = [
|
|||
ToolSubst('yaml2obj', unresolved='fatal'),
|
||||
ToolSubst('llvm-mc', unresolved='fatal'),
|
||||
ToolSubst('llvm-nm', unresolved='fatal'),
|
||||
ToolSubst('llvm-objdump', unresolved='fatal'),
|
||||
ToolSubst('llvm-strip', unresolved='fatal'),
|
||||
ToolSubst('link_fdata', command=FindTool('link_fdata.sh'), unresolved='fatal'),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue