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}
uint64_t Size
static fatal_error_handler_t ErrorHandler
static std::unique_ptr< BTFContext > create(const object::ObjectFile &Obj, std::function< void(Error)> ErrorHandler=WithColor::defaultErrorHandler)
Definition: BTFContext.cpp:65
std::optional< DILineInfo > getLineInfoForDataAddress(object::SectionedAddress Address) override
Definition: BTFContext.cpp:39
std::optional< DILineInfo > getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: BTFContext.cpp:24
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
Definition: BTFContext.cpp:59
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: BTFContext.cpp:45
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: BTFContext.cpp:53
LLVM_ABI StringRef findString(uint32_t Offset) const
Definition: BTFParser.cpp:427
LLVM_ABI const BTF::BPFLineInfo * findLineInfo(SectionedAddress Address) const
Definition: BTFParser.cpp:449
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 is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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.
Definition: AddressRanges.h:18
Specifying one line info.
Definition: BTF.h:250
uint32_t getLine() const
Definition: BTF.h:256
uint32_t getCol() const
Definition: BTF.h:257
uint32_t FileNameOff
File name index in the .BTF string table.
Definition: BTF.h:252
uint32_t LineOff
Line index in the .BTF string table.
Definition: BTF.h:253
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