| |   |
| 190 | 190 | c->allow_unknown = 0; |
| 191 | 191 | c->abbrev_flag = 0; |
| 192 | 192 | set_cmd_completer (c, make_symbol_completion_list); |
| 193 | c->destroyer = NULL; |
| 193 | 194 | c->type = not_set_cmd; |
| 194 | 195 | c->var = NULL; |
| 195 | 196 | c->var_type = var_boolean; |
| … | … | |
| 615 | 615 | void |
| 616 | 616 | delete_cmd (char *name, struct cmd_list_element **list) |
| 617 | 617 | { |
| 618 | | struct cmd_list_element *c; |
| 619 | | struct cmd_list_element *p; |
| 618 | struct cmd_list_element *iter; |
| 619 | struct cmd_list_element **previous_chain_ptr; |
| 620 | |
| 621 | previous_chain_ptr = list; |
| 620 | 622 | |
| 621 | | while (*list && strcmp ((*list)->name, name) == 0) |
| 623 | for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr) |
| 622 | 624 | { |
| 623 | | if ((*list)->hookee_pre) |
| 624 | | (*list)->hookee_pre->hook_pre = 0; /* Hook slips out of its mouth */ |
| 625 | | if ((*list)->hookee_post) |
| 626 | | (*list)->hookee_post->hook_post = 0; /* Hook slips out of its bottom */ |
| 627 | | p = (*list)->next; |
| 628 | | xfree (* list); |
| 629 | | *list = p; |
| 625 | if (strcmp (iter->name, name) == 0) |
| 626 | { |
| 627 | if (iter->destroyer) |
| 628 | iter->destroyer (iter, iter->context); |
| 629 | if (iter->hookee_pre) |
| 630 | iter->hookee_pre->hook_pre = 0; |
| 631 | if (iter->hookee_post) |
| 632 | iter->hookee_post->hook_post = 0; |
| 633 | |
| 634 | /* Update the link. Note that we don't change |
| 635 | previous_chain_ptr; next time through the loop this must |
| 636 | stay the same. */ |
| 637 | *previous_chain_ptr = iter->next; |
| 638 | |
| 639 | xfree (iter); |
| 640 | } |
| 641 | else |
| 642 | previous_chain_ptr = &iter->next; |
| 630 | 643 | } |
| 631 | | |
| 632 | | if (*list) |
| 633 | | for (c = *list; c->next;) |
| 634 | | { |
| 635 | | if (strcmp (c->next->name, name) == 0) |
| 636 | | { |
| 637 | | if (c->next->hookee_pre) |
| 638 | | c->next->hookee_pre->hook_pre = 0; /* hooked cmd gets away. */ |
| 639 | | if (c->next->hookee_post) |
| 640 | | c->next->hookee_post->hook_post = 0; /* remove post hook */ |
| 641 | | /* :( no fishing metaphore */ |
| 642 | | p = c->next->next; |
| 643 | | xfree (c->next); |
| 644 | | c->next = p; |
| 645 | | } |
| 646 | | else |
| 647 | | c = c->next; |
| 648 | | } |
| 649 | 644 | } |
| 650 | 645 | |
| 651 | 646 | /* Shorthands to the commands above. */ |
| toggle raw diff |
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -190,6 +190,7 @@ add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
c->allow_unknown = 0;
c->abbrev_flag = 0;
set_cmd_completer (c, make_symbol_completion_list);
+ c->destroyer = NULL;
c->type = not_set_cmd;
c->var = NULL;
c->var_type = var_boolean;
@@ -614,37 +615,32 @@ add_setshow_zinteger_cmd (char *name, enum command_class class,
void
delete_cmd (char *name, struct cmd_list_element **list)
{
- struct cmd_list_element *c;
- struct cmd_list_element *p;
+ struct cmd_list_element *iter;
+ struct cmd_list_element **previous_chain_ptr;
+
+ previous_chain_ptr = list;
- while (*list && strcmp ((*list)->name, name) == 0)
+ for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr)
{
- if ((*list)->hookee_pre)
- (*list)->hookee_pre->hook_pre = 0; /* Hook slips out of its mouth */
- if ((*list)->hookee_post)
- (*list)->hookee_post->hook_post = 0; /* Hook slips out of its bottom */
- p = (*list)->next;
- xfree (* list);
- *list = p;
+ if (strcmp (iter->name, name) == 0)
+ {
+ if (iter->destroyer)
+ iter->destroyer (iter, iter->context);
+ if (iter->hookee_pre)
+ iter->hookee_pre->hook_pre = 0;
+ if (iter->hookee_post)
+ iter->hookee_post->hook_post = 0;
+
+ /* Update the link. Note that we don't change
+ previous_chain_ptr; next time through the loop this must
+ stay the same. */
+ *previous_chain_ptr = iter->next;
+
+ xfree (iter);
+ }
+ else
+ previous_chain_ptr = &iter->next;
}
-
- if (*list)
- for (c = *list; c->next;)
- {
- if (strcmp (c->next->name, name) == 0)
- {
- if (c->next->hookee_pre)
- c->next->hookee_pre->hook_pre = 0; /* hooked cmd gets away. */
- if (c->next->hookee_post)
- c->next->hookee_post->hook_post = 0; /* remove post hook */
- /* :( no fishing metaphore */
- p = c->next->next;
- xfree (c->next);
- c->next = p;
- }
- else
- c = c->next;
- }
}
/* Shorthands to the commands above. */ |
| |   |
| 1 | /* gdb commands implemented in Python |
| 2 | |
| 3 | Copyright (C) 2008 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "value.h" |
| 23 | #include "exceptions.h" |
| 24 | #include "python-internal.h" |
| 25 | #include "charset.h" |
| 26 | #include "gdbcmd.h" |
| 27 | #include "cli/cli-decode.h" |
| 28 | |
| 29 | /* A gdb command. For the time being only ordinary commands (not |
| 30 | set/show commands) are allowed. */ |
| 31 | struct cmdpy_object |
| 32 | { |
| 33 | PyObject_HEAD |
| 34 | |
| 35 | /* The corresponding gdb command object, or NULL if the command is |
| 36 | no longer installed. */ |
| 37 | /* It isn't clear if we will ever care about this. */ |
| 38 | struct cmd_list_element *command; |
| 39 | }; |
| 40 | |
| 41 | typedef struct cmdpy_object cmdpy_object; |
| 42 | |
| 43 | static PyObject *cmdpy_dont_repeat (PyObject *self, PyObject *args); |
| 44 | |
| 45 | static PyMethodDef cmdpy_object_methods[] = |
| 46 | { |
| 47 | { "dont_repeat", cmdpy_dont_repeat, METH_NOARGS, |
| 48 | "Prevent command repetition when user enters empty line." }, |
| 49 | |
| 50 | { 0 } |
| 51 | }; |
| 52 | |
| 53 | static PyTypeObject cmdpy_object_type = |
| 54 | { |
| 55 | PyObject_HEAD_INIT (NULL) |
| 56 | 0, /*ob_size*/ |
| 57 | "gdb.Command", /*tp_name*/ |
| 58 | sizeof (cmdpy_object), /*tp_basicsize*/ |
| 59 | 0, /*tp_itemsize*/ |
| 60 | 0, /*tp_dealloc*/ |
| 61 | 0, /*tp_print*/ |
| 62 | 0, /*tp_getattr*/ |
| 63 | 0, /*tp_setattr*/ |
| 64 | 0, /*tp_compare*/ |
| 65 | 0, /*tp_repr*/ |
| 66 | 0, /*tp_as_number*/ |
| 67 | 0, /*tp_as_sequence*/ |
| 68 | 0, /*tp_as_mapping*/ |
| 69 | 0, /*tp_hash */ |
| 70 | 0, /*tp_call*/ |
| 71 | 0, /*tp_str*/ |
| 72 | 0, /*tp_getattro*/ |
| 73 | 0, /*tp_setattro*/ |
| 74 | 0, /*tp_as_buffer*/ |
| 75 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
| 76 | "GDB command object", /* tp_doc */ |
| 77 | 0, /* tp_traverse */ |
| 78 | 0, /* tp_clear */ |
| 79 | 0, /* tp_richcompare */ |
| 80 | 0, /* tp_weaklistoffset */ |
| 81 | 0, /* tp_iter */ |
| 82 | 0, /* tp_iternext */ |
| 83 | cmdpy_object_methods /* tp_methods */ |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | |
| 88 | static PyObject * |
| 89 | cmdpy_dont_repeat (PyObject *self, PyObject *args) |
| 90 | { |
| 91 | dont_repeat (); |
| 92 | Py_RETURN_NONE; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | /* Called if the gdb cmd_list_element is destroyed. */ |
| 99 | static void |
| 100 | cmdpy_destroyer (struct cmd_list_element *self, void *context) |
| 101 | { |
| 102 | /* Release our hold on the command object. */ |
| 103 | cmdpy_object *cmd = (cmdpy_object *) context; |
| 104 | cmd->command = NULL; |
| 105 | Py_DECREF (cmd); |
| 106 | |
| 107 | /* We allocated the name and doc string. */ |
| 108 | xfree (self->name); |
| 109 | xfree (self->doc); |
| 110 | } |
| 111 | |
| 112 | /* Called by gdb to invoke the command. */ |
| 113 | static void |
| 114 | cmdpy_function (struct cmd_list_element *command, char *args, int from_tty) |
| 115 | { |
| 116 | cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command); |
| 117 | PyObject *method, *argobj, *ttyobj, *result; |
| 118 | |
| 119 | if (! obj) |
| 120 | error ("Invalid invocation of Python command object"); |
| 121 | if (! PyObject_HasAttrString ((PyObject *) obj, "invoke")) |
| 122 | error ("Python command object missing 'invoke' method"); |
| 123 | |
| 124 | method = PyString_FromString ("invoke"); |
| 125 | if (! args) |
| 126 | { |
| 127 | argobj = Py_None; |
| 128 | Py_INCREF (argobj); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | argobj = PyString_FromString (args); |
| 133 | if (! argobj) |
| 134 | error ("Couldn't convert arguments to Python string"); |
| 135 | } |
| 136 | ttyobj = from_tty ? Py_True : Py_False; |
| 137 | Py_INCREF (ttyobj); |
| 138 | result = PyObject_CallMethodObjArgs ((PyObject *) obj, method, argobj, |
| 139 | ttyobj, NULL); |
| 140 | Py_DECREF (method); |
| 141 | Py_DECREF (argobj); |
| 142 | Py_DECREF (ttyobj); |
| 143 | if (! result) |
| 144 | { |
| 145 | /* FIXME: pretty lame. */ |
| 146 | PyErr_Print (); |
| 147 | error ("Error occurred in Python command"); |
| 148 | } |
| 149 | Py_DECREF (result); |
| 150 | } |
| 151 | |
| 152 | /* Object initializer; sets up gdb-side structures for command. |
| 153 | |
| 154 | Use: __init__(NAME, CMDCLASS). |
| 155 | |
| 156 | NAME is the name of the command; spaces in the name mean to look up |
| 157 | initial segments as prefixes. |
| 158 | |
| 159 | CMDCLASS is the kind of command. It should be one of the COMMAND_* |
| 160 | constants defined in the gdb module. |
| 161 | |
| 162 | The documentation for the command is taken from the doc string for |
| 163 | the python class. |
| 164 | |
| 165 | */ |
| 166 | static int |
| 167 | cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds) |
| 168 | { |
| 169 | cmdpy_object *obj = (cmdpy_object *) self; |
| 170 | char *name; |
| 171 | int cmdtype; |
| 172 | volatile struct gdb_exception except; |
| 173 | |
| 174 | if (obj->command) |
| 175 | { |
| 176 | /* Note: this is apparently not documented in Python. We return |
| 177 | 0 for success, -1 for failure. */ |
| 178 | PyErr_Format (PyExc_RuntimeError, "Command object already initialized"); |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | if (! PyArg_ParseTuple (args, "si", &name, &cmdtype)) |
| 183 | return -1; |
| 184 | |
| 185 | if (cmdtype != no_class && cmdtype != class_run |
| 186 | && cmdtype != class_vars && cmdtype != class_stack |
| 187 | && cmdtype != class_files && cmdtype != class_support |
| 188 | && cmdtype != class_info && cmdtype != class_breakpoint |
| 189 | && cmdtype != class_trace && cmdtype != class_obscure |
| 190 | && cmdtype != class_maintenance) |
| 191 | { |
| 192 | PyErr_Format (PyExc_RuntimeError, "invalid command class argument"); |
| 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | TRY_CATCH (except, RETURN_MASK_ALL) |
| 197 | { |
| 198 | /* FIXME: decoding NAME if it has spaces. Also, how to add new |
| 199 | prefix commands? */ |
| 200 | struct cmd_list_element *cmd = add_cmd (xstrdup (name), |
| 201 | (enum command_class) cmdtype, |
| 202 | NULL, |
| 203 | xstrdup ("FIXME: docstring"), |
| 204 | &cmdlist /* FIXME */); |
| 205 | /* There appears to be no API to set this. */ |
| 206 | cmd->func = cmdpy_function; |
| 207 | /* FIXME: route completion requests through user object. */ |
| 208 | |
| 209 | obj->command = cmd; |
| 210 | Py_INCREF (self); |
| 211 | set_cmd_context (cmd, self); |
| 212 | } |
| 213 | if (except.reason < 0) |
| 214 | { |
| 215 | PyErr_Format (except.reason == RETURN_QUIT |
| 216 | ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, |
| 217 | "%s", except.message); |
| 218 | return -1; |
| 219 | } |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | void |
| 226 | gdbpy_initialize_commands (void) |
| 227 | { |
| 228 | cmdpy_object_type.tp_new = PyType_GenericNew; |
| 229 | cmdpy_object_type.tp_init = cmdpy_init; |
| 230 | if (PyType_Ready (&cmdpy_object_type) < 0) |
| 231 | return; |
| 232 | |
| 233 | /* Note: alias and user seem to be special; pseudo appears to be |
| 234 | unused, and there is no reason to expose tui or xdb, I think. */ |
| 235 | if (PyModule_AddIntConstant (gdb_module, "COMMAND_NONE", no_class) < 0 |
| 236 | || PyModule_AddIntConstant (gdb_module, "COMMAND_RUN", class_run) < 0 |
| 237 | || PyModule_AddIntConstant (gdb_module, "COMMAND_VARS", class_vars) < 0 |
| 238 | || PyModule_AddIntConstant (gdb_module, "COMMAND_STACK", class_stack) < 0 |
| 239 | || PyModule_AddIntConstant (gdb_module, "COMMAND_FILES", class_files) < 0 |
| 240 | || PyModule_AddIntConstant (gdb_module, "COMMAND_SUPPORT", |
| 241 | class_support) < 0 |
| 242 | || PyModule_AddIntConstant (gdb_module, "COMMAND_INFO", class_info) < 0 |
| 243 | || PyModule_AddIntConstant (gdb_module, "COMMAND_BREAKPOINT", |
| 244 | class_breakpoint) < 0 |
| 245 | || PyModule_AddIntConstant (gdb_module, "COMMAND_TRACE", class_trace) < 0 |
| 246 | || PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE", |
| 247 | class_obscure) < 0 |
| 248 | || PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE", |
| 249 | class_maintenance) < 0) |
| 250 | return; |
| 251 | |
| 252 | Py_INCREF (&cmdpy_object_type); |
| 253 | PyModule_AddObject (gdb_module, "Command", |
| 254 | (PyObject *) &cmdpy_object_type); |
| 255 | } |
| toggle raw diff |
--- /dev/null
+++ b/gdb/python/cmd.c
@@ -0,0 +1,255 @@
+/* gdb commands implemented in Python
+
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include "defs.h"
+#include "value.h"
+#include "exceptions.h"
+#include "python-internal.h"
+#include "charset.h"
+#include "gdbcmd.h"
+#include "cli/cli-decode.h"
+
+/* A gdb command. For the time being only ordinary commands (not
+ set/show commands) are allowed. */
+struct cmdpy_object
+{
+ PyObject_HEAD
+
+ /* The corresponding gdb command object, or NULL if the command is
+ no longer installed. */
+ /* It isn't clear if we will ever care about this. */
+ struct cmd_list_element *command;
+};
+
+typedef struct cmdpy_object cmdpy_object;
+
+static PyObject *cmdpy_dont_repeat (PyObject *self, PyObject *args);
+
+static PyMethodDef cmdpy_object_methods[] =
+{
+ { "dont_repeat", cmdpy_dont_repeat, METH_NOARGS,
+ "Prevent command repetition when user enters empty line." },
+
+ { 0 }
+};
+
+static PyTypeObject cmdpy_object_type =
+{
+ PyObject_HEAD_INIT (NULL)
+ 0, /*ob_size*/
+ "gdb.Command", /*tp_name*/
+ sizeof (cmdpy_object), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ 0, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "GDB command object", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ cmdpy_object_methods /* tp_methods */
+};
+
+
+
+static PyObject *
+cmdpy_dont_repeat (PyObject *self, PyObject *args)
+{
+ dont_repeat ();
+ Py_RETURN_NONE;
+}
+
+
+
+
+/* Called if the gdb cmd_list_element is destroyed. */
+static void
+cmdpy_destroyer (struct cmd_list_element *self, void *context)
+{
+ /* Release our hold on the command object. */
+ cmdpy_object *cmd = (cmdpy_object *) context;
+ cmd->command = NULL;
+ Py_DECREF (cmd);
+
+ /* We allocated the name and doc string. */
+ xfree (self->name);
+ xfree (self->doc);
+}
+
+/* Called by gdb to invoke the command. */
+static void
+cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
+{
+ cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
+ PyObject *method, *argobj, *ttyobj, *result;
+
+ if (! obj)
+ error ("Invalid invocation of Python command object");
+ if (! PyObject_HasAttrString ((PyObject *) obj, "invoke"))
+ error ("Python command object missing 'invoke' method");
+
+ method = PyString_FromString ("invoke");
+ if (! args)
+ {
+ argobj = Py_None;
+ Py_INCREF (argobj);
+ }
+ else
+ {
+ argobj = PyString_FromString (args);
+ if (! argobj)
+ error ("Couldn't convert arguments to Python string");
+ }
+ ttyobj = from_tty ? Py_True : Py_False;
+ Py_INCREF (ttyobj);
+ result = PyObject_CallMethodObjArgs ((PyObject *) obj, method, argobj,
+ ttyobj, NULL);
+ Py_DECREF (method);
+ Py_DECREF (argobj);
+ Py_DECREF (ttyobj);
+ if (! result)
+ {
+ /* FIXME: pretty lame. */
+ PyErr_Print ();
+ error ("Error occurred in Python command");
+ }
+ Py_DECREF (result);
+}
+
+/* Object initializer; sets up gdb-side structures for command.
+
+ Use: __init__(NAME, CMDCLASS).
+
+ NAME is the name of the command; spaces in the name mean to look up
+ initial segments as prefixes.
+
+ CMDCLASS is the kind of command. It should be one of the COMMAND_*
+ constants defined in the gdb module.
+
+ The documentation for the command is taken from the doc string for
+ the python class.
+
+*/
+static int
+cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
+{
+ cmdpy_object *obj = (cmdpy_object *) self;
+ char *name;
+ int cmdtype;
+ volatile struct gdb_exception except;
+
+ if (obj->command)
+ {
+ /* Note: this is apparently not documented in Python. We return
+ 0 for success, -1 for failure. */
+ PyErr_Format (PyExc_RuntimeError, "Command object already initialized");
+ return -1;
+ }
+
+ if (! PyArg_ParseTuple (args, "si", &name, &cmdtype))
+ return -1;
+
+ if (cmdtype != no_class && cmdtype != class_run
+ && cmdtype != class_vars && cmdtype != class_stack
+ && cmdtype != class_files && cmdtype != class_support
+ && cmdtype != class_info && cmdtype != class_breakpoint
+ && cmdtype != class_trace && cmdtype != class_obscure
+ && cmdtype != class_maintenance)
+ {
+ PyErr_Format (PyExc_RuntimeError, "invalid command class argument");
+ return -1;
+ }
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ /* FIXME: decoding NAME if it has spaces. Also, how to add new
+ prefix commands? */
+ struct cmd_list_element *cmd = add_cmd (xstrdup (name),
+ (enum command_class) cmdtype,
+ NULL,
+ xstrdup ("FIXME: docstring"),
+ &cmdlist /* FIXME */);
+ /* There appears to be no API to set this. */
+ cmd->func = cmdpy_function;
+ /* FIXME: route completion requests through user object. */
+
+ obj->command = cmd;
+ Py_INCREF (self);
+ set_cmd_context (cmd, self);
+ }
+ if (except.reason < 0)
+ {
+ PyErr_Format (except.reason == RETURN_QUIT
+ ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
+ "%s", except.message);
+ return -1;
+ }
+ return 0;
+}
+
+
+
+void
+gdbpy_initialize_commands (void)
+{
+ cmdpy_object_type.tp_new = PyType_GenericNew;
+ cmdpy_object_type.tp_init = cmdpy_init;
+ if (PyType_Ready (&cmdpy_object_type) < 0)
+ return;
+
+ /* Note: alias and user seem to be special; pseudo appears to be
+ unused, and there is no reason to expose tui or xdb, I think. */
+ if (PyModule_AddIntConstant (gdb_module, "COMMAND_NONE", no_class) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_RUN", class_run) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_VARS", class_vars) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_STACK", class_stack) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_FILES", class_files) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_SUPPORT",
+ class_support) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_INFO", class_info) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_BREAKPOINT",
+ class_breakpoint) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_TRACE", class_trace) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE",
+ class_obscure) < 0
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
+ class_maintenance) < 0)
+ return;
+
+ Py_INCREF (&cmdpy_object_type);
+ PyModule_AddObject (gdb_module, "Command",
+ (PyObject *) &cmdpy_object_type);
+} |