From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2078.outbound.protection.outlook.com [40.107.220.78]) by sourceware.org (Postfix) with ESMTPS id C3A2A3857806 for ; Wed, 16 Mar 2022 15:09:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3A2A3857806 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OdgWXsXPOieNWZbra3bJWTDqWufwbrNskB5lo0/7fZHGQMgz2TOnJRhVKha2TLeMWsnNsgtMsVjX5pfb1DQ0Um1z8x7kZynHLg2LSL3fhS07qYL715K9WD5pftJKAso+AEX2mENka6bVmtt0aW0+zNtWGvY1QvuR+30IXG6x8P27kTi17ClSTDxxBPYnhJsnu+3UF5rMT8b1bp6bCurGGtcOBzR1hDlOtQp9uek29hQZqkcevfERYGBNTo5I9Sqy0GgsgF/oET2VCOpEo8vOufoyr36reS9u7d+6yfqk6AsWjH5G7QE49hde6VkOE/crt8rKO0AV2Z6G7mY0zSt0aw== 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=eu0t3RW4VQUBDyNOX0LJ007ZVvJ/T3I3DUnCy/AWYRg=; b=Mw6f4MfG9hl7+anGTA4LUD+0zZzDAFAoegMXLDKi5JMegmLtPHSf1fbuqfmXk6ybRVvxojeJBiJyMFRdUTirYczPv14jodq3+A4s9epl/XYKCHYU05GzcXVtid0f7IJadlnO9yJJZ9N4FywrBxRhX8ijkzOw0MIMGcpisCXHcnBOGE6LEzom8aiHCsPL1YnIAoBxKuXUG+zZb429udnz7FSCMrSP2yz8R0EC2xU+Z/YqAONcl8Vsm7qiZvty/m3vp18+kfntjV5zqFOmzS87DISSw9gBJf+hH3HNF++9EqpLSfXc72hKITo5MXwhLsla/4qRs53VUmUQaGUH+FoR/w== 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 CY4PR1701MB1829.namprd17.prod.outlook.com (2603:10b6:910:62::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.15; Wed, 16 Mar 2022 15:09:20 +0000 Received: from DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::b4e5:7f52:3fb8:ef7b]) by DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::b4e5:7f52:3fb8:ef7b%7]) with mapi id 15.20.5081.015; Wed, 16 Mar 2022 15:09:20 +0000 From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany , Andrew Burgess Subject: [pushed] gdb/mi: consistently notify user when GDB/MI client uses -thread-select Date: Wed, 16 Mar 2022 15:09:14 +0000 Message-Id: <20220316150914.1254897-1-jan.vrany@labware.com> X-Mailer: git-send-email 2.35.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0127.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:193::6) 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: a35efff5-a263-4eec-0f0b-08da075ef21d X-MS-TrafficTypeDiagnostic: CY4PR1701MB1829:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DI6nz5BvwxVG+QuhiR7xLjFWmkfbdKODiJNTlTaR56n0OnJec8+kOKiavJxIvKXjvzUvc4/gz0mJuEvGg62A6ds8slvfQGaU8/myrrjRZfX9H3zw8pyoQc1xCkxBQIbaLB4KtlLcQqSEeMm1BI3UjwMe8DlSPXOkLCj8n2xOqY0tkbe4HaZ8soPnPQhNGhQicXNIYAaYsHxM5yk0ovvGLQsIBM7swN8rbne4Dj/O2I/SjQC+c2hdjzaAfE8X7NzYceZeYC6KzSOYWPCoPuHnp5AjScUeNkIR/H+bRcqxqcYNNs6jqpmwiRDTkLF70D8GGJB/E4az7yRXLcHm+IwoJUBXEy0oM0jfdnNLZVGEHYo0NLScRQxtPbQzKalJgLUC+2s+vjilhMLFsxevkLSSK9SzILP0TqMFdh0KrIc5x6iLtQkGDYa8GIugQ318HPEx80zDKBE/8UKHZGqDlNGoRmpiGXzc5HaT3j0eonDSaHMYg1w34TZPqWGV6wuh8aiWU4JHNZLHz5hVQVusBW5w1LLRchhAm96PogFN5PAL2D24a34gQsrsk4WQUqwnBI29mhXZoATKSZPQDHV1gUZWGrl5f6FtWKZvcOKnzi3KjJGOf2QbCPgYGLNoBd6xvM9BXCVRa0aiYKnwCtWM1XZt6ZZg39qhxJFVmjpLAd2/M/u0LWb4hzAi1sZOZ1m7KR0c8NG+W9aDLnF8VyhDP/ecPx41uF8bWXJX0Ekk1zSuAxQ1W89UjCW1D+NQE1p1BfQt92yxQ+hNI/+VT3B5Ijw8eXngII5rPhFB2EaHC2YIjVawVRC9Y7Fd7NKcTQeLN/qR 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:(13230001)(366004)(2616005)(26005)(186003)(30864003)(44832011)(6916009)(1076003)(54906003)(316002)(36756003)(38350700002)(38100700002)(52116002)(6506007)(2906002)(966005)(6486002)(86362001)(4326008)(8676002)(6666004)(66476007)(66946007)(66556008)(8936002)(6512007)(83380400001)(508600001)(5660300002)(403724002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?UjlCG6EFnEYT6DB8pDmoMAqMpabHcPXurxuyNMfvviPkwUg18FtAExSbhqcu?= =?us-ascii?Q?QB42w2R57uq/rD7+KeORgpOIc1nqEgaLQdDZ5K6+7zgltBLdo6ekjVhf5b9d?= =?us-ascii?Q?jX7aiUyEAcSxqYyqOaqGuJG4Tj65mF7XLLSiCRaBH8gb1gldHyZCLclKVhkn?= =?us-ascii?Q?bstVAX6VlE+qum4ECJvBm8DxOT5XeW2K7KO9V0aj9ajlY+ehAUgh5dfyFN68?= =?us-ascii?Q?DiLuE69xeN/o6C1JYKQGMmXOuR0pZy5vAiqaTCPfX/aw3rQiQshB4iND7g6N?= =?us-ascii?Q?JfoRPsIr8p9KHCCsnNnTuRCN8w/9pHou6HVkZfymSIX97e/hkzCOM42nKh/m?= =?us-ascii?Q?TY101y78EzoimY0epbkXcEfyHxuXIoMRaoMK5mQoyQrI5Cx8RpVtEG+ZfRO2?= =?us-ascii?Q?H0IHCgfN4q/O6B2s8xhjITqUpyv8/Zhp7E5K/0xJnrzk6XSZtqUfFv2SHGG2?= =?us-ascii?Q?YwaGaCTJ0RtO0H8sztNYxpvq+VimNUBo7z60kD/9vHiyJuxEX+x9RAHpTDGR?= =?us-ascii?Q?bqWao5hMoOOu6R3sbqJiHZdkag8eJm5A0qOok7z1Vc5yjHWOQCBS4rf+6Hw+?= =?us-ascii?Q?opVHHJLxfHL1ZXG9zQE6FK/URAoS1bU/rpF4OZg+VnWpWuub5AEk0HATxN4k?= =?us-ascii?Q?OZp/LibhZgXh5st412NdaFlx9PvSrhRrp3mXYWXb5td9gg/9T6MppVDSMVoD?= =?us-ascii?Q?BvNExjFRhe3cQt6KduKKWtman+YhjfJH3IJitNi84tcnxd1aD2WEZp/FHOim?= =?us-ascii?Q?Sf/pDW7FePMM4gk1ath/B4RdczEiuaIVOQUERTFcKaxcV/ojO7OI3wnNkDTA?= =?us-ascii?Q?7bTVZ+F3n6EUP4cmuEq8RKXLu8ChqsYxGc/tLQ6cykRQmWEi28Y76f6nJfBN?= =?us-ascii?Q?guT7z0uhIwGngg/StRAP9vY6j0GojZ2kAiyJ76gmqRv94au0xKFRz4aC3Wi/?= =?us-ascii?Q?y3z5Kj6CgYWp4GwpfBhKn+BWZeajnXYZ78uIbb36rK+VeGwCkFDgZi9+R09x?= =?us-ascii?Q?QCRKTHR7OLgPfg2I2uu6RnXpYg+oM4jaEI5UjGLvjcJUTx0d7Bg2PTQzE2ZY?= =?us-ascii?Q?zmYhddnKUA/gktAN8MFqf8EGHW61a1zoqXsxB4/qAfP0W6RmgBa4ApRATuUy?= =?us-ascii?Q?YLXJJ8OTI6xbZ4daP1FMcyE99VM2X2Dz8ucK2gSsiOXRlmb7oSfmriZy8Gy7?= =?us-ascii?Q?kuPB3xMTiK6ImQO8HfKbAOhwDY/0ulNkYwHug8RTcxizLN2ABPXnKuTUHz+8?= =?us-ascii?Q?196kHCsYwj1m4ECQnMXzTC9XodezJAbGplU8CHzaOb4aMyBKUlF1v6IpjdQa?= =?us-ascii?Q?f7VD8vK1HgZsKm1aDKMPSRwnRp9wDswTREKNBo6iZSZi9BLhVg5mGZTgb8AG?= =?us-ascii?Q?uy/kejhX8rvzSUa7VTUAfRXdaEcKy4BgSUUWjWC2r86S/Ov+KARsQ/p0XiBt?= =?us-ascii?Q?Jbu77BvXS7Lpq9uwANEexBkacKcSfZ2t?= X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: a35efff5-a263-4eec-0f0b-08da075ef21d X-MS-Exchange-CrossTenant-AuthSource: DM6PR17MB3113.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2022 15:09:20.0407 (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: 9baZU0fDy/vQkuWCSahl264MJ/6xdqPfLtk3HC4s7SUXsia9l1f5CoDuuZtEZbaeeguUw9Oyb63XWPr7TJ46OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1701MB1829 X-Spam-Status: No, score=-11.8 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, T_SCC_BODY_TEXT_LINE 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: Wed, 16 Mar 2022 15:09:25 -0000 GDB notifies users about user selected thread changes somewhat inconsistently as mentioned on gdb-patches mailing list here: https://sourceware.org/pipermail/gdb-patches/2022-February/185989.html Consider GDB debugging a multi-threaded inferior with both CLI and GDB/MI interfaces connected to separate terminals. Assuming inferior is stopped and thread 1 is selected, when a thread 2 is selected using '-thread-select 2' command on GDB/MI terminal: -thread-select 2 ^done,new-thread-id="2",frame={level="0",addr="0x00005555555551cd",func="child_sub_function",args=[],file="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",fullname="/home/uuu/gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c",line="30",arch="i386:x86-64"} (gdb) and on CLI terminal we get the notification (as expected): [Switching to thread 2 (Thread 0x7ffff7daa640 (LWP 389659))] #0 child_sub_function () at /home/uuu/gdb/gdb/testsuite/gdb.mi/user-selected-context-sync.c:30 30 volatile int dummy = 0; However, now that thread 2 is selected, if thread 1 is selected using 'thread-select --thread 1 1' command on GDB/MI terminal terminal: -thread-select --thread 1 1 ^done,new-thread-id="1",frame={level="0",addr="0x0000555555555294",func="main",args=[],file="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",fullname="/home/jv/Projects/gdb/users_jv_patches/gdb/testsuite/gdb.mi/user-selected-context-sync.c",line="66",arch="i386:x86-64"} (gdb) but no notification is printed on CLI terminal, despite the fact that user selected thread has changed. The problem is that when `-thread-select --thread 1 1` is executed then thread is switched to thread 1 before mi_cmd_thread_select () is called, therefore the condition "inferior_ptid != previous_ptid" there does not hold. To address this problem, we have to move notification logic up to mi_cmd_execute () where --thread option is processed and notify user selected contents observers there if context changes. However, this in itself breaks GDB/MI because it would cause context notification to be sent on MI channel. This is because by the time we notify, MI notification suppression is already restored (done in mi_command::invoke(). Therefore we had to lift notification suppression logic also up to mi_cmd_execute (). This change in made distinction between mi_command::invoke() and mi_command::do_invoke() unnecessary as all mi_command::invoke() did (after the change) was to call do_invoke(). So this patches removes do_invoke() and moves the command execution logic directly to invoke(). With this change, all gdb.mi tests pass, tested on x86_64-linux. Co-authored-by: Andrew Burgess Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20631 --- gdb/mi/mi-cmd-stack.c | 12 +--- gdb/mi/mi-cmds.c | 18 +----- gdb/mi/mi-cmds.h | 17 ++---- gdb/mi/mi-main.c | 51 +++++++++++++--- gdb/python/py-micmd.c | 5 +- gdb/stack.c | 8 --- gdb/stack.h | 6 -- .../gdb.mi/user-selected-context-sync.exp | 58 +++++++++++++++++-- 8 files changed, 106 insertions(+), 69 deletions(-) diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index 1be8aa81c3d..e894411765a 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -757,17 +757,7 @@ mi_cmd_stack_select_frame (const char *command, char **argv, int argc) { if (argc == 0 || argc > 1) error (_("-stack-select-frame: Usage: FRAME_SPEC")); - - ptid_t previous_ptid = inferior_ptid; - - select_frame_for_mi (parse_frame_specification (argv[0])); - - /* Notify if the thread has effectively changed. */ - if (inferior_ptid != previous_ptid) - { - gdb::observers::user_selected_context_changed.notify - (USER_SELECTED_THREAD | USER_SELECTED_FRAME); - } + select_frame (parse_frame_specification (argv[0])); } void diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 38fbe0d8a32..60fec0a0b85 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -45,11 +45,9 @@ struct mi_command_mi : public mi_command gdb_assert (func != nullptr); } -protected: - /* Called when this MI command has been invoked, calls m_argv_function with arguments contained within PARSE. */ - void do_invoke (struct mi_parse *parse) const override + void invoke (struct mi_parse *parse) const override { mi_parse_argv (parse->args, parse); @@ -83,13 +81,11 @@ struct mi_command_cli : public mi_command m_args_p (args_p) { /* Nothing. */ } -protected: - /* Called when this MI command has been invoked, calls the m_cli_name CLI function. In m_args_p is true then the argument string from within PARSE is passed through to the CLI function, otherwise nullptr is passed through to the CLI function as its argument string. */ - void do_invoke (struct mi_parse *parse) const override + void invoke (struct mi_parse *parse) const override { const char *args = m_args_p ? parse->args : nullptr; mi_execute_cli_command (m_cli_name, m_args_p, args); @@ -173,16 +169,6 @@ mi_command::mi_command (const char *name, int *suppress_notification) /* See mi-cmds.h. */ -void -mi_command::invoke (struct mi_parse *parse) const -{ - gdb::optional> restore - = do_suppress_notification (); - this->do_invoke (parse); -} - -/* See mi-cmds.h. */ - gdb::optional> mi_command::do_suppress_notification () const { diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index 47b90a26064..05b702f83ec 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -160,9 +160,10 @@ struct mi_command const char *name () const { return m_name; } - /* Execute the MI command. Can throw an exception if something goes - wrong. */ - void invoke (struct mi_parse *parse) const; + /* Execute the MI command. this needs to be overridden in each + base class. PARSE is the parsed command line from the user. + Can throw an exception if something goes wrong. */ + virtual void invoke (struct mi_parse *parse) const = 0; /* Return whether this command preserves user selected context (thread and frame). */ @@ -175,14 +176,6 @@ struct mi_command return m_suppress_notification != &mi_suppress_notification.user_selected_context; } -protected: - - /* The core of command invocation, this needs to be overridden in each - base class. PARSE is the parsed command line from the user. */ - virtual void do_invoke (struct mi_parse *parse) const = 0; - -private: - /* If this command was created with a suppress notifications pointer, then this function will set the suppress flag and return a gdb::optional with its value set to an object that will restore the @@ -192,6 +185,8 @@ struct mi_command then this function returns an empty gdb::optional. */ gdb::optional> do_suppress_notification () const; +private: + /* The name of the command. */ const char *m_name; diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 73380f5e668..abd033b22ae 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -556,19 +556,10 @@ mi_cmd_thread_select (const char *command, char **argv, int argc) if (thr == NULL) error (_("Thread ID %d not known."), num); - ptid_t previous_ptid = inferior_ptid; - thread_select (argv[0], thr); print_selected_thread_frame (current_uiout, USER_SELECTED_THREAD | USER_SELECTED_FRAME); - - /* Notify if the thread has effectively changed. */ - if (inferior_ptid != previous_ptid) - { - gdb::observers::user_selected_context_changed.notify - (USER_SELECTED_THREAD | USER_SELECTED_FRAME); - } } void @@ -1975,6 +1966,37 @@ mi_execute_command (const char *cmd, int from_tty) } } +/* Captures the current user selected context state, that is the current + thread and frame. Later we can then check if the user selected context + has changed at all. */ + +struct user_selected_context +{ + /* Constructor. */ + user_selected_context () + : m_previous_ptid (inferior_ptid), + m_previous_frame (deprecated_safe_get_selected_frame ()) + { /* Nothing. */ } + + /* Return true if the user selected context has changed since this object + was created. */ + bool has_changed () const + { + return ((m_previous_ptid != null_ptid + && inferior_ptid != null_ptid + && m_previous_ptid != inferior_ptid) + || m_previous_frame != deprecated_safe_get_selected_frame ()); + } +private: + /* The previously selected thread. This might be null_ptid if there was + no previously selected thread. */ + ptid_t m_previous_ptid; + + /* The previously selected frame. This might be nullptr if there was no + previously selected frame. */ + frame_info *m_previous_frame; +}; + static void mi_cmd_execute (struct mi_parse *parse) { @@ -2015,6 +2037,8 @@ mi_cmd_execute (struct mi_parse *parse) set_current_program_space (inf->pspace); } + user_selected_context current_user_selected_context; + gdb::optional thread_saver; if (parse->thread != -1) { @@ -2060,7 +2084,16 @@ mi_cmd_execute (struct mi_parse *parse) current_context = parse; gdb_assert (parse->cmd != nullptr); + + gdb::optional> restore_suppress_notification + = parse->cmd->do_suppress_notification (); + parse->cmd->invoke (parse); + + if (!parse->cmd->preserve_user_selected_context () + && current_user_selected_context.has_changed ()) + gdb::observers::user_selected_context_changed.notify + (USER_SELECTED_THREAD | USER_SELECTED_FRAME); } /* See mi-main.h. */ diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c index 4665fcc75c7..399e89b0298 100644 --- a/gdb/python/py-micmd.c +++ b/gdb/python/py-micmd.c @@ -134,9 +134,8 @@ struct mi_command_py : public mi_command m_pyobj = new_pyobj; } -protected: /* Called when the MI command is invoked. */ - virtual void do_invoke(struct mi_parse *parse) const override; + virtual void invoke(struct mi_parse *parse) const override; private: /* The Python object representing this MI command. */ @@ -311,7 +310,7 @@ serialize_mi_result (PyObject *result) command line arguments from the user. */ void -mi_command_py::do_invoke (struct mi_parse *parse) const +mi_command_py::invoke (struct mi_parse *parse) const { PYMICMD_SCOPED_DEBUG_ENTER_EXIT; diff --git a/gdb/stack.c b/gdb/stack.c index 8855ed8fe70..10da88b88e5 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1841,14 +1841,6 @@ select_frame_command_core (struct frame_info *fi, bool ignored) gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME); } -/* See stack.h. */ - -void -select_frame_for_mi (struct frame_info *fi) -{ - select_frame_command_core (fi, false /* Ignored. */); -} - /* The core of all the "frame" sub-commands. Select frame FI, and if this means we change frame send out a change notification (otherwise, just reprint the current frame summary). */ diff --git a/gdb/stack.h b/gdb/stack.h index c49d2e2cbef..f78aedf1c85 100644 --- a/gdb/stack.h +++ b/gdb/stack.h @@ -20,12 +20,6 @@ #ifndef STACK_H #define STACK_H -/* Access method used by the MI -stack-select-frame command to switch to - frame FI. This differs from SELECT_FRAME in that the observers for a - user selected context change will be triggered. */ - -void select_frame_for_mi (struct frame_info *fi); - gdb::unique_xmalloc_ptr find_frame_funname (struct frame_info *frame, enum language *funlang, struct symbol **funcp); diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp index 3b4ff0bf2e4..9444ca5acf4 100644 --- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp +++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp @@ -916,7 +916,7 @@ proc_with_prefix test_mi_thread_select { mode } { } } - with_test_prefix "thread 1.2 with --thread" { + with_test_prefix "thread 1.2 with --thread 2" { # Test selecting a thread from MI with a --thread option. This test # verifies that even if the thread GDB would switch to is the same as # the thread specified with --thread, an event is still sent to CLI. @@ -930,10 +930,28 @@ proc_with_prefix test_mi_thread_select { mode } { } with_spawn_id $gdb_main_spawn_id { - # This doesn't work as of now, no event is sent on CLI. It is - # commented out so we don't have to wait for the timeout every time. - # match_re_or_ensure_no_output "$cli_re\r\n" "-thread-select, event on cli" - kfail "gdb/20631" "thread-select, event on cli" + match_re_or_ensure_no_output "$cli_re\r\n" "-thread-select, event on cli" + } + } + + with_test_prefix "thread 1.2 with --thread 3" { + # Test selecting a thread from MI with a --thread option. + # This test verifies that when different thread numbers are + # passed to the --thread option and the underlying + # -thread-select command, the correct thread is selected. + # In this case this is thread 1.2 + + reset_selection "1.1" + + set mi_re [make_mi_re $mode 2 0 response] + set cli_re [make_cli_re $mode -1 1.2 0] + + with_spawn_id $mi_spawn_id { + mi_gdb_test "-thread-select --thread 3 2" $mi_re "-thread-select" + } + + with_spawn_id $gdb_main_spawn_id { + match_re_or_ensure_no_output "$cli_re\r\n" "-thread-select, event on cli" } } @@ -974,6 +992,36 @@ proc_with_prefix test_mi_stack_select_frame { mode } { with_spawn_id $gdb_main_spawn_id { match_re_or_ensure_no_output $cli_re "-stack-select-frame again, event on CLI" } + + # Now use the '-stack-select-frame' command with the --frame + # option, this verifies that even when the frame GDB would + # swith to is the same as the frame specified with --frame, an + # event is still sent to the CLI. + + set cli_re [make_cli_re $mode -1 -1 0] + + with_spawn_id $mi_spawn_id { + mi_gdb_test "-stack-select-frame --thread 2 --frame 0 0" $mi_re + } + + with_spawn_id $gdb_main_spawn_id { + match_re_or_ensure_no_output "$cli_re\r\n" "-stack-select-frame with --frame 0, event on CLI" + } + + # Now use the '-stack-select-frame' command with the --frame + # option, this verifies that the correct event is sent to the + # CLI when the frame specified with --frame is different to + # the actual frame selected. + + set cli_re [make_cli_re $mode -1 -1 1] + + with_spawn_id $mi_spawn_id { + mi_gdb_test "-stack-select-frame --thread 2 --frame 2 1" $mi_re + } + + with_spawn_id $gdb_main_spawn_id { + match_re_or_ensure_no_output "$cli_re\r\n" "-stack-select-frame with --frame 2, event on CLI" + } } with_test_prefix "thread 1.3" { -- 2.35.1