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