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