public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: More trouble with i386 EFLAGS and ptrace
@ 2005-03-14  4:06 Jesse Allen
  0 siblings, 0 replies; 15+ messages in thread
From: Jesse Allen @ 2005-03-14  4:06 UTC (permalink / raw)
  To: linux-kernel

Roland, Daniel,

I was the one that reported the ptrace problems which caused all that
hoopla in Nov and Dec.  I have tested your new patches and find that
there are no new regressions.

Jesse

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: More trouble with i386 EFLAGS and ptrace
@ 2005-03-14  4:12 Jesse Allen
  0 siblings, 0 replies; 15+ messages in thread
From: Jesse Allen @ 2005-03-14  4:12 UTC (permalink / raw)
  To: linux-kernel

Andi Kleen wrote:
> > Once we're sure about the i386 state, we should update the x86_64 code to match.
>
> I have it fixed in my tree, but not pushed out yet because of lack of testing.

Andi,

I have someone who thinks they might be experiencing the same problem
that I reported but now on x86-64.  Could I get the patches from your
tree so they can be tested?

Jesse

^ permalink raw reply	[flat|nested] 15+ messages in thread
* More trouble with i386 EFLAGS and ptrace
@ 2005-03-06 19:38 Daniel Jacobowitz
  2005-03-06 20:03 ` Linus Torvalds
  2005-03-06 20:26 ` Daniel Jacobowitz
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2005-03-06 19:38 UTC (permalink / raw)
  To: Linus Torvalds, linux-kernel; +Cc: Andrew Cagney

It looks like the changes to preserve eflags when single-stepping don't work
right with signals.  Take this test case:

<snip>
#include <signal.h>
#include <unistd.h>

volatile int done;

void handler (int sig)
{
  done = 1;
}

int main()
{
  while (1)
    {
      done = 0;
      signal (SIGALRM, handler);
      alarm (1);
      while (!done);
    }
}
<snip>

And this GDB session:

(gdb) b 18
Breakpoint 1 at 0x804840d: file test.c, line 18.
(gdb) r
Starting program: /home/drow/eflags/test

Breakpoint 1, main () at test.c:18
18            while (!done);
(gdb) p/x $eflags
$1 = 0x200217
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x08048414 in main () at test.c:18
18            while (!done);
(gdb) p/x $eflags
$2 = 0x200302

There's an implied delay before the "c" which is long enough for the signal
handler to become pending.

The reason this happens is that when the inferior hits a breakpoint, the
first thing GDB will do is remove the breakpoint, single-step past it, and
reinsert it.  So GDB does a PTRACE_SINGLESTEP, and the kernel invokes the
signal handler (without single-step - good so far).  When the signal handler
returns, we've lost track of the fact that ptrace set the single-step flag,
however.  So the single-step completes and returns SIGTRAP to GDB.  GDB is
expecting a SIGTRAP and reinserts the breakpoint.  Then it resumes the
inferior, but now the trap flag is set in $eflags.  So, oops, the continue
acts like a step instead.

What to do?  We need to know when we restore the trap bit in sigreturn
whether it was set by ptrace or by the application (possibly including by
the signal handler).

Andrew, serious kudos for GDB's sigstep.exp, which uncovered this problem
(through a much more complicated test - I may add the smaller one).

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

end of thread, other threads:[~2005-03-14  5:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-14  4:06 More trouble with i386 EFLAGS and ptrace Jesse Allen
  -- strict thread matches above, loose matches on Subject: below --
2005-03-14  4:12 Jesse Allen
2005-03-06 19:38 Daniel Jacobowitz
2005-03-06 20:03 ` Linus Torvalds
2005-03-06 21:14   ` Daniel Jacobowitz
2005-03-07  0:46     ` Linus Torvalds
2005-03-06 21:22   ` Roland McGrath
2005-03-06 22:13     ` Daniel Jacobowitz
     [not found]       ` <200503070316.j273Gb4G027048@magilla.sf.frob.com>
2005-03-07  4:49         ` Daniel Jacobowitz
2005-03-07 21:29           ` Roland McGrath
2005-03-09  0:12             ` Daniel Jacobowitz
2005-03-13  8:27               ` Roland McGrath
2005-03-13 20:06                 ` Daniel Jacobowitz
2005-03-07 19:13     ` Andi Kleen
2005-03-06 20:26 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox