1 /* Generic symbol file reading for the GNU debugger, GDB.
2 Copyright 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
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.
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.
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. */
30 #include "breakpoint.h"
35 #include <sys/types.h>
40 CORE_ADDR entry_point; /* Where execution starts in symfile */
42 extern int info_verbose;
45 extern char *getenv ();
46 extern char *rindex ();
48 extern CORE_ADDR startup_file_start; /* From blockframe.c */
49 extern CORE_ADDR startup_file_end; /* From blockframe.c */
51 /* Functions this file defines */
52 static struct objfile *symfile_open ();
53 static struct sym_fns *symfile_init ();
54 static void clear_symtab_users_once ();
56 static void free_all_psymtabs ();
57 static void free_all_symtabs ();
59 /* List of all available sym_fns. */
61 struct sym_fns *symtab_fns = NULL;
63 /* Saves the sym_fns of the current symbol table, so we can call
64 the right XXX_new_init function when we free it. FIXME. This
65 should be extended to calling the new_init function for each
66 existing symtab or psymtab, since the main symbol file and
67 subsequent added symbol files can have different types. */
69 static struct sym_fns *symfile_fns;
71 /* Allocate an obstack to hold objects that should be freed
72 when we load a new symbol table.
73 This includes the symbols made by dbxread
74 and the types that are not permanent. */
76 struct obstack obstack1;
78 struct obstack *symbol_obstack = &obstack1;
80 /* This obstack will be used for partial_symbol objects. It can
81 probably actually be the same as the symbol_obstack above, but I'd
82 like to keep them seperate for now. If I want to later, I'll
83 replace one with the other. */
85 struct obstack obstack2;
87 struct obstack *psymbol_obstack = &obstack2;
89 /* The object file that the main symbol table was loaded from (e.g. the
90 argument to the "symbol-file" or "file" command). */
92 struct objfile *symfile_objfile = 0;
94 /* Structures with which to manage partial symbol allocation. */
96 struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0};
98 /* Flag for whether user will be reloading symbols multiple times.
99 Defaults to ON for VxWorks, otherwise OFF. */
101 #ifdef SYMBOL_RELOADING_DEFAULT
102 int symbol_reloading = SYMBOL_RELOADING_DEFAULT;
104 int symbol_reloading = 0;
107 /* Structure to manage complaints about symbol file contents. */
109 struct complaint complaint_root[1] = {
110 {(char *)0, 0, complaint_root},
113 /* Some actual complaints. */
115 struct complaint oldsyms_complaint = {
116 "Replacing old symbols for `%s'", 0, 0 };
118 struct complaint empty_symtab_complaint = {
119 "Empty symbol table found for `%s'", 0, 0 };
122 /* In the following sort, we always make sure that
123 register debug symbol declarations always come before regular
124 debug symbol declarations (as might happen when parameters are
125 then put into registers by the compiler). */
128 compare_symbols (s1, s2)
129 struct symbol **s1, **s2;
131 register int namediff;
133 /* Compare the initial characters. */
134 namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
135 if (namediff != 0) return namediff;
137 /* If they match, compare the rest of the names. */
138 namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
139 if (namediff != 0) return namediff;
141 /* For symbols of the same name, registers should come first. */
142 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
143 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
146 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
150 register struct block *b;
152 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
153 sizeof (struct symbol *), compare_symbols);
156 /* Call sort_symtab_syms to sort alphabetically
157 the symbols of each block of one symtab. */
161 register struct symtab *s;
163 register struct blockvector *bv;
166 register struct block *b;
170 bv = BLOCKVECTOR (s);
171 nbl = BLOCKVECTOR_NBLOCKS (bv);
172 for (i = 0; i < nbl; i++)
174 b = BLOCKVECTOR_BLOCK (bv, i);
175 if (BLOCK_SHOULD_SORT (b))
181 sort_all_symtab_syms ()
183 register struct symtab *s;
185 for (s = symtab_list; s; s = s->next)
187 sort_symtab_syms (s);
191 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
192 (and add a null character at the end in the copy).
193 Returns the address of the copy. */
196 obsavestring (ptr, size)
200 register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
201 /* Open-coded bcopy--saves function call time.
202 These strings are usually short. */
204 register char *p1 = ptr;
205 register char *p2 = p;
206 char *end = ptr + size;
214 /* Concatenate strings S1, S2 and S3; return the new string.
215 Space is found in the symbol_obstack. */
218 obconcat (s1, s2, s3)
221 register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
222 register char *val = (char *) obstack_alloc (symbol_obstack, len);
229 /* Accumulate the misc functions in bunches of 127.
230 At the end, copy them all into one newly allocated structure. */
232 #define MISC_BUNCH_SIZE 127
236 struct misc_bunch *next;
237 struct misc_function contents[MISC_BUNCH_SIZE];
240 /* Bunch currently being filled up.
241 The next field points to chain of filled bunches. */
243 static struct misc_bunch *misc_bunch;
245 /* Number of slots filled in current bunch. */
247 static int misc_bunch_index;
249 /* Total number of misc functions recorded so far. */
251 static int misc_count;
258 misc_bunch_index = MISC_BUNCH_SIZE;
262 prim_record_misc_function (name, address, misc_type)
265 enum misc_function_type misc_type;
267 register struct misc_bunch *new;
269 if (misc_bunch_index == MISC_BUNCH_SIZE)
271 new = (struct misc_bunch *) xmalloc (sizeof (struct misc_bunch));
272 misc_bunch_index = 0;
273 new->next = misc_bunch;
276 misc_bunch->contents[misc_bunch_index].name = name;
277 misc_bunch->contents[misc_bunch_index].address = address;
278 misc_bunch->contents[misc_bunch_index].type = misc_type;
279 misc_bunch->contents[misc_bunch_index].misc_info = 0;
285 compare_misc_functions (fn1, fn2)
286 struct misc_function *fn1, *fn2;
288 /* Return a signed result based on unsigned comparisons
289 so that we sort into unsigned numeric order. */
290 if (fn1->address < fn2->address)
292 if (fn1->address > fn2->address)
299 discard_misc_bunches (foo)
302 register struct misc_bunch *next;
306 next = misc_bunch->next;
312 /* After adding things to the vector, sort or re-sort it into address order. */
314 sort_misc_function_vector ()
316 qsort (misc_function_vector, misc_function_count,
317 sizeof (struct misc_function),
318 compare_misc_functions);
321 /* Compact duplicate entries out of the misc function vector by walking
322 through the vector and compacting out entries with duplicate addresses
325 When files contain multiple sources of symbol information, it is
326 possible for the misc function vector to contain many duplicate entries.
327 As an example, SVR4 systems use ELF formatted object files, which
328 usually contain at least two different types of symbol tables (a
329 standard ELF one and a smaller dynamic linking table), as well as
330 DWARF debugging information for files compiled with -g.
332 Without compacting, the misc function vector for gdb itself contains
333 over a 1000 duplicates, about a third of the total table size. Aside
334 from the potential trap of not noticing that two successive entries
335 identify the same location, this duplication impacts the time required
336 to linearly scan the table, which is done in a number of places. So
337 just do one linear scan here and toss out the duplicates.
339 Note that the strings themselves are allocated on the symbol_obstack,
340 so we can't easily reclaim their memory. They will get automatically
341 freed when the symbol table is freed.
343 Also note we only go up to the next to last entry within the loop
344 and then copy the last entry explicitly after the loop terminates.
346 Since the different sources of information for each symbol may
347 have different levels of "completeness", we may have duplicates
348 that have one entry with type "mf_unknown" and the other with a
349 known type. So if the one we are leaving alone has type mf_unknown,
350 overwrite its type with the type from the one we are compacting out. */
353 compact_misc_function_vector ()
355 struct misc_function *copyfrom;
356 struct misc_function *copyto;
358 if (misc_function_count == 0)
361 copyfrom = copyto = misc_function_vector;
362 while (copyfrom < misc_function_vector + misc_function_count - 1)
364 if (copyfrom -> address == (copyfrom + 1) -> address
365 && (strcmp (copyfrom -> name, (copyfrom + 1) -> name) == 0))
367 if ((copyfrom + 1) -> type == mf_unknown)
369 (copyfrom + 1) -> type = copyfrom -> type;
375 *copyto++ = *copyfrom++;
378 *copyto++ = *copyfrom++;
379 misc_function_count = copyto - misc_function_vector;
380 misc_function_vector = (struct misc_function *)
381 xrealloc (misc_function_vector,
382 misc_function_count * sizeof (struct misc_function));
386 /* INCLINK nonzero means bunches are from an incrementally-linked file.
387 Add them to the existing bunches.
388 Otherwise INCLINK is zero, and we start from scratch. */
390 condense_misc_bunches (inclink)
394 register struct misc_bunch *bunch;
399 = (struct misc_function *)
400 xrealloc (misc_function_vector, (misc_count + misc_function_count)
401 * sizeof (struct misc_function));
402 j = misc_function_count;
407 = (struct misc_function *)
408 xmalloc (misc_count * sizeof (struct misc_function));
415 for (i = 0; i < misc_bunch_index; i++, j++)
417 misc_function_vector[j] = bunch->contents[i];
418 #ifdef NAMES_HAVE_UNDERSCORE
419 if (misc_function_vector[j].name[0] == '_')
420 misc_function_vector[j].name++;
422 #ifdef SOME_NAMES_HAVE_DOT
423 if (misc_function_vector[j].name[0] == '.')
424 misc_function_vector[j].name++;
429 misc_bunch_index = MISC_BUNCH_SIZE;
432 if (misc_function_count + misc_count != j) /* DEBUG */
433 printf_filtered ("Function counts are off! %d + %d != %d\n",
434 misc_function_count, misc_count, j);
436 misc_function_count = j;
438 /* Sort the misc functions by address. */
440 sort_misc_function_vector ();
442 /* Compact out any duplicates. */
444 compact_misc_function_vector ();
448 /* Get the symbol table that corresponds to a partial_symtab.
449 This is fast after the first time you do it. In fact, there
450 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
454 psymtab_to_symtab (pst)
455 register struct partial_symtab *pst;
457 /* If it's been looked up before, return it. */
461 /* If it has not yet been read in, read it. */
464 (*pst->read_symtab) (pst);
470 /* Process a symbol file, as either the main file or as a dynamically
473 NAME is the file name (which will be tilde-expanded and made
474 absolute herein) (but we don't free or modify NAME itself).
475 FROM_TTY says how verbose to be. MAINLINE specifies whether this
476 is the main symbol file, or whether it's an extra symbol file such
477 as dynamically loaded code. If !mainline, ADDR is the address
478 where the text segment was loaded. If VERBO, the caller has printed
479 a verbose message about the symbol reading (and complaints can be
480 more terse about it). */
483 syms_from_objfile (objfile, addr, mainline, verbo)
484 struct objfile *objfile;
491 bfd *sym_bfd = objfile->obfd;
493 /* There is a distinction between having no symbol table
494 (we refuse to read the file, leaving the old set of symbols around)
495 and having no debugging symbols in your symbol table (we read
496 the file and end up with a mostly empty symbol table). */
498 if (!(bfd_get_file_flags (sym_bfd) & HAS_SYMS))
501 /* Save startup file's range of PC addresses to help blockframe.c
502 decide where the bottom of the stack is. */
503 if (bfd_get_file_flags (sym_bfd) & EXEC_P)
505 /* Executable file -- record its entry point so we'll recognize
506 the startup file because it contains the entry point. */
507 entry_point = bfd_get_start_address (sym_bfd);
511 /* Examination of non-executable.o files. Short-circuit this stuff. */
512 /* ~0 will not be in any file, we hope. */
514 /* set the startup file to be an empty range. */
515 startup_file_start = 0;
516 startup_file_end = 0;
519 sf = symfile_init (objfile);
523 /* Since no error yet, throw away the old symbol table. */
526 free_objfile (symfile_objfile);
529 (*sf->sym_new_init) ();
531 /* For mainline, caller didn't know the specified address of the
532 text section. We fix that here. */
533 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
534 addr = bfd_section_vma (sym_bfd, text_sect);
537 /* Allow complaints to appear for this new file, and record how
540 clear_complaints(1, verbo);
542 (*sf->sym_read) (sf, addr, mainline);
544 /* Don't allow char * to have a typename (else would get caddr_t.) */
545 /* Ditto void *. FIXME should do this for all the builtin types. */
547 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
548 TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
552 /* OK, make it the "real" symbol file. */
553 symfile_objfile = objfile;
557 /* If we have wiped out any old symbol tables, clean up. */
558 clear_symtab_users_once ();
560 /* We're done reading the symbol file; finish off complaints. */
561 clear_complaints(0, verbo);
565 /* Process a symbol file, as either the main file or as a dynamically
568 NAME is the file name (which will be tilde-expanded and made
569 absolute herein) (but we don't free or modify NAME itself).
570 FROM_TTY says how verbose to be. MAINLINE specifies whether this
571 is the main symbol file, or whether it's an extra symbol file such
572 as dynamically loaded code. If !mainline, ADDR is the address
573 where the text segment was loaded. */
576 symbol_file_add (name, from_tty, addr, mainline)
582 struct objfile *objfile;
585 objfile = symfile_open (name);
586 sym_bfd = objfile->obfd;
588 /* There is a distinction between having no symbol table
589 (we refuse to read the file, leaving the old set of symbols around)
590 and having no debugging symbols in your symbol table (we read
591 the file and end up with a mostly empty symbol table, but with lots
592 of stuff in the misc function vector). */
594 if (!(bfd_get_file_flags (sym_bfd) & HAS_SYMS))
596 error ("%s has no symbol-table", name);
599 if ((symtab_list || partial_symtab_list)
602 && !query ("Load new symbol table from \"%s\"? ", name))
603 error ("Not confirmed.");
605 if (from_tty || info_verbose)
607 printf_filtered ("Reading symbols from %s...", name);
612 syms_from_objfile (objfile, addr, mainline, from_tty);
614 if (from_tty || info_verbose)
616 printf_filtered ("done.\n");
621 /* This is the symbol-file command. Read the file, analyze its symbols,
622 and add a struct symtab to symtab_list. */
625 symbol_file_command (name, from_tty)
634 if (symfile_objfile) {
635 if ((symtab_list || partial_symtab_list)
637 && !query ("Discard symbol table from `%s'? ",
638 symfile_objfile->name))
639 error ("Not confirmed.");
640 free_objfile (symfile_objfile);
643 /* FIXME, this does not account for the main file and subsequent
644 files (shared libs, dynloads, etc) having different formats.
645 It only calls the cleanup routine for the main file's format. */
647 (*symfile_fns->sym_new_init) ();
654 /* Getting new symbols may change our opinion about what is
656 reinit_frame_cache ();
658 symbol_file_add (name, from_tty, (CORE_ADDR)0, 1);
661 /* Open NAME and hand it off to BFD for preliminary analysis. Result
662 is newly malloc'd struct objfile *, which includes a newly malloc'd`
663 copy of NAME (tilde-expanded and made absolute).
664 In case of trouble, error() is called. */
666 static struct objfile *
673 struct objfile *objfile;
675 name = tilde_expand (name); /* Returns 1st new malloc'd copy */
677 /* Look down path for it, allocate 2nd new malloc'd copy. */
678 desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
680 make_cleanup (free, name);
681 perror_with_name (name);
683 free (name); /* Free 1st new malloc'd copy */
684 name = absolute_name; /* Keep 2nd malloc'd copy in objfile and bfd */
686 sym_bfd = bfd_fdopenr (name, NULL, desc);
690 make_cleanup (free, name);
691 error ("Could not open `%s' to read symbols: %s",
692 name, bfd_errmsg (bfd_error));
695 if (!bfd_check_format (sym_bfd, bfd_object)) {
696 bfd_close (sym_bfd); /* This also closes desc */
697 make_cleanup (free, name);
698 error ("\"%s\": can't read symbols: %s.",
699 name, bfd_errmsg (bfd_error));
702 objfile = allocate_objfile (sym_bfd, name);
707 /* Allocate a new objfile struct, fill it in as best we can, and return it.
708 FIXME-soon! Eventually, the objfile will contain the obstack in which
709 the symtabs and psymtabs are contained, so they can all be blown away
710 cheaply and easily. */
713 allocate_objfile (abfd, filename)
717 struct objfile *objfile;
719 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
720 bzero (objfile, sizeof (*objfile));
722 objfile->obfd = abfd;
723 objfile->name = filename;
725 objfile->symtabs = 0; /* Don't have any yet */
726 objfile->psymtabs = 0; /* Don't have any yet */
728 objfile->mtime = bfd_get_mtime (abfd);
730 /* Chain it to the list. */
731 objfile->next = object_files;
732 object_files = objfile;
738 /* Destroy an objfile and all the symtabs and psymtabs under it. */
741 free_objfile (objfile)
742 struct objfile *objfile;
747 free (objfile->name);
749 bfd_close (objfile->obfd);
751 /* Remove it from the chain of all objfiles. */
752 if (object_files == objfile)
753 object_files = objfile->next;
754 else for (ofp = object_files; ofp; ofp = ofp->next) {
755 if (ofp->next == objfile)
756 ofp->next = objfile->next;
759 /* FIXME! This should only free those associated with the objfile
760 being passed to us. THIS IS A KLUDGE TO BOOTSTRAP US. */
761 free_all_psymtabs ();
768 /* Link a new symtab_fns into the global symtab_fns list.
769 Called by various _initialize routines. */
775 sf->next = symtab_fns;
780 /* Initialize to read symbols from the symbol file sym_bfd. It either
781 returns or calls error(). The result is a malloc'd struct sym_fns
782 that contains cached information about the symbol file. */
784 static struct sym_fns *
785 symfile_init (objfile)
786 struct objfile *objfile;
788 struct sym_fns *sf, *sf2;
789 bfd *sym_bfd = objfile->obfd;
791 for (sf = symtab_fns; sf != NULL; sf = sf->next)
793 if (!strncmp (bfd_get_target (sym_bfd), sf->sym_name, sf->sym_namelen))
795 sf2 = (struct sym_fns *)xmalloc (sizeof (*sf2));
796 /* FIXME, who frees this? */
798 sf2->objfile = objfile;
799 sf2->sym_bfd = sym_bfd;
800 sf2->sym_private = 0; /* Not alloc'd yet */
801 (*sf2->sym_init) (sf2);
805 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
806 bfd_get_target (sym_bfd));
807 return 0; /* Appease lint. */
810 /* This function runs the load command of our current target. */
813 load_command (arg, from_tty)
817 target_load (arg, from_tty);
820 /* This function allows the addition of incrementally linked object files.
821 It does not modify any state in the target, only in the debugger. */
825 add_symbol_file_command (arg_string, from_tty)
832 /* Getting new symbols may change our opinion about what is
834 reinit_frame_cache ();
837 error ("add-symbol-file takes a file name and an address");
839 arg_string = tilde_expand (arg_string);
840 make_cleanup (free, arg_string);
842 for( ; *arg_string == ' '; arg_string++ );
844 for( ; *arg_string && *arg_string != ' ' ; arg_string++ );
845 *arg_string++ = (char) 0;
848 error ("add-symbol-file takes a file name and an address");
850 text_addr = parse_and_eval_address (arg_string);
854 if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
855 name, local_hex_string (text_addr)))
856 error ("Not confirmed.");
858 symbol_file_add (name, 0, text_addr, 0);
861 /* Re-read symbols if a symbol-file has changed. */
865 struct objfile *objfile;
869 /* With the addition of shared libraries, this should be modified,
870 the load time should be saved in the partial symbol tables, since
871 different tables may come from different source files. FIXME.
872 This routine should then walk down each partial symbol table
873 and see if the symbol table that it originates from has been changed
876 for (objfile = object_files; objfile; objfile = objfile->next) {
878 new_modtime = bfd_get_mtime (objfile->obfd);
879 if (new_modtime != objfile->mtime) {
880 printf_filtered ("`%s' has changed; re-reading symbols.\n",
882 /* FIXME, this should use a different command...that would only
883 affect this objfile's symbols. */
884 symbol_file_command (objfile->name, 0);
885 objfile->mtime = new_modtime;
892 breakpoint_re_set ();
895 /* This function is really horrible, but to avoid it, there would need
896 to be more filling in of forward references. */
898 fill_in_vptr_fieldno (type)
901 if (TYPE_VPTR_FIELDNO (type) < 0)
904 for (i = 1; i < TYPE_N_BASECLASSES (type); i++)
906 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
907 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
909 TYPE_VPTR_FIELDNO (type)
910 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
911 TYPE_VPTR_BASETYPE (type)
912 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
919 /* Functions to handle complaints during symbol reading. */
921 /* How many complaints about a particular thing should be printed before
922 we stop whining about it? Default is no whining at all, since so many
923 systems have ill-constructed symbol files. */
925 static unsigned stop_whining = 0;
927 /* Should each complaint be self explanatory, or should we assume that
928 a series of complaints is being produced?
929 case 0: self explanatory message.
930 case 1: First message of a series that must start off with explanation.
931 case 2: Subsequent message, when user already knows we are reading
932 symbols and we can just state our piece. */
934 static int complaint_series = 0;
936 /* Print a complaint about the input symbols, and link the complaint block
937 into a chain for later handling. */
940 complain (complaint, val)
941 struct complaint *complaint;
944 complaint->counter++;
945 if (complaint->next == 0) {
946 complaint->next = complaint_root->next;
947 complaint_root->next = complaint;
949 if (complaint->counter > stop_whining)
953 switch (complaint_series + (info_verbose << 1)) {
955 /* Isolated messages, must be self-explanatory. */
957 puts_filtered ("During symbol reading, ");
959 printf_filtered (complaint->message, val);
960 puts_filtered (".\n");
963 /* First of a series, without `set verbose'. */
965 puts_filtered ("During symbol reading...");
966 printf_filtered (complaint->message, val);
967 puts_filtered ("...");
972 /* Subsequent messages of a series, or messages under `set verbose'.
973 (We'll already have produced a "Reading in symbols for XXX..." message
974 and will clean up at the end with a newline.) */
976 printf_filtered (complaint->message, val);
977 puts_filtered ("...");
982 /* Clear out all complaint counters that have ever been incremented.
983 If sym_reading is 1, be less verbose about successive complaints,
984 since the messages are appearing all together during a command that
985 reads symbols (rather than scattered around as psymtabs get fleshed
986 out into symtabs at random times). If noisy is 1, we are in a
987 noisy symbol reading command, and our caller will print enough
988 context for the user to figure it out. */
991 clear_complaints (sym_reading, noisy)
997 for (p = complaint_root->next; p != complaint_root; p = p->next)
1000 if (!sym_reading && !noisy && complaint_series > 1) {
1001 /* Terminate previous series, since caller won't. */
1002 puts_filtered ("\n");
1005 complaint_series = sym_reading? 1 + noisy: 0;
1009 deduce_language_from_filename (filename)
1012 char *c = rindex (filename, '.');
1014 if (!c) ; /* Get default. */
1015 else if(!strcmp(c,".mod"))
1017 else if(!strcmp(c,".c"))
1019 else if(!strcmp(c,".cc") || !strcmp(c,".C"))
1020 return language_cplus;
1022 return language_unknown; /* default */
1027 Allocate and partly initialize a new symbol table. Return a pointer
1028 to it. error() if no space.
1030 Caller must set these fields:
1036 initialize any EXTRA_SYMTAB_INFO
1037 possibly free_named_symtabs (symtab->filename);
1038 symtab->next = symtab_list;
1039 symtab_list = symtab;
1043 allocate_symtab(name, objfile)
1045 struct objfile *objfile;
1047 register struct symtab *symtab;
1049 symtab = (struct symtab *) xmalloc (sizeof (struct symtab));
1050 bzero (symtab, sizeof (*symtab));
1051 symtab->filename = name;
1052 symtab->fullname = NULL;
1054 symtab->line_charpos = 0;
1055 symtab->version = 0;
1056 symtab->language = deduce_language_from_filename (name);
1058 /* Hook it to the objfile it comes from */
1059 symtab->objfile = objfile;
1060 symtab->objfile_chain = objfile->symtabs;
1061 objfile->symtabs = symtab;
1063 #ifdef INIT_EXTRA_SYMTAB_INFO
1064 INIT_EXTRA_SYMTAB_INFO(symtab);
1070 /* clear_symtab_users_once:
1072 This function is run after symbol reading, or from a cleanup.
1073 If an old symbol table was obsoleted, the old symbol table
1074 has been blown away, but the other GDB data structures that may
1075 reference it have not yet been cleared or re-directed. (The old
1076 symtab was zapped, and the cleanup queued, in free_named_symtab()
1079 This function can be queued N times as a cleanup, or called
1080 directly; it will do all the work the first time, and then will be a
1081 no-op until the next time it is queued. This works by bumping a
1082 counter at queueing time. Much later when the cleanup is run, or at
1083 the end of symbol processing (in case the cleanup is discarded), if
1084 the queued count is greater than the "done-count", we do the work
1085 and set the done-count to the queued count. If the queued count is
1086 less than or equal to the done-count, we just ignore the call. This
1087 is needed because reading a single .o file will often replace many
1088 symtabs (one per .h file, for example), and we don't want to reset
1089 the breakpoints N times in the user's face.
1091 The reason we both queue a cleanup, and call it directly after symbol
1092 reading, is because the cleanup protects us in case of errors, but is
1093 discarded if symbol reading is successful. */
1095 static int clear_symtab_users_queued;
1096 static int clear_symtab_users_done;
1099 clear_symtab_users_once ()
1101 /* Enforce once-per-`do_cleanups'-semantics */
1102 if (clear_symtab_users_queued <= clear_symtab_users_done)
1104 clear_symtab_users_done = clear_symtab_users_queued;
1106 printf ("Resetting debugger state after updating old symbol tables\n");
1108 /* Someday, we should do better than this, by only blowing away
1109 the things that really need to be blown. */
1110 clear_value_history ();
1112 clear_internalvars ();
1113 breakpoint_re_set ();
1114 set_default_breakpoint (0, 0, 0, 0);
1115 current_source_symtab = 0;
1118 /* Delete the specified psymtab, and any others that reference it. */
1121 cashier_psymtab (pst)
1122 struct partial_symtab *pst;
1124 struct partial_symtab *ps, *pprev;
1127 /* Find its previous psymtab in the chain */
1128 for (ps = partial_symtab_list; ps; ps = ps->next) {
1135 /* Unhook it from the chain. */
1136 if (ps == partial_symtab_list)
1137 partial_symtab_list = ps->next;
1139 pprev->next = ps->next;
1141 /* FIXME, we can't conveniently deallocate the entries in the
1142 partial_symbol lists (global_psymbols/static_psymbols) that
1143 this psymtab points to. These just take up space until all
1144 the psymtabs are reclaimed. Ditto the dependencies list and
1145 filename, which are all in the psymbol_obstack. */
1147 /* We need to cashier any psymtab that has this one as a dependency... */
1149 for (ps = partial_symtab_list; ps; ps = ps->next) {
1150 for (i = 0; i < ps->number_of_dependencies; i++) {
1151 if (ps->dependencies[i] == pst) {
1152 cashier_psymtab (ps);
1153 goto again; /* Must restart, chain has been munged. */
1160 /* If a symtab or psymtab for filename NAME is found, free it along
1161 with any dependent breakpoints, displays, etc.
1162 Used when loading new versions of object modules with the "add-file"
1163 command. This is only called on the top-level symtab or psymtab's name;
1164 it is not called for subsidiary files such as .h files.
1166 Return value is 1 if we blew away the environment, 0 if not.
1168 FIXME. I think this is not the best way to do this. We should
1169 work on being gentler to the environment while still cleaning up
1170 all stray pointers into the freed symtab. */
1173 free_named_symtabs (name)
1176 register struct symtab *s;
1177 register struct symtab *prev;
1178 register struct partial_symtab *ps;
1179 struct blockvector *bv;
1182 /* We only wack things if the symbol-reload switch is set. */
1183 if (!symbol_reloading)
1186 /* Some symbol formats have trouble providing file names... */
1187 if (name == 0 || *name == '\0')
1190 /* Look for a psymtab with the specified name. */
1193 for (ps = partial_symtab_list; ps; ps = ps->next) {
1194 if (!strcmp (name, ps->filename)) {
1195 cashier_psymtab (ps); /* Blow it away...and its little dog, too. */
1196 goto again2; /* Must restart, chain has been munged */
1200 /* Look for a symtab with the specified name. */
1202 for (s = symtab_list; s; s = s->next)
1204 if (!strcmp (name, s->filename))
1211 if (s == symtab_list)
1212 symtab_list = s->next;
1214 prev->next = s->next;
1216 /* For now, queue a delete for all breakpoints, displays, etc., whether
1217 or not they depend on the symtab being freed. This should be
1218 changed so that only those data structures affected are deleted. */
1220 /* But don't delete anything if the symtab is empty.
1221 This test is necessary due to a bug in "dbxread.c" that
1222 causes empty symtabs to be created for N_SO symbols that
1223 contain the pathname of the object file. (This problem
1224 has been fixed in GDB 3.9x). */
1226 bv = BLOCKVECTOR (s);
1227 if (BLOCKVECTOR_NBLOCKS (bv) > 2
1228 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
1229 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)))
1231 complain (&oldsyms_complaint, name);
1233 clear_symtab_users_queued++;
1234 make_cleanup (clear_symtab_users_once, 0);
1237 complain (&empty_symtab_complaint, name);
1244 /* It is still possible that some breakpoints will be affected
1245 even though no symtab was found, since the file might have
1246 been compiled without debugging, and hence not be associated
1247 with a symtab. In order to handle this correctly, we would need
1248 to keep a list of text address ranges for undebuggable files.
1249 For now, we do nothing, since this is a fairly obscure case. */
1253 /* FIXME, what about the misc function vector? */
1257 /* Allocate and partially fill a partial symtab. It will be
1258 completely filled at the end of the symbol list.
1260 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1261 is the address relative to which its symbols are (incremental) or 0
1265 struct partial_symtab *
1266 start_psymtab_common (objfile, addr,
1267 filename, textlow, global_syms, static_syms)
1268 struct objfile *objfile;
1272 struct partial_symbol *global_syms;
1273 struct partial_symbol *static_syms;
1275 int filename_length = strlen (filename) + 1;
1276 struct partial_symtab *result =
1277 (struct partial_symtab *) obstack_alloc (psymbol_obstack,
1278 sizeof (struct partial_symtab));
1280 result->addr = addr;
1282 result->filename = (char *) obstack_alloc (psymbol_obstack, filename_length);
1283 memcpy (result->filename, filename, filename_length);
1285 result->textlow = textlow;
1288 result->symtab = NULL;
1290 result->globals_offset = global_syms - global_psymbols.list;
1291 result->statics_offset = static_syms - static_psymbols.list;
1293 result->n_global_syms = 0;
1294 result->n_static_syms = 0;
1296 /* Chain it to the list owned by the current object file. */
1297 result->objfile = objfile;
1298 result->objfile_chain = objfile->psymtabs;
1299 objfile->psymtabs = result;
1305 * Free all partial_symtab storage.
1310 obstack_free (psymbol_obstack, 0);
1311 obstack_init (psymbol_obstack);
1312 partial_symtab_list = (struct partial_symtab *) 0;
1315 /* Free all the symtabs that are currently installed,
1316 and all storage associated with them.
1317 Leaves us in a consistent state with no symtabs installed. */
1322 register struct symtab *s, *snext;
1324 /* All values will be invalid because their types will be! */
1326 clear_value_history ();
1328 clear_internalvars ();
1329 #if defined (CLEAR_SOLIB)
1332 set_default_breakpoint (0, 0, 0, 0);
1334 current_source_symtab = 0;
1336 for (s = symtab_list; s; s = snext)
1342 obstack_free (symbol_obstack, 0);
1343 obstack_init (symbol_obstack);
1345 if (misc_function_vector)
1346 free (misc_function_vector);
1347 misc_function_count = 0;
1348 misc_function_vector = 0;
1349 clear_pc_function_cache();
1353 _initialize_symfile ()
1356 add_com ("symbol-file", class_files, symbol_file_command,
1357 "Load symbol table from executable file FILE.\n\
1358 The `file' command can also load symbol tables, as well as setting the file\n\
1361 add_com ("add-symbol-file", class_files, add_symbol_file_command,
1362 "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
1363 The second argument provides the starting address of the file's text.");
1365 add_com ("load", class_files, load_command,
1366 "Dynamically load FILE into the running program, and record its symbols\n\
1367 for access from GDB.");
1370 (add_set_cmd ("complaints", class_support, var_zinteger,
1371 (char *)&stop_whining,
1372 "Set max number of complaints about incorrect symbols.",
1377 (add_set_cmd ("symbol-reloading", class_support, var_boolean,
1378 (char *)&symbol_reloading,
1379 "Set dynamic symbol table reloading multiple times in one run.",
1383 obstack_init (symbol_obstack);
1384 obstack_init (psymbol_obstack);