public inbox for archer-commits@sourceware.org help / color / mirror / Atom feed
From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: gdb Date: Tue, 18 Nov 2008 15:54:00 -0000 [thread overview] Message-ID: <20081118155422.19001.qmail@sourceware.org> (raw) 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 <tromey@redhat.com> 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 <tromey@redhat.com> + + * 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 <tromey@redhat.com> * 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 <tromey@redhat.com> + + * gdb.texinfo (Parameters In Python): Document set_doc, show_doc. + 2008-11-16 Tom Tromey <tromey@redhat.com> * 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; + \f /* 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.
next reply other threads:[~2008-11-18 15:54 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-11-18 15:54 tromey [this message] -- strict thread matches above, loose matches on Subject: below -- 2009-04-07 20:28 tromey 2009-03-24 17:27 tromey 2009-02-05 19:56 tromey 2008-12-17 23:10 tromey 2008-12-15 22:38 tromey 2008-12-13 0:37 tromey 2008-12-12 23:54 tromey 2008-12-10 15:28 tromey 2008-12-09 0:33 tromey 2008-12-02 21:29 tromey 2008-12-01 19:10 tromey 2008-11-25 21:17 tromey 2008-11-21 18:25 tromey 2008-11-18 18:52 tromey 2008-11-17 15:45 tromey 2008-11-16 22:18 tromey 2008-11-16 16:56 tromey 2008-11-12 1:54 tromey 2008-11-10 14:15 tromey 2008-11-06 21:11 tromey 2008-11-06 19:58 tromey 2008-10-23 22:27 tromey 2008-10-23 21:28 tromey 2008-10-22 18:18 tromey 2008-10-21 18:32 tromey
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20081118155422.19001.qmail@sourceware.org \ --to=tromey@sourceware.org \ --cc=archer-commits@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).