Skip to content

Commit 49bfbfa

Browse files
committed
Hooked GDB to JITEventListener, cleaned up jitlayers code
1 parent 0e32871 commit 49bfbfa

File tree

3 files changed

+3
-91
lines changed

3 files changed

+3
-91
lines changed

src/codegen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7480,6 +7480,8 @@ extern "C" void *jl_init_llvm(void)
74807480
jl_data_layout.reset(DL);
74817481
#endif
74827482

7483+
// Register GDB event listener
7484+
jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createGDBRegistrationListener());
74837485
#ifdef JL_USE_INTEL_JITEVENTS
74847486
if (jl_using_intel_jitevents)
74857487
jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createIntelJITEventListener());

src/jitlayers.cpp

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace llvm {
5454
#include <llvm/IR/DataLayout.h>
5555
#include <llvm/Support/DynamicLibrary.h>
5656

57-
5857
#include <llvm/Support/raw_ostream.h>
5958
#include <llvm/Support/FormattedStream.h>
6059
#include <llvm/ADT/StringMap.h>
@@ -70,6 +69,7 @@ using namespace llvm;
7069
#include "julia_assert.h"
7170

7271
RTDyldMemoryManager* createRTDyldMemoryManager(void);
72+
using namespace llvm::object;
7373

7474
static IntegerType *T_uint32;
7575
static IntegerType *T_uint64;
@@ -284,72 +284,6 @@ void jl_add_optimization_passes(LLVMPassManagerRef PM, int opt_level) {
284284
addOptimizationPasses(unwrap(PM), opt_level);
285285
}
286286

287-
// ------------------------ TEMPORARILY COPIED FROM LLVM -----------------
288-
// This must be kept in sync with gdb/gdb/jit.h .
289-
extern "C" {
290-
291-
typedef enum {
292-
JIT_NOACTION = 0,
293-
JIT_REGISTER_FN,
294-
JIT_UNREGISTER_FN
295-
} jit_actions_t;
296-
297-
struct jit_code_entry {
298-
struct jit_code_entry *next_entry;
299-
struct jit_code_entry *prev_entry;
300-
const char *symfile_addr;
301-
uint64_t symfile_size;
302-
};
303-
304-
struct jit_descriptor {
305-
uint32_t version;
306-
// This should be jit_actions_t, but we want to be specific about the
307-
// bit-width.
308-
uint32_t action_flag;
309-
struct jit_code_entry *relevant_entry;
310-
struct jit_code_entry *first_entry;
311-
};
312-
313-
// We put information about the JITed function in this global, which the
314-
// debugger reads. Make sure to specify the version statically, because the
315-
// debugger checks the version before we can set it during runtime.
316-
extern struct jit_descriptor __jit_debug_descriptor;
317-
318-
LLVM_ATTRIBUTE_NOINLINE extern void __jit_debug_register_code();
319-
}
320-
321-
namespace {
322-
323-
// Use a local variable to hold the addresses to avoid generating a PLT
324-
// on the function call.
325-
// It messes up the GDB lookup logic with dynamically linked LLVM.
326-
// (Ref https://sourceware.org/bugzilla/show_bug.cgi?id=20633)
327-
// Use `volatile` to make sure the call always loads this slot.
328-
void (*volatile jit_debug_register_code)() = __jit_debug_register_code;
329-
330-
using namespace llvm;
331-
using namespace llvm::object;
332-
using namespace llvm::orc;
333-
334-
/// Do the registration.
335-
void NotifyDebugger(jit_code_entry *JITCodeEntry)
336-
{
337-
__jit_debug_descriptor.action_flag = JIT_REGISTER_FN;
338-
339-
// Insert this entry at the head of the list.
340-
JITCodeEntry->prev_entry = nullptr;
341-
jit_code_entry *NextEntry = __jit_debug_descriptor.first_entry;
342-
JITCodeEntry->next_entry = NextEntry;
343-
if (NextEntry) {
344-
NextEntry->prev_entry = JITCodeEntry;
345-
}
346-
__jit_debug_descriptor.first_entry = JITCodeEntry;
347-
__jit_debug_descriptor.relevant_entry = JITCodeEntry;
348-
jit_debug_register_code();
349-
}
350-
}
351-
// ------------------------ END OF TEMPORARY COPY FROM LLVM -----------------
352-
353287
#if defined(_OS_LINUX_) || defined(_OS_WINDOWS_) || defined(_OS_FREEBSD_)
354288
// Resolve non-lock free atomic functions in the libatomic1 library.
355289
// This is the library that provides support for c11/c++11 atomic operations.
@@ -401,9 +335,6 @@ void JuliaOJIT::DebugObjectRegistrar::registerObject(RTDyldObjHandleT H, const O
401335
SavedObject = OwningBinary<object::ObjectFile>(std::move(*NewObj),
402336
std::move(NewBuffer));
403337
}
404-
else {
405-
NotifyGDB(SavedObject);
406-
}
407338

408339
JIT.NotifyFinalizer(*Object, *LO);
409340
SavedObjects.push_back(std::move(SavedObject));
@@ -436,7 +367,6 @@ void JuliaOJIT::DebugObjectRegistrar::registerObject(RTDyldObjHandleT H, const O
436367
}
437368
}
438369

439-
// TODO: hook up RegisterJITEventListener, instead of hard-coding the GDB and JuliaListener targets
440370
template <typename ObjSetT, typename LoadResult>
441371
void JuliaOJIT::DebugObjectRegistrar::operator()(RTDyldObjHandleT H,
442372
const ObjSetT &Objects, const LoadResult &LOS)
@@ -456,24 +386,6 @@ void JuliaOJIT::DebugObjectRegistrar::operator()(RTDyldObjHandleT H,
456386
#endif
457387
}
458388

459-
void JuliaOJIT::DebugObjectRegistrar::NotifyGDB(OwningBinary<object::ObjectFile> &DebugObj)
460-
{
461-
const char *Buffer = DebugObj.getBinary()->getMemoryBufferRef().getBufferStart();
462-
size_t Size = DebugObj.getBinary()->getMemoryBufferRef().getBufferSize();
463-
464-
assert(Buffer && "Attempt to register a null object with a debugger.");
465-
jit_code_entry *JITCodeEntry = new jit_code_entry();
466-
467-
if (!JITCodeEntry) {
468-
jl_printf(JL_STDERR, "WARNING: Allocation failed when registering a JIT entry!\n");
469-
}
470-
else {
471-
JITCodeEntry->symfile_addr = Buffer;
472-
JITCodeEntry->symfile_size = Size;
473-
474-
NotifyDebugger(JITCodeEntry);
475-
}
476-
}
477389

478390
object::OwningBinary<object::ObjectFile> JuliaOJIT::CompilerT::operator()(Module &M)
479391
{

src/jitlayers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ using RTDyldObjHandleT = orc::ObjectLinkingLayerBase::ObjSetHandleT;
103103

104104
class JuliaOJIT {
105105
// Custom object emission notification handler for the JuliaOJIT
106-
// TODO: hook up RegisterJITEventListener, instead of hard-coding the GDB and JuliaListener targets
107106
class DebugObjectRegistrar {
108107
public:
109108
DebugObjectRegistrar(JuliaOJIT &JIT);
@@ -112,7 +111,6 @@ class JuliaOJIT {
112111
private:
113112
template <typename ObjT, typename LoadResult>
114113
void registerObject(RTDyldObjHandleT H, const ObjT &Object, const LoadResult &LO);
115-
void NotifyGDB(object::OwningBinary<object::ObjectFile> &DebugObj);
116114
std::vector<object::OwningBinary<object::ObjectFile>> SavedObjects;
117115
std::unique_ptr<JITEventListener> JuliaListener;
118116
JuliaOJIT &JIT;

0 commit comments

Comments
 (0)