1//===- DWARFFormValue.h -----------------------------------------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
9#ifndef LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H
10#define LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H
27 class DWARFFormValue {
61 ValueType Value;
/// Contains all data for the form.
62 const DWARFUnit *U =
nullptr;
/// Remember the DWARFUnit at extract time.
63 const DWARFContext *C =
nullptr;
/// Context for extract time.
77 LLVM_ABI static std::optional<object::SectionedAddress>
98 /// Extracts a value in \p Data at offset \p *OffsetPtr. The information
99 /// in \p FormParams is needed to interpret some forms. The optional
100 /// \p Context and \p Unit allows extracting information if the form refers
101 /// to other sections (e.g., .debug_str).
112 /// getAsFoo functions below return the extracted value as Foo if only
113 /// DWARFFormValue has form class is suitable for representing Foo.
122 LLVM_ABI std::optional<object::SectionedAddress>
128 /// Correctly extract any file paths from a form value.
130 /// These attributes can be in the from DW_AT_decl_file or DW_AT_call_file
131 /// attributes. We need to use the file index in the correct DWARFUnit's line
132 /// table prologue, and each DWARFFormValue has the DWARFUnit the form value
133 /// was extracted from.
135 /// \param Kind The kind of path to extract.
137 /// \returns A valid string value on success, or std::nullopt if the form
138 /// class is not FC_Constant, or if the file index is not valid.
142 /// Skip a form's value in \p DebugInfoData at the offset specified by
145 /// Skips the bytes for the current form and updates the offset.
147 /// \param DebugInfoData The data where we want to skip the value.
148 /// \param OffsetPtr A reference to the offset that will be updated.
149 /// \param Params DWARF parameters to help interpret forms.
150 /// \returns true on success, false if the form was not skipped.
156 /// Skip a form's value in \p DebugInfoData at the offset specified by
159 /// Skips the bytes for the specified form and updates the offset.
161 /// \param Form The DW_FORM enumeration that indicates the form to skip.
162 /// \param DebugInfoData The data where we want to skip the value.
163 /// \param OffsetPtr A reference to the offset that will be updated.
164 /// \param FormParams DWARF parameters to help interpret forms.
165 /// \returns true on success, false if the form was not skipped.
176/// Take an optional DWARFFormValue and try to extract a string value from it.
178/// \param V and optional DWARFFormValue to attempt to extract the value from.
179/// \returns an optional value that contains a value if the form value
180/// was valid and was a string.
181inline std::optional<const char *>
193/// Take an optional DWARFFormValue and try to extract a string value from it.
195/// \param V and optional DWARFFormValue to attempt to extract the value from.
196/// \returns an optional value that contains a value if the form value
197/// was valid and was a string.
202 auto S = V->getAsCString();
212/// Take an optional DWARFFormValue and extract a string value from it.
214/// \param V and optional DWARFFormValue to attempt to extract the value from.
215/// \param Default the default value to return in case of failure.
216/// \returns the string value or Default if the V doesn't have a value or the
217/// form value's encoding wasn't a string.
218 inline const char *
toString(
const std::optional<DWARFFormValue> &V,
225/// Take an optional DWARFFormValue and try to extract an unsigned constant.
227/// \param V and optional DWARFFormValue to attempt to extract the value from.
228/// \returns an optional value that contains a value if the form value
229/// was valid and has a unsigned constant form.
230inline std::optional<uint64_t>
233 return V->getAsUnsignedConstant();
237/// Take an optional DWARFFormValue and extract a unsigned constant.
239/// \param V and optional DWARFFormValue to attempt to extract the value from.
240/// \param Default the default value to return in case of failure.
241/// \returns the extracted unsigned value or Default if the V doesn't have a
242/// value or the form value's encoding wasn't an unsigned constant form.
248/// Take an optional DWARFFormValue and try to extract a relative offset
251/// \param V an optional DWARFFormValue to attempt to extract the value from.
252/// \returns an optional value that contains a value if the form value
253/// was valid and has a relative reference form.
254inline std::optional<uint64_t>
257 return V->getAsRelativeReference();
261/// Take an optional DWARFFormValue and extract a relative offset reference.
263/// \param V an optional DWARFFormValue to attempt to extract the value from.
264/// \param Default the default value to return in case of failure.
265/// \returns the extracted reference value or Default if the V doesn't have a
266/// value or the form value's encoding wasn't a relative offset reference form.
272/// Take an optional DWARFFormValue and try to extract an absolute debug info
275/// \param V an optional DWARFFormValue to attempt to extract the value from.
276/// \returns an optional value that contains a value if the form value
277/// was valid and has an (absolute) debug info offset reference form.
278inline std::optional<uint64_t>
281 return V->getAsDebugInfoReference();
285/// Take an optional DWARFFormValue and extract an absolute debug info offset
288/// \param V an optional DWARFFormValue to attempt to extract the value from.
289/// \param Default the default value to return in case of failure.
290/// \returns the extracted reference value or Default if the V doesn't have a
291/// value or the form value's encoding wasn't an absolute debug info offset
298/// Take an optional DWARFFormValue and try to extract a signature reference.
300/// \param V an optional DWARFFormValue to attempt to extract the value from.
301/// \returns an optional value that contains a value if the form value
302/// was valid and has a signature reference form.
303inline std::optional<uint64_t>
306 return V->getAsSignatureReference();
310/// Take an optional DWARFFormValue and extract a signature reference.
312/// \param V an optional DWARFFormValue to attempt to extract the value from.
313/// \param Default the default value to return in case of failure.
314/// \returns the extracted reference value or Default if the V doesn't have a
315/// value or the form value's encoding wasn't a signature reference form.
321/// Take an optional DWARFFormValue and try to extract a supplementary debug
324/// \param V an optional DWARFFormValue to attempt to extract the value from.
325/// \returns an optional value that contains a value if the form value
326/// was valid and has a supplementary reference form.
327inline std::optional<uint64_t>
330 return V->getAsSupplementaryReference();
334/// Take an optional DWARFFormValue and extract a supplementary debug info
337/// \param V an optional DWARFFormValue to attempt to extract the value from.
338/// \param Default the default value to return in case of failure.
339/// \returns the extracted reference value or Default if the V doesn't have a
340/// value or the form value's encoding wasn't a supplementary reference form.
346/// Take an optional DWARFFormValue and try to extract an signed constant.
348/// \param V and optional DWARFFormValue to attempt to extract the value from.
349/// \returns an optional value that contains a value if the form value
350/// was valid and has a signed constant form.
351 inline std::optional<int64_t>
toSigned(
const std::optional<DWARFFormValue> &V) {
353 return V->getAsSignedConstant();
357/// Take an optional DWARFFormValue and extract a signed integer.
359/// \param V and optional DWARFFormValue to attempt to extract the value from.
360/// \param Default the default value to return in case of failure.
361/// \returns the extracted signed integer value or Default if the V doesn't
362/// have a value or the form value's encoding wasn't a signed integer form.
363 inline int64_t
toSigned(
const std::optional<DWARFFormValue> &V,
368/// Take an optional DWARFFormValue and try to extract an address.
370/// \param V and optional DWARFFormValue to attempt to extract the value from.
371/// \returns an optional value that contains a value if the form value
372/// was valid and has a address form.
373inline std::optional<uint64_t>
376 return V->getAsAddress();
380inline std::optional<object::SectionedAddress>
383 return V->getAsSectionedAddress();
387/// Take an optional DWARFFormValue and extract a address.
389/// \param V and optional DWARFFormValue to attempt to extract the value from.
390/// \param Default the default value to return in case of failure.
391/// \returns the extracted address value or Default if the V doesn't have a
392/// value or the form value's encoding wasn't an address form.
398/// Take an optional DWARFFormValue and try to extract an section offset.
400/// \param V and optional DWARFFormValue to attempt to extract the value from.
401/// \returns an optional value that contains a value if the form value
402/// was valid and has a section offset form.
403inline std::optional<uint64_t>
406 return V->getAsSectionOffset();
410/// Take an optional DWARFFormValue and extract a section offset.
412/// \param V and optional DWARFFormValue to attempt to extract the value from.
413/// \param Default the default value to return in case of failure.
414/// \returns the extracted section offset value or Default if the V doesn't
415/// have a value or the form value's encoding wasn't a section offset form.
421/// Take an optional DWARFFormValue and try to extract block data.
423/// \param V and optional DWARFFormValue to attempt to extract the value from.
424/// \returns an optional value that contains a value if the form value
425/// was valid and has a block form.
426inline std::optional<ArrayRef<uint8_t>>
427 toBlock(
const std::optional<DWARFFormValue> &V) {
429 return V->getAsBlock();
433/// Check whether specified \p Form belongs to the \p FC class.
434/// \param Form an attribute form.
435/// \param FC an attribute form class to check.
436/// \param DwarfVersion the version of DWARF debug info keeping the attribute.
437/// \returns true if specified \p Form belongs to the \p FC class.
442}
// end namespace dwarf
444}
// end namespace llvm
446#endif // LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains constants used for implementing Dwarf debug support.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
std::optional< uint64_t > toAddress(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< object::SectionedAddress > toSectionedAddress(const std::optional< DWARFFormValue > &V)
std::optional< int64_t > toSigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an signed constant.
std::optional< uint64_t > toSignatureReference(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a signature reference.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
std::optional< uint64_t > toDebugInfoReference(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an absolute debug info offset reference.
LLVM_ABI bool doesFormBelongToClass(dwarf::Form Form, DWARFFormValue::FormClass FC, uint16_t DwarfVersion)
Check whether specified Form belongs to the FC class.
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< ArrayRef< uint8_t > > toBlock(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract block data.
std::optional< uint64_t > toRelativeReference(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a relative offset reference.
std::optional< uint64_t > toSupplementaryReference(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a supplementary debug info reference.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
@ Default
The result values are uniform if and only if all operands are uniform.
void consumeError(Error Err)
Consume a Error without doing anything.
Container for dump options that control which debug information will be dumped.