blob: 0608e49b28cf43b84a0463885a577291dafc7d6b [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)
Michael Woerister47e8cf72014-10-09 14:31:0312// min-lldb-version: 310
Michael Woerister55a8bd52014-04-24 09:35:4813
14// This test case checks if function arguments already have the correct value when breaking at the
Keegan McAllisterdb3bd232014-09-06 00:28:2415// beginning of a function. Functions with the #[no_stack_check] attribute have the same prologue as
Michael Woerister55a8bd52014-04-24 09:35:4816// regular C functions compiled with GCC or Clang and therefore are better handled by GDB. As a
17// consequence, and as opposed to regular Rust functions, we can set the breakpoints via the
Michael Woeristerc7f45a92014-07-09 12:46:0918// function name (and don't have to fall back on using line numbers). For LLDB this shouldn't make
19// a difference because it can handle both cases.
Michael Woerister55a8bd52014-04-24 09:35:4820
21// compile-flags:-g
Michael Woeristerc7f45a92014-07-09 12:46:0922
Brian Andersondf290f12015-03-06 02:33:5823#![feature(old_io)]
24
Michael Woeristerc7f45a92014-07-09 12:46:0925// === GDB TESTS ===================================================================================
26
Michael Woerister55a8bd52014-04-24 09:35:4827// gdb-command:rbreak immediate_args
28// gdb-command:rbreak binding
29// gdb-command:rbreak assignment
30// gdb-command:rbreak function_call
31// gdb-command:rbreak identifier
32// gdb-command:rbreak return_expr
33// gdb-command:rbreak arithmetic_expr
34// gdb-command:rbreak if_expr
35// gdb-command:rbreak while_expr
36// gdb-command:rbreak loop_expr
37// gdb-command:run
38
39// IMMEDIATE ARGS
40// gdb-command:print a
41// gdb-check:$1 = 1
42// gdb-command:print b
43// gdb-check:$2 = true
44// gdb-command:print c
45// gdb-check:$3 = 2.5
46// gdb-command:continue
47
48// NON IMMEDIATE ARGS
49// gdb-command:print a
50// gdb-check:$4 = {a = 3, b = 4, c = 5, d = 6, e = 7, f = 8, g = 9, h = 10}
51// gdb-command:print b
52// gdb-check:$5 = {a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17, h = 18}
53// gdb-command:continue
54
55// BINDING
56// gdb-command:print a
57// gdb-check:$6 = 19
58// gdb-command:print b
59// gdb-check:$7 = 20
60// gdb-command:print c
61// gdb-check:$8 = 21.5
62// gdb-command:continue
63
64// ASSIGNMENT
65// gdb-command:print a
66// gdb-check:$9 = 22
67// gdb-command:print b
68// gdb-check:$10 = 23
69// gdb-command:print c
70// gdb-check:$11 = 24.5
71// gdb-command:continue
72
73// FUNCTION CALL
74// gdb-command:print x
75// gdb-check:$12 = 25
76// gdb-command:print y
77// gdb-check:$13 = 26
78// gdb-command:print z
79// gdb-check:$14 = 27.5
80// gdb-command:continue
81
82// EXPR
83// gdb-command:print x
84// gdb-check:$15 = 28
85// gdb-command:print y
86// gdb-check:$16 = 29
87// gdb-command:print z
88// gdb-check:$17 = 30.5
89// gdb-command:continue
90
91// RETURN EXPR
92// gdb-command:print x
93// gdb-check:$18 = 31
94// gdb-command:print y
95// gdb-check:$19 = 32
96// gdb-command:print z
97// gdb-check:$20 = 33.5
98// gdb-command:continue
99
100// ARITHMETIC EXPR
101// gdb-command:print x
102// gdb-check:$21 = 34
103// gdb-command:print y
104// gdb-check:$22 = 35
105// gdb-command:print z
106// gdb-check:$23 = 36.5
107// gdb-command:continue
108
109// IF EXPR
110// gdb-command:print x
111// gdb-check:$24 = 37
112// gdb-command:print y
113// gdb-check:$25 = 38
114// gdb-command:print z
115// gdb-check:$26 = 39.5
116// gdb-command:continue
117
118// WHILE EXPR
119// gdb-command:print x
120// gdb-check:$27 = 40
121// gdb-command:print y
122// gdb-check:$28 = 41
123// gdb-command:print z
124// gdb-check:$29 = 42
125// gdb-command:continue
126
127// LOOP EXPR
128// gdb-command:print x
129// gdb-check:$30 = 43
130// gdb-command:print y
131// gdb-check:$31 = 44
132// gdb-command:print z
133// gdb-check:$32 = 45
134// gdb-command:continue
135
Michael Woeristerc7f45a92014-07-09 12:46:09136
137// === LLDB TESTS ==================================================================================
138
139// lldb-command:breakpoint set --name immediate_args
140// lldb-command:breakpoint set --name non_immediate_args
141// lldb-command:breakpoint set --name binding
142// lldb-command:breakpoint set --name assignment
143// lldb-command:breakpoint set --name function_call
144// lldb-command:breakpoint set --name identifier
145// lldb-command:breakpoint set --name return_expr
146// lldb-command:breakpoint set --name arithmetic_expr
147// lldb-command:breakpoint set --name if_expr
148// lldb-command:breakpoint set --name while_expr
149// lldb-command:breakpoint set --name loop_expr
150// lldb-command:run
151
152// IMMEDIATE ARGS
153// lldb-command:print a
154// lldb-check:[...]$0 = 1
155// lldb-command:print b
156// lldb-check:[...]$1 = true
157// lldb-command:print c
158// lldb-check:[...]$2 = 2.5
159// lldb-command:continue
160
161// NON IMMEDIATE ARGS
162// lldb-command:print a
163// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 }
164// lldb-command:print b
165// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 }
166// lldb-command:continue
167
168// BINDING
169// lldb-command:print a
170// lldb-check:[...]$5 = 19
171// lldb-command:print b
172// lldb-check:[...]$6 = 20
173// lldb-command:print c
174// lldb-check:[...]$7 = 21.5
175// lldb-command:continue
176
177// ASSIGNMENT
178// lldb-command:print a
179// lldb-check:[...]$8 = 22
180// lldb-command:print b
181// lldb-check:[...]$9 = 23
182// lldb-command:print c
183// lldb-check:[...]$10 = 24.5
184// lldb-command:continue
185
186// FUNCTION CALL
187// lldb-command:print x
188// lldb-check:[...]$11 = 25
189// lldb-command:print y
190// lldb-check:[...]$12 = 26
191// lldb-command:print z
192// lldb-check:[...]$13 = 27.5
193// lldb-command:continue
194
195// EXPR
196// lldb-command:print x
197// lldb-check:[...]$14 = 28
198// lldb-command:print y
199// lldb-check:[...]$15 = 29
200// lldb-command:print z
201// lldb-check:[...]$16 = 30.5
202// lldb-command:continue
203
204// RETURN EXPR
205// lldb-command:print x
206// lldb-check:[...]$17 = 31
207// lldb-command:print y
208// lldb-check:[...]$18 = 32
209// lldb-command:print z
210// lldb-check:[...]$19 = 33.5
211// lldb-command:continue
212
213// ARITHMETIC EXPR
214// lldb-command:print x
215// lldb-check:[...]$20 = 34
216// lldb-command:print y
217// lldb-check:[...]$21 = 35
218// lldb-command:print z
219// lldb-check:[...]$22 = 36.5
220// lldb-command:continue
221
222// IF EXPR
223// lldb-command:print x
224// lldb-check:[...]$23 = 37
225// lldb-command:print y
226// lldb-check:[...]$24 = 38
227// lldb-command:print z
228// lldb-check:[...]$25 = 39.5
229// lldb-command:continue
230
231// WHILE EXPR
232// lldb-command:print x
233// lldb-check:[...]$26 = 40
234// lldb-command:print y
235// lldb-check:[...]$27 = 41
236// lldb-command:print z
237// lldb-check:[...]$28 = 42
238// lldb-command:continue
239
240// LOOP EXPR
241// lldb-command:print x
242// lldb-check:[...]$29 = 43
243// lldb-command:print y
244// lldb-check:[...]$30 = 44
245// lldb-command:print z
246// lldb-check:[...]$31 = 45
247// lldb-command:continue
248
Aaron Turone0ad0fc2014-10-27 22:37:07249#![allow(unused_variables)]
Michael Woerister91a0e182014-12-03 22:48:18250#![omit_gdb_pretty_printer_section]
Michael Woerister55a8bd52014-04-24 09:35:48251
Keegan McAllisterdb3bd232014-09-06 00:28:24252#[no_stack_check]
Alex Crichton43bfaa42015-03-26 00:06:52253fn immediate_args(a: isize, b: bool, c: f64) {
Alex Crichton3a07f852015-01-23 00:31:00254 ::std::old_io::print("");
Michael Woerister55a8bd52014-04-24 09:35:48255}
256
257struct BigStruct {
258 a: u64,
259 b: u64,
260 c: u64,
261 d: u64,
262 e: u64,
263 f: u64,
264 g: u64,
265 h: u64
266}
267
Keegan McAllisterdb3bd232014-09-06 00:28:24268#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48269fn non_immediate_args(a: BigStruct, b: BigStruct) {
Alex Crichton3a07f852015-01-23 00:31:00270 ::std::old_io::print("");
Michael Woerister55a8bd52014-04-24 09:35:48271}
272
Keegan McAllisterdb3bd232014-09-06 00:28:24273#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48274fn binding(a: i64, b: u64, c: f64) {
Tobias Bucher7f64fe42015-01-25 21:05:03275 let x = 0;
Alex Crichton3a07f852015-01-23 00:31:00276 ::std::old_io::print("");
Michael Woerister55a8bd52014-04-24 09:35:48277}
278
Keegan McAllisterdb3bd232014-09-06 00:28:24279#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48280fn assignment(mut a: u64, b: u64, c: f64) {
281 a = b;
Alex Crichton3a07f852015-01-23 00:31:00282 ::std::old_io::print("");
Michael Woerister55a8bd52014-04-24 09:35:48283}
284
Keegan McAllisterdb3bd232014-09-06 00:28:24285#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48286fn function_call(x: u64, y: u64, z: f64) {
Alex Crichton3a07f852015-01-23 00:31:00287 std::old_io::stdio::print("Hi!")
Michael Woerister55a8bd52014-04-24 09:35:48288}
289
Keegan McAllisterdb3bd232014-09-06 00:28:24290#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48291fn identifier(x: u64, y: u64, z: f64) -> u64 {
292 x
293}
294
Keegan McAllisterdb3bd232014-09-06 00:28:24295#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48296fn return_expr(x: u64, y: u64, z: f64) -> u64 {
297 return x;
298}
299
Keegan McAllisterdb3bd232014-09-06 00:28:24300#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48301fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 {
302 x + y
303}
304
Keegan McAllisterdb3bd232014-09-06 00:28:24305#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48306fn if_expr(x: u64, y: u64, z: f64) -> u64 {
307 if x + y < 1000 {
308 x
309 } else {
310 y
311 }
312}
313
Keegan McAllisterdb3bd232014-09-06 00:28:24314#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48315fn while_expr(mut x: u64, y: u64, z: u64) -> u64 {
316 while x + y < 1000 {
317 x += z
318 }
319 return x;
320}
321
Keegan McAllisterdb3bd232014-09-06 00:28:24322#[no_stack_check]
Michael Woerister55a8bd52014-04-24 09:35:48323fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 {
324 loop {
325 x += z;
326
327 if x + y > 1000 {
328 return x;
329 }
330 }
331}
332
333fn main() {
334 immediate_args(1, true, 2.5);
335
336 non_immediate_args(
337 BigStruct {
338 a: 3,
339 b: 4,
340 c: 5,
341 d: 6,
342 e: 7,
343 f: 8,
344 g: 9,
345 h: 10
346 },
347 BigStruct {
348 a: 11,
349 b: 12,
350 c: 13,
351 d: 14,
352 e: 15,
353 f: 16,
354 g: 17,
355 h: 18
356 }
357 );
358
359 binding(19, 20, 21.5);
360 assignment(22, 23, 24.5);
361 function_call(25, 26, 27.5);
362 identifier(28, 29, 30.5);
363 return_expr(31, 32, 33.5);
364 arithmetic_expr(34, 35, 36.5);
365 if_expr(37, 38, 39.5);
366 while_expr(40, 41, 42);
367 loop_expr(43, 44, 45);
368}