2 * Babeltrace - Debug Information State Tracker
4 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
6 * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
7 * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@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"
33 #include <plugins-common.h>
35 #include <babeltrace/assert-internal.h>
36 #include <babeltrace/common-internal.h>
39 #include "debug-info.h"
40 #include "trace-ir-data-copy.h"
41 #include "trace-ir-mapping.h"
42 #include "trace-ir-metadata-copy.h"
45 #define DEFAULT_DEBUG_INFO_FIELD_NAME "debug_info"
46 #define LTTNG_UST_STATEDUMP_PREFIX "lttng_ust"
47 #define VPID_FIELD_NAME "vpid"
48 #define IP_FIELD_NAME "ip"
49 #define BADDR_FIELD_NAME "baddr"
50 #define CRC32_FIELD_NAME "crc"
51 #define BUILD_ID_FIELD_NAME "build_id"
52 #define FILENAME_FIELD_NAME "filename"
53 #define IS_PIC_FIELD_NAME "is_pic"
54 #define MEMSZ_FIELD_NAME "memsz"
55 #define PATH_FIELD_NAME "path"
57 struct debug_info_component
{
59 gchar
*arg_debug_info_field_name
;
60 gchar
*arg_target_prefix
;
61 bt_bool arg_full_path
;
64 struct debug_info_msg_iter
{
65 struct debug_info_component
*debug_info_component
;
66 bt_self_message_iterator
*input_iterator
;
67 bt_self_component
*self_comp
;
68 bt_self_component_port_input_message_iterator
*msg_iter
;
70 struct trace_ir_maps
*ir_maps
;
71 /* in_trace -> debug_info_mapping. */
72 GHashTable
*debug_info_map
;
75 struct debug_info_source
{
76 /* Strings are owned by debug_info_source. */
79 * Store the line number as a string so that the allocation and
80 * conversion to string is only done once.
84 /* short_src_path points inside src_path, no need to free. */
85 const gchar
*short_src_path
;
87 /* short_bin_path points inside bin_path, no need to free. */
88 const gchar
*short_bin_path
;
90 * Location within the binary. Either absolute (@0x1234) or
96 struct proc_debug_info_sources
{
98 * Hash table: base address (pointer to uint64_t) to bin info; owned by
99 * proc_debug_info_sources.
101 GHashTable
*baddr_to_bin_info
;
104 * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *);
105 * owned by proc_debug_info_sources.
107 GHashTable
*ip_to_debug_info_src
;
111 struct debug_info_component
*comp
;
112 const bt_trace
*input_trace
;
113 uint64_t destruction_listener_id
;
116 * Hash table of VPIDs (pointer to int64_t) to
117 * (struct proc_debug_info_sources*); owned by debug_info.
119 GHashTable
*vpid_to_proc_dbg_info_src
;
120 GQuark q_statedump_bin_info
;
121 GQuark q_statedump_debug_link
;
122 GQuark q_statedump_build_id
;
123 GQuark q_statedump_start
;
130 int debug_info_init(struct debug_info
*info
)
132 info
->q_statedump_bin_info
= g_quark_from_string(
133 "lttng_ust_statedump:bin_info");
134 info
->q_statedump_debug_link
= g_quark_from_string(
135 "lttng_ust_statedump:debug_link");
136 info
->q_statedump_build_id
= g_quark_from_string(
137 "lttng_ust_statedump:build_id");
138 info
->q_statedump_start
= g_quark_from_string(
139 "lttng_ust_statedump:start");
140 info
->q_dl_open
= g_quark_from_string("lttng_ust_dl:dlopen");
141 info
->q_lib_load
= g_quark_from_string("lttng_ust_lib:load");
142 info
->q_lib_unload
= g_quark_from_string("lttng_ust_lib:unload");
144 return bin_info_init();
148 void debug_info_source_destroy(struct debug_info_source
*debug_info_src
)
150 if (!debug_info_src
) {
154 g_free(debug_info_src
->func
);
155 g_free(debug_info_src
->line_no
);
156 g_free(debug_info_src
->src_path
);
157 g_free(debug_info_src
->bin_path
);
158 g_free(debug_info_src
->bin_loc
);
159 g_free(debug_info_src
);
163 struct debug_info_source
*debug_info_source_create_from_bin(
164 struct bin_info
*bin
, uint64_t ip
)
167 struct debug_info_source
*debug_info_src
= NULL
;
168 struct source_location
*src_loc
= NULL
;
170 debug_info_src
= g_new0(struct debug_info_source
, 1);
172 if (!debug_info_src
) {
176 /* Lookup function name */
177 ret
= bin_info_lookup_function_name(bin
, ip
, &debug_info_src
->func
);
182 /* Can't retrieve src_loc from ELF, or could not find binary, skip. */
183 if (!bin
->is_elf_only
|| !debug_info_src
->func
) {
184 /* Lookup source location */
185 ret
= bin_info_lookup_source_location(bin
, ip
, &src_loc
);
187 BT_LOGD("Failed to lookup source location: ret=%d", ret
);
192 debug_info_src
->line_no
=
193 g_strdup_printf("%"PRId64
, src_loc
->line_no
);
194 if (!debug_info_src
->line_no
) {
195 BT_LOGD("Error occured when setting line_no field.");
199 if (src_loc
->filename
) {
200 debug_info_src
->src_path
= g_strdup(src_loc
->filename
);
201 if (!debug_info_src
->src_path
) {
205 debug_info_src
->short_src_path
= get_filename_from_path(
206 debug_info_src
->src_path
);
208 source_location_destroy(src_loc
);
212 debug_info_src
->bin_path
= g_strdup(bin
->elf_path
);
213 if (!debug_info_src
->bin_path
) {
217 debug_info_src
->short_bin_path
= get_filename_from_path(
218 debug_info_src
->bin_path
);
220 ret
= bin_info_get_bin_loc(bin
, ip
, &(debug_info_src
->bin_loc
));
227 return debug_info_src
;
230 debug_info_source_destroy(debug_info_src
);
235 void proc_debug_info_sources_destroy(
236 struct proc_debug_info_sources
*proc_dbg_info_src
)
238 if (!proc_dbg_info_src
) {
242 if (proc_dbg_info_src
->baddr_to_bin_info
) {
243 g_hash_table_destroy(proc_dbg_info_src
->baddr_to_bin_info
);
246 if (proc_dbg_info_src
->ip_to_debug_info_src
) {
247 g_hash_table_destroy(proc_dbg_info_src
->ip_to_debug_info_src
);
250 g_free(proc_dbg_info_src
);
254 struct proc_debug_info_sources
*proc_debug_info_sources_create(void)
256 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
258 proc_dbg_info_src
= g_new0(struct proc_debug_info_sources
, 1);
259 if (!proc_dbg_info_src
) {
263 proc_dbg_info_src
->baddr_to_bin_info
= g_hash_table_new_full(
264 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
265 (GDestroyNotify
) bin_info_destroy
);
266 if (!proc_dbg_info_src
->baddr_to_bin_info
) {
270 proc_dbg_info_src
->ip_to_debug_info_src
= g_hash_table_new_full(
271 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
272 (GDestroyNotify
) debug_info_source_destroy
);
273 if (!proc_dbg_info_src
->ip_to_debug_info_src
) {
278 return proc_dbg_info_src
;
281 proc_debug_info_sources_destroy(proc_dbg_info_src
);
286 struct proc_debug_info_sources
*proc_debug_info_sources_ht_get_entry(
287 GHashTable
*ht
, int64_t vpid
)
289 gpointer key
= g_new0(int64_t, 1);
290 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
296 *((int64_t *) key
) = vpid
;
298 /* Exists? Return it */
299 proc_dbg_info_src
= g_hash_table_lookup(ht
, key
);
300 if (proc_dbg_info_src
) {
304 /* Otherwise, create and return it */
305 proc_dbg_info_src
= proc_debug_info_sources_create();
306 if (!proc_dbg_info_src
) {
310 g_hash_table_insert(ht
, key
, proc_dbg_info_src
);
311 /* Ownership passed to ht */
315 return proc_dbg_info_src
;
319 const bt_field
*event_borrow_payload_field(const bt_event
*event
,
320 const char *field_name
)
322 const bt_field
*event_payload
, *field
;
324 event_payload
= bt_event_borrow_payload_field_const(event
);
325 BT_ASSERT(event_payload
);
327 field
= bt_field_structure_borrow_member_field_by_name_const(
328 event_payload
, field_name
);
333 const bt_field
*event_borrow_common_context_field(const bt_event
*event
,
334 const char *field_name
)
336 const bt_field
*event_common_ctx
, *field
= NULL
;
338 event_common_ctx
= bt_event_borrow_common_context_field_const(event
);
339 if (!event_common_ctx
) {
343 field
= bt_field_structure_borrow_member_field_by_name_const(
344 event_common_ctx
, field_name
);
351 void event_get_common_context_signed_integer_field_value(
352 const bt_event
*event
, const char *field_name
, int64_t *value
)
354 *value
= bt_field_signed_integer_get_value(
355 event_borrow_common_context_field(event
, field_name
));
359 int event_get_payload_build_id_length(const bt_event
*event
,
360 const char *field_name
, uint64_t *build_id_len
)
362 const bt_field
*build_id_field
;
363 const bt_field_class
*build_id_field_class
;
365 build_id_field
= event_borrow_payload_field(event
, field_name
);
366 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
368 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
369 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
370 BT_ASSERT(bt_field_class_get_type(
371 bt_field_class_array_borrow_element_field_class_const(
372 build_id_field_class
)) ==
373 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
375 *build_id_len
= bt_field_array_get_length(build_id_field
);
381 int event_get_payload_build_id_value(const bt_event
*event
,
382 const char *field_name
, uint8_t *build_id
)
384 const bt_field
*curr_field
, *build_id_field
;
385 const bt_field_class
*build_id_field_class
;
386 uint64_t i
, build_id_len
;
391 build_id_field
= event_borrow_payload_field(event
, field_name
);
392 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
394 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
395 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
396 BT_ASSERT(bt_field_class_get_type(
397 bt_field_class_array_borrow_element_field_class_const(
398 build_id_field_class
)) ==
399 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
401 build_id_len
= bt_field_array_get_length(build_id_field
);
403 for (i
= 0; i
< build_id_len
; i
++) {
405 bt_field_array_borrow_element_field_by_index_const(
408 build_id
[i
] = bt_field_unsigned_integer_get_value(curr_field
);
415 void event_get_payload_unsigned_integer_field_value(const bt_event
*event
,
416 const char *field_name
, uint64_t *value
)
418 *value
= bt_field_unsigned_integer_get_value(
419 event_borrow_payload_field(event
, field_name
));
423 void event_get_payload_string_field_value(const bt_event
*event
,
424 const char *field_name
, const char **value
)
426 *value
= bt_field_string_get_value(
427 event_borrow_payload_field(event
, field_name
));
431 bool event_has_payload_field(const bt_event
*event
,
432 const char *field_name
)
434 return event_borrow_payload_field(event
, field_name
) != NULL
;
438 struct debug_info_source
*proc_debug_info_sources_get_entry(
439 struct proc_debug_info_sources
*proc_dbg_info_src
, uint64_t ip
)
441 struct debug_info_source
*debug_info_src
= NULL
;
442 gpointer key
= g_new0(uint64_t, 1);
444 gpointer baddr
, value
;
450 *((uint64_t *) key
) = ip
;
452 /* Look in IP to debug infos hash table first. */
453 debug_info_src
= g_hash_table_lookup(
454 proc_dbg_info_src
->ip_to_debug_info_src
,
456 if (debug_info_src
) {
460 /* Check in all bin_infos. */
461 g_hash_table_iter_init(&iter
, proc_dbg_info_src
->baddr_to_bin_info
);
463 while (g_hash_table_iter_next(&iter
, &baddr
, &value
))
465 struct bin_info
*bin
= value
;
467 if (!bin_info_has_address(value
, ip
)) {
472 * Found; add it to cache.
474 * FIXME: this should be bounded in size (and implement
475 * a caching policy), and entries should be prunned when
476 * libraries are unmapped.
478 debug_info_src
= debug_info_source_create_from_bin(bin
, ip
);
479 if (debug_info_src
) {
481 proc_dbg_info_src
->ip_to_debug_info_src
,
482 key
, debug_info_src
);
483 /* Ownership passed to ht. */
491 return debug_info_src
;
495 struct debug_info_source
*debug_info_query(struct debug_info
*debug_info
,
496 int64_t vpid
, uint64_t ip
)
498 struct debug_info_source
*dbg_info_src
= NULL
;
499 struct proc_debug_info_sources
*proc_dbg_info_src
;
501 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
502 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
503 if (!proc_dbg_info_src
) {
507 dbg_info_src
= proc_debug_info_sources_get_entry(proc_dbg_info_src
, ip
);
514 struct debug_info
*debug_info_create(struct debug_info_component
*comp
,
515 const bt_trace
*trace
)
518 struct debug_info
*debug_info
;
520 debug_info
= g_new0(struct debug_info
, 1);
525 debug_info
->vpid_to_proc_dbg_info_src
= g_hash_table_new_full(
526 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
527 (GDestroyNotify
) proc_debug_info_sources_destroy
);
528 if (!debug_info
->vpid_to_proc_dbg_info_src
) {
532 debug_info
->comp
= comp
;
533 ret
= debug_info_init(debug_info
);
538 debug_info
->input_trace
= trace
;
548 void debug_info_destroy(struct debug_info
*debug_info
)
550 bt_trace_status status
;
555 if (debug_info
->vpid_to_proc_dbg_info_src
) {
556 g_hash_table_destroy(debug_info
->vpid_to_proc_dbg_info_src
);
559 status
= bt_trace_remove_destruction_listener(debug_info
->input_trace
,
560 debug_info
->destruction_listener_id
);
561 if (status
!= BT_TRACE_STATUS_OK
) {
562 BT_LOGD("Trace destruction listener removal failed.");
571 void handle_event_statedump_build_id(struct debug_info
*debug_info
,
572 const bt_event
*event
)
574 struct proc_debug_info_sources
*proc_dbg_info_src
;
575 uint64_t build_id_len
, baddr
;
576 uint8_t *build_id
= NULL
;
577 struct bin_info
*bin
;
581 event_get_common_context_signed_integer_field_value(event
,
582 VPID_FIELD_NAME
, &vpid
);
583 event_get_payload_unsigned_integer_field_value(event
,
584 BADDR_FIELD_NAME
, &baddr
);
586 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
587 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
588 if (!proc_dbg_info_src
) {
592 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
596 * The build_id event comes after the bin has been
597 * created. If it isn't found, just ignore this event.
601 ret
= event_get_payload_build_id_length(event
, BUILD_ID_FIELD_NAME
,
604 build_id
= g_new0(uint8_t, build_id_len
);
609 ret
= event_get_payload_build_id_value(event
, BUILD_ID_FIELD_NAME
,
615 ret
= bin_info_set_build_id(bin
, build_id
, build_id_len
);
621 * Reset the is_elf_only flag in case it had been set
622 * previously, because we might find separate debug info using
623 * the new build id information.
625 bin
->is_elf_only
= false;
633 void handle_event_statedump_debug_link(struct debug_info
*debug_info
,
634 const bt_event
*event
)
636 struct proc_debug_info_sources
*proc_dbg_info_src
;
637 struct bin_info
*bin
= NULL
;
640 const char *filename
= NULL
;
642 uint64_t crc_field_value
;
644 event_get_common_context_signed_integer_field_value(event
,
645 VPID_FIELD_NAME
, &vpid
);
647 event_get_payload_unsigned_integer_field_value(event
,
648 BADDR_FIELD_NAME
, &baddr
);
650 event_get_payload_unsigned_integer_field_value(event
,
651 CRC32_FIELD_NAME
, &crc_field_value
);
653 crc32
= (uint32_t) crc_field_value
;
655 event_get_payload_string_field_value(event
,
656 FILENAME_FIELD_NAME
, &filename
);
658 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
659 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
660 if (!proc_dbg_info_src
) {
664 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
668 * The debug_link event comes after the bin has been
669 * created. If it isn't found, just ignore this event.
674 bin_info_set_debug_link(bin
, filename
, crc32
);
681 void handle_bin_info_event(struct debug_info
*debug_info
,
682 const bt_event
*event
, bool has_pic_field
)
684 struct proc_debug_info_sources
*proc_dbg_info_src
;
685 struct bin_info
*bin
;
686 uint64_t baddr
, memsz
;
692 event_get_payload_unsigned_integer_field_value(event
,
693 MEMSZ_FIELD_NAME
, &memsz
);
699 event_get_payload_unsigned_integer_field_value(event
,
700 BADDR_FIELD_NAME
, &baddr
);
703 * This field is not produced by the dlopen event emitted before
706 if (!event_has_payload_field(event
, PATH_FIELD_NAME
)) {
709 event_get_payload_string_field_value(event
, PATH_FIELD_NAME
, &path
);
712 uint64_t is_pic_field_value
;
714 event_get_payload_unsigned_integer_field_value(event
,
715 IS_PIC_FIELD_NAME
, &is_pic_field_value
);
716 is_pic
= is_pic_field_value
== 1;
719 * dlopen has no is_pic field, because the shared
720 * object is always PIC.
725 event_get_common_context_signed_integer_field_value(event
,
726 VPID_FIELD_NAME
, &vpid
);
728 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
729 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
730 if (!proc_dbg_info_src
) {
734 key
= g_new0(uint64_t, 1);
739 *((uint64_t *) key
) = baddr
;
741 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
747 bin
= bin_info_create(path
, baddr
, memsz
, is_pic
,
748 debug_info
->comp
->arg_debug_dir
,
749 debug_info
->comp
->arg_target_prefix
);
754 g_hash_table_insert(proc_dbg_info_src
->baddr_to_bin_info
,
756 /* Ownership passed to ht. */
765 void handle_event_statedump_bin_info(struct debug_info
*debug_info
,
766 const bt_event
*event
)
768 handle_bin_info_event(debug_info
, event
, true);
772 void handle_event_lib_load(struct debug_info
*debug_info
,
773 const bt_event
*event
)
775 handle_bin_info_event(debug_info
, event
, false);
779 void handle_event_lib_unload(struct debug_info
*debug_info
,
780 const bt_event
*event
)
783 struct proc_debug_info_sources
*proc_dbg_info_src
;
787 event_get_payload_unsigned_integer_field_value(event
, BADDR_FIELD_NAME
,
790 event_get_common_context_signed_integer_field_value(event
,
791 VPID_FIELD_NAME
, &vpid
);
793 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
794 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
795 if (!proc_dbg_info_src
) {
797 * It's an unload event for a library for which no load event
798 * was previously received.
803 ret
= g_hash_table_remove(proc_dbg_info_src
->baddr_to_bin_info
,
811 void handle_event_statedump_start(struct debug_info
*debug_info
,
812 const bt_event
*event
)
814 struct proc_debug_info_sources
*proc_dbg_info_src
;
817 event_get_common_context_signed_integer_field_value(
818 event
, VPID_FIELD_NAME
, &vpid
);
820 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
821 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
822 if (!proc_dbg_info_src
) {
826 g_hash_table_remove_all(proc_dbg_info_src
->baddr_to_bin_info
);
827 g_hash_table_remove_all(proc_dbg_info_src
->ip_to_debug_info_src
);
833 void trace_debug_info_remove_func(const bt_trace
*in_trace
, void *data
)
835 struct debug_info_msg_iter
*debug_it
= data
;
836 if (debug_it
->debug_info_map
) {
838 ret
= g_hash_table_remove(debug_it
->debug_info_map
,
839 (gpointer
) in_trace
);
845 void handle_event_statedump(struct debug_info_msg_iter
*debug_it
,
846 const bt_event
*event
)
848 const bt_event_class
*event_class
;
849 const char *event_name
;
851 const bt_trace
*trace
;
852 struct debug_info
*debug_info
;
857 event_class
= bt_event_borrow_class_const(event
);
859 event_name
= bt_event_class_get_name(event_class
);
861 trace
= bt_stream_borrow_trace_const(
862 bt_event_borrow_stream_const(event
));
864 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
, trace
);
866 debug_info
= debug_info_create(debug_it
->debug_info_component
,
868 g_hash_table_insert(debug_it
->debug_info_map
, (gpointer
) trace
,
870 bt_trace_add_destruction_listener(trace
,
871 trace_debug_info_remove_func
, debug_it
,
872 &debug_info
->destruction_listener_id
);
875 q_event_name
= g_quark_try_string(event_name
);
877 if (q_event_name
== debug_info
->q_statedump_bin_info
) {
879 handle_event_statedump_bin_info(debug_info
, event
);
880 } else if (q_event_name
== debug_info
->q_dl_open
||
881 q_event_name
== debug_info
->q_lib_load
) {
883 * dl_open and lib_load events are both checked for since
884 * only dl_open was produced as of lttng-ust 2.8.
886 * lib_load, which is produced from lttng-ust 2.9+, is a lot
887 * more reliable since it will be emitted when other functions
888 * of the dlopen family are called (e.g. dlmopen) and when
889 * library are transitively loaded.
891 handle_event_lib_load(debug_info
, event
);
892 } else if (q_event_name
== debug_info
->q_statedump_start
) {
893 /* Start state dump */
894 handle_event_statedump_start(debug_info
, event
);
895 } else if (q_event_name
== debug_info
->q_statedump_debug_link
) {
896 /* Debug link info */
897 handle_event_statedump_debug_link(debug_info
, event
);
898 } else if (q_event_name
== debug_info
->q_statedump_build_id
) {
900 handle_event_statedump_build_id(debug_info
, event
);
901 } else if (q_event_name
== debug_info
-> q_lib_unload
) {
902 handle_event_lib_unload(debug_info
, event
);
909 void destroy_debug_info_comp(struct debug_info_component
*debug_info
)
915 g_free(debug_info
->arg_debug_dir
);
916 g_free(debug_info
->arg_debug_info_field_name
);
917 g_free(debug_info
->arg_target_prefix
);
922 void fill_debug_info_bin_field(struct debug_info_source
*dbg_info_src
,
923 bool full_path
, bt_field
*curr_field
)
925 bt_field_status status
;
927 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
928 BT_FIELD_CLASS_TYPE_STRING
);
932 status
= bt_field_string_set_value(curr_field
,
933 dbg_info_src
->bin_path
);
935 status
= bt_field_string_set_value(curr_field
,
936 dbg_info_src
->short_bin_path
);
938 if (status
!= BT_FIELD_STATUS_OK
) {
939 BT_LOGE("Cannot set path component of \"bin\" "
940 "curr_field field's value: str-fc-addr=%p",
944 status
= bt_field_string_append(curr_field
, ":");
945 if (status
!= BT_FIELD_STATUS_OK
) {
946 BT_LOGE("Cannot set colon component of \"bin\" "
947 "curr_field field's value: str-fc-addr=%p",
951 status
= bt_field_string_append(curr_field
, dbg_info_src
->bin_loc
);
952 if (status
!= BT_FIELD_STATUS_OK
) {
953 BT_LOGE("Cannot set bin location component of \"bin\" "
954 "curr_field field's value: str-fc-addr=%p",
958 status
= bt_field_string_set_value(curr_field
, "");
959 if (status
!= BT_FIELD_STATUS_OK
) {
960 BT_LOGE("Cannot set \"bin\" curr_field field's value: "
961 "str-fc-addr=%p", curr_field
);
967 void fill_debug_info_func_field(struct debug_info_source
*dbg_info_src
,
968 bt_field
*curr_field
)
970 bt_field_status status
;
972 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
973 BT_FIELD_CLASS_TYPE_STRING
);
974 if (dbg_info_src
&& dbg_info_src
->func
) {
975 status
= bt_field_string_set_value(curr_field
,
978 status
= bt_field_string_set_value(curr_field
, "");
980 if (status
!= BT_FIELD_STATUS_OK
) {
981 BT_LOGE("Cannot set \"func\" curr_field field's value: "
982 "str-fc-addr=%p", curr_field
);
987 void fill_debug_info_src_field(struct debug_info_source
*dbg_info_src
,
988 bool full_path
, bt_field
*curr_field
)
990 bt_field_status status
;
992 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
993 BT_FIELD_CLASS_TYPE_STRING
);
995 if (dbg_info_src
&& dbg_info_src
->src_path
) {
997 status
= bt_field_string_set_value(curr_field
,
998 dbg_info_src
->src_path
);
1000 status
= bt_field_string_set_value(curr_field
,
1001 dbg_info_src
->short_src_path
);
1003 if (status
!= BT_FIELD_STATUS_OK
) {
1004 BT_LOGE("Cannot set path component of \"src\" "
1005 "curr_field field's value: str-fc-addr=%p",
1009 status
= bt_field_string_append(curr_field
, ":");
1010 if (status
!= BT_FIELD_STATUS_OK
) {
1011 BT_LOGE("Cannot set colon component of \"src\" "
1012 "curr_field field's value: str-fc-addr=%p",
1016 status
= bt_field_string_append(curr_field
, dbg_info_src
->line_no
);
1017 if (status
!= BT_FIELD_STATUS_OK
) {
1018 BT_LOGE("Cannot set line number component of \"src\" "
1019 "curr_field field's value: str-fc-addr=%p",
1023 status
= bt_field_string_set_value(curr_field
, "");
1024 if (status
!= BT_FIELD_STATUS_OK
) {
1025 BT_LOGE("Cannot set \"src\" curr_field field's value: "
1026 "str-fc-addr=%p", curr_field
);
1031 void fill_debug_info_field_empty(bt_field
*debug_info_field
)
1033 bt_field_status status
;
1034 bt_field
*bin_field
, *func_field
, *src_field
;
1036 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1037 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1039 bin_field
= bt_field_structure_borrow_member_field_by_name(
1040 debug_info_field
, "bin");
1041 func_field
= bt_field_structure_borrow_member_field_by_name(
1042 debug_info_field
, "func");
1043 src_field
= bt_field_structure_borrow_member_field_by_name(
1044 debug_info_field
, "src");
1046 BT_ASSERT(bt_field_get_class_type(bin_field
) ==
1047 BT_FIELD_CLASS_TYPE_STRING
);
1048 BT_ASSERT(bt_field_get_class_type(func_field
) ==
1049 BT_FIELD_CLASS_TYPE_STRING
);
1050 BT_ASSERT(bt_field_get_class_type(src_field
) ==
1051 BT_FIELD_CLASS_TYPE_STRING
);
1053 status
= bt_field_string_set_value(bin_field
, "");
1054 if (status
!= BT_FIELD_STATUS_OK
) {
1055 BT_LOGE("Cannot set \"bin\" bin_field field's value: "
1056 "str-fc-addr=%p", bin_field
);
1059 status
= bt_field_string_set_value(func_field
, "");
1060 if (status
!= BT_FIELD_STATUS_OK
) {
1061 BT_LOGE("Cannot set \"func\" func_field field's value: "
1062 "str-fc-addr=%p", func_field
);
1065 status
= bt_field_string_set_value(src_field
, "");
1066 if (status
!= BT_FIELD_STATUS_OK
) {
1067 BT_LOGE("Cannot set \"src\" src_field field's value: "
1068 "str-fc-addr=%p", src_field
);
1072 void fill_debug_info_field(struct debug_info
*debug_info
, int64_t vpid
,
1073 uint64_t ip
, bt_field
*debug_info_field
)
1075 struct debug_info_source
*dbg_info_src
;
1076 const bt_field_class
*debug_info_fc
;
1078 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1079 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1081 debug_info_fc
= bt_field_borrow_class_const(debug_info_field
);
1083 BT_ASSERT(bt_field_class_structure_get_member_count(debug_info_fc
) == 3);
1085 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1087 fill_debug_info_bin_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1088 bt_field_structure_borrow_member_field_by_name(
1089 debug_info_field
, "bin"));
1090 fill_debug_info_func_field(dbg_info_src
,
1091 bt_field_structure_borrow_member_field_by_name(
1092 debug_info_field
, "func"));
1093 fill_debug_info_src_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1094 bt_field_structure_borrow_member_field_by_name(
1095 debug_info_field
, "src"));
1099 void fill_debug_info_event_if_needed(struct debug_info_msg_iter
*debug_it
,
1100 const bt_event
*in_event
, bt_event
*out_event
)
1102 bt_field
*out_common_ctx_field
, *out_debug_info_field
;
1103 const bt_field
*vpid_field
, *ip_field
, *in_common_ctx_field
;
1104 const bt_field_class
*in_common_ctx_fc
;
1105 struct debug_info
*debug_info
;
1108 gchar
*debug_info_field_name
=
1109 debug_it
->debug_info_component
->arg_debug_info_field_name
;
1111 in_common_ctx_field
= bt_event_borrow_common_context_field_const(
1113 if (!in_common_ctx_field
) {
1115 * There is no event common context so no need to add debug
1121 in_common_ctx_fc
= bt_field_borrow_class_const(in_common_ctx_field
);
1122 if (!is_event_common_ctx_dbg_info_compatible(in_common_ctx_fc
,
1123 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1125 * The input event common context does not have the necessary
1126 * fields to resolve debug information.
1131 /* Borrow the debug-info field. */
1132 out_common_ctx_field
= bt_event_borrow_common_context_field(out_event
);
1133 if (!out_common_ctx_field
) {
1137 out_debug_info_field
= bt_field_structure_borrow_member_field_by_name(
1138 out_common_ctx_field
, debug_info_field_name
);
1140 vpid_field
= bt_field_structure_borrow_member_field_by_name_const(
1141 out_common_ctx_field
, VPID_FIELD_NAME
);
1142 ip_field
= bt_field_structure_borrow_member_field_by_name_const(
1143 out_common_ctx_field
, IP_FIELD_NAME
);
1145 vpid
= bt_field_signed_integer_get_value(vpid_field
);
1146 ip
= bt_field_unsigned_integer_get_value(ip_field
);
1149 * Borrow the debug_info structure needed for the source
1152 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
,
1153 bt_stream_borrow_trace_const(
1154 bt_event_borrow_stream_const(in_event
)));
1158 * Perform the debug-info resolving and set the event fields
1161 fill_debug_info_field(debug_info
, vpid
, ip
, out_debug_info_field
);
1163 BT_LOGD("No debug information for this trace. Setting debug "
1164 "info fields to empty strings.");
1165 fill_debug_info_field_empty(out_debug_info_field
);
1172 void update_event_statedump_if_needed(struct debug_info_msg_iter
*debug_it
,
1173 const bt_event
*in_event
)
1175 const bt_field
*event_common_ctx
;
1176 const bt_field_class
*event_common_ctx_fc
;
1177 const bt_event_class
*in_event_class
= bt_event_borrow_class_const(in_event
);
1180 * If the event is an lttng_ust_statedump event AND has the right event
1181 * common context fields update the debug-info view for this process.
1183 event_common_ctx
= bt_event_borrow_common_context_field_const(in_event
);
1184 if (!event_common_ctx
) {
1188 event_common_ctx_fc
= bt_field_borrow_class_const(event_common_ctx
);
1189 if (is_event_common_ctx_dbg_info_compatible(event_common_ctx_fc
,
1190 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1191 /* Checkout if it might be a one of lttng ust statedump events. */
1192 const char *in_event_name
= bt_event_class_get_name(in_event_class
);
1193 if (strncmp(in_event_name
, LTTNG_UST_STATEDUMP_PREFIX
,
1194 strlen(LTTNG_UST_STATEDUMP_PREFIX
)) == 0) {
1195 /* Handle statedump events. */
1196 handle_event_statedump(debug_it
, in_event
);
1204 bt_message
*handle_event_message(struct debug_info_msg_iter
*debug_it
,
1205 const bt_message
*in_message
)
1207 const bt_clock_snapshot
*cs
;
1208 const bt_clock_class
*default_cc
;
1209 const bt_packet
*in_packet
;
1210 bt_clock_snapshot_state cs_state
;
1211 bt_event_class
*out_event_class
;
1212 bt_packet
*out_packet
;
1213 bt_event
*out_event
;
1215 bt_message
*out_message
= NULL
;
1217 /* Borrow the input event and its event class. */
1218 const bt_event
*in_event
=
1219 bt_message_event_borrow_event_const(in_message
);
1220 const bt_event_class
*in_event_class
=
1221 bt_event_borrow_class_const(in_event
);
1223 update_event_statedump_if_needed(debug_it
, in_event
);
1225 out_event_class
= trace_ir_mapping_borrow_mapped_event_class(
1226 debug_it
->ir_maps
, in_event_class
);
1227 if (!out_event_class
) {
1228 out_event_class
= trace_ir_mapping_create_new_mapped_event_class(
1229 debug_it
->ir_maps
, in_event_class
);
1231 BT_ASSERT(out_event_class
);
1233 /* Borrow the input and output packets. */
1234 in_packet
= bt_event_borrow_packet_const(in_event
);
1235 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
,
1238 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1239 bt_event_class_borrow_stream_class_const(in_event_class
));
1241 /* Borrow event clock snapshot. */
1243 bt_message_event_borrow_default_clock_snapshot_const(
1246 /* Create an output event message. */
1247 BT_ASSERT (cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1248 out_message
= bt_message_event_create_with_default_clock_snapshot(
1249 debug_it
->input_iterator
,
1250 out_event_class
, out_packet
,
1251 bt_clock_snapshot_get_value(cs
));
1253 out_message
= bt_message_event_create(debug_it
->input_iterator
,
1254 out_event_class
, out_packet
);
1258 BT_LOGE("Error creating output event message.");
1262 out_event
= bt_message_event_borrow_event(out_message
);
1264 /* Copy the original fields to the output event. */
1265 copy_event_content(in_event
, out_event
);
1268 * Try to set the debug-info fields based on debug information that is
1271 fill_debug_info_event_if_needed(debug_it
, in_event
, out_event
);
1278 bt_message
*handle_stream_begin_message(struct debug_info_msg_iter
*debug_it
,
1279 const bt_message
*in_message
)
1281 const bt_stream
*in_stream
;
1282 bt_message
*out_message
;
1283 bt_stream
*out_stream
;
1285 in_stream
= bt_message_stream_beginning_borrow_stream_const(in_message
);
1286 BT_ASSERT(in_stream
);
1288 /* Create a duplicated output stream. */
1289 out_stream
= trace_ir_mapping_create_new_mapped_stream(
1290 debug_it
->ir_maps
, in_stream
);
1296 /* Create an output stream beginning message. */
1297 out_message
= bt_message_stream_beginning_create(
1298 debug_it
->input_iterator
, out_stream
);
1300 BT_LOGE("Error creating output stream beginning message: "
1301 "out-s-addr=%p", out_stream
);
1308 bt_message
*handle_stream_end_message(struct debug_info_msg_iter
*debug_it
,
1309 const bt_message
*in_message
)
1311 const bt_stream
*in_stream
;
1312 bt_message
*out_message
= NULL
;
1313 bt_stream
*out_stream
;
1315 in_stream
= bt_message_stream_end_borrow_stream_const(in_message
);
1316 BT_ASSERT(in_stream
);
1318 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1319 debug_it
->ir_maps
, in_stream
);
1320 BT_ASSERT(out_stream
);
1322 /* Create an output stream end message. */
1323 out_message
= bt_message_stream_end_create(debug_it
->input_iterator
,
1326 BT_LOGE("Error creating output stream end message: out-s-addr=%p",
1330 /* Remove stream from trace mapping hashtable. */
1331 trace_ir_mapping_remove_mapped_stream(debug_it
->ir_maps
, in_stream
);
1337 bt_message
*handle_packet_begin_message(struct debug_info_msg_iter
*debug_it
,
1338 const bt_message
*in_message
)
1340 const bt_clock_class
*default_cc
;
1341 bt_clock_snapshot_state cs_state
;
1342 const bt_clock_snapshot
*cs
;
1343 bt_message
*out_message
= NULL
;
1344 bt_packet
*out_packet
;
1346 const bt_packet
*in_packet
=
1347 bt_message_packet_beginning_borrow_packet_const(in_message
);
1348 BT_ASSERT(in_packet
);
1350 /* This packet should not be already mapped. */
1351 BT_ASSERT(!trace_ir_mapping_borrow_mapped_packet(
1352 debug_it
->ir_maps
, in_packet
));
1354 out_packet
= trace_ir_mapping_create_new_mapped_packet(debug_it
->ir_maps
,
1357 BT_ASSERT(out_packet
);
1359 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1360 bt_stream_borrow_class_const(
1361 bt_packet_borrow_stream_const(in_packet
)));
1363 /* Borrow clock snapshot. */
1365 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
1368 /* Create an output packet beginning message. */
1369 BT_ASSERT(cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1370 out_message
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1371 debug_it
->input_iterator
, out_packet
,
1372 bt_clock_snapshot_get_value(cs
));
1374 out_message
= bt_message_packet_beginning_create(
1375 debug_it
->input_iterator
, out_packet
);
1378 BT_LOGE("Error creating output packet beginning message: "
1379 "out-p-addr=%p", out_packet
);
1386 bt_message
*handle_packet_end_message(struct debug_info_msg_iter
*debug_it
,
1387 const bt_message
*in_message
)
1389 const bt_clock_snapshot
*cs
;
1390 const bt_packet
*in_packet
;
1391 const bt_clock_class
*default_cc
;
1392 bt_clock_snapshot_state cs_state
;
1393 bt_message
*out_message
= NULL
;
1394 bt_packet
*out_packet
;
1396 in_packet
= bt_message_packet_end_borrow_packet_const(in_message
);
1397 BT_ASSERT(in_packet
);
1399 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
, in_packet
);
1400 BT_ASSERT(out_packet
);
1402 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1403 bt_stream_borrow_class_const(
1404 bt_packet_borrow_stream_const(in_packet
)));
1406 /* Borrow clock snapshot. */
1408 bt_message_packet_end_borrow_default_clock_snapshot_const(
1411 /* Create an outpute packet end message. */
1412 BT_ASSERT(cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1413 out_message
= bt_message_packet_end_create_with_default_clock_snapshot(
1414 debug_it
->input_iterator
, out_packet
,
1415 bt_clock_snapshot_get_value(cs
));
1417 out_message
= bt_message_packet_end_create(
1418 debug_it
->input_iterator
, out_packet
);
1422 BT_LOGE("Error creating output packet end message: "
1423 "out-p-addr=%p", out_packet
);
1426 /* Remove packet from data mapping hashtable. */
1427 trace_ir_mapping_remove_mapped_packet(debug_it
->ir_maps
, in_packet
);
1433 bt_message
*handle_msg_iterator_inactivity(struct debug_info_msg_iter
*debug_it
,
1434 const bt_message
*in_message
)
1437 * This message type can be forwarded directly because it does
1438 * not refer to any objects in the trace class.
1440 bt_message_get_ref(in_message
);
1441 return (bt_message
*) in_message
;
1445 bt_message
*handle_stream_act_begin_message(struct debug_info_msg_iter
*debug_it
,
1446 const bt_message
*in_message
)
1448 const bt_clock_snapshot
*cs
;
1449 const bt_clock_class
*default_cc
;
1450 bt_message
*out_message
= NULL
;
1451 bt_stream
*out_stream
;
1453 bt_message_stream_activity_clock_snapshot_state cs_state
;
1455 const bt_stream
*in_stream
=
1456 bt_message_stream_activity_beginning_borrow_stream_const(
1458 BT_ASSERT(in_stream
);
1460 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
,
1462 BT_ASSERT(out_stream
);
1464 out_message
= bt_message_stream_activity_beginning_create(
1465 debug_it
->input_iterator
, out_stream
);
1467 BT_LOGE("Error creating output stream activity beginning "
1468 "message: out-s-addr=%p", out_stream
);
1472 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1473 bt_stream_borrow_class_const(in_stream
));
1475 /* Borrow clock snapshot. */
1477 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
1480 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1481 cs_value
= bt_clock_snapshot_get_value(cs
);
1482 bt_message_stream_activity_beginning_set_default_clock_snapshot(
1483 out_message
, cs_value
);
1485 bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
1486 out_message
, cs_state
);
1495 bt_message
*handle_stream_act_end_message(struct debug_info_msg_iter
*debug_it
,
1496 const bt_message
*in_message
)
1498 const bt_clock_snapshot
*cs
;
1499 const bt_clock_class
*default_cc
;
1500 const bt_stream
*in_stream
;
1501 bt_message
*out_message
;
1502 bt_stream
*out_stream
;
1504 bt_message_stream_activity_clock_snapshot_state cs_state
;
1506 in_stream
= bt_message_stream_activity_end_borrow_stream_const(
1508 BT_ASSERT(in_stream
);
1510 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
, in_stream
);
1511 BT_ASSERT(out_stream
);
1513 out_message
= bt_message_stream_activity_end_create(
1514 debug_it
->input_iterator
, out_stream
);
1516 BT_LOGE("Error creating output stream activity end message: "
1517 "out-s-addr=%p", out_stream
);
1521 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1522 bt_stream_borrow_class_const(in_stream
));
1526 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
1529 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1530 cs_value
= bt_clock_snapshot_get_value(cs
);
1531 bt_message_stream_activity_end_set_default_clock_snapshot(
1532 out_message
, cs_value
);
1534 bt_message_stream_activity_end_set_default_clock_snapshot_state(
1535 out_message
, cs_state
);
1544 bt_message
*handle_discarded_events_message(struct debug_info_msg_iter
*debug_it
,
1545 const bt_message
*in_message
)
1547 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1548 const bt_stream
*in_stream
;
1549 const bt_clock_class
*default_cc
;
1550 uint64_t discarded_events
, begin_cs_value
, end_cs_value
;
1551 bt_clock_snapshot_state begin_cs_state
, end_cs_state
;
1552 bt_property_availability prop_avail
;
1553 bt_message
*out_message
= NULL
;
1554 bt_stream
*out_stream
;
1556 in_stream
= bt_message_discarded_events_borrow_stream_const(
1558 BT_ASSERT(in_stream
);
1560 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1561 debug_it
->ir_maps
, in_stream
);
1562 BT_ASSERT(out_stream
);
1564 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1565 bt_stream_borrow_class_const(in_stream
));
1568 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
1569 in_message
, &begin_cs
);
1571 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
1572 in_message
, &end_cs
);
1574 * Both clock snapshots should be known as we check that the
1575 * all input stream classes have an always known clock. Unknown
1576 * clock is not yet supported.
1578 BT_ASSERT(begin_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
&&
1579 end_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1581 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1582 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1585 bt_message_discarded_events_create_with_default_clock_snapshots(
1586 debug_it
->input_iterator
, out_stream
,
1587 begin_cs_value
, end_cs_value
);
1589 out_message
= bt_message_discarded_events_create(
1590 debug_it
->input_iterator
, out_stream
);
1593 BT_LOGE("Error creating output discarded events message: "
1594 "out-s-addr=%p", out_stream
);
1598 prop_avail
= bt_message_discarded_events_get_count(in_message
,
1601 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1602 bt_message_discarded_events_set_count(out_message
,
1611 bt_message
*handle_discarded_packets_message(struct debug_info_msg_iter
*debug_it
,
1612 const bt_message
*in_message
)
1614 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1615 const bt_clock_class
*default_cc
;
1616 const bt_stream
*in_stream
;
1617 uint64_t discarded_packets
, begin_cs_value
, end_cs_value
;
1618 bt_clock_snapshot_state begin_cs_state
, end_cs_state
;
1619 bt_property_availability prop_avail
;
1620 bt_message
*out_message
= NULL
;
1621 bt_stream
*out_stream
;
1623 in_stream
= bt_message_discarded_packets_borrow_stream_const(
1625 BT_ASSERT(in_stream
);
1627 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1628 debug_it
->ir_maps
, in_stream
);
1629 BT_ASSERT(out_stream
);
1631 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1632 bt_stream_borrow_class_const(in_stream
));
1635 bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
1636 in_message
, &begin_cs
);
1639 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
1640 in_message
, &end_cs
);
1643 * Both clock snapshots should be known as we check that the
1644 * all input stream classes have an always known clock. Unknown
1645 * clock is not yet supported.
1647 BT_ASSERT(begin_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
&&
1648 end_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1650 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1651 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1653 out_message
= bt_message_discarded_packets_create_with_default_clock_snapshots(
1654 debug_it
->input_iterator
, out_stream
,
1655 begin_cs_value
, end_cs_value
);
1657 out_message
= bt_message_discarded_packets_create(
1658 debug_it
->input_iterator
, out_stream
);
1661 BT_LOGE("Error creating output discarded packet message: "
1662 "out-s-addr=%p", out_stream
);
1666 prop_avail
= bt_message_discarded_packets_get_count(in_message
,
1667 &discarded_packets
);
1668 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1669 bt_message_discarded_packets_set_count(out_message
,
1678 const bt_message
*handle_message(struct debug_info_msg_iter
*debug_it
,
1679 const bt_message
*in_message
)
1681 bt_message
*out_message
= NULL
;
1683 switch (bt_message_get_type(in_message
)) {
1684 case BT_MESSAGE_TYPE_EVENT
:
1685 out_message
= handle_event_message(debug_it
,
1688 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1689 out_message
= handle_packet_begin_message(debug_it
,
1692 case BT_MESSAGE_TYPE_PACKET_END
:
1693 out_message
= handle_packet_end_message(debug_it
,
1696 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1697 out_message
= handle_stream_begin_message(debug_it
,
1700 case BT_MESSAGE_TYPE_STREAM_END
:
1701 out_message
= handle_stream_end_message(debug_it
,
1704 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1705 out_message
= handle_msg_iterator_inactivity(debug_it
,
1708 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
1709 out_message
= handle_stream_act_begin_message(debug_it
,
1712 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
1713 out_message
= handle_stream_act_end_message(debug_it
,
1716 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1717 out_message
= handle_discarded_events_message(debug_it
,
1720 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1721 out_message
= handle_discarded_packets_message(debug_it
,
1733 int init_from_params(struct debug_info_component
*debug_info_component
,
1734 const bt_value
*params
)
1736 const bt_value
*value
= NULL
;
1741 value
= bt_value_map_borrow_entry_value_const(params
,
1742 "debug-info-field-name");
1744 debug_info_component
->arg_debug_info_field_name
=
1745 g_strdup(bt_value_string_get(value
));
1747 debug_info_component
->arg_debug_info_field_name
=
1748 g_strdup(DEFAULT_DEBUG_INFO_FIELD_NAME
);
1751 value
= bt_value_map_borrow_entry_value_const(params
, "debug-info-dir");
1753 debug_info_component
->arg_debug_dir
=
1754 g_strdup(bt_value_string_get(value
));
1756 debug_info_component
->arg_debug_dir
= NULL
;
1760 value
= bt_value_map_borrow_entry_value_const(params
, "target-prefix");
1762 debug_info_component
->arg_target_prefix
=
1763 g_strdup(bt_value_string_get(value
));
1765 debug_info_component
->arg_target_prefix
= NULL
;
1768 value
= bt_value_map_borrow_entry_value_const(params
, "full-path");
1770 debug_info_component
->arg_full_path
= bt_value_bool_get(value
);
1772 debug_info_component
->arg_full_path
= BT_FALSE
;
1779 bt_self_component_status
debug_info_comp_init(
1780 bt_self_component_filter
*self_comp
,
1781 const bt_value
*params
, UNUSED_VAR
void *init_method_data
)
1784 struct debug_info_component
*debug_info_comp
;
1785 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
1787 BT_LOGD("Initializing debug_info component: "
1788 "comp-addr=%p, params-addr=%p", self_comp
, params
);
1790 debug_info_comp
= g_new0(struct debug_info_component
, 1);
1791 if (!debug_info_comp
) {
1792 BT_LOGE_STR("Failed to allocate one debug_info component.");
1796 bt_self_component_set_data(
1797 bt_self_component_filter_as_self_component(self_comp
),
1800 status
= bt_self_component_filter_add_input_port(self_comp
, "in",
1802 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1806 status
= bt_self_component_filter_add_output_port(self_comp
, "out",
1808 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1812 ret
= init_from_params(debug_info_comp
, params
);
1814 BT_LOGE("Cannot configure debug_info component: "
1815 "debug_info-comp-addr=%p, params-addr=%p",
1816 debug_info_comp
, params
);
1823 destroy_debug_info_comp(debug_info_comp
);
1824 bt_self_component_set_data(
1825 bt_self_component_filter_as_self_component(self_comp
),
1828 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
1829 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1836 void debug_info_comp_finalize(bt_self_component_filter
*self_comp
)
1838 struct debug_info_component
*debug_info
=
1839 bt_self_component_get_data(
1840 bt_self_component_filter_as_self_component(
1842 BT_LOGD("Finalizing debug_info self_component: comp-addr=%p",
1845 destroy_debug_info_comp(debug_info
);
1849 bt_self_message_iterator_status
debug_info_msg_iter_next(
1850 bt_self_message_iterator
*self_msg_iter
,
1851 const bt_message_array_const msgs
, uint64_t capacity
,
1854 bt_self_component_port_input_message_iterator
*upstream_iterator
= NULL
;
1855 bt_message_iterator_status upstream_iterator_ret_status
;
1856 struct debug_info_msg_iter
*debug_info_msg_iter
;
1857 struct debug_info_component
*debug_info
= NULL
;
1858 bt_self_message_iterator_status status
;
1859 bt_self_component
*self_comp
= NULL
;
1860 bt_message_array_const input_msgs
;
1861 const bt_message
*out_message
;
1862 uint64_t curr_msg_idx
, i
;
1864 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1866 self_comp
= bt_self_message_iterator_borrow_component(self_msg_iter
);
1867 BT_ASSERT(self_comp
);
1869 debug_info
= bt_self_component_get_data(self_comp
);
1870 BT_ASSERT(debug_info
);
1872 debug_info_msg_iter
= bt_self_message_iterator_get_data(self_msg_iter
);
1873 BT_ASSERT(debug_info_msg_iter
);
1875 upstream_iterator
= debug_info_msg_iter
->msg_iter
;
1876 BT_ASSERT(upstream_iterator
);
1878 upstream_iterator_ret_status
=
1879 bt_self_component_port_input_message_iterator_next(
1880 upstream_iterator
, &input_msgs
, count
);
1881 if (upstream_iterator_ret_status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1883 * No messages were returned. Not necessarily an error. Convert
1884 * the upstream message iterator status to a self status.
1886 status
= bt_common_message_iterator_status_to_self(
1887 upstream_iterator_ret_status
);
1892 * There should never be more received messages than the capacity we
1895 BT_ASSERT(*count
<= capacity
);
1897 for (curr_msg_idx
= 0; curr_msg_idx
< *count
; curr_msg_idx
++) {
1898 out_message
= handle_message(debug_info_msg_iter
,
1899 input_msgs
[curr_msg_idx
]);
1901 goto handle_msg_error
;
1904 msgs
[curr_msg_idx
] = out_message
;
1906 * Drop our reference of the input message as we are done with
1907 * it and created a output copy.
1909 bt_message_put_ref(input_msgs
[curr_msg_idx
]);
1916 * Drop references of all the output messages created before the
1919 for (i
= 0; i
< curr_msg_idx
; i
++) {
1920 bt_message_put_ref(msgs
[i
]);
1923 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1929 bt_self_message_iterator_status
debug_info_msg_iter_init(
1930 bt_self_message_iterator
*self_msg_iter
,
1931 bt_self_component_filter
*self_comp
,
1932 bt_self_component_port_output
*self_port
)
1934 bt_self_message_iterator_status status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1935 struct bt_self_component_port_input
*input_port
;
1936 bt_self_component_port_input_message_iterator
*upstream_iterator
;
1937 struct debug_info_msg_iter
*debug_info_msg_iter
;
1938 gchar
*debug_info_field_name
;
1940 /* Borrow the upstream input port. */
1941 input_port
= bt_self_component_filter_borrow_input_port_by_name(
1944 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1948 /* Create an iterator on the upstream component. */
1949 upstream_iterator
= bt_self_component_port_input_message_iterator_create(
1951 if (!upstream_iterator
) {
1952 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1956 debug_info_msg_iter
= g_new0(struct debug_info_msg_iter
, 1);
1957 if (!debug_info_msg_iter
) {
1958 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1962 /* Create hashtable to will contain debug info mapping. */
1963 debug_info_msg_iter
->debug_info_map
= g_hash_table_new_full(
1964 g_direct_hash
, g_direct_equal
,
1965 (GDestroyNotify
) NULL
,
1966 (GDestroyNotify
) debug_info_destroy
);
1967 if (!debug_info_msg_iter
->debug_info_map
) {
1968 g_free(debug_info_msg_iter
);
1969 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1973 debug_info_msg_iter
->self_comp
=
1974 bt_self_component_filter_as_self_component(self_comp
);
1976 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
1977 debug_info_msg_iter
->msg_iter
, upstream_iterator
);
1979 debug_info_msg_iter
->debug_info_component
= bt_self_component_get_data(
1980 bt_self_component_filter_as_self_component(
1983 debug_info_field_name
=
1984 debug_info_msg_iter
->debug_info_component
->arg_debug_info_field_name
;
1986 debug_info_msg_iter
->ir_maps
= trace_ir_maps_create(
1987 bt_self_component_filter_as_self_component(self_comp
),
1988 debug_info_field_name
);
1989 if (!debug_info_msg_iter
->ir_maps
) {
1990 g_hash_table_destroy(debug_info_msg_iter
->debug_info_map
);
1991 g_free(debug_info_msg_iter
);
1992 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1996 bt_self_message_iterator_set_data(self_msg_iter
, debug_info_msg_iter
);
1998 debug_info_msg_iter
->input_iterator
= self_msg_iter
;
2005 bt_bool
debug_info_msg_iter_can_seek_beginning(
2006 bt_self_message_iterator
*self_msg_iter
)
2008 struct debug_info_msg_iter
*debug_info_msg_iter
=
2009 bt_self_message_iterator_get_data(self_msg_iter
);
2010 BT_ASSERT(debug_info_msg_iter
);
2012 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2013 debug_info_msg_iter
->msg_iter
);
2017 bt_self_message_iterator_status
debug_info_msg_iter_seek_beginning(
2018 bt_self_message_iterator
*self_msg_iter
)
2020 struct debug_info_msg_iter
*debug_info_msg_iter
=
2021 bt_self_message_iterator_get_data(self_msg_iter
);
2022 bt_message_iterator_status status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
2024 BT_ASSERT(debug_info_msg_iter
);
2026 /* Ask the upstream component to seek to the beginning. */
2027 status
= bt_self_component_port_input_message_iterator_seek_beginning(
2028 debug_info_msg_iter
->msg_iter
);
2029 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
2033 /* Clear this iterator data. */
2034 trace_ir_maps_clear(debug_info_msg_iter
->ir_maps
);
2035 g_hash_table_remove_all(debug_info_msg_iter
->debug_info_map
);
2037 return bt_common_message_iterator_status_to_self(status
);
2041 void debug_info_msg_iter_finalize(bt_self_message_iterator
*it
)
2043 struct debug_info_msg_iter
*debug_info_msg_iter
;
2045 debug_info_msg_iter
= bt_self_message_iterator_get_data(it
);
2046 BT_ASSERT(debug_info_msg_iter
);
2048 bt_self_component_port_input_message_iterator_put_ref(
2049 debug_info_msg_iter
->msg_iter
);
2051 trace_ir_maps_destroy(debug_info_msg_iter
->ir_maps
);
2052 g_hash_table_destroy(debug_info_msg_iter
->debug_info_map
);
2054 g_free(debug_info_msg_iter
);