llvm.org GIT mirror llvm / 42c9ecb
llvm-symbolizer: add --obj flag to specify a single object file that should be symbolized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197988 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 6 years ago
3 changed file(s) with 48 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
99 -----------
1010
1111 :program:`llvm-symbolizer` reads object file names and addresses from standard
12 input and prints corresponding source code locations to standard output. This
12 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
1315 program uses debug info sections and symbol table in the object files.
1416
1517 EXAMPLE
4446
4547 _main
4648 /tmp/source_x86_64.cc:8
49 $ cat addr2.txt
50 0x4004f4
51 0x401000
52 $ llvm-symbolizer -obj=a.out < addr2.txt
53 main
54 /tmp/a.cc:4
55
56 foo(int)
57 /tmp/a.cc:12
4758
4859 OPTIONS
4960 -------
61
62 .. option:: -obj
63 Path to object file to be symbolized.
5064
5165 .. option:: -functions
5266
5656 UNKNOWN-ARCH-NOT: main
5757 UNKNOWN-ARCH: ??
5858 UNKNOWN-ARCH-NOT: main
59
60 RUN: echo "0x400559" > %t.input4
61 RUN: echo "0x400436" >> %t.input4
62 RUN: llvm-symbolizer --obj %p/Inputs/dwarfdump-test.elf-x86-64 < %t.input4 \
63 RUN: | FileCheck %s --check-prefix=BINARY
64
65 BINARY: main
66 BINARY-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16
67 BINARY: _start
5050 cl::desc("Default architecture "
5151 "(for multi-arch objects)"));
5252
53 static cl::opt
54 ClBinaryName("obj", cl::init(""),
55 cl::desc("Path to object file to be symbolized (if not provided, "
56 "object file should be specified for each input line)"));
57
5358 static bool parseCommand(bool &IsData, std::string &ModuleName,
5459 uint64_t &ModuleOffset) {
5560 const char *kDataCmd = "DATA ";
6166 return false;
6267 IsData = false;
6368 ModuleName = "";
64 std::string ModuleOffsetStr = "";
6569 char *pos = InputString;
6670 if (strncmp(pos, kDataCmd, strlen(kDataCmd)) == 0) {
6771 IsData = true;
7377 // If no cmd, assume it's CODE.
7478 IsData = false;
7579 }
76 // Skip delimiters and parse input filename.
77 pos += strspn(pos, kDelimiters);
78 if (*pos == '"' || *pos == '\'') {
79 char quote = *pos;
80 pos++;
81 char *end = strchr(pos, quote);
82 if (end == 0)
83 return false;
84 ModuleName = std::string(pos, end - pos);
85 pos = end + 1;
80 // Skip delimiters and parse input filename (if needed).
81 if (ClBinaryName == "") {
82 pos += strspn(pos, kDelimiters);
83 if (*pos == '"' || *pos == '\'') {
84 char quote = *pos;
85 pos++;
86 char *end = strchr(pos, quote);
87 if (end == 0)
88 return false;
89 ModuleName = std::string(pos, end - pos);
90 pos = end + 1;
91 } else {
92 int name_length = strcspn(pos, kDelimiters);
93 ModuleName = std::string(pos, name_length);
94 pos += name_length;
95 }
8696 } else {
87 int name_length = strcspn(pos, kDelimiters);
88 ModuleName = std::string(pos, name_length);
89 pos += name_length;
97 ModuleName = ClBinaryName;
9098 }
9199 // Skip delimiters and parse module offset.
92100 pos += strspn(pos, kDelimiters);
93101 int offset_length = strcspn(pos, kDelimiters);
94 ModuleOffsetStr = std::string(pos, offset_length);
95 if (StringRef(ModuleOffsetStr).getAsInteger(0, ModuleOffset))
102 if (StringRef(pos, offset_length).getAsInteger(0, ModuleOffset))
96103 return false;
97104 return true;
98105 }
103110 PrettyStackTraceProgram X(argc, argv);
104111 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
105112
106 cl::ParseCommandLineOptions(argc, argv, "llvm symbolizer for compiler-rt\n");
113 cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n");
107114 LLVMSymbolizer::Options Opts(ClUseSymbolTable, ClPrintFunctions,
108115 ClPrintInlining, ClDemangle, ClDefaultArch);
109116 LLVMSymbolizer Symbolizer(Opts);