public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org>
Cc: Bruno Larsen <blarsen@redhat.com>
Subject: Re: [PATCH 1/2] gdb/c++: validate 'using' directives based on the current line
Date: Wed, 09 Nov 2022 10:03:36 -0700	[thread overview]
Message-ID: <87cz9w2h7b.fsf@tromey.com> (raw)
In-Reply-To: <20221026155053.3394792-2-blarsen@redhat.com> (Bruno Larsen via Gdb-patches's message of "Wed, 26 Oct 2022 17:50:53 +0200")

>>>>> "Bruno" == Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:

Bruno> When asking GDB to print a variable from an imported namespace, we only
Bruno> want to see variables imported in lines that the inferior has already
Bruno> gone through, as is being tested last in gdb.cp/nsusing.exp. However
Bruno> with the proposed change to gdb.cp/nsusing.exp, we get the following
Bruno> failures:

Thanks for the patch.  I have a few minor comments.

Bruno> +      /* If the using directive was below the place we are stopped at,
Bruno> +	 do not use this directive.  */
Bruno> +      if (!valid_line (current, boundary_sal.line))
Bruno> +	continue;

'valid_line' seems like a kind of generic name for this.
Maybe it should be a method on 'using_direct'?

Bruno> +  /* When was the using directive was declared.
Bruno> +     If this was not supplied, set it to 0 so the directive is always valid.
Bruno> +     Since the type changes from DWARF 4 to DWARF 5, we must check
Bruno> +     the type of the attribute.  */
Bruno> +  struct attribute *decl_line = dwarf2_attr (die, DW_AT_decl_line, cu);
Bruno> +  unsigned int line;
Bruno> +  if (decl_line == nullptr)
Bruno> +    line = 0;
Bruno> +  else if (decl_line->form_is_constant ())
Bruno> +    line = decl_line->constant_value (0);
Bruno> +  else if (decl_line->form_is_unsigned ())
Bruno> +    line = decl_line->as_unsigned ();
Bruno> +  else
Bruno> +    gdb_assert_not_reached ();

Asserting here seems wrong, because it means gdb will crash in response
to invalid DWARF.  It's better to emit a complaint and fall back to some
default, or ignore the directive.

Bruno>  	  std::vector<const char *> excludes;
Bruno> +	  struct attribute *decl_line = dwarf2_attr (die, DW_AT_decl_line, cu);
Bruno> +	  unsigned int line;
Bruno> +	  if (decl_line == nullptr)
Bruno> +	    line = 0;
Bruno> +	  else if (decl_line->form_is_constant ())
Bruno> +	    line = decl_line->constant_value (0);
Bruno> +	  else if (decl_line->form_is_unsigned ())
Bruno> +	    line = decl_line->as_unsigned ();
Bruno> +	  else
Bruno> +	    gdb_assert_not_reached ();

Here too.
If there's a lot of duplicated code maybe it should be factored into a
new function (I didn't look).

Bruno> +bool
Bruno> +valid_line (struct using_direct *using_dir,

Seems like this could be const; and if it's a method it could be
const-qualified.

Bruno> +      return using_dir->decl_line <= curr_sal.line
Bruno> +	     || using_dir->decl_line >= boundary;

GNU style would parenthesize this.

Bruno>    struct using_direct *next;
 
Bruno> +  unsigned int decl_line;

Should have a comment.

Tom

  reply	other threads:[~2022-11-09 17:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 15:50 [PATCH 0/2] Improve handling of using directives Bruno Larsen
2022-10-26 15:50 ` [PATCH 1/2] gdb/c++: validate 'using' directives based on the current line Bruno Larsen
2022-11-09 17:03   ` Tom Tromey [this message]
2022-11-11 14:44   ` Andrew Burgess
2022-10-26 15:50 ` [PATCH 2/2] gdb/c++: Detect ambiguous variables in imported namespaces Bruno Larsen
2022-11-09 17:11   ` Tom Tromey
2022-11-11 15:34     ` Bruno Larsen
2022-11-11 16:37       ` Tom Tromey
2022-11-11 14:30   ` Andrew Burgess

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=87cz9w2h7b.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=blarsen@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).