Skip to content

Commit

Permalink
[llvm-objdump] Add -mllvm (#75892)
Browse files Browse the repository at this point in the history
When llvm-objdump switched from cl:: to OptTable
(https://reviews.llvm.org/D100433), we dropped support for LLVM cl::
options. Some LLVM_DEBUG in `llvm/lib/Target/$target/MCDisassembler/`
files might be useful. Add -mllvm to allow dumping the information.

```
# -debug is available in an LLVM_ENABLE_ASSERTIONS=on build
llvm-objdump -d -mllvm -debug a.o > /dev/null
```

Link:
https://discourse.llvm.org/t/how-to-enable-debug-logs-in-llvm-objdump/75758
  • Loading branch information
MaskRay committed Dec 19, 2023
1 parent 1d57b9a commit 3cd1e73
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions llvm/docs/CommandGuide/llvm-objdump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ OPTIONS
Enable/disable target-specific attributes. Specify ``--mattr=help`` to display
the available attributes.

.. option:: -mllvm <arg>

Specify an argument to forward to LLVM's CommandLine library.

.. option:: --no-leading-addr, --no-addresses

When disassembling, do not print leading addresses for instructions or inline
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/tools/llvm-objdump/mllvm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
# RUN: llvm-objdump --no-print-imm-hex -d -mllvm --x86-asm-syntax=intel %t | FileCheck %s
# RUN: llvm-objdump --no-print-imm-hex -d -mllvm=--x86-asm-syntax=intel %t | FileCheck %s

# CHECK: lea rax, [rsi + 4*rdi + 5]

leaq 5(%rsi,%rdi,4), %rax
3 changes: 3 additions & 0 deletions llvm/tools/llvm-objdump/ObjdumpOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def mattr_EQ : Joined<["--"], "mattr=">,
MetaVarName<"a1,+a2,-a3,...">,
HelpText<"Target specific attributes (--mattr=help for details)">;

def mllvm : Separate<["-"], "mllvm">, HelpText<"Specify an argument to forward to LLVM's CommandLine library">, MetaVarName<"<arg>">;
def : Joined<["-"], "mllvm=">, Alias<mllvm>;

def no_show_raw_insn : Flag<["--"], "no-show-raw-insn">,
HelpText<"When disassembling instructions, "
"do not print the instruction bytes.">;
Expand Down
11 changes: 7 additions & 4 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3320,10 +3320,13 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
DisassemblerOptions.push_back(V.str());
}
}
if (AsmSyntax) {
const char *Argv[] = {"llvm-objdump", AsmSyntax};
llvm::cl::ParseCommandLineOptions(2, Argv);
}
SmallVector<const char *> Args = {"llvm-objdump"};
for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_mllvm))
Args.push_back(A->getValue());
if (AsmSyntax)
Args.push_back(AsmSyntax);
if (Args.size() > 1)
llvm::cl::ParseCommandLineOptions(Args.size(), Args.data());

// Look up any provided build IDs, then append them to the input filenames.
for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {
Expand Down

0 comments on commit 3cd1e73

Please sign in to comment.