#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include "ctl/ctldef.h"
#include "ctl/debug.h"
#include <setjmp.h>
#include <signal.h>
Go to the source code of this file.
Functions | |
void | debug_log (unsigned mask, const char *fmt,...) |
Logging function. | |
void | debug_vlog (unsigned mask, const char *fmt, va_list args) |
Logging function. | |
void | debug_logalways (const char *fmt,...) |
Logging function that always logs. | |
void | debug_vlogalways (const char *fmt, va_list args) |
Logging function that always logs. | |
void | debug_setvlog (debug_vlog_t debug_vlog) |
Set log handler. | |
void | debug_setlogmask (unsigned mask) |
Set log mask. | |
unsigned | debug_getlogmask (void) |
Get the log mask. | |
void | debug_loghex (unsigned mask, const void *ptr, size_t size) |
Log a pretty, formatted hex dump. | |
void | debug_settrace (debug_trace_t trace) |
Set debug trace handler. | |
Variables | |
debug_trace_t | debug_trace = debug_printf |
The universal debug trace handler. |
Definition in file debug.c.
unsigned debug_getlogmask | ( | void | ) |
Get the log mask.
Definition at line 113 of file debug.c.
Referenced by serial_log().
void debug_log | ( | unsigned | mask, | |
const char * | fmt, | |||
... | ||||
) |
Logging function.
mask | Mask to check against allowable log types, or 0 for 'always' | |
fmt | It's a printf, so format accordingly |
Definition at line 29 of file debug.c.
References assertcodeptr, and assertconst.
Referenced by ctl_profiles_dump(), and ctl_profiles_dump_averages_sheet().
00030 { 00031 assertconst(fmt,1); 00032 assertcodeptr(pdebug_vlog); 00033 if( (mask & debug_logmask) || 0 == mask ) 00034 { 00035 va_list args; 00036 va_start( args, fmt ); 00037 pdebug_vlog( fmt, args ); 00038 fflush(stdout); 00039 } 00040 }
void debug_logalways | ( | const char * | fmt, | |
... | ||||
) |
Logging function that always logs.
fmt | It's a printf, so format accordingly |
Definition at line 62 of file debug.c.
References assertcodeptr, and assertconst.
Referenced by debug_loghex(), and serial_log().
00063 { 00064 va_list args; 00065 va_start( args, fmt ); 00066 assertconst(fmt,1); 00067 assertcodeptr(pdebug_vlog); 00068 pdebug_vlog( fmt, args ); 00069 }
void debug_loghex | ( | unsigned | mask, | |
const void * | ptr, | |||
size_t | size | |||
) |
Log a pretty, formatted hex dump.
mask | Set/clear application defined bits to reduce spew | |
ptr | Pointer to data to dump | |
size | Size of data to dump |
Definition at line 124 of file debug.c.
References assertconst, and debug_logalways().
00125 { 00126 assertconst(ptr,size); 00127 if( (mask & debug_logmask) || 0 == mask ) 00128 { 00129 char printable[16]; 00130 const unsigned char* pBuff = (const unsigned char*)ptr; 00131 size_t curr = 0; 00132 while( curr < size ) 00133 { 00134 unsigned ch = *pBuff++; 00135 if( 0 == (curr & 0xf) ) 00136 { 00137 debug_logalways( "%08x: ", curr ); 00138 } 00139 debug_logalways( "%02x ", ch ); 00140 printable[curr&0xf] = isprint(ch) ? ch : '.'; 00141 if( 0xf == (curr++ & 0xf) ) 00142 { 00143 debug_logalways( " | %16.16s\n", printable ); 00144 } 00145 } 00146 /* Leftovers */ 00147 if( 0 != (size & 0xf) ) 00148 { 00149 for( curr = curr & 0xf; curr < 16; ++curr ) 00150 { 00151 debug_logalways( "-- " ); 00152 printable[curr] = ' '; 00153 } 00154 debug_logalways( " | %16.16s\n", printable ); 00155 } 00156 } 00157 }
void debug_setlogmask | ( | unsigned | mask | ) |
void debug_settrace | ( | debug_trace_t | trace | ) |
Set debug trace handler.
trace | Function to handle traces (NULL for default) |
Definition at line 180 of file debug.c.
References assertcodeptr, and debug_trace.
00181 { 00182 debug_trace = NULL == trace ? debug_printf : trace; 00183 assertcodeptr(debug_trace); 00184 }
void debug_setvlog | ( | debug_vlog_t | debug_vlog | ) |
Set log handler.
log | Function to handle traces (NULL for default - vprintf) |
Definition at line 87 of file debug.c.
References assertcodeptr.
00088 { 00089 if( NULL == debug_vlog ) 00090 { 00091 pdebug_vlog = vprintf; 00092 } 00093 else 00094 { 00095 pdebug_vlog = debug_vlog; 00096 } 00097 assertcodeptr(pdebug_vlog); 00098 }
void debug_vlog | ( | unsigned | mask, | |
const char * | fmt, | |||
va_list | args | |||
) |
Logging function.
mask | Mask to check against allowable log types, or 0 for 'always' | |
fmt | It's a vprintf, so format accordingly | |
args | stdarg type argument pointer for vprintf-like function |
Definition at line 48 of file debug.c.
References assertcodeptr, and assertconst.
Referenced by Socket_LogError(), and SocketsLogLastError().
00049 { 00050 if( (mask & debug_logmask) || 0 == mask ) 00051 { 00052 assertconst(fmt,1); 00053 assertcodeptr(pdebug_vlog); 00054 pdebug_vlog( fmt, args ); 00055 } 00056 }
void debug_vlogalways | ( | const char * | fmt, | |
va_list | args | |||
) |
Logging function that always logs.
fmt | It's a vprintf, so format accordingly | |
args | Arguments from va_start(args,fmt) |
Definition at line 76 of file debug.c.
References assertcodeptr, and assertconst.
Referenced by serial_log().
00077 { 00078 assertconst(fmt,1); 00079 assertcodeptr(pdebug_vlog); 00080 pdebug_vlog( fmt, args ); 00081 }