This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Improve logical ops in agent expressions
- From: Stan Shebs <stan at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 19 Mar 2010 15:14:05 -0700
- Subject: [PATCH] Improve logical ops in agent expressions
This patch includes several related fixes relating to booleans and
logical operations. We need to handle bool type codes coming in from
C++ land, but at the same time it works better for expression evaluation
overall if the result type is a plain old integer. I also factored out
comparison ops and added support for pointer comparisons. As a bonus, I
kicked off a test file for agent expressions, using the "maint agent"
command, which is available even when the target doesn't do
tracepoints. All committed to trunk.
Stan
2010-03-19 Stan Shebs <stan@codesourcery.com>
* ax-gdb.c (gen_fetch): Handle bool.
(gen_usual_unary): Ditto.
(gen_cast): Ditto.
(gen_equal): New function.
(gen_less): New function.
(gen_expr_binop_rest): Call them, also return integer type from
logical operations.
(gen_expr): Ditto.
* gdb.trace/ax.exp: New file.
Index: ax-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-gdb.c,v
retrieving revision 1.71
diff -p -r1.71 ax-gdb.c
*** ax-gdb.c 18 Mar 2010 16:01:29 -0000 1.71
--- ax-gdb.c 19 Mar 2010 21:59:29 -0000
*************** gen_fetch (struct agent_expr *ax, struct
*** 478,483 ****
--- 478,484 ----
case TYPE_CODE_ENUM:
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
+ case TYPE_CODE_BOOL:
/* It's a scalar value, so we know how to dereference it. How
many bytes long is it? */
switch (TYPE_LENGTH (type))
*************** gen_usual_unary (struct expression *exp,
*** 831,838 ****
case TYPE_CODE_UNION:
return;
! /* If the value is an enum, call it an integer. */
case TYPE_CODE_ENUM:
value->type = builtin_type (exp->gdbarch)->builtin_int;
break;
}
--- 832,840 ----
case TYPE_CODE_UNION:
return;
! /* If the value is an enum or a bool, call it an integer. */
case TYPE_CODE_ENUM:
+ case TYPE_CODE_BOOL:
value->type = builtin_type (exp->gdbarch)->builtin_int;
break;
}
*************** gen_cast (struct agent_expr *ax, struct
*** 998,1003 ****
--- 1000,1006 ----
error (_("Invalid type cast: intended type must be scalar."));
case TYPE_CODE_ENUM:
+ case TYPE_CODE_BOOL:
/* We don't have to worry about the size of the value, because
all our integral values are fully sign-extended, and when
casting pointers we can do anything we like. Is there any
*************** an integer nor a pointer of the same typ
*** 1095,1100 ****
--- 1098,1130 ----
value->kind = axs_rvalue;
}
+ static void
+ gen_equal (struct agent_expr *ax, struct axs_value *value,
+ struct axs_value *value1, struct axs_value *value2,
+ struct type *result_type)
+ {
+ if (pointer_type (value1->type) || pointer_type (value2->type))
+ ax_simple (ax, aop_equal);
+ else
+ gen_binop (ax, value, value1, value2,
+ aop_equal, aop_equal, 0, "equal");
+ value->type = result_type;
+ value->kind = axs_rvalue;
+ }
+
+ static void
+ gen_less (struct agent_expr *ax, struct axs_value *value,
+ struct axs_value *value1, struct axs_value *value2,
+ struct type *result_type)
+ {
+ if (pointer_type (value1->type) || pointer_type (value2->type))
+ ax_simple (ax, aop_less_unsigned);
+ else
+ gen_binop (ax, value, value1, value2,
+ aop_less_signed, aop_less_unsigned, 0, "less than");
+ value->type = result_type;
+ value->kind = axs_rvalue;
+ }
/* Generate code for a binary operator that doesn't do pointer magic.
We set VALUE to describe the result value; we assume VALUE1 and
*************** gen_expr (struct expression *exp, union
*** 1733,1738 ****
--- 1763,1769 ----
struct axs_value value1, value2, value3;
enum exp_opcode op = (*pc)[0].opcode, op2;
int if1, go1, if2, go2, end;
+ struct type *int_type = builtin_type (exp->gdbarch)->builtin_int;
/* If we're looking at a constant expression, just push its value. */
{
*************** gen_expr (struct expression *exp, union
*** 1794,1800 ****
ax_const_l (ax, 0);
ax_label (ax, end, ax->len);
value->kind = axs_rvalue;
! value->type = language_bool_type (exp->language_defn, exp->gdbarch);
break;
case BINOP_LOGICAL_OR:
--- 1825,1831 ----
ax_const_l (ax, 0);
ax_label (ax, end, ax->len);
value->kind = axs_rvalue;
! value->type = int_type;
break;
case BINOP_LOGICAL_OR:
*************** gen_expr (struct expression *exp, union
*** 1813,1819 ****
ax_const_l (ax, 1);
ax_label (ax, end, ax->len);
value->kind = axs_rvalue;
! value->type = language_bool_type (exp->language_defn, exp->gdbarch);
break;
case TERNOP_COND:
--- 1844,1850 ----
ax_const_l (ax, 1);
ax_label (ax, end, ax->len);
value->kind = axs_rvalue;
! value->type = int_type;
break;
case TERNOP_COND:
*************** gen_expr (struct expression *exp, union
*** 1824,1831 ****
bytecodes in order, but if_goto jumps on true, so we invert
the sense of A. Then we can do B by dropping through, and
jump to do C. */
! gen_logical_not (ax, &value1,
! language_bool_type (exp->language_defn, exp->gdbarch));
if1 = ax_goto (ax, aop_if_goto);
gen_expr (exp, pc, ax, &value2);
gen_usual_unary (exp, ax, &value2);
--- 1855,1861 ----
bytecodes in order, but if_goto jumps on true, so we invert
the sense of A. Then we can do B by dropping through, and
jump to do C. */
! gen_logical_not (ax, &value1, int_type);
if1 = ax_goto (ax, aop_if_goto);
gen_expr (exp, pc, ax, &value2);
gen_usual_unary (exp, ax, &value2);
*************** gen_expr (struct expression *exp, union
*** 2027,2034 ****
(*pc)++;
gen_expr (exp, pc, ax, value);
gen_usual_unary (exp, ax, value);
! gen_logical_not (ax, value,
! language_bool_type (exp->language_defn, exp->gdbarch));
break;
case UNOP_COMPLEMENT:
--- 2057,2063 ----
(*pc)++;
gen_expr (exp, pc, ax, value);
gen_usual_unary (exp, ax, value);
! gen_logical_not (ax, value, int_type);
break;
case UNOP_COMPLEMENT:
*************** gen_expr_binop_rest (struct expression *
*** 2144,2149 ****
--- 2173,2180 ----
struct agent_expr *ax, struct axs_value *value,
struct axs_value *value1, struct axs_value *value2)
{
+ struct type *int_type = builtin_type (exp->gdbarch)->builtin_int;
+
gen_expr (exp, pc, ax, value2);
gen_usual_unary (exp, ax, value2);
gen_usual_arithmetic (exp, ax, value1, value2);
*************** cannot subscript requested type: cannot
*** 2246,2289 ****
break;
case BINOP_EQUAL:
! gen_binop (ax, value, value1, value2,
! aop_equal, aop_equal, 0, "equal");
break;
case BINOP_NOTEQUAL:
! gen_binop (ax, value, value1, value2,
! aop_equal, aop_equal, 0, "equal");
! gen_logical_not (ax, value,
! language_bool_type (exp->language_defn,
! exp->gdbarch));
break;
case BINOP_LESS:
! gen_binop (ax, value, value1, value2,
! aop_less_signed, aop_less_unsigned, 0, "less than");
break;
case BINOP_GTR:
ax_simple (ax, aop_swap);
! gen_binop (ax, value, value1, value2,
! aop_less_signed, aop_less_unsigned, 0, "less than");
break;
case BINOP_LEQ:
ax_simple (ax, aop_swap);
! gen_binop (ax, value, value1, value2,
! aop_less_signed, aop_less_unsigned, 0, "less than");
! gen_logical_not (ax, value,
! language_bool_type (exp->language_defn,
! exp->gdbarch));
break;
case BINOP_GEQ:
! gen_binop (ax, value, value1, value2,
! aop_less_signed, aop_less_unsigned, 0, "less than");
! gen_logical_not (ax, value,
! language_bool_type (exp->language_defn,
! exp->gdbarch));
break;
default:
--- 2277,2308 ----
break;
case BINOP_EQUAL:
! gen_equal (ax, value, value1, value2, int_type);
break;
case BINOP_NOTEQUAL:
! gen_equal (ax, value, value1, value2, int_type);
! gen_logical_not (ax, value, int_type);
break;
case BINOP_LESS:
! gen_less (ax, value, value1, value2, int_type);
break;
case BINOP_GTR:
ax_simple (ax, aop_swap);
! gen_less (ax, value, value1, value2, int_type);
break;
case BINOP_LEQ:
ax_simple (ax, aop_swap);
! gen_less (ax, value, value1, value2, int_type);
! gen_logical_not (ax, value, int_type);
break;
case BINOP_GEQ:
! gen_less (ax, value, value1, value2, int_type);
! gen_logical_not (ax, value, int_type);
break;
default:
Index: testsuite/gdb.trace/ax.exp
===================================================================
RCS file: testsuite/gdb.trace/ax.exp
diff -N testsuite/gdb.trace/ax.exp
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gdb.trace/ax.exp 19 Mar 2010 21:59:29 -0000
***************
*** 0 ****
--- 1,138 ----
+ # Copyright 2010 Free Software Foundation, Inc.
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 3 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ # Tests of agent expression handling.
+
+ # The tests that use the maintenance command do not need tracepoint
+ # support on the target, but they do want a live program.
+
+ load_lib "trace-support.exp";
+
+ if $tracelevel then {
+ strace $tracelevel
+ }
+
+ set prms_id 0
+ set bug_id 0
+
+ gdb_exit
+ gdb_start
+ set testfile "actions"
+ set srcfile ${testfile}.c
+ set binfile $objdir/$subdir/ax
+ if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
+ executable {debug nowarnings}] != "" } {
+ untested ax.exp
+ return -1
+ }
+
+ gdb_load $binfile
+ runto_main
+ gdb_reinitialize_dir $srcdir/$subdir
+
+ gdb_test "maint agent 12" ".*const8 12.*pop.*end.*" "maint agent 12"
+
+ gdb_test "maint agent gdb_char_test" "" "maint agent gdb_char_test"
+
+ gdb_test "maint agent gdb_arr_test\[12\]" "" "maint agent gdb_arr_test\[12\]"
+
+ gdb_test "maint agent gdb_arr_test\[gdb_short_test\]" "" "maint agent gdb_arr_test\[gdb_short_test\]"
+
+ gdb_test "maint agent gdb_struct1_test" "" "maint agent gdb_struct1_test"
+
+ gdb_test "maint agent gdb_struct1_test.s" "" "maint agent gdb_struct1_test.s"
+
+ gdb_test "maint agent gdb_struct1_test.arr\[gdb_struct1_test.c\]" "" "maint agent gdb_struct1_test.arr\[gdb_struct1_test.c\]"
+
+ gdb_test "maint agent gdb_structp_test" "" "maint agent gdb_structp_test"
+
+ gdb_test "maint agent gdb_structp_test->l" "" "maint agent gdb_structp_test->l"
+
+ gdb_test "maint agent gdb_structp_test->bfield" "" "maint agent gdb_structp_test->bfield"
+
+ gdb_test "maint agent gdb_long_test + gdb_short_test" "" "maint agent gdb_long_test + gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test - gdb_short_test" "" "maint agent gdb_long_test - gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test * gdb_short_test" "" "maint agent gdb_long_test * gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test / gdb_short_test" "" "maint agent gdb_long_test / gdb_short_test"
+
+ gdb_test "maint agent gdb_structp_test + 1" "" "maint agent gdb_structp_test + 1"
+
+ gdb_test "maint agent gdb_long_test == gdb_short_test" "" "maint agent gdb_long_test == gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test != gdb_short_test" "" "maint agent gdb_long_test != gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test < gdb_short_test" "" "maint agent gdb_long_test < gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test <= gdb_short_test" "" "maint agent gdb_long_test <= gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test > gdb_short_test" "" "maint agent gdb_long_test > gdb_short_test"
+
+ gdb_test "maint agent gdb_long_test >= gdb_short_test" "" "maint agent gdb_long_test >= gdb_short_test"
+
+ gdb_test "maint agent &gdb_long_test == &gdb_short_test" "" "maint agent &gdb_long_test == &gdb_short_test"
+
+ gdb_test "maint agent &gdb_long_test < &gdb_short_test" "" "maint agent &gdb_long_test < &gdb_short_test"
+
+ # Now test eval version of agent expressions.
+
+ gdb_test "maint agent-eval 12" ".*const8 12.*end.*" "maint agent-eval 12"
+
+ gdb_test "maint agent-eval gdb_char_test" "" "maint agent-eval gdb_char_test"
+
+ gdb_test "maint agent-eval gdb_arr_test\[12\]" "" "maint agent-eval gdb_arr_test\[12\]"
+
+ gdb_test "maint agent-eval gdb_arr_test\[gdb_short_test\]" "" "maint agent-eval gdb_arr_test\[gdb_short_test\]"
+
+ gdb_test "maint agent-eval gdb_struct1_test" "" "maint agent-eval gdb_struct1_test"
+
+ gdb_test "maint agent-eval gdb_struct1_test.s" "" "maint agent-eval gdb_struct1_test.s"
+
+ gdb_test "maint agent-eval gdb_struct1_test.arr\[gdb_struct1_test.c\]" "" "maint agent-eval gdb_struct1_test.arr\[gdb_struct1_test.c\]"
+
+ gdb_test "maint agent-eval gdb_structp_test" "" "maint agent-eval gdb_structp_test"
+
+ gdb_test "maint agent-eval gdb_structp_test->l" "" "maint agent-eval gdb_structp_test->l"
+
+ gdb_test "maint agent-eval gdb_structp_test->bfield" "" "maint agent-eval gdb_structp_test->bfield"
+
+ gdb_test "maint agent-eval gdb_long_test + gdb_short_test" "" "maint agent-eval gdb_long_test + gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test - gdb_short_test" "" "maint agent-eval gdb_long_test - gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test * gdb_short_test" "" "maint agent-eval gdb_long_test * gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test / gdb_short_test" "" "maint agent-eval gdb_long_test / gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_structp_test + 1" "" "maint agent-eval gdb_structp_test + 1"
+
+ gdb_test "maint agent-eval gdb_long_test == gdb_short_test" "" "maint agent-eval gdb_long_test == gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test != gdb_short_test" "" "maint agent-eval gdb_long_test != gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test < gdb_short_test" "" "maint agent-eval gdb_long_test < gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test <= gdb_short_test" "" "maint agent-eval gdb_long_test <= gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test > gdb_short_test" "" "maint agent-eval gdb_long_test > gdb_short_test"
+
+ gdb_test "maint agent-eval gdb_long_test >= gdb_short_test" "" "maint agent-eval gdb_long_test >= gdb_short_test"
+
+ gdb_test "maint agent-eval &gdb_long_test == &gdb_short_test" ".*equal.*end.*" "maint agent-eval &gdb_long_test == &gdb_short_test"
+
+ gdb_test "maint agent-eval &gdb_long_test < &gdb_short_test" "" "maint agent-eval &gdb_long_test < &gdb_short_test"
+