Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Pedro Alves <palves@redhat.com>,
	GDB Patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 13/13] Document "no debug info debugging" improvements
Date: Thu, 13 Jul 2017 11:09:00 -0000	[thread overview]
Message-ID: <d17cfebb-e0f1-ab0a-7878-a54c6edd734e@redhat.com> (raw)
In-Reply-To: <1499912370-1842-14-git-send-email-palves@redhat.com>

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


  reply	other threads:[~2017-07-13 11:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-13  2:19 [PATCH 00/13] No-debug-info debugging improvements Pedro Alves
2017-07-13  2:19 ` [PATCH 03/13] Make ptype/whatis print function name of functions with no debug info too Pedro Alves
2017-07-13  2:19 ` [PATCH 04/13] evaluate_subexp_standard: Eliminate one goto Pedro Alves
2017-07-13  2:19 ` [PATCH 02/13] Introduce OP_VAR_MSYM_VALUE Pedro Alves
2017-07-13  2:19 ` [PATCH 07/13] Stop assuming no-debug-info variables have type int Pedro Alves
2017-07-13  2:19 ` [PATCH 08/13] Eliminate UNOP_MEMVAL_TLS Pedro Alves
2017-07-13  2:19 ` [PATCH 01/13] Stop assuming no-debug-info functions return int Pedro Alves
2017-07-13  2:27 ` [PATCH 09/13] Handle "p S::method()::static_var" in the C++ parser Pedro Alves
2017-07-13  2:27 ` [PATCH 06/13] evaluate_subexp_standard: Factor out OP_VAR_VALUE handling Pedro Alves
2017-07-13  2:28 ` [PATCH 11/13] Make "p S::method() const::static_var" work too Pedro Alves
2017-07-13  2:28 ` [PATCH 12/13] Document "no debug info debugging" improvements Pedro Alves
2017-07-13 11:09   ` Pedro Alves [this message]
2017-07-13 13:51     ` [PATCH 13/13] " Pedro Alves
2017-07-13 13:54       ` Pedro Alves
2017-07-13 15:33         ` Pedro Alves
2017-07-13 15:47   ` [PATCH 12/13] " Eli Zaretskii
2017-07-13 16:14     ` Pedro Alves
2017-07-13  2:28 ` [PATCH 05/13] evaluate_subexp_standard: Remove useless assignments Pedro Alves
2017-07-13  2:29 ` [PATCH 10/13] Handle "p 'S::method()::static_var'" (quoted) in symbol lookup Pedro Alves
2017-07-13  2:29 ` [PATCH 12/13] Fix calling prototyped functions via function pointers Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d17cfebb-e0f1-ab0a-7878-a54c6edd734e@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox