From patchwork Thu Mar 1 11:40:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 26130 Received: (qmail 47079 invoked by alias); 1 Mar 2018 11:40: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 47065 invoked by uid 89); 1 Mar 2018 11:40:06 -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, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=expedite X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30061.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Mar 2018 11:40:03 +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:40:00 +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:40:00 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH v3 3/8] Commonise tdesc_feature Date: Thu, 1 Mar 2018 11:40:00 +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:Zeyh5LGlBDnfUZFoVhYsQQD+NZGvq1tzFpZvDoHcCvy0uCzSa4Gn9I6gCK99qiK2vEaiMvZd+4/PS79fy7ufbOCtHMcuaqCrP0bGSnAMBjqNsZAjPrCqarU2xjxLrtSYaOmXYXW0ztQvAOFpRdVt6Lj3VjCfJgbRPrlUUlRWt0T6ar1iaUp9gE4z5xEvCmSonQ5frfTObK+QY6B6Ri5/g7a/wHG1auIFJJ2jV7bry395+kp+dNR4xSHPxkfxrPMd x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 13bed482-8f6d-46fe-21c1-08d57f692a71 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:(180628864354917)(131327999870524); 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)(53946003)(53936002)(82746002)(102836004)(5660300001)(3280700002)(72206003)(316002)(478600001)(6436002)(8676002)(186003)(6486002)(81156014)(2351001)(81166006)(8936002)(33656002)(6916009)(105586002)(36756003)(6116002)(3846002); 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: 24u7S+3fFlHjnUdM6014eWNdLTUGTHiB+KoPKa5g8PtTpeKEeRDfUtDPMyl1wiQtkEUF4DMmp3JBWyCH8KUQv3xzqF3IddUi3i9WZr+HFYA7cNnZVO/jNsvoRkPpu/X0HcQwCeGQzR0Rc3a+BD9Tx4Jl6QJCiOIhuGdYpHbG6TY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13bed482-8f6d-46fe-21c1-08d57f692a71 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Mar 2018 11:40:00.2050 (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_feature and makes use of it in gdbserver tdesc. Previously in gdbserver, target_desc was interchangeable with tdesc_feature. Now gdbserver target_desc contains a vector of tdesc_feature. I am now able to commonise tdesc_create_reg (wanted to do this in the previous patch). I also had to commonise tdesc_type. This is ok, because I will need them in the next patch. Alan. 2018-03-01 Alan Hayward gdb/ * common/tdesc.c (tdesc_feature::accept): Move to here. (tdesc_feature::operator==): Likewise. (tdesc_create_reg): Likewise. * common/tdesc.h (tdesc_type_kind): Likewise. (struct tdesc_type): Likewise. (struct tdesc_feature): Likewise. * regformats/regdat.sh: Create a feature. * target-descriptions.c (tdesc_type_kind): Move from here. (tdesc_type): Likewise. (tdesc_type_up): Likewise. (tdesc_feature): Likewise. (tdesc_create_reg): Likewise. gdbserver/ * tdesc.c (~target_desc): Remove implictly deleted items. (init_target_desc): Iterate all features. (tdesc_get_features_xml): Use vector. (tdesc_create_feature): Create feature. * tdesc.h (tdesc_feature) Remove (target_desc): Add features. diff --git a/gdb/common/tdesc.h b/gdb/common/tdesc.h index ac6dfdf7bb4ec2c3bbbed1b091f04308dd741f21..07083e3d1d41c4f86f85ae032b45c1d6f6a105ff 100644 --- a/gdb/common/tdesc.h +++ b/gdb/common/tdesc.h @@ -31,6 +31,7 @@ struct tdesc_type_vector; struct tdesc_type_with_fields; struct tdesc_reg; struct target_desc; +struct type; /* The interface to visit different elements of target description. */ @@ -137,6 +138,99 @@ struct tdesc_reg : tdesc_element typedef std::unique_ptr tdesc_reg_up; +enum tdesc_type_kind +{ + /* Predefined types. */ + TDESC_TYPE_BOOL, + TDESC_TYPE_INT8, + TDESC_TYPE_INT16, + TDESC_TYPE_INT32, + TDESC_TYPE_INT64, + TDESC_TYPE_INT128, + TDESC_TYPE_UINT8, + TDESC_TYPE_UINT16, + TDESC_TYPE_UINT32, + TDESC_TYPE_UINT64, + TDESC_TYPE_UINT128, + TDESC_TYPE_CODE_PTR, + TDESC_TYPE_DATA_PTR, + TDESC_TYPE_IEEE_SINGLE, + TDESC_TYPE_IEEE_DOUBLE, + TDESC_TYPE_ARM_FPA_EXT, + TDESC_TYPE_I387_EXT, + + /* Types defined by a target feature. */ + TDESC_TYPE_VECTOR, + TDESC_TYPE_STRUCT, + TDESC_TYPE_UNION, + TDESC_TYPE_FLAGS, + TDESC_TYPE_ENUM +}; + +struct tdesc_type : tdesc_element +{ + tdesc_type (const std::string &name_, enum tdesc_type_kind kind_) + : name (name_), kind (kind_) + {} + + virtual ~tdesc_type () = default; + + DISABLE_COPY_AND_ASSIGN (tdesc_type); + + /* The name of this type. */ + std::string name; + + /* Identify the kind of this type. */ + enum tdesc_type_kind kind; + + bool operator== (const tdesc_type &other) const + { + return name == other.name && kind == other.kind; + } + + bool operator!= (const tdesc_type &other) const + { + return !(*this == other); + } +}; + +typedef std::unique_ptr tdesc_type_up; + +/* A feature from a target description. Each feature is a collection + of other elements, e.g. registers and types. */ + +struct tdesc_feature : tdesc_element +{ + tdesc_feature (const std::string &name_) + : name (name_) + {} + + virtual ~tdesc_feature () = default; + + DISABLE_COPY_AND_ASSIGN (tdesc_feature); + + /* The name of this feature. It may be recognized by the architecture + support code. */ + std::string name; + + /* The registers associated with this feature. */ + std::vector registers; + + /* The types associated with this feature. */ + std::vector types; + + void accept (tdesc_element_visitor &v) const override; + + bool operator== (const tdesc_feature &other) const; + + bool operator!= (const tdesc_feature &other) const + { + return !(*this == other); + } +}; + +typedef std::unique_ptr tdesc_feature_up; + /* Allocate a new target_desc. */ target_desc *allocate_target_description (void); diff --git a/gdb/common/tdesc.c b/gdb/common/tdesc.c index a5f2de4b5ba2adb61dd098d8fc569a6339164586..ef6ed944df20d4613dd0dd338710a4c1ad67bbf2 100644 --- a/gdb/common/tdesc.c +++ b/gdb/common/tdesc.c @@ -38,3 +38,61 @@ tdesc_reg::tdesc_reg (struct tdesc_feature *feature, const std::string &name_, have easy access to the containing feature when we want it later. */ tdesc_type = tdesc_named_type (feature, type.c_str ()); } + +void tdesc_feature::accept (tdesc_element_visitor &v) const +{ + v.visit_pre (this); + + for (const tdesc_type_up &type : types) + type->accept (v); + + for (const tdesc_reg_up ® : registers) + reg->accept (v); + + v.visit_post (this); +} + +bool tdesc_feature::operator== (const tdesc_feature &other) const +{ + if (name != other.name) + return false; + + if (registers.size () != other.registers.size ()) + return false; + + for (int ix = 0; ix < registers.size (); ix++) + { + const tdesc_reg_up ®1 = registers[ix]; + const tdesc_reg_up ®2 = other.registers[ix]; + + if (reg1 != reg2 && *reg1 != *reg2) + return false; + } + + if (types.size () != other.types.size ()) + return false; + + for (int ix = 0; ix < types.size (); ix++) + { + const tdesc_type_up &type1 = types[ix]; + const tdesc_type_up &type2 = other.types[ix]; + + if (type1 != type2 && *type1 != *type2) + return false; + } + + return true; +} + +/* See common/tdesc.h. */ + +void +tdesc_create_reg (struct tdesc_feature *feature, const char *name, + int regnum, int save_restore, const char *group, + int bitsize, const char *type) +{ + tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, + group, bitsize, type); + + feature->registers.emplace_back (reg); +} diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index b0b8fa3f9e63590398d0de52359ae8ee0271557b..8534069d616b97dc82df04939a4ac935aa4e1cad 100644 --- a/gdb/gdbserver/tdesc.h +++ b/gdb/gdbserver/tdesc.h @@ -24,16 +24,10 @@ #include "regdef.h" #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. */ -struct target_desc : tdesc_feature +struct target_desc { /* A vector of elements of register definitions that describe the inferior's register set. */ @@ -42,6 +36,9 @@ struct target_desc : tdesc_feature /* The register cache size, in bytes. */ int registers_size; + /* XML features in this target description. */ + std::vector features; + #ifndef IN_PROCESS_AGENT /* An array of register names. These are the "expedite" registers: registers whose values are sent along with stop replies. */ @@ -56,9 +53,6 @@ struct target_desc : tdesc_feature fields features, arch, and osabi in tdesc_get_features_xml. */ const char *xmltarget = NULL; - /* XML features in this target description. */ - VEC (char_ptr) *features = NULL; - /* The value of element in the XML, replying GDB. */ const char *arch = NULL; diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index 806e87da185623da29d39d9fd74c8722f795e086..72769ff00fd073d93807a4aaa59ec19ec6292641 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -23,19 +23,11 @@ target_desc::~target_desc () { - int i; - for (reg *reg : reg_defs) xfree (reg); xfree ((char *) arch); xfree ((char *) osabi); - - char *f; - - for (i = 0; VEC_iterate (char_ptr, features, i, f); i++) - xfree (f); - VEC_free (char_ptr, features); } bool target_desc::operator== (const target_desc &other) const @@ -73,28 +65,29 @@ init_target_desc (struct target_desc *tdesc) int offset = 0; /* 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; - } + for (const tdesc_feature_up &feature : tdesc->features) + for (const tdesc_reg_up &treg : feature->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; + } tdesc->registers_size = offset / 8; @@ -157,7 +150,7 @@ tdesc_get_features_xml (target_desc *tdesc) { /* Either .xmltarget or .features is not NULL. */ gdb_assert (tdesc->xmltarget != NULL - || (tdesc->features != NULL + || (!tdesc->features.empty () && tdesc->arch != NULL)); if (tdesc->xmltarget == NULL) @@ -177,12 +170,10 @@ tdesc_get_features_xml (target_desc *tdesc) buffer += ""; } - char *xml; - - for (int i = 0; VEC_iterate (char_ptr, tdesc->features, i, xml); i++) + for (const tdesc_feature_up &feature : tdesc->features) { buffer += "name; buffer += "\"/>"; } @@ -195,19 +186,16 @@ tdesc_get_features_xml (target_desc *tdesc) } #endif -struct tdesc_type -{}; - /* See common/tdesc.h. */ struct tdesc_feature * tdesc_create_feature (struct target_desc *tdesc, const char *name, const char *xml) { -#ifndef IN_PROCESS_AGENT - VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml)); -#endif - return tdesc; + struct tdesc_feature *new_feature = new tdesc_feature + (xml != nullptr ? xml : name); + tdesc->features.emplace_back (new_feature); + return new_feature; } /* See common/tdesc.h. */ @@ -252,21 +240,6 @@ tdesc_create_struct (struct tdesc_feature *feature, const char *id) /* See common/tdesc.h. */ -void -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; - - tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, - group, bitsize, type); - - tdesc->registers.emplace_back (reg); -} - -/* See common/tdesc.h. */ - struct tdesc_type * tdesc_create_vector (struct tdesc_feature *feature, const char *name, struct tdesc_type *field_type, int count) diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh index ce1627120d9439082709c82c5804724f39477eb1..8c6e191596350fb4e983f8736985d9832f41e2d3 100755 --- a/gdb/regformats/regdat.sh +++ b/gdb/regformats/regdat.sh @@ -131,7 +131,7 @@ do echo "{" echo " static struct target_desc tdesc_${name}_s;" echo " struct target_desc *result = &tdesc_${name}_s;" - + echo " struct tdesc_feature *feature = tdesc_create_feature (result, \"${name}\");" continue elif test "${type}" = "xmltarget"; then xmltarget="${entry}" @@ -149,7 +149,7 @@ do echo "$0: $1 does not specify \`\`name''." 1>&2 exit 1 else - echo " tdesc_create_reg ((struct tdesc_feature *) result, \"${entry}\"," + echo " tdesc_create_reg (feature, \"${entry}\"," echo " 0, 0, NULL, ${type}, NULL);" offset=`expr ${offset} + ${type}` diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 3186bf886fc5f1b62e0ff77a4e5a2bc0fe52b250..a453eddec0cd97b692c4c9ace3f093c3fbc67422 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -67,64 +67,6 @@ struct tdesc_type_field int start, end; }; -enum tdesc_type_kind -{ - /* Predefined types. */ - TDESC_TYPE_BOOL, - TDESC_TYPE_INT8, - TDESC_TYPE_INT16, - TDESC_TYPE_INT32, - TDESC_TYPE_INT64, - TDESC_TYPE_INT128, - TDESC_TYPE_UINT8, - TDESC_TYPE_UINT16, - TDESC_TYPE_UINT32, - TDESC_TYPE_UINT64, - TDESC_TYPE_UINT128, - TDESC_TYPE_CODE_PTR, - TDESC_TYPE_DATA_PTR, - TDESC_TYPE_IEEE_SINGLE, - TDESC_TYPE_IEEE_DOUBLE, - TDESC_TYPE_ARM_FPA_EXT, - TDESC_TYPE_I387_EXT, - - /* Types defined by a target feature. */ - TDESC_TYPE_VECTOR, - TDESC_TYPE_STRUCT, - TDESC_TYPE_UNION, - TDESC_TYPE_FLAGS, - TDESC_TYPE_ENUM -}; - -struct tdesc_type : tdesc_element -{ - tdesc_type (const std::string &name_, enum tdesc_type_kind kind_) - : name (name_), kind (kind_) - {} - - virtual ~tdesc_type () = default; - - DISABLE_COPY_AND_ASSIGN (tdesc_type); - - /* The name of this type. */ - std::string name; - - /* Identify the kind of this type. */ - enum tdesc_type_kind kind; - - bool operator== (const tdesc_type &other) const - { - return name == other.name && kind == other.kind; - } - - bool operator!= (const tdesc_type &other) const - { - return !(*this == other); - } -}; - -typedef std::unique_ptr tdesc_type_up; - struct tdesc_type_builtin : tdesc_type { tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind) @@ -428,82 +370,6 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype) return gdb_type.get_type (); } -/* A feature from a target description. Each feature is a collection - of other elements, e.g. registers and types. */ - -struct tdesc_feature : tdesc_element -{ - tdesc_feature (const std::string &name_) - : name (name_) - {} - - virtual ~tdesc_feature () = default; - - DISABLE_COPY_AND_ASSIGN (tdesc_feature); - - /* The name of this feature. It may be recognized by the architecture - support code. */ - std::string name; - - /* The registers associated with this feature. */ - std::vector registers; - - /* The types associated with this feature. */ - std::vector types; - - void accept (tdesc_element_visitor &v) const override - { - v.visit_pre (this); - - for (const tdesc_type_up &type : types) - type->accept (v); - - for (const tdesc_reg_up ® : registers) - reg->accept (v); - - v.visit_post (this); - } - - bool operator== (const tdesc_feature &other) const - { - if (name != other.name) - return false; - - if (registers.size () != other.registers.size ()) - return false; - - for (int ix = 0; ix < registers.size (); ix++) - { - const tdesc_reg_up ®1 = registers[ix]; - const tdesc_reg_up ®2 = other.registers[ix]; - - if (reg1 != reg2 && *reg1 != *reg2) - return false; - } - - if (types.size () != other.types.size ()) - return false; - - for (int ix = 0; ix < types.size (); ix++) - { - const tdesc_type_up &type1 = types[ix]; - const tdesc_type_up &type2 = other.types[ix]; - - if (type1 != type2 && *type1 != *type2) - return false; - } - - return true; - } - - bool operator!= (const tdesc_feature &other) const - { - return !(*this == other); - } -}; - -typedef std::unique_ptr tdesc_feature_up; - /* A target description. */ struct target_desc : tdesc_element @@ -1358,20 +1224,6 @@ tdesc_use_registers (struct gdbarch *gdbarch, tdesc_remote_register_number); set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p); } - - -/* See common/tdesc.h. */ - -void -tdesc_create_reg (struct tdesc_feature *feature, const char *name, - int regnum, int save_restore, const char *group, - int bitsize, const char *type) -{ - tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore, - group, bitsize, type); - - feature->registers.emplace_back (reg); -} /* See common/tdesc.h. */