From c21f37a889dbf57077981970a1b6167a0dcb39af Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 21 Oct 2020 10:43:48 -0400 Subject: gdb: make gdbarch_make_corefile_notes return a unique ptr This patch starts by making the gdbarch_make_corefile_notes function return a gdb::unique_xmalloc_ptr and takes care of the fallouts, mostly in linux-tdep.c and fbsd-tdep.c. The difficulty in these files is that they use the BFD API for writing core files, where you pass in a pointer to a malloc-ed buffer (or NULL in the beginning), it re-allocs it if needed, and returns you the possibly updated pointer. I therefore used this pattern everywhere: note_data.reset (elfcore_write_note (obfd, note_data.release (), ...) This hands over the ownership of note_data to the BFD function for the duration of the call, and then puts its back in note_data right after the call. gdb/ChangeLog: * 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. : Change type to unique pointer. : 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. : 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. : Change type to unique pointer. : Change type to bool. (linux_collect_thread_registers): Return void, adjust. (struct linux_corefile_thread_data): Add constructor. : Change type to unique pointer. (linux_corefile_thread): Adjust. (linux_make_corefile_notes): Return unique pointer, adjust. Change-Id: I1e03476bb47b87c6acb3e12204d193f38cc4e02b --- gdb/gdbarch.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gdb/gdbarch.h') diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index d126dfc..ae65f29 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -912,8 +912,8 @@ extern void set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, g 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 (gdbarch_make_corefile_notes_ftype) (struct gdbarch *gdbarch, bfd *obfd, int *note_size); +extern gdb::unique_xmalloc_ptr 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 */ -- cgit v1.1