From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by sourceware.org (Postfix) with ESMTPS id 1649F3858435 for ; Mon, 22 Apr 2024 19:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1649F3858435 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 1649F3858435 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713815992; cv=none; b=i5Njqg4UVlPxnuql7xPqJkyCJb8iKnWBbwa0CGxsVUEoDGY+o7SRtjJQlJohSXJH9JjJXDFyEKRo/1rFUI6ixxo9PoGLvdEUOnASk33OAaDTu2lae7+TRBUqE/UMiYFXzEQvRAhby6Ty8ttoFOlKb9dzbMJAB63haNo8ECodqBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713815992; c=relaxed/simple; bh=97eTKuSrzIMtQ3io5S89up4HXnOimb/+9FaGlZBP5Dc=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=J5Fk2e9YNLRrEUcZuzPCV5IH6ORAcsK3fnxxquVhJWhuaB/uqWGURH56f6XKaZbyrTiopqOjRtUhtI2jkbr/sWl/Q3Rd+ViNZeB82flFfu1qFkHtr68uAI/eggtgC2odzOnd0wQRuDoPN7/cEiJ5OLHfKqPRS5p/aMTNOpdl+aI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-34a7e47d164so2732722f8f.3 for ; Mon, 22 Apr 2024 12:59:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713815989; x=1714420789; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LHaO/NTtxdNxMpwnprINJYDNpoDLZViFMzAeQXOjrG8=; b=qt4EEuc8VITaQXnvfsE3kzL1NnivBh5C+roDJkRUY1gyyHuDfrjkb2WkKaQHrL59+l v3Ip48SHxfmzfOkxxDI1oNFfbULbN6zrZLPM/ffzMjKPGyftf6hJUTaCzWt/gwW/zs2C 2rFRDxSHTpvIKwRckjEy7HYOhRmlwQd/XtrMmjrQ2fOQZ/0NiEIctOD8YImi4saVEvmb nK6TtsUKB1oDvnWoVxp8SAZCgtiaTUjtkJ30m1ZQWJZxtehchwHhcKqAC+uf2qwFw6VK EjR/Bqc5tB1kivyYDzKyRbw7illRuEiiE8Y/zORyct+PgD7/FuOtIJ15SmfZIHcVeAX9 65rg== X-Forwarded-Encrypted: i=1; AJvYcCXvdvSK+iDngfhfkK4FteadtTaLwGy74+rlwtHd4t2L+rDv+ZNJK+KBfAj6h9mNQlWBv3xzueiQCGl68k3kbPYpS7jhhXOMITuusA== X-Gm-Message-State: AOJu0YwP0vj9ub/DV/R7lP6jXZgLr0HAi0GIhWqNGMm94PUgSeziZM4F OsZiLGixNKUEXgfvZL1pnbSwf7DYUC4KP2UoSMTOhJQQLbk70uDr X-Google-Smtp-Source: AGHT+IHqOCXtPZ/QeHAHFWYBHB/SKCzftrJKCS6shjSIQ59Wdt/zarn7TSiaSyICWVSxSsVyVx+yxQ== X-Received: by 2002:a05:6000:45a0:b0:343:8e86:f2f0 with SMTP id gb32-20020a05600045a000b003438e86f2f0mr8489803wrb.62.1713815988756; Mon, 22 Apr 2024 12:59:48 -0700 (PDT) Received: from ?IPV6:2001:8a0:f93d:b900:8880:21cb:6a55:2a43? ([2001:8a0:f93d:b900:8880:21cb:6a55:2a43]) by smtp.gmail.com with ESMTPSA id l23-20020a05600c1d1700b00418f99170f2sm15411299wms.32.2024.04.22.12.59.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 12:59:39 -0700 (PDT) Message-ID: <9675ae26-3e85-4acd-8bbb-8de829818cc8@palves.net> Date: Mon, 22 Apr 2024 20:59:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/3] gdb/nat/linux: Fix attaching to process when it has zombie threads To: Thiago Jung Bauermann , gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado References: <20240420055652.819024-1-thiago.bauermann@linaro.org> <20240420055652.819024-4-thiago.bauermann@linaro.org> From: Pedro Alves Content-Language: en-US In-Reply-To: <20240420055652.819024-4-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 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 autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2024-04-20 06:56, Thiago Jung Bauermann wrote: > When GDB attaches to a multi-threaded process, it calls > linux_proc_attach_tgid_threads () to go through all threads found in > /proc/PID/task/ and call attach_proc_task_lwp_callback () on each of > them. If it does that twice without the callback reporting that a new > thread was found, then it considers that all inferior threads have been > found and returns. > > The problem is that the callback considers any thread that it hasn't > attached to yet as new. This causes problems if the process has one or > more zombie threads, because GDB can't attach to it and the loop will > always "find" a new thread (the zombie one), and get stuck in an > infinite loop. > > This is easy to trigger (at least on aarch64-linux and powerpc64le-linux) > with the gdb.threads/attach-many-short-lived-threads.exp testcase, because > its test program constantly creates and finishes joinable threads so the > chance of having zombie threads is high. > > This problem causes the following failures: > > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: attach (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: no new threads (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted on (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break break_fn (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 1 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 2 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 3 (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: reset timer in the inferior (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: print seconds_left (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: detach (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted off (timeout) > FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: delete all breakpoints, watchpoints, tracepoints, and catchpoints in delete_breakpoints (timeout) > ERROR: breakpoints not deleted > > The iteration number is random, and all tests in the subsequent iterations > fail too, because GDB is stuck in the attach command at the beginning of > the iteration. > > The solution is to make linux_proc_attach_tgid_threads () remember when it > has already processed a given LWP and skip it in the subsequent iterations. > > PR testsuite/31312 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31312 > > Reviewed-By: Luis Machado Approved-By: Pedro Alves BTW, after seeing the other patches after patch #1, I do agree with giving names to the stat fields.