From patchwork Thu Jul 23 11:47:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 7813 Received: (qmail 32709 invoked by alias); 23 Jul 2015 11:47:30 -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 32699 invoked by uid 89); 23 Jul 2015 11:47:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 23 Jul 2015 11:47:27 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id E94AD28B35A7; Thu, 23 Jul 2015 13:47:24 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DVMmMwVJQNUm; Thu, 23 Jul 2015 13:47:24 +0200 (CEST) Received: from cacatoes.act-europe.fr (cacatoes.act-europe.fr [10.10.1.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id D652F28B35A3; Thu, 23 Jul 2015 13:47:24 +0200 (CEST) From: Pierre-Marie de Rodat To: gdb-patches@sourceware.org Cc: Pierre-Marie de Rodat Subject: [PATCH] gdb/gdbtypes: fix handling of typedef layers between array types Date: Thu, 23 Jul 2015 13:47:22 +0200 Message-Id: <1437652042-8237-1-git-send-email-derodat@adacore.com> X-IsSubscribed: yes When a dynamic array type contains a typedef-wrapped array, an assertion failure occurs during type resolution. This is what happens in the following Ada case: type Rec_Type is record I : Integer; B : Boolean; end record; type Vec_Type is array (1 .. 4) of Rec_Type; type Array_Type is array (Positive range <>) of Vec_Type; If users try to print or even pass to an inferior call a variable A of type Array_Type, GDB will raise an error: (gdb) print a ../../src/gdb/gdbtypes.c:1807: internal-error: resolve_dynamic_array: Assertion `TYPE_CODE (type) == TYPE_CODE_ARRAY' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) What happens is that during dynamic array type resolution, we first peel TYPE_CODE_TYPEDEF layers wrapping the array element type and check if its type is itself TYPE_CODE_ARRAY. If it is, we pass the typedef-wrapped type to a recursive call to resolve_dynamic_array whereas this function expects only TYPE_CODE_ARRAY types. This patch makes it pass the peeled type to the recursive call so that type resolution can continue smoothly. gdb/ChangeLog: * gdbtypes.c (resolve_dynamic_array): Pass the peeled element type to the recursive call instead of the original (maybe TYPE_CODE_TYPEDEF) type. gdb/testsuite/ChangeLog: * gdb.ada/var_arr_typedef.exp: New testcase. * gdb.ada/var_arr_typedef/pack.adb: New file. * gdb.ada/var_arr_typedef/pack.ads: New file. * gdb.ada/var_arr_typedef/var_arr_typedef.adb: New file. --- gdb/gdbtypes.c | 2 +- gdb/testsuite/gdb.ada/var_arr_typedef.exp | 44 ++++++++++++++++++++++ gdb/testsuite/gdb.ada/var_arr_typedef/pack.adb | 23 +++++++++++ gdb/testsuite/gdb.ada/var_arr_typedef/pack.ads | 27 +++++++++++++ .../gdb.ada/var_arr_typedef/var_arr_typedef.adb | 26 +++++++++++++ 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.ada/var_arr_typedef.exp create mode 100644 gdb/testsuite/gdb.ada/var_arr_typedef/pack.adb create mode 100644 gdb/testsuite/gdb.ada/var_arr_typedef/pack.ads create mode 100644 gdb/testsuite/gdb.ada/var_arr_typedef/var_arr_typedef.adb diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index e44fd4f..3f1f3fb 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1933,7 +1933,7 @@ resolve_dynamic_array (struct type *type, ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type)); if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY) - elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type), addr_stack); + elt_type = resolve_dynamic_array (ary_dim, addr_stack); else elt_type = TYPE_TARGET_TYPE (type); diff --git a/gdb/testsuite/gdb.ada/var_arr_typedef.exp b/gdb/testsuite/gdb.ada/var_arr_typedef.exp new file mode 100644 index 0000000..b691478 --- /dev/null +++ b/gdb/testsuite/gdb.ada/var_arr_typedef.exp @@ -0,0 +1,44 @@ +# Copyright 2015 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 var_arr_typedef + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "BREAK" ${testdir}/var_arr_typedef.adb] +runto "var_arr_typedef.adb:$bp_location" + +set ra "\\(i => 3, b => false\\)" +set rb "\\(i => 2, b => true\\)" + +set va "\\($ra, $ra, $rb, $rb\\)" +set vb "\\($rb, $rb, $ra, $ra\\)" + +set a "\\($va, $va, $vb, $vb\\)" + +gdb_test "print va" \ + " = $va" + +gdb_test "print vb" \ + " = $vb" + +gdb_test "print a" \ + " = $a" diff --git a/gdb/testsuite/gdb.ada/var_arr_typedef/pack.adb b/gdb/testsuite/gdb.ada/var_arr_typedef/pack.adb new file mode 100644 index 0000000..82f034b --- /dev/null +++ b/gdb/testsuite/gdb.ada/var_arr_typedef/pack.adb @@ -0,0 +1,23 @@ +-- 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 Pack is + + function Identity (I : Integer) return Integer is + begin + return I; + end Identity; + + procedure Do_Nothing (A : Array_Type) is null; + +end Pack; diff --git a/gdb/testsuite/gdb.ada/var_arr_typedef/pack.ads b/gdb/testsuite/gdb.ada/var_arr_typedef/pack.ads new file mode 100644 index 0000000..7cf7ae5 --- /dev/null +++ b/gdb/testsuite/gdb.ada/var_arr_typedef/pack.ads @@ -0,0 +1,27 @@ +-- 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 Pack is + type Rec_Type is record + I : Integer; + B : Boolean; + end record; + + type Vec_Type is array (1 .. 4) of Rec_Type; + + type Array_Type is array (Positive range <>) of Vec_Type; + + procedure Do_Nothing (A : Array_Type); + function Identity (I : Integer) return Integer; + +end Pack; diff --git a/gdb/testsuite/gdb.ada/var_arr_typedef/var_arr_typedef.adb b/gdb/testsuite/gdb.ada/var_arr_typedef/var_arr_typedef.adb new file mode 100644 index 0000000..796116b --- /dev/null +++ b/gdb/testsuite/gdb.ada/var_arr_typedef/var_arr_typedef.adb @@ -0,0 +1,26 @@ +-- 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 Pack; use Pack; + +procedure Var_Arr_Typedef is + RA : constant Rec_Type := (3, False); + RB : constant Rec_Type := (2, True); + + VA : constant Vec_Type := (RA, RA, RB, RB); + VB : constant Vec_Type := (RB, RB, RA, RA); + + A : constant Array_Type (1 .. Identity (4)) := (VA, VA, VB, VB); +begin + Do_Nothing (A); -- BREAK +end Var_Arr_Typedef;