From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12143 invoked by alias); 27 Nov 2006 23:10:00 -0000 Received: (qmail 12130 invoked by uid 22791); 27 Nov 2006 23:09:58 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Mon, 27 Nov 2006 23:09:52 +0000 Received: from drow by nevyn.them.org with local (Exim 4.63) (envelope-from ) id 1Gopbg-0005KH-W0; Mon, 27 Nov 2006 18:09:49 -0500 Date: Mon, 27 Nov 2006 23:10:00 -0000 From: Daniel Jacobowitz To: Gary Funck Cc: gdb@sourceware.org Subject: Re: how to support C type qualifiers applied to arrays? Message-ID: <20061127230948.GA19798@nevyn.them.org> Mail-Followup-To: Gary Funck , gdb@sourceware.org References: <200611272217.kARMHtw3023324@intrepid.intrepid.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200611272217.kARMHtw3023324@intrepid.intrepid.com> User-Agent: Mutt/1.5.13 (2006-08-11) X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-11/txt/msg00186.txt.bz2 On Mon, Nov 27, 2006 at 02:42:12PM -0800, Gary Funck wrote: > Q: Is GCC generating an inaccurate DWARF 2 representation > to describe a qualified array type, or is GDB not > interpreting the DWARF 2 information correctly? I will defer to experts on this but I believe GCC is incorrect. In C there is no such thing as a "qualified array type". The array has an element type (which can be c-v qualified) and a bound, and no qualifiers of its own. But you can say "int x[const 1]". You can't define variables of this type, but you can use them in function declarations. I believe it means roughly "int *const x" within the function; normally you can write: int f(int x[1]) { x[0] = 1; x++; return 0; } But this is invalid: int f(int x[const 1]) { x[0] = 1; x++; return 0; } So, by stuffing qualifiers on the outside, we lose the ability to present that. But GCC emits debug info for those as int f(int *) and int f(int * const) respectively, so it's irrelevant in practice. We can assume the qualifiers belonged to the element type in GDB. > We see that make_cv_type() is called to qualify 'base_type' as "const". > Make_cv_type() does this by setting a flag bit in the 'instance_flags' > field of base_type. In our example above, 'base_type' is an array type. My first recommendation would be to have make_cv_type create a new array type, with the qualified element type. However, doing this without being excessively wasteful might require care - you couldn't reuse main_type since the qualified array could not share main_type. But the waste is acceptably small. The alternative would be to have a function called to get the base type of an array which did appropriate qualification at that point. The easiest way to do it might be to make TYPE_TARGET_TYPE into an appropriate function. Better than auditing the 465 or so calls. The first is probably better. It should be done in gdbtypes.c, not in the DWARF reader specifically. I see that these are roughly the same two possibilities you offered :-) I would do it at a different level than expression evaluation, though, as you can see above, if I took the second option. -- Daniel Jacobowitz CodeSourcery