lib: remove unused includes
[babeltrace.git] / src / lib / lib-logging.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #define BT_LOG_TAG "LIB/LIB-LOGGING"
8 #include "lib/logging.h"
9
10 #include <stdarg.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <inttypes.h>
15 #include <stdbool.h>
16 #include <stdint.h>
17 #include <wchar.h>
18 #include <glib.h>
19 #include "common/common.h"
20 #include "common/uuid.h"
21 #include <babeltrace2/babeltrace.h>
22
23 #include "logging.h"
24 #include "assert-cond.h"
25 #include "value.h"
26 #include "integer-range-set.h"
27 #include "object-pool.h"
28 #include "graph/interrupter.h"
29 #include "graph/component-class.h"
30 #include "graph/component.h"
31 #include "graph/connection.h"
32 #include "graph/graph.h"
33 #include "graph/message/discarded-items.h"
34 #include "graph/message/event.h"
35 #include "graph/message/iterator.h"
36 #include "graph/message/message.h"
37 #include "graph/message/packet.h"
38 #include "graph/message/stream.h"
39 #include "graph/port.h"
40 #include "plugin/plugin.h"
41 #include "plugin/plugin-so.h"
42 #include "trace-ir/clock-class.h"
43 #include "trace-ir/clock-snapshot.h"
44 #include "trace-ir/event-class.h"
45 #include "trace-ir/event.h"
46 #include "trace-ir/field-class.h"
47 #include "trace-ir/field.h"
48 #include "trace-ir/field-path.h"
49 #include "trace-ir/packet.h"
50 #include "trace-ir/stream-class.h"
51 #include "trace-ir/stream.h"
52 #include "trace-ir/trace-class.h"
53 #include "trace-ir/trace.h"
54 #include "error.h"
55
56 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
57
58 static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE];
59
60 #define BUF_APPEND(_fmt, ...) \
61 do { \
62 int _count; \
63 size_t _size = LIB_LOGGING_BUF_SIZE - \
64 (size_t) (*buf_ch - lib_logging_buf); \
65 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
66 BT_ASSERT(_count >= 0); \
67 *buf_ch += MIN(_count, _size); \
68 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
69 return; \
70 } \
71 } while (0)
72
73 #define BUF_APPEND_UUID(_uuid) \
74 do { \
75 BUF_APPEND(", %suuid=", prefix); \
76 format_uuid(buf_ch, (_uuid)); \
77 } while (0)
78
79 #define PRFIELD(_expr) prefix, (_expr)
80
81 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
82
83 #define TMP_PREFIX_LEN 128
84 #define SET_TMP_PREFIX(_prefix2) \
85 do { \
86 int snprintf_ret = \
87 snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \
88 prefix, (_prefix2)); \
89 \
90 if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
91 bt_common_abort(); \
92 } \
93 \
94 tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \
95 } while (0)
96
97 static inline void format_component(char **buf_ch, bool extended,
98 const char *prefix, const struct bt_component *component);
99
100 static inline void format_port(char **buf_ch, bool extended,
101 const char *prefix, const struct bt_port *port);
102
103 static inline void format_connection(char **buf_ch, bool extended,
104 const char *prefix, const struct bt_connection *connection);
105
106 static inline void format_clock_snapshot(char **buf_ch, bool extended,
107 const char *prefix, const struct bt_clock_snapshot *clock_snapshot);
108
109 static inline void format_field_path(char **buf_ch, bool extended,
110 const char *prefix, const struct bt_field_path *field_path);
111
112 static inline void format_object(char **buf_ch, const char *prefix,
113 const struct bt_object *obj)
114 {
115 BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count);
116 }
117
118 static inline void format_uuid(char **buf_ch, bt_uuid uuid)
119 {
120 BUF_APPEND("\"" BT_UUID_FMT "\"", BT_UUID_FMT_VALUES(uuid));
121 }
122
123 static inline void format_object_pool(char **buf_ch, const char *prefix,
124 const struct bt_object_pool *pool)
125 {
126 BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size));
127
128 if (pool->objects) {
129 BUF_APPEND(", %scap=%u", PRFIELD(pool->objects->len));
130 }
131 }
132
133 static inline void format_integer_field_class(char **buf_ch, const char *prefix,
134 const struct bt_field_class *field_class)
135 {
136 const struct bt_field_class_integer *int_fc =
137 (const void *) field_class;
138
139 BUF_APPEND(", %srange-size=%" PRIu64 ", %sbase=%s",
140 PRFIELD(int_fc->range),
141 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base)));
142 }
143
144 static inline void format_array_field_class(char **buf_ch, const char *prefix,
145 const struct bt_field_class *field_class)
146 {
147 const struct bt_field_class_array *array_fc =
148 (const void *) field_class;
149
150 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
151 PRFIELD(array_fc->element_fc),
152 PRFIELD(bt_common_field_class_type_string(array_fc->element_fc->type)));
153 }
154
155 static inline void format_field_class(char **buf_ch, bool extended,
156 const char *prefix, const struct bt_field_class *field_class)
157 {
158 char tmp_prefix[TMP_PREFIX_LEN];
159
160 BUF_APPEND(", %stype=%s",
161 PRFIELD(bt_common_field_class_type_string(field_class->type)));
162
163 if (extended) {
164 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class->frozen));
165 BUF_APPEND(", %sis-part-of-trace-class=%d",
166 PRFIELD(field_class->part_of_trace_class));
167 } else {
168 return;
169 }
170
171 switch (field_class->type) {
172 case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
173 {
174 const struct bt_field_class_bit_array *ba_fc =
175 (const void *) field_class;
176
177 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(ba_fc->length));
178 break;
179 }
180 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
181 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
182 {
183 format_integer_field_class(buf_ch, prefix, field_class);
184 break;
185 }
186 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
187 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
188 {
189 const struct bt_field_class_enumeration *enum_fc =
190 (const void *) field_class;
191
192 format_integer_field_class(buf_ch, prefix, field_class);
193 BUF_APPEND(", %smapping-count=%u",
194 PRFIELD(enum_fc->mappings->len));
195 break;
196 }
197 case BT_FIELD_CLASS_TYPE_STRUCTURE:
198 {
199 const struct bt_field_class_structure *struct_fc =
200 (const void *) field_class;
201
202 if (struct_fc->common.named_fcs) {
203 BUF_APPEND(", %smember-count=%u",
204 PRFIELD(struct_fc->common.named_fcs->len));
205 }
206
207 break;
208 }
209 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
210 {
211 const struct bt_field_class_array_static *array_fc =
212 (const void *) field_class;
213
214 format_array_field_class(buf_ch, prefix, field_class);
215 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length));
216 break;
217 }
218 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD:
219 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD:
220 {
221 const struct bt_field_class_array_dynamic *array_fc =
222 (const void *) field_class;
223
224 format_array_field_class(buf_ch, prefix, field_class);
225
226 if (array_fc->length_fc) {
227 SET_TMP_PREFIX("length-fc-");
228 format_field_class(buf_ch, extended, tmp_prefix,
229 array_fc->length_fc);
230 }
231
232 if (array_fc->length_field_path) {
233 SET_TMP_PREFIX("length-field-path-");
234 format_field_path(buf_ch, extended, tmp_prefix,
235 array_fc->length_field_path);
236 }
237
238 break;
239 }
240 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD:
241 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD:
242 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
243 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
244 {
245 const struct bt_field_class_option *opt_fc =
246 (const void *) field_class;
247
248 BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s",
249 PRFIELD(opt_fc->content_fc),
250 PRFIELD(bt_common_field_class_type_string(opt_fc->content_fc->type)));
251
252 if (field_class->type !=
253 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) {
254 const struct bt_field_class_option_with_selector_field *opt_with_sel_fc =
255 (const void *) field_class;
256
257 if (opt_with_sel_fc->selector_fc) {
258 SET_TMP_PREFIX("selector-fc-");
259 format_field_class(buf_ch, extended, tmp_prefix,
260 opt_with_sel_fc->selector_fc);
261 }
262
263 if (opt_with_sel_fc->selector_field_path) {
264 SET_TMP_PREFIX("selector-field-path-");
265 format_field_path(buf_ch, extended, tmp_prefix,
266 opt_with_sel_fc->selector_field_path);
267 }
268 }
269
270 break;
271 }
272 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD:
273 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
274 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
275 {
276 const struct bt_field_class_variant *var_fc =
277 (const void *) field_class;
278
279 if (var_fc->common.named_fcs) {
280 BUF_APPEND(", %soption-count=%u",
281 PRFIELD(var_fc->common.named_fcs->len));
282 }
283
284 if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD ||
285 field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) {
286 const struct bt_field_class_variant_with_selector_field *var_with_sel_fc =
287 (const void *) var_fc;
288
289 if (var_with_sel_fc->selector_fc) {
290 SET_TMP_PREFIX("selector-fc-");
291 format_field_class(buf_ch, extended, tmp_prefix,
292 var_with_sel_fc->selector_fc);
293 }
294
295 if (var_with_sel_fc->selector_field_path) {
296 SET_TMP_PREFIX("selector-field-path-");
297 format_field_path(buf_ch, extended, tmp_prefix,
298 var_with_sel_fc->selector_field_path);
299 }
300 }
301
302 break;
303 }
304 default:
305 break;
306 }
307 }
308
309 static inline void format_field_integer_extended(char **buf_ch,
310 const char *prefix, const struct bt_field *field)
311 {
312 const struct bt_field_integer *integer = (void *) field;
313 const struct bt_field_class_integer *field_class =
314 (void *) field->class;
315 const char *fmt = NULL;
316
317 BT_ASSERT(field_class);
318
319 if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL) {
320 fmt = ", %svalue=%" PRIo64;
321 } else if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL) {
322 fmt = ", %svalue=%" PRIx64;
323 }
324
325 #pragma GCC diagnostic push
326 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
327 if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
328 field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) {
329 if (!fmt) {
330 fmt = ", %svalue=%" PRId64;
331 }
332
333 BUF_APPEND(fmt, PRFIELD(integer->value.i));
334 } else {
335 if (!fmt) {
336 fmt = ", %svalue=%" PRIu64;
337 }
338
339 BUF_APPEND(fmt, PRFIELD(integer->value.u));
340 }
341 #pragma GCC diagnostic pop
342 }
343
344 static inline void format_field(char **buf_ch, bool extended,
345 const char *prefix, const struct bt_field *field)
346 {
347 BUF_APPEND(", %sis-set=%d", PRFIELD(field->is_set));
348
349 if (extended) {
350 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen));
351 }
352
353 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field->class));
354
355 if (!field->class) {
356 return;
357 }
358
359 BUF_APPEND(", %sclass-type=%s",
360 PRFIELD(bt_common_field_class_type_string(field->class->type)));
361
362 if (!extended || !field->is_set) {
363 return;
364 }
365
366 switch (field->class->type) {
367 case BT_FIELD_CLASS_TYPE_BOOL:
368 {
369 const struct bt_field_bool *bool_field = (const void *) field;
370
371 BUF_APPEND(", %svalue=%d", PRFIELD(bool_field->value));
372 break;
373 }
374 case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
375 {
376 const struct bt_field_bit_array *ba_field = (const void *) field;
377
378 BUF_APPEND(", %svalue-as-int=%" PRIx64,
379 PRFIELD(ba_field->value_as_int));
380 break;
381 }
382 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
383 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
384 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
385 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
386 {
387 format_field_integer_extended(buf_ch, prefix, field);
388 break;
389 }
390 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
391 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
392 {
393 const struct bt_field_real *real_field = (const void *) field;
394
395 BUF_APPEND(", %svalue=%f", PRFIELD(real_field->value));
396 break;
397 }
398 case BT_FIELD_CLASS_TYPE_STRING:
399 {
400 const struct bt_field_string *str = (const void *) field;
401
402 if (str->buf) {
403 BT_ASSERT(str->buf->data);
404 BUF_APPEND(", %spartial-value=\"%.32s\"",
405 PRFIELD(str->buf->data));
406 }
407
408 break;
409 }
410 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
411 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD:
412 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD:
413 {
414 const struct bt_field_array *array_field = (const void *) field;
415
416 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_field->length));
417
418 if (array_field->fields) {
419 BUF_APPEND(", %sallocated-length=%u",
420 PRFIELD(array_field->fields->len));
421 }
422
423 break;
424 }
425 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD:
426 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
427 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
428 {
429 const struct bt_field_variant *var_field = (const void *) field;
430
431 BUF_APPEND(", %sselected-field-index=%" PRIu64,
432 PRFIELD(var_field->selected_index));
433 break;
434 }
435 default:
436 break;
437 }
438 }
439
440 static inline void format_field_path(char **buf_ch, bool extended,
441 const char *prefix, const struct bt_field_path *field_path)
442 {
443 uint64_t i;
444
445 if (field_path->items) {
446 BT_ASSERT(field_path->items);
447 BUF_APPEND(", %sitem-count=%u",
448 PRFIELD(field_path->items->len));
449 }
450
451 if (!extended || !field_path->items) {
452 return;
453 }
454
455 BUF_APPEND(", %spath=[%s",
456 PRFIELD(bt_common_scope_string(field_path->root)));
457
458 for (i = 0; i < bt_field_path_get_item_count(field_path); i++) {
459 const struct bt_field_path_item *fp_item =
460 bt_field_path_borrow_item_by_index_const(field_path, i);
461
462 switch (bt_field_path_item_get_type(fp_item)) {
463 case BT_FIELD_PATH_ITEM_TYPE_INDEX:
464 BUF_APPEND(", %" PRIu64,
465 bt_field_path_item_index_get_index(fp_item));
466 break;
467 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT:
468 BUF_APPEND("%s", ", <CUR>");
469 break;
470 default:
471 bt_common_abort();
472 }
473 }
474
475 BUF_APPEND("%s", "]");
476 }
477
478 static inline void format_trace_class(char **buf_ch, bool extended,
479 const char *prefix, const struct bt_trace_class *trace_class)
480 {
481 if (!extended) {
482 return;
483 }
484
485 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen));
486
487 if (trace_class->stream_classes) {
488 BUF_APPEND(", %sstream-class-count=%u",
489 PRFIELD(trace_class->stream_classes->len));
490 }
491
492 BUF_APPEND(", %sassigns-auto-sc-id=%d",
493 PRFIELD(trace_class->assigns_automatic_stream_class_id));
494 }
495
496 static inline void format_trace(char **buf_ch, bool extended,
497 const char *prefix, const struct bt_trace *trace)
498 {
499 char tmp_prefix[TMP_PREFIX_LEN];
500
501 if (trace->name.value) {
502 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value));
503 }
504
505 if (!extended) {
506 return;
507 }
508
509 if (trace->uuid.value) {
510 BUF_APPEND_UUID(trace->uuid.value);
511 }
512
513 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
514
515 if (trace->streams) {
516 BUF_APPEND(", %sstream-count=%u",
517 PRFIELD(trace->streams->len));
518 }
519
520 if (!trace->class) {
521 return;
522 }
523
524 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace->class));
525 SET_TMP_PREFIX("trace-class-");
526 format_trace_class(buf_ch, false, tmp_prefix, trace->class);
527 }
528
529 static inline void format_stream_class(char **buf_ch, bool extended,
530 const char *prefix,
531 const struct bt_stream_class *stream_class)
532 {
533 const struct bt_trace_class *trace_class;
534 char tmp_prefix[TMP_PREFIX_LEN];
535
536 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id));
537
538 if (stream_class->name.value) {
539 BUF_APPEND(", %sname=\"%s\"",
540 PRFIELD(stream_class->name.value));
541 }
542
543 if (!extended) {
544 return;
545 }
546
547 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen));
548
549 if (stream_class->event_classes) {
550 BUF_APPEND(", %sevent-class-count=%u",
551 PRFIELD(stream_class->event_classes->len));
552 }
553
554 BUF_APPEND(", %spacket-context-fc-addr=%p, "
555 "%sevent-common-context-fc-addr=%p",
556 PRFIELD(stream_class->packet_context_fc),
557 PRFIELD(stream_class->event_common_context_fc));
558 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
559 if (!trace_class) {
560 return;
561 }
562
563 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
564 "%ssupports-packets=%d, "
565 "%spackets-have-begin-default-cs=%d, "
566 "%spackets-have-end-default-cs=%d, "
567 "%ssupports-discarded-events=%d, "
568 "%sdiscarded-events-have-default-cs=%d, "
569 "%ssupports-discarded-packets=%d, "
570 "%sdiscarded-packets-have-default-cs=%d",
571 PRFIELD(stream_class->assigns_automatic_event_class_id),
572 PRFIELD(stream_class->assigns_automatic_stream_id),
573 PRFIELD(stream_class->supports_packets),
574 PRFIELD(stream_class->packets_have_beginning_default_clock_snapshot),
575 PRFIELD(stream_class->packets_have_end_default_clock_snapshot),
576 PRFIELD(stream_class->supports_discarded_events),
577 PRFIELD(stream_class->discarded_events_have_default_clock_snapshots),
578 PRFIELD(stream_class->supports_discarded_packets),
579 PRFIELD(stream_class->discarded_packets_have_default_clock_snapshots));
580 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
581 SET_TMP_PREFIX("trace-class-");
582 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
583 SET_TMP_PREFIX("pcf-pool-");
584 format_object_pool(buf_ch, tmp_prefix,
585 &stream_class->packet_context_field_pool);
586 }
587
588 static inline void format_event_class(char **buf_ch, bool extended,
589 const char *prefix, const struct bt_event_class *event_class)
590 {
591 const struct bt_stream_class *stream_class;
592 const struct bt_trace_class *trace_class;
593 char tmp_prefix[TMP_PREFIX_LEN];
594
595 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id));
596
597 if (event_class->name.value) {
598 BUF_APPEND(", %sname=\"%s\"",
599 PRFIELD(event_class->name.value));
600 }
601
602 if (!extended) {
603 return;
604 }
605
606 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class->frozen));
607
608 if (event_class->log_level.base.avail) {
609 BUF_APPEND(", %slog-level=%s",
610 PRFIELD(bt_common_event_class_log_level_string(
611 (int) event_class->log_level.value)));
612 }
613
614 if (event_class->emf_uri.value) {
615 BUF_APPEND(", %semf-uri=\"%s\"",
616 PRFIELD(event_class->emf_uri.value));
617 }
618
619 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
620 PRFIELD(event_class->specific_context_fc),
621 PRFIELD(event_class->payload_fc));
622
623 stream_class = bt_event_class_borrow_stream_class_const(event_class);
624 if (!stream_class) {
625 return;
626 }
627
628 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
629 SET_TMP_PREFIX("stream-class-");
630 format_stream_class(buf_ch, false, tmp_prefix, stream_class);
631 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
632 if (!trace_class) {
633 return;
634 }
635
636 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
637 SET_TMP_PREFIX("trace-class-");
638 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
639 SET_TMP_PREFIX("event-pool-");
640 format_object_pool(buf_ch, tmp_prefix, &event_class->event_pool);
641 }
642
643 static inline void format_stream(char **buf_ch, bool extended,
644 const char *prefix, const struct bt_stream *stream)
645 {
646 const struct bt_stream_class *stream_class;
647 const struct bt_trace_class *trace_class = NULL;
648 const struct bt_trace *trace = NULL;
649 char tmp_prefix[TMP_PREFIX_LEN];
650
651 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id));
652
653 if (stream->name.value) {
654 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value));
655 }
656
657 if (!extended) {
658 return;
659 }
660
661 stream_class = bt_stream_borrow_class_const(stream);
662 if (stream_class) {
663 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
664 SET_TMP_PREFIX("stream-class-");
665 format_stream_class(buf_ch, false, tmp_prefix, stream_class);
666 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
667 }
668
669 if (trace_class) {
670 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
671 SET_TMP_PREFIX("trace-class-");
672 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
673 }
674
675 trace = bt_stream_borrow_trace_inline(stream);
676 if (trace) {
677 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
678 SET_TMP_PREFIX("trace-");
679 format_trace(buf_ch, false, tmp_prefix, trace);
680 }
681
682 SET_TMP_PREFIX("packet-pool-");
683 format_object_pool(buf_ch, tmp_prefix, &stream->packet_pool);
684 }
685
686 static inline void format_packet(char **buf_ch, bool extended,
687 const char *prefix, const struct bt_packet *packet)
688 {
689 const struct bt_stream *stream;
690 const struct bt_trace_class *trace_class;
691 char tmp_prefix[TMP_PREFIX_LEN];
692
693 if (!extended) {
694 return;
695 }
696
697 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
698 PRFIELD(packet->frozen),
699 PRFIELD(packet->context_field ? packet->context_field->field : NULL));
700 stream = bt_packet_borrow_stream_const(packet);
701 if (!stream) {
702 return;
703 }
704
705 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
706 SET_TMP_PREFIX("stream-");
707 format_stream(buf_ch, false, tmp_prefix, stream);
708 trace_class = (const struct bt_trace_class *) bt_object_borrow_parent(&stream->base);
709 if (!trace_class) {
710 return;
711 }
712
713 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
714 SET_TMP_PREFIX("trace-class-");
715 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
716 }
717
718 static inline void format_event(char **buf_ch, bool extended,
719 const char *prefix, const struct bt_event *event)
720 {
721 const struct bt_trace_class *trace_class;
722 const struct bt_stream_class *stream_class;
723 char tmp_prefix[TMP_PREFIX_LEN];
724
725 if (!extended) {
726 return;
727 }
728
729 BUF_APPEND(", %sis-frozen=%d, "
730 "%scommon-context-field-addr=%p, "
731 "%sspecific-context-field-addr=%p, "
732 "%spayload-field-addr=%p, ",
733 PRFIELD(event->frozen),
734 PRFIELD(event->common_context_field),
735 PRFIELD(event->specific_context_field),
736 PRFIELD(event->payload_field));
737 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->class));
738
739 if (!event->class) {
740 return;
741 }
742
743 SET_TMP_PREFIX("event-class-");
744 format_event_class(buf_ch, false, tmp_prefix, event->class);
745 stream_class = bt_event_class_borrow_stream_class(event->class);
746 if (stream_class) {
747 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
748 SET_TMP_PREFIX("stream-class-");
749 format_stream_class(buf_ch, false, tmp_prefix,
750 stream_class);
751
752 trace_class = bt_stream_class_borrow_trace_class_inline(
753 stream_class);
754 if (trace_class) {
755 BUF_APPEND(", %strace-class-addr=%p",
756 PRFIELD(trace_class));
757 SET_TMP_PREFIX("trace-class-");
758 format_trace_class(buf_ch, false, tmp_prefix,
759 trace_class);
760 }
761 }
762
763 if (event->stream) {
764 BUF_APPEND(", %sstream-addr=%p", PRFIELD(event->stream));
765 SET_TMP_PREFIX("stream-");
766 format_stream(buf_ch, false, tmp_prefix, event->stream);
767 }
768
769 if (event->packet) {
770 BUF_APPEND(", %spacket-addr=%p", PRFIELD(event->packet));
771 SET_TMP_PREFIX("packet-");
772 format_packet(buf_ch, false, tmp_prefix, event->packet);
773 }
774 }
775
776 static inline void format_clock_class(char **buf_ch, bool extended,
777 const char *prefix, const struct bt_clock_class *clock_class)
778 {
779 char tmp_prefix[TMP_PREFIX_LEN];
780
781 if (clock_class->name.value) {
782 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value));
783 }
784
785 BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency));
786
787 if (!extended) {
788 return;
789 }
790
791 if (clock_class->description.value) {
792 BUF_APPEND(", %spartial-descr=\"%.32s\"",
793 PRFIELD(clock_class->description.value));
794 }
795
796 if (clock_class->uuid.value) {
797 BUF_APPEND_UUID(clock_class->uuid.value);
798 }
799
800 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", "
801 "%soffset-s=%" PRId64 ", "
802 "%soffset-cycles=%" PRIu64 ", %sorigin-is-unix-epoch=%d, "
803 "%sbase-offset-ns=%" PRId64,
804 PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision),
805 PRFIELD(clock_class->offset_seconds),
806 PRFIELD(clock_class->offset_cycles),
807 PRFIELD(clock_class->origin_is_unix_epoch),
808 PRFIELD(clock_class->base_offset.value_ns));
809
810 SET_TMP_PREFIX("cs-pool-");
811 format_object_pool(buf_ch, tmp_prefix, &clock_class->cs_pool);
812 }
813
814 static inline void format_clock_snapshot(char **buf_ch, bool extended,
815 const char *prefix, const struct bt_clock_snapshot *clock_snapshot)
816 {
817 char tmp_prefix[TMP_PREFIX_LEN];
818 BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64,
819 PRFIELD(clock_snapshot->value_cycles),
820 PRFIELD(clock_snapshot->ns_from_origin));
821
822 if (!extended) {
823 return;
824 }
825
826 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot->is_set));
827
828 if (clock_snapshot->clock_class) {
829 BUF_APPEND(", %sclock-class-addr=%p",
830 PRFIELD(clock_snapshot->clock_class));
831 SET_TMP_PREFIX("clock-class-");
832 format_clock_class(buf_ch, false, tmp_prefix,
833 clock_snapshot->clock_class);
834 }
835 }
836
837 static inline void format_interrupter(char **buf_ch, const char *prefix,
838 const struct bt_interrupter *intr)
839 {
840 BUF_APPEND(", %sis-set=%d", PRFIELD(intr->is_set));
841 }
842
843 static inline void format_value(char **buf_ch, bool extended,
844 const char *prefix, const struct bt_value *value)
845 {
846 BUF_APPEND(", %stype=%s",
847 PRFIELD(bt_common_value_type_string(bt_value_get_type(value))));
848
849 if (!extended) {
850 return;
851 }
852
853 switch (bt_value_get_type(value)) {
854 case BT_VALUE_TYPE_BOOL:
855 {
856 bt_bool val = bt_value_bool_get(value);
857
858 BUF_APPEND(", %svalue=%d", PRFIELD(val));
859 break;
860 }
861 case BT_VALUE_TYPE_UNSIGNED_INTEGER:
862 {
863 BUF_APPEND(", %svalue=%" PRIu64,
864 PRFIELD(bt_value_integer_unsigned_get(value)));
865 break;
866 }
867 case BT_VALUE_TYPE_SIGNED_INTEGER:
868 {
869 BUF_APPEND(", %svalue=%" PRId64,
870 PRFIELD(bt_value_integer_signed_get(value)));
871 break;
872 }
873 case BT_VALUE_TYPE_REAL:
874 {
875 double val = bt_value_real_get(value);
876
877 BUF_APPEND(", %svalue=%f", PRFIELD(val));
878 break;
879 }
880 case BT_VALUE_TYPE_STRING:
881 {
882 const char *val = bt_value_string_get(value);
883
884 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val));
885 break;
886 }
887 case BT_VALUE_TYPE_ARRAY:
888 {
889 uint64_t count = bt_value_array_get_length(value);
890
891 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
892 break;
893 }
894 case BT_VALUE_TYPE_MAP:
895 {
896 int64_t count = bt_value_map_get_size(value);
897
898 BT_ASSERT(count >= 0);
899 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
900 break;
901 }
902 default:
903 break;
904 }
905 }
906
907 static inline void format_integer_range_set(char **buf_ch, bool extended,
908 const char *prefix,
909 const struct bt_integer_range_set *range_set)
910 {
911 BUF_APPEND(", %srange-count=%u", PRFIELD(range_set->ranges->len));
912
913 if (!extended) {
914 return;
915 }
916
917 BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set->frozen));
918 }
919
920 static inline void format_message(char **buf_ch, bool extended,
921 const char *prefix, const struct bt_message *msg)
922 {
923 char tmp_prefix[TMP_PREFIX_LEN];
924
925 BUF_APPEND(", %stype=%s",
926 PRFIELD(bt_common_message_type_string(msg->type)));
927
928 if (!extended) {
929 return;
930 }
931
932 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
933 PRFIELD(msg->frozen), PRFIELD(msg->graph));
934
935 switch (msg->type) {
936 case BT_MESSAGE_TYPE_EVENT:
937 {
938 const struct bt_message_event *msg_event =
939 (const void *) msg;
940
941 if (msg_event->event) {
942 SET_TMP_PREFIX("event-");
943 format_event(buf_ch, true, tmp_prefix,
944 msg_event->event);
945 }
946
947 if (msg_event->default_cs) {
948 SET_TMP_PREFIX("default-cs-");
949 format_clock_snapshot(buf_ch, true, tmp_prefix,
950 msg_event->default_cs);
951 }
952
953 break;
954 }
955 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
956 case BT_MESSAGE_TYPE_STREAM_END:
957 {
958 const struct bt_message_stream *msg_stream = (const void *) msg;
959
960 if (msg_stream->stream) {
961 SET_TMP_PREFIX("stream-");
962 format_stream(buf_ch, true, tmp_prefix,
963 msg_stream->stream);
964 }
965
966 BUF_APPEND(", %sdefault-cs-state=%s",
967 PRFIELD(bt_message_stream_clock_snapshot_state_string(
968 msg_stream->default_cs_state)));
969
970 if (msg_stream->default_cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
971 SET_TMP_PREFIX("default-cs-");
972 format_clock_snapshot(buf_ch, true, tmp_prefix,
973 msg_stream->default_cs);
974 }
975
976 break;
977 }
978 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
979 case BT_MESSAGE_TYPE_PACKET_END:
980 {
981 const struct bt_message_packet *msg_packet = (const void *) msg;
982
983 if (msg_packet->packet) {
984 SET_TMP_PREFIX("packet-");
985 format_packet(buf_ch, true, tmp_prefix,
986 msg_packet->packet);
987 }
988
989 if (msg_packet->default_cs) {
990 SET_TMP_PREFIX("default-cs-");
991 format_clock_snapshot(buf_ch, true, tmp_prefix,
992 msg_packet->default_cs);
993 }
994
995 break;
996 }
997 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
998 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
999 {
1000 const struct bt_message_discarded_items *msg_disc_items =
1001 (const void *) msg;
1002
1003 if (msg_disc_items->stream) {
1004 SET_TMP_PREFIX("stream-");
1005 format_stream(buf_ch, true, tmp_prefix,
1006 msg_disc_items->stream);
1007 }
1008
1009 if (msg_disc_items->default_begin_cs) {
1010 SET_TMP_PREFIX("begin-default-cs-");
1011 format_clock_snapshot(buf_ch, true, tmp_prefix,
1012 msg_disc_items->default_begin_cs);
1013 }
1014
1015 if (msg_disc_items->default_end_cs) {
1016 SET_TMP_PREFIX("end-default-cs-");
1017 format_clock_snapshot(buf_ch, true, tmp_prefix,
1018 msg_disc_items->default_end_cs);
1019 }
1020
1021 if (msg_disc_items->count.base.avail) {
1022 BUF_APPEND(", %scount=%" PRIu64,
1023 PRFIELD(msg_disc_items->count.value));
1024 }
1025
1026 break;
1027 }
1028 default:
1029 break;
1030 }
1031 }
1032
1033 static inline void format_plugin_so_shared_lib_handle(char **buf_ch,
1034 const char *prefix,
1035 const struct bt_plugin_so_shared_lib_handle *handle)
1036 {
1037 BUF_APPEND(", %saddr=%p", PRFIELD(handle));
1038
1039 if (handle->path) {
1040 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle->path));
1041 }
1042 }
1043
1044 static inline void format_component_class(char **buf_ch, bool extended,
1045 const char *prefix,
1046 const struct bt_component_class *comp_class)
1047 {
1048 char tmp_prefix[TMP_PREFIX_LEN];
1049
1050 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1051 PRFIELD(bt_common_component_class_type_string(comp_class->type)),
1052 PRFIELD_GSTRING(comp_class->name));
1053
1054 if (comp_class->description) {
1055 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1056 PRFIELD_GSTRING(comp_class->description));
1057 }
1058
1059 if (!extended) {
1060 return;
1061 }
1062
1063 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen));
1064
1065 if (comp_class->so_handle) {
1066 SET_TMP_PREFIX("so-handle-");
1067 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1068 comp_class->so_handle);
1069 }
1070 }
1071
1072 static inline void format_component(char **buf_ch, bool extended,
1073 const char *prefix, const struct bt_component *component)
1074 {
1075 char tmp_prefix[TMP_PREFIX_LEN];
1076
1077 BUF_APPEND(", %sname=\"%s\", %slog-level=%s",
1078 PRFIELD_GSTRING(component->name),
1079 PRFIELD(bt_common_logging_level_string(component->log_level)));
1080
1081 if (component->class) {
1082 SET_TMP_PREFIX("class-");
1083 format_component_class(buf_ch, extended, tmp_prefix,
1084 component->class);
1085 }
1086
1087 if (!extended) {
1088 return;
1089 }
1090
1091 if (component->input_ports) {
1092 BUF_APPEND(", %sinput-port-count=%u",
1093 PRFIELD(component->input_ports->len));
1094 }
1095
1096 if (component->output_ports) {
1097 BUF_APPEND(", %soutput-port-count=%u",
1098 PRFIELD(component->output_ports->len));
1099 }
1100 }
1101
1102 static inline void format_port(char **buf_ch, bool extended,
1103 const char *prefix, const struct bt_port *port)
1104 {
1105 char tmp_prefix[TMP_PREFIX_LEN];
1106
1107 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1108 PRFIELD(bt_port_type_string(port->type)),
1109 PRFIELD_GSTRING(port->name));
1110
1111 if (!extended) {
1112 return;
1113 }
1114
1115 if (port->connection) {
1116 SET_TMP_PREFIX("conn-");
1117 format_connection(buf_ch, false, tmp_prefix, port->connection);
1118 }
1119 }
1120
1121 static inline void format_connection(char **buf_ch, bool extended,
1122 const char *prefix, const struct bt_connection *connection)
1123 {
1124 char tmp_prefix[TMP_PREFIX_LEN];
1125
1126 if (!extended) {
1127 return;
1128 }
1129
1130 if (connection->upstream_port) {
1131 SET_TMP_PREFIX("upstream-port-");
1132 format_port(buf_ch, false, tmp_prefix,
1133 connection->upstream_port);
1134 }
1135
1136 if (connection->downstream_port) {
1137 SET_TMP_PREFIX("downstream-port-");
1138 format_port(buf_ch, false, tmp_prefix,
1139 connection->downstream_port);
1140 }
1141 }
1142
1143 static inline void format_graph(char **buf_ch, bool extended,
1144 const char *prefix, const struct bt_graph *graph)
1145 {
1146 char tmp_prefix[TMP_PREFIX_LEN];
1147
1148 BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
1149 PRFIELD(graph->can_consume),
1150 PRFIELD(bt_graph_configuration_state_string(graph->config_state)));
1151
1152 if (!extended) {
1153 return;
1154 }
1155
1156 if (graph->components) {
1157 BUF_APPEND(", %scomp-count=%u",
1158 PRFIELD(graph->components->len));
1159 }
1160
1161 if (graph->connections) {
1162 BUF_APPEND(", %sconn-count=%u",
1163 PRFIELD(graph->connections->len));
1164 }
1165
1166 SET_TMP_PREFIX("en-pool-");
1167 format_object_pool(buf_ch, tmp_prefix, &graph->event_msg_pool);
1168 SET_TMP_PREFIX("pbn-pool-");
1169 format_object_pool(buf_ch, tmp_prefix, &graph->packet_begin_msg_pool);
1170 SET_TMP_PREFIX("pen-pool-");
1171 format_object_pool(buf_ch, tmp_prefix, &graph->packet_end_msg_pool);
1172 }
1173
1174 static inline void format_message_iterator(char **buf_ch,
1175 bool extended, const char *prefix,
1176 const struct bt_message_iterator *iterator)
1177 {
1178 char tmp_prefix[TMP_PREFIX_LEN];
1179 const struct bt_message_iterator *
1180 port_in_iter = (const void *) iterator;
1181
1182 if (port_in_iter->upstream_component) {
1183 SET_TMP_PREFIX("upstream-comp-");
1184 format_component(buf_ch, false, tmp_prefix,
1185 port_in_iter->upstream_component);
1186 }
1187
1188 if (!extended) {
1189 goto end;
1190 }
1191
1192 if (port_in_iter->upstream_port) {
1193 SET_TMP_PREFIX("upstream-port-");
1194 format_port(buf_ch, false, tmp_prefix,
1195 port_in_iter->upstream_port);
1196 }
1197
1198 if (port_in_iter->connection) {
1199 SET_TMP_PREFIX("upstream-conn-");
1200 format_connection(buf_ch, false, tmp_prefix,
1201 port_in_iter->connection);
1202 }
1203
1204 end:
1205 return;
1206 }
1207
1208 static inline void format_plugin(char **buf_ch, bool extended,
1209 const char *prefix, const struct bt_plugin *plugin)
1210 {
1211 char tmp_prefix[TMP_PREFIX_LEN];
1212
1213 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type)));
1214
1215 if (plugin->info.path_set) {
1216 BUF_APPEND(", %spath=\"%s\"",
1217 PRFIELD_GSTRING(plugin->info.path));
1218 }
1219
1220 if (plugin->info.name_set) {
1221 BUF_APPEND(", %sname=\"%s\"",
1222 PRFIELD_GSTRING(plugin->info.name));
1223 }
1224
1225 if (!extended) {
1226 return;
1227 }
1228
1229 if (plugin->info.author_set) {
1230 BUF_APPEND(", %sauthor=\"%s\"",
1231 PRFIELD_GSTRING(plugin->info.author));
1232 }
1233
1234 if (plugin->info.license_set) {
1235 BUF_APPEND(", %slicense=\"%s\"",
1236 PRFIELD_GSTRING(plugin->info.license));
1237 }
1238
1239 if (plugin->info.version_set) {
1240 BUF_APPEND(", %sversion=%u.%u.%u%s",
1241 PRFIELD(plugin->info.version.major),
1242 plugin->info.version.minor,
1243 plugin->info.version.patch,
1244 plugin->info.version.extra ?
1245 plugin->info.version.extra->str : "");
1246 }
1247
1248 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1249 "%ssink-comp-class-count=%u",
1250 PRFIELD(plugin->src_comp_classes->len),
1251 PRFIELD(plugin->flt_comp_classes->len),
1252 PRFIELD(plugin->sink_comp_classes->len));
1253
1254 if (plugin->spec_data) {
1255 const struct bt_plugin_so_spec_data *spec_data =
1256 (const void *) plugin->spec_data;
1257
1258 if (spec_data->shared_lib_handle) {
1259 SET_TMP_PREFIX("so-handle-");
1260 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1261 spec_data->shared_lib_handle);
1262 }
1263 }
1264 }
1265
1266 static inline void format_error_cause(char **buf_ch, bool extended,
1267 const char *prefix, const struct bt_error_cause *cause)
1268 {
1269 const struct bt_error_cause_component_class_id *comp_class_id = NULL;
1270
1271 BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"",
1272 PRFIELD(bt_error_cause_actor_type_string(cause->actor_type)),
1273 PRFIELD_GSTRING(cause->module_name));
1274
1275 if (!extended) {
1276 return;
1277 }
1278
1279 BUF_APPEND(", %spartial-msg=\"%.32s\"",
1280 PRFIELD_GSTRING(cause->message));
1281
1282 switch (cause->actor_type) {
1283 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT:
1284 {
1285 const struct bt_error_cause_component_actor *spec_cause =
1286 (const void *) cause;
1287
1288 BUF_APPEND(", %scomp-name=\"%s\"",
1289 PRFIELD_GSTRING(spec_cause->comp_name));
1290 comp_class_id = &spec_cause->comp_class_id;
1291 break;
1292 }
1293 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS:
1294 {
1295 const struct bt_error_cause_component_class_actor *spec_cause =
1296 (const void *) cause;
1297
1298 comp_class_id = &spec_cause->comp_class_id;
1299 break;
1300 }
1301 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR:
1302 {
1303 const struct bt_error_cause_message_iterator_actor *spec_cause =
1304 (const void *) cause;
1305
1306 BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"",
1307 PRFIELD_GSTRING(spec_cause->comp_name),
1308 PRFIELD_GSTRING(spec_cause->output_port_name));
1309 comp_class_id = &spec_cause->comp_class_id;
1310 break;
1311 }
1312 default:
1313 break;
1314 }
1315
1316 if (comp_class_id) {
1317 BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
1318 "%splugin-name=\"%s\"",
1319 PRFIELD(bt_common_component_class_type_string(
1320 comp_class_id->type)),
1321 PRFIELD_GSTRING(comp_class_id->name),
1322 PRFIELD_GSTRING(comp_class_id->plugin_name));
1323 }
1324 }
1325
1326 static inline void handle_conversion_specifier_bt(
1327 void *priv_data __attribute__((unused)),
1328 char **buf_ch,
1329 size_t avail_size __attribute__((unused)),
1330 const char **out_fmt_ch, va_list *args)
1331 {
1332 const char *fmt_ch = *out_fmt_ch;
1333 bool extended = false;
1334 char prefix[64];
1335 char *prefix_ch = prefix;
1336 const void *obj;
1337
1338 /* skip "%!" */
1339 fmt_ch += 2;
1340
1341 if (*fmt_ch == 'u') {
1342 /* UUID */
1343 obj = va_arg(*args, void *);
1344 format_uuid(buf_ch, obj);
1345 goto update_fmt;
1346 }
1347
1348 if (*fmt_ch == '[') {
1349 /* local prefix */
1350 fmt_ch++;
1351
1352 while (true) {
1353 if (*fmt_ch == ']') {
1354 *prefix_ch = '\0';
1355 fmt_ch++;
1356 break;
1357 }
1358
1359 *prefix_ch = *fmt_ch;
1360 prefix_ch++;
1361 fmt_ch++;
1362 }
1363 }
1364
1365 *prefix_ch = '\0';
1366
1367 if (*fmt_ch == '+') {
1368 extended = true;
1369 fmt_ch++;
1370 }
1371
1372 obj = va_arg(*args, void *);
1373 BUF_APPEND("%saddr=%p", prefix, obj);
1374
1375 if (!obj) {
1376 goto update_fmt;
1377 }
1378
1379 switch (*fmt_ch) {
1380 case 'F':
1381 format_field_class(buf_ch, extended, prefix, obj);
1382 break;
1383 case 'f':
1384 format_field(buf_ch, extended, prefix, obj);
1385 break;
1386 case 'P':
1387 format_field_path(buf_ch, extended, prefix, obj);
1388 break;
1389 case 'E':
1390 format_event_class(buf_ch, extended, prefix, obj);
1391 break;
1392 case 'e':
1393 format_event(buf_ch, extended, prefix, obj);
1394 break;
1395 case 'S':
1396 format_stream_class(buf_ch, extended, prefix, obj);
1397 break;
1398 case 's':
1399 format_stream(buf_ch, extended, prefix, obj);
1400 break;
1401 case 'a':
1402 format_packet(buf_ch, extended, prefix, obj);
1403 break;
1404 case 't':
1405 format_trace(buf_ch, extended, prefix, obj);
1406 break;
1407 case 'T':
1408 format_trace_class(buf_ch, extended, prefix, obj);
1409 break;
1410 case 'K':
1411 format_clock_class(buf_ch, extended, prefix, obj);
1412 break;
1413 case 'k':
1414 format_clock_snapshot(buf_ch, extended, prefix, obj);
1415 break;
1416 case 'v':
1417 format_value(buf_ch, extended, prefix, obj);
1418 break;
1419 case 'R':
1420 format_integer_range_set(buf_ch, extended, prefix, obj);
1421 break;
1422 case 'n':
1423 format_message(buf_ch, extended, prefix, obj);
1424 break;
1425 case 'I':
1426 /* Empty, the address is automatically printed. */
1427 break;
1428 case 'i':
1429 format_message_iterator(buf_ch, extended, prefix, obj);
1430 break;
1431 case 'C':
1432 format_component_class(buf_ch, extended, prefix, obj);
1433 break;
1434 case 'c':
1435 format_component(buf_ch, extended, prefix, obj);
1436 break;
1437 case 'p':
1438 format_port(buf_ch, extended, prefix, obj);
1439 break;
1440 case 'x':
1441 format_connection(buf_ch, extended, prefix, obj);
1442 break;
1443 case 'l':
1444 format_plugin(buf_ch, extended, prefix, obj);
1445 break;
1446 case 'g':
1447 format_graph(buf_ch, extended, prefix, obj);
1448 break;
1449 case 'z':
1450 format_interrupter(buf_ch, prefix, obj);
1451 break;
1452 case 'o':
1453 format_object_pool(buf_ch, prefix, obj);
1454 break;
1455 case 'O':
1456 format_object(buf_ch, prefix, obj);
1457 break;
1458 case 'r':
1459 format_error_cause(buf_ch, extended, prefix, obj);
1460 break;
1461 default:
1462 bt_common_abort();
1463 }
1464
1465 update_fmt:
1466 fmt_ch++;
1467 *out_fmt_ch = fmt_ch;
1468 }
1469
1470 /*
1471 * This function would normally not be BT_EXPORTed, but it is used by the
1472 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1473 * implemented as a separate shared object, for modularity. It is therefore
1474 * exposed, but not part of the public ABI.
1475 */
1476 BT_EXPORT
1477 void bt_lib_log_v(const char *file, const char *func, unsigned line,
1478 int lvl, const char *tag, const char *fmt, va_list *args)
1479 {
1480 BT_ASSERT(fmt);
1481 bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!',
1482 handle_conversion_specifier_bt, NULL, fmt, args);
1483 bt_log_write(file, func, line, lvl, tag, lib_logging_buf);
1484 }
1485
1486 /*
1487 * This function would normally not be BT_EXPORTed, but it is used by the
1488 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1489 * implemented as a separate shared object, for modularity. It is therefore
1490 * exposed, but not part of the public ABI.
1491 */
1492 BT_EXPORT
1493 void bt_lib_log(const char *file, const char *func, unsigned line,
1494 int lvl, const char *tag, const char *fmt, ...)
1495 {
1496 va_list args;
1497
1498 BT_ASSERT(fmt);
1499 va_start(args, fmt);
1500 bt_lib_log_v(file, func, line, lvl, tag, fmt, &args);
1501 va_end(args);
1502 }
1503
1504 /*
1505 * This function would normally not be BT_EXPORTed, but it is used by the
1506 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1507 * implemented as a separate shared object, for modularity. It is therefore
1508 * exposed, but not part of the ABI.
1509 */
1510 BT_EXPORT
1511 void bt_lib_maybe_log_and_append_cause(const char *func, const char *file,
1512 unsigned line, int lvl, const char *tag,
1513 const char *fmt, ...)
1514 {
1515 va_list args;
1516 bt_current_thread_error_append_cause_status status;
1517
1518 BT_ASSERT(fmt);
1519 va_start(args, fmt);
1520 bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!',
1521 handle_conversion_specifier_bt, NULL, fmt, &args);
1522 va_end(args);
1523
1524 /* Log conditionally, but always append the error cause */
1525 if (BT_LOG_ON(lvl)) {
1526 bt_log_write(file, func, line, lvl, tag, lib_logging_buf);
1527 }
1528
1529 status = bt_current_thread_error_append_cause_from_unknown(
1530 BT_LIB_LOG_LIBBABELTRACE2_NAME, file, line, "%s",
1531 lib_logging_buf);
1532 if (status) {
1533 /*
1534 * Worst case: this error cause is not appended to the
1535 * current thread's error.
1536 *
1537 * We can accept this as it's an almost impossible
1538 * scenario and returning an error here would mean you
1539 * need to check the return value of each
1540 * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be
1541 * cumbersome.
1542 */
1543 BT_LOGE("Cannot append error cause to current thread's "
1544 "error object: status=%s",
1545 bt_common_func_status_string(status));
1546 }
1547 }
This page took 0.061667 seconds and 4 git commands to generate.