From 6a43192f44333c18ec631b61e7eea4cc59e38ed6 Mon Sep 17 00:00:00 2001 From: Vadim Sadokhov Date: Thu, 16 Nov 2023 14:54:32 +0300 Subject: [PATCH] refactor script bactrace --- common/fast-backtrace.cpp | 15 +++++++++------ common/fast-backtrace.h | 1 + server/json-logger.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/fast-backtrace.cpp b/common/fast-backtrace.cpp index 2a25592891..b02b4de6d4 100644 --- a/common/fast-backtrace.cpp +++ b/common/fast-backtrace.cpp @@ -39,17 +39,20 @@ int fast_backtrace(void **buffer, int size) { stack_end = static_cast(__libc_stack_end); } #endif + return fast_backtrace_by_bp(get_bp(), stack_end, buffer, size); +} - auto *bp = static_cast(get_bp()); +int fast_backtrace_by_bp(void *bp, void *stack_end_, void **buffer, int size) { + stack_frame *current_bp = static_cast(bp); int i = 0; - while (i < size && reinterpret_cast(bp) <= stack_end && !(reinterpret_cast(bp) & (sizeof(long) - 1))) { - void *ip = bp->ip; + while (i < size && reinterpret_cast(current_bp) <= stack_end_ && !(reinterpret_cast(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; } diff --git a/common/fast-backtrace.h b/common/fast-backtrace.h index 5fb202c09c..4944b1a646 100644 --- a/common/fast-backtrace.h +++ b/common/fast-backtrace.h @@ -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; diff --git a/server/json-logger.cpp b/server/json-logger.cpp index 16f8468b38..d5e7614154 100644 --- a/server/json-logger.cpp +++ b/server/json-logger.cpp @@ -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