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. */
31 #include "breakpoint.h"
36 #include <sys/types.h>
41 CORE_ADDR entry_point
; /* Where execution starts in symfile */
43 extern int info_verbose
;
46 extern char *getenv ();
47 extern char *rindex ();
49 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
50 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
52 /* Functions this file defines */
53 static bfd
*symfile_open();
54 static struct sym_fns
*symfile_init();
55 static void clear_symtab_users_once();
57 /* List of all available sym_fns. */
59 struct sym_fns
*symtab_fns
= NULL
;
61 /* Saves the sym_fns of the current symbol table, so we can call
62 the right XXX_new_init function when we free it. FIXME. This
63 should be extended to calling the new_init function for each
64 existing symtab or psymtab, since the main symbol file and
65 subsequent added symbol files can have different types. */
67 static struct sym_fns
*symfile_fns
;
69 /* Allocate an obstack to hold objects that should be freed
70 when we load a new symbol table.
71 This includes the symbols made by dbxread
72 and the types that are not permanent. */
74 struct obstack obstack1
;
76 struct obstack
*symbol_obstack
= &obstack1
;
78 /* This obstack will be used for partial_symbol objects. It can
79 probably actually be the same as the symbol_obstack above, but I'd
80 like to keep them seperate for now. If I want to later, I'll
81 replace one with the other. */
83 struct obstack obstack2
;
85 struct obstack
*psymbol_obstack
= &obstack2
;
87 /* File name symbols were loaded from. */
91 /* The modification date of the file when they were loaded. */
93 long /* really time_t */ symfile_mtime
= 0;
95 /* Structures with which to manage partial symbol allocation. */
98 struct psymbol_allocation_list global_psymbols
= {0}, static_psymbols
= {0};
100 /* Flag for whether user will be reloading symbols multiple times.
101 Defaults to ON for VxWorks, otherwise OFF. */
103 #ifdef SYMBOL_RELOADING_DEFAULT
104 int symbol_reloading
= SYMBOL_RELOADING_DEFAULT
;
106 int symbol_reloading
= 0;
109 /* Structure to manage complaints about symbol file contents. */
111 struct complaint complaint_root
[1] = {
112 {(char *)0, 0, complaint_root
},
115 /* Some actual complaints. */
117 struct complaint oldsyms_complaint
= {
118 "Replacing old symbols for `%s'", 0, 0 };
120 struct complaint empty_symtab_complaint
= {
121 "Empty symbol table found for `%s'", 0, 0 };
124 /* In the following sort, we always make sure that
125 register debug symbol declarations always come before regular
126 debug symbol declarations (as might happen when parameters are
127 then put into registers by the compiler). */
130 compare_symbols (s1
, s2
)
131 struct symbol
**s1
, **s2
;
133 register int namediff
;
135 /* Compare the initial characters. */
136 namediff
= SYMBOL_NAME (*s1
)[0] - SYMBOL_NAME (*s2
)[0];
137 if (namediff
!= 0) return namediff
;
139 /* If they match, compare the rest of the names. */
140 namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
141 if (namediff
!= 0) return namediff
;
143 /* For symbols of the same name, registers should come first. */
144 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
145 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
148 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
152 register struct block
*b
;
154 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
155 sizeof (struct symbol
*), compare_symbols
);
158 /* Call sort_symtab_syms to sort alphabetically
159 the symbols of each block of one symtab. */
163 register struct symtab
*s
;
165 register struct blockvector
*bv
= BLOCKVECTOR (s
);
166 int nbl
= BLOCKVECTOR_NBLOCKS (bv
);
168 register struct block
*b
;
170 for (i
= 0; i
< nbl
; i
++)
172 b
= BLOCKVECTOR_BLOCK (bv
, i
);
173 if (BLOCK_SHOULD_SORT (b
))
179 sort_all_symtab_syms ()
181 register struct symtab
*s
;
183 for (s
= symtab_list
; s
; s
= s
->next
)
185 sort_symtab_syms (s
);
189 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
190 (and add a null character at the end in the copy).
191 Returns the address of the copy. */
194 obsavestring (ptr
, size
)
198 register char *p
= (char *) obstack_alloc (symbol_obstack
, size
+ 1);
199 /* Open-coded bcopy--saves function call time.
200 These strings are usually short. */
202 register char *p1
= ptr
;
203 register char *p2
= p
;
204 char *end
= ptr
+ size
;
212 /* Concatenate strings S1, S2 and S3; return the new string.
213 Space is found in the symbol_obstack. */
216 obconcat (s1
, s2
, s3
)
219 register int len
= strlen (s1
) + strlen (s2
) + strlen (s3
) + 1;
220 register char *val
= (char *) obstack_alloc (symbol_obstack
, len
);
227 /* Accumulate the misc functions in bunches of 127.
228 At the end, copy them all into one newly allocated structure. */
230 #define MISC_BUNCH_SIZE 127
234 struct misc_bunch
*next
;
235 struct misc_function contents
[MISC_BUNCH_SIZE
];
238 /* Bunch currently being filled up.
239 The next field points to chain of filled bunches. */
241 static struct misc_bunch
*misc_bunch
;
243 /* Number of slots filled in current bunch. */
245 static int misc_bunch_index
;
247 /* Total number of misc functions recorded so far. */
249 static int misc_count
;
256 misc_bunch_index
= MISC_BUNCH_SIZE
;
260 prim_record_misc_function (name
, address
, misc_type
)
263 enum misc_function_type misc_type
;
265 register struct misc_bunch
*new;
267 if (misc_bunch_index
== MISC_BUNCH_SIZE
)
269 new = (struct misc_bunch
*) xmalloc (sizeof (struct misc_bunch
));
270 misc_bunch_index
= 0;
271 new->next
= misc_bunch
;
274 misc_bunch
->contents
[misc_bunch_index
].name
= name
;
275 misc_bunch
->contents
[misc_bunch_index
].address
= address
;
276 misc_bunch
->contents
[misc_bunch_index
].type
= misc_type
;
277 misc_bunch
->contents
[misc_bunch_index
].misc_info
= 0;
283 compare_misc_functions (fn1
, fn2
)
284 struct misc_function
*fn1
, *fn2
;
286 /* Return a signed result based on unsigned comparisons
287 so that we sort into unsigned numeric order. */
288 if (fn1
->address
< fn2
->address
)
290 if (fn1
->address
> fn2
->address
)
297 discard_misc_bunches (foo
)
300 register struct misc_bunch
*next
;
304 next
= misc_bunch
->next
;
310 /* INCLINK nonzero means bunches are from an incrementally-linked file.
311 Add them to the existing bunches.
312 Otherwise INCLINK is zero, and we start from scratch. */
314 condense_misc_bunches (inclink
)
318 register struct misc_bunch
*bunch
;
323 = (struct misc_function
*)
324 xrealloc (misc_function_vector
, (misc_count
+ misc_function_count
)
325 * sizeof (struct misc_function
));
326 j
= misc_function_count
;
331 = (struct misc_function
*)
332 xmalloc (misc_count
* sizeof (struct misc_function
));
339 for (i
= 0; i
< misc_bunch_index
; i
++, j
++)
341 misc_function_vector
[j
] = bunch
->contents
[i
];
342 #ifdef NAMES_HAVE_UNDERSCORE
343 if (misc_function_vector
[j
].name
[0] == '_')
344 misc_function_vector
[j
].name
++;
346 #ifdef SOME_NAMES_HAVE_DOT
347 if (misc_function_vector
[j
].name
[0] == '.')
348 misc_function_vector
[j
].name
++;
353 misc_bunch_index
= MISC_BUNCH_SIZE
;
356 if (misc_function_count
+ misc_count
!= j
) /* DEBUG */
357 printf_filtered ("Function counts are off! %d + %d != %d\n",
358 misc_function_count
, misc_count
, j
);
360 misc_function_count
= j
;
362 /* Sort the misc functions by address. */
364 qsort (misc_function_vector
, misc_function_count
,
365 sizeof (struct misc_function
),
366 compare_misc_functions
);
370 /* Get the symbol table that corresponds to a partial_symtab.
371 This is fast after the first time you do it. In fact, there
372 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
376 psymtab_to_symtab (pst
)
377 register struct partial_symtab
*pst
;
379 /* If it's been looked up before, return it. */
383 /* If it has not yet been read in, read it. */
386 (*pst
->read_symtab
) (pst
);
392 /* Process a symbol file, as either the main file or as a dynamically
395 NAME is the file name (which will be tilde-expanded and made
396 absolute herein) (but we don't free or modify NAME itself).
397 FROM_TTY says how verbose to be. MAINLINE specifies whether this
398 is the main symbol file, or whether it's an extra symbol file such
399 as dynamically loaded code. If !mainline, ADDR is the address
400 where the text segment was loaded. */
403 syms_from_bfd (sym_bfd
, addr
, mainline
)
412 /* There is a distinction between having no symbol table
413 (we refuse to read the file, leaving the old set of symbols around)
414 and having no debugging symbols in your symbol table (we read
415 the file and end up with a mostly empty symbol table). */
417 if (!(bfd_get_file_flags (sym_bfd
) & HAS_SYMS
))
420 /* Save startup file's range of PC addresses to help blockframe.c
421 decide where the bottom of the stack is. */
422 if (bfd_get_file_flags (sym_bfd
) & EXEC_P
)
424 /* Executable file -- record its entry point so we'll recognize
425 the startup file because it contains the entry point. */
426 entry_point
= bfd_get_start_address (sym_bfd
);
430 /* Examination of non-executable.o files. Short-circuit this stuff. */
431 /* ~0 will not be in any file, we hope. */
433 /* set the startup file to be an empty range. */
434 startup_file_start
= 0;
435 startup_file_end
= 0;
438 sf
= symfile_init (sym_bfd
);
439 realname
= bfd_get_filename (sym_bfd
);
440 realname
= savestring (realname
, strlen (realname
));
441 /* FIXME, this probably creates a storage leak... */
445 /* Since no error yet, throw away the old symbol table. */
451 free_all_psymtabs ();
453 (*sf
->sym_new_init
) ();
455 /* For mainline, caller didn't know the specified address of the
456 text section. We fix that here. */
457 text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
458 addr
= bfd_section_vma (sym_bfd
, text_sect
);
461 clear_complaints(); /* Allow complaints to appear for this new file. */
463 (*sf
->sym_read
) (sf
, addr
, mainline
);
465 /* Don't allow char * to have a typename (else would get caddr_t.) */
466 /* Ditto void *. FIXME should do this for all the builtin types. */
468 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
469 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
473 /* OK, make it the "real" symbol file. */
478 /* If we have wiped out any old symbol tables, clean up. */
479 clear_symtab_users_once ();
483 /* Process a symbol file, as either the main file or as a dynamically
486 NAME is the file name (which will be tilde-expanded and made
487 absolute herein) (but we don't free or modify NAME itself).
488 FROM_TTY says how verbose to be. MAINLINE specifies whether this
489 is the main symbol file, or whether it's an extra symbol file such
490 as dynamically loaded code. If !mainline, ADDR is the address
491 where the text segment was loaded. */
494 symbol_file_add (name
, from_tty
, addr
, mainline
)
502 sym_bfd
= symfile_open (name
);
505 symfile_mtime
= bfd_get_mtime (sym_bfd
);
507 /* There is a distinction between having no symbol table
508 (we refuse to read the file, leaving the old set of symbols around)
509 and having no debugging symbols in your symbol table (we read
510 the file and end up with a mostly empty symbol table). */
512 if (!(bfd_get_file_flags (sym_bfd
) & HAS_SYMS
))
514 error ("%s has no symbol-table", name
);
517 if ((symtab_list
|| partial_symtab_list
)
520 && !query ("Load new symbol table from \"%s\"? ", name
))
521 error ("Not confirmed.");
525 printf_filtered ("Reading symbols from %s...", name
);
530 syms_from_bfd (sym_bfd
, addr
, mainline
);
534 printf_filtered ("done.\n");
539 /* This is the symbol-file command. Read the file, analyze its symbols,
540 and add a struct symtab to symtab_list. */
543 symbol_file_command (name
, from_tty
)
552 if ((symtab_list
|| partial_symtab_list
)
554 && !query ("Discard symbol table from `%s'? ", symfile
))
555 error ("Not confirmed.");
560 free_all_psymtabs ();
561 /* FIXME, this does not account for the main file and subsequent
562 files (shared libs, dynloads, etc) having different formats.
563 It only calls the cleanup routine for the main file's format. */
565 (*symfile_fns
->sym_new_init
) ();
572 /* Getting new symbols may change our opinion about what is
574 reinit_frame_cache ();
576 symbol_file_add (name
, from_tty
, (CORE_ADDR
)0, 1);
579 /* Open NAME and hand it off to BFD for preliminary analysis. Result
580 is a BFD *, which includes a new copy of NAME dynamically allocated
581 (which will be freed by the cleanup chain). In case of trouble,
582 error() is called. */
592 name
= tilde_expand (name
);
593 make_cleanup (free
, name
);
595 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
597 perror_with_name (name
);
600 make_cleanup (free
, absolute_name
);
601 name
= absolute_name
;
604 sym_bfd
= bfd_fdopenr (name
, NULL
, desc
);
608 error ("Could not open `%s' to read symbols: %s",
609 name
, bfd_errmsg (bfd_error
));
611 make_cleanup (bfd_close
, sym_bfd
);
613 if (!bfd_check_format (sym_bfd
, bfd_object
))
614 error ("\"%s\": can't read symbols: %s.",
615 name
, bfd_errmsg (bfd_error
));
620 /* Link a new symtab_fns into the global symtab_fns list.
621 Called by various _initialize routines. */
627 sf
->next
= symtab_fns
;
632 /* Initialize to read symbols from the symbol file sym_bfd. It either
633 returns or calls error(). The result is a malloc'd struct sym_fns
634 that contains cached information about the symbol file. */
636 static struct sym_fns
*
637 symfile_init (sym_bfd
)
640 struct sym_fns
*sf
, *sf2
;
642 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
->next
)
644 if (!strncmp (bfd_get_target (sym_bfd
), sf
->sym_name
, sf
->sym_namelen
))
646 sf2
= (struct sym_fns
*)xmalloc (sizeof (*sf2
));
647 /* FIXME, who frees this? */
649 sf2
->sym_bfd
= sym_bfd
;
650 sf2
->sym_private
= 0; /* Not alloc'd yet */
651 (*sf2
->sym_init
) (sf2
);
655 error ("I'm sorry, Dave, I can't do that. Symbol format unknown.");
656 return 0; /* Appease lint. */
659 /* This function runs the load command of our current target. */
662 load_command (arg
, from_tty
)
666 target_load (arg
, from_tty
);
669 /* This function allows the addition of incrementally linked object files.
670 It does not modify any state in the target, only in the debugger. */
674 add_symbol_file_command (arg_string
, from_tty
)
681 /* Getting new symbols may change our opinion about what is
683 reinit_frame_cache ();
686 error ("add-symbol-file takes a file name and an address");
688 arg_string
= tilde_expand (arg_string
);
689 make_cleanup (free
, arg_string
);
691 for( ; *arg_string
== ' '; arg_string
++ );
693 for( ; *arg_string
&& *arg_string
!= ' ' ; arg_string
++ );
694 *arg_string
++ = (char) 0;
697 error ("add-symbol-file takes a file name and an address");
699 text_addr
= parse_and_eval_address (arg_string
);
703 if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
704 name
, local_hex_string (text_addr
)))
705 error ("Not confirmed.");
707 symbol_file_add (name
, 0, text_addr
, 0);
710 /* Re-read symbols if the symbol-file has changed. */
716 /* With the addition of shared libraries, this should be modified,
717 the load time should be saved in the partial symbol tables, since
718 different tables may come from different source files. FIXME.
719 This routine should then walk down each partial symbol table
720 and see if the symbol table that it originates from has been changed
723 if (stat (symfile
, &symstat
) < 0)
724 /* Can't read symbol-file. Assume it is up to date. */
727 if (symstat
.st_mtime
> symfile_mtime
)
729 printf_filtered ("Symbol file has changed; re-reading symbols.\n");
730 symbol_file_command (symfile
, 0);
731 breakpoint_re_set ();
735 /* This function is really horrible, but to avoid it, there would need
736 to be more filling in of forward references. */
738 fill_in_vptr_fieldno (type
)
741 if (TYPE_VPTR_FIELDNO (type
) < 0)
744 for (i
= 1; i
< TYPE_N_BASECLASSES (type
); i
++)
746 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
747 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
749 TYPE_VPTR_FIELDNO (type
)
750 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
751 TYPE_VPTR_BASETYPE (type
)
752 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
759 /* Functions to handle complaints during symbol reading. */
761 /* How many complaints about a particular thing should be printed before
762 we stop whining about it? Default is no whining at all, since so many
763 systems have ill-constructed symbol files. */
765 static unsigned stop_whining
= 0;
767 /* Print a complaint about the input symbols, and link the complaint block
768 into a chain for later handling. Result is 1 if the complaint was
769 printed, 0 if it was suppressed. */
772 complain (complaint
, val
)
773 struct complaint
*complaint
;
776 complaint
->counter
++;
777 if (complaint
->next
== 0) {
778 complaint
->next
= complaint_root
->next
;
779 complaint_root
->next
= complaint
;
781 if (complaint
->counter
> stop_whining
)
785 puts_filtered ("During symbol reading...");
787 printf_filtered (complaint
->message
, val
);
788 puts_filtered ("...");
791 puts_filtered ("\n");
795 /* Clear out all complaint counters that have ever been incremented. */
802 for (p
= complaint_root
->next
; p
!= complaint_root
; p
= p
->next
)
808 Allocate and partly initialize a new symbol table. Return a pointer
809 to it. error() if no space.
811 Caller must set these fields:
817 initialize any EXTRA_SYMTAB_INFO
818 possibly free_named_symtabs (symtab->filename);
819 symtab->next = symtab_list;
820 symtab_list = symtab;
824 allocate_symtab(name
)
827 register struct symtab
*symtab
;
830 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
831 bzero (symtab
, sizeof (*symtab
));
832 symtab
->filename
= name
;
833 symtab
->fullname
= NULL
;
835 symtab
->line_charpos
= 0;
837 symtab
->language
= language_unknown
; /* default */
839 c
= rindex (name
, '.');
842 ; /* Don't know language of file. */
843 } else if(!strcmp(c
,".mod")) {
844 symtab
->language
= language_m2
;
845 } else if(!strcmp(c
,".c") || !strcmp(c
,".cc")) {
846 symtab
->language
= language_c
;
852 /* clear_symtab_users_once:
854 This function is run after symbol reading, or from a cleanup.
855 If an old symbol table was obsoleted, the old symbol table
856 has been blown away, but the other GDB data structures that may
857 reference it have not yet been cleared or re-directed. (The old
858 symtab was zapped, and the cleanup queued, in free_named_symtab()
861 This function can be queued N times as a cleanup, or called
862 directly; it will do all the work the first time, and then will be a
863 no-op until the next time it is queued. This works by bumping a
864 counter at queueing time. Much later when the cleanup is run, or at
865 the end of symbol processing (in case the cleanup is discarded), if
866 the queued count is greater than the "done-count", we do the work
867 and set the done-count to the queued count. If the queued count is
868 less than or equal to the done-count, we just ignore the call. This
869 is needed because reading a single .o file will often replace many
870 symtabs (one per .h file, for example), and we don't want to reset
871 the breakpoints N times in the user's face.
873 The reason we both queue a cleanup, and call it directly after symbol
874 reading, is because the cleanup protects us in case of errors, but is
875 discarded if symbol reading is successful. */
877 static int clear_symtab_users_queued
;
878 static int clear_symtab_users_done
;
881 clear_symtab_users_once ()
883 /* Enforce once-per-`do_cleanups'-semantics */
884 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
886 clear_symtab_users_done
= clear_symtab_users_queued
;
888 printf ("Resetting debugger state after updating old symbol tables\n");
890 /* Someday, we should do better than this, by only blowing away
891 the things that really need to be blown. */
892 clear_value_history ();
894 clear_internalvars ();
895 breakpoint_re_set ();
896 set_default_breakpoint (0, 0, 0, 0);
897 current_source_symtab
= 0;
900 /* Delete the specified psymtab, and any others that reference it. */
903 cashier_psymtab (pst
)
904 struct partial_symtab
*pst
;
906 struct partial_symtab
*ps
, *pprev
;
909 /* Find its previous psymtab in the chain */
910 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
917 /* Unhook it from the chain. */
918 if (ps
== partial_symtab_list
)
919 partial_symtab_list
= ps
->next
;
921 pprev
->next
= ps
->next
;
923 /* FIXME, we can't conveniently deallocate the entries in the
924 partial_symbol lists (global_psymbols/static_psymbols) that
925 this psymtab points to. These just take up space until all
926 the psymtabs are reclaimed. Ditto the dependencies list and
927 filename, which are all in the psymbol_obstack. */
929 /* We need to cashier any psymtab that has this one as a dependency... */
931 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
932 for (i
= 0; i
< ps
->number_of_dependencies
; i
++) {
933 if (ps
->dependencies
[i
] == pst
) {
934 cashier_psymtab (ps
);
935 goto again
; /* Must restart, chain has been munged. */
942 /* If a symtab or psymtab for filename NAME is found, free it along
943 with any dependent breakpoints, displays, etc.
944 Used when loading new versions of object modules with the "add-file"
945 command. This is only called on the top-level symtab or psymtab's name;
946 it is not called for subsidiary files such as .h files.
948 Return value is 1 if we blew away the environment, 0 if not.
950 FIXME. I think this is not the best way to do this. We should
951 work on being gentler to the environment while still cleaning up
952 all stray pointers into the freed symtab. */
955 free_named_symtabs (name
)
958 register struct symtab
*s
;
959 register struct symtab
*prev
;
960 register struct partial_symtab
*ps
;
961 struct blockvector
*bv
;
964 /* We only wack things if the symbol-reload switch is set. */
965 if (!symbol_reloading
)
968 /* Some symbol formats have trouble providing file names... */
969 if (name
== 0 || *name
== '\0')
972 /* Look for a psymtab with the specified name. */
975 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
976 if (!strcmp (name
, ps
->filename
)) {
977 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
978 goto again2
; /* Must restart, chain has been munged */
982 /* Look for a symtab with the specified name. */
984 for (s
= symtab_list
; s
; s
= s
->next
)
986 if (!strcmp (name
, s
->filename
))
993 if (s
== symtab_list
)
994 symtab_list
= s
->next
;
996 prev
->next
= s
->next
;
998 /* For now, queue a delete for all breakpoints, displays, etc., whether
999 or not they depend on the symtab being freed. This should be
1000 changed so that only those data structures affected are deleted. */
1002 /* But don't delete anything if the symtab is empty.
1003 This test is necessary due to a bug in "dbxread.c" that
1004 causes empty symtabs to be created for N_SO symbols that
1005 contain the pathname of the object file. (This problem
1006 has been fixed in GDB 3.9x). */
1009 if (BLOCKLIST_NBLOCKS (bv
) > 2
1010 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
1011 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
1013 complain (&oldsyms_complaint
, name
);
1015 clear_symtab_users_queued
++;
1016 make_cleanup (clear_symtab_users_once
, 0);
1019 complain (&empty_symtab_complaint
, name
);
1026 /* It is still possible that some breakpoints will be affected
1027 even though no symtab was found, since the file might have
1028 been compiled without debugging, and hence not be associated
1029 with a symtab. In order to handle this correctly, we would need
1030 to keep a list of text address ranges for undebuggable files.
1031 For now, we do nothing, since this is a fairly obscure case. */
1035 /* FIXME, what about the misc function vector? */
1040 _initialize_symfile ()
1043 add_com ("symbol-file", class_files
, symbol_file_command
,
1044 "Load symbol table from executable file FILE.\n\
1045 The `file' command can also load symbol tables, as well as setting the file\n\
1048 add_com ("add-symbol-file", class_files
, add_symbol_file_command
,
1049 "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
1050 The second argument provides the starting address of the file's text.");
1052 add_com ("load", class_files
, load_command
,
1053 "Dynamically load FILE into the running program, and record its symbols\n\
1054 for access from GDB.");
1057 (add_set_cmd ("complaints", class_support
, var_uinteger
,
1058 (char *)&stop_whining
,
1059 "Set max number of complaints about incorrect symbols.",
1064 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
1065 (char *)&symbol_reloading
,
1066 "Set dynamic symbol table reloading multiple times in one run.",
1070 obstack_init (symbol_obstack
);
1071 obstack_init (psymbol_obstack
);