Visual Studio Code 中的 GDB 不向 stdout 显示 printf() 输出 [英] GDB in Visual Studio Code doesn't show printf() output to stdout

查看:34
本文介绍了Visual Studio Code 中的 GDB 不向 stdout 显示 printf() 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 GDB 在 VSCode 中调试 C 项目时,输出到 stdout(通过 printf())不会出现在调试控制台上.但是,当使用 cppvsdebug 时,它可以工作.

When debugging a C project in VSCode with GDB, the output to stdout (through printf()) does not appear on the Debug Console. When using cppvsdebug, however, it works.

这是我的launch.json:

This is my launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
          {
            "name": "Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
              {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": false
              }
            ],
            "windows": {
              "miDebuggerPath": "C:/raylib/mingw/bin/gdb.exe",
            },
            "osx": {
              "MIMode": "lldb"
            },
            "linux": {
              "miDebuggerPath": "/usr/bin/gdb",
            },
            "preLaunchTask": "build debug"
          },
          {
            "name": "Run",
            "type": "cppdbg",
            "request": "launch",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "program": "${workspaceFolder}/main",
            "MIMode": "gdb",
            "windows": {
              "program": "${workspaceFolder}/main.exe",
              "miDebuggerPath": "C:/raylib/mingw/bin/gdb.exe"
            },
            "osx": {
              "MIMode": "lldb"
            },
            "linux": {
              "miDebuggerPath": "/usr/bin/gdb"
            },
            "preLaunchTask": "build release",
          }
        ]
      }

这是为了运行调试会话而执行的命令(根据终端窗口):

This is the command that is executed to run the debug session (according to the terminal window):

'c:\Users\...\.vscode\extensions\ms-vscode.cpptools-0.27.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-2dvbqvix.1cb' '--stdout=Microsoft-MIEngine-Out-1m5j1iy0.ufe' '--stderr=Microsoft-MIEngine-Error-oqyothgz.h5l' '--pid=Microsoft-MIEngine-Pid-hal3wx4b.uld' '--dbgExe=C:/raylib/mingw/bin/gdb.exe' '--interpreter=mi'

调试控制台显示启动画面"GDB 的信息,但不会在我的代码中显示 printf() 语句的任何输出:

The Debug Console shows the "splash screen" info of GDB, but doesn't display any of the output from the printf() statements in my code:

=thread-group-added,id="i1"
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
[New Thread 9488.0x54dc]
[New Thread 9488.0x577c]
[New Thread 9488.0xff4]
[New Thread 9488.0x4918]

当我从命令行(Git Bash)使用 GDB 运行 Exe 文件时,所有输出都正常显示.

When I run the Exe file with GDB from the commandline (Git Bash), all the output is displayed normally.

externalConsole 设置为 true 不起作用(它也不会打开外部控制台).

Setting externalConsole to true doesn't work (it also doesn't open an external console to begin with).

我使用的是 Windows 10.

I'm on Windows 10.

是否需要调整任何特定设置才能使其正常工作?

Is there any specific setting I need to adjust for this to work?

推荐答案

我最终解决了这个问题.在我的 launch.json 中,我将 filterStdout 设置为 true(我知道这是默认值,但哈哈):https://code.visualstudio.com/docs/cpp/launch-json-reference#_filterstdout

I ended up somewhat fixing this. In my launch.json I set filterStdout to true (I know it's default but lol): https://code.visualstudio.com/docs/cpp/launch-json-reference#_filterstdout

filterStdout 设置为 false 会做同样的事情.所以我确定某处有错误.我相信目的是将其设置为 true 应该将 stdout 输出输入到调试控制台选项卡中.

Setting filterStdout to false does the same thing. So I'm sure there's a bug somewhere. I believe the intention is that setting it to true is supposed to get stdout output into the Debug Console tab.

现在,当我调用调用 printf 的方法时,我只需进入终端选项卡,瞧,我的调用在终端选项卡中!!!!

Now when I call my method that calls printf, I just go into the terminal tab and lo and behold my call is in the Terminal tab!!!!

这篇关于Visual Studio Code 中的 GDB 不向 stdout 显示 printf() 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆