From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3990 invoked by alias); 9 Nov 2019 06:54:22 -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 3976 invoked by uid 89); 9 Nov 2019 06:54:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.6 required=5.0 tests=AWL,BAYES_00,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_PASS,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy= X-HELO: mail-oi1-f172.google.com Received: from mail-oi1-f172.google.com (HELO mail-oi1-f172.google.com) (209.85.167.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Nov 2019 06:54:20 +0000 Received: by mail-oi1-f172.google.com with SMTP id l20so7288271oie.10 for ; Fri, 08 Nov 2019 22:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5TvgSOeEMMJHKOJ+HtxBtouhTR7s8NcYp5k2/4u6Bk0=; b=jvh+UGSI1eMhkwUdFPLTQ04uOt4LEp9XIOvUoDrbR+zQHAdCKjJPk0y/BoO22V2j7v LHwCm6TXWUs5UGUC5Kcuw1l4UGRQYVMl27aNCTjAf885iwIJo7nmYOaCB1WAS64RyuNy BQWjrgUYc/Z6Sr0IeFzFrD6+WBntRRzHwiy36H2Zc0TptHzjsxGbz/bOdZW2w3V4oBkY N/+DYGb26I/VKkXiruUZIe4G5MJstMEOQArnkX+H40lCapPnAjt9vG94x7hEbHcXjNtS lstJYDXpqBmKIdT5/meQt9rNELR6mZwKo07djEwZuK+RRMoAm/vBhwDmm5RDtiBjCmgR cIww== MIME-Version: 1.0 References: <20190920192017.15293-1-tromey@adacore.com> <20190920192017.15293-3-tromey@adacore.com> <20190923141655.GH4962@embecosm.com> In-Reply-To: <20190923141655.GH4962@embecosm.com> From: "Christian Biesinger via gdb-patches" Reply-To: Christian Biesinger Date: Sat, 09 Nov 2019 06:54:00 -0000 Message-ID: Subject: Re: [PATCH v2 2/8] Search global block from basic_lookup_symbol_nonlocal To: Andrew Burgess Cc: Tom Tromey , gdb-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-11/txt/msg00252.txt.bz2 I just realized I never responded to this. I just wanted to mention a couple of things, below. On Mon, Sep 23, 2019 at 9:16 AM Andrew Burgess wrote: > > * Christian Biesinger [2019-09-21 13:31:30 +0900]: > > > On Sat, Sep 21, 2019 at 4:20 AM Tom Tromey wrote: > > > From: Andrew Burgess > > > > > > This changes lookup_global_symbol to look in the global block > > > of the passed-in block. If no block was passed in, it reverts to the > > > previous behavior. > > > > > > This change is needed to ensure that 'FILENAME'::NAME lookups work > > > properly. As debugging Pedro's test case showed, this was not working > > > properly in the case where multiple identical names could be found > > > (the one situation where this feature is truly needed :-). > > > > This further extends the situations where lookup_global_symbols checks > > a local scope first (currently only objfile) but lookup_static_symbol > > doesn't. > > [ Note, in the below I talk about "my patch", I really mean mine and > Tom's as my suggested rework was based on his original patch. ] > > I didn't fully understand this for two reasons, first, you say > "further extends", however, both lookup_global_symbol and > lookup_static_symbol pre-patch, both just call > lookup_global_or_static_symbol. And I couldn't see any code in > lookup_global_or_static_symbol that was conditional on global or > static lookup. So my question is where is the existing situation in > which lookup_global_symbol searches a local scope first? I ask only > so I can try to understand your question and my change in relation to > the existing code. lookup_static_symbol always passes nullptr as the objfile to lookup_global_or_static_symbol, unlike lookup_global_symbol, which is the difference I meant. > Second, I wanted to better understand what you mean by "local scope". > My understanding of lookup_global_symbol is that it searches every > global block from every object file in some particular order. The > change here is simply that it makes more sense to search the global > scope relating to the current compilation unit before searching other > global scopes. I can fully understand that this can be referred to as > a "local scope", I just wanted to make sure we're all agreed on what's > happening here. lookup_global_symbol takes an optional block argument; it starts the search in the objfile associated with that block (or did, before your patch). The argument I was making is that it probably makes sense for both global and static lookups to take a block (or global block) argument for starting the search, and that this is more important for static symbols because there are more likely to be name collisions there. My apologies for expressing myself poorly. > I think it makes sense. If we have multiple global symbols with the > same name, we should find the one corresponding to the current scope I > think. That feels like what I'd expect to happen. And especially as > when we do a FILE::VAR lookup we end up in lookup_global_symbol with > the block corresponding to FILE. If we then ignore that block and > search all global scopes in the predefined order then we will always > find the same global symbol, which is certainly wrong. > > > I would think that > > lookup_static_symbol is even more likely to need that check, since > > static symbols are probably (?) more likely to share the same name. Is > > my interpretation wrong? > > No, I think you are very right.... > > But... > > There are currently 5 uses of lookup_static_symbol that I could find, > 2 of these are in: > > d-namespace.c:find_symbol_in_baseclass > cp-namespace.c:cp_lookup_nested_symbol_1 > > These are interesting because almost immediately before calling > lookup_static_symbol we call lookup_symbol_in_static_block, which I > think is solving the same problem as this proposed patch. > > Then we have a call to lookup_static_symbol in: > > symtab.c:lookup_symbol_aux > > This calls lookup_static_symbol as the last fallback action after > calling the language specific hook la_lookup_symbol_nonlocal. I've > only audited some languages, but for those I've looked at they all > call lookup_symbol_in_static_block as one of their early actions: > > symtab.c:basic_lookup_symbol_nonlocal (for C, Pascal) > cp-namespace.c:cp_lookup_bare_symbol (for C++, Fortran) > cp-namespace.c:cp_lookup_bare_symbol (for Fortran) > d-namespace.c:d_lookup_symbol (for D) > rust-lang.c:rust_lookup_symbol_nonlocal (for Rust) > > That leaves two uses of lookup_static_symbol, these are: > > python/py-symbol.c:gdbpy_lookup_static_symbol > d-namespace.c:d_lookup_nested_symbol > > In these cases there is no call to lookup_symbol_in_static_block. I > would need to investigate more to see if these are working as expected > or not. I suspect the python use case might not always do what a user > expects, as it searches static symbols in a predefined order, if we > have multiple with the same name we would always find the same one > first, but we'd probably expect to find one from the current object > file before one from a different object file. As for the D use case, > I don't know D, so don't feel qualified to judge. The symbol lookup code is so confusing :( For someone like me, new to GDB, it is difficult to understand this code -- why does global lookup take a block but local doesn't. Apparently the answer is that the callers do the static block lookup. But.. why? Anyway that's the context for my questions. Thanks for your work in this area! Christian