1 /* Generic symbol file reading for the GNU debugger, GDB.
3 Copyright (C) 1990-2024 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/>. */
22 #include "arch-utils.h"
23 #include "cli/cli-cmds.h"
24 #include "extract-store-integer.h"
33 #include "breakpoint.h"
35 #include "complaints.h"
38 #include "filenames.h"
39 #include "gdbsupport/gdb_obstack.h"
40 #include "completer.h"
41 #include "readline/tilde.h"
43 #include "observable.h"
49 #include "cli/cli-utils.h"
50 #include "gdbsupport/byte-vector.h"
51 #include "gdbsupport/pathstuff.h"
52 #include "gdbsupport/selftest.h"
53 #include "cli/cli-style.h"
54 #include "gdbsupport/forward-scope-exit.h"
55 #include "gdbsupport/buildargv.h"
57 #include <sys/types.h>
64 int (*deprecated_ui_load_progress_hook
) (const char *section
,
66 void (*deprecated_show_load_progress
) (const char *section
,
67 unsigned long section_sent
,
68 unsigned long section_size
,
69 unsigned long total_sent
,
70 unsigned long total_size
);
71 void (*deprecated_pre_add_symbol_hook
) (const char *);
72 void (*deprecated_post_add_symbol_hook
) (void);
74 using clear_symtab_users_cleanup
75 = FORWARD_SCOPE_EXIT (clear_symtab_users
);
77 /* Global variables owned by this file. */
81 int readnow_symbol_files
;
85 int readnever_symbol_files
;
87 /* Functions this file defines. */
89 static void symbol_file_add_main_1 (const char *args
, symfile_add_flags add_flags
,
90 objfile_flags flags
, CORE_ADDR reloff
);
92 static const struct sym_fns
*find_sym_fns (bfd
*);
94 static void simple_free_overlay_table (void);
96 static void read_target_long_array (CORE_ADDR
, unsigned int *, int, int,
99 static int simple_read_overlay_table (void);
101 static int simple_overlay_update_1 (struct obj_section
*);
103 static void symfile_find_segment_sections (struct objfile
*objfile
);
105 /* List of all available sym_fns. On gdb startup, each object file reader
106 calls add_symtab_fns() to register information on each format it is
109 struct registered_sym_fns
111 registered_sym_fns (bfd_flavour sym_flavour_
, const struct sym_fns
*sym_fns_
)
112 : sym_flavour (sym_flavour_
), sym_fns (sym_fns_
)
115 /* BFD flavour that we handle. */
116 enum bfd_flavour sym_flavour
;
118 /* The "vtable" of symbol functions. */
119 const struct sym_fns
*sym_fns
;
122 static std::vector
<registered_sym_fns
> symtab_fns
;
124 /* Values for "set print symbol-loading". */
126 const char print_symbol_loading_off
[] = "off";
127 const char print_symbol_loading_brief
[] = "brief";
128 const char print_symbol_loading_full
[] = "full";
129 static const char *print_symbol_loading_enums
[] =
131 print_symbol_loading_off
,
132 print_symbol_loading_brief
,
133 print_symbol_loading_full
,
136 static const char *print_symbol_loading
= print_symbol_loading_full
;
140 bool auto_solib_add
= true;
143 /* Return non-zero if symbol-loading messages should be printed.
144 FROM_TTY is the standard from_tty argument to gdb commands.
145 If EXEC is non-zero the messages are for the executable.
146 Otherwise, messages are for shared libraries.
147 If FULL is non-zero then the caller is printing a detailed message.
148 E.g., the message includes the shared library name.
149 Otherwise, the caller is printing a brief "summary" message. */
152 print_symbol_loading_p (int from_tty
, int exec
, int full
)
154 if (!from_tty
&& !info_verbose
)
159 /* We don't check FULL for executables, there are few such
160 messages, therefore brief == full. */
161 return print_symbol_loading
!= print_symbol_loading_off
;
164 return print_symbol_loading
== print_symbol_loading_full
;
165 return print_symbol_loading
== print_symbol_loading_brief
;
168 /* True if we are reading a symbol table. */
170 int currently_reading_symtab
= 0;
172 /* Increment currently_reading_symtab and return a cleanup that can be
173 used to decrement it. */
175 scoped_restore_tmpl
<int>
176 increment_reading_symtab (void)
178 gdb_assert (currently_reading_symtab
>= 0);
179 return make_scoped_restore (¤tly_reading_symtab
,
180 currently_reading_symtab
+ 1);
183 /* Remember the lowest-addressed loadable section we've seen.
185 In case of equal vmas, the section with the largest size becomes the
186 lowest-addressed loadable section.
188 If the vmas and sizes are equal, the last section is considered the
189 lowest-addressed loadable section. */
192 find_lowest_section (asection
*sect
, asection
**lowest
)
194 if (0 == (bfd_section_flags (sect
) & (SEC_ALLOC
| SEC_LOAD
)))
197 *lowest
= sect
; /* First loadable section */
198 else if (bfd_section_vma (*lowest
) > bfd_section_vma (sect
))
199 *lowest
= sect
; /* A lower loadable section */
200 else if (bfd_section_vma (*lowest
) == bfd_section_vma (sect
)
201 && (bfd_section_size (*lowest
) <= bfd_section_size (sect
)))
205 /* Build (allocate and populate) a section_addr_info struct from
206 an existing section table. */
209 build_section_addr_info_from_section_table (const std::vector
<target_section
> &table
)
211 section_addr_info sap
;
213 for (const target_section
&stp
: table
)
215 struct bfd_section
*asect
= stp
.the_bfd_section
;
216 bfd
*abfd
= asect
->owner
;
218 if (bfd_section_flags (asect
) & (SEC_ALLOC
| SEC_LOAD
)
219 && sap
.size () < table
.size ())
220 sap
.emplace_back (stp
.addr
,
221 bfd_section_name (asect
),
222 gdb_bfd_section_index (abfd
, asect
));
228 /* Create a section_addr_info from section offsets in ABFD. */
230 static section_addr_info
231 build_section_addr_info_from_bfd (bfd
*abfd
)
233 struct bfd_section
*sec
;
235 section_addr_info sap
;
236 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
237 if (bfd_section_flags (sec
) & (SEC_ALLOC
| SEC_LOAD
))
238 sap
.emplace_back (bfd_section_vma (sec
),
239 bfd_section_name (sec
),
240 gdb_bfd_section_index (abfd
, sec
));
245 /* Create a section_addr_info from section offsets in OBJFILE. */
248 build_section_addr_info_from_objfile (const struct objfile
*objfile
)
252 /* Before reread_symbols gets rewritten it is not safe to call:
253 gdb_assert (objfile->num_sections == bfd_count_sections (objfile->obfd));
255 section_addr_info sap
256 = build_section_addr_info_from_bfd (objfile
->obfd
.get ());
257 for (i
= 0; i
< sap
.size (); i
++)
259 int sectindex
= sap
[i
].sectindex
;
261 sap
[i
].addr
+= objfile
->section_offsets
[sectindex
];
266 /* Initialize OBJFILE's sect_index_* members. */
269 init_objfile_sect_indices (struct objfile
*objfile
)
274 sect
= bfd_get_section_by_name (objfile
->obfd
.get (), ".text");
276 objfile
->sect_index_text
= sect
->index
;
278 sect
= bfd_get_section_by_name (objfile
->obfd
.get (), ".data");
280 objfile
->sect_index_data
= sect
->index
;
282 sect
= bfd_get_section_by_name (objfile
->obfd
.get (), ".bss");
284 objfile
->sect_index_bss
= sect
->index
;
286 sect
= bfd_get_section_by_name (objfile
->obfd
.get (), ".rodata");
288 objfile
->sect_index_rodata
= sect
->index
;
290 /* This is where things get really weird... We MUST have valid
291 indices for the various sect_index_* members or gdb will abort.
292 So if for example, there is no ".text" section, we have to
293 accommodate that. First, check for a file with the standard
294 one or two segments. */
296 symfile_find_segment_sections (objfile
);
298 /* Except when explicitly adding symbol files at some address,
299 section_offsets contains nothing but zeros, so it doesn't matter
300 which slot in section_offsets the individual sect_index_* members
301 index into. So if they are all zero, it is safe to just point
302 all the currently uninitialized indices to the first slot. But
303 beware: if this is the main executable, it may be relocated
304 later, e.g. by the remote qOffsets packet, and then this will
305 be wrong! That's why we try segments first. */
307 for (i
= 0; i
< objfile
->section_offsets
.size (); i
++)
309 if (objfile
->section_offsets
[i
] != 0)
314 if (i
== objfile
->section_offsets
.size ())
316 if (objfile
->sect_index_text
== -1)
317 objfile
->sect_index_text
= 0;
318 if (objfile
->sect_index_data
== -1)
319 objfile
->sect_index_data
= 0;
320 if (objfile
->sect_index_bss
== -1)
321 objfile
->sect_index_bss
= 0;
322 if (objfile
->sect_index_rodata
== -1)
323 objfile
->sect_index_rodata
= 0;
327 /* Find a unique offset to use for loadable section SECT if
328 the user did not provide an offset. */
331 place_section (bfd
*abfd
, asection
*sect
, section_offsets
&offsets
,
334 CORE_ADDR start_addr
;
336 ULONGEST align
= ((ULONGEST
) 1) << bfd_section_alignment (sect
);
338 /* We are only interested in allocated sections. */
339 if ((bfd_section_flags (sect
) & SEC_ALLOC
) == 0)
342 /* If the user specified an offset, honor it. */
343 if (offsets
[gdb_bfd_section_index (abfd
, sect
)] != 0)
346 /* Otherwise, let's try to find a place for the section. */
347 start_addr
= (lowest
+ align
- 1) & -align
;
354 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
; cur_sec
= cur_sec
->next
)
356 int indx
= cur_sec
->index
;
358 /* We don't need to compare against ourself. */
362 /* We can only conflict with allocated sections. */
363 if ((bfd_section_flags (cur_sec
) & SEC_ALLOC
) == 0)
366 /* If the section offset is 0, either the section has not been placed
367 yet, or it was the lowest section placed (in which case LOWEST
368 will be past its end). */
369 if (offsets
[indx
] == 0)
372 /* If this section would overlap us, then we must move up. */
373 if (start_addr
+ bfd_section_size (sect
) > offsets
[indx
]
374 && start_addr
< offsets
[indx
] + bfd_section_size (cur_sec
))
376 start_addr
= offsets
[indx
] + bfd_section_size (cur_sec
);
377 start_addr
= (start_addr
+ align
- 1) & -align
;
382 /* Otherwise, we appear to be OK. So far. */
387 offsets
[gdb_bfd_section_index (abfd
, sect
)] = start_addr
;
388 lowest
= start_addr
+ bfd_section_size (sect
);
391 /* Store section_addr_info as prepared (made relative and with SECTINDEX
392 filled-in) by addr_info_make_relative into SECTION_OFFSETS. */
395 relative_addr_info_to_section_offsets (section_offsets
§ion_offsets
,
396 const section_addr_info
&addrs
)
400 section_offsets
.assign (section_offsets
.size (), 0);
402 /* Now calculate offsets for section that were specified by the caller. */
403 for (i
= 0; i
< addrs
.size (); i
++)
405 const struct other_sections
*osp
;
408 if (osp
->sectindex
== -1)
411 /* Record all sections in offsets. */
412 /* The section_offsets in the objfile are here filled in using
414 section_offsets
[osp
->sectindex
] = osp
->addr
;
418 /* Transform section name S for a name comparison. prelink can split section
419 `.bss' into two sections `.dynbss' and `.bss' (in this order). Similarly
420 prelink can split `.sbss' into `.sdynbss' and `.sbss'. Use virtual address
421 of the new `.dynbss' (`.sdynbss') section as the adjacent new `.bss'
422 (`.sbss') section has invalid (increased) virtual address. */
425 addr_section_name (const char *s
)
427 if (strcmp (s
, ".dynbss") == 0)
429 if (strcmp (s
, ".sdynbss") == 0)
435 /* std::sort comparator for addrs_section_sort. Sort entries in
436 ascending order by their (name, sectindex) pair. sectindex makes
437 the sort by name stable. */
440 addrs_section_compar (const struct other_sections
*a
,
441 const struct other_sections
*b
)
445 retval
= strcmp (addr_section_name (a
->name
.c_str ()),
446 addr_section_name (b
->name
.c_str ()));
450 return a
->sectindex
< b
->sectindex
;
453 /* Provide sorted array of pointers to sections of ADDRS. */
455 static std::vector
<const struct other_sections
*>
456 addrs_section_sort (const section_addr_info
&addrs
)
460 std::vector
<const struct other_sections
*> array (addrs
.size ());
461 for (i
= 0; i
< addrs
.size (); i
++)
462 array
[i
] = &addrs
[i
];
464 std::sort (array
.begin (), array
.end (), addrs_section_compar
);
469 /* Relativize absolute addresses in ADDRS into offsets based on ABFD. Fill-in
470 also SECTINDEXes specific to ABFD there. This function can be used to
471 rebase ADDRS to start referencing different BFD than before. */
474 addr_info_make_relative (section_addr_info
*addrs
, bfd
*abfd
)
476 asection
*lower_sect
;
477 CORE_ADDR lower_offset
;
480 /* Find lowest loadable section to be used as starting point for
481 contiguous sections. */
483 for (asection
*iter
: gdb_bfd_sections (abfd
))
484 find_lowest_section (iter
, &lower_sect
);
485 if (lower_sect
== NULL
)
487 warning (_("no loadable sections found in added symbol-file %s"),
488 bfd_get_filename (abfd
));
492 lower_offset
= bfd_section_vma (lower_sect
);
494 /* Create ADDRS_TO_ABFD_ADDRS array to map the sections in ADDRS to sections
495 in ABFD. Section names are not unique - there can be multiple sections of
496 the same name. Also the sections of the same name do not have to be
497 adjacent to each other. Some sections may be present only in one of the
498 files. Even sections present in both files do not have to be in the same
501 Use stable sort by name for the sections in both files. Then linearly
502 scan both lists matching as most of the entries as possible. */
504 std::vector
<const struct other_sections
*> addrs_sorted
505 = addrs_section_sort (*addrs
);
507 section_addr_info abfd_addrs
= build_section_addr_info_from_bfd (abfd
);
508 std::vector
<const struct other_sections
*> abfd_addrs_sorted
509 = addrs_section_sort (abfd_addrs
);
511 /* Now create ADDRS_TO_ABFD_ADDRS from ADDRS_SORTED and
512 ABFD_ADDRS_SORTED. */
514 std::vector
<const struct other_sections
*>
515 addrs_to_abfd_addrs (addrs
->size (), nullptr);
517 std::vector
<const struct other_sections
*>::iterator abfd_sorted_iter
518 = abfd_addrs_sorted
.begin ();
519 for (const other_sections
*sect
: addrs_sorted
)
521 const char *sect_name
= addr_section_name (sect
->name
.c_str ());
523 while (abfd_sorted_iter
!= abfd_addrs_sorted
.end ()
524 && strcmp (addr_section_name ((*abfd_sorted_iter
)->name
.c_str ()),
528 if (abfd_sorted_iter
!= abfd_addrs_sorted
.end ()
529 && strcmp (addr_section_name ((*abfd_sorted_iter
)->name
.c_str ()),
534 /* Make the found item directly addressable from ADDRS. */
535 index_in_addrs
= sect
- addrs
->data ();
536 gdb_assert (addrs_to_abfd_addrs
[index_in_addrs
] == NULL
);
537 addrs_to_abfd_addrs
[index_in_addrs
] = *abfd_sorted_iter
;
539 /* Never use the same ABFD entry twice. */
544 /* Calculate offsets for the loadable sections.
545 FIXME! Sections must be in order of increasing loadable section
546 so that contiguous sections can use the lower-offset!!!
548 Adjust offsets if the segments are not contiguous.
549 If the section is contiguous, its offset should be set to
550 the offset of the highest loadable section lower than it
551 (the loadable section directly below it in memory).
552 this_offset = lower_offset = lower_addr - lower_orig_addr */
554 for (i
= 0; i
< addrs
->size (); i
++)
556 const struct other_sections
*sect
= addrs_to_abfd_addrs
[i
];
560 /* This is the index used by BFD. */
561 (*addrs
)[i
].sectindex
= sect
->sectindex
;
563 if ((*addrs
)[i
].addr
!= 0)
565 (*addrs
)[i
].addr
-= sect
->addr
;
566 lower_offset
= (*addrs
)[i
].addr
;
569 (*addrs
)[i
].addr
= lower_offset
;
573 /* addr_section_name transformation is not used for SECT_NAME. */
574 const std::string
§_name
= (*addrs
)[i
].name
;
576 /* This section does not exist in ABFD, which is normally
577 unexpected and we want to issue a warning.
579 However, the ELF prelinker does create a few sections which are
580 marked in the main executable as loadable (they are loaded in
581 memory from the DYNAMIC segment) and yet are not present in
582 separate debug info files. This is fine, and should not cause
583 a warning. Shared libraries contain just the section
584 ".gnu.liblist" but it is not marked as loadable there. There is
585 no other way to identify them than by their name as the sections
586 created by prelink have no special flags.
588 For the sections `.bss' and `.sbss' see addr_section_name. */
590 if (!(sect_name
== ".gnu.liblist"
591 || sect_name
== ".gnu.conflict"
592 || (sect_name
== ".bss"
594 && (*addrs
)[i
- 1].name
== ".dynbss"
595 && addrs_to_abfd_addrs
[i
- 1] != NULL
)
596 || (sect_name
== ".sbss"
598 && (*addrs
)[i
- 1].name
== ".sdynbss"
599 && addrs_to_abfd_addrs
[i
- 1] != NULL
)))
600 warning (_("section %s not found in %s"), sect_name
.c_str (),
601 bfd_get_filename (abfd
));
603 (*addrs
)[i
].addr
= 0;
604 (*addrs
)[i
].sectindex
= -1;
609 /* Parse the user's idea of an offset for dynamic linking, into our idea
610 of how to represent it for fast symbol reading. This is the default
611 version of the sym_fns.sym_offsets function for symbol readers that
612 don't need to do anything special. It allocates a section_offsets table
613 for the objectfile OBJFILE and stuffs ADDR into all of the offsets. */
616 default_symfile_offsets (struct objfile
*objfile
,
617 const section_addr_info
&addrs
)
619 objfile
->section_offsets
.resize (gdb_bfd_count_sections (objfile
->obfd
.get ()));
620 relative_addr_info_to_section_offsets (objfile
->section_offsets
, addrs
);
622 /* For relocatable files, all loadable sections will start at zero.
623 The zero is meaningless, so try to pick arbitrary addresses such
624 that no loadable sections overlap. This algorithm is quadratic,
625 but the number of sections in a single object file is generally
627 if ((bfd_get_file_flags (objfile
->obfd
.get ()) & (EXEC_P
| DYNAMIC
)) == 0)
629 bfd
*abfd
= objfile
->obfd
.get ();
632 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
; cur_sec
= cur_sec
->next
)
633 /* We do not expect this to happen; just skip this step if the
634 relocatable file has a section with an assigned VMA. */
635 if (bfd_section_vma (cur_sec
) != 0)
640 section_offsets
&offsets
= objfile
->section_offsets
;
642 /* Pick non-overlapping offsets for sections the user did not
644 CORE_ADDR lowest
= 0;
645 for (asection
*sect
: gdb_bfd_sections (objfile
->obfd
.get ()))
646 place_section (objfile
->obfd
.get (), sect
, objfile
->section_offsets
,
649 /* Correctly filling in the section offsets is not quite
650 enough. Relocatable files have two properties that
651 (most) shared objects do not:
653 - Their debug information will contain relocations. Some
654 shared libraries do also, but many do not, so this can not
657 - If there are multiple code sections they will be loaded
658 at different relative addresses in memory than they are
659 in the objfile, since all sections in the file will start
662 Because GDB has very limited ability to map from an
663 address in debug info to the correct code section,
664 it relies on adding SECT_OFF_TEXT to things which might be
665 code. If we clear all the section offsets, and set the
666 section VMAs instead, then symfile_relocate_debug_section
667 will return meaningful debug information pointing at the
670 GDB has too many different data structures for section
671 addresses - a bfd, objfile, and so_list all have section
672 tables, as does exec_ops. Some of these could probably
675 for (cur_sec
= abfd
->sections
; cur_sec
!= NULL
;
676 cur_sec
= cur_sec
->next
)
678 if ((bfd_section_flags (cur_sec
) & SEC_ALLOC
) == 0)
681 bfd_set_section_vma (cur_sec
, offsets
[cur_sec
->index
]);
682 exec_set_section_address (bfd_get_filename (abfd
),
684 offsets
[cur_sec
->index
]);
685 offsets
[cur_sec
->index
] = 0;
690 /* Remember the bfd indexes for the .text, .data, .bss and
692 init_objfile_sect_indices (objfile
);
695 /* Divide the file into segments, which are individual relocatable units.
696 This is the default version of the sym_fns.sym_segments function for
697 symbol readers that do not have an explicit representation of segments.
698 It assumes that object files do not have segments, and fully linked
699 files have a single segment. */
701 symfile_segment_data_up
702 default_symfile_segments (bfd
*abfd
)
708 /* Relocatable files contain enough information to position each
709 loadable section independently; they should not be relocated
711 if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
)) == 0)
714 /* Make sure there is at least one loadable section in the file. */
715 for (sect
= abfd
->sections
; sect
!= NULL
; sect
= sect
->next
)
717 if ((bfd_section_flags (sect
) & SEC_ALLOC
) == 0)
725 low
= bfd_section_vma (sect
);
726 high
= low
+ bfd_section_size (sect
);
728 symfile_segment_data_up
data (new symfile_segment_data
);
730 num_sections
= bfd_count_sections (abfd
);
732 /* All elements are initialized to 0 (map to no segment). */
733 data
->segment_info
.resize (num_sections
);
735 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
739 if ((bfd_section_flags (sect
) & SEC_ALLOC
) == 0)
742 vma
= bfd_section_vma (sect
);
745 if (vma
+ bfd_section_size (sect
) > high
)
746 high
= vma
+ bfd_section_size (sect
);
748 data
->segment_info
[i
] = 1;
751 data
->segments
.emplace_back (low
, high
- low
);
756 /* This is a convenience function to call sym_read for OBJFILE and
757 possibly force the partial symbols to be read. */
760 read_symbols (struct objfile
*objfile
, symfile_add_flags add_flags
)
762 (*objfile
->sf
->sym_read
) (objfile
, add_flags
);
763 objfile
->per_bfd
->minsyms_read
= true;
765 /* find_separate_debug_file_in_section should be called only if there is
766 single binary with no existing separate debug info file. */
767 if (!objfile
->has_partial_symbols ()
768 && objfile
->separate_debug_objfile
== NULL
769 && objfile
->separate_debug_objfile_backlink
== NULL
)
771 gdb_bfd_ref_ptr
abfd (find_separate_debug_file_in_section (objfile
));
775 /* find_separate_debug_file_in_section uses the same filename for the
776 virtual section-as-bfd like the bfd filename containing the
777 section. Therefore use also non-canonical name form for the same
778 file containing the section. */
779 symbol_file_add_separate (abfd
, bfd_get_filename (abfd
.get ()),
780 add_flags
| SYMFILE_NOT_FILENAME
, objfile
);
785 /* Initialize entry point information for this objfile. */
788 init_entry_point_info (struct objfile
*objfile
)
790 struct entry_info
*ei
= &objfile
->per_bfd
->ei
;
796 /* Save startup file's range of PC addresses to help blockframe.c
797 decide where the bottom of the stack is. */
799 if (bfd_get_file_flags (objfile
->obfd
.get ()) & EXEC_P
)
801 /* Executable file -- record its entry point so we'll recognize
802 the startup file because it contains the entry point. */
803 ei
->entry_point
= bfd_get_start_address (objfile
->obfd
.get ());
804 ei
->entry_point_p
= 1;
806 else if (bfd_get_file_flags (objfile
->obfd
.get ()) & DYNAMIC
807 && bfd_get_start_address (objfile
->obfd
.get ()) != 0)
809 /* Some shared libraries may have entry points set and be
810 runnable. There's no clear way to indicate this, so just check
811 for values other than zero. */
812 ei
->entry_point
= bfd_get_start_address (objfile
->obfd
.get ());
813 ei
->entry_point_p
= 1;
817 /* Examination of non-executable.o files. Short-circuit this stuff. */
818 ei
->entry_point_p
= 0;
821 if (ei
->entry_point_p
)
823 CORE_ADDR entry_point
= ei
->entry_point
;
826 /* Make certain that the address points at real code, and not a
827 function descriptor. */
828 entry_point
= gdbarch_convert_from_func_ptr_addr
829 (objfile
->arch (), entry_point
, current_inferior ()->top_target ());
831 /* Remove any ISA markers, so that this matches entries in the
834 = gdbarch_addr_bits_remove (objfile
->arch (), entry_point
);
837 for (obj_section
*osect
: objfile
->sections ())
839 struct bfd_section
*sect
= osect
->the_bfd_section
;
841 if (entry_point
>= bfd_section_vma (sect
)
842 && entry_point
< (bfd_section_vma (sect
)
843 + bfd_section_size (sect
)))
845 ei
->the_bfd_section_index
846 = gdb_bfd_section_index (objfile
->obfd
.get (), sect
);
853 ei
->the_bfd_section_index
= SECT_OFF_TEXT (objfile
);
857 /* Process a symbol file, as either the main file or as a dynamically
860 This function does not set the OBJFILE's entry-point info.
862 OBJFILE is where the symbols are to be read from.
864 ADDRS is the list of section load addresses. If the user has given
865 an 'add-symbol-file' command, then this is the list of offsets and
866 addresses he or she provided as arguments to the command; or, if
867 we're handling a shared library, these are the actual addresses the
868 sections are loaded at, according to the inferior's dynamic linker
869 (as gleaned by GDB's shared library code). We convert each address
870 into an offset from the section VMA's as it appears in the object
871 file, and then call the file's sym_offsets function to convert this
872 into a format-specific offset table --- a `section_offsets'.
873 The sectindex field is used to control the ordering of sections
874 with the same name. Upon return, it is updated to contain the
875 corresponding BFD section index, or -1 if the section was not found.
877 ADD_FLAGS encodes verbosity level, whether this is main symbol or
878 an extra symbol file such as dynamically loaded code, and whether
879 breakpoint reset should be deferred. */
882 syms_from_objfile_1 (struct objfile
*objfile
,
883 section_addr_info
*addrs
,
884 symfile_add_flags add_flags
)
886 section_addr_info local_addr
;
887 const int mainline
= add_flags
& SYMFILE_MAINLINE
;
889 objfile_set_sym_fns (objfile
, find_sym_fns (objfile
->obfd
.get ()));
890 objfile
->qf
.clear ();
892 if (objfile
->sf
== NULL
)
894 /* No symbols to load, but we still need to make sure
895 that the section_offsets table is allocated. */
896 int num_sections
= gdb_bfd_count_sections (objfile
->obfd
.get ());
898 objfile
->section_offsets
.assign (num_sections
, 0);
902 /* Make sure that partially constructed symbol tables will be cleaned up
903 if an error occurs during symbol reading. */
904 std::optional
<clear_symtab_users_cleanup
> defer_clear_users
;
906 objfile_up
objfile_holder (objfile
);
908 /* If ADDRS is NULL, put together a dummy address list.
909 We now establish the convention that an addr of zero means
910 no load address was specified. */
916 /* We will modify the main symbol table, make sure that all its users
917 will be cleaned up if an error occurs during symbol reading. */
918 defer_clear_users
.emplace ((symfile_add_flag
) 0);
920 /* Since no error yet, throw away the old symbol table. */
922 if (current_program_space
->symfile_object_file
!= NULL
)
924 current_program_space
->symfile_object_file
->unlink ();
925 gdb_assert (current_program_space
->symfile_object_file
== NULL
);
928 /* Currently we keep symbols from the add-symbol-file command.
929 If the user wants to get rid of them, they should do "symbol-file"
930 without arguments first. Not sure this is the best behavior
933 (*objfile
->sf
->sym_new_init
) (objfile
);
936 /* Convert addr into an offset rather than an absolute address.
937 We find the lowest address of a loaded segment in the objfile,
938 and assume that <addr> is where that got loaded.
940 We no longer warn if the lowest section is not a text segment (as
941 happens for the PA64 port. */
942 if (addrs
->size () > 0)
943 addr_info_make_relative (addrs
, objfile
->obfd
.get ());
945 /* Initialize symbol reading routines for this objfile, allow complaints to
946 appear for this new file, and record how verbose to be, then do the
947 initial symbol reading for this file. */
949 (*objfile
->sf
->sym_init
) (objfile
);
952 (*objfile
->sf
->sym_offsets
) (objfile
, *addrs
);
954 read_symbols (objfile
, add_flags
);
956 /* Discard cleanups as symbol reading was successful. */
958 objfile_holder
.release ();
959 if (defer_clear_users
)
960 defer_clear_users
->release ();
963 /* Same as syms_from_objfile_1, but also initializes the objfile
967 syms_from_objfile (struct objfile
*objfile
,
968 section_addr_info
*addrs
,
969 symfile_add_flags add_flags
)
971 syms_from_objfile_1 (objfile
, addrs
, add_flags
);
972 init_entry_point_info (objfile
);
975 /* Perform required actions after either reading in the initial
976 symbols for a new objfile, or mapping in the symbols from a reusable
977 objfile. ADD_FLAGS is a bitmask of enum symfile_add_flags. */
980 finish_new_objfile (struct objfile
*objfile
, symfile_add_flags add_flags
)
982 /* If this is the main symbol file we have to clean up all users of the
983 old main symbol file. Otherwise it is sufficient to fixup all the
984 breakpoints that may have been redefined by this symbol file. */
985 if (add_flags
& SYMFILE_MAINLINE
)
987 /* OK, make it the "real" symbol file. */
988 current_program_space
->symfile_object_file
= objfile
;
990 clear_symtab_users (add_flags
);
992 else if ((add_flags
& SYMFILE_DEFER_BP_RESET
) == 0)
994 breakpoint_re_set ();
997 /* We're done reading the symbol file; finish off complaints. */
1001 /* Process a symbol file, as either the main file or as a dynamically
1004 ABFD is a BFD already open on the file, as from symfile_bfd_open.
1005 A new reference is acquired by this function.
1007 For NAME description see the objfile constructor.
1009 ADD_FLAGS encodes verbosity, whether this is main symbol file or
1010 extra, such as dynamically loaded code, and what to do with breakpoints.
1012 ADDRS is as described for syms_from_objfile_1, above.
1013 ADDRS is ignored when SYMFILE_MAINLINE bit is set in ADD_FLAGS.
1015 PARENT is the original objfile if ABFD is a separate debug info file.
1016 Otherwise PARENT is NULL.
1018 Upon success, returns a pointer to the objfile that was added.
1019 Upon failure, jumps back to command level (never returns). */
1021 static struct objfile
*
1022 symbol_file_add_with_addrs (const gdb_bfd_ref_ptr
&abfd
, const char *name
,
1023 symfile_add_flags add_flags
,
1024 section_addr_info
*addrs
,
1025 objfile_flags flags
, struct objfile
*parent
)
1027 const int from_tty
= add_flags
& SYMFILE_VERBOSE
;
1028 const int mainline
= add_flags
& SYMFILE_MAINLINE
;
1029 const int always_confirm
= add_flags
& SYMFILE_ALWAYS_CONFIRM
;
1030 const int should_print
= (print_symbol_loading_p (from_tty
, mainline
, 1)
1031 && (readnow_symbol_files
1032 || (add_flags
& SYMFILE_NO_READ
) == 0));
1034 if (readnow_symbol_files
)
1036 flags
|= OBJF_READNOW
;
1037 add_flags
&= ~SYMFILE_NO_READ
;
1039 else if (readnever_symbol_files
1040 || (parent
!= NULL
&& (parent
->flags
& OBJF_READNEVER
)))
1042 flags
|= OBJF_READNEVER
;
1043 add_flags
|= SYMFILE_NO_READ
;
1045 if ((add_flags
& SYMFILE_NOT_FILENAME
) != 0)
1046 flags
|= OBJF_NOT_FILENAME
;
1048 /* Give user a chance to burp if ALWAYS_CONFIRM or we'd be
1049 interactively wiping out any existing symbols. */
1053 || ((have_full_symbols (current_program_space
)
1054 || have_partial_symbols (current_program_space
))
1056 && !query (_ ("Load new symbol table from \"%s\"? "), name
))
1057 error (_("Not confirmed."));
1060 flags
|= OBJF_MAINLINE
;
1063 = objfile::make (abfd
, current_program_space
, name
, flags
, parent
);
1065 /* We either created a new mapped symbol table, mapped an existing
1066 symbol table file which has not had initial symbol reading
1067 performed, or need to read an unmapped symbol table. */
1070 if (deprecated_pre_add_symbol_hook
)
1071 deprecated_pre_add_symbol_hook (name
);
1073 gdb_printf (_("Reading symbols from %ps...\n"),
1074 styled_string (file_name_style
.style (), name
));
1076 syms_from_objfile (objfile
, addrs
, add_flags
);
1078 /* We now have at least a partial symbol table. Check to see if the
1079 user requested that all symbols be read on initial access via either
1080 the gdb startup command line or on a per symbol file basis. Expand
1081 all partial symbol tables for this objfile if so. */
1083 if ((flags
& OBJF_READNOW
))
1086 gdb_printf (_("Expanding full symbols from %ps...\n"),
1087 styled_string (file_name_style
.style (), name
));
1089 objfile
->expand_all_symtabs ();
1092 /* Note that we only print a message if we have no symbols and have
1093 no separate debug file. If there is a separate debug file which
1094 does not have symbols, we'll have emitted this message for that
1095 file, and so printing it twice is just redundant. */
1096 if (should_print
&& !objfile_has_symbols (objfile
)
1097 && objfile
->separate_debug_objfile
== nullptr)
1098 gdb_printf (_("(No debugging symbols found in %ps)\n"),
1099 styled_string (file_name_style
.style (), name
));
1103 if (deprecated_post_add_symbol_hook
)
1104 deprecated_post_add_symbol_hook ();
1107 /* We print some messages regardless of whether 'from_tty ||
1108 info_verbose' is true, so make sure they go out at the right
1110 gdb_flush (gdb_stdout
);
1112 if (objfile
->sf
!= nullptr)
1113 finish_new_objfile (objfile
, add_flags
);
1115 gdb::observers::new_objfile
.notify (objfile
);
1120 /* Add BFD as a separate debug file for OBJFILE. For NAME description
1121 see the objfile constructor. */
1124 symbol_file_add_separate (const gdb_bfd_ref_ptr
&bfd
, const char *name
,
1125 symfile_add_flags symfile_flags
,
1126 struct objfile
*objfile
)
1128 /* Create section_addr_info. We can't directly use offsets from OBJFILE
1129 because sections of BFD may not match sections of OBJFILE and because
1130 vma may have been modified by tools such as prelink. */
1131 section_addr_info sap
= build_section_addr_info_from_objfile (objfile
);
1133 symbol_file_add_with_addrs
1134 (bfd
, name
, symfile_flags
, &sap
,
1135 objfile
->flags
& (OBJF_SHARED
| OBJF_READNOW
1136 | OBJF_USERLOADED
| OBJF_MAINLINE
),
1140 /* Process the symbol file ABFD, as either the main file or as a
1141 dynamically loaded file.
1142 See symbol_file_add_with_addrs's comments for details. */
1145 symbol_file_add_from_bfd (const gdb_bfd_ref_ptr
&abfd
, const char *name
,
1146 symfile_add_flags add_flags
,
1147 section_addr_info
*addrs
,
1148 objfile_flags flags
, struct objfile
*parent
)
1150 return symbol_file_add_with_addrs (abfd
, name
, add_flags
, addrs
, flags
,
1154 /* Process a symbol file, as either the main file or as a dynamically
1155 loaded file. See symbol_file_add_with_addrs's comments for details. */
1158 symbol_file_add (const char *name
, symfile_add_flags add_flags
,
1159 section_addr_info
*addrs
, objfile_flags flags
)
1161 gdb_bfd_ref_ptr
bfd (symfile_bfd_open (name
));
1163 return symbol_file_add_from_bfd (bfd
, name
, add_flags
, addrs
,
1167 /* Call symbol_file_add() with default values and update whatever is
1168 affected by the loading of a new main().
1169 Used when the file is supplied in the gdb command line
1170 and by some targets with special loading requirements.
1171 The auxiliary function, symbol_file_add_main_1(), has the flags
1172 argument for the switches that can only be specified in the symbol_file
1176 symbol_file_add_main (const char *args
, symfile_add_flags add_flags
)
1178 symbol_file_add_main_1 (args
, add_flags
, 0, 0);
1182 symbol_file_add_main_1 (const char *args
, symfile_add_flags add_flags
,
1183 objfile_flags flags
, CORE_ADDR reloff
)
1185 add_flags
|= current_inferior ()->symfile_flags
| SYMFILE_MAINLINE
;
1187 struct objfile
*objfile
= symbol_file_add (args
, add_flags
, NULL
, flags
);
1189 objfile_rebase (objfile
, reloff
);
1191 /* Getting new symbols may change our opinion about
1192 what is frameless. */
1193 reinit_frame_cache ();
1195 if ((add_flags
& SYMFILE_NO_READ
) == 0)
1196 set_initial_language ();
1200 symbol_file_clear (int from_tty
)
1202 if ((have_full_symbols (current_program_space
)
1203 || have_partial_symbols (current_program_space
))
1205 && (current_program_space
->symfile_object_file
1206 ? !query (_("Discard symbol table from `%s'? "),
1207 objfile_name (current_program_space
->symfile_object_file
))
1208 : !query (_("Discard symbol table? "))))
1209 error (_("Not confirmed."));
1211 /* solib descriptors may have handles to objfiles. Wipe them before their
1212 objfiles get stale by free_all_objfiles. */
1213 no_shared_libraries (current_program_space
);
1215 current_program_space
->free_all_objfiles ();
1217 clear_symtab_users (0);
1219 gdb_assert (current_program_space
->symfile_object_file
== NULL
);
1221 gdb_printf (_("No symbol file now.\n"));
1224 /* See symfile.h. */
1226 bool separate_debug_file_debug
= false;
1229 separate_debug_file_exists (const std::string
&name
, unsigned long crc
,
1230 struct objfile
*parent_objfile
,
1231 deferred_warnings
*warnings
)
1233 SEPARATE_DEBUG_FILE_SCOPED_DEBUG_ENTER_EXIT
;
1235 unsigned long file_crc
;
1237 struct stat parent_stat
, abfd_stat
;
1238 int verified_as_different
;
1240 /* Find a separate debug info file as if symbols would be present in
1241 PARENT_OBJFILE itself this function would not be called. .gnu_debuglink
1242 section can contain just the basename of PARENT_OBJFILE without any
1243 ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
1244 the separate debug infos with the same basename can exist. */
1246 if (filename_cmp (name
.c_str (), objfile_name (parent_objfile
)) == 0)
1249 separate_debug_file_debug_printf ("Trying %s...", name
.c_str ());
1251 gdb_bfd_ref_ptr
abfd (gdb_bfd_open (name
.c_str (), gnutarget
));
1255 separate_debug_file_debug_printf ("unable to open file");
1259 /* Verify symlinks were not the cause of filename_cmp name difference above.
1261 Some operating systems, e.g. Windows, do not provide a meaningful
1262 st_ino; they always set it to zero. (Windows does provide a
1263 meaningful st_dev.) Files accessed from gdbservers that do not
1264 support the vFile:fstat packet will also have st_ino set to zero.
1265 Do not indicate a duplicate library in either case. While there
1266 is no guarantee that a system that provides meaningful inode
1267 numbers will never set st_ino to zero, this is merely an
1268 optimization, so we do not need to worry about false negatives. */
1270 if (bfd_stat (abfd
.get (), &abfd_stat
) == 0
1271 && abfd_stat
.st_ino
!= 0
1272 && bfd_stat (parent_objfile
->obfd
.get (), &parent_stat
) == 0)
1274 if (abfd_stat
.st_dev
== parent_stat
.st_dev
1275 && abfd_stat
.st_ino
== parent_stat
.st_ino
)
1277 separate_debug_file_debug_printf ("same file as the objfile");
1280 verified_as_different
= 1;
1283 verified_as_different
= 0;
1285 file_crc_p
= gdb_bfd_crc (abfd
.get (), &file_crc
);
1289 separate_debug_file_debug_printf ("error computing CRC");
1293 if (crc
!= file_crc
)
1295 unsigned long parent_crc
;
1297 /* If the files could not be verified as different with
1298 bfd_stat then we need to calculate the parent's CRC
1299 to verify whether the files are different or not. */
1301 if (!verified_as_different
)
1303 if (!gdb_bfd_crc (parent_objfile
->obfd
.get (), &parent_crc
))
1305 separate_debug_file_debug_printf ("error computing CRC");
1310 if (verified_as_different
|| parent_crc
!= file_crc
)
1312 separate_debug_file_debug_printf
1313 ("the debug information found in \"%s\" does not match "
1314 "\"%s\" (CRC mismatch).", name
.c_str (),
1315 objfile_name (parent_objfile
));
1317 warnings
->warn (_("the debug information found in \"%ps\""
1318 " does not match \"%ps\" (CRC mismatch)."),
1319 styled_string (file_name_style
.style (),
1321 styled_string (file_name_style
.style (),
1322 objfile_name (parent_objfile
)));
1328 separate_debug_file_debug_printf ("found a match");
1333 std::string debug_file_directory
;
1335 show_debug_file_directory (struct ui_file
*file
, int from_tty
,
1336 struct cmd_list_element
*c
, const char *value
)
1339 _("The directory where separate debug "
1340 "symbols are searched for is \"%s\".\n"),
1344 #if ! defined (DEBUG_SUBDIRECTORY)
1345 #define DEBUG_SUBDIRECTORY ".debug"
1348 /* Find a separate debuginfo file for OBJFILE, using DIR as the directory
1349 where the original file resides (may not be the same as
1350 dirname(objfile->name) due to symlinks), and DEBUGLINK as the file we are
1351 looking for. CANON_DIR is the "realpath" form of DIR.
1352 DIR must contain a trailing '/'.
1353 Returns the path of the file with separate debug info, or an empty
1356 Any warnings generated as part of the lookup process are added to
1357 WARNINGS. If some other mechanism can be used to lookup the debug
1358 information then the warning will not be shown, however, if GDB fails to
1359 find suitable debug information using any approach, then any warnings
1363 find_separate_debug_file (const char *dir
,
1364 const char *canon_dir
,
1365 const char *debuglink
,
1366 unsigned long crc32
, struct objfile
*objfile
,
1367 deferred_warnings
*warnings
)
1369 SEPARATE_DEBUG_FILE_SCOPED_DEBUG_START_END
1370 ("looking for separate debug info (debug link) for %s",
1371 objfile_name (objfile
));
1373 /* First try in the same directory as the original file. */
1374 std::string debugfile
= path_join (dir
, debuglink
);
1376 if (separate_debug_file_exists (debugfile
, crc32
, objfile
, warnings
))
1379 /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
1380 debugfile
= path_join (dir
, DEBUG_SUBDIRECTORY
, debuglink
);
1382 if (separate_debug_file_exists (debugfile
, crc32
, objfile
, warnings
))
1385 /* Then try in the global debugfile directories.
1387 Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
1388 cause "/..." lookups. */
1390 bool target_prefix
= is_target_filename (dir
);
1391 const char *dir_notarget
1392 = target_prefix
? dir
+ strlen (TARGET_SYSROOT_PREFIX
) : dir
;
1393 const char *target_prefix_str
= target_prefix
? TARGET_SYSROOT_PREFIX
: "";
1394 std::vector
<gdb::unique_xmalloc_ptr
<char>> debugdir_vec
1395 = dirnames_to_char_ptr_vec (debug_file_directory
.c_str ());
1396 const char *sysroot_str
= gdb_sysroot
.c_str ();
1397 if (is_target_filename (sysroot_str
) && target_filesystem_is_local ())
1398 sysroot_str
+= strlen (TARGET_SYSROOT_PREFIX
);
1399 gdb::unique_xmalloc_ptr
<char> canon_sysroot
= gdb_realpath (sysroot_str
);
1401 /* MS-Windows/MS-DOS don't allow colons in file names; we must
1402 convert the drive letter into a one-letter directory, so that the
1403 file name resulting from splicing below will be valid.
1405 FIXME: The below only works when GDB runs on MS-Windows/MS-DOS.
1406 There are various remote-debugging scenarios where such a
1407 transformation of the drive letter might be required when GDB runs
1408 on a Posix host, see
1410 https://sourceware.org/ml/gdb-patches/2019-04/msg00605.html
1412 If some of those scenarios need to be supported, we will need to
1413 use a different condition for HAS_DRIVE_SPEC and a different macro
1414 instead of STRIP_DRIVE_SPEC, which work on Posix systems as well. */
1416 if (HAS_DRIVE_SPEC (dir_notarget
))
1418 drive
= dir_notarget
[0];
1419 dir_notarget
= STRIP_DRIVE_SPEC (dir_notarget
);
1422 for (const gdb::unique_xmalloc_ptr
<char> &debugdir
: debugdir_vec
)
1424 debugfile
= path_join (target_prefix_str
, debugdir
.get (),
1425 drive
.c_str (), dir_notarget
, debuglink
);
1427 if (separate_debug_file_exists (debugfile
, crc32
, objfile
, warnings
))
1430 const char *base_path
= NULL
;
1431 if (canon_dir
!= NULL
)
1433 if (canon_sysroot
.get () != NULL
)
1434 base_path
= child_path (canon_sysroot
.get (), canon_dir
);
1436 base_path
= child_path (gdb_sysroot
.c_str (), canon_dir
);
1438 if (base_path
!= NULL
)
1440 /* If the file is in the sysroot, try using its base path in
1441 the global debugfile directory. */
1442 debugfile
= path_join (target_prefix_str
, debugdir
.get (),
1443 base_path
, debuglink
);
1445 if (separate_debug_file_exists (debugfile
, crc32
, objfile
, warnings
))
1448 /* If the file is in the sysroot, try using its base path in
1449 the sysroot's global debugfile directory. */
1450 if (gdb_sysroot
!= TARGET_SYSROOT_PREFIX
)
1452 debugfile
= path_join (gdb_sysroot
.c_str (), debugdir
.get (),
1453 base_path
, debuglink
);
1455 if (separate_debug_file_exists (debugfile
, crc32
, objfile
,
1462 return std::string ();
1465 /* Modify PATH to contain only "[/]directory/" part of PATH.
1466 If there were no directory separators in PATH, PATH will be empty
1467 string on return. */
1470 terminate_after_last_dir_separator (char *path
)
1474 /* Strip off the final filename part, leaving the directory name,
1475 followed by a slash. The directory can be relative or absolute. */
1476 for (i
= strlen(path
) - 1; i
>= 0; i
--)
1477 if (IS_DIR_SEPARATOR (path
[i
]))
1480 /* If I is -1 then no directory is present there and DIR will be "". */
1487 find_separate_debug_file_by_debuglink
1488 (struct objfile
*objfile
, deferred_warnings
*warnings
)
1492 gdb::unique_xmalloc_ptr
<char> debuglink
1493 (bfd_get_debug_link_info (objfile
->obfd
.get (), &crc32
));
1495 if (debuglink
== NULL
)
1497 /* There's no separate debug info, hence there's no way we could
1498 load it => no warning. */
1499 return std::string ();
1502 std::string dir
= objfile_name (objfile
);
1503 terminate_after_last_dir_separator (&dir
[0]);
1504 gdb::unique_xmalloc_ptr
<char> canon_dir (lrealpath (dir
.c_str ()));
1506 std::string debugfile
1507 = find_separate_debug_file (dir
.c_str (), canon_dir
.get (),
1508 debuglink
.get (), crc32
, objfile
,
1511 if (debugfile
.empty ())
1513 /* For PR gdb/9538, try again with realpath (if different from the
1518 if (lstat (objfile_name (objfile
), &st_buf
) == 0
1519 && S_ISLNK (st_buf
.st_mode
))
1521 gdb::unique_xmalloc_ptr
<char> symlink_dir
1522 (lrealpath (objfile_name (objfile
)));
1523 if (symlink_dir
!= NULL
)
1525 terminate_after_last_dir_separator (symlink_dir
.get ());
1526 if (dir
!= symlink_dir
.get ())
1528 /* Different directory, so try using it. */
1529 debugfile
= find_separate_debug_file (symlink_dir
.get (),
1543 /* Make sure that OBJF_{READNOW,READNEVER} are not set
1547 validate_readnow_readnever (objfile_flags flags
)
1549 if ((flags
& OBJF_READNOW
) && (flags
& OBJF_READNEVER
))
1550 error (_("-readnow and -readnever cannot be used simultaneously"));
1553 /* See symfile.h. */
1556 symbol_file_command (const char *args
, int from_tty
)
1562 symbol_file_clear (from_tty
);
1566 objfile_flags flags
= OBJF_USERLOADED
;
1567 symfile_add_flags add_flags
= 0;
1569 bool stop_processing_options
= false;
1570 CORE_ADDR offset
= 0;
1575 add_flags
|= SYMFILE_VERBOSE
;
1577 gdb_argv
built_argv (args
);
1578 for (arg
= built_argv
[0], idx
= 0; arg
!= NULL
; arg
= built_argv
[++idx
])
1580 if (stop_processing_options
|| *arg
!= '-')
1585 error (_("Unrecognized argument \"%s\""), arg
);
1587 else if (strcmp (arg
, "-readnow") == 0)
1588 flags
|= OBJF_READNOW
;
1589 else if (strcmp (arg
, "-readnever") == 0)
1590 flags
|= OBJF_READNEVER
;
1591 else if (strcmp (arg
, "-o") == 0)
1593 arg
= built_argv
[++idx
];
1595 error (_("Missing argument to -o"));
1597 offset
= parse_and_eval_address (arg
);
1599 else if (strcmp (arg
, "--") == 0)
1600 stop_processing_options
= true;
1602 error (_("Unrecognized argument \"%s\""), arg
);
1606 error (_("no symbol file name was specified"));
1608 validate_readnow_readnever (flags
);
1610 /* Set SYMFILE_DEFER_BP_RESET because the proper displacement for a PIE
1611 (Position Independent Executable) main symbol file will only be
1612 computed by the solib_create_inferior_hook below. Without it,
1613 breakpoint_re_set would fail to insert the breakpoints with the zero
1615 add_flags
|= SYMFILE_DEFER_BP_RESET
;
1617 symbol_file_add_main_1 (name
, add_flags
, flags
, offset
);
1619 solib_create_inferior_hook (from_tty
);
1621 /* Now it's safe to re-add the breakpoints. */
1622 breakpoint_re_set ();
1624 /* Also, it's safe to re-add varobjs. */
1629 /* Lazily set the initial language. */
1632 set_initial_language_callback ()
1634 enum language lang
= main_language ();
1635 /* Make C the default language. */
1636 enum language default_lang
= language_c
;
1638 if (lang
== language_unknown
)
1640 const char *name
= main_name ();
1642 = lookup_symbol_in_language (name
, nullptr, SEARCH_FUNCTION_DOMAIN
,
1643 default_lang
, nullptr).symbol
;
1646 lang
= sym
->language ();
1649 if (lang
== language_unknown
)
1651 lang
= default_lang
;
1654 set_language (lang
);
1655 expected_language
= current_language
; /* Don't warn the user. */
1658 /* Set the initial language. */
1661 set_initial_language (void)
1663 if (language_mode
== language_mode_manual
)
1665 lazily_set_language (set_initial_language_callback
);
1668 /* Open the file specified by NAME and hand it off to BFD for
1669 preliminary analysis. Return a newly initialized bfd *, which
1670 includes a newly malloc'd` copy of NAME (tilde-expanded and made
1671 absolute). In case of trouble, error() is called. */
1674 symfile_bfd_open (const char *name
)
1678 gdb::unique_xmalloc_ptr
<char> absolute_name
;
1679 if (!is_target_filename (name
))
1681 gdb::unique_xmalloc_ptr
<char> expanded_name (tilde_expand (name
));
1683 /* Look down path for it, allocate 2nd new malloc'd copy. */
1684 desc
= openp (getenv ("PATH"),
1685 OPF_TRY_CWD_FIRST
| OPF_RETURN_REALPATH
,
1686 expanded_name
.get (), O_RDONLY
| O_BINARY
, &absolute_name
);
1687 #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
1690 char *exename
= (char *) alloca (strlen (expanded_name
.get ()) + 5);
1692 strcat (strcpy (exename
, expanded_name
.get ()), ".exe");
1693 desc
= openp (getenv ("PATH"),
1694 OPF_TRY_CWD_FIRST
| OPF_RETURN_REALPATH
,
1695 exename
, O_RDONLY
| O_BINARY
, &absolute_name
);
1699 perror_with_name (expanded_name
.get ());
1701 name
= absolute_name
.get ();
1704 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (name
, gnutarget
, desc
));
1705 if (sym_bfd
== NULL
)
1706 error (_("`%s': can't open to read symbols: %s."), name
,
1707 bfd_errmsg (bfd_get_error ()));
1709 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
1710 error (_("`%s': can't read symbols: %s."), name
,
1711 bfd_errmsg (bfd_get_error ()));
1716 /* See symfile.h. */
1719 symfile_bfd_open_no_error (const char *name
) noexcept
1723 return symfile_bfd_open (name
);
1725 catch (const gdb_exception_error
&err
)
1727 warning ("%s", err
.what ());
1733 /* Return the section index for SECTION_NAME on OBJFILE. Return -1 if
1734 the section was not found. */
1737 get_section_index (struct objfile
*objfile
, const char *section_name
)
1739 asection
*sect
= bfd_get_section_by_name (objfile
->obfd
.get (), section_name
);
1747 /* Link SF into the global symtab_fns list.
1748 FLAVOUR is the file format that SF handles.
1749 Called on startup by the _initialize routine in each object file format
1750 reader, to register information about each format the reader is prepared
1754 add_symtab_fns (enum bfd_flavour flavour
, const struct sym_fns
*sf
)
1756 symtab_fns
.emplace_back (flavour
, sf
);
1759 /* Initialize OBJFILE to read symbols from its associated BFD. It
1760 either returns or calls error(). The result is an initialized
1761 struct sym_fns in the objfile structure, that contains cached
1762 information about the symbol file. */
1764 static const struct sym_fns
*
1765 find_sym_fns (bfd
*abfd
)
1767 enum bfd_flavour our_flavour
= bfd_get_flavour (abfd
);
1769 if (our_flavour
== bfd_target_srec_flavour
1770 || our_flavour
== bfd_target_ihex_flavour
1771 || our_flavour
== bfd_target_tekhex_flavour
)
1772 return NULL
; /* No symbols. */
1774 for (const registered_sym_fns
&rsf
: symtab_fns
)
1775 if (our_flavour
== rsf
.sym_flavour
)
1778 error (_("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown."),
1779 bfd_get_target (abfd
));
1783 /* This function runs the load command of our current target. */
1786 load_command (const char *arg
, int from_tty
)
1790 /* The user might be reloading because the binary has changed. Take
1791 this opportunity to check. */
1792 reopen_exec_file ();
1793 reread_symbols (from_tty
);
1798 const char *parg
, *prev
;
1800 arg
= current_program_space
->exec_filename ();
1802 no_executable_specified_error ();
1804 /* We may need to quote this string so buildargv can pull it
1807 while ((parg
= strpbrk (parg
, "\\\"'\t ")))
1809 temp
.append (prev
, parg
- prev
);
1811 temp
.push_back ('\\');
1813 /* If we have not copied anything yet, then we didn't see a
1814 character to quote, and we can just leave ARG unchanged. */
1818 arg
= temp
.c_str ();
1822 target_load (arg
, from_tty
);
1824 /* After re-loading the executable, we don't really know which
1825 overlays are mapped any more. */
1826 overlay_cache_invalid
= 1;
1829 /* This version of "load" should be usable for any target. Currently
1830 it is just used for remote targets, not inftarg.c or core files,
1831 on the theory that only in that case is it useful.
1833 Avoiding xmodem and the like seems like a win (a) because we don't have
1834 to worry about finding it, and (b) On VMS, fork() is very slow and so
1835 we don't want to run a subprocess. On the other hand, I'm not sure how
1836 performance compares. */
1838 static int validate_download
= 0;
1840 /* Opaque data for load_progress. */
1841 struct load_progress_data
1843 /* Cumulative data. */
1844 unsigned long write_count
= 0;
1845 unsigned long data_count
= 0;
1846 bfd_size_type total_size
= 0;
1849 /* Opaque data for load_progress for a single section. */
1850 struct load_progress_section_data
1852 load_progress_section_data (load_progress_data
*cumulative_
,
1853 const char *section_name_
, ULONGEST section_size_
,
1854 CORE_ADDR lma_
, gdb_byte
*buffer_
)
1855 : cumulative (cumulative_
), section_name (section_name_
),
1856 section_size (section_size_
), lma (lma_
), buffer (buffer_
)
1859 struct load_progress_data
*cumulative
;
1861 /* Per-section data. */
1862 const char *section_name
;
1863 ULONGEST section_sent
= 0;
1864 ULONGEST section_size
;
1869 /* Opaque data for load_section_callback. */
1870 struct load_section_data
1872 load_section_data (load_progress_data
*progress_data_
)
1873 : progress_data (progress_data_
)
1876 ~load_section_data ()
1878 for (auto &&request
: requests
)
1880 xfree (request
.data
);
1881 delete ((load_progress_section_data
*) request
.baton
);
1885 CORE_ADDR load_offset
= 0;
1886 struct load_progress_data
*progress_data
;
1887 std::vector
<struct memory_write_request
> requests
;
1890 /* Target write callback routine for progress reporting. */
1893 load_progress (ULONGEST bytes
, void *untyped_arg
)
1895 struct load_progress_section_data
*args
1896 = (struct load_progress_section_data
*) untyped_arg
;
1897 struct load_progress_data
*totals
;
1900 /* Writing padding data. No easy way to get at the cumulative
1901 stats, so just ignore this. */
1904 totals
= args
->cumulative
;
1906 if (bytes
== 0 && args
->section_sent
== 0)
1908 /* The write is just starting. Let the user know we've started
1910 current_uiout
->message ("Loading section %s, size %s lma %s\n",
1912 hex_string (args
->section_size
),
1913 paddress (current_inferior ()->arch (),
1918 if (validate_download
)
1920 /* Broken memories and broken monitors manifest themselves here
1921 when bring new computers to life. This doubles already slow
1923 /* NOTE: cagney/1999-10-18: A more efficient implementation
1924 might add a verify_memory() method to the target vector and
1925 then use that. remote.c could implement that method using
1926 the ``qCRC'' packet. */
1927 gdb::byte_vector
check (bytes
);
1929 if (target_read_memory (args
->lma
, check
.data (), bytes
) != 0)
1930 error (_("Download verify read failed at %s"),
1931 paddress (current_inferior ()->arch (), args
->lma
));
1932 if (memcmp (args
->buffer
, check
.data (), bytes
) != 0)
1933 error (_("Download verify compare failed at %s"),
1934 paddress (current_inferior ()->arch (), args
->lma
));
1936 totals
->data_count
+= bytes
;
1938 args
->buffer
+= bytes
;
1939 totals
->write_count
+= 1;
1940 args
->section_sent
+= bytes
;
1941 if (check_quit_flag ()
1942 || (deprecated_ui_load_progress_hook
!= NULL
1943 && deprecated_ui_load_progress_hook (args
->section_name
,
1944 args
->section_sent
)))
1945 error (_("Canceled the download"));
1947 if (deprecated_show_load_progress
!= NULL
)
1948 deprecated_show_load_progress (args
->section_name
,
1952 totals
->total_size
);
1955 /* Service function for generic_load. */
1958 load_one_section (bfd
*abfd
, asection
*asec
,
1959 struct load_section_data
*args
)
1961 bfd_size_type size
= bfd_section_size (asec
);
1962 const char *sect_name
= bfd_section_name (asec
);
1964 if ((bfd_section_flags (asec
) & SEC_LOAD
) == 0)
1970 ULONGEST begin
= bfd_section_lma (asec
) + args
->load_offset
;
1971 ULONGEST end
= begin
+ size
;
1972 gdb_byte
*buffer
= (gdb_byte
*) xmalloc (size
);
1973 bfd_get_section_contents (abfd
, asec
, buffer
, 0, size
);
1975 load_progress_section_data
*section_data
1976 = new load_progress_section_data (args
->progress_data
, sect_name
, size
,
1979 args
->requests
.emplace_back (begin
, end
, buffer
, section_data
);
1982 static void print_transfer_performance (struct ui_file
*stream
,
1983 unsigned long data_count
,
1984 unsigned long write_count
,
1985 std::chrono::steady_clock::duration d
);
1987 /* See symfile.h. */
1990 generic_load (const char *args
, int from_tty
)
1992 struct load_progress_data total_progress
;
1993 struct load_section_data
cbdata (&total_progress
);
1994 struct ui_out
*uiout
= current_uiout
;
1997 error_no_arg (_("file to load"));
1999 gdb_argv
argv (args
);
2001 gdb::unique_xmalloc_ptr
<char> filename (tilde_expand (argv
[0]));
2003 if (argv
[1] != NULL
)
2007 cbdata
.load_offset
= strtoulst (argv
[1], &endptr
, 0);
2009 /* If the last word was not a valid number then
2010 treat it as a file name with spaces in. */
2011 if (argv
[1] == endptr
)
2012 error (_("Invalid download offset:%s."), argv
[1]);
2014 if (argv
[2] != NULL
)
2015 error (_("Too many parameters."));
2018 /* Open the file for loading. */
2019 gdb_bfd_ref_ptr
loadfile_bfd (gdb_bfd_open (filename
.get (), gnutarget
));
2020 if (loadfile_bfd
== NULL
)
2021 perror_with_name (filename
.get ());
2023 if (!bfd_check_format (loadfile_bfd
.get (), bfd_object
))
2025 error (_("\"%s\" is not an object file: %s"), filename
.get (),
2026 bfd_errmsg (bfd_get_error ()));
2029 for (asection
*asec
: gdb_bfd_sections (loadfile_bfd
))
2030 total_progress
.total_size
+= bfd_section_size (asec
);
2032 for (asection
*asec
: gdb_bfd_sections (loadfile_bfd
))
2033 load_one_section (loadfile_bfd
.get (), asec
, &cbdata
);
2035 using namespace std::chrono
;
2037 steady_clock::time_point start_time
= steady_clock::now ();
2039 if (target_write_memory_blocks (cbdata
.requests
, flash_discard
,
2040 load_progress
) != 0)
2041 error (_("Load failed"));
2043 steady_clock::time_point end_time
= steady_clock::now ();
2045 CORE_ADDR entry
= bfd_get_start_address (loadfile_bfd
.get ());
2046 entry
= gdbarch_addr_bits_remove (current_inferior ()->arch (), entry
);
2047 uiout
->text ("Start address ");
2048 uiout
->field_core_addr ("address", current_inferior ()->arch (), entry
);
2049 uiout
->text (", load size ");
2050 uiout
->field_unsigned ("load-size", total_progress
.data_count
);
2052 regcache_write_pc (get_thread_regcache (inferior_thread ()), entry
);
2054 /* Reset breakpoints, now that we have changed the load image. For
2055 instance, breakpoints may have been set (or reset, by
2056 post_create_inferior) while connected to the target but before we
2057 loaded the program. In that case, the prologue analyzer could
2058 have read instructions from the target to find the right
2059 breakpoint locations. Loading has changed the contents of that
2062 breakpoint_re_set ();
2064 print_transfer_performance (gdb_stdout
, total_progress
.data_count
,
2065 total_progress
.write_count
,
2066 end_time
- start_time
);
2069 /* Report on STREAM the performance of a memory transfer operation,
2070 such as 'load'. DATA_COUNT is the number of bytes transferred.
2071 WRITE_COUNT is the number of separate write operations, or 0, if
2072 that information is not available. TIME is how long the operation
2076 print_transfer_performance (struct ui_file
*stream
,
2077 unsigned long data_count
,
2078 unsigned long write_count
,
2079 std::chrono::steady_clock::duration time
)
2081 using namespace std::chrono
;
2082 struct ui_out
*uiout
= current_uiout
;
2084 milliseconds ms
= duration_cast
<milliseconds
> (time
);
2086 uiout
->text ("Transfer rate: ");
2087 if (ms
.count () > 0)
2089 unsigned long rate
= ((ULONGEST
) data_count
* 1000) / ms
.count ();
2091 if (uiout
->is_mi_like_p ())
2093 uiout
->field_unsigned ("transfer-rate", rate
* 8);
2094 uiout
->text (" bits/sec");
2096 else if (rate
< 1024)
2098 uiout
->field_unsigned ("transfer-rate", rate
);
2099 uiout
->text (" bytes/sec");
2103 uiout
->field_unsigned ("transfer-rate", rate
/ 1024);
2104 uiout
->text (" KB/sec");
2109 uiout
->field_unsigned ("transferred-bits", (data_count
* 8));
2110 uiout
->text (" bits in <1 sec");
2112 if (write_count
> 0)
2115 uiout
->field_unsigned ("write-rate", data_count
/ write_count
);
2116 uiout
->text (" bytes/write");
2118 uiout
->text (".\n");
2121 /* Add an OFFSET to the start address of each section in OBJF, except
2122 sections that were specified in ADDRS. */
2125 set_objfile_default_section_offset (struct objfile
*objf
,
2126 const section_addr_info
&addrs
,
2129 /* Add OFFSET to all sections by default. */
2130 section_offsets
offsets (objf
->section_offsets
.size (), offset
);
2132 /* Create sorted lists of all sections in ADDRS as well as all
2133 sections in OBJF. */
2135 std::vector
<const struct other_sections
*> addrs_sorted
2136 = addrs_section_sort (addrs
);
2138 section_addr_info objf_addrs
2139 = build_section_addr_info_from_objfile (objf
);
2140 std::vector
<const struct other_sections
*> objf_addrs_sorted
2141 = addrs_section_sort (objf_addrs
);
2143 /* Walk the BFD section list, and if a matching section is found in
2144 ADDRS_SORTED_LIST, set its offset to zero to keep its address
2147 Note that both lists may contain multiple sections with the same
2148 name, and then the sections from ADDRS are matched in BFD order
2149 (thanks to sectindex). */
2151 std::vector
<const struct other_sections
*>::iterator addrs_sorted_iter
2152 = addrs_sorted
.begin ();
2153 for (const other_sections
*objf_sect
: objf_addrs_sorted
)
2155 const char *objf_name
= addr_section_name (objf_sect
->name
.c_str ());
2158 while (cmp
< 0 && addrs_sorted_iter
!= addrs_sorted
.end ())
2160 const struct other_sections
*sect
= *addrs_sorted_iter
;
2161 const char *sect_name
= addr_section_name (sect
->name
.c_str ());
2162 cmp
= strcmp (sect_name
, objf_name
);
2164 ++addrs_sorted_iter
;
2168 offsets
[objf_sect
->sectindex
] = 0;
2171 /* Apply the new section offsets. */
2172 objfile_relocate (objf
, offsets
);
2175 /* This function allows the addition of incrementally linked object files.
2176 It does not modify any state in the target, only in the debugger. */
2179 add_symbol_file_command (const char *args
, int from_tty
)
2181 struct gdbarch
*gdbarch
= get_current_arch ();
2182 gdb::unique_xmalloc_ptr
<char> filename
;
2185 struct objfile
*objf
;
2186 objfile_flags flags
= OBJF_USERLOADED
| OBJF_SHARED
;
2187 symfile_add_flags add_flags
= 0;
2190 add_flags
|= SYMFILE_VERBOSE
;
2198 std::vector
<sect_opt
> sect_opts
= { { ".text", NULL
} };
2199 bool stop_processing_options
= false;
2200 CORE_ADDR offset
= 0;
2205 error (_("add-symbol-file takes a file name and an address"));
2207 bool seen_addr
= false;
2208 bool seen_offset
= false;
2209 gdb_argv
argv (args
);
2211 for (arg
= argv
[0], argcnt
= 0; arg
!= NULL
; arg
= argv
[++argcnt
])
2213 if (stop_processing_options
|| *arg
!= '-')
2215 if (filename
== NULL
)
2217 /* First non-option argument is always the filename. */
2218 filename
.reset (tilde_expand (arg
));
2220 else if (!seen_addr
)
2222 /* The second non-option argument is always the text
2223 address at which to load the program. */
2224 sect_opts
[0].value
= arg
;
2228 error (_("Unrecognized argument \"%s\""), arg
);
2230 else if (strcmp (arg
, "-readnow") == 0)
2231 flags
|= OBJF_READNOW
;
2232 else if (strcmp (arg
, "-readnever") == 0)
2233 flags
|= OBJF_READNEVER
;
2234 else if (strcmp (arg
, "-s") == 0)
2236 if (argv
[argcnt
+ 1] == NULL
)
2237 error (_("Missing section name after \"-s\""));
2238 else if (argv
[argcnt
+ 2] == NULL
)
2239 error (_("Missing section address after \"-s\""));
2241 sect_opt sect
= { argv
[argcnt
+ 1], argv
[argcnt
+ 2] };
2243 sect_opts
.push_back (sect
);
2246 else if (strcmp (arg
, "-o") == 0)
2248 arg
= argv
[++argcnt
];
2250 error (_("Missing argument to -o"));
2252 offset
= parse_and_eval_address (arg
);
2255 else if (strcmp (arg
, "--") == 0)
2256 stop_processing_options
= true;
2258 error (_("Unrecognized argument \"%s\""), arg
);
2261 if (filename
== NULL
)
2262 error (_("You must provide a filename to be loaded."));
2264 validate_readnow_readnever (flags
);
2266 /* Print the prompt for the query below. And save the arguments into
2267 a sect_addr_info structure to be passed around to other
2268 functions. We have to split this up into separate print
2269 statements because hex_string returns a local static
2272 gdb_printf (_("add symbol table from file \"%ps\""),
2273 styled_string (file_name_style
.style (), filename
.get ()));
2274 section_addr_info section_addrs
;
2275 std::vector
<sect_opt
>::const_iterator it
= sect_opts
.begin ();
2278 for (; it
!= sect_opts
.end (); ++it
)
2281 const char *val
= it
->value
;
2282 const char *sec
= it
->name
;
2284 if (section_addrs
.empty ())
2285 gdb_printf (_(" at\n"));
2286 addr
= parse_and_eval_address (val
);
2288 /* Here we store the section offsets in the order they were
2289 entered on the command line. Every array element is
2290 assigned an ascending section index to preserve the above
2291 order over an unstable sorting algorithm. This dummy
2292 index is not used for any other purpose.
2294 section_addrs
.emplace_back (addr
, sec
, section_addrs
.size ());
2295 gdb_printf ("\t%s_addr = %s\n", sec
,
2296 paddress (gdbarch
, addr
));
2298 /* The object's sections are initialized when a
2299 call is made to build_objfile_section_table (objfile).
2300 This happens in reread_symbols.
2301 At this point, we don't know what file type this is,
2302 so we can't determine what section names are valid. */
2305 gdb_printf (_("%s offset by %s\n"),
2306 (section_addrs
.empty ()
2307 ? _(" with all sections")
2308 : _("with other sections")),
2309 paddress (gdbarch
, offset
));
2310 else if (section_addrs
.empty ())
2313 if (from_tty
&& (!query ("%s", "")))
2314 error (_("Not confirmed."));
2316 objf
= symbol_file_add (filename
.get (), add_flags
, §ion_addrs
,
2318 if (!objfile_has_symbols (objf
) && objf
->per_bfd
->minimal_symbol_count
<= 0)
2319 warning (_("newly-added symbol file \"%ps\" does not provide any symbols"),
2320 styled_string (file_name_style
.style (), filename
.get ()));
2323 set_objfile_default_section_offset (objf
, section_addrs
, offset
);
2325 current_program_space
->add_target_sections (objf
);
2327 /* Getting new symbols may change our opinion about what is
2329 reinit_frame_cache ();
2333 /* Option support for 'remove-symbol-file' command. */
2335 struct remove_symbol_file_options
2337 /* True when the '-a' flag was passed. */
2338 bool address_flag
= false;
2341 using remove_symbol_file_options_opt_def
2342 = gdb::option::flag_option_def
<remove_symbol_file_options
>;
2344 static const gdb::option::option_def remove_symbol_file_opt_defs
[] = {
2345 remove_symbol_file_options_opt_def
{
2347 [] (remove_symbol_file_options
*opt
) { return &opt
->address_flag
; },
2348 N_("Select a symbol file containing ADDRESS.")
2352 static inline gdb::option::option_def_group
2353 make_remove_symbol_file_def_group (remove_symbol_file_options
*opts
)
2355 return {{remove_symbol_file_opt_defs
}, opts
};
2358 /* Completion function for 'remove-symbol-file' command. */
2361 remove_symbol_file_command_completer (struct cmd_list_element
*ignore
,
2362 completion_tracker
&tracker
,
2363 const char *text
, const char * /* word */)
2365 /* Unlike many command completion functions we do gather the option
2366 values here. How we complete the rest of the command depends on
2367 whether the '-a' flag has been given or not. */
2368 remove_symbol_file_options opts
;
2369 auto grp
= make_remove_symbol_file_def_group (&opts
);
2370 if (gdb::option::complete_options
2371 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, grp
))
2374 /* Complete the rest of the command line as either a filename or an
2375 expression (which will evaluate to an address) if the '-a' flag was
2377 if (!opts
.address_flag
)
2380 = advance_to_filename_maybe_quoted_complete_word_point (tracker
, text
);
2381 filename_maybe_quoted_completer (ignore
, tracker
, text
, word
);
2386 = advance_to_expression_complete_word_point (tracker
, text
);
2387 symbol_completer (ignore
, tracker
, text
, word
);
2391 /* This function removes a symbol file that was added via add-symbol-file. */
2394 remove_symbol_file_command (const char *args
, int from_tty
)
2398 remove_symbol_file_options opts
;
2399 auto grp
= make_remove_symbol_file_def_group (&opts
);
2400 gdb::option::process_options
2401 (&args
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, grp
);
2403 struct objfile
*objf
= nullptr;
2405 if (opts
.address_flag
)
2407 if (args
== nullptr || *args
== '\0')
2408 error (_("remove-symbol-file: no address provided"));
2410 CORE_ADDR addr
= parse_and_eval_address (args
);
2412 for (objfile
*objfile
: current_program_space
->objfiles ())
2414 if ((objfile
->flags
& OBJF_USERLOADED
) != 0
2415 && (objfile
->flags
& OBJF_SHARED
) != 0
2416 && objfile
->pspace () == current_program_space
2417 && is_addr_in_objfile (addr
, objfile
))
2426 std::string filename
= extract_single_filename_arg (args
);
2427 if (filename
.empty ())
2428 error (_("remove-symbol-file: no symbol file provided"));
2430 for (objfile
*objfile
: current_program_space
->objfiles ())
2432 if ((objfile
->flags
& OBJF_USERLOADED
) != 0
2433 && (objfile
->flags
& OBJF_SHARED
) != 0
2434 && objfile
->pspace () == current_program_space
2435 && filename_cmp (filename
.c_str (), objfile_name (objfile
)) == 0)
2444 error (_("No symbol file found"));
2447 && !query (_("Remove symbol table from file \"%s\"? "),
2448 objfile_name (objf
)))
2449 error (_("Not confirmed."));
2452 clear_symtab_users (0);
2455 /* Re-read symbols if a symbol-file has changed. */
2458 reread_symbols (int from_tty
)
2460 std::vector
<struct objfile
*> new_objfiles
;
2462 /* Check to see if the executable has changed, and if so reopen it. The
2463 executable might not be in the list of objfiles (if the user set
2464 different values for 'exec-file' and 'symbol-file'), and even if it
2465 is, then we use a separate timestamp (within the program_space) to
2466 indicate when the executable was last reloaded. */
2467 reopen_exec_file ();
2469 for (objfile
*objfile
: current_program_space
->objfiles ())
2471 if (objfile
->obfd
.get () == NULL
)
2474 /* Separate debug objfiles are handled in the main objfile. */
2475 if (objfile
->separate_debug_objfile_backlink
)
2478 /* When a in-memory BFD is initially created, it's mtime (as
2479 returned by bfd_get_mtime) is the creation time of the BFD.
2480 However, we call bfd_stat here as we want to see if the
2481 underlying file has changed, and in this case an in-memory BFD
2482 will return an st_mtime of zero, so it appears that the in-memory
2483 file has changed, which isn't what we want here -- this code is
2484 about reloading BFDs that changed on disk.
2486 Just skip any in-memory BFD. */
2487 if (objfile
->obfd
.get ()->flags
& BFD_IN_MEMORY
)
2490 struct stat new_statbuf
;
2491 int res
= bfd_stat (objfile
->obfd
.get (), &new_statbuf
);
2494 /* If this object is from an archive (what you usually create
2495 with `ar', often called a `static library' on most systems,
2496 though a `shared library' on AIX is also an archive), then you
2497 should stat on the archive name, not member name. */
2498 const char *filename
;
2499 if (objfile
->obfd
->my_archive
)
2500 filename
= bfd_get_filename (objfile
->obfd
->my_archive
);
2502 filename
= objfile_name (objfile
);
2504 warning (_("`%ps' has disappeared; keeping its symbols."),
2505 styled_string (file_name_style
.style (), filename
));
2508 time_t new_modtime
= new_statbuf
.st_mtime
;
2509 if (new_modtime
!= objfile
->mtime
)
2511 gdb_printf (_("`%ps' has changed; re-reading symbols.\n"),
2512 styled_string (file_name_style
.style (),
2513 objfile_name (objfile
)));
2515 /* There are various functions like symbol_file_add,
2516 symfile_bfd_open, syms_from_objfile, etc., which might
2517 appear to do what we want. But they have various other
2518 effects which we *don't* want. So we just do stuff
2519 ourselves. We don't worry about mapped files (for one thing,
2520 any mapped file will be out of date). */
2522 /* If we get an error, blow away this objfile (not sure if
2523 that is the correct response for things like shared
2525 objfile_up
objfile_holder (objfile
);
2527 /* We need to do this whenever any symbols go away. */
2528 clear_symtab_users_cleanup
defer_clear_users (0);
2530 /* Keep the calls order approx. the same as in free_objfile. */
2532 /* Free the separate debug objfiles. It will be
2533 automatically recreated by sym_read. */
2534 free_objfile_separate_debug (objfile
);
2536 /* Clear the stale source cache. */
2537 forget_cached_source_info ();
2539 /* Remove any references to this objfile in the global
2541 preserve_values (objfile
);
2543 /* Nuke all the state that we will re-read. Much of the following
2544 code which sets things to NULL really is necessary to tell
2545 other parts of GDB that there is nothing currently there.
2547 Try to keep the freeing order compatible with free_objfile. */
2549 if (objfile
->sf
!= NULL
)
2551 (*objfile
->sf
->sym_finish
) (objfile
);
2554 objfile
->registry_fields
.clear_registry ();
2556 /* Clean up any state BFD has sitting around. */
2558 gdb_bfd_ref_ptr obfd
= objfile
->obfd
;
2559 const char *obfd_filename
;
2561 obfd_filename
= bfd_get_filename (objfile
->obfd
.get ());
2562 /* Open the new BFD before freeing the old one, so that
2563 the filename remains live. */
2564 gdb_bfd_ref_ptr
temp (gdb_bfd_open (obfd_filename
, gnutarget
));
2565 objfile
->obfd
= std::move (temp
);
2566 if (objfile
->obfd
== NULL
)
2567 error (_("Can't open %s to read symbols."), obfd_filename
);
2570 std::string original_name
= objfile
->original_name
;
2572 /* bfd_openr sets cacheable to true, which is what we want. */
2573 if (!bfd_check_format (objfile
->obfd
.get (), bfd_object
))
2574 error (_("Can't read symbols from %s: %s."), objfile_name (objfile
),
2575 bfd_errmsg (bfd_get_error ()));
2577 /* NB: after this call to obstack_free, objfiles_changed
2578 will need to be called (see discussion below). */
2579 obstack_free (&objfile
->objfile_obstack
, 0);
2580 objfile
->sections_start
= NULL
;
2581 objfile
->section_offsets
.clear ();
2582 objfile
->sect_index_bss
= -1;
2583 objfile
->sect_index_data
= -1;
2584 objfile
->sect_index_rodata
= -1;
2585 objfile
->sect_index_text
= -1;
2586 objfile
->compunit_symtabs
= NULL
;
2587 objfile
->template_symbols
= NULL
;
2588 objfile
->static_links
.reset (nullptr);
2590 /* obstack_init also initializes the obstack so it is
2591 empty. We could use obstack_specify_allocation but
2592 gdb_obstack.h specifies the alloc/dealloc functions. */
2593 obstack_init (&objfile
->objfile_obstack
);
2595 /* set_objfile_per_bfd potentially allocates the per-bfd
2596 data on the objfile's obstack (if sharing data across
2597 multiple users is not possible), so it's important to
2598 do it *after* the obstack has been initialized. */
2599 set_objfile_per_bfd (objfile
);
2601 objfile
->original_name
2602 = obstack_strdup (&objfile
->objfile_obstack
, original_name
);
2604 /* Reset the sym_fns pointer. The ELF reader can change it
2605 based on whether .gdb_index is present, and we need it to
2606 start over. PR symtab/15885 */
2607 objfile_set_sym_fns (objfile
, find_sym_fns (objfile
->obfd
.get ()));
2608 objfile
->qf
.clear ();
2610 build_objfile_section_table (objfile
);
2612 /* What the hell is sym_new_init for, anyway? The concept of
2613 distinguishing between the main file and additional files
2614 in this way seems rather dubious. */
2615 if (objfile
== current_program_space
->symfile_object_file
)
2617 (*objfile
->sf
->sym_new_init
) (objfile
);
2620 (*objfile
->sf
->sym_init
) (objfile
);
2621 clear_complaints ();
2623 /* We are about to read new symbols and potentially also
2624 DWARF information. Some targets may want to pass addresses
2625 read from DWARF DIE's through an adjustment function before
2626 saving them, like MIPS, which may call into
2627 "find_pc_section". When called, that function will make
2628 use of per-objfile program space data.
2630 Since we discarded our section information above, we have
2631 dangling pointers in the per-objfile program space data
2632 structure. Force GDB to update the section mapping
2633 information by letting it know the objfile has changed,
2634 making the dangling pointers point to correct data
2637 objfiles_changed (current_program_space
);
2639 /* Recompute section offsets and section indices. */
2640 objfile
->sf
->sym_offsets (objfile
, {});
2642 read_symbols (objfile
, 0);
2644 if ((objfile
->flags
& OBJF_READNOW
))
2646 const int mainline
= objfile
->flags
& OBJF_MAINLINE
;
2647 const int should_print
= (print_symbol_loading_p (from_tty
, mainline
, 1)
2648 && readnow_symbol_files
);
2650 gdb_printf (_("Expanding full symbols from %ps...\n"),
2651 styled_string (file_name_style
.style (),
2652 objfile_name (objfile
)));
2654 objfile
->expand_all_symtabs ();
2657 if (!objfile_has_symbols (objfile
))
2659 gdb_stdout
->wrap_here (0);
2660 gdb_printf (_("(no debugging symbols found)\n"));
2661 gdb_stdout
->wrap_here (0);
2664 /* We're done reading the symbol file; finish off complaints. */
2665 clear_complaints ();
2667 /* Getting new symbols may change our opinion about what is
2670 reinit_frame_cache ();
2672 /* Discard cleanups as symbol reading was successful. */
2673 objfile_holder
.release ();
2674 defer_clear_users
.release ();
2676 /* If the mtime has changed between the time we set new_modtime
2677 and now, we *want* this to be out of date, so don't call stat
2679 objfile
->mtime
= new_modtime
;
2680 init_entry_point_info (objfile
);
2682 new_objfiles
.push_back (objfile
);
2686 if (!new_objfiles
.empty ())
2688 clear_symtab_users (0);
2690 /* The registry for each objfile was cleared and
2691 gdb::observers::new_objfile.notify (NULL) has been called by
2692 clear_symtab_users above. Notify the new files now. */
2693 for (auto iter
: new_objfiles
)
2694 gdb::observers::new_objfile
.notify (iter
);
2699 struct filename_language
2701 filename_language (const std::string
&ext_
, enum language lang_
)
2702 : ext (ext_
), lang (lang_
)
2709 static std::vector
<filename_language
> filename_language_table
;
2711 /* See symfile.h. */
2714 add_filename_language (const char *ext
, enum language lang
)
2716 gdb_assert (ext
!= nullptr);
2717 filename_language_table
.emplace_back (ext
, lang
);
2720 static std::string ext_args
;
2722 show_ext_args (struct ui_file
*file
, int from_tty
,
2723 struct cmd_list_element
*c
, const char *value
)
2726 _("Mapping between filename extension "
2727 "and source language is \"%s\".\n"),
2732 set_ext_lang_command (const char *args
,
2733 int from_tty
, struct cmd_list_element
*e
)
2735 const char *begin
= ext_args
.c_str ();
2736 const char *end
= ext_args
.c_str ();
2738 /* First arg is filename extension, starting with '.' */
2740 error (_("'%s': Filename extension must begin with '.'"), ext_args
.c_str ());
2742 /* Find end of first arg. */
2743 while (*end
!= '\0' && !isspace (*end
))
2747 error (_("'%s': two arguments required -- "
2748 "filename extension and language"),
2751 /* Extract first arg, the extension. */
2752 std::string extension
= ext_args
.substr (0, end
- begin
);
2754 /* Find beginning of second arg, which should be a source language. */
2755 begin
= skip_spaces (end
);
2758 error (_("'%s': two arguments required -- "
2759 "filename extension and language"),
2762 /* Lookup the language from among those we know. */
2763 language lang
= language_enum (begin
);
2765 auto it
= filename_language_table
.begin ();
2766 /* Now lookup the filename extension: do we already know it? */
2767 for (; it
!= filename_language_table
.end (); it
++)
2769 if (it
->ext
== extension
)
2773 if (it
== filename_language_table
.end ())
2775 /* New file extension. */
2776 add_filename_language (extension
.data (), lang
);
2780 /* Redefining a previously known filename extension. */
2783 /* query ("Really make files of type %s '%s'?", */
2784 /* ext_args, language_str (lang)); */
2791 info_ext_lang_command (const char *args
, int from_tty
)
2793 gdb_printf (_("Filename extensions and the languages they represent:"));
2794 gdb_printf ("\n\n");
2795 for (const filename_language
&entry
: filename_language_table
)
2796 gdb_printf ("\t%s\t- %s\n", entry
.ext
.c_str (),
2797 language_str (entry
.lang
));
2801 deduce_language_from_filename (const char *filename
)
2805 if (filename
!= NULL
)
2806 if ((cp
= strrchr (filename
, '.')) != NULL
)
2808 for (const filename_language
&entry
: filename_language_table
)
2809 if (entry
.ext
== cp
)
2813 return language_unknown
;
2816 /* Allocate and initialize a new symbol table.
2817 CUST is from the result of allocate_compunit_symtab. */
2820 allocate_symtab (struct compunit_symtab
*cust
, const char *filename
,
2821 const char *filename_for_id
)
2823 struct objfile
*objfile
= cust
->objfile ();
2824 struct symtab
*symtab
2825 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symtab
);
2827 symtab
->filename
= objfile
->intern (filename
);
2828 symtab
->filename_for_id
= objfile
->intern (filename_for_id
);
2829 symtab
->set_language (deduce_language_from_filename (filename
));
2831 /* This can be very verbose with lots of headers.
2832 Only print at higher debug levels. */
2833 if (symtab_create_debug
>= 2)
2835 /* Be a bit clever with debugging messages, and don't print objfile
2836 every time, only when it changes. */
2837 static std::string last_objfile_name
;
2838 const char *this_objfile_name
= objfile_name (objfile
);
2840 if (last_objfile_name
.empty () || last_objfile_name
!= this_objfile_name
)
2842 last_objfile_name
= this_objfile_name
;
2844 symtab_create_debug_printf_v
2845 ("creating one or more symtabs for objfile %s", this_objfile_name
);
2848 symtab_create_debug_printf_v ("created symtab %s for module %s",
2849 host_address_to_string (symtab
), filename
);
2852 /* Add it to CUST's list of symtabs. */
2853 cust
->add_filetab (symtab
);
2855 /* Backlink to the containing compunit symtab. */
2856 symtab
->set_compunit (cust
);
2861 /* Allocate and initialize a new compunit.
2862 NAME is the name of the main source file, if there is one, or some
2863 descriptive text if there are no source files. */
2865 struct compunit_symtab
*
2866 allocate_compunit_symtab (struct objfile
*objfile
, const char *name
)
2868 struct compunit_symtab
*cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2869 struct compunit_symtab
);
2870 const char *saved_name
;
2872 cu
->set_objfile (objfile
);
2874 /* The name we record here is only for display/debugging purposes.
2875 Just save the basename to avoid path issues (too long for display,
2876 relative vs absolute, etc.). */
2877 saved_name
= lbasename (name
);
2878 cu
->name
= obstack_strdup (&objfile
->objfile_obstack
, saved_name
);
2880 cu
->set_debugformat ("unknown");
2882 symtab_create_debug_printf_v ("created compunit symtab %s for %s",
2883 host_address_to_string (cu
),
2889 /* Hook CU to the objfile it comes from. */
2892 add_compunit_symtab_to_objfile (struct compunit_symtab
*cu
)
2894 cu
->next
= cu
->objfile ()->compunit_symtabs
;
2895 cu
->objfile ()->compunit_symtabs
= cu
;
2899 /* Reset all data structures in gdb which may contain references to
2900 symbol table data. */
2903 clear_symtab_users (symfile_add_flags add_flags
)
2905 /* Someday, we should do better than this, by only blowing away
2906 the things that really need to be blown. */
2908 /* Clear the "current" symtab first, because it is no longer valid.
2909 breakpoint_re_set may try to access the current symtab. */
2910 clear_current_source_symtab_and_line (current_program_space
);
2913 clear_last_displayed_sal ();
2914 clear_pc_function_cache ();
2915 gdb::observers::all_objfiles_removed
.notify (current_program_space
);
2917 /* Now that the various caches have been cleared, we can re_set
2918 our breakpoints without risking it using stale data. */
2919 if ((add_flags
& SYMFILE_DEFER_BP_RESET
) == 0)
2920 breakpoint_re_set ();
2924 The following code implements an abstraction for debugging overlay sections.
2926 The target model is as follows:
2927 1) The gnu linker will permit multiple sections to be mapped into the
2928 same VMA, each with its own unique LMA (or load address).
2929 2) It is assumed that some runtime mechanism exists for mapping the
2930 sections, one by one, from the load address into the VMA address.
2931 3) This code provides a mechanism for gdb to keep track of which
2932 sections should be considered to be mapped from the VMA to the LMA.
2933 This information is used for symbol lookup, and memory read/write.
2934 For instance, if a section has been mapped then its contents
2935 should be read from the VMA, otherwise from the LMA.
2937 Two levels of debugger support for overlays are available. One is
2938 "manual", in which the debugger relies on the user to tell it which
2939 overlays are currently mapped. This level of support is
2940 implemented entirely in the core debugger, and the information about
2941 whether a section is mapped is kept in the objfile->obj_section table.
2943 The second level of support is "automatic", and is only available if
2944 the target-specific code provides functionality to read the target's
2945 overlay mapping table, and translate its contents for the debugger
2946 (by updating the mapped state information in the obj_section tables).
2948 The interface is as follows:
2950 overlay map <name> -- tell gdb to consider this section mapped
2951 overlay unmap <name> -- tell gdb to consider this section unmapped
2952 overlay list -- list the sections that GDB thinks are mapped
2953 overlay read-target -- get the target's state of what's mapped
2954 overlay off/manual/auto -- set overlay debugging state
2955 Functional interface:
2956 find_pc_mapped_section(pc): if the pc is in the range of a mapped
2957 section, return that section.
2958 find_pc_overlay(pc): find any overlay section that contains
2959 the pc, either in its VMA or its LMA
2960 section_is_mapped(sect): true if overlay is marked as mapped
2961 section_is_overlay(sect): true if section's VMA != LMA
2962 pc_in_mapped_range(pc,sec): true if pc belongs to section's VMA
2963 pc_in_unmapped_range(...): true if pc belongs to section's LMA
2964 sections_overlap(sec1, sec2): true if mapped sec1 and sec2 ranges overlap
2965 overlay_mapped_address(...): map an address from section's LMA to VMA
2966 overlay_unmapped_address(...): map an address from section's VMA to LMA
2967 symbol_overlayed_address(...): Return a "current" address for symbol:
2968 either in VMA or LMA depending on whether
2969 the symbol's section is currently mapped. */
2971 /* Overlay debugging state: */
2973 enum overlay_debugging_state overlay_debugging
= ovly_off
;
2974 int overlay_cache_invalid
= 0; /* True if need to refresh mapped state. */
2976 /* Function: section_is_overlay (SECTION)
2977 Returns true if SECTION has VMA not equal to LMA, ie.
2978 SECTION is loaded at an address different from where it will "run". */
2981 section_is_overlay (struct obj_section
*section
)
2983 if (overlay_debugging
&& section
)
2985 asection
*bfd_section
= section
->the_bfd_section
;
2987 if (bfd_section_lma (bfd_section
) != 0
2988 && bfd_section_lma (bfd_section
) != bfd_section_vma (bfd_section
))
2995 /* Invalidate the mapped state of all overlay sections (mark it as stale) in
2999 overlay_invalidate_all (program_space
*pspace
)
3001 for (objfile
*objfile
: pspace
->objfiles ())
3002 for (obj_section
*sect
: objfile
->sections ())
3003 if (section_is_overlay (sect
))
3004 sect
->ovly_mapped
= -1;
3007 /* Function: section_is_mapped (SECTION)
3008 Returns true if section is an overlay, and is currently mapped.
3010 Access to the ovly_mapped flag is restricted to this function, so
3011 that we can do automatic update. If the global flag
3012 OVERLAY_CACHE_INVALID is set (by wait_for_inferior), then call
3013 overlay_invalidate_all. If the mapped state of the particular
3014 section is stale, then call TARGET_OVERLAY_UPDATE to refresh it. */
3017 section_is_mapped (struct obj_section
*osect
)
3019 struct gdbarch
*gdbarch
;
3021 if (osect
== 0 || !section_is_overlay (osect
))
3024 switch (overlay_debugging
)
3028 return 0; /* overlay debugging off */
3029 case ovly_auto
: /* overlay debugging automatic */
3030 /* Unles there is a gdbarch_overlay_update function,
3031 there's really nothing useful to do here (can't really go auto). */
3032 gdbarch
= osect
->objfile
->arch ();
3033 if (gdbarch_overlay_update_p (gdbarch
))
3035 if (overlay_cache_invalid
)
3037 overlay_invalidate_all (current_program_space
);
3038 overlay_cache_invalid
= 0;
3040 if (osect
->ovly_mapped
== -1)
3041 gdbarch_overlay_update (gdbarch
, osect
);
3044 case ovly_on
: /* overlay debugging manual */
3045 return osect
->ovly_mapped
== 1;
3049 /* Function: pc_in_unmapped_range
3050 If PC falls into the lma range of SECTION, return true, else false. */
3053 pc_in_unmapped_range (CORE_ADDR pc
, struct obj_section
*section
)
3055 if (section_is_overlay (section
))
3057 asection
*bfd_section
= section
->the_bfd_section
;
3059 /* We assume the LMA is relocated by the same offset as the VMA. */
3060 bfd_vma size
= bfd_section_size (bfd_section
);
3061 CORE_ADDR offset
= section
->offset ();
3063 if (bfd_section_lma (bfd_section
) + offset
<= pc
3064 && pc
< bfd_section_lma (bfd_section
) + offset
+ size
)
3071 /* Function: pc_in_mapped_range
3072 If PC falls into the vma range of SECTION, return true, else false. */
3075 pc_in_mapped_range (CORE_ADDR pc
, struct obj_section
*section
)
3077 if (section_is_overlay (section
))
3079 if (section
->contains (pc
))
3086 /* Return true if the mapped ranges of sections A and B overlap, false
3090 sections_overlap (struct obj_section
*a
, struct obj_section
*b
)
3092 CORE_ADDR a_start
= a
->addr ();
3093 CORE_ADDR a_end
= a
->endaddr ();
3094 CORE_ADDR b_start
= b
->addr ();
3095 CORE_ADDR b_end
= b
->endaddr ();
3097 return (a_start
< b_end
&& b_start
< a_end
);
3100 /* Function: overlay_unmapped_address (PC, SECTION)
3101 Returns the address corresponding to PC in the unmapped (load) range.
3102 May be the same as PC. */
3105 overlay_unmapped_address (CORE_ADDR pc
, struct obj_section
*section
)
3107 if (section_is_overlay (section
) && pc_in_mapped_range (pc
, section
))
3109 asection
*bfd_section
= section
->the_bfd_section
;
3111 return (pc
+ bfd_section_lma (bfd_section
)
3112 - bfd_section_vma (bfd_section
));
3118 /* Function: overlay_mapped_address (PC, SECTION)
3119 Returns the address corresponding to PC in the mapped (runtime) range.
3120 May be the same as PC. */
3123 overlay_mapped_address (CORE_ADDR pc
, struct obj_section
*section
)
3125 if (section_is_overlay (section
) && pc_in_unmapped_range (pc
, section
))
3127 asection
*bfd_section
= section
->the_bfd_section
;
3129 return (pc
+ bfd_section_vma (bfd_section
)
3130 - bfd_section_lma (bfd_section
));
3136 /* Function: symbol_overlayed_address
3137 Return one of two addresses (relative to the VMA or to the LMA),
3138 depending on whether the section is mapped or not. */
3141 symbol_overlayed_address (CORE_ADDR address
, struct obj_section
*section
)
3143 if (overlay_debugging
)
3145 /* If the symbol has no section, just return its regular address. */
3148 /* If the symbol's section is not an overlay, just return its
3150 if (!section_is_overlay (section
))
3152 /* If the symbol's section is mapped, just return its address. */
3153 if (section_is_mapped (section
))
3156 * HOWEVER: if the symbol is in an overlay section which is NOT mapped,
3157 * then return its LOADED address rather than its vma address!!
3159 return overlay_unmapped_address (address
, section
);
3164 /* Function: find_pc_overlay (PC)
3165 Return the best-match overlay section for PC:
3166 If PC matches a mapped overlay section's VMA, return that section.
3167 Else if PC matches an unmapped section's VMA, return that section.
3168 Else if PC matches an unmapped section's LMA, return that section. */
3170 struct obj_section
*
3171 find_pc_overlay (CORE_ADDR pc
)
3173 struct obj_section
*best_match
= NULL
;
3175 if (overlay_debugging
)
3177 for (objfile
*objfile
: current_program_space
->objfiles ())
3178 for (obj_section
*osect
: objfile
->sections ())
3179 if (section_is_overlay (osect
))
3181 if (pc_in_mapped_range (pc
, osect
))
3183 if (section_is_mapped (osect
))
3188 else if (pc_in_unmapped_range (pc
, osect
))
3195 /* Function: find_pc_mapped_section (PC)
3196 If PC falls into the VMA address range of an overlay section that is
3197 currently marked as MAPPED, return that section. Else return NULL. */
3199 struct obj_section
*
3200 find_pc_mapped_section (CORE_ADDR pc
)
3202 if (overlay_debugging
)
3204 for (objfile
*objfile
: current_program_space
->objfiles ())
3205 for (obj_section
*osect
: objfile
->sections ())
3206 if (pc_in_mapped_range (pc
, osect
) && section_is_mapped (osect
))
3213 /* Function: list_overlays_command
3214 Print a list of mapped sections and their PC ranges. */
3217 list_overlays_command (const char *args
, int from_tty
)
3221 if (overlay_debugging
)
3223 for (objfile
*objfile
: current_program_space
->objfiles ())
3224 for (obj_section
*osect
: objfile
->sections ())
3225 if (section_is_mapped (osect
))
3227 struct gdbarch
*gdbarch
= objfile
->arch ();
3232 vma
= bfd_section_vma (osect
->the_bfd_section
);
3233 lma
= bfd_section_lma (osect
->the_bfd_section
);
3234 size
= bfd_section_size (osect
->the_bfd_section
);
3235 name
= bfd_section_name (osect
->the_bfd_section
);
3237 gdb_printf ("Section %s, loaded at ", name
);
3238 gdb_puts (paddress (gdbarch
, lma
));
3240 gdb_puts (paddress (gdbarch
, lma
+ size
));
3241 gdb_printf (", mapped at ");
3242 gdb_puts (paddress (gdbarch
, vma
));
3244 gdb_puts (paddress (gdbarch
, vma
+ size
));
3251 gdb_printf (_("No sections are mapped.\n"));
3254 /* Function: map_overlay_command
3255 Mark the named section as mapped (ie. residing at its VMA address). */
3258 map_overlay_command (const char *args
, int from_tty
)
3260 if (!overlay_debugging
)
3261 error (_("Overlay debugging not enabled. Use "
3262 "either the 'overlay auto' or\n"
3263 "the 'overlay manual' command."));
3265 if (args
== 0 || *args
== 0)
3266 error (_("Argument required: name of an overlay section"));
3268 /* First, find a section matching the user supplied argument. */
3269 for (objfile
*obj_file
: current_program_space
->objfiles ())
3270 for (obj_section
*sec
: obj_file
->sections ())
3271 if (!strcmp (bfd_section_name (sec
->the_bfd_section
), args
))
3273 /* Now, check to see if the section is an overlay. */
3274 if (!section_is_overlay (sec
))
3275 continue; /* not an overlay section */
3277 /* Mark the overlay as "mapped". */
3278 sec
->ovly_mapped
= 1;
3280 /* Next, make a pass and unmap any sections that are
3281 overlapped by this new section: */
3282 for (objfile
*objfile2
: current_program_space
->objfiles ())
3283 for (obj_section
*sec2
: objfile2
->sections ())
3284 if (sec2
->ovly_mapped
&& sec
!= sec2
&& sections_overlap (sec
,
3288 gdb_printf (_("Note: section %s unmapped by overlap\n"),
3289 bfd_section_name (sec2
->the_bfd_section
));
3290 sec2
->ovly_mapped
= 0; /* sec2 overlaps sec: unmap sec2. */
3294 error (_("No overlay section called %s"), args
);
3297 /* Function: unmap_overlay_command
3298 Mark the overlay section as unmapped
3299 (ie. resident in its LMA address range, rather than the VMA range). */
3302 unmap_overlay_command (const char *args
, int from_tty
)
3304 if (!overlay_debugging
)
3305 error (_("Overlay debugging not enabled. "
3306 "Use either the 'overlay auto' or\n"
3307 "the 'overlay manual' command."));
3309 if (args
== 0 || *args
== 0)
3310 error (_("Argument required: name of an overlay section"));
3312 /* First, find a section matching the user supplied argument. */
3313 for (objfile
*objfile
: current_program_space
->objfiles ())
3314 for (obj_section
*sec
: objfile
->sections ())
3315 if (!strcmp (bfd_section_name (sec
->the_bfd_section
), args
))
3317 if (!sec
->ovly_mapped
)
3318 error (_("Section %s is not mapped"), args
);
3319 sec
->ovly_mapped
= 0;
3322 error (_("No overlay section called %s"), args
);
3325 /* Function: overlay_auto_command
3326 A utility command to turn on overlay debugging.
3327 Possibly this should be done via a set/show command. */
3330 overlay_auto_command (const char *args
, int from_tty
)
3332 overlay_debugging
= ovly_auto
;
3333 enable_overlay_breakpoints ();
3335 gdb_printf (_("Automatic overlay debugging enabled."));
3338 /* Function: overlay_manual_command
3339 A utility command to turn on overlay debugging.
3340 Possibly this should be done via a set/show command. */
3343 overlay_manual_command (const char *args
, int from_tty
)
3345 overlay_debugging
= ovly_on
;
3346 disable_overlay_breakpoints ();
3348 gdb_printf (_("Overlay debugging enabled."));
3351 /* Function: overlay_off_command
3352 A utility command to turn on overlay debugging.
3353 Possibly this should be done via a set/show command. */
3356 overlay_off_command (const char *args
, int from_tty
)
3358 overlay_debugging
= ovly_off
;
3359 disable_overlay_breakpoints ();
3361 gdb_printf (_("Overlay debugging disabled."));
3365 overlay_load_command (const char *args
, int from_tty
)
3367 struct gdbarch
*gdbarch
= get_current_arch ();
3369 if (gdbarch_overlay_update_p (gdbarch
))
3370 gdbarch_overlay_update (gdbarch
, NULL
);
3372 error (_("This target does not know how to read its overlay state."));
3375 /* Command list chain containing all defined "overlay" subcommands. */
3376 static struct cmd_list_element
*overlaylist
;
3378 /* Target Overlays for the "Simplest" overlay manager:
3380 This is GDB's default target overlay layer. It works with the
3381 minimal overlay manager supplied as an example by Cygnus. The
3382 entry point is via a function pointer "gdbarch_overlay_update",
3383 so targets that use a different runtime overlay manager can
3384 substitute their own overlay_update function and take over the
3387 The overlay_update function pokes around in the target's data structures
3388 to see what overlays are mapped, and updates GDB's overlay mapping with
3391 In this simple implementation, the target data structures are as follows:
3392 unsigned _novlys; /# number of overlay sections #/
3393 unsigned _ovly_table[_novlys][4] = {
3394 {VMA, OSIZE, LMA, MAPPED}, /# one entry per overlay section #/
3395 {..., ..., ..., ...},
3397 unsigned _novly_regions; /# number of overlay regions #/
3398 unsigned _ovly_region_table[_novly_regions][3] = {
3399 {VMA, OSIZE, MAPPED_TO_LMA}, /# one entry per overlay region #/
3402 These functions will attempt to update GDB's mappedness state in the
3403 symbol section table, based on the target's mappedness state.
3405 To do this, we keep a cached copy of the target's _ovly_table, and
3406 attempt to detect when the cached copy is invalidated. The main
3407 entry point is "simple_overlay_update(SECT), which looks up SECT in
3408 the cached table and re-reads only the entry for that section from
3409 the target (whenever possible). */
3411 /* Cached, dynamically allocated copies of the target data structures: */
3412 static unsigned (*cache_ovly_table
)[4] = 0;
3413 static unsigned cache_novlys
= 0;
3414 static CORE_ADDR cache_ovly_table_base
= 0;
3417 VMA
, OSIZE
, LMA
, MAPPED
3420 /* Throw away the cached copy of _ovly_table. */
3423 simple_free_overlay_table (void)
3425 xfree (cache_ovly_table
);
3427 cache_ovly_table
= NULL
;
3428 cache_ovly_table_base
= 0;
3431 /* Read an array of ints of size SIZE from the target into a local buffer.
3432 Convert to host order. int LEN is number of ints. */
3435 read_target_long_array (CORE_ADDR memaddr
, unsigned int *myaddr
,
3436 int len
, int size
, enum bfd_endian byte_order
)
3438 /* FIXME (alloca): Not safe if array is very large. */
3439 gdb_byte
*buf
= (gdb_byte
*) alloca (len
* size
);
3442 read_memory (memaddr
, buf
, len
* size
);
3443 for (i
= 0; i
< len
; i
++)
3444 myaddr
[i
] = extract_unsigned_integer (size
* i
+ buf
, size
, byte_order
);
3447 /* Find and grab a copy of the target _ovly_table
3448 (and _novlys, which is needed for the table's size). */
3451 simple_read_overlay_table (void)
3453 struct gdbarch
*gdbarch
;
3455 enum bfd_endian byte_order
;
3457 simple_free_overlay_table ();
3458 bound_minimal_symbol novlys_msym
3459 = lookup_minimal_symbol (current_program_space
, "_novlys");
3460 if (! novlys_msym
.minsym
)
3462 error (_("Error reading inferior's overlay table: "
3463 "couldn't find `_novlys' variable\n"
3464 "in inferior. Use `overlay manual' mode."));
3468 bound_minimal_symbol ovly_table_msym
3469 = lookup_minimal_symbol (current_program_space
, "_ovly_table");
3470 if (! ovly_table_msym
.minsym
)
3472 error (_("Error reading inferior's overlay table: couldn't find "
3473 "`_ovly_table' array\n"
3474 "in inferior. Use `overlay manual' mode."));
3478 gdbarch
= ovly_table_msym
.objfile
->arch ();
3479 word_size
= gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
3480 byte_order
= gdbarch_byte_order (gdbarch
);
3482 cache_novlys
= read_memory_integer (novlys_msym
.value_address (),
3485 = (unsigned int (*)[4]) xmalloc (cache_novlys
* sizeof (*cache_ovly_table
));
3486 cache_ovly_table_base
= ovly_table_msym
.value_address ();
3487 read_target_long_array (cache_ovly_table_base
,
3488 (unsigned int *) cache_ovly_table
,
3489 cache_novlys
* 4, word_size
, byte_order
);
3491 return 1; /* SUCCESS */
3494 /* Function: simple_overlay_update_1
3495 A helper function for simple_overlay_update. Assuming a cached copy
3496 of _ovly_table exists, look through it to find an entry whose vma,
3497 lma and size match those of OSECT. Re-read the entry and make sure
3498 it still matches OSECT (else the table may no longer be valid).
3499 Set OSECT's mapped state to match the entry. Return: 1 for
3500 success, 0 for failure. */
3503 simple_overlay_update_1 (struct obj_section
*osect
)
3506 asection
*bsect
= osect
->the_bfd_section
;
3507 struct gdbarch
*gdbarch
= osect
->objfile
->arch ();
3508 int word_size
= gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
3509 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3511 for (i
= 0; i
< cache_novlys
; i
++)
3512 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (bsect
)
3513 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (bsect
))
3515 read_target_long_array (cache_ovly_table_base
+ i
* word_size
,
3516 (unsigned int *) cache_ovly_table
[i
],
3517 4, word_size
, byte_order
);
3518 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (bsect
)
3519 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (bsect
))
3521 osect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3524 else /* Warning! Warning! Target's ovly table has changed! */
3530 /* Function: simple_overlay_update
3531 If OSECT is NULL, then update all sections' mapped state
3532 (after re-reading the entire target _ovly_table).
3533 If OSECT is non-NULL, then try to find a matching entry in the
3534 cached ovly_table and update only OSECT's mapped state.
3535 If a cached entry can't be found or the cache isn't valid, then
3536 re-read the entire cache, and go ahead and update all sections. */
3539 simple_overlay_update (struct obj_section
*osect
)
3541 /* Were we given an osect to look up? NULL means do all of them. */
3543 /* Have we got a cached copy of the target's overlay table? */
3544 if (cache_ovly_table
!= NULL
)
3546 /* Does its cached location match what's currently in the
3548 bound_minimal_symbol minsym
3549 = lookup_minimal_symbol (current_program_space
, "_ovly_table");
3551 if (minsym
.minsym
== NULL
)
3552 error (_("Error reading inferior's overlay table: couldn't "
3553 "find `_ovly_table' array\n"
3554 "in inferior. Use `overlay manual' mode."));
3556 if (cache_ovly_table_base
== minsym
.value_address ())
3557 /* Then go ahead and try to look up this single section in
3559 if (simple_overlay_update_1 (osect
))
3560 /* Found it! We're done. */
3564 /* Cached table no good: need to read the entire table anew.
3565 Or else we want all the sections, in which case it's actually
3566 more efficient to read the whole table in one block anyway. */
3568 if (! simple_read_overlay_table ())
3571 /* Now may as well update all sections, even if only one was requested. */
3572 for (objfile
*objfile
: current_program_space
->objfiles ())
3573 for (obj_section
*sect
: objfile
->sections ())
3574 if (section_is_overlay (sect
))
3577 asection
*bsect
= sect
->the_bfd_section
;
3579 for (i
= 0; i
< cache_novlys
; i
++)
3580 if (cache_ovly_table
[i
][VMA
] == bfd_section_vma (bsect
)
3581 && cache_ovly_table
[i
][LMA
] == bfd_section_lma (bsect
))
3582 { /* obj_section matches i'th entry in ovly_table. */
3583 sect
->ovly_mapped
= cache_ovly_table
[i
][MAPPED
];
3584 break; /* finished with inner for loop: break out. */
3589 /* Default implementation for sym_relocate. */
3592 default_symfile_relocate (struct objfile
*objfile
, asection
*sectp
,
3595 /* Use sectp->owner instead of objfile->obfd. sectp may point to a
3597 bfd
*abfd
= sectp
->owner
;
3599 /* We're only interested in sections with relocation
3601 if ((sectp
->flags
& SEC_RELOC
) == 0)
3604 /* We will handle section offsets properly elsewhere, so relocate as if
3605 all sections begin at 0. */
3606 for (asection
*sect
: gdb_bfd_sections (abfd
))
3608 sect
->output_section
= sect
;
3609 sect
->output_offset
= 0;
3612 return bfd_simple_get_relocated_section_contents (abfd
, sectp
, buf
, NULL
);
3615 /* Relocate the contents of a debug section SECTP in ABFD. The
3616 contents are stored in BUF if it is non-NULL, or returned in a
3617 malloc'd buffer otherwise.
3619 For some platforms and debug info formats, shared libraries contain
3620 relocations against the debug sections (particularly for DWARF-2;
3621 one affected platform is PowerPC GNU/Linux, although it depends on
3622 the version of the linker in use). Also, ELF object files naturally
3623 have unresolved relocations for their debug sections. We need to apply
3624 the relocations in order to get the locations of symbols correct.
3625 Another example that may require relocation processing, is the
3626 DWARF-2 .eh_frame section in .o files, although it isn't strictly a
3630 symfile_relocate_debug_section (struct objfile
*objfile
,
3631 asection
*sectp
, bfd_byte
*buf
)
3633 gdb_assert (objfile
->sf
->sym_relocate
);
3635 return (*objfile
->sf
->sym_relocate
) (objfile
, sectp
, buf
);
3638 symfile_segment_data_up
3639 get_symfile_segment_data (bfd
*abfd
)
3641 const struct sym_fns
*sf
= find_sym_fns (abfd
);
3646 return sf
->sym_segments (abfd
);
3650 - DATA, containing segment addresses from the object file ABFD, and
3651 the mapping from ABFD's sections onto the segments that own them,
3653 - SEGMENT_BASES[0 .. NUM_SEGMENT_BASES - 1], holding the actual
3654 segment addresses reported by the target,
3655 store the appropriate offsets for each section in OFFSETS.
3657 If there are fewer entries in SEGMENT_BASES than there are segments
3658 in DATA, then apply SEGMENT_BASES' last entry to all the segments.
3660 If there are more entries, then ignore the extra. The target may
3661 not be able to distinguish between an empty data segment and a
3662 missing data segment; a missing text segment is less plausible. */
3665 symfile_map_offsets_to_segments (bfd
*abfd
,
3666 const struct symfile_segment_data
*data
,
3667 section_offsets
&offsets
,
3668 int num_segment_bases
,
3669 const CORE_ADDR
*segment_bases
)
3674 /* It doesn't make sense to call this function unless you have some
3675 segment base addresses. */
3676 gdb_assert (num_segment_bases
> 0);
3678 /* If we do not have segment mappings for the object file, we
3679 can not relocate it by segments. */
3680 gdb_assert (data
!= NULL
);
3681 gdb_assert (data
->segments
.size () > 0);
3683 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
3685 int which
= data
->segment_info
[i
];
3687 gdb_assert (0 <= which
&& which
<= data
->segments
.size ());
3689 /* Don't bother computing offsets for sections that aren't
3690 loaded as part of any segment. */
3694 /* Use the last SEGMENT_BASES entry as the address of any extra
3695 segments mentioned in DATA->segment_info. */
3696 if (which
> num_segment_bases
)
3697 which
= num_segment_bases
;
3699 offsets
[i
] = segment_bases
[which
- 1] - data
->segments
[which
- 1].base
;
3706 symfile_find_segment_sections (struct objfile
*objfile
)
3708 bfd
*abfd
= objfile
->obfd
.get ();
3712 symfile_segment_data_up data
= get_symfile_segment_data (abfd
);
3716 if (data
->segments
.size () != 1 && data
->segments
.size () != 2)
3719 for (i
= 0, sect
= abfd
->sections
; sect
!= NULL
; i
++, sect
= sect
->next
)
3721 int which
= data
->segment_info
[i
];
3725 if (objfile
->sect_index_text
== -1)
3726 objfile
->sect_index_text
= sect
->index
;
3728 if (objfile
->sect_index_rodata
== -1)
3729 objfile
->sect_index_rodata
= sect
->index
;
3731 else if (which
== 2)
3733 if (objfile
->sect_index_data
== -1)
3734 objfile
->sect_index_data
= sect
->index
;
3736 if (objfile
->sect_index_bss
== -1)
3737 objfile
->sect_index_bss
= sect
->index
;
3742 /* Listen for free_objfile events. */
3745 symfile_free_objfile (struct objfile
*objfile
)
3747 /* Remove the target sections owned by this objfile. */
3748 objfile
->pspace ()->remove_target_sections (objfile
);
3751 /* Wrapper around the quick_symbol_functions expand_symtabs_matching "method".
3752 Expand all symtabs that match the specified criteria.
3753 See quick_symbol_functions.expand_symtabs_matching for details. */
3756 expand_symtabs_matching
3757 (gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3758 const lookup_name_info
&lookup_name
,
3759 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3760 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
3761 block_search_flags search_flags
,
3762 domain_search_flags domain
)
3764 for (objfile
*objfile
: current_program_space
->objfiles ())
3765 if (!objfile
->expand_symtabs_matching (file_matcher
,
3775 /* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
3776 Map function FUN over every file.
3777 See quick_symbol_functions.map_symbol_filenames for details. */
3780 map_symbol_filenames (gdb::function_view
<symbol_filename_ftype
> fun
,
3783 for (objfile
*objfile
: current_program_space
->objfiles ())
3784 objfile
->map_symbol_filenames (fun
, need_fullname
);
3789 namespace selftests
{
3790 namespace filename_language
{
3792 static void test_filename_language ()
3794 /* This test messes up the filename_language_table global. */
3795 scoped_restore restore_flt
= make_scoped_restore (&filename_language_table
);
3797 /* Test deducing an unknown extension. */
3798 language lang
= deduce_language_from_filename ("myfile.blah");
3799 SELF_CHECK (lang
== language_unknown
);
3801 /* Test deducing a known extension. */
3802 lang
= deduce_language_from_filename ("myfile.c");
3803 SELF_CHECK (lang
== language_c
);
3805 /* Test adding a new extension using the internal API. */
3806 add_filename_language (".blah", language_pascal
);
3807 lang
= deduce_language_from_filename ("myfile.blah");
3808 SELF_CHECK (lang
== language_pascal
);
3812 test_set_ext_lang_command ()
3814 /* This test messes up the filename_language_table global. */
3815 scoped_restore restore_flt
= make_scoped_restore (&filename_language_table
);
3817 /* Confirm that the .hello extension is not known. */
3818 language lang
= deduce_language_from_filename ("cake.hello");
3819 SELF_CHECK (lang
== language_unknown
);
3821 /* Test adding a new extension using the CLI command. */
3822 ext_args
= ".hello rust";
3823 set_ext_lang_command (NULL
, 1, NULL
);
3825 lang
= deduce_language_from_filename ("cake.hello");
3826 SELF_CHECK (lang
== language_rust
);
3828 /* Test overriding an existing extension using the CLI command. */
3829 int size_before
= filename_language_table
.size ();
3830 ext_args
= ".hello pascal";
3831 set_ext_lang_command (NULL
, 1, NULL
);
3832 int size_after
= filename_language_table
.size ();
3834 lang
= deduce_language_from_filename ("cake.hello");
3835 SELF_CHECK (lang
== language_pascal
);
3836 SELF_CHECK (size_before
== size_after
);
3839 } /* namespace filename_language */
3840 } /* namespace selftests */
3842 #endif /* GDB_SELF_TEST */
3844 void _initialize_symfile ();
3846 _initialize_symfile ()
3848 struct cmd_list_element
*c
;
3850 gdb::observers::free_objfile
.attach (symfile_free_objfile
, "symfile");
3852 #define READNOW_READNEVER_HELP \
3853 "The '-readnow' option will cause GDB to read the entire symbol file\n\
3854 immediately. This makes the command slower, but may make future operations\n\
3856 The '-readnever' option will prevent GDB from reading the symbol file's\n\
3857 symbolic debug information."
3859 c
= add_cmd ("symbol-file", class_files
, symbol_file_command
, _("\
3860 Load symbol table from executable file FILE.\n\
3861 Usage: symbol-file [-readnow | -readnever] [-o OFF] FILE\n\
3862 OFF is an optional offset which is added to each section address.\n\
3863 The `file' command can also load symbol tables, as well as setting the file\n\
3864 to execute.\n" READNOW_READNEVER_HELP
), &cmdlist
);
3865 set_cmd_completer (c
, filename_maybe_quoted_completer
);
3867 c
= add_cmd ("add-symbol-file", class_files
, add_symbol_file_command
, _("\
3868 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
3869 Usage: add-symbol-file FILE [-readnow | -readnever] [-o OFF] [ADDR] \
3870 [-s SECT-NAME SECT-ADDR]...\n\
3871 ADDR is the starting address of the file's text.\n\
3872 Each '-s' argument provides a section name and address, and\n\
3873 should be specified if the data and bss segments are not contiguous\n\
3874 with the text. SECT-NAME is a section name to be loaded at SECT-ADDR.\n\
3875 OFF is an optional offset which is added to the default load addresses\n\
3876 of all sections for which no other address was specified.\n"
3877 READNOW_READNEVER_HELP
),
3879 set_cmd_completer (c
, filename_maybe_quoted_completer
);
3881 const auto remove_symbol_file_opts
3882 = make_remove_symbol_file_def_group (nullptr);
3883 static std::string remove_symbol_file_cmd_help
3884 = gdb::option::build_help (_("\
3885 Remove a symbol file added via the add-symbol-file command.\n\
3886 Usage: remove-symbol-file FILENAME\n\
3887 remove-symbol-file -a ADDRESS\n\
3888 The file to remove can be identified by its filename or by an address\n\
3889 that lies within the boundaries of this symbol file in memory.\n\
3891 %OPTIONS%"), remove_symbol_file_opts
);
3892 c
= add_cmd ("remove-symbol-file", class_files
,
3893 remove_symbol_file_command
,
3894 remove_symbol_file_cmd_help
.c_str (),
3896 set_cmd_completer_handle_brkchars (c
, remove_symbol_file_command_completer
);
3898 c
= add_cmd ("load", class_files
, load_command
, _("\
3899 Dynamically load FILE into the running program.\n\
3900 FILE symbols are recorded for access from GDB.\n\
3901 Usage: load [FILE] [OFFSET]\n\
3902 An optional load OFFSET may also be given as a literal address.\n\
3903 When OFFSET is provided, FILE must also be provided. FILE can be provided\n\
3904 on its own."), &cmdlist
);
3905 set_cmd_completer (c
, deprecated_filename_completer
);
3907 cmd_list_element
*overlay_cmd
3908 = add_basic_prefix_cmd ("overlay", class_support
,
3909 _("Commands for debugging overlays."), &overlaylist
,
3912 add_com_alias ("ovly", overlay_cmd
, class_support
, 1);
3913 add_com_alias ("ov", overlay_cmd
, class_support
, 1);
3915 add_cmd ("map-overlay", class_support
, map_overlay_command
,
3916 _("Assert that an overlay section is mapped."), &overlaylist
);
3918 add_cmd ("unmap-overlay", class_support
, unmap_overlay_command
,
3919 _("Assert that an overlay section is unmapped."), &overlaylist
);
3921 add_cmd ("list-overlays", class_support
, list_overlays_command
,
3922 _("List mappings of overlay sections."), &overlaylist
);
3924 add_cmd ("manual", class_support
, overlay_manual_command
,
3925 _("Enable overlay debugging."), &overlaylist
);
3926 add_cmd ("off", class_support
, overlay_off_command
,
3927 _("Disable overlay debugging."), &overlaylist
);
3928 add_cmd ("auto", class_support
, overlay_auto_command
,
3929 _("Enable automatic overlay debugging."), &overlaylist
);
3930 add_cmd ("load-target", class_support
, overlay_load_command
,
3931 _("Read the overlay mapping state from the target."), &overlaylist
);
3933 /* Filename extension to source language lookup table: */
3934 add_setshow_string_noescape_cmd ("extension-language", class_files
,
3936 Set mapping between filename extension and source language."), _("\
3937 Show mapping between filename extension and source language."), _("\
3938 Usage: set extension-language .foo bar"),
3939 set_ext_lang_command
,
3941 &setlist
, &showlist
);
3943 add_info ("extensions", info_ext_lang_command
,
3944 _("All filename extensions associated with a source language."));
3946 add_setshow_optional_filename_cmd ("debug-file-directory", class_support
,
3947 &debug_file_directory
, _("\
3948 Set the directories where separate debug symbols are searched for."), _("\
3949 Show the directories where separate debug symbols are searched for."), _("\
3950 Separate debug symbols are first searched for in the same\n\
3951 directory as the binary, then in the `" DEBUG_SUBDIRECTORY
"' subdirectory,\n\
3952 and lastly at the path of the directory of the binary with\n\
3953 each global debug-file-directory component prepended."),
3955 show_debug_file_directory
,
3956 &setlist
, &showlist
);
3958 add_setshow_enum_cmd ("symbol-loading", no_class
,
3959 print_symbol_loading_enums
, &print_symbol_loading
,
3961 Set printing of symbol loading messages."), _("\
3962 Show printing of symbol loading messages."), _("\
3963 off == turn all messages off\n\
3964 brief == print messages for the executable,\n\
3965 and brief messages for shared libraries\n\
3966 full == print messages for the executable,\n\
3967 and messages for each shared library."),
3970 &setprintlist
, &showprintlist
);
3972 add_setshow_boolean_cmd ("separate-debug-file", no_class
,
3973 &separate_debug_file_debug
, _("\
3974 Set printing of separate debug info file search debug."), _("\
3975 Show printing of separate debug info file search debug."), _("\
3976 When on, GDB prints the searched locations while looking for separate debug \
3977 info files."), NULL
, NULL
, &setdebuglist
, &showdebuglist
);
3980 selftests::register_test
3981 ("filename_language", selftests::filename_language::test_filename_language
);
3982 selftests::register_test
3983 ("set_ext_lang_command",
3984 selftests::filename_language::test_set_ext_lang_command
);