public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3] Add name canonicalization for C
Date: Thu, 1 Dec 2022 11:06:34 -0500	[thread overview]
Message-ID: <24ea42d1-afe5-f876-b71a-1883d46d8cb4@simark.ca> (raw)
In-Reply-To: <20221107162356.3175221-4-tromey@adacore.com>

On 11/7/22 11:23, Tom Tromey via Gdb-patches wrote:
> PR symtab/29105 shows a number of situations where symbol lookup can
> result in the expansion of too many CUs.
> 
> What happens is that lookup_signed_typename will try to look up a type
> like "signed int".  In cooked_index_functions::expand_symtabs_matching,
> when looping over languages, the C++ case will canonicalize this type
> name to be "int" instead.  Then this method will proceed to expand
> every CU that has an entry for "int" -- i.e., nearly all of them.  A
> crucial component of this is that the caller, objfile::lookup_symbol,
> does not do this canonicalization, so when it tries to find the symbol
> for "signed int", it fails -- causing the loop to continue.
> 
> This patch fixes the problem by introducing name canonicalization for
> C.  The idea here is that, by making C and C++ agree on the canonical
> name when a symbol name can have multiple spellings, we avoid the bad
> behavior in objfile::lookup_symbol (and any other such code -- I don't
> know if there is any).
> 
> Unlike C++, C only has a few situations where canonicalization is
> needed.  And, in particular, due to the lack of overloading (thus
> avoiding any issues in linespec) and due to the way c-exp.y works, I
> think that no canonicalization is needed during symbol lookup -- only
> during symtab construction.  This explains why lookup_name_info is not
> touched.
> 
> The stabs reader is modified on a "best effort" basis.
> 
> The DWARF reader needed one small tweak in dwarf2_name to avoid a
> regression in dw2-unusual-field-names.exp.  I think this is adequately
> explained by the comment, but basically this is a scenario that should
> not occur in real code, only the gdb test suite.
> 
> lookup_signed_typename is simplified.  It used to search for two
> different type names, but now gdb can search just for the canonical
> form.
> 
> gdb.dwarf2/enum-type.exp needed a small tweak, because the
> canonicalizer turns "unsigned integer" into "unsigned int integer".
> It seems better here to use the correct C type name.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105

What's actually happening in the code is a bit over my head, I don't
think I could properly review this without spending several days diving
into it.  But I tested the cases I reported on the bug, and confirm the
over-expansion does not happen with the patch applied.

Simon

  reply	other threads:[~2022-12-01 16:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 16:23 [PATCH 0/3] Fix over-eager CU expansion with new DWARF reader Tom Tromey
2022-11-07 16:23 ` [PATCH 1/3] Remove language check from dwarf2_compute_name Tom Tromey
2022-12-01 15:16   ` Andrew Burgess
2022-11-07 16:23 ` [PATCH 2/3] Refactor cooked_index::do_finalize Tom Tromey
2022-12-01 15:34   ` Andrew Burgess
2022-11-07 16:23 ` [PATCH 3/3] Add name canonicalization for C Tom Tromey
2022-12-01 16:06   ` Simon Marchi [this message]
2022-12-01 16:29   ` Andrew Burgess
2022-12-01 17:56     ` Tom Tromey
2022-12-01 18:16       ` Tom Tromey
2022-12-01 23:23   ` Andrew Burgess
2022-12-02 14:39     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24ea42d1-afe5-f876-b71a-1883d46d8cb4@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).