Use bound_minimal_symbol in var_msym_value_operation
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:44 +0000 (07:28 -0700)
This changes var_msym_value_operation to use a bound_minimal_symbol
rather than separate minsym and objfile parameters.  The main benefit
of this is removing the possibly-confusing check_objfile overload for
a plain minimal symbol.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

* parse.c (parser_state::push_symbol, parser_state::push_dollar):
Update.
* p-exp.y (variable): Update.
* go-exp.y (variable): Update.
* expprint.c (dump_for_expression): Use bound_minimal_symbol.
Remove overload for objfile.
* expop.h (eval_op_var_msym_value): Use bound_minimal_symbol
parameter.
(check_objfile): Likewise.
(dump_for_expression): Likewise.  Remove overload for objfile.
(class var_msym_value_operation): Use bound_minimal_symbol.
* eval.c (eval_op_var_msym_value): Use bound_minimal_symbol
parameter.
(var_msym_value_operation::evaluate_for_address)
(var_msym_value_operation::evaluate_for_sizeof)
(var_msym_value_operation::evaluate_for_cast): Update.
* d-exp.y (PrimaryExpression): Update.
* c-exp.y (variable): Update.
* ax-gdb.c (var_msym_value_operation::do_generate_ax): Update.
* ada-lang.c (ada_var_msym_value_operation::evaluate_for_cast):
Update.
* ada-exp.y (write_var_or_type): Update.

12 files changed:
gdb/ChangeLog
gdb/ada-exp.y
gdb/ada-lang.c
gdb/ax-gdb.c
gdb/c-exp.y
gdb/d-exp.y
gdb/eval.c
gdb/expop.h
gdb/expprint.c
gdb/go-exp.y
gdb/p-exp.y
gdb/parse.c

index edbba7fd8bff1fa3011ab99db15bb863ae1ed522..d1cf966d21380862805ac6a3403002a8bf7dac59 100644 (file)
@@ -1,3 +1,28 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * parse.c (parser_state::push_symbol, parser_state::push_dollar):
+       Update.
+       * p-exp.y (variable): Update.
+       * go-exp.y (variable): Update.
+       * expprint.c (dump_for_expression): Use bound_minimal_symbol.
+       Remove overload for objfile.
+       * expop.h (eval_op_var_msym_value): Use bound_minimal_symbol
+       parameter.
+       (check_objfile): Likewise.
+       (dump_for_expression): Likewise.  Remove overload for objfile.
+       (class var_msym_value_operation): Use bound_minimal_symbol.
+       * eval.c (eval_op_var_msym_value): Use bound_minimal_symbol
+       parameter.
+       (var_msym_value_operation::evaluate_for_address)
+       (var_msym_value_operation::evaluate_for_sizeof)
+       (var_msym_value_operation::evaluate_for_cast): Update.
+       * d-exp.y (PrimaryExpression): Update.
+       * c-exp.y (variable): Update.
+       * ax-gdb.c (var_msym_value_operation::do_generate_ax): Update.
+       * ada-lang.c (ada_var_msym_value_operation::evaluate_for_cast):
+       Update.
+       * ada-exp.y (write_var_or_type): Update.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * parser-defs.h (exp_uses_objfile): Return bool.
index de88c863cff24fde405bef6a037a9c65d9a8b4d0..222fec536f3c3c179db279f789fe95445d4bfb5a 100644 (file)
@@ -1550,8 +1550,7 @@ write_var_or_type (struct parser_state *par_state,
                = ada_lookup_simple_minsym (encoded_name);
              if (msym.minsym != NULL)
                {
-                 par_state->push_new<ada_var_msym_value_operation>
-                   (msym.minsym, msym.objfile);
+                 par_state->push_new<ada_var_msym_value_operation> (msym);
                  /* Maybe cause error here rather than later? FIXME? */
                  write_selectors (par_state, encoded_name + tail_index);
                  return NULL;
index 323168e1b30367565376e186f805a1deba17f048..8330cbcc0b9b1a71c967bdc8ed2c1165f542adf3 100644 (file)
@@ -10241,9 +10241,8 @@ ada_var_msym_value_operation::evaluate_for_cast (struct type *expect_type,
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return value_zero (expect_type, not_lval);
 
-  value *val = evaluate_var_msym_value (noside,
-                                       std::get<1> (m_storage),
-                                       std::get<0> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
 
   val = ada_value_cast (expect_type, val);
 
index 788be528d1bb9d9e5d7d9463bba5346b9fbc4929..33fc53837645f1c5eb2e0e0476c4d079639b2d03 100644 (file)
@@ -1631,13 +1631,13 @@ var_msym_value_operation::do_generate_ax (struct expression *exp,
                                          struct axs_value *value,
                                          struct type *cast_type)
 {
-  gen_msym_var_ref (ax, value, std::get<0> (m_storage),
-                   std::get<1> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  gen_msym_var_ref (ax, value, b.minsym, b.objfile);
 
   if (value->type->code () == TYPE_CODE_ERROR)
     {
       if (cast_type == nullptr)
-       error_unknown_type (std::get<0> (m_storage)->linkage_name ());
+       error_unknown_type (b.minsym->linkage_name ());
       value->type = cast_type;
     }
 }
index 8bc7a97e0ac10f1a111caf6865278adc616863b4..c0e4b494f3d23da1a5012525eca129f38d01726c 100644 (file)
@@ -1195,7 +1195,7 @@ variable: name_not_typename
                                = find_gnu_ifunc (sym.symbol);
                              if (resolver.minsym != NULL)
                                pstate->push_new<var_msym_value_operation>
-                                 (resolver.minsym, resolver.objfile);
+                                 (resolver);
                              else
                                pstate->push_new<var_value_operation>
                                  (sym.symbol, sym.block);
@@ -1243,7 +1243,7 @@ variable: name_not_typename
                                  (alias_target, SYMBOL_BLOCK_VALUE (alias_target));
                              else
                                pstate->push_new<var_msym_value_operation>
-                                 (msymbol.minsym, msymbol.objfile);
+                                 (msymbol);
                            }
                        }
        ;
index d74fb8711a069d4e481ad3c0a57d59e1b5b129a8..90c342e0e218e8e3b385abfdf41dddf4f5e21db8 100644 (file)
@@ -470,8 +470,7 @@ PrimaryExpression:
                      /* Lookup foreign name in global static symbols.  */
                      msymbol = lookup_bound_minimal_symbol (copy.c_str ());
                      if (msymbol.minsym != NULL)
-                       pstate->push_new<var_msym_value_operation>
-                         (msymbol.minsym, msymbol.objfile);
+                       pstate->push_new<var_msym_value_operation> (msymbol);
                      else if (!have_full_symbols () && !have_partial_symbols ())
                        error (_("No symbol table is loaded.  Use the \"file\" command"));
                      else
index 9510eee962a5fe0e59ef3390559af6dc9469bf90..5af728a9bbd25979cfb1197209b89fc11b453c7d 100644 (file)
@@ -1005,14 +1005,15 @@ eval_op_var_entry_value (struct type *expect_type, struct expression *exp,
 struct value *
 eval_op_var_msym_value (struct type *expect_type, struct expression *exp,
                        enum noside noside, bool outermost_p,
-                       minimal_symbol *msymbol, struct objfile *objfile)
+                       bound_minimal_symbol msymbol)
 {
-  value *val = evaluate_var_msym_value (noside, objfile, msymbol);
+  value *val = evaluate_var_msym_value (noside, msymbol.objfile,
+                                       msymbol.minsym);
 
   struct type *type = value_type (val);
   if (type->code () == TYPE_CODE_ERROR
       && (noside != EVAL_AVOID_SIDE_EFFECTS || !outermost_p))
-    error_unknown_type (msymbol->print_name ());
+    error_unknown_type (msymbol.minsym->print_name ());
   return val;
 }
 
@@ -2529,9 +2530,8 @@ value *
 var_msym_value_operation::evaluate_for_address (struct expression *exp,
                                                enum noside noside)
 {
-  value *val = evaluate_var_msym_value (noside,
-                                       std::get<1> (m_storage),
-                                       std::get<0> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     {
       struct type *type = lookup_pointer_type (value_type (val));
@@ -2637,14 +2637,12 @@ var_msym_value_operation::evaluate_for_sizeof (struct expression *exp,
                                               enum noside noside)
 
 {
-  minimal_symbol *msymbol = std::get<0> (m_storage);
-  value *mval = evaluate_var_msym_value (noside,
-                                        std::get<1> (m_storage),
-                                        msymbol);
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *mval = evaluate_var_msym_value (noside, b.objfile, b.minsym);
 
   struct type *type = value_type (mval);
   if (type->code () == TYPE_CODE_ERROR)
-    error_unknown_type (msymbol->print_name ());
+    error_unknown_type (b.minsym->print_name ());
 
   /* FIXME: This should be size_t.  */
   struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
@@ -2750,9 +2748,8 @@ var_msym_value_operation::evaluate_for_cast (struct type *to_type,
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return value_zero (to_type, not_lval);
 
-  value *val = evaluate_var_msym_value (noside,
-                                       std::get<1> (m_storage),
-                                       std::get<0> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
 
   val = value_cast (to_type, val);
 
index c12a55e8db38a24696ca425efee14f8ce8699e4b..cc8d9ca6741d33025a1af5f6e5c980e41e15608e 100644 (file)
@@ -53,8 +53,7 @@ extern struct value *eval_op_var_msym_value (struct type *expect_type,
                                             struct expression *exp,
                                             enum noside noside,
                                             bool outermost_p,
-                                            minimal_symbol *msymbol,
-                                            struct objfile *objfile);
+                                            bound_minimal_symbol msymbol);
 extern struct value *eval_op_var_entry_value (struct type *expect_type,
                                              struct expression *exp,
                                              enum noside noside, symbol *sym);
@@ -244,11 +243,9 @@ check_objfile (const struct block *block, struct objfile *objfile)
 }
 
 static inline bool
-check_objfile (minimal_symbol *minsym, struct objfile *objfile)
+check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
 {
-  /* This may seem strange but minsyms are only used with an objfile
-     as well.  */
-  return false;
+  return check_objfile (minsym.objfile, objfile);
 }
 
 static inline bool
@@ -331,7 +328,7 @@ extern void dump_for_expression (struct ui_file *stream, int depth,
 extern void dump_for_expression (struct ui_file *stream, int depth,
                                 symbol *sym);
 extern void dump_for_expression (struct ui_file *stream, int depth,
-                                minimal_symbol *msym);
+                                bound_minimal_symbol msym);
 extern void dump_for_expression (struct ui_file *stream, int depth,
                                 const block *bl);
 extern void dump_for_expression (struct ui_file *stream, int depth,
@@ -340,8 +337,6 @@ extern void dump_for_expression (struct ui_file *stream, int depth,
                                 enum c_string_type_values flags);
 extern void dump_for_expression (struct ui_file *stream, int depth,
                                 enum range_flag flags);
-extern void dump_for_expression (struct ui_file *stream, int depth,
-                                objfile *objf);
 extern void dump_for_expression (struct ui_file *stream, int depth,
                                 const std::unique_ptr<ada_component> &comp);
 
@@ -446,7 +441,7 @@ check_constant (const operation_up &item)
 }
 
 static inline bool
-check_constant (struct minimal_symbol *msym)
+check_constant (bound_minimal_symbol msym)
 {
   return false;
 }
@@ -469,12 +464,6 @@ check_constant (const std::string &str)
   return true;
 }
 
-static inline bool
-check_constant (struct objfile *objfile)
-{
-  return true;
-}
-
 static inline bool
 check_constant (ULONGEST cst)
 {
@@ -700,7 +689,7 @@ protected:
 };
 
 class var_msym_value_operation
-  : public maybe_constant_operation<minimal_symbol *, struct objfile *>
+  : public maybe_constant_operation<bound_minimal_symbol>
 {
 public:
 
@@ -711,8 +700,7 @@ public:
                   enum noside noside) override
   {
     return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
-                                  std::get<0> (m_storage),
-                                  std::get<1> (m_storage));
+                                  std::get<0> (m_storage));
   }
 
   value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
@@ -730,7 +718,7 @@ public:
                           enum noside noside,
                           const std::vector<operation_up> &args) override
   {
-    const char *name = std::get<0> (m_storage)->print_name ();
+    const char *name = std::get<0> (m_storage).minsym->print_name ();
     return operation::evaluate_funcall (expect_type, exp, noside, name, args);
   }
 
index 49919e815fe235ec27550f9e05f1d2831b701d7a..e228beb83a59bb9f52bb6f8f4fd1d94602f4f920 100644 (file)
@@ -110,10 +110,11 @@ dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
 }
 
 void
-dump_for_expression (struct ui_file *stream, int depth, minimal_symbol *msym)
+dump_for_expression (struct ui_file *stream, int depth,
+                    bound_minimal_symbol msym)
 {
-  fprintf_filtered (stream, _("%*sMinsym: %s\n"), depth, "",
-                    msym->print_name ());
+  fprintf_filtered (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
+                   msym.minsym->print_name (), objfile_name (msym.objfile));
 }
 
 void
@@ -162,13 +163,6 @@ dump_for_expression (struct ui_file *stream, int depth,
   fputs_unfiltered ("\n", stream);
 }
 
-void
-dump_for_expression (struct ui_file *stream, int depth, objfile *objf)
-{
-  fprintf_filtered (stream, _("%*sObjfile: %s\n"), depth, "",
-                    objfile_name (objf));
-}
-
 void
 dump_for_expression (struct ui_file *stream, int depth,
                     enum range_flag flags)
index d096cc8b7c91c2de42624389ea31e058e20ffcdd..05822d142db8bf186cbb6870a9f0e309fea69855 100644 (file)
@@ -581,7 +581,7 @@ variable:   name_not_typename
                                lookup_bound_minimal_symbol (arg.c_str ());
                              if (msymbol.minsym != NULL)
                                pstate->push_new<var_msym_value_operation>
-                                 (msymbol.minsym, msymbol.objfile);
+                                 (msymbol);
                              else if (!have_full_symbols ()
                                       && !have_partial_symbols ())
                                error (_("No symbol table is loaded.  "
index 963e8989bf10bd75e7dcd315f498abbf762c3e8d..02ad6bddc4fed4a2269da438c7cbef00b9139edf 100644 (file)
@@ -728,7 +728,7 @@ variable:   name_not_typename
                                lookup_bound_minimal_symbol (arg.c_str ());
                              if (msymbol.minsym != NULL)
                                pstate->push_new<var_msym_value_operation>
-                                 (msymbol.minsym, msymbol.objfile);
+                                 (msymbol);
                              else if (!have_full_symbols ()
                                       && !have_partial_symbols ())
                                error (_("No symbol table is loaded.  "
index 966b27e56438ff5c93bd633cf5d4d26953c37a02..692d38d363ded37deda522687a00c7896a0b2990 100644 (file)
@@ -230,8 +230,7 @@ parser_state::push_symbol (const char *name, block_symbol sym)
     {
       struct bound_minimal_symbol msymbol = lookup_bound_minimal_symbol (name);
       if (msymbol.minsym != NULL)
-       push_new<expr::var_msym_value_operation> (msymbol.minsym,
-                                                 msymbol.objfile);
+       push_new<expr::var_msym_value_operation> (msymbol);
       else if (!have_full_symbols () && !have_partial_symbols ())
        error (_("No symbol table is loaded.  Use the \"file\" command."));
       else
@@ -308,7 +307,7 @@ parser_state::push_dollar (struct stoken str)
   msym = lookup_bound_minimal_symbol (copy.c_str ());
   if (msym.minsym)
     {
-      push_new<expr::var_msym_value_operation> (msym.minsym, msym.objfile);
+      push_new<expr::var_msym_value_operation> (msym);
       return;
     }