1996.1.2
by Brian Aker
Moved crash function to being debug. |
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/util/backtrace.h> |
|
42 |
#include <drizzled/function/func.h> |
|
43 |
#include <drizzled/item/cmpfunc.h> |
|
2030.2.1
by Brian Aker
Refactor boolean function. |
44 |
#include <drizzled/item/function/boolean.h> |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
45 |
|
46 |
using namespace drizzled; |
|
47 |
||
48 |
namespace debug { |
|
49 |
||
2030.2.1
by Brian Aker
Refactor boolean function. |
50 |
class Assert :public item::function::Boolean |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
51 |
{
|
52 |
public: |
|
53 |
Assert() : |
|
2030.2.1
by Brian Aker
Refactor boolean function. |
54 |
item::function::Boolean() |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
55 |
{
|
56 |
unsigned_flag= true; |
|
57 |
}
|
|
58 |
||
2039.3.1
by Brian Aker
Create a user available assert() function. |
59 |
const char *func_name() const { return "assert_and_crash"; } |
60 |
const char *fully_qualified_func_name() const { return "assert_and_crash()"; } |
|
1996.1.2
by Brian Aker
Moved crash function to being debug. |
61 |
|
62 |
bool val_bool() |
|
63 |
{
|
|
2030.2.1
by Brian Aker
Refactor boolean function. |
64 |
String _res; |
65 |
String *res= args[0]->val_str(&_res); |
|
1996.1.2
by Brian Aker
Moved crash function to being debug. |
66 |
|
67 |
null_value= false; |
|
68 |
||
69 |
if (not res or not res->length()) |
|
70 |
{
|
|
71 |
assert(0); |
|
72 |
return true; |
|
73 |
}
|
|
74 |
||
75 |
return false; |
|
76 |
}
|
|
77 |
||
78 |
int64_t val_int() |
|
79 |
{
|
|
80 |
return val_bool(); |
|
81 |
}
|
|
82 |
||
83 |
bool check_argument_count(int n) |
|
84 |
{
|
|
85 |
return (n == 1); |
|
86 |
}
|
|
87 |
};
|
|
88 |
||
2030.2.1
by Brian Aker
Refactor boolean function. |
89 |
class Backtrace :public item::function::Boolean |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
90 |
{
|
91 |
public: |
|
92 |
Backtrace() : |
|
2030.2.1
by Brian Aker
Refactor boolean function. |
93 |
item::function::Boolean() |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
94 |
{
|
95 |
unsigned_flag= true; |
|
96 |
}
|
|
97 |
||
98 |
const char *func_name() const { return "backtrace"; } |
|
99 |
const char *fully_qualified_func_name() const { return "backtrace()"; } |
|
100 |
||
101 |
bool val_bool() |
|
102 |
{
|
|
2030.2.1
by Brian Aker
Refactor boolean function. |
103 |
util::custom_backtrace(); |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
104 |
return true; |
105 |
}
|
|
106 |
||
107 |
int64_t val_int() |
|
108 |
{
|
|
109 |
return val_bool(); |
|
110 |
}
|
|
111 |
};
|
|
112 |
||
2030.2.1
by Brian Aker
Refactor boolean function. |
113 |
class Crash :public item::function::Boolean |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
114 |
{
|
115 |
public: |
|
116 |
Crash() : |
|
2030.2.1
by Brian Aker
Refactor boolean function. |
117 |
item::function::Boolean() |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
118 |
{ } |
119 |
||
120 |
const char *func_name() const { return "crash"; } |
|
121 |
const char *fully_qualified_func_name() const { return "crash()"; } |
|
122 |
||
123 |
bool val_bool() |
|
124 |
{
|
|
125 |
raise(SIGSEGV); |
|
126 |
||
127 |
return true; |
|
128 |
}
|
|
129 |
||
130 |
int64_t val_int() |
|
131 |
{
|
|
132 |
return val_bool(); |
|
133 |
}
|
|
134 |
};
|
|
135 |
||
136 |
} // namespace debug |
|
137 |
||
138 |
static int initialize(drizzled::module::Context &context) |
|
139 |
{
|
|
2039.3.1
by Brian Aker
Create a user available assert() function. |
140 |
context.add(new drizzled::plugin::Create_function<debug::Assert>("assert_and_crash")); |
1996.1.2
by Brian Aker
Moved crash function to being debug. |
141 |
context.add(new drizzled::plugin::Create_function<debug::Backtrace>("backtrace")); |
142 |
context.add(new drizzled::plugin::Create_function<debug::Crash>("crash")); |
|
143 |
||
144 |
return 0; |
|
145 |
}
|
|
146 |
||
147 |
DRIZZLE_DECLARE_PLUGIN
|
|
148 |
{
|
|
149 |
DRIZZLE_VERSION_ID, |
|
150 |
"debug", |
|
151 |
"1.1", |
|
152 |
"Brian Aker", |
|
153 |
"Useful functions for programmers to debug the server.", |
|
154 |
PLUGIN_LICENSE_BSD, |
|
155 |
initialize, /* Plugin Init */ |
|
156 |
NULL, /* system variables */ |
|
157 |
NULL /* config options */ |
|
158 |
}
|
|
159 |
DRIZZLE_DECLARE_PLUGIN_END; |