Merge in ability for memcapable to handle ascii/binary as flags to the
[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 #ifdef TARGET_OS_LINUX
19 static inline void libmemcached_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 #elif defined(__sun)
39 #include <ucontext.h>
40
41 static inline void libmemcached_stack_dump(void)
42 {
43 fflush(stderr);
44 printstack(fileno(stderr));
45 }
46
47 #else
48
49 static inline void libmemcached_stack_dump(void)
50 { }
51
52 #endif // libmemcached_stack_dump()
53
54 #include <assert.h>
55
56 #define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0)
57 #define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0)
58 #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)
59 #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0)
60 #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)
61 #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %lu\n", __FILE__, __LINE__,__func__,(unsigned long)(A));fflush(stdout); } while (0)
62 #define WATCHPOINT_LABELED_NUMBER(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(A),(unsigned long)(B));fflush(stdout); } while (0)
63 #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C) do { if(A) {fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(B),(unsigned long)(C));fflush(stdout);} } while (0)
64 #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0)
65 #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); libmemcached_stack_dump(); } assert((A)); } while (0)
66 #define WATCHPOINT_ASSERT(A) do { if (! (A)) {libmemcached_stack_dump();} assert((A)); } while (0)
67 #define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { libmemcached_stack_dump(); } assert(memcached_is_initialized((A))); } while (0);
68 #define WATCHPOINT_SET(A) do { A; } while(0);
69
70 #else
71
72 #define WATCHPOINT
73 #define WATCHPOINT_ERROR(A)
74 #define WATCHPOINT_IFERROR(A)
75 #define WATCHPOINT_STRING(A)
76 #define WATCHPOINT_NUMBER(A)
77 #define WATCHPOINT_LABELED_NUMBER(A,B)
78 #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C)
79 #define WATCHPOINT_ERRNO(A)
80 #define WATCHPOINT_ASSERT_PRINT(A,B,C)
81 #define WATCHPOINT_ASSERT(A)
82 #define WATCHPOINT_ASSERT_INITIALIZED(A)
83 #define WATCHPOINT_SET(A)
84
85 #endif /* DEBUG */
86
87 #endif /* __LIBMEMCACHED_WATCHPOINT_H__ */