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