From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FF2nFp5SI2ZGwDUAWB0awg (envelope-from ) for ; Sat, 20 Apr 2024 01:29:02 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=R943YG7J; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 418621E0C0; Sat, 20 Apr 2024 01:29:02 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 217411E030 for ; Sat, 20 Apr 2024 01:29:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6ACA3858427 for ; Sat, 20 Apr 2024 05:28:59 +0000 (GMT) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 388DF3858D33 for ; Sat, 20 Apr 2024 05:28:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 388DF3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 388DF3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713590920; cv=none; b=JtP3kDSUuro0QMH17FLf/0ThBVJfmNxHtlspU6I5jsnmsHDkYA7Dqi3ruFpZB1j/o1BLveJwQLxvPd6rlnneTxR/mKVnF1BlOQjUWHeiIVNHnmguyUCFnIGGA5/aVhjceTgUCozOAehaQIuRh+y780074adYM+xBndjeW1SNfmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713590920; c=relaxed/simple; bh=nrMwdpxlBRHDK79sruAH1Lc3F+lUyDS03YUrauSv+uQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=j/txiJQabZdsPySopiX6id2MuA650lSZMjl6YjuFGMRTqrH3wgGdvg0iv+A5XL5cNPqxXaR8Lr42AO3lOoeTl2Y9Jk1osF9o8pqSRCMzKu5kB0xiGbsRFGeTR2Zig+eepbq745XNxUb/HsuG1SHDICXI4lVaW8lspt+KnB0Y3cg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1e5715a9ebdso23226985ad.2 for ; Fri, 19 Apr 2024 22:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713590917; x=1714195717; darn=sourceware.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=tOKZmiKx+Wr3CLD0L/UJ/31zYw/8VJ7KjB3xavaKnus=; b=R943YG7JPyvwiI2EjVRKTTyxihDG+Mjkl2Q7lO26gWAl1fRNzenvmpTy+24xMsH0ET fwmLdhkM4qZzt9LpybW5l6154CC5C1T7FJdn/wJsJB1ZtUiM8gkR42X0xgnL7OsooHPp oLV2dL8KJI2qOzOc0dfoDy0f+7Vm8yu0q/TT4q+jw4iWkaSc3unil1uU3h7amWipftTA ti7ROCei3jL86DLj3fihoSifkHkzc+5mLLs+Gf2KkMFYE/fbqPH/9WSt8caBpDzGIis0 Iqn1G2KX4mkoNw0VEQrUZ7Izj0zNZgz6JPbUV0292Zr4g/VY5QglcutWGGvyDwD/SQ0h kNMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713590917; x=1714195717; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tOKZmiKx+Wr3CLD0L/UJ/31zYw/8VJ7KjB3xavaKnus=; b=H5v+rN/wd51hK+Qgb406K+hlhj264l/3STzzQzLbcTFQpDv5ozkWNNZZn9I/kjSJFT W+DMHlI2JVzngq/OzxjznOBDHu/PTqYe7e8gG+u56qadKnvsOoaVfnowdBE0zTczu8q5 tGW5FQWcFHVpySvOF3B2Ebt1ilj/XkFjcCuBl9TJrSQgWSfITnog+fmloGDSya+arAVZ uQGkJ9n76SC90FmV3SV4S8WbO+DVpcelrysqIiyHE3u4FUu3UTDS2SreddELmOESBuZM KLwuPSGUjF+3MSLFlCHGIjU68l7ySfKEQIm+q5quySvU6xpCeQkK2aC+9wPsE4XYpUU6 eCsQ== X-Gm-Message-State: AOJu0YxlLywA9ACYH/s+yZcpp7e89FrJcoc3vNUEilCXFilPujdscd7m hwi1B+bg3uiJaQCtAcVTER8dRSZoCgqc6Bot2lKBAqlfLVLiyS9eagD5rxnGbb/DxUizeXRCIcn r X-Google-Smtp-Source: AGHT+IHfy/uqgZmMC8ptFIoexpqXwFgFEUBFpiPbGpWc/5jkg4pTa5g7xYowzTVQQy8VqPAGjxK4Ow== X-Received: by 2002:a17:903:11ce:b0:1e5:8175:4968 with SMTP id q14-20020a17090311ce00b001e581754968mr4738778plh.9.1713590917064; Fri, 19 Apr 2024 22:28:37 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:1348:72c4:7c65:61e7]) by smtp.gmail.com with ESMTPSA id i13-20020a170902c94d00b001ddddc8c41fsm4254264pla.157.2024.04.19.22.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 22:28:36 -0700 (PDT) From: Thiago Jung Bauermann To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [RFC PATCH 3/3] gdb/nat/linux: Fix attaching to process when it has zombie threads In-Reply-To: <29215aa0-8387-4dee-8b8d-3cbf64e6abe3@palves.net> (Pedro Alves's message of "Wed, 17 Apr 2024 17:28:12 +0100") References: <20240321231149.519549-1-thiago.bauermann@linaro.org> <20240321231149.519549-4-thiago.bauermann@linaro.org> <29215aa0-8387-4dee-8b8d-3cbf64e6abe3@palves.net> User-Agent: mu4e 1.12.4; emacs 29.3 Date: Sat, 20 Apr 2024 02:28:33 -0300 Message-ID: <8734rgk3ge.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+public-inbox=simark.ca@sourceware.org Pedro Alves writes: > On 2024-03-21 23:11, Thiago Jung Bauermann wrote: >> diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c >> index c254f2e4f05b..998279377433 100644 >> --- a/gdb/nat/linux-osdata.c >> +++ b/gdb/nat/linux-osdata.c >> @@ -112,6 +112,28 @@ linux_common_core_of_thread (ptid_t ptid) >> return core; >> } >> >> +/* See linux-osdata.h. */ >> + >> +std::optional >> +linux_get_starttime (ptid_t ptid) > > Ditto re. moving this to linux-procfs. This has nothing to do with "info osdata". Done in v2. >> index a82fb08b998e..1cdc687aa9cf 100644 >> --- a/gdb/nat/linux-osdata.h >> +++ b/gdb/nat/linux-osdata.h >> @@ -27,4 +27,8 @@ extern int linux_common_core_of_thread (ptid_t ptid); >> extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, >> ULONGEST offset, ULONGEST len); >> >> +/* Get the start time of thread PTID. */ >> + >> +extern std::optional linux_get_starttime (ptid_t ptid); >> + >> #endif /* NAT_LINUX_OSDATA_H */ >> diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c >> index b17e3120792e..b01bf36c0b53 100644 >> --- a/gdb/nat/linux-procfs.c >> +++ b/gdb/nat/linux-procfs.c >> @@ -17,10 +17,13 @@ >> along with this program. If not, see . */ >> >> #include "gdbsupport/common-defs.h" >> +#include "linux-osdata.h" >> #include "linux-procfs.h" > > linux-procfs.h is the main header of this source file, so it should be first. > But then again, I think this shouldn't be consuming things from linux-osdata, it > should be the other way around. Right. v2 doesn't need to include "linux-osdata.h" anymore. >> #include "gdbsupport/filestuff.h" >> #include >> #include >> +#include >> +#include >> >> /* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not >> found. */ >> @@ -290,6 +293,10 @@ linux_proc_attach_tgid_threads (pid_t pid, >> return; >> } >> >> + /* Keeps track of the LWPs we have already visited in /proc, >> + identified by their PID and starttime to detect PID reuse. */ >> + std::set> visited_lwps; > > Missing space before ULONGEST. Ah, indeed. Fixed in v2. > AFAICT, you don't rely on order, so this could be an unordered_set? True. Done in v2, but I had to add a hash function for std::pair. I don't know anything about constructing hashes, so I just went with what I saw elsewhere in GDB (index_key_hasher in dwarf2/index-write.c) and XOR the hashes of each element of the pair. >> + >> /* Scan the task list for existing threads. While we go through the >> threads, new threads may be spawned. Cycle through the list of >> threads until we have done two iterations without finding new >> @@ -308,6 +315,18 @@ linux_proc_attach_tgid_threads (pid_t pid, >> if (lwp != 0) >> { >> ptid_t ptid = ptid_t (pid, lwp); >> + std::optional starttime = linux_get_starttime (ptid); >> + >> + if (starttime.has_value ()) >> + { >> + std::pair key (lwp, *starttime); > > Space before ULONGEST. Fixed in v2. >> + >> + /* If we already visited this LWP, skip it this time. */ >> + if (visited_lwps.find (key) != visited_lwps.cend ()) >> + continue; >> + >> + visited_lwps.insert (key); >> + } >> >> if (attach_lwp (ptid)) >> new_threads_found = 1; Thank you for the patch reviews. -- Thiago