1 //===-- DWARFAttribute.cpp --------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "DWARFAttribute.h" 11 #include "DWARFCompileUnit.h" 12 #include "DWARFDebugInfo.h" 13 14 DWARFAttributes::DWARFAttributes() : m_infos() {} 15 16 DWARFAttributes::~DWARFAttributes() {} 17 18 uint32_t DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const { 19 collection::const_iterator end = m_infos.end(); 20 collection::const_iterator beg = m_infos.begin(); 21 collection::const_iterator pos; 22 for (pos = beg; pos != end; ++pos) { 23 if (pos->attr.get_attr() == attr) 24 return std::distance(beg, pos); 25 } 26 return UINT32_MAX; 27 } 28 29 void DWARFAttributes::Append(const DWARFCompileUnit *cu, 30 dw_offset_t attr_die_offset, dw_attr_t attr, 31 dw_form_t form) { 32 AttributeValue attr_value = {cu, attr_die_offset, {attr, form}}; 33 m_infos.push_back(attr_value); 34 } 35 36 bool DWARFAttributes::ContainsAttribute(dw_attr_t attr) const { 37 return FindAttributeIndex(attr) != UINT32_MAX; 38 } 39 40 bool DWARFAttributes::RemoveAttribute(dw_attr_t attr) { 41 uint32_t attr_index = FindAttributeIndex(attr); 42 if (attr_index != UINT32_MAX) { 43 m_infos.erase(m_infos.begin() + attr_index); 44 return true; 45 } 46 return false; 47 } 48 49 bool DWARFAttributes::ExtractFormValueAtIndex( 50 uint32_t i, DWARFFormValue &form_value) const { 51 const DWARFCompileUnit *cu = CompileUnitAtIndex(i); 52 form_value.SetCompileUnit(cu); 53 form_value.SetForm(FormAtIndex(i)); 54 lldb::offset_t offset = DIEOffsetAtIndex(i); 55 return form_value.ExtractValue( 56 cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset); 57 } 58 59 uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr, 60 uint64_t fail_value) const { 61 const uint32_t attr_idx = FindAttributeIndex(attr); 62 if (attr_idx != UINT32_MAX) 63 return FormValueAsUnsignedAtIndex(attr_idx, fail_value); 64 return fail_value; 65 } 66 67 uint64_t 68 DWARFAttributes::FormValueAsUnsignedAtIndex(uint32_t i, 69 uint64_t fail_value) const { 70 DWARFFormValue form_value; 71 if (ExtractFormValueAtIndex(i, form_value)) 72 return form_value.Reference(); 73 return fail_value; 74 } 75