|
@@ -22,6 +22,35 @@ namespace llvm {
|
|
|
class DWARFUnit;
|
|
|
class raw_ostream;
|
|
|
|
|
|
+/// A helper struct for DWARFFormValue methods, providing information that
|
|
|
+/// allows it to know the byte size of DW_FORM values that vary in size
|
|
|
+/// depending on the DWARF version, address byte size, or DWARF32/DWARF64.
|
|
|
+struct DWARFFormParams {
|
|
|
+ uint16_t Version;
|
|
|
+ uint8_t AddrSize;
|
|
|
+ dwarf::DwarfFormat Format;
|
|
|
+
|
|
|
+ /// The definition of the size of form DW_FORM_ref_addr depends on the
|
|
|
+ /// version. In DWARF v2 it's the size of an address; after that, it's the
|
|
|
+ /// size of a reference.
|
|
|
+ uint8_t getRefAddrByteSize() const {
|
|
|
+ if (Version == 2)
|
|
|
+ return AddrSize;
|
|
|
+ return getDwarfOffsetByteSize();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// The size of a reference is determined by the DWARF 32/64-bit format.
|
|
|
+ uint8_t getDwarfOffsetByteSize() const {
|
|
|
+ switch (Format) {
|
|
|
+ case dwarf::DwarfFormat::DWARF32:
|
|
|
+ return 4;
|
|
|
+ case dwarf::DwarfFormat::DWARF64:
|
|
|
+ return 8;
|
|
|
+ }
|
|
|
+ llvm_unreachable("Invalid Format value");
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
class DWARFFormValue {
|
|
|
public:
|
|
|
enum FormClass {
|
|
@@ -104,79 +133,43 @@ public:
|
|
|
|
|
|
/// Get the fixed byte size for a given form.
|
|
|
///
|
|
|
- /// If the form always has a fixed valid byte size that doesn't depend on a
|
|
|
- /// DWARFUnit, then an Optional with a value will be returned. If the form
|
|
|
- /// can vary in size depending on the DWARFUnit (DWARF version, address byte
|
|
|
- /// size, or DWARF 32/64) and the DWARFUnit is valid, then an Optional with a
|
|
|
- /// valid value is returned. If the form is always encoded using a variable
|
|
|
- /// length storage format (ULEB or SLEB numbers or blocks) or the size
|
|
|
- /// depends on a DWARFUnit and the DWARFUnit is NULL, then None will be
|
|
|
- /// returned.
|
|
|
- /// \param Form The DWARF form to get the fixed byte size for
|
|
|
- /// \param U The DWARFUnit that can be used to help determine the byte size.
|
|
|
- ///
|
|
|
- /// \returns Optional<uint8_t> value with the fixed byte size or None if
|
|
|
- /// \p Form doesn't have a fixed byte size or a DWARFUnit wasn't supplied
|
|
|
- /// and was needed to calculate the byte size.
|
|
|
- static Optional<uint8_t> getFixedByteSize(dwarf::Form Form,
|
|
|
- const DWARFUnit *U = nullptr);
|
|
|
-
|
|
|
- /// Get the fixed byte size for a given form.
|
|
|
- ///
|
|
|
- /// If the form has a fixed byte size given a valid DWARF version and address
|
|
|
- /// byte size, then an Optional with a valid value is returned. If the form
|
|
|
- /// is always encoded using a variable length storage format (ULEB or SLEB
|
|
|
- /// numbers or blocks) then None will be returned.
|
|
|
+ /// If the form has a fixed byte size, then an Optional with a value will be
|
|
|
+ /// returned. If the form is always encoded using a variable length storage
|
|
|
+ /// format (ULEB or SLEB numbers or blocks) then None will be returned.
|
|
|
///
|
|
|
- /// \param Form DWARF form to get the fixed byte size for
|
|
|
- /// \param Version DWARF version number.
|
|
|
- /// \param AddrSize size of an address in bytes.
|
|
|
- /// \param Format enum value from llvm::dwarf::DwarfFormat.
|
|
|
+ /// \param Form DWARF form to get the fixed byte size for.
|
|
|
+ /// \param FormParams DWARF parameters to help interpret forms.
|
|
|
/// \returns Optional<uint8_t> value with the fixed byte size or None if
|
|
|
/// \p Form doesn't have a fixed byte size.
|
|
|
- static Optional<uint8_t> getFixedByteSize(dwarf::Form Form, uint16_t Version,
|
|
|
- uint8_t AddrSize,
|
|
|
- llvm::dwarf::DwarfFormat Format);
|
|
|
+ static Optional<uint8_t> getFixedByteSize(dwarf::Form Form,
|
|
|
+ const DWARFFormParams &FormParams);
|
|
|
|
|
|
- /// Skip a form in \p DebugInfoData at offset specified by \p OffsetPtr.
|
|
|
+ /// Skip a form's value in \p DebugInfoData at the offset specified by
|
|
|
+ /// \p OffsetPtr.
|
|
|
///
|
|
|
- /// Skips the bytes for this form in the debug info and updates the offset.
|
|
|
+ /// Skips the bytes for the current form and updates the offset.
|
|
|
///
|
|
|
- /// \param DebugInfoData the .debug_info data to use to skip the value.
|
|
|
- /// \param OffsetPtr a reference to the offset that will be updated.
|
|
|
- /// \param U the DWARFUnit to use when skipping the form in case the form
|
|
|
- /// size differs according to data in the DWARFUnit.
|
|
|
+ /// \param DebugInfoData The data where we want to skip the value.
|
|
|
+ /// \param OffsetPtr A reference to the offset that will be updated.
|
|
|
+ /// \param Params DWARF parameters to help interpret forms.
|
|
|
/// \returns true on success, false if the form was not skipped.
|
|
|
bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr,
|
|
|
- const DWARFUnit *U) const;
|
|
|
-
|
|
|
- /// Skip a form in \p DebugInfoData at offset specified by \p OffsetPtr.
|
|
|
- ///
|
|
|
- /// Skips the bytes for this form in the debug info and updates the offset.
|
|
|
- ///
|
|
|
- /// \param Form the DW_FORM enumeration that indicates the form to skip.
|
|
|
- /// \param DebugInfoData the .debug_info data to use to skip the value.
|
|
|
- /// \param OffsetPtr a reference to the offset that will be updated.
|
|
|
- /// \param U the DWARFUnit to use when skipping the form in case the form
|
|
|
- /// size differs according to data in the DWARFUnit.
|
|
|
- /// \returns true on success, false if the form was not skipped.
|
|
|
- static bool skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
|
|
|
- uint32_t *OffsetPtr, const DWARFUnit *U);
|
|
|
+ const DWARFFormParams &Params) const {
|
|
|
+ return DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, Params);
|
|
|
+ }
|
|
|
|
|
|
- /// Skip a form in \p DebugInfoData at offset specified by \p OffsetPtr.
|
|
|
+ /// Skip a form's value in \p DebugInfoData at the offset specified by
|
|
|
+ /// \p OffsetPtr.
|
|
|
///
|
|
|
- /// Skips the bytes for this form in the debug info and updates the offset.
|
|
|
+ /// Skips the bytes for the specified form and updates the offset.
|
|
|
///
|
|
|
- /// \param Form the DW_FORM enumeration that indicates the form to skip.
|
|
|
- /// \param DebugInfoData the .debug_info data to use to skip the value.
|
|
|
- /// \param OffsetPtr a reference to the offset that will be updated.
|
|
|
- /// \param Version DWARF version number.
|
|
|
- /// \param AddrSize size of an address in bytes.
|
|
|
- /// \param Format enum value from llvm::dwarf::DwarfFormat.
|
|
|
+ /// \param Form The DW_FORM enumeration that indicates the form to skip.
|
|
|
+ /// \param DebugInfoData The data where we want to skip the value.
|
|
|
+ /// \param OffsetPtr A reference to the offset that will be updated.
|
|
|
+ /// \param FormParams DWARF parameters to help interpret forms.
|
|
|
/// \returns true on success, false if the form was not skipped.
|
|
|
static bool skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
|
|
|
- uint32_t *OffsetPtr, uint16_t Version, uint8_t AddrSize,
|
|
|
- llvm::dwarf::DwarfFormat Format);
|
|
|
+ uint32_t *OffsetPtr, const DWARFFormParams &FormParams);
|
|
|
|
|
|
private:
|
|
|
void dumpString(raw_ostream &OS) const;
|