This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
gdb 6.3 misses breakpoint on Linux when inferior does clone()
- From: "Satish Mohan" <Satish dot Mohan at Accenia dot com>
- To: <gdb at sources dot redhat dot com>
- Cc: "Satish Mohan" <Satish dot Mohan at accenia dot com>
- Date: Thu, 26 May 2005 12:40:39 -0700
- Subject: gdb 6.3 misses breakpoint on Linux when inferior does clone()
Hi
?If the inferior does a clone(...,CLONE_VM,...) on Linux, then gdb deletes breakpoints in the child which indirectly affects the parent because of CLONE_VM. The following sample code illustrates the problem:
int mythread (void * unused)
{
?? printf("my thread running\n");
?? return 0;
}
int main (int argc, char **argv)
{
?? int status, pid;
?? char * stack = (char *)malloc(4096);
?? if ((pid = clone (mythread, (char *)(stack + 4096 - 4),
CLONE_VM | SIGCHLD, 0)) == -1)
?? {
?????? printf("clone failed, errno=%d\n", errno);
?????? return -1;
?? }
?? if (waitpid(pid, &status, 0) == -1)
{
?????? perror("waitpid failed\n");
?????? return -1;
?? }
}
If a breakpoint is set on the waitpid() call above, then gdb misses it. This seems to be because gdb deletes breakpoints in the child after the clone() but doesn't seem to know that CLONE_VM is set, and that the breakpoints will also get deleted from the parent.
Commenting the detach_breakpoints(child_pid) in child_follow_fork() in linux-nat.c fixes the problem as long as parent and child don't execute the same code after clone.
Is this a gdb bug ? Could anyone let me know the right fix for this ?
Thanks,
Satish Mohan.