1 /* Generic symbol file reading for the GNU debugger, GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "breakpoint.h"
33 #include "complaints.h"
35 #include "inferior.h" /* for write_pc */
40 #include <sys/types.h>
42 #include "gdb_string.h"
53 /* Global variables owned by this file */
54 int readnow_symbol_files
; /* Read full symbols immediately */
56 struct complaint oldsyms_complaint
= {
57 "Replacing old symbols for `%s'", 0, 0
60 struct complaint empty_symtab_complaint
= {
61 "Empty symbol table found for `%s'", 0, 0
64 /* External variables and functions referenced. */
66 extern int info_verbose
;
68 /* Functions this file defines */
71 set_initial_language
PARAMS ((void));
74 load_command
PARAMS ((char *, int));
77 add_symbol_file_command
PARAMS ((char *, int));
80 add_shared_symbol_files_command
PARAMS ((char *, int));
83 cashier_psymtab
PARAMS ((struct partial_symtab
*));
86 compare_psymbols
PARAMS ((const void *, const void *));
89 compare_symbols
PARAMS ((const void *, const void *));
92 symfile_bfd_open
PARAMS ((char *));
95 find_sym_fns
PARAMS ((struct objfile
*));
97 /* List of all available sym_fns. On gdb startup, each object file reader
98 calls add_symtab_fns() to register information on each format it is
101 static struct sym_fns
*symtab_fns
= NULL
;
103 /* Flag for whether user will be reloading symbols multiple times.
104 Defaults to ON for VxWorks, otherwise OFF. */
106 #ifdef SYMBOL_RELOADING_DEFAULT
107 int symbol_reloading
= SYMBOL_RELOADING_DEFAULT
;
109 int symbol_reloading
= 0;
112 /* If true, then shared library symbols will be added automatically
113 when the inferior is created. This is almost always what users
114 will want to have happen; but for very large programs, the startup
115 time will be excessive, and so if this is a problem, the user can
116 clear this flag and then add the shared library symbols as needed.
117 Note that there is a potential for confusion, since if the shared
118 library symbols are not loaded, commands like "info fun" will *not*
119 report all the functions that are actually present. */
121 int auto_solib_add_at_startup
= 1;
124 /* Since this function is called from within qsort, in an ANSI environment
125 it must conform to the prototype for qsort, which specifies that the
126 comparison function takes two "void *" pointers. */
129 compare_symbols (s1p
, s2p
)
133 register struct symbol
**s1
, **s2
;
135 s1
= (struct symbol
**) s1p
;
136 s2
= (struct symbol
**) s2p
;
138 return (STRCMP (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
)));
145 compare_psymbols -- compare two partial symbols by name
149 Given pointer to two partial symbol table entries, compare
150 them by name and return -N, 0, or +N (ala strcmp). Typically
151 used by sorting routines like qsort().
155 Does direct compare of first two characters before punting
156 and passing to strcmp for longer compares. Note that the
157 original version had a bug whereby two null strings or two
158 identically named one character strings would return the
159 comparison of memory following the null byte.
164 compare_psymbols (s1p
, s2p
)
168 register char *st1
= SYMBOL_NAME ((struct partial_symbol
*) s1p
);
169 register char *st2
= SYMBOL_NAME ((struct partial_symbol
*) s2p
);
171 if ((st1
[0] - st2
[0]) || !st1
[0])
173 return (st1
[0] - st2
[0]);
175 else if ((st1
[1] - st2
[1]) || !st1
[1])
177 return (st1
[1] - st2
[1]);
181 return (STRCMP (st1
+ 2, st2
+ 2));
186 sort_pst_symbols (pst
)
187 struct partial_symtab
*pst
;
189 /* Sort the global list; don't sort the static list */
191 qsort (pst
-> objfile
-> global_psymbols
.list
+ pst
-> globals_offset
,
192 pst
-> n_global_syms
, sizeof (struct partial_symbol
),
196 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
200 register struct block
*b
;
202 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
203 sizeof (struct symbol
*), compare_symbols
);
206 /* Call sort_symtab_syms to sort alphabetically
207 the symbols of each block of one symtab. */
211 register struct symtab
*s
;
213 register struct blockvector
*bv
;
216 register struct block
*b
;
220 bv
= BLOCKVECTOR (s
);
221 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
222 for (i
= 0; i
< nbl
; i
++)
224 b
= BLOCKVECTOR_BLOCK (bv
, i
);
225 if (BLOCK_SHOULD_SORT (b
))
230 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
231 (and add a null character at the end in the copy).
232 Returns the address of the copy. */
235 obsavestring (ptr
, size
, obstackp
)
238 struct obstack
*obstackp
;
240 register char *p
= (char *) obstack_alloc (obstackp
, size
+ 1);
241 /* Open-coded memcpy--saves function call time.
242 These strings are usually short. */
244 register char *p1
= ptr
;
245 register char *p2
= p
;
246 char *end
= ptr
+ size
;
254 /* Concatenate strings S1, S2 and S3; return the new string.
255 Space is found in the symbol_obstack. */
258 obconcat (obstackp
, s1
, s2
, s3
)
259 struct obstack
*obstackp
;
260 const char *s1
, *s2
, *s3
;
262 register int len
= strlen (s1
) + strlen (s2
) + strlen (s3
) + 1;
263 register char *val
= (char *) obstack_alloc (obstackp
, len
);
270 /* Get the symbol table that corresponds to a partial_symtab.
271 This is fast after the first time you do it. In fact, there
272 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
276 psymtab_to_symtab (pst
)
277 register struct partial_symtab
*pst
;
279 /* If it's been looked up before, return it. */
283 /* If it has not yet been read in, read it. */
286 (*pst
->read_symtab
) (pst
);
292 /* Initialize entry point information for this objfile. */
295 init_entry_point_info (objfile
)
296 struct objfile
*objfile
;
298 /* Save startup file's range of PC addresses to help blockframe.c
299 decide where the bottom of the stack is. */
301 if (bfd_get_file_flags (objfile
-> obfd
) & EXEC_P
)
303 /* Executable file -- record its entry point so we'll recognize
304 the startup file because it contains the entry point. */
305 objfile
-> ei
.entry_point
= bfd_get_start_address (objfile
-> obfd
);
309 /* Examination of non-executable.o files. Short-circuit this stuff. */
310 objfile
-> ei
.entry_point
= INVALID_ENTRY_POINT
;
312 objfile
-> ei
.entry_file_lowpc
= INVALID_ENTRY_LOWPC
;
313 objfile
-> ei
.entry_file_highpc
= INVALID_ENTRY_HIGHPC
;
314 objfile
-> ei
.entry_func_lowpc
= INVALID_ENTRY_LOWPC
;
315 objfile
-> ei
.entry_func_highpc
= INVALID_ENTRY_HIGHPC
;
316 objfile
-> ei
.main_func_lowpc
= INVALID_ENTRY_LOWPC
;
317 objfile
-> ei
.main_func_highpc
= INVALID_ENTRY_HIGHPC
;
320 /* Get current entry point address. */
323 entry_point_address()
325 return symfile_objfile
? symfile_objfile
->ei
.entry_point
: 0;
328 /* Remember the lowest-addressed loadable section we've seen.
329 This function is called via bfd_map_over_sections.
331 In case of equal vmas, the section with the largest size becomes the
332 lowest-addressed loadable section.
334 If the vmas and sizes are equal, the last section is considered the
335 lowest-addressed loadable section. */
338 find_lowest_section (abfd
, sect
, obj
)
343 asection
**lowest
= (asection
**)obj
;
345 if (0 == (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
))
348 *lowest
= sect
; /* First loadable section */
349 else if (bfd_section_vma (abfd
, *lowest
) > bfd_section_vma (abfd
, sect
))
350 *lowest
= sect
; /* A lower loadable section */
351 else if (bfd_section_vma (abfd
, *lowest
) == bfd_section_vma (abfd
, sect
)
352 && (bfd_section_size (abfd
, (*lowest
))
353 <= bfd_section_size (abfd
, sect
)))
357 /* Process a symbol file, as either the main file or as a dynamically
360 NAME is the file name (which will be tilde-expanded and made
361 absolute herein) (but we don't free or modify NAME itself).
362 FROM_TTY says how verbose to be. MAINLINE specifies whether this
363 is the main symbol file, or whether it's an extra symbol file such
364 as dynamically loaded code. If !mainline, ADDR is the address
365 where the text segment was loaded. If VERBO, the caller has printed
366 a verbose message about the symbol reading (and complaints can be
367 more terse about it). */
370 syms_from_objfile (objfile
, addr
, mainline
, verbo
)
371 struct objfile
*objfile
;
376 struct section_offsets
*section_offsets
;
377 asection
*lowest_sect
;
378 struct cleanup
*old_chain
;
380 init_entry_point_info (objfile
);
381 find_sym_fns (objfile
);
383 /* Make sure that partially constructed symbol tables will be cleaned up
384 if an error occurs during symbol reading. */
385 old_chain
= make_cleanup (free_objfile
, objfile
);
389 /* We will modify the main symbol table, make sure that all its users
390 will be cleaned up if an error occurs during symbol reading. */
391 make_cleanup (clear_symtab_users
, 0);
393 /* Since no error yet, throw away the old symbol table. */
395 if (symfile_objfile
!= NULL
)
397 free_objfile (symfile_objfile
);
398 symfile_objfile
= NULL
;
401 /* Currently we keep symbols from the add-symbol-file command.
402 If the user wants to get rid of them, they should do "symbol-file"
403 without arguments first. Not sure this is the best behavior
406 (*objfile
-> sf
-> sym_new_init
) (objfile
);
409 /* Convert addr into an offset rather than an absolute address.
410 We find the lowest address of a loaded segment in the objfile,
411 and assume that <addr> is where that got loaded. Due to historical
412 precedent, we warn if that doesn't happen to be a text segment. */
416 addr
= 0; /* No offset from objfile addresses. */
420 lowest_sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
421 if (lowest_sect
== NULL
)
422 bfd_map_over_sections (objfile
->obfd
, find_lowest_section
,
425 if (lowest_sect
== NULL
)
426 warning ("no loadable sections found in added symbol-file %s",
428 else if ((bfd_get_section_flags (objfile
->obfd
, lowest_sect
) & SEC_CODE
)
430 /* FIXME-32x64--assumes bfd_vma fits in long. */
431 warning ("Lowest section in %s is %s at 0x%lx",
433 bfd_section_name (objfile
->obfd
, lowest_sect
),
434 (unsigned long) bfd_section_vma (objfile
->obfd
, lowest_sect
));
437 addr
-= bfd_section_vma (objfile
->obfd
, lowest_sect
);
440 /* Initialize symbol reading routines for this objfile, allow complaints to
441 appear for this new file, and record how verbose to be, then do the
442 initial symbol reading for this file. */
444 (*objfile
-> sf
-> sym_init
) (objfile
);
445 clear_complaints (1, verbo
);
447 section_offsets
= (*objfile
-> sf
-> sym_offsets
) (objfile
, addr
);
448 objfile
->section_offsets
= section_offsets
;
450 #ifndef IBM6000_TARGET
451 /* This is a SVR4/SunOS specific hack, I think. In any event, it
452 screws RS/6000. sym_offsets should be doing this sort of thing,
453 because it knows the mapping between bfd sections and
455 /* This is a hack. As far as I can tell, section offsets are not
456 target dependent. They are all set to addr with a couple of
457 exceptions. The exceptions are sysvr4 shared libraries, whose
458 offsets are kept in solib structures anyway and rs6000 xcoff
459 which handles shared libraries in a completely unique way.
461 Section offsets are built similarly, except that they are built
462 by adding addr in all cases because there is no clear mapping
463 from section_offsets into actual sections. Note that solib.c
464 has a different algorythm for finding section offsets.
466 These should probably all be collapsed into some target
467 independent form of shared library support. FIXME. */
471 struct obj_section
*s
;
473 for (s
= objfile
->sections
; s
< objfile
->sections_end
; ++s
)
475 s
->addr
-= s
->offset
;
477 s
->endaddr
-= s
->offset
;
482 #endif /* not IBM6000_TARGET */
484 (*objfile
-> sf
-> sym_read
) (objfile
, section_offsets
, mainline
);
486 if (!have_partial_symbols () && !have_full_symbols ())
489 printf_filtered ("(no debugging symbols found)...");
493 /* Don't allow char * to have a typename (else would get caddr_t).
494 Ditto void *. FIXME: Check whether this is now done by all the
495 symbol readers themselves (many of them now do), and if so remove
498 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
499 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
501 /* Mark the objfile has having had initial symbol read attempted. Note
502 that this does not mean we found any symbols... */
504 objfile
-> flags
|= OBJF_SYMS
;
506 /* Discard cleanups as symbol reading was successful. */
508 discard_cleanups (old_chain
);
510 /* Call this after reading in a new symbol table to give target dependant code
511 a crack at the new symbols. For instance, this could be used to update the
512 values of target-specific symbols GDB needs to keep track of (such as
513 _sigtramp, or whatever). */
515 TARGET_SYMFILE_POSTREAD (objfile
);
518 /* Perform required actions after either reading in the initial
519 symbols for a new objfile, or mapping in the symbols from a reusable
523 new_symfile_objfile (objfile
, mainline
, verbo
)
524 struct objfile
*objfile
;
529 /* If this is the main symbol file we have to clean up all users of the
530 old main symbol file. Otherwise it is sufficient to fixup all the
531 breakpoints that may have been redefined by this symbol file. */
534 /* OK, make it the "real" symbol file. */
535 symfile_objfile
= objfile
;
537 clear_symtab_users ();
541 breakpoint_re_set ();
544 /* We're done reading the symbol file; finish off complaints. */
545 clear_complaints (0, verbo
);
548 /* Process a symbol file, as either the main file or as a dynamically
551 NAME is the file name (which will be tilde-expanded and made
552 absolute herein) (but we don't free or modify NAME itself).
553 FROM_TTY says how verbose to be. MAINLINE specifies whether this
554 is the main symbol file, or whether it's an extra symbol file such
555 as dynamically loaded code. If !mainline, ADDR is the address
556 where the text segment was loaded.
558 Upon success, returns a pointer to the objfile that was added.
559 Upon failure, jumps back to command level (never returns). */
562 symbol_file_add (name
, from_tty
, addr
, mainline
, mapped
, readnow
)
570 struct objfile
*objfile
;
571 struct partial_symtab
*psymtab
;
574 /* Open a bfd for the file, and give user a chance to burp if we'd be
575 interactively wiping out any existing symbols. */
577 abfd
= symfile_bfd_open (name
);
579 if ((have_full_symbols () || have_partial_symbols ())
582 && !query ("Load new symbol table from \"%s\"? ", name
))
583 error ("Not confirmed.");
585 objfile
= allocate_objfile (abfd
, mapped
);
587 /* If the objfile uses a mapped symbol file, and we have a psymtab for
588 it, then skip reading any symbols at this time. */
590 if ((objfile
-> flags
& OBJF_MAPPED
) && (objfile
-> flags
& OBJF_SYMS
))
592 /* We mapped in an existing symbol table file that already has had
593 initial symbol reading performed, so we can skip that part. Notify
594 the user that instead of reading the symbols, they have been mapped.
596 if (from_tty
|| info_verbose
)
598 printf_filtered ("Mapped symbols for %s...", name
);
600 gdb_flush (gdb_stdout
);
602 init_entry_point_info (objfile
);
603 find_sym_fns (objfile
);
607 /* We either created a new mapped symbol table, mapped an existing
608 symbol table file which has not had initial symbol reading
609 performed, or need to read an unmapped symbol table. */
610 if (from_tty
|| info_verbose
)
612 printf_filtered ("Reading symbols from %s...", name
);
614 gdb_flush (gdb_stdout
);
616 syms_from_objfile (objfile
, addr
, mainline
, from_tty
);
619 /* We now have at least a partial symbol table. Check to see if the
620 user requested that all symbols be read on initial access via either
621 the gdb startup command line or on a per symbol file basis. Expand
622 all partial symbol tables for this objfile if so. */
624 if (readnow
|| readnow_symbol_files
)
626 if (from_tty
|| info_verbose
)
628 printf_filtered ("expanding to full symbols...");
630 gdb_flush (gdb_stdout
);
633 for (psymtab
= objfile
-> psymtabs
;
635 psymtab
= psymtab
-> next
)
637 psymtab_to_symtab (psymtab
);
641 if (from_tty
|| info_verbose
)
643 printf_filtered ("done.\n");
644 gdb_flush (gdb_stdout
);
647 new_symfile_objfile (objfile
, mainline
, from_tty
);
652 /* This is the symbol-file command. Read the file, analyze its
653 symbols, and add a struct symtab to a symtab list. The syntax of
654 the command is rather bizarre--(1) buildargv implements various
655 quoting conventions which are undocumented and have little or
656 nothing in common with the way things are quoted (or not quoted)
657 elsewhere in GDB, (2) options are used, which are not generally
658 used in GDB (perhaps "set mapped on", "set readnow on" would be
659 better), (3) the order of options matters, which is contrary to GNU
660 conventions (because it is confusing and inconvenient). */
663 symbol_file_command (args
, from_tty
)
669 CORE_ADDR text_relocation
= 0; /* text_relocation */
670 struct cleanup
*cleanups
;
678 if ((have_full_symbols () || have_partial_symbols ())
680 && !query ("Discard symbol table from `%s'? ",
681 symfile_objfile
-> name
))
682 error ("Not confirmed.");
683 free_all_objfiles ();
684 symfile_objfile
= NULL
;
687 printf_unfiltered ("No symbol file now.\n");
692 if ((argv
= buildargv (args
)) == NULL
)
696 cleanups
= make_cleanup (freeargv
, (char *) argv
);
697 while (*argv
!= NULL
)
699 if (STREQ (*argv
, "-mapped"))
703 else if (STREQ (*argv
, "-readnow"))
707 else if (**argv
== '-')
709 error ("unknown option `%s'", *argv
);
717 /* this is for rombug remote only, to get the text relocation by
718 using link command */
719 p
= strrchr(name
, '/');
723 target_link(p
, &text_relocation
);
725 if (text_relocation
== (CORE_ADDR
)0)
727 else if (text_relocation
== (CORE_ADDR
)-1)
728 symbol_file_add (name
, from_tty
, (CORE_ADDR
)0, 1, mapped
,
731 symbol_file_add (name
, from_tty
, (CORE_ADDR
)text_relocation
,
734 /* Getting new symbols may change our opinion about what is
736 reinit_frame_cache ();
738 set_initial_language ();
745 error ("no symbol file name was specified");
747 do_cleanups (cleanups
);
751 /* Set the initial language.
753 A better solution would be to record the language in the psymtab when reading
754 partial symbols, and then use it (if known) to set the language. This would
755 be a win for formats that encode the language in an easily discoverable place,
756 such as DWARF. For stabs, we can jump through hoops looking for specially
757 named symbols or try to intuit the language from the specific type of stabs
758 we find, but we can't do that until later when we read in full symbols.
762 set_initial_language ()
764 struct partial_symtab
*pst
;
765 enum language lang
= language_unknown
;
767 pst
= find_main_psymtab ();
770 if (pst
-> filename
!= NULL
)
772 lang
= deduce_language_from_filename (pst
-> filename
);
774 if (lang
== language_unknown
)
776 /* Make C the default language */
780 expected_language
= current_language
; /* Don't warn the user */
784 /* Open file specified by NAME and hand it off to BFD for preliminary
785 analysis. Result is a newly initialized bfd *, which includes a newly
786 malloc'd` copy of NAME (tilde-expanded and made absolute).
787 In case of trouble, error() is called. */
790 symfile_bfd_open (name
)
797 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy */
799 /* Look down path for it, allocate 2nd new malloc'd copy. */
800 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
| O_BINARY
, 0, &absolute_name
);
803 make_cleanup (free
, name
);
804 perror_with_name (name
);
806 free (name
); /* Free 1st new malloc'd copy */
807 name
= absolute_name
; /* Keep 2nd malloc'd copy in bfd */
808 /* It'll be freed in free_objfile(). */
810 sym_bfd
= bfd_fdopenr (name
, gnutarget
, desc
);
814 make_cleanup (free
, name
);
815 error ("\"%s\": can't open to read symbols: %s.", name
,
816 bfd_errmsg (bfd_get_error ()));
818 sym_bfd
->cacheable
= true;
820 if (!bfd_check_format (sym_bfd
, bfd_object
))
822 /* FIXME: should be checking for errors from bfd_close (for one thing,
823 on error it does not free all the storage associated with the
825 bfd_close (sym_bfd
); /* This also closes desc */
826 make_cleanup (free
, name
);
827 error ("\"%s\": can't read symbols: %s.", name
,
828 bfd_errmsg (bfd_get_error ()));
834 /* Link a new symtab_fns into the global symtab_fns list. Called on gdb
835 startup by the _initialize routine in each object file format reader,
836 to register information about each format the the reader is prepared
843 sf
->next
= symtab_fns
;
848 /* Initialize to read symbols from the symbol file sym_bfd. It either
849 returns or calls error(). The result is an initialized struct sym_fns
850 in the objfile structure, that contains cached information about the
854 find_sym_fns (objfile
)
855 struct objfile
*objfile
;
858 enum bfd_flavour our_flavour
= bfd_get_flavour (objfile
-> obfd
);
859 char *our_target
= bfd_get_target (objfile
-> obfd
);
861 /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */
862 if (STREQ (our_target
, "aixcoff-rs6000") ||
863 STREQ (our_target
, "xcoff-powermac"))
864 our_flavour
= (enum bfd_flavour
)-1;
866 /* Special kludge for apollo. See dstread.c. */
867 if (STREQN (our_target
, "apollo", 6))
868 our_flavour
= (enum bfd_flavour
)-2;
870 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
-> next
)
872 if (our_flavour
== sf
-> sym_flavour
)
878 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
879 bfd_get_target (objfile
-> obfd
));
882 /* This function runs the load command of our current target. */
885 load_command (arg
, from_tty
)
890 arg
= get_exec_file (1);
891 target_load (arg
, from_tty
);
894 /* This version of "load" should be usable for any target. Currently
895 it is just used for remote targets, not inftarg.c or core files,
896 on the theory that only in that case is it useful.
898 Avoiding xmodem and the like seems like a win (a) because we don't have
899 to worry about finding it, and (b) On VMS, fork() is very slow and so
900 we don't want to run a subprocess. On the other hand, I'm not sure how
901 performance compares. */
903 generic_load (filename
, from_tty
)
907 struct cleanup
*old_cleanups
;
911 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
912 if (loadfile_bfd
== NULL
)
914 perror_with_name (filename
);
917 /* FIXME: should be checking for errors from bfd_close (for one thing,
918 on error it does not free all the storage associated with the
920 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
922 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
924 error ("\"%s\" is not an object file: %s", filename
,
925 bfd_errmsg (bfd_get_error ()));
928 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
930 if (s
->flags
& SEC_LOAD
)
934 size
= bfd_get_section_size_before_reloc (s
);
938 struct cleanup
*old_chain
;
941 buffer
= xmalloc (size
);
942 old_chain
= make_cleanup (free
, buffer
);
944 vma
= bfd_get_section_vma (loadfile_bfd
, s
);
946 /* Is this really necessary? I guess it gives the user something
947 to look at during a long download. */
948 printf_filtered ("Loading section %s, size 0x%lx vma ",
949 bfd_get_section_name (loadfile_bfd
, s
),
950 (unsigned long) size
);
951 print_address_numeric (vma
, 1, gdb_stdout
);
952 printf_filtered ("\n");
954 bfd_get_section_contents (loadfile_bfd
, s
, buffer
, 0, size
);
956 target_write_memory (vma
, buffer
, size
);
958 do_cleanups (old_chain
);
963 /* We were doing this in remote-mips.c, I suspect it is right
964 for other targets too. */
965 write_pc (loadfile_bfd
->start_address
);
967 /* FIXME: are we supposed to call symbol_file_add or not? According to
968 a comment from remote-mips.c (where a call to symbol_file_add was
969 commented out), making the call confuses GDB if more than one file is
970 loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c
973 do_cleanups (old_cleanups
);
976 /* This function allows the addition of incrementally linked object files.
977 It does not modify any state in the target, only in the debugger. */
981 add_symbol_file_command (args
, from_tty
)
995 error ("add-symbol-file takes a file name and an address");
998 /* Make a copy of the string that we can safely write into. */
1000 args
= strdup (args
);
1001 make_cleanup (free
, args
);
1003 /* Pick off any -option args and the file name. */
1005 while ((*args
!= '\000') && (name
== NULL
))
1007 while (isspace (*args
)) {args
++;}
1009 while ((*args
!= '\000') && !isspace (*args
)) {args
++;}
1010 if (*args
!= '\000')
1018 else if (STREQ (arg
, "-mapped"))
1022 else if (STREQ (arg
, "-readnow"))
1028 error ("unknown option `%s'", arg
);
1032 /* After picking off any options and the file name, args should be
1033 left pointing at the remainder of the command line, which should
1034 be the address expression to evaluate. */
1038 error ("add-symbol-file takes a file name");
1040 name
= tilde_expand (name
);
1041 make_cleanup (free
, name
);
1043 if (*args
!= '\000')
1045 text_addr
= parse_and_eval_address (args
);
1049 target_link(name
, &text_addr
);
1050 if (text_addr
== (CORE_ADDR
)-1)
1051 error("Don't know how to get text start location for this file");
1054 /* FIXME-32x64: Assumes text_addr fits in a long. */
1055 if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
1056 name
, local_hex_string ((unsigned long)text_addr
)))
1057 error ("Not confirmed.");
1059 symbol_file_add (name
, 0, text_addr
, 0, mapped
, readnow
);
1061 /* Getting new symbols may change our opinion about what is
1063 reinit_frame_cache ();
1067 add_shared_symbol_files_command (args
, from_tty
)
1071 #ifdef ADD_SHARED_SYMBOL_FILES
1072 ADD_SHARED_SYMBOL_FILES (args
, from_tty
);
1074 error ("This command is not available in this configuration of GDB.");
1078 /* Re-read symbols if a symbol-file has changed. */
1082 struct objfile
*objfile
;
1085 struct stat new_statbuf
;
1088 /* With the addition of shared libraries, this should be modified,
1089 the load time should be saved in the partial symbol tables, since
1090 different tables may come from different source files. FIXME.
1091 This routine should then walk down each partial symbol table
1092 and see if the symbol table that it originates from has been changed */
1094 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
) {
1095 if (objfile
->obfd
) {
1096 #ifdef IBM6000_TARGET
1097 /* If this object is from a shared library, then you should
1098 stat on the library name, not member name. */
1100 if (objfile
->obfd
->my_archive
)
1101 res
= stat (objfile
->obfd
->my_archive
->filename
, &new_statbuf
);
1104 res
= stat (objfile
->name
, &new_statbuf
);
1106 /* FIXME, should use print_sys_errmsg but it's not filtered. */
1107 printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
1111 new_modtime
= new_statbuf
.st_mtime
;
1112 if (new_modtime
!= objfile
->mtime
)
1114 struct cleanup
*old_cleanups
;
1115 struct section_offsets
*offsets
;
1117 int section_offsets_size
;
1118 char *obfd_filename
;
1120 printf_filtered ("`%s' has changed; re-reading symbols.\n",
1123 /* There are various functions like symbol_file_add,
1124 symfile_bfd_open, syms_from_objfile, etc., which might
1125 appear to do what we want. But they have various other
1126 effects which we *don't* want. So we just do stuff
1127 ourselves. We don't worry about mapped files (for one thing,
1128 any mapped file will be out of date). */
1130 /* If we get an error, blow away this objfile (not sure if
1131 that is the correct response for things like shared
1133 old_cleanups
= make_cleanup (free_objfile
, objfile
);
1134 /* We need to do this whenever any symbols go away. */
1135 make_cleanup (clear_symtab_users
, 0);
1137 /* Clean up any state BFD has sitting around. We don't need
1138 to close the descriptor but BFD lacks a way of closing the
1139 BFD without closing the descriptor. */
1140 obfd_filename
= bfd_get_filename (objfile
->obfd
);
1141 if (!bfd_close (objfile
->obfd
))
1142 error ("Can't close BFD for %s: %s", objfile
->name
,
1143 bfd_errmsg (bfd_get_error ()));
1144 objfile
->obfd
= bfd_openr (obfd_filename
, gnutarget
);
1145 if (objfile
->obfd
== NULL
)
1146 error ("Can't open %s to read symbols.", objfile
->name
);
1147 /* bfd_openr sets cacheable to true, which is what we want. */
1148 if (!bfd_check_format (objfile
->obfd
, bfd_object
))
1149 error ("Can't read symbols from %s: %s.", objfile
->name
,
1150 bfd_errmsg (bfd_get_error ()));
1152 /* Save the offsets, we will nuke them with the rest of the
1154 num_offsets
= objfile
->num_sections
;
1155 section_offsets_size
=
1156 sizeof (struct section_offsets
)
1157 + sizeof (objfile
->section_offsets
->offsets
) * num_offsets
;
1158 offsets
= (struct section_offsets
*) alloca (section_offsets_size
);
1159 memcpy (offsets
, objfile
->section_offsets
, section_offsets_size
);
1161 /* Nuke all the state that we will re-read. Much of the following
1162 code which sets things to NULL really is necessary to tell
1163 other parts of GDB that there is nothing currently there. */
1165 /* FIXME: Do we have to free a whole linked list, or is this
1167 if (objfile
->global_psymbols
.list
)
1168 mfree (objfile
->md
, objfile
->global_psymbols
.list
);
1169 objfile
->global_psymbols
.list
= NULL
;
1170 objfile
->global_psymbols
.next
= NULL
;
1171 objfile
->global_psymbols
.size
= 0;
1172 if (objfile
->static_psymbols
.list
)
1173 mfree (objfile
->md
, objfile
->static_psymbols
.list
);
1174 objfile
->static_psymbols
.list
= NULL
;
1175 objfile
->static_psymbols
.next
= NULL
;
1176 objfile
->static_psymbols
.size
= 0;
1178 /* Free the obstacks for non-reusable objfiles */
1179 obstack_free (&objfile
-> psymbol_obstack
, 0);
1180 obstack_free (&objfile
-> symbol_obstack
, 0);
1181 obstack_free (&objfile
-> type_obstack
, 0);
1182 objfile
->sections
= NULL
;
1183 objfile
->symtabs
= NULL
;
1184 objfile
->psymtabs
= NULL
;
1185 objfile
->free_psymtabs
= NULL
;
1186 objfile
->msymbols
= NULL
;
1187 objfile
->minimal_symbol_count
= 0;
1188 objfile
->fundamental_types
= NULL
;
1189 if (objfile
-> sf
!= NULL
)
1191 (*objfile
-> sf
-> sym_finish
) (objfile
);
1194 /* We never make this a mapped file. */
1195 objfile
-> md
= NULL
;
1196 /* obstack_specify_allocation also initializes the obstack so
1198 obstack_specify_allocation (&objfile
-> psymbol_obstack
, 0, 0,
1200 obstack_specify_allocation (&objfile
-> symbol_obstack
, 0, 0,
1202 obstack_specify_allocation (&objfile
-> type_obstack
, 0, 0,
1204 if (build_objfile_section_table (objfile
))
1206 error ("Can't find the file sections in `%s': %s",
1207 objfile
-> name
, bfd_errmsg (bfd_get_error ()));
1210 /* We use the same section offsets as from last time. I'm not
1211 sure whether that is always correct for shared libraries. */
1212 objfile
->section_offsets
= (struct section_offsets
*)
1213 obstack_alloc (&objfile
-> psymbol_obstack
, section_offsets_size
);
1214 memcpy (objfile
->section_offsets
, offsets
, section_offsets_size
);
1215 objfile
->num_sections
= num_offsets
;
1217 /* What the hell is sym_new_init for, anyway? The concept of
1218 distinguishing between the main file and additional files
1219 in this way seems rather dubious. */
1220 if (objfile
== symfile_objfile
)
1221 (*objfile
->sf
->sym_new_init
) (objfile
);
1223 (*objfile
->sf
->sym_init
) (objfile
);
1224 clear_complaints (1, 1);
1225 /* The "mainline" parameter is a hideous hack; I think leaving it
1226 zero is OK since dbxread.c also does what it needs to do if
1227 objfile->global_psymbols.size is 0. */
1228 (*objfile
->sf
->sym_read
) (objfile
, objfile
->section_offsets
, 0);
1229 if (!have_partial_symbols () && !have_full_symbols ())
1232 printf_filtered ("(no debugging symbols found)\n");
1235 objfile
-> flags
|= OBJF_SYMS
;
1237 /* We're done reading the symbol file; finish off complaints. */
1238 clear_complaints (0, 1);
1240 /* Getting new symbols may change our opinion about what is
1243 reinit_frame_cache ();
1245 /* Discard cleanups as symbol reading was successful. */
1246 discard_cleanups (old_cleanups
);
1248 /* If the mtime has changed between the time we set new_modtime
1249 and now, we *want* this to be out of date, so don't call stat
1251 objfile
->mtime
= new_modtime
;
1254 /* Call this after reading in a new symbol table to give target
1255 dependant code a crack at the new symbols. For instance, this
1256 could be used to update the values of target-specific symbols GDB
1257 needs to keep track of (such as _sigtramp, or whatever). */
1259 TARGET_SYMFILE_POSTREAD (objfile
);
1265 clear_symtab_users ();
1270 deduce_language_from_filename (filename
)
1277 else if (0 == (c
= strrchr (filename
, '.')))
1278 ; /* Get default. */
1279 else if (STREQ (c
, ".c"))
1281 else if (STREQ (c
, ".cc") || STREQ (c
, ".C") || STREQ (c
, ".cxx")
1282 || STREQ (c
, ".cpp") || STREQ (c
, ".cp") || STREQ (c
, ".c++"))
1283 return language_cplus
;
1284 else if (STREQ (c
, ".ch") || STREQ (c
, ".c186") || STREQ (c
, ".c286"))
1285 return language_chill
;
1286 else if (STREQ (c
, ".f") || STREQ (c
, ".F"))
1287 return language_fortran
;
1288 else if (STREQ (c
, ".mod"))
1290 else if (STREQ (c
, ".s") || STREQ (c
, ".S"))
1291 return language_asm
;
1293 return language_unknown
; /* default */
1298 Allocate and partly initialize a new symbol table. Return a pointer
1299 to it. error() if no space.
1301 Caller must set these fields:
1307 initialize any EXTRA_SYMTAB_INFO
1308 possibly free_named_symtabs (symtab->filename);
1312 allocate_symtab (filename
, objfile
)
1314 struct objfile
*objfile
;
1316 register struct symtab
*symtab
;
1318 symtab
= (struct symtab
*)
1319 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symtab
));
1320 memset (symtab
, 0, sizeof (*symtab
));
1321 symtab
-> filename
= obsavestring (filename
, strlen (filename
),
1322 &objfile
-> symbol_obstack
);
1323 symtab
-> fullname
= NULL
;
1324 symtab
-> language
= deduce_language_from_filename (filename
);
1326 /* Hook it to the objfile it comes from */
1328 symtab
-> objfile
= objfile
;
1329 symtab
-> next
= objfile
-> symtabs
;
1330 objfile
-> symtabs
= symtab
;
1332 #ifdef INIT_EXTRA_SYMTAB_INFO
1333 INIT_EXTRA_SYMTAB_INFO (symtab
);
1339 struct partial_symtab
*
1340 allocate_psymtab (filename
, objfile
)
1342 struct objfile
*objfile
;
1344 struct partial_symtab
*psymtab
;
1346 if (objfile
-> free_psymtabs
)
1348 psymtab
= objfile
-> free_psymtabs
;
1349 objfile
-> free_psymtabs
= psymtab
-> next
;
1352 psymtab
= (struct partial_symtab
*)
1353 obstack_alloc (&objfile
-> psymbol_obstack
,
1354 sizeof (struct partial_symtab
));
1356 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1357 psymtab
-> filename
= obsavestring (filename
, strlen (filename
),
1358 &objfile
-> psymbol_obstack
);
1359 psymtab
-> symtab
= NULL
;
1361 /* Hook it to the objfile it comes from */
1363 psymtab
-> objfile
= objfile
;
1364 psymtab
-> next
= objfile
-> psymtabs
;
1365 objfile
-> psymtabs
= psymtab
;
1371 /* Reset all data structures in gdb which may contain references to symbol
1375 clear_symtab_users ()
1377 /* Someday, we should do better than this, by only blowing away
1378 the things that really need to be blown. */
1379 clear_value_history ();
1381 clear_internalvars ();
1382 breakpoint_re_set ();
1383 set_default_breakpoint (0, 0, 0, 0);
1384 current_source_symtab
= 0;
1385 current_source_line
= 0;
1386 clear_pc_function_cache ();
1389 /* clear_symtab_users_once:
1391 This function is run after symbol reading, or from a cleanup.
1392 If an old symbol table was obsoleted, the old symbol table
1393 has been blown away, but the other GDB data structures that may
1394 reference it have not yet been cleared or re-directed. (The old
1395 symtab was zapped, and the cleanup queued, in free_named_symtab()
1398 This function can be queued N times as a cleanup, or called
1399 directly; it will do all the work the first time, and then will be a
1400 no-op until the next time it is queued. This works by bumping a
1401 counter at queueing time. Much later when the cleanup is run, or at
1402 the end of symbol processing (in case the cleanup is discarded), if
1403 the queued count is greater than the "done-count", we do the work
1404 and set the done-count to the queued count. If the queued count is
1405 less than or equal to the done-count, we just ignore the call. This
1406 is needed because reading a single .o file will often replace many
1407 symtabs (one per .h file, for example), and we don't want to reset
1408 the breakpoints N times in the user's face.
1410 The reason we both queue a cleanup, and call it directly after symbol
1411 reading, is because the cleanup protects us in case of errors, but is
1412 discarded if symbol reading is successful. */
1415 /* FIXME: As free_named_symtabs is currently a big noop this function
1416 is no longer needed. */
1418 clear_symtab_users_once
PARAMS ((void));
1420 static int clear_symtab_users_queued
;
1421 static int clear_symtab_users_done
;
1424 clear_symtab_users_once ()
1426 /* Enforce once-per-`do_cleanups'-semantics */
1427 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
1429 clear_symtab_users_done
= clear_symtab_users_queued
;
1431 clear_symtab_users ();
1435 /* Delete the specified psymtab, and any others that reference it. */
1438 cashier_psymtab (pst
)
1439 struct partial_symtab
*pst
;
1441 struct partial_symtab
*ps
, *pprev
= NULL
;
1444 /* Find its previous psymtab in the chain */
1445 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1452 /* Unhook it from the chain. */
1453 if (ps
== pst
->objfile
->psymtabs
)
1454 pst
->objfile
->psymtabs
= ps
->next
;
1456 pprev
->next
= ps
->next
;
1458 /* FIXME, we can't conveniently deallocate the entries in the
1459 partial_symbol lists (global_psymbols/static_psymbols) that
1460 this psymtab points to. These just take up space until all
1461 the psymtabs are reclaimed. Ditto the dependencies list and
1462 filename, which are all in the psymbol_obstack. */
1464 /* We need to cashier any psymtab that has this one as a dependency... */
1466 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1467 for (i
= 0; i
< ps
->number_of_dependencies
; i
++) {
1468 if (ps
->dependencies
[i
] == pst
) {
1469 cashier_psymtab (ps
);
1470 goto again
; /* Must restart, chain has been munged. */
1477 /* If a symtab or psymtab for filename NAME is found, free it along
1478 with any dependent breakpoints, displays, etc.
1479 Used when loading new versions of object modules with the "add-file"
1480 command. This is only called on the top-level symtab or psymtab's name;
1481 it is not called for subsidiary files such as .h files.
1483 Return value is 1 if we blew away the environment, 0 if not.
1484 FIXME. The return valu appears to never be used.
1486 FIXME. I think this is not the best way to do this. We should
1487 work on being gentler to the environment while still cleaning up
1488 all stray pointers into the freed symtab. */
1491 free_named_symtabs (name
)
1495 /* FIXME: With the new method of each objfile having it's own
1496 psymtab list, this function needs serious rethinking. In particular,
1497 why was it ever necessary to toss psymtabs with specific compilation
1498 unit filenames, as opposed to all psymtabs from a particular symbol
1500 Well, the answer is that some systems permit reloading of particular
1501 compilation units. We want to blow away any old info about these
1502 compilation units, regardless of which objfiles they arrived in. --gnu. */
1504 register struct symtab
*s
;
1505 register struct symtab
*prev
;
1506 register struct partial_symtab
*ps
;
1507 struct blockvector
*bv
;
1510 /* We only wack things if the symbol-reload switch is set. */
1511 if (!symbol_reloading
)
1514 /* Some symbol formats have trouble providing file names... */
1515 if (name
== 0 || *name
== '\0')
1518 /* Look for a psymtab with the specified name. */
1521 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1522 if (STREQ (name
, ps
->filename
)) {
1523 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
1524 goto again2
; /* Must restart, chain has been munged */
1528 /* Look for a symtab with the specified name. */
1530 for (s
= symtab_list
; s
; s
= s
->next
)
1532 if (STREQ (name
, s
->filename
))
1539 if (s
== symtab_list
)
1540 symtab_list
= s
->next
;
1542 prev
->next
= s
->next
;
1544 /* For now, queue a delete for all breakpoints, displays, etc., whether
1545 or not they depend on the symtab being freed. This should be
1546 changed so that only those data structures affected are deleted. */
1548 /* But don't delete anything if the symtab is empty.
1549 This test is necessary due to a bug in "dbxread.c" that
1550 causes empty symtabs to be created for N_SO symbols that
1551 contain the pathname of the object file. (This problem
1552 has been fixed in GDB 3.9x). */
1554 bv
= BLOCKVECTOR (s
);
1555 if (BLOCKVECTOR_NBLOCKS (bv
) > 2
1556 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
1557 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
1559 complain (&oldsyms_complaint
, name
);
1561 clear_symtab_users_queued
++;
1562 make_cleanup (clear_symtab_users_once
, 0);
1565 complain (&empty_symtab_complaint
, name
);
1572 /* It is still possible that some breakpoints will be affected
1573 even though no symtab was found, since the file might have
1574 been compiled without debugging, and hence not be associated
1575 with a symtab. In order to handle this correctly, we would need
1576 to keep a list of text address ranges for undebuggable files.
1577 For now, we do nothing, since this is a fairly obscure case. */
1581 /* FIXME, what about the minimal symbol table? */
1588 /* Allocate and partially fill a partial symtab. It will be
1589 completely filled at the end of the symbol list.
1591 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1592 is the address relative to which its symbols are (incremental) or 0
1596 struct partial_symtab
*
1597 start_psymtab_common (objfile
, section_offsets
,
1598 filename
, textlow
, global_syms
, static_syms
)
1599 struct objfile
*objfile
;
1600 struct section_offsets
*section_offsets
;
1603 struct partial_symbol
*global_syms
;
1604 struct partial_symbol
*static_syms
;
1606 struct partial_symtab
*psymtab
;
1608 psymtab
= allocate_psymtab (filename
, objfile
);
1609 psymtab
-> section_offsets
= section_offsets
;
1610 psymtab
-> textlow
= textlow
;
1611 psymtab
-> texthigh
= psymtab
-> textlow
; /* default */
1612 psymtab
-> globals_offset
= global_syms
- objfile
-> global_psymbols
.list
;
1613 psymtab
-> statics_offset
= static_syms
- objfile
-> static_psymbols
.list
;
1617 /* Debugging versions of functions that are usually inline macros
1620 #if !INLINE_ADD_PSYMBOL
1622 /* Add a symbol with a long value to a psymtab.
1623 Since one arg is a struct, we pass in a ptr and deref it (sigh). */
1626 add_psymbol_to_list (name
, namelength
, namespace, class, list
, val
, language
,
1630 namespace_enum
namespace;
1631 enum address_class
class;
1632 struct psymbol_allocation_list
*list
;
1634 enum language language
;
1635 struct objfile
*objfile
;
1637 register struct partial_symbol
*psym
;
1638 register char *demangled_name
;
1640 if (list
->next
>= list
->list
+ list
->size
)
1642 extend_psymbol_list (list
,objfile
);
1644 psym
= list
->next
++;
1646 SYMBOL_NAME (psym
) =
1647 (char *) obstack_alloc (&objfile
->psymbol_obstack
, namelength
+ 1);
1648 memcpy (SYMBOL_NAME (psym
), name
, namelength
);
1649 SYMBOL_NAME (psym
)[namelength
] = '\0';
1650 SYMBOL_VALUE (psym
) = val
;
1651 SYMBOL_SECTION (psym
) = 0;
1652 SYMBOL_LANGUAGE (psym
) = language
;
1653 PSYMBOL_NAMESPACE (psym
) = namespace;
1654 PSYMBOL_CLASS (psym
) = class;
1655 SYMBOL_INIT_LANGUAGE_SPECIFIC (psym
, language
);
1656 OBJSTAT (objfile
, psyms
++);
1659 /* Add a symbol with a CORE_ADDR value to a psymtab. */
1662 add_psymbol_addr_to_list (name
, namelength
, namespace, class, list
, val
,
1666 namespace_enum
namespace;
1667 enum address_class
class;
1668 struct psymbol_allocation_list
*list
;
1670 enum language language
;
1671 struct objfile
*objfile
;
1673 register struct partial_symbol
*psym
;
1674 register char *demangled_name
;
1676 if (list
->next
>= list
->list
+ list
->size
)
1678 extend_psymbol_list (list
,objfile
);
1680 psym
= list
->next
++;
1682 SYMBOL_NAME (psym
) =
1683 (char *) obstack_alloc (&objfile
->psymbol_obstack
, namelength
+ 1);
1684 memcpy (SYMBOL_NAME (psym
), name
, namelength
);
1685 SYMBOL_NAME (psym
)[namelength
] = '\0';
1686 SYMBOL_VALUE_ADDRESS (psym
) = val
;
1687 SYMBOL_SECTION (psym
) = 0;
1688 SYMBOL_LANGUAGE (psym
) = language
;
1689 PSYMBOL_NAMESPACE (psym
) = namespace;
1690 PSYMBOL_CLASS (psym
) = class;
1691 SYMBOL_INIT_LANGUAGE_SPECIFIC (psym
, language
);
1692 OBJSTAT (objfile
, psyms
++);
1695 #endif /* !INLINE_ADD_PSYMBOL */
1697 /* Initialize storage for partial symbols. */
1700 init_psymbol_list (objfile
, total_symbols
)
1701 struct objfile
*objfile
;
1704 /* Free any previously allocated psymbol lists. */
1706 if (objfile
-> global_psymbols
.list
)
1708 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
1710 if (objfile
-> static_psymbols
.list
)
1712 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
1715 /* Current best guess is that approximately a twentieth
1716 of the total symbols (in a debugging file) are global or static
1719 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
1720 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
1721 objfile
-> global_psymbols
.next
=
1722 objfile
-> global_psymbols
.list
= (struct partial_symbol
*)
1723 xmmalloc (objfile
-> md
, objfile
-> global_psymbols
.size
1724 * sizeof (struct partial_symbol
));
1725 objfile
-> static_psymbols
.next
=
1726 objfile
-> static_psymbols
.list
= (struct partial_symbol
*)
1727 xmmalloc (objfile
-> md
, objfile
-> static_psymbols
.size
1728 * sizeof (struct partial_symbol
));
1732 _initialize_symfile ()
1734 struct cmd_list_element
*c
;
1736 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
,
1737 "Load symbol table from executable file FILE.\n\
1738 The `file' command can also load symbol tables, as well as setting the file\n\
1739 to execute.", &cmdlist
);
1740 c
->completer
= filename_completer
;
1742 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
,
1743 "Usage: add-symbol-file FILE ADDR\n\
1744 Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
1745 ADDR is the starting address of the file's text.",
1747 c
->completer
= filename_completer
;
1749 c
= add_cmd ("add-shared-symbol-files", class_files
,
1750 add_shared_symbol_files_command
,
1751 "Load the symbols from shared objects in the dynamic linker's link map.",
1753 c
= add_alias_cmd ("assf", "add-shared-symbol-files", class_files
, 1,
1756 c
= add_cmd ("load", class_files
, load_command
,
1757 "Dynamically load FILE into the running program, and record its symbols\n\
1758 for access from GDB.", &cmdlist
);
1759 c
->completer
= filename_completer
;
1762 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
1763 (char *)&symbol_reloading
,
1764 "Set dynamic symbol table reloading multiple times in one run.",