>From a598fb00caf89a02eb64145cdada559f9405235b Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Mon, 29 Jul 2013 21:27:04 +0200 Subject: [PATCH] gd_vc_chr_write(): print hexdump, set nonblock Signed-off-by: Laszlo Ersek --- ui/gtk.c | 14 +++++++++++++- util/hexdump.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index c38146f..c88bd37 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -35,6 +35,7 @@ #define LOCALEDIR "po" #include "qemu-common.h" +#include "qemu/sockets.h" #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE /* Work around an -Wstrict-prototypes warning in GTK headers */ @@ -1119,8 +1120,18 @@ static gboolean gd_focus_out_event(GtkWidget *widget, static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len) { VirtualConsole *vc = chr->opaque; + int written, errno_save; - return write(vc->fd, buf, len); + errno = 0; + written = write(vc->fd, buf, len); + errno_save = errno; + + fprintf(stderr, "%s: len=%d written=%d errno=%d\n", __FUNCTION__, len, + written, errno); + qemu_hexdump((const char *)buf, stderr, __FUNCTION__, len); + + errno = errno_save; + return written; } static int nb_vcs; @@ -1213,6 +1224,7 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL vte_terminal_set_size(VTE_TERMINAL(vc->terminal), 80, 25); vc->fd = slave_fd; + qemu_set_nonblock(slave_fd); vc->chr->opaque = vc; vc->scrolled_window = scrolled_window; diff --git a/util/hexdump.c b/util/hexdump.c index 969b340..994fd69 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -13,25 +13,50 @@ * GNU GPL, version 2 or (at your option) any later version. */ +#include #include "qemu-common.h" +static void asciiize(const char *buf, FILE *fp, size_t size, unsigned *col) +{ + size_t i; + + while (*col < 4 + 1 + 4 * (1 + 4 * (1 + 2))) { + fputc(' ', fp); + ++*col; + } + *col = 0; + + fprintf(fp, " '"); + for (i = 0; i < size; ++i) { + unsigned char c = buf[i]; + + fputc(isprint(c) ? c : '.', fp); + } + fprintf(fp, "'\n"); +} + void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size) { unsigned int b; + unsigned pos, col; for (b = 0; b < size; b++) { - if ((b % 16) == 0) { + pos = b % 16; + + if (pos == 0) { fprintf(fp, "%s: %04x:", prefix, b); + col = 5; } if ((b % 4) == 0) { - fprintf(fp, " "); + col += fprintf(fp, " "); } - fprintf(fp, " %02x", (unsigned char)buf[b]); - if ((b % 16) == 15) { - fprintf(fp, "\n"); + col += fprintf(fp, " %02x", (unsigned char)buf[b]); + if (pos == 15) { + asciiize(buf + (b - 15), fp, 16, &col); } } - if ((b % 16) != 0) { - fprintf(fp, "\n"); + pos = b % 16; + if (pos != 0) { + asciiize(buf + (b - pos), fp, pos, &col); } } -- 1.7.1