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