From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eUF9D9jVKmqOswEAWB0awg (envelope-from ) for ; Thu, 11 Jun 2026 11:35:52 -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=e3LnTBp6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3479C1E070; Thu, 11 Jun 2026 11:35:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 8C4C51E070 for ; Thu, 11 Jun 2026 11:35:51 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E7264BA79A0 for ; Thu, 11 Jun 2026 15:35:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E7264BA79A0 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=e3LnTBp6 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by sourceware.org (Postfix) with ESMTPS id 7F6494BA2E09 for ; Thu, 11 Jun 2026 15:34:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F6494BA2E09 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=tempfail smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7F6494BA2E09 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781192082; cv=none; b=qXPNzhMsSd5nYRc88OihgFJ6t9qb68sYK5uzVleFnHF8kGbXu7VrRo6sPrOo23345lmbcUly825ob8YDnqooEnuQUJIivwdZl238fynrXkpBCg91QEd5ru/4GdK34lGWF+ob53xZnYcUxshJhkpUmM2xWl9ak9jPVNFtAMZ3Rg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781192082; c=relaxed/simple; bh=a6C183Ip2u+hR4TRyYCW5amoAr6dnNAGs6wIInN374c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u/nzIwaDjvsGalJ5OurXmszyWLHoFkp7t0VpUSBdDh5VBjlaYyDXcD9jH2P+s/uzUEpOKVwz4vaLCpZjTruAfII6ov7kh2gfy/hgh0heq0Vt7Ed3KDB4DQjr2/uPgqglk9Dnq7x6VgadyuOIlzJH4Zz+I7Sl5n6jMqv4Idx9roU= 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=e3LnTBp6 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F6494BA2E09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781192078; x=1812728078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a6C183Ip2u+hR4TRyYCW5amoAr6dnNAGs6wIInN374c=; b=e3LnTBp6S3ftuqUOvkp0D9ZKADlifdBHRoj/O2Bo0eRKop8bWn8Ra1aZ 0m1+pYQZ2ogtU2TouUTtNI1Z78iCY6JxMwsmu0OygOSbMWIok+ZIXWx8x ukyyn65Pqk3EJvbdbWuV+cCsipin0jqqpGiXpNmk7GbEZToahNHqn9//T hlhbPQQb64eGMERtJhdcwvVa4xXfxQJTEa9hkxFWWn/AxIan8PG61vPzp RnKYESdfeF1HQAvYrh/PfUrxEHbLAdYA8KHACUtbwFoO7qWHwZFKjJaR7 sf1OdVbvu/vrbOLJK2of8zHKYPtLmO5ro2eGIpD2n2eV+8n/8Fc2UOXFP w==; X-CSE-ConnectionGUID: QTOo+HLUTOyLvdqkpOfoPQ== X-CSE-MsgGUID: eBlWX0RTT6Sb3kfMWquIMw== X-IronPort-AV: E=McAfee;i="6800,10657,11813"; a="104675584" X-IronPort-AV: E=Sophos;i="6.24,199,1774335600"; d="scan'208";a="104675584" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2026 08:34:37 -0700 X-CSE-ConnectionGUID: bDPn/iAKTQi0bqHcWcGSyA== X-CSE-MsgGUID: uL16bPK5Q4Wzbkrl7TL1eQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,199,1774335600"; d="scan'208";a="242117246" Received: from womilian-mobl.ger.corp.intel.com (HELO localhost) ([10.245.82.28]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2026 08:34:34 -0700 From: Mohamed Bouhaouel To: gdb-patches@sourceware.org Cc: markus.t.metzger@intel.com, stephan.rohr@intel.com, aburgess@redhat.com, mohamed.bouhaouel@intel.com Subject: [PATCH v2 05/11] gdb, remote: fix crash when accessing removed events Date: Thu, 11 Jun 2026 17:32:25 +0200 Message-ID: <20260611153232.3011-6-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260611153232.3011-1-mohamed.bouhaouel@intel.com> References: <20260611153232.3011-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 2c6c686ddeb..cc0170d922c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8314,17 +8314,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