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));
57 /* Global variables owned by this file */
58 int readnow_symbol_files
; /* Read full symbols immediately */
60 struct complaint oldsyms_complaint
= {
61 "Replacing old symbols for `%s'", 0, 0
64 struct complaint empty_symtab_complaint
= {
65 "Empty symbol table found for `%s'", 0, 0
68 /* External variables and functions referenced. */
70 extern int info_verbose
;
72 extern void report_transfer_performance
PARAMS ((unsigned long,
75 /* Functions this file defines */
78 static int simple_read_overlay_region_table
PARAMS ((void));
79 static void simple_free_overlay_region_table
PARAMS ((void));
82 static void set_initial_language
PARAMS ((void));
84 static void load_command
PARAMS ((char *, int));
86 static void add_symbol_file_command
PARAMS ((char *, int));
88 static void add_shared_symbol_files_command
PARAMS ((char *, int));
90 static void cashier_psymtab
PARAMS ((struct partial_symtab
*));
92 static int compare_psymbols
PARAMS ((const void *, const void *));
94 static int compare_symbols
PARAMS ((const void *, const void *));
96 static bfd
*symfile_bfd_open
PARAMS ((char *));
98 static void find_sym_fns
PARAMS ((struct objfile
*));
100 static void decrement_reading_symtab
PARAMS ((void *));
102 /* List of all available sym_fns. On gdb startup, each object file reader
103 calls add_symtab_fns() to register information on each format it is
106 static struct sym_fns
*symtab_fns
= NULL
;
108 /* Flag for whether user will be reloading symbols multiple times.
109 Defaults to ON for VxWorks, otherwise OFF. */
111 #ifdef SYMBOL_RELOADING_DEFAULT
112 int symbol_reloading
= SYMBOL_RELOADING_DEFAULT
;
114 int symbol_reloading
= 0;
117 /* If true, then shared library symbols will be added automatically
118 when the inferior is created, new libraries are loaded, or when
119 attaching to the inferior. This is almost always what users
120 will want to have happen; but for very large programs, the startup
121 time will be excessive, and so if this is a problem, the user can
122 clear this flag and then add the shared library symbols as needed.
123 Note that there is a potential for confusion, since if the shared
124 library symbols are not loaded, commands like "info fun" will *not*
125 report all the functions that are actually present. */
127 int auto_solib_add
= 1;
130 /* Since this function is called from within qsort, in an ANSI environment
131 it must conform to the prototype for qsort, which specifies that the
132 comparison function takes two "void *" pointers. */
135 compare_symbols (s1p
, s2p
)
139 register struct symbol
**s1
, **s2
;
141 s1
= (struct symbol
**) s1p
;
142 s2
= (struct symbol
**) s2p
;
144 return (STRCMP (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
)));
151 compare_psymbols -- compare two partial symbols by name
155 Given pointers to pointers to two partial symbol table entries,
156 compare them by name and return -N, 0, or +N (ala strcmp).
157 Typically used by sorting routines like qsort().
161 Does direct compare of first two characters before punting
162 and passing to strcmp for longer compares. Note that the
163 original version had a bug whereby two null strings or two
164 identically named one character strings would return the
165 comparison of memory following the null byte.
170 compare_psymbols (s1p
, s2p
)
174 register char *st1
= SYMBOL_NAME (*(struct partial_symbol
**) s1p
);
175 register char *st2
= SYMBOL_NAME (*(struct partial_symbol
**) s2p
);
177 if ((st1
[0] - st2
[0]) || !st1
[0])
179 return (st1
[0] - st2
[0]);
181 else if ((st1
[1] - st2
[1]) || !st1
[1])
183 return (st1
[1] - st2
[1]);
187 return (STRCMP (st1
+ 2, st2
+ 2));
192 sort_pst_symbols (pst
)
193 struct partial_symtab
*pst
;
195 /* Sort the global list; don't sort the static list */
197 qsort (pst
-> objfile
-> global_psymbols
.list
+ pst
-> globals_offset
,
198 pst
-> n_global_syms
, sizeof (struct partial_symbol
*),
202 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
206 register struct block
*b
;
208 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
209 sizeof (struct symbol
*), compare_symbols
);
212 /* Call sort_symtab_syms to sort alphabetically
213 the symbols of each block of one symtab. */
217 register struct symtab
*s
;
219 register struct blockvector
*bv
;
222 register struct block
*b
;
226 bv
= BLOCKVECTOR (s
);
227 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
228 for (i
= 0; i
< nbl
; i
++)
230 b
= BLOCKVECTOR_BLOCK (bv
, i
);
231 if (BLOCK_SHOULD_SORT (b
))
236 /* Make a null terminated copy of the string at PTR with SIZE characters in
237 the obstack pointed to by OBSTACKP . Returns the address of the copy.
238 Note that the string at PTR does not have to be null terminated, I.E. it
239 may be part of a larger string and we are only saving a substring. */
242 obsavestring (ptr
, size
, obstackp
)
245 struct obstack
*obstackp
;
247 register char *p
= (char *) obstack_alloc (obstackp
, size
+ 1);
248 /* Open-coded memcpy--saves function call time. These strings are usually
249 short. FIXME: Is this really still true with a compiler that can
252 register char *p1
= ptr
;
253 register char *p2
= p
;
254 char *end
= ptr
+ size
;
262 /* Concatenate strings S1, S2 and S3; return the new string. Space is found
263 in the obstack pointed to by OBSTACKP. */
266 obconcat (obstackp
, s1
, s2
, s3
)
267 struct obstack
*obstackp
;
268 const char *s1
, *s2
, *s3
;
270 register int len
= strlen (s1
) + strlen (s2
) + strlen (s3
) + 1;
271 register char *val
= (char *) obstack_alloc (obstackp
, len
);
278 /* True if we are nested inside psymtab_to_symtab. */
280 int currently_reading_symtab
= 0;
283 decrement_reading_symtab (dummy
)
286 currently_reading_symtab
--;
289 /* Get the symbol table that corresponds to a partial_symtab.
290 This is fast after the first time you do it. In fact, there
291 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
295 psymtab_to_symtab (pst
)
296 register struct partial_symtab
*pst
;
298 /* If it's been looked up before, return it. */
302 /* If it has not yet been read in, read it. */
305 struct cleanup
*back_to
= make_cleanup (decrement_reading_symtab
, NULL
);
306 currently_reading_symtab
++;
307 (*pst
->read_symtab
) (pst
);
308 do_cleanups (back_to
);
314 /* Initialize entry point information for this objfile. */
317 init_entry_point_info (objfile
)
318 struct objfile
*objfile
;
320 /* Save startup file's range of PC addresses to help blockframe.c
321 decide where the bottom of the stack is. */
323 if (bfd_get_file_flags (objfile
-> obfd
) & EXEC_P
)
325 /* Executable file -- record its entry point so we'll recognize
326 the startup file because it contains the entry point. */
327 objfile
-> ei
.entry_point
= bfd_get_start_address (objfile
-> obfd
);
331 /* Examination of non-executable.o files. Short-circuit this stuff. */
332 objfile
-> ei
.entry_point
= INVALID_ENTRY_POINT
;
334 objfile
-> ei
.entry_file_lowpc
= INVALID_ENTRY_LOWPC
;
335 objfile
-> ei
.entry_file_highpc
= INVALID_ENTRY_HIGHPC
;
336 objfile
-> ei
.entry_func_lowpc
= INVALID_ENTRY_LOWPC
;
337 objfile
-> ei
.entry_func_highpc
= INVALID_ENTRY_HIGHPC
;
338 objfile
-> ei
.main_func_lowpc
= INVALID_ENTRY_LOWPC
;
339 objfile
-> ei
.main_func_highpc
= INVALID_ENTRY_HIGHPC
;
342 /* Get current entry point address. */
345 entry_point_address()
347 return symfile_objfile
? symfile_objfile
->ei
.entry_point
: 0;
350 /* Remember the lowest-addressed loadable section we've seen.
351 This function is called via bfd_map_over_sections.
353 In case of equal vmas, the section with the largest size becomes the
354 lowest-addressed loadable section.
356 If the vmas and sizes are equal, the last section is considered the
357 lowest-addressed loadable section. */
360 find_lowest_section (abfd
, sect
, obj
)
365 asection
**lowest
= (asection
**)obj
;
367 if (0 == (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
))
370 *lowest
= sect
; /* First loadable section */
371 else if (bfd_section_vma (abfd
, *lowest
) > bfd_section_vma (abfd
, sect
))
372 *lowest
= sect
; /* A lower loadable section */
373 else if (bfd_section_vma (abfd
, *lowest
) == bfd_section_vma (abfd
, sect
)
374 && (bfd_section_size (abfd
, (*lowest
))
375 <= bfd_section_size (abfd
, sect
)))
379 /* Parse the user's idea of an offset for dynamic linking, into our idea
380 of how to represent it for fast symbol reading. This is the default
381 version of the sym_fns.sym_offsets function for symbol readers that
382 don't need to do anything special. It allocates a section_offsets table
383 for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */
385 struct section_offsets
*
386 default_symfile_offsets (objfile
, addr
)
387 struct objfile
*objfile
;
390 struct section_offsets
*section_offsets
;
393 objfile
->num_sections
= SECT_OFF_MAX
;
394 section_offsets
= (struct section_offsets
*)
395 obstack_alloc (&objfile
-> psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
397 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
398 ANOFFSET (section_offsets
, i
) = addr
;
400 return section_offsets
;
404 /* Process a symbol file, as either the main file or as a dynamically
407 NAME is the file name (which will be tilde-expanded and made
408 absolute herein) (but we don't free or modify NAME itself).
409 FROM_TTY says how verbose to be. MAINLINE specifies whether this
410 is the main symbol file, or whether it's an extra symbol file such
411 as dynamically loaded code. If !mainline, ADDR is the address
412 where the text segment was loaded. If VERBO, the caller has printed
413 a verbose message about the symbol reading (and complaints can be
414 more terse about it). */
417 syms_from_objfile (objfile
, addr
, mainline
, verbo
)
418 struct objfile
*objfile
;
423 struct section_offsets
*section_offsets
;
424 asection
*lowest_sect
;
425 struct cleanup
*old_chain
;
427 init_entry_point_info (objfile
);
428 find_sym_fns (objfile
);
430 /* Make sure that partially constructed symbol tables will be cleaned up
431 if an error occurs during symbol reading. */
432 old_chain
= make_cleanup (free_objfile
, objfile
);
436 /* We will modify the main symbol table, make sure that all its users
437 will be cleaned up if an error occurs during symbol reading. */
438 make_cleanup (clear_symtab_users
, 0);
440 /* Since no error yet, throw away the old symbol table. */
442 if (symfile_objfile
!= NULL
)
444 free_objfile (symfile_objfile
);
445 symfile_objfile
= NULL
;
448 /* Currently we keep symbols from the add-symbol-file command.
449 If the user wants to get rid of them, they should do "symbol-file"
450 without arguments first. Not sure this is the best behavior
453 (*objfile
-> sf
-> sym_new_init
) (objfile
);
456 /* Convert addr into an offset rather than an absolute address.
457 We find the lowest address of a loaded segment in the objfile,
458 and assume that <addr> is where that got loaded. Due to historical
459 precedent, we warn if that doesn't happen to be a text segment. */
463 addr
= 0; /* No offset from objfile addresses. */
467 lowest_sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
468 if (lowest_sect
== NULL
)
469 bfd_map_over_sections (objfile
->obfd
, find_lowest_section
,
472 if (lowest_sect
== NULL
)
473 warning ("no loadable sections found in added symbol-file %s",
475 else if ((bfd_get_section_flags (objfile
->obfd
, lowest_sect
) & SEC_CODE
)
477 /* FIXME-32x64--assumes bfd_vma fits in long. */
478 warning ("Lowest section in %s is %s at 0x%lx",
480 bfd_section_name (objfile
->obfd
, lowest_sect
),
481 (unsigned long) bfd_section_vma (objfile
->obfd
, lowest_sect
));
484 addr
-= bfd_section_vma (objfile
->obfd
, lowest_sect
);
487 /* Initialize symbol reading routines for this objfile, allow complaints to
488 appear for this new file, and record how verbose to be, then do the
489 initial symbol reading for this file. */
491 (*objfile
-> sf
-> sym_init
) (objfile
);
492 clear_complaints (1, verbo
);
494 section_offsets
= (*objfile
-> sf
-> sym_offsets
) (objfile
, addr
);
495 objfile
->section_offsets
= section_offsets
;
497 #ifndef IBM6000_TARGET
498 /* This is a SVR4/SunOS specific hack, I think. In any event, it
499 screws RS/6000. sym_offsets should be doing this sort of thing,
500 because it knows the mapping between bfd sections and
502 /* This is a hack. As far as I can tell, section offsets are not
503 target dependent. They are all set to addr with a couple of
504 exceptions. The exceptions are sysvr4 shared libraries, whose
505 offsets are kept in solib structures anyway and rs6000 xcoff
506 which handles shared libraries in a completely unique way.
508 Section offsets are built similarly, except that they are built
509 by adding addr in all cases because there is no clear mapping
510 from section_offsets into actual sections. Note that solib.c
511 has a different algorythm for finding section offsets.
513 These should probably all be collapsed into some target
514 independent form of shared library support. FIXME. */
518 struct obj_section
*s
;
520 for (s
= objfile
->sections
; s
< objfile
->sections_end
; ++s
)
522 s
->addr
-= s
->offset
;
524 s
->endaddr
-= s
->offset
;
529 #endif /* not IBM6000_TARGET */
531 (*objfile
-> sf
-> sym_read
) (objfile
, section_offsets
, mainline
);
533 if (!have_partial_symbols () && !have_full_symbols ())
536 printf_filtered ("(no debugging symbols found)...");
540 /* Don't allow char * to have a typename (else would get caddr_t).
541 Ditto void *. FIXME: Check whether this is now done by all the
542 symbol readers themselves (many of them now do), and if so remove
545 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
546 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
548 /* Mark the objfile has having had initial symbol read attempted. Note
549 that this does not mean we found any symbols... */
551 objfile
-> flags
|= OBJF_SYMS
;
553 /* Discard cleanups as symbol reading was successful. */
555 discard_cleanups (old_chain
);
557 /* Call this after reading in a new symbol table to give target dependant code
558 a crack at the new symbols. For instance, this could be used to update the
559 values of target-specific symbols GDB needs to keep track of (such as
560 _sigtramp, or whatever). */
562 TARGET_SYMFILE_POSTREAD (objfile
);
565 /* Perform required actions after either reading in the initial
566 symbols for a new objfile, or mapping in the symbols from a reusable
570 new_symfile_objfile (objfile
, mainline
, verbo
)
571 struct objfile
*objfile
;
576 /* If this is the main symbol file we have to clean up all users of the
577 old main symbol file. Otherwise it is sufficient to fixup all the
578 breakpoints that may have been redefined by this symbol file. */
581 /* OK, make it the "real" symbol file. */
582 symfile_objfile
= objfile
;
584 clear_symtab_users ();
588 breakpoint_re_set ();
591 /* We're done reading the symbol file; finish off complaints. */
592 clear_complaints (0, verbo
);
595 /* Process a symbol file, as either the main file or as a dynamically
598 NAME is the file name (which will be tilde-expanded and made
599 absolute herein) (but we don't free or modify NAME itself).
600 FROM_TTY says how verbose to be. MAINLINE specifies whether this
601 is the main symbol file, or whether it's an extra symbol file such
602 as dynamically loaded code. If !mainline, ADDR is the address
603 where the text segment was loaded.
605 Upon success, returns a pointer to the objfile that was added.
606 Upon failure, jumps back to command level (never returns). */
609 symbol_file_add (name
, from_tty
, addr
, mainline
, mapped
, readnow
)
617 struct objfile
*objfile
;
618 struct partial_symtab
*psymtab
;
621 /* Open a bfd for the file, and give user a chance to burp if we'd be
622 interactively wiping out any existing symbols. */
624 abfd
= symfile_bfd_open (name
);
626 if ((have_full_symbols () || have_partial_symbols ())
629 && !query ("Load new symbol table from \"%s\"? ", name
))
630 error ("Not confirmed.");
632 objfile
= allocate_objfile (abfd
, mapped
);
634 /* If the objfile uses a mapped symbol file, and we have a psymtab for
635 it, then skip reading any symbols at this time. */
637 if ((objfile
-> flags
& OBJF_MAPPED
) && (objfile
-> flags
& OBJF_SYMS
))
639 /* We mapped in an existing symbol table file that already has had
640 initial symbol reading performed, so we can skip that part. Notify
641 the user that instead of reading the symbols, they have been mapped.
643 if (from_tty
|| info_verbose
)
645 printf_filtered ("Mapped symbols for %s...", name
);
647 gdb_flush (gdb_stdout
);
649 init_entry_point_info (objfile
);
650 find_sym_fns (objfile
);
654 /* We either created a new mapped symbol table, mapped an existing
655 symbol table file which has not had initial symbol reading
656 performed, or need to read an unmapped symbol table. */
657 if (from_tty
|| info_verbose
)
659 printf_filtered ("Reading symbols from %s...", name
);
661 gdb_flush (gdb_stdout
);
663 syms_from_objfile (objfile
, addr
, mainline
, from_tty
);
666 /* We now have at least a partial symbol table. Check to see if the
667 user requested that all symbols be read on initial access via either
668 the gdb startup command line or on a per symbol file basis. Expand
669 all partial symbol tables for this objfile if so. */
671 if (readnow
|| readnow_symbol_files
)
673 if (from_tty
|| info_verbose
)
675 printf_filtered ("expanding to full symbols...");
677 gdb_flush (gdb_stdout
);
680 for (psymtab
= objfile
-> psymtabs
;
682 psymtab
= psymtab
-> next
)
684 psymtab_to_symtab (psymtab
);
688 if (from_tty
|| info_verbose
)
690 printf_filtered ("done.\n");
691 gdb_flush (gdb_stdout
);
694 new_symfile_objfile (objfile
, mainline
, from_tty
);
696 target_new_objfile (objfile
);
701 /* This is the symbol-file command. Read the file, analyze its
702 symbols, and add a struct symtab to a symtab list. The syntax of
703 the command is rather bizarre--(1) buildargv implements various
704 quoting conventions which are undocumented and have little or
705 nothing in common with the way things are quoted (or not quoted)
706 elsewhere in GDB, (2) options are used, which are not generally
707 used in GDB (perhaps "set mapped on", "set readnow on" would be
708 better), (3) the order of options matters, which is contrary to GNU
709 conventions (because it is confusing and inconvenient). */
712 symbol_file_command (args
, from_tty
)
718 CORE_ADDR text_relocation
= 0; /* text_relocation */
719 struct cleanup
*cleanups
;
727 if ((have_full_symbols () || have_partial_symbols ())
729 && !query ("Discard symbol table from `%s'? ",
730 symfile_objfile
-> name
))
731 error ("Not confirmed.");
732 free_all_objfiles ();
733 symfile_objfile
= NULL
;
736 printf_unfiltered ("No symbol file now.\n");
741 if ((argv
= buildargv (args
)) == NULL
)
745 cleanups
= make_cleanup (freeargv
, (char *) argv
);
746 while (*argv
!= NULL
)
748 if (STREQ (*argv
, "-mapped"))
752 else if (STREQ (*argv
, "-readnow"))
756 else if (**argv
== '-')
758 error ("unknown option `%s'", *argv
);
766 /* this is for rombug remote only, to get the text relocation by
767 using link command */
768 p
= strrchr(name
, '/');
772 target_link(p
, &text_relocation
);
774 if (text_relocation
== (CORE_ADDR
)0)
776 else if (text_relocation
== (CORE_ADDR
)-1)
777 symbol_file_add (name
, from_tty
, (CORE_ADDR
)0, 1, mapped
,
780 symbol_file_add (name
, from_tty
, (CORE_ADDR
)text_relocation
,
783 /* Getting new symbols may change our opinion about what is
785 reinit_frame_cache ();
787 set_initial_language ();
794 error ("no symbol file name was specified");
796 do_cleanups (cleanups
);
800 /* Set the initial language.
802 A better solution would be to record the language in the psymtab when reading
803 partial symbols, and then use it (if known) to set the language. This would
804 be a win for formats that encode the language in an easily discoverable place,
805 such as DWARF. For stabs, we can jump through hoops looking for specially
806 named symbols or try to intuit the language from the specific type of stabs
807 we find, but we can't do that until later when we read in full symbols.
811 set_initial_language ()
813 struct partial_symtab
*pst
;
814 enum language lang
= language_unknown
;
816 pst
= find_main_psymtab ();
819 if (pst
-> filename
!= NULL
)
821 lang
= deduce_language_from_filename (pst
-> filename
);
823 if (lang
== language_unknown
)
825 /* Make C the default language */
829 expected_language
= current_language
; /* Don't warn the user */
833 /* Open file specified by NAME and hand it off to BFD for preliminary
834 analysis. Result is a newly initialized bfd *, which includes a newly
835 malloc'd` copy of NAME (tilde-expanded and made absolute).
836 In case of trouble, error() is called. */
839 symfile_bfd_open (name
)
846 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy */
848 /* Look down path for it, allocate 2nd new malloc'd copy. */
849 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
| O_BINARY
, 0, &absolute_name
);
850 #if defined(__GO32__) || defined(_WIN32)
853 char *exename
= alloca (strlen (name
) + 5);
854 strcat (strcpy (exename
, name
), ".exe");
855 desc
= openp (getenv ("PATH"), 1, exename
, O_RDONLY
| O_BINARY
,
861 make_cleanup (free
, name
);
862 perror_with_name (name
);
864 free (name
); /* Free 1st new malloc'd copy */
865 name
= absolute_name
; /* Keep 2nd malloc'd copy in bfd */
866 /* It'll be freed in free_objfile(). */
868 sym_bfd
= bfd_fdopenr (name
, gnutarget
, desc
);
872 make_cleanup (free
, name
);
873 error ("\"%s\": can't open to read symbols: %s.", name
,
874 bfd_errmsg (bfd_get_error ()));
876 sym_bfd
->cacheable
= true;
878 if (!bfd_check_format (sym_bfd
, bfd_object
))
880 /* FIXME: should be checking for errors from bfd_close (for one thing,
881 on error it does not free all the storage associated with the
883 bfd_close (sym_bfd
); /* This also closes desc */
884 make_cleanup (free
, name
);
885 error ("\"%s\": can't read symbols: %s.", name
,
886 bfd_errmsg (bfd_get_error ()));
892 /* Link a new symtab_fns into the global symtab_fns list. Called on gdb
893 startup by the _initialize routine in each object file format reader,
894 to register information about each format the the reader is prepared
901 sf
->next
= symtab_fns
;
906 /* Initialize to read symbols from the symbol file sym_bfd. It either
907 returns or calls error(). The result is an initialized struct sym_fns
908 in the objfile structure, that contains cached information about the
912 find_sym_fns (objfile
)
913 struct objfile
*objfile
;
916 enum bfd_flavour our_flavour
= bfd_get_flavour (objfile
-> obfd
);
917 char *our_target
= bfd_get_target (objfile
-> obfd
);
919 /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */
920 if (STREQ (our_target
, "aixcoff-rs6000") ||
921 STREQ (our_target
, "xcoff-powermac"))
922 our_flavour
= (enum bfd_flavour
)-1;
924 /* Special kludge for apollo. See dstread.c. */
925 if (STREQN (our_target
, "apollo", 6))
926 our_flavour
= (enum bfd_flavour
)-2;
928 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
-> next
)
930 if (our_flavour
== sf
-> sym_flavour
)
936 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
937 bfd_get_target (objfile
-> obfd
));
940 /* This function runs the load command of our current target. */
943 load_command (arg
, from_tty
)
948 arg
= get_exec_file (1);
949 target_load (arg
, from_tty
);
952 /* This version of "load" should be usable for any target. Currently
953 it is just used for remote targets, not inftarg.c or core files,
954 on the theory that only in that case is it useful.
956 Avoiding xmodem and the like seems like a win (a) because we don't have
957 to worry about finding it, and (b) On VMS, fork() is very slow and so
958 we don't want to run a subprocess. On the other hand, I'm not sure how
959 performance compares. */
961 generic_load (filename
, from_tty
)
965 struct cleanup
*old_cleanups
;
968 time_t start_time
, end_time
; /* Start and end times of download */
969 unsigned long data_count
= 0; /* Number of bytes transferred to memory */
971 unsigned long load_offset
= 0; /* offset to add to vma for each section */
974 /* enable user to specify address for downloading as 2nd arg to load */
975 n
= sscanf(filename
, "%s 0x%lx", buf
, &load_offset
);
981 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
982 if (loadfile_bfd
== NULL
)
984 perror_with_name (filename
);
987 /* FIXME: should be checking for errors from bfd_close (for one thing,
988 on error it does not free all the storage associated with the
990 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
992 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
994 error ("\"%s\" is not an object file: %s", filename
,
995 bfd_errmsg (bfd_get_error ()));
998 start_time
= time (NULL
);
1000 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
1002 if (s
->flags
& SEC_LOAD
)
1006 size
= bfd_get_section_size_before_reloc (s
);
1010 struct cleanup
*old_chain
;
1012 unsigned long l
= size
/ 100;
1018 l
= l
> 100 ? l
: 100;
1021 buffer
= xmalloc (size
);
1022 old_chain
= make_cleanup (free
, buffer
);
1027 /* Is this really necessary? I guess it gives the user something
1028 to look at during a long download. */
1029 printf_filtered ("Loading section %s, size 0x%lx lma ",
1030 bfd_get_section_name (loadfile_bfd
, s
),
1031 (unsigned long) size
);
1032 print_address_numeric (lma
, 1, gdb_stdout
);
1033 printf_filtered ("\n");
1035 bfd_get_section_contents (loadfile_bfd
, s
, buffer
, 0, size
);
1037 sect
= bfd_get_section_name (loadfile_bfd
, s
);
1041 len
= (size
- sent
) < l
? (size
- sent
) : l
;
1043 err
= target_write_memory (lma
, buffer
, len
);
1044 if (ui_load_progress_hook
)
1045 if (ui_load_progress_hook (sect
, sent
))
1046 error ("Canceled the download");
1050 while (err
== 0 && sent
< size
);
1053 error ("Memory access error while loading section %s.",
1054 bfd_get_section_name (loadfile_bfd
, s
));
1056 do_cleanups (old_chain
);
1061 end_time
= time (NULL
);
1063 printf_filtered ("Start address 0x%lx\n", loadfile_bfd
->start_address
);
1065 /* We were doing this in remote-mips.c, I suspect it is right
1066 for other targets too. */
1067 write_pc (loadfile_bfd
->start_address
);
1069 /* FIXME: are we supposed to call symbol_file_add or not? According to
1070 a comment from remote-mips.c (where a call to symbol_file_add was
1071 commented out), making the call confuses GDB if more than one file is
1072 loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c
1075 report_transfer_performance (data_count
, start_time
, end_time
);
1077 do_cleanups (old_cleanups
);
1080 /* Report how fast the transfer went. */
1083 report_transfer_performance (data_count
, start_time
, end_time
)
1084 unsigned long data_count
;
1085 time_t start_time
, end_time
;
1087 printf_filtered ("Transfer rate: ");
1088 if (end_time
!= start_time
)
1089 printf_filtered ("%d bits/sec",
1090 (data_count
* 8) / (end_time
- start_time
));
1092 printf_filtered ("%d bits in <1 sec", (data_count
* 8));
1093 printf_filtered (".\n");
1096 /* This function allows the addition of incrementally linked object files.
1097 It does not modify any state in the target, only in the debugger. */
1101 add_symbol_file_command (args
, from_tty
)
1106 CORE_ADDR text_addr
;
1115 error ("add-symbol-file takes a file name and an address");
1118 /* Make a copy of the string that we can safely write into. */
1120 args
= strdup (args
);
1121 make_cleanup (free
, args
);
1123 /* Pick off any -option args and the file name. */
1125 while ((*args
!= '\000') && (name
== NULL
))
1127 while (isspace (*args
)) {args
++;}
1129 while ((*args
!= '\000') && !isspace (*args
)) {args
++;}
1130 if (*args
!= '\000')
1138 else if (STREQ (arg
, "-mapped"))
1142 else if (STREQ (arg
, "-readnow"))
1148 error ("unknown option `%s'", arg
);
1152 /* After picking off any options and the file name, args should be
1153 left pointing at the remainder of the command line, which should
1154 be the address expression to evaluate. */
1158 error ("add-symbol-file takes a file name");
1160 name
= tilde_expand (name
);
1161 make_cleanup (free
, name
);
1163 if (*args
!= '\000')
1165 text_addr
= parse_and_eval_address (args
);
1169 target_link(name
, &text_addr
);
1170 if (text_addr
== (CORE_ADDR
)-1)
1171 error("Don't know how to get text start location for this file");
1174 /* FIXME-32x64: Assumes text_addr fits in a long. */
1175 if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
1176 name
, local_hex_string ((unsigned long)text_addr
)))
1177 error ("Not confirmed.");
1179 symbol_file_add (name
, 0, text_addr
, 0, mapped
, readnow
);
1181 /* Getting new symbols may change our opinion about what is
1183 reinit_frame_cache ();
1187 add_shared_symbol_files_command (args
, from_tty
)
1191 #ifdef ADD_SHARED_SYMBOL_FILES
1192 ADD_SHARED_SYMBOL_FILES (args
, from_tty
);
1194 error ("This command is not available in this configuration of GDB.");
1198 /* Re-read symbols if a symbol-file has changed. */
1202 struct objfile
*objfile
;
1205 struct stat new_statbuf
;
1208 /* With the addition of shared libraries, this should be modified,
1209 the load time should be saved in the partial symbol tables, since
1210 different tables may come from different source files. FIXME.
1211 This routine should then walk down each partial symbol table
1212 and see if the symbol table that it originates from has been changed */
1214 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
) {
1215 if (objfile
->obfd
) {
1216 #ifdef IBM6000_TARGET
1217 /* If this object is from a shared library, then you should
1218 stat on the library name, not member name. */
1220 if (objfile
->obfd
->my_archive
)
1221 res
= stat (objfile
->obfd
->my_archive
->filename
, &new_statbuf
);
1224 res
= stat (objfile
->name
, &new_statbuf
);
1226 /* FIXME, should use print_sys_errmsg but it's not filtered. */
1227 printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
1231 new_modtime
= new_statbuf
.st_mtime
;
1232 if (new_modtime
!= objfile
->mtime
)
1234 struct cleanup
*old_cleanups
;
1235 struct section_offsets
*offsets
;
1237 int section_offsets_size
;
1238 char *obfd_filename
;
1240 printf_filtered ("`%s' has changed; re-reading symbols.\n",
1243 /* There are various functions like symbol_file_add,
1244 symfile_bfd_open, syms_from_objfile, etc., which might
1245 appear to do what we want. But they have various other
1246 effects which we *don't* want. So we just do stuff
1247 ourselves. We don't worry about mapped files (for one thing,
1248 any mapped file will be out of date). */
1250 /* If we get an error, blow away this objfile (not sure if
1251 that is the correct response for things like shared
1253 old_cleanups
= make_cleanup (free_objfile
, objfile
);
1254 /* We need to do this whenever any symbols go away. */
1255 make_cleanup (clear_symtab_users
, 0);
1257 /* Clean up any state BFD has sitting around. We don't need
1258 to close the descriptor but BFD lacks a way of closing the
1259 BFD without closing the descriptor. */
1260 obfd_filename
= bfd_get_filename (objfile
->obfd
);
1261 if (!bfd_close (objfile
->obfd
))
1262 error ("Can't close BFD for %s: %s", objfile
->name
,
1263 bfd_errmsg (bfd_get_error ()));
1264 objfile
->obfd
= bfd_openr (obfd_filename
, gnutarget
);
1265 if (objfile
->obfd
== NULL
)
1266 error ("Can't open %s to read symbols.", objfile
->name
);
1267 /* bfd_openr sets cacheable to true, which is what we want. */
1268 if (!bfd_check_format (objfile
->obfd
, bfd_object
))
1269 error ("Can't read symbols from %s: %s.", objfile
->name
,
1270 bfd_errmsg (bfd_get_error ()));
1272 /* Save the offsets, we will nuke them with the rest of the
1274 num_offsets
= objfile
->num_sections
;
1275 section_offsets_size
=
1276 sizeof (struct section_offsets
)
1277 + sizeof (objfile
->section_offsets
->offsets
) * num_offsets
;
1278 offsets
= (struct section_offsets
*) alloca (section_offsets_size
);
1279 memcpy (offsets
, objfile
->section_offsets
, section_offsets_size
);
1281 /* Nuke all the state that we will re-read. Much of the following
1282 code which sets things to NULL really is necessary to tell
1283 other parts of GDB that there is nothing currently there. */
1285 /* FIXME: Do we have to free a whole linked list, or is this
1287 if (objfile
->global_psymbols
.list
)
1288 mfree (objfile
->md
, objfile
->global_psymbols
.list
);
1289 memset (&objfile
-> global_psymbols
, 0,
1290 sizeof (objfile
-> global_psymbols
));
1291 if (objfile
->static_psymbols
.list
)
1292 mfree (objfile
->md
, objfile
->static_psymbols
.list
);
1293 memset (&objfile
-> static_psymbols
, 0,
1294 sizeof (objfile
-> static_psymbols
));
1296 /* Free the obstacks for non-reusable objfiles */
1297 obstack_free (&objfile
-> psymbol_cache
.cache
, 0);
1298 memset (&objfile
-> psymbol_cache
, 0,
1299 sizeof (objfile
-> psymbol_cache
));
1300 obstack_free (&objfile
-> psymbol_obstack
, 0);
1301 obstack_free (&objfile
-> symbol_obstack
, 0);
1302 obstack_free (&objfile
-> type_obstack
, 0);
1303 objfile
->sections
= NULL
;
1304 objfile
->symtabs
= NULL
;
1305 objfile
->psymtabs
= NULL
;
1306 objfile
->free_psymtabs
= NULL
;
1307 objfile
->msymbols
= NULL
;
1308 objfile
->minimal_symbol_count
= 0;
1309 objfile
->fundamental_types
= NULL
;
1310 if (objfile
-> sf
!= NULL
)
1312 (*objfile
-> sf
-> sym_finish
) (objfile
);
1315 /* We never make this a mapped file. */
1316 objfile
-> md
= NULL
;
1317 /* obstack_specify_allocation also initializes the obstack so
1319 obstack_specify_allocation (&objfile
-> psymbol_cache
.cache
, 0, 0,
1321 obstack_specify_allocation (&objfile
-> psymbol_obstack
, 0, 0,
1323 obstack_specify_allocation (&objfile
-> symbol_obstack
, 0, 0,
1325 obstack_specify_allocation (&objfile
-> type_obstack
, 0, 0,
1327 if (build_objfile_section_table (objfile
))
1329 error ("Can't find the file sections in `%s': %s",
1330 objfile
-> name
, bfd_errmsg (bfd_get_error ()));
1333 /* We use the same section offsets as from last time. I'm not
1334 sure whether that is always correct for shared libraries. */
1335 objfile
->section_offsets
= (struct section_offsets
*)
1336 obstack_alloc (&objfile
-> psymbol_obstack
, section_offsets_size
);
1337 memcpy (objfile
->section_offsets
, offsets
, section_offsets_size
);
1338 objfile
->num_sections
= num_offsets
;
1340 /* What the hell is sym_new_init for, anyway? The concept of
1341 distinguishing between the main file and additional files
1342 in this way seems rather dubious. */
1343 if (objfile
== symfile_objfile
)
1344 (*objfile
->sf
->sym_new_init
) (objfile
);
1346 (*objfile
->sf
->sym_init
) (objfile
);
1347 clear_complaints (1, 1);
1348 /* The "mainline" parameter is a hideous hack; I think leaving it
1349 zero is OK since dbxread.c also does what it needs to do if
1350 objfile->global_psymbols.size is 0. */
1351 (*objfile
->sf
->sym_read
) (objfile
, objfile
->section_offsets
, 0);
1352 if (!have_partial_symbols () && !have_full_symbols ())
1355 printf_filtered ("(no debugging symbols found)\n");
1358 objfile
-> flags
|= OBJF_SYMS
;
1360 /* We're done reading the symbol file; finish off complaints. */
1361 clear_complaints (0, 1);
1363 /* Getting new symbols may change our opinion about what is
1366 reinit_frame_cache ();
1368 /* Discard cleanups as symbol reading was successful. */
1369 discard_cleanups (old_cleanups
);
1371 /* If the mtime has changed between the time we set new_modtime
1372 and now, we *want* this to be out of date, so don't call stat
1374 objfile
->mtime
= new_modtime
;
1377 /* Call this after reading in a new symbol table to give target
1378 dependant code a crack at the new symbols. For instance, this
1379 could be used to update the values of target-specific symbols GDB
1380 needs to keep track of (such as _sigtramp, or whatever). */
1382 TARGET_SYMFILE_POSTREAD (objfile
);
1388 clear_symtab_users ();
1393 deduce_language_from_filename (filename
)
1400 else if (0 == (c
= strrchr (filename
, '.')))
1401 ; /* Get default. */
1402 else if (STREQ (c
, ".c"))
1404 else if (STREQ (c
, ".cc") || STREQ (c
, ".C") || STREQ (c
, ".cxx")
1405 || STREQ (c
, ".cpp") || STREQ (c
, ".cp") || STREQ (c
, ".c++"))
1406 return language_cplus
;
1407 else if (STREQ (c
, ".java"))
1408 return language_java
;
1409 else if (STREQ (c
, ".ch") || STREQ (c
, ".c186") || STREQ (c
, ".c286"))
1410 return language_chill
;
1411 else if (STREQ (c
, ".f") || STREQ (c
, ".F"))
1412 return language_fortran
;
1413 else if (STREQ (c
, ".mod"))
1415 else if (STREQ (c
, ".s") || STREQ (c
, ".S"))
1416 return language_asm
;
1418 return language_unknown
; /* default */
1423 Allocate and partly initialize a new symbol table. Return a pointer
1424 to it. error() if no space.
1426 Caller must set these fields:
1432 initialize any EXTRA_SYMTAB_INFO
1433 possibly free_named_symtabs (symtab->filename);
1437 allocate_symtab (filename
, objfile
)
1439 struct objfile
*objfile
;
1441 register struct symtab
*symtab
;
1443 symtab
= (struct symtab
*)
1444 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symtab
));
1445 memset (symtab
, 0, sizeof (*symtab
));
1446 symtab
-> filename
= obsavestring (filename
, strlen (filename
),
1447 &objfile
-> symbol_obstack
);
1448 symtab
-> fullname
= NULL
;
1449 symtab
-> language
= deduce_language_from_filename (filename
);
1450 symtab
-> debugformat
= obsavestring ("unknown", 7,
1451 &objfile
-> symbol_obstack
);
1453 /* Hook it to the objfile it comes from */
1455 symtab
-> objfile
= objfile
;
1456 symtab
-> next
= objfile
-> symtabs
;
1457 objfile
-> symtabs
= symtab
;
1459 #ifdef INIT_EXTRA_SYMTAB_INFO
1460 INIT_EXTRA_SYMTAB_INFO (symtab
);
1466 struct partial_symtab
*
1467 allocate_psymtab (filename
, objfile
)
1469 struct objfile
*objfile
;
1471 struct partial_symtab
*psymtab
;
1473 if (objfile
-> free_psymtabs
)
1475 psymtab
= objfile
-> free_psymtabs
;
1476 objfile
-> free_psymtabs
= psymtab
-> next
;
1479 psymtab
= (struct partial_symtab
*)
1480 obstack_alloc (&objfile
-> psymbol_obstack
,
1481 sizeof (struct partial_symtab
));
1483 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1484 psymtab
-> filename
= obsavestring (filename
, strlen (filename
),
1485 &objfile
-> psymbol_obstack
);
1486 psymtab
-> symtab
= NULL
;
1488 /* Prepend it to the psymtab list for the objfile it belongs to.
1489 Psymtabs are searched in most recent inserted -> least recent
1492 psymtab
-> objfile
= objfile
;
1493 psymtab
-> next
= objfile
-> psymtabs
;
1494 objfile
-> psymtabs
= psymtab
;
1497 struct partial_symtab
**prev_pst
;
1498 psymtab
-> objfile
= objfile
;
1499 psymtab
-> next
= NULL
;
1500 prev_pst
= &(objfile
-> psymtabs
);
1501 while ((*prev_pst
) != NULL
)
1502 prev_pst
= &((*prev_pst
) -> next
);
1503 (*prev_pst
) = psymtab
;
1511 discard_psymtab (pst
)
1512 struct partial_symtab
*pst
;
1514 struct partial_symtab
**prev_pst
;
1517 Empty psymtabs happen as a result of header files which don't
1518 have any symbols in them. There can be a lot of them. But this
1519 check is wrong, in that a psymtab with N_SLINE entries but
1520 nothing else is not empty, but we don't realize that. Fixing
1521 that without slowing things down might be tricky. */
1523 /* First, snip it out of the psymtab chain */
1525 prev_pst
= &(pst
->objfile
->psymtabs
);
1526 while ((*prev_pst
) != pst
)
1527 prev_pst
= &((*prev_pst
)->next
);
1528 (*prev_pst
) = pst
->next
;
1530 /* Next, put it on a free list for recycling */
1532 pst
->next
= pst
->objfile
->free_psymtabs
;
1533 pst
->objfile
->free_psymtabs
= pst
;
1537 /* Reset all data structures in gdb which may contain references to symbol
1541 clear_symtab_users ()
1543 /* Someday, we should do better than this, by only blowing away
1544 the things that really need to be blown. */
1545 clear_value_history ();
1547 clear_internalvars ();
1548 breakpoint_re_set ();
1549 set_default_breakpoint (0, 0, 0, 0);
1550 current_source_symtab
= 0;
1551 current_source_line
= 0;
1552 clear_pc_function_cache ();
1553 target_new_objfile (NULL
);
1556 /* clear_symtab_users_once:
1558 This function is run after symbol reading, or from a cleanup.
1559 If an old symbol table was obsoleted, the old symbol table
1560 has been blown away, but the other GDB data structures that may
1561 reference it have not yet been cleared or re-directed. (The old
1562 symtab was zapped, and the cleanup queued, in free_named_symtab()
1565 This function can be queued N times as a cleanup, or called
1566 directly; it will do all the work the first time, and then will be a
1567 no-op until the next time it is queued. This works by bumping a
1568 counter at queueing time. Much later when the cleanup is run, or at
1569 the end of symbol processing (in case the cleanup is discarded), if
1570 the queued count is greater than the "done-count", we do the work
1571 and set the done-count to the queued count. If the queued count is
1572 less than or equal to the done-count, we just ignore the call. This
1573 is needed because reading a single .o file will often replace many
1574 symtabs (one per .h file, for example), and we don't want to reset
1575 the breakpoints N times in the user's face.
1577 The reason we both queue a cleanup, and call it directly after symbol
1578 reading, is because the cleanup protects us in case of errors, but is
1579 discarded if symbol reading is successful. */
1582 /* FIXME: As free_named_symtabs is currently a big noop this function
1583 is no longer needed. */
1585 clear_symtab_users_once
PARAMS ((void));
1587 static int clear_symtab_users_queued
;
1588 static int clear_symtab_users_done
;
1591 clear_symtab_users_once ()
1593 /* Enforce once-per-`do_cleanups'-semantics */
1594 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
1596 clear_symtab_users_done
= clear_symtab_users_queued
;
1598 clear_symtab_users ();
1602 /* Delete the specified psymtab, and any others that reference it. */
1605 cashier_psymtab (pst
)
1606 struct partial_symtab
*pst
;
1608 struct partial_symtab
*ps
, *pprev
= NULL
;
1611 /* Find its previous psymtab in the chain */
1612 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1619 /* Unhook it from the chain. */
1620 if (ps
== pst
->objfile
->psymtabs
)
1621 pst
->objfile
->psymtabs
= ps
->next
;
1623 pprev
->next
= ps
->next
;
1625 /* FIXME, we can't conveniently deallocate the entries in the
1626 partial_symbol lists (global_psymbols/static_psymbols) that
1627 this psymtab points to. These just take up space until all
1628 the psymtabs are reclaimed. Ditto the dependencies list and
1629 filename, which are all in the psymbol_obstack. */
1631 /* We need to cashier any psymtab that has this one as a dependency... */
1633 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
) {
1634 for (i
= 0; i
< ps
->number_of_dependencies
; i
++) {
1635 if (ps
->dependencies
[i
] == pst
) {
1636 cashier_psymtab (ps
);
1637 goto again
; /* Must restart, chain has been munged. */
1644 /* If a symtab or psymtab for filename NAME is found, free it along
1645 with any dependent breakpoints, displays, etc.
1646 Used when loading new versions of object modules with the "add-file"
1647 command. This is only called on the top-level symtab or psymtab's name;
1648 it is not called for subsidiary files such as .h files.
1650 Return value is 1 if we blew away the environment, 0 if not.
1651 FIXME. The return valu appears to never be used.
1653 FIXME. I think this is not the best way to do this. We should
1654 work on being gentler to the environment while still cleaning up
1655 all stray pointers into the freed symtab. */
1658 free_named_symtabs (name
)
1662 /* FIXME: With the new method of each objfile having it's own
1663 psymtab list, this function needs serious rethinking. In particular,
1664 why was it ever necessary to toss psymtabs with specific compilation
1665 unit filenames, as opposed to all psymtabs from a particular symbol
1667 Well, the answer is that some systems permit reloading of particular
1668 compilation units. We want to blow away any old info about these
1669 compilation units, regardless of which objfiles they arrived in. --gnu. */
1671 register struct symtab
*s
;
1672 register struct symtab
*prev
;
1673 register struct partial_symtab
*ps
;
1674 struct blockvector
*bv
;
1677 /* We only wack things if the symbol-reload switch is set. */
1678 if (!symbol_reloading
)
1681 /* Some symbol formats have trouble providing file names... */
1682 if (name
== 0 || *name
== '\0')
1685 /* Look for a psymtab with the specified name. */
1688 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
) {
1689 if (STREQ (name
, ps
->filename
)) {
1690 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
1691 goto again2
; /* Must restart, chain has been munged */
1695 /* Look for a symtab with the specified name. */
1697 for (s
= symtab_list
; s
; s
= s
->next
)
1699 if (STREQ (name
, s
->filename
))
1706 if (s
== symtab_list
)
1707 symtab_list
= s
->next
;
1709 prev
->next
= s
->next
;
1711 /* For now, queue a delete for all breakpoints, displays, etc., whether
1712 or not they depend on the symtab being freed. This should be
1713 changed so that only those data structures affected are deleted. */
1715 /* But don't delete anything if the symtab is empty.
1716 This test is necessary due to a bug in "dbxread.c" that
1717 causes empty symtabs to be created for N_SO symbols that
1718 contain the pathname of the object file. (This problem
1719 has been fixed in GDB 3.9x). */
1721 bv
= BLOCKVECTOR (s
);
1722 if (BLOCKVECTOR_NBLOCKS (bv
) > 2
1723 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
1724 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
1726 complain (&oldsyms_complaint
, name
);
1728 clear_symtab_users_queued
++;
1729 make_cleanup (clear_symtab_users_once
, 0);
1732 complain (&empty_symtab_complaint
, name
);
1739 /* It is still possible that some breakpoints will be affected
1740 even though no symtab was found, since the file might have
1741 been compiled without debugging, and hence not be associated
1742 with a symtab. In order to handle this correctly, we would need
1743 to keep a list of text address ranges for undebuggable files.
1744 For now, we do nothing, since this is a fairly obscure case. */
1748 /* FIXME, what about the minimal symbol table? */
1755 /* Allocate and partially fill a partial symtab. It will be
1756 completely filled at the end of the symbol list.
1758 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1759 is the address relative to which its symbols are (incremental) or 0
1763 struct partial_symtab
*
1764 start_psymtab_common (objfile
, section_offsets
,
1765 filename
, textlow
, global_syms
, static_syms
)
1766 struct objfile
*objfile
;
1767 struct section_offsets
*section_offsets
;
1770 struct partial_symbol
**global_syms
;
1771 struct partial_symbol
**static_syms
;
1773 struct partial_symtab
*psymtab
;
1775 psymtab
= allocate_psymtab (filename
, objfile
);
1776 psymtab
-> section_offsets
= section_offsets
;
1777 psymtab
-> textlow
= textlow
;
1778 psymtab
-> texthigh
= psymtab
-> textlow
; /* default */
1779 psymtab
-> globals_offset
= global_syms
- objfile
-> global_psymbols
.list
;
1780 psymtab
-> statics_offset
= static_syms
- objfile
-> static_psymbols
.list
;
1784 /* Add a symbol with a long value to a psymtab.
1785 Since one arg is a struct, we pass in a ptr and deref it (sigh). */
1788 add_psymbol_to_list (name
, namelength
, namespace, class, list
, val
, coreaddr
,
1792 namespace_enum
namespace;
1793 enum address_class
class;
1794 struct psymbol_allocation_list
*list
;
1795 long val
; /* Value as a long */
1796 CORE_ADDR coreaddr
; /* Value as a CORE_ADDR */
1797 enum language language
;
1798 struct objfile
*objfile
;
1800 register struct partial_symbol
*psym
;
1801 char *buf
= alloca (namelength
+ 1);
1802 /* psymbol is static so that there will be no uninitialized gaps in the
1803 structure which might contain random data, causing cache misses in
1805 static struct partial_symbol psymbol
;
1807 /* Create local copy of the partial symbol */
1808 memcpy (buf
, name
, namelength
);
1809 buf
[namelength
] = '\0';
1810 SYMBOL_NAME (&psymbol
) = bcache (buf
, namelength
+ 1, &objfile
->psymbol_cache
);
1811 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
1814 SYMBOL_VALUE (&psymbol
) = val
;
1818 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1820 SYMBOL_SECTION (&psymbol
) = 0;
1821 SYMBOL_LANGUAGE (&psymbol
) = language
;
1822 PSYMBOL_NAMESPACE (&psymbol
) = namespace;
1823 PSYMBOL_CLASS (&psymbol
) = class;
1824 SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol
, language
);
1826 /* Stash the partial symbol away in the cache */
1827 psym
= bcache (&psymbol
, sizeof (struct partial_symbol
), &objfile
->psymbol_cache
);
1829 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1830 if (list
->next
>= list
->list
+ list
->size
)
1832 extend_psymbol_list (list
, objfile
);
1834 *list
->next
++ = psym
;
1835 OBJSTAT (objfile
, n_psyms
++);
1838 /* Initialize storage for partial symbols. */
1841 init_psymbol_list (objfile
, total_symbols
)
1842 struct objfile
*objfile
;
1845 /* Free any previously allocated psymbol lists. */
1847 if (objfile
-> global_psymbols
.list
)
1849 mfree (objfile
-> md
, (PTR
)objfile
-> global_psymbols
.list
);
1851 if (objfile
-> static_psymbols
.list
)
1853 mfree (objfile
-> md
, (PTR
)objfile
-> static_psymbols
.list
);
1856 /* Current best guess is that approximately a twentieth
1857 of the total symbols (in a debugging file) are global or static
1860 objfile
-> global_psymbols
.size
= total_symbols
/ 10;
1861 objfile
-> static_psymbols
.size
= total_symbols
/ 10;
1863 if (objfile
-> global_psymbols
.size
> 0)
1865 objfile
-> global_psymbols
.next
=
1866 objfile
-> global_psymbols
.list
= (struct partial_symbol
**)
1867 xmmalloc (objfile
-> md
, (objfile
-> global_psymbols
.size
1868 * sizeof (struct partial_symbol
*)));
1870 if (objfile
-> static_psymbols
.size
> 0)
1872 objfile
-> static_psymbols
.next
=
1873 objfile
-> static_psymbols
.list
= (struct partial_symbol
**)
1874 xmmalloc (objfile
-> md
, (objfile
-> static_psymbols
.size
1875 * sizeof (struct partial_symbol
*)));
1880 The following code implements an abstraction for debugging overlay sections.
1882 The target model is as follows:
1883 1) The gnu linker will permit multiple sections to be mapped into the
1884 same VMA, each with its own unique LMA (or load address).
1885 2) It is assumed that some runtime mechanism exists for mapping the
1886 sections, one by one, from the load address into the VMA address.
1887 3) This code provides a mechanism for gdb to keep track of which
1888 sections should be considered to be mapped from the VMA to the LMA.
1889 This information is used for symbol lookup, and memory read/write.
1890 For instance, if a section has been mapped then its contents
1891 should be read from the VMA, otherwise from the LMA.
1893 Two levels of debugger support for overlays are available. One is
1894 "manual", in which the debugger relies on the user to tell it which
1895 overlays are currently mapped. This level of support is
1896 implemented entirely in the core debugger, and the information about
1897 whether a section is mapped is kept in the objfile->obj_section table.
1899 The second level of support is "automatic", and is only available if
1900 the target-specific code provides functionality to read the target's
1901 overlay mapping table, and translate its contents for the debugger
1902 (by updating the mapped state information in the obj_section tables).
1904 The interface is as follows:
1906 overlay map <name> -- tell gdb to consider this section mapped
1907 overlay unmap <name> -- tell gdb to consider this section unmapped
1908 overlay list -- list the sections that GDB thinks are mapped
1909 overlay read-target -- get the target's state of what's mapped
1910 overlay off/manual/auto -- set overlay debugging state
1911 Functional interface:
1912 find_pc_mapped_section(pc): if the pc is in the range of a mapped
1913 section, return that section.
1914 find_pc_overlay(pc): find any overlay section that contains
1915 the pc, either in its VMA or its LMA
1916 overlay_is_mapped(sect): true if overlay is marked as mapped
1917 section_is_overlay(sect): true if section's VMA != LMA
1918 pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA
1919 pc_in_unmapped_range(...): true if pc belongs to section's LMA
1920 overlay_mapped_address(...): map an address from section's LMA to VMA
1921 overlay_unmapped_address(...): map an address from section's VMA to LMA
1922 symbol_overlayed_address(...): Return a "current" address for symbol:
1923 either in VMA or LMA depending on whether
1924 the symbol's section is currently mapped
1927 /* Overlay debugging state: */
1929 int overlay_debugging
= 0; /* 0 == off, 1 == manual, -1 == auto */
1930 int overlay_cache_invalid
= 0; /* True if need to refresh mapped state */
1932 /* Target vector for refreshing overlay mapped state */
1933 static void simple_overlay_update
PARAMS ((struct obj_section
*));
1934 void (*target_overlay_update
) PARAMS ((struct obj_section
*))
1935 = simple_overlay_update
;
1937 /* Function: section_is_overlay (SECTION)
1938 Returns true if SECTION has VMA not equal to LMA, ie.
1939 SECTION is loaded at an address different from where it will "run". */
1942 section_is_overlay (section
)
1945 if (overlay_debugging
)
1946 if (section
&& section
->lma
!= 0 &&
1947 section
->vma
!= section
->lma
)
1953 /* Function: overlay_invalidate_all (void)
1954 Invalidate the mapped state of all overlay sections (mark it as stale). */
1957 overlay_invalidate_all ()
1959 struct objfile
*objfile
;
1960 struct obj_section
*sect
;
1962 ALL_OBJSECTIONS (objfile
, sect
)
1963 if (section_is_overlay (sect
->the_bfd_section
))
1964 sect
->ovly_mapped
= -1;
1967 /* Function: overlay_is_mapped (SECTION)
1968 Returns true if section is an overlay, and is currently mapped.
1969 Private: public access is thru function section_is_mapped.
1971 Access to the ovly_mapped flag is restricted to this function, so
1972 that we can do automatic update. If the global flag
1973 OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call
1974 overlay_invalidate_all. If the mapped state of the particular
1975 section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */
1978 overlay_is_mapped (osect
)
1979 struct obj_section
*osect
;
1981 if (osect
== 0 || !section_is_overlay (osect
->the_bfd_section
))
1984 switch (overlay_debugging
)
1987 case 0: return 0; /* overlay debugging off */
1988 case -1: /* overlay debugging automatic */
1989 /* Unles there is a target_overlay_update function,
1990 there's really nothing useful to do here (can't really go auto) */
1991 if (target_overlay_update
)
1993 if (overlay_cache_invalid
)
1995 overlay_invalidate_all ();
1996 overlay_cache_invalid
= 0;
1998 if (osect
->ovly_mapped
== -1)
1999 (*target_overlay_update
) (osect
);
2001 /* fall thru to manual case */
2002 case 1: /* overlay debugging manual */
2003 return osect
->ovly_mapped
== 1;
2007 /* Function: section_is_mapped
2008 Returns true if section is an overlay, and is currently mapped. */
2011 section_is_mapped (section
)
2014 struct objfile
*objfile
;
2015 struct obj_section
*osect
;
2017 if (overlay_debugging
)
2018 if (section
&& section_is_overlay (section
))
2019 ALL_OBJSECTIONS (objfile
, osect
)
2020 if (osect
->the_bfd_section
== section
)
2021 return overlay_is_mapped (osect
);
2026 /* Function: pc_in_unmapped_range
2027 If PC falls into the lma range of SECTION, return true, else false. */
2030 pc_in_unmapped_range (pc
, section
)
2036 if (overlay_debugging
)
2037 if (section
&& section_is_overlay (section
))
2039 size
= bfd_get_section_size_before_reloc (section
);
2040 if (section
->lma
<= pc
&& pc
< section
->lma
+ size
)
2046 /* Function: pc_in_mapped_range
2047 If PC falls into the vma range of SECTION, return true, else false. */
2050 pc_in_mapped_range (pc
, section
)
2056 if (overlay_debugging
)
2057 if (section
&& section_is_overlay (section
))
2059 size
= bfd_get_section_size_before_reloc (section
);
2060 if (section
->vma
<= pc
&& pc
< section
->vma
+ size
)
2066 /* Function: overlay_unmapped_address (PC, SECTION)
2067 Returns the address corresponding to PC in the unmapped (load) range.
2068 May be the same as PC. */
2071 overlay_unmapped_address (pc
, section
)
2075 if (overlay_debugging
)
2076 if (section
&& section_is_overlay (section
) &&
2077 pc_in_mapped_range (pc
, section
))
2078 return pc
+ section
->lma
- section
->vma
;
2083 /* Function: overlay_mapped_address (PC, SECTION)
2084 Returns the address corresponding to PC in the mapped (runtime) range.
2085 May be the same as PC. */
2088 overlay_mapped_address (pc
, section
)
2092 if (overlay_debugging
)
2093 if (section
&& section_is_overlay (section
) &&
2094 pc_in_unmapped_range (pc
, section
))
2095 return pc
+ section
->vma
- section
->lma
;
2101 /* Function: symbol_overlayed_address
2102 Return one of two addresses (relative to the VMA or to the LMA),
2103 depending on whether the section is mapped or not. */
2106 symbol_overlayed_address (address
, section
)
2110 if (overlay_debugging
)
2112 /* If the symbol has no section, just return its regular address. */
2115 /* If the symbol's section is not an overlay, just return its address */
2116 if (!section_is_overlay (section
))
2118 /* If the symbol's section is mapped, just return its address */
2119 if (section_is_mapped (section
))
2122 * HOWEVER: if the symbol is in an overlay section which is NOT mapped,
2123 * then return its LOADED address rather than its vma address!!
2125 return overlay_unmapped_address (address
, section
);
2130 /* Function: find_pc_overlay (PC)
2131 Return the best-match overlay section for PC:
2132 If PC matches a mapped overlay section's VMA, return that section.
2133 Else if PC matches an unmapped section's VMA, return that section.
2134 Else if PC matches an unmapped section's LMA, return that section. */
2137 find_pc_overlay (pc
)
2140 struct objfile
*objfile
;
2141 struct obj_section
*osect
, *best_match
= NULL
;
2143 if (overlay_debugging
)
2144 ALL_OBJSECTIONS (objfile
, osect
)
2145 if (section_is_overlay (osect
->the_bfd_section
))
2147 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
))
2149 if (overlay_is_mapped (osect
))
2150 return osect
->the_bfd_section
;
2154 else if (pc_in_unmapped_range (pc
, osect
->the_bfd_section
))
2157 return best_match
? best_match
->the_bfd_section
: NULL
;
2160 /* Function: find_pc_mapped_section (PC)
2161 If PC falls into the VMA address range of an overlay section that is
2162 currently marked as MAPPED, return that section. Else return NULL. */
2165 find_pc_mapped_section (pc
)
2168 struct objfile
*objfile
;
2169 struct obj_section
*osect
;
2171 if (overlay_debugging
)
2172 ALL_OBJSECTIONS (objfile
, osect
)
2173 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
) &&
2174 overlay_is_mapped (osect
))
2175 return osect
->the_bfd_section
;
2180 /* Function: list_overlays_command
2181 Print a list of mapped sections and their PC ranges */
2184 list_overlays_command (args
, from_tty
)
2189 struct objfile
*objfile
;
2190 struct obj_section
*osect
;
2192 if (overlay_debugging
)
2193 ALL_OBJSECTIONS (objfile
, osect
)
2194 if (overlay_is_mapped (osect
))
2200 vma
= bfd_section_vma (objfile
->obfd
, osect
->the_bfd_section
);
2201 lma
= bfd_section_lma (objfile
->obfd
, osect
->the_bfd_section
);
2202 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2203 name
= bfd_section_name (objfile
->obfd
, osect
->the_bfd_section
);
2204 printf_filtered ("Section %s, loaded at %08x - %08x, ",
2205 name
, lma
, lma
+ size
);
2206 printf_filtered ("mapped at %08x - %08x\n",
2211 printf_filtered ("No sections are mapped.\n");
2214 /* Function: map_overlay_command
2215 Mark the named section as mapped (ie. residing at its VMA address). */
2218 map_overlay_command (args
, from_tty
)
2222 struct objfile
*objfile
, *objfile2
;
2223 struct obj_section
*sec
, *sec2
;
2226 if (!overlay_debugging
)
2227 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2229 if (args
== 0 || *args
== 0)
2230 error ("Argument required: name of an overlay section");
2232 /* First, find a section matching the user supplied argument */
2233 ALL_OBJSECTIONS (objfile
, sec
)
2234 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2236 /* Now, check to see if the section is an overlay. */
2237 bfdsec
= sec
->the_bfd_section
;
2238 if (!section_is_overlay (bfdsec
))
2239 continue; /* not an overlay section */
2241 /* Mark the overlay as "mapped" */
2242 sec
->ovly_mapped
= 1;
2244 /* Next, make a pass and unmap any sections that are
2245 overlapped by this new section: */
2246 ALL_OBJSECTIONS (objfile2
, sec2
)
2247 if (sec2
->ovly_mapped
&&
2249 sec
->the_bfd_section
!= sec2
->the_bfd_section
&&
2250 (pc_in_mapped_range (sec2
->addr
, sec
->the_bfd_section
) ||
2251 pc_in_mapped_range (sec2
->endaddr
, sec
->the_bfd_section
)))
2254 printf_filtered ("Note: section %s unmapped by overlap\n",
2255 bfd_section_name (objfile
->obfd
,
2256 sec2
->the_bfd_section
));
2257 sec2
->ovly_mapped
= 0; /* sec2 overlaps sec: unmap sec2 */
2261 error ("No overlay section called %s", args
);
2264 /* Function: unmap_overlay_command
2265 Mark the overlay section as unmapped
2266 (ie. resident in its LMA address range, rather than the VMA range). */
2269 unmap_overlay_command (args
, from_tty
)
2273 struct objfile
*objfile
;
2274 struct obj_section
*sec
;
2276 if (!overlay_debugging
)
2277 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2279 if (args
== 0 || *args
== 0)
2280 error ("Argument required: name of an overlay section");
2282 /* First, find a section matching the user supplied argument */
2283 ALL_OBJSECTIONS (objfile
, sec
)
2284 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2286 if (!sec
->ovly_mapped
)
2287 error ("Section %s is not mapped", args
);
2288 sec
->ovly_mapped
= 0;
2291 error ("No overlay section called %s", args
);
2294 /* Function: overlay_auto_command
2295 A utility command to turn on overlay debugging.
2296 Possibly this should be done via a set/show command. */
2299 overlay_auto_command (args
, from_tty
)
2301 overlay_debugging
= -1;
2303 printf_filtered ("Automatic overlay debugging enabled.");
2306 /* Function: overlay_manual_command
2307 A utility command to turn on overlay debugging.
2308 Possibly this should be done via a set/show command. */
2311 overlay_manual_command (args
, from_tty
)
2313 overlay_debugging
= 1;
2315 printf_filtered ("Overlay debugging enabled.");
2318 /* Function: overlay_off_command
2319 A utility command to turn on overlay debugging.
2320 Possibly this should be done via a set/show command. */
2323 overlay_off_command (args
, from_tty
)
2325 overlay_debugging
= 0;
2327 printf_filtered ("Overlay debugging disabled.");
2331 overlay_load_command (args
, from_tty
)
2333 if (target_overlay_update
)
2334 (*target_overlay_update
) (NULL
);
2336 error ("This target does not know how to read its overlay state.");
2339 /* Function: overlay_command
2340 A place-holder for a mis-typed command */
2342 /* Command list chain containing all defined "overlay" subcommands. */
2343 struct cmd_list_element
*overlaylist
;
2346 overlay_command (args
, from_tty
)
2351 ("\"overlay\" must be followed by the name of an overlay command.\n");
2352 help_list (overlaylist
, "overlay ", -1, gdb_stdout
);
2356 /* Target Overlays for the "Simplest" overlay manager:
2358 This is GDB's default target overlay layer. It works with the
2359 minimal overlay manager supplied as an example by Cygnus. The
2360 entry point is via a function pointer "target_overlay_update",
2361 so targets that use a different runtime overlay manager can
2362 substitute their own overlay_update function and take over the
2365 The overlay_update function pokes around in the target's data structures
2366 to see what overlays are mapped, and updates GDB's overlay mapping with
2369 In this simple implementation, the target data structures are as follows:
2370 unsigned _novlys; /# number of overlay sections #/
2371 unsigned _ovly_table[_novlys][4] = {
2372 {VMA, SIZE, LMA, MAPPED}, /# one entry per overlay section #/
2373 {..., ..., ..., ...},
2375 unsigned _novly_regions; /# number of overlay regions #/
2376 unsigned _ovly_region_table[_novly_regions][3] = {
2377 {VMA, SIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/
2380 These functions will attempt to update GDB's mappedness state in the
2381 symbol section table, based on the target's mappedness state.
2383 To do this, we keep a cached copy of the target's _ovly_table, and
2384 attempt to detect when the cached copy is invalidated. The main
2385 entry point is "simple_overlay_update(SECT), which looks up SECT in
2386 the cached table and re-reads only the entry for that section from
2387 the target (whenever possible).
2390 /* Cached, dynamically allocated copies of the target data structures: */
2391 static unsigned (*cache_ovly_table
)[4] = 0;
2393 static unsigned (*cache_ovly_region_table
)[3] = 0;
2395 static unsigned cache_novlys
= 0;
2397 static unsigned cache_novly_regions
= 0;
2399 static CORE_ADDR cache_ovly_table_base
= 0;
2401 static CORE_ADDR cache_ovly_region_table_base
= 0;
2403 enum ovly_index
{ VMA
, SIZE
, LMA
, MAPPED
};
2404 #define TARGET_INT_BYTES (TARGET_INT_BIT / TARGET_CHAR_BIT)
2406 /* Throw away the cached copy of _ovly_table */
2408 simple_free_overlay_table ()
2410 if (cache_ovly_table
)
2411 free(cache_ovly_table
);
2413 cache_ovly_table
= NULL
;
2414 cache_ovly_table_base
= 0;
2418 /* Throw away the cached copy of _ovly_region_table */
2420 simple_free_overlay_region_table ()
2422 if (cache_ovly_region_table
)
2423 free(cache_ovly_region_table
);
2424 cache_novly_regions
= 0;
2425 cache_ovly_region_table
= NULL
;
2426 cache_ovly_region_table_base
= 0;
2430 /* Read an array of ints from the target into a local buffer.
2431 Convert to host order. int LEN is number of ints */
2433 read_target_int_array (memaddr
, myaddr
, len
)
2435 unsigned int *myaddr
;
2438 char *buf
= alloca (len
* TARGET_INT_BYTES
);
2441 read_memory (memaddr
, buf
, len
* TARGET_INT_BYTES
);
2442 for (i
= 0; i
< len
; i
++)
2443 myaddr
[i
] = extract_unsigned_integer (TARGET_INT_BYTES
* i
+ buf
,
2447 /* Find and grab a copy of the target _ovly_table
2448 (and _novlys, which is needed for the table's size) */
2450 simple_read_overlay_table ()
2452 struct minimal_symbol
*msym
;
2454 simple_free_overlay_table ();
2455 msym
= lookup_minimal_symbol ("_novlys", 0, 0);
2457 cache_novlys
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
2459 return 0; /* failure */
2460 cache_ovly_table
= (void *) xmalloc (cache_novlys
* sizeof(*cache_ovly_table
));
2461 if (cache_ovly_table
!= NULL
)
2463 msym
= lookup_minimal_symbol ("_ovly_table", 0, 0);
2466 cache_ovly_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
2467 read_target_int_array (cache_ovly_table_base
,
2468 (int *) cache_ovly_table
,
2472 return 0; /* failure */
2475 return 0; /* failure */
2476 return 1; /* SUCCESS */
2480 /* Find and grab a copy of the target _ovly_region_table
2481 (and _novly_regions, which is needed for the table's size) */
2483 simple_read_overlay_region_table ()
2485 struct minimal_symbol
*msym
;
2487 simple_free_overlay_region_table ();
2488 msym
= lookup_minimal_symbol ("_novly_regions", 0, 0);
2490 cache_novly_regions
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
2492 return 0; /* failure */
2493 cache_ovly_region_table
= (void *) xmalloc (cache_novly_regions
* 12);
2494 if (cache_ovly_region_table
!= NULL
)
2496 msym
= lookup_minimal_symbol ("_ovly_region_table", 0, 0);
2499 cache_ovly_region_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
2500 read_target_int_array (cache_ovly_region_table_base
,
2501 (int *) cache_ovly_region_table
,
2502 cache_novly_regions
* 3);
2505 return 0; /* failure */
2508 return 0; /* failure */
2509 return 1; /* SUCCESS */
2513 /* Function: simple_overlay_update_1
2514 A helper function for simple_overlay_update. Assuming a cached copy
2515 of _ovly_table exists, look through it to find an entry whose vma,
2516 lma and size match those of OSECT. Re-read the entry and make sure
2517 it still matches OSECT (else the table may no longer be valid).
2518 Set OSECT's mapped state to match the entry. Return: 1 for
2519 success, 0 for failure. */
2522 simple_overlay_update_1 (osect
)
2523 struct obj_section
*osect
;
2527 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2528 for (i
= 0; i
< cache_novlys
; i
++)
2529 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2530 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2531 cache_ovly_table[i][SIZE] == size */)
2533 read_target_int_array (cache_ovly_table_base
+ i
* TARGET_INT_BYTES
,
2534 (int *) &cache_ovly_table
[i
], 4);
2535 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2536 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2537 cache_ovly_table[i][SIZE] == size */)
2539 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
2542 else /* Warning! Warning! Target's ovly table has changed! */
2548 /* Function: simple_overlay_update
2549 If OSECT is NULL, then update all sections' mapped state
2550 (after re-reading the entire target _ovly_table).
2551 If OSECT is non-NULL, then try to find a matching entry in the
2552 cached ovly_table and update only OSECT's mapped state.
2553 If a cached entry can't be found or the cache isn't valid, then
2554 re-read the entire cache, and go ahead and update all sections. */
2557 simple_overlay_update (osect
)
2558 struct obj_section
*osect
;
2560 struct objfile
*objfile
;
2562 /* Were we given an osect to look up? NULL means do all of them. */
2564 /* Have we got a cached copy of the target's overlay table? */
2565 if (cache_ovly_table
!= NULL
)
2566 /* Does its cached location match what's currently in the symtab? */
2567 if (cache_ovly_table_base
==
2568 SYMBOL_VALUE_ADDRESS (lookup_minimal_symbol ("_ovly_table", 0, 0)))
2569 /* Then go ahead and try to look up this single section in the cache */
2570 if (simple_overlay_update_1 (osect
))
2571 /* Found it! We're done. */
2574 /* Cached table no good: need to read the entire table anew.
2575 Or else we want all the sections, in which case it's actually
2576 more efficient to read the whole table in one block anyway. */
2578 if (simple_read_overlay_table () == 0) /* read failed? No table? */
2580 warning ("Failed to read the target overlay mapping table.");
2583 /* Now may as well update all sections, even if only one was requested. */
2584 ALL_OBJSECTIONS (objfile
, osect
)
2585 if (section_is_overlay (osect
->the_bfd_section
))
2589 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2590 for (i
= 0; i
< cache_novlys
; i
++)
2591 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
2592 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
2593 cache_ovly_table[i][SIZE] == size */)
2594 { /* obj_section matches i'th entry in ovly_table */
2595 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
2596 break; /* finished with inner for loop: break out */
2603 _initialize_symfile ()
2605 struct cmd_list_element
*c
;
2607 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
,
2608 "Load symbol table from executable file FILE.\n\
2609 The `file' command can also load symbol tables, as well as setting the file\n\
2610 to execute.", &cmdlist
);
2611 c
->completer
= filename_completer
;
2613 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
,
2614 "Usage: add-symbol-file FILE ADDR\n\
2615 Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
2616 ADDR is the starting address of the file's text.",
2618 c
->completer
= filename_completer
;
2620 c
= add_cmd ("add-shared-symbol-files", class_files
,
2621 add_shared_symbol_files_command
,
2622 "Load the symbols from shared objects in the dynamic linker's link map.",
2624 c
= add_alias_cmd ("assf", "add-shared-symbol-files", class_files
, 1,
2627 c
= add_cmd ("load", class_files
, load_command
,
2628 "Dynamically load FILE into the running program, and record its symbols\n\
2629 for access from GDB.", &cmdlist
);
2630 c
->completer
= filename_completer
;
2633 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
2634 (char *)&symbol_reloading
,
2635 "Set dynamic symbol table reloading multiple times in one run.",
2639 add_prefix_cmd ("overlay", class_support
, overlay_command
,
2640 "Commands for debugging overlays.", &overlaylist
,
2641 "overlay ", 0, &cmdlist
);
2643 add_com_alias ("ovly", "overlay", class_alias
, 1);
2644 add_com_alias ("ov", "overlay", class_alias
, 1);
2646 add_cmd ("map-overlay", class_support
, map_overlay_command
,
2647 "Assert that an overlay section is mapped.", &overlaylist
);
2649 add_cmd ("unmap-overlay", class_support
, unmap_overlay_command
,
2650 "Assert that an overlay section is unmapped.", &overlaylist
);
2652 add_cmd ("list-overlays", class_support
, list_overlays_command
,
2653 "List mappings of overlay sections.", &overlaylist
);
2655 add_cmd ("manual", class_support
, overlay_manual_command
,
2656 "Enable overlay debugging.", &overlaylist
);
2657 add_cmd ("off", class_support
, overlay_off_command
,
2658 "Disable overlay debugging.", &overlaylist
);
2659 add_cmd ("auto", class_support
, overlay_auto_command
,
2660 "Enable automatic overlay debugging.", &overlaylist
);
2661 add_cmd ("load-target", class_support
, overlay_load_command
,
2662 "Read the overlay mapping state from the target.", &overlaylist
);