1b1c73532SDimitry Andric //===------ DebuggerSupport.cpp - Utils for enabling debugger support -----===// 2b1c73532SDimitry Andric // 3b1c73532SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b1c73532SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5b1c73532SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b1c73532SDimitry Andric // 7b1c73532SDimitry Andric //===----------------------------------------------------------------------===// 8b1c73532SDimitry Andric 9b1c73532SDimitry Andric #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h" 10b1c73532SDimitry Andric #include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h" 11b1c73532SDimitry Andric #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h" 12b1c73532SDimitry Andric #include "llvm/ExecutionEngine/Orc/LLJIT.h" 13b1c73532SDimitry Andric 14b1c73532SDimitry Andric #define DEBUG_TYPE "orc" 15b1c73532SDimitry Andric 16b1c73532SDimitry Andric using namespace llvm; 17b1c73532SDimitry Andric using namespace llvm::orc; 18b1c73532SDimitry Andric 19b1c73532SDimitry Andric namespace llvm::orc { 20b1c73532SDimitry Andric enableDebuggerSupport(LLJIT & J)21b1c73532SDimitry AndricError enableDebuggerSupport(LLJIT &J) { 22b1c73532SDimitry Andric auto *ObjLinkingLayer = dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer()); 23b1c73532SDimitry Andric if (!ObjLinkingLayer) 24b1c73532SDimitry Andric return make_error<StringError>("Cannot enable LLJIT debugger support: " 25b1c73532SDimitry Andric "Debugger support requires JITLink", 26b1c73532SDimitry Andric inconvertibleErrorCode()); 27b1c73532SDimitry Andric auto ProcessSymsJD = J.getProcessSymbolsJITDylib(); 28b1c73532SDimitry Andric if (!ProcessSymsJD) 29b1c73532SDimitry Andric return make_error<StringError>("Cannot enable LLJIT debugger support: " 30b1c73532SDimitry Andric "Process symbols are not available", 31b1c73532SDimitry Andric inconvertibleErrorCode()); 32b1c73532SDimitry Andric 33b1c73532SDimitry Andric auto &ES = J.getExecutionSession(); 34b1c73532SDimitry Andric const auto &TT = J.getTargetTriple(); 35b1c73532SDimitry Andric 36b1c73532SDimitry Andric switch (TT.getObjectFormat()) { 37b1c73532SDimitry Andric case Triple::ELF: { 38b1c73532SDimitry Andric auto Registrar = createJITLoaderGDBRegistrar(ES); 39b1c73532SDimitry Andric if (!Registrar) 40b1c73532SDimitry Andric return Registrar.takeError(); 41b1c73532SDimitry Andric ObjLinkingLayer->addPlugin(std::make_unique<DebugObjectManagerPlugin>( 42312c0ed1SDimitry Andric ES, std::move(*Registrar), false, true)); 43b1c73532SDimitry Andric return Error::success(); 44b1c73532SDimitry Andric } 45b1c73532SDimitry Andric case Triple::MachO: { 46b1c73532SDimitry Andric auto DS = GDBJITDebugInfoRegistrationPlugin::Create(ES, *ProcessSymsJD, TT); 47b1c73532SDimitry Andric if (!DS) 48b1c73532SDimitry Andric return DS.takeError(); 49b1c73532SDimitry Andric ObjLinkingLayer->addPlugin(std::move(*DS)); 50b1c73532SDimitry Andric return Error::success(); 51b1c73532SDimitry Andric } 52b1c73532SDimitry Andric default: 53b1c73532SDimitry Andric return make_error<StringError>( 54b1c73532SDimitry Andric "Cannot enable LLJIT debugger support: " + 55b1c73532SDimitry Andric Triple::getObjectFormatTypeName(TT.getObjectFormat()) + 56b1c73532SDimitry Andric " is not supported", 57b1c73532SDimitry Andric inconvertibleErrorCode()); 58b1c73532SDimitry Andric } 59b1c73532SDimitry Andric } 60b1c73532SDimitry Andric 61b1c73532SDimitry Andric } // namespace llvm::orc 62