From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9560 invoked by alias); 2 Apr 2013 02:33:34 -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 8714 invoked by uid 89); 2 Apr 2013 02:33:26 -0000 X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL,BAYES_00,FROM_12LTRDOM,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL autolearn=ham version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 02 Apr 2013 02:33:18 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1UMr2C-0001GU-De from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Mon, 01 Apr 2013 19:33:16 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 1 Apr 2013 19:33:16 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.1.289.1; Mon, 1 Apr 2013 19:33:15 -0700 From: Yao Qi To: Subject: [PATCH 4/5] MI notification on trace started/stopped:basic Date: Tue, 02 Apr 2013 13:07:00 -0000 Message-ID: <1364869917-12803-5-git-send-email-yao@codesourcery.com> In-Reply-To: <1364869917-12803-1-git-send-email-yao@codesourcery.com> References: <1358838232-13319-1-git-send-email-yao@codesourcery.com> <1364869917-12803-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-04/txt/msg00028.txt.bz2 Hi, This patch adds the notifications of 'trace-started' and 'trace-stopped', which are emitted when trace is started or stopped by command 'tstart' and 'tstop', so that when trace is started or stopped in console, MI frontend can be notified. This patch doesn't handle the case the trace is stopped due to some reasons in remote side, because we don't have any existing RSP notification yet. This issue will be addressed in another post. Regression tested on x86_64-linux with native and gdbserver. Is it OK? The documentation patch was approved by Eli here gdb/doc: * gdb.texinfo (GDB/MI Async Records): New MI notifications 'trace-changed'. * observer.texi (GDB Observers): New observer 'trace-changed' gdb: * mi/mi-cmds.c (mi_cmds): Adjust for commands 'trace-start' and 'trace-stop'. * mi/mi-interp.c: Declare mi_trace_changed. (mi_interpreter_init): Install mi_trace_changed to observer. (mi_trace_changed): New. * mi/mi-main.h (struct mi_suppress_notification) : New field. * tracepoint.c (start_tracing): Call observer_notify_trace_changed. (stop_tracing): Call observer_notify_trace_changed. * NEWS: Mention it. gdb/testsuite/ * gdb.mi/mi-trace-changed.exp: New. --- gdb/NEWS | 2 + gdb/doc/gdb.texinfo | 4 ++ gdb/doc/observer.texi | 6 ++ gdb/mi/mi-cmds.c | 6 ++- gdb/mi/mi-interp.c | 22 ++++++++ gdb/mi/mi-main.h | 2 + gdb/testsuite/gdb.trace/mi-trace-changed.exp | 74 ++++++++++++++++++++++++++ gdb/tracepoint.c | 4 ++ 8 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.trace/mi-trace-changed.exp diff --git a/gdb/NEWS b/gdb/NEWS index 56b68d8..f635f9f 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -23,6 +23,8 @@ show remote trace-status-packet ** The -trace-save MI command can optionally save trace buffer in Common Trace Format now. + ** The start and stop of trace are now notified using new async records + "=trace-started" and "=trace-stopped". *** Changes in GDB 7.6 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 1325012..d9b2bc0 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -28090,6 +28090,10 @@ written in an inferior. The @var{id} is the identifier of the thread group corresponding to the affected inferior. The optional @code{type="code"} part is reported if the memory written to holds executable code. + +@item =trace-started +@itemx =trace-stopped +Reports that trace was started or stopped. @end table @node GDB/MI Breakpoint Information diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi index adb7085..17e3588 100644 --- a/gdb/doc/observer.texi +++ b/gdb/doc/observer.texi @@ -249,6 +249,12 @@ The trace state variable @var{tsv} is deleted. If @var{tsv} is The trace state value @var{tsv} is modified. @end deftypefun +@deftypefun void trace_changed (int @var{started}) +The status of trace in @value{GDBN} has changed. The trace is started +if @var{started} is non-zero, and the trace is stopped if +@var{started} is zero. +@end deftypefun + @deftypefun void test_notification (int @var{somearg}) This observer is used for internal testing. Do not use. See testsuite/gdb.gdb/observer.exp. diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index df173fe..f2c037d 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -146,9 +146,11 @@ static struct mi_cmd mi_cmds[] = &mi_suppress_notification.traceframe), DEF_MI_CMD_MI ("trace-list-variables", mi_cmd_trace_list_variables), DEF_MI_CMD_MI ("trace-save", mi_cmd_trace_save), - DEF_MI_CMD_MI ("trace-start", mi_cmd_trace_start), + DEF_MI_CMD_MI_1 ("trace-start", mi_cmd_trace_start, + &mi_suppress_notification.trace), DEF_MI_CMD_MI ("trace-status", mi_cmd_trace_status), - DEF_MI_CMD_MI ("trace-stop", mi_cmd_trace_stop), + DEF_MI_CMD_MI_1 ("trace-stop", mi_cmd_trace_stop, + &mi_suppress_notification.trace), DEF_MI_CMD_MI ("var-assign", mi_cmd_var_assign), DEF_MI_CMD_MI ("var-create", mi_cmd_var_create), DEF_MI_CMD_MI ("var-delete", mi_cmd_var_delete), diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 2702f4f..ba2277a 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -68,6 +68,7 @@ static void mi_inferior_appeared (struct inferior *inf); static void mi_inferior_exit (struct inferior *inf); static void mi_inferior_removed (struct inferior *inf); static void mi_on_resume (ptid_t ptid); +static void mi_trace_changed (int started); static void mi_solib_loaded (struct so_list *solib); static void mi_solib_unloaded (struct so_list *solib); static void mi_about_to_proceed (void); @@ -133,6 +134,7 @@ mi_interpreter_init (struct interp *interp, int top_level) observer_attach_record_changed (mi_record_changed); observer_attach_normal_stop (mi_on_normal_stop); observer_attach_target_resumed (mi_on_resume); + observer_attach_trace_changed (mi_trace_changed); observer_attach_solib_loaded (mi_solib_loaded); observer_attach_solib_unloaded (mi_solib_unloaded); observer_attach_about_to_proceed (mi_about_to_proceed); @@ -620,6 +622,26 @@ mi_tsv_modified (const struct trace_state_variable *tsv) gdb_flush (mi->event_channel); } +/* Emit notification on trace was started or stopped. */ + +static void +mi_trace_changed (int started) +{ + struct mi_interp *mi = top_level_interpreter_data (); + + if (mi_suppress_notification.trace) + return; + + target_terminal_ours (); + + if (started) + fprintf_unfiltered (mi->event_channel, "trace-started\n"); + else + fprintf_unfiltered (mi->event_channel, "trace-stopped\n"); + + gdb_flush (mi->event_channel); +} + /* Emit notification about a created breakpoint. */ static void diff --git a/gdb/mi/mi-main.h b/gdb/mi/mi-main.h index d75526a..0903d60 100644 --- a/gdb/mi/mi-main.h +++ b/gdb/mi/mi-main.h @@ -43,6 +43,8 @@ struct mi_suppress_notification int traceframe; /* Memory changed notification suppressed? */ int memory; + /* Trace started/stopped notification suppressed? */ + int trace; }; extern struct mi_suppress_notification mi_suppress_notification; diff --git a/gdb/testsuite/gdb.trace/mi-trace-changed.exp b/gdb/testsuite/gdb.trace/mi-trace-changed.exp new file mode 100644 index 0000000..fbd6fe7 --- /dev/null +++ b/gdb/testsuite/gdb.trace/mi-trace-changed.exp @@ -0,0 +1,74 @@ +# Copyright 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib mi-support.exp +load_lib trace-support.exp + +standard_testfile status-stop.c + +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ + executable {debug nowarnings}] != "" } { + untested mi-record-changed.exp + return -1 +} + +clean_restart $testfile + +if ![runto_main] { + fail "Can't run to main to check for trace support" + return -1 +} + +if ![gdb_target_supports_trace] { + unsupported "target does not support trace" + return -1; +} + +gdb_exit + +# Verify that MI notification '=trace-started' and '=trace-stopped' are +# emitted for normal 'tstart' and 'tstart' command. + +proc test_normal_tstart_stop { } { + with_test_prefix "tstart_tstop" { + global decimal hex + + if [mi_gdb_start] { + return + } + mi_run_to_main + + mi_gdb_test "-break-insert -a main" {.*\^done,bkpt=.*} \ + "insert tracepoint on main" + + # No =trace-started notification. + mi_gdb_test "-trace-start" "-trace-start\r\n=breakpoint-modified\[^\n\]+\r\n\\^done" \ + "start trace without notification" + mi_gdb_test "-trace-stop" \ + "-trace-stop\r\n\\^done,stop-reason=\"request\".*" \ + "stop trace without notification" + + mi_gdb_test "tstart" \ + ".*=trace-started.*\\^done" "start trace notification" + mi_gdb_test "tstop" ".*=trace-stopped\\\\n\r\n\\^done" \ + "stop trace notification" + + mi_gdb_exit + } +} + +test_normal_tstart_stop + +return 0 diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 009db82..feeb618 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -1850,6 +1850,8 @@ start_tracing (char *notes) /* Now insert traps and begin collecting data. */ target_trace_start (); + observer_notify_trace_changed (1); + /* Reset our local state. */ set_traceframe_num (-1); set_tracepoint_num (-1); @@ -1935,6 +1937,8 @@ stop_tracing (char *note) /* Should change in response to reply? */ current_trace_status ()->running = 0; + + observer_notify_trace_changed (0); } /* tstatus command */ -- 1.7.7.6