From patchwork Tue Apr 10 14:33:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 26667 Received: (qmail 52428 invoked by alias); 10 Apr 2018 14:34: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 52156 invoked by uid 89); 10 Apr 2018 14:34:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=obs X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10045.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Apr 2018 14:34:02 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from c02tf0u7hf1t.manchester.arm.com (217.140.96.140) by HE1PR0802MB2138.eurprd08.prod.outlook.com (2603:10a6:3:c2::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Tue, 10 Apr 2018 14:33:52 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v5 1/8] Commonise tdesc_reg Date: Tue, 10 Apr 2018 15:33:30 +0100 Message-Id: <20180410143337.71768-2-alan.hayward@arm.com> In-Reply-To: <20180410143337.71768-1-alan.hayward@arm.com> References: <20180410143337.71768-1-alan.hayward@arm.com> MIME-Version: 1.0 X-ClientProxiedBy: CWXP265CA0019.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:2e::31) To HE1PR0802MB2138.eurprd08.prod.outlook.com (2603:10a6:3:c2::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2a5170e3-bd5d-43f1-1f42-08d59ef01576 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:HE1PR0802MB2138; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 3:+eSzzs9J6p+d2TOutKc9A7j2mqHcDkoQA97DRCFKFeLXgwOAWttNq9a/WMvgPTNwHpHsNioC0lIv9bouw8hCJEhts8cpkoUfwU2m7PxrSpp45/d4RxqnyTA14THTz5/jvd6dTpTGG2yBMkpgSP6T48bfvf1dQnKVqGEIjkQKZGWAontQz7KvZPlF9bWreTR4IGjN3fGvomlXyncSlsCpA7NZVwLRBaMlh3Hu9bsOBgTRRBs38zIw+WCarqZCWWL6; 25:+4mg/FBKBbefk7H64nTI9+jzE76eVp9PbtXEi6WGMO66RrId7XyItKL/0muqbEh/5VUASyNOfqkPuFH/PnA330gf4xCX63ryQ9ngDdSSVPI4Fp7D8vfv5UIL03j2m5zoCNpwbPjFBfFtsCHVzFiAm7cKdK5ysj5wdxJgX5j831Qm78qlgUckeQebzk23z8pHQSrtLyy4ua0AThVVgmInspTFbUBvHoUOuxpiaX15zG1lxNh8QUGQs26HcXJ3AGBL+U2y3O4FO37/QpphB0ECtVzQxw1vAFGGGyyvkARFrkDKz92TF1Yprt+C1ha3GkcPiMTSIKWRtV7RBnr13F870w==; 31:oU8KuDWFWr+Ij2K2JbA34XT8YLqzASiwyYoWNaiEOKSXH0QElTiAUxQfzkO316GNeiOXWyYiqdy4cRQSac7NrGwIYTY+pZEJjMubD9NRrxMnrsM7uR85pWvL4XOkTKChFEyoxRLOqTTiqvrlanEpoFH8qdl6alaBPreuDszjb4nQ0Xzcs0J4OmIeP16oC7uRqbtDr9872b388ioKHBEpveE46FcYMIX+g+TFZRBRRRQ= X-MS-TrafficTypeDiagnostic: HE1PR0802MB2138: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 20:6JONlmsQO15D5J2DzsTP3cRHRf2MV/ohEm3HuXKgrEPkEWp0duJ2ofTIftl7q9FfxDQeVQUmyksat+E5slASbqMx3LGSYwX7dg7JIAZja00G/qg6sGjWaXg36vw3s2GZxzdWr1+zYroHYluCru3VhoMu1YcVG+75do373JPD4J4=; 4:h9y1vdC10quH5qJnQwIJph6/b9FhdPiYM0GBsvbHQg96cjXbH6kw1etzSI127urtrhj4V7X1rAYWr0NRYrMEhPbFZm9ck/d/oZXCW2GR3roAj25G1R337gG4oXZKbFrPn+5zrPrINwd1qIb1QZGD0VCuZPUYI3FwOcrjSXXS//tJ6u9nE2uVk14WEkfMEo0nHhgsd/Sz3DJrV5mN1NIv759Gm0DbuWRwebzWak7iKKCQSED+DF0IfVLVCuhxM3ADi/kj3Z4My+tOskJwZ686Dwcoq2g9CSmVf+xmHMGGpnv4zS5i95WC2wjyUpR5ipZQmi2Dk8EAU/mNRjScpkroZVXwvSXE9fAnpC92SzTEUq7IPgRL3gKQu17xwR1Y4IWGxZY+KnngM2ytQOoLYJ4itvozgww/P5nwllx/koCt9XgwTiYPqO1PjYi7zvjPNlSYeJJZATiPwbwaFzgAQs8YDw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(180628864354917)(22074186197030)(131327999870524)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:HE1PR0802MB2138; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0802MB2138; X-Forefront-PRVS: 0638FD5066 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(396003)(346002)(39860400002)(366004)(376002)(377424004)(189003)(199004)(76176011)(386003)(52116002)(7696005)(36756003)(59450400001)(51416003)(6486002)(105586002)(486006)(6666003)(6306002)(11346002)(6916009)(476003)(2906002)(3846002)(2616005)(6116002)(956004)(2361001)(446003)(1076002)(2351001)(186003)(316002)(26005)(86362001)(16526019)(8676002)(68736007)(16586007)(81166006)(81156014)(5660300001)(7736002)(8936002)(53936002)(106356001)(4326008)(478600001)(66066001)(305945005)(25786009)(48376002)(97736004)(72206003)(50226002)(50466002)(47776003)(481834002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0802MB2138; H:c02tf0u7hf1t.manchester.arm.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0802MB2138; 23:c3cVU0frWvbo9spg37E9x18FE9CHCqQp8AyPJ54?= =?us-ascii?Q?rZ2Uz9pRIUB7QOAvOBs2L0u75ZfuRJVGWGl89wXspG6kG+N3CxWi5dNE80Px?= =?us-ascii?Q?HbmuTuwFD9lN4f1vWosW3pV3L2Vkzr+IsaEjjzGUOLIq/Md0nVeludkU9bGI?= =?us-ascii?Q?fMJJNDFfdvx8ltpv0rH5Isj05OvnCq9QIyLiqSsI4D8S7E9yyAp4sb5A/8VR?= =?us-ascii?Q?tu3phVs8evEzoSzbXGzNYMPebx5Z2CfxnhvBQjZuNNTbEVYMtSTuVH4LEbYG?= =?us-ascii?Q?OSp+m2IzpKGj9IJGz+QAbKtpzWvRrtbgGjtnIpT64M+N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JlwcHYMGKuyIZqSPUYZhU11VR9wJ5PQzGvL/0+NhZhBzEZHmXu0=; 24:MaS7JjTYD4laL81MGYe0xOROoT/3NCDrP9E4KXZ1kV6Gq+nE+GwdXPxxHP2JROUDT4I+upEzoHU7HV2CIsko7QHzG8no4h8/jkGLLWroC+A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 7:/9Ln8Qvw/L08g1i320NLFWoJZpd6S7N7YEQewVW2HZ/r+JaAlZQP/pVihALslwQK4ixngf7MS7Jz2fniFlMcxXNpIXNol3R1RoNgF7Lh9PFAmZ9QDLVlbQrHGUoDwJ2BCvxKqGR+72yNHRHE4KPhggaXcwfpTF1bYR/QMhyGDqMDD+/uZjEpXpOm9NA3C+MtQzEiUZU0IOse8RNeGt7C7zUxGo8rqYveylwqBzCJvVtGlRNpN8Wt+RNNk5peKfyn X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2018 14:33:52.8289 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a5170e3-bd5d-43f1-1f42-08d59ef01576 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2138 X-IsSubscribed: yes This patch commonises tdesc_reg and makes use of it in gdbserver tdesc. gdbserver tdesc_create_reg is changed to create a tdesc_reg instead of a reg_defs entry. The vector of tdesc_reg is held inside tdesc_feature. However, other modules in gdbserver directly access the reg_defs structure. To work around this, init_target_desc fills in reg_defs by parsing the tdesc_reg vector. The long term goal is to remove reg_defs, replacing with accessor funcs. I wanted to make tdesc_create_reg common, but I cannot do that until the next patch. I also had to commonise tdesc_element_visitor and tdesc_element. This patch only differs from the V4 version in init_target_desc() and the changing of constructors for regdef. 2018-04-10 Alan Hayward gdb/ * Makefile.in: Add arch/tdesc.c * common/tdesc.c: New file. * common/tdesc.h (tdesc_element_visitor): Move to here. (tdesc_element): Likewise. (tdesc_reg): Likewise. (tdesc_reg_up): Likewise. * regformats/regdef.h (reg): Add offset to constructors. * target-descriptions.c (tdesc_element_visitor): Move from here. (tdesc_element): Likewise. (tdesc_reg): Likewise. (tdesc_reg_up): Likewise. gdbserver/ * Makefile.in: Add common/tdesc.c * tdesc.c (init_target_desc): init all reg_defs from register vector. (tdesc_create_reg): Create tdesc_reg. * tdesc.h (tdesc_feature): Add register vector. --- gdb/Makefile.in | 2 + gdb/common/tdesc.c | 35 ++++++++++++++ gdb/common/tdesc.h | 105 +++++++++++++++++++++++++++++++++++++++++ gdb/gdbserver/Makefile.in | 3 ++ gdb/gdbserver/tdesc.c | 23 +++++---- gdb/gdbserver/tdesc.h | 5 +- gdb/regformats/regdef.h | 8 ++-- gdb/target-descriptions.c | 116 ---------------------------------------------- 8 files changed, 168 insertions(+), 129 deletions(-) create mode 100644 gdb/common/tdesc.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 0a07cabb43..4aa27e7c4a 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -968,6 +968,7 @@ COMMON_SFILES = \ common/run-time-clock.c \ common/signals.c \ common/signals-state-save-restore.c \ + common/tdesc.c \ common/vec.c \ common/xml-utils.c \ complaints.c \ @@ -1449,6 +1450,7 @@ HFILES_NO_SRCDIR = \ common/run-time-clock.h \ common/signals-state-save-restore.h \ common/symbol.h \ + common/tdesc.h \ common/vec.h \ common/version.h \ common/x86-xstate.h \ diff --git a/gdb/common/tdesc.c b/gdb/common/tdesc.c new file mode 100644 index 0000000000..8a3d620b04 --- /dev/null +++ b/gdb/common/tdesc.c @@ -0,0 +1,35 @@ +/* Target description support for GDB. + + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "common-defs.h" +#include "common/tdesc.h" + +tdesc_reg::tdesc_reg (struct tdesc_feature *feature, const std::string &name_, + int regnum, int save_restore_, const char *group_, + int bitsize_, const char *type_) + : name (name_), target_regnum (regnum), + save_restore (save_restore_), + group (group_ != NULL ? group_ : ""), + bitsize (bitsize_), + type (type_ != NULL ? type_ : "") +{ + /* If the register's type is target-defined, look it up now. We may not + have easy access to the containing feature when we want it later. */ + tdesc_type = tdesc_named_type (feature, type.c_str ()); +} diff --git a/gdb/common/tdesc.h b/gdb/common/tdesc.h index cc11651dca..0ec45af3b4 100644 --- a/gdb/common/tdesc.h +++ b/gdb/common/tdesc.h @@ -26,6 +26,111 @@ struct tdesc_type_with_fields; struct tdesc_reg; struct target_desc; +/* The interface to visit different elements of target description. */ + +class tdesc_element_visitor +{ +public: + virtual void visit_pre (const target_desc *e) + {} + + virtual void visit_post (const target_desc *e) + {} + + virtual void visit_pre (const tdesc_feature *e) + {} + + virtual void visit_post (const tdesc_feature *e) + {} + + virtual void visit (const tdesc_type_builtin *e) + {} + + virtual void visit (const tdesc_type_vector *e) + {} + + virtual void visit (const tdesc_type_with_fields *e) + {} + + virtual void visit (const tdesc_reg *e) + {} +}; + +class tdesc_element +{ +public: + virtual void accept (tdesc_element_visitor &v) const = 0; +}; + +/* An individual register from a target description. */ + +struct tdesc_reg : tdesc_element +{ + tdesc_reg (struct tdesc_feature *feature, const std::string &name_, + int regnum, int save_restore_, const char *group_, + int bitsize_, const char *type_); + + virtual ~tdesc_reg () = default; + + DISABLE_COPY_AND_ASSIGN (tdesc_reg); + + /* The name of this register. In standard features, it may be + recognized by the architecture support code, or it may be purely + for the user. */ + std::string name; + + /* The register number used by this target to refer to this + register. This is used for remote p/P packets and to determine + the ordering of registers in the remote g/G packets. */ + long target_regnum; + + /* If this flag is set, GDB should save and restore this register + around calls to an inferior function. */ + 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). */ + std::string group; + + /* The size of the register, in bits. */ + int bitsize; + + /* The type of the register. This string corresponds to either + a named type from the target description or a predefined + type from GDB. */ + std::string type; + + /* The target-described type corresponding to TYPE, if found. */ + struct tdesc_type *tdesc_type; + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } + + bool operator== (const tdesc_reg &other) const + { + return (name == other.name + && target_regnum == other.target_regnum + && save_restore == other.save_restore + && bitsize == other.bitsize + && group == other.group + && type == other.type); + } + + bool operator!= (const tdesc_reg &other) const + { + return !(*this == other); + } +}; + +typedef std::unique_ptr tdesc_reg_up; + /* Allocate a new target_desc. */ target_desc *allocate_target_description (void); diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 75fbf7ec75..4a54235dae 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -215,6 +215,7 @@ SFILES = \ $(srcdir)/common/print-utils.c \ $(srcdir)/common/ptid.c \ $(srcdir)/common/rsp-low.c \ + $(srcdir)/common/tdesc.c \ $(srcdir)/common/vec.c \ $(srcdir)/common/xml-utils.c \ $(srcdir)/nat/linux-btrace.c \ @@ -258,6 +259,7 @@ OBS = \ common/rsp-low.o \ common/signals.o \ common/signals-state-save-restore.o \ + common/tdesc.o \ common/vec.o \ common/xml-utils.o \ debug.o \ @@ -403,6 +405,7 @@ IPA_OBJS = \ common/format-ipa.o \ common/print-utils-ipa.o \ common/rsp-low-ipa.o \ + common/tdesc-ipa.o \ common/vec-ipa.o \ regcache-ipa.o \ remote-utils-ipa.o \ diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index 9f00ecf938..afe0187aeb 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -54,10 +54,19 @@ init_target_desc (struct target_desc *tdesc) { int offset = 0; - for (reg ® : tdesc->reg_defs) + /* Go through all the features and populate reg_defs. */ + for (const tdesc_reg_up &treg : tdesc->registers) { - reg.offset = offset; - offset += reg.size; + int regnum = treg->target_regnum; + + /* Register number will increase (possibly with gaps) or be zero. */ + gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ()); + + if (regnum != 0) + tdesc->reg_defs.resize (regnum, reg (offset)); + + tdesc->reg_defs.emplace_back (treg->name.c_str (), offset, treg->bitsize); + offset += treg->bitsize; } tdesc->registers_size = offset / 8; @@ -222,12 +231,10 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name, { struct target_desc *tdesc = (struct target_desc *) feature; - gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ()); - - if (regnum != 0) - tdesc->reg_defs.resize (regnum); + tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, + group, bitsize, type); - tdesc->reg_defs.emplace_back (name, bitsize); + tdesc->registers.emplace_back (reg); } /* See common/tdesc.h. */ diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index 85139d948c..8eb88eedce 100644 --- a/gdb/gdbserver/tdesc.h +++ b/gdb/gdbserver/tdesc.h @@ -25,7 +25,10 @@ #include struct tdesc_feature -{}; +{ + /* The registers associated with this feature. */ + std::vector registers; +}; /* A target description. Inherit from tdesc_feature so that target_desc can be used as tdesc_feature. */ diff --git a/gdb/regformats/regdef.h b/gdb/regformats/regdef.h index 4775e863e9..7c80d45d48 100644 --- a/gdb/regformats/regdef.h +++ b/gdb/regformats/regdef.h @@ -21,15 +21,15 @@ struct reg { - reg () + reg (int _offset) : name (""), - offset (0), + offset (_offset), size (0) {} - reg (const char *_name, int _size) + reg (const char *_name, int _offset, int _size) : name (_name), - offset (0), + offset (_offset), size (_size) {} diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 5d34e29a86..3186bf886f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -38,44 +38,6 @@ #include "completer.h" #include "readline/tilde.h" /* tilde_expand */ -static type *make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype); - -/* The interface to visit different elements of target description. */ - -class tdesc_element_visitor -{ -public: - virtual void visit_pre (const target_desc *e) - {} - - virtual void visit_post (const target_desc *e) - {} - - virtual void visit_pre (const tdesc_feature *e) - {} - - virtual void visit_post (const tdesc_feature *e) - {} - - virtual void visit (const tdesc_type_builtin *e) - {} - - virtual void visit (const tdesc_type_vector *e) - {} - - virtual void visit (const tdesc_type_with_fields *e) - {} - - virtual void visit (const tdesc_reg *e) - {} -}; - -class tdesc_element -{ -public: - virtual void accept (tdesc_element_visitor &v) const = 0; -}; - /* Types. */ struct property @@ -88,84 +50,6 @@ struct property std::string value; }; -/* An individual register from a target description. */ - -struct tdesc_reg : tdesc_element -{ - tdesc_reg (struct tdesc_feature *feature, const std::string &name_, - int regnum, int save_restore_, const char *group_, - int bitsize_, const char *type_) - : name (name_), target_regnum (regnum), - save_restore (save_restore_), - group (group_ != NULL ? group_ : ""), - bitsize (bitsize_), - type (type_ != NULL ? type_ : "") - { - /* If the register's type is target-defined, look it up now. We may not - have easy access to the containing feature when we want it later. */ - tdesc_type = tdesc_named_type (feature, type.c_str ()); - } - - virtual ~tdesc_reg () = default; - - DISABLE_COPY_AND_ASSIGN (tdesc_reg); - - /* The name of this register. In standard features, it may be - recognized by the architecture support code, or it may be purely - for the user. */ - std::string name; - - /* The register number used by this target to refer to this - register. This is used for remote p/P packets and to determine - the ordering of registers in the remote g/G packets. */ - long target_regnum; - - /* If this flag is set, GDB should save and restore this register - around calls to an inferior function. */ - 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. 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. */ - int bitsize; - - /* The type of the register. This string corresponds to either - a named type from the target description or a predefined - type from GDB. */ - std::string type; - - /* The target-described type corresponding to TYPE, if found. */ - struct tdesc_type *tdesc_type; - - void accept (tdesc_element_visitor &v) const override - { - v.visit (this); - } - - bool operator== (const tdesc_reg &other) const - { - return (name == other.name - && target_regnum == other.target_regnum - && save_restore == other.save_restore - && bitsize == other.bitsize - && group == other.group - && type == other.type); - } - - bool operator!= (const tdesc_reg &other) const - { - return !(*this == other); - } -}; - -typedef std::unique_ptr tdesc_reg_up; - /* A named type from a target description. */ struct tdesc_type_field