* buildsym.c (start_subfile): Remove unnecessary check for
[deliverable/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
c906108c 1/* Support routines for building symbol tables in GDB's internal format.
0b302171 2 Copyright (C) 1986-2004, 2007-2012 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,
4a64f543 24 DWARF, etc) belong somewhere else. */
c906108c
SS
25
26#include "defs.h"
27#include "bfd.h"
04ea0df1 28#include "gdb_obstack.h"
c906108c 29#include "symtab.h"
72367fb4 30#include "symfile.h"
c906108c
SS
31#include "objfiles.h"
32#include "gdbtypes.h"
0c5e171a 33#include "gdb_assert.h"
c906108c
SS
34#include "complaints.h"
35#include "gdb_string.h"
4a64f543 36#include "expression.h" /* For "enum exp_opcode" used by... */
357e46e7 37#include "bcache.h"
4a64f543 38#include "filenames.h" /* For DOSish file names. */
99d9066e 39#include "macrotab.h"
261397f8 40#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
fe898f56 41#include "block.h"
9219021c 42#include "cp-support.h"
de4f826b 43#include "dictionary.h"
801e3a5b 44#include "addrmap.h"
9219021c 45
c906108c 46/* Ask buildsym.h to define the vars it normally declares `extern'. */
c5aa993b
JM
47#define EXTERN
48/**/
4a64f543 49#include "buildsym.h" /* Our own declarations. */
c906108c
SS
50#undef EXTERN
51
0a0edcd5 52/* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
c906108c
SS
53 questionable--see comment where we call them). */
54
55#include "stabsread.h"
56
94d09e04
DE
57/* List of subfiles. */
58
59static struct subfile *subfiles;
60
c906108c
SS
61/* List of free `struct pending' structures for reuse. */
62
63static struct pending *free_pendings;
64
65/* Non-zero if symtab has line number info. This prevents an
66 otherwise empty symtab from being tossed. */
67
68static int have_line_numbers;
801e3a5b
JB
69
70/* The mutable address map for the compilation unit whose symbols
71 we're currently reading. The symtabs' shared blockvector will
72 point to a fixed copy of this. */
73static struct addrmap *pending_addrmap;
74
75/* The obstack on which we allocate pending_addrmap.
76 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
77 initialized (and holds pending_addrmap). */
78static struct obstack pending_addrmap_obstack;
79
80/* Non-zero if we recorded any ranges in the addrmap that are
81 different from those in the blockvector already. We set this to
82 zero when we start processing a symfile, and if it's still zero at
83 the end, then we just toss the addrmap. */
84static int pending_addrmap_interesting;
85
c906108c
SS
86\f
87static int compare_line_numbers (const void *ln1p, const void *ln2p);
0b49e518
TT
88
89static void record_pending_block (struct objfile *objfile,
90 struct block *block,
91 struct pending_block *opblock);
c906108c
SS
92\f
93
94/* Initial sizes of data structures. These are realloc'd larger if
95 needed, and realloc'd down to the size actually used, when
96 completed. */
97
98#define INITIAL_CONTEXT_STACK_SIZE 10
99#define INITIAL_LINE_VECTOR_LENGTH 1000
100\f
101
4a64f543 102/* Maintain the lists of symbols and blocks. */
c906108c 103
93bf33fd 104/* Add a symbol to one of the lists of symbols. */
c906108c
SS
105
106void
107add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
108{
52f0bd74 109 struct pending *link;
c906108c
SS
110
111 /* If this is an alias for another symbol, don't add it. */
112 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
113 return;
114
4a64f543 115 /* We keep PENDINGSIZE symbols in each link of the list. If we
c906108c
SS
116 don't have a link with room in it, add a new link. */
117 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
118 {
119 if (free_pendings)
120 {
121 link = free_pendings;
122 free_pendings = link->next;
123 }
124 else
125 {
126 link = (struct pending *) xmalloc (sizeof (struct pending));
127 }
128
129 link->next = *listhead;
130 *listhead = link;
131 link->nsyms = 0;
132 }
133
134 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
135}
136
137/* Find a symbol named NAME on a LIST. NAME need not be
138 '\0'-terminated; LENGTH is the length of the name. */
139
140struct symbol *
141find_symbol_in_list (struct pending *list, char *name, int length)
142{
143 int j;
0d5cff50 144 const char *pp;
c906108c
SS
145
146 while (list != NULL)
147 {
148 for (j = list->nsyms; --j >= 0;)
149 {
3567439c 150 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
5aafa1cc
PM
151 if (*pp == *name && strncmp (pp, name, length) == 0
152 && pp[length] == '\0')
c906108c
SS
153 {
154 return (list->symbol[j]);
155 }
156 }
157 list = list->next;
158 }
159 return (NULL);
160}
161
162/* At end of reading syms, or in case of quit, really free as many
4a64f543 163 `struct pending's as we can easily find. */
c906108c 164
c906108c 165void
bde58177 166really_free_pendings (void *dummy)
c906108c
SS
167{
168 struct pending *next, *next1;
169
170 for (next = free_pendings; next; next = next1)
171 {
172 next1 = next->next;
b8c9b27d 173 xfree ((void *) next);
c906108c
SS
174 }
175 free_pendings = NULL;
176
177 free_pending_blocks ();
178
179 for (next = file_symbols; next != NULL; next = next1)
180 {
181 next1 = next->next;
b8c9b27d 182 xfree ((void *) next);
c906108c
SS
183 }
184 file_symbols = NULL;
185
186 for (next = global_symbols; next != NULL; next = next1)
187 {
188 next1 = next->next;
b8c9b27d 189 xfree ((void *) next);
c906108c
SS
190 }
191 global_symbols = NULL;
99d9066e
JB
192
193 if (pending_macros)
194 free_macro_table (pending_macros);
801e3a5b
JB
195
196 if (pending_addrmap)
197 {
198 obstack_free (&pending_addrmap_obstack, NULL);
199 pending_addrmap = NULL;
200 }
c906108c
SS
201}
202
4a64f543 203/* This function is called to discard any pending blocks. */
c906108c
SS
204
205void
206free_pending_blocks (void)
207{
89ba75b1
JB
208 /* The links are made in the objfile_obstack, so we only need to
209 reset PENDING_BLOCKS. */
c906108c
SS
210 pending_blocks = NULL;
211}
212
213/* Take one of the lists of symbols and make a block from it. Keep
214 the order the symbols have in the list (reversed from the input
215 file). Put the block on the list of pending blocks. */
216
84a146c9
TT
217static struct block *
218finish_block_internal (struct symbol *symbol, struct pending **listhead,
219 struct pending_block *old_blocks,
220 CORE_ADDR start, CORE_ADDR end,
221 struct objfile *objfile,
222 int is_global)
c906108c 223{
5af949e3 224 struct gdbarch *gdbarch = get_objfile_arch (objfile);
52f0bd74
AC
225 struct pending *next, *next1;
226 struct block *block;
227 struct pending_block *pblock;
c906108c 228 struct pending_block *opblock;
c906108c 229
84a146c9
TT
230 block = (is_global
231 ? allocate_global_block (&objfile->objfile_obstack)
232 : allocate_block (&objfile->objfile_obstack));
c906108c 233
261397f8
DJ
234 if (symbol)
235 {
4a146b47 236 BLOCK_DICT (block) = dict_create_linear (&objfile->objfile_obstack,
de4f826b 237 *listhead);
261397f8
DJ
238 }
239 else
c906108c 240 {
4a146b47 241 BLOCK_DICT (block) = dict_create_hashed (&objfile->objfile_obstack,
de4f826b 242 *listhead);
c906108c
SS
243 }
244
245 BLOCK_START (block) = start;
246 BLOCK_END (block) = end;
c906108c 247
c906108c
SS
248 /* Put the block in as the value of the symbol that names it. */
249
250 if (symbol)
251 {
252 struct type *ftype = SYMBOL_TYPE (symbol);
de4f826b 253 struct dict_iterator iter;
c906108c
SS
254 SYMBOL_BLOCK_VALUE (symbol) = block;
255 BLOCK_FUNCTION (block) = symbol;
256
257 if (TYPE_NFIELDS (ftype) <= 0)
258 {
259 /* No parameter type information is recorded with the
260 function's type. Set that from the type of the
4a64f543 261 parameter symbols. */
c906108c
SS
262 int nparams = 0, iparams;
263 struct symbol *sym;
8157b174
TT
264
265 /* Here we want to directly access the dictionary, because
266 we haven't fully initialized the block yet. */
267 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
c906108c 268 {
2a2d4dc3
AS
269 if (SYMBOL_IS_ARGUMENT (sym))
270 nparams++;
c906108c
SS
271 }
272 if (nparams > 0)
273 {
274 TYPE_NFIELDS (ftype) = nparams;
275 TYPE_FIELDS (ftype) = (struct field *)
276 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
277
de4f826b 278 iparams = 0;
8157b174
TT
279 /* Here we want to directly access the dictionary, because
280 we haven't fully initialized the block yet. */
281 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
c906108c 282 {
de4f826b
DC
283 if (iparams == nparams)
284 break;
285
2a2d4dc3 286 if (SYMBOL_IS_ARGUMENT (sym))
c906108c 287 {
c906108c 288 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
8176bb6d 289 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
c906108c 290 iparams++;
c906108c
SS
291 }
292 }
293 }
294 }
295 }
296 else
297 {
298 BLOCK_FUNCTION (block) = NULL;
299 }
300
301 /* Now "free" the links of the list, and empty the list. */
302
303 for (next = *listhead; next; next = next1)
304 {
305 next1 = next->next;
306 next->next = free_pendings;
307 free_pendings = next;
308 }
309 *listhead = NULL;
310
c906108c 311 /* Check to be sure that the blocks have an end address that is
4a64f543 312 greater than starting address. */
c906108c
SS
313
314 if (BLOCK_END (block) < BLOCK_START (block))
315 {
316 if (symbol)
317 {
23136709 318 complaint (&symfile_complaints,
3e43a32a
MS
319 _("block end address less than block "
320 "start address in %s (patched it)"),
de5ad195 321 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
322 }
323 else
324 {
23136709 325 complaint (&symfile_complaints,
3e43a32a
MS
326 _("block end address %s less than block "
327 "start address %s (patched it)"),
5af949e3
UW
328 paddress (gdbarch, BLOCK_END (block)),
329 paddress (gdbarch, BLOCK_START (block)));
c906108c 330 }
4a64f543 331 /* Better than nothing. */
c906108c
SS
332 BLOCK_END (block) = BLOCK_START (block);
333 }
c906108c
SS
334
335 /* Install this block as the superblock of all blocks made since the
336 start of this scope that don't have superblocks yet. */
337
338 opblock = NULL;
c0219d42
MS
339 for (pblock = pending_blocks;
340 pblock && pblock != old_blocks;
341 pblock = pblock->next)
c906108c
SS
342 {
343 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
344 {
c906108c 345 /* Check to be sure the blocks are nested as we receive
4a64f543 346 them. If the compiler/assembler/linker work, this just
14711c82
DJ
347 burns a small amount of time.
348
349 Skip blocks which correspond to a function; they're not
350 physically nested inside this other blocks, only
351 lexically nested. */
352 if (BLOCK_FUNCTION (pblock->block) == NULL
353 && (BLOCK_START (pblock->block) < BLOCK_START (block)
354 || BLOCK_END (pblock->block) > BLOCK_END (block)))
c906108c
SS
355 {
356 if (symbol)
357 {
23136709 358 complaint (&symfile_complaints,
3d263c1d 359 _("inner block not inside outer block in %s"),
de5ad195 360 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
361 }
362 else
363 {
23136709 364 complaint (&symfile_complaints,
3e43a32a
MS
365 _("inner block (%s-%s) not "
366 "inside outer block (%s-%s)"),
5af949e3
UW
367 paddress (gdbarch, BLOCK_START (pblock->block)),
368 paddress (gdbarch, BLOCK_END (pblock->block)),
369 paddress (gdbarch, BLOCK_START (block)),
370 paddress (gdbarch, BLOCK_END (block)));
c906108c
SS
371 }
372 if (BLOCK_START (pblock->block) < BLOCK_START (block))
373 BLOCK_START (pblock->block) = BLOCK_START (block);
374 if (BLOCK_END (pblock->block) > BLOCK_END (block))
375 BLOCK_END (pblock->block) = BLOCK_END (block);
376 }
c906108c
SS
377 BLOCK_SUPERBLOCK (pblock->block) = block;
378 }
379 opblock = pblock;
380 }
381
27aa8d6a 382 block_set_using (block, using_directives, &objfile->objfile_obstack);
00ae8fef 383 using_directives = NULL;
27aa8d6a 384
c906108c 385 record_pending_block (objfile, block, opblock);
801e3a5b
JB
386
387 return block;
c906108c
SS
388}
389
84a146c9
TT
390struct block *
391finish_block (struct symbol *symbol, struct pending **listhead,
392 struct pending_block *old_blocks,
393 CORE_ADDR start, CORE_ADDR end,
394 struct objfile *objfile)
395{
396 return finish_block_internal (symbol, listhead, old_blocks,
397 start, end, objfile, 0);
398}
de4f826b 399
c906108c
SS
400/* Record BLOCK on the list of all blocks in the file. Put it after
401 OPBLOCK, or at the beginning if opblock is NULL. This puts the
402 block in the list after all its subblocks.
403
4a146b47 404 Allocate the pending block struct in the objfile_obstack to save
c906108c
SS
405 time. This wastes a little space. FIXME: Is it worth it? */
406
0b49e518 407static void
c906108c
SS
408record_pending_block (struct objfile *objfile, struct block *block,
409 struct pending_block *opblock)
410{
52f0bd74 411 struct pending_block *pblock;
c906108c
SS
412
413 pblock = (struct pending_block *)
4a146b47 414 obstack_alloc (&objfile->objfile_obstack, sizeof (struct pending_block));
c906108c
SS
415 pblock->block = block;
416 if (opblock)
417 {
418 pblock->next = opblock->next;
419 opblock->next = pblock;
420 }
421 else
422 {
423 pblock->next = pending_blocks;
424 pending_blocks = pblock;
425 }
426}
427
801e3a5b
JB
428
429/* Record that the range of addresses from START to END_INCLUSIVE
430 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
431 addresses must be set already. You must apply this function to all
432 BLOCK's children before applying it to BLOCK.
433
434 If a call to this function complicates the picture beyond that
435 already provided by BLOCK_START and BLOCK_END, then we create an
436 address map for the block. */
437void
438record_block_range (struct block *block,
439 CORE_ADDR start, CORE_ADDR end_inclusive)
440{
441 /* If this is any different from the range recorded in the block's
442 own BLOCK_START and BLOCK_END, then note that the address map has
443 become interesting. Note that even if this block doesn't have
444 any "interesting" ranges, some later block might, so we still
445 need to record this block in the addrmap. */
446 if (start != BLOCK_START (block)
447 || end_inclusive + 1 != BLOCK_END (block))
448 pending_addrmap_interesting = 1;
449
450 if (! pending_addrmap)
451 {
452 obstack_init (&pending_addrmap_obstack);
453 pending_addrmap = addrmap_create_mutable (&pending_addrmap_obstack);
454 }
455
456 addrmap_set_empty (pending_addrmap, start, end_inclusive, block);
457}
458
459
822e978b 460static struct blockvector *
c906108c
SS
461make_blockvector (struct objfile *objfile)
462{
52f0bd74
AC
463 struct pending_block *next;
464 struct blockvector *blockvector;
465 int i;
c906108c
SS
466
467 /* Count the length of the list of blocks. */
468
469 for (next = pending_blocks, i = 0; next; next = next->next, i++)
470 {;
471 }
472
473 blockvector = (struct blockvector *)
4a146b47 474 obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
475 (sizeof (struct blockvector)
476 + (i - 1) * sizeof (struct block *)));
477
4a64f543 478 /* Copy the blocks into the blockvector. This is done in reverse
c906108c 479 order, which happens to put the blocks into the proper order
4a64f543 480 (ascending starting address). finish_block has hair to insert
c906108c
SS
481 each block into the list after its subblocks in order to make
482 sure this is true. */
483
484 BLOCKVECTOR_NBLOCKS (blockvector) = i;
485 for (next = pending_blocks; next; next = next->next)
486 {
487 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
488 }
489
89ba75b1 490 free_pending_blocks ();
c906108c 491
801e3a5b
JB
492 /* If we needed an address map for this symtab, record it in the
493 blockvector. */
494 if (pending_addrmap && pending_addrmap_interesting)
495 BLOCKVECTOR_MAP (blockvector)
496 = addrmap_create_fixed (pending_addrmap, &objfile->objfile_obstack);
497 else
498 BLOCKVECTOR_MAP (blockvector) = 0;
4aad0dfc 499
c906108c 500 /* Some compilers output blocks in the wrong order, but we depend on
4a64f543 501 their being in the right order so we can binary search. Check the
4aad0dfc
DE
502 order and moan about it.
503 Note: Remember that the first two blocks are the global and static
504 blocks. We could special case that fact and begin checking at block 2.
505 To avoid making that assumption we do not. */
c906108c
SS
506 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
507 {
508 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
509 {
510 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
511 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
512 {
59527da0
JB
513 CORE_ADDR start
514 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
c906108c 515
3d263c1d 516 complaint (&symfile_complaints, _("block at %s out of order"),
bb599908 517 hex_string ((LONGEST) start));
c906108c
SS
518 }
519 }
520 }
c906108c
SS
521
522 return (blockvector);
523}
524\f
525/* Start recording information about source code that came from an
526 included (or otherwise merged-in) source file with a different
527 name. NAME is the name of the file (cannot be NULL), DIRNAME is
4a64f543
MS
528 the directory in which the file was compiled (or NULL if not
529 known). */
c906108c
SS
530
531void
72b9f47f 532start_subfile (const char *name, const char *dirname)
c906108c 533{
52f0bd74 534 struct subfile *subfile;
c906108c
SS
535
536 /* See if this subfile is already known as a subfile of the current
537 main source file. */
538
539 for (subfile = subfiles; subfile; subfile = subfile->next)
540 {
84ba0adf
DJ
541 char *subfile_name;
542
543 /* If NAME is an absolute path, and this subfile is not, then
544 attempt to create an absolute path to compare. */
545 if (IS_ABSOLUTE_PATH (name)
546 && !IS_ABSOLUTE_PATH (subfile->name)
547 && subfile->dirname != NULL)
548 subfile_name = concat (subfile->dirname, SLASH_STRING,
6eb7ee03 549 subfile->name, (char *) NULL);
84ba0adf
DJ
550 else
551 subfile_name = subfile->name;
552
553 if (FILENAME_CMP (subfile_name, name) == 0)
c906108c
SS
554 {
555 current_subfile = subfile;
84ba0adf
DJ
556 if (subfile_name != subfile->name)
557 xfree (subfile_name);
c906108c
SS
558 return;
559 }
84ba0adf
DJ
560 if (subfile_name != subfile->name)
561 xfree (subfile_name);
c906108c
SS
562 }
563
4a64f543 564 /* This subfile is not known. Add an entry for it. Make an entry
c906108c
SS
565 for this subfile in the list of all subfiles of the current main
566 source file. */
567
568 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
59527da0 569 memset ((char *) subfile, 0, sizeof (struct subfile));
c906108c
SS
570 subfile->next = subfiles;
571 subfiles = subfile;
572 current_subfile = subfile;
573
4a64f543 574 /* Save its name and compilation directory name. */
b74db436 575 subfile->name = xstrdup (name);
1b36a34b 576 subfile->dirname = (dirname == NULL) ? NULL : xstrdup (dirname);
c906108c
SS
577
578 /* Initialize line-number recording for this subfile. */
579 subfile->line_vector = NULL;
580
581 /* Default the source language to whatever can be deduced from the
582 filename. If nothing can be deduced (such as for a C/C++ include
583 file with a ".h" extension), then inherit whatever language the
584 previous subfile had. This kludgery is necessary because there
585 is no standard way in some object formats to record the source
586 language. Also, when symtabs are allocated we try to deduce a
587 language then as well, but it is too late for us to use that
588 information while reading symbols, since symtabs aren't allocated
589 until after all the symbols have been processed for a given
4a64f543 590 source file. */
c906108c
SS
591
592 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
593 if (subfile->language == language_unknown
594 && subfile->next != NULL)
c906108c
SS
595 {
596 subfile->language = subfile->next->language;
597 }
598
599 /* Initialize the debug format string to NULL. We may supply it
4a64f543 600 later via a call to record_debugformat. */
c906108c
SS
601 subfile->debugformat = NULL;
602
303b6f5d
DJ
603 /* Similarly for the producer. */
604 subfile->producer = NULL;
605
25caa7a8 606 /* If the filename of this subfile ends in .C, then change the
c906108c 607 language of any pending subfiles from C to C++. We also accept
25caa7a8 608 any other C++ suffixes accepted by deduce_language_from_filename. */
c906108c
SS
609 /* Likewise for f2c. */
610
611 if (subfile->name)
612 {
613 struct subfile *s;
614 enum language sublang = deduce_language_from_filename (subfile->name);
615
616 if (sublang == language_cplus || sublang == language_fortran)
617 for (s = subfiles; s != NULL; s = s->next)
618 if (s->language == language_c)
619 s->language = sublang;
620 }
621
622 /* And patch up this file if necessary. */
623 if (subfile->language == language_c
624 && subfile->next != NULL
625 && (subfile->next->language == language_cplus
626 || subfile->next->language == language_fortran))
627 {
628 subfile->language = subfile->next->language;
629 }
630}
631
632/* For stabs readers, the first N_SO symbol is assumed to be the
633 source file name, and the subfile struct is initialized using that
634 assumption. If another N_SO symbol is later seen, immediately
635 following the first one, then the first one is assumed to be the
636 directory name and the second one is really the source file name.
637
638 So we have to patch up the subfile struct by moving the old name
639 value to dirname and remembering the new name. Some sanity
640 checking is performed to ensure that the state of the subfile
641 struct is reasonable and that the old name we are assuming to be a
4a64f543 642 directory name actually is (by checking for a trailing '/'). */
c906108c
SS
643
644void
645patch_subfile_names (struct subfile *subfile, char *name)
646{
647 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
0ba1096a 648 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
c906108c
SS
649 {
650 subfile->dirname = subfile->name;
1b36a34b 651 subfile->name = xstrdup (name);
c906108c
SS
652 last_source_file = name;
653
654 /* Default the source language to whatever can be deduced from
655 the filename. If nothing can be deduced (such as for a C/C++
656 include file with a ".h" extension), then inherit whatever
657 language the previous subfile had. This kludgery is
658 necessary because there is no standard way in some object
659 formats to record the source language. Also, when symtabs
660 are allocated we try to deduce a language then as well, but
661 it is too late for us to use that information while reading
662 symbols, since symtabs aren't allocated until after all the
4a64f543 663 symbols have been processed for a given source file. */
c906108c
SS
664
665 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
666 if (subfile->language == language_unknown
667 && subfile->next != NULL)
c906108c
SS
668 {
669 subfile->language = subfile->next->language;
670 }
671 }
672}
673\f
674/* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
675 switching source files (different subfiles, as we call them) within
676 one object file, but using a stack rather than in an arbitrary
677 order. */
678
679void
680push_subfile (void)
681{
52f0bd74 682 struct subfile_stack *tem
cc59ec59 683 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
c906108c
SS
684
685 tem->next = subfile_stack;
686 subfile_stack = tem;
687 if (current_subfile == NULL || current_subfile->name == NULL)
688 {
4a64f543
MS
689 internal_error (__FILE__, __LINE__,
690 _("failed internal consistency check"));
c906108c
SS
691 }
692 tem->name = current_subfile->name;
693}
694
695char *
696pop_subfile (void)
697{
52f0bd74
AC
698 char *name;
699 struct subfile_stack *link = subfile_stack;
c906108c
SS
700
701 if (link == NULL)
702 {
3e43a32a
MS
703 internal_error (__FILE__, __LINE__,
704 _("failed internal consistency check"));
c906108c
SS
705 }
706 name = link->name;
707 subfile_stack = link->next;
b8c9b27d 708 xfree ((void *) link);
c906108c
SS
709 return (name);
710}
711\f
712/* Add a linetable entry for line number LINE and address PC to the
713 line vector for SUBFILE. */
714
715void
aa1ee363 716record_line (struct subfile *subfile, int line, CORE_ADDR pc)
c906108c
SS
717{
718 struct linetable_entry *e;
c906108c 719
cc59ec59 720 /* Ignore the dummy line number in libg.o */
c906108c
SS
721 if (line == 0xffff)
722 {
723 return;
724 }
725
726 /* Make sure line vector exists and is big enough. */
727 if (!subfile->line_vector)
728 {
729 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
730 subfile->line_vector = (struct linetable *)
731 xmalloc (sizeof (struct linetable)
c5aa993b 732 + subfile->line_vector_length * sizeof (struct linetable_entry));
c906108c
SS
733 subfile->line_vector->nitems = 0;
734 have_line_numbers = 1;
735 }
736
737 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
738 {
739 subfile->line_vector_length *= 2;
740 subfile->line_vector = (struct linetable *)
741 xrealloc ((char *) subfile->line_vector,
742 (sizeof (struct linetable)
743 + (subfile->line_vector_length
744 * sizeof (struct linetable_entry))));
745 }
746
607ae575
DJ
747 /* Normally, we treat lines as unsorted. But the end of sequence
748 marker is special. We sort line markers at the same PC by line
749 number, so end of sequence markers (which have line == 0) appear
750 first. This is right if the marker ends the previous function,
751 and there is no padding before the next function. But it is
752 wrong if the previous line was empty and we are now marking a
753 switch to a different subfile. We must leave the end of sequence
754 marker at the end of this group of lines, not sort the empty line
755 to after the marker. The easiest way to accomplish this is to
756 delete any empty lines from our table, if they are followed by
757 end of sequence markers. All we lose is the ability to set
758 breakpoints at some lines which contain no instructions
759 anyway. */
760 if (line == 0 && subfile->line_vector->nitems > 0)
761 {
762 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
763 while (subfile->line_vector->nitems > 0 && e->pc == pc)
764 {
765 e--;
766 subfile->line_vector->nitems--;
767 }
768 }
769
c906108c
SS
770 e = subfile->line_vector->item + subfile->line_vector->nitems++;
771 e->line = line;
607ae575 772 e->pc = pc;
c906108c
SS
773}
774
775/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
776
777static int
778compare_line_numbers (const void *ln1p, const void *ln2p)
779{
780 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
781 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
782
783 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
784 Please keep it that way. */
785 if (ln1->pc < ln2->pc)
786 return -1;
787
788 if (ln1->pc > ln2->pc)
789 return 1;
790
791 /* If pc equal, sort by line. I'm not sure whether this is optimum
792 behavior (see comment at struct linetable in symtab.h). */
793 return ln1->line - ln2->line;
794}
795\f
796/* Start a new symtab for a new source file. Called, for example,
797 when a stabs symbol of type N_SO is seen, or when a DWARF
798 TAG_compile_unit DIE is seen. It indicates the start of data for
0b0287a1
DE
799 one original source file.
800
801 NAME is the name of the file (cannot be NULL). DIRNAME is the directory in
802 which the file was compiled (or NULL if not known). START_ADDR is the
803 lowest address of objects in the file (or 0 if not known). */
c906108c
SS
804
805void
806start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
807{
c906108c
SS
808 last_source_file = name;
809 last_source_start_addr = start_addr;
810 file_symbols = NULL;
811 global_symbols = NULL;
812 within_function = 0;
813 have_line_numbers = 0;
814
815 /* Context stack is initially empty. Allocate first one with room
816 for 10 levels; reuse it forever afterward. */
817 if (context_stack == NULL)
818 {
819 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
820 context_stack = (struct context_stack *)
821 xmalloc (context_stack_size * sizeof (struct context_stack));
822 }
823 context_stack_depth = 0;
824
801e3a5b
JB
825 /* We shouldn't have any address map at this point. */
826 gdb_assert (! pending_addrmap);
827
c906108c
SS
828 /* Initialize the list of sub source files with one entry for this
829 file (the top-level source file). */
830
831 subfiles = NULL;
832 current_subfile = NULL;
833 start_subfile (name, dirname);
834}
835
4a64f543
MS
836/* Subroutine of end_symtab to simplify it. Look for a subfile that
837 matches the main source file's basename. If there is only one, and
838 if the main source file doesn't have any symbol or line number
839 information, then copy this file's symtab and line_vector to the
840 main source file's subfile and discard the other subfile. This can
841 happen because of a compiler bug or from the user playing games
842 with #line or from things like a distributed build system that
843 manipulates the debug info. */
4584e32e
DE
844
845static void
846watch_main_source_file_lossage (void)
847{
848 struct subfile *mainsub, *subfile;
849
850 /* Find the main source file.
851 This loop could be eliminated if start_symtab saved it for us. */
852 mainsub = NULL;
853 for (subfile = subfiles; subfile; subfile = subfile->next)
854 {
855 /* The main subfile is guaranteed to be the last one. */
856 if (subfile->next == NULL)
857 mainsub = subfile;
858 }
859
4a64f543
MS
860 /* If the main source file doesn't have any line number or symbol
861 info, look for an alias in another subfile.
862
863 We have to watch for mainsub == NULL here. It's a quirk of
864 end_symtab, it can return NULL so there may not be a main
865 subfile. */
4584e32e
DE
866
867 if (mainsub
868 && mainsub->line_vector == NULL
869 && mainsub->symtab == NULL)
870 {
871 const char *mainbase = lbasename (mainsub->name);
872 int nr_matches = 0;
873 struct subfile *prevsub;
874 struct subfile *mainsub_alias = NULL;
875 struct subfile *prev_mainsub_alias = NULL;
876
877 prevsub = NULL;
878 for (subfile = subfiles;
879 /* Stop before we get to the last one. */
880 subfile->next;
881 subfile = subfile->next)
882 {
0ba1096a 883 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
4584e32e
DE
884 {
885 ++nr_matches;
886 mainsub_alias = subfile;
887 prev_mainsub_alias = prevsub;
888 }
889 prevsub = subfile;
890 }
891
892 if (nr_matches == 1)
893 {
894 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
895
896 /* Found a match for the main source file.
897 Copy its line_vector and symtab to the main subfile
898 and then discard it. */
899
900 mainsub->line_vector = mainsub_alias->line_vector;
901 mainsub->line_vector_length = mainsub_alias->line_vector_length;
902 mainsub->symtab = mainsub_alias->symtab;
903
904 if (prev_mainsub_alias == NULL)
905 subfiles = mainsub_alias->next;
906 else
907 prev_mainsub_alias->next = mainsub_alias->next;
908 xfree (mainsub_alias);
909 }
910 }
911}
912
98cc87bd 913/* Helper function for qsort. Parameters are `struct block *' pointers,
07e7f39f
JK
914 function sorts them in descending order by their BLOCK_START. */
915
916static int
917block_compar (const void *ap, const void *bp)
918{
919 const struct block *a = *(const struct block **) ap;
920 const struct block *b = *(const struct block **) bp;
921
922 return ((BLOCK_START (b) > BLOCK_START (a))
923 - (BLOCK_START (b) < BLOCK_START (a)));
924}
925
c906108c
SS
926/* Finish the symbol definitions for one main source file, close off
927 all the lexical contexts for that file (creating struct block's for
928 them), then make the struct symtab for that file and put it in the
929 list of all such.
930
931 END_ADDR is the address of the end of the file's text. SECTION is
932 the section number (in objfile->section_offsets) of the blockvector
933 and linetable.
934
935 Note that it is possible for end_symtab() to return NULL. In
936 particular, for the DWARF case at least, it will return NULL when
937 it finds a compilation unit that has exactly one DIE, a
938 TAG_compile_unit DIE. This can happen when we link in an object
939 file that was compiled from an empty source file. Returning NULL
940 is probably not the correct thing to do, because then gdb will
4a64f543 941 never know about this empty file (FIXME). */
c906108c
SS
942
943struct symtab *
944end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
945{
52f0bd74
AC
946 struct symtab *symtab = NULL;
947 struct blockvector *blockvector;
948 struct subfile *subfile;
949 struct context_stack *cstk;
c906108c
SS
950 struct subfile *nextsub;
951
952 /* Finish the lexical context of the last function in the file; pop
953 the context stack. */
954
955 if (context_stack_depth > 0)
956 {
957 cstk = pop_context ();
958 /* Make a block for the local symbols within. */
959 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
960 cstk->start_addr, end_addr, objfile);
961
962 if (context_stack_depth > 0)
963 {
964 /* This is said to happen with SCO. The old coffread.c
965 code simply emptied the context stack, so we do the
966 same. FIXME: Find out why it is happening. This is not
967 believed to happen in most cases (even for coffread.c);
968 it used to be an abort(). */
23136709 969 complaint (&symfile_complaints,
3d263c1d 970 _("Context stack not empty in end_symtab"));
c906108c
SS
971 context_stack_depth = 0;
972 }
973 }
974
975 /* Reordered executables may have out of order pending blocks; if
976 OBJF_REORDERED is true, then sort the pending blocks. */
977 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
978 {
07e7f39f
JK
979 unsigned count = 0;
980 struct pending_block *pb;
981 struct block **barray, **bp;
982 struct cleanup *back_to;
c906108c 983
07e7f39f
JK
984 for (pb = pending_blocks; pb != NULL; pb = pb->next)
985 count++;
c906108c 986
07e7f39f
JK
987 barray = xmalloc (sizeof (*barray) * count);
988 back_to = make_cleanup (xfree, barray);
c906108c 989
07e7f39f
JK
990 bp = barray;
991 for (pb = pending_blocks; pb != NULL; pb = pb->next)
992 *bp++ = pb->block;
993
994 qsort (barray, count, sizeof (*barray), block_compar);
995
996 bp = barray;
997 for (pb = pending_blocks; pb != NULL; pb = pb->next)
998 pb->block = *bp++;
999
1000 do_cleanups (back_to);
c906108c
SS
1001 }
1002
1003 /* Cleanup any undefined types that have been left hanging around
1004 (this needs to be done before the finish_blocks so that
1005 file_symbols is still good).
c5aa993b 1006
0a0edcd5 1007 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
c906108c
SS
1008 specific, but harmless for other symbol readers, since on gdb
1009 startup or when finished reading stabs, the state is set so these
1010 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1011 we make this cleaner? */
1012
0a0edcd5 1013 cleanup_undefined_stabs_types (objfile);
c906108c
SS
1014 finish_global_stabs (objfile);
1015
1016 if (pending_blocks == NULL
1017 && file_symbols == NULL
1018 && global_symbols == NULL
99d9066e
JB
1019 && have_line_numbers == 0
1020 && pending_macros == NULL)
c906108c
SS
1021 {
1022 /* Ignore symtabs that have no functions with real debugging
1023 info. */
1024 blockvector = NULL;
1025 }
1026 else
1027 {
1028 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
1029 blockvector. */
4a64f543
MS
1030 finish_block (0, &file_symbols, 0, last_source_start_addr,
1031 end_addr, objfile);
84a146c9
TT
1032 finish_block_internal (0, &global_symbols, 0, last_source_start_addr,
1033 end_addr, objfile, 1);
c906108c
SS
1034 blockvector = make_blockvector (objfile);
1035 }
1036
c295b2e5
JB
1037 /* Read the line table if it has to be read separately. */
1038 if (objfile->sf->sym_read_linetable != NULL)
1039 objfile->sf->sym_read_linetable ();
c906108c 1040
4584e32e
DE
1041 /* Handle the case where the debug info specifies a different path
1042 for the main source file. It can cause us to lose track of its
1043 line number information. */
1044 watch_main_source_file_lossage ();
1045
c906108c
SS
1046 /* Now create the symtab objects proper, one for each subfile. */
1047 /* (The main file is the last one on the chain.) */
1048
1049 for (subfile = subfiles; subfile; subfile = nextsub)
1050 {
1051 int linetablesize = 0;
1052 symtab = NULL;
1053
4a64f543 1054 /* If we have blocks of symbols, make a symtab. Otherwise, just
c906108c
SS
1055 ignore this file and any line number info in it. */
1056 if (blockvector)
1057 {
1058 if (subfile->line_vector)
1059 {
1060 linetablesize = sizeof (struct linetable) +
1061 subfile->line_vector->nitems * sizeof (struct linetable_entry);
c906108c
SS
1062
1063 /* Like the pending blocks, the line table may be
1064 scrambled in reordered executables. Sort it if
1065 OBJF_REORDERED is true. */
1066 if (objfile->flags & OBJF_REORDERED)
1067 qsort (subfile->line_vector->item,
1068 subfile->line_vector->nitems,
c5aa993b 1069 sizeof (struct linetable_entry), compare_line_numbers);
c906108c
SS
1070 }
1071
1072 /* Now, allocate a symbol table. */
cb1df416
DJ
1073 if (subfile->symtab == NULL)
1074 symtab = allocate_symtab (subfile->name, objfile);
1075 else
1076 symtab = subfile->symtab;
c906108c
SS
1077
1078 /* Fill in its components. */
1079 symtab->blockvector = blockvector;
99d9066e 1080 symtab->macro_table = pending_macros;
c906108c
SS
1081 if (subfile->line_vector)
1082 {
4a64f543 1083 /* Reallocate the line table on the symbol obstack. */
c906108c 1084 symtab->linetable = (struct linetable *)
4a146b47 1085 obstack_alloc (&objfile->objfile_obstack, linetablesize);
c906108c
SS
1086 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
1087 }
1088 else
1089 {
1090 symtab->linetable = NULL;
1091 }
1092 symtab->block_line_section = section;
1093 if (subfile->dirname)
1094 {
4a64f543 1095 /* Reallocate the dirname on the symbol obstack. */
c906108c 1096 symtab->dirname = (char *)
4a146b47 1097 obstack_alloc (&objfile->objfile_obstack,
c906108c
SS
1098 strlen (subfile->dirname) + 1);
1099 strcpy (symtab->dirname, subfile->dirname);
1100 }
1101 else
1102 {
1103 symtab->dirname = NULL;
1104 }
c906108c
SS
1105
1106 /* Use whatever language we have been using for this
1107 subfile, not the one that was deduced in allocate_symtab
1108 from the filename. We already did our own deducing when
1109 we created the subfile, and we may have altered our
1110 opinion of what language it is from things we found in
4a64f543 1111 the symbols. */
c906108c
SS
1112 symtab->language = subfile->language;
1113
9182c5bc
JK
1114 /* Save the debug format string (if any) in the symtab. */
1115 symtab->debugformat = subfile->debugformat;
1116
1117 /* Similarly for the producer. */
1118 symtab->producer = subfile->producer;
1119
c906108c
SS
1120 /* All symtabs for the main file and the subfiles share a
1121 blockvector, so we need to clear primary for everything
1122 but the main file. */
1123
1124 symtab->primary = 0;
1125 }
24be086d
JB
1126 else
1127 {
1128 if (subfile->symtab)
1129 {
1130 /* Since we are ignoring that subfile, we also need
1131 to unlink the associated empty symtab that we created.
98cc87bd 1132 Otherwise, we can run into trouble because various parts
24be086d
JB
1133 such as the block-vector are uninitialized whereas
1134 the rest of the code assumes that they are.
1135
1136 We can only unlink the symtab because it was allocated
1137 on the objfile obstack. */
1138 struct symtab *s;
1139
1140 if (objfile->symtabs == subfile->symtab)
1141 objfile->symtabs = objfile->symtabs->next;
1142 else
1143 ALL_OBJFILE_SYMTABS (objfile, s)
1144 if (s->next == subfile->symtab)
1145 {
1146 s->next = s->next->next;
1147 break;
1148 }
1149 subfile->symtab = NULL;
1150 }
1151 }
c906108c
SS
1152 if (subfile->name != NULL)
1153 {
b8c9b27d 1154 xfree ((void *) subfile->name);
c906108c
SS
1155 }
1156 if (subfile->dirname != NULL)
1157 {
b8c9b27d 1158 xfree ((void *) subfile->dirname);
c906108c
SS
1159 }
1160 if (subfile->line_vector != NULL)
1161 {
b8c9b27d 1162 xfree ((void *) subfile->line_vector);
c906108c 1163 }
c906108c
SS
1164
1165 nextsub = subfile->next;
b8c9b27d 1166 xfree ((void *) subfile);
c906108c
SS
1167 }
1168
1169 /* Set this for the main source file. */
1170 if (symtab)
1171 {
1172 symtab->primary = 1;
84a146c9
TT
1173
1174 if (symtab->blockvector)
1175 {
1176 struct block *b = BLOCKVECTOR_BLOCK (symtab->blockvector,
1177 GLOBAL_BLOCK);
1178
1179 set_block_symtab (b, symtab);
1180 }
c906108c
SS
1181 }
1182
cb1df416
DJ
1183 /* Default any symbols without a specified symtab to the primary
1184 symtab. */
1185 if (blockvector)
1186 {
1187 int block_i;
1188
1189 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1190 {
1191 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1192 struct symbol *sym;
1193 struct dict_iterator iter;
1194
4a64f543
MS
1195 /* Inlined functions may have symbols not in the global or
1196 static symbol lists. */
edb3359d
DJ
1197 if (BLOCK_FUNCTION (block) != NULL)
1198 if (SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) == NULL)
1199 SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) = symtab;
1200
8157b174 1201 /* Note that we only want to fix up symbols from the local
98cc87bd
DE
1202 blocks, not blocks coming from included symtabs. That is why
1203 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
8157b174 1204 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
cb1df416
DJ
1205 if (SYMBOL_SYMTAB (sym) == NULL)
1206 SYMBOL_SYMTAB (sym) = symtab;
1207 }
1208 }
1209
c906108c
SS
1210 last_source_file = NULL;
1211 current_subfile = NULL;
99d9066e 1212 pending_macros = NULL;
801e3a5b
JB
1213 if (pending_addrmap)
1214 {
1215 obstack_free (&pending_addrmap_obstack, NULL);
1216 pending_addrmap = NULL;
1217 }
c906108c
SS
1218
1219 return symtab;
1220}
1221
1222/* Push a context block. Args are an identifying nesting level
1223 (checkable when you pop it), and the starting PC address of this
1224 context. */
1225
1226struct context_stack *
1227push_context (int desc, CORE_ADDR valu)
1228{
52f0bd74 1229 struct context_stack *new;
c906108c
SS
1230
1231 if (context_stack_depth == context_stack_size)
1232 {
1233 context_stack_size *= 2;
1234 context_stack = (struct context_stack *)
1235 xrealloc ((char *) context_stack,
c5aa993b 1236 (context_stack_size * sizeof (struct context_stack)));
c906108c
SS
1237 }
1238
1239 new = &context_stack[context_stack_depth++];
1240 new->depth = desc;
1241 new->locals = local_symbols;
1242 new->params = param_symbols;
1243 new->old_blocks = pending_blocks;
1244 new->start_addr = valu;
27aa8d6a 1245 new->using_directives = using_directives;
c906108c
SS
1246 new->name = NULL;
1247
1248 local_symbols = NULL;
1249 param_symbols = NULL;
27aa8d6a 1250 using_directives = NULL;
c906108c
SS
1251
1252 return new;
1253}
0c5e171a 1254
a672ef13 1255/* Pop a context block. Returns the address of the context block just
4a64f543 1256 popped. */
a672ef13 1257
0c5e171a
KD
1258struct context_stack *
1259pop_context (void)
1260{
1261 gdb_assert (context_stack_depth > 0);
1262 return (&context_stack[--context_stack_depth]);
1263}
1264
c906108c 1265\f
357e46e7 1266
4a64f543 1267/* Compute a small integer hash code for the given name. */
c906108c
SS
1268
1269int
0d5cff50 1270hashname (const char *name)
c906108c 1271{
357e46e7 1272 return (hash(name,strlen(name)) % HASHSIZE);
c906108c
SS
1273}
1274\f
1275
1276void
554d387d 1277record_debugformat (const char *format)
c906108c 1278{
554d387d 1279 current_subfile->debugformat = format;
c906108c
SS
1280}
1281
303b6f5d
DJ
1282void
1283record_producer (const char *producer)
1284{
554d387d 1285 current_subfile->producer = producer;
303b6f5d
DJ
1286}
1287
c906108c
SS
1288/* Merge the first symbol list SRCLIST into the second symbol list
1289 TARGETLIST by repeated calls to add_symbol_to_list(). This
1290 procedure "frees" each link of SRCLIST by adding it to the
1291 free_pendings list. Caller must set SRCLIST to a null list after
1292 calling this function.
1293
4a64f543 1294 Void return. */
c906108c
SS
1295
1296void
1297merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
1298{
52f0bd74 1299 int i;
c906108c
SS
1300
1301 if (!srclist || !*srclist)
1302 return;
1303
1304 /* Merge in elements from current link. */
1305 for (i = 0; i < (*srclist)->nsyms; i++)
1306 add_symbol_to_list ((*srclist)->symbol[i], targetlist);
1307
1308 /* Recurse on next. */
1309 merge_symbol_lists (&(*srclist)->next, targetlist);
1310
1311 /* "Free" the current link. */
1312 (*srclist)->next = free_pendings;
1313 free_pendings = (*srclist);
1314}
1315\f
1316/* Initialize anything that needs initializing when starting to read a
1317 fresh piece of a symbol file, e.g. reading in the stuff
1318 corresponding to a psymtab. */
1319
1320void
fba45db2 1321buildsym_init (void)
c906108c
SS
1322{
1323 free_pendings = NULL;
1324 file_symbols = NULL;
1325 global_symbols = NULL;
1326 pending_blocks = NULL;
99d9066e 1327 pending_macros = NULL;
801e3a5b
JB
1328
1329 /* We shouldn't have any address map at this point. */
1330 gdb_assert (! pending_addrmap);
1331 pending_addrmap_interesting = 0;
c906108c
SS
1332}
1333
1334/* Initialize anything that needs initializing when a completely new
1335 symbol file is specified (not just adding some symbols from another
1336 file, e.g. a shared library). */
1337
1338void
fba45db2 1339buildsym_new_init (void)
c906108c
SS
1340{
1341 buildsym_init ();
1342}
This page took 1.062516 seconds and 4 git commands to generate.