From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WPvGOpX+PGA3JAAAWB0awg (envelope-from ) for ; Mon, 01 Mar 2021 09:47:49 -0500 Received: by simark.ca (Postfix, from userid 112) id EDB0C1EF78; Mon, 1 Mar 2021 09:47:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7BC6F1E590 for ; Mon, 1 Mar 2021 09:47:49 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13D943939C33; Mon, 1 Mar 2021 14:47:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13D943939C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614610069; bh=khg8eTOL+BrgKfrGbyedHmoFTvwl9Kmf+e5nOpnaNCY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Vf1wurJl2uhbD4gXMdDi+nFMOoK+AO9EjRqR29MYxELd2KztB6TqPIgGZlIDrCmkG CCXzY+VbVT+VO18zFtN98MCo81fBPlWDiritPgKdU7C6aTlypIm1fBlVUzrsvFDQav QYTKTWiKTJA91kb1CtfLv0AdgRZlxE6NFl3FIwOE= Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2076.outbound.protection.outlook.com [40.107.102.76]) by sourceware.org (Postfix) with ESMTPS id E0B253938C22 for ; Mon, 1 Mar 2021 14:47:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E0B253938C22 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LSU99MegLL9xok5QqwvxYDCMz8FRQYSmjy+g17iVU+CKIq4yRuHOLb9He4kHK1Ju5ybIfq2tsSHsYPCWD9CTHZB7XwwvoWy/3RCTgTqK+O6gXF9ee6iRWC5CuTutBp0GOikAmED4wMagi+3e1TqN2EhwgVUx8dqdxaNfJW1R+Fi7ezvoD7kB1SJiEmIrWK9y9jGe45LMnTg4CVSuuVWVqTJpalYQe8VnZrh8/2pH36Aj2aiGllpr7zgfmtcjlsTt75tWLJADWD/6Swid1w5eglaYrDejBz1ppvQo5aByy0+DAem8n10TbVDK6dxEz+MnGVDqY5WTszFup9kJgLLzRw== 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=khg8eTOL+BrgKfrGbyedHmoFTvwl9Kmf+e5nOpnaNCY=; b=l9tSdLMkJ0PaB3h9fhXFVpEOKQZo5DljV7rGjralIUGO8fY6yQf04q5nCExSHDlNHFH65afRkc03Zv32U6xsfdBGao9Nh6DCkzO8/yL0nPCdtXSHwVJtk+i0MMftY6b7MZdjPqWavWt+Wgzhq5H5DK6B3RNuox0o0XmFRAIg2o2GTmgFYh6EmymT7lK7P/MiLUfv0/L4cG1IEZPu1yFUYB5YGpo7dqkQgZjzm8OgFX8rIEoGikjCAtexS61YtGU1mwiJOjhGq9bCc5b2pDl5qJ/3VSdhzyUfoIz11pBpy6a7k7yzSy443sE0U3CJX/q2TSzu66qbtbMdB8NBgpeD/A== 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 DM5PR12MB2342.namprd12.prod.outlook.com (2603:10b6:4:ba::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.28; Mon, 1 Mar 2021 14:47:44 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::31d8:f503:f7b2:f44%3]) with mapi id 15.20.3868.033; Mon, 1 Mar 2021 14:47:44 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 30/43] Add new computed struct value callback interface Date: Mon, 1 Mar 2021 14:46:07 +0000 Message-Id: <20210301144620.103016-31-Zoran.Zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301144620.103016-1-Zoran.Zaric@amd.com> References: <20210301144620.103016-1-Zoran.Zaric@amd.com> Content-Type: text/plain X-Originating-IP: [2a00:23c7:5a85:6801:b4ed:fe7b:8064:d4d] X-ClientProxiedBy: AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) 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:b4ed:fe7b:8064:d4d) by AM0PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:208:be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 14:47:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d546e055-438c-45b5-0c25-08d8dcc0e6b7 X-MS-TrafficTypeDiagnostic: DM5PR12MB2342: 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: APzke41kipWpU3J1DLubRB8h5OC8BPNtnMcRVWqafuLeXyZxvI/xlBH2NOPcdOr5CMTkiUIwlIjgDNBN/QFnKKYEVmaP/hggx0iGpWQwM7/JTvlDAQ/EAwQT+KL8s2lxJxqs/jgrf6YnuEdfdkqZZt+JjyKT4MfdmAVqHZlFyIObMMpaRVRn0yj1+nOPvwaJ2ryf1ByPOoNVp8vifhPsPKuKce0L1br3klw5eFbJ78E7w6kaYqC96JdyIL5zRdC+GGdkZ+R+mAtZZf0vd8M8P8gRQD+nO72tzp1jKwfbbviWu+2Rk8HyqnWQmR7oVvhNwHIHjdFk3nI5xsNjBDdmAXUpla24FxRNXle+AE+WRL9GCRlIittrgeoQ521QqbiLA3cjtkBT1lrfRS/btjZQUS7FpyQ2tcMLFRPnCgj1+H3QaomNRiyHRYwCOxpgAAMKdXKbydGjP25KGC3Wts4gIXrofsJHiD98QsJXUVL2lyAO3fETVtGq/fyqtW8WB+JR9DzjorsGw0+1NqjB6unP203TD+cKC+ZGCkSk6uVrQsvZxKqec3+MmzzpJ112Jgj1hhJh4l/aR8JLu+kkWa8jCg== 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)(366004)(346002)(396003)(376002)(39860400002)(136003)(6486002)(66476007)(4326008)(478600001)(66556008)(2906002)(66946007)(69590400012)(316002)(52116002)(6666004)(6916009)(2616005)(86362001)(16526019)(6512007)(36756003)(8676002)(8936002)(6506007)(5660300002)(186003)(1076003)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?t3efltXMHFEipaawMSxG/dd8WbjCVA7i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9FCdrTGZOJTJ5w4B5yKAJ4Cs2SSf5M3TFbJLiR5Dht6ilXRb18NBIM3/sB?= =?us-ascii?Q?Hc1X/UZ7qo9S727ku2YNJjuxgGacqxc+9F9xik6b7oxtU2XKudzaVIVAJufj?= =?us-ascii?Q?8RF7g4G4OQCVCeOPI7ySXS9A/CzliQvqZyvjPfNMXMv+uWfF/0+O46yNWqnp?= =?us-ascii?Q?qnZkE0RV8YpWpIx/S3ihEyxVH+zQFNN/Za4lOFGeoM0p21M20XR/9LzHP1gN?= =?us-ascii?Q?j7jA3lWEkZWAMnki5SLk2EKFEX0Q5znMjqoTn/fMRwssMMXPEoQMzJUlHBYX?= =?us-ascii?Q?1Sbcnx4XUUqo+H7JGtZLQt4F0R/qXVoqbfFEvI2+hV2k+3FiGb2Jua6IeasJ?= =?us-ascii?Q?2SGzKHfsSLXbtF5nDw0FVvvvaQjlvdOiS+A64P7dRi0WLxkKDEJpFY/ixzSi?= =?us-ascii?Q?LphwIcnQSNCLSRajVRbeG1eAZ+m97IfqM58OlIOQ9gx1+yFWVueMmZYXZlxV?= =?us-ascii?Q?lm0f8NmbF225znmwyN3swZfzjWAy?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d546e055-438c-45b5-0c25-08d8dcc0e6b7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 14:47:13.8750 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zL8mrr/ApR/7iZNpsJ4RKFOWZMe68R68n0o1n8e2GRLfogMG6N2PvnRtjhAyvyyTcNFvTtznL1GYtAi+iV3wuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2342 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: , From: Zoran Zaric via Gdb-patches Reply-To: Zoran Zaric Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" At this point all support is there to add a new callback interface for the computed struct value infrastructure. Original callback interface (piece closure) is going to be removed as soon as the switch to the new DWARF entry classes is done in the next few patches. gdb/ChangeLog: * dwarf2/expr.c (class computed_closure): New class. (closure_value_funcs): New closure callback structure. (copy_value_closure): New function. (free_value_closure): New function. (rw_closure_value): New function. (check_synthetic_pointer): New function. (write_closure_value): New function. (read_closure_value): New function. (indirect_closure_value): New function. (coerce_closure_ref): New function. --- gdb/dwarf2/expr.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 2550c59dc27..ec78a698e52 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -320,6 +320,91 @@ class dwarf_location; class dwarf_memory; class dwarf_value; +/* Closure callback functions. */ + +static void * +copy_value_closure (const struct value *v); + +static void +free_value_closure (struct value *v); + +static void +rw_closure_value (struct value *v, struct value *from); + +static int +check_synthetic_pointer (const struct value *value, LONGEST bit_offset, + int bit_length); + +static void +write_closure_value (struct value *to, struct value *from); + +static void +read_closure_value (struct value *v); + +static struct value * +indirect_closure_value (struct value *value); + +static struct value * +coerce_closure_ref (const struct value *value); + +/* Functions for accessing a variable described by DW_OP_piece, + DW_OP_bit_piece or DW_OP_implicit_pointer. */ + +static const struct lval_funcs closure_value_funcs = { + read_closure_value, + write_closure_value, + indirect_closure_value, + coerce_closure_ref, + check_synthetic_pointer, + copy_value_closure, + free_value_closure +}; + +/* Closure class that encapsulates a DWARF location description and a + frame information used when that location description was created. + Used for lval_computed value abstraction. */ + +class computed_closure : public refcounted_object +{ +public: + computed_closure (std::shared_ptr location, + struct frame_id frame_id) + : m_location (location), m_frame_id (frame_id) + {} + + computed_closure (std::shared_ptr location, + struct frame_info *frame) + : m_location (location), m_frame (frame) + {} + + const std::shared_ptr get_location () const + { + return m_location; + } + + struct frame_id get_frame_id () const + { + return m_frame_id; + } + + struct frame_info *get_frame () const + { + return m_frame; + } + +private: + /* Entry that this class encloses. */ + std::shared_ptr m_location; + + /* Frame ID context of the closure. */ + struct frame_id m_frame_id; + + /* In the case of frame expression evaluator the frame_id + is not safe to use because the frame itself is being built. + Only in these cases we set and use frame info directly. */ + struct frame_info *m_frame = NULL; +}; + /* Base class that describes entries found on a DWARF expression evaluation stack. */ @@ -1551,6 +1636,186 @@ dwarf_composite::indirect_implicit_ptr (struct frame_info *frame, return nullptr; } +static void * +copy_value_closure (const struct value *v) +{ + computed_closure *closure = ((computed_closure*) value_computed_closure (v)); + + if (closure == nullptr) + internal_error (__FILE__, __LINE__, _("invalid closure type")); + + closure->incref (); + return closure; +} + +static void +free_value_closure (struct value *v) +{ + computed_closure *closure = ((computed_closure*) value_computed_closure (v)); + + if (closure == nullptr) + internal_error (__FILE__, __LINE__, _("invalid closure type")); + + closure->decref (); + + if (closure->refcount () == 0) + delete closure; +} + +/* Read or write a closure value V. If FROM != NULL, operate in "write + mode": copy FROM into the closure comprising V. If FROM == NULL, + operate in "read mode": fetch the contents of the (lazy) value V by + composing it from its closure. */ + +static void +rw_closure_value (struct value *v, struct value *from) +{ + LONGEST bit_offset = 0, max_bit_size; + computed_closure *closure = (computed_closure*) value_computed_closure (v); + bool big_endian = type_byte_order (value_type (v)) == BFD_ENDIAN_BIG; + auto location = closure->get_location (); + + if (from == NULL) + { + if (value_type (v) != value_enclosing_type (v)) + internal_error (__FILE__, __LINE__, + _("Should not be able to create a lazy value with " + "an enclosing type")); + } + + ULONGEST bits_to_skip = HOST_CHAR_BIT * value_offset (v); + + /* If there are bits that don't complete a byte, count them in. */ + if (value_bitsize (v)) + { + bits_to_skip += HOST_CHAR_BIT * value_offset (value_parent (v)) + + value_bitpos (v); + if (from != NULL && big_endian) + { + /* Use the least significant bits of FROM. */ + max_bit_size = HOST_CHAR_BIT * TYPE_LENGTH (value_type (from)); + bit_offset = max_bit_size - value_bitsize (v); + } + else + max_bit_size = value_bitsize (v); + } + else + max_bit_size = HOST_CHAR_BIT * TYPE_LENGTH (value_type (v)); + + struct frame_info *frame = closure->get_frame (); + + if (frame == NULL) + frame = frame_find_by_id (closure->get_frame_id ()); + + if (from == NULL) + { + location->write_to_gdb_value (frame, v, bit_offset, bits_to_skip, + max_bit_size - bit_offset, 0); + } + else + { + location->read_from_gdb_value (frame, from, bit_offset, bits_to_skip, + max_bit_size - bit_offset, 0); + } +} + +static void +read_closure_value (struct value *v) +{ + rw_closure_value (v, NULL); +} + +static void +write_closure_value (struct value *to, struct value *from) +{ + rw_closure_value (to, from); +} + +/* An implementation of an lval_funcs method to see whether a value is + a synthetic pointer. */ + +static int +check_synthetic_pointer (const struct value *value, LONGEST bit_offset, + int bit_length) +{ + LONGEST total_bit_offset = bit_offset + HOST_CHAR_BIT * value_offset (value); + + if (value_bitsize (value)) + total_bit_offset += value_bitpos (value); + + computed_closure *closure + = (computed_closure *) value_computed_closure (value); + + return closure->get_location ()->is_implicit_ptr_at (total_bit_offset, + bit_length); +} + +/* An implementation of an lval_funcs method to indirect through a + pointer. This handles the synthetic pointer case when needed. */ + +static struct value * +indirect_closure_value (struct value *value) +{ + computed_closure *closure + = (computed_closure *) value_computed_closure (value); + + struct type *type = check_typedef (value_type (value)); + if (type->code () != TYPE_CODE_PTR) + return NULL; + + LONGEST bit_length = HOST_CHAR_BIT * TYPE_LENGTH (type); + LONGEST bit_offset = HOST_CHAR_BIT * value_offset (value); + + if (value_bitsize (value)) + bit_offset += value_bitpos (value); + + struct frame_info *frame = get_selected_frame (_("No frame selected.")); + + /* This is an offset requested by GDB, such as value subscripts. + However, due to how synthetic pointers are implemented, this is + always presented to us as a pointer type. This means we have to + sign-extend it manually as appropriate. Use raw + extract_signed_integer directly rather than value_as_address and + sign extend afterwards on architectures that would need it + (mostly everywhere except MIPS, which has signed addresses) as + the later would go through gdbarch_pointer_to_address and thus + return a CORE_ADDR with high bits set on architectures that + encode address spaces and other things in CORE_ADDR. */ + enum bfd_endian byte_order = gdbarch_byte_order (get_frame_arch (frame)); + LONGEST pointer_offset + = extract_signed_integer (value_contents (value), + TYPE_LENGTH (type), byte_order); + + return closure->get_location ()->indirect_implicit_ptr (frame, type, + pointer_offset, + bit_offset, bit_length); +} + +/* Implementation of the coerce_ref method of lval_funcs for synthetic C++ + references. */ + +static struct value * +coerce_closure_ref (const struct value *value) +{ + struct type *type = check_typedef (value_type (value)); + + if (value_bits_synthetic_pointer (value, value_embedded_offset (value), + TARGET_CHAR_BIT * TYPE_LENGTH (type))) + { + computed_closure *closure + = (computed_closure *) value_computed_closure (value); + struct frame_info *frame + = get_selected_frame (_("No frame selected.")); + + return closure->get_location ()->indirect_implicit_ptr (frame, type); + } + else + { + /* Else: not a synthetic reference; do nothing. */ + return NULL; + } +} + struct piece_closure { /* Reference count. */ -- 2.17.1