lib: use BT_LIB_LOG*_APPEND_CAUSE() where appropriate
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 21 Jun 2019 18:17:29 +0000 (14:17 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 6 Jul 2019 03:47:50 +0000 (23:47 -0400)
Use BT_LIB_LOGE_APPEND_CAUSE() or BT_LIB_LOGW_APPEND_CAUSE() where
appropriate, that is, where a public library function eventually fails
(returns an error status code or `NULL` for a creation function).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I86f8588accfdd7e0c8b69e3977d214d30ccbd67d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1618
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
43 files changed:
src/lib/graph/component-class-sink-colander.c
src/lib/graph/component-class.c
src/lib/graph/component-filter.c
src/lib/graph/component-sink.c
src/lib/graph/component-source.c
src/lib/graph/component.c
src/lib/graph/connection.c
src/lib/graph/graph.c
src/lib/graph/graph.h
src/lib/graph/iterator.c
src/lib/graph/message/discarded-items.c
src/lib/graph/message/event.c
src/lib/graph/message/message-iterator-inactivity.c
src/lib/graph/message/message.h
src/lib/graph/message/packet.c
src/lib/graph/message/stream-activity.c
src/lib/graph/message/stream.c
src/lib/graph/port.c
src/lib/graph/query-executor.c
src/lib/object-pool.c
src/lib/plugin/plugin-so.c
src/lib/plugin/plugin.c
src/lib/plugin/plugin.h
src/lib/trace-ir/attributes.c
src/lib/trace-ir/clock-class.c
src/lib/trace-ir/clock-snapshot-set.h
src/lib/trace-ir/clock-snapshot.c
src/lib/trace-ir/event-class.c
src/lib/trace-ir/event.c
src/lib/trace-ir/event.h
src/lib/trace-ir/field-class.c
src/lib/trace-ir/field-path.c
src/lib/trace-ir/field-wrapper.c
src/lib/trace-ir/field.c
src/lib/trace-ir/packet-context-field.c
src/lib/trace-ir/packet.c
src/lib/trace-ir/stream-class.c
src/lib/trace-ir/stream.c
src/lib/trace-ir/trace-class.c
src/lib/trace-ir/trace.c
src/lib/value.c
src/python-plugin-provider/Makefile.am
src/python-plugin-provider/python-plugin-provider.c

index b1c4ee70f0d310c3b4dd0b7d576fe723335d9327..771c626885931c54759354edbd02f46d7da58dd9 100644 (file)
@@ -53,7 +53,8 @@ enum bt_component_class_init_method_status colander_init(
        colander_data = g_new0(
                struct bt_component_class_sink_colander_priv_data, 1);
        if (!colander_data) {
-               BT_LOGE_STR("Failed to allocate colander data.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate colander sink data.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -63,7 +64,8 @@ enum bt_component_class_init_method_status colander_init(
        status = bt_self_component_sink_add_input_port(self_comp, "in",
                NULL, NULL);
        if (status != BT_FUNC_STATUS_OK) {
-               BT_LOGE_STR("Cannot add input port.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot add input port to colander sink.");
                goto end;
        }
 
@@ -111,7 +113,7 @@ colander_graph_is_configured(
                bt_self_component_port_input_message_iterator_create(
                        self_port);
        if (!colander_data->msg_iter) {
-               BT_LIB_LOGE("Cannot create message iterator on "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create message iterator on "
                        "self component input port: %![port-]+p",
                        self_port);
                status = BT_FUNC_STATUS_MEMORY_ERROR;
@@ -169,7 +171,8 @@ struct bt_component_class_sink *bt_component_class_sink_colander_get(void)
        colander_comp_cls = bt_component_class_sink_create("colander",
                colander_consume);
        if (!colander_comp_cls) {
-               BT_LOGE_STR("Cannot create sink colander component class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create sink colander component class.");
                goto end;
        }
 
index d17dbd4c1c5192fdb22a837351b3eddfb83280f5..643c6a35807d37513da960b0c8a32392d5296fc0 100644 (file)
@@ -106,32 +106,32 @@ int bt_component_class_init(struct bt_component_class *class,
        class->type = type;
        class->name = g_string_new(name);
        if (!class->name) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        class->description = g_string_new(NULL);
        if (!class->description) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        class->help = g_string_new(NULL);
        if (!class->help) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        class->plugin_name = g_string_new(NULL);
        if (!class->plugin_name) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        class->destroy_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_component_class_destroy_listener));
        if (!class->destroy_listeners) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                goto error;
        }
 
@@ -159,7 +159,8 @@ struct bt_component_class_source *bt_component_class_source_create(
                name, method);
        source_class = g_new0(struct bt_component_class_source, 1);
        if (!source_class) {
-               BT_LOGE_STR("Failed to allocate one source component class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one source component class.");
                goto end;
        }
 
@@ -197,7 +198,8 @@ struct bt_component_class_filter *bt_component_class_filter_create(
                name, method);
        filter_class = g_new0(struct bt_component_class_filter, 1);
        if (!filter_class) {
-               BT_LOGE_STR("Failed to allocate one filter component class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one filter component class.");
                goto end;
        }
 
@@ -234,7 +236,8 @@ struct bt_component_class_sink *bt_component_class_sink_create(
                name, method);
        sink_class = g_new0(struct bt_component_class_sink, 1);
        if (!sink_class) {
-               BT_LOGE_STR("Failed to allocate one sink component class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one sink component class.");
                goto end;
        }
 
index 5efff1ab75bb9ae3ca1babb38f1eaea99e464876..20f7929ec379efe39797a14b779855fdf6502a23 100644 (file)
@@ -50,7 +50,8 @@ struct bt_component *bt_component_filter_create(
 
        filter = g_new0(struct bt_component_filter, 1);
        if (!filter) {
-               BT_LOGE_STR("Failed to allocate one filter component.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one filter component.");
                goto end;
        }
 
index 669e15dffe9b84a5c21339cd13b26f2345142669..9c66bda7932b1f2ea30c6da8fef05ea4cd60dd79 100644 (file)
@@ -49,7 +49,8 @@ struct bt_component *bt_component_sink_create(
 
        sink = g_new0(struct bt_component_sink, 1);
        if (!sink) {
-               BT_LOGE_STR("Failed to allocate one sink component.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one sink component.");
                goto end;
        }
 
index e62c5bd1aad9508a54d2f365886bdcd35c813812..e81a143aec4c3f79b11f3f8d6a7fb5271acf1cd7 100644 (file)
@@ -50,7 +50,8 @@ struct bt_component *bt_component_source_create(
 
        source = g_new0(struct bt_component_source, 1);
        if (!source) {
-               BT_LOGE_STR("Failed to allocate one source component.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one source component.");
                goto end;
        }
 
index 24d7deded596ae5d9ab50e4567702a3f45825250..0d13566a2a8231e561072291c6c39949eea63269 100644 (file)
@@ -224,7 +224,7 @@ enum bt_self_component_add_port_status add_port(
 
        new_port = bt_port_create(component, port_type, name, user_data);
        if (!new_port) {
-               BT_LOGE_STR("Cannot create port object.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create port object.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -302,7 +302,8 @@ int bt_component_create(struct bt_component_class *component_class,
                bt_common_logging_level_string(log_level));
        component = component_create_funcs[type](component_class);
        if (!component) {
-               BT_LOGE_STR("Cannot create specific component object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create specific component object.");
                ret = -1;
                goto end;
        }
@@ -313,7 +314,7 @@ int bt_component_create(struct bt_component_class *component_class,
        component->destroy = component_destroy_funcs[type];
        component->name = g_string_new(name);
        if (!component->name) {
-               BT_LOGE_STR("Failed to allocate one GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
                ret = -1;
                goto end;
        }
@@ -322,7 +323,7 @@ int bt_component_create(struct bt_component_class *component_class,
        component->input_ports = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!component->input_ports) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -330,7 +331,7 @@ int bt_component_create(struct bt_component_class *component_class,
        component->output_ports = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!component->output_ports) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -338,7 +339,7 @@ int bt_component_create(struct bt_component_class *component_class,
        component->destroy_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_component_destroy_listener));
        if (!component->destroy_listeners) {
-               BT_LOGE_STR("Failed to allocate one GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray.");
                ret = -1;
                goto end;
        }
index 4fa97a40f7fb012fc1aed5ab8ff8c8653da43a7d..41fbcc6984cb877009bc2d710af1d91b2329fc60 100644 (file)
@@ -126,7 +126,7 @@ struct bt_connection *bt_connection_create(struct bt_graph *graph,
                graph, upstream_port, downstream_port);
        connection = g_new0(struct bt_connection, 1);
        if (!connection) {
-               BT_LOGE_STR("Failed to allocate one connection.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one connection.");
                goto end;
        }
 
@@ -136,7 +136,7 @@ struct bt_connection *bt_connection_create(struct bt_graph *graph,
                parent_is_owner);
        connection->iterators = g_ptr_array_new();
        if (!connection->iterators) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                BT_OBJECT_PUT_REF_AND_RESET(connection);
                goto end;
        }
index deb7a11527b2ee74191edda2871e0472d19634ce..cf112fbd8393907c0f7a8f5637188fadeec0f606 100644 (file)
@@ -78,7 +78,8 @@ struct bt_graph_listener_ports_connected {
        do {                                                            \
                _listeners = g_array_new(FALSE, TRUE, sizeof(_type));   \
                if (!(_listeners)) {                                    \
-                       BT_LOGE_STR("Failed to allocate one GArray.");  \
+                       BT_LIB_LOGE_APPEND_CAUSE(                       \
+                               "Failed to allocate one GArray.");      \
                }                                                       \
        } while (0)
 
@@ -264,7 +265,7 @@ struct bt_graph *bt_graph_create(void)
        BT_LOGI_STR("Creating graph object.");
        graph = g_new0(struct bt_graph, 1);
        if (!graph) {
-               BT_LOGE_STR("Failed to allocate one graph.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one graph.");
                goto end;
        }
 
@@ -272,18 +273,18 @@ struct bt_graph *bt_graph_create(void)
        graph->connections = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!graph->connections) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                goto error;
        }
        graph->components = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!graph->components) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                goto error;
        }
        graph->sinks_to_consume = g_queue_new();
        if (!graph->sinks_to_consume) {
-               BT_LOGE_STR("Failed to allocate one GQueue.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GQueue.");
                goto error;
        }
 
@@ -357,7 +358,8 @@ struct bt_graph *bt_graph_create(void)
                (bt_object_pool_destroy_object_func) destroy_message_event,
                graph);
        if (ret) {
-               BT_LOGE("Failed to initialize event message pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize event message pool: ret=%d",
                        ret);
                goto error;
        }
@@ -367,7 +369,8 @@ struct bt_graph *bt_graph_create(void)
                (bt_object_pool_destroy_object_func) destroy_message_packet_begin,
                graph);
        if (ret) {
-               BT_LOGE("Failed to initialize packet beginning message pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize packet beginning message pool: ret=%d",
                        ret);
                goto error;
        }
@@ -377,7 +380,8 @@ struct bt_graph *bt_graph_create(void)
                (bt_object_pool_destroy_object_func) destroy_message_packet_end,
                graph);
        if (ret) {
-               BT_LOGE("Failed to initialize packet end message pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize packet end message pool: ret=%d",
                        ret);
                goto error;
        }
@@ -441,7 +445,7 @@ enum bt_graph_connect_ports_status bt_graph_connect_ports(
        connection = bt_connection_create(graph, (void *) upstream_port,
                (void *) downstream_port);
        if (!connection) {
-               BT_LOGW("Cannot create connection object.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create connection object.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -462,12 +466,17 @@ enum bt_graph_connect_ports_status bt_graph_connect_ports(
        port_connected_status = bt_component_port_connected(upstream_component,
                (void *) upstream_port, (void *) downstream_port);
        if (port_connected_status != BT_FUNC_STATUS_OK) {
-               BT_LIB_LOGW("Error while notifying upstream component that its port is connected: "
-                       "status=%s, %![graph-]+g, %![up-comp-]+c, "
-                       "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
-                       bt_common_func_status_string(port_connected_status),
-                       graph, upstream_component, downstream_component,
-                       upstream_port, downstream_port);
+               if (port_connected_status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Upstream component's \"port connected\" method failed: "
+                               "status=%s, %![graph-]+g, %![up-comp-]+c, "
+                               "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
+                               bt_common_func_status_string(
+                                       port_connected_status),
+                               graph, upstream_component, downstream_component,
+                               upstream_port, downstream_port);
+               }
+
                bt_connection_end(connection, true);
                status = (int) port_connected_status;
                goto end;
@@ -480,12 +489,17 @@ enum bt_graph_connect_ports_status bt_graph_connect_ports(
        port_connected_status = bt_component_port_connected(downstream_component,
                (void *) downstream_port, (void *) upstream_port);
        if (port_connected_status != BT_FUNC_STATUS_OK) {
-               BT_LIB_LOGW("Error while notifying downstream component that its port is connected: "
-                       "status=%s, %![graph-]+g, %![up-comp-]+c, "
-                       "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
-                       bt_common_func_status_string(port_connected_status),
-                       graph, upstream_component, downstream_component,
-                       upstream_port, downstream_port);
+               if (port_connected_status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Downstream component's \"port connected\" method failed: "
+                               "status=%s, %![graph-]+g, %![up-comp-]+c, "
+                               "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
+                               bt_common_func_status_string(
+                                       port_connected_status),
+                               graph, upstream_component, downstream_component,
+                               upstream_port, downstream_port);
+               }
+
                bt_connection_end(connection, true);
                status = (int) port_connected_status;
                goto end;
@@ -499,6 +513,16 @@ enum bt_graph_connect_ports_status bt_graph_connect_ports(
        BT_LOGD_STR("Notifying graph's user that new component ports are connected.");
        listener_status = bt_graph_notify_ports_connected(graph, upstream_port, downstream_port);
        if (listener_status != BT_FUNC_STATUS_OK) {
+               if (listener_status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Graph \"ports connected\" listener failed: "
+                               "status=%d, %![graph-]+g, %![up-comp-]+c, "
+                               "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
+                               listener_status, graph,
+                               upstream_component, downstream_component,
+                               upstream_port, downstream_port);
+               }
+
                status = (int) listener_status;
                goto end;
        }
@@ -547,8 +571,15 @@ int consume_graph_sink(struct bt_component_sink *comp)
                consume_status == BT_FUNC_STATUS_MEMORY_ERROR,
                "Invalid component status returned by consuming method: "
                "status=%s", bt_common_func_status_string(consume_status));
-       if (consume_status < 0) {
-               BT_LOGW_STR("Consume method failed.");
+       if (consume_status) {
+               if (consume_status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Component's \"consume\" method failed: "
+                               "status=%s, %![comp-]+c",
+                               bt_common_func_status_string(consume_status),
+                               comp);
+               }
+
                goto end;
        }
 
@@ -1264,7 +1295,8 @@ int add_component_with_init_method_data(
        if (!params) {
                new_params = bt_value_map_create();
                if (!new_params) {
-                       BT_LOGE_STR("Cannot create empty map value object.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create empty map value object.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -1274,7 +1306,8 @@ int add_component_with_init_method_data(
 
        ret = bt_component_create(comp_cls, name, log_level, &component);
        if (ret) {
-               BT_LOGE("Cannot create empty component object: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create empty component object: ret=%d",
                        ret);
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
@@ -1295,8 +1328,14 @@ int add_component_with_init_method_data(
                BT_LOGD("User method returned: status=%s",
                        bt_common_func_status_string(init_status));
                if (init_status != BT_FUNC_STATUS_OK) {
-                       BT_LIB_LOGW("Component initialization method failed: "
-                               "%!+c", component);
+                       if (init_status < 0) {
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Component initialization method failed: "
+                                       "status=%s, %![comp-]+c",
+                                       bt_common_func_status_string(init_status),
+                                       component);
+                       }
+
                        status = init_status;
                        bt_component_set_graph(component, NULL);
                        g_ptr_array_remove_fast(graph->components, component);
@@ -1449,7 +1488,8 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph,
                BT_ASSERT(port);
 
                if (bt_port_is_connected(port)) {
-                       BT_LIB_LOGW("Cannot remove component from graph: "
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot remove component from graph: "
                                "an input port is connected: "
                                "%![graph-]+g, %![comp-]+c, %![port-]+p",
                                graph, component, port);
@@ -1466,7 +1506,8 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph,
                BT_ASSERT(port);
 
                if (bt_port_is_connected(port)) {
-                       BT_LIB_LOGW("Cannot remove component from graph: "
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot remove component from graph: "
                                "an output port is connected: "
                                "%![graph-]+g, %![comp-]+c, %![port-]+p",
                                graph, component, port);
index 30d59fb9d7e40eac63634884d7f8a7df8f21b956..ef847361e16dcd352b10abf12f3444bedcb6afb1 100644 (file)
  * SOFTWARE.
  */
 
+/* Protection: this file uses BT_LIB_LOG*() macros directly */
+#ifndef BT_LIB_LOG_SUPPORTED
+# error Please include "lib/logging.h" before including this file.
+#endif
+
 #include <babeltrace2/graph/graph.h>
 #include <babeltrace2/graph/message-const.h>
 #include "common/macros.h"
@@ -246,13 +251,18 @@ int bt_graph_configure(struct bt_graph *graph)
                                comp_status == BT_FUNC_STATUS_MEMORY_ERROR,
                                "Unexpected returned status: status=%s",
                                bt_common_func_status_string(comp_status));
-
                        if (comp_status != BT_FUNC_STATUS_OK) {
-                               status = BT_FUNC_STATUS_ERROR;
-                               BT_LIB_LOGW("User's \"graph is configured\" method failed: "
-                                       "%![comp-]+c, status=%s",
-                                       comp, bt_common_func_status_string(
-                                               comp_status));
+                               comp_status = BT_FUNC_STATUS_ERROR;
+                               if (comp_status < 0) {
+                                       BT_LIB_LOGW_APPEND_CAUSE(
+                                               "Component's \"graph is configured\" method failed: "
+                                               "%![comp-]+c, status=%s",
+                                               comp,
+                                               bt_common_func_status_string(
+                                                       comp_status));
+                               }
+
+                               status = comp_status;
                                goto end;
                        }
                }
index 86d7a1e414952ffda32415fbfa9d0d7c1d0eb944..2e2ab405667e684768928df02cffff6b3d3ec67a 100644 (file)
@@ -192,7 +192,7 @@ void bt_self_component_port_input_message_iterator_try_finalize(
                        "%!+i", iterator);
                goto end;
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING:
-               /* Already finalized */
+               /* Finalizing */
                BT_LIB_LOGF("Message iterator is already being finalized: "
                        "%!+i", iterator);
                abort();
@@ -267,7 +267,7 @@ int init_message_iterator(struct bt_message_iterator *iterator,
        iterator->type = type;
        iterator->msgs = g_ptr_array_new();
        if (!iterator->msgs) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -314,9 +314,10 @@ bt_self_component_port_input_message_iterator_create_initial(
        iterator = g_new0(
                struct bt_self_component_port_input_message_iterator, 1);
        if (!iterator) {
-               BT_LOGE_STR("Failed to allocate one self component input port "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one self component input port "
                        "message iterator.");
-               goto end;
+               goto error;
        }
 
        ret = init_message_iterator((void *) iterator,
@@ -324,15 +325,14 @@ bt_self_component_port_input_message_iterator_create_initial(
                bt_self_component_port_input_message_iterator_destroy);
        if (ret) {
                /* init_message_iterator() logs errors */
-               BT_OBJECT_PUT_REF_AND_RESET(iterator);
-               goto end;
+               goto error;
        }
 
        iterator->last_ns_from_origin = INT64_MIN;
 
        iterator->auto_seek.msgs = g_queue_new();
        if (!iterator->auto_seek.msgs) {
-               BT_LOGE_STR("Failed to allocate a GQueue.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
                ret = -1;
                goto end;
        }
@@ -410,6 +410,10 @@ bt_self_component_port_input_message_iterator_create_initial(
        BT_LIB_LOGI("Created initial message iterator on self component input port: "
                "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
                upstream_port, upstream_comp, iterator);
+       goto end;
+
+error:
+       BT_OBJECT_PUT_REF_AND_RESET(iterator);
 
 end:
        return iterator;
@@ -458,9 +462,9 @@ bt_self_component_port_input_message_iterator_create(
        iterator = bt_self_component_port_input_message_iterator_create_initial(
                upstream_comp, upstream_port);
        if (!iterator) {
-               BT_LOGW_STR("Cannot create self component input port "
-                       "message iterator.");
-               goto end;
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create self component input port message iterator.");
+               goto error;
        }
 
        switch (upstream_comp_cls->type) {
@@ -496,9 +500,12 @@ bt_self_component_port_input_message_iterator_create(
                BT_LOGD("User method returned: status=%s",
                        bt_common_func_status_string(iter_status));
                if (iter_status != BT_FUNC_STATUS_OK) {
-                       BT_LOGW_STR("Initialization method failed.");
-                       BT_OBJECT_PUT_REF_AND_RESET(iterator);
-                       goto end;
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Component input port message iterator initialization method failed: "
+                               "%![iter-]+i, status=%s",
+                               iterator,
+                               bt_common_func_status_string(iter_status));
+                       goto error;
                }
        }
 
@@ -508,6 +515,10 @@ bt_self_component_port_input_message_iterator_create(
        BT_LIB_LOGI("Created message iterator on self component input port: "
                "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
                upstream_port, upstream_comp, iterator);
+       goto end;
+
+error:
+       BT_OBJECT_PUT_REF_AND_RESET(iterator);
 
 end:
        return iterator;
@@ -853,8 +864,13 @@ bt_self_component_port_input_message_iterator_next(
        status = (int) call_iterator_next_method(iterator,
                (void *) iterator->base.msgs->pdata, MSG_BATCH_SIZE,
                user_count);
+       BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64,
+               bt_common_func_status_string(status), *user_count);
        if (status < 0) {
-               BT_LOGW_STR("User method failed.");
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Component input port message iterator's \"next\" method failed: "
+                       "%![iter-]+i, status=%s",
+                       iterator, bt_common_func_status_string(status));
                goto end;
        }
 
@@ -1015,7 +1031,8 @@ bt_port_output_message_iterator_create(struct bt_graph *graph,
                "%![port-]+p, %![comp-]+c", output_port, output_port_comp);
        iterator = g_new0(struct bt_port_output_message_iterator, 1);
        if (!iterator) {
-               BT_LOGE_STR("Failed to allocate one output port message iterator.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one output port message iterator.");
                goto error;
        }
 
@@ -1031,7 +1048,9 @@ bt_port_output_message_iterator_create(struct bt_graph *graph,
        /* Create colander component */
        colander_comp_cls = bt_component_class_sink_colander_get();
        if (!colander_comp_cls) {
-               BT_LOGW("Cannot get colander sink component class.");
+               /* bt_component_class_sink_colander_get() logs errors */
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get colander sink component class.");
                goto error;
        }
 
@@ -1053,8 +1072,9 @@ bt_port_output_message_iterator_create(struct bt_graph *graph,
                        NULL, &colander_data, BT_LOGGING_LEVEL_NONE,
                        (void *) &iterator->colander);
        if (graph_status != BT_FUNC_STATUS_OK) {
-               BT_LIB_LOGW("Cannot add colander sink component to graph: "
-                       "%1[graph-]+g, status=%s", graph,
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot add colander sink component to graph: "
+                       "%![graph-]+g, status=%s", graph,
                        bt_common_func_status_string(graph_status));
                goto error;
        }
@@ -1070,7 +1090,8 @@ bt_port_output_message_iterator_create(struct bt_graph *graph,
        graph_status = bt_graph_connect_ports(graph,
                output_port, colander_in_port, NULL);
        if (graph_status != BT_FUNC_STATUS_OK) {
-               BT_LIB_LOGW("Cannot add colander sink component to graph: "
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Cannot connect colander sink's port: "
                        "%![graph-]+g, %![comp-]+c, status=%s", graph,
                        iterator->colander,
                        bt_common_func_status_string(graph_status));
@@ -1090,8 +1111,11 @@ bt_port_output_message_iterator_create(struct bt_graph *graph,
        /* Also set the graph as being configured. */
        graph_status = bt_graph_configure(graph);
        if (graph_status != BT_FUNC_STATUS_OK) {
-               BT_LIB_LOGW("Cannot configure graph after having added colander: "
-                       "%![graph-]+g, status=%s", graph,
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Cannot configure graph after having "
+                       "added and connected colander sink: "
+                       "%![graph-]+g, %![comp-]+c, status=%s", graph,
+                       iterator->colander,
                        bt_common_func_status_string(graph_status));
                goto error;
        }
@@ -1253,6 +1277,13 @@ bt_self_component_port_input_message_iterator_seek_beginning(
                status == BT_FUNC_STATUS_AGAIN,
                "Unexpected status: %![iter-]+i, status=%s",
                iterator, bt_common_func_status_string(status));
+       if (status < 0) {
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Component input port message iterator's \"seek beginning\" method failed: "
+                       "%![iter-]+i, status=%s",
+                       iterator, bt_common_func_status_string(status));
+       }
+
        set_iterator_state_after_seeking(iterator, status);
        return status;
 }
@@ -1661,6 +1692,14 @@ int find_message_ge_ns_from_origin(
                 */
                status = call_iterator_next_method(iterator,
                        &messages[0], MSG_BATCH_SIZE, &user_count);
+               BT_LOGD("User method returned: status=%s",
+                       bt_common_func_status_string(status));
+               if (status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Component input port message iterator's \"next\" method failed: "
+                               "%![iter-]+i, status=%s",
+                               iterator, bt_common_func_status_string(status));
+               }
 
                /*
                 * The user's "next" method must not do any action which
@@ -1811,6 +1850,12 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin(
                        status == BT_FUNC_STATUS_AGAIN,
                        "Unexpected status: %![iter-]+i, status=%s",
                        iterator, bt_common_func_status_string(status));
+               if (status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Component input port message iterator's \"seek nanoseconds from origin\" method failed: "
+                               "%![iter-]+i, status=%s",
+                               iterator, bt_common_func_status_string(status));
+               }
        } else {
                /*
                 * The iterator doesn't know how to seek to a particular time.  We will
@@ -1829,6 +1874,13 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin(
                        status == BT_FUNC_STATUS_AGAIN,
                        "Unexpected status: %![iter-]+i, status=%s",
                        iterator, bt_common_func_status_string(status));
+               if (status < 0) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Component input port message iterator's \"seek beginning\" method failed: "
+                               "%![iter-]+i, status=%s",
+                               iterator, bt_common_func_status_string(status));
+               }
+
                switch (status) {
                case BT_FUNC_STATUS_OK:
                        break;
@@ -1854,7 +1906,8 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin(
 
                stream_states = create_auto_seek_stream_states();
                if (!stream_states) {
-                       BT_LOGE_STR("Failed to allocate one GHashTable.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Failed to allocate one GHashTable.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -1884,7 +1937,9 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin(
                                uint64_t raw_value;
 
                                if (clock_raw_value_from_ns_from_origin(clock_class, ns_from_origin, &raw_value) != 0) {
-                                       BT_LIB_LOGW("Could not convert nanoseconds from origin to clock value: ns-from-origin=%" PRId64 ", %![cc-]+K",
+                                       BT_LIB_LOGW_APPEND_CAUSE(
+                                               "Could not convert nanoseconds from origin to clock value: "
+                                               "ns-from-origin=%" PRId64 ", %![cc-]+K",
                                                ns_from_origin, clock_class);
                                        status = BT_FUNC_STATUS_ERROR;
                                        goto end;
@@ -1976,6 +2031,7 @@ end:
                destroy_auto_seek_stream_states(stream_states);
                stream_states = NULL;
        }
+
        set_iterator_state_after_seeking(iterator, status);
        return status;
 }
index b38f8facc0e23e495a4e91033713ac5b48b023f2..1658b55a9d829bd3978a0f3f3c14c0f2ce62d62c 100644 (file)
@@ -113,7 +113,8 @@ struct bt_message *create_discarded_items_message(
                with_cs, beginning_raw_value, end_raw_value);
        message = g_new0(struct bt_message_discarded_items, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one discarded items message.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one discarded items message.");
                goto error;
        }
 
index 06370c0ba69cb502b8318e0debcb0f32ca98f28f..95b39605ca30bb74880815da5e0a7a20fbb8ed29 100644 (file)
@@ -62,7 +62,8 @@ struct bt_message *bt_message_event_new(
 
        message = g_new0(struct bt_message_event, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one event message.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one event message.");
                goto error;
        }
 
@@ -110,7 +111,8 @@ struct bt_message *create_event_message(
        BT_LIB_LOGD("Creating event message object: %![ec-]+E", event_class);
        event = bt_event_create(event_class, packet);
        if (G_UNLIKELY(!event)) {
-               BT_LIB_LOGE("Cannot create event from event class: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create event from event class: "
                        "%![ec-]+E", event_class);
                goto error;
        }
index f1b94dd0b5e204d40113f2e92ebe6e09bbff2c38..71afff63062d40d39a0a4050d8912a01eeb005b4 100644 (file)
@@ -68,7 +68,8 @@ struct bt_message *bt_message_message_iterator_inactivity_create(
                default_clock_class, value_cycles);
        message = g_new0(struct bt_message_message_iterator_inactivity, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one message iterator "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one message iterator "
                        "inactivity message.");
                goto error;
        }
index 88924995b3c7f6d3e16d5251efdef932cf4bb391..1df9c5204c41d5a6187ad6fef13ab2f9ba96634a 100644 (file)
  * SOFTWARE.
  */
 
+/* Protection: this file uses BT_LIB_LOG*() macros directly */
+#ifndef BT_LIB_LOG_SUPPORTED
+# error Please include "lib/logging.h" before including this file.
+#endif
+
 #include "common/macros.h"
 #include "lib/object.h"
 #include "common/assert.h"
@@ -79,7 +84,8 @@ struct bt_message *bt_message_create_from_pool(
        struct bt_message *msg = bt_object_pool_create_object(pool);
 
        if (G_UNLIKELY(!msg)) {
-               BT_LIB_LOGE("Cannot allocate one message from message pool: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one message from message pool: "
                        "%![pool-]+o, %![graph-]+g", pool, graph);
                goto error;
        }
index 13882395d610bf7f9a9c4e15052ccfc21ea08e9b..63471f6040c1e17fc62c634db45048fa1ced2d69 100644 (file)
@@ -52,7 +52,8 @@ struct bt_message *new_packet_message(struct bt_graph *graph,
 
        message = g_new0(struct bt_message_packet, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one packet message.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one packet message.");
                goto error;
        }
 
index 21275c1ffef6fd1a3fa8a5c33ea3913a56867f45..d9ef3e6bf7796bbdb75076ff6397fd5bd7eb8f65 100644 (file)
@@ -72,7 +72,8 @@ struct bt_message *create_stream_activity_message(
                bt_message_type_string(type), stream, stream_class);
        message = g_new0(struct bt_message_stream_activity, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one stream activity message.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one stream activity message.");
                goto error;
        }
 
index 44c1a2d9241f3c5106d1499270ef06883d927d5c..ff7d1c83730a40c2a78d20837ab80f2f06524fbd 100644 (file)
@@ -67,7 +67,8 @@ struct bt_message *create_stream_message(
                bt_message_type_string(type), stream, stream_class);
        message = g_new0(struct bt_message_stream, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one stream message.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one stream message.");
                goto error;
        }
 
index df7c84df7285f26abe6cc87c90ec6e8f22eb3682..d7455dca82afb1c6ce33185d04a277e9cc982c18 100644 (file)
@@ -66,7 +66,7 @@ struct bt_port *bt_port_create(struct bt_component *parent_component,
        BT_ASSERT(strlen(name) > 0);
        port = g_new0(struct bt_port, 1);
        if (!port) {
-               BT_LOGE_STR("Failed to allocate one port.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one port.");
                goto end;
        }
 
@@ -76,7 +76,7 @@ struct bt_port *bt_port_create(struct bt_component *parent_component,
        bt_object_init_shared_with_parent(&port->base, destroy_port);
        port->name = g_string_new(name);
        if (!port->name) {
-               BT_LOGE_STR("Failed to allocate one GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
                BT_OBJECT_PUT_REF_AND_RESET(port);
                goto end;
        }
index b3367b1a8f26b145bfc6e743606e272fa3e81953..5e13d52560e41f242016740272be0f1577462fbb 100644 (file)
@@ -56,7 +56,8 @@ struct bt_query_executor *bt_query_executor_create(void)
        BT_LOGD_STR("Creating query executor.");
        query_exec = g_new0(struct bt_query_executor, 1);
        if (!query_exec) {
-               BT_LOGE_STR("Failed to allocate one query executor.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one query executor.");
                goto end;
        }
 
index dda8b718f4827a4409190acf5a2626d8c23468a6..8d95a890bbda66dd7da0ab497be3cc7a527f2e00 100644 (file)
@@ -41,7 +41,7 @@ int bt_object_pool_initialize(struct bt_object_pool *pool,
                pool, data);
        pool->objects = g_ptr_array_new();
        if (!pool->objects) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
index 2ddecdb3729a3f9005502c67ca328466c5726e12..92f47825e72ed1bc6f556b60c86f955905f1f0f6 100644 (file)
@@ -139,6 +139,11 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj)
                        BT_LOGI("Closing GModule: path=\"%s\"", path);
 
                        if (!g_module_close(shared_lib_handle->module)) {
+                               /*
+                                * Just log here: we're in a destructor,
+                                * so we cannot append an error cause
+                                * (there's no returned status).
+                                */
                                BT_LOGE("Cannot close GModule: %s: path=\"%s\"",
                                        g_module_error(), path);
                        }
@@ -171,7 +176,7 @@ int bt_plugin_so_shared_lib_handle_create(
        BT_LOGI("Creating shared library handle: path=\"%s\"", path);
        *shared_lib_handle = g_new0(struct bt_plugin_so_shared_lib_handle, 1);
        if (!*shared_lib_handle) {
-               BT_LOGE_STR("Failed to allocate one shared library handle.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one shared library handle.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -185,7 +190,7 @@ int bt_plugin_so_shared_lib_handle_create(
 
        (*shared_lib_handle)->path = g_string_new(path);
        if (!(*shared_lib_handle)->path) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -342,7 +347,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
        comp_class_full_descriptors = g_array_new(FALSE, TRUE,
                sizeof(struct comp_class_full_descriptor));
        if (!comp_class_full_descriptors) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -391,22 +396,28 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                cur_attr->value.version.extra);
                        break;
                default:
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "%s plugin descriptor attribute: "
-                               "plugin-path=\"%s\", plugin-name=\"%s\", "
-                               "attr-type-name=\"%s\", attr-type-id=%d",
-                               fail_on_load_error ? "Unknown" :
-                                       "Ignoring unknown",
-                               spec->shared_lib_handle->path ?
-                                       spec->shared_lib_handle->path->str :
-                                       NULL,
-                               descriptor->name, cur_attr->type_name,
-                               cur_attr->type);
-
                        if (fail_on_load_error) {
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Unknown plugin descriptor attribute: "
+                                       "plugin-path=\"%s\", plugin-name=\"%s\", "
+                                       "attr-type-name=\"%s\", attr-type-id=%d",
+                                       spec->shared_lib_handle->path ?
+                                               spec->shared_lib_handle->path->str :
+                                               NULL,
+                                       descriptor->name, cur_attr->type_name,
+                                       cur_attr->type);
                                status = BT_FUNC_STATUS_LOADING_ERROR;
                                goto end;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Ignoring unknown plugin descriptor attribute: "
+                                       "plugin-path=\"%s\", plugin-name=\"%s\", "
+                                       "attr-type-name=\"%s\", attr-type-id=%d",
+                                       spec->shared_lib_handle->path ?
+                                               spec->shared_lib_handle->path->str :
+                                               NULL,
+                                       descriptor->name, cur_attr->type_name,
+                                       cur_attr->type);
                        }
 
                        break;
@@ -654,30 +665,44 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                }
                                break;
                        default:
-                               BT_LOG_WRITE(fail_on_load_error ?
-                                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                                       "%s component class descriptor attribute: "
-                                       "plugin-path=\"%s\", "
-                                       "plugin-name=\"%s\", "
-                                       "comp-class-name=\"%s\", "
-                                       "comp-class-type=%s, "
-                                       "attr-type-name=\"%s\", "
-                                       "attr-type-id=%d",
-                                       fail_on_load_error ? "Unknown" :
-                                               "Ignoring unknown",
-                                       spec->shared_lib_handle->path ?
-                                               spec->shared_lib_handle->path->str :
-                                               NULL,
-                                       descriptor->name,
-                                       cur_cc_descr_attr->comp_class_descriptor->name,
-                                       bt_component_class_type_string(
-                                               cur_cc_descr_attr->comp_class_descriptor->type),
-                                       cur_cc_descr_attr->type_name,
-                                       cur_cc_descr_attr->type);
-
                                if (fail_on_load_error) {
+                                       BT_LIB_LOGW_APPEND_CAUSE(
+                                               "Unknown component class descriptor attribute: "
+                                               "plugin-path=\"%s\", "
+                                               "plugin-name=\"%s\", "
+                                               "comp-class-name=\"%s\", "
+                                               "comp-class-type=%s, "
+                                               "attr-type-name=\"%s\", "
+                                               "attr-type-id=%d",
+                                               spec->shared_lib_handle->path ?
+                                                       spec->shared_lib_handle->path->str :
+                                                       NULL,
+                                               descriptor->name,
+                                               cur_cc_descr_attr->comp_class_descriptor->name,
+                                               bt_component_class_type_string(
+                                                       cur_cc_descr_attr->comp_class_descriptor->type),
+                                               cur_cc_descr_attr->type_name,
+                                               cur_cc_descr_attr->type);
                                        status = BT_FUNC_STATUS_LOADING_ERROR;
                                        goto end;
+                               } else {
+                                       BT_LIB_LOGI(
+                                               "Ignoring unknown component class descriptor attribute: "
+                                               "plugin-path=\"%s\", "
+                                               "plugin-name=\"%s\", "
+                                               "comp-class-name=\"%s\", "
+                                               "comp-class-type=%s, "
+                                               "attr-type-name=\"%s\", "
+                                               "attr-type-id=%d",
+                                               spec->shared_lib_handle->path ?
+                                                       spec->shared_lib_handle->path->str :
+                                                       NULL,
+                                               descriptor->name,
+                                               cur_cc_descr_attr->comp_class_descriptor->name,
+                                               bt_component_class_type_string(
+                                                       cur_cc_descr_attr->comp_class_descriptor->type),
+                                               cur_cc_descr_attr->type_name,
+                                               cur_cc_descr_attr->type);
                                }
 
                                break;
@@ -695,16 +720,22 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        bt_common_func_status_string(init_status));
 
                if (init_status < 0) {
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "User's plugin initialization function failed: "
-                               "status=%s",
-                               bt_common_func_status_string(init_status));
-
                        if (fail_on_load_error) {
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "User's plugin initialization function failed: "
+                                       "status=%s",
+                                       bt_common_func_status_string(init_status));
                                status = init_status;
                                goto end;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "User's plugin initialization function failed: "
+                                       "status=%s",
+                                       bt_common_func_status_string(init_status));
+                               status = BT_FUNC_STATUS_NOT_FOUND;
                        }
+
+                       goto end;
                }
        }
 
@@ -754,30 +785,37 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                sink_comp_class);
                        break;
                default:
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "%s component class type: "
-                               "plugin-path=\"%s\", plugin-name=\"%s\", "
-                               "comp-class-name=\"%s\", comp-class-type=%d",
-                               fail_on_load_error ? "Unknown" :
-                                       "Ignoring unknown",
-                               spec->shared_lib_handle->path->str ?
-                                       spec->shared_lib_handle->path->str :
-                                       NULL,
-                               descriptor->name,
-                               cc_full_descr->descriptor->name,
-                               cc_full_descr->descriptor->type);
-
                        if (fail_on_load_error) {
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Unknown component class type: "
+                                       "plugin-path=\"%s\", plugin-name=\"%s\", "
+                                       "comp-class-name=\"%s\", comp-class-type=%d",
+                                       spec->shared_lib_handle->path->str ?
+                                               spec->shared_lib_handle->path->str :
+                                               NULL,
+                                       descriptor->name,
+                                       cc_full_descr->descriptor->name,
+                                       cc_full_descr->descriptor->type);
                                status = BT_FUNC_STATUS_LOADING_ERROR;
                                goto end;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Ignoring unknown component class type: "
+                                       "plugin-path=\"%s\", plugin-name=\"%s\", "
+                                       "comp-class-name=\"%s\", comp-class-type=%d",
+                                       spec->shared_lib_handle->path->str ?
+                                               spec->shared_lib_handle->path->str :
+                                               NULL,
+                                       descriptor->name,
+                                       cc_full_descr->descriptor->name,
+                                       cc_full_descr->descriptor->type);
+                               continue;
                        }
-
-                       continue;
                }
 
                if (!comp_class) {
-                       BT_LOGE_STR("Cannot create component class.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create component class.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -786,7 +824,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        ret = bt_component_class_set_description(
                                comp_class, cc_full_descr->description);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set component class's description.");
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot set component class's description.");
                                status = BT_FUNC_STATUS_MEMORY_ERROR;
                                BT_OBJECT_PUT_REF_AND_RESET(comp_class);
                                goto end;
@@ -797,7 +836,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        ret = bt_component_class_set_help(comp_class,
                                cc_full_descr->help);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set component class's help string.");
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot set component class's help string.");
                                status = BT_FUNC_STATUS_MEMORY_ERROR;
                                BT_OBJECT_PUT_REF_AND_RESET(comp_class);
                                goto end;
@@ -811,7 +851,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.init);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's initialization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's initialization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -823,7 +864,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.finalize);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's finalization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's finalization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -835,7 +877,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.query);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's query method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's query method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -847,7 +890,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.output_port_connected);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's \"output port connected\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -859,7 +903,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_init);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator initialization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator initialization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -871,7 +916,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_finalize);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator finalization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator finalization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -883,7 +929,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_seek_ns_from_origin);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator \"seek nanoseconds from origin\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator \"seek nanoseconds from origin\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -895,7 +942,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_seek_beginning);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator \"seek beginning\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator \"seek beginning\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -907,7 +955,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -919,7 +968,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        src_comp_class,
                                        cc_full_descr->methods.source.msg_iter_can_seek_beginning);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set source component class's message iterator \"can seek beginning\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set source component class's message iterator \"can seek beginning\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
                                        goto end;
@@ -933,7 +983,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.init);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's initialization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's initialization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -945,7 +996,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.finalize);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's finalization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's finalization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -957,7 +1009,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.query);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's query method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's query method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -969,7 +1022,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.input_port_connected);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's \"input port connected\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -981,7 +1035,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.output_port_connected);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's \"output port connected\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -993,7 +1048,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_init);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator initialization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator initialization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1005,7 +1061,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_finalize);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator finalization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator finalization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1017,7 +1074,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1029,7 +1087,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_seek_beginning);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator \"seek beginning\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator \"seek beginning\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1041,7 +1100,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1053,7 +1113,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        flt_comp_class,
                                        cc_full_descr->methods.filter.msg_iter_can_seek_beginning);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek beginning\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set filter component class's message iterator \"can seek beginning\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
                                        goto end;
@@ -1067,7 +1128,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        sink_comp_class,
                                        cc_full_descr->methods.sink.init);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set sink component class's initialization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set sink component class's initialization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
                                        goto end;
@@ -1079,7 +1141,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        sink_comp_class,
                                        cc_full_descr->methods.sink.finalize);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set sink component class's finalization method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set sink component class's finalization method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
                                        goto end;
@@ -1091,7 +1154,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        sink_comp_class,
                                        cc_full_descr->methods.sink.query);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set sink component class's query method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set sink component class's query method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
                                        goto end;
@@ -1103,7 +1167,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        sink_comp_class,
                                        cc_full_descr->methods.sink.input_port_connected);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set sink component class's \"input port connected\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
                                        goto end;
@@ -1115,7 +1180,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                        sink_comp_class,
                                        cc_full_descr->methods.sink.graph_is_configured);
                                if (ret) {
-                                       BT_LOGE_STR("Cannot set sink component class's \"graph is configured\" method.");
+                                       BT_LIB_LOGE_APPEND_CAUSE(
+                                               "Cannot set sink component class's \"graph is configured\" method.");
                                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                                        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
                                        goto end;
@@ -1139,7 +1205,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        (void *) comp_class);
                BT_OBJECT_PUT_REF_AND_RESET(comp_class);
                if (status < 0) {
-                       BT_LOGE("Cannot add component class to plugin.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot add component class to plugin.");
                        goto end;
                }
        }
@@ -1164,7 +1231,8 @@ struct bt_plugin *bt_plugin_so_create_empty(
        plugin->destroy_spec_data = bt_plugin_so_destroy_spec_data;
        plugin->spec_data = g_new0(struct bt_plugin_so_spec_data, 1);
        if (!plugin->spec_data) {
-               BT_LOGE_STR("Failed to allocate one SO plugin specific data structure.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one SO plugin specific data structure.");
                goto error;
        }
 
@@ -1241,7 +1309,7 @@ int bt_plugin_so_create_all_from_sections(
                cc_descriptors_count, cc_descr_attrs_count);
        *plugin_set_out = bt_plugin_set_create();
        if (!*plugin_set_out) {
-               BT_LOGE_STR("Cannot create empty plugin set.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -1260,22 +1328,24 @@ int bt_plugin_so_create_all_from_sections(
                        descriptor->name, descriptor->major, descriptor->minor);
 
                if (descriptor->major > __BT_PLUGIN_VERSION_MAJOR) {
-                       BT_LOG_WRITE(fail_on_load_error ? BT_LOG_WARN :
-                               BT_LOG_INFO, BT_LOG_TAG,
-                               "Unknown ABI major version: abi-major=%d",
-                                       descriptor->major);
-
                        if (fail_on_load_error) {
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Unknown ABI major version: abi-major=%d",
+                                               descriptor->major);
                                status = BT_FUNC_STATUS_LOADING_ERROR;
                                goto error;
                        } else {
+                               BT_LIB_LOGI(
+                                       "Unknown ABI major version: abi-major=%d",
+                                               descriptor->major);
                                continue;
                        }
                }
 
                plugin = bt_plugin_so_create_empty(shared_lib_handle);
                if (!plugin) {
-                       BT_LOGE_STR("Cannot create empty shared library handle.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create empty shared library handle.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto error;
                }
@@ -1299,7 +1369,8 @@ int bt_plugin_so_create_all_from_sections(
                         * `fail_on_load_error`, so this is a "real"
                         * error.
                         */
-                       BT_LOGW_STR("Cannot initialize SO plugin object from sections.");
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot initialize SO plugin object from sections.");
                        BT_OBJECT_PUT_REF_AND_RESET(plugin);
                        goto error;
                }
@@ -1418,7 +1489,8 @@ int bt_plugin_so_create_all_from_file(const char *path,
        if (status != BT_FUNC_STATUS_OK) {
                /* bt_plugin_so_shared_lib_handle_create() logs more details */
                BT_ASSERT(!shared_lib_handle);
-               BT_LOGE_STR("Cannot create shared library handle.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create shared library handle.");
                goto end;
        }
 
@@ -1447,13 +1519,20 @@ int bt_plugin_so_create_all_from_file(const char *path,
                        (gpointer *) &get_end_section_plugin_descriptors)) {
                descriptors_end = get_end_section_plugin_descriptors();
        } else {
-               BT_LOG_WRITE(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO,
-                       BT_LOG_TAG,
-                       "Cannot resolve plugin symbol: path=\"%s\", "
-                       "symbol=\"%s\"", path,
-                       "__bt_get_end_section_plugin_descriptors");
-               status = fail_on_load_error ? BT_FUNC_STATUS_LOADING_ERROR :
-                       BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot resolve plugin symbol: path=\"%s\", "
+                               "symbol=\"%s\"", path,
+                               "__bt_get_end_section_plugin_descriptors");
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot resolve plugin symbol: path=\"%s\", "
+                               "symbol=\"%s\"", path,
+                               "__bt_get_end_section_plugin_descriptors");
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto end;
        }
 
@@ -1476,17 +1555,28 @@ int bt_plugin_so_create_all_from_file(const char *path,
        }
 
        if ((!!attrs_begin - !!attrs_end) != 0) {
-               BT_LOG_WRITE(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO,
-                       BT_LOG_TAG,
-                       "Found section start or end symbol, but not both: "
-                       "path=\"%s\", symbol-start=\"%s\", "
-                       "symbol-end=\"%s\", symbol-start-addr=%p, "
-                       "symbol-end-addr=%p",
-                       path, "__bt_get_begin_section_plugin_descriptor_attributes",
-                       "__bt_get_end_section_plugin_descriptor_attributes",
-                       attrs_begin, attrs_end);
-               status = fail_on_load_error ? BT_FUNC_STATUS_LOADING_ERROR :
-                       BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_plugin_descriptor_attributes",
+                               "__bt_get_end_section_plugin_descriptor_attributes",
+                               attrs_begin, attrs_end);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_plugin_descriptor_attributes",
+                               "__bt_get_end_section_plugin_descriptor_attributes",
+                               attrs_begin, attrs_end);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto end;
        }
 
@@ -1509,17 +1599,28 @@ int bt_plugin_so_create_all_from_file(const char *path,
        }
 
        if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) {
-               BT_LOG_WRITE(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO,
-                       BT_LOG_TAG,
-                       "Found section start or end symbol, but not both: "
-                       "path=\"%s\", symbol-start=\"%s\", "
-                       "symbol-end=\"%s\", symbol-start-addr=%p, "
-                       "symbol-end-addr=%p",
-                       path, "__bt_get_begin_section_component_class_descriptors",
-                       "__bt_get_end_section_component_class_descriptors",
-                       cc_descriptors_begin, cc_descriptors_end);
-               status = fail_on_load_error ? BT_FUNC_STATUS_LOADING_ERROR :
-                       BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_component_class_descriptors",
+                               "__bt_get_end_section_component_class_descriptors",
+                               cc_descriptors_begin, cc_descriptors_end);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_component_class_descriptors",
+                               "__bt_get_end_section_component_class_descriptors",
+                               cc_descriptors_begin, cc_descriptors_end);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto end;
        }
 
@@ -1542,17 +1643,28 @@ int bt_plugin_so_create_all_from_file(const char *path,
        }
 
        if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) {
-               BT_LOG_WRITE(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO,
-                       BT_LOG_TAG,
-                       "Found section start or end symbol, but not both: "
-                       "path=\"%s\", symbol-start=\"%s\", "
-                       "symbol-end=\"%s\", symbol-start-addr=%p, "
-                       "symbol-end-addr=%p",
-                       path, "__bt_get_begin_section_component_class_descriptor_attributes",
-                       "__bt_get_end_section_component_class_descriptor_attributes",
-                       cc_descr_attrs_begin, cc_descr_attrs_end);
-               status = fail_on_load_error ? BT_FUNC_STATUS_LOADING_ERROR :
-                       BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_component_class_descriptor_attributes",
+                               "__bt_get_end_section_component_class_descriptor_attributes",
+                               cc_descr_attrs_begin, cc_descr_attrs_end);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Found section start or end symbol, but not both: "
+                               "path=\"%s\", symbol-start=\"%s\", "
+                               "symbol-end=\"%s\", symbol-start-addr=%p, "
+                               "symbol-end-addr=%p",
+                               path, "__bt_get_begin_section_component_class_descriptor_attributes",
+                               "__bt_get_end_section_component_class_descriptor_attributes",
+                               cc_descr_attrs_begin, cc_descr_attrs_end);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto end;
        }
 
index 36059c4ad3b13f6b04eb17ca7ad1dcd075948469..74b3eb51d3b1fd1a9d68de5f5d834fc8ed03f5f8 100644 (file)
@@ -33,6 +33,7 @@
 #include "common/common.h"
 #include <babeltrace2/plugin/plugin-const.h>
 #include <babeltrace2/graph/component-class-const.h>
+#include <babeltrace2/current-thread.h>
 #include "lib/graph/component-class.h"
 #include <babeltrace2/types.h>
 #include <glib.h>
@@ -64,7 +65,7 @@ int (*bt_plugin_python_create_all_from_file_sym)(
        bt_plugin_python_create_all_from_file;
 
 static
-void init_python_plugin_provider(void)
+enum bt_plugin_status init_python_plugin_provider(void)
 {
 }
 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
@@ -76,9 +77,11 @@ int (*bt_plugin_python_create_all_from_file_sym)(
                 struct bt_plugin_set **plugin_set_out);
 
 static
-void init_python_plugin_provider(void) {
+int init_python_plugin_provider(void) {
+       int status = BT_FUNC_STATUS_OK;
+
        if (bt_plugin_python_create_all_from_file_sym != NULL) {
-               return;
+               goto end;
        }
 
        BT_LOGI_STR("Loading Python plugin provider module.");
@@ -92,7 +95,7 @@ void init_python_plugin_provider(void) {
                 */
                BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
                        PYTHON_PLUGIN_PROVIDER_FILENAME, g_module_error());
-               return;
+               goto end;
        }
 
        if (!g_module_symbol(python_plugin_provider_module,
@@ -103,17 +106,22 @@ void init_python_plugin_provider(void) {
                 * plugin provider shared object, we expect this symbol
                 * to exist.
                 */
-               BT_LOGE("Cannot find the Python plugin provider loading symbol: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot find the Python plugin provider loading symbol: "
                        "%s: continuing without Python plugin support: "
                        "file=\"%s\", symbol=\"%s\"",
                        g_module_error(),
                        PYTHON_PLUGIN_PROVIDER_FILENAME,
                        PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR);
-               return;
+               status = BT_FUNC_STATUS_ERROR;
+               goto end;
        }
 
        BT_LOGI("Loaded Python plugin provider module: addr=%p",
                python_plugin_provider_module);
+
+end:
+       return status;
 }
 
 __attribute__((destructor)) static
@@ -122,6 +130,10 @@ void fini_python_plugin_provider(void) {
                BT_LOGI("Unloading Python plugin provider module.");
 
                if (!g_module_close(python_plugin_provider_module)) {
+                       /*
+                        * This occurs when the library is finalized: do
+                        * NOT append an error cause.
+                        */
                        BT_LOGE("Failed to close the Python plugin provider module: %s.",
                                g_module_error());
                }
@@ -180,8 +192,17 @@ enum bt_plugin_find_all_from_file_status bt_plugin_find_all_from_file(
        BT_ASSERT(!*plugin_set_out);
 
        /* Try Python plugins if support is available */
-       init_python_plugin_provider();
+       status = init_python_plugin_provider();
+       if (status < 0) {
+               /* init_python_plugin_provider() logs errors */
+               goto end;
+       }
+
+       BT_ASSERT(status == BT_FUNC_STATUS_OK);
+       status = BT_FUNC_STATUS_NOT_FOUND;
+
        if (bt_plugin_python_create_all_from_file_sym) {
+               /* Python plugin provider exists */
                status = bt_plugin_python_create_all_from_file_sym(path,
                        fail_on_load_error, (void *) plugin_set_out);
                if (status == BT_FUNC_STATUS_OK) {
@@ -189,6 +210,11 @@ enum bt_plugin_find_all_from_file_status bt_plugin_find_all_from_file(
                        BT_ASSERT((*plugin_set_out)->plugins->len > 0);
                        goto end;
                } else if (status < 0) {
+                       /*
+                        * bt_plugin_python_create_all_from_file_sym()
+                        * handles `fail_on_load_error` itself, so this
+                        * is a "real" error.
+                        */
                        BT_ASSERT(!*plugin_set_out);
                        goto end;
                }
@@ -235,7 +261,7 @@ enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
                "name=\"%s\"", plugin_name);
        dirs = g_ptr_array_new_with_free_func((GDestroyNotify) destroy_gstring);
        if (!dirs) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -258,7 +284,8 @@ enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
        if (envvar) {
                ret = bt_common_append_plugin_path_dirs(envvar, dirs);
                if (ret) {
-                       BT_LOGE_STR("Failed to append plugin path to array of directories.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Failed to append plugin path to array of directories.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -269,7 +296,7 @@ enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
                GString *home_plugin_dir_str = g_string_new(home_plugin_dir);
 
                if (!home_plugin_dir_str) {
-                       BT_LOGE_STR("Failed to allocate a GString.");
+                       BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -283,7 +310,7 @@ enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
                        g_string_new(system_plugin_dir);
 
                if (!system_plugin_dir_str) {
-                       BT_LOGE_STR("Failed to allocate a GString.");
+                       BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                        status = BT_FUNC_STATUS_MEMORY_ERROR;
                        goto end;
                }
@@ -501,6 +528,10 @@ int bt_plugin_create_append_all_from_dir(struct bt_plugin_set *plugin_set,
                BT_LOGW_ERRNO("Cannot open directory",
                        ": path=\"%s\", recurse=%d",
                        path, recurse);
+               (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
+                       "Babeltrace library",
+                       "Cannot open directory: path=\"%s\", recurse=%d",
+                       path, recurse);
                status = BT_FUNC_STATUS_ERROR;
                goto end;
        }
@@ -516,7 +547,7 @@ int bt_plugin_create_append_all_from_dir(struct bt_plugin_set *plugin_set,
        status = append_all_from_dir_info.status;
        pthread_mutex_unlock(&append_all_from_dir_info.lock);
        if (ret) {
-               BT_LOGW_ERRNO("Failed to walk directory",
+               BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
                        ": path=\"%s\", recurse=%d",
                        path, recurse);
                status = BT_FUNC_STATUS_ERROR;
@@ -548,7 +579,7 @@ enum bt_plugin_find_all_from_dir_status bt_plugin_find_all_from_dir(
                path, recurse);
        *plugin_set_out = bt_plugin_set_create();
        if (!*plugin_set_out) {
-               BT_LOGE_STR("Cannot create empty plugin set.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto error;
        }
@@ -564,7 +595,8 @@ enum bt_plugin_find_all_from_dir_status bt_plugin_find_all_from_dir(
                 * bt_plugin_create_append_all_from_dir() handles
                 * `fail_on_load_error`, so this is a "real" error.
                 */
-               BT_LOGW("Cannot append plugins found in directory: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot append plugins found in directory: "
                        "path=\"%s\", status=%s",
                        path, bt_common_func_status_string(status));
                goto error;
index 417d116c436fe609ddb3e78a0708da60f4867eee..616987223ca9023bfea2d64dd7da70ae2cc92b21 100644 (file)
@@ -175,7 +175,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
 
        plugin = g_new0(struct bt_plugin, 1);
        if (!plugin) {
-               BT_LOGE_STR("Failed to allocate one plugin.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one plugin.");
                goto error;
        }
 
@@ -187,7 +187,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->src_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -195,7 +195,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->flt_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -203,44 +203,44 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->sink_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
        /* Create empty info */
        plugin->info.name = g_string_new(NULL);
        if (!plugin->info.name) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.path = g_string_new(NULL);
        if (!plugin->info.path) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.description = g_string_new(NULL);
        if (!plugin->info.description) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.author = g_string_new(NULL);
        if (!plugin->info.author) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.license = g_string_new(NULL);
        if (!plugin->info.license) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.version.extra = g_string_new(NULL);
        if (!plugin->info.version.extra) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
@@ -405,7 +405,7 @@ struct bt_plugin_set *bt_plugin_set_create(void)
        plugin_set->plugins = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_put_ref);
        if (!plugin_set->plugins) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
                goto end;
        }
index 43f71437817825a50869eb14ccc457e39fc17fa4..d2047b7c72dbf36cb6e70674a28408cac7d1fd4a 100644 (file)
@@ -60,7 +60,7 @@ struct bt_value *bt_attributes_create(void)
        BT_LOGD_STR("Creating attributes object.");
        attr_obj = bt_value_array_create();
        if (!attr_obj) {
-               BT_LOGE_STR("Failed to create array value.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to create array value.");
        } else {
                BT_LOGD("Created attributes object: addr=%p",
                        attr_obj);
@@ -90,23 +90,14 @@ const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
        const struct bt_value *attr_field_obj = NULL;
        const struct bt_value *attr_field_name_obj = NULL;
 
-       if (!attr_obj) {
-               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
-               goto end;
-       }
-
-       if (index >= bt_value_array_get_size(attr_obj)) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "index=%" PRIu64 ", count=%" PRId64,
-                       index, bt_value_array_get_size(attr_obj));
-               goto end;
-       }
-
+       BT_ASSERT(attr_obj);
+       BT_ASSERT(index < bt_value_array_get_size(attr_obj));
        attr_field_obj = bt_value_array_borrow_element_by_index_const(
                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);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot borrow attributes object's array value's element by index: "
+                       "%![value-]+v, index=%" PRIu64, attr_obj, index);
                goto end;
        }
 
@@ -114,8 +105,9 @@ const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
                bt_value_array_borrow_element_by_index_const(attr_field_obj,
                        BT_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,
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get attribute array value's element by index: "
+                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
                        (uint64_t) BT_ATTR_NAME_INDEX);
                goto end;
        }
@@ -133,31 +125,23 @@ struct bt_value *bt_attributes_borrow_field_value(
        struct bt_value *value_obj = NULL;
        struct bt_value *attr_field_obj = NULL;
 
-       if (!attr_obj) {
-               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
-               goto end;
-       }
-
-       if (index >= bt_value_array_get_size(attr_obj)) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "index=%" PRIu64 ", count=%" PRId64,
-                       index, bt_value_array_get_size(attr_obj));
-               goto end;
-       }
-
+       BT_ASSERT(attr_obj);
+       BT_ASSERT(index < bt_value_array_get_size(attr_obj));
        attr_field_obj =
                bt_value_array_borrow_element_by_index(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);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get attributes object's array value's element by index: "
+                       "%![value-]+v, index=%" PRIu64, attr_obj, index);
                goto end;
        }
 
        value_obj = bt_value_array_borrow_element_by_index(
                attr_field_obj, BT_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,
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get attribute array value's element by index: "
+                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
                        (uint64_t) BT_ATTR_VALUE_INDEX);
        }
 
@@ -176,7 +160,8 @@ struct bt_value *bt_attributes_borrow_field_by_name(
 
        attr_size = bt_value_array_get_size(attr_obj);
        if (attr_size < 0) {
-               BT_LOGE("Cannot get array value's size: value-addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get array value's size: %![value-]+v",
                        attr_obj);
                goto error;
        }
@@ -187,8 +172,9 @@ struct bt_value *bt_attributes_borrow_field_by_name(
                value_obj = bt_value_array_borrow_element_by_index(
                        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);
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot get attributes object's array value's element by index: "
+                               "%![value-]+v, index=%" PRIu64, attr_obj, i);
                        goto error;
                }
 
@@ -196,8 +182,9 @@ struct bt_value *bt_attributes_borrow_field_by_name(
                        bt_value_array_borrow_element_by_index(
                                value_obj, BT_ATTR_NAME_INDEX);
                if (!attr_field_name_obj) {
-                       BT_LOGE("Cannot get attribute array value's element by index: "
-                               "value-addr=%p, index=%" PRIu64,
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot get attribute array value's element by index: "
+                               "%![value-]+v, index=%" PRIu64,
                                value_obj, (int64_t) BT_ATTR_NAME_INDEX);
                        goto error;
                }
@@ -225,14 +212,9 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj,
        int ret = 0;
        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;
-       }
-
+       BT_ASSERT(attr_obj);
+       BT_ASSERT(name);
+       BT_ASSERT(value_obj);
        attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name);
        if (attr_field_obj) {
                ret = bt_value_array_set_element_by_index(
@@ -244,7 +226,7 @@ int bt_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.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to create empty array value.");
                ret = -1;
                goto end;
        }
@@ -254,7 +236,8 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj,
        ret |= bt_value_array_append_element(attr_field_obj,
                value_obj);
        if (ret) {
-               BT_LOGE("Cannot append elements to array value: addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot append elements to array value: %!+v",
                        attr_field_obj);
                goto end;
        }
@@ -262,8 +245,9 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj,
        ret = bt_value_array_append_element(attr_obj,
                attr_field_obj);
        if (ret) {
-               BT_LOGE("Cannot append element to array value: "
-                       "array-value-addr=%p, element-value-addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot append element to array value: "
+                       "%![array-value-]+v, %![element-value-]+v",
                        attr_obj, attr_field_obj);
        }
 
@@ -279,12 +263,8 @@ struct bt_value *bt_attributes_borrow_field_value_by_name(
        struct bt_value *value_obj = NULL;
        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;
-       }
-
+       BT_ASSERT(attr_obj);
+       BT_ASSERT(name);
        attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name);
        if (!attr_field_obj) {
                BT_LOGD("Cannot find attributes object's field by name: "
@@ -295,8 +275,9 @@ struct bt_value *bt_attributes_borrow_field_value_by_name(
        value_obj = bt_value_array_borrow_element_by_index(
                attr_field_obj, BT_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,
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get attribute array value's element by index: "
+                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
                        (uint64_t) BT_ATTR_VALUE_INDEX);
        }
 
@@ -311,12 +292,7 @@ int bt_attributes_freeze(const struct bt_value *attr_obj)
        int64_t count;
        int ret = 0;
 
-       if (!attr_obj) {
-               BT_LOGW_STR("Invalid parameter: attributes object is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT(attr_obj);
        BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj);
        count = bt_value_array_get_size(attr_obj);
        BT_ASSERT(count >= 0);
@@ -332,8 +308,9 @@ int bt_attributes_freeze(const struct bt_value *attr_obj)
                obj = bt_attributes_borrow_field_value(
                        (void *) attr_obj, i);
                if (!obj) {
-                       BT_LOGE("Cannot get attributes object's field value by index: "
-                               "value-addr=%p, index=%" PRIu64,
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot get attributes object's field value by index: "
+                               "%![value-]+v, index=%" PRIu64,
                                attr_obj, i);
                        ret = -1;
                        goto end;
index fdeef9289af4ddf85f9b329f7ee64efaa2fff822..43341d0f963561a77970c3724cf0169b95186b09 100644 (file)
@@ -90,20 +90,20 @@ struct bt_clock_class *bt_clock_class_create(bt_self_component *self_comp)
 
        clock_class = g_new0(struct bt_clock_class, 1);
        if (!clock_class) {
-               BT_LOGE_STR("Failed to allocate one clock class.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one clock class.");
                goto error;
        }
 
        bt_object_init_shared(&clock_class->base, destroy_clock_class);
        clock_class->name.str = g_string_new(NULL);
        if (!clock_class->name.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        clock_class->description.str = g_string_new(NULL);
        if (!clock_class->description.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
@@ -116,7 +116,8 @@ struct bt_clock_class *bt_clock_class_create(bt_self_component *self_comp)
                        free_clock_snapshot,
                clock_class);
        if (ret) {
-               BT_LOGE("Failed to initialize clock snapshot pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize clock snapshot pool: ret=%d",
                        ret);
                goto error;
        }
index 855744b2fae9ea76b2452894643d2b8ee3ee1b43..ec790aff66676e46223ba92c708fa81379f5294a 100644 (file)
  * SOFTWARE.
  */
 
+/* Protection: this file uses BT_LIB_LOG*() macros directly */
+#ifndef BT_LIB_LOG_SUPPORTED
+# error Please include "lib/logging.h" before including this file.
+#endif
+
 #include <stdint.h>
 #include <glib.h>
 #include "common/assert.h"
@@ -50,7 +55,7 @@ int bt_clock_snapshot_set_initialize(struct bt_clock_snapshot_set *cs_set)
 
        cs_set->clock_snapshots = g_ptr_array_sized_new(1);
        if (!cs_set->clock_snapshots) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -132,7 +137,8 @@ int bt_clock_snapshot_set_set_clock_snapshot(struct bt_clock_snapshot_set *cs_se
        if (!clock_snapshot) {
                clock_snapshot = bt_clock_snapshot_create(cc);
                if (!clock_snapshot) {
-                       BT_LIB_LOGE("Cannot create a clock snapshot from a clock class: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create a clock snapshot from a clock class: "
                                "%![cc-]+K", cc);
                        ret = -1;
                        goto end;
index 757e1cb8101d4cea685dc8f2b24f416789258c78..53f6be654478454fb051468c4e5cbfd75b33278d 100644 (file)
@@ -55,7 +55,8 @@ struct bt_clock_snapshot *bt_clock_snapshot_new(
                clock_class);
        ret = g_new0(struct bt_clock_snapshot, 1);
        if (!ret) {
-               BT_LOGE_STR("Failed to allocate one clock snapshot.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one clock snapshot.");
                goto end;
        }
 
@@ -78,7 +79,8 @@ struct bt_clock_snapshot *bt_clock_snapshot_create(
        BT_ASSERT(clock_class);
        clock_snapshot = bt_object_pool_create_object(&clock_class->cs_pool);
        if (!clock_snapshot) {
-               BT_LIB_LOGE("Cannot allocate one clock snapshot from clock class's clock snapshot pool: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one clock snapshot from clock class's clock snapshot pool: "
                        "%![cc-]+K", clock_class);
                goto error;
        }
index 49ff7ff6c0a109cf9d3f1528e522ebf8535f1d69..5bc572f2516dbbaafa6f20aa844973a64f1b7e89 100644 (file)
@@ -122,7 +122,7 @@ struct bt_event_class *create_event_class_with_id(
                stream_class, id);
        event_class = g_new0(struct bt_event_class, 1);
        if (!event_class) {
-               BT_LOGE_STR("Failed to allocate one event class.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event class.");
                goto error;
        }
 
@@ -133,14 +133,14 @@ struct bt_event_class *create_event_class_with_id(
                        BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, 0);
        event_class->name.str = g_string_new(NULL);
        if (!event_class->name.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                ret = -1;
                goto end;
        }
 
        event_class->emf_uri.str = g_string_new(NULL);
        if (!event_class->emf_uri.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                ret = -1;
                goto end;
        }
@@ -150,7 +150,8 @@ struct bt_event_class *create_event_class_with_id(
                (bt_object_pool_destroy_object_func) free_event,
                event_class);
        if (ret) {
-               BT_LOGE("Failed to initialize event pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize event pool: ret=%d",
                        ret);
                goto error;
        }
index 0053b6b7f9dc8ab7c1c531342f973832a7733d58..ffe3080e315e12552b4af0f23b765f1750079b56 100644 (file)
@@ -86,7 +86,7 @@ struct bt_event *bt_event_new(struct bt_event_class *event_class)
        BT_ASSERT(event_class);
        event = g_new0(struct bt_event, 1);
        if (!event) {
-               BT_LOGE_STR("Failed to allocate one event.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event.");
                goto error;
        }
 
index b2f085a0ea3106cb2b7c378c7091edbb06ab6341..002278ce88e1bb090e2e3e01ae6d23f9166f7b18 100644 (file)
@@ -187,7 +187,8 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class,
        BT_ASSERT(event_class);
        event = bt_object_pool_create_object(&event_class->event_pool);
        if (G_UNLIKELY(!event)) {
-               BT_LIB_LOGE("Cannot allocate one event from event class's event pool: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one event from event class's event pool: "
                        "%![ec-]+E", event_class);
                goto end;
        }
index 30a1444c67685ee7afba152f46fb060f0617e994..4c3de506e875e45b97e8f81cf35230d1f930f34a 100644 (file)
@@ -93,7 +93,8 @@ struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class,
                bt_common_field_class_type_string(type));
        int_fc = g_new0(struct bt_field_class_integer, 1);
        if (!int_fc) {
-               BT_LOGE_STR("Failed to allocate one integer field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one integer field class.");
                goto error;
        }
 
@@ -240,7 +241,8 @@ struct bt_field_class *create_enumeration_field_class(
                bt_common_field_class_type_string(type));
        enum_fc = g_new0(struct bt_field_class_enumeration, 1);
        if (!enum_fc) {
-               BT_LOGE_STR("Failed to allocate one enumeration field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one enumeration field class.");
                goto error;
        }
 
@@ -249,13 +251,13 @@ struct bt_field_class *create_enumeration_field_class(
        enum_fc->mappings = g_array_new(FALSE, TRUE,
                sizeof(struct bt_field_class_enumeration_mapping));
        if (!enum_fc->mappings) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                goto error;
        }
 
        enum_fc->label_buf = g_ptr_array_new();
        if (!enum_fc->label_buf) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                goto error;
        }
 
@@ -578,7 +580,7 @@ struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
        BT_LOGD_STR("Creating default real field class object.");
        real_fc = g_new0(struct bt_field_class_real, 1);
        if (!real_fc) {
-               BT_LOGE_STR("Failed to allocate one real field class.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
                goto error;
        }
 
@@ -628,14 +630,14 @@ int init_named_field_classes_container(
        fc->named_fcs = g_array_new(FALSE, TRUE,
                sizeof(struct bt_named_field_class));
        if (!fc->named_fcs) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                ret = -1;
                goto end;
        }
 
        fc->name_to_index = g_hash_table_new(g_str_hash, g_str_equal);
        if (!fc->name_to_index) {
-               BT_LOGE_STR("Failed to allocate a GHashTable.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
                ret = -1;
                goto end;
        }
@@ -703,7 +705,8 @@ struct bt_field_class *bt_field_class_structure_create(
        BT_LOGD_STR("Creating default structure field class object.");
        struct_fc = g_new0(struct bt_field_class_structure, 1);
        if (!struct_fc) {
-               BT_LOGE_STR("Failed to allocate one structure field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one structure field class.");
                goto error;
        }
 
@@ -742,7 +745,7 @@ int append_named_field_class_to_container_field_class(
                "%![container-fc-]+F, name=\"%s\"", container_fc, name);
        name_str = g_string_new(name);
        if (!name_str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                ret = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
@@ -929,7 +932,8 @@ struct bt_field_class *bt_field_class_variant_create(
        BT_LOGD_STR("Creating default variant field class object.");
        var_fc = g_new0(struct bt_field_class_variant, 1);
        if (!var_fc) {
-               BT_LOGE_STR("Failed to allocate one variant field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one variant field class.");
                goto error;
        }
 
@@ -1113,7 +1117,8 @@ bt_field_class_static_array_create(bt_trace_class *trace_class,
        BT_LOGD_STR("Creating default static array field class object.");
        array_fc = g_new0(struct bt_field_class_static_array, 1);
        if (!array_fc) {
-               BT_LOGE_STR("Failed to allocate one static array field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one static array field class.");
                goto error;
        }
 
@@ -1187,7 +1192,8 @@ struct bt_field_class *bt_field_class_dynamic_array_create(
        BT_LOGD_STR("Creating default dynamic array field class object.");
        array_fc = g_new0(struct bt_field_class_dynamic_array, 1);
        if (!array_fc) {
-               BT_LOGE_STR("Failed to allocate one dynamic array field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one dynamic array field class.");
                goto error;
        }
 
@@ -1251,7 +1257,8 @@ struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class)
        BT_LOGD_STR("Creating default string field class object.");
        string_fc = g_new0(struct bt_field_class_string, 1);
        if (!string_fc) {
-               BT_LOGE_STR("Failed to allocate one string field class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one string field class.");
                goto error;
        }
 
index 9a4af3a29a8ab090be9a1c99cd9fde34ee185b9b..80c9f3181f287e20a0fbe639d72d737a7589358a 100644 (file)
@@ -57,7 +57,7 @@ struct bt_field_path *bt_field_path_create(void)
 
        field_path = g_new0(struct bt_field_path, 1);
        if (!field_path) {
-               BT_LOGE_STR("Failed to allocate one field path.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one field path.");
                goto error;
        }
 
@@ -65,7 +65,7 @@ struct bt_field_path *bt_field_path_create(void)
        field_path->items = g_array_new(FALSE, FALSE,
                sizeof(struct bt_field_path_item));
        if (!field_path->items) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                goto error;
        }
 
index f1dcb6799895fad082dba920cd4e61d485317380..81854c1672ac9643d99d2a04f98a44f375554993 100644 (file)
@@ -39,7 +39,8 @@ struct bt_field_wrapper *bt_field_wrapper_new(void *data)
        BT_LOGD_STR("Creating empty field wrapper object.");
 
        if (!field_wrapper) {
-               BT_LOGE("Failed to allocate one field wrapper.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one field wrapper.");
                goto end;
        }
 
@@ -76,7 +77,8 @@ struct bt_field_wrapper *bt_field_wrapper_create(
        BT_ASSERT(fc);
        field_wrapper = bt_object_pool_create_object(pool);
        if (!field_wrapper) {
-               BT_LIB_LOGE("Cannot allocate one field wrapper from field wrapper pool: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one field wrapper from field wrapper pool: "
                        "%![pool-]+o", pool);
                goto error;
        }
@@ -84,7 +86,8 @@ struct bt_field_wrapper *bt_field_wrapper_create(
        if (!field_wrapper->field) {
                field_wrapper->field = (void *) bt_field_create(fc);
                if (!field_wrapper->field) {
-                       BT_LIB_LOGE("Cannot create field wrapper from field class: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create field wrapper from field class: "
                                "%![fc-]+F", fc);
                        goto error;
                }
index 3f10d6eea28274177c905ead24f0a9db81197a32..d3db8d7221fd2a3a2e257925f5eeb1516182bee5 100644 (file)
@@ -211,7 +211,7 @@ struct bt_field *bt_field_create(struct bt_field_class *fc)
        BT_ASSERT(bt_field_class_has_known_type(fc));
        field = field_create_funcs[fc->type](fc);
        if (!field) {
-               BT_LIB_LOGE("Cannot create field object from field class: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
                        "%![fc-]+F", fc);
                goto end;
        }
@@ -240,7 +240,8 @@ struct bt_field *create_integer_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc);
        int_field = g_new0(struct bt_field_integer, 1);
        if (!int_field) {
-               BT_LOGE_STR("Failed to allocate one integer field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one integer field.");
                goto end;
        }
 
@@ -259,7 +260,7 @@ struct bt_field *create_real_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc);
        real_field = g_new0(struct bt_field_real, 1);
        if (!real_field) {
-               BT_LOGE_STR("Failed to allocate one real field.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
                goto end;
        }
 
@@ -278,7 +279,8 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc);
        string_field = g_new0(struct bt_field_string, 1);
        if (!string_field) {
-               BT_LOGE_STR("Failed to allocate one string field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one string field.");
                goto end;
        }
 
@@ -286,7 +288,7 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        string_field->buf = g_array_sized_new(FALSE, FALSE,
                sizeof(char), 1);
        if (!string_field->buf) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                BT_OBJECT_PUT_REF_AND_RESET(string_field);
                goto end;
        }
@@ -309,7 +311,7 @@ int create_fields_from_named_field_classes(
        *fields = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_field_destroy);
        if (!*fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -323,7 +325,8 @@ int create_fields_from_named_field_classes(
 
                field = bt_field_create(named_fc->fc);
                if (!field) {
-                       BT_LIB_LOGE("Failed to create structure member or variant option field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Failed to create structure member or variant option field: "
                                "name=\"%s\", %![fc-]+F",
                                named_fc->name->str, named_fc->fc);
                        ret = -1;
@@ -345,7 +348,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc);
        struct_field = g_new0(struct bt_field_structure, 1);
        if (!struct_field) {
-               BT_LOGE_STR("Failed to allocate one structure field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one structure field.");
                goto end;
        }
 
@@ -353,8 +357,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &struct_field->fields)) {
-               BT_LIB_LOGE("Cannot create structure member fields: "
-                       "%![fc-]+F", fc);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create structure member fields: %![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(struct_field);
                goto end;
        }
@@ -373,7 +377,8 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc);
        var_field = g_new0(struct bt_field_variant, 1);
        if (!var_field) {
-               BT_LOGE_STR("Failed to allocate one variant field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one variant field.");
                goto end;
        }
 
@@ -381,7 +386,7 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &var_field->fields)) {
-               BT_LIB_LOGE("Cannot create variant member fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(var_field);
                goto end;
@@ -404,7 +409,7 @@ int init_array_field_fields(struct bt_field_array *array_field)
        array_fc = (void *) array_field->common.class;
        array_field->fields = g_ptr_array_sized_new(array_field->length);
        if (!array_field->fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -417,7 +422,8 @@ int init_array_field_fields(struct bt_field_array *array_field)
                array_field->fields->pdata[i] = bt_field_create(
                        array_fc->element_fc);
                if (!array_field->fields->pdata[i]) {
-                       BT_LIB_LOGE("Cannot create array field's element field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create array field's element field: "
                                "index=%" PRIu64 ", %![fc-]+F", i, array_fc);
                        ret = -1;
                        goto end;
@@ -437,7 +443,8 @@ struct bt_field *create_static_array_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one static array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one static array field.");
                goto end;
        }
 
@@ -445,7 +452,7 @@ struct bt_field *create_static_array_field(struct bt_field_class *fc)
        array_field->length = array_fc->length;
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create static array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -465,14 +472,15 @@ struct bt_field *create_dynamic_array_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one dynamic array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one dynamic array field.");
                goto end;
        }
 
        init_field((void *) array_field, fc, &array_field_methods);
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create dynamic array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -725,7 +733,8 @@ enum bt_field_dynamic_array_set_length_status bt_field_dynamic_array_set_length(
                                array_fc->element_fc);
 
                        if (!elem_field) {
-                               BT_LIB_LOGE("Cannot create element field for "
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot create element field for "
                                        "dynamic array field: "
                                        "index=%" PRIu64 ", "
                                        "%![array-field-]+f", i, field);
index c03e1eae331de44e76404c0ff5dd6e7b75a52461..388c20f307cc83ec01c19c0f224c9f2ada610792 100644 (file)
@@ -70,7 +70,8 @@ struct bt_packet_context_field *bt_packet_context_field_create(
                &stream_class->packet_context_field_pool,
                (void *) stream_class->packet_context_fc);
        if (!field_wrapper) {
-               BT_LIB_LOGE("Cannot allocate one packet context field from stream class: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one packet context field from stream class: "
                        "%![sc-]+S", stream_class);
                goto error;
        }
index d32da65a8a155bd176309168ddc2dd6317c6c9ba..cd81ca46aeeb9b0bda7ce840062bf17eb8a707bd 100644 (file)
@@ -182,7 +182,8 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream)
        BT_LIB_LOGD("Creating packet object: %![stream-]+s", stream);
        packet = g_new0(struct bt_packet, 1);
        if (!packet) {
-               BT_LOGE_STR("Failed to allocate one packet object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one packet object.");
                goto error;
        }
 
@@ -199,7 +200,8 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream)
                        &stream->class->packet_context_field_pool,
                        stream->class->packet_context_fc);
                if (!packet->context_field) {
-                       BT_LOGE_STR("Cannot create packet context field wrapper.");
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create packet context field wrapper.");
                        goto error;
                }
        }
@@ -222,7 +224,8 @@ struct bt_packet *bt_packet_create(const struct bt_stream *c_stream)
        BT_ASSERT_PRE_NON_NULL(stream, "Stream");
        packet = bt_object_pool_create_object(&stream->packet_pool);
        if (G_UNLIKELY(!packet)) {
-               BT_LIB_LOGE("Cannot allocate one packet from stream's packet pool: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot allocate one packet from stream's packet pool: "
                        "%![stream-]+s", stream);
                goto end;
        }
index 7abea88491b456bdba8a7876608c99afd23cadf2..fe0d8259125d438351751237301c6ebe7546ae48 100644 (file)
@@ -120,7 +120,8 @@ struct bt_stream_class *create_stream_class_with_id(
                tc, id);
        stream_class = g_new0(struct bt_stream_class, 1);
        if (!stream_class) {
-               BT_LOGE_STR("Failed to allocate one stream class.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one stream class.");
                goto error;
        }
 
@@ -129,7 +130,7 @@ struct bt_stream_class *create_stream_class_with_id(
 
        stream_class->name.str = g_string_new(NULL);
        if (!stream_class->name.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                ret = -1;
                goto end;
        }
@@ -140,7 +141,7 @@ struct bt_stream_class *create_stream_class_with_id(
        stream_class->event_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!stream_class->event_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -149,7 +150,8 @@ struct bt_stream_class *create_stream_class_with_id(
                (bt_object_pool_destroy_object_func) free_field_wrapper,
                stream_class);
        if (ret) {
-               BT_LOGE("Failed to initialize packet context field pool: ret=%d",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize packet context field pool: ret=%d",
                        ret);
                goto error;
        }
index 1904143708186babd4969cdcd1a5a26318863332..81f212da57865856c9ba5beb52414f77df8795b6 100644 (file)
@@ -114,14 +114,14 @@ struct bt_stream *create_stream_with_id(struct bt_stream_class *stream_class,
                trace, id);
        stream = g_new0(struct bt_stream, 1);
        if (!stream) {
-               BT_LOGE_STR("Failed to allocate one stream.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one stream.");
                goto error;
        }
 
        bt_object_init_shared_with_parent(&stream->base, destroy_stream);
        stream->name.str = g_string_new(NULL);
        if (!stream->name.str) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
@@ -131,7 +131,8 @@ struct bt_stream *create_stream_with_id(struct bt_stream_class *stream_class,
                (bt_object_pool_destroy_object_func) bt_stream_free_packet,
                stream);
        if (ret) {
-               BT_LOGE("Failed to initialize packet pool: ret=%d", ret);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to initialize packet pool: ret=%d", ret);
                goto error;
        }
 
index a78c42a0ce1bffdf88cc97faac91ebfb0eb1bc50..1201534c919d4fd0cb74291879a140519c1c8435 100644 (file)
@@ -139,7 +139,7 @@ struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp)
        BT_LOGD_STR("Creating default trace class object.");
        tc = g_new0(struct bt_trace_class, 1);
        if (!tc) {
-               BT_LOGE_STR("Failed to allocate one trace class.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one trace class.");
                goto error;
        }
 
@@ -148,26 +148,26 @@ struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp)
        tc->stream_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!tc->stream_classes) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                goto error;
        }
 
        tc->name.str = g_string_new(NULL);
        if (!tc->name.str) {
-               BT_LOGE_STR("Failed to allocate one GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
                goto error;
        }
 
        tc->environment = bt_attributes_create();
        if (!tc->environment) {
-               BT_LOGE_STR("Cannot create empty attributes object.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object.");
                goto error;
        }
 
        tc->destruction_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_trace_class_destruction_listener_elem));
        if (!tc->destruction_listeners) {
-               BT_LOGE_STR("Failed to allocate one GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray.");
                goto error;
        }
 
@@ -318,7 +318,8 @@ enum bt_trace_class_set_environment_entry_status set_environment_entry(
                value);
        if (ret) {
                ret = BT_FUNC_STATUS_MEMORY_ERROR;
-               BT_LIB_LOGE("Cannot set trace class's environment entry: "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot set trace class's environment entry: "
                        "%![tc-]+T, entry-name=\"%s\"", tc, name);
        } else {
                bt_value_freeze(value);
@@ -340,7 +341,8 @@ bt_trace_class_set_environment_entry_string(
        BT_ASSERT_PRE_NON_NULL(value, "Value");
        value_obj = bt_value_string_create_init(value);
        if (!value_obj) {
-               BT_LOGE_STR("Cannot create a string value object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create a string value object.");
                ret = -1;
                goto end;
        }
@@ -363,7 +365,8 @@ bt_trace_class_set_environment_entry_integer(
        BT_ASSERT_PRE_NON_NULL(name, "Name");
        value_obj = bt_value_signed_integer_create_init(value);
        if (!value_obj) {
-               BT_LOGE_STR("Cannot create an integer value object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create an integer value object.");
                ret = BT_FUNC_STATUS_MEMORY_ERROR;
                goto end;
        }
index fdaa7bad1a6627f241e2fe02634242ea10997787..b7fca04bc23705f3ce615e15d5e6a548baa6d2e8 100644 (file)
@@ -142,7 +142,7 @@ struct bt_trace *bt_trace_create(struct bt_trace_class *tc)
        BT_LIB_LOGD("Creating trace object: %![tc-]+T", tc);
        trace = g_new0(struct bt_trace, 1);
        if (!trace) {
-               BT_LOGE_STR("Failed to allocate one trace.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one trace.");
                goto error;
        }
 
@@ -150,27 +150,27 @@ struct bt_trace *bt_trace_create(struct bt_trace_class *tc)
        trace->streams = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!trace->streams) {
-               BT_LOGE_STR("Failed to allocate one GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
                goto error;
        }
 
        trace->stream_classes_stream_count = g_hash_table_new(g_direct_hash,
                g_direct_equal);
        if (!trace->stream_classes_stream_count) {
-               BT_LOGE_STR("Failed to allocate one GHashTable.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GHashTable.");
                goto error;
        }
 
        trace->name.str = g_string_new(NULL);
        if (!trace->name.str) {
-               BT_LOGE_STR("Failed to allocate one GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
                goto error;
        }
 
        trace->destruction_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_trace_destruction_listener_elem));
        if (!trace->destruction_listeners) {
-               BT_LOGE_STR("Failed to allocate one GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray.");
                goto error;
        }
 
index 285971d43b1573c9aa1f388aacb36f83f9ad356f..0d42e8795ba22b8133c04ab0d72a3a6f29674f74 100644 (file)
@@ -178,7 +178,7 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj)
        typed_array_obj = BT_VALUE_TO_ARRAY(array_obj);
        copy_obj = bt_value_array_create();
        if (!copy_obj) {
-               BT_LOGE_STR("Cannot create empty array value.");
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
                goto end;
        }
 
@@ -193,7 +193,8 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj)
                        "index=%d", element_obj, i);
                ret = bt_value_copy(element_obj, &element_obj_copy);
                if (ret) {
-                       BT_LOGE("Cannot copy array value's element: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot copy array value's element: "
                                "array-addr=%p, index=%d",
                                array_obj, i);
                        BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
@@ -205,7 +206,8 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj)
                        (void *) element_obj_copy);
                BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy);
                if (ret) {
-                       BT_LOGE("Cannot append to array value: addr=%p",
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot append to array value: addr=%p",
                                array_obj);
                        BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
                        goto end;
@@ -246,7 +248,8 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj)
                        "key=\"%s\"", element_obj, key_str);
                ret = bt_value_copy(element_obj, &element_obj_copy);
                if (ret) {
-                       BT_LOGE("Cannot copy map value's element: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot copy map value's element: "
                                "map-addr=%p, key=\"%s\"",
                                map_obj, key_str);
                        BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
@@ -258,7 +261,8 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj)
                        (void *) element_obj_copy);
                BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy);
                if (ret) {
-                       BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"",
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot insert into map value: addr=%p, key=\"%s\"",
                                map_obj, key_str);
                        BT_OBJECT_PUT_REF_AND_RESET(copy_obj);
                        goto end;
@@ -581,7 +585,8 @@ struct bt_value *bt_value_bool_create_init(bt_bool val)
        BT_LOGD("Creating boolean value object: val=%d", val);
        bool_obj = g_new0(struct bt_value_bool, 1);
        if (!bool_obj) {
-               BT_LOGE_STR("Failed to allocate one boolean value object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one boolean value object.");
                goto end;
        }
 
@@ -617,7 +622,8 @@ struct bt_value *bt_value_integer_create_init(enum bt_value_type type,
 
        integer_obj = g_new0(struct bt_value_integer, 1);
        if (!integer_obj) {
-               BT_LOGE_STR("Failed to allocate one integer value object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one integer value object.");
                goto end;
        }
 
@@ -660,7 +666,8 @@ struct bt_value *bt_value_real_create_init(double val)
        BT_LOGD("Creating real number value object: val=%f", val);
        real_obj = g_new0(struct bt_value_real, 1);
        if (!real_obj) {
-               BT_LOGE_STR("Failed to allocate one real number value object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one real number value object.");
                goto end;
        }
 
@@ -682,22 +689,20 @@ struct bt_value *bt_value_string_create_init(const char *val)
 {
        struct bt_value_string *string_obj = NULL;
 
-       if (!val) {
-               BT_LOGW_STR("Invalid parameter: value is NULL.");
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(val, "Value");
        BT_LOGD("Creating string value object: val-len=%zu", strlen(val));
        string_obj = g_new0(struct bt_value_string, 1);
        if (!string_obj) {
-               BT_LOGE_STR("Failed to allocate one string object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one string object.");
                goto end;
        }
 
        string_obj->base = bt_value_create_base(BT_VALUE_TYPE_STRING);
        string_obj->gstr = g_string_new(val);
        if (!string_obj->gstr) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate a GString.");
                g_free(string_obj);
                string_obj = NULL;
                goto end;
@@ -722,7 +727,8 @@ struct bt_value *bt_value_array_create(void)
        BT_LOGD_STR("Creating empty array value object.");
        array_obj = g_new0(struct bt_value_array, 1);
        if (!array_obj) {
-               BT_LOGE_STR("Failed to allocate one array object.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one array object.");
                goto end;
        }
 
@@ -730,7 +736,7 @@ struct bt_value *bt_value_array_create(void)
        array_obj->garray = bt_g_ptr_array_new_full(0,
                (GDestroyNotify) bt_object_put_ref);
        if (!array_obj->garray) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                g_free(array_obj);
                array_obj = NULL;
                goto end;
@@ -750,7 +756,7 @@ struct bt_value *bt_value_map_create(void)
        BT_LOGD_STR("Creating empty map value object.");
        map_obj = g_new0(struct bt_value_map, 1);
        if (!map_obj) {
-               BT_LOGE_STR("Failed to allocate one map object.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
                goto end;
        }
 
@@ -758,7 +764,7 @@ struct bt_value *bt_value_map_create(void)
        map_obj->ght = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                NULL, (GDestroyNotify) bt_object_put_ref);
        if (!map_obj->ght) {
-               BT_LOGE_STR("Failed to allocate a GHashTable.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
                g_free(map_obj);
                map_obj = NULL;
                goto end;
@@ -1229,7 +1235,7 @@ bt_bool extend_map_element(const char *key,
        extend_data->status = bt_value_copy(extension_obj_elem,
                &extension_obj_elem_copy);
        if (extend_data->status) {
-               BT_LOGE("Cannot copy map element: addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
                        extension_obj_elem);
                goto error;
        }
@@ -1241,8 +1247,9 @@ bt_bool extend_map_element(const char *key,
                extend_data->extended_obj, key,
                (void *) extension_obj_elem_copy);
        if (extend_data->status) {
-               BT_LOGE("Cannot replace value in extended value: key=\"%s\", "
-                       "extended-value-addr=%p, element-value-addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot replace value in extended value: key=\"%s\", "
+                       "%![extended-value-]+v, %![element-value-]+v",
                        key, extend_data->extended_obj,
                        extension_obj_elem_copy);
                goto error;
@@ -1282,7 +1289,8 @@ enum bt_value_map_extend_status bt_value_map_extend(
        /* Create copy of base map object to start with */
        extend_data.status = bt_value_copy(base_map_obj, extended_map_obj);
        if (extend_data.status) {
-               BT_LOGE("Cannot copy base value: base-value-addr=%p",
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot copy base value: %![base-value-]+v",
                        base_map_obj);
                goto error;
        }
@@ -1297,14 +1305,16 @@ enum bt_value_map_extend_status bt_value_map_extend(
 
        if (bt_value_map_foreach_entry_const(extension_obj, extend_map_element,
                        &extend_data)) {
-               BT_LOGE("Cannot iterate on the extension object's elements: "
-                       "extension-value-addr=%p", extension_obj);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot iterate on the extension object's elements: "
+                       "%![extension-value-]+v", extension_obj);
                goto error;
        }
 
        if (extend_data.status) {
-               BT_LOGE("Failed to successfully iterate on the extension object's elements: "
-                       "extension-value-addr=%p", extension_obj);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to successfully iterate on the extension object's elements: "
+                       "%![extension-value-]+v", extension_obj);
                goto error;
        }
 
@@ -1335,7 +1345,7 @@ enum bt_value_copy_status bt_value_copy(const struct bt_value *object,
        } else {
                status = BT_FUNC_STATUS_MEMORY_ERROR;
                *copy_obj = NULL;
-               BT_LOGE_STR("Failed to copy value object.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
        }
 
        return status;
index faac47995336c6dcb182435c231f6d785363e6f1..bc3f37d58eddb32ecc999a09194a115ccf33816b 100644 (file)
@@ -20,6 +20,7 @@ if !ENABLE_BUILT_IN_PLUGINS
 libbabeltrace2_python_plugin_provider_la_LIBADD += \
        $(top_builddir)/src/logging/libbabeltrace2-logging.la \
        $(top_builddir)/src/common/libbabeltrace2-common.la \
+       $(top_builddir)/src/py-common/libbabeltrace2-py-common.la \
        $(top_builddir)/src/lib/libbabeltrace2.la
 endif
 endif # ENABLE_PYTHON_PLUGINS
index a2d136a9d9ab7492f74b268c765eaeb7f6a903b8..bd278e560ce087e491200863a919a341b8a2a16c 100644 (file)
@@ -32,7 +32,9 @@
 #include <babeltrace2/plugin/plugin-const.h>
 #include "lib/plugin/plugin.h"
 #include <babeltrace2/graph/component-class.h>
+#include <babeltrace2/current-thread.h>
 #include "lib/graph/component-class.h"
+#include "py-common/py-common.h"
 #include <stdlib.h>
 #include <signal.h>
 #include <Python.h>
@@ -65,12 +67,46 @@ static PyObject *py_try_load_plugin_module_func = NULL;
 static bool python_was_initialized_by_us;
 
 static
-void print_python_traceback(int log_level)
+void append_python_traceback_error_cause(void)
 {
-       if (BT_LOG_ON(log_level) && Py_IsInitialized() && PyErr_Occurred()) {
+       GString *exc = NULL;
+
+       if (Py_IsInitialized() && PyErr_Occurred()) {
+               exc = bt_py_common_format_exception(BT_LOG_OUTPUT_LEVEL);
+               if (!exc) {
+                       BT_LOGE_STR("Failed to format Python exception.");
+                       goto end;
+               }
+
+               (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
+                       "Babeltrace library", "%s", exc->str);
+       }
+
+end:
+       if (exc) {
+               g_string_free(exc, TRUE);
+       }
+}
+
+static
+void log_python_traceback(int log_level)
+{
+       GString *exc = NULL;
+
+       if (Py_IsInitialized() && PyErr_Occurred()) {
+               exc = bt_py_common_format_exception(BT_LOG_OUTPUT_LEVEL);
+               if (!exc) {
+                       BT_LOGE_STR("Failed to format Python exception.");
+                       goto end;
+               }
+
                BT_LOG_WRITE(log_level, BT_LOG_TAG,
-                       "Exception occured: Python traceback: ");
-               PyErr_Print();
+                       "Exception occured: Python traceback:\n%s", exc->str);
+       }
+
+end:
+       if (exc) {
+               g_string_free(exc, TRUE);
        }
 }
 
@@ -83,16 +119,28 @@ void pyerr_clear(void)
 }
 
 static
-void init_python(void)
+int init_python(void)
 {
+       int ret = BT_FUNC_STATUS_OK;
        PyObject *py_bt2_py_plugin_mod = NULL;
        const char *dis_python_env;
 #ifndef __MINGW32__
        sig_t old_sigint = signal(SIGINT, SIG_DFL);
 #endif
 
-       if (python_state != PYTHON_STATE_NOT_INITED) {
+       switch (python_state) {
+       case PYTHON_STATE_NOT_INITED:
+               break;
+       case PYTHON_STATE_FULLY_INITIALIZED:
+               goto end;
+       case PYTHON_STATE_WONT_INITIALIZE:
+               ret = BT_FUNC_STATUS_NOT_FOUND;
                goto end;
+       case PYTHON_STATE_CANNOT_INITIALIZE:
+               ret = BT_FUNC_STATUS_ERROR;
+               goto end;
+       default:
+               abort();
        }
 
        /*
@@ -104,6 +152,7 @@ void init_python(void)
        if (dis_python_env && strcmp(dis_python_env, "1") == 0) {
                BT_LOGI_STR("Python plugin support is disabled because `BABELTRACE_DISABLE_PYTHON_PLUGINS=1`.");
                python_state = PYTHON_STATE_WONT_INITIALIZE;
+               ret = BT_FUNC_STATUS_NOT_FOUND;
                goto end;
        }
 
@@ -120,16 +169,24 @@ void init_python(void)
 
        py_bt2_py_plugin_mod = PyImport_ImportModule("bt2.py_plugin");
        if (!py_bt2_py_plugin_mod) {
-               BT_LOGW_STR("Cannot import bt2.py_plugin Python module: Python plugin support is disabled.");
+               append_python_traceback_error_cause();
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Cannot import `bt2.py_plugin` Python module: "
+                       "Python plugin support is disabled.");
                python_state = PYTHON_STATE_CANNOT_INITIALIZE;
+               ret = BT_FUNC_STATUS_ERROR;
                goto end;
        }
 
        py_try_load_plugin_module_func =
                PyObject_GetAttrString(py_bt2_py_plugin_mod, "_try_load_plugin_module");
        if (!py_try_load_plugin_module_func) {
-               BT_LOGW_STR("Cannot get _try_load_plugin_module attribute from bt2.py_plugin Python module: Python plugin support is disabled.");
+               append_python_traceback_error_cause();
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Cannot get `_try_load_plugin_module` attribute from `bt2.py_plugin` Python module: "
+                       "Python plugin support is disabled.");
                python_state = PYTHON_STATE_CANNOT_INITIALIZE;
+               ret = BT_FUNC_STATUS_ERROR;
                goto end;
        }
 
@@ -142,10 +199,11 @@ end:
        }
 #endif
 
-       print_python_traceback(BT_LOG_WARN);
+       log_python_traceback(ret == BT_FUNC_STATUS_ERROR ?
+               BT_LOG_WARN : BT_LOG_INFO);
        pyerr_clear();
        Py_XDECREF(py_bt2_py_plugin_mod);
-       return;
+       return ret;
 }
 
 __attribute__((destructor)) static
@@ -167,7 +225,7 @@ static
 int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
                bool fail_on_load_error, bt_plugin **plugin_out)
 {
-       int status = __BT_FUNC_STATUS_OK;
+       int status = BT_FUNC_STATUS_OK;
        PyObject *py_name = NULL;
        PyObject *py_author = NULL;
        PyObject *py_description = NULL;
@@ -187,104 +245,165 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
        BT_ASSERT(python_state == PYTHON_STATE_FULLY_INITIALIZED);
        py_name = PyObject_GetAttrString(plugin_info, "name");
        if (!py_name) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `name` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `name` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `name` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        py_author = PyObject_GetAttrString(plugin_info, "author");
        if (!py_author) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `author` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `author` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `author` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        py_description = PyObject_GetAttrString(plugin_info, "description");
        if (!py_description) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `desciption` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `description` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `description` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        py_license = PyObject_GetAttrString(plugin_info, "license");
        if (!py_license) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `license` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `license` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `license` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        py_version = PyObject_GetAttrString(plugin_info, "version");
        if (!py_version) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `version` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `version` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `version` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        py_comp_class_addrs = PyObject_GetAttrString(plugin_info,
                "comp_class_addrs");
        if (!py_comp_class_addrs) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot find `comp_class_addrs` attribute in Python plugin info object: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot find `comp_class_addrs` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot find `comp_class_addrs` attribute in Python plugin info object: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        if (PyUnicode_Check(py_name)) {
                name = PyUnicode_AsUTF8(py_name);
                if (!name) {
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "Cannot decode Python plugin name string: "
-                               "py-plugin-info-addr=%p", plugin_info);
-                       status = fail_on_load_error ?
-                               __BT_FUNC_STATUS_LOADING_ERROR :
-                               __BT_FUNC_STATUS_NOT_FOUND;
+                       if (fail_on_load_error) {
+                               append_python_traceback_error_cause();
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Cannot decode Python plugin name string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Cannot decode Python plugin name string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_NOT_FOUND;
+                       }
+
                        goto error;
                }
        } else {
                /* Plugin name is mandatory */
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Plugin name is not a string: "
-                       "py-plugin-info-addr=%p", plugin_info);
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Plugin name is not a string: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Plugin name is not a string: "
+                               "py-plugin-info-addr=%p", plugin_info);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
        if (PyUnicode_Check(py_author)) {
                author = PyUnicode_AsUTF8(py_author);
                if (!author) {
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "Cannot decode Python plugin author string: "
-                               "py-plugin-info-addr=%p", plugin_info);
-                       status = fail_on_load_error ?
-                               __BT_FUNC_STATUS_LOADING_ERROR :
-                               __BT_FUNC_STATUS_NOT_FOUND;
+                       if (fail_on_load_error) {
+                               append_python_traceback_error_cause();
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Cannot decode Python plugin author string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Cannot decode Python plugin author string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_NOT_FOUND;
+                       }
+
                        goto error;
                }
        }
@@ -292,13 +411,19 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
        if (PyUnicode_Check(py_description)) {
                description = PyUnicode_AsUTF8(py_description);
                if (!description) {
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "Cannot decode Python plugin description string: "
-                               "py-plugin-info-addr=%p", plugin_info);
-                       status = fail_on_load_error ?
-                               __BT_FUNC_STATUS_LOADING_ERROR :
-                               __BT_FUNC_STATUS_NOT_FOUND;
+                       if (fail_on_load_error) {
+                               append_python_traceback_error_cause();
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Cannot decode Python plugin description string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Cannot decode Python plugin description string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_NOT_FOUND;
+                       }
+
                        goto error;
                }
        }
@@ -306,13 +431,19 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
        if (PyUnicode_Check(py_license)) {
                license = PyUnicode_AsUTF8(py_license);
                if (!license) {
-                       BT_LOG_WRITE(fail_on_load_error ?
-                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                               "Cannot decode Python plugin license string: "
-                               "py-plugin-info-addr=%p", plugin_info);
-                       status = fail_on_load_error ?
-                               __BT_FUNC_STATUS_LOADING_ERROR :
-                               __BT_FUNC_STATUS_NOT_FOUND;
+                       if (fail_on_load_error) {
+                               append_python_traceback_error_cause();
+                               BT_LIB_LOGW_APPEND_CAUSE(
+                                       "Cannot decode Python plugin license string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                       } else {
+                               BT_LIB_LOGI(
+                                       "Cannot decode Python plugin license string: "
+                                       "py-plugin-info-addr=%p", plugin_info);
+                               status = BT_FUNC_STATUS_NOT_FOUND;
+                       }
+
                        goto error;
                }
        }
@@ -341,13 +472,19 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
 
                        if (PyErr_Occurred()) {
                                /* Overflow error, most probably */
-                               BT_LOG_WRITE(fail_on_load_error ?
-                                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                                       "Invalid Python plugin version format: "
-                                       "py-plugin-info-addr=%p", plugin_info);
-                               status = fail_on_load_error ?
-                                       __BT_FUNC_STATUS_LOADING_ERROR :
-                                       __BT_FUNC_STATUS_NOT_FOUND;
+                               if (fail_on_load_error) {
+                                       append_python_traceback_error_cause();
+                                       BT_LIB_LOGW_APPEND_CAUSE(
+                                               "Invalid Python plugin version format: "
+                                               "py-plugin-info-addr=%p", plugin_info);
+                                       status = BT_FUNC_STATUS_LOADING_ERROR;
+                               } else {
+                                       BT_LIB_LOGI(
+                                               "Invalid Python plugin version format: "
+                                               "py-plugin-info-addr=%p", plugin_info);
+                                       status = BT_FUNC_STATUS_NOT_FOUND;
+                               }
+
                                goto error;
                        }
                }
@@ -360,13 +497,19 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
                        if (PyUnicode_Check(py_extra)) {
                                version_extra = PyUnicode_AsUTF8(py_extra);
                                if (!version_extra) {
-                                       BT_LOG_WRITE(fail_on_load_error ?
-                                               BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                                               "Cannot decode Python plugin version's extra string: "
-                                               "py-plugin-info-addr=%p", plugin_info);
-                                       status = fail_on_load_error ?
-                                               __BT_FUNC_STATUS_LOADING_ERROR :
-                                               __BT_FUNC_STATUS_NOT_FOUND;
+                                       if (fail_on_load_error) {
+                                               append_python_traceback_error_cause();
+                                               BT_LIB_LOGW_APPEND_CAUSE(
+                                                       "Cannot decode Python plugin version's extra string: "
+                                                       "py-plugin-info-addr=%p", plugin_info);
+                                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                                       } else {
+                                               BT_LIB_LOGI(
+                                                       "Cannot decode Python plugin version's extra string: "
+                                                       "py-plugin-info-addr=%p", plugin_info);
+                                               status = BT_FUNC_STATUS_NOT_FOUND;
+                                       }
+
                                        goto error;
                                }
                        }
@@ -375,8 +518,8 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
 
        *plugin_out = bt_plugin_create_empty(BT_PLUGIN_TYPE_PYTHON);
        if (!*plugin_out) {
-               BT_LOGE_STR("Cannot create empty plugin object.");
-               status = __BT_FUNC_STATUS_MEMORY_ERROR;
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin object.");
+               status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto error;
        }
 
@@ -409,15 +552,19 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
                        if (PyLong_Check(py_comp_class_addr)) {
                                comp_class = PyLong_AsVoidPtr(py_comp_class_addr);
                        } else {
-                               BT_LOG_WRITE(fail_on_load_error ?
-                                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                                       "Component class address is not an integer in Python plugin info object: "
-                                       "py-plugin-info-addr=%p, index=%zu",
-                                       plugin_info, i);
-
                                if (fail_on_load_error) {
-                                       status = __BT_FUNC_STATUS_LOADING_ERROR;
-                                       goto error;
+                                       append_python_traceback_error_cause();
+                                       BT_LIB_LOGW_APPEND_CAUSE(
+                                               "Component class address is not an integer in Python plugin info object: "
+                                               "py-plugin-info-addr=%p, index=%zu",
+                                               plugin_info, i);
+                                       status = BT_FUNC_STATUS_LOADING_ERROR;
+                               } else {
+                                       BT_LIB_LOGI(
+                                               "Component class address is not an integer in Python plugin info object: "
+                                               "py-plugin-info-addr=%p, index=%zu",
+                                               plugin_info, i);
+                                       status = BT_FUNC_STATUS_NOT_FOUND;
                                }
 
                                continue;
@@ -426,7 +573,8 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
                        status = bt_plugin_add_component_class(*plugin_out,
                                comp_class);
                        if (status < 0) {
-                               BT_LOGE("Cannot add component class to plugin: "
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot add component class to plugin: "
                                        "py-plugin-info-addr=%p, "
                                        "plugin-addr=%p, plugin-name=\"%s\", "
                                        "comp-class-addr=%p, "
@@ -446,8 +594,8 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
        goto end;
 
 error:
-       BT_ASSERT(status != __BT_FUNC_STATUS_OK);
-       print_python_traceback(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO);
+       BT_ASSERT(status != BT_FUNC_STATUS_OK);
+       log_python_traceback(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO);
        pyerr_clear();
        BT_OBJECT_PUT_REF_AND_RESET(*plugin_out);
 
@@ -469,7 +617,7 @@ int bt_plugin_python_create_all_from_file(const char *path,
        PyObject *py_plugin_info = NULL;
        gchar *basename = NULL;
        size_t path_len;
-       int status = __BT_FUNC_STATUS_OK;
+       int status = BT_FUNC_STATUS_OK;
 
        BT_ASSERT(path);
 
@@ -479,7 +627,9 @@ int bt_plugin_python_create_all_from_file(const char *path,
                 * here because we already know Python cannot be fully
                 * initialized.
                 */
-               status = __BT_FUNC_STATUS_ERROR;
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Python interpreter could not be initialized previously.");
+               status = BT_FUNC_STATUS_ERROR;
                goto error;
        } else if (python_state == PYTHON_STATE_WONT_INITIALIZE) {
                /*
@@ -487,7 +637,8 @@ int bt_plugin_python_create_all_from_file(const char *path,
                 * Python plugins are disabled, so it's simply not
                 * found.
                 */
-               status = __BT_FUNC_STATUS_NOT_FOUND;
+               BT_LOGI_STR("Python plugin support was disabled previously because `BABELTRACE_DISABLE_PYTHON_PLUGINS=1`.");
+               status = BT_FUNC_STATUS_NOT_FOUND;
                goto error;
        }
 
@@ -500,15 +651,16 @@ int bt_plugin_python_create_all_from_file(const char *path,
                        PYTHON_PLUGIN_FILE_EXT,
                        PYTHON_PLUGIN_FILE_EXT_LEN) != 0) {
                BT_LOGI("Skipping non-Python file: path=\"%s\"", path);
-               status = __BT_FUNC_STATUS_NOT_FOUND;
+               status = BT_FUNC_STATUS_NOT_FOUND;
                goto error;
        }
 
        /* File name starts with `bt_plugin_` */
        basename = g_path_get_basename(path);
        if (!basename) {
-               BT_LOGE("Cannot get path's basename: path=\"%s\"", path);
-               status = __BT_FUNC_STATUS_ERROR;
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot get path's basename: path=\"%s\"", path);
+               status = BT_FUNC_STATUS_ERROR;
                goto error;
        }
 
@@ -516,7 +668,7 @@ int bt_plugin_python_create_all_from_file(const char *path,
                        PYTHON_PLUGIN_FILE_PREFIX_LEN) != 0) {
                BT_LOGI("Skipping Python file not starting with `%s`: "
                        "path=\"%s\"", PYTHON_PLUGIN_FILE_PREFIX, path);
-               status = __BT_FUNC_STATUS_NOT_FOUND;
+               status = BT_FUNC_STATUS_NOT_FOUND;
                goto error;
        }
 
@@ -528,23 +680,9 @@ int bt_plugin_python_create_all_from_file(const char *path,
         * have any potential Python plugins, you don't need to endure
         * this waiting time everytime you load the library.
         */
-       init_python();
-       if (python_state == PYTHON_STATE_WONT_INITIALIZE) {
-               /*
-                * This is not an error: the environment requires that
-                * Python plugins are disabled, so it's simply not
-                * found.
-                */
-               status = __BT_FUNC_STATUS_NOT_FOUND;
-               goto error;
-       } else if (python_state != PYTHON_STATE_FULLY_INITIALIZED) {
-               /*
-                * For some reason we cannot initialize Python,
-                * import the required modules, and get the required
-                * attributes from them.
-                */
-               BT_LOGE("Failed to initialize Python interpreter.");
-               status = __BT_FUNC_STATUS_ERROR;
+       status = init_python();
+       if (status != BT_FUNC_STATUS_OK) {
+               /* init_python() logs and append errors */
                goto error;
        }
 
@@ -558,14 +696,17 @@ int bt_plugin_python_create_all_from_file(const char *path,
        py_plugin_info = PyObject_CallFunction(py_try_load_plugin_module_func,
                "(s)", path);
        if (!py_plugin_info || py_plugin_info == Py_None) {
-               BT_LOG_WRITE(fail_on_load_error ?
-                       BT_LOG_WARN : BT_LOG_INFO, BT_LOG_TAG,
-                       "Cannot load Python plugin: path=\"%s\"", path);
-               print_python_traceback(fail_on_load_error ? BT_LOG_WARN :
-                       BT_LOG_INFO);
-               PyErr_Clear();
-               status = fail_on_load_error ? __BT_FUNC_STATUS_LOADING_ERROR :
-                       __BT_FUNC_STATUS_NOT_FOUND;
+               if (fail_on_load_error) {
+                       append_python_traceback_error_cause();
+                       BT_LIB_LOGW_APPEND_CAUSE(
+                               "Cannot load Python plugin: path=\"%s\"", path);
+                       status = BT_FUNC_STATUS_LOADING_ERROR;
+               } else {
+                       BT_LIB_LOGI(
+                               "Cannot load Python plugin: path=\"%s\"", path);
+                       status = BT_FUNC_STATUS_NOT_FOUND;
+               }
+
                goto error;
        }
 
@@ -580,23 +721,24 @@ int bt_plugin_python_create_all_from_file(const char *path,
                 * bt_plugin_from_python_plugin_info() handles
                 * `fail_on_load_error`, so this is a "real" error.
                 */
-               BT_LOGW("Cannot create plugin object from Python plugin info object: "
+               BT_LIB_LOGW_APPEND_CAUSE(
+                       "Cannot create plugin object from Python plugin info object: "
                        "path=\"%s\", py-plugin-info-addr=%p",
                        path, py_plugin_info);
                BT_ASSERT(!plugin);
                goto error;
-       } else if (status == __BT_FUNC_STATUS_NOT_FOUND) {
+       } else if (status == BT_FUNC_STATUS_NOT_FOUND) {
                BT_ASSERT(!plugin);
                goto error;
        }
 
-       BT_ASSERT(status == __BT_FUNC_STATUS_OK);
+       BT_ASSERT(status == BT_FUNC_STATUS_OK);
        BT_ASSERT(plugin);
        bt_plugin_set_path(plugin, path);
        *plugin_set_out = bt_plugin_set_create();
        if (!*plugin_set_out) {
-               BT_LOGE_STR("Cannot create empty plugin set.");
-               status = __BT_FUNC_STATUS_MEMORY_ERROR;
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
+               status = BT_FUNC_STATUS_MEMORY_ERROR;
                goto error;
        }
 
@@ -607,12 +749,18 @@ int bt_plugin_python_create_all_from_file(const char *path,
        goto end;
 
 error:
-       BT_ASSERT(status != __BT_FUNC_STATUS_OK);
+       BT_ASSERT(status != BT_FUNC_STATUS_OK);
+       log_python_traceback(fail_on_load_error ? BT_LOG_WARN : BT_LOG_INFO);
+       pyerr_clear();
        BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out);
 
 end:
        bt_plugin_put_ref(plugin);
        Py_XDECREF(py_plugin_info);
-       g_free(basename);
+
+       if (basename) {
+               g_free(basename);
+       }
+
        return status;
 }
This page took 0.140552 seconds and 4 git commands to generate.