re PR fortran/33502 (gfortran with .F suffix and -g3 option chokes on preprocessor...
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sat, 22 Sep 2007 15:03:24 +0000 (15:03 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sat, 22 Sep 2007 15:03:24 +0000 (15:03 +0000)
PR fortran/33502
* scanner.c (gfc_advance_line): Call debug_hooks->start_source_file
and debug_hooks->end_source_file when entering and exiting
included files.
(gfc_define_undef_line): New function.
(load_file): Ignore #define and #undef preprocessor lines
while reading source files.
* parse.c (next_statement): Handle #define and #undef
preprocessor lines.
(gfc_parse_file): Call debug_hooks->start_source_file and
debug_hooks->end_source_file for the main source file if
requested by the debug format.
* gfortran.h (gfc_define_undef_line): Add prototype.

From-SVN: r128671

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/parse.c
gcc/fortran/scanner.c

index f683ea3c7f69b129151dab988b0e7ab601963262..36904b2766ccb851945e3a18f3644a757c7ba708 100644 (file)
@@ -1,3 +1,19 @@
+2007-09-22  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/33502
+       * scanner.c (gfc_advance_line): Call debug_hooks->start_source_file
+       and debug_hooks->end_source_file when entering and exiting
+       included files.
+       (gfc_define_undef_line): New function.
+       (load_file): Ignore #define and #undef preprocessor lines
+       while reading source files.
+       * parse.c (next_statement): Handle #define and #undef
+       preprocessor lines.
+       (gfc_parse_file): Call debug_hooks->start_source_file and
+       debug_hooks->end_source_file for the main source file if
+       requested by the debug format.
+       * gfortran.h (gfc_define_undef_line): Add prototype.
+
 2007-09-22  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/33445
index 42002cee21e3dbdc9e3af90d0e28b7686b05b7f0..7f6179424fb1c1c62efe3175e866408bc1c7cbc9 100644 (file)
@@ -1935,6 +1935,7 @@ int gfc_at_bol (void);
 int gfc_at_eol (void);
 void gfc_advance_line (void);
 int gfc_check_include (void);
+int gfc_define_undef_line (void);
 
 void gfc_skip_comments (void);
 int gfc_next_char_literal (int);
index a6672f46ca6731829485ec018220b940cd92dd58..9fd43758024143ccd11531f8a740d4968286b287 100644 (file)
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gfortran.h"
 #include "match.h"
 #include "parse.h"
+#include "debug.h"
 
 /* Current statement label.  Zero means no statement label.  Because new_st
    can get wiped during statement matching, we have to keep it separate.  */
@@ -673,6 +674,9 @@ next_statement (void)
          break;
        }
 
+      if (gfc_define_undef_line ())
+       continue;
+
       st = (gfc_current_form == FORM_FIXED) ? next_fixed () : next_free ();
 
       if (st != ST_NONE)
@@ -3219,6 +3223,11 @@ gfc_parse_file (void)
   gfc_statement st;
   locus prog_locus;
 
+  /* If the debugger wants the name of the main source file,
+     we give it.  */
+  if (debug_hooks->start_end_main_source_file)
+    (*debug_hooks->start_source_file) (0, gfc_source_file);
+
   top.state = COMP_NONE;
   top.sym = NULL;
   top.previous = NULL;
@@ -3329,6 +3338,9 @@ loop:
   goto loop;
 
 done:
+  if (debug_hooks->start_end_main_source_file)
+    (*debug_hooks->end_source_file) (0);
+
   return SUCCESS;
 
 duplicate_main:
index fe7d213ae0bbde0fe830d1d0919d99fa39e1ba45..ef2bbcd921e2cf4ecc14646f1b11bd87c13ed526 100644 (file)
@@ -45,6 +45,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "gfortran.h"
 #include "toplev.h"
+#include "debug.h"
+#include "flags.h"
 
 /* Structure for holding module and include file search path.  */
 typedef struct gfc_directorylist
@@ -312,6 +314,20 @@ gfc_advance_line (void)
       return;
     } 
 
+  if (gfc_current_locus.lb->next)
+    {
+      if (gfc_current_locus.lb->file->next
+         && gfc_current_locus.lb->file->up == gfc_current_locus.lb->file->next)
+       /* We exit from an included file. */
+       (*debug_hooks->end_source_file)
+               (gfc_linebuf_linenum (gfc_current_locus.lb->next));
+      else if (gfc_current_locus.lb->next->file != gfc_current_locus.lb->file)
+       /* We enter into a new file.  */
+       (*debug_hooks->start_source_file)
+               (gfc_linebuf_linenum (gfc_current_locus.lb),
+                gfc_current_locus.lb->next->file->filename);
+    }
+
   gfc_current_locus.lb = gfc_current_locus.lb->next;
 
   if (gfc_current_locus.lb != NULL)     
@@ -372,6 +388,31 @@ skip_comment_line (void)
 }
 
 
+int
+gfc_define_undef_line (void)
+{
+  /* All lines beginning with '#' are either #define or #undef.  */
+  if (! (debug_info_level == DINFO_LEVEL_VERBOSE
+        && (write_symbols == DWARF2_DEBUG
+            || write_symbols == VMS_AND_DWARF2_DEBUG))
+      || gfc_peek_char () != '#')
+    return 0;
+
+  if (strncmp (gfc_current_locus.nextc, "#define ", 8) == 0)
+    (*debug_hooks->define) (gfc_linebuf_linenum (gfc_current_locus.lb),
+                           &(gfc_current_locus.nextc[8]));
+
+  if (strncmp (gfc_current_locus.nextc, "#undef ", 7) == 0)
+    (*debug_hooks->undef) (gfc_linebuf_linenum (gfc_current_locus.lb),
+                          &(gfc_current_locus.nextc[7]));
+
+  /* Skip the rest of the line.  */
+  skip_comment_line ();
+
+  return 1;
+}
+
+
 /* Comment lines are null lines, lines containing only blanks or lines
    on which the first nonblank line is a '!'.
    Return true if !$ openmp conditional compilation sentinel was
@@ -1500,8 +1541,20 @@ load_file (const char *filename, bool initial)
 
       if (line[0] == '#')
        {
-         preprocessor_line (line);
-         continue;
+         /* When -g3 is specified, it's possible that we emit #define
+            and #undef lines, which we need to pass to the middle-end
+            so that it can emit correct debug info.  */
+         if (debug_info_level == DINFO_LEVEL_VERBOSE
+             && (write_symbols == DWARF2_DEBUG
+                 || write_symbols == VMS_AND_DWARF2_DEBUG)
+             && (strncmp (line, "#define ", 8) == 0
+                 || strncmp (line, "#undef ", 7) == 0))
+           ;
+         else
+           {
+             preprocessor_line (line);
+             continue;
+           }
        }
 
       /* Preprocessed files have preprocessor lines added before the byte