From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 71A34393C86F for ; Fri, 28 Aug 2020 17:06:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 71A34393C86F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id EA2071E599; Fri, 28 Aug 2020 13:06:42 -0400 (EDT) Subject: Re: [PATCH 04/13] Use gdb_bfd_sections in get_stap_base_address To: Tom Tromey , gdb-patches@sourceware.org References: <20200828162349.987-1-tom@tromey.com> <20200828162349.987-5-tom@tromey.com> From: Simon Marchi Message-ID: <5f794d12-c1a7-4cb5-68a8-1bb76fff3d1c@simark.ca> Date: Fri, 28 Aug 2020 13:06:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200828162349.987-5-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, 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: Fri, 28 Aug 2020 17:06:44 -0000 On 2020-08-28 12:23 p.m., Tom Tromey wrote: > This changes get_stap_base_address to avoid bfd_map_over_sections, in > favor of iteration. > > gdb/ChangeLog > 2020-08-28 Tom Tromey > > * stap-probe.c (get_stap_base_address_1): Remove. > (get_stap_base_address): Use foreach. > --- > gdb/ChangeLog | 5 +++++ > gdb/stap-probe.c | 20 ++++++-------------- > 2 files changed, 11 insertions(+), 14 deletions(-) > > diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c > index 73596446cce..fb6010d14ff 100644 > --- a/gdb/stap-probe.c > +++ b/gdb/stap-probe.c > @@ -1578,19 +1578,6 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el, > probesp->emplace_back (ret); > } > > -/* Helper function which tries to find the base address of the SystemTap > - base section named STAP_BASE_SECTION_NAME. */ > - > -static void > -get_stap_base_address_1 (bfd *abfd, asection *sect, void *obj) > -{ > - asection **ret = (asection **) obj; > - > - if ((sect->flags & (SEC_DATA | SEC_ALLOC | SEC_HAS_CONTENTS)) > - && sect->name && !strcmp (sect->name, STAP_BASE_SECTION_NAME)) > - *ret = sect; > -} > - > /* Helper function which iterates over every section in the BFD file, > trying to find the base address of the SystemTap base section. > Returns 1 if found (setting BASE to the proper value), zero otherwise. */ > @@ -1600,7 +1587,12 @@ get_stap_base_address (bfd *obfd, bfd_vma *base) > { > asection *ret = NULL; > > - bfd_map_over_sections (obfd, get_stap_base_address_1, (void *) &ret); > + for (asection *sect : gdb_bfd_sections (obfd)) > + { > + if ((sect->flags & (SEC_DATA | SEC_ALLOC | SEC_HAS_CONTENTS)) > + && sect->name && !strcmp (sect->name, STAP_BASE_SECTION_NAME)) > + ret = sect; > + } This is where I meant to say: FYI: I've been taught by Pedro [1] that we don't actually need curly braces in this case, and I've been misleading people about this for a while . For future code I write like this, I won't use the curly braces. [1] https://sourceware.org/pipermail/gdb-patches/2020-August/171532.html Simon