LLVM 22.0.0git
BTFContext.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implementation of the BTFContext interface, this is used by
10// llvm-objdump tool to print source code alongside disassembly.
11// In fact, currently it is a simple wrapper for BTFParser instance.
12//
13//===----------------------------------------------------------------------===//
14
16
17#define DEBUG_TYPE "debug-info-btf-context"
18
19using namespace llvm;
22
23std::optional<DILineInfo>
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>
40 // BTF does not convey such information.
41 return std::nullopt;
42}
43
46 DILineInfoSpecifier Specifier) {
47 // This function is used only from llvm-rtdyld utility and a few
48 // JITEventListener implementations. Ignore it for now.
49 return {};
50}
51
54 DILineInfoSpecifier Specifier) {
55 // BTF does not convey such information
56 return {};
57}
58
60 // BTF does not convey such information
61 return {};
62}
63
64std::unique_ptr<BTFContext>
66 std::function<void(Error)> ErrorHandler) {
67 auto Ctx = std::make_unique<BTFContext>();
69 Opts.LoadLines = true;
70 if (Error E = Ctx->BTF.parse(Obj, Opts))
71 ErrorHandler(std::move(E));
72 return Ctx;
73}
static fatal_error_handler_t ErrorHandler
static std::unique_ptr< BTFContext > create(const object::ObjectFile &Obj, std::function< void(Error)> ErrorHandler=WithColor::defaultErrorHandler)
std::optional< DILineInfo > getLineInfoForDataAddress(object::SectionedAddress Address) override
std::optional< DILineInfo > getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
A format-neutral container for inlined code description.
Definition DIContext.h:94
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
This class is the base class for all object file types.
Definition ObjectFile.h:231
This is an optimization pass for GlobalISel generic memory operations.
SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable
Definition DIContext.h:91
Specifying one line info.
Definition BTF.h:250
Controls which fields of DILineInfo container should be filled with data.
Definition DIContext.h:146
A format-neutral container for source line information.
Definition DIContext.h:32