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