Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfc] sigstep additions
@ 2004-08-11  0:14 Andrew Cagney
  2004-08-12  1:59 ` Andrew Cagney
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2004-08-11  0:14 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

Hello,

This adds more step tests to sigstep.exp.  They pass on a ``fixed'' PPC 
kernel but the breakpoint tests fail on a ``fixed'' i386 kernel.

Can people please test this on their various systems.

Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 8137 bytes --]

2004-08-10  Andrew Cagney  <cagney@gnu.org>

	* gdb.base/sigstep.exp (breakpoint_to_handler)
	(skip_over_handler, skip_to_handler): New test procedures.
	(advance, advancei): Add a proper prefix, do not use
	rerun_to_main.
	* gdb.base/sigstep.c (main): Change to use an infinite loop.

Index: testsuite/gdb.base/sigstep.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.c,v
retrieving revision 1.2
diff -p -u -r1.2 sigstep.c
--- testsuite/gdb.base/sigstep.c	5 Aug 2004 07:28:20 -0000	1.2
+++ testsuite/gdb.base/sigstep.c	11 Aug 2004 00:12:07 -0000
@@ -31,27 +31,38 @@ handler (int sig)
   done = 1;
 } /* handler */
 
+struct itimerval itime;
+struct sigaction action;
+
+/* The enum is so that GDB can easily see these macro values.  */
+enum {
+  itimer_real = ITIMER_REAL,
+  itimer_virtual = ITIMER_VIRTUAL
+} itimer = ITIMER_VIRTUAL;
+
 main ()
 {
+
   /* Set up the signal handler.  */
-  {
-    struct sigaction action;
-    memset (&action, 0, sizeof (action));
-    action.sa_handler = handler;
-    sigaction (SIGVTALRM, &action, NULL);
-  }
+  memset (&action, 0, sizeof (action));
+  action.sa_handler = handler;
+  sigaction (SIGVTALRM, &action, NULL);
+  sigaction (SIGALRM, &action, NULL);
 
-  /* Set up a one-off timer.  A timer, rather than SIGSEGV, is used as
-     after a timer handler finishes the interrupted code can safely
-     resume.  */
-  {
-    struct itimerval itime;
-    memset (&itime, 0, sizeof (itime));
-    itime.it_value.tv_usec = 250 * 1000;
-    setitimer (ITIMER_VIRTUAL, &itime, NULL);
-  }
+  /* The values needed for the itimer.  This needs to be at least long
+     enough for the setitimer() call to return.  */
+  memset (&itime, 0, sizeof (itime));
+  itime.it_value.tv_usec = 250 * 1000;
 
-  /* Wait.  */
-  while (!done);
-  return 0;
-} /* main */
+  /* Loop for ever, constantly taking an interrupt.  */
+  while (1)
+    {
+      /* Set up a one-off timer.  A timer, rather than SIGSEGV, is
+	 used as after a timer handler finishes the interrupted code
+	 can safely resume.  */
+      setitimer (itimer, &itime, NULL);
+      /* Wait.  */
+      while (!done);
+      done = 0;
+    }
+}
Index: testsuite/gdb.base/sigstep.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.exp,v
retrieving revision 1.4
diff -p -u -r1.4 sigstep.exp
--- testsuite/gdb.base/sigstep.exp	9 Aug 2004 13:16:16 -0000	1.4
+++ testsuite/gdb.base/sigstep.exp	11 Aug 2004 00:12:07 -0000
@@ -16,10 +16,11 @@
 
 
 # The program sigstep.c creates a very simple backtrace containing one
-# signal handler and signal trampoline.
+# signal handler and signal trampoline.  A flag is set and then the
+# handler returns.  This is repeated at infinitum.
 
 # This test runs the program up to the signal handler, and then
-# attempts to step/next the inferior back to main.
+# attempts to step/next out of the handler and back into main.
 
 if [target_info exists gdb,nosignals] {
     verbose "Skipping sigstep.exp because of nosignals."
@@ -71,12 +72,12 @@ gdb_expect_list "backtrace for nexti" ".
 
 proc advance { i } {
     global gdb_prompt
+    set prefix "$i from handler"
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i out of handler"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
 	-re "done = 1;.*${gdb_prompt} $" {
 	    send_gdb "$i\n"
@@ -90,7 +91,7 @@ proc advance { i } {
 	    setup_kfail powerpc-*-*bsd* gdb/1639
 	    fail "$test (program exited)"
 	}
-	-re "(while ..done|return 0).*${gdb_prompt} $" {
+	-re "(while ..done|done = 0).*${gdb_prompt} $" {
 	    # After stepping out of a function /r signal-handler, GDB will
 	    # advance the inferior until it is at the first instruction of
 	    # a code-line.  While typically things return to the middle of
@@ -104,13 +105,13 @@ proc advance { i } {
 
 proc advancei { i } {
     global gdb_prompt
+    set prefix "$i from handleri"
     set program_exited 0
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i into signal trampoline"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
         -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
             # Some platforms use a special read-only page for signal
@@ -144,7 +145,7 @@ proc advancei { i } {
 	}
     }
 
-    set test "$i out of signal trampoline"
+    set test "$prefix; leave signal trampoline"
     gdb_test_multiple "$i" "${test}" {
 	-re "while .*${gdb_prompt} $" {
 	    pass "$test (in main)"
@@ -175,6 +176,8 @@ proc advancei { i } {
     }
 }
 
+# Check that we can step/next our way out of a signal handler.
+
 advance step
 advancei stepi
 
@@ -183,3 +186,114 @@ advancei nexti
 
 advancei finish
 advancei return
+gdb_test "set done = 1" "" "Set done as return will have skipped it"
+
+
+# Check that we can step/next our way into a signal handler.
+
+# Use the real-time itimer, as otherwize the process never gets enough
+# time to expire the timer.
+
+delete_breakpoints
+set infinite_loop [gdb_get_line_number {while (!done)}]
+gdb_test "set itimer = itimer_real"
+gdb_test "break [gdb_get_line_number {done = 0}]"
+
+
+# Try single-stepping when there's a signal pending, a breakpoint at
+# the current instruction and a breakpoint in the handler.
+
+proc skip_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "break handler" "" "$prefix; break handler"
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+skip_to_handler step
+skip_to_handler next
+skip_to_handler continue
+
+
+# Try single-stepping et.al. when the handler is a no-op.
+
+proc skip_over_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i over handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "$i" "done = 0.*" "$prefix; performing $i"
+}
+
+skip_over_handler step
+skip_over_handler next
+skip_over_handler continue
+
+
+# Try single instruction stepping when there's a signal pending and a
+# breakpoint in the handler.
+
+proc breakpoint_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i breakpoint to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
+    gdb_test "break handler" "" "$prefix; break handler"
+
+    # Continue to the infinite loop
+    gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+breakpoint_to_handler step
+breakpoint_to_handler next
+breakpoint_to_handler continue

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

* Re: [rfc] sigstep additions
  2004-08-11  0:14 [rfc] sigstep additions Andrew Cagney
@ 2004-08-12  1:59 ` Andrew Cagney
  2004-08-12 17:15   ` Michael Chastain
  2004-08-20 11:02   ` Michael Chastain
  0 siblings, 2 replies; 8+ messages in thread
From: Andrew Cagney @ 2004-08-12  1:59 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 43 bytes --]

I'd like to turn this into an RFA.

Andrew

[-- Attachment #2: Attached Message --]
[-- Type: message/rfc822, Size: 11689 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 209 bytes --]

Hello,

This adds more step tests to sigstep.exp.  They pass on a ``fixed'' PPC 
kernel but the breakpoint tests fail on a ``fixed'' i386 kernel.

Can people please test this on their various systems.

Andrew

[-- Attachment #2.1.2: diffs --]
[-- Type: text/plain, Size: 8137 bytes --]

2004-08-10  Andrew Cagney  <cagney@gnu.org>

	* gdb.base/sigstep.exp (breakpoint_to_handler)
	(skip_over_handler, skip_to_handler): New test procedures.
	(advance, advancei): Add a proper prefix, do not use
	rerun_to_main.
	* gdb.base/sigstep.c (main): Change to use an infinite loop.

Index: testsuite/gdb.base/sigstep.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.c,v
retrieving revision 1.2
diff -p -u -r1.2 sigstep.c
--- testsuite/gdb.base/sigstep.c	5 Aug 2004 07:28:20 -0000	1.2
+++ testsuite/gdb.base/sigstep.c	11 Aug 2004 00:12:07 -0000
@@ -31,27 +31,38 @@ handler (int sig)
   done = 1;
 } /* handler */
 
+struct itimerval itime;
+struct sigaction action;
+
+/* The enum is so that GDB can easily see these macro values.  */
+enum {
+  itimer_real = ITIMER_REAL,
+  itimer_virtual = ITIMER_VIRTUAL
+} itimer = ITIMER_VIRTUAL;
+
 main ()
 {
+
   /* Set up the signal handler.  */
-  {
-    struct sigaction action;
-    memset (&action, 0, sizeof (action));
-    action.sa_handler = handler;
-    sigaction (SIGVTALRM, &action, NULL);
-  }
+  memset (&action, 0, sizeof (action));
+  action.sa_handler = handler;
+  sigaction (SIGVTALRM, &action, NULL);
+  sigaction (SIGALRM, &action, NULL);
 
-  /* Set up a one-off timer.  A timer, rather than SIGSEGV, is used as
-     after a timer handler finishes the interrupted code can safely
-     resume.  */
-  {
-    struct itimerval itime;
-    memset (&itime, 0, sizeof (itime));
-    itime.it_value.tv_usec = 250 * 1000;
-    setitimer (ITIMER_VIRTUAL, &itime, NULL);
-  }
+  /* The values needed for the itimer.  This needs to be at least long
+     enough for the setitimer() call to return.  */
+  memset (&itime, 0, sizeof (itime));
+  itime.it_value.tv_usec = 250 * 1000;
 
-  /* Wait.  */
-  while (!done);
-  return 0;
-} /* main */
+  /* Loop for ever, constantly taking an interrupt.  */
+  while (1)
+    {
+      /* Set up a one-off timer.  A timer, rather than SIGSEGV, is
+	 used as after a timer handler finishes the interrupted code
+	 can safely resume.  */
+      setitimer (itimer, &itime, NULL);
+      /* Wait.  */
+      while (!done);
+      done = 0;
+    }
+}
Index: testsuite/gdb.base/sigstep.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.exp,v
retrieving revision 1.4
diff -p -u -r1.4 sigstep.exp
--- testsuite/gdb.base/sigstep.exp	9 Aug 2004 13:16:16 -0000	1.4
+++ testsuite/gdb.base/sigstep.exp	11 Aug 2004 00:12:07 -0000
@@ -16,10 +16,11 @@
 
 
 # The program sigstep.c creates a very simple backtrace containing one
-# signal handler and signal trampoline.
+# signal handler and signal trampoline.  A flag is set and then the
+# handler returns.  This is repeated at infinitum.
 
 # This test runs the program up to the signal handler, and then
-# attempts to step/next the inferior back to main.
+# attempts to step/next out of the handler and back into main.
 
 if [target_info exists gdb,nosignals] {
     verbose "Skipping sigstep.exp because of nosignals."
@@ -71,12 +72,12 @@ gdb_expect_list "backtrace for nexti" ".
 
 proc advance { i } {
     global gdb_prompt
+    set prefix "$i from handler"
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i out of handler"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
 	-re "done = 1;.*${gdb_prompt} $" {
 	    send_gdb "$i\n"
@@ -90,7 +91,7 @@ proc advance { i } {
 	    setup_kfail powerpc-*-*bsd* gdb/1639
 	    fail "$test (program exited)"
 	}
-	-re "(while ..done|return 0).*${gdb_prompt} $" {
+	-re "(while ..done|done = 0).*${gdb_prompt} $" {
 	    # After stepping out of a function /r signal-handler, GDB will
 	    # advance the inferior until it is at the first instruction of
 	    # a code-line.  While typically things return to the middle of
@@ -104,13 +105,13 @@ proc advance { i } {
 
 proc advancei { i } {
     global gdb_prompt
+    set prefix "$i from handleri"
     set program_exited 0
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i into signal trampoline"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
         -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
             # Some platforms use a special read-only page for signal
@@ -144,7 +145,7 @@ proc advancei { i } {
 	}
     }
 
-    set test "$i out of signal trampoline"
+    set test "$prefix; leave signal trampoline"
     gdb_test_multiple "$i" "${test}" {
 	-re "while .*${gdb_prompt} $" {
 	    pass "$test (in main)"
@@ -175,6 +176,8 @@ proc advancei { i } {
     }
 }
 
+# Check that we can step/next our way out of a signal handler.
+
 advance step
 advancei stepi
 
@@ -183,3 +186,114 @@ advancei nexti
 
 advancei finish
 advancei return
+gdb_test "set done = 1" "" "Set done as return will have skipped it"
+
+
+# Check that we can step/next our way into a signal handler.
+
+# Use the real-time itimer, as otherwize the process never gets enough
+# time to expire the timer.
+
+delete_breakpoints
+set infinite_loop [gdb_get_line_number {while (!done)}]
+gdb_test "set itimer = itimer_real"
+gdb_test "break [gdb_get_line_number {done = 0}]"
+
+
+# Try single-stepping when there's a signal pending, a breakpoint at
+# the current instruction and a breakpoint in the handler.
+
+proc skip_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "break handler" "" "$prefix; break handler"
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+skip_to_handler step
+skip_to_handler next
+skip_to_handler continue
+
+
+# Try single-stepping et.al. when the handler is a no-op.
+
+proc skip_over_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i over handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "$i" "done = 0.*" "$prefix; performing $i"
+}
+
+skip_over_handler step
+skip_over_handler next
+skip_over_handler continue
+
+
+# Try single instruction stepping when there's a signal pending and a
+# breakpoint in the handler.
+
+proc breakpoint_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i breakpoint to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
+    gdb_test "break handler" "" "$prefix; break handler"
+
+    # Continue to the infinite loop
+    gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+breakpoint_to_handler step
+breakpoint_to_handler next
+breakpoint_to_handler continue

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

* Re: [rfc] sigstep additions
  2004-08-12  1:59 ` Andrew Cagney
@ 2004-08-12 17:15   ` Michael Chastain
  2004-08-20 11:02   ` Michael Chastain
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Chastain @ 2004-08-12 17:15 UTC (permalink / raw)
  To: gdb-patches, kettenis, drow, cagney

Andrew Cagney <cagney@gnu.org> wrote:
> I'd like to turn this into an RFA.

The superficial parts are all good.

I'm not qualified to comment on the signal handling innards.

I'll approve it in 24-48 hours, unless Daniel or Mark has an objection
or wants more time for review.  (Not even sure if Mark has an interest
in signal handling).

I tried it in three configurations and got these non-PASS results:

  native i686-pc-linux-gnu with red hat linux 8,
  kernel 2.4.18-14-rh, glibc 2.2.93-5-rh
  gcc 3.3.4, binutils 2.15, -gdwarf-2

    FAIL: gdb.base/sigstep.exp: step breakpoint to handler; performing step
    FAIL: gdb.base/sigstep.exp: next breakpoint to handler; performing next
    FAIL: gdb.base/sigstep.exp: continue breakpoint to handler; performing continue

  native hppa2.0w-hp-hpux11.11, hp ansi c B.11.11.28706.gp

    FAIL: gdb.base/sigstep.exp: step from handler; leave handler
    FAIL: gdb.base/sigstep.exp: stepi from handleri; leave signal trampoline
    FAIL: gdb.base/sigstep.exp: next from handler; leave handler
    FAIL: gdb.base/sigstep.exp: nexti from handleri; leave signal trampoline

  native hppa2.0w-hp-hpux11.11, gcc 3.3.4

    FAIL: gdb.base/sigstep.exp: backtrace for nexti (pattern 2)
    FAIL: gdb.base/sigstep.exp: step from handler; leave handler
    FAIL: gdb.base/sigstep.exp: stepi from handleri; leave signal trampoline
    FAIL: gdb.base/sigstep.exp: next from handler; leave handler
    FAIL: gdb.base/sigstep.exp: nexti from handleri; leave signal trampoline
    FAIL: gdb.base/sigstep.exp: finish from handleri; leave handler
    FAIL: gdb.base/sigstep.exp: return from handleri; leave handler

I can send you gdb.log files if you want to work on it more.  It's okay
with me to have FAILs in the results, as long as the test script is
doing real work (as opposed to bombing out with a compiler error).

Michael C

===

2004-08-10  Andrew Cagney  <cagney@gnu.org>

	* gdb.base/sigstep.exp (breakpoint_to_handler)
	(skip_over_handler, skip_to_handler): New test procedures.
	(advance, advancei): Add a proper prefix, do not use
	rerun_to_main.
	* gdb.base/sigstep.c (main): Change to use an infinite loop.


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

* Re: [rfc] sigstep additions
  2004-08-12  1:59 ` Andrew Cagney
  2004-08-12 17:15   ` Michael Chastain
@ 2004-08-20 11:02   ` Michael Chastain
  2004-08-24 14:29     ` Andrew Cagney
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Chastain @ 2004-08-20 11:02 UTC (permalink / raw)
  To: gdb-patches, cagney

ac> I'd like to turn this into an RFA.

mec> I'll approve it in 24-48 hours, unless Daniel or Mark has an objection
mec> or wants more time for review.  (Not even sure if Mark has an interest
mec> in signal handling).

Oops, that was 8 days ago!  I dropped my to-do item.
I'm sorry about that.

This patch is approved.

===

2004-08-10  Andrew Cagney  <cagney@gnu.org>

        * gdb.base/sigstep.exp (breakpoint_to_handler)
        (skip_over_handler, skip_to_handler): New test procedures.
        (advance, advancei): Add a proper prefix, do not use
        rerun_to_main.
        * gdb.base/sigstep.c (main): Change to use an infinite loop.


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

* Re: [rfc] sigstep additions
  2004-08-20 11:02   ` Michael Chastain
@ 2004-08-24 14:29     ` Andrew Cagney
  2004-08-24 15:47       ` Michael Chastain
  2004-08-25 14:40       ` Michael Chastain
  0 siblings, 2 replies; 8+ messages in thread
From: Andrew Cagney @ 2004-08-24 14:29 UTC (permalink / raw)
  To: Michael Chastain; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1142 bytes --]

> ac> I'd like to turn this into an RFA.
> 
> mec> I'll approve it in 24-48 hours, unless Daniel or Mark has an objection
> mec> or wants more time for review.  (Not even sure if Mark has an interest
> mec> in signal handling).
> 
> Oops, that was 8 days ago!  I dropped my to-do item.
> I'm sorry about that.

Here's a revision, I missed one case - single stepping off a breakpoint 
when there's a signal.

Now the interesting bit.

i386: single-stepping over a signal handler fails
ppc: single-stepping over a breakpoint (with signal handler) fails

I suspect they are the same underlying bug.

Tested on i386 (FC2 with a `fixed' kernel) and PPC (with a `fixed' kernel).

Still ok?

Andrew

`fixed' refers to a kernel that can correctly single-step a system call.

> This patch is approved.
> 
> ===
> 
> 2004-08-10  Andrew Cagney  <cagney@gnu.org>
> 
>         * gdb.base/sigstep.exp (breakpoint_to_handler)
>         (skip_over_handler, skip_to_handler): New test procedures.
>         (advance, advancei): Add a proper prefix, do not use
>         rerun_to_main.
>         * gdb.base/sigstep.c (main): Change to use an infinite loop.
> 

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 9476 bytes --]

2004-08-24  Andrew Cagney  <cagney@gnu.org>

	* gdb.base/sigstep.exp (breakpoint_to_handler, skip_to_handler)
	(skip_over_handler, breakpoint_over_hander): New test procedures.
	(advance, advancei): Add a proper prefix, do not use
	rerun_to_main.
	* gdb.base/sigstep.c (main): Change to use an infinite loop.

Index: gdb.base/sigstep.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.c,v
retrieving revision 1.2
diff -p -u -r1.2 sigstep.c
--- gdb.base/sigstep.c	5 Aug 2004 07:28:20 -0000	1.2
+++ gdb.base/sigstep.c	24 Aug 2004 14:17:43 -0000
@@ -31,27 +31,38 @@ handler (int sig)
   done = 1;
 } /* handler */
 
+struct itimerval itime;
+struct sigaction action;
+
+/* The enum is so that GDB can easily see these macro values.  */
+enum {
+  itimer_real = ITIMER_REAL,
+  itimer_virtual = ITIMER_VIRTUAL
+} itimer = ITIMER_VIRTUAL;
+
 main ()
 {
+
   /* Set up the signal handler.  */
-  {
-    struct sigaction action;
-    memset (&action, 0, sizeof (action));
-    action.sa_handler = handler;
-    sigaction (SIGVTALRM, &action, NULL);
-  }
+  memset (&action, 0, sizeof (action));
+  action.sa_handler = handler;
+  sigaction (SIGVTALRM, &action, NULL);
+  sigaction (SIGALRM, &action, NULL);
 
-  /* Set up a one-off timer.  A timer, rather than SIGSEGV, is used as
-     after a timer handler finishes the interrupted code can safely
-     resume.  */
-  {
-    struct itimerval itime;
-    memset (&itime, 0, sizeof (itime));
-    itime.it_value.tv_usec = 250 * 1000;
-    setitimer (ITIMER_VIRTUAL, &itime, NULL);
-  }
+  /* The values needed for the itimer.  This needs to be at least long
+     enough for the setitimer() call to return.  */
+  memset (&itime, 0, sizeof (itime));
+  itime.it_value.tv_usec = 250 * 1000;
 
-  /* Wait.  */
-  while (!done);
-  return 0;
-} /* main */
+  /* Loop for ever, constantly taking an interrupt.  */
+  while (1)
+    {
+      /* Set up a one-off timer.  A timer, rather than SIGSEGV, is
+	 used as after a timer handler finishes the interrupted code
+	 can safely resume.  */
+      setitimer (itimer, &itime, NULL);
+      /* Wait.  */
+      while (!done);
+      done = 0;
+    }
+}
Index: gdb.base/sigstep.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sigstep.exp,v
retrieving revision 1.4
diff -p -u -r1.4 sigstep.exp
--- gdb.base/sigstep.exp	9 Aug 2004 13:16:16 -0000	1.4
+++ gdb.base/sigstep.exp	24 Aug 2004 14:17:43 -0000
@@ -16,10 +16,11 @@
 
 
 # The program sigstep.c creates a very simple backtrace containing one
-# signal handler and signal trampoline.
+# signal handler and signal trampoline.  A flag is set and then the
+# handler returns.  This is repeated at infinitum.
 
 # This test runs the program up to the signal handler, and then
-# attempts to step/next the inferior back to main.
+# attempts to step/next out of the handler and back into main.
 
 if [target_info exists gdb,nosignals] {
     verbose "Skipping sigstep.exp because of nosignals."
@@ -71,12 +72,12 @@ gdb_expect_list "backtrace for nexti" ".
 
 proc advance { i } {
     global gdb_prompt
+    set prefix "$i from handler"
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i out of handler"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
 	-re "done = 1;.*${gdb_prompt} $" {
 	    send_gdb "$i\n"
@@ -90,7 +91,7 @@ proc advance { i } {
 	    setup_kfail powerpc-*-*bsd* gdb/1639
 	    fail "$test (program exited)"
 	}
-	-re "(while ..done|return 0).*${gdb_prompt} $" {
+	-re "(while ..done|done = 0).*${gdb_prompt} $" {
 	    # After stepping out of a function /r signal-handler, GDB will
 	    # advance the inferior until it is at the first instruction of
 	    # a code-line.  While typically things return to the middle of
@@ -104,13 +105,13 @@ proc advance { i } {
 
 proc advancei { i } {
     global gdb_prompt
+    set prefix "$i from handleri"
     set program_exited 0
 
     # Get us back into the handler
-    rerun_to_main
-    gdb_test "continue" ".* handler .*" "continue to handler for $i"
+    gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
 
-    set test "$i into signal trampoline"
+    set test "$prefix; leave handler"
     gdb_test_multiple "$i" "${test}" {
         -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
             # Some platforms use a special read-only page for signal
@@ -144,7 +145,7 @@ proc advancei { i } {
 	}
     }
 
-    set test "$i out of signal trampoline"
+    set test "$prefix; leave signal trampoline"
     gdb_test_multiple "$i" "${test}" {
 	-re "while .*${gdb_prompt} $" {
 	    pass "$test (in main)"
@@ -175,6 +176,8 @@ proc advancei { i } {
     }
 }
 
+# Check that we can step/next our way out of a signal handler.
+
 advance step
 advancei stepi
 
@@ -183,3 +186,153 @@ advancei nexti
 
 advancei finish
 advancei return
+gdb_test "set done = 1" "" "Set done as return will have skipped it"
+
+
+# Check that we can step/next our way into / over a signal handler.
+
+# There are at least the following cases: breakpoint @pc VS breakpoint
+# in handler VS step / next / continue.
+
+# Use the real-time itimer, as otherwize the process never gets enough
+# time to expire the timer.
+
+delete_breakpoints
+set infinite_loop [gdb_get_line_number {while (!done)}]
+gdb_test "set itimer = itimer_real"
+gdb_test "break [gdb_get_line_number {done = 0}]"
+
+# Try stepping when there's a signal pending, and a breakpoint at the
+# handler.  Should step into the signal handler.
+
+proc skip_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    # Insert / remove the handler breakpoint.
+    gdb_test "break handler" "" "$prefix; break handler"
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+skip_to_handler step
+skip_to_handler next
+skip_to_handler continue
+
+# Try stepping when there's a signal pending but no breakpoints.
+# Should skip the handler advancing to the next line.
+
+proc skip_over_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i over handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    # Advance to the infinite loop
+    gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    gdb_test "$i" "done = 0.*" "$prefix; performing $i"
+}
+
+skip_over_handler step
+skip_over_handler next
+skip_over_handler continue
+
+# Try stepping when there's a signal pending, a pre-existing
+# breakpoint at the current instruction, and a breakpoint in the
+# handler.  Should advance to the signal handler.
+
+proc breakpoint_to_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i on breakpoint, to handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
+    gdb_test "break handler" "" "$prefix; break handler"
+
+    # Continue to the infinite loop
+    gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    setup_kfail "i*86-*-*" gdb/1738
+    gdb_test "$i" " handler .*" "$prefix; performing $i"
+    gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
+    gdb_test "clear handler" "" "$prefix; clear handler"
+}
+
+breakpoint_to_handler step
+breakpoint_to_handler next
+breakpoint_to_handler continue
+
+# Try stepping when there's a signal pending, and a pre-existing
+# breakpoint at the current instruction, and no breakpoint in the
+# handler.  Should advance to the next line.
+
+proc breakpoint_over_handler { i } {
+    global gdb_prompt
+    global infinite_loop
+    set prefix "$i on breakpoint, skip handler"
+    
+    # Run around to the done
+    set test "$prefix; resync"
+    gdb_test_multiple "continue" "$test" {
+	-re "done = 0.*$gdb_prompt " {
+	    pass "$test"
+	}
+	# other patterns can go here
+    }
+    
+    gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
+
+    # Continue to the infinite loop
+    gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
+
+    # Make the signal pending
+    sleep 1
+    
+    setup_kfail "powerpc*-*-*" gdb/1757
+    gdb_test "$i" "done = 0.*" "$prefix; performing $i"
+    gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
+}
+
+breakpoint_over_handler step
+breakpoint_over_handler next
+breakpoint_over_handler continue

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

* Re: [rfc] sigstep additions
  2004-08-24 14:29     ` Andrew Cagney
@ 2004-08-24 15:47       ` Michael Chastain
  2004-08-25 14:40       ` Michael Chastain
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Chastain @ 2004-08-24 15:47 UTC (permalink / raw)
  To: kettenis.gnu.org, drow, cagney; +Cc: gdb-patches

Andrew Cagney <cagney@gnu.org> wrote:
> Still ok?

If Daniel or Mark or nobody else objects in 48 hours,
or asks for more time, okay.

(Thinking some more about setting up testsuite/gdb.signal with not-me
 as maintainer).

2004-08-10  Andrew Cagney  <cagney@gnu.org>

        * gdb.base/sigstep.exp (breakpoint_to_handler)
        (skip_over_handler, skip_to_handler): New test procedures.
        (advance, advancei): Add a proper prefix, do not use
        rerun_to_main.
        * gdb.base/sigstep.c (main): Change to use an infinite loop.


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

* Re: [rfc] sigstep additions
  2004-08-24 14:29     ` Andrew Cagney
  2004-08-24 15:47       ` Michael Chastain
@ 2004-08-25 14:40       ` Michael Chastain
  2004-08-25 15:29         ` Andrew Cagney
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Chastain @ 2004-08-25 14:40 UTC (permalink / raw)
  To: cagney; +Cc: gdb-patches

No objections sighted, so this one is approved (the first one).

> 2004-08-10  Andrew Cagney  <cagney@gnu.org>
> 
>         * gdb.base/sigstep.exp (breakpoint_to_handler)
>         (skip_over_handler, skip_to_handler): New test procedures.
>         (advance, advancei): Add a proper prefix, do not use
>         rerun_to_main.
>         * gdb.base/sigstep.c (main): Change to use an infinite loop.


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

* Re: [rfc] sigstep additions
  2004-08-25 14:40       ` Michael Chastain
@ 2004-08-25 15:29         ` Andrew Cagney
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Cagney @ 2004-08-25 15:29 UTC (permalink / raw)
  To: Michael Chastain; +Cc: gdb-patches

> No objections sighted, so this one is approved (the first one).

I've checked this in.  With this as a test to work against, I think i've 
even found 2/3 of a fix!

thanks, andrew

>>> 2004-08-10  Andrew Cagney  <cagney@gnu.org>
>>> 
>>>         * gdb.base/sigstep.exp (breakpoint_to_handler)
>>>         (skip_over_handler, skip_to_handler): New test procedures.
>>>         (advance, advancei): Add a proper prefix, do not use
>>>         rerun_to_main.
>>>         * gdb.base/sigstep.c (main): Change to use an infinite loop.



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

end of thread, other threads:[~2004-08-25 15:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-11  0:14 [rfc] sigstep additions Andrew Cagney
2004-08-12  1:59 ` Andrew Cagney
2004-08-12 17:15   ` Michael Chastain
2004-08-20 11:02   ` Michael Chastain
2004-08-24 14:29     ` Andrew Cagney
2004-08-24 15:47       ` Michael Chastain
2004-08-25 14:40       ` Michael Chastain
2004-08-25 15:29         ` Andrew Cagney

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