[PATCH] Make debug channel definitions global and unique

Faidon Liambotis paravoid at debian.org
Sun Jul 5 16:30:38 UTC 2009


Currently there were several debug channels colissions (DBG_AND, DBG_CISCO,
DBG_JUNOS) and abuses (DBG_NOT for AFI).

Also, one had to search the whole tree to find the next free debug
channel number.

Fix this by making the allocations in a global header file and
allocating new ones for those that abused other channels.

That should also serve for easily finding a particular number to enter
as a command-line argument.
---
 src/irrutil/debug.hh    |   47 ++++++++++++++++++-----------------------------
 src/normalform/NE.cc    |   36 +++++++++++++++---------------------
 src/rtconfig/f_cisco.cc |    3 +--
 src/rtconfig/f_junos.cc |    3 +--
 4 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/src/irrutil/debug.hh b/src/irrutil/debug.hh
index 9a56942..5ceb4d8 100644
--- a/src/irrutil/debug.hh
+++ b/src/irrutil/debug.hh
@@ -77,8 +77,23 @@
 #ifdef ENABLE_DEBUG
 #include <iostream>
 
-#define DBG_ERR             1
-#define DBG_INFO            2 
+/* explicit numbering since this is a user interface */
+enum dbgchannels {
+	DBG_ERR			= 1,
+	DBG_INFO		= 2,
+
+	/* Normal Expressions */
+	DBG_NE_REDUCE		= 3,
+	DBG_NE_REDUCE_DETAIL	= 4,
+	DBG_NE_OR		= 5,
+	DBG_NE_NOT		= 6,
+	DBG_NE_AND		= 7,
+	DBG_NE_AFI		= 8,
+
+	/* rtconfig */
+	DBG_RTC_CISCO		= 9,
+	DBG_RTC_JUNOS		= 10,
+};
 
 void Abort();
 void copy_constructor(const char *p);
@@ -104,39 +119,13 @@ private:
 
 extern dbgstream dbg;
 
-//----------------------------------------------------------------------
-// ASSERT
-//      If condition is false,  print a message and dump core.
-//	Useful for documenting assumptions in the code.
-//
-//	NOTE: needs to be a #define, to be able to print the location 
-//	where the error occurred.
-//----------------------------------------------------------------------
-/*
-#ifndef ASSERT
-#define ASSERT(condition)                                                     \
-    if (!(condition)) {                                                       \
-        cerr << __FILE__ << ":" << __LINE__                                   \
-	     << ": Assertion failed `" << #condition << "'\n";                \
-        Abort();                                                              \
-    }
-#endif // ASSERT
-*/
-
 #define Debug(whatever) whatever
 #define Channel(no) if (dbg.enabledp(no)) cerr
-#define PRINT(var) cout << #var << " = " << var << endl;
-
-
-
 
 #else /* ENABLE_DEBUG */
+
 #define copy_constructor(p) 
-#ifndef ASSERT
-#define ASSERT(condition) /* do nothing */
-#endif // ASSERT
 #define Debug(whatever)   /* do nothing */
-#define PRINT(var)        /* do nothing */
 
 #endif /* ENABLE_DEBUG */
 
diff --git a/src/normalform/NE.cc b/src/normalform/NE.cc
index 50be031..d4911e5 100644
--- a/src/normalform/NE.cc
+++ b/src/normalform/NE.cc
@@ -64,12 +64,6 @@
 
 using namespace std;
 
-#define DBG_REDUCE 3
-#define DBG_REDUCE_DETAIL 4
-#define DBG_OR 5
-#define DBG_NOT 6
-#define DBG_AND 7
-
 CLASS_DEBUG_MEMORY_CC(NormalExpression);
 
 NormalExpression::NormalExpression(NormalExpression& a) {
@@ -147,10 +141,10 @@ NormalExpression *NormalExpression::evaluate(const Filter *ptree,
 	 return ne;
 
       ne2 = evaluate(((FilterOR *) ptree)->f2, peerAS, expand);
-      Debug(Channel(DBG_OR) << "op1: " << *ne << "\n");
-      Debug(Channel(DBG_OR) << "op2: " << *ne2 << "\n");
+      Debug(Channel(DBG_NE_OR) << "op1: " << *ne << "\n");
+      Debug(Channel(DBG_NE_OR) << "op2: " << *ne2 << "\n");
       ne->do_or(*ne2);
-      Debug(Channel(DBG_OR) << "or:  " << *ne << "\n");
+      Debug(Channel(DBG_NE_OR) << "or:  " << *ne << "\n");
       delete ne2;
 
       return ne;
@@ -162,10 +156,10 @@ NormalExpression *NormalExpression::evaluate(const Filter *ptree,
 	 return ne;
 
       ne2 = evaluate(((FilterAND *) ptree)->f2, peerAS, expand);
-      Debug(Channel(DBG_AND) << "op1: " << *ne << "\n");
-      Debug(Channel(DBG_AND) << "op2: " << *ne2 << "\n");
+      Debug(Channel(DBG_NE_AND) << "op1: " << *ne << "\n");
+      Debug(Channel(DBG_NE_AND) << "op2: " << *ne2 << "\n");
       ne->do_and(*ne2);
-      Debug(Channel(DBG_AND) << "and: " << *ne << "\n");
+      Debug(Channel(DBG_NE_AND) << "and: " << *ne << "\n");
       delete ne2;
 
       return ne;
@@ -173,19 +167,19 @@ NormalExpression *NormalExpression::evaluate(const Filter *ptree,
 
    if (typeid(*ptree) == typeid(FilterNOT)) {
       ne = evaluate(((FilterNOT *) ptree)->f1, peerAS, expand);
-      Debug(Channel(DBG_NOT) << "op1: " << *ne << "\n");
+      Debug(Channel(DBG_NE_NOT) << "op1: " << *ne << "\n");
       ne->do_not();
-      Debug(Channel(DBG_NOT) << "not: " << *ne << "\n");
+      Debug(Channel(DBG_NE_NOT) << "not: " << *ne << "\n");
       return ne;
    }
 
    if (typeid(*ptree) == typeid(FilterMS)) {
       ne = evaluate(((FilterMS *) ptree)->f1, peerAS, expand);
-      Debug(Channel(DBG_NOT) << "op1: " << *ne << "\n");
+      Debug(Channel(DBG_NE_NOT) << "op1: " << *ne << "\n");
       ne->makeMoreSpecific(((FilterMS *) ptree)->code,
 			   ((FilterMS *) ptree)->n,
 			   ((FilterMS *) ptree)->m);
-      Debug(Channel(DBG_NOT) << "ms: " << *ne << "\n");
+      Debug(Channel(DBG_NE_NOT) << "ms: " << *ne << "\n");
       return ne;
    }
 
@@ -355,7 +349,7 @@ NormalExpression *NormalExpression::evaluate(const Filter *ptree,
    if (typeid(*ptree) == typeid(FilterAFI)) {
    
       ne = evaluate(((FilterAFI *) ptree)->f, peerAS, expand);
-      Debug(Channel(DBG_NOT) << "op1: " << *ne << "\n");
+      Debug(Channel(DBG_NE_AFI) << "op1: " << *ne << "\n");
 
       if (ne->is_any() == NEITHER &&
           ((ne->singleton_flag == NormalTerm::PRFX) || (ne->singleton_flag == NormalTerm::IPV6_PRFX) ||
@@ -363,7 +357,7 @@ NormalExpression *NormalExpression::evaluate(const Filter *ptree,
         ne->restrict((FilterAFI *) ptree);
       }
 
-      Debug(Channel(DBG_NOT) << "afi: " << *ne << "\n");
+      Debug(Channel(DBG_NE_AFI) << "afi: " << *ne << "\n");
       return ne;
 
    }
@@ -435,7 +429,7 @@ void NormalExpression::reduce() {
 	    nextpixj = pixj;
 	    terms.next(nextpixj);
 
-	    Debug(Channel(DBG_REDUCE_DETAIL) << *this << "\n");
+	    Debug(Channel(DBG_NE_REDUCE_DETAIL) << *this << "\n");
 	    
 	    j = term->find_diff(*otherterm); // returns -1 if more than 1 diff
 	    if (j >= 0) { 
@@ -460,7 +454,7 @@ void NormalExpression::reduce() {
 	       }
 	    }
 	 }
-	 Debug(Channel(DBG_REDUCE) << *this << "\n");
+	 Debug(Channel(DBG_NE_REDUCE) << *this << "\n");
       }
    }
 }
@@ -653,7 +647,7 @@ void NormalExpression::do_not() {
 	 }
       }
 
-      Debug(Channel(DBG_NOT) << tmpexp << "\n"); 
+      Debug(Channel(DBG_NE_NOT) << tmpexp << "\n"); 
       result.do_and(tmpexp);
       tmpexp.terms.clear(); // this also free's elements' memory
    }
diff --git a/src/rtconfig/f_cisco.cc b/src/rtconfig/f_cisco.cc
index 6ea9c3f..bb3864e 100644
--- a/src/rtconfig/f_cisco.cc
+++ b/src/rtconfig/f_cisco.cc
@@ -64,7 +64,6 @@
 
 using namespace std;
 
-#define DBG_CISCO 7
 #define EXPORT 0
 #define IMPORT 1
 
@@ -952,7 +951,7 @@ int CiscoConfig::print(NormalExpression *ne,
    int last = 0;
    static ListOf2Ints empty_list(1);
 
-   Debug(Channel(DBG_CISCO) << "# ne: " << *ne << "\n");
+   Debug(Channel(DBG_RTC_CISCO) << "# ne: " << *ne << "\n");
    
    // modified by katie at ripe.net to handle any/not any expr
    // for prefix filters, cisco only
diff --git a/src/rtconfig/f_junos.cc b/src/rtconfig/f_junos.cc
index 77409b1..83fb40e 100644
--- a/src/rtconfig/f_junos.cc
+++ b/src/rtconfig/f_junos.cc
@@ -68,7 +68,6 @@
 
 using namespace std;
 
-#define DBG_JUNOS 7
 #define EXPORT 0
 #define IMPORT 1
 #define STATIC 2
@@ -755,7 +754,7 @@ int JunosConfig::print(NormalExpression *ne, PolicyActionList *actn,
    int last = 0;
    static ListOf2Ints empty_list(1);
 
-   Debug(Channel(DBG_JUNOS) << "# ne: " << *ne << "\n");
+   Debug(Channel(DBG_RTC_JUNOS) << "# ne: " << *ne << "\n");
 
    if (ne->is_any() != NEITHER)
       cerr << "Warning: filter matches ANY/NOT ANY" << endl;
-- 
1.5.6.5




More information about the irrtoolset mailing list