MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / capture_stack

Function capture_stack

src/misc/alloc_tracker.cpp:160–178  ·  view source on GitHub ↗

skipFrames/skip = 2: drop the capture function and the tracker hook so the visible top frame is the caller (operator new wrapper, etc).

Source from the content-addressed store, hash-verified

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).
160static 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)

Callers 1

track_alloc_hookFunction · 0.85

Calls 1

das_fast_stack_captureFunction · 0.85

Tested by

no test coverage detected