LLVM  15.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 
15 
16 #include <cstdint>
17 #include <mutex>
18 #include <utility>
19 
20 #define DEBUG_TYPE "orc"
21 
22 // First version as landed in August 2009
23 static constexpr uint32_t JitDescriptorVersion = 1;
24 
25 // Keep in sync with gdb/gdb/jit.h
26 extern "C" {
27 
28 typedef enum {
33 
34 struct jit_code_entry {
35  struct jit_code_entry *next_entry;
36  struct jit_code_entry *prev_entry;
37  const char *symfile_addr;
39 };
40 
41 struct jit_descriptor {
43  // This should be jit_actions_t, but we want to be specific about the
44  // bit-width.
48 };
49 
50 // We put information about the JITed function in this global, which the
51 // debugger reads. Make sure to specify the version statically, because the
52 // debugger checks the version before we can set it during runtime.
54  nullptr, nullptr};
55 
56 // Debuggers that implement the GDB JIT interface put a special breakpoint in
57 // this function.
59  // The noinline and the asm prevent calls to this function from being
60  // optimized out.
61 #if !defined(_MSC_VER)
62  asm volatile("" ::: "memory");
63 #endif
64 }
65 }
66 
67 using namespace llvm;
68 using namespace llvm::orc;
69 
70 // Serialize rendezvous with the debugger as well as access to shared data.
72 
73 // Register debug object, return error message or null for success.
74 static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size) {
75  LLVM_DEBUG({
76  dbgs() << "Registering debug object with GDB JIT interface "
77  << formatv("([{0:x16} -- {1:x16}])",
78  reinterpret_cast<uintptr_t>(ObjAddr),
79  reinterpret_cast<uintptr_t>(ObjAddr + Size))
80  << "\n";
81  });
82 
84  E->symfile_addr = ObjAddr;
85  E->symfile_size = Size;
86  E->prev_entry = nullptr;
87 
88  std::lock_guard<std::mutex> Lock(*JITDebugLock);
89 
90  // Insert this entry at the head of the list.
92  E->next_entry = NextEntry;
93  if (NextEntry) {
94  NextEntry->prev_entry = E;
95  }
96 
99 
100  // Run into the rendezvous breakpoint.
103 }
104 
107  using namespace orc::shared;
108  return WrapperFunction<SPSError(SPSExecutorAddrRange)>::handle(
109  Data, Size,
110  [](ExecutorAddrRange R) {
111  registerJITLoaderGDBImpl(R.Start.toPtr<const char *>(),
112  R.size());
113  return Error::success();
114  })
115  .release();
116 }
117 
120  using namespace orc::shared;
121  return WrapperFunction<SPSError(SPSExecutorAddrRange)>::handle(
122  Data, Size,
123  [](ExecutorAddrRange R) {
124  registerJITLoaderGDBImpl(R.Start.toPtr<const char *>(),
125  R.size());
126  return Error::success();
127  })
128  .release();
129 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:76
jit_descriptor::relevant_entry
struct jit_code_entry * relevant_entry
Definition: GDBRegistrationListener.cpp:44
BinaryStreamReader.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
JITLoaderGDB.h
JITSymbol.h
llvm::orc::shared::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:33
llvm::orc::shared::SPSExecutorAddrRange
SPSTuple< SPSExecutorAddr, SPSExecutorAddr > SPSExecutorAddrRange
Definition: ExecutorAddress.h:207
llvm_orc_registerJITLoaderGDBAllocAction
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBAllocAction(const char *Data, size_t Size)
Definition: JITLoaderGDB.cpp:106
JITDebugLock
ManagedStatic< std::mutex > JITDebugLock
Definition: JITLoaderGDB.cpp:71
ManagedStatic.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
jit_code_entry
Definition: GDBRegistrationListener.cpp:32
jit_descriptor::version
uint32_t version
Definition: GDBRegistrationListener.cpp:40
llvm::AtomicOrderingCABI::release
@ release
handle
then ret i32 result Tail recursion elimination should handle
Definition: README.txt:355
JitDescriptorVersion
static constexpr uint32_t JitDescriptorVersion
Definition: JITLoaderGDB.cpp:23
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:240
__jit_debug_register_code
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code()
Definition: JITLoaderGDB.cpp:58
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
JIT_UNREGISTER_FN
@ JIT_UNREGISTER_FN
Definition: JITLoaderGDB.cpp:31
llvm::orc
Definition: CompileOnDemandLayer.h:54
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:148
FormatVariadic.h
jit_code_entry::symfile_addr
const char * symfile_addr
Definition: GDBRegistrationListener.cpp:35
llvm_orc_registerJITLoaderGDBWrapper
orc::shared::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size)
Definition: JITLoaderGDB.cpp:119
JIT_NOACTION
@ JIT_NOACTION
Definition: JITLoaderGDB.cpp:29
uint64_t
jit_code_entry::next_entry
struct jit_code_entry * next_entry
Definition: GDBRegistrationListener.cpp:33
jit_actions_t
jit_actions_t
Definition: JITLoaderGDB.cpp:28
jit_descriptor::action_flag
uint32_t action_flag
Definition: GDBRegistrationListener.cpp:43
uint32_t
jit_descriptor::first_entry
struct jit_code_entry * first_entry
Definition: GDBRegistrationListener.cpp:45
jit_code_entry::symfile_size
uint64_t symfile_size
Definition: GDBRegistrationListener.cpp:36
registerJITLoaderGDBImpl
static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size)
Definition: JITLoaderGDB.cpp:74
__jit_debug_descriptor
struct jit_descriptor __jit_debug_descriptor
Definition: JITLoaderGDB.cpp:53
LLVM_ATTRIBUTE_NOINLINE
#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:230
jit_code_entry::prev_entry
struct jit_code_entry * prev_entry
Definition: GDBRegistrationListener.cpp:34
JIT_REGISTER_FN
@ JIT_REGISTER_FN
Definition: JITLoaderGDB.cpp:30
jit_descriptor
Definition: GDBRegistrationListener.cpp:39