Skip to content

Commit

Permalink
llvm-xray {convert,extract}: Add --demangle
Browse files Browse the repository at this point in the history
No demangling may be a better default in the future.
Add `--demangle` for migration convenience.

Reviewed By: Enna1

Differential Revision: https://reviews.llvm.org/D108100
  • Loading branch information
MaskRay committed Aug 24, 2021
1 parent e4ebfb5 commit 9b96b08
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-xray/AArch64/extract-instrmap.test
Expand Up @@ -3,6 +3,7 @@

# RUN: yaml2obj %S/Inputs/elf64-pic.yaml -o %t.so
# RUN: llvm-xray extract %t.so -s | FileCheck %s
# RUN: llvm-xray extract %t.so --no-demangle --demangle -s | FileCheck %s

# CHECK: ---
# CHECK-NEXT: - { id: 1, address: 0x420, function: 0x420, kind: function-enter, always-instrument: true, function-name: 'foo()' }
Expand All @@ -14,6 +15,7 @@
# CHECK-NEXT: ...

# RUN: llvm-xray extract -s --no-demangle %t.so | FileCheck --check-prefix=MANGLED %s
# RUN: llvm-xray extract -s --demangle --no-demangle %t.so | FileCheck --check-prefix=MANGLED %s

# MANGLED: ---
# MANGLED-NEXT: - { id: 1, address: 0x420, function: 0x420, kind: function-enter, always-instrument: true, function-name: _Z3foov }
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/tools/llvm-xray/X86/convert-with-debug-syms.txt
@@ -1,4 +1,5 @@
; RUN: llvm-xray convert -m %S/Inputs/elf64-sample-o2.bin -y %S/Inputs/naive-log-simple.xray -f yaml -o - 2>&1 | FileCheck %s
; RUN: llvm-xray convert -m %S/Inputs/elf64-sample-o2.bin -y %S/Inputs/naive-log-simple.xray -f yaml 2>&1 | FileCheck %s
; RUN: llvm-xray convert -m %S/Inputs/elf64-sample-o2.bin -y %S/Inputs/naive-log-simple.xray -f yaml --demangle 2>&1 | FileCheck %s

; CHECK: ---
; CHECK-NEXT: header:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/tools/llvm-xray/X86/extract-instrmap-pie.ll
Expand Up @@ -4,8 +4,8 @@
; RUN: llvm-xray extract %S/Inputs/elf64-pie.bin -s | FileCheck %s

; CHECK: ---
; CHECK-NEXT: - { id: 1, address: 0x299C0, function: 0x299C0, kind: function-enter, always-instrument: true, function-name: {{.*foo.*}} }
; CHECK-NEXT: - { id: 1, address: 0x299D0, function: 0x299C0, kind: function-exit, always-instrument: true, function-name: {{.*foo.*}} }
; CHECK-NEXT: - { id: 2, address: 0x299E0, function: 0x299E0, kind: function-enter, always-instrument: true, function-name: {{.*bar.*}} }
; CHECK-NEXT: - { id: 2, address: 0x299F6, function: 0x299E0, kind: function-exit, always-instrument: true, function-name: {{.*bar.*}} }
; CHECK-NEXT: - { id: 1, address: 0x299C0, function: 0x299C0, kind: function-enter, always-instrument: true, function-name: 'foo()' }
; CHECK-NEXT: - { id: 1, address: 0x299D0, function: 0x299C0, kind: function-exit, always-instrument: true, function-name: 'foo()' }
; CHECK-NEXT: - { id: 2, address: 0x299E0, function: 0x299E0, kind: function-enter, always-instrument: true, function-name: 'bar()' }
; CHECK-NEXT: - { id: 2, address: 0x299F6, function: 0x299E0, kind: function-exit, always-instrument: true, function-name: 'bar()' }
; CHECK-NEXT: ...
6 changes: 5 additions & 1 deletion llvm/tools/llvm-xray/xray-converter.cpp
Expand Up @@ -63,6 +63,10 @@ static cl::opt<bool>
"when symbolizing function ids from the input log"),
cl::init(false), cl::sub(Convert));

static cl::opt<bool> Demangle("demangle",
cl::desc("demangle symbols (default)"),
cl::sub(Convert));

static cl::opt<std::string>
ConvertInstrMap("instr_map",
cl::desc("binary with the instrumentation map, or "
Expand Down Expand Up @@ -379,7 +383,7 @@ static CommandRegistration Unused(&Convert, []() -> Error {

const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer::Options SymbolizerOpts;
if (NoDemangle)
if (Demangle.getPosition() < NoDemangle.getPosition())
SymbolizerOpts.Demangle = false;
symbolize::LLVMSymbolizer Symbolizer(SymbolizerOpts);
llvm::xray::FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer,
Expand Down
13 changes: 7 additions & 6 deletions llvm/tools/llvm-xray/xray-extract.cpp
Expand Up @@ -45,11 +45,12 @@ static cl::opt<bool> ExtractSymbolize("symbolize", cl::value_desc("symbolize"),
cl::sub(Extract));
static cl::alias ExtractSymbolize2("s", cl::aliasopt(ExtractSymbolize),
cl::desc("alias for -symbolize"));
static cl::opt<bool> ExtractNoDemangle("no-demangle",
cl::value_desc("no-demangle"),
cl::init(false),
cl::desc("don't demangle symbols"),
cl::sub(Extract));
static cl::opt<bool> Demangle("demangle",
cl::desc("demangle symbols (default)"),
cl::sub(Extract));
static cl::opt<bool> NoDemangle("no-demangle",
cl::desc("don't demangle symbols"),
cl::sub(Extract));

namespace {

Expand Down Expand Up @@ -90,7 +91,7 @@ static CommandRegistration Unused(&Extract, []() -> Error {
const auto &FunctionAddresses =
InstrumentationMapOrError->getFunctionAddresses();
symbolize::LLVMSymbolizer::Options opts;
if (ExtractNoDemangle)
if (Demangle.getPosition() < NoDemangle.getPosition())
opts.Demangle = false;
symbolize::LLVMSymbolizer Symbolizer(opts);
llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
Expand Down

0 comments on commit 9b96b08

Please sign in to comment.