LLDB  mainline
DWARFAbbreviationDeclaration.cpp
Go to the documentation of this file.
1 //===-- DWARFAbbreviationDeclaration.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 
10 
11 #include "lldb/Core/dwarf.h"
12 #include "lldb/Utility/Stream.h"
13 
14 #include "llvm/Object/Error.h"
15 
16 #include "DWARFFormValue.h"
17 
18 using namespace lldb_private;
19 
21  : m_code(InvalidCode), m_tag(llvm::dwarf::DW_TAG_null), m_has_children(0),
22  m_attributes() {}
23 
25  uint8_t has_children)
26  : m_code(InvalidCode), m_tag(tag), m_has_children(has_children),
27  m_attributes() {}
28 
29 llvm::Expected<DWARFEnumState>
31  lldb::offset_t *offset_ptr) {
32  m_code = data.GetULEB128(offset_ptr);
33  if (m_code == 0)
34  return DWARFEnumState::Complete;
35 
36  m_attributes.clear();
37  m_tag = static_cast<dw_tag_t>(data.GetULEB128(offset_ptr));
38  if (m_tag == DW_TAG_null)
39  return llvm::make_error<llvm::object::GenericBinaryError>(
40  "abbrev decl requires non-null tag.");
41 
42  m_has_children = data.GetU8(offset_ptr);
43 
44  while (data.ValidOffset(*offset_ptr)) {
45  dw_attr_t attr = data.GetULEB128(offset_ptr);
46  dw_form_t form = data.GetULEB128(offset_ptr);
47 
48  // This is the last attribute for this abbrev decl, but there may still be
49  // more abbrev decls, so return MoreItems to indicate to the caller that
50  // they should call this function again.
51  if (!attr && !form)
52  return DWARFEnumState::MoreItems;
53 
54  if (!attr || !form)
55  return llvm::make_error<llvm::object::GenericBinaryError>(
56  "malformed abbreviation declaration attribute");
57 
59 
60  if (form == DW_FORM_implicit_const)
61  val.value.sval = data.GetULEB128(offset_ptr);
62 
63  m_attributes.push_back(DWARFAttribute(attr, form, val));
64  }
65 
66  return llvm::make_error<llvm::object::GenericBinaryError>(
67  "abbreviation declaration attribute list not terminated with a null "
68  "entry");
69 }
70 
72  return m_code != 0 && m_tag != llvm::dwarf::DW_TAG_null;
73 }
74 
77  uint32_t i;
78  const uint32_t kNumAttributes = m_attributes.size();
79  for (i = 0; i < kNumAttributes; ++i) {
80  if (m_attributes[i].get_attr() == attr)
81  return i;
82  }
83  return DW_INVALID_INDEX;
84 }
85 
88  return Tag() == rhs.Tag() && HasChildren() == rhs.HasChildren() &&
90 }
A class that represents a running process on the host machine.
Definition: Debugger.h:49
uint32_t FindAttributeIndex(dw_attr_t attr) const
#define DW_INVALID_INDEX
Definition: dwarf.h:35
llvm::Expected< lldb_private::DWARFEnumState > extract(const lldb_private::DWARFDataExtractor &data, lldb::offset_t *offset_ptr)
Extract one abbreviation declaration and all of its associated attributes.
uint64_t offset_t
Definition: lldb-types.h:87
bool operator==(const DWARFAbbreviationDeclaration &rhs) const
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
union DWARFFormValue::ValueTypeTag::@146 value
DWARFAttribute::collection m_attributes