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))
case TYPE_CODE_UNION:
return;
- /* If the value is an enum, call it an integer. */
+ /* 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;
}
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
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
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. */
{
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);
+ value->type = int_type;
break;
case BINOP_LOGICAL_OR:
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);
+ value->type = int_type;
break;
case TERNOP_COND:
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));
+ 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);
(*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));
+ gen_logical_not (ax, value, int_type);
break;
case UNOP_COMPLEMENT:
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);
break;
case BINOP_EQUAL:
- gen_binop (ax, value, value1, value2,
- aop_equal, aop_equal, 0, "equal");
+ gen_equal (ax, value, value1, value2, int_type);
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));
+ gen_equal (ax, value, value1, value2, int_type);
+ gen_logical_not (ax, value, int_type);
break;
case BINOP_LESS:
- gen_binop (ax, value, value1, value2,
- aop_less_signed, aop_less_unsigned, 0, "less than");
+ gen_less (ax, value, value1, value2, int_type);
break;
case BINOP_GTR:
ax_simple (ax, aop_swap);
- gen_binop (ax, value, value1, value2,
- aop_less_signed, aop_less_unsigned, 0, "less than");
+ gen_less (ax, value, value1, value2, int_type);
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));
+ gen_less (ax, value, value1, value2, int_type);
+ gen_logical_not (ax, value, int_type);
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));
+ gen_less (ax, value, value1, value2, int_type);
+ gen_logical_not (ax, value, int_type);
break;
default:
--- /dev/null
+# 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"
+