From: Tom Tromey Date: Fri, 5 Aug 2022 16:43:48 +0000 (-0600) Subject: Avoid crash with Ravenscar tasks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6bab7e67d07896d4fad755d9c2127f914c5c6492;p=binutils-gdb.git 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. --- 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; }