+2020-10-21 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * gdbarch.sh (make_corefile_notes): Return unique pointer.
+ * gdbarch.c: Re-generate.
+ * gdbarch.h: Re-generate.
+ * gcore.c (write_gcore_file_1): Adjust.
+ * fbsd-tdep.c (struct fbsd_collect_regset_section_cb_data): Add
+ constructor.
+ <note_data>: Change type to unique pointer.
+ <abort_iteration>: Change type to bool.
+ (fbsd_collect_regset_section_cb): Adjust to unique pointer.
+ (fbsd_collect_thread_registers): Return void, adjust.
+ (struct fbsd_corefile_thread_data): Add construtor.
+ <note_data>: Change type to unique pointer.
+ (fbsd_corefile_thread): Adjust.
+ (fbsd_make_corefile_notes): Return unique pointer, adjust.
+ * linux-tdep.c (linux_make_mappings_corefile_notes): Change type
+ to unique pointer, adjust.
+ (struct linux_collect_regset_section_cb_data): Add constructor.
+ <note_data>: Change type to unique pointer.
+ <abort_iteration>: Change type to bool.
+ (linux_collect_thread_registers): Return void, adjust.
+ (struct linux_corefile_thread_data): Add constructor.
+ <note_data>: Change type to unique pointer.
+ (linux_corefile_thread): Adjust.
+ (linux_make_corefile_notes): Return unique pointer, adjust.
+
2020-10-20 Simon Marchi <simon.marchi@polymtl.ca>
* gdbarch.sh (displaced_step_hw_singlestep): Return bool.
struct fbsd_collect_regset_section_cb_data
{
+ fbsd_collect_regset_section_cb_data (const struct regcache *regcache,
+ bfd *obfd,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size,
+ unsigned long lwp,
+ gdb_signal stop_signal)
+ : regcache (regcache),
+ obfd (obfd),
+ note_data (note_data),
+ note_size (note_size),
+ lwp (lwp),
+ stop_signal (stop_signal)
+ {}
+
const struct regcache *regcache;
bfd *obfd;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> ¬e_data;
int *note_size;
unsigned long lwp;
enum gdb_signal stop_signal;
- int abort_iteration;
+ bool abort_iteration = false;
};
static void
/* PRSTATUS still needs to be treated specially. */
if (strcmp (sect_name, ".reg") == 0)
- data->note_data = (char *) elfcore_write_prstatus
- (data->obfd, data->note_data, data->note_size, data->lwp,
- gdb_signal_to_host (data->stop_signal), buf);
+ 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));
else
- data->note_data = (char *) elfcore_write_register_note
- (data->obfd, data->note_data, data->note_size,
- sect_name, buf, collect_size);
+ data->note_data.reset (elfcore_write_register_note
+ (data->obfd, data->note_data.release (),
+ data->note_size, sect_name, buf,
+ collect_size));
xfree (buf);
if (data->note_data == NULL)
- data->abort_iteration = 1;
+ data->abort_iteration = true;
}
/* Records the thread's register state for the corefile note
section. */
-static char *
+static void
fbsd_collect_thread_registers (const struct regcache *regcache,
ptid_t ptid, bfd *obfd,
- char *note_data, int *note_size,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size,
enum gdb_signal stop_signal)
{
- struct gdbarch *gdbarch = regcache->arch ();
- struct fbsd_collect_regset_section_cb_data data;
-
- data.regcache = regcache;
- data.obfd = obfd;
- data.note_data = note_data;
- data.note_size = note_size;
- data.stop_signal = stop_signal;
- data.abort_iteration = 0;
- data.lwp = ptid.lwp ();
-
- gdbarch_iterate_over_regset_sections (gdbarch,
+ fbsd_collect_regset_section_cb_data data (regcache, obfd, note_data,
+ note_size, ptid.lwp (),
+ stop_signal);
+
+ gdbarch_iterate_over_regset_sections (regcache->arch (),
fbsd_collect_regset_section_cb,
&data, regcache);
- return data.note_data;
}
struct fbsd_corefile_thread_data
{
+ fbsd_corefile_thread_data (struct gdbarch *gdbarch,
+ bfd *obfd,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size,
+ gdb_signal stop_signal)
+ : gdbarch (gdbarch),
+ obfd (obfd),
+ note_data (note_data),
+ note_size (note_size),
+ stop_signal (stop_signal)
+ {}
+
struct gdbarch *gdbarch;
bfd *obfd;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> ¬e_data;
int *note_size;
enum gdb_signal stop_signal;
};
target_fetch_registers (regcache, -1);
- args->note_data = fbsd_collect_thread_registers
- (regcache, info->ptid, args->obfd, args->note_data,
- args->note_size, args->stop_signal);
+ fbsd_collect_thread_registers (regcache, info->ptid, args->obfd,
+ args->note_data, args->note_size,
+ args->stop_signal);
}
/* Return a byte_vector containing the contents of a core dump note
/* Create appropriate note sections for a corefile, returning them in
allocated memory. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
{
- struct fbsd_corefile_thread_data thread_args;
- char *note_data = NULL;
+ gdb::unique_xmalloc_ptr<char> note_data;
Elf_Internal_Ehdr *i_ehdrp;
struct thread_info *curr_thr, *signalled_thr;
if (infargs != NULL)
psargs = psargs + " " + infargs;
- note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
- fname, psargs.c_str ());
+ note_data.reset (elfcore_write_prpsinfo (obfd, note_data.release (),
+ note_size, fname,
+ psargs.c_str ()));
}
/* Thread register information. */
signalled_thr = curr_thr;
}
- thread_args.gdbarch = gdbarch;
- thread_args.obfd = obfd;
- thread_args.note_data = note_data;
- thread_args.note_size = note_size;
- thread_args.stop_signal = signalled_thr->suspend.stop_signal;
+ fbsd_corefile_thread_data thread_args (gdbarch, obfd, note_data, note_size,
+ signalled_thr->suspend.stop_signal);
fbsd_corefile_thread (signalled_thr, &thread_args);
for (thread_info *thr : current_inferior ()->non_exited_threads ())
fbsd_corefile_thread (thr, &thread_args);
}
- note_data = thread_args.note_data;
-
/* Auxiliary vector. */
uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
gdb::optional<gdb::byte_vector> note_desc =
fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize);
if (note_desc && !note_desc->empty ())
{
- note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
- NT_FREEBSD_PROCSTAT_AUXV,
- note_desc->data (), note_desc->size ());
+ note_data.reset (elfcore_write_note (obfd, note_data.release (),
+ note_size, "FreeBSD",
+ NT_FREEBSD_PROCSTAT_AUXV,
+ note_desc->data (),
+ note_desc->size ()));
if (!note_data)
return NULL;
}
note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
if (note_desc && !note_desc->empty ())
{
- note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
- NT_FREEBSD_PROCSTAT_VMMAP,
- note_desc->data (), note_desc->size ());
+ note_data.reset (elfcore_write_note (obfd, note_data.release (),
+ note_size, "FreeBSD",
+ NT_FREEBSD_PROCSTAT_VMMAP,
+ note_desc->data (),
+ note_desc->size ()));
if (!note_data)
return NULL;
}
note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
if (note_desc && !note_desc->empty ())
{
- note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
- NT_FREEBSD_PROCSTAT_PSSTRINGS,
- note_desc->data (), note_desc->size ());
+ note_data.reset (elfcore_write_note (obfd, note_data.release (),
+ note_size, "FreeBSD",
+ NT_FREEBSD_PROCSTAT_PSSTRINGS,
+ note_desc->data (),
+ note_desc->size ()));
if (!note_data)
return NULL;
}
if (!gdbarch_make_corefile_notes_p (target_gdbarch ()))
note_data.reset (target_make_corefile_notes (obfd, ¬e_size));
else
- note_data.reset (gdbarch_make_corefile_notes (target_gdbarch (), obfd,
- ¬e_size));
+ note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd,
+ ¬e_size);
if (note_data == NULL || note_size == 0)
error (_("Target does not support core file generation."));
return gdbarch->make_corefile_notes != NULL;
}
-char *
+gdb::unique_xmalloc_ptr<char>
gdbarch_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
{
gdb_assert (gdbarch != NULL);
extern bool gdbarch_make_corefile_notes_p (struct gdbarch *gdbarch);
-typedef char * (gdbarch_make_corefile_notes_ftype) (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
-extern char * gdbarch_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
+typedef gdb::unique_xmalloc_ptr<char> (gdbarch_make_corefile_notes_ftype) (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
+extern gdb::unique_xmalloc_ptr<char> gdbarch_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
extern void set_gdbarch_make_corefile_notes (struct gdbarch *gdbarch, gdbarch_make_corefile_notes_ftype *make_corefile_notes);
/* Find core file memory regions */
M;void;iterate_over_regset_sections;iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache;cb, cb_data, regcache
# Create core file notes
-M;char *;make_corefile_notes;bfd *obfd, int *note_size;obfd, note_size
+M;gdb::unique_xmalloc_ptr<char>;make_corefile_notes;bfd *obfd, int *note_size;obfd, note_size
# Find core file memory regions
M;int;find_memory_regions;find_memory_region_ftype func, void *data;func, data
/* Write the file mapping data to the core file, if possible. OBFD is
the output BFD. NOTE_DATA is the current note data, and NOTE_SIZE
- is a pointer to the note size. Returns the new NOTE_DATA and
- updates NOTE_SIZE. */
+ is a pointer to the note size. Updates NOTE_DATA and NOTE_SIZE. */
-static char *
+static void
linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
- char *note_data, int *note_size)
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size)
{
struct linux_make_mappings_data mapping_data;
struct type *long_type
obstack_grow (&data_obstack, obstack_base (&filename_obstack),
size);
- note_data = elfcore_write_note (obfd, note_data, note_size,
- "CORE", NT_FILE,
- obstack_base (&data_obstack),
- obstack_object_size (&data_obstack));
+ note_data.reset (elfcore_write_note
+ (obfd, note_data.release (),
+ note_size, "CORE", NT_FILE,
+ obstack_base (&data_obstack),
+ obstack_object_size (&data_obstack)));
}
-
- return note_data;
}
/* Structure for passing information from
struct linux_collect_regset_section_cb_data
{
+ linux_collect_regset_section_cb_data (struct gdbarch *gdbarch,
+ const struct regcache *regcache,
+ bfd *obfd,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size,
+ unsigned long lwp,
+ gdb_signal stop_signal)
+ : gdbarch (gdbarch), regcache (regcache), obfd (obfd),
+ note_data (note_data), note_size (note_size), lwp (lwp),
+ stop_signal (stop_signal)
+ {}
+
struct gdbarch *gdbarch;
const struct regcache *regcache;
bfd *obfd;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> ¬e_data;
int *note_size;
unsigned long lwp;
enum gdb_signal stop_signal;
- int abort_iteration;
+ bool abort_iteration = false;
};
/* Callback for iterate_over_regset_sections that records a single
/* PRSTATUS still needs to be treated specially. */
if (strcmp (sect_name, ".reg") == 0)
- data->note_data = (char *) elfcore_write_prstatus
- (data->obfd, data->note_data, data->note_size, data->lwp,
- gdb_signal_to_host (data->stop_signal), buf.data ());
+ 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 = (char *) elfcore_write_register_note
- (data->obfd, data->note_data, data->note_size,
- sect_name, buf.data (), collect_size);
+ 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 == NULL)
- data->abort_iteration = 1;
+ data->abort_iteration = true;
}
/* Records the thread's register state for the corefile note
section. */
-static char *
+static void
linux_collect_thread_registers (const struct regcache *regcache,
ptid_t ptid, bfd *obfd,
- char *note_data, int *note_size,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size,
enum gdb_signal stop_signal)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct linux_collect_regset_section_cb_data data;
-
- data.gdbarch = gdbarch;
- data.regcache = regcache;
- data.obfd = obfd;
- data.note_data = note_data;
- data.note_size = note_size;
- data.stop_signal = stop_signal;
- data.abort_iteration = 0;
/* For remote targets the LWP may not be available, so use the TID. */
- data.lwp = ptid.lwp ();
- if (!data.lwp)
- data.lwp = ptid.tid ();
+ long lwp = ptid.lwp ();
+ if (lwp == 0)
+ lwp = ptid.tid ();
+
+ linux_collect_regset_section_cb_data data (gdbarch, regcache, obfd, note_data,
+ note_size, lwp, stop_signal);
gdbarch_iterate_over_regset_sections (gdbarch,
linux_collect_regset_section_cb,
&data, regcache);
- return data.note_data;
}
/* Fetch the siginfo data for the specified thread, if it exists. If
struct linux_corefile_thread_data
{
+ linux_corefile_thread_data (struct gdbarch *gdbarch, bfd *obfd,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size, gdb_signal stop_signal)
+ : gdbarch (gdbarch), obfd (obfd), note_data (note_data),
+ note_size (note_size), stop_signal (stop_signal)
+ {}
+
struct gdbarch *gdbarch;
bfd *obfd;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> ¬e_data;
int *note_size;
enum gdb_signal stop_signal;
};
target_fetch_registers (regcache, -1);
gdb::byte_vector siginfo_data = linux_get_siginfo_data (info, args->gdbarch);
- args->note_data = linux_collect_thread_registers
- (regcache, info->ptid, args->obfd, args->note_data,
- args->note_size, args->stop_signal);
+ linux_collect_thread_registers (regcache, info->ptid, args->obfd,
+ args->note_data, args->note_size,
+ args->stop_signal);
/* Don't return anything if we got no register information above,
such a core file is useless. */
if (args->note_data != NULL)
- if (!siginfo_data.empty ())
- args->note_data = elfcore_write_note (args->obfd,
- args->note_data,
- args->note_size,
- "CORE", NT_SIGINFO,
- siginfo_data.data (),
- siginfo_data.size ());
+ {
+ if (!siginfo_data.empty ())
+ args->note_data.reset (elfcore_write_note (args->obfd,
+ args->note_data.release (),
+ args->note_size,
+ "CORE", NT_SIGINFO,
+ siginfo_data.data (),
+ siginfo_data.size ()));
+ }
}
/* Fill the PRPSINFO structure with information about the process being
/* Build the note section for a corefile, and return it in a malloc
buffer. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
{
- struct linux_corefile_thread_data thread_args;
struct elf_internal_linux_prpsinfo prpsinfo;
- char *note_data = NULL;
+ gdb::unique_xmalloc_ptr<char> note_data;
if (! gdbarch_iterate_over_regset_sections_p (gdbarch))
return NULL;
if (linux_fill_prpsinfo (&prpsinfo))
{
if (gdbarch_ptr_bit (gdbarch) == 64)
- note_data = elfcore_write_linux_prpsinfo64 (obfd,
- note_data, note_size,
- &prpsinfo);
+ note_data.reset (elfcore_write_linux_prpsinfo64 (obfd,
+ note_data.release (),
+ note_size, &prpsinfo));
else
- note_data = elfcore_write_linux_prpsinfo32 (obfd,
- note_data, note_size,
- &prpsinfo);
+ note_data.reset (elfcore_write_linux_prpsinfo32 (obfd,
+ note_data.release (),
+ note_size, &prpsinfo));
}
/* Thread register information. */
"First thread" is what tools use to infer the signalled
thread. */
thread_info *signalled_thr = find_signalled_thread ();
-
- thread_args.gdbarch = gdbarch;
- thread_args.obfd = obfd;
- thread_args.note_data = note_data;
- thread_args.note_size = note_size;
+ gdb_signal stop_signal;
if (signalled_thr != nullptr)
- thread_args.stop_signal = signalled_thr->suspend.stop_signal;
+ stop_signal = signalled_thr->suspend.stop_signal;
else
- thread_args.stop_signal = GDB_SIGNAL_0;
+ stop_signal = GDB_SIGNAL_0;
+
+ linux_corefile_thread_data thread_args (gdbarch, obfd, note_data, note_size,
+ stop_signal);
if (signalled_thr != nullptr)
linux_corefile_thread (signalled_thr, &thread_args);
linux_corefile_thread (thr, &thread_args);
}
- note_data = thread_args.note_data;
if (!note_data)
return NULL;
target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
if (auxv && !auxv->empty ())
{
- note_data = elfcore_write_note (obfd, note_data, note_size,
- "CORE", NT_AUXV, auxv->data (),
- auxv->size ());
+ note_data.reset (elfcore_write_note (obfd, note_data.release (),
+ note_size, "CORE", NT_AUXV,
+ auxv->data (), auxv->size ()));
if (!note_data)
return NULL;
}
/* File mappings. */
- note_data = linux_make_mappings_corefile_notes (gdbarch, obfd,
- note_data, note_size);
+ linux_make_mappings_corefile_notes (gdbarch, obfd, note_data, note_size);
return note_data;
}