From patchwork Wed Nov 15 18:06:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 79971 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 C083C3858409 for ; Wed, 15 Nov 2023 18:07:09 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id EC93B3858D32 for ; Wed, 15 Nov 2023 18:06:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC93B3858D32 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 EC93B3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700071614; cv=none; b=A5Gi88FvXz1xL083swEnjYrOQubOX4OQORhhInjFfaYRxFaBidkSVuC5iWC7pnQnp5brXOdj7AWUoho7BO9fKXiCRtck0GU0H2sKsVYxACSdlfCu8ibrhAbRgeth7ily035VKiDuU26tVEr0TPO3GJkHCVvDMxKcQUYg3VpWmmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700071614; c=relaxed/simple; bh=eP9ue6OkIL/l4llOpcWBsUbBugxngM0XoXAO++oevXg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RyMYJsp7NWjAJw4CoeMVumgQSQ/wGZLDGjqrl708EN9KUFlebrEFYPsqedubEZIo7SOsrHz4fMtwddCt3tNv91YD5RA8vE7XZc5EoZU0oDLnTrGG0FqErXuKJ0bMnZokjSPWyNM8XCwyvdXT1gbY8fteToNF1s2XK28HqK7Lpek= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4083cd3917eso58215855e9.3 for ; Wed, 15 Nov 2023 10:06:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700071611; x=1700676411; 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=uvbo1DqjLfkkdgbhsUET8zwHg1XFHWRxkA9qjwe/pU8=; b=XuIX5KSY7NHEirtXu/b0qGqmgg31Lk7p78I9fYQ3wSaxtYKkAhrKzp1gqaIYH8v3w7 AyPz7a5Az6/Q2ybII5HONgtyjBUyZsGI7M/IUdsnjJGqoRgCITiGxtOsBfxevuRDhNoS ZNksZOQ0qpMFvBfW3i5X3KZ3sxNSKq/jGulCQ6AVNoA6j0i49GpEHZSBcJVyoqvVLVdg z6vaPjguZer2bP/QSUCCwdKlt0cyYqb9Bx3fkknDZLhmoGpnCy9cxC8V4YMcKrKkO4GI KGW22wy9Dca4hcLjjB1vhTgqzV5MhgOvJuOgGF6DO/N/+iJe9+KLGh7zl9V4u7tdm3tB EKmA== X-Gm-Message-State: AOJu0YwHivn+k9Uuu23dgke7WBwz7MmIt7/9qmdsRQ0l3acqJi7vmW5G mACep+fhL2Y6x3JVXbn/fyrXHcQJtDJb7Q== X-Google-Smtp-Source: AGHT+IHWcZN/JSXiyC8bTufMKK68LxvnNKT9jSsZuaHXnfeRSikTB9Bhn0sVjaPk1y/ec2z4XHN0xw== X-Received: by 2002:a05:600c:2d8b:b0:406:4573:81d2 with SMTP id i11-20020a05600c2d8b00b00406457381d2mr11512839wmg.39.1700071610425; Wed, 15 Nov 2023 10:06:50 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:13f2:4409:9776:8d51]) by smtp.gmail.com with UTF8SMTPSA id l39-20020a05600c1d2700b003fe23b10fdfsm443840wms.36.2023.11.15.10.06.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Nov 2023 10:06:50 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Fix gdb.threads/threads-after-exec.exp race Date: Wed, 15 Nov 2023 18:06:40 +0000 Message-Id: <20231115180640.811872-1-pedro@palves.net> X-Mailer: git-send-email 2.34.1 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 Simon noticed that gdb.threads/threads-after-exec.exp was racy. You can consistenly reproduce it (at git hash 319b460545dc79280e2904dcc280057cf71fb753), with: $ taskset -c 0 make check TESTS="gdb.threads/threads-after-exec.exp" gdb.log shows: (...) Thread 3 "threads-after-e" hit Catchpoint 2 (exec'd .../gdb.threads/threads-after-exec/threads-after-exec), 0x00007ffff7fe3290 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) PASS: gdb.threads/threads-after-exec.exp: continue until exec info threads Id Target Id Frame * 3 process 1443269 "threads-after-e" 0x00007ffff7fe3290 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) FAIL: gdb.threads/threads-after-exec.exp: info threads (...) maint info linux-lwps LWP Ptid Thread ID 1443269.1443269.0 1.3 (gdb) FAIL: gdb.threads/threads-after-exec.exp: maint info linux-lwps The FAILs happen because the .exp file expects that after the exec, the only thread has GDB thread number 1, but it has instead 3. This is yet another case of zombie leader detection making things a bit fuzzy. In the passing case, we have: continue Continuing. [New Thread 0x7ffff7bff640 (LWP 603183)] [Thread 0x7ffff7bff640 (LWP 603183) exited] process 603180 is executing new program: .../gdb.threads/threads-after-exec/threads-after-exec While in the failing case, we have (note remarks on the rhs): continue Continuing. [New Thread 0x7ffff7bff640 (LWP 600205)] [Thread 0x7ffff7f95740 (LWP 600202) exited] <<< gdb deletes leader thread, thread 1. [New LWP 600202] <<< gdb adds it back -- this is now thread 3. [Thread 0x7ffff7bff640 (LWP 600205) exited] process 600202 is executing new program: .../threads-after-exec/threads-after-exec The testcase only has two threads, yet GDB presented the exec for thread 3. This is GDB deleting the leader (the backend detected it was zombie, due to the exec), and then adding the leader back when it saw the exec event. I've recorded some thoughts about this in PR gdb/31069. For now, this commit just makes the testcase cope with the non-one thread number, as the number is not important for what this test is exercising. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31069 Change-Id: Id80b5c73f09c9e0005efeb494cca5d066ac3bbae --- gdb/testsuite/gdb.threads/threads-after-exec.exp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) base-commit: 7d21600b31fe959b758ed475a2211d6805047df9 diff --git a/gdb/testsuite/gdb.threads/threads-after-exec.exp b/gdb/testsuite/gdb.threads/threads-after-exec.exp index cd8adf900d9..8d5a518f7b6 100644 --- a/gdb/testsuite/gdb.threads/threads-after-exec.exp +++ b/gdb/testsuite/gdb.threads/threads-after-exec.exp @@ -32,14 +32,18 @@ proc do_test { } { gdb_test "continue" "Catchpoint $::decimal .*" "continue until exec" # Confirm we only have one thread in the thread list. - gdb_test "info threads" "\\* 1\[ \t\]+\[^\r\n\]+.*" + gdb_test "p \$_inferior_thread_count" " = 1" + + # Get the post-exec thread number. Due to PR gdb/31069 ("Zombie + # leader detection racy") this isn't always thread 1.1. + set cur_thr [get_integer_valueof "\$_thread" 0] if {[istarget *-*-linux*] && [gdb_is_target_native]} { # Confirm there's only one LWP in the list as well, and that - # it is bound to thread 1.1. + # it is bound to the existing GDB thread. set inf_pid [get_inferior_pid] gdb_test_multiple "maint info linux-lwps" "" { - -wrap -re "Thread ID *\r\n$inf_pid\.$inf_pid\.0\[ \t\]+1\.1 *" { + -wrap -re "Thread ID *\r\n$inf_pid\.$inf_pid\.0\[ \t\]+1\.$cur_thr *" { pass $gdb_test_name } }