From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9406 invoked by alias); 5 Jan 2010 08:27:08 -0000 Received: (qmail 9398 invoked by uid 22791); 5 Jan 2010 08:27:08 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jan 2010 08:27:03 +0000 Received: (qmail 10457 invoked from network); 5 Jan 2010 08:27:01 -0000 Received: from unknown (HELO wind.localnet) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 5 Jan 2010 08:27:01 -0000 From: Vladimir Prus To: "gdb-patches@sourceware.org" Subject: RFC: fix race in multiexec case Date: Tue, 05 Jan 2010 08:27:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-14-generic-pae; KDE/4.3.2; i686; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201001051126.58970.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-01/txt/msg00075.txt.bz2 While testing my MI multiexec support patches, I've got GDB to crash. What happened is that: - inferior 1 is run - MI switches to inferior 2, which is never run. inferior_ptid gets set to null_ptid - MI tries to run inferior 2 - GDB noticed gets an even in inferior 1 - handle_inferior_event calls get_current_regcache() - get_current_regcache() calls get_thread_regcache (inferior_ptid), and inferior_ptid is still null_ptid - get_thread_regcache indirectly calls linux_nat_thread_address_space, and it has a code like this: if (GET_LWP (ptid) == 0) { ... lwp = find_lwp_pid (ptid); pid = GET_PID (lwp->ptid); } However, find_lwp_pid returns NULL for null_ptid, and this code segfaults. I attach a minimal patch that appears to fix this, but I feel uneasy about it. Maybe, inferior_ptid should be reset much earlier? Thanks, Volodya diff --git a/gdb/infrun.c b/gdb/infrun.c index d8ca40d..300af62 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3232,7 +3232,8 @@ targets should add new threads to the thread list themselves in non-stop mode.") if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) { int thread_hop_needed = 0; - struct address_space *aspace = get_regcache_aspace (get_current_regcache ()); + struct address_space *aspace = + get_regcache_aspace (get_thread_regcache (ecs->ptid)); /* Check if a regular breakpoint has been hit before checking for a potential single step breakpoint. Otherwise, GDB will - Volodya