public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix -Wdeprecated-declarations on macOS
@ 2023-03-28 14:16 Enze Li
  2023-03-28 14:55 ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Enze Li @ 2023-03-28 14:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: enze.li

I noticed that there are some issues when compiling on macOS.  There are
a few places where errors like the following are reported,

======
  CXX    cli/cli-cmds.o
cli/cli-cmds.c:929:14: error: 'vfork' is deprecated: Use posix_spawn or fork [-Werror,-Wdeprecated-declarations]
  if ((pid = vfork ()) == 0)
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:604:1: note: 'vfork' has been explicitly marked deprecated here
__deprecated_msg("Use posix_spawn or fork")
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:208:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
1 error generated.
======

This patch is only available for the macOS platform.  This is done by
using macros to differentiate between specific platforms.

Tested by rebuilding both on x86_64 linux and macOS Big Sur.
---
 gdb/cli/cli-cmds.c      | 4 ++++
 gdb/nat/fork-inferior.c | 4 ++++
 gdb/ser-pipe.c          | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0c680896c917..a1eac4c024f4 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -926,7 +926,11 @@ run_under_shell (const char *arg, int from_tty)
 #else /* Can fork.  */
   int status, pid;
 
+#ifdef __APPLE__
+  if ((pid = fork ()) == 0)
+#else
   if ((pid = vfork ()) == 0)
+#endif
     {
       const char *p, *user_shell = get_shell ();
 
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 968983b20215..a9324a550011 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -355,7 +355,11 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
     pid = fork ();
   else
 #endif
+#ifndef __APPLE__
     pid = vfork ();
+#else
+    pid = fork();
+#endif
 
   if (pid < 0)
     perror_with_name (("vfork"));
diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c
index 47ccd33cece3..2e9bfe0c0ceb 100644
--- a/gdb/ser-pipe.c
+++ b/gdb/ser-pipe.c
@@ -81,7 +81,11 @@ pipe_open (struct serial *scb, const char *name)
      apparent call to vfork() below *might* actually be a call to
      fork() due to the fact that autoconf will ``#define vfork fork''
      on certain platforms.  */
+#ifndef __APPLE__
   pid = vfork ();
+#else
+  pid = fork ();
+#endif
   
   /* Error.  */
   if (pid == -1)
-- 
2.39.1


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

end of thread, other threads:[~2023-03-28 17:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 14:16 [PATCH] gdb: fix -Wdeprecated-declarations on macOS Enze Li
2023-03-28 14:55 ` Simon Marchi
2023-03-28 15:10   ` John Baldwin
2023-03-28 15:57     ` Tom Tromey
2023-03-28 16:01     ` Simon Marchi
2023-03-28 17:52       ` John Baldwin
2023-03-28 17:57         ` John Baldwin

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