Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Suggestion: Detect inconsistent structure definitions
@ 2002-03-13 10:22 Zack Weinberg
  2002-03-13 10:40 ` Kris Warkentin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Zack Weinberg @ 2002-03-13 10:22 UTC (permalink / raw)
  To: gdb

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

$ strings -a a.out | grep '^A:'
A:T(0,20)=s8a:(0,1),0,32;b:(0,1),32,32;;
A:T(0,20)=s2a:(0,2),0,8;b:(0,2),8,8;;

I can see the same thing in readelf -w output when DWARF2 is used,
although more verbosely.

It Would Be Nice if gdb would notice this and print a warning message,
along the lines of 

warning: type `struct A' defined inconsistently in object files `a.o'
and `b.o'

when started up.

zw


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

end of thread, other threads:[~2002-03-15  6:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-13 10:22 Suggestion: Detect inconsistent structure definitions Zack Weinberg
2002-03-13 10:40 ` Kris Warkentin
2002-03-13 16:02   ` Daniel Jacobowitz
2002-03-14  5:14     ` Kris Warkentin
2002-03-13 16:07 ` Daniel Jacobowitz
2002-03-14 11:13   ` Zack Weinberg
2002-03-14 21:03     ` Daniel Jacobowitz
2002-03-14 22:11       ` Andrew Cagney
     [not found] ` <mailpost.1016043761.7328@news-sj1-1>
2002-03-13 18:35   ` cgd

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