From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28365 invoked by alias); 17 Feb 2017 01:19:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 28345 invoked by uid 89); 17 Feb 2017 01:19:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=callees, Hx-languages-length:2185, dwarf2_cu, *die X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Feb 2017 01:19:10 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A70C27E9E4; Fri, 17 Feb 2017 01:19:10 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C49926370A; Fri, 17 Feb 2017 01:19:09 +0000 (UTC) Subject: Re: [PATCH 3/8] Code cleanup: Split dwarf2_ranges_read to a callback To: Jan Kratochvil , gdb-patches@sourceware.org References: <148693097396.9024.2288256732840761882.stgit@host1.jankratochvil.net> <148693098804.9024.9905586065345063380.stgit@host1.jankratochvil.net> Cc: Victor Leschuk From: Pedro Alves Message-ID: <7ffd29af-218a-32e3-ac6a-207f0bc8a382@redhat.com> Date: Fri, 17 Feb 2017 01:19:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <148693098804.9024.9905586065345063380.stgit@host1.jankratochvil.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00459.txt.bz2 On 02/12/2017 08:23 PM, Jan Kratochvil wrote: > -/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. > - Return 1 if the attributes are present and valid, otherwise, return 0. > - If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ > +/* Call CALLBACK from DW_AT_ranges attribute value OFFSET. > + Return 1 if the attributes are present and valid, otherwise, return 0. */ > > static int > -dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, > - CORE_ADDR *high_return, struct dwarf2_cu *cu, > - struct partial_symtab *ranges_pst) > +dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, > + std::function + CORE_ADDR range_end)> callback) std::function is a lot of unnecessary overhead here. Unless you manage to trigger to small-function optimization (which you won't here, the callbacks are too big), this is forcing a heap allocation inside std::function for every call to dwarf2_ranges_process. Let's only use std::function for it's intended use-case of when the design calls for taking, or more usually, storing, a callable whose type is not knowable at compile type. In this case, the type is determinable at compile type, as everything is local to the same file and the callees are always known. So make dwarf2_ranges_process a template, and the overhead disappears, like: ~~~~~~~~~~~~~~~~~~ diff --git c/gdb/dwarf2read.c w/gdb/dwarf2read.c index 1137541..94d5de2 100644 --- c/gdb/dwarf2read.c +++ w/gdb/dwarf2read.c @@ -11877,10 +11877,13 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) /* Call CALLBACK from DW_AT_ranges attribute value OFFSET. Return 1 if the attributes are present and valid, otherwise, return 0. */ +/* Callback's type should be: + void (CORE_ADDR range_beginning, CORE_ADDR range_end) +*/ +template static int dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, - std::function callback) + Callback callback) { ~~~~~~~~~~~~~~~~~~ OK with that change. Thanks, Pedro Alves