public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid crash with Ravenscar tasks
@ 2022-08-11 15:00 Tom Tromey
  2022-08-22 18:03 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-08-11 15:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

When using Ravenscar, gdb can crash if the user sets a breakpoint very
early in task startup.  This happens because gdb thinks the runtime is
initialized, but in practice the particular task isn't sufficiently
initialized.  This patch avoids the issue by turning an assertion into
an early return.

I tested this using the AdaCore internal test suite.  I don't know how
to test Ravenscar using the FSF test suite.
---
 gdb/ravenscar-thread.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 1718c367ff6..fd4bf453cac 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -302,10 +302,12 @@ ravenscar_thread_target::add_active_thread ()
   if (!runtime_initialized ())
     return nullptr;
 
-  /* Make sure we set m_base_ptid before calling active_task
-     as the latter relies on it.  */
+  /* It's possible for runtime_initialized to return true but for it
+     not to be fully initialized.  For example, this can happen for a
+     breakpoint placed at the task's beginning.  */
   ptid_t active_ptid = active_task (base_cpu);
-  gdb_assert (active_ptid != null_ptid);
+  if (active_ptid == null_ptid)
+    return nullptr;
 
   /* The running thread may not have been added to
      system.tasking.debug's list yet; so ravenscar_update_thread_list
@@ -437,7 +439,9 @@ ravenscar_thread_target::wait (ptid_t ptid,
     {
       m_base_ptid = event_ptid;
       this->update_thread_list ();
-      return this->add_active_thread ()->ptid;
+      thread_info *thr = this->add_active_thread ();
+      if (thr != nullptr)
+	return thr->ptid;
     }
   return event_ptid;
 }
-- 
2.34.1


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

* Re: [PATCH] Avoid crash with Ravenscar tasks
  2022-08-11 15:00 [PATCH] Avoid crash with Ravenscar tasks Tom Tromey
@ 2022-08-22 18:03 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-08-22 18:03 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> When using Ravenscar, gdb can crash if the user sets a breakpoint very
Tom> early in task startup.  This happens because gdb thinks the runtime is
Tom> initialized, but in practice the particular task isn't sufficiently
Tom> initialized.  This patch avoids the issue by turning an assertion into
Tom> an early return.

Tom> I tested this using the AdaCore internal test suite.  I don't know how
Tom> to test Ravenscar using the FSF test suite.

I'm checking this in.

Tom

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

end of thread, other threads:[~2022-08-22 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 15:00 [PATCH] Avoid crash with Ravenscar tasks Tom Tromey
2022-08-22 18:03 ` Tom Tromey

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).