Use backtrace_symbols_fd() 74/293774/1
authorHwankyu Jhun <h.jhun@samsung.com>
Sat, 3 Jun 2023 10:02:48 +0000 (10:02 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Sat, 3 Jun 2023 10:02:48 +0000 (10:02 +0000)
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 <h.jhun@samsung.com>
tizen-cpp/app-core-cpp/app_core_base.cc

index 540b944264cc93b0e73497e1d177b9375e97fda1..af33a51fd4085670b24ae12dd72222d529912b28 100644 (file)
@@ -73,24 +73,9 @@ void PrintBacktrace() {
   char* buffer[BACKTRACE_BUFFER_SIZE];
   int nptrs = backtrace(reinterpret_cast<void**>(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<void**>(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<void**>(buffer), nptrs, STDERR_FILENO);
 }
 
 class ExitHandler {