This is the mail archive of the gdb-cvs@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]

[binutils-gdb] [C++] breakpoint.c: "no memory" software watchpoints and enum casts


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c6d811243634c84e185a25faf33491ee1a5f900a

commit c6d811243634c84e185a25faf33491ee1a5f900a
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Nov 19 14:32:53 2015 +0000

    [C++] breakpoint.c: "no memory" software watchpoints and enum casts
    
    Fixes:
    
     src/gdb/breakpoint.c: In function â??void update_watchpoint(watchpoint*, int)â??:
     src/gdb/breakpoint.c:2147:31: error: invalid conversion from â??intâ?? to â??target_hw_bp_typeâ?? [-fpermissive]
         base->loc->watchpoint_type = -1;
    				^
    
    Seems better to rely on "address == -1 && length == -1" than on a enum
    value that's not really part of the set of supposedly valid enum
    values.  Also, factor that out to separate functions for better
    localization of the concept.
    
    gdb/ChangeLog:
    2015-11-19  Pedro Alves  <palves@redhat.com>
    
    	* breakpoint.c (software_watchpoint_add_no_memory_location)
    	(is_no_memory_software_watchpoint): New functions.
    	(update_watchpoint): Use
    	software_watchpoint_add_memoryless_location.
    	(breakpoint_address_bits): Use is_no_memory_software_watchpoint.

Diff:
---
 gdb/ChangeLog    |  8 ++++++++
 gdb/breakpoint.c | 49 ++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4d799d0..5cc0666 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2015-11-19  Pedro Alves  <palves@redhat.com>
+
+	* breakpoint.c (software_watchpoint_add_no_memory_location)
+	(is_no_memory_software_watchpoint): New functions.
+	(update_watchpoint): Use
+	software_watchpoint_add_memoryless_location.
+	(breakpoint_address_bits): Use is_no_memory_software_watchpoint.
+
 2015-11-19  Simon Marchi  <simon.marchi@ericsson.com>
 	    Pedro Alves  <palves@redhat.com>
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 5863573..1425d2d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1775,6 +1775,36 @@ extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
   return bit_val;
 }
 
+/* Allocate a dummy location and add it to B, which must be a software
+   watchpoint.  This is required because even if a software watchpoint
+   is not watching any memory, bpstat_stop_status requires a location
+   to be able to report stops.  */
+
+static void
+software_watchpoint_add_no_memory_location (struct breakpoint *b,
+					    struct program_space *pspace)
+{
+  gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
+
+  b->loc = allocate_bp_location (b);
+  b->loc->pspace = pspace;
+  b->loc->address = -1;
+  b->loc->length = -1;
+}
+
+/* Returns true if B is a software watchpoint that is not watching any
+   memory (e.g., "watch $pc").  */
+
+static int
+is_no_memory_software_watchpoint (struct breakpoint *b)
+{
+  return (b->type == bp_watchpoint
+	  && b->loc != NULL
+	  && b->loc->next == NULL
+	  && b->loc->address == -1
+	  && b->loc->length == -1);
+}
+
 /* Assuming that B is a watchpoint:
    - Reparse watchpoint expression, if REPARSE is non-zero
    - Evaluate expression and store the result in B->val
@@ -2138,14 +2168,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 	 bpstat_stop_status requires a location to be able to report
 	 stops, so make sure there's at least a dummy one.  */
       if (b->base.type == bp_watchpoint && b->base.loc == NULL)
-	{
-	  struct breakpoint *base = &b->base;
-	  base->loc = allocate_bp_location (base);
-	  base->loc->pspace = frame_pspace;
-	  base->loc->address = -1;
-	  base->loc->length = -1;
-	  base->loc->watchpoint_type = -1;
-	}
+	software_watchpoint_add_no_memory_location (&b->base, frame_pspace);
     }
   else if (!within_current_scope)
     {
@@ -6667,15 +6690,15 @@ breakpoint_address_bits (struct breakpoint *b)
   int print_address_bits = 0;
   struct bp_location *loc;
 
+  /* Software watchpoints that aren't watching memory don't have an
+     address to print.  */
+  if (is_no_memory_software_watchpoint (b))
+    return 0;
+
   for (loc = b->loc; loc; loc = loc->next)
     {
       int addr_bit;
 
-      /* Software watchpoints that aren't watching memory don't have
-	 an address to print.  */
-      if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
-	continue;
-
       addr_bit = gdbarch_addr_bit (loc->gdbarch);
       if (addr_bit > print_address_bits)
 	print_address_bits = addr_bit;


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