// /*-------------------------------------------------------------------*\ // | Debugging Macros // |*-------------------------------------------------------------------*| // | Description: // | // | The following macros are aids that support client program // | debugging (printing values, tracing, conditionally stopping, // | etc.). They use the same framework as the "assert" macro in // | macros.h for asserting their location and prompting for // | continuation/exit after a break. // \*-------------------------------------------------------------------*/ #ifndef DEBUGGING_MACROS_H #define DEBUGGING_MACROS_H 1 // Note that by compiling with -DNDEBUG, all of these turn // into no-ops (or something equivalent). // // Description: // // The macros described here form the "real" user-level // operations for client program debugging. They are as follows: // // trace; // This is the simplest debugging macro. Place it anywhere // in your source code. When executed, it simply prints out // the file name and line number (plus the current function // name under g++). Sprinkle calls liberally around // operations where bugs are known to exist but need to be // located. // // debug(msg); // Similar to "trace", but also prints out the contents of a // user-specified "msg". Often, the "msg" is simply a // string. Because of the way this macro is written, // however, the "msg" parameter can be any object that can be // "put to" a Character_OStream using operator <<, even an // expression composed of a series of <<'s separated by // objects or by text values: // // debug ("My loop counter is: " << i << ", and x = " << x); // // breakpoint(msg); // Just like "debug(msg)", except that it also halts // execution, and prompts the user on whether to continue or // exit. // // cond_debug(cond, msg); // A conditional version of "debug". If "cond" is true, it // acts just like "debug(msg)"; otherwise, it does nothing. // // cond_breakpoint(cond, msg); // A conditional version of "breakpoint". If "cond" is true, // it acts just like "breakpoint(msg)"; otherwise, it does // nothing. // //------------------------------------------------------------------------- // Declarations of support operations extern void RCPP_Ask_To_Continue_Y (); extern void RCPP_Report_Location ( const char* file_name, int line_number, const char* function_name ); extern void Wait_For_Response (); //------------------------------------------------------------------------- // Declarations of compiler dependent stuff #ifndef __GNUG__ #define __FUNCTION__ "unknown" #endif //------------------------------------------------------------------------- // Declarations of macros #ifndef NDEBUG #define debug(msg) \ { \ RCPP_Report_Location (__FILE__, __LINE__, __FUNCTION__); \ serr << msg; serr << "\n"; \ } #define breakpoint(msg) \ { \ RCPP_Report_Location (__FILE__, __LINE__, __FUNCTION__); \ serr << msg; serr << "\n"; \ RCPP_Ask_To_Continue_Y (); \ } #define cond_debug(cond,msg) \ if (cond) \ { \ RCPP_Report_Location (__FILE__, __LINE__, __FUNCTION__); \ serr << msg; serr << "\n"; \ } #define cond_breakpoint(cond,msg) \ if (cond) \ { \ RCPP_Report_Location (__FILE__, __LINE__, __FUNCTION__); \ serr << msg; serr << "\n"; \ RCPP_Ask_To_Continue_Y (); \ } #define trace \ { \ RCPP_Report_Location (__FILE__, __LINE__, __FUNCTION__); \ serr << "\n"; \ } #else #define debug(msg) #define breakpoint(msg) #define cond_debug(cond,msg) #define cond_breakpoint(cond,msg) #define trace #endif //------------------------------------------------------------------------- #endif // DEBUGGING_MACROS_H