1 /* Generic symbol file reading for the GNU debugger, GDB.
3 Copyright (C) 1990-2013 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
35 #include "breakpoint.h"
37 #include "complaints.h"
41 #include "filenames.h" /* for DOSish file names */
42 #include "gdb-stabs.h"
43 #include "gdb_obstack.h"
44 #include "completer.h"
47 #include "readline/readline.h"
48 #include "gdb_assert.h"
52 #include "parser-defs.h"
60 #include <sys/types.h>
62 #include "gdb_string.h"
70 int (*deprecated_ui_load_progress_hook
) (const char *section
,
72 void (*deprecated_show_load_progress
) (const char *section
,
73 unsigned long section_sent
,
74 unsigned long section_size
,
75 unsigned long total_sent
,
76 unsigned long total_size
);
77 void (*deprecated_pre_add_symbol_hook
) (const char *);
78 void (*deprecated_post_add_symbol_hook
) (void);
80 static void clear_symtab_users_cleanup (void *ignore
);
82 /* Global variables owned by this file. */
83 int readnow_symbol_files
; /* Read full symbols immediately. */
85 /* Functions this file defines. */
87 static void load_command (char *, int);
89 static void symbol_file_add_main_1 (char *args
, int from_tty
, int flags
);
91 static void add_symbol_file_command (char *, int);
93 bfd
*symfile_bfd_open (char *);
95 int get_section_index (struct objfile
*, char *);
97 static const struct sym_fns
*find_sym_fns (bfd
*);
99 static void decrement_reading_symtab (void *);
101 static void overlay_invalidate_all (void);
103 static void overlay_auto_command (char *, int);
105 static void overlay_manual_command (char *, int);
107 static void overlay_off_command (char *, int);
109 static void overlay_load_command (char *, int);
111 static void overlay_command (char *, int);
113 static void simple_free_overlay_table (void);
115 static void read_target_long_array (CORE_ADDR
, unsigned int *, int, int,
118 static int simple_read_overlay_table (void);
120 static int simple_overlay_update_1 (struct obj_section
*);
122 static void add_filename_language (char *ext
, enum language lang
);
124 static void info_ext_lang_command (char *args
, int from_tty
);
126 static void init_filename_language_table (void);
128 static void symfile_find_segment_sections (struct objfile
*objfile
);
130 void _initialize_symfile (void);
132 /* List of all available sym_fns. On gdb startup, each object file reader
133 calls add_symtab_fns() to register information on each format it is
136 typedef const struct sym_fns
*sym_fns_ptr
;
137 DEF_VEC_P (sym_fns_ptr
);
139 static VEC (sym_fns_ptr
) *symtab_fns
= NULL
;
141 /* If non-zero, shared library symbols will be added automatically
142 when the inferior is created, new libraries are loaded, or when
143 attaching to the inferior. This is almost always what users will
144 want to have happen; but for very large programs, the startup time
145 will be excessive, and so if this is a problem, the user can clear
146 this flag and then add the shared library symbols as needed. Note
147 that there is a potential for confusion, since if the shared
148 library symbols are not loaded, commands like "info fun" will *not*
149 report all the functions that are actually present. */
151 int auto_solib_add
= 1;
154 /* Make a null terminated copy of the string at PTR with SIZE characters in
155 the obstack pointed to by OBSTACKP . Returns the address of the copy.
156 Note that the string at PTR does not have to be null terminated, I.e. it
157 may be part of a larger string and we are only saving a substring. */
160 obsavestring (const char *ptr
, int size
, struct obstack
*obstackp
)
162 char *p
= (char *) obstack_alloc (obstackp
, size
+ 1);
163 /* Open-coded memcpy--saves function call time. These strings are usually
164 short. FIXME: Is this really still true with a compiler that can
167 const char *p1
= ptr
;
169 const char *end
= ptr
+ size
;
178 /* Concatenate NULL terminated variable argument list of `const char *'
179 strings; return the new string. Space is found in the OBSTACKP.
180 Argument list must be terminated by a sentinel expression `(char *)
184 obconcat (struct obstack
*obstackp
, ...)
188 va_start (ap
, obstackp
);
191 const char *s
= va_arg (ap
, const char *);
196 obstack_grow_str (obstackp
, s
);
199 obstack_1grow (obstackp
, 0);
201 return obstack_finish (obstackp
);
204 /* True if we are reading a symbol table. */
206 int currently_reading_symtab
= 0;
209 decrement_reading_symtab (void *dummy
)
211 currently_reading_symtab
--;
214 /* Increment currently_reading_symtab and return a cleanup that can be
215 used to decrement it. */
217 increment_reading_symtab (void)
219 ++currently_reading_symtab
;
220 return make_cleanup (decrement_reading_symtab
, NULL
);
223 /* Remember the lowest-addressed loadable section we've seen.
224 This function is called via bfd_map_over_sections.
226 In case of equal vmas, the section with the largest size becomes the
227 lowest-addressed loadable section.
229 If the vmas and sizes are equal, the last section is considered the
230 lowest-addressed loadable section. */
233 find_lowest_section (bfd
*abfd
, asection
*sect
, void *obj
)
235 asection
**lowest
= (asection
**) obj
;
237 if (0 == (bfd_get_section_flags (abfd
, sect
) & (SEC_ALLOC
| SEC_LOAD
)))
240 *lowest
= sect
; /* First loadable section */
241 else if (bfd_section_vma (abfd
, *lowest
) > bfd_section_vma (abfd
, sect
))
242 *lowest
= sect
; /* A lower loadable section */
243 else if (bfd_section_vma (abfd
, *lowest
) == bfd_section_vma (abfd
, sect
)
244 && (bfd_section_size (abfd
, (*lowest
))
245 <= bfd_section_size (abfd
, sect
)))
249 /* Create a new section_addr_info, with room for NUM_SECTIONS. */
251 struct section_addr_info
*
252 alloc_section_addr_info (size_t num_sections
)
254 struct section_addr_info
*sap
;
257 size
= (sizeof (struct section_addr_info
)
258 + sizeof (struct other_sections
) * (num_sections
- 1));
259 sap
= (struct section_addr_info
*) xmalloc (size
);
260 memset (sap
, 0, size
);
261 sap
->num_sections
= num_sections
;
266 /* Build (allocate and populate) a section_addr_info struct from
267 an existing section table. */
269 extern struct section_addr_info
*
270 build_section_addr_info_from_section_table (const struct target_section
*start
,
271 const struct target_section
*end
)
273 struct section_addr_info
*sap
;
274 const struct target_section
*stp
;
277 sap
= alloc_section_addr_info (end
- start
);
279 for (stp
= start
, oidx
= 0; stp
!= end
; stp
++)
281 if (bfd_get_section_flags (stp
->bfd
,
282 stp
->the_bfd_section
) & (SEC_ALLOC
| SEC_LOAD
)
283 && oidx
< end
- start
)
285 sap
->other
[oidx
].addr
= stp
->addr
;
286 sap
->other
[oidx
].name
287 = xstrdup (bfd_section_name (stp
->bfd
, stp
->the_bfd_section
));
288 sap
->other
[oidx
].sectindex
= stp
->the_bfd_section
->index
;
296 /* Create a section_addr_info from section offsets in ABFD. */
298 static struct section_addr_info
*
299 build_section_addr_info_from_bfd (bfd
*abfd
)
301 struct section_addr_info
*sap
;
303 struct bfd_section
*sec
;
305 sap
= alloc_section_addr_info (bfd_count_sections (abfd
));
306 for (i
= 0, sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
307 if (bfd_get_section_flags (abfd
, sec
) & (SEC_ALLOC
| SEC_LOAD
))
309 sap
->other
[i
].addr
= bfd_get_section_vma (abfd
, sec
);
310 sap
->other
[i
].name
= xstrdup (bfd_get_section_name (abfd
, sec
));
311 sap
->other
[i
].sectindex
= sec
->index
;
317 /* Create a section_addr_info from section offsets in OBJFILE. */
319 struct section_addr_info
*
320 build_section_addr_info_from_objfile (const struct objfile
*objfile
)
322 struct section_addr_info
*sap
;
325 /* Before reread_symbols gets rewritten it is not safe to call:
326 gdb_assert (objfile->num_sections == bfd_count_sections (objfile->obfd));
328 sap
= build_section_addr_info_from_bfd (objfile
->obfd
);
329 for (i
= 0; i
< sap
->num_sections
&& sap
->other
[i
].name
; i
++)
331 int sectindex
= sap
->other
[i
].sectindex
;
333 sap
->other
[i
].addr
+= objfile
->section_offsets
->offsets
[sectindex
];
338 /* Free all memory allocated by build_section_addr_info_from_section_table. */
341 free_section_addr_info (struct section_addr_info
*sap
)
345 for (idx
= 0; idx
< sap
->num_sections
; idx
++)
346 if (sap
->other
[idx
].name
)
347 xfree (sap
->other
[idx
].name
);
352 /* Initialize OBJFILE's sect_index_* members. */
354 init_objfile_sect_indices (struct objfile
*objfile
)
359 sect
= bfd_get_section_by_name (objfile
->obfd
, ".text");
361 objfile
->sect_index_text
= sect
->index
;
363 sect
= bfd_get_section_by_name (objfile
->obfd
, ".data");
365 objfile
->sect_index_data
= sect
->index
;
367 sect
= bfd_get_section_by_name (objfile
->obfd
, ".bss");
369 objfile
->sect_index_bss
= sect
->index
;
371 sect
= bfd_get_section_by_name (objfile
->obfd
, ".rodata");
373 objfile
->sect_index_rodata
= sect
->index
;
375 /* This is where things get really weird... We MUST have valid
376 indices for the various sect_index_* members or gdb will abort.
377 So if for example, there is no ".text" section, we have to
378 accomodate that. First, check for a file with the standard
379 one or two segments. */
381 symfile_find_segment_sections (objfile
);
383 /* Except when explicitly adding symbol files at some address,
384 section_offsets contains nothing but zeros, so it doesn't matter
385 which slot in section_offsets the individual sect_index_* members
386 index into. So if they are all zero, it is safe to just point
387 all the currently uninitialized indices to the first slot. But
388 beware: if this is the main executable, it may be relocated
389 later, e.g. by the remote qOffsets packet, and then this will
390 be wrong! That's why we try segments first. */
392 for (i
= 0; i
< objfile
->num_sections
; i
++)
394 if (ANOFFSET (objfile
->section_offsets
, i
) != 0)
399 if (i
== objfile
->num_sections
)
401 if (objfile
->sect_index_text
== -1)
402 objfile
->sect_index_text
= 0;
403 if (objfile
->sect_index_data
== -1)
404 objfile
->sect_index_data
= 0;
405 if (objfile
->sect_index_bss
== -1)
406 objfile
->sect_index_bss
= 0;
407 if (objfile
->sect_index_rodata
== -1)
408 objfile
->sect_index_rodata
= 0;
412 /* The arguments to place_section. */
414 struct place_section_arg
416 struct section_offsets
*offsets
;
420 /* Find a unique offset to use for loadable section SECT if
421 the user did not provide an offset. */
424 place_section (bfd
*abfd
, asection
*sect
, void *obj
)
426 struct place_section_arg
*arg
= obj
;
427 CORE_ADDR
*offsets
= arg
->offsets
->offsets
, start_addr
;
429 ULONGEST align
= ((ULONGEST
) 1) << bfd_get_section_alignment (abfd
, sect
);
431 /* We are only interested in allocated sections. */
432 if ((bfd_get_section_flags (abfd
, sect
) & SEC_ALLOC
) == 0)
435 /* If the user specified an offset, honor it. */
436 if (offsets
[sect
->index
] != 0)
439 /* Otherwise, let's try to find a place for the section. */
440 start_addr
= (arg
->lowest
+ align
- 1) & -align
;
447 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
; cur_sec
= cur_sec
->next
)
449 int indx
= cur_sec
->index
;
451 /* We don't need to compare against ourself. */
455 /* We can only conflict with allocated sections. */
456 if ((bfd_get_section_flags (abfd
, cur_sec
) & SEC_ALLOC
) == 0)
459 /* If the section offset is 0, either the section has not been placed
460 yet, or it was the lowest section placed (in which case LOWEST
461 will be past its end). */
462 if (offsets
[indx
] == 0)
465 /* If this section would overlap us, then we must move up. */
466 if (start_addr
+ bfd_get_section_size (sect
) > offsets
[indx
]
467 && start_addr
< offsets
[indx
] + bfd_get_section_size (cur_sec
))
469 start_addr
= offsets
[indx
] + bfd_get_section_size (cur_sec
);
470 start_addr
= (start_addr
+ align
- 1) & -align
;
475 /* Otherwise, we appear to be OK. So far. */
480 offsets
[sect
->index
] = start_addr
;
481 arg
->lowest
= start_addr
+ bfd_get_section_size (sect
);
484 /* Store struct section_addr_info as prepared (made relative and with SECTINDEX
485 filled-in) by addr_info_make_relative into SECTION_OFFSETS of NUM_SECTIONS
489 relative_addr_info_to_section_offsets (struct section_offsets
*section_offsets
,
491 struct section_addr_info
*addrs
)
495 memset (section_offsets
, 0, SIZEOF_N_SECTION_OFFSETS (num_sections
));
497 /* Now calculate offsets for section that were specified by the caller. */
498 for (i
= 0; i
< addrs
->num_sections
&& addrs
->other
[i
].name
; i
++)
500 struct other_sections
*osp
;
502 osp
= &addrs
->other
[i
];
503 if (osp
->sectindex
== -1)
506 /* Record all sections in offsets. */
507 /* The section_offsets in the objfile are here filled in using
509 section_offsets
->offsets
[osp
->sectindex
] = osp
->addr
;
513 /* Transform section name S for a name comparison. prelink can split section
514 `.bss' into two sections `.dynbss' and `.bss' (in this order). Similarly
515 prelink can split `.sbss' into `.sdynbss' and `.sbss'. Use virtual address
516 of the new `.dynbss' (`.sdynbss') section as the adjacent new `.bss'
517 (`.sbss') section has invalid (increased) virtual address. */
520 addr_section_name (const char *s
)
522 if (strcmp (s
, ".dynbss") == 0)
524 if (strcmp (s
, ".sdynbss") == 0)
530 /* qsort comparator for addrs_section_sort. Sort entries in ascending order by
531 their (name, sectindex) pair. sectindex makes the sort by name stable. */
534 addrs_section_compar (const void *ap
, const void *bp
)
536 const struct other_sections
*a
= *((struct other_sections
**) ap
);
537 const struct other_sections
*b
= *((struct other_sections
**) bp
);
540 retval
= strcmp (addr_section_name (a
->name
), addr_section_name (b
->name
));
544 return a
->sectindex
- b
->sectindex
;
547 /* Provide sorted array of pointers to sections of ADDRS. The array is
548 terminated by NULL. Caller is responsible to call xfree for it. */
550 static struct other_sections
**
551 addrs_section_sort (struct section_addr_info
*addrs
)
553 struct other_sections
**array
;
556 /* `+ 1' for the NULL terminator. */
557 array
= xmalloc (sizeof (*array
) * (addrs
->num_sections
+ 1));
558 for (i
= 0; i
< addrs
->num_sections
&& addrs
->other
[i
].name
; i
++)
559 array
[i
] = &addrs
->other
[i
];
562 qsort (array
, i
, sizeof (*array
), addrs_section_compar
);
567 /* Relativize absolute addresses in ADDRS into offsets based on ABFD. Fill-in
568 also SECTINDEXes specific to ABFD there. This function can be used to
569 rebase ADDRS to start referencing different BFD than before. */
572 addr_info_make_relative (struct section_addr_info
*addrs
, bfd
*abfd
)
574 asection
*lower_sect
;
575 CORE_ADDR lower_offset
;
577 struct cleanup
*my_cleanup
;
578 struct section_addr_info
*abfd_addrs
;
579 struct other_sections
**addrs_sorted
, **abfd_addrs_sorted
;
580 struct other_sections
**addrs_to_abfd_addrs
;
582 /* Find lowest loadable section to be used as starting point for
583 continguous sections. */
585 bfd_map_over_sections (abfd
, find_lowest_section
, &lower_sect
);
586 if (lower_sect
== NULL
)
588 warning (_("no loadable sections found in added symbol-file %s"),
589 bfd_get_filename (abfd
));
593 lower_offset
= bfd_section_vma (bfd_get_filename (abfd
), lower_sect
);
595 /* Create ADDRS_TO_ABFD_ADDRS array to map the sections in ADDRS to sections
596 in ABFD. Section names are not unique - there can be multiple sections of
597 the same name. Also the sections of the same name do not have to be
598 adjacent to each other. Some sections may be present only in one of the
599 files. Even sections present in both files do not have to be in the same
602 Use stable sort by name for the sections in both files. Then linearly
603 scan both lists matching as most of the entries as possible. */
605 addrs_sorted
= addrs_section_sort (addrs
);
606 my_cleanup
= make_cleanup (xfree
, addrs_sorted
);
608 abfd_addrs
= build_section_addr_info_from_bfd (abfd
);
609 make_cleanup_free_section_addr_info (abfd_addrs
);
610 abfd_addrs_sorted
= addrs_section_sort (abfd_addrs
);
611 make_cleanup (xfree
, abfd_addrs_sorted
);
613 /* Now create ADDRS_TO_ABFD_ADDRS from ADDRS_SORTED and
614 ABFD_ADDRS_SORTED. */
616 addrs_to_abfd_addrs
= xzalloc (sizeof (*addrs_to_abfd_addrs
)
617 * addrs
->num_sections
);
618 make_cleanup (xfree
, addrs_to_abfd_addrs
);
620 while (*addrs_sorted
)
622 const char *sect_name
= addr_section_name ((*addrs_sorted
)->name
);
624 while (*abfd_addrs_sorted
625 && strcmp (addr_section_name ((*abfd_addrs_sorted
)->name
),
629 if (*abfd_addrs_sorted
630 && strcmp (addr_section_name ((*abfd_addrs_sorted
)->name
),
635 /* Make the found item directly addressable from ADDRS. */
636 index_in_addrs
= *addrs_sorted
- addrs
->other
;
637 gdb_assert (addrs_to_abfd_addrs
[index_in_addrs
] == NULL
);
638 addrs_to_abfd_addrs
[index_in_addrs
] = *abfd_addrs_sorted
;
640 /* Never use the same ABFD entry twice. */
647 /* Calculate offsets for the loadable sections.
648 FIXME! Sections must be in order of increasing loadable section
649 so that contiguous sections can use the lower-offset!!!
651 Adjust offsets if the segments are not contiguous.
652 If the section is contiguous, its offset should be set to
653 the offset of the highest loadable section lower than it
654 (the loadable section directly below it in memory).
655 this_offset = lower_offset = lower_addr - lower_orig_addr */
657 for (i
= 0; i
< addrs
->num_sections
&& addrs
->other
[i
].name
; i
++)
659 struct other_sections
*sect
= addrs_to_abfd_addrs
[i
];
663 /* This is the index used by BFD. */
664 addrs
->other
[i
].sectindex
= sect
->sectindex
;
666 if (addrs
->other
[i
].addr
!= 0)
668 addrs
->other
[i
].addr
-= sect
->addr
;
669 lower_offset
= addrs
->other
[i
].addr
;
672 addrs
->other
[i
].addr
= lower_offset
;
676 /* addr_section_name transformation is not used for SECT_NAME. */
677 const char *sect_name
= addrs
->other
[i
].name
;
679 /* This section does not exist in ABFD, which is normally
680 unexpected and we want to issue a warning.
682 However, the ELF prelinker does create a few sections which are
683 marked in the main executable as loadable (they are loaded in
684 memory from the DYNAMIC segment) and yet are not present in
685 separate debug info files. This is fine, and should not cause
686 a warning. Shared libraries contain just the section
687 ".gnu.liblist" but it is not marked as loadable there. There is
688 no other way to identify them than by their name as the sections
689 created by prelink have no special flags.
691 For the sections `.bss' and `.sbss' see addr_section_name. */
693 if (!(strcmp (sect_name
, ".gnu.liblist") == 0
694 || strcmp (sect_name
, ".gnu.conflict") == 0
695 || (strcmp (sect_name
, ".bss") == 0
697 && strcmp (addrs
->other
[i
- 1].name
, ".dynbss") == 0
698 && addrs_to_abfd_addrs
[i
- 1] != NULL
)
699 || (strcmp (sect_name
, ".sbss") == 0
701 && strcmp (addrs
->other
[i
- 1].name
, ".sdynbss") == 0
702 && addrs_to_abfd_addrs
[i
- 1] != NULL
)))
703 warning (_("section %s not found in %s"), sect_name
,
704 bfd_get_filename (abfd
));
706 addrs
->other
[i
].addr
= 0;
707 addrs
->other
[i
].sectindex
= -1;
711 do_cleanups (my_cleanup
);
714 /* Parse the user's idea of an offset for dynamic linking, into our idea
715 of how to represent it for fast symbol reading. This is the default
716 version of the sym_fns.sym_offsets function for symbol readers that
717 don't need to do anything special. It allocates a section_offsets table
718 for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */
721 default_symfile_offsets (struct objfile
*objfile
,
722 struct section_addr_info
*addrs
)
724 objfile
->num_sections
= bfd_count_sections (objfile
->obfd
);
725 objfile
->section_offsets
= (struct section_offsets
*)
726 obstack_alloc (&objfile
->objfile_obstack
,
727 SIZEOF_N_SECTION_OFFSETS (objfile
->num_sections
));
728 relative_addr_info_to_section_offsets (objfile
->section_offsets
,
729 objfile
->num_sections
, addrs
);
731 /* For relocatable files, all loadable sections will start at zero.
732 The zero is meaningless, so try to pick arbitrary addresses such
733 that no loadable sections overlap. This algorithm is quadratic,
734 but the number of sections in a single object file is generally
736 if ((bfd_get_file_flags (objfile
->obfd
) & (EXEC_P
| DYNAMIC
)) == 0)
738 struct place_section_arg arg
;
739 bfd
*abfd
= objfile
->obfd
;
742 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
; cur_sec
= cur_sec
->next
)
743 /* We do not expect this to happen; just skip this step if the
744 relocatable file has a section with an assigned VMA. */
745 if (bfd_section_vma (abfd
, cur_sec
) != 0)
750 CORE_ADDR
*offsets
= objfile
->section_offsets
->offsets
;
752 /* Pick non-overlapping offsets for sections the user did not
754 arg
.offsets
= objfile
->section_offsets
;
756 bfd_map_over_sections (objfile
->obfd
, place_section
, &arg
);
758 /* Correctly filling in the section offsets is not quite
759 enough. Relocatable files have two properties that
760 (most) shared objects do not:
762 - Their debug information will contain relocations. Some
763 shared libraries do also, but many do not, so this can not
766 - If there are multiple code sections they will be loaded
767 at different relative addresses in memory than they are
768 in the objfile, since all sections in the file will start
771 Because GDB has very limited ability to map from an
772 address in debug info to the correct code section,
773 it relies on adding SECT_OFF_TEXT to things which might be
774 code. If we clear all the section offsets, and set the
775 section VMAs instead, then symfile_relocate_debug_section
776 will return meaningful debug information pointing at the
779 GDB has too many different data structures for section
780 addresses - a bfd, objfile, and so_list all have section
781 tables, as does exec_ops. Some of these could probably
784 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
;
785 cur_sec
= cur_sec
->next
)
787 if ((bfd_get_section_flags (abfd
, cur_sec
) & SEC_ALLOC
) == 0)
790 bfd_set_section_vma (abfd
, cur_sec
, offsets
[cur_sec
->index
]);
791 exec_set_section_address (bfd_get_filename (abfd
),
793 offsets
[cur_sec
->index
]);
794 offsets
[cur_sec
->index
] = 0;
799 /* Remember the bfd indexes for the .text, .data, .bss and
801 init_objfile_sect_indices (objfile
);
805 /* Divide the file into segments, which are individual relocatable units.
806 This is the default version of the sym_fns.sym_segments function for
807 symbol readers that do not have an explicit representation of segments.
808 It assumes that object files do not have segments, and fully linked
809 files have a single segment. */
811 struct symfile_segment_data
*
812 default_symfile_segments (bfd
*abfd
)
816 struct symfile_segment_data
*data
;
819 /* Relocatable files contain enough information to position each
820 loadable section independently; they should not be relocated
822 if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
)) == 0)
825 /* Make sure there is at least one loadable section in the file. */
826 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
828 if ((bfd_get_section_flags (abfd
, sect
) & SEC_ALLOC
) == 0)
836 low
= bfd_get_section_vma (abfd
, sect
);
837 high
= low
+ bfd_get_section_size (sect
);
839 data
= XZALLOC (struct symfile_segment_data
);
840 data
->num_segments
= 1;
841 data
->segment_bases
= XCALLOC (1, CORE_ADDR
);
842 data
->segment_sizes
= XCALLOC (1, CORE_ADDR
);
844 num_sections
= bfd_count_sections (abfd
);
845 data
->segment_info
= XCALLOC (num_sections
, int);
847 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
851 if ((bfd_get_section_flags (abfd
, sect
) & SEC_ALLOC
) == 0)
854 vma
= bfd_get_section_vma (abfd
, sect
);
857 if (vma
+ bfd_get_section_size (sect
) > high
)
858 high
= vma
+ bfd_get_section_size (sect
);
860 data
->segment_info
[i
] = 1;
863 data
->segment_bases
[0] = low
;
864 data
->segment_sizes
[0] = high
- low
;
869 /* This is a convenience function to call sym_read for OBJFILE and
870 possibly force the partial symbols to be read. */
873 read_symbols (struct objfile
*objfile
, int add_flags
)
875 (*objfile
->sf
->sym_read
) (objfile
, add_flags
);
876 if (!objfile_has_partial_symbols (objfile
))
878 bfd
*abfd
= find_separate_debug_file_in_section (objfile
);
879 struct cleanup
*cleanup
= make_cleanup_bfd_unref (abfd
);
882 symbol_file_add_separate (abfd
, add_flags
, objfile
);
884 do_cleanups (cleanup
);
886 if ((add_flags
& SYMFILE_NO_READ
) == 0)
887 require_partial_symbols (objfile
, 0);
890 /* Initialize entry point information for this objfile. */
893 init_entry_point_info (struct objfile
*objfile
)
895 /* Save startup file's range of PC addresses to help blockframe.c
896 decide where the bottom of the stack is. */
898 if (bfd_get_file_flags (objfile
->obfd
) & EXEC_P
)
900 /* Executable file -- record its entry point so we'll recognize
901 the startup file because it contains the entry point. */
902 objfile
->ei
.entry_point
= bfd_get_start_address (objfile
->obfd
);
903 objfile
->ei
.entry_point_p
= 1;
905 else if (bfd_get_file_flags (objfile
->obfd
) & DYNAMIC
906 && bfd_get_start_address (objfile
->obfd
) != 0)
908 /* Some shared libraries may have entry points set and be
909 runnable. There's no clear way to indicate this, so just check
910 for values other than zero. */
911 objfile
->ei
.entry_point
= bfd_get_start_address (objfile
->obfd
);
912 objfile
->ei
.entry_point_p
= 1;
916 /* Examination of non-executable.o files. Short-circuit this stuff. */
917 objfile
->ei
.entry_point_p
= 0;
920 if (objfile
->ei
.entry_point_p
)
922 CORE_ADDR entry_point
= objfile
->ei
.entry_point
;
924 /* Make certain that the address points at real code, and not a
925 function descriptor. */
927 = gdbarch_convert_from_func_ptr_addr (objfile
->gdbarch
,
931 /* Remove any ISA markers, so that this matches entries in the
933 objfile
->ei
.entry_point
934 = gdbarch_addr_bits_remove (objfile
->gdbarch
, entry_point
);
938 /* Process a symbol file, as either the main file or as a dynamically
941 This function does not set the OBJFILE's entry-point info.
943 OBJFILE is where the symbols are to be read from.
945 ADDRS is the list of section load addresses. If the user has given
946 an 'add-symbol-file' command, then this is the list of offsets and
947 addresses he or she provided as arguments to the command; or, if
948 we're handling a shared library, these are the actual addresses the
949 sections are loaded at, according to the inferior's dynamic linker
950 (as gleaned by GDB's shared library code). We convert each address
951 into an offset from the section VMA's as it appears in the object
952 file, and then call the file's sym_offsets function to convert this
953 into a format-specific offset table --- a `struct section_offsets'.
954 If ADDRS is non-zero, OFFSETS must be zero.
956 OFFSETS is a table of section offsets already in the right
957 format-specific representation. NUM_OFFSETS is the number of
958 elements present in OFFSETS->offsets. If OFFSETS is non-zero, we
959 assume this is the proper table the call to sym_offsets described
960 above would produce. Instead of calling sym_offsets, we just dump
961 it right into objfile->section_offsets. (When we're re-reading
962 symbols from an objfile, we don't have the original load address
963 list any more; all we have is the section offset table.) If
964 OFFSETS is non-zero, ADDRS must be zero.
966 ADD_FLAGS encodes verbosity level, whether this is main symbol or
967 an extra symbol file such as dynamically loaded code, and wether
968 breakpoint reset should be deferred. */
971 syms_from_objfile_1 (struct objfile
*objfile
,
972 struct section_addr_info
*addrs
,
973 struct section_offsets
*offsets
,
977 struct section_addr_info
*local_addr
= NULL
;
978 struct cleanup
*old_chain
;
979 const int mainline
= add_flags
& SYMFILE_MAINLINE
;
981 gdb_assert (! (addrs
&& offsets
));
983 objfile
->sf
= find_sym_fns (objfile
->obfd
);
985 if (objfile
->sf
== NULL
)
987 /* No symbols to load, but we still need to make sure
988 that the section_offsets table is allocated. */
989 int num_sections
= bfd_count_sections (objfile
->obfd
);
990 size_t size
= SIZEOF_N_SECTION_OFFSETS (num_offsets
);
992 objfile
->num_sections
= num_sections
;
993 objfile
->section_offsets
994 = obstack_alloc (&objfile
->objfile_obstack
, size
);
995 memset (objfile
->section_offsets
, 0, size
);
999 /* Make sure that partially constructed symbol tables will be cleaned up
1000 if an error occurs during symbol reading. */
1001 old_chain
= make_cleanup_free_objfile (objfile
);
1003 /* If ADDRS and OFFSETS are both NULL, put together a dummy address
1004 list. We now establish the convention that an addr of zero means
1005 no load address was specified. */
1006 if (! addrs
&& ! offsets
)
1009 = alloc_section_addr_info (bfd_count_sections (objfile
->obfd
));
1010 make_cleanup (xfree
, local_addr
);
1014 /* Now either addrs or offsets is non-zero. */
1018 /* We will modify the main symbol table, make sure that all its users
1019 will be cleaned up if an error occurs during symbol reading. */
1020 make_cleanup (clear_symtab_users_cleanup
, 0 /*ignore*/);
1022 /* Since no error yet, throw away the old symbol table. */
1024 if (symfile_objfile
!= NULL
)
1026 free_objfile (symfile_objfile
);
1027 gdb_assert (symfile_objfile
== NULL
);
1030 /* Currently we keep symbols from the add-symbol-file command.
1031 If the user wants to get rid of them, they should do "symbol-file"
1032 without arguments first. Not sure this is the best behavior
1035 (*objfile
->sf
->sym_new_init
) (objfile
);
1038 /* Convert addr into an offset rather than an absolute address.
1039 We find the lowest address of a loaded segment in the objfile,
1040 and assume that <addr> is where that got loaded.
1042 We no longer warn if the lowest section is not a text segment (as
1043 happens for the PA64 port. */
1044 if (addrs
&& addrs
->other
[0].name
)
1045 addr_info_make_relative (addrs
, objfile
->obfd
);
1047 /* Initialize symbol reading routines for this objfile, allow complaints to
1048 appear for this new file, and record how verbose to be, then do the
1049 initial symbol reading for this file. */
1051 (*objfile
->sf
->sym_init
) (objfile
);
1052 clear_complaints (&symfile_complaints
, 1, add_flags
& SYMFILE_VERBOSE
);
1055 (*objfile
->sf
->sym_offsets
) (objfile
, addrs
);
1058 size_t size
= SIZEOF_N_SECTION_OFFSETS (num_offsets
);
1060 /* Just copy in the offset table directly as given to us. */
1061 objfile
->num_sections
= num_offsets
;
1062 objfile
->section_offsets
1063 = ((struct section_offsets
*)
1064 obstack_alloc (&objfile
->objfile_obstack
, size
));
1065 memcpy (objfile
->section_offsets
, offsets
, size
);
1067 init_objfile_sect_indices (objfile
);
1070 read_symbols (objfile
, add_flags
);
1072 /* Discard cleanups as symbol reading was successful. */
1074 discard_cleanups (old_chain
);
1078 /* Same as syms_from_objfile_1, but also initializes the objfile
1079 entry-point info. */
1082 syms_from_objfile (struct objfile
*objfile
,
1083 struct section_addr_info
*addrs
,
1084 struct section_offsets
*offsets
,
1088 syms_from_objfile_1 (objfile
, addrs
, offsets
, num_offsets
, add_flags
);
1089 init_entry_point_info (objfile
);
1092 /* Perform required actions after either reading in the initial
1093 symbols for a new objfile, or mapping in the symbols from a reusable
1094 objfile. ADD_FLAGS is a bitmask of enum symfile_add_flags. */
1097 new_symfile_objfile (struct objfile
*objfile
, int add_flags
)
1099 /* If this is the main symbol file we have to clean up all users of the
1100 old main symbol file. Otherwise it is sufficient to fixup all the
1101 breakpoints that may have been redefined by this symbol file. */
1102 if (add_flags
& SYMFILE_MAINLINE
)
1104 /* OK, make it the "real" symbol file. */
1105 symfile_objfile
= objfile
;
1107 clear_symtab_users (add_flags
);
1109 else if ((add_flags
& SYMFILE_DEFER_BP_RESET
) == 0)
1111 breakpoint_re_set ();
1114 /* We're done reading the symbol file; finish off complaints. */
1115 clear_complaints (&symfile_complaints
, 0, add_flags
& SYMFILE_VERBOSE
);
1118 /* Process a symbol file, as either the main file or as a dynamically
1121 ABFD is a BFD already open on the file, as from symfile_bfd_open.
1122 A new reference is acquired by this function.
1124 ADD_FLAGS encodes verbosity, whether this is main symbol file or
1125 extra, such as dynamically loaded code, and what to do with breakpoins.
1127 ADDRS, OFFSETS, and NUM_OFFSETS are as described for
1128 syms_from_objfile, above.
1129 ADDRS is ignored when SYMFILE_MAINLINE bit is set in ADD_FLAGS.
1131 PARENT is the original objfile if ABFD is a separate debug info file.
1132 Otherwise PARENT is NULL.
1134 Upon success, returns a pointer to the objfile that was added.
1135 Upon failure, jumps back to command level (never returns). */
1137 static struct objfile
*
1138 symbol_file_add_with_addrs_or_offsets (bfd
*abfd
,
1140 struct section_addr_info
*addrs
,
1141 struct section_offsets
*offsets
,
1143 int flags
, struct objfile
*parent
)
1145 struct objfile
*objfile
;
1146 const char *name
= bfd_get_filename (abfd
);
1147 const int from_tty
= add_flags
& SYMFILE_VERBOSE
;
1148 const int mainline
= add_flags
& SYMFILE_MAINLINE
;
1149 const int should_print
= ((from_tty
|| info_verbose
)
1150 && (readnow_symbol_files
1151 || (add_flags
& SYMFILE_NO_READ
) == 0));
1153 if (readnow_symbol_files
)
1155 flags
|= OBJF_READNOW
;
1156 add_flags
&= ~SYMFILE_NO_READ
;
1159 /* Give user a chance to burp if we'd be
1160 interactively wiping out any existing symbols. */
1162 if ((have_full_symbols () || have_partial_symbols ())
1165 && !query (_("Load new symbol table from \"%s\"? "), name
))
1166 error (_("Not confirmed."));
1168 objfile
= allocate_objfile (abfd
, flags
| (mainline
? OBJF_MAINLINE
: 0));
1171 add_separate_debug_objfile (objfile
, parent
);
1173 /* We either created a new mapped symbol table, mapped an existing
1174 symbol table file which has not had initial symbol reading
1175 performed, or need to read an unmapped symbol table. */
1178 if (deprecated_pre_add_symbol_hook
)
1179 deprecated_pre_add_symbol_hook (name
);
1182 printf_unfiltered (_("Reading symbols from %s..."), name
);
1184 gdb_flush (gdb_stdout
);
1187 syms_from_objfile (objfile
, addrs
, offsets
, num_offsets
,
1190 /* We now have at least a partial symbol table. Check to see if the
1191 user requested that all symbols be read on initial access via either
1192 the gdb startup command line or on a per symbol file basis. Expand
1193 all partial symbol tables for this objfile if so. */
1195 if ((flags
& OBJF_READNOW
))
1199 printf_unfiltered (_("expanding to full symbols..."));
1201 gdb_flush (gdb_stdout
);
1205 objfile
->sf
->qf
->expand_all_symtabs (objfile
);
1208 if (should_print
&& !objfile_has_symbols (objfile
))
1211 printf_unfiltered (_("(no debugging symbols found)..."));
1217 if (deprecated_post_add_symbol_hook
)
1218 deprecated_post_add_symbol_hook ();
1220 printf_unfiltered (_("done.\n"));
1223 /* We print some messages regardless of whether 'from_tty ||
1224 info_verbose' is true, so make sure they go out at the right
1226 gdb_flush (gdb_stdout
);
1228 if (objfile
->sf
== NULL
)
1230 observer_notify_new_objfile (objfile
);
1231 return objfile
; /* No symbols. */
1234 new_symfile_objfile (objfile
, add_flags
);
1236 observer_notify_new_objfile (objfile
);
1238 bfd_cache_close_all ();
1242 /* Add BFD as a separate debug file for OBJFILE. */
1245 symbol_file_add_separate (bfd
*bfd
, int symfile_flags
, struct objfile
*objfile
)
1247 struct objfile
*new_objfile
;
1248 struct section_addr_info
*sap
;
1249 struct cleanup
*my_cleanup
;
1251 /* Create section_addr_info. We can't directly use offsets from OBJFILE
1252 because sections of BFD may not match sections of OBJFILE and because
1253 vma may have been modified by tools such as prelink. */
1254 sap
= build_section_addr_info_from_objfile (objfile
);
1255 my_cleanup
= make_cleanup_free_section_addr_info (sap
);
1257 new_objfile
= symbol_file_add_with_addrs_or_offsets
1258 (bfd
, symfile_flags
,
1260 objfile
->flags
& (OBJF_REORDERED
| OBJF_SHARED
| OBJF_READNOW
1264 do_cleanups (my_cleanup
);
1267 /* Process the symbol file ABFD, as either the main file or as a
1268 dynamically loaded file.
1270 See symbol_file_add_with_addrs_or_offsets's comments for
1273 symbol_file_add_from_bfd (bfd
*abfd
, int add_flags
,
1274 struct section_addr_info
*addrs
,
1275 int flags
, struct objfile
*parent
)
1277 return symbol_file_add_with_addrs_or_offsets (abfd
, add_flags
, addrs
, 0, 0,
1282 /* Process a symbol file, as either the main file or as a dynamically
1283 loaded file. See symbol_file_add_with_addrs_or_offsets's comments
1286 symbol_file_add (char *name
, int add_flags
, struct section_addr_info
*addrs
,
1289 bfd
*bfd
= symfile_bfd_open (name
);
1290 struct cleanup
*cleanup
= make_cleanup_bfd_unref (bfd
);
1291 struct objfile
*objf
;
1293 objf
= symbol_file_add_from_bfd (bfd
, add_flags
, addrs
, flags
, NULL
);
1294 do_cleanups (cleanup
);
1299 /* Call symbol_file_add() with default values and update whatever is
1300 affected by the loading of a new main().
1301 Used when the file is supplied in the gdb command line
1302 and by some targets with special loading requirements.
1303 The auxiliary function, symbol_file_add_main_1(), has the flags
1304 argument for the switches that can only be specified in the symbol_file
1308 symbol_file_add_main (char *args
, int from_tty
)
1310 symbol_file_add_main_1 (args
, from_tty
, 0);
1314 symbol_file_add_main_1 (char *args
, int from_tty
, int flags
)
1316 const int add_flags
= (current_inferior ()->symfile_flags
1317 | SYMFILE_MAINLINE
| (from_tty
? SYMFILE_VERBOSE
: 0));
1319 symbol_file_add (args
, add_flags
, NULL
, flags
);
1321 /* Getting new symbols may change our opinion about
1322 what is frameless. */
1323 reinit_frame_cache ();
1325 if ((flags
& SYMFILE_NO_READ
) == 0)
1326 set_initial_language ();
1330 symbol_file_clear (int from_tty
)
1332 if ((have_full_symbols () || have_partial_symbols ())
1335 ? !query (_("Discard symbol table from `%s'? "),
1336 symfile_objfile
->name
)
1337 : !query (_("Discard symbol table? "))))
1338 error (_("Not confirmed."));
1340 /* solib descriptors may have handles to objfiles. Wipe them before their
1341 objfiles get stale by free_all_objfiles. */
1342 no_shared_libraries (NULL
, from_tty
);
1344 free_all_objfiles ();
1346 gdb_assert (symfile_objfile
== NULL
);
1348 printf_unfiltered (_("No symbol file now.\n"));
1352 get_debug_link_info (struct objfile
*objfile
, unsigned long *crc32_out
)
1355 bfd_size_type debuglink_size
;
1356 unsigned long crc32
;
1360 sect
= bfd_get_section_by_name (objfile
->obfd
, ".gnu_debuglink");
1365 debuglink_size
= bfd_section_size (objfile
->obfd
, sect
);
1367 contents
= xmalloc (debuglink_size
);
1368 bfd_get_section_contents (objfile
->obfd
, sect
, contents
,
1369 (file_ptr
)0, (bfd_size_type
)debuglink_size
);
1371 /* Crc value is stored after the filename, aligned up to 4 bytes. */
1372 crc_offset
= strlen (contents
) + 1;
1373 crc_offset
= (crc_offset
+ 3) & ~3;
1375 crc32
= bfd_get_32 (objfile
->obfd
, (bfd_byte
*) (contents
+ crc_offset
));
1381 /* Return 32-bit CRC for ABFD. If successful store it to *FILE_CRC_RETURN and
1382 return 1. Otherwise print a warning and return 0. ABFD seek position is
1386 get_file_crc (bfd
*abfd
, unsigned long *file_crc_return
)
1388 unsigned long file_crc
= 0;
1390 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
1392 warning (_("Problem reading \"%s\" for CRC: %s"),
1393 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1399 gdb_byte buffer
[8 * 1024];
1400 bfd_size_type count
;
1402 count
= bfd_bread (buffer
, sizeof (buffer
), abfd
);
1403 if (count
== (bfd_size_type
) -1)
1405 warning (_("Problem reading \"%s\" for CRC: %s"),
1406 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
1411 file_crc
= gnu_debuglink_crc32 (file_crc
, buffer
, count
);
1414 *file_crc_return
= file_crc
;
1419 separate_debug_file_exists (const char *name
, unsigned long crc
,
1420 struct objfile
*parent_objfile
)
1422 unsigned long file_crc
;
1425 struct stat parent_stat
, abfd_stat
;
1426 int verified_as_different
;
1428 /* Find a separate debug info file as if symbols would be present in
1429 PARENT_OBJFILE itself this function would not be called. .gnu_debuglink
1430 section can contain just the basename of PARENT_OBJFILE without any
1431 ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
1432 the separate debug infos with the same basename can exist. */
1434 if (filename_cmp (name
, parent_objfile
->name
) == 0)
1437 abfd
= gdb_bfd_open_maybe_remote (name
);
1442 /* Verify symlinks were not the cause of filename_cmp name difference above.
1444 Some operating systems, e.g. Windows, do not provide a meaningful
1445 st_ino; they always set it to zero. (Windows does provide a
1446 meaningful st_dev.) Do not indicate a duplicate library in that
1447 case. While there is no guarantee that a system that provides
1448 meaningful inode numbers will never set st_ino to zero, this is
1449 merely an optimization, so we do not need to worry about false
1452 if (bfd_stat (abfd
, &abfd_stat
) == 0
1453 && abfd_stat
.st_ino
!= 0
1454 && bfd_stat (parent_objfile
->obfd
, &parent_stat
) == 0)
1456 if (abfd_stat
.st_dev
== parent_stat
.st_dev
1457 && abfd_stat
.st_ino
== parent_stat
.st_ino
)
1459 gdb_bfd_unref (abfd
);
1462 verified_as_different
= 1;
1465 verified_as_different
= 0;
1467 file_crc_p
= get_file_crc (abfd
, &file_crc
);
1469 gdb_bfd_unref (abfd
);
1474 if (crc
!= file_crc
)
1476 /* If one (or both) the files are accessed for example the via "remote:"
1477 gdbserver way it does not support the bfd_stat operation. Verify
1478 whether those two files are not the same manually. */
1480 if (!verified_as_different
&& !parent_objfile
->crc32_p
)
1482 parent_objfile
->crc32_p
= get_file_crc (parent_objfile
->obfd
,
1483 &parent_objfile
->crc32
);
1484 if (!parent_objfile
->crc32_p
)
1488 if (verified_as_different
|| parent_objfile
->crc32
!= file_crc
)
1489 warning (_("the debug information found in \"%s\""
1490 " does not match \"%s\" (CRC mismatch).\n"),
1491 name
, parent_objfile
->name
);
1499 char *debug_file_directory
= NULL
;
1501 show_debug_file_directory (struct ui_file
*file
, int from_tty
,
1502 struct cmd_list_element
*c
, const char *value
)
1504 fprintf_filtered (file
,
1505 _("The directory where separate debug "
1506 "symbols are searched for is \"%s\".\n"),
1510 #if ! defined (DEBUG_SUBDIRECTORY)
1511 #define DEBUG_SUBDIRECTORY ".debug"
1514 /* Find a separate debuginfo file for OBJFILE, using DIR as the directory
1515 where the original file resides (may not be the same as
1516 dirname(objfile->name) due to symlinks), and DEBUGLINK as the file we are
1517 looking for. Returns the name of the debuginfo, of NULL. */
1520 find_separate_debug_file (const char *dir
,
1521 const char *canon_dir
,
1522 const char *debuglink
,
1523 unsigned long crc32
, struct objfile
*objfile
)
1528 VEC (char_ptr
) *debugdir_vec
;
1529 struct cleanup
*back_to
;
1532 /* Set I to max (strlen (canon_dir), strlen (dir)). */
1534 if (canon_dir
!= NULL
&& strlen (canon_dir
) > i
)
1535 i
= strlen (canon_dir
);
1537 debugfile
= xmalloc (strlen (debug_file_directory
) + 1
1539 + strlen (DEBUG_SUBDIRECTORY
)
1541 + strlen (debuglink
)
1544 /* First try in the same directory as the original file. */
1545 strcpy (debugfile
, dir
);
1546 strcat (debugfile
, debuglink
);
1548 if (separate_debug_file_exists (debugfile
, crc32
, objfile
))
1551 /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
1552 strcpy (debugfile
, dir
);
1553 strcat (debugfile
, DEBUG_SUBDIRECTORY
);
1554 strcat (debugfile
, "/");
1555 strcat (debugfile
, debuglink
);
1557 if (separate_debug_file_exists (debugfile
, crc32
, objfile
))
1560 /* Then try in the global debugfile directories.
1562 Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
1563 cause "/..." lookups. */
1565 debugdir_vec
= dirnames_to_char_ptr_vec (debug_file_directory
);
1566 back_to
= make_cleanup_free_char_ptr_vec (debugdir_vec
);
1568 for (ix
= 0; VEC_iterate (char_ptr
, debugdir_vec
, ix
, debugdir
); ++ix
)
1570 strcpy (debugfile
, debugdir
);
1571 strcat (debugfile
, "/");
1572 strcat (debugfile
, dir
);
1573 strcat (debugfile
, debuglink
);
1575 if (separate_debug_file_exists (debugfile
, crc32
, objfile
))
1578 /* If the file is in the sysroot, try using its base path in the
1579 global debugfile directory. */
1580 if (canon_dir
!= NULL
1581 && filename_ncmp (canon_dir
, gdb_sysroot
,
1582 strlen (gdb_sysroot
)) == 0
1583 && IS_DIR_SEPARATOR (canon_dir
[strlen (gdb_sysroot
)]))
1585 strcpy (debugfile
, debugdir
);
1586 strcat (debugfile
, canon_dir
+ strlen (gdb_sysroot
));
1587 strcat (debugfile
, "/");
1588 strcat (debugfile
, debuglink
);
1590 if (separate_debug_file_exists (debugfile
, crc32
, objfile
))
1595 do_cleanups (back_to
);
1600 /* Modify PATH to contain only "directory/" part of PATH.
1601 If there were no directory separators in PATH, PATH will be empty
1602 string on return. */
1605 terminate_after_last_dir_separator (char *path
)
1609 /* Strip off the final filename part, leaving the directory name,
1610 followed by a slash. The directory can be relative or absolute. */
1611 for (i
= strlen(path
) - 1; i
>= 0; i
--)
1612 if (IS_DIR_SEPARATOR (path
[i
]))
1615 /* If I is -1 then no directory is present there and DIR will be "". */
1619 /* Find separate debuginfo for OBJFILE (using .gnu_debuglink section).
1620 Returns pathname, or NULL. */
1623 find_separate_debug_file_by_debuglink (struct objfile
*objfile
)
1626 char *dir
, *canon_dir
;
1628 unsigned long crc32
;
1629 struct cleanup
*cleanups
;
1631 debuglink
= get_debug_link_info (objfile
, &crc32
);
1633 if (debuglink
== NULL
)
1635 /* There's no separate debug info, hence there's no way we could
1636 load it => no warning. */
1640 cleanups
= make_cleanup (xfree
, debuglink
);
1641 dir
= xstrdup (objfile
->name
);
1642 make_cleanup (xfree
, dir
);
1643 terminate_after_last_dir_separator (dir
);
1644 canon_dir
= lrealpath (dir
);
1646 debugfile
= find_separate_debug_file (dir
, canon_dir
, debuglink
,
1650 if (debugfile
== NULL
)
1653 /* For PR gdb/9538, try again with realpath (if different from the
1658 if (lstat (objfile
->name
, &st_buf
) == 0 && S_ISLNK(st_buf
.st_mode
))
1662 symlink_dir
= lrealpath (objfile
->name
);
1663 if (symlink_dir
!= NULL
)
1665 make_cleanup (xfree
, symlink_dir
);
1666 terminate_after_last_dir_separator (symlink_dir
);
1667 if (strcmp (dir
, symlink_dir
) != 0)
1669 /* Different directory, so try using it. */
1670 debugfile
= find_separate_debug_file (symlink_dir
,
1678 #endif /* HAVE_LSTAT */
1681 do_cleanups (cleanups
);
1686 /* This is the symbol-file command. Read the file, analyze its
1687 symbols, and add a struct symtab to a symtab list. The syntax of
1688 the command is rather bizarre:
1690 1. The function buildargv implements various quoting conventions
1691 which are undocumented and have little or nothing in common with
1692 the way things are quoted (or not quoted) elsewhere in GDB.
1694 2. Options are used, which are not generally used in GDB (perhaps
1695 "set mapped on", "set readnow on" would be better)
1697 3. The order of options matters, which is contrary to GNU
1698 conventions (because it is confusing and inconvenient). */
1701 symbol_file_command (char *args
, int from_tty
)
1707 symbol_file_clear (from_tty
);
1711 char **argv
= gdb_buildargv (args
);
1712 int flags
= OBJF_USERLOADED
;
1713 struct cleanup
*cleanups
;
1716 cleanups
= make_cleanup_freeargv (argv
);
1717 while (*argv
!= NULL
)
1719 if (strcmp (*argv
, "-readnow") == 0)
1720 flags
|= OBJF_READNOW
;
1721 else if (**argv
== '-')
1722 error (_("unknown option `%s'"), *argv
);
1725 symbol_file_add_main_1 (*argv
, from_tty
, flags
);
1733 error (_("no symbol file name was specified"));
1735 do_cleanups (cleanups
);
1739 /* Set the initial language.
1741 FIXME: A better solution would be to record the language in the
1742 psymtab when reading partial symbols, and then use it (if known) to
1743 set the language. This would be a win for formats that encode the
1744 language in an easily discoverable place, such as DWARF. For
1745 stabs, we can jump through hoops looking for specially named
1746 symbols or try to intuit the language from the specific type of
1747 stabs we find, but we can't do that until later when we read in
1751 set_initial_language (void)
1753 enum language lang
= language_unknown
;
1755 if (language_of_main
!= language_unknown
)
1756 lang
= language_of_main
;
1759 const char *filename
;
1761 filename
= find_main_filename ();
1762 if (filename
!= NULL
)
1763 lang
= deduce_language_from_filename (filename
);
1766 if (lang
== language_unknown
)
1768 /* Make C the default language */
1772 set_language (lang
);
1773 expected_language
= current_language
; /* Don't warn the user. */
1776 /* If NAME is a remote name open the file using remote protocol, otherwise
1777 open it normally. Returns a new reference to the BFD. On error,
1778 returns NULL with the BFD error set. */
1781 gdb_bfd_open_maybe_remote (const char *name
)
1785 if (remote_filename_p (name
))
1786 result
= remote_bfd_open (name
, gnutarget
);
1788 result
= gdb_bfd_open (name
, gnutarget
, -1);
1794 /* Open the file specified by NAME and hand it off to BFD for
1795 preliminary analysis. Return a newly initialized bfd *, which
1796 includes a newly malloc'd` copy of NAME (tilde-expanded and made
1797 absolute). In case of trouble, error() is called. */
1800 symfile_bfd_open (char *name
)
1804 char *absolute_name
;
1806 if (remote_filename_p (name
))
1808 sym_bfd
= remote_bfd_open (name
, gnutarget
);
1810 error (_("`%s': can't open to read symbols: %s."), name
,
1811 bfd_errmsg (bfd_get_error ()));
1813 if (!bfd_check_format (sym_bfd
, bfd_object
))
1815 make_cleanup_bfd_unref (sym_bfd
);
1816 error (_("`%s': can't read symbols: %s."), name
,
1817 bfd_errmsg (bfd_get_error ()));
1823 name
= tilde_expand (name
); /* Returns 1st new malloc'd copy. */
1825 /* Look down path for it, allocate 2nd new malloc'd copy. */
1826 desc
= openp (getenv ("PATH"), OPF_TRY_CWD_FIRST
, name
,
1827 O_RDONLY
| O_BINARY
, &absolute_name
);
1828 #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
1831 char *exename
= alloca (strlen (name
) + 5);
1833 strcat (strcpy (exename
, name
), ".exe");
1834 desc
= openp (getenv ("PATH"), OPF_TRY_CWD_FIRST
, exename
,
1835 O_RDONLY
| O_BINARY
, &absolute_name
);
1840 make_cleanup (xfree
, name
);
1841 perror_with_name (name
);
1845 name
= absolute_name
;
1846 make_cleanup (xfree
, name
);
1848 sym_bfd
= gdb_bfd_open (name
, gnutarget
, desc
);
1851 make_cleanup (xfree
, name
);
1852 error (_("`%s': can't open to read symbols: %s."), name
,
1853 bfd_errmsg (bfd_get_error ()));
1855 bfd_set_cacheable (sym_bfd
, 1);
1857 if (!bfd_check_format (sym_bfd
, bfd_object
))
1859 make_cleanup_bfd_unref (sym_bfd
);
1860 error (_("`%s': can't read symbols: %s."), name
,
1861 bfd_errmsg (bfd_get_error ()));
1867 /* Return the section index for SECTION_NAME on OBJFILE. Return -1 if
1868 the section was not found. */
1871 get_section_index (struct objfile
*objfile
, char *section_name
)
1873 asection
*sect
= bfd_get_section_by_name (objfile
->obfd
, section_name
);
1881 /* Link SF into the global symtab_fns list. Called on startup by the
1882 _initialize routine in each object file format reader, to register
1883 information about each format the reader is prepared to handle. */
1886 add_symtab_fns (const struct sym_fns
*sf
)
1888 VEC_safe_push (sym_fns_ptr
, symtab_fns
, sf
);
1891 /* Initialize OBJFILE to read symbols from its associated BFD. It
1892 either returns or calls error(). The result is an initialized
1893 struct sym_fns in the objfile structure, that contains cached
1894 information about the symbol file. */
1896 static const struct sym_fns
*
1897 find_sym_fns (bfd
*abfd
)
1899 const struct sym_fns
*sf
;
1900 enum bfd_flavour our_flavour
= bfd_get_flavour (abfd
);
1903 if (our_flavour
== bfd_target_srec_flavour
1904 || our_flavour
== bfd_target_ihex_flavour
1905 || our_flavour
== bfd_target_tekhex_flavour
)
1906 return NULL
; /* No symbols. */
1908 for (i
= 0; VEC_iterate (sym_fns_ptr
, symtab_fns
, i
, sf
); ++i
)
1909 if (our_flavour
== sf
->sym_flavour
)
1912 error (_("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown."),
1913 bfd_get_target (abfd
));
1917 /* This function runs the load command of our current target. */
1920 load_command (char *arg
, int from_tty
)
1924 /* The user might be reloading because the binary has changed. Take
1925 this opportunity to check. */
1926 reopen_exec_file ();
1934 parg
= arg
= get_exec_file (1);
1936 /* Count how many \ " ' tab space there are in the name. */
1937 while ((parg
= strpbrk (parg
, "\\\"'\t ")))
1945 /* We need to quote this string so buildargv can pull it apart. */
1946 char *temp
= xmalloc (strlen (arg
) + count
+ 1 );
1950 make_cleanup (xfree
, temp
);
1953 while ((parg
= strpbrk (parg
, "\\\"'\t ")))
1955 strncpy (ptemp
, prev
, parg
- prev
);
1956 ptemp
+= parg
- prev
;
1960 strcpy (ptemp
, prev
);
1966 target_load (arg
, from_tty
);
1968 /* After re-loading the executable, we don't really know which
1969 overlays are mapped any more. */
1970 overlay_cache_invalid
= 1;
1973 /* This version of "load" should be usable for any target. Currently
1974 it is just used for remote targets, not inftarg.c or core files,
1975 on the theory that only in that case is it useful.
1977 Avoiding xmodem and the like seems like a win (a) because we don't have
1978 to worry about finding it, and (b) On VMS, fork() is very slow and so
1979 we don't want to run a subprocess. On the other hand, I'm not sure how
1980 performance compares. */
1982 static int validate_download
= 0;
1984 /* Callback service function for generic_load (bfd_map_over_sections). */
1987 add_section_size_callback (bfd
*abfd
, asection
*asec
, void *data
)
1989 bfd_size_type
*sum
= data
;
1991 *sum
+= bfd_get_section_size (asec
);
1994 /* Opaque data for load_section_callback. */
1995 struct load_section_data
{
1996 unsigned long load_offset
;
1997 struct load_progress_data
*progress_data
;
1998 VEC(memory_write_request_s
) *requests
;
2001 /* Opaque data for load_progress. */
2002 struct load_progress_data
{
2003 /* Cumulative data. */
2004 unsigned long write_count
;
2005 unsigned long data_count
;
2006 bfd_size_type total_size
;
2009 /* Opaque data for load_progress for a single section. */
2010 struct load_progress_section_data
{
2011 struct load_progress_data
*cumulative
;
2013 /* Per-section data. */
2014 const char *section_name
;
2015 ULONGEST section_sent
;
2016 ULONGEST section_size
;
2021 /* Target write callback routine for progress reporting. */
2024 load_progress (ULONGEST bytes
, void *untyped_arg
)
2026 struct load_progress_section_data
*args
= untyped_arg
;
2027 struct load_progress_data
*totals
;
2030 /* Writing padding data. No easy way to get at the cumulative
2031 stats, so just ignore this. */
2034 totals
= args
->cumulative
;
2036 if (bytes
== 0 && args
->section_sent
== 0)
2038 /* The write is just starting. Let the user know we've started
2040 ui_out_message (current_uiout
, 0, "Loading section %s, size %s lma %s\n",
2041 args
->section_name
, hex_string (args
->section_size
),
2042 paddress (target_gdbarch (), args
->lma
));
2046 if (validate_download
)
2048 /* Broken memories and broken monitors manifest themselves here
2049 when bring new computers to life. This doubles already slow
2051 /* NOTE: cagney/1999-10-18: A more efficient implementation
2052 might add a verify_memory() method to the target vector and
2053 then use that. remote.c could implement that method using
2054 the ``qCRC'' packet. */
2055 gdb_byte
*check
= xmalloc (bytes
);
2056 struct cleanup
*verify_cleanups
= make_cleanup (xfree
, check
);
2058 if (target_read_memory (args
->lma
, check
, bytes
) != 0)
2059 error (_("Download verify read failed at %s"),
2060 paddress (target_gdbarch (), args
->lma
));
2061 if (memcmp (args
->buffer
, check
, bytes
) != 0)
2062 error (_("Download verify compare failed at %s"),
2063 paddress (target_gdbarch (), args
->lma
));
2064 do_cleanups (verify_cleanups
);
2066 totals
->data_count
+= bytes
;
2068 args
->buffer
+= bytes
;
2069 totals
->write_count
+= 1;
2070 args
->section_sent
+= bytes
;
2071 if (check_quit_flag ()
2072 || (deprecated_ui_load_progress_hook
!= NULL
2073 && deprecated_ui_load_progress_hook (args
->section_name
,
2074 args
->section_sent
)))
2075 error (_("Canceled the download"));
2077 if (deprecated_show_load_progress
!= NULL
)
2078 deprecated_show_load_progress (args
->section_name
,
2082 totals
->total_size
);
2085 /* Callback service function for generic_load (bfd_map_over_sections). */
2088 load_section_callback (bfd
*abfd
, asection
*asec
, void *data
)
2090 struct memory_write_request
*new_request
;
2091 struct load_section_data
*args
= data
;
2092 struct load_progress_section_data
*section_data
;
2093 bfd_size_type size
= bfd_get_section_size (asec
);
2095 const char *sect_name
= bfd_get_section_name (abfd
, asec
);
2097 if ((bfd_get_section_flags (abfd
, asec
) & SEC_LOAD
) == 0)
2103 new_request
= VEC_safe_push (memory_write_request_s
,
2104 args
->requests
, NULL
);
2105 memset (new_request
, 0, sizeof (struct memory_write_request
));
2106 section_data
= xcalloc (1, sizeof (struct load_progress_section_data
));
2107 new_request
->begin
= bfd_section_lma (abfd
, asec
) + args
->load_offset
;
2108 new_request
->end
= new_request
->begin
+ size
; /* FIXME Should size
2110 new_request
->data
= xmalloc (size
);
2111 new_request
->baton
= section_data
;
2113 buffer
= new_request
->data
;
2115 section_data
->cumulative
= args
->progress_data
;
2116 section_data
->section_name
= sect_name
;
2117 section_data
->section_size
= size
;
2118 section_data
->lma
= new_request
->begin
;
2119 section_data
->buffer
= buffer
;
2121 bfd_get_section_contents (abfd
, asec
, buffer
, 0, size
);
2124 /* Clean up an entire memory request vector, including load
2125 data and progress records. */
2128 clear_memory_write_data (void *arg
)
2130 VEC(memory_write_request_s
) **vec_p
= arg
;
2131 VEC(memory_write_request_s
) *vec
= *vec_p
;
2133 struct memory_write_request
*mr
;
2135 for (i
= 0; VEC_iterate (memory_write_request_s
, vec
, i
, mr
); ++i
)
2140 VEC_free (memory_write_request_s
, vec
);
2144 generic_load (char *args
, int from_tty
)
2147 struct timeval start_time
, end_time
;
2149 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
2150 struct load_section_data cbdata
;
2151 struct load_progress_data total_progress
;
2152 struct ui_out
*uiout
= current_uiout
;
2157 memset (&cbdata
, 0, sizeof (cbdata
));
2158 memset (&total_progress
, 0, sizeof (total_progress
));
2159 cbdata
.progress_data
= &total_progress
;
2161 make_cleanup (clear_memory_write_data
, &cbdata
.requests
);
2164 error_no_arg (_("file to load"));
2166 argv
= gdb_buildargv (args
);
2167 make_cleanup_freeargv (argv
);
2169 filename
= tilde_expand (argv
[0]);
2170 make_cleanup (xfree
, filename
);
2172 if (argv
[1] != NULL
)
2176 cbdata
.load_offset
= strtoul (argv
[1], &endptr
, 0);
2178 /* If the last word was not a valid number then
2179 treat it as a file name with spaces in. */
2180 if (argv
[1] == endptr
)
2181 error (_("Invalid download offset:%s."), argv
[1]);
2183 if (argv
[2] != NULL
)
2184 error (_("Too many parameters."));
2187 /* Open the file for loading. */
2188 loadfile_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2189 if (loadfile_bfd
== NULL
)
2191 perror_with_name (filename
);
2195 make_cleanup_bfd_unref (loadfile_bfd
);
2197 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2199 error (_("\"%s\" is not an object file: %s"), filename
,
2200 bfd_errmsg (bfd_get_error ()));
2203 bfd_map_over_sections (loadfile_bfd
, add_section_size_callback
,
2204 (void *) &total_progress
.total_size
);
2206 bfd_map_over_sections (loadfile_bfd
, load_section_callback
, &cbdata
);
2208 gettimeofday (&start_time
, NULL
);
2210 if (target_write_memory_blocks (cbdata
.requests
, flash_discard
,
2211 load_progress
) != 0)
2212 error (_("Load failed"));
2214 gettimeofday (&end_time
, NULL
);
2216 entry
= bfd_get_start_address (loadfile_bfd
);
2217 entry
= gdbarch_addr_bits_remove (target_gdbarch (), entry
);
2218 ui_out_text (uiout
, "Start address ");
2219 ui_out_field_fmt (uiout
, "address", "%s", paddress (target_gdbarch (), entry
));
2220 ui_out_text (uiout
, ", load size ");
2221 ui_out_field_fmt (uiout
, "load-size", "%lu", total_progress
.data_count
);
2222 ui_out_text (uiout
, "\n");
2223 /* We were doing this in remote-mips.c, I suspect it is right
2224 for other targets too. */
2225 regcache_write_pc (get_current_regcache (), entry
);
2227 /* Reset breakpoints, now that we have changed the load image. For
2228 instance, breakpoints may have been set (or reset, by
2229 post_create_inferior) while connected to the target but before we
2230 loaded the program. In that case, the prologue analyzer could
2231 have read instructions from the target to find the right
2232 breakpoint locations. Loading has changed the contents of that
2235 breakpoint_re_set ();
2237 /* FIXME: are we supposed to call symbol_file_add or not? According
2238 to a comment from remote-mips.c (where a call to symbol_file_add
2239 was commented out), making the call confuses GDB if more than one
2240 file is loaded in. Some targets do (e.g., remote-vx.c) but
2241 others don't (or didn't - perhaps they have all been deleted). */
2243 print_transfer_performance (gdb_stdout
, total_progress
.data_count
,
2244 total_progress
.write_count
,
2245 &start_time
, &end_time
);
2247 do_cleanups (old_cleanups
);
2250 /* Report how fast the transfer went. */
2253 print_transfer_performance (struct ui_file
*stream
,
2254 unsigned long data_count
,
2255 unsigned long write_count
,
2256 const struct timeval
*start_time
,
2257 const struct timeval
*end_time
)
2259 ULONGEST time_count
;
2260 struct ui_out
*uiout
= current_uiout
;
2262 /* Compute the elapsed time in milliseconds, as a tradeoff between
2263 accuracy and overflow. */
2264 time_count
= (end_time
->tv_sec
- start_time
->tv_sec
) * 1000;
2265 time_count
+= (end_time
->tv_usec
- start_time
->tv_usec
) / 1000;
2267 ui_out_text (uiout
, "Transfer rate: ");
2270 unsigned long rate
= ((ULONGEST
) data_count
* 1000) / time_count
;
2272 if (ui_out_is_mi_like_p (uiout
))
2274 ui_out_field_fmt (uiout
, "transfer-rate", "%lu", rate
* 8);
2275 ui_out_text (uiout
, " bits/sec");
2277 else if (rate
< 1024)
2279 ui_out_field_fmt (uiout
, "transfer-rate", "%lu", rate
);
2280 ui_out_text (uiout
, " bytes/sec");
2284 ui_out_field_fmt (uiout
, "transfer-rate", "%lu", rate
/ 1024);
2285 ui_out_text (uiout
, " KB/sec");
2290 ui_out_field_fmt (uiout
, "transferred-bits", "%lu", (data_count
* 8));
2291 ui_out_text (uiout
, " bits in <1 sec");
2293 if (write_count
> 0)
2295 ui_out_text (uiout
, ", ");
2296 ui_out_field_fmt (uiout
, "write-rate", "%lu", data_count
/ write_count
);
2297 ui_out_text (uiout
, " bytes/write");
2299 ui_out_text (uiout
, ".\n");
2302 /* This function allows the addition of incrementally linked object files.
2303 It does not modify any state in the target, only in the debugger. */
2304 /* Note: ezannoni 2000-04-13 This function/command used to have a
2305 special case syntax for the rombug target (Rombug is the boot
2306 monitor for Microware's OS-9 / OS-9000, see remote-os9k.c). In the
2307 rombug case, the user doesn't need to supply a text address,
2308 instead a call to target_link() (in target.c) would supply the
2309 value to use. We are now discontinuing this type of ad hoc syntax. */
2312 add_symbol_file_command (char *args
, int from_tty
)
2314 struct gdbarch
*gdbarch
= get_current_arch ();
2315 char *filename
= NULL
;
2316 int flags
= OBJF_USERLOADED
;
2318 int section_index
= 0;
2322 int expecting_sec_name
= 0;
2323 int expecting_sec_addr
= 0;
2332 struct section_addr_info
*section_addrs
;
2333 struct sect_opt
*sect_opts
= NULL
;
2334 size_t num_sect_opts
= 0;
2335 struct cleanup
*my_cleanups
= make_cleanup (null_cleanup
, NULL
);
2338 sect_opts
= (struct sect_opt
*) xmalloc (num_sect_opts
2339 * sizeof (struct sect_opt
));
2344 error (_("add-symbol-file takes a file name and an address"));
2346 argv
= gdb_buildargv (args
);
2347 make_cleanup_freeargv (argv
);
2349 for (arg
= argv
[0], argcnt
= 0; arg
!= NULL
; arg
= argv
[++argcnt
])
2351 /* Process the argument. */
2354 /* The first argument is the file name. */
2355 filename
= tilde_expand (arg
);
2356 make_cleanup (xfree
, filename
);
2361 /* The second argument is always the text address at which
2362 to load the program. */
2363 sect_opts
[section_index
].name
= ".text";
2364 sect_opts
[section_index
].value
= arg
;
2365 if (++section_index
>= num_sect_opts
)
2368 sect_opts
= ((struct sect_opt
*)
2369 xrealloc (sect_opts
,
2371 * sizeof (struct sect_opt
)));
2376 /* It's an option (starting with '-') or it's an argument
2381 if (strcmp (arg
, "-readnow") == 0)
2382 flags
|= OBJF_READNOW
;
2383 else if (strcmp (arg
, "-s") == 0)
2385 expecting_sec_name
= 1;
2386 expecting_sec_addr
= 1;
2391 if (expecting_sec_name
)
2393 sect_opts
[section_index
].name
= arg
;
2394 expecting_sec_name
= 0;
2397 if (expecting_sec_addr
)
2399 sect_opts
[section_index
].value
= arg
;
2400 expecting_sec_addr
= 0;
2401 if (++section_index
>= num_sect_opts
)
2404 sect_opts
= ((struct sect_opt
*)
2405 xrealloc (sect_opts
,
2407 * sizeof (struct sect_opt
)));
2411 error (_("USAGE: add-symbol-file <filename> <textaddress>"
2412 " [-readnow] [-s <secname> <addr>]*"));
2417 /* This command takes at least two arguments. The first one is a
2418 filename, and the second is the address where this file has been
2419 loaded. Abort now if this address hasn't been provided by the
2421 if (section_index
< 1)
2422 error (_("The address where %s has been loaded is missing"), filename
);
2424 /* Print the prompt for the query below. And save the arguments into
2425 a sect_addr_info structure to be passed around to other
2426 functions. We have to split this up into separate print
2427 statements because hex_string returns a local static
2430 printf_unfiltered (_("add symbol table from file \"%s\" at\n"), filename
);
2431 section_addrs
= alloc_section_addr_info (section_index
);
2432 make_cleanup (xfree
, section_addrs
);
2433 for (i
= 0; i
< section_index
; i
++)
2436 char *val
= sect_opts
[i
].value
;
2437 char *sec
= sect_opts
[i
].name
;
2439 addr
= parse_and_eval_address (val
);
2441 /* Here we store the section offsets in the order they were
2442 entered on the command line. */
2443 section_addrs
->other
[sec_num
].name
= sec
;
2444 section_addrs
->other
[sec_num
].addr
= addr
;
2445 printf_unfiltered ("\t%s_addr = %s\n", sec
,
2446 paddress (gdbarch
, addr
));
2449 /* The object's sections are initialized when a
2450 call is made to build_objfile_section_table (objfile).
2451 This happens in reread_symbols.
2452 At this point, we don't know what file type this is,
2453 so we can't determine what section names are valid. */
2456 if (from_tty
&& (!query ("%s", "")))
2457 error (_("Not confirmed."));
2459 symbol_file_add (filename
, from_tty
? SYMFILE_VERBOSE
: 0,
2460 section_addrs
, flags
);
2462 /* Getting new symbols may change our opinion about what is
2464 reinit_frame_cache ();
2465 do_cleanups (my_cleanups
);
2469 typedef struct objfile
*objfilep
;
2471 DEF_VEC_P (objfilep
);
2473 /* Re-read symbols if a symbol-file has changed. */
2475 reread_symbols (void)
2477 struct objfile
*objfile
;
2479 struct stat new_statbuf
;
2481 VEC (objfilep
) *new_objfiles
= NULL
;
2482 struct cleanup
*all_cleanups
;
2484 all_cleanups
= make_cleanup (VEC_cleanup (objfilep
), &new_objfiles
);
2486 /* With the addition of shared libraries, this should be modified,
2487 the load time should be saved in the partial symbol tables, since
2488 different tables may come from different source files. FIXME.
2489 This routine should then walk down each partial symbol table
2490 and see if the symbol table that it originates from has been changed. */
2492 for (objfile
= object_files
; objfile
; objfile
= objfile
->next
)
2494 /* solib-sunos.c creates one objfile with obfd. */
2495 if (objfile
->obfd
== NULL
)
2498 /* Separate debug objfiles are handled in the main objfile. */
2499 if (objfile
->separate_debug_objfile_backlink
)
2502 /* If this object is from an archive (what you usually create with
2503 `ar', often called a `static library' on most systems, though
2504 a `shared library' on AIX is also an archive), then you should
2505 stat on the archive name, not member name. */
2506 if (objfile
->obfd
->my_archive
)
2507 res
= stat (objfile
->obfd
->my_archive
->filename
, &new_statbuf
);
2509 res
= stat (objfile
->name
, &new_statbuf
);
2512 /* FIXME, should use print_sys_errmsg but it's not filtered. */
2513 printf_unfiltered (_("`%s' has disappeared; keeping its symbols.\n"),
2517 new_modtime
= new_statbuf
.st_mtime
;
2518 if (new_modtime
!= objfile
->mtime
)
2520 struct cleanup
*old_cleanups
;
2521 struct section_offsets
*offsets
;
2523 char *obfd_filename
;
2525 printf_unfiltered (_("`%s' has changed; re-reading symbols.\n"),
2528 /* There are various functions like symbol_file_add,
2529 symfile_bfd_open, syms_from_objfile, etc., which might
2530 appear to do what we want. But they have various other
2531 effects which we *don't* want. So we just do stuff
2532 ourselves. We don't worry about mapped files (for one thing,
2533 any mapped file will be out of date). */
2535 /* If we get an error, blow away this objfile (not sure if
2536 that is the correct response for things like shared
2538 old_cleanups
= make_cleanup_free_objfile (objfile
);
2539 /* We need to do this whenever any symbols go away. */
2540 make_cleanup (clear_symtab_users_cleanup
, 0 /*ignore*/);
2542 if (exec_bfd
!= NULL
2543 && filename_cmp (bfd_get_filename (objfile
->obfd
),
2544 bfd_get_filename (exec_bfd
)) == 0)
2546 /* Reload EXEC_BFD without asking anything. */
2548 exec_file_attach (bfd_get_filename (objfile
->obfd
), 0);
2551 /* Keep the calls order approx. the same as in free_objfile. */
2553 /* Free the separate debug objfiles. It will be
2554 automatically recreated by sym_read. */
2555 free_objfile_separate_debug (objfile
);
2557 /* Remove any references to this objfile in the global
2559 preserve_values (objfile
);
2561 /* Nuke all the state that we will re-read. Much of the following
2562 code which sets things to NULL really is necessary to tell
2563 other parts of GDB that there is nothing currently there.
2565 Try to keep the freeing order compatible with free_objfile. */
2567 if (objfile
->sf
!= NULL
)
2569 (*objfile
->sf
->sym_finish
) (objfile
);
2572 clear_objfile_data (objfile
);
2574 /* Clean up any state BFD has sitting around. */
2576 struct bfd
*obfd
= objfile
->obfd
;
2578 obfd_filename
= bfd_get_filename (objfile
->obfd
);
2579 /* Open the new BFD before freeing the old one, so that
2580 the filename remains live. */
2581 objfile
->obfd
= gdb_bfd_open_maybe_remote (obfd_filename
);
2582 if (objfile
->obfd
== NULL
)
2584 /* We have to make a cleanup and error here, rather
2585 than erroring later, because once we unref OBFD,
2586 OBFD_FILENAME will be freed. */
2587 make_cleanup_bfd_unref (obfd
);
2588 error (_("Can't open %s to read symbols."), obfd_filename
);
2590 gdb_bfd_unref (obfd
);
2593 objfile
->name
= bfd_get_filename (objfile
->obfd
);
2594 /* bfd_openr sets cacheable to true, which is what we want. */
2595 if (!bfd_check_format (objfile
->obfd
, bfd_object
))
2596 error (_("Can't read symbols from %s: %s."), objfile
->name
,
2597 bfd_errmsg (bfd_get_error ()));
2599 /* Save the offsets, we will nuke them with the rest of the
2601 num_offsets
= objfile
->num_sections
;
2602 offsets
= ((struct section_offsets
*)
2603 alloca (SIZEOF_N_SECTION_OFFSETS (num_offsets
)));
2604 memcpy (offsets
, objfile
->section_offsets
,
2605 SIZEOF_N_SECTION_OFFSETS (num_offsets
));
2607 /* FIXME: Do we have to free a whole linked list, or is this
2609 if (objfile
->global_psymbols
.list
)
2610 xfree (objfile
->global_psymbols
.list
);
2611 memset (&objfile
->global_psymbols
, 0,
2612 sizeof (objfile
->global_psymbols
));
2613 if (objfile
->static_psymbols
.list
)
2614 xfree (objfile
->static_psymbols
.list
);
2615 memset (&objfile
->static_psymbols
, 0,
2616 sizeof (objfile
->static_psymbols
));
2618 /* Free the obstacks for non-reusable objfiles. */
2619 psymbol_bcache_free (objfile
->psymbol_cache
);
2620 objfile
->psymbol_cache
= psymbol_bcache_init ();
2621 if (objfile
->demangled_names_hash
!= NULL
)
2623 htab_delete (objfile
->demangled_names_hash
);
2624 objfile
->demangled_names_hash
= NULL
;
2626 obstack_free (&objfile
->objfile_obstack
, 0);
2627 objfile
->sections
= NULL
;
2628 objfile
->symtabs
= NULL
;
2629 objfile
->psymtabs
= NULL
;
2630 objfile
->psymtabs_addrmap
= NULL
;
2631 objfile
->free_psymtabs
= NULL
;
2632 objfile
->template_symbols
= NULL
;
2633 objfile
->msymbols
= NULL
;
2634 objfile
->minimal_symbol_count
= 0;
2635 memset (&objfile
->msymbol_hash
, 0,
2636 sizeof (objfile
->msymbol_hash
));
2637 memset (&objfile
->msymbol_demangled_hash
, 0,
2638 sizeof (objfile
->msymbol_demangled_hash
));
2640 set_objfile_per_bfd (objfile
);
2642 /* obstack_init also initializes the obstack so it is
2643 empty. We could use obstack_specify_allocation but
2644 gdb_obstack.h specifies the alloc/dealloc functions. */
2645 obstack_init (&objfile
->objfile_obstack
);
2646 build_objfile_section_table (objfile
);
2647 terminate_minimal_symbol_table (objfile
);
2649 /* We use the same section offsets as from last time. I'm not
2650 sure whether that is always correct for shared libraries. */
2651 objfile
->section_offsets
= (struct section_offsets
*)
2652 obstack_alloc (&objfile
->objfile_obstack
,
2653 SIZEOF_N_SECTION_OFFSETS (num_offsets
));
2654 memcpy (objfile
->section_offsets
, offsets
,
2655 SIZEOF_N_SECTION_OFFSETS (num_offsets
));
2656 objfile
->num_sections
= num_offsets
;
2658 /* What the hell is sym_new_init for, anyway? The concept of
2659 distinguishing between the main file and additional files
2660 in this way seems rather dubious. */
2661 if (objfile
== symfile_objfile
)
2663 (*objfile
->sf
->sym_new_init
) (objfile
);
2666 (*objfile
->sf
->sym_init
) (objfile
);
2667 clear_complaints (&symfile_complaints
, 1, 1);
2669 objfile
->flags
&= ~OBJF_PSYMTABS_READ
;
2670 read_symbols (objfile
, 0);
2672 if (!objfile_has_symbols (objfile
))
2675 printf_unfiltered (_("(no debugging symbols found)\n"));
2679 /* We're done reading the symbol file; finish off complaints. */
2680 clear_complaints (&symfile_complaints
, 0, 1);
2682 /* Getting new symbols may change our opinion about what is
2685 reinit_frame_cache ();
2687 /* Discard cleanups as symbol reading was successful. */
2688 discard_cleanups (old_cleanups
);
2690 /* If the mtime has changed between the time we set new_modtime
2691 and now, we *want* this to be out of date, so don't call stat
2693 objfile
->mtime
= new_modtime
;
2694 init_entry_point_info (objfile
);
2696 VEC_safe_push (objfilep
, new_objfiles
, objfile
);
2704 /* Notify objfiles that we've modified objfile sections. */
2705 objfiles_changed ();
2707 clear_symtab_users (0);
2709 /* clear_objfile_data for each objfile was called before freeing it and
2710 observer_notify_new_objfile (NULL) has been called by
2711 clear_symtab_users above. Notify the new files now. */
2712 for (ix
= 0; VEC_iterate (objfilep
, new_objfiles
, ix
, objfile
); ix
++)
2713 observer_notify_new_objfile (objfile
);
2715 /* At least one objfile has changed, so we can consider that
2716 the executable we're debugging has changed too. */
2717 observer_notify_executable_changed ();
2720 do_cleanups (all_cleanups
);
2732 static filename_language
*filename_language_table
;
2733 static int fl_table_size
, fl_table_next
;
2736 add_filename_language (char *ext
, enum language lang
)
2738 if (fl_table_next
>= fl_table_size
)
2740 fl_table_size
+= 10;
2741 filename_language_table
=
2742 xrealloc (filename_language_table
,
2743 fl_table_size
* sizeof (*filename_language_table
));
2746 filename_language_table
[fl_table_next
].ext
= xstrdup (ext
);
2747 filename_language_table
[fl_table_next
].lang
= lang
;
2751 static char *ext_args
;
2753 show_ext_args (struct ui_file
*file
, int from_tty
,
2754 struct cmd_list_element
*c
, const char *value
)
2756 fprintf_filtered (file
,
2757 _("Mapping between filename extension "
2758 "and source language is \"%s\".\n"),
2763 set_ext_lang_command (char *args
, int from_tty
, struct cmd_list_element
*e
)
2766 char *cp
= ext_args
;
2769 /* First arg is filename extension, starting with '.' */
2771 error (_("'%s': Filename extension must begin with '.'"), ext_args
);
2773 /* Find end of first arg. */
2774 while (*cp
&& !isspace (*cp
))
2778 error (_("'%s': two arguments required -- "
2779 "filename extension and language"),
2782 /* Null-terminate first arg. */
2785 /* Find beginning of second arg, which should be a source language. */
2786 while (*cp
&& isspace (*cp
))
2790 error (_("'%s': two arguments required -- "
2791 "filename extension and language"),
2794 /* Lookup the language from among those we know. */
2795 lang
= language_enum (cp
);
2797 /* Now lookup the filename extension: do we already know it? */
2798 for (i
= 0; i
< fl_table_next
; i
++)
2799 if (0 == strcmp (ext_args
, filename_language_table
[i
].ext
))
2802 if (i
>= fl_table_next
)
2804 /* New file extension. */
2805 add_filename_language (ext_args
, lang
);
2809 /* Redefining a previously known filename extension. */
2812 /* query ("Really make files of type %s '%s'?", */
2813 /* ext_args, language_str (lang)); */
2815 xfree (filename_language_table
[i
].ext
);
2816 filename_language_table
[i
].ext
= xstrdup (ext_args
);
2817 filename_language_table
[i
].lang
= lang
;
2822 info_ext_lang_command (char *args
, int from_tty
)
2826 printf_filtered (_("Filename extensions and the languages they represent:"));
2827 printf_filtered ("\n\n");
2828 for (i
= 0; i
< fl_table_next
; i
++)
2829 printf_filtered ("\t%s\t- %s\n",
2830 filename_language_table
[i
].ext
,
2831 language_str (filename_language_table
[i
].lang
));
2835 init_filename_language_table (void)
2837 if (fl_table_size
== 0) /* Protect against repetition. */
2841 filename_language_table
=
2842 xmalloc (fl_table_size
* sizeof (*filename_language_table
));
2843 add_filename_language (".c", language_c
);
2844 add_filename_language (".d", language_d
);
2845 add_filename_language (".C", language_cplus
);
2846 add_filename_language (".cc", language_cplus
);
2847 add_filename_language (".cp", language_cplus
);
2848 add_filename_language (".cpp", language_cplus
);
2849 add_filename_language (".cxx", language_cplus
);
2850 add_filename_language (".c++", language_cplus
);
2851 add_filename_language (".java", language_java
);
2852 add_filename_language (".class", language_java
);
2853 add_filename_language (".m", language_objc
);
2854 add_filename_language (".f", language_fortran
);
2855 add_filename_language (".F", language_fortran
);
2856 add_filename_language (".for", language_fortran
);
2857 add_filename_language (".FOR", language_fortran
);
2858 add_filename_language (".ftn", language_fortran
);
2859 add_filename_language (".FTN", language_fortran
);
2860 add_filename_language (".fpp", language_fortran
);
2861 add_filename_language (".FPP", language_fortran
);
2862 add_filename_language (".f90", language_fortran
);
2863 add_filename_language (".F90", language_fortran
);
2864 add_filename_language (".f95", language_fortran
);
2865 add_filename_language (".F95", language_fortran
);
2866 add_filename_language (".f03", language_fortran
);
2867 add_filename_language (".F03", language_fortran
);
2868 add_filename_language (".f08", language_fortran
);
2869 add_filename_language (".F08", language_fortran
);
2870 add_filename_language (".s", language_asm
);
2871 add_filename_language (".sx", language_asm
);
2872 add_filename_language (".S", language_asm
);
2873 add_filename_language (".pas", language_pascal
);
2874 add_filename_language (".p", language_pascal
);
2875 add_filename_language (".pp", language_pascal
);
2876 add_filename_language (".adb", language_ada
);
2877 add_filename_language (".ads", language_ada
);
2878 add_filename_language (".a", language_ada
);
2879 add_filename_language (".ada", language_ada
);
2880 add_filename_language (".dg", language_ada
);
2885 deduce_language_from_filename (const char *filename
)
2890 if (filename
!= NULL
)
2891 if ((cp
= strrchr (filename
, '.')) != NULL
)
2892 for (i
= 0; i
< fl_table_next
; i
++)
2893 if (strcmp (cp
, filename_language_table
[i
].ext
) == 0)
2894 return filename_language_table
[i
].lang
;
2896 return language_unknown
;
2901 Allocate and partly initialize a new symbol table. Return a pointer
2902 to it. error() if no space.
2904 Caller must set these fields:
2913 allocate_symtab (const char *filename
, struct objfile
*objfile
)
2915 struct symtab
*symtab
;
2917 symtab
= (struct symtab
*)
2918 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symtab
));
2919 memset (symtab
, 0, sizeof (*symtab
));
2920 symtab
->filename
= (char *) bcache (filename
, strlen (filename
) + 1,
2921 objfile
->per_bfd
->filename_cache
);
2922 symtab
->fullname
= NULL
;
2923 symtab
->language
= deduce_language_from_filename (filename
);
2924 symtab
->debugformat
= "unknown";
2926 /* Hook it to the objfile it comes from. */
2928 symtab
->objfile
= objfile
;
2929 symtab
->next
= objfile
->symtabs
;
2930 objfile
->symtabs
= symtab
;
2932 if (symtab_create_debug
)
2934 /* Be a bit clever with debugging messages, and don't print objfile
2935 every time, only when it changes. */
2936 static char *last_objfile_name
= NULL
;
2938 if (last_objfile_name
== NULL
2939 || strcmp (last_objfile_name
, objfile
->name
) != 0)
2941 xfree (last_objfile_name
);
2942 last_objfile_name
= xstrdup (objfile
->name
);
2943 fprintf_unfiltered (gdb_stdlog
,
2944 "Creating one or more symtabs for objfile %s ...\n",
2947 fprintf_unfiltered (gdb_stdlog
,
2948 "Created symtab %s for module %s.\n",
2949 host_address_to_string (symtab
), filename
);
2956 /* Reset all data structures in gdb which may contain references to symbol
2957 table data. ADD_FLAGS is a bitmask of enum symfile_add_flags. */
2960 clear_symtab_users (int add_flags
)
2962 /* Someday, we should do better than this, by only blowing away
2963 the things that really need to be blown. */
2965 /* Clear the "current" symtab first, because it is no longer valid.
2966 breakpoint_re_set may try to access the current symtab. */
2967 clear_current_source_symtab_and_line ();
2970 if ((add_flags
& SYMFILE_DEFER_BP_RESET
) == 0)
2971 breakpoint_re_set ();
2972 clear_last_displayed_sal ();
2973 clear_pc_function_cache ();
2974 observer_notify_new_objfile (NULL
);
2976 /* Clear globals which might have pointed into a removed objfile.
2977 FIXME: It's not clear which of these are supposed to persist
2978 between expressions and which ought to be reset each time. */
2979 expression_context_block
= NULL
;
2980 innermost_block
= NULL
;
2982 /* Varobj may refer to old symbols, perform a cleanup. */
2983 varobj_invalidate ();
2988 clear_symtab_users_cleanup (void *ignore
)
2990 clear_symtab_users (0);
2994 The following code implements an abstraction for debugging overlay sections.
2996 The target model is as follows:
2997 1) The gnu linker will permit multiple sections to be mapped into the
2998 same VMA, each with its own unique LMA (or load address).
2999 2) It is assumed that some runtime mechanism exists for mapping the
3000 sections, one by one, from the load address into the VMA address.
3001 3) This code provides a mechanism for gdb to keep track of which
3002 sections should be considered to be mapped from the VMA to the LMA.
3003 This information is used for symbol lookup, and memory read/write.
3004 For instance, if a section has been mapped then its contents
3005 should be read from the VMA, otherwise from the LMA.
3007 Two levels of debugger support for overlays are available. One is
3008 "manual", in which the debugger relies on the user to tell it which
3009 overlays are currently mapped. This level of support is
3010 implemented entirely in the core debugger, and the information about
3011 whether a section is mapped is kept in the objfile->obj_section table.
3013 The second level of support is "automatic", and is only available if
3014 the target-specific code provides functionality to read the target's
3015 overlay mapping table, and translate its contents for the debugger
3016 (by updating the mapped state information in the obj_section tables).
3018 The interface is as follows:
3020 overlay map <name> -- tell gdb to consider this section mapped
3021 overlay unmap <name> -- tell gdb to consider this section unmapped
3022 overlay list -- list the sections that GDB thinks are mapped
3023 overlay read-target -- get the target's state of what's mapped
3024 overlay off/manual/auto -- set overlay debugging state
3025 Functional interface:
3026 find_pc_mapped_section(pc): if the pc is in the range of a mapped
3027 section, return that section.
3028 find_pc_overlay(pc): find any overlay section that contains
3029 the pc, either in its VMA or its LMA
3030 section_is_mapped(sect): true if overlay is marked as mapped
3031 section_is_overlay(sect): true if section's VMA != LMA
3032 pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA
3033 pc_in_unmapped_range(...): true if pc belongs to section's LMA
3034 sections_overlap(sec1, sec2): true if mapped sec1 and sec2 ranges overlap
3035 overlay_mapped_address(...): map an address from section's LMA to VMA
3036 overlay_unmapped_address(...): map an address from section's VMA to LMA
3037 symbol_overlayed_address(...): Return a "current" address for symbol:
3038 either in VMA or LMA depending on whether
3039 the symbol's section is currently mapped. */
3041 /* Overlay debugging state: */
3043 enum overlay_debugging_state overlay_debugging
= ovly_off
;
3044 int overlay_cache_invalid
= 0; /* True if need to refresh mapped state. */
3046 /* Function: section_is_overlay (SECTION)
3047 Returns true if SECTION has VMA not equal to LMA, ie.
3048 SECTION is loaded at an address different from where it will "run". */
3051 section_is_overlay (struct obj_section
*section
)
3053 if (overlay_debugging
&& section
)
3055 bfd
*abfd
= section
->objfile
->obfd
;
3056 asection
*bfd_section
= section
->the_bfd_section
;
3058 if (bfd_section_lma (abfd
, bfd_section
) != 0
3059 && bfd_section_lma (abfd
, bfd_section
)
3060 != bfd_section_vma (abfd
, bfd_section
))
3067 /* Function: overlay_invalidate_all (void)
3068 Invalidate the mapped state of all overlay sections (mark it as stale). */
3071 overlay_invalidate_all (void)
3073 struct objfile
*objfile
;
3074 struct obj_section
*sect
;
3076 ALL_OBJSECTIONS (objfile
, sect
)
3077 if (section_is_overlay (sect
))
3078 sect
->ovly_mapped
= -1;
3081 /* Function: section_is_mapped (SECTION)
3082 Returns true if section is an overlay, and is currently mapped.
3084 Access to the ovly_mapped flag is restricted to this function, so
3085 that we can do automatic update. If the global flag
3086 OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call
3087 overlay_invalidate_all. If the mapped state of the particular
3088 section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */
3091 section_is_mapped (struct obj_section
*osect
)
3093 struct gdbarch
*gdbarch
;
3095 if (osect
== 0 || !section_is_overlay (osect
))
3098 switch (overlay_debugging
)
3102 return 0; /* overlay debugging off */
3103 case ovly_auto
: /* overlay debugging automatic */
3104 /* Unles there is a gdbarch_overlay_update function,
3105 there's really nothing useful to do here (can't really go auto). */
3106 gdbarch
= get_objfile_arch (osect
->objfile
);
3107 if (gdbarch_overlay_update_p (gdbarch
))
3109 if (overlay_cache_invalid
)
3111 overlay_invalidate_all ();
3112 overlay_cache_invalid
= 0;
3114 if (osect
->ovly_mapped
== -1)
3115 gdbarch_overlay_update (gdbarch
, osect
);
3117 /* fall thru to manual case */
3118 case ovly_on
: /* overlay debugging manual */
3119 return osect
->ovly_mapped
== 1;
3123 /* Function: pc_in_unmapped_range
3124 If PC falls into the lma range of SECTION, return true, else false. */
3127 pc_in_unmapped_range (CORE_ADDR pc
, struct obj_section
*section
)
3129 if (section_is_overlay (section
))
3131 bfd
*abfd
= section
->objfile
->obfd
;
3132 asection
*bfd_section
= section
->the_bfd_section
;
3134 /* We assume the LMA is relocated by the same offset as the VMA. */
3135 bfd_vma size
= bfd_get_section_size (bfd_section
);
3136 CORE_ADDR offset
= obj_section_offset (section
);
3138 if (bfd_get_section_lma (abfd
, bfd_section
) + offset
<= pc
3139 && pc
< bfd_get_section_lma (abfd
, bfd_section
) + offset
+ size
)
3146 /* Function: pc_in_mapped_range
3147 If PC falls into the vma range of SECTION, return true, else false. */
3150 pc_in_mapped_range (CORE_ADDR pc
, struct obj_section
*section
)
3152 if (section_is_overlay (section
))
3154 if (obj_section_addr (section
) <= pc
3155 && pc
< obj_section_endaddr (section
))
3163 /* Return true if the mapped ranges of sections A and B overlap, false
3166 sections_overlap (struct obj_section
*a
, struct obj_section
*b
)
3168 CORE_ADDR a_start
= obj_section_addr (a
);
3169 CORE_ADDR a_end
= obj_section_endaddr (a
);
3170 CORE_ADDR b_start
= obj_section_addr (b
);
3171 CORE_ADDR b_end
= obj_section_endaddr (b
);
3173 return (a_start
< b_end
&& b_start
< a_end
);
3176 /* Function: overlay_unmapped_address (PC, SECTION)
3177 Returns the address corresponding to PC in the unmapped (load) range.
3178 May be the same as PC. */
3181 overlay_unmapped_address (CORE_ADDR pc
, struct obj_section
*section
)
3183 if (section_is_overlay (section
) && pc_in_mapped_range (pc
, section
))
3185 bfd
*abfd
= section
->objfile
->obfd
;
3186 asection
*bfd_section
= section
->the_bfd_section
;
3188 return pc
+ bfd_section_lma (abfd
, bfd_section
)
3189 - bfd_section_vma (abfd
, bfd_section
);
3195 /* Function: overlay_mapped_address (PC, SECTION)
3196 Returns the address corresponding to PC in the mapped (runtime) range.
3197 May be the same as PC. */
3200 overlay_mapped_address (CORE_ADDR pc
, struct obj_section
*section
)
3202 if (section_is_overlay (section
) && pc_in_unmapped_range (pc
, section
))
3204 bfd
*abfd
= section
->objfile
->obfd
;
3205 asection
*bfd_section
= section
->the_bfd_section
;
3207 return pc
+ bfd_section_vma (abfd
, bfd_section
)
3208 - bfd_section_lma (abfd
, bfd_section
);
3215 /* Function: symbol_overlayed_address
3216 Return one of two addresses (relative to the VMA or to the LMA),
3217 depending on whether the section is mapped or not. */
3220 symbol_overlayed_address (CORE_ADDR address
, struct obj_section
*section
)
3222 if (overlay_debugging
)
3224 /* If the symbol has no section, just return its regular address. */
3227 /* If the symbol's section is not an overlay, just return its
3229 if (!section_is_overlay (section
))
3231 /* If the symbol's section is mapped, just return its address. */
3232 if (section_is_mapped (section
))
3235 * HOWEVER: if the symbol is in an overlay section which is NOT mapped,
3236 * then return its LOADED address rather than its vma address!!
3238 return overlay_unmapped_address (address
, section
);
3243 /* Function: find_pc_overlay (PC)
3244 Return the best-match overlay section for PC:
3245 If PC matches a mapped overlay section's VMA, return that section.
3246 Else if PC matches an unmapped section's VMA, return that section.
3247 Else if PC matches an unmapped section's LMA, return that section. */
3249 struct obj_section
*
3250 find_pc_overlay (CORE_ADDR pc
)
3252 struct objfile
*objfile
;
3253 struct obj_section
*osect
, *best_match
= NULL
;
3255 if (overlay_debugging
)
3256 ALL_OBJSECTIONS (objfile
, osect
)
3257 if (section_is_overlay (osect
))
3259 if (pc_in_mapped_range (pc
, osect
))
3261 if (section_is_mapped (osect
))
3266 else if (pc_in_unmapped_range (pc
, osect
))
3272 /* Function: find_pc_mapped_section (PC)
3273 If PC falls into the VMA address range of an overlay section that is
3274 currently marked as MAPPED, return that section. Else return NULL. */
3276 struct obj_section
*
3277 find_pc_mapped_section (CORE_ADDR pc
)
3279 struct objfile
*objfile
;
3280 struct obj_section
*osect
;
3282 if (overlay_debugging
)
3283 ALL_OBJSECTIONS (objfile
, osect
)
3284 if (pc_in_mapped_range (pc
, osect
) && section_is_mapped (osect
))
3290 /* Function: list_overlays_command
3291 Print a list of mapped sections and their PC ranges. */
3294 list_overlays_command (char *args
, int from_tty
)
3297 struct objfile
*objfile
;
3298 struct obj_section
*osect
;
3300 if (overlay_debugging
)
3301 ALL_OBJSECTIONS (objfile
, osect
)
3302 if (section_is_mapped (osect
))
3304 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3309 vma
= bfd_section_vma (objfile
->obfd
, osect
->the_bfd_section
);
3310 lma
= bfd_section_lma (objfile
->obfd
, osect
->the_bfd_section
);
3311 size
= bfd_get_section_size (osect
->the_bfd_section
);
3312 name
= bfd_section_name (objfile
->obfd
, osect
->the_bfd_section
);
3314 printf_filtered ("Section %s, loaded at ", name
);
3315 fputs_filtered (paddress (gdbarch
, lma
), gdb_stdout
);
3316 puts_filtered (" - ");
3317 fputs_filtered (paddress (gdbarch
, lma
+ size
), gdb_stdout
);
3318 printf_filtered (", mapped at ");
3319 fputs_filtered (paddress (gdbarch
, vma
), gdb_stdout
);
3320 puts_filtered (" - ");
3321 fputs_filtered (paddress (gdbarch
, vma
+ size
), gdb_stdout
);
3322 puts_filtered ("\n");
3327 printf_filtered (_("No sections are mapped.\n"));
3330 /* Function: map_overlay_command
3331 Mark the named section as mapped (ie. residing at its VMA address). */
3334 map_overlay_command (char *args
, int from_tty
)
3336 struct objfile
*objfile
, *objfile2
;
3337 struct obj_section
*sec
, *sec2
;
3339 if (!overlay_debugging
)
3340 error (_("Overlay debugging not enabled. Use "
3341 "either the 'overlay auto' or\n"
3342 "the 'overlay manual' command."));
3344 if (args
== 0 || *args
== 0)
3345 error (_("Argument required: name of an overlay section"));
3347 /* First, find a section matching the user supplied argument. */
3348 ALL_OBJSECTIONS (objfile
, sec
)
3349 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
3351 /* Now, check to see if the section is an overlay. */
3352 if (!section_is_overlay (sec
))
3353 continue; /* not an overlay section */
3355 /* Mark the overlay as "mapped". */
3356 sec
->ovly_mapped
= 1;
3358 /* Next, make a pass and unmap any sections that are
3359 overlapped by this new section: */
3360 ALL_OBJSECTIONS (objfile2
, sec2
)
3361 if (sec2
->ovly_mapped
&& sec
!= sec2
&& sections_overlap (sec
, sec2
))
3364 printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
3365 bfd_section_name (objfile
->obfd
,
3366 sec2
->the_bfd_section
));
3367 sec2
->ovly_mapped
= 0; /* sec2 overlaps sec: unmap sec2. */
3371 error (_("No overlay section called %s"), args
);
3374 /* Function: unmap_overlay_command
3375 Mark the overlay section as unmapped
3376 (ie. resident in its LMA address range, rather than the VMA range). */
3379 unmap_overlay_command (char *args
, int from_tty
)
3381 struct objfile
*objfile
;
3382 struct obj_section
*sec
;
3384 if (!overlay_debugging
)
3385 error (_("Overlay debugging not enabled. "
3386 "Use either the 'overlay auto' or\n"
3387 "the 'overlay manual' command."));
3389 if (args
== 0 || *args
== 0)
3390 error (_("Argument required: name of an overlay section"));
3392 /* First, find a section matching the user supplied argument. */
3393 ALL_OBJSECTIONS (objfile
, sec
)
3394 if (!strcmp (bfd_section_name (objfile
->obfd
, sec
->the_bfd_section
), args
))
3396 if (!sec
->ovly_mapped
)
3397 error (_("Section %s is not mapped"), args
);
3398 sec
->ovly_mapped
= 0;
3401 error (_("No overlay section called %s"), args
);
3404 /* Function: overlay_auto_command
3405 A utility command to turn on overlay debugging.
3406 Possibly this should be done via a set/show command. */
3409 overlay_auto_command (char *args
, int from_tty
)
3411 overlay_debugging
= ovly_auto
;
3412 enable_overlay_breakpoints ();
3414 printf_unfiltered (_("Automatic overlay debugging enabled."));
3417 /* Function: overlay_manual_command
3418 A utility command to turn on overlay debugging.
3419 Possibly this should be done via a set/show command. */
3422 overlay_manual_command (char *args
, int from_tty
)
3424 overlay_debugging
= ovly_on
;
3425 disable_overlay_breakpoints ();
3427 printf_unfiltered (_("Overlay debugging enabled."));
3430 /* Function: overlay_off_command
3431 A utility command to turn on overlay debugging.
3432 Possibly this should be done via a set/show command. */
3435 overlay_off_command (char *args
, int from_tty
)
3437 overlay_debugging
= ovly_off
;
3438 disable_overlay_breakpoints ();
3440 printf_unfiltered (_("Overlay debugging disabled."));
3444 overlay_load_command (char *args
, int from_tty
)
3446 struct gdbarch
*gdbarch
= get_current_arch ();
3448 if (gdbarch_overlay_update_p (gdbarch
))
3449 gdbarch_overlay_update (gdbarch
, NULL
);
3451 error (_("This target does not know how to read its overlay state."));
3454 /* Function: overlay_command
3455 A place-holder for a mis-typed command. */
3457 /* Command list chain containing all defined "overlay" subcommands. */
3458 static struct cmd_list_element
*overlaylist
;
3461 overlay_command (char *args
, int from_tty
)
3464 ("\"overlay\" must be followed by the name of an overlay command.\n");
3465 help_list (overlaylist
, "overlay ", -1, gdb_stdout
);
3469 /* Target Overlays for the "Simplest" overlay manager:
3471 This is GDB's default target overlay layer. It works with the
3472 minimal overlay manager supplied as an example by Cygnus. The
3473 entry point is via a function pointer "gdbarch_overlay_update",
3474 so targets that use a different runtime overlay manager can
3475 substitute their own overlay_update function and take over the
3478 The overlay_update function pokes around in the target's data structures
3479 to see what overlays are mapped, and updates GDB's overlay mapping with
3482 In this simple implementation, the target data structures are as follows:
3483 unsigned _novlys; /# number of overlay sections #/
3484 unsigned _ovly_table[_novlys][4] = {
3485 {VMA, SIZE, LMA, MAPPED}, /# one entry per overlay section #/
3486 {..., ..., ..., ...},
3488 unsigned _novly_regions; /# number of overlay regions #/
3489 unsigned _ovly_region_table[_novly_regions][3] = {
3490 {VMA, SIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/
3493 These functions will attempt to update GDB's mappedness state in the
3494 symbol section table, based on the target's mappedness state.
3496 To do this, we keep a cached copy of the target's _ovly_table, and
3497 attempt to detect when the cached copy is invalidated. The main
3498 entry point is "simple_overlay_update(SECT), which looks up SECT in
3499 the cached table and re-reads only the entry for that section from
3500 the target (whenever possible). */
3502 /* Cached, dynamically allocated copies of the target data structures: */
3503 static unsigned (*cache_ovly_table
)[4] = 0;
3504 static unsigned cache_novlys
= 0;
3505 static CORE_ADDR cache_ovly_table_base
= 0;
3508 VMA
, SIZE
, LMA
, MAPPED
3511 /* Throw away the cached copy of _ovly_table. */
3513 simple_free_overlay_table (void)
3515 if (cache_ovly_table
)
3516 xfree (cache_ovly_table
);
3518 cache_ovly_table
= NULL
;
3519 cache_ovly_table_base
= 0;
3522 /* Read an array of ints of size SIZE from the target into a local buffer.
3523 Convert to host order. int LEN is number of ints. */
3525 read_target_long_array (CORE_ADDR memaddr
, unsigned int *myaddr
,
3526 int len
, int size
, enum bfd_endian byte_order
)
3528 /* FIXME (alloca): Not safe if array is very large. */
3529 gdb_byte
*buf
= alloca (len
* size
);
3532 read_memory (memaddr
, buf
, len
* size
);
3533 for (i
= 0; i
< len
; i
++)
3534 myaddr
[i
] = extract_unsigned_integer (size
* i
+ buf
, size
, byte_order
);
3537 /* Find and grab a copy of the target _ovly_table
3538 (and _novlys, which is needed for the table's size). */
3540 simple_read_overlay_table (void)
3542 struct minimal_symbol
*novlys_msym
, *ovly_table_msym
;
3543 struct gdbarch
*gdbarch
;
3545 enum bfd_endian byte_order
;
3547 simple_free_overlay_table ();
3548 novlys_msym
= lookup_minimal_symbol ("_novlys", NULL
, NULL
);
3551 error (_("Error reading inferior's overlay table: "
3552 "couldn't find `_novlys' variable\n"
3553 "in inferior. Use `overlay manual' mode."));
3557 ovly_table_msym
= lookup_minimal_symbol ("_ovly_table", NULL
, NULL
);
3558 if (! ovly_table_msym
)
3560 error (_("Error reading inferior's overlay table: couldn't find "
3561 "`_ovly_table' array\n"
3562 "in inferior. Use `overlay manual' mode."));
3566 gdbarch
= get_objfile_arch (msymbol_objfile (ovly_table_msym
));
3567 word_size
= gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
3568 byte_order
= gdbarch_byte_order (gdbarch
);
3570 cache_novlys
= read_memory_integer (SYMBOL_VALUE_ADDRESS (novlys_msym
),
3573 = (void *) xmalloc (cache_novlys
* sizeof (*cache_ovly_table
));
3574 cache_ovly_table_base
= SYMBOL_VALUE_ADDRESS (ovly_table_msym
);
3575 read_target_long_array (cache_ovly_table_base
,
3576 (unsigned int *) cache_ovly_table
,
3577 cache_novlys
* 4, word_size
, byte_order
);
3579 return 1; /* SUCCESS */
3582 /* Function: simple_overlay_update_1
3583 A helper function for simple_overlay_update. Assuming a cached copy
3584 of _ovly_table exists, look through it to find an entry whose vma,
3585 lma and size match those of OSECT. Re-read the entry and make sure
3586 it still matches OSECT (else the table may no longer be valid).
3587 Set OSECT's mapped state to match the entry. Return: 1 for
3588 success, 0 for failure. */
3591 simple_overlay_update_1 (struct obj_section
*osect
)
3594 bfd
*obfd
= osect
->objfile
->obfd
;
3595 asection
*bsect
= osect
->the_bfd_section
;
3596 struct gdbarch
*gdbarch
= get_objfile_arch (osect
->objfile
);
3597 int word_size
= gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
3598 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3600 size
= bfd_get_section_size (osect
->the_bfd_section
);
3601 for (i
= 0; i
< cache_novlys
; i
++)
3602 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (obfd
, bsect
)
3603 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (obfd
, bsect
)
3604 /* && cache_ovly_table[i][SIZE] == size */ )
3606 read_target_long_array (cache_ovly_table_base
+ i
* word_size
,
3607 (unsigned int *) cache_ovly_table
[i
],
3608 4, word_size
, byte_order
);
3609 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (obfd
, bsect
)
3610 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (obfd
, bsect
)
3611 /* && cache_ovly_table[i][SIZE] == size */ )
3613 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3616 else /* Warning! Warning! Target's ovly table has changed! */
3622 /* Function: simple_overlay_update
3623 If OSECT is NULL, then update all sections' mapped state
3624 (after re-reading the entire target _ovly_table).
3625 If OSECT is non-NULL, then try to find a matching entry in the
3626 cached ovly_table and update only OSECT's mapped state.
3627 If a cached entry can't be found or the cache isn't valid, then
3628 re-read the entire cache, and go ahead and update all sections. */
3631 simple_overlay_update (struct obj_section
*osect
)
3633 struct objfile
*objfile
;
3635 /* Were we given an osect to look up? NULL means do all of them. */
3637 /* Have we got a cached copy of the target's overlay table? */
3638 if (cache_ovly_table
!= NULL
)
3640 /* Does its cached location match what's currently in the
3642 struct minimal_symbol
*minsym
3643 = lookup_minimal_symbol ("_ovly_table", NULL
, NULL
);
3646 error (_("Error reading inferior's overlay table: couldn't "
3647 "find `_ovly_table' array\n"
3648 "in inferior. Use `overlay manual' mode."));
3650 if (cache_ovly_table_base
== SYMBOL_VALUE_ADDRESS (minsym
))
3651 /* Then go ahead and try to look up this single section in
3653 if (simple_overlay_update_1 (osect
))
3654 /* Found it! We're done. */
3658 /* Cached table no good: need to read the entire table anew.
3659 Or else we want all the sections, in which case it's actually
3660 more efficient to read the whole table in one block anyway. */
3662 if (! simple_read_overlay_table ())
3665 /* Now may as well update all sections, even if only one was requested. */
3666 ALL_OBJSECTIONS (objfile
, osect
)
3667 if (section_is_overlay (osect
))
3670 bfd
*obfd
= osect
->objfile
->obfd
;
3671 asection
*bsect
= osect
->the_bfd_section
;
3673 size
= bfd_get_section_size (bsect
);
3674 for (i
= 0; i
< cache_novlys
; i
++)
3675 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (obfd
, bsect
)
3676 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (obfd
, bsect
)
3677 /* && cache_ovly_table[i][SIZE] == size */ )
3678 { /* obj_section matches i'th entry in ovly_table. */
3679 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3680 break; /* finished with inner for loop: break out. */
3685 /* Set the output sections and output offsets for section SECTP in
3686 ABFD. The relocation code in BFD will read these offsets, so we
3687 need to be sure they're initialized. We map each section to itself,
3688 with no offset; this means that SECTP->vma will be honored. */
3691 symfile_dummy_outputs (bfd
*abfd
, asection
*sectp
, void *dummy
)
3693 sectp
->output_section
= sectp
;
3694 sectp
->output_offset
= 0;
3697 /* Default implementation for sym_relocate. */
3701 default_symfile_relocate (struct objfile
*objfile
, asection
*sectp
,
3704 /* Use sectp->owner instead of objfile->obfd. sectp may point to a
3706 bfd
*abfd
= sectp
->owner
;
3708 /* We're only interested in sections with relocation
3710 if ((sectp
->flags
& SEC_RELOC
) == 0)
3713 /* We will handle section offsets properly elsewhere, so relocate as if
3714 all sections begin at 0. */
3715 bfd_map_over_sections (abfd
, symfile_dummy_outputs
, NULL
);
3717 return bfd_simple_get_relocated_section_contents (abfd
, sectp
, buf
, NULL
);
3720 /* Relocate the contents of a debug section SECTP in ABFD. The
3721 contents are stored in BUF if it is non-NULL, or returned in a
3722 malloc'd buffer otherwise.
3724 For some platforms and debug info formats, shared libraries contain
3725 relocations against the debug sections (particularly for DWARF-2;
3726 one affected platform is PowerPC GNU/Linux, although it depends on
3727 the version of the linker in use). Also, ELF object files naturally
3728 have unresolved relocations for their debug sections. We need to apply
3729 the relocations in order to get the locations of symbols correct.
3730 Another example that may require relocation processing, is the
3731 DWARF-2 .eh_frame section in .o files, although it isn't strictly a
3735 symfile_relocate_debug_section (struct objfile
*objfile
,
3736 asection
*sectp
, bfd_byte
*buf
)
3738 gdb_assert (objfile
->sf
->sym_relocate
);
3740 return (*objfile
->sf
->sym_relocate
) (objfile
, sectp
, buf
);
3743 struct symfile_segment_data
*
3744 get_symfile_segment_data (bfd
*abfd
)
3746 const struct sym_fns
*sf
= find_sym_fns (abfd
);
3751 return sf
->sym_segments (abfd
);
3755 free_symfile_segment_data (struct symfile_segment_data
*data
)
3757 xfree (data
->segment_bases
);
3758 xfree (data
->segment_sizes
);
3759 xfree (data
->segment_info
);
3765 - DATA, containing segment addresses from the object file ABFD, and
3766 the mapping from ABFD's sections onto the segments that own them,
3768 - SEGMENT_BASES[0 .. NUM_SEGMENT_BASES - 1], holding the actual
3769 segment addresses reported by the target,
3770 store the appropriate offsets for each section in OFFSETS.
3772 If there are fewer entries in SEGMENT_BASES than there are segments
3773 in DATA, then apply SEGMENT_BASES' last entry to all the segments.
3775 If there are more entries, then ignore the extra. The target may
3776 not be able to distinguish between an empty data segment and a
3777 missing data segment; a missing text segment is less plausible. */
3779 symfile_map_offsets_to_segments (bfd
*abfd
, struct symfile_segment_data
*data
,
3780 struct section_offsets
*offsets
,
3781 int num_segment_bases
,
3782 const CORE_ADDR
*segment_bases
)
3787 /* It doesn't make sense to call this function unless you have some
3788 segment base addresses. */
3789 gdb_assert (num_segment_bases
> 0);
3791 /* If we do not have segment mappings for the object file, we
3792 can not relocate it by segments. */
3793 gdb_assert (data
!= NULL
);
3794 gdb_assert (data
->num_segments
> 0);
3796 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
3798 int which
= data
->segment_info
[i
];
3800 gdb_assert (0 <= which
&& which
<= data
->num_segments
);
3802 /* Don't bother computing offsets for sections that aren't
3803 loaded as part of any segment. */
3807 /* Use the last SEGMENT_BASES entry as the address of any extra
3808 segments mentioned in DATA->segment_info. */
3809 if (which
> num_segment_bases
)
3810 which
= num_segment_bases
;
3812 offsets
->offsets
[i
] = (segment_bases
[which
- 1]
3813 - data
->segment_bases
[which
- 1]);
3820 symfile_find_segment_sections (struct objfile
*objfile
)
3822 bfd
*abfd
= objfile
->obfd
;
3825 struct symfile_segment_data
*data
;
3827 data
= get_symfile_segment_data (objfile
->obfd
);
3831 if (data
->num_segments
!= 1 && data
->num_segments
!= 2)
3833 free_symfile_segment_data (data
);
3837 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
3839 int which
= data
->segment_info
[i
];
3843 if (objfile
->sect_index_text
== -1)
3844 objfile
->sect_index_text
= sect
->index
;
3846 if (objfile
->sect_index_rodata
== -1)
3847 objfile
->sect_index_rodata
= sect
->index
;
3849 else if (which
== 2)
3851 if (objfile
->sect_index_data
== -1)
3852 objfile
->sect_index_data
= sect
->index
;
3854 if (objfile
->sect_index_bss
== -1)
3855 objfile
->sect_index_bss
= sect
->index
;
3859 free_symfile_segment_data (data
);
3863 _initialize_symfile (void)
3865 struct cmd_list_element
*c
;
3867 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
, _("\
3868 Load symbol table from executable file FILE.\n\
3869 The `file' command can also load symbol tables, as well as setting the file\n\
3870 to execute."), &cmdlist
);
3871 set_cmd_completer (c
, filename_completer
);
3873 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
, _("\
3874 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
3875 Usage: add-symbol-file FILE ADDR [-s <SECT> <SECT_ADDR> -s <SECT> <SECT_ADDR>\
3876 ...]\nADDR is the starting address of the file's text.\n\
3877 The optional arguments are section-name section-address pairs and\n\
3878 should be specified if the data and bss segments are not contiguous\n\
3879 with the text. SECT is a section name to be loaded at SECT_ADDR."),
3881 set_cmd_completer (c
, filename_completer
);
3883 c
= add_cmd ("load", class_files
, load_command
, _("\
3884 Dynamically load FILE into the running program, and record its symbols\n\
3885 for access from GDB.\n\
3886 A load OFFSET may also be given."), &cmdlist
);
3887 set_cmd_completer (c
, filename_completer
);
3889 add_prefix_cmd ("overlay", class_support
, overlay_command
,
3890 _("Commands for debugging overlays."), &overlaylist
,
3891 "overlay ", 0, &cmdlist
);
3893 add_com_alias ("ovly", "overlay", class_alias
, 1);
3894 add_com_alias ("ov", "overlay", class_alias
, 1);
3896 add_cmd ("map-overlay", class_support
, map_overlay_command
,
3897 _("Assert that an overlay section is mapped."), &overlaylist
);
3899 add_cmd ("unmap-overlay", class_support
, unmap_overlay_command
,
3900 _("Assert that an overlay section is unmapped."), &overlaylist
);
3902 add_cmd ("list-overlays", class_support
, list_overlays_command
,
3903 _("List mappings of overlay sections."), &overlaylist
);
3905 add_cmd ("manual", class_support
, overlay_manual_command
,
3906 _("Enable overlay debugging."), &overlaylist
);
3907 add_cmd ("off", class_support
, overlay_off_command
,
3908 _("Disable overlay debugging."), &overlaylist
);
3909 add_cmd ("auto", class_support
, overlay_auto_command
,
3910 _("Enable automatic overlay debugging."), &overlaylist
);
3911 add_cmd ("load-target", class_support
, overlay_load_command
,
3912 _("Read the overlay mapping state from the target."), &overlaylist
);
3914 /* Filename extension to source language lookup table: */
3915 init_filename_language_table ();
3916 add_setshow_string_noescape_cmd ("extension-language", class_files
,
3918 Set mapping between filename extension and source language."), _("\
3919 Show mapping between filename extension and source language."), _("\
3920 Usage: set extension-language .foo bar"),
3921 set_ext_lang_command
,
3923 &setlist
, &showlist
);
3925 add_info ("extensions", info_ext_lang_command
,
3926 _("All filename extensions associated with a source language."));
3928 add_setshow_optional_filename_cmd ("debug-file-directory", class_support
,
3929 &debug_file_directory
, _("\
3930 Set the directories where separate debug symbols are searched for."), _("\
3931 Show the directories where separate debug symbols are searched for."), _("\
3932 Separate debug symbols are first searched for in the same\n\
3933 directory as the binary, then in the `" DEBUG_SUBDIRECTORY
"' subdirectory,\n\
3934 and lastly at the path of the directory of the binary with\n\
3935 each global debug-file-directory component prepended."),
3937 show_debug_file_directory
,
3938 &setlist
, &showlist
);