]> Git Repo - binutils.git/blob - gdb/buildsym.c
comment change
[binutils.git] / gdb / buildsym.c
1 /* Support routines for building symbol tables in GDB's internal format.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3              Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 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-
23    file-reading routines.
24
25    Routines to support specific debugging information formats (stabs,
26    DWARF, etc) belong somewhere else. */
27
28 #include "defs.h"
29 #include "bfd.h"
30 #include "obstack.h"
31 #include "symtab.h"
32 #include "symfile.h"            /* Needed for "struct complaint" */
33 #include "objfiles.h"
34 #include "complaints.h"
35 #include <string.h>
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
42 static int
43 compare_line_numbers PARAMS ((const void *, const void *));
44
45 static struct blockvector *
46 make_blockvector PARAMS ((struct objfile *));
47
48 \f
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
53 #define INITIAL_LINE_VECTOR_LENGTH      1000
54
55 \f
56 /* Complaints about the symbols we have encountered.  */
57
58 struct complaint innerblock_complaint =
59   {"inner block not inside outer block in %s", 0, 0};
60
61 struct complaint innerblock_anon_complaint =
62   {"inner block not inside outer block", 0, 0};
63
64 struct complaint blockvector_complaint = 
65   {"block at 0x%x out of order", 0, 0};
66
67 \f
68 /* maintain the lists of symbols and blocks */
69
70 /* Add a symbol to one of the lists of symbols.  */
71
72 void
73 add_symbol_to_list (symbol, listhead)
74      struct symbol *symbol;
75      struct pending **listhead;
76 {
77   register struct pending *link;
78       
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.  */
81   if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
82     {
83       if (free_pendings)
84         {
85           link = free_pendings;
86           free_pendings = link->next;
87         }
88       else
89         {
90           link = (struct pending *) xmalloc (sizeof (struct pending));
91         }
92
93       link->next = *listhead;
94       *listhead = link;
95       link->nsyms = 0;
96     }
97
98   (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
99 }
100
101 /* Find a symbol on a pending list.  */
102
103 struct symbol *
104 find_symbol_in_list (list, name, length)
105      struct pending *list;
106      char *name;
107      int length;
108 {
109   int j;
110   char *pp;
111
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;
124     }
125   return (NULL);
126 }
127
128 /* At end of reading syms, or in case of quit,
129    really free as many `struct pending's as we can easily find. */
130
131 /* ARGSUSED */
132 void
133 really_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;
144       free ((PTR)next);
145     }
146   free_pendings = NULL;
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;
152       free ((PTR)bnext);
153     }
154 #endif
155   pending_blocks = NULL;
156
157   for (next = file_symbols; next != NULL; next = next1)
158     {
159       next1 = next->next;
160       free ((PTR)next);
161     }
162   file_symbols = NULL;
163
164   for (next = global_symbols; next != NULL; next = next1)
165     {
166       next1 = next->next;
167       free ((PTR)next);
168     }
169   global_symbols = NULL;
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
176 void
177 finish_block (symbol, listhead, old_blocks, start, end, objfile)
178      struct symbol *symbol;
179      struct pending **listhead;
180      struct pending_block *old_blocks;
181      CORE_ADDR start, end;
182      struct objfile *objfile;
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;
189   register int j;
190
191   /* Count the length of the list of symbols.  */
192
193   for (next = *listhead, i = 0;
194        next;
195        i += next->nsyms, next = next->next)
196     {
197       /*EMPTY*/;
198     }
199
200   block = (struct block *) obstack_alloc (&objfile -> symbol_obstack,
201           (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
202
203   /* Copy the symbols into the block.  */
204
205   BLOCK_NSYMS (block) = i;
206   for (next = *listhead; next; next = next->next)
207     {
208       for (j = next->nsyms - 1; j >= 0; j--)
209         {
210           BLOCK_SYM (block, --i) = next->symbol[j];
211         }
212     }
213
214   BLOCK_START (block) = start;
215   BLOCK_END (block) = end;
216  /* Superblock filled in when containing block is made */
217   BLOCK_SUPERBLOCK (block) = NULL;
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
228     {
229       BLOCK_FUNCTION (block) = NULL;
230     }
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     }
240   *listhead = NULL;
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
246   opblock = NULL;
247   for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
248     {
249       if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
250         {
251 #if 1
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,
261                             SYMBOL_SOURCE_NAME (symbol));
262                 }
263               else
264                 {
265                   complain (&innerblock_anon_complaint);
266                 }
267               BLOCK_START (pblock->block) = BLOCK_START (block);
268               BLOCK_END   (pblock->block) = BLOCK_END   (block);
269             }
270 #endif
271           BLOCK_SUPERBLOCK (pblock->block) = block;
272         }
273       opblock = pblock;
274     }
275
276   /* Record this block on the list of all blocks in the file.
277      Put it after opblock, or at the beginning if opblock is 0.
278      This puts the block in the list after all its subblocks.  */
279
280   /* Allocate in the symbol_obstack to save time.
281      It wastes a little space.  */
282   pblock = (struct pending_block *)
283     obstack_alloc (&objfile -> symbol_obstack,
284                    sizeof (struct pending_block));
285   pblock->block = block;
286   if (opblock)
287     {
288       pblock->next = opblock->next;
289       opblock->next = pblock;
290     }
291   else
292     {
293       pblock->next = pending_blocks;
294       pending_blocks = pblock;
295     }
296 }
297
298 static struct blockvector *
299 make_blockvector (objfile)
300       struct objfile *objfile;
301 {
302   register struct pending_block *next;
303   register struct blockvector *blockvector;
304   register int i;
305
306   /* Count the length of the list of blocks.  */
307
308   for (next = pending_blocks, i = 0; next; next = next->next, i++) {;}
309
310   blockvector = (struct blockvector *)
311     obstack_alloc (&objfile -> symbol_obstack,
312                    (sizeof (struct blockvector)
313                     + (i - 1) * sizeof (struct block *)));
314
315   /* Copy the blocks into the blockvector.
316      This is done in reverse order, which happens to put
317      the blocks into the proper order (ascending starting address).
318      finish_block has hair to insert each block into the list
319      after its subblocks in order to make sure this is true.  */
320
321   BLOCKVECTOR_NBLOCKS (blockvector) = i;
322   for (next = pending_blocks; next; next = next->next)
323     {
324       BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
325     }
326
327 #if 0 /* Now we make the links in the obstack, so don't free them.  */
328   /* Now free the links of the list, and empty the list.  */
329
330   for (next = pending_blocks; next; next = next1)
331     {
332       next1 = next->next;
333       free (next);
334     }
335 #endif
336   pending_blocks = NULL;
337
338 #if 1  /* FIXME, shut this off after a while to speed up symbol reading.  */
339   /* Some compilers output blocks in the wrong order, but we depend
340      on their being in the right order so we can binary search. 
341      Check the order and moan about it.  FIXME.  */
342   if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
343     {
344       for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
345         {
346           if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
347               > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)))
348             {
349               complain (&blockvector_complaint, 
350                         BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
351             }
352         }
353     }
354 #endif
355
356   return (blockvector);
357 }
358
359 \f
360 /* Start recording information about source code that came from an included
361    (or otherwise merged-in) source file with a different name.  */
362
363 void
364 start_subfile (name, dirname)
365      char *name;
366      char *dirname;
367 {
368   register struct subfile *subfile;
369
370   /* See if this subfile is already known as a subfile of the
371      current main source file.  */
372
373   for (subfile = subfiles; subfile; subfile = subfile->next)
374     {
375       if (STREQ (subfile->name, name))
376         {
377           current_subfile = subfile;
378           return;
379         }
380     }
381
382   /* This subfile is not known.  Add an entry for it.
383      Make an entry for this subfile in the list of all subfiles
384      of the current main source file.  */
385
386   subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
387   subfile->next = subfiles;
388   subfiles = subfile;
389   current_subfile = subfile;
390
391   /* Save its name and compilation directory name */
392   subfile->name = (name == NULL)? NULL : strdup (name);
393   subfile->dirname = (dirname == NULL) ? NULL : strdup (dirname);
394   
395   /* Initialize line-number recording for this subfile.  */
396   subfile->line_vector = NULL;
397
398   /* Default the source language to whatever can be deduced from
399      the filename.  If nothing can be deduced (such as for a C/C++
400      include file with a ".h" extension), then inherit whatever
401      language the previous subfile had.  This kludgery is necessary
402      because there is no standard way in some object formats to
403      record the source language.  Also, when symtabs are allocated
404      we try to deduce a language then as well, but it is too late
405      for us to use that information while reading symbols, since
406      symtabs aren't allocated until after all the symbols have
407      been processed for a given source file. */
408
409   subfile->language = deduce_language_from_filename (subfile->name);
410   if (subfile->language == language_unknown &&
411       subfile->next != NULL)
412     {
413       subfile->language = subfile->next->language;
414     }
415
416   /* cfront output is a C program, so in most ways it looks like a C
417      program.  But to demangle we need to set the language to C++.  We
418      can distinguish cfront code by the fact that it has #line
419      directives which specify a file name ending in .C.
420
421      So if the filename of this subfile ends in .C, then change the language
422      of any pending subfiles from C to C++.  .cc is also accepted, even
423      though I don't think cfront allows it.  */
424
425   if (subfile->name)
426     {
427       char *p;
428       struct subfile *s;
429
430       p = strrchr (subfile->name, '.');
431       if (p != NULL
432           && (p[1] == 'C' && p[2] == '\0'
433               || p[1] == 'c' && p[2] == 'c' && p[3] == '\0'))
434         for (s = subfiles; s != NULL; s = s->next)
435           if (s->language == language_c)
436             s->language = language_cplus;
437     }
438
439   /* And patch up this file if necessary.  */
440   if (subfile->language == language_c
441       && subfile->next != NULL
442       && subfile->next->language == language_cplus)
443     {
444       subfile->language = language_cplus;
445     }
446 }
447
448 /* For stabs readers, the first N_SO symbol is assumed to be the source
449    file name, and the subfile struct is initialized using that assumption.
450    If another N_SO symbol is later seen, immediately following the first
451    one, then the first one is assumed to be the directory name and the
452    second one is really the source file name.
453
454    So we have to patch up the subfile struct by moving the old name value to
455    dirname and remembering the new name.  Some sanity checking is performed
456    to ensure that the state of the subfile struct is reasonable and that the
457    old name we are assuming to be a directory name actually is (by checking
458    for a trailing '/'). */
459
460 void
461 patch_subfile_names (subfile, name)
462      struct subfile *subfile;
463      char *name;
464 {
465   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
466       && subfile->name[strlen(subfile->name)-1] == '/')
467     {
468       subfile->dirname = subfile->name;
469       subfile->name = strdup (name);
470
471       /* Default the source language to whatever can be deduced from
472          the filename.  If nothing can be deduced (such as for a C/C++
473          include file with a ".h" extension), then inherit whatever
474          language the previous subfile had.  This kludgery is necessary
475          because there is no standard way in some object formats to
476          record the source language.  Also, when symtabs are allocated
477          we try to deduce a language then as well, but it is too late
478          for us to use that information while reading symbols, since
479          symtabs aren't allocated until after all the symbols have
480          been processed for a given source file. */
481
482       subfile->language = deduce_language_from_filename (subfile->name);
483       if (subfile->language == language_unknown &&
484           subfile->next != NULL)
485         {
486           subfile->language = subfile->next->language;
487         }
488     }
489 }
490
491 \f
492 /* Handle the N_BINCL and N_EINCL symbol types
493    that act like N_SOL for switching source files
494    (different subfiles, as we call them) within one object file,
495    but using a stack rather than in an arbitrary order.  */
496
497 void
498 push_subfile ()
499 {
500   register struct subfile_stack *tem
501     = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
502
503   tem->next = subfile_stack;
504   subfile_stack = tem;
505   if (current_subfile == NULL || current_subfile->name == NULL)
506     {
507       abort ();
508     }
509   tem->name = current_subfile->name;
510 }
511
512 char *
513 pop_subfile ()
514 {
515   register char *name;
516   register struct subfile_stack *link = subfile_stack;
517
518   if (link == NULL)
519     {
520       abort ();
521     }
522   name = link->name;
523   subfile_stack = link->next;
524   free ((PTR)link);
525   return (name);
526 }
527
528 \f
529 /* Manage the vector of line numbers for each subfile.  */
530
531 void
532 record_line (subfile, line, pc)
533      register struct subfile *subfile;
534      int line;
535      CORE_ADDR pc;
536 {
537   struct linetable_entry *e;
538   /* Ignore the dummy line number in libg.o */
539
540   if (line == 0xffff)
541     {
542       return;
543     }
544
545   /* Make sure line vector exists and is big enough.  */
546   if (!subfile->line_vector)
547     {
548       subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
549       subfile->line_vector = (struct linetable *)
550         xmalloc (sizeof (struct linetable)
551           + subfile->line_vector_length * sizeof (struct linetable_entry));
552       subfile->line_vector->nitems = 0;
553     }
554
555   if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
556     {
557       subfile->line_vector_length *= 2;
558       subfile->line_vector = (struct linetable *)
559         xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable)
560           + subfile->line_vector_length * sizeof (struct linetable_entry)));
561     }
562
563   e = subfile->line_vector->item + subfile->line_vector->nitems++;
564   e->line = line; e->pc = pc;
565 }
566
567
568 /* Needed in order to sort line tables from IBM xcoff files.  Sigh!  */
569
570 static int
571 compare_line_numbers (ln1p, ln2p)
572      const PTR ln1p;
573      const PTR ln2p;
574 {
575   return (((struct linetable_entry *) ln1p) -> line -
576           ((struct linetable_entry *) ln2p) -> line);
577 }
578
579 \f
580 /* Start a new symtab for a new source file.
581    Called, for example, when a stabs symbol of type N_SO is seen, or when
582    a DWARF TAG_compile_unit DIE is seen.
583    It indicates the start of data for one original source file.  */
584
585 void
586 start_symtab (name, dirname, start_addr)
587      char *name;
588      char *dirname;
589      CORE_ADDR start_addr;
590 {
591
592   last_source_file = name;
593   last_source_start_addr = start_addr;
594   file_symbols = NULL;
595   global_symbols = NULL;
596   within_function = 0;
597
598   /* Context stack is initially empty.  Allocate first one with room for
599      10 levels; reuse it forever afterward.  */
600   if (context_stack == NULL)
601     {
602       context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
603       context_stack = (struct context_stack *)
604         xmalloc (context_stack_size * sizeof (struct context_stack));
605     }
606   context_stack_depth = 0;
607
608   /* Initialize the list of sub source files with one entry
609      for this file (the top-level source file).  */
610
611   subfiles = NULL;
612   current_subfile = NULL;
613   start_subfile (name, dirname);
614 }
615
616 /* Finish the symbol definitions for one main source file,
617    close off all the lexical contexts for that file
618    (creating struct block's for them), then make the struct symtab
619    for that file and put it in the list of all such.
620
621    END_ADDR is the address of the end of the file's text.
622    SECTION is the section number (in objfile->section_offsets) of
623    the blockvector and linetable.
624
625    Note that it is possible for end_symtab() to return NULL.  In particular,
626    for the DWARF case at least, it will return NULL when it finds a
627    compilation unit that has exactly one DIE, a TAG_compile_unit DIE.  This
628    can happen when we link in an object file that was compiled from an empty
629    source file.  Returning NULL is probably not the correct thing to do,
630    because then gdb will never know about this empty file (FIXME). */
631
632 struct symtab *
633 end_symtab (end_addr, sort_pending, sort_linevec, objfile, section)
634      CORE_ADDR end_addr;
635      int sort_pending;
636      int sort_linevec;
637      struct objfile *objfile;
638      int section;
639 {
640   register struct symtab *symtab;
641   register struct blockvector *blockvector;
642   register struct subfile *subfile;
643   register struct context_stack *cstk;
644   struct subfile *nextsub;
645
646   /* Finish the lexical context of the last function in the file;
647      pop the context stack.  */
648
649   if (context_stack_depth > 0)
650     {
651       context_stack_depth--;
652       cstk = &context_stack[context_stack_depth];
653       /* Make a block for the local symbols within.  */
654       finish_block (cstk->name, &local_symbols, cstk->old_blocks,
655                     cstk->start_addr, end_addr, objfile);
656
657       /* Debug: if context stack still has something in it,
658          we are in trouble.  */
659       if (context_stack_depth > 0)
660         {
661           abort ();
662         }
663     }
664
665   /* It is unfortunate that in xcoff, pending blocks might not be ordered
666      in this stage. Especially, blocks for static functions will show up at
667      the end.  We need to sort them, so tools like `find_pc_function' and
668      `find_pc_block' can work reliably. */
669
670   if (sort_pending && pending_blocks)
671     {
672       /* FIXME!  Remove this horrid bubble sort and use qsort!!! */
673       int swapped;
674       do
675         {
676           struct pending_block *pb, *pbnext;
677           
678           pb = pending_blocks;
679           pbnext = pb->next;
680           swapped = 0;
681
682           while (pbnext)
683             {
684               /* swap blocks if unordered! */
685           
686               if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) 
687                 {
688                   struct block *tmp = pb->block;
689                   pb->block = pbnext->block;
690                   pbnext->block = tmp;
691                   swapped = 1;
692                 }
693               pb = pbnext;
694               pbnext = pbnext->next;
695             }
696         } while (swapped);
697     }
698
699   /* Cleanup any undefined types that have been left hanging around
700      (this needs to be done before the finish_blocks so that
701      file_symbols is still good).
702      FIXME:  Stabs specific. */
703   cleanup_undefined_types ();
704   finish_global_stabs (objfile);
705
706   if (pending_blocks == NULL
707       && file_symbols == NULL
708       && global_symbols == NULL)
709     {
710       /* Ignore symtabs that have no functions with real debugging info */
711       blockvector = NULL;
712     }
713   else
714     {
715       /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */
716       finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
717                     objfile);
718       finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
719                     objfile);
720       blockvector = make_blockvector (objfile);
721     }
722
723 #ifdef PROCESS_LINENUMBER_HOOK
724   PROCESS_LINENUMBER_HOOK ();                   /* Needed for xcoff. */
725 #endif
726
727   /* Now create the symtab objects proper, one for each subfile.  */
728   /* (The main file is the last one on the chain.)  */
729
730   for (subfile = subfiles; subfile; subfile = nextsub)
731     {
732       int linetablesize;
733       /* If we have blocks of symbols, make a symtab.
734          Otherwise, just ignore this file and any line number info in it.  */
735       symtab = NULL;
736       if (blockvector)
737         {
738           if (subfile->line_vector)
739             {
740               /* First, shrink the linetable to make more memory.  */
741               linetablesize = sizeof (struct linetable) +
742                 subfile->line_vector->nitems * sizeof (struct linetable_entry);
743               subfile->line_vector = (struct linetable *)
744                 xrealloc ((char *) subfile->line_vector, linetablesize);
745
746               if (sort_linevec)
747                 qsort (subfile->line_vector->item,
748                        subfile->line_vector->nitems,
749                        sizeof (struct linetable_entry), compare_line_numbers);
750             }
751
752           /* Now, allocate a symbol table.  */
753           symtab = allocate_symtab (subfile->name, objfile);
754
755           /* Fill in its components.  */
756           symtab->blockvector = blockvector;
757           if (subfile->line_vector)
758             {
759               /* Reallocate the line table on the symbol obstack */
760               symtab->linetable = (struct linetable *) 
761                 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
762               memcpy (symtab->linetable, subfile->line_vector, linetablesize);
763             }
764           else
765             {
766               symtab->linetable = NULL;
767             }
768           symtab->block_line_section = section;
769           if (subfile->dirname)
770             {
771               /* Reallocate the dirname on the symbol obstack */
772               symtab->dirname = (char *)
773                 obstack_alloc (&objfile -> symbol_obstack,
774                                strlen (subfile -> dirname) + 1);
775               strcpy (symtab->dirname, subfile->dirname);
776             }
777           else
778             {
779               symtab->dirname = NULL;
780             }
781           symtab->free_code = free_linetable;
782           symtab->free_ptr = NULL;
783
784           /* Use whatever language we have been using for this subfile,
785              not the one that was deduced in allocate_symtab from the
786              filename.  We already did our own deducing when we created
787              the subfile, and we may have altered our opinion of what
788              language it is from things we found in the symbols. */
789           symtab->language = subfile->language;
790
791           /* All symtabs for the main file and the subfiles share a
792              blockvector, so we need to clear primary for everything but
793              the main file.  */
794
795           symtab->primary = 0;
796         }
797       if (subfile->name != NULL)
798         {
799           free ((PTR) subfile->name);
800         }
801       if (subfile->dirname != NULL)
802         {
803           free ((PTR) subfile->dirname);
804         }
805       if (subfile->line_vector != NULL)
806         {
807           free ((PTR) subfile->line_vector);
808         }
809
810       nextsub = subfile->next;
811       free ((PTR)subfile);
812     }
813
814   /* Set this for the main source file.  */
815   if (symtab)
816     {
817       symtab->primary = 1;
818     }
819
820   last_source_file = NULL;
821   current_subfile = NULL;
822
823   return (symtab);
824 }
825
826
827 /* Push a context block.  Args are an identifying nesting level (checkable
828    when you pop it), and the starting PC address of this context.  */
829
830 struct context_stack *
831 push_context (desc, valu)
832      int desc;
833      CORE_ADDR valu;
834 {
835   register struct context_stack *new;
836
837   if (context_stack_depth == context_stack_size)
838     {
839       context_stack_size *= 2;
840       context_stack = (struct context_stack *)
841         xrealloc ((char *) context_stack,
842                   (context_stack_size * sizeof (struct context_stack)));
843     }
844
845   new = &context_stack[context_stack_depth++];
846   new->depth = desc;
847   new->locals = local_symbols;
848   new->old_blocks = pending_blocks;
849   new->start_addr = valu;
850   new->name = NULL;
851
852   local_symbols = NULL;
853
854   return (new);
855 }
856
857 \f
858 /* Compute a small integer hash code for the given name. */
859
860 int
861 hashname (name)
862      char *name;
863 {
864   register char *p = name;
865   register int total = p[0];
866   register int c;
867
868   c = p[1];
869   total += c << 2;
870   if (c)
871     {
872       c = p[2];
873       total += c << 4;
874       if (c)
875         {
876           total += p[3] << 6;
877         }
878     }
879
880   /* Ensure result is positive.  */
881   if (total < 0)
882     {
883       total += (1000 << 6);
884     }
885   return (total % HASHSIZE);
886 }
887
888 \f
889 /* Initialize anything that needs initializing when starting to read
890    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
891    to a psymtab.  */
892
893 void
894 buildsym_init ()
895 {
896   free_pendings = NULL;
897   file_symbols = NULL;
898   global_symbols = NULL;
899   pending_blocks = NULL;
900 }
901
902 /* Initialize anything that needs initializing when a completely new
903    symbol file is specified (not just adding some symbols from another
904    file, e.g. a shared library).  */
905
906 void
907 buildsym_new_init ()
908 {
909   buildsym_init ();
910 }
911
912 /* Initializer for this module */
913
914 void
915 _initialize_buildsym ()
916 {
917 }
This page took 0.076627 seconds and 4 git commands to generate.