From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mFoSCpv+PGA3JAAAWB0awg (envelope-from ) for ; Mon, 01 Mar 2021 09:47:55 -0500 Received: by simark.ca (Postfix, from userid 112) id 267511EF7C; Mon, 1 Mar 2021 09:47:55 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 597E91E590 for ; Mon, 1 Mar 2021 09:47:53 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9DF23939C1F; Mon, 1 Mar 2021 14:47:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9DF23939C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614610072; bh=Kec+t1Jye6zz0z7dHu3Up+WxvlUzYnl55aWqSZCpNuM=; 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=Q+yObJLlbFnTnSL5aVbqKBT+B9fDeHDE3JBMaOKCNpOgYwhwrvEWZK35j0h336YXc ahENP9KXFHWva9nPg8DCjBpHjNIeQCWnHjyUGX4MiNJNzsfQR+Y+YhXDz/0w/nS8nU /jtjnttucr2uIxtNXYLcv2M0WI70EYiE6v1+4XZ0= 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 B72313938C0A for ; Mon, 1 Mar 2021 14:47:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B72313938C0A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dmS0DG9KDN58TdoceSn+saoLfnPKKKC8YJo9BvI3+2UdxX2z2LdxIpruBmU0+C9U4xbUBCvRwdsIktG3KpxZeYN0EYI8Ux2ZQ1q9lO9SGGPPZuOUKhxdHXuZ3cq0vR3YE4B7iKSWc11nTEr/RbD5vn2/rQv1+BOeKG7uwU7ucKahhlmBbTlidbODYT1mFqimHy11BcIPgfgIKXVu75L1RkiHYCnf99DVNBnNjuG0ZGxYOJKeuqwISt0PzJp78UhqkhCkUilEFmPJM+yy1eOtSN6pZWHv4jXWRAp/Hi7/iAMOL3epc6vYZIsYe8iymoUDq2JMk3cAvclzws53aHFh1Q== 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=Kec+t1Jye6zz0z7dHu3Up+WxvlUzYnl55aWqSZCpNuM=; b=KVVPFmaBz/AS8bHI/JIEmlA13peTWsef7jLpaRBa3GsKGQuF6ZpUlBPM0eNZ1Y7K+1eYvaJPbshFL9bmrb9725VuBeImpCVuIs/OQ9ZPjYVpWAhLYHUEnVnQsSUPuO68/k+TG4Qu8T/sgmNV5CyWAH3nAGCh4Z8F+WzwVHXhriI8/BRnF6juwjSOcOTf78qjMv3hpQXO5dMXJl4C31jL9N4pjEAp94Bk3WLaYf4by+3AQTLLRYAWUJt3RWqYuQv2/ca8C41aPorxLDG0Q7VL8P0jVxspSxek540YgvMC3W6rrLJXYNv4QPF4ia7MPQwz2mF9lDiQ7adq8eLH7z6s/g== 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 31/43] Add to_gdb_value method to DWARF entry class Date: Mon, 1 Mar 2021 14:46:08 +0000 Message-Id: <20210301144620.103016-32-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:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dfac165f-0645-451a-6738-08d8dcc0e771 X-MS-TrafficTypeDiagnostic: DM5PR12MB2342: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Tp3wfUiEPGbMdkfd7v/mqCPdwLe8tfTJHt3bSSxWvi6VhkMmUnJnRZ8kuO/E8y0BayCLpGHKaDfScuKEUaoh6BADmok8AUS5QyPybZjB3Quq75mBI40YRJ+TioatCajWfVxI/YYIpge7YRftGj+3sdTpwlJBVofLGz92r9wzp+hCN/Pst5MIf9GDfHQFjL2jZHBcCXA9Np/4TkejilsQemRmlVIPZipG5HQEX3RAw/WgnCxe/eXZPvj0hpF3tVxpSjNak04jlavr8YtSddM13Ok10hXfuwyF+O4Q8fWK5fwM9Z+CDU21uB6/6Q9qyw5RR0NY0DCNIYLFQfV8rqtfhwCYh+eFIDI1CCnaFyBp8dAYHoUb2e3OkcF10ounuhW9TehLrfACfqPjqKHe20hmFC7vNhFa5fEwfONexgWUNGWxS0xeNDXtKJ4zKY+nXbaUxy1kHUOBZILlCDhuUUdGiM/GjdQ/eyMEMnlgIcbwv/6MTj0opfkV9IAg12cxAfo5A3mr2h4Kd1q89Hc09Vq6CoDaG3o3YuJ4YCiHcioxDryVXgL3in3kRQDg6nerQlyG4T3RelG0i7UhgzllEPHM/g== 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)(30864003)(5660300002)(186003)(1076003)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ZYFrTh0LiEkSFxIDYS44kYqD5voMsu9NYSO6R+4DcgO9tIWTv+s6GQiWn4J8?= =?us-ascii?Q?sxhUMqsOSo2qy3whVn3yaaeUZEUe/OQVsbtpxfEMpJazjyMeNljR0+myyvux?= =?us-ascii?Q?NaOAKihJ3i/+IEBHsRaFTGk8vZG2Y+MKTDOncmPDTAPzhJA7O3lpJQf+xn1B?= =?us-ascii?Q?O2ztywq9QRHZRxtHgJmiOoyEfpjwQkgWgCAXazC3G9o06OgvaCR4FW2qDY4u?= =?us-ascii?Q?v6ad5tjNswtgwYsUc5dlqRPgq3xUaXUFybA5MNTqiHY41ylBbYQw4z71Oohw?= =?us-ascii?Q?JaJtJqnEotoR4wCiroNW1lgTfQw1XzJpzQwN20M8rdL8JQobE9DU6v+PpYhu?= =?us-ascii?Q?gidftp8PgJerS/Zdlj1SZNUdpIN5u8Qfmm7XeFtqmPgWOpxqzsrTtzBaSOby?= =?us-ascii?Q?rvtlPj0fOG1ZgeCAB9tQaCio5gI/CW5hh7bvr7BIfoxLnPjjr4BH5g75GFp+?= =?us-ascii?Q?DcP+8nbH9wseOeUvMbeCZ1lY5/yMa8/h3mxWwOpS/wLxnoXGXJYs3tdxu7D8?= =?us-ascii?Q?7RAlTGwJHHu8bMqW6Ug556lV6unwGSXJgFbYIsW7j6UeRHWatRovHXvT+FPv?= =?us-ascii?Q?FX8N9nqm80Y66gMjfiP+p7beibfB2zTXuoXeKd1q0CE8QvaCSlHsSNuRjv9+?= =?us-ascii?Q?KNcPkxyHKcZ2+oec/i+Uj1RnYPf3IPXteTdb4Zz8TLNU/WSyYMySb6ZSndxC?= =?us-ascii?Q?ZL6ERrWMsLAb2K5x4BHGvUz6Gi/IQdA6/W3QvC8wO3EN81p4ju+GCGT03ra9?= =?us-ascii?Q?QRRrGA5RRyge+mWfM6qTY0ZbsSd9z0WMw/iBnfOp+2cHCJHiiEL9gAWgvKDO?= =?us-ascii?Q?tXlXa0ygOa08eZ4GW8Yif5DcCmQJ4g91jGtnXfPb/1J3C0KJF+wX2M2QJs64?= =?us-ascii?Q?DFpedIfE/N2F7g7YjqPEZTXdK+h//3G6hKJvvLSqFHiOyMLc3hdCLq8sZeEy?= =?us-ascii?Q?r+0F80NSD107szjrRkXkr4lyr46Q4QEk1UHwEUbXQb1PhRw8AFC7WAQSTDe4?= =?us-ascii?Q?CZ95fY2HzP5naOFVsc/nREcWka2IY+MiZ0XXO907KgMvbOh+NLHjMrUEBuh9?= =?us-ascii?Q?42hnUF59LGV2n5SQo7PSk4uHYzgChTj07HIJjHq3E4a3RicyDOIOjSq8oIbM?= =?us-ascii?Q?4bg0fSmJAFe1X+UbWzD0PTaOQW5fWvocrqLX8NvMtK741HlHA1WI0WizPYSI?= =?us-ascii?Q?SVT5cXKGfrJOoSr0qGzY0MEiHGHIG72UzyYbSPN95LNw5eZxGFaQbGEWRrLS?= =?us-ascii?Q?g2JGq9STORrcWjq68ozZ5aBJhZppKpq6LmBDCD+NrVGYrLCFPFti/heizXA7?= =?us-ascii?Q?Y8LtapEPA3bpsnLyJAhFTTLrlTYOgVxeoMhhnH6X94s8xVszdQsOH8Vay4nt?= =?us-ascii?Q?XYzKboUf6vsjKANARanLPaYxW0CK?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfac165f-0645-451a-6738-08d8dcc0e771 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:15.0224 (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: 306248nAKShsJy7BaLzRcEBbMqVMep4i5VvMpB5x88jpWSTDgW4891VclSlPQ5GKWDNSYgbAmfs5mUv1WEADxg== 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" The result of the DWARF expression evaluation is expected to be in a format of a struct value object. This means that a new to_gdb_value method is needed for all classes that derive from dwarf_entry class. In the case of the dwarf_value class, it is usefull to have an even more simplified version of this method (convert_to_gdb_value) that does not require the evaluation frame context or any subobj information. This method will be used even more in the following patch. gdb/ChangeLog: * dwarf2/expr.c (dwarf_entry::to_gdb_value): New method. (dwarf_location::to_gdb_value): New method. (dwarf_value::convert_to_gdb_value): New method. (dwarf_value::to_gdb_value): New method. (dwarf_undefined::to_gdb_value): New method. (dwarf_memory::to_gdb_value): New method. (dwarf_register::to_gdb_value): New method. (dwarf_implicit::to_gdb_value): New method. (dwarf_implicit_pointer::to_gdb_value): New method. (dwarf_composite::to_gdb_value): New method. --- gdb/dwarf2/expr.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index ec78a698e52..a2bdee95725 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -425,6 +425,16 @@ class dwarf_entry : public std::enable_shared_from_this desired type of the returned DWARF value if it already doesnt have one. */ virtual std::shared_ptr to_value (struct type *type) = 0; + + /* Convert DWARF entry to the matching struct value representation + of the given TYPE type in a given FRAME. SUBOBJ_TYPE information + if specified, will be used for more precise description of the + source variable type information. Where SUBOBJ_OFFSET defines an + offset into the DWARF entry contents. */ + virtual struct value *to_gdb_value (struct frame_info *frame, + struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const = 0; }; dwarf_entry::~dwarf_entry () = default; @@ -744,6 +754,12 @@ class dwarf_value : public dwarf_entry return unpack_long (m_type, m_contents.get ()); } + /* Convert DWARF value to the matching struct value representation + of the given TYPE type. Where offset defines an offset into the + DWARF value contents. */ + struct value *convert_to_gdb_value (struct type *type, + LONGEST offset = 0) const; + /* Convert DWARF value into a DWARF memory location description. ARCH defines an architecture of the location described. */ std::shared_ptr to_location (struct gdbarch *arch) override; @@ -756,6 +772,10 @@ class dwarf_value : public dwarf_entry return std::dynamic_pointer_cast (shared_from_this ()); } + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* Value contents as a stream of bytes in target byte order. */ gdb::unique_xmalloc_ptr m_contents; @@ -764,6 +784,20 @@ class dwarf_value : public dwarf_entry struct type *m_type; }; +struct value * +dwarf_value::convert_to_gdb_value (struct type *type, LONGEST offset) const +{ + size_t type_len = TYPE_LENGTH (type); + + if (offset + type_len > TYPE_LENGTH (m_type)) + invalid_synthetic_pointer (); + + struct value *retval = allocate_value (type); + memcpy (value_contents_raw (retval), + m_contents.get () + offset, type_len); + return retval; +} + std::shared_ptr dwarf_value::to_location (struct gdbarch *arch) { @@ -779,6 +813,17 @@ dwarf_value::to_location (struct gdbarch *arch) return std::dynamic_pointer_cast (memory); } +struct value * +dwarf_value::to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + if (subobj_type == nullptr) + subobj_type = type; + + return convert_to_gdb_value (subobj_type, subobj_offset); +} + /* Undefined location description entry. This is a special location description type that describes the location description that is not known. */ @@ -807,6 +852,20 @@ class dwarf_undefined : public dwarf_location *unavailable = 0; *optimized = 1; } + + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override + { + struct value *retval = allocate_value (subobj_type); + + if (subobj_type == nullptr) + subobj_type = type; + + mark_value_bytes_optimized_out (retval, subobj_offset, + TYPE_LENGTH (subobj_type)); + return retval; + } }; class dwarf_memory : public dwarf_location @@ -839,6 +898,10 @@ class dwarf_memory : public dwarf_location (struct frame_info *frame, const struct property_addr_info *addr_info, struct type *type, size_t size = 0) const override; + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* True if the location belongs to a stack memory region. */ bool m_stack; @@ -1012,6 +1075,27 @@ dwarf_memory::deref (struct frame_info *frame, return std::make_shared (read_buf.data (), type); } +struct value * +dwarf_memory::to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + if (subobj_type == nullptr) + subobj_type = type; + + struct type *ptr_type = builtin_type (m_arch)->builtin_data_ptr; + CORE_ADDR address = m_offset; + + if (subobj_type->code () == TYPE_CODE_FUNC + || subobj_type->code () == TYPE_CODE_METHOD) + ptr_type = builtin_type (m_arch)->builtin_func_ptr; + + address = value_as_address (value_from_pointer (ptr_type, address)); + struct value *retval = value_at_lazy (subobj_type, address + subobj_offset); + set_value_stack (retval, m_stack); + return retval; +} + /* Register location description entry. */ class dwarf_register : public dwarf_location @@ -1032,6 +1116,10 @@ class dwarf_register : public dwarf_location size_t location_bit_limit, bool big_endian, int *optimized, int *unavailable) const override; + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* DWARF register number. */ unsigned int m_regnum; @@ -1123,6 +1211,50 @@ dwarf_register::write (struct frame_info *frame, const gdb_byte *buf, temp_buf, optimized, unavailable); } +struct value * +dwarf_register::to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + int gdb_regnum = dwarf_reg_to_regnum_or_error (m_arch, m_regnum); + + if (subobj_type == nullptr) + subobj_type = type; + + if (frame == NULL) + internal_error (__FILE__, __LINE__, _("invalid frame information")); + + /* Construct the value. */ + struct value *retval + = gdbarch_value_from_register (m_arch, type, + gdb_regnum, get_frame_id (frame)); + LONGEST retval_offset = value_offset (retval); + + if (type_byte_order (type) == BFD_ENDIAN_BIG + && TYPE_LENGTH (type) + m_offset < retval_offset) + /* Big-endian, and we want less than full size. */ + set_value_offset (retval, retval_offset - m_offset); + else + set_value_offset (retval, retval_offset + m_offset); + + /* Get the data. */ + read_frame_register_value (retval, frame); + + if (value_optimized_out (retval)) + { + /* This means the register has undefined value / was not saved. + As we're computing the location of some variable etc. in the + program, not a value for inspecting a register ($pc, $sp, etc.), + return a generic optimized out value instead, so that we show + instead of . */ + struct value *temp = allocate_value (subobj_type); + value_contents_copy (temp, 0, retval, 0, TYPE_LENGTH (subobj_type)); + retval = temp; + } + + return retval; +} + /* Implicit location description entry. Describes a location description not found on the target but instead saved in a gdb-allocated buffer. */ @@ -1155,6 +1287,10 @@ class dwarf_implicit : public dwarf_location *unavailable = 0; } + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* Implicit location contents as a stream of bytes in target byte-order. */ gdb::unique_xmalloc_ptr m_contents; @@ -1205,6 +1341,36 @@ dwarf_implicit::read (struct frame_info *frame, gdb_byte *buf, total_bits_to_skip, bit_size, big_endian); } +struct value * +dwarf_implicit::to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + if (subobj_type == nullptr) + subobj_type = type; + + size_t subtype_len = TYPE_LENGTH (subobj_type); + size_t type_len = TYPE_LENGTH (type); + + /* To be compatible with expected error output of the existing + tests, the invalid synthetic pointer is not reported for + DW_OP_implicit_value operation. */ + if (subobj_offset + subtype_len > type_len + && m_byte_order != BFD_ENDIAN_UNKNOWN) + invalid_synthetic_pointer (); + + struct value *retval = allocate_value (subobj_type); + + /* The given offset is relative to the actual object. */ + if (m_byte_order == BFD_ENDIAN_BIG) + subobj_offset += m_size - type_len; + + memcpy ((void *)value_contents_raw (retval), + (void *)(m_contents.get () + subobj_offset), subtype_len); + + return retval; +} + /* Implicit pointer location description entry. */ class dwarf_implicit_pointer : public dwarf_location @@ -1260,6 +1426,10 @@ class dwarf_implicit_pointer : public dwarf_location LONGEST bit_offset = 0, int bit_length = 0) const override; + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* Per object file data of the implicit pointer. */ dwarf2_per_objfile *m_per_objfile; @@ -1323,6 +1493,32 @@ dwarf_implicit_pointer::indirect_implicit_ptr (struct frame_info *frame, m_per_cu, m_per_objfile, frame, type); } +struct value * +dwarf_implicit_pointer::to_gdb_value (struct frame_info *frame, + struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + if (subobj_type == nullptr) + subobj_type = type; + + /* Complain if the expression is larger than the size of the + outer type. */ + if (m_addr_size > HOST_CHAR_BIT * TYPE_LENGTH (type)) + invalid_synthetic_pointer (); + + computed_closure *closure + = new computed_closure (std::make_shared (*this), + get_frame_id (frame)); + closure->incref (); + + struct value *retval + = allocate_computed_value (subobj_type, &closure_value_funcs, closure); + set_value_offset (retval, subobj_offset); + + return retval; +} + /* Composite location description entry. */ class dwarf_composite : public dwarf_location @@ -1366,6 +1562,10 @@ class dwarf_composite : public dwarf_location LONGEST bit_offset = 0, int bit_length = 0) const override; + struct value *to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const override; + private: /* Composite piece that contains a piece location description and it's size. */ @@ -1636,6 +1836,45 @@ dwarf_composite::indirect_implicit_ptr (struct frame_info *frame, return nullptr; } +struct value * +dwarf_composite::to_gdb_value (struct frame_info *frame, struct type *type, + struct type *subobj_type, + LONGEST subobj_offset) const +{ + size_t pieces_num = m_pieces.size (); + ULONGEST bit_size = 0; + + if (subobj_type == nullptr) + subobj_type = type; + + for (unsigned int i = 0; i < pieces_num; i++) + bit_size += m_pieces[i].m_size; + + /* Complain if the expression is larger than the size of the + outer type. */ + if (bit_size > HOST_CHAR_BIT * TYPE_LENGTH (type)) + invalid_synthetic_pointer (); + + computed_closure *closure; + + /* If compilation unit information is not available + we are in a CFI context. */ + if (m_per_cu == NULL) + closure = new computed_closure (std::make_shared (*this), + frame); + else + closure = new computed_closure (std::make_shared (*this), + get_frame_id (frame)); + + closure->incref (); + + struct value *retval + = allocate_computed_value (subobj_type, &closure_value_funcs, closure); + set_value_offset (retval, subobj_offset); + + return retval; +} + static void * copy_value_closure (const struct value *v) { -- 2.17.1