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]

Re: [RFC] checking the Z-packet support on gdbserver


Hello Jim,

Thank you for your comment.  

From: Jim Blandy <jimb at codesourcery.com>
Subject: Re: [RFC] checking the Z-packet support on gdbserver
Date: Thu, 13 Sep 2007 10:05:50 -0700

> Emi SUZUKI <emi-suzuki@tjsys.co.jp> writes:
> > Would anyone give me any comments how it should be treated as a whole?
> > Defines another packet for it?  Applies as proposed and notes "it
> > might not work with older versions of gdbserver" ?
> 
> I wonder, would it make sense to have GDB assume that hardware
> watchpoints are *not* available on remote targets, and then have
> gdbserver send a 'qSupported' packet stubfeature that tells GDB that
> hardware watchpoints are okay?

Well, I understood casually that the answer of 'qSupported' packet
would tell the support for the other 'q' packets from the current
implementaion...  According to the description in the info, definitely
it would make sense.  How about the attached?


Meanwhile, I've found the definition below in gdb/config/nm-i386.h.  

  #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(type, cnt, ot) 1

TARGET_CAN_USE_HARDWARE_WATCHPOINT is used in watch_command_1 for
checking if the support of hardware watchpoints are available on the
target.  If it is not defined, the target vector function
'to_can_use_hw_breakpoint' would be called.  So, the above implies
that GDB built for the x86 native target is not supposed to debug the
remote target.  But it should be, to debug a target running on a
remote machine which is the same architecture to the local host,
shouldn't it?
(Although it would not be much necessary in practice...)

Best regards,
-- 
Emi SUZUKI / emi-suzuki at tjsys.co.jp

Index: gdb/gdbserver/server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.56
diff -u -r1.56 server.c
--- gdb/gdbserver/server.c	23 Aug 2007 18:08:48 -0000	1.56
+++ gdb/gdbserver/server.c	14 Sep 2007 09:30:25 -0000
@@ -540,8 +540,21 @@
 	strcat (own_buf, ";qXfer:spu:read+;qXfer:spu:write+");
 
       if (get_features_xml ("target.xml") != NULL)
-	strcat (own_buf, ";qXfer:features:read+");
+ 	strcat (own_buf, ";qXfer:features:read+");
 
+      char type;
+      char buf[8];
+      /* Watchpoints support: the watchpoint type codes are 
+	 described in target.h. */
+      for (type = 2; type < 5; type++)
+	{
+	  if (the_target->watchpoint_support != NULL
+	      && the_target->watchpoint_support (type))
+	    {
+	      sprintf (buf, ";Z%d+", type);
+	      strcat (own_buf, buf);
+	    }
+	}
       return;
     }
 
Index: gdb/gdbserver/linux-low.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.h,v
retrieving revision 1.18
diff -u -r1.18 linux-low.h
--- gdb/gdbserver/linux-low.h	23 Aug 2007 18:08:48 -0000	1.18
+++ gdb/gdbserver/linux-low.h	14 Sep 2007 09:30:19 -0000
@@ -63,6 +63,7 @@
   /* Watchpoint related functions.  See target.h for comments.  */
   int (*insert_watchpoint) (char type, CORE_ADDR addr, int len);
   int (*remove_watchpoint) (char type, CORE_ADDR addr, int len);
+  int (*watchpoint_support) (char type);
   int (*stopped_by_watchpoint) (void);
   CORE_ADDR (*stopped_data_address) (void);
 
Index: gdb/gdbserver/linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.61
diff -u -r1.61 linux-low.c
--- gdb/gdbserver/linux-low.c	4 Sep 2007 21:30:23 -0000	1.61
+++ gdb/gdbserver/linux-low.c	14 Sep 2007 09:30:19 -0000
@@ -1635,6 +1635,16 @@
 }
 
 static int
+linux_watchpoint_support (char type)
+{
+  if (the_low_target.watchpoint_support != NULL)
+    return the_low_target.watchpoint_support (type);
+  else
+    /* Unsupported.  */
+    return 0;
+}
+
+static int
 linux_stopped_by_watchpoint (void)
 {
   if (the_low_target.stopped_by_watchpoint != NULL)
@@ -1721,6 +1731,7 @@
   linux_read_auxv,
   linux_insert_watchpoint,
   linux_remove_watchpoint,
+  linux_watchpoint_support,
   linux_stopped_by_watchpoint,
   linux_stopped_data_address,
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)
Index: gdb/gdbserver/target.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/target.h,v
retrieving revision 1.25
diff -u -r1.25 target.h
--- gdb/gdbserver/target.h	23 Aug 2007 18:08:48 -0000	1.25
+++ gdb/gdbserver/target.h	14 Sep 2007 09:30:29 -0000
@@ -155,6 +155,11 @@
 
   int (*insert_watchpoint) (char type, CORE_ADDR addr, int len);
   int (*remove_watchpoint) (char type, CORE_ADDR addr, int len);
+  
+  /* Check if hardware watchpoints are supported.  
+     Returns 0 on unsupported, else on supported.  
+     The type is coded as mentioned above.  */
+  int (*watchpoint_support) (char type);
 
   /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise.  */
 
Index: gdb/gdbserver/linux-x86-64-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-x86-64-low.c,v
retrieving revision 1.16
diff -u -r1.16 linux-x86-64-low.c
--- gdb/gdbserver/linux-x86-64-low.c	23 Aug 2007 18:08:48 -0000	1.16
+++ gdb/gdbserver/linux-x86-64-low.c	14 Sep 2007 09:30:21 -0000
@@ -174,6 +174,7 @@
   NULL,
   NULL,
   NULL,
+  NULL,
   0,
   "i386:x86-64",
 };
Index: gdb/gdbserver/win32-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v
retrieving revision 1.15
diff -u -r1.15 win32-low.c
--- gdb/gdbserver/win32-low.c	3 Sep 2007 22:17:27 -0000	1.15
+++ gdb/gdbserver/win32-low.c	14 Sep 2007 09:30:34 -0000
@@ -1522,6 +1522,7 @@
   NULL,
   NULL,
   NULL,
+  NULL,
   win32_arch_string
 };
 
Index: gdb/gdbserver/linux-i386-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-i386-low.c,v
retrieving revision 1.13
diff -u -r1.13 linux-i386-low.c
--- gdb/gdbserver/linux-i386-low.c	23 Aug 2007 18:08:48 -0000	1.13
+++ gdb/gdbserver/linux-i386-low.c	14 Sep 2007 09:30:10 -0000
@@ -200,6 +200,7 @@
   NULL,
   NULL,
   NULL,
+  NULL,
   0,
   "i386"
 };
Index: gdb/gdbserver/linux-crisv32-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-crisv32-low.c,v
retrieving revision 1.5
diff -u -r1.5 linux-crisv32-low.c
--- gdb/gdbserver/linux-crisv32-low.c	23 Aug 2007 18:08:48 -0000	1.5
+++ gdb/gdbserver/linux-crisv32-low.c	14 Sep 2007 09:30:10 -0000
@@ -307,6 +307,21 @@
 }
 
 static int
+cris_watchpoint_support (char type)
+{
+  /* Breakpoint/watchpoint types is described in the comment for 
+     cris_insert_watchpoint.  */
+  
+  if (type < '2' || type > '4') 
+    {
+      /* Unsupported.  */
+      return 0;
+    }
+  /* Supported.  */
+  return 1;
+}
+
+static int
 cris_stopped_by_watchpoint (void)
 {
   unsigned long exs;
@@ -373,6 +388,7 @@
   cris_breakpoint_at,
   cris_insert_watchpoint,
   cris_remove_watchpoint,
+  cris_watchpoint_support,
   cris_stopped_by_watchpoint,
   cris_stopped_data_address,
 };
Index: gdb/gdbserver/linux-ppc64-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-ppc64-low.c,v
retrieving revision 1.8
diff -u -r1.8 linux-ppc64-low.c
--- gdb/gdbserver/linux-ppc64-low.c	23 Aug 2007 18:08:48 -0000	1.8
+++ gdb/gdbserver/linux-ppc64-low.c	14 Sep 2007 09:30:21 -0000
@@ -130,5 +130,6 @@
   NULL,
   NULL,
   NULL,
+  NULL,
   1
 };
Index: gdb/gdbserver/spu-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/spu-low.c,v
retrieving revision 1.12
diff -u -r1.12 spu-low.c
--- gdb/gdbserver/spu-low.c	23 Aug 2007 18:08:48 -0000	1.12
+++ gdb/gdbserver/spu-low.c	14 Sep 2007 09:30:27 -0000
@@ -596,6 +596,7 @@
   NULL,
   NULL,
   NULL,
+  NULL,
   spu_arch_string,
   spu_proc_xfer_spu,
 };
Index: gdb/gdbserver/linux-cris-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-cris-low.c,v
retrieving revision 1.5
diff -u -r1.5 linux-cris-low.c
--- gdb/gdbserver/linux-cris-low.c	23 Aug 2007 18:08:48 -0000	1.5
+++ gdb/gdbserver/linux-cris-low.c	14 Sep 2007 09:30:07 -0000
@@ -116,8 +116,4 @@
   cris_reinsert_addr,
   0,
   cris_breakpoint_at,
-  0,
-  0,
-  0,
-  0,
 };
Index: gdb/remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.266
diff -u -r1.266 remote.c
--- gdb/remote.c	23 Aug 2007 18:08:36 -0000	1.266
+++ gdb/remote.c	14 Sep 2007 09:30:06 -0000
@@ -2395,6 +2395,11 @@
     PACKET_qXfer_spu_write },
   { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
     PACKET_QPassSignals },
+  { "Z0", PACKET_DISABLE, remote_supported_packet, PACKET_Z0 },
+  { "Z1", PACKET_DISABLE, remote_supported_packet, PACKET_Z1 },
+  { "Z2", PACKET_DISABLE, remote_supported_packet, PACKET_Z2 },
+  { "Z3", PACKET_DISABLE, remote_supported_packet, PACKET_Z3 },
+  { "Z4", PACKET_DISABLE, remote_supported_packet, PACKET_Z4 },
 };
 
 static void
@@ -5374,6 +5379,39 @@
 		  _("remote_remove_watchpoint: reached end of function"));
 }
 
+static int
+hardware_resouce_to_Z_packet (int type)
+{
+  switch (type)
+    {
+    case bp_hardware_breakpoint:
+      return Z_PACKET_HARDWARE_BP;
+      break;
+    case bp_hardware_watchpoint:
+      return Z_PACKET_WRITE_WP;
+      break;
+    case bp_read_watchpoint:
+      return Z_PACKET_READ_WP;
+      break;
+    case bp_access_watchpoint:
+      return Z_PACKET_ACCESS_WP;
+      break;
+    default:
+      internal_error (__FILE__, __LINE__,
+		      _("hardware_resouce_to_Z_packet: bad watchpoint type %d"), type);
+    }
+}
+
+static int
+remote_check_Zpacket_support (int type)
+{
+  enum Z_packet_type packet = hardware_resouce_to_Z_packet (type);
+
+  if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
+    return 0;
+
+  return 1;
+}
 
 int remote_hw_watchpoint_limit = -1;
 int remote_hw_breakpoint_limit = -1;
@@ -5381,6 +5419,9 @@
 static int
 remote_check_watch_resources (int type, int cnt, int ot)
 {
+  if (! remote_check_Zpacket_support (type))
+    return 0;
+
   if (type == bp_hardware_breakpoint)
     {
       if (remote_hw_breakpoint_limit == 0)

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