public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 15/23] Make breakpoint_address_bits look at the location kind
Date: Mon, 16 May 2022 19:40:22 +0100	[thread overview]
Message-ID: <20220516184030.665489-16-pedro@palves.net> (raw)
In-Reply-To: <20220516184030.665489-1-pedro@palves.net>

Software watchpoints allocate a special dummy location using
software_watchpoint_add_no_memory_location, and then
breakpoint_address_bits checks whether the location is that special
location to decide whether the location has a meaninful address to
print.

Introduce a new bp_loc_software_watchpoint location kind, and make
breakpoint_address_bits use bl_address_is_meaningful instead, which
returns false for bp_loc_other, which is in accordance with we
document for bp_location::address:

  /* (... snip ...)  Valid for all types except
     bp_loc_other.  */
  CORE_ADDR address = 0;

Rename software_watchpoint_add_no_memory_location to
add_dummy_location, and simplify it.  This will be used by catchpoints
too in a following patch.

Note that neither "info breakpoints" nor "maint info breakpoints"
actually prints the addresses of watchpoints, but I think it would be
useful to do so in "maint info breakpoints".  This approach let's us
implement that in the future.

Change-Id: I50e398f66ef618c31ffa662da755eaba6295aed7
---
 gdb/breakpoint.c | 59 ++++++++++++++++++------------------------------
 gdb/breakpoint.h |  1 +
 2 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6e24137ec4b..6dfb89f51bc 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -164,6 +164,8 @@ static std::vector<symtab_and_line> bkpt_probe_decode_location
       struct event_location *location,
       struct program_space *search_pspace);
 
+static bool bl_address_is_meaningful (bp_location *loc);
+
 /* update_global_location_list's modes of operation wrt to whether to
    insert locations now.  */
 enum ugll_insert_mode
@@ -1830,34 +1832,18 @@ 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.  */
+/* Allocate a dummy location and add it to B.  This is required
+   because 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)
+add_dummy_location (struct breakpoint *b,
+		    struct program_space *pspace)
 {
-  gdb_assert (b->type == bp_watchpoint && b->loc == NULL);
+  gdb_assert (b->loc == NULL);
 
-  b->loc = b->allocate_location ();
+  b->loc = new bp_location (b, bp_loc_other);
   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 bool
-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:
@@ -2197,7 +2183,7 @@ update_watchpoint (struct watchpoint *b, int reparse)
 	  else
 	    b->type = bp_watchpoint;
 
-	  loc_type = (b->type == bp_watchpoint? bp_loc_other
+	  loc_type = (b->type == bp_watchpoint? bp_loc_software_watchpoint
 		      : bp_loc_hardware_watchpoint);
 	  for (bp_location *bl : b->locations ())
 	    bl->loc_type = loc_type;
@@ -2208,7 +2194,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->type == bp_watchpoint && b->loc == NULL)
-	software_watchpoint_add_no_memory_location (b, frame_pspace);
+	add_dummy_location (b, frame_pspace);
     }
   else if (!within_current_scope)
     {
@@ -3840,11 +3826,12 @@ detach_breakpoints (ptid_t ptid)
 
       /* This function must physically remove breakpoints locations
 	 from the specified ptid, without modifying the breakpoint
-	 package's state.  Locations of type bp_loc_other are only
-	 maintained at GDB side.  So, there is no need to remove
-	 these bp_loc_other locations.  Moreover, removing these
+	 package's state.  Locations of type bp_loc_other and
+	 bp_loc_software_watchpoint are only maintained at GDB side,
+	 so there is no need to remove them.  Moreover, removing these
 	 would modify the breakpoint package's state.  */
-      if (bl->loc_type == bp_loc_other)
+      if (bl->loc_type == bp_loc_other
+	  || bl->loc_type == bp_loc_software_watchpoint)
 	continue;
 
       if (bl->inserted)
@@ -5798,7 +5785,8 @@ bpstat_what (bpstat *bs_head)
 	    {
 	      /* Some catchpoints are implemented with breakpoints.
 		 For those, we need to step over the breakpoint.  */
-	      if (bs->bp_location_at->loc_type != bp_loc_other)
+	      if (bs->bp_location_at->loc_type == bp_loc_software_breakpoint
+		  || bs->bp_location_at->loc_type == bp_loc_hardware_breakpoint)
 		this_action = BPSTAT_WHAT_SINGLE;
 	    }
 	  break;
@@ -6557,16 +6545,12 @@ breakpoint_address_bits (struct breakpoint *b)
 {
   int print_address_bits = 0;
 
-  /* Software watchpoints that aren't watching memory don't have an
-     address to print.  */
-  if (is_no_memory_software_watchpoint (b))
-    return 0;
-
   for (bp_location *loc : b->locations ())
     {
-      int addr_bit;
+      if (!bl_address_is_meaningful (loc))
+	continue;
 
-      addr_bit = gdbarch_addr_bit (loc->gdbarch);
+      int addr_bit = gdbarch_addr_bit (loc->gdbarch);
       if (addr_bit > print_address_bits)
 	print_address_bits = addr_bit;
     }
@@ -7161,6 +7145,7 @@ bp_location_from_bp_type (bptype type)
     case bp_access_watchpoint:
       return bp_loc_hardware_watchpoint;
     case bp_watchpoint:
+      return bp_loc_software_watchpoint;
     case bp_catchpoint:
     case bp_tracepoint:
     case bp_fast_tracepoint:
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index a4ead8b4d4e..7375e976dc6 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -314,6 +314,7 @@ enum bp_loc_type
 {
   bp_loc_software_breakpoint,
   bp_loc_hardware_breakpoint,
+  bp_loc_software_watchpoint,
   bp_loc_hardware_watchpoint,
   bp_loc_other			/* Miscellaneous...  */
 };
-- 
2.36.0


  parent reply	other threads:[~2022-05-16 18:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 18:40 [PATCH 00/23] More breakpoints cleanups Pedro Alves
2022-05-16 18:40 ` [PATCH 01/23] add_location_to_breakpoint -> breakpoint::add_location Pedro Alves
2022-05-16 18:40 ` [PATCH 02/23] Make structs breakpoint/base_breakpoint/catchpoint be abstract Pedro Alves
2022-05-16 18:40 ` [PATCH 03/23] ranged_breakpoint: don't use init_raw_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 04/23] ranged_breakpoint, use install_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 05/23] ranged_breakpoint - move initialization to ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 06/23] Make a few functions work with base_breakpoint instead of breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 07/23] More breakpoint_ops parameter elimination Pedro Alves
2022-05-16 18:40 ` [PATCH 08/23] Remove "internal" parameter from a couple functions Pedro Alves
2022-05-16 18:40 ` [PATCH 09/23] init_breakpoint_sal -> base_breakpoint::base_breakpoint Pedro Alves
2022-05-20 13:40   ` Lancelot SIX
2022-05-20 19:20     ` Pedro Alves
2022-05-16 18:40 ` [PATCH 10/23] Make ada_catchpoint_location's owner ctor parameter be ada_catchpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 11/23] Convert init_ada_exception_catchpoint to a ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 12/23] Refactor set_internal_breakpoint / internal_breakpoint ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 13/23] Refactor momentary breakpoints, eliminate set_raw_breakpoint{, _without_location} Pedro Alves
2022-05-16 18:40 ` [PATCH 14/23] Make exception_catchpoint inherit base_breakpoint instead of catchpoint Pedro Alves
2022-05-16 18:40 ` Pedro Alves [this message]
2022-05-16 18:40 ` [PATCH 16/23] Make catchpoint inherit breakpoint, eliminate init_raw_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 17/23] Move common bits of catchpoint/exception_catchpoint to breakpoint's ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 18/23] Move add_location(sal) to base_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 19/23] Add/tweak intro comments of struct breakpoint and several subclasses Pedro Alves
2022-05-16 18:40 ` [PATCH 20/23] Momentary breakpoints should have no breakpoint number Pedro Alves
2022-05-20 16:00   ` Tom Tromey
2022-05-20 19:25     ` Pedro Alves
2022-05-16 18:40 ` [PATCH 21/23] Make sure momentary breakpoints are always thread-specific Pedro Alves
2022-05-16 18:40 ` [PATCH 22/23] Test "set multiple-symbols on" creating multiple breakpoints Pedro Alves
2022-05-16 18:40 ` [PATCH 23/23] Rename base_breakpoint -> code_breakpoint Pedro Alves
2022-05-20 16:05   ` Tom Tromey
2022-05-20 16:06 ` [PATCH 00/23] More breakpoints cleanups Tom Tromey
2022-05-20 19:43   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220516184030.665489-16-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).