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

Last change on this file since 109 was 109, checked in by rosiere, 15 years ago

1) Configuration : instance configuration file : regroup similar instance
2) Configuration : timing default = 0
3) Debug/Commit_unit : Add watch dog timer
4) Issue_queue : Test parameters : add test if type is optionnal
5) Cor_glue : Fix insert index
6) Free_list : remove bank_by_pop (else deadlock)
7) Update Free List : add register to source event

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