public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
@ 2019-04-13  8:28 Philippe Waroquiers
  2019-04-19 11:04 ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Waroquiers @ 2019-04-13  8:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

This crash was detected when using GDB with the valgrind gdbserver.
To reproduce:

valgrind sleep 10000

In another window:
gdb
target remote | vgdb
p printf("make sleep print something\n")
=>
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
Aborted

The problem is that the valgrind gdbserver does not allow to change
registers when the inferior is blocked in a system call.
GDB then raises an exception.  The exception causes the destructor
of
 typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
    infcall_suspend_state_up;
to be called.  This destructor itself tries to restore the value of
the registers, and fails similarly.  We must catch the exception in
the destructor to avoid crashing GDB.
If the destructor encounters a problem, no warning is produced if
there is an uncaught exception, as in this case, the user will already
be informed of a problem via this exception.

With this change, no crash anymore, and all the valgrind 3.15 tests
pass succesfully.

Note: when this patch is approved, I will push an equivalent patch
on master, but with TRY/CATCH/e.message () replaced by
try/catch/e.what ().

gdb/ChangeLog

struct infcall_suspend_state_deleter
2019-04-13  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* inferior.h (struct infcall_suspend_state_deleter):
	Catch exception in destructor to avoid crash.
---
 gdb/inferior.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gdb/inferior.h b/gdb/inferior.h
index 2d1bb97a28..4d84afac6a 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -68,7 +68,19 @@ struct infcall_suspend_state_deleter
 {
   void operator() (struct infcall_suspend_state *state) const
   {
-    restore_infcall_suspend_state (state);
+    TRY
+      {
+	restore_infcall_suspend_state (state);
+      }
+    CATCH (e, RETURN_MASK_ALL)
+      {
+	/* If we are restoring the inferior state due to an exception,
+	   some error message will be printed.  So, only warn the user
+	   when we cannot restore during normal execution.  */
+	if (!std::uncaught_exception ())
+	  warning (_("Failed to restore inferior state: %s"), e.message);
+      }
+    END_CATCH
   }
 };
 
-- 
2.20.1

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

* Re: [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
  2019-04-13  8:28 [RFA] Fix GDB 8.3 regression crash when registers cannot be modified Philippe Waroquiers
@ 2019-04-19 11:04 ` Mark Wielaard
  2019-04-19 11:36   ` Philippe Waroquiers
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2019-04-19 11:04 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: gdb-patches, Pedro Alves, Sergio Durigan Junior

Hi,

On Sat, Apr 13, 2019 at 10:28:17AM +0200, Philippe Waroquiers wrote:
> This crash was detected when using GDB with the valgrind gdbserver.
> To reproduce:
> 
> valgrind sleep 10000
> 
> In another window:
> gdb
> target remote | vgdb
> p printf("make sleep print something\n")
> =>
> terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
> Aborted
> 
> The problem is that the valgrind gdbserver does not allow to change
> registers when the inferior is blocked in a system call.
> GDB then raises an exception.  The exception causes the destructor
> of
>  typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
>     infcall_suspend_state_up;
> to be called.  This destructor itself tries to restore the value of
> the registers, and fails similarly.  We must catch the exception in
> the destructor to avoid crashing GDB.
> If the destructor encounters a problem, no warning is produced if
> there is an uncaught exception, as in this case, the user will already
> be informed of a problem via this exception.
> 
> With this change, no crash anymore, and all the valgrind 3.15 tests
> pass succesfully.
> 
> Note: when this patch is approved, I will push an equivalent patch
> on master, but with TRY/CATCH/e.message () replaced by
> try/catch/e.what ().
> 
> gdb/ChangeLog
> 
> struct infcall_suspend_state_deleter
> 2019-04-13  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> 
> 	* inferior.h (struct infcall_suspend_state_deleter):
> 	Catch exception in destructor to avoid crash.

What is the current status of this patch?
We really need something like this to enable the valgrind gdbserver
integration testing again on Fedora 30/rawhide.

Thanks,

Mark

> ---
>  gdb/inferior.h | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index 2d1bb97a28..4d84afac6a 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -68,7 +68,19 @@ struct infcall_suspend_state_deleter
>  {
>    void operator() (struct infcall_suspend_state *state) const
>    {
> -    restore_infcall_suspend_state (state);
> +    TRY
> +      {
> +	restore_infcall_suspend_state (state);
> +      }
> +    CATCH (e, RETURN_MASK_ALL)
> +      {
> +	/* If we are restoring the inferior state due to an exception,
> +	   some error message will be printed.  So, only warn the user
> +	   when we cannot restore during normal execution.  */
> +	if (!std::uncaught_exception ())
> +	  warning (_("Failed to restore inferior state: %s"), e.message);
> +      }
> +    END_CATCH
>    }
>  };
>  
> -- 
> 2.20.1

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

* Re: [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
  2019-04-19 11:04 ` Mark Wielaard
@ 2019-04-19 11:36   ` Philippe Waroquiers
  2019-04-19 11:49     ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Waroquiers @ 2019-04-19 11:36 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gdb-patches, Pedro Alves, Sergio Durigan Junior

On Fri, 2019-04-19 at 13:03 +0200, Mark Wielaard wrote:
> > gdb/ChangeLog
> > 
> > struct infcall_suspend_state_deleter
> > 2019-04-13  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> > 
> > 	* inferior.h (struct infcall_suspend_state_deleter):
> > 	Catch exception in destructor to avoid crash.
> 
> What is the current status of this patch?
> We really need something like this to enable the valgrind gdbserver
> integration testing again on Fedora 30/rawhide.
This is still in state RFA, waiting for review.
Philippe

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

* Re: [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
  2019-04-19 11:36   ` Philippe Waroquiers
@ 2019-04-19 11:49     ` Pedro Alves
  2019-04-19 12:37       ` Philippe Waroquiers
  0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2019-04-19 11:49 UTC (permalink / raw)
  To: Philippe Waroquiers, Mark Wielaard; +Cc: gdb-patches, Sergio Durigan Junior

On 4/19/19 12:36 PM, Philippe Waroquiers wrote:
> On Fri, 2019-04-19 at 13:03 +0200, Mark Wielaard wrote:
>>> gdb/ChangeLog
>>>
>>> struct infcall_suspend_state_deleter
>>> 2019-04-13  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
>>>
>>> 	* inferior.h (struct infcall_suspend_state_deleter):
>>> 	Catch exception in destructor to avoid crash.
>>
>> What is the current status of this patch?
>> We really need something like this to enable the valgrind gdbserver
>> integration testing again on Fedora 30/rawhide.
> This is still in state RFA, waiting for review.

I had not realized you had posted this updated patch.

This version is OK.

Thanks,
Pedro Alves

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

* Re: [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
  2019-04-19 11:49     ` Pedro Alves
@ 2019-04-19 12:37       ` Philippe Waroquiers
  2019-04-22 17:13         ` Sergio Durigan Junior
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Waroquiers @ 2019-04-19 12:37 UTC (permalink / raw)
  To: Pedro Alves, Mark Wielaard; +Cc: gdb-patches, Sergio Durigan Junior

On Fri, 2019-04-19 at 12:48 +0100, Pedro Alves wrote:
> This version is OK.
Thanks for the review and the suggestion to use
std::uncaught_exception ().

Pushed to 8.3 branch.
Pushed an equivalent patch to master,
  with TRY/CATCH/e.message replaced by try/catch/e.what ().

Philippe


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

* Re: [RFA] Fix GDB 8.3 regression crash when registers cannot be modified.
  2019-04-19 12:37       ` Philippe Waroquiers
@ 2019-04-22 17:13         ` Sergio Durigan Junior
  0 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2019-04-22 17:13 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: Pedro Alves, Mark Wielaard, gdb-patches

On Friday, April 19 2019, Philippe Waroquiers wrote:

> On Fri, 2019-04-19 at 12:48 +0100, Pedro Alves wrote:
>> This version is OK.
> Thanks for the review and the suggestion to use
> std::uncaught_exception ().
>
> Pushed to 8.3 branch.
> Pushed an equivalent patch to master,
>   with TRY/CATCH/e.message replaced by try/catch/e.what ().

Today is a holiday here, but I'll rebase F30 GDB first thing tomorrow.
Thanks.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

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

end of thread, other threads:[~2019-04-22 17:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-13  8:28 [RFA] Fix GDB 8.3 regression crash when registers cannot be modified Philippe Waroquiers
2019-04-19 11:04 ` Mark Wielaard
2019-04-19 11:36   ` Philippe Waroquiers
2019-04-19 11:49     ` Pedro Alves
2019-04-19 12:37       ` Philippe Waroquiers
2019-04-22 17:13         ` Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).