[all-commits] [llvm/llvm-project] eb6da9: [lldb] Improve disassembly of unknown instructions...

tedwoodward via All-commits all-commits at lists.llvm.org
Mon Jul 14 19:50:43 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: eb6da944af31dd684be3ab2f93f453a3837a72c6
      https://github.com/llvm/llvm-project/commit/eb6da944af31dd684be3ab2f93f453a3837a72c6
  Author: tedwoodward <56049650+tedwoodward at users.noreply.github.com>
  Date:   2025-07-14 (Mon, 14 Jul 2025)

  Changed paths:
    A lldb/examples/python/filter_disasm.py
    M lldb/include/lldb/Core/Opcode.h
    M lldb/source/Core/Disassembler.cpp
    M lldb/source/Core/Opcode.cpp
    M lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
    M lldb/source/Utility/ArchSpec.cpp
    A lldb/test/Shell/Commands/Inputs/dis_filt.py
    A lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s
    A lldb/test/Shell/Commands/command-disassemble-x86-bytes.s
    M lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp
    M llvm/docs/ReleaseNotes.md

  Log Message:
  -----------
  [lldb] Improve disassembly of unknown instructions (#145793)

LLDB uses the LLVM disassembler to determine the size of instructions and
to do the actual disassembly. Currently, if the LLVM disassembler can't
disassemble an instruction, LLDB will ignore the instruction size, assume
the instruction size is the minimum size for that device, print no useful
opcode, and print nothing for the instruction.

This patch changes this behavior to separate the instruction size and
"can't disassemble". If the LLVM disassembler knows the size, but can't
dissasemble the instruction, LLDB will use that size. It will print out
the opcode, and will print "<unknown>" for the instruction. This is much
more useful to both a user and a script.

The impetus behind this change is to clean up RISC-V disassembly when
the LLVM disassembler doesn't understand all of the instructions.
RISC-V supports proprietary extensions, where the TD files don't know
about certain instructions, and the disassembler can't disassemble them.
Internal users want to be able to disassemble these instructions.

With llvm-objdump, the solution is to pipe the output of the disassembly
through a filter program. This patch modifies LLDB's disassembly to look
more like llvm-objdump's, and includes an example python script that adds
a command "fdis" that will disassemble, then pipe the output through a
specified filter program. This has been tested with crustfilt, a sample
filter located at https://github.com/quic/crustfilt .

Changes in this PR:
- Decouple "can't disassemble" with "instruction size".
  DisassemblerLLVMC::MCDisasmInstance::GetMCInst now returns a bool for
    valid disassembly, and has the size as an out paramter.
  Use the size even if the disassembly is invalid.
  Disassemble if disassemby is valid.

- Always print out the opcode when -b is specified.
  Previously it wouldn't print out the opcode if it couldn't disassemble.

- Print out RISC-V opcodes the way llvm-objdump does.
  Code for the new Opcode Type eType16_32Tuples by Jason Molenda.

- Print <unknown> for instructions that can't be disassembled, matching
  llvm-objdump, instead of printing nothing.

- Update max riscv32 and riscv64 instruction size to 8.

- Add example "fdis" command script.

- Added disassembly byte test for x86 with known and unknown instructions.
- Added disassembly byte test for riscv32 with known and unknown instructions,
  with and without filtering.
- Added test from Jason Molenda to RISC-V disassembly unit tests.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list