tracy icon indicating copy to clipboard operation
tracy copied to clipboard

TracySourceView can't find symbols unless `baseAddr` is fixed up by walking back from `symAddr` across the function prologue

Open bjacob opened this issue 2 years ago • 6 comments

I'm using Tracy with sampling on Android/aarch64. Some of my symbols, that are created by a custom LLVM-based compiler (IREE), are at first not visible to TracySourceView: trying to open the source view shows '0x0' as the symbol address, and no symbol name.

I traced that to SourceView::OpenSymbol being called with baseAddr = 0. I then tried locally fixing that up by using symAddr instead. That made things slightly better: now the source view showed not only the symbol address, but also the symbol name. But still no disassembly.

To get the disassembly to work, I found that I had to use not exactly symAddr, but rather, symAddr minus the size of the function prologue. Example:

0000000000117dac <main_dispatch_2415>:
  117dac: ff 43 02 d1  	sub	sp, sp, #144          # \
  117db0: ef 3b 04 6d  	stp	d15, d14, [sp, #64]   #  \
  117db4: ed 33 05 6d  	stp	d13, d12, [sp, #80]   #   \
  117db8: eb 2b 06 6d  	stp	d11, d10, [sp, #96]   #    Function prologue -- stack frame work.
  117dbc: e9 23 07 6d  	stp	d9, d8, [sp, #112]    #   /
  117dc0: fd 7b 08 a9  	stp	x29, x30, [sp, #128]  #  /
  117dc4: fd 03 02 91  	add	x29, sp, #128         # /   <--- x29 is the frame pointer.
  117dc8: 2b 10 40 f9  	ldr	x11, [x1, #32]        # <--- symAddr initially points to this instruction.
  117dcc: 09 00 96 52  	mov	w9, #45056

#383 is the diff that I'm using to do all of the above: https://github.com/wolfpld/tracy/pull/383/files

Not sending this as a PR because that's obviously a hack. I'm just sending this as a way to show what happens to locally unblock me in the hope that someone who better understands Tracy can find the right fix!

bjacob avatar May 04 '22 16:05 bjacob

Updated PR #383 - In order to get the column with the instruction sample counts (leftmost column in asm view) I also needed to adjust the IP passed to GatherIpStats.

bjacob avatar May 06 '22 19:05 bjacob

@wolfpld is that information somehow actionable? Clearly #383 is a bad hack, but does the fact that it "solves" a problem that I observe, useful info?

bjacob avatar May 12 '22 17:05 bjacob

useful info?

No. The base address of a symbol has to be known, otherwise the machine code couldn't be retrieved. It obviously is retrieved, as you are able to eventually find it by walking back from the symAddr you get. The valid question here is why baseAddr is 0.

wolfpld avatar May 14 '22 11:05 wolfpld

The following image shows anatomy of a symbol. It may be of some help.

symbol

Example: Symbol = sort Inline function = operator <

wolfpld avatar May 14 '22 11:05 wolfpld

I have just fixed a rather nasty regression with 5a36782c. It was introduced in 18112d3c6, in April, which nicely lines up with this issue submission date. Please check if your problem is fixed now.

wolfpld avatar Jul 31 '22 10:07 wolfpld

Great, thanks for the note! I'm on vacation until August 17, will try then.

bjacob avatar Jul 31 '22 20:07 bjacob

Thanks, the fix is working as intended!

bjacob avatar Sep 22 '22 14:09 bjacob