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