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 gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error


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

            Bug ID: 17450
           Summary: resolve_dynamic_type_internal misunderstands
                    check_typedef -> internal error
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: dje at google dot com

Clang is emitting no bounds info for the "x" in
class c { char x[0]; char more_x[42]; };

This causes has_static_range for "x" to return false (lower bound is defaulted
to zero, upper bound is unknown), which in turn causes is_dynamic_type to
return true and we enter resolve_dynamic_type (which is just a wrapper on
resolve_dynamic_type_internal).

In the example at hand (I don't have an easy to provide testcase, at least not
yet), the type is defined in another CU so what resolve_dynamic_type gets is an
opaque type.  We then hit this assert in resolve_dynamic_struct and crash:

  gdb_assert (TYPE_NFIELDS (type) > 0);

resolve_dynamic_type_internal seems to not understand that check_typedef has
(at least) two main purposes:

1) check for typedefs (duh ... :-)),
2) AND resolve opaque types.

It's easy to understand this happening given how poorly named check_typedef is.

static struct type *
resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
                               int top_level)
{
  struct type *real_type = check_typedef (type);
  struct type *resolved_type = type;
  const struct dynamic_prop *prop;
  CORE_ADDR value;

  if (!is_dynamic_type_internal (real_type, top_level))
    return type;

  switch (TYPE_CODE (type))
    {

    ...

    case TYPE_CODE_STRUCT:
      resolved_type = resolve_dynamic_struct (type, addr);
      break;
    }

  ...
}

Note that we've called check_typedef, BUT we're passing type to
resolve_dynamic_struct not real_type.  If type is an opaque type we in fact do
want to pass real_type to resolve_dynamic_struct.

Either that or call check_typedef again in resolve_dynamic_struct.  Since this
collection of functions is all just implementation detail for
resolve_dynamic_type I'm ok with not sprinkling calls to check_typedef
everywhere it might be needed (and in fact since the function is so badly named
sprinkling it about doesn't improve readability).  It would be reasonable to
create a resolve_opaque_type function that handles this part of what
check_typedef does, and use that instead, but I'm ok with just passing
real_type to resolve_dynamic_struct here.

-- 
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]