* [RFA] remove calls to fprintf in language parsers
@ 2002-06-20 2:44 Pierre Muller
2002-06-20 17:49 ` Andrew Cagney
0 siblings, 1 reply; 5+ messages in thread
From: Pierre Muller @ 2002-06-20 2:44 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Cagney
This is a follow-up of
http://sources.redhat.com/ml/gdb-patches/2002-05/msg00633.html
It follows the first alternative exposed in that
mail.
All parsers get their YYDEBUG set to 1 by default.
The YYFPRINTF macro is set to parse_fprintf function
that is defined in parser-def.h and implemented in
parse.c.
As far as I saw, YYFPRINTF is only used
with stderr as FILE * parameter if we use bison
parser, but I added a check in case some other parser
uses it diferently.
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 19 Jun 2002 10:03:54 -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 *, ...);
+
#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 19 Jun 2002 10:03:54 -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 19 Jun 2002 10:03:55 -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 19 Jun 2002 10:03:55 -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 19 Jun 2002 10:03:55 -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 19 Jun 2002 10:03:55 -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 19 Jun 2002 10:03:55 -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 19 Jun 2002 10:03:55 -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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFA] remove calls to fprintf in language parsers 2002-06-20 2:44 [RFA] remove calls to fprintf in language parsers Pierre Muller @ 2002-06-20 17:49 ` Andrew Cagney 2002-06-21 0:52 ` Pierre Muller 0 siblings, 1 reply; 5+ messages in thread From: Andrew Cagney @ 2002-06-20 17:49 UTC (permalink / raw) To: Pierre Muller; +Cc: gdb-patches > +/* 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? Anyway, yes, Andrew ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] remove calls to fprintf in language parsers 2002-06-20 17:49 ` Andrew Cagney @ 2002-06-21 0:52 ` Pierre Muller 2002-06-21 7:13 ` Andrew Cagney 0 siblings, 1 reply; 5+ messages in thread From: Pierre Muller @ 2002-06-21 0:52 UTC (permalink / raw) To: Andrew Cagney; +Cc: gdb-patches 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] remove calls to fprintf in language parsers 2002-06-21 0:52 ` Pierre Muller @ 2002-06-21 7:13 ` Andrew Cagney 2002-06-21 7:40 ` Pierre Muller 0 siblings, 1 reply; 5+ messages in thread From: Andrew Cagney @ 2002-06-21 7:13 UTC (permalink / raw) To: Pierre Muller; +Cc: gdb-patches > 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 :( BTW, attr_format was only added to error() (one of GDBs most important functions) a month or so ago. While the attribute has been around for a while, it is relativly new for GDB. > But it does look appropriate indeed. My only reservation was that bison/yacc could turn out to generate badly formatted printf statements. However, if that is happening then we need to know anyway. As for indentation. GNU indent doesn't handle ATTR_FORMAT() very well so any location is likely ok. >>Anyway, yes, > > > Does this mean I can apply the patch? Yes, either way. Andrew (I'm just happy to see these fprintf() slowly disappearing :-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] remove calls to fprintf in language parsers 2002-06-21 7:13 ` Andrew Cagney @ 2002-06-21 7:40 ` Pierre Muller 0 siblings, 0 replies; 5+ messages in thread From: Pierre Muller @ 2002-06-21 7:40 UTC (permalink / raw) To: Andrew Cagney; +Cc: gdb-patches At 16:13 21/06/2002 , Andrew Cagney a écrit: >>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 :( > >BTW, attr_format was only added to error() (one of GDBs most important functions) a month or so ago. While the attribute has been around for a while, it is relativly new for GDB. > >>But it does look appropriate indeed. > >My only reservation was that bison/yacc could turn out to generate badly formatted printf statements. However, if that is happening then we need to know anyway. Isn't it the purpose of this modifer to check if the format and the parameter list match? >As for indentation. GNU indent doesn't handle ATTR_FORMAT() very well so any location is likely ok. > >>>Anyway, yes, >> >>Does this mean I can apply the patch? > >Yes, either way. Committed. >Andrew >(I'm just happy to see these fprintf() slowly disappearing :-) The only fprintf call remaining (at least for cygwin native GDB) is in tracepoint.c function tracepoint_save_command but this is directly to a disk file, so it shouldn't harm any program using GDB lib like Insight. Nevertheless for consistency, this FILE *fp local var should probably also be converted into a ui_file by using gdb_fopen instead of fopen, no? 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-06-21 14:40 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-06-20 2:44 [RFA] remove calls to fprintf in language parsers Pierre Muller 2002-06-20 17:49 ` Andrew Cagney 2002-06-21 0:52 ` Pierre Muller 2002-06-21 7:13 ` Andrew Cagney 2002-06-21 7:40 ` Pierre Muller
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox