GDB (xrefs)
Loading...
Searching...
No Matches
cu.c
Go to the documentation of this file.
1/* DWARF CU data structure
2
3 Copyright (C) 2021-2023 Free Software Foundation, Inc.
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#include "objfiles.h"
24#include "filenames.h"
25#include "gdbsupport/pathstuff.h"
26
27/* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
28
30 dwarf2_per_objfile *per_objfile)
31 : per_cu (per_cu),
32 per_objfile (per_objfile),
33 m_mark (false),
34 has_loclist (false),
35 checked_producer (false),
38 producer_is_gcc_11 (false),
39 producer_is_icc (false),
42 producer_is_clang (false),
43 processing_has_namespace_info (false),
44 load_all_dies (false)
45{
46}
47
48/* See cu.h. */
49
50struct type *
51dwarf2_cu::addr_sized_int_type (bool unsigned_p) const
52{
53 int addr_size = this->per_cu->addr_size ();
54 return objfile_int_type (this->per_objfile->objfile, addr_size, unsigned_p);
55}
56
57/* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
58 buildsym_compunit constructor. */
59
60struct compunit_symtab *
61dwarf2_cu::start_compunit_symtab (const char *name, const char *comp_dir,
62 CORE_ADDR low_pc)
63{
64 gdb_assert (m_builder == nullptr);
65
66 std::string name_for_id_holder;
67 const char *name_for_id = name;
68
69 /* Prepend the compilation directory to the filename if needed (if not
70 absolute already) to get the "name for id" for our main symtab. The name
71 for the main file coming from the line table header will be generated using
72 the same logic, so will hopefully match what we pass here. */
73 if (!IS_ABSOLUTE_PATH (name) && comp_dir != nullptr)
74 {
75 name_for_id_holder = path_join (comp_dir, name);
76 name_for_id = name_for_id_holder.c_str ();
77 }
78
79 m_builder.reset (new struct buildsym_compunit
80 (this->per_objfile->objfile,
81 name, comp_dir, name_for_id, lang (), low_pc));
82
84
85 /* DWARF versions are restricted to [2, 5], thanks to the check in
86 read_comp_unit_head. */
87 gdb_assert (this->header.version >= 2 && this->header.version <= 5);
88 static const char *debugformat_strings[] = {
89 "DWARF 2",
90 "DWARF 3",
91 "DWARF 4",
92 "DWARF 5",
93 };
94 const char *debugformat = debugformat_strings[this->header.version - 2];
95
96 get_builder ()->record_debugformat (debugformat);
98
100
101 return get_builder ()->get_compunit_symtab ();
102}
103
104/* See read.h. */
105
106struct type *
108{
109 struct objfile *objfile = this->per_objfile->objfile;
110 struct type *void_type = builtin_type (objfile)->builtin_void;
111 struct type *addr_type = lookup_pointer_type (void_type);
112 int addr_size = this->per_cu->addr_size ();
113
114 if (addr_type->length () == addr_size)
115 return addr_type;
116
118 return addr_type;
119}
120
121/* A hashtab traversal function that marks the dependent CUs. */
122
123static int
124dwarf2_mark_helper (void **slot, void *data)
125{
126 dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot;
127 dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data;
128 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
129
130 /* cu->m_dependencies references may not yet have been ever read if
131 QUIT aborts reading of the chain. As such dependencies remain
132 valid it is not much useful to track and undo them during QUIT
133 cleanups. */
134 if (cu != nullptr)
135 cu->mark ();
136 return 1;
137}
138
139/* See dwarf2/cu.h. */
140
141void
143{
144 if (!m_mark)
145 {
146 m_mark = true;
147 if (m_dependencies != nullptr)
149 }
150}
151
152/* See dwarf2/cu.h. */
153
154void
156{
157 void **slot;
158
159 if (m_dependencies == nullptr)
161 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
162 NULL, &comp_unit_obstack,
163 hashtab_obstack_allocate,
164 dummy_obstack_deallocate);
165
166 slot = htab_find_slot (m_dependencies, ref_per_cu, INSERT);
167 if (*slot == nullptr)
168 *slot = ref_per_cu;
169}
170
171/* See dwarf2/cu.h. */
172
175{
176 /* If this CU has a builder associated with it, use that. */
177 if (m_builder != nullptr)
178 return m_builder.get ();
179
180 if (per_objfile->sym_cu != nullptr)
181 return per_objfile->sym_cu->m_builder.get ();
182
183 gdb_assert_not_reached ("");
184}
const char *const name
static int dwarf2_mark_helper(void **slot, void *data)
Definition cu.c:124
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
struct type * objfile_int_type(struct objfile *of, int size_in_bytes, bool unsigned_p)
Definition objfiles.c:1299
static bool producer_is_gcc_lt_4_3(struct dwarf2_cu *cu)
Definition read.c:7500
static bool producer_is_icc(struct dwarf2_cu *cu)
Definition read.c:7487
static bool producer_is_codewarrior(struct dwarf2_cu *cu)
Definition read.c:11456
bool producer_is_clang(struct dwarf2_cu *cu)
Definition read.c:7510
static bool producer_is_gxx_lt_4_6(struct dwarf2_cu *cu)
Definition read.c:11443
static bool producer_is_icc_lt_14(struct dwarf2_cu *cu)
Definition read.c:7474
struct compunit_symtab * get_compunit_symtab()
Definition buildsym.h:245
void record_producer(const char *producer)
Definition buildsym.h:317
struct pending ** get_file_symbols()
Definition buildsym.h:302
void record_debugformat(const char *format)
Definition buildsym.h:312
struct type * builtin_void
Definition gdbtypes.h:2077
unsigned char version
Definition cu.h:50
bool processing_has_namespace_info
Definition cu.h:273
struct type * addr_type() const
Definition cu.c:107
dwarf2_per_objfile * per_objfile
Definition cu.h:151
htab_t m_dependencies
Definition cu.h:125
bool m_mark
Definition cu.h:248
dwarf2_cu(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition cu.c:29
enum language lang() const
Definition cu.h:109
struct compunit_symtab * start_compunit_symtab(const char *name, const char *comp_dir, CORE_ADDR low_pc)
Definition cu.c:61
buildsym_compunit * get_builder()
Definition cu.c:174
struct pending ** list_in_scope
Definition cu.h:137
void mark()
Definition cu.c:142
struct dwarf2_per_cu_data * per_cu
Definition cu.h:148
std::unique_ptr< buildsym_compunit > m_builder
Definition cu.h:120
const char * producer
Definition cu.h:115
auto_obstack comp_unit_obstack
Definition cu.h:145
struct comp_unit_head header
Definition cu.h:101
struct type * addr_sized_int_type(bool unsigned_p) const
Definition cu.c:51
void add_dependence(struct dwarf2_per_cu_data *ref_per_cu)
Definition cu.c:155
int addr_size() const
Definition read.c:21567
struct objfile * objfile
Definition read.h:724
dwarf2_cu * sym_cu
Definition read.h:739
dwarf2_cu * get_cu(dwarf2_per_cu_data *per_cu)
Definition read.c:21773
ULONGEST length() const
Definition gdbtypes.h:983
bool is_unsigned() const
Definition gdbtypes.h:1100