public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] sim: callback: add printf attributes
Date: Sun, 27 Jun 2021 23:24:38 -0400	[thread overview]
Message-ID: <20210628032439.14514-2-vapier@gentoo.org> (raw)
In-Reply-To: <20210628032439.14514-1-vapier@gentoo.org>

This helps these funcs get printf format checking coverage.

The sim-io.c hack as a result is a bit unfortunate, but the compiler
throws warnings when printing with empty strings.  In this one case,
we actually want that due to the side-effect of the callback halting
execution for us.
---
 include/sim/callback.h | 12 ++++++++----
 sim/common/sim-io.c    |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/include/sim/callback.h b/include/sim/callback.h
index be72f4503e1a..06aa2d4be790 100644
--- a/include/sim/callback.h
+++ b/include/sim/callback.h
@@ -113,18 +113,22 @@ struct host_callback_struct
   int (*init)     (host_callback *);
 
   /* depreciated, use vprintf_filtered - Talk to the user on a console.  */
-  void (*printf_filtered) (host_callback *, const char *, ...);
+  void (*printf_filtered) (host_callback *, const char *, ...)
+    ATTRIBUTE_PRINTF_2;
 
   /* Talk to the user on a console.  */
-  void (*vprintf_filtered) (host_callback *, const char *, va_list);
+  void (*vprintf_filtered) (host_callback *, const char *, va_list)
+    ATTRIBUTE_PRINTF (2, 0);
 
   /* Same as vprintf_filtered but to stderr.  */
-  void (*evprintf_filtered) (host_callback *, const char *, va_list);
+  void (*evprintf_filtered) (host_callback *, const char *, va_list)
+    ATTRIBUTE_PRINTF (2, 0);
 
   /* Print an error message and "exit".
      In the case of gdb "exiting" means doing a longjmp back to the main
      command loop.  */
-  void (*error) (host_callback *, const char *, ...) ATTRIBUTE_NORETURN;
+  void (*error) (host_callback *, const char *, ...)
+    ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_2;
 
   int last_errno;		/* host format */
 
diff --git a/sim/common/sim-io.c b/sim/common/sim-io.c
index e09a4af7ba2e..0d14e0dfc452 100644
--- a/sim/common/sim-io.c
+++ b/sim/common/sim-io.c
@@ -309,7 +309,8 @@ sim_io_error (SIM_DESC sd,
     va_start (ap, fmt);
     STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
     va_end (ap);
-    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), "");
+    /* Printing a space here avoids empty printf compiler warnings.  */
+    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), " ");
   }
 }
 
-- 
2.31.1


  reply	other threads:[~2021-06-28  3:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  3:24 [PATCH 1/3] sim: callback: drop unused printf helpers Mike Frysinger
2021-06-28  3:24 ` Mike Frysinger [this message]
2021-06-29  7:01   ` [PATCH 2/3] sim: callback: add printf attributes Aktemur, Tankut Baris
2021-06-29 14:32     ` Mike Frysinger
2021-06-29 16:03       ` Aktemur, Tankut Baris
2021-06-29 20:35         ` Mike Frysinger
2021-07-02  0:34         ` Mike Frysinger
2021-07-02  7:16           ` Aktemur, Tankut Baris
2021-06-30  2:33     ` [PATCH] sim: ppc: fix printf warnings Mike Frysinger
2021-06-28  3:24 ` [PATCH 3/3] sim: io: add printf attributes to vprintf funcs too Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628032439.14514-2-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).