LLDB mainline
DWARFASTParser.cpp
Go to the documentation of this file.
1//===-- DWARFASTParser.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 "DWARFASTParser.h"
10#include "DWARFAttribute.h"
11#include "DWARFDIE.h"
12#include "SymbolFileDWARF.h"
13
17#include <optional>
18
19using namespace lldb;
20using namespace lldb_private;
21using namespace lldb_private::plugin::dwarf;
22using namespace llvm::dwarf;
23
25
26std::optional<SymbolFile::ArrayInfo>
28 const ExecutionContext *exe_ctx) {
29 SymbolFile::ArrayInfo array_info;
30 if (!parent_die)
31 return std::nullopt;
32
33 for (DWARFDIE die : parent_die.children()) {
34 const dw_tag_t tag = die.Tag();
35 if (tag != DW_TAG_subrange_type)
36 continue;
37
38 DWARFAttributes attributes = die.GetAttributes();
39 if (attributes.Size() == 0)
40 continue;
41
42 std::optional<uint64_t> num_elements;
43 uint64_t lower_bound = 0;
44 uint64_t upper_bound = 0;
45 bool upper_bound_valid = false;
46 for (size_t i = 0; i < attributes.Size(); ++i) {
47 const dw_attr_t attr = attributes.AttributeAtIndex(i);
48 DWARFFormValue form_value;
49 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
50 switch (attr) {
51 case DW_AT_name:
52 break;
53
54 case DW_AT_count:
55 if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
56 if (var_die.Tag() == DW_TAG_variable)
57 if (exe_ctx) {
58 if (auto frame = exe_ctx->GetFrameSP()) {
60 lldb::VariableSP var_sp;
61 auto valobj_sp = frame->GetValueForVariableExpressionPath(
62 var_die.GetName(), eNoDynamicValues, 0, var_sp, error);
63 if (valobj_sp) {
64 num_elements = valobj_sp->GetValueAsUnsigned(0);
65 break;
66 }
67 }
68 }
69 } else
70 num_elements = form_value.Unsigned();
71 break;
72
73 case DW_AT_bit_stride:
74 array_info.bit_stride = form_value.Unsigned();
75 break;
76
77 case DW_AT_byte_stride:
78 array_info.byte_stride = form_value.Unsigned();
79 break;
80
81 case DW_AT_lower_bound:
82 lower_bound = form_value.Unsigned();
83 break;
84
85 case DW_AT_upper_bound:
86 upper_bound_valid = true;
87 upper_bound = form_value.Unsigned();
88 break;
89
90 default:
91 break;
92 }
93 }
94 }
95
96 if (!num_elements || *num_elements == 0) {
97 if (upper_bound_valid && upper_bound >= lower_bound)
98 num_elements = upper_bound - lower_bound + 1;
99 }
100
101 array_info.element_orders.push_back(num_elements);
102 }
103 return array_info;
104}
105
107 if (!die)
108 return nullptr;
109
111 if (!dwarf)
112 return nullptr;
113
114 DWARFAttributes attributes = die.GetAttributes();
115 if (attributes.Size() == 0)
116 return nullptr;
117
118 DWARFFormValue type_die_form;
119 for (size_t i = 0; i < attributes.Size(); ++i) {
120 dw_attr_t attr = attributes.AttributeAtIndex(i);
121 DWARFFormValue form_value;
122
123 if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value))
124 return dwarf->ResolveTypeUID(form_value.Reference(), true);
125 }
126
127 return nullptr;
128}
129
131DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility) {
132 switch (dwarf_accessibility) {
133 case DW_ACCESS_public:
134 return eAccessPublic;
135 case DW_ACCESS_private:
136 return eAccessPrivate;
137 case DW_ACCESS_protected:
138 return eAccessProtected;
139 default:
140 break;
141 }
142 return eAccessNone;
143}
144
146 llvm::StringRef name) {
147 for (DWARFDIE child : die.children())
148 if (child.Tag() == DW_TAG_LLVM_annotation &&
149 llvm::StringRef(child.GetName()) == name)
150 return child;
151 return {};
152}
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
An error handling class.
Definition Status.h:118
lldb_private::Type * GetTypeForDIE(const DWARFDIE &die)
static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility)
static std::optional< SymbolFile::ArrayInfo > ParseChildArrayInfo(const DWARFDIE &parent_die, const ExecutionContext *exe_ctx=nullptr)
static DWARFDIE GetAnnotation(const DWARFDIE &die, llvm::StringRef name)
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition DWARFDIE.cpp:601
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition DWARFDIE.cpp:118
llvm::dwarf::Tag dw_tag_t
Definition dwarf.h:19
llvm::dwarf::Attribute dw_attr_t
Definition dwarf.h:17
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Variable > VariableSP
The characteristics of an array type.
Definition SymbolFile.h:220
llvm::SmallVector< std::optional< uint64_t >, 1 > element_orders
Each entry belongs to a distinct DW_TAG_subrange_type.
Definition SymbolFile.h:230