diff --git a/docs/CommandGuide/llvm-symbolizer.rst b/docs/CommandGuide/llvm-symbolizer.rst index ec4178e4e7a..7bcad1c12f1 100644 --- a/docs/CommandGuide/llvm-symbolizer.rst +++ b/docs/CommandGuide/llvm-symbolizer.rst @@ -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 -------- diff --git a/test/tools/llvm-symbolizer/Inputs/addr.inp b/test/tools/llvm-symbolizer/Inputs/addr.inp index 4de096479da..b5e146b114e 100644 --- a/test/tools/llvm-symbolizer/Inputs/addr.inp +++ b/test/tools/llvm-symbolizer/Inputs/addr.inp @@ -1 +1,3 @@ +some text 0x40054d +some text2 diff --git a/test/tools/llvm-symbolizer/sym.test b/test/tools/llvm-symbolizer/sym.test index 01a6692222e..27f06901ff6 100644 --- a/test/tools/llvm-symbolizer/sym.test +++ b/test/tools/llvm-symbolizer/sym.test @@ -20,11 +20,15 @@ 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 diff --git a/tools/llvm-symbolizer/llvm-symbolizer.cpp b/tools/llvm-symbolizer/llvm-symbolizer.cpp index e45660c84c7..a4dfc2e2392 100644 --- a/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -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);