10 months agoRelease: Babeltrace 2.0.4 "Amqui" v2.0.4
Jérémie Galarneau [Tue, 23 Feb 2021 16:20:35 +0000 (11:20 -0500)] 
Release: Babeltrace 2.0.4 "Amqui"

Signed-off-by: Jérémie Galarneau <>
Change-Id: I571c7e7db416d964f3b66ea072fc6b06b6216368

11 months agoFix: macro name for "get supported mip versions method" attribute descriptor
Simon Marchi [Tue, 26 Jan 2021 21:28:12 +0000 (16:28 -0500)] 
Fix: macro name for "get supported mip versions method" attribute descriptor


    In file included from /home/simark/src/babeltrace/include/babeltrace2/babeltrace.h:67,
                     from /home/simark/src/babeltrace/src/cpp-common/bt2/plugin-dev.hpp:10,
                     from /home/simark/src/babeltrace/tests/cpp-common/plugin-dev/plugin.cpp:7:
    /home/simark/src/babeltrace/include/babeltrace2/plugin/plugin-dev.h:2214:91: error: ‘BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS’ was not declared in this scope; did you mean ‘BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS_METHOD’?
     2214 |  __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_get_supported_mip_versions_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS, _plugin_id, _component_class_id, sink, _method)
          |                                                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/include/babeltrace2/plugin/plugin-dev.h:2641:11: note: in definition of macro ‘__BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE’
     2641 |   .type = _attr_type,     \
          |           ^~~~~~~~~~
    /home/simark/src/babeltrace/include/babeltrace2/plugin/plugin-dev.h:2224:2: note: in expansion of macro ‘BT_PLUGIN_SINK_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_WITH_ID’
          |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/src/cpp-common/bt2/plugin-dev.hpp:110:5: note: in expansion of macro ‘BT_PLUGIN_SINK_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD’
      110 |     BT_PLUGIN_SINK_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD(                              \
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/tests/cpp-common/plugin-dev/plugin.cpp:19:1: note: in expansion of macro ‘BT_CPP_PLUGIN_SINK_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD’
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I think it should be


instead of


Change-Id: I397da2945e3eedcedefe713fbb9a469633c57f7a
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
11 months agoFix: configure: support Autoconf 2.70
Simon Marchi [Tue, 26 Jan 2021 16:42:30 +0000 (11:42 -0500)] 
Fix: configure: support Autoconf 2.70

This patch is stolen and adapted from lttng-tools' patch:;a=commit;h=faa88ea855741f5c356d223011ff4b347576c7d2

The newly-released autoconf 2.70 introduces a number of breaking
changes [1] and is being rolled-out by some distros.

Amongst those changes, the AC_PROG_CC_STDC macro is marked as obsolete
and was merged into AC_PROG_CC, which we already use. On 2.70, this
results in a warning which we handle as an error.

A version check is added to invoke the AC_PROG_CC_STDC macro only when
running a pre-2.70 version of autoconf, fixing the issue.

The AC_PROG_LEX now takes an argument, and the argument-less version is
marked as obsolete. The macro is invoked with the `noyywrap` option, as
recommended in the documentation.

Also, the AX_PTHREAD macro makes use of the $as_echo built-in shell
variable which no longer exists in 2.70. A patch was submitted to the
GNU Autoconf archive in March, but there have been no signs of life
given since then [2].

As such, our local copy is updated to the latest version and the patch
(which looks fairly straight-forward / safe) is applied. This should
minimize changes once we go back to an "official" version of the macro.

Some issues with glib2 remain: warning: The macro `AC_TRY_RUN' is obsolete. You should run autoupdate.
    ./lib/autoconf/general.m4:2996: AC_TRY_RUN is expanded from...
    /usr/share/aclocal/glib-2.0.m4:11: AM_PATH_GLIB_2_0 is expanded from... the top level warning: The macro `AC_TRY_LINK' is obsolete. You should run autoupdate.
    ./lib/autoconf/general.m4:2919: AC_TRY_LINK is expanded from...
    /usr/share/aclocal/glib-2.0.m4:11: AM_PATH_GLIB_2_0 is expanded from... the top level

Those have been fixed upstream:

so it's always possible to get the modifications from there for local


Change-Id: I484b2caed1c7e89e100be76b7853099239397012
Signed-off-by: Michael Jeanson <>
11 months agoport: add 'notext' keyword linker support
Michael Jeanson [Mon, 19 Oct 2020 16:26:36 +0000 (12:26 -0400)] 
port: add 'notext' keyword linker support

Check if the linker support the 'notext' keyword to allow relocations
against read-only segments. GNU ld defaults to notext but LLVM's ld does
not, both linkers support the keyword.

This is required for the plugins section symbols.

Signed-off-by: Michael Jeanson <>
Change-Id: I952586447a837ce48711a218a2d03050ef3deb1a

11 months agoport: fix compat/endian.h on FreeBSD
Michael Jeanson [Mon, 19 Oct 2020 17:04:17 +0000 (13:04 -0400)] 
port: fix compat/endian.h on FreeBSD

Signed-off-by: Michael Jeanson <>
Change-Id: I2f346213786392fc62ed1a815ccd367f162710ed

11 months agoport: tests: Add sys/wait.h include for FreeBSD
Michael Jeanson [Mon, 19 Oct 2020 16:44:32 +0000 (12:44 -0400)] 
port: tests: Add sys/wait.h include for FreeBSD


Signed-off-by: Michael Jeanson <>
Change-Id: I2a74762da3ffba58a27fecc3c0d85cc9007bd7c4

11 months agoport: namespace align.h with BT_ prefix
Michael Jeanson [Mon, 19 Oct 2020 16:37:53 +0000 (12:37 -0400)] 
port: namespace align.h with BT_ prefix

ALIGN is defined in FreeBSD system includes with an incompatible
signature, namespace our internal version.

Signed-off-by: Michael Jeanson <>
Change-Id: I2d7e24ebb1756b0e115118fa3f2e6ebc8595fea5

11 months agoport: Add sys/param.h include to compat/limits.h for FreeBSD
Michael Jeanson [Mon, 19 Oct 2020 16:29:53 +0000 (12:29 -0400)] 
port: Add sys/param.h include to compat/limits.h for FreeBSD


Signed-off-by: Michael Jeanson <>
Change-Id: I3adf11a260752cd6805802966be4db38f221d3ea

11 months agoport: disable debug-info by default on FreeBSD
Michael Jeanson [Mon, 19 Oct 2020 16:18:07 +0000 (12:18 -0400)] 
port: disable debug-info by default on FreeBSD

Signed-off-by: Michael Jeanson <>
Change-Id: Iea229bdcb00ae51a83fc7c5570415a5a7d264752

11 months agoFix: disable deprecation warnings for SWIG generated code
Michael Jeanson [Tue, 26 Jan 2021 20:14:09 +0000 (15:14 -0500)] 
Fix: disable deprecation warnings for SWIG generated code

There is nothing we can do about deprecations in SWIG generated code so
silence this warning.

Signed-off-by: Michael Jeanson <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia3188e6e8fcb52a635d6793f4a40808479860252

11 months agoport: 'ls --ignore=' is a GNU extension
Michael Jeanson [Mon, 19 Oct 2020 22:13:35 +0000 (18:13 -0400)] 
port: 'ls --ignore=' is a GNU extension

Use grep -v instead to filter README.adoc.

Signed-off-by: Michael Jeanson <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: I9b58120ee94dc4caa7b1e69bb4a4807f2af6f98c

13 months agotests/lib/test_trace_ir_ref.c: rename user structure
Fabrice Fontaine [Sat, 26 Sep 2020 20:03:10 +0000 (22:03 +0200)] 
tests/lib/test_trace_ir_ref.c: rename user structure

Rename user structure to bt_user to avoid the following build failure
with uclibc:

test_trace_ir_ref.c:41:8: error: redefinition of 'struct user'
 struct user {
In file included from /home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/sys/procfs.h:33,
                 from /home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/sys/ucontext.h:25,
                 from /home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/signal.h:329,
                 from /home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/glib-2.0/glib/gbacktrace.h:36,
                 from /home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/bin/../arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/glib-2.0/glib.h:34,
                 from ../../src/common/assert.h:28,
                 from ../../src/lib/object.h:28,
                 from test_trace_ir_ref.c:25:
/home/naourr/work/instance-0/output-1/per-package/babeltrace2/host/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/include/sys/user.h:48:8: note: originally defined here
 struct user


Signed-off-by: Fabrice Fontaine <>
Change-Id: I1a9d912545f781d61d6e3c62b31998285d2a237c
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
(cherry picked from commit 8009058387e16d70c065f8afb24953ed389c18a6)
Reviewed-by: Simon Marchi <>
13 months agoFix: sink.ctf.fs: fix logic of make_unique_stream_file_name
Simon Marchi [Wed, 2 Dec 2020 22:36:05 +0000 (17:36 -0500)] 
Fix: sink.ctf.fs: fix logic of make_unique_stream_file_name

The logic in make_unique_stream_file_name is wrong.  It tries names as
long as the candidate exists _and_ is named "metadata".  The intent here
is that we keep trying names as long as the candidate name names an
already existing file _or_ is named "metadata".  So the && should be a

The impact of this bug is that if two streams have the same name,
they'll write to the same file, with troubling consequences (see bug
1279 [1]).

Add a test where `sink.ctf.fs` writes a trace with two streams with the
same name, and one stream named "metadata".


Change-Id: Ifaa30459574229aa5e607095f65033d2caae188f
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>

13 months agoFix: sink.ctf.fs: remove spurious directory level when using assume-single-trace
Simon Marchi [Wed, 2 Dec 2020 21:04:19 +0000 (16:04 -0500)] 
Fix: sink.ctf.fs: remove spurious directory level when using assume-single-trace

The behavior of `sink.ctf.fs` with the `assume-single-trace=true`
parameter does not match the documentation nor the comments in the code.
The man page says:

    If the assume-single-trace parameter is true, then the output trace
    path to use for the single input trace is the directory specified by
    the path parameter.

What I understand from this is that if you pass `path=/tmp/yo`, that
should produce the `/tmp/yo/metadata` file and the data files alongside

The documentation on the `fs_sink_comp::assume_single_trace` says:

     * True if the component assumes that it will only write a
     * single CTF trace (which can contain one or more data
     * streams). This makes the component write the stream files
     * directly in the output directory (`output_dir_path` above).
    bool assume_single_trace;

The `output_dir_path` would contain `/tmp/yo`, in the previous example,
so that confirms the previous assumption.

The actual behavior is that the sink puts the trace in an extra `trace`
directory, in `/tmp/yo/trace`.

We end up with the `trace` relative trace path (relative to the base
output directory) because `make_trace_path_rel` returns an empty string
when `assume_single_trace` is true and `sanitize_trace_path` replaces it
with `trace`.

When using `assume-single-trace=true`, we should not deal with a
relative trace path, as the trace is output directly in the base output
directory.  We also don't want to run the path in
`make_unique_trace_path`, as the trace should be output in the base
directory specified by the user, not another directory.  Anyway, if the
user specifies  an existing directory, `sink.ctf.fs` will initially
error out with:

    Single trace mode, but output path exists: output-path="/tmp/yo"

Although that's a TOCTOU bug, two babeltrace instances could both check
at the same time that the same output directory does not exist, and both
write in the same directory.  That would not be good.

Change-Id: Ib2415420eabbc096a920d113863993161105e90a
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>

13 months agoFix: bt2: _trim_docstring(): docstring can have 0 or 1 line
Philippe Proulx [Thu, 10 Sep 2020 20:47:52 +0000 (16:47 -0400)] 
Fix: bt2: _trim_docstring(): docstring can have 0 or 1 line

It is possible that a user component class's docstring has no lines or a
single one, for example:

    # no line
    class MySink(bt2._UserSinkComponent):

        def _user_consume(self):

    # single line
    class MySink(bt2._UserSinkComponent):
        """The single line"""

        def _user_consume(self):

The previous version of _trim_docstring() expects this format:

    class MySink(bt2._UserSinkComponent):
        My sink's description

        Dolore officia ex et aliquip eiusmod enim pariatur reprehenderit
        ad adipisicing non occaecat ullamco aliquip laborum duis
        proident ex duis.

        Irure commodo proident esse non pariatur in aute cillum id aute.

        def _user_consume(self):

In _trim_docstring(), accept no lines or a single one.

Adding new tests to `` to validate this
behaviour. The

    # fmt: off
    # fmt: on

docstring has off/on formatting markers as Black 20.8b1 transforms this
into the non-equivalent


(which is another test now).

In addition, reformat Python files with Black v20.8b1, so that the
pylint CI job passes.

Signed-off-by: Philippe Proulx <>
Change-Id: Ia12b0e9bfd4d1e1aaa86f0c8c207c3c1535f5c3e
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
16 months agoFix: `ctf` plugin: use element FC's alignment as array/seq. FC alignment
Philippe Proulx [Tue, 21 Jul 2020 17:57:10 +0000 (13:57 -0400)] 
Fix: `ctf` plugin: use element FC's alignment as array/seq. FC alignment

Observed issue
When reading some CTF trace with an empty array/sequence field,
Babeltrace 2 can fail.

More specifically, for the trace `tests/data/ctf-traces/succeed/array-align-elem`
(added by this patch):

The CLI's output is:

    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:535 [auto-disc-source-ctf-fs] User function returned EOF, but message iterator is in an unexpected state: state=DSCOPE_EVENT_PAYLOAD_CONTINUE, cur-packet-size=-1, cur=24, packet-cur=24, last-eh-at=16
    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER read_dscope_continue_state@msg-iter.c:632 [auto-disc-source-ctf-fs] Cannot ensure that buffer has at least one byte: msg-addr=0x55d3b4e051f0, status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER ctf_msg_iter_get_next_message@msg-iter.c:2881 [auto-disc-source-ctf-fs] Cannot handle state: msg-it-addr=0x55d3b4e051f0, state=DSCOPE_EVENT_PAYLOAD_CONTINUE
    07-21 14:00:24.636 73959 73959 E PLUGIN/SRC.CTF.FS ctf_fs_iterator_next_one@fs.c:90 [auto-disc-source-ctf-fs] Failed to get next message from CTF message iterator.
    07-21 14:00:24.636 73959 73959 W LIB/MSG-ITER bt_message_iterator_next@iterator.c:865 Component input port message iterator's "next" method failed: iter-addr=0x55d3b4e05000, iter-upstream-comp-name="auto-disc-source-ctf-fs", iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=SOURCE, iter-upstream-comp-class-name="fs", iter-upstream-comp-class-partial-descr="Read CTF traces from the file sy", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="array-align-elem | 0 | array-align-elem/stream", status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER muxer_upstream_msg_iter_next@muxer.c:446 [muxer] Upstream iterator's next method returned an error: status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER validate_muxer_upstream_msg_iters@muxer.c:989 [muxer] Cannot validate muxer's upstream message iterator wrapper: muxer-msg-iter-addr=0x55d3b4dcb830, muxer-upstream-msg-iter-wrap-addr=0x55d3b4e055c0
    ev: { a = 1, b = [ ], c = 2 }
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER muxer_msg_iter_next@muxer.c:1417 [muxer] Cannot get next message: comp-addr=0x55d3b4dcae70, muxer-comp-addr=0x55d3b4dcaef0, muxer-msg-iter-addr=0x55d3b4dcb830, msg-iter-addr=0x55d3b4dcb750, status=ERROR
    07-21 14:00:24.636 73959 73959 W LIB/MSG-ITER bt_message_iterator_next@iterator.c:865 Component input port message iterator's "next" method failed: iter-addr=0x55d3b4dcb750, iter-upstream-comp-name="muxer", iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=FILTER, iter-upstream-comp-class-name="muxer", iter-upstream-comp-class-partial-descr="Sort messages from multiple inpu", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
    07-21 14:00:24.636 73959 73959 W LIB/GRAPH consume_graph_sink@graph.c:462 Component's "consume" method failed: status=ERROR, comp-addr=0x55d3b4dcb070, comp-name="pretty", comp-log-level=WARNING, comp-class-type=SINK, comp-class-name="pretty", comp-class-partial-descr="Pretty-print messages (`text` fo", comp-class-is-frozen=1, comp-class-so-handle-addr=0x55d3b4dc7c50, comp-class-so-handle-path="/home/eepp/dev/babeltrace/install/lib/babeltrace2/plugins/", comp-input-port-count=1, comp-output-port-count=0
    07-21 14:00:24.636 73959 73959 E CLI cmd_run@babeltrace2.c:2529 Graph failed to complete successfully

    ERROR:    [Babeltrace CLI] (babeltrace2.c:2529)
      Graph failed to complete successfully
    CAUSED BY [libbabeltrace2] (graph.c:462)
      Component's "consume" method failed: status=ERROR, comp-addr=0x55d3b4dcb070, comp-name="pretty", comp-log-level=WARNING, comp-class-type=SINK,
      comp-class-name="pretty", comp-class-partial-descr="Pretty-print messages (`text` fo", comp-class-is-frozen=1, comp-class-so-handle-addr=0x55d3b4dc7c50,
      comp-class-so-handle-path="/home/eepp/dev/babeltrace/install/lib/babeltrace2/plugins/", comp-input-port-count=1,
    CAUSED BY [libbabeltrace2] (iterator.c:865)
      Component input port message iterator's "next" method failed: iter-addr=0x55d3b4dcb750, iter-upstream-comp-name="muxer",
      iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=FILTER, iter-upstream-comp-class-name="muxer",
      iter-upstream-comp-class-partial-descr="Sort messages from multiple inpu", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:1417)
      Cannot get next message: comp-addr=0x55d3b4dcae70, muxer-comp-addr=0x55d3b4dcaef0, muxer-msg-iter-addr=0x55d3b4dcb830, msg-iter-addr=0x55d3b4dcb750,
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:989)
      Cannot validate muxer's upstream message iterator wrapper: muxer-msg-iter-addr=0x55d3b4dcb830, muxer-upstream-msg-iter-wrap-addr=0x55d3b4e055c0
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:446)
      Upstream iterator's next method returned an error: status=ERROR
    CAUSED BY [libbabeltrace2] (iterator.c:865)
      Component input port message iterator's "next" method failed: iter-addr=0x55d3b4e05000, iter-upstream-c

The internal CTF IR array and sequence field classes do not have an
alignment which is equal to their element FC's alignment, although
CTF 1.8.3 requires it [1]:

> Arrays are always aligned on their element alignment requirement.

In `bfcr.c`, align_class_state() is already called for array/sequence

Add a CTF IR trace class visitor to set any array/sequence FC's
alignment to its element FC's alignment, recursively (postorder).

Also update, postorder, structure FC alignments since some of the
alignments of the field types of their members can change.

This patch adds two minimalist CTF traces to test the fix as well as two
new corresponding tests in


        struct {
            integer { size = 8; } a;
            integer { size = 8; align = 16; } b[0];
            integer { size = 8; } c;

    Taking the aligment of `b` into account, there's one byte of padding
    between `a` and `c`:

        a # c
          ^---- alignment of `b`


        struct {
            integer { size = 8; } x;
            struct {
                integer { size = 8; } a;
                integer { size = 8; align = 32; } b[0];
            } y;
            integer { size = 8; } z;

    Taking the alignment of `y.b` into account, the `y` structure itself
    is 32-bit-aligned, making the outer structure also 32-bit-aligned.
    Therefore, there are three bytes of padding between `x` and `a`, and
    three other bytes of padding between `a` and `z`:

        x # # # a # # # z
          ^       ^-------- alignment of `b`
          '---------------- alignment of `y`


Signed-off-by: Philippe Proulx <>
Change-Id: I06b4fbeda9ffd5b87b4964dd567027d0bfd5e9c7

18 months agoFix: source.ctf.lttng-live: muxing failure on clear (unit conversion)
Jérémie Galarneau [Thu, 16 Jul 2020 20:09:53 +0000 (16:09 -0400)] 
Fix: source.ctf.lttng-live: muxing failure on clear (unit conversion)

This commit is a follow-up fix for 8ec4d5ff (see original message).
The original fix included a bogus comparison of:
  `stream_iter->last_inactivity_ts > curr_msg_ts_ns`

While the idea behind the fix is valid, this statement compares
nanoseconds since Unix Epoch (former) to clock cycles (latter).

A conversion of the `last_inactivity_ts` to nanoseconds since Unix epoch
is performed using the stream's default clock class allowing a
comparison in a common time base to take place.

The diff looks more intimidating than it really is as it shifts the
indentation of a lot of code at once. This is because we only want to
perform the timestamp conversion when necessary (very rarely) on this
fairly hot path.

Reviewed-by: Francis Deslauriers <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ibdc365fec4685da88ae141383d5e5ef0af169a87

19 months agoFix: src.ctf.lttng-live: incomplete metadata packet is an error
Jérémie Galarneau [Wed, 27 May 2020 16:15:54 +0000 (12:15 -0400)] 
Fix: src.ctf.lttng-live: incomplete metadata packet is an error

Observed issue

While investigating the issue described in [1], I noticed that
babeltrace2 falls into a retry loop when the src.ctf.lttng-live
component encounters unparseable metadata.

The src.ctf.lttng-live reports parsing errors on every subsequent
reception of a metadata packet. The relay daemon eventually sends
binary data which fails to be decoded, ending the graph's execution
with a binary decoding error, which is not the "real" issue.


Due to a (now fixed) bug in LTTng [1], unparseable (incomplete)
metadata can be made visible to live clients. This bug fix doesn't
involve the clients; it resulted in an illegal state in the lttng-live

When the relay daemon notifies the live client that new metadata is
available, lttng_live_metadata_update() receives all the metadata made
available by the relay daemon in a memory stream and then uses the
ctf_metadata_decoder to append the new content to the existing trace

However, if the decoder returns
`LTTNG_LIVE_ITERATOR_STATUS_AGAIN` is returned to the caller,
resulting in the graph retrying to invoke the live iterator's `next`
method until another error eventually prevents the successful
completion of the graph.

I am assuming that the use of the `AGAIN` status code may have been a
failed attempt at fixing [1] in the live component rather than
adressing the underlying problem.


To my knowledge there are no provisions made for incomplete metadata
in the lttng-live protocol as of the current version. This may have
been done in anticipation of a future change (?), but it currently
obscures the error reported when a corrupted/incomplete/unparseable
metadata packet is received by the src.ctf.lttng-live component.

The current approach doesn't work anyhow as
lttng_live_metadata_update() creates a "fresh" memory stream on each
invocation. If the intention was to accumulate partial metadata until
it can be successfully parsed, the accumulated metadata would have to
be preserved from one invocation to the next.

The conversion of the status code from `INCOMPLETE` to `AGAIN` is
removed to fail immediately during the current invocation of the
iterator's `next` method.





Signed-off-by: Jérémie Galarneau <>
Change-Id: I8a379ea5d838786a6731199dd5f03bbf70ec13f5
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
19 months agoFix: source.ctf.lttng-live: muxing failure on clear
Jérémie Galarneau [Thu, 4 Jun 2020 22:32:32 +0000 (18:32 -0400)] 
Fix: source.ctf.lttng-live: muxing failure on clear

Observed issue

The lttng-tools port builds regularly fail on the CI with the following

05-28 16:13:52.864 11219 11219 E PLUGIN/SRC.CTF.LTTNG-LIVE next_stream_iterator_for_trace@lttng-live.c:1067 [lttng-live] Message's timestamp is less than lttng-live's message iterator's last returned timestamp: lttng-live-msg-iter-addr=0xd810220dd30, ts=1590696831733594090, last-msg-ts=1590696832514058899
05-28 16:13:52.864 11219 11219 E PLUGIN/SRC.CTF.LTTNG-LIVE lttng_live_msg_iter_next@lttng-live.c:1502 [lttng-live] Error preparing the next batch of messages: live-iter-status=LTTNG_LIVE_ITERATOR_STATUS_ERROR
05-28 16:13:52.864 11219 11219 W LIB/MSG-ITER bt_message_iterator_next@iterator.c:868 Component input port message iterator's "next" method failed: iter-addr=0xd810221c7c0, iter-upstream-comp-name="lttng-live", iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=SOURCE, iter-upstream-comp-class-name="lttng-live", iter-upstream-comp-class-partial-descr="Connect to an LTTng relay daemon", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
05-28 16:13:52.864 11219 11219 W LIB/GRAPH consume_graph_sink@graph.c:466 Component's "consume" method failed: status=ERROR, comp-addr=0xd81022373a0, comp-name="sink.text.details", comp-log-level=WARNING, comp-class-type=SINK, comp-class-name="details", comp-class-partial-descr="Print messages with details.", comp-class-is-frozen=0, comp-class-so-handle-addr=0xd8102233ca0, comp-class-so-handle-path="/tmp/debug_jgalar/build/usr/lib/babeltrace2/plugins/", comp-input-port-count=1, comp-output-port-count=0
05-28 16:13:52.865 11219 11219 E CLI cmd_run@babeltrace2.c:2530 Graph failed to complete successfully

ERROR:    [Babeltrace CLI] (babeltrace2.c:2530)
  Graph failed to complete successfully
CAUSED BY [libbabeltrace2] (graph.c:466)
  Component's "consume" method failed: status=ERROR, comp-addr=0xd81022373a0,
  comp-name="sink.text.details", comp-log-level=WARNING, comp-class-type=SINK,
  comp-class-name="details", comp-class-partial-descr="Print messages with
  details.", comp-class-is-frozen=0, comp-class-so-handle-addr=0xd8102233ca0,
  comp-input-port-count=1, comp-output-port-count=0
CAUSED BY [libbabeltrace2] (iterator.c:868)
  Component input port message iterator's "next" method failed:
  iter-addr=0xd810221c7c0, iter-upstream-comp-name="lttng-live",
  iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=SOURCE,
  iter-upstream-comp-class-partial-descr="Connect to an LTTng relay daemon",
  iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
CAUSED BY [lttng-live: 'source.ctf.lttng-live'] (lttng-live.c:1502)
  Error preparing the next batch of messages:
CAUSED BY [lttng-live: 'source.ctf.lttng-live'] (lttng-live.c:1067)
  Message's timestamp is less than lttng-live's message iterator's last returned
  timestamp: lttng-live-msg-iter-addr=0xd810220dd30, ts=1590696831733594090,

The test that ends up with this error performs a session `clear`
while tracing an application as part of a "live" session.


Given the following trace,

| pkt seq:0 |<-------discarded packets------>| pkt seq:8 |
0          20                                121       140

a CTF source is expected to introduce a "Discarded Packets" message
between packets 0 and 8. The begin and end timestamps of such a message
are synthesized from the timestamps of the last known packet (seq:0)
and the newly decoded packet (seq:8).

For instance, here the Discarded Packets message would have the bounds
[pkt0.end_ts, pkt8.begin_ts].

In the context of a live source, the tracer could report an inactivity
period during the interval of the "Discarded packets" message.

Those live protocol messages eventually translate into an "Iterator
Inactivity" message with a timestamp set at the end of the inactivity

If the tracer reports an inactivity period that ends at a point
between pkt0 and pkt8 (resulting in an "Iterator Inactivity" message),
the live source will send a "Discarded Packets" message that starts
before the preceding "Iterator Inactivity" message, breaking the
monotonicity constraint of the graph.

This happens regularly when `clear` is used on an LTTng live session as
it effectively discards packets, something that would otherwise not
happen (before LTTng 2.12) as most users set their tracing channels in
"discard" mode (the default for that session type).

However, the same problem as described above applies to "Discarded
Events" messages and could occur with older LTTng versions.


"Discarded Events" and Discarded Packets" messages are intercepted
in the lttng-live source's "muxer" and are _adjusted_ so that
they honor the monotonicity guarantee of the graph.

In effect, whenever such a message is seen to have a begin timestamp
that is _before_ the last inactivity timestamp, its begin timestamp
is adjusted to the last inactivity timestamp's value.

From a correctness standpoint, this is okay. If the tracer notified the
relay daemon of an inactivity period on a stream, we can rely on the
fact that no data was produced during that time to affirm that no
packets where lost during that time either.

A test reproducing the "Discarded Packets" scenatio described in
this message is added in a follow-up patch.

Known drawbacks


Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia8f32ba6717b33203637bf8d5aa34ff2a78c3e7f
Tested-by: jenkins <>
19 months agoFix: source.ctf.fs: 0-length packet index length causes SIGFPE
Jérémie Galarneau [Mon, 1 Jun 2020 22:53:45 +0000 (18:53 -0400)] 
Fix: source.ctf.fs: 0-length packet index length causes SIGFPE

A corrupted index can present a 0-length packet index length
which will result in a division by 0 when computing the index
entry count.

Program terminated with signal SIGFPE, Arithmetic exception.
 #0  0x00007f6ecbd44978 in build_index_from_idx_file (ds_file=0x561ade51ca00, file_info=0x561ade51d000,
    msg_iter=0x561ade51cd00) at data-stream-file.c:640
640 file_entry_count = (filesize - sizeof(*header)) / file_index_entry_size;

The index packet length is checked against the smallest valid size:
the size of an index entry as of the 1.0 CTF index version.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I83c705575d55f3b56ae413d1ce5ae0fc60121f2c
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
21 months agoUpdate working version to Babeltrace 2.0.4
Jérémie Galarneau [Thu, 23 Apr 2020 15:17:05 +0000 (11:17 -0400)] 
Update working version to Babeltrace 2.0.4

Signed-off-by: Jérémie Galarneau <>
Change-Id: Idfcf7e0dfbe4841c4032b60b11748a8cfb744d0c

21 months agoRelease: Babeltrace 2.0.3 "Amqui" v2.0.3
Jérémie Galarneau [Thu, 23 Apr 2020 15:16:07 +0000 (11:16 -0400)] 
Release: Babeltrace 2.0.3 "Amqui"

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib443f69b40fbfd04a779b31ecda70e25827d4e97

21 months agoFix: lib: use appropriate format specifier to print message iterator class
Simon Marchi [Wed, 22 Apr 2020 21:13:08 +0000 (17:13 -0400)] 
Fix: lib: use appropriate format specifier to print message iterator class


  babeltrace2 --debug /some/trace

... results in the following crash:

    ==31705==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f5b9c25ae22 bp 0x7ffc64114490 sp 0x7ffc64113ba8 T0)
    ==31705==The signal is caused by a READ memory access.
    ==31705==Hint: address points to the zero page.
        #0 0x7f5b9c25ae21  (/usr/lib/x86_64-linux-gnu/
        #1 0x7f5b9c1d231f  (/usr/lib/x86_64-linux-gnu/
        #2 0x7f5b9c1fef4d in __interceptor_vsnprintf (/usr/lib/x86_64-linux-gnu/
        #3 0x7f5b9c1ff286 in snprintf (/usr/lib/x86_64-linux-gnu/
        #4 0x7f5b9bdf61c3 in format_component_class /home/smarchi/src/babeltrace/src/lib/lib-logging.c:1061
        #5 0x7f5b9bdfad46 in handle_conversion_specifier_bt /home/smarchi/src/babeltrace/src/lib/lib-logging.c:1451
        #6 0x7f5b9bead260 in bt_common_custom_vsnprintf /home/smarchi/src/babeltrace/src/common/common.c:1727
        #7 0x7f5b9bdfb10b in bt_lib_log /home/smarchi/src/babeltrace/src/lib/lib-logging.c:1496
        #8 0x7f5b9be32965 in bt_message_iterator_class_set_seek_beginning_methods /home/smarchi/src/babeltrace/src/lib/graph/message-iterator-class.c:138

This is due to an object being printed with the wrong format specifier.
`C` is for component class objects, use `I` instead, since we are
printing a message iterator object.

Change-Id: Ie3985d8b7c4e02ac7d09aee84bfe46ea4bab87e9
Signed-off-by: Simon Marchi <>
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
21 months agoFix: sink.text.pretty: check that port is connected before creating message iterator
Simon Marchi [Tue, 14 Apr 2020 15:22:17 +0000 (11:22 -0400)] 
Fix: sink.text.pretty: check that port is connected before creating message iterator

sink.text.pretty does not check if its input port is connected before
trying to create a message iterator on it.  This can lead to a
precondition assertion failure.  It can be reproduced with this Python

    import bt2
    g = bt2.Graph()
    g.add_component(bt2.find_plugin('text').sink_component_classes['pretty'], 'snk')

The assertion failure we get is:

    04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Babeltrace 2 library precondition not satisfied; error is:
    04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Input port is not connected: port-addr=0x607000001d70, port-type=INPUT, port-name="in"
    04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Aborting...
    ./tests/utils/../utils/ line 283: 1231815 Aborted (core dumped) env "${env_args[@]}" "$@"

Add a check and return an error if that happens instead.  A
corresponding test is also added.

Change-Id: Ibeed94cd6ece543817fe8a765a69cb52bbaaba76
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>

21 months agoAdd initial Python bindings documentation
Simon Marchi [Thu, 26 Mar 2020 20:33:13 +0000 (16:33 -0400)] 
Add initial Python bindings documentation

This initial documentation contains a home page, an installation page,
and a few examples to understand how the `bt2` package works.

Still missing: how exactly the bindings wrap libbabeltrace2 (wraping
rules, exceptions, etc.).


    Specify that you need Sphinx to build the Python bindings

`` and `m4/check_sphinx.m4`:
    Add `--enable-python-bindings-doc` which requires

    This is because the Sphinx configuration file actually imports the
    `bt2` package to get the version (and, eventually, for Sphinx's
    autodoc to find docstrings within the `bt2` modules).

    The actual documentation's contents and configuration.

    A Sphinx extension to add Babeltrace 2 manual page and other links
    of which the URL includes the project's version.

Signed-off-by: Simon Marchi <>
Signed-off-by: Philippe Proulx <>

Backported from ba64dfcccb1f1bd7a259dc5d563ba422b8375582

   Removed example usage for `in`:
      if 'next_comm' in event:
    This utility was introduced by
    f03b6364aec2d77bbb5ef0625cbaea8de4179f63, not backported,
    and only provides a shortcut to iterate over all `root` fields.
    User can implement their own as needed.
  Updated referenced version of lttng from 2.11 to "latest" for
  lttng-live url.

Signed-off-by: Jonathan Rajotte <>
Change-Id: Id0f4636a5f66e98d383548bdcb894f53d31812b4
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
21 months agoFix: bt2: read properties on _DiscardedEventsMessage
Simon Marchi [Sat, 11 Apr 2020 16:17:36 +0000 (12:17 -0400)] 
Fix: bt2: read properties on _DiscardedEventsMessage

Reading the count and clock snapshot properties on a _DiscardedEventsMessage
does not work.  For example, this:

    msg = self._create_discarded_events_message(stream, count=10)

Results in:

      File "", line 10, in __init__
      File "/home/simark/build/babeltrace/src/bindings/python/bt2/build/build_lib/bt2/", line 208, in count
        avail, count = self._get_count(self._ptr)
    AttributeError: '_DiscardedEventsMessage' object has no attribute '_get_count'

The problem is simply that _DiscardedEventsMessage is missing inheriting
from _DiscardedEventsMessageConst.

Change-Id: Id40ea54bb26b4e4aec264d84bda52ed815090341
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>

21 months agotests: add tests for discarded events/packets creation
Simon Marchi [Fri, 10 Apr 2020 20:05:25 +0000 (16:05 -0400)] 
tests: add tests for discarded events/packets creation

Creation of these messages is a bit tested in AllMessagesTestCase, but
not everything, especially not the error cases.

To avoid code duplication as much as possible, I've added a
`run_in_message_iterator_next` helper, similar to the existing
`run_in_component_init`.  This helper takes a callback to run in the
context of a source component's message iterator's __next__method.
Individual tests also need to customize the stream class creation, to
decide if the stream class supports discarded event/packet messages,
clock snapshots on those messages, etc.  So it also receives a callback
executed in the source component's __init__ method, which must return a
stream class.  This callback takes a trace class as a parameter, which
it will need to create the stream class, and a clock class.  It is free
to use the clock class as the stream class' default_clock_class or not.

Doing this, I noticed that reading the count and clock snapshot
properties on a _DiscardedEventsMessage didn't work.  This will be fixed
in a subsequent patch, in the mean time the corresponding assertions are
commented out.

Change-Id: I5025d06e6cb5b9d1bbd4372818b391cbc7b5bfa2
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>

21 months agoFix: bt2: add precond. check, for stream class supporting discarded msgs with clock...
Simon Marchi [Fri, 10 Apr 2020 20:31:32 +0000 (16:31 -0400)] 
Fix: bt2: add precond. check, for stream class supporting discarded msgs with clock snapshot without clock class

We hit the following precondition failure from the Python bindings when
creating a stream class that supports discarded event messages with
clock snapshots, but does not have a default clock class.  Same with
discarded packet messages.

    04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Babeltrace 2 library precondition not satisfied; error is:
    04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Stream class has no default clock class: addr=0x60f0000023e0, id=0, is-frozen=0, event-class-count=0, packet-context-fc-addr=(nil), event-common-context-fc-addr=(nil), assigns-auto-ec-id=1, assigns-auto-stream-id=1, supports-packets=0, packets-have-begin-default-cs=0, packets-have-end-default-cs=0, supports-discarded-events=0, discarded-events-have-default-cs=0, supports-discarded-packets=0, discarded-packets-have-default-cs=0, trace-class-addr=0x608000002b20, pcf-pool-size=0, pcf-pool-cap=0
    04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Aborting...

Add some checks for that in _StreamClass._validate_create_params, and
some corresponding tests.

Change-Id: I5d79b8ecfc05acbb79b7b15d28ba2c5c34f00729
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
(cherry picked from commit aa7407227594c8e5ebff8e1944a902760f2c9a17)
CI-Build: Philippe Proulx <>

21 months agoFix: flt-utils.muxer: reference leak in muxer_msg_iter_add_upstream_msg_iter error...
Simon Marchi [Sat, 11 Apr 2020 16:52:45 +0000 (12:52 -0400)] 
Fix: flt-utils.muxer: reference leak in muxer_msg_iter_add_upstream_msg_iter error path

Let's say we fail to allocate `muxer_upstream_msg_iter->msgs`, we will have
already gotten a reference on `self_msg_iter`, which we need to put.  Calling
destroy_muxer_upstream_msg_iter ensures we do that.

Change-Id: I9b113d2e335d529599cb9197c39c8675915508e5
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
(cherry picked from commit 6adf99d540b2d239fc49bb64934becf410812c39)
CI-Build: Philippe Proulx <>

21 months agoFix: sink.text.details: goto error when failing to add input port
Simon Marchi [Thu, 9 Apr 2020 17:55:05 +0000 (13:55 -0400)] 
Fix: sink.text.details: goto error when failing to add input port

If bt_self_component_sink_add_input_port fails, the current code does
not goto error.  This patch fixes it.  It also changes the switch, used
to convert from `add_port_status` to `status`, to a cast, as is the
practice throughout the project.

Change-Id: I82b2719316ad00ffd9d9c14b86b8890b98130669
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
(cherry picked from commit c7f21c12d5cec35f3e48630cf603207748409847)
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
21 months agoFix: src.text.dmesg: add missing assignment of `status` on error path
Simon Marchi [Thu, 9 Apr 2020 18:27:39 +0000 (14:27 -0400)] 
Fix: src.text.dmesg: add missing assignment of `status` on error path

The error path under `if (!*msg)`, originally at line 789, is missing
assigning an error status to the `status` variable, fix it.

Change-Id: I2b47c6ce7c6099a6db68c4da108d7c0886c7177e
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
(cherry picked from commit c16fb81a23dcfa6ab8331efe1c98a86e4444040d)
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
21 months agoRevert "bt2: _EventConst.__getitem__(): use a single temporary variable"
Philippe Proulx [Wed, 8 Apr 2020 17:05:55 +0000 (13:05 -0400)] 
Revert "bt2: _EventConst.__getitem__(): use a single temporary variable"

I did not want to merge this and pressed the wrong button on Gerrit.


Change-Id: I11cc739c126131560ba31d2a1f3f01b7e961a837
Reviewed-by: Philippe Proulx <>
CI-Build: Philippe Proulx <>

21 months agoFix: src.ctf.fs: initialize the other_entry variable
Mingli Yu [Thu, 12 Mar 2020 03:42:07 +0000 (11:42 +0800)] 
Fix: src.ctf.fs: initialize the other_entry variable

Initialize the pointer other_entry to silence this warning:

    | ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function 'ds_index_insert_ds_index_entry_sorted':
    | ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    |  702 |    !ds_index_entries_equal(entry, other_entry)) {

This was encountered with gcc 9.2.0 at the -Og optimization level.
After inspection, it appears that this is a false positive, the
`other_entry` pointer can only be used after being initialized first.

Signed-off-by: Mingli Yu <>
Change-Id: Icf63e605cf543c3eb29e5aadec18b22b137ee9da
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
21 months agobt2: _EventConst.__getitem__(): use a single temporary variable
Philippe Proulx [Tue, 7 Apr 2020 13:47:50 +0000 (09:47 -0400)] 
bt2: _EventConst.__getitem__(): use a single temporary variable

Signed-off-by: Philippe Proulx <>
Change-Id: I241565ca7414952cd667d2912235231ef15ad314
Tested-by: jenkins <>
21 months agoFix: _EventConst.__getitem__(): check if event has a packet
Philippe Proulx [Tue, 7 Apr 2020 13:41:55 +0000 (09:41 -0400)] 
Fix: _EventConst.__getitem__(): check if event has a packet

I'm also adding a test to check this. Without this patch and an invalid
key, __getitem__() throws `AttributeError` instead of the expected

Signed-off-by: Philippe Proulx <>
Change-Id: Ie6258a2354ece8aee6c8530587c900ea08e45fe8
Tested-by: jenkins <>
22 months agodoc: bt_field_class...get_mapping_labels...(): clarify RV's validity
Philippe Proulx [Thu, 12 Mar 2020 17:33:09 +0000 (13:33 -0400)] 
doc: bt_field_class...get_mapping_labels...(): clarify RV's validity

The label array which
bt_field_class_enumeration_unsigned_get_mapping_labels_for_value() and
bt_field_class_enumeration_signed_get_mapping_labels_for_value() return
remains valid as long as:

* The enumeration field class is not modified.

* You don't call the same function again with the same enumeration
  field class.

Signed-off-by: Philippe Proulx <>
Change-Id: I7b197ab5e176c77f4418d23b12e194c6477e5cf8

22 months agodoc/api/libbabeltrace2/style.css: make font weight of `.intertd` normal
Philippe Proulx [Thu, 12 Mar 2020 17:24:00 +0000 (13:24 -0400)] 
doc/api/libbabeltrace2/style.css: make font weight of `.intertd` normal

For some reason, `.intertd` paragraphs, which Doxygen creates when a
given table cell (used for parameter descriptions, amongst other things)
contains more than one paragraphs, are bold.

Here's an example to generate such paragraphs:

    @param some_param
        Normal paragraph.

        Bold paragraph.

        Also bold.

I don't know the bold font weight's rationale here, but it does not look
pretty, so force the weight to be normal in `style.css`.

Signed-off-by: Philippe Proulx <>
Change-Id: Ida6970a75f6cc1b4ac4f1fc873e86a3b453d09ac

22 months agoUpdate working version to Babeltrace 2.0.3
Jérémie Galarneau [Tue, 10 Mar 2020 20:34:58 +0000 (16:34 -0400)] 
Update working version to Babeltrace 2.0.3

Signed-off-by: Jérémie Galarneau <>
Change-Id: I0b996d8b2bda69efad869ba3d5f0c5cf7ab6ac24

22 months agoRelease: Babeltrace 2.0.2 "Amqui" v2.0.2
Jérémie Galarneau [Tue, 10 Mar 2020 20:33:22 +0000 (16:33 -0400)] 
Release: Babeltrace 2.0.2 "Amqui"

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib5db5b0ff56e7a919a2d5c5f3133d1fa38836807

22 months agocommon: cast arguments to character classification functions to unsigned char
Simon Marchi [Fri, 6 Mar 2020 20:05:57 +0000 (15:05 -0500)] 
common: cast arguments to character classification functions to unsigned char

We get failures of this type on the cygwin CI machine:

    15:28:20 common.c: In function `bt_common_string_is_printable`:
    15:28:20 common.c:786:16: error: array subscript has type `char` [-Werror=char-subscripts]
    15:28:20   786 |   if (!isprint(*ch) && *ch != '\n' && *ch != '\r' &&
    15:28:20       |                ^~~

This error only pops up on some platforms that have isprint implemented
using a lookup table.  This table is indexed using `*ch`, which is a
char.  And because char is signed on some platforms, gcc warns that this
is dangerous: we could access the array with a negative index, which
would yield unexpected results.

This is on purpose in newlib (the libc used by cygwin, apparently), see
this comment:;a=blob;f=newlib/libc/include/ctype.h;h=a0009af17485acc3d70586a0051269a7a9c350d5;hb=HEAD#l78

The Linux man page for isprint also mentions it:

       The standards require that the argument c for these functions is
       either EOF or a value that is representable in the type unsigned
       char.  If the argument c is of type char, it must be cast to unsigned
       char, as in the following example:

           char c;
           res = toupper((unsigned char) c);

       This is necessary because char may be the equivalent of signed char,
       in which case a byte where the top bit is set would be sign extended
       when converting to int, yielding a value that is outside the range of
       unsigned char.

Add casts to unsigned char to fix the various instances of this error.

Change-Id: Ice2305490997f595c6f5140a8be2abaa7fd1d8f6
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
CI-Build: Michael Jeanson <>
Tested-by: jenkins <>
(cherry picked from commit 994cd345db7a82957ce647c2dac28cae11382dcc)

22 months agoflt.utils.muxer: initialize variable to silence -Wmaybe-uninitialized warning
Simon Marchi [Tue, 10 Mar 2020 16:09:20 +0000 (12:09 -0400)] 
flt.utils.muxer: initialize variable to silence -Wmaybe-uninitialized warning

gcc 4.8 shows this warning:

      CC       muxer.lo
    In file included from /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c:26:0:
    /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c: In function ‘muxer_msg_iter_next’:
    /home/smarchi/src/babeltrace/src/logging/comp-logging.h:145:3: error: ‘next_return_ts’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    /home/smarchi/src/babeltrace/src/plugins/utils/muxer/muxer.c:1042:10: note: ‘next_return_ts’ was declared here
      int64_t next_return_ts;

I looked at the interaction between muxer_msg_iter_do_next_one and
muxer_msg_iter_youngest_upstream_msg_iter (which is the one that sets
next_return_ts), and I think the code is fine:

 * muxer_msg_iter_youngest_upstream_msg_iter returns either OK, END, or
   an error status code (< 0).  It does not return AGAIN, because it
   does not call the upstream iterators, it works with the data already
   available to the muxer component.
 * muxer_msg_iter_do_next_one, only uses next_return_ts when
   muxer_msg_iter_youngest_upstream_msg_iter returns OK.
 * When muxer_msg_iter_youngest_upstream_msg_iter returns OK, it always sets

I think that initializing the variable to suppress this warning doesn't
hurt, and I don't see any other modifications needed to the code.

Change-Id: If4e8f1fd381a6ec2da044cf4cb8ffc8de2b373d9
Signed-off-by: Simon Marchi <>
Reviewed-by: Michael Jeanson <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
(cherry picked from commit 18961057774c796ea8522db964bc6f03e07a2027)

22 months agoFix: silently accepting invalid Python configuration
Francis Deslauriers [Thu, 27 Feb 2020 22:08:28 +0000 (17:08 -0500)] 
Fix: silently accepting invalid Python configuration

Currently, if the user builds and installs the project with:
  ./configure --enable-python-plugins
  make install

They won't be able to do the `import bt2` necessary to start defining
their BT2 plugin. To write a Python plugin , the user needs to use the
Python bindings as well.

The user gets this:
  >>> import bt2
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ModuleNotFoundError: No module named 'bt2'

As suggested by Simon Marchi, I implemented the following truth table
for the Python-related configure options (--enable-python-bindings and

  plugins | bindings
  missing | missing  -> both disabled
  missing | enable   -> plugins disabled, bindings enabled
  missing | disable  -> both disabled
  enable  | missing  -> both enabled
  enable  | enable   -> both enabled
  enable  | disable  -> error
  disable | missing  -> both disabled
  disable | enable   -> plugins disabled, bindings enabled
  disable | disable  -> both disabled

This makes sure the user doesn't get into an invalid configuration _and_
offers the sane default of enabling the bindings (if they were omitted)
when plugins are enabled explicitly.

Fixes #1240

Signed-off-by: Francis Deslauriers <>
Change-Id: I3b94d8911568290239add616f8e794ad73e278db
Tested-by: jenkins <>
Reviewed-by: Michael Jeanson <>
22 months agoCleanup: remove redundant `AC_ARG_ENABLE` parameters
Francis Deslauriers [Thu, 27 Feb 2020 21:51:38 +0000 (16:51 -0500)] 
Cleanup: remove redundant `AC_ARG_ENABLE` parameters

According to the documentation [1], the last parameter of the
`AC_ARG_ENABLE()` macro (`action-if-not-given`) is executed only if
neither `--enable-foo` nor `--disable-foo` is provided.

So in cases where the feature is disabled by default, there is no need
to turn if off explicitly in the `action-if-not-given` parameter as
the macro will simply not set the `enable_foo` to `yes`.

Also, I fixed up the comment for the `enable_man_pages` variable.


Signed-off-by: Francis Deslauriers <>
Change-Id: I7416bed88ed1e719ef896f0ca0117b382d99f68f
Tested-by: jenkins <>
Reviewed-by: Michael Jeanson <>
22 months agoFix: plugin-dev.h: Disable address sanitizer on pointer array section variables
Mathieu Desnoyers [Mon, 17 Feb 2020 23:33:12 +0000 (18:33 -0500)] 
Fix: plugin-dev.h: Disable address sanitizer on pointer array section variables

The plugin header declares pointer global variables in plugins meant to
be placed contiguously within their own sections, and then used as an
array of pointers when loading the plugin.

Clang Address Sanitizer adds redzones around each variable, thus leading
to detection of a global buffer overflow.

Those redzones should not be placed within this section, because it
defeats its purpose. Therefore, teach asan not to add redzones
around those variables with an attribute.

Note that there does not appear to be any issue with gcc (tested with
gcc-8 with address sanitization enabled), and gcc ignores the
no_sanitize_address attribute when applied to a global variable.

Fixes: #1231

Signed-off-by: Mathieu Desnoyers <>
Change-Id: I5488d61a7d714e6525a3a623d303c5fd30b76bc2
Reviewed-by: Simon Marchi <>
22 months agoFix: cli: use BT_CLI_LOGE_APPEND_CAUSE instead of printf to print errors
Simon Marchi [Tue, 25 Feb 2020 21:02:57 +0000 (16:02 -0500)] 
Fix: cli: use BT_CLI_LOGE_APPEND_CAUSE instead of printf to print errors

While fixing up the test cli/convert/test_convert_args, I noticed that
some error messages were printed on stdout, and not using error causes.
Indeed, they are printed directly using printf.

Change them to use BT_CLI_LOGE_APPEND_CAUSE.

This is tested by a following patch which updates

Change-Id: I18a901d50b643293dd806c1fbe7d2372dc8bd46f
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
23 months agotests: improve flt.utils.trimmer/test_trimming to test streams without packets
Simon Marchi [Mon, 17 Feb 2020 22:30:59 +0000 (17:30 -0500)] 
tests: improve flt.utils.trimmer/test_trimming to test streams without packets

Augment the test to make it test streams without packet support.  A new
parameter 'with-packet-msgs' must be passed to the test source component to
control whether it will emit packet messages.

There are now two configuration axis in this test (with and without
stream message clock snapshots, with and without packet messages), which
gives 4 configurations.  I think it's still manageable to have them all
written explicitly.  However, if we are to add a third configuration
axis, I think we'll need to refactor the test to avoid having all the
expected outputs written explicitly, as it will become too big to be

Change-Id: I0b488aa3f1506e9d43f320c1643a65db5317d63c
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
23 months agoFix: flt-utils.trimmer: accept streams without packet support
Simon Marchi [Tue, 18 Feb 2020 17:04:51 +0000 (12:04 -0500)] 
Fix: flt-utils.trimmer: accept streams without packet support

When the trimmer notices a new stream, it checks various properties to
make sure it is able to handle it.  If the stream's packet messages
don't have default clock snapshots, it returns an error, because that it
not supported right now.

However, this also has the unwanted effect of rejecting streams which
don't support packets.  Indeed, the
bt_stream_class_packets_have_beginning_default_clock_snapshot and
bt_stream_class_packets_have_end_default_clock_snapshot functions return
false in this case.

Streams without packet support are supported by the trimmer, there is
not reason to reject them.  Fix that by checking if the stream supports
packets before checking if the packet messages have default clock

This is covered by a test that is added by an following patch in this

Change-Id: If4732e89680d8dc8f02cb9be56d3a0d39fed6afe
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
23 months agoFix: lib: don't assume that streams have packets in auto seek
Simon Marchi [Mon, 17 Feb 2020 21:58:00 +0000 (16:58 -0500)] 
Fix: lib: don't assume that streams have packets in auto seek

We get a segmentation fault when trying to instantiate a trimmer
downstream of a component that creates streams without packets.  The
reason is that the line changed by this patch assumes that events are
always within packets.  However, it is possible (since
26fc5aedf "lib: make packets and packet messages optional, disabled by
default") for stream to not use packets.  In that situation, the
`packet` field of `event_msg->event` will be NULL.

Fix it by using `event_msg->event->stream`, which is expected to be the
same thing as `event_msg->event->packet->stream`, in the case where the
stream uses packets.

A test exercising this is added by a following patch in this series.

The stack at the point of the crash is the following:

    #0 0x7f2235db23ab in auto_seek_handle_message /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:1419
    #1 0x7f2235db330a in find_message_ge_ns_from_origin /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:1567
    #2 0x7f2235db4b1a in bt_message_iterator_seek_ns_from_origin /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:1790
    #3 0x7f2230abf6a4 in state_seek_initially /home/smarchi/src/babeltrace/src/plugins/utils/trimmer/trimmer.c:1095
    #4 0x7f2230ac2f3b in trimmer_msg_iter_next /home/smarchi/src/babeltrace/src/plugins/utils/trimmer/trimmer.c:1920
    #5 0x7f2235dae530 in call_iterator_next_method /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:808
    #6 0x7f2235daefc6 in bt_message_iterator_next /home/smarchi/src/babeltrace/src/lib/graph/iterator.c:855
    #7 0x7f2230d1b458 in details_consume /home/smarchi/src/babeltrace/src/plugins/text/details/details.c:476
    #8 0x7f2235da3d61 in consume_graph_sink /home/smarchi/src/babeltrace/src/lib/graph/graph.c:456
    #9 0x7f2235da40e0 in consume_sink_node /home/smarchi/src/babeltrace/src/lib/graph/graph.c:498
    #10 0x7f2235da4875 in consume_no_check /home/smarchi/src/babeltrace/src/lib/graph/graph.c:572
    #11 0x7f2235da510b in bt_graph_run /home/smarchi/src/babeltrace/src/lib/graph/graph.c:636
    #12 0x563a71c8127a in cmd_run /home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2503
    #13 0x563a71c8218a in main /home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2691
    #14 0x7f22351f2b96 in __libc_start_main (/lib/x86_64-linux-gnu/
    #15 0x563a71c73709 in _start (/home/smarchi/build/babeltrace/src/cli/.libs/babeltrace2+0x1f709)

Change-Id: Ic7ed3927d5ad1ca04833248a97723f0d8c4e4907
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
23 months agoFix: correct typo in README
Antoine Busque [Sat, 26 Oct 2019 01:56:25 +0000 (21:56 -0400)] 
Fix: correct typo in README

Signed-off-by: Antoine Busque <>
Signed-off-by: Jérémie Galarneau <>
23 months agoUpdate working version to Babeltrace 2.0.2
Jérémie Galarneau [Tue, 4 Feb 2020 19:28:54 +0000 (14:28 -0500)] 
Update working version to Babeltrace 2.0.2

Signed-off-by: Jérémie Galarneau <>
Change-Id: I9cc5540a7bc2077d619c00881af680f7e23e21f7

23 months agoRelease: Babeltrace 2.0.1 "Amqui" v2.0.1
Jérémie Galarneau [Tue, 4 Feb 2020 19:28:13 +0000 (14:28 -0500)] 
Release: Babeltrace 2.0.1 "Amqui"

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6e44bf5f274dd25b49ad8dc5a9f40f1cd1a0dbd2

23 months agofix: Remove empty python bindings documentation
Michael Jeanson [Mon, 3 Feb 2020 17:05:55 +0000 (12:05 -0500)] 
fix: Remove empty python bindings documentation

The python bindings documentation doesn't exist yet but the build system
contains remnants of the bt1 doc. Moreover, it contains a Sphinx theme
without any copyright or licensing information which makes our distro
friends a bit nervous.

Remove everything for now, it can be re-introduced when the doc is
actually written.

Signed-off-by: Michael Jeanson <>
Change-Id: I11b23822c8bf98c54a88c7e856d606d01102797f
Reviewed-by: Jérémie Galarneau <>
23 months agoREADME: Babeltrace 2 was released in 2020
Jérémie Galarneau [Fri, 24 Jan 2020 19:12:36 +0000 (14:12 -0500)] 
README: Babeltrace 2 was released in 2020

Signed-off-by: Jérémie Galarneau <>
Change-Id: I98b628edf257982fe42143f109a9d785424f7252

23 months agofix: set autoconf package name to babeltrace2
Michael Jeanson [Thu, 23 Jan 2020 19:35:00 +0000 (14:35 -0500)] 
fix: set autoconf package name to babeltrace2

This will help to make sure we are co-installable with babeltrace 1 by
moving the documentation directory to '/usr/share/doc/babeltrace2'.

Signed-off-by: Michael Jeanson <>
Change-Id: Ia55d2049967016fc5a00594c928e0f2c4f0e477d
Reviewed-by: Jérémie Galarneau <>
23 months agoTypo: occured -> occurred
Michael Jeanson [Thu, 23 Jan 2020 21:37:37 +0000 (16:37 -0500)] 
Typo: occured -> occurred

Signed-off-by: Michael Jeanson <>
Change-Id: I57d85deda90603e5c2824b8e0d4d07c71ca291db
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
23 months ago.gitignore: Add missing bt2/native_bt.d
Michael Jeanson [Thu, 30 Jan 2020 18:35:08 +0000 (13:35 -0500)] 
.gitignore: Add missing bt2/native_bt.d

Signed-off-by: Michael Jeanson <>
Change-Id: Ia0619ac791fb06f3fbbb414a75fcd145eb9f9d70
Reviewed-by: Simon Marchi <>
23 months agofix: build failure on ppc64el with '-Werror=format-overflow='
Michael Jeanson [Thu, 30 Jan 2020 16:11:52 +0000 (11:11 -0500)] 
fix: build failure on ppc64el with '-Werror=format-overflow='

Enabling optimizations makes gcc inline bt_plugin_so_shared_lib_handle_create
into bt_plugin_so_create_all_from_static.  That call site passes path == NULL,
so gcc notices that the argument to %s will always be NULL. This is
undefined behavior even if glibc will print "(null)".

Passing NULL to this function just means that we are loading the static
plugins, built-in Babeltrace.  So there's no path to a shared object file,
in this case explicitly print "(null)".

In file included from ../../../src/lib/logging.h:35,
                 from plugin-so.c:27:
In function ‘bt_plugin_so_shared_lib_handle_create’,
    inlined from ‘bt_plugin_so_create_all_from_static’ at plugin-so.c:1393:11:
../../../src/logging/log.h:811:6: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  811 |      _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812 |        lvl, tag, __VA_ARGS__); \
      |        ~~~~~~~~~~~~~~~~~~~~~~
../../../src/logging/log.h:897:4: note: in expansion of macro ‘BT_LOG_WRITE’
      |    ^~~~~~~~~~~~
plugin-so.c:174:2: note: in expansion of macro ‘BT_LOGI’
  174 |  BT_LOGI("Creating shared library handle: path=\"%s\"", path);
      |  ^~~~~~~
plugin-so.c: In function ‘bt_plugin_so_create_all_from_static’:
plugin-so.c:174:50: note: format string is defined here
  174 |  BT_LOGI("Creating shared library handle: path=\"%s\"", path);
      |                                                  ^~
In file included from ../../../src/lib/logging.h:35,
                 from plugin-so.c:27:
In function ‘bt_plugin_so_shared_lib_handle_create’,
    inlined from ‘bt_plugin_so_create_all_from_static’ at plugin-so.c:1393:11:
../../../src/logging/log.h:811:6: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  811 |      _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812 |        lvl, tag, __VA_ARGS__); \
      |        ~~~~~~~~~~~~~~~~~~~~~~
../../../src/logging/log.h:897:4: note: in expansion of macro ‘BT_LOG_WRITE’
      |    ^~~~~~~~~~~~
plugin-so.c:217:3: note: in expansion of macro ‘BT_LOGI’
  217 |   BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
      |   ^~~~~~~
plugin-so.c: In function ‘bt_plugin_so_create_all_from_static’:
plugin-so.c:217:50: note: format string is defined here
  217 |   BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
      |                                                  ^~
cc1: all warnings being treated as errors

Signed-off-by: Michael Jeanson <>
Change-Id: Ia727b37b04cb10f29e705f21c6889035a304a822
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
23 months agoSilence -Wnull-dereference warning in generated CTF parser code
Simon Marchi [Thu, 30 Jan 2020 16:52:10 +0000 (11:52 -0500)] 
Silence -Wnull-dereference warning in generated CTF parser code

Building Babeltrace on amd64 with -O3 on Ubuntnu 18.04 (gcc
7.4.0-1ubuntu1~18.04.1), I see:

  make[1]: Entering directory '/home/smarchi/build/babeltrace-opt/src/plugins/ctf/common/metadata'
    CC       libctf_parser_la-lexer.lo
  /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/lexer.c: In function ‘yyrestart’:
  /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/lexer.c:1997:20: error: potential null pointer dereference [-Werror=null-dereference]
    b->yy_fill_buffer = 1;

This is code generated by flex, there's not much we can do, so silence
the warning for the helper library that contains the lexer/parser.

Change-Id: I6698a73f50e88cb75b94ca80deec0f3a9556c4bf
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Michael Jeanson <>
Signed-off-by: Jérémie Galarneau <>
23 months agoplugin-so.c: add comment about why we're not using a GLib linked list
Philippe Proulx [Mon, 3 Feb 2020 17:07:28 +0000 (12:07 -0500)] 
plugin-so.c: add comment about why we're not using a GLib linked list

Signed-off-by: Philippe Proulx <>
Change-Id: I2e05156289d0d66a0a6ed9610d9d88a827a0b357

23 months agodoc: graph.h: do not link to `` for `babeltrace(1)`
Philippe Proulx [Mon, 27 Jan 2020 17:50:59 +0000 (12:50 -0500)] 
doc: graph.h: do not link to `` for `babeltrace(1)`

This website uses the project's upstream repository to find its manual

> This page was obtained from the project's upstream Git repository
> ⟨git://⟩ on 2019-05-09.

At that date, the Babeltrace 2 CLI's name was still `babeltrace`, so
<> is actually an
old Babeltrace 2 CLI manual page.

Signed-off-by: Philippe Proulx <>
Change-Id: I2a449dd3afee25dfb87993ee0d653f717b109c99

23 months agofix: common/list.h is LGPL-2.1
Michael Jeanson [Thu, 23 Jan 2020 16:38:25 +0000 (11:38 -0500)] 
fix: common/list.h is LGPL-2.1

Add 'lgpl-2.1.txt' to the distribution tarball and correct the path to
list.h in LICENSE.

Signed-off-by: Michael Jeanson <>
Change-Id: I7b3612b47da52170fc5fc2da3d38115152adcdbd
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
23 months agofix: build Python bindings with GCC10
Michael Jeanson [Thu, 23 Jan 2020 16:00:08 +0000 (11:00 -0500)] 
fix: build Python bindings with GCC10

Disable -Wnull-dereference for native_bt.c

bt2/native_bt.c: In function ‘SWIG_Python_NewPointerObj.constprop’:
bt2/native_bt.c:2207:13: error: potential null pointer dereference [-Werror=null-dereference]
 2207 |   PyObject *newraw = data->newraw;
      |             ^~~~~~

Change-Id: I05db1c48304b1fbc715d273425e16d7605405b27
Signed-off-by: Michael Jeanson <>
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
23 months agofix: use correct function to print 'enum bt_ctf_scope'
Michael Jeanson [Thu, 23 Jan 2020 15:47:34 +0000 (10:47 -0500)] 
fix: use correct function to print 'enum bt_ctf_scope'

Building with GCC10 results in the following error:

implicit conversion from 'enum bt_ctf_scope' to 'enum bt_field_path_scope' [-Werror=enum-conversion]

Change-Id: Id1144231f8439444696e4683dff2b0abf0d26d60
Signed-off-by: Michael Jeanson <>
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
23 months agoUpdate working version to Babeltrace 2.0.1
Jérémie Galarneau [Fri, 24 Jan 2020 18:31:24 +0000 (13:31 -0500)] 
Update working version to Babeltrace 2.0.1

This is not the _release_ commit of Babeltrace 2.0.1; it merely
updates the current working version to 2.0.1.

Since this commit is not tagged, the `git describe`
output (e.g. v2.0.0-1-g7adcb97be) will be included as part of the
library's "development stage" version field.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Iad8006929c97d72ebfed7cd683bcaa85c59f9c56

2 years agoRelease: Babeltrace 2.0.0 "Amqui" v2.0.0
Jérémie Galarneau [Tue, 21 Jan 2020 22:02:59 +0000 (17:02 -0500)] 
Release: Babeltrace 2.0.0 "Amqui"

Released at long last!

Adds the name and description of the release.

The ChangeLog is reset as we are starting a new release series afresh.
The ChangeLog of this release describes the changes that were
introduced between the fourth release candidate (rc4) and this
final version of Babeltrace v2.0.0.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id57d79cd0efba4aa0f8c699abe1def190dd841d7
Reviewed-by: Philippe Proulx <>
Reviewed-by: Michael Jeanson <>
2 years agocli: colorize version printing
Philippe Proulx [Tue, 21 Jan 2020 16:38:06 +0000 (11:38 -0500)] 
cli: colorize version printing

Signed-off-by: Philippe Proulx <>
Change-Id: I76388372a3b2f11ebb2ee76020f3d224f376f604
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agocli: print full version name
Philippe Proulx [Tue, 21 Jan 2020 15:52:12 +0000 (10:52 -0500)] 
cli: print full version name

Include the release's name and name description, the Git revision
description, and extra information.

Signed-off-by: Philippe Proulx <>
Change-Id: I478da57eb24b6a8d0f9c7a0b7b1fb8a41d8e4867
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agolib: add bt_version_get_extra_{name,description,patch_names}
Philippe Proulx [Tue, 21 Jan 2020 15:28:07 +0000 (10:28 -0500)] 
lib: add bt_version_get_extra_{name,description,patch_names}

Those new functions return extra information about the library's version
for custom builds (see `version/README.adoc`).

Signed-off-by: Philippe Proulx <>
Change-Id: I52abca8235826d1e336584285e925147895b13f4
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agolib: add bt_version_get_vcs_revision_description()
Philippe Proulx [Tue, 21 Jan 2020 15:11:49 +0000 (10:11 -0500)] 
lib: add bt_version_get_vcs_revision_description()

For a non-release build, this function returns the Git revision's

Signed-off-by: Philippe Proulx <>
Change-Id: Iec5e5fb1bb220c3477bfecab3c3f35b103c0592e
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agocommon: support custom, extra information for build's version
Philippe Proulx [Tue, 21 Jan 2020 14:55:43 +0000 (09:55 -0500)] 
common: support custom, extra information for build's version

This patch adds a system of extra version information also found in

`src/common/Makefile` generates `src/common/version.i` at every build.
This file contains:

* The current Git revision description.

* Extra name of the version (found in `version/extra_version_name`).

* Extra description of the version (found in

* A list of patch file names found in `version/extra_patches`.

All definitions can be empty strings.

See `version/README.adoc` to learn more.

As of this patch, libbabeltrace2 does not offer getters for this data
and the CLI does not print it with the `--version` option. This is
reserved for subsequent patches.

Signed-off-by: Philippe Proulx <>
Change-Id: Ife50e5bcaa6b3bdeda6ee4e7c1fdeb2fb1f63887
Reviewed-by: Francis Deslauriers <>
Reviewed-by: Michael Jeanson <>
Tested-by: jenkins <>
2 years, lib: rename "extra" (version) to "development stage"
Philippe Proulx [Tue, 21 Jan 2020 14:20:40 +0000 (09:20 -0500)], lib: rename "extra" (version) to "development stage"

"Extra" is a term which we'll use for something else brought by a
subsequent patch.

I took the "development stage" term from
where "Release candidate" is one of the stages.

Signed-off-by: Philippe Proulx <>
Change-Id: I285fbf9851cde41a520079b4c31cdc5d8bf32412
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agolib: add bt_version_get_name() and bt_version_get_name_description()
Philippe Proulx [Mon, 20 Jan 2020 22:00:35 +0000 (17:00 -0500)] 
lib: add bt_version_get_name() and bt_version_get_name_description()

Signed-off-by: Philippe Proulx <>
Change-Id: If080c93994ac5869e29061b21d7b5c35387985d3
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years agolib: bt_version_get_extra(): return `NULL` if none instead of empty str.
Philippe Proulx [Mon, 20 Jan 2020 21:59:05 +0000 (16:59 -0500)] 
lib: bt_version_get_extra(): return `NULL` if none instead of empty str.

This follows the pattern we have for other optional strings returned by
the library.

Signed-off-by: Philippe Proulx <>
Change-Id: I775f4f3be917bde405ad3b5e63183dae9609cf03
Reviewed-by: Francis Deslauriers <>
Tested-by: jenkins <>
2 years add version name/description definitions and report them
Philippe Proulx [Mon, 20 Jan 2020 21:54:03 +0000 (16:54 -0500)] add version name/description definitions and report them

Signed-off-by: Philippe Proulx <>
Change-Id: If287cce862facaaec71c63030ae578e24bcf4591
Reviewed-by: Francis Deslauriers <>
Reviewed-by: Michael Jeanson <>
Tested-by: jenkins <>
2 years agoDocument libbabeltrace2's C API
Philippe Proulx [Sat, 21 Sep 2019 16:02:25 +0000 (12:02 -0400)] 
Document libbabeltrace2's C API

This patch adds initial documentation for the Babeltrace 2 library's
C API using Doxygen.

The Doxygen project is located in `doc/api/libbabeltrace2`, as we can
eventually add `doc/api/libbabeltrace2-ctf-writer`.

To be able to use Doxygen's member grouping [1], I had to join some
header files (`const` and non `const` headers, for example), because
otherwise I could not get some functions in separate files to be in the
same member group in the order I want. In the end, the library user
includes `<babeltrace2/babeltrace.h>`, so how we organize the headers
exactly is not so crucial.


Signed-off-by: Philippe Proulx <>
Change-Id: I6d1dc2e7c5ee63fcd4220d0fd9f0931d361d2f31
Tested-by: jenkins <>
2 years agoFix: src.ctf.lttng-live: emitting stream end msg with no stream
Francis Deslauriers [Thu, 19 Dec 2019 21:39:45 +0000 (16:39 -0500)] 
Fix: src.ctf.lttng-live: emitting stream end msg with no stream

When a stream hangs up on the `src.ctf.lttng-live` component, we make
sure we send a stream end message to ensure we honor The Contract which
states that any stream beginning must eventually be followed by its
stream end counterpart. We do this by calling
`ctf_msg_iter_get_next_message()` one last time to emit any missing

Using the upcoming lttng clear feature in conjunction with a per-pid
session makes it highly likely that a live stream hangs up on the
`src.ctf.lttng-live` component between the moment we learn about it and
the moment we first ask for its live index.

In such event, the live stream iterator and its `ctf_msg_it` are both
created but the corresponding stream is uninitialized.

When the component realized that a live stream has hung up, it calls
`ctf_msg_iter_get_next_message()` to respect The Contract but then
errors out here:
  CAUSED BY [lttng-live: 'source.ctf.lttng-live'] (msg-iter.c:2474)
    Cannot create stream end message because stream is NULL:

The `stream` field is null because we never got the chance to received
any index for this stream.

It's possible for a `ctf_msg` state machine to pass by the
`STATE_EMIT_MSG_STREAM_END` state without having passed by the

Keep track of the fact that we sent a stream beginning message
downstream and that we need to send its respective stream end message.
If no message were send for a particular stream, we can omit sending a
stream end message.

Signed-off-by: Francis Deslauriers <>
Change-Id: If7f52f43162e7263785713c01c226907fe475d94
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
2 years agolib: msg. iter. inactivity message has a simple CS, not a default CS
Philippe Proulx [Tue, 14 Jan 2020 18:36:51 +0000 (13:36 -0500)] 
lib: msg. iter. inactivity message has a simple CS, not a default CS

The "default clock snapshot" properties of some types of messages come
from the fact that a stream class has a default clock class, and
therefore its streams have a default clock.

A message iterator inactivity message is not related to any stream, so
it doesn't have a "default" clock class: it has a simple clock class,
and therefore a simple clock snapshot.

Update the C and Python APIs to show this.

Signed-off-by: Philippe Proulx <>
Change-Id: I0142c4f91217791e3157d37a32f4e2f234afa8d2
Tested-by: jenkins <>
2 years agolib: remove self component param. from msg. iterator init. method
Philippe Proulx [Sat, 11 Jan 2020 13:57:43 +0000 (08:57 -0500)] 
lib: remove self component param. from msg. iterator init. method

Since a3f0c7db ("lib: introduce bt_message_iterator_class"), the
`self_component` parameter of
`bt_message_iterator_class_initialize_method` is useless because you can
access the equivalent with bt_self_message_iterator_borrow_component().

Remove it.

Signed-off-by: Philippe Proulx <>
Change-Id: I81e967acfd99b6ef3a2e01ae2ee19008a3c60408
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
2 years agolib: graph API: return borrowed references when adding to an object
Philippe Proulx [Sun, 12 Jan 2020 15:45:31 +0000 (10:45 -0500)] 
lib: graph API: return borrowed references when adding to an object

Before this patch, the following functions return a new reference when
their last parameter is not `NULL`:

* bt_graph_add_filter_component()
* bt_graph_add_filter_component_with_initialize_method_data()
* bt_graph_add_simple_sink_component()
* bt_graph_add_sink_component()
* bt_graph_add_sink_component_with_initialize_method_data()
* bt_graph_add_source_component()
* bt_graph_add_source_component_with_initialize_method_data()
* bt_graph_connect_ports()
* bt_self_component_filter_add_input_port()
* bt_self_component_filter_add_output_port()
* bt_self_component_sink_add_input_port()
* bt_self_component_source_add_output_port()

I'm changing this so that they return a borrowed reference instead. This
is more in line with other non-creating functions which always return
borrowed references.

It's okay to borrow here because the object to which you add an object
becomes its owner anyway.

Most sites are updated by removing the *_put_ref() call as the reference
is now borrowed.

Signed-off-by: Philippe Proulx <>
Change-Id: I71a5e18760504d8f8610162e3f6d7bd8d87474f9
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
2 years agolib: plugin-dev.h: rename `MESSAGE_ITERATOR` -> `MESSAGE_ITERATOR_CLASS`
Philippe Proulx [Fri, 10 Jan 2020 16:45:34 +0000 (11:45 -0500)] 
lib: plugin-dev.h: rename `MESSAGE_ITERATOR` -> `MESSAGE_ITERATOR_CLASS`

This is more in line with the message iterator class concept and
indicates that a given method belongs to the (implicit) component
class's message iterator class.

Signed-off-by: Philippe Proulx <>
Change-Id: Icbcefec886fcbb2b1928d4b1009f3aca88c032a0
CI-Build: Simon Marchi <>
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agolib: rename "self comp. input port message iter." -> "message iterator"
Philippe Proulx [Fri, 10 Jan 2020 02:16:39 +0000 (21:16 -0500)] 
lib: rename "self comp. input port message iter." -> "message iterator"

This simplifies the terminology (and therefore the eventual
documentation). It's possible because we have a single type of message
iterator since 6c373cc9 ("lib: remove output port message iterator").

I just moved everything in
`self-component-port-input-message-iterator.h` to `message-iterator.h`
and removed the specific prefix. Header files are about to be reshaped
soon anyway with the C API documentation patch.

In the Python API, I changed *._create_input_port_message_iterator() to
*._create_message_iterator(). I didn't change
`_UserComponentInputPortMessageIterator` because it's not a public name,
so it's not critical to change it now.

Signed-off-by: Philippe Proulx <>
Change-Id: I219b25495911363595bdf3b8b3f3b3cf802f20ac
Reviewed-by: Simon Marchi <>
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
2 years agolib: append `_FUNC` to `BT_PLUGIN_{INITIALIZE,FINALIZE}*`
Philippe Proulx [Fri, 10 Jan 2020 03:30:41 +0000 (22:30 -0500)] 

Signed-off-by: Philippe Proulx <>
Change-Id: Ie643815f2ec07149025d864324e6aefc55a14cd5
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
2 years agoReplace `` with ``
Philippe Proulx [Wed, 8 Jan 2020 21:42:03 +0000 (16:42 -0500)] 
Replace `` with ``

Signed-off-by: Philippe Proulx <>
Change-Id: I87e6b0722358d74a0377b6b3f37ed81d65aeaa8c

2 years agolib: create common base for bt_component_class_{source,filter}
Simon Marchi [Tue, 7 Jan 2020 22:23:31 +0000 (17:23 -0500)] 
lib: create common base for bt_component_class_{source,filter}

There are multiple spots which deal with message iterators, that have
duplicated code for source and filter components.  The code is the same,
except that one side deals with a bt_component_class_source and the
other with a bt_component_class_filter.

This patch introduce a common base,
bt_component_class_with_iterator_class, that holds the message iterator
class property.  The aforementioned code paths can then be deduplicated.

Change-Id: Ib2b42da4e77a0ab7faf94533684a7c1d665eb2e9
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agolib: introduce bt_message_iterator_class
Simon Marchi [Fri, 20 Dec 2019 22:20:55 +0000 (17:20 -0500)] 
lib: introduce bt_message_iterator_class

Today, when defining a source or filter component class, the user sets
the message iterator methods directly on the class.  The `next`
methods is mandatory, so it is passed to
bt_component_class_{source,filter}_create, and the rest are optional, so
they are set by dedicated setters.  All these setters are therefore
duplicated for source and filter, for example:

  - bt_component_class_source_set_message_iterator_initialize_method
  - bt_component_class_filter_set_message_iterator_initialize_method

This patch factorizes everything related to message iterator methods and
introduces the concept of "message iterator class".  Instead of setting
the message iterator methods on a component class, the user will now
prepare a message iterator class, and pass a reference to this class
when creating a source or filter component class.  So, what used to be

    src_cls = bt_component_class_source_create(my_iter_next_method);

would now become:

    iter_cls = bt_message_iterator_class_create(my_iter_next_method);
    src_cls = bt_component_class_source_create(iter_cls);

The message iterator class is a ref-counted object, and
bt_component_class_{source,filter}_create take their own references, so
a user would typically call bt_message_iterator_class_put_ref just after
that, as they would likely have no more use for the iterator class.  It
would be possible, in theory, to share an iterator class between
multiple component classes, but to this day no practical usage has been
found.  The search continues.

The macros to define a component class in a plugin remain the same,
where the message iterator methods are attached to the component class.
For example


In other words, the message iterator class concept is not exposed in
this area.

There is a small change on the message iterator `initialize` methods
impacting existing components: the `initialize` method of
`bt_message_iterator_class` accepts a `bt_self_component` instead of a
specialized `bt_self_component_source` or `bt_self_component_filter`.
If the `initialize` method requires the specialized version, the
user should pass it through the user data attached to the component.
This had to be changed in the debug info component, for example.

Change-Id: Idf8666d028eadae34589cc0460dc1da19ca75765
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agolib: run most of bt_self_component_port_input_message_iterator_try_finalize when...
Simon Marchi [Wed, 11 Dec 2019 18:43:34 +0000 (13:43 -0500)] 
lib: run most of bt_self_component_port_input_message_iterator_try_finalize when iterator is in NON_INITIALIZED state

We hit a failed BT_ASSERT in the specific scenario explained below (and
illustrated by the new test).

The problem

Let's say we have a graph with this topology, where everything is
implemented in Python:

  MySink [in] <-> [out] MyFilter (MyFilterIter) [in] <-> [out] MySource (MySourceIter)

And the following sequence of events:

1. MySink's _user_graph_is_configured method creates an iterator on its
   "in" input port.  This runs MyFilterIter's __init__ method.
2. MyFilterIter's __init__ method starts by creating an upstream
   iterator on its "in" input port.  This iterator, of type
   MySourceIter, is initialized successfully.
3. MyFilterIter's __init__ method creates some other data structure which
   happens to form a Python reference cycle (the MyFilterIter instance has a
   reference on an object, which has a reference on the MyFilterIter
4. MyFilterIter's __init__ method encounters an error, so an exception
   is raised.

When the MySourceIter is created, an entry is added to MyFilterIter's
upstream_msg_iters array (in the underlying
bt_self_component_port_input_message_iterator object).

When the exception is raised, because of the reference cycle, the
MyFilterIter Python object stays alive.  It has a reference on the
MySourceIter Python object, which keeps the underlying
bt_self_component_port_input_message_iterator object alive as well.

When the create_self_component_input_port_message_iterator call realizes
that the initialization of the filter iterator failed, it does a put_ref
on the iterator object, which ends up calling
bt_self_component_port_input_message_iterator_destroy.  In there, we
assert that:

  BT_ASSERT(iterator->upstream_msg_iters->len == 0);

This assertion does not hold, because the array still contains the entry
for the upstream iterator (on MySource).

Normally, the call to
bt_self_component_port_input_message_iterator_try_finalize, earlier in
bt_self_component_port_input_message_iterator_destroy, should take care
of unlinking any upstream or downstream iterator.  However, that step is
completely skipped because the iterator is still in the NON_INITIALIZED

To reproduce, it is important to have the two conditions before the
exception is raised:

  - an upstream iterator is created: otherwise, the upstream_msg_iters
    array is empty so the assertion is true
  - a Python reference cycle exists, keeping the MyFilterIter object
    alive: otherwise, it is destroyed when the exception is raised (or
    caught?), which destroys the MySourceIter object, which destroys the
    underlying bt_self_component_port_input_message_iterator object (or
    the source iterator), which removes itself from the filter
    iterator's upstream_msg_iters array.  The array now being empty, the
    assertion would be true.

Note that the Python reference cycle is a user error that is not
desirable, but likely to happen.  To avoid any memory leak due to such a
reference cycle, I think the filter iterator here should normally make
sure to break the reference cycle.  In a successful execution, it would
be in _user_finalize.  If __init__ fails, it should make sure to not
leave a reference cycle in place, perhaps by using a try-except to clear
it before exiting the function.

The fix

I believe it's wrong to skip the _try_finalize function even when we are
in this state, because it's possible (as shown above) for an iterator
initialize method to create some upstream iterators but then fail.  The
iterator remains in the NON_INITIALIZED state, but has some upstream

I have changed
bt_self_component_port_input_message_iterator_try_finalize so that when
the iterator is in the NON_INITIALIZED, we do unlink the upstream and
downstream iterators.  However, I don't think we want to call the
iterator's finalize method in that case, since it hasn't been properly
initialized (a bit like a C++ object destructor is not called if the
constructor throws).  So I made it so the finalize method is only called
if the state is not NON_INITIALIZED.

Change-Id: Ibe2cbc729fc81ff0d68219400d925110242b7ae1
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Francis Deslauriers <>
2 years agotests: plug memory leak in test_bin_info
Simon Marchi [Tue, 7 Jan 2020 19:51:41 +0000 (14:51 -0500)] 
tests: plug memory leak in test_bin_info

When running test_bin_info (e.g. through
under Valgrind, I get:

==25792== 1,112 (88 direct, 1,024 indirect) bytes in 1 blocks are definitely lost in loss record 18 of 20
==25792==    at 0x4C31B25: calloc (in /usr/lib/valgrind/
==25792==    by 0x55C2B10: g_malloc0 (gmem.c:129)
==25792==    by 0x55C86F2: g_option_context_new (goption.c:361)
==25792==    by 0x10CB25: main (test_bin_info.c:419)

Fix that by calling g_option_context_free.

Reported-by: Valgrind Memcheck
Change-Id: I9cd9a5ef786484169b9215744861af8cd6f5a9c8
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Francis Deslauriers <>
2 years agodebug-info: free existing build-id in bin_info_set_build_id
Simon Marchi [Tue, 7 Jan 2020 19:42:34 +0000 (14:42 -0500)] 
debug-info: free existing build-id in bin_info_set_build_id

When running test
tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu, I

Direct leak of 20 byte(s) in 1 object(s) allocated from:
    #0 0x7f623da26d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/
    #1 0x7f623ce37b10 in g_malloc0 (/usr/lib/x86_64-linux-gnu/
    #2 0x5583ef04ad8f in test_bin_info_build_id /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c:239
    #3 0x5583ef04bd01 in main /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c:445
    #4 0x7f623c7f7b96 in __libc_start_main (/lib/x86_64-linux-gnu/

This is because a build id is set twice on the same bin_info object in
test_bin_info_build_id.  However, bin_info_set_build_id doesn't free the
existing build id, if there is one, before assigning the new build id.

Fix that by freeing the existing build id, if any, before allocating the
new one.

Reported-by: ASan
Change-Id: I66409294bf11accde6c9d54a5e07572f9a995ff6
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Francis Deslauriers <>
2 years agocli: free log level string value
Simon Marchi [Tue, 7 Jan 2020 19:23:47 +0000 (14:23 -0500)] 
cli: free log level string value

In bt_config_convert_from_args, when encoutering a --log-level argument
applied to a non-option argument, we create a string bt_value.  We add
it to an array, which takes its own reference on it.  However, in the
successful case, we never drop our reference to it, so it's never freed.
Fix it by calling bt_value_put_ref on it in all cases.

This is the error reported by address sanitizer:

Direct leak of 128 byte(s) in 2 object(s) allocated from:
    #0 0x7f1e36724d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/
    #1 0x7f1e35d97b10 in g_malloc0 (/usr/lib/x86_64-linux-gnu/
    #2 0x558c39c19d3b in bt_config_convert_from_args /home/smarchi/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:3445
    #3 0x558c39c1f9e4 in bt_config_cli_args_create /home/smarchi/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:4654
    #4 0x558c39c233db in bt_config_cli_args_create_with_default /home/smarchi/src/babeltrace/src/cli/babeltrace2-cfg-cli-args-default.c:74
    #5 0x558c39c0781a in main /home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2647
    #6 0x7f1e35757b96 in __libc_start_main (/lib/x86_64-linux-gnu/

Reported-by: ASan
Change-Id: Ib2251d9dd8628bda128ae4d2e756d0d86fa12163
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agobt2: free port user data when finalizing components
Simon Marchi [Tue, 7 Jan 2020 01:47:20 +0000 (20:47 -0500)] 
bt2: free port user data when finalizing components

When creating component ports in Python, it is possible to pass a Python
object as user data:

    class MySource(
        bt2._UserSourceComponent, message_iterator_class=MyIter
        def __init__(self, config, params, obj):
            self._add_output_port('out', MyUserData())

The port takes a reference to this Python object, thanks to the `void *`
typemap in native_bt_port.i:

    %typemap(out) void * {
            $result = $1;

However, this reference is never released.

This patches makes it so that when a component is finalized, it releases
the reference for the user data of all of its ports.

Change-Id: Ifebecc3b242c2ccf2bd65347a9087b90093f286c
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
2 years agobuild: try calling python-config with --embed
Simon Marchi [Sun, 29 Dec 2019 22:27:04 +0000 (17:27 -0500)] 
build: try calling python-config with --embed

To get the flags required to link an application with Python 3.8 (such
as to embed Python in the application), it is necessary to use the
"--embed" flag of python-config.  These flags include "-lpython3.8".
Without "--embed", the printed flags are for building a Python
extension.  These don't require being linked with the Python library,
since they are dlopen'ed by the library itself.

Our Python plugin provider requires being linked with Python, since it
embeds a Python interpreter.  Since we don't use "--embed" currently
when getting link flags, we don't link with the Python library, and
therefore the provider is not usable with Python 3.8.

The solution proposed here:

is to try calling python-config with --embed first, and then without if
that didn't work.  With this patch, I am able to use the Python plugin
provider with Python 3.8.

Change-Id: I0c0e61dd3bded853abf124c651efe98ee7700101
Signed-off-by: Simon Marchi <>
Reviewed-by: Michael Jeanson <>
2 years agotests: remove unnecessary message iterator classes
Simon Marchi [Tue, 7 Jan 2020 03:23:08 +0000 (22:23 -0500)] 
tests: remove unnecessary message iterator classes

These user message iterator classes don't do anything special, we can
remove them and pass bt2._UserMessageIterator directly to the components
instead, reducing a little bit the noise in the tests.

Some classes in were simply unused, so I removed

Change-Id: I79f787b9d121a3dc6456f81090ebf51d088d2c73
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agotests: make test_sink_self_port_user_data actually test a sink
Simon Marchi [Tue, 7 Jan 2020 01:29:52 +0000 (20:29 -0500)] 
tests: make test_sink_self_port_user_data actually test a sink

This test method is meant to test a sink, but currently tests a filter,
fix that.

Change-Id: Icca321f50a43b709b64f15c885c37c6e7106653d
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agolib: remove unnecessary (void *) cast in extend_map_element
Simon Marchi [Mon, 6 Jan 2020 19:00:31 +0000 (14:00 -0500)] 
lib: remove unnecessary (void *) cast in extend_map_element

Change-Id: I238aeef707d2822030c18e2a8dc1ebf4d432a9f2
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agocli: fix bt_plugin leak when using `-i ctf`
Simon Marchi [Mon, 6 Jan 2020 18:20:57 +0000 (13:20 -0500)] 
cli: fix bt_plugin leak when using `-i ctf`

When running:

    libtool --mode=execute valgrind --leak-check=full  ./src/cli/babeltrace2 /home/smarchi/src/babeltrace/tests/data/ctf-traces/succeed/succeed1 -i ctf

I get:

    2,680 (168 direct, 2,512 indirect) bytes in 1 blocks are definitely lost in loss record 56 of 58
       at 0x4C31B25: calloc (in /usr/lib/valgrind/
       by 0x5360B10: g_malloc0 (gmem.c:129)
       by 0x4E97502: bt_plugin_create_empty (plugin.h:178)
       by 0x4E9AD72: bt_plugin_so_create_empty (plugin-so.c:1239)
       by 0x4E9B0D1: bt_plugin_so_create_all_from_sections (plugin-so.c:1342)
       by 0x4E9BFBF: bt_plugin_so_create_all_from_file (plugin-so.c:1678)
       by 0x4E93FB4: bt_plugin_find_all_from_file (plugin.c:210)
       by 0x4E95300: nftw_append_all_from_dir (plugin.c:551)
       by 0x5956F13: process_entry (ftw.c:464)
       by 0x59573BA: ftw_dir (ftw.c:543)
       by 0x5957BEB: ftw_startup (ftw.c:768)
       by 0x4E95748: bt_plugin_create_append_all_from_dir (plugin.c:641)

The call to find_loaded_plugin at babeltrace2-cfg-cli-args.c:4013
returns a new reference to the plugin, for which we don't have a
corresponding put_ref.

Looking at all the users of find_loaded_plugin, they only really need to
borrow the plugin, so rather than add a put_ref, I've made it so
find_loaded_plugin returns a borrowed reference instead of a new
reference.  For clarity, I've renamed that function to
borrow_loaded_plugin_by_name.  And for consistency, I've renamed
borrow_loaded_plugin to borrow_loaded_plugin_by_index.

Change-Id: I19234bda6e219efa3e55da760846d138c381fac4
Signed-off-by: Simon Marchi <>
Reported-by: Valgrind Memcheck
Tested-by: jenkins <>
2 years agocli: remove unused structures and enums
Simon Marchi [Mon, 6 Jan 2020 16:47:23 +0000 (11:47 -0500)] 
cli: remove unused structures and enums

These have apparently been unused for a while, since:

    commit db0f160afd671de44e52d2b364de957ddccdac02
    Author: Philippe Proulx <>
    Date:   Fri Mar 3 00:13:36 2017 -0500

        CLI: add `run` command and make `convert` command use it

Change-Id: Ib8ce061540a0c268d3949a565c570142f37e123c
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agotests: fix test failure with msys2's Python 3.8.1-1 package
Simon Marchi [Tue, 7 Jan 2020 03:33:49 +0000 (22:33 -0500)] 
tests: fix test failure with msys2's Python 3.8.1-1 package

msys2's Python package version 3.8.1-1 produces wrong output for
PureWindowsPath's string representation.  It does this:

    >>> import pathlib
    >>> str(pathlib.PureWindowsPath('/yo/madame'))

When it should do this:

    >>> import pathlib
    >>> str(pathlib.PureWindowsPath('/yo/madame'))

Because of this, tests/plugins/src.ctf.fs/query/
is currently failing, as the Babeltrace output contains back-slashes but
the regex we produce contains forward-slashes.

The issue appears to be fixed in 3.8.1-2:

But anyway, it's not really necessary to use PureWindowsPath and
PurePosixPath.  I changed the code to just use a version of the regex
with back-slashes when on Windows, and with front-slashes when on the

Change-Id: Idcd865d87350682644a536ada95cfac161cc1182
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 years agotrimmer: free GMatchInfo object in set_bound_from_str
Simon Marchi [Tue, 31 Dec 2019 04:34:29 +0000 (23:34 -0500)] 
trimmer: free GMatchInfo object in set_bound_from_str

When a call to compile_and_match succeeds, it returns an allocated
GMatchInfo object in `*match_info`, which is never freed, causing a
memory leak:

    ==3711000== 508 (72 direct, 436 indirect) bytes in 1 blocks are definitely lost in loss record 33 of 42
    ==3711000==    at 0x483AB65: calloc (vg_replace_malloc.c:762)
    ==3711000==    by 0x49CB7C1: g_malloc0 (in /usr/lib/
    ==3711000==    by 0x49BCEAA: ??? (in /usr/lib/
    ==3711000==    by 0x49BD310: g_regex_match_full (in /usr/lib/
    ==3711000==    by 0x49BDEEA: g_regex_match (in /usr/lib/
    ==3711000==    by 0x510CF25: compile_and_match (trimmer.c:187)
    ==3711000==    by 0x510D55D: set_bound_from_str (trimmer.c:378)
    ==3711000==    by 0x510D90A: set_bound_from_param (trimmer.c:463)
    ==3711000==    by 0x510DEBE: init_trimmer_comp_from_params (trimmer.c:568)
    ==3711000==    by 0x510E090: trimmer_init (trimmer.c:643)
    ==3711000==    by 0x4886457: add_component_with_init_method_data (graph.c:971)
    ==3711000==    by 0x4886C28: bt_graph_add_filter_component_with_initialize_method_data (graph.c:1075)

Fix that by calling g_match_info_free at the end of the function.

Reported-by: Valgrind Memcheck
Change-Id: Iee42f63d45f5761e1191dcc6d3f6d47e75a4123c
Signed-off-by: Simon Marchi <>
Reviewed-by: Francis Deslauriers <>
2 years agobt2: rename `object` parameter -> `object_name`
Philippe Proulx [Wed, 18 Dec 2019 02:54:38 +0000 (21:54 -0500)] 
bt2: rename `object` parameter -> `object_name`

I think it's more evident this way.

Signed-off-by: Philippe Proulx <>
Change-Id: I20f80ab8b28c4f4f0d390dd9fb4676ff69e8e609
Tested-by: jenkins <>
2 years agolib: remove bt_query_executor_interrupt, add bt_query_executor_borrow_default_interrupter
Simon Marchi [Tue, 17 Dec 2019 19:11:36 +0000 (14:11 -0500)] 
lib: remove bt_query_executor_interrupt, add bt_query_executor_borrow_default_interrupter

It is currently possible to interrupt a running quer executor with
bt_query_executor_interrupt.  It is however not possible to reset the
default interrupter that this function sets and resume the query

Rather than add a new query executor function to reset the default query
executor interrupter, introduce a new function,
bt_query_executor_borrow_default_interrupter, to borrow that default
interrupter.  All the bt_interrupter API is therefore accessible with
this default interrupter.

This patch removes the bt_query_executor_interrupt function, since it's
no longer needed.

Change-Id: I877dfbf22e36233750a71220fc5ab0297f8c0c28
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
This page took 0.095824 seconds and 4 git commands to generate.