Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command
@ 2015-09-30  4:43 Kevin Buettner
  2015-09-30 10:27 ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2015-09-30  4:43 UTC (permalink / raw)
  To: gdb-patches

Architectures which use RETURN_VALUE_STRUCT_CONVENTION will have a
NULL return value after executing a finish command.  See get_return_value()
in infcmd.c.

This patch avoids an eventual SIGSEV (caused by attempting to
derefrence a NULL pointer) by adding a suitable test to
finish_command_fsm_should_stop().

I encountered this problem while testing msp430:

(gdb) PASS: gdb.base/structs.exp: zed L<n> for finish; return 1 structs-tc
finish
Run till exit from #0  fun1 () at /ironwood1/sourceware-git/msp430-elf/../binutils-gdb/gdb/testsuite/gdb.base/structs.c:125
ERROR: Process no longer exists

gdb/ChangeLog:
    	* infcmd.c (finish_command_fsm_should_stop): Don't attempt to
    	record a NULL value.
---
 gdb/infcmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index c4d7d8b..6be95e4 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1788,7 +1788,7 @@ finish_command_fsm_should_stop (struct thread_fsm *self)
 	internal_error (__FILE__, __LINE__,
 			_("finish_command: function has no target type"));
 
-      if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
+      if (rv->value != NULL && TYPE_CODE (rv->type) != TYPE_CODE_VOID)
 	{
 	  struct value *func;
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command
  2015-09-30  4:43 [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command Kevin Buettner
@ 2015-09-30 10:27 ` Pedro Alves
  2015-09-30 12:17   ` Kevin Buettner
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2015-09-30 10:27 UTC (permalink / raw)
  To: Kevin Buettner, gdb-patches

On 09/30/2015 05:43 AM, Kevin Buettner wrote:
> Architectures which use RETURN_VALUE_STRUCT_CONVENTION will have a
> NULL return value after executing a finish command.  See get_return_value()
> in infcmd.c.
> 
> This patch avoids an eventual SIGSEV (caused by attempting to
> derefrence a NULL pointer) by adding a suitable test to
> finish_command_fsm_should_stop().
> 
> I encountered this problem while testing msp430:
> 
> (gdb) PASS: gdb.base/structs.exp: zed L<n> for finish; return 1 structs-tc
> finish
> Run till exit from #0  fun1 () at /ironwood1/sourceware-git/msp430-elf/../binutils-gdb/gdb/testsuite/gdb.base/structs.c:125
> ERROR: Process no longer exists
> 
> gdb/ChangeLog:
>     	* infcmd.c (finish_command_fsm_should_stop): Don't attempt to
>     	record a NULL value.
> ---
>  gdb/infcmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index c4d7d8b..6be95e4 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -1788,7 +1788,7 @@ finish_command_fsm_should_stop (struct thread_fsm *self)
>  	internal_error (__FILE__, __LINE__,
>  			_("finish_command: function has no target type"));
>  
> -      if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
> +      if (rv->value != NULL && TYPE_CODE (rv->type) != TYPE_CODE_VOID)
>  	{
>  	  struct value *func;

It's this else block that below sets rv->value in the first place:

      if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
	{
	  struct value *func;

	  func = read_var_value (f->function, NULL, get_current_frame ());
	  rv->value = get_return_value (func, rv->type);
	  rv->value_history_index = record_latest_value (rv->value);
	}

So seems like that patch would break !RETURN_VALUE_STRUCT_CONVENTION
targets?

I assume that it's record_latest_value that crashes?  Isn't the right
fix instead:

	  rv->value = get_return_value (func, rv->type);
-	  rv->value_history_index = record_latest_value (rv->value);
+          if (rv->value != NULL)
+  	    rv->value_history_index = record_latest_value (rv->value);

?

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command
  2015-09-30 10:27 ` Pedro Alves
@ 2015-09-30 12:17   ` Kevin Buettner
  2015-09-30 12:21     ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2015-09-30 12:17 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Wed, 30 Sep 2015 11:27:25 +0100
Pedro Alves <palves@redhat.com> wrote:

> On 09/30/2015 05:43 AM, Kevin Buettner wrote:
> > Architectures which use RETURN_VALUE_STRUCT_CONVENTION will have a
> > NULL return value after executing a finish command.  See get_return_value()
> > in infcmd.c.
> > 
> > This patch avoids an eventual SIGSEV (caused by attempting to
> > derefrence a NULL pointer) by adding a suitable test to
> > finish_command_fsm_should_stop().
> > 
> > I encountered this problem while testing msp430:
> > 
> > (gdb) PASS: gdb.base/structs.exp: zed L<n> for finish; return 1 structs-tc
> > finish
> > Run till exit from #0  fun1 () at /ironwood1/sourceware-git/msp430-elf/../binutils-gdb/gdb/testsuite/gdb.base/structs.c:125
> > ERROR: Process no longer exists
> > 
> > gdb/ChangeLog:
> >     	* infcmd.c (finish_command_fsm_should_stop): Don't attempt to
> >     	record a NULL value.
> > ---
> >  gdb/infcmd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> > index c4d7d8b..6be95e4 100644
> > --- a/gdb/infcmd.c
> > +++ b/gdb/infcmd.c
> > @@ -1788,7 +1788,7 @@ finish_command_fsm_should_stop (struct thread_fsm *self)
> >  	internal_error (__FILE__, __LINE__,
> >  			_("finish_command: function has no target type"));
> >  
> > -      if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
> > +      if (rv->value != NULL && TYPE_CODE (rv->type) != TYPE_CODE_VOID)
> >  	{
> >  	  struct value *func;
> 
> It's this else block that below sets rv->value in the first place:
> 
>       if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
> 	{
> 	  struct value *func;
> 
> 	  func = read_var_value (f->function, NULL, get_current_frame ());
> 	  rv->value = get_return_value (func, rv->type);
> 	  rv->value_history_index = record_latest_value (rv->value);
> 	}
> 
> So seems like that patch would break !RETURN_VALUE_STRUCT_CONVENTION
> targets?
> 
> I assume that it's record_latest_value that crashes?  Isn't the right
> fix instead:
> 
> 	  rv->value = get_return_value (func, rv->type);
> -	  rv->value_history_index = record_latest_value (rv->value);
> +          if (rv->value != NULL)
> +  	    rv->value_history_index = record_latest_value (rv->value);
> 

You're right.  (I honestly don't know what I was thinking.)

Please commit your patch instead.

Thanks,

Kevin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command
  2015-09-30 12:17   ` Kevin Buettner
@ 2015-09-30 12:21     ` Pedro Alves
  2015-09-30 13:02       ` Kevin Buettner
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2015-09-30 12:21 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On 09/30/2015 01:17 PM, Kevin Buettner wrote:
> On Wed, 30 Sep 2015 11:27:25 +0100
> Pedro Alves <palves@redhat.com> wrote:
> 
>> On 09/30/2015 05:43 AM, Kevin Buettner wrote:
>>> Architectures which use RETURN_VALUE_STRUCT_CONVENTION will have a
>>> NULL return value after executing a finish command.  See get_return_value()
>>> in infcmd.c.
>>>
>>> This patch avoids an eventual SIGSEV (caused by attempting to
>>> derefrence a NULL pointer) by adding a suitable test to
>>> finish_command_fsm_should_stop().
>>>
>>> I encountered this problem while testing msp430:
>>>
>>> (gdb) PASS: gdb.base/structs.exp: zed L<n> for finish; return 1 structs-tc
>>> finish
>>> Run till exit from #0  fun1 () at /ironwood1/sourceware-git/msp430-elf/../binutils-gdb/gdb/testsuite/gdb.base/structs.c:125
>>> ERROR: Process no longer exists
>>>
>>> gdb/ChangeLog:
>>>     	* infcmd.c (finish_command_fsm_should_stop): Don't attempt to
>>>     	record a NULL value.
>>> ---
>>>  gdb/infcmd.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
>>> index c4d7d8b..6be95e4 100644
>>> --- a/gdb/infcmd.c
>>> +++ b/gdb/infcmd.c
>>> @@ -1788,7 +1788,7 @@ finish_command_fsm_should_stop (struct thread_fsm *self)
>>>  	internal_error (__FILE__, __LINE__,
>>>  			_("finish_command: function has no target type"));
>>>  
>>> -      if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
>>> +      if (rv->value != NULL && TYPE_CODE (rv->type) != TYPE_CODE_VOID)
>>>  	{
>>>  	  struct value *func;
>>
>> It's this else block that below sets rv->value in the first place:
>>
>>       if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
>> 	{
>> 	  struct value *func;
>>
>> 	  func = read_var_value (f->function, NULL, get_current_frame ());
>> 	  rv->value = get_return_value (func, rv->type);
>> 	  rv->value_history_index = record_latest_value (rv->value);
>> 	}
>>
>> So seems like that patch would break !RETURN_VALUE_STRUCT_CONVENTION
>> targets?
>>
>> I assume that it's record_latest_value that crashes?  Isn't the right
>> fix instead:
>>
>> 	  rv->value = get_return_value (func, rv->type);
>> -	  rv->value_history_index = record_latest_value (rv->value);
>> +          if (rv->value != NULL)
>> +  	    rv->value_history_index = record_latest_value (rv->value);
>>
> 
> You're right.  (I honestly don't know what I was thinking.)
> 
> Please commit your patch instead.

I don't have a patch -- I wrote that hunk by hand
in the mail client.  :-)  Please fix up yours and push it.

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command
  2015-09-30 12:21     ` Pedro Alves
@ 2015-09-30 13:02       ` Kevin Buettner
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Buettner @ 2015-09-30 13:02 UTC (permalink / raw)
  To: gdb-patches

On Wed, 30 Sep 2015 13:21:34 +0100
Pedro Alves <palves@redhat.com> wrote:

> >> I assume that it's record_latest_value that crashes?  Isn't the right
> >> fix instead:
> >>
> >> 	  rv->value = get_return_value (func, rv->type);
> >> -	  rv->value_history_index = record_latest_value (rv->value);
> >> +          if (rv->value != NULL)
> >> +  	    rv->value_history_index = record_latest_value (rv->value);
> >>
> > 
> > You're right.  (I honestly don't know what I was thinking.)
> > 
> > Please commit your patch instead.
> 
> I don't have a patch -- I wrote that hunk by hand
> in the mail client.  :-)  Please fix up yours and push it.

Oh, okay.

It's pushed.

Kevin


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-30 13:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30  4:43 [PATCH] infcmd.c: Don't attempt to record a NULL value after a finish command Kevin Buettner
2015-09-30 10:27 ` Pedro Alves
2015-09-30 12:17   ` Kevin Buettner
2015-09-30 12:21     ` Pedro Alves
2015-09-30 13:02       ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox