Split out eval_op_func_static_var
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:27:58 +0000 (07:27 -0700)
This splits OP_FUNC_STATIC_VAR into a new function for future use.

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

* eval.c (eval_op_func_static_var): New function.
(evaluate_subexp_standard): Use it.

gdb/ChangeLog
gdb/eval.c

index 3e13478f885e40810a07bb9a11e1449c021feaee..a549ce0da6a6095d6c1bb401249ea5c1bc2dd769 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * eval.c (eval_op_func_static_var): New function.
+       (evaluate_subexp_standard): Use it.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * eval.c (eval_op_var_msym_value): New function.
index ee7712281024e6d4c29fbe9d2841ec9d2108c037..c36594304d40672cf23089e07ded996474cf5cd0 100644 (file)
@@ -1234,6 +1234,23 @@ eval_op_var_msym_value (struct type *expect_type, struct expression *exp,
   return val;
 }
 
+/* Helper function that implements the body of OP_FUNC_STATIC_VAR.  */
+
+static struct value *
+eval_op_func_static_var (struct type *expect_type, struct expression *exp,
+                        enum noside noside,
+                        value *func, const char *var)
+{
+  if (noside == EVAL_SKIP)
+    return eval_skip_value (exp);
+  CORE_ADDR addr = value_address (func);
+  const block *blk = block_for_pc (addr);
+  struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
+  if (sym.symbol == NULL)
+    error (_("No symbol \"%s\" in specified context."), var);
+  return evaluate_var_value (noside, sym.block, sym.symbol);
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
                          struct expression *exp, int *pos,
@@ -1318,17 +1335,9 @@ evaluate_subexp_standard (struct type *expect_type,
 
       {
        value *func = evaluate_subexp_standard (NULL, exp, pos, noside);
-       CORE_ADDR addr = value_address (func);
-
-       const block *blk = block_for_pc (addr);
-       const char *var = &exp->elts[pc + 2].string;
-
-       struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
-
-       if (sym.symbol == NULL)
-         error (_("No symbol \"%s\" in specified context."), var);
 
-       return evaluate_var_value (noside, sym.block, sym.symbol);
+       return eval_op_func_static_var (expect_type, exp, noside, func,
+                                       &exp->elts[pc + 2].string);
       }
 
     case OP_LAST: