Skip to content

Commit

Permalink
make backtrace in timeout's logs with recursion (VKCOM#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik authored Dec 20, 2023
1 parent 34d1b23 commit 8f335c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions common/fast-backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ int fast_backtrace(void **buffer, int size) {
stack_end = static_cast<char *>(__libc_stack_end);
}
#endif
return fast_backtrace_by_bp(get_bp(), stack_end, buffer, size);
}

auto *bp = static_cast<stack_frame *>(get_bp());
int fast_backtrace_by_bp(void *bp, void *stack_end_, void **buffer, int size) {
stack_frame *current_bp = static_cast<stack_frame *>(bp);
int i = 0;
while (i < size && reinterpret_cast<char *>(bp) <= stack_end && !(reinterpret_cast<long>(bp) & (sizeof(long) - 1))) {
void *ip = bp->ip;
while (i < size && reinterpret_cast<char *>(current_bp) <= stack_end_ && !(reinterpret_cast<long>(current_bp) & (sizeof(long) - 1))) {
void *ip = current_bp->ip;
buffer[i++] = ip;
stack_frame *p = bp->bp;
if (p <= bp) {
stack_frame *p = current_bp->bp;
if (p <= current_bp) {
break;
}
bp = p;
current_bp = p;
}
return i;
}
Expand Down
1 change: 1 addition & 0 deletions common/fast-backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern char *stack_end;
}

int fast_backtrace (void **buffer, int size) __attribute__ ((noinline));
int fast_backtrace_by_bp (void *bp, void *stack_end_, void **buffer, int size) __attribute__ ((noinline));
int fast_backtrace_without_recursions(void **buffer, int size) noexcept;
int fast_backtrace_without_recursions_by_bp(void *bp, void *stack_end_, void **buffer, int size) noexcept;

Expand Down
2 changes: 1 addition & 1 deletion server/json-logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int script_backtrace(void **buffer, int size) {
#endif
char *stack_start = PhpScript::current_script->script_stack.get_stack_ptr();
char *stack_end = stack_start + PhpScript::current_script->script_stack.get_stack_size();
return fast_backtrace_without_recursions_by_bp(rbp, stack_end, buffer, size);
return fast_backtrace_by_bp(rbp, stack_end, buffer, size);
}

} // namespace
Expand Down

0 comments on commit 8f335c7

Please sign in to comment.