~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to include/my_dbug.h

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. 
 
2
   Copyright (C) 2000-2011 Monty Program Ab
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
16
 
 
17
#ifndef _my_dbug_h
 
18
#define _my_dbug_h
 
19
 
 
20
#ifndef __WIN__
 
21
#include <signal.h>
 
22
#endif  /* not __WIN__ */
 
23
 
 
24
#ifdef  __cplusplus
 
25
extern "C" {
 
26
#endif
 
27
#if !defined(DBUG_OFF) && !defined(_lint)
 
28
 
 
29
struct _db_stack_frame_ {
 
30
  const char *func;      /* function name of the previous stack frame       */
 
31
  const char *file;      /* filename of the function of previous frame      */
 
32
  uint level;            /* this nesting level, highest bit enables tracing */
 
33
  struct _db_stack_frame_ *prev; /* pointer to the previous frame */
 
34
};
 
35
 
 
36
struct  _db_code_state_;
 
37
extern  my_bool _dbug_on_;
 
38
extern  my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
 
39
extern  int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
 
40
extern  int _db_explain_init_(char *buf, size_t len);
 
41
extern  int _db_is_pushed_(void);
 
42
extern  void _db_setjmp_(void);
 
43
extern  void _db_longjmp_(void);
 
44
extern  void _db_process_(const char *name);
 
45
extern  void _db_push_(const char *control);
 
46
extern  void _db_pop_(void);
 
47
extern  void _db_set_(const char *control);
 
48
extern  void _db_set_init_(const char *control);
 
49
extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
 
50
                       struct _db_stack_frame_ *_stack_frame_);
 
51
extern  void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_);
 
52
extern  void _db_pargs_(uint _line_,const char *keyword);
 
53
extern  void _db_doprnt_(const char *format,...)
 
54
  ATTRIBUTE_FORMAT(printf, 1, 2);
 
55
extern  void _db_dump_(uint _line_,const char *keyword,
 
56
                       const unsigned char *memory, size_t length);
 
57
extern  void _db_end_(void);
 
58
extern  void _db_lock_file_(void);
 
59
extern  void _db_unlock_file_(void);
 
60
extern  FILE *_db_fp_(void);
 
61
extern  void _db_flush_();
 
62
extern void dbug_swap_code_state(void **code_state_store);
 
63
extern void dbug_free_code_state(void **code_state_store);
 
64
extern  const char* _db_get_func_(void);
 
65
 
 
66
#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
 
67
        _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
 
68
#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_)
 
69
 
 
70
#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
 
71
#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
 
72
#define DBUG_EXECUTE(keyword,a1) \
 
73
        do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
 
74
#define DBUG_EXECUTE_IF(keyword,a1) \
 
75
        do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
 
76
#define DBUG_EVALUATE(keyword,a1,a2) \
 
77
        (_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
 
78
#define DBUG_EVALUATE_IF(keyword,a1,a2) \
 
79
        (_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
 
80
#define DBUG_PRINT(keyword,arglist) \
 
81
        do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0)
 
82
#define DBUG_PUSH(a1) _db_push_ (a1)
 
83
#define DBUG_POP() _db_pop_ ()
 
84
#define DBUG_SET(a1) _db_set_ (a1)
 
85
#define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
 
86
#define DBUG_PROCESS(a1) _db_process_(a1)
 
87
#define DBUG_FILE _db_fp_()
 
88
#define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
 
89
#define DBUG_END()  _db_end_ ()
 
90
#define DBUG_LOCK_FILE _db_lock_file_()
 
91
#define DBUG_UNLOCK_FILE _db_unlock_file_()
 
92
#define DBUG_ASSERT(A) do { _db_flush_(); assert(A); } while(0)
 
93
#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
 
94
#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
 
95
#define DEBUGGER_OFF                    do { _dbug_on_= 0; } while(0)
 
96
#define DEBUGGER_ON                     do { _dbug_on_= 1; } while(0)
 
97
#define IF_DBUG(A,B)                    A
 
98
#define DBUG_SWAP_CODE_STATE(arg) dbug_swap_code_state(arg)
 
99
#define DBUG_FREE_CODE_STATE(arg) dbug_free_code_state(arg)
 
100
 
 
101
#ifndef __WIN__
 
102
#define DBUG_ABORT()                    (_db_flush_(), abort())
 
103
#else
 
104
/*
 
105
  Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can
 
106
  call abort() instead of _exit(3) (now it would cause a "test signal" popup).
 
107
*/
 
108
#include <crtdbg.h>
 
109
#define DBUG_ABORT() (_db_flush_(),\
 
110
                     (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\
 
111
                     (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
 
112
                     _exit(3))
 
113
#endif
 
114
 
 
115
/*
 
116
  Make the program fail, without creating a core file.
 
117
  abort() will send SIGABRT which (most likely) generates core.
 
118
  Use SIGKILL instead, which cannot be caught.
 
119
  We also pause the current thread, until the signal is actually delivered.
 
120
  An alternative would be to use _exit(EXIT_FAILURE),
 
121
  but then valgrind would report lots of memory leaks.
 
122
 */
 
123
#ifdef __WIN__
 
124
#define DBUG_SUICIDE() DBUG_ABORT()
 
125
#else
 
126
extern void _db_suicide_();
 
127
#define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
 
128
#endif
 
129
 
 
130
#else                                           /* No debugger */
 
131
 
 
132
#define DBUG_ENTER(a1)
 
133
#define DBUG_VIOLATION_HELPER_LEAVE do { } while(0)
 
134
#define DBUG_LEAVE
 
135
#define DBUG_RETURN(a1)                 do { return(a1); } while(0)
 
136
#define DBUG_VOID_RETURN                do { return; } while(0)
 
137
#define DBUG_EXECUTE(keyword,a1)        do { } while(0)
 
138
#define DBUG_EXECUTE_IF(keyword,a1)     do { } while(0)
 
139
#define DBUG_EVALUATE(keyword,a1,a2) (a2)
 
140
#define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
 
141
#define DBUG_PRINT(keyword,arglist)     do { } while(0)
 
142
#define DBUG_PUSH(a1)                   do { } while(0)
 
143
#define DBUG_SET(a1)                    do { } while(0)
 
144
#define DBUG_SET_INITIAL(a1)            do { } while(0)
 
145
#define DBUG_POP()                      do { } while(0)
 
146
#define DBUG_PROCESS(a1)                do { } while(0)
 
147
#define DBUG_DUMP(keyword,a1,a2)        do { } while(0)
 
148
#define DBUG_END()                      do { } while(0)
 
149
#define DBUG_ASSERT(A)                  do { } while(0)
 
150
#define DBUG_LOCK_FILE                  do { } while(0)
 
151
#define DBUG_FILE (stderr)
 
152
#define DBUG_UNLOCK_FILE                do { } while(0)
 
153
#define DBUG_EXPLAIN(buf,len)
 
154
#define DBUG_EXPLAIN_INITIAL(buf,len)
 
155
#define DEBUGGER_OFF                    do { } while(0)
 
156
#define DEBUGGER_ON                     do { } while(0)
 
157
#define IF_DBUG(A,B)                    B
 
158
#define DBUG_SWAP_CODE_STATE(arg)       do { } while(0)
 
159
#define DBUG_FREE_CODE_STATE(arg)       do { } while(0)
 
160
#define DBUG_ABORT()                    do { } while(0)
 
161
#define DBUG_CRASH_ENTER(func)
 
162
#define DBUG_CRASH_RETURN(val)          do { return(val); } while(0)
 
163
#define DBUG_CRASH_VOID_RETURN          do { return; } while(0)
 
164
#define DBUG_SUICIDE()                  do { } while(0)
 
165
 
 
166
#endif
 
167
 
 
168
#ifdef EXTRA_DEBUG
 
169
/**
 
170
  Sync points allow us to force the server to reach a certain line of code
 
171
  and block there until the client tells the server it is ok to go on.
 
172
  The client tells the server to block with SELECT GET_LOCK()
 
173
  and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
 
174
  concurrency problems
 
175
*/
 
176
#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
 
177
 debug_sync_point(lock_name,lock_timeout)
 
178
void debug_sync_point(const char* lock_name, uint lock_timeout);
 
179
#else
 
180
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
 
181
#endif /* EXTRA_DEBUG */
 
182
 
 
183
#ifdef  __cplusplus
 
184
}
 
185
#endif
 
186
 
 
187
#endif /* _my_dbug_h */