From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D1F603858C2D for ; Tue, 8 Nov 2022 10:40:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D1F603858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667904032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GzlInMhrHUy9Bhp9oGewhuel+n8smqGpz9vdyE3MUGU=; b=Y1QPu2mUN3PL/2VMdkkDeVBf0k9w5YYFUXTuHnRp2xm0gggcaGyOdiT4wlVis2A+X0DOsT WuxcTs0lI+p8y5B8IhiuRfxjdt35d5zLCdfXhjdNKMR9jnbJR5QRhCg7yMafeHpmG3L2OD 1ZcvzzzYDnNGrF1EuvmiO1oy+iqDs/4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-99-cczkhwHFP5-4Swn-jCfdDg-1; Tue, 08 Nov 2022 05:40:31 -0500 X-MC-Unique: cczkhwHFP5-4Swn-jCfdDg-1 Received: by mail-ed1-f71.google.com with SMTP id y20-20020a056402271400b004630f3a32c3so10274630edd.15 for ; Tue, 08 Nov 2022 02:40:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GzlInMhrHUy9Bhp9oGewhuel+n8smqGpz9vdyE3MUGU=; b=3moTg+IURtg5WXWKAgMx6BIJ7eYiVXlgkuh/N4NEBmP3fqA18lMeWjB7diGNbiu2Td lENmorJhyg/lecgCMpV5uthHKXBM0AWTZSZSyYbMPJxWia0XXdg6T+JDG3rgHiWsxH94 hVHRVh9Lu3rQs2R+rcr/ARUh/3vxV7GMRbOu/eu0a8DIDf7BZHGGLh65iddwqSpCjAiV AFC6Y36YA+8QQN0Gu6j80INqKOumcIRazHCoV93nuQ0dsSsM2OlVvchnzppaNbi6tKJk qrtCInpySMq/uRDXgqfwATAD1ezEV3v78/EHrlWxjXgEIVJAC0qeavx0bmzVAAcdkMbG s+QQ== X-Gm-Message-State: ACrzQf2RCYuCrXIKwkOmfVuZCDby2/ja6vSNQ5OHfSZF2R8VNKt6eOuB uJr6kM/gQSLy0k+jNttBVXEIDnEbN4TcxsNvXCElftJg/cVjPNrkRCCVORr0rRz5zVW2ZMv8fKL 0yqULkH/5LSsWAkZ/5AG/iw== X-Received: by 2002:a05:6402:496:b0:443:a5f5:d3b with SMTP id k22-20020a056402049600b00443a5f50d3bmr56585291edv.331.1667904029921; Tue, 08 Nov 2022 02:40:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM60WX7QULUKy9yWSlm1hvhYNUwtMSzmvZ65spXZSuofUPwJU9eB95W+WqvR35u3QiUpEc/M4Q== X-Received: by 2002:a05:6402:496:b0:443:a5f5:d3b with SMTP id k22-20020a056402049600b00443a5f50d3bmr56585277edv.331.1667904029699; Tue, 08 Nov 2022 02:40:29 -0800 (PST) Received: from [10.43.2.105] (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 1-20020a170906310100b007ad94fd48dfsm4579785ejx.139.2022.11.08.02.40.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Nov 2022 02:40:29 -0800 (PST) Message-ID: <24a4edb5-4081-7b34-a5ca-291d51decea4@redhat.com> Date: Tue, 8 Nov 2022 11:40:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH 7/7] gdb: add special handling for frame level 0 in frame_info_ptr To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi References: <20221107155310.2590069-1-simon.marchi@polymtl.ca> <20221107155310.2590069-7-simon.marchi@polymtl.ca> From: Bruno Larsen In-Reply-To: <20221107155310.2590069-7-simon.marchi@polymtl.ca> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 07/11/2022 16:53, Simon Marchi via Gdb-patches wrote: > From: Simon Marchi > > I noticed this problem while preparing the initial submission for the > ROCm GDB port. One particularity of this patch set is that it does not > support unwinding frames, that requires support of some DWARF extensions > that will come later. It was still possible to run to a breakpoint and > print frame #0, though. > > When rebasing on top of the frame_info_ptr work, GDB started tripping on > a prepare_reinflate call, making it not possible anymore to event print > the frame when stopping on a breakpoint. One thing to know about frame > 0 is that its id is lazily computed when something requests it through > get_frame_id. See: > > https://gitlab.com/gnutools/binutils-gdb/-/blob/23912acd402f5af9caf91b257e5209ec4c58a09c/gdb/frame.c#L2070-2080 > > So, up to that prepare_reinflate call, frame 0's id was not computed, > and prepare_reinflate, calling get_frame_id, forces it to be computed. > Computing the frame id generally requires unwinding the previous frame, > which with my ROCm GDB patch fails. An exception is thrown and the > printing of the frame is simply abandonned. > > Regardless of this ROCm GDB problem (which is admittedly temporary, it > will be possible to unwind with subsequent patches), we want to avoid > prepare_reinflate to force the computing of the frame id, for the same > reasons we lazily compute it in the first place. > > In addition, frame 0's id is subject to change across a frame cache > reset. This is why save_selected_frame and restore_selected_frame have > special handling for frame 0: > > https://gitlab.com/gnutools/binutils-gdb/-/blob/23912acd402f5af9caf91b257e5209ec4c58a09c/gdb/frame.c#L1841-1863 > > For this last reason, we also need to handle frame 0 specially in > prepare_reinflate / reinflate. Because the frame id of frame 0 can > change across a frame cache reset, we must not rely on the frame id from > that frame to reinflate it. We should instead just re-fetch the current > frame at that point. > > This patch adds a frame_info_ptr::m_cached_level field, set in > frame_info_ptr::prepare_reinflate, so we can tell if a frame is frame 0. > There are cases where a frame_info_ptr object wraps a sentinel frame, > for which frame_relative_level returns -1, so I have chosen the value -2 > to represent "invalid frame level", for when the frame_info_ptr object > is empty. > > In frame_info_ptr::prepare_reinflate, only cache the frame id if the > frame level is not 0. It's fine to cache the frame id for the sentinel > frame, it will be properly handled by frame_find_by_id later. > > In frame_info_ptr::reinflate, if the frame level is 0, call > get_current_frame to get the target's current frame. Otherwise, use > frame_find_by_id just as before. > > This patch should not have user-visible changes with upstream GDB. But > it will avoid forcing the computation of frame 0's when calling > prepare_reinflate. And, well, it fixes the upcoming ROCm GDB patch > series. > > Change-Id: I176ed7ee9317ddbb190acee8366e087e08e4d266 This all makes sense. I have a small style preference below, but even if you dislike it, the code is still fine. Reviewed-By: Bruno Larsen > --- > gdb/frame-info.c | 24 ++++++++++++++++++++---- > gdb/frame-info.h | 20 ++++++++++++++++++-- > 2 files changed, 38 insertions(+), 6 deletions(-) > > diff --git a/gdb/frame-info.c b/gdb/frame-info.c > index 584222dc490f..e3ee9f8174e1 100644 > --- a/gdb/frame-info.c > +++ b/gdb/frame-info.c > @@ -31,7 +31,11 @@ intrusive_list frame_info_ptr::frame_list; > void > frame_info_ptr::prepare_reinflate () > { > - m_cached_id = get_frame_id (*this); > + m_cached_level = frame_relative_level (*this); > + gdb_assert (m_cached_level >= -1); Since you have declared invalid_level = -2 for this class, I feel like it would be more better to have the assert be gdb_assert (m_cached_level > invalid_level); This way there is no need to wonder why -1 is a valid level, and makes it easier to grep for the comment in the file, should someone want to know. > + > + if (m_cached_level != 0) > + m_cached_id = get_frame_id (*this); > } > > /* See frame-info-ptr.h. */ > @@ -39,9 +43,21 @@ frame_info_ptr::prepare_reinflate () > void > frame_info_ptr::reinflate () > { > - gdb_assert (frame_id_p (m_cached_id)); > + gdb_assert (m_cached_level >= -1); Likewise -- Cheers, Bruno