Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

scv_debug.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 
00003 /*
00004  * Author:  Dean Shea
00005  *
00006  * Description:
00007  *
00008  * The public interface for debug messages.
00009  *
00010  * This is scv_debug.h, the header file for the Debug/Tracing facility
00011  * in Test Builder.
00012  *
00013  * To add a new facility, and an enum item to scv_debug::debug_facilities,
00014  * and also add the string name to scv_debug::facility_names[].  Also,
00015  * modify scv_debug::set_level_for_classes() to modify the debug levels for
00016  * appropriate classes when a level is set for the new facility.
00017  *
00018  * Here's a summary of what scv_debug can do:
00019  *
00020  *   A macro called SCV_DEBUG is used to put strings into a trace file and
00021  *   to stdout.  The argument to the macro are: object, level, and a string.
00022  *   object is a pointer to any member of a class derived from scv_object_if.
00023  *
00024  *   A macro called SCV_DEBUG_CHECK is used to check if tracing is turned on.
00025  *
00026  *   Each facility that can be traced has an enum item and a string name.
00027  *   (A facility can also be a developer name, for special cases.)
00028  *
00029  *   Each SCV_DEBUG call specifies a level, where 0 is highest, increasing
00030  *   numbers are lower levels.
00031  *
00032  *   You can set a level for tracing - all traces up to that level number
00033  *   are set.  Exception: 0 means all, and -1 means none.  You can use
00034  *   scv_debug::set_level() to control tracing for all classes in a
00035  *   particular facility, or use <class>::set_debug() to control tracing 
00036  *   for each class separately.
00037  *
00038  *   You can suspend/resume tracing to the log file and to stdout.
00039  *
00040  *
00041  * Here's a summary of how to use scv_debug:
00042  *
00043  *   Open a trace file, usually at the beginning of execution.  If you don't
00044  *   make this call, the default file is: "scv_debug.log"
00045  *
00046  *   Turn on tracing for facilities.  This could be done at any time, but
00047  *   usually at the beginning of execution, while parsing the command line:
00048  *
00049  *   options:
00050  *     scv_debug::set_level("threads");  // Default is level 0 tracing.
00051  *   or:
00052  *     scv_debug::set_level("threads", 2);  // Level 2 tracing.
00053  *
00054  *   Add a trace, for the tb_thread class, at level 0.  First argument is
00055  *   any member of the class.  Third argument is a string:
00056  *
00057  *     SCV_DEBUG(this, 0, "Hello 1"); 
00058  *
00059  *   To check if tracing for a class is turned on:
00060  *
00061  *     if (SCV_DEBUG_CHECK(this, 0)) { 
00062  *       ...
00063  *     }
00064  *
00065  */
00066 
00067 
00068 #ifndef SCV_DEBUG_H
00069 #define SCV_DEBUG_H
00070 
00071 #include "scv/scv_config.h"
00072 
00073 #include <stdio.h>
00074 
00075 #include "scv/scv_object_if.h"
00076 #include "scv/scv_util.h"
00077 
00078 #define _scv_trace(arg) if ((arg)) \
00079 scv_out << "_scv_trace at file " << __FILE__ << " line " << __LINE__ << " "
00080 
00081 
00082 // Comment out the following for builds without tracing capability.
00083 #define SCV_DEBUG_ON
00084 
00085 
00086 #ifdef SCV_DEBUG_ON 
00087 
00088 // Use this macro to add traces to the trace file - arg1 is the string
00089 // that's put into the file.
00090 #define SCV_DEBUG(object_p, level, arg1) \
00091   if ( scv_debug::check((object_p)->get_debug(),(level)) ) \
00092     scv_debug::record_data((__FILE__), (__LINE__), (object_p), (level), (arg1))
00093 
00094 // This macro will check if tracing is turned on for a facility/level.
00095 // If set, then return 1, else return 0.
00096 #define SCV_DEBUG_CHECK(item, level) _scv_debug_check((item),(level))
00097 
00098 #else
00099 // Macros do nothing if SCV_DEBUG_ON is not defined.
00100 #define SCV_DEBUG(object_p, level, arg1)
00101 #define SCV_DEBUG_CHECK(object_p, level) 0
00102 #endif
00103 
00104 
00105 class scv_debug : public scv_object_if {
00106 public:
00107   // Modify this enum to add a new facility; you also need to add a 
00108   // string for the facility name to scv_debug::facility_names[] in 
00109   // scv_debug.cpp.
00110   enum debug_facilities {
00111     ALL = 0,
00112     DATA_STRUCTURES,
00113     INTROSPECTION,
00114     MESSAGES,
00115     RANDOMIZATION,
00116     RECORDING,
00117     SIGNALS,
00118     TRANSACTORS,
00119     LAST    // Add new ones above this
00120   };
00121   static const int INITIAL_DEBUG_LEVEL = -1;
00122   static const int SUSPENDED_DEBUG_LEVEL = -1;
00123 
00124 private:
00125   scv_debug(const char *filename = 0);
00126 
00127 public:
00128   virtual ~scv_debug();
00129 
00130 public:
00131 
00132   // This is called by the SCV_DEBUG_CHECK macro, not by users:
00133   static int check(int actual_level, int target_level);
00134 
00135   // This is called by the SCV_DEBUG macro, not by users:
00136   static void record_data(
00137     const char *filename,
00138     int lineno,
00139     scv_object_if *object_p,
00140     int target_level,
00141     const char *data);
00142 
00143   // Open a new trace file, default is tbvdbg.log.  Also close the old file.
00144   static void open_trace_file(const char *filename);
00145   static void close_trace_file();  // Traces will now only go to stdout.
00146 
00147   // Turns on/off stdout:
00148   static void open_stdout();
00149   static void close_stdout();
00150 
00151   // Set tracing level:
00152   static void set_level(debug_facilities facility, int level = 0);
00153   static void set_level(const char *facility_name, int level = 0);
00154 
00155   // Set tracing level by call from facility
00156   static void set_facility_level(debug_facilities facility, int level = 0);
00157 
00158   // Temporarily suspend/resume tracing:
00159   static void resume(int facility);
00160   static void suspend(int facility);
00161 
00162   static void indent(ostream& os, int indent);
00163 
00164   // implement scv_object_if methods
00165   const char *get_name() const { return kind(); }
00166   const char *kind() const { return _kind; }
00167   void print(ostream& o=scv_out, int details=0, int indent=0) const;
00168   void show(int details=0, int indent=0) const { print(scv_out,details,indent); }
00169   static int get_debug() { return _debug; }
00170   static void set_debug(int);
00171 
00172 private:
00173   static void set_level_for_classes(int, int);
00174 
00175 private:
00176   FILE *file_p;  // Trace log file.
00177   int facility_levels[LAST];
00178   int send_to_stdout;  // Toggle stdout tracing.
00179   static int _debug;
00180   static int local_origination;
00181   static scv_debug *scv_debug_p; // the only instance of scv_debug
00182   static const char* facility_names[];
00183   static const char *_kind;
00184 
00185   void send_to_log(const char *theString);
00186 };
00187 
00188 template<typename T>
00189 bool _scv_debug_check(T *object_p, int target_level)
00190 { return scv_debug::check(object_p->get_debug(),target_level); }
00191 
00192 inline bool _scv_debug_check(int actual_level, int target_level)
00193 { return scv_debug::check(actual_level,target_level); }
00194 
00195 #endif

Generated on Fri Jan 14 08:29:10 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18