lib: mark graph as faulty when adding a comp. or connecting ports fails
[babeltrace.git] / plugins / lttng-utils / debug-info.c
CommitLineData
4f45f9bb
JD
1/*
2 * Babeltrace - Debug Information State Tracker
3 *
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>
ca9f27f3 8 * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
4f45f9bb
JD
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
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
26 * SOFTWARE.
27 */
28
b4565e8b
PP
29#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-UTILS-DEBUG-INFO-FLT"
30#include "logging.h"
31
4f45f9bb 32#include <glib.h>
ca9f27f3
FD
33#include <plugins-common.h>
34
35#include <babeltrace/assert-internal.h>
36#include <babeltrace/common-internal.h>
37
4f45f9bb 38#include "bin-info.h"
ca9f27f3
FD
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"
4f45f9bb 43#include "utils.h"
ca9f27f3
FD
44
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"
56
57struct debug_info_component {
58 char *arg_debug_info_field_name;
59 const char *arg_debug_dir;
60 bool arg_full_path;
61 const char *arg_target_prefix;
62};
63
64struct 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;
69
70 struct trace_ir_maps *ir_maps;
71 /* in_trace -> debug_info_mapping. */
72 GHashTable *debug_info_map;
73};
74
75struct debug_info_source {
76 /* Strings are owned by debug_info_source. */
77 char *func;
78 /*
79 * Store the line number as a string so that the allocation and
80 * conversion to string is only done once.
81 */
82 char *line_no;
83 char *src_path;
84 /* short_src_path points inside src_path, no need to free. */
85 const char *short_src_path;
86 char *bin_path;
87 /* short_bin_path points inside bin_path, no need to free. */
88 const char *short_bin_path;
89 /*
90 * Location within the binary. Either absolute (@0x1234) or
91 * relative (+0x4321).
92 */
93 char *bin_loc;
94};
4f45f9bb
JD
95
96struct proc_debug_info_sources {
97 /*
98 * Hash table: base address (pointer to uint64_t) to bin info; owned by
99 * proc_debug_info_sources.
100 */
101 GHashTable *baddr_to_bin_info;
102
103 /*
104 * Hash table: IP (pointer to uint64_t) to (struct debug_info_source *);
105 * owned by proc_debug_info_sources.
106 */
107 GHashTable *ip_to_debug_info_src;
108};
109
110struct debug_info {
9d325e17 111 struct debug_info_component *comp;
ca9f27f3
FD
112 const bt_trace *input_trace;
113 uint64_t destruction_listener_id;
9d325e17 114
4f45f9bb
JD
115 /*
116 * Hash table of VPIDs (pointer to int64_t) to
117 * (struct ctf_proc_debug_infos*); owned by debug_info.
118 */
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;
124 GQuark q_dl_open;
125 GQuark q_lib_load;
126 GQuark q_lib_unload;
127};
128
129static
130int debug_info_init(struct debug_info *info)
131{
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(
ca9f27f3 135 "lttng_ust_statedump:debug_link");
4f45f9bb
JD
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");
143
144 return bin_info_init();
145}
146
147static
148void debug_info_source_destroy(struct debug_info_source *debug_info_src)
149{
150 if (!debug_info_src) {
151 return;
152 }
153
154 free(debug_info_src->func);
ca9f27f3 155 free(debug_info_src->line_no);
4f45f9bb
JD
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);
160}
161
162static
ca9f27f3
FD
163struct debug_info_source *debug_info_source_create_from_bin(
164 struct bin_info *bin, uint64_t ip)
4f45f9bb
JD
165{
166 int ret;
167 struct debug_info_source *debug_info_src = NULL;
168 struct source_location *src_loc = NULL;
169
170 debug_info_src = g_new0(struct debug_info_source, 1);
171
172 if (!debug_info_src) {
173 goto end;
174 }
175
176 /* Lookup function name */
177 ret = bin_info_lookup_function_name(bin, ip, &debug_info_src->func);
178 if (ret) {
179 goto error;
180 }
181
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);
ca9f27f3
FD
186 if (ret) {
187 BT_LOGD("Failed to lookup source location: ret=%d", ret);
188 }
4f45f9bb
JD
189 }
190
191 if (src_loc) {
ca9f27f3
FD
192 ret = asprintf(&debug_info_src->line_no, "%"PRId64, src_loc->line_no);
193 if (ret == -1) {
194 BT_LOGD("Error occured when setting line_no field.");
195 goto error;
196 }
4f45f9bb
JD
197
198 if (src_loc->filename) {
199 debug_info_src->src_path = strdup(src_loc->filename);
200 if (!debug_info_src->src_path) {
201 goto error;
202 }
203
204 debug_info_src->short_src_path = get_filename_from_path(
205 debug_info_src->src_path);
206 }
4f45f9bb
JD
207 source_location_destroy(src_loc);
208 }
209
210 if (bin->elf_path) {
211 debug_info_src->bin_path = strdup(bin->elf_path);
212 if (!debug_info_src->bin_path) {
213 goto error;
214 }
215
216 debug_info_src->short_bin_path = get_filename_from_path(
217 debug_info_src->bin_path);
218
219 ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc));
220 if (ret) {
221 goto error;
222 }
223 }
224
225end:
226 return debug_info_src;
227
228error:
229 debug_info_source_destroy(debug_info_src);
230 return NULL;
231}
232
233static
234void proc_debug_info_sources_destroy(
235 struct proc_debug_info_sources *proc_dbg_info_src)
236{
237 if (!proc_dbg_info_src) {
238 return;
239 }
240
241 if (proc_dbg_info_src->baddr_to_bin_info) {
242 g_hash_table_destroy(proc_dbg_info_src->baddr_to_bin_info);
243 }
244
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);
247 }
248
249 g_free(proc_dbg_info_src);
250}
251
252static
253struct proc_debug_info_sources *proc_debug_info_sources_create(void)
254{
255 struct proc_debug_info_sources *proc_dbg_info_src = NULL;
256
257 proc_dbg_info_src = g_new0(struct proc_debug_info_sources, 1);
258 if (!proc_dbg_info_src) {
259 goto end;
260 }
261
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) {
266 goto error;
267 }
268
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) {
273 goto error;
274 }
275
276end:
277 return proc_dbg_info_src;
278
279error:
280 proc_debug_info_sources_destroy(proc_dbg_info_src);
281 return NULL;
282}
283
284static
285struct proc_debug_info_sources *proc_debug_info_sources_ht_get_entry(
286 GHashTable *ht, int64_t vpid)
287{
288 gpointer key = g_new0(int64_t, 1);
289 struct proc_debug_info_sources *proc_dbg_info_src = NULL;
290
291 if (!key) {
292 goto end;
293 }
294
295 *((int64_t *) key) = vpid;
296
297 /* Exists? Return it */
298 proc_dbg_info_src = g_hash_table_lookup(ht, key);
299 if (proc_dbg_info_src) {
300 goto end;
301 }
302
303 /* Otherwise, create and return it */
304 proc_dbg_info_src = proc_debug_info_sources_create();
305 if (!proc_dbg_info_src) {
306 goto end;
307 }
308
309 g_hash_table_insert(ht, key, proc_dbg_info_src);
310 /* Ownership passed to ht */
311 key = NULL;
312end:
313 g_free(key);
314 return proc_dbg_info_src;
315}
316
ca9f27f3
FD
317static inline
318const bt_field *event_borrow_payload_field(const bt_event *event,
319 const char *field_name)
320{
321 const bt_field *event_payload, *field;
322
323 event_payload = bt_event_borrow_payload_field_const(event);
324 BT_ASSERT(event_payload);
325
326 field = bt_field_structure_borrow_member_field_by_name_const(
327 event_payload, field_name);
328 return field;
329}
330
331static inline
332const bt_field *event_borrow_common_context_field(const bt_event *event,
333 const char *field_name)
334{
335 const bt_field *event_common_ctx, *field = NULL;
336
337 event_common_ctx = bt_event_borrow_common_context_field_const(event);
338 if (!event_common_ctx) {
339 goto end;
340 }
341
342 field = bt_field_structure_borrow_member_field_by_name_const(
343 event_common_ctx, field_name);
344
345end:
346 return field;
347}
348
349static inline
350void event_get_common_context_signed_integer_field_value(
351 const bt_event *event, const char *field_name, int64_t *value)
352{
353 *value = bt_field_signed_integer_get_value(
354 event_borrow_common_context_field(event, field_name));
355}
356
357static inline
358int event_get_payload_build_id_length(const bt_event *event,
359 const char *field_name, uint64_t *build_id_len)
360{
361 const bt_field *build_id_field;
362 const bt_field_class *build_id_field_class;
363
364 build_id_field = event_borrow_payload_field(event, field_name);
365 build_id_field_class = bt_field_borrow_class_const(build_id_field);
366
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);
373
374 *build_id_len = bt_field_array_get_length(build_id_field);
375
376 return 0;
377}
378
379static inline
380int event_get_payload_build_id_value(const bt_event *event,
381 const char *field_name, uint8_t *build_id)
382{
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;
386 int ret;
387
388 ret = 0;
389
390 build_id_field = event_borrow_payload_field(event, field_name);
391 build_id_field_class = bt_field_borrow_class_const(build_id_field);
392
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);
399
400 build_id_len = bt_field_array_get_length(build_id_field);
401
402 for (i = 0; i < build_id_len; i++) {
403 curr_field =
404 bt_field_array_borrow_element_field_by_index_const(
405 build_id_field, i);
406
407 build_id[i] = bt_field_unsigned_integer_get_value(curr_field);
408 }
409
410 return ret;
411}
412
413static
414void event_get_payload_unsigned_integer_field_value(const bt_event *event,
415 const char *field_name, uint64_t *value)
416{
417 *value = bt_field_unsigned_integer_get_value(
418 event_borrow_payload_field(event, field_name));
419}
420
421static
422void event_get_payload_string_field_value(const bt_event *event,
423 const char *field_name, const char **value)
424{
425 *value = bt_field_string_get_value(
426 event_borrow_payload_field(event, field_name));
427}
428
429static inline
430bool event_has_payload_field(const bt_event *event,
431 const char *field_name)
432{
433 return event_borrow_payload_field(event, field_name) != NULL;
434}
435
4f45f9bb
JD
436static
437struct debug_info_source *proc_debug_info_sources_get_entry(
438 struct proc_debug_info_sources *proc_dbg_info_src, uint64_t ip)
439{
440 struct debug_info_source *debug_info_src = NULL;
441 gpointer key = g_new0(uint64_t, 1);
442 GHashTableIter iter;
443 gpointer baddr, value;
444
445 if (!key) {
446 goto end;
447 }
448
449 *((uint64_t *) key) = ip;
450
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,
454 key);
455 if (debug_info_src) {
456 goto end;
457 }
458
459 /* Check in all bin_infos. */
460 g_hash_table_iter_init(&iter, proc_dbg_info_src->baddr_to_bin_info);
461
462 while (g_hash_table_iter_next(&iter, &baddr, &value))
463 {
464 struct bin_info *bin = value;
465
466 if (!bin_info_has_address(value, ip)) {
467 continue;
468 }
469
470 /*
471 * Found; add it to cache.
472 *
473 * FIXME: this should be bounded in size (and implement
474 * a caching policy), and entries should be prunned when
475 * libraries are unmapped.
476 */
477 debug_info_src = debug_info_source_create_from_bin(bin, ip);
478 if (debug_info_src) {
479 g_hash_table_insert(
480 proc_dbg_info_src->ip_to_debug_info_src,
481 key, debug_info_src);
482 /* Ownership passed to ht. */
483 key = NULL;
484 }
485 break;
486 }
487
488end:
489 free(key);
490 return debug_info_src;
491}
492
493BT_HIDDEN
494struct debug_info_source *debug_info_query(struct debug_info *debug_info,
495 int64_t vpid, uint64_t ip)
496{
497 struct debug_info_source *dbg_info_src = NULL;
498 struct proc_debug_info_sources *proc_dbg_info_src;
499
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) {
503 goto end;
504 }
505
506 dbg_info_src = proc_debug_info_sources_get_entry(proc_dbg_info_src, ip);
507
508end:
509 return dbg_info_src;
510}
511
512BT_HIDDEN
ca9f27f3
FD
513struct debug_info *debug_info_create(struct debug_info_component *comp,
514 const bt_trace *trace)
4f45f9bb
JD
515{
516 int ret;
517 struct debug_info *debug_info;
518
519 debug_info = g_new0(struct debug_info, 1);
520 if (!debug_info) {
521 goto end;
522 }
523
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) {
528 goto error;
529 }
530
9d325e17 531 debug_info->comp = comp;
4f45f9bb
JD
532 ret = debug_info_init(debug_info);
533 if (ret) {
534 goto error;
535 }
536
ca9f27f3
FD
537 debug_info->input_trace = trace;
538
4f45f9bb
JD
539end:
540 return debug_info;
541error:
542 g_free(debug_info);
543 return NULL;
544}
545
546BT_HIDDEN
547void debug_info_destroy(struct debug_info *debug_info)
548{
ca9f27f3 549 bt_trace_status status;
4f45f9bb
JD
550 if (!debug_info) {
551 goto end;
552 }
553
554 if (debug_info->vpid_to_proc_dbg_info_src) {
555 g_hash_table_destroy(debug_info->vpid_to_proc_dbg_info_src);
556 }
557
ca9f27f3
FD
558 status = bt_trace_remove_destruction_listener(debug_info->input_trace,
559 debug_info->destruction_listener_id);
560
4f45f9bb
JD
561 g_free(debug_info);
562end:
563 return;
564}
565
566static
ca9f27f3 567void handle_event_statedump_build_id(struct debug_info *debug_info,
b19ff26f 568 const bt_event *event)
4f45f9bb
JD
569{
570 struct proc_debug_info_sources *proc_dbg_info_src;
ca9f27f3
FD
571 uint64_t build_id_len, baddr;
572 uint8_t *build_id = NULL;
573 struct bin_info *bin;
4f45f9bb 574 int64_t vpid;
ca9f27f3 575 int ret = 0;
4f45f9bb 576
ca9f27f3
FD
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);
4f45f9bb
JD
581
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) {
585 goto end;
586 }
587
588 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
589 (gpointer) &baddr);
590 if (!bin) {
591 /*
592 * The build_id event comes after the bin has been
593 * created. If it isn't found, just ignore this event.
594 */
595 goto end;
596 }
ca9f27f3
FD
597 ret = event_get_payload_build_id_length(event, BUILD_ID_FIELD_NAME,
598 &build_id_len);
599
600 build_id = g_new0(uint8_t, build_id_len);
601 if (!build_id) {
602 goto end;
603 }
4f45f9bb 604
ca9f27f3
FD
605 ret = event_get_payload_build_id_value(event, BUILD_ID_FIELD_NAME,
606 build_id);
4f45f9bb 607 if (ret) {
4f45f9bb
JD
608 goto end;
609 }
ca9f27f3
FD
610
611 ret = bin_info_set_build_id(bin, build_id, build_id_len);
612 if (ret) {
613 goto end;
445e79d6 614 }
4f45f9bb
JD
615
616 /*
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.
620 */
621 bin->is_elf_only = false;
622
4f45f9bb 623end:
ca9f27f3 624 g_free(build_id);
4f45f9bb
JD
625 return;
626}
627
628static
ca9f27f3 629void handle_event_statedump_debug_link(struct debug_info *debug_info,
b19ff26f 630 const bt_event *event)
4f45f9bb
JD
631{
632 struct proc_debug_info_sources *proc_dbg_info_src;
633 struct bin_info *bin = NULL;
634 int64_t vpid;
635 uint64_t baddr;
636 const char *filename = NULL;
637 uint32_t crc32;
ca9f27f3 638 uint64_t crc_field_value;
4f45f9bb 639
ca9f27f3 640 event_get_common_context_signed_integer_field_value(event,
c4838cef 641 VPID_FIELD_NAME, &vpid);
4f45f9bb 642
ca9f27f3
FD
643 event_get_payload_unsigned_integer_field_value(event,
644 BADDR_FIELD_NAME, &baddr);
4f45f9bb 645
ca9f27f3
FD
646 event_get_payload_unsigned_integer_field_value(event,
647 CRC32_FIELD_NAME, &crc_field_value);
4f45f9bb 648
ca9f27f3
FD
649 crc32 = (uint32_t) crc_field_value;
650
651 event_get_payload_string_field_value(event,
652 FILENAME_FIELD_NAME, &filename);
4f45f9bb
JD
653
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) {
657 goto end;
658 }
659
660 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
661 (gpointer) &baddr);
662 if (!bin) {
663 /*
664 * The debug_link event comes after the bin has been
665 * created. If it isn't found, just ignore this event.
666 */
667 goto end;
668 }
669
670 bin_info_set_debug_link(bin, filename, crc32);
671
672end:
673 return;
674}
675
676static
ca9f27f3 677void handle_bin_info_event(struct debug_info *debug_info,
b19ff26f 678 const bt_event *event, bool has_pic_field)
4f45f9bb
JD
679{
680 struct proc_debug_info_sources *proc_dbg_info_src;
681 struct bin_info *bin;
682 uint64_t baddr, memsz;
683 int64_t vpid;
684 const char *path;
685 gpointer key = NULL;
686 bool is_pic;
4f45f9bb 687
ca9f27f3
FD
688 event_get_payload_unsigned_integer_field_value(event,
689 MEMSZ_FIELD_NAME, &memsz);
690 if (memsz == 0) {
691 /* Ignore VDSO. */
4f45f9bb
JD
692 goto end;
693 }
694
ca9f27f3
FD
695 event_get_payload_unsigned_integer_field_value(event,
696 BADDR_FIELD_NAME, &baddr);
4f45f9bb 697
65db8b88
JD
698 /*
699 * This field is not produced by the dlopen event emitted before
700 * lttng-ust 2.9.
701 */
ca9f27f3 702 if (!event_has_payload_field(event, PATH_FIELD_NAME)) {
4f45f9bb
JD
703 goto end;
704 }
ca9f27f3 705 event_get_payload_string_field_value(event, PATH_FIELD_NAME, &path);
4f45f9bb
JD
706
707 if (has_pic_field) {
ca9f27f3 708 uint64_t is_pic_field_value;
4f45f9bb 709
ca9f27f3
FD
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;
4f45f9bb
JD
713 } else {
714 /*
715 * dlopen has no is_pic field, because the shared
716 * object is always PIC.
717 */
718 is_pic = true;
719 }
720
ca9f27f3 721 event_get_common_context_signed_integer_field_value(event,
c4838cef 722 VPID_FIELD_NAME, &vpid);
4f45f9bb
JD
723
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) {
727 goto end;
728 }
729
730 key = g_new0(uint64_t, 1);
731 if (!key) {
732 goto end;
733 }
734
735 *((uint64_t *) key) = baddr;
736
737 bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
738 key);
739 if (bin) {
740 goto end;
741 }
742
9d325e17
PP
743 bin = bin_info_create(path, baddr, memsz, is_pic,
744 debug_info->comp->arg_debug_dir,
745 debug_info->comp->arg_target_prefix);
4f45f9bb
JD
746 if (!bin) {
747 goto end;
748 }
749
750 g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
751 key, bin);
752 /* Ownership passed to ht. */
753 key = NULL;
754
755end:
756 g_free(key);
757 return;
758}
759
760static inline
ca9f27f3 761void handle_event_statedump_bin_info(struct debug_info *debug_info,
b19ff26f 762 const bt_event *event)
4f45f9bb 763{
ca9f27f3 764 handle_bin_info_event(debug_info, event, true);
4f45f9bb
JD
765}
766
767static inline
ca9f27f3 768void handle_event_lib_load(struct debug_info *debug_info,
b19ff26f 769 const bt_event *event)
4f45f9bb 770{
ca9f27f3 771 handle_bin_info_event(debug_info, event, false);
4f45f9bb
JD
772}
773
ca9f27f3
FD
774static
775void handle_event_lib_unload(struct debug_info *debug_info,
b19ff26f 776 const bt_event *event)
4f45f9bb 777{
ca9f27f3 778 gboolean ret;
4f45f9bb
JD
779 struct proc_debug_info_sources *proc_dbg_info_src;
780 uint64_t baddr;
781 int64_t vpid;
4f45f9bb 782
ca9f27f3
FD
783 event_get_payload_unsigned_integer_field_value(event, BADDR_FIELD_NAME,
784 &baddr);
4f45f9bb 785
ca9f27f3
FD
786 event_get_common_context_signed_integer_field_value(event,
787 VPID_FIELD_NAME, &vpid);
4f45f9bb
JD
788
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) {
ca9f27f3
FD
792 /*
793 * It's an unload event for a library for which no load event
794 * was previously received.
795 */
4f45f9bb
JD
796 goto end;
797 }
798
ca9f27f3
FD
799 ret = g_hash_table_remove(proc_dbg_info_src->baddr_to_bin_info,
800 (gpointer) &baddr);
801 BT_ASSERT(ret);
4f45f9bb
JD
802end:
803 return;
804}
805
806static
ca9f27f3 807void handle_event_statedump_start(struct debug_info *debug_info,
b19ff26f 808 const bt_event *event)
4f45f9bb
JD
809{
810 struct proc_debug_info_sources *proc_dbg_info_src;
811 int64_t vpid;
4f45f9bb 812
ca9f27f3
FD
813 event_get_common_context_signed_integer_field_value(
814 event, VPID_FIELD_NAME, &vpid);
4f45f9bb
JD
815
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) {
819 goto end;
820 }
821
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);
824
825end:
826 return;
827}
828
ca9f27f3
FD
829void trace_debug_info_remove_func(const bt_trace *in_trace, void *data)
830{
831 struct debug_info_msg_iter *debug_it = data;
832 if (debug_it->debug_info_map) {
833 gboolean ret;
834 ret = g_hash_table_remove(debug_it->debug_info_map,
835 (gpointer) in_trace);
836 BT_ASSERT(ret);
837 }
838}
839
840static
841void handle_event_statedump(struct debug_info_msg_iter *debug_it,
842 const bt_event *event)
4f45f9bb 843{
b19ff26f 844 const bt_event_class *event_class;
4f45f9bb
JD
845 const char *event_name;
846 GQuark q_event_name;
ca9f27f3
FD
847 const bt_trace *trace;
848 struct debug_info *debug_info;
849
850 BT_ASSERT(debug_it);
851 BT_ASSERT(event);
852
853 event_class = bt_event_borrow_class_const(event);
4f45f9bb 854
50842bdc 855 event_name = bt_event_class_get_name(event_class);
ca9f27f3
FD
856
857 trace = bt_stream_borrow_trace_const(
858 bt_event_borrow_stream_const(event));
859
860 debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace);
861 if (!debug_info) {
862 debug_info = debug_info_create(debug_it->debug_info_component,
863 trace);
864 g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace,
865 debug_info);
866 bt_trace_add_destruction_listener(trace,
867 trace_debug_info_remove_func, debug_it,
868 &debug_info->destruction_listener_id);
4f45f9bb 869 }
ca9f27f3 870
4f45f9bb
JD
871 q_event_name = g_quark_try_string(event_name);
872
873 if (q_event_name == debug_info->q_statedump_bin_info) {
874 /* State dump */
ca9f27f3 875 handle_event_statedump_bin_info(debug_info, event);
4f45f9bb
JD
876 } else if (q_event_name == debug_info->q_dl_open ||
877 q_event_name == debug_info->q_lib_load) {
878 /*
879 * dl_open and lib_load events are both checked for since
880 * only dl_open was produced as of lttng-ust 2.8.
881 *
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.
886 */
ca9f27f3 887 handle_event_lib_load(debug_info, event);
4f45f9bb
JD
888 } else if (q_event_name == debug_info->q_statedump_start) {
889 /* Start state dump */
ca9f27f3 890 handle_event_statedump_start(debug_info, event);
4f45f9bb
JD
891 } else if (q_event_name == debug_info->q_statedump_debug_link) {
892 /* Debug link info */
ca9f27f3 893 handle_event_statedump_debug_link(debug_info, event);
4f45f9bb
JD
894 } else if (q_event_name == debug_info->q_statedump_build_id) {
895 /* Build ID info */
ca9f27f3 896 handle_event_statedump_build_id(debug_info, event);
4f45f9bb 897 } else if (q_event_name == debug_info-> q_lib_unload) {
ca9f27f3
FD
898 handle_event_lib_unload(debug_info, event);
899 }
900
901 return;
902}
903
904static
905void destroy_debug_info_comp(struct debug_info_component *debug_info)
906{
907 free(debug_info->arg_debug_info_field_name);
908 g_free(debug_info);
909}
910
911static
912void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src,
913 bool full_path, bt_field *curr_field)
914{
915 bt_field_status status;
916
917 BT_ASSERT(bt_field_get_class_type(curr_field) ==
918 BT_FIELD_CLASS_TYPE_STRING);
919
920 if (dbg_info_src) {
921 if (full_path) {
922 status = bt_field_string_set_value(curr_field,
923 dbg_info_src->bin_path);
924 } else {
925 status = bt_field_string_set_value(curr_field,
926 dbg_info_src->short_bin_path);
927 }
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",
931 curr_field);
932 }
933
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",
938 curr_field);
939 }
940
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",
945 curr_field);
946 }
947 } else {
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);
952 }
953 }
954}
955
956static
957void fill_debug_info_func_field(struct debug_info_source *dbg_info_src,
958 bt_field *curr_field)
959{
960 bt_field_status status;
961
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,
966 dbg_info_src->func);
967 } else {
968 status = bt_field_string_set_value(curr_field, "");
969 }
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);
973 }
974}
975
976static
977void fill_debug_info_src_field(struct debug_info_source *dbg_info_src,
978 bool full_path, bt_field *curr_field)
979{
980 bt_field_status status;
981
982 BT_ASSERT(bt_field_get_class_type(curr_field) ==
983 BT_FIELD_CLASS_TYPE_STRING);
984
985 if (dbg_info_src && dbg_info_src->src_path) {
986 if (full_path) {
987 status = bt_field_string_set_value(curr_field,
988 dbg_info_src->src_path);
989 } else {
990 status = bt_field_string_set_value(curr_field,
991 dbg_info_src->short_src_path);
992 }
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",
996 curr_field);
997 }
998
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",
1003 curr_field);
1004 }
1005
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",
1010 curr_field);
1011 }
1012 } else {
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);
1017 }
1018 }
1019}
1020
1021void fill_debug_info_field_empty(bt_field *debug_info_field)
1022{
1023 bt_field_status status;
1024 bt_field *bin_field, *func_field, *src_field;
1025
1026 BT_ASSERT(bt_field_get_class_type(debug_info_field) ==
1027 BT_FIELD_CLASS_TYPE_STRUCTURE);
1028
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");
1035
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);
1042
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);
1047 }
1048
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);
1053 }
1054
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);
1059 }
1060}
1061static
1062void fill_debug_info_field(struct debug_info *debug_info, int64_t vpid,
1063 uint64_t ip, bt_field *debug_info_field)
1064{
1065 struct debug_info_source *dbg_info_src;
1066 const bt_field_class *debug_info_fc;
1067
1068 BT_ASSERT(bt_field_get_class_type(debug_info_field) ==
1069 BT_FIELD_CLASS_TYPE_STRUCTURE);
1070
1071 debug_info_fc = bt_field_borrow_class_const(debug_info_field);
1072
1073 BT_ASSERT(bt_field_class_structure_get_member_count(debug_info_fc) == 3);
1074
1075 dbg_info_src = debug_info_query(debug_info, vpid, ip);
1076
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"));
1086}
1087
1088static
1089void fill_debug_info_event_if_needed(struct debug_info_msg_iter *debug_it,
1090 const bt_event *in_event, bt_event *out_event)
1091{
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;
1096 uint64_t vpid;
1097 int64_t ip;
1098 char *debug_info_field_name =
1099 debug_it->debug_info_component->arg_debug_info_field_name;
1100
1101 in_common_ctx_field = bt_event_borrow_common_context_field_const(
1102 in_event);
1103 if (!in_common_ctx_field) {
1104 /*
1105 * There is no event common context so no need to add debug
1106 * info field.
1107 */
1108 goto end;
1109 }
1110
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)) {
1114 /*
1115 * The input event common context does not have the necessary
1116 * fields to resolve debug information.
1117 */
1118 goto end;
1119 }
1120
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) {
1124 goto end;
4f45f9bb
JD
1125 }
1126
ca9f27f3
FD
1127 out_debug_info_field = bt_field_structure_borrow_member_field_by_name(
1128 out_common_ctx_field, debug_info_field_name);
1129
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);
1134
1135 vpid = bt_field_signed_integer_get_value(vpid_field);
1136 ip = bt_field_unsigned_integer_get_value(ip_field);
1137
1138 /*
1139 * Borrow the debug_info structure needed for the source
1140 * resolving.
1141 */
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)));
1145
1146 if (debug_info) {
1147 /*
1148 * Perform the debug-info resolving and set the event fields
1149 * accordingly.
1150 */
1151 fill_debug_info_field(debug_info, vpid, ip, out_debug_info_field);
1152 } else {
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);
1156 }
4f45f9bb
JD
1157end:
1158 return;
1159}
ca9f27f3
FD
1160
1161static
1162void update_event_statedump_if_needed(struct debug_info_msg_iter *debug_it,
1163 const bt_event *in_event)
1164{
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);
1168
1169 /*
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.
1172 */
1173 event_common_ctx = bt_event_borrow_common_context_field_const(in_event);
1174 if (!event_common_ctx) {
1175 goto end;
1176 }
1177
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);
1187 }
1188 }
1189end:
1190 return;
1191}
1192
1193static
1194bt_message *handle_event_message(struct debug_info_msg_iter *debug_it,
1195 const bt_message *in_message)
1196{
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;
1204
1205 bt_message *out_message = NULL;
1206
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);
1212
1213 update_event_statedump_if_needed(debug_it, in_event);
1214
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);
1220 }
1221 BT_ASSERT(out_event_class);
1222
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,
1226 in_packet);
1227
1228 default_cc = bt_stream_class_borrow_default_clock_class_const(
1229 bt_event_class_borrow_stream_class_const(in_event_class));
1230 if (default_cc) {
1231 /* Borrow event clock snapshot. */
1232 cs_state =
1233 bt_message_event_borrow_default_clock_snapshot_const(
1234 in_message, &cs);
1235
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));
1242 } else {
1243 out_message = bt_message_event_create(debug_it->input_iterator,
1244 out_event_class, out_packet);
1245 }
1246
1247 if (!out_message) {
1248 BT_LOGE("Error creating output event message.");
1249 goto error;
1250 }
1251
1252 out_event = bt_message_event_borrow_event(out_message);
1253
1254 /* Copy the original fields to the output event. */
1255 copy_event_content(in_event, out_event);
1256
1257 /*
1258 * Try to set the debug-info fields based on debug information that is
1259 * gathered so far.
1260 */
1261 fill_debug_info_event_if_needed(debug_it, in_event, out_event);
1262
1263error:
1264 return out_message;
1265}
1266
1267static
1268bt_message *handle_stream_begin_message(struct debug_info_msg_iter *debug_it,
1269 const bt_message *in_message)
1270{
1271 const bt_stream *in_stream;
1272 bt_message *out_message;
1273 bt_stream *out_stream;
1274
1275 in_stream = bt_message_stream_beginning_borrow_stream_const(in_message);
1276 BT_ASSERT(in_stream);
1277
1278 /* Create a duplicated output stream. */
1279 out_stream = trace_ir_mapping_create_new_mapped_stream(
1280 debug_it->ir_maps, in_stream);
1281 if (!out_stream) {
1282 out_message = NULL;
1283 goto error;
1284 }
1285
1286 /* Create an output stream beginning message. */
1287 out_message = bt_message_stream_beginning_create(
1288 debug_it->input_iterator, out_stream);
1289 if (!out_message) {
1290 BT_LOGE("Error creating output stream beginning message: "
1291 "out-s-addr=%p", out_stream);
1292 }
1293error:
1294 return out_message;
1295}
1296
1297static
1298bt_message *handle_stream_end_message(struct debug_info_msg_iter *debug_it,
1299 const bt_message *in_message)
1300{
1301 const bt_stream *in_stream;
1302 bt_message *out_message = NULL;
1303 bt_stream *out_stream;
1304
1305 in_stream = bt_message_stream_end_borrow_stream_const(in_message);
1306 BT_ASSERT(in_stream);
1307
1308 out_stream = trace_ir_mapping_borrow_mapped_stream(
1309 debug_it->ir_maps, in_stream);
1310 BT_ASSERT(out_stream);
1311
1312 /* Create an output stream end message. */
1313 out_message = bt_message_stream_end_create(debug_it->input_iterator,
1314 out_stream);
1315 if (!out_message) {
1316 BT_LOGE("Error creating output stream end message: out-s-addr=%p",
1317 out_stream);
1318 }
1319
1320 /* Remove stream from trace mapping hashtable. */
1321 trace_ir_mapping_remove_mapped_stream(debug_it->ir_maps, in_stream);
1322
1323 return out_message;
1324}
1325
1326static
1327bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it,
1328 const bt_message *in_message)
1329{
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;
1335
1336 const bt_packet *in_packet =
1337 bt_message_packet_beginning_borrow_packet_const(in_message);
1338 BT_ASSERT(in_packet);
1339
1340 /* This packet should not be already mapped. */
1341 BT_ASSERT(!trace_ir_mapping_borrow_mapped_packet(
1342 debug_it->ir_maps, in_packet));
1343
1344 out_packet = trace_ir_mapping_create_new_mapped_packet(debug_it->ir_maps,
1345 in_packet);
1346
1347 BT_ASSERT(out_packet);
1348
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)));
1352 if (default_cc) {
1353 /* Borrow clock snapshot. */
1354 cs_state =
1355 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
1356 in_message, &cs);
1357
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));
1363 } else {
1364 out_message = bt_message_packet_beginning_create(
1365 debug_it->input_iterator, out_packet);
1366 }
1367 if (!out_message) {
1368 BT_LOGE("Error creating output packet beginning message: "
1369 "out-p-addr=%p", out_packet);
1370 }
1371
1372 return out_message;
1373}
1374
1375static
1376bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it,
1377 const bt_message *in_message)
1378{
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;
1385
1386 in_packet = bt_message_packet_end_borrow_packet_const(in_message);
1387 BT_ASSERT(in_packet);
1388
1389 out_packet = trace_ir_mapping_borrow_mapped_packet(debug_it->ir_maps, in_packet);
1390 BT_ASSERT(out_packet);
1391
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)));
1395 if (default_cc) {
1396 /* Borrow clock snapshot. */
1397 cs_state =
1398 bt_message_packet_end_borrow_default_clock_snapshot_const(
1399 in_message, &cs);
1400
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));
1406 } else {
1407 out_message = bt_message_packet_end_create(
1408 debug_it->input_iterator, out_packet);
1409 }
1410
1411 if (!out_message) {
1412 BT_LOGE("Error creating output packet end message: "
1413 "out-p-addr=%p", out_packet);
1414 }
1415
1416 /* Remove packet from data mapping hashtable. */
1417 trace_ir_mapping_remove_mapped_packet(debug_it->ir_maps, in_packet);
1418
1419 return out_message;
1420}
1421
1422static
1423bt_message *handle_msg_iterator_inactivity(struct debug_info_msg_iter *debug_it,
1424 const bt_message *in_message)
1425{
1426 /*
1427 * This message type can be forwarded directly because it does
1428 * not refer to any objects in the trace class.
1429 */
1430 bt_message_get_ref(in_message);
1431 return (bt_message*) in_message;
1432}
1433
1434static
1435bt_message *handle_stream_act_begin_message(struct debug_info_msg_iter *debug_it,
1436 const bt_message *in_message)
1437{
1438 const bt_clock_snapshot *cs;
1439 const bt_clock_class *default_cc;
1440 bt_message *out_message = NULL;
1441 bt_stream *out_stream;
1442 uint64_t cs_value;
1443 bt_message_stream_activity_clock_snapshot_state cs_state;
1444
1445 const bt_stream *in_stream =
1446 bt_message_stream_activity_beginning_borrow_stream_const(
1447 in_message);
1448 BT_ASSERT(in_stream);
1449
1450 out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
1451 in_stream);
1452 BT_ASSERT(out_stream);
1453
1454 out_message = bt_message_stream_activity_beginning_create(
1455 debug_it->input_iterator, out_stream);
1456 if (!out_message) {
1457 BT_LOGE("Error creating output stream activity beginning "
1458 "message: out-s-addr=%p", out_stream);
1459 goto error;
1460 }
1461
1462 default_cc = bt_stream_class_borrow_default_clock_class_const(
1463 bt_stream_borrow_class_const(in_stream));
1464 if (default_cc) {
1465 /* Borrow clock snapshot. */
1466 cs_state =
1467 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
1468 in_message, &cs);
1469
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);
1474 } else {
1475 bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
1476 out_message, cs_state);
1477 }
1478 }
1479
1480error:
1481 return out_message;
1482}
1483
1484static
1485bt_message *handle_stream_act_end_message(struct debug_info_msg_iter *debug_it,
1486 const bt_message *in_message)
1487{
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;
1493 uint64_t cs_value;
1494 bt_message_stream_activity_clock_snapshot_state cs_state;
1495
1496 in_stream = bt_message_stream_activity_end_borrow_stream_const(
1497 in_message);
1498 BT_ASSERT(in_stream);
1499
1500 out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps, in_stream);
1501 BT_ASSERT(out_stream);
1502
1503 out_message = bt_message_stream_activity_end_create(
1504 debug_it->input_iterator, out_stream);
1505 if (!out_message) {
1506 BT_LOGE("Error creating output stream activity end message: "
1507 "out-s-addr=%p", out_stream);
1508 goto error;
1509 }
1510
1511 default_cc = bt_stream_class_borrow_default_clock_class_const(
1512 bt_stream_borrow_class_const(in_stream));
1513
1514 if (default_cc) {
1515 cs_state =
1516 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
1517 in_message, &cs);
1518
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);
1523 } else {
1524 bt_message_stream_activity_end_set_default_clock_snapshot_state(
1525 out_message, cs_state);
1526 }
1527 }
1528
1529error:
1530 return out_message;
1531}
1532
1533static
1534bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it,
1535 const bt_message *in_message)
1536{
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;
1545
1546 in_stream = bt_message_discarded_events_borrow_stream_const(
1547 in_message);
1548 BT_ASSERT(in_stream);
1549
1550 out_stream = trace_ir_mapping_borrow_mapped_stream(
1551 debug_it->ir_maps, in_stream);
1552 BT_ASSERT(out_stream);
1553
1554 default_cc = bt_stream_class_borrow_default_clock_class_const(
1555 bt_stream_borrow_class_const(in_stream));
1556 if (default_cc) {
1557 begin_cs_state =
1558 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
1559 in_message, &begin_cs);
1560 end_cs_state =
1561 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
1562 in_message, &end_cs);
1563 /*
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.
1567 */
1568 BT_ASSERT(begin_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN &&
1569 end_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
1570
1571 begin_cs_value = bt_clock_snapshot_get_value(begin_cs);
1572 end_cs_value = bt_clock_snapshot_get_value(end_cs);
1573
1574 out_message =
1575 bt_message_discarded_events_create_with_default_clock_snapshots(
1576 debug_it->input_iterator, out_stream,
1577 begin_cs_value, end_cs_value);
1578 } else {
1579 out_message = bt_message_discarded_events_create(
1580 debug_it->input_iterator, out_stream);
1581 }
1582 if (!out_message) {
1583 BT_LOGE("Error creating output discarded events message: "
1584 "out-s-addr=%p", out_stream);
1585 goto error;
1586 }
1587
1588 prop_avail = bt_message_discarded_events_get_count(in_message,
1589 &discarded_events);
1590
1591 if (prop_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
1592 bt_message_discarded_events_set_count(out_message,
1593 discarded_events);
1594 }
1595
1596error:
1597 return out_message;
1598}
1599
1600static
1601bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_it,
1602 const bt_message *in_message)
1603{
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;
1612
1613 in_stream = bt_message_discarded_packets_borrow_stream_const(
1614 in_message);
1615 BT_ASSERT(in_stream);
1616
1617 out_stream = trace_ir_mapping_borrow_mapped_stream(
1618 debug_it->ir_maps, in_stream);
1619 BT_ASSERT(out_stream);
1620
1621 default_cc = bt_stream_class_borrow_default_clock_class_const(
1622 bt_stream_borrow_class_const(in_stream));
1623 if (default_cc) {
1624 begin_cs_state =
1625 bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
1626 in_message, &begin_cs);
1627
1628 end_cs_state =
1629 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
1630 in_message, &end_cs);
1631
1632 /*
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.
1636 */
1637 BT_ASSERT(begin_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN &&
1638 end_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
1639
1640 begin_cs_value = bt_clock_snapshot_get_value(begin_cs);
1641 end_cs_value = bt_clock_snapshot_get_value(end_cs);
1642
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);
1646 } else {
1647 out_message = bt_message_discarded_packets_create(
1648 debug_it->input_iterator, out_stream);
1649 }
1650 if (!out_message) {
1651 BT_LOGE("Error creating output discarded packet message: "
1652 "out-s-addr=%p", out_stream);
1653 goto error;
1654 }
1655
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,
1660 discarded_packets);
1661 }
1662
1663error:
1664 return out_message;
1665}
1666
1667static
1668const bt_message *handle_message(struct debug_info_msg_iter *debug_it,
1669 const bt_message *in_message)
1670{
1671 bt_message *out_message = NULL;
1672
1673 switch (bt_message_get_type(in_message)) {
1674 case BT_MESSAGE_TYPE_EVENT:
1675 out_message = handle_event_message(debug_it,
1676 in_message);
1677 break;
1678 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
1679 out_message = handle_packet_begin_message(debug_it,
1680 in_message);
1681 break;
1682 case BT_MESSAGE_TYPE_PACKET_END:
1683 out_message = handle_packet_end_message(debug_it,
1684 in_message);
1685 break;
1686 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
1687 out_message = handle_stream_begin_message(debug_it,
1688 in_message);
1689 break;
1690 case BT_MESSAGE_TYPE_STREAM_END:
1691 out_message = handle_stream_end_message(debug_it,
1692 in_message);
1693 break;
1694 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
1695 out_message = handle_msg_iterator_inactivity(debug_it,
1696 in_message);
1697 break;
1698 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
1699 out_message = handle_stream_act_begin_message(debug_it,
1700 in_message);
1701 break;
1702 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
1703 out_message = handle_stream_act_end_message(debug_it,
1704 in_message);
1705 break;
1706 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
1707 out_message = handle_discarded_events_message(debug_it,
1708 in_message);
1709 break;
1710 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
1711 out_message = handle_discarded_packets_message(debug_it,
1712 in_message);
1713 break;
1714 default:
1715 abort();
1716 break;
1717 }
1718
1719 return out_message;
1720}
1721
1722static
1723int init_from_params(struct debug_info_component *debug_info_component,
1724 const bt_value *params)
1725{
1726 const bt_value *value = NULL;
1727 int ret = 0;
1728
1729 BT_ASSERT(params);
1730
1731 value = bt_value_map_borrow_entry_value_const(params,
1732 "debug-info-field-name");
1733 if (value) {
1734 const char *debug_info_field_name;
1735
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);
1739 } else {
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.");
1745 goto end;
1746 }
1747 sprintf(debug_info_component->arg_debug_info_field_name,
1748 DEFAULT_DEBUG_INFO_FIELD_NAME);
1749 }
1750 if (ret) {
1751 goto end;
1752 }
1753
1754 value = bt_value_map_borrow_entry_value_const(params, "debug-info-dir");
1755 if (value) {
1756 debug_info_component->arg_debug_dir = bt_value_string_get(value);
1757 }
1758
1759 value = bt_value_map_borrow_entry_value_const(params, "target-prefix");
1760 if (value) {
1761 debug_info_component->arg_target_prefix =
1762 bt_value_string_get(value);
1763 }
1764
1765 value = bt_value_map_borrow_entry_value_const(params, "full-path");
1766 if (value) {
1767 debug_info_component->arg_full_path = bt_value_bool_get(value);
1768 }
1769
1770end:
1771 return ret;
1772}
1773
1774BT_HIDDEN
1775bt_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)
1778{
1779 int ret;
1780 struct debug_info_component *debug_info_comp;
1781 bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
1782
1783 BT_LOGD("Initializing debug_info component: "
1784 "comp-addr=%p, params-addr=%p", self_comp, params);
1785
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.");
1789 goto error;
1790 }
1791
1792 bt_self_component_set_data(
1793 bt_self_component_filter_as_self_component(self_comp),
1794 debug_info_comp);
1795
1796 status = bt_self_component_filter_add_input_port(self_comp, "in",
1797 NULL, NULL);
1798 if (status != BT_SELF_COMPONENT_STATUS_OK) {
1799 goto error;
1800 }
1801
1802 status = bt_self_component_filter_add_output_port(self_comp, "out",
1803 NULL, NULL);
1804 if (status != BT_SELF_COMPONENT_STATUS_OK) {
1805 goto error;
1806 }
1807
1808 ret = init_from_params(debug_info_comp, params);
1809 if (ret) {
1810 BT_LOGE("Cannot configure debug_info component: "
1811 "debug_info-comp-addr=%p, params-addr=%p",
1812 debug_info_comp, params);
1813 goto error;
1814 }
1815
1816 goto end;
1817
1818error:
1819 destroy_debug_info_comp(debug_info_comp);
1820 bt_self_component_set_data(
1821 bt_self_component_filter_as_self_component(self_comp),
1822 NULL);
1823
1824 if (status == BT_SELF_COMPONENT_STATUS_OK) {
1825 status = BT_SELF_COMPONENT_STATUS_ERROR;
1826 }
1827end:
1828 return status;
1829}
1830
1831BT_HIDDEN
1832void debug_info_comp_finalize(bt_self_component_filter *self_comp)
1833{
1834 struct debug_info_component *debug_info =
1835 bt_self_component_get_data(
1836 bt_self_component_filter_as_self_component(
1837 self_comp));
1838 BT_LOGD("Finalizing debug_info self_component: comp-addr=%p",
1839 self_comp);
1840
1841 destroy_debug_info_comp(debug_info);
1842}
1843
1844BT_HIDDEN
1845bt_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,
1848 uint64_t *count)
1849{
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;
1859
1860 status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
1861
1862 self_comp = bt_self_message_iterator_borrow_component(self_msg_iter);
1863 BT_ASSERT(self_comp);
1864
1865 debug_info = bt_self_component_get_data(self_comp);
1866 BT_ASSERT(debug_info);
1867
1868 debug_info_msg_iter = bt_self_message_iterator_get_data(self_msg_iter);
1869 BT_ASSERT(debug_info_msg_iter);
1870
1871 upstream_iterator = debug_info_msg_iter->msg_iter;
1872 BT_ASSERT(upstream_iterator);
1873
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) {
1878 /*
1879 * No messages were returned. Not necessarily an error. Convert
1880 * the upstream message iterator status to a self status.
1881 */
1882 status = bt_common_message_iterator_status_to_self(
1883 upstream_iterator_ret_status);
1884 goto end;
1885 }
1886
1887 /*
1888 * There should never be more received messages than the capacity we
1889 * provided.
1890 */
1891 BT_ASSERT(*count <= capacity);
1892
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]);
1896 if (!out_message) {
1897 goto handle_msg_error;
1898 }
1899
1900 msgs[curr_msg_idx] = out_message;
1901 /*
1902 * Drop our reference of the input message as we are done with
1903 * it and created a output copy.
1904 */
1905 bt_message_put_ref(input_msgs[curr_msg_idx]);
1906 }
1907
1908 goto end;
1909
1910handle_msg_error:
1911 /*
1912 * Drop references of all the output messages created before the
1913 * failure.
1914 */
1915 for (i = 0; i < curr_msg_idx; i++) {
1916 bt_message_put_ref(msgs[i]);
1917 }
1918
1919 status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
1920end:
1921 return status;
1922}
1923
1924BT_HIDDEN
1925bt_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)
1929{
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;
1934
1935 /* Borrow the upstream input port. */
1936 input_port = bt_self_component_filter_borrow_input_port_by_name(
1937 self_comp, "in");
1938 if (!input_port) {
1939 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
1940 goto end;
1941 }
1942
1943 /* Create an iterator on the upstream component. */
1944 upstream_iterator = bt_self_component_port_input_message_iterator_create(
1945 input_port);
1946 if (!upstream_iterator) {
1947 status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
1948 goto end;
1949 }
1950
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;
1954 goto end;
1955 }
1956
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;
1964 goto end;
1965 }
1966
1967 debug_info_msg_iter->self_comp =
1968 bt_self_component_filter_as_self_component(self_comp);
1969
1970 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
1971 debug_info_msg_iter->msg_iter, upstream_iterator);
1972
1973 debug_info_msg_iter->debug_info_component = bt_self_component_get_data(
1974 bt_self_component_filter_as_self_component(
1975 self_comp));
1976
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;
1984 goto end;
1985 }
1986
1987 bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
1988
1989 debug_info_msg_iter->input_iterator = self_msg_iter;
1990
1991end:
1992 return status;
1993}
1994
1995BT_HIDDEN
1996bt_bool debug_info_msg_iter_can_seek_beginning(
1997 bt_self_message_iterator *self_msg_iter)
1998{
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);
2002
2003 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2004 debug_info_msg_iter->msg_iter);
2005}
2006
2007BT_HIDDEN
2008bt_self_message_iterator_status debug_info_msg_iter_seek_beginning(
2009 bt_self_message_iterator *self_msg_iter)
2010{
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;
2014
2015 BT_ASSERT(debug_info_msg_iter);
2016
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) {
2021 goto end;
2022 }
2023
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);
2027end:
2028 return bt_common_message_iterator_status_to_self(status);
2029}
2030
2031BT_HIDDEN
2032void debug_info_msg_iter_finalize(bt_self_message_iterator *it)
2033{
2034 struct debug_info_msg_iter *debug_info_msg_iter;
2035
2036 debug_info_msg_iter = bt_self_message_iterator_get_data(it);
2037 BT_ASSERT(debug_info_msg_iter);
2038
2039 bt_self_component_port_input_message_iterator_put_ref(
2040 debug_info_msg_iter->msg_iter);
2041
2042 trace_ir_maps_destroy(debug_info_msg_iter->ir_maps);
2043 g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
2044
2045 g_free(debug_info_msg_iter);
2046}
This page took 0.120497 seconds and 4 git commands to generate.