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 it's type with the type from the one we are compacting out.
355 compact_misc_function_vector ()
357 struct misc_function
*copyfrom
;
358 struct misc_function
*copyto
;
360 copyfrom
= copyto
= misc_function_vector
;
361 while (copyfrom
< misc_function_vector
+ misc_function_count
- 1)
363 if (copyfrom
-> address
== (copyfrom
+ 1) -> address
364 && (strcmp (copyfrom
-> name
, (copyfrom
+ 1) -> name
) == 0))
366 if ((copyfrom
+ 1) -> type
== mf_unknown
)
368 (copyfrom
+ 1) -> type
= copyfrom
-> type
;
374 *copyto
++ = *copyfrom
++;
377 *copyto
++ = *copyfrom
++;
378 misc_function_count
= copyto
- misc_function_vector
;
379 misc_function_vector
= (struct misc_function
*)
380 xrealloc (misc_function_vector
,
381 misc_function_count
* sizeof (struct misc_function
));
385 /* INCLINK nonzero means bunches are from an incrementally-linked file.
386 Add them to the existing bunches.
387 Otherwise INCLINK is zero, and we start from scratch. */
389 condense_misc_bunches (inclink
)
393 register struct misc_bunch
*bunch
;
398 = (struct misc_function
*)
399 xrealloc (misc_function_vector
, (misc_count
+ misc_function_count
)
400 * sizeof (struct misc_function
));
401 j
= misc_function_count
;
406 = (struct misc_function
*)
407 xmalloc (misc_count
* sizeof (struct misc_function
));
414 for (i
= 0; i
< misc_bunch_index
; i
++, j
++)
416 misc_function_vector
[j
] = bunch
->contents
[i
];
417 #ifdef NAMES_HAVE_UNDERSCORE
418 if (misc_function_vector
[j
].name
[0] == '_')
419 misc_function_vector
[j
].name
++;
421 #ifdef SOME_NAMES_HAVE_DOT
422 if (misc_function_vector
[j
].name
[0] == '.')
423 misc_function_vector
[j
].name
++;
428 misc_bunch_index
= MISC_BUNCH_SIZE
;
431 if (misc_function_count
+ misc_count
!= j
) /* DEBUG */
432 printf_filtered ("Function counts are off! %d + %d != %d\n",
433 misc_function_count
, misc_count
, j
);
435 misc_function_count
= j
;
437 /* Sort the misc functions by address. */
439 sort_misc_function_vector ();
441 /* Compact out any duplicates. */
443 compact_misc_function_vector ();
447 /* Get the symbol table that corresponds to a partial_symtab.
448 This is fast after the first time you do it. In fact, there
449 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
453 psymtab_to_symtab (pst
)
454 register struct partial_symtab
*pst
;
456 /* If it's been looked up before, return it. */
460 /* If it has not yet been read in, read it. */
463 (*pst
->read_symtab
) (pst
);
469 /* Process a symbol file, as either the main file or as a dynamically
472 NAME is the file name (which will be tilde-expanded and made
473 absolute herein) (but we don't free or modify NAME itself).
474 FROM_TTY says how verbose to be. MAINLINE specifies whether this
475 is the main symbol file, or whether it's an extra symbol file such
476 as dynamically loaded code. If !mainline, ADDR is the address
477 where the text segment was loaded. */
480 syms_from_objfile (objfile
, addr
, mainline
)
481 struct objfile
*objfile
;
487 bfd
*sym_bfd
= objfile
->obfd
;
489 /* There is a distinction between having no symbol table
490 (we refuse to read the file, leaving the old set of symbols around)
491 and having no debugging symbols in your symbol table (we read
492 the file and end up with a mostly empty symbol table). */
494 if (!(bfd_get_file_flags (sym_bfd
) & HAS_SYMS
))
497 /* Save startup file's range of PC addresses to help blockframe.c
498 decide where the bottom of the stack is. */
499 if (bfd_get_file_flags (sym_bfd
) & EXEC_P
)
501 /* Executable file -- record its entry point so we'll recognize
502 the startup file because it contains the entry point. */
503 entry_point
= bfd_get_start_address (sym_bfd
);
507 /* Examination of non-executable.o files. Short-circuit this stuff. */
508 /* ~0 will not be in any file, we hope. */
510 /* set the startup file to be an empty range. */
511 startup_file_start
= 0;
512 startup_file_end
= 0;
515 sf
= symfile_init (objfile
);
519 /* Since no error yet, throw away the old symbol table. */
522 free_objfile (symfile_objfile
);
525 (*sf
->sym_new_init
) ();
527 /* For mainline, caller didn't know the specified address of the
528 text section. We fix that here. */
529 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
530 addr
= bfd_section_vma (sym_bfd
, text_sect
);
533 clear_complaints(); /* Allow complaints to appear for this new file. */
535 (*sf
->sym_read
) (sf
, addr
, mainline
);
537 /* Don't allow char * to have a typename (else would get caddr_t.) */
538 /* Ditto void *. FIXME should do this for all the builtin types. */
540 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
541 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
545 /* OK, make it the "real" symbol file. */
546 symfile_objfile
= objfile
;
550 /* If we have wiped out any old symbol tables, clean up. */
551 clear_symtab_users_once ();
555 /* Process a symbol file, as either the main file or as a dynamically
558 NAME is the file name (which will be tilde-expanded and made
559 absolute herein) (but we don't free or modify NAME itself).
560 FROM_TTY says how verbose to be. MAINLINE specifies whether this
561 is the main symbol file, or whether it's an extra symbol file such
562 as dynamically loaded code. If !mainline, ADDR is the address
563 where the text segment was loaded. */
566 symbol_file_add (name
, from_tty
, addr
, mainline
)
572 struct objfile
*objfile
;
575 objfile
= symfile_open (name
);
576 sym_bfd
= objfile
->obfd
;
578 /* There is a distinction between having no symbol table
579 (we refuse to read the file, leaving the old set of symbols around)
580 and having no debugging symbols in your symbol table (we read
581 the file and end up with a mostly empty symbol table, but with lots
582 of stuff in the misc function vector). */
584 if (!(bfd_get_file_flags (sym_bfd
) & HAS_SYMS
))
586 error ("%s has no symbol-table", name
);
589 if ((symtab_list
|| partial_symtab_list
)
592 && !query ("Load new symbol table from \"%s\"? ", name
))
593 error ("Not confirmed.");
597 printf_filtered ("Reading symbols from %s...", name
);
602 syms_from_objfile (objfile
, addr
, mainline
);
606 printf_filtered ("done.\n");
611 /* This is the symbol-file command. Read the file, analyze its symbols,
612 and add a struct symtab to symtab_list. */
615 symbol_file_command (name
, from_tty
)
624 if (symfile_objfile
) {
625 if ((symtab_list
|| partial_symtab_list
)
627 && !query ("Discard symbol table from `%s'? ",
628 symfile_objfile
->name
))
629 error ("Not confirmed.");
630 free_objfile (symfile_objfile
);
633 /* FIXME, this does not account for the main file and subsequent
634 files (shared libs, dynloads, etc) having different formats.
635 It only calls the cleanup routine for the main file's format. */
637 (*symfile_fns
->sym_new_init
) ();
644 /* Getting new symbols may change our opinion about what is
646 reinit_frame_cache ();
648 symbol_file_add (name
, from_tty
, (CORE_ADDR
)0, 1);
651 /* Open NAME and hand it off to BFD for preliminary analysis. Result
652 is newly malloc'd struct objfile *, which includes a newly malloc'd`
653 copy of NAME (tilde-expanded and made absolute).
654 In case of trouble, error() is called. */
656 static struct objfile
*
663 struct objfile
*objfile
;
665 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy */
667 /* Look down path for it, allocate 2nd new malloc'd copy. */
668 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
670 make_cleanup (free
, name
);
671 perror_with_name (name
);
673 free (name
); /* Free 1st new malloc'd copy */
674 name
= absolute_name
; /* Keep 2nd malloc'd copy in objfile and bfd */
676 sym_bfd
= bfd_fdopenr (name
, NULL
, desc
);
680 make_cleanup (free
, name
);
681 error ("Could not open `%s' to read symbols: %s",
682 name
, bfd_errmsg (bfd_error
));
685 if (!bfd_check_format (sym_bfd
, bfd_object
)) {
686 bfd_close (sym_bfd
); /* This also closes desc */
687 make_cleanup (free
, name
);
688 error ("\"%s\": can't read symbols: %s.",
689 name
, bfd_errmsg (bfd_error
));
692 objfile
= allocate_objfile (sym_bfd
, name
);
697 /* Allocate a new objfile struct, fill it in as best we can, and return it.
698 FIXME-soon! Eventually, the objfile will contain the obstack in which
699 the symtabs and psymtabs are contained, so they can all be blown away
700 cheaply and easily. */
703 allocate_objfile (abfd
, filename
)
707 struct objfile
*objfile
;
709 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
710 bzero (objfile
, sizeof (*objfile
));
712 objfile
->obfd
= abfd
;
713 objfile
->name
= filename
;
715 objfile
->symtabs
= 0; /* Don't have any yet */
716 objfile
->psymtabs
= 0; /* Don't have any yet */
718 objfile
->mtime
= bfd_get_mtime (abfd
);
720 /* Chain it to the list. */
721 objfile
->next
= object_files
;
722 object_files
= objfile
;
728 /* Destroy an objfile and all the symtabs and psymtabs under it. */
731 free_objfile (objfile
)
732 struct objfile
*objfile
;
737 free (objfile
->name
);
739 bfd_close (objfile
->obfd
);
741 /* Remove it from the chain of all objfiles. */
742 if (object_files
== objfile
)
743 object_files
= objfile
->next
;
744 else for (ofp
= object_files
; ofp
; ofp
= ofp
->next
) {
745 if (ofp
->next
== objfile
)
746 ofp
->next
= objfile
->next
;
749 /* FIXME! This should only free those associated with the objfile
750 being passed to us. THIS IS A KLUDGE TO BOOTSTRAP US. */
751 free_all_psymtabs ();
758 /* Link a new symtab_fns into the global symtab_fns list.
759 Called by various _initialize routines. */
765 sf
->next
= symtab_fns
;
770 /* Initialize to read symbols from the symbol file sym_bfd. It either
771 returns or calls error(). The result is a malloc'd struct sym_fns
772 that contains cached information about the symbol file. */
774 static struct sym_fns
*
775 symfile_init (objfile
)
776 struct objfile
*objfile
;
778 struct sym_fns
*sf
, *sf2
;
779 bfd
*sym_bfd
= objfile
->obfd
;
781 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
->next
)
783 if (!strncmp (bfd_get_target (sym_bfd
), sf
->sym_name
, sf
->sym_namelen
))
785 sf2
= (struct sym_fns
*)xmalloc (sizeof (*sf2
));
786 /* FIXME, who frees this? */
788 sf2
->objfile
= objfile
;
789 sf2
->sym_bfd
= sym_bfd
;
790 sf2
->sym_private
= 0; /* Not alloc'd yet */
791 (*sf2
->sym_init
) (sf2
);
795 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
796 bfd_get_target (sym_bfd
));
797 return 0; /* Appease lint. */
800 /* This function runs the load command of our current target. */
803 load_command (arg
, from_tty
)
807 target_load (arg
, from_tty
);
810 /* This function allows the addition of incrementally linked object files.
811 It does not modify any state in the target, only in the debugger. */
815 add_symbol_file_command (arg_string
, from_tty
)
822 /* Getting new symbols may change our opinion about what is
824 reinit_frame_cache ();
827 error ("add-symbol-file takes a file name and an address");
829 arg_string
= tilde_expand (arg_string
);
830 make_cleanup (free
, arg_string
);
832 for( ; *arg_string
== ' '; arg_string
++ );
834 for( ; *arg_string
&& *arg_string
!= ' ' ; arg_string
++ );
835 *arg_string
++ = (char) 0;
838 error ("add-symbol-file takes a file name and an address");
840 text_addr
= parse_and_eval_address (arg_string
);
844 if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
845 name
, local_hex_string (text_addr
)))
846 error ("Not confirmed.");
848 symbol_file_add (name
, 0, text_addr
, 0);
851 /* Re-read symbols if a symbol-file has changed. */
855 struct objfile
*objfile
;
859 /* With the addition of shared libraries, this should be modified,
860 the load time should be saved in the partial symbol tables, since
861 different tables may come from different source files. FIXME.
862 This routine should then walk down each partial symbol table
863 and see if the symbol table that it originates from has been changed
866 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
) {
868 objfile
->obfd
->mtime_set
= false; /* Force it to reread. */
869 new_modtime
= bfd_get_mtime (objfile
->obfd
);
870 if (new_modtime
!= objfile
->mtime
) {
871 printf_filtered ("`%s' has changed; re-reading symbols.\n",
873 /* FIXME, this should use a different command...that would only
874 affect this objfile's symbols. */
875 symbol_file_command (objfile
->name
, 0);
876 objfile
->mtime
= new_modtime
;
883 breakpoint_re_set ();
886 /* This function is really horrible, but to avoid it, there would need
887 to be more filling in of forward references. */
889 fill_in_vptr_fieldno (type
)
892 if (TYPE_VPTR_FIELDNO (type
) < 0)
895 for (i
= 1; i
< TYPE_N_BASECLASSES (type
); i
++)
897 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
898 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
900 TYPE_VPTR_FIELDNO (type
)
901 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
902 TYPE_VPTR_BASETYPE (type
)
903 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
910 /* Functions to handle complaints during symbol reading. */
912 /* How many complaints about a particular thing should be printed before
913 we stop whining about it? Default is no whining at all, since so many
914 systems have ill-constructed symbol files. */
916 static unsigned stop_whining
= 0;
918 /* Print a complaint about the input symbols, and link the complaint block
919 into a chain for later handling. */
922 complain (complaint
, val
)
923 struct complaint
*complaint
;
926 complaint
->counter
++;
927 if (complaint
->next
== 0) {
928 complaint
->next
= complaint_root
->next
;
929 complaint_root
->next
= complaint
;
931 if (complaint
->counter
> stop_whining
)
935 puts_filtered ("During symbol reading...");
937 printf_filtered (complaint
->message
, val
);
938 puts_filtered ("...");
941 puts_filtered ("\n");
944 /* Clear out all complaint counters that have ever been incremented. */
951 for (p
= complaint_root
->next
; p
!= complaint_root
; p
= p
->next
)
956 deduce_language_from_filename (filename
)
959 char *c
= rindex (filename
, '.');
961 if (!c
) ; /* Get default. */
962 else if(!strcmp(c
,".mod"))
964 else if(!strcmp(c
,".c"))
966 else if(!strcmp(c
,".cc") || !strcmp(c
,".C"))
967 return language_cplus
;
969 return language_unknown
; /* default */
974 Allocate and partly initialize a new symbol table. Return a pointer
975 to it. error() if no space.
977 Caller must set these fields:
983 initialize any EXTRA_SYMTAB_INFO
984 possibly free_named_symtabs (symtab->filename);
985 symtab->next = symtab_list;
986 symtab_list = symtab;
990 allocate_symtab(name
, objfile
)
992 struct objfile
*objfile
;
994 register struct symtab
*symtab
;
996 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
997 bzero (symtab
, sizeof (*symtab
));
998 symtab
->filename
= name
;
999 symtab
->fullname
= NULL
;
1001 symtab
->line_charpos
= 0;
1002 symtab
->version
= 0;
1003 symtab
->language
= deduce_language_from_filename (name
);
1005 /* Hook it to the objfile it comes from */
1006 symtab
->objfile
= objfile
;
1007 symtab
->objfile_chain
= objfile
->symtabs
;
1008 objfile
->symtabs
= symtab
;
1010 #ifdef INIT_EXTRA_SYMTAB_INFO
1011 INIT_EXTRA_SYMTAB_INFO(symtab
);
1017 /* clear_symtab_users_once:
1019 This function is run after symbol reading, or from a cleanup.
1020 If an old symbol table was obsoleted, the old symbol table
1021 has been blown away, but the other GDB data structures that may
1022 reference it have not yet been cleared or re-directed. (The old
1023 symtab was zapped, and the cleanup queued, in free_named_symtab()
1026 This function can be queued N times as a cleanup, or called
1027 directly; it will do all the work the first time, and then will be a
1028 no-op until the next time it is queued. This works by bumping a
1029 counter at queueing time. Much later when the cleanup is run, or at
1030 the end of symbol processing (in case the cleanup is discarded), if
1031 the queued count is greater than the "done-count", we do the work
1032 and set the done-count to the queued count. If the queued count is
1033 less than or equal to the done-count, we just ignore the call. This
1034 is needed because reading a single .o file will often replace many
1035 symtabs (one per .h file, for example), and we don't want to reset
1036 the breakpoints N times in the user's face.
1038 The reason we both queue a cleanup, and call it directly after symbol
1039 reading, is because the cleanup protects us in case of errors, but is
1040 discarded if symbol reading is successful. */
1042 static int clear_symtab_users_queued
;
1043 static int clear_symtab_users_done
;
1046 clear_symtab_users_once ()
1048 /* Enforce once-per-`do_cleanups'-semantics */
1049 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
1051 clear_symtab_users_done
= clear_symtab_users_queued
;
1053 printf ("Resetting debugger state after updating old symbol tables\n");
1055 /* Someday, we should do better than this, by only blowing away
1056 the things that really need to be blown. */
1057 clear_value_history ();
1059 clear_internalvars ();
1060 breakpoint_re_set ();
1061 set_default_breakpoint (0, 0, 0, 0);
1062 current_source_symtab
= 0;
1065 /* Delete the specified psymtab, and any others that reference it. */
1068 cashier_psymtab (pst
)
1069 struct partial_symtab
*pst
;
1071 struct partial_symtab
*ps
, *pprev
;
1074 /* Find its previous psymtab in the chain */
1075 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1082 /* Unhook it from the chain. */
1083 if (ps
== partial_symtab_list
)
1084 partial_symtab_list
= ps
->next
;
1086 pprev
->next
= ps
->next
;
1088 /* FIXME, we can't conveniently deallocate the entries in the
1089 partial_symbol lists (global_psymbols/static_psymbols) that
1090 this psymtab points to. These just take up space until all
1091 the psymtabs are reclaimed. Ditto the dependencies list and
1092 filename, which are all in the psymbol_obstack. */
1094 /* We need to cashier any psymtab that has this one as a dependency... */
1096 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1097 for (i
= 0; i
< ps
->number_of_dependencies
; i
++) {
1098 if (ps
->dependencies
[i
] == pst
) {
1099 cashier_psymtab (ps
);
1100 goto again
; /* Must restart, chain has been munged. */
1107 /* If a symtab or psymtab for filename NAME is found, free it along
1108 with any dependent breakpoints, displays, etc.
1109 Used when loading new versions of object modules with the "add-file"
1110 command. This is only called on the top-level symtab or psymtab's name;
1111 it is not called for subsidiary files such as .h files.
1113 Return value is 1 if we blew away the environment, 0 if not.
1115 FIXME. I think this is not the best way to do this. We should
1116 work on being gentler to the environment while still cleaning up
1117 all stray pointers into the freed symtab. */
1120 free_named_symtabs (name
)
1123 register struct symtab
*s
;
1124 register struct symtab
*prev
;
1125 register struct partial_symtab
*ps
;
1126 struct blockvector
*bv
;
1129 /* We only wack things if the symbol-reload switch is set. */
1130 if (!symbol_reloading
)
1133 /* Some symbol formats have trouble providing file names... */
1134 if (name
== 0 || *name
== '\0')
1137 /* Look for a psymtab with the specified name. */
1140 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1141 if (!strcmp (name
, ps
->filename
)) {
1142 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
1143 goto again2
; /* Must restart, chain has been munged */
1147 /* Look for a symtab with the specified name. */
1149 for (s
= symtab_list
; s
; s
= s
->next
)
1151 if (!strcmp (name
, s
->filename
))
1158 if (s
== symtab_list
)
1159 symtab_list
= s
->next
;
1161 prev
->next
= s
->next
;
1163 /* For now, queue a delete for all breakpoints, displays, etc., whether
1164 or not they depend on the symtab being freed. This should be
1165 changed so that only those data structures affected are deleted. */
1167 /* But don't delete anything if the symtab is empty.
1168 This test is necessary due to a bug in "dbxread.c" that
1169 causes empty symtabs to be created for N_SO symbols that
1170 contain the pathname of the object file. (This problem
1171 has been fixed in GDB 3.9x). */
1173 bv
= BLOCKVECTOR (s
);
1174 if (BLOCKVECTOR_NBLOCKS (bv
) > 2
1175 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
1176 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
1178 complain (&oldsyms_complaint
, name
);
1180 clear_symtab_users_queued
++;
1181 make_cleanup (clear_symtab_users_once
, 0);
1184 complain (&empty_symtab_complaint
, name
);
1191 /* It is still possible that some breakpoints will be affected
1192 even though no symtab was found, since the file might have
1193 been compiled without debugging, and hence not be associated
1194 with a symtab. In order to handle this correctly, we would need
1195 to keep a list of text address ranges for undebuggable files.
1196 For now, we do nothing, since this is a fairly obscure case. */
1200 /* FIXME, what about the misc function vector? */
1205 * Free all partial_symtab storage.
1210 obstack_free (psymbol_obstack
, 0);
1211 obstack_init (psymbol_obstack
);
1212 partial_symtab_list
= (struct partial_symtab
*) 0;
1215 /* Free all the symtabs that are currently installed,
1216 and all storage associated with them.
1217 Leaves us in a consistent state with no symtabs installed. */
1222 register struct symtab
*s
, *snext
;
1224 /* All values will be invalid because their types will be! */
1226 clear_value_history ();
1228 clear_internalvars ();
1229 #if defined (CLEAR_SOLIB)
1232 set_default_breakpoint (0, 0, 0, 0);
1234 current_source_symtab
= 0;
1236 for (s
= symtab_list
; s
; s
= snext
)
1242 obstack_free (symbol_obstack
, 0);
1243 obstack_init (symbol_obstack
);
1245 if (misc_function_vector
)
1246 free (misc_function_vector
);
1247 misc_function_count
= 0;
1248 misc_function_vector
= 0;
1249 clear_pc_function_cache();
1253 _initialize_symfile ()
1256 add_com ("symbol-file", class_files
, symbol_file_command
,
1257 "Load symbol table from executable file FILE.\n\
1258 The `file' command can also load symbol tables, as well as setting the file\n\
1261 add_com ("add-symbol-file", class_files
, add_symbol_file_command
,
1262 "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
1263 The second argument provides the starting address of the file's text.");
1265 add_com ("load", class_files
, load_command
,
1266 "Dynamically load FILE into the running program, and record its symbols\n\
1267 for access from GDB.");
1270 (add_set_cmd ("complaints", class_support
, var_uinteger
,
1271 (char *)&stop_whining
,
1272 "Set max number of complaints about incorrect symbols.",
1277 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
1278 (char *)&symbol_reloading
,
1279 "Set dynamic symbol table reloading multiple times in one run.",
1283 obstack_init (symbol_obstack
);
1284 obstack_init (psymbol_obstack
);