From patchwork Mon Dec 21 15:15:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 10094 Received: (qmail 100798 invoked by alias); 21 Dec 2015 15:15:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 100772 invoked by uid 89); 21 Dec 2015 15:15:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=listening, 689, callback, 687 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 21 Dec 2015 15:15:30 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 134BA11668D; Mon, 21 Dec 2015 10:15:29 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id F2TwbxGyuwKs; Mon, 21 Dec 2015 10:15:29 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id A17711165D8; Mon, 21 Dec 2015 10:15:28 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 9D6BC46BAD; Mon, 21 Dec 2015 19:15:24 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [RFA] gdbserver crash in gdb/gdbserver/thread.c::thread_search_callback Date: Mon, 21 Dec 2015 19:15:22 +0400 Message-Id: <1450710922-29601-1-git-send-email-brobecker@adacore.com> 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) We saw this crash on LynxOS and also when using GDBserver on Windows. 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. Does the fix look good to you? Tested on both Windows (native gdbserver) and LynxOS using AdaCore's gdb-testsuite. Thanks, 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)