From 0987cf351276271164c94b3bc8ca54482573bda4 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Tue, 10 Dec 2013 16:20:08 -0800 Subject: 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. --- gdb/testsuite/gdb.python/py-value.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'gdb/testsuite/gdb.python/py-value.c') diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index 0c94e64..4f8c27b 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -16,6 +16,8 @@ along with this program. If not, see . */ #include +#include +#include struct s { @@ -39,6 +41,13 @@ typedef struct s *PTR; enum e evalue = TWO; +struct str +{ + int length; + /* Variable length. */ + char text[1]; +}; + #ifdef __cplusplus struct Base { @@ -86,6 +95,8 @@ main (int argc, char *argv[]) int i = 2; int *ptr_i = &i; const char *sn = 0; + struct str *xstr; + s.a = 3; s.b = 5; u.a = 7; @@ -96,6 +107,12 @@ main (int argc, char *argv[]) ptr_ref(ptr_i); #endif +#define STR_LENGTH 100 + xstr = (struct str *) malloc (sizeof (*xstr) + STR_LENGTH); + xstr->length = STR_LENGTH; + memset (xstr->text, 'x', STR_LENGTH); +#undef STR_LENGTH + save_argv = argv; /* break to inspect struct and union */ return 0; } -- cgit v1.1