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 BAC13384E23B for ; Mon, 12 Dec 2022 13:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BAC13384E23B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca 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 2BCDjU9i026794 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Dec 2022 08:45:34 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2BCDjU9i026794 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1670852735; bh=0lXEwT2UsbtSwtQ0jWRep16BBrU6ujJClC6E9NS7l3I=; h=Date:Subject:To:References:From:In-Reply-To:From; b=gQGCdAVJ8YWhvY2b2uRnRxgMjICShbsS/xcwPyB8TsW/9JLFj/g4fij5SoLfOQIEu xHq06cyFGXn2J9n1Ss+NApkVFVtv5TCjuBBVHbWVb5aQIwOWczCRf0or8/K4xAc2P1 0OR3KBXA0mrbydY19JW5olh7VabgYaVj7InaqiCo= Received: from [10.0.0.11] (unknown [217.28.27.60]) (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 1C5621E0CB; Mon, 12 Dec 2022 08:45:30 -0500 (EST) Message-ID: Date: Mon, 12 Dec 2022 08:45:29 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH 3/6] gdb: make user-created frames reinflatable Content-Language: en-US To: Bruno Larsen , gdb-patches@sourceware.org References: <20221202180052.212745-1-simon.marchi@polymtl.ca> <20221202180052.212745-4-simon.marchi@polymtl.ca> From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 12 Dec 2022 13:45:30 +0000 X-Spam-Status: No, score=-3038.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/12/22 08:33, Bruno Larsen wrote: > On 12/12/2022 14:17, Simon Marchi wrote: >> >>>> diff --git a/gdb/frame-info.c b/gdb/frame-info.c >>>> index 40a872ea152d..d61fb7ed0e95 100644 >>>> --- a/gdb/frame-info.c >>>> +++ b/gdb/frame-info.c >>>> @@ -21,6 +21,9 @@ >>>> #include "frame-info.h" >>>> #include "frame.h" >>>> +#include "gdbsupport/selftest.h" >>>> +#include "scoped-mock-context.h" >>>> +#include "test-target.h" >>>> /* See frame-info-ptr.h. */ >>>> @@ -33,7 +36,8 @@ frame_info_ptr::prepare_reinflate () >>>> { >>>> m_cached_level = frame_relative_level (*this); >>>> - if (m_cached_level != 0) >>>> + if (m_cached_level != 0 >>>> + || (m_ptr != nullptr && frame_is_user_created (m_ptr))) >>>> m_cached_id = get_frame_id (*this); >>>> } >>>> @@ -54,7 +58,13 @@ frame_info_ptr::reinflate () >>>> /* Frame #0 needs special handling, see comment in select_frame. */ >>>> if (m_cached_level == 0) >>>> - m_ptr = get_current_frame ().get (); >>>> + { >>>> + if (!frame_id_p (m_cached_id)) >>> You seem to be using the stack being valid to check if the frame is >> stack -> frame id? > > No, I meant stack because frame_id_p checks stack_status == FID_STACK_INVALID. > >> >>> user created, but in the commit message you mention that you use null >>> frame id. Wouldn't it be more reliable to check if m_cached_id == >>> null_frame_id ? >> Comparing anything against null_frame_id (even a null frame id) yields >> false: >> >> if (stack_status == FID_STACK_INVALID >> || r.stack_status == FID_STACK_INVALID) >> /* Like a NaN, if either ID is invalid, the result is false. >> Note that a frame ID is invalid iff it is the null frame ID. */ >> eq = false; >> >> From: https://gitlab.com/gnutools/binutils-gdb/-/blob/a28fedbc3f582ce7c8bad2eb017b1dc072bb1da7/gdb/frame.c#L759-763 >> >> I don't really understand the point, I think it would be useful to be >> able to compare a frame id to null_frame_id, like we compare pointers to >> nullptr. But currently, the correct (and only?) way of checking if we >> have a frame id or not in a frame_id is frame_id_p. > > Ah right, that explains it. I think we could add a comment to frame_id_p to make it more clear for newer contributors like me. > > However, it isn't the only way to check if a frame_id is null, we can use the fact that null_frame_id != null_frame_id and check for: > > if (m_cached_id != m_cached_id) > /* get current frame */ > else > /* recreate user frame */ > > This is (apparently) very common for folks using Javascript to check if something is NaN. I personally find it hideous and would much prefer checking against null_frame_id directly. I just figured I might as well throw this cursed knowledge out there :) Huh, I didn't think of that! I don't like it either, it really doesn't convey the intent. Simon