1 /* GDB parameters implemented in Python
3 Copyright (C) 2008-2024 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/>. */
22 #include "python-internal.h"
24 #include "cli/cli-cmds.h"
25 #include "cli/cli-decode.h"
26 #include "completer.h"
28 #include "arch-utils.h"
30 /* Python parameter types as in PARM_CONSTANTS below. */
39 param_string_noescape
,
40 param_optional_filename
,
44 param_zuinteger_unlimited
,
48 /* Translation from Python parameters to GDB variable types. Keep in the
49 same order as PARAM_TYPES due to C++'s lack of designated initializers. */
53 /* The type of the parameter. */
56 /* Extra literals, such as `unlimited', accepted in lieu of a number. */
57 const literal_def
*extra_literals
;
63 { var_uinteger
, uinteger_unlimited_literals
},
64 { var_integer
, integer_unlimited_literals
},
66 { var_string_noescape
},
67 { var_optional_filename
},
71 { var_pinteger
, pinteger_unlimited_literals
},
75 /* Parameter constants and their values. */
81 { "PARAM_BOOLEAN", param_boolean
}, /* ARI: param_boolean */
82 { "PARAM_AUTO_BOOLEAN", param_auto_boolean
},
83 { "PARAM_UINTEGER", param_uinteger
},
84 { "PARAM_INTEGER", param_integer
},
85 { "PARAM_STRING", param_string
},
86 { "PARAM_STRING_NOESCAPE", param_string_noescape
},
87 { "PARAM_OPTIONAL_FILENAME", param_optional_filename
},
88 { "PARAM_FILENAME", param_filename
},
89 { "PARAM_ZINTEGER", param_zinteger
},
90 { "PARAM_ZUINTEGER", param_zuinteger
},
91 { "PARAM_ZUINTEGER_UNLIMITED", param_zuinteger_unlimited
},
92 { "PARAM_ENUM", param_enum
},
96 /* A union that can hold anything described by enum var_types. */
99 /* Hold a boolean value. */
102 /* Hold an integer value. */
105 /* Hold an auto_boolean. */
106 enum auto_boolean autoboolval
;
108 /* Hold an unsigned integer value, for uinteger. */
109 unsigned int uintval
;
111 /* Hold a string, for the various string types. The std::string is
113 std::string
*stringval
;
115 /* Hold a string, for enums. */
116 const char *cstringval
;
119 /* A GDB parameter. */
124 /* The type of the parameter. */
127 /* Extra literals, such as `unlimited', accepted in lieu of a number. */
128 const literal_def
*extra_literals
;
130 /* The value of the parameter. */
131 union parmpy_variable value
;
133 /* For an enum command, the possible values. The vector is
134 allocated with xmalloc, as is each element. It is
136 const char **enumeration
;
139 /* Wraps a setting around an existing parmpy_object. This abstraction
140 is used to manipulate the value in S->VALUE in a type safe manner using
141 the setting interface. */
144 make_setting (parmpy_object
*s
)
146 enum var_types type
= s
->type
;
148 if (var_type_uses
<bool> (type
))
149 return setting (type
, &s
->value
.boolval
);
150 else if (var_type_uses
<int> (type
))
151 return setting (type
, &s
->value
.intval
, s
->extra_literals
);
152 else if (var_type_uses
<auto_boolean
> (type
))
153 return setting (type
, &s
->value
.autoboolval
);
154 else if (var_type_uses
<unsigned int> (type
))
155 return setting (type
, &s
->value
.uintval
, s
->extra_literals
);
156 else if (var_type_uses
<std::string
> (type
))
157 return setting (type
, s
->value
.stringval
);
158 else if (var_type_uses
<const char *> (type
))
159 return setting (type
, &s
->value
.cstringval
);
161 gdb_assert_not_reached ("unhandled var type");
164 extern PyTypeObject parmpy_object_type
165 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
167 /* Some handy string constants. */
168 static PyObject
*set_doc_cst
;
169 static PyObject
*show_doc_cst
;
173 /* Get an attribute. */
175 get_attr (PyObject
*obj
, PyObject
*attr_name
)
177 if (PyUnicode_Check (attr_name
)
178 && ! PyUnicode_CompareWithASCIIString (attr_name
, "value"))
180 parmpy_object
*self
= (parmpy_object
*) obj
;
182 return gdbpy_parameter_value (make_setting (self
));
185 return PyObject_GenericGetAttr (obj
, attr_name
);
188 /* Set a parameter value from a Python value. Return 0 on success. Returns
189 -1 on error, with a python exception set. */
191 set_parameter_value (parmpy_object
*self
, PyObject
*value
)
198 case var_string_noescape
:
199 case var_optional_filename
:
201 if (! gdbpy_is_string (value
)
202 && (self
->type
== var_filename
203 || value
!= Py_None
))
205 PyErr_SetString (PyExc_RuntimeError
,
206 _("String required for filename."));
210 if (value
== Py_None
)
211 self
->value
.stringval
->clear ();
214 gdb::unique_xmalloc_ptr
<char>
215 string (python_string_to_host_string (value
));
219 *self
->value
.stringval
= string
.get ();
227 if (! gdbpy_is_string (value
))
229 PyErr_SetString (PyExc_RuntimeError
,
230 _("ENUM arguments must be a string."));
234 gdb::unique_xmalloc_ptr
<char>
235 str (python_string_to_host_string (value
));
238 for (i
= 0; self
->enumeration
[i
]; ++i
)
239 if (! strcmp (self
->enumeration
[i
], str
.get ()))
241 if (! self
->enumeration
[i
])
243 PyErr_SetString (PyExc_RuntimeError
,
244 _("The value must be member of an enumeration."));
247 self
->value
.cstringval
= self
->enumeration
[i
];
252 if (! PyBool_Check (value
))
254 PyErr_SetString (PyExc_RuntimeError
,
255 _("A boolean argument is required."));
258 cmp
= PyObject_IsTrue (value
);
261 self
->value
.boolval
= cmp
;
264 case var_auto_boolean
:
265 if (! PyBool_Check (value
) && value
!= Py_None
)
267 PyErr_SetString (PyExc_RuntimeError
,
268 _("A boolean or None is required"));
272 if (value
== Py_None
)
273 self
->value
.autoboolval
= AUTO_BOOLEAN_AUTO
;
276 cmp
= PyObject_IsTrue (value
);
280 self
->value
.autoboolval
= AUTO_BOOLEAN_TRUE
;
282 self
->value
.autoboolval
= AUTO_BOOLEAN_FALSE
;
290 const literal_def
*extra_literals
= self
->extra_literals
;
291 enum tribool allowed
= TRIBOOL_UNKNOWN
;
292 enum var_types var_type
= self
->type
;
293 std::string buffer
= "";
297 if (extra_literals
!= nullptr)
299 gdb::unique_xmalloc_ptr
<char>
300 str (python_string_to_host_string (value
));
301 const char *s
= str
!= nullptr ? str
.get () : nullptr;
304 for (const literal_def
*l
= extra_literals
;
305 l
->literal
!= nullptr;
310 buffer
= buffer
+ "'" + l
->literal
+ "'";
311 if (allowed
== TRIBOOL_UNKNOWN
312 && ((value
== Py_None
&& !strcmp ("unlimited", l
->literal
))
313 || (s
!= nullptr && !strcmp (s
, l
->literal
))))
316 allowed
= TRIBOOL_TRUE
;
321 if (allowed
== TRIBOOL_UNKNOWN
)
323 val
= PyLong_AsLongLong (value
);
325 if (PyErr_Occurred ())
327 if (extra_literals
== nullptr)
328 PyErr_SetString (PyExc_RuntimeError
,
329 _("The value must be integer."));
331 PyErr_SetString (PyExc_RuntimeError
,
332 string_printf (_("integer or one of: %s"),
333 buffer
.c_str ()).c_str ());
335 PyErr_SetString (PyExc_RuntimeError
,
336 string_printf (_("integer or %s"),
337 buffer
.c_str ()).c_str ());
342 if (extra_literals
!= nullptr)
343 for (const literal_def
*l
= extra_literals
;
344 l
->literal
!= nullptr;
347 if (l
->val
.has_value () && val
== *l
->val
)
349 allowed
= TRIBOOL_TRUE
;
353 else if (val
== l
->use
)
354 allowed
= TRIBOOL_FALSE
;
358 if (allowed
== TRIBOOL_UNKNOWN
)
360 if (val
> UINT_MAX
|| val
< INT_MIN
361 || (var_type
== var_uinteger
&& val
< 0)
362 || (var_type
== var_integer
&& val
> INT_MAX
)
363 || (var_type
== var_pinteger
&& val
< 0)
364 || (var_type
== var_pinteger
&& val
> INT_MAX
))
365 allowed
= TRIBOOL_FALSE
;
367 if (allowed
== TRIBOOL_FALSE
)
369 PyErr_SetString (PyExc_RuntimeError
,
370 _("Range exceeded."));
374 if (self
->type
== var_uinteger
)
375 self
->value
.uintval
= (unsigned) val
;
377 self
->value
.intval
= (int) val
;
382 PyErr_SetString (PyExc_RuntimeError
,
383 _("Unhandled type in parameter value."));
390 /* Set an attribute. Returns -1 on error, with a python exception set. */
392 set_attr (PyObject
*obj
, PyObject
*attr_name
, PyObject
*val
)
394 if (PyUnicode_Check (attr_name
)
395 && ! PyUnicode_CompareWithASCIIString (attr_name
, "value"))
399 PyErr_SetString (PyExc_RuntimeError
,
400 _("Cannot delete a parameter's value."));
403 return set_parameter_value ((parmpy_object
*) obj
, val
);
406 return PyObject_GenericSetAttr (obj
, attr_name
, val
);
409 /* Build up the path to command C, but drop the first component of the
410 command prefix. This is only intended for use with the set/show
411 parameters this file deals with, the first prefix should always be
412 either 'set' or 'show'.
414 As an example, if this full command is 'set prefix_a prefix_b command'
415 this function will return the string 'prefix_a prefix_b command'. */
418 full_cmd_name_without_first_prefix (struct cmd_list_element
*c
)
420 std::vector
<std::string
> components
421 = c
->command_components ();
422 gdb_assert (components
.size () > 1);
423 std::string result
= components
[1];
424 for (int i
= 2; i
< components
.size (); ++i
)
425 result
+= " " + components
[i
];
429 /* The different types of documentation string. */
435 doc_string_description
438 /* A helper function which returns a documentation string for an
441 static gdb::unique_xmalloc_ptr
<char>
442 get_doc_string (PyObject
*object
, enum doc_string_type doc_type
,
443 const char *cmd_name
)
445 gdb::unique_xmalloc_ptr
<char> result
;
447 PyObject
*attr
= nullptr;
453 case doc_string_show
:
456 case doc_string_description
:
457 attr
= gdbpy_doc_cst
;
460 gdb_assert (attr
!= nullptr);
462 if (PyObject_HasAttr (object
, attr
))
464 gdbpy_ref
<> ds_obj (PyObject_GetAttr (object
, attr
));
466 if (ds_obj
!= NULL
&& gdbpy_is_string (ds_obj
.get ()))
468 result
= python_string_to_host_string (ds_obj
.get ());
470 gdbpy_print_stack ();
471 else if (doc_type
== doc_string_description
)
472 result
= gdbpy_fix_doc_string_indentation (std::move (result
));
476 if (result
== nullptr)
478 if (doc_type
== doc_string_description
)
479 result
.reset (xstrdup (_("This command is not documented.")));
482 if (doc_type
== doc_string_show
)
483 result
= xstrprintf (_("Show the current value of '%s'."),
486 result
= xstrprintf (_("Set the current value of '%s'."),
493 /* Helper function which will execute a METHOD in OBJ passing the
494 argument ARG. ARG can be NULL. METHOD should return a Python
495 string. If this function returns NULL, there has been an error and
496 the appropriate exception set. */
497 static gdb::unique_xmalloc_ptr
<char>
498 call_doc_function (PyObject
*obj
, PyObject
*method
, PyObject
*arg
)
500 gdb::unique_xmalloc_ptr
<char> data
;
501 gdbpy_ref
<> result (PyObject_CallMethodObjArgs (obj
, method
, arg
, NULL
));
506 if (gdbpy_is_string (result
.get ()))
508 data
= python_string_to_host_string (result
.get ());
514 PyErr_SetString (PyExc_RuntimeError
,
515 _("Parameter must return a string value."));
522 /* A callback function that is registered against the respective
523 add_setshow_* set_doc prototype. This function calls the Python function
524 "get_set_string" if it exists, which will return a string. That string
525 is then printed. If "get_set_string" does not exist, or returns an
526 empty string, then nothing is printed. */
528 get_set_value (const char *args
, int from_tty
,
529 struct cmd_list_element
*c
)
531 PyObject
*obj
= (PyObject
*) c
->context ();
532 gdb::unique_xmalloc_ptr
<char> set_doc_string
;
534 gdbpy_enter enter_py
;
535 gdbpy_ref
<> set_doc_func (PyUnicode_FromString ("get_set_string"));
537 if (set_doc_func
== NULL
)
539 gdbpy_print_stack ();
543 if (PyObject_HasAttr (obj
, set_doc_func
.get ()))
545 set_doc_string
= call_doc_function (obj
, set_doc_func
.get (), NULL
);
546 if (! set_doc_string
)
547 gdbpy_handle_exception ();
550 const char *str
= set_doc_string
.get ();
551 if (str
!= nullptr && str
[0] != '\0')
552 gdb_printf ("%s\n", str
);
555 /* A callback function that is registered against the respective
556 add_setshow_* show_doc prototype. This function will either call
557 the Python function "get_show_string" or extract the Python
558 attribute "show_doc" and return the contents as a string. If
559 neither exist, insert a string indicating the Parameter is not
562 get_show_value (struct ui_file
*file
, int from_tty
,
563 struct cmd_list_element
*c
,
566 PyObject
*obj
= (PyObject
*) c
->context ();
567 gdb::unique_xmalloc_ptr
<char> show_doc_string
;
569 gdbpy_enter enter_py
;
570 gdbpy_ref
<> show_doc_func (PyUnicode_FromString ("get_show_string"));
572 if (show_doc_func
== NULL
)
574 gdbpy_print_stack ();
578 if (PyObject_HasAttr (obj
, show_doc_func
.get ()))
580 gdbpy_ref
<> val_obj (PyUnicode_FromString (value
));
584 gdbpy_print_stack ();
588 show_doc_string
= call_doc_function (obj
, show_doc_func
.get (),
590 if (! show_doc_string
)
592 gdbpy_print_stack ();
596 gdb_printf (file
, "%s\n", show_doc_string
.get ());
600 /* If there is no 'get_show_string' callback then we want to show
601 something sensible here. In older versions of GDB (< 7.3) we
602 didn't support 'get_show_string', and instead we just made use of
603 GDB's builtin use of the show_doc. However, GDB's builtin
604 show_doc adjustment is not i18n friendly, so, instead, we just
605 print this generic string. */
606 std::string cmd_path
= full_cmd_name_without_first_prefix (c
);
607 gdb_printf (file
, _("The current value of '%s' is \"%s\".\n"),
608 cmd_path
.c_str (), value
);
613 /* A helper function that dispatches to the appropriate add_setshow
616 add_setshow_generic (enum var_types type
, const literal_def
*extra_literals
,
617 enum command_class cmdclass
,
618 gdb::unique_xmalloc_ptr
<char> cmd_name
,
620 const char *set_doc
, const char *show_doc
,
621 const char *help_doc
,
622 struct cmd_list_element
**set_list
,
623 struct cmd_list_element
**show_list
)
625 set_show_commands commands
;
630 commands
= add_setshow_boolean_cmd (cmd_name
.get (), cmdclass
,
631 &self
->value
.boolval
, set_doc
,
632 show_doc
, help_doc
, get_set_value
,
633 get_show_value
, set_list
, show_list
);
637 case var_auto_boolean
:
638 commands
= add_setshow_auto_boolean_cmd (cmd_name
.get (), cmdclass
,
639 &self
->value
.autoboolval
,
640 set_doc
, show_doc
, help_doc
,
641 get_set_value
, get_show_value
,
642 set_list
, show_list
);
646 commands
= add_setshow_uinteger_cmd (cmd_name
.get (), cmdclass
,
647 &self
->value
.uintval
,
648 extra_literals
, set_doc
,
649 show_doc
, help_doc
, get_set_value
,
650 get_show_value
, set_list
, show_list
);
654 commands
= add_setshow_integer_cmd (cmd_name
.get (), cmdclass
,
656 extra_literals
, set_doc
,
657 show_doc
, help_doc
, get_set_value
,
658 get_show_value
, set_list
, show_list
);
662 commands
= add_setshow_pinteger_cmd (cmd_name
.get (), cmdclass
,
664 extra_literals
, set_doc
,
665 show_doc
, help_doc
, get_set_value
,
666 get_show_value
, set_list
, show_list
);
670 commands
= add_setshow_string_cmd (cmd_name
.get (), cmdclass
,
671 self
->value
.stringval
, set_doc
,
672 show_doc
, help_doc
, get_set_value
,
673 get_show_value
, set_list
, show_list
);
676 case var_string_noescape
:
677 commands
= add_setshow_string_noescape_cmd (cmd_name
.get (), cmdclass
,
678 self
->value
.stringval
,
679 set_doc
, show_doc
, help_doc
,
680 get_set_value
, get_show_value
,
681 set_list
, show_list
);
684 case var_optional_filename
:
685 commands
= add_setshow_optional_filename_cmd (cmd_name
.get (), cmdclass
,
686 self
->value
.stringval
,
687 set_doc
, show_doc
, help_doc
,
689 get_show_value
, set_list
,
694 commands
= add_setshow_filename_cmd (cmd_name
.get (), cmdclass
,
695 self
->value
.stringval
, set_doc
,
696 show_doc
, help_doc
, get_set_value
,
697 get_show_value
, set_list
, show_list
);
701 /* Initialize the value, just in case. */
702 self
->value
.cstringval
= self
->enumeration
[0];
703 commands
= add_setshow_enum_cmd (cmd_name
.get (), cmdclass
,
705 &self
->value
.cstringval
, set_doc
,
706 show_doc
, help_doc
, get_set_value
,
707 get_show_value
, set_list
, show_list
);
711 gdb_assert_not_reached ("Unhandled parameter class.");
714 /* Register Python objects in both commands' context. */
715 commands
.set
->set_context (self
);
716 commands
.show
->set_context (self
);
718 /* We (unfortunately) currently leak the command name. */
722 /* A helper which computes enum values. Returns 1 on success. Returns 0 on
723 error, with a python exception set. */
725 compute_enum_values (parmpy_object
*self
, PyObject
*enum_values
)
731 PyErr_SetString (PyExc_RuntimeError
,
732 _("An enumeration is required for PARAM_ENUM."));
736 if (! PySequence_Check (enum_values
))
738 PyErr_SetString (PyExc_RuntimeError
,
739 _("The enumeration is not a sequence."));
743 size
= PySequence_Size (enum_values
);
748 PyErr_SetString (PyExc_RuntimeError
,
749 _("The enumeration is empty."));
753 gdb_argv
holder (XCNEWVEC (char *, size
+ 1));
754 char **enumeration
= holder
.get ();
756 for (i
= 0; i
< size
; ++i
)
758 gdbpy_ref
<> item (PySequence_GetItem (enum_values
, i
));
762 if (! gdbpy_is_string (item
.get ()))
764 PyErr_SetString (PyExc_RuntimeError
,
765 _("The enumeration item not a string."));
768 enumeration
[i
] = python_string_to_host_string (item
.get ()).release ();
769 if (enumeration
[i
] == NULL
)
773 self
->enumeration
= const_cast<const char**> (holder
.release ());
777 /* Object initializer; sets up gdb-side structures for command.
779 Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
781 NAME is the name of the parameter. It may consist of multiple
782 words, in which case the final word is the name of the new command,
783 and earlier words must be prefix commands.
785 CMDCLASS is the kind of command. It should be one of the COMMAND_*
786 constants defined in the gdb module.
788 PARMCLASS is the type of the parameter. It should be one of the
789 PARAM_* constants defined in the gdb module.
791 If PARMCLASS is PARAM_ENUM, then the final argument should be a
792 collection of strings. These strings are the valid values for this
795 The documentation for the parameter is taken from the doc string
796 for the python class.
798 Returns -1 on error, with a python exception set. */
801 parmpy_init (PyObject
*self
, PyObject
*args
, PyObject
*kwds
)
803 parmpy_object
*obj
= (parmpy_object
*) self
;
805 gdb::unique_xmalloc_ptr
<char> set_doc
, show_doc
, doc
;
806 int parmclass
, cmdtype
;
807 PyObject
*enum_values
= NULL
;
808 struct cmd_list_element
**set_list
, **show_list
;
809 const literal_def
*extra_literals
;
812 if (! PyArg_ParseTuple (args
, "sii|O", &name
, &cmdtype
, &parmclass
,
816 if (cmdtype
!= no_class
&& cmdtype
!= class_run
817 && cmdtype
!= class_vars
&& cmdtype
!= class_stack
818 && cmdtype
!= class_files
&& cmdtype
!= class_support
819 && cmdtype
!= class_info
&& cmdtype
!= class_breakpoint
820 && cmdtype
!= class_trace
&& cmdtype
!= class_obscure
821 && cmdtype
!= class_maintenance
)
823 PyErr_Format (PyExc_RuntimeError
, _("Invalid command class argument."));
827 if (parmclass
!= param_boolean
/* ARI: param_boolean */
828 && parmclass
!= param_auto_boolean
829 && parmclass
!= param_uinteger
&& parmclass
!= param_integer
830 && parmclass
!= param_string
&& parmclass
!= param_string_noescape
831 && parmclass
!= param_optional_filename
&& parmclass
!= param_filename
832 && parmclass
!= param_zinteger
&& parmclass
!= param_zuinteger
833 && parmclass
!= param_zuinteger_unlimited
&& parmclass
!= param_enum
)
835 PyErr_SetString (PyExc_RuntimeError
,
836 _("Invalid parameter class argument."));
840 if (enum_values
&& parmclass
!= param_enum
)
842 PyErr_SetString (PyExc_RuntimeError
,
843 _("Only PARAM_ENUM accepts a fourth argument."));
846 if (parmclass
== param_enum
)
848 if (! compute_enum_values (obj
, enum_values
))
852 obj
->enumeration
= NULL
;
853 type
= param_to_var
[parmclass
].type
;
854 extra_literals
= param_to_var
[parmclass
].extra_literals
;
856 obj
->extra_literals
= extra_literals
;
857 memset (&obj
->value
, 0, sizeof (obj
->value
));
859 if (var_type_uses
<std::string
> (obj
->type
))
860 obj
->value
.stringval
= new std::string
;
862 gdb::unique_xmalloc_ptr
<char> cmd_name
863 = gdbpy_parse_command_name (name
, &set_list
, &setlist
);
864 if (cmd_name
== nullptr)
867 cmd_name
= gdbpy_parse_command_name (name
, &show_list
, &showlist
);
868 if (cmd_name
== nullptr)
871 set_doc
= get_doc_string (self
, doc_string_set
, name
);
872 show_doc
= get_doc_string (self
, doc_string_show
, name
);
873 doc
= get_doc_string (self
, doc_string_description
, cmd_name
.get ());
879 add_setshow_generic (type
, extra_literals
,
880 (enum command_class
) cmdtype
,
881 std::move (cmd_name
), obj
,
882 set_doc
.get (), show_doc
.get (),
883 doc
.get (), set_list
, show_list
);
885 catch (const gdb_exception
&except
)
888 return gdbpy_handle_gdb_exception (-1, except
);
894 /* Deallocate function for a gdb.Parameter. */
897 parmpy_dealloc (PyObject
*obj
)
899 parmpy_object
*parm_obj
= (parmpy_object
*) obj
;
901 if (var_type_uses
<std::string
> (parm_obj
->type
))
902 delete parm_obj
->value
.stringval
;
905 /* Initialize the 'parameters' module. */
906 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
907 gdbpy_initialize_parameters (void)
911 parmpy_object_type
.tp_new
= PyType_GenericNew
;
912 if (gdbpy_type_ready (&parmpy_object_type
) < 0)
915 set_doc_cst
= PyUnicode_FromString ("set_doc");
918 show_doc_cst
= PyUnicode_FromString ("show_doc");
922 for (i
= 0; parm_constants
[i
].name
; ++i
)
924 if (PyModule_AddIntConstant (gdb_module
,
925 parm_constants
[i
].name
,
926 parm_constants
[i
].value
) < 0)
933 GDBPY_INITIALIZE_FILE (gdbpy_initialize_parameters
);
937 PyTypeObject parmpy_object_type
=
939 PyVarObject_HEAD_INIT (NULL
, 0)
940 "gdb.Parameter", /*tp_name*/
941 sizeof (parmpy_object
), /*tp_basicsize*/
943 parmpy_dealloc
, /*tp_dealloc*/
950 0, /*tp_as_sequence*/
955 get_attr
, /*tp_getattro*/
956 set_attr
, /*tp_setattro*/
958 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /*tp_flags*/
959 "GDB parameter object", /* tp_doc */
962 0, /* tp_richcompare */
963 0, /* tp_weaklistoffset */
971 0, /* tp_descr_get */
972 0, /* tp_descr_set */
973 0, /* tp_dictoffset */
974 parmpy_init
, /* tp_init */