aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:27:59 -0700
commitfb461aa39e52cbbe722136bdbb9625bf993f59f0 (patch)
tree2665b5156b4290b3af2545c9a82d30a3600f56de
parent3e96c4fc0f4b286c96e6c95618c7f34293185308 (diff)
downloadgdb-fb461aa39e52cbbe722136bdbb9625bf993f59f0.zip
gdb-fb461aa39e52cbbe722136bdbb9625bf993f59f0.tar.gz
gdb-fb461aa39e52cbbe722136bdbb9625bf993f59f0.tar.bz2
Split out eval_op_structop_ptr
This splits STRUCTOP_PTR into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * eval.c (eval_op_structop_ptr): New function. (evaluate_subexp_standard): Use it.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/eval.c111
2 files changed, 66 insertions, 50 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f3cbdd0..fb4299e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * eval.c (eval_op_structop_ptr): New function.
+ (evaluate_subexp_standard): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* eval.c (eval_op_structop_struct): New function.
(evaluate_subexp_standard): Use it.
diff --git a/gdb/eval.c b/gdb/eval.c
index 753e914..4800438 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1354,6 +1354,65 @@ eval_op_structop_struct (struct type *expect_type, struct expression *exp,
return arg3;
}
+/* A helper function for STRUCTOP_PTR. */
+
+static struct value *
+eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
+ enum noside noside, enum exp_opcode op,
+ struct value *arg1, const char *string)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+
+ /* Check to see if operator '->' has been overloaded. If so replace
+ arg1 with the value returned by evaluating operator->(). */
+ while (unop_user_defined_p (op, arg1))
+ {
+ struct value *value = NULL;
+ try
+ {
+ value = value_x_unop (arg1, op, noside);
+ }
+
+ catch (const gdb_exception_error &except)
+ {
+ if (except.error == NOT_FOUND_ERROR)
+ break;
+ else
+ throw;
+ }
+
+ arg1 = value;
+ }
+
+ /* JYG: if print object is on we need to replace the base type
+ with rtti type in order to continue on with successful
+ lookup of member / method only available in the rtti type. */
+ {
+ struct type *arg_type = value_type (arg1);
+ struct type *real_type;
+ int full, using_enc;
+ LONGEST top;
+ struct value_print_options opts;
+
+ get_user_print_options (&opts);
+ if (opts.objectprint && TYPE_TARGET_TYPE (arg_type)
+ && (TYPE_TARGET_TYPE (arg_type)->code () == TYPE_CODE_STRUCT))
+ {
+ real_type = value_rtti_indirect_type (arg1, &full, &top,
+ &using_enc);
+ if (real_type)
+ arg1 = value_cast (real_type, arg1);
+ }
+ }
+
+ struct value *arg3 = value_struct_elt (&arg1, NULL, string,
+ NULL, "structure pointer");
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
+ return arg3;
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
@@ -1952,56 +2011,8 @@ evaluate_subexp_standard (struct type *expect_type,
tem = longest_to_int (exp->elts[pc + 1].longconst);
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
- if (noside == EVAL_SKIP)
- return eval_skip_value (exp);
-
- /* Check to see if operator '->' has been overloaded. If so replace
- arg1 with the value returned by evaluating operator->(). */
- while (unop_user_defined_p (op, arg1))
- {
- struct value *value = NULL;
- try
- {
- value = value_x_unop (arg1, op, noside);
- }
-
- catch (const gdb_exception_error &except)
- {
- if (except.error == NOT_FOUND_ERROR)
- break;
- else
- throw;
- }
-
- arg1 = value;
- }
-
- /* JYG: if print object is on we need to replace the base type
- with rtti type in order to continue on with successful
- lookup of member / method only available in the rtti type. */
- {
- struct type *arg_type = value_type (arg1);
- struct type *real_type;
- int full, using_enc;
- LONGEST top;
- struct value_print_options opts;
-
- get_user_print_options (&opts);
- if (opts.objectprint && TYPE_TARGET_TYPE (arg_type)
- && (TYPE_TARGET_TYPE (arg_type)->code () == TYPE_CODE_STRUCT))
- {
- real_type = value_rtti_indirect_type (arg1, &full, &top,
- &using_enc);
- if (real_type)
- arg1 = value_cast (real_type, arg1);
- }
- }
-
- arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
- NULL, "structure pointer");
- if (noside == EVAL_AVOID_SIDE_EFFECTS)
- arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
- return arg3;
+ return eval_op_structop_ptr (expect_type, exp, noside, op, arg1,
+ &exp->elts[pc + 2].string);
case STRUCTOP_MEMBER:
case STRUCTOP_MPTR: