From: Hwankyu Jhun Date: Tue, 10 Jan 2023 09:40:01 +0000 (+0000) Subject: Handle exit(127) X-Git-Tag: accepted/tizen/7.0/unified/20230111.174852~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63f0e5ec5d6edee4ff95f2e473a8ff21019adefe;p=platform%2Fcore%2Fappfw%2Fapp-core.git Handle exit(127) If the process is terminated with status 127, we prints the backtrace for debugging. Change-Id: Ice9f2eb47ed53a73adde1d0d7834583837677321 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 4ee310c..ad7aa52 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,49 @@ AppCoreBase* AppCoreBase::context_ = nullptr; namespace { +constexpr const int BACKTRACE_BUFFER_SIZE = 128; + +class ExitHandler { + public: + ExitHandler() { + on_exit(OnExit, this); + } + + private: + static void OnExit(int status, void *user_data) { + if (status != 127) + return; + + char* buffer[BACKTRACE_BUFFER_SIZE]; + int nptrs = backtrace(reinterpret_cast(buffer), + BACKTRACE_BUFFER_SIZE); + fprintf(stderr, "%s backtrace() returned %d addesses\n", + __FUNCTION__, nptrs); + + // 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; + } + + Dl_info info; + for (int i = 0; i < nptrs; ++i) { + dladdr(buffer[i], &info); + fprintf(stderr, "[%3d] %s %s\n", + i, info.dli_sname ? info.dli_sname : "?", strings[i]); + } + free(strings); + + fprintf(stderr, "%s(%d) abort()\n", __FUNCTION__, __LINE__); + abort(); + } +}; + +ExitHandler exit_handler; + enum TizenProfile { Unknown = 0x00, Mobile = 0x01,