Add many methods to buildsym_compunit
[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
b37dd3bc 1243/* Reset state after a successful building of a symtab. */
6d30eef8
DE
1244
1245static void
1246reset_symtab_globals (void)
1247{
0ab9ce85 1248 free_buildsym_compunit ();
6d30eef8
DE
1249}
1250
4359dff1
JK
1251/* Implementation of the first part of end_symtab. It allows modifying
1252 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1253 If the returned value is NULL there is no blockvector created for
1254 this symtab (you still must call end_symtab_from_static_block).
c906108c 1255
4359dff1
JK
1256 END_ADDR is the same as for end_symtab: the address of the end of the
1257 file's text.
c906108c 1258
4359dff1 1259 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
36586728
TT
1260 expandable.
1261
1262 If REQUIRED is non-zero, then a symtab is created even if it does
1263 not contain any symbols. */
6d30eef8 1264
4359dff1 1265struct block *
4a2125f5
TT
1266buildsym_compunit::end_symtab_get_static_block (CORE_ADDR end_addr,
1267 int expandable, int required)
c906108c 1268{
c906108c
SS
1269 /* Finish the lexical context of the last function in the file; pop
1270 the context stack. */
1271
4a2125f5 1272 if (!m_context_stack.empty ())
c906108c 1273 {
a60f3166 1274 struct context_stack cstk = pop_context ();
4359dff1 1275
c906108c 1276 /* Make a block for the local symbols within. */
c233e9c6 1277 finish_block (cstk.name, cstk.old_blocks, NULL,
a60f3166 1278 cstk.start_addr, end_addr);
c906108c 1279
4a2125f5 1280 if (!m_context_stack.empty ())
c906108c
SS
1281 {
1282 /* This is said to happen with SCO. The old coffread.c
1283 code simply emptied the context stack, so we do the
1284 same. FIXME: Find out why it is happening. This is not
1285 believed to happen in most cases (even for coffread.c);
1286 it used to be an abort(). */
b98664d3 1287 complaint (_("Context stack not empty in end_symtab"));
4a2125f5 1288 m_context_stack.clear ();
c906108c
SS
1289 }
1290 }
1291
1292 /* Reordered executables may have out of order pending blocks; if
1293 OBJF_REORDERED is true, then sort the pending blocks. */
6d30eef8 1294
4a2125f5 1295 if ((objfile->flags & OBJF_REORDERED) && m_pending_blocks)
c906108c 1296 {
07e7f39f 1297 struct pending_block *pb;
c906108c 1298
b05628f0 1299 std::vector<block *> barray;
c906108c 1300
4a2125f5 1301 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 1302 barray.push_back (pb->block);
07e7f39f 1303
5033013f
UW
1304 /* Sort blocks by start address in descending order. Blocks with the
1305 same start address must remain in the original order to preserve
1306 inline function caller/callee relationships. */
1307 std::stable_sort (barray.begin (), barray.end (),
1308 [] (const block *a, const block *b)
1309 {
1310 return BLOCK_START (a) > BLOCK_START (b);
1311 });
07e7f39f 1312
b05628f0 1313 int i = 0;
4a2125f5 1314 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 1315 pb->block = barray[i++];
c906108c
SS
1316 }
1317
1318 /* Cleanup any undefined types that have been left hanging around
1319 (this needs to be done before the finish_blocks so that
1320 file_symbols is still good).
c5aa993b 1321
0a0edcd5 1322 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
c906108c
SS
1323 specific, but harmless for other symbol readers, since on gdb
1324 startup or when finished reading stabs, the state is set so these
1325 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1326 we make this cleaner? */
1327
0a0edcd5 1328 cleanup_undefined_stabs_types (objfile);
c906108c
SS
1329 finish_global_stabs (objfile);
1330
36586728 1331 if (!required
4a2125f5
TT
1332 && m_pending_blocks == NULL
1333 && m_file_symbols == NULL
1334 && m_global_symbols == NULL
1335 && !m_have_line_numbers
1336 && m_pending_macros == NULL
1337 && m_global_using_directives == NULL)
c906108c 1338 {
4359dff1
JK
1339 /* Ignore symtabs that have no functions with real debugging info. */
1340 return NULL;
1341 }
1342 else
1343 {
1344 /* Define the STATIC_BLOCK. */
e148f09d 1345 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
4a2125f5 1346 m_last_source_start_addr,
2c99ee5c 1347 end_addr, 0, expandable);
4359dff1
JK
1348 }
1349}
1350
7bab9b58
DE
1351/* Subroutine of end_symtab_from_static_block to simplify it.
1352 Handle the "have blockvector" case.
1353 See end_symtab_from_static_block for a description of the arguments. */
1354
4a2125f5
TT
1355struct compunit_symtab *
1356buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
1357 int section, int expandable)
4359dff1 1358{
4a2125f5 1359 struct compunit_symtab *cu = compunit_symtab;
7bab9b58 1360 struct symtab *symtab;
4359dff1
JK
1361 struct blockvector *blockvector;
1362 struct subfile *subfile;
7bab9b58 1363 CORE_ADDR end_addr;
4359dff1 1364
7bab9b58 1365 gdb_assert (static_block != NULL);
4a2125f5 1366 gdb_assert (subfiles != NULL);
7bab9b58
DE
1367
1368 end_addr = BLOCK_END (static_block);
1369
1370 /* Create the GLOBAL_BLOCK and build the blockvector. */
e148f09d 1371 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
4a2125f5 1372 m_last_source_start_addr, end_addr,
7bab9b58 1373 1, expandable);
43f3e411 1374 blockvector = make_blockvector ();
c906108c 1375
f56ce883
DE
1376 /* Read the line table if it has to be read separately.
1377 This is only used by xcoffread.c. */
c295b2e5 1378 if (objfile->sf->sym_read_linetable != NULL)
f56ce883 1379 objfile->sf->sym_read_linetable (objfile);
c906108c 1380
4584e32e
DE
1381 /* Handle the case where the debug info specifies a different path
1382 for the main source file. It can cause us to lose track of its
1383 line number information. */
1384 watch_main_source_file_lossage ();
1385
43f3e411
DE
1386 /* Now create the symtab objects proper, if not already done,
1387 one for each subfile. */
c906108c 1388
4a2125f5 1389 for (subfile = subfiles;
43f3e411
DE
1390 subfile != NULL;
1391 subfile = subfile->next)
c906108c
SS
1392 {
1393 int linetablesize = 0;
c906108c 1394
7bab9b58 1395 if (subfile->line_vector)
c906108c 1396 {
7bab9b58
DE
1397 linetablesize = sizeof (struct linetable) +
1398 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1399
1400 /* Like the pending blocks, the line table may be
1401 scrambled in reordered executables. Sort it if
1402 OBJF_REORDERED is true. */
1403 if (objfile->flags & OBJF_REORDERED)
1404 qsort (subfile->line_vector->item,
1405 subfile->line_vector->nitems,
1406 sizeof (struct linetable_entry), compare_line_numbers);
1407 }
9182c5bc 1408
7bab9b58
DE
1409 /* Allocate a symbol table if necessary. */
1410 if (subfile->symtab == NULL)
43f3e411 1411 subfile->symtab = allocate_symtab (cu, subfile->name);
7bab9b58 1412 symtab = subfile->symtab;
9182c5bc 1413
7bab9b58 1414 /* Fill in its components. */
43f3e411 1415
7bab9b58
DE
1416 if (subfile->line_vector)
1417 {
1418 /* Reallocate the line table on the symbol obstack. */
8435453b 1419 SYMTAB_LINETABLE (symtab) = (struct linetable *)
7bab9b58 1420 obstack_alloc (&objfile->objfile_obstack, linetablesize);
8435453b
DE
1421 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1422 linetablesize);
c906108c 1423 }
24be086d 1424 else
c906108c 1425 {
8435453b 1426 SYMTAB_LINETABLE (symtab) = NULL;
c906108c 1427 }
c906108c 1428
7bab9b58
DE
1429 /* Use whatever language we have been using for this
1430 subfile, not the one that was deduced in allocate_symtab
1431 from the filename. We already did our own deducing when
1432 we created the subfile, and we may have altered our
1433 opinion of what language it is from things we found in
1434 the symbols. */
1435 symtab->language = subfile->language;
43f3e411 1436 }
c906108c 1437
43f3e411
DE
1438 /* Make sure the symtab of main_subfile is the first in its list. */
1439 {
1440 struct symtab *main_symtab, *prev_symtab;
1441
4a2125f5 1442 main_symtab = main_subfile->symtab;
43f3e411
DE
1443 prev_symtab = NULL;
1444 ALL_COMPUNIT_FILETABS (cu, symtab)
1445 {
1446 if (symtab == main_symtab)
1447 {
1448 if (prev_symtab != NULL)
1449 {
1450 prev_symtab->next = main_symtab->next;
1451 main_symtab->next = COMPUNIT_FILETABS (cu);
1452 COMPUNIT_FILETABS (cu) = main_symtab;
1453 }
1454 break;
1455 }
1456 prev_symtab = symtab;
1457 }
1458 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1459 }
84a146c9 1460
0ab9ce85 1461 /* Fill out the compunit symtab. */
84a146c9 1462
4a2125f5 1463 if (comp_dir != NULL)
43f3e411
DE
1464 {
1465 /* Reallocate the dirname on the symbol obstack. */
4a2125f5 1466 const char *comp_dir = this->comp_dir.get ();
43f3e411 1467 COMPUNIT_DIRNAME (cu)
224c3ddb 1468 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
905eb0e2 1469 comp_dir, strlen (comp_dir));
c906108c
SS
1470 }
1471
43f3e411 1472 /* Save the debug format string (if any) in the symtab. */
4a2125f5 1473 COMPUNIT_DEBUGFORMAT (cu) = debugformat;
43f3e411
DE
1474
1475 /* Similarly for the producer. */
4a2125f5 1476 COMPUNIT_PRODUCER (cu) = producer;
43f3e411
DE
1477
1478 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
7bab9b58 1479 {
43f3e411 1480 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
cb1df416 1481
43f3e411 1482 set_block_compunit_symtab (b, cu);
7bab9b58 1483 }
cb1df416 1484
43f3e411
DE
1485 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1486
4a2125f5 1487 COMPUNIT_MACRO_TABLE (cu) = release_macros ();
43f3e411 1488
7bab9b58
DE
1489 /* Default any symbols without a specified symtab to the primary symtab. */
1490 {
1491 int block_i;
1492
43f3e411
DE
1493 /* The main source file's symtab. */
1494 symtab = COMPUNIT_FILETABS (cu);
1495
7bab9b58
DE
1496 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1497 {
1498 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1499 struct symbol *sym;
1500 struct dict_iterator iter;
1501
1502 /* Inlined functions may have symbols not in the global or
1503 static symbol lists. */
1504 if (BLOCK_FUNCTION (block) != NULL)
08be3fe3
DE
1505 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1506 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
7bab9b58
DE
1507
1508 /* Note that we only want to fix up symbols from the local
1509 blocks, not blocks coming from included symtabs. That is why
1510 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1511 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
08be3fe3
DE
1512 if (symbol_symtab (sym) == NULL)
1513 symbol_set_symtab (sym, symtab);
7bab9b58
DE
1514 }
1515 }
edb3359d 1516
43f3e411 1517 add_compunit_symtab_to_objfile (cu);
43f3e411
DE
1518
1519 return cu;
7bab9b58
DE
1520}
1521
1522/* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1523 as value returned by end_symtab_get_static_block.
1524
1525 SECTION is the same as for end_symtab: the section number
1526 (in objfile->section_offsets) of the blockvector and linetable.
1527
1528 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1529 expandable. */
1530
43f3e411 1531struct compunit_symtab *
4a2125f5
TT
1532buildsym_compunit::end_symtab_from_static_block (struct block *static_block,
1533 int section, int expandable)
7bab9b58 1534{
43f3e411 1535 struct compunit_symtab *cu;
7bab9b58
DE
1536
1537 if (static_block == NULL)
1538 {
0ab9ce85
DE
1539 /* Handle the "no blockvector" case.
1540 When this happens there is nothing to record, so there's nothing
1541 to do: memory will be freed up later.
1542
1543 Note: We won't be adding a compunit to the objfile's list of
1544 compunits, so there's nothing to unchain. However, since each symtab
1545 is added to the objfile's obstack we can't free that space.
1546 We could do better, but this is believed to be a sufficiently rare
1547 event. */
43f3e411 1548 cu = NULL;
7bab9b58
DE
1549 }
1550 else
43f3e411 1551 cu = end_symtab_with_blockvector (static_block, section, expandable);
cb1df416 1552
6d30eef8
DE
1553 reset_symtab_globals ();
1554
43f3e411 1555 return cu;
6d30eef8
DE
1556}
1557
4359dff1
JK
1558/* Finish the symbol definitions for one main source file, close off
1559 all the lexical contexts for that file (creating struct block's for
1560 them), then make the struct symtab for that file and put it in the
1561 list of all such.
1562
1563 END_ADDR is the address of the end of the file's text. SECTION is
1564 the section number (in objfile->section_offsets) of the blockvector
1565 and linetable.
1566
1567 Note that it is possible for end_symtab() to return NULL. In
1568 particular, for the DWARF case at least, it will return NULL when
1569 it finds a compilation unit that has exactly one DIE, a
1570 TAG_compile_unit DIE. This can happen when we link in an object
1571 file that was compiled from an empty source file. Returning NULL
1572 is probably not the correct thing to do, because then gdb will
1573 never know about this empty file (FIXME).
1574
1575 If you need to modify STATIC_BLOCK before it is finalized you should
1576 call end_symtab_get_static_block and end_symtab_from_static_block
1577 yourself. */
6d30eef8 1578
43f3e411 1579struct compunit_symtab *
4a2125f5 1580buildsym_compunit::end_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1581{
4359dff1
JK
1582 struct block *static_block;
1583
4d663531
DE
1584 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1585 return end_symtab_from_static_block (static_block, section, 0);
6d30eef8
DE
1586}
1587
4359dff1 1588/* Same as end_symtab except create a symtab that can be later added to. */
6d30eef8 1589
43f3e411 1590struct compunit_symtab *
4a2125f5 1591buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1592{
4359dff1
JK
1593 struct block *static_block;
1594
4d663531
DE
1595 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1596 return end_symtab_from_static_block (static_block, section, 1);
6d30eef8
DE
1597}
1598
1599/* Subroutine of augment_type_symtab to simplify it.
43f3e411
DE
1600 Attach the main source file's symtab to all symbols in PENDING_LIST that
1601 don't have one. */
6d30eef8
DE
1602
1603static void
43f3e411
DE
1604set_missing_symtab (struct pending *pending_list,
1605 struct compunit_symtab *cu)
6d30eef8
DE
1606{
1607 struct pending *pending;
1608 int i;
1609
1610 for (pending = pending_list; pending != NULL; pending = pending->next)
801e3a5b 1611 {
6d30eef8
DE
1612 for (i = 0; i < pending->nsyms; ++i)
1613 {
08be3fe3
DE
1614 if (symbol_symtab (pending->symbol[i]) == NULL)
1615 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
6d30eef8 1616 }
801e3a5b 1617 }
6d30eef8 1618}
c906108c 1619
6d30eef8
DE
1620/* Same as end_symtab, but for the case where we're adding more symbols
1621 to an existing symtab that is known to contain only type information.
1622 This is the case for DWARF4 Type Units. */
1623
1624void
4a2125f5 1625buildsym_compunit::augment_type_symtab ()
6d30eef8 1626{
4a2125f5 1627 struct compunit_symtab *cust = compunit_symtab;
43f3e411 1628 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
6d30eef8 1629
4a2125f5 1630 if (!m_context_stack.empty ())
a60f3166 1631 complaint (_("Context stack not empty in augment_type_symtab"));
4a2125f5 1632 if (m_pending_blocks != NULL)
b98664d3 1633 complaint (_("Blocks in a type symtab"));
4a2125f5 1634 if (m_pending_macros != NULL)
b98664d3 1635 complaint (_("Macro in a type symtab"));
4a2125f5 1636 if (m_have_line_numbers)
b98664d3 1637 complaint (_("Line numbers recorded in a type symtab"));
6d30eef8 1638
4a2125f5 1639 if (m_file_symbols != NULL)
6d30eef8
DE
1640 {
1641 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1642
1643 /* First mark any symbols without a specified symtab as belonging
1644 to the primary symtab. */
4a2125f5 1645 set_missing_symtab (m_file_symbols, cust);
6d30eef8 1646
4a2125f5 1647 dict_add_pending (BLOCK_DICT (block), m_file_symbols);
6d30eef8
DE
1648 }
1649
4a2125f5 1650 if (m_global_symbols != NULL)
6d30eef8
DE
1651 {
1652 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1653
1654 /* First mark any symbols without a specified symtab as belonging
1655 to the primary symtab. */
4a2125f5 1656 set_missing_symtab (m_global_symbols, cust);
6d30eef8 1657
e148f09d 1658 dict_add_pending (BLOCK_DICT (block),
4a2125f5 1659 m_global_symbols);
6d30eef8
DE
1660 }
1661
1662 reset_symtab_globals ();
c906108c
SS
1663}
1664
1665/* Push a context block. Args are an identifying nesting level
1666 (checkable when you pop it), and the starting PC address of this
1667 context. */
1668
1669struct context_stack *
4a2125f5 1670buildsym_compunit::push_context (int desc, CORE_ADDR valu)
c906108c 1671{
4a2125f5
TT
1672 m_context_stack.emplace_back ();
1673 struct context_stack *newobj = &m_context_stack.back ();
c906108c 1674
fe978cb0 1675 newobj->depth = desc;
4a2125f5
TT
1676 newobj->locals = m_local_symbols;
1677 newobj->old_blocks = m_pending_blocks;
fe978cb0 1678 newobj->start_addr = valu;
4a2125f5 1679 newobj->local_using_directives = m_local_using_directives;
fe978cb0 1680 newobj->name = NULL;
c906108c 1681
4a2125f5
TT
1682 m_local_symbols = NULL;
1683 m_local_using_directives = NULL;
c906108c 1684
fe978cb0 1685 return newobj;
c906108c 1686}
0c5e171a 1687
a672ef13 1688/* Pop a context block. Returns the address of the context block just
4a64f543 1689 popped. */
a672ef13 1690
a60f3166 1691struct context_stack
4a2125f5 1692buildsym_compunit::pop_context ()
0c5e171a 1693{
4a2125f5
TT
1694 gdb_assert (!m_context_stack.empty ());
1695 struct context_stack result = m_context_stack.back ();
1696 m_context_stack.pop_back ();
a60f3166 1697 return result;
0c5e171a
KD
1698}
1699
c906108c 1700\f
357e46e7 1701
c906108c 1702void
554d387d 1703record_debugformat (const char *format)
c906108c 1704{
4a2125f5 1705 buildsym_compunit->record_debugformat (format);
c906108c
SS
1706}
1707
303b6f5d
DJ
1708void
1709record_producer (const char *producer)
1710{
4a2125f5 1711 buildsym_compunit->record_producer (producer);
303b6f5d
DJ
1712}
1713
c906108c 1714\f
46212e0b 1715
46212e0b
TT
1716/* See buildsym.h. */
1717
1718void
1719set_last_source_file (const char *name)
1720{
c0015d44
TT
1721 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1722 if (buildsym_compunit != nullptr)
1723 buildsym_compunit->set_last_source_file (name);
46212e0b
TT
1724}
1725
1726/* See buildsym.h. */
1727
1728const char *
4a2125f5 1729get_last_source_file ()
46212e0b 1730{
c0015d44
TT
1731 if (buildsym_compunit == nullptr)
1732 return nullptr;
4a2125f5 1733 return buildsym_compunit->get_last_source_file ();
46212e0b
TT
1734}
1735
2c99ee5c
TT
1736/* See buildsym.h. */
1737
1738void
1739set_last_source_start_addr (CORE_ADDR addr)
1740{
1741 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1742 buildsym_compunit->set_last_source_start_addr (addr);
2c99ee5c
TT
1743}
1744
1745/* See buildsym.h. */
1746
1747CORE_ADDR
1748get_last_source_start_addr ()
1749{
1750 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1751 return buildsym_compunit->get_last_source_start_addr ();
2c99ee5c
TT
1752}
1753
6cccc9a8
TT
1754/* See buildsym.h. */
1755
1756struct using_direct **
1757get_local_using_directives ()
1758{
1759 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1760 return buildsym_compunit->get_local_using_directives ();
6cccc9a8
TT
1761}
1762
1763/* See buildsym.h. */
1764
1765void
1766set_local_using_directives (struct using_direct *new_local)
1767{
1768 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1769 buildsym_compunit->set_local_using_directives (new_local);
6cccc9a8
TT
1770}
1771
1772/* See buildsym.h. */
1773
1774struct using_direct **
1775get_global_using_directives ()
1776{
1777 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1778 return buildsym_compunit->get_global_using_directives ();
6cccc9a8
TT
1779}
1780
a60f3166
TT
1781/* See buildsym.h. */
1782
1783bool
1784outermost_context_p ()
1785{
1786 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1787 return buildsym_compunit->outermost_context_p ();
a60f3166
TT
1788}
1789
1790/* See buildsym.h. */
1791
1792struct context_stack *
1793get_current_context_stack ()
1794{
1795 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1796 return buildsym_compunit->get_current_context_stack ();
a60f3166
TT
1797}
1798
1799/* See buildsym.h. */
1800
1801int
1802get_context_stack_depth ()
1803{
1804 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1805 return buildsym_compunit->get_context_stack_depth ();
a60f3166
TT
1806}
1807
3c65e5b3
TT
1808/* See buildsym.h. */
1809
1810struct subfile *
1811get_current_subfile ()
1812{
1813 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1814 return buildsym_compunit->get_current_subfile ();
3c65e5b3
TT
1815}
1816
e148f09d
TT
1817/* See buildsym.h. */
1818
1819struct pending **
1820get_local_symbols ()
1821{
1822 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1823 return buildsym_compunit->get_local_symbols ();
e148f09d
TT
1824}
1825
1826/* See buildsym.h. */
1827
1828struct pending **
1829get_file_symbols ()
1830{
1831 gdb_assert (buildsym_compunit != nullptr);
4a2125f5 1832 return buildsym_compunit->get_file_symbols ();
e148f09d
TT
1833}
1834
1835/* See buildsym.h. */
1836
1837struct pending **
1838get_global_symbols ()
1839{
1840 gdb_assert (buildsym_compunit != nullptr);
4a2125f5
TT
1841 return buildsym_compunit->get_global_symbols ();
1842}
1843
1844void
1845start_subfile (const char *name)
1846{
1847 gdb_assert (buildsym_compunit != nullptr);
1848 buildsym_compunit->start_subfile (name);
1849}
1850
1851void
1852patch_subfile_names (struct subfile *subfile, const char *name)
1853{
1854 gdb_assert (buildsym_compunit != nullptr);
1855 buildsym_compunit->patch_subfile_names (subfile, name);
1856}
1857
1858void
1859push_subfile ()
1860{
1861 gdb_assert (buildsym_compunit != nullptr);
1862 buildsym_compunit->push_subfile ();
1863}
1864
1865const char *
1866pop_subfile ()
1867{
1868 gdb_assert (buildsym_compunit != nullptr);
1869 return buildsym_compunit->pop_subfile ();
1870}
1871
1872struct block *
1873end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1874{
1875 gdb_assert (buildsym_compunit != nullptr);
1876 return buildsym_compunit->end_symtab_get_static_block (end_addr, expandable,
1877 required);
1878}
1879
1880struct compunit_symtab *
1881end_symtab_from_static_block (struct block *static_block,
1882 int section, int expandable)
1883{
1884 gdb_assert (buildsym_compunit != nullptr);
1885 struct compunit_symtab *result
1886 = buildsym_compunit->end_symtab_from_static_block (static_block,
1887 section, expandable);
1888 reset_symtab_globals ();
1889 return result;
1890}
1891
1892struct compunit_symtab *
1893end_symtab (CORE_ADDR end_addr, int section)
1894{
1895 gdb_assert (buildsym_compunit != nullptr);
1896 struct compunit_symtab *result
1897 = buildsym_compunit->end_symtab (end_addr, section);
1898 reset_symtab_globals ();
1899 return result;
1900}
1901
1902struct compunit_symtab *
1903end_expandable_symtab (CORE_ADDR end_addr, int section)
1904{
1905 gdb_assert (buildsym_compunit != nullptr);
1906 struct compunit_symtab *result
1907 = buildsym_compunit->end_expandable_symtab (end_addr, section);
1908 reset_symtab_globals ();
1909 return result;
1910}
1911
1912void
1913augment_type_symtab ()
1914{
1915 gdb_assert (buildsym_compunit != nullptr);
1916 buildsym_compunit->augment_type_symtab ();
1917 reset_symtab_globals ();
1918}
1919
1920struct context_stack *
1921push_context (int desc, CORE_ADDR valu)
1922{
1923 gdb_assert (buildsym_compunit != nullptr);
1924 return buildsym_compunit->push_context (desc, valu);
1925}
1926
1927struct context_stack
1928pop_context ()
1929{
1930 gdb_assert (buildsym_compunit != nullptr);
1931 return buildsym_compunit->pop_context ();
1932}
1933
1934struct block *
1935finish_block (struct symbol *symbol, struct pending_block *old_blocks,
1936 const struct dynamic_prop *static_link,
1937 CORE_ADDR start, CORE_ADDR end)
1938{
1939 gdb_assert (buildsym_compunit != nullptr);
1940 return buildsym_compunit->finish_block (symbol, old_blocks, static_link,
1941 start, end);
1942}
1943
1944void
1945record_block_range (struct block *block, CORE_ADDR start,
1946 CORE_ADDR end_inclusive)
1947{
1948 gdb_assert (buildsym_compunit != nullptr);
1949 buildsym_compunit->record_block_range (block, start, end_inclusive);
1950}
1951
1952void
1953record_line (struct subfile *subfile, int line, CORE_ADDR pc)
1954{
1955 gdb_assert (buildsym_compunit != nullptr);
1956 buildsym_compunit->record_line (subfile, line, pc);
e148f09d 1957}
This page took 1.308773 seconds and 4 git commands to generate.