Mercurial > dropbear
changeset 1893:180e580778df
Added DEBUG1,DEBUG2,DEBUG3 to separate functions while keeping TRACE and TRACE2.
author | HansH111 <hans@atbas.org> |
---|---|
date | Sat, 19 Mar 2022 09:01:05 +0000 |
parents | 3442105b2aba |
children | 62e4baa059c3 |
files | dbutil.c dbutil.h debug.h |
diffstat | 3 files changed, 82 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/dbutil.c Sat Mar 19 08:55:31 2022 +0000 +++ b/dbutil.c Sat Mar 19 09:01:05 2022 +0000 @@ -155,7 +155,7 @@ } -#if DEBUG_TRACE +#if DEBUG_TRACE static double debug_start_time = -1; @@ -185,21 +185,52 @@ return nowf - debug_start_time; } -void dropbear_trace(const char* format, ...) { - va_list param; - - if (!debug_trace) { +static void dropbear_tracelevel(int level, const char *format, va_list param) +{ + if (debug_trace==0 || debug_trace < level) { return; } - va_start(param, format); - fprintf(stderr, "TRACE (%d) %f: ", getpid(), time_since_start()); + fprintf(stderr, "TRACE%d (%d) %f: ", level, getpid(), time_since_start()); vfprintf(stderr, format, param); fprintf(stderr, "\n"); +} +void dropbear_trace1(const char* format, ...) { + va_list param; + + va_start(param, format); + dropbear_tracelevel(1,format, param); + va_end(param); +} +#if (DEBUG_TRACE>1) +void dropbear_trace2(const char* format, ...) { + va_list param; + + va_start(param, format); + dropbear_tracelevel(2,format,param); va_end(param); } +#endif +#if (DEBUG_TRACE>2) +void dropbear_trace3(const char* format, ...) { + va_list param; -void dropbear_trace2(const char* format, ...) { + va_start(param, format); + dropbear_tracelevel(3,format,param); + va_end(param); +} +#endif +#if (DEBUG_TRACE>3) +void dropbear_trace4(const char* format, ...) { + va_list param; + + va_start(param, format); + dropbear_tracelevel(4,format,param); + va_end(param); +} +#endif +#if (DEBUG_TRACE>4) +void dropbear_trace5(const char* format, ...) { static int trace_env = -1; va_list param; @@ -207,17 +238,17 @@ trace_env = getenv("DROPBEAR_TRACE2") ? 1 : 0; } - if (!(debug_trace && trace_env)) { + if (!(debug_trace && trace_env)) { return; } va_start(param, format); - fprintf(stderr, "TRACE2 (%d) %f: ", getpid(), time_since_start()); - vfprintf(stderr, format, param); - fprintf(stderr, "\n"); + dropbear_tracelevel(5,format,param); va_end(param); } -#endif /* DEBUG_TRACE */ +#endif +#endif + /* Connect to a given unix socket. The socket is blocking */ #if ENABLE_CONNECT_UNIX
--- a/dbutil.h Sat Mar 19 08:55:31 2022 +0000 +++ b/dbutil.h Sat Mar 19 09:01:05 2022 +0000 @@ -47,8 +47,11 @@ void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN; #if DEBUG_TRACE -void dropbear_trace(const char* format, ...) ATTRIB_PRINTF(1,2); +void dropbear_trace1(const char* format, ...) ATTRIB_PRINTF(1,2); void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2); +void dropbear_trace3(const char* format, ...) ATTRIB_PRINTF(1,2); +void dropbear_trace4(const char* format, ...) ATTRIB_PRINTF(1,2); +void dropbear_trace5(const char* format, ...) ATTRIB_PRINTF(1,2); void printhex(const char * label, const unsigned char * buf, int len); void printmpint(const char *label, mp_int *mp); void debug_start_net(void);
--- a/debug.h Sat Mar 19 08:55:31 2022 +0000 +++ b/debug.h Sat Mar 19 09:01:05 2022 +0000 @@ -48,15 +48,44 @@ /*#define DEBUG_KEXHASH*/ /*#define DEBUG_RSA*/ -/* you don't need to touch this block */ + #if DEBUG_TRACE extern int debug_trace; -#define TRACE(X) dropbear_trace X; -#define TRACE2(X) dropbear_trace2 X; -#else /*DEBUG_TRACE*/ +#endif + +/* you don't need to touch this block */ +/* enable debug trace levels */ +#if (DEBUG_TRACE==1) +#define DEBUG1(X) dropbear_trace1 X; +#define DEBUG2(X) +#define DEBUG3(X) +#define TRACE(X) +#define TRACE2(X) +#elif (DEBUG_TRACE==2) +#define DEBUG1(X) dropbear_trace1 X; +#define DEBUG2(X) dropbear_trace2 X; +#define DEBUG3(X) #define TRACE(X) #define TRACE2(X) -#endif /*DEBUG_TRACE*/ +#elif (DEBUG_TRACE==3) +#define DEBUG1(X) dropbear_trace1 X; +#define DEBUG2(X) dropbear_trace2 X; +#define DEBUG3(X) dropbear_trace3 X; +#define TRACE(X) +#define TRACE2(X) +#elif (DEBUG_TRACE==4) +#define DEBUG1(X) dropbear_trace1 X; +#define DEBUG2(X) dropbear_trace2 X; +#define DEBUG3(X) dropbear_trace3 X; +#define TRACE(X) dropbear_trace4 X; +#define TRACE2(X) +#elif (DEBUG_TRACE==5) +#define DEBUG1(X) dropbear_trace1 X; +#define DEBUG2(X) dropbear_trace2 X; +#define DEBUG3(X) dropbear_trace3 X; +#define TRACE(X) dropbear_trace4 X; +#define TRACE2(X) dropbear_trace5 X; +#endif /* To debug with GDB it is easier to run with no forking of child processes. You will need to pass "-F" as well. */