From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 48848385480A for ; Fri, 11 Dec 2020 15:15:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 48848385480A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 290C856220; Fri, 11 Dec 2020 10:15:50 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id yvmSXAjep+hp; Fri, 11 Dec 2020 10:15:50 -0500 (EST) Received: from murgatroyd.Home (97-122-89-243.hlrn.qwest.net [97.122.89.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id DA34C5621F; Fri, 11 Dec 2020 10:15:49 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle fixed-point division by zero Date: Fri, 11 Dec 2020 08:15:48 -0700 Message-Id: <20201211151548.732285-1-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2020 15:15:51 -0000 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-11 Tom Tromey * valarith.c (fixed_point_binop): Call error on division by zero. gdb/testsuite/ChangeLog 2020-12-11 Tom Tromey * gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero. --- gdb/ChangeLog | 4 ++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp | 3 +++ gdb/valarith.c | 2 ++ 4 files changed, 13 insertions(+) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp index 67d1d34d8f3..2c859d1fd16 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp @@ -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" diff --git a/gdb/valarith.c b/gdb/valarith.c index 37988f1dfa7..6854d9b80f0 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -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; -- 2.26.2