public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* 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

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

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.  Until it does, there's very
little that GDB can do about this.  It assumes that clone using SIGCHLD
is not sharing a VM space, and clone using a different signal is.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

* Re: gdb 6.3 misses breakpoint on Linux when inferior does clone()
  2005-06-11 23:31   ` Mark Kettenis
@ 2005-06-12  0:23     ` Daniel Jacobowitz
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-06-12  0:23 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: tronics93-gdb, gdb

On Sun, Jun 12, 2005 at 01:31:38AM +0200, Mark Kettenis wrote:
>    Date: Wed, 1 Jun 2005 09:23:31 -0400
>    From: Daniel Jacobowitz <drow@false.org>
> 
>    On Tue, May 31, 2005 at 10:05:22AM -0700, tronics93-gdb@yahoo.com wrote:
>    > 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]);
> 
>    Only if you're stopped at the clone.  Hmm.  Good point; perhaps we can
>    recover them from registers when we receive the clone event.
> 
> But having to do that in a machine-dependent manner really sucks...
> 
>    It could probably be implemented if someone spent the time.
> 
> ...so that time is probably better spent on implementing the proper
> machine-independent functionality in the Linux kernel!

Except that what we implement in GDB, we don't need to test for at
runtime and handle dependencies on the kernel version.  For the special
case of CLONE_VM there's a third option, which may be superior: write
to one thread's memory and see where the value shows up.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

* Re: gdb 6.3 misses breakpoint on Linux when inferior does clone()
  2005-06-01 13:23 ` Daniel Jacobowitz
@ 2005-06-11 23:31   ` Mark Kettenis
  2005-06-12  0:23     ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Kettenis @ 2005-06-11 23:31 UTC (permalink / raw)
  To: drow; +Cc: tronics93-gdb, gdb

   Date: Wed, 1 Jun 2005 09:23:31 -0400
   From: Daniel Jacobowitz <drow@false.org>

   On Tue, May 31, 2005 at 10:05:22AM -0700, tronics93-gdb@yahoo.com wrote:
   > 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]);

   Only if you're stopped at the clone.  Hmm.  Good point; perhaps we can
   recover them from registers when we receive the clone event.

But having to do that in a machine-dependent manner really sucks...

   It could probably be implemented if someone spent the time.

...so that time is probably better spent on implementing the proper
machine-independent functionality in the Linux kernel!

Mark

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

* 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
  2005-06-11 23:31   ` Mark Kettenis
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-06-01 13:23 UTC (permalink / raw)
  To: tronics93-gdb; +Cc: gdb

On Tue, May 31, 2005 at 10:05:22AM -0700, tronics93-gdb@yahoo.com wrote:
> >> 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]);

Only if you're stopped at the clone.  Hmm.  Good point; perhaps we can
recover them from registers when we receive the clone event.

It could probably be implemented if someone spent the time.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

* 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, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-05-26 20:03 UTC (permalink / raw)
  To: Satish Mohan; +Cc: gdb

On Thu, May 26, 2005 at 01:02:28PM -0700, Satish Mohan wrote:
> 
> 
> -----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 ?

No, it does not.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ 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

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-26 19:40 gdb 6.3 misses breakpoint on Linux when inferior does clone() Satish Mohan
2005-05-26 19:43 ` Daniel Jacobowitz
2005-05-26 20:02 Satish Mohan
2005-05-26 20:03 ` Daniel Jacobowitz
2005-05-31 17:06 tronics93-gdb
2005-06-01 13:23 ` Daniel Jacobowitz
2005-06-11 23:31   ` Mark Kettenis
2005-06-12  0:23     ` 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).