diff options
author | Doug Evans <dje@google.com> | 2013-12-10 16:20:08 -0800 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2013-12-10 16:20:08 -0800 |
commit | 0987cf351276271164c94b3bc8ca54482573bda4 (patch) | |
tree | 6f5e90b28a6fcbdadcfd1a29c56c3ac5b8fde3df /gdb/testsuite | |
parent | 34dc884e1711a3d00c6815bf32aa5823390ff1f6 (diff) | |
download | gdb-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/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-value.c | 17 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-value.exp | 6 |
3 files changed, 32 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ec01bff..c850604 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2013-12-10 Doug Evans <dje@google.com> + + * 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. + 2013-12-10 Andrew Burgess <aburgess@broadcom.com> * lib/gdb.exp (gdb_compile_shlib): Add call to get_compiler_info, 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 <http://www.gnu.org/licenses/>. */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> 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; } diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 43de063..a052104 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -291,6 +291,12 @@ proc test_value_in_inferior {} { # For the purposes of this test, use repr() gdb_py_test_silent_cmd "python nullst = nullst.string (length = 9)" "get string beyond null" 1 gdb_test "python print (repr(nullst))" "u?'divide\\\\x00et'" + + # Test fetching a string longer than its declared (in C) size. + # PR 16286 + gdb_py_test_silent_cmd "python xstr = gdb.parse_and_eval('xstr')" "get xstr" 1 + gdb_test "python print xstr\['text'\].string (length = xstr\['length'\])" "x{100}" \ + "read string beyond declared size" } proc test_lazy_strings {} { |