LLDB  mainline
DWARFAttribute.cpp
Go to the documentation of this file.
1 //===-- DWARFAttribute.cpp ------------------------------------------------===//
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 #include "DWARFAttribute.h"
10 #include "DWARFUnit.h"
11 #include "DWARFDebugInfo.h"
12 
14 
16 
18  collection::const_iterator end = m_infos.end();
19  collection::const_iterator beg = m_infos.begin();
20  collection::const_iterator pos;
21  for (pos = beg; pos != end; ++pos) {
22  if (pos->attr.get_attr() == attr)
23  return std::distance(beg, pos);
24  }
25  return UINT32_MAX;
26 }
27 
28 void DWARFAttributes::Append(const DWARFFormValue &form_value,
29  dw_offset_t attr_die_offset, dw_attr_t attr) {
30  AttributeValue attr_value = {const_cast<DWARFUnit *>(form_value.GetUnit()),
31  attr_die_offset,
32  {attr, form_value.Form(), form_value.Value()}};
33  m_infos.push_back(attr_value);
34 }
35 
37  uint32_t i, DWARFFormValue &form_value) const {
38  const DWARFUnit *cu = CompileUnitAtIndex(i);
39  form_value.SetUnit(cu);
40  form_value.SetForm(FormAtIndex(i));
41  if (form_value.Form() == DW_FORM_implicit_const) {
42  form_value.SetValue(ValueAtIndex(i));
43  return true;
44  }
45  lldb::offset_t offset = DIEOffsetAtIndex(i);
46  return form_value.ExtractValue(cu->GetData(), &offset);
47 }
48 
51  const uint32_t attr_idx = FindAttributeIndex(attr);
52  if (attr_idx != UINT32_MAX)
53  return FormValueAsReferenceAtIndex(attr_idx);
54  return {};
55 }
56 
59  DWARFFormValue form_value;
60  if (ExtractFormValueAtIndex(i, form_value))
61  return form_value.Reference();
62  return {};
63 }
DWARFAttributes::AttributeValue
Definition: DWARFAttribute.h:70
DWARFAttribute.h
DWARFFormValue::Reference
DWARFDIE Reference() const
Definition: DWARFFormValue.cpp:501
DWARFUnit::GetData
const lldb_private::DWARFDataExtractor & GetData() const
Get the data that contains the DIE information for this unit.
Definition: DWARFUnit.cpp:978
DWARFFormValue::Value
const ValueType & Value() const
Definition: DWARFFormValue.h:50
DWARFAttributes::FormValueAsReference
DWARFDIE FormValueAsReference(dw_attr_t attr) const
Definition: DWARFAttribute.cpp:50
DWARFFormValue::SetForm
void SetForm(dw_form_t form)
Definition: DWARFFormValue.h:49
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
DWARFFormValue::SetUnit
void SetUnit(const DWARFUnit *unit)
Definition: DWARFFormValue.h:46
DWARFFormValue::SetValue
void SetValue(const ValueType &val)
Definition: DWARFFormValue.h:52
DWARFDIE
Definition: DWARFDIE.h:16
DWARFAttributes::~DWARFAttributes
~DWARFAttributes()
DWARFUnit
Definition: DWARFUnit.h:80
DWARFAttributes::m_infos
collection m_infos
Definition: DWARFAttribute.h:77
DWARFFormValue::Form
dw_form_t Form() const
Definition: DWARFFormValue.h:47
DWARFFormValue
Definition: DWARFFormValue.h:20
DWARFDebugInfo.h
DWARFUnit.h
DWARFAttributes::ExtractFormValueAtIndex
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
Definition: DWARFAttribute.cpp:36
DWARFAttributes::FormAtIndex
dw_attr_t FormAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:58
DWARFAttributes::ValueAtIndex
DWARFFormValue::ValueType ValueAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:59
DWARFAttributes::FormValueAsReferenceAtIndex
DWARFDIE FormValueAsReferenceAtIndex(uint32_t i) const
Definition: DWARFAttribute.cpp:58
DWARFFormValue::GetUnit
const DWARFUnit * GetUnit() const
Definition: DWARFFormValue.h:45
DWARFAttributes::FindAttributeIndex
uint32_t FindAttributeIndex(dw_attr_t attr) const
Definition: DWARFAttribute.cpp:17
uint32_t
DWARFFormValue::ExtractValue
bool ExtractValue(const lldb_private::DWARFDataExtractor &data, lldb::offset_t *offset_ptr)
Definition: DWARFFormValue.cpp:30
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
uint16_t
DWARFAttributes::DWARFAttributes
DWARFAttributes()
Definition: DWARFAttribute.cpp:13
DWARFAttributes::DIEOffsetAtIndex
dw_offset_t DIEOffsetAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:52
DWARFAttributes::CompileUnitAtIndex
DWARFUnit * CompileUnitAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:51
DWARFAttributes::Append
void Append(const DWARFFormValue &form_value, dw_offset_t attr_die_offset, dw_attr_t attr)
Definition: DWARFAttribute.cpp:28