EPCDebugObjectRegistrar.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
  9. #include "llvm/ExecutionEngine/Orc/Core.h"
  10. #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
  11. #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
  12. #include "llvm/Support/BinaryStreamWriter.h"
  13. namespace llvm {
  14. namespace orc {
  15. Expected<std::unique_ptr<EPCDebugObjectRegistrar>>
  16. createJITLoaderGDBRegistrar(ExecutionSession &ES) {
  17. auto &EPC = ES.getExecutorProcessControl();
  18. auto ProcessHandle = EPC.loadDylib(nullptr);
  19. if (!ProcessHandle)
  20. return ProcessHandle.takeError();
  21. SymbolStringPtr RegisterFn =
  22. EPC.getTargetTriple().isOSBinFormatMachO()
  23. ? EPC.intern("_llvm_orc_registerJITLoaderGDBWrapper")
  24. : EPC.intern("llvm_orc_registerJITLoaderGDBWrapper");
  25. SymbolLookupSet RegistrationSymbols;
  26. RegistrationSymbols.add(RegisterFn);
  27. auto Result = EPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});
  28. if (!Result)
  29. return Result.takeError();
  30. assert(Result->size() == 1 && "Unexpected number of dylibs in result");
  31. assert((*Result)[0].size() == 1 &&
  32. "Unexpected number of addresses in result");
  33. return std::make_unique<EPCDebugObjectRegistrar>(
  34. ES, ExecutorAddr((*Result)[0][0]));
  35. }
  36. Error EPCDebugObjectRegistrar::registerDebugObject(
  37. ExecutorAddrRange TargetMem) {
  38. return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(RegisterFn, TargetMem);
  39. }
  40. } // namespace orc
  41. } // namespace llvm