aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-02-23 13:10:28 -0700
committerTom Tromey <tromey@adacore.com>2024-02-27 10:30:29 -0700
commit1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d (patch)
treedc0770a269e741138de98fda6ea6cb4c8c179ce1 /gdb
parentcfe51255b892962c25166cc0afd8911caf9e1e56 (diff)
downloadbinutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.zip
binutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.tar.gz
binutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.tar.bz2
Rewrite final cleanups
This patch rewrites final cleanups to use std::function and otherwise be more C++-ish.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/compile/compile.c30
-rw-r--r--gdb/debuginfod-support.c14
-rw-r--r--gdb/python/python.c4
3 files changed, 18 insertions, 30 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8cb2e8ac..27cff25 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -427,23 +427,6 @@ compile_print_command (const char *arg, int from_tty)
}
}
-/* A cleanup function to remove a directory and all its contents. */
-
-static void
-do_rmdir (void *arg)
-{
- const char *dir = (const char *) arg;
- char *zap;
- int wstat;
-
- gdb_assert (startswith (dir, TMP_PREFIX));
- zap = concat ("rm -rf ", dir, (char *) NULL);
- wstat = system (zap);
- if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
- warning (_("Could not remove temporary directory %s"), dir);
- XDELETEVEC (zap);
-}
-
/* Return the name of the temporary directory to use for .o files, and
arrange for the directory to be removed at shutdown. */
@@ -465,7 +448,18 @@ get_compile_file_tempdir (void)
perror_with_name (_("Could not make temporary directory"));
tempdir_name = xstrdup (tempdir_name);
- make_final_cleanup (do_rmdir, tempdir_name);
+ add_final_cleanup ([] ()
+ {
+ char *zap;
+ int wstat;
+
+ gdb_assert (startswith (tempdir_name, TMP_PREFIX));
+ zap = concat ("rm -rf ", tempdir_name, (char *) NULL);
+ wstat = system (zap);
+ if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
+ warning (_("Could not remove temporary directory %s"), tempdir_name);
+ XDELETEVEC (zap);
+ });
return tempdir_name;
}
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 7d8ada3..9bb3748 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -188,15 +188,6 @@ progressfn (debuginfod_client *c, long cur, long total)
return 0;
}
-/* Cleanup ARG, which is a debuginfod_client pointer. */
-
-static void
-cleanup_debuginfod_client (void *arg)
-{
- debuginfod_client *client = static_cast<debuginfod_client *> (arg);
- debuginfod_end (client);
-}
-
/* Return a pointer to the single global debuginfod_client, initialising it
first if needed. */
@@ -221,7 +212,10 @@ get_debuginfod_client ()
handlers, which is too late.
So instead, we make use of GDB's final cleanup mechanism. */
- make_final_cleanup (cleanup_debuginfod_client, global_client);
+ add_final_cleanup ([] ()
+ {
+ debuginfod_end (global_client);
+ });
debuginfod_set_progressfn (global_client, progressfn);
}
}
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8aa674c..8f8ee7c 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -2057,7 +2057,7 @@ static struct cmd_list_element *user_show_python_list;
interpreter. This lets Python's 'atexit' work. */
static void
-finalize_python (void *ignore)
+finalize_python ()
{
struct active_ext_lang_state *previous_active;
@@ -2297,7 +2297,7 @@ init_done:
/* Release the GIL while gdb runs. */
PyEval_SaveThread ();
- make_final_cleanup (finalize_python, NULL);
+ add_final_cleanup (finalize_python);
/* Only set this when initialization has succeeded. */
gdb_python_initialized = 1;