LLVM 22.0.0git
GsymContext.cpp
Go to the documentation of this file.
1//===-- GsymContext.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
10
12#include "llvm/Support/Path.h"
13
14using namespace llvm;
15using namespace llvm::gsym;
16
18GsymContext::GsymContext(std::unique_ptr<GsymReader> Reader)
19 : DIContext(CK_GSYM), Reader(std::move(Reader)) {}
20
22
23static bool fillLineInfoFromLocation(const SourceLocation &Location,
24 DILineInfoSpecifier Specifier,
25 DILineInfo &LineInfo) {
26 // FIXME Demangle in case of DINameKind::ShortName
27 if (Specifier.FNKind != DINameKind::None) {
28 LineInfo.FunctionName = Location.Name.str();
29 }
30
31 switch (Specifier.FLIKind) {
32 case DILineInfoSpecifier::FileLineInfoKind::RelativeFilePath:
33 // We have no information to determine the relative path, so we fall back to
34 // returning the absolute path.
35 case DILineInfoSpecifier::FileLineInfoKind::RawValue:
36 case DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath:
37 if (Location.Dir.empty()) {
38 if (Location.Base.empty())
40 else
41 LineInfo.FileName = Location.Base.str();
42 } else {
43 SmallString<128> Path(Location.Dir);
44 sys::path::append(Path, Location.Base);
45 LineInfo.FileName = static_cast<std::string>(Path);
46 }
47 break;
48
49 case DILineInfoSpecifier::FileLineInfoKind::BaseNameOnly:
50 LineInfo.FileName = Location.Base.str();
51 break;
52
53 default:
54 return false;
55 }
56 LineInfo.Line = Location.Line;
57
58 // We don't have information in GSYM to fill any of the Source, Column,
59 // StartFileName or StartLine attributes.
60
61 return true;
62}
63
64std::optional<DILineInfo>
66 DILineInfoSpecifier Specifier) {
68 return {};
69
70 auto ResultOrErr = Reader->lookup(Address.Address);
71
72 if (!ResultOrErr) {
73 consumeError(ResultOrErr.takeError());
74 return {};
75 }
76
77 const auto &Result = *ResultOrErr;
78
79 DILineInfo LineInfo;
80
81 if (Result.Locations.empty()) {
82 // No debug info for this, we just had a symbol from the symbol table.
83
84 // FIXME Demangle in case of DINameKind::ShortName
85 if (Specifier.FNKind != DINameKind::None)
86 LineInfo.FunctionName = Result.FuncName.str();
87 } else if (!fillLineInfoFromLocation(Result.Locations.front(), Specifier,
88 LineInfo))
89 return {};
90
91 LineInfo.StartAddress = Result.FuncRange.start();
92
93 return LineInfo;
94}
95
96std::optional<DILineInfo>
98 // We can't implement this, there's no such information in the GSYM file.
99
100 return {};
101}
102
106 DILineInfoSpecifier Specifier) {
107 if (Size == 0)
108 return DILineInfoTable();
109
111 return DILineInfoTable();
112
113 if (auto FuncInfoOrErr = Reader->getFunctionInfo(Address.Address)) {
114 DILineInfoTable Table;
115 if (FuncInfoOrErr->OptLineTable) {
116 const gsym::LineTable &LT = *FuncInfoOrErr->OptLineTable;
117 const uint64_t StartAddr = Address.Address;
118 const uint64_t EndAddr = Address.Address + Size;
119 for (const auto &LineEntry : LT) {
120 if (StartAddr <= LineEntry.Addr && LineEntry.Addr < EndAddr) {
121 // Use LineEntry.Addr, LineEntry.File (which is a file index into the
122 // files tables from the GsymReader), and LineEntry.Line (source line
123 // number) to add stuff to the DILineInfoTable
124 }
125 }
126 }
127 return Table;
128 } else {
129 consumeError(FuncInfoOrErr.takeError());
130 return DILineInfoTable();
131 }
132}
133
136 DILineInfoSpecifier Specifier) {
137 auto ResultOrErr = Reader->lookup(Address.Address);
138
139 if (!ResultOrErr)
140 return {};
141
142 const auto &Result = *ResultOrErr;
143
145
146 for (const auto &Location : Result.Locations) {
147 DILineInfo LineInfo;
148
149 if (!fillLineInfoFromLocation(Location, Specifier, LineInfo))
150 return {};
151
152 // Hm, that's probably something that should only be filled in the first or
153 // last frame?
154 LineInfo.StartAddress = Result.FuncRange.start();
155
156 InlineInfo.addFrame(LineInfo);
157 }
158
159 return InlineInfo;
160}
161
162std::vector<DILocal>
164 // We can't implement this, there's no such information in the GSYM file.
165
166 return {};
167}
uint64_t Size
static bool fillLineInfoFromLocation(const SourceLocation &Location, DILineInfoSpecifier Specifier, DILineInfo &LineInfo)
Definition: GsymContext.cpp:23
raw_pwrite_stream & OS
A format-neutral container for inlined code description.
Definition: DIContext.h:94
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
std::optional< DILineInfo > getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
Definition: GsymContext.cpp:65
void dump(raw_ostream &OS, DIDumpOptions DIDumpOpts) override
Definition: GsymContext.cpp:21
std::vector< DILocal > getLocalsForAddress(object::SectionedAddress Address) override
std::optional< DILineInfo > getLineInfoForDataAddress(object::SectionedAddress Address) override
Definition: GsymContext.cpp:97
GsymContext(std::unique_ptr< GsymReader > Reader)
Definition: GsymContext.cpp:18
LineTable class contains deserialized versions of line tables for each function's address ranges.
Definition: LineTable.h:119
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:456
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable
Definition: DIContext.h:91
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1083
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:851
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:196
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:146
A format-neutral container for source line information.
Definition: DIContext.h:32
static constexpr const char *const BadString
Definition: DIContext.h:35
std::optional< uint64_t > StartAddress
Definition: DIContext.h:49
uint32_t Line
Definition: DIContext.h:46
std::string FileName
Definition: DIContext.h:38
std::string FunctionName
Definition: DIContext.h:39
Inline information stores the name of the inline function along with an array of address ranges.
Definition: InlineInfo.h:60
Line entries are used to encode the line tables in FunctionInfo objects.
Definition: LineEntry.h:22
uint64_t Addr
Start address of this line entry.
Definition: LineEntry.h:23
static const uint64_t UndefSection
Definition: ObjectFile.h:148