summaryrefslogtreecommitdiff
path: root/src/lib/eo
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-07-14 15:57:36 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-08-04 10:24:03 +0900
commitc4769ff8989bab2b745017b843f073e5737e91e0 (patch)
tree604752c6183f7615cacf5be15fdab1a947549fb9 /src/lib/eo
parent0834511067a99faafc2c59f0aabcd58dab1cbc0b (diff)
eo: Add debug_name read-only property to ease debugging
This will include the following information, by default: - class name - whether the class is an override - eo id (pointer) - refcount - name if one was set (Efl.Object property) This also supports classes, which is why it's an EAPI in eo.c and not only a method of Efl.Object This can be overriden by subclasses using the empty method Efl.Object.debug_name_override.get If the function is overriden, then the returned string is used as is and so it is left to the subclass to include all the necessary information (as above). This can easily be achieved by calling efl_debug_name_get(efl_super()) and then concatenating the strings. Think of this function as something like Java's toString(), but only for debugging (i.e. a string class should not just return its string value). @feature
Diffstat (limited to 'src/lib/eo')
-rw-r--r--src/lib/eo/Eo.h17
-rw-r--r--src/lib/eo/efl_object.eo10
-rw-r--r--src/lib/eo/eo.c61
-rw-r--r--src/lib/eo/eo_base_class.c6
-rw-r--r--src/lib/eo/eo_ptr_indirection.h2
5 files changed, 95 insertions, 1 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 44610e410c..16617e9dfd 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -691,6 +691,23 @@ EAPI Eina_Bool efl_isa(const Eo *obj, const Efl_Class *klass);
691EAPI const char *efl_class_name_get(const Efl_Class *klass); 691EAPI const char *efl_class_name_get(const Efl_Class *klass);
692 692
693/** 693/**
694 * @brief Gets a debug name for this object
695 * @param obj_id The object (or class)
696 * @return A name to use in logs and for other debugging purposes
697 *
698 * Note that subclasses can override Efl.Object "debug_name_override" to
699 * provide more meaningful debug strings. The standard format includes the
700 * class name, the object ID (this @p obj_id), the reference count and
701 * optionally the object name (as defined by Efl.Object.name).
702 *
703 * This might return a temporary string, as created by eina_slstr, which means
704 * that a main loop should probably be running.
705 *
706 * @since 1.21
707 */
708EAPI const char *efl_debug_name_get(const Eo *obj_id);
709
710/**
694 * @} 711 * @}
695 */ 712 */
696 713
diff --git a/src/lib/eo/efl_object.eo b/src/lib/eo/efl_object.eo
index 33188756f5..31861a61c9 100644
--- a/src/lib/eo/efl_object.eo
+++ b/src/lib/eo/efl_object.eo
@@ -81,6 +81,16 @@ abstract Efl.Object ()
81 comment: string @nullable; [[The comment]] 81 comment: string @nullable; [[The comment]]
82 } 82 }
83 } 83 }
84 @property debug_name_override {
85 [[ A read-only name for this object used for debugging.
86
87 @since 1.21
88 ]]
89 get {}
90 values {
91 name: string; [[A name including class name and object name.]]
92 }
93 }
84 @property event_global_freeze_count @class { 94 @property event_global_freeze_count @class {
85 get { 95 get {
86 [[Return freeze events of object. 96 [[Return freeze events of object.
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 50ddddd8de..72db1dd0a9 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -2476,6 +2476,67 @@ err:
2476 return EINA_FALSE; 2476 return EINA_FALSE;
2477} 2477}
2478 2478
2479EAPI const char *
2480efl_debug_name_get(const Eo *obj_id)
2481{
2482 const char *override = "";
2483 const char *name, *clsname, *ret;
2484
2485 if (!obj_id) return "(null)";
2486
2487 if (_eo_is_a_class(obj_id))
2488 {
2489 const char *clstype;
2490
2491 EO_CLASS_POINTER(obj_id, klass);
2492 if (!klass || !klass->desc)
2493 return eina_slstr_printf("Invalid_Class_ID(invalid)@%p", obj_id);
2494
2495 switch (klass->desc->type)
2496 {
2497 case EFL_CLASS_TYPE_REGULAR: clstype = "regular"; break;
2498 case EFL_CLASS_TYPE_REGULAR_NO_INSTANT: clstype = "abstract"; break;
2499 case EFL_CLASS_TYPE_INTERFACE: clstype = "interface"; break;
2500 case EFL_CLASS_TYPE_MIXIN: clstype = "mixin"; break;
2501 default: clstype = "invalid"; break;
2502 }
2503
2504 return eina_slstr_printf("%s(%s)@%p", klass->desc->name, clstype, obj_id);
2505 }
2506
2507 EO_OBJ_POINTER(obj_id, obj);
2508 if (!obj) return eina_slstr_printf("Invalid_Object_ID@%p", obj_id);
2509
2510 if (!obj->cur_klass)
2511 {
2512 ret = efl_debug_name_override_get(obj_id);
2513 if (ret) goto end;
2514 }
2515 else
2516 {
2517 if (obj->super)
2518 ret = efl_debug_name_override_get(efl_super(obj_id, (Efl_Class *) obj->cur_klass->header.id));
2519 else
2520 ret = efl_debug_name_override_get(efl_cast(obj_id, (Efl_Class *) obj->cur_klass->header.id));
2521 obj->super = EINA_FALSE;
2522 obj->cur_klass = NULL;
2523 if (ret) goto end;
2524 }
2525
2526 name = efl_name_get(obj_id);
2527 clsname = obj->klass->desc->name;
2528 if (_obj_is_override(obj)) override = "(override)";
2529
2530 if (name)
2531 ret = eina_slstr_printf("%s%s@%p[%d]:'%s'", clsname, override, obj_id, (int) obj->refcount, name);
2532 else
2533 ret = eina_slstr_printf("%s%s@%p[%d]", clsname, override, obj_id, (int) obj->refcount);
2534
2535end:
2536 EO_OBJ_DONE(obj_id);
2537 return ret;
2538}
2539
2479EAPI int 2540EAPI int
2480efl_callbacks_cmp(const Efl_Callback_Array_Item *a, const Efl_Callback_Array_Item *b) 2541efl_callbacks_cmp(const Efl_Callback_Array_Item *a, const Efl_Callback_Array_Item *b)
2481{ 2542{
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 6d05aed81d..ceea2261bb 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -572,6 +572,12 @@ _efl_object_comment_get(Eo *obj EINA_UNUSED, Efl_Object_Data *pd)
572 return pd->ext->comment; 572 return pd->ext->comment;
573} 573}
574 574
575EOLIAN static const char *
576_efl_object_debug_name_override_get(Eo *obj_id EINA_UNUSED, Efl_Object_Data *pd EINA_UNUSED)
577{
578 return NULL;
579}
580
575EOLIAN static void 581EOLIAN static void
576_efl_object_del(const Eo *obj, Efl_Object_Data *pd EINA_UNUSED) 582_efl_object_del(const Eo *obj, Efl_Object_Data *pd EINA_UNUSED)
577{ 583{
diff --git a/src/lib/eo/eo_ptr_indirection.h b/src/lib/eo/eo_ptr_indirection.h
index c0aaff8089..9cde5ba0c2 100644
--- a/src/lib/eo/eo_ptr_indirection.h
+++ b/src/lib/eo/eo_ptr_indirection.h
@@ -69,7 +69,7 @@ void _eo_pointer_error(const Eo *obj_id, const char *func_name, const char *file
69#define EO_CLASS_POINTER(klass_id, klass) \ 69#define EO_CLASS_POINTER(klass_id, klass) \
70 _Efl_Class *klass; \ 70 _Efl_Class *klass; \
71 do { \ 71 do { \
72 klass = _eo_class_pointer_get(klass_id, __FUNCTION__, __FILE__, __LINE__); \ 72 klass = _eo_class_pointer_get(klass_id); \
73 } while (0) 73 } while (0)
74 74
75#define EO_CLASS_POINTER_PROXY(klass_id, klass) \ 75#define EO_CLASS_POINTER_PROXY(klass_id, klass) \