Support opcodes registration for Windows
authorDaniel Zaoui <daniel.zaoui@yahoo.com>
Fri, 2 Jun 2017 09:13:31 +0000 (12:13 +0300)
committerDaniel Zaoui <daniel.zaoui@yahoo.com>
Mon, 5 Jun 2017 05:55:38 +0000 (08:55 +0300)
A standard static array with symbols whose addresses are only known at
runtime is not supported in Windows.

src/bin/efl/efl_debug.c
src/lib/eina/eina_debug.h
src/lib/eina/eina_debug_bt.c
src/lib/eina/eina_debug_cpu.c
src/lib/eina/eina_evlog.c

index be96b04..1ebe8c8 100644 (file)
@@ -225,19 +225,18 @@ _args_handle(void *data EINA_UNUSED, Eina_Bool flag)
      }
 }
 
-static const Eina_Debug_Opcode ops[] =
-{
-     {"Daemon/Client/register_observer",  &_cl_stat_reg_opcode,   NULL},
-     {"Daemon/Client/added",              NULL,                   &_clients_info_added_cb},
-     {"Daemon/Client/deleted",            NULL,                   &_clients_info_deleted_cb},
-     {"Daemon/Client/cid_from_pid",       &_cid_from_pid_opcode,  &_cid_get_cb},
-     {"Profiler/on",                      &_prof_on_opcode,       NULL},
-     {"Profiler/off",                     &_prof_off_opcode,      NULL},
-     {"CPU/Freq/on",                      &_cpufreq_on_opcode,    NULL},
-     {"CPU/Freq/off",                     &_cpufreq_off_opcode,   NULL},
-     {"EvLog/get",                        &_evlog_get_opcode,     _evlog_get_cb},
-     {NULL, NULL, NULL}
-};
+EINA_DEBUG_OPCODES_ARRAY_DEFINE(ops,
+      {"Daemon/Client/register_observer",  &_cl_stat_reg_opcode,   NULL},
+      {"Daemon/Client/added",              NULL,                   &_clients_info_added_cb},
+      {"Daemon/Client/deleted",            NULL,                   &_clients_info_deleted_cb},
+      {"Daemon/Client/cid_from_pid",       &_cid_from_pid_opcode,  &_cid_get_cb},
+      {"Profiler/on",                      &_prof_on_opcode,       NULL},
+      {"Profiler/off",                     &_prof_off_opcode,      NULL},
+      {"CPU/Freq/on",                      &_cpufreq_on_opcode,    NULL},
+      {"CPU/Freq/off",                     &_cpufreq_off_opcode,   NULL},
+      {"EvLog/get",                        &_evlog_get_opcode,     _evlog_get_cb},
+      {NULL, NULL, NULL}
+);
 
 int
 main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
@@ -254,7 +253,7 @@ main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
         fprintf(stderr, "ERROR: Cannot connect to debug daemon.\n");
         return -1;
      }
-   eina_debug_opcodes_register(_session, ops, _args_handle, NULL);
+   eina_debug_opcodes_register(_session, ops(), _args_handle, NULL);
 
    ecore_main_loop_begin();
 
index 6f7eee1..8fb797d 100644 (file)
@@ -122,6 +122,25 @@ typedef struct
 } Eina_Debug_Packet_Header;
 
 /**
+ * Helper for creating global opcodes arrays.
+ * The problem is on windows where you can't declare a static array with
+ * external symbols in it, because the addresses are only known at runtime.
+ */
+#define EINA_DEBUG_OPCODES_ARRAY_DEFINE(Name, ...)                           \
+  static Eina_Debug_Opcode *                                      \
+  Name(void)                                                            \
+  {                                                                     \
+     Eina_Debug_Opcode tmp[] = { __VA_ARGS__ }; \
+     static Eina_Debug_Opcode internal[EINA_C_ARRAY_LENGTH(tmp) + 1] = \
+       { { 0, 0, 0 } };         \
+     if (internal[0].opcode_name == NULL)                                      \
+       {                                                                \
+          memcpy(internal, tmp, sizeof(tmp)); \
+       }                                                                \
+     return internal;                                                   \
+  }
+
+/**
  * @typedef Eina_Debug_Opcode
  *
  * Structure to describe information for an opcode. It is used to register new
index 157fe54..69fe6b4 100644 (file)
@@ -256,19 +256,18 @@ _prof_off_cb(Eina_Debug_Session *session EINA_UNUSED, int cid EINA_UNUSED, void
    return EINA_TRUE;
 }
 
-static const Eina_Debug_Opcode _OPS[] =
-{
-     {"Profiler/on", NULL, &_prof_on_cb},
-     {"Profiler/off", NULL, &_prof_off_cb},
-     {NULL, NULL, NULL}
-};
+EINA_DEBUG_OPCODES_ARRAY_DEFINE(_OPS,
+      {"Profiler/on", NULL, &_prof_on_cb},
+      {"Profiler/off", NULL, &_prof_off_cb},
+      {NULL, NULL, NULL}
+);
 
 Eina_Bool
 _eina_debug_bt_init(void)
 {
    _signal_init();
    eina_semaphore_new(&_wait_for_bts_sem, 0);
-   eina_debug_opcodes_register(NULL, _OPS, NULL, NULL);
+   eina_debug_opcodes_register(NULL, _OPS(), NULL, NULL);
    return EINA_TRUE;
 }
 
index 505bed0..060bde3 100644 (file)
@@ -272,12 +272,11 @@ _cpufreq_off_cb(Eina_Debug_Session *session EINA_UNUSED, int cid EINA_UNUSED, vo
    return EINA_TRUE;
 }
 
-static const Eina_Debug_Opcode _OPS[] =
-{
-     {"CPU/Freq/on", NULL, &_cpufreq_on_cb},
-     {"CPU/Freq/off", NULL, &_cpufreq_off_cb},
-     {NULL, NULL, NULL}
-};
+EINA_DEBUG_OPCODES_ARRAY_DEFINE(_OPS,
+      {"CPU/Freq/on", NULL, &_cpufreq_on_cb},
+      {"CPU/Freq/off", NULL, &_cpufreq_off_cb},
+      {NULL, NULL, NULL}
+);
 
 Eina_Bool
 _eina_debug_cpu_init(void)
@@ -296,7 +295,7 @@ _eina_debug_cpu_init(void)
           }
         _sysmon_thread_runs = EINA_TRUE;
      }
-   eina_debug_opcodes_register(NULL, _OPS, NULL, NULL);
+   eina_debug_opcodes_register(NULL, _OPS(), NULL, NULL);
    return EINA_TRUE;
 }
 
index c078bee..0c2fda4 100644 (file)
@@ -249,13 +249,12 @@ _stop_cb(Eina_Debug_Session *session EINA_UNUSED, int cid EINA_UNUSED, void *buf
    return EINA_TRUE;
 }
 
-static const Eina_Debug_Opcode _EINA_DEBUG_EVLOG_OPS[] =
-{
-     {"EvLog/on", NULL, &_start_cb},
-     {"EvLog/off", NULL, &_stop_cb},
-     {"EvLog/get", &_evlog_get_opcode, &_get_cb},
-     {NULL, NULL, NULL}
-};
+EINA_DEBUG_OPCODES_ARRAY_DEFINE(_EINA_DEBUG_EVLOG_OPS,
+      {"EvLog/on", NULL, &_start_cb},
+      {"EvLog/off", NULL, &_stop_cb},
+      {"EvLog/get", &_evlog_get_opcode, &_get_cb},
+      {NULL, NULL, NULL}
+);
 
 Eina_Bool
 eina_evlog_init(void)
@@ -273,7 +272,7 @@ eina_evlog_init(void)
      }
 #endif
    eina_evlog("+eina_init", NULL, 0.0, NULL);
-   eina_debug_opcodes_register(NULL, _EINA_DEBUG_EVLOG_OPS, NULL, NULL);
+   eina_debug_opcodes_register(NULL, _EINA_DEBUG_EVLOG_OPS(), NULL, NULL);
    return EINA_TRUE;
 }