gdb 6.3 misses breakpoint on Linux when inferior does clone()

Satish Mohan Satish.Mohan@Accenia.com
Thu May 26 19:40:00 GMT 2005


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.



More information about the Gdb mailing list