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