[llvm] [llvm-c] Expose debug support for LLJIT in Orc C-API bindings (PR #73257)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 14:21:39 PST 2023


Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/73257 at github.com>


================
@@ -494,6 +494,70 @@ TEST_F(OrcCAPITestBase, AddObjectBuffer) {
   ASSERT_TRUE(!!SumAddr);
 }
 
+// This must be kept in sync with gdb/gdb/jit.h .
+extern "C" {
+
+typedef enum {
+  JIT_NOACTION = 0,
+  JIT_REGISTER_FN,
+  JIT_UNREGISTER_FN
+} jit_actions_t;
+
+struct jit_code_entry {
+  struct jit_code_entry *next_entry;
+  struct jit_code_entry *prev_entry;
+  const char *symfile_addr;
+  uint64_t symfile_size;
+};
+
+struct jit_descriptor {
+  uint32_t version;
+  // This should be jit_actions_t, but we want to be specific about the
+  // bit-width.
+  uint32_t action_flag;
+  struct jit_code_entry *relevant_entry;
+  struct jit_code_entry *first_entry;
+};
+
+// We put information about the JITed function in this global, which the
+// debugger reads.  Make sure to specify the version statically, because the
+// debugger checks the version before we can set it during runtime.
+struct jit_descriptor __jit_debug_descriptor;
+
+static void *findLastDebugDescriptorEntryPtr() {
+  struct jit_code_entry *Last = __jit_debug_descriptor.first_entry;
+  while (Last && Last->next_entry)
+    Last = Last->next_entry;
+  return Last;
+}
+}
+
+#if defined(_AIX) or not defined(__ELF__)
----------------
lhames wrote:

> > The MachO plugin just bails out early if there's no debug info, right? I think that's reasonable behavior.
> 
> Not sure. I think it's confusing for users. People are used to have symbol names in non-debug builds, so they can at least set breakpoints on their functions. With the bail out behavior here they have nothing at all and it's not immediately obvious why. It's one of too many things that can go wrong in JITed code debugging.

Regarding that: I'm working on some lighter-weight symbolication solutions that we could use to enable breakpoints (and symbolicated backtraces) for JIT'd code, even in the case of a crashed executor. So hopefully this situation will be temporary. :)

https://github.com/llvm/llvm-project/pull/73257


More information about the llvm-commits mailing list