xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp (revision 43a5ec4eb41567cc92586503212743d89686d78f)
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 #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
13 #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
14 #include "llvm/Support/BinaryStreamWriter.h"
15 
16 namespace llvm {
17 namespace orc {
18 
19 Expected<std::unique_ptr<EPCDebugObjectRegistrar>>
20 createJITLoaderGDBRegistrar(ExecutionSession &ES) {
21   auto &EPC = ES.getExecutorProcessControl();
22   auto ProcessHandle = EPC.loadDylib(nullptr);
23   if (!ProcessHandle)
24     return ProcessHandle.takeError();
25 
26   SymbolStringPtr RegisterFn =
27       EPC.getTargetTriple().isOSBinFormatMachO()
28           ? EPC.intern("_llvm_orc_registerJITLoaderGDBWrapper")
29           : EPC.intern("llvm_orc_registerJITLoaderGDBWrapper");
30 
31   SymbolLookupSet RegistrationSymbols;
32   RegistrationSymbols.add(RegisterFn);
33 
34   auto Result = EPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});
35   if (!Result)
36     return Result.takeError();
37 
38   assert(Result->size() == 1 && "Unexpected number of dylibs in result");
39   assert((*Result)[0].size() == 1 &&
40          "Unexpected number of addresses in result");
41 
42   return std::make_unique<EPCDebugObjectRegistrar>(ES, (*Result)[0][0]);
43 }
44 
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()));
49 }
50 
51 } // namespace orc
52 } // namespace llvm
53