From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32730 invoked by alias); 6 Feb 2002 21:43:53 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 32522 invoked from network); 6 Feb 2002 21:43:44 -0000 Received: from unknown (HELO mail-out2.apple.com) (17.254.0.51) by sources.redhat.com with SMTP; 6 Feb 2002 21:43:44 -0000 Received: from mailgate1.apple.com (A17-128-100-225.apple.com [17.128.100.225]) by mail-out2.apple.com (8.11.3/8.11.3) with ESMTP id g16Lhh712748 for ; Wed, 6 Feb 2002 13:43:43 -0800 (PST) Received: from scv1.apple.com (scv1.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id ; Wed, 6 Feb 2002 13:43:23 -0800 Received: from localhost (vpn-scv-x4-142.apple.com [17.219.194.142]) by scv1.apple.com (8.11.3/8.11.3) with ESMTP id g16LhgG24563; Wed, 6 Feb 2002 13:43:42 -0800 (PST) Date: Wed, 06 Feb 2002 13:43:00 -0000 Subject: Re: [RFA] Function return type checking Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v480) Cc: Klee Dienes , gdb-patches@sources.redhat.com To: Daniel Jacobowitz From: Klee Dienes In-Reply-To: <20020205110722.A24325@nevyn.them.org> Message-Id: <98590BF8-1B4A-11D6-812E-0030653FA4C6@apple.com> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.480) X-SW-Source: 2002-02/txt/msg00181.txt.bz2 On Tuesday, February 5, 2002, at 08:07 AM, Daniel Jacobowitz wrote: > Have you considered casting the function itself? Something like: > (gdb) print ((float (*)(float)) fabs) (3.0) > $1 = 3.0 > (gdb) set fabs > > Which, I will note, already works except for the fact that we neglect > the argument types on function pointers. Or > (gdb) set $fabs = (float (*)(float)) fabs > (gdb) p $fabs(4.0) > $2 = 4.0 We have; for a long time that was the answer we gave to people who were running into this problem. Our experience was that it was a nightmare to explain to people how this mechanism worked, and that even for folks who did undertand it, they found it a major mental burden to use in practice. C function casting syntax is neither intuitive nor pleasant to type. The reason we chose the "cast" syntax wasn't so much to be cute, but because it was the first thing everyone tried when they were trying to get this to work. People would try 'print (float) fabs (3.0)', followed by 'print {float} fabs (3.0)', usually followed by several unsuccessful attemtps to remember the correct syntax to cast the function pointer. I also think there's a pretty solid rationale behind the syntax, and one that generalizes to argument-passing. The theory goes: All symbols without debugging information are assumed to be of type 'unknown' (previously, they were assumed to be 'int', or (int (*) ())). When you cast an expression of type 'unknown' to anything else, GDB does no conversion, but simply interprets the data (or generates the data) according to the specified type. So if you have 'f' with no symbols, print (long long) f ((long long) 7, (float) 3.0) will generate a function call as if 'f' had been declared as long long f (long long, float) For function arguments, I claim this is both intuitive and matches the behavior of the C compiler. For function return values, wee have to choose something for what 'print (type) f ()' is to mean, and I claim that it's the best of the two alternatives (the other being "assume 'int', then cast the 'int' to the specified type).