Bug 471311 - gdb --multi mode stdout redirecting to stderr
Summary: gdb --multi mode stdout redirecting to stderr
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.21.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Mark Wielaard
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-21 22:09 UTC by Mark Wielaard
Modified: 2023-08-21 16:03 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
gdb --multi mode stdout redirecting to stderr (3.82 KB, text/plain)
2023-08-17 13:45 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2023-06-21 22:09:00 UTC
Sasha is working on a real solution for redirecting all of the stdin/out/err file descriptors:
https://git.sr.ht/~sasshka/binutils-gdb/log/split_fd

But that needs a new gdb that understand the new proposed FdSwitch packet.

As a temporary workaround we can at least redirect stdout to stderr (and close stdin) for the inferior (unless --port is used).

Something like:
/* close stdin */
close (0);
/* open /dev/null as new stdin */
open ("/dev/null", O_RDONLY);
/* redirect stdout as stderr */
dup2 (2, 1);
Comment 1 Mark Wielaard 2023-08-17 13:45:48 UTC
Created attachment 161024 [details]
gdb --multi mode stdout redirecting to stderr

Implementing this is almost trivial, see attached.
Comment 2 Mark Wielaard 2023-08-21 16:03:56 UTC
commit b35a8ed5a9575dbadb7e2a84bd4b6c4ab9eda21a
Author: Mark Wielaard <mark@klomp.org>
Date:   Thu Aug 17 15:40:30 2023 +0200

    gdb --multi mode stdout redirecting to stderr
    
    When in stdio mode (talking to gdb through stdin/stdout, not
    through a socket), redirect stdout to stderr and close stdin
    for the inferior. That way at least some output can be seen,
    but there will be no input.
    
    This is workaround till we have real terminal handling.
    
         * coregrind/vgdb.c (main): Pass in_port to do_multi_mode.
         (do_multi_mode): Pass in_port to fork_and_exec_valgrind.
         (fork_and_exec_valgrind): Close stdin, redirect stdout to
         stderr if in_port <= 0.
    
    https://bugs.kde.org/show_bug.cgi?id=471311