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