74 lines · cpp
1//===- BTFContext.cpp ---------------------------------------------------===//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// Implementation of the BTFContext interface, this is used by10// llvm-objdump tool to print source code alongside disassembly.11// In fact, currently it is a simple wrapper for BTFParser instance.12//13//===----------------------------------------------------------------------===//14 15#include "llvm/DebugInfo/BTF/BTFContext.h"16 17#define DEBUG_TYPE "debug-info-btf-context"18 19using namespace llvm;20using object::ObjectFile;21using object::SectionedAddress;22 23std::optional<DILineInfo>24BTFContext::getLineInfoForAddress(SectionedAddress Address,25 DILineInfoSpecifier Specifier) {26 const BTF::BPFLineInfo *LineInfo = BTF.findLineInfo(Address);27 DILineInfo Result;28 if (!LineInfo)29 return std::nullopt;30 31 Result.LineSource = BTF.findString(LineInfo->LineOff);32 Result.FileName = BTF.findString(LineInfo->FileNameOff);33 Result.Line = LineInfo->getLine();34 Result.Column = LineInfo->getCol();35 return Result;36}37 38std::optional<DILineInfo>39BTFContext::getLineInfoForDataAddress(SectionedAddress Address) {40 // BTF does not convey such information.41 return std::nullopt;42}43 44DILineInfoTable45BTFContext::getLineInfoForAddressRange(SectionedAddress Address, uint64_t Size,46 DILineInfoSpecifier Specifier) {47 // This function is used only from llvm-rtdyld utility and a few48 // JITEventListener implementations. Ignore it for now.49 return {};50}51 52DIInliningInfo53BTFContext::getInliningInfoForAddress(SectionedAddress Address,54 DILineInfoSpecifier Specifier) {55 // BTF does not convey such information56 return {};57}58 59std::vector<DILocal> BTFContext::getLocalsForAddress(SectionedAddress Address) {60 // BTF does not convey such information61 return {};62}63 64std::unique_ptr<BTFContext>65BTFContext::create(const ObjectFile &Obj,66 std::function<void(Error)> ErrorHandler) {67 auto Ctx = std::make_unique<BTFContext>();68 BTFParser::ParseOptions Opts;69 Opts.LoadLines = true;70 if (Error E = Ctx->BTF.parse(Obj, Opts))71 ErrorHandler(std::move(E));72 return Ctx;73}74