changeset 1898:3f87f7ff1092

Fix building with DEBUG_TRACE = 0 Also try a less repetitive way of specifying macros
author Matt Johnston <matt@ucc.asn.au>
date Tue, 22 Mar 2022 23:29:38 +0800
parents fe68c0244b97
children ab9c5467970d
files dbutil.c debug.h
diffstat 2 files changed, 33 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/dbutil.c	Tue Mar 22 23:28:24 2022 +0800
+++ b/dbutil.c	Tue Mar 22 23:29:38 2022 +0800
@@ -187,7 +187,7 @@
 
 static void dropbear_tracelevel(int level, const char *format, va_list param)
 {
-	if (debug_trace==0 || debug_trace < level) {
+	if (debug_trace == 0 || debug_trace < level) {
 		return;
 	}
 
@@ -195,55 +195,48 @@
 	vfprintf(stderr, format, param);
 	fprintf(stderr, "\n");
 }
+#if (DEBUG_TRACE>=1)
 void dropbear_trace1(const char* format, ...) {
 	va_list param;
 
 	va_start(param, format);
-	dropbear_tracelevel(1,format, param);
+	dropbear_tracelevel(1, format, param);
 	va_end(param);
 }
-#if (DEBUG_TRACE>1) 
+#endif
+#if (DEBUG_TRACE>=2)
 void dropbear_trace2(const char* format, ...) {
 	va_list param;
 
 	va_start(param, format);
-	dropbear_tracelevel(2,format,param);
+	dropbear_tracelevel(2, format, param);
 	va_end(param);
 }
 #endif
-#if (DEBUG_TRACE>2) 
+#if (DEBUG_TRACE>=3)
 void dropbear_trace3(const char* format, ...) {
 	va_list param;
 
 	va_start(param, format);
-	dropbear_tracelevel(3,format,param);
+	dropbear_tracelevel(3, format, param);
 	va_end(param);
 }
 #endif
-#if (DEBUG_TRACE>3) 
+#if (DEBUG_TRACE>=4)
 void dropbear_trace4(const char* format, ...) {
 	va_list param;
 
 	va_start(param, format);
-	dropbear_tracelevel(4,format,param);
+	dropbear_tracelevel(4, format, param);
 	va_end(param);
 }
 #endif
-#if (DEBUG_TRACE>4) 
+#if (DEBUG_TRACE>=5)
 void dropbear_trace5(const char* format, ...) {
-	static int trace_env = -1;
 	va_list param;
 
-	if (trace_env == -1) {
-		trace_env = getenv("DROPBEAR_TRACE2") ? 1 : 0;
-	}
-
-        if (!(debug_trace && trace_env)) {
-		return;
-	}
-
 	va_start(param, format);
-	dropbear_tracelevel(5,format,param);
+	dropbear_tracelevel(5, format, param);
 	va_end(param);
 }
 #endif
--- a/debug.h	Tue Mar 22 23:28:24 2022 +0800
+++ b/debug.h	Tue Mar 22 23:29:38 2022 +0800
@@ -53,37 +53,34 @@
 extern int 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;
+/* Enable debug trace levels.
+   We can't use __VA_ARGS_ here because Dropbear supports 
+   old ~C89 compilers */
+/* Default is to discard output ... */
+#define DEBUG1(X)
 #define DEBUG2(X)
 #define DEBUG3(X)
 #define TRACE(X)
 #define TRACE2(X)
-#elif (DEBUG_TRACE==2)
+/* ... unless DEBUG_TRACE is high enough */
+#if (DEBUG_TRACE>=1)
+#undef DEBUG1
 #define DEBUG1(X) dropbear_trace1 X;
+#endif
+#if (DEBUG_TRACE>=2)
+#undef DEBUG2
 #define DEBUG2(X) dropbear_trace2 X;
-#define DEBUG3(X)
-#define TRACE(X)
-#define TRACE2(X)
-#elif (DEBUG_TRACE==3)
-#define DEBUG1(X) dropbear_trace1 X;
-#define DEBUG2(X) dropbear_trace2 X;
+#endif
+#if (DEBUG_TRACE>=3)
+#undef DEBUG3
 #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;
+#endif
+#if (DEBUG_TRACE>=4)
+#undef TRACE
+#define TRACE(X) dropbear_trace4 X;
+#endif
+#if (DEBUG_TRACE>=5)
+#undef TRACE2
 #define TRACE2(X) dropbear_trace5 X;
 #endif