From patchwork Thu Mar 9 17:50:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66176 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 231213857352 for ; Thu, 9 Mar 2023 17:52:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 231213857352 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678384326; bh=LTGjMp5kN921YvHpXcrby47SxjTXFBjZFKF+FQMeZLw=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=T6+GRKvL2rMsPRjIm22L9e6a2zlH5tuBbju9fjCdjcIPGAF2deMNrBuoM+rITAmvz OBVYhEfT9Ultu54lNoVQHBsp/FZ3t/nnHMKbSWmWmLUoeKXqml0pRZiMVi/c38klXQ MrYVN/z4NzxcB9KkzsDYs2gK2q0MZnyhHjDDdGhc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id BD4BE3858C5E for ; Thu, 9 Mar 2023 17:51:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD4BE3858C5E Received: by mail-il1-x12a.google.com with SMTP id x10so1432611ill.12 for ; Thu, 09 Mar 2023 09:51:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678384275; 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=LTGjMp5kN921YvHpXcrby47SxjTXFBjZFKF+FQMeZLw=; b=vyIGwGlddMeK27cieIvKW6Eiw3K/HSTyyyMp5+gXVuJrGdeRjPXebojIp1jmPsEfT4 voFiRhrAel9g/seAnZAYks2sTlY+pFeHeo1eI/bjCid/VEoCoZ9/LjES6ZSkf6o0s1uG EqhI0jr1zFUVUUuDG11eQEXFY5v2cPsnsr8+XdC444HXkPwx4LbGN/jFCZmQXvqMCl8h /yf3y17U1CMB07Pp4vTnkWspPVLR9H374ZjrEoA+p+lfkIvUIGigIYe7p9Bbr4+NTfIx uAQUL6tBjX9D3refwwHTNim7ie/bJcWh4fIGj0eM3f0mcrHdBqp0LLO6b9DFnlZYDPl6 QwnA== X-Gm-Message-State: AO0yUKUcWOcz5dq1DJWHlTez6PxsF+UdOSei0BCmTBGaEYeU4gbVz9DL LvPcrKBkaHajL1xqq/F1yljkR+ky0kTKqjz3WPY= X-Google-Smtp-Source: AK7set+8j8Fn14jYF+fiuKNjzElqN5gvXgNUsGTxTeiA05sZ5v8z9l0fWAkiv/rjLfBTUOJQMH/omQ== X-Received: by 2002:a05:6e02:b4d:b0:314:e6f:f2d1 with SMTP id f13-20020a056e020b4d00b003140e6ff2d1mr16745131ilu.31.1678384274918; Thu, 09 Mar 2023 09:51:14 -0800 (PST) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id j5-20020a056e020ee500b00315785bfabfsm5572276ilk.47.2023.03.09.09.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 09:51:14 -0800 (PST) Date: Thu, 09 Mar 2023 10:50:55 -0700 Subject: [PATCH 1/3] Add frame parameter to resolve_dynamic_type MIME-Version: 1.0 Message-Id: <20230309-submit-static-link-fix-v1-1-23af27781fd2@adacore.com> References: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> In-Reply-To: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds a frame parameter to resolve_dynamic_type and arranges for it to be passed through the call tree and, in particular, to all calls to dwarf2_evaluate_property. Nothing passes this parameter yet, so this patch should have no visible effect. A 'const frame_info_ptr *' is used here to avoid including frame.h from gdbtypes.h. --- gdb/gdbtypes.c | 71 +++++++++++++++++++++++++++++++++++----------------------- gdb/gdbtypes.h | 6 ++++- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index f22ba44a538..37203b5a436 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2190,7 +2190,8 @@ is_dynamic_type (struct type *type) } static struct type *resolve_dynamic_type_internal - (struct type *type, struct property_addr_info *addr_stack, int top_level); + (struct type *type, struct property_addr_info *addr_stack, + const frame_info_ptr &frame, int top_level); /* Given a dynamic range type (dyn_range_type) and a stack of struct property_addr_info elements, return a static version @@ -2211,6 +2212,7 @@ static struct type *resolve_dynamic_type_internal static struct type * resolve_dynamic_range (struct type *dyn_range_type, struct property_addr_info *addr_stack, + const frame_info_ptr &frame, int rank, bool resolve_p = true) { CORE_ADDR value; @@ -2221,14 +2223,14 @@ resolve_dynamic_range (struct type *dyn_range_type, gdb_assert (rank >= 0); const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low; - if (resolve_p && dwarf2_evaluate_property (prop, NULL, addr_stack, &value, + if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value, { (CORE_ADDR) rank })) low_bound.set_const_val (value); else low_bound.set_undefined (); prop = &dyn_range_type->bounds ()->high; - if (resolve_p && dwarf2_evaluate_property (prop, NULL, addr_stack, &value, + if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value, { (CORE_ADDR) rank })) { high_bound.set_const_val (value); @@ -2242,7 +2244,7 @@ resolve_dynamic_range (struct type *dyn_range_type, bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride; prop = &dyn_range_type->bounds ()->stride; - if (resolve_p && dwarf2_evaluate_property (prop, NULL, addr_stack, &value, + if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value, { (CORE_ADDR) rank })) { stride.set_const_val (value); @@ -2265,7 +2267,7 @@ resolve_dynamic_range (struct type *dyn_range_type, static_target_type = resolve_dynamic_type_internal (dyn_range_type->target_type (), - addr_stack, 0); + addr_stack, frame, 0); LONGEST bias = dyn_range_type->bounds ()->bias; static_range_type = create_range_type_with_stride (copy_type (dyn_range_type), static_target_type, @@ -2296,6 +2298,7 @@ resolve_dynamic_range (struct type *dyn_range_type, static struct type * resolve_dynamic_array_or_string_1 (struct type *type, struct property_addr_info *addr_stack, + const frame_info_ptr &frame, int rank, bool resolve_p) { CORE_ADDR value; @@ -2325,7 +2328,7 @@ resolve_dynamic_array_or_string_1 (struct type *type, dimension of the array. */ prop = TYPE_ALLOCATED_PROP (type); if (prop != NULL && resolve_p - && dwarf2_evaluate_property (prop, NULL, addr_stack, &value)) + && dwarf2_evaluate_property (prop, frame, addr_stack, &value)) { prop->set_const_val (value); if (value == 0) @@ -2334,7 +2337,7 @@ resolve_dynamic_array_or_string_1 (struct type *type, prop = TYPE_ASSOCIATED_PROP (type); if (prop != NULL && resolve_p - && dwarf2_evaluate_property (prop, NULL, addr_stack, &value)) + && dwarf2_evaluate_property (prop, frame, addr_stack, &value)) { prop->set_const_val (value); if (value == 0) @@ -2343,14 +2346,15 @@ resolve_dynamic_array_or_string_1 (struct type *type, range_type = check_typedef (type->index_type ()); range_type - = resolve_dynamic_range (range_type, addr_stack, rank, resolve_p); + = resolve_dynamic_range (range_type, addr_stack, frame, rank, resolve_p); ary_dim = check_typedef (type->target_type ()); if (ary_dim != NULL && ary_dim->code () == TYPE_CODE_ARRAY) { ary_dim = copy_type (ary_dim); elt_type = resolve_dynamic_array_or_string_1 (ary_dim, addr_stack, - rank - 1, resolve_p); + frame, rank - 1, + resolve_p); } else elt_type = type->target_type (); @@ -2358,7 +2362,7 @@ resolve_dynamic_array_or_string_1 (struct type *type, prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE); if (prop != NULL && resolve_p) { - if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value)) + if (dwarf2_evaluate_property (prop, frame, addr_stack, &value)) { type->remove_dyn_prop (DYN_PROP_BYTE_STRIDE); bit_stride = (unsigned int) (value * 8); @@ -2385,7 +2389,8 @@ resolve_dynamic_array_or_string_1 (struct type *type, static struct type * resolve_dynamic_array_or_string (struct type *type, - struct property_addr_info *addr_stack) + struct property_addr_info *addr_stack, + const frame_info_ptr &frame) { CORE_ADDR value; int rank = 0; @@ -2399,7 +2404,7 @@ resolve_dynamic_array_or_string (struct type *type, /* Resolve the rank property to get rank value. */ struct dynamic_prop *prop = TYPE_RANK_PROP (type); - if (dwarf2_evaluate_property (prop, nullptr, addr_stack, &value)) + if (dwarf2_evaluate_property (prop, frame, addr_stack, &value)) { prop->set_const_val (value); rank = value; @@ -2467,7 +2472,8 @@ resolve_dynamic_array_or_string (struct type *type, reduce the rank by 1 here. */ --rank; - return resolve_dynamic_array_or_string_1 (type, addr_stack, rank, true); + return resolve_dynamic_array_or_string_1 (type, addr_stack, frame, rank, + true); } /* Resolve dynamic bounds of members of the union TYPE to static @@ -2476,7 +2482,8 @@ resolve_dynamic_array_or_string (struct type *type, static struct type * resolve_dynamic_union (struct type *type, - struct property_addr_info *addr_stack) + struct property_addr_info *addr_stack, + const frame_info_ptr &frame) { struct type *resolved_type; int i; @@ -2500,7 +2507,7 @@ resolve_dynamic_union (struct type *type, continue; t = resolve_dynamic_type_internal (resolved_type->field (i).type (), - addr_stack, 0); + addr_stack, frame, 0); resolved_type->field (i).set_type (t); struct type *real_type = check_typedef (t); @@ -2675,7 +2682,8 @@ compute_variant_fields (struct type *type, static struct type * resolve_dynamic_struct (struct type *type, - struct property_addr_info *addr_stack) + struct property_addr_info *addr_stack, + const frame_info_ptr &frame) { struct type *resolved_type; int i; @@ -2725,7 +2733,7 @@ resolve_dynamic_struct (struct type *type, prop.set_locexpr (&baton); CORE_ADDR addr; - if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr, + if (dwarf2_evaluate_property (&prop, frame, addr_stack, &addr, {addr_stack->addr})) resolved_type->field (i).set_loc_bitpos (TARGET_CHAR_BIT * (addr - addr_stack->addr)); @@ -2752,7 +2760,7 @@ resolve_dynamic_struct (struct type *type, resolved_type->field (i).set_type (resolve_dynamic_type_internal (resolved_type->field (i).type (), - &pinfo, 0)); + &pinfo, frame, 0)); gdb_assert (resolved_type->field (i).loc_kind () == FIELD_LOC_KIND_BITPOS); @@ -2797,6 +2805,7 @@ resolve_dynamic_struct (struct type *type, static struct type * resolve_dynamic_type_internal (struct type *type, struct property_addr_info *addr_stack, + const frame_info_ptr &frame, int top_level) { struct type *real_type = check_typedef (type); @@ -2810,7 +2819,7 @@ resolve_dynamic_type_internal (struct type *type, gdb::optional type_length; prop = TYPE_DYNAMIC_LENGTH (type); if (prop != NULL - && dwarf2_evaluate_property (prop, NULL, addr_stack, &value)) + && dwarf2_evaluate_property (prop, frame, addr_stack, &value)) type_length = value; if (type->code () == TYPE_CODE_TYPEDEF) @@ -2818,7 +2827,7 @@ resolve_dynamic_type_internal (struct type *type, resolved_type = copy_type (type); resolved_type->set_target_type (resolve_dynamic_type_internal (type->target_type (), addr_stack, - top_level)); + frame, top_level)); } else { @@ -2843,7 +2852,7 @@ resolve_dynamic_type_internal (struct type *type, resolved_type = copy_type (type); resolved_type->set_target_type (resolve_dynamic_type_internal (type->target_type (), - &pinfo, top_level)); + &pinfo, frame, top_level)); break; } @@ -2851,7 +2860,8 @@ resolve_dynamic_type_internal (struct type *type, /* Strings are very much like an array of characters, and can be treated as one here. */ case TYPE_CODE_ARRAY: - resolved_type = resolve_dynamic_array_or_string (type, addr_stack); + resolved_type = resolve_dynamic_array_or_string (type, addr_stack, + frame); break; case TYPE_CODE_RANGE: @@ -2860,15 +2870,15 @@ resolve_dynamic_type_internal (struct type *type, this rank value is not actually required for the resolution of the dynamic range, otherwise, we'd be resolving this range within the context of a dynamic array. */ - resolved_type = resolve_dynamic_range (type, addr_stack, 0); + resolved_type = resolve_dynamic_range (type, addr_stack, frame, 0); break; case TYPE_CODE_UNION: - resolved_type = resolve_dynamic_union (type, addr_stack); + resolved_type = resolve_dynamic_union (type, addr_stack, frame); break; case TYPE_CODE_STRUCT: - resolved_type = resolve_dynamic_struct (type, addr_stack); + resolved_type = resolve_dynamic_struct (type, addr_stack, frame); break; } } @@ -2885,7 +2895,7 @@ resolve_dynamic_type_internal (struct type *type, /* Resolve data_location attribute. */ prop = TYPE_DATA_LOCATION (resolved_type); if (prop != NULL - && dwarf2_evaluate_property (prop, NULL, addr_stack, &value)) + && dwarf2_evaluate_property (prop, frame, addr_stack, &value)) { /* Start of Fortran hack. See comment in f-lang.h for what is going on here.*/ @@ -2905,12 +2915,17 @@ resolve_dynamic_type_internal (struct type *type, struct type * resolve_dynamic_type (struct type *type, gdb::array_view valaddr, - CORE_ADDR addr) + CORE_ADDR addr, + const frame_info_ptr *in_frame) { struct property_addr_info pinfo = {check_typedef (type), valaddr, addr, NULL}; - return resolve_dynamic_type_internal (type, &pinfo, 1); + frame_info_ptr frame; + if (in_frame != nullptr) + frame = *in_frame; + + return resolve_dynamic_type_internal (type, &pinfo, frame, 1); } /* See gdbtypes.h */ diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index c4889a4a05b..884cdc5bfb0 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2419,6 +2419,10 @@ extern CORE_ADDR get_pointer_type_max (struct type *); If TYPE has no dynamic properties return TYPE; otherwise a new type with static properties is returned. + If FRAME is given, it is used when evaluating dynamic properties. + This can be important when a static link is seen. If not given, + the selected frame is used. + For an array type, if the element type is dynamic, then that will not be resolved. This is done because each individual element may have a different type when resolved (depending on the contents of @@ -2426,7 +2430,7 @@ extern CORE_ADDR get_pointer_type_max (struct type *); true for the return value of this function. */ extern struct type *resolve_dynamic_type (struct type *type, gdb::array_view valaddr, - CORE_ADDR addr); + CORE_ADDR addr, const frame_info_ptr *frame = nullptr); /* * Predicate if the type has dynamic values, which are not resolved yet. See the caveat in 'resolve_dynamic_type' to understand a scenario From patchwork Thu Mar 9 17:50:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66175 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 AB7FD385703A for ; Thu, 9 Mar 2023 17:51:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB7FD385703A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678384300; bh=tlYvavASI9X5I5aHFhOUxljjSRmx8DAqoND/Kw/nB5Y=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Fy5TL1oP9z37g1Yqm+9E3DM5L+JoXpWjRp62GmDtr8iHWD1rXkr3qpJ/vHoe5t+s3 HX4a023bANrW5pbXJkB7tW4jr5fA6YR0m5Jhwr+DNE0AKcaEH6peeDe7V3nJUgLjfq PQ8F9Bzs7fVL/QCkbPwK+UIiMTdq9dSSa8UBvCT8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 51D1A3858C74 for ; Thu, 9 Mar 2023 17:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51D1A3858C74 Received: by mail-il1-x12c.google.com with SMTP id w4so1508732ilv.0 for ; Thu, 09 Mar 2023 09:51:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678384275; 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=tlYvavASI9X5I5aHFhOUxljjSRmx8DAqoND/Kw/nB5Y=; b=DcaAvKIQ3juMPBb3z0X5KKtSSmjkuMLypdX1GyOLrg2U4MHs6CRFI4Owl7z3+JGF7K KwKUo46YVR+nDG1pT0p3rvwLs5J8jxsQcqCFOpCiCGAlbtelDfT3o9rLN5XrafuidP35 PWy/4he0J2uaU7Bd4vdilrfNQuVSqV1kH3UemHTSRRc5r4qnS7DABe8iEqpwBhzvdx9m U7/wROGF+ogwYoR8Cba+9AumhldSTZsLmYvIfcNUHeKT5yLvRXIjsUOxLn98kShQfDuR Mh3d2ZslBCf0AB8/Pomsgjn9Ej7HUoV9g6vLTpiP9INv6hpD1+P+RBe5MeLcCdvmZumR k1ug== X-Gm-Message-State: AO0yUKXFMr5Dm6pw+hWTQ/CI8A+Vxcdz0sDl0rc9RIGgV5JYGLZDp+Xi r/z2LRy6mgnJMOVZHxj5K6c+WKWK4vnUe7CkpLs= X-Google-Smtp-Source: AK7set+OAgh2BQuulx4ygCCMwYkjGh0RFmGaYU+Yv6W9BPPGTKO7xgvSGVr/0mdgpCtHxFtR4l31Qw== X-Received: by 2002:a05:6e02:1b87:b0:313:c74c:725a with SMTP id h7-20020a056e021b8700b00313c74c725amr17195095ili.12.1678384275455; Thu, 09 Mar 2023 09:51:15 -0800 (PST) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id j5-20020a056e020ee500b00315785bfabfsm5572276ilk.47.2023.03.09.09.51.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 09:51:15 -0800 (PST) Date: Thu, 09 Mar 2023 10:50:56 -0700 Subject: [PATCH 2/3] Pass a frame to value_at_lazy and value_from_contents_and_address MIME-Version: 1.0 Message-Id: <20230309-submit-static-link-fix-v1-2-23af27781fd2@adacore.com> References: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> In-Reply-To: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch adds a 'frame' parameter to value_at_lazy and ensures that it is passed down to the call to resolve_dynamic_type. This required also adding a frame parameter to value_from_contents_and_address. Nothing passes this parameter to value_at_lazy yet, so this patch should have no visible effect. --- gdb/valops.c | 11 ++++++----- gdb/value.c | 6 ++++-- gdb/value.h | 14 ++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gdb/valops.c b/gdb/valops.c index 3a1b14c3d44..e14c5d05c06 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -982,14 +982,15 @@ value_one (struct type *type) e.g. in case the type is a variable length array. */ static struct value * -get_value_at (struct type *type, CORE_ADDR addr, int lazy) +get_value_at (struct type *type, CORE_ADDR addr, frame_info_ptr frame, + int lazy) { struct value *val; if (check_typedef (type)->code () == TYPE_CODE_VOID) error (_("Attempt to dereference a generic pointer.")); - val = value_from_contents_and_address (type, NULL, addr); + val = value_from_contents_and_address (type, NULL, addr, frame); if (!lazy) val->fetch_lazy (); @@ -1015,7 +1016,7 @@ get_value_at (struct type *type, CORE_ADDR addr, int lazy) struct value * value_at (struct type *type, CORE_ADDR addr) { - return get_value_at (type, addr, 0); + return get_value_at (type, addr, nullptr, 0); } /* See value.h. */ @@ -1034,9 +1035,9 @@ value_at_non_lval (struct type *type, CORE_ADDR addr) e.g. in case the type is a variable length array. */ struct value * -value_at_lazy (struct type *type, CORE_ADDR addr) +value_at_lazy (struct type *type, CORE_ADDR addr, frame_info_ptr frame) { - return get_value_at (type, addr, 1); + return get_value_at (type, addr, frame, 1); } void diff --git a/gdb/value.c b/gdb/value.c index 7b4df338304..253ed3d596d 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -3438,12 +3438,14 @@ value_from_contents_and_address_unresolved (struct type *type, struct value * value_from_contents_and_address (struct type *type, const gdb_byte *valaddr, - CORE_ADDR address) + CORE_ADDR address, + frame_info_ptr frame) { gdb::array_view view; if (valaddr != nullptr) view = gdb::make_array_view (valaddr, type->length ()); - struct type *resolved_type = resolve_dynamic_type (type, view, address); + struct type *resolved_type = resolve_dynamic_type (type, view, address, + &frame); struct type *resolved_type_no_typedef = check_typedef (resolved_type); struct value *v; diff --git a/gdb/value.h b/gdb/value.h index d83c4ab3674..02d66a80ef8 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1077,7 +1077,13 @@ extern struct value *value_from_component (struct value *, struct type *, extern struct value *value_at (struct type *type, CORE_ADDR addr); -extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr); + +/* Return a new value given a type and an address. The new value is + lazy. If FRAME is given, it is used when resolving dynamic + properties. */ + +extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr, + frame_info_ptr frame = nullptr); /* Like value_at, but ensures that the result is marked not_lval. This can be important if the memory is "volatile". */ @@ -1085,9 +1091,9 @@ extern struct value *value_at_non_lval (struct type *type, CORE_ADDR addr); extern struct value *value_from_contents_and_address_unresolved (struct type *, const gdb_byte *, CORE_ADDR); -extern struct value *value_from_contents_and_address (struct type *, - const gdb_byte *, - CORE_ADDR); +extern struct value *value_from_contents_and_address + (struct type *, const gdb_byte *, CORE_ADDR, + frame_info_ptr frame = nullptr); extern struct value *value_from_contents (struct type *, const gdb_byte *); extern struct value *default_value_from_register (struct gdbarch *gdbarch, From patchwork Thu Mar 9 17:50:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66177 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 C30163858296 for ; Thu, 9 Mar 2023 17:52:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C30163858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678384328; bh=k/zRQ9/TlELDJqEsHGw98vn2cACKg63OppzuECBqUuM=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xeItKSoxaiGsr7cBGVxaMymA3mrTpl3+3h5jv9eEnqFQYi9tpA9SYfJuMwVQRA3lU /2nGBjqQesN1B2dkHjiF8Apiu0oPcC2VF5fkVbOn6Y00Aa00gqtbkuq5RsZTQWG5Yl OqLI2rCgiGpfKHfMeLkk8SWHAruJsrVlqwpYpc4I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id D0DE23858C78 for ; Thu, 9 Mar 2023 17:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0DE23858C78 Received: by mail-il1-x135.google.com with SMTP id i19so1438497ila.10 for ; Thu, 09 Mar 2023 09:51:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678384276; 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=k/zRQ9/TlELDJqEsHGw98vn2cACKg63OppzuECBqUuM=; b=A55kCLcgbx6fdQ6g1isev797+0wgcB9+5bZ+Oc+4mO3iqNeT0902g2lxjGfLaYv+BC xdw/JJX/BnYX3n7cJq/iq3w/aBcS+xYUoNRET47xMzXMVchCcEOzcktzsaCMWvaH4+Kc 1Bk0ugex4ejIx+5vNN/ZPn5IWZQ8O6H2Iwmsn+nCvqbWn5tXYMG5pp4Du/Agm9NI114F wM7xf9qBcj3gz6wHOM0CWqtUyt+EYqp3w+R7+AmaNR3NoBl+rkjsSfePWk5b9lIPorxw GMCdKLEjVjKNSv04iBG9/eCoUM//vQOS2DabqrYo94B8BgxkMo7MnRl4c/m3jq2dv2fc Fy9Q== X-Gm-Message-State: AO0yUKUO+UVKJ4jqzgapGdLMGVDg9KVCfS5KabAtpQIdY8cXOz3Gvrkh x95Lu6Pz6He0LJX9/0SDLCW78vlBk4QQawVAATE= X-Google-Smtp-Source: AK7set+ZR3rz/eLxo7r2QucWHLDUaQQLZJI7pW1bozJTSkd36aU+plzslLViRMc4awUUyWfUh/vzGg== X-Received: by 2002:a05:6e02:144f:b0:314:f7f:a35a with SMTP id p15-20020a056e02144f00b003140f7fa35amr18725995ilo.7.1678384276030; Thu, 09 Mar 2023 09:51:16 -0800 (PST) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id j5-20020a056e020ee500b00315785bfabfsm5572276ilk.47.2023.03.09.09.51.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 09:51:15 -0800 (PST) Date: Thu, 09 Mar 2023 10:50:57 -0700 Subject: [PATCH 3/3] Use the correct frame when evaluating a dynamic property MIME-Version: 1.0 Message-Id: <20230309-submit-static-link-fix-v1-3-23af27781fd2@adacore.com> References: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> In-Reply-To: <20230309-submit-static-link-fix-v1-0-23af27781fd2@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The test case in this patch shows an unusual situation: an Ada array has a dynamic bound, but the bound comes from a frame that's referred to by the static link. This frame is correctly found when evaluating the array variable itself, but is lost when evaluating the array's bounds. This patch fixes the problem by passing this frame through to value_at_lazy in the DWARF expression evaluator. --- gdb/dwarf2/expr.c | 4 ++-- gdb/testsuite/gdb.ada/static-link.exp | 33 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/static-link/pck.ads | 18 +++++++++++++++ gdb/testsuite/gdb.ada/static-link/prog.adb | 35 ++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 2b41372be8a..fd83ba29a90 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -1002,8 +1002,8 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, } address = value_as_address (value_from_pointer (ptr_type, address)); - retval = value_at_lazy (subobj_type, - address + subobj_offset); + retval = value_at_lazy (subobj_type, address + subobj_offset, + m_frame); if (in_stack_memory) retval->set_stack (true); } diff --git a/gdb/testsuite/gdb.ada/static-link.exp b/gdb/testsuite/gdb.ada/static-link.exp new file mode 100644 index 00000000000..86f2fb5076b --- /dev/null +++ b/gdb/testsuite/gdb.ada/static-link.exp @@ -0,0 +1,33 @@ +# Copyright 2023 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile prog + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/prog.adb] +if {![runto "prog.adb:$bp_location"]} { + return -1 +} + +gdb_test "ptype value" [string_to_regexp "type = array (1 .. 3) of integer"] diff --git a/gdb/testsuite/gdb.ada/static-link/pck.ads b/gdb/testsuite/gdb.ada/static-link/pck.ads new file mode 100644 index 00000000000..a37f7bb0a10 --- /dev/null +++ b/gdb/testsuite/gdb.ada/static-link/pck.ads @@ -0,0 +1,18 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +package Pck is + Some_Value : Integer := 3; +end Pck; diff --git a/gdb/testsuite/gdb.ada/static-link/prog.adb b/gdb/testsuite/gdb.ada/static-link/prog.adb new file mode 100644 index 00000000000..a14817b7440 --- /dev/null +++ b/gdb/testsuite/gdb.ada/static-link/prog.adb @@ -0,0 +1,35 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pck; use Pck; + +procedure Prog is + + Upper : Integer := Some_Value; + Value : array (1 .. Upper) of Integer := (23, 24, 25); + + procedure Inner_Most is + begin + null; -- STOP + end; + + procedure Intermediate is + begin + Inner_Most; + end; + +begin + Intermediate; +end Prog;