From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-eopbgr750049.outbound.protection.outlook.com [40.107.75.49]) by sourceware.org (Postfix) with ESMTPS id DAC0A385701E for ; Wed, 28 Apr 2021 13:15:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DAC0A385701E ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gSHtmuXoCnZoihNxTsiqwVFNaGj3KTqNVuOQSYY3i1dOsLXAKn2nUq6zlkxbF80CAhqA0taXEcXt44sB/+XC07SrPa/Dt2U5k9MDshyvD4HyS9ABQH1uMq3e3p5yUNyjGJsq17zSxJUs8aBSjhRp/QFrC+Z7xKGd/BI23iYOe5+jL45kOwgMGe1rrhkFpSZsb9s8eNh2WrNsqs+VyyKZ1E+hr/rD2PkE4T64ERYa8zMW7bKm7yvBbK6Wwl+JXqQDLcY8o2LaORwpPU0wiBhdkFhpqLyOn5l2yIxIQBZf9/30e7UNoX/tzc2MPumG45AXZBLgQPYfD6bO8egEhH9CjQ== 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=HI8wjIYYi5ItlnfbRyP++/2954qtENONcLwMMB5cDk0=; b=TSVTDknotF3L+akWhmHRIUHJK5WJn/WKn2/TGzjpXEmwPTK+FXPmqyBa9+F2UiwLHtP5EcHiz10bR/SWesod4wKuV2kpVn/UjDsorfxAQXv9j6tBwhBErPW7z/J48TMkX8+seVGAunaRKTZrwR5vLdsa0RyuXFWJmDOy42XFrrYam4cN6NThijWle3V5PLyC4nnZUVcqlsWiKdW5F7fYyiz1QxcfxtWxDGru0YmMExxwoQcu5DhBQ+zrsHTMY+trIehJGEnEPIcYs8qZ7fPT8Gi8XF4zt5m0dBMgM53G04OjrcQZ5hfaWzHDgcK0dAdwDGhNJAlsNt0IRmY07uvW3g== 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 DM6PR12MB4331.namprd12.prod.outlook.com (2603:10b6:5:21a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Wed, 28 Apr 2021 13:15:44 +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 13:15:44 +0000 Subject: Re: [PATCH 16/43] Simplify dwarf_expr_context class interface To: Simon Marchi , gdb-patches@sourceware.org References: <20210301144620.103016-1-Zoran.Zaric@amd.com> <20210301144620.103016-17-Zoran.Zaric@amd.com> From: Zoran Zaric Message-ID: Date: Wed, 28 Apr 2021 14:15:39 +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: LO2P265CA0224.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::20) 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 LO2P265CA0224.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Wed, 28 Apr 2021 13:15:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 33acd8f5-f864-4e08-79a1-08d90a47bb06 X-MS-TrafficTypeDiagnostic: DM6PR12MB4331: 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: GRsnSnXjNVrjUPq/lhl1vgxMg1LzA3FaO1dBHxZFbyVVxagV4zofTymkEAQgjqpJ91pvhu4b4VNzCjXqwoASjaXmsmlqnLU9VK98BBsBC1KrmUeFXRDlb66sHi3xKGHaF4yLs3hu5EGSfP7KabdjhslMhtAFxVAEADvXxErMWV03whCC8ilXwZtfyTZ5bcgUBJGANkrwPiMheHIxl/lfz+pTxkgcmT7ky0tWeCoIsw7WCdiK5PYhrW9rWgRlV1+Y8V7WZ4E+lo6EMnTLy9j2hM4dgr7lPJzvJV+R8pULHov+AqCH70QV3NyURSqw99hioE1RNSFUVibwJtnuN675QrzpZ8Chom7uDuzts6F+fV/tuuL7IgWUEM+Xn721Cx85ADi8jgEFg1KCkqBBaHWckD7auTbvTE8l0BdtV87cPjcsjpKGve1oP7W8zpaytU04nlo/DMdgqsqXYXJbFE729quBv1Ssf5F1HNZjvQYHRdy1FJOmtK5xORCUjlW+AZLzfM1DbYvKGRnHX7zLtW1/lHtJD5O9AW7DVkBbpuSuYccBHtgAkw59WRjt6i+0IeFtAwDM/UR56yxtY7Elm/F4jirON/qJRPHozEnL0DWRnXVtBC08PmtTiaRTZSqcZ1kT4p+4SSbCCOPI1ofPtQCU1RPFT9ZpJSDnFYw+XBpBMfa2Qj4qBZgryngog9h5ZS4r 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)(39860400002)(376002)(396003)(346002)(136003)(6666004)(2616005)(31686004)(8676002)(16526019)(8936002)(316002)(86362001)(6486002)(83380400001)(38100700002)(2906002)(66946007)(478600001)(66556008)(36756003)(186003)(66476007)(52116002)(5660300002)(31696002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?d1Y1V3R2Rm1nSHZENEZrbzNWWU0zM21DT0liVDhGd0FyWEViRFRyNWRtTHUr?= =?utf-8?B?UHlRd1pacmxyMXJXRWxwTHRraFVKeVg3L2txUXlnQzNuOVJwcTFhNldwT3Bj?= =?utf-8?B?aFlqU0RSZVJScFcweXdUYWtpdHhaS2dKL1JIN0MwZk13L25KM1ltZVZUbmFO?= =?utf-8?B?ZXJPUWlBS00zZnJIYWFMSG9hUUg2Qzh4TEl1Y2IzQVZuNDRsSU1RSlZFcGVM?= =?utf-8?B?bkVJOFhEcElRcnlHUTZhZE1CYUpyb2kxZ2NxSlVzbVBEUTArMVk0ZUYxUmhZ?= =?utf-8?B?NndFSCtwTnVaQ0xPZTdFVDQ5TGYrMElNTTZWSlcxTThwWkJFdlJRTlBybmVM?= =?utf-8?B?WGl0N3BFWEx4cW02STlYTjFweHZjemtacWM4MEpsZkZ3cmZEOXN3T1AvSnJu?= =?utf-8?B?VVk3Qy9RRUxLaTVTYjFIY09lTDJPbWd2VkhHUjlDV3hxbmVzUFdqUWk0Y0Fv?= =?utf-8?B?NkdpeCtpek1wVmVDVWxDa1JXVjJ1YWRRTTg1YjdmT0RzRzFxdlptU2IzcmNa?= =?utf-8?B?UVZiTFE1MUFObWZaYW1YTmtRZVFtbDFSMWZSRSt5dUowUzYyYzNCWDdCSWp2?= =?utf-8?B?RjBoRFFhQm1vblhoQkFkcUtrbjZpNGxKWjJKQzRHZE5PZmhqeHZHOExTWlA0?= =?utf-8?B?ZFZPODUvTnR4Y3JWUUs5SXBqbDg5MFFaR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vUE5Yb1N1YUpibXdlVTJIdUVzVWQ0bW92VlJKazE5RWZvVEJBSDJNcVpt?= =?utf-8?B?VHZhcFRIbTBGODBuZjN3bjRSVE9FMGkwZUZDVURmRXROZExOQnh0VGJZeDZD?= =?utf-8?B?elRRMnhEd05QbUhNK3JKQUZMaU9nNlRKWGs4bEN6TjBWNi9TZlJORmVHWm1P?= =?utf-8?B?SmNIM3MxNWFUd0EwVklyMWtaWXJUbU9lTy9GQWc1VnNyM3BYaXZOdFpwRnhy?= =?utf-8?B?amdEbXFZcnlOKzlXR1YrSkoxd0JseDYvRTBhZDJITTJtd0NlSFI5b1pTNHE3?= =?utf-8?Q?uX3dUgoyXuFV5?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33acd8f5-f864-4e08-79a1-08d90a47bb06 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2021 13:15:44.7924 (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: zJyJCrzuoJf7aAyfukkC3ZirDGTn0bSsfovaDc9bhltJpkSj5FV5Zaza0G2bjGJSDVzZHKywXOmZxxxRr3pmqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4331 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, 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: Wed, 28 Apr 2021 13:15:52 -0000 >> /* Create a new context for the expression evaluator. */ >> >> -dwarf_expr_context::dwarf_expr_context (dwarf2_per_objfile *per_objfile) >> -: per_objfile (per_objfile) >> +dwarf_expr_context::dwarf_expr_context (dwarf2_per_objfile *per_objfile, >> + int addr_size) >> +: gdbarch (per_objfile->objfile->arch ()), > > If gdbarch is always obtained from the objfile, we could maybe avoid > storing it. Sure, but it is used so many times (often as a few times per operation) so we currently cut off two indirection per each use. I think having one pointer as a class member that cuts through all that is worth it. > >> + addr_size (addr_size), >> + per_objfile (per_objfile) >> { >> } >> >> @@ -825,13 +828,17 @@ dwarf_expr_context::read_mem (gdb_byte *buf, CORE_ADDR addr, >> return; >> >> /* Prefer the passed-in memory, if it exists. */ >> - CORE_ADDR offset = addr - obj_address; >> + if (addr_info != nullptr) >> + { >> + CORE_ADDR offset = addr - addr_info->addr; >> >> - if (offset < data_view.size () && offset + length <= data_view.size ()) >> + if (offset < addr_info->valaddr.size () >> + && offset + length <= addr_info->valaddr.size ()) >> { >> - memcpy (buf, data_view.data (), length); >> + memcpy (buf, addr_info->valaddr.data (), length); > > Not related to this patch, but: I find it odd that the field `valaddr` > contains the object's value. Why is it called like that? My understanding is that this is because it often (although not always) represents a pointer to a struct value contents of some object in cases where the DWARF spec is not descriptive enough to support the actual case. This is something that could be replaced by our extensions in the future but it would probably require a compiler change. > >> return; >> } >> + } > > The indentation here is not right. > >> >> read_memory (addr, buf, length); >> } >> @@ -874,8 +881,8 @@ dwarf_expr_context::push_dwarf_reg_entry_value >> caller_frame); >> scoped_restore save_per_cu = make_scoped_restore (&this->per_cu, >> caller_per_cu); >> - scoped_restore save_obj_addr = make_scoped_restore (&this->obj_address, >> - (CORE_ADDR) 0); >> + scoped_restore save_addr_info = make_scoped_restore (&this->addr_info, >> + nullptr); >> scoped_restore save_per_objfile = make_scoped_restore (&this->per_objfile, >> caller_per_objfile); >> >> @@ -1043,6 +1050,28 @@ dwarf_expr_context::fetch_result (struct type *type, >> return retval; >> } >> >> +/* See expr.h. */ >> + >> +struct value * >> +dwarf_expr_context::evaluate (const gdb_byte *addr, size_t len, >> + struct dwarf2_per_cu_data *per_cu, >> + struct frame_info *frame, >> + const struct property_addr_info *addr_info, >> + struct type *type, >> + struct type *subobj_type, >> + LONGEST subobj_offset) >> +{ >> + this->per_cu = per_cu; >> + this->frame = frame; >> + this->addr_info = addr_info; >> + >> + if (per_cu != nullptr) >> + this->ref_addr_size = per_cu->ref_addr_size (); > > As mentioned in a previous message, I have the feeling that we could get > rid of the ref_addr_size field and just call per_cu->ref_addr_size when > we need it. It could always be a follow-up cleanup. Agreed. > >> + >> + eval (addr, len); >> + return fetch_result (type, subobj_type, subobj_offset); > > This is just me, not an officiel style rule, when I like to use `this->` > when accessing fields and methods, to make it clear what they are (not > global variables or free functions). Although for fields prefixed with > `m_`, I don't, because it's already obvious by the naming. I was wondering about this because the old code was inconsistent. I will probably do like a systematic change for all places in one of the new patches. > >> diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h >> index a0ac21f2ed1..d1374068732 100644 >> --- a/gdb/dwarf2/expr.h >> +++ b/gdb/dwarf2/expr.h >> @@ -119,19 +119,30 @@ struct dwarf_stack_value >> its current state and its callbacks. */ >> struct dwarf_expr_context >> { >> - dwarf_expr_context (dwarf2_per_objfile *per_objfile); >> + /* We should ever only pass in the PER_OBJFILE, while the ADDR_SIZE >> + information should be retrievable from there. The PER_OBJFILE >> + contains a pointer to the PER_BFD information anyway and the >> + address size information must be the same for the whole BFD. */ >> + dwarf_expr_context (struct dwarf2_per_objfile *per_objfile, >> + int addr_size); > > I don't really understand the comment. What do you mean by "We should > ever only pass..."? In general, I don't find that the comment helps me > understand what the parameters are and do. Try to change it to be more > concrete and straight to the point. This was more me venting about that particular design choice because the reality is that an address size has to be consistent with what is defined in the original object file but there is no interface to always get it in a clean way in gdb. It makes sense for me to remove that comment altogether in the next iteration and thing about a future change that would clean it up. > >> virtual ~dwarf_expr_context () = default; >> >> void push_address (CORE_ADDR value, bool in_stack_memory); >> - void eval (const gdb_byte *addr, size_t len); >> >> - /* 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. */ >> - struct value *fetch_result (struct type *type = nullptr, >> - struct type *subobj_type = nullptr, >> - LONGEST subobj_offset = 0); >> + /* 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. */ > > It sounds like you are missing a word between PER_CU and FRAME. > > The sentence starting with "Where" sounds strange, I'd remove the > "Where" to make it a simple statement. > > It sounds like you are missing a "the" between "describe" and > "expected". Thank you, I will change it in the next iteration. > >> + struct value *evaluate (const gdb_byte *addr, size_t len, >> + struct dwarf2_per_cu_data *per_cu, >> + struct frame_info *frame, >> + const struct property_addr_info *addr_info = nullptr, >> + struct type *type = nullptr, >> + struct type *subobj_type = nullptr, >> + LONGEST subobj_offset = 0); > > Note to self that ADDR + LEN would be good candidates to become a > gdb::array_view later. > Agreed. >> >> +private: >> /* The stack of values. */ >> std::vector stack; > > If all these fields become private, it would be good to rename them to > add the `m_` prefix. It could be done at the end (if not already done > later in the series), to avoid the conflicts. > > Simon > I didn't do it, but I will in the next iteration. Zoran