[llvm-symbolizer] Print out non-address lines verbatim.
authorMike Aizatsky <aizatsky@chromium.org>
Thu, 7 Jan 2016 23:57:41 +0000 (23:57 +0000)
committerMike Aizatsky <aizatsky@chromium.org>
Thu, 7 Jan 2016 23:57:41 +0000 (23:57 +0000)
Differential Revision: http://reviews.llvm.org/D15876

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

docs/CommandGuide/llvm-symbolizer.rst
test/tools/llvm-symbolizer/Inputs/addr.inp
test/tools/llvm-symbolizer/sym.test
tools/llvm-symbolizer/llvm-symbolizer.cpp

index ec4178e4e7ab19f32e6c4840ec20fc451f142afc..7bcad1c12f119cf4a5ed313b25fc99b6025ed42d 100644 (file)
@@ -11,9 +11,9 @@ DESCRIPTION
 
 :program:`llvm-symbolizer` reads object file names and addresses from standard
 input and prints corresponding source code locations to standard output.
-If object file is specified in command line, :program:`llvm-symbolizer` reads
-only addresses from standard input. This
-program uses debug info sections and symbol table in the object files.
+If object file is specified in command line, :program:`llvm-symbolizer` 
+processes only addresses from standard input, the rest is output verbatim.
+This program uses debug info sections and symbol table in the object files.
 
 EXAMPLE
 --------
index 4de096479dae431d01b514514c1ce63797163852..b5e146b114e254f335bc5796340367c71253506e 100644 (file)
@@ -1 +1,3 @@
+some text
 0x40054d
+some text2
index 01a6692222e728168e6ceb02f7718e2b3d82a34f..27f06901ff6ccb2439cd59922b208c3af4169478 100644 (file)
 RUN: llvm-symbolizer -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
 RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck --check-prefix="PRETTY" %s 
 
+#CHECK: some text
 #CHECK: 0x40054d
 #CHECK: main
 #CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
+#CHECK: some text2
 #
+#PRETTY: some text
 #PRETTY: {{[0x]+}}40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3:3
 #PRETTY:  (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7:0
 #PRETTY   (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14:0
+#PRETTY: some text2
 
index e45660c84c7723c5923b547bd5639c308a867f8b..a4dfc2e2392e62450bf62e1325027c9efa2c0a56 100644 (file)
@@ -89,18 +89,14 @@ static bool error(std::error_code ec) {
   return true;
 }
 
-static bool parseCommand(bool &IsData, std::string &ModuleName,
-                         uint64_t &ModuleOffset) {
+static bool parseCommand(StringRef InputString, bool &IsData,
+                         std::string &ModuleName, uint64_t &ModuleOffset) {
   const char *kDataCmd = "DATA ";
   const char *kCodeCmd = "CODE ";
-  const int kMaxInputStringLength = 1024;
-  const char kDelimiters[] = " \n";
-  char InputString[kMaxInputStringLength];
-  if (!fgets(InputString, sizeof(InputString), stdin))
-    return false;
+  const char kDelimiters[] = " \n\r";
   IsData = false;
   ModuleName = "";
-  char *pos = InputString;
+  const char *pos = InputString.data();
   if (strncmp(pos, kDataCmd, strlen(kDataCmd)) == 0) {
     IsData = true;
     pos += strlen(kDataCmd);
@@ -117,7 +113,7 @@ static bool parseCommand(bool &IsData, std::string &ModuleName,
     if (*pos == '"' || *pos == '\'') {
       char quote = *pos;
       pos++;
-      char *end = strchr(pos, quote);
+      const char *end = strchr(pos, quote);
       if (!end)
         return false;
       ModuleName = std::string(pos, end - pos);
@@ -158,13 +154,25 @@ int main(int argc, char **argv) {
   }
   LLVMSymbolizer Symbolizer(Opts);
 
-  bool IsData = false;
-  std::string ModuleName;
-  uint64_t ModuleOffset;
   DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
                     ClPrettyPrint);
 
-  while (parseCommand(IsData, ModuleName, ModuleOffset)) {
+  const int kMaxInputStringLength = 1024;
+  char InputString[kMaxInputStringLength];
+
+  while (true) {
+    if (!fgets(InputString, sizeof(InputString), stdin))
+      break;
+
+    bool IsData = false;
+    std::string ModuleName;
+    uint64_t ModuleOffset = 0;
+    if (!parseCommand(StringRef(InputString), IsData, ModuleName,
+                      ModuleOffset)) {
+      outs() << InputString;
+      continue;
+    }
+
     if (ClPrintAddress) {
       outs() << "0x";
       outs().write_hex(ModuleOffset);