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;
}
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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)
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;
}
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;
}
(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;
}
(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;
}
(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;
}
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;
}
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;
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;
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;
}
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;
}
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;
}
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;
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);
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);
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);
* 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"
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;
}
}
"%!+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();
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;
}
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,
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;
}
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;
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) {
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;
}
}
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;
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;
}
"%![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;
}
/* 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;
}
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;
}
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));
/* 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;
}
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;
}
*/
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
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
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;
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;
}
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;
destroy_auto_seek_stream_states(stream_states);
stream_states = NULL;
}
+
set_iterator_state_after_seeking(iterator, status);
return status;
}
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;
}
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;
}
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;
}
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;
}
* 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"
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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);
}
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;
}
(*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;
}
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;
}
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;
}
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;
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;
}
}
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;
}
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
(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;
}
}
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;
}
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;
}
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;
}
* `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;
}
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;
}
(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;
}
}
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;
}
}
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;
}
}
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;
}
#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>
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 */
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.");
*/
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,
* 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
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());
}
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) {
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;
}
"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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
}
* 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;
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;
}
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;
}
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;
}
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;
}
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;
}
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);
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;
}
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;
}
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);
}
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;
}
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;
}
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;
}
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(
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;
}
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;
}
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);
}
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: "
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);
}
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);
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;
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;
}
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;
}
* 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"
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;
}
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;
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;
}
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;
}
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;
}
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;
}
(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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
"%![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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
*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;
}
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;
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;
}
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;
}
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;
}
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;
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;
}
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;
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;
}
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;
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;
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);
&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;
}
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;
}
&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;
}
}
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;
}
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;
}
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;
}
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;
}
(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;
}
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;
}
(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;
}
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;
}
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;
}
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);
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;
}
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;
}
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;
}
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;
}
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;
}
"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);
(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;
"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);
(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;
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;
}
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;
}
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;
}
{
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;
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;
}
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;
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;
}
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;
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;
}
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;
/* 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;
}
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;
}
} 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;
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
#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>
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);
}
}
}
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();
}
/*
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;
}
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;
}
}
#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
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;
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
*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;
}
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;
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, "
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);
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);
* 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) {
/*
* 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;
}
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;
}
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;
}
* 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;
}
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;
}
* 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;
}
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;
}