Re: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory

Hui Zhu
2011-09-09T07:28:11Z

[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

On Wed, Sep 7, 2011 at 17:58, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> On Wed, 07 Sep 2011 04:55:32 +0200, Hui Zhu wrote:
>> +#Test printing internal var values with printf
>> +proc test_printf_with_internalvar {} {
>> +    gdb_test "set \$a={\'a\',\'b\'}" ""
>
> Escaping of ' is redundant.
>
>> +    gdb_test "printf \"%s\\n\", \$a" "ab"
>
> I would find easier { and } instead of " and " to prevent so many backslashes
> but opinions differ on it, FYI:
>    gdb_test_no_output {set $a={'a','b'}}
>    gdb_test {printf "%s\n", $a} "ab"
>

Thanks for your help Jan.

I make a new patch according to it. And I add more
test_printf_with_internalvar in the end of test because I think it can
test this issue after the inferior exec.
>
> Still this testcase FAILs for me:
> printf "%s\n", $a^M
> abX^M
> (gdb) FAIL: gdb.base/printcmds.exp: printf "%s\n", $a
>
> Where X is some binary unprintable garbage character, not sure which way you
> plan to fix it (maybe some `error' call if there is no zero-terminator?).

I didn't got this issue. Could you post more info about this issue?

>
>
> Thanks,
> Jan
>

Best,
Hui

2011-09-07 Hui Zhu <teawater@gmail.com>

* gdb.base/printcmds.exp: Add test for printing internal var
values with printf.

[-- Attachment #2: test-v-string.txt --]
[-- Type: text/plain, Size: 965 bytes --]

---
testsuite/gdb.base/printcmds.exp | 9 +++++++++
1 file changed, 9 insertions(+)

--- a/testsuite/gdb.base/printcmds.exp
+++ b/testsuite/gdb.base/printcmds.exp
@@ -775,6 +775,12 @@ proc test_printf_with_dfp {} {
gdb_test "printf \"%DDf\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
}

+#Test printing internal var values with printf
+proc test_printf_with_internalvar {} {
+ gdb_test_no_output {set $a={'a','b'}}
+ gdb_test {printf "%s\n", $a} "ab"
+}
+
# Escape a left curly brace to prevent it from being interpreted as
# the beginning of a bound
proc gdb_test_escape_braces { args } {
@@ -816,6 +822,8 @@ if { [test_compiler_info "armcc-*"] } {
}
gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1"

+test_printf_with_internalvar
+
gdb_load ${binfile}

if ![runto_main] then {
@@ -842,3 +850,4 @@ test_print_array_constants
test_print_enums
test_printf
test_printf_with_dfp
+test_printf_with_internalvar