Handle fixed-point division by zero

fixed_point_binop did not account for division by zero.  This would
lead to gdb getting SIGFPE and subsequently cause some test cases to
hang.

gdb/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

	* valarith.c (fixed_point_binop): Call error on division by zero.

gdb/testsuite/ChangeLog
2020-12-14  Tom Tromey  <tromey@adacore.com>

	* gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero.
This commit is contained in:
Tom Tromey 2020-12-14 07:35:45 -07:00
parent bf6d803782
commit a3bdae4ef8
4 changed files with 13 additions and 0 deletions

View file

@ -1,3 +1,7 @@
2020-12-14 Tom Tromey <tromey@adacore.com>
* valarith.c (fixed_point_binop): Call error on division by zero.
2020-12-13 Tom Tromey <tom@tromey.com>
* gdbtypes.c (safe_parse_type): Make argument const.

View file

@ -1,3 +1,7 @@
2020-12-14 Tom Tromey <tromey@adacore.com>
* gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero.
2020-12-13 Tom de Vries <tdevries@suse.de>
PR testsuite/26953

View file

@ -164,6 +164,9 @@ gdb_test "print pck.fp3_var * 1" \
gdb_test "print pck.fp3_var / pck.fp3_var" \
" = 1"
gdb_test "print pck.fp3_var / 0" \
"Division by zero"
gdb_test "print pck.fp1_range_var - 0.5" \
" = 0.5"

View file

@ -965,6 +965,8 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
break;
case BINOP_DIV:
if (mpq_sgn (v2.val) == 0)
error (_("Division by zero"));
mpq_div (res.val, v1.val, v2.val);
val = fixed_point_to_value (res);
break;