From patchwork Sun Sep 8 17:41:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 34448 Received: (qmail 101094 invoked by alias); 8 Sep 2019 17:41:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101082 invoked by uid 89); 8 Sep 2019 17:41:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Back, repetition, Range, escaped X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 08 Sep 2019 17:41:11 +0000 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDAEAC00A17C for ; Sun, 8 Sep 2019 17:41:09 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id j3so5836782wrn.7 for ; Sun, 08 Sep 2019 10:41:09 -0700 (PDT) Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id y14sm22655660wrd.84.2019.09.08.10.41.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Sep 2019 10:41:07 -0700 (PDT) Subject: Re: [RFAv4 2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting. To: Philippe Waroquiers , gdb-patches@sourceware.org References: <20190907113823.17436-1-philippe.waroquiers@skynet.be> <20190907113823.17436-3-philippe.waroquiers@skynet.be> From: Pedro Alves Message-ID: <9b2760b0-5934-8b73-cee6-bb0e8c21317c@redhat.com> Date: Sun, 8 Sep 2019 18:41:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190907113823.17436-3-philippe.waroquiers@skynet.be> On 9/7/19 12:38 PM, Philippe Waroquiers wrote: > gdb/testsuite/ChangeLog > 2019-09-07 Philippe Waroquiers > > * gdb.base/setshow.exp: Test $_gdb_setting and $_gdb_setting_str. > * gdb.base/settings.exp: Test all settings types using > $_gdb_maint_setting and $_gdb_maint_setting_str in proc_show_setting, > that now verifies that the value of "maint show" is the same as > returned by the settings functions. > * gdb.base/default.exp: Update show_conv_list. > --- > gdb/testsuite/gdb.base/default.exp | 4 ++ > gdb/testsuite/gdb.base/setshow.exp | 60 ++++++++++++++++++++++++- > gdb/testsuite/gdb.base/settings.exp | 68 ++++++++++++++++++++++++++--- > 3 files changed, 125 insertions(+), 7 deletions(-) > > diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp > index 0325b8045d..114831f2fc 100644 > --- a/gdb/testsuite/gdb.base/default.exp > +++ b/gdb/testsuite/gdb.base/default.exp > @@ -604,6 +604,10 @@ set show_conv_list \ > {$_cimag = } \ > {$_creal = } \ > {$_isvoid = } \ > + {$_gdb_maint_setting_str = } \ > + {$_gdb_maint_setting = } \ > + {$_gdb_setting_str = } \ > + {$_gdb_setting = } \ > {$_gdb_major = 8} \ > {$_gdb_minor = 4} \ > {$_shell_exitsignal = void} \ > diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp > index d807d75a66..4c25c7bb32 100644 > --- a/gdb/testsuite/gdb.base/setshow.exp > +++ b/gdb/testsuite/gdb.base/setshow.exp > @@ -91,6 +91,9 @@ gdb_test "show args" "Argument list to give program being debugged when it is st > gdb_test_no_output "set args foo bar blup baz bubble" "set args" > #test show args > gdb_test "show args" "Argument list to give program being debugged when it is started is \"foo bar blup baz bubble\"..*" "show args" > +gdb_test "p \$_gdb_setting(\"args\")" ".*\"foo bar blup baz bubble\"" \ > + "_gdb_setting args" That ".*" at the start of the regexp is not necessary, as its implied. For print tests, it's better to expect the leading " = ", like: gdb_test "p \$_gdb_setting(\"args\")" " = \"foo bar blup baz bubble\"" \ "_gdb_setting args" The reason is that without that, you'd get a pass even if gdb outputs $1 = xxx"foo bar blup baz bubble" or $1 = "foo bar blup baz bubble""foo bar blup baz bubble" etc. It's a bit more obviously dangerous with numeric values. Like, for example, this: gdb_test "p \$_gdb_setting(\"height\")" "0" would issue a PASS with either of these outputs: $1 = 0 $1 = 10 So we write instead: gdb_test "p \$_gdb_setting(\"height\")" " = 0" This applies to several places in your patch. I won't point out the others individually. BTW, I noticed this, right after starting gdb: (gdb) show args Argument list to give program being debugged when it is started is "". (gdb) p $_gdb_setting("args") $1 = 0x0 I would expect $1 = "" instead? Also, I noticed that we're missing tests for checking the type of the values returned. Something seems off with types too, actually. Notice: (gdb) p $_gdb_setting_str("args") $1 = 0x0 (gdb) ptype $_gdb_setting_str("args") type = int "int" seems bogus, but also seems like a consequence of the "0x0". But, look here: (gdb) p $_gdb_setting_str("args") $1 = "\"foo\"" (gdb) ptype $2 type = char [5] OK, but ... now the broken part: (gdb) set args "foo" (gdb) ptype $_gdb_setting_str("args") type = int ??? Same thing with other types, here an unsigned type: (gdb) p $_gdb_setting("height") $2 = 42 (gdb) ptype $2 type = unsigned int (gdb) ptype $_gdb_setting("height") type = int Odd... > + > > # Don't test if we can't pass args or if we're using a stub. > if { !$use_gdb_stub && ![target_info exists noargs] } { > @@ -100,17 +103,23 @@ if { !$use_gdb_stub && ![target_info exists noargs] } { > gdb_test "run" "Starting program:.*foo bar blup baz bubble.*" "passing args" > } > #test set check range on > -gdb_test "set check range on" ".*" "set check range on" > +gdb_test "set check range on" ".*" "set check range on" > +gdb_test "p \$_gdb_setting(\"check range\")" ".*\"on\"" \ > + "_gdb_setting check range on" > #test show check range on > gdb_test "show check range" "Range checking is \"on\"\..*" "show check range (on)" > #test set check range off with trailing space > gdb_test_no_output "set check range off " "set check range off" > #test show check range off > gdb_test "show check range" "Range checking is \"off\"\..*" "show check range (off)" > +gdb_test "p \$_gdb_setting(\"check range\")" ".*\"off\"" \ > + "_gdb_setting check range off" > #test set check range auto > gdb_test_no_output "set check range auto" "set check range auto" > #test show check range auto > gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)" > +gdb_test "p \$_gdb_setting(\"check range\")" ".*\"auto\"" \ > + "_gdb_setting check range auto" > > # Test set check type on > gdb_test "set check type on" ".*" "set check type on" > @@ -118,14 +127,49 @@ gdb_test "set check type on" ".*" "set check type on" > # Test show check type on > gdb_test "show check type" "Strict type checking is on\..*" \ > "show check type (on)" > +gdb_test "p \$_gdb_setting_str(\"check type\")" ".*\"on\"" \ > + "_gdb_setting_str check type on" > +gdb_test "p \$_gdb_setting(\"check type\")" ".*= 1" \ > + "_gdb_setting check type on 1" > > # Test set check type off with trailing space > gdb_test_no_output "set check type off " "set check type off" > +gdb_test "p \$_gdb_setting_str(\"check type\")" ".*\"off\"" \ > + "_gdb_setting_str check type off" > +gdb_test "p \$_gdb_setting(\"check type\")" ".*= 0" \ > + "_gdb_setting check type off 0" > > # Test show check type off > gdb_test "show check type" "Strict type checking is off\..*" \ > "show check type (off)" > > +#test set breakpoint pending > +#test set breakpoint pending on > +gdb_test "set breakpoint pending on" ".*" "set breakpoint pending on" Please use gdb_test_no_output. BTW, no need to repeat "set breakpoint pending on", since the third argument defaults to the first argument if unspecified. > +gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" ".*\"on\"" \ > + "_gdb_setting_str breakpoint pending on" > +gdb_test "p \$_gdb_setting(\"breakpoint pending\")" ".*= 1" \ > + "_gdb_setting breakpoint pending 1" > +#test show breakpoint pending on > +gdb_test "show breakpoint pending" ".* is on\..*" "show breakpoint pending on" > +#test show breakpoint pending off > +gdb_test "set breakpoint pending off" ".*" "set breakpoint pending off" > +gdb_test "show breakpoint pending" ".* is off\..*" "show breakpoint pending off" > +gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" ".*\"off\"" \ > + "_gdb_setting_str breakpoint pending off" > +gdb_test "p \$_gdb_setting(\"breakpoint pending\")" ".* = 0" \ > + "_gdb_setting breakpoint pending 0" > +#test set breakpoint pending auto > +gdb_test_no_output "set breakpoint pending auto" "set breakpoint pending auto" > +#test show breakpoint pending auto > +gdb_test "show breakpoint pending" " is auto.*" "show breakpoint pending auto" > +gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" ".*\"auto\"" \ > + "_gdb_setting_str breakpoint pending auto" > +gdb_test "p \$_gdb_setting(\"breakpoint pending\")" ".* = -1" \ > + "_gdb_setting breakpoint pending -1" > + I think this would be much more readable with some empty lines between the subsections above. It looks like a big blob of text as is, to me. :-) > #test set complaints 100 > gdb_test_no_output "set complaints 100" "set complaints 100" > #test show complaints 100 > @@ -159,9 +203,17 @@ gdb_test "show environment FOOBARBAZ" "FOOBARBAZ = grbxgrbxgrbx.*" "show enviro > gdb_test_no_output "set height 100" "set height 100" > #test show height 100 > gdb_test "show height" "Number of lines gdb thinks are in a page is 100..*" "show height" > +gdb_test "p \$_gdb_setting_str(\"height\")" ".*\"100\"" \ > + "_gdb_setting_str height 100" > +gdb_test "p \$_gdb_setting(\"height\")" ".*= 100" \ > + "_gdb_setting height 100" > # Back to infinite height to avoid pagers. While at it, check that > # literal "unlimited" works just as well as 0. > gdb_test_no_output "set height unlimited" > +gdb_test "p \$_gdb_setting_str(\"height\")" ".*\"unlimited\"" \ > + "_gdb_setting_str height unlimited" > +gdb_test "p \$_gdb_setting(\"height\")" ".*= 0" \ > + "_gdb_setting height unlimited" > #test set history expansion on > gdb_test_no_output "set history expansion on" "set history expansion on" > #test show history expansion on > @@ -182,6 +234,12 @@ gdb_test_no_output "set history filename ~/foobar.baz" \ > gdb_test "show history filename" \ > "The filename in which to record the command history is \"[string_to_regexp $HOME]/foobar.baz\"..*" \ > "show history filename (~/foobar.baz)" > +gdb_test "p \$_gdb_setting(\"history filename\")" \ > + ".*\"[string_to_regexp $HOME]/foobar.baz\"..*" \ > + "_gdb_setting history filename" > +gdb_test "p \$_gdb_setting_str(\"history filename\")" \ > + ".*\"[string_to_regexp $HOME]/foobar.baz\"..*" \ > + "_gdb_setting_str history filename" > #get current working directory > set PWD "" > set test "show working directory" > diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp > index 53049d6b59..102e0c57a4 100644 > --- a/gdb/testsuite/gdb.base/settings.exp > +++ b/gdb/testsuite/gdb.base/settings.exp > @@ -35,13 +35,69 @@ if { ![readline_is_used] } { > } > > # Test the show command SHOW_CMD. EXPECTED_RE is the expected output. > -# This procedure exists in order to make it easier to make the test > +# Also verifies that $_gdb_maint_setting_str produces an equivalent output, > +# matching it with EXPECTED_RE. EXPECTED_RE double quotes are escaped > +# unless EXPECTED_RE_QUOTED is 1, indicating the quotes in EXPECTED_RE > +# are already escaped. Shouldn't that be better called EXPECTED_RE_ESCAPED instead of EXPECTED_RE_QUOTED ? > +# The value for the setting corresponding to SHOW_CMD is then reset > +# to RESET_VALUE, then set again to the value given by $_gdb_maint_setting_str > +# and $_gdb_maint_setting. > +# The setting value must still be the one in force before calling show_setting. > +# In other words, this verifies that > +# maint set test-settings $_gdb_maint_setting_str() > +# maint set test-settings $_gdb_maint_setting() > +# do not change the setting value. > +# This procedure makes it easier to make the test > # name/message unique, since we test the "show" commands many times. > # EXPECTED_RE is made part of the test name. > -proc show_setting {show_cmd expected_re} { > +proc show_setting {show_cmd expected_re {expected_re_quoted 0} {reset_value 0}} { > + global gdb_prompt > gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re" > + > + # Remove the first two words (such as "maint show") to have the > + # setting name to use for $_gdb_maint_setting_str. > + regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting > + if {$expected_re_quoted == 1} { Write: if {$expected_re_quoted} { and say "is true" instead of "is 1" in the intro comment. > + set quoted_expected_re $expected_re > + } else { > + regsub -all "\"" $expected_re "\\\\\\\"" quoted_expected_re > + } > + set test "print \$_gdb_maint_setting_str(\"$maint_setting\") $quoted_expected_re $expected_re" > + gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test { > + -re ".*= \"\($quoted_expected_re\)\".*$gdb_prompt $" { Unnecessary leading ".*". > + set setting_str_value $expect_out(1,string) > + regsub -all "\\\\" $expect_out(1,string) "" setting_str_value > + pass "$test value $setting_str_value" > + } > + } This leaves $setting_str_value uninitialized if the gdb_test_multiple above fails, which then causes TCL errors below where $setting_str_value is used, referencing a nonexistent variable. The usual fix is to initialize the variable to some invalid value before gdb_test_multiple. (see patch below before acting.) > + > + # Change the setting value to RESET_VALUE, set it back to setting_str_value > + # and check we still have the original value. > + gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $show_cmd: $expected_re" > + gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again $show_cmd: $expected_re" > + gdb_test "$show_cmd" $expected_re "str $show_cmd: $expected_re after reset+set again" > + > + # Same test, but with value captured from $_gdb_maint_setting. > + set test "print \$_gdb_maint_setting(\"$maint_setting\") $quoted_expected_re $expected_re" > + gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test { > + -re ".*= \"\(.*\)\".*$gdb_prompt $" { Ditto. > + set setting_value $expect_out(1,string) > + regsub -all "\\\\" $expect_out(1,string) "" setting_value > + pass "$test quoted value $setting_value" > + } > + -re ".*= \(.*\)\r\n$gdb_prompt $" { > + set setting_value $expect_out(1,string) > + pass "$test non quoted value $setting_value" > + } Same comments about leaving $setting_value uninitialized. > + } > + > + gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $show_cmd: $expected_re" > + gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again $show_cmd: $expected_re" > + gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re after reset+set again" > + > } > > + > # var_Xinteger tests. VARIANT determines which command/variant to > # exercise. > proc test-integer {variant} { > @@ -409,11 +465,11 @@ proc_with_prefix test-enum {} { > # Various valid values. Test both full value names and > # abbreviations. > gdb_test_no_output "$set_cmd x" > - show_setting "$show_cmd" "xxx" > + show_setting "$show_cmd" "xxx" 0 "zzz" > gdb_test_no_output "$set_cmd yy" > - show_setting "$show_cmd" "yyy" > + show_setting "$show_cmd" "yyy" 0 "zzz" > gdb_test_no_output "$set_cmd zzz" > - show_setting "$show_cmd" "zzz" > + show_setting "$show_cmd" "zzz" 0 "yyy" > > test_gdb_complete_multiple "$set_cmd " "" "" { > "xxx" > @@ -461,7 +517,7 @@ proc test-string {variant} { > # A quoted string value. > if {$variant == "string"} { > gdb_test_no_output "$set_cmd \"hello world\"" > - show_setting "$show_cmd" "\\\\\"hello world\\\\\"" > + show_setting "$show_cmd" "\\\\\"hello world\\\\\"" 1 > } else { > gdb_test_no_output "$set_cmd \"hello world\"" > show_setting "$show_cmd" "\"hello world\"" Running the tests locally and looking at gdb.sum to get a sense of what the new tests are doing, I found the results very confusing, because it's not easy to track the sequence of the set/show commands being tested, with all the new reset/set again, show, etc. commands involved. With your patch, we get a lot of these: PASS: gdb.base/settings.exp: test-string filename: maint set test-settings filename hello world PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename: hello world PASS: gdb.base/settings.exp: test-string filename: print $_gdb_maint_setting_str("test-settings filename") hello world hello world value hello world PASS: gdb.base/settings.exp: test-string filename: str reset maint show test-settings filename: hello world PASS: gdb.base/settings.exp: test-string filename: str set again maint show test-settings filename: hello world PASS: gdb.base/settings.exp: test-string filename: str maint show test-settings filename: hello world after reset+set again PASS: gdb.base/settings.exp: test-string filename: print $_gdb_maint_setting("test-settings filename") hello world hello world quoted value hello world PASS: gdb.base/settings.exp: test-string filename: reset maint show test-settings filename: hello world PASS: gdb.base/settings.exp: test-string filename: set again maint show test-settings filename: hello world PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename: hello world after reset+set again PASS: gdb.base/settings.exp: test-string filename: maint set test-settings filename "hello world" PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename: "hello world" PASS: gdb.base/settings.exp: test-string filename: print $_gdb_maint_setting_str("test-settings filename") \\"hello world\\" "hello world" value "hello world" PASS: gdb.base/settings.exp: test-string filename: str reset maint show test-settings filename: "hello world" PASS: gdb.base/settings.exp: test-string filename: str set again maint show test-settings filename: "hello world" PASS: gdb.base/settings.exp: test-string filename: str maint show test-settings filename: "hello world" after reset+set again PASS: gdb.base/settings.exp: test-string filename: print $_gdb_maint_setting("test-settings filename") \\"hello world\\" "hello world" quoted value "hello world" PASS: gdb.base/settings.exp: test-string filename: reset maint show test-settings filename: "hello world" PASS: gdb.base/settings.exp: test-string filename: set again maint show test-settings filename: "hello world" PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename: "hello world" after reset+set again I'd rather we group things with with_test_prefix, avoid much repetition, and I don't think there's a real need to put all the values of the internal variables in gdb.sum. We can put those in gdb.log if we need. See patch below on top of yours. With that, we get instead: PASS: gdb.base/settings.exp: test-string filename: maint set test-settings filename hello world PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: show PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: print $_gdb_maint_setting_str PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: str reset 0 PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: str set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: str show after reset+set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: print $_gdb_maint_setting PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: reset 0 PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename hello world: show after reset+set again PASS: gdb.base/settings.exp: test-string filename: maint set test-settings filename "hello world" PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": show PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": print $_gdb_maint_setting_str PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": str reset 0 PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": str set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": str show after reset+set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": print $_gdb_maint_setting PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": reset 0 PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": set again PASS: gdb.base/settings.exp: test-string filename: maint show test-settings filename "hello world": show after reset+set again It's easy to spot a pattern this way. If some test fails, it's going to be much more obvious what set/show we were testing, and that part exactly failed, IMO. I was also wondering whether it would work to make show_setting detect/assert that the reset value isn't the same as the expected value? From 315417945a9edf8e2cf58e32545faa5774e59a32 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sun, 8 Sep 2019 18:01:56 +0100 Subject: [PATCH] tweak tests --- gdb/testsuite/gdb.base/settings.exp | 78 +++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp index 102e0c57a43..b597bd6c0ad 100644 --- a/gdb/testsuite/gdb.base/settings.exp +++ b/gdb/testsuite/gdb.base/settings.exp @@ -52,49 +52,53 @@ if { ![readline_is_used] } { # EXPECTED_RE is made part of the test name. proc show_setting {show_cmd expected_re {expected_re_quoted 0} {reset_value 0}} { global gdb_prompt - gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re" - # Remove the first two words (such as "maint show") to have the - # setting name to use for $_gdb_maint_setting_str. - regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting - if {$expected_re_quoted == 1} { - set quoted_expected_re $expected_re - } else { - regsub -all "\"" $expected_re "\\\\\\\"" quoted_expected_re - } - set test "print \$_gdb_maint_setting_str(\"$maint_setting\") $quoted_expected_re $expected_re" - gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test { - -re ".*= \"\($quoted_expected_re\)\".*$gdb_prompt $" { - set setting_str_value $expect_out(1,string) - regsub -all "\\\\" $expect_out(1,string) "" setting_str_value - pass "$test value $setting_str_value" - } - } + with_test_prefix "$show_cmd $expected_re" { + gdb_test "$show_cmd" $expected_re "show" - # Change the setting value to RESET_VALUE, set it back to setting_str_value - # and check we still have the original value. - gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $show_cmd: $expected_re" - gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again $show_cmd: $expected_re" - gdb_test "$show_cmd" $expected_re "str $show_cmd: $expected_re after reset+set again" - - # Same test, but with value captured from $_gdb_maint_setting. - set test "print \$_gdb_maint_setting(\"$maint_setting\") $quoted_expected_re $expected_re" - gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test { - -re ".*= \"\(.*\)\".*$gdb_prompt $" { - set setting_value $expect_out(1,string) - regsub -all "\\\\" $expect_out(1,string) "" setting_value - pass "$test quoted value $setting_value" + # Remove the first two words (such as "maint show") to have the + # setting name to use for $_gdb_maint_setting_str. + regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting + if {$expected_re_quoted == 1} { + set quoted_expected_re $expected_re + } else { + regsub -all "\"" $expected_re "\\\\\\\"" quoted_expected_re } - -re ".*= \(.*\)\r\n$gdb_prompt $" { - set setting_value $expect_out(1,string) - pass "$test non quoted value $setting_value" + set test "print \$_gdb_maint_setting_str" + set setting_str_value "xxxYYYxxx" + gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test { + -re " = \"\($quoted_expected_re\)\".*$gdb_prompt $" { + set setting_str_value $expect_out(1,string) + regsub -all "\\\\" $expect_out(1,string) "" setting_str_value + pass $test + } } - } - gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $show_cmd: $expected_re" - gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again $show_cmd: $expected_re" - gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re after reset+set again" + # Change the setting value to RESET_VALUE, set it back to setting_str_value + # and check we still have the original value. + gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $reset_value" + gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again" + gdb_test "$show_cmd" $expected_re "str show after reset+set again" + + # Same test, but with value captured from $_gdb_maint_setting. + set test "print \$_gdb_maint_setting" + set setting_value "xxxYYYxxx" + gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test { + -re " = \"\(.*\)\".*$gdb_prompt $" { + set setting_value $expect_out(1,string) + regsub -all "\\\\" $expect_out(1,string) "" setting_value + pass $test + } + -re " = \(.*\)\r\n$gdb_prompt $" { + set setting_value $expect_out(1,string) + pass $test + } + } + gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $reset_value" + gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again" + gdb_test "$show_cmd" $expected_re "show after reset+set again" + } }