From patchwork Thu Apr 24 21:47:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serhei Makarov X-Patchwork-Id: 110964 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 345663858D38 for ; Thu, 24 Apr 2025 21:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 345663858D38 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=HcNmAEBE; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=mk7pZnt9 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 595013858D38 for ; Thu, 24 Apr 2025 21:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 595013858D38 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 595013858D38 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=1745531282; cv=none; b=J4H4VO3XNfsGg2USvoRehEBwfu7HEoYxgSu/dbcEMHTs8jyz9nzoUGAMR76LTScYZbXzfvoVV69G4FiIq3CHRbT7f5xllAjRzIVYLPWNd/rCahEZwBbZKKKNCquSoOa0sO8cVJzzn8WmXtMFkLfvV47a0Z55h+ZhXURVk9H6OM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745531282; c=relaxed/simple; bh=SVPNwMCKe3UiwsKTFP4ZIEjtMsd/T99TwzMhYZ/fdBM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=E//l7oSLmZjY3nvxTyDpqttqrLNK72pnNqpyuNh8NXrMzZ9JqD+pLBGPYAPZU94nT7NDEqkXPpakOtCGfl8wwPaysTuHptvhLRsaGYOuEmTfyW6ADKscd4Hmt5QllauTyMO1KBceqVTz0jS/Nlh2P2WWAn66VOSNVRI0LUTqaYg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 595013858D38 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id F0008254020D; Thu, 24 Apr 2025 17:48:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 24 Apr 2025 17:48:02 -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=1745531281; x= 1745617681; bh=WaistFNJ//002qBDUXtcv0MhD6WWCfY6X4UH/F03deY=; b=H cNmAEBEXpc9iMfujBQgDhgj5gQt65jdLJwRIXK+0ZR2cgczmhA5sa6Wd8noisVmI aqpYbrf1Fti7c3eP2irnBv0tHXmt10Gm7fhhLLw+u7WFqcv9ap4wzKeXRHdEg1OY 4qhzKXLOS++fRW72CYFHukhpJKnJluKYljK4jtecMPp+o8rtGLSbDxYUAFqgg8en k8rx6k2I9CuCS8/0KGUTc6bT2+EDBMmtD8HmKoxEmj+9Jyh6cPcLLq1j0m4K2jl1 vMDFkAKmcKf4w0+o9HkfPr4KSDX0dK7Eiwh9SDyFZMPps/JbKiobzygNraQiPClu 3D8WeeIvnm7TnJ/1Ynlqg== 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=1745531281; x=1745617681; bh=W aistFNJ//002qBDUXtcv0MhD6WWCfY6X4UH/F03deY=; b=mk7pZnt9jK4gkH7NA mrYdR7+hpDl0MAQeegDvcnPuW80iQozAr6TnLzM1pP0UVRX+EXLPH9JUDqBLTs8+ N6VD1lzbC7kXpwle/x+dYwSeYvS5aEYDD7lmpsv6JuZZVCZ74X7fl1T5SwE0iDJ8 7gy5N3vrgXRiq/DsUkB6LnWnrR+qj7R9V5CrndB9qbUvPZgjQc187bvAZgva1Dpr 6TkZY7QFe4aYuHXQjMA5dvpk8d0ePzRcddiGgp9CjO4aFQeIUB3X0JitPyCt6UC9 gGAuRjlwP8W5NWJuLBDgFylPq5mwVcfJpfCXT4A5xKzYC8N3qGnVqGbZjnzoEhnl NrpjA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvhedtheekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvghrhhgvihcuofgrkhgr rhhovhcuoehsvghrhhgvihesshgvrhhhvghirdhioheqnecuggftrfgrthhtvghrnhepge evleelieegheetheeuhffgtdettdfhjeejfeelveduffdvuefgvdfffedvfeegnecuffho mhgrihhnpehqthdqphhrohhjvggtthdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehsvghrhhgvihesshgvrhhhvghirdhiohdpnhgs pghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepvghlfhhuth hilhhsqdguvghvvghlsehsohhurhgtvgifrghrvgdrohhrghdprhgtphhtthhopehsvghr hhgvihesshgvrhhhvghirdhioh X-ME-Proxy: Feedback-ID: i572946fc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Apr 2025 17:48:01 -0400 (EDT) From: Serhei Makarov To: elfutils-devel@sourceware.org Cc: Serhei Makarov Subject: [PATCH v5 03/12] libebl [3/12]: eu-stacktrace: use new register handling api Date: Thu, 24 Apr 2025 17:47:05 -0400 Message-ID: <20250424214715.306147-3-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.5 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: - Since __libdwfl_set_initial_registers_thread is now private to libdwfl, the modified code in this patch has been disabled. * * * Dummy commit to show how the sample_set_initial_registers callback in eu-stacktrace would use the proper libebl ebl_set_initial_registers_sample function (if it were public). * src/Makefile.am (stacktrace_LDADD): Add libebl. * src/stacktrace.c (sample_registers_cb): New function, though identical to pid_thread_state_registers_cb. (sample_set_initial_registers): (XXX Invoke ebl_set_initial_registers_sample instead of containing platform-specific code directly. This is now commented out. Patch12 in the series replaces with code in libdwfl_stacktrace/dwflst_perf_frame.c.) --- src/Makefile.am | 4 ++-- src/stacktrace.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index ed245fc1..6d713e88 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 1996-2014, 2016, 2024 Red Hat, Inc. +## Copyright (C) 1996-2014, 2016, 2024-2025 Red Hat, Inc. ## This file is part of elfutils. ## ## This file is free software; you can redistribute it and/or modify @@ -105,7 +105,7 @@ ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS) unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib) if ENABLE_STACKTRACE -stacktrace_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD) +stacktrace_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) endif elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) elfclassify_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD) diff --git a/src/stacktrace.c b/src/stacktrace.c index d8699ce5..3f5950fb 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -1,5 +1,5 @@ /* Process a stream of stack samples into stack traces. - Copyright (C) 2023-2024 Red Hat, Inc. + Copyright (C) 2023-2025 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -93,9 +93,11 @@ * Includes: libdwfl data structures * *************************************/ +#include ELFUTILS_HEADER(ebl) /* #include ELFUTILS_HEADER(dwfl) */ #include "../libdwfl/libdwflP.h" -/* XXX: Private header needed for find_procfile, sysprof_init_dwfl */ +/* XXX: Private header needed for find_procfile, sysprof_init_dwfl, + sample_set_initial_registers. */ /************************************* * Includes: sysprof data structures * @@ -574,10 +576,31 @@ sample_memory_read (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result, void *arg) return true; } -/* TODO: Need to generalize this code beyond x86 architectures. */ static bool -sample_set_initial_registers (Dwfl_Thread *thread, void *thread_arg) +sample_set_initial_registers (Dwfl_Thread *thread, void *arg) { +#if 0 + /* TODO: __libdwfl_set_initial_registers_thread not exported from libdwfl, + after it was decided to be unsuitable for a public API. + + A subsequent patch in the series removes sample_set_initial_registers, + replacing it with code in libdwfl_stacktrace/dwflst_perf_frame.c. + Keeping this code commented-out for the record, cf how we would + implement if the set_initial_registers utility func was public. + + To *actually* make this work, would need to copy the set_initial_registers + implementation into stacktrace.c; not worth doing since the later patch + overrides this code. */ + struct __sample_arg *sample_arg = (struct __sample_arg *)arg; + dwfl_thread_state_register_pc (thread, sample_arg->pc); + Dwfl_Process *process = thread->process; + Ebl *ebl = process->ebl; + /* XXX Sysprof provides exactly the required registers for unwinding: */ + uint64_t regs_mask = ebl_perf_frame_regs_mask (ebl); + return ebl_set_initial_registers_sample + (ebl, sample_arg->regs, sample_arg->n_regs, regs_mask, sample_arg->abi, + __libdwfl_set_initial_registers_thread, thread); +#else /* The following facts are needed to translate x86 registers correctly: - perf register order seen in linux arch/x86/include/uapi/asm/perf_regs.h The registers array is built in the same order as the enum! @@ -592,7 +615,7 @@ sample_set_initial_registers (Dwfl_Thread *thread, void *thread_arg) For comparison, you can study codereview.qt-project.org/gitweb?p=qt-creator/perfparser.git;a=blob;f=app/perfregisterinfo.cpp;hb=HEAD and follow the code which uses those tables of magic numbers. But it's better to follow original sources of truth for this. */ - struct __sample_arg *sample_arg = (struct __sample_arg *)thread_arg; + struct __sample_arg *sample_arg = (struct __sample_arg *)arg; bool is_abi32 = (sample_arg->abi == PERF_SAMPLE_REGS_ABI_32); static const int regs_i386[] = {0, 2, 3, 1, 7/*sp*/, 6, 4, 5, 8/*ip*/}; static const int regs_x86_64[] = {0, 3, 2, 1, 4, 5, 6, 7/*sp*/, 9, 10, 11, 12, 13, 14, 15, 16, 8/*ip*/}; @@ -610,6 +633,7 @@ sample_set_initial_registers (Dwfl_Thread *thread, void *thread_arg) dwfl_thread_state_registers (thread, i, 1, &sample_arg->regs[j]); } return true; +#endif } static void