Skip to content

Commit

Permalink
[gdb/build] Fix build breaker on mingw-w64
Browse files Browse the repository at this point in the history
The mingw-w64 build breaks currently:
...
    In file included from gdb/cli/cli-cmds.c:58:
    gdbsupport/eintr.h: In function ‘pid_t gdb::waitpid(pid_t, int*, int)’:
    gdbsupport/eintr.h:77:35: error: ‘::waitpid’ has not been declared; \
                                     did you mean ‘gdb::waitpid’?
       77 |   return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
          |                                   ^~~~~~~
          |                                   gdb::waitpid
    gdbsupport/eintr.h:75:1: note: ‘gdb::waitpid’ declared here
       75 | waitpid (pid_t pid, int *wstatus, int options)
          | ^~~~~~~
...

This is a regression since commit 658a03e ("[gdbsupport] Add
gdb::{waitpid,read,write,close}"), which moved the use of ::waitpid from
run_under_shell, where it was used conditionally:
...
 #if defined(CANT_FORK) || \
       (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
   ...
 #else
   ...
       int ret = gdb::handle_eintr (-1, ::waitpid, pid, &status, 0);
...
to gdb::waitpid, where it's used unconditionally:
...
inline pid_t
waitpid (pid_t pid, int *wstatus, int options)
{
  return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
}
...

Likewise for ::wait.

Guard these uses with HAVE_WAITPID and HAVE_WAIT.

Reproduced and tested by doing a mingw-w64 cross-build on x86_64-linux.

Reported-By: Simon Marchi <simark@simark.ca>
Co-Authored-By: Tom de Vries <tdevries@suse.de>
  • Loading branch information
simark and vries committed Dec 4, 2024
1 parent c719eb2 commit 0225ef6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
3 changes: 0 additions & 3 deletions gdb/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H

/* Define to 1 if you have the `waitpid' function. */
#undef HAVE_WAITPID

/* Define to 1 if you have the <wait.h> header file. */
#undef HAVE_WAIT_H

Expand Down
1 change: 0 additions & 1 deletion gdb/configure
Original file line number Diff line number Diff line change
Expand Up @@ -29924,7 +29924,6 @@ for ac_func in \
sigsetmask \
ttrace \
use_default_colors \
waitpid \
wresize \

do :
Expand Down
1 change: 0 additions & 1 deletion gdb/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,6 @@ AC_CHECK_FUNCS([ \
sigsetmask \
ttrace \
use_default_colors \
waitpid \
wresize \
])

Expand Down
6 changes: 6 additions & 0 deletions gdbsupport/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H

/* Define to 1 if you have the `wait' function. */
#undef HAVE_WAIT

/* Define to 1 if you have the `waitpid' function. */
#undef HAVE_WAITPID

/* Define to 1 if you have the <wait.h> header file. */
#undef HAVE_WAIT_H

Expand Down
16 changes: 16 additions & 0 deletions gdbsupport/configure
Original file line number Diff line number Diff line change
Expand Up @@ -13948,6 +13948,22 @@ else
fi


for ac_func in \
waitpid \
wait

do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done


# Check the return and argument types of ptrace.


Expand Down
5 changes: 5 additions & 0 deletions gdbsupport/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ AM_CONDITIONAL(SELFTEST, $enable_unittests)
AM_CONDITIONAL(HAVE_PIPE_OR_PIPE2,
[test x$ac_cv_func_pipe = xyes -o x$ac_cv_func_pipe2 = xyes ])

AC_CHECK_FUNCS([ \
waitpid \
wait
])

# Check the return and argument types of ptrace.
GDB_AC_PTRACE

Expand Down
4 changes: 4 additions & 0 deletions gdbsupport/eintr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,27 @@ handle_eintr (ErrorValType errval, const Fun &f, const Args &... args)
return ret;
}

#ifdef HAVE_WAITPID
inline pid_t
waitpid (pid_t pid, int *wstatus, int options)
{
return gdb::handle_eintr (-1, ::waitpid, pid, wstatus, options);
}
#endif /* HAVE_WAITPID */

inline int
open (const char *pathname, int flags)
{
return gdb::handle_eintr (-1, ::open, pathname, flags);
}

#ifdef HAVE_WAIT
inline pid_t
wait (int *wstatus)
{
return gdb::handle_eintr (-1, ::wait, wstatus);
}
#endif /* HAVE_WAIT */

inline int
close (int fd)
Expand Down

0 comments on commit 0225ef6

Please sign in to comment.