From patchwork Thu Mar 22 08:44:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 26418 Received: (qmail 42964 invoked by alias); 22 Mar 2018 08:45:23 -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 37376 invoked by uid 89); 22 Mar 2018 08:45:10 -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= X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0054.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Mar 2018 08:45:03 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.arm.com (217.140.96.140) by AM2PR08MB0097.eurprd08.prod.outlook.com (2a01:111:e400:841e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.609.10; Thu, 22 Mar 2018 08:44:54 +0000 From: alan.hayward@arm.com To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v4 03/10] Commonise tdesc_reg Date: Thu, 22 Mar 2018 08:44:22 +0000 Message-Id: <20180322084429.26250-4-alan.hayward@arm.com> In-Reply-To: <20180322084429.26250-1-alan.hayward@arm.com> References: <20180322084429.26250-1-alan.hayward@arm.com> MIME-Version: 1.0 X-ClientProxiedBy: CWXP265CA0052.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:2c::16) To AM2PR08MB0097.eurprd08.prod.outlook.com (2a01:111:e400:841e::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 948f9d70-5ff5-404e-9a76-08d58fd12f22 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM2PR08MB0097; X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0097; 3:4mxSdafGVgFRzPEG8hspQ9DFC1km8DnjjAseqPDmcYBKrNL5j7OZk/t9iEm7m3KH7Xc7xCeYAUr86yfKDKUl9t441/y9EEzmiN+oYhDeGz7TLy6S5+IoAa/mXE42CWeoCl4M3hHd/E7HSVRVHpftBdUEcPelKac+WZEU9Y+odwhpDOEQmFBdMqSQI1xgakL+K/ShcDOMKSWUt8/zLhJP5KhOxo9JKWck096FKdFM4oJEZbCqcSM8a4i1MRDFq1iw; 25:C1q2wL8lQ9Sj9ZSQQp4fo/TqvsdkPyz0SVqhFap8K4myKiBulqh5ZTpptiNQjCm80JOB5PkPDwAYVnOjkKZboNa0Ou2hVO5+ZIuMedDVJ8NVTiKOb9g4myAP/Dv3CYYYoGxccsfEFcqU/4zc05wv3yH+y/8K+iLnhZcloVMX4dffczo1xVD7IFozflBaaFczVaqi/llbrnvseFq3ClYgRXA5+F5ko42BQdqLhKYPB0fI+e6qq5Q0GyoqiIlcAXIzXJYptgvfOy0ZjUl7gcUY8D6omO11ecDLpTB72kpvUE2Zyh2tM7Xldm2xt43FmzszTmKd5TOuN2OVqA00cjZqOQ==; 31:BFp2ZD8VkrS7posGj+2oZDvVA4ulD4GguW93pbV/q/bXiAVfIVO9r0y6EcShSlcac/XwzJsF9oeTDHYDdvjk5IFKlGuYynQRaZBr5JE2iUPIA9GlI3k2Mfz/+2GkESUposI70IsHxZ9uRAQC9PWAJraSRNLua5mJY8XBn+W0hukrhb75e+CyYhERiG49JbZtNFrDBrWH/YyZ+1G3o7VFuxMCbCiYih+1/QFqkGR8BoI= X-MS-TrafficTypeDiagnostic: AM2PR08MB0097: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0097; 20:TE4OErsXFon0tV0ZbePS5uTgj5wefqmH9qTGpf6LBQBYPkfwjpw7Uv76C0hl5rUwscLtZXdJSiVW8BuF2430wr5B2sMEx5SE9mJzxqJoyfYQypvR2pwoCBPEAkyly1sYTWBIWSkpUUaRQ2cCxnCHRGdveT43qAMKKuXgakErBCk=; 4:+Le07tqyEcKn6BWNBWd9qNgQCzudL3aqytmQ1mZQPbFfuPubk8kTWcMUQKbLs794llIppWX0mtIUy4DAZfkulgnQz/DVl957Pxgi+9FWcu36VhkjVBJNS94DwNcc9hG3EktgcIRDPgQAF6NO2kp3zskQ5dw+qH9j5/nYmfIjnVWnBo7AP2o4j5KzidgEKvkYM1YuCJEXtozCWv8l55fH9SkuhPOWuBNdlMwpSLfbfc1GPa7ucflu8yh24+nH5EZfueUpwGfLmO6DhYJKF8njNE0o0HV14iWr+4kEnoU1QQ+3/vPAA/jiIwkVuY5P7CPXsBA/ECrxdIUaX9xCZVH54Nhi8d/0Fn/LOxw/HuDPKc9XC/PyDKjylSztwMqTyFygPnQ9lamymRSjKHgnuQWygecvFskjwp84AEOTZGJlMYrIYOVEl2V3sQ6wrc+w74C/yvR+Ct1nTogcCTy+QlPgAw== 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)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:AM2PR08MB0097; BCL:0; PCL:0; RULEID:; SRVR:AM2PR08MB0097; X-Forefront-PRVS: 0619D53754 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(366004)(376002)(39380400002)(396003)(39860400002)(377424004)(189003)(199004)(97736004)(72206003)(16586007)(7696005)(6666003)(86362001)(6916009)(2906002)(2950100002)(66066001)(47776003)(6486002)(25786009)(53936002)(51416003)(4326008)(106356001)(1076002)(8676002)(105586002)(478600001)(53416004)(6306002)(6116002)(305945005)(50226002)(36756003)(386003)(7736002)(59450400001)(52116002)(3846002)(81156014)(81166006)(9686003)(68736007)(76176011)(50466002)(8936002)(186003)(2351001)(16526019)(85782001)(26005)(316002)(5660300001)(2361001)(48376002)(446003)(2004002)(85772001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR08MB0097; H:C02TF0U7HF1T.arm.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM2PR08MB0097; 23:7ZJFQgKyT3YpXapsNFcOQq/xd+WlFZRoRiaW47e4x?= =?us-ascii?Q?tQWRgIPyQB1Wu9qv7FNJN9+PMhHnkhG1EtCu1ZmzIgZUx4yYeA5Ejvy1Dz6L?= =?us-ascii?Q?XFHBcTdVSDR+gwheg1NNrBnz0MXQwyhDCADKL7cxASufX5K4VCjgoJ7qkoVi?= =?us-ascii?Q?wtaCcxpLqaFgr9pPzakBhEDa1njPorziKFOUySmSaHnqM3FDJjfl19lJowta?= =?us-ascii?Q?R1AyZoTHZqfKZ0nt465pnYO4926SAYECthCl/bQN0ws6WNTBLyjxsnrEvLkE?= =?us-ascii?Q?LHgN1VWZASJ2ROv1ho3ezq+i6uKlUpUiDpeM03yqjH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/GnVKp5JvoowJJwkWycv5qzmo/01+rhwRF4lINK5NCZPR1Wao5jAMI=; 24:cwo13yp0T1vUT03P+P3eo0TSsuCu/uG/u7Umrb/o4XDlrg8WVwYJR+py3HhPXCPtaRHxNlxxhUQb6WIpe5DvZmRiUGDm+EzodAPsITJkjso= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0097; 7:krnl87T13LKOJnpQ83HSU/eJe39AluZn292rY5g71WFY11w83lf5dH1zCkKqpBVTU1fNfSQsnFhVsrAZUSDdc6xCFhtymvsdHrVxXk3MF4H+pINaGNEbkYoZ5ZOAjdHtLlOQfLn20Zg/0OGyOTh0IfDDnWg3wI0O8b4+pO/JOgGZVROgDLaeIirtcVUyZ7fejk24h68yV5uzpIC9B8H6BZ2AvNO3p8LkL3r1LmNsOXRT89fTP3TbcDO7mYZXlQEV X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2018 08:44:54.2183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 948f9d70-5ff5-404e-9a76-08d58fd12f22 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR08MB0097 X-IsSubscribed: yes From: Alan Hayward 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 V3 version in init_target_desc(), where I now use reg_def references as introduced in the previous patch. 2018-03-21 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. * 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 | 40 ++++++++++++++++ gdb/common/tdesc.h | 111 ++++++++++++++++++++++++++++++++++++++++++++ gdb/gdbserver/Makefile.in | 3 ++ gdb/gdbserver/tdesc.c | 53 ++++++++++++--------- gdb/gdbserver/tdesc.h | 5 +- gdb/target-descriptions.c | 116 ---------------------------------------------- 7 files changed, 191 insertions(+), 139 deletions(-) create mode 100644 gdb/common/tdesc.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 44db1937b6..f1d2f0193a 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -966,6 +966,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 \ @@ -1443,6 +1444,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..a5f2de4b5b --- /dev/null +++ b/gdb/common/tdesc.c @@ -0,0 +1,40 @@ +/* Target description support for GDB. + + Copyright (C) 2017 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 . */ + +#ifdef GDBSERVER +#include "server.h" +#else +#include "defs.h" +#endif + +#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..ac6dfdf7bb 100644 --- a/gdb/common/tdesc.h +++ b/gdb/common/tdesc.h @@ -18,6 +18,12 @@ #ifndef ARCH_TDESC_H #define ARCH_TDESC_H 1 +#ifdef GDBSERVER +#include "server.h" +#else +#include "defs.h" +#endif + struct tdesc_feature; struct tdesc_type; struct tdesc_type_builtin; @@ -26,6 +32,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 8e68a27c7c..dbf07b2c8d 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -69,10 +69,35 @@ 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 current_size = tdesc->reg_defs.size (); + + /* Register number will either increase (possibly with gaps) or be + zero. */ + gdb_assert (treg->target_regnum == 0 + || treg->target_regnum >= current_size); + + tdesc->reg_defs.resize (treg->target_regnum != 0 + ? treg->target_regnum + 1 + : current_size + 1); + + /* Fill in any blank spaces. */ + while (current_size < treg->target_regnum) + { + struct reg *reg = &tdesc->reg_defs[current_size]; + reg->name = ""; + reg->size = 0; + reg->offset = offset; + current_size++; + } + + struct reg *reg = &tdesc->reg_defs.back (); + reg->name = treg->name.c_str (); + reg->size = treg->bitsize; + reg->offset = offset; + offset += reg->size; } tdesc->registers_size = offset / 8; @@ -236,26 +261,10 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name, int regnum, int save_restore, const char *group, int bitsize, const char *type) { - struct target_desc *tdesc = (struct target_desc *) feature; - int current_size = tdesc->reg_defs.size (); - - tdesc->reg_defs.resize (regnum != 0 ? regnum + 1 : current_size + 1); - - while (current_size < regnum) - { - struct reg *reg = &tdesc->reg_defs[current_size]; - reg->name = ""; - reg->size = 0; - current_size++; - } - - gdb_assert (regnum == 0 - || regnum + 1 == tdesc->reg_defs.size ()); - - struct reg *reg = &tdesc->reg_defs.back (); + tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, + group, bitsize, type); - reg->name = name; - reg->size = bitsize; + tdesc->registers.emplace_back (reg); } /* See common/tdesc.h. */ diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index a62544341c..c64ce13b25 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/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