Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
39645 views
//===-- DWARFASTParser.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DWARFASTParser.h"9#include "DWARFAttribute.h"10#include "DWARFDIE.h"11#include "SymbolFileDWARF.h"1213#include "lldb/Core/ValueObject.h"14#include "lldb/Symbol/SymbolFile.h"15#include "lldb/Target/StackFrame.h"16#include <optional>1718using namespace lldb;19using namespace lldb_private;20using namespace lldb_private::dwarf;21using namespace lldb_private::plugin::dwarf;2223std::optional<SymbolFile::ArrayInfo>24DWARFASTParser::ParseChildArrayInfo(const DWARFDIE &parent_die,25const ExecutionContext *exe_ctx) {26SymbolFile::ArrayInfo array_info;27if (!parent_die)28return std::nullopt;2930for (DWARFDIE die : parent_die.children()) {31const dw_tag_t tag = die.Tag();32if (tag != DW_TAG_subrange_type)33continue;3435DWARFAttributes attributes = die.GetAttributes();36if (attributes.Size() == 0)37continue;3839uint64_t num_elements = 0;40uint64_t lower_bound = 0;41uint64_t upper_bound = 0;42bool upper_bound_valid = false;43for (size_t i = 0; i < attributes.Size(); ++i) {44const dw_attr_t attr = attributes.AttributeAtIndex(i);45DWARFFormValue form_value;46if (attributes.ExtractFormValueAtIndex(i, form_value)) {47switch (attr) {48case DW_AT_name:49break;5051case DW_AT_count:52if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {53if (var_die.Tag() == DW_TAG_variable)54if (exe_ctx) {55if (auto frame = exe_ctx->GetFrameSP()) {56Status error;57lldb::VariableSP var_sp;58auto valobj_sp = frame->GetValueForVariableExpressionPath(59var_die.GetName(), eNoDynamicValues, 0, var_sp, error);60if (valobj_sp) {61num_elements = valobj_sp->GetValueAsUnsigned(0);62break;63}64}65}66} else67num_elements = form_value.Unsigned();68break;6970case DW_AT_bit_stride:71array_info.bit_stride = form_value.Unsigned();72break;7374case DW_AT_byte_stride:75array_info.byte_stride = form_value.Unsigned();76break;7778case DW_AT_lower_bound:79lower_bound = form_value.Unsigned();80break;8182case DW_AT_upper_bound:83upper_bound_valid = true;84upper_bound = form_value.Unsigned();85break;8687default:88break;89}90}91}9293if (num_elements == 0) {94if (upper_bound_valid && upper_bound >= lower_bound)95num_elements = upper_bound - lower_bound + 1;96}9798array_info.element_orders.push_back(num_elements);99}100return array_info;101}102103Type *DWARFASTParser::GetTypeForDIE(const DWARFDIE &die) {104if (!die)105return nullptr;106107SymbolFileDWARF *dwarf = die.GetDWARF();108if (!dwarf)109return nullptr;110111DWARFAttributes attributes = die.GetAttributes();112if (attributes.Size() == 0)113return nullptr;114115DWARFFormValue type_die_form;116for (size_t i = 0; i < attributes.Size(); ++i) {117dw_attr_t attr = attributes.AttributeAtIndex(i);118DWARFFormValue form_value;119120if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value))121return dwarf->ResolveTypeUID(form_value.Reference(), true);122}123124return nullptr;125}126127AccessType128DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility) {129switch (dwarf_accessibility) {130case DW_ACCESS_public:131return eAccessPublic;132case DW_ACCESS_private:133return eAccessPrivate;134case DW_ACCESS_protected:135return eAccessProtected;136default:137break;138}139return eAccessNone;140}141142143