OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <string.h> | 8 #include <string.h> |
| 9 #include <alloca.h> |
9 | 10 |
10 int global_var; | 11 int global_var; |
| 12 volatile void *global_ptr; |
11 | 13 |
12 void test_two_line_function(int arg) { | 14 void test_two_line_function(int arg) { |
13 global_var = arg - 1; | 15 global_var = arg - 1; |
14 global_var = arg; | 16 global_var = arg; |
15 } | 17 } |
16 | 18 |
17 void test_stepi_after_break() { | 19 void test_stepi_after_break() { |
18 /* Something meaningful to step through. */ | 20 /* Something meaningful to step through. */ |
19 global_var = 0; | 21 global_var = 0; |
20 } | 22 } |
(...skipping 12 matching lines...) Expand all Loading... |
33 } | 35 } |
34 | 36 |
35 int test_print_symbol() { | 37 int test_print_symbol() { |
36 int local_var = 3; | 38 int local_var = 3; |
37 global_var = 2 + local_var * 0; /* Use local variable to prevent warning. */ | 39 global_var = 2 + local_var * 0; /* Use local variable to prevent warning. */ |
38 set_global_var(1); | 40 set_global_var(1); |
39 nested_calls(1); | 41 nested_calls(1); |
40 return global_var; | 42 return global_var; |
41 } | 43 } |
42 | 44 |
| 45 /* A function with non-trivial prolog. */ |
| 46 void test_step_from_function_start(int arg) { |
| 47 int local_var = arg - 1; |
| 48 global_var = local_var; |
| 49 /* |
| 50 * Force using frame pointer for this function by calling alloca. |
| 51 * This allows to test skipping %esp modifying instructions when they |
| 52 * are located in the middle of the function. |
| 53 */ |
| 54 global_ptr = alloca(arg); |
| 55 } |
| 56 |
43 int main(int argc, char **argv) { | 57 int main(int argc, char **argv) { |
44 assert(argc >= 2); | 58 assert(argc >= 2); |
45 | 59 |
46 if (strcmp(argv[1], "break_inside_function") == 0) { | 60 if (strcmp(argv[1], "break_inside_function") == 0) { |
47 test_two_line_function(1); | 61 test_two_line_function(1); |
48 return 0; | 62 return 0; |
49 } | 63 } |
50 if (strcmp(argv[1], "stepi_after_break") == 0) { | 64 if (strcmp(argv[1], "stepi_after_break") == 0) { |
51 test_stepi_after_break(); | 65 test_stepi_after_break(); |
52 return 0; | 66 return 0; |
53 } | 67 } |
54 if (strcmp(argv[1], "print_symbol") == 0) { | 68 if (strcmp(argv[1], "print_symbol") == 0) { |
55 return test_print_symbol(); | 69 return test_print_symbol(); |
56 } | 70 } |
57 if (strcmp(argv[1], "stack_trace") == 0) { | 71 if (strcmp(argv[1], "stack_trace") == 0) { |
58 nested_calls(1); | 72 nested_calls(1); |
59 return 0; | 73 return 0; |
60 } | 74 } |
| 75 if (strcmp(argv[1], "step_from_func_start") == 0) { |
| 76 global_var = 0; |
| 77 test_step_from_function_start(2); |
| 78 return 0; |
| 79 } |
61 return 1; | 80 return 1; |
62 } | 81 } |
OLD | NEW |