diff options
Diffstat (limited to 'gdb/python/py-param.c')
-rw-r--r-- | gdb/python/py-param.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index 9741782..0e79d21 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -26,6 +26,7 @@ #include "completer.h" #include "language.h" #include "arch-utils.h" +#include "py-color.h" /* Python parameter types as in PARM_CONSTANTS below. */ @@ -43,6 +44,7 @@ enum py_param_types param_zuinteger, param_zuinteger_unlimited, param_enum, + param_color, }; /* Translation from Python parameters to GDB variable types. Keep in the @@ -69,7 +71,8 @@ param_to_var[] = { var_integer }, { var_uinteger }, { var_pinteger, pinteger_unlimited_literals }, - { var_enum } + { var_enum }, + { var_color } }; /* Parameter constants and their values. */ @@ -90,6 +93,7 @@ static struct { { "PARAM_ZUINTEGER", param_zuinteger }, { "PARAM_ZUINTEGER_UNLIMITED", param_zuinteger_unlimited }, { "PARAM_ENUM", param_enum }, + { "PARAM_COLOR", param_color }, { NULL, 0 } }; @@ -114,6 +118,9 @@ union parmpy_variable /* Hold a string, for enums. */ const char *cstringval; + + /* Hold a color. */ + ui_file_style::color color; }; /* A GDB parameter. */ @@ -157,6 +164,8 @@ make_setting (parmpy_object *s) return setting (type, s->value.stringval); else if (var_type_uses<const char *> (type)) return setting (type, &s->value.cstringval); + else if (var_type_uses<ui_file_style::color> (s->type)) + return setting (s->type, &s->value.color); else gdb_assert_not_reached ("unhandled var type"); } @@ -248,6 +257,19 @@ set_parameter_value (parmpy_object *self, PyObject *value) break; } + case var_color: + { + if (gdbpy_is_color (value)) + self->value.color = gdbpy_get_color (value); + else + { + PyErr_SetString (PyExc_RuntimeError, + _("color argument must be a gdb.Color object.")); + return -1; + } + } + break; + case var_boolean: if (! PyBool_Check (value)) { @@ -707,6 +729,15 @@ add_setshow_generic (enum var_types type, const literal_def *extra_literals, get_show_value, set_list, show_list); break; + case var_color: + /* Initialize the value, just in case. */ + self->value.color = ui_file_style::NONE; + commands = add_setshow_color_cmd (cmd_name.get (), cmdclass, + &self->value.color, set_doc, + show_doc, help_doc, get_set_value, + get_show_value, set_list, show_list); + break; + default: gdb_assert_not_reached ("Unhandled parameter class."); } @@ -830,7 +861,8 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) && parmclass != param_string && parmclass != param_string_noescape && parmclass != param_optional_filename && parmclass != param_filename && parmclass != param_zinteger && parmclass != param_zuinteger - && parmclass != param_zuinteger_unlimited && parmclass != param_enum) + && parmclass != param_zuinteger_unlimited && parmclass != param_enum + && parmclass != param_color) { PyErr_SetString (PyExc_RuntimeError, _("Invalid parameter class argument.")); @@ -854,7 +886,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) extra_literals = param_to_var[parmclass].extra_literals; obj->type = type; obj->extra_literals = extra_literals; - memset (&obj->value, 0, sizeof (obj->value)); + obj->value = {}; /* zeros initialization */ if (var_type_uses<std::string> (obj->type)) obj->value.stringval = new std::string; @@ -900,6 +932,8 @@ parmpy_dealloc (PyObject *obj) if (var_type_uses<std::string> (parm_obj->type)) delete parm_obj->value.stringval; + else if (var_type_uses<ui_file_style::color> (parm_obj->type)) + parm_obj->value.color.~color(); } /* Initialize the 'parameters' module. */ |