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