Skip to content

Commit 99a6d00

Browse files
[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
1 parent ef23892 commit 99a6d00

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

llvm/lib/ExecutionEngine/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_llvm_component_library(LLVMExecutionEngine
1717
Core
1818
MC
1919
Object
20+
OrcTargetProcess
2021
RuntimeDyld
2122
Support
2223
Target

llvm/lib/ExecutionEngine/GDBRegistrationListener.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,28 @@ extern "C" {
4747
// We put information about the JITed function in this global, which the
4848
// debugger reads. Make sure to specify the version statically, because the
4949
// debugger checks the version before we can set it during runtime.
50-
struct jit_descriptor __jit_debug_descriptor = { 1, 0, nullptr, nullptr };
50+
extern struct jit_descriptor __jit_debug_descriptor;
5151

5252
// Debuggers puts a breakpoint in this function.
53-
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
54-
// The noinline and the asm prevent calls to this function from being
55-
// optimized out.
56-
#if !defined(_MSC_VER)
57-
asm volatile("":::"memory");
58-
#endif
59-
}
60-
53+
extern "C" void __jit_debug_register_code();
6154
}
6255

6356
namespace {
6457

58+
// FIXME: lli aims to provide both, RuntimeDyld and JITLink, as the dynamic
59+
// loaders for it's JIT implementations. And they both offer debugging via the
60+
// GDB JIT interface, which builds on the two well-known symbol names below.
61+
// As these symbols must be unique accross the linked executable, we can only
62+
// define them in one of the libraries and make the other depend on it.
63+
// OrcTargetProcess is a minimal stub for embedding a JIT client in remote
64+
// executors. For the moment it seems reasonable to have the definition there
65+
// and let ExecutionEngine depend on it, until we find a better solution.
66+
//
67+
LLVM_ATTRIBUTE_USED void requiredSymbolDefinitionsFromOrcTargetProcess() {
68+
errs() << (void *)&__jit_debug_register_code
69+
<< (void *)&__jit_debug_descriptor;
70+
}
71+
6572
struct RegisteredObjectInfo {
6673
RegisteredObjectInfo() {}
6774

llvm/tools/lli/lli.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/ExecutionEngine/JITEventListener.h"
2727
#include "llvm/ExecutionEngine/MCJIT.h"
2828
#include "llvm/ExecutionEngine/ObjectCache.h"
29+
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
2930
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
3031
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
3132
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
@@ -34,7 +35,9 @@
3435
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
3536
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
3637
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
38+
#include "llvm/ExecutionEngine/Orc/TPCDebugObjectRegistrar.h"
3739
#include "llvm/ExecutionEngine/Orc/TPCEHFrameRegistrar.h"
40+
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
3841
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
3942
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
4043
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
@@ -277,7 +280,8 @@ namespace {
277280

278281
LLVM_ATTRIBUTE_USED void linkComponents() {
279282
errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper
280-
<< (void *)&llvm_orc_deregisterEHFrameSectionWrapper;
283+
<< (void *)&llvm_orc_deregisterEHFrameSectionWrapper
284+
<< (void *)&llvm_orc_registerJITLoaderGDBWrapper;
281285
}
282286

283287
//===----------------------------------------------------------------------===//
@@ -923,6 +927,8 @@ int runOrcLazyJIT(const char *ProgName) {
923927
auto L = std::make_unique<orc::ObjectLinkingLayer>(ES, TPC->getMemMgr());
924928
L->addPlugin(std::make_unique<orc::EHFrameRegistrationPlugin>(
925929
ES, ExitOnErr(orc::TPCEHFrameRegistrar::Create(*TPC))));
930+
L->addPlugin(std::make_unique<orc::DebugObjectManagerPlugin>(
931+
ES, ExitOnErr(orc::createJITLoaderGDBRegistrar(*TPC))));
926932
return L;
927933
});
928934
}

0 commit comments

Comments
 (0)