~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/debug/module.cc

  • Committer: Patrick Crews
  • Date: 2010-09-14 20:21:03 UTC
  • mto: (1771.1.1 pcrews)
  • mto: This revision was merged to the branch mainline in revision 1772.
  • Revision ID: gleebix@gmail.com-20100914202103-1db2n0bshzafep19
Moved transaction_log tests into updated non-publisher-based tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
    util::custom_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
 
  "Useful functions for programmers to debug the server.",
155
 
  PLUGIN_LICENSE_BSD,
156
 
  initialize, /* Plugin Init */
157
 
  NULL,   /* depends */
158
 
  NULL    /* config options */
159
 
}
160
 
DRIZZLE_DECLARE_PLUGIN_END;