1# Copyright 1999, 2000, 2001, 2002, 2003, 2004 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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17#
18# Test essential Machine interface (MI) operations
19#
20# Verify that, using the MI, we can run a simple program and perform basic
21# debugging activities like: insert breakpoints, run the program,
22# step, next, continue until it ends and, last but not least, quit.
23#
24# The goal is not to test gdb functionality, which is done by other tests,
25# but to verify the correct output response to MI operations.
26#
27
28load_lib mi-support.exp
29set MIFLAGS "-i=mi2"
30
31gdb_exit
32if [mi_gdb_start] {
33    continue
34}
35
36set testfile "basics"
37set srcfile ${testfile}.c
38set binfile ${objdir}/${subdir}/${testfile}
39if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
40     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41}
42
43mi_delete_breakpoints
44mi_gdb_reinitialize_dir $srcdir/$subdir
45mi_gdb_load ${binfile}
46
47proc test_watchpoint_creation_and_listing {} {
48    global mi_gdb_prompt
49    global srcfile
50    global hex
51
52    set line_callee4_head [gdb_get_line_number "callee4 ("]
53    set line_callee4_body [expr $line_callee4_head + 2]
54
55    # Insert a watchpoint and list
56    # Tests:
57    # -break-watch C
58    # -break-list
59
60    mi_gdb_test "111-break-watch C" \
61             "111\\^done,wpt=\{number=\"2\",exp=\"C\"\}" \
62             "break-watch operation"
63
64    mi_gdb_test "222-break-list" \
65	    "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=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_callee4_body\",times=\"1\"\},bkpt=\{number=\"2\",type=\".*watchpoint\",disp=\"keep\",enabled=\"y\",addr=\"\",what=\"C\",times=\"0\"\}\\\]\}" \
66                "list of watchpoints"
67
68}
69
70# UNUSED at the time
71proc test_awatch_creation_and_listing {} {
72    global mi_gdb_prompt
73    global srcfile
74    global hex
75
76    set line_main_head [gdb_get_line_number "main ("]
77    set line_main_body [expr $line_main_head + 2]
78
79    # Insert an access watchpoint and list it
80    # Tests:
81    # -break-watch -a A
82    # -break-list
83
84    mi_gdb_test "333-break-watch -a A" \
85             "333\\^done,bkpt=\{number=\"1\",addr=\"$hex\",file=\".*basics.c\",line=\"$line_main_body\"\}" \
86             "break-watch -a operation"
87
88    mi_gdb_test "444-break-list" \
89	    "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\"\},.*\}\\\]\}" \
90                "list of watchpoints awatch"
91
92    mi_gdb_test "777-break-delete 3" \
93	    "777\\^done" \
94	    "delete access watchpoint"
95}
96
97# UNUSED at the time
98proc test_rwatch_creation_and_listing {} {
99    global mi_gdb_prompt
100    global srcfile
101    global hex
102
103    set line_main_head [gdb_get_line_number "main ("]
104    set line_main_body [expr $line_main_head + 2]
105
106    # Insert a read watchpoint and list it.
107    # Tests:
108    # -break-insert -r B
109    # -break-list
110
111    mi_gdb_test "200-break-watch -r C" \
112             "200\\^done,bkpt=\{number=\"5\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\}" \
113             "break-insert -r operation"
114
115    mi_gdb_test "300-break-list" \
116	    "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\"\},.*\}\\\}\}" \
117                "list of breakpoints"
118
119    mi_gdb_test "177-break-delete 4" \
120	    "177\\^done" \
121	    "delete read watchpoint"
122}
123
124proc test_watchpoint_triggering {} {
125    global mi_gdb_prompt
126    global hex
127
128    set line_callee4_return_0     [gdb_get_line_number "return 0;"]
129    set line_callee3_head         [gdb_get_line_number "callee3 ("]
130    set line_callee3_close_brace  [expr $line_callee3_head + 3]
131
132    # Continue execution until the watchpoint is reached,  continue again,
133    # to see the watchpoint go out of scope.
134    # Does:
135    # -exec-continue (Here wp triggers)
136    # -exec-continue (Here wp goes out of scope)
137
138    send_gdb "222-exec-continue\n"
139    gdb_expect {
140      -re "222\\^running\r\n$mi_gdb_prompt" {
141        gdb_expect {
142	    -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\",line=\"$line_callee4_return_0\"\}\r\n$mi_gdb_prompt$" {
143            pass "watchpoint trigger"
144          }
145          -re ".*$mi_gdb_prompt$" {fail "watchpoint trigger (2)"}
146          timeout {fail "watchpoint trigger (timeout 2)"}
147        }
148      }
149      -re ".*$mi_gdb_prompt$" {fail "watchpoint trigger (1)"}
150      timeout {fail "watchpoint trigger (timeout 1)"}
151    }
152
153    send_gdb "223-exec-continue\n"
154    gdb_expect {
155      -re "223\\^running\r\n$mi_gdb_prompt" {
156        gdb_expect {
157	    -re "\[\r\n\]*223\\*stopped,reason=\"watchpoint-scope\",wpnum=\"2\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee3\",args=\\\[.*\\\],file=\".*basics.c\",line=\"$line_callee3_close_brace\"\}\r\n$mi_gdb_prompt$" {
158            pass "wp out of scope"
159          }
160          -re ".*$mi_gdb_prompt$" {fail "wp out of scope (2)"}
161          timeout {fail "wp out of scope (timeout 2)"}
162        }
163      }
164      -re ".*$mi_gdb_prompt$" {fail "wp out of scope (1)"}
165      timeout {fail "wp out of scope (timeout 1)"}
166    }
167}
168
169mi_runto callee4
170test_watchpoint_creation_and_listing
171#test_rwatch_creation_and_listing
172#test_awatch_creation_and_listing
173test_watchpoint_triggering
174
175mi_gdb_exit
176return 0
177