From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2709A3858C78 for ; Wed, 6 Sep 2023 11:50:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2709A3858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694001027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7t4b3oY6bbyjLQ2Tj5MyahZzMP/RtnltuHJzxDNxgiU=; b=PJQIv2bElxjCySPZ8voXvSZy5otiQlipHGKH5VIm49p3mqeCVkwBnKMJtLp3e7tMzOCb3h q0KUMC1DXJwjM8cQj7KNPSvkLfPAb+QytIFtCwvZZ8jdmUiekXCmnTgc/hZOcoB3BCe4b+ h6+DHXl4Yg77lrrX/u9cBxUBOG9994M= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-6gXVP117OFivLS90yj4GLA-1; Wed, 06 Sep 2023 07:50:26 -0400 X-MC-Unique: 6gXVP117OFivLS90yj4GLA-1 Received: by mail-io1-f69.google.com with SMTP id ca18e2360f4ac-794c719e2fbso264043839f.1 for ; Wed, 06 Sep 2023 04:50:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694001025; x=1694605825; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7t4b3oY6bbyjLQ2Tj5MyahZzMP/RtnltuHJzxDNxgiU=; b=AWYBs5Hdc8x+WLzhndOg4PbJf4uu8srCqUqtkgDB1KrL8IsKX/rZjEnv33Zfzil1CL 2H6PZtPCq8a00mXBcp5ld9ztNra8myDerYD4fvucOThVTW4v9opPlct77WXXaX+1mnGi pLSwSVqxCPAXw2J9/LrlpdZ/2QSok8k9cw71bMW/whY3BjFbw8UvzvMfab93SmzDoBgt q+wji4GAXvhKCVYQVBk7oWZU4VvCFQ0IuXssDpy5jbD+EYr5VwW66ch5nxw+lTc66Zhb sz4LjrPoX0Mo2SDH6xjoPOKhVt362eRH5ErWegSP1g/A6eLhSHweWtYFgW+bAZR1c2X2 m9LQ== X-Gm-Message-State: AOJu0YxgLSkTlLOOvEJbsveHUkQxETZw75PV8QclmQAjj0GkKrFkErUa mqQyAKBW79A2rn0qH6IiVrZZhboOf2yO/7bMpRBWuFcYqa9tMn8ZRiNh19K66/QoF60uFZdyhu8 2QW24fYqN671f8odkzCjI14oOzUYJBNrGgw8tR/N2mHuN1Q== X-Received: by 2002:a05:6e02:13d4:b0:34d:ff6c:3e22 with SMTP id v20-20020a056e0213d400b0034dff6c3e22mr16137911ilj.20.1694001025453; Wed, 06 Sep 2023 04:50:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvzkRnt9bplP7Zxa4FtNDixJBsd59yTyzUZkYgljYgci8O6b0F11beKpCfu3j1IbmvK6LK/rr2dTxcvJo+sPY= X-Received: by 2002:a05:6e02:13d4:b0:34d:ff6c:3e22 with SMTP id v20-20020a056e0213d400b0034dff6c3e22mr16137898ilj.20.1694001025211; Wed, 06 Sep 2023 04:50:25 -0700 (PDT) MIME-Version: 1.0 References: <20230901232843.3050666-1-tom@tromey.com> In-Reply-To: <20230901232843.3050666-1-tom@tromey.com> From: Alexandra Petlanova Hajkova Date: Wed, 6 Sep 2023 13:50:13 +0200 Message-ID: Subject: Re: [PATCH] Simplify block_find_symbol To: Tom Tromey Cc: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000005b7efc0604af5960" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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: --0000000000005b7efc0604af5960 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Sep 2, 2023 at 1:29=E2=80=AFAM Tom Tromey wrote: > block_find_symbol takes a callback function, but only two callbacks > are ever passed to it -- and they are similar enough that it seems > cleaner to just have block_find_symbol do the work itself. Also, > block_find_symbol can take a lookup_name_info as an argument, > following the general idea of pushing the construction of these > objects as high in the call chain as feasible. > > Regression tested on x86-64 Fedora 38. > --- > gdb/block.c | 43 +++++++++++-------------------------------- > gdb/block.h | 36 ++++++------------------------------ > gdb/symfile-debug.c | 10 +++------- > gdb/symtab.c | 13 +++++++------ > 4 files changed, 27 insertions(+), 75 deletions(-) > > diff --git a/gdb/block.c b/gdb/block.c > index 8e1b6ec88d4..6ada69c388f 100644 > --- a/gdb/block.c > +++ b/gdb/block.c > @@ -778,46 +778,25 @@ block_lookup_symbol_primary (const struct block > *block, const char *name, > /* See block.h. */ > > struct symbol * > -block_find_symbol (const struct block *block, const char *name, > - const domain_enum domain, > - block_symbol_matcher_ftype *matcher, void *data) > +block_find_symbol (const struct block *block, const lookup_name_info > &name, > + const domain_enum domain, struct symbol **stub) > { > - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); > - > /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */ > gdb_assert (block->superblock () =3D=3D NULL > || block->superblock ()->superblock () =3D=3D NULL); > > - for (struct symbol *sym : block_iterator_range (block, &lookup_name)) > + for (struct symbol *sym : block_iterator_range (block, &name)) > { > - /* MATCHER is deliberately called second here so that it never sees > - a non-domain-matching symbol. */ > - if (sym->matches (domain) > - && matcher (sym, data)) > - return sym; > - } > - return NULL; > -} > - > -/* See block.h. */ > + if (!sym->matches (domain)) > + continue; > > -int > -block_find_non_opaque_type (struct symbol *sym, void *data) > -{ > - return !TYPE_IS_OPAQUE (sym->type ()); > -} > - > -/* See block.h. */ > - > -int > -block_find_non_opaque_type_preferred (struct symbol *sym, void *data) > -{ > - struct symbol **best =3D (struct symbol **) data; > + if (!TYPE_IS_OPAQUE (sym->type ())) > + return sym; > > - if (!TYPE_IS_OPAQUE (sym->type ())) > - return 1; > - *best =3D sym; > - return 0; > + if (stub !=3D nullptr) > + *stub =3D sym; > + } > + return nullptr; > } > > /* See block.h. */ > diff --git a/gdb/block.h b/gdb/block.h > index f132d351bb6..3a197e63754 100644 > --- a/gdb/block.h > +++ b/gdb/block.h > @@ -556,39 +556,15 @@ extern struct symbol *block_lookup_symbol_primary > (const struct block *block, > const char *name, > const domain_enum > domain); > > -/* The type of the MATCHER argument to block_find_symbol. */ > - > -typedef int (block_symbol_matcher_ftype) (struct symbol *, void *); > - > -/* Find symbol NAME in BLOCK and in DOMAIN that satisfies MATCHER. > - DATA is passed unchanged to MATCHER. > - BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. */ > +/* Find symbol NAME in BLOCK and in DOMAIN. This will return a > + matching symbol whose type is not a "opaque", see TYPE_IS_OPAQUE. > + If STUB is non-NULL, an otherwise matching symbol whose type is a > + opaque will be stored here. */ > > extern struct symbol *block_find_symbol (const struct block *block, > - const char *name, > + const lookup_name_info &name, > const domain_enum domain, > - block_symbol_matcher_ftype > *matcher, > - void *data); > - > -/* A matcher function for block_find_symbol to find only symbols with > - non-opaque types. */ > - > -extern int block_find_non_opaque_type (struct symbol *sym, void *data); > - > -/* A matcher function for block_find_symbol to prefer symbols with > - non-opaque types. The way to use this function is as follows: > - > - struct symbol *with_opaque =3D NULL; > - struct symbol *sym > - =3D block_find_symbol (block, name, domain, > - block_find_non_opaque_type_preferred, > &with_opaque); > - > - At this point if SYM is non-NULL then a non-opaque type has been foun= d. > - Otherwise, if WITH_OPAQUE is non-NULL then an opaque type has been > found. > - Otherwise, the symbol was not found. */ > - > -extern int block_find_non_opaque_type_preferred (struct symbol *sym, > - void *data); > + struct symbol **stub); > > /* Given a vector of pairs, allocate and build an obstack allocated > blockranges struct for a block. */ > diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c > index 9db5c47a8ce..233cf3390e5 100644 > --- a/gdb/symfile-debug.c > +++ b/gdb/symfile-debug.c > @@ -260,23 +260,19 @@ objfile::lookup_symbol (block_enum kind, const char > *name, domain_enum domain) > const struct blockvector *bv =3D stab->blockvector (); > const struct block *block =3D bv->block (kind); > > - sym =3D block_find_symbol (block, name, domain, > - block_find_non_opaque_type_preferred, > - &with_opaque); > + sym =3D block_find_symbol (block, lookup_name, domain, &with_opaque); > > /* Some caution must be observed with overloaded functions > and methods, since the index will not contain any overload > information (but NAME might contain it). */ > > - if (sym !=3D NULL > - && symbol_matches_search_name (sym, lookup_name)) > + if (sym !=3D nullptr) > { > retval =3D stab; > /* Found it. */ > return false; > } > - if (with_opaque !=3D NULL > - && symbol_matches_search_name (with_opaque, lookup_name)) > + if (with_opaque !=3D nullptr) > retval =3D stab; > > /* Keep looking through other psymtabs. */ > diff --git a/gdb/symtab.c b/gdb/symtab.c > index d8ce2bf8482..29ca418d1e9 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -2675,9 +2675,10 @@ basic_lookup_transparent_type_quick (struct objfile > *objfile, > > bv =3D cust->blockvector (); > block =3D bv->block (block_index); > - sym =3D block_find_symbol (block, name, STRUCT_DOMAIN, > - block_find_non_opaque_type, NULL); > - if (sym =3D=3D NULL) > + > + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); > + sym =3D block_find_symbol (block, lookup_name, STRUCT_DOMAIN, nullptr); > + if (sym =3D=3D nullptr) > error_in_psymtab_expansion (block_index, name, cust); > gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); > return sym->type (); > @@ -2696,13 +2697,13 @@ basic_lookup_transparent_type_1 (struct objfile > *objfile, > const struct block *block; > const struct symbol *sym; > > + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); > for (compunit_symtab *cust : objfile->compunits ()) > { > bv =3D cust->blockvector (); > block =3D bv->block (block_index); > - sym =3D block_find_symbol (block, name, STRUCT_DOMAIN, > - block_find_non_opaque_type, NULL); > - if (sym !=3D NULL) > + sym =3D block_find_symbol (block, lookup_name, STRUCT_DOMAIN, > nullptr); > + if (sym !=3D nullptr) > { > gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); > return sym->type (); > -- > 2.41.0 > > Things are simpler and nicer this way indeed. I tested this on ppc64le Fedora Rawhide and I can see no regressions. --0000000000005b7efc0604af5960--