Re: More trouble with i386 EFLAGS and ptrace

From: Daniel Jacobowitz (dan_at_debian.org)
Date: 03/06/05

  • Next message: Michael S. Tsirkin: "[PATCH] disable MSI for AMD-8131"
    Date:	Sun, 6 Mar 2005 15:26:41 -0500
    To: Linus Torvalds <torvalds@osdl.org>, linux-kernel@vger.kernel.org, Andrew Cagney <cagney@redhat.com>
    
    

    On Sun, Mar 06, 2005 at 02:38:41PM -0500, Daniel Jacobowitz wrote:
    > 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.

    Eh, I got the event sequence wrong as usual, but the basic description
    is right.

    - Original SIGTRAP at breakpoint
    - user says "cont"
    - GDB tries to singlestep past the breakpoint - PTRACE_SINGLESTEP, no
      signal
    - GDB receives SIGALRM at the same PC
    - GDB tries to singlestep past the breakpoint - PTRACE_SINGLESTEP,
      SIGALRM
    - GDB receives SIGTRAP at the first instruction of the handler
    - GDB reinserts the breakpoint at line 18. This is a "step-resume"
      breakpoint - we were stepping, we were interrupted by a signal.
    - GDB issues PTRACE_CONT, no signal
    - GDB receives SIGTRAP at the sigreturn location - this is the
      step-resume breakpoint.
    - GDB remove that and issues PTRACE_SINGLESTEP, no signal - It
      is trying again to get past the breakpoint location so that it
      can honor the user's "cont" request.
    - GDB receives SIGTRAP at the instruction after the breakpoint.
    - GDB reinserts the original breakpoint and issues PTRACE_CONTINUE.

    All of this is what's supposed to happen. The executable be running
    free now until it hits the breakpoint again.

    - GDB receives an unexpected SIGTRAP at the next instruction (the
      second instruction after the original breakpoint).

    If your compiler uses only two instructions for the loop, you might not
    see this. gcc -O0 will use three by default. Just stick something
    else in the loop.

    > 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).

    If I'm following this right, then the saved value of eflags in the
    signal handler should not contain the trap bit at this point. It does,
    though. It's hard to see this in GDB, because the CFI does not express
    %eflags, so "print $eflags" won't track up the stack. I don't think
    there's a handy dwarf register number for it at the moment. But you
    can print out the struct sigcontext by hand once you locate it on the
    stack.

    -- 
    Daniel Jacobowitz
    CodeSourcery, LLC
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Michael S. Tsirkin: "[PATCH] disable MSI for AMD-8131"

    Relevant Pages

    • [PATCH 9/21] KGDB: This adds basic support to the MIPS architecture
      ... This patch also adds support for the rs232 early kgdb access for MIPS ... * To enable debugger support, ... * or error conditions to be properly intercepted and reported to gdb. ... a breakpoint needs to be generated to begin communication. ...
      (Linux-Kernel)
    • Re: When is SIGTRAP raised?
      ... in gdb, gdb shows the signal as having been raised at the point at ... what could be reason for the SIGTRAP being rasied here? ... The user asks gdb to set a breakpoint at a certain address in the ... When the target process hits that address, ...
      (comp.os.linux.development.apps)
    • Re: [Kgdb-bugreport] [PATCH][3/3] Update CVS KGDBs wrt connect / detach
      ... >>If gdb is restarted, kgdb has to remove all breakpoints. ... >>We have to check for gdb connection in putpacket or else following problem ... Once connected and running, ^C/hit breakpoint and ...
      (Linux-Kernel)
    • Re: [Kgdb-bugreport] [KGDB PATCH][2/7] Serial updates, take 2
      ... >>(i.e. we're trying to send something while gdb wants to break in). ... If you don't break out of put_packet, kgdb will ... > patch) should check to see if the CURRENT cpu is in the kgdb console code ... > The problem is that you are now doing a breakpoint from inside kgdb while ...
      (Linux-Kernel)
    • Re: [Kgdb-bugreport] [KGDB PATCH][2/7] Serial updates, take 2
      ... Would this be to ensure that we only schedule one breakpoint not 2? ... (i.e. we're trying to send something while gdb wants to break in). ... it's OK to give up on the console packet (it's not ...
      (Linux-Kernel)