From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2044.outbound.protection.outlook.com [40.107.241.44]) by sourceware.org (Postfix) with ESMTPS id 97734384F4B4 for ; Mon, 21 Nov 2022 21:16:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97734384F4B4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v37UwY+ckk5xDWiPE0bOIb8UVTexLRTN4h6XzJoUHYs=; b=n52lv8w1qFT1LejOhJ62BlJfsOrCjmuCoGRc3buLyHPqFN+loHijsWsnR9WluG4H9HxLBpXh+3ouCVr1LGCGuMJAJsh22iPOTvy5TtrDj8lBzxEEQu8dnaMCYLG7AUWamjke/obOcEYXkCwVlCMd0Ra/bqn9ElHsJ92yfsV8DN0= Received: from AM5PR0101CA0001.eurprd01.prod.exchangelabs.com (2603:10a6:206:16::14) by GV1PR08MB8240.eurprd08.prod.outlook.com (2603:10a6:150:5d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Mon, 21 Nov 2022 21:16:41 +0000 Received: from VI1EUR03FT013.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:16:cafe::d2) by AM5PR0101CA0001.outlook.office365.com (2603:10a6:206:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15 via Frontend Transport; Mon, 21 Nov 2022 21:16:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT013.mail.protection.outlook.com (100.127.145.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.8 via Frontend Transport; Mon, 21 Nov 2022 21:16:40 +0000 Received: ("Tessian outbound 73ab5f36653e:v130"); Mon, 21 Nov 2022 21:16:40 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3930751100f6a5da X-CR-MTA-TID: 64aa7808 Received: from c7ed194a5608.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 627A04C8-D974-4699-B261-05FEC502607E.1; Mon, 21 Nov 2022 21:16:33 +0000 Received: from EUR03-DBA-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c7ed194a5608.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 21 Nov 2022 21:16:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FVmZWhcIJz1N52un5Xn4+2I4wsIK4gUSXZRnHIs3SMfzRmHOxZI5aRNSwl8mNtembKjKxpL17sMjHzaUrZjGt7jA0jZrWqEIsedUni9+BHALFaKDcX7Pv1sTB3IMJm+M+spAlTA9TB7evjivNdp18e0Raw5+cq44Y009c48FWx2Irqj2P1IiHtaBy12eyAcqXZlM4tUrYMFqdWARapdIyeRQdMYyco/Gd4OGMtoyq+JZtYxyJtmKgZmx4ozDKjDuz8yaQp4qI5dr6wRMqaku2qYXTUAuK9NSzMJOK+6OcZ+PHagEEMFCECHg/tMfgfXNYQtZS96Z8pWeFnf5hiLl9w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=v37UwY+ckk5xDWiPE0bOIb8UVTexLRTN4h6XzJoUHYs=; b=lZuSVN92mJqtt0QViDxvJf2I6vymI/CbQRoumgw9Hp+zl+tX9KTP3PelUtfxvGYJ1lcOeWI2UxLWpCPjfv/gR39pc7E2wqMwH8X9Vh/C3p3cGXRdS7EgPegUq56CSaY22Dt/8PMYVojc1Ss1bGEDRKc4LQnrYTS+cd9aK70ThgYlHrlrZS3foaXQJxrBXMYh2hH4bASKN8u5VbGApeiEckLc2laWWaRGAhb4Y0M/zvMkBAVuETS2IWr7XNnWdUO9cxNCZzlxG1ItlguOVzYdyai0+6AH6h2X47H0Iz4xq5iYNdLL1famGo1sAmA/HTR5QsbV0/s2NMl7znkBMCzDIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v37UwY+ckk5xDWiPE0bOIb8UVTexLRTN4h6XzJoUHYs=; b=n52lv8w1qFT1LejOhJ62BlJfsOrCjmuCoGRc3buLyHPqFN+loHijsWsnR9WluG4H9HxLBpXh+3ouCVr1LGCGuMJAJsh22iPOTvy5TtrDj8lBzxEEQu8dnaMCYLG7AUWamjke/obOcEYXkCwVlCMd0Ra/bqn9ElHsJ92yfsV8DN0= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by PAWPR08MB9853.eurprd08.prod.outlook.com (2603:10a6:102:2e6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Mon, 21 Nov 2022 21:16:23 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::c470:cc90:a9ad:6dd1]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::c470:cc90:a9ad:6dd1%4]) with mapi id 15.20.5857.017; Mon, 21 Nov 2022 21:16:22 +0000 Message-ID: Date: Mon, 21 Nov 2022 21:16:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 3/4] gdb: dwarf2 generic implementation for caching function data Content-Language: en-US To: =?UTF-8?Q?Torbj=c3=b6rn_SVENSSON?= , gdb-patches@sourceware.org Cc: vanekt@volny.cz, Yvan Roux References: <20221118155252.113476-1-torbjorn.svensson@foss.st.com> <20221118155252.113476-4-torbjorn.svensson@foss.st.com> From: Luis Machado In-Reply-To: <20221118155252.113476-4-torbjorn.svensson@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO4P265CA0155.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::7) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|PAWPR08MB9853:EE_|VI1EUR03FT013:EE_|GV1PR08MB8240:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a29180b-9ac8-4bb0-b6b4-08dacc05aef8 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: VGA39El736xpy3MZnwJRGLwuJgADTYfSQwyLm8w0TyZ3bVoi5typcGVbUnKod7APHfP35QceZbcGVthZFqFNu5tHTFVTT6xm0gl2fttuItMF4GRygNxwpKIiqKJvd4gGvvMnJOIytSL5OTnwuuNaXr+EVJO6Nh1b3csu2eTt0gSAaG9o/oZMPcPr1uoeoeDESeS5eQpv6taI1hUfwGzNcB/tWmtqqKN84J3zpqYpf909E4myRNphJgaOC23jUUwY8UN9JE4t0/4H/ibvlchJ9t8pbCiFB2Bh+FdMGLP9X+qibHHTLUY6LhHH75JdXz6l4tFurm/n+KJb8xFKOFLQYsfeMcav4rSCXib75CvBI2kIaaJvPSTswvCRtDvwlXRW/UBvpAOKPCvccHbudQy2gpZiBIQUbu05I8vzI8zguOda19O15m2Ak+i5ndBYphMzA/ME2CIPLhzpk32I5PolnU0TBkx5wff37Zs4XnY69AW8GQ26l5mfRhEsNgeIKugXb3/oph2F1jGEy8AyghtV2uDUP04jN5LF533ITKRKtsWzZ19HZWeyD4Nyq/dmVF4HmF/PqyJ1IEL0wQ99Prpw/zrOXSlOOFExGiBEa6nplJ2ohPJ/j0YR4wlePwT+0AcrUSVVZ/IIa7pguoYJtP0Bdthu7vsEPemt/xFKUWlOIjfvcGXokTam6e0aoWj4tXMt26UH4jFxSajteiKv05DjJvYxqyytHWAcV9QVH73r5+bpv87tww/qQ3WuOa8CkIeA X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(396003)(39860400002)(136003)(376002)(346002)(451199015)(478600001)(31696002)(86362001)(38100700002)(6506007)(316002)(83380400001)(2906002)(2616005)(36756003)(53546011)(41300700001)(6486002)(66899015)(31686004)(186003)(8936002)(4326008)(5660300002)(44832011)(26005)(66556008)(66476007)(6512007)(8676002)(66946007)(41533002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9853 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0c1f3e02-fedf-497e-c895-08dacc05a415 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7YD5xx4PeicpuiORYRljczLUrirGWe0whpJ6yXPK4CZp+Ky2i1btmCw+WZ3qyHXUUw6FZ9KOshc97FOHxVpK77/3I5zR3VA3Xl47I/xQ9KqibwRzNpX2d7VkzbkjSGthsjjCngn/avEWaToCMmPkKGyNic59+js/RemzAcOv+kxtO2gqMvbAQgl53HgcUHLWBTPGlKmDLcCouQnGhfAPCbsAbPcKRROa+6nxeEzwojYe3LtbMDvhm+TQlAGBv8gHW4QM3kar3HKsXKUXUoyiopFd69RDBwaZ7JmwxOkEuA211AsZo3N/B2+dy3NTpiL/NpQ/hikXjd2eeh460XN9p5uJcWXzzSCUrW1kRGC617u4RzP6edvVRonuZRVOcfKOp6VqGiCYFF+pD6wInkcY+cOhQziCiqMDvnsCmMuhvcA9qh9Ptj2mUh7GHvEuedMeGQiHYM53NDyeKhVah6K0dbwrKwmygHBh+s8gnMJ0Z2CzrytH1A3FWyiGURXZXN8p4MxyfuVRPNrEy5fsqPeeNgNtP3z9nshcMl/3SOnR5rPi34GExVauSspALq6h2iPeQG7OkbDLji+fzvtI3fL6TeF/wJlcvfEjsyL+qe5DwGB478AMHGsHn00t7Rlg9PJwcxZYzWKBz5jv7kBQU80eW2v0OOqpZyJNh7lXV+gMrWj2q9eX4OfjFYrRMY3SSa1CUyF3OY41QM8UvifdvT97luzdhdo53YS5Rk6tv14dbZRQ+a5olqNojQJ7RXJBETi115oIejrKH1QZTBZfN4v+EQ== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(396003)(376002)(346002)(136003)(451199015)(46966006)(40470700004)(36840700001)(82740400003)(356005)(40480700001)(81166007)(36756003)(86362001)(31696002)(40460700003)(316002)(6486002)(478600001)(5660300002)(8936002)(2906002)(44832011)(70586007)(70206006)(8676002)(4326008)(41300700001)(36860700001)(83380400001)(6512007)(26005)(2616005)(53546011)(6506007)(82310400005)(336012)(186003)(47076005)(31686004)(66899015)(41533002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 21:16:40.7534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a29180b-9ac8-4bb0-b6b4-08dacc05aef8 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8240 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, On 11/18/22 15:52, Torbjörn SVENSSON wrote: > When there is no dwarf2 data for a register, a function can be called > to provide the value of this register. In some situations, it might > not be trivial to determine the value to return and it would cause a > performance bottleneck to do the computation each time. > > This patch allows the called function to have a "cache" object that it > can use to store some metadata between calls to reduce the performance > impact of the complex logic. > > The cache object is unique for each function and frame, so if there are > more than one function pointer stored in the dwarf2_frame_cache->reg > array, then the appropriate pointer will be supplied (the type is not > known by the dwarf2 implementation). > > dwarf2_frame_get_fn_data can be used to retrieve the function unique > cache object. > dwarf2_frame_allocate_fn_data can be used to allocate and retrieve the > function unqiue cache object. unqiue -> unique > > Signed-off-by: Torbjörn SVENSSON > Signed-off-by: Yvan Roux > --- > gdb/dwarf2/frame.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ > gdb/dwarf2/frame.h | 20 +++++++++++++++++-- > 2 files changed, 66 insertions(+), 2 deletions(-) > > diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c > index 3f884abe1d5..bff3b706e7e 100644 > --- a/gdb/dwarf2/frame.c > +++ b/gdb/dwarf2/frame.c > @@ -831,6 +831,14 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc, > } > > > +struct dwarf2_frame_fn_data > +{ > + struct value *(*fn) (frame_info_ptr this_frame, void **this_cache, > + int regnum); > + void *data; > + struct dwarf2_frame_fn_data* next; > +}; > + I'm wondering if we really need to have a function pointer here. Isn't the cache supposed to be frame-wide and not function-specific? If we don't need it, the cache just becomes an opaque data pointer. > struct dwarf2_frame_cache > { > /* DWARF Call Frame Address. */ > @@ -862,6 +870,8 @@ struct dwarf2_frame_cache > dwarf2_tailcall_frame_unwind unwinder so this field does not apply for > them. */ > void *tailcall_cache; > + > + struct dwarf2_frame_fn_data *fn_data; > }; > > static struct dwarf2_frame_cache * > @@ -1221,6 +1231,44 @@ dwarf2_frame_prev_register (frame_info_ptr this_frame, void **this_cache, > } > } > > +void *dwarf2_frame_get_fn_data (frame_info_ptr this_frame, void **this_cache, > + fn_prev_register fn) > +{ > + struct dwarf2_frame_fn_data *fn_data = nullptr; > + struct dwarf2_frame_cache *cache > + = dwarf2_frame_cache (this_frame, this_cache); > + > + /* Find the object for the function. */ > + for (fn_data = cache->fn_data; fn_data; fn_data = fn_data->next) > + if (fn_data->fn == fn) > + return fn_data->data; > + > + return nullptr; > +} > + > +void *dwarf2_frame_allocate_fn_data (frame_info_ptr this_frame, > + void **this_cache, > + fn_prev_register fn, unsigned long size) > +{ > + struct dwarf2_frame_fn_data *fn_data = nullptr; > + struct dwarf2_frame_cache *cache > + = dwarf2_frame_cache (this_frame, this_cache); > + > + /* First try to find an existing object. */ > + void *data = dwarf2_frame_get_fn_data (this_frame, this_cache, fn); > + if (data) > + return data; > + > + /* No object found, lets create a new instance. */ > + fn_data = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_fn_data); > + fn_data->fn = fn; > + fn_data->data = frame_obstack_zalloc (size); > + fn_data->next = cache->fn_data; > + cache->fn_data = fn_data; > + > + return fn_data->data; > +} And if we only have a data pointer, we can return a reference to it through the argument, and then DWARF can cache it. We could even have a destructor/cleanup that can get called once the frames are destroyed. > + > /* Proxy for tailcall_frame_dealloc_cache for bottom frame of a virtual tail > call frames chain. */ > > diff --git a/gdb/dwarf2/frame.h b/gdb/dwarf2/frame.h > index 06c8a10c178..444afd9f8eb 100644 > --- a/gdb/dwarf2/frame.h > +++ b/gdb/dwarf2/frame.h > @@ -66,6 +66,9 @@ enum dwarf2_frame_reg_rule > > /* Register state. */ > > +typedef struct value *(*fn_prev_register) (frame_info_ptr this_frame, > + void **this_cache, int regnum); > + > struct dwarf2_frame_state_reg > { > /* Each register save state can be described in terms of a CFA slot, > @@ -78,8 +81,7 @@ struct dwarf2_frame_state_reg > const gdb_byte *start; > ULONGEST len; > } exp; > - struct value *(*fn) (frame_info_ptr this_frame, void **this_cache, > - int regnum); > + fn_prev_register fn; > } loc; > enum dwarf2_frame_reg_rule how; > }; > @@ -262,4 +264,18 @@ extern int dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc, > const gdb_byte **cfa_start_out, > const gdb_byte **cfa_end_out); > > + > +/* Allocate a new instance of the function unique data. */ > + > +extern void *dwarf2_frame_allocate_fn_data (frame_info_ptr this_frame, > + void **this_cache, > + fn_prev_register fn, > + unsigned long size); > + > +/* Retrieve the function unique data for this frame. */ > + > +extern void *dwarf2_frame_get_fn_data (frame_info_ptr this_frame, > + void **this_cache, > + fn_prev_register fn); > + > #endif /* dwarf2-frame.h */ As we've discussed before, I think the cache idea is nice if we have to deal with targets with multiple CFA's (in our case, we have either 4 SP's or 2 SP's, plus aliases). DWARF doesn't seem to support this at the moment, and the function HOW for DWARF is not smart enough to remember a previously-fetched value. So it seems we have room for some improvement, unless there is enough reason elsewhere about why we shouldn't have a cache. It would be nice to have some opinions from others, so we can potentially shape this in a way that makes it useful for the general case.