LLVM 22.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.
28 JitDescriptorVersion, 0, nullptr, nullptr};
29
30// Debuggers that implement the GDB JIT interface put a special breakpoint in
31// this function.
34 // The noinline and the asm prevent calls to this function from being
35 // optimized out.
36#if !defined(_MSC_VER)
37 asm volatile("" ::: "memory");
38#endif
39}
40}
41
42using namespace llvm;
43using namespace llvm::orc;
44
45// Register debug object, return error message or null for success.
46static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size) {
48 dbgs() << "Adding debug object to GDB JIT interface "
49 << formatv("([{0:x16} -- {1:x16}])",
50 reinterpret_cast<uintptr_t>(ObjAddr),
51 reinterpret_cast<uintptr_t>(ObjAddr + Size))
52 << "\n";
53 });
54
56 E->symfile_addr = ObjAddr;
57 E->symfile_size = Size;
58 E->prev_entry = nullptr;
59
60 // Serialize rendezvous with the debugger as well as access to shared data.
61 static std::mutex JITDebugLock;
62 std::lock_guard<std::mutex> Lock(JITDebugLock);
63
64 // Insert this entry at the head of the list.
66 E->next_entry = NextEntry;
67 if (NextEntry) {
68 NextEntry->prev_entry = E;
69 }
70
74}
75
77llvm_orc_registerJITLoaderGDBAllocAction(const char *ArgData, size_t ArgSize) {
78 using namespace orc::shared;
79 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
80 ArgData, ArgSize,
81 [](ExecutorAddrRange R, bool AutoRegisterCode) {
82 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
83 R.size());
84 // Run into the rendezvous breakpoint.
85 if (AutoRegisterCode)
87 return Error::success();
88 })
89 .release();
90}
91
93llvm_orc_registerJITLoaderGDBWrapper(const char *ArgData, size_t ArgSize) {
94 using namespace orc::shared;
95 return WrapperFunction<SPSError(SPSExecutorAddrRange, bool)>::handle(
96 ArgData, ArgSize,
97 [](ExecutorAddrRange R, bool AutoRegisterCode) {
98 appendJITDebugDescriptor(R.Start.toPtr<const char *>(),
99 R.size());
100 // Run into the rendezvous breakpoint.
101 if (AutoRegisterCode)
103 return Error::success();
104 })
105 .release();
106}
#define LLVM_ABI
Definition: Compiler.h:213
#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:346
#define LLVM_ALWAYS_EXPORT
Definition: Compiler.h:145
uint64_t Size
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBAllocAction(const char *ArgData, size_t ArgSize)
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBWrapper(const char *ArgData, size_t ArgSize)
static void appendJITDebugDescriptor(const char *ObjAddr, size_t Size)
LLVM_ABI LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code()
static constexpr uint32_t JitDescriptorVersion
LLVM_ABI LLVM_ALWAYS_EXPORT struct jit_descriptor __jit_debug_descriptor
@ JIT_REGISTER_FN
Definition: JITLoaderGDB.h:25
#define LLVM_DEBUG(...)
Definition: Debug.h:119
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
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.