OSDN Git Service

b3ba8445971183a1f936bf9d49a42b8f0c3b4446
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.mi / mi-watch.exp
1 # Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2007
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
17
18 #
19 # Test essential Machine interface (MI) operations
20 #
21 # Verify that, using the MI, we can run a simple program and perform basic
22 # debugging activities like: insert breakpoints, run the program,
23 # step, next, continue until it ends and, last but not least, quit.
24 #
25 # The goal is not to test gdb functionality, which is done by other tests,
26 # but to verify the correct output response to MI operations.
27 #
28
29 load_lib mi-support.exp
30 set MIFLAGS "-i=mi"
31
32 gdb_exit
33 if [mi_gdb_start] {
34     continue
35 }
36
37 set testfile "basics"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
41      untested mi-watch.exp
42      return -1
43 }
44
45 mi_delete_breakpoints
46 mi_gdb_reinitialize_dir $srcdir/$subdir
47 mi_gdb_load ${binfile}
48
49 proc test_watchpoint_creation_and_listing {} {
50     global mi_gdb_prompt
51     global srcfile
52     global hex
53
54     set line_callee4_head [gdb_get_line_number "callee4 ("]
55     set line_callee4_body [expr $line_callee4_head + 2]
56
57     # Insert a watchpoint and list
58     # Tests:
59     # -break-watch C
60     # -break-list
61
62     mi_gdb_test "111-break-watch C" \
63              "111\\^done,wpt=\{number=\"2\",exp=\"C\"\}" \
64              "break-watch operation"
65
66     mi_gdb_test "222-break-list" \
67             "222\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[bkpt=\{number=\"2\",type=\".*watchpoint\",disp=\"keep\",enabled=\"y\",addr=\"\",what=\"C\",times=\"0\"\}\\\]\}" \
68                 "list of watchpoints"
69
70 }
71
72 # UNUSED at the time
73 proc test_awatch_creation_and_listing {} {
74     global mi_gdb_prompt
75     global srcfile
76     global hex
77
78     set line_main_head [gdb_get_line_number "main ("]
79     set line_main_body [expr $line_main_head + 2]
80
81     # Insert an access watchpoint and list it
82     # Tests:
83     # -break-watch -a A
84     # -break-list
85
86     mi_gdb_test "333-break-watch -a A" \
87              "333\\^done,bkpt=\{number=\"1\",addr=\"$hex\",file=\".*basics.c\",line=\"$line_main_body\"\}" \
88              "break-watch -a operation"
89
90     mi_gdb_test "444-break-list" \
91             "444\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"3\",type=\"watchpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\},.*\}\\\]\}" \
92                 "list of watchpoints awatch"
93
94     mi_gdb_test "777-break-delete 3" \
95             "777\\^done" \
96             "delete access watchpoint"
97 }
98
99 # UNUSED at the time
100 proc test_rwatch_creation_and_listing {} {
101     global mi_gdb_prompt
102     global srcfile
103     global hex
104
105     set line_main_head [gdb_get_line_number "main ("]
106     set line_main_body [expr $line_main_head + 2]
107
108     # Insert a read watchpoint and list it.
109     # Tests:
110     # -break-insert -r B
111     # -break-list
112
113     mi_gdb_test "200-break-watch -r C" \
114              "200\\^done,bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\}" \
115              "break-insert -r operation"
116
117     mi_gdb_test "300-break-list" \
118             "300\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\},.*\}\\\}\}" \
119                 "list of breakpoints"
120
121     mi_gdb_test "177-break-delete 4" \
122             "177\\^done" \
123             "delete read watchpoint"
124 }
125
126 proc test_watchpoint_triggering {} {
127     global mi_gdb_prompt
128     global hex fullname_syntax srcfile
129
130     set line_callee4_return_0     [gdb_get_line_number "return 0;"]
131     set line_callee3_head         [gdb_get_line_number "callee3 ("]
132     set line_callee3_close_brace  [expr $line_callee3_head + 3]
133
134     # Continue execution until the watchpoint is reached,  continue again, 
135     # to see the watchpoint go out of scope.
136     # Does:
137     # -exec-continue (Here wp triggers)
138     # -exec-continue (Here wp goes out of scope)
139
140     send_gdb "222-exec-continue\n"
141     gdb_expect {
142       -re "222\\^running\r\n$mi_gdb_prompt" {
143         gdb_expect {
144             -re "222\\*stopped,reason=\"watchpoint-trigger\",wpt=\{number=\"2\",exp=\"C\"\},value=\{old=\".*\",new=\"3\"\},thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee4\",args=\\\[\\\],file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_return_0\"\}\r\n$mi_gdb_prompt$" {
145             pass "watchpoint trigger"
146           }
147           -re ".*$mi_gdb_prompt$" {fail "watchpoint trigger (2)"}
148           timeout {fail "watchpoint trigger (timeout 2)"}
149         }
150       }
151       -re ".*$mi_gdb_prompt$" {fail "watchpoint trigger (1)"}
152       timeout {fail "watchpoint trigger (timeout 1)"}
153     }
154
155     send_gdb "223-exec-continue\n"
156     gdb_expect {
157       -re "223\\^running\r\n$mi_gdb_prompt" {
158         gdb_expect {
159             -re "\[\r\n\]*223\\*stopped,reason=\"watchpoint-scope\",wpnum=\"2\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee3\",args=\\\[.*\\\],file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee3_close_brace\"\}\r\n$mi_gdb_prompt$" {
160             pass "wp out of scope"
161           }
162           -re ".*$mi_gdb_prompt$" {fail "wp out of scope (2)"}
163           timeout {fail "wp out of scope (timeout 2)"}
164         }
165       }
166       -re ".*$mi_gdb_prompt$" {fail "wp out of scope (1)"}
167       timeout {fail "wp out of scope (timeout 1)"}
168     }
169 }
170
171 mi_runto callee4
172 test_watchpoint_creation_and_listing
173 #test_rwatch_creation_and_listing
174 #test_awatch_creation_and_listing
175 test_watchpoint_triggering
176
177 mi_gdb_exit
178 return 0