* Makefile.in: Make check depend on all.
[deliverable/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
d07734e3 1/* Support routines for building symbol tables in GDB's internal format.
93297ea0
JG
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
c0302457
JG
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/* This module provides subroutines used for creating and adding to
22 the symbol table. These routines are called from various symbol-
d07734e3 23 file-reading routines.
c0302457 24
d07734e3
FF
25 Routines to support specific debugging information formats (stabs,
26 DWARF, etc) belong somewhere else. */
c0302457
JG
27
28#include "defs.h"
d07734e3 29#include "bfd.h"
c0302457
JG
30#include "obstack.h"
31#include "symtab.h"
c0302457 32#include "symfile.h" /* Needed for "struct complaint" */
5e2e79f8 33#include "objfiles.h"
51b80b00 34#include "complaints.h"
c0302457 35#include <string.h>
c0302457
JG
36
37/* Ask buildsym.h to define the vars it normally declares `extern'. */
38#define EXTERN /**/
39#include "buildsym.h" /* Our own declarations */
40#undef EXTERN
41
1ab3bf1b
JG
42static int
43compare_line_numbers PARAMS ((const void *, const void *));
44
45static struct blockvector *
46make_blockvector PARAMS ((struct objfile *));
47
1ab3bf1b 48\f
4137c5fc
JG
49/* Initial sizes of data structures. These are realloc'd larger if needed,
50 and realloc'd down to the size actually used, when completed. */
51
52#define INITIAL_CONTEXT_STACK_SIZE 10
4137c5fc 53#define INITIAL_LINE_VECTOR_LENGTH 1000
d07734e3 54
c0302457
JG
55\f
56/* Complaints about the symbols we have encountered. */
57
58struct complaint innerblock_complaint =
59 {"inner block not inside outer block in %s", 0, 0};
60
76512886
JG
61struct complaint innerblock_anon_complaint =
62 {"inner block not inside outer block", 0, 0};
63
c0302457 64struct complaint blockvector_complaint =
76512886 65 {"block at 0x%x out of order", 0, 0};
c0302457 66
c0302457
JG
67\f
68/* maintain the lists of symbols and blocks */
69
70/* Add a symbol to one of the lists of symbols. */
d07734e3 71
c0302457
JG
72void
73add_symbol_to_list (symbol, listhead)
74 struct symbol *symbol;
75 struct pending **listhead;
76{
d07734e3
FF
77 register struct pending *link;
78
c0302457
JG
79 /* We keep PENDINGSIZE symbols in each link of the list.
80 If we don't have a link with room in it, add a new link. */
d07734e3 81 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
c0302457 82 {
c0302457
JG
83 if (free_pendings)
84 {
85 link = free_pendings;
86 free_pendings = link->next;
87 }
88 else
d07734e3
FF
89 {
90 link = (struct pending *) xmalloc (sizeof (struct pending));
91 }
c0302457
JG
92
93 link->next = *listhead;
94 *listhead = link;
95 link->nsyms = 0;
96 }
97
98 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
99}
100
a048c8f5 101/* Find a symbol on a pending list. */
d07734e3 102
a048c8f5
JG
103struct symbol *
104find_symbol_in_list (list, name, length)
105 struct pending *list;
106 char *name;
107 int length;
108{
109 int j;
d07734e3 110 char *pp;
a048c8f5 111
d07734e3
FF
112 while (list != NULL)
113 {
114 for (j = list->nsyms; --j >= 0; )
115 {
116 pp = SYMBOL_NAME (list->symbol[j]);
117 if (*pp == *name && strncmp (pp, name, length) == 0 &&
118 pp[length] == '\0')
119 {
120 return (list->symbol[j]);
121 }
122 }
123 list = list->next;
a048c8f5 124 }
d07734e3 125 return (NULL);
a048c8f5
JG
126}
127
c0302457 128/* At end of reading syms, or in case of quit,
d07734e3 129 really free as many `struct pending's as we can easily find. */
c0302457
JG
130
131/* ARGSUSED */
132void
133really_free_pendings (foo)
134 int foo;
135{
136 struct pending *next, *next1;
137#if 0
138 struct pending_block *bnext, *bnext1;
139#endif
140
141 for (next = free_pendings; next; next = next1)
142 {
143 next1 = next->next;
84ffdec2 144 free ((PTR)next);
c0302457 145 }
d07734e3 146 free_pendings = NULL;
c0302457
JG
147
148#if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
149 for (bnext = pending_blocks; bnext; bnext = bnext1)
150 {
151 bnext1 = bnext->next;
84ffdec2 152 free ((PTR)bnext);
c0302457
JG
153 }
154#endif
d07734e3 155 pending_blocks = NULL;
c0302457 156
d07734e3 157 for (next = file_symbols; next != NULL; next = next1)
c0302457
JG
158 {
159 next1 = next->next;
84ffdec2 160 free ((PTR)next);
c0302457 161 }
d07734e3 162 file_symbols = NULL;
c0302457 163
d07734e3 164 for (next = global_symbols; next != NULL; next = next1)
c0302457
JG
165 {
166 next1 = next->next;
84ffdec2 167 free ((PTR)next);
c0302457 168 }
d07734e3 169 global_symbols = NULL;
c0302457
JG
170}
171
172/* Take one of the lists of symbols and make a block from it.
173 Keep the order the symbols have in the list (reversed from the input file).
174 Put the block on the list of pending blocks. */
175
176void
1ab3bf1b 177finish_block (symbol, listhead, old_blocks, start, end, objfile)
c0302457
JG
178 struct symbol *symbol;
179 struct pending **listhead;
180 struct pending_block *old_blocks;
181 CORE_ADDR start, end;
1ab3bf1b 182 struct objfile *objfile;
c0302457
JG
183{
184 register struct pending *next, *next1;
185 register struct block *block;
186 register struct pending_block *pblock;
187 struct pending_block *opblock;
188 register int i;
d07734e3 189 register int j;
c0302457
JG
190
191 /* Count the length of the list of symbols. */
192
cd46ffad
FF
193 for (next = *listhead, i = 0;
194 next;
195 i += next->nsyms, next = next->next)
d07734e3
FF
196 {
197 /*EMPTY*/;
198 }
c0302457 199
1ab3bf1b 200 block = (struct block *) obstack_alloc (&objfile -> symbol_obstack,
a048c8f5 201 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
c0302457
JG
202
203 /* Copy the symbols into the block. */
204
205 BLOCK_NSYMS (block) = i;
206 for (next = *listhead; next; next = next->next)
207 {
c0302457 208 for (j = next->nsyms - 1; j >= 0; j--)
d07734e3
FF
209 {
210 BLOCK_SYM (block, --i) = next->symbol[j];
211 }
c0302457
JG
212 }
213
214 BLOCK_START (block) = start;
215 BLOCK_END (block) = end;
d07734e3
FF
216 /* Superblock filled in when containing block is made */
217 BLOCK_SUPERBLOCK (block) = NULL;
c0302457
JG
218 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
219
220 /* Put the block in as the value of the symbol that names it. */
221
222 if (symbol)
223 {
224 SYMBOL_BLOCK_VALUE (symbol) = block;
225 BLOCK_FUNCTION (block) = symbol;
226 }
227 else
d07734e3
FF
228 {
229 BLOCK_FUNCTION (block) = NULL;
230 }
c0302457
JG
231
232 /* Now "free" the links of the list, and empty the list. */
233
234 for (next = *listhead; next; next = next1)
235 {
236 next1 = next->next;
237 next->next = free_pendings;
238 free_pendings = next;
239 }
d07734e3 240 *listhead = NULL;
c0302457
JG
241
242 /* Install this block as the superblock
243 of all blocks made since the start of this scope
244 that don't have superblocks yet. */
245
d07734e3 246 opblock = NULL;
c0302457
JG
247 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
248 {
d07734e3
FF
249 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
250 {
c0302457 251#if 1
d07734e3
FF
252 /* Check to be sure the blocks are nested as we receive them.
253 If the compiler/assembler/linker work, this just burns a small
254 amount of time. */
255 if (BLOCK_START (pblock->block) < BLOCK_START (block) ||
256 BLOCK_END (pblock->block) > BLOCK_END (block))
257 {
258 if (symbol)
259 {
260 complain (&innerblock_complaint, SYMBOL_NAME (symbol));
261 }
262 else
263 {
51b80b00 264 complain (&innerblock_anon_complaint);
d07734e3
FF
265 }
266 BLOCK_START (pblock->block) = BLOCK_START (block);
267 BLOCK_END (pblock->block) = BLOCK_END (block);
268 }
c0302457 269#endif
d07734e3
FF
270 BLOCK_SUPERBLOCK (pblock->block) = block;
271 }
c0302457
JG
272 opblock = pblock;
273 }
274
275 /* Record this block on the list of all blocks in the file.
276 Put it after opblock, or at the beginning if opblock is 0.
277 This puts the block in the list after all its subblocks. */
278
279 /* Allocate in the symbol_obstack to save time.
280 It wastes a little space. */
281 pblock = (struct pending_block *)
1ab3bf1b 282 obstack_alloc (&objfile -> symbol_obstack,
c0302457
JG
283 sizeof (struct pending_block));
284 pblock->block = block;
285 if (opblock)
286 {
287 pblock->next = opblock->next;
288 opblock->next = pblock;
289 }
290 else
291 {
292 pblock->next = pending_blocks;
293 pending_blocks = pblock;
294 }
295}
296
1ab3bf1b
JG
297static struct blockvector *
298make_blockvector (objfile)
299 struct objfile *objfile;
c0302457
JG
300{
301 register struct pending_block *next;
302 register struct blockvector *blockvector;
303 register int i;
304
305 /* Count the length of the list of blocks. */
306
d07734e3 307 for (next = pending_blocks, i = 0; next; next = next->next, i++) {;}
c0302457
JG
308
309 blockvector = (struct blockvector *)
1ab3bf1b 310 obstack_alloc (&objfile -> symbol_obstack,
c0302457
JG
311 (sizeof (struct blockvector)
312 + (i - 1) * sizeof (struct block *)));
313
314 /* Copy the blocks into the blockvector.
315 This is done in reverse order, which happens to put
316 the blocks into the proper order (ascending starting address).
317 finish_block has hair to insert each block into the list
318 after its subblocks in order to make sure this is true. */
319
320 BLOCKVECTOR_NBLOCKS (blockvector) = i;
d07734e3
FF
321 for (next = pending_blocks; next; next = next->next)
322 {
323 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
324 }
c0302457
JG
325
326#if 0 /* Now we make the links in the obstack, so don't free them. */
327 /* Now free the links of the list, and empty the list. */
328
329 for (next = pending_blocks; next; next = next1)
330 {
331 next1 = next->next;
332 free (next);
333 }
334#endif
d07734e3 335 pending_blocks = NULL;
c0302457
JG
336
337#if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
338 /* Some compilers output blocks in the wrong order, but we depend
339 on their being in the right order so we can binary search.
340 Check the order and moan about it. FIXME. */
341 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
d07734e3
FF
342 {
343 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
344 {
345 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
346 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)))
347 {
348 complain (&blockvector_complaint,
51b80b00 349 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
d07734e3
FF
350 }
351 }
c0302457
JG
352 }
353#endif
354
d07734e3 355 return (blockvector);
c0302457 356}
d07734e3 357
c0302457 358\f
4137c5fc
JG
359/* Start recording information about source code that came from an included
360 (or otherwise merged-in) source file with a different name. */
c0302457
JG
361
362void
4137c5fc
JG
363start_subfile (name, dirname)
364 char *name;
365 char *dirname;
366{
367 register struct subfile *subfile;
368
369 /* See if this subfile is already known as a subfile of the
370 current main source file. */
371
372 for (subfile = subfiles; subfile; subfile = subfile->next)
373 {
374 if (!strcmp (subfile->name, name))
375 {
376 current_subfile = subfile;
377 return;
378 }
379 }
380
381 /* This subfile is not known. Add an entry for it.
382 Make an entry for this subfile in the list of all subfiles
383 of the current main source file. */
384
385 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
386 subfile->next = subfiles;
387 subfiles = subfile;
388 current_subfile = subfile;
389
390 /* Save its name and compilation directory name */
1ab3bf1b 391 subfile->name = strdup (name);
3416d90b 392 subfile->dirname = (dirname == NULL) ? NULL : strdup (dirname);
4137c5fc
JG
393
394 /* Initialize line-number recording for this subfile. */
d07734e3 395 subfile->line_vector = NULL;
4137c5fc 396}
d07734e3 397
3416d90b
FF
398/* For stabs readers, the first N_SO symbol is assumed to be the source
399 file name, and the subfile struct is initialized using that assumption.
400 If another N_SO symbol is later seen, immediately following the first
401 one, then the first one is assumed to be the directory name and the
402 second one is really the source file name.
403
404 So we have to patch up the subfile struct by moving the old name value to
405 dirname and remembering the new name. Some sanity checking is performed
406 to ensure that the state of the subfile struct is reasonable and that the
407 old name we are assuming to be a directory name actually is (by checking
408 for a trailing '/'). */
409
410void
411patch_subfile_names (subfile, name)
412 struct subfile *subfile;
413 char *name;
414{
415 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
416 && subfile->name[strlen(subfile->name)-1] == '/')
417 {
418 subfile->dirname = subfile->name;
419 subfile->name = strdup (name);
420 }
421}
422
4137c5fc 423\f
a048c8f5
JG
424/* Handle the N_BINCL and N_EINCL symbol types
425 that act like N_SOL for switching source files
426 (different subfiles, as we call them) within one object file,
427 but using a stack rather than in an arbitrary order. */
428
429void
430push_subfile ()
431{
432 register struct subfile_stack *tem
433 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
434
435 tem->next = subfile_stack;
436 subfile_stack = tem;
d07734e3
FF
437 if (current_subfile == NULL || current_subfile->name == NULL)
438 {
439 abort ();
440 }
a048c8f5 441 tem->name = current_subfile->name;
a048c8f5
JG
442}
443
444char *
445pop_subfile ()
446{
447 register char *name;
448 register struct subfile_stack *link = subfile_stack;
449
d07734e3
FF
450 if (link == NULL)
451 {
452 abort ();
453 }
a048c8f5
JG
454 name = link->name;
455 subfile_stack = link->next;
84ffdec2 456 free ((PTR)link);
d07734e3 457 return (name);
a048c8f5 458}
d07734e3 459
a048c8f5 460\f
4137c5fc
JG
461/* Manage the vector of line numbers for each subfile. */
462
463void
464record_line (subfile, line, pc)
465 register struct subfile *subfile;
c0302457
JG
466 int line;
467 CORE_ADDR pc;
468{
469 struct linetable_entry *e;
470 /* Ignore the dummy line number in libg.o */
471
472 if (line == 0xffff)
d07734e3
FF
473 {
474 return;
475 }
c0302457 476
4137c5fc 477 /* Make sure line vector exists and is big enough. */
d07734e3
FF
478 if (!subfile->line_vector)
479 {
480 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
481 subfile->line_vector = (struct linetable *)
4137c5fc
JG
482 xmalloc (sizeof (struct linetable)
483 + subfile->line_vector_length * sizeof (struct linetable_entry));
d07734e3
FF
484 subfile->line_vector->nitems = 0;
485 }
c0302457 486
4137c5fc 487 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
c0302457 488 {
4137c5fc
JG
489 subfile->line_vector_length *= 2;
490 subfile->line_vector = (struct linetable *)
1ab3bf1b 491 xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable)
d07734e3 492 + subfile->line_vector_length * sizeof (struct linetable_entry)));
c0302457
JG
493 }
494
4137c5fc 495 e = subfile->line_vector->item + subfile->line_vector->nitems++;
c0302457
JG
496 e->line = line; e->pc = pc;
497}
4137c5fc
JG
498
499
500/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
501
1ab3bf1b
JG
502static int
503compare_line_numbers (ln1p, ln2p)
504 const PTR ln1p;
505 const PTR ln2p;
4137c5fc 506{
1ab3bf1b
JG
507 return (((struct linetable_entry *) ln1p) -> line -
508 ((struct linetable_entry *) ln2p) -> line);
4137c5fc 509}
1ab3bf1b 510
c0302457
JG
511\f
512/* Start a new symtab for a new source file.
d07734e3
FF
513 Called, for example, when a stabs symbol of type N_SO is seen, or when
514 a DWARF TAG_compile_unit DIE is seen.
515 It indicates the start of data for one original source file. */
c0302457
JG
516
517void
518start_symtab (name, dirname, start_addr)
519 char *name;
520 char *dirname;
521 CORE_ADDR start_addr;
522{
523
524 last_source_file = name;
525 last_source_start_addr = start_addr;
d07734e3
FF
526 file_symbols = NULL;
527 global_symbols = NULL;
c0302457
JG
528 within_function = 0;
529
a048c8f5
JG
530 /* Context stack is initially empty. Allocate first one with room for
531 10 levels; reuse it forever afterward. */
d07734e3
FF
532 if (context_stack == NULL)
533 {
534 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
535 context_stack = (struct context_stack *)
536 xmalloc (context_stack_size * sizeof (struct context_stack));
537 }
c0302457
JG
538 context_stack_depth = 0;
539
c0302457
JG
540 /* Initialize the list of sub source files with one entry
541 for this file (the top-level source file). */
542
d07734e3
FF
543 subfiles = NULL;
544 current_subfile = NULL;
c0302457
JG
545 start_subfile (name, dirname);
546}
547
548/* Finish the symbol definitions for one main source file,
549 close off all the lexical contexts for that file
550 (creating struct block's for them), then make the struct symtab
551 for that file and put it in the list of all such.
552
7b5d9650
FF
553 END_ADDR is the address of the end of the file's text.
554
555 Note that it is possible for end_symtab() to return NULL. In particular,
556 for the DWARF case at least, it will return NULL when it finds a
557 compilation unit that has exactly one DIE, a TAG_compile_unit DIE. This
558 can happen when we link in an object file that was compiled from an empty
559 source file. Returning NULL is probably not the correct thing to do,
560 because then gdb will never know about this empty file (FIXME). */
c0302457
JG
561
562struct symtab *
a048c8f5 563end_symtab (end_addr, sort_pending, sort_linevec, objfile)
c0302457 564 CORE_ADDR end_addr;
4137c5fc
JG
565 int sort_pending;
566 int sort_linevec;
a048c8f5 567 struct objfile *objfile;
c0302457
JG
568{
569 register struct symtab *symtab;
570 register struct blockvector *blockvector;
571 register struct subfile *subfile;
d07734e3 572 register struct context_stack *cstk;
c0302457
JG
573 struct subfile *nextsub;
574
575 /* Finish the lexical context of the last function in the file;
576 pop the context stack. */
577
578 if (context_stack_depth > 0)
579 {
c0302457
JG
580 context_stack_depth--;
581 cstk = &context_stack[context_stack_depth];
582 /* Make a block for the local symbols within. */
583 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1ab3bf1b 584 cstk->start_addr, end_addr, objfile);
a048c8f5 585
d07734e3
FF
586 /* Debug: if context stack still has something in it,
587 we are in trouble. */
a048c8f5 588 if (context_stack_depth > 0)
d07734e3
FF
589 {
590 abort ();
591 }
c0302457
JG
592 }
593
9b280a7f 594 /* It is unfortunate that in xcoff, pending blocks might not be ordered
4137c5fc
JG
595 in this stage. Especially, blocks for static functions will show up at
596 the end. We need to sort them, so tools like `find_pc_function' and
597 `find_pc_block' can work reliably. */
d07734e3
FF
598
599 if (sort_pending && pending_blocks)
600 {
601 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
602 int swapped;
603 do
604 {
605 struct pending_block *pb, *pbnext;
606
607 pb = pending_blocks;
608 pbnext = pb->next;
609 swapped = 0;
610
611 while (pbnext)
612 {
613 /* swap blocks if unordered! */
614
615 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block))
616 {
617 struct block *tmp = pb->block;
618 pb->block = pbnext->block;
619 pbnext->block = tmp;
620 swapped = 1;
621 }
622 pb = pbnext;
623 pbnext = pbnext->next;
624 }
625 } while (swapped);
626 }
4137c5fc 627
c0302457
JG
628 /* Cleanup any undefined types that have been left hanging around
629 (this needs to be done before the finish_blocks so that
d07734e3
FF
630 file_symbols is still good).
631 FIXME: Stabs specific. */
c0302457 632 cleanup_undefined_types ();
d07734e3 633 finish_global_stabs (objfile);
c0302457 634
d07734e3
FF
635 if (pending_blocks == NULL
636 && file_symbols == NULL
637 && global_symbols == NULL)
638 {
639 /* Ignore symtabs that have no functions with real debugging info */
640 blockvector = NULL;
641 }
642 else
643 {
644 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */
645 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
646 objfile);
647 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
648 objfile);
649 blockvector = make_blockvector (objfile);
650 }
c0302457 651
818de002 652#ifdef PROCESS_LINENUMBER_HOOK
9b280a7f 653 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
818de002
PB
654#endif
655
c0302457
JG
656 /* Now create the symtab objects proper, one for each subfile. */
657 /* (The main file is the last one on the chain.) */
658
659 for (subfile = subfiles; subfile; subfile = nextsub)
660 {
1ab3bf1b 661 int linetablesize;
a048c8f5
JG
662 /* If we have blocks of symbols, make a symtab.
663 Otherwise, just ignore this file and any line number info in it. */
d07734e3
FF
664 symtab = NULL;
665 if (blockvector)
666 {
667 if (subfile->line_vector)
668 {
669 /* First, shrink the linetable to make more memory. */
670 linetablesize = sizeof (struct linetable) +
671 subfile->line_vector->nitems * sizeof (struct linetable_entry);
672 subfile->line_vector = (struct linetable *)
673 xrealloc ((char *) subfile->line_vector, linetablesize);
674
675 if (sort_linevec)
676 qsort (subfile->line_vector->item,
677 subfile->line_vector->nitems,
678 sizeof (struct linetable_entry), compare_line_numbers);
679 }
680
681 /* Now, allocate a symbol table. */
682 symtab = allocate_symtab (subfile->name, objfile);
4137c5fc 683
d07734e3
FF
684 /* Fill in its components. */
685 symtab->blockvector = blockvector;
686 if (subfile->line_vector)
687 {
688 /* Reallocate the line table on the symbol obstack */
689 symtab->linetable = (struct linetable *)
690 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
691 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
692 }
693 else
694 {
695 symtab->linetable = NULL;
696 }
8275e802
FF
697 if (subfile->dirname)
698 {
699 /* Reallocate the dirname on the symbol obstack */
700 symtab->dirname = (char *)
701 obstack_alloc (&objfile -> symbol_obstack,
702 strlen (subfile -> dirname) + 1);
703 strcpy (symtab->dirname, subfile->dirname);
704 }
705 else
706 {
707 symtab->dirname = NULL;
708 }
d07734e3
FF
709 symtab->free_code = free_linetable;
710 symtab->free_ptr = NULL;
2b5a8d9c 711
1eeba686 712#ifdef IBM6000_TARGET
d07734e3
FF
713 /* In case we need to duplicate symbol tables (to represent include
714 files), and in case our system needs relocation, we want to
715 relocate the main symbol table node only (for the main file,
716 not for the include files). */
2b5a8d9c 717
d07734e3 718 symtab->nonreloc = TRUE;
2b5a8d9c 719#endif
d07734e3 720 }
3416d90b
FF
721 if (subfile->name != NULL)
722 {
723 free ((PTR) subfile->name);
724 }
725 if (subfile->dirname != NULL)
726 {
727 free ((PTR) subfile->dirname);
728 }
729 if (subfile->line_vector != NULL)
d07734e3 730 {
3416d90b 731 free ((PTR) subfile->line_vector);
d07734e3 732 }
4137c5fc 733
c0302457 734 nextsub = subfile->next;
84ffdec2 735 free ((PTR)subfile);
c0302457
JG
736 }
737
1eeba686 738#ifdef IBM6000_TARGET
2b5a8d9c
PB
739 /* all include symbol tables are non-relocatable, except the main source
740 file's. */
1eeba686 741 if (symtab)
d07734e3
FF
742 {
743 symtab->nonreloc = FALSE;
744 }
2b5a8d9c
PB
745#endif
746
d07734e3
FF
747 last_source_file = NULL;
748 current_subfile = NULL;
4137c5fc 749
d07734e3 750 return (symtab);
c0302457 751}
a048c8f5
JG
752
753
754/* Push a context block. Args are an identifying nesting level (checkable
755 when you pop it), and the starting PC address of this context. */
756
757struct context_stack *
758push_context (desc, valu)
759 int desc;
760 CORE_ADDR valu;
761{
762 register struct context_stack *new;
763
764 if (context_stack_depth == context_stack_size)
765 {
766 context_stack_size *= 2;
767 context_stack = (struct context_stack *)
1ab3bf1b
JG
768 xrealloc ((char *) context_stack,
769 (context_stack_size * sizeof (struct context_stack)));
a048c8f5
JG
770 }
771
772 new = &context_stack[context_stack_depth++];
773 new->depth = desc;
774 new->locals = local_symbols;
775 new->old_blocks = pending_blocks;
776 new->start_addr = valu;
d07734e3 777 new->name = NULL;
a048c8f5 778
d07734e3 779 local_symbols = NULL;
a048c8f5 780
d07734e3 781 return (new);
a048c8f5 782}
d07734e3 783
c0302457
JG
784\f
785/* Initialize anything that needs initializing when starting to read
786 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
787 to a psymtab. */
788
789void
790buildsym_init ()
791{
d07734e3
FF
792 free_pendings = NULL;
793 file_symbols = NULL;
794 global_symbols = NULL;
795 pending_blocks = NULL;
c0302457
JG
796}
797
798/* Initialize anything that needs initializing when a completely new
799 symbol file is specified (not just adding some symbols from another
800 file, e.g. a shared library). */
801
802void
803buildsym_new_init ()
804{
c0302457
JG
805 buildsym_init ();
806}
807
d07734e3 808/* Initializer for this module */
095db7ce 809
c0302457
JG
810void
811_initialize_buildsym ()
812{
c0302457 813}
This page took 0.142516 seconds and 4 git commands to generate.