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/FLT.LTTNG-UTILS.DEBUG-INFO"
34 #include "common/assert.h"
35 #include "common/common.h"
36 #include "fd-cache/fd-cache.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
;
74 struct bt_fd_cache fd_cache
;
77 struct debug_info_source
{
78 /* Strings are owned by debug_info_source. */
81 * Store the line number as a string so that the allocation and
82 * conversion to string is only done once.
86 /* short_src_path points inside src_path, no need to free. */
87 const gchar
*short_src_path
;
89 /* short_bin_path points inside bin_path, no need to free. */
90 const gchar
*short_bin_path
;
92 * Location within the binary. Either absolute (@0x1234) or
98 struct proc_debug_info_sources
{
100 * Hash table: base address (pointer to uint64_t) to bin info; owned by
101 * proc_debug_info_sources.
103 GHashTable
*baddr_to_bin_info
;
106 * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *);
107 * owned by proc_debug_info_sources.
109 GHashTable
*ip_to_debug_info_src
;
113 struct debug_info_component
*comp
;
114 const bt_trace
*input_trace
;
115 uint64_t destruction_listener_id
;
118 * Hash table of VPIDs (pointer to int64_t) to
119 * (struct proc_debug_info_sources*); owned by debug_info.
121 GHashTable
*vpid_to_proc_dbg_info_src
;
122 GQuark q_statedump_bin_info
;
123 GQuark q_statedump_debug_link
;
124 GQuark q_statedump_build_id
;
125 GQuark q_statedump_start
;
129 struct bt_fd_cache
*fd_cache
; /* Weak ref. Owned by the iterator. */
133 int debug_info_init(struct debug_info
*info
)
135 info
->q_statedump_bin_info
= g_quark_from_string(
136 "lttng_ust_statedump:bin_info");
137 info
->q_statedump_debug_link
= g_quark_from_string(
138 "lttng_ust_statedump:debug_link");
139 info
->q_statedump_build_id
= g_quark_from_string(
140 "lttng_ust_statedump:build_id");
141 info
->q_statedump_start
= g_quark_from_string(
142 "lttng_ust_statedump:start");
143 info
->q_dl_open
= g_quark_from_string("lttng_ust_dl:dlopen");
144 info
->q_lib_load
= g_quark_from_string("lttng_ust_lib:load");
145 info
->q_lib_unload
= g_quark_from_string("lttng_ust_lib:unload");
147 return bin_info_init();
151 void debug_info_source_destroy(struct debug_info_source
*debug_info_src
)
153 if (!debug_info_src
) {
157 g_free(debug_info_src
->func
);
158 g_free(debug_info_src
->line_no
);
159 g_free(debug_info_src
->src_path
);
160 g_free(debug_info_src
->bin_path
);
161 g_free(debug_info_src
->bin_loc
);
162 g_free(debug_info_src
);
166 struct debug_info_source
*debug_info_source_create_from_bin(
167 struct bin_info
*bin
, uint64_t ip
)
170 struct debug_info_source
*debug_info_src
= NULL
;
171 struct source_location
*src_loc
= NULL
;
173 debug_info_src
= g_new0(struct debug_info_source
, 1);
175 if (!debug_info_src
) {
179 /* Lookup function name */
180 ret
= bin_info_lookup_function_name(bin
, ip
, &debug_info_src
->func
);
185 /* Can't retrieve src_loc from ELF, or could not find binary, skip. */
186 if (!bin
->is_elf_only
|| !debug_info_src
->func
) {
187 /* Lookup source location */
188 ret
= bin_info_lookup_source_location(bin
, ip
, &src_loc
);
190 BT_LOGI("Failed to lookup source location: ret=%d", ret
);
195 debug_info_src
->line_no
=
196 g_strdup_printf("%"PRId64
, src_loc
->line_no
);
197 if (!debug_info_src
->line_no
) {
198 BT_LOGE("Error occured when setting line_no field.");
202 if (src_loc
->filename
) {
203 debug_info_src
->src_path
= g_strdup(src_loc
->filename
);
204 if (!debug_info_src
->src_path
) {
208 debug_info_src
->short_src_path
= get_filename_from_path(
209 debug_info_src
->src_path
);
211 source_location_destroy(src_loc
);
215 debug_info_src
->bin_path
= g_strdup(bin
->elf_path
);
216 if (!debug_info_src
->bin_path
) {
220 debug_info_src
->short_bin_path
= get_filename_from_path(
221 debug_info_src
->bin_path
);
223 ret
= bin_info_get_bin_loc(bin
, ip
, &(debug_info_src
->bin_loc
));
230 return debug_info_src
;
233 debug_info_source_destroy(debug_info_src
);
238 void proc_debug_info_sources_destroy(
239 struct proc_debug_info_sources
*proc_dbg_info_src
)
241 if (!proc_dbg_info_src
) {
245 if (proc_dbg_info_src
->baddr_to_bin_info
) {
246 g_hash_table_destroy(proc_dbg_info_src
->baddr_to_bin_info
);
249 if (proc_dbg_info_src
->ip_to_debug_info_src
) {
250 g_hash_table_destroy(proc_dbg_info_src
->ip_to_debug_info_src
);
253 g_free(proc_dbg_info_src
);
257 struct proc_debug_info_sources
*proc_debug_info_sources_create(void)
259 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
261 proc_dbg_info_src
= g_new0(struct proc_debug_info_sources
, 1);
262 if (!proc_dbg_info_src
) {
266 proc_dbg_info_src
->baddr_to_bin_info
= g_hash_table_new_full(
267 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
268 (GDestroyNotify
) bin_info_destroy
);
269 if (!proc_dbg_info_src
->baddr_to_bin_info
) {
273 proc_dbg_info_src
->ip_to_debug_info_src
= g_hash_table_new_full(
274 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
275 (GDestroyNotify
) debug_info_source_destroy
);
276 if (!proc_dbg_info_src
->ip_to_debug_info_src
) {
281 return proc_dbg_info_src
;
284 proc_debug_info_sources_destroy(proc_dbg_info_src
);
289 struct proc_debug_info_sources
*proc_debug_info_sources_ht_get_entry(
290 GHashTable
*ht
, int64_t vpid
)
292 gpointer key
= g_new0(int64_t, 1);
293 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
299 *((int64_t *) key
) = vpid
;
301 /* Exists? Return it */
302 proc_dbg_info_src
= g_hash_table_lookup(ht
, key
);
303 if (proc_dbg_info_src
) {
307 /* Otherwise, create and return it */
308 proc_dbg_info_src
= proc_debug_info_sources_create();
309 if (!proc_dbg_info_src
) {
313 g_hash_table_insert(ht
, key
, proc_dbg_info_src
);
314 /* Ownership passed to ht */
318 return proc_dbg_info_src
;
322 const bt_field
*event_borrow_payload_field(const bt_event
*event
,
323 const char *field_name
)
325 const bt_field
*event_payload
, *field
;
327 event_payload
= bt_event_borrow_payload_field_const(event
);
328 BT_ASSERT(event_payload
);
330 field
= bt_field_structure_borrow_member_field_by_name_const(
331 event_payload
, field_name
);
336 const bt_field
*event_borrow_common_context_field(const bt_event
*event
,
337 const char *field_name
)
339 const bt_field
*event_common_ctx
, *field
= NULL
;
341 event_common_ctx
= bt_event_borrow_common_context_field_const(event
);
342 if (!event_common_ctx
) {
346 field
= bt_field_structure_borrow_member_field_by_name_const(
347 event_common_ctx
, field_name
);
354 void event_get_common_context_signed_integer_field_value(
355 const bt_event
*event
, const char *field_name
, int64_t *value
)
357 *value
= bt_field_signed_integer_get_value(
358 event_borrow_common_context_field(event
, field_name
));
362 int event_get_payload_build_id_length(const bt_event
*event
,
363 const char *field_name
, uint64_t *build_id_len
)
365 const bt_field
*build_id_field
;
366 const bt_field_class
*build_id_field_class
;
368 build_id_field
= event_borrow_payload_field(event
, field_name
);
369 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
371 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
372 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
373 BT_ASSERT(bt_field_class_get_type(
374 bt_field_class_array_borrow_element_field_class_const(
375 build_id_field_class
)) ==
376 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
378 *build_id_len
= bt_field_array_get_length(build_id_field
);
384 int event_get_payload_build_id_value(const bt_event
*event
,
385 const char *field_name
, uint8_t *build_id
)
387 const bt_field
*curr_field
, *build_id_field
;
388 const bt_field_class
*build_id_field_class
;
389 uint64_t i
, build_id_len
;
394 build_id_field
= event_borrow_payload_field(event
, field_name
);
395 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
397 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
398 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
399 BT_ASSERT(bt_field_class_get_type(
400 bt_field_class_array_borrow_element_field_class_const(
401 build_id_field_class
)) ==
402 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
404 build_id_len
= bt_field_array_get_length(build_id_field
);
406 for (i
= 0; i
< build_id_len
; i
++) {
408 bt_field_array_borrow_element_field_by_index_const(
411 build_id
[i
] = bt_field_unsigned_integer_get_value(curr_field
);
418 void event_get_payload_unsigned_integer_field_value(const bt_event
*event
,
419 const char *field_name
, uint64_t *value
)
421 *value
= bt_field_unsigned_integer_get_value(
422 event_borrow_payload_field(event
, field_name
));
426 void event_get_payload_string_field_value(const bt_event
*event
,
427 const char *field_name
, const char **value
)
429 *value
= bt_field_string_get_value(
430 event_borrow_payload_field(event
, field_name
));
434 bool event_has_payload_field(const bt_event
*event
,
435 const char *field_name
)
437 return event_borrow_payload_field(event
, field_name
) != NULL
;
441 struct debug_info_source
*proc_debug_info_sources_get_entry(
442 struct proc_debug_info_sources
*proc_dbg_info_src
, uint64_t ip
)
444 struct debug_info_source
*debug_info_src
= NULL
;
445 gpointer key
= g_new0(uint64_t, 1);
447 gpointer baddr
, value
;
453 *((uint64_t *) key
) = ip
;
455 /* Look in IP to debug infos hash table first. */
456 debug_info_src
= g_hash_table_lookup(
457 proc_dbg_info_src
->ip_to_debug_info_src
,
459 if (debug_info_src
) {
463 /* Check in all bin_infos. */
464 g_hash_table_iter_init(&iter
, proc_dbg_info_src
->baddr_to_bin_info
);
466 while (g_hash_table_iter_next(&iter
, &baddr
, &value
))
468 struct bin_info
*bin
= value
;
470 if (!bin_info_has_address(value
, ip
)) {
475 * Found; add it to cache.
477 * FIXME: this should be bounded in size (and implement
478 * a caching policy), and entries should be prunned when
479 * libraries are unmapped.
481 debug_info_src
= debug_info_source_create_from_bin(bin
, ip
);
482 if (debug_info_src
) {
484 proc_dbg_info_src
->ip_to_debug_info_src
,
485 key
, debug_info_src
);
486 /* Ownership passed to ht. */
494 return debug_info_src
;
498 struct debug_info_source
*debug_info_query(struct debug_info
*debug_info
,
499 int64_t vpid
, uint64_t ip
)
501 struct debug_info_source
*dbg_info_src
= NULL
;
502 struct proc_debug_info_sources
*proc_dbg_info_src
;
504 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
505 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
506 if (!proc_dbg_info_src
) {
510 dbg_info_src
= proc_debug_info_sources_get_entry(proc_dbg_info_src
, ip
);
517 struct debug_info
*debug_info_create(struct debug_info_component
*comp
,
518 const bt_trace
*trace
, struct bt_fd_cache
*fdc
)
521 struct debug_info
*debug_info
;
527 debug_info
= g_new0(struct debug_info
, 1);
532 debug_info
->vpid_to_proc_dbg_info_src
= g_hash_table_new_full(
533 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
534 (GDestroyNotify
) proc_debug_info_sources_destroy
);
535 if (!debug_info
->vpid_to_proc_dbg_info_src
) {
539 debug_info
->comp
= comp
;
540 ret
= debug_info_init(debug_info
);
545 debug_info
->input_trace
= trace
;
546 debug_info
->fd_cache
= fdc
;
556 void debug_info_destroy(struct debug_info
*debug_info
)
558 bt_trace_status status
;
563 if (debug_info
->vpid_to_proc_dbg_info_src
) {
564 g_hash_table_destroy(debug_info
->vpid_to_proc_dbg_info_src
);
567 status
= bt_trace_remove_destruction_listener(debug_info
->input_trace
,
568 debug_info
->destruction_listener_id
);
569 if (status
!= BT_TRACE_STATUS_OK
) {
570 BT_LOGE("Trace destruction listener removal failed.");
579 void handle_event_statedump_build_id(struct debug_info
*debug_info
,
580 const bt_event
*event
)
582 struct proc_debug_info_sources
*proc_dbg_info_src
;
583 uint64_t build_id_len
, baddr
;
584 uint8_t *build_id
= NULL
;
585 struct bin_info
*bin
;
589 event_get_common_context_signed_integer_field_value(event
,
590 VPID_FIELD_NAME
, &vpid
);
591 event_get_payload_unsigned_integer_field_value(event
,
592 BADDR_FIELD_NAME
, &baddr
);
594 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
595 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
596 if (!proc_dbg_info_src
) {
600 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
604 * The build_id event comes after the bin has been
605 * created. If it isn't found, just ignore this event.
609 ret
= event_get_payload_build_id_length(event
, BUILD_ID_FIELD_NAME
,
612 build_id
= g_new0(uint8_t, build_id_len
);
617 ret
= event_get_payload_build_id_value(event
, BUILD_ID_FIELD_NAME
,
623 ret
= bin_info_set_build_id(bin
, build_id
, build_id_len
);
629 * Reset the is_elf_only flag in case it had been set
630 * previously, because we might find separate debug info using
631 * the new build id information.
633 bin
->is_elf_only
= false;
641 void handle_event_statedump_debug_link(struct debug_info
*debug_info
,
642 const bt_event
*event
)
644 struct proc_debug_info_sources
*proc_dbg_info_src
;
645 struct bin_info
*bin
= NULL
;
648 const char *filename
= NULL
;
650 uint64_t crc_field_value
;
652 event_get_common_context_signed_integer_field_value(event
,
653 VPID_FIELD_NAME
, &vpid
);
655 event_get_payload_unsigned_integer_field_value(event
,
656 BADDR_FIELD_NAME
, &baddr
);
658 event_get_payload_unsigned_integer_field_value(event
,
659 CRC32_FIELD_NAME
, &crc_field_value
);
661 crc32
= (uint32_t) crc_field_value
;
663 event_get_payload_string_field_value(event
,
664 FILENAME_FIELD_NAME
, &filename
);
666 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
667 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
668 if (!proc_dbg_info_src
) {
672 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
676 * The debug_link event comes after the bin has been
677 * created. If it isn't found, just ignore this event.
682 bin_info_set_debug_link(bin
, filename
, crc32
);
689 void handle_bin_info_event(struct debug_info
*debug_info
,
690 const bt_event
*event
, bool has_pic_field
)
692 struct proc_debug_info_sources
*proc_dbg_info_src
;
693 struct bin_info
*bin
;
694 uint64_t baddr
, memsz
;
700 event_get_payload_unsigned_integer_field_value(event
,
701 MEMSZ_FIELD_NAME
, &memsz
);
707 event_get_payload_unsigned_integer_field_value(event
,
708 BADDR_FIELD_NAME
, &baddr
);
711 * This field is not produced by the dlopen event emitted before
714 if (!event_has_payload_field(event
, PATH_FIELD_NAME
)) {
717 event_get_payload_string_field_value(event
, PATH_FIELD_NAME
, &path
);
720 uint64_t is_pic_field_value
;
722 event_get_payload_unsigned_integer_field_value(event
,
723 IS_PIC_FIELD_NAME
, &is_pic_field_value
);
724 is_pic
= is_pic_field_value
== 1;
727 * dlopen has no is_pic field, because the shared
728 * object is always PIC.
733 event_get_common_context_signed_integer_field_value(event
,
734 VPID_FIELD_NAME
, &vpid
);
736 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
737 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
738 if (!proc_dbg_info_src
) {
742 key
= g_new0(uint64_t, 1);
747 *((uint64_t *) key
) = baddr
;
749 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
, key
);
754 bin
= bin_info_create(debug_info
->fd_cache
, path
, baddr
, memsz
, is_pic
,
755 debug_info
->comp
->arg_debug_dir
,
756 debug_info
->comp
->arg_target_prefix
);
761 g_hash_table_insert(proc_dbg_info_src
->baddr_to_bin_info
, key
, bin
);
762 /* Ownership passed to ht. */
771 void handle_event_statedump_bin_info(struct debug_info
*debug_info
,
772 const bt_event
*event
)
774 handle_bin_info_event(debug_info
, event
, true);
778 void handle_event_lib_load(struct debug_info
*debug_info
,
779 const bt_event
*event
)
781 handle_bin_info_event(debug_info
, event
, false);
785 void handle_event_lib_unload(struct debug_info
*debug_info
,
786 const bt_event
*event
)
789 struct proc_debug_info_sources
*proc_dbg_info_src
;
793 event_get_payload_unsigned_integer_field_value(event
, BADDR_FIELD_NAME
,
796 event_get_common_context_signed_integer_field_value(event
,
797 VPID_FIELD_NAME
, &vpid
);
799 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
800 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
801 if (!proc_dbg_info_src
) {
803 * It's an unload event for a library for which no load event
804 * was previously received.
809 ret
= g_hash_table_remove(proc_dbg_info_src
->baddr_to_bin_info
,
817 void handle_event_statedump_start(struct debug_info
*debug_info
,
818 const bt_event
*event
)
820 struct proc_debug_info_sources
*proc_dbg_info_src
;
823 event_get_common_context_signed_integer_field_value(
824 event
, VPID_FIELD_NAME
, &vpid
);
826 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
827 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
828 if (!proc_dbg_info_src
) {
832 g_hash_table_remove_all(proc_dbg_info_src
->baddr_to_bin_info
);
833 g_hash_table_remove_all(proc_dbg_info_src
->ip_to_debug_info_src
);
839 void trace_debug_info_remove_func(const bt_trace
*in_trace
, void *data
)
841 struct debug_info_msg_iter
*debug_it
= data
;
842 if (debug_it
->debug_info_map
) {
844 ret
= g_hash_table_remove(debug_it
->debug_info_map
,
845 (gpointer
) in_trace
);
851 void handle_event_statedump(struct debug_info_msg_iter
*debug_it
,
852 const bt_event
*event
)
854 const bt_event_class
*event_class
;
855 const char *event_name
;
857 const bt_trace
*trace
;
858 struct debug_info
*debug_info
;
863 event_class
= bt_event_borrow_class_const(event
);
865 event_name
= bt_event_class_get_name(event_class
);
867 trace
= bt_stream_borrow_trace_const(
868 bt_event_borrow_stream_const(event
));
870 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
, trace
);
872 debug_info
= debug_info_create(debug_it
->debug_info_component
,
873 trace
, &debug_it
->fd_cache
);
874 g_hash_table_insert(debug_it
->debug_info_map
, (gpointer
) trace
,
876 bt_trace_add_destruction_listener(trace
,
877 trace_debug_info_remove_func
, debug_it
,
878 &debug_info
->destruction_listener_id
);
881 q_event_name
= g_quark_try_string(event_name
);
883 if (q_event_name
== debug_info
->q_statedump_bin_info
) {
885 handle_event_statedump_bin_info(debug_info
, event
);
886 } else if (q_event_name
== debug_info
->q_dl_open
||
887 q_event_name
== debug_info
->q_lib_load
) {
889 * dl_open and lib_load events are both checked for since
890 * only dl_open was produced as of lttng-ust 2.8.
892 * lib_load, which is produced from lttng-ust 2.9+, is a lot
893 * more reliable since it will be emitted when other functions
894 * of the dlopen family are called (e.g. dlmopen) and when
895 * library are transitively loaded.
897 handle_event_lib_load(debug_info
, event
);
898 } else if (q_event_name
== debug_info
->q_statedump_start
) {
899 /* Start state dump */
900 handle_event_statedump_start(debug_info
, event
);
901 } else if (q_event_name
== debug_info
->q_statedump_debug_link
) {
902 /* Debug link info */
903 handle_event_statedump_debug_link(debug_info
, event
);
904 } else if (q_event_name
== debug_info
->q_statedump_build_id
) {
906 handle_event_statedump_build_id(debug_info
, event
);
907 } else if (q_event_name
== debug_info
-> q_lib_unload
) {
908 handle_event_lib_unload(debug_info
, event
);
915 void destroy_debug_info_comp(struct debug_info_component
*debug_info
)
921 g_free(debug_info
->arg_debug_dir
);
922 g_free(debug_info
->arg_debug_info_field_name
);
923 g_free(debug_info
->arg_target_prefix
);
928 void fill_debug_info_bin_field(struct debug_info_source
*dbg_info_src
,
929 bool full_path
, bt_field
*curr_field
)
931 bt_field_status status
;
933 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
934 BT_FIELD_CLASS_TYPE_STRING
);
938 status
= bt_field_string_set_value(curr_field
,
939 dbg_info_src
->bin_path
);
941 status
= bt_field_string_set_value(curr_field
,
942 dbg_info_src
->short_bin_path
);
944 if (status
!= BT_FIELD_STATUS_OK
) {
945 BT_LOGE("Cannot set path component of \"bin\" "
946 "curr_field field's value: str-fc-addr=%p",
950 status
= bt_field_string_append(curr_field
, dbg_info_src
->bin_loc
);
951 if (status
!= BT_FIELD_STATUS_OK
) {
952 BT_LOGE("Cannot set bin location component of \"bin\" "
953 "curr_field field's value: str-fc-addr=%p",
957 status
= bt_field_string_set_value(curr_field
, "");
958 if (status
!= BT_FIELD_STATUS_OK
) {
959 BT_LOGE("Cannot set \"bin\" curr_field field's value: "
960 "str-fc-addr=%p", curr_field
);
966 void fill_debug_info_func_field(struct debug_info_source
*dbg_info_src
,
967 bt_field
*curr_field
)
969 bt_field_status status
;
971 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
972 BT_FIELD_CLASS_TYPE_STRING
);
973 if (dbg_info_src
&& dbg_info_src
->func
) {
974 status
= bt_field_string_set_value(curr_field
,
977 status
= bt_field_string_set_value(curr_field
, "");
979 if (status
!= BT_FIELD_STATUS_OK
) {
980 BT_LOGE("Cannot set \"func\" curr_field field's value: "
981 "str-fc-addr=%p", curr_field
);
986 void fill_debug_info_src_field(struct debug_info_source
*dbg_info_src
,
987 bool full_path
, bt_field
*curr_field
)
989 bt_field_status status
;
991 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
992 BT_FIELD_CLASS_TYPE_STRING
);
994 if (dbg_info_src
&& dbg_info_src
->src_path
) {
996 status
= bt_field_string_set_value(curr_field
,
997 dbg_info_src
->src_path
);
999 status
= bt_field_string_set_value(curr_field
,
1000 dbg_info_src
->short_src_path
);
1002 if (status
!= BT_FIELD_STATUS_OK
) {
1003 BT_LOGE("Cannot set path component of \"src\" "
1004 "curr_field field's value: str-fc-addr=%p",
1008 status
= bt_field_string_append(curr_field
, ":");
1009 if (status
!= BT_FIELD_STATUS_OK
) {
1010 BT_LOGE("Cannot set colon component of \"src\" "
1011 "curr_field field's value: str-fc-addr=%p",
1015 status
= bt_field_string_append(curr_field
, dbg_info_src
->line_no
);
1016 if (status
!= BT_FIELD_STATUS_OK
) {
1017 BT_LOGE("Cannot set line number component of \"src\" "
1018 "curr_field field's value: str-fc-addr=%p",
1022 status
= bt_field_string_set_value(curr_field
, "");
1023 if (status
!= BT_FIELD_STATUS_OK
) {
1024 BT_LOGE("Cannot set \"src\" curr_field field's value: "
1025 "str-fc-addr=%p", curr_field
);
1030 void fill_debug_info_field_empty(bt_field
*debug_info_field
)
1032 bt_field_status status
;
1033 bt_field
*bin_field
, *func_field
, *src_field
;
1035 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1036 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1038 bin_field
= bt_field_structure_borrow_member_field_by_name(
1039 debug_info_field
, "bin");
1040 func_field
= bt_field_structure_borrow_member_field_by_name(
1041 debug_info_field
, "func");
1042 src_field
= bt_field_structure_borrow_member_field_by_name(
1043 debug_info_field
, "src");
1045 BT_ASSERT(bt_field_get_class_type(bin_field
) ==
1046 BT_FIELD_CLASS_TYPE_STRING
);
1047 BT_ASSERT(bt_field_get_class_type(func_field
) ==
1048 BT_FIELD_CLASS_TYPE_STRING
);
1049 BT_ASSERT(bt_field_get_class_type(src_field
) ==
1050 BT_FIELD_CLASS_TYPE_STRING
);
1052 status
= bt_field_string_set_value(bin_field
, "");
1053 if (status
!= BT_FIELD_STATUS_OK
) {
1054 BT_LOGE("Cannot set \"bin\" bin_field field's value: "
1055 "str-fc-addr=%p", bin_field
);
1058 status
= bt_field_string_set_value(func_field
, "");
1059 if (status
!= BT_FIELD_STATUS_OK
) {
1060 BT_LOGE("Cannot set \"func\" func_field field's value: "
1061 "str-fc-addr=%p", func_field
);
1064 status
= bt_field_string_set_value(src_field
, "");
1065 if (status
!= BT_FIELD_STATUS_OK
) {
1066 BT_LOGE("Cannot set \"src\" src_field field's value: "
1067 "str-fc-addr=%p", src_field
);
1071 void fill_debug_info_field(struct debug_info
*debug_info
, int64_t vpid
,
1072 uint64_t ip
, bt_field
*debug_info_field
)
1074 struct debug_info_source
*dbg_info_src
;
1075 const bt_field_class
*debug_info_fc
;
1077 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1078 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1080 debug_info_fc
= bt_field_borrow_class_const(debug_info_field
);
1082 BT_ASSERT(bt_field_class_structure_get_member_count(debug_info_fc
) == 3);
1084 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1086 fill_debug_info_bin_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1087 bt_field_structure_borrow_member_field_by_name(
1088 debug_info_field
, "bin"));
1089 fill_debug_info_func_field(dbg_info_src
,
1090 bt_field_structure_borrow_member_field_by_name(
1091 debug_info_field
, "func"));
1092 fill_debug_info_src_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1093 bt_field_structure_borrow_member_field_by_name(
1094 debug_info_field
, "src"));
1098 void fill_debug_info_event_if_needed(struct debug_info_msg_iter
*debug_it
,
1099 const bt_event
*in_event
, bt_event
*out_event
)
1101 bt_field
*out_common_ctx_field
, *out_debug_info_field
;
1102 const bt_field
*vpid_field
, *ip_field
, *in_common_ctx_field
;
1103 const bt_field_class
*in_common_ctx_fc
;
1104 struct debug_info
*debug_info
;
1107 gchar
*debug_info_field_name
=
1108 debug_it
->debug_info_component
->arg_debug_info_field_name
;
1110 in_common_ctx_field
= bt_event_borrow_common_context_field_const(
1112 if (!in_common_ctx_field
) {
1114 * There is no event common context so no need to add debug
1120 in_common_ctx_fc
= bt_field_borrow_class_const(in_common_ctx_field
);
1121 if (!is_event_common_ctx_dbg_info_compatible(in_common_ctx_fc
,
1122 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1124 * The input event common context does not have the necessary
1125 * fields to resolve debug information.
1130 /* Borrow the debug-info field. */
1131 out_common_ctx_field
= bt_event_borrow_common_context_field(out_event
);
1132 if (!out_common_ctx_field
) {
1136 out_debug_info_field
= bt_field_structure_borrow_member_field_by_name(
1137 out_common_ctx_field
, debug_info_field_name
);
1139 vpid_field
= bt_field_structure_borrow_member_field_by_name_const(
1140 out_common_ctx_field
, VPID_FIELD_NAME
);
1141 ip_field
= bt_field_structure_borrow_member_field_by_name_const(
1142 out_common_ctx_field
, IP_FIELD_NAME
);
1144 vpid
= bt_field_signed_integer_get_value(vpid_field
);
1145 ip
= bt_field_unsigned_integer_get_value(ip_field
);
1148 * Borrow the debug_info structure needed for the source
1151 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
,
1152 bt_stream_borrow_trace_const(
1153 bt_event_borrow_stream_const(in_event
)));
1157 * Perform the debug-info resolving and set the event fields
1160 fill_debug_info_field(debug_info
, vpid
, ip
, out_debug_info_field
);
1162 BT_LOGD("No debug information for this trace. Setting debug "
1163 "info fields to empty strings.");
1164 fill_debug_info_field_empty(out_debug_info_field
);
1171 void update_event_statedump_if_needed(struct debug_info_msg_iter
*debug_it
,
1172 const bt_event
*in_event
)
1174 const bt_field
*event_common_ctx
;
1175 const bt_field_class
*event_common_ctx_fc
;
1176 const bt_event_class
*in_event_class
= bt_event_borrow_class_const(in_event
);
1179 * If the event is an lttng_ust_statedump event AND has the right event
1180 * common context fields update the debug-info view for this process.
1182 event_common_ctx
= bt_event_borrow_common_context_field_const(in_event
);
1183 if (!event_common_ctx
) {
1187 event_common_ctx_fc
= bt_field_borrow_class_const(event_common_ctx
);
1188 if (is_event_common_ctx_dbg_info_compatible(event_common_ctx_fc
,
1189 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1190 /* Checkout if it might be a one of lttng ust statedump events. */
1191 const char *in_event_name
= bt_event_class_get_name(in_event_class
);
1192 if (strncmp(in_event_name
, LTTNG_UST_STATEDUMP_PREFIX
,
1193 strlen(LTTNG_UST_STATEDUMP_PREFIX
)) == 0) {
1194 /* Handle statedump events. */
1195 handle_event_statedump(debug_it
, in_event
);
1203 bt_message
*handle_event_message(struct debug_info_msg_iter
*debug_it
,
1204 const bt_message
*in_message
)
1206 const bt_clock_snapshot
*cs
;
1207 const bt_clock_class
*default_cc
;
1208 const bt_packet
*in_packet
;
1209 bt_event_class
*out_event_class
;
1210 bt_packet
*out_packet
;
1211 bt_event
*out_event
;
1213 bt_message
*out_message
= NULL
;
1215 /* Borrow the input event and its event class. */
1216 const bt_event
*in_event
=
1217 bt_message_event_borrow_event_const(in_message
);
1218 const bt_event_class
*in_event_class
=
1219 bt_event_borrow_class_const(in_event
);
1221 update_event_statedump_if_needed(debug_it
, in_event
);
1223 out_event_class
= trace_ir_mapping_borrow_mapped_event_class(
1224 debug_it
->ir_maps
, in_event_class
);
1225 if (!out_event_class
) {
1226 out_event_class
= trace_ir_mapping_create_new_mapped_event_class(
1227 debug_it
->ir_maps
, in_event_class
);
1229 BT_ASSERT(out_event_class
);
1231 /* Borrow the input and output packets. */
1232 in_packet
= bt_event_borrow_packet_const(in_event
);
1233 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
,
1236 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1237 bt_event_class_borrow_stream_class_const(in_event_class
));
1239 /* Borrow event clock snapshot. */
1240 cs
= bt_message_event_borrow_default_clock_snapshot_const(
1243 /* Create an output event message. */
1244 out_message
= bt_message_event_create_with_default_clock_snapshot(
1245 debug_it
->input_iterator
,
1246 out_event_class
, out_packet
,
1247 bt_clock_snapshot_get_value(cs
));
1249 out_message
= bt_message_event_create(debug_it
->input_iterator
,
1250 out_event_class
, out_packet
);
1254 BT_LOGE("Error creating output event message.");
1258 out_event
= bt_message_event_borrow_event(out_message
);
1260 /* Copy the original fields to the output event. */
1261 copy_event_content(in_event
, out_event
);
1264 * Try to set the debug-info fields based on debug information that is
1267 fill_debug_info_event_if_needed(debug_it
, in_event
, out_event
);
1274 bt_message
*handle_stream_begin_message(struct debug_info_msg_iter
*debug_it
,
1275 const bt_message
*in_message
)
1277 const bt_stream
*in_stream
;
1278 bt_message
*out_message
;
1279 bt_stream
*out_stream
;
1281 in_stream
= bt_message_stream_beginning_borrow_stream_const(in_message
);
1282 BT_ASSERT(in_stream
);
1284 /* Create a duplicated output stream. */
1285 out_stream
= trace_ir_mapping_create_new_mapped_stream(
1286 debug_it
->ir_maps
, in_stream
);
1292 /* Create an output stream beginning message. */
1293 out_message
= bt_message_stream_beginning_create(
1294 debug_it
->input_iterator
, out_stream
);
1296 BT_LOGE("Error creating output stream beginning message: "
1297 "out-s-addr=%p", out_stream
);
1304 bt_message
*handle_stream_end_message(struct debug_info_msg_iter
*debug_it
,
1305 const bt_message
*in_message
)
1307 const bt_stream
*in_stream
;
1308 bt_message
*out_message
= NULL
;
1309 bt_stream
*out_stream
;
1311 in_stream
= bt_message_stream_end_borrow_stream_const(in_message
);
1312 BT_ASSERT(in_stream
);
1314 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1315 debug_it
->ir_maps
, in_stream
);
1316 BT_ASSERT(out_stream
);
1318 /* Create an output stream end message. */
1319 out_message
= bt_message_stream_end_create(debug_it
->input_iterator
,
1322 BT_LOGE("Error creating output stream end message: out-s-addr=%p",
1326 /* Remove stream from trace mapping hashtable. */
1327 trace_ir_mapping_remove_mapped_stream(debug_it
->ir_maps
, in_stream
);
1333 bt_message
*handle_packet_begin_message(struct debug_info_msg_iter
*debug_it
,
1334 const bt_message
*in_message
)
1336 bool has_default_clock_snapshot
;
1337 const bt_clock_snapshot
*cs
;
1338 bt_message
*out_message
= NULL
;
1339 bt_packet
*out_packet
;
1341 const bt_packet
*in_packet
=
1342 bt_message_packet_beginning_borrow_packet_const(in_message
);
1343 BT_ASSERT(in_packet
);
1345 /* This packet should not be already mapped. */
1346 BT_ASSERT(!trace_ir_mapping_borrow_mapped_packet(
1347 debug_it
->ir_maps
, in_packet
));
1349 out_packet
= trace_ir_mapping_create_new_mapped_packet(debug_it
->ir_maps
,
1352 BT_ASSERT(out_packet
);
1354 has_default_clock_snapshot
=
1355 bt_stream_class_packets_have_beginning_default_clock_snapshot(
1356 bt_stream_borrow_class_const(
1357 bt_packet_borrow_stream_const(in_packet
)));
1358 if (has_default_clock_snapshot
) {
1359 /* Borrow clock snapshot. */
1360 cs
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
1363 /* Create an output packet beginning message. */
1364 out_message
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1365 debug_it
->input_iterator
, out_packet
,
1366 bt_clock_snapshot_get_value(cs
));
1368 out_message
= bt_message_packet_beginning_create(
1369 debug_it
->input_iterator
, out_packet
);
1372 BT_LOGE("Error creating output packet beginning message: "
1373 "out-p-addr=%p", out_packet
);
1380 bt_message
*handle_packet_end_message(struct debug_info_msg_iter
*debug_it
,
1381 const bt_message
*in_message
)
1383 bool has_default_clock_snapshot
;
1384 const bt_clock_snapshot
*cs
;
1385 const bt_packet
*in_packet
;
1386 bt_message
*out_message
= NULL
;
1387 bt_packet
*out_packet
;
1389 in_packet
= bt_message_packet_end_borrow_packet_const(in_message
);
1390 BT_ASSERT(in_packet
);
1392 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
, in_packet
);
1393 BT_ASSERT(out_packet
);
1395 has_default_clock_snapshot
=
1396 bt_stream_class_packets_have_end_default_clock_snapshot(
1397 bt_stream_borrow_class_const(
1398 bt_packet_borrow_stream_const(in_packet
)));
1399 if (has_default_clock_snapshot
) {
1400 /* Borrow clock snapshot. */
1401 cs
= bt_message_packet_end_borrow_default_clock_snapshot_const(
1404 /* Create an outpute packet end message. */
1405 out_message
= bt_message_packet_end_create_with_default_clock_snapshot(
1406 debug_it
->input_iterator
, out_packet
,
1407 bt_clock_snapshot_get_value(cs
));
1409 out_message
= bt_message_packet_end_create(
1410 debug_it
->input_iterator
, out_packet
);
1414 BT_LOGE("Error creating output packet end message: "
1415 "out-p-addr=%p", out_packet
);
1418 /* Remove packet from data mapping hashtable. */
1419 trace_ir_mapping_remove_mapped_packet(debug_it
->ir_maps
, in_packet
);
1425 bt_message
*handle_msg_iterator_inactivity(struct debug_info_msg_iter
*debug_it
,
1426 const bt_message
*in_message
)
1429 * This message type can be forwarded directly because it does
1430 * not refer to any objects in the trace class.
1432 bt_message_get_ref(in_message
);
1433 return (bt_message
*) in_message
;
1437 bt_message
*handle_stream_act_begin_message(struct debug_info_msg_iter
*debug_it
,
1438 const bt_message
*in_message
)
1440 const bt_clock_snapshot
*cs
;
1441 const bt_clock_class
*default_cc
;
1442 bt_message
*out_message
= NULL
;
1443 bt_stream
*out_stream
;
1445 bt_message_stream_activity_clock_snapshot_state cs_state
;
1447 const bt_stream
*in_stream
=
1448 bt_message_stream_activity_beginning_borrow_stream_const(
1450 BT_ASSERT(in_stream
);
1452 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
,
1454 BT_ASSERT(out_stream
);
1456 out_message
= bt_message_stream_activity_beginning_create(
1457 debug_it
->input_iterator
, out_stream
);
1459 BT_LOGE("Error creating output stream activity beginning "
1460 "message: out-s-addr=%p", out_stream
);
1464 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1465 bt_stream_borrow_class_const(in_stream
));
1467 /* Borrow clock snapshot. */
1469 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
1472 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1473 cs_value
= bt_clock_snapshot_get_value(cs
);
1474 bt_message_stream_activity_beginning_set_default_clock_snapshot(
1475 out_message
, cs_value
);
1477 bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
1478 out_message
, cs_state
);
1487 bt_message
*handle_stream_act_end_message(struct debug_info_msg_iter
*debug_it
,
1488 const bt_message
*in_message
)
1490 const bt_clock_snapshot
*cs
;
1491 const bt_clock_class
*default_cc
;
1492 const bt_stream
*in_stream
;
1493 bt_message
*out_message
;
1494 bt_stream
*out_stream
;
1496 bt_message_stream_activity_clock_snapshot_state cs_state
;
1498 in_stream
= bt_message_stream_activity_end_borrow_stream_const(
1500 BT_ASSERT(in_stream
);
1502 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
,
1504 BT_ASSERT(out_stream
);
1506 out_message
= bt_message_stream_activity_end_create(
1507 debug_it
->input_iterator
, out_stream
);
1509 BT_LOGE("Error creating output stream activity end message: "
1510 "out-s-addr=%p", out_stream
);
1514 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1515 bt_stream_borrow_class_const(in_stream
));
1519 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
1522 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1523 cs_value
= bt_clock_snapshot_get_value(cs
);
1524 bt_message_stream_activity_end_set_default_clock_snapshot(
1525 out_message
, cs_value
);
1527 bt_message_stream_activity_end_set_default_clock_snapshot_state(
1528 out_message
, cs_state
);
1537 bt_message
*handle_discarded_events_message(struct debug_info_msg_iter
*debug_it
,
1538 const bt_message
*in_message
)
1540 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1541 const bt_stream
*in_stream
;
1542 bool has_default_clock_snapshots
;
1543 uint64_t discarded_events
, begin_cs_value
, end_cs_value
;
1544 bt_property_availability prop_avail
;
1545 bt_message
*out_message
= NULL
;
1546 bt_stream
*out_stream
;
1548 in_stream
= bt_message_discarded_events_borrow_stream_const(
1550 BT_ASSERT(in_stream
);
1552 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1553 debug_it
->ir_maps
, in_stream
);
1554 BT_ASSERT(out_stream
);
1556 has_default_clock_snapshots
=
1557 bt_stream_class_discarded_events_have_default_clock_snapshots(
1558 bt_stream_borrow_class_const(in_stream
));
1559 if (has_default_clock_snapshots
) {
1561 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
1564 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
1567 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1568 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1571 bt_message_discarded_events_create_with_default_clock_snapshots(
1572 debug_it
->input_iterator
, out_stream
,
1573 begin_cs_value
, end_cs_value
);
1575 out_message
= bt_message_discarded_events_create(
1576 debug_it
->input_iterator
, out_stream
);
1579 BT_LOGE("Error creating output discarded events message: "
1580 "out-s-addr=%p", out_stream
);
1584 prop_avail
= bt_message_discarded_events_get_count(in_message
,
1587 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1588 bt_message_discarded_events_set_count(out_message
,
1597 bt_message
*handle_discarded_packets_message(struct debug_info_msg_iter
*debug_it
,
1598 const bt_message
*in_message
)
1600 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1601 bool has_default_clock_snapshots
;
1602 const bt_stream
*in_stream
;
1603 uint64_t discarded_packets
, begin_cs_value
, end_cs_value
;
1604 bt_property_availability prop_avail
;
1605 bt_message
*out_message
= NULL
;
1606 bt_stream
*out_stream
;
1608 in_stream
= bt_message_discarded_packets_borrow_stream_const(
1610 BT_ASSERT(in_stream
);
1612 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1613 debug_it
->ir_maps
, in_stream
);
1614 BT_ASSERT(out_stream
);
1616 has_default_clock_snapshots
=
1617 bt_stream_class_discarded_packets_have_default_clock_snapshots(
1618 bt_stream_borrow_class_const(in_stream
));
1619 if (has_default_clock_snapshots
) {
1621 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
1625 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
1628 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1629 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1631 out_message
= bt_message_discarded_packets_create_with_default_clock_snapshots(
1632 debug_it
->input_iterator
, out_stream
,
1633 begin_cs_value
, end_cs_value
);
1635 out_message
= bt_message_discarded_packets_create(
1636 debug_it
->input_iterator
, out_stream
);
1639 BT_LOGE("Error creating output discarded packet message: "
1640 "out-s-addr=%p", out_stream
);
1644 prop_avail
= bt_message_discarded_packets_get_count(in_message
,
1645 &discarded_packets
);
1646 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1647 bt_message_discarded_packets_set_count(out_message
,
1656 const bt_message
*handle_message(struct debug_info_msg_iter
*debug_it
,
1657 const bt_message
*in_message
)
1659 bt_message
*out_message
= NULL
;
1661 switch (bt_message_get_type(in_message
)) {
1662 case BT_MESSAGE_TYPE_EVENT
:
1663 out_message
= handle_event_message(debug_it
,
1666 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1667 out_message
= handle_packet_begin_message(debug_it
,
1670 case BT_MESSAGE_TYPE_PACKET_END
:
1671 out_message
= handle_packet_end_message(debug_it
,
1674 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1675 out_message
= handle_stream_begin_message(debug_it
,
1678 case BT_MESSAGE_TYPE_STREAM_END
:
1679 out_message
= handle_stream_end_message(debug_it
,
1682 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1683 out_message
= handle_msg_iterator_inactivity(debug_it
,
1686 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
1687 out_message
= handle_stream_act_begin_message(debug_it
,
1690 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
1691 out_message
= handle_stream_act_end_message(debug_it
,
1694 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1695 out_message
= handle_discarded_events_message(debug_it
,
1698 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1699 out_message
= handle_discarded_packets_message(debug_it
,
1711 int init_from_params(struct debug_info_component
*debug_info_component
,
1712 const bt_value
*params
)
1714 const bt_value
*value
= NULL
;
1719 value
= bt_value_map_borrow_entry_value_const(params
,
1720 "debug-info-field-name");
1722 debug_info_component
->arg_debug_info_field_name
=
1723 g_strdup(bt_value_string_get(value
));
1725 debug_info_component
->arg_debug_info_field_name
=
1726 g_strdup(DEFAULT_DEBUG_INFO_FIELD_NAME
);
1729 value
= bt_value_map_borrow_entry_value_const(params
, "debug-info-dir");
1731 debug_info_component
->arg_debug_dir
=
1732 g_strdup(bt_value_string_get(value
));
1734 debug_info_component
->arg_debug_dir
= NULL
;
1738 value
= bt_value_map_borrow_entry_value_const(params
, "target-prefix");
1740 debug_info_component
->arg_target_prefix
=
1741 g_strdup(bt_value_string_get(value
));
1743 debug_info_component
->arg_target_prefix
= NULL
;
1746 value
= bt_value_map_borrow_entry_value_const(params
, "full-path");
1748 debug_info_component
->arg_full_path
= bt_value_bool_get(value
);
1750 debug_info_component
->arg_full_path
= BT_FALSE
;
1757 bt_self_component_status
debug_info_comp_init(
1758 bt_self_component_filter
*self_comp
,
1759 const bt_value
*params
, __attribute__((unused
)) void *init_method_data
)
1762 struct debug_info_component
*debug_info_comp
;
1763 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
1765 BT_LOGI("Initializing debug_info component: "
1766 "comp-addr=%p, params-addr=%p", self_comp
, params
);
1768 debug_info_comp
= g_new0(struct debug_info_component
, 1);
1769 if (!debug_info_comp
) {
1770 BT_LOGE_STR("Failed to allocate one debug_info component.");
1774 bt_self_component_set_data(
1775 bt_self_component_filter_as_self_component(self_comp
),
1778 status
= bt_self_component_filter_add_input_port(self_comp
, "in",
1780 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1784 status
= bt_self_component_filter_add_output_port(self_comp
, "out",
1786 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1790 ret
= init_from_params(debug_info_comp
, params
);
1792 BT_LOGE("Cannot configure debug_info component: "
1793 "debug_info-comp-addr=%p, params-addr=%p",
1794 debug_info_comp
, params
);
1801 destroy_debug_info_comp(debug_info_comp
);
1802 bt_self_component_set_data(
1803 bt_self_component_filter_as_self_component(self_comp
),
1806 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
1807 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1814 void debug_info_comp_finalize(bt_self_component_filter
*self_comp
)
1816 struct debug_info_component
*debug_info
=
1817 bt_self_component_get_data(
1818 bt_self_component_filter_as_self_component(
1820 BT_LOGI("Finalizing debug_info self_component: comp-addr=%p",
1823 destroy_debug_info_comp(debug_info
);
1827 bt_self_message_iterator_status
debug_info_msg_iter_next(
1828 bt_self_message_iterator
*self_msg_iter
,
1829 const bt_message_array_const msgs
, uint64_t capacity
,
1832 bt_self_component_port_input_message_iterator
*upstream_iterator
= NULL
;
1833 bt_message_iterator_status upstream_iterator_ret_status
;
1834 struct debug_info_msg_iter
*debug_info_msg_iter
;
1835 struct debug_info_component
*debug_info
= NULL
;
1836 bt_self_message_iterator_status status
;
1837 bt_self_component
*self_comp
= NULL
;
1838 bt_message_array_const input_msgs
;
1839 const bt_message
*out_message
;
1840 uint64_t curr_msg_idx
, i
;
1842 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1844 self_comp
= bt_self_message_iterator_borrow_component(self_msg_iter
);
1845 BT_ASSERT(self_comp
);
1847 debug_info
= bt_self_component_get_data(self_comp
);
1848 BT_ASSERT(debug_info
);
1850 debug_info_msg_iter
= bt_self_message_iterator_get_data(self_msg_iter
);
1851 BT_ASSERT(debug_info_msg_iter
);
1853 upstream_iterator
= debug_info_msg_iter
->msg_iter
;
1854 BT_ASSERT(upstream_iterator
);
1856 upstream_iterator_ret_status
=
1857 bt_self_component_port_input_message_iterator_next(
1858 upstream_iterator
, &input_msgs
, count
);
1859 if (upstream_iterator_ret_status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1861 * No messages were returned. Not necessarily an error. Convert
1862 * the upstream message iterator status to a self status.
1864 status
= bt_common_message_iterator_status_to_self(
1865 upstream_iterator_ret_status
);
1870 * There should never be more received messages than the capacity we
1873 BT_ASSERT(*count
<= capacity
);
1875 for (curr_msg_idx
= 0; curr_msg_idx
< *count
; curr_msg_idx
++) {
1876 out_message
= handle_message(debug_info_msg_iter
,
1877 input_msgs
[curr_msg_idx
]);
1879 goto handle_msg_error
;
1882 msgs
[curr_msg_idx
] = out_message
;
1884 * Drop our reference of the input message as we are done with
1885 * it and created a output copy.
1887 bt_message_put_ref(input_msgs
[curr_msg_idx
]);
1894 * Drop references of all the output messages created before the
1897 for (i
= 0; i
< curr_msg_idx
; i
++) {
1898 bt_message_put_ref(msgs
[i
]);
1901 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1907 void debug_info_msg_iter_destroy(struct debug_info_msg_iter
*debug_info_msg_iter
)
1909 if (!debug_info_msg_iter
) {
1913 if (debug_info_msg_iter
->msg_iter
) {
1914 bt_self_component_port_input_message_iterator_put_ref(
1915 debug_info_msg_iter
->msg_iter
);
1918 if (debug_info_msg_iter
->ir_maps
) {
1919 trace_ir_maps_destroy(debug_info_msg_iter
->ir_maps
);
1922 if (debug_info_msg_iter
->debug_info_map
) {
1923 g_hash_table_destroy(debug_info_msg_iter
->debug_info_map
);
1926 bt_fd_cache_fini(&debug_info_msg_iter
->fd_cache
);
1927 g_free(debug_info_msg_iter
);
1934 bt_self_message_iterator_status
debug_info_msg_iter_init(
1935 bt_self_message_iterator
*self_msg_iter
,
1936 bt_self_component_filter
*self_comp
,
1937 bt_self_component_port_output
*self_port
)
1939 bt_self_message_iterator_status status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1940 struct bt_self_component_port_input
*input_port
= NULL
;
1941 bt_self_component_port_input_message_iterator
*upstream_iterator
= NULL
;
1942 struct debug_info_msg_iter
*debug_info_msg_iter
= NULL
;
1943 gchar
*debug_info_field_name
;
1946 /* Borrow the upstream input port. */
1947 input_port
= bt_self_component_filter_borrow_input_port_by_name(
1950 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1954 debug_info_msg_iter
= g_new0(struct debug_info_msg_iter
, 1);
1955 if (!debug_info_msg_iter
) {
1956 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1960 /* Create an iterator on the upstream component. */
1961 upstream_iterator
= bt_self_component_port_input_message_iterator_create(
1963 if (!upstream_iterator
) {
1964 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1968 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
1969 debug_info_msg_iter
->msg_iter
, upstream_iterator
);
1971 /* Create hashtable that will contain debug info mapping. */
1972 debug_info_msg_iter
->debug_info_map
= g_hash_table_new_full(
1973 g_direct_hash
, g_direct_equal
, (GDestroyNotify
) NULL
,
1974 (GDestroyNotify
) debug_info_destroy
);
1975 if (!debug_info_msg_iter
->debug_info_map
) {
1976 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1980 debug_info_msg_iter
->self_comp
=
1981 bt_self_component_filter_as_self_component(self_comp
);
1983 debug_info_msg_iter
->debug_info_component
= bt_self_component_get_data(
1984 bt_self_component_filter_as_self_component(
1987 debug_info_field_name
=
1988 debug_info_msg_iter
->debug_info_component
->arg_debug_info_field_name
;
1990 debug_info_msg_iter
->ir_maps
= trace_ir_maps_create(
1991 bt_self_component_filter_as_self_component(self_comp
),
1992 debug_info_field_name
);
1993 if (!debug_info_msg_iter
->ir_maps
) {
1994 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1998 ret
= bt_fd_cache_init(&debug_info_msg_iter
->fd_cache
);
2000 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
2004 bt_self_message_iterator_set_data(self_msg_iter
, debug_info_msg_iter
);
2005 debug_info_msg_iter
->input_iterator
= self_msg_iter
;
2010 debug_info_msg_iter_destroy(debug_info_msg_iter
);
2016 bt_bool
debug_info_msg_iter_can_seek_beginning(
2017 bt_self_message_iterator
*self_msg_iter
)
2019 struct debug_info_msg_iter
*debug_info_msg_iter
=
2020 bt_self_message_iterator_get_data(self_msg_iter
);
2021 BT_ASSERT(debug_info_msg_iter
);
2023 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2024 debug_info_msg_iter
->msg_iter
);
2028 bt_self_message_iterator_status
debug_info_msg_iter_seek_beginning(
2029 bt_self_message_iterator
*self_msg_iter
)
2031 struct debug_info_msg_iter
*debug_info_msg_iter
=
2032 bt_self_message_iterator_get_data(self_msg_iter
);
2033 bt_message_iterator_status status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
2035 BT_ASSERT(debug_info_msg_iter
);
2037 /* Ask the upstream component to seek to the beginning. */
2038 status
= bt_self_component_port_input_message_iterator_seek_beginning(
2039 debug_info_msg_iter
->msg_iter
);
2040 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
2044 /* Clear this iterator data. */
2045 trace_ir_maps_clear(debug_info_msg_iter
->ir_maps
);
2046 g_hash_table_remove_all(debug_info_msg_iter
->debug_info_map
);
2048 return bt_common_message_iterator_status_to_self(status
);
2052 void debug_info_msg_iter_finalize(bt_self_message_iterator
*it
)
2054 struct debug_info_msg_iter
*debug_info_msg_iter
;
2056 debug_info_msg_iter
= bt_self_message_iterator_get_data(it
);
2057 BT_ASSERT(debug_info_msg_iter
);
2059 debug_info_msg_iter_destroy(debug_info_msg_iter
);