[llvm] r364121 - [llvm-objdump] Allow --disassemble-functions to take demangled names
Yuanfang Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 18:13:04 PDT 2019
Author: yuanfang
Date: Fri Jun 21 18:13:04 2019
New Revision: 364121
URL: http://llvm.org/viewvc/llvm-project?rev=364121&view=rev
Log:
[llvm-objdump] Allow --disassemble-functions to take demangled names
The --disassemble-functions switch takes demangled names when
--demangle is specified, otherwise the switch takes mangled names.
https://bugs.llvm.org/show_bug.cgi?id=41908
Reviewers: jhenderson, grimar, MaskRay, rupprecht
Differential Revision: https://reviews.llvm.org/D63524
Added:
llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test
Removed:
llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangled-name.test
Modified:
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Removed: llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangled-name.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangled-name.test?rev=364120&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangled-name.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangled-name.test (removed)
@@ -1,27 +0,0 @@
-## Show that the --disassemble-functions switch takes mangled names, not
-## demangled names.
-
-# RUN: yaml2obj %s -o %t.o
-# RUN: llvm-objdump -d --disassemble-functions=_Z3foov %t.o | FileCheck %s
-# RUN: llvm-objdump -d --disassemble-functions='foo()' %t.o | FileCheck %s --check-prefix=NOFOO
-# RUN: llvm-objdump -d -C --disassemble-functions='foo()' %t.o | FileCheck %s --check-prefix=NOFOO
-# RUN: llvm-objdump -d --disassemble-functions=foo %t.o | FileCheck %s --check-prefix=NOFOO
-
-# CHECK: _Z3foov:
-
-# NOFOO-NOT: foo
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_EXEC
- Machine: EM_X86_64
-Sections:
- - Name: .text
- Type: SHT_PROGBITS
- Flags: [SHF_ALLOC, SHF_EXECINSTR]
- Content: '90'
-Symbols:
- - Name: _Z3foov
- Section: .text
Added: llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test?rev=364121&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test Fri Jun 21 18:13:04 2019
@@ -0,0 +1,61 @@
+## Show that the --disassemble-functions switch takes demangled names when
+## --demangle is specified, otherwise the switch takes mangled names.
+
+# RUN: yaml2obj %s -o %t.o
+
+## --disassemble-functions without --demangle.
+# RUN: llvm-objdump --disassemble-functions=_Z3foov %t.o | FileCheck %s --check-prefix=MANGLED
+# RUN: llvm-objdump --disassemble-functions='foo()' %t.o 2>&1 \
+# RUN: | FileCheck %s --check-prefix=MANGLED-MISS
+# RUN: llvm-objdump --disassemble-functions=foo %t.o 2>&1 \
+# RUN: | FileCheck %s --check-prefix=MANGLED-MISS
+# RUN: llvm-objdump --disassemble-functions='i,f' %t.o | FileCheck %s --check-prefix=NOMANGLE
+
+## --disassemble-functions with --demangle.
+# RUN: llvm-objdump -C --disassemble-functions='foo()' %t.o | FileCheck %s --check-prefix=DEMANGLED
+# RUN: llvm-objdump -C --disassemble-functions='_Z3foov' %t.o 2>&1 \
+# RUN: | FileCheck %s --check-prefix=DEMANGLED-MISS
+# RUN: llvm-objdump -C --disassemble-functions='i,f' %t.o | FileCheck %s --check-prefix=NOMANGLE
+# RUN: llvm-objdump -C --disassemble-functions='std::allocator<wchar_t>::allocator()' %t.o 2>&1 \
+# RUN: | FileCheck %s --check-prefix=DEMANGLED-MULTI
+
+# MANGLED: _Z3foov:
+# MANGLED-MISS: warning: failed to disassemble missing function foo
+
+# DEMANGLED: foo():
+# DEMANGLED-MISS: warning: failed to disassemble missing function _Z3foov
+
+# NOMANGLE: i:
+# NOMANGLE: f:
+
+# DEMANGLED-MULTI: std::allocator<wchar_t>::allocator():
+# DEMANGLED-MULTI: std::allocator<wchar_t>::allocator():
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ Address: 0x1000
+ Content: 9090909090
+Symbols:
+ - Name: _Z3foov
+ Value: 0x1000
+ Section: .text
+ - Name: i
+ Value: 0x1001
+ Section: .text
+ - Name: f
+ Value: 0x1002
+ Section: .text
+ - Name: _ZNSaIwEC1Ev
+ Value: 0x1003
+ Section: .text
+ - Name: _ZNSaIwEC2Ev
+ Value: 0x1004
+ Section: .text
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=364121&r1=364120&r2=364121&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Jun 21 18:13:04 2019
@@ -143,7 +143,9 @@ static cl::alias DisassembleAllShort("D"
static cl::list<std::string>
DisassembleFunctions("disassemble-functions", cl::CommaSeparated,
- cl::desc("List of functions to disassemble"),
+ cl::desc("List of functions to disassemble. "
+ "Accept demangled names when --demangle is "
+ "specified, otherwise accept mangled names"),
cl::cat(ObjdumpCat));
static cl::opt<bool> DisassembleZeroes(
@@ -1207,17 +1209,20 @@ static void disassembleObject(const Targ
std::vector<RelocationRef>::const_iterator RelEnd = Rels.end();
// Disassemble symbol by symbol.
for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) {
+ std::string SymbolName = std::get<1>(Symbols[SI]).str();
+ if (Demangle)
+ SymbolName = demangle(SymbolName);
+
// Skip if --disassemble-functions is not empty and the symbol is not in
// the list.
- if (!DisasmFuncsSet.empty() &&
- !DisasmFuncsSet.count(std::get<1>(Symbols[SI])))
+ if (!DisasmFuncsSet.empty() && !DisasmFuncsSet.count(SymbolName))
continue;
uint64_t Start = std::get<0>(Symbols[SI]);
if (Start < SectionAddr || StopAddress <= Start)
continue;
else
- FoundDisasmFuncsSet.insert(std::get<1>(Symbols[SI]));
+ FoundDisasmFuncsSet.insert(SymbolName);
// The end is the section end, the beginning of the next symbol, or
// --stop-address.
@@ -1259,11 +1264,7 @@ static void disassembleObject(const Targ
outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
SectionAddr + Start + VMAAdjustment);
- StringRef SymbolName = std::get<1>(Symbols[SI]);
- if (Demangle)
- outs() << demangle(SymbolName) << ":\n";
- else
- outs() << SymbolName << ":\n";
+ outs() << SymbolName << ":\n";
// Don't print raw contents of a virtual section. A virtual section
// doesn't have any contents in the file.
More information about the llvm-commits
mailing list