LLVM 18.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
14
15#include <cstdint>
16#include <mutex>
17#include <utility>
18
19#define DEBUG_TYPE "orc"
20
21// First version as landed in August 2009
22static constexpr uint32_t JitDescriptorVersion = 1;
23
24// Keep in sync with gdb/gdb/jit.h
25extern "C" {
26
27typedef enum {
32
33struct jit_code_entry {
36 const char *symfile_addr;
38};
39
40struct jit_descriptor {
42 // This should be jit_actions_t, but we want to be specific about the
43 // bit-width.
47};
48
49// We put information about the JITed function in this global, which the
50// debugger reads. Make sure to specify the version statically, because the
51// debugger checks the version before we can set it during runtime.
53 nullptr, nullptr};
54
55// Debuggers that implement the GDB JIT interface put a special breakpoint in
56// this function.
58 // The noinline and the asm prevent calls to this function from being
59 // optimized out.
60#if !defined(_MSC_VER)
61 asm volatile("" ::: "memory");
62#endif
63}
64}
65
66using namespace llvm;
67using namespace llvm::orc;
68
69// Register debug object, return error message or null for success.
70static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size) {
72 dbgs() << "Adding debug object to GDB JIT interface "
73 << formatv("([{0:x16} -- {1:x16}])",
74 reinterpret_cast<uintptr_t>(ObjAddr),
75 reinterpret_cast<uintptr_t>(ObjAddr + Size))
76 << "\n";
77 });
78
80 E->symfile_addr = ObjAddr;
81 E->symfile_size = Size;
82 E->prev_entry = nullptr;
83
84 // Serialize rendezvous with the debugger as well as access to shared data.
85 static std::mutex JITDebugLock;
86 std::lock_guard<std::mutex> Lock(JITDebugLock);
87
88 // Insert this entry at the head of the list.
90 E->next_entry = NextEntry;
91 if (NextEntry) {
92 NextEntry->prev_entry = E;
93 }
94
98}
99
102 using namespace orc::shared;
103 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
104 Data, Size,
105 [](ExecutorAddrRange R, bool AutoRegisterCode) {
106 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
107 R.size());
108 // Run into the rendezvous breakpoint.
109 if (AutoRegisterCode)
111 return Error::success();
112 })
113 .release();
114}
115
118 using namespace orc::shared;
119 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
120 Data, Size,
121 [](ExecutorAddrRange R, bool AutoRegisterCode) {
122 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
123 R.size());
124 // Run into the rendezvous breakpoint.
125 if (AutoRegisterCode)
127 return Error::success();
128 })
129 .release();
130}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#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:232
#define LLVM_DEBUG(X)
Definition: Debug.h:101
uint64_t Size
struct jit_descriptor __jit_debug_descriptor
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code()
static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size)
jit_actions_t
@ JIT_UNREGISTER_FN
@ JIT_REGISTER_FN
@ JIT_NOACTION
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBAllocAction(const char *Data, size_t Size)
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size)
static constexpr uint32_t JitDescriptorVersion
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
struct jit_code_entry * prev_entry
const char * symfile_addr
uint64_t symfile_size
struct jit_code_entry * next_entry
struct jit_code_entry * relevant_entry
struct jit_code_entry * first_entry
Represents an address range in the exceutor process.