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