stack does the real work for Stack. This lets stack's body handle m == nil and potentially be inlined.
(w Writer)
| 439 | // stack does the real work for Stack. |
| 440 | // This lets stack's body handle m == nil and potentially be inlined. |
| 441 | func (m *Matcher) stack(w Writer) bool { |
| 442 | const maxStack = 16 |
| 443 | var stk [maxStack]uintptr |
| 444 | n := runtime.Callers(2, stk[:]) |
| 445 | // caller #2 is not for printing; need it to normalize PCs if ASLR. |
| 446 | if n <= 1 { |
| 447 | return false |
| 448 | } |
| 449 | |
| 450 | base := stk[0] |
| 451 | // normalize PCs |
| 452 | for i := range stk[:n] { |
| 453 | stk[i] -= base |
| 454 | } |
| 455 | |
| 456 | h := Hash(stk[:n]) |
| 457 | if m.ShouldPrint(h) { |
| 458 | var d *dedup |
| 459 | for { |
| 460 | d = m.dedup.Load() |
| 461 | if d != nil { |
| 462 | break |
| 463 | } |
| 464 | d = new(dedup) |
| 465 | if m.dedup.CompareAndSwap(nil, d) { |
| 466 | break |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | if m.MarkerOnly() { |
| 471 | if !d.seenLossy(h) { |
| 472 | PrintMarker(w, h) |
| 473 | } |
| 474 | } else { |
| 475 | if !d.seen(h) { |
| 476 | // Restore PCs in stack for printing |
| 477 | for i := range stk[:n] { |
| 478 | stk[i] += base |
| 479 | } |
| 480 | printStack(w, h, stk[1:n]) |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | return m.ShouldEnable(h) |
| 485 | } |
| 486 | |
| 487 | // Writer is the same interface as io.Writer. |
| 488 | // It is duplicated here to avoid importing io. |
no test coverage detected