From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71170 invoked by alias); 29 Jan 2018 18:06:35 -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 71161 invoked by uid 89); 29 Jan 2018 18:06:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS,TRACKER_ID,T_RP_MATCHES_RCVD autolearn=no 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 ESMTP; Mon, 29 Jan 2018 18:06:34 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C18112579C; Mon, 29 Jan 2018 18:06:32 +0000 (UTC) Received: from localhost (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 885255EDE0; Mon, 29 Jan 2018 18:06:32 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: Simon Marchi , gdb-patches@sourceware.org, Simon Marchi Subject: Re: [Regression] Segfault on native-extended-gdbserver + fork References: <20180119161628.21611-1-simon.marchi@polymtl.ca> <20180119161628.21611-3-simon.marchi@polymtl.ca> <87efmaebo3.fsf_-_@redhat.com> <931f8b594f7405649778f66ab2960a40@polymtl.ca> <669ec8c3-caa3-6901-b26c-00a7e20bc0d1@redhat.com> <1b82573ce66790c935eaff87b7565907@polymtl.ca> <87mv0w8tnr.fsf@redhat.com> <87372o8t45.fsf@redhat.com> Date: Mon, 29 Jan 2018 18:06:00 -0000 In-Reply-To: (Pedro Alves's message of "Mon, 29 Jan 2018 17:47:33 +0000") Message-ID: <87y3kg7d5k.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg00612.txt.bz2 On Monday, January 29 2018, Pedro Alves wrote: > On 01/29/2018 05:36 PM, Sergio Durigan Junior wrote: >> From 4a37d08ca6c1aec7f47e2278b0fe78a0038eb9ee Mon Sep 17 00:00:00 2001 >> From: Sergio Durigan Junior >> Date: Mon, 29 Jan 2018 12:29:21 -0500 >> Subject: [PATCH] Don't call "detach_inferior" on "remote_follow_fork" >> >> This patch fixes a regression that has been introduced by: >> >> commit bc09b0c14fb713a9aec25e09b78499f3bc2441b5 >> Date: Fri Jan 19 11:48:11 2018 -0500 >> >> Make linux_nat_detach/thread_db_detach use the inferior parameter >> >> Consider the following example program: >> >> #include >> >> int >> main (int argc, char *argv[]) >> { >> fork (); >> >> return 0; >> } >> > > Please also mention gdb.base/foll-fork.exp. Done. >> When running it under gdbserver: >> >> # ./gdb/gdbserver/gdbserver --multi --once :2345 >> >> And debugging it under GDB, we see a segmentation fault: >> >> # ./gdb/gdb -q -batch -ex 'set remote exec-file ./a.out' -ex 'tar extended-remote :2345' -ex r ./a.out >> Starting program: >> ... >> [Detaching after fork from child process 16102.] >> Segmentation fault (core dumped) >> >> The problem happens on inferior.c:detach_inferior: >> >> void >> detach_inferior (inferior *inf) >> { >> /* Save the pid, since exit_inferior_1 will reset it. */ >> int pid = inf->pid; >> ^^^^^^^^^ >> >> exit_inferior_1 (inf, 0); >> >> if (print_inferior_events) >> printf_unfiltered (_("[Inferior %d detached]\n"), pid); >> } >> >> When this code is called from remote.c:remote_follow_fork, the PID is >> valid but there is not 'inferior' associated with it, which means that >> 'inf == NULL'. > > s/there is not/there is no/ Fixed. >> >> The proper fix here is to not call "detach_inferior" when doing remote >> follow-fork, because we don't have an inferior to detach on the host >> side. > > Add something like this here: > > Before bc09b0c1, that call was already a nop (exit_inferior_1 bails > out early if you pass it a NULL inferior), except that it printed > "Inferior PID detached" when "set print inferior-events" is on. > Since native debugging doesn't call detach_inferior in this case, > removing the call from remote aligns remote debugging output > with native debugging output further. Added. > and it's good to me. Pushed. 69ab5edb4d601611ba7b4d05e56689d4b60ca3b1 Thanks, -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/