xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/BTF/BTFContext.cpp (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 DILineInfo BTFContext::getLineInfoForAddress(SectionedAddress Address,
24                                              DILineInfoSpecifier Specifier) {
25   const BTF::BPFLineInfo *LineInfo = BTF.findLineInfo(Address);
26   DILineInfo Result;
27   if (!LineInfo)
28     return Result;
29 
30   Result.LineSource = BTF.findString(LineInfo->LineOff);
31   Result.FileName = BTF.findString(LineInfo->FileNameOff);
32   Result.Line = LineInfo->getLine();
33   Result.Column = LineInfo->getCol();
34   return Result;
35 }
36 
37 DILineInfo BTFContext::getLineInfoForDataAddress(SectionedAddress Address) {
38   // BTF does not convey such information.
39   return {};
40 }
41 
42 DILineInfoTable
43 BTFContext::getLineInfoForAddressRange(SectionedAddress Address, uint64_t Size,
44                                        DILineInfoSpecifier Specifier) {
45   // This function is used only from llvm-rtdyld utility and a few
46   // JITEventListener implementations. Ignore it for now.
47   return {};
48 }
49 
50 DIInliningInfo
51 BTFContext::getInliningInfoForAddress(SectionedAddress Address,
52                                       DILineInfoSpecifier Specifier) {
53   // BTF does not convey such information
54   return {};
55 }
56 
57 std::vector<DILocal> BTFContext::getLocalsForAddress(SectionedAddress Address) {
58   // BTF does not convey such information
59   return {};
60 }
61 
62 std::unique_ptr<BTFContext>
63 BTFContext::create(const ObjectFile &Obj,
64                    std::function<void(Error)> ErrorHandler) {
65   auto Ctx = std::make_unique<BTFContext>();
66   if (Error E = Ctx->BTF.parse(Obj))
67     ErrorHandler(std::move(E));
68   return Ctx;
69 }
70