drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
plugin/debug/module.cc
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
*
4
* Copyright (C) 2010 Brian Aker
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are
9
* met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
*
14
* * Redistributions in binary form must reproduce the above
15
* copyright notice, this list of conditions and the following disclaimer
16
* in the documentation and/or other materials provided with the
17
* distribution.
18
*
19
* * The names of its contributors may not be used to endorse or
20
* promote products derived from this software without specific prior
21
* written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*
35
*/
36
37
#include <config.h>
38
39
#include <signal.h>
40
41
#include <drizzled/function/func.h>
42
#include <drizzled/item/cmpfunc.h>
43
#include <drizzled/item/function/boolean.h>
44
#include <drizzled/plugin/function.h>
45
#include <drizzled/util/backtrace.h>
46
47
using namespace
drizzled
;
48
49
namespace
debug {
50
51
class
Assert :
public
item::function::Boolean
52
{
53
public
:
54
Assert() :
55
item::function::Boolean
()
56
{
57
unsigned_flag=
true
;
58
}
59
60
const
char
*func_name()
const
{
return
"assert_and_crash"
; }
61
const
char
*fully_qualified_func_name()
const
{
return
"assert_and_crash()"
; }
62
63
bool
val_bool
()
64
{
65
String
_res;
66
String
*res= args[0]->val_str(&_res);
67
68
null_value
=
false
;
69
70
if
(not res or not res->length())
71
{
72
assert(0);
73
return
true
;
74
}
75
76
return
false
;
77
}
78
79
int64_t
val_int
()
80
{
81
return
val_bool
();
82
}
83
84
bool
check_argument_count
(
int
n)
85
{
86
return
(n == 1);
87
}
88
};
89
90
class
Backtrace :
public
item::function::Boolean
91
{
92
public
:
93
Backtrace() :
94
item::function::Boolean
()
95
{
96
unsigned_flag=
true
;
97
}
98
99
const
char
*func_name()
const
{
return
"backtrace"
; }
100
const
char
*fully_qualified_func_name()
const
{
return
"backtrace()"
; }
101
102
bool
val_bool
()
103
{
104
call_backtrace();
105
return
true
;
106
}
107
108
int64_t
val_int
()
109
{
110
return
val_bool
();
111
}
112
};
113
114
class
Crash :
public
item::function::Boolean
115
{
116
public
:
117
Crash() :
118
item::function::Boolean
()
119
{ }
120
121
const
char
*func_name()
const
{
return
"crash"
; }
122
const
char
*fully_qualified_func_name()
const
{
return
"crash()"
; }
123
124
bool
val_bool
()
125
{
126
raise(SIGSEGV);
127
128
return
true
;
129
}
130
131
int64_t
val_int
()
132
{
133
return
val_bool
();
134
}
135
};
136
137
}
// namespace debug
138
139
static
int
initialize(
drizzled::module::Context
&context)
140
{
141
context.add(
new
drizzled::plugin::Create_function<debug::Assert>
(
"assert_and_crash"
));
142
context.add(
new
drizzled::plugin::Create_function<debug::Backtrace>
(
"backtrace"
));
143
context.add(
new
drizzled::plugin::Create_function<debug::Crash>
(
"crash"
));
144
145
return
0;
146
}
147
148
DRIZZLE_DECLARE_PLUGIN
149
{
150
DRIZZLE_VERSION_ID,
151
"debug"
,
152
"1.1"
,
153
"Brian Aker"
,
154
N_(
"Debug functions"
),
155
PLUGIN_LICENSE_BSD,
156
initialize,
157
NULL,
158
NULL
159
}
160
DRIZZLE_DECLARE_PLUGIN_END;
debug::Assert::val_bool
bool val_bool()
Definition
plugin/debug/module.cc:63
debug::Assert::check_argument_count
bool check_argument_count(int n)
Definition
plugin/debug/module.cc:84
debug::Assert::val_int
int64_t val_int()
Definition
plugin/debug/module.cc:79
debug::Backtrace::val_bool
bool val_bool()
Definition
plugin/debug/module.cc:102
debug::Backtrace::val_int
int64_t val_int()
Definition
plugin/debug/module.cc:108
debug::Crash::val_int
int64_t val_int()
Definition
plugin/debug/module.cc:131
debug::Crash::val_bool
bool val_bool()
Definition
plugin/debug/module.cc:124
drizzled::Item::null_value
bool null_value
Definition
item.h:124
drizzled::String
Definition
sql_string.h:58
drizzled::item::function::Boolean
Definition
item/function/boolean.h:37
drizzled::module::Context
Definition
module/context.h:45
drizzled::plugin::Create_function
Definition
drizzled/plugin/function.h:68
drizzled
TODO: Rename this file - func.h is stupid.
Definition
abort_exception.h:27
← Back to Drizzle docs
plugin
debug
module.cc
Generated by
1.15.0