From patchwork Wed Nov 29 20:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 80988 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7DFEF384F498 for ; Wed, 29 Nov 2023 20:34:06 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 1858B384F498 for ; Wed, 29 Nov 2023 20:33:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1858B384F498 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1858B384F498 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701290013; cv=none; b=G7QkWBZ+xoPFfiIdQ3pAhsSFgwWs7wQ38B3wCFTltMFCkopXwqB+cL/rdr/SJLgjxCFUO1j/mTblDEaIKp5Vu0KfT4grnwgE7D25kr13GnCy2kHG6N/2fAyF/Hovhy9MnnQGwdgGRGecbKw4SujEHESjPtfOMuAAoRZrpqYel2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701290013; c=relaxed/simple; bh=EciDMKq3af9YlTbvRfVCgyLFLQifGMKXrrHKkCDmxm4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=GeD1+jSkrTvHg9lWM/v5B06FgjATK6raCuegnvcfwOK8VHPIFgN5SSVQMLSQUckB1o1AUy5ecDobrwaWR+9SLqdWgvnin7E+DeOzdmH0Wll2JR+hM2q8SV/zHtUB05Jfz85kw3wqkeuhV13hlVxp/wdq/ky2pNlwqaNdIv3FeK0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 441CF219C8 for ; Wed, 29 Nov 2023 20:33:29 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2DB6313AA2 for ; Wed, 29 Nov 2023 20:33:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gC2yCRmgZ2U5QQAAD6G6ig (envelope-from ) for ; Wed, 29 Nov 2023 20:33:29 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 4/4] [gdb/testsuite] Add test-case gdb.base/gdb-sigterm-3.exp Date: Wed, 29 Nov 2023 21:33:26 +0100 Message-Id: <20231129203326.11952-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231129203326.11952-1-tdevries@suse.de> References: <20231129203326.11952-1-tdevries@suse.de> MIME-Version: 1.0 X-Spamd-Bar: +++++++++++++++ X-Spam-Score: 15.29 X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of tdevries@suse.de) smtp.mailfrom=tdevries@suse.de; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none) X-Rspamd-Queue-Id: 441CF219C8 X-Spamd-Result: default: False [15.29 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; NEURAL_SPAM_SHORT(3.00)[0.999]; MX_GOOD(-0.01)[]; NEURAL_SPAM_LONG(3.50)[1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam: Yes X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Reproduce PR gdb/31061 (originally reported on arm, a software single-step architecture) on amd64, a hardware single-step architecture, using the new maintenance command "maint set prefer-software-single-stepping on". The test-case is based on gdb.base/gdb-sigterm.exp, so leave the 2013-2023 copyright years in place. Tested on x86_64-linux. --- gdb/testsuite/gdb.base/gdb-sigterm-3.c | 52 +++++++++++ gdb/testsuite/gdb.base/gdb-sigterm-3.exp | 105 +++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 gdb/testsuite/gdb.base/gdb-sigterm-3.c create mode 100644 gdb/testsuite/gdb.base/gdb-sigterm-3.exp diff --git a/gdb/testsuite/gdb.base/gdb-sigterm-3.c b/gdb/testsuite/gdb.base/gdb-sigterm-3.c new file mode 100644 index 00000000000..3e359f009ee --- /dev/null +++ b/gdb/testsuite/gdb.base/gdb-sigterm-3.c @@ -0,0 +1,52 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013-2023 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 + +#if defined(__s390__) || defined(__s390x__) +#define NOP asm("nopr 0") +#elif defined(__or1k__) +#define NOP asm("l.nop") +#else +#define NOP asm("nop") +#endif + +#define NOP10 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP + +int +main (void) +{ + /* Allow for as much timeout as DejaGnu wants, plus a bit of + slack. */ + unsigned int seconds = TIMEOUT + 20; + + alarm (seconds); + + for (;;) /* loop-line */ + { + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + NOP10; + } +} diff --git a/gdb/testsuite/gdb.base/gdb-sigterm-3.exp b/gdb/testsuite/gdb.base/gdb-sigterm-3.exp new file mode 100644 index 00000000000..44ce20b4f26 --- /dev/null +++ b/gdb/testsuite/gdb.base/gdb-sigterm-3.exp @@ -0,0 +1,105 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2013-2023 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 . + +# Test relies on checking gdb debug output. Do not run if gdb debug is +# enabled as any debug will be redirected to the log. +require !gdb_debug_enabled + +standard_testfile + +# The test program exits after a while, in case GDB crashes. Make it +# wait at least as long as we may wait before declaring a time out +# failure. +set options { "additional_flags=-DTIMEOUT=$timeout" debug } +if { [build_executable ${testfile}.exp ${testfile} $srcfile $options] == -1 } { + return -1 +} + +# Return 0 on success, non-zero otherwise. + +proc do_test { pass } { + global testfile gdb_prompt binfile pf_prefix + + if ![runto_main] { + return -1 + } + + gdb_breakpoint "${testfile}.c:[gdb_get_line_number "loop-line" ${testfile}.c]" \ + temporary + + gdb_test "continue" "Temporary breakpoint .* NOP10;.*" + + gdb_test_no_output "set range-stepping off" + gdb_test_no_output "set debug infrun 1" + + set abort 1 + gdb_test_multiple "stepi-loop" "run a bit" { + -re {\[infrun\] process_event_stop_test: stepi/nexti} { + pass $gdb_test_name + set abort 0 + } + } + if $abort { + verbose -log "$pf_prefix $test: did not run" + return $abort + } + + set gdb_pid [exp_pid -i [board_info host fileid]] + remote_exec host "kill -TERM ${gdb_pid}" + + set test "expect eof" + set abort 1 + set stepping 0 + # If GDB mishandles the SIGTERM and doesn't exit, this should FAIL + # with timeout. We don't expect a GDB prompt, so we see one, + # we'll FAIL too. + gdb_test_multiple "" "expect eof" { + eof { + pass "$gdb_test_name (got eof)" + set abort 0 + } + -re {\[infrun\] process_event_stop_test: stepping inside range} { + incr stepping + exp_continue + } + } + verbose -log "$pf_prefix $test: stepped $stepping times" + return $abort +} + +# Testcase was FAILing approx. on 10th pass with unpatched GDB. +# 50 runs should be approx. a safe number to be sure it is fixed now. +set passes 50 + +for {set pass 0} {$pass < $passes} {incr pass} { + with_test_prefix "pass=$pass" { + clean_restart ${testfile} + send_gdb "define stepi-loop\n" + send_gdb "while 1\n" + send_gdb "stepi\n" + send_gdb "end\n" + send_gdb "end\n" + gdb_test "" "" + gdb_test_no_output "maint set prefer-software-single-stepping on" + + if { [do_test $pass] != 0 } { + break + } + } +} + +gdb_assert {$pass == $passes} "$passes SIGTERM passes"