{
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
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);
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);
/* See mi-cmds.h. */
-void
-mi_command::invoke (struct mi_parse *parse) const
-{
- gdb::optional<scoped_restore_tmpl<int>> restore
- = do_suppress_notification ();
- this->do_invoke (parse);
-}
-
-/* See mi-cmds.h. */
-
gdb::optional<scoped_restore_tmpl<int>>
mi_command::do_suppress_notification () const
{
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). */
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
then this function returns an empty gdb::optional. */
gdb::optional<scoped_restore_tmpl<int>> do_suppress_notification () const;
+private:
+
/* The name of the command. */
const char *m_name;
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
}
}
+/* 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)
{
set_current_program_space (inf->pspace);
}
+ user_selected_context current_user_selected_context;
+
gdb::optional<scoped_restore_current_thread> thread_saver;
if (parse->thread != -1)
{
current_context = parse;
gdb_assert (parse->cmd != nullptr);
+
+ gdb::optional<scoped_restore_tmpl<int>> 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. */
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. */
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;
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). */
#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<char> find_frame_funname (struct frame_info *frame,
enum language *funlang,
struct symbol **funcp);
}
}
- 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.
}
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"
}
}
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" {