Skip to content

[GDB]Can’t hit the breakpoint in child process after "-exec set follow-fork-mode child" #2738

@losttem

Description

@losttem

Type: Debugger

i want to debug child process created by fork() and i use "-exec set follow-fork-mode child" before the fork() is called, but i found it doesn't work at all, it can't hit any break point in child process. Then i use the simple program in #511 to test, not work too.The answer in #511 doesn't work too.( "setupCommands": [
{"text": "-gdb-set follow-fork-mode child"}
])

simple program that i use to test(see #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;
}

launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

build task:
{
"version": "2.0.0",
"tasks": [
{
"label": "forktest compile task",
"type": "shell",
"command": "gcc -g forktest.c",
"group": {
"kind": "build",
"isDefault": true
}
}
],
}

here is debug console output:
=thread-group-added,id="i1"
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7
Copyright (C) 2013 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Loaded '/lib64/libc.so.6'. Symbols loaded.
Execute debugger commands using "-exec ", for example "-exec info registers" will list registers in use (when GDB is the debugger)

-exec set follow-fork-mode child
=cmd-param-changed,param="follow-fork-mode",value="child"
=thread-group-added,id="i2"
[New process 24823]
[Switching to process 24823]

Metadata

Metadata

Assignees

Labels

bugdebuggerfixedCheck the Milestone for the release in which the fix is or will be available.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions