我有这个问题: 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文件如下所示。
我单击debug,我将断点设置为第一行。在第一站,我在调试控制台下输入-exec set follow-fork-mode child
,它返回=cmd-param-changed,param="follow-fork-mode",value="child"
。然后它只是不起作用。它转到父进程(pid显示为0)。我已尝试使用{"text": "-gdb-set follow-fork-mode child"}
在launch.json文件中设置它,但这也不起作用。
{
"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
}
]
}
]
}
答案 0 :(得分:0)
我遇到了同样的问题,我解决了这个问题:
"setupCommands": [
{
"description": "Enable funcy printing to gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{ "description":"In this mode GDB will be attached to both processes after a call to fork() or vfork().",
"text": "-gdb-set detach-on-fork off",
"ignoreFailures": true
},
{ "description": "The new process is debugged after a fork. The parent process runs unimpeded.",
"text": "-gdb-set follow-fork-mode child",
"ignoreFailures": true
}
],