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/babeltrace.h>
33 #include <plugins-common.h>
34 #include <babeltrace/assert-internal.h>
35 #include "debug-info.h"
39 gboolean
empty_trace_map(gpointer key
, gpointer value
, gpointer user_data
)
41 struct debug_info_trace
*di_trace
= value
;
43 di_trace
->trace_static
= 1;
44 debug_info_close_trace(di_trace
->debug_it
, di_trace
);
50 void destroy_debug_info_data(struct debug_info_component
*debug_info
)
52 free(debug_info
->arg_debug_info_field_name
);
57 void destroy_debug_info_component(struct bt_private_component
*component
)
59 void *data
= bt_private_component_get_user_data(component
);
60 destroy_debug_info_data(data
);
64 struct debug_info_component
*create_debug_info_component_data(void)
66 struct debug_info_component
*debug_info
;
68 debug_info
= g_new0(struct debug_info_component
, 1);
72 debug_info
->err
= stderr
;
79 void unref_trace(struct debug_info_trace
*di_trace
)
81 bt_object_put_ref(di_trace
->writer_trace
);
86 void debug_info_iterator_destroy(struct bt_private_connection_private_notification_iterator
*it
)
88 struct debug_info_iterator
*it_data
;
90 it_data
= bt_private_connection_private_notification_iterator_get_user_data(it
);
93 if (it_data
->input_iterator_group
) {
94 g_ptr_array_free(it_data
->input_iterator_group
, TRUE
);
97 g_hash_table_foreach_remove(it_data
->trace_map
,
98 empty_trace_map
, it_data
);
99 g_hash_table_destroy(it_data
->trace_map
);
101 bt_object_put_ref(it_data
->current_notification
);
102 bt_object_put_ref(it_data
->input_iterator
);
108 struct bt_notification
*handle_notification(FILE *err
,
109 struct debug_info_iterator
*debug_it
,
110 struct bt_notification
*notification
)
112 struct bt_notification
*new_notification
= NULL
;
114 switch (bt_notification_get_type(notification
)) {
115 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
117 struct bt_packet
*packet
=
118 bt_notification_packet_begin_get_packet(notification
);
119 struct bt_packet
*writer_packet
;
125 writer_packet
= debug_info_new_packet(debug_it
, packet
);
126 BT_ASSERT(writer_packet
);
127 new_notification
= bt_notification_packet_begin_create(
129 BT_ASSERT(new_notification
);
130 bt_object_put_ref(packet
);
131 bt_object_put_ref(writer_packet
);
134 case BT_NOTIFICATION_TYPE_PACKET_END
:
136 struct bt_packet
*packet
=
137 bt_notification_packet_end_get_packet(notification
);
138 struct bt_packet
*writer_packet
;
144 writer_packet
= debug_info_close_packet(debug_it
, packet
);
145 BT_ASSERT(writer_packet
);
146 new_notification
= bt_notification_packet_end_create(
148 BT_ASSERT(new_notification
);
149 bt_object_put_ref(packet
);
150 bt_object_put_ref(writer_packet
);
153 case BT_NOTIFICATION_TYPE_EVENT
:
155 struct bt_event
*event
= bt_notification_event_get_event(
157 struct bt_event
*writer_event
;
158 struct bt_clock_class_priority_map
*cc_prio_map
=
159 bt_notification_event_get_clock_class_priority_map(
165 writer_event
= debug_info_output_event(debug_it
, event
);
166 BT_ASSERT(writer_event
);
167 new_notification
= bt_notification_event_create(writer_event
,
169 bt_object_put_ref(cc_prio_map
);
170 BT_ASSERT(new_notification
);
171 bt_object_put_ref(event
);
172 bt_object_put_ref(writer_event
);
175 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
177 struct bt_stream
*stream
=
178 bt_notification_stream_begin_get_stream(notification
);
179 struct bt_stream
*writer_stream
;
185 writer_stream
= debug_info_stream_begin(debug_it
, stream
);
186 BT_ASSERT(writer_stream
);
187 new_notification
= bt_notification_stream_begin_create(
189 BT_ASSERT(new_notification
);
190 bt_object_put_ref(stream
);
191 bt_object_put_ref(writer_stream
);
194 case BT_NOTIFICATION_TYPE_STREAM_END
:
196 struct bt_stream
*stream
=
197 bt_notification_stream_end_get_stream(notification
);
198 struct bt_stream
*writer_stream
;
204 writer_stream
= debug_info_stream_end(debug_it
, stream
);
205 BT_ASSERT(writer_stream
);
206 new_notification
= bt_notification_stream_end_create(
208 BT_ASSERT(new_notification
);
209 bt_object_put_ref(stream
);
210 bt_object_put_ref(writer_stream
);
214 new_notification
= bt_object_get_ref(notification
);
219 return new_notification
;
223 struct bt_notification_iterator_next_method_return
debug_info_iterator_next(
224 struct bt_private_connection_private_notification_iterator
*iterator
)
226 struct debug_info_iterator
*debug_it
= NULL
;
227 struct bt_private_component
*component
= NULL
;
228 struct debug_info_component
*debug_info
= NULL
;
229 struct bt_notification_iterator
*source_it
= NULL
;
230 struct bt_notification
*notification
;
231 struct bt_notification_iterator_next_method_return ret
= {
232 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
233 .notification
= NULL
,
236 debug_it
= bt_private_connection_private_notification_iterator_get_user_data(iterator
);
239 component
= bt_private_connection_private_notification_iterator_get_private_component(iterator
);
240 BT_ASSERT(component
);
241 debug_info
= bt_private_component_get_user_data(component
);
242 BT_ASSERT(debug_info
);
244 source_it
= debug_it
->input_iterator
;
246 ret
.status
= bt_notification_iterator_next(source_it
);
247 if (ret
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
251 notification
= bt_notification_iterator_get_notification(
254 ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
258 ret
.notification
= handle_notification(debug_info
->err
, debug_it
,
260 BT_ASSERT(ret
.notification
);
261 bt_object_put_ref(notification
);
264 bt_object_put_ref(component
);
269 enum bt_notification_iterator_status
debug_info_iterator_init(
270 struct bt_private_connection_private_notification_iterator
*iterator
,
271 struct bt_private_port
*port
)
273 enum bt_notification_iterator_status ret
=
274 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
275 enum bt_notification_iterator_status it_ret
;
276 enum bt_connection_status conn_status
;
277 struct bt_private_connection
*connection
= NULL
;
278 struct bt_private_component
*component
=
279 bt_private_connection_private_notification_iterator_get_private_component(iterator
);
280 struct debug_info_iterator
*it_data
= g_new0(struct debug_info_iterator
, 1);
281 struct bt_private_port
*input_port
;
284 ret
= BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
;
288 input_port
= bt_private_component_filter_get_input_port_by_name(
291 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
295 connection
= bt_private_port_get_connection(input_port
);
296 bt_object_put_ref(input_port
);
298 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
302 conn_status
= bt_private_connection_create_notification_iterator(
303 connection
, &it_data
->input_iterator
);
304 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
305 ret
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
309 it_data
->debug_info_component
= (struct debug_info_component
*)
310 bt_private_component_get_user_data(component
);
311 it_data
->err
= it_data
->debug_info_component
->err
;
312 it_data
->trace_map
= g_hash_table_new_full(g_direct_hash
,
313 g_direct_equal
, NULL
, (GDestroyNotify
) unref_trace
);
315 it_ret
= bt_private_connection_private_notification_iterator_set_user_data(iterator
, it_data
);
321 bt_object_put_ref(connection
);
322 bt_object_put_ref(component
);
327 enum bt_component_status
init_from_params(
328 struct debug_info_component
*debug_info_component
,
329 struct bt_value
*params
)
331 struct bt_value
*value
= NULL
;
332 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
336 value
= bt_value_map_get(params
, "debug-info-field-name");
338 enum bt_value_status value_ret
;
341 tmp
= bt_value_string_get(value
);
342 strcpy(debug_info_component
->arg_debug_info_field_name
, tmp
);
343 bt_object_put_ref(value
);
345 debug_info_component
->arg_debug_info_field_name
=
346 malloc(strlen("debug_info") + 1);
347 if (!debug_info_component
->arg_debug_info_field_name
) {
348 ret
= BT_COMPONENT_STATUS_NOMEM
;
349 BT_LOGE_STR("Missing field name.");
352 sprintf(debug_info_component
->arg_debug_info_field_name
,
355 if (ret
!= BT_COMPONENT_STATUS_OK
) {
359 value
= bt_value_map_get(params
, "debug-info-dir");
361 enum bt_value_status value_ret
;
363 debug_info_component
->arg_debug_dir
= bt_value_string_get(value
);
365 bt_object_put_ref(value
);
366 if (ret
!= BT_COMPONENT_STATUS_OK
) {
370 value
= bt_value_map_get(params
, "target-prefix");
372 enum bt_value_status value_ret
;
374 debug_info_component
->arg_target_prefix
= bt_value_string_get(value
);
376 bt_object_put_ref(value
);
377 if (ret
!= BT_COMPONENT_STATUS_OK
) {
381 value
= bt_value_map_get(params
, "full-path");
383 enum bt_value_status value_ret
;
386 bool_val
= bt_value_bool_get(value
);
388 debug_info_component
->arg_full_path
= bool_val
;
390 bt_object_put_ref(value
);
391 if (ret
!= BT_COMPONENT_STATUS_OK
) {
399 enum bt_component_status
debug_info_component_init(
400 struct bt_private_component
*component
, struct bt_value
*params
,
401 UNUSED_VAR
void *init_method_data
)
403 enum bt_component_status ret
;
404 struct debug_info_component
*debug_info
= create_debug_info_component_data();
407 ret
= BT_COMPONENT_STATUS_NOMEM
;
411 ret
= bt_private_component_set_user_data(component
, debug_info
);
412 if (ret
!= BT_COMPONENT_STATUS_OK
) {
416 ret
= bt_private_component_filter_add_input_port(
417 component
, "in", NULL
, NULL
);
418 if (ret
!= BT_COMPONENT_STATUS_OK
) {
422 ret
= bt_private_component_filter_add_output_port(
423 component
, "out", NULL
, NULL
);
424 if (ret
!= BT_COMPONENT_STATUS_OK
) {
428 ret
= init_from_params(debug_info
, params
);
432 destroy_debug_info_data(debug_info
);
436 #ifndef BT_BUILT_IN_PLUGINS
440 /* Initialize plug-in entry points. */
441 BT_PLUGIN_WITH_ID(lttng_utils
, "lttng-utils");
442 BT_PLUGIN_DESCRIPTION_WITH_ID(lttng_utils
, "LTTng utilities");
443 BT_PLUGIN_AUTHOR_WITH_ID(lttng_utils
, "Julien Desfossez");
444 BT_PLUGIN_LICENSE_WITH_ID(lttng_utils
, "MIT");
446 BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(lttng_utils
, debug_info
, "debug-info",
447 debug_info_iterator_next
);
448 BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(lttng_utils
, debug_info
,
449 "Augment compatible events with debugging information.");
450 BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(lttng_utils
,
451 debug_info
, debug_info_component_init
);
452 BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(lttng_utils
,
453 debug_info
, destroy_debug_info_component
);
454 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(
455 lttng_utils
, debug_info
, debug_info_iterator_init
);
456 BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(
457 lttng_utils
, debug_info
, debug_info_iterator_destroy
);