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