Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v4] infcall: Add support for integer literals as reference function paramters
Date: Mon, 2 Feb 2026 09:21:17 -0800	[thread overview]
Message-ID: <dfd40011-3ce9-40f8-90f0-7f3e29e7010c@redhat.com> (raw)
In-Reply-To: <87h5s5g7vt.fsf@redhat.com>

Hi,

Thank you for looking at my patch.

On 1/28/26 5:54 AM, Andrew Burgess wrote:
> Keith Seitz <keiths@redhat.com> writes:
> 
>> Changes in v4
>> - Allocate to stack instead of heap
> 
> I'm interested by this change.  Within value_arg_coerce, a few lines
> before your change, there's this comment:
> 
>    /* Force the value to the target if we will need its address.  At
>       this point, we could allocate arguments on the stack instead of
>       calling malloc if we knew that their addresses would not be
>       saved by the called function.  */
>    arg = value_coerce_to_target (arg);
> 
> I don't believe there's anything stopping the inferior function taking
> the address of the reference argument and storing it.  Could you explain
> this change a little more?

Hmm... I see where you're headed with this, and I had not thought
of this possibility. This would certainly provide a counter-
argument to a previous review suggesting stack allocation.

However, if we malloc memory to hold this integer during the
function call, is this also not free'd after the call returns?
That pretty much leaves us in the same dilemma.

[Pardon my ignorance; I am just learning this code for the (nearly)
first time.]

>> - Use value::force_lval to simply copying to inferior memory
>> - Add some addition tests
>>
>> Changes in v3
>> - Move logic to value_arg_coerce
>> - Add some attempt to limit copying to trivially copyable types
>> ---
>>   gdb/infcall.c                                |  26 +++-
>>   gdb/testsuite/gdb.cp/ref-params.cc           |  95 +++++++++++-
>>   gdb/testsuite/gdb.cp/ref-params.exp          | 146 +++++++++++++++++++
>>   gdb/testsuite/gdb.cp/rvalue-ref-overload.exp |   1 -
>>   4 files changed, 261 insertions(+), 7 deletions(-)
>>
>> diff --git a/gdb/infcall.c b/gdb/infcall.c
>> index dcbae679d07..c4e9605a665 100644
>> --- a/gdb/infcall.c
>> +++ b/gdb/infcall.c
>> @@ -63,6 +63,8 @@ static bool debug_infcall = false;
>>   #define INFCALL_SCOPED_DEBUG_START_END(fmt, ...) \
>>     scoped_debug_start_end (debug_infrun, "infcall", fmt, ##__VA_ARGS__)
>>   
>> +static CORE_ADDR reserve_stack_space (const type *values_type, CORE_ADDR &sp);
>> +
>>   /* Implement 'show debug infcall'.  */
>>   
>>   static void
>> @@ -246,7 +248,8 @@ show_unwind_on_timeout_p (struct ui_file *file, int from_tty,
>>   
>>   static struct value *
>>   value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
>> -		  struct type *param_type, int is_prototyped)
>> +		  struct type *param_type, int is_prototyped,
>> +		  CORE_ADDR *sp, struct thread_info *call_thread)
>>   {
>>     const struct builtin_type *builtin = builtin_type (gdbarch);
>>     struct type *arg_type = check_typedef (arg->type ());
>> @@ -276,10 +279,23 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
>>   	  return value_cast_pointers (type, arg, 0);
>>   
>>   	/* Cast the value to the reference's target type, and then
>> -	   convert it back to a reference.  This will issue an error
>> -	   if the value was not previously in memory - in some cases
>> -	   we should clearly be allowing this, but how?  */
>> +	   convert it back to a reference.  If the value is not already
>> +	   in memory (e.g., a literal), we need to allocate space in the
>> +	   inferior and copy it there.  */
>>   	new_value = value_cast (type->target_type (), arg);
>> +	if (new_value->lval () != lval_memory
>> +	    && language_pass_by_reference (new_value->type ())
>> +	    .trivially_copyable)
>> +	  {
>> +	    CORE_ADDR addr;
>> +
>> +	    gdb_assert (sp != nullptr);
> 
> Given reserve_stack_space expects a reference to a CORE_ADDR, I think
> I'd just make the argument to this function 'CORE_ADDR &sp', then this
> assert can be dropped.

I will make that change.

Thank you again for taking a look at this,
Keith


  parent reply	other threads:[~2026-02-02 17:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 15:48 [PATCH] " Keith Seitz
2025-10-17 14:49 ` Tom Tromey
2025-10-20 19:00   ` Keith Seitz
2025-10-20 19:36 ` [PATCH v2] " Keith Seitz
2025-10-21 20:19   ` Tom Tromey
2025-10-22 12:05     ` Andrew Burgess
2025-10-22 13:21       ` Tom Tromey
2026-01-22 19:05       ` Keith Seitz
2026-01-23 14:07         ` Aktemur, Tankut Baris
2026-01-27 18:43           ` Keith Seitz
2026-01-27 19:01 ` [PATCH v4] " Keith Seitz
2026-01-28  8:24   ` Aktemur, Tankut Baris
2026-01-28 13:54   ` Andrew Burgess
2026-02-02 17:05     ` Aktemur, Tankut Baris
2026-02-02 17:21     ` Keith Seitz [this message]
2026-01-30 20:59   ` Tom Tromey
2026-02-02 16:58     ` Keith Seitz
2026-02-02 17:22       ` Aktemur, Tankut Baris
2026-02-12 16:31       ` Tom Tromey
2026-03-12 14:14 ` [PATCH v5] infcall: Add support for integer literals as reference function parameters Keith Seitz
2026-03-12 16:23   ` Tom de Vries
2026-03-12 16:45     ` Keith Seitz
2026-03-12 17:12 ` [PATCH v6] " Keith Seitz
2026-03-17 14:10   ` Andrew Burgess
2026-03-17 18:11     ` Keith Seitz

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=dfd40011-3ce9-40f8-90f0-7f3e29e7010c@redhat.com \
    --to=keiths@redhat.com \
    --cc=aburgess@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