X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Flib-logging.c;h=8766e4463ef2058f2d30ee1339a7d3a5f9a672d6;hb=6375b9429f8332f3eacc2ec795aa1924c73d9cc8;hp=ce69b30ddefb301353f5ed5d4629a01a46456517;hpb=1094efa4f2edbf019427bf0322dab3f3ea9ec5ab;p=babeltrace.git diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index ce69b30d..8766e446 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -1,23 +1,7 @@ /* - * Copyright 2018 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * SPDX-License-Identifier: MIT * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright 2018 Philippe Proulx */ #define BT_LOG_TAG "LIB/LIB-LOGGING" @@ -28,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -36,8 +21,7 @@ #include #include "logging.h" -#include "assert-pre.h" -#include "assert-post.h" +#include "assert-cond.h" #include "value.h" #include "integer-range-set.h" #include "object-pool.h" @@ -73,7 +57,6 @@ #include "trace-ir/trace.h" #include "trace-ir/utils.h" #include "error.h" -#include "assert-pre.h" #define LIB_LOGGING_BUF_SIZE (4096 * 4) @@ -110,7 +93,7 @@ static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE]; prefix, (_prefix2)); \ \ if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \ - abort(); \ + bt_common_abort(); \ } \ \ tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \ @@ -207,14 +190,6 @@ static inline void format_field_class(char **buf_ch, bool extended, format_integer_field_class(buf_ch, extended, prefix, field_class); break; } - case BT_FIELD_CLASS_TYPE_REAL: - { - const struct bt_field_class_real *real_fc = (void *) field_class; - - BUF_APPEND(", %sis-single-precision=%d", - PRFIELD(real_fc->is_single_precision)); - break; - } case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: { @@ -247,7 +222,8 @@ static inline void format_field_class(char **buf_ch, bool extended, BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length)); break; } - case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: { const struct bt_field_class_array_dynamic *array_fc = (const void *) field_class; @@ -268,7 +244,10 @@ static inline void format_field_class(char **buf_ch, bool extended, break; } - case BT_FIELD_CLASS_TYPE_OPTION: + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD: { const struct bt_field_class_option *opt_fc = (const void *) field_class; @@ -277,23 +256,29 @@ static inline void format_field_class(char **buf_ch, bool extended, PRFIELD(opt_fc->content_fc), PRFIELD(bt_common_field_class_type_string(opt_fc->content_fc->type))); - if (opt_fc->selector_fc) { - SET_TMP_PREFIX("selector-fc-"); - format_field_class(buf_ch, extended, tmp_prefix, - opt_fc->selector_fc); - } + if (field_class->type != + BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) { + const struct bt_field_class_option_with_selector_field *opt_with_sel_fc = + (const void *) field_class; - if (opt_fc->selector_field_path) { - SET_TMP_PREFIX("selector-field-path-"); - format_field_path(buf_ch, extended, tmp_prefix, - opt_fc->selector_field_path); + if (opt_with_sel_fc->selector_fc) { + SET_TMP_PREFIX("selector-fc-"); + format_field_class(buf_ch, extended, tmp_prefix, + opt_with_sel_fc->selector_fc); + } + + if (opt_with_sel_fc->selector_field_path) { + SET_TMP_PREFIX("selector-field-path-"); + format_field_path(buf_ch, extended, tmp_prefix, + opt_with_sel_fc->selector_field_path); + } } break; } - case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: { const struct bt_field_class_variant *var_fc = (const void *) field_class; @@ -303,9 +288,9 @@ static inline void format_field_class(char **buf_ch, bool extended, PRFIELD(var_fc->common.named_fcs->len)); } - if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR || - field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) { - const struct bt_field_class_variant_with_selector *var_with_sel_fc = + if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || + field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) { + const struct bt_field_class_variant_with_selector_field *var_with_sel_fc = (const void *) var_fc; if (var_with_sel_fc->selector_fc) { @@ -344,6 +329,8 @@ static inline void format_field_integer_extended(char **buf_ch, fmt = ", %svalue=%" PRIx64; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { if (!fmt) { @@ -358,6 +345,7 @@ static inline void format_field_integer_extended(char **buf_ch, BUF_APPEND(fmt, PRFIELD(integer->value.u)); } +#pragma GCC diagnostic pop } static inline void format_field(char **buf_ch, bool extended, @@ -406,7 +394,8 @@ static inline void format_field(char **buf_ch, bool extended, format_field_integer_extended(buf_ch, prefix, field); break; } - case BT_FIELD_CLASS_TYPE_REAL: + case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: + case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: { const struct bt_field_real *real_field = (const void *) field; @@ -426,7 +415,8 @@ static inline void format_field(char **buf_ch, bool extended, break; } case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: - case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: { const struct bt_field_array *array_field = (const void *) field; @@ -439,9 +429,9 @@ static inline void format_field(char **buf_ch, bool extended, break; } - case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: - case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: { const struct bt_field_variant *var_field = (const void *) field; @@ -485,7 +475,7 @@ static inline void format_field_path(char **buf_ch, bool extended, BUF_APPEND("%s", ", "); break; default: - abort(); + bt_common_abort(); } } @@ -905,9 +895,8 @@ static inline void format_value(char **buf_ch, bool extended, } case BT_VALUE_TYPE_ARRAY: { - int64_t count = bt_value_array_get_size(value); + uint64_t count = bt_value_array_get_length(value); - BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); break; } @@ -1068,7 +1057,7 @@ static inline void format_component_class(char **buf_ch, bool extended, char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s, %sname=\"%s\"", - PRFIELD(bt_component_class_type_string(comp_class->type)), + PRFIELD(bt_common_component_class_type_string(comp_class->type)), PRFIELD_GSTRING(comp_class->name)); if (comp_class->description) { @@ -1194,12 +1183,19 @@ static inline void format_graph(char **buf_ch, bool extended, &graph->packet_end_msg_pool); } +static inline void format_message_iterator_class(char **buf_ch, + bool extended, const char *prefix, + const struct bt_message_iterator_class *iterator_class) +{ + /* Empty, the address is automatically printed. */ +} + static inline void format_message_iterator(char **buf_ch, bool extended, const char *prefix, const struct bt_message_iterator *iterator) { char tmp_prefix[TMP_PREFIX_LEN]; - const struct bt_self_component_port_input_message_iterator * + const struct bt_message_iterator * port_in_iter = (const void *) iterator; if (port_in_iter->upstream_component) { @@ -1339,7 +1335,7 @@ static inline void format_error_cause(char **buf_ch, bool extended, if (comp_class_id) { BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", " "%splugin-name=\"%s\"", - PRFIELD(bt_component_class_type_string( + PRFIELD(bt_common_component_class_type_string( comp_class_id->type)), PRFIELD_GSTRING(comp_class_id->name), PRFIELD_GSTRING(comp_class_id->plugin_name)); @@ -1443,6 +1439,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 'n': format_message(buf_ch, extended, prefix, obj); break; + case 'I': + format_message_iterator_class(buf_ch, extended, prefix, obj); + break; case 'i': format_message_iterator(buf_ch, extended, prefix, obj); break; @@ -1477,7 +1476,7 @@ static inline void handle_conversion_specifier_bt(void *priv_data, format_error_cause(buf_ch, extended, prefix, obj); break; default: - abort(); + bt_common_abort(); } update_fmt: @@ -1485,6 +1484,15 @@ update_fmt: *out_fmt_ch = fmt_ch; } +void bt_lib_log_v(const char *func, const char *file, unsigned line, + int lvl, const char *tag, const char *fmt, va_list *args) +{ + BT_ASSERT(fmt); + bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', + handle_conversion_specifier_bt, NULL, fmt, args); + _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); +} + void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...) { @@ -1492,10 +1500,8 @@ void bt_lib_log(const char *func, const char *file, unsigned line, BT_ASSERT(fmt); va_start(args, fmt); - bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', - handle_conversion_specifier_bt, NULL, fmt, &args); + bt_lib_log_v(func, file, line, lvl, tag, fmt, &args); va_end(args); - _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); } void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, @@ -1518,7 +1524,8 @@ void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, } status = bt_current_thread_error_append_cause_from_unknown( - "Babeltrace library", file, line, "%s", lib_logging_buf); + BT_LIB_LOG_LIBBABELTRACE2_NAME, file, line, "%s", + lib_logging_buf); if (status) { /* * Worst case: this error cause is not appended to the