[Dwarf-Discuss] Complete/Incomplete struct clarification

Michael Eager eager@eagercon.com
Tue Nov 25 16:44:07 GMT 2008


Christophe LYON wrote:
> Hello,
> 
> I would like some clarification on the use of DW_AT_declaration to 
> describe incomplete types. Indeed, the Dwarf standard says that for 
> incomplete structs, there should be no DW_AT_byte_size info in addition 
> to the DW_AT_declaration flag.
> 
> Why is there this additional constraint on DW_AT_byte_size?

The size of an incomplete type is unknown.

The most common use of incomplete types is to support encapsulation
of C types.  For example:

	typedef struct internal_foo * FOO;
	FOO mydata;
	extern FOO get_foo(void);
	extern void use_foo(FOO);

You can get a FOO from a library routine and pass it to other routines.
The declaration of "struct internal_foo" would have DW_AT_declaration
and no DW_AT_byte_size, since you don't have a definition of the struct.

Other occurrences of incomplete types would seem to be bugs.
Any use of an incomplete type other than to create an encapsulated
pointer is certainly non-standard C.

> If the compiler generates DW_AT_declaration even for "complete" type 
> declaration, is this a compiler bug?

It seems that it is incorrectly describing the source.  The compiler
is indicating that the type is incomplete.

> I have discovered the hard way that GDB simply ignores struct members 
> description if the structure_type node has FW_AT_declaration, even if it 
> also has DW_AT_byte_size (see scan_partial_symbols(), which has a more 
> restrictive condition than add_partial_symbol()). Is this an 
> inconsistency in GDB that should be fixed also?

Ignoring the internal structure of incomplete structure types may
be a reasonable decision.  GDB probably doesn't have any way to
indicate that a member's offset within a struct is unknown.  It's
probably much simpler to indicate that it doesn't know the member
name rather than saying it knows the name but not its location.

As for what the debugger should do when you have conflicting descriptions
(both DW_AT_byte_size and DW_AT_declaration) the best answer is to not
generate inconsistent DWARF.  Only complete types have DW_AT_byte_size.
DW_AT_declaration explicitly says that the type is incomplete.
Which of the two incompatible specifications do you want to believe?


-- 
Michael Eager	 eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077




More information about the Dwarf-discuss mailing list