1 //===-- UniqueDWARFASTType.cpp ----------------------------------*- C++ -*-===//
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 "UniqueDWARFASTType.h"
11 #include "lldb/Symbol/Declaration.h"
13 bool UniqueDWARFASTTypeList::Find(const DWARFDIE &die,
14 const lldb_private::Declaration &decl,
15 const int32_t byte_size,
16 UniqueDWARFASTType &entry) const {
17 for (const UniqueDWARFASTType &udt : m_collection) {
18 // Make sure the tags match
19 if (udt.m_die.Tag() == die.Tag()) {
20 // Validate byte sizes of both types only if both are valid.
21 if (udt.m_byte_size < 0 || byte_size < 0 ||
22 udt.m_byte_size == byte_size) {
23 // Make sure the file and line match
24 if (udt.m_declaration == decl) {
25 // The type has the same name, and was defined on the same file and
26 // line. Now verify all of the parent DIEs match.
27 DWARFDIE parent_arg_die = die.GetParent();
28 DWARFDIE parent_pos_die = udt.m_die.GetParent();
31 while (!done && match && parent_arg_die && parent_pos_die) {
32 const dw_tag_t parent_arg_tag = parent_arg_die.Tag();
33 const dw_tag_t parent_pos_tag = parent_pos_die.Tag();
34 if (parent_arg_tag == parent_pos_tag) {
35 switch (parent_arg_tag) {
36 case DW_TAG_class_type:
37 case DW_TAG_structure_type:
38 case DW_TAG_union_type:
39 case DW_TAG_namespace: {
40 const char *parent_arg_die_name = parent_arg_die.GetName();
41 if (parent_arg_die_name ==
42 nullptr) // Anonymous (i.e. no-name) struct
46 const char *parent_pos_die_name = parent_pos_die.GetName();
47 if (parent_pos_die_name == nullptr ||
48 ((parent_arg_die_name != parent_pos_die_name) &&
49 strcmp(parent_arg_die_name, parent_pos_die_name)))
54 case DW_TAG_compile_unit:
55 case DW_TAG_partial_unit:
60 parent_arg_die = parent_arg_die.GetParent();
61 parent_pos_die = parent_pos_die.GetParent();