Rename "sun" variable to avoid conflicts on Solaris
[deliverable/binutils-gdb.git] / gdb / buildsym.h
CommitLineData
c906108c 1/* Build symbol tables in GDB's internal format.
42a4f53d 2 Copyright (C) 1986-2019 Free Software Foundation, Inc.
c906108c 3
c5aa993b
JM
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b
JM
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
18
19#if !defined (BUILDSYM_H)
20#define BUILDSYM_H 1
21
0d12e84c
TT
22#include "gdb_obstack.h"
23
da3331ec
AC
24struct objfile;
25struct symbol;
801e3a5b 26struct addrmap;
43f3e411 27struct compunit_symtab;
5ffa0793 28enum language;
da3331ec 29
c906108c
SS
30/* This module provides definitions used for creating and adding to
31 the symbol table. These routines are called from various symbol-
32 file-reading routines.
33
34 They originated in dbxread.c of gdb-4.2, and were split out to
b80a981d 35 make xcoffread.c more maintainable by sharing code. */
c906108c 36
fe898f56 37struct block;
93eed41f 38struct pending_block;
fe898f56 39
63e43d3a
PMR
40struct dynamic_prop;
41
c906108c
SS
42/* The list of sub-source-files within the current individual
43 compilation. Each file gets its own symtab with its own linetable
44 and associated info, but they all share one blockvector. */
45
46struct subfile
43f3e411
DE
47{
48 struct subfile *next;
49 /* Space for this is malloc'd. */
50 char *name;
51 /* Space for this is malloc'd. */
52 struct linetable *line_vector;
53 int line_vector_length;
54 /* The "containing" compunit. */
55 struct buildsym_compunit *buildsym_compunit;
56 enum language language;
57 struct symtab *symtab;
58};
c906108c 59
c906108c
SS
60/* Record the symbols defined for each context in a list. We don't
61 create a struct block for the context until we know how long to
62 make it. */
63
64#define PENDINGSIZE 100
65
66struct pending
67 {
68 struct pending *next;
69 int nsyms;
70 struct symbol *symbol[PENDINGSIZE];
71 };
72
c906108c
SS
73/* Stack representing unclosed lexical contexts (that will become
74 blocks, eventually). */
75
76struct context_stack
77 {
78 /* Outer locals at the time we entered */
79
80 struct pending *locals;
81
27aa8d6a
SW
82 /* Pending using directives at the time we entered. */
83
22cee43f 84 struct using_direct *local_using_directives;
27aa8d6a 85
c906108c
SS
86 /* Pointer into blocklist as of entry */
87
88 struct pending_block *old_blocks;
89
90 /* Name of function, if any, defining context */
91
92 struct symbol *name;
93
63e43d3a
PMR
94 /* Expression that computes the frame base of the lexically enclosing
95 function, if any. NULL otherwise. */
96
97 struct dynamic_prop *static_link;
98
c906108c
SS
99 /* PC where this context starts */
100
101 CORE_ADDR start_addr;
102
0e2de366 103 /* Temp slot for exception handling. */
c906108c
SS
104
105 CORE_ADDR end_addr;
106
107 /* For error-checking matching push/pop */
108
109 int depth;
110
111 };
112
ab209f6f
TT
113/* Buildsym's counterpart to struct compunit_symtab. */
114
115struct buildsym_compunit
116{
117 /* Start recording information about a primary source file (IOW, not an
118 included source file).
119 COMP_DIR is the directory in which the compilation unit was compiled
120 (or NULL if not known). */
121
122 buildsym_compunit (struct objfile *objfile_, const char *name,
123 const char *comp_dir_, enum language language_,
124 CORE_ADDR last_addr);
125
126 /* Reopen an existing compunit_symtab so that additional symbols can
127 be added to it. Arguments are as for the main constructor. CUST
128 is the expandable compunit_symtab to be reopened. */
129
130 buildsym_compunit (struct objfile *objfile_, const char *name,
131 const char *comp_dir_, enum language language_,
132 CORE_ADDR last_addr, struct compunit_symtab *cust)
cbb09508 133 : m_objfile (objfile_),
ab209f6f 134 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
cbb09508
KS
135 m_comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
136 m_compunit_symtab (cust),
137 m_language (language_),
ab209f6f
TT
138 m_last_source_start_addr (last_addr)
139 {
140 }
141
142 ~buildsym_compunit ();
143
144 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
145
146 void set_last_source_file (const char *name)
147 {
148 char *new_name = name == NULL ? NULL : xstrdup (name);
149 m_last_source_file.reset (new_name);
150 }
151
152 const char *get_last_source_file ()
153 {
154 return m_last_source_file.get ();
155 }
156
157 struct macro_table *get_macro_table ();
158
159 struct macro_table *release_macros ()
160 {
161 struct macro_table *result = m_pending_macros;
162 m_pending_macros = nullptr;
163 return result;
164 }
165
166 /* This function is called to discard any pending blocks. */
167
168 void free_pending_blocks ()
169 {
170 m_pending_block_obstack.clear ();
171 m_pending_blocks = nullptr;
172 }
173
174 struct block *finish_block (struct symbol *symbol,
175 struct pending_block *old_blocks,
176 const struct dynamic_prop *static_link,
177 CORE_ADDR start, CORE_ADDR end);
178
179 void record_block_range (struct block *block,
180 CORE_ADDR start, CORE_ADDR end_inclusive);
181
182 void start_subfile (const char *name);
183
184 void patch_subfile_names (struct subfile *subfile, const char *name);
185
186 void push_subfile ();
187
188 const char *pop_subfile ();
189
190 void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
191
192 struct compunit_symtab *get_compunit_symtab ()
193 {
cbb09508 194 return m_compunit_symtab;
ab209f6f
TT
195 }
196
197 void set_last_source_start_addr (CORE_ADDR addr)
198 {
199 m_last_source_start_addr = addr;
200 }
201
202 CORE_ADDR get_last_source_start_addr ()
203 {
204 return m_last_source_start_addr;
205 }
206
207 struct using_direct **get_local_using_directives ()
208 {
209 return &m_local_using_directives;
210 }
211
212 void set_local_using_directives (struct using_direct *new_local)
213 {
214 m_local_using_directives = new_local;
215 }
216
217 struct using_direct **get_global_using_directives ()
218 {
219 return &m_global_using_directives;
220 }
221
222 bool outermost_context_p () const
223 {
224 return m_context_stack.empty ();
225 }
226
227 struct context_stack *get_current_context_stack ()
228 {
229 if (m_context_stack.empty ())
230 return nullptr;
231 return &m_context_stack.back ();
232 }
233
234 int get_context_stack_depth () const
235 {
236 return m_context_stack.size ();
237 }
238
239 struct subfile *get_current_subfile ()
240 {
241 return m_current_subfile;
242 }
243
244 struct pending **get_local_symbols ()
245 {
246 return &m_local_symbols;
247 }
248
249 struct pending **get_file_symbols ()
250 {
251 return &m_file_symbols;
252 }
253
254 struct pending **get_global_symbols ()
255 {
256 return &m_global_symbols;
257 }
258
259 void record_debugformat (const char *format)
260 {
cbb09508 261 m_debugformat = format;
ab209f6f
TT
262 }
263
264 void record_producer (const char *producer)
265 {
cbb09508 266 m_producer = producer;
ab209f6f
TT
267 }
268
269 struct context_stack *push_context (int desc, CORE_ADDR valu);
270
271 struct context_stack pop_context ();
272
273 struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
274 int expandable, int required);
275
276 struct compunit_symtab *end_symtab_from_static_block
277 (struct block *static_block, int section, int expandable);
278
279 struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
280
281 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
282 int section);
283
284 void augment_type_symtab ();
285
286private:
287
288 void record_pending_block (struct block *block, struct pending_block *opblock);
289
290 struct block *finish_block_internal (struct symbol *symbol,
291 struct pending **listhead,
292 struct pending_block *old_blocks,
293 const struct dynamic_prop *static_link,
294 CORE_ADDR start, CORE_ADDR end,
295 int is_global, int expandable);
296
297 struct blockvector *make_blockvector ();
298
299 void watch_main_source_file_lossage ();
300
301 struct compunit_symtab *end_symtab_with_blockvector
302 (struct block *static_block, int section, int expandable);
303
304 /* The objfile we're reading debug info from. */
cbb09508 305 struct objfile *m_objfile;
ab209f6f
TT
306
307 /* List of subfiles (source files).
308 Files are added to the front of the list.
309 This is important mostly for the language determination hacks we use,
310 which iterate over previously added files. */
cbb09508 311 struct subfile *m_subfiles = nullptr;
ab209f6f
TT
312
313 /* The subfile of the main source file. */
cbb09508 314 struct subfile *m_main_subfile = nullptr;
ab209f6f
TT
315
316 /* Name of source file whose symbol data we are now processing. This
317 comes from a symbol of type N_SO for stabs. For DWARF it comes
318 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
319 gdb::unique_xmalloc_ptr<char> m_last_source_file;
320
321 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
cbb09508 322 gdb::unique_xmalloc_ptr<char> m_comp_dir;
ab209f6f
TT
323
324 /* Space for this is not malloc'd, and is assumed to have at least
325 the same lifetime as objfile. */
cbb09508 326 const char *m_producer = nullptr;
ab209f6f
TT
327
328 /* Space for this is not malloc'd, and is assumed to have at least
329 the same lifetime as objfile. */
cbb09508 330 const char *m_debugformat = nullptr;
ab209f6f
TT
331
332 /* The compunit we are building. */
cbb09508 333 struct compunit_symtab *m_compunit_symtab = nullptr;
ab209f6f
TT
334
335 /* Language of this compunit_symtab. */
cbb09508 336 enum language m_language;
ab209f6f
TT
337
338 /* The macro table for the compilation unit whose symbols we're
339 currently reading. */
340 struct macro_table *m_pending_macros = nullptr;
341
342 /* True if symtab has line number info. This prevents an otherwise
343 empty symtab from being tossed. */
344 bool m_have_line_numbers = false;
345
346 /* Core address of start of text of current source file. This too
347 comes from the N_SO symbol. For Dwarf it typically comes from the
348 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
349 CORE_ADDR m_last_source_start_addr;
350
351 /* Stack of subfile names. */
352 std::vector<const char *> m_subfile_stack;
353
354 /* The "using" directives local to lexical context. */
355 struct using_direct *m_local_using_directives = nullptr;
356
357 /* Global "using" directives. */
358 struct using_direct *m_global_using_directives = nullptr;
359
360 /* The stack of contexts that are pushed by push_context and popped
361 by pop_context. */
362 std::vector<struct context_stack> m_context_stack;
363
364 struct subfile *m_current_subfile = nullptr;
365
366 /* The mutable address map for the compilation unit whose symbols
367 we're currently reading. The symtabs' shared blockvector will
368 point to a fixed copy of this. */
369 struct addrmap *m_pending_addrmap = nullptr;
370
371 /* The obstack on which we allocate pending_addrmap.
372 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
373 initialized (and holds pending_addrmap). */
374 auto_obstack m_pending_addrmap_obstack;
375
376 /* True if we recorded any ranges in the addrmap that are different
377 from those in the blockvector already. We set this to false when
378 we start processing a symfile, and if it's still false at the
379 end, then we just toss the addrmap. */
380 bool m_pending_addrmap_interesting = false;
381
382 /* An obstack used for allocating pending blocks. */
383 auto_obstack m_pending_block_obstack;
384
385 /* Pointer to the head of a linked list of symbol blocks which have
386 already been finalized (lexical contexts already closed) and which
387 are just waiting to be built into a blockvector when finalizing the
388 associated symtab. */
389 struct pending_block *m_pending_blocks = nullptr;
390
391 /* Pending static symbols and types at the top level. */
392 struct pending *m_file_symbols = nullptr;
393
394 /* Pending global functions and variables. */
395 struct pending *m_global_symbols = nullptr;
396
397 /* Pending symbols that are local to the lexical context. */
398 struct pending *m_local_symbols = nullptr;
399};
400
c906108c
SS
401\f
402
c906108c
SS
403extern void add_symbol_to_list (struct symbol *symbol,
404 struct pending **listhead);
405
406extern struct symbol *find_symbol_in_list (struct pending *list,
407 char *name, int length);
408
c906108c 409#endif /* defined (BUILDSYM_H) */
This page took 1.238302 seconds and 4 git commands to generate.