From: Hwankyu Jhun Date: Sat, 3 Jun 2023 10:02:48 +0000 (+0000) Subject: Use backtrace_symbols_fd() X-Git-Tag: accepted/tizen/unified/20230605.170343~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35bed848d152b7c6e2a6157d726d73402a32e865;p=platform%2Fcore%2Fappfw%2Fapp-core.git Use backtrace_symbols_fd() We used backtrace_symbols() instead of backtrace_symbols_fd() to print numbers. Unfortunately, some applications have issues related to the memory corruption. While printing the backtrace, the crash issue is occured. To avoid the crash issue, this patch changes the implementation to using the backtrace_symbols_fd() Change-Id: If01ff27df070a6be3ca77e8ac12481e651537b4e Signed-off-by: Hwankyu Jhun --- diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index 540b944..af33a51 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -73,24 +73,9 @@ void PrintBacktrace() { char* buffer[BACKTRACE_BUFFER_SIZE]; int nptrs = backtrace(reinterpret_cast(buffer), BACKTRACE_BUFFER_SIZE); - _ERR("backtrace() returned %d addresses", nptrs - 4); - - // To print numbers, we use backtrace_symbols() instead of backtrace_symbols_fd(). - // If there is an issues related to the memory, we cannot use backtrace_symbols(). - // backtrace_symbols_fd(buffer, nptrs, STDERR_FILENO); - char** strings = backtrace_symbols(reinterpret_cast(buffer), nptrs); - if (strings == nullptr) { - perror("backtrace_symbols"); - return; - } + _ERR("backtrace() returned %d addresses", nptrs); - Dl_info info; - for (int i = 4; i < nptrs; ++i) { - dladdr(buffer[i], &info); - _ERR("[%3d] %s %s", - i - 4, info.dli_sname ? info.dli_sname : "?", strings[i]); - } - free(strings); + backtrace_symbols_fd(reinterpret_cast(buffer), nptrs, STDERR_FILENO); } class ExitHandler {