1 /* DWARF CU data structure
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "dwarf2/cu.h"
22 #include "dwarf2/read.h"
24 #include "filenames.h"
25 #include "gdbsupport/pathstuff.h"
27 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
29 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
30 dwarf2_per_objfile
*per_objfile
)
32 per_objfile (per_objfile
),
35 checked_producer (false),
36 producer_is_gxx_lt_4_6 (false),
37 producer_is_gcc_lt_4_3 (false),
38 producer_is_gcc_11 (false),
39 producer_is_icc (false),
40 producer_is_icc_lt_14 (false),
41 producer_is_codewarrior (false),
42 processing_has_namespace_info (false),
50 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
52 int addr_size
= this->per_cu
->addr_size ();
53 return objfile_int_type (this->per_objfile
->objfile
, addr_size
, unsigned_p
);
56 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
57 buildsym_compunit constructor. */
59 struct compunit_symtab
*
60 dwarf2_cu::start_compunit_symtab (const char *name
, const char *comp_dir
,
63 gdb_assert (m_builder
== nullptr);
65 std::string name_for_id_holder
;
66 const char *name_for_id
= name
;
68 /* Prepend the compilation directory to the filename if needed (if not
69 absolute already) to get the "name for id" for our main symtab. The name
70 for the main file coming from the line table header will be generated using
71 the same logic, so will hopefully match what we pass here. */
72 if (!IS_ABSOLUTE_PATH (name
) && comp_dir
!= nullptr)
74 name_for_id_holder
= path_join (comp_dir
, name
);
75 name_for_id
= name_for_id_holder
.c_str ();
78 m_builder
.reset (new struct buildsym_compunit
79 (this->per_objfile
->objfile
,
80 name
, comp_dir
, name_for_id
, lang (), low_pc
));
82 list_in_scope
= get_builder ()->get_file_symbols ();
84 /* DWARF versions are restricted to [2, 5], thanks to the check in
85 read_comp_unit_head. */
86 gdb_assert (this->header
.version
>= 2 && this->header
.version
<= 5);
87 static const char *debugformat_strings
[] = {
93 const char *debugformat
= debugformat_strings
[this->header
.version
- 2];
95 get_builder ()->record_debugformat (debugformat
);
96 get_builder ()->record_producer (producer
);
98 processing_has_namespace_info
= false;
100 return get_builder ()->get_compunit_symtab ();
106 dwarf2_cu::addr_type () const
108 struct objfile
*objfile
= this->per_objfile
->objfile
;
109 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
110 struct type
*addr_type
= lookup_pointer_type (void_type
);
111 int addr_size
= this->per_cu
->addr_size ();
113 if (TYPE_LENGTH (addr_type
) == addr_size
)
116 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
120 /* A hashtab traversal function that marks the dependent CUs. */
123 dwarf2_mark_helper (void **slot
, void *data
)
125 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
126 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
127 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
129 /* cu->m_dependencies references may not yet have been ever read if
130 QUIT aborts reading of the chain. As such dependencies remain
131 valid it is not much useful to track and undo them during QUIT
138 /* See dwarf2/cu.h. */
146 if (m_dependencies
!= nullptr)
147 htab_traverse (m_dependencies
, dwarf2_mark_helper
, per_objfile
);
151 /* See dwarf2/cu.h. */
154 dwarf2_cu::add_dependence (struct dwarf2_per_cu_data
*ref_per_cu
)
158 if (m_dependencies
== nullptr)
160 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
161 NULL
, &comp_unit_obstack
,
162 hashtab_obstack_allocate
,
163 dummy_obstack_deallocate
);
165 slot
= htab_find_slot (m_dependencies
, ref_per_cu
, INSERT
);
166 if (*slot
== nullptr)
170 /* See dwarf2/cu.h. */
173 dwarf2_cu::get_builder ()
175 /* If this CU has a builder associated with it, use that. */
176 if (m_builder
!= nullptr)
177 return m_builder
.get ();
179 if (per_objfile
->sym_cu
!= nullptr)
180 return per_objfile
->sym_cu
->m_builder
.get ();
182 gdb_assert_not_reached ("");