From patchwork Wed Jun 19 12:06:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33208 Received: (qmail 106137 invoked by alias); 19 Jun 2019 12:06:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 106129 invoked by uid 89); 19 Jun 2019 12:06:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jun 2019 12:06:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B2862560B9; Wed, 19 Jun 2019 08:06:37 -0400 (EDT) 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 WJsICEcBIHCD; Wed, 19 Jun 2019 08:06:37 -0400 (EDT) Received: from murgatroyd.Home (75-166-12-78.hlrn.qwest.net [75.166.12.78]) (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 5C998560B8; Wed, 19 Jun 2019 08:06:37 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Fix crash when setting breakpoint condition Date: Wed, 19 Jun 2019 06:06:35 -0600 Message-Id: <20190619120635.25475-1-tromey@adacore.com> MIME-Version: 1.0 gdb could crash when setting a breakpoint condition on a breakpoint when using the Ada language. The problem occurred because the ada_evaluate_subexp would try to evaluate the array to compute its attributes, but evaluating can't really be done at this time. This patch fixes the problem by arranging not to try to evaluate in EVAL_AVOID_SIDE_EFFECTS mode when computing an attribute. Tested on x86-64 Fedora 29. Because this is Ada-specific, and because Joel approved it internally, I am checking it in. gdb/ChangeLog 2019-06-19 Tom Tromey * ada-lang.c (ada_evaluate_subexp) : Handle EVAL_AVOID_SIDE_EFFECTS specially. gdb/testsuite/ChangeLog 2019-06-19 Tom Tromey * gdb.ada/length_cond.exp: New file. * gdb.ada/length_cond/length_cond.adb: New file. * gdb.ada/length_cond/pck.adb: New file. * gdb.ada/length_cond/pck.ads: New file. --- gdb/ChangeLog | 5 +++ gdb/ada-lang.c | 34 +++++++++++--- gdb/testsuite/ChangeLog | 7 +++ gdb/testsuite/gdb.ada/length_cond.exp | 44 +++++++++++++++++++ .../gdb.ada/length_cond/length_cond.adb | 37 ++++++++++++++++ gdb/testsuite/gdb.ada/length_cond/pck.adb | 21 +++++++++ gdb/testsuite/gdb.ada/length_cond/pck.ads | 18 ++++++++ 7 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/length_cond.exp create mode 100644 gdb/testsuite/gdb.ada/length_cond/length_cond.adb create mode 100644 gdb/testsuite/gdb.ada/length_cond/pck.adb create mode 100644 gdb/testsuite/gdb.ada/length_cond/pck.ads diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index bf17c67f4d0..1e996557b6e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -11055,8 +11055,34 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, if (noside == EVAL_SKIP) goto nosideret; + else if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + if (type_arg == NULL) + type_arg = value_type (arg1); + + if (ada_is_constrained_packed_array_type (type_arg)) + type_arg = decode_constrained_packed_array_type (type_arg); - if (type_arg == NULL) + if (!discrete_type_p (type_arg)) + { + switch (op) + { + default: /* Should never happen. */ + error (_("unexpected attribute encountered")); + case OP_ATR_FIRST: + case OP_ATR_LAST: + type_arg = ada_index_type (type_arg, tem, + ada_attribute_name (op)); + break; + case OP_ATR_LENGTH: + type_arg = builtin_type (exp->gdbarch)->builtin_int; + break; + } + } + + return value_zero (type_arg, not_lval); + } + else if (type_arg == NULL) { arg1 = ada_coerce_ref (arg1); @@ -11073,9 +11099,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, type = builtin_type (exp->gdbarch)->builtin_int; } - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return allocate_value (type); - switch (op) { default: /* Should never happen. */ @@ -11133,9 +11156,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, type = builtin_type (exp->gdbarch)->builtin_int; } - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return allocate_value (type); - switch (op) { default: diff --git a/gdb/testsuite/gdb.ada/length_cond.exp b/gdb/testsuite/gdb.ada/length_cond.exp new file mode 100644 index 00000000000..53e9187dc4d --- /dev/null +++ b/gdb/testsuite/gdb.ada/length_cond.exp @@ -0,0 +1,44 @@ +# Copyright 2019 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 . + +load_lib "ada.exp" + +standard_ada_testfile length_cond + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "BREAKPOINT" ${testdir}/length_cond.adb] +gdb_breakpoint length_cond.adb:$bp_location message + +# Resolving the conditional expression would cause a crash, so it's +# enough to just set the conditions. + +foreach var {loc enum_val int_val} { + foreach attr {first last} { + gdb_test_no_output "cond 1 $var'$attr > 15" + } +} + +gdb_test_no_output "cond 1 loc'length > 15" + +foreach attr {first last length} { + foreach val {1 2} { + gdb_test_no_output "cond 1 my_array'${attr}($val) > 15" + } +} diff --git a/gdb/testsuite/gdb.ada/length_cond/length_cond.adb b/gdb/testsuite/gdb.ada/length_cond/length_cond.adb new file mode 100644 index 00000000000..7b563c363ed --- /dev/null +++ b/gdb/testsuite/gdb.ada/length_cond/length_cond.adb @@ -0,0 +1,37 @@ +-- Copyright 2019 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 . + +with Pck; + +procedure Length_Cond is + type Enum is (One, Two, Three); + Enum_Val : Enum := Three; + + type My_Int is range -23 .. 23; + Int_Val : My_Int := 0; + + type My_Array is array (0..1, 0..1) of Boolean; + Array_Val : My_Array := ((True, False), (False, True)); + + procedure p (s : String) is + loc : String := s & "."; + begin + Pck.Do_Nothing (loc); -- BREAKPOINT + end p; +begin + for I in 1 .. 25 loop + p ((1 .. I => 'X')); + end loop; +end Length_Cond; diff --git a/gdb/testsuite/gdb.ada/length_cond/pck.adb b/gdb/testsuite/gdb.ada/length_cond/pck.adb new file mode 100644 index 00000000000..79bbe599b68 --- /dev/null +++ b/gdb/testsuite/gdb.ada/length_cond/pck.adb @@ -0,0 +1,21 @@ +-- Copyright 2019 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 . + +package body Pck is + procedure Do_Nothing (A : String) is + begin + null; + end Do_Nothing; +end Pck; diff --git a/gdb/testsuite/gdb.ada/length_cond/pck.ads b/gdb/testsuite/gdb.ada/length_cond/pck.ads new file mode 100644 index 00000000000..433b389dfcb --- /dev/null +++ b/gdb/testsuite/gdb.ada/length_cond/pck.ads @@ -0,0 +1,18 @@ +-- Copyright 2019 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 . + +package Pck is + procedure Do_Nothing (A : String); +end Pck;