[llvm] 99a6d00 - [lli] Add JITLink in-process debug support

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 2 06:08:21 PST 2021


Author: Stefan Gränitz
Date: 2021-03-02T15:07:36+01:00
New Revision: 99a6d003edbe97fcb94854547276ffad3382ec1d

URL: https://github.com/llvm/llvm-project/commit/99a6d003edbe97fcb94854547276ffad3382ec1d
DIFF: https://github.com/llvm/llvm-project/commit/99a6d003edbe97fcb94854547276ffad3382ec1d.diff

LOG: [lli] Add JITLink in-process debug support

lli aims to provide both, RuntimeDyld and JITLink, as the dynamic linkers/loaders for it's JIT implementations. And they both offer debugging via the GDB JIT interface, which builds on the two well-known symbol names `__jit_debug_descriptor` and `__jit_debug_register_code`. As these symbols must be unique accross the linked executable, we can only define them in one of the libraries and make the other depend on it. OrcTargetProcess is a minimal stub for embedding a JIT client in remote executors. For the moment it seems reasonable to have the definition there and let ExecutionEngine depend on it, until we find a better solution.

This is the second commit for the reviewed patch.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D97339

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/CMakeLists.txt
    llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
    llvm/tools/lli/lli.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/CMakeLists.txt b/llvm/lib/ExecutionEngine/CMakeLists.txt
index 22203da90f7a..a5607872c706 100644
--- a/llvm/lib/ExecutionEngine/CMakeLists.txt
+++ b/llvm/lib/ExecutionEngine/CMakeLists.txt
@@ -17,6 +17,7 @@ add_llvm_component_library(LLVMExecutionEngine
   Core
   MC
   Object
+  OrcTargetProcess
   RuntimeDyld
   Support
   Target

diff  --git a/llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp b/llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
index 7ed025fbb481..e15bce0d6c4b 100644
--- a/llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
+++ b/llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp
@@ -47,21 +47,28 @@ extern "C" {
   // 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 = { 1, 0, nullptr, nullptr };
+  extern struct jit_descriptor __jit_debug_descriptor;
 
   // Debuggers puts a breakpoint in this function.
-  LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
-    // The noinline and the asm prevent calls to this function from being
-    // optimized out.
-#if !defined(_MSC_VER)
-    asm volatile("":::"memory");
-#endif
-  }
-
+  extern "C" void __jit_debug_register_code();
 }
 
 namespace {
 
+// FIXME: lli aims to provide both, RuntimeDyld and JITLink, as the dynamic
+// loaders for it's JIT implementations. And they both offer debugging via the
+// GDB JIT interface, which builds on the two well-known symbol names below.
+// As these symbols must be unique accross the linked executable, we can only
+// define them in one of the libraries and make the other depend on it.
+// OrcTargetProcess is a minimal stub for embedding a JIT client in remote
+// executors. For the moment it seems reasonable to have the definition there
+// and let ExecutionEngine depend on it, until we find a better solution.
+//
+LLVM_ATTRIBUTE_USED void requiredSymbolDefinitionsFromOrcTargetProcess() {
+  errs() << (void *)&__jit_debug_register_code
+         << (void *)&__jit_debug_descriptor;
+}
+
 struct RegisteredObjectInfo {
   RegisteredObjectInfo() {}
 

diff  --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 4b8ea50c92b5..66b2c13c426f 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ExecutionEngine/JITEventListener.h"
 #include "llvm/ExecutionEngine/MCJIT.h"
 #include "llvm/ExecutionEngine/ObjectCache.h"
+#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
 #include "llvm/ExecutionEngine/Orc/DebugUtils.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
@@ -34,7 +35,9 @@
 #include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
+#include "llvm/ExecutionEngine/Orc/TPCDebugObjectRegistrar.h"
 #include "llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
 #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
 #include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
@@ -277,7 +280,8 @@ namespace {
 
 LLVM_ATTRIBUTE_USED void linkComponents() {
   errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper
-         << (void *)&llvm_orc_deregisterEHFrameSectionWrapper;
+         << (void *)&llvm_orc_deregisterEHFrameSectionWrapper
+         << (void *)&llvm_orc_registerJITLoaderGDBWrapper;
 }
 
 //===----------------------------------------------------------------------===//
@@ -923,6 +927,8 @@ int runOrcLazyJIT(const char *ProgName) {
       auto L = std::make_unique<orc::ObjectLinkingLayer>(ES, TPC->getMemMgr());
       L->addPlugin(std::make_unique<orc::EHFrameRegistrationPlugin>(
           ES, ExitOnErr(orc::TPCEHFrameRegistrar::Create(*TPC))));
+      L->addPlugin(std::make_unique<orc::DebugObjectManagerPlugin>(
+          ES, ExitOnErr(orc::createJITLoaderGDBRegistrar(*TPC))));
       return L;
     });
   }


        


More information about the llvm-commits mailing list