From patchwork Mon Nov 13 15:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 56367 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 9598338CA5D1 for ; Mon, 13 Nov 2023 15:05:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id 91A4A3858C01 for ; Mon, 13 Nov 2023 15:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91A4A3858C01 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 91A4A3858C01 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887890; cv=none; b=jT4YEbQ8bOht123iZOMlUZq8sOkVZga6KAALl1stg1GvI1uP7xS3BQIBUxwLUSZQJv/nPQmIcCd/synhs6H5JhF5MdEEuiXCiF7+Xrx/7x27BCRK7YkvifUwPYVgZsYwzFLf9H/fQJ30G2dxhFhL5P8cSgEbEjA5gon7dEMuHtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887890; c=relaxed/simple; bh=hnGwXn6XsqLWavwGPaRqIjY2r68z4tHCTH4gZD4NEPg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=kTIdnJT+Jj/732+ZXoW5ugDlbCUWCq3kqEffXGZmGNNSFNssc0lrQZ1xeId1uWFKLHPuhYupZfWYUw9qBbQofzzWSgbsn832EEBhSOzhtKqxZrXSsiWic9mCgT1DI6YIhD899XkpibOJNIl0B4uMNWOlM30aYNpY7qjvNl+oQac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-32d9effe314so2760153f8f.3 for ; Mon, 13 Nov 2023 07:04:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887884; x=1700492684; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=utQ6y9IuH+uLqNlLB8vm1G6Y9LBcIUBRYv7tHlfWBHQ=; b=xGeiP8nO+kBw6pshpC5V3RglZ8hBz2fZpdm0dLJI9uJqlP1m+M0A5oUol940NkDXZC flRX4QYo84EwzTsKVZBgKsSX4CpmihvfbGUww1x+9+vt87SENf3DmdG6k7Y9IKWqyeZv La3zfUmsqYQ2pUylCgdK33VajlX+VcHj8TnatvsyUyqAP2BilkOJPVpqe95aVnqKNQVf 2ajROFmj/k7thZHzKy+c6pUoylGdPAFfyQc7gA6JLqea8/OHNYDQ4tFMdUz7oH7Ehvf6 nGRJG/FX8Yb4P9quaA+pmoCfo4/LeyzdsHyvD4en4rqBX1Kt6n4jYzqpZGcg2vnvUs0l nZAw== X-Gm-Message-State: AOJu0Yw5lJ2wDLLBn3heJ15SBWNW8332CXvdkU3Q7DqKrqTZA6QbQYdU GYAeJA2s+CqJOKI6R9DiPV1Dp9v9tRM= X-Google-Smtp-Source: AGHT+IGByViJQTcKKQMzp4f0FzDIWghDf/L1vpEf+EFjZjBpC8b1+f7lUuXXGnmJV0fqOS1tukTX4Q== X-Received: by 2002:adf:fdcd:0:b0:32d:8982:ff1c with SMTP id i13-20020adffdcd000000b0032d8982ff1cmr4293472wrs.36.1699887883688; Mon, 13 Nov 2023 07:04:43 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id t6-20020a5d42c6000000b003313902cef5sm5598829wrr.93.2023.11.13.07.04.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:04:42 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [FYI/pushed v4 00/25] Step over thread clone and thread exit Date: Mon, 13 Nov 2023 15:04:02 +0000 Message-Id: <20231113150427.477431-1-pedro@palves.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, 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=no 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 Here's v4 of the series I previously posted here: [PATCH 00/31] Step over thread clone and thread exit https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-1-pedro@palves.net/ (That was v3, I had forgotten to update the subject line back then.) As I mentioned earlier today, I've addressed all the review comments in the remaining patches in the v3 series, and since none required any invasive/design change, I've gone ahead with merging this. If there's anything that doesn't look right, please don't hesitate to raise it and I'll try to address it. New in v4: - Patches 1-2, 29-30 from v3 were already merged a while ago. - Addressed Andrew's comments throughout. - The stepi-over-clone.exp testcase is now merged into the patch where the test first works on native GNU/Linux. - Patch "[PATCH 25/31] Ignore failure to read PC when resuming" from v3 was dropped, for now. Here's the series description, updated for v4: This is a new series that replaces two different series from a couple years ago. The first is this series Simon and I wrote, here: [PATCH 00/10] Step over thread exit (PR gdb/27338) https://sourceware.org/pipermail/gdb-patches/2021-July/180567.html The other is a series that coincidentally, back then, Andrew posted at about the same time, and that addressed problems in kind of the mirror scenario. His patch series was about stepping over clone (creating new threads), instead of stepping over thread exit: [PATCH 0/3] Stepping over clone syscall https://sourceware.org/pipermail/gdb-patches/2021-June/180517.html My & Simon's solution back then involved adding a new contract between GDB and GDBserver -- if a thread is single stepping, and it exits, the server was supposed to report back the thread's exit to GDB. One of the motivations for this approach was to be able to control the enablement of thread exit events per thread, to avoid creating thread-exit event traffic unnecessarily, as done by target_thread_events()/QThreadEvents. Andrew's solution involves using the QThreadEvents mechanism, which tells the server to report thread create and thread exit events for all threads. This would conflict with the desire to avoid unnecessary traffic in the step over thread exit series. The step over clone fixes back then also weren't yet fully complete, as Andrew's series only addressed inline step overs. Fixing displaced stepping over clone syscall would still remain broken. This new series fixes all of stepping over thread exit and clone, for both of displaced stepping and inline step overs. It: - Merges both Andrew's and my/Simon's series, and then reworks both parts in different ways. - Introduces clone events at the GDB core and remote protocol level. - Gets rid of the idea of "reporting thread exit if thread is single-stepping", replaces it by a new mechanism GDB can use to explicitly enable thread clone and/or thread exit events, and other events in the future. The old mechanism also only worked when the remote server supported hardware single-stepping. This new approach has an advantage of also working on software single-step targets. - Uses the new clone events to fix displaced stepping over clone syscalls too. - Addresses an issue that Andrew alluded to in his series, and that coincidentally, we/AMD also ran into with AMDGPU debugging -- currently, with "set scheduler-locking on", if you step over a function that spawns a thread, that thread runs free, for a bit at least, and then may stop or not, basically in an unspecified manner. - Cancels next/step/until/etc. commands on thread exit event, like so: (gdb) n [Thread 0x7ffff7d89700 (LWP 3961883) exited] Command aborted, thread exited. (gdb) - Non-trivial documentation changes have already been approved by Eli. Tested on x86-64 Ubuntu 20.04, native and gdbserver. Andrew Burgess (1): Add "maint info linux-lwps" command Pedro Alves (23): gdb/linux: Delete all other LWPs immediately on ptrace exec event Step over clone syscall w/ breakpoint, TARGET_WAITKIND_THREAD_CLONED Support clone events in the remote protocol Avoid duplicate QThreadEvents packets Thread options & clone events (core + remote) Thread options & clone events (native Linux) Thread options & clone events (Linux GDBserver) gdbserver: Hide and don't detach pending clone children Remove gdb/19675 kfails (displaced stepping + clone) all-stop/synchronous RSP support thread-exit events gdbserver/linux-low.cc: Ignore event_ptid if TARGET_WAITKIND_IGNORE Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core Introduce GDB_THREAD_OPTION_EXIT thread option, fix step-over-thread-exit Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver Implement GDB_THREAD_OPTION_EXIT support for native Linux gdb: clear step over information on thread exit (PR gdb/27338) stop_all_threads: (re-)enable async before waiting for stops gdbserver: Queue no-resumed event after thread exit Don't resume new threads if scheduler-locking is in effect Report thread exit event for leader if reporting thread exit events gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Document remote clone events, and QThreadOptions packet Cancel execution command on thread exit, when stepping, nexting, etc. Simon Marchi (1): Testcases for stepping over thread exit syscall (PR gdb/27338) gdb/NEWS | 32 + gdb/displaced-stepping.c | 7 + gdb/doc/gdb.texinfo | 136 +++- gdb/gdbarch-gen.h | 6 +- gdb/gdbarch_components.py | 4 + gdb/gdbthread.h | 16 + gdb/infrun.c | 588 +++++++++++++++--- gdb/linux-nat.c | 383 +++++++----- gdb/linux-nat.h | 4 + gdb/remote.c | 304 +++++++-- gdb/target-debug.h | 2 + gdb/target-delegates.c | 52 ++ gdb/target.c | 16 + gdb/target.h | 15 + gdb/target/target.c | 12 + gdb/target/target.h | 20 + gdb/target/waitstatus.c | 1 + gdb/target/waitstatus.h | 31 +- gdb/testsuite/gdb.base/step-over-syscall.exp | 44 +- .../gdb.threads/schedlock-new-thread.c | 54 ++ .../gdb.threads/schedlock-new-thread.exp | 67 ++ ...-over-thread-exit-while-stop-all-threads.c | 77 +++ ...ver-thread-exit-while-stop-all-threads.exp | 69 ++ .../gdb.threads/step-over-thread-exit.c | 52 ++ .../gdb.threads/step-over-thread-exit.exp | 155 +++++ gdb/testsuite/gdb.threads/stepi-over-clone.c | 90 +++ .../gdb.threads/stepi-over-clone.exp | 389 ++++++++++++ .../gdb.threads/threads-after-exec.c | 56 ++ .../gdb.threads/threads-after-exec.exp | 57 ++ gdb/testsuite/lib/my-syscalls.S | 54 +- gdb/testsuite/lib/my-syscalls.h | 5 + gdb/thread.c | 18 + gdbserver/gdbthread.h | 3 + gdbserver/linux-low.cc | 417 ++++++++----- gdbserver/linux-low.h | 78 ++- gdbserver/remote-utils.cc | 26 +- gdbserver/server.cc | 158 ++++- gdbserver/target.cc | 15 +- gdbserver/target.h | 28 +- 39 files changed, 2994 insertions(+), 547 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/schedlock-new-thread.c create mode 100644 gdb/testsuite/gdb.threads/schedlock-new-thread.exp create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit-while-stop-all-threads.c create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit-while-stop-all-threads.exp create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit.c create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit.exp create mode 100644 gdb/testsuite/gdb.threads/stepi-over-clone.c create mode 100644 gdb/testsuite/gdb.threads/stepi-over-clone.exp create mode 100644 gdb/testsuite/gdb.threads/threads-after-exec.c create mode 100644 gdb/testsuite/gdb.threads/threads-after-exec.exp base-commit: 6b682bbf86f37982ce1d270fb47f363413490bda