From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6ZdjBc56nWUg4zYAWB0awg (envelope-from ) for ; Tue, 09 Jan 2024 11:56:46 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=lc11wUxB; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6RM2+KFy; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Y2iBan64; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qrcGesWu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0AFC51E0C3; Tue, 9 Jan 2024 11:56:46 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 70AEB1E0B9 for ; Tue, 9 Jan 2024 11:56:43 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 945B0385771D for ; Tue, 9 Jan 2024 16:56:42 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 23CD7385802E for ; Tue, 9 Jan 2024 16:55:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23CD7385802E 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 23CD7385802E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704819354; cv=none; b=Osd4rsd0aPHeJJr94giciQ+zzJEX4MBAEEP17VdtFizQWzbV2B7XY8wX+Wm/GJlj7adkgXsXVdQiRLLz030w7TmKMqXnhdOKg1o/1k/CP3aApL7IZGdhEtmxFUwkx3n4zKeJszh3MPvu++haZqp+k7Q6reN/VY1e5gTpKW3OAWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704819354; c=relaxed/simple; bh=nYb2AcdH9+rlpKpZRyaTRqarn0YAj1nPFahLF8cHjMQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=PpvxBCdTxsWQ9+VJwi0EZUX2qhlYv/QilX5fO1+11+whzze2srtCjwqBY4kRYcarvmVOpEjm9ppQ3igBpD40m6zV473Zln7r5uIo/yVlRPqj4MPL+tJoxbp+7EJvwzjIwKbNd2YiBSMf7qlNRfE/ArWSAQKhV9BoJc2vTMgzgtU= 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 868662219A for ; Tue, 9 Jan 2024 16:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704819348; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lTrXDti7GI+l5KCk73Yo7bz7MNubFC8ANBiweALcwXQ=; b=lc11wUxBqDm0YjjQWWM0Qv9uFNtRWWC3EYNwEBBDsK8rR/aHoo74RtFtTwTfmnG/uhTPlx s1H8LARKz1pDr98+oJeXBEEnTt/N4+EcjIhyVoHvw59+wjISiwq+We6vBIjUPyR/BwtvAs +TYOkNYcn4PLb3EZ/aKIWv6OLcBY9NU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704819348; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lTrXDti7GI+l5KCk73Yo7bz7MNubFC8ANBiweALcwXQ=; b=6RM2+KFytCcjeQ2xB00LMfZVvIoPip1JBmqd1DAl33d+hP7seV2nDCpqwNsKkrDhb1Car5 VFEU3qcgQiVl3kCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704819346; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lTrXDti7GI+l5KCk73Yo7bz7MNubFC8ANBiweALcwXQ=; b=Y2iBan64omr97W5+ZeixFZULcWYhKm6qT0zXZPpnyTn85u8/lfRuYiEDUcL12oQYqN9Mmt 7cQ2yjAfVzNbbllCWhj+mvXoNodPuoJ0T6PoWLHLFJU3oOm2dx3TXS1AEDG/LBXKr2X8xn bHYblsrhqwV9YxoKJyvNnhIc4KrmuJY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704819346; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lTrXDti7GI+l5KCk73Yo7bz7MNubFC8ANBiweALcwXQ=; b=qrcGesWuOIjDmSQ9eKMC/3dcbZJOtK3YKQPhO6D3pCjRTS72Lka1qgRsi+dSQlxkNUSxPz oHuzOs0IriAVigDg== 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 70304134E8 for ; Tue, 9 Jan 2024 16:55:46 +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 ZRjwGZJ6nWVwEAAAD6G6ig (envelope-from ) for ; Tue, 09 Jan 2024 16:55:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/testsuite] Extend gdb.base/kill-during-detach.exp Date: Tue, 9 Jan 2024 17:56:20 +0100 Message-Id: <20240109165620.18066-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 868662219A Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Y2iBan64; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qrcGesWu X-Spam-Score: -1.51 X-Spam-Level: X-Spamd-Result: default: False [-1.51 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url,gnu.org:url,suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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+public-inbox=simark.ca@sourceware.org I ran into the following FAIL: ... (gdb) python kill_and_detach()^M Traceback (most recent call last):^M File "", line 1, in ^M File "", line 7, in kill_and_detach^M gdb.error: Selected thread is running.^M Error while executing Python code.^M (gdb) FAIL: gdb.base/kill-during-detach.exp: exit_p=true: checkpoint_p=true: \ python kill_and_detach() ... The FAIL happens as follows: - gdb is debugging a process A - a checkpoint is created, in other words, fork is called in the inferior, after which we have: - checkpoint 0 (the fork parent, process A), and - checkpoint 1 (the fork child, process B). - during checkpoint creation, lseek is called in the inferior (process A) for all file descriptors, and it returns != -1 for at least one file descriptor. - the process A continues in the background - gdb detaches, from process A - gdb switches to process B, in other words, it restarts checkpoint 1 - while restarting checkpoint 1, gdb tries to call lseek in the inferior (process B), but this fails because gdb incorrectly thinks that inferior B is running. This happens because linux_nat_switch_fork patches the pid of process B into the current inferior and current thread which where originally representing process A. So, because process A was running in the background, the thread_info fields executing and resumed are set accordingly, but they are not correct for process B. There's a line in fork_load_infrun_state that fixes up the thread_info field stop_pc, so fix this by adding similar fixups for the executing and resumed fields alongside. The FAIL did not always reproduce, so extend the test-case to reliably trigger this scenario. Tested on x86_64-linux. PR gdb/31203 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31203 --- gdb/linux-fork.c | 2 ++ gdb/testsuite/gdb.base/kill-during-detach.c | 26 +++++++++++++++++++ gdb/testsuite/gdb.base/kill-during-detach.exp | 16 +++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 1430ff89fa7..ac4277e3962 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -227,6 +227,8 @@ fork_load_infrun_state (struct fork_info *fp) inferior_thread ()->set_stop_pc (regcache_read_pc (get_thread_regcache (inferior_thread ()))); + inferior_thread ()->set_executing (false); + inferior_thread ()->set_resumed (false); nullify_last_target_wait_ptid (); /* Now restore the file positions of open file descriptors. */ diff --git a/gdb/testsuite/gdb.base/kill-during-detach.c b/gdb/testsuite/gdb.base/kill-during-detach.c index 2d9cca91e2f..9567eab1e2e 100644 --- a/gdb/testsuite/gdb.base/kill-during-detach.c +++ b/gdb/testsuite/gdb.base/kill-during-detach.c @@ -16,14 +16,40 @@ along with this program. If not, see . */ #include +#include +#include volatile int dont_exit_just_yet = 1; +#define XSTR(s) STR(s) +#define STR(s) #s + +volatile int with_checkpoint = 0; + int main () { alarm (300); + if (with_checkpoint) + { + /* We open a file and move file pos from 0 to 1. We set the checkpoint + when pos is 0, and restart it when pos is 1. This makes sure that + restarting the checkpoint excercises calling lseek in the + inferior. */ + + /* Open a file. */ + const char *filename = XSTR (BINFILE); + FILE *fp = fopen (filename, "r"); + assert (fp != NULL); + + volatile int checkpoint_here = 0; /* Checkpoint here. */ + + /* Move file pos from 0 to 1. */ + int res = fseek (fp, 1, SEEK_SET); + assert (res == 0); + } + /* Spin until GDB releases us. */ while (dont_exit_just_yet) usleep (100000); diff --git a/gdb/testsuite/gdb.base/kill-during-detach.exp b/gdb/testsuite/gdb.base/kill-during-detach.exp index 26028d5fc34..a5b0127f4b7 100644 --- a/gdb/testsuite/gdb.base/kill-during-detach.exp +++ b/gdb/testsuite/gdb.base/kill-during-detach.exp @@ -39,10 +39,16 @@ if { [istarget "*-*-linux*"] && [target_info gdb_protocol] == ""} { set has_checkpoint false } -if {[build_executable "failed to prepare" $testfile $srcfile] == -1} { +set flags {} +lappend flags debug +lappend flags additional_flags=-DBINFILE=$binfile + +if {[build_executable "failed to prepare" $testfile $srcfile $flags] == -1} { return -1 } +set checkpoint_line [gdb_get_line_number "Checkpoint here"] + # Start an inferior, which blocks in a spin loop. Setup a Python # function that performs an action based on EXIT_P that will cause the # inferior to exit, and then, within the same Python function, ask GDB @@ -78,6 +84,14 @@ proc run_test { exit_p checkpoint_p } { } if { $checkpoint_p } { + # Active checkpoint-specific code in $srcfile. + gdb_test_no_output "set var with_checkpoint=1" + + # Run to line where we want to set the checkpoint. + gdb_breakpoint "$::srcfile:$::checkpoint_line" + gdb_continue_to_breakpoint "checkpoint line" + + # Set the checkpoint. gdb_test "checkpoint" \ "checkpoint 1: fork returned pid $::decimal\\." } base-commit: d006ec41c448d9f4a84df50391e87cbf0aa8c152 -- 2.35.3