Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org>
Cc: Felix Willgerodt <felix.willgerodt@intel.com>
Subject: Re: [PATCH 1/1] gdb: Enable complete to show members of anonymous classes/structs.
Date: Fri, 18 Nov 2022 13:33:28 -0700	[thread overview]
Message-ID: <877czsq9yf.fsf@tromey.com> (raw)
In-Reply-To: <20220906072153.508130-1-felix.willgerodt@intel.com> (Felix Willgerodt via Gdb-patches's message of "Tue, 6 Sep 2022 09:21:53 +0200")

>>>>> "Felix" == Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> writes:

Hello.  Thank you for the patch.  I'm sorry it took so long to review,
but I appreciate your persistence in pinging it.

Felix> After:
Felix> ~~~
Felix> (gdb) p unique_name_foo
Felix> $1 = 5
Felix> (gdb) complete p unique_name_fo
Felix> p unique_name_foo
Felix> (gdb)
Felix> ~~~

The outcome seems like what we want.

Felix> As we are able to print the member we should be able to complete on it.
Felix> GDB doesn't look at "this" and its members for complete, while it does
Felix> when printing.  So I tried fixing that.
Felix> I saw that "this" is always represented as a PTR type with the symbol
Felix> class LOC_COMPUTED (with g++ 11.3.1, clang++ 10.0.1 and icpx 2022.1).

Felix> Not knowing too much about LOC_COMPUTED, I am assuming that this is the right
Felix> symbol class for this case and that we should adjust
Felix> completion_list_add_fields() for it.
Felix> But it could very well be that I missed something.  Any comments welcome!

I don't think there's any requirement that 'this' be LOC_COMPUTED.

LOC_COMPUTED just means that the symbol's address is computed via some
function call (normally into the DWARF code to handle an exprloc).
However, nothing says it couldn't be LOC_REGISTER or LOC_ARG or
something.

Felix> +  if (sym->aclass () == LOC_TYPEDEF
Felix> +      || (sym->aclass () == LOC_COMPUTED && t->code () == TYPE_CODE_PTR))

It seems like this could match many local symbols -- like, nearly any
local variable that has pointer type.  But, completing on these fields
is not desirable; instead you only want to examine 'this'.

Instead you probably want something like what lookup_symbol_aux does:

  if (is_a_field_of_this != NULL && domain != STRUCT_DOMAIN)
    {
      result = lookup_language_this (langdef, block);

      if (result.symbol)

That is, use the current language (or in this case perhaps some search
language, I don't really know) to find the name of 'this', then use it
if this symbol matches.  Probably this should be done in the caller to
avoid a lot of repeated calls.

Felix> +	for (int j = TYPE_N_BASECLASSES (t); j < t->num_fields (); j++)
Felix>  	  if (t->field (j).name ())
Felix>  	    completion_list_add_name (tracker, sym->language (),

To me this loop looks incomplete, because it seems like it ought to walk
over superclasses as well.  Not your bug but if you really want this to
work correctly, it's worth fixing (and adding a test for).

Tom

  parent reply	other threads:[~2022-11-18 20:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06  7:21 Felix Willgerodt via Gdb-patches
2022-09-06 14:41 ` Bruno Larsen via Gdb-patches
2022-09-20  9:48 ` [Ping] " Willgerodt, Felix via Gdb-patches
2022-10-17  8:33 ` [Ping v2] " Willgerodt, Felix via Gdb-patches
2022-10-26 12:06 ` [Ping v3] " Willgerodt, Felix via Gdb-patches
2022-11-08 11:00 ` [Ping v4] " Willgerodt, Felix via Gdb-patches
2022-11-18 20:33 ` Tom Tromey [this message]
2022-11-24 12:58   ` Willgerodt, Felix via Gdb-patches

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=877czsq9yf.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=felix.willgerodt@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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