From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id enBFJHJLiWD0IwAAWB0awg (envelope-from ) for ; Wed, 28 Apr 2021 07:48:02 -0400 Received: by simark.ca (Postfix, from userid 112) id 853DD1F11C; Wed, 28 Apr 2021 07:48:02 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 E55041E01F for ; Wed, 28 Apr 2021 07:48:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91C0B3970817; Wed, 28 Apr 2021 11:48:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91C0B3970817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619610480; bh=OFVr05Ajvwdt6W0tLLaP3NKawYWG7zMkg9akMj6xCJA=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qieK4cwrLJJPZEEKv1dGJ74kdPVY06TN5tCwP577IkHV5Elp5xpHD3kOnMAQGtnXX cDC+2KW5lHxeRPaEhry8ko9JY0XRjiUod/JQzp4MeTm67taL1o4SlTUdxWOQp5g2b1 zr3NsPiIHvH3yQnz9f5gBhz+BObzpR11WL7MCKqg= Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by sourceware.org (Postfix) with ESMTPS id E02C03939C01 for ; Wed, 28 Apr 2021 11:47:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E02C03939C01 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eA4GRst61BUM3ttOzYOGGbhItj5i1DDYDMOWrWKPIUFw7NtMkSKq8cgyhBZRtW6EwybLzrCnDi2npkjCE3pjoPJVghMToNYh06kpCLJSzvyTXVCbwShZF4vSG+8DhhKCaIlD1LY77L9ZLtFC6QHgvVw3robxWd71muKA81k9KE41323q1jV/PTMMX2V8wjKqi/J8HhG1WWC5l3+c9IXGJka4WpmQU2RP7yJNv1hB6yc3BqGLdi7CIaQNID1EN7We3JQGhu5liqaqlIsKSbHfZDcvDa4TMmTHYUHYHVwoLnvZfJgObw/3dLPtHNj+Dszl8qSppZMMtOgPskPBGrpG6Q== 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=OFVr05Ajvwdt6W0tLLaP3NKawYWG7zMkg9akMj6xCJA=; b=Xn5aPBxCs5+EqTIFhdQ+zVCwiAmixi0ptCW/vcxxhejZqkiiNHTiTFcoWrM4kC4VoaIvaNQKu2Whe49KhoLz3kQyUetsWCWal/VJLcDMbz0cRYA6uGyVv+DGJ2Evx+6srkech1+iSzT1GTVqa9burEG/IcniIqc+Hgp+HvWBMt/rCpPIGz69GY7YE3RH0SsB8BmLIX37v1Nk+Cf+Wdxr+F6XAXOM1XgMIfsLAmY91dOE5hiZsxtnPWRCIAuhV9eOI6krU5YntqZL24gBXyWNrN1aq8C46NHwmSC5ekBx5Lxs0CVWs/KbZYLhclqurAVyy/njY2g5bwxg8+lsBuO7sA== 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 DM6PR12MB3195.namprd12.prod.outlook.com (2603:10b6:5:183::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.25; Wed, 28 Apr 2021 11:47:55 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::49d0:1ee5:47ef:e0e5]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::49d0:1ee5:47ef:e0e5%7]) with mapi id 15.20.4065.023; Wed, 28 Apr 2021 11:47:55 +0000 Subject: Re: [PATCH 15/43] Make DWARF evaluator return a single struct value To: Simon Marchi , gdb-patches@sourceware.org References: <20210301144620.103016-1-Zoran.Zaric@amd.com> <20210301144620.103016-16-Zoran.Zaric@amd.com> Message-ID: <320722e8-79e8-1890-bda8-bccf57ad52a3@amd.com> Date: Wed, 28 Apr 2021 12:47:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [2a00:23c7:5a85:6801:f5b0:44e8:2b3e:76c1] X-ClientProxiedBy: LO3P265CA0012.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:bb::17) To DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [IPv6:2a00:23c7:5a85:6801:f5b0:44e8:2b3e:76c1] (2a00:23c7:5a85:6801:f5b0:44e8:2b3e:76c1) by LO3P265CA0012.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:bb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.25 via Frontend Transport; Wed, 28 Apr 2021 11:47:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef758c80-728d-454a-2a43-08d90a3b75f0 X-MS-TrafficTypeDiagnostic: DM6PR12MB3195: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bZB4lyOJy6WwKmzJWOgkAgpG0qcVnWzmapnTX2UtW/A+61/8cmlRE55Y3mCxqU+LtkT1Zdf3gOLYiPWAD/UbAX0+RMKnjVBTZTFXsWpma3NTOPaSjnxhnDn/6d9Uu+L/dxz76FN41ZgSbkY26rb4S7kNvpvwhqxde2Ut8qvWI23ibWUBnPy6I1iSpj1hAdArTiKSX6cSf8bMHINZ6mFhWmzJyOf8aFIvKiuEqfUDRko8nXy+2U5Wz2/AdSLpc/oKkTUY0C8LxuvM5lNik+9xrrpDW4JAurszszcoZN1b+nfS9+KPeSHHUO6/tdL8BmMx/qkCjpAUuqWsBAGN80Djv2o+etQMHVzklPIP1Q3iuMbeT5bpcDapfAHbgLUTHyQE2wce5Ra+8jaTFfJO/X+J4KDePHFffQ6anImNba2U6E3hlTLbMJ69rHbdtUJE4GOrd2LgQ2Jr8a1PzXSywqZGTcL+qM9MNls0+eEv4OcFT59i1R+7kl3qZvTo7aFk1eqcpb8aOobecY/lKGI4OLyRkg8S5CBWb+QiCp0P96//sGz6WvVGDiI7IlYsXqu3qV8/GWUFue66jwh7pAPvcbsZHlualFKVEOrnu3NEw/qEYpNMdCYEAMfx4IDyXMWXjkTkfzBK/j/+Uy2ltwMPWxV5+XUh/DZJy9jwP86y7NViBFerL873COovpDC7q4Y2SfMz 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)(39840400004)(366004)(376002)(346002)(136003)(396003)(53546011)(8676002)(8936002)(38100700002)(31696002)(2616005)(6666004)(66946007)(2906002)(52116002)(5660300002)(86362001)(30864003)(6486002)(66476007)(36756003)(478600001)(186003)(31686004)(316002)(16526019)(83380400001)(66556008)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?TDVEQnFBKzhjYitSSTRQTEl2K0xDdVNSdnd6TU5LRUQwWHJkWFRUZkRKTHBs?= =?utf-8?B?dlkwVHBmdnFWbWZEaGk5bitFT3dmTm9rVmZlSXFPdUJFN0ErdkxET3VDSTlM?= =?utf-8?B?TmRZb28xTHJ2WHZwWEVOSXhoSkxJbmN3d3dyQWYxUHBxQU4zNWUrQndEbGx4?= =?utf-8?B?Z1Rubkc1M3R3ZDkwamxZUGRWbC9HUEtZay9ZWkpSNEMxNHR5THN0T3JNRS8x?= =?utf-8?B?Sk9kV1BVOHYvanoyNkhFQUc3WVk2d3NOOUVCSW45ZkNSOUxvYy9peUs5OTRj?= =?utf-8?B?ekR6U1NDR24vVEV0MVp1Q2hTWXd5eVdyRHNpVUIwbW82a2ptdlJVWlgrMVlQ?= =?utf-8?B?U0RkbnZXMTRlL05CYnJHMFkvR3ZxOG9MYi9ySHZZR2tSWHdGYzduY1ptSllZ?= =?utf-8?B?N3hkV0JTd29ScExvOWtwTWdWQ3BYSkpPZE1hVjdNckt4Sll1VjFRdVFLNEhL?= =?utf-8?B?TlZneXgrWm1OSzBQd04yWnRnL0h6NzRZMTBuSWhvcmZLcnRPVmtyYmtIMDB4?= =?utf-8?B?RUd4RHNESnJTWklsWTc4bmpvUDB4bzkvMXhneU9FN2N5RGhNR0luNGVEOGZT?= =?utf-8?B?NlYzMTZPZUdORVJYZEdHTy85c3RwRWJQa1p4dkhsMVFEWW1oYm9nQzBCR1Zs?= =?utf-8?B?VGw0R29MNkFEU1JVQXJoSktrQm5oVSs3dVJWc3VjalVCZkNVOWRvSjZwWnUr?= =?utf-8?B?dndKdXJiSDFEMFFJd25GSGt0L1EvNE1wc1JURDVVZGk1UlhrZjEvMzNvbjBm?= =?utf-8?B?d1craHoyamdNZXYxb25LaFJjMmtDMDIrQnZ4Q05FTC9rNFFDZ2NlWlJ5RnFX?= =?utf-8?B?dEh5cXZJSGVRMDdmU284Szl1VUk0dU4weWV3aDVycDlmS3l4bFhkaGpJb3E0?= =?utf-8?B?NnZUVmJ0NkRqQWI4di80eXdEQTZtaGliZHRRWVcyWmpoakdQWlpkSG1OYmdW?= =?utf-8?B?R1B6aGw3dFR0OS9OVjVQblpNS0VvTHpvUm95cVI1Nkc1NnR0bG9jSTJENXpV?= =?utf-8?B?eC9NaW1QTlM2QWcxcFdQSmNTQ1BMSWhXUGk1SUtzYkw3M1pGQWV4TC9xMHdl?= =?utf-8?B?eXJnQUZXZ0tLSmppVlVJWTFwNXluK05vcGhuNzhrWEdhNGVzUEZBRmlCQi9X?= =?utf-8?B?eG5hanE4alFKUFBGSXZQTkdYNmtXWFVJVEw5Yk1yWU9YZnJWalpvN05EWVB4?= =?utf-8?B?cU8zZnZwbVpLN2dMMi8wdFAwQ2F3SmdPeVVsUFZVUW1pT0sySHd6VUU5SkFU?= =?utf-8?B?ZHk0S1BWZW5MUU1DaDcxSThGZm4wYUxUcFh1LzQrUWVRVW1MVnBJWlYzSFpJ?= =?utf-8?B?ZXdiQnQ3QlU5cE5PTWxlSFpVcjBISVgwYVB2dmJFSStOWHhWNHJBb1BOOUFD?= =?utf-8?B?UW5NYmdXa0ovYTVUaVVhUVo3bTlBUzNkR2tlMGpkNkMvSWoxaER0ZU9XOEYy?= =?utf-8?B?dDBVUGJ3clVaNEl3c0MxbzVMbGdJYkd3Yk1nRUdXRnFGMi95VTcwNmxDVzNt?= =?utf-8?B?cUU5cUpLVi9FNEVla1V6MVVLR1ZVc2VvNHlYTmhKWUhqYnNCOUMrRWdHL2xx?= =?utf-8?B?RDhGOFZzZk90S0lNN1BGYkFiV1hwU2QwVmwwOGJlOEtDUkh0MGdHOE9zUHFX?= =?utf-8?B?VHZKNFkvL1FMcXdDVm9mL1BnSGFHeldjUWIxa3lDaWsrRlVSN2J2b3lwZDN0?= =?utf-8?B?SU1QQU84Wi8zMm5NQ0VBdzY3NHVrTi9VeE8yVStxV0d2ZXhjZk1xV1pyTlJJ?= =?utf-8?B?UWEvcFZucXpFVzg4V2Y0Y0VaZVc1clFpU3k3TGNyRll0MnF2Wmw3bGFhN0k0?= =?utf-8?B?YThWeEdMTXZoVW9VTEZVaG1HR2hWTE9QUUQxUWxhYUJCa0tFZnVUQU5TRWsy?= =?utf-8?Q?mGJ7l6jHhrQ2i?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef758c80-728d-454a-2a43-08d90a3b75f0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2021 11:47:54.8417 (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: RooEh3jFbuY9OsiNKRQ5TQkzLu29cE/vDlYnRS0lNiJ2lfD8oBGtbcwoXHi6Gha6s69aFjVUbIOiisMKdi2dZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3195 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" On 4/28/21 3:21 AM, Simon Marchi wrote: > [CAUTION: External Email] > >> @@ -886,6 +887,162 @@ dwarf_expr_context::push_dwarf_reg_entry_value >> this->eval (data_src, size); >> } >> >> +/* See expr.h. */ >> + >> +struct value * >> +dwarf_expr_context::fetch_result (struct type *type, >> + struct type *subobj_type, >> + LONGEST subobj_offset) >> +{ >> + struct value *retval = nullptr; >> + >> + if (type == nullptr) >> + type = address_type (); >> + >> + if (subobj_type == nullptr) >> + subobj_type = type; >> + >> + if (this->pieces.size () > 0) >> + { >> + struct piece_closure *c; > > You can move this to where it's first initialized (and drop the struct > keyword). > >> + ULONGEST bit_size = 0; >> + >> + for (dwarf_expr_piece &piece : this->pieces) >> + bit_size += piece.size; >> + /* Complain if the expression is larger than the size of the >> + outer type. */ >> + if (bit_size > 8 * TYPE_LENGTH (type)) >> + invalid_synthetic_pointer (); >> + >> + c = allocate_piece_closure (this->per_cu, this->per_objfile, >> + std::move (this->pieces), this->frame); >> + retval = allocate_computed_value (subobj_type, >> + &pieced_value_funcs, c); >> + set_value_offset (retval, subobj_offset); >> + } >> + else >> + { >> + switch (this->location) >> + { >> + case DWARF_VALUE_REGISTER: >> + { >> + int dwarf_regnum >> + = longest_to_int (value_as_long (this->fetch (0))); >> + int gdb_regnum = dwarf_reg_to_regnum_or_error (this->gdbarch, >> + dwarf_regnum); >> + >> + if (subobj_offset != 0) >> + error (_("cannot use offset on synthetic pointer to register")); >> + >> + gdb_assert (this->frame != NULL); >> + >> + retval = value_from_register (subobj_type, gdb_regnum, >> + this->frame); >> + if (value_optimized_out (retval)) >> + { >> + struct value *tmp; >> + >> + /* 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 . */ >> + tmp = allocate_value (subobj_type); >> + value_contents_copy (tmp, 0, retval, 0, >> + TYPE_LENGTH (subobj_type)); >> + retval = tmp; >> + } >> + } >> + break; >> + >> + case DWARF_VALUE_MEMORY: >> + { >> + struct type *ptr_type; >> + CORE_ADDR address = this->fetch_address (0); >> + bool in_stack_memory = this->fetch_in_stack_memory (0); >> + >> + /* DW_OP_deref_size (and possibly other operations too) may >> + create a pointer instead of an address. Ideally, the >> + pointer to address conversion would be performed as part >> + of those operations, but the type of the object to >> + which the address refers is not known at the time of >> + the operation. Therefore, we do the conversion here >> + since the type is readily available. */ >> + >> + switch (subobj_type->code ()) >> + { >> + case TYPE_CODE_FUNC: >> + case TYPE_CODE_METHOD: >> + ptr_type = builtin_type (this->gdbarch)->builtin_func_ptr; >> + break; >> + default: >> + ptr_type = builtin_type (this->gdbarch)->builtin_data_ptr; >> + break; >> + } >> + address = value_as_address (value_from_pointer (ptr_type, address)); >> + >> + retval = value_at_lazy (subobj_type, >> + address + subobj_offset); >> + if (in_stack_memory) >> + set_value_stack (retval, 1); >> + } >> + break; >> + >> + case DWARF_VALUE_STACK: >> + { >> + struct value *value = this->fetch (0); >> + size_t n = TYPE_LENGTH (value_type (value)); >> + size_t len = TYPE_LENGTH (subobj_type); >> + size_t max = TYPE_LENGTH (type); >> + >> + if (subobj_offset + len > max) >> + invalid_synthetic_pointer (); >> + >> + retval = allocate_value (subobj_type); >> + >> + /* The given offset is relative to the actual object. */ >> + if (gdbarch_byte_order (this->gdbarch) == BFD_ENDIAN_BIG) >> + subobj_offset += n - max; >> + >> + memcpy (value_contents_raw (retval), >> + value_contents_all (value) + subobj_offset, len); >> + } >> + break; >> + >> + case DWARF_VALUE_LITERAL: >> + { >> + bfd_byte *contents; > > Same here, declare where initialized. > >> + size_t n = TYPE_LENGTH (subobj_type); >> + >> + if (subobj_offset + n > this->len) >> + invalid_synthetic_pointer (); >> + >> + retval = allocate_value (subobj_type); >> + contents = value_contents_raw (retval); >> + memcpy (contents, this->data + subobj_offset, n); >> + } >> + break; >> + >> + case DWARF_VALUE_OPTIMIZED_OUT: >> + retval = allocate_optimized_out_value (subobj_type); >> + break; >> + >> + /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced >> + operation by execute_stack_op. */ >> + case DWARF_VALUE_IMPLICIT_POINTER: >> + /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context -- >> + it can only be encountered when making a piece. */ >> + default: >> + internal_error (__FILE__, __LINE__, _("invalid location type")); > > You could change this to use gdb_assert_not_reached. > >> @@ -1479,155 +1481,15 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, >> throw; >> } >> >> - if (ctx.pieces.size () > 0) >> - { >> - struct piece_closure *c; >> - ULONGEST bit_size = 0; >> - >> - for (dwarf_expr_piece &piece : ctx.pieces) >> - bit_size += piece.size; >> - /* Complain if the expression is larger than the size of the >> - outer type. */ >> - if (bit_size > 8 * TYPE_LENGTH (type)) >> - invalid_synthetic_pointer (); >> - >> - c = allocate_piece_closure (per_cu, per_objfile, std::move (ctx.pieces), >> - frame); >> - /* We must clean up the value chain after creating the piece >> - closure but before allocating the result. */ >> - free_values.free_to_mark (); >> - retval = allocate_computed_value (subobj_type, >> - &pieced_value_funcs, c); >> - set_value_offset (retval, subobj_byte_offset); >> - } >> - else >> - { >> - switch (ctx.location) >> - { >> - case DWARF_VALUE_REGISTER: >> - { >> - struct gdbarch *arch = get_frame_arch (frame); >> - int dwarf_regnum >> - = longest_to_int (value_as_long (ctx.fetch (0))); >> - int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, dwarf_regnum); >> - >> - if (subobj_byte_offset != 0) >> - error (_("cannot use offset on synthetic pointer to register")); >> - free_values.free_to_mark (); >> - retval = value_from_register (subobj_type, gdb_regnum, frame); >> - if (value_optimized_out (retval)) >> - { >> - struct value *tmp; >> - >> - /* 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 . */ >> - tmp = allocate_value (subobj_type); >> - value_contents_copy (tmp, 0, retval, 0, >> - TYPE_LENGTH (subobj_type)); >> - retval = tmp; >> - } >> - } >> - break; >> - >> - case DWARF_VALUE_MEMORY: >> - { >> - struct type *ptr_type; >> - CORE_ADDR address = ctx.fetch_address (0); >> - bool in_stack_memory = ctx.fetch_in_stack_memory (0); >> - >> - /* DW_OP_deref_size (and possibly other operations too) may >> - create a pointer instead of an address. Ideally, the >> - pointer to address conversion would be performed as part >> - of those operations, but the type of the object to >> - which the address refers is not known at the time of >> - the operation. Therefore, we do the conversion here >> - since the type is readily available. */ >> - >> - switch (subobj_type->code ()) >> - { >> - case TYPE_CODE_FUNC: >> - case TYPE_CODE_METHOD: >> - ptr_type = builtin_type (ctx.gdbarch)->builtin_func_ptr; >> - break; >> - default: >> - ptr_type = builtin_type (ctx.gdbarch)->builtin_data_ptr; >> - break; >> - } >> - address = value_as_address (value_from_pointer (ptr_type, address)); >> - >> - free_values.free_to_mark (); >> - retval = value_at_lazy (subobj_type, >> - address + subobj_byte_offset); >> - if (in_stack_memory) >> - set_value_stack (retval, 1); >> - } >> - break; >> - >> - case DWARF_VALUE_STACK: >> - { >> - struct value *value = ctx.fetch (0); >> - size_t n = TYPE_LENGTH (value_type (value)); >> - size_t len = TYPE_LENGTH (subobj_type); >> - size_t max = TYPE_LENGTH (type); >> - gdbarch *objfile_gdbarch = per_objfile->objfile->arch (); >> - >> - if (subobj_byte_offset + len > max) >> - invalid_synthetic_pointer (); >> - >> - /* Preserve VALUE because we are going to free values back >> - to the mark, but we still need the value contents >> - below. */ >> - value_ref_ptr value_holder = value_ref_ptr::new_reference (value); >> - free_values.free_to_mark (); >> - >> - retval = allocate_value (subobj_type); >> - >> - /* The given offset is relative to the actual object. */ >> - if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG) >> - subobj_byte_offset += n - max; >> - >> - memcpy (value_contents_raw (retval), >> - value_contents_all (value) + subobj_byte_offset, len); >> - } >> - break; >> - >> - case DWARF_VALUE_LITERAL: >> - { >> - bfd_byte *contents; >> - size_t n = TYPE_LENGTH (subobj_type); >> - >> - if (subobj_byte_offset + n > ctx.len) >> - invalid_synthetic_pointer (); >> - >> - free_values.free_to_mark (); >> - retval = allocate_value (subobj_type); >> - contents = value_contents_raw (retval); >> - memcpy (contents, ctx.data + subobj_byte_offset, n); >> - } >> - break; >> - >> - case DWARF_VALUE_OPTIMIZED_OUT: >> - free_values.free_to_mark (); >> - retval = allocate_optimized_out_value (subobj_type); >> - break; >> - >> - /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced >> - operation by execute_stack_op. */ >> - case DWARF_VALUE_IMPLICIT_POINTER: >> - /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context -- >> - it can only be encountered when making a piece. */ >> - default: >> - internal_error (__FILE__, __LINE__, _("invalid location type")); >> - } >> - } I've just copied this whole block from the loc.c. Everything is replaced with a new implementation in the later patch. Do you still feel that I need to clean it up here or it doesn't really matter considering the later patches? >> - >> - set_value_initialized (retval, ctx.initialized); >> + /* We need to clean up all the values that are not needed any more. >> + The problem with a value_ref_ptr class is that it disconnects the >> + RETVAL from the value garbage collection, so we need to make >> + a copy of that value on the stack to keep everything consistent. >> + The value_ref_ptr will clean up after itself at the end of this block. */ >> + value_ref_ptr value_holder = value_ref_ptr::new_reference (retval); >> + free_values.free_to_mark (); >> >> - return retval; >> + return value_copy(retval); > > Missing space. > > Simon > Thanks, I will fix it in the next iteration. Zoran