[LoongArch] Supports FP_TO_SINT operation for fp16 (#118303)
[llvm-project.git] / lldb / source / Plugins / SymbolFile / DWARF / DWARFASTParser.cpp
blobe53e930665a602de10a05be50ab7e5f72d194c65
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 //===----------------------------------------------------------------------===//
9 #include "DWARFASTParser.h"
10 #include "DWARFAttribute.h"
11 #include "DWARFDIE.h"
12 #include "SymbolFileDWARF.h"
14 #include "lldb/Symbol/SymbolFile.h"
15 #include "lldb/Target/StackFrame.h"
16 #include "lldb/ValueObject/ValueObject.h"
17 #include <optional>
19 using namespace lldb;
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;
28 if (!parent_die)
29 return std::nullopt;
31 for (DWARFDIE die : parent_die.children()) {
32 const dw_tag_t tag = die.Tag();
33 if (tag != DW_TAG_subrange_type)
34 continue;
36 DWARFAttributes attributes = die.GetAttributes();
37 if (attributes.Size() == 0)
38 continue;
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)) {
48 switch (attr) {
49 case DW_AT_name:
50 break;
52 case DW_AT_count:
53 if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
54 if (var_die.Tag() == DW_TAG_variable)
55 if (exe_ctx) {
56 if (auto frame = exe_ctx->GetFrameSP()) {
57 Status error;
58 lldb::VariableSP var_sp;
59 auto valobj_sp = frame->GetValueForVariableExpressionPath(
60 var_die.GetName(), eNoDynamicValues, 0, var_sp, error);
61 if (valobj_sp) {
62 num_elements = valobj_sp->GetValueAsUnsigned(0);
63 break;
67 } else
68 num_elements = form_value.Unsigned();
69 break;
71 case DW_AT_bit_stride:
72 array_info.bit_stride = form_value.Unsigned();
73 break;
75 case DW_AT_byte_stride:
76 array_info.byte_stride = form_value.Unsigned();
77 break;
79 case DW_AT_lower_bound:
80 lower_bound = form_value.Unsigned();
81 break;
83 case DW_AT_upper_bound:
84 upper_bound_valid = true;
85 upper_bound = form_value.Unsigned();
86 break;
88 default:
89 break;
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);
101 return array_info;
104 Type *DWARFASTParser::GetTypeForDIE(const DWARFDIE &die) {
105 if (!die)
106 return nullptr;
108 SymbolFileDWARF *dwarf = die.GetDWARF();
109 if (!dwarf)
110 return nullptr;
112 DWARFAttributes attributes = die.GetAttributes();
113 if (attributes.Size() == 0)
114 return nullptr;
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);
125 return nullptr;
128 AccessType
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;
137 default:
138 break;
140 return eAccessNone;