#include <babeltrace/assert-internal.h>
#include <babeltrace/common-internal.h>
+#include <babeltrace/fd-cache-internal.h>
#include "bin-info.h"
#include "debug-info.h"
struct trace_ir_maps *ir_maps;
/* in_trace -> debug_info_mapping. */
GHashTable *debug_info_map;
+
+ struct bt_fd_cache fd_cache;
};
struct debug_info_source {
GQuark q_dl_open;
GQuark q_lib_load;
GQuark q_lib_unload;
+ struct bt_fd_cache *fd_cache; /* Weak ref. Owned by the iterator. */
};
static
return debug_info_src;
}
-BT_HIDDEN
+static
struct debug_info_source *debug_info_query(struct debug_info *debug_info,
int64_t vpid, uint64_t ip)
{
return dbg_info_src;
}
-BT_HIDDEN
+static
struct debug_info *debug_info_create(struct debug_info_component *comp,
- const bt_trace *trace)
+ const bt_trace *trace, struct bt_fd_cache *fdc)
{
int ret;
struct debug_info *debug_info;
+ BT_ASSERT(comp);
+ BT_ASSERT(trace);
+ BT_ASSERT(fdc);
+
debug_info = g_new0(struct debug_info, 1);
if (!debug_info) {
goto end;
}
debug_info->input_trace = trace;
+ debug_info->fd_cache = fdc;
end:
return debug_info;
return NULL;
}
-BT_HIDDEN
+static
void debug_info_destroy(struct debug_info *debug_info)
{
bt_trace_status status;
uint64_t is_pic_field_value;
event_get_payload_unsigned_integer_field_value(event,
- IS_PIC_FIELD_NAME, &is_pic_field_value);
+ IS_PIC_FIELD_NAME, &is_pic_field_value);
is_pic = is_pic_field_value == 1;
} else {
/*
VPID_FIELD_NAME, &vpid);
proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
- debug_info->vpid_to_proc_dbg_info_src, vpid);
+ debug_info->vpid_to_proc_dbg_info_src, vpid);
if (!proc_dbg_info_src) {
goto end;
}
*((uint64_t *) key) = baddr;
- bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
- key);
+ bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, key);
if (bin) {
goto end;
}
- bin = bin_info_create(path, baddr, memsz, is_pic,
+ bin = bin_info_create(debug_info->fd_cache, path, baddr, memsz, is_pic,
debug_info->comp->arg_debug_dir,
debug_info->comp->arg_target_prefix);
if (!bin) {
goto end;
}
- g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
- key, bin);
+ g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info, key, bin);
/* Ownership passed to ht. */
key = NULL;
debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace);
if (!debug_info) {
debug_info = debug_info_create(debug_it->debug_info_component,
- trace);
+ trace, &debug_it->fd_cache);
g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace,
debug_info);
bt_trace_add_destruction_listener(trace,
curr_field);
}
- status = bt_field_string_append(curr_field, ":");
- if (status != BT_FIELD_STATUS_OK) {
- BT_LOGE("Cannot set colon component of \"bin\" "
- "curr_field field's value: str-fc-addr=%p",
- curr_field);
- }
-
status = bt_field_string_append(curr_field, dbg_info_src->bin_loc);
if (status != BT_FIELD_STATUS_OK) {
BT_LOGE("Cannot set bin location component of \"bin\" "
in_message);
BT_ASSERT(in_stream);
- out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps, in_stream);
+ out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
+ in_stream);
BT_ASSERT(out_stream);
out_message = bt_message_stream_activity_end_create(
return status;
}
+static
+void debug_info_msg_iter_destroy(struct debug_info_msg_iter *debug_info_msg_iter)
+{
+ if (!debug_info_msg_iter) {
+ goto end;
+ }
+
+ if (debug_info_msg_iter->msg_iter) {
+ bt_self_component_port_input_message_iterator_put_ref(
+ debug_info_msg_iter->msg_iter);
+ }
+
+ if (debug_info_msg_iter->ir_maps) {
+ trace_ir_maps_destroy(debug_info_msg_iter->ir_maps);
+ }
+
+ if (debug_info_msg_iter->debug_info_map) {
+ g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
+ }
+
+ bt_fd_cache_fini(&debug_info_msg_iter->fd_cache);
+ g_free(debug_info_msg_iter);
+
+end:
+ return;
+}
+
BT_HIDDEN
bt_self_message_iterator_status debug_info_msg_iter_init(
bt_self_message_iterator *self_msg_iter,
bt_self_component_port_output *self_port)
{
bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
- struct bt_self_component_port_input *input_port;
- bt_self_component_port_input_message_iterator *upstream_iterator;
- struct debug_info_msg_iter *debug_info_msg_iter;
+ struct bt_self_component_port_input *input_port = NULL;
+ bt_self_component_port_input_message_iterator *upstream_iterator = NULL;
+ struct debug_info_msg_iter *debug_info_msg_iter = NULL;
gchar *debug_info_field_name;
+ int ret;
/* Borrow the upstream input port. */
input_port = bt_self_component_filter_borrow_input_port_by_name(
- self_comp, "in");
+ self_comp, "in");
if (!input_port) {
status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
- goto end;
+ goto error;
+ }
+
+ debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1);
+ if (!debug_info_msg_iter) {
+ status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
+ goto error;
}
/* Create an iterator on the upstream component. */
input_port);
if (!upstream_iterator) {
status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
- goto end;
+ goto error;
}
- debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1);
- if (!debug_info_msg_iter) {
- status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
- goto end;
- }
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
+ debug_info_msg_iter->msg_iter, upstream_iterator);
- /* Create hashtable to will contain debug info mapping. */
+ /* Create hashtable that will contain debug info mapping. */
debug_info_msg_iter->debug_info_map = g_hash_table_new_full(
- g_direct_hash, g_direct_equal,
- (GDestroyNotify) NULL,
- (GDestroyNotify) debug_info_destroy);
+ g_direct_hash, g_direct_equal, (GDestroyNotify) NULL,
+ (GDestroyNotify) debug_info_destroy);
if (!debug_info_msg_iter->debug_info_map) {
- g_free(debug_info_msg_iter);
status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
- goto end;
+ goto error;
}
debug_info_msg_iter->self_comp =
bt_self_component_filter_as_self_component(self_comp);
- BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
- debug_info_msg_iter->msg_iter, upstream_iterator);
-
debug_info_msg_iter->debug_info_component = bt_self_component_get_data(
- bt_self_component_filter_as_self_component(
- self_comp));
+ bt_self_component_filter_as_self_component(
+ self_comp));
debug_info_field_name =
debug_info_msg_iter->debug_info_component->arg_debug_info_field_name;
debug_info_msg_iter->ir_maps = trace_ir_maps_create(
- bt_self_component_filter_as_self_component(self_comp),
- debug_info_field_name);
+ bt_self_component_filter_as_self_component(self_comp),
+ debug_info_field_name);
if (!debug_info_msg_iter->ir_maps) {
- g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
- g_free(debug_info_msg_iter);
status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
- goto end;
+ goto error;
}
- bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
+ ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache);
+ if (ret) {
+ status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
+ goto error;
+ }
+ bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
debug_info_msg_iter->input_iterator = self_msg_iter;
+ goto end;
+
+error:
+ debug_info_msg_iter_destroy(debug_info_msg_iter);
end:
return status;
}
debug_info_msg_iter = bt_self_message_iterator_get_data(it);
BT_ASSERT(debug_info_msg_iter);
- bt_self_component_port_input_message_iterator_put_ref(
- debug_info_msg_iter->msg_iter);
-
- trace_ir_maps_destroy(debug_info_msg_iter->ir_maps);
- g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
-
- g_free(debug_info_msg_iter);
+ debug_info_msg_iter_destroy(debug_info_msg_iter);
}