LLVM 20.0.0git
JITLoaderGDB.cpp
Go to the documentation of this file.
1//===- JITLoaderGDB.h - Register objects via GDB JIT interface -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
13
14#include <cstdint>
15#include <mutex>
16
17#define DEBUG_TYPE "orc"
18
19// First version as landed in August 2009
20static constexpr uint32_t JitDescriptorVersion = 1;
21
22extern "C" {
23
24// We put information about the JITed function in this global, which the
25// debugger reads. Make sure to specify the version statically, because the
26// debugger checks the version before we can set it during runtime.
29 nullptr, nullptr};
30
31// Debuggers that implement the GDB JIT interface put a special breakpoint in
32// this function.
35 // The noinline and the asm prevent calls to this function from being
36 // optimized out.
37#if !defined(_MSC_VER)
38 asm volatile("" ::: "memory");
39#endif
40}
41}
42
43using namespace llvm;
44using namespace llvm::orc;
45
46// Register debug object, return error message or null for success.
47static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size) {
49 dbgs() << "Adding debug object to GDB JIT interface "
50 << formatv("([{0:x16} -- {1:x16}])",
51 reinterpret_cast<uintptr_t>(ObjAddr),
52 reinterpret_cast<uintptr_t>(ObjAddr + Size))
53 << "\n";
54 });
55
57 E->symfile_addr = ObjAddr;
58 E->symfile_size = Size;
59 E->prev_entry = nullptr;
60
61 // Serialize rendezvous with the debugger as well as access to shared data.
62 static std::mutex JITDebugLock;
63 std::lock_guard<std::mutex> Lock(JITDebugLock);
64
65 // Insert this entry at the head of the list.
67 E->next_entry = NextEntry;
68 if (NextEntry) {
69 NextEntry->prev_entry = E;
70 }
71
75}
76
79 using namespace orc::shared;
80 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
81 Data, Size,
82 [](ExecutorAddrRange R, bool AutoRegisterCode) {
83 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
84 R.size());
85 // Run into the rendezvous breakpoint.
86 if (AutoRegisterCode)
88 return Error::success();
89 })
90 .release();
91}
92
95 using namespace orc::shared;
96 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
97 Data, Size,
98 [](ExecutorAddrRange R, bool AutoRegisterCode) {
99 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
100 R.size());
101 // Run into the rendezvous breakpoint.
102 if (AutoRegisterCode)
104 return Error::success();
105 })
106 .release();
107}
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
Definition: Compiler.h:330
#define LLVM_ALWAYS_EXPORT
Definition: Compiler.h:141
#define LLVM_DEBUG(...)
Definition: Debug.h:106
uint64_t Size
LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code()
static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size)
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBAllocAction(const char *Data, size_t Size)
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size)
LLVM_ALWAYS_EXPORT struct jit_descriptor __jit_debug_descriptor
static constexpr uint32_t JitDescriptorVersion
@ JIT_REGISTER_FN
Definition: JITLoaderGDB.h:25
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Definition: JITLoaderGDB.h:29
struct jit_code_entry * prev_entry
Definition: JITLoaderGDB.h:31
const char * symfile_addr
Definition: JITLoaderGDB.h:32
struct jit_code_entry * next_entry
Definition: JITLoaderGDB.h:30
uint32_t action_flag
Definition: JITLoaderGDB.h:40
struct jit_code_entry * relevant_entry
Definition: JITLoaderGDB.h:41
struct jit_code_entry * first_entry
Definition: JITLoaderGDB.h:42
Represents an address range in the exceutor process.