]> Git Repo - binutils.git/blob - gdb/python/py-param.c
Simplify Ada catchpoints
[binutils.git] / gdb / python / py-param.c
1 /* GDB parameters implemented in Python
2
3    Copyright (C) 2008-2022 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 "python-internal.h"
24 #include "charset.h"
25 #include "gdbcmd.h"
26 #include "cli/cli-decode.h"
27 #include "completer.h"
28 #include "language.h"
29 #include "arch-utils.h"
30
31 /* Parameter constants and their values.  */
32 static struct {
33   const char *name;
34   int value;
35 } parm_constants[] =
36 {
37   { "PARAM_BOOLEAN", var_boolean }, /* ARI: var_boolean */
38   { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
39   { "PARAM_UINTEGER", var_uinteger },
40   { "PARAM_INTEGER", var_integer },
41   { "PARAM_STRING", var_string },
42   { "PARAM_STRING_NOESCAPE", var_string_noescape },
43   { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
44   { "PARAM_FILENAME", var_filename },
45   { "PARAM_ZINTEGER", var_zinteger },
46   { "PARAM_ZUINTEGER", var_zuinteger },
47   { "PARAM_ZUINTEGER_UNLIMITED", var_zuinteger_unlimited },
48   { "PARAM_ENUM", var_enum },
49   { NULL, 0 }
50 };
51
52 /* A union that can hold anything described by enum var_types.  */
53 union parmpy_variable
54 {
55   /* Hold a boolean value.  */
56   bool boolval;
57
58   /* Hold an integer value.  */
59   int intval;
60
61   /* Hold an auto_boolean.  */
62   enum auto_boolean autoboolval;
63
64   /* Hold an unsigned integer value, for uinteger.  */
65   unsigned int uintval;
66
67   /* Hold a string, for the various string types.  The std::string is
68      new-ed.  */
69   std::string *stringval;
70
71   /* Hold a string, for enums.  */
72   const char *cstringval;
73 };
74
75 /* A GDB parameter.  */
76 struct parmpy_object
77 {
78   PyObject_HEAD
79
80   /* The type of the parameter.  */
81   enum var_types type;
82
83   /* The value of the parameter.  */
84   union parmpy_variable value;
85
86   /* For an enum command, the possible values.  The vector is
87      allocated with xmalloc, as is each element.  It is
88      NULL-terminated.  */
89   const char **enumeration;
90 };
91
92 /* Wraps a setting around an existing parmpy_object.  This abstraction
93    is used to manipulate the value in S->VALUE in a type safe manner using
94    the setting interface.  */
95
96 static setting
97 make_setting (parmpy_object *s)
98 {
99   if (var_type_uses<bool> (s->type))
100     return setting (s->type, &s->value.boolval);
101   else if (var_type_uses<int> (s->type))
102     return setting (s->type, &s->value.intval);
103   else if (var_type_uses<auto_boolean> (s->type))
104     return setting (s->type, &s->value.autoboolval);
105   else if (var_type_uses<unsigned int> (s->type))
106     return setting (s->type, &s->value.uintval);
107   else if (var_type_uses<std::string> (s->type))
108     return setting (s->type, s->value.stringval);
109   else if (var_type_uses<const char *> (s->type))
110     return setting (s->type, &s->value.cstringval);
111   else
112     gdb_assert_not_reached ("unhandled var type");
113 }
114
115 extern PyTypeObject parmpy_object_type
116     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
117
118 /* Some handy string constants.  */
119 static PyObject *set_doc_cst;
120 static PyObject *show_doc_cst;
121
122 \f
123
124 /* Get an attribute.  */
125 static PyObject *
126 get_attr (PyObject *obj, PyObject *attr_name)
127 {
128   if (PyString_Check (attr_name)
129 #ifdef IS_PY3K
130       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
131 #else
132       && ! strcmp (PyString_AsString (attr_name), "value"))
133 #endif
134     {
135       parmpy_object *self = (parmpy_object *) obj;
136
137       return gdbpy_parameter_value (make_setting (self));
138     }
139
140   return PyObject_GenericGetAttr (obj, attr_name);
141 }
142
143 /* Set a parameter value from a Python value.  Return 0 on success.  Returns
144    -1 on error, with a python exception set.  */
145 static int
146 set_parameter_value (parmpy_object *self, PyObject *value)
147 {
148   int cmp;
149
150   switch (self->type)
151     {
152     case var_string:
153     case var_string_noescape:
154     case var_optional_filename:
155     case var_filename:
156       if (! gdbpy_is_string (value)
157           && (self->type == var_filename
158               || value != Py_None))
159         {
160           PyErr_SetString (PyExc_RuntimeError,
161                            _("String required for filename."));
162
163           return -1;
164         }
165       if (value == Py_None)
166         self->value.stringval->clear ();
167       else
168         {
169           gdb::unique_xmalloc_ptr<char>
170             string (python_string_to_host_string (value));
171           if (string == NULL)
172             return -1;
173
174           *self->value.stringval = string.get ();
175         }
176       break;
177
178     case var_enum:
179       {
180         int i;
181
182         if (! gdbpy_is_string (value))
183           {
184             PyErr_SetString (PyExc_RuntimeError,
185                              _("ENUM arguments must be a string."));
186             return -1;
187           }
188
189         gdb::unique_xmalloc_ptr<char>
190           str (python_string_to_host_string (value));
191         if (str == NULL)
192           return -1;
193         for (i = 0; self->enumeration[i]; ++i)
194           if (! strcmp (self->enumeration[i], str.get ()))
195             break;
196         if (! self->enumeration[i])
197           {
198             PyErr_SetString (PyExc_RuntimeError,
199                              _("The value must be member of an enumeration."));
200             return -1;
201           }
202         self->value.cstringval = self->enumeration[i];
203         break;
204       }
205
206     case var_boolean:
207       if (! PyBool_Check (value))
208         {
209           PyErr_SetString (PyExc_RuntimeError,
210                            _("A boolean argument is required."));
211           return -1;
212         }
213       cmp = PyObject_IsTrue (value);
214       if (cmp < 0)
215           return -1;
216       self->value.boolval = cmp;
217       break;
218
219     case var_auto_boolean:
220       if (! PyBool_Check (value) && value != Py_None)
221         {
222           PyErr_SetString (PyExc_RuntimeError,
223                            _("A boolean or None is required"));
224           return -1;
225         }
226
227       if (value == Py_None)
228         self->value.autoboolval = AUTO_BOOLEAN_AUTO;
229       else
230         {
231           cmp = PyObject_IsTrue (value);
232           if (cmp < 0 )
233             return -1;  
234           if (cmp == 1)
235             self->value.autoboolval = AUTO_BOOLEAN_TRUE;
236           else
237             self->value.autoboolval = AUTO_BOOLEAN_FALSE;
238         }
239       break;
240
241     case var_integer:
242     case var_zinteger:
243     case var_uinteger:
244     case var_zuinteger:
245     case var_zuinteger_unlimited:
246       {
247         long l;
248         int ok;
249
250         if (! PyInt_Check (value))
251           {
252             PyErr_SetString (PyExc_RuntimeError,
253                              _("The value must be integer."));
254             return -1;
255           }
256
257         if (! gdb_py_int_as_long (value, &l))
258           return -1;
259
260         switch (self->type)
261           {
262           case var_uinteger:
263             if (l == 0)
264               l = UINT_MAX;
265             /* Fall through.  */
266           case var_zuinteger:
267             ok = (l >= 0 && l <= UINT_MAX);
268             break;
269
270           case var_zuinteger_unlimited:
271             ok = (l >= -1 && l <= INT_MAX);
272             break;
273
274           case var_integer:
275             ok = (l >= INT_MIN && l <= INT_MAX);
276             if (l == 0)
277               l = INT_MAX;
278             break;
279
280           case var_zinteger:
281             ok = (l >= INT_MIN && l <= INT_MAX);
282             break;
283
284           default:
285             gdb_assert_not_reached ("unknown var_ constant");
286           }
287
288         if (! ok)
289           {
290             PyErr_SetString (PyExc_RuntimeError,
291                              _("Range exceeded."));
292             return -1;
293           }
294
295         if (self->type == var_uinteger || self->type == var_zuinteger)
296           self->value.uintval = (unsigned) l;
297         else
298           self->value.intval = (int) l;
299         break;
300       }
301
302     default:
303       PyErr_SetString (PyExc_RuntimeError,
304                        _("Unhandled type in parameter value."));
305       return -1;
306     }
307
308   return 0;
309 }
310
311 /* Set an attribute.  Returns -1 on error, with a python exception set.  */
312 static int
313 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
314 {
315   if (PyString_Check (attr_name)
316 #ifdef IS_PY3K
317       && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
318 #else
319       && ! strcmp (PyString_AsString (attr_name), "value"))
320 #endif
321     {
322       if (!val)
323         {
324           PyErr_SetString (PyExc_RuntimeError,
325                            _("Cannot delete a parameter's value."));
326           return -1;
327         }
328       return set_parameter_value ((parmpy_object *) obj, val);
329     }
330
331   return PyObject_GenericSetAttr (obj, attr_name, val);
332 }
333
334 /* A helper function which returns a documentation string for an
335    object. */
336
337 static gdb::unique_xmalloc_ptr<char>
338 get_doc_string (PyObject *object, PyObject *attr)
339 {
340   gdb::unique_xmalloc_ptr<char> result;
341
342   if (PyObject_HasAttr (object, attr))
343     {
344       gdbpy_ref<> ds_obj (PyObject_GetAttr (object, attr));
345
346       if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
347         {
348           result = python_string_to_host_string (ds_obj.get ());
349           if (result == NULL)
350             gdbpy_print_stack ();
351         }
352     }
353   if (! result)
354     result.reset (xstrdup (_("This command is not documented.")));
355   return result;
356 }
357
358 /* Helper function which will execute a METHOD in OBJ passing the
359    argument ARG.  ARG can be NULL.  METHOD should return a Python
360    string.  If this function returns NULL, there has been an error and
361    the appropriate exception set.  */
362 static gdb::unique_xmalloc_ptr<char>
363 call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
364 {
365   gdb::unique_xmalloc_ptr<char> data;
366   gdbpy_ref<> result (PyObject_CallMethodObjArgs (obj, method, arg, NULL));
367
368   if (result == NULL)
369     return NULL;
370
371   if (gdbpy_is_string (result.get ()))
372     {
373       data = python_string_to_host_string (result.get ());
374       if (! data)
375         return NULL;
376     }
377   else
378     {
379       PyErr_SetString (PyExc_RuntimeError,
380                        _("Parameter must return a string value."));
381       return NULL;
382     }
383
384   return data;
385 }
386
387 /* A callback function that is registered against the respective
388    add_setshow_* set_doc prototype.  This function calls the Python function
389    "get_set_string" if it exists, which will return a string.  That string
390    is then printed.  If "get_set_string" does not exist, or returns an
391    empty string, then nothing is printed.  */
392 static void
393 get_set_value (const char *args, int from_tty,
394                struct cmd_list_element *c)
395 {
396   PyObject *obj = (PyObject *) c->context ();
397   gdb::unique_xmalloc_ptr<char> set_doc_string;
398
399   gdbpy_enter enter_py (get_current_arch (), current_language);
400   gdbpy_ref<> set_doc_func (PyString_FromString ("get_set_string"));
401
402   if (set_doc_func == NULL)
403     {
404       gdbpy_print_stack ();
405       return;
406     }
407
408   if (PyObject_HasAttr (obj, set_doc_func.get ()))
409     {
410       set_doc_string = call_doc_function (obj, set_doc_func.get (), NULL);
411       if (! set_doc_string)
412         gdbpy_handle_exception ();
413     }
414
415   const char *str = set_doc_string.get ();
416   if (str != nullptr && str[0] != '\0')
417     fprintf_filtered (gdb_stdout, "%s\n", str);
418 }
419
420 /* A callback function that is registered against the respective
421    add_setshow_* show_doc prototype.  This function will either call
422    the Python function "get_show_string" or extract the Python
423    attribute "show_doc" and return the contents as a string.  If
424    neither exist, insert a string indicating the Parameter is not
425    documented.  */
426 static void
427 get_show_value (struct ui_file *file, int from_tty,
428                 struct cmd_list_element *c,
429                 const char *value)
430 {
431   PyObject *obj = (PyObject *) c->context ();
432   gdb::unique_xmalloc_ptr<char> show_doc_string;
433
434   gdbpy_enter enter_py (get_current_arch (), current_language);
435   gdbpy_ref<> show_doc_func (PyString_FromString ("get_show_string"));
436
437   if (show_doc_func == NULL)
438     {
439       gdbpy_print_stack ();
440       return;
441     }
442
443   if (PyObject_HasAttr (obj, show_doc_func.get ()))
444     {
445       gdbpy_ref<> val_obj (PyString_FromString (value));
446
447       if (val_obj == NULL)
448         {
449           gdbpy_print_stack ();
450           return;
451         }
452
453       show_doc_string = call_doc_function (obj, show_doc_func.get (),
454                                            val_obj.get ());
455       if (! show_doc_string)
456         {
457           gdbpy_print_stack ();
458           return;
459         }
460
461       fprintf_filtered (file, "%s\n", show_doc_string.get ());
462     }
463   else
464     {
465       /* We have to preserve the existing < GDB 7.3 API.  If a
466          callback function does not exist, then attempt to read the
467          show_doc attribute.  */
468       show_doc_string  = get_doc_string (obj, show_doc_cst);
469       fprintf_filtered (file, "%s %s\n", show_doc_string.get (), value);
470     }
471 }
472 \f
473
474 /* A helper function that dispatches to the appropriate add_setshow
475    function.  */
476 static void
477 add_setshow_generic (int parmclass, enum command_class cmdclass,
478                      gdb::unique_xmalloc_ptr<char> cmd_name,
479                      parmpy_object *self,
480                      const char *set_doc, const char *show_doc,
481                      const char *help_doc,
482                      struct cmd_list_element **set_list,
483                      struct cmd_list_element **show_list)
484 {
485   set_show_commands commands;
486
487   switch (parmclass)
488     {
489     case var_boolean:
490       commands = add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
491                                           &self->value.boolval, set_doc,
492                                           show_doc, help_doc, get_set_value,
493                                           get_show_value, set_list, show_list);
494
495       break;
496
497     case var_auto_boolean:
498       commands = add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
499                                                &self->value.autoboolval,
500                                                set_doc, show_doc, help_doc,
501                                                get_set_value, get_show_value,
502                                                set_list, show_list);
503       break;
504
505     case var_uinteger:
506       commands = add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
507                                            &self->value.uintval, set_doc,
508                                            show_doc, help_doc, get_set_value,
509                                            get_show_value, set_list, show_list);
510       break;
511
512     case var_integer:
513       commands = add_setshow_integer_cmd (cmd_name.get (), cmdclass,
514                                           &self->value.intval, set_doc,
515                                           show_doc, help_doc, get_set_value,
516                                           get_show_value, set_list, show_list);
517       break;
518
519     case var_string:
520       commands = add_setshow_string_cmd (cmd_name.get (), cmdclass,
521                                          self->value.stringval, set_doc,
522                                          show_doc, help_doc, get_set_value,
523                                          get_show_value, set_list, show_list);
524       break;
525
526     case var_string_noescape:
527       commands = add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
528                                                   self->value.stringval,
529                                                   set_doc, show_doc, help_doc,
530                                                   get_set_value, get_show_value,
531                                                   set_list, show_list);
532       break;
533
534     case var_optional_filename:
535       commands = add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
536                                                     self->value.stringval,
537                                                     set_doc, show_doc, help_doc,
538                                                     get_set_value,
539                                                     get_show_value, set_list,
540                                                     show_list);
541       break;
542
543     case var_filename:
544       commands = add_setshow_filename_cmd (cmd_name.get (), cmdclass,
545                                            self->value.stringval, set_doc,
546                                            show_doc, help_doc, get_set_value,
547                                            get_show_value, set_list, show_list);
548       break;
549
550     case var_zinteger:
551       commands = add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
552                                            &self->value.intval, set_doc,
553                                            show_doc, help_doc, get_set_value,
554                                            get_show_value, set_list, show_list);
555       break;
556
557     case var_zuinteger:
558       commands = add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
559                                             &self->value.uintval, set_doc,
560                                             show_doc, help_doc, get_set_value,
561                                             get_show_value, set_list,
562                                             show_list);
563       break;
564
565     case var_zuinteger_unlimited:
566       commands = add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
567                                                       &self->value.intval,
568                                                       set_doc, show_doc,
569                                                       help_doc, get_set_value,
570                                                       get_show_value, set_list,
571                                                       show_list);
572       break;
573
574     case var_enum:
575       commands = add_setshow_enum_cmd (cmd_name.get (), cmdclass,
576                                        self->enumeration,
577                                        &self->value.cstringval, set_doc,
578                                        show_doc, help_doc, get_set_value,
579                                        get_show_value, set_list, show_list);
580       /* Initialize the value, just in case.  */
581       self->value.cstringval = self->enumeration[0];
582       break;
583
584     default:
585       gdb_assert_not_reached ("Unhandled parameter class.");
586     }
587
588   /* Register Python objects in both commands' context.  */
589   commands.set->set_context (self);
590   commands.show->set_context (self);
591
592   /* We (unfortunately) currently leak the command name.  */
593   cmd_name.release ();
594 }
595
596 /* A helper which computes enum values.  Returns 1 on success.  Returns 0 on
597    error, with a python exception set.  */
598 static int
599 compute_enum_values (parmpy_object *self, PyObject *enum_values)
600 {
601   Py_ssize_t size, i;
602
603   if (! enum_values)
604     {
605       PyErr_SetString (PyExc_RuntimeError,
606                        _("An enumeration is required for PARAM_ENUM."));
607       return 0;
608     }
609
610   if (! PySequence_Check (enum_values))
611     {
612       PyErr_SetString (PyExc_RuntimeError,
613                        _("The enumeration is not a sequence."));
614       return 0;
615     }
616
617   size = PySequence_Size (enum_values);
618   if (size < 0)
619     return 0;
620   if (size == 0)
621     {
622       PyErr_SetString (PyExc_RuntimeError,
623                        _("The enumeration is empty."));
624       return 0;
625     }
626
627   gdb_argv holder (XCNEWVEC (char *, size + 1));
628   char **enumeration = holder.get ();
629
630   for (i = 0; i < size; ++i)
631     {
632       gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
633
634       if (item == NULL)
635         return 0;
636       if (! gdbpy_is_string (item.get ()))
637         {
638           PyErr_SetString (PyExc_RuntimeError,
639                            _("The enumeration item not a string."));
640           return 0;
641         }
642       enumeration[i] = python_string_to_host_string (item.get ()).release ();
643       if (enumeration[i] == NULL)
644         return 0;
645     }
646
647   self->enumeration = const_cast<const char**> (holder.release ());
648   return 1;
649 }
650
651 /* Object initializer; sets up gdb-side structures for command.
652
653    Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
654
655    NAME is the name of the parameter.  It may consist of multiple
656    words, in which case the final word is the name of the new command,
657    and earlier words must be prefix commands.
658
659    CMDCLASS is the kind of command.  It should be one of the COMMAND_*
660    constants defined in the gdb module.
661
662    PARMCLASS is the type of the parameter.  It should be one of the
663    PARAM_* constants defined in the gdb module.
664
665    If PARMCLASS is PARAM_ENUM, then the final argument should be a
666    collection of strings.  These strings are the valid values for this
667    parameter.
668
669    The documentation for the parameter is taken from the doc string
670    for the python class.
671
672    Returns -1 on error, with a python exception set.  */
673
674 static int
675 parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
676 {
677   parmpy_object *obj = (parmpy_object *) self;
678   const char *name;
679   gdb::unique_xmalloc_ptr<char> set_doc, show_doc, doc;
680   int parmclass, cmdtype;
681   PyObject *enum_values = NULL;
682   struct cmd_list_element **set_list, **show_list;
683
684   if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
685                           &enum_values))
686     return -1;
687
688   if (cmdtype != no_class && cmdtype != class_run
689       && cmdtype != class_vars && cmdtype != class_stack
690       && cmdtype != class_files && cmdtype != class_support
691       && cmdtype != class_info && cmdtype != class_breakpoint
692       && cmdtype != class_trace && cmdtype != class_obscure
693       && cmdtype != class_maintenance)
694     {
695       PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
696       return -1;
697     }
698
699   if (parmclass != var_boolean /* ARI: var_boolean */
700       && parmclass != var_auto_boolean
701       && parmclass != var_uinteger && parmclass != var_integer
702       && parmclass != var_string && parmclass != var_string_noescape
703       && parmclass != var_optional_filename && parmclass != var_filename
704       && parmclass != var_zinteger && parmclass != var_zuinteger
705       && parmclass != var_zuinteger_unlimited && parmclass != var_enum)
706     {
707       PyErr_SetString (PyExc_RuntimeError,
708                        _("Invalid parameter class argument."));
709       return -1;
710     }
711
712   if (enum_values && parmclass != var_enum)
713     {
714       PyErr_SetString (PyExc_RuntimeError,
715                        _("Only PARAM_ENUM accepts a fourth argument."));
716       return -1;
717     }
718   if (parmclass == var_enum)
719     {
720       if (! compute_enum_values (obj, enum_values))
721         return -1;
722     }
723   else
724     obj->enumeration = NULL;
725   obj->type = (enum var_types) parmclass;
726   memset (&obj->value, 0, sizeof (obj->value));
727
728   if (var_type_uses<std::string> (obj->type))
729     obj->value.stringval = new std::string;
730
731   gdb::unique_xmalloc_ptr<char> cmd_name
732     = gdbpy_parse_command_name (name, &set_list, &setlist);
733   if (cmd_name == nullptr)
734     return -1;
735
736   cmd_name = gdbpy_parse_command_name (name, &show_list, &showlist);
737   if (cmd_name == nullptr)
738     return -1;
739
740   set_doc = get_doc_string (self, set_doc_cst);
741   show_doc = get_doc_string (self, show_doc_cst);
742   doc = get_doc_string (self, gdbpy_doc_cst);
743
744   Py_INCREF (self);
745
746   try
747     {
748       add_setshow_generic (parmclass, (enum command_class) cmdtype,
749                            std::move (cmd_name), obj,
750                            set_doc.get (), show_doc.get (),
751                            doc.get (), set_list, show_list);
752     }
753   catch (const gdb_exception &except)
754     {
755       Py_DECREF (self);
756       gdbpy_convert_exception (except);
757       return -1;
758     }
759
760   return 0;
761 }
762
763 /* Deallocate function for a gdb.Parameter.  */
764
765 static void
766 parmpy_dealloc (PyObject *obj)
767 {
768   parmpy_object *parm_obj = (parmpy_object *) obj;
769
770   if (var_type_uses<std::string> (parm_obj->type))
771     delete parm_obj->value.stringval;
772 }
773
774 /* Initialize the 'parameters' module.  */
775 int
776 gdbpy_initialize_parameters (void)
777 {
778   int i;
779
780   parmpy_object_type.tp_new = PyType_GenericNew;
781   if (PyType_Ready (&parmpy_object_type) < 0)
782     return -1;
783
784   set_doc_cst = PyString_FromString ("set_doc");
785   if (! set_doc_cst)
786     return -1;
787   show_doc_cst = PyString_FromString ("show_doc");
788   if (! show_doc_cst)
789     return -1;
790
791   for (i = 0; parm_constants[i].name; ++i)
792     {
793       if (PyModule_AddIntConstant (gdb_module,
794                                    parm_constants[i].name,
795                                    parm_constants[i].value) < 0)
796         return -1;
797     }
798
799   return gdb_pymodule_addobject (gdb_module, "Parameter",
800                                  (PyObject *) &parmpy_object_type);
801 }
802
803 \f
804
805 PyTypeObject parmpy_object_type =
806 {
807   PyVarObject_HEAD_INIT (NULL, 0)
808   "gdb.Parameter",                /*tp_name*/
809   sizeof (parmpy_object),         /*tp_basicsize*/
810   0,                              /*tp_itemsize*/
811   parmpy_dealloc,                 /*tp_dealloc*/
812   0,                              /*tp_print*/
813   0,                              /*tp_getattr*/
814   0,                              /*tp_setattr*/
815   0,                              /*tp_compare*/
816   0,                              /*tp_repr*/
817   0,                              /*tp_as_number*/
818   0,                              /*tp_as_sequence*/
819   0,                              /*tp_as_mapping*/
820   0,                              /*tp_hash */
821   0,                              /*tp_call*/
822   0,                              /*tp_str*/
823   get_attr,                       /*tp_getattro*/
824   set_attr,                       /*tp_setattro*/
825   0,                              /*tp_as_buffer*/
826   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
827   "GDB parameter object",         /* tp_doc */
828   0,                              /* tp_traverse */
829   0,                              /* tp_clear */
830   0,                              /* tp_richcompare */
831   0,                              /* tp_weaklistoffset */
832   0,                              /* tp_iter */
833   0,                              /* tp_iternext */
834   0,                              /* tp_methods */
835   0,                              /* tp_members */
836   0,                              /* tp_getset */
837   0,                              /* tp_base */
838   0,                              /* tp_dict */
839   0,                              /* tp_descr_get */
840   0,                              /* tp_descr_set */
841   0,                              /* tp_dictoffset */
842   parmpy_init,                    /* tp_init */
843   0,                              /* tp_alloc */
844 };
This page took 0.076053 seconds and 4 git commands to generate.