From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19165 invoked by alias); 18 Nov 2008 15:54:24 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 19044 invoked by uid 306); 18 Nov 2008 15:54:22 -0000 Date: Tue, 18 Nov 2008 15:54:00 -0000 Message-ID: <20081118155422.19001.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: gdb X-Git-Refname: refs/heads/archer-tromey-python X-Git-Reftype: branch X-Git-Oldrev: 98011209ea5a2fc236cce680946b1097caa80df7 X-Git-Newrev: 01af16dc305d029f7bc580ec848b60b7f2b2a880 X-SW-Source: 2008-q4/txt/msg00121.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via 01af16dc305d029f7bc580ec848b60b7f2b2a880 (commit) from 98011209ea5a2fc236cce680946b1097caa80df7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 01af16dc305d029f7bc580ec848b60b7f2b2a880 Author: Tom Tromey Date: Tue Nov 18 08:54:03 2008 -0700 gdb * python/python-internal.h (gdbpy_doc_cst): Declare. * python/python-cmd.c (cmdpy_init): Use gdbpy_doc_cst. Don't set tp_new or tp_init. (cmdpy_object_type): Add extra entries. Set tp_init and tp_new. * python/python.c (gdbpy_doc_cst): New global. (_initialize_python): Initialize it. * python/python-param.c (set_doc_cst, show_doc_cst): New globals. (gdbpy_initialize_parameters): Initialize them. Don't set tp_new or tp_init. (parmpy_init): Use gdbpy_doc_cst. Get set and show help. Don't examine __doc__. (get_doc_string): New function. (parmpy_object_type): Add extra entries. Set tp_init and tp_new. gdb/doc * gdb.texinfo (Parameters In Python): Document set_doc, show_doc. ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 16 ++++++++++ gdb/doc/ChangeLog | 4 ++ gdb/doc/gdb.texinfo | 14 +++++++++ gdb/python/python-cmd.c | 18 ++++++++--- gdb/python/python-internal.h | 1 + gdb/python/python-param.c | 64 +++++++++++++++++++++++++++++++---------- gdb/python/python.c | 2 + 7 files changed, 98 insertions(+), 21 deletions(-) First 500 lines of diff: diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c51b9b1..c5fa878 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,19 @@ +2008-11-18 Tom Tromey + + * python/python-internal.h (gdbpy_doc_cst): Declare. + * python/python-cmd.c (cmdpy_init): Use gdbpy_doc_cst. Don't set + tp_new or tp_init. + (cmdpy_object_type): Add extra entries. Set tp_init and tp_new. + * python/python.c (gdbpy_doc_cst): New global. + (_initialize_python): Initialize it. + * python/python-param.c (set_doc_cst, show_doc_cst): New globals. + (gdbpy_initialize_parameters): Initialize them. Don't set + tp_new or tp_init. + (parmpy_init): Use gdbpy_doc_cst. Get set and show help. Don't + examine __doc__. + (get_doc_string): New function. + (parmpy_object_type): Add extra entries. Set tp_init and tp_new. + 2008-11-17 Tom Tromey * varobj.c (install_default_visualizer): Remove 'type' argument. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index e205dea..385bbca 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-11-18 Tom Tromey + + * gdb.texinfo (Parameters In Python): Document set_doc, show_doc. + 2008-11-16 Tom Tromey * gdb.texinfo (Types From Inferior): Update. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index eb24ece..9446ce4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18553,6 +18553,20 @@ documentation string for the parameter's class, if there is one. If there is no documentation string, a default value is used. @end defmethod +@defivar Parameter set_doc +If this attribute exists, and is a string, then its value is used as +the help text for this parameter's @code{set} command. The value is +examined when @code{Parameter.__init__} is invoked; subsequent changes +have no effect. +@end defivar + +@defivar Parameter show_doc +If this attribute exists, and is a string, then its value is used as +the help text for this parameter's @code{show} command. The value is +examined when @code{Parameter.__init__} is invoked; subsequent changes +have no effect. +@end defivar + @defivar Parameter value The @code{value} attribute holds the underlying value of the parameter. It can be read and assigned to just as any other diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c index 63b5432..91cdc7f 100644 --- a/gdb/python/python-cmd.c +++ b/gdb/python/python-cmd.c @@ -389,9 +389,9 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds) if (! cmd_name) return -1; - if (PyObject_HasAttrString (self, "__doc__")) + if (PyObject_HasAttr (self, gdbpy_doc_cst)) { - PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__"); + PyObject *ds_obj = PyObject_GetAttr (self, gdbpy_doc_cst); if (ds_obj && gdbpy_is_string (ds_obj)) docstring = python_string_to_host_string (ds_obj); } @@ -437,8 +437,6 @@ gdbpy_initialize_commands (void) { int i; - cmdpy_object_type.tp_new = PyType_GenericNew; - cmdpy_object_type.tp_init = cmdpy_init; if (PyType_Ready (&cmdpy_object_type) < 0) return; @@ -515,5 +513,15 @@ static PyTypeObject cmdpy_object_type = 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - cmdpy_object_methods /* tp_methods */ + cmdpy_object_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + cmdpy_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew /* tp_new */ }; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 19f39cb..a03d889 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -136,5 +136,6 @@ char *gdbpy_get_display_hint (PyObject *printer); extern PyObject *gdbpy_children_cst; extern PyObject *gdbpy_to_string_cst; extern PyObject *gdbpy_display_hint_cst; +extern PyObject *gdbpy_doc_cst; #endif /* GDB_PYTHON_INTERNAL_H */ diff --git a/gdb/python/python-param.c b/gdb/python/python-param.c index cf1ceaa..96c92c8 100644 --- a/gdb/python/python-param.c +++ b/gdb/python/python-param.c @@ -89,6 +89,10 @@ typedef struct parmpy_object parmpy_object; static PyTypeObject parmpy_object_type; +/* Some handy string constants. */ +static PyObject *set_doc_cst; +static PyObject *show_doc_cst; + /* Get an attribute. */ @@ -374,6 +378,23 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values) return 1; } +/* A helper function which returns a documentation string for an + object. */ +static char * +get_doc_string (PyObject *object, PyObject *attr) +{ + char *result = NULL; + if (PyObject_HasAttr (object, attr)) + { + PyObject *ds_obj = PyObject_GetAttr (object, attr); + if (ds_obj && gdbpy_is_string (ds_obj)) + result = python_string_to_host_string (ds_obj); + } + if (! result) + result = xstrdup ("This command is not documented."); + return result; +} + /* Object initializer; sets up gdb-side structures for command. Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM]) @@ -401,7 +422,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) { parmpy_object *obj = (parmpy_object *) self; char *name; - char *docstring = NULL; + char *set_doc, *show_doc; char *cmd_name; int parmclass, cmdtype; PyObject *enum_values = NULL; @@ -458,15 +479,10 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) if (! cmd_name) return -1; - /* FIXME: need set and show docs. */ - if (PyObject_HasAttrString (self, "__doc__")) - { - PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__"); - if (ds_obj && gdbpy_is_string (ds_obj)) - docstring = python_string_to_host_string (ds_obj); - } - if (! docstring) - docstring = xstrdup ("This command is not documented."); + /* FIXME: there is no way to register a destructor function for + set/show commands. So, these are leaked. */ + set_doc = get_doc_string (self, set_doc_cst); + show_doc = get_doc_string (self, show_doc_cst); Py_INCREF (self); @@ -474,13 +490,14 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds) { add_setshow_generic (parmclass, (enum command_class) cmdtype, cmd_name, obj, - "FIXME: set doc", "FIXME: show doc", - docstring, set_list, show_list); + set_doc, show_doc, + NULL, set_list, show_list); } if (except.reason < 0) { xfree (cmd_name); - xfree (docstring); + xfree (set_doc); + xfree (show_doc); Py_DECREF (self); PyErr_Format (except.reason == RETURN_QUIT ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, @@ -498,11 +515,16 @@ gdbpy_initialize_parameters (void) { int i; - parmpy_object_type.tp_new = PyType_GenericNew; - parmpy_object_type.tp_init = parmpy_init; if (PyType_Ready (&parmpy_object_type) < 0) return; + set_doc_cst = PyString_FromString ("set_doc"); + if (! set_doc_cst) + return; + show_doc_cst = PyString_FromString ("show_doc"); + if (! show_doc_cst) + return; + for (i = 0; parm_constants[i].name; ++i) { if (PyModule_AddIntConstant (gdb_module, @@ -548,5 +570,15 @@ static PyTypeObject parmpy_object_type = 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0 /* tp_methods */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + parmpy_init, /* tp_init */ + 0, /* tp_alloc */ + PyType_GenericNew /* tp_new */ }; diff --git a/gdb/python/python.c b/gdb/python/python.c index 1ff3c25..340213f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -66,6 +66,7 @@ PyObject *gdb_module; PyObject *gdbpy_to_string_cst; PyObject *gdbpy_children_cst; PyObject *gdbpy_display_hint_cst; +PyObject *gdbpy_doc_cst; /* Given a command_line, return a command string suitable for passing to Python. Lines in the string are separated by newlines. The @@ -1276,6 +1277,7 @@ Enables or disables auto-loading of Python code when an object is opened."), gdbpy_to_string_cst = PyString_FromString ("to_string"); gdbpy_children_cst = PyString_FromString ("children"); gdbpy_display_hint_cst = PyString_FromString ("display_hint"); + gdbpy_doc_cst = PyString_FromString ("__doc__"); /* Create a couple objects which are used for Python's stdout and stderr. */ hooks/post-receive -- Repository for Project Archer.