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]

Re: [2/3] RFC: merge symbol "ops" and "aclass" fields


On Wed, 06 Feb 2013 16:52:35 +0100, Jan Kratochvil wrote:
> FYI I am just working on a patch to remove that &dwarf2_loclist_funcs
> comparison ugliness.

BTW here it is.

Not sure how clean it is, without the full virtualization it is never too
clean.

No regressions on {x86_64,x86_64-m32,i686}-fedora19pre-linux-gnu.


Thanks,
Jan


gdb/
2013-02-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.c (dwarf_expr_frame_base_1): Call find_location_expr
	method.  Drop internal_error, fall back to the error call.
	(locexpr_find_location_expr): New function.
	(dwarf2_locexpr_funcs): Install it, new field has_loclist.
	(loclist_find_location_expr): New function.
	(dwarf2_loclist_funcs): Install it, new field has_loclist.
	* dwarf2loc.h (dwarf2_locexpr_block_index, dwarf2_loclist_block_index):
	Remove the declarations.
	* dwarf2read.c (dwarf2_locexpr_block_index, dwarf2_loclist_block_index):
	Make them static.
	(var_decode_location): Use has_loclist.
	(_initialize_dwarf2_read): Replace register_symbol_alias_impl by
	register_symbol_computed_impl.
	* symtab.c (register_symbol_computed_impl): Update the comment.  Allow
	also LOC_BLOCK.
	(register_symbol_alias_impl): Remove.
	* symtab.h (struct symbol_computed_ops): New fields has_loclist and
	find_location_expr.
	(struct symbol_impl): Update comment for ops_computed.
	(register_symbol_alias_impl): Remove.

diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 6047f09..f90a9c4 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -361,30 +361,13 @@ static void
 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
 			 const gdb_byte **start, size_t *length)
 {
-  if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
-    *length = 0;
-  else if (SYMBOL_ACLASS_INDEX (framefunc) == dwarf2_loclist_block_index)
-    {
-      struct dwarf2_loclist_baton *symbaton;
-
-      symbaton = SYMBOL_LOCATION_BATON (framefunc);
-      *start = dwarf2_find_location_expression (symbaton, length, pc);
-    }
-  else if (SYMBOL_ACLASS_INDEX (framefunc) == dwarf2_locexpr_block_index)
-    {
-      struct dwarf2_locexpr_baton *symbaton;
+  const struct symbol_computed_ops *ops_computed;
 
-      symbaton = SYMBOL_LOCATION_BATON (framefunc);
-      if (symbaton != NULL)
-	{
-	  *length = symbaton->size;
-	  *start = symbaton->data;
-	}
-      else
-	*length = 0;
-    }
+  ops_computed = SYMBOL_COMPUTED_OPS (framefunc);
+  if (ops_computed != NULL)
+    ops_computed->find_location_expr (framefunc, pc, start, length);
   else
-    internal_error (__FILE__, __LINE__, _("invalid function aclass index"));
+    *length = 0;
 
   if (*length == 0)
     error (_("Could not find the frame base for \"%s\"."),
@@ -3971,6 +3954,18 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
 			       dlbaton->per_cu);
 }
 
+/* Implement find_location_expr method for dwarf2_locexpr_baton.  */
+
+static void
+locexpr_find_location_expr (struct symbol *sym, CORE_ADDR pc,
+			    const gdb_byte **start, size_t *length)
+{
+  struct dwarf2_locexpr_baton *symbaton = SYMBOL_LOCATION_BATON (sym);
+
+  *length = symbaton->size;
+  *start = symbaton->data;
+}
+
 /* The set of location functions used with the DWARF-2 expression
    evaluator.  */
 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
@@ -3978,6 +3973,8 @@ const struct symbol_computed_ops dwarf2_locexpr_funcs = {
   locexpr_read_variable_at_entry,
   locexpr_read_needs_frame,
   locexpr_describe_location,
+  0,	/* has_loclist */
+  locexpr_find_location_expr,
   locexpr_tracepoint_var_ref
 };
 
@@ -4149,6 +4146,17 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
 			       dlbaton->per_cu);
 }
 
+/* Implement find_location_expr method for dwarf2_loclist_baton.  */
+
+static void
+loclist_find_location_expr (struct symbol *sym, CORE_ADDR pc,
+			    const gdb_byte **start, size_t *length)
+{
+  struct dwarf2_loclist_baton *symbaton = SYMBOL_LOCATION_BATON (sym);
+
+  *start = dwarf2_find_location_expression (symbaton, length, pc);
+}
+
 /* The set of location functions used with the DWARF-2 expression
    evaluator and location lists.  */
 const struct symbol_computed_ops dwarf2_loclist_funcs = {
@@ -4156,6 +4164,8 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = {
   loclist_read_variable_at_entry,
   loclist_read_needs_frame,
   loclist_describe_location,
+  1,	/* has_loclist */
+  loclist_find_location_expr,
   loclist_tracepoint_var_ref
 };
 
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index 9060a65..36641b3 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -133,10 +133,6 @@ struct dwarf2_loclist_baton
 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
 
-/* Two variables from dwarf2read.c.  */
-extern int dwarf2_locexpr_block_index;
-extern int dwarf2_loclist_block_index;
-
 /* Compile a DWARF location expression to an agent expression.
    
    EXPR is the agent expression we are building.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bf068e8..bc0067e 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -96,8 +96,8 @@ static const struct objfile_data *dwarf2_objfile_data_key;
 
 static int dwarf2_locexpr_index;
 static int dwarf2_loclist_index;
-int dwarf2_locexpr_block_index;
-int dwarf2_loclist_block_index;
+static int dwarf2_locexpr_block_index;
+static int dwarf2_loclist_block_index;
 
 struct dwarf2_section_info
 {
@@ -15757,7 +15757,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
 
   dwarf2_symbol_mark_computed (attr, sym, cu, 0);
 
-  if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
+  if (SYMBOL_COMPUTED_OPS (sym)->has_loclist)
     cu->has_loclist = 1;
 }
 
@@ -20718,6 +20718,9 @@ Usage: save gdb-index DIRECTORY"),
   dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED,
 							&dwarf2_loclist_funcs);
 
-  dwarf2_locexpr_block_index = register_symbol_alias_impl (LOC_BLOCK);
-  dwarf2_loclist_block_index = register_symbol_alias_impl (LOC_BLOCK);
+  dwarf2_locexpr_block_index = register_symbol_computed_impl (LOC_BLOCK,
+							 &dwarf2_locexpr_funcs);
+
+  dwarf2_loclist_block_index = register_symbol_computed_impl (LOC_BLOCK,
+							 &dwarf2_loclist_funcs);
 }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 50096fa..7ed5738 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5063,10 +5063,10 @@ const struct symbol_impl *symbol_impls = &symbol_impl[0];
 
 gdb_static_assert (MAX_SYMBOL_IMPLS <= (1 << SYMBOL_ACLASS_BITS));
 
-/* Register a computed symbol type.  ACLASS must be LOC_COMPUTED.  OPS
-   is the ops vector associated with this index.  This returns the new
-   index, which should be used as the aclass_index field for symbols
-   of this type.  */
+/* Register a computed symbol type.  ACLASS must be LOC_COMPUTED or LOC_BLOCK.
+   OPS is the ops vector associated with this index.  This returns the new
+   index, which should be used as the aclass_index field for symbols of this
+   type.  */
 
 int
 register_symbol_computed_impl (enum address_class aclass,
@@ -5074,7 +5074,7 @@ register_symbol_computed_impl (enum address_class aclass,
 {
   int result = next_aclass_value++;
 
-  gdb_assert (aclass == LOC_COMPUTED);
+  gdb_assert (aclass == LOC_COMPUTED || aclass == LOC_BLOCK);
   gdb_assert (result < MAX_SYMBOL_IMPLS);
   symbol_impl[result].aclass = aclass;
   symbol_impl[result].ops_computed = ops;
@@ -5082,21 +5082,6 @@ register_symbol_computed_impl (enum address_class aclass,
   return result;
 }
 
-/* Register a symbol type to be recognized by its index.  ACLASS can be
-   anything.  This returns the new index, which should be used as the
-   aclass_index field for symbols of this type.  */
-
-int
-register_symbol_alias_impl (enum address_class aclass)
-{
-  int result = next_aclass_value++;
-
-  gdb_assert (result < MAX_SYMBOL_IMPLS);
-  symbol_impl[result].aclass = aclass;
-
-  return result;
-}
-
 /* Register a register symbol type.  ACLASS must be LOC_REGISTER or
    LOC_REGPARM_ADDR.  OPS is the register ops vector associated with
    this index.  This returns the new index, which should be used as
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 293c443..4ec0f08 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -575,6 +575,15 @@ struct symbol_computed_ops
   void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
 			     struct ui_file * stream);
 
+  /* Non-zero if this symbol is dependent on PC.  */
+  unsigned char has_loclist;
+
+  /* Fill in *START and *LENGTH with DWARF block data of symbol SYM valid for
+     inferior context address PC.  Set *LENGTH to zero if such location is not
+     valid for PC (*START is left uninitialized in such case).  */
+  void (*find_location_expr) (struct symbol *sym, CORE_ADDR pc,
+			      const gdb_byte **start, size_t *length);
+
   /* Tracepoint support.  Append bytecodes to the tracepoint agent
      expression AX that push the address of the object SYMBOL.  Set
      VALUE appropriately.  Note --- for objects in registers, this
@@ -600,7 +609,7 @@ struct symbol_impl
 {
   enum address_class aclass;
 
-  /* Used with LOC_COMPUTED.  */
+  /* Used with LOC_COMPUTED or LOC_BLOCK (for LOC_BLOCK it may be NULL).  */
   const struct symbol_computed_ops *ops_computed;
 
   /* Used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
@@ -703,8 +712,6 @@ extern const struct symbol_impl *symbol_impls;
 extern int register_symbol_computed_impl (enum address_class,
 					  const struct symbol_computed_ops *);
 
-extern int register_symbol_alias_impl (enum address_class);
-
 extern int register_symbol_register_impl (enum address_class,
 					  const struct symbol_register_ops *);
 


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