Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2497692rdf; Mon, 6 Nov 2023 16:50:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFaqSXZGj7b0/7yT3ip3CngugBxfPbCByn8XVqOPtLmEs0zppDlxYealcRLqnr/NVTCrFp X-Received: by 2002:a17:902:db0f:b0:1cc:5aef:f2d1 with SMTP id m15-20020a170902db0f00b001cc5aeff2d1mr26546158plx.25.1699318232607; Mon, 06 Nov 2023 16:50:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699318232; cv=none; d=google.com; s=arc-20160816; b=gLLtquhQ70t1oL9S0hMRIM56913r75KgtZvZlpUcnNGHXnPazdCXWxorkkiUgPz2ff xm+u/rsg4oenPwOXfXkYs3sZi39iy00mhkOOgohxT4Kuim7RNrsBPt+K1YfjN0sQRn7i YIVh4qL0DR8+uFMGPMw9jR7L6eQsHSuIaIODwUwQvvTI6gZXa31lJf9S/06dv1EzKh+4 l10ZoTemhJRZE+buM1RChH08elksvpPxBKNEFAcUYRV74Wi/Lm+cGPHxB+HIPY77S6fd eztxmJg2kdFtBgzM3VhpK7WHej2zmyLCP06BI6r14JS3QtSKlRJQ/l40AD+alONTMly6 pe/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=KFuQS8NtKHxNkiHB/li2lGXKWwpAkDnY61X1ATe5600=; fh=isJd0JZVDkfXL73EXh8XKFxOIWM94S6/sYnFcQuWgSQ=; b=0Ik/qi9Aq14HcWR4TrfS4/R0OOk5FJIg8Upz1LTFHBhs6djVXoSC0pAiqzYvdQqP2d pzkRfgZ8WIx4e4VULQud5LIccnIae8wQmVUYP4hoGH3bmUvxvXCKnXniUZw3v+4jfLA8 S1CafIw334aD2cLtUgdBoIuSGZ9qh2eX5VoR0RHq4qxbJlRYH2sCLG7FpN5sZsi9gdAe YMI2Hey52XFV/ubySMsgjVC3azr3nW/m7nUWKHfp2WyO+k4Xd+YUi7255O/h49LBvLkP vfhh4f/ML5HsKc/WtdoLj5oCZ5dq7P5vUIQN6it6fHnaBLudqXW1oafgN/mbHF744vSQ LV5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FJP5CGJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h5-20020a170902b94500b001c736266dedsi8727039pls.189.2023.11.06.16.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 16:50:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FJP5CGJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8F47C8106787; Mon, 6 Nov 2023 16:50:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232821AbjKGAuV (ORCPT + 99 others); Mon, 6 Nov 2023 19:50:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjKGAuU (ORCPT ); Mon, 6 Nov 2023 19:50:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91C7A9C; Mon, 6 Nov 2023 16:50:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D67C1C433C7; Tue, 7 Nov 2023 00:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699318217; bh=+vq4d6CCWDzMfZDEDlYqaTwwQMt8QPiakU/bxCSgh5M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FJP5CGJbzzPFKSxm5emzr1yg3F6JIQiXqily3skMibkMoTLWrwsfsgxUiqxb76zX6 D7dPtBLeKnMAuPTs71KoBRVkDkdSTSLkK6aGcxE7n+M9+pCP6D7sGCS5/cdt/laN8d o3EzBxnSk0/wEe1nEDmz/ZqfrHOx/qoOaZB2GIGV2BG1uVqnRgLEz3F8fmQWfMctCz sSTBmqm+NpSDVjAsGtFSJ7lrHMw8Ri4+kByhvSUmzvvAQYl0TIDRJQPXBMAMDuGTro ohYYBx6NlzPcFPxVTudhfOikdGoQbGrn71btej6LK1jfx8WsBdGdCTU3nZJHQSYAH6 l5dQi54xrIa9Q== Date: Tue, 7 Nov 2023 09:50:11 +0900 From: Masami Hiramatsu (Google) To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra , Ian Rogers , Adrian Hunter , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: Re: [PATCH 31/48] perf dwarf-aux: Add die_get_cfa() Message-Id: <20231107095011.7538657bbe34f0d7171add09@kernel.org> In-Reply-To: <20231012035111.676789-32-namhyung@kernel.org> References: <20231012035111.676789-1-namhyung@kernel.org> <20231012035111.676789-32-namhyung@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 16:50:29 -0800 (PST) On Wed, 11 Oct 2023 20:50:54 -0700 Namhyung Kim wrote: > The die_get_cfa() is to get frame base register and offset at the given > instruction address (pc). This info will be used to locate stack > variables which have location expression using DW_OP_fbreg. > In the util/probe-finder.c, I added the elfutils version checker #if _ELFUTILS_PREREQ(0, 142) for CFI related code, in commit 7752f1b096e1 ("perf probe: Don't compile CFI related code if elfutils is old"). Maybe we'd better to have a config of HAVE_DWARF_CFI_SUPPORT for this. Thank you, > Signed-off-by: Namhyung Kim > --- > tools/perf/util/dwarf-aux.c | 64 +++++++++++++++++++++++++++++++++++++ > tools/perf/util/dwarf-aux.h | 9 ++++++ > 2 files changed, 73 insertions(+) > > diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c > index 97d9ae56350e..796413eb4e8f 100644 > --- a/tools/perf/util/dwarf-aux.c > +++ b/tools/perf/util/dwarf-aux.c > @@ -1408,6 +1408,70 @@ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die, Dwarf_Addr pc, > return result; > } > > +static int reg_from_dwarf_op(Dwarf_Op *op) > +{ > + switch (op->atom) { > + case DW_OP_reg0 ... DW_OP_reg31: > + return op->atom - DW_OP_reg0; > + case DW_OP_breg0 ... DW_OP_breg31: > + return op->atom - DW_OP_breg0; > + case DW_OP_regx: > + case DW_OP_bregx: > + return op->number; > + default: > + break; > + } > + return -1; > +} > + > +static int offset_from_dwarf_op(Dwarf_Op *op) > +{ > + switch (op->atom) { > + case DW_OP_reg0 ... DW_OP_reg31: > + case DW_OP_regx: > + return 0; > + case DW_OP_breg0 ... DW_OP_breg31: > + return op->number; > + case DW_OP_bregx: > + return op->number2; > + default: > + break; > + } > + return -1; > +} > + > +/** > + * die_get_cfa - Get frame base information > + * @dwarf: a Dwarf info > + * @pc: program address > + * @preg: pointer for saved register > + * @poffset: pointer for saved offset > + * > + * This function gets register and offset for CFA (Canonical Frame Address) > + * by searching the CIE/FDE info. The CFA usually points to the start address > + * of the current stack frame and local variables can be located using an offset > + * from the CFA. The @preg and @poffset will be updated if it returns 0. > + */ > +int die_get_cfa(Dwarf *dwarf, u64 pc, int *preg, int *poffset) > +{ > + Dwarf_CFI *cfi; > + Dwarf_Frame *frame = NULL; > + Dwarf_Op *ops = NULL; > + size_t nops; > + > + cfi = dwarf_getcfi(dwarf); > + if (cfi == NULL) > + return -1; > + > + if (!dwarf_cfi_addrframe(cfi, pc, &frame) && > + !dwarf_frame_cfa(frame, &ops, &nops) && nops == 1) { > + *preg = reg_from_dwarf_op(ops); > + *poffset = offset_from_dwarf_op(ops); > + return 0; > + } > + return -1; > +} > + > #endif > > /* > diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h > index 742098e3ee7e..29a7243b1a45 100644 > --- a/tools/perf/util/dwarf-aux.h > +++ b/tools/perf/util/dwarf-aux.h > @@ -149,6 +149,9 @@ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die, Dwarf_Addr pc, > Dwarf_Addr addr, Dwarf_Die *die_mem, > int *offset); > > +/* Get the frame base information from CFA */ > +int die_get_cfa(Dwarf *dwarf, u64 pc, int *preg, int *poffset); > + > #else /* HAVE_DWARF_GETLOCATIONS_SUPPORT */ > > static inline int die_get_var_range(Dwarf_Die *sp_die __maybe_unused, > @@ -175,6 +178,12 @@ static inline Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die __maybe_unu > return NULL; > } > > +static inline int die_get_cfa(Dwarf *dwarf __maybe_unused, u64 pc __maybe_unused, > + int *preg __maybe_unused, int *poffset __maybe_unused) > +{ > + return -1; > +} > + > #endif /* HAVE_DWARF_GETLOCATIONS_SUPPORT */ > > #endif /* _DWARF_AUX_H */ > -- > 2.42.0.655.g421f12c284-goog > -- Masami Hiramatsu (Google)