Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit e0d2d7f

Browse files
author
Alexey Samsonov
committed
[llvm-symbolizer] Print file/line for a PC even if there is no DIE describing it.
This is important for symbolizing executables with debug info in unavailable .dwo files. Even if all DIE entries are missing, we can still symbolize an address: function name can be fetched from symbol table, and file/line info can be fetched from line table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206665 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1c60993 commit e0d2d7f

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

lib/DebugInfo/DWARFContext.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,18 +545,32 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
545545

546546
DIInliningInfo DWARFContext::getInliningInfoForAddress(uint64_t Address,
547547
DILineInfoSpecifier Specifier) {
548+
DIInliningInfo InliningInfo;
549+
548550
DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
549551
if (!CU)
550-
return DIInliningInfo();
552+
return InliningInfo;
551553

554+
const DWARFLineTable *LineTable = nullptr;
555+
const bool NeedsAbsoluteFilePath =
556+
Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
552557
const DWARFDebugInfoEntryInlinedChain &InlinedChain =
553558
CU->getInlinedChainForAddress(Address);
554-
if (InlinedChain.DIEs.size() == 0)
555-
return DIInliningInfo();
559+
if (InlinedChain.DIEs.size() == 0) {
560+
// If there is no DIE for address (e.g. it is in unavailable .dwo file),
561+
// try to at least get file/line info from symbol table.
562+
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
563+
DILineInfo Frame;
564+
LineTable = getLineTableForCompileUnit(CU);
565+
if (getFileLineInfoForCompileUnit(CU, LineTable, Address,
566+
NeedsAbsoluteFilePath, Frame)) {
567+
InliningInfo.addFrame(Frame);
568+
}
569+
}
570+
return InliningInfo;
571+
}
556572

557-
DIInliningInfo InliningInfo;
558573
uint32_t CallFile = 0, CallLine = 0, CallColumn = 0;
559-
const DWARFLineTable *LineTable = nullptr;
560574
for (uint32_t i = 0, n = InlinedChain.DIEs.size(); i != n; i++) {
561575
const DWARFDebugInfoEntryMinimal &FunctionDIE = InlinedChain.DIEs[i];
562576
DILineInfo Frame;
@@ -566,16 +580,13 @@ DIInliningInfo DWARFContext::getInliningInfoForAddress(uint64_t Address,
566580
Frame.FunctionName = Name;
567581
}
568582
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
569-
const bool NeedsAbsoluteFilePath =
570-
Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
571583
if (i == 0) {
572584
// For the topmost frame, initialize the line table of this
573585
// compile unit and fetch file/line info from it.
574586
LineTable = getLineTableForCompileUnit(CU);
575587
// For the topmost routine, get file/line info from line table.
576588
getFileLineInfoForCompileUnit(CU, LineTable, Address,
577-
NeedsAbsoluteFilePath,
578-
Frame);
589+
NeedsAbsoluteFilePath, Frame);
579590
} else {
580591
// Otherwise, use call file, call line and call column from
581592
// previous DIE in inlined chain.
9.35 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int f(int a, int b) {
2+
return a + b;
3+
}
4+
5+
int g(int a) {
6+
return a + 1;
7+
}
8+
9+
10+
int main() {
11+
return f(2, g(2));
12+
}
13+
14+
// Built with Clang 3.5.0:
15+
// $ mkdir -p /tmp/dbginfo
16+
// $ cp llvm-symbolizer-dwo-test.cc /tmp/dbginfo
17+
// $ cd /tmp/dbginfo
18+
// $ clang -gsplit-dwarf llvm-symbolizer-dwo-test.cc

test/DebugInfo/llvm-symbolizer.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN: echo "\"%p/Inputs/dwarfdump-test3.elf-x86-64 space\" 0x633" >> %t.input
88
RUN: echo "%p/Inputs/macho-universal 0x1f84" >> %t.input
99
RUN: echo "%p/Inputs/macho-universal:i386 0x1f67" >> %t.input
1010
RUN: echo "%p/Inputs/macho-universal:x86_64 0x100000f05" >> %t.input
11+
RUN: echo "%p/Inputs/llvm-symbolizer-dwo-test 0x400514" >> %t.input
1112

1213
RUN: llvm-symbolizer --functions --inlining --demangle=false \
1314
RUN: --default-arch=i386 < %t.input | FileCheck %s
@@ -48,6 +49,9 @@ CHECK: main
4849
CHECK: _Z3inci
4950
CHECK: _Z3inci
5051

52+
CHECK: main
53+
CHECK-NEXT: llvm-symbolizer-dwo-test.cc:11
54+
5155
RUN: echo "unexisting-file 0x1234" > %t.input2
5256
RUN: llvm-symbolizer < %t.input2
5357

0 commit comments

Comments
 (0)