From patchwork Tue Dec 26 13:48:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 25104 Received: (qmail 40369 invoked by alias); 26 Dec 2017 13:49:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 39083 invoked by uid 89); 26 Dec 2017 13:49:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:ultra-s, sk:ultras X-HELO: mail-pl0-f54.google.com Received: from mail-pl0-f54.google.com (HELO mail-pl0-f54.google.com) (209.85.160.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Dec 2017 13:48:59 +0000 Received: by mail-pl0-f54.google.com with SMTP id n13so17903682plp.11 for ; Tue, 26 Dec 2017 05:48:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UJf0ZAdPHD95gAhdyRrq6827bAVWq+b+3biXWrkswuw=; b=uXvgeScAVvGTO9m0B0p+Tem8wifBCCFoFVvBjOmhN5Mwviq993R1/8LALdZJh3bfUi S7KjJc5b9RruJpOeqc6DdyH51z5UJdBWBsQUrQDo4GUjsH5d2+faLeyHmzb5bkfUsuov cZIX0dCubKNSeOKcOSe1cglCaPuxTQWpnZoOfuDLUQh2CaHpT61QVV36v11XeGIaqNRI B1TLckIHwyI5/Ek5tBrxOW0ltErP4HCkHASizIb6ZLvvLAZ4l5okKFqaFu8JD5gyXdgq Z2UxkNUWreldkB5NkFS+Qr43rci3Tqf7U30cJQ0YWLBqjO8X5EsBfK4PUaJR9yDQXqoV I1+A== X-Gm-Message-State: AKGB3mK7HBOHMLUtRzCCV6EbMZd9NrhqnKvsEgrM/VEtZfvkzqaEzePc rJPaa58L86GarxFoVV6BICsdHHqz X-Google-Smtp-Source: ACJfBosqkmddIysJ7Cy8ZX0VcjABG5cgYdw5cmoWdut0BFaa6Ps7DrthSLdb4X8DaLgX91UNI1/Tog== X-Received: by 10.84.210.66 with SMTP id z60mr25669148plh.359.1514296137280; Tue, 26 Dec 2017 05:48:57 -0800 (PST) Received: from localhost (g121.222-224-191.ppp.wakwak.ne.jp. [222.224.191.121]) by smtp.gmail.com with ESMTPSA id n22sm34416416pgd.86.2017.12.26.05.48.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Dec 2017 05:48:56 -0800 (PST) From: Stafford Horne To: GDB patches Cc: Simon Marchi , Eli Zaretskii , Stafford Horne Subject: [PATCH v4 4/4] tdesc: handle arbitrary strings in tdesc_register_in_reggroup_p Date: Tue, 26 Dec 2017 22:48:32 +0900 Message-Id: <20171226134832.23497-5-shorne@gmail.com> In-Reply-To: <20171226134832.23497-1-shorne@gmail.com> References: <20171226134832.23497-1-shorne@gmail.com> X-IsSubscribed: yes tdesc_register_in_reggroup_p in now able to handle arbitrary groups. This is useful when groups are created while the target descriptor file is received from the remote. This can be the case of a soft core target processor where registers/groups can change. gdb/ChangeLog: yyyy-mm-dd Franck Jullien Stafford Horne * target-descriptions.c (tdesc_register_in_reggroup_p): Support arbitrary strings. * NEWS (Changes since GDB 8.0): Announce that GDB supports arbitrary reggroups. gdb/testsuite/ChangeLog: yyyy-mm-dd Stafford Horne * gdb.xml/extra-regs.xml: Add example foo reggroup. * gdb.xml/tdesc-regs.exp: Add test to check for foo reggroup. gdb/doc/ChangeLog: yyyy-mm-dd Stafford Horne * gdb.texinfo (Target Description Format): Explain that arbitrary strings are now allowed for register groups. --- Changes since v3 * Removed bad paragraph from NEWS (Eli) * Reworded "internal hyphens" in gdb.texinfo (Eli) * Use == comparitor for std::string compares (Simon) * Use new reggroup_find() utility function (Simon) gdb/NEWS | 4 +++ gdb/doc/gdb.texinfo | 11 ++++--- gdb/target-descriptions.c | 58 +++++++++++++----------------------- gdb/testsuite/gdb.xml/extra-regs.xml | 1 + gdb/testsuite/gdb.xml/tdesc-regs.exp | 3 ++ 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 44f481d1f5..c861853798 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,10 @@ *** Changes since GDB 8.0 +* GDB now supports dynamically creating arbitrary register groups specified + in XML target descriptions. This allows for finer grain grouping of + registers on systems with a large amount of registers. + * The 'ptype' command now accepts a '/o' flag, which prints the offsets and sizes of fields in a struct, like the pahole(1) tool. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a16e79bc2a..f8ecf216b4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41761,10 +41761,13 @@ architecture's normal floating point format) of the correct size for @var{bitsize}. The default is @code{int}. @item group -The register group to which this register belongs. It must -be either @code{general}, @code{float}, or @code{vector}. If no -@var{group} is specified, @value{GDBN} will not display the register -in @code{info registers}. +The register group to which this register belongs. It can be one of the +standard register groups @code{general}, @code{float}, @code{vector} or an +arbitrary string. Group names should be limited to alphanumeric characters. +If a group name is made up of multiple words the words may be separated by +hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no +@var{group} is specified, @value{GDBN} will not display the register in +@code{info registers}. @end table diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 88ac55f404..349cebb51b 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -111,12 +111,11 @@ struct tdesc_reg : tdesc_element int save_restore; /* The name of the register group containing this register, or empty - if the group should be automatically determined from the - register's type. If this is "general", "float", or "vector", the - corresponding "info" command should display this register's - value. It can be an arbitrary string, but should be limited to - alphanumeric characters and internal hyphens. Currently other - strings are ignored (treated as empty). */ + if the group should be automatically determined from the register's + type. This is traditionally "general", "float", "vector" but can + also be an arbitrary string. If defined the corresponding "info" + command should display this register's value. The string should be + limited to alphanumeric characters and internal hyphens. */ std::string group; /* The size of the register, in bits. */ @@ -1279,17 +1278,13 @@ tdesc_remote_register_number (struct gdbarch *gdbarch, int regno) } /* Check whether REGNUM is a member of REGGROUP. Registers from the - target description may be classified as general, float, or vector. - Unlike a gdbarch register_reggroup_p method, this function will - return -1 if it does not know; the caller should handle registers - with no specified group. - - Arbitrary strings (other than "general", "float", and "vector") - from the description are not used; they cause the register to be - displayed in "info all-registers" but excluded from "info - registers" et al. The names of containing features are also not - used. This might be extended to display registers in some more - useful groupings. + target description may be classified as general, float, vector or other + register groups registered with reggroup_add(). Unlike a gdbarch + register_reggroup_p method, this function will return -1 if it does not + know; the caller should handle registers with no specified group. + + The names of containing features are not used. This might be extended + to display registers in some more useful groupings. The save-restore flag is also implemented here. */ @@ -1299,26 +1294,9 @@ tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, { struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno); - if (reg != NULL && !reg->group.empty ()) - { - int general_p = 0, float_p = 0, vector_p = 0; - - if (reg->group == "general") - general_p = 1; - else if (reg->group == "float") - float_p = 1; - else if (reg->group == "vector") - vector_p = 1; - - if (reggroup == float_reggroup) - return float_p; - - if (reggroup == vector_reggroup) - return vector_p; - - if (reggroup == general_reggroup) - return general_p; - } + if (reg != NULL && !reg->group.empty () + && (reg->group == reggroup_name (reggroup))) + return 1; if (reg != NULL && (reggroup == save_reggroup || reggroup == restore_reggroup)) @@ -1421,6 +1399,12 @@ tdesc_use_registers (struct gdbarch *gdbarch, void **slot = htab_find_slot (reg_hash, reg.get (), INSERT); *slot = reg.get (); + /* Add reggroup if its new. */ + if (!reg->group.empty ()) + if (reggroup_find (gdbarch, reg->group.c_str ()) == NULL) + reggroup_add (gdbarch, reggroup_gdbarch_new (gdbarch, + reg->group.c_str (), + USER_REGGROUP)); } /* Remove any registers which were assigned numbers by the diff --git a/gdb/testsuite/gdb.xml/extra-regs.xml b/gdb/testsuite/gdb.xml/extra-regs.xml index 997d6598e5..302e64ce7d 100644 --- a/gdb/testsuite/gdb.xml/extra-regs.xml +++ b/gdb/testsuite/gdb.xml/extra-regs.xml @@ -53,5 +53,6 @@ + diff --git a/gdb/testsuite/gdb.xml/tdesc-regs.exp b/gdb/testsuite/gdb.xml/tdesc-regs.exp index d62ed9841b..e8b7fd506b 100644 --- a/gdb/testsuite/gdb.xml/tdesc-regs.exp +++ b/gdb/testsuite/gdb.xml/tdesc-regs.exp @@ -190,6 +190,9 @@ gdb_test "ptype \$flags" \ "type = flag flags {\r\n *bool X @0;\r\n *uint32_t Y @2;\r\n}" gdb_test "ptype \$mixed_flags" \ "type = flag mixed_flags {\r\n *bool A @0;\r\n *uint32_t B @1-3;\r\n *bool C @4;\r\n *uint32_t D @5;\r\n *uint32_t @6-7;\r\n *enum {yes = 1, no = 0, maybe = 2, so} Z @8-9;\r\n}" +# Reggroups should have at least general and the extra foo group +gdb_test "maintenance print reggroups" \ + " Group\[ \t\]+Type\[ \t\]+\r\n.* general\[ \t\]+user\[ \t\]+\r\n.* foo\[ \t\]+user\[ \t\]+" load_description "core-only.xml" "" "test-regs.xml" # The extra register from the previous description should be gone.