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