From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75132 invoked by alias); 3 Apr 2015 12:45:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 75119 invoked by uid 89); 3 Apr 2015 12:45:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 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; Fri, 03 Apr 2015 12:45:38 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 14D6B2D4E2F2; Fri, 3 Apr 2015 14:45:33 +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 ctfN-qTbkF6N; Fri, 3 Apr 2015 14:45:33 +0200 (CEST) Received: from [10.10.1.112] (cacatoes.act-europe.fr [10.10.1.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id F418C2D4E2F0; Fri, 3 Apr 2015 14:45:32 +0200 (CEST) Message-ID: <551E8B6D.4070706@adacore.com> Date: Fri, 03 Apr 2015 12:45:00 -0000 From: Pierre-Marie de Rodat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: GDB Patches CC: Joel Brobecker Subject: [PATCH 1/2] Preserve typedef layer when getting struct element Content-Type: multipart/mixed; boundary="------------060401070607010903040605" X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00117.txt.bz2 This is a multi-part message in MIME format. --------------060401070607010903040605 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1764 On behalf of Joel: Consider the following declarations: type Int_Access is access Integer; type Record_Type is record IA : Int_Access; end record; R : Record_Type; Printing the type name of "R.IA" yields: (gdb) whatis r.ia type = access integer It should be: (gdb) whatis r.ia type = bar.int_access Looking at the debugging info, field "r.ia" is defined as a typedef which has the name of the field type: .uleb128 0x3 # (DIE (0x4e) DW_TAG_typedef) .long .LASF4 # DW_AT_name: "bar__int_access" .long 0x8b # DW_AT_type ... with the typedef's target type being an anonymous pointer type: .uleb128 0x7 # (DIE (0x8b) DW_TAG_pointer_type) .byte 0x8 # DW_AT_byte_size .long 0x91 # DW_AT_type What happens here is that a couple of function in ada-lang.c always start by stripping all typedef layers when handling struct fields, with the effect of making us lose the type name in this case. We did not understand this at the time the code was written, but typedefs should be stripped only when we know we do not need them. So this patch, adjust the code to avoid the stripping while handling the fields, and adds it back in the lone place which handles the result of processing and didn't know how to handle typedefs struct fields yet. gdb/ChangeLog: * ada-lang.c (ada_is_tagged_type): Add call to ada_check_typedef. (ada_lookup_struct_elt_type): Remove calls to ada_check_typedef. (template_to_static_fixed_type): Call ada_check_typedef only when necessary. gdb/testsuite/ChangeLog: * gdb.ada/rec_comp: New testcase. No regression on x86_64-linux. Ok to push? -- Pierre-Marie de Rodat --------------060401070607010903040605 Content-Type: text/x-diff; name="0001-Ada-Preserve-typedef-layer-when-getting-struct-eleme.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Ada-Preserve-typedef-layer-when-getting-struct-eleme.pa"; filename*1="tch" Content-length: 9203 >From 567d1e0adbc7179bec6795cbbfa19248058373b2 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Thu, 12 Feb 2015 14:39:14 +0400 Subject: [PATCH 1/2] [Ada] Preserve typedef layer when getting struct element Consider the following declarations: type Int_Access is access Integer; type Record_Type is record IA : Int_Access; end record; R : Record_Type; Printing the type name of "R.IA" yields: (gdb) whatis r.ia type = access integer It should be: (gdb) whatis r.ia type = bar.int_access Looking at the debugging info, field "r.ia" is defined as a typedef which has the name of the field type: .uleb128 0x3 # (DIE (0x4e) DW_TAG_typedef) .long .LASF4 # DW_AT_name: "bar__int_access" .long 0x8b # DW_AT_type ... with the typedef's target type being an anonymous pointer type: .uleb128 0x7 # (DIE (0x8b) DW_TAG_pointer_type) .byte 0x8 # DW_AT_byte_size .long 0x91 # DW_AT_type What happens here is that a couple of function in ada-lang.c always start by stripping all typedef layers when handling struct fields, with the effect of making us lose the type name in this case. We did not understand this at the time the code was written, but typedefs should be stripped only when we know we do not need them. So this patch, adjust the code to avoid the stripping while handling the fields, and adds it back in the lone place which handles the result of processing and didn't know how to handle typedefs struct fields yet. gdb/ChangeLog: * ada-lang.c (ada_is_tagged_type): Add call to ada_check_typedef. (ada_lookup_struct_elt_type): Remove calls to ada_check_typedef. (template_to_static_fixed_type): Call ada_check_typedef only when necessary. gdb/testsuite/ChangeLog: * gdb.ada/rec_comp: New testcase. --- gdb/ada-lang.c | 13 ++++++--- gdb/testsuite/gdb.ada/rec_comp.exp | 37 +++++++++++++++++++++++++ gdb/testsuite/gdb.ada/rec_comp/bar_o203_012.adb | 32 +++++++++++++++++++++ gdb/testsuite/gdb.ada/rec_comp/pck.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/rec_comp/pck.ads | 22 +++++++++++++++ 5 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/rec_comp.exp create mode 100644 gdb/testsuite/gdb.ada/rec_comp/bar_o203_012.adb create mode 100644 gdb/testsuite/gdb.ada/rec_comp/pck.adb create mode 100644 gdb/testsuite/gdb.ada/rec_comp/pck.ads diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 124e370..e147d5a 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6399,6 +6399,8 @@ ada_is_tagged_type (struct type *type, int refok) int ada_is_tag_type (struct type *type) { + type = ada_check_typedef (type); + if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR) return 0; else @@ -7322,7 +7324,7 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok, { if (dispp != NULL) *dispp += TYPE_FIELD_BITPOS (type, i) / 8; - return ada_check_typedef (TYPE_FIELD_TYPE (type, i)); + return TYPE_FIELD_TYPE (type, i); } else if (ada_is_wrapper_field (type, i)) @@ -7354,7 +7356,7 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok, disp = 0; if (v_field_name != NULL && field_name_match (v_field_name, name)) - t = ada_check_typedef (TYPE_FIELD_TYPE (field_type, j)); + t = TYPE_FIELD_TYPE (field_type, j); else t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j), @@ -8177,11 +8179,14 @@ template_to_static_fixed_type (struct type *type0) for (f = 0; f < nfields; f += 1) { - struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f)); + struct type *field_type = TYPE_FIELD_TYPE (type0, f); struct type *new_type; if (is_dynamic_field (type0, f)) - new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type)); + { + field_type = ada_check_typedef (field_type); + new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type)); + } else new_type = static_unwrap_type (field_type); if (type == type0 && new_type != field_type) diff --git a/gdb/testsuite/gdb.ada/rec_comp.exp b/gdb/testsuite/gdb.ada/rec_comp.exp new file mode 100644 index 0000000..c462643 --- /dev/null +++ b/gdb/testsuite/gdb.ada/rec_comp.exp @@ -0,0 +1,37 @@ +# 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 bar_o203_012 + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/bar_o203_012.adb] +if ![runto "bar_o203_012.adb:$bp_location" ] then { + perror "Couldn't run ${testfile}" + return +} + +gdb_test "whatis r.ia" " = bar_o203_012.int_access" + +gdb_test "ptype r" \ + " = record\r\n *ia: bar_o203_012\.int_access;\r\nend record" + +gdb_test "ptype r.ia" " = access <$decimal-byte integer>" diff --git a/gdb/testsuite/gdb.ada/rec_comp/bar_o203_012.adb b/gdb/testsuite/gdb.ada/rec_comp/bar_o203_012.adb new file mode 100644 index 0000000..9783f51 --- /dev/null +++ b/gdb/testsuite/gdb.ada/rec_comp/bar_o203_012.adb @@ -0,0 +1,32 @@ +-- 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 . + +with Pck; use Pck; + +procedure Bar_O203_012 is + type Int_Access is access Integer; + type Record_Type is record + IA : Int_Access; + end record; + + R : Record_Type; + IA : Int_Access; +begin + R.IA := new Integer'(3); -- STOP + IA := R.IA; + Do_Nothing (R'Address); + Do_Nothing (IA'Address); +end Bar_O203_012; + diff --git a/gdb/testsuite/gdb.ada/rec_comp/pck.adb b/gdb/testsuite/gdb.ada/rec_comp/pck.adb new file mode 100644 index 0000000..c0465af --- /dev/null +++ b/gdb/testsuite/gdb.ada/rec_comp/pck.adb @@ -0,0 +1,23 @@ +-- Copyright 2011-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 . + +package body Pck is + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/rec_comp/pck.ads b/gdb/testsuite/gdb.ada/rec_comp/pck.ads new file mode 100644 index 0000000..594847c --- /dev/null +++ b/gdb/testsuite/gdb.ada/rec_comp/pck.ads @@ -0,0 +1,22 @@ +-- Copyright 2011-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 . + +with System; + +package Pck is + + procedure Do_Nothing (A : System.Address); + +end Pck; -- 2.3.4 --------------060401070607010903040605--