c++gdb

Pass symbols to gdb at runtime


I am making a JIT recompiler, which means I generate blocks of code at runtime. I would like to be able to tell gdb that a host region, say 0x7f00'0ac0-0x7f00'03c0 has the name block_1000_0ac0 because in this example that host region maps to a block generated from the guest address 0x1000'0ac0.

I want this to happen from within my C++ app, so that the JIT can mark the blocks it recompiles with symbols. This will make it so that when I break in gdb I know which guest region my recompiled block maps to.

Is there a way to accomplish this?


Solution

  • This is absolutely possible, though it will be a significant amount of work.

    GDB has a JIT plugin API, the documentation for which can be found here. I think there's too much to describe it here.

    The problem with this plugin API is it's pretty old. I think it was added either before, or at a similar time as the Python API support. If this was being added to GDB today then it would for sure be written as a Python extension. As it is you may end up having to write some C code to make it work.

    If after reading the docs you have more specific questions then it might be worth creating new questions on here.