]> Git Repo - binutils.git/blob - gdb/dwarf2/cu.c
gdb: remove SYMBOL_CLASS macro, add getter
[binutils.git] / gdb / dwarf2 / cu.c
1 /* DWARF CU data structure
2
3    Copyright (C) 2021-2022 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
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),
30     m_mark (false),
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_gcc_11 (false),
36     producer_is_icc (false),
37     producer_is_icc_lt_14 (false),
38     producer_is_codewarrior (false),
39     processing_has_namespace_info (false),
40     load_all_dies (false)
41 {
42 }
43
44 /* See cu.h.  */
45
46 struct type *
47 dwarf2_cu::addr_sized_int_type (bool unsigned_p) const
48 {
49   int addr_size = this->per_cu->addr_size ();
50   return objfile_int_type (this->per_objfile->objfile, addr_size, unsigned_p);
51 }
52
53 /* Start a symtab for DWARF.  NAME, COMP_DIR, LOW_PC are passed to the
54    buildsym_compunit constructor.  */
55
56 struct compunit_symtab *
57 dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
58                          CORE_ADDR low_pc)
59 {
60   gdb_assert (m_builder == nullptr);
61
62   m_builder.reset (new struct buildsym_compunit
63                    (this->per_objfile->objfile,
64                     name, comp_dir, per_cu->lang, low_pc));
65
66   list_in_scope = get_builder ()->get_file_symbols ();
67
68   /* DWARF versions are restricted to [2, 5], thanks to the check in
69      read_comp_unit_head.  */
70   gdb_assert (this->header.version >= 2 && this->header.version <= 5);
71   static const char *debugformat_strings[] = {
72     "DWARF 2",
73     "DWARF 3",
74     "DWARF 4",
75     "DWARF 5",
76   };
77   const char *debugformat = debugformat_strings[this->header.version - 2];
78
79   get_builder ()->record_debugformat (debugformat);
80   get_builder ()->record_producer (producer);
81
82   processing_has_namespace_info = false;
83
84   return get_builder ()->get_compunit_symtab ();
85 }
86
87 /* See read.h.  */
88
89 struct type *
90 dwarf2_cu::addr_type () const
91 {
92   struct objfile *objfile = this->per_objfile->objfile;
93   struct type *void_type = objfile_type (objfile)->builtin_void;
94   struct type *addr_type = lookup_pointer_type (void_type);
95   int addr_size = this->per_cu->addr_size ();
96
97   if (TYPE_LENGTH (addr_type) == addr_size)
98     return addr_type;
99
100   addr_type = addr_sized_int_type (addr_type->is_unsigned ());
101   return addr_type;
102 }
103
104 /* A hashtab traversal function that marks the dependent CUs.  */
105
106 static int
107 dwarf2_mark_helper (void **slot, void *data)
108 {
109   dwarf2_per_cu_data *per_cu = (dwarf2_per_cu_data *) *slot;
110   dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) data;
111   dwarf2_cu *cu = per_objfile->get_cu (per_cu);
112
113   /* cu->m_dependencies references may not yet have been ever read if
114      QUIT aborts reading of the chain.  As such dependencies remain
115      valid it is not much useful to track and undo them during QUIT
116      cleanups.  */
117   if (cu != nullptr)
118     cu->mark ();
119   return 1;
120 }
121
122 /* See dwarf2/cu.h.  */
123
124 void
125 dwarf2_cu::mark ()
126 {
127   if (!m_mark)
128     {
129       m_mark = true;
130       if (m_dependencies != nullptr)
131         htab_traverse (m_dependencies, dwarf2_mark_helper, per_objfile);
132     }
133 }
134
135 /* See dwarf2/cu.h.  */
136
137 void
138 dwarf2_cu::add_dependence (struct dwarf2_per_cu_data *ref_per_cu)
139 {
140   void **slot;
141
142   if (m_dependencies == nullptr)
143     m_dependencies
144       = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
145                               NULL, &comp_unit_obstack,
146                               hashtab_obstack_allocate,
147                               dummy_obstack_deallocate);
148
149   slot = htab_find_slot (m_dependencies, ref_per_cu, INSERT);
150   if (*slot == nullptr)
151     *slot = ref_per_cu;
152 }
153
154 /* See dwarf2/cu.h.  */
155
156 buildsym_compunit *
157 dwarf2_cu::get_builder ()
158 {
159   /* If this CU has a builder associated with it, use that.  */
160   if (m_builder != nullptr)
161     return m_builder.get ();
162
163   if (per_objfile->sym_cu != nullptr)
164     return per_objfile->sym_cu->m_builder.get ();
165
166   gdb_assert_not_reached ("");
167 }
This page took 0.035329 seconds and 4 git commands to generate.