From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 8115D3857830 for ; Thu, 10 Dec 2020 14:52:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8115D3857830 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 0BAEqEeZ031012 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Dec 2020 09:52:19 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 0BAEqEeZ031012 Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id ABE451E590; Thu, 10 Dec 2020 09:52:14 -0500 (EST) Subject: Re: [PATCH 3/4] gdb/dwarf: don't enqueue CU in maybe_queue_comp_unit if already expanded To: Tom Tromey , Simon Marchi via Gdb-patches Cc: nilsgladitz@gmail.com References: <20201117191231.2712629-1-simon.marchi@polymtl.ca> <20201117191231.2712629-4-simon.marchi@polymtl.ca> <87eejyr7uq.fsf@tromey.com> From: Simon Marchi Message-ID: Date: Thu, 10 Dec 2020 09:52:14 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <87eejyr7uq.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 10 Dec 2020 14:52:14 +0000 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 10 Dec 2020 14:52:23 -0000 On 2020-12-09 4:24 p.m., Tom Tromey wrote: > Re-reading this code, I realized again that the return value of this > function does not really make sense to me. The intro says: > > The result is non-zero if PER_CU was queued, otherwise the result is zero > meaning either PER_CU is already queued or it is already loaded. > > ... but it seems unlikely for callees to want to detect that just this > call caused the enqueueing. Ok, re-reading that comment, I think I understand things a bit differently than I did previously: /* If PER_CU is not yet queued, add it to the queue. If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a dependency. The result is non-zero if PER_CU was queued, otherwise the result is zero meaning either PER_CU is already queued or it is already loaded. N.B. There is an invariant here that if a CU is queued then it is loaded. The caller is required to load PER_CU if we return non-zero. */ The premise is: there is the invariant that if a CU is queued for expansion, its DIEs are loaded. If maybe_queue_comp_unit enqueues a CU for expansion whose DIEs are not loaded, it returns 1 to its caller to ask "please load the DIEs for that CU because I just enqueued it and if you don't the invariant will get violated and we'll get in trouble". So if a CU is already expanded and maybe_queue_comp_unit doesn't enqueue it, it makes sense that it returns 0, because it doesn't *require* the caller to load the DIEs. However, that means that the caller shouldn't rely on maybe_queue_comp_unit's return value to determine whether the CU's DIEs are currently loaded, because: 1. whether maybe_queue_comp_unit requires it to load the CU's DIEs 2. whether the CU's DIEs are currently loaded are two different things. If the caller wants to know #2, because it itself needs to ensure the DIEs are loaded, it should not rely on maybe_queue_comp_unit's return value, but instead check itself with dwarf2_per_objfile::get_cu. I'll go over my patch and think about it a little more. Simon