diff options
author | Tom Tromey <tom@tromey.com> | 2018-08-29 22:49:40 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-13 16:22:33 -0600 |
commit | 5b4cbbe357aaf6462a68e1a15c9532dd3d01e06d (patch) | |
tree | f20fe4ea62b8bc633666f1c788a65cb75d696bda /gdb | |
parent | db68fbe2f946cb36359c8672548fde198f812c4e (diff) | |
download | gdb-5b4cbbe357aaf6462a68e1a15c9532dd3d01e06d.zip gdb-5b4cbbe357aaf6462a68e1a15c9532dd3d01e06d.tar.gz gdb-5b4cbbe357aaf6462a68e1a15c9532dd3d01e06d.tar.bz2 |
Remove cleanup from procfs.c
This removes the last remaining cleanup from procfs.c, replacing it
with a unique_ptr specialization.
gdb/ChangeLog
2018-09-13 Tom Tromey <tom@tromey.com>
* procfs.c (struct procinfo_deleter): New.
(procinfo_up): New typedef.
(do_destroy_procinfo_cleanup): Remove.
(procfs_target::info_proc): Use procinfo_up. Remove cleanups.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/procfs.c | 22 |
2 files changed, 19 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2f4d94d..7351e5d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2018-09-13 Tom Tromey <tom@tromey.com> + * procfs.c (struct procinfo_deleter): New. + (procinfo_up): New typedef. + (do_destroy_procinfo_cleanup): Remove. + (procfs_target::info_proc): Use procinfo_up. Remove cleanups. + +2018-09-13 Tom Tromey <tom@tromey.com> + * source.c (add_path): Use gdb::unique_xmalloc_ptr. 2018-09-13 Simon Marchi <simon.marchi@ericsson.com> diff --git a/gdb/procfs.c b/gdb/procfs.c index ec34650..81a4900 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -272,7 +272,6 @@ static procinfo *find_procinfo_or_die (int pid, int tid); static procinfo *find_procinfo (int pid, int tid); static procinfo *create_procinfo (int pid, int tid); static void destroy_procinfo (procinfo *p); -static void do_destroy_procinfo_cleanup (void *); static void dead_procinfo (procinfo *p, const char *msg, int killp); static int open_procinfo_files (procinfo *p, int which); static void close_procinfo_files (procinfo *p); @@ -549,11 +548,16 @@ destroy_procinfo (procinfo *pi) } } -static void -do_destroy_procinfo_cleanup (void *pi) +/* A deleter that calls destroy_procinfo. */ +struct procinfo_deleter { - destroy_procinfo ((procinfo *) pi); -} + void operator() (procinfo *pi) const + { + destroy_procinfo (pi); + } +}; + +typedef std::unique_ptr<procinfo, procinfo_deleter> procinfo_up; enum { NOKILL, KILL }; @@ -3545,7 +3549,6 @@ info_proc_mappings (procinfo *pi, int summary) bool procfs_target::info_proc (const char *args, enum info_proc_what what) { - struct cleanup *old_chain; procinfo *process = NULL; procinfo *thread = NULL; char *tmp = NULL; @@ -3567,7 +3570,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) error (_("Not supported on this target.")); } - old_chain = make_cleanup (null_cleanup, 0); gdb_argv built_argv (args); for (char *arg : built_argv) { @@ -3582,6 +3584,8 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) tid = strtoul (arg + 1, NULL, 10); } } + + procinfo_up temporary_procinfo; if (pid == 0) pid = inferior_ptid.pid (); if (pid == 0) @@ -3596,7 +3600,7 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) /* No. So open a procinfo for it, but remember to close it again when finished. */ process = create_procinfo (pid, 0); - make_cleanup (do_destroy_procinfo_cleanup, process); + temporary_procinfo.reset (process); if (!open_procinfo_files (process, FD_CTL)) proc_error (process, "info proc, open_procinfo_files", __LINE__); } @@ -3627,8 +3631,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what) info_proc_mappings (process, 0); } - do_cleanups (old_chain); - return true; } |