From patchwork Thu Apr 24 21:47:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serhei Makarov X-Patchwork-Id: 110966 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 B7F193858D21 for ; Thu, 24 Apr 2025 21:50:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7F193858D21 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=serhei.io header.i=@serhei.io header.a=rsa-sha256 header.s=fm3 header.b=AAly14Y7; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=TR6Rnpkg X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from fhigh-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.156]) by sourceware.org (Postfix) with ESMTPS id 766553858D35 for ; Thu, 24 Apr 2025 21:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 766553858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=serhei.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=serhei.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 766553858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=202.12.124.156 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745531329; cv=none; b=pkwCYZLneHECQTZJDGNLe4S7KWEsVv32NtP8ndkdr0+XVRH8KfGV3dKTLbHCR1uhRplhP2Kgahl5ZIPfFyWl8LJSLRAdkIFj3IiQVPo0FUosF7oU6vkx1FtgAFAistu06dzdYdJp6xAppm955YZndx0ug3SAKaCrkPKGhioupy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745531329; c=relaxed/simple; bh=QJANPKDSbTfZEqjaCQm4cpxfGXRL/TUxFLOrE8UyZxU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=uoxUyzGkw2EU/lhLhVeZ8n8q0VIapf87kbLCcgUEibdOVtmg9nXvBa2uuzNMQXNskVwGIALmtAIQ+4viOJ5ABGVGi6urXN3YH63kY/NqbLOxdaDcqgn7rq/+zMKlNfQW2Vb/a+QX0vz9WaTOTP7PUNucerNA55DxQ9OPM+q39Zk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 766553858D35 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id 1BA25254023C; Thu, 24 Apr 2025 17:48:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 24 Apr 2025 17:48:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=serhei.io; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1745531328; x= 1745617728; bh=+s2QhLtIiEUMcGn6vw9fMRNXOVdQjsKOMkSsk4wgyic=; b=A Aly14Y7T6u0H3eHsptI6RjAfGpuOt883n8xCx3rGwRXJcIuxHd1Haapm9erlycpJ pNRZLvR/4ZaG1e6iPanbO9jZE3QPPgAUHP+99yNEOnWuqcJHJs6ZnLKUyIUVYs2j 5lTZH0lmWXQABtX/7LZuJqg5CNziIBy4cDz/p97hsLYsYlabtxe1YWQzyo+swuS0 SBL745VvGUvDRki4rlfMc3/Ccb6efP3/G+42tnyFoRREqR7aLZ2a3ziiJnzSbMRr nrWXeeadHsM15TTMrhXN2BO+jilO7+ooQosWLzAQd4IqnTGOa0NyYeKyv3WeKDwb E91b+fXQyoICLePtaszig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1745531328; x=1745617728; bh=+ s2QhLtIiEUMcGn6vw9fMRNXOVdQjsKOMkSsk4wgyic=; b=TR6RnpkgOO/WWJJew K4E3fW7ZONY7H+SlUNYWvT/qXxNWdZpeAgwnzFwlYowwr4CYILsbkMufE48iy2EP 0TtaanDpcAB/R5aR/UuBXSmaqmk84OD755UYlVFXKRq9ntUIAmceG6dVC1m4NeeY 3GCWEmfdT4Ma4sXV3Z7xttAAiP+vGQxCKI/tpW9lf4ta3zfd86OWP5RHqnEBDLtb 9MIQ/Pq13BZYYsDLbYkvTWHneOY9CxJgGTMCEVLMPMCocTU0NSrtJQ85eSPiMoCr 5vcoPrgM4GUD10P5kP13Va23RJEzA1QL3oN97Y77NAu5JhPt80Typw7kki08sjkw FO+PA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvhedtheelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvghrhhgvihcuofgrkhgr rhhovhcuoehsvghrhhgvihesshgvrhhhvghirdhioheqnecuggftrfgrthhtvghrnheptd euudfftdehgfetheehlefghefffeegieekheefgfdufefgudeifefhvefgudeknecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshgvrhhhvghise hsvghrhhgvihdrihhopdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopegvlhhfuhhtihhlshdquggvvhgvlhesshhouhhrtggvfigrrhgvrdhorh hgpdhrtghpthhtohepshgvrhhhvghisehsvghrhhgvihdrihho X-ME-Proxy: Feedback-ID: i572946fc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Apr 2025 17:48:48 -0400 (EDT) From: Serhei Makarov To: elfutils-devel@sourceware.org Cc: Serhei Makarov Subject: [PATCH v5 09/12] libdwfl_stacktrace [9/12]: add dwflst_tracker_find_pid Date: Thu, 24 Apr 2025 17:47:12 -0400 Message-ID: <20250424214715.306147-10-serhei@serhei.io> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250424214715.306147-1-serhei@serhei.io> References: <20250424214715.306147-1-serhei@serhei.io> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org Changes for v4: - Separate out libdwfl_stacktrace, as requested. Changes for v2: - Add locking for dwfltab. * * * New function that retrieves the Dwfl for a particular PID, or, if the Dwfl is absent, creates it via a provided callback and adds it to the table later, when the PID is confirmed via dwfl_attach_state. * libdwfl_stacktrace/libdwfl_stacktrace.h (dwflst_tracker_find_pid): New function. * libdwfl_stacktrace/dwfl_process_tracker.c (dwflst_tracker_find_pid): New function; find a Dwfl in the dwfltab or create one using the provided callback. The newly created Dwfl will be added to the dwfltab automatically when its pid is confirmed by a call to dwfl_attach_state. * libdw/libdw.map: Add dwflst_tracker_find_pid. --- libdw/libdw.map | 1 + libdwfl_stacktrace/dwflst_process_tracker.c | 26 +++++++++++++++++++++ libdwfl_stacktrace/libdwfl_stacktrace.h | 11 +++++++++ 3 files changed, 38 insertions(+) diff --git a/libdw/libdw.map b/libdw/libdw.map index 46d0878a..688e415c 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -404,4 +404,5 @@ ELFUTILS_0.193_EXPERIMENTAL { dwflst_tracker_cache_elf; dwflst_module_gettracker; dwflst_tracker_linux_proc_find_elf; + dwflst_tracker_find_pid; }; diff --git a/libdwfl_stacktrace/dwflst_process_tracker.c b/libdwfl_stacktrace/dwflst_process_tracker.c index f72b72b0..fc019b23 100644 --- a/libdwfl_stacktrace/dwflst_process_tracker.c +++ b/libdwfl_stacktrace/dwflst_process_tracker.c @@ -67,6 +67,32 @@ Dwfl *dwflst_tracker_dwfl_begin (Dwflst_Process_Tracker *tracker) return dwfl; } +Dwfl *dwflst_tracker_find_pid (Dwflst_Process_Tracker *tracker, + pid_t pid, + Dwfl *(*callback) (Dwflst_Process_Tracker *, + pid_t, void *), + void *arg) +{ + Dwfl *dwfl = NULL; + + rwlock_rdlock (tracker->dwfltab_lock); + dwflst_tracker_dwfl_info *ent + = dwflst_tracker_dwfltab_find(&tracker->dwfltab, pid); + rwlock_unlock (tracker->dwfltab_lock); + + if (ent != NULL && !ent->invalid) + dwfl = ent->dwfl; + if (dwfl == NULL && callback != NULL) + dwfl = callback(tracker, pid, arg); + if (dwfl != NULL) + { + assert (dwfl->tracker == tracker); + /* XXX: dwfl added to dwfltab when dwfl->process set in dwfl_attach_state. + Prior to that, the pid is not confirmed. */ + } + + return dwfl; +} void internal_function diff --git a/libdwfl_stacktrace/libdwfl_stacktrace.h b/libdwfl_stacktrace/libdwfl_stacktrace.h index d29dc640..ed6a6a5c 100644 --- a/libdwfl_stacktrace/libdwfl_stacktrace.h +++ b/libdwfl_stacktrace/libdwfl_stacktrace.h @@ -79,6 +79,17 @@ extern bool dwflst_tracker_cache_elf (Dwflst_Process_Tracker *tracker, Elf *elf, int fd) __nonnull_attribute__ (1, 2); +/* Find the Dwfl corresponding to PID. If CALLBACK is non-NULL and + the Dwfl has not been created, invoke CALLBACK to create the Dwfl + and then store it in the tracker. */ +extern Dwfl *dwflst_tracker_find_pid (Dwflst_Process_Tracker *tracker, + pid_t pid, + Dwfl *(*callback) (Dwflst_Process_Tracker *tracker, + pid_t pid, + void *arg), + void *arg) + __nonnull_attribute__ (1); + /* For implementing a find_elf callback based on the prior two functions. Returns the Dwflst_Process_Tracker corresponding to MOD. */ extern Dwflst_Process_Tracker *dwflst_module_gettracker (Dwfl_Module *mod);