1254721Semaste//===-- UniqueDWARFASTType.cpp ----------------------------------*- C++ -*-===// 2254721Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6254721Semaste// 7254721Semaste//===----------------------------------------------------------------------===// 8254721Semaste 9254721Semaste#include "UniqueDWARFASTType.h" 10254721Semaste 11254721Semaste#include "lldb/Symbol/Declaration.h" 12254721Semaste 13314564Sdimbool UniqueDWARFASTTypeList::Find(const DWARFDIE &die, 14314564Sdim const lldb_private::Declaration &decl, 15314564Sdim const int32_t byte_size, 16314564Sdim UniqueDWARFASTType &entry) const { 17314564Sdim for (const UniqueDWARFASTType &udt : m_collection) { 18314564Sdim // Make sure the tags match 19314564Sdim if (udt.m_die.Tag() == die.Tag()) { 20314564Sdim // Validate byte sizes of both types only if both are valid. 21314564Sdim if (udt.m_byte_size < 0 || byte_size < 0 || 22314564Sdim udt.m_byte_size == byte_size) { 23314564Sdim // Make sure the file and line match 24314564Sdim if (udt.m_declaration == decl) { 25341825Sdim // The type has the same name, and was defined on the same file and 26341825Sdim // line. Now verify all of the parent DIEs match. 27314564Sdim DWARFDIE parent_arg_die = die.GetParent(); 28314564Sdim DWARFDIE parent_pos_die = udt.m_die.GetParent(); 29314564Sdim bool match = true; 30314564Sdim bool done = false; 31314564Sdim while (!done && match && parent_arg_die && parent_pos_die) { 32314564Sdim const dw_tag_t parent_arg_tag = parent_arg_die.Tag(); 33314564Sdim const dw_tag_t parent_pos_tag = parent_pos_die.Tag(); 34314564Sdim if (parent_arg_tag == parent_pos_tag) { 35314564Sdim switch (parent_arg_tag) { 36314564Sdim case DW_TAG_class_type: 37314564Sdim case DW_TAG_structure_type: 38314564Sdim case DW_TAG_union_type: 39314564Sdim case DW_TAG_namespace: { 40314564Sdim const char *parent_arg_die_name = parent_arg_die.GetName(); 41314564Sdim if (parent_arg_die_name == 42353358Sdim nullptr) // Anonymous (i.e. no-name) struct 43254721Semaste { 44314564Sdim match = false; 45314564Sdim } else { 46314564Sdim const char *parent_pos_die_name = parent_pos_die.GetName(); 47353358Sdim if (parent_pos_die_name == nullptr || 48314564Sdim ((parent_arg_die_name != parent_pos_die_name) && 49314564Sdim strcmp(parent_arg_die_name, parent_pos_die_name))) 50314564Sdim match = false; 51314564Sdim } 52314564Sdim } break; 53254721Semaste 54314564Sdim case DW_TAG_compile_unit: 55341825Sdim case DW_TAG_partial_unit: 56314564Sdim done = true; 57314564Sdim break; 58360784Sdim default: 59360784Sdim break; 60314564Sdim } 61254721Semaste } 62314564Sdim parent_arg_die = parent_arg_die.GetParent(); 63314564Sdim parent_pos_die = parent_pos_die.GetParent(); 64314564Sdim } 65314564Sdim 66314564Sdim if (match) { 67314564Sdim entry = udt; 68314564Sdim return true; 69314564Sdim } 70254721Semaste } 71314564Sdim } 72254721Semaste } 73314564Sdim } 74314564Sdim return false; 75254721Semaste} 76