Skip to content

Commit bdce12a

Browse files
author
Hemant Kulkarni
committed
[Symbolizer]: Add -pretty-print option
Differential Revision: http://reviews.llvm.org/D13671 llvm-svn: 252798
1 parent 932d88c commit bdce12a

File tree

6 files changed

+55
-13
lines changed

6 files changed

+55
-13
lines changed

llvm/docs/CommandGuide/llvm-symbolizer.rst

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ EXAMPLE
5656
5757
foo(int)
5858
/tmp/a.cc:12
59+
$cat addr.txt
60+
0x40054d
61+
$llvm-symbolizer -inlining -print-address -pretty-print -obj=addr.exe < addr.txt
62+
0x40054d: inc at /tmp/x.c:3:3
63+
(inlined by) main at /tmp/x.c:9:0
64+
$llvm-symbolizer -inlining -pretty-print -obj=addr.exe < addr.txt
65+
inc at /tmp/x.c:3:3
66+
(inlined by) main at /tmp/x.c:9:0
5967
6068
OPTIONS
6169
-------
@@ -101,6 +109,10 @@ OPTIONS
101109
.. option:: -print-address
102110
Print address before the source code location. Defaults to false.
103111

112+
.. option:: -pretty-print
113+
Print human readable output. If ``-inlining`` is specified, enclosing scope is
114+
prefixed by (inlined by). Refer to listed examples.
115+
104116
EXIT STATUS
105117
-----------
106118

llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ namespace symbolize {
2727
class DIPrinter {
2828
raw_ostream &OS;
2929
bool PrintFunctionNames;
30+
bool PrintPretty;
31+
void printName(const DILineInfo &Info, bool Inlined);
3032

3133
public:
32-
DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true)
33-
: OS(OS), PrintFunctionNames(PrintFunctionNames) {}
34+
DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true,
35+
bool PrintPretty = false)
36+
: OS(OS), PrintFunctionNames(PrintFunctionNames),
37+
PrintPretty(PrintPretty) {}
3438

3539
DIPrinter &operator<<(const DILineInfo &Info);
3640
DIPrinter &operator<<(const DIInliningInfo &Info);

llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ namespace symbolize {
2424
static const char kDILineInfoBadString[] = "<invalid>";
2525
static const char kBadString[] = "??";
2626

27-
DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) {
27+
void DIPrinter::printName(const DILineInfo &Info, bool Inlined) {
2828
if (PrintFunctionNames) {
2929
std::string FunctionName = Info.FunctionName;
3030
if (FunctionName == kDILineInfoBadString)
3131
FunctionName = kBadString;
32-
OS << FunctionName << "\n";
32+
33+
StringRef Delimiter = (PrintPretty == true) ? " at " : "\n";
34+
StringRef Prefix = (PrintPretty && Inlined) ? " (inlined by) " : "";
35+
OS << Prefix << FunctionName << Delimiter;
3336
}
3437
std::string Filename = Info.FileName;
3538
if (Filename == kDILineInfoBadString)
3639
Filename = kBadString;
3740
OS << Filename << ":" << Info.Line << ":" << Info.Column << "\n";
41+
}
42+
43+
DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) {
44+
printName(Info, false);
3845
return *this;
3946
}
4047

4148
DIPrinter &DIPrinter::operator<<(const DIInliningInfo &Info) {
4249
uint32_t FramesNum = Info.getNumberOfFrames();
43-
if (FramesNum == 0)
44-
return (*this << DILineInfo());
45-
for (uint32_t i = 0; i < FramesNum; i++) {
46-
*this << Info.getFrame(i);
50+
if (FramesNum == 0) {
51+
printName(DILineInfo(), false);
52+
return *this;
4753
}
54+
for (uint32_t i = 0; i < FramesNum; i++)
55+
printName(Info.getFrame(i), i > 0);
4856
return *this;
4957
}
5058

360 Bytes
Binary file not shown.
+14-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
#Source:
22
##include <stdio.h>
3-
#static inline int inc (int *a) {
3+
#static inline int inctwo (int *a) {
44
# printf ("%d\n",(*a)++);
55
# return (*a)++;
66
#}
7+
#static inline int inc (int *a) {
8+
# printf ("%d\n",inctwo(a));
9+
# return (*a)++;
10+
#}
11+
#
712
#
813
#int main () {
914
# int x = 1;
1015
# return inc(&x);
1116
#}
17+
#
1218
#Build as : clang -g -O2 addr.c
1319

14-
RUN: llvm-symbolizer -inlining -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
20+
RUN: llvm-symbolizer -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
21+
RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck --check-prefix="PRETTY" %s
1522

1623
#CHECK: 0x40054d
1724
#CHECK: main
18-
#CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:9:0
25+
#CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
26+
#
27+
#PRETTY: {{[0x]+}}40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3:3
28+
#PRETTY: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7:0
29+
#PRETTY (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14:0
1930

llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ static cl::opt<bool>
7878
ClPrintAddress("print-address", cl::init(false),
7979
cl::desc("Show address before line information"));
8080

81+
static cl::opt<bool>
82+
ClPrettyPrint("pretty-print", cl::init(false),
83+
cl::desc("Make the output more human friendly"));
84+
8185
static bool error(std::error_code ec) {
8286
if (!ec)
8387
return false;
@@ -143,6 +147,7 @@ int main(int argc, char **argv) {
143147
cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n");
144148
LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle,
145149
ClUseRelativeAddress, ClDefaultArch);
150+
146151
for (const auto &hint : ClDsymHint) {
147152
if (sys::path::extension(hint) == ".dSYM") {
148153
Opts.DsymHints.push_back(hint);
@@ -156,13 +161,15 @@ int main(int argc, char **argv) {
156161
bool IsData = false;
157162
std::string ModuleName;
158163
uint64_t ModuleOffset;
159-
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None);
164+
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
165+
ClPrettyPrint);
160166

161167
while (parseCommand(IsData, ModuleName, ModuleOffset)) {
162168
if (ClPrintAddress) {
163169
outs() << "0x";
164170
outs().write_hex(ModuleOffset);
165-
outs() << "\n";
171+
StringRef Delimiter = (ClPrettyPrint == true) ? ": " : "\n";
172+
outs() << Delimiter;
166173
}
167174
if (IsData) {
168175
auto ResOrErr = Symbolizer.symbolizeData(ModuleName, ModuleOffset);

0 commit comments

Comments
 (0)