gdb/testsuite/tui: Introduce check_box_contents
[deliverable/binutils-gdb.git] / gdb / python / py-param.c
index 455c99e51641dcce738dd398803332e58aba7799..7b183cfa553c71bbd767937018e722138608f86d 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB parameters implemented in Python
 
-   Copyright (C) 2008-2017 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -27,7 +27,6 @@
 #include "completer.h"
 #include "language.h"
 #include "arch-utils.h"
-#include "py-ref.h"
 
 /* Parameter constants and their values.  */
 struct parm_constant
@@ -47,6 +46,8 @@ struct parm_constant parm_constants[] =
   { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
   { "PARAM_FILENAME", var_filename },
   { "PARAM_ZINTEGER", var_zinteger },
+  { "PARAM_ZUINTEGER", var_zuinteger },
+  { "PARAM_ZUINTEGER_UNLIMITED", var_zuinteger_unlimited },
   { "PARAM_ENUM", var_enum },
   { NULL, 0 }
 };
@@ -54,7 +55,10 @@ struct parm_constant parm_constants[] =
 /* A union that can hold anything described by enum var_types.  */
 union parmpy_variable
 {
-  /* Hold an integer value, for boolean and integer types.  */
+  /* Hold a boolean value.  */
+  bool boolval;
+
+  /* Hold an integer value.  */
   int intval;
 
   /* Hold an auto_boolean.  */
@@ -197,7 +201,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
       cmp = PyObject_IsTrue (value);
       if (cmp < 0)
          return -1;
-      self->value.intval = cmp;
+      self->value.boolval = cmp;
       break;
 
     case var_auto_boolean:
@@ -225,6 +229,8 @@ set_parameter_value (parmpy_object *self, PyObject *value)
     case var_integer:
     case var_zinteger:
     case var_uinteger:
+    case var_zuinteger:
+    case var_zuinteger_unlimited:
       {
        long l;
        int ok;
@@ -239,20 +245,33 @@ set_parameter_value (parmpy_object *self, PyObject *value)
        if (! gdb_py_int_as_long (value, &l))
          return -1;
 
-       if (self->type == var_uinteger)
+       switch (self->type)
          {
-           ok = (l >= 0 && l <= UINT_MAX);
+         case var_uinteger:
            if (l == 0)
              l = UINT_MAX;
-         }
-       else if (self->type == var_integer)
-         {
+           /* Fall through.  */
+         case var_zuinteger:
+           ok = (l >= 0 && l <= UINT_MAX);
+           break;
+
+         case var_zuinteger_unlimited:
+           ok = (l >= -1 && l <= INT_MAX);
+           break;
+
+         case var_integer:
            ok = (l >= INT_MIN && l <= INT_MAX);
            if (l == 0)
              l = INT_MAX;
+           break;
+
+         case var_zinteger:
+           ok = (l >= INT_MIN && l <= INT_MAX);
+           break;
+
+         default:
+           gdb_assert_not_reached ("unknown var_ constant");
          }
-       else
-         ok = (l >= INT_MIN && l <= INT_MAX);
 
        if (! ok)
          {
@@ -261,7 +280,10 @@ set_parameter_value (parmpy_object *self, PyObject *value)
            return -1;
          }
 
-       self->value.intval = (int) l;
+       if (self->type == var_uinteger || self->type == var_zuinteger)
+         self->value.uintval = (unsigned) l;
+       else
+         self->value.intval = (int) l;
        break;
       }
 
@@ -357,7 +379,7 @@ call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
    neither exist, insert a string indicating the Parameter is not
    documented.  */
 static void
-get_set_value (char *args, int from_tty,
+get_set_value (const char *args, int from_tty,
               struct cmd_list_element *c)
 {
   PyObject *obj = (PyObject *) get_cmd_context (c);
@@ -376,20 +398,12 @@ get_set_value (char *args, int from_tty,
     {
       set_doc_string = call_doc_function (obj, set_doc_func.get (), NULL);
       if (! set_doc_string)
-       {
-         gdbpy_print_stack ();
-         return;
-       }
-    }
-  else
-    {
-      /* We have to preserve the existing < GDB 7.3 API.  If a
-        callback function does not exist, then attempt to read the
-        set_doc attribute.  */
-      set_doc_string  = get_doc_string (obj, set_doc_cst);
+       gdbpy_handle_exception ();
     }
 
-  fprintf_filtered (gdb_stdout, "%s\n", set_doc_string.get ());
+  const char *str = set_doc_string.get ();
+  if (str != nullptr && str[0] != '\0')
+    fprintf_filtered (gdb_stdout, "%s\n", str);
 }
 
 /* A callback function that is registered against the respective
@@ -450,8 +464,9 @@ get_show_value (struct ui_file *file, int from_tty,
    function.  */
 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,
+                    const 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)
 {
@@ -463,7 +478,7 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
     case var_boolean:
 
       add_setshow_boolean_cmd (cmd_name, cmdclass,
-                              &self->value.intval, set_doc, show_doc,
+                              &self->value.boolval, set_doc, show_doc,
                               help_doc, get_set_value, get_show_value,
                               set_list, show_list);
 
@@ -526,6 +541,21 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
                                set_list, show_list);
       break;
 
+    case var_zuinteger:
+      add_setshow_zuinteger_cmd (cmd_name, cmdclass,
+                               &self->value.uintval, set_doc, show_doc,
+                               help_doc, get_set_value, get_show_value,
+                               set_list, show_list);
+      break;
+
+    case var_zuinteger_unlimited:
+      add_setshow_zuinteger_unlimited_cmd (cmd_name, cmdclass,
+                                          &self->value.intval, set_doc,
+                                          show_doc, help_doc, get_set_value,
+                                          get_show_value,
+                                          set_list, show_list);
+      break;
+
     case var_enum:
       add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
                            &self->value.cstringval, set_doc, show_doc,
@@ -632,7 +662,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 {
   parmpy_object *obj = (parmpy_object *) self;
   const char *name;
-  char *set_doc, *show_doc, *doc;
+  gdb::unique_xmalloc_ptr<char> set_doc, show_doc, doc;
   char *cmd_name;
   int parmclass, cmdtype;
   PyObject *enum_values = NULL;
@@ -658,7 +688,8 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
       && parmclass != var_uinteger && parmclass != var_integer
       && parmclass != var_string && parmclass != var_string_noescape
       && parmclass != var_optional_filename && parmclass != var_filename
-      && parmclass != var_zinteger && parmclass != var_enum)
+      && parmclass != var_zinteger && parmclass != var_zuinteger
+      && parmclass != var_zuinteger_unlimited && parmclass != var_enum)
     {
       PyErr_SetString (PyExc_RuntimeError,
                       _("Invalid parameter class argument."));
@@ -692,32 +723,26 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (! cmd_name)
     return -1;
 
-  set_doc = get_doc_string (self, set_doc_cst).release ();
-  show_doc = get_doc_string (self, show_doc_cst).release ();
-  doc = get_doc_string (self, gdbpy_doc_cst).release ();
+  set_doc = get_doc_string (self, set_doc_cst);
+  show_doc = get_doc_string (self, show_doc_cst);
+  doc = get_doc_string (self, gdbpy_doc_cst);
 
   Py_INCREF (self);
 
-  TRY
+  try
     {
       add_setshow_generic (parmclass, (enum command_class) cmdtype,
                           cmd_name, obj,
-                          set_doc, show_doc,
-                          doc, set_list, show_list);
+                          set_doc.get (), show_doc.get (),
+                          doc.get (), set_list, show_list);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
       xfree (cmd_name);
-      xfree (set_doc);
-      xfree (show_doc);
-      xfree (doc);
       Py_DECREF (self);
-      PyErr_Format (except.reason == RETURN_QUIT
-                   ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-                   "%s", except.message);
+      gdbpy_convert_exception (except);
       return -1;
     }
-  END_CATCH
 
   return 0;
 }
This page took 0.027012 seconds and 4 git commands to generate.