*t, bfd *abfd)
{
struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
/* FIXME: 16 is not wide enough when gdbarch_addr_bit > 64. */
int wid = gdbarch_addr_bit (gdbarch) <= 32 ? 8 : 16;
gdb_printf ("\t`%ps', ",
styled_string (file_name_style.style (),
bfd_get_filename (abfd)));
gdb_stdout->wrap_here (8);
gdb_printf (_("file type %s.\n"), bfd_get_target (abfd));
if (abfd == current_program_space->exec_bfd ())
{
/* gcc-3.4 does not like the initialization in
sections_end>. */
bfd_vma displacement = 0;
bfd_vma entry_point;
bool found = false;
for (const target_section &p : *t)
{
struct bfd_section *psect = p.the_bfd_section;
if ((bfd_section_flags (psect) & (SEC_ALLOC | SEC_LOAD))
!= (SEC_ALLOC | SEC_LOAD))
continue;
if (bfd_section_vma (psect) <= abfd->start_address
&& abfd->start_address < (bfd_section_vma (psect)
+ bfd_section_size (psect)))
{
displacement = p.addr - bfd_section_vma (psect);
found = true;
break;
}
}
if (!found)
warning (_("Cannot find section for the entry point of %ps."),
styled_string (file_name_style.style (),
bfd_get_filename (abfd)));
entry_point = gdbarch_addr_bits_remove (gdbarch,
bfd_get_start_address (abfd)
+ displacement);
gdb_printf (_("\tEntry point: %s\n"),
paddress (gdbarch, entry_point));
}
for (const target_section &p : *t)
{
struct bfd_section *psect = p.the_bfd_section;
bfd *pbfd = psect->owner;
gdb_printf ("\t%s", hex_string_custom (p.addr, wid));
gdb_printf (" - %s", hex_string_custom (p.endaddr, wid));
/* FIXME: A format of "08l" is not wide enough for file offsets
larger than 4GB. OTOH, making it "016l" isn't desirable either
since most output will then be much wider than necessary. It
may make sense to test the size of the file and choose the
format string accordingly. */
/* FIXME: i18n: Need to rewrite this sentence. */
if (info_verbose)
gdb_printf (" @ %s",
hex_string_custom (psect->filepos, 8));
gdb_printf (" is %s", bfd_section_name (psect));
if (pbfd != abfd)
gdb_printf (" in %ps",
styled_string (file_name_style.style (),
bfd_get_filename (pbfd)));
gdb_printf ("\n");
}
}
void
exec_target::files_info ()
{
if (current_program_space->exec_bfd ())
print_section_info (¤t_program_space->target_sections (),
current_program_space->exec_bfd ());
else
gdb_puts (_("\t\n"));
}
static void
set_section_command (const char *args, int from_tty)
{
const char *secname;
if (args == 0)
error (_("Must specify section name and its virtual address"));
/* Parse out section name. */
for (secname = args; !isspace (*args); args++);
unsigned seclen = args - secname;
/* Parse out new virtual address. */
CORE_ADDR secaddr = parse_and_eval_address (args);
for (target_section &p : current_program_space->target_sections ())
{
if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
&& bfd_section_name (p.the_bfd_section)[seclen] == '\0')
{
long offset = secaddr - p.addr;
p.addr += offset;
p.endaddr += offset;
if (from_tty)
exec_ops.files_info ();
return;
}
}
std::string secprint (secname, seclen);
error (_("Section %s not found"), secprint.c_str ());
}
/* If we can find a section in FILENAME with BFD index INDEX, adjust
it to ADDRESS. */
void
exec_set_section_address (const char *filename, int index, CORE_ADDR address)
{
for (target_section &p : current_program_space->target_sections ())
{
if (filename_cmp (filename,
bfd_get_filename (p.the_bfd_section->owner)) == 0
&& index == p.the_bfd_section->index)
{
p.endaddr += address - p.addr;
p.addr = address;
}
}
}
bool
exec_target::has_memory ()
{
/* We can provide memory if we have any file/target sections to read
from. */
return !current_program_space->target_sections ().empty ();
}
gdb::unique_xmalloc_ptr
exec_target::make_corefile_notes (bfd *obfd, int *note_size)
{
error (_("Can't create a corefile"));
}
int
exec_target::find_memory_regions (find_memory_region_ftype func, void *data)
{
return objfile_find_memory_regions (this, func, data);
}
void _initialize_exec ();
void
_initialize_exec ()
{
struct cmd_list_element *c;
c = add_cmd ("file", class_files, file_command, _("\
Use FILE as program to be debugged.\n\
It is read for its symbols, for getting the contents of pure memory,\n\
and it is the program executed when you use the `run' command.\n\
If FILE cannot be found as specified, your execution directory path\n\
($PATH) is searched for a command of that name.\n\
No arg means to have no executable file and no symbols."), &cmdlist);
set_cmd_completer (c, filename_maybe_quoted_completer);
c = add_cmd ("exec-file", class_files, exec_file_command, _("\
Use FILE as program for getting contents of pure memory.\n\
If FILE cannot be found as specified, your execution directory path\n\
is searched for a command of that name.\n\
No arg means have no executable file."), &cmdlist);
set_cmd_completer (c, filename_maybe_quoted_completer);
add_com ("section", class_files, set_section_command, _("\
Change the base address of section SECTION of the exec file to ADDR.\n\
This can be used if the exec file does not contain section addresses,\n\
(such as in the a.out format), or when the addresses specified in the\n\
file itself are wrong. Each section must be changed separately. The\n\
``info files'' command lists all the sections and their addresses."));
add_setshow_boolean_cmd ("write", class_support, &write_files, _("\
Set writing into executable and core files."), _("\
Show writing into executable and core files."), NULL,
NULL,
show_write_files,
&setlist, &showlist);
add_setshow_enum_cmd ("exec-file-mismatch", class_support,
exec_file_mismatch_names,
&exec_file_mismatch,
_("\
Set exec-file-mismatch handling (ask|warn|off)."),
_("\
Show exec-file-mismatch handling (ask|warn|off)."),
_("\
Specifies how to handle a mismatch between the current exec-file\n\
loaded by GDB and the exec-file automatically determined when attaching\n\
to a process:\n\n\
ask - warn the user and ask whether to load the determined exec-file.\n\
warn - warn the user, but do not change the exec-file.\n\
off - do not check for mismatch.\n\
\n\
GDB detects a mismatch by comparing the build IDs of the files.\n\
If the user confirms loading the determined exec-file, then its symbols\n\
will be loaded as well."),
set_exec_file_mismatch_command,
show_exec_file_mismatch_command,
&setlist, &showlist);
add_target (exec_target_info, exec_target_open,
filename_maybe_quoted_completer);
}