From patchwork Thu Mar 1 11:39:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 26129 Received: (qmail 45972 invoked by alias); 1 Mar 2018 11:39:43 -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 45950 invoked by uid 89); 1 Mar 2018 11:39:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=traditionally X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30040.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Mar 2018 11:39:39 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) by AM3PR08MB0689.eurprd08.prod.outlook.com (10.163.189.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.527.15; Thu, 1 Mar 2018 11:39:36 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::fc60:4b4d:7de8:f8b7]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::fc60:4b4d:7de8:f8b7%16]) with mapi id 15.20.0527.022; Thu, 1 Mar 2018 11:39:36 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH v3 2/8] Commonise tdesc_reg Date: Thu, 1 Mar 2018 11:39:36 +0000 Message-ID: References: <757A8B89-2EF0-46BD-BAA6-6E668538B17F@arm.com> In-Reply-To: <757A8B89-2EF0-46BD-BAA6-6E668538B17F@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM3PR08MB0689; 7:6DDSFxFUfZZsaMX5qCXVtOBhfgY963xtAsMqeQotedWyOPNuKPaN3HMpqOom8cxDB3qanzc4Uj/P6NbeNZGdHWB+FK8RQpSWmdiwnmEFkHVaoR6+wS9cBy1KQbGbFS6R/OZM7CcWw5DQdH27R/QXJ2F4hTvE2p+YEJdw8QIdGrylBeQkIj/bpNlD7fmiVvI4nH+OepGUX+u/6OQKz9HeLT+/b327mYviUOPPlRFPy/QIKB4zXjbQUQNazd0dq1QP x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b828d492-91db-4715-ee1b-08d57f691c0f x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:AM3PR08MB0689; x-ms-traffictypediagnostic: AM3PR08MB0689: nodisclaimer: True 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)(6040501)(2401047)(5005006)(8121501046)(3231220)(944501227)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041288)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:AM3PR08MB0689; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0689; x-forefront-prvs: 05986C03E0 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(396003)(39860400002)(366004)(376002)(39380400002)(377424004)(189003)(199004)(5640700003)(6512007)(14454004)(86362001)(575784001)(25786009)(26005)(4743002)(66066001)(2950100002)(5250100002)(2900100001)(2501003)(305945005)(97736004)(3660700001)(4326008)(83716003)(7736002)(6506007)(59450400001)(106356001)(76176011)(99286004)(2906002)(68736007)(53936002)(82746002)(102836004)(5660300001)(3280700002)(72206003)(316002)(478600001)(6436002)(8676002)(186003)(6486002)(81156014)(2351001)(81166006)(8936002)(33656002)(6306002)(6916009)(105586002)(36756003)(6116002)(3846002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0689; H:AM3PR08MB0101.eurprd08.prod.outlook.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-antispam-message-info: s4+CzqYKzIjNMAyscDdmiQmbwMg3x5D03Kfc3rNla0uTP49MLs6e/vj5qkmERdFUYR9Igh/186WI7ovFUau4T6Hrhfdk3AtggkM+W5xksx8JBFe4kLW4/68EsS66isOTkj8Fbxu+Rbwx0pjO51ehIDcor7O875NCHSAaBb3XvTo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <1E20618111F56A438235DF4630FC3BA2@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: b828d492-91db-4715-ee1b-08d57f691c0f X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Mar 2018 11:39:36.0799 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0689 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. 2018-03-01 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. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 1c58b9270d63b3bc30ebd61ae725149b2e5e760a..59d47858bbf4b2a3dc34499dc126b18af717c368 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -961,6 +961,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 \ @@ -1436,6 +1437,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.h b/gdb/common/tdesc.h index cc11651dcaa7abe81598b69f509ef34ff0d94dbf..ac6dfdf7bb4ec2c3bbbed1b091f04308dd741f21 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/common/tdesc.c b/gdb/common/tdesc.c new file mode 100644 index 0000000000000000000000000000000000000000..a5f2de4b5ba2adb61dd098d8fc569a6339164586 --- /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/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 2dbf9ae63df15502d038bcd26af6963dfa87e739..ce09b492646a810a554485372648c928bbae3cdc 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -212,6 +212,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 \ @@ -254,6 +255,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 \ @@ -397,6 +399,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.h b/gdb/gdbserver/tdesc.h index 4513ea74232a456cc86eb9a655904012ff117373..b0b8fa3f9e63590398d0de52359ae8ee0271557b 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/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index e50a848e2f9f280a84ab139cfce4d1f17bd05884..806e87da185623da29d39d9fd74c8722f795e086 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -72,9 +72,27 @@ init_target_desc (struct target_desc *tdesc) { int offset = 0; - for (reg *reg : tdesc->reg_defs) + /* Go through all the features and populate reg_defs. */ + for (const tdesc_reg_up &treg : tdesc->registers) { + /* Fill in any blank spaces. */ + while (tdesc->reg_defs.size () < treg->target_regnum) + { + struct reg *reg = XCNEW (struct reg); + reg->name = ""; + reg->size = 0; + reg->offset = offset; + tdesc->reg_defs.push_back (reg); + } + + gdb_assert (treg->target_regnum == 0 + || treg->target_regnum == tdesc->reg_defs.size ()); + + struct reg *reg = XCNEW (struct reg); + reg->name = treg->name.c_str (); + reg->size = treg->bitsize; reg->offset = offset; + tdesc->reg_defs.push_back (reg); offset += reg->size; } @@ -241,23 +259,10 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name, { struct target_desc *tdesc = (struct target_desc *) feature; - while (tdesc->reg_defs.size () < regnum) - { - struct reg *reg = XCNEW (struct reg); - - reg->name = ""; - reg->size = 0; - tdesc->reg_defs.push_back (reg); - } - - gdb_assert (regnum == 0 - || regnum == tdesc->reg_defs.size ()); - - struct reg *reg = XCNEW (struct reg); + tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, + group, bitsize, type); - reg->name = name; - reg->size = bitsize; - tdesc->reg_defs.push_back (reg); + tdesc->registers.emplace_back (reg); } /* See common/tdesc.h. */ diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 5d34e29a867f8d39cd0451eb48cbf39614c9acba..3186bf886fc5f1b62e0ff77a4e5a2bc0fe52b250 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