gdb.base/watch-bitfields.exp: Improve test
[external/binutils.git] / gdb / testsuite / gdb.base / watch-bitfields.exp
1 # Copyright 2014 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the gdb testsuite
17
18 standard_testfile
19
20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
21     return -1
22 }
23
24 # Set a watchpoint watching EXPR.
25 proc watch { expr } {
26     global decimal
27
28     set expr_re [string_to_regexp $expr]
29     gdb_test "watch $expr" \
30         "\(Hardware \)?\[Ww\]atchpoint $decimal: $expr_re"
31 }
32
33 # Continue inferior execution, expecting the watchpoint EXPR to be triggered
34 # having old value OLD and new value NEW.
35 proc expect_watchpoint { expr old new } {
36     with_test_prefix "$expr: $old->$new" {
37         set expr_re [string_to_regexp $expr]
38         gdb_test "print $expr" "\\$\\d+ = $old\\s" "print expression before"
39         gdb_test "continue" "$expr_re\\s.*Old value = $old\\s+New value = $new\\s.*"
40         gdb_test "print $expr" "\\$\\d+ = $new\\s" "print expression after"
41     }
42 }
43
44 # Check that -location watchpoints against bitfields trigger properly.
45 proc test_watch_location {} {
46     with_test_prefix "-location watch against bitfields" {
47         if {![runto_main]} {
48             return -1
49         }
50
51         watch "-location q.a"
52         watch "-location q.e"
53         expect_watchpoint "q.a" 0 1
54         expect_watchpoint "q.e" 0 5
55         expect_watchpoint "q.a" 1 0
56         expect_watchpoint "q.e" 5 4
57         gdb_continue_to_end
58     }
59 }
60
61 # Check that regular watchpoints against expressions involving
62 # bitfields trigger properly.
63 proc test_regular_watch {} {
64     with_test_prefix "regular watch against bitfields" {
65         if {![runto_main]} {
66             return -1
67         }
68
69         watch "q.d + q.f + q.g"
70         expect_watchpoint "q.d + q.f + q.g" 0 4
71         expect_watchpoint "q.d + q.f + q.g" 4 10
72         expect_watchpoint "q.d + q.f + q.g" 10 3
73         expect_watchpoint "q.d + q.f + q.g" 3 2
74         expect_watchpoint "q.d + q.f + q.g" 2 1
75         expect_watchpoint "q.d + q.f + q.g" 1 0
76         gdb_continue_to_end
77     }
78 }
79
80 test_watch_location
81 test_regular_watch