From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18599 invoked by alias); 3 Jun 2016 15:16:28 -0000 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 Received: (qmail 18544 invoked by uid 89); 3 Jun 2016 15:16:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 03 Jun 2016 15:16:26 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 124CFA146B; Fri, 3 Jun 2016 15:16:25 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u53FGNIW012283; Fri, 3 Jun 2016 11:16:24 -0400 Subject: Re: [PATCH v2] Fix failure to detach if threads exit while detaching on linux To: Antoine Tremblay , gdb-patches@sourceware.org References: <1464965361-25399-1-git-send-email-antoine.tremblay@ericsson.com> From: Pedro Alves Message-ID: Date: Fri, 03 Jun 2016 15:16:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <1464965361-25399-1-git-send-email-antoine.tremblay@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-06/txt/msg00057.txt.bz2 On 06/03/2016 03:49 PM, Antoine Tremblay wrote: > @@ -1491,7 +1523,28 @@ linux_nat_detach (struct target_ops *ops, const char *args, int from_tty) > linux_fork_detach (args, from_tty); > } > else > - linux_ops->to_detach (ops, args, from_tty); > + { > + TRY > + { > + linux_ops->to_detach (ops, args, from_tty); > + } > + CATCH (ex, RETURN_MASK_ERROR) > + { > + if (!check_ptrace_stopped_lwp_gone (main_lwp)) > + { > + delete_lwp (main_lwp->ptid); Is deleting the right thing to do? I think we'll likely crash, the next time we try to do something (e.g., try to detach again). Seems like on the gdbserver side, the lwp isn't deleted in this case. > + throw_exception (ex); > + } > + /* Ignore the error since the thread is gone already. */ > + else > + { > + inferior_ptid = null_ptid; > + detach_inferior (pid); > + inf_child_maybe_unpush_target (ops); Please factor these three lines out of inf_ptrace_attach into a separate function, exported from inf-ptrace.h and called from both places. E.g.: extern void inf_ptrace_attach_success (struct target_ops *ops); > + } > + } > + } > + delete_lwp (main_lwp->ptid); > } > > +clean_restart ${testfile} > + > +if ![runto_main] { > + fail "Can't run to main to check for trace support" "to check for trace support" is stale. > + return -1 > +} > + > +gdb_breakpoint "_exit" > +gdb_continue_to_breakpoint "_exit" ".*_exit.*" > + > +# Since the gdbserver-native board ends remote debugging on detach, > +# we can't use gdb_test as this function intercepts the Ending remote > +# debugging message and tries to restart gdb. Eh, that looks like a bogus think for gdb_test_multiple to be doing. Seems like it's been there since "forever": commit 19fa4a0af34ff07f260fc75e903ab92d8ca03d33 Author: Mike Werner AuthorDate: Sun Feb 21 20:03:55 1993 +0000 * gdb/testsuite: Initial creation of gdb/testsuite. Migrated dejagnu testcases and support files for testing nm to gdb/testsuite from deja-gnu. These files were moved "as is" with no modifications. This migration is part of a major overhaul of dejagnu. The modifications to these testcases, etc., which will allow them to work with the new version of dejagnu will be made in a future update. I'd support just removing that bit. In any case, there's no need to avoid gdb_test/gdb_test_multiple. Any user-specified pattern overrides gdb_test_multiple's internal patterns. So you just need to intercept the "Ending remote debugging" message yourself. > However, it can't do that > +# as gdb_exit on this board will call monitor exit which will fail as > +# we're not remote debugging anymore after a detach in this case. > +send_gdb "detach\n" > +gdb_expect { set test "detach" gdb_test_multiple $test $test { -re "Detaching from .*, process $decimal\r\nEnding remote debugging\.\r\n$gdb_prompt $" { # This is what you get with "target remote". pass $test } -re "Detaching from .*, process $decimal\r\n$gdb_prompt $" { pass $test } } > + -re "Detaching from .*, process $decimal\r\nEnding remote debugging\." { Missing $gdb_prompt match. > + #Don't try to exit gdbserver see above comment. > + set gdbserver_reconnect_p 1 I don't understand this one. It shouldn't be needed. > + pass "detach non-extended" Please use the same test message for all branches: pass $test > + } > + -re "Detaching from .*, process $decimal\r\n$gdb_prompt $" { > + pass "detach" > + } > + -re ".*$gdb_prompt $" { > + fail "detach" > + } > + timeout { > + fail "detach timeout" FYI, this would have been the standard: > + fail "$test (timeout)" > + } > +} > Thanks, Pedro Alves