Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: pedro@codesourcery.com
Cc: gdb@sourceware.org, drow@false.org
Subject: Re: Regression
Date: Tue, 10 Feb 2009 18:40:00 -0000	[thread overview]
Message-ID: <200902101839.n1AId4Mb031903@brahms.sibelius.xs4all.nl> (raw)
In-Reply-To: <200902101800.35832.pedro@codesourcery.com> (message from Pedro 	Alves on Tue, 10 Feb 2009 18:00:35 +0000)

> From: Pedro Alves <pedro@codesourcery.com>
> Date: Tue, 10 Feb 2009 18:00:35 +0000

Thanks Pedro, for looking into this!

> Opps, my logs didn't show something as clearly as I indended:
> 
> >  $1 = (void (*)()) 0xa43a633 <printf+19>
> 
>  vs 
> 
> >  infrun: stop_pc = 0xeff4636
> 
> > Here, it seems like telling BSD to single-step, and, to deliver
> > a signal at the same time, just single-steps, resulting in a SIGTRAP.
> 
> Errr, here it tells that I re-ran the inferior to get first PC, after
> having pased the stop_pc bit already, from a previous run.  Different runs,
> different PCs, notice the randomization affecting the first bytes of the
> addresses.  Sorry for any confusion it may have caused.
> 
> Here's a run, to show how OpenBSD forgets to single-step into
> the handler:
> 
>  (gdb) p $pc
>  $1 = (void (*)()) 0x51b0633 <printf+19>
>  (gdb) signal SIGUSR1
>  Continuing with signal SIGUSR1.
>  infrun: clear_proceed_status_thread (process 18606)
>  infrun: proceed (addr=0xffffffff, signal=30, step=0)
>  infrun: resume (step=1, signal=30), trap_expected=1
>  infrun: wait_for_inferior (treat_exec_as_sigtrap=0)
>  infrun: target_wait (-1, status) = 18606, status->kind = stopped, signal = SIGTRAP
>  infrun: infwait_normal_state
>  infrun: TARGET_WAITKIND_STOPPED
>  infrun: stop_pc = 0x51b0636
> 
> Then, I've added a printf in the signal handler itself, to see
> if it runs at all:
> 
>  (gdb) signal SIGUSR1
>  Continuing with signal SIGUSR1.
>  infrun: clear_proceed_status_thread (process 1505)
>  infrun: proceed (addr=0xffffffff, signal=30, step=0)
>  infrun: resume (step=1, signal=30), trap_expected=1
>  infrun: wait_for_inferior (treat_exec_as_sigtrap=0)
>  handle_USR1
>  ^^^^^^^^^^^ (1)
>  infrun: target_wait (-1, status) = 1505, status->kind = stopped, signal = SIGTRAP
>  infrun: infwait_normal_state
>  infrun: TARGET_WAITKIND_STOPPED
>  infrun: stop_pc = 0x6919636
>  infrun: no stepping, continue
>  infrun: resume (step=0, signal=0), trap_expected=0
>  ^^^^^^^^^^^^^^ (2)
>  infrun: prepare_to_wait
>  my_array[2] is 3
>  infrun: target_wait (-1, status) = 1505, status->kind = exited, status = 0
>  infrun: infwait_normal_state
>  infrun: TARGET_WAITKIND_EXITED
> 
> So, it does run, according to (1) above, but, since we were stepping
> over a breakpoint notice (trap_expected=1), GDB had removed breakpoints
> from the inferior.  They're only inserted on the following resume, at (2).
> That's why you miss the breakpoint in the signal handler.
> 
> Without Daniel's patch, "signal FOO" *would not remove breakpoints*, since
> it was calling `proceed' like if it was a "jump".
> 
> Here's the same on i386-linux:
> 
>  Breakpoint 1, 0x00007ffff784ae40 in printf () from /lib/libc.so.6
>  (gdb) set debug infrun 1
>  (gdb) signal SIGUSR1
>  Continuing with signal SIGUSR1.
>  infrun: clear_proceed_status_thread (process 17569)
>  infrun: proceed (addr=0xffffffffffffffff, signal=30, step=0)
>  infrun: resume (step=1, signal=30), trap_expected=1
>  infrun: wait_for_inferior (treat_exec_as_sigtrap=0)
>  infrun: target_wait (-1, status) = 17569, status->kind = stopped, signal = SIGTRAP
>  infrun: infwait_normal_state
>  infrun: TARGET_WAITKIND_STOPPED
>  infrun: stop_pc = 0x400528
>          ^^^^^^^^^^^^^^^^^^
>  infrun: no stepping, continue
>  infrun: resume (step=0, signal=0), trap_expected=0
>  infrun: prepare_to_wait
>  infrun: target_wait (-1, status) = 17569, status->kind = stopped, signal = SIGTRAP
>  infrun: infwait_normal_state
>  infrun: TARGET_WAITKIND_STOPPED
>  infrun: stop_pc = 0x40052f
>  infrun: BPSTAT_WHAT_STOP_NOISY
>  infrun: stop_stepping
> 
>  Breakpoint 2, handle_USR1 (sig=10) at ../../../src/gdb/testsuite/gdb.base/annota1.c:19
>  19      }
> 
> That stop was a finished single-step to the start of the signal handler:
> 
>  (gdb) disassemble 0x400528 (0x400528 + 100)
>  Dump of assembler code from 0x400528 to 0x40058c:
>  0x0000000000400528 <handle_USR1+0>:     push   %rbp
>  0x0000000000400529 <handle_USR1+1>:     mov    %rsp,%rbp
>  0x000000000040052c <handle_USR1+4>:     mov    %edi,-0x4(%rbp)
>  0x000000000040052f <handle_USR1+7>:     leaveq
>  0x0000000000400530 <handle_USR1+8>:     retq
>  (...)
> 
> So, linux can single-step into a signal handler, OpenBSD doesn't.

Indeed.  OpenBSD/i386 (as well as NetBSD, FreeBSD and probably Darwin)
clears the trace bit before running the signal handler.

I've looked at the PR mentioned in the commi message, and I don't
quite understand how the change to the signal command has anything to
do with that.


  reply	other threads:[~2009-02-10 18:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10 15:17 Regression Mark Kettenis
2009-02-10 15:27 ` Regression Daniel Jacobowitz
2009-02-10 15:47   ` Regression Mark Kettenis
2009-02-10 16:06     ` Regression Pedro Alves
2009-02-10 16:18       ` Regression Tristan Gingold
2009-02-10 18:00       ` Regression Pedro Alves
2009-02-10 18:40         ` Mark Kettenis [this message]
2009-02-10 19:05           ` Regression Pedro Alves
2009-02-10 19:18             ` Regression Pedro Alves
2009-02-10 19:27               ` Regression Pedro Alves
2009-02-11 15:50                 ` Regression Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2009-02-10 15:14 Regression Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200902101839.n1AId4Mb031903@brahms.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=drow@false.org \
    --cc=gdb@sourceware.org \
    --cc=pedro@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox