This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] gdbserver crash in gdb/gdbserver/thread.c::thread_search_callback
- From: Joel Brobecker <brobecke at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 22 Dec 2015 15:26:56 -0000
- Subject: [binutils-gdb] gdbserver crash in gdb/gdbserver/thread.c::thread_search_callback
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0e50fe5ca6ed2ce780cbbfa516aec20b023433ce
commit 0e50fe5ca6ed2ce780cbbfa516aec20b023433ce
Author: Joel Brobecker <brobecker@adacore.com>
Date: Sun Dec 20 00:49:59 2015 -0500
gdbserver crash in gdb/gdbserver/thread.c::thread_search_callback
Connecting GDB to a LynxOS-178 GDBserver causes GDBserver to crash:
% gdbserver :4444 simple_main
Process simple_main created; pid = 19
Listening on port 4444
Remote debugging from host 205.232.38.10
Segmentation fault (core dumped)
The crash happens in thread_search_callback where the function
calls the_target->thread_stopped (via the thread_stopped macro)
without verifying whether the callback is NULL or not.
For the record, the regression was introduced by:
commit a67a9faef0e32886c83611cc7a0ba61e91123063
Date: Mon Nov 30 16:05:26 2015 +0000
Subject: gdbserver:prepare_access_memory: pick another thread
This patch avoids the crash by checking the value of the callback
first, before calling it.
gdb/gdbserver/ChangeLog:
* target.c (thread_search_callback): Add check that
the thread_stopped target callback is not NULL before
calling it.
Diff:
---
gdb/gdbserver/ChangeLog | 6 ++++++
gdb/gdbserver/target.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 1d240f2..a80a088 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-22 Joel Brobecker <brobecker@adacore.com>
+
+ * target.c (thread_search_callback): Add check that
+ the thread_stopped target callback is not NULL before
+ calling it.
+
2015-12-21 Yao Qi <yao.qi@linaro.org>
* linux-aarch32-low.h [__aarch64__]: Use arm_abi_breakpoint
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index b376ce8..59736e5 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -68,7 +68,9 @@ thread_search_callback (struct inferior_list_entry *entry, void *args)
if (ptid_get_pid (entry->id) == ptid_get_pid (s->current_gen_ptid)
&& mythread_alive (ptid_of (thread)))
{
- if (s->stopped == NULL && thread_stopped (thread))
+ if (s->stopped == NULL
+ && the_target->thread_stopped != NULL
+ && thread_stopped (thread))
s->stopped = thread;
if (s->first == NULL)