Skip to content

Commit 09b458b

Browse files
committed
Fix skips
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 1588be9 commit 09b458b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/memray/_memray/ghost_stack/src/ghost_stack.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class GhostStackImpl {
251251
size_t count = (available < max_frames) ? available : max_frames;
252252

253253
for (size_t i = 0; i < count; ++i) {
254-
buffer[i] = reinterpret_cast<void*>(entries_[i].ip);
254+
buffer[i] = reinterpret_cast<void*>(entries_[count - 1 - i].ip);
255255
}
256256

257257
LOG_DEBUG("Fast path: %zu frames\n", count);
@@ -278,15 +278,6 @@ class GhostStackImpl {
278278
unw_getcontext(&ctx);
279279
unw_init_local(&cursor, &ctx);
280280

281-
// Skip internal frames (platform-specific due to backtrace/libunwind differences)
282-
#ifdef __APPLE__
283-
// macOS: Skip fewer frames due to backtrace()/libunwind difference
284-
for (int i = 0; i < 1 && unw_step(&cursor) > 0; ++i) {}
285-
#else
286-
// Linux: Skip internal frames (this function + backtrace)
287-
for (int i = 0; i < 3 && unw_step(&cursor) > 0; ++i) {}
288-
#endif
289-
290281
// Process frames: read current frame, then step to next
291282
// Note: After skip loop, cursor is positioned AT the first frame we want
292283
// We need to read first, then step (not step-then-read)

src/memray/_memray/tracking_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
#ifdef MEMRAY_HAS_GHOST_STACK
2929
# include "ghost_stack.h"
30+
#if defined(__linux__)
31+
# define GHOST_STACK_SKIP_FRAMES 2
32+
#elif defined(__APPLE__)
33+
# define GHOST_STACK_SKIP_FRAMES 1
34+
#endif
3035
#endif
3136

3237
#include "frame_tree.h"
@@ -197,7 +202,11 @@ class NativeTrace
197202
d_data.resize(d_data.size() * 2);
198203
}
199204
d_size = size > skip ? size - skip : 0;
205+
#ifdef MEMRAY_HAS_GHOST_STACK
206+
d_skip = skip + (s_use_fast_unwind ? GHOST_STACK_SKIP_FRAMES : 0);
207+
#else
200208
d_skip = skip;
209+
#endif
201210
return d_size > 0;
202211
}
203212

0 commit comments

Comments
 (0)