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]

[1/6] make catchpoints a bit more OO: split initialization/construction from allocation


First step, split breakpoint initialization from allocation.
Basically, add init_... variants to set_raw_breakpoint_without_location
that take a breakpoint pointer as argument and work on that
breakpoint, instead of allocating the breakpoint themselves.
The set_... variants are reimplemented on top of the init_ variants.

Pedro Alves

2011-06-20  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* breakpoint.c (add_to_breakpoint_chain)
	(init_raw_breakpoint_without_location): New functions, factored
	out from ...
	(set_raw_breakpoint_without_location): ... this one.
	(init_raw_breakpoint): New function, factored out from
	set_raw_breakpoint and adjusted to use
	init_raw_breakpoint_without_location.
	(set_raw_breakpoint): Adjust.
	(init_catchpoint): New function, factored out from
	create_catchpoint_without_mention and adjusted to use
	init_raw_breakpoint.
	(create_catchpoint_without_mention): Adjust.

---
 gdb/breakpoint.c |  158 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 108 insertions(+), 50 deletions(-)

Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2011-06-20 20:50:32.000000000 +0100
+++ src/gdb/breakpoint.c	2011-06-20 20:51:08.925404047 +0100
@@ -5785,18 +5785,34 @@ decref_bp_location (struct bp_location *
   *blp = NULL;
 }
 
-/* Helper to set_raw_breakpoint below.  Creates a breakpoint that has
-   type BPTYPE and has no locations as yet.  */
-/* This function is used in gdbtk sources and thus can not be made
-   static.  */
+/* Add breakpoint B at the end of the global breakpoint chain.  */
 
-static struct breakpoint *
-set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
-				     enum bptype bptype)
+static void
+add_to_breakpoint_chain (struct breakpoint *b)
 {
-  struct breakpoint *b, *b1;
+  struct breakpoint *b1;
 
-  b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
+  /* Add this breakpoint to the end of the chain so that a list of
+     breakpoints will come out in order of increasing numbers.  */
+
+  b1 = breakpoint_chain;
+  if (b1 == 0)
+    breakpoint_chain = b;
+  else
+    {
+      while (b1->next)
+	b1 = b1->next;
+      b1->next = b;
+    }
+}
+
+/* Initializes breakpoint B with type BPTYPE and no locations yet.  */
+
+static void
+init_raw_breakpoint_without_location (struct breakpoint *b,
+				      struct gdbarch *gdbarch,
+				      enum bptype bptype)
+{
   memset (b, 0, sizeof (*b));
 
   b->type = bptype;
@@ -5818,18 +5834,22 @@ set_raw_breakpoint_without_location (str
   b->py_bp_object = NULL;
   b->related_breakpoint = b;
 
-  /* Add this breakpoint to the end of the chain so that a list of
-     breakpoints will come out in order of increasing numbers.  */
+  add_to_breakpoint_chain (b);
+}
+
+/* Helper to set_raw_breakpoint below.  Creates a breakpoint
+   that has type BPTYPE and has no locations as yet.  */
+/* This function is used in gdbtk sources and thus can not be made
+   static.  */
+
+static struct breakpoint *
+set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
+				     enum bptype bptype)
+{
+  struct breakpoint *b = XNEW (struct breakpoint);
+
+  init_raw_breakpoint_without_location (b, gdbarch, bptype);
 
-  b1 = breakpoint_chain;
-  if (b1 == 0)
-    breakpoint_chain = b;
-  else
-    {
-      while (b1->next)
-	b1 = b1->next;
-      b1->next = b;
-    }
   return b;
 }
 
@@ -5890,30 +5910,29 @@ get_sal_arch (struct symtab_and_line sal
   return NULL;
 }
 
-/* set_raw_breakpoint is a low level routine for allocating and
-   partially initializing a breakpoint of type BPTYPE.  The newly
-   created breakpoint's address, section, source file name, and line
-   number are provided by SAL.  The newly created and partially
-   initialized breakpoint is added to the breakpoint chain and
-   is also returned as the value of this function.
+/* Low level routine for partially initializing a breakpoint of type
+   BPTYPE.  The newly created breakpoint's address, section, source
+   file name, and line number are provided by SAL.  The newly created
+   and partially initialized breakpoint is added to the breakpoint
+   chain.
 
    It is expected that the caller will complete the initialization of
    the newly created breakpoint struct as well as output any status
    information regarding the creation of a new breakpoint.  In
-   particular, set_raw_breakpoint does NOT set the breakpoint
-   number!  Care should be taken to not allow an error to occur
-   prior to completing the initialization of the breakpoint.  If this
-   should happen, a bogus breakpoint will be left on the chain.  */
+   particular, init_raw_breakpoint does NOT set the breakpoint number!
+   Care should be taken to not allow an error to occur prior to
+   completing the initialization of the breakpoint.  If this should
+   happen, a bogus breakpoint will be left on the chain.  */
 
-struct breakpoint *
-set_raw_breakpoint (struct gdbarch *gdbarch,
-		    struct symtab_and_line sal, enum bptype bptype)
+static void
+init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
+		     struct symtab_and_line sal, enum bptype bptype)
 {
-  struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, 
-							      bptype);
   CORE_ADDR adjusted_address;
   struct gdbarch *loc_gdbarch;
 
+  init_raw_breakpoint_without_location (b, gdbarch, bptype);
+
   loc_gdbarch = get_sal_arch (sal);
   if (!loc_gdbarch)
     loc_gdbarch = b->gdbarch;
@@ -5951,7 +5970,30 @@ set_raw_breakpoint (struct gdbarch *gdba
 				    sal.explicit_pc || sal.explicit_line);
 
   breakpoints_changed ();
+}
+
+/* set_raw_breakpoint is a low level routine for allocating and
+   partially initializing a breakpoint of type BPTYPE.  The newly
+   created breakpoint's address, section, source file name, and line
+   number are provided by SAL.  The newly created and partially
+   initialized breakpoint is added to the breakpoint chain and
+   is also returned as the value of this function.
+
+   It is expected that the caller will complete the initialization of
+   the newly created breakpoint struct as well as output any status
+   information regarding the creation of a new breakpoint.  In
+   particular, set_raw_breakpoint does NOT set the breakpoint
+   number!  Care should be taken to not allow an error to occur
+   prior to completing the initialization of the breakpoint.  If this
+   should happen, a bogus breakpoint will be left on the chain.  */
+
+struct breakpoint *
+set_raw_breakpoint (struct gdbarch *gdbarch,
+		    struct symtab_and_line sal, enum bptype bptype)
+{
+  struct breakpoint *b = XNEW (struct breakpoint);
 
+  init_raw_breakpoint (b, gdbarch, sal, bptype);
   return b;
 }
 
@@ -6737,28 +6779,25 @@ syscall_catchpoint_p (struct breakpoint
   return (b->ops == &catch_syscall_breakpoint_ops);
 }
 
-/* Create a new breakpoint of the bp_catchpoint kind and return it,
-   but does NOT mention it nor update the global location list.
-   This is useful if you need to fill more fields in the
-   struct breakpoint before calling mention.
- 
-   If TEMPFLAG is non-zero, then make the breakpoint temporary.
-   If COND_STRING is not NULL, then store it in the breakpoint.
-   OPS, if not NULL, is the breakpoint_ops structure associated
-   to the catchpoint.  */
+/* Initialize a new breakpoint of the bp_catchpoint kind.  If TEMPFLAG
+   is non-zero, then make the breakpoint temporary.  If COND_STRING is
+   not NULL, then store it in the breakpoint.  OPS, if not NULL, is
+   the breakpoint_ops structure associated to the catchpoint.  */
 
-static struct breakpoint *
-create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
-				   char *cond_string,
-				   struct breakpoint_ops *ops)
+static void
+init_catchpoint (struct breakpoint *b,
+		 struct gdbarch *gdbarch, int tempflag,
+		 char *cond_string,
+		 struct breakpoint_ops *ops)
 {
   struct symtab_and_line sal;
-  struct breakpoint *b;
+
+  memset (b, 0, sizeof (*b));
 
   init_sal (&sal);
   sal.pspace = current_program_space;
 
-  b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint);
+  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint);
   set_breakpoint_count (breakpoint_count + 1);
   b->number = breakpoint_count;
 
@@ -6768,7 +6807,26 @@ create_catchpoint_without_mention (struc
   b->enable_state = bp_enabled;
   b->disposition = tempflag ? disp_del : disp_donttouch;
   b->ops = ops;
+}
+
+/* Create a new breakpoint of the bp_catchpoint kind and return it,
+   but does NOT mention it nor update the global location list.
+   This is useful if you need to fill more fields in the
+   struct breakpoint before calling mention.
+
+   If TEMPFLAG is non-zero, then make the breakpoint temporary.
+   If COND_STRING is not NULL, then store it in the breakpoint.
+   OPS, if not NULL, is the breakpoint_ops structure associated
+   to the catchpoint.  */
+
+static struct breakpoint *
+create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag,
+				   char *cond_string,
+				   struct breakpoint_ops *ops)
+{
+  struct breakpoint *b = XNEW (struct breakpoint);
 
+  init_catchpoint (b, gdbarch, tempflag, cond_string, ops);
   return b;
 }
 


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