Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1894191rdf; Sun, 5 Nov 2023 20:01:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnvvN1nOkxhGOsNnNxe7TadUDiU+fbesh0edRsPF9lxF+qeYRUTIQG77l7O5Tpn9B5I/DY X-Received: by 2002:a17:90a:bb14:b0:280:8e7d:5701 with SMTP id u20-20020a17090abb1400b002808e7d5701mr12847981pjr.2.1699243299784; Sun, 05 Nov 2023 20:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699243299; cv=none; d=google.com; s=arc-20160816; b=lkXVhHVOu8Tkw5DHNrMrB9rG4hBc5j/vZMeaa8kX22pYCYwt8rkB6dy3JB8of1N2O/ +Co7fthAT7dpgWRJIJQ72fSPDw6wH3GoGYd3zeDBufSCEkDqGkScLOsSDoKM3KU8sY8+ VLIwzI2rGLbMJJDGNYJnaOCS63iSTYHnR/COofey7TNieJmmbyrxb/PPb3DNS3G1hnn9 MHyOqbMx5YDvvjTXYKrEWfdwadimeI/UCsZ7d7MfRHatlcw5sC53ulhHc9blU3kRN65e KM3yBDAOtSJ8szk9+OlBrcNurx+IEoDW+XbPmv3NPHO3D+asKv/WuRIHbOY9ny7mnaNC RZCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=GMr+iqVuNUMWXan86XmtUlqzrYbI5OhvVk5UudNTaxg=; fh=5N5Nme/D0uOoH6taT9UZl/OeVzWLH99kl+aFITyNPME=; b=i6Tyj30eWvxpaI8R961bsfKjuOEQSgCY1juDzgzhTmKNGaP6xFqw6nCpycFDts0EIr w3uV9gnhWIR7w6D8hcwaM4eBAqo6DsAT7i31e/lLiyfEvdLIQVA7YVjnDmul/lV/YU0c Cu1+9EuNg/oOoF7n9xxUHoEPB4ezkWxcKmB1Zp6GBB9V+zcTM/FOuZzl8XKQNPxZAOxN GP2m+nkzI18t2mVjBDni9F0zV16GlMzl1iviueAlNRSQGIvgQpP+Zqehlqgp6JsK4IuD KvutZI5SdESV85FewzzVsc60hUHzWez0S7051l2o6pMmt3zIDZr8UcopK6CFqjH+wMBt JDAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l1-20020a656801000000b005b82de74216si6910482pgt.901.2023.11.05.20.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 20:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id EC043806B707; Sun, 5 Nov 2023 20:01:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbjKFEB2 convert rfc822-to-8bit (ORCPT + 99 others); Sun, 5 Nov 2023 23:01:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjKFEB0 (ORCPT ); Sun, 5 Nov 2023 23:01:26 -0500 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36A4F2; Sun, 5 Nov 2023 20:01:23 -0800 (PST) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5b9390d6bd3so3987426a12.0; Sun, 05 Nov 2023 20:01:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699243283; x=1699848083; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xq2PaTTm8ScGQcrNNQNUmc8/MIWUPOH3hzTm7x5JKOQ=; b=ZqIpafNkphcCtZJk6Nh4nHOnHiaLsjCixaQEt+YGDB1+NGPfg2R+Ke2ozVrSp5FrPB hSN+u2vvedBsHlGp+Noq9opHcmuelFts7n6TUH1L+SWGgONxu9aPnLDco8WEuruue3gi y8Rov/AXkJ4B6SBIVrXJsPKoexqkj1Fu2IrY+HSt2HHtpmt+SF8AvnMA7gxGxOlQMrGM tTNIcAoLNehA4dBa78H5gPBLR1FkX+gOwHx72Mxu2/UnElzegmzbo1r3pdRXH7xk1nt2 g/nsmHwtlni+ZvkOsNRnHsBy3SnpznSjJDErOctZqXGsWLBRvi0RK1Tmgw6QnB9dTG0x jefw== X-Gm-Message-State: AOJu0Yyqu1l6+0He4eamhC71awzhkAeh0mpKOelK9F1T2YYQ9rZjIE+8 z9Cg7YTs9JSl8YV9+JWiZdPaI1+a5hGCCpw687I= X-Received: by 2002:a17:90b:3ec9:b0:27d:1369:515e with SMTP id rm9-20020a17090b3ec900b0027d1369515emr13333388pjb.22.1699243283129; Sun, 05 Nov 2023 20:01:23 -0800 (PST) MIME-Version: 1.0 References: <20231012035111.676789-1-namhyung@kernel.org> <20231012035111.676789-9-namhyung@kernel.org> <20231105180732.f3483276b09360267e6d6fbb@kernel.org> In-Reply-To: <20231105180732.f3483276b09360267e6d6fbb@kernel.org> From: Namhyung Kim Date: Sun, 5 Nov 2023 20:01:12 -0800 Message-ID: Subject: Re: [PATCH 08/48] perf dwarf-aux: Factor out __die_get_typename() To: Masami Hiramatsu 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 , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sun, 05 Nov 2023 20:01:37 -0800 (PST) Hi Masami, On Sun, Nov 5, 2023 at 1:07 AM Masami Hiramatsu wrote: > > On Wed, 11 Oct 2023 20:50:31 -0700 > Namhyung Kim wrote: > > > The __die_get_typename() is to get the name of the given DIE in C-style > > type name. The difference from the die_get_typename() is that it does > > not retrieve the DW_AT_type and use the given DIE directly. This will > > be used when users know the type DIE already. > > Hmm, I would rather like to have another name for this function. > What about 'die_get_typename_from_type()' ? Ok. > > > > Cc: Masami Hiramatsu > > Signed-off-by: Namhyung Kim > > --- > > tools/perf/util/dwarf-aux.c | 38 ++++++++++++++++++++++++++----------- > > tools/perf/util/dwarf-aux.h | 3 +++ > > 2 files changed, 30 insertions(+), 11 deletions(-) > > > > diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c > > index 652e6e7368a2..5bb05c84d249 100644 > > --- a/tools/perf/util/dwarf-aux.c > > +++ b/tools/perf/util/dwarf-aux.c > > @@ -1051,32 +1051,28 @@ Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, > > } > > > > /** > > - * die_get_typename - Get the name of given variable DIE > > - * @vr_die: a variable DIE > > + * __die_get_typename - Get the name of given type DIE > > + * @type: a type DIE > > * @buf: a strbuf for result type name > > * > > - * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded. > > + * Get the name of @type_die and stores it to @buf. Return 0 if succeeded. > > * and Return -ENOENT if failed to find type name. > > * Note that the result will stores typedef name if possible, and stores > > * "*(function_type)" if the type is a function pointer. > > */ > > -int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf) > > +int __die_get_typename(Dwarf_Die *type, struct strbuf *buf) > > Could you use 'type_die' instead of 'type' if it is exposed? Will change, thanks for your review! Namhyung > > { > > - Dwarf_Die type; > > int tag, ret; > > const char *tmp = ""; > > > > - if (__die_get_real_type(vr_die, &type) == NULL) > > - return -ENOENT; > > - > > - tag = dwarf_tag(&type); > > + tag = dwarf_tag(type); > > if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type) > > tmp = "*"; > > else if (tag == DW_TAG_subroutine_type) { > > /* Function pointer */ > > return strbuf_add(buf, "(function_type)", 15); > > } else { > > - const char *name = dwarf_diename(&type); > > + const char *name = dwarf_diename(type); > > > > if (tag == DW_TAG_union_type) > > tmp = "union "; > > @@ -1089,7 +1085,7 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf) > > /* Write a base name */ > > return strbuf_addf(buf, "%s%s", tmp, name ?: ""); > > } > > - ret = die_get_typename(&type, buf); > > + ret = die_get_typename(type, buf); > > if (ret < 0) { > > /* void pointer has no type attribute */ > > if (tag == DW_TAG_pointer_type && ret == -ENOENT) > > @@ -1100,6 +1096,26 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf) > > return strbuf_addstr(buf, tmp); > > } > > > > +/** > > + * die_get_typename - Get the name of given variable DIE > > + * @vr_die: a variable DIE > > + * @buf: a strbuf for result type name > > + * > > + * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded. > > + * and Return -ENOENT if failed to find type name. > > + * Note that the result will stores typedef name if possible, and stores > > + * "*(function_type)" if the type is a function pointer. > > + */ > > +int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf) > > +{ > > + Dwarf_Die type; > > + > > + if (__die_get_real_type(vr_die, &type) == NULL) > > + return -ENOENT; > > + > > + return __die_get_typename(&type, buf); > > +} > > + > > /** > > * die_get_varname - Get the name and type of given variable DIE > > * @vr_die: a variable DIE > > diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h > > index b6f430730bd1..574405c57d3b 100644 > > --- a/tools/perf/util/dwarf-aux.h > > +++ b/tools/perf/util/dwarf-aux.h > > @@ -116,6 +116,9 @@ Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, > > Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, > > Dwarf_Die *die_mem); > > > > +/* Get the name of given type DIE */ > > +int __die_get_typename(Dwarf_Die *type, struct strbuf *buf); > > + > > /* Get the name of given variable DIE */ > > int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf); > > > > -- > > 2.42.0.655.g421f12c284-goog > > > > > -- > Masami Hiramatsu (Google)