From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127917 invoked by alias); 19 Jun 2019 15:10:13 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 127907 invoked by uid 89); 19 Jun 2019 15:10:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=H*i:sk:5df1c9d, H*f:sk:5df1c9d X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jun 2019 15:10:11 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [IPv6:2001:718:2:2901:0:0:0:238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id x5JFA6HQ049568 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 19 Jun 2019 17:10:07 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Received: from [IPv6:2a02:c7d:2fcb:c700:6267:20ff:fee4:3e2c] ([IPv6:2a02:c7d:2fcb:c700:6267:20ff:fee4:3e2c]) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id x5JFA4iJ020310 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 19 Jun 2019 17:10:05 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Message-ID: <3b34a5e356a75454b6b7903048c0d62a409673d5.camel@fit.cvut.cz> Subject: Re: MI commands with --thread (--frame?) do not preserve user selected thread / frame From: Jan Vrany To: gdb@sourceware.org Date: Wed, 19 Jun 2019 15:10:00 -0000 In-Reply-To: <5df1c9d79778a5d6703bba442031b5a1bbeda141.camel@fit.cvut.cz> References: <5df1c9d79778a5d6703bba442031b5a1bbeda141.camel@fit.cvut.cz> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-06/txt/msg00055.txt.bz2 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 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 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); }