Project

General

Profile

Actions

Emulator Issues #8165

closed

Tools: Linux perf cannot disassemble JIT-compiled code

Added by flacs almost 10 years ago.

Status:
Fixed
Priority:
Low
Assignee:
-
% Done:

0%

Operating system:
N/A
Issue type:
Feature request
Milestone:
Regression:
No
Relates to usability:
No
Relates to performance:
No
Easy:
No
Relates to maintainability:
No
Regression start:
Fixed in:

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.

Actions #1

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…

Actions #2

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.

Actions #3

Updated by degasus over 9 years ago

corona.gabriel: "Your approach sounds better" means pull requests are welcome ;)

Actions #4

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).

Actions #5

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.

Actions #6

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.

Actions #8

Updated by flacs over 9 years ago

(I'm assuming you forgot the --objdump option?)

Actions #9

Updated by flacs over 9 years ago

To answer your question, I'm using perf 4.1.0.

Actions #10

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.

Actions #11

Updated by flacs over 9 years ago

Haven't tried it yet, but looks good!

Actions

Also available in: Atom PDF