]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
gdb --multi mode stdout redirecting to stderr
authorMark Wielaard <mark@klomp.org>
Thu, 17 Aug 2023 13:40:30 +0000 (15:40 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 21 Aug 2023 12:08:40 +0000 (14:08 +0200)
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
coregrind/vgdb.c

diff --git a/NEWS b/NEWS
index 56f4701e0032f4c6b74abf540445430f6564fcf8..ee0dc582fe0459dd46d913a90fae92284d6620a1 100644 (file)
--- 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
index 56a969de7881585eabc18ee6027b81284e7ab7bc..c024ffca6b9b226149a51dd991c4c8ff25360995 100644 (file)
@@ -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 {