#include <bundle_internal.h>
#include <dlfcn.h>
#include <errno.h>
+#include <execinfo.h>
#include <gio/gio.h>
#include <glib.h>
#include <libintl.h>
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<void**>(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<void**>(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,