LLDB  mainline
DWARFAttribute.cpp
Go to the documentation of this file.
1 //===-- DWARFAttribute.cpp --------------------------------------*- 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 #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 DWARFUnit *cu, dw_offset_t attr_die_offset,
29  dw_attr_t attr, dw_form_t form) {
30  AttributeValue attr_value = {
31  cu, attr_die_offset, {attr, form, DWARFFormValue::ValueType()}};
32  m_infos.push_back(attr_value);
33 }
34 
36  uint32_t i, DWARFFormValue &form_value) const {
37  const DWARFUnit *cu = CompileUnitAtIndex(i);
38  form_value.SetCompileUnit(cu);
39  form_value.SetForm(FormAtIndex(i));
40  lldb::offset_t offset = DIEOffsetAtIndex(i);
41  return form_value.ExtractValue(cu->GetData(), &offset);
42 }
43 
45  uint64_t fail_value) const {
46  const uint32_t attr_idx = FindAttributeIndex(attr);
47  if (attr_idx != UINT32_MAX)
48  return FormValueAsUnsignedAtIndex(attr_idx, fail_value);
49  return fail_value;
50 }
51 
52 uint64_t
54  uint64_t fail_value) const {
55  DWARFFormValue form_value;
56  if (ExtractFormValueAtIndex(i, form_value))
57  return form_value.Reference();
58  return fail_value;
59 }
void SetCompileUnit(const DWARFUnit *cu)
uint64_t FormValueAsUnsignedAtIndex(uint32_t i, uint64_t fail_value) const
collection m_infos
#define UINT32_MAX
Definition: lldb-defines.h:31
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
bool ExtractValue(const lldb_private::DWARFDataExtractor &data, lldb::offset_t *offset_ptr)
uint64_t offset_t
Definition: lldb-types.h:87
virtual const lldb_private::DWARFDataExtractor & GetData() const =0
Get the data that contains the DIE information for this unit.
uint64_t Reference() const
uint64_t FormValueAsUnsigned(dw_attr_t attr, uint64_t fail_value) const
dw_offset_t DIEOffsetAtIndex(uint32_t i) const
uint32_t FindAttributeIndex(dw_attr_t attr) const
const DWARFUnit * CompileUnitAtIndex(uint32_t i) const
dw_attr_t FormAtIndex(uint32_t i) const
struct DWARFFormValue::ValueTypeTag ValueType
void Append(const DWARFUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form)
void SetForm(dw_form_t form)