[llvm-symbolizer] Add -print-address option
authorHemant Kulkarni <khemant@codeaurora.org>
Mon, 12 Oct 2015 19:26:44 +0000 (19:26 +0000)
committerHemant Kulkarni <khemant@codeaurora.org>
Mon, 12 Oct 2015 19:26:44 +0000 (19:26 +0000)
Differential Revision: http://reviews.llvm.org/D13518

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250086 91177308-0d34-0410-b5e6-96231b3b80d8

docs/CommandGuide/llvm-symbolizer.rst
test/tools/llvm-symbolizer/Inputs/addr.exe [new file with mode: 0755]
test/tools/llvm-symbolizer/Inputs/addr.inp [new file with mode: 0644]
test/tools/llvm-symbolizer/sym.test [new file with mode: 0644]
tools/llvm-symbolizer/llvm-symbolizer.cpp

index 96720e633f2fafb9c53a03e1c5d983c4d40b9d25..9d6571d5c4c2a954c6dfb7b4adcad347670d4b2c 100644 (file)
@@ -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.
 
  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
 -----------
 
 EXIT STATUS
 -----------
diff --git a/test/tools/llvm-symbolizer/Inputs/addr.exe b/test/tools/llvm-symbolizer/Inputs/addr.exe
new file mode 100755 (executable)
index 0000000..0d9e87d
Binary files /dev/null and b/test/tools/llvm-symbolizer/Inputs/addr.exe differ
diff --git a/test/tools/llvm-symbolizer/Inputs/addr.inp b/test/tools/llvm-symbolizer/Inputs/addr.inp
new file mode 100644 (file)
index 0000000..4de0964
--- /dev/null
@@ -0,0 +1 @@
+0x40054d
diff --git a/test/tools/llvm-symbolizer/sym.test b/test/tools/llvm-symbolizer/sym.test
new file mode 100644 (file)
index 0000000..559124a
--- /dev/null
@@ -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
+
index 9c9f3adbf60e13c9e9f122bc180f5eb29fb9caf1..b4485339b0d48a1c5590523d619a18e603febf72 100644 (file)
@@ -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"));
 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) {
 
 static bool parseCommand(bool &IsData, std::string &ModuleName,
                          uint64_t &ModuleOffset) {
@@ -152,6 +155,11 @@ int main(int argc, char **argv) {
     std::string Result =
         IsData ? Symbolizer.symbolizeData(ModuleName, ModuleOffset)
                : Symbolizer.symbolizeCode(ModuleName, ModuleOffset);
     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();
   }
     outs() << Result << "\n";
     outs().flush();
   }