1 /* Generic symbol file reading for the GNU debugger, GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998
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,
21 Boston, MA 02111-1307, USA. */
33 #include "breakpoint.h"
35 #include "complaints.h"
37 #include "inferior.h" /* for write_pc */
38 #include "gdb-stabs.h"
42 #include <sys/types.h>
44 #include "gdb_string.h"
55 /* Some HP-UX related globals to clear when a new "main"
56 symbol file is loaded. HP-specific. */
58 extern int hp_som_som_object_present
;
59 extern int hp_cxx_exception_support_initialized
;
60 #define RESET_HP_UX_GLOBALS() do {\
61 hp_som_som_object_present = 0; /* indicates HP-compiled code */ \
62 hp_cxx_exception_support_initialized = 0; /* must reinitialize exception stuff */ \
66 int (*ui_load_progress_hook
) (const char *section
, unsigned long num
);
67 void (*show_load_progress
) (const char *section
,
68 unsigned long section_sent
,
69 unsigned long section_size
,
70 unsigned long total_sent
,
71 unsigned long total_size
);
72 void (*pre_add_symbol_hook
) PARAMS ((char *));
73 void (*post_add_symbol_hook
) PARAMS ((void));
74 void (*target_new_objfile_hook
) PARAMS ((struct objfile
*));
76 /* Global variables owned by this file */
77 int readnow_symbol_files
; /* Read full symbols immediately */
79 struct complaint oldsyms_complaint
=
81 "Replacing old symbols for `%s'", 0, 0
84 struct complaint empty_symtab_complaint
=
86 "Empty symbol table found for `%s'", 0, 0
89 struct complaint unknown_option_complaint
=
91 "Unknown option `%s' ignored", 0, 0
94 /* External variables and functions referenced. */
96 extern int info_verbose
;
98 extern void report_transfer_performance
PARAMS ((unsigned long,
101 /* Functions this file defines */
104 static int simple_read_overlay_region_table
PARAMS ((void));
105 static void simple_free_overlay_region_table
PARAMS ((void));
108 static void set_initial_language
PARAMS ((void));
110 static void load_command
PARAMS ((char *, int));
112 static void add_symbol_file_command
PARAMS ((char *, int));
114 static void add_shared_symbol_files_command
PARAMS ((char *, int));
116 static void cashier_psymtab
PARAMS ((struct partial_symtab
*));
118 static int compare_psymbols
PARAMS ((const void *, const void *));
120 static int compare_symbols
PARAMS ((const void *, const void *));
122 bfd
*symfile_bfd_open
PARAMS ((char *));
124 static void find_sym_fns
PARAMS ((struct objfile
*));
126 static void decrement_reading_symtab
PARAMS ((void *));
128 static void overlay_invalidate_all
PARAMS ((void));
130 static int overlay_is_mapped
PARAMS ((struct obj_section
*));
132 void list_overlays_command
PARAMS ((char *, int));
134 void map_overlay_command
PARAMS ((char *, int));
136 void unmap_overlay_command
PARAMS ((char *, int));
138 static void overlay_auto_command
PARAMS ((char *, int));
140 static void overlay_manual_command
PARAMS ((char *, int));
142 static void overlay_off_command
PARAMS ((char *, int));
144 static void overlay_load_command
PARAMS ((char *, int));
146 static void overlay_command
PARAMS ((char *, int));
148 static void simple_free_overlay_table
PARAMS ((void));
150 static void read_target_long_array
PARAMS ((CORE_ADDR
, unsigned int *, int));
152 static int simple_read_overlay_table
PARAMS ((void));
154 static int simple_overlay_update_1
PARAMS ((struct obj_section
*));
156 static void add_filename_language
PARAMS ((char *ext
, enum language lang
));
158 static void set_ext_lang_command
PARAMS ((char *args
, int from_tty
));
160 static void info_ext_lang_command
PARAMS ((char *args
, int from_tty
));
162 static void init_filename_language_table
PARAMS ((void));
164 void _initialize_symfile
PARAMS ((void));
166 /* List of all available sym_fns. On gdb startup, each object file reader
167 calls add_symtab_fns() to register information on each format it is
170 static struct sym_fns
*symtab_fns
= NULL
;
172 /* Flag for whether user will be reloading symbols multiple times.
173 Defaults to ON for VxWorks, otherwise OFF. */
175 #ifdef SYMBOL_RELOADING_DEFAULT
176 int symbol_reloading
= SYMBOL_RELOADING_DEFAULT
;
178 int symbol_reloading
= 0;
181 /* If non-zero, then on HP-UX (i.e., platforms that use somsolib.c),
182 this variable is interpreted as a threshhold. If adding a new
183 library's symbol table to those already known to the debugger would
184 exceed this threshhold, then the shlib's symbols are not added.
186 If non-zero on other platforms, shared library symbols will be added
187 automatically when the inferior is created, new libraries are loaded,
188 or when attaching to the inferior. This is almost always what users
189 will want to have happen; but for very large programs, the startup
190 time will be excessive, and so if this is a problem, the user can
191 clear this flag and then add the shared library symbols as needed.
192 Note that there is a potential for confusion, since if the shared
193 library symbols are not loaded, commands like "info fun" will *not*
194 report all the functions that are actually present.
196 Note that HP-UX interprets this variable to mean, "threshhold size
197 in megabytes, where zero means never add". Other platforms interpret
198 this variable to mean, "always add if non-zero, never add if zero."
201 int auto_solib_add
= 1;
204 /* Since this function is called from within qsort, in an ANSI environment
205 it must conform to the prototype for qsort, which specifies that the
206 comparison function takes two "void *" pointers. */
209 compare_symbols (s1p
, s2p
)
213 register struct symbol
**s1
, **s2
;
215 s1
= (struct symbol
**) s1p
;
216 s2
= (struct symbol
**) s2p
;
218 return (STRCMP (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
)));
225 compare_psymbols -- compare two partial symbols by name
229 Given pointers to pointers to two partial symbol table entries,
230 compare them by name and return -N, 0, or +N (ala strcmp).
231 Typically used by sorting routines like qsort().
235 Does direct compare of first two characters before punting
236 and passing to strcmp for longer compares. Note that the
237 original version had a bug whereby two null strings or two
238 identically named one character strings would return the
239 comparison of memory following the null byte.
244 compare_psymbols (s1p
, s2p
)
248 register char *st1
= SYMBOL_NAME (*(struct partial_symbol
**) s1p
);
249 register char *st2
= SYMBOL_NAME (*(struct partial_symbol
**) s2p
);
251 if ((st1
[0] - st2
[0]) || !st1
[0])
253 return (st1
[0] - st2
[0]);
255 else if ((st1
[1] - st2
[1]) || !st1
[1])
257 return (st1
[1] - st2
[1]);
261 /* Note: I replaced the STRCMP line (commented out below)
262 * with a simpler "strcmp()" which compares the 2 strings
263 * from the beginning. (STRCMP is a macro which first compares
264 * the initial characters, then falls back on strcmp).
265 * The reason is that the STRCMP line was tickling a C compiler
266 * bug on HP-UX 10.30, which is avoided with the simpler
267 * code. The performance gain from the more complicated code
268 * is negligible, given that we have already checked the
269 * initial 2 characters above. I reported the compiler bug,
270 * and once it is fixed the original line can be put back. RT
272 /* return ( STRCMP (st1 + 2, st2 + 2)); */
273 return (strcmp (st1
, st2
));
278 sort_pst_symbols (pst
)
279 struct partial_symtab
*pst
;
281 /* Sort the global list; don't sort the static list */
283 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
284 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
288 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
292 register struct block
*b
;
294 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
295 sizeof (struct symbol
*), compare_symbols
);
298 /* Call sort_symtab_syms to sort alphabetically
299 the symbols of each block of one symtab. */
303 register struct symtab
*s
;
305 register struct blockvector
*bv
;
308 register struct block
*b
;
312 bv
= BLOCKVECTOR (s
);
313 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
314 for (i
= 0; i
< nbl
; i
++)
316 b
= BLOCKVECTOR_BLOCK (bv
, i
);
317 if (BLOCK_SHOULD_SORT (b
))
322 /* Make a null terminated copy of the string at PTR with SIZE characters in
323 the obstack pointed to by OBSTACKP . Returns the address of the copy.
324 Note that the string at PTR does not have to be null terminated, I.E. it
325 may be part of a larger string and we are only saving a substring. */
328 obsavestring (ptr
, size
, obstackp
)
331 struct obstack
*obstackp
;
333 register char *p
= (char *) obstack_alloc (obstackp
, size
+ 1);
334 /* Open-coded memcpy--saves function call time. These strings are usually
335 short. FIXME: Is this really still true with a compiler that can
338 register char *p1
= ptr
;
339 register char *p2
= p
;
340 char *end
= ptr
+ size
;
348 /* Concatenate strings S1, S2 and S3; return the new string. Space is found
349 in the obstack pointed to by OBSTACKP. */
352 obconcat (obstackp
, s1
, s2
, s3
)
353 struct obstack
*obstackp
;
354 const char *s1
, *s2
, *s3
;
356 register int len
= strlen (s1
) + strlen (s2
) + strlen (s3
) + 1;
357 register char *val
= (char *) obstack_alloc (obstackp
, len
);
364 /* True if we are nested inside psymtab_to_symtab. */
366 int currently_reading_symtab
= 0;
369 decrement_reading_symtab (dummy
)
372 currently_reading_symtab
--;
375 /* Get the symbol table that corresponds to a partial_symtab.
376 This is fast after the first time you do it. In fact, there
377 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
381 psymtab_to_symtab (pst
)
382 register struct partial_symtab
*pst
;
384 /* If it's been looked up before, return it. */
388 /* If it has not yet been read in, read it. */
391 struct cleanup
*back_to
= make_cleanup (decrement_reading_symtab
, NULL
);
392 currently_reading_symtab
++;
393 (*pst
->read_symtab
) (pst
);
394 do_cleanups (back_to
);
400 /* Initialize entry point information for this objfile. */
403 init_entry_point_info (objfile
)
404 struct objfile
*objfile
;
406 /* Save startup file's range of PC addresses to help blockframe.c
407 decide where the bottom of the stack is. */
409 if (bfd_get_file_flags (objfile
->obfd
) & EXEC_P
)
411 /* Executable file -- record its entry point so we'll recognize
412 the startup file because it contains the entry point. */
413 objfile
->ei
.entry_point
= bfd_get_start_address (objfile
->obfd
);
417 /* Examination of non-executable.o files. Short-circuit this stuff. */
418 objfile
->ei
.entry_point
= INVALID_ENTRY_POINT
;
420 objfile
->ei
.entry_file_lowpc
= INVALID_ENTRY_LOWPC
;
421 objfile
->ei
.entry_file_highpc
= INVALID_ENTRY_HIGHPC
;
422 objfile
->ei
.entry_func_lowpc
= INVALID_ENTRY_LOWPC
;
423 objfile
->ei
.entry_func_highpc
= INVALID_ENTRY_HIGHPC
;
424 objfile
->ei
.main_func_lowpc
= INVALID_ENTRY_LOWPC
;
425 objfile
->ei
.main_func_highpc
= INVALID_ENTRY_HIGHPC
;
428 /* Get current entry point address. */
431 entry_point_address ()
433 return symfile_objfile
? symfile_objfile
->ei
.entry_point
: 0;
436 /* Remember the lowest-addressed loadable section we've seen.
437 This function is called via bfd_map_over_sections.
439 In case of equal vmas, the section with the largest size becomes the
440 lowest-addressed loadable section.
442 If the vmas and sizes are equal, the last section is considered the
443 lowest-addressed loadable section. */
446 find_lowest_section (abfd
, sect
, obj
)
451 asection
**lowest
= (asection
**) obj
;
453 if (0 == (bfd_get_section_flags (abfd
, sect
) & SEC_LOAD
))
456 *lowest
= sect
; /* First loadable section */
457 else if (bfd_section_vma (abfd
, *lowest
) > bfd_section_vma (abfd
, sect
))
458 *lowest
= sect
; /* A lower loadable section */
459 else if (bfd_section_vma (abfd
, *lowest
) == bfd_section_vma (abfd
, sect
)
460 && (bfd_section_size (abfd
, (*lowest
))
461 <= bfd_section_size (abfd
, sect
)))
465 /* Parse the user's idea of an offset for dynamic linking, into our idea
466 of how to represent it for fast symbol reading. This is the default
467 version of the sym_fns.sym_offsets function for symbol readers that
468 don't need to do anything special. It allocates a section_offsets table
469 for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */
472 default_symfile_offsets (objfile
, addrs
)
473 struct objfile
*objfile
;
474 struct section_addr_info
*addrs
;
478 objfile
->num_sections
= SECT_OFF_MAX
;
479 objfile
->section_offsets
= (struct section_offsets
*)
480 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
481 memset (objfile
->section_offsets
, 0, SIZEOF_SECTION_OFFSETS
);
483 /* If user explicitly specified values for data and bss, set them here. */
485 if (addrs
->text_addr
)
486 ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT
) = addrs
->text_addr
;
487 if (addrs
->data_addr
)
488 ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA
) = addrs
->data_addr
;
490 ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS
) = addrs
->bss_addr
;
492 /* Now calculate offsets for other sections. */
493 for (i
= 0; i
< MAX_SECTIONS
&& addrs
->other
[i
].name
; i
++)
495 struct other_sections
*osp
;
497 osp
= &addrs
->other
[i
] ;
498 if (addrs
->other
[i
].addr
== 0)
501 if (strcmp (".text", osp
->name
) == 0)
502 SECT_OFF_TEXT
= osp
->sectindex
;
503 else if (strcmp (".data", osp
->name
) == 0)
504 SECT_OFF_DATA
= osp
->sectindex
;
505 else if (strcmp (".bss", osp
->name
) == 0)
506 SECT_OFF_BSS
= osp
->sectindex
;
508 /* Record all sections in offsets */
509 ANOFFSET (objfile
->section_offsets
, osp
->sectindex
) = osp
->addr
;
514 /* Process a symbol file, as either the main file or as a dynamically
517 OBJFILE is where the symbols are to be read from.
519 ADDR is the address where the text segment was loaded, unless the
520 objfile is the main symbol file, in which case it is zero.
522 MAINLINE is nonzero if this is the main symbol file, or zero if
523 it's an extra symbol file such as dynamically loaded code.
525 VERBO is nonzero if the caller has printed a verbose message about
526 the symbol reading (and complaints can be more terse about it). */
529 syms_from_objfile (objfile
, addrs
, mainline
, verbo
)
530 struct objfile
*objfile
;
531 struct section_addr_info
*addrs
;
535 struct section_offsets
*section_offsets
;
536 asection
*lower_sect
;
538 CORE_ADDR lower_offset
;
539 struct section_addr_info local_addr
;
540 struct cleanup
*old_chain
;
543 /* If ADDRS is NULL, initialize the local section_addr_info struct and
544 point ADDRS to it. We now establish the convention that an addr of
545 zero means no load address was specified. */
549 memset (&local_addr
, 0, sizeof (local_addr
));
553 init_entry_point_info (objfile
);
554 find_sym_fns (objfile
);
556 /* Make sure that partially constructed symbol tables will be cleaned up
557 if an error occurs during symbol reading. */
558 old_chain
= make_cleanup ((make_cleanup_func
) free_objfile
, objfile
);
562 /* We will modify the main symbol table, make sure that all its users
563 will be cleaned up if an error occurs during symbol reading. */
564 make_cleanup ((make_cleanup_func
) clear_symtab_users
, 0);
566 /* Since no error yet, throw away the old symbol table. */
568 if (symfile_objfile
!= NULL
)
570 free_objfile (symfile_objfile
);
571 symfile_objfile
= NULL
;
574 /* Currently we keep symbols from the add-symbol-file command.
575 If the user wants to get rid of them, they should do "symbol-file"
576 without arguments first. Not sure this is the best behavior
579 (*objfile
->sf
->sym_new_init
) (objfile
);
582 /* Convert addr into an offset rather than an absolute address.
583 We find the lowest address of a loaded segment in the objfile,
584 and assume that <addr> is where that got loaded.
586 We no longer warn if the lowest section is not a text segment (as
587 happens for the PA64 port. */
590 /* No offset from objfile addresses. */
591 addrs
-> text_addr
= 0;
592 addrs
-> data_addr
= 0;
593 addrs
-> bss_addr
= 0;
597 /* Find lowest loadable section to be used as starting point for
598 continguous sections. FIXME!! won't work without call to find
599 .text first, but this assumes text is lowest section. */
600 lower_sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
601 if (lower_sect
== NULL
)
602 bfd_map_over_sections (objfile
->obfd
, find_lowest_section
,
604 if (lower_sect
== NULL
)
605 warning ("no loadable sections found in added symbol-file %s",
607 else if ((bfd_get_section_flags (objfile
->obfd
, lower_sect
) & SEC_CODE
)
609 warning ("Lowest section in %s is %s at %s",
611 bfd_section_name (objfile
->obfd
, lower_sect
),
612 paddr (bfd_section_vma (objfile
->obfd
, lower_sect
)));
613 if (lower_sect
!= NULL
)
614 lower_offset
= bfd_section_vma (objfile
->obfd
, lower_sect
);
618 /* Calculate offsets for the loadable sections.
619 FIXME! Sections must be in order of increasing loadable section
620 so that contiguous sections can use the lower-offset!!!
622 Adjust offsets if the segments are not contiguous.
623 If the section is contiguous, its offset should be set to
624 the offset of the highest loadable section lower than it
625 (the loadable section directly below it in memory).
626 this_offset = lower_offset = lower_addr - lower_orig_addr */
628 /* FIXME: These sections will not need special treatment because ALL
629 sections are in the other sections table */
631 if (addrs
->text_addr
!= 0)
633 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
636 addrs
->text_addr
-= bfd_section_vma (objfile
->obfd
, sect
);
637 lower_offset
= addrs
->text_addr
;
641 /* ??? who's below me? */
642 addrs
->text_addr
= lower_offset
;
644 if (addrs
->data_addr
!= 0)
646 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
649 addrs
->data_addr
-= bfd_section_vma (objfile
->obfd
, sect
);
650 lower_offset
= addrs
->data_addr
;
654 addrs
->data_addr
= lower_offset
;
656 if (addrs
->bss_addr
!= 0)
658 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
661 addrs
->bss_addr
-= bfd_section_vma (objfile
->obfd
, sect
);
662 lower_offset
= addrs
->bss_addr
;
666 addrs
->bss_addr
= lower_offset
;
668 /* Now calculate offsets for other sections. */
669 for (i
=0 ; i
< MAX_SECTIONS
&& addrs
->other
[i
].name
; i
++)
672 if (addrs
->other
[i
].addr
!= 0)
674 sect
=bfd_get_section_by_name(objfile
->obfd
, addrs
->other
[i
].name
);
677 addrs
->other
[i
].addr
-= bfd_section_vma (objfile
->obfd
, sect
);
678 lower_offset
= addrs
->other
[i
].addr
;
679 addrs
->other
[i
].sectindex
= sect
->index
;
683 warning ("section %s not found in %s", addrs
->other
[i
].name
,
685 addrs
->other
[i
].addr
= 0;
689 addrs
->other
[i
].addr
= lower_offset
;
693 /* Initialize symbol reading routines for this objfile, allow complaints to
694 appear for this new file, and record how verbose to be, then do the
695 initial symbol reading for this file. */
697 (*objfile
->sf
->sym_init
) (objfile
);
698 clear_complaints (1, verbo
);
700 (*objfile
->sf
->sym_offsets
) (objfile
, addrs
);
702 #ifndef IBM6000_TARGET
703 /* This is a SVR4/SunOS specific hack, I think. In any event, it
704 screws RS/6000. sym_offsets should be doing this sort of thing,
705 because it knows the mapping between bfd sections and
707 /* This is a hack. As far as I can tell, section offsets are not
708 target dependent. They are all set to addr with a couple of
709 exceptions. The exceptions are sysvr4 shared libraries, whose
710 offsets are kept in solib structures anyway and rs6000 xcoff
711 which handles shared libraries in a completely unique way.
713 Section offsets are built similarly, except that they are built
714 by adding addr in all cases because there is no clear mapping
715 from section_offsets into actual sections. Note that solib.c
716 has a different algorithm for finding section offsets.
718 These should probably all be collapsed into some target
719 independent form of shared library support. FIXME. */
723 struct obj_section
*s
;
725 /* Map section offsets in "addr" back to the object's
726 sections by comparing the section names with bfd's
727 section names. Then adjust the section address by
728 the offset. */ /* for gdb/13815 */
730 ALL_OBJFILE_OSECTIONS (objfile
, s
)
732 CORE_ADDR s_addr
= 0;
735 if (strcmp (s
->the_bfd_section
->name
, ".text") == 0)
736 s_addr
= addrs
->text_addr
;
737 else if (strcmp (s
->the_bfd_section
->name
, ".data") == 0)
738 s_addr
= addrs
->data_addr
;
739 else if (strcmp (s
->the_bfd_section
->name
, ".bss") == 0)
740 s_addr
= addrs
->bss_addr
;
742 for (i
= 0; !s_addr
&& addrs
->other
[i
].name
; i
++)
743 if (strcmp (s
->the_bfd_section
->name
, addrs
->other
[i
].name
) == 0)
744 s_addr
= addrs
->other
[i
].addr
; /* end added for gdb/13815 */
746 s
->addr
-= s
->offset
;
748 s
->endaddr
-= s
->offset
;
749 s
->endaddr
+= s_addr
;
753 #endif /* not IBM6000_TARGET */
755 (*objfile
->sf
->sym_read
) (objfile
, mainline
);
757 if (!have_partial_symbols () && !have_full_symbols ())
760 printf_filtered ("(no debugging symbols found)...");
764 /* Don't allow char * to have a typename (else would get caddr_t).
765 Ditto void *. FIXME: Check whether this is now done by all the
766 symbol readers themselves (many of them now do), and if so remove
769 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
770 TYPE_NAME (lookup_pointer_type (builtin_type_void
)) = 0;
772 /* Mark the objfile has having had initial symbol read attempted. Note
773 that this does not mean we found any symbols... */
775 objfile
->flags
|= OBJF_SYMS
;
777 /* Discard cleanups as symbol reading was successful. */
779 discard_cleanups (old_chain
);
781 /* Call this after reading in a new symbol table to give target
782 dependant code a crack at the new symbols. For instance, this
783 could be used to update the values of target-specific symbols GDB
784 needs to keep track of (such as _sigtramp, or whatever). */
786 TARGET_SYMFILE_POSTREAD (objfile
);
789 /* Perform required actions after either reading in the initial
790 symbols for a new objfile, or mapping in the symbols from a reusable
794 new_symfile_objfile (objfile
, mainline
, verbo
)
795 struct objfile
*objfile
;
800 /* If this is the main symbol file we have to clean up all users of the
801 old main symbol file. Otherwise it is sufficient to fixup all the
802 breakpoints that may have been redefined by this symbol file. */
805 /* OK, make it the "real" symbol file. */
806 symfile_objfile
= objfile
;
808 clear_symtab_users ();
812 breakpoint_re_set ();
815 /* We're done reading the symbol file; finish off complaints. */
816 clear_complaints (0, verbo
);
819 /* Process a symbol file, as either the main file or as a dynamically
822 NAME is the file name (which will be tilde-expanded and made
823 absolute herein) (but we don't free or modify NAME itself).
824 FROM_TTY says how verbose to be. MAINLINE specifies whether this
825 is the main symbol file, or whether it's an extra symbol file such
826 as dynamically loaded code. If !mainline, ADDR is the address
827 where the text segment was loaded.
829 Upon success, returns a pointer to the objfile that was added.
830 Upon failure, jumps back to command level (never returns). */
833 symbol_file_add (name
, from_tty
, addrs
, mainline
, flags
)
836 struct section_addr_info
*addrs
;
840 struct objfile
*objfile
;
841 struct partial_symtab
*psymtab
;
844 /* Open a bfd for the file, and give user a chance to burp if we'd be
845 interactively wiping out any existing symbols. */
847 abfd
= symfile_bfd_open (name
);
849 if ((have_full_symbols () || have_partial_symbols ())
852 && !query ("Load new symbol table from \"%s\"? ", name
))
853 error ("Not confirmed.");
855 objfile
= allocate_objfile (abfd
, flags
);
857 /* If the objfile uses a mapped symbol file, and we have a psymtab for
858 it, then skip reading any symbols at this time. */
860 if ((objfile
->flags
& OBJF_MAPPED
) && (objfile
->flags
& OBJF_SYMS
))
862 /* We mapped in an existing symbol table file that already has had
863 initial symbol reading performed, so we can skip that part. Notify
864 the user that instead of reading the symbols, they have been mapped.
866 if (from_tty
|| info_verbose
)
868 printf_filtered ("Mapped symbols for %s...", name
);
870 gdb_flush (gdb_stdout
);
872 init_entry_point_info (objfile
);
873 find_sym_fns (objfile
);
877 /* We either created a new mapped symbol table, mapped an existing
878 symbol table file which has not had initial symbol reading
879 performed, or need to read an unmapped symbol table. */
880 if (from_tty
|| info_verbose
)
882 if (pre_add_symbol_hook
)
883 pre_add_symbol_hook (name
);
886 printf_filtered ("Reading symbols from %s...", name
);
888 gdb_flush (gdb_stdout
);
891 syms_from_objfile (objfile
, addrs
, mainline
, from_tty
);
894 /* We now have at least a partial symbol table. Check to see if the
895 user requested that all symbols be read on initial access via either
896 the gdb startup command line or on a per symbol file basis. Expand
897 all partial symbol tables for this objfile if so. */
899 if ((flags
& OBJF_READNOW
) || readnow_symbol_files
)
901 if (from_tty
|| info_verbose
)
903 printf_filtered ("expanding to full symbols...");
905 gdb_flush (gdb_stdout
);
908 for (psymtab
= objfile
->psymtabs
;
910 psymtab
= psymtab
->next
)
912 psymtab_to_symtab (psymtab
);
916 if (from_tty
|| info_verbose
)
918 if (post_add_symbol_hook
)
919 post_add_symbol_hook ();
922 printf_filtered ("done.\n");
923 gdb_flush (gdb_stdout
);
927 new_symfile_objfile (objfile
, mainline
, from_tty
);
929 if (target_new_objfile_hook
)
930 target_new_objfile_hook (objfile
);
935 /* This is the symbol-file command. Read the file, analyze its
936 symbols, and add a struct symtab to a symtab list. The syntax of
937 the command is rather bizarre--(1) buildargv implements various
938 quoting conventions which are undocumented and have little or
939 nothing in common with the way things are quoted (or not quoted)
940 elsewhere in GDB, (2) options are used, which are not generally
941 used in GDB (perhaps "set mapped on", "set readnow on" would be
942 better), (3) the order of options matters, which is contrary to GNU
943 conventions (because it is confusing and inconvenient). */
946 symbol_file_command (args
, from_tty
)
952 CORE_ADDR text_relocation
= 0; /* text_relocation */
953 struct cleanup
*cleanups
;
954 int flags
= OBJF_USERLOADED
;
960 if ((have_full_symbols () || have_partial_symbols ())
962 && !query ("Discard symbol table from `%s'? ",
963 symfile_objfile
->name
))
964 error ("Not confirmed.");
965 free_all_objfiles ();
967 /* solib descriptors may have handles to objfiles. Since their
968 storage has just been released, we'd better wipe the solib
971 #if defined(SOLIB_RESTART)
975 symfile_objfile
= NULL
;
978 printf_unfiltered ("No symbol file now.\n");
981 RESET_HP_UX_GLOBALS ();
986 if ((argv
= buildargv (args
)) == NULL
)
990 cleanups
= make_cleanup_freeargv (argv
);
991 while (*argv
!= NULL
)
993 if (STREQ (*argv
, "-mapped"))
995 flags
|= OBJF_MAPPED
;
997 else if (STREQ (*argv
, "-readnow"))
999 flags
|= OBJF_READNOW
;
1001 else if (**argv
== '-')
1003 error ("unknown option `%s'", *argv
);
1011 /* this is for rombug remote only, to get the text relocation by
1012 using link command */
1013 p
= strrchr (name
, '/');
1019 target_link (p
, &text_relocation
);
1021 if (text_relocation
== (CORE_ADDR
) 0)
1023 else if (text_relocation
== (CORE_ADDR
) -1)
1025 symbol_file_add (name
, from_tty
, NULL
, 1, flags
);
1027 RESET_HP_UX_GLOBALS ();
1032 struct section_addr_info section_addrs
;
1033 memset (§ion_addrs
, 0, sizeof (section_addrs
));
1034 section_addrs
.text_addr
= (CORE_ADDR
) text_relocation
;
1035 symbol_file_add (name
, from_tty
, §ion_addrs
, 0, flags
);
1038 /* Getting new symbols may change our opinion about what is
1040 reinit_frame_cache ();
1042 set_initial_language ();
1049 error ("no symbol file name was specified");
1051 TUIDO (((TuiOpaqueFuncPtr
) tuiDisplayMainFunction
));
1052 do_cleanups (cleanups
);
1056 /* Set the initial language.
1058 A better solution would be to record the language in the psymtab when reading
1059 partial symbols, and then use it (if known) to set the language. This would
1060 be a win for formats that encode the language in an easily discoverable place,
1061 such as DWARF. For stabs, we can jump through hoops looking for specially
1062 named symbols or try to intuit the language from the specific type of stabs
1063 we find, but we can't do that until later when we read in full symbols.
1067 set_initial_language ()
1069 struct partial_symtab
*pst
;
1070 enum language lang
= language_unknown
;
1072 pst
= find_main_psymtab ();
1075 if (pst
->filename
!= NULL
)
1077 lang
= deduce_language_from_filename (pst
->filename
);
1079 if (lang
== language_unknown
)
1081 /* Make C the default language */
1084 set_language (lang
);
1085 expected_language
= current_language
; /* Don't warn the user */
1089 /* Open file specified by NAME and hand it off to BFD for preliminary
1090 analysis. Result is a newly initialized bfd *, which includes a newly
1091 malloc'd` copy of NAME (tilde-expanded and made absolute).
1092 In case of trouble, error() is called. */
1095 symfile_bfd_open (name
)
1100 char *absolute_name
;
1104 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy */
1106 /* Look down path for it, allocate 2nd new malloc'd copy. */
1107 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
| O_BINARY
, 0, &absolute_name
);
1108 #if defined(__GO32__) || defined(_WIN32)
1111 char *exename
= alloca (strlen (name
) + 5);
1112 strcat (strcpy (exename
, name
), ".exe");
1113 desc
= openp (getenv ("PATH"), 1, exename
, O_RDONLY
| O_BINARY
,
1119 make_cleanup (free
, name
);
1120 perror_with_name (name
);
1122 free (name
); /* Free 1st new malloc'd copy */
1123 name
= absolute_name
; /* Keep 2nd malloc'd copy in bfd */
1124 /* It'll be freed in free_objfile(). */
1126 sym_bfd
= bfd_fdopenr (name
, gnutarget
, desc
);
1130 make_cleanup (free
, name
);
1131 error ("\"%s\": can't open to read symbols: %s.", name
,
1132 bfd_errmsg (bfd_get_error ()));
1134 sym_bfd
->cacheable
= true;
1136 if (!bfd_check_format (sym_bfd
, bfd_object
))
1138 /* FIXME: should be checking for errors from bfd_close (for one thing,
1139 on error it does not free all the storage associated with the
1141 bfd_close (sym_bfd
); /* This also closes desc */
1142 make_cleanup (free
, name
);
1143 error ("\"%s\": can't read symbols: %s.", name
,
1144 bfd_errmsg (bfd_get_error ()));
1149 /* Link a new symtab_fns into the global symtab_fns list. Called on gdb
1150 startup by the _initialize routine in each object file format reader,
1151 to register information about each format the the reader is prepared
1158 sf
->next
= symtab_fns
;
1163 /* Initialize to read symbols from the symbol file sym_bfd. It either
1164 returns or calls error(). The result is an initialized struct sym_fns
1165 in the objfile structure, that contains cached information about the
1169 find_sym_fns (objfile
)
1170 struct objfile
*objfile
;
1173 enum bfd_flavour our_flavour
= bfd_get_flavour (objfile
->obfd
);
1174 char *our_target
= bfd_get_target (objfile
->obfd
);
1176 /* Special kludge for RS/6000 and PowerMac. See xcoffread.c. */
1177 if (STREQ (our_target
, "aixcoff-rs6000") ||
1178 STREQ (our_target
, "xcoff-powermac"))
1179 our_flavour
= (enum bfd_flavour
) -1;
1181 /* Special kludge for apollo. See dstread.c. */
1182 if (STREQN (our_target
, "apollo", 6))
1183 our_flavour
= (enum bfd_flavour
) -2;
1185 for (sf
= symtab_fns
; sf
!= NULL
; sf
= sf
->next
)
1187 if (our_flavour
== sf
->sym_flavour
)
1193 error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
1194 bfd_get_target (objfile
->obfd
));
1197 /* This function runs the load command of our current target. */
1200 load_command (arg
, from_tty
)
1205 arg
= get_exec_file (1);
1206 target_load (arg
, from_tty
);
1209 /* This version of "load" should be usable for any target. Currently
1210 it is just used for remote targets, not inftarg.c or core files,
1211 on the theory that only in that case is it useful.
1213 Avoiding xmodem and the like seems like a win (a) because we don't have
1214 to worry about finding it, and (b) On VMS, fork() is very slow and so
1215 we don't want to run a subprocess. On the other hand, I'm not sure how
1216 performance compares. */
1218 static int download_write_size
= 512;
1219 static int validate_download
= 0;
1222 generic_load (char *args
, int from_tty
)
1226 time_t start_time
, end_time
; /* Start and end times of download */
1227 unsigned long data_count
= 0; /* Number of bytes transferred to memory */
1228 unsigned long write_count
= 0; /* Number of writes needed. */
1229 unsigned long load_offset
; /* offset to add to vma for each section */
1231 struct cleanup
*old_cleanups
;
1233 CORE_ADDR total_size
= 0;
1234 CORE_ADDR total_sent
= 0;
1236 /* Parse the input argument - the user can specify a load offset as
1237 a second argument. */
1238 filename
= xmalloc (strlen (args
) + 1);
1239 old_cleanups
= make_cleanup (free
, filename
);
1240 strcpy (filename
, args
);
1241 offptr
= strchr (filename
, ' ');
1245 load_offset
= strtoul (offptr
, &endptr
, 0);
1246 if (offptr
== endptr
)
1247 error ("Invalid download offset:%s\n", offptr
);
1253 /* Open the file for loading. */
1254 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
1255 if (loadfile_bfd
== NULL
)
1257 perror_with_name (filename
);
1261 /* FIXME: should be checking for errors from bfd_close (for one thing,
1262 on error it does not free all the storage associated with the
1264 make_cleanup ((make_cleanup_func
) bfd_close
, loadfile_bfd
);
1266 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
1268 error ("\"%s\" is not an object file: %s", filename
,
1269 bfd_errmsg (bfd_get_error ()));
1272 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
1273 if (s
->flags
& SEC_LOAD
)
1274 total_size
+= bfd_get_section_size_before_reloc (s
);
1276 start_time
= time (NULL
);
1278 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
1280 if (s
->flags
& SEC_LOAD
)
1282 CORE_ADDR size
= bfd_get_section_size_before_reloc (s
);
1286 struct cleanup
*old_chain
;
1287 CORE_ADDR lma
= s
->lma
+ load_offset
;
1288 CORE_ADDR block_size
;
1290 const char *sect_name
= bfd_get_section_name (loadfile_bfd
, s
);
1293 if (download_write_size
> 0 && size
> download_write_size
)
1294 block_size
= download_write_size
;
1298 buffer
= xmalloc (size
);
1299 old_chain
= make_cleanup (free
, buffer
);
1301 /* Is this really necessary? I guess it gives the user something
1302 to look at during a long download. */
1303 fprintf_unfiltered (gdb_stdout
,
1304 "Loading section %s, size 0x%s lma 0x%s\n",
1305 sect_name
, paddr_nz (size
), paddr_nz (lma
));
1307 bfd_get_section_contents (loadfile_bfd
, s
, buffer
, 0, size
);
1313 CORE_ADDR this_transfer
= size
- sent
;
1314 if (this_transfer
>= block_size
)
1315 this_transfer
= block_size
;
1316 len
= target_write_memory_partial (lma
, buffer
,
1317 this_transfer
, &err
);
1320 if (validate_download
)
1322 /* Broken memories and broken monitors manifest
1323 themselves here when bring new computers to
1324 life. This doubles already slow downloads. */
1325 /* NOTE: cagney/1999-10-18: A more efficient
1326 implementation might add a verify_memory()
1327 method to the target vector and then use
1328 that. remote.c could implement that method
1329 using the ``qCRC'' packet. */
1330 char *check
= xmalloc (len
);
1331 struct cleanup
*verify_cleanups
= make_cleanup (free
, check
);
1332 if (target_read_memory (lma
, check
, len
) != 0)
1333 error ("Download verify read failed at 0x%s",
1335 if (memcmp (buffer
, check
, len
) != 0)
1336 error ("Download verify compare failed at 0x%s",
1338 do_cleanups (verify_cleanups
);
1347 || (ui_load_progress_hook
!= NULL
1348 && ui_load_progress_hook (sect_name
, sent
)))
1349 error ("Canceled the download");
1351 if (show_load_progress
!= NULL
)
1352 show_load_progress (sect_name
, sent
, size
, total_sent
, total_size
);
1354 while (sent
< size
);
1357 error ("Memory access error while loading section %s.", sect_name
);
1359 do_cleanups (old_chain
);
1364 end_time
= time (NULL
);
1367 entry
= bfd_get_start_address (loadfile_bfd
);
1368 fprintf_unfiltered (gdb_stdout
,
1369 "Start address 0x%s , load size %ld\n",
1370 paddr_nz (entry
), data_count
);
1371 /* We were doing this in remote-mips.c, I suspect it is right
1372 for other targets too. */
1376 /* FIXME: are we supposed to call symbol_file_add or not? According to
1377 a comment from remote-mips.c (where a call to symbol_file_add was
1378 commented out), making the call confuses GDB if more than one file is
1379 loaded in. remote-nindy.c had no call to symbol_file_add, but remote-vx.c
1382 print_transfer_performance (gdb_stdout
, data_count
, write_count
,
1383 end_time
- start_time
);
1385 do_cleanups (old_cleanups
);
1388 /* Report how fast the transfer went. */
1390 /* DEPRECATED: cagney/1999-10-18: report_transfer_performance is being
1391 replaced by print_transfer_performance (with a very different
1392 function signature). */
1395 report_transfer_performance (data_count
, start_time
, end_time
)
1396 unsigned long data_count
;
1397 time_t start_time
, end_time
;
1399 print_transfer_performance (gdb_stdout
, data_count
, end_time
- start_time
, 0);
1403 print_transfer_performance (struct gdb_file
*stream
,
1404 unsigned long data_count
,
1405 unsigned long write_count
,
1406 unsigned long time_count
)
1408 fprintf_unfiltered (stream
, "Transfer rate: ");
1410 fprintf_unfiltered (stream
, "%ld bits/sec", (data_count
* 8) / time_count
);
1412 fprintf_unfiltered (stream
, "%ld bits in <1 sec", (data_count
* 8));
1413 if (write_count
> 0)
1414 fprintf_unfiltered (stream
, ", %ld bytes/write", data_count
/ write_count
);
1415 fprintf_unfiltered (stream
, ".\n");
1418 /* This function allows the addition of incrementally linked object files.
1419 It does not modify any state in the target, only in the debugger. */
1423 add_symbol_file_command (args
, from_tty
)
1428 CORE_ADDR text_addr
;
1429 int flags
= OBJF_USERLOADED
;
1431 int expecting_option
= 0;
1432 int option_index
= 0;
1438 enum { OPT_SECTION
} type
;
1441 } opt
[SECT_OFF_MAX
];
1442 struct section_addr_info section_addrs
;
1448 error ("add-symbol-file takes a file name and an address");
1451 /* Make a copy of the string that we can safely write into. */
1453 args
= xstrdup (args
);
1454 make_cleanup (free
, args
);
1456 /* Ensure section_addrs is initialized */
1457 memset (§ion_addrs
, 0, sizeof (section_addrs
));
1459 /* Pick off any -option args and the file name. */
1461 while (*args
!= '\000')
1463 while (isspace (*args
))
1468 while ((*args
!= '\000') && !isspace (*args
))
1472 if (*args
!= '\000')
1478 if (expecting_option
)
1480 opt
[option_index
++].value
= arg
;
1481 expecting_option
= 0;
1491 opt
[option_index
].type
= OPT_SECTION
;
1492 opt
[option_index
].name
= ".text";
1493 opt
[option_index
++].value
= arg
;
1496 opt
[option_index
].type
= OPT_SECTION
;
1497 opt
[option_index
].name
= ".data";
1498 opt
[option_index
++].value
= arg
;
1501 opt
[option_index
].type
= OPT_SECTION
;
1502 opt
[option_index
].name
= ".bss";
1503 opt
[option_index
++].value
= arg
;
1506 warning ("Too many arguments entered; see \"help add-symbol-file\" for command syntax.");
1511 else if (STREQ (arg
, "-mapped"))
1513 flags
|= OBJF_MAPPED
;
1515 else if (STREQ (arg
, "-readnow"))
1517 flags
|= OBJF_READNOW
;
1519 else if (STREQN (arg
, "-T", 2))
1521 if (option_index
>= SECT_OFF_MAX
)
1523 warning ("Number of options exceeds maximum allowed.");
1527 expecting_option
= 1;
1528 opt
[option_index
].type
= OPT_SECTION
;
1529 opt
[option_index
].name
= arg
+ 2;
1534 error ("Unknown option `%s'", arg
);
1540 error ("add-symbol-file takes a file name");
1542 name
= tilde_expand (name
);
1543 make_cleanup (free
, name
);
1545 if (option_index
> 0)
1547 /* Print the prompt for the query below.
1548 We have to split this up into 3 print statements because
1549 local_hex_string returns a local static string. */
1551 printf_filtered ("add symbol table from file \"%s\" at\n", name
);
1552 for (i
= 0; i
< option_index
; i
++)
1554 switch (opt
[i
].type
)
1559 char *val
= opt
[i
].value
;
1560 char *sec
= opt
[i
].name
;
1563 if (val
[0] == '0' && val
[1] == 'x')
1564 addr
= strtoul (val
+2, NULL
, 16);
1566 addr
= strtoul (val
, NULL
, 10);
1568 if (strcmp (sec
, ".text") == 0)
1569 section_addrs
.text_addr
= addr
;
1570 else if (strcmp (sec
, ".data") == 0)
1571 section_addrs
.data_addr
= addr
;
1572 else if (strcmp (sec
, ".bss") == 0)
1573 section_addrs
.bss_addr
= addr
;
1574 /* Add the section to the others even if it is a
1575 text data or bss section. This is redundent but
1576 eventually, none will be given special treatment */
1578 section_addrs
.other
[sec_num
].name
= xstrdup (sec
);
1579 make_cleanup (free
, section_addrs
.other
[sec_num
].name
);
1580 section_addrs
.other
[sec_num
++].addr
= addr
;
1581 printf_filtered ("\t%s_addr = %s\n",
1583 local_hex_string ((unsigned long)addr
));
1586 /* The object's sections are initialized when a
1587 call is made to build_objfile_section_table (objfile).
1588 This happens in reread_symbols.
1589 At this point, we don't know what file type this is,
1590 so we can't determine what section names are valid. */
1594 complain (&unknown_option_complaint
, opt
[i
].name
);
1597 /* Eventually, these hard coded names will be obsolete */
1598 /* All the addresses will be on the others section */
1602 CORE_ADDR text_addr
;
1603 target_link (name
, &text_addr
);
1604 if (text_addr
== (CORE_ADDR
) -1)
1605 error("Don't know how to get text start location for this file");
1606 section_addrs
.text_addr
= text_addr
;
1607 section_addrs
.data_addr
= 0;
1608 section_addrs
.bss_addr
= 0;
1609 printf_filtered("add symbol table from file \"%s\" at text_addr = %s?\n",
1610 name
, local_hex_string ((unsigned long)text_addr
));
1612 if (from_tty
&& (!query ("%s", "")))
1613 error ("Not confirmed.");
1615 symbol_file_add (name
, from_tty
, §ion_addrs
, 0, flags
);
1617 /* Getting new symbols may change our opinion about what is
1619 reinit_frame_cache ();
1623 add_shared_symbol_files_command (args
, from_tty
)
1627 #ifdef ADD_SHARED_SYMBOL_FILES
1628 ADD_SHARED_SYMBOL_FILES (args
, from_tty
);
1630 error ("This command is not available in this configuration of GDB.");
1634 /* Re-read symbols if a symbol-file has changed. */
1638 struct objfile
*objfile
;
1641 struct stat new_statbuf
;
1644 /* With the addition of shared libraries, this should be modified,
1645 the load time should be saved in the partial symbol tables, since
1646 different tables may come from different source files. FIXME.
1647 This routine should then walk down each partial symbol table
1648 and see if the symbol table that it originates from has been changed */
1650 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
)
1654 #ifdef IBM6000_TARGET
1655 /* If this object is from a shared library, then you should
1656 stat on the library name, not member name. */
1658 if (objfile
->obfd
->my_archive
)
1659 res
= stat (objfile
->obfd
->my_archive
->filename
, &new_statbuf
);
1662 res
= stat (objfile
->name
, &new_statbuf
);
1665 /* FIXME, should use print_sys_errmsg but it's not filtered. */
1666 printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
1670 new_modtime
= new_statbuf
.st_mtime
;
1671 if (new_modtime
!= objfile
->mtime
)
1673 struct cleanup
*old_cleanups
;
1674 struct section_offsets
*offsets
;
1676 char *obfd_filename
;
1678 printf_filtered ("`%s' has changed; re-reading symbols.\n",
1681 /* There are various functions like symbol_file_add,
1682 symfile_bfd_open, syms_from_objfile, etc., which might
1683 appear to do what we want. But they have various other
1684 effects which we *don't* want. So we just do stuff
1685 ourselves. We don't worry about mapped files (for one thing,
1686 any mapped file will be out of date). */
1688 /* If we get an error, blow away this objfile (not sure if
1689 that is the correct response for things like shared
1691 old_cleanups
= make_cleanup ((make_cleanup_func
) free_objfile
,
1693 /* We need to do this whenever any symbols go away. */
1694 make_cleanup ((make_cleanup_func
) clear_symtab_users
, 0);
1696 /* Clean up any state BFD has sitting around. We don't need
1697 to close the descriptor but BFD lacks a way of closing the
1698 BFD without closing the descriptor. */
1699 obfd_filename
= bfd_get_filename (objfile
->obfd
);
1700 if (!bfd_close (objfile
->obfd
))
1701 error ("Can't close BFD for %s: %s", objfile
->name
,
1702 bfd_errmsg (bfd_get_error ()));
1703 objfile
->obfd
= bfd_openr (obfd_filename
, gnutarget
);
1704 if (objfile
->obfd
== NULL
)
1705 error ("Can't open %s to read symbols.", objfile
->name
);
1706 /* bfd_openr sets cacheable to true, which is what we want. */
1707 if (!bfd_check_format (objfile
->obfd
, bfd_object
))
1708 error ("Can't read symbols from %s: %s.", objfile
->name
,
1709 bfd_errmsg (bfd_get_error ()));
1711 /* Save the offsets, we will nuke them with the rest of the
1713 num_offsets
= objfile
->num_sections
;
1714 offsets
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1715 memcpy (offsets
, objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1717 /* Nuke all the state that we will re-read. Much of the following
1718 code which sets things to NULL really is necessary to tell
1719 other parts of GDB that there is nothing currently there. */
1721 /* FIXME: Do we have to free a whole linked list, or is this
1723 if (objfile
->global_psymbols
.list
)
1724 mfree (objfile
->md
, objfile
->global_psymbols
.list
);
1725 memset (&objfile
->global_psymbols
, 0,
1726 sizeof (objfile
->global_psymbols
));
1727 if (objfile
->static_psymbols
.list
)
1728 mfree (objfile
->md
, objfile
->static_psymbols
.list
);
1729 memset (&objfile
->static_psymbols
, 0,
1730 sizeof (objfile
->static_psymbols
));
1732 /* Free the obstacks for non-reusable objfiles */
1733 free_bcache (&objfile
->psymbol_cache
);
1734 obstack_free (&objfile
->psymbol_obstack
, 0);
1735 obstack_free (&objfile
->symbol_obstack
, 0);
1736 obstack_free (&objfile
->type_obstack
, 0);
1737 objfile
->sections
= NULL
;
1738 objfile
->symtabs
= NULL
;
1739 objfile
->psymtabs
= NULL
;
1740 objfile
->free_psymtabs
= NULL
;
1741 objfile
->msymbols
= NULL
;
1742 objfile
->minimal_symbol_count
= 0;
1743 objfile
->fundamental_types
= NULL
;
1744 if (objfile
->sf
!= NULL
)
1746 (*objfile
->sf
->sym_finish
) (objfile
);
1749 /* We never make this a mapped file. */
1751 /* obstack_specify_allocation also initializes the obstack so
1753 obstack_specify_allocation (&objfile
->psymbol_cache
.cache
, 0, 0,
1755 obstack_specify_allocation (&objfile
->psymbol_obstack
, 0, 0,
1757 obstack_specify_allocation (&objfile
->symbol_obstack
, 0, 0,
1759 obstack_specify_allocation (&objfile
->type_obstack
, 0, 0,
1761 if (build_objfile_section_table (objfile
))
1763 error ("Can't find the file sections in `%s': %s",
1764 objfile
->name
, bfd_errmsg (bfd_get_error ()));
1767 /* We use the same section offsets as from last time. I'm not
1768 sure whether that is always correct for shared libraries. */
1769 objfile
->section_offsets
= (struct section_offsets
*)
1770 obstack_alloc (&objfile
->psymbol_obstack
, SIZEOF_SECTION_OFFSETS
);
1771 memcpy (objfile
->section_offsets
, offsets
, SIZEOF_SECTION_OFFSETS
);
1772 objfile
->num_sections
= num_offsets
;
1774 /* What the hell is sym_new_init for, anyway? The concept of
1775 distinguishing between the main file and additional files
1776 in this way seems rather dubious. */
1777 if (objfile
== symfile_objfile
)
1779 (*objfile
->sf
->sym_new_init
) (objfile
);
1781 RESET_HP_UX_GLOBALS ();
1785 (*objfile
->sf
->sym_init
) (objfile
);
1786 clear_complaints (1, 1);
1787 /* The "mainline" parameter is a hideous hack; I think leaving it
1788 zero is OK since dbxread.c also does what it needs to do if
1789 objfile->global_psymbols.size is 0. */
1790 (*objfile
->sf
->sym_read
) (objfile
, 0);
1791 if (!have_partial_symbols () && !have_full_symbols ())
1794 printf_filtered ("(no debugging symbols found)\n");
1797 objfile
->flags
|= OBJF_SYMS
;
1799 /* We're done reading the symbol file; finish off complaints. */
1800 clear_complaints (0, 1);
1802 /* Getting new symbols may change our opinion about what is
1805 reinit_frame_cache ();
1807 /* Discard cleanups as symbol reading was successful. */
1808 discard_cleanups (old_cleanups
);
1810 /* If the mtime has changed between the time we set new_modtime
1811 and now, we *want* this to be out of date, so don't call stat
1813 objfile
->mtime
= new_modtime
;
1816 /* Call this after reading in a new symbol table to give target
1817 dependant code a crack at the new symbols. For instance, this
1818 could be used to update the values of target-specific symbols GDB
1819 needs to keep track of (such as _sigtramp, or whatever). */
1821 TARGET_SYMFILE_POSTREAD (objfile
);
1827 clear_symtab_users ();
1839 static filename_language
*filename_language_table
;
1840 static int fl_table_size
, fl_table_next
;
1843 add_filename_language (ext
, lang
)
1847 if (fl_table_next
>= fl_table_size
)
1849 fl_table_size
+= 10;
1850 filename_language_table
= realloc (filename_language_table
,
1854 filename_language_table
[fl_table_next
].ext
= strsave (ext
);
1855 filename_language_table
[fl_table_next
].lang
= lang
;
1859 static char *ext_args
;
1862 set_ext_lang_command (args
, from_tty
)
1867 char *cp
= ext_args
;
1870 /* First arg is filename extension, starting with '.' */
1872 error ("'%s': Filename extension must begin with '.'", ext_args
);
1874 /* Find end of first arg. */
1875 while (*cp
&& !isspace (*cp
))
1879 error ("'%s': two arguments required -- filename extension and language",
1882 /* Null-terminate first arg */
1885 /* Find beginning of second arg, which should be a source language. */
1886 while (*cp
&& isspace (*cp
))
1890 error ("'%s': two arguments required -- filename extension and language",
1893 /* Lookup the language from among those we know. */
1894 lang
= language_enum (cp
);
1896 /* Now lookup the filename extension: do we already know it? */
1897 for (i
= 0; i
< fl_table_next
; i
++)
1898 if (0 == strcmp (ext_args
, filename_language_table
[i
].ext
))
1901 if (i
>= fl_table_next
)
1903 /* new file extension */
1904 add_filename_language (ext_args
, lang
);
1908 /* redefining a previously known filename extension */
1911 /* query ("Really make files of type %s '%s'?", */
1912 /* ext_args, language_str (lang)); */
1914 free (filename_language_table
[i
].ext
);
1915 filename_language_table
[i
].ext
= strsave (ext_args
);
1916 filename_language_table
[i
].lang
= lang
;
1921 info_ext_lang_command (args
, from_tty
)
1927 printf_filtered ("Filename extensions and the languages they represent:");
1928 printf_filtered ("\n\n");
1929 for (i
= 0; i
< fl_table_next
; i
++)
1930 printf_filtered ("\t%s\t- %s\n",
1931 filename_language_table
[i
].ext
,
1932 language_str (filename_language_table
[i
].lang
));
1936 init_filename_language_table ()
1938 if (fl_table_size
== 0) /* protect against repetition */
1942 filename_language_table
=
1943 xmalloc (fl_table_size
* sizeof (*filename_language_table
));
1944 add_filename_language (".c", language_c
);
1945 add_filename_language (".C", language_cplus
);
1946 add_filename_language (".cc", language_cplus
);
1947 add_filename_language (".cp", language_cplus
);
1948 add_filename_language (".cpp", language_cplus
);
1949 add_filename_language (".cxx", language_cplus
);
1950 add_filename_language (".c++", language_cplus
);
1951 add_filename_language (".java", language_java
);
1952 add_filename_language (".class", language_java
);
1953 add_filename_language (".ch", language_chill
);
1954 add_filename_language (".c186", language_chill
);
1955 add_filename_language (".c286", language_chill
);
1956 add_filename_language (".f", language_fortran
);
1957 add_filename_language (".F", language_fortran
);
1958 add_filename_language (".s", language_asm
);
1959 add_filename_language (".S", language_asm
);
1964 deduce_language_from_filename (filename
)
1970 if (filename
!= NULL
)
1971 if ((cp
= strrchr (filename
, '.')) != NULL
)
1972 for (i
= 0; i
< fl_table_next
; i
++)
1973 if (strcmp (cp
, filename_language_table
[i
].ext
) == 0)
1974 return filename_language_table
[i
].lang
;
1976 return language_unknown
;
1981 Allocate and partly initialize a new symbol table. Return a pointer
1982 to it. error() if no space.
1984 Caller must set these fields:
1990 possibly free_named_symtabs (symtab->filename);
1994 allocate_symtab (filename
, objfile
)
1996 struct objfile
*objfile
;
1998 register struct symtab
*symtab
;
2000 symtab
= (struct symtab
*)
2001 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symtab
));
2002 memset (symtab
, 0, sizeof (*symtab
));
2003 symtab
->filename
= obsavestring (filename
, strlen (filename
),
2004 &objfile
->symbol_obstack
);
2005 symtab
->fullname
= NULL
;
2006 symtab
->language
= deduce_language_from_filename (filename
);
2007 symtab
->debugformat
= obsavestring ("unknown", 7,
2008 &objfile
->symbol_obstack
);
2010 /* Hook it to the objfile it comes from */
2012 symtab
->objfile
= objfile
;
2013 symtab
->next
= objfile
->symtabs
;
2014 objfile
->symtabs
= symtab
;
2016 /* FIXME: This should go away. It is only defined for the Z8000,
2017 and the Z8000 definition of this macro doesn't have anything to
2018 do with the now-nonexistent EXTRA_SYMTAB_INFO macro, it's just
2019 here for convenience. */
2020 #ifdef INIT_EXTRA_SYMTAB_INFO
2021 INIT_EXTRA_SYMTAB_INFO (symtab
);
2027 struct partial_symtab
*
2028 allocate_psymtab (filename
, objfile
)
2030 struct objfile
*objfile
;
2032 struct partial_symtab
*psymtab
;
2034 if (objfile
->free_psymtabs
)
2036 psymtab
= objfile
->free_psymtabs
;
2037 objfile
->free_psymtabs
= psymtab
->next
;
2040 psymtab
= (struct partial_symtab
*)
2041 obstack_alloc (&objfile
->psymbol_obstack
,
2042 sizeof (struct partial_symtab
));
2044 memset (psymtab
, 0, sizeof (struct partial_symtab
));
2045 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
2046 &objfile
->psymbol_obstack
);
2047 psymtab
->symtab
= NULL
;
2049 /* Prepend it to the psymtab list for the objfile it belongs to.
2050 Psymtabs are searched in most recent inserted -> least recent
2053 psymtab
->objfile
= objfile
;
2054 psymtab
->next
= objfile
->psymtabs
;
2055 objfile
->psymtabs
= psymtab
;
2058 struct partial_symtab
**prev_pst
;
2059 psymtab
->objfile
= objfile
;
2060 psymtab
->next
= NULL
;
2061 prev_pst
= &(objfile
->psymtabs
);
2062 while ((*prev_pst
) != NULL
)
2063 prev_pst
= &((*prev_pst
)->next
);
2064 (*prev_pst
) = psymtab
;
2072 discard_psymtab (pst
)
2073 struct partial_symtab
*pst
;
2075 struct partial_symtab
**prev_pst
;
2078 Empty psymtabs happen as a result of header files which don't
2079 have any symbols in them. There can be a lot of them. But this
2080 check is wrong, in that a psymtab with N_SLINE entries but
2081 nothing else is not empty, but we don't realize that. Fixing
2082 that without slowing things down might be tricky. */
2084 /* First, snip it out of the psymtab chain */
2086 prev_pst
= &(pst
->objfile
->psymtabs
);
2087 while ((*prev_pst
) != pst
)
2088 prev_pst
= &((*prev_pst
)->next
);
2089 (*prev_pst
) = pst
->next
;
2091 /* Next, put it on a free list for recycling */
2093 pst
->next
= pst
->objfile
->free_psymtabs
;
2094 pst
->objfile
->free_psymtabs
= pst
;
2098 /* Reset all data structures in gdb which may contain references to symbol
2102 clear_symtab_users ()
2104 /* Someday, we should do better than this, by only blowing away
2105 the things that really need to be blown. */
2106 clear_value_history ();
2108 clear_internalvars ();
2109 breakpoint_re_set ();
2110 set_default_breakpoint (0, 0, 0, 0);
2111 current_source_symtab
= 0;
2112 current_source_line
= 0;
2113 clear_pc_function_cache ();
2114 if (target_new_objfile_hook
)
2115 target_new_objfile_hook (NULL
);
2118 /* clear_symtab_users_once:
2120 This function is run after symbol reading, or from a cleanup.
2121 If an old symbol table was obsoleted, the old symbol table
2122 has been blown away, but the other GDB data structures that may
2123 reference it have not yet been cleared or re-directed. (The old
2124 symtab was zapped, and the cleanup queued, in free_named_symtab()
2127 This function can be queued N times as a cleanup, or called
2128 directly; it will do all the work the first time, and then will be a
2129 no-op until the next time it is queued. This works by bumping a
2130 counter at queueing time. Much later when the cleanup is run, or at
2131 the end of symbol processing (in case the cleanup is discarded), if
2132 the queued count is greater than the "done-count", we do the work
2133 and set the done-count to the queued count. If the queued count is
2134 less than or equal to the done-count, we just ignore the call. This
2135 is needed because reading a single .o file will often replace many
2136 symtabs (one per .h file, for example), and we don't want to reset
2137 the breakpoints N times in the user's face.
2139 The reason we both queue a cleanup, and call it directly after symbol
2140 reading, is because the cleanup protects us in case of errors, but is
2141 discarded if symbol reading is successful. */
2144 /* FIXME: As free_named_symtabs is currently a big noop this function
2145 is no longer needed. */
2147 clear_symtab_users_once
PARAMS ((void));
2149 static int clear_symtab_users_queued
;
2150 static int clear_symtab_users_done
;
2153 clear_symtab_users_once ()
2155 /* Enforce once-per-`do_cleanups'-semantics */
2156 if (clear_symtab_users_queued
<= clear_symtab_users_done
)
2158 clear_symtab_users_done
= clear_symtab_users_queued
;
2160 clear_symtab_users ();
2164 /* Delete the specified psymtab, and any others that reference it. */
2167 cashier_psymtab (pst
)
2168 struct partial_symtab
*pst
;
2170 struct partial_symtab
*ps
, *pprev
= NULL
;
2173 /* Find its previous psymtab in the chain */
2174 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
)
2183 /* Unhook it from the chain. */
2184 if (ps
== pst
->objfile
->psymtabs
)
2185 pst
->objfile
->psymtabs
= ps
->next
;
2187 pprev
->next
= ps
->next
;
2189 /* FIXME, we can't conveniently deallocate the entries in the
2190 partial_symbol lists (global_psymbols/static_psymbols) that
2191 this psymtab points to. These just take up space until all
2192 the psymtabs are reclaimed. Ditto the dependencies list and
2193 filename, which are all in the psymbol_obstack. */
2195 /* We need to cashier any psymtab that has this one as a dependency... */
2197 for (ps
= pst
->objfile
->psymtabs
; ps
; ps
= ps
->next
)
2199 for (i
= 0; i
< ps
->number_of_dependencies
; i
++)
2201 if (ps
->dependencies
[i
] == pst
)
2203 cashier_psymtab (ps
);
2204 goto again
; /* Must restart, chain has been munged. */
2211 /* If a symtab or psymtab for filename NAME is found, free it along
2212 with any dependent breakpoints, displays, etc.
2213 Used when loading new versions of object modules with the "add-file"
2214 command. This is only called on the top-level symtab or psymtab's name;
2215 it is not called for subsidiary files such as .h files.
2217 Return value is 1 if we blew away the environment, 0 if not.
2218 FIXME. The return valu appears to never be used.
2220 FIXME. I think this is not the best way to do this. We should
2221 work on being gentler to the environment while still cleaning up
2222 all stray pointers into the freed symtab. */
2225 free_named_symtabs (name
)
2229 /* FIXME: With the new method of each objfile having it's own
2230 psymtab list, this function needs serious rethinking. In particular,
2231 why was it ever necessary to toss psymtabs with specific compilation
2232 unit filenames, as opposed to all psymtabs from a particular symbol
2234 Well, the answer is that some systems permit reloading of particular
2235 compilation units. We want to blow away any old info about these
2236 compilation units, regardless of which objfiles they arrived in. --gnu. */
2238 register struct symtab
*s
;
2239 register struct symtab
*prev
;
2240 register struct partial_symtab
*ps
;
2241 struct blockvector
*bv
;
2244 /* We only wack things if the symbol-reload switch is set. */
2245 if (!symbol_reloading
)
2248 /* Some symbol formats have trouble providing file names... */
2249 if (name
== 0 || *name
== '\0')
2252 /* Look for a psymtab with the specified name. */
2255 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2257 if (STREQ (name
, ps
->filename
))
2259 cashier_psymtab (ps
); /* Blow it away...and its little dog, too. */
2260 goto again2
; /* Must restart, chain has been munged */
2264 /* Look for a symtab with the specified name. */
2266 for (s
= symtab_list
; s
; s
= s
->next
)
2268 if (STREQ (name
, s
->filename
))
2275 if (s
== symtab_list
)
2276 symtab_list
= s
->next
;
2278 prev
->next
= s
->next
;
2280 /* For now, queue a delete for all breakpoints, displays, etc., whether
2281 or not they depend on the symtab being freed. This should be
2282 changed so that only those data structures affected are deleted. */
2284 /* But don't delete anything if the symtab is empty.
2285 This test is necessary due to a bug in "dbxread.c" that
2286 causes empty symtabs to be created for N_SO symbols that
2287 contain the pathname of the object file. (This problem
2288 has been fixed in GDB 3.9x). */
2290 bv
= BLOCKVECTOR (s
);
2291 if (BLOCKVECTOR_NBLOCKS (bv
) > 2
2292 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
2293 || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)))
2295 complain (&oldsyms_complaint
, name
);
2297 clear_symtab_users_queued
++;
2298 make_cleanup (clear_symtab_users_once
, 0);
2303 complain (&empty_symtab_complaint
, name
);
2310 /* It is still possible that some breakpoints will be affected
2311 even though no symtab was found, since the file might have
2312 been compiled without debugging, and hence not be associated
2313 with a symtab. In order to handle this correctly, we would need
2314 to keep a list of text address ranges for undebuggable files.
2315 For now, we do nothing, since this is a fairly obscure case. */
2319 /* FIXME, what about the minimal symbol table? */
2326 /* Allocate and partially fill a partial symtab. It will be
2327 completely filled at the end of the symbol list.
2329 FILENAME is the name of the symbol-file we are reading from. */
2331 struct partial_symtab
*
2332 start_psymtab_common (objfile
, section_offsets
,
2333 filename
, textlow
, global_syms
, static_syms
)
2334 struct objfile
*objfile
;
2335 struct section_offsets
*section_offsets
;
2338 struct partial_symbol
**global_syms
;
2339 struct partial_symbol
**static_syms
;
2341 struct partial_symtab
*psymtab
;
2343 psymtab
= allocate_psymtab (filename
, objfile
);
2344 psymtab
->section_offsets
= section_offsets
;
2345 psymtab
->textlow
= textlow
;
2346 psymtab
->texthigh
= psymtab
->textlow
; /* default */
2347 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
2348 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
2352 /* Add a symbol with a long value to a psymtab.
2353 Since one arg is a struct, we pass in a ptr and deref it (sigh). */
2356 add_psymbol_to_list (name
, namelength
, namespace, class, list
, val
, coreaddr
,
2360 namespace_enum
namespace;
2361 enum address_class
class;
2362 struct psymbol_allocation_list
*list
;
2363 long val
; /* Value as a long */
2364 CORE_ADDR coreaddr
; /* Value as a CORE_ADDR */
2365 enum language language
;
2366 struct objfile
*objfile
;
2368 register struct partial_symbol
*psym
;
2369 char *buf
= alloca (namelength
+ 1);
2370 /* psymbol is static so that there will be no uninitialized gaps in the
2371 structure which might contain random data, causing cache misses in
2373 static struct partial_symbol psymbol
;
2375 /* Create local copy of the partial symbol */
2376 memcpy (buf
, name
, namelength
);
2377 buf
[namelength
] = '\0';
2378 SYMBOL_NAME (&psymbol
) = bcache (buf
, namelength
+ 1, &objfile
->psymbol_cache
);
2379 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
2382 SYMBOL_VALUE (&psymbol
) = val
;
2386 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
2388 SYMBOL_SECTION (&psymbol
) = 0;
2389 SYMBOL_LANGUAGE (&psymbol
) = language
;
2390 PSYMBOL_NAMESPACE (&psymbol
) = namespace;
2391 PSYMBOL_CLASS (&psymbol
) = class;
2392 SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol
, language
);
2394 /* Stash the partial symbol away in the cache */
2395 psym
= bcache (&psymbol
, sizeof (struct partial_symbol
), &objfile
->psymbol_cache
);
2397 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
2398 if (list
->next
>= list
->list
+ list
->size
)
2400 extend_psymbol_list (list
, objfile
);
2402 *list
->next
++ = psym
;
2403 OBJSTAT (objfile
, n_psyms
++);
2406 /* Add a symbol with a long value to a psymtab. This differs from
2407 * add_psymbol_to_list above in taking both a mangled and a demangled
2411 add_psymbol_with_dem_name_to_list (name
, namelength
, dem_name
, dem_namelength
,
2412 namespace, class, list
, val
, coreaddr
, language
, objfile
)
2417 namespace_enum
namespace;
2418 enum address_class
class;
2419 struct psymbol_allocation_list
*list
;
2420 long val
; /* Value as a long */
2421 CORE_ADDR coreaddr
; /* Value as a CORE_ADDR */
2422 enum language language
;
2423 struct objfile
*objfile
;
2425 register struct partial_symbol
*psym
;
2426 char *buf
= alloca (namelength
+ 1);
2427 /* psymbol is static so that there will be no uninitialized gaps in the
2428 structure which might contain random data, causing cache misses in
2430 static struct partial_symbol psymbol
;
2432 /* Create local copy of the partial symbol */
2434 memcpy (buf
, name
, namelength
);
2435 buf
[namelength
] = '\0';
2436 SYMBOL_NAME (&psymbol
) = bcache (buf
, namelength
+ 1, &objfile
->psymbol_cache
);
2438 buf
= alloca (dem_namelength
+ 1);
2439 memcpy (buf
, dem_name
, dem_namelength
);
2440 buf
[dem_namelength
] = '\0';
2445 case language_cplus
:
2446 SYMBOL_CPLUS_DEMANGLED_NAME (&psymbol
) =
2447 bcache (buf
, dem_namelength
+ 1, &objfile
->psymbol_cache
);
2449 case language_chill
:
2450 SYMBOL_CHILL_DEMANGLED_NAME (&psymbol
) =
2451 bcache (buf
, dem_namelength
+ 1, &objfile
->psymbol_cache
);
2453 /* FIXME What should be done for the default case? Ignoring for now. */
2456 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
2459 SYMBOL_VALUE (&psymbol
) = val
;
2463 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
2465 SYMBOL_SECTION (&psymbol
) = 0;
2466 SYMBOL_LANGUAGE (&psymbol
) = language
;
2467 PSYMBOL_NAMESPACE (&psymbol
) = namespace;
2468 PSYMBOL_CLASS (&psymbol
) = class;
2469 SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol
, language
);
2471 /* Stash the partial symbol away in the cache */
2472 psym
= bcache (&psymbol
, sizeof (struct partial_symbol
), &objfile
->psymbol_cache
);
2474 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
2475 if (list
->next
>= list
->list
+ list
->size
)
2477 extend_psymbol_list (list
, objfile
);
2479 *list
->next
++ = psym
;
2480 OBJSTAT (objfile
, n_psyms
++);
2483 /* Initialize storage for partial symbols. */
2486 init_psymbol_list (objfile
, total_symbols
)
2487 struct objfile
*objfile
;
2490 /* Free any previously allocated psymbol lists. */
2492 if (objfile
->global_psymbols
.list
)
2494 mfree (objfile
->md
, (PTR
) objfile
->global_psymbols
.list
);
2496 if (objfile
->static_psymbols
.list
)
2498 mfree (objfile
->md
, (PTR
) objfile
->static_psymbols
.list
);
2501 /* Current best guess is that approximately a twentieth
2502 of the total symbols (in a debugging file) are global or static
2505 objfile
->global_psymbols
.size
= total_symbols
/ 10;
2506 objfile
->static_psymbols
.size
= total_symbols
/ 10;
2508 if (objfile
->global_psymbols
.size
> 0)
2510 objfile
->global_psymbols
.next
=
2511 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
2512 xmmalloc (objfile
->md
, (objfile
->global_psymbols
.size
2513 * sizeof (struct partial_symbol
*)));
2515 if (objfile
->static_psymbols
.size
> 0)
2517 objfile
->static_psymbols
.next
=
2518 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
2519 xmmalloc (objfile
->md
, (objfile
->static_psymbols
.size
2520 * sizeof (struct partial_symbol
*)));
2525 The following code implements an abstraction for debugging overlay sections.
2527 The target model is as follows:
2528 1) The gnu linker will permit multiple sections to be mapped into the
2529 same VMA, each with its own unique LMA (or load address).
2530 2) It is assumed that some runtime mechanism exists for mapping the
2531 sections, one by one, from the load address into the VMA address.
2532 3) This code provides a mechanism for gdb to keep track of which
2533 sections should be considered to be mapped from the VMA to the LMA.
2534 This information is used for symbol lookup, and memory read/write.
2535 For instance, if a section has been mapped then its contents
2536 should be read from the VMA, otherwise from the LMA.
2538 Two levels of debugger support for overlays are available. One is
2539 "manual", in which the debugger relies on the user to tell it which
2540 overlays are currently mapped. This level of support is
2541 implemented entirely in the core debugger, and the information about
2542 whether a section is mapped is kept in the objfile->obj_section table.
2544 The second level of support is "automatic", and is only available if
2545 the target-specific code provides functionality to read the target's
2546 overlay mapping table, and translate its contents for the debugger
2547 (by updating the mapped state information in the obj_section tables).
2549 The interface is as follows:
2551 overlay map <name> -- tell gdb to consider this section mapped
2552 overlay unmap <name> -- tell gdb to consider this section unmapped
2553 overlay list -- list the sections that GDB thinks are mapped
2554 overlay read-target -- get the target's state of what's mapped
2555 overlay off/manual/auto -- set overlay debugging state
2556 Functional interface:
2557 find_pc_mapped_section(pc): if the pc is in the range of a mapped
2558 section, return that section.
2559 find_pc_overlay(pc): find any overlay section that contains
2560 the pc, either in its VMA or its LMA
2561 overlay_is_mapped(sect): true if overlay is marked as mapped
2562 section_is_overlay(sect): true if section's VMA != LMA
2563 pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA
2564 pc_in_unmapped_range(...): true if pc belongs to section's LMA
2565 overlay_mapped_address(...): map an address from section's LMA to VMA
2566 overlay_unmapped_address(...): map an address from section's VMA to LMA
2567 symbol_overlayed_address(...): Return a "current" address for symbol:
2568 either in VMA or LMA depending on whether
2569 the symbol's section is currently mapped
2572 /* Overlay debugging state: */
2574 int overlay_debugging
= 0; /* 0 == off, 1 == manual, -1 == auto */
2575 int overlay_cache_invalid
= 0; /* True if need to refresh mapped state */
2577 /* Target vector for refreshing overlay mapped state */
2578 static void simple_overlay_update
PARAMS ((struct obj_section
*));
2579 void (*target_overlay_update
) PARAMS ((struct obj_section
*))
2580 = simple_overlay_update
;
2582 /* Function: section_is_overlay (SECTION)
2583 Returns true if SECTION has VMA not equal to LMA, ie.
2584 SECTION is loaded at an address different from where it will "run". */
2587 section_is_overlay (section
)
2590 if (overlay_debugging
)
2591 if (section
&& section
->lma
!= 0 &&
2592 section
->vma
!= section
->lma
)
2598 /* Function: overlay_invalidate_all (void)
2599 Invalidate the mapped state of all overlay sections (mark it as stale). */
2602 overlay_invalidate_all ()
2604 struct objfile
*objfile
;
2605 struct obj_section
*sect
;
2607 ALL_OBJSECTIONS (objfile
, sect
)
2608 if (section_is_overlay (sect
->the_bfd_section
))
2609 sect
->ovly_mapped
= -1;
2612 /* Function: overlay_is_mapped (SECTION)
2613 Returns true if section is an overlay, and is currently mapped.
2614 Private: public access is thru function section_is_mapped.
2616 Access to the ovly_mapped flag is restricted to this function, so
2617 that we can do automatic update. If the global flag
2618 OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call
2619 overlay_invalidate_all. If the mapped state of the particular
2620 section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */
2623 overlay_is_mapped (osect
)
2624 struct obj_section
*osect
;
2626 if (osect
== 0 || !section_is_overlay (osect
->the_bfd_section
))
2629 switch (overlay_debugging
)
2633 return 0; /* overlay debugging off */
2634 case -1: /* overlay debugging automatic */
2635 /* Unles there is a target_overlay_update function,
2636 there's really nothing useful to do here (can't really go auto) */
2637 if (target_overlay_update
)
2639 if (overlay_cache_invalid
)
2641 overlay_invalidate_all ();
2642 overlay_cache_invalid
= 0;
2644 if (osect
->ovly_mapped
== -1)
2645 (*target_overlay_update
) (osect
);
2647 /* fall thru to manual case */
2648 case 1: /* overlay debugging manual */
2649 return osect
->ovly_mapped
== 1;
2653 /* Function: section_is_mapped
2654 Returns true if section is an overlay, and is currently mapped. */
2657 section_is_mapped (section
)
2660 struct objfile
*objfile
;
2661 struct obj_section
*osect
;
2663 if (overlay_debugging
)
2664 if (section
&& section_is_overlay (section
))
2665 ALL_OBJSECTIONS (objfile
, osect
)
2666 if (osect
->the_bfd_section
== section
)
2667 return overlay_is_mapped (osect
);
2672 /* Function: pc_in_unmapped_range
2673 If PC falls into the lma range of SECTION, return true, else false. */
2676 pc_in_unmapped_range (pc
, section
)
2682 if (overlay_debugging
)
2683 if (section
&& section_is_overlay (section
))
2685 size
= bfd_get_section_size_before_reloc (section
);
2686 if (section
->lma
<= pc
&& pc
< section
->lma
+ size
)
2692 /* Function: pc_in_mapped_range
2693 If PC falls into the vma range of SECTION, return true, else false. */
2696 pc_in_mapped_range (pc
, section
)
2702 if (overlay_debugging
)
2703 if (section
&& section_is_overlay (section
))
2705 size
= bfd_get_section_size_before_reloc (section
);
2706 if (section
->vma
<= pc
&& pc
< section
->vma
+ size
)
2712 /* Function: overlay_unmapped_address (PC, SECTION)
2713 Returns the address corresponding to PC in the unmapped (load) range.
2714 May be the same as PC. */
2717 overlay_unmapped_address (pc
, section
)
2721 if (overlay_debugging
)
2722 if (section
&& section_is_overlay (section
) &&
2723 pc_in_mapped_range (pc
, section
))
2724 return pc
+ section
->lma
- section
->vma
;
2729 /* Function: overlay_mapped_address (PC, SECTION)
2730 Returns the address corresponding to PC in the mapped (runtime) range.
2731 May be the same as PC. */
2734 overlay_mapped_address (pc
, section
)
2738 if (overlay_debugging
)
2739 if (section
&& section_is_overlay (section
) &&
2740 pc_in_unmapped_range (pc
, section
))
2741 return pc
+ section
->vma
- section
->lma
;
2747 /* Function: symbol_overlayed_address
2748 Return one of two addresses (relative to the VMA or to the LMA),
2749 depending on whether the section is mapped or not. */
2752 symbol_overlayed_address (address
, section
)
2756 if (overlay_debugging
)
2758 /* If the symbol has no section, just return its regular address. */
2761 /* If the symbol's section is not an overlay, just return its address */
2762 if (!section_is_overlay (section
))
2764 /* If the symbol's section is mapped, just return its address */
2765 if (section_is_mapped (section
))
2768 * HOWEVER: if the symbol is in an overlay section which is NOT mapped,
2769 * then return its LOADED address rather than its vma address!!
2771 return overlay_unmapped_address (address
, section
);
2776 /* Function: find_pc_overlay (PC)
2777 Return the best-match overlay section for PC:
2778 If PC matches a mapped overlay section's VMA, return that section.
2779 Else if PC matches an unmapped section's VMA, return that section.
2780 Else if PC matches an unmapped section's LMA, return that section. */
2783 find_pc_overlay (pc
)
2786 struct objfile
*objfile
;
2787 struct obj_section
*osect
, *best_match
= NULL
;
2789 if (overlay_debugging
)
2790 ALL_OBJSECTIONS (objfile
, osect
)
2791 if (section_is_overlay (osect
->the_bfd_section
))
2793 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
))
2795 if (overlay_is_mapped (osect
))
2796 return osect
->the_bfd_section
;
2800 else if (pc_in_unmapped_range (pc
, osect
->the_bfd_section
))
2803 return best_match
? best_match
->the_bfd_section
: NULL
;
2806 /* Function: find_pc_mapped_section (PC)
2807 If PC falls into the VMA address range of an overlay section that is
2808 currently marked as MAPPED, return that section. Else return NULL. */
2811 find_pc_mapped_section (pc
)
2814 struct objfile
*objfile
;
2815 struct obj_section
*osect
;
2817 if (overlay_debugging
)
2818 ALL_OBJSECTIONS (objfile
, osect
)
2819 if (pc_in_mapped_range (pc
, osect
->the_bfd_section
) &&
2820 overlay_is_mapped (osect
))
2821 return osect
->the_bfd_section
;
2826 /* Function: list_overlays_command
2827 Print a list of mapped sections and their PC ranges */
2830 list_overlays_command (args
, from_tty
)
2835 struct objfile
*objfile
;
2836 struct obj_section
*osect
;
2838 if (overlay_debugging
)
2839 ALL_OBJSECTIONS (objfile
, osect
)
2840 if (overlay_is_mapped (osect
))
2846 vma
= bfd_section_vma (objfile
->obfd
, osect
->the_bfd_section
);
2847 lma
= bfd_section_lma (objfile
->obfd
, osect
->the_bfd_section
);
2848 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
2849 name
= bfd_section_name (objfile
->obfd
, osect
->the_bfd_section
);
2851 printf_filtered ("Section %s, loaded at ", name
);
2852 print_address_numeric (lma
, 1, gdb_stdout
);
2853 puts_filtered (" - ");
2854 print_address_numeric (lma
+ size
, 1, gdb_stdout
);
2855 printf_filtered (", mapped at ");
2856 print_address_numeric (vma
, 1, gdb_stdout
);
2857 puts_filtered (" - ");
2858 print_address_numeric (vma
+ size
, 1, gdb_stdout
);
2859 puts_filtered ("\n");
2864 printf_filtered ("No sections are mapped.\n");
2867 /* Function: map_overlay_command
2868 Mark the named section as mapped (ie. residing at its VMA address). */
2871 map_overlay_command (args
, from_tty
)
2875 struct objfile
*objfile
, *objfile2
;
2876 struct obj_section
*sec
, *sec2
;
2879 if (!overlay_debugging
)
2880 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2882 if (args
== 0 || *args
== 0)
2883 error ("Argument required: name of an overlay section");
2885 /* First, find a section matching the user supplied argument */
2886 ALL_OBJSECTIONS (objfile
, sec
)
2887 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2889 /* Now, check to see if the section is an overlay. */
2890 bfdsec
= sec
->the_bfd_section
;
2891 if (!section_is_overlay (bfdsec
))
2892 continue; /* not an overlay section */
2894 /* Mark the overlay as "mapped" */
2895 sec
->ovly_mapped
= 1;
2897 /* Next, make a pass and unmap any sections that are
2898 overlapped by this new section: */
2899 ALL_OBJSECTIONS (objfile2
, sec2
)
2900 if (sec2
->ovly_mapped
&&
2902 sec
->the_bfd_section
!= sec2
->the_bfd_section
&&
2903 (pc_in_mapped_range (sec2
->addr
, sec
->the_bfd_section
) ||
2904 pc_in_mapped_range (sec2
->endaddr
, sec
->the_bfd_section
)))
2907 printf_filtered ("Note: section %s unmapped by overlap\n",
2908 bfd_section_name (objfile
->obfd
,
2909 sec2
->the_bfd_section
));
2910 sec2
->ovly_mapped
= 0; /* sec2 overlaps sec: unmap sec2 */
2914 error ("No overlay section called %s", args
);
2917 /* Function: unmap_overlay_command
2918 Mark the overlay section as unmapped
2919 (ie. resident in its LMA address range, rather than the VMA range). */
2922 unmap_overlay_command (args
, from_tty
)
2926 struct objfile
*objfile
;
2927 struct obj_section
*sec
;
2929 if (!overlay_debugging
)
2930 error ("Overlay debugging not enabled. Use the 'OVERLAY ON' command.");
2932 if (args
== 0 || *args
== 0)
2933 error ("Argument required: name of an overlay section");
2935 /* First, find a section matching the user supplied argument */
2936 ALL_OBJSECTIONS (objfile
, sec
)
2937 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
2939 if (!sec
->ovly_mapped
)
2940 error ("Section %s is not mapped", args
);
2941 sec
->ovly_mapped
= 0;
2944 error ("No overlay section called %s", args
);
2947 /* Function: overlay_auto_command
2948 A utility command to turn on overlay debugging.
2949 Possibly this should be done via a set/show command. */
2952 overlay_auto_command (args
, from_tty
)
2956 overlay_debugging
= -1;
2958 printf_filtered ("Automatic overlay debugging enabled.");
2961 /* Function: overlay_manual_command
2962 A utility command to turn on overlay debugging.
2963 Possibly this should be done via a set/show command. */
2966 overlay_manual_command (args
, from_tty
)
2970 overlay_debugging
= 1;
2972 printf_filtered ("Overlay debugging enabled.");
2975 /* Function: overlay_off_command
2976 A utility command to turn on overlay debugging.
2977 Possibly this should be done via a set/show command. */
2980 overlay_off_command (args
, from_tty
)
2984 overlay_debugging
= 0;
2986 printf_filtered ("Overlay debugging disabled.");
2990 overlay_load_command (args
, from_tty
)
2994 if (target_overlay_update
)
2995 (*target_overlay_update
) (NULL
);
2997 error ("This target does not know how to read its overlay state.");
3000 /* Function: overlay_command
3001 A place-holder for a mis-typed command */
3003 /* Command list chain containing all defined "overlay" subcommands. */
3004 struct cmd_list_element
*overlaylist
;
3007 overlay_command (args
, from_tty
)
3012 ("\"overlay\" must be followed by the name of an overlay command.\n");
3013 help_list (overlaylist
, "overlay ", -1, gdb_stdout
);
3017 /* Target Overlays for the "Simplest" overlay manager:
3019 This is GDB's default target overlay layer. It works with the
3020 minimal overlay manager supplied as an example by Cygnus. The
3021 entry point is via a function pointer "target_overlay_update",
3022 so targets that use a different runtime overlay manager can
3023 substitute their own overlay_update function and take over the
3026 The overlay_update function pokes around in the target's data structures
3027 to see what overlays are mapped, and updates GDB's overlay mapping with
3030 In this simple implementation, the target data structures are as follows:
3031 unsigned _novlys; /# number of overlay sections #/
3032 unsigned _ovly_table[_novlys][4] = {
3033 {VMA, SIZE, LMA, MAPPED}, /# one entry per overlay section #/
3034 {..., ..., ..., ...},
3036 unsigned _novly_regions; /# number of overlay regions #/
3037 unsigned _ovly_region_table[_novly_regions][3] = {
3038 {VMA, SIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/
3041 These functions will attempt to update GDB's mappedness state in the
3042 symbol section table, based on the target's mappedness state.
3044 To do this, we keep a cached copy of the target's _ovly_table, and
3045 attempt to detect when the cached copy is invalidated. The main
3046 entry point is "simple_overlay_update(SECT), which looks up SECT in
3047 the cached table and re-reads only the entry for that section from
3048 the target (whenever possible).
3051 /* Cached, dynamically allocated copies of the target data structures: */
3052 static unsigned (*cache_ovly_table
)[4] = 0;
3054 static unsigned (*cache_ovly_region_table
)[3] = 0;
3056 static unsigned cache_novlys
= 0;
3058 static unsigned cache_novly_regions
= 0;
3060 static CORE_ADDR cache_ovly_table_base
= 0;
3062 static CORE_ADDR cache_ovly_region_table_base
= 0;
3066 VMA
, SIZE
, LMA
, MAPPED
3068 #define TARGET_LONG_BYTES (TARGET_LONG_BIT / TARGET_CHAR_BIT)
3070 /* Throw away the cached copy of _ovly_table */
3072 simple_free_overlay_table ()
3074 if (cache_ovly_table
)
3075 free (cache_ovly_table
);
3077 cache_ovly_table
= NULL
;
3078 cache_ovly_table_base
= 0;
3082 /* Throw away the cached copy of _ovly_region_table */
3084 simple_free_overlay_region_table ()
3086 if (cache_ovly_region_table
)
3087 free (cache_ovly_region_table
);
3088 cache_novly_regions
= 0;
3089 cache_ovly_region_table
= NULL
;
3090 cache_ovly_region_table_base
= 0;
3094 /* Read an array of ints from the target into a local buffer.
3095 Convert to host order. int LEN is number of ints */
3097 read_target_long_array (memaddr
, myaddr
, len
)
3099 unsigned int *myaddr
;
3102 char *buf
= alloca (len
* TARGET_LONG_BYTES
);
3105 read_memory (memaddr
, buf
, len
* TARGET_LONG_BYTES
);
3106 for (i
= 0; i
< len
; i
++)
3107 myaddr
[i
] = extract_unsigned_integer (TARGET_LONG_BYTES
* i
+ buf
,
3111 /* Find and grab a copy of the target _ovly_table
3112 (and _novlys, which is needed for the table's size) */
3114 simple_read_overlay_table ()
3116 struct minimal_symbol
*msym
;
3118 simple_free_overlay_table ();
3119 msym
= lookup_minimal_symbol ("_novlys", 0, 0);
3121 cache_novlys
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
3123 return 0; /* failure */
3124 cache_ovly_table
= (void *) xmalloc (cache_novlys
* sizeof (*cache_ovly_table
));
3125 if (cache_ovly_table
!= NULL
)
3127 msym
= lookup_minimal_symbol ("_ovly_table", 0, 0);
3130 cache_ovly_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
3131 read_target_long_array (cache_ovly_table_base
,
3132 (int *) cache_ovly_table
,
3136 return 0; /* failure */
3139 return 0; /* failure */
3140 return 1; /* SUCCESS */
3144 /* Find and grab a copy of the target _ovly_region_table
3145 (and _novly_regions, which is needed for the table's size) */
3147 simple_read_overlay_region_table ()
3149 struct minimal_symbol
*msym
;
3151 simple_free_overlay_region_table ();
3152 msym
= lookup_minimal_symbol ("_novly_regions", 0, 0);
3154 cache_novly_regions
= read_memory_integer (SYMBOL_VALUE_ADDRESS (msym
), 4);
3156 return 0; /* failure */
3157 cache_ovly_region_table
= (void *) xmalloc (cache_novly_regions
* 12);
3158 if (cache_ovly_region_table
!= NULL
)
3160 msym
= lookup_minimal_symbol ("_ovly_region_table", 0, 0);
3163 cache_ovly_region_table_base
= SYMBOL_VALUE_ADDRESS (msym
);
3164 read_target_long_array (cache_ovly_region_table_base
,
3165 (int *) cache_ovly_region_table
,
3166 cache_novly_regions
* 3);
3169 return 0; /* failure */
3172 return 0; /* failure */
3173 return 1; /* SUCCESS */
3177 /* Function: simple_overlay_update_1
3178 A helper function for simple_overlay_update. Assuming a cached copy
3179 of _ovly_table exists, look through it to find an entry whose vma,
3180 lma and size match those of OSECT. Re-read the entry and make sure
3181 it still matches OSECT (else the table may no longer be valid).
3182 Set OSECT's mapped state to match the entry. Return: 1 for
3183 success, 0 for failure. */
3186 simple_overlay_update_1 (osect
)
3187 struct obj_section
*osect
;
3191 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
3192 for (i
= 0; i
< cache_novlys
; i
++)
3193 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
3194 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
3195 cache_ovly_table[i][SIZE] == size */ )
3197 read_target_long_array (cache_ovly_table_base
+ i
* TARGET_LONG_BYTES
,
3198 (int *) cache_ovly_table
[i
], 4);
3199 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
3200 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
3201 cache_ovly_table[i][SIZE] == size */ )
3203 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3206 else /* Warning! Warning! Target's ovly table has changed! */
3212 /* Function: simple_overlay_update
3213 If OSECT is NULL, then update all sections' mapped state
3214 (after re-reading the entire target _ovly_table).
3215 If OSECT is non-NULL, then try to find a matching entry in the
3216 cached ovly_table and update only OSECT's mapped state.
3217 If a cached entry can't be found or the cache isn't valid, then
3218 re-read the entire cache, and go ahead and update all sections. */
3221 simple_overlay_update (osect
)
3222 struct obj_section
*osect
;
3224 struct objfile
*objfile
;
3226 /* Were we given an osect to look up? NULL means do all of them. */
3228 /* Have we got a cached copy of the target's overlay table? */
3229 if (cache_ovly_table
!= NULL
)
3230 /* Does its cached location match what's currently in the symtab? */
3231 if (cache_ovly_table_base
==
3232 SYMBOL_VALUE_ADDRESS (lookup_minimal_symbol ("_ovly_table", 0, 0)))
3233 /* Then go ahead and try to look up this single section in the cache */
3234 if (simple_overlay_update_1 (osect
))
3235 /* Found it! We're done. */
3238 /* Cached table no good: need to read the entire table anew.
3239 Or else we want all the sections, in which case it's actually
3240 more efficient to read the whole table in one block anyway. */
3242 if (simple_read_overlay_table () == 0) /* read failed? No table? */
3244 warning ("Failed to read the target overlay mapping table.");
3247 /* Now may as well update all sections, even if only one was requested. */
3248 ALL_OBJSECTIONS (objfile
, osect
)
3249 if (section_is_overlay (osect
->the_bfd_section
))
3253 size
= bfd_get_section_size_before_reloc (osect
->the_bfd_section
);
3254 for (i
= 0; i
< cache_novlys
; i
++)
3255 if (cache_ovly_table
[i
][VMA
] == osect
->the_bfd_section
->vma
&&
3256 cache_ovly_table
[i
][LMA
] == osect
->the_bfd_section
->lma
/* &&
3257 cache_ovly_table[i][SIZE] == size */ )
3258 { /* obj_section matches i'th entry in ovly_table */
3259 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3260 break; /* finished with inner for loop: break out */
3267 _initialize_symfile ()
3269 struct cmd_list_element
*c
;
3271 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
,
3272 "Load symbol table from executable file FILE.\n\
3273 The `file' command can also load symbol tables, as well as setting the file\n\
3274 to execute.", &cmdlist
);
3275 c
->completer
= filename_completer
;
3277 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
,
3278 "Usage: add-symbol-file FILE ADDR [DATA_ADDR [BSS_ADDR]]\n\
3279 or: add-symbol-file FILE -T<SECT> <SECT_ADDR> -T<SECT> <SECT_ADDR> ...\n\
3280 Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
3281 ADDR is the starting address of the file's text.\n\
3282 The optional arguments, DATA_ADDR and BSS_ADDR, should be specified\n\
3283 if the data and bss segments are not contiguous with the text.\n\
3284 For complicated cases, SECT is a section name to be loaded at SECT_ADDR.",
3286 c
->completer
= filename_completer
;
3288 c
= add_cmd ("add-shared-symbol-files", class_files
,
3289 add_shared_symbol_files_command
,
3290 "Load the symbols from shared objects in the dynamic linker's link map.",
3292 c
= add_alias_cmd ("assf", "add-shared-symbol-files", class_files
, 1,
3295 c
= add_cmd ("load", class_files
, load_command
,
3296 "Dynamically load FILE into the running program, and record its symbols\n\
3297 for access from GDB.", &cmdlist
);
3298 c
->completer
= filename_completer
;
3301 (add_set_cmd ("symbol-reloading", class_support
, var_boolean
,
3302 (char *) &symbol_reloading
,
3303 "Set dynamic symbol table reloading multiple times in one run.",
3307 add_prefix_cmd ("overlay", class_support
, overlay_command
,
3308 "Commands for debugging overlays.", &overlaylist
,
3309 "overlay ", 0, &cmdlist
);
3311 add_com_alias ("ovly", "overlay", class_alias
, 1);
3312 add_com_alias ("ov", "overlay", class_alias
, 1);
3314 add_cmd ("map-overlay", class_support
, map_overlay_command
,
3315 "Assert that an overlay section is mapped.", &overlaylist
);
3317 add_cmd ("unmap-overlay", class_support
, unmap_overlay_command
,
3318 "Assert that an overlay section is unmapped.", &overlaylist
);
3320 add_cmd ("list-overlays", class_support
, list_overlays_command
,
3321 "List mappings of overlay sections.", &overlaylist
);
3323 add_cmd ("manual", class_support
, overlay_manual_command
,
3324 "Enable overlay debugging.", &overlaylist
);
3325 add_cmd ("off", class_support
, overlay_off_command
,
3326 "Disable overlay debugging.", &overlaylist
);
3327 add_cmd ("auto", class_support
, overlay_auto_command
,
3328 "Enable automatic overlay debugging.", &overlaylist
);
3329 add_cmd ("load-target", class_support
, overlay_load_command
,
3330 "Read the overlay mapping state from the target.", &overlaylist
);
3332 /* Filename extension to source language lookup table: */
3333 init_filename_language_table ();
3334 c
= add_set_cmd ("extension-language", class_files
, var_string_noescape
,
3336 "Set mapping between filename extension and source language.\n\
3337 Usage: set extension-language .foo bar",
3339 c
->function
.cfunc
= set_ext_lang_command
;
3341 add_info ("extensions", info_ext_lang_command
,
3342 "All filename extensions associated with a source language.");
3345 (add_set_cmd ("download-write-size", class_obscure
,
3346 var_integer
, (char *) &download_write_size
,
3347 "Set the write size used when downloading a program.\n"
3348 "Only used when downloading a program onto a remote\n"
3349 "target. Specify zero, or a negative value, to disable\n"
3350 "blocked writes. The actual size of each transfer is also\n"
3351 "limited by the size of the target packet and the memory\n"