visual-studio-code - 在 WSL 中使用 GDB 进行调试时的输入/输出
问题描述
我已经开始在 Windows 上使用 Visual Studio Code 并且我想调试以下文件
main.c(位于C:/Users/aibrakov/Projects/c目录):
#include <stdio.h>
int main(void) {
int x = 42; // add breakpoint here
printf("Hello World!\n");
getchar();
return 0;
}
按照这个线程
- VS Code 中的 C\C++ 与适用于 Windows 的 Linux 子系统
- Visual Studio Code 和 Bash on Ubuntu on Windows (WSL) GCC/GDB 集成
我有
设置.json:
{
"window.zoomLevel": 0,
"terminal.integrated.shell.windows": "c:\\windows\\sysnative\\bash.exe"
}
任务.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build project",
"type": "shell",
"command": "gcc",
"args": [
"-g", "main.c"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
启动.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/c/Users/aibrakov/Projects/c/a.out",
"stopAtEntry": false,
"cwd": "/mnt/c/Users/aibrakov/Projects/c",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": [
"-c"
],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/c": "c:\\"
}
}
]
}
Ctrl使用++构建项目Shift成功B。
调试有点工作:它在断点处停止并且DEBUG CONSOLE
可以访问选项卡,但我没有得到输出(Hello World!
在我的示例中)并且也无法发送getchar
等待的字符。
有没有办法在我的程序运行的终端上工作?还是我错过了什么?
解决方案
推荐阅读
- swift - 使用游标递归函数从 CloudKit 获取所有记录 - 如何将结果传递到其范围之外?
- php - Shopify SDK - 导致内存泄漏的分页请求
- jupyter-notebook - Google Colab 磁盘空间已满
- rust - 将大浮点数转换为 int 时会发生什么?
- c# - Entity Framework Core DateTime 字段更新为 1/1/0001
- javascript - 将远程 GraphQL 查询包装到公共父级中
- for-loop - Python Matplotlib 添加2个动态标题组件
- android - 打印机上的文本大小不适用于 Android
- ruby-on-rails - 如何在 Windows 上调试 Paste?
- python - 将部分抓取过程置于循环中