From: Mark Wielaard Date: Thu, 17 Aug 2023 13:40:30 +0000 (+0200) Subject: gdb --multi mode stdout redirecting to stderr X-Git-Tag: VALGRIND_3_22_0~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b35a8ed5a9575dbadb7e2a84bd4b6c4ab9eda21a;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/NEWS b/NEWS index 56f4701e00..ee0dc582fe 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. Assertion 'resolved' failed 470830 Don't print actions vgdb me ... continue for vgdb --multi mode 470978 s390x: Valgrind cannot start qemu-kvm when "sysctl vm.allocate_pgste=0" +471311 gdb --multi mode stdout redirecting to stderr 471807 Add support for lazy reading and downloading of DWARF debuginfo 472219 Syscall param ppoll(ufds.events) points to uninitialised byte(s) 472963 Broken regular expression in configure.ac diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 56a969de78..c024ffca6b 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 {