libcsdbg  1.28
C++ exception (and generic) stack trace debug library
config.hpp
Go to the documentation of this file.
1 #ifndef _CSDBG_CONFIG
2 #define _CSDBG_CONFIG 1
3 
10 #include <typeinfo>
11 #include <iostream>
12 
13 #include <cstdarg>
14 #include <cstring>
15 #include <climits>
16 #include <cstdlib>
17 #include <cstdio>
18 #include <cerrno>
19 #include <cctype>
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <pthread.h>
27 #include <unistd.h>
28 #include <cxxabi.h>
29 #include <regex.h>
30 #include <link.h>
31 #include <bfd.h>
32 #include <sys/stat.h>
33 
34 #ifdef CSDBG_WITH_STREAMBUF
35 #include <sys/time.h>
36 #include <sys/file.h>
37 
38 #ifdef CSDBG_WITH_STREAMBUF_TCP
39 #include <sys/socket.h>
40 #include <arpa/inet.h>
41 #endif
42 
43 #ifdef CSDBG_WITH_STREAMBUF_STTY
44 #include <termios.h>
45 #endif
46 #endif
47 
48 #ifdef CSDBG_WITH_HIGHLIGHT
49 #include <fcntl.h>
50 #include <sys/mman.h>
51 #endif
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 
67 namespace csdbg {
68 
72 typedef char i8;
73 
77 typedef short i16;
78 
82 typedef int i32;
83 
87 typedef long long i64;
88 
92 typedef unsigned char u8;
93 
97 typedef unsigned short u16;
98 
102 typedef unsigned int u32;
103 
107 typedef unsigned long long u64;
108 
112 typedef struct stat fileinfo_t;
113 
114 
115 #if defined __x86_64__ || defined __ppc64__
116 
120 typedef unsigned long long mem_addr_t;
121 
122 #else
123 
127 typedef unsigned int mem_addr_t;
128 
129 #endif
130 
131 
132 #ifdef CSDBG_WITH_STREAMBUF_TCP
133 
137 typedef struct sockaddr_in tcp_addr_t;
138 
142 typedef struct sockaddr ip_addr_t;
143 
144 #endif
145 
146 
147 #ifdef CSDBG_WITH_PLUGIN
148 
152 typedef void (* modsym_t)(void*, void*);
153 
154 #endif
155 
156 
157 #ifdef CSDBG_WITH_HIGHLIGHT
158 
162 typedef u8 color_t;
163 
170 typedef u16 attrset_t;
171 
172 #endif
173 
174 
178 static const i8 g_prefix[] = "/usr/local";
179 
185 static const i8 g_libs_env[] = "CSDBG_LIBS";
186 
190 static const u16 g_major = 1;
191 
195 static const u16 g_minor = 28;
196 
202 static const u16 g_memblock_sz = 64;
203 
204 
205 #ifdef CSDBG_WITH_STREAMBUF_TCP
206 
210 static const i32 g_ldp_port = 4242;
211 
212 #endif
213 
214 
215 #ifdef CSDBG_WITH_HIGHLIGHT
216 
222 static const i8 g_trace_syntax[] = "[ \t\n\r\\{\\}\\(\\)\\*&,:<>]+";
223 
224 #endif
225 }
226 
227 
228 #ifdef CSDBG_WITH_DEBUG
229 
233 #define CSDBG_DBGL_ERROR 0x01
234 
238 #define CSDBG_DBGL_WARNING 0x02
239 
243 #define CSDBG_DBGL_INFO 0x04
244 
248 #define CSDBG_DBGL_LOW (CSDBG_DBGL_ERROR)
249 
253 #define CSDBG_DBGL_MEDIUM (CSDBG_DBGL_LOW | CSDBG_DBGL_WARNING)
254 
258 #define CSDBG_DBGL_HIGH (CSDBG_DBGL_MEDIUM | CSDBG_DBGL_INFO)
259 
263 #define CSDBG_DBG_LEVEL CSDBG_DBGL_HIGH
264 
268 #define __D_ASSERT(x) \
269 if (!(x)) { \
270  std::cerr << "assertion '" << #x << "' failed"; \
271  std::cerr << "\r\non line " << std::dec << __LINE__; \
272  std::cerr << "\r\nin file '" << __FILE__ << "'"; \
273  std::cerr << "\r\nin function " << __PRETTY_FUNCTION__; \
274  std::cerr << "\r\n\r\n"; \
275 }
276 
277 #else
278 
279 #define __D_ASSERT(x)
280 
281 #endif
282 
283 
284 #ifdef CSDBG_WITH_COLOR_TERM
285 
289 #define INFO_TAG_FG 61
290 
294 #define WARNING_TAG_FG 60
295 
299 #define ERROR_TAG_FG 9
300 
301 #endif
302 
303 
304 #ifdef CSDBG_WITH_HIGHLIGHT
305 
309 #define HLT_NUMBER_FG 208
310 
314 #define HLT_KEYWORD_FG 61
315 
319 #define HLT_TYPE_FG 105
320 
324 #define HLT_FILE_FG 250
325 
329 #define HLT_SCOPE_FG 250
330 
334 #define HLT_FUNCTION_FG 214
335 
336 #endif
337 
338 
339 #ifdef __GNUC__
340 
344 #define likely(expr) __builtin_expect((expr), true)
345 
349 #define unlikely(expr) __builtin_expect((expr), false)
350 
354 #define precache_r(addr) __builtin_prefetch((addr), 0, 3)
355 
359 #define precache_w(addr) __builtin_prefetch((addr), 1, 3)
360 
361 #else
362 
363 #define likely(expr) (expr)
364 
365 #define unlikely(expr) (expr)
366 
367 #define precache_r(addr)
368 
369 #define precache_w(addr)
370 
371 #endif
372 
373 #endif
374 
long long i64
64-bit signed integer
Definition: config.hpp:87
static const i8 g_trace_syntax[]
C++ stack trace syntax.
Definition: config.hpp:222
char i8
8-bit signed integer
Definition: config.hpp:72
struct stat fileinfo_t
File metadata.
Definition: config.hpp:112
unsigned long long u64
64-bit unsigned integer
Definition: config.hpp:107
static const u16 g_minor
Library version minor.
Definition: config.hpp:195
static const u16 g_memblock_sz
Block size (allocation alignment)
Definition: config.hpp:202
static const i8 g_libs_env[]
DSO filtering shell variable.
Definition: config.hpp:185
u8 color_t
VT100 terminal color.
Definition: config.hpp:162
unsigned short u16
16-bit unsigned integer
Definition: config.hpp:97
unsigned char u8
8-bit unsigned integer
Definition: config.hpp:92
struct sockaddr_in tcp_addr_t
TCP IPv4 address.
Definition: config.hpp:137
static const i8 g_prefix[]
Library installation prefix.
Definition: config.hpp:178
void(* modsym_t)(void *, void *)
Plugin callback.
Definition: config.hpp:152
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
int i32
32-bit signed integer
Definition: config.hpp:82
short i16
16-bit signed integer
Definition: config.hpp:77
u16 attrset_t
VT100 attribute bitmask.
Definition: config.hpp:170
unsigned long long mem_addr_t
64-bit memory address
Definition: config.hpp:120
static const i32 g_ldp_port
LDP service port.
Definition: config.hpp:210
struct sockaddr ip_addr_t
IP address.
Definition: config.hpp:142
static const u16 g_major
Library version major.
Definition: config.hpp:190