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 | |
15 | #include "llvm/DebugInfo/BTF/BTFContext.h" |
16 | |
17 | #define DEBUG_TYPE "debug-info-btf-context" |
18 | |
19 | using namespace llvm; |
20 | using object::ObjectFile; |
21 | using object::SectionedAddress; |
22 | |
23 | std::optional<DILineInfo> |
24 | BTFContext::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(Offset: LineInfo->LineOff); |
32 | Result.FileName = BTF.findString(Offset: LineInfo->FileNameOff); |
33 | Result.Line = LineInfo->getLine(); |
34 | Result.Column = LineInfo->getCol(); |
35 | return Result; |
36 | } |
37 | |
38 | std::optional<DILineInfo> |
39 | BTFContext::getLineInfoForDataAddress(SectionedAddress Address) { |
40 | // BTF does not convey such information. |
41 | return std::nullopt; |
42 | } |
43 | |
44 | DILineInfoTable |
45 | BTFContext::getLineInfoForAddressRange(SectionedAddress Address, uint64_t Size, |
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 | |
52 | DIInliningInfo |
53 | BTFContext::getInliningInfoForAddress(SectionedAddress Address, |
54 | DILineInfoSpecifier Specifier) { |
55 | // BTF does not convey such information |
56 | return {}; |
57 | } |
58 | |
59 | std::vector<DILocal> BTFContext::getLocalsForAddress(SectionedAddress Address) { |
60 | // BTF does not convey such information |
61 | return {}; |
62 | } |
63 | |
64 | std::unique_ptr<BTFContext> |
65 | BTFContext::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 |