From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48018 invoked by alias); 1 Oct 2018 17:12:02 -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 47967 invoked by uid 89); 1 Oct 2018 17:12:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=lastly X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.253) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 01 Oct 2018 17:11:58 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 44CB5AAF7 for ; Mon, 1 Oct 2018 12:11:57 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 71jJgvJBXRPoj71jXgF6Us; Mon, 01 Oct 2018 12:11:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7+Ex8fqHtdG2caQIIPy3Ou8JqY9ATtTT5Fohh0bjPLQ=; b=MvyNTK1ki4ioq5qlOCRRJKV8yk F1YlC2vk6AK0LCNFRCUG9YaV056qPuiSmzxTaq0WvVGJ+gkCW4p4MRJoSOEJA39MMQoQNeEuSR7Fd uJEZLKnTP4WSHor/MpmXYnmuE; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:38948 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g71jJ-001GaT-2R; Mon, 01 Oct 2018 12:11:33 -0500 From: Tom Tromey To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/3] Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. References: <20181001103252.5150-1-palves@redhat.com> <20181001103252.5150-4-palves@redhat.com> Date: Mon, 01 Oct 2018 17:12:00 -0000 In-Reply-To: <20181001103252.5150-4-palves@redhat.com> (Pedro Alves's message of "Mon, 1 Oct 2018 11:32:52 +0100") Message-ID: <878t3hlhh7.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2018-10/txt/msg00022.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> As preparation for multi-target, this patch makes each inferior have Pedro> its own thread list. This is great. Pedro> Lastly, the solution I settled with was to replace the ALL_THREADS / Pedro> ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges Pedro> and iterators, such that you can instead naturaly iterate over Pedro> threads/inferiors using range-for, like e.g,.: This is my preferred approach as well. I wouldn't mind if we got rid of all the iteration macros, and (by default) changed callback-based iteration to for-range with iterators. I like filtered_iterator and safe_iterator quite a bit. I think I had a use for them already but just didn't think to do it this way. Pedro> init_wait_for_inferior is currently responsible for discarding skipped Pedro> inline frames, which had to be moved elsewhere. Note that ASAN pointed out a use-after-free bug in clear_inline_frame_state. It can be called sometimes after the thread_info has been deleted, so: return pid == state.thread->inf->pid; ... references freed memory. I wonder if your patch fixes this. If not, maybe I have a patch on my asan branch (or maybe that was one of the ones I had to rewrite, I can't recall at the moment). Pedro> * inline-frame.c (clear_inline_frame_state(thread_info*)): New Pedro> overload. Pedro> * inline-frame.h (clear_inline_frame_state(thread_info*)): New Pedro> overload. I didn't see these in the patch. Pedro> +/* Filter for filtered_iterator. Filters out exited inferiors. */ Pedro> + Pedro> +struct exited_inferior_filter Pedro> +{ Pedro> + bool operator() (inferior *inf) Pedro> + { Pedro> + return (inf->pid != 0); Nit: the parens. There were some other instances of this. Maybe we don't care. Pedro> + /* Returns a range adapter covering the inferior's non-exited Pedro> + threads. Used like this: Pedro> + Pedro> + for (thread_info *thr : inf->non_exited_threads ()) Pedro> + [...] Pedro> + */ Pedro> + inf_non_exited_threads_range non_exited_threads () Pedro> + { return inf_non_exited_threads_range (this->thread_list); } Pedro> + Pedro> + inline safe_inf_threads_range threads_safe () Pedro> + { return safe_inf_threads_range (this->thread_list); } Nit: threads_safe should have an intro comment. Pedro> +#include "inferior-iter.h" I've been using "common/..." but it seems to vary in gdb. Pedro> +void Pedro> +all_threads_iterator::advance () Pedro> +{ Pedro> + /* The loop below is written in the natural way as-if we'd always Pedro> + start at the beginning of the inferior list. This fast forwards Pedro> + the algorithm to the actual current position. */ Pedro> + goto start; I did a double take on this one, but it does make sense. Tom