The functions:
- bt_message_packet_beginning_borrow_default_clock_snapshot_const
- bt_message_packet_end_borrow_default_clock_snapshot_const
respectively have the preconditions:
- The packets of the stream class of message have a beginning default
clock snapshot.
- The packets of the stream class of message have an end default clock
snapshot.
These preconditions are currently not enforced by the code. A user of
these functions violating these preconditions in a dev build currently
gets NULL back, which is not an expected return value. Add some checks
for this.
This helps for example when using the trimmer component on a trace
without packet beginning/end default clock snapshots, like the one here
[1]. Without this patch, we hit a precondition failure when we pass the
unexpected NULL value to another function:
$ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:64 Babeltrace 2 library precondition not satisfied.
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:clock-snapshot-get-ns-from-origin:not-null:clock-snapshot`.
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_clock_snapshot_get_ns_from_origin().
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Clock snapshot is NULL.
05-05 10:02:15.110
3642287 3642287 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...
With this patch, the problem is caught a little bit earlier, so closer
to the root of the problem:
$ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:64 Babeltrace 2 library precondition not satisfied.
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:message-packet-beginning-borrow-default-clock-snapshot-const:msg-stream-class-packets-have-beginning-default-clock-snapshot`.
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_message_packet_beginning_borrow_default_clock_snapshot_const().
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Message's stream class packets don't have beginning default clock snapshot.
05-05 10:02:30.784
3647078 3647078 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...
[1] https://lists.lttng.org/pipermail/lttng-dev/2021-May/029955.html
Change-Id: I420bb71ab3a5139ff15b524f09c818a1c2aafa81
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5688
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>