diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/espik.c | 22 | ||||
-rw-r--r-- | src/espik_debug.c | 43 | ||||
-rw-r--r-- | src/espik_debug.h | 8 |
4 files changed, 68 insertions, 7 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 84ac16f..0748e82 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,7 @@ ESPIKHEADERS = \ espik_config.h \ espik_common_handler.h \ espik_error.h \ + espik_debug.h \ espik_global.h espik_SOURCES = \ @@ -20,6 +21,7 @@ espik_SOURCES = \ espik_config.c \ espik_common_handler.c \ espik_error.c \ + espik_debug.c \ $(ESPIKHEADERS) espik_LDADD = \ diff --git a/src/espik.c b/src/espik.c index 0ab6fd7..6936033 100644 --- a/src/espik.c +++ b/src/espik.c @@ -6,8 +6,8 @@ /* EFL Stuff */ #include <Ecore.h> -#include <Ecore_Config.h> /* Configuration lib */ -//#include <Ecore_Con.h> /* Socket lib */ +#include <Ecore_Config.h> /* Configuration lib */ +/*#include <Ecore_Con.h> */ /* Socket lib */ /* Ebic Stuff */ #include "espik_global.h" @@ -16,12 +16,16 @@ #include "espik_common_handler.h" #include "espik_net.h" #include "espik.h" +#if _ESPIK_DEBUG_ +# include "espik_debug.h" +#endif typedef int (*Handler_Func) (void *data, int ev_type, void *ev); -//typedef int (*Handler_Fd_Func) (void *data, Ecore_Fd_Handler * fd_handler); +/* typedef int (*Handler_Fd_Func) (void *data, Ecore_Fd_Handler * fd_handler); */ /* Use to replace EOL ('\n') with NULL ('\0') */ + int del_backslash (char *msg) { int i, count; @@ -45,6 +49,10 @@ int main (int argc, char **argv) printf ("Welcome to %s %s\n", APPS_NAME, ESPIK_VERSION); +#if _ESPIK_DEBUG_ + debug_init(); +#endif + espik_config_init (); if (argc < 3) @@ -94,7 +102,7 @@ int main (int argc, char **argv) fprintf (stderr, "main: Cannot ecore_main_fd_handler_add\n"); exit (-1); } - //ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL); + /* ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL); */ /* Init IRC connection */ @@ -108,7 +116,7 @@ int main (int argc, char **argv) ecore_main_loop_begin (); - //ecore_con_server_del (con_sock); + /* ecore_con_server_del (con_sock); */ free (a_infos.server->host); free (a_infos.server); @@ -119,14 +127,14 @@ int main (int argc, char **argv) */ free (a_infos.client); - // ecore_main_loop_quit (); + /* ecore_main_loop_quit (); */ #if _ESPIK_DEBUG_ printf (" end\n"); #endif ecore_config_shutdown (); - // ecore_con_shutdown (); + /* ecore_con_shutdown (); */ ecore_shutdown (); return (0); diff --git a/src/espik_debug.c b/src/espik_debug.c new file mode 100644 index 0000000..9f4a121 --- /dev/null +++ b/src/espik_debug.c @@ -0,0 +1,43 @@ +#if _ESPIK_DEBUG + +#ifdef __GLIBC__ +#include <execinfo.h> +#endif + +#include <stdio.h> +#include <signal.h> + +inline void espik_debug_bt (int num) +{ +#ifdef __GLIBC__ + void *array[128]; + size_t size; + char **strings; + size_t i; + + if (!debug_bt) return; + + fprintf(stderr, "\n***** Backtrace (Signal %d) *****\n", num); + size = backtrace(array, 128); + strings = backtrace_symbols(array, size); + for (i = 0 ; i < size ; i++) + fprintf(stderr, "%s\n", strings[i]); + + if (strings) + free(strings); +#else + fprintf(stderr, "Your system doesn't have glibc. Backtraces disabled. But program receive signal %d.\n", num); +#endif /* __GLIBC__ */ +} + +void espik_debug_init() +{ + struct sigaction sa; + + sa.sa_handler = espik_debug_bt; + sigaction(SIGSEGV, &sa, (struct sigaction *)0); + sigaction(SIGINT, &sa, (struct sigaction *)0); + sigaction(SIGKILL, &sa, (struct sigaction *)0); +} + +#endif /* _ESPIK_DEBUG */ diff --git a/src/espik_debug.h b/src/espik_debug.h new file mode 100644 index 0000000..fec35e0 --- /dev/null +++ b/src/espik_debug.h @@ -0,0 +1,8 @@ +#if _ESPIK_DEBUG +# ifndef _HAVE_ESPIK_DEBUG_H +# define _HAVE_ESPIK_DEBUG_H + +inline void espik_bt (void); + +# endif /* _HAVE_ESPIK_DEBUG_H */ +#endif /* _ESPIK_DEBUG */ |