public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Merge probe and ordinary breakpoints
@ 2022-04-29 22:24 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-29 22:24 UTC (permalink / raw)
  To: gdb-cvs

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

commit 5d926615e9684d1f9a95801106300ade64548dcc
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Jan 16 17:25:52 2022 -0700

    Merge probe and ordinary breakpoints
    
    Right now, probe breakpoints are handled by a separate ops object.
    However, they differ only in a small way from ordinary breakpoints,
    and furthermore can be distinguished by their "probe" object.
    
    This patch merges the two cases.  This avoids having to introduce a
    new bp_ constant (which can be quite subtle to do correctly) and a new
    subclass.

Diff:
---
 gdb/breakpoint.c | 58 +++++++++++++++++++++++++-------------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 67b9313ad83..c7fa53c53e2 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -177,6 +177,11 @@ static void decref_bp_location (struct bp_location **loc);
 
 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
 
+static std::vector<symtab_and_line> bkpt_probe_decode_location
+     (struct breakpoint *b,
+      struct event_location *location,
+      struct program_space *search_pspace);
+
 /* update_global_location_list's modes of operation wrt to whether to
    insert locations now.  */
 enum ugll_insert_mode
@@ -11845,16 +11850,32 @@ base_breakpoint::insert_location (struct bp_location *bl)
   bl->target_info.kind = breakpoint_kind (bl, &addr);
   bl->target_info.placed_address = addr;
 
+  int result;
   if (bl->loc_type == bp_loc_hardware_breakpoint)
-    return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
+    result = target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
-    return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
+    result = target_insert_breakpoint (bl->gdbarch, &bl->target_info);
+
+  if (result == 0 && bl->probe.prob != nullptr)
+    {
+      /* The insertion was successful, now let's set the probe's semaphore
+	 if needed.  */
+      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
+    }
+
+  return result;
 }
 
 int
 base_breakpoint::remove_location (struct bp_location *bl,
 				  enum remove_bp_reason reason)
 {
+  if (bl->probe.prob != nullptr)
+    {
+      /* Let's clear the semaphore before removing the location.  */
+      bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
+    }
+
   if (bl->loc_type == bp_loc_hardware_breakpoint)
     return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
@@ -12001,6 +12022,9 @@ std::vector<symtab_and_line>
 base_breakpoint::decode_location (struct event_location *location,
 				  struct program_space *search_pspace)
 {
+  if (event_location_type (location) == PROBE_LOCATION)
+    return bkpt_probe_decode_location (this, location, search_pspace);
+
   return decode_location_default (this, location, search_pspace);
 }
 
@@ -12139,33 +12163,6 @@ longjmp_breakpoint::~longjmp_breakpoint ()
     tp->initiating_frame = null_frame_id;
 }
 
-/* Specific methods for probe breakpoints.  */
-
-static int
-bkpt_probe_insert_location (struct bp_location *bl)
-{
-  int v = bl->owner->insert_location (bl);
-
-  if (v == 0)
-    {
-      /* The insertion was successful, now let's set the probe's semaphore
-	 if needed.  */
-      bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch);
-    }
-
-  return v;
-}
-
-static int
-bkpt_probe_remove_location (struct bp_location *bl,
-			    enum remove_bp_reason reason)
-{
-  /* Let's clear the semaphore before removing the location.  */
-  bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch);
-
-  return bl->owner->remove_location (bl, reason);
-}
-
 static void
 bkpt_probe_create_sals_from_location (struct event_location *location,
 				      struct linespec_result *canonical,
@@ -14579,10 +14576,7 @@ initialize_breakpoint_ops (void)
   /* Probe breakpoints.  */
   ops = &bkpt_probe_breakpoint_ops;
   *ops = vtable_breakpoint_ops;
-  ops->insert_location = bkpt_probe_insert_location;
-  ops->remove_location = bkpt_probe_remove_location;
   ops->create_sals_from_location = bkpt_probe_create_sals_from_location;
-  ops->decode_location = bkpt_probe_decode_location;
 
   /* Probe tracepoints.  */
   ops = &tracepoint_probe_breakpoint_ops;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-29 22:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 22:24 [binutils-gdb] Merge probe and ordinary breakpoints Tom Tromey

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).