lib/ctf-ir/attributes.c: add logging
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 11 May 2017 05:12:04 +0000 (01:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:42 +0000 (12:57 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/ctf-ir/attributes.c

index b354951090de8fd0318bee31e23cfa1717258751..f945799663e75a107b13ff1b853010e5e59c3901 100644 (file)
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/values.h>
+#include <inttypes.h>
+
+#define BT_LOG_TAG "ATTRS"
+#include <babeltrace/lib-logging-internal.h>
 
 #define BT_CTF_ATTR_NAME_INDEX         0
 #define BT_CTF_ATTR_VALUE_INDEX                1
@@ -34,6 +38,8 @@
 BT_HIDDEN
 struct bt_value *bt_ctf_attributes_create(void)
 {
+       struct bt_value *attr_obj;
+
        /*
         * Attributes: array value object of array value objects, each one
         * containing two entries: a string value object (attributes
@@ -48,12 +54,22 @@ struct bt_value *bt_ctf_attributes_create(void)
         *         ["tracer_minor", 5]
         *     ]
         */
-       return bt_value_array_create();
+       BT_LOGD_STR("Creating attributes object.");
+       attr_obj = bt_value_array_create();
+       if (!attr_obj) {
+               BT_LOGE_STR("Failed to create array value.");
+       } else {
+               BT_LOGD("Created attributes object: addr=%p",
+                       attr_obj);
+       }
+
+       return attr_obj;
 }
 
 BT_HIDDEN
 void bt_ctf_attributes_destroy(struct bt_value *attr_obj)
 {
+       BT_LOGD("Destroying attributes object: addr=%p", attr_obj);
        bt_put(attr_obj);
 }
 
@@ -72,26 +88,31 @@ const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj,
        struct bt_value *attr_field_obj = NULL;
        struct bt_value *attr_field_name_obj = NULL;
 
-       if (!attr_obj || index < 0) {
+       if (!attr_obj) {
+               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
                goto end;
        }
 
        attr_field_obj = bt_value_array_get(attr_obj, index);
-
        if (!attr_field_obj) {
+               BT_LOGE("Cannot get attributes object's array value's element by index: "
+                       "value-addr=%p, index=%" PRIu64, attr_obj, index);
                goto end;
        }
 
        attr_field_name_obj = bt_value_array_get(attr_field_obj,
                BT_CTF_ATTR_NAME_INDEX);
-
        if (!attr_field_name_obj) {
+               BT_LOGE("Cannot get attribute array value's element by index: "
+                       "value-addr=%p, index=%" PRIu64, attr_field_obj,
+                       (uint64_t) BT_CTF_ATTR_NAME_INDEX);
                goto end;
        }
 
        rc = bt_value_string_get(attr_field_name_obj, &ret);
-
        if (rc) {
+               BT_LOGE("Cannot get raw value from string value: value-addr=%p",
+                       attr_field_name_obj);
                ret = NULL;
        }
 
@@ -108,18 +129,25 @@ struct bt_value *bt_ctf_attributes_get_field_value(struct bt_value *attr_obj,
        struct bt_value *value_obj = NULL;
        struct bt_value *attr_field_obj = NULL;
 
-       if (!attr_obj || index < 0) {
+       if (!attr_obj) {
+               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
                goto end;
        }
 
        attr_field_obj = bt_value_array_get(attr_obj, index);
-
        if (!attr_field_obj) {
+               BT_LOGE("Cannot get attributes object's array value's element by index: "
+                       "value-addr=%p, index=%" PRIu64, attr_obj, index);
                goto end;
        }
 
        value_obj = bt_value_array_get(attr_field_obj,
                BT_CTF_ATTR_VALUE_INDEX);
+       if (!value_obj) {
+               BT_LOGE("Cannot get attribute array value's element by index: "
+                       "value-addr=%p, index=%" PRIu64, attr_field_obj,
+                       (uint64_t) BT_CTF_ATTR_VALUE_INDEX);
+       }
 
 end:
        BT_PUT(attr_field_obj);
@@ -136,8 +164,9 @@ struct bt_value *bt_ctf_attributes_get_field_by_name(
        struct bt_value *attr_field_name_obj = NULL;
 
        attr_size = bt_value_array_size(attr_obj);
-
        if (attr_size < 0) {
+               BT_LOGE("Cannot get array value's size: value-addr=%p",
+                       attr_obj);
                goto error;
        }
 
@@ -146,19 +175,24 @@ struct bt_value *bt_ctf_attributes_get_field_by_name(
                const char *field_name;
 
                value_obj = bt_value_array_get(attr_obj, i);
-
                if (!value_obj) {
+                       BT_LOGE("Cannot get attributes object's array value's element by index: "
+                               "value-addr=%p, index=%" PRIu64, attr_obj, i);
                        goto error;
                }
 
                attr_field_name_obj = bt_value_array_get(value_obj, 0);
-
                if (!attr_field_name_obj) {
+                       BT_LOGE("Cannot get attribute array value's element by index: "
+                               "value-addr=%p, index=%" PRIu64,
+                               value_obj, 0);
                        goto error;
                }
 
                ret = bt_value_string_get(attr_field_name_obj, &field_name);
                if (ret) {
+                       BT_LOGE("Cannot get raw value from string value: value-addr=%p",
+                               attr_field_name_obj);
                        goto error;
                }
 
@@ -188,12 +222,14 @@ int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj,
        struct bt_value *attr_field_obj = NULL;
 
        if (!attr_obj || !name || !value_obj) {
+               BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: "
+                       "attr-value-addr=%p, name-addr=%p, value-addr=%p",
+                       attr_obj, name, value_obj);
                ret = -1;
                goto end;
        }
 
        attr_field_obj = bt_ctf_attributes_get_field_by_name(attr_obj, name);
-
        if (attr_field_obj) {
                ret = bt_value_array_set(attr_field_obj,
                        BT_CTF_ATTR_VALUE_INDEX, value_obj);
@@ -201,20 +237,26 @@ int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj,
        }
 
        attr_field_obj = bt_value_array_create();
-
        if (!attr_field_obj) {
+               BT_LOGE_STR("Failed to create empty array value.");
                ret = -1;
                goto end;
        }
 
        ret = bt_value_array_append_string(attr_field_obj, name);
        ret |= bt_value_array_append(attr_field_obj, value_obj);
-
        if (ret) {
+               BT_LOGE("Cannot append elements to array value: addr=%p",
+                       attr_field_obj);
                goto end;
        }
 
        ret = bt_value_array_append(attr_obj, attr_field_obj);
+       if (ret) {
+               BT_LOGE("Cannot append element to array value: "
+                       "array-value-addr=%p, element-value-addr=%p",
+                       attr_obj, attr_field_obj);
+       }
 
 end:
        BT_PUT(attr_field_obj);
@@ -230,17 +272,25 @@ struct bt_value *bt_ctf_attributes_get_field_value_by_name(
        struct bt_value *attr_field_obj = NULL;
 
        if (!attr_obj || !name) {
+               BT_LOGW("Invalid parameter: attributes object or name is NULL: "
+                       "value-addr=%p, name-addr=%p", attr_obj, name);
                goto end;
        }
 
        attr_field_obj = bt_ctf_attributes_get_field_by_name(attr_obj, name);
-
        if (!attr_field_obj) {
+               BT_LOGD("Cannot find attributes object's field by name: "
+                       "value-addr=%p, name=\"%s\"", attr_obj, name);
                goto end;
        }
 
        value_obj = bt_value_array_get(attr_field_obj,
                BT_CTF_ATTR_VALUE_INDEX);
+       if (!value_obj) {
+               BT_LOGE("Cannot get attribute array value's element by index: "
+                       "value-addr=%p, index=%" PRIu64, attr_field_obj,
+                       (uint64_t) BT_CTF_ATTR_VALUE_INDEX);
+       }
 
 end:
        BT_PUT(attr_field_obj);
@@ -256,13 +306,16 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj)
        int ret = 0;
 
        if (!attr_obj) {
+               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
                ret = -1;
                goto end;
        }
 
+       BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj);
        count = bt_value_array_size(attr_obj);
-
        if (count < 0) {
+               BT_LOGE("Cannot get array value's size: value-addr=%p",
+                       attr_obj);
                ret = -1;
                goto end;
        }
@@ -276,8 +329,10 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj)
                struct bt_value *obj = NULL;
 
                obj = bt_ctf_attributes_get_field_value(attr_obj, i);
-
                if (!obj) {
+                       BT_LOGE("Cannot get attributes object's field value by index: "
+                               "value-addr=%p, index=%" PRIu64,
+                               attr_obj, i);
                        ret = -1;
                        goto end;
                }
This page took 0.02672 seconds and 4 git commands to generate.