From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2049.outbound.protection.outlook.com [40.107.244.49]) by sourceware.org (Postfix) with ESMTPS id 3152F393C85C for ; Mon, 7 Dec 2020 19:01:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3152F393C85C ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ypdzf8d5Dk7wpsL6F2UJ+ts1YvEyrbIa/zP2Yhc8dv6SjWITdE4jvWDXZipGpV65Hxm292vRYQtHfu28SA4gy66TB6+LTI9yIpEgMeK3fvxq39W/F/TuopZJl0u/NXku6DRM/5tUlA7zIO/P0yTberqzeI5lga36upEiXYrZlRgOkOjzrG9gBBCe8VU6Pqq61ZUvz+W/JJNVuqt93w0S9wQ4LLJfmHRobM++EDcyMpDHbO8ZCclHM0a/1IEbFaRmYfFiRP+hCjOdt6nsvGjvbNAn1sPUG7ux8tCCE/kDyz01gxQCk9U7AIPDlFeb2hpHTSLbWfnzJknB2bzxGfXXMw== 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=QPBbRTU7m4yNmIjPFVGP8QJ8jVi6VXQQ9MVg7N9PUdM=; b=fQkfOQsofIwsUsrSi2AB9951pqjGnYrbH8P86ZvrtNQC625J/isOFcrBZ/45QI3BiFbDlJbwR8UqSfFF75AC6+pypNM0Fb62ula9is+elZdP5e8NVA713CsU9CIZp8Coapdg8y3aVlwgFx5y8QzR29ozte0h7lAu+GSbEYPups3g7NQTCVHFK+7dCB6DLZfkgxCr2SQZ6JRisP7h49zwnRxtuaSiVKxrGIKZcx31+aJgsoZoLNkQ3iyTgmRyZnHU454TrwWGClkn4Lel1pnkQet21C6GN3pxdF5tj8XQc3wEtoSUbS94cLeXZdWGSSpjqmCj3Xst9lSiJAM8VyVz0Q== 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:04 +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:04 +0000 From: Zoran Zaric To: gdb-patches@sourceware.org Cc: Zoran Zaric Subject: [PATCH 11/30] Merge evaluate_for_locexpr_baton evaluator Date: Mon, 7 Dec 2020 19:00:12 +0000 Message-Id: <20201207190031.13341-12-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:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: acbc3f08-7e03-4e89-b305-08d89ae27289 X-MS-TrafficTypeDiagnostic: DM6PR12MB4561: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0wfpM4VoPlqnv+oexVMLxN/UUi4AWbhSgAwWtab+fSwa1sgmnNeybuT6OtaDR14SUmdgXMRTAy7BCZU1AOLhqBEo+3SjB/Qd/SPPVIB8Y+paJTNkWNhpI0Uk7KtRNPkmKFCxp+qeU7jHpTneKARlgHytvaReluUN+bn1zZ9Szr5CgrjDoNrHjVOKjRwBIbnjJhZvZA4sHYQ1LimodOxWAd+87YqhtUr7vPtt9gvPuyDzp3fNqqsvid40ITuPGlzC3ZVLolvhzSrb6/27HlTKiprgpXFhia8kzSLYtAoYVnniFcDVJO/BRX6JCli/AcY2L3iWyFB5AsA8PvnXUIfQIVUnLmN+fPEFbTkw+T/M6A6jS7JcID1NAUrRmOX1dLy8 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)(6486002)(16526019)(2616005)(66946007)(66476007)(66556008)(6916009)(5660300002)(186003)(8936002)(478600001)(6666004)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?nbcVAYEJGojZQGtoxitGmBxV9YChIeMho3X5sIZg1SLypIXj3ltiKRxiEHxm?= =?us-ascii?Q?5lEOK2FqMc+89Tvf2fH/Cq+ki0GVGokxx/+mfPIePHae1b0SNp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+kmL+GM6gnKcjxjLEgWdUWdSrdbjlYaa8XNjwM+LHhArsR0?= =?us-ascii?Q?U/iNCH+Yzfbbyzd4s1QT9r17dNcxe0APo5A2FsKpS1Mlk5B5vfi3x1g+UUzG?= =?us-ascii?Q?BOOlJYzl?= 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:04.7218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: acbc3f08-7e03-4e89-b305-08d89ae27289 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LwJUha1xtj/Hxm08x5GXa1Fp9vZ/HcR1KB/DJfu5WGMsUzpDkJZ1zvLzeJGdvMaOszMbV4NJ3C6Zf/IUcYlFEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4561 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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:14 -0000 From: Zoran Zaric The evaluate_for_locexpr_baton is the last derived class from the dwarf_expr_context class. It's purpose is to support the passed in buffer functionality. Although, it is not really necessary to merge this class with it's base class, doing that simplifies new expression evaluator design. Considering that this functionality is going around the DWARF standard, it is also reasonable to expect that with a new evaluator design and extending the push object address functionality to accept any location description, there will be no need to support passed in buffers. Alternatively, it would also makes sense to abstract the interaction between the evaluator and a given resource in the near future. The passed in buffer would then be a specialization of that abstraction. gdb/ChangeLog: * dwarf2/expr.c (dwarf_expr_context::read_mem): Merge with evaluate_for_locexpr_baton implementation. * dwarf2/loc.c (class evaluate_for_locexpr_baton): Remove class. (evaluate_for_locexpr_baton::read_mem): Move to dwarf_expr_context. (dwarf2_locexpr_baton_eval): Instantiate dwarf_expr_context instead of evaluate_for_locexpr_baton class. --- gdb/dwarf2/expr.c | 19 +++++++++++++++++-- gdb/dwarf2/expr.h | 13 +++---------- gdb/dwarf2/loc.c | 45 ++------------------------------------------- 3 files changed, 22 insertions(+), 55 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index a7bc084755..9662f83d2e 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -256,6 +256,18 @@ void dwarf_expr_context::read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length) { + if (length == 0) + return; + + /* Prefer the passed-in memory, if it exists. */ + CORE_ADDR offset = addr - obj_address; + + if (offset < data_view.size () && offset + length <= data_view.size ()) + { + memcpy (buf, data_view.data (), length); + return; + } + read_memory (addr, buf, length); } @@ -1580,8 +1592,11 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr, case DW_OP_push_object_address: /* Return the address of the object we are currently observing. */ - result = this->get_object_address (); - result_val = value_from_ulongest (address_type, result); + if (this->data_view.data () == nullptr + && this->obj_address == 0) + error (_("Location address is not set.")); + + result_val = value_from_ulongest (address_type, this->obj_address); break; default: diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h index a04a67c0f8..2fb65822bd 100644 --- a/gdb/dwarf2/expr.h +++ b/gdb/dwarf2/expr.h @@ -195,16 +195,8 @@ struct dwarf_expr_context /* Object address used for the evaluation. */ CORE_ADDR obj_address; - /* Read LENGTH bytes at ADDR into BUF. */ - virtual void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length); - - /* Return the `object address' for DW_OP_push_object_address. */ - virtual CORE_ADDR get_object_address () - { - if (obj_address == 0) - error (_("Location address is not set.")); - return obj_address; - } + /* The data that was passed in. */ + gdb::array_view data_view; private: @@ -239,6 +231,7 @@ struct dwarf_expr_context void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind, union call_site_parameter_u kind_u, int deref_size); + void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length); }; /* Return the value of register number REG (a DWARF register number), diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 2e353f1b31..b9fe5c2f81 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -2221,45 +2221,6 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame, per_objfile, NULL, 0); } -/* A specialization of dwarf_expr_context that is used by - dwarf2_locexpr_baton_eval. This subclass exists to handle the case - where a caller of dwarf2_locexpr_baton_eval passes in some data, - but with the address being 0. In this situation, we arrange for - memory reads to come from the passed-in buffer. */ - -struct evaluate_for_locexpr_baton : public dwarf_expr_context -{ - evaluate_for_locexpr_baton (dwarf2_per_objfile *per_objfile) - : dwarf_expr_context (per_objfile) - {} - - /* The data that was passed in. */ - gdb::array_view data_view; - - CORE_ADDR get_object_address () override - { - if (data_view.data () == nullptr && obj_address == 0) - error (_("Location address is not set.")); - return obj_address; - } - - void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override - { - if (len == 0) - return; - - /* Prefer the passed-in memory, if it exists. */ - CORE_ADDR offset = addr - obj_address; - if (offset < data_view.size () && offset + len <= data_view.size ()) - { - memcpy (buf, data_view.data (), len); - return; - } - - read_memory (addr, buf, len); - } -}; - /* Evaluates a dwarf expression and stores the result in VAL, expecting that the dwarf expression only produces a single CORE_ADDR. FRAME is the frame in which the expression is @@ -2283,13 +2244,11 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, return 0; dwarf2_per_objfile *per_objfile = dlbaton->per_objfile; - evaluate_for_locexpr_baton ctx (per_objfile); + dwarf_expr_context ctx (per_objfile); ctx.frame = frame; ctx.per_cu = dlbaton->per_cu; - if (addr_stack == nullptr) - ctx.obj_address = 0; - else + if (addr_stack != nullptr) { ctx.obj_address = addr_stack->addr; ctx.data_view = addr_stack->valaddr; -- 2.17.1