Remove reset_symtab_globals
[deliverable/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
c906108c 1/* Support routines for building symbol tables in GDB's internal format.
e2882c85 2 Copyright (C) 1986-2018 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b 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/* This module provides subroutines used for creating and adding to
20 the symbol table. These routines are called from various symbol-
21 file-reading routines.
22
23 Routines to support specific debugging information formats (stabs,
0ab9ce85
DE
24 DWARF, etc) belong somewhere else.
25
26 The basic way this module is used is as follows:
27
33c7c59d 28 scoped_free_pendings free_pending;
0ab9ce85
DE
29 cust = start_symtab (...);
30 ... read debug info ...
31 cust = end_symtab (...);
0ab9ce85
DE
32
33 The compunit symtab pointer ("cust") is returned from both start_symtab
34 and end_symtab to simplify the debug info readers.
35
36 There are minor variations on this, e.g., dwarf2read.c splits end_symtab
37 into two calls: end_symtab_get_static_block, end_symtab_from_static_block,
38 but all debug info readers follow this basic flow.
39
40 Reading DWARF Type Units is another variation:
41
33c7c59d 42 scoped_free_pendings free_pending;
0ab9ce85
DE
43 cust = start_symtab (...);
44 ... read debug info ...
45 cust = end_expandable_symtab (...);
0ab9ce85
DE
46
47 And then reading subsequent Type Units within the containing "Comp Unit"
48 will use a second flow:
49
33c7c59d 50 scoped_free_pendings free_pending;
0ab9ce85
DE
51 cust = restart_symtab (...);
52 ... read debug info ...
53 cust = augment_type_symtab (...);
0ab9ce85
DE
54
55 dbxread.c and xcoffread.c use another variation:
56
33c7c59d 57 scoped_free_pendings free_pending;
0ab9ce85
DE
58 cust = start_symtab (...);
59 ... read debug info ...
60 cust = end_symtab (...);
61 ... start_symtab + read + end_symtab repeated ...
0ab9ce85 62*/
c906108c
SS
63
64#include "defs.h"
b80a981d 65#include "buildsym.h"
c906108c 66#include "bfd.h"
04ea0df1 67#include "gdb_obstack.h"
c906108c 68#include "symtab.h"
72367fb4 69#include "symfile.h"
c906108c
SS
70#include "objfiles.h"
71#include "gdbtypes.h"
72#include "complaints.h"
4a64f543 73#include "expression.h" /* For "enum exp_opcode" used by... */
4a64f543 74#include "filenames.h" /* For DOSish file names. */
99d9066e 75#include "macrotab.h"
261397f8 76#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
fe898f56 77#include "block.h"
9219021c 78#include "cp-support.h"
de4f826b 79#include "dictionary.h"
801e3a5b 80#include "addrmap.h"
b05628f0 81#include <algorithm>
9219021c 82
0a0edcd5 83/* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
c906108c
SS
84 questionable--see comment where we call them). */
85
86#include "stabsread.h"
87
ddb70602 88/* Buildsym's counterpart to struct compunit_symtab. */
4d663531 89
43f3e411
DE
90struct buildsym_compunit
91{
b248663f
TT
92 /* Start recording information about a primary source file (IOW, not an
93 included source file).
94 COMP_DIR is the directory in which the compilation unit was compiled
95 (or NULL if not known). */
96
c0015d44 97 buildsym_compunit (struct objfile *objfile_, const char *name,
2c99ee5c
TT
98 const char *comp_dir_, enum language language_,
99 CORE_ADDR last_addr)
b248663f 100 : objfile (objfile_),
c0015d44 101 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
b248663f 102 comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
2c99ee5c
TT
103 language (language_),
104 m_last_source_start_addr (last_addr)
4a2125f5
TT
105 {
106 /* Allocate the compunit symtab now. The caller needs it to allocate
107 non-primary symtabs. It is also needed by get_macro_table. */
108 compunit_symtab = allocate_compunit_symtab (objfile, name);
109
110 /* Build the subfile for NAME (the main source file) so that we can record
111 a pointer to it for later.
112 IMPORTANT: Do not allocate a struct symtab for NAME here.
113 It can happen that the debug info provides a different path to NAME than
114 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
115 that only works if the main_subfile doesn't have a symtab yet. */
116 start_subfile (name);
117 /* Save this so that we don't have to go looking for it at the end
118 of the subfiles list. */
119 main_subfile = m_current_subfile;
120 }
121
122 /* Reopen an existing compunit_symtab so that additional symbols can
123 be added to it. Arguments are as for the main constructor. CUST
124 is the expandable compunit_symtab to be reopened. */
125
126 buildsym_compunit (struct objfile *objfile_, const char *name,
127 const char *comp_dir_, enum language language_,
128 CORE_ADDR last_addr, struct compunit_symtab *cust)
129 : objfile (objfile_),
130 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
131 comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
132 compunit_symtab (cust),
133 language (language_),
134 m_last_source_start_addr (last_addr)
b248663f
TT
135 {
136 }
137
138 ~buildsym_compunit ()
139 {
140 struct subfile *subfile, *nextsub;
141
6a976300
TT
142 if (m_pending_macros != nullptr)
143 free_macro_table (m_pending_macros);
144
b248663f
TT
145 for (subfile = subfiles;
146 subfile != NULL;
147 subfile = nextsub)
148 {
149 nextsub = subfile->next;
150 xfree (subfile->name);
151 xfree (subfile->line_vector);
152 xfree (subfile);
153 }
e148f09d
TT
154
155 struct pending *next, *next1;
156
157 for (next = m_file_symbols; next != NULL; next = next1)
158 {
159 next1 = next->next;
160 xfree ((void *) next);
161 }
162
163 for (next = m_global_symbols; next != NULL; next = next1)
164 {
165 next1 = next->next;
166 xfree ((void *) next);
167 }
b248663f
TT
168 }
169
c0015d44
TT
170 void set_last_source_file (const char *name)
171 {
172 char *new_name = name == NULL ? NULL : xstrdup (name);
173 m_last_source_file.reset (new_name);
174 }
175
4a2125f5
TT
176 const char *get_last_source_file ()
177 {
178 return m_last_source_file.get ();
179 }
180
6a976300
TT
181 struct macro_table *get_macro_table ()
182 {
183 if (m_pending_macros == nullptr)
184 m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
185 objfile->per_bfd->macro_cache,
186 compunit_symtab);
187 return m_pending_macros;
188 }
189
190 struct macro_table *release_macros ()
191 {
192 struct macro_table *result = m_pending_macros;
193 m_pending_macros = nullptr;
194 return result;
195 }
196
5ac04550
TT
197 /* This function is called to discard any pending blocks. */
198
199 void free_pending_blocks ()
200 {
201 m_pending_block_obstack.clear ();
202 m_pending_blocks = nullptr;
203 }
204
4a2125f5
TT
205 struct block *finish_block (struct symbol *symbol,
206 struct pending_block *old_blocks,
207 const struct dynamic_prop *static_link,
208 CORE_ADDR start, CORE_ADDR end);
209
210 void record_block_range (struct block *block,
211 CORE_ADDR start, CORE_ADDR end_inclusive);
212
213 void start_subfile (const char *name);
214
215 void patch_subfile_names (struct subfile *subfile, const char *name);
216
217 void push_subfile ();
218
219 const char *pop_subfile ();
220
221 void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
222
223 struct compunit_symtab *get_compunit_symtab ()
224 {
225 return compunit_symtab;
226 }
227
228 void set_last_source_start_addr (CORE_ADDR addr)
229 {
230 m_last_source_start_addr = addr;
231 }
232
233 CORE_ADDR get_last_source_start_addr ()
234 {
235 return m_last_source_start_addr;
236 }
237
238 struct using_direct **get_local_using_directives ()
239 {
240 return &m_local_using_directives;
241 }
242
243 void set_local_using_directives (struct using_direct *new_local)
244 {
245 m_local_using_directives = new_local;
246 }
247
248 struct using_direct **get_global_using_directives ()
249 {
250 return &m_global_using_directives;
251 }
252
253 bool outermost_context_p () const
254 {
255 return m_context_stack.empty ();
256 }
257
258 struct context_stack *get_current_context_stack ()
259 {
260 if (m_context_stack.empty ())
261 return nullptr;
262 return &m_context_stack.back ();
263 }
264
265 int get_context_stack_depth () const
266 {
267 return m_context_stack.size ();
268 }
269
270 struct subfile *get_current_subfile ()
271 {
272 return m_current_subfile;
273 }
274
275 struct pending **get_local_symbols ()
276 {
277 return &m_local_symbols;
278 }
279
280 struct pending **get_file_symbols ()
281 {
282 return &m_file_symbols;
283 }
284
285 struct pending **get_global_symbols ()
286 {
287 return &m_global_symbols;
288 }
289
290 void record_debugformat (const char *format)
291 {
292 debugformat = format;
293 }
294
295 void record_producer (const char *producer)
296 {
297 this->producer = producer;
298 }
299
300 struct context_stack *push_context (int desc, CORE_ADDR valu);
301
302 struct context_stack pop_context ();
303
304 struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
305 int expandable, int required);
306
307 struct compunit_symtab *end_symtab_from_static_block
308 (struct block *static_block, int section, int expandable);
309
310 struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
311
312 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
313 int section);
314
315 void augment_type_symtab ();
316
317private:
318
319 void record_pending_block (struct block *block, struct pending_block *opblock);
320
321 struct block *finish_block_internal (struct symbol *symbol,
322 struct pending **listhead,
323 struct pending_block *old_blocks,
324 const struct dynamic_prop *static_link,
325 CORE_ADDR start, CORE_ADDR end,
326 int is_global, int expandable);
327
328 struct blockvector *make_blockvector ();
329
330 void watch_main_source_file_lossage ();
331
332 struct compunit_symtab *end_symtab_with_blockvector
333 (struct block *static_block, int section, int expandable);
334
43f3e411
DE
335 /* The objfile we're reading debug info from. */
336 struct objfile *objfile;
337
338 /* List of subfiles (source files).
339 Files are added to the front of the list.
340 This is important mostly for the language determination hacks we use,
341 which iterate over previously added files. */
b248663f 342 struct subfile *subfiles = nullptr;
43f3e411
DE
343
344 /* The subfile of the main source file. */
b248663f 345 struct subfile *main_subfile = nullptr;
4d663531 346
c0015d44
TT
347 /* Name of source file whose symbol data we are now processing. This
348 comes from a symbol of type N_SO for stabs. For DWARF it comes
349 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
350 gdb::unique_xmalloc_ptr<char> m_last_source_file;
351
43f3e411 352 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
905eb0e2 353 gdb::unique_xmalloc_ptr<char> comp_dir;
4d663531 354
43f3e411
DE
355 /* Space for this is not malloc'd, and is assumed to have at least
356 the same lifetime as objfile. */
b248663f 357 const char *producer = nullptr;
4d663531 358
43f3e411
DE
359 /* Space for this is not malloc'd, and is assumed to have at least
360 the same lifetime as objfile. */
b248663f 361 const char *debugformat = nullptr;
94d09e04 362
43f3e411 363 /* The compunit we are building. */
b248663f 364 struct compunit_symtab *compunit_symtab = nullptr;
5ffa0793
PA
365
366 /* Language of this compunit_symtab. */
367 enum language language;
6a976300
TT
368
369 /* The macro table for the compilation unit whose symbols we're
370 currently reading. */
371 struct macro_table *m_pending_macros = nullptr;
530fedbc
TT
372
373 /* True if symtab has line number info. This prevents an otherwise
374 empty symtab from being tossed. */
375 bool m_have_line_numbers = false;
2c99ee5c
TT
376
377 /* Core address of start of text of current source file. This too
378 comes from the N_SO symbol. For Dwarf it typically comes from the
379 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
380 CORE_ADDR m_last_source_start_addr;
8419ee53
TT
381
382 /* Stack of subfile names. */
383 std::vector<const char *> m_subfile_stack;
6cccc9a8
TT
384
385 /* The "using" directives local to lexical context. */
386 struct using_direct *m_local_using_directives = nullptr;
387
388 /* Global "using" directives. */
389 struct using_direct *m_global_using_directives = nullptr;
a60f3166
TT
390
391 /* The stack of contexts that are pushed by push_context and popped
392 by pop_context. */
393 std::vector<struct context_stack> m_context_stack;
3c65e5b3
TT
394
395 struct subfile *m_current_subfile = nullptr;
7ea05a7b
TT
396
397 /* The mutable address map for the compilation unit whose symbols
398 we're currently reading. The symtabs' shared blockvector will
399 point to a fixed copy of this. */
400 struct addrmap *m_pending_addrmap = nullptr;
401
402 /* The obstack on which we allocate pending_addrmap.
403 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
404 initialized (and holds pending_addrmap). */
405 auto_obstack m_pending_addrmap_obstack;
406
407 /* True if we recorded any ranges in the addrmap that are different
408 from those in the blockvector already. We set this to false when
409 we start processing a symfile, and if it's still false at the
410 end, then we just toss the addrmap. */
411 bool m_pending_addrmap_interesting = false;
5ac04550
TT
412
413 /* An obstack used for allocating pending blocks. */
414 auto_obstack m_pending_block_obstack;
415
416 /* Pointer to the head of a linked list of symbol blocks which have
417 already been finalized (lexical contexts already closed) and which
418 are just waiting to be built into a blockvector when finalizing the
419 associated symtab. */
420 struct pending_block *m_pending_blocks = nullptr;
e148f09d
TT
421
422 /* Pending static symbols and types at the top level. */
423 struct pending *m_file_symbols = nullptr;
424
425 /* Pending global functions and variables. */
426 struct pending *m_global_symbols = nullptr;
427
428 /* Pending symbols that are local to the lexical context. */
429 struct pending *m_local_symbols = nullptr;
43f3e411 430};
94d09e04 431
43f3e411
DE
432/* The work-in-progress of the compunit we are building.
433 This is created first, before any subfiles by start_symtab. */
7bab9b58 434
43f3e411 435static struct buildsym_compunit *buildsym_compunit;
7bab9b58 436
93eed41f
TT
437/* List of blocks already made (lexical contexts already closed).
438 This is used at the end to make the blockvector. */
439
440struct pending_block
441 {
442 struct pending_block *next;
443 struct block *block;
444 };
445
0ab9ce85
DE
446static void free_buildsym_compunit (void);
447
c906108c 448static int compare_line_numbers (const void *ln1p, const void *ln2p);
0b49e518 449
c906108c
SS
450/* Initial sizes of data structures. These are realloc'd larger if
451 needed, and realloc'd down to the size actually used, when
452 completed. */
453
c906108c
SS
454#define INITIAL_LINE_VECTOR_LENGTH 1000
455\f
456
4a64f543 457/* Maintain the lists of symbols and blocks. */
c906108c 458
93bf33fd 459/* Add a symbol to one of the lists of symbols. */
c906108c
SS
460
461void
462add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
463{
52f0bd74 464 struct pending *link;
c906108c
SS
465
466 /* If this is an alias for another symbol, don't add it. */
467 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
468 return;
469
4a64f543 470 /* We keep PENDINGSIZE symbols in each link of the list. If we
c906108c
SS
471 don't have a link with room in it, add a new link. */
472 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
473 {
1d376700 474 link = XNEW (struct pending);
c906108c
SS
475 link->next = *listhead;
476 *listhead = link;
477 link->nsyms = 0;
478 }
479
480 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
481}
482
483/* Find a symbol named NAME on a LIST. NAME need not be
484 '\0'-terminated; LENGTH is the length of the name. */
485
486struct symbol *
487find_symbol_in_list (struct pending *list, char *name, int length)
488{
489 int j;
0d5cff50 490 const char *pp;
c906108c
SS
491
492 while (list != NULL)
493 {
494 for (j = list->nsyms; --j >= 0;)
495 {
3567439c 496 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
5aafa1cc
PM
497 if (*pp == *name && strncmp (pp, name, length) == 0
498 && pp[length] == '\0')
c906108c
SS
499 {
500 return (list->symbol[j]);
501 }
502 }
503 list = list->next;
504 }
505 return (NULL);
506}
507
33c7c59d
TT
508/* At end of reading syms, or in case of quit, ensure everything
509 associated with building symtabs is freed.
0ab9ce85
DE
510
511 N.B. This is *not* intended to be used when building psymtabs. Some debug
512 info readers call this anyway, which is harmless if confusing. */
c906108c 513
33c7c59d 514scoped_free_pendings::~scoped_free_pendings ()
c906108c 515{
0ab9ce85 516 free_buildsym_compunit ();
c906108c
SS
517}
518
6b213a47
TT
519/* Record BLOCK on the list of all blocks in the file. Put it after
520 OPBLOCK, or at the beginning if opblock is NULL. This puts the
521 block in the list after all its subblocks. */
522
4a2125f5
TT
523void
524buildsym_compunit::record_pending_block (struct block *block,
525 struct pending_block *opblock)
6b213a47
TT
526{
527 struct pending_block *pblock;
528
4a2125f5 529 pblock = XOBNEW (&m_pending_block_obstack, struct pending_block);
6b213a47
TT
530 pblock->block = block;
531 if (opblock)
532 {
533 pblock->next = opblock->next;
534 opblock->next = pblock;
535 }
536 else
537 {
4a2125f5
TT
538 pblock->next = m_pending_blocks;
539 m_pending_blocks = pblock;
6b213a47
TT
540 }
541}
542
c906108c
SS
543/* Take one of the lists of symbols and make a block from it. Keep
544 the order the symbols have in the list (reversed from the input
545 file). Put the block on the list of pending blocks. */
546
4a2125f5
TT
547struct block *
548buildsym_compunit::finish_block_internal
549 (struct symbol *symbol,
550 struct pending **listhead,
551 struct pending_block *old_blocks,
552 const struct dynamic_prop *static_link,
553 CORE_ADDR start, CORE_ADDR end,
554 int is_global, int expandable)
c906108c 555{
5af949e3 556 struct gdbarch *gdbarch = get_objfile_arch (objfile);
52f0bd74
AC
557 struct pending *next, *next1;
558 struct block *block;
559 struct pending_block *pblock;
c906108c 560 struct pending_block *opblock;
c906108c 561
84a146c9
TT
562 block = (is_global
563 ? allocate_global_block (&objfile->objfile_obstack)
564 : allocate_block (&objfile->objfile_obstack));
c906108c 565
261397f8
DJ
566 if (symbol)
567 {
5ffa0793
PA
568 BLOCK_DICT (block)
569 = dict_create_linear (&objfile->objfile_obstack,
4a2125f5 570 language, *listhead);
261397f8
DJ
571 }
572 else
c906108c 573 {
6d30eef8
DE
574 if (expandable)
575 {
4a2125f5 576 BLOCK_DICT (block) = dict_create_hashed_expandable (language);
6d30eef8
DE
577 dict_add_pending (BLOCK_DICT (block), *listhead);
578 }
579 else
580 {
581 BLOCK_DICT (block) =
5ffa0793 582 dict_create_hashed (&objfile->objfile_obstack,
4a2125f5 583 language, *listhead);
6d30eef8 584 }
c906108c
SS
585 }
586
587 BLOCK_START (block) = start;
588 BLOCK_END (block) = end;
c906108c 589
c906108c
SS
590 /* Put the block in as the value of the symbol that names it. */
591
592 if (symbol)
593 {
594 struct type *ftype = SYMBOL_TYPE (symbol);
de4f826b 595 struct dict_iterator iter;
c906108c
SS
596 SYMBOL_BLOCK_VALUE (symbol) = block;
597 BLOCK_FUNCTION (block) = symbol;
598
599 if (TYPE_NFIELDS (ftype) <= 0)
600 {
601 /* No parameter type information is recorded with the
602 function's type. Set that from the type of the
4a64f543 603 parameter symbols. */
c906108c
SS
604 int nparams = 0, iparams;
605 struct symbol *sym;
8157b174
TT
606
607 /* Here we want to directly access the dictionary, because
608 we haven't fully initialized the block yet. */
609 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
c906108c 610 {
2a2d4dc3
AS
611 if (SYMBOL_IS_ARGUMENT (sym))
612 nparams++;
c906108c
SS
613 }
614 if (nparams > 0)
615 {
616 TYPE_NFIELDS (ftype) = nparams;
617 TYPE_FIELDS (ftype) = (struct field *)
618 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
619
de4f826b 620 iparams = 0;
8157b174
TT
621 /* Here we want to directly access the dictionary, because
622 we haven't fully initialized the block yet. */
623 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
c906108c 624 {
de4f826b
DC
625 if (iparams == nparams)
626 break;
627
2a2d4dc3 628 if (SYMBOL_IS_ARGUMENT (sym))
c906108c 629 {
c906108c 630 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
8176bb6d 631 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
c906108c 632 iparams++;
c906108c
SS
633 }
634 }
635 }
636 }
637 }
638 else
639 {
640 BLOCK_FUNCTION (block) = NULL;
641 }
642
63e43d3a
PMR
643 if (static_link != NULL)
644 objfile_register_static_link (objfile, block, static_link);
645
1d376700 646 /* Now free the links of the list, and empty the list. */
c906108c
SS
647
648 for (next = *listhead; next; next = next1)
649 {
650 next1 = next->next;
1d376700 651 xfree (next);
c906108c
SS
652 }
653 *listhead = NULL;
654
c906108c 655 /* Check to be sure that the blocks have an end address that is
4a64f543 656 greater than starting address. */
c906108c
SS
657
658 if (BLOCK_END (block) < BLOCK_START (block))
659 {
660 if (symbol)
661 {
b98664d3 662 complaint (_("block end address less than block "
3e43a32a 663 "start address in %s (patched it)"),
de5ad195 664 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
665 }
666 else
667 {
b98664d3 668 complaint (_("block end address %s less than block "
3e43a32a 669 "start address %s (patched it)"),
5af949e3
UW
670 paddress (gdbarch, BLOCK_END (block)),
671 paddress (gdbarch, BLOCK_START (block)));
c906108c 672 }
4a64f543 673 /* Better than nothing. */
c906108c
SS
674 BLOCK_END (block) = BLOCK_START (block);
675 }
c906108c
SS
676
677 /* Install this block as the superblock of all blocks made since the
678 start of this scope that don't have superblocks yet. */
679
680 opblock = NULL;
4a2125f5 681 for (pblock = m_pending_blocks;
c0219d42
MS
682 pblock && pblock != old_blocks;
683 pblock = pblock->next)
c906108c
SS
684 {
685 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
686 {
c906108c 687 /* Check to be sure the blocks are nested as we receive
4a64f543 688 them. If the compiler/assembler/linker work, this just
14711c82
DJ
689 burns a small amount of time.
690
691 Skip blocks which correspond to a function; they're not
692 physically nested inside this other blocks, only
693 lexically nested. */
694 if (BLOCK_FUNCTION (pblock->block) == NULL
695 && (BLOCK_START (pblock->block) < BLOCK_START (block)
696 || BLOCK_END (pblock->block) > BLOCK_END (block)))
c906108c
SS
697 {
698 if (symbol)
699 {
b98664d3 700 complaint (_("inner block not inside outer block in %s"),
de5ad195 701 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
702 }
703 else
704 {
b98664d3 705 complaint (_("inner block (%s-%s) not "
3e43a32a 706 "inside outer block (%s-%s)"),
5af949e3
UW
707 paddress (gdbarch, BLOCK_START (pblock->block)),
708 paddress (gdbarch, BLOCK_END (pblock->block)),
709 paddress (gdbarch, BLOCK_START (block)),
710 paddress (gdbarch, BLOCK_END (block)));
c906108c
SS
711 }
712 if (BLOCK_START (pblock->block) < BLOCK_START (block))
713 BLOCK_START (pblock->block) = BLOCK_START (block);
714 if (BLOCK_END (pblock->block) > BLOCK_END (block))
715 BLOCK_END (pblock->block) = BLOCK_END (block);
716 }
c906108c
SS
717 BLOCK_SUPERBLOCK (pblock->block) = block;
718 }
719 opblock = pblock;
720 }
721
22cee43f
PMR
722 block_set_using (block,
723 (is_global
4a2125f5
TT
724 ? m_global_using_directives
725 : m_local_using_directives),
22cee43f
PMR
726 &objfile->objfile_obstack);
727 if (is_global)
4a2125f5 728 m_global_using_directives = NULL;
22cee43f 729 else
4a2125f5 730 m_local_using_directives = NULL;
27aa8d6a 731
6b213a47 732 record_pending_block (block, opblock);
801e3a5b
JB
733
734 return block;
c906108c
SS
735}
736
84a146c9 737struct block *
4a2125f5
TT
738buildsym_compunit::finish_block (struct symbol *symbol,
739 struct pending_block *old_blocks,
740 const struct dynamic_prop *static_link,
741 CORE_ADDR start, CORE_ADDR end)
84a146c9 742{
4a2125f5
TT
743 return finish_block_internal (symbol, &m_local_symbols,
744 old_blocks, static_link, start, end, 0, 0);
84a146c9 745}
de4f826b 746
801e3a5b
JB
747/* Record that the range of addresses from START to END_INCLUSIVE
748 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
749 addresses must be set already. You must apply this function to all
750 BLOCK's children before applying it to BLOCK.
751
752 If a call to this function complicates the picture beyond that
753 already provided by BLOCK_START and BLOCK_END, then we create an
754 address map for the block. */
755void
4a2125f5
TT
756buildsym_compunit::record_block_range (struct block *block,
757 CORE_ADDR start,
758 CORE_ADDR end_inclusive)
801e3a5b
JB
759{
760 /* If this is any different from the range recorded in the block's
761 own BLOCK_START and BLOCK_END, then note that the address map has
762 become interesting. Note that even if this block doesn't have
763 any "interesting" ranges, some later block might, so we still
764 need to record this block in the addrmap. */
765 if (start != BLOCK_START (block)
766 || end_inclusive + 1 != BLOCK_END (block))
4a2125f5 767 m_pending_addrmap_interesting = true;
801e3a5b 768
4a2125f5
TT
769 if (m_pending_addrmap == nullptr)
770 m_pending_addrmap = addrmap_create_mutable (&m_pending_addrmap_obstack);
801e3a5b 771
4a2125f5 772 addrmap_set_empty (m_pending_addrmap, start, end_inclusive, block);
801e3a5b
JB
773}
774
4a2125f5
TT
775struct blockvector *
776buildsym_compunit::make_blockvector ()
c906108c 777{
52f0bd74
AC
778 struct pending_block *next;
779 struct blockvector *blockvector;
780 int i;
c906108c
SS
781
782 /* Count the length of the list of blocks. */
783
4a2125f5 784 for (next = m_pending_blocks, i = 0; next; next = next->next, i++)
5ac04550 785 {
c906108c
SS
786 }
787
788 blockvector = (struct blockvector *)
4a146b47 789 obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
790 (sizeof (struct blockvector)
791 + (i - 1) * sizeof (struct block *)));
792
4a64f543 793 /* Copy the blocks into the blockvector. This is done in reverse
c906108c 794 order, which happens to put the blocks into the proper order
4a64f543 795 (ascending starting address). finish_block has hair to insert
c906108c
SS
796 each block into the list after its subblocks in order to make
797 sure this is true. */
798
799 BLOCKVECTOR_NBLOCKS (blockvector) = i;
4a2125f5 800 for (next = m_pending_blocks; next; next = next->next)
c906108c
SS
801 {
802 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
803 }
804
4a2125f5 805 free_pending_blocks ();
c906108c 806
801e3a5b
JB
807 /* If we needed an address map for this symtab, record it in the
808 blockvector. */
4a2125f5 809 if (m_pending_addrmap != nullptr && m_pending_addrmap_interesting)
801e3a5b 810 BLOCKVECTOR_MAP (blockvector)
4a2125f5 811 = addrmap_create_fixed (m_pending_addrmap, &objfile->objfile_obstack);
801e3a5b
JB
812 else
813 BLOCKVECTOR_MAP (blockvector) = 0;
4aad0dfc 814
c906108c 815 /* Some compilers output blocks in the wrong order, but we depend on
4a64f543 816 their being in the right order so we can binary search. Check the
4aad0dfc
DE
817 order and moan about it.
818 Note: Remember that the first two blocks are the global and static
819 blocks. We could special case that fact and begin checking at block 2.
820 To avoid making that assumption we do not. */
c906108c
SS
821 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
822 {
823 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
824 {
825 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
826 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
827 {
59527da0
JB
828 CORE_ADDR start
829 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
c906108c 830
b98664d3 831 complaint (_("block at %s out of order"),
bb599908 832 hex_string ((LONGEST) start));
c906108c
SS
833 }
834 }
835 }
c906108c
SS
836
837 return (blockvector);
838}
839\f
840/* Start recording information about source code that came from an
841 included (or otherwise merged-in) source file with a different
4d663531 842 name. NAME is the name of the file (cannot be NULL). */
c906108c
SS
843
844void
4a2125f5 845buildsym_compunit::start_subfile (const char *name)
c906108c 846{
43f3e411 847 const char *subfile_dirname;
52f0bd74 848 struct subfile *subfile;
c906108c 849
4a2125f5 850 subfile_dirname = comp_dir.get ();
c906108c 851
43f3e411
DE
852 /* See if this subfile is already registered. */
853
4a2125f5 854 for (subfile = subfiles; subfile; subfile = subfile->next)
c906108c 855 {
84ba0adf
DJ
856 char *subfile_name;
857
858 /* If NAME is an absolute path, and this subfile is not, then
859 attempt to create an absolute path to compare. */
860 if (IS_ABSOLUTE_PATH (name)
861 && !IS_ABSOLUTE_PATH (subfile->name)
43f3e411
DE
862 && subfile_dirname != NULL)
863 subfile_name = concat (subfile_dirname, SLASH_STRING,
6eb7ee03 864 subfile->name, (char *) NULL);
84ba0adf
DJ
865 else
866 subfile_name = subfile->name;
867
868 if (FILENAME_CMP (subfile_name, name) == 0)
c906108c 869 {
4a2125f5 870 m_current_subfile = subfile;
84ba0adf
DJ
871 if (subfile_name != subfile->name)
872 xfree (subfile_name);
c906108c
SS
873 return;
874 }
84ba0adf
DJ
875 if (subfile_name != subfile->name)
876 xfree (subfile_name);
c906108c
SS
877 }
878
43f3e411 879 /* This subfile is not known. Add an entry for it. */
c906108c 880
8d749320 881 subfile = XNEW (struct subfile);
43f3e411 882 memset (subfile, 0, sizeof (struct subfile));
4a2125f5 883 subfile->buildsym_compunit = this;
43f3e411 884
4a2125f5
TT
885 subfile->next = subfiles;
886 subfiles = subfile;
43f3e411 887
4a2125f5 888 m_current_subfile = subfile;
c906108c 889
b74db436 890 subfile->name = xstrdup (name);
c906108c
SS
891
892 /* Initialize line-number recording for this subfile. */
893 subfile->line_vector = NULL;
894
895 /* Default the source language to whatever can be deduced from the
896 filename. If nothing can be deduced (such as for a C/C++ include
897 file with a ".h" extension), then inherit whatever language the
898 previous subfile had. This kludgery is necessary because there
899 is no standard way in some object formats to record the source
900 language. Also, when symtabs are allocated we try to deduce a
901 language then as well, but it is too late for us to use that
902 information while reading symbols, since symtabs aren't allocated
903 until after all the symbols have been processed for a given
4a64f543 904 source file. */
c906108c
SS
905
906 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
907 if (subfile->language == language_unknown
908 && subfile->next != NULL)
c906108c
SS
909 {
910 subfile->language = subfile->next->language;
911 }
912
25caa7a8 913 /* If the filename of this subfile ends in .C, then change the
c906108c 914 language of any pending subfiles from C to C++. We also accept
25caa7a8 915 any other C++ suffixes accepted by deduce_language_from_filename. */
c906108c
SS
916 /* Likewise for f2c. */
917
918 if (subfile->name)
919 {
920 struct subfile *s;
921 enum language sublang = deduce_language_from_filename (subfile->name);
922
923 if (sublang == language_cplus || sublang == language_fortran)
4a2125f5 924 for (s = subfiles; s != NULL; s = s->next)
c906108c
SS
925 if (s->language == language_c)
926 s->language = sublang;
927 }
928
929 /* And patch up this file if necessary. */
930 if (subfile->language == language_c
931 && subfile->next != NULL
932 && (subfile->next->language == language_cplus
933 || subfile->next->language == language_fortran))
934 {
935 subfile->language = subfile->next->language;
936 }
937}
938
43f3e411 939/* Delete the buildsym compunit. */
7bab9b58
DE
940
941static void
43f3e411 942free_buildsym_compunit (void)
7bab9b58 943{
43f3e411
DE
944 if (buildsym_compunit == NULL)
945 return;
b248663f 946 delete buildsym_compunit;
43f3e411 947 buildsym_compunit = NULL;
7bab9b58
DE
948}
949
c906108c
SS
950/* For stabs readers, the first N_SO symbol is assumed to be the
951 source file name, and the subfile struct is initialized using that
952 assumption. If another N_SO symbol is later seen, immediately
953 following the first one, then the first one is assumed to be the
954 directory name and the second one is really the source file name.
955
956 So we have to patch up the subfile struct by moving the old name
957 value to dirname and remembering the new name. Some sanity
958 checking is performed to ensure that the state of the subfile
959 struct is reasonable and that the old name we are assuming to be a
4a64f543 960 directory name actually is (by checking for a trailing '/'). */
c906108c
SS
961
962void
4a2125f5
TT
963buildsym_compunit::patch_subfile_names (struct subfile *subfile,
964 const char *name)
c906108c 965{
43f3e411 966 if (subfile != NULL
4a2125f5 967 && comp_dir == NULL
43f3e411 968 && subfile->name != NULL
0ba1096a 969 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
c906108c 970 {
4a2125f5 971 comp_dir.reset (subfile->name);
1b36a34b 972 subfile->name = xstrdup (name);
46212e0b 973 set_last_source_file (name);
c906108c
SS
974
975 /* Default the source language to whatever can be deduced from
976 the filename. If nothing can be deduced (such as for a C/C++
977 include file with a ".h" extension), then inherit whatever
978 language the previous subfile had. This kludgery is
979 necessary because there is no standard way in some object
980 formats to record the source language. Also, when symtabs
981 are allocated we try to deduce a language then as well, but
982 it is too late for us to use that information while reading
983 symbols, since symtabs aren't allocated until after all the
4a64f543 984 symbols have been processed for a given source file. */
c906108c
SS
985
986 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
987 if (subfile->language == language_unknown
988 && subfile->next != NULL)
c906108c
SS
989 {
990 subfile->language = subfile->next->language;
991 }
992 }
993}
994\f
995/* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
996 switching source files (different subfiles, as we call them) within
997 one object file, but using a stack rather than in an arbitrary
998 order. */
999
1000void
4a2125f5 1001buildsym_compunit::push_subfile ()
c906108c 1002{
4a2125f5
TT
1003 gdb_assert (m_current_subfile != NULL);
1004 gdb_assert (m_current_subfile->name != NULL);
1005 m_subfile_stack.push_back (m_current_subfile->name);
c906108c
SS
1006}
1007
8419ee53 1008const char *
4a2125f5 1009buildsym_compunit::pop_subfile ()
c906108c 1010{
4a2125f5
TT
1011 gdb_assert (!m_subfile_stack.empty ());
1012 const char *name = m_subfile_stack.back ();
1013 m_subfile_stack.pop_back ();
8419ee53 1014 return name;
c906108c
SS
1015}
1016\f
1017/* Add a linetable entry for line number LINE and address PC to the
1018 line vector for SUBFILE. */
1019
1020void
4a2125f5
TT
1021buildsym_compunit::record_line (struct subfile *subfile, int line,
1022 CORE_ADDR pc)
c906108c
SS
1023{
1024 struct linetable_entry *e;
c906108c 1025
cc59ec59 1026 /* Ignore the dummy line number in libg.o */
c906108c
SS
1027 if (line == 0xffff)
1028 {
1029 return;
1030 }
1031
1032 /* Make sure line vector exists and is big enough. */
1033 if (!subfile->line_vector)
1034 {
1035 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
1036 subfile->line_vector = (struct linetable *)
1037 xmalloc (sizeof (struct linetable)
c5aa993b 1038 + subfile->line_vector_length * sizeof (struct linetable_entry));
c906108c 1039 subfile->line_vector->nitems = 0;
4a2125f5 1040 m_have_line_numbers = true;
c906108c
SS
1041 }
1042
1043 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
1044 {
1045 subfile->line_vector_length *= 2;
1046 subfile->line_vector = (struct linetable *)
1047 xrealloc ((char *) subfile->line_vector,
1048 (sizeof (struct linetable)
1049 + (subfile->line_vector_length
1050 * sizeof (struct linetable_entry))));
1051 }
1052
607ae575
DJ
1053 /* Normally, we treat lines as unsorted. But the end of sequence
1054 marker is special. We sort line markers at the same PC by line
1055 number, so end of sequence markers (which have line == 0) appear
1056 first. This is right if the marker ends the previous function,
1057 and there is no padding before the next function. But it is
1058 wrong if the previous line was empty and we are now marking a
1059 switch to a different subfile. We must leave the end of sequence
1060 marker at the end of this group of lines, not sort the empty line
1061 to after the marker. The easiest way to accomplish this is to
1062 delete any empty lines from our table, if they are followed by
1063 end of sequence markers. All we lose is the ability to set
1064 breakpoints at some lines which contain no instructions
1065 anyway. */
1066 if (line == 0 && subfile->line_vector->nitems > 0)
1067 {
1068 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
1069 while (subfile->line_vector->nitems > 0 && e->pc == pc)
1070 {
1071 e--;
1072 subfile->line_vector->nitems--;
1073 }
1074 }
1075
c906108c
SS
1076 e = subfile->line_vector->item + subfile->line_vector->nitems++;
1077 e->line = line;
607ae575 1078 e->pc = pc;
c906108c
SS
1079}
1080
1081/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
1082
1083static int
1084compare_line_numbers (const void *ln1p, const void *ln2p)
1085{
1086 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
1087 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
1088
1089 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
1090 Please keep it that way. */
1091 if (ln1->pc < ln2->pc)
1092 return -1;
1093
1094 if (ln1->pc > ln2->pc)
1095 return 1;
1096
1097 /* If pc equal, sort by line. I'm not sure whether this is optimum
1098 behavior (see comment at struct linetable in symtab.h). */
1099 return ln1->line - ln2->line;
1100}
1101\f
43f3e411
DE
1102/* See buildsym.h. */
1103
1104struct compunit_symtab *
1105buildsym_compunit_symtab (void)
1106{
1107 gdb_assert (buildsym_compunit != NULL);
1108
4a2125f5 1109 return buildsym_compunit->get_compunit_symtab ();
43f3e411
DE
1110}
1111
1112/* See buildsym.h. */
fc474241
DE
1113
1114struct macro_table *
43f3e411 1115get_macro_table (void)
fc474241 1116{
43f3e411
DE
1117 struct objfile *objfile;
1118
1119 gdb_assert (buildsym_compunit != NULL);
6a976300 1120 return buildsym_compunit->get_macro_table ();
fc474241
DE
1121}
1122\f
4d663531 1123/* Start a new symtab for a new source file in OBJFILE. Called, for example,
c906108c
SS
1124 when a stabs symbol of type N_SO is seen, or when a DWARF
1125 TAG_compile_unit DIE is seen. It indicates the start of data for
0b0287a1
DE
1126 one original source file.
1127
5ffa0793
PA
1128 NAME is the name of the file (cannot be NULL). COMP_DIR is the
1129 directory in which the file was compiled (or NULL if not known).
1130 START_ADDR is the lowest address of objects in the file (or 0 if
1131 not known). LANGUAGE is the language of the source file, or
1132 language_unknown if not known, in which case it'll be deduced from
1133 the filename. */
c906108c 1134
43f3e411 1135struct compunit_symtab *
4d663531 1136start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
5ffa0793 1137 CORE_ADDR start_addr, enum language language)
c906108c 1138{
b37dd3bc
TT
1139 /* These should have been reset either by successful completion of building
1140 a symtab, or by the scoped_free_pendings destructor. */
1141 gdb_assert (buildsym_compunit == nullptr);
43f3e411 1142
c0015d44 1143 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
2c99ee5c 1144 language, start_addr);
43f3e411 1145
4a2125f5 1146 return buildsym_compunit->get_compunit_symtab ();
6d30eef8
DE
1147}
1148
1149/* Restart compilation for a symtab.
0ab9ce85
DE
1150 CUST is the result of end_expandable_symtab.
1151 NAME, START_ADDR are the source file we are resuming with.
1152
6d30eef8 1153 This is used when a symtab is built from multiple sources.
0ab9ce85
DE
1154 The symtab is first built with start_symtab/end_expandable_symtab
1155 and then for each additional piece call restart_symtab/augment_*_symtab.
1156 Note: At the moment there is only augment_type_symtab. */
6d30eef8
DE
1157
1158void
0ab9ce85
DE
1159restart_symtab (struct compunit_symtab *cust,
1160 const char *name, CORE_ADDR start_addr)
6d30eef8 1161{
b37dd3bc
TT
1162 /* These should have been reset either by successful completion of building
1163 a symtab, or by the scoped_free_pendings destructor. */
1164 gdb_assert (buildsym_compunit == nullptr);
c906108c 1165
b248663f
TT
1166 buildsym_compunit
1167 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
c0015d44 1168 name,
b248663f 1169 COMPUNIT_DIRNAME (cust),
2c99ee5c 1170 compunit_language (cust),
4a2125f5
TT
1171 start_addr,
1172 cust);
c906108c
SS
1173}
1174
4a64f543
MS
1175/* Subroutine of end_symtab to simplify it. Look for a subfile that
1176 matches the main source file's basename. If there is only one, and
1177 if the main source file doesn't have any symbol or line number
1178 information, then copy this file's symtab and line_vector to the
1179 main source file's subfile and discard the other subfile. This can
1180 happen because of a compiler bug or from the user playing games
1181 with #line or from things like a distributed build system that
43f3e411
DE
1182 manipulates the debug info. This can also happen from an innocent
1183 symlink in the paths, we don't canonicalize paths here. */
4584e32e 1184
4a2125f5
TT
1185void
1186buildsym_compunit::watch_main_source_file_lossage ()
4584e32e 1187{
43f3e411 1188 struct subfile *mainsub, *subfile;
4584e32e 1189
43f3e411 1190 /* Get the main source file. */
4a2125f5 1191 mainsub = main_subfile;
43f3e411 1192
4a64f543 1193 /* If the main source file doesn't have any line number or symbol
7bab9b58 1194 info, look for an alias in another subfile. */
4584e32e 1195
43f3e411
DE
1196 if (mainsub->line_vector == NULL
1197 && mainsub->symtab == NULL)
4584e32e 1198 {
43f3e411 1199 const char *mainbase = lbasename (mainsub->name);
4584e32e
DE
1200 int nr_matches = 0;
1201 struct subfile *prevsub;
1202 struct subfile *mainsub_alias = NULL;
1203 struct subfile *prev_mainsub_alias = NULL;
1204
1205 prevsub = NULL;
4a2125f5 1206 for (subfile = subfiles;
43f3e411 1207 subfile != NULL;
4584e32e
DE
1208 subfile = subfile->next)
1209 {
43f3e411
DE
1210 if (subfile == mainsub)
1211 continue;
0ba1096a 1212 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
4584e32e
DE
1213 {
1214 ++nr_matches;
1215 mainsub_alias = subfile;
1216 prev_mainsub_alias = prevsub;
1217 }
1218 prevsub = subfile;
1219 }
1220
1221 if (nr_matches == 1)
1222 {
43f3e411 1223 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
4584e32e
DE
1224
1225 /* Found a match for the main source file.
1226 Copy its line_vector and symtab to the main subfile
1227 and then discard it. */
1228
43f3e411
DE
1229 mainsub->line_vector = mainsub_alias->line_vector;
1230 mainsub->line_vector_length = mainsub_alias->line_vector_length;
1231 mainsub->symtab = mainsub_alias->symtab;
4584e32e
DE
1232
1233 if (prev_mainsub_alias == NULL)
4a2125f5 1234 subfiles = mainsub_alias->next;
4584e32e
DE
1235 else
1236 prev_mainsub_alias->next = mainsub_alias->next;
98387a29 1237 xfree (mainsub_alias->name);
4584e32e
DE
1238 xfree (mainsub_alias);
1239 }
1240 }
1241}
1242
4359dff1
JK
1243/* Implementation of the first part of end_symtab. It allows modifying
1244 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1245 If the returned value is NULL there is no blockvector created for
1246 this symtab (you still must call end_symtab_from_static_block).
c906108c 1247
4359dff1
JK
1248 END_ADDR is the same as for end_symtab: the address of the end of the
1249 file's text.
c906108c 1250
4359dff1 1251 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
36586728
TT
1252 expandable.
1253
1254 If REQUIRED is non-zero, then a symtab is created even if it does
1255 not contain any symbols. */
6d30eef8 1256
4359dff1 1257struct block *
4a2125f5
TT
1258buildsym_compunit::end_symtab_get_static_block (CORE_ADDR end_addr,
1259 int expandable, int required)
c906108c 1260{
c906108c
SS
1261 /* Finish the lexical context of the last function in the file; pop
1262 the context stack. */
1263
4a2125f5 1264 if (!m_context_stack.empty ())
c906108c 1265 {
a60f3166 1266 struct context_stack cstk = pop_context ();
4359dff1 1267
c906108c 1268 /* Make a block for the local symbols within. */
c233e9c6 1269 finish_block (cstk.name, cstk.old_blocks, NULL,
a60f3166 1270 cstk.start_addr, end_addr);
c906108c 1271
4a2125f5 1272 if (!m_context_stack.empty ())
c906108c
SS
1273 {
1274 /* This is said to happen with SCO. The old coffread.c
1275 code simply emptied the context stack, so we do the
1276 same. FIXME: Find out why it is happening. This is not
1277 believed to happen in most cases (even for coffread.c);
1278 it used to be an abort(). */
b98664d3 1279 complaint (_("Context stack not empty in end_symtab"));
4a2125f5 1280 m_context_stack.clear ();
c906108c
SS
1281 }
1282 }
1283
1284 /* Reordered executables may have out of order pending blocks; if
1285 OBJF_REORDERED is true, then sort the pending blocks. */
6d30eef8 1286
4a2125f5 1287 if ((objfile->flags & OBJF_REORDERED) && m_pending_blocks)
c906108c 1288 {
07e7f39f 1289 struct pending_block *pb;
c906108c 1290
b05628f0 1291 std::vector<block *> barray;
c906108c 1292
4a2125f5 1293 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 1294 barray.push_back (pb->block);
07e7f39f 1295
5033013f
UW
1296 /* Sort blocks by start address in descending order. Blocks with the
1297 same start address must remain in the original order to preserve
1298 inline function caller/callee relationships. */
1299 std::stable_sort (barray.begin (), barray.end (),
1300 [] (const block *a, const block *b)
1301 {
1302 return BLOCK_START (a) > BLOCK_START (b);
1303 });
07e7f39f 1304
b05628f0 1305 int i = 0;
4a2125f5 1306 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 1307 pb->block = barray[i++];
c906108c
SS
1308 }
1309
1310 /* Cleanup any undefined types that have been left hanging around
1311 (this needs to be done before the finish_blocks so that
1312 file_symbols is still good).
c5aa993b 1313
0a0edcd5 1314 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
c906108c
SS
1315 specific, but harmless for other symbol readers, since on gdb
1316 startup or when finished reading stabs, the state is set so these
1317 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1318 we make this cleaner? */
1319
0a0edcd5 1320 cleanup_undefined_stabs_types (objfile);
c906108c
SS
1321 finish_global_stabs (objfile);
1322
36586728 1323 if (!required
4a2125f5
TT
1324 && m_pending_blocks == NULL
1325 && m_file_symbols == NULL
1326 && m_global_symbols == NULL
1327 && !m_have_line_numbers
1328 && m_pending_macros == NULL
1329 && m_global_using_directives == NULL)
c906108c 1330 {
4359dff1
JK
1331 /* Ignore symtabs that have no functions with real debugging info. */
1332 return NULL;
1333 }
1334 else
1335 {
1336 /* Define the STATIC_BLOCK. */
e148f09d 1337 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
4a2125f5 1338 m_last_source_start_addr,
2c99ee5c 1339 end_addr, 0, expandable);
4359dff1
JK
1340 }
1341}
1342
7bab9b58
DE
1343/* Subroutine of end_symtab_from_static_block to simplify it.
1344 Handle the "have blockvector" case.
1345 See end_symtab_from_static_block for a description of the arguments. */
1346
4a2125f5
TT
1347struct compunit_symtab *
1348buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
1349 int section, int expandable)
4359dff1 1350{
4a2125f5 1351 struct compunit_symtab *cu = compunit_symtab;
7bab9b58 1352 struct symtab *symtab;
4359dff1
JK
1353 struct blockvector *blockvector;
1354 struct subfile *subfile;
7bab9b58 1355 CORE_ADDR end_addr;
4359dff1 1356
7bab9b58 1357 gdb_assert (static_block != NULL);
4a2125f5 1358 gdb_assert (subfiles != NULL);
7bab9b58
DE
1359
1360 end_addr = BLOCK_END (static_block);
1361
1362 /* Create the GLOBAL_BLOCK and build the blockvector. */
e148f09d 1363 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
4a2125f5 1364 m_last_source_start_addr, end_addr,
7bab9b58 1365 1, expandable);
43f3e411 1366 blockvector = make_blockvector ();
c906108c 1367
f56ce883
DE
1368 /* Read the line table if it has to be read separately.
1369 This is only used by xcoffread.c. */
c295b2e5 1370 if (objfile->sf->sym_read_linetable != NULL)
f56ce883 1371 objfile->sf->sym_read_linetable (objfile);
c906108c 1372
4584e32e
DE
1373 /* Handle the case where the debug info specifies a different path
1374 for the main source file. It can cause us to lose track of its
1375 line number information. */
1376 watch_main_source_file_lossage ();
1377
43f3e411
DE
1378 /* Now create the symtab objects proper, if not already done,
1379 one for each subfile. */
c906108c 1380
4a2125f5 1381 for (subfile = subfiles;
43f3e411
DE
1382 subfile != NULL;
1383 subfile = subfile->next)
c906108c
SS
1384 {
1385 int linetablesize = 0;
c906108c 1386
7bab9b58 1387 if (subfile->line_vector)
c906108c 1388 {
7bab9b58
DE
1389 linetablesize = sizeof (struct linetable) +
1390 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1391
1392 /* Like the pending blocks, the line table may be
1393 scrambled in reordered executables. Sort it if
1394 OBJF_REORDERED is true. */
1395 if (objfile->flags & OBJF_REORDERED)
1396 qsort (subfile->line_vector->item,
1397 subfile->line_vector->nitems,
1398 sizeof (struct linetable_entry), compare_line_numbers);
1399 }
9182c5bc 1400
7bab9b58
DE
1401 /* Allocate a symbol table if necessary. */
1402 if (subfile->symtab == NULL)
43f3e411 1403 subfile->symtab = allocate_symtab (cu, subfile->name);
7bab9b58 1404 symtab = subfile->symtab;
9182c5bc 1405
7bab9b58 1406 /* Fill in its components. */
43f3e411 1407
7bab9b58
DE
1408 if (subfile->line_vector)
1409 {
1410 /* Reallocate the line table on the symbol obstack. */
8435453b 1411 SYMTAB_LINETABLE (symtab) = (struct linetable *)
7bab9b58 1412 obstack_alloc (&objfile->objfile_obstack, linetablesize);
8435453b
DE
1413 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1414 linetablesize);
c906108c 1415 }
24be086d 1416 else
c906108c 1417 {
8435453b 1418 SYMTAB_LINETABLE (symtab) = NULL;
c906108c 1419 }
c906108c 1420
7bab9b58
DE
1421 /* Use whatever language we have been using for this
1422 subfile, not the one that was deduced in allocate_symtab
1423 from the filename. We already did our own deducing when
1424 we created the subfile, and we may have altered our
1425 opinion of what language it is from things we found in
1426 the symbols. */
1427 symtab->language = subfile->language;
43f3e411 1428 }
c906108c 1429
43f3e411
DE
1430 /* Make sure the symtab of main_subfile is the first in its list. */
1431 {
1432 struct symtab *main_symtab, *prev_symtab;
1433
4a2125f5 1434 main_symtab = main_subfile->symtab;
43f3e411
DE
1435 prev_symtab = NULL;
1436 ALL_COMPUNIT_FILETABS (cu, symtab)
1437 {
1438 if (symtab == main_symtab)
1439 {
1440 if (prev_symtab != NULL)
1441 {
1442 prev_symtab->next = main_symtab->next;
1443 main_symtab->next = COMPUNIT_FILETABS (cu);
1444 COMPUNIT_FILETABS (cu) = main_symtab;
1445 }
1446 break;
1447 }
1448 prev_symtab = symtab;
1449 }
1450 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1451 }
84a146c9 1452
0ab9ce85 1453 /* Fill out the compunit symtab. */
84a146c9 1454
4a2125f5 1455 if (comp_dir != NULL)
43f3e411
DE
1456 {
1457 /* Reallocate the dirname on the symbol obstack. */
4a2125f5 1458 const char *comp_dir = this->comp_dir.get ();
43f3e411 1459 COMPUNIT_DIRNAME (cu)
224c3ddb 1460 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
905eb0e2 1461 comp_dir, strlen (comp_dir));
c906108c
SS
1462 }
1463
43f3e411 1464 /* Save the debug format string (if any) in the symtab. */
4a2125f5 1465 COMPUNIT_DEBUGFORMAT (cu) = debugformat;
43f3e411
DE
1466
1467 /* Similarly for the producer. */
4a2125f5 1468 COMPUNIT_PRODUCER (cu) = producer;
43f3e411
DE
1469
1470 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
7bab9b58 1471 {
43f3e411 1472 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
cb1df416 1473
43f3e411 1474 set_block_compunit_symtab (b, cu);
7bab9b58 1475 }
cb1df416 1476
43f3e411
DE
1477 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1478
4a2125f5 1479 COMPUNIT_MACRO_TABLE (cu) = release_macros ();
43f3e411 1480
7bab9b58
DE
1481 /* Default any symbols without a specified symtab to the primary symtab. */
1482 {
1483 int block_i;
1484
43f3e411
DE
1485 /* The main source file's symtab. */
1486 symtab = COMPUNIT_FILETABS (cu);
1487
7bab9b58
DE
1488 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1489 {
1490 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1491 struct symbol *sym;
1492 struct dict_iterator iter;
1493
1494 /* Inlined functions may have symbols not in the global or
1495 static symbol lists. */
1496 if (BLOCK_FUNCTION (block) != NULL)
08be3fe3
DE
1497 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1498 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
7bab9b58
DE
1499
1500 /* Note that we only want to fix up symbols from the local
1501 blocks, not blocks coming from included symtabs. That is why
1502 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1503 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
08be3fe3
DE
1504 if (symbol_symtab (sym) == NULL)
1505 symbol_set_symtab (sym, symtab);
7bab9b58
DE
1506 }
1507 }
edb3359d 1508
43f3e411 1509 add_compunit_symtab_to_objfile (cu);
43f3e411
DE
1510
1511 return cu;
7bab9b58
DE
1512}
1513
1514/* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1515 as value returned by end_symtab_get_static_block.
1516
1517 SECTION is the same as for end_symtab: the section number
1518 (in objfile->section_offsets) of the blockvector and linetable.
1519
1520 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1521 expandable. */
1522
43f3e411 1523struct compunit_symtab *
4a2125f5
TT
1524buildsym_compunit::end_symtab_from_static_block (struct block *static_block,
1525 int section, int expandable)
7bab9b58 1526{
43f3e411 1527 struct compunit_symtab *cu;
7bab9b58
DE
1528
1529 if (static_block == NULL)
1530 {
0ab9ce85
DE
1531 /* Handle the "no blockvector" case.
1532 When this happens there is nothing to record, so there's nothing
1533 to do: memory will be freed up later.
1534
1535 Note: We won't be adding a compunit to the objfile's list of
1536 compunits, so there's nothing to unchain. However, since each symtab
1537 is added to the objfile's obstack we can't free that space.
1538 We could do better, but this is believed to be a sufficiently rare
1539 event. */
43f3e411 1540 cu = NULL;
7bab9b58
DE
1541 }
1542 else
43f3e411 1543 cu = end_symtab_with_blockvector (static_block, section, expandable);
cb1df416 1544
43f3e411 1545 return cu;
6d30eef8
DE
1546}
1547
4359dff1
JK
1548/* Finish the symbol definitions for one main source file, close off
1549 all the lexical contexts for that file (creating struct block's for
1550 them), then make the struct symtab for that file and put it in the
1551 list of all such.
1552
1553 END_ADDR is the address of the end of the file's text. SECTION is
1554 the section number (in objfile->section_offsets) of the blockvector
1555 and linetable.
1556
1557 Note that it is possible for end_symtab() to return NULL. In
1558 particular, for the DWARF case at least, it will return NULL when
1559 it finds a compilation unit that has exactly one DIE, a
1560 TAG_compile_unit DIE. This can happen when we link in an object
1561 file that was compiled from an empty source file. Returning NULL
1562 is probably not the correct thing to do, because then gdb will
1563 never know about this empty file (FIXME).
1564
1565 If you need to modify STATIC_BLOCK before it is finalized you should
1566 call end_symtab_get_static_block and end_symtab_from_static_block
1567 yourself. */
6d30eef8 1568
43f3e411 1569struct compunit_symtab *
4a2125f5 1570buildsym_compunit::end_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1571{
4359dff1
JK
1572 struct block *static_block;
1573
4d663531
DE
1574 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1575 return end_symtab_from_static_block (static_block, section, 0);
6d30eef8
DE
1576}
1577
4359dff1 1578/* Same as end_symtab except create a symtab that can be later added to. */
6d30eef8 1579
43f3e411 1580struct compunit_symtab *
4a2125f5 1581buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1582{
4359dff1
JK
1583 struct block *static_block;
1584
4d663531
DE
1585 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1586 return end_symtab_from_static_block (static_block, section, 1);
6d30eef8
DE
1587}
1588
1589/* Subroutine of augment_type_symtab to simplify it.
43f3e411
DE
1590 Attach the main source file's symtab to all symbols in PENDING_LIST that
1591 don't have one. */
6d30eef8
DE
1592
1593static void
43f3e411
DE
1594set_missing_symtab (struct pending *pending_list,
1595 struct compunit_symtab *cu)
6d30eef8
DE
1596{
1597 struct pending *pending;
1598 int i;
1599
1600 for (pending = pending_list; pending != NULL; pending = pending->next)
801e3a5b 1601 {
6d30eef8
DE
1602 for (i = 0; i < pending->nsyms; ++i)
1603 {
08be3fe3
DE
1604 if (symbol_symtab (pending->symbol[i]) == NULL)
1605 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
6d30eef8 1606 }
801e3a5b 1607 }
6d30eef8 1608}
c906108c 1609
6d30eef8
DE
1610/* Same as end_symtab, but for the case where we're adding more symbols
1611 to an existing symtab that is known to contain only type information.
1612 This is the case for DWARF4 Type Units. */
1613
1614void
4a2125f5 1615buildsym_compunit::augment_type_symtab ()
6d30eef8 1616{
4a2125f5 1617 struct compunit_symtab *cust = compunit_symtab;
43f3e411 1618 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
6d30eef8 1619
4a2125f5 1620 if (!m_context_stack.empty ())
a60f3166 1621 complaint (_("Context stack not empty in augment_type_symtab"));
4a2125f5 1622 if (m_pending_blocks != NULL)
b98664d3 1623 complaint (_("Blocks in a type symtab"));
4a2125f5 1624 if (m_pending_macros != NULL)
b98664d3 1625 complaint (_("Macro in a type symtab"));
4a2125f5 1626 if (m_have_line_numbers)
b98664d3 1627 complaint (_("Line numbers recorded in a type symtab"));
6d30eef8 1628
4a2125f5 1629 if (m_file_symbols != NULL)
6d30eef8
DE
1630 {
1631 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1632
1633 /* First mark any symbols without a specified symtab as belonging
1634 to the primary symtab. */
4a2125f5 1635 set_missing_symtab (m_file_symbols, cust);
6d30eef8 1636
4a2125f5 1637 dict_add_pending (BLOCK_DICT (block), m_file_symbols);
6d30eef8
DE
1638 }
1639
4a2125f5 1640 if (m_global_symbols != NULL)
6d30eef8
DE
1641 {
1642 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1643
1644 /* First mark any symbols without a specified symtab as belonging
1645 to the primary symtab. */
4a2125f5 1646 set_missing_symtab (m_global_symbols, cust);
6d30eef8 1647
e148f09d 1648 dict_add_pending (BLOCK_DICT (block),
4a2125f5 1649 m_global_symbols);
6d30eef8 1650 }
c906108c
SS
1651}
1652
1653/* Push a context block. Args are an identifying nesting level
1654 (checkable when you pop it), and the starting PC address of this
1655 context. */
1656
1657struct context_stack *
4a2125f5 1658buildsym_compunit::push_context (int desc, CORE_ADDR valu)
c906108c 1659{
4a2125f5
TT
1660 m_context_stack.emplace_back ();
1661 struct context_stack *newobj = &m_context_stack.back ();
c906108c 1662
fe978cb0 1663 newobj->depth = desc;
4a2125f5
TT
1664 newobj->locals = m_local_symbols;
1665 newobj->old_blocks = m_pending_blocks;
fe978cb0 1666 newobj->start_addr = valu;
4a2125f5 1667 newobj->local_using_directives = m_local_using_directives;
fe978cb0 1668 newobj->name = NULL;
c906108c 1669
4a2125f5
TT
1670 m_local_symbols = NULL;
1671 m_local_using_directives = NULL;
c906108c 1672
fe978cb0 1673 return newobj;
c906108c 1674}
0c5e171a 1675
a672ef13 1676/* Pop a context block. Returns the address of the context block just
4a64f543 1677 popped. */
a672ef13 1678
a60f3166 1679struct context_stack
4a2125f5 1680buildsym_compunit::pop_context ()
0c5e171a 1681{
4a2125f5
TT
1682 gdb_assert (!m_context_stack.empty ());
1683 struct context_stack result = m_context_stack.back ();
1684 m_context_stack.pop_back ();
a60f3166 1685 return result;
0c5e171a
KD
1686}
1687
c906108c 1688\f
357e46e7 1689
c906108c 1690void
554d387d 1691record_debugformat (const char *format)
c906108c 1692{
4a2125f5 1693 buildsym_compunit->record_debugformat (format);
c906108c
SS
1694}
1695
303b6f5d
DJ
1696void
1697record_producer (const char *producer)
1698{
4a2125f5 1699 buildsym_compunit->record_producer (producer);
303b6f5d
DJ
1700}
1701
c906108c 1702\f
46212e0b 1703
46212e0b
TT
1704/* See buildsym.h. */
1705
1706void
1707set_last_source_file (const char *name)
1708{
c0015d44
TT
1709 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1710 if (buildsym_compunit != nullptr)
1711 buildsym_compunit->set_last_source_file (name);
46212e0b
TT
1712}
1713
1714/* See buildsym.h. */
1715
1716const char *
4a2125f5 1717get_last_source_file ()
46212e0b 1718{
c0015d44
TT
1719 if (buildsym_compunit == nullptr)
1720 return nullptr;
4a2125f5 1721 return buildsym_compunit->get_last_source_file ();
46212e0b
TT
1722}
1723
2c99ee5c
TT
1724/* See buildsym.h. */
1725
1726void
1727set_last_source_start_addr (CORE_ADDR addr)
1728{
1729 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1730 buildsym_compunit->set_last_source_start_addr (addr);
2c99ee5c
TT
1731}
1732
1733/* See buildsym.h. */
1734
1735CORE_ADDR
1736get_last_source_start_addr ()
1737{
1738 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1739 return buildsym_compunit->get_last_source_start_addr ();
2c99ee5c
TT
1740}
1741
6cccc9a8
TT
1742/* See buildsym.h. */
1743
1744struct using_direct **
1745get_local_using_directives ()
1746{
1747 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1748 return buildsym_compunit->get_local_using_directives ();
6cccc9a8
TT
1749}
1750
1751/* See buildsym.h. */
1752
1753void
1754set_local_using_directives (struct using_direct *new_local)
1755{
1756 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1757 buildsym_compunit->set_local_using_directives (new_local);
6cccc9a8
TT
1758}
1759
1760/* See buildsym.h. */
1761
1762struct using_direct **
1763get_global_using_directives ()
1764{
1765 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1766 return buildsym_compunit->get_global_using_directives ();
6cccc9a8
TT
1767}
1768
a60f3166
TT
1769/* See buildsym.h. */
1770
1771bool
1772outermost_context_p ()
1773{
1774 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1775 return buildsym_compunit->outermost_context_p ();
a60f3166
TT
1776}
1777
1778/* See buildsym.h. */
1779
1780struct context_stack *
1781get_current_context_stack ()
1782{
1783 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1784 return buildsym_compunit->get_current_context_stack ();
a60f3166
TT
1785}
1786
1787/* See buildsym.h. */
1788
1789int
1790get_context_stack_depth ()
1791{
1792 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1793 return buildsym_compunit->get_context_stack_depth ();
a60f3166
TT
1794}
1795
3c65e5b3
TT
1796/* See buildsym.h. */
1797
1798struct subfile *
1799get_current_subfile ()
1800{
1801 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1802 return buildsym_compunit->get_current_subfile ();
3c65e5b3
TT
1803}
1804
e148f09d
TT
1805/* See buildsym.h. */
1806
1807struct pending **
1808get_local_symbols ()
1809{
1810 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1811 return buildsym_compunit->get_local_symbols ();
e148f09d
TT
1812}
1813
1814/* See buildsym.h. */
1815
1816struct pending **
1817get_file_symbols ()
1818{
1819 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1820 return buildsym_compunit->get_file_symbols ();
e148f09d
TT
1821}
1822
1823/* See buildsym.h. */
1824
1825struct pending **
1826get_global_symbols ()
1827{
1828 gdb_assert (buildsym_compunit != nullptr);
4a2125f5
TT
1829 return buildsym_compunit->get_global_symbols ();
1830}
1831
1832void
1833start_subfile (const char *name)
1834{
1835 gdb_assert (buildsym_compunit != nullptr);
1836 buildsym_compunit->start_subfile (name);
1837}
1838
1839void
1840patch_subfile_names (struct subfile *subfile, const char *name)
1841{
1842 gdb_assert (buildsym_compunit != nullptr);
1843 buildsym_compunit->patch_subfile_names (subfile, name);
1844}
1845
1846void
1847push_subfile ()
1848{
1849 gdb_assert (buildsym_compunit != nullptr);
1850 buildsym_compunit->push_subfile ();
1851}
1852
1853const char *
1854pop_subfile ()
1855{
1856 gdb_assert (buildsym_compunit != nullptr);
1857 return buildsym_compunit->pop_subfile ();
1858}
1859
1860struct block *
1861end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1862{
1863 gdb_assert (buildsym_compunit != nullptr);
1864 return buildsym_compunit->end_symtab_get_static_block (end_addr, expandable,
1865 required);
1866}
1867
1868struct compunit_symtab *
1869end_symtab_from_static_block (struct block *static_block,
1870 int section, int expandable)
1871{
1872 gdb_assert (buildsym_compunit != nullptr);
1873 struct compunit_symtab *result
1874 = buildsym_compunit->end_symtab_from_static_block (static_block,
1875 section, expandable);
74c72eac 1876 free_buildsym_compunit ();
4a2125f5
TT
1877 return result;
1878}
1879
1880struct compunit_symtab *
1881end_symtab (CORE_ADDR end_addr, int section)
1882{
1883 gdb_assert (buildsym_compunit != nullptr);
1884 struct compunit_symtab *result
1885 = buildsym_compunit->end_symtab (end_addr, section);
74c72eac 1886 free_buildsym_compunit ();
4a2125f5
TT
1887 return result;
1888}
1889
1890struct compunit_symtab *
1891end_expandable_symtab (CORE_ADDR end_addr, int section)
1892{
1893 gdb_assert (buildsym_compunit != nullptr);
1894 struct compunit_symtab *result
1895 = buildsym_compunit->end_expandable_symtab (end_addr, section);
74c72eac 1896 free_buildsym_compunit ();
4a2125f5
TT
1897 return result;
1898}
1899
1900void
1901augment_type_symtab ()
1902{
1903 gdb_assert (buildsym_compunit != nullptr);
1904 buildsym_compunit->augment_type_symtab ();
74c72eac 1905 free_buildsym_compunit ();
4a2125f5
TT
1906}
1907
1908struct context_stack *
1909push_context (int desc, CORE_ADDR valu)
1910{
1911 gdb_assert (buildsym_compunit != nullptr);
1912 return buildsym_compunit->push_context (desc, valu);
1913}
1914
1915struct context_stack
1916pop_context ()
1917{
1918 gdb_assert (buildsym_compunit != nullptr);
1919 return buildsym_compunit->pop_context ();
1920}
1921
1922struct block *
1923finish_block (struct symbol *symbol, struct pending_block *old_blocks,
1924 const struct dynamic_prop *static_link,
1925 CORE_ADDR start, CORE_ADDR end)
1926{
1927 gdb_assert (buildsym_compunit != nullptr);
1928 return buildsym_compunit->finish_block (symbol, old_blocks, static_link,
1929 start, end);
1930}
1931
1932void
1933record_block_range (struct block *block, CORE_ADDR start,
1934 CORE_ADDR end_inclusive)
1935{
1936 gdb_assert (buildsym_compunit != nullptr);
1937 buildsym_compunit->record_block_range (block, start, end_inclusive);
1938}
1939
1940void
1941record_line (struct subfile *subfile, int line, CORE_ADDR pc)
1942{
1943 gdb_assert (buildsym_compunit != nullptr);
1944 buildsym_compunit->record_line (subfile, line, pc);
e148f09d 1945}
This page took 1.837393 seconds and 4 git commands to generate.