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