EPCDebugObjectRegistrar.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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>> createJITLoaderGDBRegistrar(
  16. ExecutionSession &ES,
  17. std::optional<ExecutorAddr> RegistrationFunctionDylib) {
  18. auto &EPC = ES.getExecutorProcessControl();
  19. if (!RegistrationFunctionDylib) {
  20. if (auto D = EPC.loadDylib(nullptr))
  21. RegistrationFunctionDylib = *D;
  22. else
  23. return D.takeError();
  24. }
  25. SymbolStringPtr RegisterFn =
  26. EPC.getTargetTriple().isOSBinFormatMachO()
  27. ? EPC.intern("_llvm_orc_registerJITLoaderGDBWrapper")
  28. : EPC.intern("llvm_orc_registerJITLoaderGDBWrapper");
  29. SymbolLookupSet RegistrationSymbols;
  30. RegistrationSymbols.add(RegisterFn);
  31. auto Result =
  32. EPC.lookupSymbols({{*RegistrationFunctionDylib, RegistrationSymbols}});
  33. if (!Result)
  34. return Result.takeError();
  35. assert(Result->size() == 1 && "Unexpected number of dylibs in result");
  36. assert((*Result)[0].size() == 1 &&
  37. "Unexpected number of addresses in result");
  38. return std::make_unique<EPCDebugObjectRegistrar>(
  39. ES, ExecutorAddr((*Result)[0][0]));
  40. }
  41. Error EPCDebugObjectRegistrar::registerDebugObject(
  42. ExecutorAddrRange TargetMem) {
  43. return ES.callSPSWrapper<void(shared::SPSExecutorAddrRange)>(RegisterFn,
  44. TargetMem);
  45. }
  46. } // namespace orc
  47. } // namespace llvm