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>>
20 createJITLoaderGDBRegistrar(ExecutionSession &ES) {
21 auto &EPC = ES.getExecutorProcessControl();
22 auto ProcessHandle = EPC.loadDylib(nullptr);
24 return ProcessHandle.takeError();
26 SymbolStringPtr RegisterFn =
27 EPC.getTargetTriple().isOSBinFormatMachO()
28 ? EPC.intern("_llvm_orc_registerJITLoaderGDBWrapper")
29 : EPC.intern("llvm_orc_registerJITLoaderGDBWrapper");
31 SymbolLookupSet RegistrationSymbols;
32 RegistrationSymbols.add(RegisterFn);
34 auto Result = EPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});
36 return Result.takeError();
38 assert(Result->size() == 1 && "Unexpected number of dylibs in result");
39 assert((*Result)[0].size() == 1 &&
40 "Unexpected number of addresses in result");
42 return std::make_unique<EPCDebugObjectRegistrar>(ES, (*Result)[0][0]);
45 Error EPCDebugObjectRegistrar::registerDebugObject(sys::MemoryBlock TargetMem) {
46 return ES.callSPSWrapper<void(SPSExecutorAddress, uint64_t)>(
47 RegisterFn, ExecutorAddress::fromPtr(TargetMem.base()),
48 static_cast<uint64_t>(TargetMem.allocatedSize()));