~drizzle-trunk/drizzle/development

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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
37
#include <config.h>
1996.1.2 by Brian Aker
Moved crash function to being debug.
38
39
#include <signal.h>
40
41
#include <drizzled/function/func.h>
42
#include <drizzled/item/cmpfunc.h>
2030.2.1 by Brian Aker
Refactor boolean function.
43
#include <drizzled/item/function/boolean.h>
2154.2.14 by Brian Aker
More removal of session from includes.
44
#include <drizzled/plugin/function.h>
45
#include <drizzled/util/backtrace.h>
1996.1.2 by Brian Aker
Moved crash function to being debug.
46
47
using namespace drizzled;
48
49
namespace debug {
50
2030.2.1 by Brian Aker
Refactor boolean function.
51
class Assert :public item::function::Boolean
1996.1.2 by Brian Aker
Moved crash function to being debug.
52
{
53
public:
54
  Assert() :
2030.2.1 by Brian Aker
Refactor boolean function.
55
    item::function::Boolean()
1996.1.2 by Brian Aker
Moved crash function to being debug.
56
  {
57
    unsigned_flag= true;
58
  }
59
2039.3.1 by Brian Aker
Create a user available assert() function.
60
  const char *func_name() const { return "assert_and_crash"; }
61
  const char *fully_qualified_func_name() const { return "assert_and_crash()"; }
1996.1.2 by Brian Aker
Moved crash function to being debug.
62
63
  bool val_bool()
64
  {
2030.2.1 by Brian Aker
Refactor boolean function.
65
    String _res;
66
    String *res= args[0]->val_str(&_res);
1996.1.2 by Brian Aker
Moved crash function to being debug.
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
2030.2.1 by Brian Aker
Refactor boolean function.
90
class Backtrace :public item::function::Boolean
1996.1.2 by Brian Aker
Moved crash function to being debug.
91
{
92
public:
93
  Backtrace() :
2030.2.1 by Brian Aker
Refactor boolean function.
94
    item::function::Boolean()
1996.1.2 by Brian Aker
Moved crash function to being debug.
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
  {
2363.1.4 by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly.
104
    call_backtrace();
1996.1.2 by Brian Aker
Moved crash function to being debug.
105
    return true;
106
  }
107
108
  int64_t val_int()
109
  {
110
    return val_bool();
111
  }
112
};
113
2030.2.1 by Brian Aker
Refactor boolean function.
114
class Crash :public item::function::Boolean
1996.1.2 by Brian Aker
Moved crash function to being debug.
115
{
116
public:
117
  Crash() :
2030.2.1 by Brian Aker
Refactor boolean function.
118
    item::function::Boolean()
1996.1.2 by Brian Aker
Moved crash function to being debug.
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
{
2039.3.1 by Brian Aker
Create a user available assert() function.
141
  context.add(new drizzled::plugin::Create_function<debug::Assert>("assert_and_crash"));
1996.1.2 by Brian Aker
Moved crash function to being debug.
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
  "Useful functions for programmers to debug the server.",
155
  PLUGIN_LICENSE_BSD,
156
  initialize, /* Plugin Init */
2095.3.1 by Monty Taylor
Re-purpose the old plugin sysvar slot in the struct to be a depends list.
157
  NULL,   /* depends */
1996.1.2 by Brian Aker
Moved crash function to being debug.
158
  NULL    /* config options */
159
}
160
DRIZZLE_DECLARE_PLUGIN_END;