blob: a9ccf3cdb161be4c16e5c5204305c84a91c509c5 [file] [log] [blame]
Michael Woerister55a8bd52014-04-24 09:35:481// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11// ignore-android: FIXME(#10381)
12
13// This test case checks if function arguments already have the correct value when breaking at the
14// beginning of a function. Functions with the #[no_split_stack] attribute have the same prologue as
15// regular C functions compiled with GCC or Clang and therefore are better handled by GDB. As a
16// consequence, and as opposed to regular Rust functions, we can set the breakpoints via the
17// function name (and don't have to fall back on using line numbers).
18
19// compile-flags:-g
20// gdb-command:set print pretty off
21// gdb-command:rbreak immediate_args
22// gdb-command:rbreak binding
23// gdb-command:rbreak assignment
24// gdb-command:rbreak function_call
25// gdb-command:rbreak identifier
26// gdb-command:rbreak return_expr
27// gdb-command:rbreak arithmetic_expr
28// gdb-command:rbreak if_expr
29// gdb-command:rbreak while_expr
30// gdb-command:rbreak loop_expr
31// gdb-command:run
32
33// IMMEDIATE ARGS
34// gdb-command:print a
35// gdb-check:$1 = 1
36// gdb-command:print b
37// gdb-check:$2 = true
38// gdb-command:print c
39// gdb-check:$3 = 2.5
40// gdb-command:continue
41
42// NON IMMEDIATE ARGS
43// gdb-command:print a
44// gdb-check:$4 = {a = 3, b = 4, c = 5, d = 6, e = 7, f = 8, g = 9, h = 10}
45// gdb-command:print b
46// gdb-check:$5 = {a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17, h = 18}
47// gdb-command:continue
48
49// BINDING
50// gdb-command:print a
51// gdb-check:$6 = 19
52// gdb-command:print b
53// gdb-check:$7 = 20
54// gdb-command:print c
55// gdb-check:$8 = 21.5
56// gdb-command:continue
57
58// ASSIGNMENT
59// gdb-command:print a
60// gdb-check:$9 = 22
61// gdb-command:print b
62// gdb-check:$10 = 23
63// gdb-command:print c
64// gdb-check:$11 = 24.5
65// gdb-command:continue
66
67// FUNCTION CALL
68// gdb-command:print x
69// gdb-check:$12 = 25
70// gdb-command:print y
71// gdb-check:$13 = 26
72// gdb-command:print z
73// gdb-check:$14 = 27.5
74// gdb-command:continue
75
76// EXPR
77// gdb-command:print x
78// gdb-check:$15 = 28
79// gdb-command:print y
80// gdb-check:$16 = 29
81// gdb-command:print z
82// gdb-check:$17 = 30.5
83// gdb-command:continue
84
85// RETURN EXPR
86// gdb-command:print x
87// gdb-check:$18 = 31
88// gdb-command:print y
89// gdb-check:$19 = 32
90// gdb-command:print z
91// gdb-check:$20 = 33.5
92// gdb-command:continue
93
94// ARITHMETIC EXPR
95// gdb-command:print x
96// gdb-check:$21 = 34
97// gdb-command:print y
98// gdb-check:$22 = 35
99// gdb-command:print z
100// gdb-check:$23 = 36.5
101// gdb-command:continue
102
103// IF EXPR
104// gdb-command:print x
105// gdb-check:$24 = 37
106// gdb-command:print y
107// gdb-check:$25 = 38
108// gdb-command:print z
109// gdb-check:$26 = 39.5
110// gdb-command:continue
111
112// WHILE EXPR
113// gdb-command:print x
114// gdb-check:$27 = 40
115// gdb-command:print y
116// gdb-check:$28 = 41
117// gdb-command:print z
118// gdb-check:$29 = 42
119// gdb-command:continue
120
121// LOOP EXPR
122// gdb-command:print x
123// gdb-check:$30 = 43
124// gdb-command:print y
125// gdb-check:$31 = 44
126// gdb-command:print z
127// gdb-check:$32 = 45
128// gdb-command:continue
129
130#![allow(unused_variable)]
131
132#[no_split_stack]
133fn immediate_args(a: int, b: bool, c: f64) {
134 ()
135}
136
137struct BigStruct {
138 a: u64,
139 b: u64,
140 c: u64,
141 d: u64,
142 e: u64,
143 f: u64,
144 g: u64,
145 h: u64
146}
147
148#[no_split_stack]
149fn non_immediate_args(a: BigStruct, b: BigStruct) {
150 ()
151}
152
153#[no_split_stack]
154fn binding(a: i64, b: u64, c: f64) {
155 let x = 0;
156}
157
158#[no_split_stack]
159fn assignment(mut a: u64, b: u64, c: f64) {
160 a = b;
161}
162
163#[no_split_stack]
164fn function_call(x: u64, y: u64, z: f64) {
165 std::io::stdio::print("Hi!")
166}
167
168#[no_split_stack]
169fn identifier(x: u64, y: u64, z: f64) -> u64 {
170 x
171}
172
173#[no_split_stack]
174fn return_expr(x: u64, y: u64, z: f64) -> u64 {
175 return x;
176}
177
178#[no_split_stack]
179fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 {
180 x + y
181}
182
183#[no_split_stack]
184fn if_expr(x: u64, y: u64, z: f64) -> u64 {
185 if x + y < 1000 {
186 x
187 } else {
188 y
189 }
190}
191
192#[no_split_stack]
193fn while_expr(mut x: u64, y: u64, z: u64) -> u64 {
194 while x + y < 1000 {
195 x += z
196 }
197 return x;
198}
199
200#[no_split_stack]
201fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 {
202 loop {
203 x += z;
204
205 if x + y > 1000 {
206 return x;
207 }
208 }
209}
210
211fn main() {
212 immediate_args(1, true, 2.5);
213
214 non_immediate_args(
215 BigStruct {
216 a: 3,
217 b: 4,
218 c: 5,
219 d: 6,
220 e: 7,
221 f: 8,
222 g: 9,
223 h: 10
224 },
225 BigStruct {
226 a: 11,
227 b: 12,
228 c: 13,
229 d: 14,
230 e: 15,
231 f: 16,
232 g: 17,
233 h: 18
234 }
235 );
236
237 binding(19, 20, 21.5);
238 assignment(22, 23, 24.5);
239 function_call(25, 26, 27.5);
240 identifier(28, 29, 30.5);
241 return_expr(31, 32, 33.5);
242 arithmetic_expr(34, 35, 36.5);
243 if_expr(37, 38, 39.5);
244 while_expr(40, 41, 42);
245 loop_expr(43, 44, 45);
246}