Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp
39645 views
//===-- DWARFAttribute.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DWARFAttribute.h"9#include "DWARFUnit.h"10#include "DWARFDebugInfo.h"1112using namespace lldb_private::dwarf;13using namespace lldb_private::plugin::dwarf;1415DWARFAttributes::DWARFAttributes() : m_infos() {}1617DWARFAttributes::~DWARFAttributes() = default;1819uint32_t DWARFAttributes::FindAttributeIndex(dw_attr_t attr) const {20collection::const_iterator end = m_infos.end();21collection::const_iterator beg = m_infos.begin();22collection::const_iterator pos;23for (pos = beg; pos != end; ++pos) {24if (pos->attr.get_attr() == attr)25return std::distance(beg, pos);26}27return UINT32_MAX;28}2930void DWARFAttributes::Append(const DWARFFormValue &form_value,31dw_offset_t attr_die_offset, dw_attr_t attr) {32AttributeValue attr_value = {const_cast<DWARFUnit *>(form_value.GetUnit()),33attr_die_offset,34{attr, form_value.Form(), form_value.Value()}};35m_infos.push_back(attr_value);36}3738bool DWARFAttributes::ExtractFormValueAtIndex(39uint32_t i, DWARFFormValue &form_value) const {40const DWARFUnit *cu = CompileUnitAtIndex(i);41form_value.SetUnit(cu);42form_value.SetForm(FormAtIndex(i));43if (form_value.Form() == DW_FORM_implicit_const) {44form_value.SetValue(ValueAtIndex(i));45return true;46}47lldb::offset_t offset = DIEOffsetAtIndex(i);48return form_value.ExtractValue(cu->GetData(), &offset);49}5051DWARFDIE52DWARFAttributes::FormValueAsReference(dw_attr_t attr) const {53const uint32_t attr_idx = FindAttributeIndex(attr);54if (attr_idx != UINT32_MAX)55return FormValueAsReferenceAtIndex(attr_idx);56return {};57}5859DWARFDIE60DWARFAttributes::FormValueAsReferenceAtIndex(uint32_t i) const {61DWARFFormValue form_value;62if (ExtractFormValueAtIndex(i, form_value))63return form_value.Reference();64return {};65}666768