Files
binutils-gdb/gdb/testsuite/gdb.base/maint-print-frame-id.exp
Andrew Burgess a68f7e9844 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).
2023-05-12 13:45:52 +01:00

65 lines
1.8 KiB
Plaintext

# Copyright 2022-2023 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test the 'maint print frame-id' command.
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile \
$srcfile {debug}]} {
return -1
}
if {![runto_main]} {
return -1
}
gdb_breakpoint foo
gdb_continue_to_breakpoint "run to foo"
proc get_frame_id { level } {
set id "**unknown**"
gdb_test_multiple "maint print frame-id ${level}" "" {
-wrap -re "^frame-id for frame #\[0-9\]+: (\[^\r\n\]+)" {
set id $expect_out(1,string)
pass $gdb_test_name
}
}
return $id
}
# Get the frame-id for each frame using the frame level.
array set ids {}
with_test_prefix "get id by level" {
for { set i 0 } { $i < 4 } { incr i } {
set ids($i) [get_frame_id $i]
}
}
# Now get the frame-id of the currently selected frame, and check it
# matches the frame-id we got earlier. Then move up the stack,
# selecting a new frame.
for { set i 0 } { $i < 4 } { incr i } {
with_test_prefix "frame $i is current" {
set id [get_frame_id ""]
gdb_assert { [string equal $id $ids($i)] } \
"check frame-id matches"
}
gdb_test "up" ".*" \
"move up from frame $i"
}