From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2054.outbound.protection.outlook.com [40.107.93.54]) by sourceware.org (Postfix) with ESMTPS id D552B3858025 for ; Mon, 17 Jan 2022 12:44:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D552B3858025 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aubbC9A1Qs/zXQRmMni7TpQfl88Tklwcl7jphrNThFJhvUbb+dh2Hf6hjLhR4CCFOQcLFUKoL4F6esq+XOgt4cBlOlnwhC1kCl72eH7ToEy4Bp6EqvmbbK21ZT3Ui023NIZM34FOSXnXUl33AZhBGJ/Di+nrzjVbseYJCjkbfYIsCjhQAeyy73t2AJl6acAfztG2eXYC4kb5Une0iWZDOhmG7CslQuhL937zYF1QSN0DBD/B0Du/qEYv+TlhVFeaecrA5JnKwXxPy9HopI2Nt+M1HkRxQzvk64wR96R2prsfptcgiZsR+DkGB1lbuq0oA2c3Ur429Bl85iL6qtB7QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z3RRCFl3GOxbvXDMryRrd2rqNj3YeLRNDZMTOt8Waik=; b=Md7Jp3IBl6ccGHcgHNc9bw/FDp9fjMWb+feONKX0LHM7UtIjbn7fGQeZBsNigMgpaaAD7qIJeyLm1dQSaWgyrH5jBF0l0PXsksJ0SG6upzuiz1EruufiZvT6WhYEOUzs6LpO/5FSiqqtH3sGguQVbGfGxsYBF3MBGo//ArebziBRjK0O/1gXQhIcdFaqld9JXNOPZ4ArDX4UsR8A0ZWiuGZgJxfzUo5p1kGmvA4J0w8b90yP5NbpTG9JAXSfEyqoOu0jPMUaz67FnxIlwe5bIrBPzQohEIAhsBGZrbyeaGEaTpfGwUt0Sm6BL/Q9NWrpAPDJE6Qadw1yDpe+VDz8qQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=labware.com; dmarc=pass action=none header.from=labware.com; dkim=pass header.d=labware.com; arc=none Received: from DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) by DM5PR17MB1484.namprd17.prod.outlook.com (2603:10b6:3:145::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Mon, 17 Jan 2022 12:44:43 +0000 Received: from DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::7839:31f:2416:6ba5]) by DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::7839:31f:2416:6ba5%7]) with mapi id 15.20.4888.014; Mon, 17 Jan 2022 12:44:43 +0000 From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [PATCH 1/5] gdb/mi: introduce new class mi_command_builtin Date: Mon, 17 Jan 2022 12:44:21 +0000 Message-Id: <20220117124425.2658516-2-jan.vrany@labware.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220117124425.2658516-1-jan.vrany@labware.com> References: <20220117124425.2658516-1-jan.vrany@labware.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0006.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::11) To DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fa6926d-c656-481f-921f-08d9d9b722b7 X-MS-TrafficTypeDiagnostic: DM5PR17MB1484:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YOmW6DZYZSQ3550plVGrtBqMQ1+se82vevSVtj81H8eon+TzYtHH8N0PGCoRPj1YHwTQbUyNFtXHKhK/egLr+Y7UK1tfcBir1Zrt5JsqFM+G87eOQmpevdzJEl1AQaS9hlRt9nixff51U/G2RJ8AzrbOW4ZQu3bhHMHNQ1kTxhB5WHdnTJM6iTFJT8/dYdeURRR/vL3zjgsCw6UOMBk3Vo73fv1JiCShgMNR/vhLnu8mRMVTNpIOItsDYr0c2+sf0bk6RQlWOKIwCZz5Cx1zsvl7P/6uuPtlM8jF84yD7AfvFdWobF33d9bDogOJtcLe3QFyQ0lzVRW8tb1/h8mQbOPWObsZ6YAIXTYml61mSX1Pxs3MVd1edqTHZXgJ3VX4Sf9tShNElESLNoMNfhGsZhRs8JJYIIAA85EKqT9Zp8T1M9QJpcbXAWu2r6xTmsZ/aRQkStMprGu2zI2J1t60RDwbqKZHP/H+00kIRUOeNhvuUGUY5yva56FPH7LuEVtyCGGIUYDF05DqioFAzlUrYPjnlGbf8IZ78+Rd2/m8dtwBRMubDnIKnH7dt4TZIvMIDhX71itRsYFS4Ovjld+tfoBAmih+UOsX9iUFtzXJHxf3WoVPnQ7n6I2USgiLsU5fNDMr01giIW/3ZM36NyfbulqjTXh2KhJ6IvLY6Okq0wkBcGqklYCxmMyVYfWfs8ZvtkRSfbwlKk3wimC3IBz/ww== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR17MB3113.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(4326008)(26005)(6916009)(1076003)(2906002)(316002)(6506007)(36756003)(66946007)(6666004)(66476007)(66556008)(38100700002)(5660300002)(38350700002)(508600001)(186003)(107886003)(52116002)(86362001)(83380400001)(44832011)(6512007)(6486002)(8676002)(8936002)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TXZFGUkEgxLP6KEgq3igsPU3wfHGXGjD/j1mFO6DOrwmYMjLOajKTrQqy6Ek?= =?us-ascii?Q?o8RYundHpxShbk4Kfmuuer/maNi0iJnNn5xS3+qiFMilGkCoRB1vt9glkk0G?= =?us-ascii?Q?GlUAJNvAg64Rk4TP3y8nt/8ouOXRzlDxNntrWRi4/idSqklu534P8TOCUe8J?= =?us-ascii?Q?MkQ/gC912WzbPpd65Te0ojhxrKijedr3DSEkhLpLzBMwcJFsTQs60D6G8U+3?= =?us-ascii?Q?ZtM5aAoNhQQaH2Sa73TDtdhP6pWr2YhF2X48OwgUqCI64q+Q98tSjqbth1an?= =?us-ascii?Q?sXNn0KxIY9btibO5nmos0+DF2TMKxzCpsE8Jpo22f8IyD/J71dO1tcTenxga?= =?us-ascii?Q?yjBgaUx210D/wloS1M09RYyx9vtq+gtFZ/F1OgMCigoBXKauIrctT6PN1+zE?= =?us-ascii?Q?TTAckqR5kPhZyWxlYCc8GBdhO13WXXzSLS6E9jhwuowwFkacp5PjH/t39gma?= =?us-ascii?Q?n791DW5rwIiJq7DG7P4a89CHR7+aDu2pWdB5G0dKw93lFzeDNIYlgeGKzJKR?= =?us-ascii?Q?0WaEVgHbQQKJNkdrIp024F87s67K6XFZqS2/xkFx8HF/HqPKCk7FsHMErt4t?= =?us-ascii?Q?xezngzDIDOnMMqXe8yn5qznCUs9/e0P6ro4FrqT2KiEXipFWL+ZLDFq/zyS7?= =?us-ascii?Q?VT5KUlyp4fQvWiiCMzb4kcDIkjutn/Y5AW4J25LwwpLtBkoVE7DR1qO93+SX?= =?us-ascii?Q?XK4FavqQSaJDia/RIuWnl2wNw1bntTtAnS1CmvSU0+LpGNLFbJDWAqka537Y?= =?us-ascii?Q?jAi3UG1f/+ZZMrFU1aeQLl1iDTwxD1mq8hm8cxnYXbELulDf192wnuk1wZe/?= =?us-ascii?Q?k9Lop9nExyvkdCfpgiVOewbfgs7HCAC/FvYU14u44e7qEbXQ8J72WMzX7a7F?= =?us-ascii?Q?PvVHHfITF76E0q/KVPG42cfQN030YHEZPGDGLS6+/lMpntZmgbRoOjwcD+/c?= =?us-ascii?Q?BjmQS9CViOLFEuiFdQ3DacwOZ4mEQCaUah+g1CYlwy39E98iCMhzoxB9GSjv?= =?us-ascii?Q?FogII8100wXcMjEhu0Vy6MiHRDSvUH2+dW5Mh2/hGcTPitup1bmZPwToAYVN?= =?us-ascii?Q?0OZ4XLLOv+YDK2txBJstFvq0n79lfSEIY2wjfl3QJSUbiB4p0FTTvQogAfDW?= =?us-ascii?Q?jvghpppz9IbxqS2RRIkoCD+sCXW/Lt4UdDJy96oAUB3ojG9uc5XGYnBKAr1k?= =?us-ascii?Q?lAxYdIa+swRfO7476oMpYsqbedo+4curY5/z4B8joy4NBkGEV3zbcb9FgiGG?= =?us-ascii?Q?4GtajuSyF4pHXJFe/4HYa6/UE7mO6soqOGdrU7vKvJ8akdf8lUIOxz0/r2Gl?= =?us-ascii?Q?9j7TdWApOsTRgA56QXPNMsvajtHKv/NPOsQ1FWqo/2JV0XwCXLaLZkdSfYP6?= =?us-ascii?Q?atOxQx8i6JdHiBECHomucm9s4WD35YfELkn7UOLDG8RMHtLZrPZk32Rz7Hr6?= =?us-ascii?Q?mP2/qlVZZO0DY9R+9LUoGoQmFKqb2WFyAGa4E9eVNUpSyjVVpKdppoxG1xEv?= =?us-ascii?Q?hLUUvPiMqc6oTwK6EW5/fTr1uT3ZFN2rku3Eng0ROEXGIKN00orblzX0D+/L?= =?us-ascii?Q?2mtMSpk48XM/33+AMPplAmM5VJBt2xEb95TzHyGsScYGS8s01VnTUb9wyd/Q?= =?us-ascii?Q?JNmvfE6HXz/Q5gLkDWmxtO8=3D?= X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fa6926d-c656-481f-921f-08d9d9b722b7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR17MB3113.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2022 12:44:43.4959 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: clEcVE5jYFkA/nNDSwKiWlr40+Yx8VgeTZ/LLLGZFeHCpCXPDyFP2tCgU1BJgnKXUvQVdHbVGtIDGQGSz2mjqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR17MB1484 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 12:44:46 -0000 The motivation for this commit is that GDB/MI commands have their names statically allocated whereas Python-based commands (that will be introduced in later) will have their name dynamically allocated. To support this, this commit introduces new abstract class `mi_command_builtin` that allows for its name to be statically allocated. Future Python-based commands will hold onto dynamically allocated std::string. --- gdb/mi/mi-cmds.c | 43 ++++++++++++++++++++++++++++++------------- gdb/mi/mi-cmds.h | 14 +++++--------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index cd7cabdda9b..57fe32c1cc6 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -34,16 +34,42 @@ using mi_command_up = std::unique_ptr; static std::map mi_cmd_table; +/* The abstract base class for all built-in MI command types. */ + +struct mi_command_builtin : public mi_command +{ + /* Constructor. NAME is the name of this MI command, excluding any + leading dash, that is the initial string the user will enter to run + this command. For SUPPRESS_NOTIFICATION see mi_command + constructor, FUNC is the function called from do_invoke, which + implements this MI command. */ + mi_command_builtin (const char *name, int *suppress_notification) + : mi_command (suppress_notification), + m_name (name) + { + gdb_assert (m_name != nullptr && m_name[0] != '\0' && m_name[0] != '-'); + } + + virtual const char *name () const override + { + return m_name; + } + +private: + /* The name of the command. */ + const char *m_name; +}; + /* MI command with a pure MI implementation. */ -struct mi_command_mi : public mi_command +struct mi_command_mi : public mi_command_builtin { /* Constructor. For NAME and SUPPRESS_NOTIFICATION see mi_command constructor, FUNC is the function called from do_invoke, which implements this MI command. */ mi_command_mi (const char *name, mi_cmd_argv_ftype func, int *suppress_notification) - : mi_command (name, suppress_notification), + : mi_command_builtin (name, suppress_notification), m_argv_function (func) { gdb_assert (func != nullptr); @@ -72,7 +98,7 @@ struct mi_command_mi : public mi_command /* MI command implemented on top of a CLI command. */ -struct mi_command_cli : public mi_command +struct mi_command_cli : public mi_command_builtin { /* Constructor. For NAME and SUPPRESS_NOTIFICATION see mi_command constructor, CLI_NAME is the name of a CLI command that should be @@ -82,7 +108,7 @@ struct mi_command_cli : public mi_command false, nullptr is send to CLI_NAME as its argument string. */ mi_command_cli (const char *name, const char *cli_name, bool args_p, int *suppress_notification) - : mi_command (name, suppress_notification), + : mi_command_builtin (name, suppress_notification), m_cli_name (cli_name), m_args_p (args_p) { /* Nothing. */ } @@ -159,15 +185,6 @@ add_mi_cmd_cli (const char *name, const char *cli_name, int args_p, /* See mi-cmds.h. */ -mi_command::mi_command (const char *name, int *suppress_notification) - : m_name (name), - m_suppress_notification (suppress_notification) -{ - gdb_assert (m_name != nullptr && m_name[0] != '\0'); -} - -/* See mi-cmds.h. */ - void mi_command::invoke (struct mi_parse *parse) const { diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index 2a93a9f5476..94ecb271d48 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -143,12 +143,12 @@ extern mi_cmd_argv_ftype mi_cmd_complete; struct mi_command { - /* Constructor. NAME is the name of this MI command, excluding any - leading dash, that is the initial string the user will enter to run - this command. The SUPPRESS_NOTIFICATION pointer is a flag which will + /* Constructor. The SUPPRESS_NOTIFICATION pointer is a flag which will be set to 1 when this command is invoked, and reset to its previous value once the command invocation has completed. */ - mi_command (const char *name, int *suppress_notification); + mi_command (int *suppress_notification) + : m_suppress_notification (suppress_notification) + {} /* Destructor. */ virtual ~mi_command () = default; @@ -156,8 +156,7 @@ struct mi_command /* Return the name of this command. This is the command that the user will actually type in, without any arguments, and without the leading dash. */ - const char *name () const - { return m_name; } + virtual const char *name () const = 0; /* Execute the MI command. Can throw an exception if something goes wrong. */ @@ -180,9 +179,6 @@ struct mi_command then this function returns an empty gdb::optional. */ gdb::optional> do_suppress_notification () const; - /* The name of the command. */ - const char *m_name; - /* Pointer to integer to set during command's invocation. */ int *m_suppress_notification; }; -- 2.30.2