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