From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19651 invoked by alias); 14 Mar 2002 00:07:01 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 19583 invoked from network); 14 Mar 2002 00:07:00 -0000 Received: from unknown (HELO nevyn.them.org) (128.2.145.6) by sources.redhat.com with SMTP; 14 Mar 2002 00:07:00 -0000 Received: from drow by nevyn.them.org with local (Exim 3.35 #1 (Debian)) id 16lIlw-00072d-00; Wed, 13 Mar 2002 19:07:08 -0500 Date: Wed, 13 Mar 2002 16:07:00 -0000 From: Daniel Jacobowitz To: Zack Weinberg Cc: gdb@sources.redhat.com Subject: Re: Suggestion: Detect inconsistent structure definitions Message-ID: <20020313190708.B26841@nevyn.them.org> Mail-Followup-To: Zack Weinberg , gdb@sources.redhat.com References: <20020313182221.GE8197@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020313182221.GE8197@codesourcery.com> User-Agent: Mutt/1.3.23i X-SW-Source: 2002-03/txt/msg00124.txt.bz2 On Wed, Mar 13, 2002 at 10:22:22AM -0800, Zack Weinberg wrote: > Consider the following two source files: > > -- a.c -- > struct A { > int a; > int b; > }; > > struct A a = { 1, 2 }; > > -- b.c -- > struct A { > char a; > char b; > }; > > extern struct A a; > > int main(void) { > if (a.a == 1 && b.a == 2) > return 0; > else > return 1; > } > > -- > It is obvious that the complete program consisting of these two files > is buggy: the declarations of struct A do not match. However, the > program will compile, link, and execute with no complaints, just an > unexpected return value. > > When the program is large and complicated, this sort of bug can be > near-impossible to find, especially when the structure type > declaration _is_ properly isolated in a header file, but other headers > (possibly from third-party libraries) have issued inconsistent > typedefs/#defines for the aggregate's member types. I just spent two > days chasing exactly this problem in an INN installation. > > The compiler and linker do not have enough information to detect the > bug, but gdb does; each object file's debug info will contain a type > declaration for struct A, and they won't match. With stabs, it's > obvious just doing It's not clear that GDB does. Consider a slightly modified example: > -- a.c -- > struct A { > int a; > int b; > }; > > static struct A a = { 1, 2 }; > > -- b.c -- > struct A { > char a; > char b; > }; > > static struct A a = {3, 4}; > > int main(void) { > if (a.a == 1 && b.a == 2) > return 0; > else > return 1; > } > > -- OK, that's a somewhat degenerate case, but my point holds. When do we have enough information to know that two references are 'supposed' to be of the same type, rather than an implementation-private type? And in stabs, at least, no debug information appears to be emitted for 'extern' statements, so we don't know if a file referenced the type it had a different definition of or not. Perhaps a command to show types with multiple different definitions? Please file a GNATS PR so that this idea doesn't get forgotten. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer