我有这个确切的问题:https://github.com/Microsoft/vscode-cpptools/issues/511 https://github.com/Microsoft/vscode-cpptools/issues/511
但那里的解决方案不起作用。
我尝试过相同的简单示例代码,
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid = fork();
if (pid != 0) {
printf("Main process\n");
} else {
printf("Forked process\n");
}
return 0;
}
我使用 -g 进行编译,我的 launch.json 文件如下所示。
我单击“调试”,将断点设置到第一行。在第一站,我进入-exec set follow-fork-mode child
在调试控制台下,它给了我返回=cmd-param-changed,param="follow-fork-mode",value="child"
。那么它就行不通了。它转到父进程(pid 显示不为 0)。我尝试使用以下命令将其设置在 launch.json 文件本身中{"text": "-gdb-set follow-fork-mode child"}
,但这也行不通。
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceRoot}/a.exe",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe"
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}