llvm.org GIT mirror llvm / ba07fc7
[llvm-symbolizer] Print out non-address lines verbatim. Differential Revision: http://reviews.llvm.org/D15876 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257115 91177308-0d34-0410-b5e6-96231b3b80d8 Mike Aizatsky 3 years ago
4 changed file(s) with 30 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1010
1111 :program:`llvm-symbolizer` reads object file names and addresses from standard
1212 input and prints corresponding source code locations to standard output.
13 If object file is specified in command line, :program:`llvm-symbolizer` reads
14 only addresses from standard input. This
15 program uses debug info sections and symbol table in the object files.
13 If object file is specified in command line, :program:`llvm-symbolizer`
14 processes only addresses from standard input, the rest is output verbatim.
15 This program uses debug info sections and symbol table in the object files.
1616
1717 EXAMPLE
1818 --------
0 some text
1 0x40054d
2 some text2
1919 RUN: llvm-symbolizer -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
2020 RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck --check-prefix="PRETTY" %s
2121
22 #CHECK: some text
2223 #CHECK: 0x40054d
2324 #CHECK: main
2425 #CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
26 #CHECK: some text2
2527 #
28 #PRETTY: some text
2629 #PRETTY: {{[0x]+}}40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3:3
2730 #PRETTY: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7:0
2831 #PRETTY (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14:0
32 #PRETTY: some text2
2933
8888 return true;
8989 }
9090
91 static bool parseCommand(bool &IsData, std::string &ModuleName,
92 uint64_t &ModuleOffset) {
91 static bool parseCommand(StringRef InputString, bool &IsData,
92 std::string &ModuleName, uint64_t &ModuleOffset) {
9393 const char *kDataCmd = "DATA ";
9494 const char *kCodeCmd = "CODE ";
95 const int kMaxInputStringLength = 1024;
96 const char kDelimiters[] = " \n";
97 char InputString[kMaxInputStringLength];
98 if (!fgets(InputString, sizeof(InputString), stdin))
99 return false;
95 const char kDelimiters[] = " \n\r";
10096 IsData = false;
10197 ModuleName = "";
102 char *pos = InputString;
98 const char *pos = InputString.data();
10399 if (strncmp(pos, kDataCmd, strlen(kDataCmd)) == 0) {
104100 IsData = true;
105101 pos += strlen(kDataCmd);
116112 if (*pos == '"' || *pos == '\'') {
117113 char quote = *pos;
118114 pos++;
119 char *end = strchr(pos, quote);
115 const char *end = strchr(pos, quote);
120116 if (!end)
121117 return false;
122118 ModuleName = std::string(pos, end - pos);
157153 }
158154 LLVMSymbolizer Symbolizer(Opts);
159155
160 bool IsData = false;
161 std::string ModuleName;
162 uint64_t ModuleOffset;
163156 DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
164157 ClPrettyPrint);
165158
166 while (parseCommand(IsData, ModuleName, ModuleOffset)) {
159 const int kMaxInputStringLength = 1024;
160 char InputString[kMaxInputStringLength];
161
162 while (true) {
163 if (!fgets(InputString, sizeof(InputString), stdin))
164 break;
165
166 bool IsData = false;
167 std::string ModuleName;
168 uint64_t ModuleOffset = 0;
169 if (!parseCommand(StringRef(InputString), IsData, ModuleName,
170 ModuleOffset)) {
171 outs() << InputString;
172 continue;
173 }
174
167175 if (ClPrintAddress) {
168176 outs() << "0x";
169177 outs().write_hex(ModuleOffset);