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