| ... | ... | @@ -360,14 +360,24 @@ pub const StackIterator = struct { |
| 360 | 360 | }; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | | // Negative offset of the saved BP wrt the frame pointer. |
| 363 | // Offset of the saved BP wrt the frame pointer. |
| 364 | 364 | const fp_offset = if (builtin.arch.isRISCV()) |
| 365 | 365 | // On RISC-V the frame pointer points to the top of the saved register |
| 366 | 366 | // area, on pretty much every other architecture it points to the stack |
| 367 | 367 | // slot where the previous frame pointer is saved. |
| 368 | 368 | 2 * @sizeOf(usize) |
| 369 | else if (builtin.arch.isSPARC()) |
| 370 | // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS. |
| 371 | 14 * @sizeOf(usize) |
| 369 | 372 | else |
| 370 | 373 | 0; |
| 374 | |
| 375 | const fp_bias = if (builtin.arch.isSPARC()) |
| 376 | // On SPARC frame pointers are biased by a constant. |
| 377 | 2047 |
| 378 | else |
| 379 | 0; |
| 380 | |
| 371 | 381 | // Positive offset of the saved PC wrt the frame pointer. |
| 372 | 382 | const pc_offset = if (builtin.arch == .powerpc64le) |
| 373 | 383 | 2 * @sizeOf(usize) |
| ... | ... | @@ -388,13 +398,17 @@ pub const StackIterator = struct { |
| 388 | 398 | } |
| 389 | 399 | |
| 390 | 400 | fn next_internal(self: *StackIterator) ?usize { |
| 391 | | const fp = math.sub(usize, self.fp, fp_offset) catch return null; |
| 401 | const fp = if (builtin.arch.isSPARC()) |
| 402 | // On SPARC the offset is positive. (!) |
| 403 | math.add(usize, self.fp, fp_offset) catch return null |
| 404 | else |
| 405 | math.sub(usize, self.fp, fp_offset) catch return null; |
| 392 | 406 | |
| 393 | 407 | // Sanity check. |
| 394 | 408 | if (fp == 0 or !mem.isAligned(fp, @alignOf(usize))) |
| 395 | 409 | return null; |
| 396 | 410 | |
| 397 | | const new_fp = @intToPtr(*const usize, fp).*; |
| 411 | const new_fp = math.add(usize, @intToPtr(*const usize, fp).*, fp_bias) catch return null; |
| 398 | 412 | |
| 399 | 413 | // Sanity check: the stack grows down thus all the parent frames must be |
| 400 | 414 | // be at addresses that are greater (or equal) than the previous one. |