1 | #include <algorithm> |
---|---|
2 | #include <cstdio> |
3 | #include <string> |
4 | |
5 | inline int inline_ref_1 (int &value) __attribute__((always_inline)); |
6 | inline int inline_ref_2 (int &value) __attribute__((always_inline)); |
7 | |
8 | int caller_ref_1 (int &value); |
9 | int caller_ref_2 (int &value); |
10 | |
11 | int called_by_inline_ref (int &value); |
12 | |
13 | inline void inline_trivial_1 () __attribute__((always_inline)); |
14 | inline void inline_trivial_2 () __attribute__((always_inline)); |
15 | |
16 | void caller_trivial_1 (); |
17 | void caller_trivial_2 (); |
18 | |
19 | void called_by_inline_trivial (); |
20 | |
21 | static int inline_value; |
22 | |
23 | int |
24 | function_to_call () |
25 | { |
26 | return inline_value; |
27 | } |
28 | |
29 | int |
30 | caller_ref_1 (int &value) |
31 | { |
32 | int increment = caller_ref_2(value); // In caller_ref_1. |
33 | value += increment; // At increment in caller_ref_1. |
34 | return value; |
35 | } |
36 | |
37 | int |
38 | caller_ref_2 (int &value) |
39 | { |
40 | int increment = inline_ref_1 (value); // In caller_ref_2. |
41 | value += increment; // At increment in caller_ref_2. |
42 | return value; |
43 | } |
44 | |
45 | int |
46 | called_by_inline_ref (int &value) |
47 | { |
48 | value += 1; // In called_by_inline_ref. |
49 | return value; |
50 | } |
51 | |
52 | int |
53 | inline_ref_1 (int &value) |
54 | { |
55 | int increment = inline_ref_2(value); // In inline_ref_1. |
56 | value += increment; // At increment in inline_ref_1. |
57 | return value; |
58 | } |
59 | |
60 | int |
61 | inline_ref_2 (int &value) |
62 | { |
63 | int increment = called_by_inline_ref (value); // In inline_ref_2. |
64 | value += 1; // At increment in inline_ref_2. |
65 | return value; |
66 | } |
67 | |
68 | void |
69 | caller_trivial_1 () |
70 | { |
71 | caller_trivial_2(); // In caller_trivial_1. |
72 | inline_value += 1; |
73 | } |
74 | |
75 | void |
76 | caller_trivial_2 () |
77 | { |
78 | asm volatile ("nop"); inline_trivial_1 (); // In caller_trivial_2. |
79 | inline_value += 1; // At increment in caller_trivial_2. |
80 | } |
81 | |
82 | void |
83 | called_by_inline_trivial () |
84 | { |
85 | inline_value += 1; // In called_by_inline_trivial. |
86 | } |
87 | |
88 | void |
89 | inline_trivial_1 () |
90 | { |
91 | asm volatile ("nop"); inline_trivial_2(); // In inline_trivial_1. |
92 | inline_value += 1; // At increment in inline_trivial_1. |
93 | } |
94 | |
95 | void |
96 | inline_trivial_2 () |
97 | { |
98 | inline_value += 1; // In inline_trivial_2. |
99 | called_by_inline_trivial (); // At caller_by_inline_trivial in inline_trivial_2. |
100 | } |
101 | |
102 | template<typename T> T |
103 | max_value(const T& lhs, const T& rhs) |
104 | { |
105 | return std::max(lhs, rhs); // In max_value template |
106 | } |
107 | |
108 | template<> std::string |
109 | max_value(const std::string& lhs, const std::string& rhs) |
110 | { |
111 | return (lhs.size() > rhs.size()) ? lhs : rhs; // In max_value specialized |
112 | } |
113 | |
114 | int |
115 | main (int argc, char **argv) |
116 | { |
117 | |
118 | inline_value = 0; // Stop here and step over to set up stepping over. |
119 | |
120 | inline_trivial_1 (); // At inline_trivial_1 called from main. |
121 | |
122 | caller_trivial_1(); // At first call of caller_trivial_1 in main. |
123 | |
124 | caller_trivial_1(); // At second call of caller_trivial_1 in main. |
125 | |
126 | caller_ref_1 (value&: argc); // At first call of caller_ref_1 in main. |
127 | |
128 | caller_ref_1 (value&: argc); // At second call of caller_ref_1 in main. |
129 | |
130 | function_to_call (); // Make sure debug info for this function gets generated. |
131 | |
132 | max_value(lhs: 123, rhs: 456); // Call max_value template |
133 | max_value(lhs: std::string("abc"), rhs: std::string( "0022")); // Call max_value specialized |
134 | |
135 | return 0; // About to return from main. |
136 | } |
137 |