babeltrace.git
21 months agoFix: bt2: autodisc: remove thread error while inserting status in map
Simon Marchi [Thu, 30 Jun 2022 14:46:53 +0000 (10:46 -0400)] 
Fix: bt2: autodisc: remove thread error while inserting status in map

If something fails in `bt_bt2_auto_discover_source_components`, we
append an error cause and we go to the error label.  This function
returns a bt_value map containing the return status code and the auto-discovery results, if it was successful.
So we then run into:

if (result) {
insert_entry_status = bt_value_map_insert_signed_integer_entry(result, "status", status);
if (insert_entry_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
BT_VALUE_PUT_REF_AND_RESET(result);
PyErr_NoMemory();
}
}

However, since there is an error on the current thread, we fail this
precondition:

    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:64 Babeltrace 2 library precondition not satisfied.
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:value-map-insert-signed-integer-entry:no-error`.
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_value_map_insert_signed_integer_entry().
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 API function called while current thread has an error: function=bt_value_map_insert_signed_integer_entry
    06-30 11:27:11.697 3948806 3948806 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...

Change the function to temporarily remove the current thread error,
while inserting the status in the map.  In the unlikely event where the
insertion fail because of a memory error, then we just release the error
and it gets lost.

Change-Id: I1b54fb7c8cb0f719fee867e7385dd6a3949cbde4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8512
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
21 months agotests: src.ctf.fs: add test for metadata with invalid syntax
Simon Marchi [Thu, 30 Jun 2022 14:33:50 +0000 (10:33 -0400)] 
tests: src.ctf.fs: add test for metadata with invalid syntax

It looks like we don't have any test for a metadata file with a syntax
error in it.  Add one.

It could be argued that we should not error out in that case, as there
may be unrelated files called `metadata`, and if they don't parse as CTF
1 metadata files, we should just skip over them.  But erroring out is
the current behavior of Babeltrace 2, so it should be tested to ensure
it doesn't change by mistake.

Change-Id: I82cae8ebc5df984592205c28041276cc861f30df
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8511
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
21 months agoRemove `skip-string-normalization` in Python formatter config
Francis Deslauriers [Tue, 21 Jun 2022 20:29:32 +0000 (16:29 -0400)] 
Remove `skip-string-normalization` in Python formatter config

Initially, this option was added to follow existing coding style of
the project. It was recently agreed upon that relying on `black`
completely would be simpler.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic4f7fc672502d512c10f107c254cec18c28a7710
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8518
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
22 months agoconfigure: disable -Wmaybe-uninitialized
Simon Marchi [Tue, 14 Jun 2022 13:38:57 +0000 (09:38 -0400)] 
configure: disable -Wmaybe-uninitialized

gcc produces the following warning at -O2, breaking the CI:

      CXX      msg-iter.lo
    /home/simark/src/babeltrace/src/plugins/ctf/common/src/msg-iter.cpp: In member function 'virtual void ctf::src::internal::MsgIterItemVisitor::visit(const ctf::src::PktInfoItem&)':
    /home/simark/src/babeltrace/src/plugins/ctf/common/src/msg-iter.cpp:132:87: error: '*(nonstd::optional_lite::optional<long long unsigned int>::value_type*)((char*)&prevPacketEndDefClkVal + offsetof(nonstd::optio
    nal_lite::optional<long long unsigned int>,nonstd::optional_lite::optional<long long unsigned int>::contained))' may be used uninitialized [-Werror=maybe-uninitialized]
      132 |                 msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
          |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      133 |                     _mSelfMsgIter, _mLibStream.libObjPtr(), *prevPacketEndDefClkVal,
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      134 |                     *_mPacketBeginDefClkVal);
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/src/plugins/ctf/common/src/msg-iter.cpp:76:42: note: '*(nonstd::optional_lite::optional<long long unsigned int>::value_type*)((char*)&prevPacketEndDefClkVal + offsetof(nonstd::optiona
    l_lite::optional<long long unsigned int>,nonstd::optional_lite::optional<long long unsigned int>::contained))' was declared here
       76 |     nonstd::optional<unsigned long long> prevPacketEndDefClkVal = _mPacketEndDefClkVal;
          |                                          ^~~~~~~~~~~~~~~~~~~~~~

I don't see anything wrong with the code, the compiler just seems
unhappy with the fact that the value part of the optional will possibly
be uninitialized.

I tried to disable -Wmaybe-uninitialized at specific spots, but it's too
difficult.  We get different spurious warnings on different
architectures, at different optimization levels, so it's going to end up
as a whack-a-mole game.  My previous experience is that this warning
generates a lot of noise and rarely leads to real bug fixes anyway.

Change-Id: Ia013447ee3659954d010b0c4e29b567bc40b6ee7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8351
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoCONTRIBUTING.adoc: remove BT_LIB_LOGF_APPEND_CAUSE
Simon Marchi [Fri, 11 Mar 2022 15:22:54 +0000 (10:22 -0500)] 
CONTRIBUTING.adoc: remove BT_LIB_LOGF_APPEND_CAUSE

This does not exist.

Change-Id: Ieb1f5ee16c02cf90e68ca7419ff3dd335c295639
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7565
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoFix: common: handle missing status in bt_common_func_status_string
Simon Marchi [Fri, 11 Mar 2022 01:16:47 +0000 (20:16 -0500)] 
Fix: common: handle missing status in bt_common_func_status_string

bt_common_func_status_string does not handle __BT_FUNC_STATUS_NO_MATCH,
trying to use it leads to an abort.

Add it, and reorder the cases to be in the same order as the statuses
are listed in include/babeltrace2/func-status.h, to make it easier to
see that none is missing.

Change-Id: I1c1da11b0e9a0694c96b67a4d1e6efb8e4da55d7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7564
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agotests: remove spurious print in test_field_class.py
Simon Marchi [Tue, 14 Jun 2022 00:05:42 +0000 (20:05 -0400)] 
tests: remove spurious print in test_field_class.py

Change-Id: I147b027b835520e39148938eff1b930e28768eec
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8350
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoconfigure: enable -Wsuggest-override
Simon Marchi [Mon, 13 Jun 2022 16:15:28 +0000 (12:15 -0400)] 
configure: enable -Wsuggest-override

Change-Id: I4d90271476258a22390ecbf3b4f7637c77cf2389
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8334
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoconfigure: enable -Wshadow-field-in-constructor
Simon Marchi [Mon, 13 Jun 2022 16:15:10 +0000 (12:15 -0400)] 
configure: enable -Wshadow-field-in-constructor

Change-Id: I049672c0fe73fd7a0cc31e4aa9f750e64ee8ad70
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8333
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoctf: rename identifiers ERROR and DEBUG_PROCESS
Simon Marchi [Tue, 14 Jun 2022 20:59:21 +0000 (16:59 -0400)] 
ctf: rename identifiers ERROR and DEBUG_PROCESS

When trying to use src/cpp-common/bt2/trace-ir.hpp, the build fails on
Windows (MinGW64) with:

      CXX      viewer-connection.o
    In file included from /usr/x86_64-w64-mingw32/include/windows.h:71,
                     from /usr/x86_64-w64-mingw32/include/winsock2.h:23,
                     from /home/smarchi/src/babeltrace/src/compat/socket.h:15,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/lttng-live/viewer-connection.cpp:23:
    /home/smarchi/src/babeltrace/src/cpp-common/bt2/trace-ir.hpp:1081:9: error: expected identifier before numeric constant
     1081 |         ERROR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
          |         ^~~~~

This is because there is an "ERROR" macro defined in wingdi.h:

    https://github.com/mirror/mingw-w64/blob/7da5597116c5335e9a0f1154d171750bd2531baf/mingw-w64-headers/include/wingdi.h#L75

Same thing with DEBUG_PROCESS.  Rename to ERROR to ERR and DEBUG_PROCESS
to DEBUG_PROC.

Change-Id: I31ed7578e84ce1bee883f0d9f121c1ea47e8a679
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8368
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoflt.utils.muxer: replace queue with array
Simon Marchi [Sun, 22 May 2022 19:46:36 +0000 (15:46 -0400)] 
flt.utils.muxer: replace queue with array

While profiling, I noticed "a lot" of time spent in g_queue* functions,
in the context of the muxer.  Using a dummy output and an LTTng kernel
trace as input, 2.7% of the time was spent in g_queue_pop_head and
1.92% in g_queue_push_tail.  Under those, most of the time was spent in
memory allocation functions.

For something fast path like the muxer's message queues, I think we
would benefit on reducing the number of allocation/deallocations.

To improve that, replace the queue with a GPtrArray.  Incoming messages
are put in this array, and the index of the next message to be returned
is kept in a separate field.  When a message from that queue is
returned, return the message at that index.  Write NULL at that index
(the ownership of the message is transferred from the queue) and
increment the next message index.  The queue is considered empty when
the next message index is equal to the array length.  At this point, all
entries in the array are expected to be NULL, and more messages need to
be obtained from the upstream message iterator.  The array is resized
(g_ptr_array_set_size) to the size of the new message batch.  In
practice, the message count is always the same, so the size of the array
won't change, and g_ptr_array_set_size just does trivial work.

Performance results I get locally:

Before:

$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.77s user 0.02s system 99% cpu 3.791 total
$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.78s user 0.03s system 99% cpu 3.822 total

After:

$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.52s user 0.06s system 99% cpu 3.577 total
$ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.52s user 0.04s system 99% cpu 3.563 total

This is with Babeltrace configured with:

    --enable-python-bindings --enable-python-plugins --disable-man-pages 'CFLAGS=-gdwarf-5 -g3 -O2' 'CXXFLAGS=-gdwarf-5 -g3 -O2' --prefix=/tmp/babeltrace 'CC=ccache clang' 'CXX=ccache clang++'

Change-Id: I0ce20994981be0479f0529880b4bdbca53a03fd6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8107
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agologging: use G_UNLIKELY in BT_LOG_ON macros
Simon Marchi [Sun, 22 May 2022 01:53:00 +0000 (21:53 -0400)] 
logging: use G_UNLIKELY in BT_LOG_ON macros

Use G_UNLIKELY to hint the compiler (and the processor) that logging is
likely not going to be enabled.  We care about performance in the
logging disabled case more than in the logging enabled case.

I see a small but consistent speedup.  Not scientific (sample size of
2), but before it looks like:

    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.98s user 0.05s system 99% cpu 4.025 total
    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.96s user 0.04s system 99% cpu 4.000 total

And after:

    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.81s user 0.04s system 99% cpu 3.848 total
    $ time ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy
    ./src/cli/babeltrace2 /home/simark/lttng-traces/auto-20180226-075238 -o dummy  3.77s user 0.04s system 100% cpu 3.806 total

This is with babeltrace configured with:

    --enable-python-bindings --enable-python-plugins --disable-man-pages 'CFLAGS=-gdwarf-5 -g3 -O2' 'CXXFLAGS=-gdwarf-5 -g3 -O2' --prefix=/tmp/babeltrace 'CC=ccache clang' 'CXX=ccache clang++'

Change-Id: I3b11d1023f4dfad9c88ffa24e98a07afccb8cc61
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8106
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agotests: add diag in plugins/src.ctf.lttng-live/test_live
Simon Marchi [Thu, 26 May 2022 21:12:06 +0000 (17:12 -0400)] 
tests: add diag in plugins/src.ctf.lttng-live/test_live

This was helpful when trying to reproduce by hand, to know how to run
the mock server.

Change-Id: I834265633659ce943dc3e539ee36c203182aeb3b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8148
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agosrc.ctf.lttng-live: remove unused variable in live_get_msg_ts_ns
Simon Marchi [Thu, 26 May 2022 15:30:10 +0000 (11:30 -0400)] 
src.ctf.lttng-live: remove unused variable in live_get_msg_ts_ns

clock_class is assigned, but never used outside of assertions, remove
it (I don't think the assertions are particularly important here).

Change-Id: I8b7e23bb14d51837d6120567cb303a0436c8648a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8129
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoFix: python: don't get extra references when creating field classes
Simon Marchi [Mon, 13 Jun 2022 13:42:44 +0000 (09:42 -0400)] 
Fix: python: don't get extra references when creating field classes

Running:

    $ G_SLICE=always-malloc G_DEBUG=gc-friendly PYTHONMALLOC=malloc tests/utils/run_python_bt2 /home/smarchi/build/babeltrace/tests/../src/cli/babeltrace2 --plugin-path=/home/smarchi/src/babeltrace/tests/data/plugins/flt.lttng-utils.debug-info -c src.test_debug_info.CompleteSrc -c sink.text.details --params with-trace-name=false,with-stream-name=false,with-uuid=false -c flt.lttng-utils.debug-info

... ASan gives me many field class-related leaks such as:

    Indirect leak of 32 byte(s) in 1 object(s) allocated from:
        #0 0x7fe783780e17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
        #1 0x7fe783417ef0 in g_malloc0 ../../../glib/gmem.c:132
        #2 0x7fe7835e6305 in bt_field_class_variant_without_selector_append_option /home/smarchi/src/babeltrace/src/lib/trace-ir/field-class.c:1576
        #3 0x7fe77e92ff4c in _wrap_field_class_variant_without_selector_append_option bt2/native_bt.c:10957
        #4 0x7fe77f752686 in cfunction_call_varargs ../Objects/call.c:758

I only see this on Ubuntu 20.04, not on my other development machine that is on
Arch Linux.

I think that we erroneously make some get_refs when creating some field
classes in trace_class.py.  For instance, when creating a static array:

    def create_static_array_field_class(self, elem_fc, length, user_attributes=None):
        utils._check_type(elem_fc, bt2_field_class._FieldClass)
        utils._check_uint64(length)
        ptr = native_bt.field_class_array_static_create(self._ptr, elem_fc._ptr, length)
        self._check_field_class_create_status(ptr, 'static array')
        fc = bt2_field_class._StaticArrayFieldClass._create_from_ptr_and_get_ref(ptr)
        self._set_field_class_user_attrs(fc, user_attributes)
        return fc

The `native_bt.field_class_array_static_create` line returns a pointer
to the created object, with a refcount of 1, where the reference belongs
to the caller.  We then call `_create_from_ptr_and_get_ref` to create a
Python wrapper around the raw pointer, which brings the refcount to 2.
We then return that wrapper.  The create_static_array_field_class
function should return an object with a refcount of 1, since the only
reference at this point will belong to its caller.  So we must not take
an additional reference here, the only returned by the native code is
enough.

 - Add a field_class._obj_type_from_field_class_ptr_template function,
   to get an object wrapper type from a pointer
 - Make the existing
   field_class._create_field_class_from_ptr_and_get_ref_template
   function use it, to avoid duplicating code
 - Add a new field_class._obj_type_from_field_class_ptr, for use in the
   field class-creation functions, in trace_class.py.

With this, the command line shown above does not produce any leaks
reported by ASan.

Change-Id: Iba5bae3f98bed67d0168b467627667994b32288e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8328
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoFix: tests: create correct field class in bt_plugin_test_debug_info.py
Simon Marchi [Mon, 13 Jun 2022 13:18:01 +0000 (09:18 -0400)] 
Fix: tests: create correct field class in bt_plugin_test_debug_info.py

The wrong function is used to create this component class.  The
intention is to create a static array field class, but
create_dynamic_array_field_class is used.  Change it to
create_static_array_field_class.  Length 3 matches the length of the
value set in CompleteIter.__init__.

Change-Id: I69962e10c2f4b945487d7b818adcd71b460fe17b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8327
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
22 months agoFix: python: free py_config_ptr in component_class_message_iterator_init
Simon Marchi [Mon, 13 Jun 2022 12:40:44 +0000 (08:40 -0400)] 
Fix: python: free py_config_ptr in component_class_message_iterator_init

It looks like we never decref the py_config_ptr object.  This causes
this leak:

    Direct leak of 48 byte(s) in 1 object(s) allocated from:
        #0 0x7fe01c31fc47 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
        #1 0x7fe017434b67 in SwigPyObject_New bt2/native_bt.c:1754
        #2 0x7fe017436ef8 in SWIG_Python_NewPointerObj bt2/native_bt.c:2336
        #3 0x7fe01743cee0 in component_class_message_iterator_init /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/native_bt_component_class.i.h:1141
        #4 0x7fe01c13d46f in create_self_component_input_port_message_iterator /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:408
        #5 0x7fe01c13d877 in bt_message_iterator_create_from_message_iterator /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:468
        #6 0x7fe018a251cb in create_msg_iter_on_input_port /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c:365
        #7 0x7fe018a2bd26 in muxer_msg_iter_init_upstream_iterators /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c:1243
        #8 0x7fe018a2c6eb in muxer_msg_iter_init /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c:1341
        #9 0x7fe01c13d46f in create_self_component_input_port_message_iterator /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:408
        #10 0x7fe01c13d877 in bt_message_iterator_create_from_message_iterator /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:468
        #11 0x7fe0188b9123 in debug_info_msg_iter_init /home/smarchi/src/babeltrace/src/plugins/lttng-utils/debug-info/debug-info.c:1999
        #12 0x7fe01c13d46f in create_self_component_input_port_message_iterator /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:408
        #13 0x7fe01c13d93b in bt_message_iterator_create_from_sink_component /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:480
        #14 0x7fe018a9c665 in details_graph_is_configured /home/smarchi/src/babeltrace/src/plugins/text/details/details.c:418
        #15 0x7fe01c1360da in configure_graph /home/smarchi/src/babeltrace/src/lib/graph/graph.c:614
        #16 0x7fe01c136718 in bt_graph_run /home/smarchi/src/babeltrace/src/lib/graph/graph.c:688
        #17 0x55bdd975fdca in cmd_run /home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2493
        #18 0x55bdd9760c3b in main /home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2679
        #19 0x7fe01bd6e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

... when I run:

    $ G_SLICE=always-malloc G_DEBUG=gc-friendly PYTHONMALLOC=malloc tests/utils/run_python_bt2 /home/smarchi/build/babeltrace/tests/../src/cli/babeltrace2 --plugin-path=/home/smarchi/src/babeltrace/tests/data/plugins/flt.lttng-utils.debug-info -c src.test_debug_info.CompleteSrc -c sink.text.details --params with-trace-name=false,with-stream-name=false,with-uuid=false -c flt.lttng-utils.debug-info

I see the leak on Ubuntu 20.04, not on Arch.  Not sure why.

Change-Id: Iad3b1ae78c4f983da27a4e57914af4d5de05ce7e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8326
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
23 months agoFix: lib: pass down API function name to some helpers
Simon Marchi [Sun, 8 May 2022 01:42:36 +0000 (21:42 -0400)] 
Fix: lib: pass down API function name to some helpers

Let's say I change bt_field_structure_borrow_member_field_by_index to
pass an invalid index (e.g. 99999) to
borrow_structure_field_member_field_by_index, to exercise the "valid
index" precondition assertion, I get:

   (╯°□°)╯︵ ┻━┻  /home/simark/src/babeltrace/src/lib/assert-cond.c:33: format_cond_id(): Assertion `strstr(func, func_prefix) == func` failed.

This is because `format_cond_id` expects to receive the name of the API
function called by the user, starting with `bt_`.  But it's the name of
the `borrow_structure_field_member_field_by_index` helper that is passed
down to `format_cond_id`, instead.

Change some helpers in lib/trace-ir/field.c to pass down the API
function name to their helper, to avoid this.  Add some necessary
"FROM_FUNC" version of assertions used by these helpers.

Introducing the same "bug", I get the expected precondition assertion
failure message:

    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:65 Babeltrace 2 library precondition not satisfied.
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:field-structure-borrow-member-field-by-index:valid-index`.
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_field_structure_borrow_member_field_by_index().
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Index is out of bounds: index=99999, count=1
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...

Change-Id: Id3c310a3c5c46358532657d38d867c5ed802df78
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8002
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

23 months agosrc.ctf.fs: remove unused ctf_fs_ds_file::self_msg_iter field
Simon Marchi [Tue, 10 May 2022 01:56:33 +0000 (21:56 -0400)] 
src.ctf.fs: remove unused ctf_fs_ds_file::self_msg_iter field

Remove the unused field, and then the unused ctf_fs_ds_file_create
parameter.

Change-Id: I275622d454bbcb71a2035bf73d2490a8dd94c5f3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8009
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoClean-up: lttng-live: left-over tabs in comment
Jérémie Galarneau [Thu, 24 Feb 2022 20:25:32 +0000 (15:25 -0500)] 
Clean-up: lttng-live: left-over tabs in comment

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I44784de7beb2b97779084d701faf89e9c4a03b3f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7388

2 years agoUse Black stable to format python code
Michael Jeanson [Mon, 28 Feb 2022 15:54:43 +0000 (10:54 -0500)] 
Use Black stable to format python code

The first stable release of the Black code formatter, 22.1.0 [1] is now
available with a promise of code style stability for all versions
sharing the same major version number [2].

Set the requirements to 'black ~= 22.0' to get bug fix releases while
maintaining a stable code style.

[1] https://github.com/psf/black/releases/tag/22.1.0
[2] https://black.readthedocs.io/en/latest/the_black_code_style/index.html#stability-policy

Change-Id: I8b7843deff87464237a9214d4ea3bf18e4d987a1
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7406
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agofix: add dependency between cli bin and plugins when built-in
Michael Jeanson [Wed, 2 Mar 2022 18:25:05 +0000 (13:25 -0500)] 
fix: add dependency between cli bin and plugins when built-in

When building with '--enable-built-in-plugins' we use some linker
trickery to embed the plugins in the cli binary. The automake build
system is however unaware of this dependency and won't trigger a
relinking when a plugin is modified.

Use the  EXTRA_*_DEPENDENCIES [1] variable to add explicit dependencies
between the cli binary and each embedded plugin.

[1] https://www.gnu.org/software/automake/manual/html_node/Program-and-Library-Variables.html

Fixes #1237

Change-Id: Ib989edcc083c55509f4a990d90948761a18fc1d0
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7464
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years ago.gitignore: generated files moved to cpp
Michael Jeanson [Wed, 2 Mar 2022 19:36:33 +0000 (14:36 -0500)] 
.gitignore: generated files moved to cpp

Change-Id: I43941935b02f7dfacf079a994fef56df6122740d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7472
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: src.text.details: use write_uint_prop_value to handle unsigned values in write_i...
Simon Marchi [Sat, 5 Mar 2022 01:20:34 +0000 (20:20 -0500)] 
Fix: src.text.details: use write_uint_prop_value to handle unsigned values in write_int_range

I tried creating an option field class with unsigned integer selector,
with a [1, UINT64_MAX] range.  The details field class shows it as:

     opt_with_uint_sel: Option (unsigned integer selector) (Selector field location [Event payload: uint_selector]):
      Selector ranges: [1, -1]

The -1 is wrong.  Fix two spots to call write_uint_prop_value instead of
write_int_prop_value.

After:

    opt_with_uint_sel: Option (unsigned integer selector) (Selector field location [Event payload: uint_selector]):
       Selector ranges: [1, 18,446,744,073,709,551,615]

Change-Id: I83344b2a241f597da86c21da030b40eed2a4955f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7503
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoTests: src.ctf.lttng-live: split metadata sections
Francis Deslauriers [Tue, 14 Jul 2020 23:01:22 +0000 (19:01 -0400)] 
Tests: src.ctf.lttng-live: split metadata sections

Background
==========
This commit adds a test case to emulate when a live session is cleared
by the user and the metadata is sent in two different batches.

Here is the scenario this new test case is testing:
  1. Live session is running and generating events,
  2. User clears the session,
  3. Relay empties its metadata stream (Relay is aware that metadata
    is available but has not received it from the consumer since the
    clear),
  4. Babeltrace requests for newly available metadata from the Relay,
  5. Relay sends a zero-sized metadata buffer and status
  `LTTNG_VIEWER_METADATA_OK`,
  6. Babeltrace interpret this as a retry,
  7. Relay receives new (and old) metadata from consumer,
  8. Babeltrace requests for newly available metadata again,
  9. Relay replies with the new metadata section.

This key steps here are 6 to 10 where the relay sends an empty metadata
buffer to signify to the viewer to try again hoping that next time it
will have received the metadata.

Approach
========
To emulate this scenario, this commit adds the concept of metadata
sections to the `lttng_live_server.py` script. A new optional
"metadata-sections" field in the JSON trace description. This list
contains sections described by a JSON object containing the line at
which the metadata section starts and a timestamp at which it must be
sent to the viewer. Empty section are represented by a "empty" string.
    e.g.
        "metadata-sections": [
          {
            "line": 1,
            "timestamp": 1294581
          },
          "empty",
          {
            "line": 111,
            "timestamp": 1295918
          },
        ]

The metadata stream object acts as a queue and is systematically (on
LTTNG_VIEWER_GET_NEXT_INDEX) checked against the current timestamp to
see if the next metadata section needs to be activated.

If the "metadata-sections" field is absent, the uses the metadata file
as a single section, as usual.

Notes
=====
You will notice that the all .expect files were modified to increment
the stream ID of all data streams. This is because we now create the
`_LttngLiveViewerSessionMetadataStreamState` object before (instead of
after) the `_LttngLiveViewerSessionDataStreamState` objects. This is
done because we need a reference from any data stream to its metadata
stream. The metadata stream id is pass to the
`_LttngLiveViewerSessionDataStreamState` __init__() method.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I45c7e12cc596033bce376e45393ff6970670f1da
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3775
Tested-by: jenkins <jenkins@lttng.org>
2 years agoFix: src.ctf.lttng-live: consider empty metadata packet as retry
Francis Deslauriers [Thu, 24 Feb 2022 21:51:50 +0000 (16:51 -0500)] 
Fix: src.ctf.lttng-live: consider empty metadata packet as retry

When clearing a live session, it's possible for the Relay to know that
metadata is available even though it has not yet received it from the
consumer.

In such cases, the relay will send a `LTTNG_VIEWER_METADATA_OK` reply
with a zero length metadata packet. The viewer needs to interpret that
as "please try again later". In fact, the viewer needs to keep
requesting metadata from the relay until it receives either a
`LTTNG_VIEWER_NO_NEW_METADATA` status or an error status.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ief33f1a43ec827e211a2f4f2ace623e9d3254246
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3763

2 years agoFix: ctf: wrongfully requiring CTF metadata signature for every section
Francis Deslauriers [Thu, 24 Feb 2022 21:48:33 +0000 (16:48 -0500)] 
Fix: ctf: wrongfully requiring CTF metadata signature for every section

Issue
=====
When testing the special live tracing session case of sending the
metadata in multiple batches, we witnessed the CTF metadata decoder
returning an error if the "/* CTF 1.8" signature is omitted from the
metadata sections following the first one.

Here is the output of Babeltrace when this error occurs:
07-22 12:18:38.518 539222 539222 W PLUGIN/CTF/META/DECODER ctf_metadata_decoder_append_content@decoder.c:242 [lttng-live] Missing "/* CTF major.minor" signature in plain text metadata file stream: mdec
-addr=0x2398ec0
07-22 12:18:38.518 539222 539222 E PLUGIN/CTF/META/DECODER ctf_metadata_decoder_append_content@decoder.c:251 [lttng-live] Invalid metadata version found in plain text signature: version=571641920.0, md
ec-addr=0x2398ec0

We expect the decoder to only require this signature when decoding the
first section of plain-text metadata.

Solution
========
Only check for the signature when processing the first metadata section.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3153abf58ade5f5b02362dbedde382f398f5ee4e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3807

2 years agoFix: src.ctf.lttng-live: session closed before any metadata is received
Francis Deslauriers [Thu, 24 Feb 2022 21:24:36 +0000 (16:24 -0500)] 
Fix: src.ctf.lttng-live: session closed before any metadata is received

Issue
=====
When stress-testing the LTTng-UST clear feature over an entire night I
witnessed 6 instances of Babeltrace infinite loop.

Using the GNU Debugger, Babeltrace was found to be endlessly issuing the
`LTTNG_VIEWER_GET_NEW_STREAMS` command to the Relay daemon to which the
Relay Daemon endlessly replied `LTTNG_VIEWER_NEW_STREAMS_HUP`.

This is caused by the fact that the session was closed before we
received any metadata and the lttng-live component class keeps trying to
ask for new streams before requesting the metadata.

Fix
===
If the session is marked as closed return a `_STATUS_END` to stop
considering this session.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9c18d03cef1b61d1c02b7d608720bf5750a348c4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6827

2 years agosrc.ctf.lttng-live: add comments and debug statements
Francis Deslauriers [Thu, 24 Feb 2022 21:21:20 +0000 (16:21 -0500)] 
src.ctf.lttng-live: add comments and debug statements

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7d6425df0912be66421296512b2aca01c985e785
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7080

2 years agoFix: C++ bindings typos in lib function name
Francis Deslauriers [Mon, 14 Feb 2022 16:23:11 +0000 (11:23 -0500)] 
Fix: C++ bindings typos in lib function name

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic72511ce1c8cd2b214c23d71cf2e12bfed455f70
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7295
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: lib: fix memory leak in simple_sink_init error path
Simon Marchi [Mon, 31 Jan 2022 17:33:17 +0000 (12:33 -0500)] 
Fix: lib: fix memory leak in simple_sink_init error path

If bt_self_component_sink_add_input_port fails, we don't free the
simple_sink_data instance.

Move the code to free a simple_sink_data in a new function,
simple_sink_data_destroy.  Call it from simple_sink_finalize and from
simple_sink_init's error path.

Change-Id: If8f87ef4a39836e02ed1c125dc8feb160d21cc37
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7196
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoFix: src.ctf.lttng-live: return correct error status in lttng_live_msg_iter_init
Simon Marchi [Mon, 31 Jan 2022 15:38:11 +0000 (10:38 -0500)] 
Fix: src.ctf.lttng-live: return correct error status in lttng_live_msg_iter_init

Fix this clang-tidy warning:

    /home/simark/src/babeltrace/src/plugins/ctf/lttng-live/lttng-live.cpp:1802:9: warning: Value stored to 'status' is never read [clang-analyzer-deadcode.DeadStores]
            status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
            ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indeed, we set status to MEMORY_ERROR here, but overwrite it to ERROR at
the error label.  Remove the assignment at the error label, add
assignments to all points where we go to the error label.

Change-Id: I5a81210609d913854f7b7d1b1be5bd54fffa02b2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7195
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: remove unnecessary assignment in lttng_live_get_stream_bytes
Simon Marchi [Thu, 3 Feb 2022 15:10:47 +0000 (10:10 -0500)] 
src.ctf.lttng-live: remove unnecessary assignment in lttng_live_get_stream_bytes

No need to assign status here, it will be overwritten later.

Change-Id: I53bfc51399c5854f90bdcf5118d94520d1cc94b6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7207
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: remove unnecessary assignment in lttng_live_iterator_handle_new_s...
Simon Marchi [Mon, 31 Jan 2022 15:34:20 +0000 (10:34 -0500)] 
src.ctf.lttng-live: remove unnecessary assignment in lttng_live_iterator_handle_new_streams_and_metadata

Fix this clang-tidy warning:

    /home/simark/src/babeltrace/src/plugins/ctf/lttng-live/lttng-live.cpp:612:13: warning: Value stored to 'status' is never read [clang-analyzer-deadcode.DeadStores]
                status = LTTNG_LIVE_ITERATOR_STATUS_OK;
                ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This value is indeed always overwritten in any case, in the if at the
end of the function.

Change-Id: I1899d07f389ae32abda34218b452d93d6d6a092b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7186
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: lib: add NULL check for destroy_listeners in destroy_component_class
Simon Marchi [Mon, 31 Jan 2022 15:19:35 +0000 (10:19 -0500)] 
Fix: lib: add NULL check for destroy_listeners in destroy_component_class

By doing this change, to simulate an allocation failure:

    @@ -99,6 +99,8 @@ int bt_component_class_init(struct bt_component_class *class,
      }

      class->description = g_string_new(NULL);
    + g_string_free(class->description, 1);
    + class->description = NULL;
      if (!class->description) {
      BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
      goto error;

... and trying to read a trace, we get this crash:

    ==2788787==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7f779199cd2b bp 0x7ffd04f1a300 sp 0x7ffd04f1a2c0 T0)
    ==2788787==The signal is caused by a READ memory access.
    ==2788787==Hint: address points to the zero page.
        #0 0x7f779199cd2b in destroy_component_class /home/simark/src/babeltrace/src/lib/graph/component-class.c:39
        #1 0x7f779199ca19 in bt_object_put_ref_no_null_check /home/simark/src/babeltrace/src/lib/object.h:307
        #2 0x7f779199cb85 in bt_object_put_ref /home/simark/src/babeltrace/src/lib/object.h:335
        #3 0x7f779199d57f in bt_component_class_init /home/simark/src/babeltrace/src/lib/graph/component-class.c:131

This is because destroy_component_class can be called before the
destroy_listeners field has been initialized.  Add a check for
destroy_listeners to be non-NULL in destroy_component_class.

Change-Id: I3616f608f05e2abed4a85a62bebe05b1efedeb2b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7185
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoparam-parse: remove unnecessary variable assignment
Simon Marchi [Mon, 31 Jan 2022 15:10:13 +0000 (10:10 -0500)] 
param-parse: remove unnecessary variable assignment

This assignment of token_type is not used, remove it.

Change-Id: Ifed19105cd6369e89240998f62c39d70d2e6fe5f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7184
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoparam-validation: add static creation methods to bt_param_validation_value_descr
Simon Marchi [Fri, 4 Feb 2022 20:43:23 +0000 (15:43 -0500)] 
param-validation: add static creation methods to bt_param_validation_value_descr

Replace the various constructors of bt_param_validation_value_descr with
equivalent static methods.

Change-Id: Ia53e05369df9f5f357f1e9eed72d7cfc8c6cb11b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7209
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoAdd `src/cpp-common/bt2/logging.hpp`
Philippe Proulx [Fri, 22 Jan 2021 16:44:01 +0000 (11:44 -0500)] 
Add `src/cpp-common/bt2/logging.hpp`

This file contains a scoped enumeration which is equivalent to
`bt_logging_level`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I27e0ea6b0a1a521a1d45a707b1b22402ab372afd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4736

2 years agoAdd C++ interface for the libbabeltrace2 `bt_message` API
Philippe Proulx [Fri, 22 Jan 2021 14:23:02 +0000 (09:23 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_message` API

This patch adds C++ wrappers for Babeltrace 2 message objects.

The class hierarchy is:

    Message
      StreamBeginningMessage
      StreamEndMessage
      PacketBeginningMessage
      PacketEndMessage
      EventMessage
      DiscardedEventsMessage
      DiscardedPacketsMessage
      MessageIteratorInactivityMessage
    ConstMessage
      ConstStreamBeginningMessage
      ConstStreamEndMessage
      ConstPacketBeginningMessage
      ConstPacketEndMessage
      ConstEventMessage
      ConstDiscardedEventsMessage
      ConstDiscardedPacketsMessage
      ConstMessageIteratorInactivityMessage

Implicitly convert from a mutable field class to a constant field class
with converting constructors and assignment operators.

Those new template classes follow the approach of other wrappers in
`src/cpp-common/bt2`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: If01ac4b2bbf8eb1ea400f8e5e7c2003b4844b80f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4735

2 years agoAdd missing C++ interface for the libbabeltrace2 trace IR API
Philippe Proulx [Thu, 14 Jan 2021 20:07:52 +0000 (15:07 -0500)] 
Add missing C++ interface for the libbabeltrace2 trace IR API

This patch adds C++ wrappers for the following Babeltrace 2 objects:

* Event
* Packet
* Stream
* Trace
* Event class
* Stream class
* Trace class

Those are the missing wrappers to complete trace IR API wrapping
within `src/cpp-common/bt2`.

I used a single file (`src/cpp-common/bt2/trace-ir.hpp`) to implement
those wrappers as there are many interdependencies between them. For
example, you can borrow the parent stream class S of an event class E
while you can also borrow E from S. This means some methods need to be
implemented after the full definitions of classes on which they depend.
Doing this in dedicated files while also making sure that you can
include any header in any order is not straightforward. With this patch,
simply include `cpp-common/bt2/trace-ir.hpp` to get the whole trace IR
C++ API.

Implicitly convert from a mutable object to a constant field class
with converting constructors and assignment operators.

Those new template classes follow the approach of other wrappers in
`src/cpp-common/bt2`.

Many of the new common classes become friends of
`bt2::CommonFieldClass`, `bt2::CommonValue`, and
`bt2::CommonIntegerRangeSet` to access their _libObjPtr() method.

The new creation methods are:

* Create a packet with bt2::Stream::createPacket().

* Create a stream with bt2::StreamClass::instantiate().

* Create a trace with bt2::TraceClass::instantiate().

* Create an event class with bt2::StreamClass::createEventClass().

* Create a stream class with bt2::TraceClass::createStreamClass().

* Create a field class with one of the
  bt2::TraceClass::create*FieldClass() methods.

Access the class of an event/stream/trace object with its cls() method.

As of this patch, you cannot create a trace class. This will be possible
when we add a self component wrapper.

This patch doesn't wrap the trace and trace class destruction listener
APIs.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1f2977b0c5d5eba35b468a9748216f2201f205dd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4688

2 years agoAdd C++ interface for the libbabeltrace2 `bt_field` API
Philippe Proulx [Fri, 18 Dec 2020 04:27:10 +0000 (23:27 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_field` API

This patch adds C++ wrappers for Babeltrace 2 field objects.

The class hierarchy is:

    Field
      BoolField
      BitArrayField
      UnsignedIntegerField
        UnsignedEnumerationField
      SignedIntegerField
        SignedEnumerationField
      SinglePrecisionRealField
      DoublePrecisionRealField
      StringField
      StructureField
      ArrayField
        DynamicArrayField
      OptionField
      VariantField
    ConstField
      ConstBoolField
      ConstBitArrayField
      ConstUnsignedIntegerField
        ConstUnsignedEnumerationField
      ConstSignedIntegerField
        ConstSignedEnumerationField
      ConstSinglePrecisionRealField
      ConstDoublePrecisionRealField
      ConstStringField
      ConstStructureField
      ConstArrayField
        ConstDynamicArrayField
      ConstOptionField
      ConstVariantField
    EnumerationFieldClassMappingLabels

Implicitly convert from a mutable field to a constant field with
converting constructors and assignment operators.

Those new template classes follow the approach of other wrappers in
`src/cpp-common/bt2`.

Each specialized field type has a cls() method which returns a
corresponding specialized field class type instance.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic8886033befc38366f3ee676e0c779640420a72f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4629

2 years agoAdd C++ interface for the libbabeltrace2 `bt_field_class` API
Philippe Proulx [Thu, 17 Dec 2020 18:44:51 +0000 (13:44 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_field_class` API

This patch adds C++ wrappers for Babeltrace 2 field class objects.

The class hierarchy is:

    FieldClass
      BitArrayFieldClass
      IntegerFieldClass
        UnsignedEnumerationFieldClass
        SignedEnumerationFieldClass
      StructureFieldClass
      ArrayFieldClass
        StaticArrayFieldClass
        DynamicArrayWithLengthFieldClass
      OptionFieldClass
        OptionWithSelectorFieldClass
          OptionWithBoolSelectorFieldClass
          OptionWithUnsignedIntegerSelectorFieldClass
          OptionWithSignedIntegerSelectorFieldClass
      VariantFieldClass
        VariantWithoutSelectorFieldClass
        VariantWithUnsignedIntegerSelectorFieldClass
        VariantWithSignedIntegerSelectorFieldClass
    ConstFieldClass
      ConstBitArrayFieldClass
      ConstIntegerFieldClass
        ConstUnsignedEnumerationFieldClass
        ConstSignedEnumerationFieldClass
      ConstStructureFieldClass
      ConstArrayFieldClass
        ConstStaticArrayFieldClass
        ConstDynamicArrayWithLengthFieldClass
      ConstOptionFieldClass
        ConstOptionWithSelectorFieldClass
          ConstOptionWithBoolSelectorFieldClass
          ConstOptionWithUnsignedIntegerSelectorFieldClass
          ConstOptionWithSignedIntegerSelectorFieldClass
      ConstVariantFieldClass
        ConstVariantWithoutSelectorFieldClass
        ConstVariantWithUnsignedIntegerSelectorFieldClass
        ConstVariantWithSignedIntegerSelectorFieldClass
    ConstUnsignedEnumerationFieldClassMapping
    ConstSignedEnumerationFieldClassMapping
    StructureFieldClassMember
    ConstStructureFieldClassMember
    VariantFieldClassOption
    ConstVariantFieldClassOption
    ConstVariantWithUnsignedIntegerSelectorFieldClassOption
    ConstVariantWithSignedIntegerSelectorFieldClassOption

`ConstVariantWith*IntegerSelectorFieldClassOption` doesn't inherit
`ConstVariantFieldClassOption` as they don't wrap the same pointer type:
you need to call
bt_field_class_variant_with_selector_field_integer_*_option_as_option_const()
to obtain a `const bt_field_class_variant_option *` value. Therefore,
you can call asBaseOption() to get a `ConstVariantFieldClassOption`. I
also implemented name() and fieldClass() which call
asBaseOption().name() and asBaseOption().fieldClass().

Implicitly convert from a mutable field class to a constant field class
with converting constructors and assignment operators.

Those new template classes follow the approach of other wrappers in
`src/cpp-common/bt2`.

Because `bt2::FieldClass::userAttributes()` needs to access the
libbabeltrace2 pointer of the map value, `bt2::CommonValue` makes
`bt2::FieldClass` a friend.

Because
`bt2::VariantWithUnsignedIntegerSelectorFieldClass::appendOption()` and
`bt2::VariantWithSignedIntegerSelectorFieldClass::appendOption()` need
to access the libbabeltrace2 pointer of the integer range set,
`bt2::CommonIntegerRangeSet` makes those classes friends.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5244b603b1f43e61cfa52c4a5fb6b19e2cbac576
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4612

2 years agoAdd C++ interface for the libbabeltrace2 `bt_field_path` API
Philippe Proulx [Thu, 17 Dec 2020 18:13:10 +0000 (13:13 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_field_path` API

This patch adds C++ wrappers for Babeltrace 2 field path objects.

The new available classes are:

* `bt2::ConstFieldPathItem`
* `bt2::ConstIndexFieldPathItem`
* `bt2::ConstFieldPath`

Those new classes follow the approach of other wrappers in
`src/cpp-common/bt2`.

You can't create a field path: it's what some field class methods (not
part of `src/cpp-common/bt2` yet) return.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3414ac96ff2d305669ae24ef13aa8e88dad88df5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4611

2 years agoAdd C++ interface for the libbabeltrace2 `bt_clock_snapshot` API
Philippe Proulx [Thu, 17 Dec 2020 13:52:40 +0000 (08:52 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_clock_snapshot` API

This patch adds C++ wrappers for Babeltrace 2 clock snapshot objects.

The new available class is `bt2::ClockSnapshot`.

This new class follows the approach of other wrappers in
`src/cpp-common/bt2`.

You can't create such objects: they are what various message methods
(not part of `src/cpp-common/bt2` yet) return.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id462b88b1575cddf50ae250f22dda71d7b27733c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4603

2 years agoAdd C++ interface for the libbabeltrace2 `bt_clock_class` API
Philippe Proulx [Thu, 17 Dec 2020 04:33:50 +0000 (23:33 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_clock_class` API

This patch adds C++ wrappers for Babeltrace 2 clock class objects.

The two new available types are `bt2::ClockClass` and
`bt2::ConstClockClass`.

This new template class follows the approach of other wrappers in
`src/cpp-common/bt2`.

Because `bt2::ClockClass::userAttributes()` needs to access the
libbabeltrace2 pointer of the map value, `bt2::CommonValue` makes
`bt2::ClockClass` a friend.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I40e012e1682208f2a43896be3a952cdf8ae0889b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4602

2 years agoAdd `bt2_common::UuidView`
Philippe Proulx [Thu, 17 Dec 2020 04:30:00 +0000 (23:30 -0500)] 
Add `bt2_common::UuidView`

This patch adds the `bt2_common::UuidView` class which is like
`std::string_view`, but for UUIDs.

You cannot modify the underlying UUID (`const std::uint8_t *`).

Compare UUID views with operator==() and operator!=().

Get a UUID view's data with its data() method.

Get a UUID view's data size with its size() method.

Get the canonical string of a UUID view with its string() method, which
returns a new `std::string` instance.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icc633b44b852383d223ff8e73034736f47b64579
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4601

2 years agoAdd C++ interface for the libbabeltrace2 `bt_integer_range_set_*` API
Philippe Proulx [Thu, 17 Dec 2020 02:13:13 +0000 (21:13 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_integer_range_set_*` API

This patch adds C++ wrappers for Babeltrace 2 integer range set objects.

The four new available types are:

* `bt2::UnsignedIntegerRange`
* `bt2::ConstUnsignedIntegerRange`
* `bt2::SignedIntegerRange`
* `bt2::ConstSignedIntegerRange`

Implicitly convert from a mutable integer range set to a constant
integer range set with converting constructors and assignment operators.

All classes have the `Shared` type alias which is what the shared()
method returns. You can also implicitly convert from a shared mutable
integer range set to a shared constant integer range set.

The corresponding integer range type of any integer range set type `T`
is `T::Range`.

Borrow an integer range by index from the set with operator[]():

    auto myRange = myRangeSet[3];

Get the number of integer ranges in the set with the size() method.

Compare compatible integer range sets with operator==() and
operator!=().

Create a shared integer range set with the static create() methods, for
example:

    auto myRangeSet = bt2::SignedIntegerRangeSet::create();

Those methods can throw a `LibMemoryError` instance.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I14f00e9a020ec8f429bf632132e030ff4cc881a6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4599

2 years agoAdd C++ interface for the libbabeltrace2 `bt_integer_range_*` API
Philippe Proulx [Wed, 16 Dec 2020 21:16:55 +0000 (16:16 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_integer_range_*` API

This patch adds C++ wrappers for Babeltrace 2 integer range objects.

The two new available types are `bt2::ConstUnsignedIntegerRange` and
`bt2::ConstSignedIntegerRange`.

Get the lower and upper bounds of an integer range object with its
lower() and upper() methods.

Compare compatible integer ranges with with operator==() and
operator!=().

You can't create such objects: they are what integer range set methods
(not part of `src/cpp-common/bt2` yet) return.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I712a34756aa170b862b358e3553814ffa59547e8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4597

2 years agoAdd C++ interface for the libbabeltrace2 `bt_value` API
Philippe Proulx [Fri, 11 Dec 2020 00:40:00 +0000 (19:40 -0500)] 
Add C++ interface for the libbabeltrace2 `bt_value` API

This patch adds C++ wrappers for Babeltrace 2 value objects.

The class hierarchy is:

    Value
      NullValue
      BoolValue
      UnsignedIntegerValue
      SignedIntegerValue
      RealValue
      StringValue
      ArrayValue
      MapValue
    ConstValue
      ConstNullValue
      ConstBoolValue
      ConstUnsignedIntegerValue
      ConstSignedIntegerValue
      ConstRealValue
      ConstStringValue
      ConstArrayValue
      ConstMapValue

Implicitly convert from a mutable value to a constant value with
converting constructors and assignment operators.

All classes have the `Shared` type alias which is what the shared()
method returns. You can also implicitly convert from a shared mutable
value to a shared constant value.

Create a shared value with the static create() methods, for example:

    auto myRealVal = bt2::RealValue::create(17.42);

You can also use one of the overloaded bt2::createValue() functions:

    auto myStrVal = bt2::createValue("salut");

Those methods and functions can throw a `LibMemoryError` instance.

`NullValue` has no create() static function as there's nothing to be
created. If you want to wrap the null value singleton, use:

    bt2::NullValue {}

or

    bt2::ConstNullValue {}

If you want a shared null value for any reason, use:

    bt2::NullValue {}.shared()

Downcast a `Value` or `ConstValue` object to a specific value object
with one of its as*() methods, for example:

    auto myBoolVal = myVal.asBool();

Each as*() method checks that the conversion is legal with
BT_ASSERT_DBG().

MapValue::forEach() and ConstMapValue::forEach() accept a function which
receives the key and value of the entry, for example:

    myMapVal.forEach([&](const bpstd::string_view& key,
                         const Value val) {
        // Do something
    });

If you throw anything from such a function, then
bt_value_map_foreach_entry() or bt_value_map_foreach_entry_const()
receives `BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR` or
`BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR`, which in turn makes the
forEach() method throw a `LibError` instance. As of this patch, there's
no way for the user function to gracefully interrupt the iterating
operation (`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPT` and
`BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPT` status code
equivalents).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7c278aa660e9716a69e7d540763dc31623e45fec
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4537

2 years agoAdd `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr())
Philippe Proulx [Fri, 11 Dec 2020 00:27:18 +0000 (19:27 -0500)] 
Add `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr())

This patch adds `src/cpp-common/bt2/internal/utils.hpp`, that is,
internal utils for the libbabeltrace2 C++ interface.

Currently, the new file only contains validateCreatedObjPtr() which
throws a memory error if a pointer is `nullptr`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iba8428da517bbeb0714cd554cb69758a3f7c62c7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4536

2 years agoAdd `src/cpp-common/bt2/lib-error.hpp`
Philippe Proulx [Fri, 11 Dec 2020 00:29:14 +0000 (19:29 -0500)] 
Add `src/cpp-common/bt2/lib-error.hpp`

This new file contains classes for equivalent common libbabeltrace2
errors to be thrown by the libbabeltrace2 C++ interface code.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie70002c0b15e8b6c139b57e8a9ca5f7be5ef98ed
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4535

2 years agoAdd `std::string_view` replacement (`bpstd::string_view`)
Philippe Proulx [Tue, 8 Dec 2020 14:48:44 +0000 (09:48 -0500)] 
Add `std::string_view` replacement (`bpstd::string_view`)

This patch adds an `std::string_view` replacement, `bpstd::string_view`,
which comes from the MIT-licensed
<https://github.com/bitwizeshift/string_view-standalone> project.

Babeltrace 2 cannot use `std::string_view` as it's part of C++17,
whereas the project only requires C++11.

`bpstd::basic_string_view` and `bpstd::string_view` are meant to work
like C++17's `std::basic_string_view` and `std::string_view`.

In any Babeltrace 2 C++ file, include it like this:

    #include "cpp-common/string_view.hpp"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icd9329fb55959de92832f4715b02359e1ef44184
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4519

2 years agoAdd `std::optional` replacement (`nonstd::optional`)
Philippe Proulx [Thu, 27 Jan 2022 16:41:55 +0000 (11:41 -0500)] 
Add `std::optional` replacement (`nonstd::optional`)

This patch adds an `std::optional` replacement, `nonstd::optional`,
which comes from the Boost-licensed
<https://github.com/martinmoene/optional-lite> project.

Babeltrace 2 cannot use `std::optional` as it's part of C++17, whereas
the project only requires C++11.

`nonstd::optional` is meant to work like C++17's `std::optional`.

In any Babeltrace 2 C++ file, include it like this:

    #include "cpp-common/optional.hpp"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icda5af4bd5affd1237786bdb9cb2e64861643440
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4517

2 years agoAdd libbabeltrace2 C++ interface base
Philippe Proulx [Tue, 8 Dec 2020 14:37:17 +0000 (09:37 -0500)] 
Add libbabeltrace2 C++ interface base

This patch adds three new C++ headers to `src/cpp-common/bt2/internal`:

`borrowed-obj.hpp`:
    Defines `bt2::internal::BorrowedObj` which wraps a libbabeltrace2
    object pointer without managing reference counting.

`shared-obj.hpp`:
    Defines `bt2::internal::SharedObj` which contains a
    `bt2::internal::BorrowedObj` instance and manages the underlying
    reference count of the libbabeltrace2 object.

Those classes are meant to be used by public classes in
`src/cpp-common/bt2`, hence their `internal` namespace.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1433ef3c1ed9cca5677012ebe68f63545dbbe547
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4505

2 years agoRe-format new C++ files
Simon Marchi [Sat, 22 Jan 2022 02:11:21 +0000 (21:11 -0500)] 
Re-format new C++ files

Run tools/format-cpp to format the C++ files introduced in the previous
commit.  Then, run:

    sed -ri 's|^\t \*|     *|' $(find . -name '*.cpp' -o -name '*.hpp')
    sed -ri 's|^\t\t \*|         *|' $(find . -name '*.cpp' -o -name '*.hpp')
    sed -ri 's|^\t\t\t \*|             *|' $(find . -name '*.cpp' -o -name '*.hpp')
    sed -ri 's|^\t\t\t\t \*|                 *|' $(find . -name '*.cpp' -o -name '*.hpp')
    sed -ri 's|^\t\t\t\t\t \*|                     *|' $(find . -name '*.cpp' -o -name '*.hpp')

to fix up the multi-line comments which didn't get un-indented by
clang-format.

Change-Id: Iaf22f898ea5d0839b55d9f1bf09eb3754dc56cf2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7105
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf: compile plugin as C++
Simon Marchi [Wed, 19 Jan 2022 18:32:03 +0000 (13:32 -0500)] 
ctf: compile plugin as C++

Rename files under src/plugins/ctf:

 - .c to .cpp
 - .h to .hpp
 - .y to .ypp
 - .l to .lpp

Do the necessary adjustements to get it to compile as C++.  Most changes
are not too surprising, just typical adjustments to casts and things
like that.  But there a few things worthy of mention:

  * g++ 7 doesn't accept non-trivial static initializers.  This means
    that parameter validation descriptors don't compile, and we need
    another approach.  Add constructors (only if __cplusplus is
    defined) to bt_param_validation_value_descr to allow constructing a
    descriptor of the various types.  This allows retaining a syntax
    very close to the existing one.

  * Similary, g++ 7 doesn't like the existing initialization of
    node_error, in parser.ypp.  Explicitly initialize the fields before
    `type` to work around that.

  * About the class hierarchies of ctf_field_class and
    fs_sink_ctf_field_class.  Casting to sub- or super-class is
    currently done by casting to `void *`, which doesn't work in C++.
    Replace that with:

     * to cast to a super-class, get the pointer to the right base, like
     `&fc->base.base`.  It might be a bit ugly, but it's shorter than
     casting and type-safe, so why not.

     * to cast to a sub-class, add some free functions such as
     `ctf_field_class_as_string` that check the field class' type, make
     sure they are indeed an instance of the requested type, and do the
     cast.  Note that this cast still assumes that bases are the first
     member in each sub-class.

  * For the rest, if you are wondering why some change is necessary, try
    reverting and compiling (with a recent gcc and clang), the compiler
    will tell you.

Change-Id: I05b12b906c5df0d89fdc2a70ce4a3b6810b48d41
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7096
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocompat: fix compilation with !BABELTRACE_HAVE_OPEN_MEMSTREAM
Simon Marchi [Sun, 23 Jan 2022 01:37:19 +0000 (20:37 -0500)] 
compat: fix compilation with !BABELTRACE_HAVE_OPEN_MEMSTREAM

When commenting out BABELTRACE_HAVE_OPEN_MEMSTREAM in config.h, to test
the alternative implementation of bt_open_memstream, I get:

      CC       decoder.lo
    In file included from /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:20:
    /home/simark/src/babeltrace/src/compat/memstream.h: In function ‘bt_open_memstream’:
    /home/simark/src/babeltrace/src/compat/memstream.h:257:15: error: implicit declaration of function ‘unlink’ [-Werror=implicit-function-declaration]
      257 |         ret = unlink(tmpname);
          |               ^~~~~~

Fix that by including unistd.h.

Change-Id: Iaa44bc51846a0b8c9e16fdc24d42aef0c5ad0aca
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7107
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf/visitor-generate-ir: rename struct ctf to ctf_visitor_generate_ir
Simon Marchi [Thu, 20 Jan 2022 14:51:17 +0000 (09:51 -0500)] 
ctf/visitor-generate-ir: rename struct ctf to ctf_visitor_generate_ir

This code uses a different name for an externally visible struct type
(struct ctf_visitor_generate_ir) that is never defined, and an internal
struct type (struct ctx).  This requires some casts from the external
type to the internal type at the entry points.  This seems pointless to
me.  Change the internal type to have the same name as the externally
visible type.  It is still opaque from the point of view of the users
outside this compilation unit.

Change-Id: I1503b50658bf43e5cb4a60dfb811384ac5a24359
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7100
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocommon: rename struct mmap_align to mmap_align_data
Simon Marchi [Thu, 20 Jan 2022 14:40:34 +0000 (09:40 -0500)] 
common: rename struct mmap_align to mmap_align_data

In C++, g++ complains that the mmap_align free function shadows the
constructor of the structure of the same name.  Rename the structure to
mmap_align_data to avoid that.

Change-Id: Iae5e0175e3530ebc51804602240ca3037bc02c5b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7099
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoUse __typeof__ instead of typeof
Simon Marchi [Thu, 20 Jan 2022 14:32:56 +0000 (09:32 -0500)] 
Use __typeof__ instead of typeof

When compiling the ctf plugin as C++, a common error was:

    In file included from /home/simark/src/babeltrace/src/plugins/ctf/common/bfcr/bfcr.cpp:23:
    /home/simark/src/babeltrace/src/plugins/ctf/common/bfcr/bfcr.cpp: In function ‘void read_unsigned_bitfield(bt_bfcr*, const uint8_t*, size_t, unsigned int, ctf_byte_order, uint64_t*)’:
    /home/simark/src/babeltrace/src/compat/bitfield.h:343:9: error: ‘typeof’ was not declared in this scope
      343 |         typeof(*(vptr)) *_vptr = (vptr);                                \
          |         ^~~~~~

Use __typeof__ instead, gcc and clang seem happy with that in both C and
C++.  Using `decltype` or `auto` would be more C++-y, but using
__typeof__ works and we don't need separate paths for both languages.

Change-Id: Iec503420f27dd2fe0a246d02af9380a2cff1c96e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7098
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoAdjust .editorconfig
Simon Marchi [Thu, 20 Jan 2022 14:27:40 +0000 (09:27 -0500)] 
Adjust .editorconfig

 - Move current indent_style and tab_width to the [*] section, so it
   applies by default to all files (.c, .h,, .l, .y, Makefile).
 - Add indent_size to [*]
 - Add handling of .hpp and .cpp file, which use indent of 4 spaces and
   no tabs, like .py files.

Change-Id: Ifc8028eb7ba00dfcd2d3904d3301b66bdfa28d79
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7097
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: fix switch cases using wrong enumerator
Simon Marchi [Wed, 19 Jan 2022 22:30:30 +0000 (17:30 -0500)] 
src.ctf.fs: fix switch cases using wrong enumerator

Fix these two cases using CTF_MSG_ITER_MEDIUM_STATUS_FOO instead of
CTF_MSG_ITER_STATUS_FOO.  This isn't a problem in practice, because they
have the same numerical values.

Change-Id: I5d9e22c4e25e9c28a488c4a7b12bf102208dacf0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7095
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: add status conversion function
Simon Marchi [Wed, 19 Jan 2022 22:20:28 +0000 (17:20 -0500)] 
src.ctf.fs: add status conversion function

The line changed, in bt_message_iterator_class_initialize_method_status,
converts a ctf_msg_iter_medium_status to a
bt_message_iterator_class_initialize_method_status using a direct cast.
However, there is not a 1:1 mapping between the two enums.  There are
values in the source that are not valid in the destination.

Replace the int cast with a dedicated conversion method.

Change-Id: Iad24a87bb3926ea9191ca00e18e13df933807f65
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7094
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agotools/format-cpp: enforce clang-format 13
Philippe Proulx [Thu, 27 Jan 2022 16:00:30 +0000 (11:00 -0500)] 
tools/format-cpp: enforce clang-format 13

This patch updates `tools/format-cpp` so that if the `FORMATTER`
environment variable is not empty, the script tries to format with
`$FORMATTER`; otherwise, it tries `clang-format-13 -i` or, if not
available, `clang-format -i`.

In all cases, the script checks the major version of the selected
formatter with `--version`, failing before formatting if it's not 13.

Using exactly clang-format 13 is important for formatting consistency
across developers and CI systems because it's possible that a future
version of clang-format, given the same configuration file, formats
files dissimilarly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic81d8d09c35657b602de044f6123e8b11fc37c44
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7151

2 years ago.clang-format: update for clang-format 13
Philippe Proulx [Thu, 27 Jan 2022 03:02:37 +0000 (22:02 -0500)] 
.clang-format: update for clang-format 13

This patch adds missing clang-format options for clang-format 11 to 13,
as the project now requires clang-format 13.

Notable changes:

* The `AttributeMacros` and `ForEachMacros` lists make clang-format
  aware of those identifiers as attributes and for-each macros so that
  its formatting is more consistent.

  For example,

      bt_list_for_each(pos, head) {
          // ...
      }

  becomes

      bt_list_for_each (pos, head) {
          // ...
      }

* `EmptyLineBeforeAccessModifier` set to `Always` makes sure there's
  always an empty line before an access modifier line
  (`public`/`protected`/`private`).

* `SpaceAroundPointerQualifiers` set to `Both` makes qualifiers such as
  `const` get spaces at their left and right, for example
  `const Hello * const *hello`.

* `SpaceInEmptyBlock` set to `true` makes empty blocks contain a single
  space instead of none (`{ }` instead of `{}`).

* `ReferenceAlignment` set to `Left` makes the `&` of references on the
  left side: `const Hello& hello`.

  Having this makes it possible to set `PointerAlignment` to `Right` so
  that pointers look like they always looked in Babeltrace:
  `const Hello *hello`.

`AlignArrayOfStructures` set to `Left` would be nice but I'm getting
bugs (crashes and wrong formatting) with it as of clang-format 13.0.0
(see <https://bugs.llvm.org/show_bug.cgi?id=52463> and
<https://bugs.llvm.org/show_bug.cgi?id=52425>), therefore I'm leaving it
to `None` until it's fixed.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I743d630242de0cd222df3ac8a932f8b48ff61125
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7150
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agofix: don't add libelf and libdw to global LIBS
Michael Jeanson [Fri, 12 Nov 2021 20:37:17 +0000 (15:37 -0500)] 
fix: don't add libelf and libdw to global LIBS

The default behavior, for AC_CHECK_LIB when the `action-if-found` is NOT
defined, is to prepend the library to LIBS. [1]

"
If action-if-found is not specified, the default action prepends
-llibrary to LIBS and defines ‘HAVE_LIBlibrary’ (in all capitals).
"

It is important to note that the LIBS variable is used for ALL linking.

This is normally not a problem for most distribution since they force
the use of `--as-needed` at the toolchain level (gcc specs) (for example
debian [2]). One could also pass the `--as-needed` flag manually but
libtool reorganize flags in the case of shared object creation [3].

In our case, we always explicitly state the dependencies via the *_LIBADD
automake clause. We do not rely on the LIBS variable.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Libraries.html
[2] https://salsa.debian.org/toolchain-team/gcc/-/blob/master/debian/patches/gcc-as-needed.diff
[3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=347650

Change-Id: Iea7812ccabb17e976362f9ea9412e0834ce946f4
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6745
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Jonathan Rajotte Julien <jonathan.rajotte-julien@efficios.com>
2 years agoCleanup: src.ctf.lttng-live: missing comma between fields
Francis Deslauriers [Fri, 19 Nov 2021 02:38:16 +0000 (21:38 -0500)] 
Cleanup: src.ctf.lttng-live: missing comma between fields

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I959fb77c6c8448240a2a1dc4e65eef571b9af676
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6783
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoDoc: query executor: extra 'get' in sentence
Jérémie Galarneau [Mon, 6 Dec 2021 16:09:15 +0000 (11:09 -0500)] 
Doc: query executor: extra 'get' in sentence

The documentation specifies that:
"The query operation feature exists so that you can get benefit from a
[...]"

I think the author meant to use "[...] so that you can benefit from
[...]", which seems more idiomatic.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0402c48bf18de8138344c230c0b82968ce8f7d5f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6867
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agofix: remove autoconf features default value in help message
Michael Jeanson [Fri, 12 Nov 2021 19:51:57 +0000 (14:51 -0500)] 
fix: remove autoconf features default value in help message

The default values of yes|no can be confusing combined with the
--enable / --disable switches of autoconf, remove them from the help
message.

Before :

  --disable-man-pages     Do not build and install man pages (already built in
                          a distributed tarball
                          [default=yes]

After :

  --disable-man-pages     Do not build and install man pages (already built in
                          a distributed tarball

Change-Id: I7a290aaacbcd0d04e0efd161357755451e5d4d4d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6742
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoUpdate CONTRIBUTING.adoc to mention tests/utils/env.sh
Simon Marchi [Mon, 22 Nov 2021 21:52:47 +0000 (16:52 -0500)] 
Update CONTRIBUTING.adoc to mention tests/utils/env.sh

We can simplify the explanations of how to set up the appropriate
environment for running tests to just mention sourcing env.sh.

Change-Id: I905f8ef94b6b5d904ad62d367f04a29ede687213
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6725
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
2 years agoconfigure: Introduce macro ae_in_git_repo
Michael Jeanson [Fri, 19 Mar 2021 19:29:18 +0000 (15:29 -0400)] 
configure: Introduce macro ae_in_git_repo

This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.

Change-Id: I03cb700240b24bbd7146f40b6634db11fe1d17c3
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5272
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoconfigure: centralize version information
Michael Jeanson [Fri, 19 Mar 2021 18:33:30 +0000 (14:33 -0400)] 
configure: centralize version information

Centralize version information at the beginning of configure.ac to
improve readability.

This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.

Change-Id: I7a4d8615737189afb9b3e19ef5a53150561844a1
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5271
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoconfigure: regroup program checks
Michael Jeanson [Fri, 19 Mar 2021 18:31:11 +0000 (14:31 -0400)] 
configure: regroup program checks

This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.

Change-Id: Ie8a1f23f9f2e9760126cffbabc49204b9c230b21
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5270
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoconfigure: Normalize indentation to 2 spaces
Michael Jeanson [Fri, 19 Mar 2021 18:22:07 +0000 (14:22 -0400)] 
configure: Normalize indentation to 2 spaces

We have a mix of tab and space indentation, normalize to 2 spaces to
help with the high level of indentation required to make M4sh somewhat
readable.

Change-Id: Id8a4d3eca4985161a2f49355881c63cbbffea29b
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5269
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoconfigure: cleanup typos and sorting
Michael Jeanson [Mon, 1 Mar 2021 23:47:45 +0000 (18:47 -0500)] 
configure: cleanup typos and sorting

This is part of an effort to standardize our autotools setup across
projects to simplify maintenance.

Change-Id: I3323c010efad184167e7fa43ac8bd7db891bcb9d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5268
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoAdd --enable-asan configure option
Simon Marchi [Fri, 14 May 2021 14:23:19 +0000 (10:23 -0400)] 
Add --enable-asan configure option

It's possible to build babeltrace with AddressSanitizer by adding
-fsanitize=address to CFLAGS/LDFLAGS, but it causes some issues.  These
issues are related to the fact that if libasan.so is to be loaded, it
must be the first library to be loaded.  When a Python interpreter loads
the bt2 module, that pulls in libbabeltrace2.so, which pulls libasan.so.
libasan.so then complains about not being the first loaded libraries.
The only way I know to fix this is to LD_PRELOAD libasan.so in the
Python interpreter.

The first case where this happens is when building the Python bindings.
This is because the Sphinx tool (so, the Python interpreter) loads the
bt2 Python module in order to obtain the documentation.

The other case is when running the Python bindings tests, the test
runner is in Python, and the .py tests imports the bt2 module.

In both cases, libasan unfortunately finds some leaks in the Python
interpreter.  We must therefore disable leak reporting with
ASAN_OPTIONS=detect_leaks=0.  This is particularly unfortunate for the
Python bindings tests, because it would be nice to know about leaks that
are libbabeltrace2's or the tests' fault.  But I don't see any way
around it.  For running Sphinx, we don't care about leaks.

Since we need to set some special environment variables when building
and checking if AddressSanitizer is used, it's much easier if the build
system knows that we want to use AddressSanitizer.  This patch therefore
adds a new `--enable-asan` option that developers should use in order to
use AddressSanitizer, instead of manually adding -fsanitize=address in
CFLAGS/LDFLAGS.

If `--enable-asan` is used, the following command will be invoked :

  $(CC) -print-file-name=libasan.so

... to find the path of the libasan.so library associated to the
compiler being used (it's important that we pre-load the right version
of libasan.so).

For the Python bindings documentation generation, the command is used in
the Makefile where Sphinx is invoked.

For tests, a boolean is written in a generated tests/utils/env.sh file,
which is sourced by tests/utils/utils.sh and the command is then used
when running the tests.

Change-Id: I5e0ca10532605cfdfda08b3ee4fcc39922480797
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5860
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
2 years agoctf: logging: missing comma and space between fields
Francis Deslauriers [Fri, 12 Nov 2021 14:01:39 +0000 (09:01 -0500)] 
ctf: logging: missing comma and space between fields

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I75a0021fd465d08df898b9f0557f5129f09a9ab7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6723
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoAdd a single generated env file to the test suite
Michael Jeanson [Tue, 31 Aug 2021 15:25:18 +0000 (11:25 -0400)] 
Add a single generated env file to the test suite

Regroup all the configure detected values relevant to the test suite in
a single generated file. This file will be automatically sourced by the
test suite in most scenarios but can also be sourced in the shell of a
user.

 * All user overridable variables start with 'BT_TESTS_'.
 * The priority for variables is :
     Environment -> env.sh -> utils.sh (defaults).
 * A user can source 'env.sh', override some of the values and manually
   run test scripts.
 * The test suite can run without an 'env.sh' file present.

Scenarios:

 * Manually running tests in an in-tree build:

   The test suite sources 'env.sh' relative to itself, no environment
   variables required.

 * Manually running tests in an out-of-tree build:

   The user sets BT_TESTS_BUILDDIR in its environment or sources 'env.sh'.

 * Running the test suite with 'make check' in either builds:

   The Makefile sets BT_TESTS_BUILDDIR in the environment which allows
   the test suite to source env.sh in either in-tree or out-of-tree builds.

Change-Id: I1ba3775ea3d724345cab769af9b2efc22ee53585
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6314
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoctf: change logging of raw packet data to TRACE level
Francis Deslauriers [Thu, 11 Nov 2021 18:33:41 +0000 (13:33 -0500)] 
ctf: change logging of raw packet data to TRACE level

This logging statement is very noisy. Even if the packet is mostly
empty, the logging statement will print ~120 lines of 0x00 bytes.

For example:

  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 c11ffcc12a8a00ec460a46f1818701327971f76a000000001400000000000000  ????*???F?F????2yq?j????????????
  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 d2e48fbadb1c070047ce81f7db1c0700a0020000000000000080000000000000  ????????G???????????????????????
  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 0000000000000000000000000000000014000000000000000000000000000000  ????????????????????????????????
  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 0000000000000000000000000000000000000000000000000000000000000000  ????????????????????????????????
  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 0000000000000000000000000000000000000000000000000000000000000000  ????????????????????????????????
  11-11 18:29:32.493 59609 59609 D PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:510 0000000000000000000000000000000000000000000000000000000000000000  ????????????????????????????????
  ...

This commit changes the log-level of this statement to TRACE.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idd3fc655f2fffc77130a7898ef94e7c117bcd9ec
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6705
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: src.ctf.lttng-live: leaking late message after fixing
Francis Deslauriers [Thu, 11 Nov 2021 18:11:12 +0000 (13:11 -0500)] 
Fix: src.ctf.lttng-live: leaking late message after fixing

The late message is replaced by a new one with a correct timestamp, we
need to put the reference we have on it.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I124c9da9b29d05ee85ece4c32505655e87b3b43e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6704
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: use optional pattern for `ctf_stream_class_id`
Francis Deslauriers [Wed, 10 Nov 2021 18:59:59 +0000 (13:59 -0500)] 
src.ctf.lttng-live: use optional pattern for `ctf_stream_class_id`

Instead of checking for an initial boundary value to signify if the
value is initialized use a optional like anonymous struct with a
`is_set` flag.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3045ef884345bea58824fd2170d29e982d219b7a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6699
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: add detailed error reporting for late msg
Francis Deslauriers [Mon, 8 Nov 2021 23:17:08 +0000 (18:17 -0500)] 
src.ctf.lttng-live: add detailed error reporting for late msg

The only scenario in which it's okay and fixable to received a late
message is when:
  1. the late message is a discarded packets or discarded events
    message,
  2. this component sent am inactivity message downstream, and
  3. the timestamp of the late message is within the inactivity timespan
    we sent downstream through the inactivity message.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I46ec383bffdce237fb18590354bbe2d64374ff3e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6698
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: src.ctf.lttng-live: using `last_inactivity_ts` uninitialized
Francis Deslauriers [Wed, 10 Nov 2021 18:16:15 +0000 (13:16 -0500)] 
Fix: src.ctf.lttng-live: using `last_inactivity_ts` uninitialized

Observed issue
==============
I saw the following error message in the logs of a `lttng clear` test case
crash:

  bt_clock_class_cycles_to_ns_from_origin@clock-class.c:311 Cannot convert cycles to nanoseconds from origin for given clock class: value overflows the signed 64-bit integer range:
    cc-addr=0x55f5b33280f0, cc-name="monotonic", cc-freq=1000000000,
    cc-partial-descr="Monotonic Clock",
    cc-uuid="c812f5e1-ceda-4f13-8b99-23a5be8a2908",
    cc-is-frozen=0, cc-precision=0, cc-offset-s=1634653310,
    cc-offset-cycles=492621904, cc-origin-is-unix-epoch=1,
    cc-base-offset-ns=1634653310492621904, cc-cs-pool-size=6, cc-cs-pool-cap=15,
    cycles=9223372036854775808

Take note that last line of this log statement shows a `cycles` value of
9223372036854775808. This value is `INT64_MIN` stored on a 64bits
unsigned integer.

Cause
=====
This error occurs because the
`lttng_live_stream_iterator::last_inactivity_ts` field is used without
being initialized to an actual value.

This field is a `uint64_t` and is initialized to `INT64_MIN` with the
intent of setting it to the minimum value and used as is in that error
statement.

Fix
===
Change the `last_inactivity_ts` field to an anonymous struct that
contains an `is_set` boolean and the value. Use the `is_set` flag to
ensure we only use this field once initialized.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I24ba0dd9267508b2c9f0de99386a16b1ce022329
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6677
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: Extract `handle_late_message()` function for future fix
Francis Deslauriers [Wed, 10 Nov 2021 16:48:35 +0000 (11:48 -0500)] 
src.ctf.lttng-live: Extract `handle_late_message()` function for future fix

An upcoming commit will include a fix regarding the handling of late
messages. So, extract this logic into its own function simplifies the
that future commit.

No change of behaviour intended by this commit.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ida4f980ab2574ebc64fb455e22047233c0f25cee
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6697
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: Add setter for stream iterator state for uniform logging
Francis Deslauriers [Mon, 8 Nov 2021 22:25:39 +0000 (17:25 -0500)] 
src.ctf.lttng-live: Add setter for stream iterator state for uniform logging

Debugging LTTng live issues is tricky and having clean and uniform
logging statement for each state transition is useful to understand the
current state a lttng-live source.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ifc334bbb2afe78f9ea57fe24b0ad3860b59b0640
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6676
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.lttng-live: Add debug statements and comments
Francis Deslauriers [Mon, 8 Nov 2021 15:06:37 +0000 (10:06 -0500)] 
src.ctf.lttng-live: Add debug statements and comments

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I55395dfc4ba2b5aa5eacd092c22fd88059a9ea24
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6652
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoMove bt_message_type_string to common
Simon Marchi [Wed, 10 Nov 2021 15:22:58 +0000 (10:22 -0500)] 
Move bt_message_type_string to common

Move it to src/common/common.h, so that it can be used by plugins.
Rename it to bt_common_message_type_string.

Change-Id: Ica2fc901a35a142ac54a68b3a69a3470e92a327a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6694
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoFix: add missing cases in enum-to-string functions
Simon Marchi [Wed, 10 Nov 2021 15:17:41 +0000 (10:17 -0500)] 
Fix: add missing cases in enum-to-string functions

Change the enum-to-string functions to not use a default case, such that
the compiler will give a -Wswitch warning if an enumerator is not
handled.  Add some missing ones found by such warnings.

Put a bt_common_abort call after each switch (rather than returning
"(unknown)", because there's no way in theory that we can reach that.
Having anything else would be a bug we would want to fix in babeltrace.

Change-Id: I2cfae112386aede4844062be51dba009a1e9a056
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6693
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agotests: rename BT_OS_TYPE to BT_TESTS_OS_TYPE
Simon Marchi [Tue, 28 Sep 2021 20:43:44 +0000 (16:43 -0400)] 
tests: rename BT_OS_TYPE to BT_TESTS_OS_TYPE

Follow the naming scheme used by other testsuite environment variables.

Change-Id: I26dfe20b0c06a9de4d1e4bd1418f15d17ed4477c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6455
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoFix: build with `--enable-python-bindings` fails
Francis Deslauriers [Thu, 9 Sep 2021 19:09:26 +0000 (15:09 -0400)] 
Fix: build with `--enable-python-bindings` fails

Issue
=====
Configuring with the following option:
  `./configure --disable-man-pages --enable-python-bindings`
makes the build fails with the following error:
  make[4]: Entering directory '/home/frdeso/projets/babeltrace/src/bindings/python/bt2'
  touch copy-static-deps.stamp
    SWIG      bt2/native_bt.c
  /bin/bash: -MD: command not found

This error is due to the fact that the `SWIG` automake variable is empty
leading to that unexpected `-MD: command not found` error.

Currently, in the `configure.ac`, the `SWIG` variable is only set when the
`--enable-python-plugins` is enabled. This is wrong because it's the
bindings that require SWIG.

Fix
===
Define the `SWIG` variable when the bindings are enabled.

Note
====
Enabling the plugins requires also enabling the bindings.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie6eb21c5bd2ebc1fa97751148b44c8e9263dcf0c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6378
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
2 years agoctf: append error causes when returning errors
Simon Marchi [Wed, 5 May 2021 14:09:23 +0000 (10:09 -0400)] 
ctf: append error causes when returning errors

Change as many error paths as possible in the CTF metadata parsing code
to append error causes.  This will give clearer error messages to users
when the metadata can't be parsed.  The errors are already printed to
stderr, but this will make them more obvious, as they will be printed in
the error stack.

For example, a syntax error caught by the metadata-info query:

    $ cat test/metadata
    /* CTF 1.8 */

    trace {
      foo = ;
    };
    $ ./src/cli/babeltrace2 query src.ctf.fs metadata-info -p 'path=test'
    ...
    ERROR:    [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:649)
      Failed to query component class: unknown error: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1 object="metadata-info"
    CAUSED BY [libbabeltrace2] (/home/simark/src/babeltrace/src/lib/graph/query-executor.c:231)
      Component class's "query" method failed: query-exec-addr=0x60b000001430, cc-addr=0x60f000000220, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from the file sy",
      cc-is-frozen=0, cc-so-handle-addr=0x607000000100, cc-so-handle-path="/home/simark/build/babeltrace/src/plugins/ctf/babeltrace-plugin-ctf.la", object="metadata-info", params-addr=0x606000000980,
      params-type=MAP, params-element-count=1, log-level=WARNING
    CAUSED BY ['source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/fs-src/query.c:121)
      Cannot update metadata decoder's content: path="test".
    CAUSED BY ['source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:279)
      Cannot create the metadata AST out of the metadata text: mdec-addr=0x60c000003a00
    CAUSED BY [CTF metadata parser] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/parser.y:925)
      At line 4 in metadata stream: syntax error, unexpected CTF_SEMICOLON: token=";"

And a semantic error caught when trying to read the trace:

    $ cat test/metadata
    /* CTF 1.8 */

    trace {
      byte_order = 2;
    };
    $ ./src/cli/babeltrace2 test
    ...
    ERROR:    [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:2462)
      Cannot create components.
    CAUSED BY [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:2277)
      Cannot create component: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1, comp-name="auto-disc-source-ctf-fs"
    CAUSED BY [libbabeltrace2] (/home/simark/src/babeltrace/src/lib/graph/graph.c:1055)
      Component initialization method failed: status=ERROR, comp-addr=0x60c000004f00, comp-name="auto-disc-source-ctf-fs", comp-log-level=WARNING, comp-class-type=SOURCE, comp-class-name="fs", comp-class-partial-descr="Read CTF traces
      from the file sy", comp-class-is-frozen=1, comp-class-so-handle-addr=0x607000000100, comp-class-so-handle-path="/home/simark/build/babeltrace/src/plugins/ctf/babeltrace-plugin-ctf.la", comp-input-port-count=0,
      comp-output-port-count=0
    CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.c:1186)
      Cannot create trace for `/home/simark/build/babeltrace/test`.
    CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:327)
      Failed to visit AST node to create CTF IR objects: mdec-addr=0x60c0000052c0, ret=-22
    CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:4722)
      At line 0 in metadata stream: Cannot set trace's native byte order: ret=-22
    CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:4148)
      At line 4 in metadata stream: Invalid `byte_order` attribute in trace (`trace` block): expecting `le`, `be`, or `network`.
    CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:920)
      At line 4 in metadata stream: "byte_order" attribute: expecting `be`, `le`, `network`, or `native`.

The metadata parser can be used in both component and component class
context.  For logging purposes, only a component is passed through
ctf_metadata_decoder_config, when the parsing is done in the context of
a component.  To be able to append error causes with the right component
class actor, add the option to pass a component class as well.

Change-Id: I8db734fa27cea5ea3b911e36800d535290c51ad9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5693
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: ctf: free all scopes of ctf_scanner
Simon Marchi [Wed, 5 May 2021 19:06:18 +0000 (15:06 -0400)] 
Fix: ctf: free all scopes of ctf_scanner

When parsing using a ctf_scanner does not complete, because an error is
encountered, ctf_scanner_free does not properly free all the scopes
allocated by and held by ctf_scanner.

This can be observed on an ASan-enabled build of Babeltrace.  Create a
test/metadata file with:

    /* CTF 1.8 */

    trace {}

and run:

    $ LIBBABELTRACE2_NO_DLCLOSE=1 ./src/cli/babeltrace2 query src.ctf.fs metadata-info -p 'path=test'

I get:

    Direct leak of 16 byte(s) in 1 object(s) allocated from:
        #0 0x7ffff7677459 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
        #1 0x7ffff35605b9 in push_scope /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/parser.y:296
        #2 0x7ffff356726f in yyparse /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/parser.y:1478
        #3 0x7ffff3563297 in ctf_scanner_append_ast /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/parser.y:958
        #4 0x7ffff3598a6a in ctf_metadata_decoder_append_content /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:277
        #5 0x7ffff3626fff in metadata_info_query /home/simark/src/babeltrace/src/plugins/ctf/fs-src/query.c:118
        #6 0x7ffff3625ac1 in ctf_fs_query /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.c:2454
        #7 0x7ffff74a616d in bt_query_executor_query /home/simark/src/babeltrace/src/lib/graph/query-executor.c:219
        #8 0x5555555a09e2 in cli_query /home/simark/src/babeltrace/src/cli/babeltrace2-query.c:62
        #9 0x555555574fb3 in query /home/simark/src/babeltrace/src/cli/babeltrace2.c:113
        #10 0x5555555775c6 in cmd_query /home/simark/src/babeltrace/src/cli/babeltrace2.c:645
        #11 0x555555582ae7 in main /home/simark/src/babeltrace/src/cli/babeltrace2.c:2682
        #12 0x7ffff70ebb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

What happens is: while parsing, push_scope is called to allocate a new
scope and make it current (ctf_scanner::cs).  The previous current scope
becomes the parent of the new scope.  When everything goes right,
pop_scope is called as many times as push_scope is called, freeing all
the scopes created during parsing.  ctf_scanner_free doesn't need to
free any scopes in that case.  However, if parsing ends early to due to
an error, ctf_scanner_free is called on a scanner that may have some
scopes that were pushed and not popped.  If so, it needs to free them.

Change it to start freeing ctf_scanner::cs (the innermost scope) and
then go up the chain.  The last scope in that chain is
ctf_scanner::root_scope.  This one doesn't need free'ing, as its storage
is allocate within the ctf_scanner structure, but it still needs
finalizing.

Change-Id: I3a1b83af8128cd1b8a3ee235311dd41e45e29ea2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5692
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: ctf: set `ret` on error paths
Simon Marchi [Wed, 5 May 2021 14:19:19 +0000 (10:19 -0400)] 
Fix: ctf: set `ret` on error paths

The error paths touched by this patch currently don't set the `ret`
variable, resulting in the error not being communicated to the caller.
Fix that.

Change-Id: If044e4ff28a98bda408610c1c2f85d7fe13ea1c1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5691
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agolib: make auto-seek skip over packet messages without clock snapshots
Simon Marchi [Wed, 5 May 2021 14:08:35 +0000 (10:08 -0400)] 
lib: make auto-seek skip over packet messages without clock snapshots

Trying to use a CTF trace with packets that don't have beginning clock
snapshots [1] with a trimmer component invokes the "auto-seek" seeking
mechanism provided by the lib, and leads to:

    $ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
    ...
    Babeltrace 2 library postcondition not satisfied.
    ------------------------------------------------------------------------
    Condition ID: `post:message-iterator-class-next-method:packet-message-has-default-clock-snapshot`.
    Function: bt_message_iterator_class_next_method().
    ------------------------------------------------------------------------
    Error is:
    Packet message has no default clock snapshot: addr=0x607000001fa0, type=PACKET_BEGINNING, is-frozen=0, graph-addr=0x612000001840, packet-is-frozen=1, packet-context-field-addr=(nil), packet-stream-addr=0x60d000001cb0, packet-stream-id=0, packet-stream-name="/home/simark/build/babeltrace/nvctf/channel0", packet-trace-class-addr=0x60d000001be0

The problem is with the auto_seek_handle_message function assuming that
all packet beginning messages have a clock snapshot.  Fix it by making
it check the relevant property in the stream class, and skip the message
if it doesn't have a clock snapshot.

Change it as well for packet end, discarded event and discarded packet
messages, although I did not test these cases.

[1] Like the trace from
    https://lists.lttng.org/pipermail/lttng-dev/2021-May/029955.html

Change-Id: I6be0ab013285c2a01125dbf27161d31e227250a8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5690
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agotrimmer: don't get clock snapshots from messages that don't have them
Simon Marchi [Wed, 5 May 2021 14:07:56 +0000 (10:07 -0400)] 
trimmer: don't get clock snapshots from messages that don't have them

When using a trace with packets that don't have beginning clock
snapshots [1] with a trimmer component, we hit:

    $ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55"
    ...
    Condition ID: `pre:message-packet-beginning-borrow-default-clock-snapshot-const:msg-stream-class-packets-have-beginning-default-clock-snapshot`.
    Function: bt_message_packet_beginning_borrow_default_clock_snapshot_const().
    ------------------------------------------------------------------------
    Error is:
    Message's stream class packets don't have beginning default clock snapshot.

The problem is with the trimmer's get_msg_ns_from_origin function
assuming that that packet begnning messages have a clock snapshot if the
stream class has a clock class (which I suppose was true in early
development stages).

Fix that by making get_msg_ns_from_origin skip over messages
that don't have clock snapshots.  In addition to packet beginning
messages, I found (just by inspection, not tested) that packet end,
discarded events and discarded packets messages are in the same
situation.

Note that the trimmer component currently requires packet messages to
have clock snapshots in order to work.  However, the check for this
happens later, during the TRIM state.  get_msg_ns_from_origin is called
early, during the SET_BOUNDS_NS_FROM_ORIGIN state.  So in
get_msg_ns_from_origin, we can't assume that messages we encounter have
them.

[1] Like the trace from
    https://lists.lttng.org/pipermail/lttng-dev/2021-May/029955.html

Change-Id: Ie56b3250829197eadb823b7ac5d23efc46d12b3c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5689
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agolib: enforce preconditions when getting packet message clock snapshots
Simon Marchi [Wed, 5 May 2021 13:52:13 +0000 (09:52 -0400)] 
lib: enforce preconditions when getting packet message clock snapshots

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>
2 years agocommon: move bt_component_class_type_string here, use it more
Simon Marchi [Fri, 10 Sep 2021 03:25:19 +0000 (23:25 -0400)] 
common: move bt_component_class_type_string here, use it more

I spotted some messages in the CLI code that could print the component
class type as a string rather than an integer.
bt_component_class_type_string is not accessible to the CLI code,
because it's in a lib header.  Move it to common/common.h, and rename it
accordingly.

Adjust all existing callers, and use it in cli/babeltrace2.c.

Before:

    $ ./src/cli/babeltrace2 query src.ctf.fs foo
    ...
    Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1 object="foo"

After:

    $ ./src/cli/babeltrace2 query src.ctf.fs foo
    ...
    Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=SOURCE object="foo"

Change-Id: I88f01ac7cae9723ce11dbf2ec0843a06d761abb6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6273
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/common/uuid.h: wrap code in C++ guards
Philippe Proulx [Thu, 17 Dec 2020 02:22:43 +0000 (21:22 -0500)] 
src/common/uuid.h: wrap code in C++ guards

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia87b11fe0a7015085325259446f15393dc1f1e19
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4600
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoAdd `tools/format-cpp` script
Philippe Proulx [Tue, 15 Dec 2020 15:36:15 +0000 (10:36 -0500)] 
Add `tools/format-cpp` script

The new `format-cpp` script uses `clang-format -i` to inline-format all
the C++ files except `src/cpp-common/optional/optional.hpp` and
`src/cpp-common/string_view/string_view.hpp`.

You can run it from any directory: it always runs `clang-format -i` for
the whole project.

By default, the script runs `clang-format -i`; you can override this
with the `FORMATTER` environment variable, for example:

    $ FORMATTER='clang-format-10 -i' ./tools/format-cpp

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1049eabf8da71ce5c1d8443e1e2cdc9a73f4b4d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4592
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agosrc/common/common.h: do not use `void *` in arithmetic
Philippe Proulx [Mon, 14 Dec 2020 18:07:40 +0000 (13:07 -0500)] 
src/common/common.h: do not use `void *` in arithmetic

This avoids a G++ warning:

> common.h:445:22: warning: pointer of type ‘void *’ used in arithmetic
> [-Wpointer-arith]

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I71bad4b54a0aa3baa806e5c29e060d0047c007f2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4566
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
This page took 0.057869 seconds and 4 git commands to generate.