llvm.org GIT mirror llvm / 22939fa
llvm-symbolizer: make mangled name heuristic apply to all symbols PR: http://llvm.org/pr18431 Review: http://llvm-reviews.chandlerc.com/D2552 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199404 91177308-0d34-0410-b5e6-96231b3b80d8 Ed Maste 6 years ago
5 changed file(s) with 34 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 int f(int a, int b) {
1 return a + b;
2 }
3
4 int g(int a) {
5 return a + 1;
6 }
7
8
9 int main() {
10 return f(2, g(2));
11 }
12
13 // Built with Clang 3.3:
14 // $ mkdir -p /tmp/dbginfo
15 // $ cp llvm-symbolizer-test.c /tmp/dbginfo
16 // $ cd /tmp/dbginfo
17 // $ clang -g llvm-symbolizer-test.c -o
6565 BINARY: main
6666 BINARY-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16
6767 BINARY: _start
68
69 RUN: echo "0x400720" > %t.input5
70 RUN: echo "0x4004a0" >> %t.input5
71 RUN: echo "0x4006f0" >> %t.input5
72 RUN: llvm-symbolizer --obj %p/Inputs/llvm-symbolizer-test.elf-x86-64 < %t.input5 \
73 RUN: | FileCheck %s --check-prefix=BINARY_C
74
75 BINARY_C: main
76 BINARY_C-NEXT: /tmp/dbginfo{{[/\\]}}llvm-symbolizer-test.c:10
77 BINARY_C: _start
78 BINARY_C: {{g$}}
194194 if (Opts.UseSymbolTable) {
195195 if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) {
196196 if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
197 Name = DemangleGlobalName(Name);
197 Name = DemangleName(Name);
198198 }
199199 }
200200 std::stringstream ss;
423423
424424 std::string LLVMSymbolizer::DemangleName(const std::string &Name) {
425425 #if !defined(_MSC_VER)
426 // We can spoil names of symbols with C linkage, so use an heuristic
427 // approach to check if the name should be demangled.
428 if (Name.substr(0, 2) != "_Z")
429 return Name;
426430 int status = 0;
427431 char *DemangledName = __cxa_demangle(Name.c_str(), 0, 0, &status);
428432 if (status != 0)
435439 #endif
436440 }
437441
438 std::string LLVMSymbolizer::DemangleGlobalName(const std::string &Name) {
439 // We can spoil names of globals with C linkage, so use an heuristic
440 // approach to check if the name should be demangled.
441 return (Name.substr(0, 2) == "_Z") ? DemangleName(Name) : Name;
442 }
443
444442 } // namespace symbolize
445443 } // namespace llvm
7070 ObjectFile *getObjectFileFromBinary(Binary *Bin, const std::string &ArchName);
7171
7272 std::string printDILineInfo(DILineInfo LineInfo) const;
73 static std::string DemangleGlobalName(const std::string &Name);
7473
7574 // Owns all the parsed binaries and object files.
7675 SmallVector ParsedBinariesAndObjects;