From: Sunil Kumar Dora <sunilkumar.dora@windriver.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>
Cc: gdb-patches@sourceware.org, Kevin Buettner <kevinb@redhat.com>,
Randy.MacLeod@windriver.com, Sundeep.Kokkonda@windriver.com,
schwab@linux-m68k.org, tromey@sourceware.org,
Simon Marchi <simark@simark.ca>
Subject: Re: [PATCH V3] PR gdb/33747: gdb/ser-unix: modernize Linux custom baud rate support
Date: Mon, 23 Mar 2026 01:25:56 +0530 [thread overview]
Message-ID: <87596303-eabc-4489-ab49-5d56849717c1@windriver.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2603200048280.1878@angie.orcam.me.uk>
Thanks Maciej.
On 3/20/2026 6:54 AM, Maciej W. Rozycki wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Thu, 12 Mar 2026, sunilkumar.dora@windriver.com wrote:
>
>> diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
>> index c295a9c5ba1..a15f4cc2162 100644
>> --- a/gdb/ser-unix.c
>> +++ b/gdb/ser-unix.c
>> @@ -510,36 +510,59 @@ set_baudcode_baudrate (struct serial *scb, int baud_code)
>>
>> #if HAVE_CUSTOM_BAUDRATE_SUPPORT && defined(BOTHER)
>>
>> -/* Set a custom baud rate using the termios BOTHER. */
>> +/* Set a custom baud rate.
>> +
>> + Prefer the POSIX cfsetispeed/cfsetospeed interface when it accepts
>> + arbitrary baud rates. Otherwise fall back to Linux-specific termios2
>> + (BOTHER) or legacy termios interfaces. */
>>
>> static void
>> set_custom_baudrate_linux (int fd, int rate)
>> {
>> -#ifdef TCGETS2
>> - struct termios2 tio;
>> - const unsigned long req_get = TCGETS2;
>> - const unsigned long req_set = TCSETS2;
>> -#else
>> +#if defined(HAVE_CFSETSPEED_ARBITRARY)
>> struct termios tio;
>> - const unsigned long req_get = TCGETS;
>> - const unsigned long req_set = TCSETS;
>> -#endif
>> + if (tcgetattr (fd, &tio) < 0)
>> + perror_with_name (_("Cannot get current baud rate"));
>> +
>> + cfsetispeed (&tio, rate);
>> + cfsetospeed (&tio, rate);
>> +
>> + if (tcsetattr (fd, TCSANOW, &tio) < 0)
>> + perror_with_name (_("Cannot set custom baud rate"));
> It doesn't appear to me this code should be wrapped in:
>
> #if ... && defined(BOTHER)
>
> or for that matter be a part of `set_custom_baudrate_linux' (which AFAICT
> should be left alone, or please point me at what actually you have changed
> there that is not pure code massaging) as this is now platform-agnostic
> (and I believe GNU Hurd has always supported arbitrary baud rates using
> this interface). I'm leaving it up to you to come up with a name for this
> new variant of the function.
>
> Also ISTM that HAVE_CUSTOM_BAUDRATE_SUPPORT now also needs to be set if
> HAVE_CFSETSPEED_ARBITRARY rather than relying on BOTHER to be defined as
> well, which may not necessarily be the case (cf. GNU Hurd again).
To clarify the change in set_custom_baudrate_linux: on musl-based
systems BOTHER is visible via <asm/termbits.h>, included through the
HAVE_ASM_TERMIOS_H path in ser-unix.c, so the function does get
compiled. The #else branch then fails to compile because musl's
struct termios exposes the speed fields only as private
__c_ispeed/__c_ospeed, not as c_ispeed/c_ospeed.
Following your suggestion, the fix belongs at the macro level.
Requiring HAVE_STRUCT_TERMIOS_C_OSPEED alongside BOTHER in the
HAVE_CUSTOM_BAUDRATE_SUPPORT guard ensures the Linux path is simply
not compiled on musl systems where those fields are unavailable,
leaving set_custom_baudrate_linux completely unchanged.
In V4:
- set_custom_baudrate_linux is left completely unchanged.
- HAVE_CUSTOM_BAUDRATE_SUPPORT is updated to require
HAVE_STRUCT_TERMIOS_C_OSPEED alongside BOTHER, so the Linux
path is not compiled on musl where struct termios lacks those
fields.
- New independent function set_custom_baudrate_posix(), guarded
by #if HAVE_CFSETSPEED_ARBITRARY, outside the defined(BOTHER)
block, covering systems like GNU Hurd.
- HAVE_CUSTOM_BAUDRATE_SUPPORT extended to also fire when
HAVE_CFSETSPEED_ARBITRARY is defined.
- The #else error() fallback is removed. Unsupported platforms
are already handled in rate_to_code() and
hardwire_setbaudrate().
V4 will be posted shortly.
>
>> +#else
>> + error (_("Custom baud rate not supported on this platform"));
>> +#endif
> This shouldn't be needed as this code is not supposed to be ever compiled
> if !HAVE_CUSTOM_BAUDRATE_SUPPORT (IOW don't set the macro instead if the
> conditions required are not met).
Fixed in V4.
Thanks,
Sunil Dora
>
> Maciej
prev parent reply other threads:[~2026-03-22 19:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 21:01 sunilkumar.dora
2026-03-19 22:44 ` Kevin Buettner
2026-03-22 19:49 ` Sunil Kumar Dora
2026-03-20 1:24 ` Maciej W. Rozycki
2026-03-22 19:55 ` Sunil Kumar Dora [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87596303-eabc-4489-ab49-5d56849717c1@windriver.com \
--to=sunilkumar.dora@windriver.com \
--cc=Randy.MacLeod@windriver.com \
--cc=Sundeep.Kokkonda@windriver.com \
--cc=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
--cc=macro@orcam.me.uk \
--cc=schwab@linux-m68k.org \
--cc=simark@simark.ca \
--cc=tromey@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox