1 //===----- EPCDebugObjectRegistrar.cpp - EPC-based debug registration -----===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
11 #include "llvm/ExecutionEngine/Orc/Core.h"
12 #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
13 #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
14 #include "llvm/Support/BinaryStreamWriter.h"
19 Expected
<std::unique_ptr
<EPCDebugObjectRegistrar
>> createJITLoaderGDBRegistrar(
21 std::optional
<ExecutorAddr
> RegistrationFunctionDylib
) {
22 auto &EPC
= ES
.getExecutorProcessControl();
24 if (!RegistrationFunctionDylib
) {
25 if (auto D
= EPC
.loadDylib(nullptr))
26 RegistrationFunctionDylib
= *D
;
31 SymbolStringPtr RegisterFn
=
32 EPC
.getTargetTriple().isOSBinFormatMachO()
33 ? EPC
.intern("_llvm_orc_registerJITLoaderGDBWrapper")
34 : EPC
.intern("llvm_orc_registerJITLoaderGDBWrapper");
36 SymbolLookupSet RegistrationSymbols
;
37 RegistrationSymbols
.add(RegisterFn
);
40 EPC
.lookupSymbols({{*RegistrationFunctionDylib
, RegistrationSymbols
}});
42 return Result
.takeError();
44 assert(Result
->size() == 1 && "Unexpected number of dylibs in result");
45 assert((*Result
)[0].size() == 1 &&
46 "Unexpected number of addresses in result");
48 return std::make_unique
<EPCDebugObjectRegistrar
>(ES
, (*Result
)[0][0]);
51 Error
EPCDebugObjectRegistrar::registerDebugObject(ExecutorAddrRange TargetMem
,
52 bool AutoRegisterCode
) {
53 return ES
.callSPSWrapper
<void(shared::SPSExecutorAddrRange
, bool)>(
54 RegisterFn
, TargetMem
, AutoRegisterCode
);