//===- DWARFFormValue.h -----------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H #define LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H #include "llvm/ADT/ArrayRef.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/DebugInfo/DIContext.h" #include "llvm/Support/DataExtractor.h" #include <cstdint> namespace llvm { class DWARFContext; class DWARFObject; class DWARFDataExtractor; class DWARFUnit; class raw_ostream; class DWARFFormValue { … }; namespace dwarf { /// Take an optional DWARFFormValue and try to extract a string value from it. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and was a string. inline std::optional<const char *> toString(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and try to extract a string value from it. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and was a string. inline StringRef toStringRef(const std::optional<DWARFFormValue> &V, StringRef Default = { … } /// Take an optional DWARFFormValue and extract a string value from it. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the string value or Default if the V doesn't have a value or the /// form value's encoding wasn't a string. inline const char *toString(const std::optional<DWARFFormValue> &V, const char *Default) { … } /// Take an optional DWARFFormValue and try to extract an unsigned constant. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a unsigned constant form. inline std::optional<uint64_t> toUnsigned(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a unsigned constant. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted unsigned value or Default if the V doesn't have a /// value or the form value's encoding wasn't an unsigned constant form. inline uint64_t toUnsigned(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract a relative offset /// reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a relative reference form. inline std::optional<uint64_t> toRelativeReference(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a relative offset reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted reference value or Default if the V doesn't have a /// value or the form value's encoding wasn't a relative offset reference form. inline uint64_t toRelativeReference(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract an absolute debug info /// offset reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has an (absolute) debug info offset reference form. inline std::optional<uint64_t> toDebugInfoReference(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract an absolute debug info offset /// reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted reference value or Default if the V doesn't have a /// value or the form value's encoding wasn't an absolute debug info offset /// reference form. inline uint64_t toDebugInfoReference(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract a signature reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a signature reference form. inline std::optional<uint64_t> toSignatureReference(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a signature reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted reference value or Default if the V doesn't have a /// value or the form value's encoding wasn't a signature reference form. inline uint64_t toSignatureReference(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract a supplementary debug /// info reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a supplementary reference form. inline std::optional<uint64_t> toSupplementaryReference(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a supplementary debug info /// reference. /// /// \param V an optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted reference value or Default if the V doesn't have a /// value or the form value's encoding wasn't a supplementary reference form. inline uint64_t toSupplementaryReference(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract an signed constant. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a signed constant form. inline std::optional<int64_t> toSigned(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a signed integer. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted signed integer value or Default if the V doesn't /// have a value or the form value's encoding wasn't a signed integer form. inline int64_t toSigned(const std::optional<DWARFFormValue> &V, int64_t Default) { … } /// Take an optional DWARFFormValue and try to extract an address. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a address form. inline std::optional<uint64_t> toAddress(const std::optional<DWARFFormValue> &V) { … } inline std::optional<object::SectionedAddress> toSectionedAddress(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a address. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted address value or Default if the V doesn't have a /// value or the form value's encoding wasn't an address form. inline uint64_t toAddress(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract an section offset. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a section offset form. inline std::optional<uint64_t> toSectionOffset(const std::optional<DWARFFormValue> &V) { … } /// Take an optional DWARFFormValue and extract a section offset. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \param Default the default value to return in case of failure. /// \returns the extracted section offset value or Default if the V doesn't /// have a value or the form value's encoding wasn't a section offset form. inline uint64_t toSectionOffset(const std::optional<DWARFFormValue> &V, uint64_t Default) { … } /// Take an optional DWARFFormValue and try to extract block data. /// /// \param V and optional DWARFFormValue to attempt to extract the value from. /// \returns an optional value that contains a value if the form value /// was valid and has a block form. inline std::optional<ArrayRef<uint8_t>> toBlock(const std::optional<DWARFFormValue> &V) { … } /// Check whether specified \p Form belongs to the \p FC class. /// \param Form an attribute form. /// \param FC an attribute form class to check. /// \param DwarfVersion the version of DWARF debug info keeping the attribute. /// \returns true if specified \p Form belongs to the \p FC class. bool doesFormBelongToClass(dwarf::Form Form, DWARFFormValue::FormClass FC, uint16_t DwarfVersion); } // end namespace dwarf } // end namespace llvm #endif // LLVM_DEBUGINFO_DWARF_DWARFFORMVALUE_H