From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29776 invoked by alias); 1 Apr 2004 14:23:25 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 29748 invoked from network); 1 Apr 2004 14:23:19 -0000 Received: from unknown (HELO atlantic.mail.pas.earthlink.net) (207.217.120.179) by sources.redhat.com with SMTP; 1 Apr 2004 14:23:19 -0000 Received: from ip216-26-76-226.dsl.du.teleport.com ([216.26.76.226] helo=grayscale.canids) by atlantic.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 1B936E-0000Xv-00 for gdb-patches@sources.redhat.com; Thu, 01 Apr 2004 06:23:19 -0800 Received: from grayscale.canids (localhost [127.0.0.1]) by grayscale.canids (Postfix) with ESMTP id 08335145 for ; Thu, 1 Apr 2004 06:23:18 -0800 (PST) From: Felix Lee To: gdb-patches@sources.redhat.com Subject: stabsread, struct wipeout, missing type Date: Thu, 01 Apr 2004 14:23:00 -0000 Message-Id: <20040401142319.08335145@grayscale.canids> X-SW-Source: 2004-04/txt/msg00016.txt.bz2 sometimes "ptype foo" will print "struct " 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 " instead of "char *". 2004-04-01 Felix Lee * 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);