From patchwork Wed Jun 7 22:15:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 20838 Received: (qmail 6689 invoked by alias); 7 Jun 2017 22:16:00 -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 6617 invoked by uid 89); 7 Jun 2017 22:15:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, 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=grain, Hx-spam-relays-external:74.125.83.68, H*RU:74.125.83.68 X-HELO: mail-pg0-f68.google.com Received: from mail-pg0-f68.google.com (HELO mail-pg0-f68.google.com) (74.125.83.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Jun 2017 22:15:55 +0000 Received: by mail-pg0-f68.google.com with SMTP id a70so2567089pge.0 for ; Wed, 07 Jun 2017 15:16:00 -0700 (PDT) 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:in-reply-to:references; bh=T22d5R2cVfDH48ANn25r5tGGHSif3ErPo5jQAU7SZlY=; b=TVKNOppUgE5BBN+skfoqragQkioxxu4rOKYC6hbrs8LJ+BZmkddZezXX1gG/Md+IE1 MG7uD21rsIpga7LWZOTQCcL4XUDLFZjMPF0wgvJ9j75kbuMca5rtORzf+GUzzaK4jwdq YsdZX1N1V+YRjuVa+JWC465jsgEkmArRVdd5iqkp/EuEV79hB/DN7piNIlP+mQpHD89Z lAX70e24t0i8ozXD3b/eQI5qGhGbSD2jft5c1bPAoQLnDCQ8E41cJ/UAcjLpV2eMn6yx tQLi2DRsO+3LNff1kralzLIukLqiImFwmfwWASj0q3auSVM/OD9PqKAEHZ7KLANDgcAf DotQ== X-Gm-Message-State: AODbwcDELh1fYU4Q1zst7I8fZbXrLyvP5dfczdGcckz2NxtLQmHm0p9Q KlPIGNEXMBTHpgBwxpk= X-Received: by 10.99.95.193 with SMTP id t184mr33861375pgb.127.1496873758392; Wed, 07 Jun 2017 15:15:58 -0700 (PDT) Received: from localhost (g212.61-193-241.ppp.wakwak.ne.jp. [61.193.241.212]) by smtp.gmail.com with ESMTPSA id w24sm6532573pfa.79.2017.06.07.15.15.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Jun 2017 15:15:57 -0700 (PDT) From: Stafford Horne To: GDB patches Cc: Stafford Horne Subject: [PATCH 3/3] tdesc: handle arbitrary strings in tdesc_register_in_reggroup_p Date: Thu, 8 Jun 2017 07:15:47 +0900 Message-Id: <0c4f5b59a645a64535e7c8bb0f34b03df805f4e4.1496871270.git.shorne@gmail.com> In-Reply-To: References: In-Reply-To: References: 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: 2017-06-06 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: 2017-06-06 Stafford Horne * gdb.xml/extra-regs.xml: Add example foo reggroup. * gdb.xml/tdesc-regs.exp: Add test to check for foo reggroup. --- gdb/NEWS | 4 ++ gdb/target-descriptions.c | 73 ++++++++++++++++++------------------ gdb/testsuite/gdb.xml/extra-regs.xml | 1 + gdb/testsuite/gdb.xml/tdesc-regs.exp | 3 ++ 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 112aa2f..0b18552 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 descriptors. This allows for finer grain grouping of + registers on systems with a large amount of registers. + *** Changes in GDB 8.0 * GDB now supports access to the PKU register on GNU/Linux. The register is diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 9a7e2dd..015f6ba 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -63,12 +63,11 @@ typedef struct tdesc_reg int save_restore; /* The name of the register group containing this register, or NULL - 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 NULL). */ + 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. */ char *group; /* The size of the register, in bits. */ @@ -1081,17 +1080,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 registerd 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. */ @@ -1101,26 +1096,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 != NULL) - { - int general_p = 0, float_p = 0, vector_p = 0; - - if (strcmp (reg->group, "general") == 0) - general_p = 1; - else if (strcmp (reg->group, "float") == 0) - float_p = 1; - else if (strcmp (reg->group, "vector") == 0) - 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 != NULL + && (strcmp (reg->group, reggroup_name (reggroup)) == 0)) + return 1; if (reg != NULL && (reggroup == save_reggroup || reggroup == restore_reggroup)) @@ -1231,6 +1209,27 @@ tdesc_use_registers (struct gdbarch *gdbarch, void **slot = htab_find_slot (reg_hash, reg, INSERT); *slot = reg; + /* Add reggroup if its new. */ + if (reg->group != NULL) + { + struct reggroup *group; + bool group_exists = false; + + for (group = reggroup_next (gdbarch, NULL); + group != NULL; + group = reggroup_next (gdbarch, group)) + { + if (strcmp (reg->group, reggroup_name (group)) == 0) + { + group_exists = true; + break; + } + } + + if (!group_exists) + reggroup_add (gdbarch, reggroup_new (reg->group, + 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 997d659..302e64c 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 70fc0e0..21f6fcc 100644 --- a/gdb/testsuite/gdb.xml/tdesc-regs.exp +++ b/gdb/testsuite/gdb.xml/tdesc-regs.exp @@ -187,6 +187,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.