GDB (API)
/home/stan/gdb/src/gdb/python/py-param.c
Go to the documentation of this file.
00001 /* GDB parameters implemented in Python
00002 
00003    Copyright (C) 2008-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 
00021 #include "defs.h"
00022 #include "value.h"
00023 #include "exceptions.h"
00024 #include "python-internal.h"
00025 #include "charset.h"
00026 #include "gdbcmd.h"
00027 #include "cli/cli-decode.h"
00028 #include "completer.h"
00029 #include "language.h"
00030 #include "arch-utils.h"
00031 
00032 /* Parameter constants and their values.  */
00033 struct parm_constant
00034 {
00035   char *name;
00036   int value;
00037 };
00038 
00039 struct parm_constant parm_constants[] =
00040 {
00041   { "PARAM_BOOLEAN", var_boolean }, /* ARI: var_boolean */
00042   { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
00043   { "PARAM_UINTEGER", var_uinteger },
00044   { "PARAM_INTEGER", var_integer },
00045   { "PARAM_STRING", var_string },
00046   { "PARAM_STRING_NOESCAPE", var_string_noescape },
00047   { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
00048   { "PARAM_FILENAME", var_filename },
00049   { "PARAM_ZINTEGER", var_zinteger },
00050   { "PARAM_ENUM", var_enum },
00051   { NULL, 0 }
00052 };
00053 
00054 /* A union that can hold anything described by enum var_types.  */
00055 union parmpy_variable
00056 {
00057   /* Hold an integer value, for boolean and integer types.  */
00058   int intval;
00059 
00060   /* Hold an auto_boolean.  */
00061   enum auto_boolean autoboolval;
00062 
00063   /* Hold an unsigned integer value, for uinteger.  */
00064   unsigned int uintval;
00065 
00066   /* Hold a string, for the various string types.  */
00067   char *stringval;
00068 
00069   /* Hold a string, for enums.  */
00070   const char *cstringval;
00071 };
00072 
00073 /* A GDB parameter.  */
00074 struct parmpy_object
00075 {
00076   PyObject_HEAD
00077 
00078   /* The type of the parameter.  */
00079   enum var_types type;
00080 
00081   /* The value of the parameter.  */
00082   union parmpy_variable value;
00083 
00084   /* For an enum command, the possible values.  The vector is
00085      allocated with xmalloc, as is each element.  It is
00086      NULL-terminated.  */
00087   const char **enumeration;
00088 };
00089 
00090 typedef struct parmpy_object parmpy_object;
00091 
00092 static PyTypeObject parmpy_object_type
00093     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
00094 
00095 /* Some handy string constants.  */
00096 static PyObject *set_doc_cst;
00097 static PyObject *show_doc_cst;
00098 
00099 
00100 
00101 /* Get an attribute.  */
00102 static PyObject *
00103 get_attr (PyObject *obj, PyObject *attr_name)
00104 {
00105   if (PyString_Check (attr_name)
00106 #ifdef IS_PY3K
00107       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
00108 #else
00109       && ! strcmp (PyString_AsString (attr_name), "value"))
00110 #endif
00111     {
00112       parmpy_object *self = (parmpy_object *) obj;
00113 
00114       return gdbpy_parameter_value (self->type, &self->value);
00115     }
00116 
00117   return PyObject_GenericGetAttr (obj, attr_name);
00118 }
00119 
00120 /* Set a parameter value from a Python value.  Return 0 on success.  Returns
00121    -1 on error, with a python exception set.  */
00122 static int
00123 set_parameter_value (parmpy_object *self, PyObject *value)
00124 {
00125   int cmp;
00126 
00127   switch (self->type)
00128     {
00129     case var_string:
00130     case var_string_noescape:
00131     case var_optional_filename:
00132     case var_filename:
00133       if (! gdbpy_is_string (value)
00134           && (self->type == var_filename
00135               || value != Py_None))
00136         {
00137           PyErr_SetString (PyExc_RuntimeError, 
00138                            _("String required for filename."));
00139 
00140           return -1;
00141         }
00142       if (value == Py_None)
00143         {
00144           xfree (self->value.stringval);
00145           if (self->type == var_optional_filename)
00146             self->value.stringval = xstrdup ("");
00147           else
00148             self->value.stringval = NULL;
00149         }
00150       else
00151         {
00152           char *string;
00153 
00154           string = python_string_to_host_string (value);
00155           if (string == NULL)
00156             return -1;
00157 
00158           xfree (self->value.stringval);
00159           self->value.stringval = string;
00160         }
00161       break;
00162 
00163     case var_enum:
00164       {
00165         int i;
00166         char *str;
00167 
00168         if (! gdbpy_is_string (value))
00169           {
00170             PyErr_SetString (PyExc_RuntimeError, 
00171                              _("ENUM arguments must be a string."));
00172             return -1;
00173           }
00174 
00175         str = python_string_to_host_string (value);
00176         if (str == NULL)
00177           return -1;
00178         for (i = 0; self->enumeration[i]; ++i)
00179           if (! strcmp (self->enumeration[i], str))
00180             break;
00181         xfree (str);
00182         if (! self->enumeration[i])
00183           {
00184             PyErr_SetString (PyExc_RuntimeError,
00185                              _("The value must be member of an enumeration."));
00186             return -1;
00187           }
00188         self->value.cstringval = self->enumeration[i];
00189         break;
00190       }
00191 
00192     case var_boolean:
00193       if (! PyBool_Check (value))
00194         {
00195           PyErr_SetString (PyExc_RuntimeError, 
00196                            _("A boolean argument is required."));
00197           return -1;
00198         }
00199       cmp = PyObject_IsTrue (value);
00200       if (cmp < 0) 
00201           return -1;
00202       self->value.intval = cmp;
00203       break;
00204 
00205     case var_auto_boolean:
00206       if (! PyBool_Check (value) && value != Py_None)
00207         {
00208           PyErr_SetString (PyExc_RuntimeError,
00209                            _("A boolean or None is required"));
00210           return -1;
00211         }
00212 
00213       if (value == Py_None)
00214         self->value.autoboolval = AUTO_BOOLEAN_AUTO;
00215       else
00216         {
00217           cmp = PyObject_IsTrue (value);
00218           if (cmp < 0 )
00219             return -1;    
00220           if (cmp == 1)
00221             self->value.autoboolval = AUTO_BOOLEAN_TRUE;
00222           else 
00223             self->value.autoboolval = AUTO_BOOLEAN_FALSE;
00224         }
00225       break;
00226 
00227     case var_integer:
00228     case var_zinteger:
00229     case var_uinteger:
00230       {
00231         long l;
00232         int ok;
00233 
00234         if (! PyInt_Check (value))
00235           {
00236             PyErr_SetString (PyExc_RuntimeError, 
00237                              _("The value must be integer."));
00238             return -1;
00239           }
00240 
00241         if (! gdb_py_int_as_long (value, &l))
00242           return -1;
00243 
00244         if (self->type == var_uinteger)
00245           {
00246             ok = (l >= 0 && l <= UINT_MAX);
00247             if (l == 0)
00248               l = UINT_MAX;
00249           }
00250         else if (self->type == var_integer)
00251           {
00252             ok = (l >= INT_MIN && l <= INT_MAX);
00253             if (l == 0)
00254               l = INT_MAX;
00255           }
00256         else
00257           ok = (l >= INT_MIN && l <= INT_MAX);
00258 
00259         if (! ok)
00260           {
00261             PyErr_SetString (PyExc_RuntimeError, 
00262                              _("Range exceeded."));
00263             return -1;
00264           }
00265 
00266         self->value.intval = (int) l;
00267         break;
00268       }
00269 
00270     default:
00271       PyErr_SetString (PyExc_RuntimeError, 
00272                        _("Unhandled type in parameter value."));
00273       return -1;
00274     }
00275 
00276   return 0;
00277 }
00278 
00279 /* Set an attribute.  Returns -1 on error, with a python exception set.  */
00280 static int
00281 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
00282 {
00283   if (PyString_Check (attr_name)
00284 #ifdef IS_PY3K
00285       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
00286 #else
00287       && ! strcmp (PyString_AsString (attr_name), "value"))
00288 #endif
00289     {
00290       if (!val)
00291         {
00292           PyErr_SetString (PyExc_RuntimeError,
00293                            _("Cannot delete a parameter's value."));
00294           return -1;
00295         }
00296       return set_parameter_value ((parmpy_object *) obj, val);
00297     }
00298 
00299   return PyObject_GenericSetAttr (obj, attr_name, val);
00300 }
00301 
00302 /* A helper function which returns a documentation string for an
00303    object. */
00304 
00305 static char *
00306 get_doc_string (PyObject *object, PyObject *attr)
00307 {
00308   char *result = NULL;
00309 
00310   if (PyObject_HasAttr (object, attr))
00311     {
00312       PyObject *ds_obj = PyObject_GetAttr (object, attr);
00313 
00314       if (ds_obj && gdbpy_is_string (ds_obj))
00315         {
00316           result = python_string_to_host_string (ds_obj);
00317           if (result == NULL)
00318             gdbpy_print_stack ();
00319         }
00320       Py_XDECREF (ds_obj);
00321     }
00322   if (! result)
00323     result = xstrdup (_("This command is not documented."));
00324   return result;
00325 }
00326 
00327 /* Helper function which will execute a METHOD in OBJ passing the
00328    argument ARG.  ARG can be NULL.  METHOD should return a Python
00329    string.  If this function returns NULL, there has been an error and
00330    the appropriate exception set.  */
00331 static char *
00332 call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
00333 {
00334   char *data = NULL;
00335   PyObject *result = PyObject_CallMethodObjArgs (obj, method, arg, NULL);
00336 
00337   if (! result)
00338     return NULL;
00339 
00340   if (gdbpy_is_string (result))
00341     {
00342       data = python_string_to_host_string (result);
00343       Py_DECREF (result);
00344       if (! data)
00345         return NULL;
00346     }
00347   else
00348     {
00349       PyErr_SetString (PyExc_RuntimeError,
00350                        _("Parameter must return a string value."));
00351       Py_DECREF (result);
00352       return NULL;
00353     }
00354 
00355   return data;
00356 }
00357 
00358 /* A callback function that is registered against the respective
00359    add_setshow_* set_doc prototype.  This function will either call
00360    the Python function "get_set_string" or extract the Python
00361    attribute "set_doc" and return the contents as a string.  If
00362    neither exist, insert a string indicating the Parameter is not
00363    documented.  */
00364 static void
00365 get_set_value (char *args, int from_tty,
00366                struct cmd_list_element *c)
00367 {
00368   PyObject *obj = (PyObject *) get_cmd_context (c);
00369   char *set_doc_string;
00370   struct cleanup *cleanup = ensure_python_env (get_current_arch (),
00371                                                current_language);
00372   PyObject *set_doc_func = PyString_FromString ("get_set_string");
00373 
00374   if (! set_doc_func)
00375     goto error;
00376 
00377   if (PyObject_HasAttr (obj, set_doc_func))
00378     {
00379       set_doc_string = call_doc_function (obj, set_doc_func, NULL);
00380       if (! set_doc_string)
00381         goto error;
00382     }
00383   else
00384     {
00385       /* We have to preserve the existing < GDB 7.3 API.  If a
00386          callback function does not exist, then attempt to read the
00387          set_doc attribute.  */
00388       set_doc_string  = get_doc_string (obj, set_doc_cst);
00389     }
00390 
00391   make_cleanup (xfree, set_doc_string);
00392   fprintf_filtered (gdb_stdout, "%s\n", set_doc_string);
00393 
00394   Py_XDECREF (set_doc_func);
00395   do_cleanups (cleanup);
00396   return;
00397 
00398  error:
00399   Py_XDECREF (set_doc_func);
00400   gdbpy_print_stack ();
00401   do_cleanups (cleanup);
00402   return;
00403 }
00404 
00405 /* A callback function that is registered against the respective
00406    add_setshow_* show_doc prototype.  This function will either call
00407    the Python function "get_show_string" or extract the Python
00408    attribute "show_doc" and return the contents as a string.  If
00409    neither exist, insert a string indicating the Parameter is not
00410    documented.  */
00411 static void
00412 get_show_value (struct ui_file *file, int from_tty,
00413                 struct cmd_list_element *c,
00414                 const char *value)
00415 {
00416   PyObject *obj = (PyObject *) get_cmd_context (c);
00417   char *show_doc_string = NULL;
00418   struct cleanup *cleanup = ensure_python_env (get_current_arch (),
00419                                                current_language);
00420   PyObject *show_doc_func = PyString_FromString ("get_show_string");
00421 
00422   if (! show_doc_func)
00423     goto error;
00424 
00425   if (PyObject_HasAttr (obj, show_doc_func))
00426     {
00427       PyObject *val_obj = PyString_FromString (value);
00428 
00429       if (! val_obj)
00430         goto error;
00431 
00432       show_doc_string = call_doc_function (obj, show_doc_func, val_obj);
00433       Py_DECREF (val_obj);
00434       if (! show_doc_string)
00435         goto error;
00436 
00437       make_cleanup (xfree, show_doc_string);
00438 
00439       fprintf_filtered (file, "%s\n", show_doc_string);
00440     }
00441   else
00442     {
00443       /* We have to preserve the existing < GDB 7.3 API.  If a
00444          callback function does not exist, then attempt to read the
00445          show_doc attribute.  */
00446       show_doc_string  = get_doc_string (obj, show_doc_cst);
00447       make_cleanup (xfree, show_doc_string);
00448       fprintf_filtered (file, "%s %s\n", show_doc_string, value);
00449     }
00450 
00451   Py_XDECREF (show_doc_func);
00452   do_cleanups (cleanup);
00453   return;
00454 
00455  error:
00456   Py_XDECREF (show_doc_func);
00457   gdbpy_print_stack ();
00458   do_cleanups (cleanup);
00459   return;
00460 }
00461 
00462 
00463 /* A helper function that dispatches to the appropriate add_setshow
00464    function.  */
00465 static void
00466 add_setshow_generic (int parmclass, enum command_class cmdclass,
00467                      char *cmd_name, parmpy_object *self,
00468                      char *set_doc, char *show_doc, char *help_doc,
00469                      struct cmd_list_element **set_list,
00470                      struct cmd_list_element **show_list)
00471 {
00472   struct cmd_list_element *param = NULL;
00473   const char *tmp_name = NULL;
00474 
00475   switch (parmclass)
00476     {
00477     case var_boolean:
00478 
00479       add_setshow_boolean_cmd (cmd_name, cmdclass,
00480                                &self->value.intval, set_doc, show_doc,
00481                                help_doc, get_set_value, get_show_value,
00482                                set_list, show_list);
00483 
00484       break;
00485 
00486     case var_auto_boolean:
00487       add_setshow_auto_boolean_cmd (cmd_name, cmdclass,
00488                                     &self->value.autoboolval,
00489                                     set_doc, show_doc, help_doc,
00490                                     get_set_value, get_show_value,
00491                                     set_list, show_list);
00492       break;
00493 
00494     case var_uinteger:
00495       add_setshow_uinteger_cmd (cmd_name, cmdclass,
00496                                 &self->value.uintval, set_doc, show_doc,
00497                                 help_doc, get_set_value, get_show_value,
00498                                 set_list, show_list);
00499       break;
00500 
00501     case var_integer:
00502       add_setshow_integer_cmd (cmd_name, cmdclass,
00503                                &self->value.intval, set_doc, show_doc,
00504                                help_doc, get_set_value, get_show_value,
00505                                set_list, show_list); break;
00506 
00507     case var_string:
00508       add_setshow_string_cmd (cmd_name, cmdclass,
00509                               &self->value.stringval, set_doc, show_doc,
00510                               help_doc, get_set_value, get_show_value,
00511                               set_list, show_list); break;
00512 
00513     case var_string_noescape:
00514       add_setshow_string_noescape_cmd (cmd_name, cmdclass,
00515                                        &self->value.stringval,
00516                                        set_doc, show_doc, help_doc,
00517                                        get_set_value, get_show_value,
00518                                        set_list, show_list);
00519 
00520       break;
00521 
00522     case var_optional_filename:
00523       add_setshow_optional_filename_cmd (cmd_name, cmdclass,
00524                                          &self->value.stringval, set_doc,
00525                                          show_doc, help_doc, get_set_value,
00526                                          get_show_value, set_list,
00527                                          show_list);
00528       break;
00529 
00530     case var_filename:
00531       add_setshow_filename_cmd (cmd_name, cmdclass,
00532                                 &self->value.stringval, set_doc, show_doc,
00533                                 help_doc, get_set_value, get_show_value,
00534                                 set_list, show_list); break;
00535 
00536     case var_zinteger:
00537       add_setshow_zinteger_cmd (cmd_name, cmdclass,
00538                                 &self->value.intval, set_doc, show_doc,
00539                                 help_doc, get_set_value, get_show_value,
00540                                 set_list, show_list);
00541       break;
00542 
00543     case var_enum:
00544       add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
00545                             &self->value.cstringval, set_doc, show_doc,
00546                             help_doc, get_set_value, get_show_value,
00547                             set_list, show_list);
00548       /* Initialize the value, just in case.  */
00549       self->value.cstringval = self->enumeration[0];
00550       break;
00551     }
00552 
00553   /* Lookup created parameter, and register Python object against the
00554      parameter context.  Perform this task against both lists.  */
00555   tmp_name = cmd_name;
00556   param = lookup_cmd (&tmp_name, *show_list, "", 0, 1);
00557   if (param)
00558     set_cmd_context (param, self);
00559 
00560   tmp_name = cmd_name;
00561   param = lookup_cmd (&tmp_name, *set_list, "", 0, 1);
00562   if (param)
00563     set_cmd_context (param, self);
00564 }
00565 
00566 /* A helper which computes enum values.  Returns 1 on success.  Returns 0 on
00567    error, with a python exception set.  */
00568 static int
00569 compute_enum_values (parmpy_object *self, PyObject *enum_values)
00570 {
00571   Py_ssize_t size, i;
00572   struct cleanup *back_to;
00573 
00574   if (! enum_values)
00575     {
00576       PyErr_SetString (PyExc_RuntimeError,
00577                        _("An enumeration is required for PARAM_ENUM."));
00578       return 0;
00579     }
00580 
00581   if (! PySequence_Check (enum_values))
00582     {
00583       PyErr_SetString (PyExc_RuntimeError, 
00584                        _("The enumeration is not a sequence."));
00585       return 0;
00586     }
00587 
00588   size = PySequence_Size (enum_values);
00589   if (size < 0)
00590     return 0;
00591   if (size == 0)
00592     {
00593       PyErr_SetString (PyExc_RuntimeError, 
00594                        _("The enumeration is empty."));
00595       return 0;
00596     }
00597 
00598   self->enumeration = xmalloc ((size + 1) * sizeof (char *));
00599   back_to = make_cleanup (free_current_contents, &self->enumeration);
00600   memset (self->enumeration, 0, (size + 1) * sizeof (char *));
00601 
00602   for (i = 0; i < size; ++i)
00603     {
00604       PyObject *item = PySequence_GetItem (enum_values, i);
00605 
00606       if (! item)
00607         {
00608           do_cleanups (back_to);
00609           return 0;
00610         }
00611       if (! gdbpy_is_string (item))
00612         {
00613           Py_DECREF (item);
00614           do_cleanups (back_to);
00615           PyErr_SetString (PyExc_RuntimeError, 
00616                            _("The enumeration item not a string."));
00617           return 0;
00618         }
00619       self->enumeration[i] = python_string_to_host_string (item);
00620       Py_DECREF (item);
00621       if (self->enumeration[i] == NULL)
00622         {
00623           do_cleanups (back_to);
00624           return 0;
00625         }
00626       make_cleanup (xfree, (char *) self->enumeration[i]);
00627     }
00628 
00629   discard_cleanups (back_to);
00630   return 1;
00631 }
00632 
00633 /* Object initializer; sets up gdb-side structures for command.
00634 
00635    Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
00636 
00637    NAME is the name of the parameter.  It may consist of multiple
00638    words, in which case the final word is the name of the new command,
00639    and earlier words must be prefix commands.
00640 
00641    CMDCLASS is the kind of command.  It should be one of the COMMAND_*
00642    constants defined in the gdb module.
00643 
00644    PARMCLASS is the type of the parameter.  It should be one of the
00645    PARAM_* constants defined in the gdb module.
00646 
00647    If PARMCLASS is PARAM_ENUM, then the final argument should be a
00648    collection of strings.  These strings are the valid values for this
00649    parameter.
00650 
00651    The documentation for the parameter is taken from the doc string
00652    for the python class.
00653 
00654    Returns -1 on error, with a python exception set.  */
00655 
00656 static int
00657 parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
00658 {
00659   parmpy_object *obj = (parmpy_object *) self;
00660   const char *name;
00661   char *set_doc, *show_doc, *doc;
00662   char *cmd_name;
00663   int parmclass, cmdtype;
00664   PyObject *enum_values = NULL;
00665   struct cmd_list_element **set_list, **show_list;
00666   volatile struct gdb_exception except;
00667 
00668   if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
00669                           &enum_values))
00670     return -1;
00671 
00672   if (cmdtype != no_class && cmdtype != class_run
00673       && cmdtype != class_vars && cmdtype != class_stack
00674       && cmdtype != class_files && cmdtype != class_support
00675       && cmdtype != class_info && cmdtype != class_breakpoint
00676       && cmdtype != class_trace && cmdtype != class_obscure
00677       && cmdtype != class_maintenance)
00678     {
00679       PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
00680       return -1;
00681     }
00682 
00683   if (parmclass != var_boolean /* ARI: var_boolean */
00684       && parmclass != var_auto_boolean
00685       && parmclass != var_uinteger && parmclass != var_integer
00686       && parmclass != var_string && parmclass != var_string_noescape
00687       && parmclass != var_optional_filename && parmclass != var_filename
00688       && parmclass != var_zinteger && parmclass != var_enum)
00689     {
00690       PyErr_SetString (PyExc_RuntimeError,
00691                        _("Invalid parameter class argument."));
00692       return -1;
00693     }
00694 
00695   if (enum_values && parmclass != var_enum)
00696     {
00697       PyErr_SetString (PyExc_RuntimeError,
00698                        _("Only PARAM_ENUM accepts a fourth argument."));
00699       return -1;
00700     }
00701   if (parmclass == var_enum)
00702     {
00703       if (! compute_enum_values (obj, enum_values))
00704         return -1;
00705     }
00706   else
00707     obj->enumeration = NULL;
00708   obj->type = (enum var_types) parmclass;
00709   memset (&obj->value, 0, sizeof (obj->value));
00710 
00711   cmd_name = gdbpy_parse_command_name (name, &set_list,
00712                                        &setlist);
00713 
00714   if (! cmd_name)
00715     return -1;
00716   xfree (cmd_name);
00717   cmd_name = gdbpy_parse_command_name (name, &show_list,
00718                                        &showlist);
00719   if (! cmd_name)
00720     return -1;
00721 
00722   set_doc = get_doc_string (self, set_doc_cst);
00723   show_doc = get_doc_string (self, show_doc_cst);
00724   doc = get_doc_string (self, gdbpy_doc_cst);
00725 
00726   Py_INCREF (self);
00727 
00728   TRY_CATCH (except, RETURN_MASK_ALL)
00729     {
00730       add_setshow_generic (parmclass, (enum command_class) cmdtype,
00731                            cmd_name, obj,
00732                            set_doc, show_doc,
00733                            doc, set_list, show_list);
00734     }
00735   if (except.reason < 0)
00736     {
00737       xfree (cmd_name);
00738       xfree (set_doc);
00739       xfree (show_doc);
00740       xfree (doc);
00741       Py_DECREF (self);
00742       PyErr_Format (except.reason == RETURN_QUIT
00743                     ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
00744                     "%s", except.message);
00745       return -1;
00746     }
00747   return 0;
00748 }
00749 
00750 
00751 
00752 /* Initialize the 'parameters' module.  */
00753 int
00754 gdbpy_initialize_parameters (void)
00755 {
00756   int i;
00757 
00758   parmpy_object_type.tp_new = PyType_GenericNew;
00759   if (PyType_Ready (&parmpy_object_type) < 0)
00760     return -1;
00761 
00762   set_doc_cst = PyString_FromString ("set_doc");
00763   if (! set_doc_cst)
00764     return -1;
00765   show_doc_cst = PyString_FromString ("show_doc");
00766   if (! show_doc_cst)
00767     return -1;
00768 
00769   for (i = 0; parm_constants[i].name; ++i)
00770     {
00771       if (PyModule_AddIntConstant (gdb_module,
00772                                    parm_constants[i].name,
00773                                    parm_constants[i].value) < 0)
00774         return -1;
00775     }
00776 
00777   return gdb_pymodule_addobject (gdb_module, "Parameter",
00778                                  (PyObject *) &parmpy_object_type);
00779 }
00780 
00781 
00782 
00783 static PyTypeObject parmpy_object_type =
00784 {
00785   PyVarObject_HEAD_INIT (NULL, 0)
00786   "gdb.Parameter",                /*tp_name*/
00787   sizeof (parmpy_object),         /*tp_basicsize*/
00788   0,                              /*tp_itemsize*/
00789   0,                              /*tp_dealloc*/
00790   0,                              /*tp_print*/
00791   0,                              /*tp_getattr*/
00792   0,                              /*tp_setattr*/
00793   0,                              /*tp_compare*/
00794   0,                              /*tp_repr*/
00795   0,                              /*tp_as_number*/
00796   0,                              /*tp_as_sequence*/
00797   0,                              /*tp_as_mapping*/
00798   0,                              /*tp_hash */
00799   0,                              /*tp_call*/
00800   0,                              /*tp_str*/
00801   get_attr,                       /*tp_getattro*/
00802   set_attr,                       /*tp_setattro*/
00803   0,                              /*tp_as_buffer*/
00804   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
00805   "GDB parameter object",         /* tp_doc */
00806   0,                              /* tp_traverse */
00807   0,                              /* tp_clear */
00808   0,                              /* tp_richcompare */
00809   0,                              /* tp_weaklistoffset */
00810   0,                              /* tp_iter */
00811   0,                              /* tp_iternext */
00812   0,                              /* tp_methods */
00813   0,                              /* tp_members */
00814   0,                              /* tp_getset */
00815   0,                              /* tp_base */
00816   0,                              /* tp_dict */
00817   0,                              /* tp_descr_get */
00818   0,                              /* tp_descr_set */
00819   0,                              /* tp_dictoffset */
00820   parmpy_init,                    /* tp_init */
00821   0,                              /* tp_alloc */
00822 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines