This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stacktraverse.c
282 lines (275 loc) · 12.7 KB
/
stacktraverse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#define _GNU_SOURCE
#include <stddef.h>
#include "stacktraverse.h"
void *
getreturnaddr(int level)
{
switch(level) {
case 0: return __builtin_return_address(1);
case 1: return __builtin_return_address(2);
case 2: return __builtin_return_address(3);
case 3: return __builtin_return_address(4);
case 4: return __builtin_return_address(5);
case 5: return __builtin_return_address(6);
case 6: return __builtin_return_address(7);
case 7: return __builtin_return_address(8);
case 8: return __builtin_return_address(9);
case 9: return __builtin_return_address(10);
case 10: return __builtin_return_address(11);
case 11: return __builtin_return_address(12);
case 12: return __builtin_return_address(13);
case 13: return __builtin_return_address(14);
case 14: return __builtin_return_address(15);
case 15: return __builtin_return_address(16);
case 16: return __builtin_return_address(17);
case 17: return __builtin_return_address(18);
case 18: return __builtin_return_address(19);
case 19: return __builtin_return_address(20);
case 20: return __builtin_return_address(21);
case 21: return __builtin_return_address(22);
case 22: return __builtin_return_address(23);
case 23: return __builtin_return_address(24);
case 24: return __builtin_return_address(25);
case 25: return __builtin_return_address(26);
case 26: return __builtin_return_address(27);
case 27: return __builtin_return_address(28);
case 28: return __builtin_return_address(29);
case 29: return __builtin_return_address(30);
case 30: return __builtin_return_address(31);
case 31: return __builtin_return_address(32);
case 32: return __builtin_return_address(33);
case 33: return __builtin_return_address(34);
case 34: return __builtin_return_address(35);
case 35: return __builtin_return_address(36);
case 36: return __builtin_return_address(37);
case 37: return __builtin_return_address(38);
case 38: return __builtin_return_address(39);
case 39: return __builtin_return_address(40);
case 40: return __builtin_return_address(41);
case 41: return __builtin_return_address(42);
case 42: return __builtin_return_address(43);
case 43: return __builtin_return_address(44);
case 44: return __builtin_return_address(45);
case 45: return __builtin_return_address(46);
case 46: return __builtin_return_address(47);
case 47: return __builtin_return_address(48);
case 48: return __builtin_return_address(49);
case 49: return __builtin_return_address(50);
case 50: return __builtin_return_address(51);
case 51: return __builtin_return_address(52);
case 52: return __builtin_return_address(53);
case 53: return __builtin_return_address(54);
case 54: return __builtin_return_address(55);
case 55: return __builtin_return_address(56);
case 56: return __builtin_return_address(57);
case 57: return __builtin_return_address(58);
case 58: return __builtin_return_address(59);
case 59: return __builtin_return_address(60);
case 60: return __builtin_return_address(61);
case 61: return __builtin_return_address(62);
case 62: return __builtin_return_address(63);
case 63: return __builtin_return_address(64);
case 64: return __builtin_return_address(65);
case 65: return __builtin_return_address(66);
case 66: return __builtin_return_address(67);
case 67: return __builtin_return_address(68);
case 68: return __builtin_return_address(69);
case 69: return __builtin_return_address(70);
case 70: return __builtin_return_address(71);
case 71: return __builtin_return_address(72);
case 72: return __builtin_return_address(73);
case 73: return __builtin_return_address(74);
case 74: return __builtin_return_address(75);
case 75: return __builtin_return_address(76);
case 76: return __builtin_return_address(77);
case 77: return __builtin_return_address(78);
case 78: return __builtin_return_address(79);
case 79: return __builtin_return_address(80);
case 80: return __builtin_return_address(81);
case 81: return __builtin_return_address(82);
case 82: return __builtin_return_address(83);
case 83: return __builtin_return_address(84);
case 84: return __builtin_return_address(85);
case 85: return __builtin_return_address(86);
case 86: return __builtin_return_address(87);
case 87: return __builtin_return_address(88);
case 88: return __builtin_return_address(89);
case 89: return __builtin_return_address(90);
case 90: return __builtin_return_address(91);
case 91: return __builtin_return_address(92);
case 92: return __builtin_return_address(93);
case 93: return __builtin_return_address(94);
case 94: return __builtin_return_address(95);
case 95: return __builtin_return_address(96);
case 96: return __builtin_return_address(97);
case 97: return __builtin_return_address(98);
case 98: return __builtin_return_address(99);
case 99: return __builtin_return_address(100);
case 100: return __builtin_return_address(101);
case 101: return __builtin_return_address(102);
case 102: return __builtin_return_address(103);
case 103: return __builtin_return_address(104);
case 104: return __builtin_return_address(105);
case 105: return __builtin_return_address(106);
case 106: return __builtin_return_address(107);
case 107: return __builtin_return_address(108);
case 108: return __builtin_return_address(109);
case 109: return __builtin_return_address(110);
case 110: return __builtin_return_address(111);
case 111: return __builtin_return_address(112);
case 112: return __builtin_return_address(113);
case 113: return __builtin_return_address(114);
case 114: return __builtin_return_address(115);
case 115: return __builtin_return_address(116);
case 116: return __builtin_return_address(117);
case 117: return __builtin_return_address(118);
case 118: return __builtin_return_address(119);
case 119: return __builtin_return_address(120);
case 120: return __builtin_return_address(121);
case 121: return __builtin_return_address(122);
case 122: return __builtin_return_address(123);
case 123: return __builtin_return_address(124);
case 124: return __builtin_return_address(125);
case 125: return __builtin_return_address(126);
case 126: return __builtin_return_address(127);
case 127: return __builtin_return_address(128);
default: return NULL;
}
}
#include <stddef.h>
#include "stacktraverse.h"
void *
getframeaddr(int level)
{
switch(level) {
case 0: return __builtin_frame_address(1);
case 1: return __builtin_frame_address(2);
case 2: return __builtin_frame_address(3);
case 3: return __builtin_frame_address(4);
case 4: return __builtin_frame_address(5);
case 5: return __builtin_frame_address(6);
case 6: return __builtin_frame_address(7);
case 7: return __builtin_frame_address(8);
case 8: return __builtin_frame_address(9);
case 9: return __builtin_frame_address(10);
case 10: return __builtin_frame_address(11);
case 11: return __builtin_frame_address(12);
case 12: return __builtin_frame_address(13);
case 13: return __builtin_frame_address(14);
case 14: return __builtin_frame_address(15);
case 15: return __builtin_frame_address(16);
case 16: return __builtin_frame_address(17);
case 17: return __builtin_frame_address(18);
case 18: return __builtin_frame_address(19);
case 19: return __builtin_frame_address(20);
case 20: return __builtin_frame_address(21);
case 21: return __builtin_frame_address(22);
case 22: return __builtin_frame_address(23);
case 23: return __builtin_frame_address(24);
case 24: return __builtin_frame_address(25);
case 25: return __builtin_frame_address(26);
case 26: return __builtin_frame_address(27);
case 27: return __builtin_frame_address(28);
case 28: return __builtin_frame_address(29);
case 29: return __builtin_frame_address(30);
case 30: return __builtin_frame_address(31);
case 31: return __builtin_frame_address(32);
case 32: return __builtin_frame_address(33);
case 33: return __builtin_frame_address(34);
case 34: return __builtin_frame_address(35);
case 35: return __builtin_frame_address(36);
case 36: return __builtin_frame_address(37);
case 37: return __builtin_frame_address(38);
case 38: return __builtin_frame_address(39);
case 39: return __builtin_frame_address(40);
case 40: return __builtin_frame_address(41);
case 41: return __builtin_frame_address(42);
case 42: return __builtin_frame_address(43);
case 43: return __builtin_frame_address(44);
case 44: return __builtin_frame_address(45);
case 45: return __builtin_frame_address(46);
case 46: return __builtin_frame_address(47);
case 47: return __builtin_frame_address(48);
case 48: return __builtin_frame_address(49);
case 49: return __builtin_frame_address(50);
case 50: return __builtin_frame_address(51);
case 51: return __builtin_frame_address(52);
case 52: return __builtin_frame_address(53);
case 53: return __builtin_frame_address(54);
case 54: return __builtin_frame_address(55);
case 55: return __builtin_frame_address(56);
case 56: return __builtin_frame_address(57);
case 57: return __builtin_frame_address(58);
case 58: return __builtin_frame_address(59);
case 59: return __builtin_frame_address(60);
case 60: return __builtin_frame_address(61);
case 61: return __builtin_frame_address(62);
case 62: return __builtin_frame_address(63);
case 63: return __builtin_frame_address(64);
case 64: return __builtin_frame_address(65);
case 65: return __builtin_frame_address(66);
case 66: return __builtin_frame_address(67);
case 67: return __builtin_frame_address(68);
case 68: return __builtin_frame_address(69);
case 69: return __builtin_frame_address(70);
case 70: return __builtin_frame_address(71);
case 71: return __builtin_frame_address(72);
case 72: return __builtin_frame_address(73);
case 73: return __builtin_frame_address(74);
case 74: return __builtin_frame_address(75);
case 75: return __builtin_frame_address(76);
case 76: return __builtin_frame_address(77);
case 77: return __builtin_frame_address(78);
case 78: return __builtin_frame_address(79);
case 79: return __builtin_frame_address(80);
case 80: return __builtin_frame_address(81);
case 81: return __builtin_frame_address(82);
case 82: return __builtin_frame_address(83);
case 83: return __builtin_frame_address(84);
case 84: return __builtin_frame_address(85);
case 85: return __builtin_frame_address(86);
case 86: return __builtin_frame_address(87);
case 87: return __builtin_frame_address(88);
case 88: return __builtin_frame_address(89);
case 89: return __builtin_frame_address(90);
case 90: return __builtin_frame_address(91);
case 91: return __builtin_frame_address(92);
case 92: return __builtin_frame_address(93);
case 93: return __builtin_frame_address(94);
case 94: return __builtin_frame_address(95);
case 95: return __builtin_frame_address(96);
case 96: return __builtin_frame_address(97);
case 97: return __builtin_frame_address(98);
case 98: return __builtin_frame_address(99);
case 99: return __builtin_frame_address(100);
case 100: return __builtin_frame_address(101);
case 101: return __builtin_frame_address(102);
case 102: return __builtin_frame_address(103);
case 103: return __builtin_frame_address(104);
case 104: return __builtin_frame_address(105);
case 105: return __builtin_frame_address(106);
case 106: return __builtin_frame_address(107);
case 107: return __builtin_frame_address(108);
case 108: return __builtin_frame_address(109);
case 109: return __builtin_frame_address(110);
case 110: return __builtin_frame_address(111);
case 111: return __builtin_frame_address(112);
case 112: return __builtin_frame_address(113);
case 113: return __builtin_frame_address(114);
case 114: return __builtin_frame_address(115);
case 115: return __builtin_frame_address(116);
case 116: return __builtin_frame_address(117);
case 117: return __builtin_frame_address(118);
case 118: return __builtin_frame_address(119);
case 119: return __builtin_frame_address(120);
case 120: return __builtin_frame_address(121);
case 121: return __builtin_frame_address(122);
case 122: return __builtin_frame_address(123);
case 123: return __builtin_frame_address(124);
case 124: return __builtin_frame_address(125);
case 125: return __builtin_frame_address(126);
case 126: return __builtin_frame_address(127);
case 127: return __builtin_frame_address(128);
default: return NULL;
}
}