qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qemu-print: New qemu_fprintf(), qemu_vfprintf()

Code that doesn't want to know about current monitor vs. stdout
vs. stderr takes an fprintf_function callback and a FILE * argument to
pass to it. Actual arguments are either fprintf() and stdout or
stderr, or monitor_fprintf() and the current monitor cast to FILE *.
monitor_fprintf() casts it right back, and is otherwise identical to
monitor_printf(). The type-punning is ugly.

New qemu_fprintf() and qemu_vprintf() address this need without type
punning: they are like fprintf() and vfprintf(), except they print to
the current monitor when passed a null FILE *. The next commits will
put them to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20190417191805.28198-14-armbru@redhat.com>

+31
+4
include/qemu/qemu-print.h
··· 16 16 int qemu_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); 17 17 int qemu_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); 18 18 19 + int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) 20 + GCC_FMT_ATTR(2, 0); 21 + int qemu_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3); 22 + 19 23 #endif
+27
util/qemu-print.c
··· 40 40 va_end(ap); 41 41 return ret; 42 42 } 43 + 44 + /* 45 + * Print like vfprintf() 46 + * Print to @stream if non-null, else to current monitor. 47 + */ 48 + int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) 49 + { 50 + if (!stream) { 51 + return monitor_vprintf(cur_mon, fmt, ap); 52 + } 53 + return vfprintf(stream, fmt, ap); 54 + } 55 + 56 + /* 57 + * Print like fprintf(). 58 + * Print to @stream if non-null, else to current monitor. 59 + */ 60 + int qemu_fprintf(FILE *stream, const char *fmt, ...) 61 + { 62 + va_list ap; 63 + int ret; 64 + 65 + va_start(ap, fmt); 66 + ret = qemu_vfprintf(stream, fmt, ap); 67 + va_end(ap); 68 + return ret; 69 + }