This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: [PATCH]: Allow struct compare in expressions.
- To: Michael Snyder <msnyder at cygnus dot com>
- Subject: Re: [PATCH]: Allow struct compare in expressions.
- From: Jim Blandy <jimb at zwingli dot cygnus dot com>
- Date: 27 Mar 2000 15:54:40 -0500
- Cc: gdb-patches at sourceware dot cygnus dot com
- References: <200003222043.MAA10512@cleaver.cygnus.com>
The name "binop_user_defined_p" suggests to me that it's supposed to
tell if there is a user-defined binary operation --- for example, a
C++ overloaded operator --- for that operator on those two types.
Shouldn't its definition be corrected, instead of adding checks at certain
call sites?
For example, I think binop_user_defined_p should return zero if
total_number_of_methods is zero. Then no change is needed in
evaluate_subexp_standard. That's just a small modification to this
patch.
Ideally, binop_user_defined_p should actually *check* whether OP is
actually overloaded on those types, using the same criteria
value_x_binop does. It's going to be stupid if binop_user_defined_p
says "yes", but then value_x_binop can't find the operator.
> The following change allows GDB to evaluate (and set watchpoints on)
> expressions of the form (a == b) and (a != b), where a and b are
> simple C structs or unions. It would be possible to extend this
> further by allowing simple binary comparison for classes that don't
> have an operator== method: I leave that as an exercise for someone
> else.
>
> Jim Blandy, David Taylor, I think both of your approvals is required.
>
> 2000-03-22 Michael Snyder <msnyder@cleaver.cygnus.com>
>
> * eval.c (evaluate_subexp_standard): allow for simple comparison
> of structures, in the absense of C++ method symbols.
> * symtab.c (total_number_of_methods): make public, for use above.
> * symtab.h (total_number_of_methods): publish prototype.
>
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/src/src/gdb/ChangeLog,v
> retrieving revision 1.163
> diff -c -r1.163 ChangeLog
> *** ChangeLog 2000/03/22 09:45:01 1.163
> --- ChangeLog 2000/03/22 20:38:33
> ***************
> *** 1,3 ****
> --- 1,10 ----
> + 2000-03-22 Michael Snyder <msnyder@cleaver.cygnus.com>
> +
> + * eval.c (evaluate_subexp_standard): allow for simple comparison
> + of structures, in the absense of C++ method symbols.
> + * symtab.c (total_number_of_methods): make public, for use above.
> + * symtab.h (total_number_of_methods): publish prototype.
> +
> 2000-03-22 Mark Kettenis <kettenis@gnu.org>
>
> * config/i386/tm-i386aix.h (I386_AIX_TARGET): Remove.
> Index: eval.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/eval.c,v
> retrieving revision 1.2
> diff -c -r1.2 eval.c
> *** eval.c 2000/03/14 17:01:04 1.2
> --- eval.c 2000/03/22 20:38:34
> ***************
> *** 1448,1454 ****
> arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
> if (noside == EVAL_SKIP)
> goto nosideret;
> ! if (binop_user_defined_p (op, arg1, arg2))
> {
> return value_x_binop (arg1, arg2, op, OP_NULL, noside);
> }
> --- 1448,1459 ----
> arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
> if (noside == EVAL_SKIP)
> goto nosideret;
> !
> ! /* NOTE: because BINOP_EQUAL is a legal operaton for
> ! C structs (as opposed to C++ classes), revert to
> ! simple value comparison if the type has no methods. */
> ! if (binop_user_defined_p (op, arg1, arg2) &&
> ! total_number_of_methods (arg1->type) > 0)
> {
> return value_x_binop (arg1, arg2, op, OP_NULL, noside);
> }
> ***************
> *** 1463,1469 ****
> arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
> if (noside == EVAL_SKIP)
> goto nosideret;
> ! if (binop_user_defined_p (op, arg1, arg2))
> {
> return value_x_binop (arg1, arg2, op, OP_NULL, noside);
> }
> --- 1468,1479 ----
> arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
> if (noside == EVAL_SKIP)
> goto nosideret;
> !
> ! /* NOTE: because BINOP_NOTEQUAL is a legal operaton for
> ! C structs (as opposed to C++ classes), revert to
> ! simple value comparison if the type has no methods. */
> ! if (binop_user_defined_p (op, arg1, arg2) &&
> ! total_number_of_methods (arg1->type) > 0)
> {
> return value_x_binop (arg1, arg2, op, OP_NULL, noside);
> }
> Index: symtab.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/symtab.c,v
> retrieving revision 1.2
> diff -c -r1.2 symtab.c
> *** symtab.c 2000/02/08 04:39:02 1.2
> --- symtab.c 2000/03/22 20:38:34
> ***************
> *** 2217,2225 ****
> reader because the type of the baseclass might still be stubbed
> when the definition of the derived class is parsed. */
>
> ! static int total_number_of_methods PARAMS ((struct type * type));
> !
> ! static int
> total_number_of_methods (type)
> struct type *type;
> {
> --- 2217,2223 ----
> reader because the type of the baseclass might still be stubbed
> when the definition of the derived class is parsed. */
>
> ! int
> total_number_of_methods (type)
> struct type *type;
> {
> Index: symtab.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/symtab.h,v
> retrieving revision 1.4
> diff -c -r1.4 symtab.h
> *** symtab.h 2000/03/21 22:37:42 1.4
> --- symtab.h 2000/03/22 20:38:34
> ***************
> *** 1462,1467 ****
> --- 1462,1472 ----
> extern int
> in_prologue PARAMS ((CORE_ADDR pc, CORE_ADDR func_start));
>
> + /* Number of method symbols for TYPE
> + (and all its base classes) */
> + extern int
> + total_number_of_methods PARAMS ((struct type * type));
> +
> extern struct symbol *
> fixup_symbol_section PARAMS ((struct symbol *, struct objfile *));
>
>