public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Re: gdb 6.3 misses breakpoint on Linux when inferior does clone()
@ 2005-05-31 17:06 tronics93-gdb
  2005-06-01 13:23 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: tronics93-gdb @ 2005-05-31 17:06 UTC (permalink / raw)
  To: gdb

>> The kernel does not provide any interface for GDB to know whether
or
>> not a clone syscall has used CLONE_VM.   
>> 
>> [Satish] Doesn't ptrace(PTRACE_GETREGS,...) provide that
information >>? Or is that arch. specific ?

>No, it does not.

The following code snippet gets the flags passed in to clone() (on
x86):

   unsigned long regs[FRAME_SIZE];

   if (ptrace(PTRACE_GETREGS, pid, 0, &regs) < 0)
        perror("ptrace_getregs failed:");

   printf("syscall=%d, arg1=%#x, arg2=%#x\n", regs[ORIG_EAX], 
                              regs[EBX], regs[ECX]);

--tronics93.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: gdb 6.3  misses breakpoint on Linux when inferior does clone()
@ 2005-05-26 20:02 Satish Mohan
  2005-05-26 20:03 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Satish Mohan @ 2005-05-26 20:02 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb



-----Original Message-----
From: Daniel Jacobowitz [mailto:drow@false.org] 
Sent: Thursday, May 26, 2005 12:44 PM
To: Satish Mohan
Cc: gdb@sources.redhat.com
Subject: Re: gdb 6.3 misses breakpoint on Linux when inferior does clone()

On Thu, May 26, 2005 at 12:40:39PM -0700, Satish Mohan wrote:
> 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:

The kernel does not provide any interface for GDB to know whether or
not a clone syscall has used CLONE_VM.   

[Satish] Doesn't ptrace(PTRACE_GETREGS,...) provide that information ? Or is that arch. specific ?

Thx
--satish

^ permalink raw reply	[flat|nested] 8+ messages in thread
* gdb 6.3  misses breakpoint on Linux when inferior does clone()
@ 2005-05-26 19:40 Satish Mohan
  2005-05-26 19:43 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Satish Mohan @ 2005-05-26 19:40 UTC (permalink / raw)
  To: gdb; +Cc: Satish Mohan

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-06-12  0:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-31 17:06 gdb 6.3 misses breakpoint on Linux when inferior does clone() tronics93-gdb
2005-06-01 13:23 ` Daniel Jacobowitz
2005-06-11 23:31   ` Mark Kettenis
2005-06-12  0:23     ` Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2005-05-26 20:02 Satish Mohan
2005-05-26 20:03 ` Daniel Jacobowitz
2005-05-26 19:40 Satish Mohan
2005-05-26 19:43 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).