2 * SPDX-License-Identifier: MIT
4 * Copyright 2020 Philippe Proulx <pproulx@efficios.com>
7 #define BT_LOG_TAG "LIB/ASSERT-COND"
8 #include "lib/logging.h"
13 #include "common/assert.h"
14 #include "common/common.h"
15 #include "assert-cond-base.h"
18 GString
*format_cond_id(const char *cond_type
, const char *func
,
19 const char *id_suffix
)
21 static const char func_prefix
[] = "bt_";
22 GString
*id
= g_string_new(NULL
);
29 g_string_append_printf(id
, "%s:", cond_type
);
31 /* Function name: no prefix */
33 BT_ASSERT(strstr(func
, func_prefix
) == func
);
34 src_ch
= &func
[strlen(func_prefix
)];
36 /* Function name: `_` replaced with `-` */
37 for (; *src_ch
; src_ch
++) {
46 g_string_append_c(id
, dst_ch
);
51 g_string_append_printf(id
, ":%s", id_suffix
);
56 void bt_lib_assert_cond_failed(const char *cond_type
, const char *func
,
57 const char *id_suffix
, const char *fmt
, ...)
60 GString
*cond_id
= format_cond_id(cond_type
, func
, id_suffix
);
63 BT_ASSERT_COND_MSG("Babeltrace 2 library %scondition not satisfied.",
65 BT_ASSERT_COND_MSG("------------------------------------------------------------------------");
66 BT_ASSERT_COND_MSG("Condition ID: `%s`.", cond_id
->str
);
67 g_string_free(cond_id
, TRUE
);
68 BT_ASSERT_COND_MSG("Function: %s().", func
);
69 BT_ASSERT_COND_MSG("------------------------------------------------------------------------");
70 BT_ASSERT_COND_MSG("Error is:");
72 bt_lib_log_v(__FILE__
, __func__
, __LINE__
, BT_LOG_FATAL
,
73 BT_LOG_TAG
, fmt
, &args
);
75 BT_ASSERT_COND_MSG("Aborting...");
This page took 0.043453 seconds and 4 git commands to generate.