This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] MI notification on trace started/stopped:basic


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?

gdb/doc:

	* gdb.texinfo (GDB/MI Async Records): New MI notifications
	'trace-started' and 'trace-stopped'.
	* observer.texi (GDB Observers): New observer 'trace-started'
	and 'trace-stopped'.

gdb:

	* mi/mi-cmds.c (mi_cmds): Adjust for commands 'trace-start'
	and 'trace-stop'.
	* mi/mi-interp.c: Declare mi_trace_started and
	mi_trace_stopped.
	(mi_interpreter_init): Install mi_trace_started and
	mi_trace_stopped to observers.
	(mi_trace_started, mi_trace_stopped): New.
	* mi/mi-main.h (struct mi_suppress_notification) <trace>:
	New field.
	* tracepoint.c (start_tracing): Call observer_notify_trace_started.
	(stop_tracing): Call observer_notify_trace_stopped.

	* NEWS: Mention it.

gdb/testsuite/

	* gdb.mi/mi-trace-changed.exp: New.
---
 gdb/NEWS                                     |    2 +
 gdb/doc/gdb.texinfo                          |    6 ++
 gdb/doc/observer.texi                        |    8 +++
 gdb/mi/mi-cmds.c                             |    6 +-
 gdb/mi/mi-interp.c                           |   46 ++++++++++++++
 gdb/mi/mi-main.h                             |    2 +
 gdb/testsuite/gdb.trace/mi-trace-changed.exp |   84 ++++++++++++++++++++++++++
 gdb/tracepoint.c                             |    4 +
 8 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.trace/mi-trace-changed.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index f725b46..9628a51 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -68,6 +68,8 @@ show debug notification
      async record "=record-started" and "=record-stopped".
   ** Memory changes are now notified using new async record
      "=memory-changed".
+  ** The start and stop of trace are now notified using new async records
+     "=trace-started" and "=trace-stopped".
 
 *** Changes in GDB 7.5
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 45ba78d..76551bb 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27718,6 +27718,12 @@ 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[,notes="@var{notes}"]
+@itemx =trace-stopped[,notes="@var{notes}"]
+Reports that trace was started or stopped.  The optional
+@code{notes="@var{notes}"} part is reported if trace notes or
+stop trace notes are not NULL.
 @end table
 
 @node GDB/MI Frame Information
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index 50038ac..e68aa79 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -246,6 +246,14 @@ The trace state variable @var{name} is deleted.  If @var{name} is
 @code{NULL}, all trace state variables are deleted.
 @end deftypefun
 
+@deftypefun void trace_started (const char *@var{notes})
+The trace was started with trace notes @var{notes}.
+@end deftypefun
+
+@deftypefun void trace_stopped (const char *@var{notes})
+The trace was stopped with stop trace notes @var{notes}.
+@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 572625f..bf6cb96 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -143,9 +143,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 d3c3d81..22897bc 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -67,6 +67,8 @@ 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_started (const char *notes);
+static void mi_trace_stopped (const char *notes);
 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);
@@ -131,6 +133,8 @@ 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_started (mi_trace_started);
+      observer_attach_trace_stopped (mi_trace_stopped);
       observer_attach_solib_loaded (mi_solib_loaded);
       observer_attach_solib_unloaded (mi_solib_unloaded);
       observer_attach_about_to_proceed (mi_about_to_proceed);
@@ -594,6 +598,48 @@ mi_tsv_deleted (const char *name)
   gdb_flush (mi->event_channel);
 }
 
+/* Emit notification on trace was started.  */
+
+static void
+mi_trace_started (const char *notes)
+{
+  struct mi_interp *mi = top_level_interpreter_data ();
+
+  if (mi_suppress_notification.trace)
+    return;
+
+  target_terminal_ours ();
+
+  if (notes != NULL)
+    fprintf_unfiltered (mi->event_channel, "trace-started,"
+			"notes=\"%s\"\n", notes);
+  else
+    fprintf_unfiltered (mi->event_channel, "trace-started\n");
+
+  gdb_flush (mi->event_channel);
+}
+
+/* Emit notification on trace was stopped.  */
+
+static void
+mi_trace_stopped (const char *notes)
+{
+  struct mi_interp *mi = top_level_interpreter_data ();
+
+  if (mi_suppress_notification.trace)
+    return;
+
+  target_terminal_ours ();
+
+  if (notes != NULL)
+    fprintf_unfiltered (mi->event_channel, "trace-stopped,"
+			"notes=\"%s\"\n", notes);
+  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 a815fbe..d56ce6a 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..0b27eb9
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/mi-trace-changed.exp
@@ -0,0 +1,84 @@
+# Copyright 2012 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 <http://www.gnu.org/licenses/>.
+
+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"
+
+	mi_gdb_test "set trace-notes foo" \
+	    ".*=cmd-param-changed,param=\"trace-notes\",value=\"foo\".*\\^done" \
+	    "set trace notes"
+	mi_gdb_test "-trace-start" "-trace-start\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,notes=\"foo\".*\\^done" "start trace notification 1"
+	mi_gdb_test "tstop" ".*=trace-stopped\\\\n\r\n\\^done" \
+	    "stop trace notification 1"
+
+	mi_gdb_test "set trace-stop-notes bar" \
+	    ".*=cmd-param-changed,param=\"trace-stop-notes\",value=\"bar\".*\\^done" \
+	    "set trace stop notes"
+	mi_gdb_test "tstart" \
+	    ".*=trace-started,notes=\"foo\".*\\^done" "start trace notification 2"
+	mi_gdb_test "tstop" ".*=trace-stopped,notes=\"bar\".*\\^done" \
+	    "stop trace notification 2"
+
+	mi_gdb_exit
+    }
+}
+
+test_normal_tstart_stop
+
+return 0
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 6e55d57..d6b94e4 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1820,6 +1820,8 @@ start_tracing (char *notes)
   /* Now insert traps and begin collecting data.  */
   target_trace_start ();
 
+  observer_notify_trace_started (notes);
+
   /* Reset our local state.  */
   set_traceframe_num (-1);
   set_tracepoint_num (-1);
@@ -1905,6 +1907,8 @@ stop_tracing (char *note)
 
   /* Should change in response to reply?  */
   current_trace_status ()->running = 0;
+
+  observer_notify_trace_stopped (note);
 }
 
 /* tstatus command */
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]