skipFrames/skip = 2: drop the capture function and the tracker hook so the visible top frame is the caller (operator new wrapper, etc).
| 158 | // skipFrames/skip = 2: drop the capture function and the tracker hook so the |
| 159 | // visible top frame is the caller (operator new wrapper, etc). |
| 160 | static int capture_stack(void **frames, int max_frames) noexcept { |
| 161 | #if defined(_MSC_VER) && defined(_M_X64) |
| 162 | return (int)das_fast_stack_capture(frames, (unsigned)max_frames, 2); |
| 163 | #elif defined(_MSC_VER) |
| 164 | return (int)CaptureStackBackTrace(1, (DWORD)max_frames, frames, nullptr); |
| 165 | #elif defined(__linux__) || defined(__APPLE__) |
| 166 | void * raw[64]; |
| 167 | int n = max_frames + 2 > 64 ? 64 : max_frames + 2; |
| 168 | int got = backtrace(raw, n); |
| 169 | int skip = got > 2 ? 2 : got; |
| 170 | int out = got - skip; |
| 171 | if (out > max_frames) out = max_frames; |
| 172 | for (int i = 0; i < out; ++i) frames[i] = raw[skip + i]; |
| 173 | return out; |
| 174 | #else |
| 175 | (void)frames; (void)max_frames; |
| 176 | return 0; |
| 177 | #endif |
| 178 | } |
| 179 | |
| 180 | // noinline so the skipFrames count above reliably drops this frame. |
| 181 | #if defined(_MSC_VER) |
no test coverage detected