Fix Windows compilation
authorDaniel Zaoui <daniel.zaoui@yahoo.com>
Sun, 4 Jun 2017 13:11:16 +0000 (16:11 +0300)
committerDaniel Zaoui <daniel.zaoui@yahoo.com>
Mon, 5 Jun 2017 05:55:38 +0000 (08:55 +0300)
Thanks to vtorri for his help on this delicate issue named Windows

src/bin/efl/efl_debugd.c
src/lib/eina/eina_debug.c
src/lib/eina/eina_debug_bt.c
src/lib/eina/eina_debug_private.h
src/lib/eina/eina_debug_timer.c

index 72f6062..902a2c6 100644 (file)
  * if not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <unistd.h>
-#include <sys/epoll.h>
+#ifdef HAVE_SYS_EPOLL_H
+# include <sys/epoll.h>
+#endif
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
 #include <fcntl.h>
 #include "eina_debug_private.h"
 
@@ -598,15 +612,12 @@ err:
 static Eina_Bool
 _server_launch()
 {
+#ifndef _WIN32
    struct epoll_event event = {0};
 
    _epfd = epoll_create (MAX_EVENTS);
 
-#ifndef _WIN32
    _listening_unix_fd = _listening_unix_socket_create();
-#else
-   _listening_unix_fd = -1;
-#endif
    if (_listening_unix_fd <= 0) goto err;
    event.data.fd = _listening_unix_fd;
    event.events = EPOLLIN;
@@ -623,6 +634,7 @@ err:
    _listening_unix_fd = -1;
    if (_listening_tcp_fd >= 0) close(_listening_tcp_fd);
    _listening_tcp_fd = -1;
+#endif
    return EINA_FALSE;
 }
 
index 081b5b6..ae0ac0f 100644 (file)
 #  define _GNU_SOURCE 1
 # endif
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
-#include <sys/epoll.h>
+#ifdef HAVE_SYS_EPOLL_H
+# include <sys/epoll.h>
+#endif
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
 #include <fcntl.h>
 
+#ifdef _WIN32
+# include <winsock2.h>
+# include <Evil.h>
+#endif
+
 #include "eina_debug.h"
 #include "eina_types.h"
 #include "eina_list.h"
@@ -50,7 +69,7 @@
 #include "eina_stringshare.h"
 #include "eina_debug_private.h"
 
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) || defined (_WIN32)
 # define LIBEXT ".dll"
 #else
 # define LIBEXT ".so"
@@ -107,7 +126,9 @@ struct _Eina_Debug_Session
    int fd; /* File descriptor */
 };
 
+#ifndef _WIN32
 static void _opcodes_register_all(Eina_Debug_Session *session);
+#endif
 static void _thread_start(Eina_Debug_Session *session);
 
 EAPI int
@@ -130,10 +151,13 @@ eina_debug_session_send(Eina_Debug_Session *session, int dest, int op, void *dat
    /* Sending payload */
    if (size) write(session->fd, data, size);
    eina_spinlock_release(&_eina_debug_lock);
+#else
+   (void)data;
 #endif
    return size;
 }
 
+#ifndef _WIN32
 static void
 _daemon_greet(Eina_Debug_Session *session)
 {
@@ -159,7 +183,6 @@ _daemon_greet(Eina_Debug_Session *session)
    eina_debug_session_send(session, 0, EINA_DEBUG_OPCODE_HELLO, buf, size);
 }
 
-#ifndef _WIN32
 static int
 _packet_receive(Eina_Debug_Session *session, unsigned char **buffer)
 {
@@ -249,6 +272,7 @@ eina_debug_session_dispatch_get(Eina_Debug_Session *session)
    else return NULL;
 }
 
+#ifndef _WIN32
 static void
 _static_opcode_register(Eina_Debug_Session *session,
       int op_id, Eina_Debug_Cb cb)
@@ -305,6 +329,7 @@ _callbacks_register_cb(Eina_Debug_Session *session, int src_id EINA_UNUSED, void
 
    return EINA_FALSE;
 }
+#endif
 
 static void
 _opcodes_registration_send(Eina_Debug_Session *session,
@@ -323,7 +348,7 @@ _opcodes_registration_send(Eina_Debug_Session *session,
 
    buf = malloc(size);
 
-   uint64_t info_64 = (uint64_t)info;
+   uint64_t info_64 = (uint64_t)(uintptr_t)info;
    info_64 = SWAP_64(info_64);
    memcpy(buf, &info_64, sizeof(uint64_t));
    int size_curr = sizeof(uint64_t);
@@ -341,6 +366,7 @@ _opcodes_registration_send(Eina_Debug_Session *session,
    free(buf);
 }
 
+#ifndef _WIN32
 static void
 _opcodes_register_all(Eina_Debug_Session *session)
 {
@@ -389,7 +415,6 @@ _socket_home_get()
    return dir;
 }
 
-#ifndef _WIN32
 #define LENGTH_OF_SOCKADDR_UN(s) \
    (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
 #endif
@@ -485,6 +510,8 @@ err:
 // even if the mainloop is blocked or the app otherwise deadlocked in some
 // way. this is an alternative to using external debuggers so we can get
 // users or developers to get useful information about an app at all times
+
+#ifndef _WIN32
 static void *
 _monitor(void *_data)
 {
@@ -537,11 +564,13 @@ _monitor(void *_data)
      }
    return NULL;
 }
+#endif
 
 // start up the debug monitor if we haven't already
 static void
 _thread_start(Eina_Debug_Session *session)
 {
+#ifndef _WIN32
    pthread_t monitor_thread;
    int err;
    sigset_t oldset, newset;
@@ -569,6 +598,9 @@ _thread_start(Eina_Debug_Session *session)
         e_debug("EINA DEBUG ERROR: Can't create monitor debug thread!");
         abort();
      }
+#else
+   (void)session;
+#endif
 }
 
 /*
index 69fe6b4..e8f96fd 100644 (file)
 # endif
 
 #ifdef HAVE_DLADDR
-# include <dlfcn.h>
+# ifdef _WIN32
+#  include <Evil.h>
+# else
+#  include <dlfcn.h>
+# endif
 #endif
+
+#ifdef HAVE_UNWIND
 #include <libunwind.h>
+#endif
 
 #include "eina_debug.h"
 #include "eina_debug_private.h"
 
-#define SIG SIGPROF
+#ifndef _WIN32
+# define SIG SIGPROF
+#endif
 
 static Eina_Semaphore _wait_for_bts_sem;
 
@@ -45,6 +54,7 @@ static Eina_Debug_Timer *_timer = NULL;
 void
 _eina_debug_dump_fhandle_bt(FILE *f, void **bt, int btlen)
 {
+#ifndef _WIN32
    int i;
    Dl_info info;
    const char *file;
@@ -67,12 +77,18 @@ _eina_debug_dump_fhandle_bt(FILE *f, void **bt, int btlen)
         if (file) fprintf(f, "%s\t 0x%llx 0x%llx\n", file, offset, base);
         else fprintf(f, "??\t -\n");
      }
+#else
+   (void)f;
+   (void)bt;
+   (void)btlen;
+#endif
 }
 
 // a backtracer that uses libunwind to do the job
 static inline int
 _eina_debug_unwind_bt(void **bt, int max)
 {
+#ifdef HAVE_UNWIND
    unw_cursor_t cursor;
    unw_context_t uc;
    unw_word_t p;
@@ -90,6 +106,11 @@ _eina_debug_unwind_bt(void **bt, int max)
      }
    // return our total backtrace stack size
    return total;
+#else
+   (void)bt;
+   (void)max;
+   return 0;
+#endif
 }
 
 // a quick and dirty local time point getter func - not portable
@@ -107,6 +128,7 @@ get_time(void)
 #endif
 }
 
+#ifndef _WIN32
 static void
 _signal_handler(int sig EINA_UNUSED,
       siginfo_t *si EINA_UNUSED, void *foo EINA_UNUSED)
@@ -143,10 +165,12 @@ found:
    // backtrace info
    eina_semaphore_release(&_wait_for_bts_sem, 1);
 }
+#endif
 
 static void
 _signal_init(void)
 {
+#ifndef _WIN32
    struct sigaction sa;
 
    // set up signal handler for our profiling signal - eevery thread should
@@ -162,6 +186,7 @@ _signal_init(void)
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    if (sigaction(SIGPIPE, &sa, 0) == -1) perror(0);
+#endif
 }
 
 static void
@@ -169,7 +194,9 @@ _collect_bt(pthread_t pth)
 {
    // this async signals the thread to switch to the deebug signal handler
    // and collect a backtrace and other info from inside the thread
+#ifndef _WIN32
    pthread_kill(pth, SIG);
+#endif
 }
 
 static Eina_Bool
@@ -277,3 +304,4 @@ _eina_debug_bt_shutdown(void)
    eina_semaphore_free(&_wait_for_bts_sem);
    return EINA_TRUE;
 }
+
index 2d07409..448f790 100644 (file)
@@ -65,13 +65,19 @@ void  _eina_debug_chunk_tmp_reset(void);
 const char *_eina_debug_file_get(const char *fname);
 
 void _eina_debug_dump_fhandle_bt(FILE *f, void **bt, int btlen);
+
 #define EINA_MAX_BT 256
+#ifdef HAVE_BACKTRACE
 #define EINA_BT(file) \
    do { \
       void *bt[EINA_MAX_BT]; \
       int btlen = backtrace((void **)bt, EINA_MAX_BT); \
       _eina_debug_dump_fhandle_bt(file, bt, btlen); \
    } while (0)
+#else
+#define EINA_BT(file) do { } while (0)
+#endif
+
 
 Eina_Bool _eina_debug_cpu_init(void);
 Eina_Bool _eina_debug_cpu_shutdown(void);
index 8fc8b33..ece2db6 100644 (file)
 #  define _GNU_SOURCE 1
 # endif
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
-#include <sys/epoll.h>
+#ifdef HAVE_SYS_EPOLL_H
+# include <sys/epoll.h>
+#endif
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -182,7 +188,9 @@ Eina_Bool
 _eina_debug_timer_init(void)
 {
    eina_spinlock_new(&_lock);
+#ifndef _WIN32
    pipe(pipeToThread);
+#endif
    return EINA_TRUE;
 }