From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103971 invoked by alias); 3 Jun 2016 15:32:26 -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 103962 invoked by uid 89); 3 Jun 2016 15:32:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy= X-HELO: usplmg21.ericsson.net Received: from usplmg21.ericsson.net (HELO usplmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 03 Jun 2016 15:32:24 +0000 Received: from EUSAAHC001.ericsson.se (Unknown_Domain [147.117.188.75]) by usplmg21.ericsson.net (Symantec Mail Security) with SMTP id D9.A3.03614.EC2A1575; Fri, 3 Jun 2016 17:31:27 +0200 (CEST) Received: from elxa4wqvvz1 (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.75) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 3 Jun 2016 11:32:21 -0400 References: <1464965361-25399-1-git-send-email-antoine.tremblay@ericsson.com> User-agent: mu4e 0.9.17; emacs 24.4.1 From: Antoine Tremblay To: Pedro Alves CC: Antoine Tremblay , Subject: Re: [PATCH v2] Fix failure to detach if threads exit while detaching on linux In-Reply-To: Date: Fri, 03 Jun 2016 15:32:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00059.txt.bz2 Pedro Alves writes: > 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. > Indeed, OK. >> + 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.: > OK. > extern void inf_ptrace_attach_success (struct target_ops *ops); > OK. (detach_success) >> + } >> + } >> + } >> + 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. > Oops thanks. >> + 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. > Right, I tested that before without sucess but had not the perfect regex yet... I'll use this now. thanks. >> 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. > OK. >> + #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. > This one is needed since on the teardown of the .exp test gdb_exit is called and calls monitor_exit which fails with a timeout this avoids this and the original gdb_exit is called. >> + 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)" > >> + } >> +} >> Noted, thx.