gdb: make target_ops::make_corefile_notes return a unique ptr

Since we converted gdbarch_make_corefile_notes to returning a
gdb::unique_xmalloc_ptr, I figured it would make sense to converted
target_ops::make_corefile_notes as well.

The only implementation of that is in procfs.c, and it should ideally be
re-written as a gdbarch method (see comment in write_gcore_file_1), but
in the mean time I guess it doesn't hurt to throw some unique pointer at
it.

I tested that it builds on Solaris 11 (gcc compile farm machine gcc211),
but I am not able to test it, because I can't get GDB to start a
process (I'll look at that separately).

gdb/ChangeLog:

	* 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.

Change-Id: I768fb17ac0f7adc67d2fe95e952c784fe0ac37ab
This commit is contained in:
Simon Marchi
2020-10-22 12:58:11 -04:00
committed by Simon Marchi
parent 5fb4027fae
commit 24f5300a53
8 changed files with 81 additions and 56 deletions

View File

@ -1,3 +1,24 @@
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> 2020-10-22 Tom de Vries <tdevries@suse.de>
* block.c (find_block_in_blockvector): Make sure the returned block * block.c (find_block_in_blockvector): Make sure the returned block

View File

@ -79,7 +79,7 @@ struct exec_target final : public target_ops
void files_info () override; void files_info () override;
bool has_memory () 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; int find_memory_regions (find_memory_region_ftype func, void *data) override;
}; };
@ -1089,7 +1089,7 @@ exec_target::has_memory ()
return !current_target_sections->empty (); return !current_target_sections->empty ();
} }
char * gdb::unique_xmalloc_ptr<char>
exec_target::make_corefile_notes (bfd *obfd, int *note_size) exec_target::make_corefile_notes (bfd *obfd, int *note_size)
{ {
error (_("Can't create a corefile")); error (_("Can't create a corefile"));

View File

@ -78,7 +78,7 @@ write_gcore_file_1 (bfd *obfd)
generation should be converted to gdbarch_make_corefile_notes; at that generation should be converted to gdbarch_make_corefile_notes; at that
point, the target vector method can be removed. */ point, the target vector method can be removed. */
if (!gdbarch_make_corefile_notes_p (target_gdbarch ())) if (!gdbarch_make_corefile_notes_p (target_gdbarch ()))
note_data.reset (target_make_corefile_notes (obfd, &note_size)); note_data = target_make_corefile_notes (obfd, &note_size);
else else
note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd, note_data = gdbarch_make_corefile_notes (target_gdbarch (), obfd,
&note_size); &note_size);

View File

@ -136,7 +136,7 @@ public:
int find_memory_regions (find_memory_region_ftype func, void *data) int find_memory_regions (find_memory_region_ftype func, void *data)
override; 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; bool info_proc (const char *, enum info_proc_what) override;
@ -3495,10 +3495,10 @@ procfs_first_available (void)
/* =================== GCORE .NOTE "MODULE" =================== */ /* =================== GCORE .NOTE "MODULE" =================== */
static char * static void
procfs_do_thread_registers (bfd *obfd, ptid_t ptid, procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
char *note_data, int *note_size, gdb::unique_xmalloc_ptr<char> &note_data,
enum gdb_signal stop_signal) int *note_size, enum gdb_signal stop_signal)
{ {
struct regcache *regcache = get_thread_regcache (&the_procfs_target, ptid); struct regcache *regcache = get_thread_regcache (&the_procfs_target, ptid);
gdb_gregset_t gregs; gdb_gregset_t gregs;
@ -3515,25 +3515,31 @@ procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
target_fetch_registers (regcache, -1); target_fetch_registers (regcache, -1);
fill_gregset (regcache, &gregs, -1); fill_gregset (regcache, &gregs, -1);
note_data = (char *) elfcore_write_lwpstatus (obfd, note_data.reset (elfcore_write_lwpstatus (obfd,
note_data, note_data.release (),
note_size, note_size,
merged_pid, merged_pid,
stop_signal, stop_signal,
&gregs); &gregs));
fill_fpregset (regcache, &fpregs, -1); fill_fpregset (regcache, &fpregs, -1);
note_data = (char *) elfcore_write_prfpreg (obfd, note_data.reset (elfcore_write_prfpreg (obfd,
note_data, note_data.release (),
note_size, note_size,
&fpregs, &fpregs,
sizeof (fpregs)); sizeof (fpregs)));
return note_data;
} }
struct procfs_corefile_thread_data { struct procfs_corefile_thread_data
{
procfs_corefile_thread_data (bfd *obfd,
gdb::unique_xmalloc_ptr<char> &note_data,
int *note_size, gdb_signal stop_signal)
: obfd (obfd), note_data (note_data), note_size (note_size),
stop_signal (stop_signal)
{}
bfd *obfd; bfd *obfd;
char *note_data; gdb::unique_xmalloc_ptr<char> &note_data;
int *note_size; int *note_size;
enum gdb_signal stop_signal; enum gdb_signal stop_signal;
}; };
@ -3548,7 +3554,7 @@ procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
{ {
ptid_t ptid = ptid_t (pi->pid, thread->tid, 0); ptid_t ptid = ptid_t (pi->pid, thread->tid, 0);
args->note_data = procfs_do_thread_registers (args->obfd, ptid, procfs_do_thread_registers (args->obfd, ptid,
args->note_data, args->note_data,
args->note_size, args->note_size,
args->stop_signal); args->stop_signal);
@ -3578,16 +3584,15 @@ find_stop_signal (void)
return GDB_SIGNAL_0; return GDB_SIGNAL_0;
} }
char * gdb::unique_xmalloc_ptr<char>
procfs_target::make_corefile_notes (bfd *obfd, int *note_size) procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
{ {
gdb_gregset_t gregs; gdb_gregset_t gregs;
char fname[16] = {'\0'}; char fname[16] = {'\0'};
char psargs[80] = {'\0'}; char psargs[80] = {'\0'};
procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 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; const char *inf_args;
struct procfs_corefile_thread_data thread_args;
enum gdb_signal stop_signal; enum gdb_signal stop_signal;
if (get_exec_file (0)) if (get_exec_file (0))
@ -3609,33 +3614,30 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
} }
} }
note_data = (char *) elfcore_write_prpsinfo (obfd, note_data.reset (elfcore_write_prpsinfo (obfd,
note_data, note_data.release (),
note_size, note_size,
fname, fname,
psargs); psargs));
stop_signal = find_stop_signal (); stop_signal = find_stop_signal ();
fill_gregset (get_current_regcache (), &gregs, -1); fill_gregset (get_current_regcache (), &gregs, -1);
note_data = elfcore_write_pstatus (obfd, note_data, note_size, note_data.reset (elfcore_write_pstatus (obfd, note_data.release (), note_size,
inferior_ptid.pid (), inferior_ptid.pid (),
stop_signal, &gregs); stop_signal, &gregs));
thread_args.obfd = obfd; procfs_corefile_thread_data thread_args (obfd, note_data, note_size,
thread_args.note_data = note_data; stop_signal);
thread_args.note_size = note_size;
thread_args.stop_signal = stop_signal;
proc_iterate_over_threads (pi, procfs_corefile_thread_callback, proc_iterate_over_threads (pi, procfs_corefile_thread_callback,
&thread_args); &thread_args);
note_data = thread_args.note_data;
gdb::optional<gdb::byte_vector> auxv = gdb::optional<gdb::byte_vector> auxv =
target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL); target_read_alloc (current_top_target (), TARGET_OBJECT_AUXV, NULL);
if (auxv && !auxv->empty ()) if (auxv && !auxv->empty ())
note_data = elfcore_write_note (obfd, note_data, note_size, note_data.reset (elfcore_write_note (obfd, note_data.release (), note_size,
"CORE", NT_AUXV, auxv->data (), "CORE", NT_AUXV, auxv->data (),
auxv->size ()); auxv->size ()));
return note_data; return note_data;
} }

View File

@ -188,6 +188,8 @@
target_debug_do_print ((X).c_str ()) target_debug_do_print ((X).c_str ())
#define target_debug_print_gdb_byte_vector(X) \ #define target_debug_print_gdb_byte_vector(X) \
target_debug_do_print (host_address_to_string (X.data ())) 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 static void
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status) target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)

View File

@ -88,7 +88,7 @@ struct dummy_target : public target_ops
bool supports_non_stop () override; bool supports_non_stop () override;
bool always_non_stop_p () override; bool always_non_stop_p () override;
int find_memory_regions (find_memory_region_ftype arg0, void *arg1) 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; gdb_byte *get_bookmark (const char *arg0, int arg1) override;
void goto_bookmark (const gdb_byte *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; CORE_ADDR get_thread_local_address (ptid_t arg0, CORE_ADDR arg1, CORE_ADDR arg2) override;
@ -259,7 +259,7 @@ struct debug_target : public target_ops
bool supports_non_stop () override; bool supports_non_stop () override;
bool always_non_stop_p () override; bool always_non_stop_p () override;
int find_memory_regions (find_memory_region_ftype arg0, void *arg1) 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; gdb_byte *get_bookmark (const char *arg0, int arg1) override;
void goto_bookmark (const gdb_byte *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; CORE_ADDR get_thread_local_address (ptid_t arg0, CORE_ADDR arg1, CORE_ADDR arg2) override;
@ -2292,22 +2292,22 @@ debug_target::find_memory_regions (find_memory_region_ftype arg0, void *arg1)
return result; return result;
} }
char * gdb::unique_xmalloc_ptr<char>
target_ops::make_corefile_notes (bfd *arg0, int *arg1) target_ops::make_corefile_notes (bfd *arg0, int *arg1)
{ {
return this->beneath ()->make_corefile_notes (arg0, arg1); return this->beneath ()->make_corefile_notes (arg0, arg1);
} }
char * gdb::unique_xmalloc_ptr<char>
dummy_target::make_corefile_notes (bfd *arg0, int *arg1) dummy_target::make_corefile_notes (bfd *arg0, int *arg1)
{ {
return dummy_make_corefile_notes (this, arg0, arg1); return dummy_make_corefile_notes (this, arg0, arg1);
} }
char * gdb::unique_xmalloc_ptr<char>
debug_target::make_corefile_notes (bfd *arg0, int *arg1) 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 ()); fprintf_unfiltered (gdb_stdlog, "-> %s->make_corefile_notes (...)\n", this->beneath ()->shortname ());
result = this->beneath ()->make_corefile_notes (arg0, arg1); result = this->beneath ()->make_corefile_notes (arg0, arg1);
fprintf_unfiltered (gdb_stdlog, "<- %s->make_corefile_notes (", this->beneath ()->shortname ()); fprintf_unfiltered (gdb_stdlog, "<- %s->make_corefile_notes (", this->beneath ()->shortname ());
@ -2315,7 +2315,7 @@ debug_target::make_corefile_notes (bfd *arg0, int *arg1)
fputs_unfiltered (", ", gdb_stdlog); fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_int_p (arg1); target_debug_print_int_p (arg1);
fputs_unfiltered (") = ", gdb_stdlog); fputs_unfiltered (") = ", gdb_stdlog);
target_debug_print_char_p (result); target_debug_print_gdb_unique_xmalloc_ptr_char (result);
fputs_unfiltered ("\n", gdb_stdlog); fputs_unfiltered ("\n", gdb_stdlog);
return result; return result;
} }

View File

@ -89,8 +89,8 @@ static int dummy_find_memory_regions (struct target_ops *self,
find_memory_region_ftype ignore1, find_memory_region_ftype ignore1,
void *ignore2); void *ignore2);
static char *dummy_make_corefile_notes (struct target_ops *self, static gdb::unique_xmalloc_ptr<char> dummy_make_corefile_notes
bfd *ignore1, int *ignore2); (struct target_ops *self, bfd *ignore1, int *ignore2);
static std::string default_pid_to_str (struct target_ops *ops, ptid_t ptid); static std::string default_pid_to_str (struct target_ops *ops, ptid_t ptid);
@ -3058,7 +3058,7 @@ dummy_find_memory_regions (struct target_ops *self,
} }
/* Error-catcher for target_make_corefile_notes. */ /* Error-catcher for target_make_corefile_notes. */
static char * static gdb::unique_xmalloc_ptr<char>
dummy_make_corefile_notes (struct target_ops *self, dummy_make_corefile_notes (struct target_ops *self,
bfd *ignore1, int *ignore2) bfd *ignore1, int *ignore2)
{ {

View File

@ -719,7 +719,7 @@ struct target_ops
virtual int find_memory_regions (find_memory_region_ftype func, void *data) virtual int find_memory_regions (find_memory_region_ftype func, void *data)
TARGET_DEFAULT_FUNC (dummy_find_memory_regions); TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
/* make_corefile_notes support method for gcore */ /* 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); TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
/* get_bookmark support method for bookmarks */ /* get_bookmark support method for bookmarks */
virtual gdb_byte *get_bookmark (const char *, int) virtual gdb_byte *get_bookmark (const char *, int)