Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* stabsread, struct wipeout, missing type
@ 2004-04-01 14:23 Felix Lee
  2004-04-01 20:22 ` Jim Blandy
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Lee @ 2004-04-01 14:23 UTC (permalink / raw)
  To: gdb-patches

sometimes "ptype foo" will print "struct <unknown>" when it
should be "char *".

consider a program that has these files
    ace.h:
        typedef struct ace ace_t;

    ace2.h:
        #include "ace.h"
        struct ace { const char * a_name; };

    bit.c:
        typedef const char * bit_t;
        #include "ace2.h"

    cap.c:
        #include "ace2.h"
        typedef const char * cap_t;

after linking, the stabs look like this:
23     BINCL  0      0      000008ab 1      bit.c
24     LSYM   0      0      00000000 767    bit_t:t(1,1)=(1,2)=*(0,2)
25     BINCL  0      0      000007f7 793    ace2.h
26     BINCL  0      0      000006cf 800    ace.h
27     LSYM   0      0      00000000 806    ace_t:t(3,1)=(3,2)=xsace:
28     EINCL  0      0      00000000 0
29     LSYM   0      0      00000000 832    ace:T(3,2)=s4a_name:(1,2),0,32;;
30     EINCL  0      0      00000000 0

56     BINCL  0      0      0000077e 878    cap.c
57     BINCL  0      0      0000090c 793    ace2.h
58     EXCL   0      0      000006cf 800    ace.h
59     LSYM   0      0      00000000 884    ace:T(3,2)=s4a_name:(2,1)=*(0,2),0,32;;
60     EINCL  0      0      00000000 0
61     LSYM   0      0      00000000 924    cap_t:t(1,1)=(2,1)

note that ace.h got EXCL'd, but ace2.h didn't,
because the stabs for ace2.h are different,
because they depend on who mentions "const char *" first.

when gdb sees the second occurrence of struct ace,
it looks up the type number (3,2),
which refers to ace.h,
which is the same as the earlier ace.h,
so gdb reuses the previously-defined ace type.

then gdb complains about struct wipeout and ignores the second definition,
which means it misses the type definition (2,1)=*(0,2),
which means cap_t uses an undefined type,
so "ptype cap_t" prints "struct <unknown>" instead of "char *".

2004-04-01  Felix Lee  <felix+log1@specifixinc.com>

        * stabsread.c (read_struct_type): Always read struct types,
        so we don't miss any type definitions.

--- stabsread.c.~1.76.~	2004-03-29 09:48:14.000000000 -0800
+++ stabsread.c	2004-03-30 08:56:05.000000000 -0800
@@ -3334,14 +3334,18 @@ read_struct_type (char **pp, struct type
 
      Obviously, GDB can't fix this by itself, but it can at least avoid
      scribbling on existing structure type objects when new definitions
-     appear.  */
+     appear.
+
+     GDB has to read the struct type in any case, since it may contain
+     definitions of other types that will be needed elsewhere.  Creating a
+     new type is not really the right thing to do, but it's better than
+     nothing. */
+
   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
          || TYPE_STUB (type)))
     {
       complain_about_struct_wipeout (type);
-
-      /* It's probably best to return the type unchanged.  */
-      return type;
+      type = alloc_type (TYPE_OBJFILE (type));
     }
 
   back_to = make_cleanup (null_cleanup, 0);


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

end of thread, other threads:[~2004-04-02 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-01 14:23 stabsread, struct wipeout, missing type Felix Lee
2004-04-01 20:22 ` Jim Blandy
2004-04-02 22:17   ` Jim Blandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox