Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/4] [gdb] Add logging_file::fd
Date: Fri, 23 Oct 2026 10:02:23 +0200	[thread overview]
Message-ID: <bf8ce52e-b319-4e79-94ec-c7e23a916a81@suse.de> (raw)
In-Reply-To: <878q3ryoxx.fsf@tromey.com>

On 10/21/26 6:54 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> Logging_file is derived from ui_file, which defines a virtual fd member
> Tom> function:
> Tom> ...
> Tom>   /* If this object has an underlying file descriptor, then return it.
> Tom>      Otherwise, return -1.  */
> Tom>   virtual int fd () const
> Tom>   { return -1; }
> Tom> ...
> 
> Tom> Logging_file doesn't define its own fd, so it defaults to -1.
> 
> That test in bt-utils.c (and the other one in event-top.c) look weird to
> me.  It does this:
> 
>    if (gdb_stderr == nullptr || gdb_stderr->fd () == -1)
>      std::ignore = ::write (2, msg, strlen (msg));
>    else
>      gdb_stderr->write_async_safe (msg, strlen (msg));
> 
> But why is that -1 check there?
> 
> Is it because the default ui_file::write_async_safe aborts?
> 
> Since if so then maybe that's the real issue: the API is kind of
> incoherent here.
> 

Hi Tom,

thanks for the review.

AFAIR, the -1 check is indeed there to make sure not to run into the 
default ui_file::write_async_safe, specifically when gdb_stderr is 
temporarily set to a string_file.

> I wonder whether we could simply remove the fd() method entirely and
> instead make the default write_async_safe do something sensible; or make
> it pure virtual and require the subclasses to DTRT.

Removing the fd () method doesn't seem possible due to the use in 
backtrace_symbols_fd (used when using execinfo instead of libbacktrace).

I've submitted an alternative approach ( 
https://sourceware.org/pipermail/gdb-patches/2026-October/231353.html ):
- make the default write_async_safe print to fd ()
- make it return true if the write was handled
- use the return value to decide whether to call the stderr fd fallback.
- add a new method for_each_fd to handle the execinfo case as well

The code is somewhat cleaner, and there's no more direct testing of "fd 
() == -1" in the code, only in the ui_file classes.

I'm not very familiar with this code, so I used two LLMs for review to 
get here.  Unfortunately, they don't agree on what is correct behavior 
for the return value of logging_file::write_async_safe and 
logging_file::for_each_fd, so that probably requires some review attention.

Thanks,
- Tom


  reply	other threads:[~2026-10-23  8:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  8:01 [PATCH 0/4] [gdb/tui] Fix hang in tui_disable in handle_fatal_signal Tom de Vries
2026-10-21  8:01 ` [PATCH 1/4] [gdb] Add logging_file::fd Tom de Vries
2026-10-21 16:54   ` Tom Tromey
2026-10-23  8:02     ` Tom de Vries [this message]
2026-10-23 17:41       ` Tom Tromey
2026-10-23 18:25         ` Tom de Vries
2026-10-21  8:01 ` [PATCH 2/4] [gdb/testsuite] Check internal-error in gdb.tui/new-ui.exp Tom de Vries
2026-10-21  8:01 ` [PATCH 3/4] [gdb/tui] Switch to main UI before disabling TUI Tom de Vries
2026-10-21  8:01 ` [PATCH 4/4] [gdb/tui] Fix hang in tui_disable in handle_fatal_signal Tom de Vries

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=bf8ce52e-b319-4e79-94ec-c7e23a916a81@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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