Created attachment 39489 [details] example.c I have found a missing debug information in dwarf for file compiled with g++. Same file compiled with gcc has correct debug information. I have compiled the file as g++ -c -g example.c Export debug information as readelf -wi example.o >deb There is a missing information for type tHash1 <1><2b>: Abbrev Number: 3 (DW_TAG_typedef) <2c> DW_AT_name : (indirect string, offset: 0x23): tHash1 <30> DW_AT_decl_file : 1 <31> DW_AT_decl_line : 4 but for the type tHash2 the information is correct <1><39>: Abbrev Number: 4 (DW_TAG_typedef) <3a> DW_AT_name : (indirect string, offset: 0x2a): tHash2 <3e> DW_AT_decl_file : 1 <3f> DW_AT_decl_line : 5 <40> DW_AT_type : <0x44> <------- OK I ask someone to confirm the bug. example.c attached
Confirmed with GCC 6. The root cause seems to be that we lack a DIE for the uint8 typedef as well (the uint16 one is IMHO correctly pruned as unused by both FEs). It works fine with GCC 4.8 and 4.9 where we also lack the uint8 typedef DIE but at least get <1><24>: Abbrev Number: 2 (DW_TAG_base_type) <25> DW_AT_byte_size : 1 <26> DW_AT_encoding : 8 (unsigned char) <27> DW_AT_name : (indirect string, offset: 0x72): unsigned char <1><2b>: Abbrev Number: 3 (DW_TAG_typedef) <2c> DW_AT_name : (indirect string, offset: 0x23): tHash1 <30> DW_AT_decl_file : 1 <31> DW_AT_decl_line : 4 <32> DW_AT_type : <0x36> <1><36>: Abbrev Number: 4 (DW_TAG_array_type) <37> DW_AT_type : <0x24> <3b> DW_AT_sibling : <0x46> <2><3f>: Abbrev Number: 5 (DW_TAG_subrange_type) <40> DW_AT_type : <0x46> <44> DW_AT_upper_bound : 15
Investigating the bug I found that GCC 5.3.0 is partially correct, same way as 4.8 and 4.9. The bug was introduced by this revision https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=231673 GIT 0c4341e59b724e51deb033a64e057159f27de7dd
This pr68162 breaks the function
Created attachment 39513 [details] gcc7-pr77363.patch Untested fix. I believe the bug is that Richard changed just gen_type_die_with_usage, but modified_type_die needs to be in sync in what that function does, otherwise it can't look it up or looks up something different.
Author: jakub Date: Tue Aug 30 06:46:38 2016 New Revision: 239855 URL: https://gcc.gnu.org/viewcvs?rev=239855&root=gcc&view=rev Log: PR debug/77363 * dwarf2out.c (modified_type_die): Use lookup_type_die (type) instead of lookup_type_die (type_main_variant (type)) even for array types. * g++.dg/debug/dwarf2/pr77363.C: New test. Added: trunk/gcc/testsuite/g++.dg/debug/dwarf2/pr77363.C Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c trunk/gcc/testsuite/ChangeLog
Confirmed that the patch fixes my case in GCC 5.4.0. Please backport the patch to gcc-5 branch.
Still not fixed for 6.3/5.5, so reopening until that happens.
Author: jakub Date: Thu Sep 1 11:43:15 2016 New Revision: 239930 URL: https://gcc.gnu.org/viewcvs?rev=239930&root=gcc&view=rev Log: Backported from mainline 2016-08-30 Jakub Jelinek <jakub@redhat.com> PR debug/77363 * dwarf2out.c (modified_type_die): Use lookup_type_die (type) instead of lookup_type_die (type_main_variant (type)) even for array types. * g++.dg/debug/dwarf2/pr77363.C: New test. Added: branches/gcc-6-branch/gcc/testsuite/g++.dg/debug/dwarf2/pr77363.C Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/dwarf2out.c branches/gcc-6-branch/gcc/testsuite/ChangeLog
*** Bug 80596 has been marked as a duplicate of this bug. ***
Author: jakub Date: Tue May 30 07:18:37 2017 New Revision: 248602 URL: https://gcc.gnu.org/viewcvs?rev=248602&root=gcc&view=rev Log: Backported from mainline 2016-08-30 Jakub Jelinek <jakub@redhat.com> PR debug/77363 * dwarf2out.c (modified_type_die): Use lookup_type_die (type) instead of lookup_type_die (type_main_variant (type)) even for array types. * g++.dg/debug/dwarf2/pr77363.C: New test. Added: branches/gcc-5-branch/gcc/testsuite/g++.dg/debug/dwarf2/pr77363.C Modified: branches/gcc-5-branch/gcc/ChangeLog branches/gcc-5-branch/gcc/dwarf2out.c branches/gcc-5-branch/gcc/testsuite/ChangeLog
Fixed.