106c3fb27SDimitry Andric //===- BTFContext.cpp ---------------------------------------------------===// 206c3fb27SDimitry Andric // 306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 606c3fb27SDimitry Andric // 706c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 806c3fb27SDimitry Andric // 906c3fb27SDimitry Andric // Implementation of the BTFContext interface, this is used by 1006c3fb27SDimitry Andric // llvm-objdump tool to print source code alongside disassembly. 1106c3fb27SDimitry Andric // In fact, currently it is a simple wrapper for BTFParser instance. 1206c3fb27SDimitry Andric // 1306c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 1406c3fb27SDimitry Andric 1506c3fb27SDimitry Andric #include "llvm/DebugInfo/BTF/BTFContext.h" 1606c3fb27SDimitry Andric 1706c3fb27SDimitry Andric #define DEBUG_TYPE "debug-info-btf-context" 1806c3fb27SDimitry Andric 1906c3fb27SDimitry Andric using namespace llvm; 2006c3fb27SDimitry Andric using object::ObjectFile; 2106c3fb27SDimitry Andric using object::SectionedAddress; 2206c3fb27SDimitry Andric 2306c3fb27SDimitry Andric DILineInfo BTFContext::getLineInfoForAddress(SectionedAddress Address, 2406c3fb27SDimitry Andric DILineInfoSpecifier Specifier) { 2506c3fb27SDimitry Andric const BTF::BPFLineInfo *LineInfo = BTF.findLineInfo(Address); 2606c3fb27SDimitry Andric DILineInfo Result; 2706c3fb27SDimitry Andric if (!LineInfo) 2806c3fb27SDimitry Andric return Result; 2906c3fb27SDimitry Andric 3006c3fb27SDimitry Andric Result.LineSource = BTF.findString(LineInfo->LineOff); 3106c3fb27SDimitry Andric Result.FileName = BTF.findString(LineInfo->FileNameOff); 3206c3fb27SDimitry Andric Result.Line = LineInfo->getLine(); 3306c3fb27SDimitry Andric Result.Column = LineInfo->getCol(); 3406c3fb27SDimitry Andric return Result; 3506c3fb27SDimitry Andric } 3606c3fb27SDimitry Andric 3706c3fb27SDimitry Andric DILineInfo BTFContext::getLineInfoForDataAddress(SectionedAddress Address) { 3806c3fb27SDimitry Andric // BTF does not convey such information. 3906c3fb27SDimitry Andric return {}; 4006c3fb27SDimitry Andric } 4106c3fb27SDimitry Andric 4206c3fb27SDimitry Andric DILineInfoTable 4306c3fb27SDimitry Andric BTFContext::getLineInfoForAddressRange(SectionedAddress Address, uint64_t Size, 4406c3fb27SDimitry Andric DILineInfoSpecifier Specifier) { 4506c3fb27SDimitry Andric // This function is used only from llvm-rtdyld utility and a few 4606c3fb27SDimitry Andric // JITEventListener implementations. Ignore it for now. 4706c3fb27SDimitry Andric return {}; 4806c3fb27SDimitry Andric } 4906c3fb27SDimitry Andric 5006c3fb27SDimitry Andric DIInliningInfo 5106c3fb27SDimitry Andric BTFContext::getInliningInfoForAddress(SectionedAddress Address, 5206c3fb27SDimitry Andric DILineInfoSpecifier Specifier) { 5306c3fb27SDimitry Andric // BTF does not convey such information 5406c3fb27SDimitry Andric return {}; 5506c3fb27SDimitry Andric } 5606c3fb27SDimitry Andric 5706c3fb27SDimitry Andric std::vector<DILocal> BTFContext::getLocalsForAddress(SectionedAddress Address) { 5806c3fb27SDimitry Andric // BTF does not convey such information 5906c3fb27SDimitry Andric return {}; 6006c3fb27SDimitry Andric } 6106c3fb27SDimitry Andric 6206c3fb27SDimitry Andric std::unique_ptr<BTFContext> 6306c3fb27SDimitry Andric BTFContext::create(const ObjectFile &Obj, 6406c3fb27SDimitry Andric std::function<void(Error)> ErrorHandler) { 6506c3fb27SDimitry Andric auto Ctx = std::make_unique<BTFContext>(); 66*5f757f3fSDimitry Andric BTFParser::ParseOptions Opts; 67*5f757f3fSDimitry Andric Opts.LoadLines = true; 68*5f757f3fSDimitry Andric if (Error E = Ctx->BTF.parse(Obj, Opts)) 6906c3fb27SDimitry Andric ErrorHandler(std::move(E)); 7006c3fb27SDimitry Andric return Ctx; 7106c3fb27SDimitry Andric } 72