This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug mi/21381] Invalid -var-info-path-expression result with anonymous union in std::string


https://sourceware.org/bugzilla/show_bug.cgi?id=21381

--- Comment #3 from Simon Marchi <simon.marchi at ericsson dot com> ---
I think I identified the problem.  In c_is_path_expr_parent, we are doing this:

field_name = TYPE_FIELD_NAME (parent_type, var->index);

var->index is the index of the current varobj (a class field) in its parent. 
The problem is that the varobj index in its parent doesn't translate directly
to an index in the array of fields of the type of its parent, which is assumed
by the statement above.

That's because while the fields array of the class type looks like this:

[0] public field npos
[1] private field _M_dataplus
[2] private field _M_string_length
[3] private field <anonymous union>

... the varobj tree looks like:

string
  public
    npos
  private
    _M_dataplus
    _M_string_length
    2_anonymous (name given to the anonymous union by gdb)

When calling c_is_path_expr_parent with var = 2_anonymous, var->index is 2
(it's the index in its varobj parent).  This index is used to lookup the field
type in the parent's type's field table, which erroneously ends up referring to
_M_string_length.  It returns true instead of false, which ends up in an empty
string being used as a path instead of searching higher in the varobj tree for
something that really is a path expression parent.

So, like in cplus_describe_child, we have to iterate on the parent's type's
field table to find the 3rd private field (as in the proposed patch).  That
will find the right field.

In cplus_describe_child, we could probably assert that parent_expression is not
empty.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]