Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: Stephan Rohr <stephan.rohr@intel.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: fix path expression for anonymous union members
Date: Thu, 8 Oct 2026 12:16:00 -0700	[thread overview]
Message-ID: <5afb25c6-cdb8-4f6c-8944-26ad1acb7497@redhat.com> (raw)
In-Reply-To: <20261007082731.728382-1-stephan.rohr@intel.com>

Hi,

Thanks for the patch.

On 10/7/26 1:27 AM, Stephan Rohr wrote:
> 
> Extract the required logic from cplus_describe_child and use it to get
> the correct index of the field within the parent type.  With this change
> the path expression is computed correctly:
> 
>    interpret mi "-var-info-path-expression var1.public.1_anonymous.public.c"
>    ^done,path_expr="((s).c)"
> 

I think this is the correct approach.

> I modified the related test to include both base type and access layers.
> However, to correctly parse the base types within the MI var tree I had to
> introduce a heuristic that if the child's type is equal to child's name
> then it is a base type, and the path expression is different in this case.

Let's look at this a bit in the actual change:

> diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
> index cd7e0a61189..465cf3fd69c 100644
> --- a/gdb/testsuite/lib/mi-support.exp
> +++ b/gdb/testsuite/lib/mi-support.exp
> @@ -2401,6 +2401,10 @@ namespace eval ::varobj_tree {
>         set is_compound 0
>       }
>   
> +    if {$type eq $name} {
> +	# This is the base type.
> +	return "((class $type) $path_parent(path_expr))"
> +    }
>       if {[string index $parent(type) end] == "\]"} {
>         # Parent is an array.
>         return "($path_parent(path_expr))\[$name\]"

IIUC, if we have a construct like:

class Outer {
public:
   struct Inner { int x; };
   Inner Inner;
};

Outer o;

Then the proposed heuristic change would return "((class Inner) o)".
However, the real path should be "((o).Inner)".

While this is probably unlikely to actually affect anything,
perhaps we can tighten this a little bit by applying the heuristic
only if its parent is not one of these artificial access parents?

That is, something like:

proc is_cplus_fake_child {variable} {
   upvar #0 $variable varobj
   return [string equal $varobj(type) ""]
}

# Note that proc get_path_expr walks parent_variable -- we need to save
# it before that.
if {$type eq $name && is_cplus_fake_child $saved_parent} {
    return #...
}

That might be a simple change to mitigate some future frustration.

Keith


      reply	other threads:[~2026-10-08 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07  8:27 Stephan Rohr
2026-10-08 19:16 ` Keith Seitz [this message]

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=5afb25c6-cdb8-4f6c-8944-26ad1acb7497@redhat.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=stephan.rohr@intel.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