manual copyright year range of various GDB files to add 2023
[binutils-gdb.git] / gdb / python / py-param.c
blob2771bf4bf0ac10d6db6496907e5ffd392b261b83
1 /* GDB parameters implemented in Python
3 Copyright (C) 2008-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
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"
31 /* Parameter constants and their values. */
32 static struct {
33 const char *name;
34 int value;
35 } parm_constants[] =
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 }
52 /* A union that can hold anything described by enum var_types. */
53 union parmpy_variable
55 /* Hold a boolean value. */
56 bool boolval;
58 /* Hold an integer value. */
59 int intval;
61 /* Hold an auto_boolean. */
62 enum auto_boolean autoboolval;
64 /* Hold an unsigned integer value, for uinteger. */
65 unsigned int uintval;
67 /* Hold a string, for the various string types. The std::string is
68 new-ed. */
69 std::string *stringval;
71 /* Hold a string, for enums. */
72 const char *cstringval;
75 /* A GDB parameter. */
76 struct parmpy_object
78 PyObject_HEAD
80 /* The type of the parameter. */
81 enum var_types type;
83 /* The value of the parameter. */
84 union parmpy_variable value;
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;
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. */
96 static setting
97 make_setting (parmpy_object *s)
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");
115 extern PyTypeObject parmpy_object_type
116 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
118 /* Some handy string constants. */
119 static PyObject *set_doc_cst;
120 static PyObject *show_doc_cst;
124 /* Get an attribute. */
125 static PyObject *
126 get_attr (PyObject *obj, PyObject *attr_name)
128 if (PyUnicode_Check (attr_name)
129 && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
131 parmpy_object *self = (parmpy_object *) obj;
133 return gdbpy_parameter_value (make_setting (self));
136 return PyObject_GenericGetAttr (obj, attr_name);
139 /* Set a parameter value from a Python value. Return 0 on success. Returns
140 -1 on error, with a python exception set. */
141 static int
142 set_parameter_value (parmpy_object *self, PyObject *value)
144 int cmp;
146 switch (self->type)
148 case var_string:
149 case var_string_noescape:
150 case var_optional_filename:
151 case var_filename:
152 if (! gdbpy_is_string (value)
153 && (self->type == var_filename
154 || value != Py_None))
156 PyErr_SetString (PyExc_RuntimeError,
157 _("String required for filename."));
159 return -1;
161 if (value == Py_None)
162 self->value.stringval->clear ();
163 else
165 gdb::unique_xmalloc_ptr<char>
166 string (python_string_to_host_string (value));
167 if (string == NULL)
168 return -1;
170 *self->value.stringval = string.get ();
172 break;
174 case var_enum:
176 int i;
178 if (! gdbpy_is_string (value))
180 PyErr_SetString (PyExc_RuntimeError,
181 _("ENUM arguments must be a string."));
182 return -1;
185 gdb::unique_xmalloc_ptr<char>
186 str (python_string_to_host_string (value));
187 if (str == NULL)
188 return -1;
189 for (i = 0; self->enumeration[i]; ++i)
190 if (! strcmp (self->enumeration[i], str.get ()))
191 break;
192 if (! self->enumeration[i])
194 PyErr_SetString (PyExc_RuntimeError,
195 _("The value must be member of an enumeration."));
196 return -1;
198 self->value.cstringval = self->enumeration[i];
199 break;
202 case var_boolean:
203 if (! PyBool_Check (value))
205 PyErr_SetString (PyExc_RuntimeError,
206 _("A boolean argument is required."));
207 return -1;
209 cmp = PyObject_IsTrue (value);
210 if (cmp < 0)
211 return -1;
212 self->value.boolval = cmp;
213 break;
215 case var_auto_boolean:
216 if (! PyBool_Check (value) && value != Py_None)
218 PyErr_SetString (PyExc_RuntimeError,
219 _("A boolean or None is required"));
220 return -1;
223 if (value == Py_None)
224 self->value.autoboolval = AUTO_BOOLEAN_AUTO;
225 else
227 cmp = PyObject_IsTrue (value);
228 if (cmp < 0 )
229 return -1;
230 if (cmp == 1)
231 self->value.autoboolval = AUTO_BOOLEAN_TRUE;
232 else
233 self->value.autoboolval = AUTO_BOOLEAN_FALSE;
235 break;
237 case var_integer:
238 case var_zinteger:
239 case var_uinteger:
240 case var_zuinteger:
241 case var_zuinteger_unlimited:
243 long l;
244 int ok;
246 if (value == Py_None
247 && (self->type == var_uinteger || self->type == var_integer))
248 l = 0;
249 else if (value == Py_None && self->type == var_zuinteger_unlimited)
250 l = -1;
251 else if (!PyLong_Check (value))
253 PyErr_SetString (PyExc_RuntimeError,
254 _("The value must be integer."));
255 return -1;
257 else if (! gdb_py_int_as_long (value, &l))
258 return -1;
260 switch (self->type)
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;
270 case var_zuinteger_unlimited:
271 ok = (l >= -1 && l <= INT_MAX);
272 break;
274 case var_integer:
275 ok = (l >= INT_MIN && l <= INT_MAX);
276 if (l == 0)
277 l = INT_MAX;
278 break;
280 case var_zinteger:
281 ok = (l >= INT_MIN && l <= INT_MAX);
282 break;
284 default:
285 gdb_assert_not_reached ("unknown var_ constant");
288 if (! ok)
290 PyErr_SetString (PyExc_RuntimeError,
291 _("Range exceeded."));
292 return -1;
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;
302 default:
303 PyErr_SetString (PyExc_RuntimeError,
304 _("Unhandled type in parameter value."));
305 return -1;
308 return 0;
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)
315 if (PyUnicode_Check (attr_name)
316 && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
318 if (!val)
320 PyErr_SetString (PyExc_RuntimeError,
321 _("Cannot delete a parameter's value."));
322 return -1;
324 return set_parameter_value ((parmpy_object *) obj, val);
327 return PyObject_GenericSetAttr (obj, attr_name, val);
330 /* Build up the path to command C, but drop the first component of the
331 command prefix. This is only intended for use with the set/show
332 parameters this file deals with, the first prefix should always be
333 either 'set' or 'show'.
335 As an example, if this full command is 'set prefix_a prefix_b command'
336 this function will return the string 'prefix_a prefix_b command'. */
338 static std::string
339 full_cmd_name_without_first_prefix (struct cmd_list_element *c)
341 std::vector<std::string> components
342 = c->command_components ();
343 gdb_assert (components.size () > 1);
344 std::string result = components[1];
345 for (int i = 2; i < components.size (); ++i)
346 result += " " + components[i];
347 return result;
350 /* The different types of documentation string. */
352 enum doc_string_type
354 doc_string_set,
355 doc_string_show,
356 doc_string_description
359 /* A helper function which returns a documentation string for an
360 object. */
362 static gdb::unique_xmalloc_ptr<char>
363 get_doc_string (PyObject *object, enum doc_string_type doc_type,
364 const char *cmd_name)
366 gdb::unique_xmalloc_ptr<char> result;
368 PyObject *attr = nullptr;
369 switch (doc_type)
371 case doc_string_set:
372 attr = set_doc_cst;
373 break;
374 case doc_string_show:
375 attr = show_doc_cst;
376 break;
377 case doc_string_description:
378 attr = gdbpy_doc_cst;
379 break;
381 gdb_assert (attr != nullptr);
383 if (PyObject_HasAttr (object, attr))
385 gdbpy_ref<> ds_obj (PyObject_GetAttr (object, attr));
387 if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
389 result = python_string_to_host_string (ds_obj.get ());
390 if (result == NULL)
391 gdbpy_print_stack ();
392 else if (doc_type == doc_string_description)
393 result = gdbpy_fix_doc_string_indentation (std::move (result));
397 if (result == nullptr)
399 if (doc_type == doc_string_description)
400 result.reset (xstrdup (_("This command is not documented.")));
401 else
403 if (doc_type == doc_string_show)
404 result = xstrprintf (_("Show the current value of '%s'."),
405 cmd_name);
406 else
407 result = xstrprintf (_("Set the current value of '%s'."),
408 cmd_name);
411 return result;
414 /* Helper function which will execute a METHOD in OBJ passing the
415 argument ARG. ARG can be NULL. METHOD should return a Python
416 string. If this function returns NULL, there has been an error and
417 the appropriate exception set. */
418 static gdb::unique_xmalloc_ptr<char>
419 call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
421 gdb::unique_xmalloc_ptr<char> data;
422 gdbpy_ref<> result (PyObject_CallMethodObjArgs (obj, method, arg, NULL));
424 if (result == NULL)
425 return NULL;
427 if (gdbpy_is_string (result.get ()))
429 data = python_string_to_host_string (result.get ());
430 if (! data)
431 return NULL;
433 else
435 PyErr_SetString (PyExc_RuntimeError,
436 _("Parameter must return a string value."));
437 return NULL;
440 return data;
443 /* A callback function that is registered against the respective
444 add_setshow_* set_doc prototype. This function calls the Python function
445 "get_set_string" if it exists, which will return a string. That string
446 is then printed. If "get_set_string" does not exist, or returns an
447 empty string, then nothing is printed. */
448 static void
449 get_set_value (const char *args, int from_tty,
450 struct cmd_list_element *c)
452 PyObject *obj = (PyObject *) c->context ();
453 gdb::unique_xmalloc_ptr<char> set_doc_string;
455 gdbpy_enter enter_py;
456 gdbpy_ref<> set_doc_func (PyUnicode_FromString ("get_set_string"));
458 if (set_doc_func == NULL)
460 gdbpy_print_stack ();
461 return;
464 if (PyObject_HasAttr (obj, set_doc_func.get ()))
466 set_doc_string = call_doc_function (obj, set_doc_func.get (), NULL);
467 if (! set_doc_string)
468 gdbpy_handle_exception ();
471 const char *str = set_doc_string.get ();
472 if (str != nullptr && str[0] != '\0')
473 gdb_printf ("%s\n", str);
476 /* A callback function that is registered against the respective
477 add_setshow_* show_doc prototype. This function will either call
478 the Python function "get_show_string" or extract the Python
479 attribute "show_doc" and return the contents as a string. If
480 neither exist, insert a string indicating the Parameter is not
481 documented. */
482 static void
483 get_show_value (struct ui_file *file, int from_tty,
484 struct cmd_list_element *c,
485 const char *value)
487 PyObject *obj = (PyObject *) c->context ();
488 gdb::unique_xmalloc_ptr<char> show_doc_string;
490 gdbpy_enter enter_py;
491 gdbpy_ref<> show_doc_func (PyUnicode_FromString ("get_show_string"));
493 if (show_doc_func == NULL)
495 gdbpy_print_stack ();
496 return;
499 if (PyObject_HasAttr (obj, show_doc_func.get ()))
501 gdbpy_ref<> val_obj (PyUnicode_FromString (value));
503 if (val_obj == NULL)
505 gdbpy_print_stack ();
506 return;
509 show_doc_string = call_doc_function (obj, show_doc_func.get (),
510 val_obj.get ());
511 if (! show_doc_string)
513 gdbpy_print_stack ();
514 return;
517 gdb_printf (file, "%s\n", show_doc_string.get ());
519 else
521 /* If there is no 'get_show_string' callback then we want to show
522 something sensible here. In older versions of GDB (< 7.3) we
523 didn't support 'get_show_string', and instead we just made use of
524 GDB's builtin use of the show_doc. However, GDB's builtin
525 show_doc adjustment is not i18n friendly, so, instead, we just
526 print this generic string. */
527 std::string cmd_path = full_cmd_name_without_first_prefix (c);
528 gdb_printf (file, _("The current value of '%s' is \"%s\".\n"),
529 cmd_path.c_str (), value);
534 /* A helper function that dispatches to the appropriate add_setshow
535 function. */
536 static void
537 add_setshow_generic (int parmclass, enum command_class cmdclass,
538 gdb::unique_xmalloc_ptr<char> cmd_name,
539 parmpy_object *self,
540 const char *set_doc, const char *show_doc,
541 const char *help_doc,
542 struct cmd_list_element **set_list,
543 struct cmd_list_element **show_list)
545 set_show_commands commands;
547 switch (parmclass)
549 case var_boolean:
550 commands = add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
551 &self->value.boolval, set_doc,
552 show_doc, help_doc, get_set_value,
553 get_show_value, set_list, show_list);
555 break;
557 case var_auto_boolean:
558 commands = add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
559 &self->value.autoboolval,
560 set_doc, show_doc, help_doc,
561 get_set_value, get_show_value,
562 set_list, show_list);
563 break;
565 case var_uinteger:
566 commands = add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
567 &self->value.uintval, set_doc,
568 show_doc, help_doc, get_set_value,
569 get_show_value, set_list, show_list);
570 break;
572 case var_integer:
573 commands = add_setshow_integer_cmd (cmd_name.get (), cmdclass,
574 &self->value.intval, set_doc,
575 show_doc, help_doc, get_set_value,
576 get_show_value, set_list, show_list);
577 break;
579 case var_string:
580 commands = add_setshow_string_cmd (cmd_name.get (), cmdclass,
581 self->value.stringval, set_doc,
582 show_doc, help_doc, get_set_value,
583 get_show_value, set_list, show_list);
584 break;
586 case var_string_noescape:
587 commands = add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
588 self->value.stringval,
589 set_doc, show_doc, help_doc,
590 get_set_value, get_show_value,
591 set_list, show_list);
592 break;
594 case var_optional_filename:
595 commands = add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
596 self->value.stringval,
597 set_doc, show_doc, help_doc,
598 get_set_value,
599 get_show_value, set_list,
600 show_list);
601 break;
603 case var_filename:
604 commands = add_setshow_filename_cmd (cmd_name.get (), cmdclass,
605 self->value.stringval, set_doc,
606 show_doc, help_doc, get_set_value,
607 get_show_value, set_list, show_list);
608 break;
610 case var_zinteger:
611 commands = add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
612 &self->value.intval, set_doc,
613 show_doc, help_doc, get_set_value,
614 get_show_value, set_list, show_list);
615 break;
617 case var_zuinteger:
618 commands = add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
619 &self->value.uintval, set_doc,
620 show_doc, help_doc, get_set_value,
621 get_show_value, set_list,
622 show_list);
623 break;
625 case var_zuinteger_unlimited:
626 commands = add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
627 &self->value.intval,
628 set_doc, show_doc,
629 help_doc, get_set_value,
630 get_show_value, set_list,
631 show_list);
632 break;
634 case var_enum:
635 /* Initialize the value, just in case. */
636 self->value.cstringval = self->enumeration[0];
637 commands = add_setshow_enum_cmd (cmd_name.get (), cmdclass,
638 self->enumeration,
639 &self->value.cstringval, set_doc,
640 show_doc, help_doc, get_set_value,
641 get_show_value, set_list, show_list);
642 break;
644 default:
645 gdb_assert_not_reached ("Unhandled parameter class.");
648 /* Register Python objects in both commands' context. */
649 commands.set->set_context (self);
650 commands.show->set_context (self);
652 /* We (unfortunately) currently leak the command name. */
653 cmd_name.release ();
656 /* A helper which computes enum values. Returns 1 on success. Returns 0 on
657 error, with a python exception set. */
658 static int
659 compute_enum_values (parmpy_object *self, PyObject *enum_values)
661 Py_ssize_t size, i;
663 if (! enum_values)
665 PyErr_SetString (PyExc_RuntimeError,
666 _("An enumeration is required for PARAM_ENUM."));
667 return 0;
670 if (! PySequence_Check (enum_values))
672 PyErr_SetString (PyExc_RuntimeError,
673 _("The enumeration is not a sequence."));
674 return 0;
677 size = PySequence_Size (enum_values);
678 if (size < 0)
679 return 0;
680 if (size == 0)
682 PyErr_SetString (PyExc_RuntimeError,
683 _("The enumeration is empty."));
684 return 0;
687 gdb_argv holder (XCNEWVEC (char *, size + 1));
688 char **enumeration = holder.get ();
690 for (i = 0; i < size; ++i)
692 gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
694 if (item == NULL)
695 return 0;
696 if (! gdbpy_is_string (item.get ()))
698 PyErr_SetString (PyExc_RuntimeError,
699 _("The enumeration item not a string."));
700 return 0;
702 enumeration[i] = python_string_to_host_string (item.get ()).release ();
703 if (enumeration[i] == NULL)
704 return 0;
707 self->enumeration = const_cast<const char**> (holder.release ());
708 return 1;
711 /* Object initializer; sets up gdb-side structures for command.
713 Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
715 NAME is the name of the parameter. It may consist of multiple
716 words, in which case the final word is the name of the new command,
717 and earlier words must be prefix commands.
719 CMDCLASS is the kind of command. It should be one of the COMMAND_*
720 constants defined in the gdb module.
722 PARMCLASS is the type of the parameter. It should be one of the
723 PARAM_* constants defined in the gdb module.
725 If PARMCLASS is PARAM_ENUM, then the final argument should be a
726 collection of strings. These strings are the valid values for this
727 parameter.
729 The documentation for the parameter is taken from the doc string
730 for the python class.
732 Returns -1 on error, with a python exception set. */
734 static int
735 parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
737 parmpy_object *obj = (parmpy_object *) self;
738 const char *name;
739 gdb::unique_xmalloc_ptr<char> set_doc, show_doc, doc;
740 int parmclass, cmdtype;
741 PyObject *enum_values = NULL;
742 struct cmd_list_element **set_list, **show_list;
744 if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
745 &enum_values))
746 return -1;
748 if (cmdtype != no_class && cmdtype != class_run
749 && cmdtype != class_vars && cmdtype != class_stack
750 && cmdtype != class_files && cmdtype != class_support
751 && cmdtype != class_info && cmdtype != class_breakpoint
752 && cmdtype != class_trace && cmdtype != class_obscure
753 && cmdtype != class_maintenance)
755 PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
756 return -1;
759 if (parmclass != var_boolean /* ARI: var_boolean */
760 && parmclass != var_auto_boolean
761 && parmclass != var_uinteger && parmclass != var_integer
762 && parmclass != var_string && parmclass != var_string_noescape
763 && parmclass != var_optional_filename && parmclass != var_filename
764 && parmclass != var_zinteger && parmclass != var_zuinteger
765 && parmclass != var_zuinteger_unlimited && parmclass != var_enum)
767 PyErr_SetString (PyExc_RuntimeError,
768 _("Invalid parameter class argument."));
769 return -1;
772 if (enum_values && parmclass != var_enum)
774 PyErr_SetString (PyExc_RuntimeError,
775 _("Only PARAM_ENUM accepts a fourth argument."));
776 return -1;
778 if (parmclass == var_enum)
780 if (! compute_enum_values (obj, enum_values))
781 return -1;
783 else
784 obj->enumeration = NULL;
785 obj->type = (enum var_types) parmclass;
786 memset (&obj->value, 0, sizeof (obj->value));
788 if (var_type_uses<std::string> (obj->type))
789 obj->value.stringval = new std::string;
791 gdb::unique_xmalloc_ptr<char> cmd_name
792 = gdbpy_parse_command_name (name, &set_list, &setlist);
793 if (cmd_name == nullptr)
794 return -1;
796 cmd_name = gdbpy_parse_command_name (name, &show_list, &showlist);
797 if (cmd_name == nullptr)
798 return -1;
800 set_doc = get_doc_string (self, doc_string_set, name);
801 show_doc = get_doc_string (self, doc_string_show, name);
802 doc = get_doc_string (self, doc_string_description, cmd_name.get ());
804 Py_INCREF (self);
808 add_setshow_generic (parmclass, (enum command_class) cmdtype,
809 std::move (cmd_name), obj,
810 set_doc.get (), show_doc.get (),
811 doc.get (), set_list, show_list);
813 catch (const gdb_exception &except)
815 Py_DECREF (self);
816 gdbpy_convert_exception (except);
817 return -1;
820 return 0;
823 /* Deallocate function for a gdb.Parameter. */
825 static void
826 parmpy_dealloc (PyObject *obj)
828 parmpy_object *parm_obj = (parmpy_object *) obj;
830 if (var_type_uses<std::string> (parm_obj->type))
831 delete parm_obj->value.stringval;
834 /* Initialize the 'parameters' module. */
836 gdbpy_initialize_parameters (void)
838 int i;
840 parmpy_object_type.tp_new = PyType_GenericNew;
841 if (PyType_Ready (&parmpy_object_type) < 0)
842 return -1;
844 set_doc_cst = PyUnicode_FromString ("set_doc");
845 if (! set_doc_cst)
846 return -1;
847 show_doc_cst = PyUnicode_FromString ("show_doc");
848 if (! show_doc_cst)
849 return -1;
851 for (i = 0; parm_constants[i].name; ++i)
853 if (PyModule_AddIntConstant (gdb_module,
854 parm_constants[i].name,
855 parm_constants[i].value) < 0)
856 return -1;
859 return gdb_pymodule_addobject (gdb_module, "Parameter",
860 (PyObject *) &parmpy_object_type);
865 PyTypeObject parmpy_object_type =
867 PyVarObject_HEAD_INIT (NULL, 0)
868 "gdb.Parameter", /*tp_name*/
869 sizeof (parmpy_object), /*tp_basicsize*/
870 0, /*tp_itemsize*/
871 parmpy_dealloc, /*tp_dealloc*/
872 0, /*tp_print*/
873 0, /*tp_getattr*/
874 0, /*tp_setattr*/
875 0, /*tp_compare*/
876 0, /*tp_repr*/
877 0, /*tp_as_number*/
878 0, /*tp_as_sequence*/
879 0, /*tp_as_mapping*/
880 0, /*tp_hash */
881 0, /*tp_call*/
882 0, /*tp_str*/
883 get_attr, /*tp_getattro*/
884 set_attr, /*tp_setattro*/
885 0, /*tp_as_buffer*/
886 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
887 "GDB parameter object", /* tp_doc */
888 0, /* tp_traverse */
889 0, /* tp_clear */
890 0, /* tp_richcompare */
891 0, /* tp_weaklistoffset */
892 0, /* tp_iter */
893 0, /* tp_iternext */
894 0, /* tp_methods */
895 0, /* tp_members */
896 0, /* tp_getset */
897 0, /* tp_base */
898 0, /* tp_dict */
899 0, /* tp_descr_get */
900 0, /* tp_descr_set */
901 0, /* tp_dictoffset */
902 parmpy_init, /* tp_init */
903 0, /* tp_alloc */