aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-lang.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2013-12-10 16:20:08 -0800
committerDoug Evans <dje@google.com>2013-12-10 16:20:08 -0800
commit0987cf351276271164c94b3bc8ca54482573bda4 (patch)
tree6f5e90b28a6fcbdadcfd1a29c56c3ac5b8fde3df /gdb/c-lang.c
parent34dc884e1711a3d00c6815bf32aa5823390ff1f6 (diff)
downloadgdb-0987cf351276271164c94b3bc8ca54482573bda4.zip
gdb-0987cf351276271164c94b3bc8ca54482573bda4.tar.gz
gdb-0987cf351276271164c94b3bc8ca54482573bda4.tar.bz2
PR 16286
* c-lang.c (c_get_string): Ignore the declared size of the object if a specific length is requested. testsuite/ * gdb.python/py-value.c: #include stdlib.h, string.h. (str): New struct. (main): New local xstr. * gdb.python/py-value.exp (test_value_in_inferior): Add test to fetch a value as a string with a length beyond the declared length of the array.
Diffstat (limited to 'gdb/c-lang.c')
-rw-r--r--gdb/c-lang.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index eecc76d..2c075f4 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -227,9 +227,13 @@ c_printstr (struct ui_file *stream, struct type *type,
until a null character of the appropriate width is found, otherwise
the string is read to the length of characters specified. The size
of a character is determined by the length of the target type of
- the pointer or array. If VALUE is an array with a known length,
- the function will not read past the end of the array. On
- completion, *LENGTH will be set to the size of the string read in
+ the pointer or array.
+
+ If VALUE is an array with a known length, and *LENGTH is -1,
+ the function will not read past the end of the array. However, any
+ declared size of the array is ignored if *LENGTH > 0.
+
+ On completion, *LENGTH will be set to the size of the string read in
characters. (If a length of -1 is specified, the length returned
will not include the null character). CHARSET is always set to the
target charset. */
@@ -309,6 +313,21 @@ c_get_string (struct value *value, gdb_byte **buffer,
{
CORE_ADDR addr = value_as_address (value);
+ /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
+ if length > 0. The old "broken" behaviour is the behaviour we want:
+ The caller may want to fetch 100 bytes from a variable length array
+ implemented using the common idiom of having an array of length 1 at
+ the end of a struct. In this case we want to ignore the declared
+ size of the array. However, it's counterintuitive to implement that
+ behaviour in read_string: what does fetchlimit otherwise mean if
+ length > 0. Therefore we implement the behaviour we want here:
+ If *length > 0, don't specify a fetchlimit. This preserves the
+ previous behaviour. We could move this check above where we know
+ whether the array is declared with a fixed size, but we only want
+ to apply this behaviour when calling read_string. PR 16286. */
+ if (*length > 0)
+ fetchlimit = UINT_MAX;
+
err = read_string (addr, *length, width, fetchlimit,
byte_order, buffer, length);
if (err)