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 4/4] remote notification on itset


Hi,
When GDB connects to remote target, remote target may have some
predefined or builtin itsets, and GDB has to get them uploaded.  For
example, remote target may have some predefined itset for all its
working cores or broken cores.  Since it is possible that some core
stops working, remote target will notify GDB about this with the
updated itsets.  This requires that remote target is able to send
itsets at anytime during connection, and GDB update its itsets.

This patch is to achieve this feature, and it depends on 'general
notification' patches I submitted last week.

  [RCF 0/4] A general notification in GDB RSP
  http://sourceware.org/ml/gdb-patches/2012-08/msg00703.html

The GDBserver side of this patch is a hack to get some notifications
on itsts to exercise the code in GDB side, so don't have to review the
GDBserver part of this patch.

gdb:

2012-08-30  Yao Qi  <yao@codesourcery.com>

	* itset.c (itset_reply): New struct.
	(remote_notif_parse_itset): New.
	(remote_notif_ack_itset): New.
	(remote_notif_alloc_reply_itset): New.
	(notif_packet_itset): New.
	* remote-notif.c (notifs): Add 'notif_packet_itset'.

gdb/gdbserver:

2012-08-30  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add itset.c.
	(OBJS): Add itset.o.
	(itset.o): New rule.
	* itset.c: New.
	* linux-low.c (linux_fetch_registers): Add event to queue for
	itset changes.
	* notif.c (notif_packets): Add 'notif_itset'.
	* notif.h (notif_type): New enum 'NOTIF_ITSET'.
	* server.c (handle_target_event): Handle NOTIF_ITSET.

gdbserver itset notif
---
 gdb/gdbserver/Makefile.in |    5 ++-
 gdb/gdbserver/itset.c     |   62 ++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-low.c |   13 +++++++++
 gdb/gdbserver/notif.c     |    2 +
 gdb/gdbserver/notif.h     |    2 +-
 gdb/gdbserver/server.c    |    3 ++
 gdb/itset.c               |   66 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/remote-notif.c        |    3 ++
 8 files changed, 153 insertions(+), 3 deletions(-)
 create mode 100644 gdb/gdbserver/itset.c

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 68f6b23..9210e56 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -124,7 +124,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/mem-break.c $(srcdir)/proc-service.c \
 	$(srcdir)/proc-service.list $(srcdir)/regcache.c \
 	$(srcdir)/remote-utils.c $(srcdir)/server.c $(srcdir)/target.c \
-	$(srcdir)/thread-db.c $(srcdir)/utils.c \
+	$(srcdir)/thread-db.c $(srcdir)/utils.c $(srcdir)/itset.c \
 	$(srcdir)/linux-arm-low.c $(srcdir)/linux-bfin-low.c \
 	$(srcdir)/linux-cris-low.c $(srcdir)/linux-crisv32-low.c \
 	${srcdir}/i386-low.c $(srcdir)/i387-fp.c \
@@ -153,7 +153,7 @@ SOURCES = $(SFILES)
 TAGFILES = $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS}
 
 OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o target.o \
-	utils.o version.o vec.o gdb_vecs.o \
+	utils.o version.o vec.o gdb_vecs.o itset.o \
 	mem-break.o hostio.o event-loop.o tracepoint.o \
 	xml-utils.o common-utils.o ptid.o buffer.o format.o \
 	dll.o notif.o \
@@ -495,6 +495,7 @@ tracepoint.o: tracepoint.c $(server_h) $(ax_h) $(agent_h) $(gdbthread_h)
 utils.o: utils.c $(server_h)
 gdbreplay.o: gdbreplay.c config.h
 dll.o: dll.c $(server_h)
+itset.o: $(notif_h)
 
 signals.o: ../common/signals.c $(server_h) $(signals_def)
 	$(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
diff --git a/gdb/gdbserver/itset.c b/gdb/gdbserver/itset.c
new file mode 100644
index 0000000..8c55497
--- /dev/null
+++ b/gdb/gdbserver/itset.c
@@ -0,0 +1,62 @@
+/* Builtin ITSET.  */
+#include "notif.h"
+
+struct builtin_itset
+{
+  const char *name;
+  char *spec;
+  /* The status of field <spec>.  0 means <spec> is unchanged, 1 means <spec>
+     is changed, 2 means reply has been queued. When the reply has been
+     ack'ed by GDB, it is set back to 0.  */
+  int changed;
+};
+
+static struct builtin_itset itsets[] =
+{
+  {"working-cores", NULL, 0},
+  {"broken-cores", NULL, 0},
+};
+
+static void
+notif_reply_itset (struct notif_reply *reply, char *own_buf)
+{
+  int i;
+
+  for (i = 0; i < sizeof (itsets) / sizeof (itsets[0]); i++)
+    if (itsets[i].changed)
+      {
+	sprintf (own_buf, "%s:%s;", itsets[i].name, itsets[i].spec);
+	own_buf += strlen (own_buf);
+
+	itsets[i].changed = 0;
+      }
+}
+
+/* Notification %ITSET to send updated builtin ITSETs.  */
+
+struct notif notif_itset =
+{
+  "vITSET", "ITSET", NOTIF_ITSET, NULL, notif_reply_itset,
+};
+
+extern void itset_update_itsets (void);
+
+/* Mark builtin itsets as changed.  */
+
+void
+itset_update_itsets (void)
+{
+  int i;
+  static int counter = 0;
+
+  for (i = 0; i < sizeof (itsets) / sizeof (itsets[0]); i++)
+    {
+      if (itsets[i].spec != NULL)
+	xfree (itsets[i].spec);
+
+      itsets[i].spec = xmalloc (16);
+      xsnprintf (itsets[i].spec, 16, "c%d", counter++);
+
+      itsets[i].changed = 1;
+    }
+}
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index e9752b0..debf47a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4341,6 +4341,19 @@ linux_fetch_registers (struct regcache *regcache, int regno)
   int use_regsets;
   int all = 0;
 
+  if (target_is_async_p ())
+    {
+      /* Only for test.  */
+
+      extern struct notif notif_itset;
+      extern void itset_update_itsets (void);
+
+      itset_update_itsets ();
+      gdb_queue_notif_enque (&notif_itset, &notif_queue);
+      async_file_mark ();
+    }
+
+
   if (regno == -1)
     {
       if (the_low_target.fetch_register != NULL)
diff --git a/gdb/gdbserver/notif.c b/gdb/gdbserver/notif.c
index 838f391..a2fadab 100644
--- a/gdb/gdbserver/notif.c
+++ b/gdb/gdbserver/notif.c
@@ -20,10 +20,12 @@
 #include "notif.h"
 
 extern struct notif notif_stop;
+extern struct notif notif_itset;
 
 static struct notif *notif_packets [] =
 {
   &notif_stop,
+  &notif_itset,
   NULL,
 };
 
diff --git a/gdb/gdbserver/notif.h b/gdb/gdbserver/notif.h
index ac62eab..ce16930 100644
--- a/gdb/gdbserver/notif.h
+++ b/gdb/gdbserver/notif.h
@@ -42,7 +42,7 @@ struct vstop_notif
   struct target_waitstatus status;
 };
 
-enum notif_type { NOTIF_STOP };
+enum notif_type { NOTIF_STOP, NOTIF_ITSET };
 
 /* A notification to GDB.  */
 
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 0b756cd..2a4a117 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3412,6 +3412,9 @@ handle_target_event (int err, gdb_client_data client_data)
 		    new_notif = (struct notif_reply *) vstop_notif;
 		  }
 		  break;
+		case NOTIF_ITSET:
+		  new_notif = xmalloc (sizeof (struct notif_reply));
+		  break;
 		default:
 		  error ("Unknown notification type");
 		}
diff --git a/gdb/itset.c b/gdb/itset.c
index 573f332..b610f7f 100644
--- a/gdb/itset.c
+++ b/gdb/itset.c
@@ -2482,3 +2482,69 @@ Use the 'source' command in another debug session to restore them."),
 	       &save_cmdlist);
   set_cmd_completer (c, filename_completer);
 }
+
+/* Remote notification on ITSET.  */
+#include "remote-notif.h"
+#include "remote.h"
+
+struct itset_reply
+{
+  struct notif_reply base;
+};
+
+static void
+remote_notif_parse_itset (struct notif *self, char *buf, void *data)
+{
+  /* parse the name and spec of itset from BUF.  */
+  char *p = NULL;
+  char *next_p = NULL;
+
+  for (p = buf; p != NULL && *p; p = next_p)
+    {
+      next_p = strchr (p, ';');
+
+      if (next_p != NULL)
+	{
+	  char *spec = strchr (p, ':');
+
+	  if (spec == NULL)
+	    error (_("name:spec is expected"));
+
+	  next_p[0] =0;
+	  spec[0] = 0;
+	  spec++;
+	  next_p++;
+
+	  named_itset_create (p, spec);
+	}
+    }
+}
+
+static void
+remote_notif_ack_itset (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_itset (void)
+{
+  struct notif_reply *reply = xmalloc (sizeof (struct itset_reply));
+
+  reply->dtr = NULL;
+
+  return reply;
+}
+
+struct notif notif_packet_itset =
+{
+  "ITSET", "vITSET",
+  remote_notif_parse_itset,
+  remote_notif_ack_itset,
+  remote_notif_alloc_reply_itset,
+  NULL, NULL,
+};
+
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index 5b1d532..c8c7758 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -27,11 +27,14 @@
 
 extern struct remote_state *get_remote_state (void);
 
+extern struct notif notif_packet_itset;
+
 /* Supported notifications.  */
 
 static struct notif *notifs[] =
 {
   &notif_packet_stop,
+  &notif_packet_itset,
 };
 
 /* Parse the BUF for the expected notification NP, and send packet to
-- 
1.7.7.6


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