From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KGxQAlSzvV93eQAAWB0awg (envelope-from ) for ; Tue, 24 Nov 2020 20:28:52 -0500 Received: by simark.ca (Postfix, from userid 112) id 078EF1F0AB; Tue, 24 Nov 2020 20:28:52 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5FC301EFC1 for ; Tue, 24 Nov 2020 20:28:49 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2A4839540BF; Wed, 25 Nov 2020 01:28:48 +0000 (GMT) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by sourceware.org (Postfix) with ESMTPS id 146C03953C14 for ; Wed, 25 Nov 2020 01:28:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 146C03953C14 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wm1-f65.google.com with SMTP id a186so630135wme.1 for ; Tue, 24 Nov 2020 17:28:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kMQThipoNTZUI+gn8a/nQkHll8wBws3AbHEJ4U6Vk1g=; b=uSwMIxTiA4sSPK9iYx+J/ncGpbDLEsnFefvrmjbv9LeBjkspPalFfkjSlwf7Jol/Qt KPNP6t5GQV3M+OyZqJi3gbY2o4z6mym0klNw+c+4I7PuunjtssiAcmrqeXohncTGDw7S xyIj9w+jMkJwxzQQA+5K1Ee5Z4RdZNAkXqr7eEN1JVUBOa3QNX4d9dLaJ42xPQNuGgOb ZB8iNSZB0sUcMAeEE6dB4CjmEMGzFHIeb865XQ2hnkbLHlTzoYyJZ+jxTIUtANcfOcuq XUfG+KbBC35oyfEUKTzEq1pmui3KqpFYi9hoZA0FQFY1DaOAAFPS2l7J8QBqUynOhGT8 Jr+Q== X-Gm-Message-State: AOAM530RpCZxF2KOkfVVfViVfSBsRoPZNikzRQo7RmadElgvOzcx4Izs RzLxe/TRG2gZx+VJTQC5bwEJt7gtDIOl7w== X-Google-Smtp-Source: ABdhPJw/K7xdK23rAsiksULWb7Fp9BoZ++i7otR+ntusX4mEz2074OKBdNGFmPbnl6mOa1SW9tQK8Q== X-Received: by 2002:a05:600c:ce:: with SMTP id u14mr1139588wmm.150.1606267719504; Tue, 24 Nov 2020 17:28:39 -0800 (PST) Received: from ?IPv6:2001:8a0:f91f:e900:1d90:d745:3c32:c159? ([2001:8a0:f91f:e900:1d90:d745:3c32:c159]) by smtp.gmail.com with ESMTPSA id u81sm1299848wmb.27.2020.11.24.17.28.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Nov 2020 17:28:38 -0800 (PST) Subject: Re: [PATCH 02/12] gdb: clear inferior displaced stepping state on exec To: Simon Marchi , gdb-patches@sourceware.org References: <20201110214614.2842615-1-simon.marchi@efficios.com> <20201110214614.2842615-3-simon.marchi@efficios.com> From: Pedro Alves Message-ID: <43495e04-beb9-bf75-0bc1-efcce540fa57@palves.net> Date: Wed, 25 Nov 2020 01:28:37 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20201110214614.2842615-3-simon.marchi@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 11/10/20 9:46 PM, Simon Marchi via Gdb-patches wrote: > When a process does an exec, all its program space is replaced with the > newly loaded executable. All non-main threads disappear and the main > thread starts executing at the entry point of the new executable. > > Things can go wrong if a displaced step operation is in progress while > we process the exec event. > > If the main thread is the one executing the displaced step: when that > thread (now executing in the new executable) stops somewhere (say, at a > breakpoint), displaced_step_fixup will run and clear up the state. We > will execute the "fixup" phase for the instruction we single-stepped in > the old program space. We are now in a completely different context, > so doing the fixup may corrupt the state. > > If it is a non-main thread that is doing the displaced step: while > handling the exec event, GDB deletes the thread_info representing that > thread (since the thread doesn't exist in the inferior after the exec). > But inferior::displaced_step_state::step_thread will still point to it. > When handling events later, this condition, in displaced_step_fixup, > will likely never be true: > > /* Was this event for the thread we displaced? */ > if (displaced->step_thread != event_thread) > return 0; > > ... since displaced->step_thread points to a deleted thread (unless that > storage gets re-used for a new thread_info, but that wouldn't be good > either). This effectively makes the displaced stepping buffer occupied > for ever. When a thread in the new program space will want to do a > displaced step, it will wait for ever. > > I think we simply need to reset the displaced stepping state of the > inferior on exec. Everything execution-related that existed before the > exec is now gone. > > I tried to write a test where a non-main thread displaced-steps an exec > syscall, where things would hang due to the displaced step buffer not > getting released. However, due to PR 26754 [1], it is hard to make it > stable. So I'm not including a test for this patch. If you have an > idea for another way to test this without triggering this bug, I'd like > to hear it. > > [1] https://sourceware.org/bugzilla/show_bug.cgi?id=26754 I can't think of another way to test this. > > gdb/ChangeLog: > > * infrun.c (infrun_inferior_execd): New function. > (_initialize_infrun): Attach inferior_execd observer. OK.