Skip to content

Commit

Permalink
Merge pull request #82 from frasercrmck/gdb-jit-listener
Browse files Browse the repository at this point in the history
[host] Add better debugger integration with OrcJIT
  • Loading branch information
frasercrmck authored Aug 8, 2023
2 parents 4a85d73 + 040b1b8 commit 8e895d8
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions modules/compiler/targets/host/source/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h>
#include <llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h>
#include <llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h>
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
#include <llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/IR/DiagnosticInfo.h>
#include <llvm/IR/DiagnosticPrinter.h>
#include <llvm/IR/LLVMContext.h>
Expand Down Expand Up @@ -199,25 +201,27 @@ compiler::Result HostTarget::initWithBuiltins(

Builder.setJITTargetMachineBuilder(TMBuilder);

// On 64-bit non-Windows platforms, customize the JIT linking layer.
if (triple.isArch64Bit() && host_device_info.os != host::os::WINDOWS) {
Builder.setObjectLinkingLayerCreator(
[](llvm::orc::ExecutionSession &ES, const llvm::Triple &)
-> llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>> {
auto ObjLinkingLayer =
std::make_unique<llvm::orc::ObjectLinkingLayer>(ES);
// Don't create a EPCEHFrameRegistrar like the default object
// linking layer does; the symbols aren't in our process's dylib,
// and it's not clear that we need it when we don't allow exceptions
// in kernels. Until that question's resolved, resort to the LLVM 16
// way of doing things: using InProcessEHFrameRegistrar.
ObjLinkingLayer->addPlugin(std::make_unique<
llvm::orc::EHFrameRegistrationPlugin>(
ES,
std::make_unique<llvm::jitlink::InProcessEHFrameRegistrar>()));
return std::move(ObjLinkingLayer);
});
}
// Customize the JIT linking layer to provide better profiler/debugger
// integration.
Builder.setObjectLinkingLayerCreator(
[&](llvm::orc::ExecutionSession &ES, const llvm::Triple &)
-> llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>> {
auto GetMemMgr = []() {
return std::make_unique<llvm::SectionMemoryManager>();
};
auto ObjLinkingLayer =
std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(
ES, std::move(GetMemMgr));

// Register the event listener.
ObjLinkingLayer->registerJITEventListener(
*llvm::JITEventListener::createGDBRegistrationListener());

// Make sure the debug info sections aren't stripped.
ObjLinkingLayer->setProcessAllSections(true);

return std::move(ObjLinkingLayer);
});

auto JIT = Builder.create();
if (auto err = JIT.takeError()) {
Expand Down

0 comments on commit 8e895d8

Please sign in to comment.