[13/30] Use read_var_value in gdb/compile

Message ID 20231029-split-objfile-2023-bound-sym-october-v1-13-612531df2734@tromey.com
State New
Headers
Series Baby step for objfile splitting |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed

Commit Message

Tom Tromey Oct. 29, 2023, 11:23 p.m. UTC
  This changes the code in gdb/compile to use the new read_var_value
overload.
---
 gdb/compile/compile-c-symbols.c | 12 +++++++-----
 gdb/compile/compile-loc2c.c     | 14 ++++++++------
 gdb/compile/compile.h           |  6 +++---
 gdb/dwarf2/ada-imported.c       |  2 +-
 gdb/dwarf2/loc.c                | 12 +++++++-----
 gdb/dwarf2/loc.h                |  3 ++-
 gdb/symtab.h                    |  2 +-
 7 files changed, 29 insertions(+), 22 deletions(-)
  

Patch

diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 40578bf36f4..b8632013909 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -493,7 +493,7 @@  generate_vla_size (compile_instance *compiler,
 		   std::vector<bool> &registers_used,
 		   CORE_ADDR pc,
 		   struct type *type,
-		   struct symbol *sym)
+		   block_symbol sym)
 {
   type = check_typedef (type);
 
@@ -546,8 +546,9 @@  generate_c_for_for_one_variable (compile_instance *compiler,
 				 struct gdbarch *gdbarch,
 				 std::vector<bool> &registers_used,
 				 CORE_ADDR pc,
-				 struct symbol *sym)
+				 block_symbol bsym)
 {
+  struct symbol *sym = bsym.symbol;
 
   try
     {
@@ -558,7 +559,7 @@  generate_c_for_for_one_variable (compile_instance *compiler,
 	  string_file local_file;
 
 	  generate_vla_size (compiler, &local_file, gdbarch, registers_used, pc,
-			     sym->type (), sym);
+			     sym->type (), bsym);
 
 	  stream->write (local_file.c_str (), local_file.size ());
 	}
@@ -571,7 +572,7 @@  generate_c_for_for_one_variable (compile_instance *compiler,
 	     occurs in the middle.  */
 	  string_file local_file;
 
-	  SYMBOL_COMPUTED_OPS (sym)->generate_c_location (sym, &local_file,
+	  SYMBOL_COMPUTED_OPS (sym)->generate_c_location (bsym, &local_file,
 							  gdbarch,
 							  registers_used,
 							  pc,
@@ -639,9 +640,10 @@  generate_c_for_variable_locations (compile_instance *compiler,
 	 compute the location of each local variable.  */
       for (struct symbol *sym : block_iterator_range (block))
 	{
+	  block_symbol bsym { sym, block };
 	  if (!symbol_seen (symhash.get (), sym))
 	    generate_c_for_for_one_variable (compiler, stream, gdbarch,
-					     registers_used, pc, sym);
+					     registers_used, pc, bsym);
 	}
 
       /* If we just finished the outermost block of a function, we're
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 8a5a0f5abc5..ef150e7c27e 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -592,7 +592,7 @@  static void
 do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 			    const char *type_name,
 			    const char *result_name,
-			    struct symbol *sym, CORE_ADDR pc,
+			    block_symbol bsym, CORE_ADDR pc,
 			    struct gdbarch *arch,
 			    std::vector<bool> &registers_used,
 			    unsigned int addr_size,
@@ -605,6 +605,8 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
      unique names.  */
   static unsigned int scope;
 
+  struct symbol *sym = bsym.symbol;
+
   enum bfd_endian byte_order = gdbarch_byte_order (arch);
   const gdb_byte * const base = op_ptr;
   int need_tempvar = 0;
@@ -641,7 +643,7 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 		 "there is no selected frame"),
 	       sym->print_name ());
 
-      val = read_var_value (sym, NULL, frame);
+      val = read_var_value (bsym, frame);
       if (val->lval () != lval_memory)
 	error (_("Symbol \"%s\" cannot be used for compilation evaluation "
 		 "as its address has not been found."),
@@ -909,7 +911,7 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 	    do_compile_dwarf_expr_to_c (indent, stream,
 					GCC_UINTPTR, fb_name,
-					sym, pc,
+					bsym, pc,
 					arch, registers_used, addr_size,
 					datastart, datastart + datalen,
 					NULL, per_cu, per_objfile);
@@ -1097,7 +1099,7 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 		do_compile_dwarf_expr_to_c (indent, stream,
 					    GCC_UINTPTR, cfa_name,
-					    sym, pc, arch, registers_used,
+					    bsym, pc, arch, registers_used,
 					    addr_size,
 					    cfa_start, cfa_end,
 					    &text_offset, per_cu, per_objfile);
@@ -1143,7 +1145,7 @@  do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 
 void
 compile_dwarf_expr_to_c (string_file *stream, const char *result_name,
-			 struct symbol *sym, CORE_ADDR pc,
+			 block_symbol sym, CORE_ADDR pc,
 			 struct gdbarch *arch,
 			 std::vector<bool> &registers_used,
 			 unsigned int addr_size,
@@ -1162,7 +1164,7 @@  void
 compile_dwarf_bounds_to_c (string_file *stream,
 			   const char *result_name,
 			   const struct dynamic_prop *prop,
-			   struct symbol *sym, CORE_ADDR pc,
+			   block_symbol sym, CORE_ADDR pc,
 			   struct gdbarch *arch,
 			   std::vector<bool> &registers_used,
 			   unsigned int addr_size,
diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h
index a3b6a18fe20..7cb38cb006c 100644
--- a/gdb/compile/compile.h
+++ b/gdb/compile/compile.h
@@ -19,12 +19,12 @@ 
 #define COMPILE_COMPILE_H
 
 #include "gcc-c-interface.h"
+#include "block-symbol.h"
 
 struct ui_file;
 struct gdbarch;
 struct dwarf2_per_cu_data;
 struct dwarf2_per_objfile;
-struct symbol;
 struct dynamic_prop;
 
 /* An object of this type holds state associated with a given
@@ -177,7 +177,7 @@  extern void eval_compile_command (struct command_line *cmd,
 
 extern void compile_dwarf_expr_to_c (string_file *stream,
 				     const char *result_name,
-				     struct symbol *sym,
+				     block_symbol sym,
 				     CORE_ADDR pc,
 				     struct gdbarch *arch,
 				     std::vector<bool> &registers_used,
@@ -217,7 +217,7 @@  extern void compile_dwarf_expr_to_c (string_file *stream,
 extern void compile_dwarf_bounds_to_c (string_file *stream,
 				       const char *result_name,
 				       const struct dynamic_prop *prop,
-				       struct symbol *sym, CORE_ADDR pc,
+				       block_symbol sym, CORE_ADDR pc,
 				       struct gdbarch *arch,
 				       std::vector<bool> &registers_used,
 				       unsigned int addr_size,
diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index d1d99be6923..9947d8e04b7 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -75,7 +75,7 @@  ada_imported_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
    symbol_computed_ops.  */
 
 static void
-ada_imported_generate_c_location (struct symbol *symbol, string_file *stream,
+ada_imported_generate_c_location (block_symbol symbol, string_file *stream,
 				  struct gdbarch *gdbarch,
 				  std::vector<bool> &registers_used,
 				  CORE_ADDR pc, const char *result_name)
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 5b2d58ab44e..53031aa809a 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1786,7 +1786,7 @@  dwarf2_compile_property_to_c (string_file *stream,
 			      std::vector<bool> &registers_used,
 			      const struct dynamic_prop *prop,
 			      CORE_ADDR pc,
-			      struct symbol *sym)
+			      block_symbol sym)
 {
   const dwarf2_property_baton *baton = prop->baton ();
   const gdb_byte *data;
@@ -3847,11 +3847,12 @@  locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 /* symbol_computed_ops 'generate_c_location' method.  */
 
 static void
-locexpr_generate_c_location (struct symbol *sym, string_file *stream,
+locexpr_generate_c_location (block_symbol bsym, string_file *stream,
 			     struct gdbarch *gdbarch,
 			     std::vector<bool> &registers_used,
 			     CORE_ADDR pc, const char *result_name)
 {
+  symbol *sym = bsym.symbol;
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
   unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -3860,7 +3861,7 @@  locexpr_generate_c_location (struct symbol *sym, string_file *stream,
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
 
   compile_dwarf_expr_to_c (stream, result_name,
-			   sym, pc, gdbarch, registers_used, addr_size,
+			   bsym, pc, gdbarch, registers_used, addr_size,
 			   dlbaton->data, dlbaton->data + dlbaton->size,
 			   dlbaton->per_cu, dlbaton->per_objfile);
 }
@@ -4083,11 +4084,12 @@  loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 /* symbol_computed_ops 'generate_c_location' method.  */
 
 static void
-loclist_generate_c_location (struct symbol *sym, string_file *stream,
+loclist_generate_c_location (block_symbol bsym, string_file *stream,
 			     struct gdbarch *gdbarch,
 			     std::vector<bool> &registers_used,
 			     CORE_ADDR pc, const char *result_name)
 {
+  symbol *sym = bsym.symbol;
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
   unsigned int addr_size = dlbaton->per_cu->addr_size ();
@@ -4099,7 +4101,7 @@  loclist_generate_c_location (struct symbol *sym, string_file *stream,
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
 
   compile_dwarf_expr_to_c (stream, result_name,
-			   sym, pc, gdbarch, registers_used, addr_size,
+			   bsym, pc, gdbarch, registers_used, addr_size,
 			   data, data + size,
 			   dlbaton->per_cu,
 			   dlbaton->per_objfile);
diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h
index 5cf824d3ae2..9722083cbeb 100644
--- a/gdb/dwarf2/loc.h
+++ b/gdb/dwarf2/loc.h
@@ -21,6 +21,7 @@ 
 #define DWARF2LOC_H
 
 #include "dwarf2/expr.h"
+#include "block-symbol.h"
 
 struct symbol_computed_ops;
 struct dwarf2_per_objfile;
@@ -144,7 +145,7 @@  void dwarf2_compile_property_to_c (string_file *stream,
 				   std::vector<bool> &registers_used,
 				   const struct dynamic_prop *prop,
 				   CORE_ADDR address,
-				   struct symbol *sym);
+				   block_symbol sym);
 
 /* The symbol location baton types used by the DWARF-2 reader (i.e.
    SYMBOL_LOCATION_BATON for a LOC_COMPUTED symbol).  "struct
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 93cc1f11d08..5292fadbbab 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1130,7 +1130,7 @@  struct symbol_computed_ops
      The generated C code must assign the location to a local
      variable; this variable's name is RESULT_NAME.  */
 
-  void (*generate_c_location) (struct symbol *symbol, string_file *stream,
+  void (*generate_c_location) (block_symbol symbol, string_file *stream,
 			       struct gdbarch *gdbarch,
 			       std::vector<bool> &registers_used,
 			       CORE_ADDR pc, const char *result_name);