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]

RFC: remove gdbarch from struct breakpoint


I would appreciate comments on this patch.

This is the first of two patches in preparation for my "ambiguous
linespec" patch.  I think they are reasonably independent so I am
sending them separately.

This patch removes the 'gdbarch' field from struct breakpoint.

In most cases, it is sufficient to replace the use of this field with
the location's gdbarch instead.  In fact, I think the cases in
tracepoint.c where this is not done are probably latent bugs.

Looking again at the patch I am not totally sure that there is not a
subtle dependency here on the ambiguous linespec patch -- maybe the
assertion in add_location_to_breakpoint is not always valid without some
linespec changes.  I won't check this in until the whole series is ready
to avoid any doubt.

Built and regtested on x86-64 F15.

Tom

b/gdb/ChangeLog:
2011-10-27  Tom Tromey  <tromey@redhat.com>

	* tracepoint.c (encode_actions_1): Use the location's gdbarch.
	(encode_actions): Likewise.
	* python/py-breakpoint.c (gdbpy_should_stop)
	(gdbpy_breakpoint_has_py_cond): Update.
	* breakpoint.h (struct breakpoint) <gdbarch>: Remove field.
	* breakpoint.c (print_one_breakpoint_location): Use location's
	gdbarch.
	(init_raw_breakpoint_without_location): Remove gdbarch argument.
	(set_raw_breakpoint_without_location): Likewise.
	(get_sal_arch): Use find_pc_section as a fallback.
	(init_raw_breakpoint, momentary_breakpoint_from_master)
	(add_location_to_breakpoint, create_breakpoint, watch_command_1):
	Update.

>From f52366f687f5e191fcbff3598f50ffc11a2b28e3 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Thu, 6 Oct 2011 08:10:07 -0600
Subject: [PATCH 1/3] remove gdbarch from struct breakpoint

---
 gdb/ChangeLog              |   16 ++++++++++++++++
 gdb/breakpoint.c           |   33 +++++++++++++++++----------------
 gdb/breakpoint.h           |    2 --
 gdb/python/py-breakpoint.c |    5 ++---
 gdb/tracepoint.c           |   16 ++++++++--------
 5 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ba1b08f..3ae7508 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -106,8 +106,7 @@ static void break_command_1 (char *, int, int);
 
 static void mention (struct breakpoint *);
 
-static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
-							       enum bptype,
+static struct breakpoint *set_raw_breakpoint_without_location (enum bptype,
 							       const struct breakpoint_ops *);
 /* This function is used in gdbtk sources and thus can not be made
    static.  */
@@ -4861,7 +4860,7 @@ print_one_breakpoint_location (struct breakpoint *b,
       /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
          the frame ID.  */
       ui_out_field_core_addr (uiout, "frame",
-			      b->gdbarch, b->frame_id.stack_addr);
+			      loc->gdbarch, b->frame_id.stack_addr);
       ui_out_text (uiout, "\n");
     }
   
@@ -5678,7 +5677,6 @@ add_to_breakpoint_chain (struct breakpoint *b)
 
 static void
 init_raw_breakpoint_without_location (struct breakpoint *b,
-				      struct gdbarch *gdbarch,
 				      enum bptype bptype,
 				      const struct breakpoint_ops *ops)
 {
@@ -5688,7 +5686,6 @@ init_raw_breakpoint_without_location (struct breakpoint *b,
 
   b->ops = ops;
   b->type = bptype;
-  b->gdbarch = gdbarch;
   b->language = current_language->la_language;
   b->input_radix = input_radix;
   b->thread = -1;
@@ -5707,13 +5704,12 @@ init_raw_breakpoint_without_location (struct breakpoint *b,
    that has type BPTYPE and has no locations as yet.  */
 
 static struct breakpoint *
-set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
-				     enum bptype bptype,
+set_raw_breakpoint_without_location (enum bptype bptype,
 				     const struct breakpoint_ops *ops)
 {
   struct breakpoint *b = XNEW (struct breakpoint);
 
-  init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
+  init_raw_breakpoint_without_location (b, bptype, ops);
   add_to_breakpoint_chain (b);
   return b;
 }
@@ -5767,11 +5763,17 @@ set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
 static struct gdbarch *
 get_sal_arch (struct symtab_and_line sal)
 {
+  struct obj_section *sect;
+
   if (sal.section)
     return get_objfile_arch (sal.section->objfile);
   if (sal.symtab)
     return get_objfile_arch (sal.symtab->objfile);
 
+  sect = find_pc_section (sal.pc);
+  if (sect)
+    return get_objfile_arch (sect->objfile);
+
   return NULL;
 }
 
@@ -5791,11 +5793,11 @@ init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
   CORE_ADDR adjusted_address;
   struct gdbarch *loc_gdbarch;
 
-  init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
+  init_raw_breakpoint_without_location (b, bptype, ops);
 
   loc_gdbarch = get_sal_arch (sal);
   if (!loc_gdbarch)
-    loc_gdbarch = b->gdbarch;
+    loc_gdbarch = gdbarch;
 
   if (bptype != bp_catchpoint)
     gdb_assert (sal.pspace != NULL);
@@ -7049,7 +7051,7 @@ momentary_breakpoint_from_master (struct breakpoint *orig,
 {
   struct breakpoint *copy;
 
-  copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
+  copy = set_raw_breakpoint_without_location (type, ops);
   copy->loc = allocate_bp_location (copy);
   set_breakpoint_location_function (copy->loc, 1);
 
@@ -7128,8 +7130,7 @@ add_location_to_breakpoint (struct breakpoint *b,
     ;
   *tmp = loc;
   loc->gdbarch = get_sal_arch (*sal);
-  if (!loc->gdbarch)
-    loc->gdbarch = b->gdbarch;
+  gdb_assert (loc->gdbarch);
   loc->requested_address = sal->pc;
   loc->address = adjust_breakpoint_address (loc->gdbarch,
 					    loc->requested_address, b->type);
@@ -7991,7 +7992,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 
       make_cleanup (xfree, copy_arg);
 
-      b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops);
+      b = set_raw_breakpoint_without_location (type_wanted, ops);
       set_breakpoint_number (internal, b);
       b->thread = -1;
       b->addr_string = canonical.canonical[0];
@@ -9327,10 +9328,10 @@ watch_command_1 (char *arg, int accessflag, int from_tty,
   w = XCNEW (struct watchpoint);
   b = &w->base;
   if (use_mask)
-    init_raw_breakpoint_without_location (b, NULL, bp_type,
+    init_raw_breakpoint_without_location (b, bp_type,
 					  &masked_watchpoint_breakpoint_ops);
   else
-    init_raw_breakpoint_without_location (b, NULL, bp_type,
+    init_raw_breakpoint_without_location (b, bp_type,
 					  &watchpoint_breakpoint_ops);
   b->thread = thread;
   b->disposition = disp_donttouch;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index c2116e2..dba5392 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -581,8 +581,6 @@ struct breakpoint
        the end of the range (malloc'd).  */
     char *addr_string_range_end;
 
-    /* Architecture we used to set the breakpoint.  */
-    struct gdbarch *gdbarch;
     /* Language we used to set the breakpoint.  */
     enum language language;
     /* Input radix we used to set the breakpoint.  */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index daceb99..94dbc72 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -733,7 +733,7 @@ gdbpy_should_stop (struct breakpoint_object *bp_obj)
 
   PyObject *py_bp = (PyObject *) bp_obj;
   struct breakpoint *b = bp_obj->bp;
-  struct gdbarch *garch = b->gdbarch ? b->gdbarch : get_current_arch ();
+  struct gdbarch *garch = get_current_arch ();
   struct cleanup *cleanup = ensure_python_env (garch, current_language);
 
   if (PyObject_HasAttrString (py_bp, stop_func))
@@ -771,8 +771,7 @@ gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj)
 {
   int has_func = 0;
   PyObject *py_bp = (PyObject *) bp_obj;
-  struct gdbarch *garch = bp_obj->bp->gdbarch ? bp_obj->bp->gdbarch :
-    get_current_arch ();
+  struct gdbarch *garch = get_current_arch ();
   struct cleanup *cleanup = ensure_python_env (garch, current_language);
   
   if (py_bp != NULL)
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index d88fcd7..23f3071 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1321,14 +1321,14 @@ encode_actions_1 (struct command_line *action,
 
 	      if (0 == strncasecmp ("$reg", action_exp, 4))
 		{
-		  for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++)
+		  for (i = 0; i < gdbarch_num_regs (tloc->gdbarch); i++)
 		    add_register (collect, i);
 		  action_exp = strchr (action_exp, ',');	/* more? */
 		}
 	      else if (0 == strncasecmp ("$arg", action_exp, 4))
 		{
 		  add_local_symbols (collect,
-				     t->gdbarch,
+				     tloc->gdbarch,
 				     tloc->address,
 				     frame_reg,
 				     frame_offset,
@@ -1338,7 +1338,7 @@ encode_actions_1 (struct command_line *action,
 	      else if (0 == strncasecmp ("$loc", action_exp, 4))
 		{
 		  add_local_symbols (collect,
-				     t->gdbarch,
+				     tloc->gdbarch,
 				     tloc->address,
 				     frame_reg,
 				     frame_offset,
@@ -1350,7 +1350,7 @@ encode_actions_1 (struct command_line *action,
 		  struct cleanup *old_chain1 = NULL;
 
 		  aexpr = gen_trace_for_return_address (tloc->address,
-							t->gdbarch);
+							tloc->gdbarch);
 
 		  old_chain1 = make_cleanup_free_agent_expr (aexpr);
 
@@ -1403,7 +1403,7 @@ encode_actions_1 (struct command_line *action,
 		      {
 			const char *name = &exp->elts[2].string;
 
-			i = user_reg_map_name_to_regnum (t->gdbarch,
+			i = user_reg_map_name_to_regnum (tloc->gdbarch,
 							 name, strlen (name));
 			if (i == -1)
 			  internal_error (__FILE__, __LINE__,
@@ -1426,7 +1426,7 @@ encode_actions_1 (struct command_line *action,
 		    case OP_VAR_VALUE:
 		      collect_symbol (collect,
 				      exp->elts[2].symbol,
-				      t->gdbarch,
+				      tloc->gdbarch,
 				      frame_reg,
 				      frame_offset,
 				      tloc->address);
@@ -1539,8 +1539,8 @@ encode_actions (struct breakpoint *t, struct bp_location *tloc,
   *tdp_actions = NULL;
   *stepping_actions = NULL;
 
-  gdbarch_virtual_frame_pointer (t->gdbarch,
-				 t->loc->address, &frame_reg, &frame_offset);
+  gdbarch_virtual_frame_pointer (tloc->gdbarch,
+				 tloc->address, &frame_reg, &frame_offset);
 
   actions = breakpoint_commands (t);
 
-- 
1.7.6.4


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