LLVM  14.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
22 static constexpr uint32_t JitDescriptorVersion = 1;
23 
24 // Keep in sync with gdb/gdb/jit.h
25 extern "C" {
26 
27 typedef enum {
32 
33 struct jit_code_entry {
34  struct jit_code_entry *next_entry;
35  struct jit_code_entry *prev_entry;
36  const char *symfile_addr;
38 };
39 
40 struct 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 
66 using namespace llvm;
67 using namespace llvm::orc;
68 
69 // Serialize rendezvous with the debugger as well as access to shared data.
71 
72 // Register debug object, return error message or null for success.
73 static void registerJITLoaderGDBImpl(ExecutorAddrRange DebugObjRange) {
75  E->symfile_addr = DebugObjRange.Start.toPtr<const char *>();
76  E->symfile_size = DebugObjRange.size().getValue();
77  E->prev_entry = nullptr;
78 
79  std::lock_guard<std::mutex> Lock(*JITDebugLock);
80 
81  // Insert this entry at the head of the list.
83  E->next_entry = NextEntry;
84  if (NextEntry) {
85  NextEntry->prev_entry = E;
86  }
87 
90 
91  // Run into the rendezvous breakpoint.
94 }
95 
98  using namespace orc::shared;
99  return WrapperFunction<void(SPSExecutorAddrRange)>::handle(
101  .release();
102 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
jit_descriptor::relevant_entry
struct jit_code_entry * relevant_entry
Definition: GDBRegistrationListener.cpp:43
BinaryStreamReader.h
registerJITLoaderGDBImpl
static void registerJITLoaderGDBImpl(ExecutorAddrRange DebugObjRange)
Definition: JITLoaderGDB.cpp:73
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
JITLoaderGDB.h
JITSymbol.h
llvm::orc::shared::SPSExecutorAddrRange
SPSTuple< SPSExecutorAddr, SPSExecutorAddr > SPSExecutorAddrRange
Definition: ExecutorAddress.h:183
JITDebugLock
ManagedStatic< std::mutex > JITDebugLock
Definition: JITLoaderGDB.cpp:70
ManagedStatic.h
jit_code_entry
Definition: GDBRegistrationListener.cpp:31
jit_descriptor::version
uint32_t version
Definition: GDBRegistrationListener.cpp:39
llvm_orc_registerJITLoaderGDBWrapper
orc::shared::detail::CWrapperFunctionResult llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size)
Definition: JITLoaderGDB.cpp:97
handle
then ret i32 result Tail recursion elimination should handle
Definition: README.txt:355
JitDescriptorVersion
static constexpr uint32_t JitDescriptorVersion
Definition: JITLoaderGDB.cpp:22
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
__jit_debug_register_code
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code()
Definition: JITLoaderGDB.cpp:57
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
JIT_UNREGISTER_FN
@ JIT_UNREGISTER_FN
Definition: JITLoaderGDB.cpp:30
llvm::orc
Definition: CompileOnDemandLayer.h:57
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::orc::shared::detail::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:37
llvm::orc::ExecutorAddrDiff::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:30
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:134
jit_code_entry::symfile_addr
const char * symfile_addr
Definition: GDBRegistrationListener.cpp:34
llvm::orc::ExecutorAddrRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:142
JIT_NOACTION
@ JIT_NOACTION
Definition: JITLoaderGDB.cpp:28
uint64_t
jit_code_entry::next_entry
struct jit_code_entry * next_entry
Definition: GDBRegistrationListener.cpp:32
llvm::orc::ExecutorAddrRange::Start
ExecutorAddr Start
Definition: ExecutorAddress.h:157
jit_actions_t
jit_actions_t
Definition: JITLoaderGDB.cpp:27
jit_descriptor::action_flag
uint32_t action_flag
Definition: GDBRegistrationListener.cpp:42
uint32_t
jit_descriptor::first_entry
struct jit_code_entry * first_entry
Definition: GDBRegistrationListener.cpp:44
jit_code_entry::symfile_size
uint64_t symfile_size
Definition: GDBRegistrationListener.cpp:35
__jit_debug_descriptor
struct jit_descriptor __jit_debug_descriptor
Definition: JITLoaderGDB.cpp:52
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:236
jit_code_entry::prev_entry
struct jit_code_entry * prev_entry
Definition: GDBRegistrationListener.cpp:33
JIT_REGISTER_FN
@ JIT_REGISTER_FN
Definition: JITLoaderGDB.cpp:29
llvm::orc::ExecutorAddr::toPtr
T toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:53
jit_descriptor
Definition: GDBRegistrationListener.cpp:38