Emulator Issues #8165
closedTools: Linux perf cannot disassemble JIT-compiled code
0%
Description
Even when Dolphin is started with "-P /tmp" to generate JIT symbols, perf still can't disassemble JIT-compiled code because it uses objdump for that which only looks at the executable on disk.
I hacked up a little workaround which should be re-done properly and either be merged upstream (Linux), added to our Tools/, or at least get documented somewhere:
$ cat disassemble.sh
#!/bin/bash
gdb -q -p $(pidof dolphin-emu) -ex "disas ${1##--start-address=},${2##--stop-address=}" -ex q -batch
$ dolphin-emu -P /tmp -b -e $game.iso &
$ perf top $(pidof dolphin-emu) --objdump ./disassemble.sh
This works but has a few issues:
- gdb shows relative addresses for non-JIT functions, perf doesn't understand that
- only supports the default disassembly mode of perf
I'll get to it when I have time but if someone else wants to work on this, please do.
Updated by corona.gabriel over 9 years ago
Isn't this very slow? AFAIU, GDB always ptrace (and stops) the target process.
With recent version of Linux we can read from another process memory without ptracing it (suing process_vm_readv or reading in /proc/$pid/mem). I have a prototype tool (https://github.com/randomstuff/unjit) using this + LLVM decompiler + perf maps in order to decompiler JITed code. It couold be adapted (simplified) in order to be used in perf top…
Updated by flacs over 9 years ago
- Status changed from New to Fixed
Oops, forgot to update this issue, it was addressed in: https://github.com/dolphin-emu/dolphin/pull/2022
Yes, it's kind of slow. Your approach sounds better.
Updated by degasus over 9 years ago
corona.gabriel: "Your approach sounds better" means pull requests are welcome ;)
Updated by corona.gabriel over 9 years ago
I guess I might work on this as a third party tool (because there is nothing really specific to Dolphin).
Updated by degasus over 9 years ago
The best would be to include such a tool into linux-tools, so that perf will do this automatically.
Updated by corona.gabriel over 9 years ago
Which version of perf are you using? With 3.16.0, I can't get it to annotate JIT-ed code. I have entries for perf-xxx.map but there is no menu option for "Annotate" for those entries.
Updated by flacs over 9 years ago
Updated by flacs over 9 years ago
(I'm assuming you forgot the --objdump option?)
Updated by flacs over 9 years ago
To answer your question, I'm using perf 4.1.0.
Updated by corona.gabriel over 9 years ago
OK, I got the thing working. The "unjit" tool now as support for this. There is a perfobjdump script included (largely inspired by your script) in order to do this. It's not dolphin specific (it parses the PID from the /tmp/perf-$pid.map argument in order to find the suitable argument). It is able to decompile JITed code without stopping the target process at all.