DEBUGMSG

From Net-SNMP Wiki
Revision as of 14:50, 22 June 2010 by Wes (Talk | contribs) (DEBUG)

Jump to: navigation, search

If you want to add Debugging output statements to your own code, you can use the following conventions:

DEBUGMSGTL

DEBUGMSGTL(("token", "statement of some kind: %s\n", "with printf arguments"));

This actually outputs two lines:

  • A "trace" line showing where in the source it came from (that's what the T stands for)
  • Your debugging line (when -Dtoken is turned on)

This should be the most common debugging statement used. It should be used for complete debugging lines.

DEBUGMSG

For creating lines a piece at a time, start with DEBUGMSGTL followed by DEBUGMSG macros until you hit the newline ("\n"). This is a stupid example but shows how it works:

 int total = 0;
 DEBUGMSGTL(("token", "Calculating running total: "));
 for(int i = 0; i < 5; i++) {
    total = total + i;
    DEBUGMSG(("token", " %d", total));
 }
 DEBUGMSG(("token", "\n"));

DEBUGMSGOID

For printing OIDs you can use the DEBUGOID macro:

 oid my_oid[] = { 1, 3, 6, 1}
 size_t my_oid_len = 4;
 
 DEBUGMSGTL(("token", "this is my oid: "));
 DEBUGMSGOID(("token", my_oid, my_oid_len));
 DEBUGMSG(("token", "\n"));