UniqueDWARFASTType.cpp revision 353358
1//===-- UniqueDWARFASTType.cpp ----------------------------------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8
9#include "UniqueDWARFASTType.h"
10
11#include "lldb/Symbol/Declaration.h"
12
13bool 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();
29          bool match = true;
30          bool done = false;
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
43                {
44                  match = false;
45                } else {
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)))
50                    match = false;
51                }
52              } break;
53
54              case DW_TAG_compile_unit:
55              case DW_TAG_partial_unit:
56                done = true;
57                break;
58              }
59            }
60            parent_arg_die = parent_arg_die.GetParent();
61            parent_pos_die = parent_pos_die.GetParent();
62          }
63
64          if (match) {
65            entry = udt;
66            return true;
67          }
68        }
69      }
70    }
71  }
72  return false;
73}
74