From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27992 invoked by alias); 28 Oct 2014 15:38:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 27897 invoked by uid 89); 28 Oct 2014 15:38:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 28 Oct 2014 15:38:51 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9SFcoBb012912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 28 Oct 2014 11:38:50 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9SFcm5h028598 for ; Tue, 28 Oct 2014 11:38:49 -0400 Message-ID: <544FB888.8020607@redhat.com> Date: Tue, 28 Oct 2014 15:38:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1 MIME-Version: 1.0 To: "gdb- >> GDB Patches" Subject: Re: [pushed] gdb.base/sigstep.exp: cleanup and make it easier to extend References: <1414510569-29145-1-git-send-email-palves@redhat.com> In-Reply-To: <1414510569-29145-1-git-send-email-palves@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-10/txt/msg00779.txt.bz2 And here's a diff -w version: diff --git c/gdb/testsuite/gdb.base/sigstep.exp w/gdb/testsuite/gdb.base/sigstep.exp index 85d4178..ef98b3d 100644 --- c/gdb/testsuite/gdb.base/sigstep.exp +++ w/gdb/testsuite/gdb.base/sigstep.exp @@ -29,16 +29,24 @@ if [target_info exists gdb,nosignals] { standard_testfile -if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { +if {[build_executable $testfile.exp $testfile $srcfile debug]} { untested $testfile.exp return -1 } +set clear_done [gdb_get_line_number {done = 0}] +set infinite_loop [gdb_get_line_number {while (!done)}] + +# Restart GDB, set a display showing $PC, and run to main. + +proc restart {} { + global binfile + + clean_restart $binfile + gdb_test "display/i \$pc" -# Advance to main -if { ![runto_main] } then { - gdb_suppress_tests + runto_main } # Pass all the alarms straight through (but verbosely) @@ -47,6 +55,11 @@ if { ![runto_main] } then { # gdb_test "handle SIGPROF print pass nostop" # Run to the signal handler, validate the backtrace. + +proc validate_backtrace {} { + with_test_prefix "validate backtrace" { + restart + gdb_test "break handler" gdb_test "continue" ".* handler .*" "continue to stepi handler" gdb_test_sequence "bt" "backtrace for nexti" { @@ -54,26 +67,34 @@ gdb_test_sequence "bt" "backtrace for nexti" { "\[\r\n\]+.1 .signal handler called." "\[\r\n\]+.2 \[^\r\n\]* main " } + } +} + +validate_backtrace -proc advance { i } { +proc advance { cmd } { global gdb_prompt inferior_exited_re - set prefix "$i from handler" - # Get us back into the handler - gdb_test "continue" ".* handler .*" "$prefix; continue to handler" + with_test_prefix "$cmd from handler" { + restart - set test "$prefix; leave handler" - gdb_test_multiple "$i" "${test}" { + gdb_test "break handler" + + # Get us into the handler + gdb_test "continue" ".* handler .*" "continue to handler" + + set test "leave handler" + gdb_test_multiple "$cmd" "${test}" { -re "Could not insert single-step breakpoint.*$gdb_prompt $" { setup_kfail gdb/8841 "sparc*-*-openbsd*" fail "$test (could not insert single-step breakpoint)" } -re "done = 1;.*${gdb_prompt} $" { - send_gdb "$i\n" + send_gdb "$cmd\n" exp_continue -continue_timer } -re "\} .. handler .*${gdb_prompt} $" { - send_gdb "$i\n" + send_gdb "$cmd\n" exp_continue -continue_timer } -re "$inferior_exited_re normally.*${gdb_prompt} $" { @@ -91,17 +112,21 @@ proc advance { i } { } } } +} -proc advancei { i } { +proc advancei { cmd } { global gdb_prompt inferior_exited_re - set prefix "$i from handleri" - set program_exited 0 - # Get us back into the handler - gdb_test "continue" ".* handler .*" "$prefix; continue to handler" + with_test_prefix "$cmd from handleri" { + restart - set test "$prefix; leave handler" - gdb_test_multiple "$i" "${test}" { + # Get us into the handler. + gdb_test "break handler" + gdb_test "continue" ".* handler .*" "continue to handler" + + set program_exited 0 + set test "leave handler" + gdb_test_multiple "$cmd" "${test}" { -re "Cannot insert breakpoint 0.*${gdb_prompt} $" { # Some platforms use a special read-only page for signal # trampolines. We can't set a breakpoint there, and we @@ -119,11 +144,11 @@ proc advancei { i } { fail "$test (hit breakpoint again)" } -re "done = 1;.*${gdb_prompt} $" { - send_gdb "$i\n" + send_gdb "$cmd\n" exp_continue -continue_timer } -re "\} .. handler .*${gdb_prompt} $" { - send_gdb "$i\n" + send_gdb "$cmd\n" exp_continue -continue_timer } -re "signal handler called.*${gdb_prompt} $" { @@ -142,13 +167,13 @@ proc advancei { i } { } } - set test "$prefix; leave signal trampoline" - gdb_test_multiple "$i" "${test}" { + set test "leave signal trampoline" + gdb_test_multiple "$cmd" "${test}" { -re "while .*${gdb_prompt} $" { pass "$test (in main)" } -re "signal handler called.*${gdb_prompt} $" { - send_gdb "$i\n" + send_gdb "$cmd\n" exp_continue -continue_timer } -re "return .*${gdb_prompt} $" { @@ -172,65 +197,53 @@ proc advancei { i } { } } } +} # Check that we can step/next our way out of a signal handler. -advance step -advancei stepi - -advance next -advancei nexti - -advancei finish -advancei return -gdb_test_no_output "set done = 1" "Set done as return will have skipped it" +foreach cmd {"step" "next"} { + advance $cmd +} +foreach cmd {"stepi" "nexti" "finish" "return"} { + advancei $cmd +} # 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_no_output "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 +proc skip_to_handler { cmd } { global infinite_loop - set prefix "$i to handler" - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd to handler" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - # Advance to the infinite loop - gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" + # Advance to the infinite loop. + gdb_test "advance $infinite_loop" ".*" "advance to infinite loop" - # Make the signal pending + # 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" + # Insert the handler breakpoint. + gdb_test "break handler" ".*" "break handler" + + # Step into the handler. + gdb_test "$cmd" " handler .*" "performing $cmd" + } } -skip_to_handler step -skip_to_handler next -skip_to_handler continue +foreach cmd {"step" "next" "continue"} { + skip_to_handler $cmd +} # Try stepping when there's a signal pending, and a breakpoint at the # handler's entry-point. Should step into the signal handler stopping @@ -243,30 +256,25 @@ skip_to_handler continue # have been called by the trampoline code. This test checks that it # is possible to stop the inferior, even at that first instruction. -proc skip_to_handler_entry { i } { - global gdb_prompt +proc skip_to_handler_entry { cmd } { global infinite_loop - set prefix "$i to handler entry" - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd to handler entry" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - # Advance to the infinite loop - gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" + # Advance to the infinite loop. + gdb_test "advance $infinite_loop" ".*" "advance to infinite loop" - # Make the signal pending + # 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" + gdb_test "break *handler" ".*" "break handler" + gdb_test "$cmd" " handler .*" "performing $cmd" + } } foreach cmd {"stepi" "nexti" "step" "next" "continue"} { @@ -292,40 +300,39 @@ proc get_next_pc {test} { # Test that the command skipped over the handler. -proc test_skip_handler {prefix i} { - if {$i == "stepi" || $i == "nexti"} { - set next_pc [get_next_pc "$prefix; get next PC"] - gdb_test "$i" "dummy = 0.*" "$prefix; performing $i" - gdb_test "p /x \$pc" " = $next_pc" "$prefix; advanced" +proc test_skip_handler {cmd} { + if {$cmd == "stepi" || $cmd == "nexti"} { + set next_pc [get_next_pc "get next PC"] + gdb_test "$cmd" "dummy = 0.*" "performing $cmd" + gdb_test "p /x \$pc" " = $next_pc" "advanced" } else { - gdb_test "$i" "done = 0.*" "$prefix; performing $i" + gdb_test "$cmd" "done = 0.*" "performing $cmd" } } # 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 +proc skip_over_handler { cmd } { global infinite_loop - set prefix "$i over handler" + global clear_done - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd over handler" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - # Advance to the infinite loop - gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" + gdb_test "break $clear_done" ".*" "break clear done" - # Make the signal pending + # Advance to the infinite loop. + gdb_test "advance $infinite_loop" ".*" "advance to infinite loop" + + # Make the signal pending. sleep 1 - test_skip_handler $prefix $i + test_skip_handler $cmd + } } foreach cmd {"stepi" "nexti" "step" "next" "continue"} { @@ -336,37 +343,31 @@ foreach cmd {"stepi" "nexti" "step" "next" "continue"} { # 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 +proc breakpoint_to_handler { cmd } { global infinite_loop - set prefix "$i on breakpoint, to handler" - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd on breakpoint, to handler" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" - gdb_test "break handler" ".*" "$prefix; break handler" + gdb_test "break $infinite_loop" ".*" "break infinite loop" + gdb_test "break handler" ".*" "break handler" - # Continue to the infinite loop - gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop" + # Continue to the infinite loop. + gdb_test "continue" "while ..done.*" "continue to infinite loop" - # Make the signal pending + # 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" + gdb_test "$cmd" " handler .*" "performing $cmd" + } } -breakpoint_to_handler step -breakpoint_to_handler next -breakpoint_to_handler continue +foreach cmd {"step" "next" "continue"} { + breakpoint_to_handler $cmd +} # Try stepping when there's a signal pending, and a breakpoint at the # handler's entry instruction and a breakpoint at the current @@ -380,66 +381,58 @@ breakpoint_to_handler continue # have been called by the trampoline code. This test checks that it # is possible to stop the inferior, even at that first instruction. -proc breakpoint_to_handler_entry { i } { - global gdb_prompt +proc breakpoint_to_handler_entry { cmd } { global infinite_loop - set prefix "$i on breakpoint, to handler entry" - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd on breakpoint, to handler entry" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" - gdb_test "break *handler" ".*" "$prefix; break handler" + gdb_test "break $infinite_loop" ".*" "break infinite loop" + gdb_test "break *handler" ".*" "break handler" - # Continue to the infinite loop - gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop" + # Continue to the infinite loop. + gdb_test "continue" "while ..done.*" "continue to infinite loop" - # Make the signal pending + # 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" + gdb_test "$cmd" " handler .*" "performing $cmd" + } } -breakpoint_to_handler_entry step -breakpoint_to_handler_entry next -breakpoint_to_handler_entry continue +foreach cmd {"step" "next" "continue"} { + breakpoint_to_handler_entry $cmd +} # 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/instruction. -proc breakpoint_over_handler { i } { - global gdb_prompt +proc breakpoint_over_handler { cmd } { global infinite_loop - set prefix "$i on breakpoint, skip handler" + global clear_done - # Run around to the done - # You can add more patterns to this if you need them. - set test "$prefix; resync" - gdb_test_multiple "continue" "$test" { - -re "done = 0.*$gdb_prompt " { - pass "$test" - } - } + with_test_prefix "$cmd on breakpoint, skip handler" { + restart + # Use the real-time itimer, as otherwize the process never gets + # enough time to expire the timer. + gdb_test_no_output "set itimer = itimer_real" - gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" + gdb_test "break $infinite_loop" ".*" "break infinite loop" + + gdb_test "break $clear_done" ".*" "break clear done" # Continue to the infinite loop - gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop" + gdb_test "continue" "while ..done.*" "continue to infinite loop" # Make the signal pending sleep 1 - test_skip_handler $prefix $i - gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop" + test_skip_handler $cmd + } } foreach cmd {"stepi" "nexti" "step" "next" "continue"} {