dwarf2out.c (add_data_member_location_attribute) always generates a full dwarf location expression even for simple struct member offsets. This results in debug_info for structs that looks like this:
<1><77>: Abbrev Number: 7 (DW_TAG_structure_type) <78> DW_AT_name : (indirect string, offset: 0x64): mystruct <7c> DW_AT_byte_size : 40 <7d> DW_AT_decl_file : 1 <7e> DW_AT_decl_line : 5 <7f> DW_AT_sibling : <0xc0> <2><83>: Abbrev Number: 8 (DW_TAG_member) <84> DW_AT_name : n <86> DW_AT_decl_file : 1 <87> DW_AT_decl_line : 6 <88> DW_AT_type : <0xc0> <8c> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0) <2><8f>: Abbrev Number: 8 (DW_TAG_member) <90> DW_AT_name : c <92> DW_AT_decl_file : 1 <93> DW_AT_decl_line : 7 <94> DW_AT_type : <0x6a> <98> DW_AT_data_member_location: 2 byte block: 23 8 (DW_OP_plus_uconst: 8) <2><9b>: Abbrev Number: 8 (DW_TAG_member) <9c> DW_AT_name : i <9e> DW_AT_decl_file : 1 <9f> DW_AT_decl_line : 8 <a0> DW_AT_type : <0x57> <a4> DW_AT_data_member_location: 2 byte block: 23 10 (DW_OP_plus_uconst: 16) The dwarf spec says: "If a data member is defined in a structure, union or class, the corresponding member entry has a DW_AT_data_member_location attribute whose value describes the location of that member relative to the base address of the structure, union, or class that most closely encloses the member declaration. If that value is a constant, it is the offset in bytes from the beginning of the innermost enclosing structure, union or class to the beginning of the data member. Otherwise, the value must be a location description." So if we only have a simple constant offset it seems more space efficient to output the offset as a constant instead of a location expression using DW_OP_plus_uconst. A suggested patch might be the following (still building/testing against gdb and stap - gdb should work, systemtap will need some adjusting): Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 149279) +++ gcc/dwarf2out.c (working copy) @@ -11475,8 +11475,6 @@ if (! loc_descr) { - enum dwarf_location_atom op; - /* The DWARF2 standard says that we should assume that the structure address is already on the stack, so we can specify a structure field address by using DW_OP_plus_uconst. */ @@ -11485,12 +11483,16 @@ /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator correctly. It works only if we leave the offset on the stack. */ + enum dwarf_location_atom op; + op = DW_OP_constu; + loc_descr = new_loc_descr (op, offset, 0); #else - op = DW_OP_plus_uconst; + /* Don't need an whole location expression, just a constant offset. */ + add_AT_int (die, DW_AT_data_member_location, offset); + return; #endif - loc_descr = new_loc_descr (op, offset, 0); } add_AT_loc (die, DW_AT_data_member_location, loc_descr); That will simplify the debug_info for structs so it reads: <1><77>: Abbrev Number: 7 (DW_TAG_structure_type) <78> DW_AT_name : (indirect string, offset: 0x3d): mystruct <7c> DW_AT_byte_size : 40 <7d> DW_AT_decl_file : 1 <7e> DW_AT_decl_line : 4 <7f> DW_AT_sibling : <0xb6> <2><83>: Abbrev Number: 8 (DW_TAG_member) <84> DW_AT_name : n <86> DW_AT_decl_file : 1 <87> DW_AT_decl_line : 6 <88> DW_AT_type : <0xb6> <8c> DW_AT_data_member_location: 0 <2><8d>: Abbrev Number: 8 (DW_TAG_member) <8e> DW_AT_name : c <90> DW_AT_decl_file : 1 <91> DW_AT_decl_line : 7 <92> DW_AT_type : <0x6a> <96> DW_AT_data_member_location: 8 <2><97>: Abbrev Number: 8 (DW_TAG_member) <98> DW_AT_name : i <9a> DW_AT_decl_file : 1 <9b> DW_AT_decl_line : 8 <9c> DW_AT_type : <0x57> <a0> DW_AT_data_member_location: 16 -- Summary: A simple struct member offset doesn't need a full dwarf location expression Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mark at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40659