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 13:54:00 -0000 [thread overview]
Message-ID: <04a5c127-f307-9202-4a5a-b4a9ef837589@redhat.com> (raw)
In-Reply-To: <bab7bcf4-357e-61ba-2787-e1d599c5340a@redhat.com>
On 07/13/2017 02:51 PM, Pedro Alves wrote:
> On 07/13/2017 12:09 PM, Pedro Alves wrote:
>
>> 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.
>
> This worked nicely, see below.
>
> I'll tweak the docs, and send an updated patch.
>
Err, now with patch.
From 3bdd3f159fa7b3a24f31f779da28e3d699447d1d Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 13 Jul 2017 11:20:43 +0100
Subject: [PATCH] assume prototyped
---
gdb/infcall.c | 15 +++++++++++++++
gdb/testsuite/gdb.base/nodebug.c | 39 ++++++++++++++++++++++++++++++++++++++
gdb/testsuite/gdb.base/nodebug.exp | 25 ++++++++++++++++++++++++
3 files changed, 79 insertions(+)
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 9593875..b09dc8f 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -981,6 +981,21 @@ call_function_by_hand_dummy (struct value *function,
prototyped. Can we respect TYPE_VARARGS? Probably not. */
if (TYPE_CODE (ftype) == TYPE_CODE_METHOD)
prototyped = 1;
+ if (TYPE_TARGET_TYPE (ftype) == NULL && TYPE_NFIELDS (ftype) == 0
+ && default_return_type != NULL)
+ {
+ /* Calling a no-debug function with the return type
+ explicitly cast. Assume the function is prototyped,
+ with a prototype matching the types of the arguments.
+ E.g., with:
+ float mult (float v1, float v2) { return v1 * v2; }
+ This:
+ (gdb) p (float) mult (2.0f, 3.0f)
+ Is a simpler alternative to:
+ (gdb) p ((float (*) (float, float)) mult) (2.0f, 3.0f)
+ */
+ prototyped = 1;
+ }
else if (i < TYPE_NFIELDS (ftype))
prototyped = TYPE_PROTOTYPED (ftype);
else
diff --git a/gdb/testsuite/gdb.base/nodebug.c b/gdb/testsuite/gdb.base/nodebug.c
index 5cb763b..29cd3f7 100644
--- a/gdb/testsuite/gdb.base/nodebug.c
+++ b/gdb/testsuite/gdb.base/nodebug.c
@@ -15,6 +15,45 @@ uint32_t dataglobal32_2 = 0x000000ff;
uint64_t dataglobal64_1 = 0x7fffffffffffffff;
uint64_t dataglobal64_2 = 0x00000000000000ff;
+float
+multf (float v1, float v2)
+{
+ return v1 * v2;
+}
+
+float
+multf_noproto (v1, v2)
+ float v1, v2;
+{
+ return v1 * v2;
+}
+
+double
+mult (double v1, double v2)
+{
+ return v1 * v2;
+}
+
+double
+mult_noproto (v1, v2)
+ double v1, v2;
+{
+ return v1 * v2;
+}
+
+uint8_t
+add8 (uint8_t v1, uint8_t v2)
+{
+ return v1 + v2;
+}
+
+uint8_t
+add8_noproto (v1, v2)
+ uint8_t v1, v2;
+{
+ return v1 + v2;
+}
+
int
inner (int x)
{
diff --git a/gdb/testsuite/gdb.base/nodebug.exp b/gdb/testsuite/gdb.base/nodebug.exp
index c6e78e2..858d9d9 100644
--- a/gdb/testsuite/gdb.base/nodebug.exp
+++ b/gdb/testsuite/gdb.base/nodebug.exp
@@ -210,6 +210,31 @@ if [runto inner] then {
gdb_test "ptype bsslocal" $data_var_type
+ # Call prototyped function with float parameters via both
+ # return-type cast and function-pointer cast. This checks that
+ # GDB doesn't do float->double coercion.
+ gdb_test "p (float) multf (2.0f, 3.0f)" " = 6"
+ gdb_test "p ((float (*) (float, float)) multf) (2, 3)" " = 6"
+ gdb_test "p ((float (*) (float, float)) multf) (2.0f, 3.0f)" " = 6"
+
+ # Call unprototyped function with float parameters via
+ # function-pointer cast, only. return-type cast assumes
+ # protototyped. Check that GDB does float->double coercion.
+ gdb_test "p ((float (*) ()) multf_noproto) (2.0f, 3.0f)" " = 6"
+ gdb_test "p ((float (*) ()) multf_noproto) (2.0, 3.0)" " = 6"
+
+ # Same, but for double.
+ gdb_test "p (double) mult (2.0, 3.0)" " = 6"
+ gdb_test "p ((double (*) (double, double)) mult) (2.0f, 3.0f)" " = 6"
+ gdb_test "p ((double (*) (double, double)) mult) (2, 3)" " = 6"
+ gdb_test "p ((double (*) ()) mult_noproto) (2.0f, 3.0f)" " = 6"
+ gdb_test "p ((double (*) ()) mult_noproto) (2.0, 3.0)" " = 6"
+
+ # Check that GDB promotes char->int correctly.
+ gdb_test "p /d (uint8) add8 ((uint8) 2, (uint8) 3)" " = 5"
+ gdb_test "p /d ((uint8 (*) (uint8, uint8)) add8) (2, 3)" " = 5"
+ gdb_test "p /d ((uint8 (*) ()) add8_noproto) (2, 3)" " = 5"
+
gdb_test "backtrace 10" "#0.*inner.*#1.*middle.*#2.*top.*#3.*main.*" \
"backtrace from inner in nodebug.exp"
# Or if that doesn't work, at least hope for the external symbols
--
2.5.5
next prev parent reply other threads:[~2017-07-13 13:54 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 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:19 ` [PATCH 02/13] Introduce OP_VAR_MSYM_VALUE Pedro Alves
2017-07-13 2:19 ` [PATCH 04/13] evaluate_subexp_standard: Eliminate one goto 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:27 ` [PATCH 06/13] evaluate_subexp_standard: Factor out OP_VAR_VALUE handling 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:28 ` [PATCH 05/13] evaluate_subexp_standard: Remove useless assignments Pedro Alves
2017-07-13 2:28 ` [PATCH 12/13] Document "no debug info debugging" improvements Pedro Alves
2017-07-13 11:09 ` [PATCH 13/13] " Pedro Alves
2017-07-13 13:51 ` Pedro Alves
2017-07-13 13:54 ` Pedro Alves [this message]
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 11/13] Make "p S::method() const::static_var" work too Pedro Alves
2017-07-13 2:29 ` [PATCH 12/13] Fix calling prototyped functions via function pointers Pedro Alves
2017-07-13 2:29 ` [PATCH 10/13] Handle "p 'S::method()::static_var'" (quoted) in symbol lookup 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=04a5c127-f307-9202-4a5a-b4a9ef837589@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