From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E990B3858C2D for ; Thu, 1 Sep 2022 21:31:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E990B3858C2D Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-388-coB72NY9PIGct-sG3HHoyA-1; Thu, 01 Sep 2022 17:31:29 -0400 X-MC-Unique: coB72NY9PIGct-sG3HHoyA-1 Received: by mail-wm1-f72.google.com with SMTP id c66-20020a1c3545000000b003a5f6dd6a25so1856126wma.1 for ; Thu, 01 Sep 2022 14:31:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=b6cRQbR1xiLpK16r30gt6iDYOxy13wyQd4GvI+C0+Io=; b=fqsHFjHPtvZwuDTuvf9UWoZhANmVsiJAL64Y2ptsj27qEr9CatbWnaxS7A7b2wcAf+ pETS3AxoxTJ7TONq/GOLFaXtssYY1DE+1LcFp8Vox33yIPkLIoCpQjUU4ZoutUbHdpxe VBFPI2Z9jlM5t7u2deM1SUh4kw78gzTy/Ti9omXPEL33jvRHLRWvmJX/L7jT7MH4pmfx lhCsOJ4shWAiotuKpjCJstXCnKIS+vNAs7UxV2U9NMUdUUkUxz2GIGO4aWA4t8Q+b1mU MdbqFR3ylaJn6rW8tjKLlf51oRkuOWp14RWa5oOpvosoDsYECmzCdc/oxbhYkRCyucuR 3Tpw== X-Gm-Message-State: ACgBeo3dy/MbMG2Txc5wOxs8CVD8bJN2M3CQABefj2Jg7cMMJVw88rLh S2LjQECMpPwv3KNlpP1KnBH4S4qJyF5tFmuBlpNKtRzMs4r7J8L+Ise4qZOW9Kr+hLIzTXXJGwm 1/baIu7jv9/PEXVJT1Lg2cg1mQsZ0ZxBcVaHi4YVT32Jwbx8bpfk/I++OZIUn2GqGdf4Csk/nLw == X-Received: by 2002:adf:e4d1:0:b0:226:e84d:286c with SMTP id v17-20020adfe4d1000000b00226e84d286cmr6607088wrm.300.1662067887877; Thu, 01 Sep 2022 14:31:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR6DWnSSy5BsnQz4vtEzM9gHQueKketaXYt+VBpawytePt837Y63lKLLePx9hSTPQQhq3EkzZw== X-Received: by 2002:adf:e4d1:0:b0:226:e84d:286c with SMTP id v17-20020adfe4d1000000b00226e84d286cmr6607077wrm.300.1662067887547; Thu, 01 Sep 2022 14:31:27 -0700 (PDT) Received: from localhost ([31.111.84.229]) by smtp.gmail.com with ESMTPSA id az26-20020adfe19a000000b0022529d3e911sm16311428wrb.109.2022.09.01.14.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 14:31:27 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 5/9] gdb: check for duplicate register names in selftest Date: Thu, 1 Sep 2022 22:31:13 +0100 Message-Id: <7c3f810e976d03e516956492a16a8ae2948e3023.1662067442.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, 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 server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2022 21:31:36 -0000 Building on the previous commit, this commit extends the register_name selftest to check for duplicate register names. If two registers in the cooked register set (real + pseudo registers) have the same name, then this will show up as duplicate registers in the 'info all-registers' output, but the user will only be able to interact with one copy of the register. In this commit I extend the selftest that I added in the previous commit to check for duplicate register names, I didn't include this functionality in the previous commit because one architecture needed fixing, and I wanted to keep those fixes separate from the fixes in the previous commit. The problematic architecture(s) are powerpc:750 and powerpc:604. In both of these cases the 'dabr' register appears twice, there's a definition of dabr in power-oea.xml which is included into both powerpc-604.xml and powerpc-750.xml. Both of these later two xml files also define the dabr register. I'm hopeful that this change shouldn't break anything, but I don't have the ability to actually test this change, however: On the gdbserver side, neither powerpc-604.xml nor powerpc-750.xml are mentioned in gdbserver/configure.srv, which I think means that gdbserver will never use these descriptions, and, Within GDB the problematic descriptions are held in the variables tdesc_powerpc_604 and tdesc_powerpc_750, which are only mentioned in the variants array in rs6000-tdep.c, this is used when looking up a description based on the architecture. For a native Linux target however, this will not be used as ppc_linux_nat_target::read_description exists, which calls ppc_linux_match_description, which I don't believe can return either of the problematic descriptions. This leaves the other native targets, FreeBSD, AIX, etc. These don't appear to override the ::read_description method, so will potentially return the problematic descriptions, but, in each case I think the ::fetch_registers and ::store_registers methods will ignore the dabr register, which will leave the register as . So, my proposed solution is to just remove the duplicate register from each of powerpc-604.xml and powerpc-750.xml, then regenerate the corresponding C++ source file. With this change made, the selftest now passes for all architectures. --- gdb/features/rs6000/powerpc-604.c | 13 ++++++------- gdb/features/rs6000/powerpc-604.xml | 1 - gdb/features/rs6000/powerpc-750.c | 1 - gdb/features/rs6000/powerpc-750.xml | 1 - gdb/gdbarch-selftests.c | 21 ++++++++++++++++++++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/gdb/features/rs6000/powerpc-604.c b/gdb/features/rs6000/powerpc-604.c index fe0fe2fc7e4..474b29fed55 100644 --- a/gdb/features/rs6000/powerpc-604.c +++ b/gdb/features/rs6000/powerpc-604.c @@ -141,13 +141,12 @@ initialize_tdesc_powerpc_604 (void) tdesc_create_reg (feature, "hid0", 119, 1, NULL, 32, "int"); tdesc_create_reg (feature, "hid1", 120, 1, NULL, 32, "int"); tdesc_create_reg (feature, "iabr", 121, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "dabr", 122, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "pir", 123, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "mmcr0", 124, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "pmc1", 125, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "pmc2", 126, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "sia", 127, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "sda", 128, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "pir", 122, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "mmcr0", 123, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "pmc1", 124, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "pmc2", 125, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "sia", 126, 1, NULL, 32, "int"); + tdesc_create_reg (feature, "sda", 127, 1, NULL, 32, "int"); tdesc_powerpc_604 = result.release (); } diff --git a/gdb/features/rs6000/powerpc-604.xml b/gdb/features/rs6000/powerpc-604.xml index fbc9e946d22..052cfbb7e76 100644 --- a/gdb/features/rs6000/powerpc-604.xml +++ b/gdb/features/rs6000/powerpc-604.xml @@ -17,7 +17,6 @@ - diff --git a/gdb/features/rs6000/powerpc-750.c b/gdb/features/rs6000/powerpc-750.c index 396ec456651..3533c42d6cb 100644 --- a/gdb/features/rs6000/powerpc-750.c +++ b/gdb/features/rs6000/powerpc-750.c @@ -141,7 +141,6 @@ initialize_tdesc_powerpc_750 (void) tdesc_create_reg (feature, "hid0", 119, 1, NULL, 32, "int"); tdesc_create_reg (feature, "hid1", 120, 1, NULL, 32, "int"); tdesc_create_reg (feature, "iabr", 121, 1, NULL, 32, "int"); - tdesc_create_reg (feature, "dabr", 122, 1, NULL, 32, "int"); tdesc_create_reg (feature, "ummcr0", 124, 1, NULL, 32, "int"); tdesc_create_reg (feature, "upmc1", 125, 1, NULL, 32, "int"); tdesc_create_reg (feature, "upmc2", 126, 1, NULL, 32, "int"); diff --git a/gdb/features/rs6000/powerpc-750.xml b/gdb/features/rs6000/powerpc-750.xml index 908ecbdfd96..dfc5a87aaa0 100644 --- a/gdb/features/rs6000/powerpc-750.xml +++ b/gdb/features/rs6000/powerpc-750.xml @@ -17,7 +17,6 @@ - diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c index 75a3109143f..9bb00c93ff0 100644 --- a/gdb/gdbarch-selftests.c +++ b/gdb/gdbarch-selftests.c @@ -27,6 +27,8 @@ #include "gdbarch.h" #include "scoped-mock-context.h" +#include + namespace selftests { /* Test gdbarch methods register_to_value and value_to_register. */ @@ -129,6 +131,9 @@ register_name_test (struct gdbarch *gdbarch) { scoped_mock_context mockctx (gdbarch); + /* Track the number of times each register name appears. */ + std::map name_counts; + const int num_regs = gdbarch_num_cooked_regs (gdbarch); for (auto regnum = 0; regnum < num_regs; regnum++) { @@ -141,8 +146,22 @@ register_name_test (struct gdbarch *gdbarch) debug_printf ("arch: %s, register: %d returned nullptr\n", gdbarch_bfd_arch_info (gdbarch)->printable_name, regnum); - SELF_CHECK (name != nullptr); + + /* Every register name, that is not the empty string, should be + unique. If this is not the case then the user will see duplicate + copies of the register in e.g. 'info registers' output, but will + only be able to interact with one of the copies. */ + if (*name != '\0') + { + std::string s (name); + name_counts[s]++; + if (run_verbose() && name_counts[s] > 1) + debug_printf ("arch: %s, register: %d (%s) is a duplicate\n", + gdbarch_bfd_arch_info (gdbarch)->printable_name, + regnum, name); + SELF_CHECK (name_counts[s] == 1); + } } } -- 2.25.4