diff options
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/printcmd.c | 3 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/printcmds.exp | 8 |
4 files changed, 20 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2400982..291e83a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-03-03 Sergio Durigan Junior <sergiodj@redhat.com> + + * printcmd.c (print_c_string): Check also for TYPE_CODE_PTR + when verifying if dealing with a convenience variable. + 2020-03-03 Luis Machado <luis.machado@linaro.org> * auxv.c (default_print_auxv_entry): Add new AUXV entries. diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 7970414..78d8d3d 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2260,7 +2260,8 @@ printf_c_string (struct ui_file *stream, const char *format, { const gdb_byte *str; - if (VALUE_LVAL (value) == lval_internalvar + if (TYPE_CODE (value_type (value)) != TYPE_CODE_PTR + && VALUE_LVAL (value) == lval_internalvar && c_is_string_type_p (value_type (value))) { size_t len = TYPE_LENGTH (value_type (value)); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0563fec..28726b8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-03 Sergio Durigan Junior <sergiodj@redhat.com> + + * gdb.base/printcmds.exp: Add test to verify printf of a + variable holding an address. + 2020-03-03 Tom de Vries <tdevries@suse.de> * gdb.mi/gdb2549.exp: Fix "register values t" check-read1 timeout. diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index bd2afc8..c87a151 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -1039,6 +1039,14 @@ gdb_test_no_output "set may-call-functions off" test_printf_convenience_var "with target, may-call-functions off" gdb_test_no_output "set may-call-functions on" +# Test printf of a variable that holds the address to a substring in +# the inferior. This test will not work without a target. +gdb_test_no_output "set var \$test_substr = \(char \*\) \(&teststring\[0\] + 4\)" \ + "set \$test_substr var" +gdb_test "printf \"test_substr val = %s\\n\", \$test_substr" \ + "test_substr val = string contents" \ + "print \$test_substr" + test_integer_literals_accepted test_integer_literals_rejected test_float_accepted |