From ef98ef7211bc6277e9a87349f0405957ab264936 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 8 Jan 2009 18:17:21 +0100 Subject: Perform proper goodby on lockdown shutdown. --- src/utils.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 049777a..fb98471 100644 --- a/src/utils.c +++ b/src/utils.c @@ -46,7 +46,7 @@ void log_debug_msg(const char *format, ...) va_start(args, format); if (toto_debug) - fprintf(stderr, format, args); + vfprintf(stderr, format, args); va_end(args); @@ -56,11 +56,35 @@ void log_debug_msg(const char *format, ...) inline void log_debug_buffer(const char *data, const int length) { #ifndef STRIP_DEBUG_CODE + int i; + int j; + unsigned char c; - /* run the real fprintf */ - if (toto_debug) - fwrite(data, 1, length, stderr); - + if (toto_debug) { + for (i = 0; i < length; i += 16) { + fprintf(stderr, "%04x: ", i); + for (j = 0; j < 16; j++) { + if (i + j >= length) { + fprintf(stderr, " "); + continue; + } + fprintf(stderr, "%02hhx ", *(data + i + j)); + } + fprintf(stderr, " | "); + for (j = 0; j < 16; j++) { + if (i + j >= length) + break; + c = *(data + i + j); + if ((c < 32) || (c > 127)) { + fprintf(stderr, "."); + continue; + } + fprintf(stderr, "%c", c); + } + fprintf(stderr, "\n"); + } + fprintf(stderr, "\n"); + } #endif } -- cgit v1.1-32-gdbae From bc2f3964851dff088dd47a08997e6c6730258834 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Fri, 9 Jan 2009 19:23:43 +0100 Subject: Improve logging mechanism. --- src/utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index fb98471..988cb03 100644 --- a/src/utils.c +++ b/src/utils.c @@ -23,6 +23,7 @@ #include "utils.h" int toto_debug = 0; +uint16_t dbg_mask = 0; /** * Sets the level of debugging. Currently the only acceptable values are 0 and @@ -36,6 +37,15 @@ void iphone_set_debug(int level) } +/** + * Set debug ids to display. Values can be OR-ed + * + * @param level Set to 0 for no debugging or 1 for debugging. + */ +void iphone_set_debug_mask(uint16_t mask) +{ + dbg_mask = mask; +} void log_debug_msg(const char *format, ...) { @@ -53,6 +63,22 @@ void log_debug_msg(const char *format, ...) #endif } +void log_dbg_msg(uint16_t id, const char *format, ...) +{ +#ifndef STRIP_DEBUG_CODE + + if (id & dbg_mask) { + va_list args; + /* run the real fprintf */ + va_start(args, format); + + vfprintf(stderr, format, args); + + va_end(args); + } +#endif +} + inline void log_debug_buffer(const char *data, const int length) { #ifndef STRIP_DEBUG_CODE -- cgit v1.1-32-gdbae