aboutsummaryrefslogtreecommitdiff
path: root/gdb/procfs.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-10-22 12:58:11 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2020-10-22 12:58:21 -0400
commit24f5300a537e0a8b31ec0391e45babf8a160ce56 (patch)
tree97af2a3c43eae11d3dcb217e67bf669969d3a6f8 /gdb/procfs.c
parent5fb4027fae1839cabbea75112c31bd89d46d2af0 (diff)
downloadbinutils-24f5300a537e0a8b31ec0391e45babf8a160ce56.zip
binutils-24f5300a537e0a8b31ec0391e45babf8a160ce56.tar.gz
binutils-24f5300a537e0a8b31ec0391e45babf8a160ce56.tar.bz2
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
Diffstat (limited to 'gdb/procfs.c')
-rw-r--r--gdb/procfs.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 31f33fe..0b66a21 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -136,7 +136,7 @@ public:
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;
@@ -3495,10 +3495,10 @@ procfs_first_available (void)
/* =================== 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> &note_data,
+ int *note_size, enum gdb_signal stop_signal)
{
struct regcache *regcache = get_thread_regcache (&the_procfs_target, ptid);
gdb_gregset_t gregs;
@@ -3515,25 +3515,31 @@ procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
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> &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;
- char *note_data;
+ gdb::unique_xmalloc_ptr<char> &note_data;
int *note_size;
enum gdb_signal stop_signal;
};
@@ -3548,10 +3554,10 @@ procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
{
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;
}
@@ -3578,16 +3584,15 @@ find_stop_signal (void)
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))
@@ -3609,33 +3614,30 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
}
}
- 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;
}