xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/BTF/BTFContext.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric //===- BTFContext.cpp ---------------------------------------------------===//
2*06c3fb27SDimitry Andric //
3*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*06c3fb27SDimitry Andric //
7*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
8*06c3fb27SDimitry Andric //
9*06c3fb27SDimitry Andric // Implementation of the BTFContext interface, this is used by
10*06c3fb27SDimitry Andric // llvm-objdump tool to print source code alongside disassembly.
11*06c3fb27SDimitry Andric // In fact, currently it is a simple wrapper for BTFParser instance.
12*06c3fb27SDimitry Andric //
13*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
14*06c3fb27SDimitry Andric 
15*06c3fb27SDimitry Andric #include "llvm/DebugInfo/BTF/BTFContext.h"
16*06c3fb27SDimitry Andric 
17*06c3fb27SDimitry Andric #define DEBUG_TYPE "debug-info-btf-context"
18*06c3fb27SDimitry Andric 
19*06c3fb27SDimitry Andric using namespace llvm;
20*06c3fb27SDimitry Andric using object::ObjectFile;
21*06c3fb27SDimitry Andric using object::SectionedAddress;
22*06c3fb27SDimitry Andric 
23*06c3fb27SDimitry Andric DILineInfo BTFContext::getLineInfoForAddress(SectionedAddress Address,
24*06c3fb27SDimitry Andric                                              DILineInfoSpecifier Specifier) {
25*06c3fb27SDimitry Andric   const BTF::BPFLineInfo *LineInfo = BTF.findLineInfo(Address);
26*06c3fb27SDimitry Andric   DILineInfo Result;
27*06c3fb27SDimitry Andric   if (!LineInfo)
28*06c3fb27SDimitry Andric     return Result;
29*06c3fb27SDimitry Andric 
30*06c3fb27SDimitry Andric   Result.LineSource = BTF.findString(LineInfo->LineOff);
31*06c3fb27SDimitry Andric   Result.FileName = BTF.findString(LineInfo->FileNameOff);
32*06c3fb27SDimitry Andric   Result.Line = LineInfo->getLine();
33*06c3fb27SDimitry Andric   Result.Column = LineInfo->getCol();
34*06c3fb27SDimitry Andric   return Result;
35*06c3fb27SDimitry Andric }
36*06c3fb27SDimitry Andric 
37*06c3fb27SDimitry Andric DILineInfo BTFContext::getLineInfoForDataAddress(SectionedAddress Address) {
38*06c3fb27SDimitry Andric   // BTF does not convey such information.
39*06c3fb27SDimitry Andric   return {};
40*06c3fb27SDimitry Andric }
41*06c3fb27SDimitry Andric 
42*06c3fb27SDimitry Andric DILineInfoTable
43*06c3fb27SDimitry Andric BTFContext::getLineInfoForAddressRange(SectionedAddress Address, uint64_t Size,
44*06c3fb27SDimitry Andric                                        DILineInfoSpecifier Specifier) {
45*06c3fb27SDimitry Andric   // This function is used only from llvm-rtdyld utility and a few
46*06c3fb27SDimitry Andric   // JITEventListener implementations. Ignore it for now.
47*06c3fb27SDimitry Andric   return {};
48*06c3fb27SDimitry Andric }
49*06c3fb27SDimitry Andric 
50*06c3fb27SDimitry Andric DIInliningInfo
51*06c3fb27SDimitry Andric BTFContext::getInliningInfoForAddress(SectionedAddress Address,
52*06c3fb27SDimitry Andric                                       DILineInfoSpecifier Specifier) {
53*06c3fb27SDimitry Andric   // BTF does not convey such information
54*06c3fb27SDimitry Andric   return {};
55*06c3fb27SDimitry Andric }
56*06c3fb27SDimitry Andric 
57*06c3fb27SDimitry Andric std::vector<DILocal> BTFContext::getLocalsForAddress(SectionedAddress Address) {
58*06c3fb27SDimitry Andric   // BTF does not convey such information
59*06c3fb27SDimitry Andric   return {};
60*06c3fb27SDimitry Andric }
61*06c3fb27SDimitry Andric 
62*06c3fb27SDimitry Andric std::unique_ptr<BTFContext>
63*06c3fb27SDimitry Andric BTFContext::create(const ObjectFile &Obj,
64*06c3fb27SDimitry Andric                    std::function<void(Error)> ErrorHandler) {
65*06c3fb27SDimitry Andric   auto Ctx = std::make_unique<BTFContext>();
66*06c3fb27SDimitry Andric   if (Error E = Ctx->BTF.parse(Obj))
67*06c3fb27SDimitry Andric     ErrorHandler(std::move(E));
68*06c3fb27SDimitry Andric   return Ctx;
69*06c3fb27SDimitry Andric }
70