[PATCH 7/7] new notification "TEST".

Yao Qi yao@codesourcery.com
Tue Oct 23 11:27:00 GMT 2012


This patch is only to present how do we add a new type of notifcation
in the future, and to test two types of notifications coexist together
for testing purpose.  In each time GDB fetches registers, a new event
is pushed, and GDBserver will send a notification %Test to GDB.

This patch is not for committing to CVS trunk.

gdb/gdbserver:

2012-10-23  Yao Qi  <yao@codesourcery.com>

   	* linux-low.c (linux_fetch_registers): Call circular_queue_enque
	and async_file_mark.
	* notif.c (notif_process_vtested): New.
	(notif_test): New variable.
	(notfi_packets): Add new element 'notif_test'.
	* notif.h (notif_type): New enum 'NOTIF_TEST'.
	* server.c (handle_target_event): Handle 'NOTIF_TEST'.

gdb:

2012-10-23  Yao Qi  <yao@codesourcery.com>

	* remote-notif.c (struct test_reply): New.
	(remote_notif_parse_test): New.
	(remote_notif_ack_test): New.
	(remote_notif_alloc_reply_test): New.
	(notif_packet_test): New variable.
	(notifs): New element 'notif_packet_test'.
---
 gdb/gdbserver/linux-low.c |    6 ++++++
 gdb/gdbserver/notif.c     |   15 +++++++++++++++
 gdb/gdbserver/notif.h     |    3 ++-
 gdb/remote-notif.c        |   41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 7c82eab..a09bddd 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4335,6 +4335,12 @@ linux_fetch_registers (struct regcache *regcache, int regno)
   int use_regsets;
   int all = 0;
 
+  /* Only for test.  */
+  if (notif_test.queue != NULL)
+    notif_process (&notif_test,
+		   ((struct inferior_list_entry *)current_inferior)->id,
+		   NULL);
+
   if (regno == -1)
     {
       if (the_low_target.fetch_register != NULL)
diff --git a/gdb/gdbserver/notif.c b/gdb/gdbserver/notif.c
index eede13e..bd2d01d 100644
--- a/gdb/gdbserver/notif.c
+++ b/gdb/gdbserver/notif.c
@@ -55,9 +55,21 @@
 
 #include "notif.h"
 
+static void
+notif_reply_test (struct notif_reply *reply, char *own_buf)
+{
+  strcpy (own_buf, "CESHI");
+}
+
+struct notif notif_test =
+{
+  "vTested", "NTest", NOTIF_TEST, NULL, notif_reply_test
+};
+
 static struct notif *notif_packets[] =
 {
   &notif_stop,
+  &notif_test,
   NULL,
 };
 
@@ -145,6 +157,9 @@ notif_process (struct notif *np, ptid_t ptid, void *data)
 	new_notif = (struct notif_reply *) vstop_notif;
       }
       break;
+    case NOTIF_TEST:
+      new_notif = xmalloc (sizeof (struct notif_reply));
+      break;
     default:
       error ("Unknown notification type");
     }
diff --git a/gdb/gdbserver/notif.h b/gdb/gdbserver/notif.h
index bf45910..f53255e 100644
--- a/gdb/gdbserver/notif.h
+++ b/gdb/gdbserver/notif.h
@@ -41,7 +41,7 @@ struct vstop_notif
   struct target_waitstatus status;
 };
 
-enum notif_type { NOTIF_STOP };
+enum notif_type { NOTIF_STOP, NOTIF_TEST };
 
 /* A type notification to GDB.  An object of 'struct notif' represents
    a type of notification.  */
@@ -78,6 +78,7 @@ void notif_queued_replies_discard_all (int pid);
 void notif_process (struct notif *np, ptid_t ptid, void *data);
 void notif_reply_enque (struct notif *notif, struct notif_reply *reply);
 
+extern struct notif notif_test;
 DECLARE_QUEUE_P (notif_reply_p);
 
 void initialize_notif (void);
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index adeb2c7..154cffc 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -43,11 +43,52 @@
 
 unsigned int notif_debug = 0;
 
+struct test_reply
+{
+  struct notif_reply base;
+};
+
+static void
+remote_notif_parse_test (struct notif *self, char *buf, void *data)
+{
+  if (strncmp (buf, "CESHI", 5) != 0)
+    error (_("'CESHI' is expected"));
+}
+
+static void
+remote_notif_ack_test (struct notif *self, char *buf, void *data)
+{
+  struct notif_reply *reply = (struct notif_reply *) data;
+
+  /* acknowledge */
+  putpkt ((char *) self->ack_command);
+}
+
+static struct notif_reply *
+remote_notif_alloc_reply_test (void)
+{
+  struct notif_reply *reply = xmalloc (sizeof (struct test_reply));
+
+  reply->dtr = NULL;
+
+  return reply;
+}
+
+static struct notif notif_packet_test =
+{
+  "NTest", "vTested",
+  remote_notif_parse_test,
+  remote_notif_ack_test,
+  remote_notif_alloc_reply_test,
+  NULL, NULL,
+};
+
 /* Supported notifications.  */
 
 static struct notif *notifs[] =
 {
   (struct notif *) &notif_packet_stop,
+  &notif_packet_test,
 };
 
 static void do_notif_reply_xfree (void *arg);
-- 
1.7.7.6



More information about the Gdb-patches mailing list