395d7306ddffe2dfc2992ee9787eb245cfbc3075
[deliverable/binutils-gdb.git] / gdb / symfile.c
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.
4
5 This file is part of GDB.
6
7 GDB 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 1, or (at your option)
10 any later version.
11
12 GDB is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GDB; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include <stdio.h>
22 #include "defs.h"
23 #include "symtab.h"
24 #include "param.h"
25 #include "gdbcore.h"
26 #include "frame.h"
27 #include "target.h"
28 #include "value.h"
29 #include "symfile.h"
30 #include "gdbcmd.h"
31 #include "breakpoint.h"
32
33 #include <obstack.h>
34 #include <assert.h>
35
36 #include <sys/types.h>
37 #include <fcntl.h>
38 #include <string.h>
39 #include <sys/stat.h>
40
41 extern int info_verbose;
42
43 extern int close ();
44 extern void qsort ();
45 extern char *getenv ();
46
47 /* Functions this file defines */
48 static bfd *symfile_open();
49 static struct sym_fns *symfile_init();
50 static void clear_symtab_users_once();
51
52 /* List of all available sym_fns. */
53
54 struct sym_fns *symtab_fns = NULL;
55
56 /* Saves the sym_fns of the current symbol table, so we can call
57 the right sym_discard function when we free it. */
58
59 static struct sym_fns *symfile_fns;
60
61 /* Allocate an obstack to hold objects that should be freed
62 when we load a new symbol table.
63 This includes the symbols made by dbxread
64 and the types that are not permanent. */
65
66 struct obstack obstack1;
67
68 struct obstack *symbol_obstack = &obstack1;
69
70 /* This obstack will be used for partial_symbol objects. It can
71 probably actually be the same as the symbol_obstack above, but I'd
72 like to keep them seperate for now. If I want to later, I'll
73 replace one with the other. */
74
75 struct obstack obstack2;
76
77 struct obstack *psymbol_obstack = &obstack2;
78
79 /* File name symbols were loaded from. */
80
81 char *symfile = 0;
82
83 /* The modification date of the file when they were loaded. */
84
85 int symfile_mtime = 0;
86
87 /* Structures with which to manage partial symbol allocation. */
88
89 struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0};
90
91 /* Structure to manage complaints about symbol file contents. */
92
93 struct complaint complaint_root[1] = {
94 {(char *)0, 0, complaint_root},
95 };
96
97 /* Some actual complaints. */
98
99 struct complaint oldsyms_complaint = {
100 "Replacing old symbols for `%s'", 0, 0 };
101
102 struct complaint empty_symtab_complaint = {
103 "Empty symbol table found for `%s'", 0, 0 };
104
105 \f
106 /* In the following sort, we always make sure that
107 register debug symbol declarations always come before regular
108 debug symbol declarations (as might happen when parameters are
109 then put into registers by the compiler). */
110
111 static int
112 compare_symbols (s1, s2)
113 struct symbol **s1, **s2;
114 {
115 register int namediff;
116
117 /* Compare the initial characters. */
118 namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
119 if (namediff != 0) return namediff;
120
121 /* If they match, compare the rest of the names. */
122 namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
123 if (namediff != 0) return namediff;
124
125 /* For symbols of the same name, registers should come first. */
126 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
127 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
128 }
129
130 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
131
132 void
133 sort_block_syms (b)
134 register struct block *b;
135 {
136 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
137 sizeof (struct symbol *), compare_symbols);
138 }
139
140 /* Call sort_symtab_syms to sort alphabetically
141 the symbols of each block of one symtab. */
142
143 void
144 sort_symtab_syms (s)
145 register struct symtab *s;
146 {
147 register struct blockvector *bv = BLOCKVECTOR (s);
148 int nbl = BLOCKVECTOR_NBLOCKS (bv);
149 int i;
150 register struct block *b;
151
152 for (i = 0; i < nbl; i++)
153 {
154 b = BLOCKVECTOR_BLOCK (bv, i);
155 if (BLOCK_SHOULD_SORT (b))
156 sort_block_syms (b);
157 }
158 }
159
160 void
161 sort_all_symtab_syms ()
162 {
163 register struct symtab *s;
164
165 for (s = symtab_list; s; s = s->next)
166 {
167 sort_symtab_syms (s);
168 }
169 }
170
171 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
172 (and add a null character at the end in the copy).
173 Returns the address of the copy. */
174
175 char *
176 obsavestring (ptr, size)
177 char *ptr;
178 int size;
179 {
180 register char *p = (char *) obstack_alloc (symbol_obstack, size + 1);
181 /* Open-coded bcopy--saves function call time.
182 These strings are usually short. */
183 {
184 register char *p1 = ptr;
185 register char *p2 = p;
186 char *end = ptr + size;
187 while (p1 != end)
188 *p2++ = *p1++;
189 }
190 p[size] = 0;
191 return p;
192 }
193
194 /* Concatenate strings S1, S2 and S3; return the new string.
195 Space is found in the symbol_obstack. */
196
197 char *
198 obconcat (s1, s2, s3)
199 char *s1, *s2, *s3;
200 {
201 register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
202 register char *val = (char *) obstack_alloc (symbol_obstack, len);
203 strcpy (val, s1);
204 strcat (val, s2);
205 strcat (val, s3);
206 return val;
207 }
208 \f
209 /* Accumulate the misc functions in bunches of 127.
210 At the end, copy them all into one newly allocated structure. */
211
212 #define MISC_BUNCH_SIZE 127
213
214 struct misc_bunch
215 {
216 struct misc_bunch *next;
217 struct misc_function contents[MISC_BUNCH_SIZE];
218 };
219
220 /* Bunch currently being filled up.
221 The next field points to chain of filled bunches. */
222
223 static struct misc_bunch *misc_bunch;
224
225 /* Number of slots filled in current bunch. */
226
227 static int misc_bunch_index;
228
229 /* Total number of misc functions recorded so far. */
230
231 static int misc_count;
232
233 void
234 init_misc_bunches ()
235 {
236 misc_count = 0;
237 misc_bunch = 0;
238 misc_bunch_index = MISC_BUNCH_SIZE;
239 }
240
241 void
242 prim_record_misc_function (name, address, misc_type)
243 char *name;
244 CORE_ADDR address;
245 enum misc_function_type misc_type;
246 {
247 register struct misc_bunch *new;
248
249 if (misc_bunch_index == MISC_BUNCH_SIZE)
250 {
251 new = (struct misc_bunch *) xmalloc (sizeof (struct misc_bunch));
252 misc_bunch_index = 0;
253 new->next = misc_bunch;
254 misc_bunch = new;
255 }
256 misc_bunch->contents[misc_bunch_index].name = name;
257 misc_bunch->contents[misc_bunch_index].address = address;
258 misc_bunch->contents[misc_bunch_index].type = misc_type;
259 misc_bunch->contents[misc_bunch_index].misc_info = 0;
260 misc_bunch_index++;
261 misc_count++;
262 }
263
264 static int
265 compare_misc_functions (fn1, fn2)
266 struct misc_function *fn1, *fn2;
267 {
268 /* Return a signed result based on unsigned comparisons
269 so that we sort into unsigned numeric order. */
270 if (fn1->address < fn2->address)
271 return -1;
272 if (fn1->address > fn2->address)
273 return 1;
274 return 0;
275 }
276
277 /* ARGSUSED */
278 void
279 discard_misc_bunches (foo)
280 int foo;
281 {
282 register struct misc_bunch *next;
283
284 while (misc_bunch)
285 {
286 next = misc_bunch->next;
287 free (misc_bunch);
288 misc_bunch = next;
289 }
290 }
291
292 /* INCLINK nonzero means bunches are from an incrementally-linked file.
293 Add them to the existing bunches.
294 Otherwise INCLINK is zero, and we start from scratch. */
295 void
296 condense_misc_bunches (inclink)
297 int inclink;
298 {
299 register int i, j;
300 register struct misc_bunch *bunch;
301
302 if (inclink)
303 {
304 misc_function_vector
305 = (struct misc_function *)
306 xrealloc (misc_function_vector, (misc_count + misc_function_count)
307 * sizeof (struct misc_function));
308 j = misc_function_count;
309 }
310 else
311 {
312 misc_function_vector
313 = (struct misc_function *)
314 xmalloc (misc_count * sizeof (struct misc_function));
315 j = 0;
316 }
317
318 bunch = misc_bunch;
319 while (bunch)
320 {
321 for (i = 0; i < misc_bunch_index; i++, j++)
322 {
323 misc_function_vector[j] = bunch->contents[i];
324 #ifdef NAMES_HAVE_UNDERSCORE
325 if (misc_function_vector[j].name[0] == '_')
326 misc_function_vector[j].name++;
327 #endif
328 }
329 bunch = bunch->next;
330 misc_bunch_index = MISC_BUNCH_SIZE;
331 }
332
333 if (misc_function_count + misc_count != j) /* DEBUG */
334 printf_filtered ("Function counts are off! %d + %d != %d\n",
335 misc_function_count, misc_count, j);
336
337 misc_function_count = j;
338
339 /* Sort the misc functions by address. */
340
341 qsort (misc_function_vector, misc_function_count,
342 sizeof (struct misc_function),
343 compare_misc_functions);
344 }
345
346
347 /* Get the symbol table that corresponds to a partial_symtab.
348 This is fast after the first time you do it. In fact, there
349 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
350 case inline. */
351
352 struct symtab *
353 psymtab_to_symtab (pst)
354 register struct partial_symtab *pst;
355 {
356 register struct symtab *result;
357
358 /* If it's been looked up before, return it. */
359 if (pst->symtab)
360 return pst->symtab;
361
362 /* If it has not yet been read in, read it. */
363 if (!pst->readin)
364 {
365 (*pst->read_symtab) (pst);
366 }
367
368 /* Search through list for correct name. */
369 for (result = symtab_list; result; result = result->next)
370 if (!strcmp (result->filename, pst->filename))
371 {
372 pst->symtab = result; /* Remember where it was. */
373 return result;
374 }
375
376 return 0;
377 }
378
379 /* Process a symbol file, as either the main file or as a dynamically
380 loaded file.
381
382 NAME is the file name (which will be tilde-expanded and made
383 absolute herein) (but we don't free or modify NAME itself).
384 FROM_TTY says how verbose to be. MAINLINE specifies whether this
385 is the main symbol file, or whether it's an extra symbol file such
386 as dynamically loaded code. If !mainline, ADDR is the address
387 where the text segment was loaded. */
388
389 void
390 symbol_file_add (name, from_tty, addr, mainline)
391 char *name;
392 int from_tty;
393 CORE_ADDR addr;
394 int mainline;
395 {
396 bfd *sym_bfd;
397 asection *text_sect;
398 struct sym_fns *sf;
399 char *realname;
400
401 sym_bfd = symfile_open (name);
402
403 entry_point = bfd_get_start_address (sym_bfd);
404
405 if (mainline)
406 symfile_mtime = bfd_get_mtime (sym_bfd);
407
408 /* There is a distinction between having no symbol table
409 (we refuse to read the file, leaving the old set of symbols around)
410 and having no debugging symbols in your symbol table (we read
411 the file and end up with a mostly empty symbol table). */
412
413 if (!(bfd_get_file_flags (sym_bfd) & HAS_SYMS))
414 {
415 error ("%s has no symbol-table", name);
416 }
417
418 if ((symtab_list || partial_symtab_list)
419 && mainline
420 && from_tty
421 && !query ("Load new symbol table from \"%s\"? ", name))
422 error ("Not confirmed.");
423
424 if (from_tty)
425 {
426 printf_filtered ("Reading symbol data from %s...", name);
427 wrap_here ("");
428 fflush (stdout);
429 }
430
431 sf = symfile_init (sym_bfd);
432 realname = bfd_get_filename (sym_bfd);
433 realname = savestring (realname, strlen (realname));
434 /* FIXME, this probably creates a storage leak... */
435
436 if (mainline)
437 {
438 /* Since no error yet, throw away the old symbol table. */
439
440 if (symfile)
441 free (symfile);
442 symfile = 0;
443 free_all_symtabs ();
444 free_all_psymtabs ();
445
446 (*sf->sym_new_init) ();
447
448 /* For mainline, caller didn't know the specified address of the
449 text section. We fix that here. */
450 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
451 addr = bfd_section_vma (sym_bfd, text_sect);
452 }
453
454 clear_complaints(); /* Allow complaints to appear for this new file. */
455
456 (*sf->sym_read) (sf, addr, mainline);
457
458 /* Don't allow char * to have a typename (else would get caddr_t.) */
459 /* Ditto void *. FIXME should do this for all the builtin types. */
460
461 TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
462 TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
463
464 if (mainline)
465 {
466 /* OK, make it the "real" symbol file. */
467 symfile = realname;
468 symfile_fns = sf;
469 }
470
471 /* If we have wiped out any old symbol tables, clean up. */
472 clear_symtab_users_once ();
473
474 if (from_tty)
475 {
476 printf_filtered ("done.\n");
477 fflush (stdout);
478 }
479 }
480
481 /* This is the symbol-file command. Read the file, analyze its symbols,
482 and add a struct symtab to symtab_list. */
483
484 void
485 symbol_file_command (name, from_tty)
486 char *name;
487 int from_tty;
488 {
489
490 dont_repeat ();
491
492 if (name == 0)
493 {
494 if ((symtab_list || partial_symtab_list)
495 && from_tty
496 && !query ("Discard symbol table from `%s'? ", symfile))
497 error ("Not confirmed.");
498 if (symfile)
499 free (symfile);
500 symfile = 0;
501 free_all_symtabs ();
502 free_all_psymtabs ();
503 /* FIXME, this does not account for the main file and subsequent
504 files (shared libs, dynloads, etc) having different formats.
505 It only calls the cleanup routine for the main file's format. */
506 if (symfile_fns) {
507 (*symfile_fns->sym_new_init) ();
508 free (symfile_fns);
509 symfile_fns = 0;
510 }
511 return;
512 }
513
514 symbol_file_add (name, from_tty, (CORE_ADDR)0, 1);
515 }
516
517 /* Open NAME and hand it off to BFD for preliminary analysis. Result
518 is a BFD *, which includes a new copy of NAME dynamically allocated
519 (which will be freed by the cleanup chain). In case of trouble,
520 error() is called. */
521
522 static bfd *
523 symfile_open (name)
524 char *name;
525 {
526 bfd *sym_bfd;
527 int desc;
528 char *absolute_name;
529
530 name = tilde_expand (name);
531 make_cleanup (free, name);
532
533 desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
534 if (desc < 0)
535 perror_with_name (name);
536 else
537 {
538 make_cleanup (free, absolute_name);
539 name = absolute_name;
540 }
541
542 sym_bfd = bfd_fdopenr (name, NULL, desc);
543 if (!sym_bfd)
544 {
545 close (desc);
546 error ("Could not open `%s' to read symbols: %s",
547 name, bfd_errmsg (bfd_error));
548 }
549 make_cleanup (bfd_close, sym_bfd);
550
551 if (!bfd_check_format (sym_bfd, bfd_object))
552 error ("\"%s\": can't read symbols: %s.",
553 name, bfd_errmsg (bfd_error));
554
555 return sym_bfd;
556 }
557
558 /* Link a new symtab_fns into the global symtab_fns list.
559 Called by various _initialize routines. */
560
561 void
562 add_symtab_fns (sf)
563 struct sym_fns *sf;
564 {
565 sf->next = symtab_fns;
566 symtab_fns = sf;
567 }
568
569
570 /* Initialize to read symbols from the symbol file sym_bfd. It either
571 returns or calls error(). The result is a malloc'd struct sym_fns
572 that contains cached information about the symbol file. */
573
574 static struct sym_fns *
575 symfile_init (sym_bfd)
576 bfd *sym_bfd;
577 {
578 struct sym_fns *sf, *sf2;
579
580 for (sf = symtab_fns; sf != NULL; sf = sf->next)
581 {
582 if (!strncmp (bfd_get_target (sym_bfd), sf->sym_name, sf->sym_namelen))
583 {
584 sf2 = (struct sym_fns *)xmalloc (sizeof (*sf2));
585 /* FIXME, who frees this? */
586 *sf2 = *sf;
587 sf2->sym_bfd = sym_bfd;
588 sf2->sym_private = 0; /* Not alloc'd yet */
589 (*sf2->sym_init) (sf2);
590 return sf2;
591 }
592 }
593 error ("I'm sorry, Dave, I can't do that. Symbol format unknown.");
594 }
595 \f
596 /* This function runs the load command of our current target. */
597
598 void
599 load_command (arg, from_tty)
600 char *arg;
601 int from_tty;
602 {
603 target_load (arg, from_tty);
604 }
605
606 /* This function runs the add_syms command of our current target. */
607
608 void
609 add_symbol_file_command (args, from_tty)
610 char *args;
611 int from_tty;
612 {
613 target_add_syms (args, from_tty);
614 }
615
616 /* This function allows the addition of incrementally linked object files. */
617
618 void
619 add_syms_addr_command (arg_string, from_tty)
620 char* arg_string;
621 int from_tty;
622 {
623 char *name;
624 CORE_ADDR text_addr;
625
626 if (arg_string == 0)
627 error ("add-symbol-file takes a file name and an address");
628
629 arg_string = tilde_expand (arg_string);
630 make_cleanup (free, arg_string);
631
632 for( ; *arg_string == ' '; arg_string++ );
633 name = arg_string;
634 for( ; *arg_string && *arg_string != ' ' ; arg_string++ );
635 *arg_string++ = (char) 0;
636
637 if (name[0] == 0)
638 error ("add-symbol-file takes a file name and an address");
639
640 text_addr = parse_and_eval_address (arg_string);
641
642 dont_repeat ();
643
644 if (!query ("add symbol table from file \"%s\" at text_addr = 0x%x\n",
645 name, text_addr))
646 error ("Not confirmed.");
647
648 symbol_file_add (name, 0, text_addr, 0);
649 }
650 \f
651 /* Re-read symbols if the symbol-file has changed. */
652 void
653 reread_symbols ()
654 {
655 struct stat symstat;
656
657 /* With the addition of shared libraries, this should be modified,
658 the load time should be saved in the partial symbol tables, since
659 different tables may come from different source files. FIXME.
660 This routine should then walk down each partial symbol table
661 and see if the symbol table that it originates from has been changed
662 */
663
664 if (stat (symfile, &symstat) < 0)
665 /* Can't read symbol-file. Assume it is up to date. */
666 return;
667
668 if (symstat.st_mtime > symfile_mtime)
669 {
670 printf_filtered ("Symbol file has changed; re-reading symbols.\n");
671 symbol_file_command (symfile, 0);
672 breakpoint_re_set ();
673 }
674 }
675
676
677 /* This function is really horrible, but to avoid it, there would need
678 to be more filling in of forward references. */
679 int
680 fill_in_vptr_fieldno (type)
681 struct type *type;
682 {
683 check_stub_type (type);
684 if (TYPE_VPTR_FIELDNO (type) < 0)
685 TYPE_VPTR_FIELDNO (type) =
686 fill_in_vptr_fieldno (TYPE_BASECLASS (type, 1));
687 return TYPE_VPTR_FIELDNO (type);
688 }
689 \f
690 /* Functions to handle complaints during symbol reading. */
691
692 /* How many complaints about a particular thing should be printed before
693 we stop whining about it? */
694
695 static unsigned stop_whining = 1;
696
697 /* Print a complaint about the input symbols, and link the complaint block
698 into a chain for later handling. Result is 1 if the complaint was
699 printed, 0 if it was suppressed. */
700
701 int
702 complain (complaint, val)
703 struct complaint *complaint;
704 char *val;
705 {
706 complaint->counter++;
707 if (complaint->next == 0) {
708 complaint->next = complaint_root->next;
709 complaint_root->next = complaint;
710 }
711 if (complaint->counter > stop_whining)
712 return 0;
713 wrap_here ("");
714 if (!info_verbose) {
715 puts_filtered ("During symbol reading...");
716 }
717 printf_filtered (complaint->message, val);
718 puts_filtered ("...");
719 wrap_here("");
720 if (!info_verbose)
721 puts_filtered ("\n");
722 return 1;
723 }
724
725 /* Clear out all complaint counters that have ever been incremented. */
726
727 void
728 clear_complaints ()
729 {
730 struct complaint *p;
731
732 for (p = complaint_root->next; p != complaint_root; p = p->next)
733 p->counter = 0;
734 }
735 \f
736 /* clear_symtab_users_once:
737
738 This function is run after symbol reading, or from a cleanup.
739 If an old symbol table was obsoleted, the old symbol table
740 has been blown away, but the other GDB data structures that may
741 reference it have not yet been cleared or re-directed. (The old
742 symtab was zapped, and the cleanup queued, in free_named_symtab()
743 below.)
744
745 This function can be queued N times as a cleanup, or called
746 directly; it will do all the work the first time, and then will be a
747 no-op until the next time it is queued. This works by bumping a
748 counter at queueing time. Much later when the cleanup is run, or at
749 the end of symbol processing (in case the cleanup is discarded), if
750 the queued count is greater than the "done-count", we do the work
751 and set the done-count to the queued count. If the queued count is
752 less than or equal to the done-count, we just ignore the call. This
753 is needed because reading a single .o file will often replace many
754 symtabs (one per .h file, for example), and we don't want to reset
755 the breakpoints N times in the user's face.
756
757 The reason we both queue a cleanup, and call it directly after symbol
758 reading, is because the cleanup protects us in case of errors, but is
759 discarded if symbol reading is successful. */
760
761 static int clear_symtab_users_queued;
762 static int clear_symtab_users_done;
763
764 static void
765 clear_symtab_users_once ()
766 {
767 /* Enforce once-per-`do_cleanups'-semantics */
768 if (clear_symtab_users_queued <= clear_symtab_users_done)
769 return;
770 clear_symtab_users_done = clear_symtab_users_queued;
771
772 printf ("Resetting debugger state after updating old symbol tables\n");
773
774 /* Someday, we should do better than this, by only blowing away
775 the things that really need to be blown. */
776 clear_value_history ();
777 clear_displays ();
778 clear_internalvars ();
779 breakpoint_re_set ();
780 set_default_breakpoint (0, 0, 0, 0);
781 current_source_symtab = 0;
782 }
783
784 /* Delete the specified psymtab, and any others that reference it. */
785
786 cashier_psymtab (pst)
787 struct partial_symtab *pst;
788 {
789 struct partial_symtab *ps, *pprev;
790 int i;
791
792 /* Find its previous psymtab in the chain */
793 for (ps = partial_symtab_list; ps; ps = ps->next) {
794 if (ps == pst)
795 break;
796 pprev = ps;
797 }
798
799 if (ps) {
800 /* Unhook it from the chain. */
801 if (ps == partial_symtab_list)
802 partial_symtab_list = ps->next;
803 else
804 pprev->next = ps->next;
805
806 /* FIXME, we can't conveniently deallocate the entries in the
807 partial_symbol lists (global_psymbols/static_psymbols) that
808 this psymtab points to. These just take up space until all
809 the psymtabs are reclaimed. Ditto the dependencies list and
810 filename, which are all in the psymbol_obstack. */
811
812 /* We need to cashier any psymtab that has this one as a dependency... */
813 again:
814 for (ps = partial_symtab_list; ps; ps = ps->next) {
815 for (i = 0; i < ps->number_of_dependencies; i++) {
816 if (ps->dependencies[i] == pst) {
817 cashier_psymtab (ps);
818 goto again; /* Must restart, chain has been munged. */
819 }
820 }
821 }
822 }
823 }
824
825 /* If a symtab or psymtab for filename NAME is found, free it along
826 with any dependent breakpoints, displays, etc.
827 Used when loading new versions of object modules with the "add-file"
828 command. This is only called on the top-level symtab or psymtab's name;
829 it is not called for subsidiary files such as .h files.
830
831 Return value is 1 if we blew away the environment, 0 if not.
832
833 FIXME. I think this is not the best way to do this. We should
834 work on being gentler to the environment while still cleaning up
835 all stray pointers into the freed symtab. */
836
837 int
838 free_named_symtabs (name)
839 char *name;
840 {
841 register struct symtab *s;
842 register struct symtab *prev;
843 register struct partial_symtab *ps;
844 register struct partial_symtab *pprev;
845 struct blockvector *bv;
846 int blewit = 0;
847
848 /* Look for a psymtab with the specified name. */
849
850 again2:
851 for (ps = partial_symtab_list; ps; ps = ps->next) {
852 if (!strcmp (name, ps->filename)) {
853 cashier_psymtab (ps); /* Blow it away...and its little dog, too. */
854 goto again2; /* Must restart, chain has been munged */
855 }
856 }
857
858 /* Look for a symtab with the specified name. */
859
860 for (s = symtab_list; s; s = s->next)
861 {
862 if (!strcmp (name, s->filename))
863 break;
864 prev = s;
865 }
866
867 if (s)
868 {
869 if (s == symtab_list)
870 symtab_list = s->next;
871 else
872 prev->next = s->next;
873
874 /* For now, queue a delete for all breakpoints, displays, etc., whether
875 or not they depend on the symtab being freed. This should be
876 changed so that only those data structures affected are deleted. */
877
878 /* But don't delete anything if the symtab is empty.
879 This test is necessary due to a bug in "dbxread.c" that
880 causes empty symtabs to be created for N_SO symbols that
881 contain the pathname of the object file. (This problem
882 has been fixed in GDB 3.9x). */
883
884 bv = BLOCKLIST (s);
885 if (BLOCKLIST_NBLOCKS (bv) > 2
886 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
887 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)))
888 {
889 complain (&oldsyms_complaint, name);
890
891 clear_symtab_users_queued++;
892 make_cleanup (clear_symtab_users_once, 0);
893 blewit = 1;
894 } else {
895 complain (&empty_symtab_complaint, name);
896 }
897
898 free_symtab (s);
899 }
900 else
901 /* It is still possible that some breakpoints will be affected
902 even though no symtab was found, since the file might have
903 been compiled without debugging, and hence not be associated
904 with a symtab. In order to handle this correctly, we would need
905 to keep a list of text address ranges for undebuggable files.
906 For now, we do nothing, since this is a fairly obscure case. */
907 ;
908
909 /* FIXME, what about the misc function vector? */
910 return blewit;
911 }
912 \f
913 void
914 _initialize_symfile ()
915 {
916
917 add_com ("symbol-file", class_files, symbol_file_command,
918 "Load symbol table from executable file FILE.\n\
919 The `file' command can also load symbol tables, as well as setting the file\n\
920 to execute.");
921
922 add_com ("add-symbol-file", class_files, add_symbol_file_command,
923 "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
924 The second argument provides the starting address of the file's text.");
925
926 add_com ("load", class_files, load_command,
927 "Dynamically load FILE into the running program, and record its symbols\n\
928 for access from GDB.");
929
930 add_show_from_set
931 (add_set_cmd ("complaints", class_support, var_uinteger,
932 (char *)&stop_whining,
933 "Set max number of complaints about incorrect symbols.",
934 &setlist),
935 &showlist);
936
937 obstack_init (symbol_obstack);
938 obstack_init (psymbol_obstack);
939 }
This page took 0.04831 seconds and 4 git commands to generate.