five ways to invoke the LLVM disassembler.
- invoking the disassembler interactively using the
llvm-mc
command [^1] - invoking the disassembler in tests using
llvm-lit
, the LLVM testing tool. - invoking the disassembler with a potential
--binary
option tollvm-objdump
[^2] - invoking the disassembler using the LLVM C API [^3] (plus code in this gist).
- invoking the disassembler using the LLVM C++ API (with code in this gist).
first;y, one can invoke the dissassembler using the llvm-mc
command.
$ echo '0x49, 0x0f, 0xc7, 0x0f' | llvm-mc -disassemble -triple x86_64
secondly, one can invoke the dissassembler using llvm-lit
to run disassembly tests.
$ ./build/bin/llvm-lit llvm/test/MC/X86
thirdly, one can invoke the dissassembler in a shell script using llvm-objdump
.
#!/bin/sh
T=$(mktemp fooXXXXXX)
echo $* | xxd -r -p - > ${T}
# objdump -D -bbinary -mi386:x86-64 -Mintel ${T} | sed -n '/<.data>:/{n;s/0://g p}'
llvm-objdump -d --binary --triple -Mintel ${T} | sed -n '/<.data>:/{n;s/0://g p}'
rm -f ${T}
which we can run like this:
$ ./disasm.sh 49 0f c7 0f
49 0f c7 0f cmpxchg16b xmmword ptr [r15]
note: this depends on a pull request to add a --binary
option to llvm-objdump
[^2].
and finally, this gist contains example code in C and C++ to show how to invoke the disassembler using the LLVM C API and the LLVM C++ API:
llvmdisc.c
- example showing how to invoke the disassembler using the LLVM C API.llvmdicpp.cpp
- example showing how to invoke the disassembler using the LLVM C++ API.
there is also llvm-mc-disassemble-fuzzer.cpp
in the LLVM source repo, which I found from
grepping the sources, as well as a blog post from 2010 [^1] and 2017[^3]. I started off my
journey into finding out about LLVM disassembly with man llvm-objdump
as I was expecting
something like the GNU binutils objdump -bbinary
option. hence the pull request.
- [^1] https://blog.llvm.org/2010/01/x86-disassembler.html
- [^2] llvm/llvm-project#115667
- [^3] https://raywang.tech/2017/12/04/Using-the-LLVM-MC-Disassembly-API/
here is an article on debugging in-memory JIT code by hooking up in-memory DWARF objects
to the debugger by intercepting calls to __jit_debug_register_code
.