Fixing bogus assert in debug build.
[awesomized/libmemcached] / libmemcached / watchpoint.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: Localized copy of WATCHPOINT debug symbols
9 *
10 */
11
12 #ifndef __LIBMEMCACHED_WATCHPOINT_H__
13 #define __LIBMEMCACHED_WATCHPOINT_H__
14
15 /* Some personal debugging functions */
16 #if defined(DEBUG)
17
18 #if TARGET_OS_LINUX
19 static inline void __stack_dump(void)
20 {
21 void *array[10];
22 int size;
23 char **strings;
24
25 size= backtrace(array, 10);
26 strings= backtrace_symbols(array, size);
27
28 fprintf(stderr, "Found %d stack frames.\n", size);
29
30 for (int x= 0; x < size; x++)
31 fprintf(stderr, "%s\n", strings[x]);
32
33 free (strings);
34
35 fflush(stderr);
36 }
37
38 #else
39
40 static inline void __stack_dump(void)
41 { }
42
43 #endif // __stack_dump()
44
45 #include <assert.h>
46
47 #define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0)
48 #define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0)
49 #define WATCHPOINT_IFERROR(A) do { if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0)
50 #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0)
51 #define WATCHPOINT_STRING_LENGTH(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); } while (0)
52 #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); } while (0)
53 #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0)
54 #define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout); __stack_dump(); } assert((A)); } while (0)
55 #define WATCHPOINT_ASSERT(A) do { if (! (A)) {__stack_dump();} assert((A)); } while (0)
56 #define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { __stack_dump(); } assert(memcached_is_initialized((A))); } while (0);
57 #define WATCHPOINT_SET(A) do { A; } while(0);
58
59 #else
60
61 #define WATCHPOINT
62 #define WATCHPOINT_ERROR(A)
63 #define WATCHPOINT_IFERROR(A)
64 #define WATCHPOINT_STRING(A)
65 #define WATCHPOINT_NUMBER(A)
66 #define WATCHPOINT_ERRNO(A)
67 #define WATCHPOINT_ASSERT_PRINT(A,B,C)
68 #define WATCHPOINT_ASSERT(A)
69 #define WATCHPOINT_ASSERT_INITIALIZED(A)
70 #define WATCHPOINT_SET(A)
71
72 #endif /* DEBUG */
73
74 #endif /* __LIBMEMCACHED_WATCHPOINT_H__ */