This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] string improvement (was Re: Value.string method)
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: archer ml <archer at sourceware dot org>
- Date: Thu, 20 Nov 2008 01:35:54 -0200
- Subject: [python] string improvement (was Re: Value.string method)
- References: <1227126380.28256.86.camel@localhost.localdomain>
El miÃ, 19-11-2008 a las 18:26 -0200, Thiago Jung Bauermann escribiÃ:
> One thing which just crossed my mind is that this code doesn't take into
> accound values which are internal to GDB, just values which live in the
> inferior's memory.
Turns out it actually worked for GDB-hosted strings. It was inefficient
though, because GDB would allocate memory in the inferior, copy the
string there and then read it back with read_string. Not too smart, and
it also requires a live process in order to run malloc.
This patch adds a special case for GDB-hosted strings, enabling the
method to work even when there's no inferior running. It also has some
minor cleanups.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
commit e78e391a74c8ebad2f920116f3829d48e375c02a
Author: Thiago Jung Bauermann <bauerman@br.ibm.com>
Date: Thu Nov 20 01:16:39 2008 -0200
* c-lang.c (c_getstr): Add special case for GDB-hosted strings, and
some minor cleanups.
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index ffba774..759e942 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -202,7 +202,7 @@ c_printstr (struct ui_file *stream, const gdb_byte *string,
int
c_getstr (struct value *value, gdb_byte **buffer, int *length)
{
- int fetchlimit, errno, width;
+ int fetchlimit, err, width;
struct type *type = value_type (value);
struct type *element_type = TYPE_TARGET_TYPE (type);
@@ -240,14 +240,26 @@ c_getstr (struct value *value, gdb_byte **buffer, int *length)
width = TYPE_LENGTH (element_type);
- errno = read_string (value_as_address (value), -1, width, fetchlimit, buffer,
- length);
+ /* If the string lives in GDB's memory intead of the inferior's, then we
+ just need to copy it to BUFFER. Also, since such strings are arrays
+ with known size, FETCHLIMIT will hold the size of the string. */
+ if (((VALUE_LVAL (value) == not_lval)
+ || (VALUE_LVAL (value) == lval_internalvar)) && (fetchlimit != -1))
+ {
+ *length = fetchlimit;
+ *buffer = xmalloc (*length * width);
+ memcpy (*buffer, value_contents (value), *length * width);
+ err = 0;
+ }
+ else
+ err = read_string (value_as_address (value), -1, width, fetchlimit,
+ buffer, length);
/* If the last character is NULL, subtract it from length. */
if (extract_unsigned_integer (*buffer + *length - width, width) == 0)
*length -= width;
- return errno;
+ return err;
error:
{
@@ -256,8 +268,13 @@ error:
type_str = type_to_string (type);
if (type_str)
- old_chain = make_cleanup (xfree, type_str);
- error (_("Trying to read string with inappropriate type `%s'."), type_str);
+ {
+ old_chain = make_cleanup (xfree, type_str);
+ error (_("Trying to read string with inappropriate type `%s'."),
+ type_str);
+ }
+ else
+ error (_("Trying to read string with inappropriate type."));
}
}