aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-08-05 10:43:48 -0600
committerTom Tromey <tromey@adacore.com>2022-08-22 12:03:41 -0600
commit6bab7e67d07896d4fad755d9c2127f914c5c6492 (patch)
tree42b50fc58c3f5354c8cac1c47d4a570b65115cb5
parentb3ea2010cd06d49dd4fbfaa64b055700f7869e34 (diff)
downloadgdb-6bab7e67d07896d4fad755d9c2127f914c5c6492.zip
gdb-6bab7e67d07896d4fad755d9c2127f914c5c6492.tar.gz
gdb-6bab7e67d07896d4fad755d9c2127f914c5c6492.tar.bz2
Avoid crash with Ravenscar tasks
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.
-rw-r--r--gdb/ravenscar-thread.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 1718c36..fd4bf45 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;
}