Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1476334rdf; Sun, 5 Nov 2023 01:36:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9VL2tDXa+rsUEjlIgy2SilFHwefjApxoMwYuruEK7v/1OZF91WsqzwOzIt6uBJmuDJ5UG X-Received: by 2002:a17:90b:3b41:b0:27d:433e:e69c with SMTP id ot1-20020a17090b3b4100b0027d433ee69cmr10798226pjb.18.1699173414952; Sun, 05 Nov 2023 01:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699173414; cv=none; d=google.com; s=arc-20160816; b=s9TJIWhy+Y/Y3oZ+hFZ/3eX0VdDddQbIP50LiE0nCZKETJUbRlsv+/ORDyrozjUexs /5Bvi9FAh3PQHy8uQTXTOdDXiHCrjUzpFGP0sdS7amqWFR60EYBRUVzeT8kckEgCUHEV /Wh4beo9z7oUzbh8yvjtRR9mCq/ddc8FARgB8xIQUGQg0AZLNkdvUDWWrOL3nfnov0fS OvIO2G/yTcSR4iqe4PT7r99HGamVGCjp1cIy8P/ruEQhwhZxHtfhhl5XAJtBBpy7d1RF xLihe2uBn8qV4xrO+f+siWitSz6O7T3Tfpj5VN1q9uunF1gacXABmVTHun0OEXgiD0kC +Rzg== 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=yZXMwsaAsUjt/7UpwS1UBqI+tWgab0d3U9X8D56rUtQ=; fh=isJd0JZVDkfXL73EXh8XKFxOIWM94S6/sYnFcQuWgSQ=; b=OECaKVmsNhNY1eZBaW0MpFWJ4d3nkguUCuixXPI8VFif9ppx76SCu8dpS27Tahdo1C 24cuQ+oUdrDm8NiCD0OtHKxCgb9JfOJmDeJKplnrqEbBtxpsAp3lL0eEJi0e8Gs8G94D 7pKU3bXCWuzHUCDgisC+0RlMi5LJQ9XpWgMCtV1m/vD94e8JD8iAuAAMiScHOHKK0ciw /lafqo1b6w/sFgZQf8KrCsucAVB+djQ4yRCFBPmv18jLfB7KrCTQdtCEwpvXv45jzMlO CLAecr3KbyeCLAwdtYHoq79qFuvOzis11qgWbZqw7n3wdJKXDV50STcWw1j7AaWW7TEn E2sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lgdbL1ug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t10-20020a17090aae0a00b0027b15e572c2si5600637pjq.21.2023.11.05.01.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 01:36:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lgdbL1ug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id B25F98095671; Sun, 5 Nov 2023 01:36:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjKEIg3 (ORCPT + 99 others); Sun, 5 Nov 2023 03:36:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjKEIg1 (ORCPT ); Sun, 5 Nov 2023 03:36:27 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BAC1DB; Sun, 5 Nov 2023 01:36:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6161C433C7; Sun, 5 Nov 2023 08:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699173384; bh=cq1uyWY//yo7TAcMVEgPAIfwQ/7UUGgpAXQ4/ztZPIs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lgdbL1ughmbn5SdYS5NIgJkGd+qRDZYZOzn5e9qsvTMSftldjyJfIbdv7XZSfB1sP hOazaIlNu3WlZho88+1iQRAbdZaATP66mIlHR8fGOdVPho9yyq+teZCAvJQOju4bmD h06LFkWCYRAJHzr4EGBaYfoPKs4NMzpGgZ6LahhFjLup4TPfkjbL1Bf1t4ooKdXhzL budJSW4Q4gqzydby7ppFXZGRbFTiQ0peo4w6Zwo0HAWtjjU5oYlcFbpPsaLqtsQefC XrC8TCmAe8x5lUitirZZ7cDk145QcshXEfvm0XZbOSc5o08UvdjSBcbuL/uQvrgwCf CNKoNfupxJRHw== Date: Sun, 5 Nov 2023 17:36:18 +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 09/48] perf dwarf-regs: Add get_dwarf_regnum() Message-Id: <20231105173618.c3e5d9faef347f27a6c4f049@kernel.org> In-Reply-To: <20231012035111.676789-10-namhyung@kernel.org> References: <20231012035111.676789-1-namhyung@kernel.org> <20231012035111.676789-10-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=-4.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 01:36:49 -0700 (PDT) On Wed, 11 Oct 2023 20:50:32 -0700 Namhyung Kim wrote: > The get_dwarf_regnum() returns a DWARF register number from a register > name string according to the psABI. Also add two pseudo encodings of > DWARF_REG_PC which is a register that are used by PC-relative addressing > and DWARF_REG_FB which is a frame base register. They need to be > handled in a special way. > I have some comments below. > Cc: Masami Hiramatsu > Signed-off-by: Namhyung Kim > --- > tools/perf/arch/x86/util/dwarf-regs.c | 38 +++++++++++++++++++++++++++ > tools/perf/util/dwarf-regs.c | 33 +++++++++++++++++++++++ > tools/perf/util/include/dwarf-regs.h | 11 ++++++++ > 3 files changed, 82 insertions(+) > > diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c > index 530934805710..79835b897cae 100644 > --- a/tools/perf/arch/x86/util/dwarf-regs.c > +++ b/tools/perf/arch/x86/util/dwarf-regs.c > @@ -113,3 +113,41 @@ int regs_query_register_offset(const char *name) > return roff->offset; > return -EINVAL; > } > + > +struct dwarf_regs_idx { > + const char *name; > + int idx; > +}; > + > +static const struct dwarf_regs_idx x86_regidx_table[] = { > + { "rax", 0 }, { "eax", 0 }, { "ax", 0 }, { "al", 0 }, > + { "rdx", 1 }, { "edx", 1 }, { "dx", 1 }, { "dl", 1 }, > + { "rcx", 2 }, { "ecx", 2 }, { "cx", 2 }, { "cl", 2 }, > + { "rbx", 3 }, { "edx", 3 }, { "bx", 3 }, { "bl", 3 }, > + { "rsi", 4 }, { "esi", 4 }, { "si", 4 }, { "sil", 4 }, > + { "rdi", 5 }, { "edi", 5 }, { "di", 5 }, { "dil", 5 }, > + { "rbp", 6 }, { "ebp", 6 }, { "bp", 6 }, { "bpl", 6 }, > + { "rsp", 7 }, { "esp", 7 }, { "sp", 7 }, { "spl", 7 }, > + { "r8", 8 }, { "r8d", 8 }, { "r8w", 8 }, { "r8b", 8 }, > + { "r9", 9 }, { "r9d", 9 }, { "r9w", 9 }, { "r9b", 9 }, > + { "r10", 10 }, { "r10d", 10 }, { "r10w", 10 }, { "r10b", 10 }, > + { "r11", 11 }, { "r11d", 11 }, { "r11w", 11 }, { "r11b", 11 }, > + { "r12", 12 }, { "r12d", 12 }, { "r12w", 12 }, { "r12b", 12 }, > + { "r13", 13 }, { "r13d", 13 }, { "r13w", 13 }, { "r13b", 13 }, > + { "r14", 14 }, { "r14d", 14 }, { "r14w", 14 }, { "r14b", 14 }, > + { "r15", 15 }, { "r15d", 15 }, { "r15w", 15 }, { "r15b", 15 }, > + { "rip", DWARF_REG_PC }, > +}; > + > +int get_arch_regnum(const char *name) > +{ > + unsigned int i; > + > + if (*name != '%') > + return -1; Isn't it better to return an error code? e.g. -EINVAL. > + > + for (i = 0; i < ARRAY_SIZE(x86_regidx_table); i++) > + if (!strcmp(x86_regidx_table[i].name, name + 1)) > + return x86_regidx_table[i].idx; > + return -1; And -ENOENT. > +} > diff --git a/tools/perf/util/dwarf-regs.c b/tools/perf/util/dwarf-regs.c > index 69cfaa5953bf..28d786c7df55 100644 > --- a/tools/perf/util/dwarf-regs.c > +++ b/tools/perf/util/dwarf-regs.c > @@ -5,6 +5,8 @@ > * Written by: Masami Hiramatsu > */ > > +#include > +#include > #include > #include > #include > @@ -68,3 +70,34 @@ const char *get_dwarf_regstr(unsigned int n, unsigned int machine) > } > return NULL; > } > + > +__weak int get_arch_regnum(const char *name __maybe_unused) > +{ > + return -1; And -EOPNOTSUPP. > +} > + > +/* Return DWARF register number from architecture register name */ > +int get_dwarf_regnum(const char *name, unsigned int machine) > +{ > + char *regname = strdup(name); > + int reg = -1; > + char *p; > + > + if (regname == NULL) > + return -1; Here, -EINVAL. > + > + /* For convenience, remove trailing characters */ > + p = strpbrk(regname, " ,)"); > + if (p) > + *p = '\0'; > + > + switch (machine) { > + case EM_NONE: /* Generic arch - use host arch */ > + reg = get_arch_regnum(regname); > + break; > + default: > + pr_err("ELF MACHINE %x is not supported.\n", machine); > + } > + free(regname); > + return reg; > +} > diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h > index 7d99a084e82d..b515f694f55e 100644 > --- a/tools/perf/util/include/dwarf-regs.h > +++ b/tools/perf/util/include/dwarf-regs.h > @@ -2,6 +2,9 @@ > #ifndef _PERF_DWARF_REGS_H_ > #define _PERF_DWARF_REGS_H_ > > +#define DWARF_REG_PC 0xd3af9c /* random number */ > +#define DWARF_REG_FB 0xd3affb /* random number */ > + Is this for other patch in the series? > #ifdef HAVE_DWARF_SUPPORT > const char *get_arch_regstr(unsigned int n); > /* > @@ -10,6 +13,14 @@ const char *get_arch_regstr(unsigned int n); > * machine: ELF machine signature (EM_*) > */ > const char *get_dwarf_regstr(unsigned int n, unsigned int machine); > + > +int get_arch_regnum(const char *name); > +/* > + * get_dwarf_regnum - Returns DWARF regnum from register name > + * name: architecture register name > + * machine: ELF machine signature (EM_*) > + */ > +int get_dwarf_regnum(const char *name, unsigned int machine); > #endif > > #ifdef HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET > -- > 2.42.0.655.g421f12c284-goog > Thank you, -- Masami Hiramatsu (Google)