GDB (xrefs)
py-param.c
Go to the documentation of this file.
1 /* GDB parameters implemented in Python
2 
3  Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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.
11 
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.
16 
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/>. */
19 
20 
21 #include "defs.h"
22 #include "value.h"
23 #include "python-internal.h"
24 #include "charset.h"
25 #include "gdbcmd.h"
26 #include "cli/cli-decode.h"
27 #include "completer.h"
28 #include "language.h"
29 #include "arch-utils.h"
30 
31 /* Parameter constants and their values. */
33 {
34  char *name;
35  int value;
36 };
37 
38 struct parm_constant parm_constants[] =
39 {
40  { "PARAM_BOOLEAN", var_boolean }, /* ARI: var_boolean */
41  { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
42  { "PARAM_UINTEGER", var_uinteger },
43  { "PARAM_INTEGER", var_integer },
44  { "PARAM_STRING", var_string },
45  { "PARAM_STRING_NOESCAPE", var_string_noescape },
46  { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
47  { "PARAM_FILENAME", var_filename },
48  { "PARAM_ZINTEGER", var_zinteger },
49  { "PARAM_ENUM", var_enum },
50  { NULL, 0 }
51 };
52 
53 /* A union that can hold anything described by enum var_types. */
55 {
56  /* Hold an integer value, for boolean and integer types. */
57  int intval;
58 
59  /* Hold an auto_boolean. */
61 
62  /* Hold an unsigned integer value, for uinteger. */
63  unsigned int uintval;
64 
65  /* Hold a string, for the various string types. */
66  char *stringval;
67 
68  /* Hold a string, for enums. */
69  const char *cstringval;
70 };
71 
72 /* A GDB parameter. */
74 {
75  PyObject_HEAD
76 
77  /* The type of the parameter. */
79 
80  /* The value of the parameter. */
82 
83  /* For an enum command, the possible values. The vector is
84  allocated with xmalloc, as is each element. It is
85  NULL-terminated. */
86  const char **enumeration;
87 };
88 
90 
91 extern PyTypeObject parmpy_object_type
92  CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
93 
94 /* Some handy string constants. */
95 static PyObject *set_doc_cst;
96 static PyObject *show_doc_cst;
97 
98 
99 
100 /* Get an attribute. */
101 static PyObject *
102 get_attr (PyObject *obj, PyObject *attr_name)
103 {
104  if (PyString_Check (attr_name)
105 #ifdef IS_PY3K
106  && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
107 #else
108  && ! strcmp (PyString_AsString (attr_name), "value"))
109 #endif
110  {
111  parmpy_object *self = (parmpy_object *) obj;
112 
113  return gdbpy_parameter_value (self->type, &self->value);
114  }
115 
116  return PyObject_GenericGetAttr (obj, attr_name);
117 }
118 
119 /* Set a parameter value from a Python value. Return 0 on success. Returns
120  -1 on error, with a python exception set. */
121 static int
123 {
124  int cmp;
125 
126  switch (self->type)
127  {
128  case var_string:
129  case var_string_noescape:
131  case var_filename:
132  if (! gdbpy_is_string (value)
133  && (self->type == var_filename
134  || value != Py_None))
135  {
136  PyErr_SetString (PyExc_RuntimeError,
137  _("String required for filename."));
138 
139  return -1;
140  }
141  if (value == Py_None)
142  {
143  xfree (self->value.stringval);
144  if (self->type == var_optional_filename)
145  self->value.stringval = xstrdup ("");
146  else
147  self->value.stringval = NULL;
148  }
149  else
150  {
151  char *string;
152 
153  string = python_string_to_host_string (value);
154  if (string == NULL)
155  return -1;
156 
157  xfree (self->value.stringval);
158  self->value.stringval = string;
159  }
160  break;
161 
162  case var_enum:
163  {
164  int i;
165  char *str;
166 
167  if (! gdbpy_is_string (value))
168  {
169  PyErr_SetString (PyExc_RuntimeError,
170  _("ENUM arguments must be a string."));
171  return -1;
172  }
173 
174  str = python_string_to_host_string (value);
175  if (str == NULL)
176  return -1;
177  for (i = 0; self->enumeration[i]; ++i)
178  if (! strcmp (self->enumeration[i], str))
179  break;
180  xfree (str);
181  if (! self->enumeration[i])
182  {
183  PyErr_SetString (PyExc_RuntimeError,
184  _("The value must be member of an enumeration."));
185  return -1;
186  }
187  self->value.cstringval = self->enumeration[i];
188  break;
189  }
190 
191  case var_boolean:
192  if (! PyBool_Check (value))
193  {
194  PyErr_SetString (PyExc_RuntimeError,
195  _("A boolean argument is required."));
196  return -1;
197  }
198  cmp = PyObject_IsTrue (value);
199  if (cmp < 0)
200  return -1;
201  self->value.intval = cmp;
202  break;
203 
204  case var_auto_boolean:
205  if (! PyBool_Check (value) && value != Py_None)
206  {
207  PyErr_SetString (PyExc_RuntimeError,
208  _("A boolean or None is required"));
209  return -1;
210  }
211 
212  if (value == Py_None)
213  self->value.autoboolval = AUTO_BOOLEAN_AUTO;
214  else
215  {
216  cmp = PyObject_IsTrue (value);
217  if (cmp < 0 )
218  return -1;
219  if (cmp == 1)
220  self->value.autoboolval = AUTO_BOOLEAN_TRUE;
221  else
222  self->value.autoboolval = AUTO_BOOLEAN_FALSE;
223  }
224  break;
225 
226  case var_integer:
227  case var_zinteger:
228  case var_uinteger:
229  {
230  long l;
231  int ok;
232 
233  if (! PyInt_Check (value))
234  {
235  PyErr_SetString (PyExc_RuntimeError,
236  _("The value must be integer."));
237  return -1;
238  }
239 
240  if (! gdb_py_int_as_long (value, &l))
241  return -1;
242 
243  if (self->type == var_uinteger)
244  {
245  ok = (l >= 0 && l <= UINT_MAX);
246  if (l == 0)
247  l = UINT_MAX;
248  }
249  else if (self->type == var_integer)
250  {
251  ok = (l >= INT_MIN && l <= INT_MAX);
252  if (l == 0)
253  l = INT_MAX;
254  }
255  else
256  ok = (l >= INT_MIN && l <= INT_MAX);
257 
258  if (! ok)
259  {
260  PyErr_SetString (PyExc_RuntimeError,
261  _("Range exceeded."));
262  return -1;
263  }
264 
265  self->value.intval = (int) l;
266  break;
267  }
268 
269  default:
270  PyErr_SetString (PyExc_RuntimeError,
271  _("Unhandled type in parameter value."));
272  return -1;
273  }
274 
275  return 0;
276 }
277 
278 /* Set an attribute. Returns -1 on error, with a python exception set. */
279 static int
280 set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
281 {
282  if (PyString_Check (attr_name)
283 #ifdef IS_PY3K
284  && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
285 #else
286  && ! strcmp (PyString_AsString (attr_name), "value"))
287 #endif
288  {
289  if (!val)
290  {
291  PyErr_SetString (PyExc_RuntimeError,
292  _("Cannot delete a parameter's value."));
293  return -1;
294  }
295  return set_parameter_value ((parmpy_object *) obj, val);
296  }
297 
298  return PyObject_GenericSetAttr (obj, attr_name, val);
299 }
300 
301 /* A helper function which returns a documentation string for an
302  object. */
303 
304 static char *
305 get_doc_string (PyObject *object, PyObject *attr)
306 {
307  char *result = NULL;
308 
309  if (PyObject_HasAttr (object, attr))
310  {
311  PyObject *ds_obj = PyObject_GetAttr (object, attr);
312 
313  if (ds_obj && gdbpy_is_string (ds_obj))
314  {
315  result = python_string_to_host_string (ds_obj);
316  if (result == NULL)
318  }
319  Py_XDECREF (ds_obj);
320  }
321  if (! result)
322  result = xstrdup (_("This command is not documented."));
323  return result;
324 }
325 
326 /* Helper function which will execute a METHOD in OBJ passing the
327  argument ARG. ARG can be NULL. METHOD should return a Python
328  string. If this function returns NULL, there has been an error and
329  the appropriate exception set. */
330 static char *
331 call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
332 {
333  char *data = NULL;
334  PyObject *result = PyObject_CallMethodObjArgs (obj, method, arg, NULL);
335 
336  if (! result)
337  return NULL;
338 
339  if (gdbpy_is_string (result))
340  {
341  data = python_string_to_host_string (result);
342  Py_DECREF (result);
343  if (! data)
344  return NULL;
345  }
346  else
347  {
348  PyErr_SetString (PyExc_RuntimeError,
349  _("Parameter must return a string value."));
350  Py_DECREF (result);
351  return NULL;
352  }
353 
354  return data;
355 }
356 
357 /* A callback function that is registered against the respective
358  add_setshow_* set_doc prototype. This function will either call
359  the Python function "get_set_string" or extract the Python
360  attribute "set_doc" and return the contents as a string. If
361  neither exist, insert a string indicating the Parameter is not
362  documented. */
363 static void
364 get_set_value (char *args, int from_tty,
365  struct cmd_list_element *c)
366 {
367  PyObject *obj = (PyObject *) get_cmd_context (c);
368  char *set_doc_string;
371  PyObject *set_doc_func = PyString_FromString ("get_set_string");
372 
373  if (! set_doc_func)
374  goto error;
375 
376  if (PyObject_HasAttr (obj, set_doc_func))
377  {
378  set_doc_string = call_doc_function (obj, set_doc_func, NULL);
379  if (! set_doc_string)
380  goto error;
381  }
382  else
383  {
384  /* We have to preserve the existing < GDB 7.3 API. If a
385  callback function does not exist, then attempt to read the
386  set_doc attribute. */
387  set_doc_string = get_doc_string (obj, set_doc_cst);
388  }
389 
390  make_cleanup (xfree, set_doc_string);
391  fprintf_filtered (gdb_stdout, "%s\n", set_doc_string);
392 
393  Py_XDECREF (set_doc_func);
394  do_cleanups (cleanup);
395  return;
396 
397  error:
398  Py_XDECREF (set_doc_func);
400  do_cleanups (cleanup);
401  return;
402 }
403 
404 /* A callback function that is registered against the respective
405  add_setshow_* show_doc prototype. This function will either call
406  the Python function "get_show_string" or extract the Python
407  attribute "show_doc" and return the contents as a string. If
408  neither exist, insert a string indicating the Parameter is not
409  documented. */
410 static void
411 get_show_value (struct ui_file *file, int from_tty,
412  struct cmd_list_element *c,
413  const char *value)
414 {
415  PyObject *obj = (PyObject *) get_cmd_context (c);
416  char *show_doc_string = NULL;
419  PyObject *show_doc_func = PyString_FromString ("get_show_string");
420 
421  if (! show_doc_func)
422  goto error;
423 
424  if (PyObject_HasAttr (obj, show_doc_func))
425  {
426  PyObject *val_obj = PyString_FromString (value);
427 
428  if (! val_obj)
429  goto error;
430 
431  show_doc_string = call_doc_function (obj, show_doc_func, val_obj);
432  Py_DECREF (val_obj);
433  if (! show_doc_string)
434  goto error;
435 
436  make_cleanup (xfree, show_doc_string);
437 
438  fprintf_filtered (file, "%s\n", show_doc_string);
439  }
440  else
441  {
442  /* We have to preserve the existing < GDB 7.3 API. If a
443  callback function does not exist, then attempt to read the
444  show_doc attribute. */
445  show_doc_string = get_doc_string (obj, show_doc_cst);
446  make_cleanup (xfree, show_doc_string);
447  fprintf_filtered (file, "%s %s\n", show_doc_string, value);
448  }
449 
450  Py_XDECREF (show_doc_func);
451  do_cleanups (cleanup);
452  return;
453 
454  error:
455  Py_XDECREF (show_doc_func);
457  do_cleanups (cleanup);
458  return;
459 }
460 
461 
462 /* A helper function that dispatches to the appropriate add_setshow
463  function. */
464 static void
465 add_setshow_generic (int parmclass, enum command_class cmdclass,
466  char *cmd_name, parmpy_object *self,
467  char *set_doc, char *show_doc, char *help_doc,
468  struct cmd_list_element **set_list,
469  struct cmd_list_element **show_list)
470 {
471  struct cmd_list_element *param = NULL;
472  const char *tmp_name = NULL;
473 
474  switch (parmclass)
475  {
476  case var_boolean:
477 
478  add_setshow_boolean_cmd (cmd_name, cmdclass,
479  &self->value.intval, set_doc, show_doc,
480  help_doc, get_set_value, get_show_value,
481  set_list, show_list);
482 
483  break;
484 
485  case var_auto_boolean:
486  add_setshow_auto_boolean_cmd (cmd_name, cmdclass,
487  &self->value.autoboolval,
488  set_doc, show_doc, help_doc,
490  set_list, show_list);
491  break;
492 
493  case var_uinteger:
494  add_setshow_uinteger_cmd (cmd_name, cmdclass,
495  &self->value.uintval, set_doc, show_doc,
496  help_doc, get_set_value, get_show_value,
497  set_list, show_list);
498  break;
499 
500  case var_integer:
501  add_setshow_integer_cmd (cmd_name, cmdclass,
502  &self->value.intval, set_doc, show_doc,
503  help_doc, get_set_value, get_show_value,
504  set_list, show_list); break;
505 
506  case var_string:
507  add_setshow_string_cmd (cmd_name, cmdclass,
508  &self->value.stringval, set_doc, show_doc,
509  help_doc, get_set_value, get_show_value,
510  set_list, show_list); break;
511 
512  case var_string_noescape:
513  add_setshow_string_noescape_cmd (cmd_name, cmdclass,
514  &self->value.stringval,
515  set_doc, show_doc, help_doc,
517  set_list, show_list);
518 
519  break;
520 
522  add_setshow_optional_filename_cmd (cmd_name, cmdclass,
523  &self->value.stringval, set_doc,
524  show_doc, help_doc, get_set_value,
525  get_show_value, set_list,
526  show_list);
527  break;
528 
529  case var_filename:
530  add_setshow_filename_cmd (cmd_name, cmdclass,
531  &self->value.stringval, set_doc, show_doc,
532  help_doc, get_set_value, get_show_value,
533  set_list, show_list); break;
534 
535  case var_zinteger:
536  add_setshow_zinteger_cmd (cmd_name, cmdclass,
537  &self->value.intval, set_doc, show_doc,
538  help_doc, get_set_value, get_show_value,
539  set_list, show_list);
540  break;
541 
542  case var_enum:
543  add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
544  &self->value.cstringval, set_doc, show_doc,
545  help_doc, get_set_value, get_show_value,
546  set_list, show_list);
547  /* Initialize the value, just in case. */
548  self->value.cstringval = self->enumeration[0];
549  break;
550  }
551 
552  /* Lookup created parameter, and register Python object against the
553  parameter context. Perform this task against both lists. */
554  tmp_name = cmd_name;
555  param = lookup_cmd (&tmp_name, *show_list, "", 0, 1);
556  if (param)
557  set_cmd_context (param, self);
558 
559  tmp_name = cmd_name;
560  param = lookup_cmd (&tmp_name, *set_list, "", 0, 1);
561  if (param)
562  set_cmd_context (param, self);
563 }
564 
565 /* A helper which computes enum values. Returns 1 on success. Returns 0 on
566  error, with a python exception set. */
567 static int
568 compute_enum_values (parmpy_object *self, PyObject *enum_values)
569 {
570  Py_ssize_t size, i;
571  struct cleanup *back_to;
572 
573  if (! enum_values)
574  {
575  PyErr_SetString (PyExc_RuntimeError,
576  _("An enumeration is required for PARAM_ENUM."));
577  return 0;
578  }
579 
580  if (! PySequence_Check (enum_values))
581  {
582  PyErr_SetString (PyExc_RuntimeError,
583  _("The enumeration is not a sequence."));
584  return 0;
585  }
586 
587  size = PySequence_Size (enum_values);
588  if (size < 0)
589  return 0;
590  if (size == 0)
591  {
592  PyErr_SetString (PyExc_RuntimeError,
593  _("The enumeration is empty."));
594  return 0;
595  }
596 
597  self->enumeration = xmalloc ((size + 1) * sizeof (char *));
598  back_to = make_cleanup (free_current_contents, &self->enumeration);
599  memset (self->enumeration, 0, (size + 1) * sizeof (char *));
600 
601  for (i = 0; i < size; ++i)
602  {
603  PyObject *item = PySequence_GetItem (enum_values, i);
604 
605  if (! item)
606  {
607  do_cleanups (back_to);
608  return 0;
609  }
610  if (! gdbpy_is_string (item))
611  {
612  Py_DECREF (item);
613  do_cleanups (back_to);
614  PyErr_SetString (PyExc_RuntimeError,
615  _("The enumeration item not a string."));
616  return 0;
617  }
618  self->enumeration[i] = python_string_to_host_string (item);
619  Py_DECREF (item);
620  if (self->enumeration[i] == NULL)
621  {
622  do_cleanups (back_to);
623  return 0;
624  }
625  make_cleanup (xfree, (char *) self->enumeration[i]);
626  }
627 
628  discard_cleanups (back_to);
629  return 1;
630 }
631 
632 /* Object initializer; sets up gdb-side structures for command.
633 
634  Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
635 
636  NAME is the name of the parameter. It may consist of multiple
637  words, in which case the final word is the name of the new command,
638  and earlier words must be prefix commands.
639 
640  CMDCLASS is the kind of command. It should be one of the COMMAND_*
641  constants defined in the gdb module.
642 
643  PARMCLASS is the type of the parameter. It should be one of the
644  PARAM_* constants defined in the gdb module.
645 
646  If PARMCLASS is PARAM_ENUM, then the final argument should be a
647  collection of strings. These strings are the valid values for this
648  parameter.
649 
650  The documentation for the parameter is taken from the doc string
651  for the python class.
652 
653  Returns -1 on error, with a python exception set. */
654 
655 static int
656 parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
657 {
658  parmpy_object *obj = (parmpy_object *) self;
659  const char *name;
660  char *set_doc, *show_doc, *doc;
661  char *cmd_name;
662  int parmclass, cmdtype;
663  PyObject *enum_values = NULL;
664  struct cmd_list_element **set_list, **show_list;
665 
666  if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
667  &enum_values))
668  return -1;
669 
670  if (cmdtype != no_class && cmdtype != class_run
671  && cmdtype != class_vars && cmdtype != class_stack
672  && cmdtype != class_files && cmdtype != class_support
673  && cmdtype != class_info && cmdtype != class_breakpoint
674  && cmdtype != class_trace && cmdtype != class_obscure
675  && cmdtype != class_maintenance)
676  {
677  PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument."));
678  return -1;
679  }
680 
681  if (parmclass != var_boolean /* ARI: var_boolean */
682  && parmclass != var_auto_boolean
683  && parmclass != var_uinteger && parmclass != var_integer
684  && parmclass != var_string && parmclass != var_string_noescape
685  && parmclass != var_optional_filename && parmclass != var_filename
686  && parmclass != var_zinteger && parmclass != var_enum)
687  {
688  PyErr_SetString (PyExc_RuntimeError,
689  _("Invalid parameter class argument."));
690  return -1;
691  }
692 
693  if (enum_values && parmclass != var_enum)
694  {
695  PyErr_SetString (PyExc_RuntimeError,
696  _("Only PARAM_ENUM accepts a fourth argument."));
697  return -1;
698  }
699  if (parmclass == var_enum)
700  {
701  if (! compute_enum_values (obj, enum_values))
702  return -1;
703  }
704  else
705  obj->enumeration = NULL;
706  obj->type = (enum var_types) parmclass;
707  memset (&obj->value, 0, sizeof (obj->value));
708 
709  cmd_name = gdbpy_parse_command_name (name, &set_list,
710  &setlist);
711 
712  if (! cmd_name)
713  return -1;
714  xfree (cmd_name);
715  cmd_name = gdbpy_parse_command_name (name, &show_list,
716  &showlist);
717  if (! cmd_name)
718  return -1;
719 
720  set_doc = get_doc_string (self, set_doc_cst);
721  show_doc = get_doc_string (self, show_doc_cst);
722  doc = get_doc_string (self, gdbpy_doc_cst);
723 
724  Py_INCREF (self);
725 
726  TRY
727  {
728  add_setshow_generic (parmclass, (enum command_class) cmdtype,
729  cmd_name, obj,
730  set_doc, show_doc,
731  doc, set_list, show_list);
732  }
733  CATCH (except, RETURN_MASK_ALL)
734  {
735  xfree (cmd_name);
736  xfree (set_doc);
737  xfree (show_doc);
738  xfree (doc);
739  Py_DECREF (self);
740  PyErr_Format (except.reason == RETURN_QUIT
741  ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
742  "%s", except.message);
743  return -1;
744  }
745  END_CATCH
746 
747  return 0;
748 }
749 
750 
751 
752 /* Initialize the 'parameters' module. */
753 int
755 {
756  int i;
757 
758  parmpy_object_type.tp_new = PyType_GenericNew;
759  if (PyType_Ready (&parmpy_object_type) < 0)
760  return -1;
761 
762  set_doc_cst = PyString_FromString ("set_doc");
763  if (! set_doc_cst)
764  return -1;
765  show_doc_cst = PyString_FromString ("show_doc");
766  if (! show_doc_cst)
767  return -1;
768 
769  for (i = 0; parm_constants[i].name; ++i)
770  {
771  if (PyModule_AddIntConstant (gdb_module,
772  parm_constants[i].name,
773  parm_constants[i].value) < 0)
774  return -1;
775  }
776 
777  return gdb_pymodule_addobject (gdb_module, "Parameter",
778  (PyObject *) &parmpy_object_type);
779 }
780 
781 
782 
783 PyTypeObject parmpy_object_type =
784 {
785  PyVarObject_HEAD_INIT (NULL, 0)
786  "gdb.Parameter", /*tp_name*/
787  sizeof (parmpy_object), /*tp_basicsize*/
788  0, /*tp_itemsize*/
789  0, /*tp_dealloc*/
790  0, /*tp_print*/
791  0, /*tp_getattr*/
792  0, /*tp_setattr*/
793  0, /*tp_compare*/
794  0, /*tp_repr*/
795  0, /*tp_as_number*/
796  0, /*tp_as_sequence*/
797  0, /*tp_as_mapping*/
798  0, /*tp_hash */
799  0, /*tp_call*/
800  0, /*tp_str*/
801  get_attr, /*tp_getattro*/
802  set_attr, /*tp_setattro*/
803  0, /*tp_as_buffer*/
804  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
805  "GDB parameter object", /* tp_doc */
806  0, /* tp_traverse */
807  0, /* tp_clear */
808  0, /* tp_richcompare */
809  0, /* tp_weaklistoffset */
810  0, /* tp_iter */
811  0, /* tp_iternext */
812  0, /* tp_methods */
813  0, /* tp_members */
814  0, /* tp_getset */
815  0, /* tp_base */
816  0, /* tp_dict */
817  0, /* tp_descr_get */
818  0, /* tp_descr_set */
819  0, /* tp_dictoffset */
820  parmpy_init, /* tp_init */
821  0, /* tp_alloc */
822 };
const char * string
Definition: signals.c:50
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
Definition: py-utils.c:437
void set_cmd_context(struct cmd_list_element *cmd, void *context)
Definition: cli-decode.c:141
static int parmpy_init(PyObject *self, PyObject *args, PyObject *kwds)
Definition: py-param.c:656
#define Py_DECREF(op)
char * stringval
Definition: py-param.c:66
void * get_cmd_context(struct cmd_list_element *cmd)
Definition: cli-decode.c:147
PyTypeObject parmpy_object_type
Definition: py-param.c:783
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)
Definition: cli-decode.c:719
static PyObject * get_attr(PyObject *obj, PyObject *attr_name)
Definition: py-param.c:102
void xfree(void *)
Definition: common-utils.c:97
int gdbpy_is_string(PyObject *obj)
Definition: py-utils.c:228
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)
Definition: cli-decode.c:487
#define INT_MAX
Definition: defs.h:509
#define INT_MIN
Definition: defs.h:513
struct ui_file * gdb_stdout
Definition: main.c:71
static PyObject * show_doc_cst
Definition: py-param.c:96
static int set_attr(PyObject *obj, PyObject *attr_name, PyObject *val)
Definition: py-param.c:280
const char * cstringval
Definition: py-param.c:69
#define _(String)
Definition: gdb_locale.h:40
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, char *cmdtype, int allow_unknown, int ignore_help_classes)
Definition: cli-decode.c:1475
#define END_CATCH
var_types
Definition: command.h:60
const char ** enumeration
Definition: py-param.c:86
PyTypeObject parmpy_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("parmpy_object")
unsigned int uintval
Definition: py-param.c:63
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)
Definition: cli-decode.c:604
#define TRY
struct cmd_list_element * setlist
Definition: cli-cmds.c:135
const char *const name
Definition: aarch64-tdep.c:68
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)
Definition: cli-decode.c:516
PyObject * gdbpy_doc_cst
Definition: python.c:119
int gdbpy_initialize_parameters(void)
Definition: py-param.c:754
#define CATCH(EXCEPTION, MASK)
#define UINT_MAX
Definition: defs.h:505
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2351
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)
Definition: cli-decode.c:694
static void get_show_value(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: py-param.c:411
struct cmd_list_element * showlist
Definition: cli-cmds.c:143
void free_current_contents(void *ptr)
Definition: utils.c:476
PyObject * gdbpy_parameter_value(enum var_types type, void *var)
Definition: python.c:504
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
char * python_string_to_host_string(PyObject *obj)
Definition: py-utils.c:210
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)
Definition: cli-decode.c:585
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:781
char * gdbpy_parse_command_name(const char *name, struct cmd_list_element ***base_list, struct cmd_list_element **start_list)
Definition: py-cmd.c:428
static char * get_doc_string(PyObject *object, PyObject *attr)
Definition: py-param.c:305
struct cleanup * ensure_python_env(struct gdbarch *gdbarch, const struct language_defn *language)
Definition: python.c:247
void * xmalloc(YYSIZE_T)
static PyObject * set_doc_cst
Definition: py-param.c:95
Definition: value.c:172
static int set_parameter_value(parmpy_object *self, PyObject *value)
Definition: py-param.c:122
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)
Definition: py-param.c:465
const char const char int
Definition: command.h:229
void discard_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:213
const struct language_defn * current_language
Definition: language.c:85
PyObject_HEAD enum var_types type
Definition: py-param.c:78
command_class
Definition: command.h:33
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)
Definition: cli-decode.c:669
union parmpy_variable value
Definition: py-param.c:81
void gdbpy_print_stack(void)
Definition: python.c:1199
char * name
Definition: py-param.c:34
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)
Definition: cli-decode.c:563
auto_boolean
Definition: defs.h:196
static int compute_enum_values(parmpy_object *self, PyObject *enum_values)
Definition: py-param.c:568
int gdb_py_int_as_long(PyObject *obj, long *result)
Definition: py-utils.c:407
PyObject * gdb_module
Definition: python.c:112
void error(const char *fmt,...)
Definition: errors.c:38
size_t size
Definition: go32-nat.c:242
static char * call_doc_function(PyObject *obj, PyObject *method, PyObject *arg)
Definition: py-param.c:331
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)
Definition: cli-decode.c:626
static void get_set_value(char *args, int from_tty, struct cmd_list_element *c)
Definition: py-param.c:364
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
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)
Definition: cli-decode.c:541
struct parmpy_object parmpy_object
Definition: py-param.c:89
enum auto_boolean autoboolval
Definition: py-param.c:60
#define PyVarObject_HEAD_INIT(type, size)