summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2017-03-16 13:13:37 +0200
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2017-03-17 10:27:06 +0200
commit3ad8c1b5c27ca10a99a726f7b2621484c4a5c0ed (patch)
tree2af9948f0f0eb172df6815df23400e2659ec84f0
parent4442d186ab7976d1789c887435ada8ec9d6fdebc (diff)
Add Clouseau module
It includes the snapshot feature. Instead of duplicating code to retrieve the classes, objects... we send to ourselves debug packets with the Eo/Eolian opcodes.
-rw-r--r--edebug.pc.in2
-rw-r--r--src/lib/CMakeLists.txt7
-rw-r--r--src/lib/clouseau_debug.c148
3 files changed, 156 insertions, 1 deletions
diff --git a/edebug.pc.in b/edebug.pc.in
index 3f14181..0930e79 100644
--- a/edebug.pc.in
+++ b/edebug.pc.in
@@ -6,7 +6,7 @@ includedir=@includedir@
6Name: libedebug 6Name: libedebug
7Description: Library to store debug modules used in EFL 7Description: Library to store debug modules used in EFL
8Version: @PNGLIB_VERSION@ 8Version: @PNGLIB_VERSION@
9Libs: -L${libdir} -leolian_debug -leo_debug -levas_debug 9Libs: -L${libdir} -leolian_debug -leo_debug -levas_debug -lclouseau_debug
10Libs.private: @LIBS@ 10Libs.private: @LIBS@
11Cflags: -I${includedir} 11Cflags: -I${includedir}
12 12
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 79398e1..262bad3 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -13,6 +13,7 @@ include_directories(
13add_library(eolian_debug SHARED eolian_debug.c) 13add_library(eolian_debug SHARED eolian_debug.c)
14add_library(eo_debug SHARED eo_debug.c) 14add_library(eo_debug SHARED eo_debug.c)
15add_library(evas_debug SHARED evas_debug.c) 15add_library(evas_debug SHARED evas_debug.c)
16add_library(clouseau_debug SHARED clouseau_debug.c)
16 17
17target_link_libraries(eo_debug 18target_link_libraries(eo_debug
18 ${EINA_LIBRARIES} 19 ${EINA_LIBRARIES}
@@ -33,6 +34,11 @@ target_link_libraries(evas_debug
33 ${EVAS_LIBRARIES} 34 ${EVAS_LIBRARIES}
34 ) 35 )
35 36
37target_link_libraries(clouseau_debug
38 ${EINA_LIBRARIES}
39 ${EO_LIBRARIES}
40 )
41
36#INSTALL(FILES Eolian_Debug.h DESTINATION include/edebug) 42#INSTALL(FILES Eolian_Debug.h DESTINATION include/edebug)
37INSTALL(FILES Eo_Debug.h DESTINATION include/edebug) 43INSTALL(FILES Eo_Debug.h DESTINATION include/edebug)
38INSTALL(FILES Evas_Debug.h DESTINATION include/edebug) 44INSTALL(FILES Evas_Debug.h DESTINATION include/edebug)
@@ -40,3 +46,4 @@ INSTALL(FILES Evas_Debug.h DESTINATION include/edebug)
40INSTALL(TARGETS eo_debug LIBRARY DESTINATION lib) 46INSTALL(TARGETS eo_debug LIBRARY DESTINATION lib)
41INSTALL(TARGETS eolian_debug LIBRARY DESTINATION lib) 47INSTALL(TARGETS eolian_debug LIBRARY DESTINATION lib)
42INSTALL(TARGETS evas_debug LIBRARY DESTINATION lib) 48INSTALL(TARGETS evas_debug LIBRARY DESTINATION lib)
49INSTALL(TARGETS clouseau_debug LIBRARY DESTINATION lib)
diff --git a/src/lib/clouseau_debug.c b/src/lib/clouseau_debug.c
new file mode 100644
index 0000000..0a92b08
--- /dev/null
+++ b/src/lib/clouseau_debug.c
@@ -0,0 +1,148 @@
1#define _GNU_SOURCE
2#include <dlfcn.h>
3
4#include <Eo.h>
5
6#ifdef EAPI
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef DEBUG_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif /* ! DLL_EXPORT */
17# else
18# define EAPI __declspec(dllimport)
19# endif /* ! DEBUG_BUILD */
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif /* ! _WIN32 */
31
32static int _snapshot_do_op = EINA_DEBUG_OPCODE_INVALID;
33static int _snapshot_done_op = EINA_DEBUG_OPCODE_INVALID;
34static int _klids_get_op = EINA_DEBUG_OPCODE_INVALID;
35static int _eoids_get_op = EINA_DEBUG_OPCODE_INVALID;
36static int _obj_info_op = EINA_DEBUG_OPCODE_INVALID;
37static int _snapshot_objs_get_op = EINA_DEBUG_OPCODE_INVALID;
38
39static Eina_Debug_Error
40_snapshot_do_cb(Eina_Debug_Session *session, int srcid, void *buffer, int size)
41{
42 char *buf = alloca(sizeof(Eina_Debug_Packet_Header) + size);
43 Eina_Debug_Packet_Header *hdr = (Eina_Debug_Packet_Header *)buf;
44
45 hdr->size = sizeof(Eina_Debug_Packet_Header);
46 hdr->cid = srcid;
47 hdr->thread_id = 0;
48 hdr->opcode = _klids_get_op;
49 eina_debug_dispatch(session, buf);
50
51 hdr->size = sizeof(Eina_Debug_Packet_Header) + size;
52 if (size) memcpy(buf + sizeof(Eina_Debug_Packet_Header), buffer, size);
53 hdr->thread_id = 0xFFFFFFFF;
54 hdr->opcode = _snapshot_objs_get_op;
55 eina_debug_dispatch(session, buf);
56
57 eina_debug_session_send(session, srcid, _snapshot_done_op, NULL, 0);
58 return EINA_DEBUG_OK;
59}
60
61typedef struct
62{
63 Eina_Debug_Session *session;
64 char *buf;
65 uint64_t *kls;
66 int nb_kls;
67} _EoIds_Walk_Data;
68
69static Eina_Bool
70_eoids_walk_cb(void *_data, Eo *obj)
71{
72 _EoIds_Walk_Data *data = _data;
73 int i;
74 Eina_Bool klass_ok = EINA_FALSE;
75
76 for (i = 0; i < data->nb_kls && !klass_ok; i++)
77 {
78 if (efl_isa(obj, (Efl_Class *)data->kls[i])) klass_ok = EINA_TRUE;
79 }
80 if (!klass_ok && data->nb_kls) return EINA_TRUE;
81
82 uint64_t u64 = (uint64_t)obj;
83 memcpy(data->buf + sizeof(Eina_Debug_Packet_Header), &u64, sizeof(u64));
84 eina_debug_dispatch(data->session, data->buf);
85
86 return EINA_TRUE;
87}
88
89static Eina_Debug_Error
90_snapshot_objs_get_req_cb(Eina_Debug_Session *session, int srcid, void *buffer, int size)
91{
92 static Eina_Bool (*foo)(Eo_Debug_Object_Iterator_Cb, void *) = NULL;
93 _EoIds_Walk_Data data;
94
95 char *buf = alloca(sizeof(Eina_Debug_Packet_Header) + size);
96 Eina_Debug_Packet_Header *hdr = (Eina_Debug_Packet_Header *)buf;
97
98 hdr->size = sizeof(Eina_Debug_Packet_Header) + size;
99 if (size) memcpy(buf + sizeof(Eina_Debug_Packet_Header), buffer, size);
100 hdr->cid = srcid;
101 hdr->thread_id = 0;
102 hdr->opcode = _eoids_get_op;
103 eina_debug_dispatch(session, buf);
104
105 hdr->size = sizeof(Eina_Debug_Packet_Header) + sizeof(uint64_t);
106 hdr->cid = srcid;
107 hdr->thread_id = 0;
108 hdr->opcode = _obj_info_op;
109
110 data.session = session;
111 data.buf = buf;
112 data.kls = buffer;
113 data.nb_kls = size / sizeof(uint64_t);
114 if (!foo) foo = dlsym(RTLD_DEFAULT, "eo_debug_objects_iterate");
115 foo(_eoids_walk_cb, &data);
116
117 return EINA_DEBUG_OK;
118}
119
120static const Eina_Debug_Opcode _debug_ops[] =
121{
122 {"Clouseau/snapshot_do", &_snapshot_do_op, &_snapshot_do_cb},
123 {"Clouseau/snapshot/objs_get", &_snapshot_objs_get_op, &_snapshot_objs_get_req_cb},
124 {"Clouseau/snapshot_done", &_snapshot_done_op, NULL},
125 {"Eo/classes_ids_get", &_klids_get_op, NULL},
126 {"Eo/objects_ids_get", &_eoids_get_op, NULL},
127 {"Eolian/object/info_get", &_obj_info_op, NULL},
128 {NULL, NULL, NULL}
129};
130
131EAPI Eina_Bool
132clouseau_debug_init(void)
133{
134 eina_init();
135
136 eina_debug_opcodes_register(NULL, _debug_ops, NULL);
137
138 printf("%s - In\n", __FUNCTION__);
139 return EINA_TRUE;
140}
141
142EAPI Eina_Bool
143clouseau_debug_shutdown(void)
144{
145 eina_shutdown();
146
147 return EINA_TRUE;
148}