CensoredUsername / dynasm-rs

A dynasm-like tool for rust.
https://censoredusername.github.io/dynasm-rs/language/index.html
Mozilla Public License 2.0
716 stars 52 forks source link

Symbols for dynamic labels #83

Closed vext01 closed 1 year ago

vext01 commented 1 year ago

Hi,

Long time no speak. Hope you are well!

I'm trying to figure out a way to add a dynamic label to some code I'm generating, and give it a symbol a debugger can find at runtime. I've managed to use dynamic labels for control flow just fine, but I can't see a way to add a symbol for them.

Is it possible?

(I've looked at static labels, but their name has to be &'static str, but I'll need symbol names to be generated at runtime)

Cheers

CensoredUsername commented 1 year ago

Generating debugging information for JITted code at runtime is likely dependent on the debugger you're using. GDB has some information on how to do it here: https://sourceware.org/gdb/onlinedocs/gdb/JIT-Interface.html , but actually implementing this is on you. Dynasm-rs assemblers provide an API where you can get the offset of a dynamic label from its ID, and so you can tell GDB that code at that offset has a name of your choosing.

vext01 commented 1 year ago

For some reason I thought gdb could trap based on basic symbol addresses too? Maybe I'm wrong.

CensoredUsername commented 1 year ago

I'm not sure what you mean? Either way the labels you use in dynasm-rs aren't true symbols as you'd find them in the binary. They're just entries in some HashMap. If you want to be able to use them in a debugger you'll have to inform your debugger of them at runtime.

vext01 commented 1 year ago

Thanks.

vext01 commented 1 year ago

Hey,

I managed to implement the gdb interface for our (dynasm) JIT and now gdb recognises the code with a symbol name and shows debugging source lines.

For some reason I still can't break on these symbols though.. any ideas?

image

CensoredUsername commented 1 year ago

I'm not that familiar with GDB, sorry.