1//===----- EPCDebugObjectRegistrar.cpp - EPC-based debug registration -----===//
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
9#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
10
11#include "llvm/ExecutionEngine/Orc/Core.h"
12
13namespace llvm {
14namespace orc {
15
16Expected<std::unique_ptr<EPCDebugObjectRegistrar>> createJITLoaderGDBRegistrar(
17 ExecutionSession &ES,
18 std::optional<ExecutorAddr> RegistrationFunctionDylib) {
19 auto &EPC = ES.getExecutorProcessControl();
20
21 if (!RegistrationFunctionDylib) {
22 if (auto D = EPC.getDylibMgr().loadDylib(DylibPath: nullptr))
23 RegistrationFunctionDylib = *D;
24 else
25 return D.takeError();
26 }
27
28 SymbolStringPtr RegisterFn =
29 EPC.getTargetTriple().isOSBinFormatMachO()
30 ? EPC.intern(SymName: "_llvm_orc_registerJITLoaderGDBWrapper")
31 : EPC.intern(SymName: "llvm_orc_registerJITLoaderGDBWrapper");
32
33 SymbolLookupSet RegistrationSymbols;
34 RegistrationSymbols.add(Name: RegisterFn);
35
36 auto Result = EPC.getDylibMgr().lookupSymbols(
37 Request: {{*RegistrationFunctionDylib, RegistrationSymbols}});
38 if (!Result)
39 return Result.takeError();
40
41 assert(Result->size() == 1 && "Unexpected number of dylibs in result");
42 assert((*Result)[0].size() == 1 &&
43 "Unexpected number of addresses in result");
44
45 ExecutorAddr RegisterAddr = (*Result)[0][0].getAddress();
46 return std::make_unique<EPCDebugObjectRegistrar>(args&: ES, args&: RegisterAddr);
47}
48
49Error EPCDebugObjectRegistrar::registerDebugObject(ExecutorAddrRange TargetMem,
50 bool AutoRegisterCode) {
51 return ES.callSPSWrapper<void(shared::SPSExecutorAddrRange, bool)>(
52 WrapperFnAddr: RegisterFn, WrapperCallArgs&: TargetMem, WrapperCallArgs&: AutoRegisterCode);
53}
54
55} // namespace orc
56} // namespace llvm
57