[fortran,patch] Handle preprocessing with -g3

FX Coudert fxcoudert@gmail.com
Sat Sep 22 14:10:00 GMT 2007


The Fortran front-end currently thinks the only preprocessor lines it  
can be given are location lines (of the form: # linenum "filename").  
This is not true for verbose dwarf2 debug (-g3 on a platform that  
uses dwarf2): in that case, #define and #undef preprocessor  
directives are included in the preprocessed file, so that they debug  
info can be emitted for macros. The Fortran front-end not only  
doesn't emit such debug information, but it even chokes on the  
preprocessor lines. This patch makes us handle them and emit  
appropriate debug info for each #define and #undef, and adds  
additional debug info needed to make it work.

Half the patch is doing exactly that: We first encounter the #define  
and #undef lines when loading the file; at that time, however, it's  
too early to emit debug info (the compiler hasn't yet setup the  
output file), so we just have to ignore them (that's the part in  
scanner.c:load_file). Later, when we actually parse the source, we  
can actually handle them: in next_statement [parse.c], we call about  
new function gfc_define_undef_line [scanner.c], which calls  
debug_hooks->define and debug_hooks->undef.

The second half of the patch is needed to make it work: we need to  
register filenames with debug_hooks->start_source_file and  
debug_hooks->end_source_file whenever we enter a new included file  
and exit it. We also do it for the main source file, if the debug  
format requests it (indicated by debug_hooks- 
 >start_end_main_source_file). This part was designed by looking at  
gcc/c-lex.c.


Bootstrapped and tested on x86_64-linux both with --enable-mapped- 
location and without. (During the testing with --enable-mapped- 
location, I uncovered pre-existing PR33528.) OK for mainline?


PS: here's an example debug session with the patch:

$ cat w1.F90
   implicit none
#define foo "xxx"
#define bar 42
   print *, foo
#include "inc1.f90"
   print *, bar
#undef foo
   print *, bar
   end
$ cat inc1.f90
   print *, 12
$ gfortran -g3 w1.F90
$ gdb -quiet ./a.out
(gdb) b MAIN__
Breakpoint 1 at 0x401ea7: file w1.F90, line 1.
(gdb) r
Starting program: /home/fxcoudert/devel/debug/irun-nonmapped/a.out

Breakpoint 1, MAIN__ () at w1.F90:1
1         implicit none
Current language:  auto; currently fortran
(gdb) info macro foo
The symbol `foo' has no definition as a C/C++ preprocessor macro
at /home/fxcoudert/devel/debug/irun-nonmapped/w1.F90:1
(gdb) n
4         print *, foo
(gdb) info macro foo
Defined at /home/fxcoudert/devel/debug/irun-nonmapped/w1.F90:2
#define foo "xxx"
(gdb) n
xxx
1         print *, 12
(gdb)
           12
6         print *, bar
(gdb) info macro foo
Defined at /home/fxcoudert/devel/debug/irun-nonmapped/w1.F90:2
#define foo "xxx"
(gdb) n
           42
8         print *, bar
(gdb) info macro foo
The symbol `foo' has no definition as a C/C++ preprocessor macro
at /home/fxcoudert/devel/debug/irun-nonmapped/w1.F90:8
(gdb) info macro bar
Defined at /home/fxcoudert/devel/debug/irun-nonmapped/w1.F90:3
#define bar 42







:ADDPATCH fortran:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr33502.ChangeLog
Type: application/octet-stream
Size: 634 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070922/5fccf326/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr33502.diff
Type: application/octet-stream
Size: 4380 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070922/5fccf326/attachment-0001.obj>


More information about the Gcc-patches mailing list