From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GaoAEDyqOWoa6RMAWB0awg (envelope-from ) for ; Mon, 22 Jun 2026 17:33:48 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dTeP8all; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3E5101E070; Mon, 22 Jun 2026 17:33:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 982AB1E070 for ; Mon, 22 Jun 2026 17:33:47 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68F254BA23EC for ; Mon, 22 Jun 2026 21:33:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68F254BA23EC Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dTeP8all Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 817574BA2E12 for ; Mon, 22 Jun 2026 21:33:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 817574BA2E12 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 817574BA2E12 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782163995; cv=none; b=IGje5/p4kaaThZGUuEn2ENBp+1c60TBjHkauBTKNzasL1t1v54CH8aqk01rG16FD7jdJWiZ7eh9kO5s7CC51HUbpe9f4YE3auxWtVeSf46xKpRj3Goj1yCnDnvON65Qq6Xlt7nHsqc1ih9hBAysrOLysdRXYkHVJ2fEGpOimND4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782163995; c=relaxed/simple; bh=UZiCIhA1eNKyjoTyTjBuENGGea+EHZVwBZJPVl1XnjE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=AGEVVAgOhVGm+m4fgVTF+ysyPZrHh2YrUJRGSBJMYCAbM85Q6mqELIV7o3RSQywHKTieRktRmQK8MkacNgZJYHheMScZOKLIcPckXDtyTdzNjE+cPdOwXhSEK+sD5VxgQGVbFTpihlMHbvG4C8hkWcOREsDZg0TKVcjvj4rpkPk= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dTeP8all DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 817574BA2E12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782163995; 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=AZ9m/P7E46rzcXIo1EPbGMdvfK+hRF/LOs6PrEjur5E=; b=dTeP8allIbHv8XPvtnaJk8rD5HqSXRtySXrUsprahcli0btjv17opRS22Jqs4djY7KOJ/M K7ps3w8a9/+wCfeUUo5Pbt9NSVCDsEWOs4f+1N2aMrZMtrcQa1mgDGZQ0Xr0F5Pzarpgtj qrHXwmJkUATHJKfL4CdY85U+xC+WL/Q= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-rGLjb96pMIGfqCdpPXHQ9A-1; Mon, 22 Jun 2026 17:33:13 -0400 X-MC-Unique: rGLjb96pMIGfqCdpPXHQ9A-1 X-Mimecast-MFC-AGG-ID: rGLjb96pMIGfqCdpPXHQ9A_1782163993 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4924583c7baso33429555e9.1 for ; Mon, 22 Jun 2026 14:33:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782163992; x=1782768792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AZ9m/P7E46rzcXIo1EPbGMdvfK+hRF/LOs6PrEjur5E=; b=HLZwOy0UangBBWU1xa/QUJOk1VdX0AomcRbmMJXdPf2JFwl8sXmN5wH0iCEoo25FBK 8m3IBIrQN67E+2ahLQ86V8XE7T/f+4Pae5si3paSq1Td988ykqet6hFFzmFWp+5Lb03d 7QlmuL1Nj27cY3lbGjORWKnvKi2Tiy3flStpxtuA3qAtTPZREsvrZ2akZbClQrNKn8cO nQMmZyP3OcU3bLu3oqK+0/yWrvk5q9bcSwX4oIq7hcmF76eBoXborKzIVhHdRE0jyaov RV30basIwE9Ze5pnSfL5tJk1FUcfTut32ooiedUk/yIALIMt99X19wsmFRsNKsbc1y7Y RKtA== X-Gm-Message-State: AOJu0YxIdgzwJLrCA3m8Q34KUHkyzFIWZE5GNJXAvClCqj3BaKg+6goN ZTGmqTVhgzUn2g/mcl6c+MrbOarLPHCAzVMxjJpGyKwO2WMTieRwr1pP4mIftxUEYfLaGEqMGI4 Pf72sZz5falva7Q/wIDB4mbh2G/PaOiISEQ0qL7cp3TODjQP85FCsAPl0qr4Z9zK73IlAtyxsMw 8ds5N5h+DqW2i33O7qP3EmiXfjd3+plXXFU028qoeTMJy1lJ8= X-Gm-Gg: AfdE7clYtVWKjkjnnhQri/A90TJ3jk3QfgFnZ/qWHhhl6qYFhVR9C/q4/S91/BUYYFq vS7OS8utltuPyv5TlCPAcHyMnvlv4/txTI3goSo0uoF2ApxIyx6eAIf3lZ8z/7gAMyXfzW8d4Nf T1/Ce4tcvwHQRC9tOkKujuDWHn5+AZVKdK+Vqca/npVm5r8eCmRWUtn0XUULSfpIJtxZvxtvEcQ yyL7Y6hSOkeiFVjB42xqy34z0sR7TFIe5VO9KHQrKQ5vWy6EfvbcSHx/r7AY//ISW5FH6VWMLXf CvOT9yOAWa05iecG3R+cyhhj+xzhJb4y528/0XqGjajrDPVPFA/rz84I+RhrfGzTi944yPv82wS odQXQNLzVgfbYOJ63VhvVcsRIGfSlHw== X-Received: by 2002:a05:600c:6298:b0:48e:7854:1608 with SMTP id 5b1f17b1804b1-4923f5872d5mr281782235e9.25.1782163992492; Mon, 22 Jun 2026 14:33:12 -0700 (PDT) X-Received: by 2002:a05:600c:6298:b0:48e:7854:1608 with SMTP id 5b1f17b1804b1-4923f5872d5mr281781825e9.25.1782163991992; Mon, 22 Jun 2026 14:33:11 -0700 (PDT) Received: from localhost (19.81.93.209.dyn.plus.net. [209.93.81.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49245711032sm298318785e9.0.2026.06.22.14.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 14:33:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Simon Marchi Subject: [PATCHv2 2/2] gdb: convert sentinel_frame to a frame_info_ptr Date: Mon, 22 Jun 2026 22:33:06 +0100 Message-Id: <75107040e4b5cdaa04f7e954d36d36857cbc8318.1782163808.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yEQZhIp7XtPt6ikLnEUeQbn5HApjA0PQeBxIEOFdOtQ_1782163993 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The global sentinel_frame object is currently held as a raw frame_info pointer. In contrast, most frames are managed through a frame_info_ptr, and the global selected_frame is itself a frame_info_ptr. This commit converts the sentinel_frame to a frame_info_ptr. The frame_info_ptr constructor registers the new object in the global frame_list, so we need to ensure that the frame_list has been constructed before the sentinel_frame (now a frame_info_ptr) is constructed. This is achieved by moving the frame_list global earlier within the frame.c file. I chose to also move the selected_frame, selected_frame_id, and selected_frame_level globals. This isn't required, but keeps similar and related objects (the frame_list, selected_frame*, and sentinel_frame) together in the file. In get_current_frame, when assigning to the sentinel_frame global, we no longer need to pull the raw frame_info pointer from the result of calling create_sentinel_frame, this means we can drop the '.get ()' call. I took this opportunity to move the '=' operator onto the next line inline with GDB style. Additionally, in get_current_frame, we no longer need to convert sentinel_frame into a frame_info_ptr. There should be no user visible changes after this commit. --- gdb/frame.c | 96 ++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index c1a7c41dc4a..22bfb95aa95 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -45,6 +45,46 @@ #include "cli/cli-option.h" #include "dwarf2/loc.h" +/* Number of calls to reinit_frame_cache. */ +static unsigned int frame_cache_generation = 0; + +/* The "selected" stack frame is used by default for local and arg + access. + + The "single source of truth" for the selected frame is the + SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL pair. + + Frame IDs can be saved/restored across reinitializing the frame + cache, while frame_info pointers can't (frame_info objects are + invalidated). If we know the corresponding frame_info object, it + is cached in SELECTED_FRAME. + + If SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL are null_frame_id / -1, + and the target has stack and is stopped, the selected frame is the + current (innermost) target frame. SELECTED_FRAME_ID is never the ID + of the current (innermost) target frame. SELECTED_FRAME_LEVEL may + only be 0 if the selected frame is a user-created one (created and + selected through the "select-frame view" command), in which case + SELECTED_FRAME_ID is the frame id derived from the user-provided + addresses. + + If SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL are null_frame_id / -1, + and the target has no stack or is executing, then there's no + selected frame. */ +static frame_id selected_frame_id = null_frame_id; +static int selected_frame_level = -1; + +/* See frame.h. This definition should come before any definition of a static + frame_info_ptr, to ensure that frame_list is destroyed after any static + frame_info_ptr. This is necessary because the destructor of frame_info_ptr + uses frame_list. */ + +intrusive_list frame_info_ptr::frame_list; + +/* The cached frame_info object pointing to the selected frame. + Looked up on demand by get_selected_frame. */ +static frame_info_ptr selected_frame; + /* The sentinel frame terminates the innermost end of the frame chain. If unwound, it returns the information needed to construct an innermost frame. @@ -55,10 +95,7 @@ This is an optimization to be able to find the sentinel frame quickly, it could otherwise be found in the frame cache. */ -static frame_info *sentinel_frame; - -/* Number of calls to reinit_frame_cache. */ -static unsigned int frame_cache_generation = 0; +static frame_info_ptr sentinel_frame; /* See frame.h. */ @@ -1726,12 +1763,12 @@ get_current_frame (void) if (get_traceframe_number () < 0) validate_registers_access (); - if (sentinel_frame == NULL) - sentinel_frame = - create_sentinel_frame (current_program_space, - current_inferior ()->aspace.get (), - get_thread_regcache (inferior_thread ()), - 0, 0).get (); + if (sentinel_frame == nullptr) + sentinel_frame + = create_sentinel_frame (current_program_space, + current_inferior ()->aspace.get (), + get_thread_regcache (inferior_thread ()), + 0, 0); /* Set the current frame before computing the frame id, to avoid recursion inside compute_frame_id, in case the frame's @@ -1744,49 +1781,12 @@ get_current_frame (void) want to leave with the current frame created and linked in -- we should never end up with the sentinel frame as outermost frame. */ - current_frame = get_prev_frame_always_1 (frame_info_ptr (sentinel_frame)); + current_frame = get_prev_frame_always_1 (sentinel_frame); gdb_assert (current_frame != NULL); return current_frame; } -/* The "selected" stack frame is used by default for local and arg - access. - - The "single source of truth" for the selected frame is the - SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL pair. - - Frame IDs can be saved/restored across reinitializing the frame - cache, while frame_info pointers can't (frame_info objects are - invalidated). If we know the corresponding frame_info object, it - is cached in SELECTED_FRAME. - - If SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL are null_frame_id / -1, - and the target has stack and is stopped, the selected frame is the - current (innermost) target frame. SELECTED_FRAME_ID is never the ID - of the current (innermost) target frame. SELECTED_FRAME_LEVEL may - only be 0 if the selected frame is a user-created one (created and - selected through the "select-frame view" command), in which case - SELECTED_FRAME_ID is the frame id derived from the user-provided - addresses. - - If SELECTED_FRAME_ID / SELECTED_FRAME_LEVEL are null_frame_id / -1, - and the target has no stack or is executing, then there's no - selected frame. */ -static frame_id selected_frame_id = null_frame_id; -static int selected_frame_level = -1; - -/* See frame.h. This definition should come before any definition of a static - frame_info_ptr, to ensure that frame_list is destroyed after any static - frame_info_ptr. This is necessary because the destructor of frame_info_ptr - uses frame_list. */ - -intrusive_list frame_info_ptr::frame_list; - -/* The cached frame_info object pointing to the selected frame. - Looked up on demand by get_selected_frame. */ -static frame_info_ptr selected_frame; - /* See frame.h. */ void -- 2.25.4