/*
- * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
- *
- * 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 <pproulx@efficios.com>
*/
#define BT_LOG_TAG "LIB/LIB-LOGGING"
#include <babeltrace2/babeltrace.h>
#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"
#include "trace-ir/trace.h"
#include "trace-ir/utils.h"
#include "error.h"
-#include "assert-pre.h"
#define LIB_LOGGING_BUF_SIZE (4096 * 4)
prefix, (_prefix2)); \
\
if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
- abort(); \
+ bt_common_abort(); \
} \
\
tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \
static inline void format_field_path(char **buf_ch, bool extended,
const char *prefix, const struct bt_field_path *field_path);
-static inline void format_object(char **buf_ch, bool extended,
- const char *prefix, const struct bt_object *obj)
+static inline void format_object(char **buf_ch, const char *prefix,
+ const struct bt_object *obj)
{
BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count);
}
BUF_APPEND("\"" BT_UUID_FMT "\"", BT_UUID_FMT_VALUES(uuid));
}
-static inline void format_object_pool(char **buf_ch, bool extended,
- const char *prefix, const struct bt_object_pool *pool)
+static inline void format_object_pool(char **buf_ch, const char *prefix,
+ const struct bt_object_pool *pool)
{
BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size));
}
}
-static inline void format_integer_field_class(char **buf_ch,
- bool extended, const char *prefix,
+static inline void format_integer_field_class(char **buf_ch, const char *prefix,
const struct bt_field_class *field_class)
{
const struct bt_field_class_integer *int_fc =
PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base)));
}
-static inline void format_array_field_class(char **buf_ch,
- bool extended, const char *prefix,
+static inline void format_array_field_class(char **buf_ch, const char *prefix,
const struct bt_field_class *field_class)
{
const struct bt_field_class_array *array_fc =
case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
{
- format_integer_field_class(buf_ch, extended, prefix, field_class);
+ format_integer_field_class(buf_ch, prefix, field_class);
break;
}
case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
const struct bt_field_class_enumeration *enum_fc =
(const void *) field_class;
- format_integer_field_class(buf_ch, extended, prefix, field_class);
+ format_integer_field_class(buf_ch, prefix, field_class);
BUF_APPEND(", %smapping-count=%u",
PRFIELD(enum_fc->mappings->len));
break;
const struct bt_field_class_array_static *array_fc =
(const void *) field_class;
- format_array_field_class(buf_ch, extended, prefix, field_class);
+ format_array_field_class(buf_ch, prefix, field_class);
BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length));
break;
}
const struct bt_field_class_array_dynamic *array_fc =
(const void *) field_class;
- format_array_field_class(buf_ch, extended, prefix, field_class);
+ format_array_field_class(buf_ch, prefix, field_class);
if (array_fc->length_fc) {
SET_TMP_PREFIX("length-fc-");
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) {
BUF_APPEND(fmt, PRFIELD(integer->value.u));
}
+#pragma GCC diagnostic pop
}
static inline void format_field(char **buf_ch, bool extended,
BUF_APPEND("%s", ", <CUR>");
break;
default:
- abort();
+ bt_common_abort();
}
}
SET_TMP_PREFIX("trace-class-");
format_trace_class(buf_ch, false, tmp_prefix, trace_class);
SET_TMP_PREFIX("pcf-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
+ format_object_pool(buf_ch, tmp_prefix,
&stream_class->packet_context_field_pool);
}
SET_TMP_PREFIX("trace-class-");
format_trace_class(buf_ch, false, tmp_prefix, trace_class);
SET_TMP_PREFIX("event-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
- &event_class->event_pool);
+ format_object_pool(buf_ch, tmp_prefix, &event_class->event_pool);
}
static inline void format_stream(char **buf_ch, bool extended,
}
SET_TMP_PREFIX("packet-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix, &stream->packet_pool);
+ format_object_pool(buf_ch, tmp_prefix, &stream->packet_pool);
}
static inline void format_packet(char **buf_ch, bool extended,
PRFIELD(clock_class->base_offset.value_ns));
SET_TMP_PREFIX("cs-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
- &clock_class->cs_pool);
+ format_object_pool(buf_ch, tmp_prefix, &clock_class->cs_pool);
}
static inline void format_clock_snapshot(char **buf_ch, bool extended,
}
}
-static inline void format_interrupter(char **buf_ch, bool extended,
- const char *prefix, const struct bt_interrupter *intr)
+static inline void format_interrupter(char **buf_ch, const char *prefix,
+ const struct bt_interrupter *intr)
{
BUF_APPEND(", %sis-set=%d", PRFIELD(intr->is_set));
}
char tmp_prefix[TMP_PREFIX_LEN];
BUF_APPEND(", %stype=%s",
- PRFIELD(bt_message_type_string(msg->type)));
+ PRFIELD(bt_common_message_type_string(msg->type)));
if (!extended) {
return;
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) {
}
SET_TMP_PREFIX("en-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
- &graph->event_msg_pool);
+ format_object_pool(buf_ch, tmp_prefix, &graph->event_msg_pool);
SET_TMP_PREFIX("pbn-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
- &graph->packet_begin_msg_pool);
+ format_object_pool(buf_ch, tmp_prefix, &graph->packet_begin_msg_pool);
SET_TMP_PREFIX("pen-pool-");
- format_object_pool(buf_ch, extended, tmp_prefix,
- &graph->packet_end_msg_pool);
+ format_object_pool(buf_ch, tmp_prefix, &graph->packet_end_msg_pool);
}
static inline void format_message_iterator(char **buf_ch,
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) {
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));
}
}
-static inline void handle_conversion_specifier_bt(void *priv_data,
- char **buf_ch, size_t avail_size,
+static inline void handle_conversion_specifier_bt(
+ void *priv_data __attribute__((unused)),
+ char **buf_ch,
+ size_t avail_size __attribute__((unused)),
const char **out_fmt_ch, va_list *args)
{
const char *fmt_ch = *out_fmt_ch;
case 'n':
format_message(buf_ch, extended, prefix, obj);
break;
+ case 'I':
+ /* Empty, the address is automatically printed. */
+ break;
case 'i':
format_message_iterator(buf_ch, extended, prefix, obj);
break;
format_graph(buf_ch, extended, prefix, obj);
break;
case 'z':
- format_interrupter(buf_ch, extended, prefix, obj);
+ format_interrupter(buf_ch, prefix, obj);
break;
case 'o':
- format_object_pool(buf_ch, extended, prefix, obj);
+ format_object_pool(buf_ch, prefix, obj);
break;
case 'O':
- format_object(buf_ch, extended, prefix, obj);
+ format_object(buf_ch, prefix, obj);
break;
case 'r':
format_error_cause(buf_ch, extended, prefix, obj);
break;
default:
- abort();
+ bt_common_abort();
}
update_fmt:
*out_fmt_ch = fmt_ch;
}
+/*
+ * This function would normally not be BT_EXPORTed, but it is used by the
+ * Python plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity. It is therefore
+ * exposed, but not part of the public ABI.
+ */
+BT_EXPORT
+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);
+}
+
+/*
+ * This function would normally not be BT_EXPORTed, but it is used by the
+ * Python plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity. It is therefore
+ * exposed, but not part of the public ABI.
+ */
+BT_EXPORT
void bt_lib_log(const char *func, const char *file, unsigned line,
int lvl, const char *tag, const char *fmt, ...)
{
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);
}
+/*
+ * This function would normally not be BT_EXPORTed, but it is used by the
+ * Python plugin provider, which is conceptually part of libbabeltrace2, but
+ * implemented as a separate shared object, for modularity. It is therefore
+ * exposed, but not part of the ABI.
+ */
+BT_EXPORT
void bt_lib_maybe_log_and_append_cause(const char *func, const char *file,
unsigned line, int lvl, const char *tag,
const char *fmt, ...)
}
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