forked from Imagelibrary/binutils-gdb
gdb/testsuite: extend special '^' handling to gdb_test_multiple
The commit:
commit 08ec06d644
Date: Wed Mar 29 10:41:07 2023 +0100
gdb/testsuite: special case '^' in gdb_test pattern
Added some special handling of '^' to gdb_test -- a leading '^' will
cause the command regexp to automatically be included in the expected
output pattern.
It was pointed out that the '-wrap' flag of gdb_test_multiple is
supposed to work in the same way as gdb_test, and that the recent
changes for '^' had not been replicated for gdb_test_multiple. This
patch addresses this issue.
So, after this commit, the following two constructs should have the
same meaning:
gdb_test "command" "^output" "test name"
gdb_test_multiple "command" "test name" {
-re -wrap "^output" {
pass $gdb_test_name
}
}
In both cases the '^' will case gdb.exp to inject a regexp that
matches 'command' after the '^' and before the 'output', this is in
addition to adding the $gdb_prompt pattern after 'output' in the
normal way.
The special '^' handling is only applied when '-wrap' is used, as this
is the only mode that aims to mimic gdb_test.
While working on this patch I realised that I could actually improve
the logic for the special '^' handling in the case where the expected
output pattern is empty. I replicated these updates for both gdb_test
and gdb_test_multiple in order to keep these two paths in sync.
There were a small number of tests that needed adjustment after this
change, mostly just removing command regexps that are now added
automatically, but the gdb.base/settings.exp case was a little weird
as it turns out trying to match a single blank line is probably harder
now than it used to be -- still, I suspect this is a pretty rare case,
so I think the benefits (improved anchoring) outweigh this small
downside (IMHO).
This commit is contained in:
@@ -24,19 +24,17 @@ clean_restart
|
|||||||
# expected error. If WARNING_OR_ERROR is empty, it is expected that
|
# expected error. If WARNING_OR_ERROR is empty, it is expected that
|
||||||
# GDB prints no text other than the print result.
|
# GDB prints no text other than the print result.
|
||||||
proc test_shift {lang cmd result_re {warning_or_error ""}} {
|
proc test_shift {lang cmd result_re {warning_or_error ""}} {
|
||||||
set cmd_re [string_to_regexp $cmd]
|
|
||||||
|
|
||||||
if {$lang == "go"} {
|
if {$lang == "go"} {
|
||||||
if {$warning_or_error != ""} {
|
if {$warning_or_error != ""} {
|
||||||
set error_re "[string_to_regexp $warning_or_error]"
|
set error_re "[string_to_regexp $warning_or_error]"
|
||||||
gdb_test_multiple $cmd "" {
|
gdb_test_multiple $cmd "" {
|
||||||
-re -wrap "^$cmd_re\r\n$error_re" {
|
-re -wrap "^$error_re" {
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gdb_test_multiple $cmd "" {
|
gdb_test_multiple $cmd "" {
|
||||||
-re -wrap "^$cmd_re\r\n\\$$::decimal$result_re" {
|
-re -wrap "^\\$$::decimal$result_re" {
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +47,7 @@ proc test_shift {lang cmd result_re {warning_or_error ""}} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gdb_test_multiple $cmd "" {
|
gdb_test_multiple $cmd "" {
|
||||||
-re -wrap "^$cmd_re\r\n$warning_re\\$$::decimal$result_re" {
|
-re -wrap "^$warning_re\\$$::decimal$result_re" {
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,6 @@ proc get_frame_id { level } {
|
|||||||
set id "**unknown**"
|
set id "**unknown**"
|
||||||
|
|
||||||
gdb_test_multiple "maint print frame-id ${level}" "" {
|
gdb_test_multiple "maint print frame-id ${level}" "" {
|
||||||
-re "^maint print frame-id\[^\r\n\]+\r\n" {
|
|
||||||
exp_continue
|
|
||||||
}
|
|
||||||
|
|
||||||
-wrap -re "^frame-id for frame #\[0-9\]+: (\[^\r\n\]+)" {
|
-wrap -re "^frame-id for frame #\[0-9\]+: (\[^\r\n\]+)" {
|
||||||
set id $expect_out(1,string)
|
set id $expect_out(1,string)
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ proc test-string {variant} {
|
|||||||
if {$variant != "filename"} {
|
if {$variant != "filename"} {
|
||||||
# This odd expected output here is because we expect GDB to
|
# This odd expected output here is because we expect GDB to
|
||||||
# emit a single blank line as a result of this command.
|
# emit a single blank line as a result of this command.
|
||||||
gdb_test "$show_cmd" "^" "$show_cmd: show default"
|
gdb_test -nonl "$show_cmd" "^\r\n" "$show_cmd: show default"
|
||||||
} else {
|
} else {
|
||||||
gdb_test "$show_cmd" "/foo/bar" "$show_cmd: show default"
|
gdb_test "$show_cmd" "/foo/bar" "$show_cmd: show default"
|
||||||
}
|
}
|
||||||
@@ -574,7 +574,7 @@ proc test-string {variant} {
|
|||||||
gdb_test_no_output "$set_cmd"
|
gdb_test_no_output "$set_cmd"
|
||||||
# This odd expected output here is because we expect GDB to
|
# This odd expected output here is because we expect GDB to
|
||||||
# emit a single blank line as a result of this command.
|
# emit a single blank line as a result of this command.
|
||||||
gdb_test "$show_cmd" "^" "$show_cmd: empty second time"
|
gdb_test -nonl "$show_cmd" "^\r\n" "$show_cmd: empty second time"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ proc get_screen_width { } {
|
|||||||
set cmd "maint info screen"
|
set cmd "maint info screen"
|
||||||
set re \
|
set re \
|
||||||
[multi_line \
|
[multi_line \
|
||||||
^$cmd \
|
^$re1 \
|
||||||
$re1 \
|
|
||||||
$re2 \
|
$re2 \
|
||||||
"(?:$re3" \
|
"(?:$re3" \
|
||||||
")?$re4" \
|
")?$re4" \
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ gdb_test_multiple $cmd "try to save gdb index" {
|
|||||||
-re -wrap $no_debug_re {
|
-re -wrap $no_debug_re {
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
}
|
}
|
||||||
-re -wrap "^$cmd" {
|
-re -wrap "^" {
|
||||||
pass $gdb_test_name
|
pass $gdb_test_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ proc test_wrap_cli_tui { auto_detected_width } {
|
|||||||
set cmd "maint info screen"
|
set cmd "maint info screen"
|
||||||
set re \
|
set re \
|
||||||
[multi_line \
|
[multi_line \
|
||||||
"^$cmd" \
|
"^$re1" \
|
||||||
$re1 \
|
|
||||||
$re2 \
|
$re2 \
|
||||||
".*"]
|
".*"]
|
||||||
gdb_test_multiple $cmd "" {
|
gdb_test_multiple $cmd "" {
|
||||||
|
|||||||
@@ -980,6 +980,8 @@ proc fill_in_default_prompt {prompt_regexp with_anchor} {
|
|||||||
# pass $gdb_test_name
|
# pass $gdb_test_name
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
|
# The special handling of '^' that is available in gdb_test is also
|
||||||
|
# supported in gdb_test_multiple when -wrap is used.
|
||||||
#
|
#
|
||||||
# In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
|
# In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
|
||||||
# pattern is inserted before any implicit pattern added by gdb_test_multiple.
|
# pattern is inserted before any implicit pattern added by gdb_test_multiple.
|
||||||
@@ -1125,6 +1127,19 @@ proc gdb_test_multiple { command message args } {
|
|||||||
set expecting_action 1
|
set expecting_action 1
|
||||||
if { $wrap_pattern } {
|
if { $wrap_pattern } {
|
||||||
# Wrap subst_item as is done for the gdb_test PATTERN argument.
|
# Wrap subst_item as is done for the gdb_test PATTERN argument.
|
||||||
|
if {[string range $subst_item 0 0] eq "^"} {
|
||||||
|
if {$command ne ""} {
|
||||||
|
set command_regex [string_to_regexp $command]
|
||||||
|
set subst_item [string range $subst_item 1 end]
|
||||||
|
if {[string length "$subst_item"] > 0} {
|
||||||
|
# We have an output pattern (other than the '^'),
|
||||||
|
# add a newline at the start, this will eventually
|
||||||
|
# sit between the command and the output pattern.
|
||||||
|
set subst_item "\r\n${subst_item}"
|
||||||
|
}
|
||||||
|
set subst_item "^${command_regex}${subst_item}"
|
||||||
|
}
|
||||||
|
}
|
||||||
lappend $current_list \
|
lappend $current_list \
|
||||||
"(?:$subst_item)\r\n$prompt_regexp"
|
"(?:$subst_item)\r\n$prompt_regexp"
|
||||||
set wrap_pattern 0
|
set wrap_pattern 0
|
||||||
@@ -1465,10 +1480,16 @@ proc gdb_test { args } {
|
|||||||
# additional pattern that matches the command immediately after
|
# additional pattern that matches the command immediately after
|
||||||
# the '^'.
|
# the '^'.
|
||||||
if {[string range $pattern 0 0] eq "^"} {
|
if {[string range $pattern 0 0] eq "^"} {
|
||||||
set command_regex [string_to_regexp $command]
|
if {$command ne ""} {
|
||||||
set pattern [string range $pattern 1 end]
|
set command_regex [string_to_regexp $command]
|
||||||
if {$command_regex ne ""} {
|
set pattern [string range $pattern 1 end]
|
||||||
set pattern "^${command_regex}\r\n$pattern"
|
if {[string length "$pattern"] > 0} {
|
||||||
|
# We have an output pattern (other than the '^'), add a
|
||||||
|
# newline at the start, this will eventually sit between the
|
||||||
|
# command and the output pattern.
|
||||||
|
set pattern "\r\n$pattern"
|
||||||
|
}
|
||||||
|
set pattern "^${command_regex}${pattern}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6174,9 +6195,8 @@ proc with_set { var val body } {
|
|||||||
perror "Did not manage to set $var"
|
perror "Did not manage to set $var"
|
||||||
} else {
|
} else {
|
||||||
# Set var.
|
# Set var.
|
||||||
set cmd "set $var $val"
|
gdb_test_multiple "set $var $val" "" {
|
||||||
gdb_test_multiple $cmd "" {
|
-re -wrap "^" {
|
||||||
-re -wrap "^$cmd" {
|
|
||||||
}
|
}
|
||||||
-re -wrap " is set to \"?$val\"?\\." {
|
-re -wrap " is set to \"?$val\"?\\." {
|
||||||
}
|
}
|
||||||
@@ -6187,9 +6207,8 @@ proc with_set { var val body } {
|
|||||||
|
|
||||||
# Restore saved setting.
|
# Restore saved setting.
|
||||||
if { $save != "" } {
|
if { $save != "" } {
|
||||||
set cmd "set $var $save"
|
gdb_test_multiple "set $var $save" "" {
|
||||||
gdb_test_multiple $cmd "" {
|
-re -wrap "^" {
|
||||||
-re -wrap "^$cmd" {
|
|
||||||
}
|
}
|
||||||
-re -wrap "is set to \"?$save\"?( \\(\[^)\]*\\))?\\." {
|
-re -wrap "is set to \"?$save\"?( \\(\[^)\]*\\))?\\." {
|
||||||
}
|
}
|
||||||
@@ -7753,7 +7772,7 @@ proc get_valueof { fmt exp default {test ""} } {
|
|||||||
|
|
||||||
set val ${default}
|
set val ${default}
|
||||||
gdb_test_multiple "print${fmt} ${exp}" "$test" {
|
gdb_test_multiple "print${fmt} ${exp}" "$test" {
|
||||||
-re "\\$\[0-9\]* = (\[^\r\n\]*)\r\n$gdb_prompt $" {
|
-re -wrap "^\\$\[0-9\]* = (\[^\r\n\]*)" {
|
||||||
set val $expect_out(1,string)
|
set val $expect_out(1,string)
|
||||||
pass "$test"
|
pass "$test"
|
||||||
}
|
}
|
||||||
@@ -7802,7 +7821,7 @@ proc get_integer_valueof { exp default {test ""} } {
|
|||||||
|
|
||||||
set val ${default}
|
set val ${default}
|
||||||
gdb_test_multiple "print /d ${exp}" "$test" {
|
gdb_test_multiple "print /d ${exp}" "$test" {
|
||||||
-re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
|
-re -wrap "^\\$\[0-9\]* = (\[-\]*\[0-9\]*).*" {
|
||||||
set val $expect_out(1,string)
|
set val $expect_out(1,string)
|
||||||
pass "$test"
|
pass "$test"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user