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