* [PATCH v5 1/2] gdb/ser-unix: fix musl build failure when setting custom baud rates
2026-03-24 16:45 [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support sunilkumar.dora
@ 2026-03-24 16:45 ` sunilkumar.dora
2026-03-24 16:45 ` [PATCH v5 2/2] gdb/ser-unix: add POSIX cfsetispeed/cfsetospeed support for " sunilkumar.dora
2026-03-27 18:15 ` [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support Kevin Buettner
2 siblings, 0 replies; 7+ messages in thread
From: sunilkumar.dora @ 2026-03-24 16:45 UTC (permalink / raw)
To: gdb-patches
Cc: SunilKumar.Dora, kevinb, macro, eliz, Randy.MacLeod,
Sundeep.Kokkonda, schwab, tromey, simark
From: Sunil Dora <sunilkumar.dora@windriver.com>
On musl-based systems, <asm/termbits.h> may expose BOTHER even though
struct termios does not define c_ispeed/c_ospeed. This causes the
Linux-specific custom baud rate path to be compiled and fail to build.
Fix the problem at the macro level by requiring
HAVE_STRUCT_TERMIOS_C_OSPEED (obtained via AC_CHECK_MEMBERS) together
with BOTHER in the HAVE_CUSTOM_BAUDRATE_SUPPORT guard. This prevents
the Linux-specific code from being compiled on musl while leaving
set_custom_baudrate_linux unchanged.
This is a pure build fix with no functional or behavioural change on
any existing platform.
Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
gdb/config.in | 3 +++
gdb/configure | 13 +++++++++++++
gdb/configure.ac | 3 +++
gdb/ser-unix.c | 4 +++-
4 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/gdb/config.in b/gdb/config.in
index b11fcf18372..6ad5240397b 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -517,6 +517,9 @@
/* Define to 1 if `st_blocks' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BLOCKS
+/* Define to 1 if `c_ospeed' is a member of `struct termios'. */
+#undef HAVE_STRUCT_TERMIOS_C_OSPEED
+
/* Define to 1 if `td_pcb' is a member of `struct thread'. */
#undef HAVE_STRUCT_THREAD_TD_PCB
diff --git a/gdb/configure b/gdb/configure
index 12c54521682..72e69c9749f 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -27728,6 +27728,19 @@ if test "$ac_res" != no; then :
fi
+# Check for members required by the legacy Linux custom baud rate path.
+ac_fn_c_check_member "$LINENO" "struct termios" "c_ospeed" "ac_cv_member_struct_termios_c_ospeed" "#include <termios.h>
+"
+if test "x$ac_cv_member_struct_termios_c_ospeed" = xyes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_TERMIOS_C_OSPEED 1
+_ACEOF
+
+
+fi
+
+
# Check whether --with-jit-reader-dir was given.
diff --git a/gdb/configure.ac b/gdb/configure.ac
index cf8078e1d89..277eb945e84 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -725,6 +725,9 @@ AC_CONFIG_FILES([jit-reader.h:jit-reader.in])
AC_SEARCH_LIBS(dlopen, dl)
+# Check for members required by the legacy Linux custom baud rate path.
+AC_CHECK_MEMBERS([struct termios.c_ospeed], [], [], [[#include <termios.h>]])
+
GDB_AC_WITH_DIR([JIT_READER_DIR], [jit-reader-dir],
[directory to load the JIT readers from],
[${libdir}/gdb])
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index c295a9c5ba1..72c46d29e8f 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -55,7 +55,9 @@
#include "gdbsupport/scoped_ignore_sigttou.h"
-#if defined(HAVE_SYS_IOCTL_H) && (defined(BOTHER) || defined(IOSSIOSPEED))
+#if (defined(HAVE_SYS_IOCTL_H) \
+ && ((defined(BOTHER) && defined(HAVE_STRUCT_TERMIOS_C_OSPEED)) \
+ || defined(IOSSIOSPEED)))
# define HAVE_CUSTOM_BAUDRATE_SUPPORT 1
#endif
--
2.49.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v5 2/2] gdb/ser-unix: add POSIX cfsetispeed/cfsetospeed support for custom baud rates
2026-03-24 16:45 [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support sunilkumar.dora
2026-03-24 16:45 ` [PATCH v5 1/2] gdb/ser-unix: fix musl build failure when setting custom baud rates sunilkumar.dora
@ 2026-03-24 16:45 ` sunilkumar.dora
2026-03-24 17:15 ` Eli Zaretskii
2026-03-27 18:15 ` [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support Kevin Buettner
2 siblings, 1 reply; 7+ messages in thread
From: sunilkumar.dora @ 2026-03-24 16:45 UTC (permalink / raw)
To: gdb-patches
Cc: SunilKumar.Dora, kevinb, macro, eliz, Randy.MacLeod,
Sundeep.Kokkonda, schwab, tromey, simark
From: Sunil Dora <sunilkumar.dora@windriver.com>
glibc 2.42 and later, and GNU Hurd, accept arbitrary baud rates
directly via cfsetispeed and cfsetospeed. This behaviour is expected
to be standardized in a future POSIX revision.
Introduce a configure-time test (HAVE_CFSETSPEED_ARBITRARY) that
detects this capability and add a new platform-agnostic helper
set_custom_baudrate_posix. The main dispatcher now prefers the POSIX
path when it is available, falling back to the existing Linux (BOTHER)
or Darwin (IOSSIOSPEED) implementations otherwise.
The HAVE_CUSTOM_BAUDRATE_SUPPORT guard is extended to also cover the
new POSIX case.
Suggested-by: Kevin Buettner <kevinb@redhat.com>
Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
gdb/NEWS | 6 ++++++
gdb/config.in | 3 +++
gdb/configure | 39 ++++++++++++++++++++++++++++++++++++++
gdb/configure.ac | 19 +++++++++++++++++++
gdb/ser-unix.c | 49 +++++++++++++++++++++++++++++++++++++++---------
5 files changed, 107 insertions(+), 9 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 03f46df5400..e46b3a56a1f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -36,6 +36,12 @@
subsequent runs of the inferior will use the same arguments as the
first run.
+* GDB now supports arbitrary (non-standard) baud rates for serial
+ connections to remote targets on systems where the host libc accepts
+ them via cfsetispeed/cfsetospeed, such as glibc 2.42 and later and
+ GNU Hurd. On other systems, existing platform-specific mechanisms
+ are used.
+
* Support for stabs debug information has been removed.
* Support for mdebug debug information has been removed.
diff --git a/gdb/config.in b/gdb/config.in
index 6ad5240397b..e357c22e411 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -110,6 +110,9 @@
the CoreFoundation framework. */
#undef HAVE_CFPREFERENCESCOPYAPPVALUE
+/* Define if cfsetispeed/cfsetospeed accept arbitrary baud rates. */
+#undef HAVE_CFSETSPEED_ARBITRARY
+
/* Define to 1 if you have the `clearenv' function. */
#undef HAVE_CLEARENV
diff --git a/gdb/configure b/gdb/configure
index 72e69c9749f..d10c4fdce34 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -27741,6 +27741,45 @@ _ACEOF
fi
+# Check whether cfsetispeed/cfsetospeed accept arbitrary baud rates.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cfsetispeed/cfsetospeed accept arbitrary baud rates" >&5
+$as_echo_n "checking whether cfsetispeed/cfsetospeed accept arbitrary baud rates... " >&6; }
+if ${gdb_cv_cfsetspeed_arbitrary+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <termios.h>
+int
+main ()
+{
+
+ #if B9600 != 9600
+ #error B-constants are not numeric symbols
+ #endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ gdb_cv_cfsetspeed_arbitrary=yes
+else
+ gdb_cv_cfsetspeed_arbitrary=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cfsetspeed_arbitrary" >&5
+$as_echo "$gdb_cv_cfsetspeed_arbitrary" >&6; }
+
+if test "$gdb_cv_cfsetspeed_arbitrary" = yes; then
+
+$as_echo "#define HAVE_CFSETSPEED_ARBITRARY 1" >>confdefs.h
+
+fi
+
# Check whether --with-jit-reader-dir was given.
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 277eb945e84..42d7594fa31 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -728,6 +728,25 @@ AC_SEARCH_LIBS(dlopen, dl)
# Check for members required by the legacy Linux custom baud rate path.
AC_CHECK_MEMBERS([struct termios.c_ospeed], [], [], [[#include <termios.h>]])
+# Check whether cfsetispeed/cfsetospeed accept arbitrary baud rates.
+AC_CACHE_CHECK([whether cfsetispeed/cfsetospeed accept arbitrary baud rates],
+ [gdb_cv_cfsetspeed_arbitrary], [
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <termios.h>]],
+ [[
+ #if B9600 != 9600
+ #error B-constants are not numeric symbols
+ #endif
+ ]])],
+ [gdb_cv_cfsetspeed_arbitrary=yes],
+ [gdb_cv_cfsetspeed_arbitrary=no])
+])
+
+if test "$gdb_cv_cfsetspeed_arbitrary" = yes; then
+ AC_DEFINE([HAVE_CFSETSPEED_ARBITRARY], [1],
+ [Define if cfsetispeed/cfsetospeed accept arbitrary baud rates.])
+fi
+
GDB_AC_WITH_DIR([JIT_READER_DIR], [jit-reader-dir],
[directory to load the JIT readers from],
[${libdir}/gdb])
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 72c46d29e8f..1bb21a08572 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -55,9 +55,10 @@
#include "gdbsupport/scoped_ignore_sigttou.h"
-#if (defined(HAVE_SYS_IOCTL_H) \
- && ((defined(BOTHER) && defined(HAVE_STRUCT_TERMIOS_C_OSPEED)) \
- || defined(IOSSIOSPEED)))
+#if (defined(HAVE_CFSETSPEED_ARBITRARY) \
+ || (defined(HAVE_SYS_IOCTL_H) \
+ && ((defined(BOTHER) && defined(HAVE_STRUCT_TERMIOS_C_OSPEED)) \
+ || defined(IOSSIOSPEED))))
# define HAVE_CUSTOM_BAUDRATE_SUPPORT 1
#endif
@@ -510,7 +511,32 @@ set_baudcode_baudrate (struct serial *scb, int baud_code)
perror_with_name (_("could not set tty state"));
}
-#if HAVE_CUSTOM_BAUDRATE_SUPPORT && defined(BOTHER)
+#if HAVE_CUSTOM_BAUDRATE_SUPPORT && defined(HAVE_CFSETSPEED_ARBITRARY)
+
+/* Set a custom baud rate using the POSIX cfsetispeed/cfsetospeed
+ interface. Supported in glibc 2.42 and later and expected to be
+ standardized in a future POSIX revision. It is platform-agnostic
+ and also covers systems like GNU Hurd that do not provide BOTHER. */
+
+static void
+set_custom_baudrate_posix (int fd, int rate)
+{
+ struct termios tio;
+
+ if (tcgetattr (fd, &tio) < 0)
+ perror_with_name (_("Cannot get current baud rate"));
+
+ if (cfsetispeed (&tio, rate) < 0)
+ perror_with_name (_("Cannot set custom input baud rate"));
+
+ if (cfsetospeed (&tio, rate) < 0)
+ perror_with_name (_("Cannot set custom output baud rate"));
+
+ if (tcsetattr (fd, TCSANOW, &tio) < 0)
+ perror_with_name (_("Cannot set custom baud rate"));
+}
+
+#elif HAVE_CUSTOM_BAUDRATE_SUPPORT && defined(BOTHER)
/* Set a custom baud rate using the termios BOTHER. */
@@ -557,19 +583,24 @@ set_custom_baudrate_darwin (int fd, int rate)
}
#endif /* HAVE_CUSTOM_BAUDRATE_SUPPORT
- && (defined(BOTHER) || defined(IOSSIOSPEED)) */
+ && (defined(HAVE_CFSETSPEED_ARBITRARY)
+ || defined(BOTHER)
+ || defined(IOSSIOSPEED)) */
#if HAVE_CUSTOM_BAUDRATE_SUPPORT
/* Set a baud rate that differs from the OS B_codes.
- This is possible if one of the following macros is available:
- - BOTHER (Linux).
- - IOSSIOSPEED (Darwin). */
+ Prefer the POSIX cfsetispeed/cfsetospeed interface when the host
+ libc accepts arbitrary baud rates. Otherwise fall back to
+ Linux-specific (BOTHER) or Darwin-specific (IOSSIOSPEED)
+ interfaces. */
static void
set_custom_baudrate (int fd, int rate)
{
-#if defined(BOTHER)
+#if defined(HAVE_CFSETSPEED_ARBITRARY)
+ set_custom_baudrate_posix (fd, rate);
+#elif defined(BOTHER)
set_custom_baudrate_linux (fd, rate);
#elif defined(IOSSIOSPEED)
set_custom_baudrate_darwin (fd, rate);
--
2.49.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support
2026-03-24 16:45 [PATCH v5 0/2] PR gdb/33747: gdb/ser-unix: fix musl build failure and add POSIX custom baud rate support sunilkumar.dora
2026-03-24 16:45 ` [PATCH v5 1/2] gdb/ser-unix: fix musl build failure when setting custom baud rates sunilkumar.dora
2026-03-24 16:45 ` [PATCH v5 2/2] gdb/ser-unix: add POSIX cfsetispeed/cfsetospeed support for " sunilkumar.dora
@ 2026-03-27 18:15 ` Kevin Buettner
2026-03-27 19:26 ` Sunil Kumar Dora
2026-04-14 16:28 ` Sunil Kumar Dora
2 siblings, 2 replies; 7+ messages in thread
From: Kevin Buettner @ 2026-03-27 18:15 UTC (permalink / raw)
To: sunilkumar.dora
Cc: gdb-patches, macro, eliz, Randy.MacLeod, Sundeep.Kokkonda,
schwab, tromey, simark
On Tue, 24 Mar 2026 09:45:25 -0700
sunilkumar.dora@windriver.com wrote:
> From: Sunil Dora <sunilkumar.dora@windriver.com>
>
> On musl-based systems <asm/termbits.h> exposes BOTHER, so the
> Linux-specific custom baud rate path was being compiled. However,
> musl's struct termios does not provide the public members c_ispeed
> and c_ospeed, causing a build failure.
>
> This series fixes the build issue at the macro level (patch 1).
> It then adds the preferred POSIX cfsetispeed/cfsetospeed path as the
> first choice on platforms where the host libc supports arbitrary baud
> rates, such as glibc 2.42 and later, GNU Hurd, and potentially other
> libc implementations (patch 2). The existing Linux (termios2/BOTHER)
> and Darwin (IOSSIOSPEED) paths remain as fallbacks.
>
> The two patches are independent:
> - Patch 1 is a pure build fix with no functional change.
> - Patch 2 adds the new POSIX feature on top of the fixed guard.
>
> set_custom_baudrate_linux is left unchanged.
>
> Changes since V4:
> - Split into two patches, with patch 1 as a pure build fix
> and patch 2 adding the POSIX interface.
> - Fixed #if guard formatting and added full stop to the
> AC_DEFINE description.
> - Removed parentheses from function name references in
> commit messages and comments.
> - Updated NEWS entry to describe which configurations are
> affected.
>
> v4: https://sourceware.org/pipermail/gdb-patches/2026-March/226133.html
> v3: https://sourceware.org/pipermail/gdb-patches/2026-March/225952.html
> v2: https://sourceware.org/pipermail/gdb-patches/2026-February/225251.html
> v1: https://sourceware.org/pipermail/gdb-patches/2026-February/224968.html
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33747
Both parts are approved. Thanks for persevering through the many
requests for changes.
One thing I noticed - Some error messages in ser-unix.c still use
"Can not" whereas you uniformly (and correctly IMO) use "Cannot".
If you're up for doing a follow-on patch, one which does
s/Can not/Cannot/ on the remaining occurrences would be appreciated.
Approved-by: Kevin Buettner <kevinb@redhat.com>
^ permalink raw reply [flat|nested] 7+ messages in thread