This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] remove calls to fprintf in language parsers


At 02:49 21/06/2002 , Andrew Cagney a écrit:
>>+/* Function used to avoid direct calls to fprintf
>>+   in the code generated by the bison parser.  */
>>+
>>+extern void parser_fprintf (FILE *, const char *, ...);
>
>Hmm, wonder if there is any benefit in adding ATTR_FORMAT(printf, 2, 3) to the declaration?

I didn't even  know this modifier :(
But it does look appropriate indeed.

>Anyway, yes,

Does this mean I can apply the patch?
Below is the revised patch, with just
the ATTR_FORMAT modifier added.
This makes the line longer than 80 chars, but
I looked at other declarations using the same ATTR_FORMAT
and they are all in one single line...
Do I need to add a 
/* *INDENT-OFF* */ like in defs.h
that has the following comment about it:
/* ATTR_FORMAT confuses indent, avoid running it for now */
But some other headers using ATTR_FORMAT 
like serial.h for instance also don't have INDENT_OFF,
so I guess that the above comment only concerns the declaration
of the ATTR_FORMAT.


2002-06-19  Pierre Muller  <muller@ics.u-strasbg.fr>

         * parse.c (parse_fprintf): New function used to avoid calls to
         fprintf in bison parser generated debug code.
         * parser-defs.h: Declaration of new parse_fprintf function.
         * ada-exp.y, c-exp.y, f-exp.y, jv-exp.y, m2-exp.y, p-exp.y:
         Set YYDEBUG to 1 by default.
         Set YYFPRINTF as parse_fprintf.


Index: parser-defs.h
===================================================================
RCS file: /cvs/src/src/gdb/parser-defs.h,v
retrieving revision 1.9
diff -u -p -r1.9 parser-defs.h
--- parser-defs.h       17 May 2002 17:57:48 -0000      1.9
+++ parser-defs.h       21 Jun 2002 07:39:28 -0000
@@ -216,4 +216,9 @@ struct op_print
  
  extern int target_map_name_to_register (char *, int);
  
+/* Function used to avoid direct calls to fprintf
+   in the code generated by the bison parser.  */
+
+extern void parser_fprintf (FILE *, const char *, ...) ATTR_FORMAT (printf, 2 ,3);
+
  #endif /* PARSER_DEFS_H */
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.24
diff -u -p -r1.24 parse.c
--- parse.c     17 May 2002 17:57:48 -0000      1.24
+++ parse.c     21 Jun 2002 07:39:29 -0000
@@ -1366,6 +1366,23 @@ build_parse (void)
                NULL);
  }
  
+/* This function avoids direct calls to fprintf 
+   in the parser generated debug code.  */
+void
+parser_fprintf (FILE *x, const char *y, ...)
+{ 
+  va_list args;
+  va_start (args, y);
+  if (x == stderr)
+    vfprintf_unfiltered (gdb_stderr, y, args); 
+  else
+    {
+      fprintf_unfiltered (gdb_stderr, " Unknown FILE used.\n");
+      vfprintf_unfiltered (gdb_stderr, y, args);
+    }
+  va_end (args);
+}
+
  void
  _initialize_parse (void)
  {
Index: ada-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/ada-exp.y,v
retrieving revision 1.1
diff -u -p -r1.1 ada-exp.y
--- ada-exp.y   4 Jun 2002 15:28:47 -0000       1.1
+++ ada-exp.y   21 Jun 2002 07:39:29 -0000
@@ -92,8 +92,10 @@ Foundation, Inc., 675 Mass Ave, Cambridg
  #define yytoks ada_toks                /* With YYDEBUG defined */
  
  #ifndef YYDEBUG
-#define        YYDEBUG 0               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  struct name_info {
    struct symbol* sym;
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.10
diff -u -p -r1.10 c-exp.y
--- c-exp.y     17 May 2002 17:57:48 -0000      1.10
+++ c-exp.y     21 Jun 2002 07:39:29 -0000
@@ -100,8 +100,10 @@ extern int hp_som_som_object_present;
  #define yycheck         c_yycheck
  
  #ifndef YYDEBUG
-#define        YYDEBUG 0               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  int yyparse (void);
  
Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.6
diff -u -p -r1.6 f-exp.y
--- f-exp.y     3 May 2002 08:22:52 -0000       1.6
+++ f-exp.y     21 Jun 2002 07:39:29 -0000
@@ -102,8 +102,10 @@ Foundation, Inc., 59 Temple Place - Suit
  #define yycheck         f_yycheck
  
  #ifndef YYDEBUG
-#define        YYDEBUG 1               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  int yyparse (void);
  
Index: jv-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/jv-exp.y,v
retrieving revision 1.6
diff -u -p -r1.6 jv-exp.y
--- jv-exp.y    3 May 2002 08:22:52 -0000       1.6
+++ jv-exp.y    21 Jun 2002 07:39:29 -0000
@@ -96,8 +96,10 @@ Foundation, Inc., 59 Temple Place - Suit
  #define yycheck         java_yycheck
  
  #ifndef YYDEBUG
-#define        YYDEBUG 0               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  int yyparse (void);
  
Index: m2-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/m2-exp.y,v
retrieving revision 1.4
diff -u -p -r1.4 m2-exp.y
--- m2-exp.y    3 May 2002 08:22:52 -0000       1.4
+++ m2-exp.y    21 Jun 2002 07:39:29 -0000
@@ -98,8 +98,10 @@ Foundation, Inc., 59 Temple Place - Suit
  #define yycheck         m2_yycheck
  
  #ifndef YYDEBUG
-#define        YYDEBUG 0               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  int yyparse (void);
  
Index: p-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/p-exp.y,v
retrieving revision 1.11
diff -u -p -r1.11 p-exp.y
--- p-exp.y     16 May 2002 09:34:54 -0000      1.11
+++ p-exp.y     21 Jun 2002 07:39:29 -0000
@@ -104,8 +104,10 @@ Foundation, Inc., 59 Temple Place - Suit
  #define yycheck         pascal_yycheck
  
  #ifndef YYDEBUG
-#define        YYDEBUG 0               /* Default to no yydebug support */
+#define        YYDEBUG 1               /* Default to yydebug support */
  #endif
+
+#define YYFPRINTF parser_fprintf
  
  int yyparse (void);
  



Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]