Skip to content

Commit 561156e

Browse files
committed
Document the JIT interface
1 parent 5f514de commit 561156e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,46 @@ Explanation:
897897
table for compile units emitted by many compilers. Cpptrace uses these by default if they are present since they can
898898
speed up resolution, however, they can also result in significant memory usage.
899899
900+
## JIT Support
901+
902+
Cpptrace has support for resolving symbols from frames in JIT-compiled code. To do this, cpptrace relies on in-memory
903+
object files (elf on linux or mach-o on mac) that contain symbol tables and dwarf debug information. The main reason for
904+
this is many JIT implementations already produce these for debugger support.
905+
906+
These in-memory object files must be set up in such a way that the symbol table and debug symbol addresses match the
907+
run-time addresses of the JIT code.
908+
909+
The basic interface for informing cpptrace about these in-memory object files is as follows:
910+
911+
```cpp
912+
namespace cpptrace {
913+
void register_jit_object(const char*, std::size_t);
914+
void unregister_jit_object(const char*);
915+
void clear_all_jit_objects();
916+
}
917+
```
918+
919+
Many JIT implementations follow the GDB [JIT Compilation Interface][jitci] so that JIT code can be debugged. The
920+
interface, at a high level, entails adding in-memory object files to a linked list of object files that GDB and other
921+
debuggers can reference (stored in the `__jit_debug_descriptor`). Cpptrace provides, as a utility, a mechanism for
922+
loading all in-memory object files present in the `__jit_debug_descriptor` linked list via `<cpptrace/gdb_jit.hpp>`:
923+
924+
```cpp
925+
namespace cpptrace {
926+
namespace experimental {
927+
void register_jit_objects_from_gdb_jit_interface();
928+
}
929+
}
930+
```
931+
932+
Note: Your program must be able to link against a global C symbol `__jit_debug_descriptor`.
933+
934+
Note: Calling `cpptrace::experimental::register_jit_objects_from_gdb_jit_interface` clears all jit objects previously
935+
registered with cpptrace.
936+
937+
938+
[jitci]: https://sourceware.org/gdb/current/onlinedocs/gdb.html/JIT-Interface.html
939+
900940
# Supported Debug Formats
901941
902942
| Format | Supported |

0 commit comments

Comments
 (0)