From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77210 invoked by alias); 24 Apr 2018 10:20:48 -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 77188 invoked by uid 89); 24 Apr 2018 10:20:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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.2 spammy=H*r:user, H*r:may, H*r:forged, sk:mi_comm 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; Tue, 24 Apr 2018 10:20:43 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [IPv6:2001:718:2:2901:0:0:0:238] (may be forged)) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id w3OAKMia020784 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Tue, 24 Apr 2018 12:20:24 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Received: from [192.168.160.10] (cpe-190-55-26-63.telecentro-reversos.com.ar [190.55.26.63] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id w3OAKAS2000841 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 24 Apr 2018 12:20:19 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Message-ID: <2836ac51befe41b0411f89b6bcdb2ea935148787.camel@fit.cvut.cz> Subject: Re: How to use -list-target-features MI command From: Jan Vrany To: Pedro Alves , Simon Marchi Cc: gdb@sourceware.org Date: Thu, 26 Apr 2018 23:49:00 -0000 In-Reply-To: References: <7d2d750c39c73c13c2d0e04667475d8f@polymtl.ca> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-FIT-MailScanner-Information: X-FIT-MailScanner-ID: w3OAKMia020784 X-FIT-MailScanner: Found to be clean X-FIT-MailScanner-SpamCheck: not spam, SpamAssassin (score=-0.1, required 6, autolearn=not spam, BAYES_00 -0.10) X-FIT-MailScanner-From: jan.vrany@fit.cvut.cz X-FIT-MailScanner-Watermark: 1524586824.7998@LzSy6mpZ9vr6y8sypXVXxQ X-IsSubscribed: yes X-SW-Source: 2018-04/txt/msg00022.txt.bz2 Hi, On Mon, 2018-04-23 at 14:45 +0100, Pedro Alves wrote: > > > One way to hack around it would be to use for example the new > > "starti" command, which breaks at (before?) the first instruction > > of the program, issue -list-target-features, and then continue. > > There might be some better/cleaner solution, but that's what comes > > to mind right now. > > IMO the clean solution is to connect to the native target > explicitly, with "-target-select native", before -exec-run, > instead of letting -exec-run automatically connect to > the native target if not connected to any other target yet. > > -gdb-set mi-async on > ^done > (gdb) > -target-select native > ^connected > (gdb) > -list-target-features > ^done,features=["async"] > (gdb) > -exec-run ... > > I'd also suggest that frontends consider using > "set auto-connect-native-target off" > https://sourceware.org/gdb/onlinedocs/gdb/Starting.html > Thanks! This makes sense. The only problem I see is that it only works reliably if one does not use CLI. In my case, I want user to be able to use the CLI. > I don't see a way right now that you could know about that. There would > need to be a new asynchronous event emitted when the target stack > changes. So gave it a go and added a new event. Seems to work fine (for me): diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 8bfb1298a5..f140a3cca2 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -22,6 +22,7 @@ #include "event-top.h" #include "event-loop.h" #include "inferior.h" +#include "target.h" #include "infrun.h" #include "ui-out.h" #include "top.h" @@ -85,6 +86,7 @@ static void mi_command_param_changed (const char *param, const char *value); static void mi_memory_changed (struct inferior *inf, CORE_ADDR memaddr, ssize_t len, const bfd_byte *myaddr); static void mi_on_sync_execution_done (void); +static void mi_current_target_changed (struct target_ops *target); static int report_initial_inferior (struct inferior *inf, void *closure); @@ -1280,6 +1282,38 @@ mi_user_selected_context_changed (user_selected_what selection) } } +static void +mi_current_target_changed (struct target_ops *target) +{ + SWITCH_THRU_ALL_UIS () + { + struct mi_interp *mi = as_mi_interp (top_level_interpreter ()); + + if (mi == NULL) + continue; + + target_terminal::scoped_restore_terminal_state term_state; + target_terminal::ours_for_output (); + + fprintf_unfiltered (mi->event_channel, + "target-changed,features=["); + if (mi_async_p ()) + fprintf_unfiltered (mi->event_channel, + "\"async\""); + if (target_can_execute_reverse) + { + if (mi_async_p ()) + fprintf_unfiltered (mi->event_channel,",\"reverse\""); + else + fprintf_unfiltered (mi->event_channel,"\"reverse\""); + } + fprintf_unfiltered (mi->event_channel, + "]"); + gdb_flush (mi->event_channel); + } +} + + static int report_initial_inferior (struct inferior *inf, void *closure) { @@ -1382,4 +1416,5 @@ _initialize_mi_interp (void) gdb::observers::sync_execution_done.attach (mi_on_sync_execution_done); gdb::observers::user_selected_context_changed.attach (mi_user_selected_context_changed); + gdb::observers::current_target_changed.attach (mi_current_target_changed); } diff --git a/gdb/observable.c b/gdb/observable.c index 5539b9837b..f99a39b909 100644 --- a/gdb/observable.c +++ b/gdb/observable.c @@ -74,6 +74,7 @@ DEFINE_OBSERVABLE (inferior_call_pre); DEFINE_OBSERVABLE (inferior_call_post); DEFINE_OBSERVABLE (register_changed); DEFINE_OBSERVABLE (user_selected_context_changed); +DEFINE_OBSERVABLE (current_target_changed); } /* namespace observers */ } /* namespace gdb */ diff --git a/gdb/observable.h b/gdb/observable.h index 34447b90bb..3f97cc5cb1 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -228,6 +228,9 @@ extern observable register_changed; frame has changed. */ extern observable user_selected_context_changed; +/* The current target has changed. */ +extern observable current_target_changed; + } /* namespace observers */ } /* namespace gdb */ diff --git a/gdb/target.c b/gdb/target.c index e8d4ae7ea8..5cb182c849 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -49,6 +49,7 @@ #include "byte-vector.h" #include "terminal.h" #include +#include static void generic_tls_error (void) ATTRIBUTE_NORETURN; @@ -719,6 +720,8 @@ update_current_target (void) if (targetdebug) setup_target_debug (); + + gdb::observers::current_target_changed.notify(¤t_target); } /* Push a new target type into the stack of the existing target accessors,