Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp52390rdg; Wed, 11 Oct 2023 20:52:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1RxNf7TgJuUrqBuxTDEO/hm8yRmnMy0Ip23fdDZEsFEfIDz41+vcqlgbD+K4SmRSiZ2Z+ X-Received: by 2002:a05:6358:52c5:b0:135:85ec:a080 with SMTP id z5-20020a05635852c500b0013585eca080mr27884775rwz.32.1697082747362; Wed, 11 Oct 2023 20:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697082747; cv=none; d=google.com; s=arc-20160816; b=0EKkXWzfIiFDgYBOLZ2SyMLdmSa3sk1DyJW8wY+Tl8NG115hOUZj2ywFzIZmJfXWxd nPqSFYqwLtS+SvQlbAAuGvumq7W3nKlvpP8QsmMuVGoAmrVDdyZLkn8TNnbmDC5LkSqH dS2KiwnmBps8jZPG17Sppv9jTykLIfVMDiuRmcwDZCY3V3Ne0AvMuWpJsKdvs7Ewj764 lg2VuJzyKBebPPetGD6ZGYJzb0Ry6F52v4NT3lPgFhsWYSIxFR+GfiXIrqJt2tgustQt 6A1s/jKbTan/Vns9ILmLCFpnqCFUh2R6YrJ+GhDLGb5T6TCWtiiJq6hRsz05AgCGhgjX EgAA== 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:date:subject:cc:to:from:sender :dkim-signature; bh=oDCRLN//GDrGJp7khI5N6nKLZqiZJEAgcyWXlKtsgWI=; fh=7Id7wL2M+oCJXD4imOzx4OKioxBXSOZqypDprm7aO4E=; b=qxU6lBpfyuCb7wpGI2s28493ugebbenSVE3AMp25xhoWMGee9h+Xjl3sfoUfNa52rD Z01D0Z9btcY4XlWDQLB6ePgn5yPkGXBCjBvEVf3OmEZfgM95EEKqzui36Ba5BDd1IG1J EkNwQAy/YUczalKCkKTkSsviPXoYcvLBz0pGARqY2CiRZ2akPzbFTmlrUT1JJb+7ef4e n/CWrbvoGOAy0f+bFAO5M98Jsur/xU/BG4CsI38j37UrwUTeWBfai6soudIKHjFU5bAH W/Zi+230hSx0QSMUGY4CznuVDzc32OTnbrDAwAvZYnqCCE+lGpBhcTAA8+bnC/P/r+kl yAYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ITRuwuGQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r1-20020a63fc41000000b005859e8c7c2dsi1207435pgk.639.2023.10.11.20.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:52:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ITRuwuGQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 6D8BE817ABD2; Wed, 11 Oct 2023 20:52:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377100AbjJLDvx (ORCPT + 99 others); Wed, 11 Oct 2023 23:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376873AbjJLDvY (ORCPT ); Wed, 11 Oct 2023 23:51:24 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1569EC6; Wed, 11 Oct 2023 20:51:23 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c871a095ceso4549055ad.2; Wed, 11 Oct 2023 20:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697082682; x=1697687482; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=oDCRLN//GDrGJp7khI5N6nKLZqiZJEAgcyWXlKtsgWI=; b=ITRuwuGQsdVJsSJtABcm3Elp0k/+SOu+TjSj5C20R+F1Y1EikCShpvWvMtYIIEiDQS EaJ3djTVa9vO8UFQKZVP+M4SOSTjiJdNgN2XpUmfQ+l17jpKaws297C+8j4uCkvSqFC9 BMGFYHoRt09gyftMoELYY45ZGAkM/8kI0P7NuYprsgrr5BE8JAWKBmGvWQriDbXb6AjX Sif4ZIlcIVYBEvx+1GBRk6DxUQUP5E0T19Ki9ToSX7qm5stLrK4HICA2gblmW8yk23He 2Jxnmt8XDXxuFCNsvQMZHzucHo9bUCj3IC06iWgMQHX6BnO4tMvKhXUbB5THEsm/Qi4M fe9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697082682; x=1697687482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oDCRLN//GDrGJp7khI5N6nKLZqiZJEAgcyWXlKtsgWI=; b=CU3SXSjivXCt/rKBVsZslvhlpGq9h3lb6m1TuRnMHsfTmOQ8FQQo6Bdt0PMaQKReHP sbt32EBnkMb1B2mBZAPD1vzDVl3zbGgE1T/vPXl40H8im8CuLVsphw3R4b8MwFPLgy2f Osgi+zrlWXRpcMGEMgfL85LM1+8opG9g9yEluM5lBKqchC+kxSCifo2KRDG63kgrdUHb +NT+4gYBsG18V7KgcBvlAPlQTlJXnc6mLDbvsjVEwz/jmKGTPZZNMgYbhQRU4wRB6U0g bH4yEqNXyB/Y6A9+5y9/o40Q9KszEhG0kQy9gFfB+YxgMXTJoVj9+qkbZnkkqdjSzOj7 TmkA== X-Gm-Message-State: AOJu0YzDFVClPfRWpT8LJ1a8sgN7X9BOTqPZISzIeLJdHbVDRL37YN/1 7s4nkGX7wkEXKnwBWaTc5s8= X-Received: by 2002:a17:903:41c9:b0:1c5:f1fd:5da with SMTP id u9-20020a17090341c900b001c5f1fd05damr24713893ple.2.1697082682477; Wed, 11 Oct 2023 20:51:22 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:b1b9:d490:2f5e:be06]) by smtp.gmail.com with ESMTPSA id w8-20020a170902d70800b001bc18e579aesm711374ply.101.2023.10.11.20.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:51:22 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: 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: [PATCH 06/48] perf dwarf-aux: Add die_get_scopes() helper Date: Wed, 11 Oct 2023 20:50:29 -0700 Message-ID: <20231012035111.676789-7-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012035111.676789-1-namhyung@kernel.org> References: <20231012035111.676789-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 20:52:24 -0700 (PDT) The die_get_scopes() would return the number of enclosing DIEs for the given address and it fills an array of DIEs like dwarf_getscopes(). But it doesn't follow the abstract origin of inlined functions as we want information of the concrete instance. This is needed to check the location of parameters and local variables properly. Users can check the origin separately if needed. Cc: Masami Hiramatsu Signed-off-by: Namhyung Kim --- tools/perf/util/dwarf-aux.c | 53 +++++++++++++++++++++++++++++++++++++ tools/perf/util/dwarf-aux.h | 3 +++ 2 files changed, 56 insertions(+) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index adef2635587d..10aa32334d6f 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1425,3 +1425,56 @@ void die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die, *entrypc = postprologue_addr; } + +/* Internal parameters for __die_find_scope_cb() */ +struct find_scope_data { + /* Target instruction address */ + Dwarf_Addr pc; + /* Number of scopes found [output] */ + int nr; + /* Array of scopes found, 0 for the outermost one. [output] */ + Dwarf_Die *scopes; +}; + +static int __die_find_scope_cb(Dwarf_Die *die_mem, void *arg) +{ + struct find_scope_data *data = arg; + + if (dwarf_haspc(die_mem, data->pc)) { + Dwarf_Die *tmp; + + tmp = realloc(data->scopes, (data->nr + 1) * sizeof(*tmp)); + if (tmp == NULL) + return DIE_FIND_CB_END; + + memcpy(tmp + data->nr, die_mem, sizeof(*die_mem)); + data->scopes = tmp; + data->nr++; + return DIE_FIND_CB_CHILD; + } + return DIE_FIND_CB_SIBLING; +} + +/** + * die_get_scopes - Return a list of scopes including the address + * @cu_die: a compile unit DIE + * @pc: the address to find + * @scopes: the array of DIEs for scopes (result) + * + * This function does the same as the dwarf_getscopes() but doesn't follow + * the origins of inlined functions. It returns the number of scopes saved + * in the @scopes argument. The outer scope will be saved first (index 0) and + * the last one is the innermost scope at the @pc. + */ +int die_get_scopes(Dwarf_Die *cu_die, Dwarf_Addr pc, Dwarf_Die **scopes) +{ + struct find_scope_data data = { + .pc = pc, + }; + Dwarf_Die die_mem; + + die_find_child(cu_die, __die_find_scope_cb, &data, &die_mem); + + *scopes = data.scopes; + return data.nr; +} diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index 4f5d0211ee4f..f9d765f80fb0 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -129,6 +129,9 @@ bool die_is_optimized_target(Dwarf_Die *cu_die); void die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die, Dwarf_Addr *entrypc); +/* Get the list of including scopes */ +int die_get_scopes(Dwarf_Die *cu_die, Dwarf_Addr pc, Dwarf_Die **scopes); + #ifdef HAVE_DWARF_GETLOCATIONS_SUPPORT /* Get byte offset range of given variable DIE */ -- 2.42.0.655.g421f12c284-goog