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

Last change on this file since 82 was 82, checked in by rosiere, 16 years ago
  • support locale (now must "just" translate)
  • update all component with new test format
  • update all component with usage
  • New component : decod queue and prediction_unit
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#ifndef DEBUG_H
2#define DEBUG_H
3
4/*
5 * $Id: Debug.h 82 2008-05-01 16:48:45Z 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 *  - breakpoint
16 *
17 *  Debug's Level :
18 *  - None    : print elementary information
19 *  - Info    : print basic information
20 *  - Trace   : trace internal variable
21 *  - Func    : trace call and return function
22 *  - All     : print all information
23 */
24
25#include "Common/include/Message.h"
26#include "Behavioural/include/Debug_component.h"
27#include "Behavioural/include/Environment.h"
28#include <stdio.h>
29#include <string.h>
30#include <iostream>
31#include <sstream>
32#include <string>
33
34enum _debug_verbosity
35  {
36    DEBUG_NONE ,
37    DEBUG_INFO ,
38    DEBUG_TRACE,
39    DEBUG_FUNC ,
40    DEBUG_ALL
41  };
42
43std::string debug_tab     (void);
44void        debug_tab_inc (void);
45void        debug_tab_dec (void);
46
47#ifdef DEBUG
48# define log_printf(level, component, func, str... )                    \
49  do                                                                    \
50    {                                                                   \
51      if ((DEBUG == DEBUG_ALL ) or                                      \
52          (DEBUG_ ## level == DEBUG_NONE) or                            \
53          (( DEBUG_ ## level     <= DEBUG) and                          \
54           ( DEBUG_ ## component == true )) )                           \
55        {                                                               \
56          if (DEBUG >= DEBUG_FUNC)                                      \
57            {                                                           \
58              msg(_("%s"),debug_tab().c_str());                         \
59            }                                                           \
60          if (DEBUG >= DEBUG_ALL )                                      \
61            {                                                           \
62              switch (DEBUG_ ## level)                                  \
63                {                                                       \
64                case DEBUG_NONE  : msg(_("(none       ) ")); break;     \
65                case DEBUG_INFO  : msg(_("(information) ")); break;     \
66                case DEBUG_TRACE : msg(_("(trace      ) ")); break;     \
67                case DEBUG_FUNC  : msg(_("(function   ) ")); break;     \
68                case DEBUG_ALL   : msg(_("(all        ) ")); break;     \
69                default          : msg(_("(undefine   ) ")); break;     \
70                }                                                       \
71            }                                                           \
72          if (DEBUG >= DEBUG_FUNC)                                      \
73            {                                                           \
74              msg(_("<%s> "),func);                                     \
75              msg(_("In file %s, "),__FILE__);                          \
76              msg(_("at line %d " ),__LINE__);                          \
77              msg(_(": "));                                             \
78            }                                                           \
79          msg(str);                                                     \
80          msg(_("\n"));                                                 \
81          fflush (stdout);                                              \
82        }                                                               \
83    } while(0)
84
85# define log_begin(component, func)                                     \
86  do                                                                    \
87    {                                                                   \
88      debug_tab_inc ();                                                 \
89      log_printf(FUNC,component,func,"Begin");                          \
90    } while(0)
91
92# define log_end(component, func)                                       \
93  do                                                                    \
94    {                                                                   \
95      log_printf(FUNC,component,func,"End");                            \
96      debug_tab_dec ();                                                 \
97    } while(0)
98
99#else
100# define log_printf(level, component, func, str... )                    \
101  do                                                                    \
102    {                                                                   \
103    } while(0)
104
105# define log_begin(component, func)                                     \
106  do                                                                    \
107    {                                                                   \
108    } while(0)
109
110# define log_end(component, func)                                       \
111  do                                                                    \
112    {                                                                   \
113    } while(0)
114
115#endif // DEBUG
116
117#define breakpoint(str...)                                              \
118  do                                                                    \
119    {                                                                   \
120      msg(_("Breakpoint : file %s, line %d. Enter Any key to continue\n"),__FILE__,__LINE__); \
121      msg(str);                                                         \
122      getchar();                                                        \
123    } while(0)
124
125#ifdef DEBUG_TEST
126#define TEST_PTR(x)                                                     \
127  do                                                                    \
128    {                                                                   \
129      if (x == NULL)                                                    \
130        err(_("%s File %s, Line %d, this pointeur is null"),MSG_ERROR,__FILE__,__LINE__); \
131    }                                                                   \
132  while (0)
133#else
134#define TEST_PTR(x)      \
135  do                     \
136    {                    \
137    }                    \
138  while (0)
139#endif
140
141
142#endif // !DEBUG_H
Note: See TracBrowser for help on using the repository browser.