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
{
58 char *arg_debug_info_field_name
;
59 const char *arg_debug_dir
;
61 const char *arg_target_prefix
;
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 char *short_src_path
;
87 /* short_bin_path points inside bin_path, no need to free. */
88 const char *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 ctf_proc_debug_infos*); 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 free(debug_info_src
->func
);
155 free(debug_info_src
->line_no
);
156 free(debug_info_src
->src_path
);
157 free(debug_info_src
->bin_path
);
158 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 ret
= asprintf(&debug_info_src
->line_no
, "%"PRId64
, src_loc
->line_no
);
194 BT_LOGD("Error occured when setting line_no field.");
198 if (src_loc
->filename
) {
199 debug_info_src
->src_path
= strdup(src_loc
->filename
);
200 if (!debug_info_src
->src_path
) {
204 debug_info_src
->short_src_path
= get_filename_from_path(
205 debug_info_src
->src_path
);
207 source_location_destroy(src_loc
);
211 debug_info_src
->bin_path
= strdup(bin
->elf_path
);
212 if (!debug_info_src
->bin_path
) {
216 debug_info_src
->short_bin_path
= get_filename_from_path(
217 debug_info_src
->bin_path
);
219 ret
= bin_info_get_bin_loc(bin
, ip
, &(debug_info_src
->bin_loc
));
226 return debug_info_src
;
229 debug_info_source_destroy(debug_info_src
);
234 void proc_debug_info_sources_destroy(
235 struct proc_debug_info_sources
*proc_dbg_info_src
)
237 if (!proc_dbg_info_src
) {
241 if (proc_dbg_info_src
->baddr_to_bin_info
) {
242 g_hash_table_destroy(proc_dbg_info_src
->baddr_to_bin_info
);
245 if (proc_dbg_info_src
->ip_to_debug_info_src
) {
246 g_hash_table_destroy(proc_dbg_info_src
->ip_to_debug_info_src
);
249 g_free(proc_dbg_info_src
);
253 struct proc_debug_info_sources
*proc_debug_info_sources_create(void)
255 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
257 proc_dbg_info_src
= g_new0(struct proc_debug_info_sources
, 1);
258 if (!proc_dbg_info_src
) {
262 proc_dbg_info_src
->baddr_to_bin_info
= g_hash_table_new_full(
263 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
264 (GDestroyNotify
) bin_info_destroy
);
265 if (!proc_dbg_info_src
->baddr_to_bin_info
) {
269 proc_dbg_info_src
->ip_to_debug_info_src
= g_hash_table_new_full(
270 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
271 (GDestroyNotify
) debug_info_source_destroy
);
272 if (!proc_dbg_info_src
->ip_to_debug_info_src
) {
277 return proc_dbg_info_src
;
280 proc_debug_info_sources_destroy(proc_dbg_info_src
);
285 struct proc_debug_info_sources
*proc_debug_info_sources_ht_get_entry(
286 GHashTable
*ht
, int64_t vpid
)
288 gpointer key
= g_new0(int64_t, 1);
289 struct proc_debug_info_sources
*proc_dbg_info_src
= NULL
;
295 *((int64_t *) key
) = vpid
;
297 /* Exists? Return it */
298 proc_dbg_info_src
= g_hash_table_lookup(ht
, key
);
299 if (proc_dbg_info_src
) {
303 /* Otherwise, create and return it */
304 proc_dbg_info_src
= proc_debug_info_sources_create();
305 if (!proc_dbg_info_src
) {
309 g_hash_table_insert(ht
, key
, proc_dbg_info_src
);
310 /* Ownership passed to ht */
314 return proc_dbg_info_src
;
318 const bt_field
*event_borrow_payload_field(const bt_event
*event
,
319 const char *field_name
)
321 const bt_field
*event_payload
, *field
;
323 event_payload
= bt_event_borrow_payload_field_const(event
);
324 BT_ASSERT(event_payload
);
326 field
= bt_field_structure_borrow_member_field_by_name_const(
327 event_payload
, field_name
);
332 const bt_field
*event_borrow_common_context_field(const bt_event
*event
,
333 const char *field_name
)
335 const bt_field
*event_common_ctx
, *field
= NULL
;
337 event_common_ctx
= bt_event_borrow_common_context_field_const(event
);
338 if (!event_common_ctx
) {
342 field
= bt_field_structure_borrow_member_field_by_name_const(
343 event_common_ctx
, field_name
);
350 void event_get_common_context_signed_integer_field_value(
351 const bt_event
*event
, const char *field_name
, int64_t *value
)
353 *value
= bt_field_signed_integer_get_value(
354 event_borrow_common_context_field(event
, field_name
));
358 int event_get_payload_build_id_length(const bt_event
*event
,
359 const char *field_name
, uint64_t *build_id_len
)
361 const bt_field
*build_id_field
;
362 const bt_field_class
*build_id_field_class
;
364 build_id_field
= event_borrow_payload_field(event
, field_name
);
365 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
367 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
368 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
369 BT_ASSERT(bt_field_class_get_type(
370 bt_field_class_array_borrow_element_field_class_const(
371 build_id_field_class
)) ==
372 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
374 *build_id_len
= bt_field_array_get_length(build_id_field
);
380 int event_get_payload_build_id_value(const bt_event
*event
,
381 const char *field_name
, uint8_t *build_id
)
383 const bt_field
*curr_field
, *build_id_field
;
384 const bt_field_class
*build_id_field_class
;
385 uint64_t i
, build_id_len
;
390 build_id_field
= event_borrow_payload_field(event
, field_name
);
391 build_id_field_class
= bt_field_borrow_class_const(build_id_field
);
393 BT_ASSERT(bt_field_class_get_type(build_id_field_class
) ==
394 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
);
395 BT_ASSERT(bt_field_class_get_type(
396 bt_field_class_array_borrow_element_field_class_const(
397 build_id_field_class
)) ==
398 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
400 build_id_len
= bt_field_array_get_length(build_id_field
);
402 for (i
= 0; i
< build_id_len
; i
++) {
404 bt_field_array_borrow_element_field_by_index_const(
407 build_id
[i
] = bt_field_unsigned_integer_get_value(curr_field
);
414 void event_get_payload_unsigned_integer_field_value(const bt_event
*event
,
415 const char *field_name
, uint64_t *value
)
417 *value
= bt_field_unsigned_integer_get_value(
418 event_borrow_payload_field(event
, field_name
));
422 void event_get_payload_string_field_value(const bt_event
*event
,
423 const char *field_name
, const char **value
)
425 *value
= bt_field_string_get_value(
426 event_borrow_payload_field(event
, field_name
));
430 bool event_has_payload_field(const bt_event
*event
,
431 const char *field_name
)
433 return event_borrow_payload_field(event
, field_name
) != NULL
;
437 struct debug_info_source
*proc_debug_info_sources_get_entry(
438 struct proc_debug_info_sources
*proc_dbg_info_src
, uint64_t ip
)
440 struct debug_info_source
*debug_info_src
= NULL
;
441 gpointer key
= g_new0(uint64_t, 1);
443 gpointer baddr
, value
;
449 *((uint64_t *) key
) = ip
;
451 /* Look in IP to debug infos hash table first. */
452 debug_info_src
= g_hash_table_lookup(
453 proc_dbg_info_src
->ip_to_debug_info_src
,
455 if (debug_info_src
) {
459 /* Check in all bin_infos. */
460 g_hash_table_iter_init(&iter
, proc_dbg_info_src
->baddr_to_bin_info
);
462 while (g_hash_table_iter_next(&iter
, &baddr
, &value
))
464 struct bin_info
*bin
= value
;
466 if (!bin_info_has_address(value
, ip
)) {
471 * Found; add it to cache.
473 * FIXME: this should be bounded in size (and implement
474 * a caching policy), and entries should be prunned when
475 * libraries are unmapped.
477 debug_info_src
= debug_info_source_create_from_bin(bin
, ip
);
478 if (debug_info_src
) {
480 proc_dbg_info_src
->ip_to_debug_info_src
,
481 key
, debug_info_src
);
482 /* Ownership passed to ht. */
490 return debug_info_src
;
494 struct debug_info_source
*debug_info_query(struct debug_info
*debug_info
,
495 int64_t vpid
, uint64_t ip
)
497 struct debug_info_source
*dbg_info_src
= NULL
;
498 struct proc_debug_info_sources
*proc_dbg_info_src
;
500 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
501 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
502 if (!proc_dbg_info_src
) {
506 dbg_info_src
= proc_debug_info_sources_get_entry(proc_dbg_info_src
, ip
);
513 struct debug_info
*debug_info_create(struct debug_info_component
*comp
,
514 const bt_trace
*trace
)
517 struct debug_info
*debug_info
;
519 debug_info
= g_new0(struct debug_info
, 1);
524 debug_info
->vpid_to_proc_dbg_info_src
= g_hash_table_new_full(
525 g_int64_hash
, g_int64_equal
, (GDestroyNotify
) g_free
,
526 (GDestroyNotify
) proc_debug_info_sources_destroy
);
527 if (!debug_info
->vpid_to_proc_dbg_info_src
) {
531 debug_info
->comp
= comp
;
532 ret
= debug_info_init(debug_info
);
537 debug_info
->input_trace
= trace
;
547 void debug_info_destroy(struct debug_info
*debug_info
)
549 bt_trace_status status
;
554 if (debug_info
->vpid_to_proc_dbg_info_src
) {
555 g_hash_table_destroy(debug_info
->vpid_to_proc_dbg_info_src
);
558 status
= bt_trace_remove_destruction_listener(debug_info
->input_trace
,
559 debug_info
->destruction_listener_id
);
567 void handle_event_statedump_build_id(struct debug_info
*debug_info
,
568 const bt_event
*event
)
570 struct proc_debug_info_sources
*proc_dbg_info_src
;
571 uint64_t build_id_len
, baddr
;
572 uint8_t *build_id
= NULL
;
573 struct bin_info
*bin
;
577 event_get_common_context_signed_integer_field_value(event
,
578 VPID_FIELD_NAME
, &vpid
);
579 event_get_payload_unsigned_integer_field_value(event
,
580 BADDR_FIELD_NAME
, &baddr
);
582 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
583 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
584 if (!proc_dbg_info_src
) {
588 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
592 * The build_id event comes after the bin has been
593 * created. If it isn't found, just ignore this event.
597 ret
= event_get_payload_build_id_length(event
, BUILD_ID_FIELD_NAME
,
600 build_id
= g_new0(uint8_t, build_id_len
);
605 ret
= event_get_payload_build_id_value(event
, BUILD_ID_FIELD_NAME
,
611 ret
= bin_info_set_build_id(bin
, build_id
, build_id_len
);
617 * Reset the is_elf_only flag in case it had been set
618 * previously, because we might find separate debug info using
619 * the new build id information.
621 bin
->is_elf_only
= false;
629 void handle_event_statedump_debug_link(struct debug_info
*debug_info
,
630 const bt_event
*event
)
632 struct proc_debug_info_sources
*proc_dbg_info_src
;
633 struct bin_info
*bin
= NULL
;
636 const char *filename
= NULL
;
638 uint64_t crc_field_value
;
640 event_get_common_context_signed_integer_field_value(event
,
641 VPID_FIELD_NAME
, &vpid
);
643 event_get_payload_unsigned_integer_field_value(event
,
644 BADDR_FIELD_NAME
, &baddr
);
646 event_get_payload_unsigned_integer_field_value(event
,
647 CRC32_FIELD_NAME
, &crc_field_value
);
649 crc32
= (uint32_t) crc_field_value
;
651 event_get_payload_string_field_value(event
,
652 FILENAME_FIELD_NAME
, &filename
);
654 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
655 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
656 if (!proc_dbg_info_src
) {
660 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
664 * The debug_link event comes after the bin has been
665 * created. If it isn't found, just ignore this event.
670 bin_info_set_debug_link(bin
, filename
, crc32
);
677 void handle_bin_info_event(struct debug_info
*debug_info
,
678 const bt_event
*event
, bool has_pic_field
)
680 struct proc_debug_info_sources
*proc_dbg_info_src
;
681 struct bin_info
*bin
;
682 uint64_t baddr
, memsz
;
688 event_get_payload_unsigned_integer_field_value(event
,
689 MEMSZ_FIELD_NAME
, &memsz
);
695 event_get_payload_unsigned_integer_field_value(event
,
696 BADDR_FIELD_NAME
, &baddr
);
699 * This field is not produced by the dlopen event emitted before
702 if (!event_has_payload_field(event
, PATH_FIELD_NAME
)) {
705 event_get_payload_string_field_value(event
, PATH_FIELD_NAME
, &path
);
708 uint64_t is_pic_field_value
;
710 event_get_payload_unsigned_integer_field_value(event
,
711 IS_PIC_FIELD_NAME
, &is_pic_field_value
);
712 is_pic
= is_pic_field_value
== 1;
715 * dlopen has no is_pic field, because the shared
716 * object is always PIC.
721 event_get_common_context_signed_integer_field_value(event
,
722 VPID_FIELD_NAME
, &vpid
);
724 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
725 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
726 if (!proc_dbg_info_src
) {
730 key
= g_new0(uint64_t, 1);
735 *((uint64_t *) key
) = baddr
;
737 bin
= g_hash_table_lookup(proc_dbg_info_src
->baddr_to_bin_info
,
743 bin
= bin_info_create(path
, baddr
, memsz
, is_pic
,
744 debug_info
->comp
->arg_debug_dir
,
745 debug_info
->comp
->arg_target_prefix
);
750 g_hash_table_insert(proc_dbg_info_src
->baddr_to_bin_info
,
752 /* Ownership passed to ht. */
761 void handle_event_statedump_bin_info(struct debug_info
*debug_info
,
762 const bt_event
*event
)
764 handle_bin_info_event(debug_info
, event
, true);
768 void handle_event_lib_load(struct debug_info
*debug_info
,
769 const bt_event
*event
)
771 handle_bin_info_event(debug_info
, event
, false);
775 void handle_event_lib_unload(struct debug_info
*debug_info
,
776 const bt_event
*event
)
779 struct proc_debug_info_sources
*proc_dbg_info_src
;
783 event_get_payload_unsigned_integer_field_value(event
, BADDR_FIELD_NAME
,
786 event_get_common_context_signed_integer_field_value(event
,
787 VPID_FIELD_NAME
, &vpid
);
789 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
790 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
791 if (!proc_dbg_info_src
) {
793 * It's an unload event for a library for which no load event
794 * was previously received.
799 ret
= g_hash_table_remove(proc_dbg_info_src
->baddr_to_bin_info
,
807 void handle_event_statedump_start(struct debug_info
*debug_info
,
808 const bt_event
*event
)
810 struct proc_debug_info_sources
*proc_dbg_info_src
;
813 event_get_common_context_signed_integer_field_value(
814 event
, VPID_FIELD_NAME
, &vpid
);
816 proc_dbg_info_src
= proc_debug_info_sources_ht_get_entry(
817 debug_info
->vpid_to_proc_dbg_info_src
, vpid
);
818 if (!proc_dbg_info_src
) {
822 g_hash_table_remove_all(proc_dbg_info_src
->baddr_to_bin_info
);
823 g_hash_table_remove_all(proc_dbg_info_src
->ip_to_debug_info_src
);
829 void trace_debug_info_remove_func(const bt_trace
*in_trace
, void *data
)
831 struct debug_info_msg_iter
*debug_it
= data
;
832 if (debug_it
->debug_info_map
) {
834 ret
= g_hash_table_remove(debug_it
->debug_info_map
,
835 (gpointer
) in_trace
);
841 void handle_event_statedump(struct debug_info_msg_iter
*debug_it
,
842 const bt_event
*event
)
844 const bt_event_class
*event_class
;
845 const char *event_name
;
847 const bt_trace
*trace
;
848 struct debug_info
*debug_info
;
853 event_class
= bt_event_borrow_class_const(event
);
855 event_name
= bt_event_class_get_name(event_class
);
857 trace
= bt_stream_borrow_trace_const(
858 bt_event_borrow_stream_const(event
));
860 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
, trace
);
862 debug_info
= debug_info_create(debug_it
->debug_info_component
,
864 g_hash_table_insert(debug_it
->debug_info_map
, (gpointer
) trace
,
866 bt_trace_add_destruction_listener(trace
,
867 trace_debug_info_remove_func
, debug_it
,
868 &debug_info
->destruction_listener_id
);
871 q_event_name
= g_quark_try_string(event_name
);
873 if (q_event_name
== debug_info
->q_statedump_bin_info
) {
875 handle_event_statedump_bin_info(debug_info
, event
);
876 } else if (q_event_name
== debug_info
->q_dl_open
||
877 q_event_name
== debug_info
->q_lib_load
) {
879 * dl_open and lib_load events are both checked for since
880 * only dl_open was produced as of lttng-ust 2.8.
882 * lib_load, which is produced from lttng-ust 2.9+, is a lot
883 * more reliable since it will be emitted when other functions
884 * of the dlopen family are called (e.g. dlmopen) and when
885 * library are transitively loaded.
887 handle_event_lib_load(debug_info
, event
);
888 } else if (q_event_name
== debug_info
->q_statedump_start
) {
889 /* Start state dump */
890 handle_event_statedump_start(debug_info
, event
);
891 } else if (q_event_name
== debug_info
->q_statedump_debug_link
) {
892 /* Debug link info */
893 handle_event_statedump_debug_link(debug_info
, event
);
894 } else if (q_event_name
== debug_info
->q_statedump_build_id
) {
896 handle_event_statedump_build_id(debug_info
, event
);
897 } else if (q_event_name
== debug_info
-> q_lib_unload
) {
898 handle_event_lib_unload(debug_info
, event
);
905 void destroy_debug_info_comp(struct debug_info_component
*debug_info
)
907 free(debug_info
->arg_debug_info_field_name
);
912 void fill_debug_info_bin_field(struct debug_info_source
*dbg_info_src
,
913 bool full_path
, bt_field
*curr_field
)
915 bt_field_status status
;
917 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
918 BT_FIELD_CLASS_TYPE_STRING
);
922 status
= bt_field_string_set_value(curr_field
,
923 dbg_info_src
->bin_path
);
925 status
= bt_field_string_set_value(curr_field
,
926 dbg_info_src
->short_bin_path
);
928 if (status
!= BT_FIELD_STATUS_OK
) {
929 BT_LOGE("Cannot set path component of \"bin\" "
930 "curr_field field's value: str-fc-addr=%p",
934 status
= bt_field_string_append(curr_field
, ":");
935 if (status
!= BT_FIELD_STATUS_OK
) {
936 BT_LOGE("Cannot set colon component of \"bin\" "
937 "curr_field field's value: str-fc-addr=%p",
941 status
= bt_field_string_append(curr_field
, dbg_info_src
->bin_loc
);
942 if (status
!= BT_FIELD_STATUS_OK
) {
943 BT_LOGE("Cannot set bin location component of \"bin\" "
944 "curr_field field's value: str-fc-addr=%p",
948 status
= bt_field_string_set_value(curr_field
, "");
949 if (status
!= BT_FIELD_STATUS_OK
) {
950 BT_LOGE("Cannot set \"bin\" curr_field field's value: "
951 "str-fc-addr=%p", curr_field
);
957 void fill_debug_info_func_field(struct debug_info_source
*dbg_info_src
,
958 bt_field
*curr_field
)
960 bt_field_status status
;
962 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
963 BT_FIELD_CLASS_TYPE_STRING
);
964 if (dbg_info_src
&& dbg_info_src
->func
) {
965 status
= bt_field_string_set_value(curr_field
,
968 status
= bt_field_string_set_value(curr_field
, "");
970 if (status
!= BT_FIELD_STATUS_OK
) {
971 BT_LOGE("Cannot set \"func\" curr_field field's value: "
972 "str-fc-addr=%p", curr_field
);
977 void fill_debug_info_src_field(struct debug_info_source
*dbg_info_src
,
978 bool full_path
, bt_field
*curr_field
)
980 bt_field_status status
;
982 BT_ASSERT(bt_field_get_class_type(curr_field
) ==
983 BT_FIELD_CLASS_TYPE_STRING
);
985 if (dbg_info_src
&& dbg_info_src
->src_path
) {
987 status
= bt_field_string_set_value(curr_field
,
988 dbg_info_src
->src_path
);
990 status
= bt_field_string_set_value(curr_field
,
991 dbg_info_src
->short_src_path
);
993 if (status
!= BT_FIELD_STATUS_OK
) {
994 BT_LOGE("Cannot set path component of \"src\" "
995 "curr_field field's value: str-fc-addr=%p",
999 status
= bt_field_string_append(curr_field
, ":");
1000 if (status
!= BT_FIELD_STATUS_OK
) {
1001 BT_LOGE("Cannot set colon component of \"src\" "
1002 "curr_field field's value: str-fc-addr=%p",
1006 status
= bt_field_string_append(curr_field
, dbg_info_src
->line_no
);
1007 if (status
!= BT_FIELD_STATUS_OK
) {
1008 BT_LOGE("Cannot set line number component of \"src\" "
1009 "curr_field field's value: str-fc-addr=%p",
1013 status
= bt_field_string_set_value(curr_field
, "");
1014 if (status
!= BT_FIELD_STATUS_OK
) {
1015 BT_LOGE("Cannot set \"src\" curr_field field's value: "
1016 "str-fc-addr=%p", curr_field
);
1021 void fill_debug_info_field_empty(bt_field
*debug_info_field
)
1023 bt_field_status status
;
1024 bt_field
*bin_field
, *func_field
, *src_field
;
1026 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1027 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1029 bin_field
= bt_field_structure_borrow_member_field_by_name(
1030 debug_info_field
, "bin");
1031 func_field
= bt_field_structure_borrow_member_field_by_name(
1032 debug_info_field
, "func");
1033 src_field
= bt_field_structure_borrow_member_field_by_name(
1034 debug_info_field
, "src");
1036 BT_ASSERT(bt_field_get_class_type(bin_field
) ==
1037 BT_FIELD_CLASS_TYPE_STRING
);
1038 BT_ASSERT(bt_field_get_class_type(func_field
) ==
1039 BT_FIELD_CLASS_TYPE_STRING
);
1040 BT_ASSERT(bt_field_get_class_type(src_field
) ==
1041 BT_FIELD_CLASS_TYPE_STRING
);
1043 status
= bt_field_string_set_value(bin_field
, "");
1044 if (status
!= BT_FIELD_STATUS_OK
) {
1045 BT_LOGE("Cannot set \"bin\" bin_field field's value: "
1046 "str-fc-addr=%p", bin_field
);
1049 status
= bt_field_string_set_value(func_field
, "");
1050 if (status
!= BT_FIELD_STATUS_OK
) {
1051 BT_LOGE("Cannot set \"func\" func_field field's value: "
1052 "str-fc-addr=%p", func_field
);
1055 status
= bt_field_string_set_value(src_field
, "");
1056 if (status
!= BT_FIELD_STATUS_OK
) {
1057 BT_LOGE("Cannot set \"src\" src_field field's value: "
1058 "str-fc-addr=%p", src_field
);
1062 void fill_debug_info_field(struct debug_info
*debug_info
, int64_t vpid
,
1063 uint64_t ip
, bt_field
*debug_info_field
)
1065 struct debug_info_source
*dbg_info_src
;
1066 const bt_field_class
*debug_info_fc
;
1068 BT_ASSERT(bt_field_get_class_type(debug_info_field
) ==
1069 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1071 debug_info_fc
= bt_field_borrow_class_const(debug_info_field
);
1073 BT_ASSERT(bt_field_class_structure_get_member_count(debug_info_fc
) == 3);
1075 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1077 fill_debug_info_bin_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1078 bt_field_structure_borrow_member_field_by_name(
1079 debug_info_field
, "bin"));
1080 fill_debug_info_func_field(dbg_info_src
,
1081 bt_field_structure_borrow_member_field_by_name(
1082 debug_info_field
, "func"));
1083 fill_debug_info_src_field(dbg_info_src
, debug_info
->comp
->arg_full_path
,
1084 bt_field_structure_borrow_member_field_by_name(
1085 debug_info_field
, "src"));
1089 void fill_debug_info_event_if_needed(struct debug_info_msg_iter
*debug_it
,
1090 const bt_event
*in_event
, bt_event
*out_event
)
1092 bt_field
*out_common_ctx_field
, *out_debug_info_field
;
1093 const bt_field
*vpid_field
, *ip_field
, *in_common_ctx_field
;
1094 const bt_field_class
*in_common_ctx_fc
;
1095 struct debug_info
*debug_info
;
1098 char *debug_info_field_name
=
1099 debug_it
->debug_info_component
->arg_debug_info_field_name
;
1101 in_common_ctx_field
= bt_event_borrow_common_context_field_const(
1103 if (!in_common_ctx_field
) {
1105 * There is no event common context so no need to add debug
1111 in_common_ctx_fc
= bt_field_borrow_class_const(in_common_ctx_field
);
1112 if (!is_event_common_ctx_dbg_info_compatible(in_common_ctx_fc
,
1113 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1115 * The input event common context does not have the necessary
1116 * fields to resolve debug information.
1121 /* Borrow the debug-info field. */
1122 out_common_ctx_field
= bt_event_borrow_common_context_field(out_event
);
1123 if (!out_common_ctx_field
) {
1127 out_debug_info_field
= bt_field_structure_borrow_member_field_by_name(
1128 out_common_ctx_field
, debug_info_field_name
);
1130 vpid_field
= bt_field_structure_borrow_member_field_by_name_const(
1131 out_common_ctx_field
, VPID_FIELD_NAME
);
1132 ip_field
= bt_field_structure_borrow_member_field_by_name_const(
1133 out_common_ctx_field
, IP_FIELD_NAME
);
1135 vpid
= bt_field_signed_integer_get_value(vpid_field
);
1136 ip
= bt_field_unsigned_integer_get_value(ip_field
);
1139 * Borrow the debug_info structure needed for the source
1142 debug_info
= g_hash_table_lookup(debug_it
->debug_info_map
,
1143 bt_stream_borrow_trace_const(
1144 bt_event_borrow_stream_const(in_event
)));
1148 * Perform the debug-info resolving and set the event fields
1151 fill_debug_info_field(debug_info
, vpid
, ip
, out_debug_info_field
);
1153 BT_LOGD("No debug information for this trace. Setting debug "
1154 "info fields to empty strings.");
1155 fill_debug_info_field_empty(out_debug_info_field
);
1162 void update_event_statedump_if_needed(struct debug_info_msg_iter
*debug_it
,
1163 const bt_event
*in_event
)
1165 const bt_field
*event_common_ctx
;
1166 const bt_field_class
*event_common_ctx_fc
;
1167 const bt_event_class
*in_event_class
= bt_event_borrow_class_const(in_event
);
1170 * If the event is an lttng_ust_statedump event AND has the right event
1171 * common context fields update the debug-info view for this process.
1173 event_common_ctx
= bt_event_borrow_common_context_field_const(in_event
);
1174 if (!event_common_ctx
) {
1178 event_common_ctx_fc
= bt_field_borrow_class_const(event_common_ctx
);
1179 if (is_event_common_ctx_dbg_info_compatible(event_common_ctx_fc
,
1180 debug_it
->ir_maps
->debug_info_field_class_name
)) {
1181 /* Checkout if it might be a one of lttng ust statedump events. */
1182 const char *in_event_name
= bt_event_class_get_name(in_event_class
);
1183 if (strncmp(in_event_name
, LTTNG_UST_STATEDUMP_PREFIX
,
1184 strlen(LTTNG_UST_STATEDUMP_PREFIX
)) == 0) {
1185 /* Handle statedump events. */
1186 handle_event_statedump(debug_it
, in_event
);
1194 bt_message
*handle_event_message(struct debug_info_msg_iter
*debug_it
,
1195 const bt_message
*in_message
)
1197 const bt_clock_snapshot
*cs
;
1198 const bt_clock_class
*default_cc
;
1199 const bt_packet
*in_packet
;
1200 bt_clock_snapshot_state cs_state
;
1201 bt_event_class
*out_event_class
;
1202 bt_packet
*out_packet
;
1203 bt_event
*out_event
;
1205 bt_message
*out_message
= NULL
;
1207 /* Borrow the input event and its event class. */
1208 const bt_event
*in_event
=
1209 bt_message_event_borrow_event_const(in_message
);
1210 const bt_event_class
*in_event_class
=
1211 bt_event_borrow_class_const(in_event
);
1213 update_event_statedump_if_needed(debug_it
, in_event
);
1215 out_event_class
= trace_ir_mapping_borrow_mapped_event_class(
1216 debug_it
->ir_maps
, in_event_class
);
1217 if (!out_event_class
) {
1218 out_event_class
= trace_ir_mapping_create_new_mapped_event_class(
1219 debug_it
->ir_maps
, in_event_class
);
1221 BT_ASSERT(out_event_class
);
1223 /* Borrow the input and output packets. */
1224 in_packet
= bt_event_borrow_packet_const(in_event
);
1225 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
,
1228 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1229 bt_event_class_borrow_stream_class_const(in_event_class
));
1231 /* Borrow event clock snapshot. */
1233 bt_message_event_borrow_default_clock_snapshot_const(
1236 /* Create an output event message. */
1237 BT_ASSERT (cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1238 out_message
= bt_message_event_create_with_default_clock_snapshot(
1239 debug_it
->input_iterator
,
1240 out_event_class
, out_packet
,
1241 bt_clock_snapshot_get_value(cs
));
1243 out_message
= bt_message_event_create(debug_it
->input_iterator
,
1244 out_event_class
, out_packet
);
1248 BT_LOGE("Error creating output event message.");
1252 out_event
= bt_message_event_borrow_event(out_message
);
1254 /* Copy the original fields to the output event. */
1255 copy_event_content(in_event
, out_event
);
1258 * Try to set the debug-info fields based on debug information that is
1261 fill_debug_info_event_if_needed(debug_it
, in_event
, out_event
);
1268 bt_message
*handle_stream_begin_message(struct debug_info_msg_iter
*debug_it
,
1269 const bt_message
*in_message
)
1271 const bt_stream
*in_stream
;
1272 bt_message
*out_message
;
1273 bt_stream
*out_stream
;
1275 in_stream
= bt_message_stream_beginning_borrow_stream_const(in_message
);
1276 BT_ASSERT(in_stream
);
1278 /* Create a duplicated output stream. */
1279 out_stream
= trace_ir_mapping_create_new_mapped_stream(
1280 debug_it
->ir_maps
, in_stream
);
1286 /* Create an output stream beginning message. */
1287 out_message
= bt_message_stream_beginning_create(
1288 debug_it
->input_iterator
, out_stream
);
1290 BT_LOGE("Error creating output stream beginning message: "
1291 "out-s-addr=%p", out_stream
);
1298 bt_message
*handle_stream_end_message(struct debug_info_msg_iter
*debug_it
,
1299 const bt_message
*in_message
)
1301 const bt_stream
*in_stream
;
1302 bt_message
*out_message
= NULL
;
1303 bt_stream
*out_stream
;
1305 in_stream
= bt_message_stream_end_borrow_stream_const(in_message
);
1306 BT_ASSERT(in_stream
);
1308 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1309 debug_it
->ir_maps
, in_stream
);
1310 BT_ASSERT(out_stream
);
1312 /* Create an output stream end message. */
1313 out_message
= bt_message_stream_end_create(debug_it
->input_iterator
,
1316 BT_LOGE("Error creating output stream end message: out-s-addr=%p",
1320 /* Remove stream from trace mapping hashtable. */
1321 trace_ir_mapping_remove_mapped_stream(debug_it
->ir_maps
, in_stream
);
1327 bt_message
*handle_packet_begin_message(struct debug_info_msg_iter
*debug_it
,
1328 const bt_message
*in_message
)
1330 const bt_clock_class
*default_cc
;
1331 bt_clock_snapshot_state cs_state
;
1332 const bt_clock_snapshot
*cs
;
1333 bt_message
*out_message
= NULL
;
1334 bt_packet
*out_packet
;
1336 const bt_packet
*in_packet
=
1337 bt_message_packet_beginning_borrow_packet_const(in_message
);
1338 BT_ASSERT(in_packet
);
1340 /* This packet should not be already mapped. */
1341 BT_ASSERT(!trace_ir_mapping_borrow_mapped_packet(
1342 debug_it
->ir_maps
, in_packet
));
1344 out_packet
= trace_ir_mapping_create_new_mapped_packet(debug_it
->ir_maps
,
1347 BT_ASSERT(out_packet
);
1349 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1350 bt_stream_borrow_class_const(
1351 bt_packet_borrow_stream_const(in_packet
)));
1353 /* Borrow clock snapshot. */
1355 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
1358 /* Create an output packet beginning message. */
1359 BT_ASSERT(cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1360 out_message
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1361 debug_it
->input_iterator
, out_packet
,
1362 bt_clock_snapshot_get_value(cs
));
1364 out_message
= bt_message_packet_beginning_create(
1365 debug_it
->input_iterator
, out_packet
);
1368 BT_LOGE("Error creating output packet beginning message: "
1369 "out-p-addr=%p", out_packet
);
1376 bt_message
*handle_packet_end_message(struct debug_info_msg_iter
*debug_it
,
1377 const bt_message
*in_message
)
1379 const bt_clock_snapshot
*cs
;
1380 const bt_packet
*in_packet
;
1381 const bt_clock_class
*default_cc
;
1382 bt_clock_snapshot_state cs_state
;
1383 bt_message
*out_message
= NULL
;
1384 bt_packet
*out_packet
;
1386 in_packet
= bt_message_packet_end_borrow_packet_const(in_message
);
1387 BT_ASSERT(in_packet
);
1389 out_packet
= trace_ir_mapping_borrow_mapped_packet(debug_it
->ir_maps
, in_packet
);
1390 BT_ASSERT(out_packet
);
1392 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1393 bt_stream_borrow_class_const(
1394 bt_packet_borrow_stream_const(in_packet
)));
1396 /* Borrow clock snapshot. */
1398 bt_message_packet_end_borrow_default_clock_snapshot_const(
1401 /* Create an outpute packet end message. */
1402 BT_ASSERT(cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1403 out_message
= bt_message_packet_end_create_with_default_clock_snapshot(
1404 debug_it
->input_iterator
, out_packet
,
1405 bt_clock_snapshot_get_value(cs
));
1407 out_message
= bt_message_packet_end_create(
1408 debug_it
->input_iterator
, out_packet
);
1412 BT_LOGE("Error creating output packet end message: "
1413 "out-p-addr=%p", out_packet
);
1416 /* Remove packet from data mapping hashtable. */
1417 trace_ir_mapping_remove_mapped_packet(debug_it
->ir_maps
, in_packet
);
1423 bt_message
*handle_msg_iterator_inactivity(struct debug_info_msg_iter
*debug_it
,
1424 const bt_message
*in_message
)
1427 * This message type can be forwarded directly because it does
1428 * not refer to any objects in the trace class.
1430 bt_message_get_ref(in_message
);
1431 return (bt_message
*) in_message
;
1435 bt_message
*handle_stream_act_begin_message(struct debug_info_msg_iter
*debug_it
,
1436 const bt_message
*in_message
)
1438 const bt_clock_snapshot
*cs
;
1439 const bt_clock_class
*default_cc
;
1440 bt_message
*out_message
= NULL
;
1441 bt_stream
*out_stream
;
1443 bt_message_stream_activity_clock_snapshot_state cs_state
;
1445 const bt_stream
*in_stream
=
1446 bt_message_stream_activity_beginning_borrow_stream_const(
1448 BT_ASSERT(in_stream
);
1450 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
,
1452 BT_ASSERT(out_stream
);
1454 out_message
= bt_message_stream_activity_beginning_create(
1455 debug_it
->input_iterator
, out_stream
);
1457 BT_LOGE("Error creating output stream activity beginning "
1458 "message: out-s-addr=%p", out_stream
);
1462 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1463 bt_stream_borrow_class_const(in_stream
));
1465 /* Borrow clock snapshot. */
1467 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
1470 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1471 cs_value
= bt_clock_snapshot_get_value(cs
);
1472 bt_message_stream_activity_beginning_set_default_clock_snapshot(
1473 out_message
, cs_value
);
1475 bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
1476 out_message
, cs_state
);
1485 bt_message
*handle_stream_act_end_message(struct debug_info_msg_iter
*debug_it
,
1486 const bt_message
*in_message
)
1488 const bt_clock_snapshot
*cs
;
1489 const bt_clock_class
*default_cc
;
1490 const bt_stream
*in_stream
;
1491 bt_message
*out_message
;
1492 bt_stream
*out_stream
;
1494 bt_message_stream_activity_clock_snapshot_state cs_state
;
1496 in_stream
= bt_message_stream_activity_end_borrow_stream_const(
1498 BT_ASSERT(in_stream
);
1500 out_stream
= trace_ir_mapping_borrow_mapped_stream(debug_it
->ir_maps
, in_stream
);
1501 BT_ASSERT(out_stream
);
1503 out_message
= bt_message_stream_activity_end_create(
1504 debug_it
->input_iterator
, out_stream
);
1506 BT_LOGE("Error creating output stream activity end message: "
1507 "out-s-addr=%p", out_stream
);
1511 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1512 bt_stream_borrow_class_const(in_stream
));
1516 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
1519 if (cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1520 cs_value
= bt_clock_snapshot_get_value(cs
);
1521 bt_message_stream_activity_end_set_default_clock_snapshot(
1522 out_message
, cs_value
);
1524 bt_message_stream_activity_end_set_default_clock_snapshot_state(
1525 out_message
, cs_state
);
1534 bt_message
*handle_discarded_events_message(struct debug_info_msg_iter
*debug_it
,
1535 const bt_message
*in_message
)
1537 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1538 const bt_stream
*in_stream
;
1539 const bt_clock_class
*default_cc
;
1540 uint64_t discarded_events
, begin_cs_value
, end_cs_value
;
1541 bt_clock_snapshot_state begin_cs_state
, end_cs_state
;
1542 bt_property_availability prop_avail
;
1543 bt_message
*out_message
= NULL
;
1544 bt_stream
*out_stream
;
1546 in_stream
= bt_message_discarded_events_borrow_stream_const(
1548 BT_ASSERT(in_stream
);
1550 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1551 debug_it
->ir_maps
, in_stream
);
1552 BT_ASSERT(out_stream
);
1554 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1555 bt_stream_borrow_class_const(in_stream
));
1558 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
1559 in_message
, &begin_cs
);
1561 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
1562 in_message
, &end_cs
);
1564 * Both clock snapshots should be known as we check that the
1565 * all input stream classes have an always known clock. Unknown
1566 * clock is not yet supported.
1568 BT_ASSERT(begin_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
&&
1569 end_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1571 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1572 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1575 bt_message_discarded_events_create_with_default_clock_snapshots(
1576 debug_it
->input_iterator
, out_stream
,
1577 begin_cs_value
, end_cs_value
);
1579 out_message
= bt_message_discarded_events_create(
1580 debug_it
->input_iterator
, out_stream
);
1583 BT_LOGE("Error creating output discarded events message: "
1584 "out-s-addr=%p", out_stream
);
1588 prop_avail
= bt_message_discarded_events_get_count(in_message
,
1591 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1592 bt_message_discarded_events_set_count(out_message
,
1601 bt_message
*handle_discarded_packets_message(struct debug_info_msg_iter
*debug_it
,
1602 const bt_message
*in_message
)
1604 const bt_clock_snapshot
*begin_cs
, *end_cs
;
1605 const bt_clock_class
*default_cc
;
1606 const bt_stream
*in_stream
;
1607 uint64_t discarded_packets
, begin_cs_value
, end_cs_value
;
1608 bt_clock_snapshot_state begin_cs_state
, end_cs_state
;
1609 bt_property_availability prop_avail
;
1610 bt_message
*out_message
= NULL
;
1611 bt_stream
*out_stream
;
1613 in_stream
= bt_message_discarded_packets_borrow_stream_const(
1615 BT_ASSERT(in_stream
);
1617 out_stream
= trace_ir_mapping_borrow_mapped_stream(
1618 debug_it
->ir_maps
, in_stream
);
1619 BT_ASSERT(out_stream
);
1621 default_cc
= bt_stream_class_borrow_default_clock_class_const(
1622 bt_stream_borrow_class_const(in_stream
));
1625 bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
1626 in_message
, &begin_cs
);
1629 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
1630 in_message
, &end_cs
);
1633 * Both clock snapshots should be known as we check that the
1634 * all input stream classes have an always known clock. Unknown
1635 * clock is not yet supported.
1637 BT_ASSERT(begin_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
&&
1638 end_cs_state
== BT_CLOCK_SNAPSHOT_STATE_KNOWN
);
1640 begin_cs_value
= bt_clock_snapshot_get_value(begin_cs
);
1641 end_cs_value
= bt_clock_snapshot_get_value(end_cs
);
1643 out_message
= bt_message_discarded_packets_create_with_default_clock_snapshots(
1644 debug_it
->input_iterator
, out_stream
,
1645 begin_cs_value
, end_cs_value
);
1647 out_message
= bt_message_discarded_packets_create(
1648 debug_it
->input_iterator
, out_stream
);
1651 BT_LOGE("Error creating output discarded packet message: "
1652 "out-s-addr=%p", out_stream
);
1656 prop_avail
= bt_message_discarded_packets_get_count(in_message
,
1657 &discarded_packets
);
1658 if (prop_avail
== BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
) {
1659 bt_message_discarded_packets_set_count(out_message
,
1668 const bt_message
*handle_message(struct debug_info_msg_iter
*debug_it
,
1669 const bt_message
*in_message
)
1671 bt_message
*out_message
= NULL
;
1673 switch (bt_message_get_type(in_message
)) {
1674 case BT_MESSAGE_TYPE_EVENT
:
1675 out_message
= handle_event_message(debug_it
,
1678 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1679 out_message
= handle_packet_begin_message(debug_it
,
1682 case BT_MESSAGE_TYPE_PACKET_END
:
1683 out_message
= handle_packet_end_message(debug_it
,
1686 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1687 out_message
= handle_stream_begin_message(debug_it
,
1690 case BT_MESSAGE_TYPE_STREAM_END
:
1691 out_message
= handle_stream_end_message(debug_it
,
1694 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1695 out_message
= handle_msg_iterator_inactivity(debug_it
,
1698 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
1699 out_message
= handle_stream_act_begin_message(debug_it
,
1702 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
1703 out_message
= handle_stream_act_end_message(debug_it
,
1706 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1707 out_message
= handle_discarded_events_message(debug_it
,
1710 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1711 out_message
= handle_discarded_packets_message(debug_it
,
1723 int init_from_params(struct debug_info_component
*debug_info_component
,
1724 const bt_value
*params
)
1726 const bt_value
*value
= NULL
;
1731 value
= bt_value_map_borrow_entry_value_const(params
,
1732 "debug-info-field-name");
1734 const char *debug_info_field_name
;
1736 debug_info_field_name
= bt_value_string_get(value
);
1737 debug_info_component
->arg_debug_info_field_name
=
1738 strdup(debug_info_field_name
);
1740 debug_info_component
->arg_debug_info_field_name
=
1741 malloc(strlen(DEFAULT_DEBUG_INFO_FIELD_NAME
) + 1);
1742 if (!debug_info_component
->arg_debug_info_field_name
) {
1743 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;
1744 BT_LOGE_STR("Missing field name.");
1747 sprintf(debug_info_component
->arg_debug_info_field_name
,
1748 DEFAULT_DEBUG_INFO_FIELD_NAME
);
1754 value
= bt_value_map_borrow_entry_value_const(params
, "debug-info-dir");
1756 debug_info_component
->arg_debug_dir
= bt_value_string_get(value
);
1759 value
= bt_value_map_borrow_entry_value_const(params
, "target-prefix");
1761 debug_info_component
->arg_target_prefix
=
1762 bt_value_string_get(value
);
1765 value
= bt_value_map_borrow_entry_value_const(params
, "full-path");
1767 debug_info_component
->arg_full_path
= bt_value_bool_get(value
);
1775 bt_self_component_status
debug_info_comp_init(
1776 bt_self_component_filter
*self_comp
,
1777 const bt_value
*params
, UNUSED_VAR
void *init_method_data
)
1780 struct debug_info_component
*debug_info_comp
;
1781 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
1783 BT_LOGD("Initializing debug_info component: "
1784 "comp-addr=%p, params-addr=%p", self_comp
, params
);
1786 debug_info_comp
= g_new0(struct debug_info_component
, 1);
1787 if (!debug_info_comp
) {
1788 BT_LOGE_STR("Failed to allocate one debug_info component.");
1792 bt_self_component_set_data(
1793 bt_self_component_filter_as_self_component(self_comp
),
1796 status
= bt_self_component_filter_add_input_port(self_comp
, "in",
1798 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1802 status
= bt_self_component_filter_add_output_port(self_comp
, "out",
1804 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
1808 ret
= init_from_params(debug_info_comp
, params
);
1810 BT_LOGE("Cannot configure debug_info component: "
1811 "debug_info-comp-addr=%p, params-addr=%p",
1812 debug_info_comp
, params
);
1819 destroy_debug_info_comp(debug_info_comp
);
1820 bt_self_component_set_data(
1821 bt_self_component_filter_as_self_component(self_comp
),
1824 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
1825 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1832 void debug_info_comp_finalize(bt_self_component_filter
*self_comp
)
1834 struct debug_info_component
*debug_info
=
1835 bt_self_component_get_data(
1836 bt_self_component_filter_as_self_component(
1838 BT_LOGD("Finalizing debug_info self_component: comp-addr=%p",
1841 destroy_debug_info_comp(debug_info
);
1845 bt_self_message_iterator_status
debug_info_msg_iter_next(
1846 bt_self_message_iterator
*self_msg_iter
,
1847 const bt_message_array_const msgs
, uint64_t capacity
,
1850 bt_self_component_port_input_message_iterator
*upstream_iterator
= NULL
;
1851 bt_message_iterator_status upstream_iterator_ret_status
;
1852 struct debug_info_msg_iter
*debug_info_msg_iter
;
1853 struct debug_info_component
*debug_info
= NULL
;
1854 bt_self_message_iterator_status status
;
1855 bt_self_component
*self_comp
= NULL
;
1856 bt_message_array_const input_msgs
;
1857 const bt_message
*out_message
;
1858 uint64_t curr_msg_idx
, i
;
1860 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1862 self_comp
= bt_self_message_iterator_borrow_component(self_msg_iter
);
1863 BT_ASSERT(self_comp
);
1865 debug_info
= bt_self_component_get_data(self_comp
);
1866 BT_ASSERT(debug_info
);
1868 debug_info_msg_iter
= bt_self_message_iterator_get_data(self_msg_iter
);
1869 BT_ASSERT(debug_info_msg_iter
);
1871 upstream_iterator
= debug_info_msg_iter
->msg_iter
;
1872 BT_ASSERT(upstream_iterator
);
1874 upstream_iterator_ret_status
=
1875 bt_self_component_port_input_message_iterator_next(
1876 upstream_iterator
, &input_msgs
, count
);
1877 if (upstream_iterator_ret_status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1879 * No messages were returned. Not necessarily an error. Convert
1880 * the upstream message iterator status to a self status.
1882 status
= bt_common_message_iterator_status_to_self(
1883 upstream_iterator_ret_status
);
1888 * There should never be more received messages than the capacity we
1891 BT_ASSERT(*count
<= capacity
);
1893 for (curr_msg_idx
= 0; curr_msg_idx
< *count
; curr_msg_idx
++) {
1894 out_message
= handle_message(debug_info_msg_iter
,
1895 input_msgs
[curr_msg_idx
]);
1897 goto handle_msg_error
;
1900 msgs
[curr_msg_idx
] = out_message
;
1902 * Drop our reference of the input message as we are done with
1903 * it and created a output copy.
1905 bt_message_put_ref(input_msgs
[curr_msg_idx
]);
1912 * Drop references of all the output messages created before the
1915 for (i
= 0; i
< curr_msg_idx
; i
++) {
1916 bt_message_put_ref(msgs
[i
]);
1919 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1925 bt_self_message_iterator_status
debug_info_msg_iter_init(
1926 bt_self_message_iterator
*self_msg_iter
,
1927 bt_self_component_filter
*self_comp
,
1928 bt_self_component_port_output
*self_port
)
1930 bt_self_message_iterator_status status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1931 struct bt_self_component_port_input
*input_port
;
1932 bt_self_component_port_input_message_iterator
*upstream_iterator
;
1933 struct debug_info_msg_iter
*debug_info_msg_iter
;
1935 /* Borrow the upstream input port. */
1936 input_port
= bt_self_component_filter_borrow_input_port_by_name(
1939 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1943 /* Create an iterator on the upstream component. */
1944 upstream_iterator
= bt_self_component_port_input_message_iterator_create(
1946 if (!upstream_iterator
) {
1947 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1951 debug_info_msg_iter
= g_new0(struct debug_info_msg_iter
, 1);
1952 if (!debug_info_msg_iter
) {
1953 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1957 debug_info_msg_iter
->debug_info_map
= g_hash_table_new_full(
1958 g_direct_hash
, g_direct_equal
,
1959 (GDestroyNotify
) NULL
,
1960 (GDestroyNotify
) debug_info_destroy
);
1961 if (!debug_info_msg_iter
->debug_info_map
) {
1962 g_free(debug_info_msg_iter
);
1963 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1967 debug_info_msg_iter
->self_comp
=
1968 bt_self_component_filter_as_self_component(self_comp
);
1970 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
1971 debug_info_msg_iter
->msg_iter
, upstream_iterator
);
1973 debug_info_msg_iter
->debug_info_component
= bt_self_component_get_data(
1974 bt_self_component_filter_as_self_component(
1977 debug_info_msg_iter
->ir_maps
= trace_ir_maps_create(
1978 bt_self_component_filter_as_self_component(self_comp
),
1979 debug_info_msg_iter
->debug_info_component
->arg_debug_info_field_name
);
1980 if (!debug_info_msg_iter
->ir_maps
) {
1981 g_hash_table_destroy(debug_info_msg_iter
->debug_info_map
);
1982 g_free(debug_info_msg_iter
);
1983 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM
;
1987 bt_self_message_iterator_set_data(self_msg_iter
, debug_info_msg_iter
);
1989 debug_info_msg_iter
->input_iterator
= self_msg_iter
;
1996 bt_bool
debug_info_msg_iter_can_seek_beginning(
1997 bt_self_message_iterator
*self_msg_iter
)
1999 struct debug_info_msg_iter
*debug_info_msg_iter
=
2000 bt_self_message_iterator_get_data(self_msg_iter
);
2001 BT_ASSERT(debug_info_msg_iter
);
2003 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2004 debug_info_msg_iter
->msg_iter
);
2008 bt_self_message_iterator_status
debug_info_msg_iter_seek_beginning(
2009 bt_self_message_iterator
*self_msg_iter
)
2011 struct debug_info_msg_iter
*debug_info_msg_iter
=
2012 bt_self_message_iterator_get_data(self_msg_iter
);
2013 bt_message_iterator_status status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
2015 BT_ASSERT(debug_info_msg_iter
);
2017 /* Ask the upstream component to seek to the beginning. */
2018 status
= bt_self_component_port_input_message_iterator_seek_beginning(
2019 debug_info_msg_iter
->msg_iter
);
2020 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
2024 /* Clear this iterator data. */
2025 trace_ir_maps_clear(debug_info_msg_iter
->ir_maps
);
2026 g_hash_table_remove_all(debug_info_msg_iter
->debug_info_map
);
2028 return bt_common_message_iterator_status_to_self(status
);
2032 void debug_info_msg_iter_finalize(bt_self_message_iterator
*it
)
2034 struct debug_info_msg_iter
*debug_info_msg_iter
;
2036 debug_info_msg_iter
= bt_self_message_iterator_get_data(it
);
2037 BT_ASSERT(debug_info_msg_iter
);
2039 bt_self_component_port_input_message_iterator_put_ref(
2040 debug_info_msg_iter
->msg_iter
);
2042 trace_ir_maps_destroy(debug_info_msg_iter
->ir_maps
);
2043 g_hash_table_destroy(debug_info_msg_iter
->debug_info_map
);
2045 g_free(debug_info_msg_iter
);