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