From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28859 invoked by alias); 3 Jan 2008 15:46:55 -0000 Received: (qmail 28844 invoked by uid 22791); 3 Jan 2008 15:46:54 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 03 Jan 2008 15:41:16 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id A49182A9663 for ; Thu, 3 Jan 2008 10:41:04 -0500 (EST) 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 bZQGsjtfMx5v for ; Thu, 3 Jan 2008 10:41:04 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 51D0E2A964F for ; Thu, 3 Jan 2008 10:41:03 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 05D95E7ACB; Thu, 3 Jan 2008 07:40:55 -0800 (PST) Date: Thu, 03 Jan 2008 15:46:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/DWARF] Set TYPE_FLAG_STUB for enum DIEs that are declarations only Message-ID: <20080103154055.GD582@adacore.com> References: <20080103153952.GC582@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="s/l3CgOIzMHHjg/5" Content-Disposition: inline In-Reply-To: <20080103153952.GC582@adacore.com> User-Agent: Mutt/1.4.2.2i 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 X-SW-Source: 2008-01/txt/msg00038.txt.bz2 --s/l3CgOIzMHHjg/5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2005 [resending with the patch, sorry...] Long explaination but small patch :-). For those who are not familiar with Ada, the declaration of types whose implementation must be opaque is done as follow: type My_Opaque type is private; And then the language expects that you provide the definition of that type in the private section of your package spec, like so: private type My_Opaque is (One, Two, Three); But there has been a small amendment to that which allows a developer to provide the actual definition not in the spec, but in the body. This is an approach that is not used very often, but still legitimate. These types are called "Taft Amendment Types" (TAT) because they were introduced by Tucker Taft, I believe. Unfortunately, we found out that this can cause trouble in the debugger. When compiling a unit that uses a TAT, the compiler does not look inside the package body, but only in the package spec. So it knows that we have an object of that type, but it doesn't know what that type is. As a result, it generates a bogus "stub" enumeration type and sets its AT_declaration attribute. The debugger missed that part, and so we ended up thinking that our object was a degenerated enum type, and printed its value accordingly: (gdb) p w.e.all $1 = 0 The expected output is: (gdb) p w.e.all $1 = (month => 8, year => 1974) The fix is to flag the type as a TYPE_FLAG_STUB, so that we will know to lookup the complete definition. 2008-01-03 Joel Brobecker * dwarf2read.c (read_enumeration_type): Flag type as stub if the given die is a declaration. I also wrote a small testcase that reproduces the issue: 2008-01-03 Joel Brobecker * gdb.ada/taft_type/pck.ads, gdb.ada/taft_type/pck.adb, gdb.ada/taft_type/p.adb: New files. * gdb.ada/taft_type.exp: New testcase. Tested on x86-linux. No regression. OK to apply? Thanks, -- Joel --s/l3CgOIzMHHjg/5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="taft.diff" Content-length: 372 Index: dwarf2read.c =================================================================== --- dwarf2read.c (revision 59) +++ dwarf2read.c (revision 60) @@ -4237,6 +4237,9 @@ read_enumeration_type (struct die_info * TYPE_LENGTH (type) = 0; } + if (die_is_declaration (die, cu)) + TYPE_FLAGS (type) |= TYPE_FLAG_STUB; + set_die_type (die, type, cu); } --s/l3CgOIzMHHjg/5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="taft-tc.diff" Content-length: 4959 Index: gdb.ada/taft_type.exp =================================================================== --- gdb.ada/taft_type.exp (revision 0) +++ gdb.ada/taft_type.exp (revision 61) @@ -0,0 +1,46 @@ +# Copyright 2008 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 . + +if $tracelevel then { + strace $tracelevel +} + +load_lib "ada.exp" + +set testdir "taft_type" +set testfile "${testdir}/p" +set srcfile ${srcdir}/${subdir}/${testfile}.adb +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/p.adb] +if ![runto "p.adb:$bp_location" ] then { + perror "Couldn't run ${testfile}" + return +} + +gdb_test "print w.e.all" \ + "\\(month => 8, year => 1974\\)" \ + "print w.e.all" + Index: gdb.ada/taft_type/pck.adb =================================================================== --- gdb.ada/taft_type/pck.adb (revision 0) +++ gdb.ada/taft_type/pck.adb (revision 61) @@ -0,0 +1,29 @@ +-- Copyright 2008 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 + + type Empty is record + Month : Integer; + Year : Integer; + end record; + + function Create return Wrap is + begin + return (E => new Empty'(Month => 8, Year => 1974)); + end Create; + +end Pck; Index: gdb.ada/taft_type/pck.ads =================================================================== --- gdb.ada/taft_type/pck.ads (revision 0) +++ gdb.ada/taft_type/pck.ads (revision 61) @@ -0,0 +1,31 @@ +-- Copyright 2008 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 + + type Wrap is private; + + function Create return Wrap; + +private + + type Empty; + type Empty_Access is access Empty; + + type Wrap is record + E : Empty_Access; + end record; + +end Pck; Index: gdb.ada/taft_type/p.adb =================================================================== --- gdb.ada/taft_type/p.adb (revision 0) +++ gdb.ada/taft_type/p.adb (revision 61) @@ -0,0 +1,23 @@ +-- Copyright 2008 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 P is + W : Wrap; +begin + W := Create; +end P; -- START + --s/l3CgOIzMHHjg/5--