[llvm] [llvm-c] Expose debug object registration in Orc C-API bindings (PR #73257)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 14:58:24 PST 2023
https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/73257
>From 74340b3032e5caf135e0dbb14d9ea2c8ad7af581 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Wed, 29 Nov 2023 23:22:22 +0100
Subject: [PATCH 1/2] [llvm-c] Expose debug support for LLJIT in Orc bindings
---
llvm/include/llvm-c/LLJIT.h | 6 ++
.../Orc/Debugging/DebuggerSupport.cpp | 2 +-
.../ExecutionEngine/Orc/OrcV2CBindings.cpp | 5 ++
.../ExecutionEngine/Orc/CMakeLists.txt | 1 +
.../ExecutionEngine/Orc/OrcCAPITest.cpp | 64 +++++++++++++++++++
5 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm-c/LLJIT.h b/llvm/include/llvm-c/LLJIT.h
index a06133aac4fb0630..88a2261aacd66867 100644
--- a/llvm/include/llvm-c/LLJIT.h
+++ b/llvm/include/llvm-c/LLJIT.h
@@ -242,6 +242,12 @@ LLVMOrcIRTransformLayerRef LLVMOrcLLJITGetIRTransformLayer(LLVMOrcLLJITRef J);
*/
const char *LLVMOrcLLJITGetDataLayoutStr(LLVMOrcLLJITRef J);
+/**
+ * Install the plugin that submits debug objects to the executor. Executors must
+ * expose the llvm_orc_registerJITLoaderGDBWrapper symbol.
+ */
+LLVMErrorRef LLVMOrcLLJITEnableDebugSupport(LLVMOrcLLJITRef J);
+
/**
* @}
*/
diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupport.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupport.cpp
index 9ba6dd90f50de51a..1668473c0eb47498 100644
--- a/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupport.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupport.cpp
@@ -39,7 +39,7 @@ Error enableDebuggerSupport(LLJIT &J) {
if (!Registrar)
return Registrar.takeError();
ObjLinkingLayer->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
- ES, std::move(*Registrar), true, true));
+ ES, std::move(*Registrar), false, true));
return Error::success();
}
case Triple::MachO: {
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
index 72314cceedf33f60..698cb3241cb3d419 100644
--- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp
@@ -11,6 +11,7 @@
#include "llvm-c/OrcEE.h"
#include "llvm-c/TargetMachine.h"
+#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
@@ -1179,3 +1180,7 @@ void LLVMOrcDisposeLazyCallThroughManager(
LLVMOrcLazyCallThroughManagerRef LCM) {
std::unique_ptr<LazyCallThroughManager> TmpLCM(unwrap(LCM));
}
+
+LLVMErrorRef LLVMOrcLLJITEnableDebugSupport(LLVMOrcLLJITRef J) {
+ return wrap(llvm::orc::enableDebuggerSupport(*unwrap(J)));
+}
diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
index 37768e91fd447290..f102ba59e3754256 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
IRReader
JITLink
Object
+ OrcDebugging
OrcJIT
OrcShared
OrcTargetProcess
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index cbdd4af47e1d47da..7b3be6532944ea8b 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -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__) and not defined(__MACH__))
+TEST_F(OrcCAPITestBase, DISABLED_EnableDebugSupport) {
+#else
+TEST_F(OrcCAPITestBase, EnableDebugSupport) {
+#endif
+ if (LLVMErrorRef E = LLVMOrcLLJITEnableDebugSupport(Jit))
+ FAIL() << "Error testing LLJIT debug support (triple = " << TargetTriple
+ << "): " << toString(E);
+
+ void *Before = findLastDebugDescriptorEntryPtr();
+ LLVMMemoryBufferRef ObjBuffer = createTestObject(SumExample, "sum.ll");
+ LLVMOrcObjectLayerRef ObjLayer = LLVMOrcLLJITGetObjLinkingLayer(Jit);
+ if (LLVMErrorRef E =
+ LLVMOrcObjectLayerAddObjectFile(ObjLayer, MainDylib, ObjBuffer))
+ FAIL() << "Failed to add object file to ObjLinkingLayer (triple = "
+ << TargetTriple << "): " << toString(E);
+
+ LLVMOrcJITTargetAddress SumAddr;
+ if (LLVMErrorRef E = LLVMOrcLLJITLookup(Jit, &SumAddr, "sum"))
+ FAIL() << "Symbol \"sum\" was not added into JIT (triple = " << TargetTriple
+ << "): " << toString(E);
+
+ void *After = findLastDebugDescriptorEntryPtr();
+ ASSERT_NE(Before, After);
+}
+
#if defined(_AIX)
TEST_F(OrcCAPITestBase, DISABLED_ExecutionTest) {
#else
>From bf47a4b412e6eed0aedc2e2995c40d9b40dc1bb2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Wed, 29 Nov 2023 23:51:36 +0100
Subject: [PATCH 2/2] Temporarily disable the test for MachO
---
llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index 7b3be6532944ea8b..04d41eeb37f1f7d5 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -532,7 +532,7 @@ static void *findLastDebugDescriptorEntryPtr() {
}
}
-#if defined(_AIX) or (not defined(__ELF__) and not defined(__MACH__))
+#if defined(_AIX) or not defined(__ELF__)
TEST_F(OrcCAPITestBase, DISABLED_EnableDebugSupport) {
#else
TEST_F(OrcCAPITestBase, EnableDebugSupport) {
More information about the llvm-commits
mailing list