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.133.124]) by sourceware.org (Postfix) with ESMTPS id 4C02D3888C5A for ; Wed, 23 Mar 2022 12:00:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C02D3888C5A Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-sazVuER_P8uxgV-kTGy9Bg-1; Wed, 23 Mar 2022 08:00:06 -0400 X-MC-Unique: sazVuER_P8uxgV-kTGy9Bg-1 Received: by mail-wm1-f69.google.com with SMTP id m123-20020a1c2681000000b0038c9e1197f6so491457wmm.4 for ; Wed, 23 Mar 2022 05:00:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EokNSfhIsedMxBhnFMHzdsURHPzVuXGQciNx7qVQ7zo=; b=HaqXA91IidxOIyxKh44rOZPQSevn1d9q9TndYjnWXv/9CraJCKT2eSem50Ffp4LsK/ Dite6piV6Nq1RCMWy2VI7gIefDn8vfbVeieQBbNp/sBnxxC4paklMer0I3gx3vOXNllW Z+skprEBOceaarew7COH8RjG3qeaZEwiBa66J9VI80fgpX7i4vWsQm1oSF9XES9rhMkR 1Lk9hZddeDomqr2r5LNMCrFmnhmp6B8YZdmo6hy/AKEselHviTCF4gBcPpl8KekEascR UUbRGYeJlb4NkwOf8++f/kobDwGVpmAitMp40l4RfdG916qQPZsjMF99sD+3H7JtMXXM cIug== X-Gm-Message-State: AOAM530yB2+9/V3Hadsw4bzHrJ9MqbqRcYZzTGWTnCg5zt67FJrfC7iS QtvzsqUBKaxL4KGyULAsxspmoJyDK2sGiwl8AX2XFrU300aK//Xs1zf5JHzxi+avtanqghBejRO GpwuCL7cWHFUkvm5dFvJtDCvpr83DQoSjzIs3T6Gz5bcBTU9VN2jo1W3yTg/cdhHSCLKUXhktEQ == X-Received: by 2002:adf:ffc9:0:b0:204:195:4ab0 with SMTP id x9-20020adfffc9000000b0020401954ab0mr16920360wrs.561.1648036804974; Wed, 23 Mar 2022 05:00:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR66pzlyC5jpB4h+R6uO22wxFycmN42yXg7j87Nfwh3yZGi1U7IGkEkW2wc4oYzDdRHwkinA== X-Received: by 2002:adf:ffc9:0:b0:204:195:4ab0 with SMTP id x9-20020adfffc9000000b0020401954ab0mr16920333wrs.561.1648036804660; Wed, 23 Mar 2022 05:00:04 -0700 (PDT) Received: from localhost (host109-158-45-15.range109-158.btcentralplus.com. [109.158.45.15]) by smtp.gmail.com with ESMTPSA id c4-20020adffb04000000b001f0494de239sm17969994wrr.21.2022.03.23.05.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 05:00:04 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/3] gdb/dwarf: pass an array of values to the dwarf evaluator Date: Wed, 23 Mar 2022 11:59:57 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <20220323115809.GT1212730@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 23 Mar 2022 12:00:11 -0000 When we need to evaluate a DWARF expression in order to resolve some dynamic property of a type we call the dwarf2_evaluate_property function, which is declared in gdb/dwarf/loc.h and defined in gdb/dwarf/loc.c. Currently, this function takes (amongst other things) an argument of type property_addr_info called addr_stack and a boolean called push_initial_value. When push_initial_value then the top value of addr_stack is pushed onto the dwarf expression evaluation stack before the expression is evaluated. So far this has worked fine, as the only two cases we needed to handle are the case the DWARF expression doesn't require the object address (what the top of addr_stack represents), and the case where the DWARF expression does require the address. In the next commit this is going to change. As we add support for Fortran assumed rank arrays, we need to start resolving the dynamic properties of arrays. To do this, we need to push the array rank onto the dwarf expression evaluation stack before the expression is evaluated. This commit is a refactoring commit aimed at making it easier to support Fortran assumed rank arrays. Instead of passing a boolean, and using this to decide if we should push the object address or not, we instead pass an array (view) of values that should be pushed to the dwarf expression evaluation stack. In the couple of places where we previously passed push_initial_value as true (mostly this was defaulting to false), we now have to pass the address from the addr_stack as an item in the array view. In the next commit, when we want to handle passing the array rank, this will easily be supported too. There should be no user visible changes after this commit. --- gdb/dwarf2/loc.c | 20 ++++++++------------ gdb/dwarf2/loc.h | 8 +++++--- gdb/gdbtypes.c | 2 +- gdb/gnu-v3-abi.c | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 4c3d04b3226..8821f56f10d 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1536,10 +1536,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, evaluated. ADDR_STACK is a context (location of a variable) and might be needed to evaluate the location expression. - PUSH_INITIAL_VALUE is true if the first address from ADDR_STACK, should - be pushed on the DWARF expression evaluation stack before evaluating the - expression; this is required by certain forms of DWARF expression. When - PUSH_INITIAL_VALUE is true ADDR_STACK can't be nullptr. + PUSH_VALUES is an array of values to be pushed to the expression stack + before evaluation starts. Returns 1 on success, 0 otherwise. */ @@ -1548,7 +1546,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *valp, - bool push_initial_value, + gdb::array_view push_values, bool *is_reference) { if (dlbaton == NULL || dlbaton->size == 0) @@ -1561,11 +1559,9 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, value *result; scoped_value_mark free_values; - if (push_initial_value) - { - gdb_assert (addr_stack != nullptr); - ctx.push_address (addr_stack->addr, false); - } + /* Place any initial values onto the expression stack. */ + for (const auto &val : push_values) + ctx.push_address (val, false); try { @@ -1611,7 +1607,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *value, - bool push_initial_value) + gdb::array_view push_values) { if (prop == NULL) return false; @@ -1629,7 +1625,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, bool is_reference = baton->locexpr.is_reference; if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack, - value, push_initial_value, &is_reference)) + value, push_values, &is_reference)) { if (is_reference) { diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index cf02f609cb0..6943463b7db 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -114,14 +114,16 @@ struct property_addr_info Returns true if PROP could be converted and the static value is passed back into VALUE, otherwise returns false. - If PUSH_INITIAL_VALUE is true, then the top value of ADDR_STACK - will be pushed before evaluating a location expression. */ + Any values in PUSH_VALUES will be pushe before evaluating the location + expression, PUSH_VALUES[0] will be pushed first, then PUSH_VALUES[1], + etc. This means the during evaluation PUSH_VALUES[0] will be at the + bottom of the stack. */ bool dwarf2_evaluate_property (const struct dynamic_prop *prop, struct frame_info *frame, const struct property_addr_info *addr_stack, CORE_ADDR *value, - bool push_initial_value = false); + gdb::array_view push_values = {}); /* A helper for the compiler interface that compiles a single dynamic property to C code. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index f41d6bd960e..6a6acc80b4b 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2601,7 +2601,7 @@ resolve_dynamic_struct (struct type *type, CORE_ADDR addr; if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr, - true)) + {addr_stack->addr})) resolved_type->field (i).set_loc_bitpos (TARGET_CHAR_BIT * (addr - addr_stack->addr)); } diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 0cbb8d0d3a6..142fa46f21c 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -483,7 +483,7 @@ gnuv3_baseclass_offset (struct type *type, int index, CORE_ADDR result; if (dwarf2_evaluate_property (&prop, nullptr, &addr_stack, &result, - true)) + {addr_stack.addr})) return (int) (result - addr_stack.addr); } -- 2.25.4