From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id BF0423850400 for ; Mon, 28 Sep 2020 12:21:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BF0423850400 Received: by mail-il1-x12c.google.com with SMTP id o9so967395ils.9 for ; Mon, 28 Sep 2020 05:21:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=4ZOsp9e+1INs0MG7TkFiufEO9yUPqj+fTOHEzqlFU0o=; b=bAMtJgm8rm/N8Sr+pnMBJiVP911GLWDc7KwdAaBhgcX/4UnYhb7A1mSGle/4vPnVWC xqGBSSuYbVFAl108kvYxvy1FbjCycL7Zxfw+hnOT95euaI4xCZ7pBQuTMvWUEXcBPnFi uzyJhQQij8IwsgsU736JPK9zOycugLKS6S27GF2ENySXqIdizoxfJ+P8g85IyceN4GlZ R+CwHVwVZklbyjId63pGjY2gyIexmuWKo5bgO5HyCRuLU7fLN+wnMkdc2SW0tvIK8ruc qvZEiifbEHdGnDensyTGhjtS+Hb3gVdyLi9BqY055rpL16WZrsQcJfWlX6fne2X5SD5A c3fA== X-Gm-Message-State: AOAM531yTPKW4P9C7MxlSq14SXTMXJ0i2dTTk4rrQftQsUDzXPQGuyWg v30vSpP2gg3WhWtgvOJMcxPOYFGzti08KpI/i9pNBaPBsu0= X-Google-Smtp-Source: ABdhPJzr/BGqzVVtiKQY818k4MBS5Dc71YE6g+dwPICygACs9R2cpOY8nRgQkMj/dtbPTupGhSe6VULBXD8zsFQHQtU= X-Received: by 2002:a92:3650:: with SMTP id d16mr869930ilf.29.1601295708896; Mon, 28 Sep 2020 05:21:48 -0700 (PDT) MIME-Version: 1.0 From: Roy Qu Date: Mon, 28 Sep 2020 20:21:38 +0800 Message-ID: Subject: the redirected stdin/out/err for new console is wrong when the gdb's stdin/out/err is already redirected To: gdb-patches@sourceware.org X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2020 12:21:51 -0000 I'm using gdb 9.2 of mingw.org. (not mingw-w64) With "set new-console on", gdb will create a new console and run the debugged program in it. Commands like "run < somefile" will redirect STDIN to the input of 'somefile', and the STDOUT should leave to the created console. but when the gdb is running embedded in some IDE such as Dev-CPP and its STDIN/STDOUT/STDERR is already redirected into the host IDE, Console created by commands like "run < somefile" will inherit gdb's STDOUT/STDERR value and redirect all the output to host IDE too. (The running result should show in the debugged console, not in the IDE's debug log window) So I create a patch to fix it. --- gdb-9.2-new/gdb/windows-nat.c 2020-07-11 20:13:30.000000000 +0800 +++ gdb-9.2/gdb/windows-nat.c 2020-09-28 20:21:06.515524700 +0800 @@ -2736,20 +2736,20 @@ si.hStdInput = (HANDLE) _get_osfhandle (fd_inp); else if (tty != INVALID_HANDLE_VALUE) si.hStdInput = tty; - else - si.hStdInput = GetStdHandle (STD_INPUT_HANDLE); + else + si.hStdInput = (HANDLE)0; if (fd_out >= 0) si.hStdOutput = (HANDLE) _get_osfhandle (fd_out); else if (tty != INVALID_HANDLE_VALUE) si.hStdOutput = tty; else - si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); + si.hStdOutput = NULL; if (fd_err >= 0) si.hStdError = (HANDLE) _get_osfhandle (fd_err); else if (tty != INVALID_HANDLE_VALUE) si.hStdError = tty; else - si.hStdError = GetStdHandle (STD_ERROR_HANDLE); + si.hStdError = NULL; si.dwFlags |= STARTF_USESTDHANDLES; }