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: PATCH: add format attributes to gdb


 > Kaveh, my only gripe is that you've stuck these markers at the end of
 > a bunch of lines that were already quite long.  You're past eighty
 > columns in a lot of places.  Do you think you could fix that?
 > 
 > The rest of the patch looks just fine, of course.

Okay, how's this?


2005-07-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* cli-out.c (cli_field_fmt, cli_message, out_field_fmt): Add
	ATTR_FORMAT or ATTRIBUTE_FPTR_PRINTF.
	* complaints.c (vcomplaint): Likewise.
	* defs.h (xvasprintf, xstrvprintf, verror, vfatal)
	(internal_verror, internal_vwarning, vwarning)
	(deprecated_query_hook, deprecated_warning_hook)
	(deprecated_readline_begin_hook): Likewise.
	* disasm.c (fprintf_disasm): Likewise.
	* exceptions.c (throw_it): Likewise.
	* exceptions.h (throw_verror, throw_vfatal): Likewise.
	* mi/mi-interp.c (mi_interp_query_hook): Likewise.
	* mi/mi-out.c (mi_field_fmt, mi_message): Likewise.
	* tui/tui-hooks.c (tui_query_hook): Likewise.
	* tui/tui-out.c (tui_field_fmt, tui_message, out_field_fmt):
	Likewise.
	* ui-out.c (default_field_fmt, default_message, uo_field_fmt)
	(uo_message): Likewise.
	* ui-out.h (ui_out_field_fmt, ui_out_message, field_fmt_ftype)
	(message_ftype): Likewise.
	* utils.c (vfprintf_maybe_filtered, internal_vproblem)
	(defaulted_query, printchar): Likewise.
	
gdbserver:
	* server.h (error, fatal, warning): Add ATTR_FORMAT.


diff -rup orig/gdb-6.3.50.20050727/gdb/cli-out.c gdb-6.3.50.20050727/gdb/cli-out.c
--- orig/gdb-6.3.50.20050727/gdb/cli-out.c	2005-01-13 18:39:40.000000000 -0500
+++ gdb-6.3.50.20050727/gdb/cli-out.c	2005-07-29 12:29:16.000000000 -0400
@@ -58,11 +58,12 @@ static void cli_field_string (struct ui_
 static void cli_field_fmt (struct ui_out *uiout, int fldno,
 			   int width, enum ui_align align,
 			   const char *fldname, const char *format,
-			   va_list args);
+			   va_list args) ATTR_FORMAT (printf, 6, 0);
 static void cli_spaces (struct ui_out *uiout, int numspaces);
 static void cli_text (struct ui_out *uiout, const char *string);
 static void cli_message (struct ui_out *uiout, int verbosity,
-			 const char *format, va_list args);
+			 const char *format, va_list args)
+     ATTR_FORMAT (printf, 3, 0);
 static void cli_wrap_hint (struct ui_out *uiout, char *identstring);
 static void cli_flush (struct ui_out *uiout);
 static int cli_redirect (struct ui_out *uiout, struct ui_file *outstream);
@@ -101,7 +102,7 @@ static void field_separator (void);
 
 static void out_field_fmt (struct ui_out *uiout, int fldno,
 			   const char *fldname,
-			   const char *format,...);
+			   const char *format,...) ATTR_FORMAT (printf, 4, 5);
 
 /* local variables */
 
diff -rup orig/gdb-6.3.50.20050727/gdb/complaints.c gdb-6.3.50.20050727/gdb/complaints.c
--- orig/gdb-6.3.50.20050727/gdb/complaints.c	2005-02-17 08:49:49.000000000 -0500
+++ gdb-6.3.50.20050727/gdb/complaints.c	2005-07-29 12:28:16.000000000 -0400
@@ -166,7 +166,7 @@ static unsigned int stop_whining = 0;
 /* Print a complaint, and link the complaint block into a chain for
    later handling.  */
 
-static void
+static void ATTR_FORMAT (printf, 4, 0)
 vcomplaint (struct complaints **c, const char *file, int line, const char *fmt,
 	    va_list args)
 {
diff -rup orig/gdb-6.3.50.20050727/gdb/defs.h gdb-6.3.50.20050727/gdb/defs.h
--- orig/gdb-6.3.50.20050727/gdb/defs.h	2005-05-19 13:55:53.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/defs.h	2005-07-29 12:38:53.000000000 -0400
@@ -872,12 +872,14 @@ extern void *xzalloc (size_t);
 /* Like asprintf/vasprintf but get an internal_error if the call
    fails. */
 extern void xasprintf (char **ret, const char *format, ...) ATTR_FORMAT (printf, 2, 3);
-extern void xvasprintf (char **ret, const char *format, va_list ap);
+extern void xvasprintf (char **ret, const char *format, va_list ap)
+     ATTR_FORMAT (printf, 2, 0);
 
 /* Like asprintf and vasprintf, but return the string, throw an error
    if no memory.  */
 extern char *xstrprintf (const char *format, ...) ATTR_FORMAT (printf, 1, 2);
-extern char *xstrvprintf (const char *format, va_list ap);
+extern char *xstrvprintf (const char *format, va_list ap)
+     ATTR_FORMAT (printf, 1, 0);
 
 /* Like snprintf, but throw an error if the output buffer is too small.  */
 extern int xsnprintf (char *str, size_t size, const char *format, ...)
@@ -897,24 +899,28 @@ extern char *quit_pre_print;
 
 extern char *warning_pre_print;
 
-extern NORETURN void verror (const char *fmt, va_list ap) ATTR_NORETURN;
+extern NORETURN void verror (const char *fmt, va_list ap)
+     ATTR_NORETURN ATTR_FORMAT (printf, 1, 0);
 
 extern NORETURN void error (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 
 extern NORETURN void error_stream (struct ui_file *) ATTR_NORETURN;
 
-extern NORETURN void vfatal (const char *fmt, va_list ap) ATTR_NORETURN;
+extern NORETURN void vfatal (const char *fmt, va_list ap)
+     ATTR_NORETURN ATTR_FORMAT (printf, 1, 0);
 
 extern NORETURN void fatal (const char *fmt, ...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 
 extern NORETURN void internal_verror (const char *file, int line,
-				      const char *, va_list ap) ATTR_NORETURN;
+				      const char *, va_list ap)
+     ATTR_NORETURN ATTR_FORMAT (printf, 3, 0);
 
 extern NORETURN void internal_error (const char *file, int line,
 				     const char *, ...) ATTR_NORETURN ATTR_FORMAT (printf, 3, 4);
 
 extern void internal_vwarning (const char *file, int line,
-			       const char *, va_list ap);
+			       const char *, va_list ap)
+     ATTR_FORMAT (printf, 3, 0);
 
 extern void internal_warning (const char *file, int line,
 			      const char *, ...) ATTR_FORMAT (printf, 3, 4);
@@ -923,7 +929,7 @@ extern NORETURN void nomem (long) ATTR_N
 
 extern void warning (const char *, ...) ATTR_FORMAT (printf, 1, 2);
 
-extern void vwarning (const char *, va_list args);
+extern void vwarning (const char *, va_list args) ATTR_FORMAT (printf, 1, 0);
 
 /* List of known OS ABIs.  If you change this, make sure to update the
    table in osabi.c.  */
@@ -1092,15 +1098,18 @@ extern void (*deprecated_print_frame_inf
 							 int line, int stopline,
 							 int noerror);
 extern struct frame_info *parse_frame_specification (char *frame_exp);
-extern int (*deprecated_query_hook) (const char *, va_list);
-extern void (*deprecated_warning_hook) (const char *, va_list);
+extern int (*deprecated_query_hook) (const char *, va_list)
+     ATTRIBUTE_FPTR_PRINTF(1,0);
+extern void (*deprecated_warning_hook) (const char *, va_list)
+     ATTRIBUTE_FPTR_PRINTF(1,0);
 extern void (*deprecated_flush_hook) (struct ui_file * stream);
 extern void (*deprecated_create_breakpoint_hook) (struct breakpoint * b);
 extern void (*deprecated_delete_breakpoint_hook) (struct breakpoint * bpt);
 extern void (*deprecated_modify_breakpoint_hook) (struct breakpoint * bpt);
 extern void (*deprecated_interactive_hook) (void);
 extern void (*deprecated_registers_changed_hook) (void);
-extern void (*deprecated_readline_begin_hook) (char *,...);
+extern void (*deprecated_readline_begin_hook) (char *, ...)
+     ATTRIBUTE_FPTR_PRINTF_1;
 extern char *(*deprecated_readline_hook) (char *);
 extern void (*deprecated_readline_end_hook) (void);
 extern void (*deprecated_register_changed_hook) (int regno);
diff -rup orig/gdb-6.3.50.20050727/gdb/disasm.c gdb-6.3.50.20050727/gdb/disasm.c
--- orig/gdb-6.3.50.20050727/gdb/disasm.c	2005-05-16 00:45:42.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/disasm.c	2005-07-29 12:28:16.000000000 -0400
@@ -313,7 +313,7 @@ do_assembly_only (struct ui_out *uiout, 
 /* Initialize the disassemble info struct ready for the specified
    stream.  */
 
-static int
+static int ATTR_FORMAT (printf, 2, 3)
 fprintf_disasm (void *stream, const char *format, ...)
 {
   va_list args;
diff -rup orig/gdb-6.3.50.20050727/gdb/exceptions.c gdb-6.3.50.20050727/gdb/exceptions.c
--- orig/gdb-6.3.50.20050727/gdb/exceptions.c	2005-04-28 10:07:54.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/exceptions.c	2005-07-29 12:28:16.000000000 -0400
@@ -373,10 +373,7 @@ print_any_exception (struct ui_file *fil
     }
 }
 
-NORETURN static void
-throw_it (enum return_reason reason, enum errors error, const char *fmt,
-	  va_list ap) ATTR_NORETURN;
-NORETURN static void
+NORETURN static void ATTR_NORETURN ATTR_FORMAT (printf, 3, 0)
 throw_it (enum return_reason reason, enum errors error, const char *fmt,
 	  va_list ap)
 {
diff -rup orig/gdb-6.3.50.20050727/gdb/exceptions.h gdb-6.3.50.20050727/gdb/exceptions.h
--- orig/gdb-6.3.50.20050727/gdb/exceptions.h	2005-06-02 12:52:04.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/exceptions.h	2005-07-29 12:32:43.000000000 -0400
@@ -160,9 +160,10 @@ extern void exception_fprintf (struct ui
    Wombat.  */
 
 extern NORETURN void throw_exception (struct gdb_exception exception) ATTR_NORETURN;
-extern NORETURN void throw_verror (enum errors, const char *fmt,
-				   va_list ap) ATTR_NORETURN;
-extern NORETURN void throw_vfatal (const char *fmt, va_list ap) ATTR_NORETURN;
+extern NORETURN void throw_verror (enum errors, const char *fmt, va_list ap)
+     ATTR_NORETURN ATTR_FORMAT (printf, 2, 0);
+extern NORETURN void throw_vfatal (const char *fmt, va_list ap)
+     ATTR_NORETURN ATTR_FORMAT (printf, 1, 0);
 extern NORETURN void throw_error (enum errors error, const char *fmt,
 				  ...) ATTR_NORETURN ATTR_FORMAT (printf, 2, 3);
 
diff -rup orig/gdb-6.3.50.20050727/gdb/gdbserver/server.h gdb-6.3.50.20050727/gdb/gdbserver/server.h
--- orig/gdb-6.3.50.20050727/gdb/gdbserver/server.h	2005-07-13 11:02:49.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/gdbserver/server.h	2005-07-29 12:28:16.000000000 -0400
@@ -163,9 +163,9 @@ int target_signal_to_host (enum target_s
 /* Functions from utils.c */
 
 void perror_with_name (char *string);
-void error (const char *string,...) ATTR_NORETURN;
-void fatal (const char *string,...) ATTR_NORETURN;
-void warning (const char *string,...);
+void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+void fatal (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+void warning (const char *string,...) ATTR_FORMAT (printf, 1, 2);
 
 /* Functions from the register cache definition.  */
 
diff -rup orig/gdb-6.3.50.20050727/gdb/mi/mi-interp.c gdb-6.3.50.20050727/gdb/mi/mi-interp.c
--- orig/gdb-6.3.50.20050727/gdb/mi/mi-interp.c	2005-04-26 01:03:40.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/mi/mi-interp.c	2005-07-29 12:33:00.000000000 -0400
@@ -55,7 +55,8 @@ static void mi_command_loop (int mi_vers
 /* These are hooks that we put in place while doing interpreter_exec
    so we can report interesting things that happened "behind the mi's
    back" in this command */
-static int mi_interp_query_hook (const char *ctlstr, va_list ap);
+static int mi_interp_query_hook (const char *ctlstr, va_list ap)
+     ATTR_FORMAT (printf, 1, 0);
 
 static void mi3_command_loop (void);
 static void mi2_command_loop (void);
diff -rup orig/gdb-6.3.50.20050727/gdb/mi/mi-out.c gdb-6.3.50.20050727/gdb/mi/mi-out.c
--- orig/gdb-6.3.50.20050727/gdb/mi/mi-out.c	2005-02-11 13:13:55.000000000 -0500
+++ gdb-6.3.50.20050727/gdb/mi/mi-out.c	2005-07-29 12:33:30.000000000 -0400
@@ -56,11 +56,12 @@ static void mi_field_string (struct ui_o
 static void mi_field_fmt (struct ui_out *uiout, int fldno,
 			  int width, enum ui_align align,
 			  const char *fldname, const char *format,
-			  va_list args);
+			  va_list args) ATTR_FORMAT (printf, 6, 0);
 static void mi_spaces (struct ui_out *uiout, int numspaces);
 static void mi_text (struct ui_out *uiout, const char *string);
 static void mi_message (struct ui_out *uiout, int verbosity,
-			const char *format, va_list args);
+			const char *format, va_list args)
+     ATTR_FORMAT (printf, 3, 0);
 static void mi_wrap_hint (struct ui_out *uiout, char *identstring);
 static void mi_flush (struct ui_out *uiout);
 
diff -rup orig/gdb-6.3.50.20050727/gdb/tui/tui-hooks.c gdb-6.3.50.20050727/gdb/tui/tui-hooks.c
--- orig/gdb-6.3.50.20050727/gdb/tui/tui-hooks.c	2005-02-11 19:39:24.000000000 -0500
+++ gdb-6.3.50.20050727/gdb/tui/tui-hooks.c	2005-07-29 12:28:16.000000000 -0400
@@ -70,7 +70,7 @@ tui_new_objfile_hook (struct objfile* ob
     tui_target_new_objfile_chain (objfile);
 }
 
-static int
+static int ATTR_FORMAT (printf, 1, 0)
 tui_query_hook (const char * msg, va_list argp)
 {
   int retval;
diff -rup orig/gdb-6.3.50.20050727/gdb/tui/tui-out.c gdb-6.3.50.20050727/gdb/tui/tui-out.c
--- orig/gdb-6.3.50.20050727/gdb/tui/tui-out.c	2003-10-24 13:37:04.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/tui/tui-out.c	2005-07-29 12:33:50.000000000 -0400
@@ -60,11 +60,12 @@ static void tui_field_string (struct ui_
 static void tui_field_fmt (struct ui_out *uiout, int fldno,
 			   int width, enum ui_align align,
 			   const char *fldname, const char *format,
-			   va_list args);
+			   va_list args) ATTR_FORMAT (printf, 6, 0);
 static void tui_spaces (struct ui_out *uiout, int numspaces);
 static void tui_text (struct ui_out *uiout, const char *string);
 static void tui_message (struct ui_out *uiout, int verbosity,
-			 const char *format, va_list args);
+			 const char *format, va_list args)
+     ATTR_FORMAT (printf, 3, 0);
 static void tui_wrap_hint (struct ui_out *uiout, char *identstring);
 static void tui_flush (struct ui_out *uiout);
 
@@ -102,7 +103,7 @@ static void field_separator (void);
 
 static void out_field_fmt (struct ui_out *uiout, int fldno,
 			   const char *fldname,
-			   const char *format,...);
+			   const char *format,...) ATTR_FORMAT (printf, 4, 5);
 
 /* local variables */
 
diff -rup orig/gdb-6.3.50.20050727/gdb/ui-out.c gdb-6.3.50.20050727/gdb/ui-out.c
--- orig/gdb-6.3.50.20050727/gdb/ui-out.c	2005-02-14 09:37:38.000000000 -0500
+++ gdb-6.3.50.20050727/gdb/ui-out.c	2005-07-29 12:34:26.000000000 -0400
@@ -178,12 +178,12 @@ static void default_field_fmt (struct ui
 			       int width, enum ui_align align,
 			       const char *fldname,
 			       const char *format,
-			       va_list args);
+			       va_list args) ATTR_FORMAT (printf, 6, 0);
 static void default_spaces (struct ui_out *uiout, int numspaces);
 static void default_text (struct ui_out *uiout, const char *string);
 static void default_message (struct ui_out *uiout, int verbosity,
 			     const char *format,
-			     va_list args);
+			     va_list args) ATTR_FORMAT (printf, 3, 0);
 static void default_wrap_hint (struct ui_out *uiout, char *identstring);
 static void default_flush (struct ui_out *uiout);
 
@@ -248,11 +248,13 @@ static void uo_field_string (struct ui_o
 			     const char *string);
 static void uo_field_fmt (struct ui_out *uiout, int fldno, int width,
 			  enum ui_align align, const char *fldname,
-			  const char *format, va_list args);
+			  const char *format, va_list args)
+     ATTR_FORMAT (printf, 6, 0);
 static void uo_spaces (struct ui_out *uiout, int numspaces);
 static void uo_text (struct ui_out *uiout, const char *string);
 static void uo_message (struct ui_out *uiout, int verbosity,
-			const char *format, va_list args);
+			const char *format, va_list args)
+     ATTR_FORMAT (printf, 3, 0);
 static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
 static void uo_flush (struct ui_out *uiout);
 static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
diff -rup orig/gdb-6.3.50.20050727/gdb/ui-out.h gdb-6.3.50.20050727/gdb/ui-out.h
--- orig/gdb-6.3.50.20050727/gdb/ui-out.h	2003-07-18 15:01:14.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/ui-out.h	2005-07-29 12:35:05.000000000 -0400
@@ -123,7 +123,8 @@ extern void ui_out_field_stream (struct 
 				 struct ui_stream *buf);
 
 extern void ui_out_field_fmt (struct ui_out *uiout, const char *fldname,
-			      const char *format, ...);
+			      const char *format, ...)
+     ATTR_FORMAT (printf, 3, 4);
 
 extern void ui_out_field_skip (struct ui_out *uiout, const char *fldname);
 
@@ -132,7 +133,8 @@ extern void ui_out_spaces (struct ui_out
 extern void ui_out_text (struct ui_out *uiout, const char *string);
 
 extern void ui_out_message (struct ui_out *uiout, int verbosity,
-			    const char *format, ...);
+			    const char *format, ...)
+     ATTR_FORMAT (printf, 3, 4);
 
 extern struct ui_stream *ui_out_stream_new (struct ui_out *uiout);
 
@@ -223,12 +225,13 @@ typedef void (field_fmt_ftype) (struct u
 				enum ui_align align,
 				const char *fldname,
 				const char *format,
-				va_list args);
+				va_list args) ATTRIBUTE_FPTR_PRINTF(6,0);
 typedef void (spaces_ftype) (struct ui_out * uiout, int numspaces);
 typedef void (text_ftype) (struct ui_out * uiout,
 			   const char *string);
 typedef void (message_ftype) (struct ui_out * uiout, int verbosity,
-			      const char *format, va_list args);
+			      const char *format, va_list args)
+     ATTRIBUTE_FPTR_PRINTF(3,0);
 typedef void (wrap_hint_ftype) (struct ui_out * uiout, char *identstring);
 typedef void (flush_ftype) (struct ui_out * uiout);
 typedef int (redirect_ftype) (struct ui_out * uiout,
diff -rup orig/gdb-6.3.50.20050727/gdb/utils.c gdb-6.3.50.20050727/gdb/utils.c
--- orig/gdb-6.3.50.20050727/gdb/utils.c	2005-07-04 09:29:13.000000000 -0400
+++ gdb-6.3.50.20050727/gdb/utils.c	2005-07-29 12:35:37.000000000 -0400
@@ -80,7 +80,7 @@ void (*deprecated_error_begin_hook) (voi
 /* Prototypes for local functions */
 
 static void vfprintf_maybe_filtered (struct ui_file *, const char *,
-				     va_list, int);
+				     va_list, int) ATTR_FORMAT (printf, 2, 0);
 
 static void fputs_maybe_filtered (const char *, struct ui_file *, int);
 
@@ -693,7 +693,7 @@ struct internal_problem
    has been reported, and assuming GDB didn't quit, the caller can
    either allow execution to resume or throw an error.  */
 
-static void
+static void ATTR_FORMAT (printf, 4, 0)
 internal_vproblem (struct internal_problem *problem,
 		   const char *file, int line, const char *fmt, va_list ap)
 {
@@ -1236,7 +1236,7 @@ query (const char *ctlstr, ...)
    ARGS are the arguments passed along with the CTLSTR argument to
    printf.  */
 
-static int
+static int ATTR_FORMAT (printf, 1, 0)
 defaulted_query (const char *ctlstr, const char defchar, va_list args)
 {
   int answer;
@@ -1495,8 +1495,8 @@ parse_escape (char **string_ptr)
 
 static void
 printchar (int c, void (*do_fputs) (const char *, struct ui_file *),
-	   void (*do_fprintf) (struct ui_file *, const char *, ...),
-	   struct ui_file *stream, int quoter)
+	   void (*do_fprintf) (struct ui_file *, const char *, ...)
+	   ATTRIBUTE_FPTR_PRINTF_2, struct ui_file *stream, int quoter)
 {
 
   c &= 0xFF;			/* Avoid sign bit follies */


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