[05/11] gdb, remote: fix crash when accessing removed events
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
From: "Bouhaouel, Mohamed" <mohamed.bouhaouel@intel.com>
Dereferencing events after calling std::remove_if causes GDB to crash
due to accessing invalidated iterators. Fix by logging events in
std::remove_if.
---
gdb/remote.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
@@ -8314,17 +8314,20 @@ remote_target::discard_pending_stop_replies (struct inferior *inf)
/* Discard the stop replies we have already pulled with
vStopped. */
- auto iter = std::remove_if (rs->stop_reply_queue.begin (),
- rs->stop_reply_queue.end (),
- [=] (const stop_reply_up &event)
- {
- return event->ptid.pid () == inf->pid;
- });
- for (auto it = iter; it != rs->stop_reply_queue.end (); ++it)
- remote_debug_printf
- ("discarding queued stop reply: ptid: %s, ws: %s\n",
- (*it)->ptid.to_string().c_str(),
- (*it)->ws.to_string ().c_str ());
+ auto iter
+ = std::remove_if (rs->stop_reply_queue.begin (),
+ rs->stop_reply_queue.end (),
+ [=] (const stop_reply_up &event)
+ {
+ if (event->ptid.pid () != inf->pid)
+ return false;
+
+ remote_debug_printf
+ ("discarding queued stop reply: ptid: %s, ws: %s\n",
+ event->ptid.to_string ().c_str (),
+ event->ws.to_string ().c_str ());
+ return true;
+ });
rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
}