CensoredUsername/dynasm-rs

Symbols for dynamic labels

Closed this issue · 6 comments

vext01 commented

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

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

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

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

Thanks.

vext01 commented

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

I'm not that familiar with GDB, sorry.