From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7261 invoked by alias); 11 Mar 2013 17:29:05 -0000 Received: (qmail 7234 invoked by uid 22791); 11 Mar 2013 17:29:05 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Mar 2013 17:28:49 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2BHSgK4020624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Mar 2013 13:28:42 -0400 Received: from host2.jankratochvil.net (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2BHSbt0026493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 11 Mar 2013 13:28:40 -0400 Date: Mon, 11 Mar 2013 17:29:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: "Metzger, Markus T" Subject: [patch] Fix remote.c incorrectly using pop_target (wrt btrace) Message-ID: <20130311172836.GA22575@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2013-03/txt/msg00477.txt.bz2 Hi, with the btrace patchset checked in one may get stuck when using btrace and gdbserver: ./gdbserver :1234 true ./gdb true -ex 'target remote localhost:1234' -ex 'set debug remote 1' -ex 'record btrace' (gdb) stepi Sending packet: $qTStatus#49...qTStatus: Remote connection closed Sending packet: $Z0,7ffff7debd10,1#09...Sending packet: $QPassSignals:e;10;14;17;1a;1b;1c;21;24;25;2c;4c;#5f...0x00007ffff7ddd420 in _start () from /lib64/ld-linux-x86-64.so.2 putpkt: write failed: Broken pipe. (gdb) q A debugging session is active. Inferior 1 [process 26817] will be killed. Quit anyway? (y or n) y Sending packet: $qTStatus#49...putpkt: write failed: Broken pipe. (gdb) _ as discussed in: RE: Crash of GDB with gdbserver btrace enabled [Re: [patch v9 00/23] branch tracing support for Atom] http://sourceware.org/ml/gdb-patches/2013-03/msg00296.html Message-ID: From: "Metzger, Markus T" with the fix below: (gdb) stepi Sending packet: $qTStatus#49...qTStatus: You can't do that when your target is `record-btrace' PC register is not available (gdb) stepi The program is not being run. (gdb) q $ _ Those two removed pop_target calls around target_preopen (from_tty); unpush_target (target); were redundant as they were added by: commit ef378e83937c25e9da9c4e545bb1a8bb5fd767f1 Author: Daniel Jacobowitz Date: Wed Jan 30 00:51:50 2008 +0000 but later target_preopen started removing all the targets in target_preopen by: commit 3db54b199473ba136a4821c420f85096ff17e98e Author: Pedro Alves Date: Mon Aug 18 23:12:39 2008 +0000 No regressions on {x86_64,x86_64-m32,i686}-fedora19pre-linux-gnu and with gdbserver. I would like to get it checked in for 7.6 is it is some sort of regression from btrace. Thanks, Jan gdb/ 2013-03-11 Jan Kratochvil * remote.c (remote_unpush_target): New function. (remote_open_1): Remove two pop_target calls, update one comment, add comment to target_preopen call. Replace pop_target call by remote_unpush_target call. (interrupt_query, readchar, getpkt_or_notif_sane_1): Replace pop_target calls by remote_unpush_target calls. diff --git a/gdb/remote.c b/gdb/remote.c index 8fc6b85..6e6c0d6 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4188,6 +4188,14 @@ remote_query_supported (void) } } +/* Remove any of the remote.c targets from target stack. */ + +static void +remote_unpush_target (void) +{ + unpush_target (&remote_ops); + unpush_target (&extended_remote_ops); +} static void remote_open_1 (char *name, int from_tty, @@ -4205,30 +4213,18 @@ remote_open_1 (char *name, int from_tty, wait_forever_enabled_p = 1; /* If we're connected to a running target, target_preopen will kill it. - But if we're connected to a target system with no running process, - then we will still be connected when it returns. Ask this question - first, before target_preopen has a chance to kill anything. */ + Ask this question first, before target_preopen has a chance to kill + anything. */ if (remote_desc != NULL && !have_inferiors ()) { - if (!from_tty - || query (_("Already connected to a remote target. Disconnect? "))) - pop_target (); - else + if (from_tty + && !query (_("Already connected to a remote target. Disconnect? "))) error (_("Still connected.")); } + /* Here the possibly existing remote target gets unpushed. */ target_preopen (from_tty); - unpush_target (target); - - /* This time without a query. If we were connected to an - extended-remote target and target_preopen killed the running - process, we may still be connected. If we are starting "target - remote" now, the extended-remote target will not have been - removed by unpush_target. */ - if (remote_desc != NULL && !have_inferiors ()) - pop_target (); - /* Make sure we send the passed signals list the next time we resume. */ xfree (last_pass_packet); last_pass_packet = NULL; @@ -4348,7 +4344,7 @@ remote_open_1 (char *name, int from_tty, /* Pop the partially set up target - unless something else did already before throwing the exception. */ if (remote_desc != NULL) - pop_target (); + remote_unpush_target (); if (target_async_permitted) wait_forever_enabled_p = 1; throw_exception (ex); @@ -5096,7 +5092,7 @@ interrupt_query (void) if (query (_("Interrupted while waiting for the program.\n\ Give up (and stop debugging it)? "))) { - pop_target (); + remote_unpush_target (); deprecated_throw_reason (RETURN_QUIT); } } @@ -7051,11 +7047,11 @@ readchar (int timeout) switch ((enum serial_rc) ch) { case SERIAL_EOF: - pop_target (); + remote_unpush_target (); error (_("Remote connection closed")); /* no return */ case SERIAL_ERROR: - pop_target (); + remote_unpush_target (); perror_with_name (_("Remote communication error. " "Target disconnected.")); /* no return */ @@ -7579,7 +7575,7 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever, if (forever) /* Watchdog went off? Kill the target. */ { QUIT; - pop_target (); + remote_unpush_target (); error (_("Watchdog timeout has expired. Target detached.")); } if (remote_debug)