153 else if (var_type_uses<auto_boolean> (
type))
162 gdb_assert_not_reached (
"unhandled var type");
178 if (PyUnicode_Check (attr_name)
179 && ! PyUnicode_CompareWithASCIIString (attr_name,
"value"))
186 return PyObject_GenericGetAttr (obj, attr_name);
204 ||
value != Py_None))
206 PyErr_SetString (PyExc_RuntimeError,
207 _(
"String required for filename."));
211 if (
value == Py_None)
215 gdb::unique_xmalloc_ptr<char>
230 PyErr_SetString (PyExc_RuntimeError,
231 _(
"ENUM arguments must be a string."));
235 gdb::unique_xmalloc_ptr<char>
244 PyErr_SetString (PyExc_RuntimeError,
245 _(
"The value must be member of an enumeration."));
253 if (! PyBool_Check (
value))
255 PyErr_SetString (PyExc_RuntimeError,
256 _(
"A boolean argument is required."));
259 cmp = PyObject_IsTrue (
value);
266 if (! PyBool_Check (
value) &&
value != Py_None)
268 PyErr_SetString (PyExc_RuntimeError,
269 _(
"A boolean or None is required"));
273 if (
value == Py_None)
277 cmp = PyObject_IsTrue (
value);
292 enum tribool allowed = TRIBOOL_UNKNOWN;
294 std::string buffer =
"";
300 gdb::unique_xmalloc_ptr<char>
302 const char *s = str !=
nullptr ? str.get () :
nullptr;
311 buffer = buffer +
"'" + l->literal +
"'";
312 if (allowed == TRIBOOL_UNKNOWN
313 && ((
value == Py_None && !strcmp (
"unlimited", l->literal))
314 || (s !=
nullptr && !strcmp (s, l->literal))))
317 allowed = TRIBOOL_TRUE;
322 if (allowed == TRIBOOL_UNKNOWN)
324 val = PyLong_AsLongLong (
value);
326 if (PyErr_Occurred ())
329 PyErr_SetString (PyExc_RuntimeError,
330 _(
"The value must be integer."));
332 PyErr_SetString (PyExc_RuntimeError,
333 string_printf (_(
"integer or one of: %s"),
334 buffer.c_str ()).c_str ());
336 PyErr_SetString (PyExc_RuntimeError,
337 string_printf (_(
"integer or %s"),
338 buffer.c_str ()).c_str ());
348 if (l->val.has_value () && val == *l->val)
350 allowed = TRIBOOL_TRUE;
354 else if (val == l->use)
355 allowed = TRIBOOL_FALSE;
359 if (allowed == TRIBOOL_UNKNOWN)
361 if (val > UINT_MAX || val < INT_MIN
366 allowed = TRIBOOL_FALSE;
368 if (allowed == TRIBOOL_FALSE)
370 PyErr_SetString (PyExc_RuntimeError,
371 _(
"Range exceeded."));
383 PyErr_SetString (PyExc_RuntimeError,
384 _(
"Unhandled type in parameter value."));
395 if (PyUnicode_Check (attr_name)
396 && ! PyUnicode_CompareWithASCIIString (attr_name,
"value"))
400 PyErr_SetString (PyExc_RuntimeError,
401 _(
"Cannot delete a parameter's value."));
407 return PyObject_GenericSetAttr (obj, attr_name, val);
421 std::vector<std::string> components
423 gdb_assert (components.size () > 1);
424 std::string result = components[1];
425 for (
int i = 2; i < components.size (); ++i)
426 result +=
" " + components[i];
442static gdb::unique_xmalloc_ptr<char>
444 const char *cmd_name)
446 gdb::unique_xmalloc_ptr<char> result;
461 gdb_assert (attr !=
nullptr);
463 if (PyObject_HasAttr (
object, attr))
465 gdbpy_ref<> ds_obj (PyObject_GetAttr (
object, attr));
477 if (result ==
nullptr)
480 result.reset (xstrdup (_(
"This command is not documented.")));
484 result = xstrprintf (_(
"Show the current value of '%s'."),
487 result = xstrprintf (_(
"Set the current value of '%s'."),
498static gdb::unique_xmalloc_ptr<char>
501 gdb::unique_xmalloc_ptr<char> data;
502 gdbpy_ref<> result (PyObject_CallMethodObjArgs (obj, method, arg, NULL));
515 PyErr_SetString (PyExc_RuntimeError,
516 _(
"Parameter must return a string value."));
533 gdb::unique_xmalloc_ptr<char> set_doc_string;
536 gdbpy_ref<> set_doc_func (PyUnicode_FromString (
"get_set_string"));
538 if (set_doc_func == NULL)
544 if (PyObject_HasAttr (obj, set_doc_func.get ()))
547 if (! set_doc_string)
551 const char *str = set_doc_string.get ();
552 if (str !=
nullptr && str[0] !=
'\0')
568 gdb::unique_xmalloc_ptr<char> show_doc_string;
571 gdbpy_ref<> show_doc_func (PyUnicode_FromString (
"get_show_string"));
573 if (show_doc_func == NULL)
579 if (PyObject_HasAttr (obj, show_doc_func.get ()))
591 if (! show_doc_string)
597 gdb_printf (file,
"%s\n", show_doc_string.get ());
608 gdb_printf (file, _(
"The current value of '%s' is \"%s\".\n"),
609 cmd_path.c_str (),
value);
619 gdb::unique_xmalloc_ptr<char> cmd_name,
621 const char *set_doc,
const char *show_doc,
622 const char *help_doc,
641 set_doc, show_doc, help_doc,
643 set_list, show_list);
680 set_doc, show_doc, help_doc,
682 set_list, show_list);
688 set_doc, show_doc, help_doc,
712 gdb_assert_not_reached (
"Unhandled parameter class.");
732 PyErr_SetString (PyExc_RuntimeError,
733 _(
"An enumeration is required for PARAM_ENUM."));
737 if (! PySequence_Check (enum_values))
739 PyErr_SetString (PyExc_RuntimeError,
740 _(
"The enumeration is not a sequence."));
744 size = PySequence_Size (enum_values);
749 PyErr_SetString (PyExc_RuntimeError,
750 _(
"The enumeration is empty."));
754 gdb_argv holder (XCNEWVEC (
char *,
size + 1));
755 char **enumeration = holder.get ();
757 for (i = 0; i <
size; ++i)
759 gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
765 PyErr_SetString (PyExc_RuntimeError,
766 _(
"The enumeration item not a string."));
770 if (enumeration[i] == NULL)
774 self->
enumeration =
const_cast<const char**
> (holder.release ());
806 gdb::unique_xmalloc_ptr<char> set_doc, show_doc, doc;
807 int parmclass, cmdtype;
813 if (! PyArg_ParseTuple (args,
"sii|O", &
name, &cmdtype, &parmclass,
824 PyErr_Format (PyExc_RuntimeError, _(
"Invalid command class argument."));
836 PyErr_SetString (PyExc_RuntimeError,
837 _(
"Invalid parameter class argument."));
843 PyErr_SetString (PyExc_RuntimeError,
844 _(
"Only PARAM_ENUM accepts a fourth argument."));
863 gdb::unique_xmalloc_ptr<char> cmd_name
865 if (cmd_name ==
nullptr)
869 if (cmd_name ==
nullptr)
882 std::move (cmd_name), obj,
883 set_doc.get (), show_doc.get (),
884 doc.get (), set_list, show_list);
886 catch (
const gdb_exception &except)
942 PyVarObject_HEAD_INIT (NULL, 0)
961 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
962 "GDB parameter object",
struct cmd_list_element * showlist
struct cmd_list_element * setlist
const literal_def pinteger_unlimited_literals[]
set_show_commands add_setshow_filename_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_optional_filename_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const literal_def integer_unlimited_literals[]
set_show_commands add_setshow_string_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands 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_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_integer_cmd(const char *name, enum command_class theclass, int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const literal_def uinteger_unlimited_literals[]
set_show_commands add_setshow_pinteger_cmd(const char *name, enum command_class theclass, int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_string_noescape_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands 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_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
bool var_type_uses< bool >(var_types t)
bool var_type_uses< std::string >(var_types t)
bool var_type_uses< int >(var_types t)
bool var_type_uses< const char * >(var_types t)
bool var_type_uses< unsigned int >(var_types t)
gdb::unique_xmalloc_ptr< char > gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
static struct @156 parm_constants[]
static std::string full_cmd_name_without_first_prefix(struct cmd_list_element *c)
static void get_set_value(const char *args, int from_tty, struct cmd_list_element *c)
static PyObject * show_doc_cst
PyTypeObject parmpy_object_type
static void add_setshow_generic(enum var_types type, const literal_def *extra_literals, enum command_class cmdclass, gdb::unique_xmalloc_ptr< char > cmd_name, parmpy_object *self, const char *set_doc, const char *show_doc, const char *help_doc, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static PyObject * get_attr(PyObject *obj, PyObject *attr_name)
static PyObject * set_doc_cst
static int set_parameter_value(parmpy_object *self, PyObject *value)
const literal_def * extra_literals
static void get_show_value(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_parameters(void)
static setting make_setting(parmpy_object *s)
static int compute_enum_values(parmpy_object *self, PyObject *enum_values)
static int set_attr(PyObject *obj, PyObject *attr_name, PyObject *val)
@ param_optional_filename
@ param_zuinteger_unlimited
static gdb::unique_xmalloc_ptr< char > call_doc_function(PyObject *obj, PyObject *method, PyObject *arg)
static void parmpy_dealloc(PyObject *obj)
static const struct @155 param_to_var[]
static int parmpy_init(PyObject *self, PyObject *args, PyObject *kwds)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
gdb::unique_xmalloc_ptr< char > gdbpy_fix_doc_string_indentation(gdb::unique_xmalloc_ptr< char > doc)
void gdbpy_convert_exception(const struct gdb_exception &exception)
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
void gdbpy_handle_exception()
int gdbpy_is_string(PyObject *obj)
void gdbpy_print_stack(void)
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#define GDBPY_INITIALIZE_FILE(INIT,...)
PyObject * gdbpy_parameter_value(const setting &var)
static char * get_doc_string(void)
std::vector< std::string > command_components() const
void set_context(void *context)
PyObject_HEAD enum var_types type
const literal_def * extra_literals
const char ** enumeration
union parmpy_variable value
enum auto_boolean autoboolval
void gdb_printf(struct ui_file *stream, const char *format,...)