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 25 namespace llvm { 26 namespace orc { 27 28 /// Abstract interface for registering debug objects in the target process. 29 class DebugObjectRegistrar { 30 public: 31 virtual Error registerDebugObject(sys::MemoryBlock) = 0; ~DebugObjectRegistrar()32 virtual ~DebugObjectRegistrar() {} 33 }; 34 35 /// Use TargetProcessControl to register debug objects locally or in a remote 36 /// target process. 37 class TPCDebugObjectRegistrar : public DebugObjectRegistrar { 38 public: 39 using SerializeBlockInfoFn = 40 std::vector<uint8_t> (*)(sys::MemoryBlock TargetMemBlock); 41 TPCDebugObjectRegistrar(TargetProcessControl & TPC,JITTargetAddress RegisterFn,SerializeBlockInfoFn SerializeBlockInfo)42 TPCDebugObjectRegistrar(TargetProcessControl &TPC, 43 JITTargetAddress RegisterFn, 44 SerializeBlockInfoFn SerializeBlockInfo) 45 : TPC(TPC), RegisterFn(RegisterFn), 46 SerializeBlockInfo(SerializeBlockInfo) {} 47 registerDebugObject(sys::MemoryBlock TargetMem)48 Error registerDebugObject(sys::MemoryBlock TargetMem) override { 49 return TPC.runWrapper(RegisterFn, SerializeBlockInfo(TargetMem)) 50 .takeError(); 51 } 52 53 private: 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. 61 Expected<std::unique_ptr<TPCDebugObjectRegistrar>> 62 createJITLoaderGDBRegistrar(TargetProcessControl &TPC); 63 64 } // end namespace orc 65 } // end namespace llvm 66 67 #endif // LLVM_EXECUTIONENGINE_ORC_TDEBUGOBJECTREGISTRAR_H 68