From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40587 invoked by alias); 3 Aug 2016 13:41:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 40567 invoked by uid 89); 3 Aug 2016 13:41:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=kinda, 1000000 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 03 Aug 2016 13:41:37 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C933488E60; Wed, 3 Aug 2016 13:41:36 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u73DfYDM009575; Wed, 3 Aug 2016 09:41:35 -0400 Subject: Re: [PATCH 1/2] mi: Restore original thread/frame when specifying --thread or --thread-group To: Simon Marchi , gdb-patches@sourceware.org References: <20160801211401.18155-1-simon.marchi@ericsson.com> <20160801211401.18155-2-simon.marchi@ericsson.com> <155e8052-19b5-a446-c9bd-f973ded3eaa3@ericsson.com> From: Pedro Alves Message-ID: <83adec9c-d7a1-3165-eac7-236372e994ef@redhat.com> Date: Wed, 03 Aug 2016 13:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-08/txt/msg00055.txt.bz2 On 08/02/2016 11:14 PM, Simon Marchi wrote: > On 16-08-02 01:38 PM, Simon Marchi wrote: >> Ok, I kinda had the same design idea, but it was blurry. Now that you explain it >> (I didn't know what previous_inferior_ptid was), it's clear. I'll try to prototype it >> quickly to see if it's viable. > > I started to prototype what you described, but it's definitely not a small job. It would > also be too big of a change to put in 7.12. I'd be really interested to work on that for > the next development cycle though. > > In the mean time, here is a new version of the patch that implements what I had described > (with the global flag), which I think is less risky. I think you need to consider infcalls, and canned sequence of commands Python/Scheme, etc., basically any place that sets ui->async = 0 ... guile/guile.c:169: current_ui->async = 0; guile/guile.c:202: current_ui->async = 0; guile/guile.c:332: current_ui->async = 0; guile/scm-ports.c:521: current_ui->async = 0; top.c:700: current_ui->async = 0; compile/compile.c:95: current_ui->async = 0; compile/compile.c:137: current_ui->async = 0; compile/compile.c:191: current_ui->async = 0; infcall.c:586: current_ui->async = 0; python/python.c:326: current_ui->async = 0; python/python.c:471: current_ui->async = 0; python/python.c:655: current_ui->async = 0; cli/cli-script.c:384: current_ui->async = 0; cli/cli-script.c:666: current_ui->async = 0; cli/cli-script.c:690: current_ui->async = 0; cli/cli-script.c:1697: current_ui->async = 0; ... because these will only return when execution next stops, so the cleanup runs after, and undoes the thread change. E.g., this infcall stops due to a breakpoint on another thread, but MI still reverts back to the "--thread" thread: (gdb) b usleep [...] ^done (gdb) thread 1 [...] ^done =thread-selected,id="1" (gdb) -interpreter-exec --thread 1 console "print sleep (10)" [...] ~"[Switching to Thread 0x7ffff6ffb700 (LWP 7818)]\n" ~"\n" ~"Thread 3 \"threads\" hit Breakpoint 2, usleep (useconds=1) at ../sysdeps/posix/usleep.c:26\n" ~"26\t struct timespec ts = { .tv_sec = (long int) (useconds / 1000000),\n" *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame={addr="0x00007ffff78f6030",func="usleep",args=[{name="useconds",value="1"}],file="../sysdeps/posix/usleep.c",fullname="/usr/src/debug/glibc-2.22/sysdeps/posix/usleep.c",line="26"},thread-id="3",stopped-threads="all",core="2" &"The program stopped in another thread while making a function call from GDB.\n" &"Evaluation of the expression containing the function\n" &"(__sleep) will be abandoned.\n" &"When the function is done executing, GDB will silently stop.\n" ^error,msg="The program stopped in another thread while making a function call from GDB.\nEvaluation of the expression containing the function\n(__sleep) will be abandoned.\nWhen the function is done executing, GDB will silently stop." (gdb) thread [...] ~"[Current thread is 1 (Thread 0x7ffff7fc8700 (LWP 7813))]\n" ^done (gdb) Above should have been 3. E.g., this user-defined command starts the program and stops in thread 2.1, but MI still reverts back to the "--thread" thread: (gdb) define foo ~">" inferior 2 ~">" start ~">" end (gdb) info inferiors ~" Num Description Executable \n" ~"* 1 process 8216 /home/pedro/brno/pedro/gdb/tests/threads \n" ~" 2 /home/pedro/brno/pedro/gdb/tests/threads \n" ^done (gdb) info threads ~" Id Target Id Frame \n" ~"* 1.1 Thread 0x7ffff7fc8700 (LWP 8216) \"threads\" main () at threads.c:54\n" ^done (gdb) -interpreter-exec --thread 1 console "foo" ~"[Switching to inferior 2 [] (/home/pedro/brno/pedro/gdb/tests/threads)]\n" [...] ~"\n" ~"Thread 2.1 \"threads\" hit Temporary breakpoint 3, main () at threads.c:54\n" ~"54\t long i = 0;\n" *stopped,reason="breakpoint-hit",disp="del",bkptno="3",frame={addr="0x000000000040076e",func="main",args=[],file="threads.c",fullname="/home/pedro/brno/pedro/gdb/tests/threads.c",line="54"},thread-id="3",stopped-threads="all",core="7" =breakpoint-deleted,id="3" (gdb) thread &"thread\n" ~"[Current thread is 1.1 (Thread 0x7ffff7fc8700 (LWP 8216))]\n" ^done (gdb) While at it, "inferior 2" is a command that explicitly changes the thread, but misses setting the new flag: -interpreter-exec --thread 1 console "inferior 2" ~"[Switching to inferior 2 [process 8603] (/home/pedro/brno/pedro/gdb/tests/threads)]\n" ~"[Switching to thread 2.1 (Thread 0x7ffff7fc8700 (LWP 8603))] \n" ~"#0 main () at threads.c:54\n" ~"54\t long i = 0;\n" ^done (gdb) thread &"thread \n" ~"[Current thread is 1.1 (Thread 0x7ffff7fc8700 (LWP 8599))]\n" ^done (gdb) It may be this requires setting the flag in most of the places that we'd set the user-selected thread in the other approach, not sure. Thanks, Pedro Alves