gdb: make gdbarch_make_corefile_notes return a unique ptr
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 21 Oct 2020 14:43:48 +0000 (10:43 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 21 Oct 2020 14:43:48 +0000 (10:43 -0400)
commitc21f37a889dbf57077981970a1b6167a0dcb39af
tree9fb1572976cf1664ed89cb7749d7b706c5edf6d7
parent4dbe16c8115cd9820cadba5300cbfe04f518269f
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<char> 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.
<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.

Change-Id: I1e03476bb47b87c6acb3e12204d193f38cc4e02b
gdb/ChangeLog
gdb/fbsd-tdep.c
gdb/gcore.c
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/linux-tdep.c
This page took 0.025198 seconds and 4 git commands to generate.