From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122773 invoked by alias); 6 Nov 2017 23:27:26 -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 122729 invoked by uid 89); 6 Nov 2017 23:27:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=continuously, pressed, reaches, arrives 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 ESMTP; Mon, 06 Nov 2017 23:27:23 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72B9A19D4C9 for ; Mon, 6 Nov 2017 23:27:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72B9A19D4C9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E61F360C90 for ; Mon, 6 Nov 2017 23:27:21 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 5/5] Test breakpoint commands w/ "continue" + Ctrl-C Date: Mon, 06 Nov 2017 23:27:00 -0000 Message-Id: <1510010836-15287-6-git-send-email-palves@redhat.com> In-Reply-To: <1510010836-15287-1-git-send-email-palves@redhat.com> References: <1510010836-15287-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-11/txt/msg00131.txt.bz2 This adds the testcase that exposed the multiple problems with Ctrl-C handling fixed by the previous patches, when run against both native and gdbserver GNU/Linux. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/bp-cmds-continue-ctrl-c.c: New file. * gdb.base/bp-cmds-continue-ctrl-c.exp: New file. --- gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.c | 35 ++++++ gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.exp | 136 +++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.c create mode 100644 gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.exp diff --git a/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.c b/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.c new file mode 100644 index 0000000..2ec0b54 --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.c @@ -0,0 +1,35 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2017 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +static void +foo (void) +{ + usleep (100); +} + +int +main () +{ + alarm (60); + + while (1) + foo (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.exp b/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.exp new file mode 100644 index 0000000..e152459 --- /dev/null +++ b/gdb/testsuite/gdb.base/bp-cmds-continue-ctrl-c.exp @@ -0,0 +1,136 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Set a breakpoint with a "continue" command attached, let the +# inferior hit the breakpoint continuously. Check that we can use ^C +# to interrupt the command, and that if ^C is pressed while GDB has +# the terminal (between the stop and the re-resume), the resulting +# "Quit" doesn't mess up the debug session. + +if [target_info exists gdb,nosignals] { + verbose "Skipping because of nosignals." + continue +} + +# This test requires sending ^C to interrupt the running target. +if [target_info exists gdb,nointerrupts] { + verbose "Skipping because of nointerrupts." + return +} + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +# See intro. + +proc do_test {} { + global srcfile binfile + global gdb_prompt + + gdb_test "break foo" "Breakpoint .*" "set breakpoint" + + gdb_test \ + [multi_line_input \ + {commands} \ + { c} \ + {end}] \ + "" "commands" + + set test "stop with control-c" + + for {set iter 0} {$iter < 20} {incr iter} { + + # Useful for debugging. + #send_user "iter: $iter\n" + + # Consume one breakpoint hit (at least), to make sure that the + # continue actually continues between attempts, as opposed to + # "c" not actually resuming and then Ctrl-C managing to + # interrupt anyway. + if {[gdb_test_multiple "continue" "$test (continue)" { + -re "Continuing.*Breakpoint \[^\r\n\]*\r\n" { + } + }] != 0} { + return + } + + set internal_pass "IPASS: $test (iter $iter)" + + # Breakpoint commands run after the target is considered + # stopped, and thus run with GDB owning the terminal. That + # means that it is expected that a Ctrl-C that arrives between + # - GDB reporting the breakpoint hit, and, + # - the breakpoint command continuing the target + # results in a Quit. + + after 200 {send_gdb "\003"} + if {[gdb_test_multiple "" "$test (unexpected)" { + -re "Program terminated with signal SIGALRM.*\r\n$gdb_prompt $" { + fail "$test (SIGALRM)" + return + } + -re "Program received signal SIGINT.*\r\n$gdb_prompt $" { + send_log "$internal_pass (SIGINT)\n" + } + -re "Quit\r\n$gdb_prompt $" { + send_log "$internal_pass (Quit)\n" + } + -re "Quit\r\n\r\nCommand aborted.\r\n$gdb_prompt $" { + send_log "$internal_pass (Command aborted)\n" + } + -re "Breakpoint \[^\r\n\]*$srcfile" { + exp_continue + } + }] != 0} { + break + } + } + + gdb_assert {$iter == 20} "stop with control-c" +} + +# With native debugging and "run" (with job control), if the inferior +# is running, the Ctrl-C reaches the inferior directly, not GDB. With +# native debugging and "attach", or with remote debugging, the Ctrl-C +# reaches GDB first. So for completeness, try both "run" and +# "attach". + +with_test_prefix "run" { + clean_restart $binfile + + if {![runto_main]} { + return -1 + } + + do_test +} + +with_test_prefix "attach" { + if {[can_spawn_for_attach]} { + clean_restart $binfile + + set test_spawn_id [spawn_wait_for_attach $binfile] + set testpid [spawn_id_get_pid $test_spawn_id] + + gdb_test "attach $testpid" "Attaching to.*process $testpid.*" "attach" + + do_test + + kill_wait_spawned_process $test_spawn_id + } +} -- 2.5.5