|
13 | 13 | using namespace lldb_private::dwarf;
|
14 | 14 | using namespace lldb_private::plugin::dwarf;
|
15 | 15 |
|
16 |
| -bool UniqueDWARFASTTypeList::Find(const DWARFDIE &die, |
17 |
| - const lldb_private::Declaration &decl, |
18 |
| - const int32_t byte_size, |
19 |
| - UniqueDWARFASTType &entry) const { |
20 |
| - for (const UniqueDWARFASTType &udt : m_collection) { |
| 16 | +UniqueDWARFASTType *UniqueDWARFASTTypeList::Find( |
| 17 | + const DWARFDIE &die, const lldb_private::Declaration &decl, |
| 18 | + const int32_t byte_size, bool is_forward_declaration) { |
| 19 | + for (UniqueDWARFASTType &udt : m_collection) { |
21 | 20 | // Make sure the tags match
|
22 | 21 | if (udt.m_die.Tag() == die.Tag()) {
|
23 |
| - // Validate byte sizes of both types only if both are valid. |
24 |
| - if (udt.m_byte_size < 0 || byte_size < 0 || |
25 |
| - udt.m_byte_size == byte_size) { |
26 |
| - // Make sure the file and line match |
27 |
| - if (udt.m_declaration == decl) { |
28 |
| - // The type has the same name, and was defined on the same file and |
29 |
| - // line. Now verify all of the parent DIEs match. |
30 |
| - DWARFDIE parent_arg_die = die.GetParent(); |
31 |
| - DWARFDIE parent_pos_die = udt.m_die.GetParent(); |
32 |
| - bool match = true; |
33 |
| - bool done = false; |
34 |
| - while (!done && match && parent_arg_die && parent_pos_die) { |
35 |
| - const dw_tag_t parent_arg_tag = parent_arg_die.Tag(); |
36 |
| - const dw_tag_t parent_pos_tag = parent_pos_die.Tag(); |
37 |
| - if (parent_arg_tag == parent_pos_tag) { |
38 |
| - switch (parent_arg_tag) { |
39 |
| - case DW_TAG_class_type: |
40 |
| - case DW_TAG_structure_type: |
41 |
| - case DW_TAG_union_type: |
42 |
| - case DW_TAG_namespace: { |
43 |
| - const char *parent_arg_die_name = parent_arg_die.GetName(); |
44 |
| - if (parent_arg_die_name == |
45 |
| - nullptr) // Anonymous (i.e. no-name) struct |
46 |
| - { |
47 |
| - match = false; |
48 |
| - } else { |
49 |
| - const char *parent_pos_die_name = parent_pos_die.GetName(); |
50 |
| - if (parent_pos_die_name == nullptr || |
51 |
| - ((parent_arg_die_name != parent_pos_die_name) && |
52 |
| - strcmp(parent_arg_die_name, parent_pos_die_name))) |
53 |
| - match = false; |
54 |
| - } |
55 |
| - } break; |
56 |
| - |
57 |
| - case DW_TAG_compile_unit: |
58 |
| - case DW_TAG_partial_unit: |
59 |
| - done = true; |
60 |
| - break; |
61 |
| - default: |
62 |
| - break; |
63 |
| - } |
| 22 | + // If they are not both definition DIEs or both declaration DIEs, then |
| 23 | + // don't check for byte size and declaration location, because declaration |
| 24 | + // DIEs usually don't have those info. |
| 25 | + bool matching_size_declaration = |
| 26 | + udt.m_is_forward_declaration != is_forward_declaration |
| 27 | + ? true |
| 28 | + : (udt.m_byte_size < 0 || byte_size < 0 || |
| 29 | + udt.m_byte_size == byte_size) && |
| 30 | + udt.m_declaration == decl; |
| 31 | + if (!matching_size_declaration) |
| 32 | + continue; |
| 33 | + // The type has the same name, and was defined on the same file and |
| 34 | + // line. Now verify all of the parent DIEs match. |
| 35 | + DWARFDIE parent_arg_die = die.GetParent(); |
| 36 | + DWARFDIE parent_pos_die = udt.m_die.GetParent(); |
| 37 | + bool match = true; |
| 38 | + bool done = false; |
| 39 | + while (!done && match && parent_arg_die && parent_pos_die) { |
| 40 | + const dw_tag_t parent_arg_tag = parent_arg_die.Tag(); |
| 41 | + const dw_tag_t parent_pos_tag = parent_pos_die.Tag(); |
| 42 | + if (parent_arg_tag == parent_pos_tag) { |
| 43 | + switch (parent_arg_tag) { |
| 44 | + case DW_TAG_class_type: |
| 45 | + case DW_TAG_structure_type: |
| 46 | + case DW_TAG_union_type: |
| 47 | + case DW_TAG_namespace: { |
| 48 | + const char *parent_arg_die_name = parent_arg_die.GetName(); |
| 49 | + if (parent_arg_die_name == nullptr) { |
| 50 | + // Anonymous (i.e. no-name) struct |
| 51 | + match = false; |
| 52 | + } else { |
| 53 | + const char *parent_pos_die_name = parent_pos_die.GetName(); |
| 54 | + if (parent_pos_die_name == nullptr || |
| 55 | + ((parent_arg_die_name != parent_pos_die_name) && |
| 56 | + strcmp(parent_arg_die_name, parent_pos_die_name))) |
| 57 | + match = false; |
64 | 58 | }
|
65 |
| - parent_arg_die = parent_arg_die.GetParent(); |
66 |
| - parent_pos_die = parent_pos_die.GetParent(); |
67 |
| - } |
| 59 | + } break; |
68 | 60 |
|
69 |
| - if (match) { |
70 |
| - entry = udt; |
71 |
| - return true; |
| 61 | + case DW_TAG_compile_unit: |
| 62 | + case DW_TAG_partial_unit: |
| 63 | + done = true; |
| 64 | + break; |
| 65 | + default: |
| 66 | + break; |
72 | 67 | }
|
73 | 68 | }
|
| 69 | + parent_arg_die = parent_arg_die.GetParent(); |
| 70 | + parent_pos_die = parent_pos_die.GetParent(); |
| 71 | + } |
| 72 | + |
| 73 | + if (match) { |
| 74 | + return &udt; |
74 | 75 | }
|
75 | 76 | }
|
76 | 77 | }
|
77 |
| - return false; |
| 78 | + return nullptr; |
78 | 79 | }
|
0 commit comments