1 //===-- DWARFASTParser.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "DWARFASTParser.h"
10 #include "DWARFAttribute.h"
12 #include "SymbolFileDWARF.h"
14 #include "lldb/Symbol/SymbolFile.h"
15 #include "lldb/Target/StackFrame.h"
16 #include "lldb/ValueObject/ValueObject.h"
20 using namespace lldb_private
;
21 using namespace lldb_private::dwarf
;
22 using namespace lldb_private::plugin::dwarf
;
24 std::optional
<SymbolFile::ArrayInfo
>
25 DWARFASTParser::ParseChildArrayInfo(const DWARFDIE
&parent_die
,
26 const ExecutionContext
*exe_ctx
) {
27 SymbolFile::ArrayInfo array_info
;
31 for (DWARFDIE die
: parent_die
.children()) {
32 const dw_tag_t tag
= die
.Tag();
33 if (tag
!= DW_TAG_subrange_type
)
36 DWARFAttributes attributes
= die
.GetAttributes();
37 if (attributes
.Size() == 0)
40 std::optional
<uint64_t> num_elements
;
41 uint64_t lower_bound
= 0;
42 uint64_t upper_bound
= 0;
43 bool upper_bound_valid
= false;
44 for (size_t i
= 0; i
< attributes
.Size(); ++i
) {
45 const dw_attr_t attr
= attributes
.AttributeAtIndex(i
);
46 DWARFFormValue form_value
;
47 if (attributes
.ExtractFormValueAtIndex(i
, form_value
)) {
53 if (DWARFDIE var_die
= die
.GetReferencedDIE(DW_AT_count
)) {
54 if (var_die
.Tag() == DW_TAG_variable
)
56 if (auto frame
= exe_ctx
->GetFrameSP()) {
58 lldb::VariableSP var_sp
;
59 auto valobj_sp
= frame
->GetValueForVariableExpressionPath(
60 var_die
.GetName(), eNoDynamicValues
, 0, var_sp
, error
);
62 num_elements
= valobj_sp
->GetValueAsUnsigned(0);
68 num_elements
= form_value
.Unsigned();
71 case DW_AT_bit_stride
:
72 array_info
.bit_stride
= form_value
.Unsigned();
75 case DW_AT_byte_stride
:
76 array_info
.byte_stride
= form_value
.Unsigned();
79 case DW_AT_lower_bound
:
80 lower_bound
= form_value
.Unsigned();
83 case DW_AT_upper_bound
:
84 upper_bound_valid
= true;
85 upper_bound
= form_value
.Unsigned();
94 if (!num_elements
|| *num_elements
== 0) {
95 if (upper_bound_valid
&& upper_bound
>= lower_bound
)
96 num_elements
= upper_bound
- lower_bound
+ 1;
99 array_info
.element_orders
.push_back(num_elements
);
104 Type
*DWARFASTParser::GetTypeForDIE(const DWARFDIE
&die
) {
108 SymbolFileDWARF
*dwarf
= die
.GetDWARF();
112 DWARFAttributes attributes
= die
.GetAttributes();
113 if (attributes
.Size() == 0)
116 DWARFFormValue type_die_form
;
117 for (size_t i
= 0; i
< attributes
.Size(); ++i
) {
118 dw_attr_t attr
= attributes
.AttributeAtIndex(i
);
119 DWARFFormValue form_value
;
121 if (attr
== DW_AT_type
&& attributes
.ExtractFormValueAtIndex(i
, form_value
))
122 return dwarf
->ResolveTypeUID(form_value
.Reference(), true);
129 DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility
) {
130 switch (dwarf_accessibility
) {
131 case DW_ACCESS_public
:
132 return eAccessPublic
;
133 case DW_ACCESS_private
:
134 return eAccessPrivate
;
135 case DW_ACCESS_protected
:
136 return eAccessProtected
;