source: trunk/IPs/systemC/processor/Morpheo/Common/include/Debug.h @ 88

Last change on this file since 88 was 88, checked in by rosiere, 16 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1#ifndef Morpheo_Debug_h
2#define Morpheo_Debug_h
3
4/*
5 * $Id: Debug.h 88 2008-12-10 18:31:39Z rosiere $
6 *
7 * [ Description ]
8 *
9 * function to help the debugging :
10 *
11 *  - debug_tab
12 *  - log_printf
13 *  - log_begin
14 *  - log_end
15 *  - log_function
16 *  - msg_print
17 *  - breakpoint
18 *
19 *  Debug's Level :
20 *  - None    : print elementary information
21 *  - Info    : print basic information
22 *  - Trace   : trace internal variable
23 *  - Func    : trace call and return function
24 *  - All     : print all information
25 */
26
27#include "Common/include/Message.h"
28#include "Behavioural/include/Debug_component.h"
29#include <systemc.h>
30#include <stdio.h>
31#include <string.h>
32#include <iostream>
33#include <sstream>
34#include <string>
35
36namespace morpheo {
37
38enum _debug_verbosity
39  {
40    DEBUG_NONE ,
41    DEBUG_INFO ,
42    DEBUG_TRACE,
43    DEBUG_FUNC ,
44    DEBUG_ALL
45  };
46
47std::string debug_tab     (void);
48void        debug_tab_inc (void);
49void        debug_tab_dec (void);
50
51#ifdef DEBUG
52# define log_printf(level, component, func, str... )                    \
53  do                                                                    \
54    {                                                                   \
55      if ((DEBUG == DEBUG_ALL ) or                                      \
56          (DEBUG_ ## level == DEBUG_NONE) or                            \
57          (( DEBUG_ ## level     <= DEBUG) and                          \
58           ( DEBUG_ ## component == true )) )                           \
59        {                                                               \
60          if (DEBUG_ ## level <= DEBUG_INFO)                            \
61            {                                                           \
62              msg("%s ",MSG_INFORMATION);                               \
63            }                                                           \
64          else                                                          \
65            {                                                           \
66              msg("%s ",MSG_DEBUG);                                     \
67            }                                                           \
68                                                                        \
69          if (DEBUG >= DEBUG_FUNC)                                      \
70            {                                                           \
71              msg("%s",debug_tab().c_str());                            \
72            }                                                           \
73          if (DEBUG >= DEBUG_ALL )                                      \
74            {                                                           \
75              switch (DEBUG_ ## level)                                  \
76                {                                                       \
77                case DEBUG_NONE  : msg(_("(none       ) ")); break;     \
78                case DEBUG_INFO  : msg(_("(information) ")); break;     \
79                case DEBUG_TRACE : msg(_("(trace      ) ")); break;     \
80                case DEBUG_FUNC  : msg(_("(function   ) ")); break;     \
81                case DEBUG_ALL   : msg(_("(all        ) ")); break;     \
82                default          : msg(_("(undefine   ) ")); break;     \
83                }                                                       \
84            }                                                           \
85          if (DEBUG >= DEBUG_FUNC)                                      \
86            {                                                           \
87              msg(  "<%s> " ,func);                                     \
88              msg(_("In file %s, "),__FILE__);                          \
89              msg(_("at line %d " ),__LINE__);                          \
90              msg(  ": " );                                             \
91            }                                                           \
92          msg(str);                                                     \
93          msg("\n");                                                    \
94        }                                                               \
95    } while(0)
96
97# define log_begin(component, func)                                     \
98  do                                                                    \
99    {                                                                   \
100      debug_tab_inc ();                                                 \
101      log_printf(FUNC,component,func,_("Begin"));                       \
102    } while(0)
103
104# define log_end(component, func)                                       \
105  do                                                                    \
106    {                                                                   \
107      log_printf(FUNC,component,func,_("End"));                         \
108      debug_tab_dec ();                                                 \
109    } while(0)
110
111#else
112# define log_printf(level, component, func, str... )                    \
113  do                                                                    \
114    {                                                                   \
115    } while(0)
116
117# define log_begin(component, func)                                     \
118  do                                                                    \
119    {                                                                   \
120    } while(0)
121
122# define log_end(component, func)                                       \
123  do                                                                    \
124    {                                                                   \
125    } while(0)
126
127#endif // DEBUG
128
129# define log_function(component,func,name)                              \
130  do                                                                    \
131    {                                                                   \
132      log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(sc_simulation_time()),name,func); \
133    } while(0)
134
135
136#define msg_printf(type,str...)                                         \
137  do                                                                    \
138    {                                                                   \
139      msg("%s ",MSG_ ## type);                                          \
140      msg(str);                                                         \
141      msg("\n");                                                        \
142    } while(0)
143
144
145#define breakpoint(str...)                                              \
146  do                                                                    \
147    {                                                                   \
148      fprintf(stdout,_("%s "),MSG_BREAKPOINT);                                     \
149      fprintf(stdout,_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__);    \
150      fprintf(stdout,_("%s "),MSG_NONE);                                           \
151      fprintf(stdout,str);                                                              \
152      fprintf(stdout,_("\n"));                                                     \
153      fprintf(stdout,_("%s "),MSG_NONE);                                           \
154      fprintf(stdout,_("Enter any key to continue\n"));                            \
155      getchar();                                                        \
156    } while(0)
157
158#ifdef DEBUG_TEST
159#define TEST_PTR(x)                                                     \
160  do                                                                    \
161    {                                                                   \
162      if (x == NULL)                                                    \
163        err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \
164    }                                                                   \
165  while (0)
166#else
167#define TEST_PTR(x)      \
168  do                     \
169    {                    \
170    }                    \
171  while (0)
172#endif
173
174}; // end namespace morpheo
175#endif // !DEBUG_H
Note: See TracBrowser for help on using the repository browser.