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] Hardware breakpoint error reporting


Hi,

I've attached a patch to improve error reporting for hardware breakpoint insertion errors on remote targets. Currently the error response coming back over RSP is discarded, and instead the default error:

"... You may have requested too many hardware breakpoints/watchpoints."

is printed, which is often not helpful to users.

Note my copyright assignment is currently in progress.

Thanks,
Mike

Attachment: ChangeLog.txt
Description: Text document

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ab5f324..4c555e0 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2091,6 +2091,8 @@ insert_bp_location (struct bp_location *bl,
 		    int *hw_breakpoint_error)
 {
   int val = 0;
+  char *hw_bp_err_string = NULL;
+  struct gdb_exception e;
 
   if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
     return 0;
@@ -2186,8 +2188,15 @@ insert_bp_location (struct bp_location *bl,
 	  || !(section_is_overlay (bl->section)))
 	{
 	  /* No overlay handling: just set the breakpoint.  */
-
-	  val = bl->owner->ops->insert_location (bl);
+	  TRY_CATCH (e, RETURN_MASK_ALL)
+	    {
+	      val = bl->owner->ops->insert_location (bl);
+	    }
+	  if (e.reason < 0)
+	    {
+	      val = 1;
+	      hw_bp_err_string = (char *) e.message;
+	    }
 	}
       else
 	{
@@ -2221,7 +2230,15 @@ insert_bp_location (struct bp_location *bl,
 	  if (section_is_mapped (bl->section))
 	    {
 	      /* Yes.  This overlay section is mapped into memory.  */
-	      val = bl->owner->ops->insert_location (bl);
+	      TRY_CATCH (e, RETURN_MASK_ALL)
+	        {
+	          val = bl->owner->ops->insert_location (bl);
+	        }
+	      if (e.reason < 0)
+	        {
+	          val = 1;
+	          hw_bp_err_string = (char *) e.message;
+	        }
 	    }
 	  else
 	    {
@@ -2257,11 +2274,20 @@ insert_bp_location (struct bp_location *bl,
 	    {
 	      if (bl->loc_type == bp_loc_hardware_breakpoint)
 		{
-		  *hw_breakpoint_error = 1;
-		  fprintf_unfiltered (tmp_error_stream,
-				      "Cannot insert hardware "
-				      "breakpoint %d.\n",
-				      bl->owner->number);
+                  if (hw_bp_err_string)
+                    {
+                      *hw_breakpoint_error = 2;
+                      fprintf_unfiltered (tmp_error_stream,
+                                          "Cannot insert hardware breakpoint %d: %s.\n",
+                                          bl->owner->number, hw_bp_err_string);
+                    }
+                  else
+                    {
+                      *hw_breakpoint_error = 1;
+                      fprintf_unfiltered (tmp_error_stream,
+                                          "Cannot insert hardware breakpoint %d.\n",
+                                          bl->owner->number);
+                    }
 		}
 	      else
 		{
@@ -2590,7 +2616,7 @@ insert_breakpoint_locations (void)
     {
       /* If a hardware breakpoint or watchpoint was inserted, add a
          message about possibly exhausted resources.  */
-      if (hw_breakpoint_error)
+      if (hw_breakpoint_error == 1)
 	{
 	  fprintf_unfiltered (tmp_error_stream, 
 			      "Could not insert hardware breakpoints:\n\
diff --git a/gdb/remote.c b/gdb/remote.c
index 68864d1..be55828 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -6979,6 +6979,7 @@ putpkt_binary (char *buf, int cnt)
   int ch;
   int tcount = 0;
   char *p;
+  char *message;
 
   /* Catch cases like trying to read memory or listing threads while
      we're waiting for a stop reply.  The remote server wouldn't be
@@ -8100,6 +8101,7 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
   CORE_ADDR addr;
   struct remote_state *rs;
   char *p, *endbuf;
+  char *message;
 
   /* The length field should be set to the size of a breakpoint
      instruction, even though we aren't inserting one ourselves.  */
@@ -8131,6 +8133,13 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
   switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
     {
     case PACKET_ERROR:
+      if (rs->buf[1] == '.')
+        {
+          message = strchr (rs->buf + 2, '.');
+          if (message)
+            error ("%s", message + 1);
+        }
+      return -1;
     case PACKET_UNKNOWN:
       return -1;
     case PACKET_OK:

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