Leo*_*iro 5 c debugging cygwin visual-studio-code
我正在尝试设置 VSCODE 以使用 Cygwin64 在 Windows 上调试C 程序。
我使用了 @stephw 建议的配置(在 Windows 上使用 Cygwin64 编译器和调试器设置 C 的 VS 代码),但它对我不起作用。
我无法评论原始帖子,因为我没有足够的声誉点,并且我无法回答,因为我不知道原始问题的答案。
脚本的名称是dirigir.c,我可以编译。创建文件 dirigir.exe。但...
我收到以下错误:
错误:无法开始调试。命令“-exec-run”出现意外的 GDB 输出。创建进程 /usr/bin/E:\cloud\Backup\Trabalhos com 程序\C 和 Cpp\scripts/e:\cloud\Backup\Trabalhos com 程序\C 和 Cpp\scripts\dirigir.exe 时出错,(错误 2) 。
由于某种原因,/usr/bin/ ... /被插入到路径中,并且 .exe 的路径是重复的。
我的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": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "%PATH%;z:\\cygwin64\\bin"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": { "engineLogging": true }, //optional
"preLaunchTask": "gcc.exe build active file"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的tasks.json
如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-g",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-Werror", // Optional
"-Wall", // Optional
"-Wextra", // Optional
"-ansi", // Optional
"-pedantic", // Optional
"${file}"
],
"options": {
"cwd": "C:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
]
}
Run Code Online (Sandbox Code Playgroud)
您知道如何继续吗?先感谢您。
最后,我成功了。
\n基于 WardenGnaw 在这个线程中的答案:\n [cppdbg] Cygwin 10.1-1: intereratedTerminal无法接受输入#6475,当然,@stephw\在这个问题所依据的原始问题中的答案,我可以调试我的 C 程序。
\n首先,我在C 程序所在的同一文件夹中保存了 VSCODE工作区。
\n然后,我使用了最新的Cygwin gdb版本(10.2-1)。不起作用(我收到了提出这个问题的错误消息)。然后,我尝试了9.2-1,现在它可以工作了。
\n\n请务必记住将“C:\\cygwin64\\bin”添加到 PATH。
\n\n我改变了launch.json
一点点。请注意,“preLaunchTask”键的值与“label”键的值不完全相同tasks.json
:
{\n // Use IntelliSense to learn about possible attributes.\n // Hover to view descriptions of existing attributes.\n // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n "version": "0.2.0",\n "configurations": [\n {\n "name": "gcc.exe build and debug active file",\n "type": "cppdbg",\n "request": "launch",\n "program": "${fileDirname}\\\\${fileBasenameNoExtension}.exe",\n "args": [],\n "stopAtEntry": false,\n "cwd": "${workspaceFolder}",\n "environment": [\n {\n "name": "PATH",\n "value": "%PATH%;C:\\\\cygwin64\\\\bin"\n }\n ],\n "externalConsole": false,\n "MIMode": "gdb",\n "miDebuggerPath": "C:\\\\cygwin64\\\\bin\\\\gdb.exe",\n "setupCommands": [\n {\n "description": "Enable pretty-printing for gdb",\n "text": "-enable-pretty-printing",\n "ignoreFailures": true\n }\n ],\n "logging": { "engineLogging": true }, //optional\n "preLaunchTask": "gcc.exe build active file"\n }\n ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n我的tasks.json
是这个(注意最后我的名字,在“详细信息”键中):
{\n "version": "2.0.0",\n "tasks": [\n {\n "type": "cppbuild",\n "label": "C/C++: gcc.exe build active file",\n "command": "C:\\\\cygwin64\\\\bin\\\\gcc.exe",\n "args": [\n "-fdiagnostics-color=always",\n "-g",\n "${file}",\n "-o",\n "${fileDirname}\\\\${fileBasenameNoExtension}.exe"\n ],\n "options": {\n "cwd": "${fileDirname}"\n },\n "problemMatcher": [\n "$gcc"\n ],\n "group": "build",\n "detail": "Task generated by Leonardo."\n }\n ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n我注意到有些奇怪的事情:\n当我按 F5 时,它不起作用,因为找不到创建的任务。
\n\n当我将launch.json
文件(preLaunchTask 键)编辑为文件中完全相同的值时tasks.json
,“未找到”错误消失,但调试过程不会启动。
"preLaunchTask": "C/C++: gcc.exe build active file"\n
Run Code Online (Sandbox Code Playgroud)\n如果我按“运行并调试播放”按钮,调试过程也不起作用。
\n\n当我使用命令面板(按 CTRL+SHIFT+P)并单击 时C/C++: Build and Debug Active File
,
程序已编译并开始调试过程。
\n这是我非常简单的测试脚本:
\n#include <stdio.h>\n#include <stdlib.h>\n\nint main() {\n\n /* declare and initialize string */\n char myString[] = "This is an example of string declaration!";\n\n /* print string */\n printf("%s", myString);\n\n int numberA = 5;\n int numberB = 10;\n\n int sum = numberA + numberB;\n\n /* Printing a number */\n printf("A soma de numberA + numberB \xc3\xa9: %d", sum);\n\n return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n我希望这个问题和答案可以帮助将来的人。和平。
\n 归档时间: |
|
查看次数: |
3816 次 |
最近记录: |