1//===- TPCDebugObjectRegistrar.h - TPC-based debug registration -*- C++ -*-===//
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// TargetProcessControl based registration of debug objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_TPCDEBUGOBJECTREGISTRAR_H
14#define LLVM_EXECUTIONENGINE_ORC_TPCDEBUGOBJECTREGISTRAR_H
15
16#include "llvm/ExecutionEngine/JITSymbol.h"
17#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
18#include "llvm/Support/Error.h"
19#include "llvm/Support/Memory.h"
20
21#include <cstdint>
22#include <memory>
23#include <vector>
24
25namespace llvm {
26namespace orc {
27
28/// Abstract interface for registering debug objects in the target process.
29class DebugObjectRegistrar {
30public:
31 virtual Error registerDebugObject(sys::MemoryBlock) = 0;
32 virtual ~DebugObjectRegistrar() {}
33};
34
35/// Use TargetProcessControl to register debug objects locally or in a remote
36/// target process.
37class TPCDebugObjectRegistrar : public DebugObjectRegistrar {
38public:
39 using SerializeBlockInfoFn =
40 std::vector<uint8_t> (*)(sys::MemoryBlock TargetMemBlock);
41
42 TPCDebugObjectRegistrar(TargetProcessControl &TPC,
43 JITTargetAddress RegisterFn,
44 SerializeBlockInfoFn SerializeBlockInfo)
45 : TPC(TPC), RegisterFn(RegisterFn),
46 SerializeBlockInfo(SerializeBlockInfo) {}
47
48 Error registerDebugObject(sys::MemoryBlock TargetMem) override {
49 return TPC.runWrapper(RegisterFn, SerializeBlockInfo(TargetMem))
50 .takeError();
51 }
52
53private:
54 TargetProcessControl &TPC;
55 JITTargetAddress RegisterFn;
56 SerializeBlockInfoFn SerializeBlockInfo;
57};
58
59/// Create a TargetProcessControl-based DebugObjectRegistrar that emits debug
60/// objects to the GDB JIT interface.
61Expected<std::unique_ptr<TPCDebugObjectRegistrar>>
62createJITLoaderGDBRegistrar(TargetProcessControl &TPC);
63
64} // end namespace orc
65} // end namespace llvm
66
67#endif // LLVM_EXECUTIONENGINE_ORC_TDEBUGOBJECTREGISTRAR_H
68