blob: 05e2c5eb6c7ca84ad916494998331a4039479d7a [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
Michael Woeristerc7f45a92014-07-09 12:46:0917// function name (and don't have to fall back on using line numbers). For LLDB this shouldn't make
18// a difference because it can handle both cases.
Michael Woerister55a8bd52014-04-24 09:35:4819
20// compile-flags:-g
Michael Woeristerc7f45a92014-07-09 12:46:0921
22// === GDB TESTS ===================================================================================
23
Michael Woerister55a8bd52014-04-24 09:35:4824// gdb-command:set print pretty off
25// gdb-command:rbreak immediate_args
26// gdb-command:rbreak binding
27// gdb-command:rbreak assignment
28// gdb-command:rbreak function_call
29// gdb-command:rbreak identifier
30// gdb-command:rbreak return_expr
31// gdb-command:rbreak arithmetic_expr
32// gdb-command:rbreak if_expr
33// gdb-command:rbreak while_expr
34// gdb-command:rbreak loop_expr
35// gdb-command:run
36
37// IMMEDIATE ARGS
38// gdb-command:print a
39// gdb-check:$1 = 1
40// gdb-command:print b
41// gdb-check:$2 = true
42// gdb-command:print c
43// gdb-check:$3 = 2.5
44// gdb-command:continue
45
46// NON IMMEDIATE ARGS
47// gdb-command:print a
48// gdb-check:$4 = {a = 3, b = 4, c = 5, d = 6, e = 7, f = 8, g = 9, h = 10}
49// gdb-command:print b
50// gdb-check:$5 = {a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17, h = 18}
51// gdb-command:continue
52
53// BINDING
54// gdb-command:print a
55// gdb-check:$6 = 19
56// gdb-command:print b
57// gdb-check:$7 = 20
58// gdb-command:print c
59// gdb-check:$8 = 21.5
60// gdb-command:continue
61
62// ASSIGNMENT
63// gdb-command:print a
64// gdb-check:$9 = 22
65// gdb-command:print b
66// gdb-check:$10 = 23
67// gdb-command:print c
68// gdb-check:$11 = 24.5
69// gdb-command:continue
70
71// FUNCTION CALL
72// gdb-command:print x
73// gdb-check:$12 = 25
74// gdb-command:print y
75// gdb-check:$13 = 26
76// gdb-command:print z
77// gdb-check:$14 = 27.5
78// gdb-command:continue
79
80// EXPR
81// gdb-command:print x
82// gdb-check:$15 = 28
83// gdb-command:print y
84// gdb-check:$16 = 29
85// gdb-command:print z
86// gdb-check:$17 = 30.5
87// gdb-command:continue
88
89// RETURN EXPR
90// gdb-command:print x
91// gdb-check:$18 = 31
92// gdb-command:print y
93// gdb-check:$19 = 32
94// gdb-command:print z
95// gdb-check:$20 = 33.5
96// gdb-command:continue
97
98// ARITHMETIC EXPR
99// gdb-command:print x
100// gdb-check:$21 = 34
101// gdb-command:print y
102// gdb-check:$22 = 35
103// gdb-command:print z
104// gdb-check:$23 = 36.5
105// gdb-command:continue
106
107// IF EXPR
108// gdb-command:print x
109// gdb-check:$24 = 37
110// gdb-command:print y
111// gdb-check:$25 = 38
112// gdb-command:print z
113// gdb-check:$26 = 39.5
114// gdb-command:continue
115
116// WHILE EXPR
117// gdb-command:print x
118// gdb-check:$27 = 40
119// gdb-command:print y
120// gdb-check:$28 = 41
121// gdb-command:print z
122// gdb-check:$29 = 42
123// gdb-command:continue
124
125// LOOP EXPR
126// gdb-command:print x
127// gdb-check:$30 = 43
128// gdb-command:print y
129// gdb-check:$31 = 44
130// gdb-command:print z
131// gdb-check:$32 = 45
132// gdb-command:continue
133
Michael Woeristerc7f45a92014-07-09 12:46:09134
135// === LLDB TESTS ==================================================================================
136
137// lldb-command:breakpoint set --name immediate_args
138// lldb-command:breakpoint set --name non_immediate_args
139// lldb-command:breakpoint set --name binding
140// lldb-command:breakpoint set --name assignment
141// lldb-command:breakpoint set --name function_call
142// lldb-command:breakpoint set --name identifier
143// lldb-command:breakpoint set --name return_expr
144// lldb-command:breakpoint set --name arithmetic_expr
145// lldb-command:breakpoint set --name if_expr
146// lldb-command:breakpoint set --name while_expr
147// lldb-command:breakpoint set --name loop_expr
148// lldb-command:run
149
150// IMMEDIATE ARGS
151// lldb-command:print a
152// lldb-check:[...]$0 = 1
153// lldb-command:print b
154// lldb-check:[...]$1 = true
155// lldb-command:print c
156// lldb-check:[...]$2 = 2.5
157// lldb-command:continue
158
159// NON IMMEDIATE ARGS
160// lldb-command:print a
161// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 }
162// lldb-command:print b
163// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 }
164// lldb-command:continue
165
166// BINDING
167// lldb-command:print a
168// lldb-check:[...]$5 = 19
169// lldb-command:print b
170// lldb-check:[...]$6 = 20
171// lldb-command:print c
172// lldb-check:[...]$7 = 21.5
173// lldb-command:continue
174
175// ASSIGNMENT
176// lldb-command:print a
177// lldb-check:[...]$8 = 22
178// lldb-command:print b
179// lldb-check:[...]$9 = 23
180// lldb-command:print c
181// lldb-check:[...]$10 = 24.5
182// lldb-command:continue
183
184// FUNCTION CALL
185// lldb-command:print x
186// lldb-check:[...]$11 = 25
187// lldb-command:print y
188// lldb-check:[...]$12 = 26
189// lldb-command:print z
190// lldb-check:[...]$13 = 27.5
191// lldb-command:continue
192
193// EXPR
194// lldb-command:print x
195// lldb-check:[...]$14 = 28
196// lldb-command:print y
197// lldb-check:[...]$15 = 29
198// lldb-command:print z
199// lldb-check:[...]$16 = 30.5
200// lldb-command:continue
201
202// RETURN EXPR
203// lldb-command:print x
204// lldb-check:[...]$17 = 31
205// lldb-command:print y
206// lldb-check:[...]$18 = 32
207// lldb-command:print z
208// lldb-check:[...]$19 = 33.5
209// lldb-command:continue
210
211// ARITHMETIC EXPR
212// lldb-command:print x
213// lldb-check:[...]$20 = 34
214// lldb-command:print y
215// lldb-check:[...]$21 = 35
216// lldb-command:print z
217// lldb-check:[...]$22 = 36.5
218// lldb-command:continue
219
220// IF EXPR
221// lldb-command:print x
222// lldb-check:[...]$23 = 37
223// lldb-command:print y
224// lldb-check:[...]$24 = 38
225// lldb-command:print z
226// lldb-check:[...]$25 = 39.5
227// lldb-command:continue
228
229// WHILE EXPR
230// lldb-command:print x
231// lldb-check:[...]$26 = 40
232// lldb-command:print y
233// lldb-check:[...]$27 = 41
234// lldb-command:print z
235// lldb-check:[...]$28 = 42
236// lldb-command:continue
237
238// LOOP EXPR
239// lldb-command:print x
240// lldb-check:[...]$29 = 43
241// lldb-command:print y
242// lldb-check:[...]$30 = 44
243// lldb-command:print z
244// lldb-check:[...]$31 = 45
245// lldb-command:continue
246
Michael Woerister55a8bd52014-04-24 09:35:48247#![allow(unused_variable)]
248
249#[no_split_stack]
250fn immediate_args(a: int, b: bool, c: f64) {
251 ()
252}
253
254struct BigStruct {
255 a: u64,
256 b: u64,
257 c: u64,
258 d: u64,
259 e: u64,
260 f: u64,
261 g: u64,
262 h: u64
263}
264
265#[no_split_stack]
266fn non_immediate_args(a: BigStruct, b: BigStruct) {
267 ()
268}
269
270#[no_split_stack]
271fn binding(a: i64, b: u64, c: f64) {
Patrick Waltona5bb0a32014-06-27 19:30:25272 let x = 0i;
Michael Woerister55a8bd52014-04-24 09:35:48273}
274
275#[no_split_stack]
276fn assignment(mut a: u64, b: u64, c: f64) {
277 a = b;
278}
279
280#[no_split_stack]
281fn function_call(x: u64, y: u64, z: f64) {
282 std::io::stdio::print("Hi!")
283}
284
285#[no_split_stack]
286fn identifier(x: u64, y: u64, z: f64) -> u64 {
287 x
288}
289
290#[no_split_stack]
291fn return_expr(x: u64, y: u64, z: f64) -> u64 {
292 return x;
293}
294
295#[no_split_stack]
296fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 {
297 x + y
298}
299
300#[no_split_stack]
301fn if_expr(x: u64, y: u64, z: f64) -> u64 {
302 if x + y < 1000 {
303 x
304 } else {
305 y
306 }
307}
308
309#[no_split_stack]
310fn while_expr(mut x: u64, y: u64, z: u64) -> u64 {
311 while x + y < 1000 {
312 x += z
313 }
314 return x;
315}
316
317#[no_split_stack]
318fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 {
319 loop {
320 x += z;
321
322 if x + y > 1000 {
323 return x;
324 }
325 }
326}
327
328fn main() {
329 immediate_args(1, true, 2.5);
330
331 non_immediate_args(
332 BigStruct {
333 a: 3,
334 b: 4,
335 c: 5,
336 d: 6,
337 e: 7,
338 f: 8,
339 g: 9,
340 h: 10
341 },
342 BigStruct {
343 a: 11,
344 b: 12,
345 c: 13,
346 d: 14,
347 e: 15,
348 f: 16,
349 g: 17,
350 h: 18
351 }
352 );
353
354 binding(19, 20, 21.5);
355 assignment(22, 23, 24.5);
356 function_call(25, 26, 27.5);
357 identifier(28, 29, 30.5);
358 return_expr(31, 32, 33.5);
359 arithmetic_expr(34, 35, 36.5);
360 if_expr(37, 38, 39.5);
361 while_expr(40, 41, 42);
362 loop_expr(43, 44, 45);
363}