From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19293 invoked by alias); 21 Nov 2008 18:25:07 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 19189 invoked by uid 306); 21 Nov 2008 18:25:06 -0000 Date: Fri, 21 Nov 2008 18:25:00 -0000 Message-ID: <20081121182506.19149.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: d622890c0091978356760aafbb8bc7adfec3724e X-Git-Newrev: 0fdf3e3468cebce67721a34c04adf813d7dc48eb X-SW-Source: 2008-q4/txt/msg00141.txt.bz2 List-Id: The branch, archer-tromey-python has been updated via 0fdf3e3468cebce67721a34c04adf813d7dc48eb (commit) from d622890c0091978356760aafbb8bc7adfec3724e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 0fdf3e3468cebce67721a34c04adf813d7dc48eb Author: Tom Tromey Date: Fri Nov 21 11:24:44 2008 -0700 gdb * python/python-value.c (value_object_methods) : Accept varargs. (valpy_string): Accept optional encoding argument. gdb/doc * gdb.texinfo (Values From Inferior): Document Value.string. ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 6 ++++++ gdb/doc/ChangeLog | 4 ++++ gdb/doc/gdb.texinfo | 20 ++++++++++++++++++++ gdb/python/python-value.c | 11 +++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) First 500 lines of diff: diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ca4807f..549ca85 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2008-11-21 Tom Tromey + + * python/python-value.c (value_object_methods) : Accept + varargs. + (valpy_string): Accept optional encoding argument. + 2008-11-20 Tom Tromey * gdbtypes.c (delete_main_type): Use TYPE_FIELD_LOC_KIND. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index e6b9a7b..4a557f9 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-11-21 Tom Tromey + + * gdb.texinfo (Values From Inferior): Document Value.string. + 2008-11-18 Tom Tromey * gdb.texinfo (Commands In Python): Document prefix commands. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index fad65e2..18fe77f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18225,6 +18225,26 @@ The result @code{bar} will be a @code{gdb.Value} object holding the value pointed to by @code{foo}. @end defmethod +@defmethod Value string @r{[}encoding@r{]} +If this @code{gdb.Value} represents a string, then this method +converts the contents to a Python string. Otherwise, this method will +throw an exception. + +Strings are recognized in a language-specific way; whether a given +@code{gdb.Value} represents a string is determined by the current +language. + +For C-like languages, a value is a string if it is a pointer to or an +array of characters or ints. The string is assumed to be terminated +by a zero of the appropriate width. + +If the optional @var{encoding} argument is given, it must be a string +naming the encoding of the string in the @code{gdb.Value}. The Python +codec machinery will be used to convert the string. If @var{encoding} +is not given, then the @code{target-charset} (@pxref{Character Sets}) +will be used. +@end defmethod + @defmethod Value type Return the type of this @code{gdb.Value}. The result is a @code{gdb.Type} object. diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index 0712408..e8196ed 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -164,6 +164,13 @@ valpy_string (PyObject *self, PyObject *args) struct value *value = ((value_object *) self)->value; volatile struct gdb_exception except; PyObject *unicode; + const char *encoding = NULL; + + if (!PyArg_ParseTuple (args, "|s", &encoding)) + return NULL; + + if (!encoding) + encoding = target_charset (); TRY_CATCH (except, RETURN_MASK_ALL) { @@ -181,7 +188,7 @@ valpy_string (PyObject *self, PyObject *args) return NULL; } - unicode = target_string_to_unicode (buffer, length); + unicode = PyUnicode_Decode (buffer, length, encoding, NULL); xfree (buffer); return unicode; @@ -905,7 +912,7 @@ static PyMethodDef value_object_methods[] = { { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." }, { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, { "type", valpy_type, METH_NOARGS, "Return type of the value." }, - { "string", valpy_string, METH_NOARGS, + { "string", valpy_string, METH_VARARGS, "Return Unicode string representation of the value." }, {NULL} /* Sentinel */ }; hooks/post-receive -- Repository for Project Archer.