Commit | Line | Data |
---|---|---|
839118f9 TT |
1 | /* DWARF CU data structure |
2 | ||
88b9d363 | 3 | Copyright (C) 2021-2022 Free Software Foundation, Inc. |
839118f9 TT |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "dwarf2/cu.h" | |
22 | #include "dwarf2/read.h" | |
23 | ||
24 | /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */ | |
25 | ||
26 | dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu, | |
27 | dwarf2_per_objfile *per_objfile) | |
28 | : per_cu (per_cu), | |
29 | per_objfile (per_objfile), | |
347212b8 | 30 | m_mark (false), |
839118f9 TT |
31 | has_loclist (false), |
32 | checked_producer (false), | |
33 | producer_is_gxx_lt_4_6 (false), | |
34 | producer_is_gcc_lt_4_3 (false), | |
35 | producer_is_icc (false), | |
36 | producer_is_icc_lt_14 (false), | |
37 | producer_is_codewarrior (false), | |
6dcd1193 TV |
38 | processing_has_namespace_info (false), |
39 | load_all_dies (false) | |
839118f9 TT |
40 | { |
41 | } | |
42 | ||
43 | /* See cu.h. */ | |
44 | ||
45 | struct type * | |
46 | dwarf2_cu::addr_sized_int_type (bool unsigned_p) const | |
47 | { | |
48 | int addr_size = this->per_cu->addr_size (); | |
49 | return this->per_objfile->int_type (addr_size, unsigned_p); | |
50 | } | |
51 | ||
52 | /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the | |
53 | buildsym_compunit constructor. */ | |
54 | ||
55 | struct compunit_symtab * | |
56 | dwarf2_cu::start_symtab (const char *name, const char *comp_dir, | |
57 | CORE_ADDR low_pc) | |
58 | { | |
59 | gdb_assert (m_builder == nullptr); | |
60 | ||
61 | m_builder.reset (new struct buildsym_compunit | |
62 | (this->per_objfile->objfile, | |
3e9f1ca1 | 63 | name, comp_dir, per_cu->lang, low_pc)); |
839118f9 TT |
64 | |
65 | list_in_scope = get_builder ()->get_file_symbols (); | |
66 | ||
67 | get_builder ()->record_debugformat ("DWARF 2"); | |
68 | get_builder ()->record_producer (producer); | |
69 | ||
70 | processing_has_namespace_info = false; | |
71 | ||
72 | return get_builder ()->get_compunit_symtab (); | |
73 | } | |
74 | ||
75 | /* See read.h. */ | |
76 | ||
77 | struct type * | |
78 | dwarf2_cu::addr_type () const | |
79 | { | |
80 | struct objfile *objfile = this->per_objfile->objfile; | |
81 | struct type *void_type = objfile_type (objfile)->builtin_void; | |
82 | struct type *addr_type = lookup_pointer_type (void_type); | |
83 | int addr_size = this->per_cu->addr_size (); | |
84 | ||
85 | if (TYPE_LENGTH (addr_type) == addr_size) | |
86 | return addr_type; | |
87 | ||
88 | addr_type = addr_sized_int_type (addr_type->is_unsigned ()); | |
89 | return addr_type; | |
90 | } | |
347212b8 TT |
91 | |
92 | /* A hashtab traversal function that marks the dependent CUs. */ | |
93 | ||
94 | static int | |
95 | dwarf2_mark_helper (void **slot, void *data) | |
96 | { | |
97 | dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot; | |
98 | dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data; | |
99 | dwarf2_cu *cu = per_objfile->get_cu (per_cu); | |
100 | ||
101 | /* cu->m_dependencies references may not yet have been ever read if | |
102 | QUIT aborts reading of the chain. As such dependencies remain | |
103 | valid it is not much useful to track and undo them during QUIT | |
104 | cleanups. */ | |
105 | if (cu != nullptr) | |
106 | cu->mark (); | |
107 | return 1; | |
108 | } | |
109 | ||
110 | /* See dwarf2/cu.h. */ | |
111 | ||
112 | void | |
113 | dwarf2_cu::mark () | |
114 | { | |
115 | if (!m_mark) | |
116 | { | |
117 | m_mark = true; | |
118 | if (m_dependencies != nullptr) | |
119 | htab_traverse (m_dependencies, dwarf2_mark_helper, per_objfile); | |
120 | } | |
121 | } | |
122 | ||
123 | /* See dwarf2/cu.h. */ | |
124 | ||
125 | void | |
126 | dwarf2_cu::add_dependence (struct dwarf2_per_cu_data *ref_per_cu) | |
127 | { | |
128 | void **slot; | |
129 | ||
130 | if (m_dependencies == nullptr) | |
131 | m_dependencies | |
132 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
133 | NULL, &comp_unit_obstack, | |
134 | hashtab_obstack_allocate, | |
135 | dummy_obstack_deallocate); | |
136 | ||
137 | slot = htab_find_slot (m_dependencies, ref_per_cu, INSERT); | |
138 | if (*slot == nullptr) | |
139 | *slot = ref_per_cu; | |
140 | } | |
8457e5ec TV |
141 | |
142 | /* See dwarf2/cu.h. */ | |
143 | ||
144 | buildsym_compunit * | |
145 | dwarf2_cu::get_builder () | |
146 | { | |
147 | /* If this CU has a builder associated with it, use that. */ | |
148 | if (m_builder != nullptr) | |
149 | return m_builder.get (); | |
150 | ||
151 | if (per_objfile->sym_cu != nullptr) | |
152 | return per_objfile->sym_cu->m_builder.get (); | |
153 | ||
154 | gdb_assert_not_reached (""); | |
155 | } |