aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-06-10 21:41:51 +0200
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-07-08 23:31:54 +0200
commit1f6f6e21fa86dc3411a6498608f32e9eb24b7851 (patch)
tree37520dd0294952b805f1358230555b20e89bd4a9 /gdb/testsuite
parentea142fbfc9c1708a83d3532257d6728e1f5c142e (diff)
downloadgdb-1f6f6e21fa86dc3411a6498608f32e9eb24b7851.zip
gdb-1f6f6e21fa86dc3411a6498608f32e9eb24b7851.tar.gz
gdb-1f6f6e21fa86dc3411a6498608f32e9eb24b7851.tar.bz2
Ensure GDB printf command can print convenience var strings without a target.
Without this patch, GDB printf command calls malloc on the target, writes the convenience var content to the target, re-reads the content from the target, and then locally printf the string. This implies inferior calls, and does not work when there is no running inferior, or when the inferior is a core dump. With this patch, printf command can printf string convenience variables without inferior function calls. Ada string convenience variables can also be printed. gdb/ChangeLog 2019-07-08 Philippe Waroquiers <philippe.waroquiers@skynet.be> * NEWS: Mention that GDB printf and eval commands can now print C-style and Ada-style convenience var strings without calling the inferior. * printcmd.c (printf_c_string): Locally print GDB internal var instead of transiting via the inferior. (printf_wide_c_string): Likewise. gdb/testsuite/ChangeLog 2019-07-08 Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/printcmds.exp: Test printing C string and C wide string convenience vars without transiting via the inferior. Also make test names unique.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/printcmds.exp59
2 files changed, 60 insertions, 5 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a6d6843..f8ef540 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-08 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
+ * gdb.base/printcmds.exp: Test printing C string and
+ C wide string convenience vars without transiting via the inferior.
+ Also make test names unique.
+
2019-07-08 Alan Hayward <alan.hayward@arm.com>
* gdb.base/break-idempotent.exp: Test both PIE and non PIE.
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index f2d6ee2..0e3126b 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -438,7 +438,7 @@ proc test_print_repeats_10 {} {
global gdb_prompt decimal
for { set x 1 } { $x <= 16 } { incr x } {
- gdb_test_no_output "set print elements $x"
+ gdb_test_no_output "set print elements $x" "elements $x repeats"
for { set e 1 } { $e <= 16 } {incr e } {
set v [expr $e - 1]
set command "p &ctable2\[${v}*16\]"
@@ -596,7 +596,7 @@ proc test_print_strings {} {
proc test_print_int_arrays {} {
global gdb_prompt
- gdb_test_no_output "set print elements 24"
+ gdb_test_no_output "set print elements 24" "elements 24 int arrays"
gdb_test_escape_braces "p int1dim" \
" = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"
@@ -621,7 +621,7 @@ proc test_print_int_arrays {} {
proc test_print_typedef_arrays {} {
global gdb_prompt
- gdb_test_no_output "set print elements 24"
+ gdb_test_no_output "set print elements 24" "elements 24 typedef_arrays"
gdb_test_escape_braces "p a1" \
" = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}"
@@ -666,7 +666,7 @@ proc test_print_char_arrays {} {
global gdb_prompt
global hex decimal
- gdb_test_no_output "set print elements 24"
+ gdb_test_no_output "set print elements 24" "elements 24 char_arrays"
gdb_test_no_output "set print address on"
gdb_test "p arrays" \
@@ -684,7 +684,7 @@ proc test_print_char_arrays {} {
gdb_test "p parrays->array5" " = \"hij\""
gdb_test "p &parrays->array5" " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex <arrays\\+$decimal>"
- gdb_test_no_output "set print address off"
+ gdb_test_no_output "set print address off" "address off char arrays"
}
proc test_print_string_constants {} {
@@ -932,6 +932,42 @@ proc test_repeat_bytes {} {
}
}
+# Test printf of convenience variables.
+# These tests can be done with or without a running inferior.
+# PREFIX ensures uniqueness of test names.
+# DO_WSTRING 1 tells to test printf of wide strings. Wide strings tests
+# must be skipped (DO_WSTRING 0) if the wchar_t type is not yet known by
+# GDB, as this type is needed to create wide strings.
+
+proc test_printf_convenience_var {prefix do_wstring} {
+
+ with_test_prefix "conv var: $prefix" {
+ gdb_test_no_output "set var \$cstr = \"abcde\"" "set \$cstr"
+ gdb_test "printf \"cstr val = %s\\n\", \$cstr" "cstr val = abcde" \
+ "printf \$cstr"
+ gdb_test_no_output "set var \$abcde = \"ABCDE\"" "set \$abcde"
+ gdb_test "eval \"print \$%s\\n\", \$cstr" "= \"ABCDE\"" \
+ "indirect print abcde"
+ # Without a target, the below produces no output
+ # but with a target, it gives a warning.
+ # So, use gdb_test expecting ".*" instead of gdb_test_no_output.
+ gdb_test "set language ada" ".*" "set language ada"
+ gdb_test_no_output "set var \$astr := \"fghij\"" "set \$astr"
+ gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
+ "printf \$astr"
+ gdb_test_no_output "set language auto" "set language auto"
+ gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
+ "printf \$astr, auto language"
+ if {$do_wstring} {
+ gdb_test_no_output "set var \$wstr = L\"facile\"" \
+ "set \$wstr"
+ gdb_test "printf \"wstr val = %ls\\n\", \$wstr" \
+ "wstr val = facile" "printf \$wstr"
+ }
+ }
+}
+
+
# Start with a fresh gdb.
gdb_exit
@@ -948,6 +984,11 @@ gdb_test "ptype \"abc\"" " = char \\\[4\\\]"
gdb_test "print \$cvar = \"abc\"" " = \"abc\""
gdb_test "print sizeof (\$cvar)" " = 4"
+# Similarly, printf of a string convenience var should work without a target.
+# At this point, we cannot create a wide string convenience var, as the
+# wchar_t type is not yet known, so skip the wide string tests.
+test_printf_convenience_var "no target" 0
+
# GDB used to complete the explicit location options even when
# printing expressions.
gdb_test_no_output "complete p -function"
@@ -977,6 +1018,14 @@ if ![runto_main] then {
return 0
}
+# With a running target, printf convenience vars should of course work.
+test_printf_convenience_var "with target" 1
+
+# It should also work when inferior function calls are forbidden.
+gdb_test_no_output "set may-call-functions off"
+test_printf_convenience_var "with target, may-call-functions off" 1
+gdb_test_no_output "set may-call-functions on"
+
test_integer_literals_accepted
test_integer_literals_rejected
test_float_accepted