Skip to contentSkip to conversation

debugcon: fix always print "addr=0x0, val=0x0" bug

PATCH Superseded liguang 2 participants 6 messages Apr 12, 2013 – Apr 15, 2013

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH 1/3 debugcon: fix always print "addr=0x0, val=0x0" bug

when use DEBUG_DEBUGCON, screen spits:
debugcon: write addr=0x0000 val=0x00
Rdebugcon: write addr=0x0000 val=0x00
udebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
idebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
gdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
pdebugcon: write addr=0x0000 val=0x00
tdebugcon: write addr=0x0000 val=0x00
idebugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
rdebugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
mdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
adebugcon: write addr=0x0000 val=0x00
tdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00

Oh, that's wrong, val is not always be 0. this bug caused by lack of length modifier for specifier 'x'.

---
 hw/char/debugcon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/char/debugcon.c +1 -1
index 0588eeb..e41ec8a 100644
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+    printf("debugcon: write addr=0x%04llx val=0x%02x\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
Signature · 1 line
1.7.2.5
author
#1 lore raw

PATCH 2/3 debugcon: make debug message more readable

before change:
Bdebugcon: write addr=0x0000 val=0x6f
odebugcon: write addr=0x0000 val=0x6f
odebugcon: write addr=0x0000 val=0x74
tdebugcon: write addr=0x0000 val=0x69
idebugcon: write addr=0x0000 val=0x6e
ndebugcon: write addr=0x0000 val=0x67
gdebugcon: write addr=0x0000 val=0x20
debugcon: write addr=0x0000 val=0x66

after change:
B [debugcon: write addr=0x0000 val=0x6f]
o [debugcon: write addr=0x0000 val=0x6f]
o [debugcon: write addr=0x0000 val=0x74] t [debugcon: write addr=0x0000 val=0x69] i [debugcon: write addr=0x0000 val=0x6e] n [debugcon: write addr=0x0000 val=0x67] g [debugcon: write addr=0x0000 val=0x20] [debugcon: write addr=0x0000 val=0x66]

---
 hw/char/debugcon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/char/debugcon.c +1 -1
index e41ec8a..b52cbeb 100644
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: write addr=0x%04llx val=0x%02x\n", addr, val);
+    printf(" [debugcon: write addr=0x%04llx val=0x%02x]\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
Signature · 1 line
1.7.2.5
author
#2 lore raw

PATCH 3/3 debugcon: fix compiler warning when open DEBUG_DEBUGCON

In reply to liguang

compiler warnings:
CC hw/char/debugcon.o
hw/char/debugcon.c: In function ‘debugcon_ioport_write’:
hw/char/debugcon.c:58: warning: format ‘%02x’ expects type ‘unsigned int’, but argument 3 has type ‘uint64_t’ hw/char/debugcon.c: In function ‘debugcon_ioport_read’:
hw/char/debugcon.c:70: warning: format ‘%04x’ expects type ‘unsigned int’, but argument 2 has type ‘hwaddr’

---
 hw/char/debugcon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/char/debugcon.c +2 -2
index b52cbeb..4cf07c6 100644
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf(" [debugcon: write addr=0x%04llx val=0x%02x]\n", addr, val);
+    printf(" [debugcon: write addr=0x%04llx val=0x%02llx]\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
@@ -67,7 +67,7 @@ static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
     DebugconState *s = opaque;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: read addr=0x%04x\n", addr);
+    printf("debugcon: read addr=0x%04llx\n", addr);
 #endif
 
     return s->readback;
Signature · 1 line
1.7.2.5
#3 lore raw

Re: [Qemu-devel] [PATCH 3/3] debugcon: fix compiler warning when open DEBUG_DEBUGCON

Am 12.04.2013 06:12, schrieb liguang:

Quoted 26 lines

compiler warnings:
CC hw/char/debugcon.o
hw/char/debugcon.c: In function ‘debugcon_ioport_write’:
hw/char/debugcon.c:58: warning: format ‘%02x’ expects type ‘unsigned int’, but argument 3 has type ‘uint64_t’ hw/char/debugcon.c: In function ‘debugcon_ioport_read’:
hw/char/debugcon.c:70: warning: format ‘%04x’ expects type ‘unsigned int’, but argument 2 has type ‘hwaddr’

---
 hw/char/debugcon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/char/debugcon.c +1 -1
index b52cbeb..4cf07c6 100644
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf(" [debugcon: write addr=0x%04llx val=0x%02x]\n", addr, val);
+    printf(" [debugcon: write addr=0x%04llx val=0x%02llx]\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);

hw/char/debugcon.c static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width) · line 73

Quoted 8 lines
hw/char/debugcon.c +1 -1
@@ -67,7 +67,7 @@ static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
     DebugconState *s = opaque;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: read addr=0x%04x\n", addr);
+    printf("debugcon: read addr=0x%04llx\n", addr);
 #endif
 
     return s->readback;

Please see PRIx comment on 1/3.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#4 lore raw

Re: [Qemu-devel] [PATCH 3/3] debugcon: fix compiler warning when open DEBUG_DEBUGCON

Quoted 29 lines · 在 2013-04-12五的 14:19 +0200,Andreas Färber写道:

Am 12.04.2013 06:12, schrieb liguang:

Quoted 28 lines

compiler warnings:
CC hw/char/debugcon.o
hw/char/debugcon.c: In function ‘debugcon_ioport_write’:
hw/char/debugcon.c:58: warning: format ‘%02x’ expects type ‘unsigned int’, but argument 3 has type ‘uint64_t’ hw/char/debugcon.c: In function ‘debugcon_ioport_read’:
hw/char/debugcon.c:70: warning: format ‘%04x’ expects type ‘unsigned int’, but argument 2 has type ‘hwaddr’

---
 hw/char/debugcon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/char/debugcon.c +1 -1
index b52cbeb..4cf07c6 100644
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf(" [debugcon: write addr=0x%04llx val=0x%02x]\n", addr, val);
+    printf(" [debugcon: write addr=0x%04llx val=0x%02llx]\n", addr, val);
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
@@ -67,7 +67,7 @@ static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width)
     DebugconState *s = opaque;
 
Quoted 9 lines

hw/char/debugcon.c static uint64_t debugcon_ioport_read(void *opaque, hwaddr addr, unsigned width) · line 73

Quoted 6 lines
hw/char/debugcon.c +1 -1
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: read addr=0x%04x\n", addr);
+    printf("debugcon: read addr=0x%04llx\n", addr);
 #endif
 
     return s->readback;

Please see PRIx comment on 1/3.

right, thanks!

#5 lore raw
In reply to liguang

Am 12.04.2013 06:12, schrieb liguang:

Quoted 39 lines

when use DEBUG_DEBUGCON, screen spits:
debugcon: write addr=0x0000 val=0x00
Rdebugcon: write addr=0x0000 val=0x00
udebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
idebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
gdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
pdebugcon: write addr=0x0000 val=0x00
tdebugcon: write addr=0x0000 val=0x00
idebugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
ndebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
rdebugcon: write addr=0x0000 val=0x00
odebugcon: write addr=0x0000 val=0x00
mdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00
adebugcon: write addr=0x0000 val=0x00
tdebugcon: write addr=0x0000 val=0x00
debugcon: write addr=0x0000 val=0x00

Oh, that's wrong, val is not always be 0. this bug caused by lack of length modifier for specifier 'x'.

---
 hw/char/debugcon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/char/debugcon.c +0 -0
index 0588eeb..e41ec8a 100644

hw/char/debugcon.c static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val, · line 58

Quoted 5 lines
hw/char/debugcon.c +1 -1
@@ -55,7 +55,7 @@ static void debugcon_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     unsigned char ch = val;
 
 #ifdef DEBUG_DEBUGCON
-    printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+    printf("debugcon: write addr=0x%04llx val=0x%02x\n", addr, val);

That is almost as wrong as before:

addr is of type hwaddr, so there should be a HWADDR_PRIx to use instead of hardcoded x or llx, which in turn depends on uint64_t implementation.

val is of type uint64_t so you should use POSIX' PRIx64.

Andreas

Quoted 4 lines
hw/char/debugcon.c +0 -0
 #endif
 
     qemu_chr_fe_write(s->chr, &ch, 1);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg