diff options
| author | 2010-01-22 13:45:53 +0100 | |
|---|---|---|
| committer | 2010-01-22 13:45:53 +0100 | |
| commit | ab56c34e17f2f44fd51ff3e890c002215fbe7690 (patch) | |
| tree | 75a8ba61bec72e351d466739ef5dfa751a1b46fd | |
| parent | 808d461fea2c1b028e8fbb232eb09a94555856e8 (diff) | |
| download | libimobiledevice-ab56c34e17f2f44fd51ff3e890c002215fbe7690.tar.gz libimobiledevice-ab56c34e17f2f44fd51ff3e890c002215fbe7690.tar.bz2 | |
Turn debug_plist into macro to show caller func/file/line and improve output
| -rw-r--r-- | src/debug.c | 16 | ||||
| -rw-r--r-- | src/debug.h | 9 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/debug.c b/src/debug.c index 2cdeebf..b194b0d 100644 --- a/src/debug.c +++ b/src/debug.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | * contains utilitary functions for debugging | 3 | * contains utilitary functions for debugging |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. |
| 6 | * Copyright (c) 2010 Martin S. All Rights Reserved. | ||
| 6 | * | 7 | * |
| 7 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public | 9 | * modify it under the terms of the GNU Lesser General Public |
| @@ -56,10 +57,12 @@ static void debug_print_line(const char *func, const char *file, int line, const | |||
| 56 | (void)asprintf(&header, "%s %s:%d %s()", str_time, file, line, func); | 57 | (void)asprintf(&header, "%s %s:%d %s()", str_time, file, line, func); |
| 57 | free (str_time); | 58 | free (str_time); |
| 58 | 59 | ||
| 59 | /* always in light green */ | 60 | /* trim ending newlines */ |
| 61 | |||
| 62 | /* print header */ | ||
| 60 | printf ("%s: ", header); | 63 | printf ("%s: ", header); |
| 61 | 64 | ||
| 62 | /* different colors according to the severity */ | 65 | /* print actual debug content */ |
| 63 | printf ("%s\n", buffer); | 66 | printf ("%s\n", buffer); |
| 64 | 67 | ||
| 65 | /* flush this output, as we need to debug */ | 68 | /* flush this output, as we need to debug */ |
| @@ -135,7 +138,7 @@ inline void debug_buffer_to_file(const char *file, const char *data, const int l | |||
| 135 | #endif | 138 | #endif |
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | inline void debug_plist(plist_t plist) | 141 | inline void debug_plist_real(const char *func, const char *file, int line, plist_t plist) |
| 139 | { | 142 | { |
| 140 | #ifndef STRIP_DEBUG_CODE | 143 | #ifndef STRIP_DEBUG_CODE |
| 141 | if (!plist) | 144 | if (!plist) |
| @@ -144,7 +147,12 @@ inline void debug_plist(plist_t plist) | |||
| 144 | char *buffer = NULL; | 147 | char *buffer = NULL; |
| 145 | uint32_t length = 0; | 148 | uint32_t length = 0; |
| 146 | plist_to_xml(plist, &buffer, &length); | 149 | plist_to_xml(plist, &buffer, &length); |
| 147 | debug_info("plist size: %i\nbuffer :\n%s", length, buffer); | 150 | |
| 151 | /* get rid of ending newline as one is already added in the debug line */ | ||
| 152 | if (buffer[length-1] == '\n') | ||
| 153 | buffer[length-1] = '\0'; | ||
| 154 | |||
| 155 | debug_info_real(func, file, line, "printing %i bytes plist:\n%s", length, buffer); | ||
| 148 | free(buffer); | 156 | free(buffer); |
| 149 | #endif | 157 | #endif |
| 150 | } | 158 | } |
diff --git a/src/debug.h b/src/debug.h index 0a29be3..2fd0960 100644 --- a/src/debug.h +++ b/src/debug.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | * contains utilitary functions for debugging | 3 | * contains utilitary functions for debugging |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. |
| 6 | * Copyright (c) 2010 Martin S. All Rights Reserved. | ||
| 6 | * | 7 | * |
| 7 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public | 9 | * modify it under the terms of the GNU Lesser General Public |
| @@ -27,10 +28,13 @@ | |||
| 27 | 28 | ||
| 28 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE) | 29 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE) |
| 29 | #define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__) | 30 | #define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__) |
| 31 | #define debug_plist(a) debug_plist_real (__func__, __FILE__, __LINE__, a) | ||
| 30 | #elif defined(__GNUC__) && __GNUC__ >= 3 && !defined(STRIP_DEBUG_CODE) | 32 | #elif defined(__GNUC__) && __GNUC__ >= 3 && !defined(STRIP_DEBUG_CODE) |
| 31 | #define debug_info(...) debug_info_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) | 33 | #define debug_info(...) debug_info_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) |
| 34 | #define debug_plist(a) debug_plist_real (__FUNCTION__, __FILE__, __LINE__, a) | ||
| 32 | #else | 35 | #else |
| 33 | #define debug_info(...) | 36 | #define debug_info(...) |
| 37 | #define debug_plist(a) | ||
| 34 | #endif | 38 | #endif |
| 35 | 39 | ||
| 36 | G_GNUC_INTERNAL inline void debug_info_real(const char *func, | 40 | G_GNUC_INTERNAL inline void debug_info_real(const char *func, |
| @@ -40,6 +44,9 @@ G_GNUC_INTERNAL inline void debug_info_real(const char *func, | |||
| 40 | 44 | ||
| 41 | G_GNUC_INTERNAL inline void debug_buffer(const char *data, const int length); | 45 | G_GNUC_INTERNAL inline void debug_buffer(const char *data, const int length); |
| 42 | G_GNUC_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length); | 46 | G_GNUC_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length); |
| 43 | G_GNUC_INTERNAL inline void debug_plist(plist_t plist); | 47 | G_GNUC_INTERNAL inline void debug_plist_real(const char *func, |
| 48 | const char *file, | ||
| 49 | int line, | ||
| 50 | plist_t plist); | ||
| 44 | 51 | ||
| 45 | #endif | 52 | #endif |
