Add valgrind-3.21.0-gdb-multi-mode-stdout-redirecting-to-stderr.patch

This commit is contained in:
Mark Wielaard 2023-08-17 16:17:56 +02:00
parent 2cb3825159
commit d80baf58dc
2 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,85 @@
From 449dd82becae6533a8e658e76f30f65434f6417f Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 17 Aug 2023 15:40:30 +0200
Subject: [PATCH] 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
---
NEWS | 1 +
coregrind/vgdb.c | 20 +++++++++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c
index 56a969de7..c024ffca6 100644
--- a/coregrind/vgdb.c
+++ b/coregrind/vgdb.c
@@ -1159,7 +1159,7 @@ static void gdb_relay(int pid, int send_noack_mode, char *q_buf);
or the errno from the child on failure. */
static
int fork_and_exec_valgrind (int argc, char **argv, const char *working_dir,
- pid_t *pid)
+ int in_port, pid_t *pid)
{
int err = 0;
// We will use a pipe to track what the child does,
@@ -1243,6 +1243,19 @@ int fork_and_exec_valgrind (int argc, char **argv, const char *working_dir,
}
}
+ /* 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. */
+ if (in_port <= 0) {
+ /* close stdin */
+ close (0);
+ /* open /dev/null as new stdin */
+ open ("/dev/null", O_RDONLY);
+ /* redirect stdout as stderr */
+ dup2 (2, 1);
+ }
+
/* Try to launch valgrind. Add --vgdb-error=0 to stop immediately so we
can attach and --launched-with-multi to let valgrind know it doesn't
need to show a banner how to connect to gdb, we will do that
@@ -1309,7 +1322,7 @@ int fork_and_exec_valgrind (int argc, char **argv, const char *working_dir,
/* Do multi stuff. */
static
-void do_multi_mode(int check_trials)
+void do_multi_mode(int check_trials, int in_port)
{
char *buf = vmalloc(PBUFSIZ+1);
char *q_buf = vmalloc(PBUFSIZ+1); //save the qSupported packet sent by gdb
@@ -1459,6 +1472,7 @@ void do_multi_mode(int check_trials)
int res = fork_and_exec_valgrind (count,
decoded_string,
working_dir,
+ in_port,
&valgrind_pid);
if (res == 0) {
@@ -2427,7 +2441,7 @@ int main(int argc, char** argv)
if (multi_mode) {
/* check_trails is the --wait argument in seconds, defaulting to 1
* if not given. */
- do_multi_mode (check_trials);
+ do_multi_mode (check_trials, in_port);
} else if (last_command >= 0) {
standalone_send_commands(pid, last_command, commands);
} else {
--
2.41.0

View File

@ -112,6 +112,10 @@ Patch11: valgrind-3.21.0-vgm-tests.patch
# https://bugs.kde.org/show_bug.cgi?id=470978
Patch12: valgrind-3.21.0-pgste.patch
# gdb --multi mode stdout redirecting to stderr
# https://bugs.kde.org/show_bug.cgi?id=471311
Patch13: valgrind-3.21.0-gdb-multi-mode-stdout-redirecting-to-stderr.patch
BuildRequires: make
BuildRequires: glibc-devel
@ -257,6 +261,7 @@ Valgrind User Manual for details.
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%build
@ -490,6 +495,9 @@ fi
%endif
%changelog
* Thu Aug 17 2023 Mark Wielaard <mjw@fedoraproject.org>
- Add valgrind-3.21.0-gdb-multi-mode-stdout-redirecting-to-stderr.patch
* Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1:3.21.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild