Skip to content

Commit

Permalink
[llvm-symbolizer] Add -print-address option
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D13518

llvm-svn: 250086
  • Loading branch information
Hemant Kulkarni committed Oct 12, 2015
1 parent b0fe4eb commit 80f82fb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/docs/CommandGuide/llvm-symbolizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ OPTIONS
location, look for the debug info at the .dSYM path provided via the
``-dsym-hint`` flag. This flag can be used multiple times.

.. option:: -print-address
Print address before the source code location. Defaults to false.

EXIT STATUS
-----------
Expand Down
Binary file added llvm/test/tools/llvm-symbolizer/Inputs/addr.exe
Binary file not shown.
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-symbolizer/Inputs/addr.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x40054d
19 changes: 19 additions & 0 deletions llvm/test/tools/llvm-symbolizer/sym.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Source:
##include <stdio.h>
#static inline int inc (int *a) {
# printf ("%d\n",(*a)++);
# return (*a)++;
#}
#
#int main () {
# int x = 1;
# return inc(&x);
#}
#Build as : clang -g -O2 addr.c

RUN: llvm-symbolizer -inlining -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s

#CHECK: 0x40054d
#CHECK: main
#CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:9:0

8 changes: 8 additions & 0 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ static cl::list<std::string>
ClDsymHint("dsym-hint", cl::ZeroOrMore,
cl::desc("Path to .dSYM bundles to search for debug info for the "
"object files"));
static cl::opt<bool>
ClPrintAddress("print-address", cl::init(false),
cl::desc("Show address before line information"));

static bool parseCommand(bool &IsData, std::string &ModuleName,
uint64_t &ModuleOffset) {
Expand Down Expand Up @@ -152,6 +155,11 @@ int main(int argc, char **argv) {
std::string Result =
IsData ? Symbolizer.symbolizeData(ModuleName, ModuleOffset)
: Symbolizer.symbolizeCode(ModuleName, ModuleOffset);
if (ClPrintAddress) {
outs() << "0x";
outs().write_hex(ModuleOffset);
outs() << "\n";
}
outs() << Result << "\n";
outs().flush();
}
Expand Down

0 comments on commit 80f82fb

Please sign in to comment.