104 if (PyString_Check (attr_name)
106 && ! PyUnicode_CompareWithASCIIString (attr_name,
"value"))
108 && ! strcmp (PyString_AsString (attr_name),
"value"))
116 return PyObject_GenericGetAttr (obj, attr_name);
134 || value != Py_None))
136 PyErr_SetString (PyExc_RuntimeError,
137 _(
"String required for filename."));
141 if (value == Py_None)
143 xfree (self->value.stringval);
145 self->value.stringval = xstrdup (
"");
147 self->value.stringval = NULL;
157 xfree (self->value.stringval);
158 self->value.stringval =
string;
169 PyErr_SetString (PyExc_RuntimeError,
170 _(
"ENUM arguments must be a string."));
177 for (i = 0;
self->enumeration[i]; ++i)
178 if (! strcmp (self->enumeration[i], str))
181 if (! self->enumeration[i])
183 PyErr_SetString (PyExc_RuntimeError,
184 _(
"The value must be member of an enumeration."));
187 self->value.cstringval =
self->enumeration[i];
192 if (! PyBool_Check (value))
194 PyErr_SetString (PyExc_RuntimeError,
195 _(
"A boolean argument is required."));
198 cmp = PyObject_IsTrue (value);
201 self->value.intval = cmp;
205 if (! PyBool_Check (value) && value != Py_None)
207 PyErr_SetString (PyExc_RuntimeError,
208 _(
"A boolean or None is required"));
212 if (value == Py_None)
216 cmp = PyObject_IsTrue (value);
233 if (! PyInt_Check (value))
235 PyErr_SetString (PyExc_RuntimeError,
236 _(
"The value must be integer."));
260 PyErr_SetString (PyExc_RuntimeError,
261 _(
"Range exceeded."));
265 self->value.intval = (
int) l;
270 PyErr_SetString (PyExc_RuntimeError,
271 _(
"Unhandled type in parameter value."));
280 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
282 if (PyString_Check (attr_name)
284 && ! PyUnicode_CompareWithASCIIString (attr_name,
"value"))
286 && ! strcmp (PyString_AsString (attr_name),
"value"))
291 PyErr_SetString (PyExc_RuntimeError,
292 _(
"Cannot delete a parameter's value."));
298 return PyObject_GenericSetAttr (obj, attr_name, val);
309 if (PyObject_HasAttr (
object, attr))
311 PyObject *ds_obj = PyObject_GetAttr (
object, attr);
322 result = xstrdup (
_(
"This command is not documented."));
334 PyObject *result = PyObject_CallMethodObjArgs (obj, method, arg, NULL);
348 PyErr_SetString (PyExc_RuntimeError,
349 _(
"Parameter must return a string value."));
368 char *set_doc_string;
371 PyObject *set_doc_func = PyString_FromString (
"get_set_string");
376 if (PyObject_HasAttr (obj, set_doc_func))
379 if (! set_doc_string)
393 Py_XDECREF (set_doc_func);
398 Py_XDECREF (set_doc_func);
416 char *show_doc_string = NULL;
419 PyObject *show_doc_func = PyString_FromString (
"get_show_string");
424 if (PyObject_HasAttr (obj, show_doc_func))
426 PyObject *val_obj = PyString_FromString (value);
433 if (! show_doc_string)
450 Py_XDECREF (show_doc_func);
455 Py_XDECREF (show_doc_func);
467 char *set_doc,
char *show_doc,
char *help_doc,
472 const char *tmp_name = NULL;
479 &self->value.intval, set_doc, show_doc,
481 set_list, show_list);
487 &self->value.autoboolval,
488 set_doc, show_doc, help_doc,
490 set_list, show_list);
495 &self->value.uintval, set_doc, show_doc,
497 set_list, show_list);
502 &self->value.intval, set_doc, show_doc,
504 set_list, show_list);
break;
508 &self->value.stringval, set_doc, show_doc,
510 set_list, show_list);
break;
514 &self->value.stringval,
515 set_doc, show_doc, help_doc,
517 set_list, show_list);
523 &self->value.stringval, set_doc,
531 &self->value.stringval, set_doc, show_doc,
533 set_list, show_list);
break;
537 &self->value.intval, set_doc, show_doc,
539 set_list, show_list);
544 &self->value.cstringval, set_doc, show_doc,
546 set_list, show_list);
548 self->value.cstringval =
self->enumeration[0];
555 param =
lookup_cmd (&tmp_name, *show_list,
"", 0, 1);
560 param =
lookup_cmd (&tmp_name, *set_list,
"", 0, 1);
575 PyErr_SetString (PyExc_RuntimeError,
576 _(
"An enumeration is required for PARAM_ENUM."));
580 if (! PySequence_Check (enum_values))
582 PyErr_SetString (PyExc_RuntimeError,
583 _(
"The enumeration is not a sequence."));
587 size = PySequence_Size (enum_values);
592 PyErr_SetString (PyExc_RuntimeError,
593 _(
"The enumeration is empty."));
597 self->enumeration =
xmalloc ((size + 1) *
sizeof (
char *));
599 memset (self->enumeration, 0, (size + 1) * sizeof (
char *));
601 for (i = 0; i <
size; ++i)
603 PyObject *item = PySequence_GetItem (enum_values, i);
614 PyErr_SetString (PyExc_RuntimeError,
615 _(
"The enumeration item not a string."));
620 if (self->enumeration[i] == NULL)
660 char *set_doc, *show_doc, *doc;
662 int parmclass, cmdtype;
663 PyObject *enum_values = NULL;
666 if (! PyArg_ParseTuple (args,
"sii|O", &name, &cmdtype, &parmclass,
677 PyErr_Format (PyExc_RuntimeError,
_(
"Invalid command class argument."));
688 PyErr_SetString (PyExc_RuntimeError,
689 _(
"Invalid parameter class argument."));
693 if (enum_values && parmclass !=
var_enum)
695 PyErr_SetString (PyExc_RuntimeError,
696 _(
"Only PARAM_ENUM accepts a fourth argument."));
731 doc, set_list, show_list);
741 ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
742 "%s", except.message);
762 set_doc_cst = PyString_FromString (
"set_doc");
765 show_doc_cst = PyString_FromString (
"show_doc");
769 for (i = 0; parm_constants[i].
name; ++i)
772 parm_constants[i].
name,
773 parm_constants[i].
value) < 0)
804 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
805 "GDB parameter object",
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
void set_cmd_context(struct cmd_list_element *cmd, void *context)
static int parmpy_init(PyObject *self, PyObject *args, PyObject *kwds)
void * get_cmd_context(struct cmd_list_element *cmd)
PyTypeObject parmpy_object_type
void add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static PyObject * get_attr(PyObject *obj, PyObject *attr_name)
int gdbpy_is_string(PyObject *obj)
void add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct ui_file * gdb_stdout
static PyObject * show_doc_cst
static int set_attr(PyObject *obj, PyObject *attr_name, PyObject *val)
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, char *cmdtype, int allow_unknown, int ignore_help_classes)
const char ** enumeration
PyTypeObject parmpy_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("parmpy_object")
struct cmd_list_element * add_setshow_string_noescape_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * setlist
void add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int gdbpy_initialize_parameters(void)
#define CATCH(EXCEPTION, MASK)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
void add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void get_show_value(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cmd_list_element * showlist
void free_current_contents(void *ptr)
PyObject * gdbpy_parameter_value(enum var_types type, void *var)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
char * python_string_to_host_string(PyObject *obj)
void add_setshow_string_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct gdbarch * get_current_arch(void)
char * gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
static char * get_doc_string(PyObject *object, PyObject *attr)
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
static PyObject * set_doc_cst
static int set_parameter_value(parmpy_object *self, PyObject *value)
static void add_setshow_generic(int parmclass, enum command_class cmdclass, char *cmd_name, parmpy_object *self, char *set_doc, char *show_doc, char *help_doc, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const char const char int
void discard_cleanups(struct cleanup *old_chain)
const struct language_defn * current_language
PyObject_HEAD enum var_types type
void add_setshow_integer_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
union parmpy_variable value
void gdbpy_print_stack(void)
void add_setshow_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static int compute_enum_values(parmpy_object *self, PyObject *enum_values)
int gdb_py_int_as_long(PyObject *obj, long *result)
void error(const char *fmt,...)
static char * call_doc_function(PyObject *obj, PyObject *method, PyObject *arg)
void add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void get_set_value(char *args, int from_tty, struct cmd_list_element *c)
void do_cleanups(struct cleanup *old_chain)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct parmpy_object parmpy_object
enum auto_boolean autoboolval
#define PyVarObject_HEAD_INIT(type, size)