From: SeokYeon Hwang Date: Sat, 1 Aug 2015 08:02:37 +0000 (+0900) Subject: emulator: cleaned common codes up X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~40^2~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=527a2944fa5950860f2845c79308b925120ba520;p=sdk%2Femulator%2Fqemu.git emulator: cleaned common codes up Change-Id: Ia6b6ba6094233d743ab15f6d2257e14f489e31d0 Signed-off-by: SeokYeon Hwang --- diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index ab70685f39..67d4ae7478 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -121,13 +121,19 @@ static void emulator_notify_exit(Notifier *notifier, void *data) LOG_INFO("Exit emulator...\n"); - maru_atexit(); + handle_error_at_exit(); } static Notifier emulator_exit = { .notify = emulator_notify_exit }; -static void print_system_info(void) +void print_system_info(void) { + static bool is_printed = false; + + if (is_printed) { + return; + } + LOG_INFO("* Board name : %s\n", build_version); LOG_INFO("* Package %s\n", pkginfo_version); LOG_INFO("* Package %s\n", pkginfo_maintainer); @@ -158,6 +164,8 @@ static void print_system_info(void) #endif print_system_info_os(); + + is_printed = true; } static void set_qemu_input_mode(void) @@ -201,11 +209,15 @@ static void print_options_info(void) const char *prepare_maru(const char * const kernel_cmdline) { emulator_add_exit_notifier(&emulator_exit); - socket_init(); print_system_info(); - set_base_port(); - // assemble new kernel cmdline + // We should call socket_init() here since this function called + // before calling socket_init() in "vl.c". + // It is safe to call socket_init() multiple times. + socket_init(); + init_vm_base_port(); + + // Assemble new kernel cmdline maru_kernel_cmdline = g_strdup_printf("%s sdb_port=%d, " "vm_resolution=%dx%d", kernel_cmdline, get_emul_vm_base_port(), get_emul_resolution_width(), get_emul_resolution_height()); @@ -219,11 +231,11 @@ void prepare_maru_after_device_init(void) { make_vm_lock_os(); set_qemu_input_mode(); - maru_device_hotplug_init(); + init_device_hotplug(); start_ecs(); - sdb_setup(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX); + init_sdb(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX); - // only for intent logging of essential information + // Only for intent logging of essential information get_vm_name(); get_vm_data_path(); } @@ -337,7 +349,7 @@ static int emulator_main(int argc, char *argv[], char **envp) if (!assemble_emulator_args(&_qemu_argc, _qemu_argv)) { return -1; } -#if defined(CONFIG_JAVA_UI) + #if defined(CONFIG_JAVA_UI) // java skin is deprecated, it is used for only debugging... _skin_argv[_skin_argc++] = g_strdup_printf("skin.path=%s", get_emul_skin_path()); @@ -346,7 +358,7 @@ static int emulator_main(int argc, char *argv[], char **envp) _skin_argv[_skin_argc++] = g_strdup_printf("vm.path=%s/%s", get_variable("vms_path"), get_variable("vm_name")); -#endif + #endif #endif } @@ -366,44 +378,16 @@ static int emulator_main(int argc, char *argv[], char **envp) return 0; } -#if defined(CONFIG_DARWIN) && !defined(CONFIG_QT) -int g_argc; - -static void* main_thread(void* args) -{ - char** argv; - int argc = g_argc; - argv = (char**) args; - - emulator_main(argc, argv, NULL); - - thread_running = 0; - pthread_exit(NULL); -} - -int main(int argc, char *argv[]) -{ - char** args; - QemuThread main_thread_id; - g_argc = argc; - args = argv; - qemu_thread_create(&main_thread_id, "main_thread", main_thread, (void *)args, QEMU_THREAD_DETACHED); - ns_event_loop(&thread_running); - - return 0; -} -#elif defined (CONFIG_LINUX) +#if defined (CONFIG_LINUX) int main(int argc, char *argv[], char **envp) { - maru_register_exception_handler(); + register_exception_handler(); return emulator_main(argc, argv, envp); } -#else // WIN32 +#else int main(int argc, char *argv[]) { - #ifndef CONFIG_DARWIN - maru_register_exception_handler(); - #endif + register_exception_handler(); return emulator_main(argc, argv, NULL); } #endif diff --git a/tizen/src/emulator.h b/tizen/src/emulator.h index 4a62b72896..b4ff368b01 100644 --- a/tizen/src/emulator.h +++ b/tizen/src/emulator.h @@ -44,8 +44,11 @@ const char *prepare_maru(const gchar * const kernel_cmdline); void prepare_maru_after_device_init(void); -void start_skin(void); - +void print_system_info(void); void emulator_add_exit_notifier(Notifier *notify); +#if defined(CONFIG_JAVA_UI) +void start_skin(void); +#endif + #endif /* __EMULATOR_H__ */ diff --git a/tizen/src/emulator_legacy.c b/tizen/src/emulator_legacy.c index f9f7667fc9..619b24f0ea 100644 --- a/tizen/src/emulator_legacy.c +++ b/tizen/src/emulator_legacy.c @@ -89,7 +89,7 @@ char **_skin_argv; extern int _qemu_argc; extern char **_qemu_argv; -static void print_system_info(void) +static void print_system_info_legacy(void) { #define DIV 1024 @@ -294,7 +294,7 @@ int legacy_emulator_main(int argc, char * argv[], char **envp) extract_qemu_info(_qemu_argc, _qemu_argv); INFO("Emulator start !!!\n"); - atexit(maru_atexit); + atexit(handle_error_at_exit); emulator_add_exit_notifier(&emulator_exit); extract_skin_info(_skin_argc, _skin_argv); @@ -302,7 +302,7 @@ int legacy_emulator_main(int argc, char * argv[], char **envp) /* Redirect stdout and stderr after debug_ch is initialized. */ redir_output(); - print_system_info(); + print_system_info_legacy(); INFO("Prepare running...\n"); INFO("drive_image_flle: %s\n", get_drive_image_file()); diff --git a/tizen/src/util/maru_device_hotplug.c b/tizen/src/util/maru_device_hotplug.c index 6241880cc1..e22605e4a5 100644 --- a/tizen/src/util/maru_device_hotplug.c +++ b/tizen/src/util/maru_device_hotplug.c @@ -285,16 +285,16 @@ static void device_hotplug_handler(EventNotifier *e) } } -static void maru_device_hotplug_deinit(Notifier *notifier, void *data) +static void deinit_maru_device_hotplug(Notifier *notifier, void *data) { event_notifier_cleanup(&state->notifier); g_free(state); } -static Notifier maru_device_hotplug_exit = { .notify = maru_device_hotplug_deinit }; +static Notifier maru_device_hotplug_exit = { .notify = deinit_maru_device_hotplug }; -void maru_device_hotplug_init(void) +void init_device_hotplug(void) { state = g_malloc0(sizeof(struct maru_device_hotplug)); diff --git a/tizen/src/util/maru_device_hotplug.h b/tizen/src/util/maru_device_hotplug.h index 4db1bdc4b7..6001ee3b81 100644 --- a/tizen/src/util/maru_device_hotplug.h +++ b/tizen/src/util/maru_device_hotplug.h @@ -38,7 +38,7 @@ enum command { DETACH_HDS, }; -void maru_device_hotplug_init(void); +void init_device_hotplug(void); void do_hotplug(int command, void *opaque, size_t size); diff --git a/tizen/src/util/maru_err_table.c b/tizen/src/util/maru_err_table.c index 18b80027f5..fc5edc5f1f 100644 --- a/tizen/src/util/maru_err_table.c +++ b/tizen/src/util/maru_err_table.c @@ -28,24 +28,26 @@ * */ -#include "qemu-common.h" -#include "emulator_common.h" -#include "maru_err_table.h" -#include "debug_ch.h" - #include #include #include #include - #ifdef CONFIG_WIN32 #include #else #include #endif +#include "qemu-common.h" + +#include "emulator_common.h" +#include "emulator.h" +#include "maru_err_table.h" + +#include "debug_ch.h" MULTI_DEBUG_CHANNEL(qemu, backtrace); + /* This table must match the enum definition */ static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = { /* 0 */ "", @@ -132,19 +134,6 @@ void maru_register_exit_msg(int maru_exit_index, char const *format, ...) maru_exit_status, maru_exit_msg); } -void maru_atexit(void) -{ - - if (maru_exit_status != MARU_EXIT_NORMAL || maru_exit_msg) { - start_simple_client(maru_exit_msg); - } - g_free(maru_exit_msg); - - INFO("normal exit called\n"); - // dump backtrace log no matter what - maru_dump_backtrace(NULL, 0); -} - /* Print 'backtrace' */ #ifdef _WIN32 struct frame_layout { @@ -180,7 +169,7 @@ static HMODULE aqua_get_module_handle(DWORD dwAddress) } #endif -void maru_dump_backtrace(void *ptr, int depth) +static void dump_backtrace(void *ptr, int depth) { #ifdef _WIN32 int nCount; @@ -258,9 +247,27 @@ void maru_dump_backtrace(void *ptr, int depth) #endif } +void handle_error_at_exit(void) +{ + + if (maru_exit_status != MARU_EXIT_NORMAL || maru_exit_msg) { + start_simple_client(maru_exit_msg); + } + g_free(maru_exit_msg); + + // dump backtrace log no matter what + INFO("This is not a error.\n"); + INFO("Stack backtrace for tracing...\n"); + dump_backtrace(NULL, 0); +} + #ifdef CONFIG_WIN32 static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExceptionInfo){ char module_buf[1024]; + + // print system information again + print_system_info(); + DWORD dwException = pExceptionInfo->ExceptionRecord->ExceptionCode; ERR("%d\n ", (int)dwException); @@ -285,7 +292,7 @@ static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExcepti ); pContext = pExceptionInfo->ContextRecord; - maru_dump_backtrace(pContext, 0); + dump_backtrace(pContext, 0); _exit(0); //return EXCEPTION_CONTINUE_SEARCH; } @@ -294,9 +301,12 @@ static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExcepti #ifdef CONFIG_LINUX void maru_sighandler(int sig) { + // print system information again + print_system_info(); + pthread_spin_lock(&siglock); ERR("Got signal %d\n", sig); - maru_dump_backtrace(NULL, 0); + dump_backtrace(NULL, 0); pthread_spin_unlock(&siglock); _exit(0); } @@ -304,11 +314,11 @@ void maru_sighandler(int sig) #ifndef CONFIG_DARWIN -void maru_register_exception_handler(void) +void register_exception_handler(void) { -#ifdef CONFIG_WIN32 + #ifdef CONFIG_WIN32 prevExceptionFilter = SetUnhandledExceptionFilter(maru_unhandled_exception_filter); -#else // LINUX + #else // LINUX void *trace[1]; struct sigaction sa; @@ -327,6 +337,11 @@ void maru_register_exception_handler(void) // main thread only sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); -#endif + #endif +} +#else // CONFIG_DARWIN +void register_exception_handler(void) +{ + // TODO: Exception handling on darwin } #endif diff --git a/tizen/src/util/maru_err_table.h b/tizen/src/util/maru_err_table.h index f27dc91013..f7f8b81072 100644 --- a/tizen/src/util/maru_err_table.h +++ b/tizen/src/util/maru_err_table.h @@ -50,9 +50,7 @@ enum { char *get_canonical_path(char const *const path); void maru_register_exit_msg(int maru_exit_status, char const *format, ...); -void maru_atexit(void); +void register_exception_handler(void); +void handle_error_at_exit(void); -void maru_dump_backtrace(void *ptr, int depth); - -void maru_register_exception_handler(void); #endif /* __EMUL_ERR_TABLE_H__ */ diff --git a/tizen/src/util/sdb.c b/tizen/src/util/sdb.c index 1b4a70bfc8..f9f5f7066b 100644 --- a/tizen/src/util/sdb.c +++ b/tizen/src/util/sdb.c @@ -164,7 +164,7 @@ int check_port_bind_listen(uint32_t port) #define ECS_INDEX 3 #define SDB_GUEST_PORT 26101 #define GDB_GUEST_PORT 26102 -void set_base_port(void) +void init_vm_base_port(void) { int tries = 10; int success = 0; @@ -196,7 +196,7 @@ void set_base_port(void) } static void start_sdb_noti_server(int server_port); -void sdb_setup(int server_port) +void init_sdb(int server_port) { start_sdb_noti_server(server_port); diff --git a/tizen/src/util/sdb.h b/tizen/src/util/sdb.h index 49cbcb0cf1..cadb6ee657 100644 --- a/tizen/src/util/sdb.h +++ b/tizen/src/util/sdb.h @@ -52,8 +52,8 @@ #define SDB_TCP_OPENGL_INDEX 3 /* opengl server port */ #define SDB_UDP_SENSOR_INDEX 3 /* sensor server port */ -void sdb_setup(int server_port); -void set_base_port(void); +void init_sdb(int server_port); +void init_vm_base_port(void); int inet_strtoip(const char* str, uint32_t *ip); int socket_send(int fd, const void* buf, int buflen); void socket_close(int fd); diff --git a/vl.c b/vl.c index 62f118f82f..e8891c920e 100644 --- a/vl.c +++ b/vl.c @@ -4231,9 +4231,7 @@ int main(int argc, char **argv, char **envp) } #endif -#ifndef CONFIG_MARU socket_init(); -#endif if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) exit(1);