public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: define type aliases for `fork_inferior()` callbacks
@ 2024-05-16 16:55 Simon Marchi
  2024-05-16 18:43 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2024-05-16 16:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

The `fork_inferior()` function accepts multiple callbacks, making its
signature a bit hard to read.  Define some type aliases to make it a bit
clearer.  Use function view for all, while at it.

Change-Id: Ide8d1fa533d0c5eaf3249860f8c0d339baa09bce
---
 gdb/nat/fork-inferior.c | 15 ++++++---------
 gdb/nat/fork-inferior.h | 18 ++++++++++++------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 4378177bc8c4..c1082eb04411 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -266,12 +266,9 @@ execv_argv::init_for_shell (const char *exec_file,
 
 pid_t
 fork_inferior (const char *exec_file_arg, const std::string &allargs,
-	       char **env, void (*traceme_fun) (),
-	       gdb::function_view<void (int)> init_trace_fun,
-	       void (*pre_trace_fun) (),
-	       const char *shell_file_arg,
-	       void (*exec_fun)(const char *file, char * const *argv,
-				char * const *env))
+	       char **env, traceme_ftype traceme_fun,
+	       init_trace_ftype init_trace_fun, pre_trace_ftype pre_trace_fun,
+	       const char *shell_file_arg, exec_ftype exec_fun)
 {
   pid_t pid;
   /* Set debug_fork then attach to the child while it sleeps, to debug.  */
@@ -337,7 +334,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
      happen to prepare to handle the child we're about fork, do it
      now...  */
   if (pre_trace_fun != NULL)
-    (*pre_trace_fun) ();
+    pre_trace_fun ();
 
   /* Create the child process.  Since the child process is going to
      exec(3) shortly afterwards, try to reduce the overhead by
@@ -389,7 +386,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
 	 for the inferior.  */
 
       /* "Trace me, Dr. Memory!"  */
-      (*traceme_fun) ();
+      traceme_fun ();
 
       /* The call above set this process (the "child") as debuggable
 	by the original gdb process (the "parent").  Since processes
@@ -412,7 +409,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
       char **argv = child_argv.argv ();
 
       if (exec_fun != NULL)
-	(*exec_fun) (argv[0], &argv[0], env);
+	exec_fun (argv[0], &argv[0], env);
       else
 	execvp (argv[0], &argv[0]);
 
diff --git a/gdb/nat/fork-inferior.h b/gdb/nat/fork-inferior.h
index a609f68bcb44..f3e2f54b4e92 100644
--- a/gdb/nat/fork-inferior.h
+++ b/gdb/nat/fork-inferior.h
@@ -31,6 +31,13 @@ struct process_stratum_target;
    implementations.  */
 #define START_INFERIOR_TRAPS_EXPECTED 1
 
+using traceme_ftype = gdb::function_view<void ()>;
+using init_trace_ftype = gdb::function_view<void (int /* pid */)>;
+using pre_trace_ftype = gdb::function_view<void ()>;
+using exec_ftype = gdb::function_view<void (const char * /* file */,
+					    char * const * /* argv */,
+					    char * const * /* env */)>;
+
 /* Start an inferior Unix child process and sets inferior_ptid to its
    pid.  EXEC_FILE is the file to run.  ALLARGS is a string containing
    the arguments to the program.  ENV is the environment vector to
@@ -42,13 +49,12 @@ struct process_stratum_target;
    made static to ensure that they survive the vfork call.  */
 extern pid_t fork_inferior (const char *exec_file_arg,
 			    const std::string &allargs,
-			    char **env, void (*traceme_fun) (),
-			    gdb::function_view<void (int)> init_trace_fun,
-			    void (*pre_trace_fun) (),
+			    char **env,
+			    traceme_ftype traceme_fun,
+			    init_trace_ftype init_trace_fun,
+			    pre_trace_ftype pre_trace_fun,
 			    const char *shell_file_arg,
-			    void (*exec_fun) (const char *file,
-					      char * const *argv,
-					      char * const *env));
+			    exec_ftype exec_fun);
 
 /* Accept NTRAPS traps from the inferior.
 

base-commit: f6bbac3f2e3e448e32dc15e8a0d25141e97d9729
-- 
2.45.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: define type aliases for `fork_inferior()` callbacks
  2024-05-16 16:55 [PATCH] gdb: define type aliases for `fork_inferior()` callbacks Simon Marchi
@ 2024-05-16 18:43 ` Tom Tromey
  2024-05-16 19:10   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2024-05-16 18:43 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> The `fork_inferior()` function accepts multiple callbacks, making its
Simon> signature a bit hard to read.  Define some type aliases to make it a bit
Simon> clearer.  Use function view for all, while at it.

Looks good to me.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: define type aliases for `fork_inferior()` callbacks
  2024-05-16 18:43 ` Tom Tromey
@ 2024-05-16 19:10   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2024-05-16 19:10 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches



On 2024-05-16 14:43, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> The `fork_inferior()` function accepts multiple callbacks, making its
> Simon> signature a bit hard to read.  Define some type aliases to make it a bit
> Simon> clearer.  Use function view for all, while at it.
> 
> Looks good to me.  Thank you.
> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-16 19:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16 16:55 [PATCH] gdb: define type aliases for `fork_inferior()` callbacks Simon Marchi
2024-05-16 18:43 ` Tom Tromey
2024-05-16 19:10   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).