From patchwork Mon Oct 14 14:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 98876 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 2C4583857022 for ; Mon, 14 Oct 2024 14:49:56 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 05D87385829B for ; Mon, 14 Oct 2024 14:49:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05D87385829B 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 05D87385829B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728917372; cv=none; b=R7LvdqLj0ZRyyRh6fevGaO/q9xSFouW2ULB1/ecqGJ+RCQy/DEyITAt4nn0c3aVYRaEuvPvM/K2SM4wJAD2PTLxCt8L/QYQcelPxhzswtAGh+7cF7KpXtyM5O+t34Y5FYZPmTVblXa+Oh6KWOI5e8seevqKh8APBkj7D2DGn3mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728917372; c=relaxed/simple; bh=lzM6rGZvf8NSZ+nbKLcBAAI1017wgXgE8gR+HZPev3o=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=eTURWYTNUr1jQKE+Cvtb2fXK5vR0Oc7EIaPbb3vm9Fq426lSEuvzYmsCwtTkA//RxMS73jfuRHHEeudkDQ6HRDnMMpfYampKQ7BIAKUy2XCgz/9a6nIi/WoKxYIP+SpUtRABjHod0+xKYevCPWpoKTzmY/C2gtanxdDSAnY7zes= 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-out2.suse.de (Postfix) with ESMTPS id B18B11F798 for ; Mon, 14 Oct 2024 14:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728917360; 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=zjq3v3Lg2vJC90kwOeAtxzi+YTEWHBs4W22wvHhQimk=; b=WWlC0HA/Qqck6nAozxB0gKsEHo41Kab1d/ImnxTHIgC7m6iYR/NCy8WwWDQ166VsE5n1EJ v/3EOke149dmgCuDrVKh0nXmJ5sjPuui8Hjg6RHP93MsIqrWhUopOebr2m8cBMlDx9T62k uQAoPtqsZvO51kjwfVXnZC9O+0lxATE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728917360; 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=zjq3v3Lg2vJC90kwOeAtxzi+YTEWHBs4W22wvHhQimk=; b=rSWuMPcG0HtFFh5speOeHUmgh6owNQzP0GlN0Rzy7KyEHeI645b2DiMnzIZwbscM+9bT0P 8owcreIuXEFqUKCQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="WWlC0HA/"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=rSWuMPcG DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728917360; 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=zjq3v3Lg2vJC90kwOeAtxzi+YTEWHBs4W22wvHhQimk=; b=WWlC0HA/Qqck6nAozxB0gKsEHo41Kab1d/ImnxTHIgC7m6iYR/NCy8WwWDQ166VsE5n1EJ v/3EOke149dmgCuDrVKh0nXmJ5sjPuui8Hjg6RHP93MsIqrWhUopOebr2m8cBMlDx9T62k uQAoPtqsZvO51kjwfVXnZC9O+0lxATE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728917360; 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=zjq3v3Lg2vJC90kwOeAtxzi+YTEWHBs4W22wvHhQimk=; b=rSWuMPcG0HtFFh5speOeHUmgh6owNQzP0GlN0Rzy7KyEHeI645b2DiMnzIZwbscM+9bT0P 8owcreIuXEFqUKCQ== 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 9565F13A42 for ; Mon, 14 Oct 2024 14:49:20 +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 JtJ2InAvDWdsbgAAD6G6ig (envelope-from ) for ; Mon, 14 Oct 2024 14:49:20 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb] Handle EINTR in run_under_shell Date: Mon, 14 Oct 2024 16:49:26 +0200 Message-Id: <20241014144926.10842-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: B18B11F798 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 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, SPF_HELO_NONE, SPF_PASS, TXREP 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 When building gdb with -O2 -fsanitize=thread and running test-case gdb.base/bg-exec-sigint-bp-cond.exp, I run into: ... (gdb) c&^M Continuing.^M (gdb) Quit^M (gdb) quit_count=1 ^M Breakpoint 2, foo () at bg-exec-sigint-bp-cond.c:23^M 23 return 0;^M FAIL: $exp: no force memory write: \ SIGINT does not interrupt background execution ... What happens is that: - the breakpoint hits - while evaluating the condition of the breakpoint, $_shell("kill -INT ") is called, handled by run_under_shell - in run_under_shell, a vfork is issued - in the vfork child, execl executes the kill command - in the vfork parent, waitpid is called to wait for the result of the kill command - waitpid returns -1 with errno set to EINTR - run_under_shell doesn't check the result of waitpid, and returns the value of local variable status. Since waitpid returned -1, status was not assigned a value, so it's uninitialized, and happens to be non-zero - the breakpoint condition evaluates to true, because $_shell("kill -INT ") != 0 - the breakpoint triggers a stop, which the test-case doesn't expect. Fix this by using gdb::handle_eintr to call waitpid in run_under_shell. Also handle the case that waitpid returns an error other than EINTR, using perror_with_name. Tested on x86_64-linux. PR gdb/30695 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30695 --- gdb/cli/cli-cmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) base-commit: 22c62092858e5623338a18a42491718d754977e8 diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index ea2e156a00c..65ac7d6e7fb 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -55,6 +55,7 @@ #include "extension.h" #include "gdbsupport/pathstuff.h" #include "gdbsupport/gdb_tilde_expand.h" +#include "gdbsupport/eintr.h" #ifdef TUI #include "tui/tui.h" @@ -921,7 +922,11 @@ run_under_shell (const char *arg, int from_tty) } if (pid != -1) - waitpid (pid, &status, 0); + { + int ret = gdb::handle_eintr (-1, ::waitpid, pid, &status, 0); + if (ret == -1) + perror_with_name ("Cannot get status of shell command"); + } else error (_("Fork failed")); return status;