xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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>(
43       ES, ExecutorAddr((*Result)[0][0]));
44 }
45 
46 Error EPCDebugObjectRegistrar::registerDebugObject(
47     ExecutorAddrRange TargetMem) {
48   return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(RegisterFn, TargetMem);
49 }
50 
51 } // namespace orc
52 } // namespace llvm
53