From patchwork Wed Nov 1 17:09:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 78881 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C0FB3858C3A for ; Wed, 1 Nov 2023 17:10:10 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id C726D3858D37 for ; Wed, 1 Nov 2023 17:09:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C726D3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C726D3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698858588; cv=none; b=lqSTupO1es95u5bkameMDNwIeAmuqHwk0evt0Hj5naMwJsAw2ZI2lm0U9DAvoKZpe3ceeijD3eJ1rCbRHWJWQCNNr25SxIYyGnUEY9Jo+FQK8GiTjl9xnYFq70BQbPaNGIVPDUdypOtBkyj1mrFwlsDLw9dujn6hsK7CfUrcpDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698858588; c=relaxed/simple; bh=Em0z4xUSnmcwZL6N/YobM9L8uttUzwMAI90By16ZkZI=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=ZXU/Ei3o9eYfmc3/YQUoiFqg1JJSi0BlYNas7MDzDki0ob+iPyUbi7S/7ijE7TH/4kHx9VEgeGoVOdniYY93iHSzTCF/86OurCQ3dnim4HL4OvkZE8JIqFZ74115qfPxEy2jVQKwkSMVljvSroXjWxkevgCF8ClGWM3+fPRN3Jc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-357c9dc1068so161205ab.0 for ; Wed, 01 Nov 2023 10:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1698858580; x=1699463380; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8xOfG0EK0PwCA1U6OBfWaClCBJneM8uaw8vTfDSYYSU=; b=UrCv2+pQ5PIRrRSgUDfMWh1bKxa6wiV3xGlchZ/DYoZ3EE34PknnZO2GLZLVmiEKgd QvVqrSWpIZ+Et8S2niyTFXS1BkjX8iGLcjrpHgNzwjRl0+VHaJCkj4eDhpwhTVwtdgaQ YCbvvnazMU7K7T2mjM5sgz6NRVwVJdRw24nMYXtzsZuq2rOBi8z5wQlSUTnkK1DUYnZV HN7nATHSB+fih8kDs8UWinx5fyyhLrAT0tIuc0q21G6dxzH71NBAW/ynTw70ouah2ifD j1C6CdGSEIeLg9sAuLutdSHjfnhhRM+kd9yXp+sC8rKv2JsD+UzR//w53NaiVkuOADas c1uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698858580; x=1699463380; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8xOfG0EK0PwCA1U6OBfWaClCBJneM8uaw8vTfDSYYSU=; b=EFYMG5axpiK9g+EHFU66ZDMRaCCW2vVef4e1eryyQhQY4NXhEV6S0J35lb3SRz1BTG RCmq/mFpr3x2JRH+fd6QyFmp6jsvLaPv3Y9HmulJZ4GIOrxRnrB9rA66rG0XWf6P7/0I ht8yshMQF5nN223Zv6BhH07rMaeb4sCwx+bwfa0BST53P04eUm1Ly8N5rxGgqF5F788w lr0QwgfgtPR1Sy076AuRa2MOI5agzlBsPP4ySLR+5LdgvUW6zMlOwoelFvIAFoXuwvQN uk2mcnKNr5ywQwgbtfBBE+0tIbgUDz0jjnnsBQv2okEwMdOpJrUYl4mz4GTxTr2ju834 Sh/w== X-Gm-Message-State: AOJu0Yy4RFYi7/fdTsVRb/Zqr0ZF/hbplBuehMFepxMRewOhutX4+M1W hjzHSb+DbBP+OYt9WBH7HFZvI3CbSKggV8nG+qr38A== X-Google-Smtp-Source: AGHT+IEcBQnDhysimCQ1OrD0ScIJ0kL19CG/YutoNqGQXt/7ZZvdkKeoz7XnavRFDX42fcy/CcLkkQ== X-Received: by 2002:a05:6e02:1aa5:b0:34a:95f9:650c with SMTP id l5-20020a056e021aa500b0034a95f9650cmr3610835ilv.10.1698858579928; Wed, 01 Nov 2023 10:09:39 -0700 (PDT) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id gm2-20020a0566382b8200b0042b3a328ee0sm1017019jab.166.2023.11.01.10.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 10:09:39 -0700 (PDT) From: Tom Tromey Date: Wed, 01 Nov 2023 11:09:35 -0600 Subject: [PATCH 3/7] Move follow_static_link to frame.c MIME-Version: 1.0 Message-Id: <20231101-dap-nested-function-v1-3-0b0c3b228ac7@adacore.com> References: <20231101-dap-nested-function-v1-0-0b0c3b228ac7@adacore.com> In-Reply-To: <20231101-dap-nested-function-v1-0-0b0c3b228ac7@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org This moves the follow_static_link function to frame.c and exports it for use elsewhere. The API is changed slightly to make it more generically useful. --- gdb/findvar.c | 59 ++++++----------------------------------------------------- gdb/frame.c | 40 ++++++++++++++++++++++++++++++++++++++++ gdb/frame.h | 7 +++++++ 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index 1079b85df82..952ec20c0b7 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -31,7 +31,6 @@ #include "block.h" #include "objfiles.h" #include "language.h" -#include "dwarf2/loc.h" #include "gdbsupport/selftest.h" /* Basic byte-swapping routines. All 'extract' functions return a @@ -391,41 +390,6 @@ symbol_read_needs_frame (struct symbol *sym) return symbol_read_needs (sym) == SYMBOL_NEEDS_FRAME; } -/* Given static link expression and the frame it lives in, look for the frame - the static links points to and return it. Return NULL if we could not find - such a frame. */ - -static frame_info_ptr -follow_static_link (frame_info_ptr frame, - const struct dynamic_prop *static_link) -{ - CORE_ADDR upper_frame_base; - - if (!dwarf2_evaluate_property (static_link, frame, NULL, &upper_frame_base)) - return NULL; - - /* Now climb up the stack frame until we reach the frame we are interested - in. */ - for (; frame != NULL; frame = get_prev_frame (frame)) - { - struct symbol *framefunc = get_frame_function (frame); - - /* Stacks can be quite deep: give the user a chance to stop this. */ - QUIT; - - /* If we don't know how to compute FRAME's base address, don't give up: - maybe the frame we are looking for is upper in the stack frame. */ - if (framefunc != NULL - && SYMBOL_BLOCK_OPS (framefunc) != NULL - && SYMBOL_BLOCK_OPS (framefunc)->get_frame_base != NULL - && (SYMBOL_BLOCK_OPS (framefunc)->get_frame_base (framefunc, frame) - == upper_frame_base)) - break; - } - - return frame; -} - /* Assuming VAR is a symbol that can be reached from FRAME thanks to lexical rules, look for the frame that is actually hosting VAR and return it. If, for some reason, we found no such frame, return NULL. @@ -494,25 +458,14 @@ get_hosting_frame (struct symbol *var, const struct block *var_block, /* Assuming we have a block for this frame: if we are at the function level, the immediate upper lexical block is in an outer function: follow the static link. */ - else if (frame_block->function ()) + else if (frame_block->function () != nullptr) { - const struct dynamic_prop *static_link - = frame_block->static_link (); - int could_climb_up = 0; - - if (static_link != NULL) - { - frame = follow_static_link (frame, static_link); - if (frame != NULL) - { - frame_block = get_frame_block (frame, NULL); - could_climb_up = frame_block != NULL; - } - } - if (!could_climb_up) + frame = frame_follow_static_link (frame); + if (frame != nullptr) { - frame = NULL; - break; + frame_block = get_frame_block (frame, nullptr); + if (frame_block == nullptr) + frame = nullptr; } } diff --git a/gdb/frame.c b/gdb/frame.c index 7077016ccba..4a46ccb9abc 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -43,6 +43,7 @@ #include "hashtab.h" #include "valprint.h" #include "cli/cli-option.h" +#include "dwarf2/loc.h" /* The sentinel frame terminates the innermost end of the frame chain. If unwound, it returns the information needed to construct an @@ -3120,6 +3121,45 @@ get_frame_sp (frame_info_ptr this_frame) return gdbarch_unwind_sp (gdbarch, frame_info_ptr (this_frame->next)); } +/* See frame.h. */ + +frame_info_ptr +frame_follow_static_link (frame_info_ptr frame) +{ + const block *frame_block = get_frame_block (frame, nullptr); + frame_block = frame_block->function_block (); + + const struct dynamic_prop *static_link = frame_block->static_link (); + if (static_link == nullptr) + return {}; + + CORE_ADDR upper_frame_base; + + if (!dwarf2_evaluate_property (static_link, frame, NULL, &upper_frame_base)) + return {}; + + /* Now climb up the stack frame until we reach the frame we are interested + in. */ + for (; frame != nullptr; frame = get_prev_frame (frame)) + { + struct symbol *framefunc = get_frame_function (frame); + + /* Stacks can be quite deep: give the user a chance to stop this. */ + QUIT; + + /* If we don't know how to compute FRAME's base address, don't give up: + maybe the frame we are looking for is upper in the stack frame. */ + if (framefunc != NULL + && SYMBOL_BLOCK_OPS (framefunc) != NULL + && SYMBOL_BLOCK_OPS (framefunc)->get_frame_base != NULL + && (SYMBOL_BLOCK_OPS (framefunc)->get_frame_base (framefunc, frame) + == upper_frame_base)) + break; + } + + return frame; +} + /* Return the reason why we can't unwind past FRAME. */ enum unwind_stop_reason diff --git a/gdb/frame.h b/gdb/frame.h index 1d7422cac32..19bf8176682 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -640,6 +640,13 @@ class address_space; /* Return the frame's address space. */ extern const address_space *get_frame_address_space (frame_info_ptr); +/* A frame may have a "static link". That is, in some languages, a + nested function may have access to variables from the enclosing + block and frame. This function looks for a frame's static link. + If found, returns the corresponding frame; otherwise, returns a + null frame_info_ptr. */ +extern frame_info_ptr frame_follow_static_link (frame_info_ptr frame); + /* For frames where we can not unwind further, describe why. */ enum unwind_stop_reason