+2020-10-22 Simon Marchi <simon.marchi@efficios.com>
+
+ * target.h (struct target_ops) <make_corefile_notes>:
+ Change return type to unique pointer.
+ * target.c (dummy_make_corefile_notes): Likewise.
+ * exec.c (struct exec_target) <make_corefile_notes>:
+ Likewise.
+ (exec_target::make_corefile_notes): Likewise.
+ * procfs.c (class procfs_target) <make_corefile_notes>:
+ Likewise.
+ (procfs_do_thread_registers): Adjust to unique pointer.
+ (struct procfs_corefile_thread_data): Add constructor.
+ <note_data>: Change type to unique pointer.
+ (procfs_corefile_thread_callback): Adjust to unique pointer.
+ (procfs_target::make_corefile_notes): Change return type to
+ unique pointer.
+ * target-delegates.c: Re-generate.
+ * gcore.c (write_gcore_file_1): Adjust.
+ * target-debug.h (target_debug_print_gdb_unique_xmalloc_ptr_char):
+ New.
+
2020-10-22 Tom de Vries <tdevries@suse.de>
* block.c (find_block_in_blockvector): Make sure the returned block
void files_info () override;
bool has_memory () override;
- char *make_corefile_notes (bfd *, int *) override;
+ gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override;
int find_memory_regions (find_memory_region_ftype func, void *data) override;
};
return !current_target_sections->empty ();
}
-char *
+gdb::unique_xmalloc_ptr<char>
exec_target::make_corefile_notes (bfd *obfd, int *note_size)
{
error (_("Can't create a corefile"));
generation should be converted to gdbarch_make_corefile_notes; at that
point, the target vector method can be removed. */
if (!gdbarch_make_corefile_notes_p (target_gdbarch ()))
- note_data.reset (target_make_corefile_notes (obfd, ¬e_size));
+ note_data = target_make_corefile_notes (obfd, ¬e_size);
else
note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd,
¬e_size);
int find_memory_regions (find_memory_region_ftype func, void *data)
override;
- char *make_corefile_notes (bfd *, int *) override;
+ gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *) override;
bool info_proc (const char *, enum info_proc_what) override;
/* =================== GCORE .NOTE "MODULE" =================== */
-static char *
+static void
procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
- char *note_data, int *note_size,
- enum gdb_signal stop_signal)
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size, enum gdb_signal stop_signal)
{
struct regcache *regcache = get_thread_regcache (&the_procfs_target, ptid);
gdb_gregset_t gregs;
target_fetch_registers (regcache, -1);
fill_gregset (regcache, &gregs, -1);
- note_data = (char *) elfcore_write_lwpstatus (obfd,
- note_data,
- note_size,
- merged_pid,
- stop_signal,
- &gregs);
+ note_data.reset (elfcore_write_lwpstatus (obfd,
+ note_data.release (),
+ note_size,
+ merged_pid,
+ stop_signal,
+ &gregs));
fill_fpregset (regcache, &fpregs, -1);
- note_data = (char *) elfcore_write_prfpreg (obfd,
- note_data,
- note_size,
- &fpregs,
- sizeof (fpregs));
-
- return note_data;
+ note_data.reset (elfcore_write_prfpreg (obfd,
+ note_data.release (),
+ note_size,
+ &fpregs,
+ sizeof (fpregs)));
}
-struct procfs_corefile_thread_data {
+struct procfs_corefile_thread_data
+{
+ procfs_corefile_thread_data (bfd *obfd,
+ gdb::unique_xmalloc_ptr<char> ¬e_data,
+ int *note_size, gdb_signal stop_signal)
+ : obfd (obfd), note_data (note_data), note_size (note_size),
+ stop_signal (stop_signal)
+ {}
+
bfd *obfd;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> ¬e_data;
int *note_size;
enum gdb_signal stop_signal;
};
{
ptid_t ptid = ptid_t (pi->pid, thread->tid, 0);
- args->note_data = procfs_do_thread_registers (args->obfd, ptid,
- args->note_data,
- args->note_size,
- args->stop_signal);
+ procfs_do_thread_registers (args->obfd, ptid,
+ args->note_data,
+ args->note_size,
+ args->stop_signal);
}
return 0;
}
return GDB_SIGNAL_0;
}
-char *
+gdb::unique_xmalloc_ptr<char>
procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
{
gdb_gregset_t gregs;
char fname[16] = {'\0'};
char psargs[80] = {'\0'};
procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
- char *note_data = NULL;
+ gdb::unique_xmalloc_ptr<char> note_data;
const char *inf_args;
- struct procfs_corefile_thread_data thread_args;
enum gdb_signal stop_signal;
if (get_exec_file (0))
}
}
- note_data = (char *) elfcore_write_prpsinfo (obfd,
- note_data,
- note_size,
- fname,
- psargs);
+ note_data.reset (elfcore_write_prpsinfo (obfd,
+ note_data.release (),
+ note_size,
+ fname,
+ psargs));
stop_signal = find_stop_signal ();
fill_gregset (get_current_regcache (), &gregs, -1);
- note_data = elfcore_write_pstatus (obfd, note_data, note_size,
- inferior_ptid.pid (),
- stop_signal, &gregs);
-
- thread_args.obfd = obfd;
- thread_args.note_data = note_data;
- thread_args.note_size = note_size;
- thread_args.stop_signal = stop_signal;
+ note_data.reset (elfcore_write_pstatus (obfd, note_data.release (), note_size,
+ inferior_ptid.pid (),
+ stop_signal, &gregs));
+
+ procfs_corefile_thread_data thread_args (obfd, note_data, note_size,
+ stop_signal);
proc_iterate_over_threads (pi, procfs_corefile_thread_callback,
&thread_args);
- note_data = thread_args.note_data;
gdb::optional<gdb::byte_vector> auxv =
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 ()));
return note_data;
}
target_debug_do_print ((X).c_str ())
#define target_debug_print_gdb_byte_vector(X) \
target_debug_do_print (host_address_to_string (X.data ()))
+#define target_debug_print_gdb_unique_xmalloc_ptr_char(X) \
+ target_debug_do_print (X.get ())
static void
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
bool supports_non_stop () override;
bool always_non_stop_p () override;
int find_memory_regions (find_memory_region_ftype arg0, void *arg1) override;
- char *make_corefile_notes (bfd *arg0, int *arg1) override;
+ gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override;
gdb_byte *get_bookmark (const char *arg0, int arg1) override;
void goto_bookmark (const gdb_byte *arg0, int arg1) override;
CORE_ADDR get_thread_local_address (ptid_t arg0, CORE_ADDR arg1, CORE_ADDR arg2) override;
bool supports_non_stop () override;
bool always_non_stop_p () override;
int find_memory_regions (find_memory_region_ftype arg0, void *arg1) override;
- char *make_corefile_notes (bfd *arg0, int *arg1) override;
+ gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *arg0, int *arg1) override;
gdb_byte *get_bookmark (const char *arg0, int arg1) override;
void goto_bookmark (const gdb_byte *arg0, int arg1) override;
CORE_ADDR get_thread_local_address (ptid_t arg0, CORE_ADDR arg1, CORE_ADDR arg2) override;
return result;
}
-char *
+gdb::unique_xmalloc_ptr<char>
target_ops::make_corefile_notes (bfd *arg0, int *arg1)
{
return this->beneath ()->make_corefile_notes (arg0, arg1);
}
-char *
+gdb::unique_xmalloc_ptr<char>
dummy_target::make_corefile_notes (bfd *arg0, int *arg1)
{
return dummy_make_corefile_notes (this, arg0, arg1);
}
-char *
+gdb::unique_xmalloc_ptr<char>
debug_target::make_corefile_notes (bfd *arg0, int *arg1)
{
- char * result;
+ gdb::unique_xmalloc_ptr<char> result;
fprintf_unfiltered (gdb_stdlog, "-> %s->make_corefile_notes (...)\n", this->beneath ()->shortname ());
result = this->beneath ()->make_corefile_notes (arg0, arg1);
fprintf_unfiltered (gdb_stdlog, "<- %s->make_corefile_notes (", this->beneath ()->shortname ());
fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_int_p (arg1);
fputs_unfiltered (") = ", gdb_stdlog);
- target_debug_print_char_p (result);
+ target_debug_print_gdb_unique_xmalloc_ptr_char (result);
fputs_unfiltered ("\n", gdb_stdlog);
return result;
}
find_memory_region_ftype ignore1,
void *ignore2);
-static char *dummy_make_corefile_notes (struct target_ops *self,
- bfd *ignore1, int *ignore2);
+static gdb::unique_xmalloc_ptr<char> dummy_make_corefile_notes
+ (struct target_ops *self, bfd *ignore1, int *ignore2);
static std::string default_pid_to_str (struct target_ops *ops, ptid_t ptid);
}
/* Error-catcher for target_make_corefile_notes. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
dummy_make_corefile_notes (struct target_ops *self,
bfd *ignore1, int *ignore2)
{
virtual int find_memory_regions (find_memory_region_ftype func, void *data)
TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
/* make_corefile_notes support method for gcore */
- virtual char *make_corefile_notes (bfd *, int *)
+ virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *)
TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
/* get_bookmark support method for bookmarks */
virtual gdb_byte *get_bookmark (const char *, int)