[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH] lib/ukdebug: Align hexdump with print system
With the recent update of the print system, the hexdump functionality was not adopted. This made this functionality useless. With this commit hexdump is align with the printing again system. For instance, uk_hexdumpd() is only enabled in the code when either UK_DEBUG is defined for the compilation unit or debug messages are enabled globally. uk_hexdumpk() depends on having kernel console enabled and on the configured maximum message level. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- lib/ukdebug/exportsyms.uk | 3 ++- lib/ukdebug/hexdump.c | 44 +++++++++++++++++++++---------------- lib/ukdebug/include/uk/hexdump.h | 47 +++++++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/lib/ukdebug/exportsyms.uk b/lib/ukdebug/exportsyms.uk index d3494301..cb8d2403 100644 --- a/lib/ukdebug/exportsyms.uk +++ b/lib/ukdebug/exportsyms.uk @@ -5,4 +5,5 @@ _uk_printk uk_hexdumpsn uk_hexdumpf uk_hexdumpd -_uk_hexdumdk +_uk_hexdumpd +_uk_hexdumpk diff --git a/lib/ukdebug/hexdump.c b/lib/ukdebug/hexdump.c index cd70c734..eb533bdb 100644 --- a/lib/ukdebug/hexdump.c +++ b/lib/ukdebug/hexdump.c @@ -61,18 +61,20 @@ struct _hxd_output { enum _hxd_output_type type; union { -#if CONFIG_LIBUKDEBUG_PRINTK + /* UK_HXDOUT_KERN, UK_HXDOUT_DEBUG */ struct { - int lvl; + int lvl; /* UK_HXDOUT_KERN only */ const char *libname; const char *srcname; unsigned int srcline; - } kern; -#endif + } ukprint; + + /* UK_HXDOUT_FILE */ struct { FILE *fp; } file; + /* UK_HXDOUT_BUFFER */ struct { char *pos; size_t left; @@ -105,12 +107,15 @@ static int _hxd_outf(struct _hxd_output *o, const char *fmt, ...) } break; case UK_HXDOUT_DEBUG: - uk_vprintd(fmt, ap); + _uk_vprintd(o->ukprint.libname, + o->ukprint.srcname, o->ukprint.srcline, + fmt, ap); break; #if CONFIG_LIBUKDEBUG_PRINTK case UK_HXDOUT_KERN: - _uk_vprintk(o->kern.lvl, o->kern.libname, o->kern.srcname, - o->kern.srcline, fmt, ap); + _uk_vprintk(o->ukprint.lvl, o->ukprint.libname, + o->ukprint.srcname, o->ukprint.srcline, + fmt, ap); break; #endif default: @@ -319,16 +324,17 @@ int uk_hexdumpf(FILE *fp, const void *data, size_t len, size_t addr0, int flags, return _hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix); } -void uk_hexdumpd(const void *data, size_t len, int flags, - unsigned int grps_per_line) +void _uk_hexdumpd(const char *libname, const char *srcname, + unsigned int srcline, const void *data, size_t len, + size_t addr0, int flags, unsigned int grps_per_line, + const char *line_prefix) { -#if CONFIG_LIBUKDEBUG_PRINTD - struct _hxd_output o = {.type = UK_HXDOUT_DEBUG}; + struct _hxd_output o = {.type = UK_HXDOUT_DEBUG, + .ukprint.libname = libname, + .ukprint.srcname = srcname, + .ukprint.srcline = srcline}; - _hxd(&o, data, len, (size_t)data, flags, grps_per_line, ""); -#else - return; -#endif + _hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix); } #if CONFIG_LIBUKDEBUG_PRINTK @@ -338,10 +344,10 @@ void _uk_hexdumpk(int lvl, const char *libname, const char *srcname, const char *line_prefix) { struct _hxd_output o = {.type = UK_HXDOUT_KERN, - .kern.lvl = lvl, - .kern.libname = libname, - .kern.srcname = srcname, - .kern.srcline = srcline}; + .ukprint.lvl = lvl, + .ukprint.libname = libname, + .ukprint.srcname = srcname, + .ukprint.srcline = srcline}; _hxd(&o, data, len, addr0, flags, grps_per_line, line_prefix); } diff --git a/lib/ukdebug/include/uk/hexdump.h b/lib/ukdebug/include/uk/hexdump.h index c77742c0..2e91edb2 100644 --- a/lib/ukdebug/include/uk/hexdump.h +++ b/lib/ukdebug/include/uk/hexdump.h @@ -55,11 +55,34 @@ extern "C" { #define UK_HXDF_COMPRESS (64) /* suppress repeated lines */ -#if defined UK_DEBUG || CONFIG_LIBUKDEBUG_PRINTD +/* + * HEXDUMP ON DEBUG CONSOLE + */ +#ifdef __IN_LIBUKDEBUG__ +/* + * This redefinition of CONFIG_LIBUKDEBUG_PRINTD is doing the trick to + * switch on the correct declaration of uk_hexdumpd() when we are compiling + * this library and have the global debug switch CONFIG_LIBUKDEBUG_PRINTD + * not enabled. + */ +#if !defined CONFIG_LIBUKDEBUG_PRINTD || !CONFIG_LIBUKDEBUG_PRINTD +#undef CONFIG_LIBUKDEBUG_PRINTD +#define CONFIG_LIBUKDEBUG_PRINTD 1 +#endif +#endif /* __IN_LIBUKDEBUG__ */ + +#if (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD +/* Please use uk_hexdumpd() instead */ +void _uk_hexdumpd(const char *libname, const char *srcname, + unsigned int srcline, const void *data, size_t len, + size_t addr0, int flags, unsigned int grps_per_line, + const char *line_prefix); + /** - * Plots an hexdump for a given data region to debug output + * Plots an hexdump for a given data region to kernel output * The absolute address is plotted when UK_HXDF_ADDR is set * + * @param lvl Debug level * @param data Start of data region to plot * @param len Length of data region (number of bytes) * @param flags Format flags, see UK_HXDF_* @@ -67,16 +90,20 @@ extern "C" { * Number of groups (UK_HXDF_GRP*) shown per line * @return Returns the number of printed characters to output fp */ -void uk_hexdumpd(const void *data, size_t len, int flags, - unsigned int grps_per_line); -#else +#define uk_hexdumpd(data, len, flags, grps_per_line) \ + _uk_hexdumpd(__STR_LIBNAME__, __STR_BASENAME__, \ + __LINE__, (data), (len), \ + ((size_t)(data)), (flags), \ + (grps_per_line), STRINGIFY(data) ": ") +#else /* (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD */ static inline void uk_hexdumpd(const void *data __unused, size_t len __unused, int flags __unused, unsigned int grps_per_line __unused) {} -#endif +#endif /* (defined UK_DEBUG) || CONFIG_LIBUKDEBUG_PRINTD */ #if CONFIG_LIBUKDEBUG_PRINTK +/* Please use uk_hexdumpk() instead */ void _uk_hexdumpk(int lvl, const char *libname, const char *srcname, unsigned int srcline, const void *data, size_t len, size_t addr0, int flags, unsigned int grps_per_line, @@ -97,17 +124,17 @@ void _uk_hexdumpk(int lvl, const char *libname, const char *srcname, #define uk_hexdumpk(lvl, data, len, flags, grps_per_line) \ do { \ if ((lvl) <= KLVL_MAX) \ - _uk_hexdumpd((lvl), __STR_LIBNAME__, __STR_BASENAME__, \ + _uk_hexdumpk((lvl), __STR_LIBNAME__, __STR_BASENAME__, \ __LINE__, (data), (len), \ ((size_t)(data)), (flags), \ (grps_per_line), STRINGIFY(data) ": "); \ } while (0) -#else +#else /* CONFIG_LIBUKDEBUG_PRINTK */ static inline void uk_hexdumpk(int lvl __unused, const void *data __unused, size_t len __unused, int flags __unused, unsigned int grps_per_line __unused) {} -#endif +#endif /* CONFIG_LIBUKDEBUG_PRINTK */ /** * Plots an hexdump for a given data region to a file descriptor @@ -214,7 +241,7 @@ int uk_hexdumpsn(char *str, size_t size, const void *data, size_t len, 2, NULL) #define uk_hexdumpC(data, len) \ - uk_hexdumpf((data), (len), ((size_t)(data)), \ + uk_hexdump((data), (len), ((size_t)(data)), \ (UK_HXDF_ADDR | UK_HXDF_ASCIISEC | UK_HXDF_GRPQWORD \ | UK_HXDF_COMPRESS), \ 2, NULL) -- 2.11.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |