4 * Babeltrace Debug Info Plug-in
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT"
32 #include <babeltrace/graph/notification-iterator.h>
33 #include <babeltrace/graph/private-notification-iterator.h>
34 #include <babeltrace/graph/connection.h>
35 #include <babeltrace/graph/notification.h>
36 #include <babeltrace/graph/notification-event.h>
37 #include <babeltrace/graph/notification-stream.h>
38 #include <babeltrace/graph/notification-packet.h>
39 #include <babeltrace/graph/component-filter.h>
40 #include <babeltrace/graph/private-component-filter.h>
41 #include <babeltrace/graph/private-port.h>
42 #include <babeltrace/graph/private-connection.h>
43 #include <babeltrace/graph/private-component.h>
44 #include <babeltrace/plugin/plugin-dev.h>
45 #include <plugins-common.h>
47 #include "debug-info.h"
51 gboolean
empty_trace_map(gpointer key
, gpointer value
, gpointer user_data
)
53 struct debug_info_trace
*di_trace
= value
;
55 di_trace
->trace_static
= 1;
56 debug_info_close_trace(di_trace
->debug_it
, di_trace
);
62 void destroy_debug_info_data(struct debug_info_component
*debug_info
)
64 free(debug_info
->arg_debug_info_field_name
);
69 void destroy_debug_info_component(struct bt_private_component
*component
)
71 void *data
= bt_private_component_get_user_data(component
);
72 destroy_debug_info_data(data
);
76 struct debug_info_component
*create_debug_info_component_data(void)
78 struct debug_info_component
*debug_info
;
80 debug_info
= g_new0(struct debug_info_component
, 1);
84 debug_info
->err
= stderr
;
91 void unref_trace(struct debug_info_trace
*di_trace
)
93 bt_put(di_trace
->writer_trace
);
98 void debug_info_iterator_destroy(struct bt_private_notification_iterator
*it
)
100 struct debug_info_iterator
*it_data
;
102 it_data
= bt_private_notification_iterator_get_user_data(it
);
105 if (it_data
->input_iterator_group
) {
106 g_ptr_array_free(it_data
->input_iterator_group
, TRUE
);
109 g_hash_table_foreach_remove(it_data
->trace_map
,
110 empty_trace_map
, it_data
);
111 g_hash_table_destroy(it_data
->trace_map
);
113 bt_put(it_data
->current_notification
);
114 bt_put(it_data
->input_iterator
);
120 struct bt_notification
*handle_notification(FILE *err
,
121 struct debug_info_iterator
*debug_it
,
122 struct bt_notification
*notification
)
124 struct bt_notification
*new_notification
= NULL
;
126 switch (bt_notification_get_type(notification
)) {
127 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
129 struct bt_ctf_packet
*packet
=
130 bt_notification_packet_begin_get_packet(notification
);
131 struct bt_ctf_packet
*writer_packet
;
137 writer_packet
= debug_info_new_packet(debug_it
, packet
);
138 assert(writer_packet
);
139 new_notification
= bt_notification_packet_begin_create(
141 assert(new_notification
);
143 bt_put(writer_packet
);
146 case BT_NOTIFICATION_TYPE_PACKET_END
:
148 struct bt_ctf_packet
*packet
=
149 bt_notification_packet_end_get_packet(notification
);
150 struct bt_ctf_packet
*writer_packet
;
156 writer_packet
= debug_info_close_packet(debug_it
, packet
);
157 assert(writer_packet
);
158 new_notification
= bt_notification_packet_end_create(
160 assert(new_notification
);
162 bt_put(writer_packet
);
165 case BT_NOTIFICATION_TYPE_EVENT
:
167 struct bt_ctf_event
*event
= bt_notification_event_get_event(
169 struct bt_ctf_event
*writer_event
;
170 struct bt_clock_class_priority_map
*cc_prio_map
=
171 bt_notification_event_get_clock_class_priority_map(
177 writer_event
= debug_info_output_event(debug_it
, event
);
178 assert(writer_event
);
179 new_notification
= bt_notification_event_create(writer_event
,
182 assert(new_notification
);
184 bt_put(writer_event
);
187 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
189 struct bt_ctf_stream
*stream
=
190 bt_notification_stream_begin_get_stream(notification
);
191 struct bt_ctf_stream
*writer_stream
;
197 writer_stream
= debug_info_stream_begin(debug_it
, stream
);
198 assert(writer_stream
);
199 new_notification
= bt_notification_stream_begin_create(
201 assert(new_notification
);
203 bt_put(writer_stream
);
206 case BT_NOTIFICATION_TYPE_STREAM_END
:
208 struct bt_ctf_stream
*stream
=
209 bt_notification_stream_end_get_stream(notification
);
210 struct bt_ctf_stream
*writer_stream
;
216 writer_stream
= debug_info_stream_end(debug_it
, stream
);
217 assert(writer_stream
);
218 new_notification
= bt_notification_stream_end_create(
220 assert(new_notification
);
222 bt_put(writer_stream
);
226 new_notification
= bt_get(notification
);
231 return new_notification
;
235 struct bt_notification_iterator_next_return
debug_info_iterator_next(
236 struct bt_private_notification_iterator
*iterator
)
238 struct debug_info_iterator
*debug_it
= NULL
;
239 struct bt_private_component
*component
= NULL
;
240 struct debug_info_component
*debug_info
= NULL
;
241 struct bt_notification_iterator
*source_it
= NULL
;
242 struct bt_notification
*notification
;
243 struct bt_notification_iterator_next_return ret
= {
244 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
245 .notification
= NULL
,
248 debug_it
= bt_private_notification_iterator_get_user_data(iterator
);
251 component
= bt_private_notification_iterator_get_private_component(iterator
);
253 debug_info
= bt_private_component_get_user_data(component
);
256 source_it
= debug_it
->input_iterator
;
258 ret
.status
= bt_notification_iterator_next(source_it
);
259 if (ret
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
263 notification
= bt_notification_iterator_get_notification(
266 ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
270 ret
.notification
= handle_notification(debug_info
->err
, debug_it
,
272 assert(ret
.notification
);
273 bt_put(notification
);
281 enum bt_notification_iterator_status
debug_info_iterator_init(
282 struct bt_private_notification_iterator
*iterator
,
283 struct bt_private_port
*port
)
285 enum bt_notification_iterator_status ret
=
286 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
287 enum bt_notification_iterator_status it_ret
;
288 enum bt_connection_status conn_status
;
289 struct bt_private_connection
*connection
= NULL
;
290 struct bt_private_component
*component
=
291 bt_private_notification_iterator_get_private_component(iterator
);
292 struct debug_info_iterator
*it_data
= g_new0(struct debug_info_iterator
, 1);
293 struct bt_private_port
*input_port
;
296 ret
= BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
;
300 input_port
= bt_private_component_filter_get_input_private_port_by_name(
303 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
307 connection
= bt_private_port_get_private_connection(input_port
);
310 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
314 conn_status
= bt_private_connection_create_notification_iterator(
315 connection
, NULL
, &it_data
->input_iterator
);
316 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
317 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
321 it_data
->debug_info_component
= (struct debug_info_component
*)
322 bt_private_component_get_user_data(component
);
323 it_data
->err
= it_data
->debug_info_component
->err
;
324 it_data
->trace_map
= g_hash_table_new_full(g_direct_hash
,
325 g_direct_equal
, NULL
, (GDestroyNotify
) unref_trace
);
327 it_ret
= bt_private_notification_iterator_set_user_data(iterator
, it_data
);
339 enum bt_component_status
init_from_params(
340 struct debug_info_component
*debug_info_component
,
341 struct bt_value
*params
)
343 struct bt_value
*value
= NULL
;
344 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
348 value
= bt_value_map_get(params
, "debug-info-field-name");
350 enum bt_value_status value_ret
;
353 value_ret
= bt_value_string_get(value
, &tmp
);
355 ret
= BT_COMPONENT_STATUS_INVALID
;
356 BT_LOGE_STR("Failed to retrieve debug-info-field-name value. "
357 "Expecting a string");
359 strcpy(debug_info_component
->arg_debug_info_field_name
, tmp
);
362 debug_info_component
->arg_debug_info_field_name
=
363 malloc(strlen("debug_info") + 1);
364 if (!debug_info_component
->arg_debug_info_field_name
) {
365 ret
= BT_COMPONENT_STATUS_NOMEM
;
366 BT_LOGE_STR("Missing field name.");
368 sprintf(debug_info_component
->arg_debug_info_field_name
,
371 if (ret
!= BT_COMPONENT_STATUS_OK
) {
375 value
= bt_value_map_get(params
, "debug-dir");
377 enum bt_value_status value_ret
;
379 value_ret
= bt_value_string_get(value
,
380 &debug_info_component
->arg_debug_dir
);
382 ret
= BT_COMPONENT_STATUS_INVALID
;
383 BT_LOGE_STR("Failed to retrieve debug-dir value. "
384 "Expecting a string");
388 if (ret
!= BT_COMPONENT_STATUS_OK
) {
392 value
= bt_value_map_get(params
, "target-prefix");
394 enum bt_value_status value_ret
;
396 value_ret
= bt_value_string_get(value
,
397 &debug_info_component
->arg_target_prefix
);
399 ret
= BT_COMPONENT_STATUS_INVALID
;
400 BT_LOGE_STR("Failed to retrieve target-prefix value. "
401 "Expecting a string");
405 if (ret
!= BT_COMPONENT_STATUS_OK
) {
409 value
= bt_value_map_get(params
, "full-path");
411 enum bt_value_status value_ret
;
414 value_ret
= bt_value_bool_get(value
,
417 ret
= BT_COMPONENT_STATUS_INVALID
;
418 BT_LOGE_STR("Failed to retrieve full-path value. "
419 "Expecting a boolean");
422 debug_info_component
->arg_full_path
= bool_val
;
425 if (ret
!= BT_COMPONENT_STATUS_OK
) {
433 enum bt_component_status
debug_info_component_init(
434 struct bt_private_component
*component
, struct bt_value
*params
,
435 UNUSED_VAR
void *init_method_data
)
437 enum bt_component_status ret
;
438 struct debug_info_component
*debug_info
= create_debug_info_component_data();
441 ret
= BT_COMPONENT_STATUS_NOMEM
;
445 ret
= bt_private_component_set_user_data(component
, debug_info
);
446 if (ret
!= BT_COMPONENT_STATUS_OK
) {
450 ret
= bt_private_component_filter_add_input_private_port(
451 component
, "in", NULL
, NULL
);
452 if (ret
!= BT_COMPONENT_STATUS_OK
) {
456 ret
= bt_private_component_filter_add_output_private_port(
457 component
, "out", NULL
, NULL
);
458 if (ret
!= BT_COMPONENT_STATUS_OK
) {
462 ret
= init_from_params(debug_info
, params
);
466 destroy_debug_info_data(debug_info
);
470 #ifndef BT_BUILT_IN_PLUGINS
474 /* Initialize plug-in entry points. */
475 BT_PLUGIN_WITH_ID(lttng_utils
, "lttng-utils");
476 BT_PLUGIN_DESCRIPTION_WITH_ID(lttng_utils
, "LTTng utilities");
477 BT_PLUGIN_AUTHOR_WITH_ID(lttng_utils
, "Julien Desfossez");
478 BT_PLUGIN_LICENSE_WITH_ID(lttng_utils
, "MIT");
480 BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(lttng_utils
, debug_info
, "debug-info",
481 debug_info_iterator_next
);
482 BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(lttng_utils
, debug_info
,
483 "Augment compatible events with debugging information.");
484 BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(lttng_utils
,
485 debug_info
, debug_info_component_init
);
486 BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(lttng_utils
,
487 debug_info
, destroy_debug_info_component
);
488 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(
489 lttng_utils
, debug_info
, debug_info_iterator_init
);
490 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(
491 lttng_utils
, debug_info
, debug_info_iterator_destroy
);