450 changes: 450 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/DebuggerSupportPlugin.cpp

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ManagedStatic.h"

#include <cstdint>
Expand Down Expand Up @@ -70,10 +71,18 @@ using namespace llvm::orc;
ManagedStatic<std::mutex> JITDebugLock;

// Register debug object, return error message or null for success.
static void registerJITLoaderGDBImpl(ExecutorAddrRange DebugObjRange) {
static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size) {
LLVM_DEBUG({
dbgs() << "Registering debug object with GDB JIT interface "
<< formatv("([{0:x16} -- {1:x16}])",
reinterpret_cast<uintptr_t>(ObjAddr),
reinterpret_cast<uintptr_t>(ObjAddr + Size))
<< "\n";
});

jit_code_entry *E = new jit_code_entry;
E->symfile_addr = DebugObjRange.Start.toPtr<const char *>();
E->symfile_size = DebugObjRange.size().getValue();
E->symfile_addr = ObjAddr;
E->symfile_size = Size;
E->prev_entry = nullptr;

std::lock_guard<std::mutex> Lock(*JITDebugLock);
Expand All @@ -93,10 +102,26 @@ static void registerJITLoaderGDBImpl(ExecutorAddrRange DebugObjRange) {
__jit_debug_register_code();
}

extern "C" orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderGDBAllocAction(const char *Data, size_t Size) {
using namespace orc::shared;
return WrapperFunction<SPSError()>::handle(nullptr, 0,
[=]() -> Error {
registerJITLoaderGDBImpl(Data,
Size);
return Error::success();
})
.release();
}

extern "C" orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size) {
using namespace orc::shared;
return WrapperFunction<void(SPSExecutorAddrRange)>::handle(
Data, Size, registerJITLoaderGDBImpl)
Data, Size,
[](ExecutorAddrRange R) {
registerJITLoaderGDBImpl(R.Start.toPtr<char *>(),
R.size().getValue());
})
.release();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# REQUIRES: asserts
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s
# RUN: llvm-jitlink -debug-only=orc -noexec %t 2>&1 | FileCheck %s
#
# Check that presence of a "__DWARF" section triggers the
# GDBJITDebugInfoRegistrationPlugin.
#
# CHECK: Registering debug object with GDB JIT interface

.section __TEXT,__text,regular,pure_instructions
.globl _main
.p2align 4, 0x90
_main:
xorl %eax, %eax
retq

.section __DWARF,__debug_str,regular,debug
Linfo_string:
.asciz "test dwarf string"

.subsections_via_symbols
21 changes: 0 additions & 21 deletions llvm/test/ExecutionEngine/JITLink/X86/MachO_skip_debug_sections.s

This file was deleted.

8 changes: 7 additions & 1 deletion llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "llvm/BinaryFormat/Magic.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
Expand Down Expand Up @@ -987,8 +988,13 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
ExitOnErr(loadProcessSymbols(*this));
ExitOnErr(loadDylibs(*this));

// Set up the platform.
auto &TT = ES.getExecutorProcessControl().getTargetTriple();

if (TT.isOSBinFormatMachO())
ObjLayer.addPlugin(ExitOnErr(
GDBJITDebugInfoRegistrationPlugin::Create(this->ES, *MainJD, TT)));

// Set up the platform.
if (TT.isOSBinFormatMachO() && !OrcRuntime.empty()) {
if (auto P =
MachOPlatform::Create(ES, ObjLayer, *MainJD, OrcRuntime.c_str()))
Expand Down