1 /* Generic symbol file reading for the GNU debugger, GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 #include "breakpoint.h"
34 #include "complaints.h"
36 #include "inferior.h" /* for write_pc */
37 #include "gdb-stabs.h"
41 #include <sys/types.h>
43 #include "gdb_string.h"
55 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
56 void (*pre_add_symbol_hook
) PARAMS ((char *));
57 void (*post_add_symbol_hook
) PARAMS ((void));
59 /* Global variables owned by this file */
60 int readnow_symbol_files
; /* Read full symbols immediately */
62 struct complaint oldsyms_complaint
= {
63 "Replacing old symbols for `%s'", 0, 0
66 struct complaint empty_symtab_complaint
= {
67 "Empty symbol table found for `%s'", 0, 0
70 /* External variables and functions referenced. */
72 extern int info_verbose
;
74 extern void report_transfer_performance
PARAMS ((unsigned long,
77 /* Functions this file defines */
80 static int simple_read_overlay_region_table
PARAMS ((void));
81 static void simple_free_overlay_region_table
PARAMS ((void));
84 static void set_initial_language
PARAMS ((void));
86 static void load_command
PARAMS ((char *, int));
88 static void add_symbol_file_command
PARAMS ((char *, int));
90 static void add_shared_symbol_files_command
PARAMS ((char *, int));
92 static void cashier_psymtab
PARAMS ((struct partial_symtab
*));
94 static int compare_psymbols
PARAMS ((const void *, const void *));
96 static int compare_symbols
PARAMS ((const void *, const void *));
98 static bfd
*symfile_bfd_open
PARAMS ((char *));
100 static void find_sym_fns
PARAMS ((struct objfile
*));
102 static void decrement_reading_symtab
PARAMS ((void *));
104 /* List of all available sym_fns. On gdb startup, each object file reader
105 calls add_symtab_fns() to register information on each format it is
108 static struct sym_fns
*symtab_fns
= NULL
;
110 /* Flag for whether user will be reloading symbols multiple times.
111 Defaults to ON for VxWorks, otherwise OFF. */
113 #ifdef SYMBOL_RELOADING_DEFAULT
114 int symbol_reloading
= SYMBOL_RELOADING_DEFAULT
;
116 int symbol_reloading
= 0;
119 /* If true, then shared library symbols will be added automatically
120 when the inferior is created, new libraries are loaded, or when
121 attaching to the inferior. This is almost always what users
122 will want to have happen; but for very large programs, the startup
123 time will be excessive, and so if this is a problem, the user can
124 clear this flag and then add the shared library symbols as needed.
125 Note that there is a potential for confusion, since if the shared
126 library symbols are not loaded, commands like "info fun" will *not*
127 report all the functions that are actually present. */
129 int auto_solib_add
= 1;
132 /* Since this function is called from within qsort, in an ANSI environment
133 it must conform to the prototype for qsort, which specifies that the
134 comparison function takes two "void *" pointers. */
137 compare_symbols (s1p
, s2p
)
141 register struct symbol
**s1
, **s2
;
143 s1
= (struct symbol
**) s1p
;
144 s2
= (struct symbol
**) s2p
;
146 return (STRCMP (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
)));
153 compare_psymbols -- compare two partial symbols by name
157 Given pointers to pointers to two partial symbol table entries,
158 compare them by name and return -N, 0, or +N (ala strcmp).
159 Typically used by sorting routines like qsort().
163 Does direct compare of first two characters before punting
164 and passing to strcmp for longer compares. Note that the
165 original version had a bug whereby two null strings or two
166 identically named one character strings would return the
167 comparison of memory following the null byte.
172 compare_psymbols (s1p
, s2p
)
176 register char *st1
= SYMBOL_NAME (*(struct partial_symbol
**) s1p
);
177 register char *st2
= SYMBOL_NAME (*(struct partial_symbol
**) s2p
);
179 if ((st1
[0] - st2
[0]) || !st1
[0])
181 return (st1
[0] - st2
[0]);
183 else if ((st1
[1] - st2
[1]) || !st1
[1])
185 return (st1
[1] - st2
[1]);
189 return (STRCMP (st1
+ 2, st2
+ 2));
194 sort_pst_symbols (pst
)
195 struct partial_symtab
*pst
;
197 /* Sort the global list; don't sort the static list */
199 qsort (pst
-> objfile
-> global_psymbols
.list
+ pst
-> globals_offset
,
200 pst
-> n_global_syms
, sizeof (struct partial_symbol
*),
204 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
208 register struct block
*b
;
210 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
211 sizeof (struct symbol
*), compare_symbols
);
214 /* Call sort_symtab_syms to sort alphabetically
215 the symbols of each block of one symtab. */
219 register struct symtab
*s
;
221 register struct blockvector
*bv
;
224 register struct block
*b
;
228 bv
= BLOCKVECTOR (s
);
229 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
230 for (i
= 0; i
< nbl
; i
++)
232 b
= BLOCKVECTOR_BLOCK (bv
, i
);
233 if (BLOCK_SHOULD_SORT (b
))
238 /* Make a null terminated copy of the string at PTR with SIZE characters in
239 the obstack pointed to by OBSTACKP . Returns the address of the copy.
240 Note that the string at PTR does not have to be null terminated, I.E. it
241 may be part of a larger string and we are only saving a substring. */
244 obsavestring (ptr
, size
, obstackp
)
247 struct obstack
*obstackp
;
249 register char *p
= (char *) obstack_alloc (obstackp
, size
+ 1);
250 /* Open-coded memcpy--saves function call time. These strings are usually
251 short. FIXME: Is this really still true with a compiler that can
254 register char *p1
= ptr
;
255 register char *p2
= p
;
256 char *end
= ptr
+ size
;
264 /* Concatenate strings S1, S2 and S3; return the new string. Space is found
265 in the obstack pointed to by OBSTACKP. */
268 obconcat (obstackp
, s1
, s2
, s3
)
269 struct obstack
*obstackp
;
270 const char *s1
, *s2
, *s3
;
272 register int len
= strlen (s1
) + strlen (s2
) + strlen (s3
) + 1;
273 register char *val
= (char *) obstack_alloc (obstackp
, len
);
280 /* True if we are nested inside psymtab_to_symtab. */
282 int currently_reading_symtab
= 0;
285 decrement_reading_symtab (dummy
)
288 currently_reading_symtab
--;
291 /* Get the symbol table that corresponds to a partial_symtab.
292 This is fast after the first time you do it. In fact, there
293 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
297 psymtab_to_symtab (pst
)
298 register struct partial_symtab
*pst
;
300 /* If it's been looked up before, return it. */
304 /* If it has not yet been read in, read it. */
307 struct cleanup
*back_to
= make_cleanup (decrement_reading_symtab
, NULL
);
308 currently_reading_symtab
++;
309 (*pst
->read_symtab
) (pst
);
310 do_cleanups (back_to
);
316 /* Initialize entry point information for this objfile. */
319 init_entry_point_info (objfile
)
320 struct objfile
*objfile
;
322 /* Save startup file's range of PC addresses to help blockframe.c
323 decide where the bottom of the stack is. */
325 if (bfd_get_file_flags (objfile
-> obfd
) & EXEC_P
)
327 /* Executable file -- record its entry point so we'll recognize
328 the startup file because it contains the entry point. */
329 objfile
-> ei
.entry_point
= bfd_get_start_address (objfile
-> obfd
);
333 /* Examination of non-executable.o files. Short-circuit this stuff. */
334 objfile
-> ei
.entry_point
= INVALID_ENTRY_POINT
;
336 objfile
-> ei
.entry_file_lowpc
= INVALID_ENTRY_LOWPC
;
337 objfile
-> ei
.entry_file_highpc
= INVALID_ENTRY_HIGHPC
;
338 objfile
-> ei
.entry_func_lowpc
= INVALID_ENTRY_LOWPC
;
339 objfile
-> ei
.entry_func_highpc
= INVALID_ENTRY_HIGHPC
;
340 objfile
-> ei
.main_func_lowpc
= INVALID_ENTRY_LOWPC
;
341 objfile
-> ei
.main_func_highpc
= INVALID_ENTRY_HIGHPC
;
344 /* Get current entry point address. */
347 entry_point_address()
349 return symfile_objfile
? symfile_objfile
->ei
.entry_point
: 0;
352 /* Remember the lowest-addressed loadable section we've seen.
353 This function is called via bfd_map_over_sections.
355 In case of equal vmas, the section with the largest size becomes the
356 lowest-addressed loadable section.
358 If the vmas and sizes are equal, the last section is considered the
359 lowest-addressed loadable section. */
362 find_lowest_section (abfd
, sect
, obj
)
367 asection
**lowest
= (asection
**)obj
;
369 if (0 == (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
))
372 *lowest
= sect
; /* First loadable section */
373 else if (bfd_section_vma (abfd
, *lowest
) > bfd_section_vma (abfd
, sect
))
374 *lowest
= sect
; /* A lower loadable section */
375 else if (bfd_section_vma (abfd
, *lowest
) == bfd_section_vma (abfd
, sect
)
376 && (bfd_section_size (abfd
, (*lowest
))
377 <= bfd_section_size (abfd
, sect
)))
381 /* Parse the user's idea of an offset for dynamic linking, into our idea
382 of how to represent it for fast symbol reading. This is the default
383 version of the sym_fns.sym_offsets function for symbol readers that
384 don't need to do anything special. It allocates a section_offsets table
385 for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */
387 struct section_offsets
*
388 default_symfile_offsets (objfile
, addr
)
389 struct objfile
*objfile
;
392 struct section_offsets
*section_offsets
;
395 objfile
->num_sections
= SECT_OFF_MAX
;
396 section_offsets
= (struct section_offsets
*)
397 obstack_alloc (&objfile
-> psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
399 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
400 ANOFFSET (section_offsets
, i
) = addr
;
402 return section_offsets
;
406 /* Process a symbol file, as either the main file or as a dynamically
409 NAME is the file name (which will be tilde-expanded and made
410 absolute herein) (but we don't free or modify NAME itself).
411 FROM_TTY says how verbose to be. MAINLINE specifies whether this
412 is the main symbol file, or whether it's an extra symbol file such
413 as dynamically loaded code. If !mainline, ADDR is the address
414 where the text segment was loaded. If VERBO, the caller has printed
415 a verbose message about the symbol reading (and complaints can be
416 more terse about it). */
419 syms_from_objfile (objfile
, addr
, mainline
, verbo
)
420 struct objfile
*objfile
;
425 struct section_offsets
*section_offsets
;
426 asection
*lowest_sect
;
427 struct cleanup
*old_chain
;
429 init_entry_point_info (objfile
);
430 find_sym_fns (objfile
);
432 /* Make sure that partially constructed symbol tables will be cleaned up
433 if an error occurs during symbol reading. */
434 old_chain
= make_cleanup (free_objfile
, objfile
);
438 /* We will modify the main symbol table, make sure that all its users
439 will be cleaned up if an error occurs during symbol reading. */
440 make_cleanup (clear_symtab_users
, 0);
442 /* Since no error yet, throw away the old symbol table. */
444 if (symfile_objfile
!= NULL
)
446 free_objfile (symfile_objfile
);
447 symfile_objfile
= NULL
;
450 /* Currently we keep symbols from the add-symbol-file command.
451 If the user wants to get rid of them, they should do "symbol-file"
452 without arguments first. Not sure this is the best behavior
455 (*objfile
-> sf
-> sym_new_init
) (objfile
);
458 /* Convert addr into an offset rather than an absolute address.
459 We find the lowest address of a loaded segment in the objfile,
460 and assume that <addr> is where that got loaded. Due to historical
461 precedent, we warn if that doesn't happen to be a text segment. */
465 addr
= 0; /* No offset from objfile addresses. */
469 lowest_sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
470 if (lowest_sect
== NULL
)
471 bfd_map_over_sections (objfile
->obfd
, find_lowest_section
,
474 if (lowest_sect
== NULL
)
475 warning ("no loadable sections found in added symbol-file %s",
477 else if ((bfd_get_section_flags (objfile
->obfd
, lowest_sect
) & SEC_CODE
)
479 /* FIXME-32x64--assumes bfd_vma fits in long. */
480 warning ("Lowest section in %s is %s at 0x%lx",
482 bfd_section_name (objfile
->obfd
, lowest_sect
),
483 (unsigned long) bfd_section_vma (objfile
->obfd
, lowest_sect
));
486 addr
-= bfd_section_vma (objfile
->obfd
, lowest_sect
);
489 /* Initialize symbol reading routines for this objfile, allow complaints to
490 appear for this new file, and record how verbose to be, then do the
491 initial symbol reading for this file. */
493 (*objfile
-> sf
-> sym_init
) (objfile
);
494 clear_complaints (1, verbo
);
496 section_offsets
= (*objfile
-> sf
-> sym_offsets
) (objfile
, addr
);
497 objfile
->section_offsets
= section_offsets
;
499 #ifndef IBM6000_TARGET
500 /* This is a SVR4/SunOS specific hack, I think. In any event, it
501 screws RS/6000. sym_offsets should be doing this sort of thing,
502 because it knows the mapping between bfd sections and
504 /* This is a hack. As far as I can tell, section offsets are not
505 target dependent. They are all set to addr with a couple of
506 exceptions. The exceptions are sysvr4 shared libraries, whose
507 offsets are kept in solib structures anyway and rs6000 xcoff
508 which handles shared libraries in a completely unique way.
510 Section offsets are built similarly, except that they are built
511 by adding addr in all cases because there is no clear mapping
512 from section_offsets into actual sections. Note that solib.c
513 has a different algorythm for finding section offsets.
515 These should probably all be collapsed into some target
516 independent form of shared library support. FIXME. */
520 struct obj_section
*s
;
522 for (s
= objfile
->sections
; s
< objfile
->sections_end
; ++s
)
524 s
->addr
-= s
->offset
;
526 s
->endaddr
-= s
->offset
;
531 #endif /* not IBM6000_TARGET */
533 (*objfile
-> sf
-> sym_read
) (objfile
, section_offsets
, mainline
);
535 if (!have_partial_symbols () && !have_full_symbols ())
538 printf_filtered ("(no debugging symbols found)...");
542 /* Don't allow char * to have a typename (else would get caddr_t).
543 Ditto void *. FIXME: Check whether this is now done by all the
544 symbol readers themselves (many of them now do), and if so remove
547 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
548 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
550 /* Mark the objfile has having had initial symbol read attempted. Note
551 that this does not mean we found any symbols... */
553 objfile
-> flags
|= OBJF_SYMS
;
555 /* Discard cleanups as symbol reading was successful. */
557 discard_cleanups (old_chain
);
559 /* Call this after reading in a new symbol table to give target dependant code
560 a crack at the new symbols. For instance, this could be used to update the
561 values of target-specific symbols GDB needs to keep track of (such as
562 _sigtramp, or whatever). */
564 TARGET_SYMFILE_POSTREAD (objfile
);
567 /* Perform required actions after either reading in the initial
568 symbols for a new objfile, or mapping in the symbols from a reusable
572 new_symfile_objfile (objfile
, mainline
, verbo
)
573 struct objfile
*objfile
;
578 /* If this is the main symbol file we have to clean up all users of the
579 old main symbol file. Otherwise it is sufficient to fixup all the
580 breakpoints that may have been redefined by this symbol file. */
583 /* OK, make it the "real" symbol file. */
584 symfile_objfile
= objfile
;
586 clear_symtab_users ();
590 breakpoint_re_set ();
593 /* We're done reading the symbol file; finish off complaints. */
594 clear_complaints (0, verbo
);
597 /* Process a symbol file, as either the main file or as a dynamically
600 NAME is the file name (which will be tilde-expanded and made
601 absolute herein) (but we don't free or modify NAME itself).
602 FROM_TTY says how verbose to be. MAINLINE specifies whether this
603 is the main symbol file, or whether it's an extra symbol file such
604 as dynamically loaded code. If !mainline, ADDR is the address
605 where the text segment was loaded.
607 Upon success, returns a pointer to the objfile that was added.
608 Upon failure, jumps back to command level (never returns). */
611 symbol_file_add (name
, from_tty
, addr
, mainline
, mapped
, readnow
)
619 struct objfile
*objfile
;
620 struct partial_symtab
*psymtab
;
623 /* Open a bfd for the file, and give user a chance to burp if we'd be
624 interactively wiping out any existing symbols. */
626 abfd
= symfile_bfd_open (name
);
628 if ((have_full_symbols () || have_partial_symbols ())
631 && !query ("Load new symbol table from \"%s\"? ", name
))
632 error ("Not confirmed.");
634 objfile
= allocate_objfile (abfd
, mapped
);
636 /* If the objfile uses a mapped symbol file, and we have a psymtab for
637 it, then skip reading any symbols at this time. */
639 if ((objfile
-> flags
& OBJF_MAPPED
) && (objfile
-> flags
& OBJF_SYMS
))
641 /* We mapped in an existing symbol table file that already has had
642 initial symbol reading performed, so we can skip that part. Notify
643 the user that instead of reading the symbols, they have been mapped.
645 if (from_tty
|| info_verbose
)
647 printf_filtered ("Mapped symbols for %s...", name
);
649 gdb_flush (gdb_stdout
);
651 init_entry_point_info (objfile
);
652 find_sym_fns (objfile
);
656 /* We either created a new mapped symbol table, mapped an existing
657 symbol table file which has not had initial symbol reading
658 performed, or need to read an unmapped symbol table. */
659 if (from_tty
|| info_verbose
)
661 if (pre_add_symbol_hook
)
662 pre_add_symbol_hook (name
);
665 printf_filtered ("Reading symbols from %s...", name
);
667 gdb_flush (gdb_stdout
);
670 syms_from_objfile (objfile
, addr
, mainline
, from_tty
);
673 /* We now have at least a partial symbol table. Check to see if the
674 user requested that all symbols be read on initial access via either
675 the gdb startup command line or on a per symbol file basis. Expand
676 all partial symbol tables for this objfile if so. */
678 if (readnow
|| readnow_symbol_files
)
680 if (from_tty
|| info_verbose
)
682 printf_filtered ("expanding to full symbols...");
684 gdb_flush (gdb_stdout
);
687 for (psymtab
= objfile
-> psymtabs
;
689 psymtab
= psymtab
-> next
)
691 psymtab_to_symtab (psymtab
);
695 if (from_tty
|| info_verbose
)
697 if (post_add_symbol_hook
)
698 post_add_symbol_hook ();
701 printf_filtered ("done.\n");
702 gdb_flush (gdb_stdout
);
706 new_symfile_objfile (objfile
, mainline
, from_tty
);
708 target_new_objfile (objfile
);
713 /* This is the symbol-file command. Read the file, analyze its
714 symbols, and add a struct symtab to a symtab list. The syntax of
715 the command is rather bizarre--(1) buildargv implements various
716 quoting conventions which are undocumented and have little or
717 nothing in common with the way things are quoted (or not quoted)
718 elsewhere in GDB, (2) options are used, which are not generally
719 used in GDB (perhaps "set mapped on", "set readnow on" would be
720 better), (3) the order of options matters, which is contrary to GNU
721 conventions (because it is confusing and inconvenient). */
724 symbol_file_command (args
, from_tty
)
730 CORE_ADDR text_relocation
= 0; /* text_relocation */
731 struct cleanup
*cleanups
;
739 if ((have_full_symbols () || have_partial_symbols ())
741 && !query ("Discard symbol table from `%s'? ",
742 symfile_objfile
-> name
))
743 error ("Not confirmed.");
744 free_all_objfiles ();
745 symfile_objfile
= NULL
;
748 printf_unfiltered ("No symbol file now.\n");
753 if ((argv
= buildargv (args
)) == NULL
)
757 cleanups
= make_cleanup (freeargv
, (char *) argv
);
758 while (*argv
!= NULL
)
760 if (STREQ (*argv
, "-mapped"))
764 else if (STREQ (*argv
, "-readnow"))
768 else if (**argv
== '-')
770 error ("unknown option `%s'", *argv
);
778 /* this is for rombug remote only, to get the text relocation by
779 using link command */
780 p
= strrchr(name
, '/');
784 target_link(p
, &text_relocation
);
786 if (text_relocation
== (CORE_ADDR
)0)
788 else if (text_relocation
== (CORE_ADDR
)-1)
789 symbol_file_add (name
, from_tty
, (CORE_ADDR
)0, 1, mapped
,
792 symbol_file_add (name
, from_tty
, (CORE_ADDR
)text_relocation
,
795 /* Getting new symbols may change our opinion about what is
797 reinit_frame_cache ();
799 set_initial_language ();
806 error ("no symbol file name was specified");
808 do_cleanups (cleanups
);
812 /* Set the initial language.
814 A better solution would be to record the language in the psymtab when reading
815 partial symbols, and then use it (if known) to set the language. This would
816 be a win for formats that encode the language in an easily discoverable place,
817 such as DWARF. For stabs, we can jump through hoops looking for specially
818 named symbols or try to intuit the language from the specific type of stabs
819 we find, but we can't do that until later when we read in full symbols.
823 set_initial_language ()
825 struct partial_symtab
*pst
;
826 enum language lang
= language_unknown
;
828 pst
= find_main_psymtab ();
831 if (pst
-> filename
!= NULL
)
833 lang
= deduce_language_from_filename (pst
-> filename
);
835 if (lang
== language_unknown
)
837 /* Make C the default language */
841 expected_language
= current_language
; /* Don't warn the user */
845 /* Open file specified by NAME and hand it off to BFD for preliminary
846 analysis. Result is a newly initialized bfd *, which includes a newly
847 malloc'd` copy of NAME (tilde-expanded and made absolute).
848 In case of trouble, error() is called. */
851 symfile_bfd_open (name
)
858 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy */
860 /* Look down path for it, allocate 2nd new malloc'd copy. */
861 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
| O_BINARY
, 0, &absolute_name
);
862 #if defined(__GO32__) || defined(_WIN32)
865 char *exename
= alloca (strlen (name
) + 5);
866 strcat (strcpy (exename
, name
), ".exe");
867 desc
= openp (getenv ("PATH"), 1, exename
, O_RDONLY
| O_BINARY
,
873 make_cleanup (free
, name
);
874 perror_with_name (name
);
876 free (name
); /* Free 1st new malloc'd copy */
877 name
= absolute_name
; /* Keep 2nd malloc'd copy in bfd */
878 /* It'll be freed in free_objfile(). */
880 sym_bfd
= bfd_fdopenr (name
, gnutarget
, desc
);
884 make_cleanup (free
, name
);
885 error ("\"%s\": can't open to read symbols: %s.", name
,
886 bfd_errmsg (bfd_get_error ()));
888 sym_bfd
->cacheable
= true;
890 if (!bfd_check_format (sym_bfd
, bfd_object
))
892 /* FIXME: should be checking for errors from bfd_close (for one thing,
893 on error it does not free all the storage associated with the
895 bfd_close (sym_bfd
); /* This also closes desc */
896 make_cleanup (free
, name
);
897 error ("\"%s\": can't read symbols: %s.", name
,
898 bfd_errmsg (bfd_get_error ()));
904 /* Link a new symtab_fns into the global symtab_fns list. Called on gdb
905 startup by the _initialize routine in each object file format reader,
906 to register information about each format the the reader is prepared
913 sf
->next
= symtab_fns
;
918 /* Initialize to read symbols from the symbol file sym_bfd. It either
919 returns or calls error(). The result is an initialized struct sym_fns
920 in the objfile structure, that contains cached information about the
924 find_sym_fns (objfile
)
925 struct objfile
*objfile
;
928 enum bfd_flavour our_flavour
= bfd_get_flavour (objfile
-> obfd
);
929 char *our_target
= bfd_get_target (objfile
-> obfd
);
931 /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */
932 if (STREQ (our_target
, "aixcoff-rs6000") ||
933 STREQ (our_target
, "xcoff-powermac"))
934 our_flavour
= (enum bfd_flavour
)-1;
936 /* Special kludge for apollo. See dstread.c. */
937 if (STREQN (our_target
, "apollo", 6))
938 our_flavour
= (enum bfd_flavour
)-2;
940 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
-> next
)
942 if (our_flavour
== sf
-> sym_flavour
)
948 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
949 bfd_get_target (objfile
-> obfd
));
952 /* This function runs the load command of our current target. */
955 load_command (arg
, from_tty
)
960 arg
= get_exec_file (1);
961 target_load (arg
, from_tty
);
964 /* This version of "load" should be usable for any target. Currently
965 it is just used for remote targets, not inftarg.c or core files,
966 on the theory that only in that case is it useful.
968 Avoiding xmodem and the like seems like a win (a) because we don't have
969 to worry about finding it, and (b) On VMS, fork() is very slow and so
970 we don't want to run a subprocess. On the other hand, I'm not sure how
971 performance compares. */
972 #define GENERIC_LOAD_CHUNK 256
973 #define VALIDATE_DOWNLOAD 0
975 generic_load (filename
, from_tty
)
979 struct cleanup
*old_cleanups
;
982 time_t start_time
, end_time
; /* Start and end times of download */
983 unsigned long data_count
= 0; /* Number of bytes transferred to memory */
985 unsigned long load_offset
= 0; /* offset to add to vma for each section */
986 char buf
[GENERIC_LOAD_CHUNK
+8];
987 #if VALIDATE_DOWNLOAD
988 char verify_buffer
[GENERIC_LOAD_CHUNK
+8] ;
991 /* enable user to specify address for downloading as 2nd arg to load */
992 n
= sscanf(filename
, "%s 0x%lx", buf
, &load_offset
);
998 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
999 if (loadfile_bfd
== NULL
)
1001 perror_with_name (filename
);
1004 /* FIXME: should be checking for errors from bfd_close (for one thing,
1005 on error it does not free all the storage associated with the
1007 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
1009 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
1011 error ("\"%s\" is not an object file: %s", filename
,
1012 bfd_errmsg (bfd_get_error ()));
1015 start_time
= time (NULL
);
1017 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
1019 if (s
->flags
& SEC_LOAD
)
1023 size
= bfd_get_section_size_before_reloc (s
);
1027 struct cleanup
*old_chain
;
1029 unsigned long l
= size
;
1035 l
= l
> GENERIC_LOAD_CHUNK
? GENERIC_LOAD_CHUNK
: l
;
1037 buffer
= xmalloc (size
);
1038 old_chain
= make_cleanup (free
, buffer
);
1043 /* Is this really necessary? I guess it gives the user something
1044 to look at during a long download. */
1045 printf_filtered ("Loading section %s, size 0x%lx lma ",
1046 bfd_get_section_name (loadfile_bfd
, s
),
1047 (unsigned long) size
);
1048 print_address_numeric (lma
, 1, gdb_stdout
);
1049 printf_filtered ("\n");
1051 bfd_get_section_contents (loadfile_bfd
, s
, buffer
, 0, size
);
1053 sect
= (char *) bfd_get_section_name (loadfile_bfd
, s
);
1057 len
= (size
- sent
) < l
? (size
- sent
) : l
;
1059 err
= target_write_memory (lma
, buffer
, len
);
1060 if (ui_load_progress_hook
)
1061 if (ui_load_progress_hook (sect
, sent
))
1062 error ("Canceled the download");
1063 #if VALIDATE_DOWNLOAD
1064 /* Broken memories and broken monitors manifest themselves
1065 here when bring new computers to life.
1066 This doubles already slow downloads.
1070 target_read_memory(lma
,verify_buffer
,len
) ;
1071 if (0 != bcmp(buffer
,verify_buffer
,len
))
1072 error("Download verify failed at %08x",
1073 (unsigned long)lma
) ;
1081 while (err
== 0 && sent
< size
);
1084 error ("Memory access error while loading section %s.",
1085 bfd_get_section_name (loadfile_bfd
, s
));
1087 do_cleanups (old_chain
);
1092 end_time
= time (NULL
);
1094 unsigned long entry
;
1095 entry
= bfd_get_start_address(loadfile_bfd
) ;
1096 printf_filtered ("Start address 0x%lx , load size %d\n", entry
,data_count
);
1097 /* We were doing this in remote-mips.c, I suspect it is right
1098 for other targets too. */
1102 /* FIXME: are we supposed to call symbol_file_add or not? According to
1103 a comment from remote-mips.c (where a call to symbol_file_add was
1104 commented out), making the call confuses GDB if more than one file is
1105 loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c
1108 report_transfer_performance (data_count
, start_time
, end_time
);
1110 do_cleanups (old_cleanups
);
1113 /* Report how fast the transfer went. */
1116 report_transfer_performance (data_count
, start_time
, end_time
)
1117 unsigned long data_count
;
1118 time_t start_time
, end_time
;
1120 printf_filtered ("Transfer rate: ");
1121 if (end_time
!= start_time
)
1122 printf_filtered ("%d bits/sec",
1123 (data_count
* 8) / (end_time
- start_time
));
1125 printf_filtered ("%d bits in <1 sec", (data_count
* 8));
1126 printf_filtered (".\n");
1129 /* This function allows the addition of incrementally linked object files.
1130 It does not modify any state in the target, only in the debugger. */
1134 add_symbol_file_command (args
, from_tty
)
1139 CORE_ADDR text_addr
;
1148 error ("add-symbol-file takes a file name and an address");
1151 /* Make a copy of the string that we can safely write into. */
1153 args
= strdup (args
);
1154 make_cleanup (free
, args
);
1156 /* Pick off any -option args and the file name. */
1158 while ((*args
!= '\000') && (name
== NULL
))
1160 while (isspace (*args
)) {args
++;}
1162 while ((*args
!= '\000') && !isspace (*args
)) {args
++;}
1163 if (*args
!= '\000')
1171 else if (STREQ (arg
, "-mapped"))
1175 else if (STREQ (arg
, "-readnow"))
1181 error ("unknown option `%s'", arg
);
1185 /* After picking off any options and the file name, args should be
1186 left pointing at the remainder of the command line, which should
1187 be the address expression to evaluate. */
1191 error ("add-symbol-file takes a file name");
1193 name
= tilde_expand (name
);
1194 make_cleanup (free
, name
);
1196 if (*args
!= '\000')
1198 text_addr
= parse_and_eval_address (args
);
1202 target_link(name
, &text_addr
);
1203 if (text_addr
== (CORE_ADDR
)-1)
1204 error("Don't know how to get text start location for this file");
1207 /* FIXME-32x64: Assumes text_addr fits in a long. */
1209 && (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
1210 name
, local_hex_string ((unsigned long)text_addr
))))
1211 error ("Not confirmed.");
1213 symbol_file_add (name
, from_tty
, text_addr
, 0, mapped
, readnow
);
1215 /* Getting new symbols may change our opinion about what is
1217 reinit_frame_cache ();
1221 add_shared_symbol_files_command (args
, from_tty
)
1225 #ifdef ADD_SHARED_SYMBOL_FILES
1226 ADD_SHARED_SYMBOL_FILES (args
, from_tty
);
1228 error ("This command is not available in this configuration of GDB.");
1232 /* Re-read symbols if a symbol-file has changed. */
1236 struct objfile
*objfile
;
1239 struct stat new_statbuf
;
1242 /* With the addition of shared libraries, this should be modified,
1243 the load time should be saved in the partial symbol tables, since
1244 different tables may come from different source files. FIXME.
1245 This routine should then walk down each partial symbol table
1246 and see if the symbol table that it originates from has been changed */
1248 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
) {
1249 if (objfile
->obfd
) {
1250 #ifdef IBM6000_TARGET
1251 /* If this object is from a shared library, then you should
1252 stat on the library name, not member name. */
1254 if (objfile
->obfd
->my_archive
)
1255 res
= stat (objfile
->obfd
->my_archive
->filename
, &new_statbuf
);
1258 res
= stat (objfile
->name
, &new_statbuf
);
1260 /* FIXME, should use print_sys_errmsg but it's not filtered. */
1261 printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
1265 new_modtime
= new_statbuf
.st_mtime
;
1266 if (new_modtime
!= objfile
->mtime
)
1268 struct cleanup
*old_cleanups
;
1269 struct section_offsets
*offsets
;
1271 int section_offsets_size
;
1272 char *obfd_filename
;
1274 printf_filtered ("`%s' has changed; re-reading symbols.\n",
1277 /* There are various functions like symbol_file_add,
1278 symfile_bfd_open, syms_from_objfile, etc., which might
1279 appear to do what we want. But they have various other
1280 effects which we *don't* want. So we just do stuff
1281 ourselves. We don't worry about mapped files (for one thing,
1282 any mapped file will be out of date). */
1284 /* If we get an error, blow away this objfile (not sure if
1285 that is the correct response for things like shared
1287 old_cleanups
= make_cleanup (free_objfile
, objfile
);
1288 /* We need to do this whenever any symbols go away. */
1289 make_cleanup (clear_symtab_users
, 0);
1291 /* Clean up any state BFD has sitting around. We don't need
1292 to close the descriptor but BFD lacks a way of closing the
1293 BFD without closing the descriptor. */
1294 obfd_filename
= bfd_get_filename (objfile
->obfd
);
1295 if (!bfd_close (objfile
->obfd
))
1296 error ("Can't close BFD for %s: %s", objfile
->name
,
1297 bfd_errmsg (bfd_get_error ()));
1298 objfile
->obfd
= bfd_openr (obfd_filename
, gnutarget
);
1299 if (objfile
->obfd
== NULL
)
1300 error ("Can't open %s to read symbols.", objfile
->name
);
1301 /* bfd_openr sets cacheable to true, which is what we want. */
1302 if (!bfd_check_format (objfile
->obfd
, bfd_object
))
1303 error ("Can't read symbols from %s: %s.", objfile
->name
,
1304 bfd_errmsg (bfd_get_error ()));
1306 /* Save the offsets, we will nuke them with the rest of the
1308 num_offsets
= objfile
->num_sections
;
1309 section_offsets_size
=
1310 sizeof (struct section_offsets
)
1311 + sizeof (objfile
->section_offsets
->offsets
) * num_offsets
;
1312 offsets
= (struct section_offsets
*) alloca (section_offsets_size
);
1313 memcpy (offsets
, objfile
->section_offsets
, section_offsets_size
);
1315 /* Nuke all the state that we will re-read. Much of the following
1316 code which sets things to NULL really is necessary to tell
1317 other parts of GDB that there is nothing currently there. */
1319 /* FIXME: Do we have to free a whole linked list, or is this
1321 if (objfile
->global_psymbols
.list
)
1322 mfree (objfile
->md
, objfile
->global_psymbols
.list
);
1323 memset (&objfile
-> global_psymbols
, 0,
1324 sizeof (objfile
-> global_psymbols
));
1325 if (objfile
->static_psymbols
.list
)
1326 mfree (objfile
->md
, objfile
->static_psymbols
.list
);
1327 memset (&objfile
-> static_psymbols
, 0,
1328 sizeof (objfile
-> static_psymbols
));
1330 /* Free the obstacks for non-reusable objfiles */
1331 obstack_free (&objfile
-> psymbol_cache
.cache
, 0);
1332 memset (&objfile
-> psymbol_cache
, 0,
1333 sizeof (objfile
-> psymbol_cache
));
1334 obstack_free (&objfile
-> psymbol_obstack
, 0);
1335 obstack_free (&objfile
-> symbol_obstack
, 0);
1336 obstack_free (&objfile
-> type_obstack
, 0);
1337 objfile
->sections
= NULL
;
1338 objfile
->symtabs
= NULL
;
1339 objfile
->psymtabs
= NULL
;
1340 objfile
->free_psymtabs
= NULL
;
1341 objfile
->msymbols
= NULL
;
1342 objfile
->minimal_symbol_count
= 0;
1343 objfile
->fundamental_types
= NULL
;
1344 if (objfile
-> sf
!= NULL
)
1346 (*objfile
-> sf
-> sym_finish
) (objfile
);
1349 /* We never make this a mapped file. */
1350 objfile
-> md
= NULL
;
1351 /* obstack_specify_allocation also initializes the obstack so
1353 obstack_specify_allocation (&objfile
-> psymbol_cache
.cache
, 0, 0,
1355 obstack_specify_allocation (&objfile
-> psymbol_obstack
, 0, 0,
1357 obstack_specify_allocation (&objfile
-> symbol_obstack
, 0, 0,
1359 obstack_specify_allocation (&objfile
-> type_obstack
, 0, 0,
1361 if (build_objfile_section_table (objfile
))
1363 error ("Can't find the file sections in `%s': %s",
1364 objfile
-> name
, bfd_errmsg (bfd_get_error ()));
1367 /* We use the same section offsets as from last time. I'm not
1368 sure whether that is always correct for shared libraries. */
1369 objfile
->section_offsets
= (struct section_offsets
*)
1370 obstack_alloc (&objfile
-> psymbol_obstack
, section_offsets_size
);
1371 memcpy (objfile
->section_offsets
, offsets
, section_offsets_size
);
1372 objfile
->num_sections
= num_offsets
;
1374 /* What the hell is sym_new_init for, anyway? The concept of
1375 distinguishing between the main file and additional files
1376 in this way seems rather dubious. */
1377 if (objfile
== symfile_objfile
)
1378 (*objfile
->sf
->sym_new_init
) (objfile
);
1380 (*objfile
->sf
->sym_init
) (objfile
);
1381 clear_complaints (1, 1);
1382 /* The "mainline" parameter is a hideous hack; I think leaving it
1383 zero is OK since dbxread.c also does what it needs to do if
1384 objfile->global_psymbols.size is 0. */
1385 (*objfile
->sf
->sym_read
) (objfile
, objfile
->section_offsets
, 0);
1386 if (!have_partial_symbols () && !have_full_symbols ())
1389 printf_filtered ("(no debugging symbols found)\n");
1392 objfile
-> flags
|= OBJF_SYMS
;
1394 /* We're done reading the symbol file; finish off complaints. */
1395 clear_complaints (0, 1);
1397 /* Getting new symbols may change our opinion about what is
1400 reinit_frame_cache ();
1402 /* Discard cleanups as symbol reading was successful. */
1403 discard_cleanups (old_cleanups
);
1405 /* If the mtime has changed between the time we set new_modtime
1406 and now, we *want* this to be out of date, so don't call stat
1408 objfile
->mtime
= new_modtime
;
1411 /* Call this after reading in a new symbol table to give target
1412 dependant code a crack at the new symbols. For instance, this
1413 could be used to update the values of target-specific symbols GDB
1414 needs to keep track of (such as _sigtramp, or whatever). */
1416 TARGET_SYMFILE_POSTREAD (objfile
);
1422 clear_symtab_users ();
1427 deduce_language_from_filename (filename
)
1434 else if (0 == (c
= strrchr (filename
, '.')))
1435 ; /* Get default. */
1436 else if (STREQ (c
, ".c"))
1438 else if (STREQ (c
, ".cc") || STREQ (c
, ".C") || STREQ (c
, ".cxx")
1439 || STREQ (c
, ".cpp") || STREQ (c
, ".cp") || STREQ (c
, ".c++"))
1440 return language_cplus
;
1441 /* start-sanitize-java */
1442 else if (STREQ (c
, ".java") || STREQ (c
, ".class"))
1443 return language_java
;
1444 /* end-sanitize-java */
1445 else if (STREQ (c
, ".ch") || STREQ (c
, ".c186") || STREQ (c
, ".c286"))
1446 return language_chill
;
1447 else if (STREQ (c
, ".f") || STREQ (c
, ".F"))
1448 return language_fortran
;
1449 else if (STREQ (c
, ".mod"))
1451 else if (STREQ (c
, ".s") || STREQ (c
, ".S"))
1452 return language_asm
;
1454 return language_unknown
; /* default */
1459 Allocate and partly initialize a new symbol table. Return a pointer
1460 to it. error() if no space.
1462 Caller must set these fields:
1468 possibly free_named_symtabs (symtab->filename);
1472 allocate_symtab (filename
, objfile
)
1474 struct objfile
*objfile
;
1476 register struct symtab
*symtab
;
1478 symtab
= (struct symtab
*)
1479 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symtab
));
1480 memset (symtab
, 0, sizeof (*symtab
));
1481 symtab
-> filename
= obsavestring (filename
, strlen (filename
),
1482 &objfile
-> symbol_obstack
);
1483 symtab
-> fullname
= NULL
;
1484 symtab
-> language
= deduce_language_from_filename (filename
);
1485 symtab
-> debugformat
= obsavestring ("unknown", 7,
1486 &objfile
-> symbol_obstack
);
1488 /* Hook it to the objfile it comes from */
1490 symtab
-> objfile
= objfile
;
1491 symtab
-> next
= objfile
-> symtabs
;
1492 objfile
-> symtabs
= symtab
;
1494 /* FIXME: This should go away. It is only defined for the Z8000,
1495 and the Z8000 definition of this macro doesn't have anything to
1496 do with the now-nonexistent EXTRA_SYMTAB_INFO macro, it's just
1497 here for convenience. */
1498 #ifdef INIT_EXTRA_SYMTAB_INFO
1499 INIT_EXTRA_SYMTAB_INFO (symtab
);
1505 struct partial_symtab
*
1506 allocate_psymtab (filename
, objfile
)
1508 struct objfile
*objfile
;
1510 struct partial_symtab
*psymtab
;
1512 if (objfile
-> free_psymtabs
)
1514 psymtab
= objfile
-> free_psymtabs
;
1515 objfile
-> free_psymtabs
= psymtab
-> next
;
1518 psymtab
= (struct partial_symtab
*)
1519 obstack_alloc (&objfile
-> psymbol_obstack
,
1520 sizeof (struct partial_symtab
));
1522 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1523 psymtab
-> filename
= obsavestring (filename
, strlen (filename
),
1524 &objfile
-> psymbol_obstack
);
1525 psymtab
-> symtab
= NULL
;
1527 /* Prepend it to the psymtab list for the objfile it belongs to.
1528 Psymtabs are searched in most recent inserted -> least recent
1531 psymtab
-> objfile
= objfile
;
1532 psymtab
-> next
= objfile
-> psymtabs
;
1533 objfile
-> psymtabs
= psymtab
;
1536 struct partial_symtab
**prev_pst
;
1537 psymtab
-> objfile
= objfile
;
1538 psymtab
-> next
= NULL
;
1539 prev_pst
= &(objfile
-> psymtabs
);
1540 while ((*prev_pst
) != NULL
)
1541 prev_pst
= &((*prev_pst
) -> next
);
1542 (*prev_pst
) = psymtab
;
1550 discard_psymtab (pst
)
1551 struct partial_symtab
*pst
;
1553 struct partial_symtab
**prev_pst
;
1556 Empty psymtabs happen as a result of header files which don't
1557 have any symbols in them. There can be a lot of them. But this
1558 check is wrong, in that a psymtab with N_SLINE entries but
1559 nothing else is not empty, but we don't realize that. Fixing
1560 that without slowing things down might be tricky. */
1562 /* First, snip it out of the psymtab chain */
1564 prev_pst
= &(pst
->objfile
->psymtabs
);
1565 while ((*prev_pst
) != pst
)
1566 prev_pst
= &((*prev_pst
)->next
);
1567 (*prev_pst
) = pst
->next
;
1569 /* Next, put it on a free list for recycling */
1571 pst
->next
= pst
->objfile
->free_psymtabs
;
1572 pst
->objfile
->free_psymtabs
= pst
;
1576 /* Reset all data structures in gdb which may contain references to symbol
1580 clear_symtab_users ()
1582 /* Someday, we should do better than this, by only blowing away
1583 the things that really need to be blown. */
1584 clear_value_history ();
1586 clear_internalvars ();
1587 breakpoint_re_set ();
1588 set_default_breakpoint (0, 0, 0, 0);
1589 current_source_symtab
= 0;
1590 current_source_line
= 0;
1591 clear_pc_function_cache ();
1592 target_new_objfile (NULL
);
1595 /* clear_symtab_users_once:
1597 This function is run after symbol reading, or from a cleanup.
1598 If an old symbol table was obsoleted, the old symbol table
1599 has been blown away, but the other GDB data structures that may
1600 reference it have not yet been cleared or re-directed. (The old
1601 symtab was zapped, and the cleanup queued, in free_named_symtab()
1604 This function can be queued N times as a cleanup, or called
1605 directly; it will do all the work the first time, and then will be a
1606 no-op until the next time it is queued. This works by bumping a
1607 counter at queueing time. Much later when the cleanup is run, or at
1608 the end of symbol processing (in case the cleanup is discarded), if
1609 the queued count is greater than the "done-count", we do the work
1610 and set the done-count to the queued count. If the queued count is
1611 less than or equal to the done-count, we just ignore the call. This
1612 is needed because reading a single .o file will often replace many
1613 symtabs (one per .h file, for example), and we don't want to reset
1614 the breakpoints N times in the user's face.
1616 The reason we both queue a cleanup, and call it directly after symbol
1617 reading, is because the cleanup protects us in case of errors, but is
1618 discarded if symbol reading is successful. */
1621 /* FIXME: As free_named_symtabs is currently a big noop this function
1622 is no longer needed. */
1624 clear_symtab_users_once
PARAMS ((void));
1626 static int clear_symtab_users_queued
;
1627 static int clear_symtab_users_done
;
1630 clear_symtab_users_once ()
1632 /* Enforce once-per-`do_cleanups'-semantics */
1633 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
1635 clear_symtab_users_done
= clear_symtab_users_queued
;
1637 clear_symtab_users ();
1641 /* Delete the specified psymtab, and any others that reference it. */
1644 cashier_psymtab (pst
)
1645 struct partial_symtab
*pst
;
1647 struct partial_symtab
*ps
, *pprev
= NULL
;
1650 /* Find its previous psymtab in the chain */
1651 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1658 /* Unhook it from the chain. */
1659 if (ps
== pst
->objfile
->psymtabs
)
1660 pst
->objfile
->psymtabs
= ps
->next
;
1662 pprev
->next
= ps
->next
;
1664 /* FIXME, we can't conveniently deallocate the entries in the
1665 partial_symbol lists (global_psymbols/static_psymbols) that
1666 this psymtab points to. These just take up space until all
1667 the psymtabs are reclaimed. Ditto the dependencies list and
1668 filename, which are all in the psymbol_obstack. */
1670 /* We need to cashier any psymtab that has this one as a dependency... */
1672 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1673 for (i
= 0; i
< ps
->number_of_dependencies
; i
++) {
1674 if (ps
->dependencies
[i
] == pst
) {
1675 cashier_psymtab (ps
);
1676 goto again
; /* Must restart, chain has been munged. */
1683 /* If a symtab or psymtab for filename NAME is found, free it along
1684 with any dependent breakpoints, displays, etc.
1685 Used when loading new versions of object modules with the "add-file"
1686 command. This is only called on the top-level symtab or psymtab's name;
1687 it is not called for subsidiary files such as .h files.
1689 Return value is 1 if we blew away the environment, 0 if not.
1690 FIXME. The return valu appears to never be used.
1692 FIXME. I think this is not the best way to do this. We should
1693 work on being gentler to the environment while still cleaning up
1694 all stray pointers into the freed symtab. */
1697 free_named_symtabs (name
)
1701 /* FIXME: With the new method of each objfile having it's own
1702 psymtab list, this function needs serious rethinking. In particular,
1703 why was it ever necessary to toss psymtabs with specific compilation
1704 unit filenames, as opposed to all psymtabs from a particular symbol
1706 Well, the answer is that some systems permit reloading of particular
1707 compilation units. We want to blow away any old info about these
1708 compilation units, regardless of which objfiles they arrived in. --gnu. */
1710 register struct symtab
*s
;
1711 register struct symtab
*prev
;
1712 register struct partial_symtab
*ps
;
1713 struct blockvector
*bv
;
1716 /* We only wack things if the symbol-reload switch is set. */
1717 if (!symbol_reloading
)
1720 /* Some symbol formats have trouble providing file names... */
1721 if (name
== 0 || *name
== '\0')
1724 /* Look for a psymtab with the specified name. */
1727 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1728 if (STREQ (name
, ps
->filename
)) {
1729 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
1730 goto again2
; /* Must restart, chain has been munged */
1734 /* Look for a symtab with the specified name. */
1736 for (s
= symtab_list
; s
; s
= s
->next
)
1738 if (STREQ (name
, s
->filename
))
1745 if (s
== symtab_list
)
1746 symtab_list
= s
->next
;
1748 prev
->next
= s
->next
;
1750 /* For now, queue a delete for all breakpoints, displays, etc., whether
1751 or not they depend on the symtab being freed. This should be
1752 changed so that only those data structures affected are deleted. */
1754 /* But don't delete anything if the symtab is empty.
1755 This test is necessary due to a bug in "dbxread.c" that
1756 causes empty symtabs to be created for N_SO symbols that
1757 contain the pathname of the object file. (This problem
1758 has been fixed in GDB 3.9x). */
1760 bv
= BLOCKVECTOR (s
);
1761 if (BLOCKVECTOR_NBLOCKS (bv
) > 2
1762 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
1763 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
1765 complain (&oldsyms_complaint
, name
);
1767 clear_symtab_users_queued
++;
1768 make_cleanup (clear_symtab_users_once
, 0);
1771 complain (&empty_symtab_complaint
, name
);
1778 /* It is still possible that some breakpoints will be affected
1779 even though no symtab was found, since the file might have
1780 been compiled without debugging, and hence not be associated
1781 with a symtab. In order to handle this correctly, we would need
1782 to keep a list of text address ranges for undebuggable files.
1783 For now, we do nothing, since this is a fairly obscure case. */
1787 /* FIXME, what about the minimal symbol table? */
1794 /* Allocate and partially fill a partial symtab. It will be
1795 completely filled at the end of the symbol list.
1797 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1798 is the address relative to which its symbols are (incremental) or 0
1802 struct partial_symtab
*
1803 start_psymtab_common (objfile
, section_offsets
,
1804 filename
, textlow
, global_syms
, static_syms
)
1805 struct objfile
*objfile
;
1806 struct section_offsets
*section_offsets
;
1809 struct partial_symbol
**global_syms
;
1810 struct partial_symbol
**static_syms
;
1812 struct partial_symtab
*psymtab
;
1814 psymtab
= allocate_psymtab (filename
, objfile
);
1815 psymtab
-> section_offsets
= section_offsets
;
1816 psymtab
-> textlow
= textlow
;
1817 psymtab
-> texthigh
= psymtab
-> textlow
; /* default */
1818 psymtab
-> globals_offset
= global_syms
- objfile
-> global_psymbols
.list
;
1819 psymtab
-> statics_offset
= static_syms
- objfile
-> static_psymbols
.list
;
1823 /* Add a symbol with a long value to a psymtab.
1824 Since one arg is a struct, we pass in a ptr and deref it (sigh). */
1827 add_psymbol_to_list (name
, namelength
, namespace, class, list
, val
, coreaddr
,
1831 namespace_enum
namespace;
1832 enum address_class
class;
1833 struct psymbol_allocation_list
*list
;
1834 long val
; /* Value as a long */
1835 CORE_ADDR coreaddr
; /* Value as a CORE_ADDR */
1836 enum language language
;
1837 struct objfile
*objfile
;
1839 register struct partial_symbol
*psym
;
1840 char *buf
= alloca (namelength
+ 1);
1841 /* psymbol is static so that there will be no uninitialized gaps in the
1842 structure which might contain random data, causing cache misses in
1844 static struct partial_symbol psymbol
;
1846 /* Create local copy of the partial symbol */
1847 memcpy (buf
, name
, namelength
);
1848 buf
[namelength
] = '\0';
1849 SYMBOL_NAME (&psymbol
) = bcache (buf
, namelength
+ 1, &objfile
->psymbol_cache
);
1850 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
1853 SYMBOL_VALUE (&psymbol
) = val
;
1857 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1859 SYMBOL_SECTION (&psymbol
) = 0;
1860 SYMBOL_LANGUAGE (&psymbol
) = language
;
1861 PSYMBOL_NAMESPACE (&psymbol
) = namespace;
1862 PSYMBOL_CLASS (&psymbol
) = class;
1863 SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol
, language
);
1865 /* Stash the partial symbol away in the cache */
1866 psym
= bcache (&psymbol
, sizeof (struct partial_symbol
), &objfile
->psymbol_cache
);
1868 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1869 if (list
->next
>= list
->list
+ list
->size
)
1871 extend_psymbol_list (list
, objfile
);
1873 *list
->next
++ = psym
;
1874 OBJSTAT (objfile
, n_psyms
++);
1877 /* Initialize storage for partial symbols. */
1880 init_psymbol_list (objfile
, total_symbols
)
1881 struct objfile
*objfile
;
1884 /* Free any previously allocated psymbol lists. */
1886 if (objfile
-> global_psymbols
.list
)
1888 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
1890 if (objfile
-> static_psymbols
.list
)
1892 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
1895 /* Current best guess is that approximately a twentieth
1896 of the total symbols (in a debugging file) are global or static
1899 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
1900 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
1902 if (objfile
-> global_psymbols
.size
> 0)
1904 objfile
-> global_psymbols
.next
=
1905 objfile
-> global_psymbols
.list
= (struct partial_symbol
**)
1906 xmmalloc (objfile
-> md
, (objfile
-> global_psymbols
.size
1907 * sizeof (struct partial_symbol
*)));
1909 if (objfile
-> static_psymbols
.size
> 0)
1911 objfile
-> static_psymbols
.next
=
1912 objfile
-> static_psymbols
.list
= (struct partial_symbol
**)
1913 xmmalloc (objfile
-> md
, (objfile
-> static_psymbols
.size
1914 * sizeof (struct partial_symbol
*)));
1919 The following code implements an abstraction for debugging overlay sections.
1921 The target model is as follows:
1922 1) The gnu linker will permit multiple sections to be mapped into the
1923 same VMA, each with its own unique LMA (or load address).
1924 2) It is assumed that some runtime mechanism exists for mapping the
1925 sections, one by one, from the load address into the VMA address.
1926 3) This code provides a mechanism for gdb to keep track of which
1927 sections should be considered to be mapped from the VMA to the LMA.
1928 This information is used for symbol lookup, and memory read/write.
1929 For instance, if a section has been mapped then its contents
1930 should be read from the VMA, otherwise from the LMA.
1932 Two levels of debugger support for overlays are available. One is
1933 "manual", in which the debugger relies on the user to tell it which
1934 overlays are currently mapped. This level of support is
1935 implemented entirely in the core debugger, and the information about
1936 whether a section is mapped is kept in the objfile->obj_section table.
1938 The second level of support is "automatic", and is only available if
1939 the target-specific code provides functionality to read the target's
1940 overlay mapping table, and translate its contents for the debugger
1941 (by updating the mapped state information in the obj_section tables).
1943 The interface is as follows:
1945 overlay map <name> -- tell gdb to consider this section mapped
1946 overlay unmap <name> -- tell gdb to consider this section unmapped
1947 overlay list -- list the sections that GDB thinks are mapped
1948 overlay read-target -- get the target's state of what's mapped
1949 overlay off/manual/auto -- set overlay debugging state
1950 Functional interface:
1951 find_pc_mapped_section(pc): if the pc is in the range of a mapped
1952 section, return that section.
1953 find_pc_overlay(pc): find any overlay section that contains
1954 the pc, either in its VMA or its LMA
1955 overlay_is_mapped(sect): true if overlay is marked as mapped
1956 section_is_overlay(sect): true if section's VMA != LMA
1957 pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA
1958 pc_in_unmapped_range(...): true if pc belongs to section's LMA
1959 overlay_mapped_address(...): map an address from section's LMA to VMA
1960 overlay_unmapped_address(...): map an address from section's VMA to LMA
1961 symbol_overlayed_address(...): Return a "current" address for symbol:
1962 either in VMA or LMA depending on whether
1963 the symbol's section is currently mapped
1966 /* Overlay debugging state: */
1968 int overlay_debugging
= 0; /* 0 == off, 1 == manual, -1 == auto */
1969 int overlay_cache_invalid
= 0; /* True if need to refresh mapped state */
1971 /* Target vector for refreshing overlay mapped state */
1972 static void simple_overlay_update
PARAMS ((struct obj_section
*));
1973 void (*target_overlay_update
) PARAMS ((struct obj_section
*))
1974 = simple_overlay_update
;
1976 /* Function: section_is_overlay (SECTION)
1977 Returns true if SECTION has VMA not equal to LMA, ie.
1978 SECTION is loaded at an address different from where it will "run". */
1981 section_is_overlay (section
)
1984 if (overlay_debugging
)
1985 if (section
&& section
->lma
!= 0 &&
1986 section
->vma
!= section
->lma
)
1992 /* Function: overlay_invalidate_all (void)
1993 Invalidate the mapped state of all overlay sections (mark it as stale). */
1996 overlay_invalidate_all ()
1998 struct objfile
*objfile
;
1999 struct obj_section
*sect
;
2001 ALL_OBJSECTIONS (objfile
, sect
)
2002 if (section_is_overlay (sect
->the_bfd_section
))
2003 sect
->ovly_mapped
= -1;
2006 /* Function: overlay_is_mapped (SECTION)
2007 Returns true if section is an overlay, and is currently mapped.
2008 Private: public access is thru function section_is_mapped.
2010 Access to the ovly_mapped flag is restricted to this function, so
2011 that we can do automatic update. If the global flag
2012 OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call
2013 overlay_invalidate_all. If the mapped state of the particular
2014 section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */
2017 overlay_is_mapped (osect
)
2018 struct obj_section
*osect
;
2020 if (osect
== 0 || !section_is_overlay (osect
->the_bfd_section
))
2023 switch (overlay_debugging
)
2026 case 0: return 0; /* overlay debugging off */
2027 case -1: /* overlay debugging automatic */
2028 /* Unles there is a target_overlay_update function,
2029 there's really nothing useful to do here (can't really go auto) */
2030 if (target_overlay_update
)
2032 if (overlay_cache_invalid
)
2034 overlay_invalidate_all ();
2035 overlay_cache_invalid
= 0;
2037 if (osect
->ovly_mapped
== -1)
2038 (*target_overlay_update
) (osect
);
2040 /* fall thru to manual case */
2041 case 1: /* overlay debugging manual */
2042 return osect
->ovly_mapped
== 1;
2046 /* Function: section_is_mapped
2047 Returns true if section is an overlay, and is currently mapped. */
2050 section_is_mapped (section
)
2053 struct objfile
*objfile
;
2054 struct obj_section
*osect
;
2056 if (overlay_debugging
)
2057 if (section
&& section_is_overlay (section
))
2058 ALL_OBJSECTIONS (objfile
, osect
)
2059 if (osect
->the_bfd_section
== section
)
2060 return overlay_is_mapped (osect
);
2065 /* Function: pc_in_unmapped_range
2066 If PC falls into the lma range of SECTION, return true, else false. */
2069 pc_in_unmapped_range (pc
, section
)
2075 if (overlay_debugging
)
2076 if (section
&& section_is_overlay (section
))
2078 size
= bfd_get_section_size_before_reloc (section
);
2079 if (section
->lma
<= pc
&& pc
< section
->lma
+ size
)
2085 /* Function: pc_in_mapped_range
2086 If PC falls into the vma range of SECTION, return true, else false. */
2089 pc_in_mapped_range (pc
, section
)
2095 if (overlay_debugging
)
2096 if (section
&& section_is_overlay (section
))
2098 size
= bfd_get_section_size_before_reloc (section
);
2099 if (section
->vma
<= pc
&& pc
< section
->vma
+ size
)
2105 /* Function: overlay_unmapped_address (PC, SECTION)
2106 Returns the address corresponding to PC in the unmapped (load) range.
2107 May be the same as PC. */
2110 overlay_unmapped_address (pc
, section
)
2114 if (overlay_debugging
)
2115 if (section
&& section_is_overlay (section
) &&
2116 pc_in_mapped_range (pc
, section
))
2117 return pc
+ section
->lma
- section
->vma
;
2122 /* Function: overlay_mapped_address (PC, SECTION)
2123 Returns the address corresponding to PC in the mapped (runtime) range.
2124 May be the same as PC. */
2127 overlay_mapped_address (pc
, section
)
2131 if (overlay_debugging
)
2132 if (section
&& section_is_overlay (section
) &&
2133 pc_in_unmapped_range (pc
, section
))
2134 return pc
+ section
->vma
- section
->lma
;
2140 /* Function: symbol_overlayed_address
2141 Return one of two addresses (relative to the VMA or to the LMA),
2142 depending on whether the section is mapped or not. */
2145 symbol_overlayed_address (address
, section
)
2149 if (overlay_debugging
)
2151 /* If the symbol has no section, just return its regular address. */
2154 /* If the symbol's section is not an overlay, just return its address */
2155 if (!section_is_overlay (section
))
2157 /* If the symbol's section is mapped, just return its address */
2158 if (section_is_mapped (section
))
2161 * HOWEVER: if the symbol is in an overlay section which is NOT mapped,
2162 * then return its LOADED address rather than its vma address!!
2164 return overlay_unmapped_address (address
, section
);
2169 /* Function: find_pc_overlay (PC)
2170 Return the best-match overlay section for PC:
2171 If PC matches a mapped overlay section's VMA, return that section.
2172 Else if PC matches an unmapped section's VMA, return that section.
2173 Else if PC matches an unmapped section's LMA, return that section. */
2176 find_pc_overlay (pc
)
2179 struct objfile
*objfile
;
2180 struct obj_section
*osect
, *best_match
= NULL
;
2182 if (overlay_debugging
)
2183 ALL_OBJSECTIONS (objfile
, osect
)
2184 if (section_is_overlay (osect
->the_bfd_section
))
2186 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
))
2188 if (overlay_is_mapped (osect
))
2189 return osect
->the_bfd_section
;
2193 else if (pc_in_unmapped_range (pc
, osect
->the_bfd_section
))
2196 return best_match
? best_match
->the_bfd_section
: NULL
;
2199 /* Function: find_pc_mapped_section (PC)
2200 If PC falls into the VMA address range of an overlay section that is
2201 currently marked as MAPPED, return that section. Else return NULL. */
2204 find_pc_mapped_section (pc
)
2207 struct objfile
*objfile
;
2208 struct obj_section
*osect
;
2210 if (overlay_debugging
)
2211 ALL_OBJSECTIONS (objfile
, osect
)
2212 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
) &&
2213 overlay_is_mapped (osect
))
2214 return osect
->the_bfd_section
;
2219 /* Function: list_overlays_command
2220 Print a list of mapped sections and their PC ranges */
2223 list_overlays_command (args
, from_tty
)
2228 struct objfile
*objfile
;
2229 struct obj_section
*osect
;
2231 if (overlay_debugging
)
2232 ALL_OBJSECTIONS (objfile
, osect
)
2233 if (overlay_is_mapped (osect
))
2239 vma
= bfd_section_vma (objfile
->obfd
, osect
->the_bfd_section
);
2240 lma
= bfd_section_lma (objfile
->obfd
, osect
->the_bfd_section
);
2241 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2242 name
= bfd_section_name (objfile
->obfd
, osect
->the_bfd_section
);
2243 printf_filtered ("Section %s, loaded at %08x - %08x, ",
2244 name
, lma
, lma
+ size
);
2245 printf_filtered ("mapped at %08x - %08x\n",
2250 printf_filtered ("No sections are mapped.\n");
2253 /* Function: map_overlay_command
2254 Mark the named section as mapped (ie. residing at its VMA address). */
2257 map_overlay_command (args
, from_tty
)
2261 struct objfile
*objfile
, *objfile2
;
2262 struct obj_section
*sec
, *sec2
;
2265 if (!overlay_debugging
)
2266 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2268 if (args
== 0 || *args
== 0)
2269 error ("Argument required: name of an overlay section");
2271 /* First, find a section matching the user supplied argument */
2272 ALL_OBJSECTIONS (objfile
, sec
)
2273 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2275 /* Now, check to see if the section is an overlay. */
2276 bfdsec
= sec
->the_bfd_section
;
2277 if (!section_is_overlay (bfdsec
))
2278 continue; /* not an overlay section */
2280 /* Mark the overlay as "mapped" */
2281 sec
->ovly_mapped
= 1;
2283 /* Next, make a pass and unmap any sections that are
2284 overlapped by this new section: */
2285 ALL_OBJSECTIONS (objfile2
, sec2
)
2286 if (sec2
->ovly_mapped
&&
2288 sec
->the_bfd_section
!= sec2
->the_bfd_section
&&
2289 (pc_in_mapped_range (sec2
->addr
, sec
->the_bfd_section
) ||
2290 pc_in_mapped_range (sec2
->endaddr
, sec
->the_bfd_section
)))
2293 printf_filtered ("Note: section %s unmapped by overlap\n",
2294 bfd_section_name (objfile
->obfd
,
2295 sec2
->the_bfd_section
));
2296 sec2
->ovly_mapped
= 0; /* sec2 overlaps sec: unmap sec2 */
2300 error ("No overlay section called %s", args
);
2303 /* Function: unmap_overlay_command
2304 Mark the overlay section as unmapped
2305 (ie. resident in its LMA address range, rather than the VMA range). */
2308 unmap_overlay_command (args
, from_tty
)
2312 struct objfile
*objfile
;
2313 struct obj_section
*sec
;
2315 if (!overlay_debugging
)
2316 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2318 if (args
== 0 || *args
== 0)
2319 error ("Argument required: name of an overlay section");
2321 /* First, find a section matching the user supplied argument */
2322 ALL_OBJSECTIONS (objfile
, sec
)
2323 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2325 if (!sec
->ovly_mapped
)
2326 error ("Section %s is not mapped", args
);
2327 sec
->ovly_mapped
= 0;
2330 error ("No overlay section called %s", args
);
2333 /* Function: overlay_auto_command
2334 A utility command to turn on overlay debugging.
2335 Possibly this should be done via a set/show command. */
2338 overlay_auto_command (args
, from_tty
)
2342 overlay_debugging
= -1;
2344 printf_filtered ("Automatic overlay debugging enabled.");
2347 /* Function: overlay_manual_command
2348 A utility command to turn on overlay debugging.
2349 Possibly this should be done via a set/show command. */
2352 overlay_manual_command (args
, from_tty
)
2356 overlay_debugging
= 1;
2358 printf_filtered ("Overlay debugging enabled.");
2361 /* Function: overlay_off_command
2362 A utility command to turn on overlay debugging.
2363 Possibly this should be done via a set/show command. */
2366 overlay_off_command (args
, from_tty
)
2370 overlay_debugging
= 0;
2372 printf_filtered ("Overlay debugging disabled.");
2376 overlay_load_command (args
, from_tty
)
2380 if (target_overlay_update
)
2381 (*target_overlay_update
) (NULL
);
2383 error ("This target does not know how to read its overlay state.");
2386 /* Function: overlay_command
2387 A place-holder for a mis-typed command */
2389 /* Command list chain containing all defined "overlay" subcommands. */
2390 struct cmd_list_element
*overlaylist
;
2393 overlay_command (args
, from_tty
)
2398 ("\"overlay\" must be followed by the name of an overlay command.\n");
2399 help_list (overlaylist
, "overlay ", -1, gdb_stdout
);
2403 /* Target Overlays for the "Simplest" overlay manager:
2405 This is GDB's default target overlay layer. It works with the
2406 minimal overlay manager supplied as an example by Cygnus. The
2407 entry point is via a function pointer "target_overlay_update",
2408 so targets that use a different runtime overlay manager can
2409 substitute their own overlay_update function and take over the
2412 The overlay_update function pokes around in the target's data structures
2413 to see what overlays are mapped, and updates GDB's overlay mapping with
2416 In this simple implementation, the target data structures are as follows:
2417 unsigned _novlys; /# number of overlay sections #/
2418 unsigned _ovly_table[_novlys][4] = {
2419 {VMA, SIZE, LMA, MAPPED}, /# one entry per overlay section #/
2420 {..., ..., ..., ...},
2422 unsigned _novly_regions; /# number of overlay regions #/
2423 unsigned _ovly_region_table[_novly_regions][3] = {
2424 {VMA, SIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/
2427 These functions will attempt to update GDB's mappedness state in the
2428 symbol section table, based on the target's mappedness state.
2430 To do this, we keep a cached copy of the target's _ovly_table, and
2431 attempt to detect when the cached copy is invalidated. The main
2432 entry point is "simple_overlay_update(SECT), which looks up SECT in
2433 the cached table and re-reads only the entry for that section from
2434 the target (whenever possible).
2437 /* Cached, dynamically allocated copies of the target data structures: */
2438 static unsigned (*cache_ovly_table
)[4] = 0;
2440 static unsigned (*cache_ovly_region_table
)[3] = 0;
2442 static unsigned cache_novlys
= 0;
2444 static unsigned cache_novly_regions
= 0;
2446 static CORE_ADDR cache_ovly_table_base
= 0;
2448 static CORE_ADDR cache_ovly_region_table_base
= 0;
2450 enum ovly_index
{ VMA
, SIZE
, LMA
, MAPPED
};
2451 #define TARGET_LONG_BYTES (TARGET_LONG_BIT / TARGET_CHAR_BIT)
2453 /* Throw away the cached copy of _ovly_table */
2455 simple_free_overlay_table ()
2457 if (cache_ovly_table
)
2458 free(cache_ovly_table
);
2460 cache_ovly_table
= NULL
;
2461 cache_ovly_table_base
= 0;
2465 /* Throw away the cached copy of _ovly_region_table */
2467 simple_free_overlay_region_table ()
2469 if (cache_ovly_region_table
)
2470 free(cache_ovly_region_table
);
2471 cache_novly_regions
= 0;
2472 cache_ovly_region_table
= NULL
;
2473 cache_ovly_region_table_base
= 0;
2477 /* Read an array of ints from the target into a local buffer.
2478 Convert to host order. int LEN is number of ints */
2480 read_target_long_array (memaddr
, myaddr
, len
)
2482 unsigned int *myaddr
;
2485 char *buf
= alloca (len
* TARGET_LONG_BYTES
);
2488 read_memory (memaddr
, buf
, len
* TARGET_LONG_BYTES
);
2489 for (i
= 0; i
< len
; i
++)
2490 myaddr
[i
] = extract_unsigned_integer (TARGET_LONG_BYTES
* i
+ buf
,
2494 /* Find and grab a copy of the target _ovly_table
2495 (and _novlys, which is needed for the table's size) */
2497 simple_read_overlay_table ()
2499 struct minimal_symbol
*msym
;
2501 simple_free_overlay_table ();
2502 msym
= lookup_minimal_symbol ("_novlys", 0, 0);
2504 cache_novlys
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
2506 return 0; /* failure */
2507 cache_ovly_table
= (void *) xmalloc (cache_novlys
* sizeof(*cache_ovly_table
));
2508 if (cache_ovly_table
!= NULL
)
2510 msym
= lookup_minimal_symbol ("_ovly_table", 0, 0);
2513 cache_ovly_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
2514 read_target_long_array (cache_ovly_table_base
,
2515 (int *) cache_ovly_table
,
2519 return 0; /* failure */
2522 return 0; /* failure */
2523 return 1; /* SUCCESS */
2527 /* Find and grab a copy of the target _ovly_region_table
2528 (and _novly_regions, which is needed for the table's size) */
2530 simple_read_overlay_region_table ()
2532 struct minimal_symbol
*msym
;
2534 simple_free_overlay_region_table ();
2535 msym
= lookup_minimal_symbol ("_novly_regions", 0, 0);
2537 cache_novly_regions
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
2539 return 0; /* failure */
2540 cache_ovly_region_table
= (void *) xmalloc (cache_novly_regions
* 12);
2541 if (cache_ovly_region_table
!= NULL
)
2543 msym
= lookup_minimal_symbol ("_ovly_region_table", 0, 0);
2546 cache_ovly_region_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
2547 read_target_long_array (cache_ovly_region_table_base
,
2548 (int *) cache_ovly_region_table
,
2549 cache_novly_regions
* 3);
2552 return 0; /* failure */
2555 return 0; /* failure */
2556 return 1; /* SUCCESS */
2560 /* Function: simple_overlay_update_1
2561 A helper function for simple_overlay_update. Assuming a cached copy
2562 of _ovly_table exists, look through it to find an entry whose vma,
2563 lma and size match those of OSECT. Re-read the entry and make sure
2564 it still matches OSECT (else the table may no longer be valid).
2565 Set OSECT's mapped state to match the entry. Return: 1 for
2566 success, 0 for failure. */
2569 simple_overlay_update_1 (osect
)
2570 struct obj_section
*osect
;
2574 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2575 for (i
= 0; i
< cache_novlys
; i
++)
2576 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2577 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2578 cache_ovly_table[i][SIZE] == size */)
2580 read_target_long_array (cache_ovly_table_base
+ i
* TARGET_LONG_BYTES
,
2581 (int *) cache_ovly_table
[i
], 4);
2582 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2583 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2584 cache_ovly_table[i][SIZE] == size */)
2586 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
2589 else /* Warning! Warning! Target's ovly table has changed! */
2595 /* Function: simple_overlay_update
2596 If OSECT is NULL, then update all sections' mapped state
2597 (after re-reading the entire target _ovly_table).
2598 If OSECT is non-NULL, then try to find a matching entry in the
2599 cached ovly_table and update only OSECT's mapped state.
2600 If a cached entry can't be found or the cache isn't valid, then
2601 re-read the entire cache, and go ahead and update all sections. */
2604 simple_overlay_update (osect
)
2605 struct obj_section
*osect
;
2607 struct objfile
*objfile
;
2609 /* Were we given an osect to look up? NULL means do all of them. */
2611 /* Have we got a cached copy of the target's overlay table? */
2612 if (cache_ovly_table
!= NULL
)
2613 /* Does its cached location match what's currently in the symtab? */
2614 if (cache_ovly_table_base
==
2615 SYMBOL_VALUE_ADDRESS (lookup_minimal_symbol ("_ovly_table", 0, 0)))
2616 /* Then go ahead and try to look up this single section in the cache */
2617 if (simple_overlay_update_1 (osect
))
2618 /* Found it! We're done. */
2621 /* Cached table no good: need to read the entire table anew.
2622 Or else we want all the sections, in which case it's actually
2623 more efficient to read the whole table in one block anyway. */
2625 if (simple_read_overlay_table () == 0) /* read failed? No table? */
2627 warning ("Failed to read the target overlay mapping table.");
2630 /* Now may as well update all sections, even if only one was requested. */
2631 ALL_OBJSECTIONS (objfile
, osect
)
2632 if (section_is_overlay (osect
->the_bfd_section
))
2636 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2637 for (i
= 0; i
< cache_novlys
; i
++)
2638 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2639 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2640 cache_ovly_table[i][SIZE] == size */)
2641 { /* obj_section matches i'th entry in ovly_table */
2642 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
2643 break; /* finished with inner for loop: break out */
2650 _initialize_symfile ()
2652 struct cmd_list_element
*c
;
2654 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
,
2655 "Load symbol table from executable file FILE.\n\
2656 The `file' command can also load symbol tables, as well as setting the file\n\
2657 to execute.", &cmdlist
);
2658 c
->completer
= filename_completer
;
2660 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
,
2661 "Usage: add-symbol-file FILE ADDR\n\
2662 Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
2663 ADDR is the starting address of the file's text.",
2665 c
->completer
= filename_completer
;
2667 c
= add_cmd ("add-shared-symbol-files", class_files
,
2668 add_shared_symbol_files_command
,
2669 "Load the symbols from shared objects in the dynamic linker's link map.",
2671 c
= add_alias_cmd ("assf", "add-shared-symbol-files", class_files
, 1,
2674 c
= add_cmd ("load", class_files
, load_command
,
2675 "Dynamically load FILE into the running program, and record its symbols\n\
2676 for access from GDB.", &cmdlist
);
2677 c
->completer
= filename_completer
;
2680 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
2681 (char *)&symbol_reloading
,
2682 "Set dynamic symbol table reloading multiple times in one run.",
2686 add_prefix_cmd ("overlay", class_support
, overlay_command
,
2687 "Commands for debugging overlays.", &overlaylist
,
2688 "overlay ", 0, &cmdlist
);
2690 add_com_alias ("ovly", "overlay", class_alias
, 1);
2691 add_com_alias ("ov", "overlay", class_alias
, 1);
2693 add_cmd ("map-overlay", class_support
, map_overlay_command
,
2694 "Assert that an overlay section is mapped.", &overlaylist
);
2696 add_cmd ("unmap-overlay", class_support
, unmap_overlay_command
,
2697 "Assert that an overlay section is unmapped.", &overlaylist
);
2699 add_cmd ("list-overlays", class_support
, list_overlays_command
,
2700 "List mappings of overlay sections.", &overlaylist
);
2702 add_cmd ("manual", class_support
, overlay_manual_command
,
2703 "Enable overlay debugging.", &overlaylist
);
2704 add_cmd ("off", class_support
, overlay_off_command
,
2705 "Disable overlay debugging.", &overlaylist
);
2706 add_cmd ("auto", class_support
, overlay_auto_command
,
2707 "Enable automatic overlay debugging.", &overlaylist
);
2708 add_cmd ("load-target", class_support
, overlay_load_command
,
2709 "Read the overlay mapping state from the target.", &overlaylist
);