public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error
@ 2014-10-01 17:57 dje at google dot com
  2014-11-27  0:23 ` [Bug gdb/17450] " dje at google dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dje at google dot com @ 2014-10-01 17:57 UTC (permalink / raw)
  To: gdb-prs

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/17450] resolve_dynamic_type_internal misunderstands check_typedef -> internal error
  2014-10-01 17:57 [Bug gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error dje at google dot com
@ 2014-11-27  0:23 ` dje at google dot com
  2014-11-27 23:09 ` jan.kratochvil at redhat dot com
  2014-11-27 23:49 ` dje at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: dje at google dot com @ 2014-11-27  0:23 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from dje at google dot com ---
See also PR 17642

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/17450] resolve_dynamic_type_internal misunderstands check_typedef -> internal error
  2014-10-01 17:57 [Bug gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error dje at google dot com
  2014-11-27  0:23 ` [Bug gdb/17450] " dje at google dot com
@ 2014-11-27 23:09 ` jan.kratochvil at redhat dot com
  2014-11-27 23:49 ` dje at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jan.kratochvil at redhat dot com @ 2014-11-27 23:09 UTC (permalink / raw)
  To: gdb-prs

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

Jan Kratochvil <jan.kratochvil at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jan.kratochvil at redhat dot com
         Resolution|---                         |DUPLICATE

--- Comment #2 from Jan Kratochvil <jan.kratochvil at redhat dot com> ---
I do not see how this is clang specific.

echo 'class c { char x[0]; char more_x[42]; };'|clang++ -c -g -o o.out -x c++ -
gdb ./o.out

does not crash for me.  IMO there have to be at least two CUs to make there the
stub type but then it is PR 17642.

*** This bug has been marked as a duplicate of bug 17642 ***

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gdb/17450] resolve_dynamic_type_internal misunderstands check_typedef -> internal error
  2014-10-01 17:57 [Bug gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error dje at google dot com
  2014-11-27  0:23 ` [Bug gdb/17450] " dje at google dot com
  2014-11-27 23:09 ` jan.kratochvil at redhat dot com
@ 2014-11-27 23:49 ` dje at google dot com
  2 siblings, 0 replies; 4+ messages in thread
From: dje at google dot com @ 2014-11-27 23:49 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from dje at google dot com ---
Ahem.
Just because I report a bug I'm seeing with clang does not mean I'm claiming
the bug is clang specific.
Sheesh.

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-27 23:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-01 17:57 [Bug gdb/17450] New: resolve_dynamic_type_internal misunderstands check_typedef -> internal error dje at google dot com
2014-11-27  0:23 ` [Bug gdb/17450] " dje at google dot com
2014-11-27 23:09 ` jan.kratochvil at redhat dot com
2014-11-27 23:49 ` dje at google dot com

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).