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