Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@fit.cvut.cz>
To: gdb@sourceware.org
Subject: Re: MI commands with --thread (--frame?) do not preserve user selected thread /  frame
Date: Wed, 19 Jun 2019 15:10:00 -0000	[thread overview]
Message-ID: <3b34a5e356a75454b6b7903048c0d62a409673d5.camel@fit.cvut.cz> (raw)
In-Reply-To: <5df1c9d79778a5d6703bba442031b5a1bbeda141.camel@fit.cvut.cz>

On Wed, 2019-06-19 at 11:53 +0100, Jan Vrany wrote:
> Hi, 
> 
> I was debugging a multithreaded program and realized that using --thread option to
> verious MI command silently changes user selected thread - here's an example using
> separate UI and CLI chahhel (tested on commit 6f5601c4d0)
> 
> 
...
> 
> 
> As you can see, there was no `frame`, `thread`, `-select-frame` or `-thread-select` command between
> first and second info thread / frame commands on CLI, yet the selected thread / frame changed (silently).
> 
> Is this intended behavior? If so what's the rationale?
> 

Simple patch that preserves user selected context:

---

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 13c310d494..ac3969f1b4 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2060,6 +2060,7 @@ mi_cmd_execute (struct mi_parse *parse)
       set_current_program_space (inf->pspace);
     }
 
+  gdb::optional<scoped_restore_current_thread> thread_saver;
   if (parse->thread != -1)
     {
       thread_info *tp = find_thread_global_id (parse->thread);
@@ -2070,9 +2071,11 @@ mi_cmd_execute (struct mi_parse *parse)
       if (tp->state == THREAD_EXITED)
        error (_("Thread id: %d has terminated"), parse->thread);
 
+      thread_saver.emplace ();
       switch_to_thread (tp);
     }
 
+  gdb::optional<scoped_restore_selected_frame> frame_saver;
   if (parse->frame != -1)
     {
       struct frame_info *fid;
@@ -2080,8 +2083,11 @@ mi_cmd_execute (struct mi_parse *parse)
 
       fid = find_relative_frame (get_current_frame (), &frame);
       if (frame == 0)
-       /* find_relative_frame was successful */
-       select_frame (fid);
+        {
+          /* find_relative_frame was successful */
+          frame_saver.emplace ();
+          select_frame (fid);
+        }
       else
        error (_("Invalid frame id: %d"), frame);
     }


       reply	other threads:[~2019-06-19 15:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5df1c9d79778a5d6703bba442031b5a1bbeda141.camel@fit.cvut.cz>
2019-06-19 15:10 ` Jan Vrany [this message]
2019-06-19 15:54   ` Simon Marchi
2019-06-19 16:04     ` Jan Vrany
2019-06-19 17:14       ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b34a5e356a75454b6b7903048c0d62a409673d5.camel@fit.cvut.cz \
    --to=jan.vrany@fit.cvut.cz \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox