From 8e547ca36a210df0f8c6224e97333751b1526fa7 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Sat, 1 Aug 2015 21:13:43 +0900 Subject: [PATCH] emulator: introduced new error report architecture User can see all errors reported by error_report(). Removed most emulator specified codes. Renamed some source files. Removed redudant header includes. Change-Id: I61f92f4e32763eaa1e3ed20c77259dd8b034d497 Signed-off-by: SeokYeon Hwang --- accel.c | 12 +-- blockdev.c | 12 +-- hw/9pfs/virtio-9p-device.c | 23 ----- hw/i386/pc.c | 13 +-- hw/i386/pc_sysfw.c | 11 +-- include/qemu/error-report.h | 14 ++++ tizen/src/display/maru_shm.c | 9 +- tizen/src/ecs/ecs_msg_device.c | 2 +- tizen/src/ecs/ecs_msg_injector.c | 2 +- tizen/src/ecs/ecs_sdcard.c | 2 +- tizen/src/emulator.c | 15 ++-- tizen/src/emulator_legacy.c | 3 +- tizen/src/skin/maruskin_client.c | 6 +- tizen/src/skin/maruskin_client.h | 2 +- tizen/src/skin/maruskin_operation.c | 2 +- tizen/src/skin/maruskin_server.c | 4 +- tizen/src/util/Makefile.objs | 6 +- ...maru_device_hotplug.c => device_hotplug.c} | 2 +- ...maru_device_hotplug.h => device_hotplug.h} | 0 .../{maru_err_table.c => error_handler.c} | 83 +++++++++++++------ .../{maru_err_table.h => error_handler.h} | 20 ++--- ...maru_util_strings.h => exported_strings.h} | 2 +- tizen/src/util/osutil-darwin.c | 1 - tizen/src/util/osutil-linux.c | 30 +++---- tizen/src/util/osutil-win32.c | 5 +- util/qemu-error.c | 23 +++++ vl.c | 10 +-- 27 files changed, 163 insertions(+), 151 deletions(-) rename tizen/src/util/{maru_device_hotplug.c => device_hotplug.c} (99%) rename tizen/src/util/{maru_device_hotplug.h => device_hotplug.h} (100%) rename tizen/src/util/{maru_err_table.c => error_handler.c} (82%) rename tizen/src/util/{maru_err_table.h => error_handler.h} (78%) rename tizen/src/util/{maru_util_strings.h => exported_strings.h} (95%) diff --git a/accel.c b/accel.c index 63e15f8e01..f384c697a8 100644 --- a/accel.c +++ b/accel.c @@ -34,10 +34,7 @@ #include "qom/object.h" #include "hw/boards.h" #include "sysemu/hax.h" - -#ifdef CONFIG_MARU -#include "tizen/src/util/maru_err_table.h" -#endif +#include "qemu/error-report.h" int tcg_tb_size; static bool tcg_allowed = true; @@ -124,11 +121,10 @@ int configure_accelerator(MachineState *ms) if (!accel_initialised) { if (!init_failed) { - fprintf(stderr, "No accelerator found!\n"); +// CONFIG_MARU MODIFICATION +// fprintf(stderr, "No accelerator found!\n"); + error_report("No accelerator found!\n"); } -#ifdef CONFIG_MARU - maru_register_exit_msg(MARU_EXIT_UNKNOWN, NO_ACCELERATOR_FOUND); -#endif exit(1); } diff --git a/blockdev.c b/blockdev.c index db8c7acd65..f4b83015fc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -48,7 +48,7 @@ #include "sysemu/arch_init.h" #ifdef CONFIG_MARU -#include "tizen/src/util/maru_err_table.h" +#include "tizen/src/util/exported_strings.h" #endif static const char *const if_name[IF_COUNT] = { @@ -556,16 +556,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, assert(bs == blk_bs(blk)); if (ret < 0) { -#ifdef CONFIG_MARU - char *path = get_canonical_path(file); - char *msg = g_strdup_printf("%s%s%s", FAILED_TO_LOAD_DISK, CHECK_FILE_VALID, path); - - start_simple_client(msg); - - g_free(path); - g_free(msg); -#endif - error_setg(errp, "could not open disk image %s: %s", file ?: blk_name(blk), error_get_pretty(error)); error_free(error); diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 99cddf1e5f..abb190b209 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -21,10 +21,6 @@ #include "virtio-9p-coth.h" #include "hw/virtio/virtio-access.h" -#ifdef CONFIG_MARU -#include "tizen/src/util/maru_err_table.h" -#endif - static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features) { features |= 1 << VIRTIO_9P_MOUNT_TAG; @@ -107,13 +103,6 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp) if (s->ops->init(&s->ctx) < 0) { error_setg(errp, "Virtio-9p Failed to initialize fs-driver with id:%s" " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root); -#ifdef CONFIG_MARU - gchar *canonical_path = get_canonical_path(s->ctx.fs_root); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "Virtio-9p Failed to initialize fs-driver with id: %s" - " and export path: %s", s->fsconf.fsdev_id, canonical_path); - g_free(canonical_path); -#endif goto out; } if (v9fs_init_worker_threads() < 0) { @@ -141,21 +130,9 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp) } if (s->ops->lstat(&s->ctx, &path, &stat)) { error_setg(errp, "share path %s does not exist", fse->path); -#ifdef CONFIG_MARU - gchar *canonical_path = get_canonical_path(fse->path); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "share path %s does not exist", canonical_path); - g_free(canonical_path); -#endif goto out; } else if (!S_ISDIR(stat.st_mode)) { error_setg(errp, "share path %s is not a directory", fse->path); -#ifdef CONFIG_MARU - gchar *canonical_path = get_canonical_path(fse->path); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "share path %s is not a directory", canonical_path); - g_free(canonical_path); -#endif goto out; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 6e83a17d30..eb57d6f055 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -63,9 +63,6 @@ #include "qapi/visitor.h" #include "qapi-visit.h" -#ifdef CONFIG_MARU -#include "tizen/src/util/maru_err_table.h" -#endif /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -756,15 +753,13 @@ static void load_linux(FWCfgState *fw_cfg, if (!f || !(kernel_size = get_file_size(f)) || fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != MIN(ARRAY_SIZE(header), kernel_size)) { - fprintf(stderr, "qemu: could not load kernel '%s': %s\n", +// CONFIG_MARU MODIFICATION +// fprintf(stderr, "qemu: could not load kernel '%s': %s\n", +// kernel_filename, strerror(errno)); + error_report("qemu: could not load kernel '%s': %s\n", kernel_filename, strerror(errno)); -#ifdef CONFIG_MARU - char *path = get_canonical_path(kernel_filename); - maru_register_exit_msg(MARU_EXIT_KERNEL_FILE_EXCEPTION, path); - g_free(path); -#endif exit(1); } diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 8cc2e7a0ea..5d282831cb 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -34,10 +34,6 @@ #include "hw/block/flash.h" #include "sysemu/kvm.h" -#ifdef CONFIG_MARU -#include "tizen/src/util/maru_err_table.h" -#endif - #define BIOS_FILENAME "bios.bin" typedef struct PcSysFwDevice { @@ -205,10 +201,9 @@ static void old_pc_system_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw) ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); if (ret != 0) { bios_error: - fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); -#ifdef CONFIG_MARU - maru_register_exit_msg(MARU_EXIT_BIOS_FILE_EXCEPTION, bios_name); -#endif +// CONFIG_MARU MODIFICATION +// fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); + error_report("qemu: could not load PC BIOS '%s'\n", bios_name); exit(1); } if (filename) { diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 7ab235590e..6c3a2df512 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -43,4 +43,18 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); const char *error_get_progname(void); extern bool enable_timestamp_msg; +#ifdef CONFIG_MARU +#include "qemu/queue.h" + +typedef struct ErrorReporter ErrorReporter; + +struct ErrorReporter +{ + void (*report)(const char *fmt, va_list ap); + QLIST_ENTRY(ErrorReporter) node; +}; + +void add_error_reporter(ErrorReporter *new_reporter); +#endif + #endif diff --git a/tizen/src/display/maru_shm.c b/tizen/src/display/maru_shm.c index ef7fc6dbb9..ea076509b7 100644 --- a/tizen/src/display/maru_shm.c +++ b/tizen/src/display/maru_shm.c @@ -34,12 +34,13 @@ #include #include "qemu/main-loop.h" +#include "qemu/error-report.h" + #include "maru_display.h" #include "emul_state.h" #include "maru_display_processing.h" #include "hw/pci/maru_brightness.h" #include "skin/maruskin_server.h" -#include "util/maru_err_table.h" #include "debug_ch.h" #include "eventcast/encode_fb.h" @@ -267,8 +268,7 @@ static void maru_shm_init(uint64 swt_handle, ERR("shmget failed\n"); perror("maru_vga: "); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - (char*) "Cannot launch this VM.\n" + error_report("Cannot launch this VM." "Failed to get identifier of the shared memory segment."); exit(1); } @@ -278,8 +278,7 @@ static void maru_shm_init(uint64 swt_handle, ERR("shmat failed\n"); perror("maru_vga: "); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - (char*) "Cannot launch this VM.\n" + error_report("Cannot launch this VM. " "Failed to attach the shared memory segment."); exit(1); } diff --git a/tizen/src/ecs/ecs_msg_device.c b/tizen/src/ecs/ecs_msg_device.c index d2d67772d6..57b921bd10 100644 --- a/tizen/src/ecs/ecs_msg_device.c +++ b/tizen/src/ecs/ecs_msg_device.c @@ -40,7 +40,7 @@ #include "skin/maruskin_operation.h" #include "skin/maruskin_server.h" -#include "util/maru_device_hotplug.h" +#include "util/device_hotplug.h" #include "util/hds.h" #include "emul_state.h" #include "ecs.h" diff --git a/tizen/src/ecs/ecs_msg_injector.c b/tizen/src/ecs/ecs_msg_injector.c index bb6c48f2a9..dca573046b 100644 --- a/tizen/src/ecs/ecs_msg_injector.c +++ b/tizen/src/ecs/ecs_msg_injector.c @@ -38,7 +38,7 @@ #include "hw/virtio/maru_virtio_jack.h" #include "hw/virtio/maru_virtio_power.h" -#include "util/maru_device_hotplug.h" +#include "util/device_hotplug.h" #include "util/hds.h" #include "emul_state.h" #include "ecs.h" diff --git a/tizen/src/ecs/ecs_sdcard.c b/tizen/src/ecs/ecs_sdcard.c index 25487d36c8..00a814021b 100644 --- a/tizen/src/ecs/ecs_sdcard.c +++ b/tizen/src/ecs/ecs_sdcard.c @@ -30,7 +30,7 @@ #include "ecs_sdcard.h" #include "ecs.h" #include "util/osutil.h" -#include "util/maru_device_hotplug.h" +#include "util/device_hotplug.h" #include "debug_ch.h" #include "emul_state.h" diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 67d4ae7478..c4d6e9b429 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -40,13 +40,14 @@ #include "emul_state.h" #include "emulator_options.h" #include "util/check_gl.h" -#include "util/maru_err_table.h" +#include "util/error_handler.h" #include "util/osutil.h" #include "util/sdb.h" #include "skin/maruskin_server.h" #include "util/new_debug_ch.h" #include "ecs/ecs.h" -#include "util/maru_device_hotplug.h" +#include "util/device_hotplug.h" +#include "util/exported_strings.h" #ifdef CONFIG_SDL #include @@ -97,8 +98,8 @@ static void construct_main_window(int skin_argc, char *skin_argv[], /* the next line checks for debugging and etc.. */ if (get_emul_skin_enable()) { if (0 > start_skin_client(skin_argc, skin_argv)) { - maru_register_exit_msg(MARU_EXIT_SKIN_SERVER_FAILED, NULL); - exit(-1); + error_report(FAILED_TO_INITIALIZE_SKIN); + exit(1); } } } @@ -120,8 +121,6 @@ static void emulator_notify_exit(Notifier *notifier, void *data) reset_variables(); LOG_INFO("Exit emulator...\n"); - - handle_error_at_exit(); } static Notifier emulator_exit = { .notify = emulator_notify_exit }; @@ -381,13 +380,13 @@ static int emulator_main(int argc, char *argv[], char **envp) #if defined (CONFIG_LINUX) int main(int argc, char *argv[], char **envp) { - register_exception_handler(); + init_error_handler(); return emulator_main(argc, argv, envp); } #else int main(int argc, char *argv[]) { - register_exception_handler(); + init_error_handler(); return emulator_main(argc, argv, NULL); } #endif diff --git a/tizen/src/emulator_legacy.c b/tizen/src/emulator_legacy.c index 619b24f0ea..6092e61dc4 100644 --- a/tizen/src/emulator_legacy.c +++ b/tizen/src/emulator_legacy.c @@ -41,7 +41,7 @@ #include "emul_state.h" #include "hw/virtio/maru_virtio_touchscreen.h" #include "util/check_gl.h" -#include "util/maru_err_table.h" +#include "util/error_handler.h" #include "display/maru_display.h" #include "util/osutil.h" #include "util/sdb.h" @@ -294,7 +294,6 @@ int legacy_emulator_main(int argc, char * argv[], char **envp) extract_qemu_info(_qemu_argc, _qemu_argv); INFO("Emulator start !!!\n"); - atexit(handle_error_at_exit); emulator_add_exit_notifier(&emulator_exit); extract_skin_info(_skin_argc, _skin_argv); diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index bdbdc2d0cf..ebdf0d894f 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -45,7 +45,7 @@ #ifdef CONFIG_WIN32 #include -#include "util/maru_err_table.h" +#include "qemu/error-report.h" #endif MULTI_DEBUG_CHANNEL(qemu, skinclient); @@ -279,8 +279,8 @@ static void *run_skin_client(void *arg) &pi)) { ERR("Unable to generate process! error %u\n", GetLastError()); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "CreateProcess function failed. Unable to generate process."); + error_report("CreateProcess function failed. " + "Unable to generate process."); exit(1); } diff --git a/tizen/src/skin/maruskin_client.h b/tizen/src/skin/maruskin_client.h index 496956c9bf..5e6cd3d256 100644 --- a/tizen/src/skin/maruskin_client.h +++ b/tizen/src/skin/maruskin_client.h @@ -31,7 +31,7 @@ #ifndef MARUSKIN_CLIENT_H_ #define MARUSKIN_CLIENT_H_ -#include "tizen/src/util/maru_util_strings.h" +#include "tizen/src/util/exported_strings.h" int start_skin_client(int argc, char* argv[]); int start_simple_client(char* msg); diff --git a/tizen/src/skin/maruskin_operation.c b/tizen/src/skin/maruskin_operation.c index f89edeab0e..c53b86da41 100644 --- a/tizen/src/skin/maruskin_operation.c +++ b/tizen/src/skin/maruskin_operation.c @@ -49,7 +49,7 @@ #include "maruskin_server.h" #include "display/maru_display.h" #include "hw/maru_pm.h" -#include "util/maru_device_hotplug.h" +#include "util/device_hotplug.h" #include "ecs/ecs.h" #include "hw/virtio/maru_virtio_evdi.h" #include "hw/virtio/maru_virtio_rotary.h" diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 29f6af297b..f0c334e505 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -33,9 +33,9 @@ #include "maruskin_server.h" #include "maruskin_operation.h" #include "display/maru_display.h" -#include "util/maru_err_table.h" #include "ecs/ecs.h" #include "emul_state.h" +#include "util/exported_strings.h" #ifdef CONFIG_WIN32 #include @@ -1457,7 +1457,7 @@ static void* do_heart_beat(void* args) ERR("!!! Fail to operate with heartbeat from skin client. Shutdown QEMU !!!\n"); ERR("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); - maru_register_exit_msg(MARU_EXIT_HB_TIME_EXPIRED, NULL); + error_report(EMULATOR_HAS_STOPPED "\n"); shutdown_qemu_gracefully(TIMEOUT_FOR_SHUTDOWN); } diff --git a/tizen/src/util/Makefile.objs b/tizen/src/util/Makefile.objs index 708b313d5c..43009e8e65 100644 --- a/tizen/src/util/Makefile.objs +++ b/tizen/src/util/Makefile.objs @@ -23,10 +23,10 @@ obj-$(CONFIG_WIN32) += check_gl_wgl.o obj-$(CONFIG_DARWIN) += check_gl_cgl.o # hotplug -obj-y += maru_device_hotplug.o +obj-y += device_hotplug.o -# error table -obj-y += maru_err_table.o +# error handler +obj-y += error_handler.o # debug channel obj-y += new_debug_ch.o diff --git a/tizen/src/util/maru_device_hotplug.c b/tizen/src/util/device_hotplug.c similarity index 99% rename from tizen/src/util/maru_device_hotplug.c rename to tizen/src/util/device_hotplug.c index e22605e4a5..f6d8994d6c 100644 --- a/tizen/src/util/maru_device_hotplug.c +++ b/tizen/src/util/device_hotplug.c @@ -33,7 +33,7 @@ #include "emulator.h" #include "emul_state.h" -#include "maru_device_hotplug.h" +#include "device_hotplug.h" #include "ecs/ecs.h" #include "hds.h" #include "ecs/ecs_sdcard.h" diff --git a/tizen/src/util/maru_device_hotplug.h b/tizen/src/util/device_hotplug.h similarity index 100% rename from tizen/src/util/maru_device_hotplug.h rename to tizen/src/util/device_hotplug.h diff --git a/tizen/src/util/maru_err_table.c b/tizen/src/util/error_handler.c similarity index 82% rename from tizen/src/util/maru_err_table.c rename to tizen/src/util/error_handler.c index fc5edc5f1f..87f36f7c2b 100644 --- a/tizen/src/util/maru_err_table.c +++ b/tizen/src/util/error_handler.c @@ -1,12 +1,11 @@ /* - * Error message + * Error handler * - * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * SeokYeon Hwang * GiWoong Kim - * YeongKyoon Lee * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,35 +31,38 @@ #include #include #include + +#include "qemu-common.h" + #ifdef CONFIG_WIN32 #include #else #include #endif -#include "qemu-common.h" +#include "qemu/error-report.h" +#include "error_handler.h" #include "emulator_common.h" #include "emulator.h" -#include "maru_err_table.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL(qemu, backtrace); +// deprecated /* This table must match the enum definition */ static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = { /* 0 */ "", /* 1 */ FAILED_TO_ALLOCATE_MEMORY, /* 2 */ FAILED_TO_LOAD_KERNEL CHECK_FILE_VALID, /* 3 */ FAILED_TO_LOAD_BIOS CHECK_FILE_VALID, - /* 4 */ FAILED_TO_INITIAL_SKIN, + /* 4 */ FAILED_TO_INITIALIZE_SKIN, /* 5 */ EMULATOR_HAS_STOPPED, /* add here.. */ "" }; - static int maru_exit_status = MARU_EXIT_NORMAL; static char *maru_exit_msg; @@ -73,6 +75,7 @@ static pthread_spinlock_t siglock; void maru_sighandler(int sig); #endif +// deprecated char *get_canonical_path(char const *const path) { if ((int)g_path_is_absolute(path)) { @@ -93,13 +96,15 @@ char *get_canonical_path(char const *const path) return canonical_path; } -void maru_register_exit_msg(int maru_exit_index, char const *format, ...) +// deprecated +// Use error_report() instead +void register_exit_message(int status, char const *format, ...) { va_list args; - if (maru_exit_index >= MARU_EXIT_NORMAL) { + if (status >= MARU_EXIT_NORMAL) { fprintf(stderr, "Invalid error message index = %d\n", - maru_exit_index); + status); return; } if (maru_exit_status != MARU_EXIT_NORMAL) { @@ -108,7 +113,7 @@ void maru_register_exit_msg(int maru_exit_index, char const *format, ...) return; } - maru_exit_status = maru_exit_index; + maru_exit_status = status; if (maru_exit_status == MARU_EXIT_HB_TIME_EXPIRED) { fprintf(stderr, "Skin client could not connect to Skin server." @@ -141,7 +146,7 @@ struct frame_layout { void *pReturnAddr; }; -static char *aqua_get_filename_from_path(char *path_buf) +static char *get_filename_from_path(char *path_buf) { char *ret_slash; char *ret_rslash; @@ -161,7 +166,7 @@ static char *aqua_get_filename_from_path(char *path_buf) } -static HMODULE aqua_get_module_handle(DWORD dwAddress) +static HMODULE get_module_handle(DWORD dwAddress) { MEMORY_BASIC_INFORMATION Buffer; return VirtualQuery((LPCVOID) dwAddress, &Buffer, sizeof(Buffer)) @@ -200,13 +205,13 @@ static void dump_backtrace(void *ptr, int depth) ERR("\nBacktrace Dump Start :\n"); if (pContext) { memset(module_buf, 0, sizeof(module_buf)); - hModule = aqua_get_module_handle((DWORD)((PCONTEXT)pContext)->Eip); + hModule = get_module_handle((DWORD)((PCONTEXT)pContext)->Eip); if (hModule) { if (!GetModuleFileNameA(hModule, module_buf, sizeof(module_buf))) { memset(module_buf, 0, sizeof(module_buf)); } } - ERR("[%02d]Addr = 0x%p : %s\n", nCount, ((PCONTEXT)pContext)->Eip, aqua_get_filename_from_path(module_buf)); + ERR("[%02d]Addr = 0x%p : %s\n", nCount, ((PCONTEXT)pContext)->Eip, get_filename_from_path(module_buf)); nCount++; } @@ -217,13 +222,13 @@ static void dump_backtrace(void *ptr, int depth) } memset(module_buf, 0, sizeof(module_buf)); - hModule = aqua_get_module_handle((DWORD)currentFrame.pReturnAddr); + hModule = get_module_handle((DWORD)currentFrame.pReturnAddr); if (hModule) { if (!GetModuleFileNameA(hModule, module_buf, sizeof(module_buf))) { memset(module_buf, 0, sizeof(module_buf)); } } - ERR("[%02d]Addr = 0x%p : %s\n", nCount, currentFrame.pReturnAddr, aqua_get_filename_from_path(module_buf)); + ERR("[%02d]Addr = 0x%p : %s\n", nCount, currentFrame.pReturnAddr, get_filename_from_path(module_buf)); if (!ReadProcessMemory(GetCurrentProcess(), currentFrame.pNext, (void *)¤tFrame, sizeof(struct frame_layout), NULL)) { @@ -247,17 +252,18 @@ static void dump_backtrace(void *ptr, int depth) #endif } -void handle_error_at_exit(void) +static void handle_error_at_exit(void) { + // deprecated 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"); + INFO("This is not an error.\n"); dump_backtrace(NULL, 0); } @@ -278,7 +284,7 @@ static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExcepti pExceptionRecord = pExceptionInfo->ExceptionRecord; memset(module_buf, 0, sizeof(module_buf)); - hModule = aqua_get_module_handle((DWORD)pExceptionRecord->ExceptionAddress); + hModule = get_module_handle((DWORD)pExceptionRecord->ExceptionAddress); if(hModule){ if(!GetModuleFileNameA(hModule, module_buf, sizeof(module_buf))){ memset(module_buf, 0, sizeof(module_buf)); @@ -287,7 +293,7 @@ static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExcepti ERR("Exception [%X] occured at %s:0x%08x\n", pExceptionRecord->ExceptionCode, - aqua_get_filename_from_path(module_buf), + get_filename_from_path(module_buf), pExceptionRecord->ExceptionAddress ); @@ -301,11 +307,11 @@ static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExcepti #ifdef CONFIG_LINUX void maru_sighandler(int sig) { + ERR("Got signal %d\n", sig); // print system information again print_system_info(); pthread_spin_lock(&siglock); - ERR("Got signal %d\n", sig); dump_backtrace(NULL, 0); pthread_spin_unlock(&siglock); _exit(0); @@ -314,7 +320,7 @@ void maru_sighandler(int sig) #ifndef CONFIG_DARWIN -void register_exception_handler(void) +static void register_exception_handler(void) { #ifdef CONFIG_WIN32 prevExceptionFilter = SetUnhandledExceptionFilter(maru_unhandled_exception_filter); @@ -340,8 +346,37 @@ void register_exception_handler(void) #endif } #else // CONFIG_DARWIN -void register_exception_handler(void) +static void register_exception_handler(void) { // TODO: Exception handling on darwin } #endif + +#define MAX_MESSAGE_LEN 2048 +static size_t message_len; +static char message[MAX_MESSAGE_LEN]; + +static void report(const char *fmt, va_list ap) +{ + char *new_message = g_strdup_vprintf(fmt, ap); + message_len = g_strlcat(message, new_message, MAX_MESSAGE_LEN); + g_free(new_message); + + // We are wating for '\n' + if (message[message_len - 1] == '\n') { + fprintf(stderr, "%s", message); + start_simple_client(message); + message[0] = '\0'; + message_len = 0; + } +} + +static ErrorReporter error_reporter = + { .report = report }; + +void init_error_handler(void) { + register_exception_handler(); + add_error_reporter(&error_reporter); + + atexit(handle_error_at_exit); +} diff --git a/tizen/src/util/maru_err_table.h b/tizen/src/util/error_handler.h similarity index 78% rename from tizen/src/util/maru_err_table.h rename to tizen/src/util/error_handler.h index f7f8b81072..7081672d1a 100644 --- a/tizen/src/util/maru_err_table.h +++ b/tizen/src/util/error_handler.h @@ -1,12 +1,11 @@ /* - * Error message + * Error handler * - * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * SeokYeon Hwang * GiWoong Kim - * YeongKyoon Lee * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,11 +28,12 @@ */ -#ifndef __EMUL_ERR_TABLE_H__ -#define __EMUL_ERR_TABLE_H__ +#ifndef __ERROR_HANDLER_H__ +#define __ERROR_HANDLER_H__ #include "tizen/src/skin/maruskin_client.h" +// deprecated /* TODO: define macro for fair of definition */ /* This enum must match the table definition */ enum { @@ -47,10 +47,10 @@ enum { MARU_EXIT_NORMAL }; - +void init_error_handler(void); +// deprecated +void register_exit_message(int status, char const *format, ...); +// deprecated char *get_canonical_path(char const *const path); -void maru_register_exit_msg(int maru_exit_status, char const *format, ...); -void register_exception_handler(void); -void handle_error_at_exit(void); -#endif /* __EMUL_ERR_TABLE_H__ */ +#endif /* __ERROR_HANDLER_H__ */ diff --git a/tizen/src/util/maru_util_strings.h b/tizen/src/util/exported_strings.h similarity index 95% rename from tizen/src/util/maru_util_strings.h rename to tizen/src/util/exported_strings.h index 4bae1c221e..e29c77f067 100644 --- a/tizen/src/util/maru_util_strings.h +++ b/tizen/src/util/exported_strings.h @@ -38,7 +38,7 @@ #define FAILED_TO_LOAD_BIOS "Failed to load a bios file in bios path that mentioned on document." #define FAILED_TO_LOAD_DISK "Failed to load disk file from the following path." #define CHECK_FILE_VALID " Check if the file is corrupted or missing.\n\n" -#define FAILED_TO_INITIAL_SKIN "Skin process cannot be initialized. Skin server is not ready." +#define FAILED_TO_INITIALIZE_SKIN "Skin process cannot be initialized. Skin server is not ready." #define FAILED_TO_INSTALL_EXTRAPACKAGE_1 "Extra package installation is failed.\n" #define FAILED_TO_INSTALL_EXTRAPACKAGE_2 " must be installed MANUALLY!" #define EMULATOR_HAS_STOPPED "Emulator has stopped working.\nA problem caused the program to stop working correctly." diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index ee7e1943a3..4fc31e28e0 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -39,7 +39,6 @@ #include "emulator.h" #include "emul_state.h" #include "debug_ch.h" -#include "maru_err_table.h" #include "sdb.h" #include "emulator_options.h" diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index b940fd11a5..9f0ac30787 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -35,11 +35,19 @@ */ #include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/error-report.h" + #include "osutil.h" #include "emulator.h" #include "emul_state.h" -#include "debug_ch.h" -#include "maru_err_table.h" #include "sdb.h" #include "emulator_options.h" @@ -47,14 +55,7 @@ #error #endif -#include -#include -#include -#include -#include -#include -#include - +#include "debug_ch.h" MULTI_DEBUG_CHANNEL(emulator, osutil); static int g_shmid; @@ -79,7 +80,7 @@ void check_vm_lock_os(void) val = shmctl(shm_id, IPC_STAT, &shm_info); if (val != -1) { - INFO("count of process that use shared memory : %d\n", + INFO("count of process that use shared memory: %d\n", shm_info.shm_nattch); if ((shm_info.shm_nattch > 0) && g_strcmp0(get_drive_image_file(), (char *)shm_addr) == 0) { @@ -88,10 +89,9 @@ void check_vm_lock_os(void) continue; } shmdt(shm_addr); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "Can not execute this VM.\n" - "The same name is running now."); - exit(0); + error_report("Can not execute this VM. " + "The same name is running now."); + exit(1); } else { shmdt(shm_addr); } diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index cc7f3276c3..d01e658e86 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -39,7 +39,6 @@ #include "osutil.h" #include "emulator.h" #include "emul_state.h" -#include "maru_err_table.h" #include "sdb.h" #include "emulator_options.h" @@ -48,6 +47,7 @@ #endif #include +#include "qemu/error-report.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL (emulator, osutil); @@ -79,8 +79,7 @@ void check_vm_lock_os(void) } if (strcmp(pBuf, get_drive_image_file()) == 0) { - maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "Can not execute this VM.\n" + error_report("Can not execute this VM. " "The same name is running now."); UnmapViewOfFile(pBuf); CloseHandle(hMapFile); diff --git a/util/qemu-error.c b/util/qemu-error.c index 9bba5f53d8..abab065500 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -13,6 +13,26 @@ #include #include "monitor/monitor.h" +#ifdef CONFIG_MARU +static QLIST_HEAD(, ErrorReporter) error_reporters = + QLIST_HEAD_INITIALIZER(error_reporters); + +void add_error_reporter(ErrorReporter *new_reporter) +{ + QLIST_INSERT_HEAD(&error_reporters, new_reporter, node); +} + +static void report_to_clients(const char *fmt, va_list ap) +{ + ErrorReporter *reporter; + QLIST_FOREACH(reporter, &error_reporters, node) { + if (reporter->report) { + (*(reporter->report))(fmt, ap); + } + } +} +#endif + /* * Print to current monitor if we have one, else to stderr. * TODO should return int, so callers can calculate width, but that @@ -24,6 +44,9 @@ void error_vprintf(const char *fmt, va_list ap) monitor_vprintf(cur_mon, fmt, ap); } else { vfprintf(stderr, fmt, ap); +#ifdef CONFIG_MARU + report_to_clients(fmt, ap); +#endif } } diff --git a/vl.c b/vl.c index e8891c920e..bbbe0f69e6 100644 --- a/vl.c +++ b/vl.c @@ -132,7 +132,6 @@ int qemu_main(int argc, char **argv, char **envp); #ifdef CONFIG_MARU #include "tizen/src/emulator.h" -#include "tizen/src/util/maru_err_table.h" #include "tizen/src/emul_state.h" #include "tizen/src/display/maru_display.h" #include "tizen/src/skin/maruskin_operation.h" @@ -2223,9 +2222,8 @@ static DisplayType select_display(const char *p) display = DT_MARU_QT_ONSCREEN; } # else - fprintf(stderr, "maru_qt is disabled\n"); + error_report("maru_qt is disabled.\n"); - maru_register_exit_msg(MARU_EXIT_UNKNOWN, "maru_qt is disabled"); exit(1); # endif #endif /* CONFIG_MARU */ @@ -2697,9 +2695,6 @@ static const QEMUOption *lookup_opt(int argc, char **argv, for(;;) { if (!popt->name) { error_report("invalid option"); -#ifdef CONFIG_MARU - maru_register_exit_msg(MARU_EXIT_UNKNOWN, "invalid option."); -#endif exit(1); } if (!strcmp(popt->name, r + 1)) @@ -2709,9 +2704,6 @@ static const QEMUOption *lookup_opt(int argc, char **argv, if (popt->flags & HAS_ARG) { if (optind >= argc) { error_report("requires an argument"); -#ifdef CONFIG_MARU - maru_register_exit_msg(MARU_EXIT_UNKNOWN, "requires an argument."); -#endif exit(1); } optarg = argv[optind++]; -- 2.34.1