openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
eerror.h
Go to the documentation of this file.
1 #ifndef __E_ERROR__
2 #define __E_ERROR__
3 
4 #include <string>
5 #include <map>
6 #include <new>
7 #include <libsig_comp.h>
8 
9 // to use memleak check change the following in configure.ac
10 // * add -DMEMLEAK_CHECK and -rdynamic to CPP_FLAGS
11 
12 #ifdef MEMLEAK_CHECK
13 #define BACKTRACE_DEPTH 5
14 #include <map>
15 #include <lib/base/elock.h>
16 #include <execinfo.h>
17 #include <string>
18 #include <new>
19 #include <cxxabi.h>
20 typedef struct
21 {
22  unsigned int address;
23  unsigned int size;
24  const char *file;
25  void *backtrace[BACKTRACE_DEPTH];
26  unsigned char btcount;
27  unsigned short line;
28  unsigned char type;
29 } ALLOC_INFO;
30 
31 typedef std::map<unsigned int, ALLOC_INFO> AllocList;
32 
33 extern AllocList *allocList;
34 extern pthread_mutex_t memLock;
35 
36 static inline void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum, unsigned int type)
37 {
38  ALLOC_INFO info;
39 
40  if(!allocList)
41  allocList = new(AllocList);
42 
43  info.address = addr;
44  info.file = fname;
45  info.line = lnum;
46  info.size = asize;
47  info.type = type;
48  info.btcount = 0; //backtrace( info.backtrace, BACKTRACE_DEPTH );
49  singleLock s(memLock);
50  (*allocList)[addr]=info;
51 };
52 
53 static inline void RemoveTrack(unsigned int addr, unsigned int type)
54 {
55  if(!allocList)
56  return;
57  AllocList::iterator i;
58  singleLock s(memLock);
59  i = allocList->find(addr);
60  if ( i != allocList->end() )
61  {
62  if ( i->second.type != type )
63  i->second.type=3;
64  else
65  allocList->erase(i);
66  }
67 };
68 
69 inline void * operator new(size_t size, const char *file, int line)
70 {
71  void *ptr = (void *)malloc(size);
72  AddTrack((unsigned int)ptr, size, file, line, 1);
73  return(ptr);
74 };
75 
76 inline void operator delete(void *p)
77 {
78  RemoveTrack((unsigned int)p,1);
79  free(p);
80 };
81 
82 inline void * operator new[](size_t size, const char *file, int line)
83 {
84  void *ptr = (void *)malloc(size);
85  AddTrack((unsigned int)ptr, size, file, line, 2);
86  return(ptr);
87 };
88 
89 inline void operator delete[](void *p)
90 {
91  RemoveTrack((unsigned int)p, 2);
92  free(p);
93 };
94 
95 void DumpUnfreed();
96 #define new new(__FILE__, __LINE__)
97 
98 #endif // MEMLEAK_CHECK
99 
100 #ifndef NULL
101 #define NULL 0
102 #endif
103 
104 #ifdef ASSERT
105 #undef ASSERT
106 #endif
107 
108 #ifndef SWIG
109 
110 #define CHECKFORMAT __attribute__ ((__format__(__printf__, 2, 3)))
111 
112 /*
113  * Current loglevel
114  * Maybe set by ENIGMA_DEBUG_LVL environment variable.
115  * main() will check the environemnt to set the values.
116  */
117 extern int debugLvl;
118 
119 void CHECKFORMAT eDebugImpl(int flags, const char*, ...);
121 
122 #define DEFAULT_DEBUG_LVL 4
123 
124 #ifndef DEBUG
125 # define MAX_DEBUG_LEVEL 0
126 #else
127 # ifndef MAX_DEBUG_LEVEL
128 # define MAX_DEBUG_LEVEL 5
129 # endif
130 #endif
131 
132 /* When lvl is above MAX_DEBUG_LEVEL, the compiler will optimize the whole debug
133  * statement away. If level is not active, nothing inside the debug call will be
134  * evaluated. This enables compile-time check of parameters and code. */
135 #define eDebugLow(lvl, flags, ...) \
136  do { \
137  if (((lvl) <= MAX_DEBUG_LEVEL) && ((lvl) <= debugLvl)) \
138  eDebugImpl((flags), __VA_ARGS__); \
139  } while (0)
140 
141 #define _DBGFLG_NONEWLINE 1
142 #define _DBGFLG_NOTIME 2
143 #define _DBGFLG_FATAL 4
144 #define eFatal(...) eDebugLow(lvlFatal, _DBGFLG_FATAL, __VA_ARGS__)
145 #define eLog(lvl, ...) eDebugLow(lvl, 0, ##__VA_ARGS__)
146 #define eLogNoNewLineStart(lvl, ...) eDebugLow(lvl, _DBGFLG_NONEWLINE, ##__VA_ARGS__)
147 #define eLogNoNewLine(lvl, ...) eDebugLow(lvl, _DBGFLG_NOTIME | _DBGFLG_NONEWLINE, ##__VA_ARGS__)
148 #define eWarning(...) eDebugLow(lvlWarning, 0, __VA_ARGS__)
149 #define eDebug(...) eDebugLow(lvlDebug, 0, __VA_ARGS__)
150 #define eDebugNoNewLineStart(...) eDebugLow(lvlDebug, _DBGFLG_NONEWLINE, __VA_ARGS__)
151 #define eDebugNoNewLine(...) eDebugLow(lvlDebug, _DBGFLG_NOTIME | _DBGFLG_NONEWLINE, __VA_ARGS__)
152 #define eTrace(...) eDebugLow(lvlTrace, 0, ##__VA_ARGS__)
153 #define eTraceNoNewLineStart(...) eDebugLow(lvlTrace, _DBGFLG_NONEWLINE, ##__VA_ARGS__)
154 #define eTraceNoNewLine(...) eDebugLow(lvlTrace, _DBGFLG_NOTIME | _DBGFLG_NONEWLINE, ##__VA_ARGS__)
155 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
156 
157 #endif // SWIG
158 
159 void ePythonOutput(const char *, int lvl = lvlDebug);
160 int eGetEnigmaDebugLvl();
161 
162 #endif // __E_ERROR__
static int ptr
Definition: bcm.cpp:17
Definition: elock.h:7
void ePythonOutput(const char *, int lvl=lvlDebug)
Definition: eerror.cpp:215
#define CHECKFORMAT
Definition: eerror.h:110
int eGetEnigmaDebugLvl()
Definition: eerror.cpp:223
void CHECKFORMAT eDebugImpl(int flags, const char *,...)
Definition: eerror.cpp:167
@ lvlInfo
Definition: eerror.h:120
@ lvlDebug
Definition: eerror.h:120
@ lvlTrace
Definition: eerror.h:120
@ lvlError
Definition: eerror.h:120
@ lvlFatal
Definition: eerror.h:120
@ lvlWarning
Definition: eerror.h:120
int debugLvl
Definition: eerror.cpp:79
unsigned char address
Definition: hdmi_cec.h:0
size
Definition: Plugins/SystemPlugins/PositionerSetup/log.py:16
line
Definition: newplugin.py:87
file
Definition: newplugin.py:100
dictionary info
Definition: GetEcmInfo.py:9
p
Definition: upgrade.py:63