Bug 9873 - DWARF command-line defined macros get ignored
Summary: DWARF command-line defined macros get ignored
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: macros (show other bugs)
Version: unknown
: P3 minor
Target Milestone: 6.8
Assignee: Jan Kratochvil
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-19 21:36 UTC by Jan Kratochvil
Modified: 2009-03-09 18:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
GCC patch by Jakub Jelinek. (632 bytes, patch)
2009-02-19 21:37 UTC, Jan Kratochvil
Details | Diff
GDB fix+testcase. (2.88 KB, patch)
2009-02-19 21:39 UTC, Jan Kratochvil
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2009-02-19 21:36:24 UTC
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
Comment 1 Jan Kratochvil 2009-02-19 21:37:44 UTC
Created attachment 3753 [details]
GCC patch by Jakub Jelinek.
Comment 2 Jan Kratochvil 2009-02-19 21:39:06 UTC
Created attachment 3754 [details]
GDB fix+testcase.
Comment 3 Sourceware Commits 2009-03-09 18:54:07 UTC
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 4 Jan Kratochvil 2009-03-09 18:56:40 UTC
Comment on attachment 3754 [details]
GDB fix+testcase.

Updated patch has been checked-in.
Comment 5 Jan Kratochvil 2009-03-09 18:57:10 UTC
Checked-in.