brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 7be5887 Raw
60 lines · cpp
1//===------ DebuggerSupport.cpp - Utils for enabling debugger support -----===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"10#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"11#include "llvm/ExecutionEngine/Orc/Debugging/ELFDebugObjectPlugin.h"12#include "llvm/ExecutionEngine/Orc/LLJIT.h"13 14#define DEBUG_TYPE "orc"15 16using namespace llvm;17using namespace llvm::orc;18 19namespace llvm::orc {20 21Error enableDebuggerSupport(LLJIT &J) {22  auto *ObjLinkingLayer = dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer());23  if (!ObjLinkingLayer)24    return make_error<StringError>("Cannot enable LLJIT debugger support: "25                                   "Debugger support requires JITLink",26                                   inconvertibleErrorCode());27  auto ProcessSymsJD = J.getProcessSymbolsJITDylib();28  if (!ProcessSymsJD)29    return make_error<StringError>("Cannot enable LLJIT debugger support: "30                                   "Process symbols are not available",31                                   inconvertibleErrorCode());32 33  auto &ES = J.getExecutionSession();34  const auto &TT = J.getTargetTriple();35 36  switch (TT.getObjectFormat()) {37  case Triple::ELF: {38    Error TargetSymErr = Error::success();39    ObjLinkingLayer->addPlugin(40        std::make_unique<ELFDebugObjectPlugin>(ES, false, true, TargetSymErr));41    return TargetSymErr;42  }43  case Triple::MachO: {44    auto DS = GDBJITDebugInfoRegistrationPlugin::Create(ES, *ProcessSymsJD, TT);45    if (!DS)46      return DS.takeError();47    ObjLinkingLayer->addPlugin(std::move(*DS));48    return Error::success();49  }50  default:51    return make_error<StringError>(52        "Cannot enable LLJIT debugger support: " +53            Triple::getObjectFormatTypeName(TT.getObjectFormat()) +54            " is not supported",55        inconvertibleErrorCode());56  }57}58 59} // namespace llvm::orc60