[committed]: [PATCH 1/2] MI notification on tsv created and deleted.

Yao Qi
2012-09-18T12:19:08Z

On 09/13/2012 01:47 AM, Eli Zaretskii wrote:
>> From: Yao Qi <yao@codesourcery.com>
>> Date: Wed, 12 Sep 2012 15:15:17 +0800
>>
>> +@item =tsv-deleted,name=@var{name}
>> +Reports that the trace state variable @var{name} is deleted. If
>> +@var{name} is @code{NULL}, all trace state variables are deleted.
>
> From the code I glean that the last sentence is incorrect: when all
> tsv's are deleted, the notification is
>
> =tsv-deleted
>
> without the "name=" part.
>
> OK for the documentation parts, provided that you fix the above.
>

It is fixed, and this is what I committed.

--
Yao

gdb/doc:

* gdb.texinfo (GDB/MI Async Records): Document new MI
notifications '=tsv-created' and '=tsv-deleted'.
* observer.texi (GDB Observers): New observer tsv_created and
tsv_deleted.

gdb:

* mi/mi-interp.c: Declare mi_tsv_created and mi_tsv_deleted.
(mi_interpreter_init): Call observer_attach_tsv_created and
observer_attach_tsv_deleted.
(mi_tsv_created, mi_tsv_deleted): New.
* tracepoint.c (delete_trace_state_variable): Call
observer_notify_tsv_deleted.
(trace_variable_command): Call observer_notify_tsv_created.
(delete_trace_variable_command): Call
observer_notify_tsv_deleted.
(create_tsv_from_upload): Call observer_notify_tsv_created.
* NEWS: Mention it.

gdb/testsuite:

gdb.trace/mi-tsv-changed.exp: New.
---
gdb/NEWS | 2 +
gdb/doc/gdb.texinfo | 9 ++
gdb/doc/observer.texi | 9 ++
gdb/mi/mi-interp.c | 38 ++++++
gdb/testsuite/gdb.trace/mi-tsv-changed.exp | 171 ++++++++++++++++++++++++++++
gdb/tracepoint.c | 8 ++
6 files changed, 237 insertions(+), 0 deletions(-)
create mode 100644 gdb/testsuite/gdb.trace/mi-tsv-changed.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index 126c2af..dad72af 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -45,6 +45,8 @@ py [command]
"=cmd-param-changed".
** Traceframe changes caused by command "tfind" are now notified using
new async record "=traceframe-changed".
+ ** The creation and deletion of trace state variables are now notified
+ using new async records "=tsv-created" and "=tsv-deleted".

*** Changes in GDB 7.5

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ee03521..cd4513b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27639,6 +27639,15 @@ Reports that the trace frame was changed and its new number is
@var{tfnum}. The number of the tracepoint associated with this trace
frame is @var{tpnum}.

+@item =tsv-created,name=@var{name},value=@var{value}
+Reports that the new trace state variable @var{name} is created with
+value @var{value}.
+
+@item =tsv-deleted,name=@var{name}
+@itemx =tsv-deleted
+Reports that the trace state variable @var{name} is deleted or all
+trace state variables are deleted.
+
@item =breakpoint-created,bkpt=@{...@}
@itemx =breakpoint-modified,bkpt=@{...@}
@itemx =breakpoint-deleted,id=@var{number}
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index 4270286..09aa91f 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -242,7 +242,16 @@ The parameter of some @code{set} commands in console are changed. This
method is called after a command @code{set @var{param} @var{value}}.
@var{param} is the parameter of @code{set} command, and @var{value}
is the value of changed parameter.
+@end deftypefun
+
+@deftypefun void tsv_created (const char *@var{name}, LONGEST @var{value})
+The new trace state variable @var{name} is created with value
+@var{value}.
+@end deftypefun

+@deftypefun void tsv_deleted (const char *@var{name})
+The trace state variable @var{name} is deleted. If @var{name} is
+@code{NULL}, all trace state variables are deleted.
@end deftypefun

@deftypefun void test_notification (int @var{somearg})
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 9537aac..5c37bc7 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -69,6 +69,8 @@ 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);
static void mi_traceframe_changed (int tfnum, int tpnum);
+static void mi_tsv_created (const char *name, LONGEST value);
+static void mi_tsv_deleted (const char *name);
static void mi_breakpoint_created (struct breakpoint *b);
static void mi_breakpoint_deleted (struct breakpoint *b);
static void mi_breakpoint_modified (struct breakpoint *b);
@@ -128,6 +130,8 @@ mi_interpreter_init (struct interp *interp, int top_level)
observer_attach_solib_unloaded (mi_solib_unloaded);
observer_attach_about_to_proceed (mi_about_to_proceed);
observer_attach_traceframe_changed (mi_traceframe_changed);
+ observer_attach_tsv_created (mi_tsv_created);
+ observer_attach_tsv_deleted (mi_tsv_deleted);
observer_attach_breakpoint_created (mi_breakpoint_created);
observer_attach_breakpoint_deleted (mi_breakpoint_deleted);
observer_attach_breakpoint_modified (mi_breakpoint_modified);
@@ -537,6 +541,40 @@ mi_traceframe_changed (int tfnum, int tpnum)
gdb_flush (mi->event_channel);
}

+/* Emit notification on creating a trace state variable. */
+
+static void
+mi_tsv_created (const char *name, LONGEST value)
+{
+ struct mi_interp *mi = top_level_interpreter_data ();
+
+ target_terminal_ours ();
+
+ fprintf_unfiltered (mi->event_channel, "tsv-created,"
+ "name=\"%s\",value=\"%s\"\n",
+ name, plongest (value));
+
+ gdb_flush (mi->event_channel);
+}
+
+/* Emit notification on deleting a trace state variable. */
+
+static void
+mi_tsv_deleted (const char *name)
+{
+ struct mi_interp *mi = top_level_interpreter_data ();
+
+ target_terminal_ours ();
+
+ if (name != NULL)
+ fprintf_unfiltered (mi->event_channel, "tsv-deleted,"
+ "name=\"%s\"\n", name);
+ else
+ fprintf_unfiltered (mi->event_channel, "tsv-deleted\n");
+
+ gdb_flush (mi->event_channel);
+}
+
/* Emit notification about a created breakpoint. */

static void
diff --git a/gdb/testsuite/gdb.trace/mi-tsv-changed.exp b/gdb/testsuite/gdb.trace/mi-tsv-changed.exp
new file mode 100644
index 0000000..411efad
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/mi-tsv-changed.exp
@@ -0,0 +1,171 @@
+# 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 trace-support.exp
+load_lib mi-support.exp
+
+standard_testfile actions.c
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
+ executable {debug nowarnings}] != "" } {
+ untested mi-tsv-changed.exp
+ return -1
+}
+
+# Test notifications on creating and deleting TSV.
+
+proc test_create_delete_tsv { } {with_test_prefix "create delete" {
+ global binfile
+ global decimal
+
+ if [mi_gdb_start] {
+ return
+ }
+ mi_gdb_load ${binfile}
+
+ mi_gdb_test "tvariable \$tvar1" \
+ ".*=tsv-created,name=\"tvar1\",value=\"0\"\\\\n.*\\^done" \
+ "tvariable \$tvar1"
+ mi_gdb_test "tvariable \$tvar2 = 45" \
+ ".*=tsv-created,name=\"tvar2\",value=\"45\"\\\\n.*\\^done" \
+ "tvariable \$tvar2"
+
+ mi_gdb_test "delete tvariable \$tvar2" \
+ ".*=tsv-deleted,name=\"tvar2\"\\\\n.*\\^done" \
+ "delete tvariable \$tvar2"
+
+ mi_gdb_test "delete tvariable" \
+ ".*=tsv-deleted\\\\n.*\\^done" \
+ "delete all tvariables"
+
+}}
+
+
+# Test when GDB connects to a disconnected stub, existing TSVs in
+# remote stub can be uploaded to GDB, and GDB emits MI notification
+# for new uploaded TSVs.
+
+proc test_upload_tsv { } { with_test_prefix "upload" {
+
+ global gdbserver_reconnect_p
+ global gdb_prompt
+ global testfile
+ global decimal
+
+ set gdbserver_reconnect_p 1
+ if { [info proc gdb_reconnect] == "" } {
+ return 0
+ }
+
+ clean_restart $testfile
+ if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+ }
+
+ gdb_test "tvariable \$tvar1" \
+ "Trace state variable \\\$tvar1 created, with initial value 0." \
+ "Create a trace state variable"
+
+ gdb_test "tvariable \$tvar2 = 45" \
+ "Trace state variable \\\$tvar2 created, with initial value 45." \
+ "Create a trace state variable with initial value"
+ # Define a tracepoint otherwise tracing cannot be started.
+ gdb_test "trace main" "Tracepoint $decimal at .*"
+ gdb_test_no_output "tstart" "start trace experiment"
+
+ set test "disconnect"
+ gdb_test_multiple "disconnect" $test {
+ -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
+ pass $test
+
+ set test "disconnected"
+ gdb_test_multiple "y" $test {
+ -re "$gdb_prompt $" {
+ pass "$test"
+ }
+ }
+ }
+ }
+
+ gdb_exit
+
+ if [mi_gdb_start] {
+ return
+ }
+
+ global srcdir
+ global subdir
+ global binfile
+
+ mi_gdb_reinitialize_dir $srcdir/$subdir
+ mi_gdb_load ${binfile}
+
+ global gdbserver_protocol
+ global gdbserver_gdbport
+
+ send_gdb "47-target-select $gdbserver_protocol $gdbserver_gdbport\n"
+
+ global mi_gdb_prompt
+ set tsv1_created 0
+ set tsv2_created 0
+ gdb_expect {
+ -re "=tsv-created,name=\"tvar1\",value=\"0\"" {
+ set tsv1_created 1
+ exp_continue
+ }
+ -re "=tsv-created,name=\"tvar2\",value=\"45\"" {
+ set tsv2_created 1
+ exp_continue
+ }
+ -re ".*${mi_gdb_prompt}" {
+
+ }
+ }
+
+ if $tsv1_created {
+ pass "tsv1 created"
+ } else {
+ fail "tsv1 created"
+ }
+ if $tsv2_created {
+ pass "tsv2 created"
+ } else {
+ fail "tsv2 created"
+ }
+
+ set gdbserver_reconnect_p 0
+}}
+
+ test_create_delete_tsv
+
+# Test target supports tracepoints or not.
+
+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 "Current target does not support trace"
+ return -1;
+}
+
+gdb_exit
+
+test_upload_tsv
+
+return 0
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 296999b..bdd6f50 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -359,6 +359,9 @@ delete_trace_state_variable (const char *name)
{
xfree ((void *)tsv->name);
VEC_unordered_remove (tsv_s, tvariables, ix);
+
+ observer_notify_tsv_deleted (name);
+
return;
}

@@ -423,6 +426,8 @@ trace_variable_command (char *args, int from_tty)
tsv = create_trace_state_variable (internalvar_name (intvar));
tsv->initial_value = initval;

+ observer_notify_tsv_created (tsv->name, initval);
+
printf_filtered (_("Trace state variable $%s "
"created, with initial value %s.\n"),
tsv->name, plongest (tsv->initial_value));
@@ -442,6 +447,7 @@ delete_trace_variable_command (char *args, int from_tty)
if (query (_("Delete all trace state variables? ")))
VEC_free (tsv_s, tvariables);
dont_repeat ();
+ observer_notify_tsv_deleted (NULL);
return;
}

@@ -3551,6 +3557,8 @@ create_tsv_from_upload (struct uploaded_tsv *utsv)
tsv->initial_value = utsv->initial_value;
tsv->builtin = utsv->builtin;

+ observer_notify_tsv_created (tsv->name, tsv->initial_value);
+
do_cleanups (old_chain);

return tsv;
--
1.7.7.6