From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Kdo9EOqbS2pKvCkAWB0awg (envelope-from ) for ; Mon, 06 Jul 2026 08:13:30 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dc16t8NI; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3F6421E070; Mon, 06 Jul 2026 08:13:30 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 98C1D1E070 for ; Mon, 06 Jul 2026 08:13:29 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BF2C4BA2E12 for ; Mon, 6 Jul 2026 12:13:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BF2C4BA2E12 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dc16t8NI Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by sourceware.org (Postfix) with ESMTPS id 0C6E44BA2E17 for ; Mon, 6 Jul 2026 12:12:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C6E44BA2E17 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0C6E44BA2E17 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783339974; cv=none; b=WJmg2+r6Xw+ubulyhazixYzHYSbtkK5VcF2WGZfAwQReJGN4As5PCPlQ9OfkDNtMGAmHJ9pkZtxvzOKJvANXc7WArJfY4nYZUTIPAfgdj503oHXVNDElav2x31aQMgFMPUA7Zd9EbncRTMDjeYovqjfwzVvhRCcdLWB9ev7hX7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783339974; c=relaxed/simple; bh=rRXWCL2A+5ETGtJ+7iT1YBeMbO0nMn5/bUkBbwQv+8s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aJUqOn3lokYOpcz88EMVLJC3NAG3+lShNFC2fq78gdjNWVsIq6PF9GVvZGiZ8Zmya+LcBhLWTGRVNVS2cBWftkOzW34TXzfk/nqR8rTAyd2PGKBDVh7N5JBIzZozOOmA4rEzZts4FTgG4GcJT2G4oEVeqwgaLwDCPsH2LshOToc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dc16t8NI DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C6E44BA2E17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783339974; x=1814875974; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rRXWCL2A+5ETGtJ+7iT1YBeMbO0nMn5/bUkBbwQv+8s=; b=dc16t8NI+f1ougJCEU/DydHl9VVT+UHb2GH8+QIuy4T9shyOOp9hciww LP/1J8T5A5F1GPt64aGGF6Ii90rjvfevuHPQZnwj9bp8XwtoqRSL9Gxmc 3sheDD1gN5i6eKq1ZSzj5Abte0kTsVKh/aYWBIXEp04AzIiE8AKmOK6y3 H5etbgspha2GVgbKXlJngNe236jOPHsbtYGpGir2JtrbDOunfUAsTaOF3 i0id0N0NX7eqgGb0HNepBRo/HCx+k1toZHrCWz5Svmebj4vibR9UM8LOV 6ylZyfkl7crL0whnUzqsqyCY80EwAs2nRk2H38Bj4qj2oz2wtEBu6COlz Q==; X-CSE-ConnectionGUID: qZnd4fd0RKKOtux97ymq6w== X-CSE-MsgGUID: lpRdN/pgRIugVkvqJXU0LA== X-IronPort-AV: E=McAfee;i="6800,10657,11838"; a="83834565" X-IronPort-AV: E=Sophos;i="6.25,149,1779174000"; d="scan'208";a="83834565" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2026 05:12:53 -0700 X-CSE-ConnectionGUID: AbxqMJSISHibOeO+Vl3utw== X-CSE-MsgGUID: ulOZIbzFSE28fg4NiR1DEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,149,1779174000"; d="scan'208";a="255637969" Received: from unknown (HELO localhost) ([10.245.114.180]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2026 05:12:52 -0700 From: Mohamed Bouhaouel To: gdb-patches@sourceware.org Cc: stephan.rohr@intel.com, markus.t.metzger@intel.com, pedro@palves.net, aburgess@redhat.com Subject: [PATCH v3 05/11] gdb, remote: fix crash when accessing removed events Date: Mon, 6 Jul 2026 14:11:18 +0200 Message-ID: <20260706121124.18784-6-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260706121124.18784-1-mohamed.bouhaouel@intel.com> References: <20260706121124.18784-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 From: "Bouhaouel, Mohamed" Dereferencing events after calling std::remove_if causes GDB to crash because the matching unique_ptrs have been moved from and are null. Fix by logging events in std::remove_if. The bug is visible by inspection; reproducing it requires discard_pending_stop_replies to be called with matching entries in the queue and remote debug logging enabled. --- gdb/remote.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index f6178caf7a1..323edd6cb0f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8254,17 +8254,20 @@ remote_target::discard_pending_stop_replies (struct inferior *inf) /* Discard the stop replies we have already pulled with vStopped. */ - auto iter = std::remove_if (rs->stop_reply_queue.begin (), - rs->stop_reply_queue.end (), - [=] (const stop_reply_up &event) - { - return event->ptid.pid () == inf->pid; - }); - for (auto it = iter; it != rs->stop_reply_queue.end (); ++it) - remote_debug_printf - ("discarding queued stop reply: ptid: %s, ws: %s\n", - (*it)->ptid.to_string().c_str(), - (*it)->ws.to_string ().c_str ()); + auto iter + = std::remove_if (rs->stop_reply_queue.begin (), + rs->stop_reply_queue.end (), + [=] (const stop_reply_up &event) + { + if (event->ptid.pid () != inf->pid) + return false; + + remote_debug_printf + ("discarding queued stop reply: ptid: %s, ws: %s\n", + event->ptid.to_string ().c_str (), + event->ws.to_string ().c_str ()); + return true; + }); rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ()); } -- 2.43.0 Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928