From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98047 invoked by alias); 13 Jul 2017 11:09: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 97682 invoked by uid 89); 13 Jul 2017 11:09:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=BAYES_00,LOTS_OF_MONEY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:2682 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 11:09:38 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A73480463 for ; Thu, 13 Jul 2017 11:09:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5A73480463 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5A73480463 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1338600CD; Thu, 13 Jul 2017 11:09:36 +0000 (UTC) Subject: Re: [PATCH 13/13] Document "no debug info debugging" improvements To: Pedro Alves , GDB Patches References: <1499912370-1842-1-git-send-email-palves@redhat.com> <1499912370-1842-14-git-send-email-palves@redhat.com> From: Pedro Alves Message-ID: Date: Thu, 13 Jul 2017 11:09:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1499912370-1842-14-git-send-email-palves@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-07/txt/msg00128.txt.bz2 On 07/13/2017 03:19 AM, Pedro Alves wrote: > +Sometimes, a function you wish to call is missing debug information. > +In such case, @value{GDBN} does not know the type of the function, > +including the types of the function's parameters. To avoid calling > +the inferior function incorrectly, which could result in the called > +function functioning erroneously and even crash, @value{GDBN} refuses > +to call the function unless you tell it at least the return type of > +the function, with a cast. For example: > + > +@smallexample > + (@value{GDBP}) p getenv ("PATH") > + 'getenv' has unknown return type; cast the call to its declared return type > + (@value{GDBP}) p (char *) getenv ("PATH") > + $1 = 0x7fffffffe7ba "/usr/local/bin:/"... > +@end smallexample > + > +Casting the return type of the function is equivalent to casting the > +function to a pointer to an unprototyped function, and calling that: > + > +@smallexample > + (@value{GDBP}) p ((char * (*) ()) getenv) ("PATH") > + $2 = 0x7fffffffe7ba "/usr/local/bin:/"... > +@end smallexample I woke up thinking that mapping to unprototyped is the wrong equivalence -- that it'd be better to assume the function is prototyped, since that's how most C functions are written as nowadays. Also, there's no such thing as an unprototyped function in C++. Assuming prototyped would allow this, for example: float mult (float v1, float v2) { return v1 * v2; } (gdb) p (float) mult (2.0f, 3.0f) $1 = 6 (gdb) p (float) mult ((float) 2, (float) 3) $2 = 6 (gdb) p ((float (*) (float, float)) mult) (2, 3) $3 = 6 (gdb) ptype 2.0f type = float (gdb) ptype 2.0 type = double If the function really is unprototyped, then you'd still be able to call it correctly via the function pointer cast syntax: float mult_noproto (v1, v2) float v1, v2; { return v1 * v2; } (gdb) p ((float (*) ()) mult_noproto) (2.0f, 3.0f) $1 = 6 (gdb) p ((float (*) ()) mult_noproto) (2.0, 3.0) $2 = 6 (gdb) p ((float (*) ()) mult_noproto) ((float) 2, (float) 3) $3 = 6 I'll give this a try, and add those as tests to gdb.base/nodebug.exp. > + > +If the function you wish to call is declared as prototyped and has > +floating point parameters or integer parameters narrower than int, you > +may need to cast the function to a function pointer of the same type > +as the function and call that, to avoid @value{GDBN} coercing > +arguments to integer/double, as would be required if calling an > +unprototyped function. @xref{ABI, float promotion}. For example, > +given this prototyped (i.e.@: ANSI/ISO style) function: This paragraph will need adjustment. Thanks, Pedro Alves