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