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