From patchwork Tue Apr 10 14:33:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 26669 Received: (qmail 53115 invoked by alias); 10 Apr 2018 14:34:13 -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 53003 invoked by uid 89); 10 Apr 2018 14:34:12 -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, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= 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:06 +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:54 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v5 3/8] Commonise tdesc types Date: Tue, 10 Apr 2018 15:33:32 +0100 Message-Id: <20180410143337.71768-4-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: 08c53702-f643-41fb-d890-08d59ef01672 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:NNG+eW9MCsDxdx7T6PMDHUDUPIjwQcMaxTbsXbX36PHJTszSk1GXA0B+/rNq75bRwVUU1RCfoiI58nkQmaYmzQYCRcM2bbsXVltUpndYKX+OxIoVX0Mwh4u086lbdFQY97B1GH9v89qdt0KUNgrHmiFd4Llr6Yyr31TciVt7rJ+iNkNl/Ufgtil63mE/tH654/AdWijwBPeDDHx2+pWKfjiZOMzrC4u7nrnBnOvdVY0dXftNdStzFJhqnOayCYck; 25:zTa0+ITohzcQ17N3oPNTTnf5nmNg61ef18oXYmVh1yikMCILCvYyxrF1ueVrJNB1pOSeLuIiefvP787BhGmKoeI8ugD7hsJgXmlDxiWpXmHm60Fyl7htQjNl9+MgDU+x8azlSR/z8+mfyWKgR2ja+jXGbq05oBptlxOK+1GRHKWHTQLvBbmDAk//GAS7kKnpUV47Rohys10pxBvKLv1t2U88A2ic9C063FOvbiZur6MqWJkHptgs4xiS1jNzCQoWAfq5kQmE98UMe/hhuu789VbgYjBRiKQ4+sP2RugqFxxvwW2V5gReDoGXjdTIRKQtJ5BazTFaHAzYF+ufsuEY2g==; 31:zJVvydW8R9zihE7to3bQzNj6vGihMdxVTWuV7Jht8J9Sd/NCTOXroLArjNxnwpMh9nrJbXA9BbwwDHSWvqzsghZLfz5kf4QR8OEDCkVfzaK4Tg7iEScSUNvso+cK1D+IkQN0I5EH72HRt1ENt5AuukQiHWEy6Aoc/u/X6WqLyt226++7gJ87c9WlkV8H8Da/yWNBdtoPsQfJet99WJzficUul1fulPSHVaEuoR9PFVM= X-MS-TrafficTypeDiagnostic: HE1PR0802MB2138: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 20:dGXGqSSC4i0rprGiTGVGIRKHgAVl2IgzeeWvQLHe42reNOEBtUt/gAPGAD9hI1XF+IxWIV6SKtuXXELQM4q8QcogDn1TW7Y6bXeKp+oyfi3JClsM/0WYK7r+r0+1wYYU7xO0rJJ7m7akM5qgZwxXq3PNGyV2c3ac83OtA5gji6k=; 4:psUm/HQsMf/rI36dd3yw3QiYlQGZZ2zyNuHaf+U7XsqUXHZtU+tovGvEaV058+9FDyRDWVqpmCUh+CCU4OxnAdUxiKBV9na3f1/MmnfzovyaNHJlqEH5iocH4iaSb/QK+X0CGtnbtInIuV9mpcPKHH94NuI643f8i31TraGRK1udEcf1mgAgDcvLXB+Ky+NGw2fq5XqY/oD3jxaYsTDhnDkUCFS1x3vgxw8Im/Fl2laHiMNBEHekCyTufEMjKJBC7zAxZ+QFFOVEL6cMwuZYXNUQB7l3bqR7uXWdmNWE6LcHUYHblJMWAwvBimnSbtB/Pud5uP/QFt+bVyCwG2Wsuv+687ZRn9XHOqymBXAf45c= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(131327999870524); 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)(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); 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:ci0eH1Qr+MrIDlT8K73dhVYK3nDZih/c+EC1oeO?= =?us-ascii?Q?1GIx7bFL20Q7XrSPZS44df3qxzqc2b9+phU2lyCTgbPrjiT3zl/ozIVJPndI?= =?us-ascii?Q?VBcBzSf3c/oRNU+WzjAKD5MCkbP6lN81RNtgEgFD0f0h+XvqtIrGODVBsUNB?= =?us-ascii?Q?V3Wz7VnFLun+bs9suacljfSeJFSkXyxGyU1dCAQHYUvXLQX5Nn2r3DcWM26Q?= =?us-ascii?Q?tBX9V8xBgrQrXkgu0FgokQaVLuh5Uc8esjGJtep7sIuPPs4B6aLy1E4WQBTk?= =?us-ascii?Q?/c36UIjS6MvGdiisdcGrTvVLkbhQ0E4ES+jjJocPUrN04MeHXlqD6hb/eiZZ?= =?us-ascii?Q?66c5Hoegwq4VZTWRhO70ftKWcQ0zqpgjox4zEyBOVXpmxatnbUB58GBRaSGN?= =?us-ascii?Q?aRcFgRAG3fEilsXINhj7Y3uWrNsoEzJSrd1QRHL9xlKrGIcDWH2cZb1Zqwsz?= =?us-ascii?Q?puSOAWxkcWioyqN+U/MLB3hzUgXgufR9LVYEAPrIxS81+JZWZzTRAGR45Xu2?= =?us-ascii?Q?diHtc+tDExiVQhpGWWidCzjAwbMuhZGxY4pqJumZ1/ju9uY/QxPlMXlKuFmt?= =?us-ascii?Q?QWHLWpyPjB8m6FRM0WwYT5MbiqZbXcsQPuJ3XnsMWto3oLOkNrGGbM2PeYMQ?= =?us-ascii?Q?sSWht5x8efF/XCIYBUpNIyyNnqZOHXd5UaZ+jFV80UxLl4bY5UCzppMSkWrU?= =?us-ascii?Q?VVSM/QyX+aNqJ+uUhL1ogDO9tOnnPDXnLaIIjBq+JNpADGYisA8T1wZnqUmF?= =?us-ascii?Q?fn9xW0Kztn5WplaLvOjtr//wP10fD62OM6D4x9o6W1RJ5G48f+qiuxh3nmUO?= =?us-ascii?Q?zb4Kvfg7GF/z7zJSJl1uUUlwuhYjVFeRxO1ceqzIPBa/DIpQ/nTzdomdBtXm?= =?us-ascii?Q?bTxfPgEjwgOCooByAYr+xF4dcGltw6Yjjd+Pi0qL/J3Q5G+K0TodwBOF3nsG?= =?us-ascii?Q?/CNsyN1vWhA3n2xtdcnlWNQqQb0C/ZI5fam4Ax8OK/EG6JGlzHVQMiv3zBcR?= =?us-ascii?Q?fxG4pbR7iixkdrxmXOxFP5Rh9WoSxP3kme0hZq+YSnlB2R+HfLyE0XKfwqkP?= =?us-ascii?Q?e71e2PGTqYYYkvCeIcAuPOk4ko2EsJFtYiHbICnJ9CXBU2rbGl/S4dPKNezN?= =?us-ascii?Q?8aGOeR/1GHFn+vsePgzz9mbOEZr/t+qXuHPchPaBJ6pzh622WyAjLxPJDfxc?= =?us-ascii?Q?YM3jE1iApXXp6rm9QlaoUyyNdU6ny6yg5Zj+MDH8shckNrwDrIIga5u1aJqm?= =?us-ascii?Q?Pd9nouplKTm4QMBMbmtd6XvBrKWWpO8Zd+HoxZt4wEmKtEAgMXO19FfrDKE+?= =?us-ascii?Q?oEQ=3D=3D?= X-Microsoft-Antispam-Message-Info: tw9Q8c3cEvWX8eA2dUC2q5geYGJzfrGCxbOGVZxUjrVtOJic/lqC22ka5e/L1s4U8WPt2exVX2SVEUbeDujC0mXC3pnY9LX+lRfloAhjbKUw8vSJ/kxRyPKxYMJaSH/MZzk7zabaRvbtsCHziJuOLUyunUBEPASZNdCqEgh+ulohtjagcjocfUx8WCU0NQtp X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 6:CSGUPlrE93RT7S81JncoUsLLoMuwBUexC8BEOxeLH3xDgM8yOnrIgFgX44kZXMqKx0DyFoxyvKYxvs5Tq6e5s5kJNifiz1eLtPMUSZmlgS0YtDOImCndriCo0FMRbeU0w/POez2jX0vfCgH9RZYZJJm3mcSur+E2ZdgDtVDbGjO3B2zO0Is0AqEIW6gQldBE0c8fMDucik9YWl4Bje0F/dIPUvYFYOpDzEY7awEDENbU8jPQbBv4eW1NZeKuEKhXrMNWJyh7E82rCdacElxH7WysEdGOj1TlL35wlvORYWlCRTfrfbGxZn9egX9UNTQjP0zSrejhI8LXDgM5gNo8LRfhdtdj3trf+/Vk9q9m/XdlazIYvTzh8FCQ4BcKDKLAZxgWeu+m490GoZAV48eiVQuUg7DB9W/IM3losGtEXewG3dK2fjUQM/7vq1obM3QEh6MBsZgTehJV49wzIzydxw==; 5:2PbIpqdz8qpIP+JvTOhKeopoE5m7g7BhEoaryTG7oI5urW9rk5DdpEKLqdtKrc7voR6lUQSFPNj5DuVq2/cxxTXZLDjmkW3g5pMwl1RE+PsK4ogee4Mgp3X/xjpdsVVLBHoLjT2wG1U1x7g98cB+hn01eAlNP7Rx9dmS2afPBlQ=; 24:zOMeTfk+JuyUImgS63HPtrFAMpfWyLnaSy3ieH6LYINEruOOV7tn/EMcpctQuLS6/cajmPGFOFvHVOLO79igZRHjR2/fOKyt/nG80UBcX98= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2138; 7:yeG7Gz0T83pbg5pazWoMOjIhi4pGWrXgxEiebPZOs1mQe1PHQF+5Ulyx1WVY+GupKc4r2RRlKQBQi+55pg/mrnx+XveEGyS2RCcfo/Nyz9bh51gQ9We800Wpwqf6IWs7Cgpd5YOkOr3IrCaYyUrntvDKY8x8my6C3cqyaMidoOzo/+tPWd1Tp9FprCQkDZFpiQ27NDmLeFe6Hrqca/V5A/S4ECJ9l2HXa/DT2PNwZS1TNlXglGepmE75vTifXKA6 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2018 14:33:54.4695 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08c53702-f643-41fb-d890-08d59ef01672 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 moves all the various tdesc types to common code. It also commonises all the tdesc_ functions that are stubbed out in gdbserver. This is a lot of code to move across, but it is the simplest way of getting gdbserver to retain the target description information. With this patch, gdb and gdbserver will now parse a target description in the same way. Identical to V4 version, except for additional declarations moved from common/tdesc.h. Alan. 2018-04-10 Alan Hayward gdb/ * common/tdesc.c (tdesc_predefined_type): Move to here. (tdesc_named_type): Likewise. (tdesc_create_vector): Likewise. (tdesc_create_struct): Likewise. (tdesc_set_struct_size): Likewise. (tdesc_create_union): Likewise. (tdesc_create_flags): Likewise. (tdesc_create_enum): Likewise. (tdesc_add_field): Likewise. (tdesc_add_typed_bitfield): Likewise. (tdesc_add_bitfield): Likewise. (tdesc_add_flag): Likewise. (tdesc_add_enum_value): Likewise. * common/tdesc.h (struct tdesc_type_builtin): Likewise. (struct tdesc_type_vector): Likewise. (struct tdesc_type_field): Likewise. (struct tdesc_type_with_fields): Likewise. (tdesc_create_enum): Add declaration. (tdesc_add_typed_bitfield): Likewise. (tdesc_add_enum_value): Likewise. * target-descriptions.c (tdesc_type_field): Move from here. (tdesc_type_builtin): Likewise. (tdesc_type_vector): Likewise. (tdesc_type_with_fields): Likewise. (tdesc_predefined_types): Likewise. (tdesc_named_type): Likewise. (tdesc_create_vector): Likewise. (tdesc_create_struct): Likewise. (tdesc_set_struct_size): Likewise. (tdesc_create_union): Likewise. (tdesc_create_flags): Likewise. (tdesc_create_enum): Likewise. (tdesc_add_field): Likewise. (tdesc_add_typed_bitfield): Likewise. (tdesc_add_bitfield): Likewise. (tdesc_add_flag): Likewise. (tdesc_add_enum_value): Likewise. * gdb/target-descriptions.h (tdesc_create_enum): Likewise. (tdesc_add_typed_bitfield): Likewise. (tdesc_add_enum_value): Likewise. gdbserver/ * tdesc.c (tdesc_create_flags): Remove. (tdesc_add_flag): Likewise. (tdesc_named_type): Likewise. (tdesc_create_union): Likewise. (tdesc_create_struct): Likewise. (tdesc_create_vector): Likewise. (tdesc_add_bitfield): Likewise. (tdesc_add_field): Likewise. (tdesc_set_struct_size): Likewise. --- gdb/common/tdesc.c | 199 +++++++++++++++++++++++++++++++++++ gdb/common/tdesc.h | 82 +++++++++++++++ gdb/gdbserver/tdesc.c | 68 ------------ gdb/target-descriptions.c | 258 ---------------------------------------------- gdb/target-descriptions.h | 8 -- 5 files changed, 281 insertions(+), 334 deletions(-) diff --git a/gdb/common/tdesc.c b/gdb/common/tdesc.c index eefb2016f6..b9e9ddb3fa 100644 --- a/gdb/common/tdesc.c +++ b/gdb/common/tdesc.c @@ -34,6 +34,28 @@ tdesc_reg::tdesc_reg (struct tdesc_feature *feature, const std::string &name_, tdesc_type = tdesc_named_type (feature, type.c_str ()); } +/* Predefined types. */ +static tdesc_type_builtin tdesc_predefined_types[] = +{ + { "bool", TDESC_TYPE_BOOL }, + { "int8", TDESC_TYPE_INT8 }, + { "int16", TDESC_TYPE_INT16 }, + { "int32", TDESC_TYPE_INT32 }, + { "int64", TDESC_TYPE_INT64 }, + { "int128", TDESC_TYPE_INT128 }, + { "uint8", TDESC_TYPE_UINT8 }, + { "uint16", TDESC_TYPE_UINT16 }, + { "uint32", TDESC_TYPE_UINT32 }, + { "uint64", TDESC_TYPE_UINT64 }, + { "uint128", TDESC_TYPE_UINT128 }, + { "code_ptr", TDESC_TYPE_CODE_PTR }, + { "data_ptr", TDESC_TYPE_DATA_PTR }, + { "ieee_single", TDESC_TYPE_IEEE_SINGLE }, + { "ieee_double", TDESC_TYPE_IEEE_DOUBLE }, + { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT }, + { "i387_ext", TDESC_TYPE_I387_EXT } +}; + void tdesc_feature::accept (tdesc_element_visitor &v) const { v.visit_pre (this); @@ -79,6 +101,36 @@ bool tdesc_feature::operator== (const tdesc_feature &other) const return true; } +/* Lookup a predefined type. */ + +static struct tdesc_type * +tdesc_predefined_type (enum tdesc_type_kind kind) +{ + for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) + if (tdesc_predefined_types[ix].kind == kind) + return &tdesc_predefined_types[ix]; + + gdb_assert_not_reached ("bad predefined tdesc type"); +} + +/* See common/tdesc.h. */ + +struct tdesc_type * +tdesc_named_type (const struct tdesc_feature *feature, const char *id) +{ + /* First try target-defined types. */ + for (const tdesc_type_up &type : feature->types) + if (type->name == id) + return type.get (); + + /* Next try the predefined types. */ + for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) + if (tdesc_predefined_types[ix].name == id) + return &tdesc_predefined_types[ix]; + + return NULL; +} + /* See common/tdesc.h. */ void @@ -91,3 +143,150 @@ tdesc_create_reg (struct tdesc_feature *feature, const char *name, feature->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) +{ + tdesc_type_vector *type = new tdesc_type_vector (name, field_type, count); + feature->types.emplace_back (type); + + return type; +} + +/* See common/tdesc.h. */ + +tdesc_type_with_fields * +tdesc_create_struct (struct tdesc_feature *feature, const char *name) +{ + tdesc_type_with_fields *type + = new tdesc_type_with_fields (name, TDESC_TYPE_STRUCT); + feature->types.emplace_back (type); + + return type; +} + +/* See common/tdesc.h. */ + +void +tdesc_set_struct_size (tdesc_type_with_fields *type, int size) +{ + gdb_assert (type->kind == TDESC_TYPE_STRUCT); + gdb_assert (size > 0); + type->size = size; +} + +/* See common/tdesc.h. */ + +tdesc_type_with_fields * +tdesc_create_union (struct tdesc_feature *feature, const char *name) +{ + tdesc_type_with_fields *type + = new tdesc_type_with_fields (name, TDESC_TYPE_UNION); + feature->types.emplace_back (type); + + return type; +} + +/* See common/tdesc.h. */ + +tdesc_type_with_fields * +tdesc_create_flags (struct tdesc_feature *feature, const char *name, + int size) +{ + gdb_assert (size > 0); + + tdesc_type_with_fields *type + = new tdesc_type_with_fields (name, TDESC_TYPE_FLAGS, size); + feature->types.emplace_back (type); + + return type; +} + +/* See common/tdesc.h. */ + +tdesc_type_with_fields * +tdesc_create_enum (struct tdesc_feature *feature, const char *name, + int size) +{ + gdb_assert (size > 0); + + tdesc_type_with_fields *type + = new tdesc_type_with_fields (name, TDESC_TYPE_ENUM, size); + feature->types.emplace_back (type); + + return type; +} + +/* See common/tdesc.h. */ + +void +tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, + struct tdesc_type *field_type) +{ + gdb_assert (type->kind == TDESC_TYPE_UNION + || type->kind == TDESC_TYPE_STRUCT); + + /* Initialize start and end so we know this is not a bit-field + when we print-c-tdesc. */ + type->fields.emplace_back (field_name, field_type, -1, -1); +} + +/* See common/tdesc.h. */ + +void +tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name, + int start, int end, struct tdesc_type *field_type) +{ + gdb_assert (type->kind == TDESC_TYPE_STRUCT + || type->kind == TDESC_TYPE_FLAGS); + gdb_assert (start >= 0 && end >= start); + + type->fields.emplace_back (field_name, field_type, start, end); +} + +/* See common/tdesc.h. */ + +void +tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, + int start, int end) +{ + struct tdesc_type *field_type; + + gdb_assert (start >= 0 && end >= start); + + if (type->size > 4) + field_type = tdesc_predefined_type (TDESC_TYPE_UINT64); + else + field_type = tdesc_predefined_type (TDESC_TYPE_UINT32); + + tdesc_add_typed_bitfield (type, field_name, start, end, field_type); +} + +/* See common/tdesc.h. */ + +void +tdesc_add_flag (tdesc_type_with_fields *type, int start, + const char *flag_name) +{ + gdb_assert (type->kind == TDESC_TYPE_FLAGS + || type->kind == TDESC_TYPE_STRUCT); + + type->fields.emplace_back (flag_name, + tdesc_predefined_type (TDESC_TYPE_BOOL), + start, start); +} + +/* See common/tdesc.h. */ + +void +tdesc_add_enum_value (tdesc_type_with_fields *type, int value, + const char *name) +{ + gdb_assert (type->kind == TDESC_TYPE_ENUM); + type->fields.emplace_back (name, + tdesc_predefined_type (TDESC_TYPE_INT32), + value, -1); +} diff --git a/gdb/common/tdesc.h b/gdb/common/tdesc.h index b501dfa995..7f4222b653 100644 --- a/gdb/common/tdesc.h +++ b/gdb/common/tdesc.h @@ -189,6 +189,72 @@ struct tdesc_type : tdesc_element 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) + : tdesc_type (name, kind) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } +}; + +/* tdesc_type for vector types. */ + +struct tdesc_type_vector : tdesc_type +{ + tdesc_type_vector (const std::string &name, tdesc_type *element_type_, + int count_) + : tdesc_type (name, TDESC_TYPE_VECTOR), + element_type (element_type_), count (count_) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } + + struct tdesc_type *element_type; + int count; +}; + +/* A named type from a target description. */ + +struct tdesc_type_field +{ + tdesc_type_field (const std::string &name_, tdesc_type *type_, + int start_, int end_) + : name (name_), type (type_), start (start_), end (end_) + {} + + std::string name; + struct tdesc_type *type; + /* For non-enum-values, either both are -1 (non-bitfield), or both are + not -1 (bitfield). For enum values, start is the value (which could be + -1), end is -1. */ + int start, end; +}; + +/* tdesc_type for struct, union, flags, and enum types. */ + +struct tdesc_type_with_fields : tdesc_type +{ + tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind, + int size_ = 0) + : tdesc_type (name, kind), size (size_) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } + + std::vector fields; + int size; +}; + /* A feature from a target description. Each feature is a collection of other elements, e.g. registers and types. */ @@ -264,11 +330,23 @@ tdesc_type_with_fields *tdesc_create_flags (struct tdesc_feature *feature, const char *name, int size); +/* Return the created enum tdesc_type named NAME in FEATURE. */ +tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature, + const char *name, + int size); + /* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is its type. */ void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, struct tdesc_type *field_type); +/* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name, + and FIELD_TYPE is its type. */ +void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, + const char *field_name, + int start, int end, + struct tdesc_type *field_type); + /* Set the total length of TYPE. Structs which contain bitfields may omit the reserved bits, so the end of the last field may not suffice. */ @@ -285,6 +363,10 @@ void tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, void tdesc_add_flag (tdesc_type_with_fields *type, int start, const char *flag_name); +/* Add field with VALUE and NAME to the enum TYPE. */ +void tdesc_add_enum_value (tdesc_type_with_fields *type, int value, + const char *name); + /* Create a register in feature FEATURE. */ void tdesc_create_reg (struct tdesc_feature *feature, const char *name, int regnum, int save_restore, const char *group, diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index 1047949e6d..aca27ea3b0 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -177,71 +177,3 @@ tdesc_create_feature (struct target_desc *tdesc, const char *name, tdesc->features.emplace_back (new_feature); return new_feature; } - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_flags (struct tdesc_feature *feature, const char *name, - int size) -{ - return NULL; -} - -/* See common/tdesc.h. */ - -void -tdesc_add_flag (tdesc_type_with_fields *type, int start, - const char *flag_name) -{} - -/* See common/tdesc.h. */ - -struct tdesc_type * -tdesc_named_type (const struct tdesc_feature *feature, const char *id) -{ - return NULL; -} - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_union (struct tdesc_feature *feature, const char *id) -{ - return NULL; -} - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_struct (struct tdesc_feature *feature, const char *id) -{ - return NULL; -} - -/* See common/tdesc.h. */ - -struct tdesc_type * -tdesc_create_vector (struct tdesc_feature *feature, const char *name, - struct tdesc_type *field_type, int count) -{ - return NULL; -} - -void -tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, - int start, int end) -{} - -/* See common/tdesc.h. */ - -void -tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, - struct tdesc_type *field_type) -{} - -/* See common/tdesc.h. */ - -void -tdesc_set_struct_size (tdesc_type_with_fields *type, int size) -{ -} diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index a453eddec0..2782ffaab9 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -50,71 +50,6 @@ struct property std::string value; }; -/* A named type from a target description. */ - -struct tdesc_type_field -{ - tdesc_type_field (const std::string &name_, tdesc_type *type_, - int start_, int end_) - : name (name_), type (type_), start (start_), end (end_) - {} - - std::string name; - struct tdesc_type *type; - /* For non-enum-values, either both are -1 (non-bitfield), or both are - not -1 (bitfield). For enum values, start is the value (which could be - -1), end is -1. */ - int start, end; -}; - -struct tdesc_type_builtin : tdesc_type -{ - tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind) - : tdesc_type (name, kind) - {} - - void accept (tdesc_element_visitor &v) const override - { - v.visit (this); - } -}; - -/* tdesc_type for vector types. */ - -struct tdesc_type_vector : tdesc_type -{ - tdesc_type_vector (const std::string &name, tdesc_type *element_type_, int count_) - : tdesc_type (name, TDESC_TYPE_VECTOR), - element_type (element_type_), count (count_) - {} - - void accept (tdesc_element_visitor &v) const override - { - v.visit (this); - } - - struct tdesc_type *element_type; - int count; -}; - -/* tdesc_type for struct, union, flags, and enum types. */ - -struct tdesc_type_with_fields : tdesc_type -{ - tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind, - int size_ = 0) - : tdesc_type (name, kind), size (size_) - {} - - void accept (tdesc_element_visitor &v) const override - { - v.visit (this); - } - - std::vector fields; - int size; -}; - /* Convert a tdesc_type to a gdb type. */ static type * @@ -741,58 +676,6 @@ tdesc_feature_name (const struct tdesc_feature *feature) return feature->name.c_str (); } -/* Predefined types. */ -static tdesc_type_builtin tdesc_predefined_types[] = -{ - { "bool", TDESC_TYPE_BOOL }, - { "int8", TDESC_TYPE_INT8 }, - { "int16", TDESC_TYPE_INT16 }, - { "int32", TDESC_TYPE_INT32 }, - { "int64", TDESC_TYPE_INT64 }, - { "int128", TDESC_TYPE_INT128 }, - { "uint8", TDESC_TYPE_UINT8 }, - { "uint16", TDESC_TYPE_UINT16 }, - { "uint32", TDESC_TYPE_UINT32 }, - { "uint64", TDESC_TYPE_UINT64 }, - { "uint128", TDESC_TYPE_UINT128 }, - { "code_ptr", TDESC_TYPE_CODE_PTR }, - { "data_ptr", TDESC_TYPE_DATA_PTR }, - { "ieee_single", TDESC_TYPE_IEEE_SINGLE }, - { "ieee_double", TDESC_TYPE_IEEE_DOUBLE }, - { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT }, - { "i387_ext", TDESC_TYPE_I387_EXT } -}; - -/* Lookup a predefined type. */ - -static struct tdesc_type * -tdesc_predefined_type (enum tdesc_type_kind kind) -{ - for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) - if (tdesc_predefined_types[ix].kind == kind) - return &tdesc_predefined_types[ix]; - - gdb_assert_not_reached ("bad predefined tdesc type"); -} - -/* See common/tdesc.h. */ - -struct tdesc_type * -tdesc_named_type (const struct tdesc_feature *feature, const char *id) -{ - /* First try target-defined types. */ - for (const tdesc_type_up &type : feature->types) - if (type->name == id) - return type.get (); - - /* Next try the predefined types. */ - for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++) - if (tdesc_predefined_types[ix].name == id) - return &tdesc_predefined_types[ix]; - - return NULL; -} - /* Lookup type associated with ID. */ struct type * @@ -1227,147 +1110,6 @@ tdesc_use_registers (struct gdbarch *gdbarch, /* See common/tdesc.h. */ -struct tdesc_type * -tdesc_create_vector (struct tdesc_feature *feature, const char *name, - struct tdesc_type *field_type, int count) -{ - tdesc_type_vector *type = new tdesc_type_vector (name, field_type, count); - feature->types.emplace_back (type); - - return type; -} - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_struct (struct tdesc_feature *feature, const char *name) -{ - tdesc_type_with_fields *type - = new tdesc_type_with_fields (name, TDESC_TYPE_STRUCT); - feature->types.emplace_back (type); - - return type; -} - -/* See common/tdesc.h. */ - -void -tdesc_set_struct_size (tdesc_type_with_fields *type, int size) -{ - gdb_assert (type->kind == TDESC_TYPE_STRUCT); - gdb_assert (size > 0); - type->size = size; -} - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_union (struct tdesc_feature *feature, const char *name) -{ - tdesc_type_with_fields *type - = new tdesc_type_with_fields (name, TDESC_TYPE_UNION); - feature->types.emplace_back (type); - - return type; -} - -/* See common/tdesc.h. */ - -tdesc_type_with_fields * -tdesc_create_flags (struct tdesc_feature *feature, const char *name, - int size) -{ - gdb_assert (size > 0); - - tdesc_type_with_fields *type - = new tdesc_type_with_fields (name, TDESC_TYPE_FLAGS, size); - feature->types.emplace_back (type); - - return type; -} - -tdesc_type_with_fields * -tdesc_create_enum (struct tdesc_feature *feature, const char *name, - int size) -{ - gdb_assert (size > 0); - - tdesc_type_with_fields *type - = new tdesc_type_with_fields (name, TDESC_TYPE_ENUM, size); - feature->types.emplace_back (type); - - return type; -} - -/* See common/tdesc.h. */ - -void -tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, - struct tdesc_type *field_type) -{ - gdb_assert (type->kind == TDESC_TYPE_UNION - || type->kind == TDESC_TYPE_STRUCT); - - /* Initialize start and end so we know this is not a bit-field - when we print-c-tdesc. */ - type->fields.emplace_back (field_name, field_type, -1, -1); -} - -void -tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name, - int start, int end, struct tdesc_type *field_type) -{ - gdb_assert (type->kind == TDESC_TYPE_STRUCT - || type->kind == TDESC_TYPE_FLAGS); - gdb_assert (start >= 0 && end >= start); - - type->fields.emplace_back (field_name, field_type, start, end); -} - -/* See common/tdesc.h. */ - -void -tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, - int start, int end) -{ - struct tdesc_type *field_type; - - gdb_assert (start >= 0 && end >= start); - - if (type->size > 4) - field_type = tdesc_predefined_type (TDESC_TYPE_UINT64); - else - field_type = tdesc_predefined_type (TDESC_TYPE_UINT32); - - tdesc_add_typed_bitfield (type, field_name, start, end, field_type); -} - -/* See common/tdesc.h. */ - -void -tdesc_add_flag (tdesc_type_with_fields *type, int start, - const char *flag_name) -{ - gdb_assert (type->kind == TDESC_TYPE_FLAGS - || type->kind == TDESC_TYPE_STRUCT); - - type->fields.emplace_back (flag_name, - tdesc_predefined_type (TDESC_TYPE_BOOL), - start, start); -} - -void -tdesc_add_enum_value (tdesc_type_with_fields *type, int value, - const char *name) -{ - gdb_assert (type->kind == TDESC_TYPE_ENUM); - type->fields.emplace_back (name, - tdesc_predefined_type (TDESC_TYPE_INT32), - value, -1); -} - -/* See common/tdesc.h. */ - struct tdesc_feature * tdesc_create_feature (struct target_desc *tdesc, const char *name, const char *xml) diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index fa554fddf6..3ba71b1add 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -209,14 +209,6 @@ void set_tdesc_property (struct target_desc *, const char *key, const char *value); void tdesc_add_compatible (struct target_desc *, const struct bfd_arch_info *); -tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature, - const char *name, - int size); -void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name, - int start, int end, - struct tdesc_type *field_type); -void tdesc_add_enum_value (tdesc_type_with_fields *type, int value, - const char *name); #if GDB_SELF_TEST namespace selftests {