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