From Roland McGrath: -g3 puts both implicit predefines and -D/-U records in the wrong place in .debug_macinfo. Steps to Reproduce: 1. echo '#define foo bar' > g3.c; echo 'foo(){}' >> g3.c 2. gcc -c -g3 g3.c -DFOO=1 -UFOO 3. readelf --debug-dump=macro g3.o Actual results: The implicit predefines appear after the start_file record for "g3.c", with fake line numbers, then the -D/-U records also with fake line numbers. Expected results: DWARF spec says predefines come before the first start_file record, and all use line number 0. GCC patch by Jakub Jelinek is provided but current GDB starts to ignore such macros. Thus the GDB HEAD acceptance is a prerequisite for the GCC HEAD change. current GCC: Contents of the .debug_macinfo section: DW_MACINFO_start_file - lineno: 0 filenum: 1 DW_MACINFO_define - lineno : 0 macro : __STDC__ 1 DW_MACINFO_define - lineno : 0 macro : __STDC_HOSTED__ 1 patched GCC: Contents of the .debug_macinfo section: DW_MACINFO_define - lineno : 0 macro : __STDC__ 1 DW_MACINFO_define - lineno : 0 macro : __STDC_HOSTED__ 1 http://dwarf.freestandards.org/Dwarf3.pdf 6.3.3 Macinfo Entries for Command Line Options [..] All such DW_MACINFO_define and DW_MACINFO_undef entries representing compilation options should appear before the first DW_MACINFO_start_file entry for that compilation unit and should encode the value 0 in their line number operands. current GCC + current GDB: patched GCC + patched GDB: (gdb) info macro __STDC__ Defined at ../.././gdb/testsuite/gdb.base/macscp1.c:0 #define __STDC__ 1 patched GCC + current GDB: During symbol reading, debug info gives macro definition outside of any file: __STDC__ 1. During symbol reading, debug info gives macro definition outside of any file: __STDC_HOSTED__ 1. (gdb) info macro __STDC__ The symbol `__STDC__' has no definition as a C/C++ preprocessor macro at gdb.base/macscp1.c:102 current GCC + patched GDB: During symbol reading, debug info gives in-file macro definition with zero line 0: __STDC__ 1. During symbol reading, debug info gives in-file macro definition with zero line 0: __STDC_HOSTED__ 1. (gdb) info macro __STDC__ Defined at ../.././gdb/testsuite/gdb.base/macscp1.c:0 #define __STDC__ 1
Created attachment 3753 [details] GCC patch by Jakub Jelinek.
Created attachment 3754 [details] GDB fix+testcase.
Subject: Bug 9873 CVSROOT: /cvs/src Module name: src Changes by: jkratoch@sourceware.org 2009-03-09 18:53:48 Modified files: gdb : ChangeLog dwarf2read.c Log message: PR gdb/9873: * dwarf2read.c (dwarf_decode_macros): New variable `at_commandline'. Move the variable `macinfo_type' out of the loop. Create a new processing pass before the current one to pre-create `current_file'. New complaint on misplaced zero/non-zero definitions/includes. Skip first DW_MACINFO_start_file with `at_commandline' set. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.10233&r2=1.10234 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.295&r2=1.296
Comment on attachment 3754 [details] GDB fix+testcase. Updated patch has been checked-in.
Checked-in.