1 //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===// 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 9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H 10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H 11 12 #include "DWARFDefines.h" 13 #include "DWARFFormValue.h" 14 #include "llvm/ADT/SmallVector.h" 15 #include <vector> 16 17 class DWARFUnit; 18 19 class DWARFAttribute { 20 public: 21 DWARFAttribute(dw_attr_t attr, dw_form_t form, 22 DWARFFormValue::ValueType value) 23 : m_attr(attr), m_form(form), m_value(value) {} 24 25 dw_attr_t get_attr() const { return m_attr; } 26 dw_form_t get_form() const { return m_form; } 27 DWARFFormValue::ValueType get_value() const { return m_value; } 28 void get(dw_attr_t &attr, dw_form_t &form, 29 DWARFFormValue::ValueType &val) const { 30 attr = m_attr; 31 form = m_form; 32 val = m_value; 33 } 34 typedef std::vector<DWARFAttribute> collection; 35 typedef collection::iterator iterator; 36 typedef collection::const_iterator const_iterator; 37 38 protected: 39 dw_attr_t m_attr; 40 dw_form_t m_form; 41 DWARFFormValue::ValueType m_value; 42 }; 43 44 class DWARFAttributes { 45 public: 46 DWARFAttributes(); 47 ~DWARFAttributes(); 48 49 void Append(const DWARFFormValue &form_value, dw_offset_t attr_die_offset, 50 dw_attr_t attr); 51 DWARFUnit *CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; } 52 dw_offset_t DIEOffsetAtIndex(uint32_t i) const { 53 return m_infos[i].die_offset; 54 } 55 dw_attr_t AttributeAtIndex(uint32_t i) const { 56 return m_infos[i].attr.get_attr(); 57 } 58 dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); } 59 DWARFFormValue::ValueType ValueAtIndex(uint32_t i) const { 60 return m_infos[i].attr.get_value(); 61 } 62 bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const; 63 DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const; 64 DWARFDIE FormValueAsReference(dw_attr_t attr) const; 65 uint32_t FindAttributeIndex(dw_attr_t attr) const; 66 void Clear() { m_infos.clear(); } 67 size_t Size() const { return m_infos.size(); } 68 69 protected: 70 struct AttributeValue { 71 DWARFUnit *cu; // Keep the compile unit with each attribute in 72 // case we have DW_FORM_ref_addr values 73 dw_offset_t die_offset; 74 DWARFAttribute attr; 75 }; 76 typedef llvm::SmallVector<AttributeValue, 8> collection; 77 collection m_infos; 78 }; 79 80 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFATTRIBUTE_H 81