/* Generate a core file for the inferior process.
- Copyright (C) 2001-2021 Free Software Foundation, Inc.
+ Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of GDB.
else
{
/* Default corefile name is "core.PID". */
- corefilename.reset (xstrprintf ("core.%d", inferior_ptid.pid ()));
+ corefilename = xstrprintf ("core.%d", inferior_ptid.pid ());
}
if (info_verbose)
bfd *abfd = objfile->obfd;
asection *asec = objsec->the_bfd_section;
bfd_vma align = (bfd_vma) 1 << bfd_section_alignment (asec);
- bfd_vma start = obj_section_addr (objsec) & -align;
- bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
+ bfd_vma start = objsec->addr () & -align;
+ bfd_vma end = (objsec->endaddr () + align - 1) & -align;
/* Match if either the entire memory region lies inside the
section (i.e. a mapping covering some pages of a large
int size = bfd_section_size (isec);
int ret;
- ret = (*func) (obj_section_addr (objsec), size,
+ ret = (*func) (objsec->addr (), size,
1, /* All sections will be readable. */
(flags & SEC_READONLY) == 0, /* Writable. */
(flags & SEC_CODE) != 0, /* Executable. */
return 1;
}
-/* Structure for passing information from GCORE_COLLECT_THREAD_REGISTERS
- via an iterator to GCORE_COLLECT_REGSET_SECTION_CB. */
-
-struct gcore_collect_regset_section_cb_data
-{
- gcore_collect_regset_section_cb_data (struct gdbarch *gdbarch,
- const struct regcache *regcache,
- bfd *obfd, ptid_t ptid,
- gdb_signal stop_signal,
- gdb::unique_xmalloc_ptr<char> *note_data,
- int *note_size)
-
- : gdbarch (gdbarch), regcache (regcache), obfd (obfd),
- note_data (note_data), note_size (note_size),
- stop_signal (stop_signal)
- {
- /* The LWP is often not available for bare metal target, in which case
- use the tid instead. */
- if (ptid.lwp_p ())
- lwp = ptid.lwp ();
- else
- lwp = ptid.tid ();
- }
-
- struct gdbarch *gdbarch;
- const struct regcache *regcache;
- bfd *obfd;
- gdb::unique_xmalloc_ptr<char> *note_data;
- int *note_size;
- unsigned long lwp;
- enum gdb_signal stop_signal;
- bool abort_iteration = false;
-};
-
-/* Callback for ITERATE_OVER_REGSET_SECTIONS that records a single
- regset in the core file note section. */
-
-static void
-gcore_collect_regset_section_cb (const char *sect_name, int supply_size,
- int collect_size,
- const struct regset *regset,
- const char *human_name, void *cb_data)
-{
- struct gcore_collect_regset_section_cb_data *data
- = (struct gcore_collect_regset_section_cb_data *) cb_data;
- bool variable_size_section = (regset != NULL
- && regset->flags & REGSET_VARIABLE_SIZE);
-
- gdb_assert (variable_size_section || supply_size == collect_size);
-
- if (data->abort_iteration)
- return;
-
- gdb_assert (regset != nullptr && regset->collect_regset != nullptr);
-
- /* This is intentionally zero-initialized by using std::vector, so
- that any padding bytes in the core file will show as 0. */
- std::vector<gdb_byte> buf (collect_size);
-
- regset->collect_regset (regset, data->regcache, -1, buf.data (),
- collect_size);
-
- /* PRSTATUS still needs to be treated specially. */
- if (strcmp (sect_name, ".reg") == 0)
- data->note_data->reset (elfcore_write_prstatus
- (data->obfd, data->note_data->release (),
- data->note_size, data->lwp,
- gdb_signal_to_host (data->stop_signal),
- buf.data ()));
- else
- data->note_data->reset (elfcore_write_register_note
- (data->obfd, data->note_data->release (),
- data->note_size, sect_name, buf.data (),
- collect_size));
-
- if (data->note_data == nullptr)
- data->abort_iteration = true;
-}
-
-/* Records the register state of thread PTID out of REGCACHE into the note
- buffer represented by *NOTE_DATA and NOTE_SIZE. OBFD is the bfd into
- which the core file is being created, and STOP_SIGNAL is the signal that
- cause thread PTID to stop. */
-
-static void
-gcore_collect_thread_registers (const struct regcache *regcache,
- ptid_t ptid, bfd *obfd,
- gdb::unique_xmalloc_ptr<char> *note_data,
- int *note_size,
- enum gdb_signal stop_signal)
-{
- struct gdbarch *gdbarch = regcache->arch ();
- gcore_collect_regset_section_cb_data data (gdbarch, regcache, obfd, ptid,
- stop_signal, note_data,
- note_size);
- gdbarch_iterate_over_regset_sections (gdbarch,
- gcore_collect_regset_section_cb,
- &data, regcache);
-}
-
-/* See gcore.h. */
-
-void
-gcore_build_thread_register_notes
- (struct gdbarch *gdbarch, struct thread_info *info, gdb_signal stop_signal,
- bfd *obfd, gdb::unique_xmalloc_ptr<char> *note_data, int *note_size)
-{
- struct regcache *regcache
- = get_thread_arch_regcache (info->inf->process_target (),
- info->ptid, gdbarch);
- target_fetch_registers (regcache, -1);
- gcore_collect_thread_registers (regcache, info->ptid, obfd, note_data,
- note_size, stop_signal);
-}
-
/* See gcore.h. */
thread_info *
{
thread_info *curr_thr = inferior_thread ();
if (curr_thr->state != THREAD_EXITED
- && curr_thr->suspend.stop_signal != GDB_SIGNAL_0)
+ && curr_thr->stop_signal () != GDB_SIGNAL_0)
return curr_thr;
for (thread_info *thr : current_inferior ()->non_exited_threads ())
- if (thr->suspend.stop_signal != GDB_SIGNAL_0)
+ if (thr->stop_signal () != GDB_SIGNAL_0)
return thr;
/* Default to the current thread, unless it has exited. */
void
_initialize_gcore ()
{
- add_com ("generate-core-file", class_files, gcore_command, _("\
+ cmd_list_element *generate_core_file_cmd
+ = add_com ("generate-core-file", class_files, gcore_command, _("\
Save a core file with the current state of the debugged process.\n\
Usage: generate-core-file [FILENAME]\n\
Argument is optional filename. Default filename is 'core.PROCESS_ID'."));
- add_com_alias ("gcore", "generate-core-file", class_files, 1);
+ add_com_alias ("gcore", generate_core_file_cmd, class_files, 1);
}