Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/GSYM/GsymContext.cpp
213799 views
//===-- GsymContext.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===/78#include "llvm/DebugInfo/GSYM/GsymContext.h"910#include "llvm/DebugInfo/GSYM/GsymReader.h"11#include "llvm/Support/Path.h"1213using namespace llvm;14using namespace llvm::gsym;1516GsymContext::GsymContext(std::unique_ptr<GsymReader> Reader)17: DIContext(CK_GSYM), Reader(std::move(Reader)) {}1819void GsymContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {}2021static bool fillLineInfoFromLocation(const SourceLocation &Location,22DILineInfoSpecifier Specifier,23DILineInfo &LineInfo) {24// FIXME Demangle in case of DINameKind::ShortName25if (Specifier.FNKind != DINameKind::None) {26LineInfo.FunctionName = Location.Name.str();27}2829switch (Specifier.FLIKind) {30case DILineInfoSpecifier::FileLineInfoKind::RelativeFilePath:31// We have no information to determine the relative path, so we fall back to32// returning the absolute path.33case DILineInfoSpecifier::FileLineInfoKind::RawValue:34case DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath:35if (Location.Dir.empty()) {36if (Location.Base.empty())37LineInfo.FileName = DILineInfo::BadString;38else39LineInfo.FileName = Location.Base.str();40} else {41SmallString<128> Path(Location.Dir);42sys::path::append(Path, Location.Base);43LineInfo.FileName = static_cast<std::string>(Path);44}45break;4647case DILineInfoSpecifier::FileLineInfoKind::BaseNameOnly:48LineInfo.FileName = Location.Base.str();49break;5051default:52return false;53}54LineInfo.Line = Location.Line;5556// We don't have information in GSYM to fill any of the Source, Column,57// StartFileName or StartLine attributes.5859return true;60}6162std::optional<DILineInfo>63GsymContext::getLineInfoForAddress(object::SectionedAddress Address,64DILineInfoSpecifier Specifier) {65if (Address.SectionIndex != object::SectionedAddress::UndefSection)66return {};6768auto ResultOrErr = Reader->lookup(Address.Address);6970if (!ResultOrErr) {71consumeError(ResultOrErr.takeError());72return {};73}7475const auto &Result = *ResultOrErr;7677DILineInfo LineInfo;7879if (Result.Locations.empty()) {80// No debug info for this, we just had a symbol from the symbol table.8182// FIXME Demangle in case of DINameKind::ShortName83if (Specifier.FNKind != DINameKind::None)84LineInfo.FunctionName = Result.FuncName.str();85} else if (!fillLineInfoFromLocation(Result.Locations.front(), Specifier,86LineInfo))87return {};8889LineInfo.StartAddress = Result.FuncRange.start();9091return LineInfo;92}9394std::optional<DILineInfo>95GsymContext::getLineInfoForDataAddress(object::SectionedAddress Address) {96// We can't implement this, there's no such information in the GSYM file.9798return {};99}100101DILineInfoTable102GsymContext::getLineInfoForAddressRange(object::SectionedAddress Address,103uint64_t Size,104DILineInfoSpecifier Specifier) {105if (Size == 0)106return DILineInfoTable();107108if (Address.SectionIndex != llvm::object::SectionedAddress::UndefSection)109return DILineInfoTable();110111if (auto FuncInfoOrErr = Reader->getFunctionInfo(Address.Address)) {112DILineInfoTable Table;113if (FuncInfoOrErr->OptLineTable) {114const gsym::LineTable < = *FuncInfoOrErr->OptLineTable;115const uint64_t StartAddr = Address.Address;116const uint64_t EndAddr = Address.Address + Size;117for (const auto &LineEntry : LT) {118if (StartAddr <= LineEntry.Addr && LineEntry.Addr < EndAddr) {119// Use LineEntry.Addr, LineEntry.File (which is a file index into the120// files tables from the GsymReader), and LineEntry.Line (source line121// number) to add stuff to the DILineInfoTable122}123}124}125return Table;126} else {127consumeError(FuncInfoOrErr.takeError());128return DILineInfoTable();129}130}131132DIInliningInfo133GsymContext::getInliningInfoForAddress(object::SectionedAddress Address,134DILineInfoSpecifier Specifier) {135auto ResultOrErr = Reader->lookup(Address.Address);136137if (!ResultOrErr)138return {};139140const auto &Result = *ResultOrErr;141142DIInliningInfo InlineInfo;143144for (const auto &Location : Result.Locations) {145DILineInfo LineInfo;146147if (!fillLineInfoFromLocation(Location, Specifier, LineInfo))148return {};149150// Hm, that's probably something that should only be filled in the first or151// last frame?152LineInfo.StartAddress = Result.FuncRange.start();153154InlineInfo.addFrame(LineInfo);155}156157return InlineInfo;158}159160std::vector<DILocal>161GsymContext::getLocalsForAddress(object::SectionedAddress Address) {162// We can't implement this, there's no such information in the GSYM file.163164return {};165}166167168