From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2056.outbound.protection.outlook.com [40.107.244.56]) by sourceware.org (Postfix) with ESMTPS id 5C425393D02B for ; Mon, 7 Dec 2020 19:01:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5C425393D02B ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MGIR6kfnkJd1mY5CRjmWXDn/lLJJ3ixVLY+WstTMfBbH+bojvnwCX+YSVvDLDRU0ruGF3ONgz15a28vCaHS7BsOu7hgtVjT8q6QKX9K062GuKhPYIxLNJMSJHl6uMuoVE9/yWY7n5avbGSqpl77QCEHjAotQIPIk4gn+vYBObjYVs7NSFjJxozboY+bScwU5qWjB0BoOAxzB2BaPyxc2IHhirpwOT2MqISy53+/SLKevh77C0EBxlqSZMTC4bUpJfZ30PIqwLDNB9ndXO/PxCJ3im5DCNyakG9jXVwAO+Hs9puesWWnJ9cFzOhS1oKSRGH2Y3bj9/jejN16Sk09alg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g/sBj0W0oZc+MtOhLp2+2/eHWGCKyIB+ofYeSeuPY1E=; b=i0buXxthu8jqaiM1TmuhXqU87v9xOqpxpkkU75CLFkfOzfnaRNk5DdW+OT9W6YbhOqNTHK+MY84fzayk/pdfebiKH3dRbmH/vLPq66MYXwzQ6e9d5uvNQlkgTZmJC3hvF8cFfGWBJogzGzQlqSKQcPo8/ntwzpIb6A97+KIZCX1lrmtASf2vH/hys4f1CX1K/8fiBdC7FYSlfEiypKU5uDtC7K9s3bNdjqAwkTkaPGdLZVpA90ZOaTReHSTpUu17NJ7LZJBmpcafDgLvYjSE4LR6GqlI8EifJzC6BS2z5JFc7LEMfw0SIYRd07dbXuDRicijD4Z/9Ei9oBsZGyVN9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) by DM6PR12MB4561.namprd12.prod.outlook.com (2603:10b6:5:2ac::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.18; Mon, 7 Dec 2020 19:01:12 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::6841:61df:984b:b3c]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::6841:61df:984b:b3c%3]) with mapi id 15.20.3632.021; Mon, 7 Dec 2020 19:01:12 +0000 From: Zoran Zaric To: gdb-patches@sourceware.org Cc: Zoran Zaric Subject: [PATCH 15/30] Add as_lval argument to expression evaluator Date: Mon, 7 Dec 2020 19:00:16 +0000 Message-Id: <20201207190031.13341-16-Zoran.Zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201207190031.13341-1-Zoran.Zaric@amd.com> References: <20201207190031.13341-1-Zoran.Zaric@amd.com> Content-Type: text/plain X-Originating-IP: [2a00:23c7:5a85:6801:5c7:2db6:d2c2:ae4e] X-ClientProxiedBy: AM4PR0101CA0053.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::21) To DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a00:23c7:5a85:6801:5c7:2db6:d2c2:ae4e) by AM4PR0101CA0053.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Mon, 7 Dec 2020 19:01:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6a87bc67-9e21-471e-b30c-08d89ae276e5 X-MS-TrafficTypeDiagnostic: DM6PR12MB4561: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: av9YnP0uzFCUsl/8HTytgCakpOOey4A/TBhmYm19mPCcZcJXmpL3t/AjrxiDNpx77xnxxclr/0Eh1pnmZ8Sx/OTmVNk/vgGPmdRlnlW+vID0bKZPYVijHz120OeSbKjxJj8HjyJbHadzzBPLWn+VgGHVBUI4c8F0THXsH8s01U8BQ/v9q5u/jmC/Bi18VuemOpY4Qsc6KsIslScHWW4Bi+kA0wUJdWvYL7Mx4aRbD93Rp2VAzIAuMWhNyzH8fDZ2s/GT8SKDsldQi3zmYAAGqYopXnRrFeJ+3PatlfHzF6mXUJIOfCF9UlTnmzzc518ssv9fs+S1eeodqbm8qIe6R3uIrNr63AGvEJ9VnxgCpVjdAPJdSsqZEz/2BVZI5ShdKy+SfY2ShTDiN0vevOhi6dtu0I9UB2BbKhNJSgzZmzSOq3DzVzQiFuPRN2vjJKTMFAg8pKXV5a+23qUrUfm6Fw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB2762.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(39860400002)(366004)(136003)(396003)(1076003)(83380400001)(86362001)(6506007)(4326008)(69590400008)(52116002)(36756003)(2906002)(6512007)(8676002)(966005)(6486002)(16526019)(2616005)(66946007)(66476007)(66556008)(6916009)(5660300002)(186003)(8936002)(478600001)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?q1UCk9fsIky8tDRBYDC8X4PydKrao4M6OSP3IJ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DEZGp+u7u4MXfuNFfxYDcadaZdBCU91IFshybmWUsPE0zMIK?= =?us-ascii?Q?3SOax3EDiIvZcwlVrcJWnmD/OgUb4BUysLmTtgA3eXRU5GJhn6tNmzS3xQo4?= =?us-ascii?Q?0FupbHtTfpmIvdilSm1uiyC3IeYFvz5d45NLa2T57mcUg3WpkaaxkGbXOvtS?= =?us-ascii?Q?AvGokXQE?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2020 19:01:11.9517 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 6a87bc67-9e21-471e-b30c-08d89ae276e5 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Jey03S0JO0QrCyfQ6OvSUWN9kGx6pmrS1iaObvQb0w957aHI/xsU5RUdSuls2Y2EM488D891+twwRpjpVSWVfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4561 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 07 Dec 2020 19:01:27 -0000 There are cases where the result of the expression evaluation is expected to be in a form of a value and not location description. One place that has this requirement is dwarf_entry_parameter_to_value function, but more are expected in the future. Until now, this requirement was fulfilled by extending the evaluated expression with a DW_OP_stack_value operation at the end. New implementation, introduces a new evaluation argument instead. * dwarf2/expr.c (dwarf_expr_context::fetch_result): Add as_lval argument. (dwarf_expr_context::eval_exp): Add as_lval argument. * dwarf2/expr.h (struct dwarf_expr_context): Add as_lval argument to fetch_result and eval_exp methods. * dwarf2/frame.c (execute_stack_op): Add as_lval argument. * dwarf2/loc.c (dwarf_entry_parameter_to_value): Remove DWARF expression extension. (dwarf2_evaluate_loc_desc_full): Add as_lval argument support. (dwarf2_evaluate_loc_desc): Add as_lval argument support. (dwarf2_locexpr_baton_eval): Add as_lval argument support. --- gdb/dwarf2/expr.c | 12 +++++++++--- gdb/dwarf2/expr.h | 19 ++++++++++++------- gdb/dwarf2/frame.c | 2 +- gdb/dwarf2/loc.c | 27 ++++++++++----------------- gdb/dwarf2/loc.h | 6 ++++-- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 5e99a98e1e..b1283e70df 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -903,7 +903,8 @@ dwarf_expr_context::push_dwarf_reg_entry_value struct value * dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, - LONGEST subobj_offset) + LONGEST subobj_offset, + bool as_lval) { struct value *retval = nullptr; @@ -933,6 +934,11 @@ dwarf_expr_context::fetch_result (struct type *type, } else { + /* If AS_LVAL is false, means that the implicit conversion + from a location description to value is expected. */ + if (as_lval == false) + this->location = DWARF_VALUE_STACK; + switch (this->location) { case DWARF_VALUE_REGISTER: @@ -1057,7 +1063,7 @@ dwarf_expr_context::fetch_result (struct type *type, /* See expr.h. */ struct value * -dwarf_expr_context::eval_exp (const gdb_byte *addr, size_t len, +dwarf_expr_context::eval_exp (const gdb_byte *addr, size_t len, bool as_lval, struct dwarf2_per_cu_data *per_cu, struct frame_info *frame, const struct property_addr_info *addr_info, @@ -1073,7 +1079,7 @@ dwarf_expr_context::eval_exp (const gdb_byte *addr, size_t len, this->ref_addr_size = per_cu->ref_addr_size (); eval (addr, len); - return fetch_result (type, subobj_type, subobj_offset); + return fetch_result (type, subobj_type, subobj_offset, as_lval); } /* Require that TYPE be an integral type; throw an exception if not. */ diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h index 69a043da50..1c06308f99 100644 --- a/gdb/dwarf2/expr.h +++ b/gdb/dwarf2/expr.h @@ -130,11 +130,13 @@ struct dwarf_expr_context void push_address (CORE_ADDR value, bool in_stack_memory); /* Evaluate the expression at ADDR (LEN bytes long) in a given PER_CU - FRAME context. Where TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET describe - expected struct value representation of the evaluation result. - The ADDR_INFO property can be specified to override the range of - memory addresses with the passed in buffer. */ - struct value *eval_exp (const gdb_byte *addr, size_t len, + FRAME context. AS_LVAL defines if the returned struct value is + expected to be a value or a location description. Where TYPE, + SUBOBJ_TYPE and SUBOBJ_OFFSET describe expected struct value + representation of the evaluation result. The ADDR_INFO property + can be specified to override the range of memory addresses with + the passed in buffer. */ + struct value *eval_exp (const gdb_byte *addr, size_t len, bool as_lval, struct dwarf2_per_cu_data *per_cu, struct frame_info *frame, const struct property_addr_info *addr_info = nullptr, @@ -223,10 +225,13 @@ struct dwarf_expr_context /* Fetch the result of the expression evaluation in a form of a struct value, where TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET - describe the source level representation of that result. */ + describe the source level representation of that result. + AS_LVAL defines if the fetched struct value is expected to + be a value or a location description. */ struct value *fetch_result (struct type *type, struct type *subobj_type, - LONGEST subobj_offset); + LONGEST subobj_offset, + bool as_lval); /* Return the location expression for the frame base attribute, in START and LENGTH. The result must be live until the current diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index 228c48f387..4037653106 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -232,7 +232,7 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size, scoped_value_mark free_values; ctx.push_address (initial, initial_in_stack_memory); - struct value *result_val = ctx.eval_exp (exp, len, nullptr, this_frame); + struct value *result_val = ctx.eval_exp (exp, len, true, nullptr, this_frame); if (VALUE_LVAL (result_val) == lval_memory) return value_address (result_val); diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index fdf8385933..1a23e0b2da 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -50,7 +50,7 @@ static struct value *dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, const gdb_byte *data, size_t size, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, - struct type *subobj_type, LONGEST subobj_byte_offset); + struct type *subobj_type, LONGEST subobj_byte_offset, bool as_lval = true); /* Until these have formal names, we define these here. ref: http://gcc.gnu.org/wiki/DebugFission @@ -1183,7 +1183,6 @@ dwarf_entry_parameter_to_value (struct call_site_parameter *parameter, dwarf2_per_objfile *per_objfile) { const gdb_byte *data_src; - gdb_byte *data; size_t size; data_src = deref_size == -1 ? parameter->value : parameter->data_value; @@ -1194,15 +1193,8 @@ dwarf_entry_parameter_to_value (struct call_site_parameter *parameter, throw_error (NO_ENTRY_VALUE_ERROR, _("Cannot resolve DW_AT_call_data_value")); - /* DW_AT_call_value is a DWARF expression, not a DWARF - location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from - DWARF block. */ - data = (gdb_byte *) alloca (size + 1); - memcpy (data, data_src, size); - data[size] = DW_OP_stack_value; - - return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu, - per_objfile); + return dwarf2_evaluate_loc_desc (type, caller_frame, data_src, size, per_cu, + per_objfile, false); } /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform @@ -1428,7 +1420,8 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, struct type *subobj_type, - LONGEST subobj_byte_offset) + LONGEST subobj_byte_offset, + bool as_lval) { if (subobj_type == NULL) { @@ -1448,8 +1441,8 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, try { - retval = ctx.eval_exp (data, size, per_cu, frame, nullptr, type, - subobj_type, subobj_byte_offset); + retval = ctx.eval_exp (data, size, as_lval, per_cu, frame, nullptr, + type, subobj_type, subobj_byte_offset); } catch (const gdb_exception_error &ex) { @@ -1490,10 +1483,10 @@ struct value * dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, const gdb_byte *data, size_t size, dwarf2_per_cu_data *per_cu, - dwarf2_per_objfile *per_objfile) + dwarf2_per_objfile *per_objfile, bool as_lval) { return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, - per_objfile, NULL, 0); + per_objfile, NULL, 0, as_lval); } /* Evaluates a dwarf expression and stores the result in VAL, @@ -1536,7 +1529,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, try { result = ctx.eval_exp (dlbaton->data, dlbaton->size, - per_cu, frame, addr_stack); + true, per_cu, frame, addr_stack); } catch (const gdb_exception_error &ex) { diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index 1de3604194..c14ba8febd 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -69,14 +69,16 @@ struct call_site_parameter *dwarf_expr_reg_to_entry_parameter /* Evaluate a location description, starting at DATA and with length SIZE, to find the current location of variable of TYPE in the context - of FRAME. */ + of FRAME. AS_LVAL defines if the resulting struct value is expected to + be a value or a location description. */ struct value *dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, const gdb_byte *data, size_t size, dwarf2_per_cu_data *per_cu, - dwarf2_per_objfile *per_objfile); + dwarf2_per_objfile *per_objfile, + bool as_lval = true); /* A chain of addresses that might be needed to resolve a dynamic property. */ -- 2.17.1