public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pedro Alves <palves@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Move add_location(sal) to base_breakpoint
Date: Fri, 20 May 2022 19:43:54 +0000 (GMT)	[thread overview]
Message-ID: <20220520194354.99E43383088B@sourceware.org> (raw)

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

commit 960bc2bd1402bb5e8312e731d6a7f6fe2b6a9863
Author: Pedro Alves <pedro@palves.net>
Date:   Thu May 12 18:58:38 2022 +0100

    Move add_location(sal) to base_breakpoint
    
    After the previous patches, only base_breakpoint subclasses use
    add_location(sal), so we can move it to base_breakpoint (a.k.a. base
    class for code breakpoints).
    
    This requires a few casts here and there, but always at spots where
    you can see from context what the breakpoint's type actually is.
    
    I inlined new_single_step_breakpoint into its only caller exactly for
    this reason.
    
    I did try to propagate more use of base_breakpoint to avoid casts, but
    that turned out unwieldy for this patch.
    
    Change-Id: I49d959322b0fdce5a88a216bb44730fc5dd7c6f8

Diff:
---
 gdb/breakpoint.c | 45 +++++++++++++++++++--------------------------
 gdb/breakpoint.h |  8 ++++----
 gdb/elfread.c    |  6 +++---
 gdb/minsyms.c    |  4 ++--
 gdb/symtab.h     |  5 +++--
 5 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index bfb5cd37ecd..b6e31836df1 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -87,7 +87,7 @@
 static void map_breakpoint_numbers (const char *,
 				    gdb::function_view<void (breakpoint *)>);
 
-static void breakpoint_re_set_default (struct breakpoint *);
+static void breakpoint_re_set_default (base_breakpoint *);
 
 static void
   create_sals_from_location_default (struct event_location *location,
@@ -5860,10 +5860,10 @@ bpstat_run_callbacks (bpstat *bs_head)
 	  handle_jit_event (bs->bp_location_at->address);
 	  break;
 	case bp_gnu_ifunc_resolver:
-	  gnu_ifunc_resolver_stop (b);
+	  gnu_ifunc_resolver_stop ((base_breakpoint *) b);
 	  break;
 	case bp_gnu_ifunc_resolver_return:
-	  gnu_ifunc_resolver_return_stop (b);
+	  gnu_ifunc_resolver_return_stop ((base_breakpoint *) b);
 	  break;
 	}
     }
@@ -7867,24 +7867,6 @@ enable_breakpoints_after_startup (void)
   breakpoint_re_set ();
 }
 
-/* Create a new single-step breakpoint for thread THREAD, with no
-   locations.  */
-
-static struct breakpoint *
-new_single_step_breakpoint (int thread, struct gdbarch *gdbarch)
-{
-  std::unique_ptr<breakpoint> b (new momentary_breakpoint (gdbarch,
-							   bp_single_step));
-
-  b->disposition = disp_donttouch;
-  b->frame_id = null_frame_id;
-
-  b->thread = thread;
-  gdb_assert (b->thread != 0);
-
-  return add_to_breakpoint_chain (std::move (b));
-}
-
 /* Allocate a new momentary breakpoint.  */
 
 static momentary_breakpoint *
@@ -8057,7 +8039,7 @@ handle_automatic_hardware_breakpoints (bp_location *bl)
 }
 
 bp_location *
-breakpoint::add_location (const symtab_and_line &sal)
+base_breakpoint::add_location (const symtab_and_line &sal)
 {
   struct bp_location *new_loc, **tmp;
   CORE_ADDR adjusted_address;
@@ -12476,7 +12458,7 @@ hoist_existing_locations (struct breakpoint *b, struct program_space *pspace)
    untouched.  */
 
 void
-update_breakpoint_locations (struct breakpoint *b,
+update_breakpoint_locations (base_breakpoint *b,
 			     struct program_space *filter_pspace,
 			     gdb::array_view<const symtab_and_line> sals,
 			     gdb::array_view<const symtab_and_line> sals_end)
@@ -12684,7 +12666,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
    locations.  */
 
 static void
-breakpoint_re_set_default (struct breakpoint *b)
+breakpoint_re_set_default (base_breakpoint *b)
 {
   struct program_space *filter_pspace = current_program_space;
   std::vector<symtab_and_line> expanded, expanded_end;
@@ -13395,15 +13377,26 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch,
 
   if (tp->control.single_step_breakpoints == NULL)
     {
+      std::unique_ptr<breakpoint> b
+	(new momentary_breakpoint (gdbarch, bp_single_step));
+
+      b->disposition = disp_donttouch;
+
+      b->thread = tp->global_num;
+      gdb_assert (b->thread != 0);
+
       tp->control.single_step_breakpoints
-	= new_single_step_breakpoint (tp->global_num, gdbarch);
+	= add_to_breakpoint_chain (std::move (b));
     }
 
   sal = find_pc_line (pc, 0);
   sal.pc = pc;
   sal.section = find_pc_overlay (pc);
   sal.explicit_pc = 1;
-  tp->control.single_step_breakpoints->add_location (sal);
+
+  auto *ss_bp
+    = static_cast<momentary_breakpoint *> (tp->control.single_step_breakpoints);
+  ss_bp->add_location (sal);
 
   update_global_location_list (UGLL_INSERT);
 }
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index af69af6863b..807c97a5bed 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -733,9 +733,6 @@ struct breakpoint
     /* Nothing to do.  */
   }
 
-  /* Add a location for SAL to this breakpoint.  */
-  bp_location *add_location (const symtab_and_line &sal);
-
   /* Return a range of this breakpoint's locations.  */
   bp_location_range locations () const;
 
@@ -874,6 +871,9 @@ struct base_breakpoint : public breakpoint
 
   ~base_breakpoint () override = 0;
 
+  /* Add a location for SAL to this breakpoint.  */
+  bp_location *add_location (const symtab_and_line &sal);
+
   void re_set () override;
   int insert_location (struct bp_location *) override;
   int remove_location (struct bp_location *,
@@ -1383,7 +1383,7 @@ extern void until_break_command (const char *, int, int);
 /* Initialize a struct bp_location.  */
 
 extern void update_breakpoint_locations
-  (struct breakpoint *b,
+  (base_breakpoint *b,
    struct program_space *filter_pspace,
    gdb::array_view<const symtab_and_line> sals,
    gdb::array_view<const symtab_and_line> sals_end);
diff --git a/gdb/elfread.c b/gdb/elfread.c
index b136c605b1a..27203722802 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -927,7 +927,7 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
 /* Handle inferior hit of bp_gnu_ifunc_resolver, see its definition.  */
 
 static void
-elf_gnu_ifunc_resolver_stop (struct breakpoint *b)
+elf_gnu_ifunc_resolver_stop (base_breakpoint *b)
 {
   struct breakpoint *b_return;
   struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
@@ -978,7 +978,7 @@ elf_gnu_ifunc_resolver_stop (struct breakpoint *b)
 /* Handle inferior hit of bp_gnu_ifunc_resolver_return, see its definition.  */
 
 static void
-elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
+elf_gnu_ifunc_resolver_return_stop (base_breakpoint *b)
 {
   thread_info *thread = inferior_thread ();
   struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
@@ -1008,7 +1008,7 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
 			    "gnu-indirect-function breakpoint type %d"),
 			  (int) b->type);
 	}
-      b = b_next;
+      b = (base_breakpoint *) b_next;
     }
   gdb_assert (b->type == bp_gnu_ifunc_resolver);
   gdb_assert (b->loc->next == NULL);
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index cbd0ad22392..217ee047446 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1019,7 +1019,7 @@ stub_gnu_ifunc_resolve_name (const char *function_name,
 /* See elf_gnu_ifunc_resolver_stop for its real implementation.  */
 
 static void
-stub_gnu_ifunc_resolver_stop (struct breakpoint *b)
+stub_gnu_ifunc_resolver_stop (base_breakpoint *b)
 {
   internal_error (__FILE__, __LINE__,
 		  _("elf_gnu_ifunc_resolver_stop cannot be reached."));
@@ -1028,7 +1028,7 @@ stub_gnu_ifunc_resolver_stop (struct breakpoint *b)
 /* See elf_gnu_ifunc_resolver_return_stop for its real implementation.  */
 
 static void
-stub_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
+stub_gnu_ifunc_resolver_return_stop (base_breakpoint *b)
 {
   internal_error (__FILE__, __LINE__,
 		  _("elf_gnu_ifunc_resolver_return_stop cannot be reached."));
diff --git a/gdb/symtab.h b/gdb/symtab.h
index b1cf84f756f..5218be587de 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -55,6 +55,7 @@ struct obj_section;
 struct cmd_list_element;
 class probe;
 struct lookup_name_info;
+struct base_breakpoint;
 
 /* How to match a lookup name against a symbol search name.  */
 enum class symbol_name_match_type
@@ -2227,10 +2228,10 @@ struct gnu_ifunc_fns
 				 CORE_ADDR *function_address_p);
 
   /* See elf_gnu_ifunc_resolver_stop for its real implementation.  */
-  void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
+  void (*gnu_ifunc_resolver_stop) (base_breakpoint *b);
 
   /* See elf_gnu_ifunc_resolver_return_stop for its real implementation.  */
-  void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
+  void (*gnu_ifunc_resolver_return_stop) (base_breakpoint *b);
 };
 
 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr


                 reply	other threads:[~2022-05-20 19:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220520194354.99E43383088B@sourceware.org \
    --to=palves@sourceware.org \
    --cc=gdb-cvs@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).