Patchwork [4/4] debugcon: use fprintf(stderr...) instead of printf

login
register
mail settings
Submitter liguang
Date May 24, 2013, 2:47 a.m.
Message ID <1369363654-7063-5-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/246049/
State New
Headers show

Comments

liguang - May 24, 2013, 2:47 a.m.
suggested by Andreas Färber <afaerber@suse.de>

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 hw/char/debugcon.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
Andreas Färber - May 24, 2013, 11:55 a.m.
Am 24.05.2013 04:47, schrieb liguang:
> suggested by Andreas Färber <afaerber@suse.de>
> 
> Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> ---
>  hw/char/debugcon.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
> index 3b0637d..be20ede 100644
> --- a/hw/char/debugcon.c
> +++ b/hw/char/debugcon.c
> @@ -55,7 +55,8 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
>      unsigned char ch = val;
>  
>  #ifdef DEBUG_DEBUGCON
> -    printf(" [debugcon: write addr=0x%04" HWADDR_PRIx " val=0x%02" PRIx64 "]\n", addr, val);
> +    fprintf(stderr, " [debugcon: write addr=0x%04" HWADDR_PRIx
> +            " val=0x%02" PRIx64 "]\n", addr, val);
>  #endif
>  
>      qemu_chr_fe_write(s->chr, &ch, 1);
> @@ -67,7 +68,7 @@ static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
>      DebugconState *s = opaque;
>  
>  #ifdef DEBUG_DEBUGCON
> -    printf("debugcon: read addr=0x%04" HWADDR_PRIx "\n", addr);
> +    fprintf(stderr, "debugcon: read addr=0x%04" HWADDR_PRIx "\n", addr);
>  #endif
>  
>      return s->readback;
> 

Actually my suggestion was to make this a two-patch series:

1/2 debugcon: Fix debug format specifiers
2/2 debugcon: Separate debug console output from device debug output

The former would do both HWADDR_PRIx and PRIx64 in one go and not do a
lengthy example or "Oh, that's wrong" in the commit message.
The latter would change where/how the debug output is written, without
changing to " [...]".

Thinking more about this, I think it would be best to turn this into a
DPRINTF() macro or so, then the change can be made in one central
location and the inline #ifdefs can be dropped. Bonus points if the
macro were designed in such a way that even if DEBUG_DEBUGCON is not
defined the (f)printfs get tested, to avoid regressions. :)

Regards,
Andreas

Patch

diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c
index 3b0637d..be20ede 100644
--- a/hw/char/debugcon.c
+++ b/hw/char/debugcon.c
@@ -55,7 +55,8 @@  static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf(" [debugcon: write addr=0x%04" HWADDR_PRIx " val=0x%02" PRIx64 "]\n", addr, val);
+    fprintf(stderr, " [debugcon: write addr=0x%04" HWADDR_PRIx
+            " val=0x%02" PRIx64 "]\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
@@ -67,7 +68,7 @@  static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
     DebugconState *s = opaque;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: read addr=0x%04" HWADDR_PRIx "\n", addr);
+    fprintf(stderr, "debugcon: read addr=0x%04" HWADDR_PRIx "\n", addr);
 #endif
 
     return s->readback;