From patchwork Thu Dec 14 20:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 82168 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 D4F84384F02C for ; Thu, 14 Dec 2023 20:23:12 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by sourceware.org (Postfix) with ESMTPS id 002933861884 for ; Thu, 14 Dec 2023 20:22:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 002933861884 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 002933861884 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702585370; cv=none; b=IRlHkYCPT8NUv/JmC0/TR2hGO9t4CILqH5O6DG/f4sFqO1Q7pRNkvpqfF+ZpcCPjOEsq316bHMPLa3KQ6sgm0sFvfXGSgkSAwE//AS137HIRBTCyaqwyYh9VC4ClP5kbT73h+NisWCK7hynLzscvzazbaFWI3g1fzIYOseo1Cvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702585370; c=relaxed/simple; bh=mgS9qWNoeXPiT9OqO7/JiZDfMoOUcGS/BhVbYysShW0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KyxBnbJBSwNZLEPRG9nQqVI/TMPVVm9aMvcj/Bs3bYNVc1AgGnZfXeRj++f8w9A2S03sw03VADVEFX2ZCkWwT6VNNRqGvKslMEULQJq8C9A4bMQLs3NiTHV/Kh0tteaqiAtPv5XCCFe9OGefcxdfL6uMTLKGk7fH1HuxpnHdgP0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40c69403b3eso1511335e9.3 for ; Thu, 14 Dec 2023 12:22:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702585366; x=1703190166; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JCsAKoIPbVGLOzyEK27t/7ZN7astFqJODNx4mVHCmHM=; b=ZBJ4hjlAk4yUeJEEj2hAcWvYykB2+OGfiqGUAa+GMyv9ZzLJlsZo/jZvUnn9Lo3bk3 GG4Rr8IDU78GDKRCi3g3ppa4U041avr2RnCX7iAuVtwpL/zcj02R1W7z2abqLGf9KhSP 9IskaP3FWEVKFnA4o+ltUzciMtPM+QjAIt4dRkaZNu5yL2HlH7AjycvzOJ6O93Onfxkw 1QKcbqgadegMq/xkyxtKXTgdxVL9pDmoiC+RxDYlwWfBte0V86Le1BeyWsuvqXATw/SD biPAMiuPMsrbtrbv6QOMx3ScBhPln8mQDcc01z9P9sX99quFqicZod50U1fDdCjdm6AG Xe7w== X-Gm-Message-State: AOJu0Yy5GEWOlwKCnugxI77w2FiVAu6o0fm9ZAA1a6gpON2o6xCqMOn7 pxC3j++bivQ2nfLzEpdUSXQKQxcAsLBURw== X-Google-Smtp-Source: AGHT+IGo9bulI6CwokWPqZ+LMOjygaU9C2wYlG8lMgA4FfJQ1j2k9fxcCPArwbgXYq4d8aSabVhz8Q== X-Received: by 2002:a05:600c:3b9f:b0:40c:2878:35ec with SMTP id n31-20020a05600c3b9f00b0040c287835ecmr5620876wms.131.1702585366569; Thu, 14 Dec 2023 12:22:46 -0800 (PST) Received: from localhost ([2001:8a0:f923:4f00:2646:535c:5a04:e380]) by smtp.gmail.com with UTF8SMTPSA id g20-20020a05600c4ed400b0040c31bb66dcsm25658587wmq.20.2023.12.14.12.22.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 12:22:46 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/8] Ensure selected thread after thread exit stop Date: Thu, 14 Dec 2023 20:22:32 +0000 Message-ID: <20231214202238.1065676-3-pedro@palves.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214202238.1065676-1-pedro@palves.net> References: <20231214202238.1065676-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 While making step over thread exit work properly on AMDGPU, I noticed that if there's a breakpoint on top of the exit syscall, and, displaced stepping is off, then when GDB reports "Command aborted, thread exited.", GDB also switches focus to a random thread, instead of leaving the exited thread as selected: (gdb) thread [Current thread is 6, lane 0 (AMDGPU Lane 1:4:1:1/0 (0,0,0)[0,0,0])] (gdb) si Command aborted, thread exited. (gdb) thread [Current thread is 5 (Thread 0x7ffff626f640 (LWP 3248392))] (gdb) The previous patch extended gdb.threads/step-over-thread-exit.exp to exercise this on GNU/Linux (on the CPU side), and there, after that "si", we always end up with the exiting thread as selected even without this fix, but that's just a concidence, there's a code path that happens to select the exiting thread for an unrelated reason. This commit add the explict switch, fixing the latent problem for GNU/Linux, and the actual problem on AMDGPU. I wrote a gdb.rocm/ testcase for this, but it can't be upstreamed yet, until more pieces of the DWARF machinery are upstream as well. Change-Id: I6ff57a79514ac0142bba35c749fe83d53d9e4e51 --- gdb/infrun.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gdb/infrun.c b/gdb/infrun.c index 45c1b4a79bb..6dc0a2bb9a5 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5895,7 +5895,14 @@ handle_thread_exited (execution_control_state *ecs) if (abort_cmd) { + /* We're stopping for the thread exit event. Switch to the + event thread again, as finish_step_over may have switched + threads. */ + switch_to_thread (ecs->event_thread); + + /* Emit [Thread ... exited] notification. */ delete_thread (ecs->event_thread); + ecs->event_thread = nullptr; return false; }