4 weeks agoFix: lib: use appropriate format specifier to print message iterator class master
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 <>
Reviewed-by: Geneviève Bastien <>
Reviewed-by: Philippe Proulx <>
4 weeks agoFix: lib: BT_ASSERT_PRE_NON_NULL_FROM_FUNC(): change `: ` -> `.` in msg.
Philippe Proulx [Wed, 22 Apr 2020 21:18:38 +0000 (17:18 -0400)] 
Fix: lib: BT_ASSERT_PRE_NON_NULL_FROM_FUNC(): change `: ` -> `.` in msg.

This changes, for example,

    Error is:
    Value object is NULL:


    Error is:
    Value object is NULL.

Signed-off-by: Philippe Proulx <>
Change-Id: Ic122d50f5cb88dd72978d5dd8e2e4b22ee965a3e
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
4 weeks agotests: add libbabeltrace2 pre/postcondition testing infrastructure
Philippe Proulx [Tue, 14 Apr 2020 01:38:22 +0000 (21:38 -0400)] 
tests: add libbabeltrace2 pre/postcondition testing infrastructure

This patch adds a basic libbabeltrace2 pre/postcondition testing
infrastructure to the project.

When a libbabeltrace2 public function precondition or postcondition is
not satisfied, the function logs a FATAL-level message which indicates
what's wrong and then aborts. Slow path functions check such conditions
unconditionally, while fast path functions check them only in developer

Testing that a libbabeltrace2 function catches an unsatisfied
pre/postcondition and reports it is not straightforward: the library
aborts the program, so we can't use the usual approach because the test
program itself would abort.

The solution brought by this patch is the following process in

1. The `conds-triggers.c` program contains all the pre/postcondition
   failure triggering instructions to test, one condition per function.

   Each triggering function triggers a single pre/postcondition check.
   It is expected that the function actually aborts.

   main() calls ppc_main(), an internal utility, with its command-line
   arguments and an array of condition trigger descriptors.

   Each condition trigger descriptor has:

   * A condition type: precondition or postcondition.
   * The ID of the condition to trigger.
   * A name suffix.
   * A condition triggering function.

   Each condition trigger descriptor has a unique name: its condition ID
   and an optional name suffix.

   As of this patch, the PPC_TRIGGER_*_RUN_IN_COMP_CLS_INIT() macros
   create condition trigger descriptors of which the function runs
   within a component class initialization function (accepts a
   `bt_self_component *` parameter). This is often needed as many
   libbabeltrace2 functions are only accessible through a self component
   (all the trace IR API, for example).

   ppc_main() handles two command-line subcommands:

       Prints a JSON array of objects which represent the triggering
       descriptors, for example (output for this patch):

               "cond-id": "pre:field-class-integer-set-field-value-range:valid-n",
               "name": "pre:field-class-integer-set-field-value-range:valid-n-0"
               "cond-id": "pre:field-class-integer-set-field-value-range:valid-n",
               "name": "pre:field-class-integer-set-field-value-range:valid-n-gt-64"
               "cond-id": "pre:field-class-integer-set-field-value-range:not-null:field-class",
               "name": "pre:field-class-integer-set-field-value-range:not-null:field-class"

   `run INDEX`:
       Runs the condition triggering function for the descriptor at
       index `INDEX` in the `list` array.

       It is expected that this command aborts.

2. `test_conds` is a Bash script which only does this:

       export BT_TESTS_LIB_CONDS_TRIGGER_BIN="$BT_TESTS_BUILDDIR/$reldir/conds-triggers"

       if [ "$BT_OS_TYPE" = "mingw" ]; then

       run_python_bt2_test "$BT_TESTS_SRCDIR/$reldir"

   In other words, it runs the Python TAP test runner to discover and
   run tests in ``.

   This script is part of the `make check` test set.

3. In ``, a function:

   a) Runs `conds-triggers list` and decodes the output to get the list
      of available condition trigger descriptors.

      This step also validates the regular expressions and checks that
      there are no duplicate descriptor names.

   b) For each condition trigger descriptor, creates and adds a test to
      its single test case class which:

        I. Executes `conds-triggers run INDEX` as a subprocess,
           where `INDEX` is the descriptor's index.

       II. Reads the complete process's standard error.

      III. Asserts that the process aborts (`SIGABRT` signal).

           This seems to be only possible on a POSIX system with the
           `subprocess.Popen` API.

       IV. Asserts that the standard error (II) contains the
           descriptor's condition ID.

All this is only enabled if, at configuration time:

* Python 3 is available.
* The Babeltrace 2 developer mode is enabled (`BABELTRACE_DEV_MODE=1`).

This patch's `conds-triggers.c` includes two precondition triggering
functions to confirm that everything works as expected:

    When calling bt_field_class_integer_set_field_value_range(), the
    parameter `N` cannot be greater than 64.

    When calling bt_field_class_integer_set_field_value_range(), the
    parameter `N` cannot be 0.

    When calling bt_field_class_integer_set_field_value_range(), the
    field class cannot be `NULL`.

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

4 weeks agolib: assign a unique ID to each pre/postcond. and report it on failure
Philippe Proulx [Tue, 21 Apr 2020 15:15:42 +0000 (11:15 -0400)] 
lib: assign a unique ID to each pre/postcond. and report it on failure

This patch changes the libbabeltrace2 pre/postcondition assertion macros
so that each precondition and postcondion has a unique ID within the

The macros report (log with a FATAL level) the condition ID on assertion
failure as such (logging prefixes removed):

    Babeltrace 2 library precondition not satisfied.
    Condition ID: `pre:field-class-integer-set-field-value-range:valid-n`.
    Function: bt_field_class_integer_set_field_value_range().
    Error is:
    Unsupported size for integer field class's field value range
    (minimum is 1, maximum is 64): size=65

The main goal of this change is to make it easier to test library
precondition and postcondition assertions: now you only need to confirm
that the log indicates the expected condition ID, making the details
("Unsupported size for [...]" in the example above) unimportant.

The condition IDs could also exist in the documentation so as to make it
easier to search for libbabeltrace2 pre/postcondition documentation when
failing to satisfy one.

The general condition ID format is:



    `pre` or `post`.

    Name of the API function (precondition) or user function type
    (postcondition) without the `bt_` prefix and with `_` replaced with

    With the scope of the function: unique, specific precondition or
    postcondition ID.

The BT_ASSERT_PRE_FROM_FUNC() macro (and its developer mode counterpart)
accepts a function name and an ID suffix.

The BT_ASSERT_PRE() macro (and its developer mode counterpart) only
accepts an ID suffix: it uses BT_ASSERT_PRE_FROM_FUNC() with `__func__`
as the function name.

All the other precondition assertion macros follow the same scheme:
`_FROM_FUNC` suffix for a specific function, no suffix for the current

Many precondition assertion macros in `assert-cond.h` build a complete
ID suffix based on a part of it. For example, BT_ASSERT_PRE_NON_NULL()
accepts an object ID, so that

    BT_ASSERT_PRE_NON_NULL("description", descr, "Description");

has the condition ID, when used from the hypothetical public function
bt_do_xyz(), `pre:do-xyz:not-null:description`.

It is imperative that the used API function name is always the one the
user called. Knowing this, internal, static functions _cannot_ use
BT_ASSERT_PRE() because the reported function name would be the internal
one. Not only is this confusing for the library user, it could also
change in the future.

This patch uses two strategies to deal with this constraint depending
on the intended execution path of the public function:

Slow path:
    The common (internal) function accepts an `api_func` parameter which
    is the ultimate public API function name.

    The common function only uses precondition assertion macros which
    end with `_FROM_FUNC`.

    A public function which calls this common function passes `__func__`
    as its `api_func` parameter.

Fast path:
    We define (locally) a new macro which uses the required precondition
    assertion macros (the variants without `_FROM_FUNC`).

    A public function which calls the common function uses the custom

Postconditions are checked when a user function returns. Therefore, the
function name in that case is the user function type name.
BT_ASSERT_POST() accepts a function name and an ID suffix.

_BT_ASSERT_COND() calls the internal bt_lib_assert_cond_failed() which
formats the condition ID, prints it and the function name, prints the
details, and aborts.

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

4 weeks agolib: add bt_lib_log_v()
Philippe Proulx [Tue, 21 Apr 2020 14:56:20 +0000 (10:56 -0400)] 
lib: add bt_lib_log_v()

This is a `va_list` (vprintf() style) version of bt_lib_log().

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

4 weeks agolib: rename BT_ASSERT_PRE_BEGIN_LE_END() -> BT_..._MSG_CS_BEGIN_LE_END()
Philippe Proulx [Tue, 21 Apr 2020 14:42:13 +0000 (10:42 -0400)] 

This adds a namespace as BT_ASSERT_PRE_MSG_CS_BEGIN_LE_END() is now part
of the common `assert-cond.h` header.

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

4 weeks agolib: use common precond. assert. macros from `assert-cond.h` thru lib
Philippe Proulx [Thu, 16 Apr 2020 17:13:11 +0000 (13:13 -0400)] 
lib: use common precond. assert. macros from `assert-cond.h` thru lib

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

4 weeks agolib: rename *_IS_TYPE() and *_HAS_ID() macros -> *_HAS_TYPE()
Philippe Proulx [Tue, 21 Apr 2020 14:27:48 +0000 (10:27 -0400)] 
lib: rename *_IS_TYPE() and *_HAS_ID() macros -> *_HAS_TYPE()

This is to normalize this type of macro.

Since those macros check that a given object _has_ a given type, I
believe "has" makes more sense than "is" (you pass the instance, not the

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

4 weeks agolib: commonize some precondition assertion macros
Philippe Proulx [Thu, 16 Apr 2020 17:12:55 +0000 (13:12 -0400)] 
lib: commonize some precondition assertion macros

1. Rename `assert-cond.h` to `assert-cond-base.h`.

2. Move common specialized pre/postcondition macros from
   `assert-cond-base.h` to `assert-cond.h`.

   Now `assert-cond-base.h` only contains the very basic
   pre/postcondition assertion macros.

3. Move common specialized macros from various internal header files to

4. Add new common specialized macros to `assert-cond.h`, mostly "non
   null" precondition assertion macros.

The goal of this patch is to make it easy to change code for many sites
at the same time when those sites use the same macro.

This patch introduces the common precondition assertion macros, but
does not use them in source files (future patch).

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

4 weeks agolib: move bt_graph_configure() to `graph.c` (only used there)
Philippe Proulx [Thu, 16 Apr 2020 14:00:55 +0000 (10:00 -0400)] 
lib: move bt_graph_configure() to `graph.c` (only used there)

Signed-off-by: Philippe Proulx <>
Change-Id: I097f61f1e64d9e83d929980f5224b429e6202eb5
Reviewed-by: Simon Marchi <>
4 weeks agoFix: lib: bt_component_class_sink_simple_borrow() is internal
Philippe Proulx [Thu, 16 Apr 2020 13:58:08 +0000 (09:58 -0400)] 
Fix: lib: bt_component_class_sink_simple_borrow() is internal

My guess is that at some point the intention was to have the user borrow
the simple sink component class and call bt_graph_add_sink_component()
herself but that's not how it works now:
bt_graph_add_simple_sink_component() calls
bt_component_class_sink_simple_borrow() internally.

Signed-off-by: Philippe Proulx <>
Change-Id: I77e10d43a2d90ea4b99c7c7fc09606cbf2ffbe41
Reviewed-by: Simon Marchi <>
4 weeks agolib: object.h: convert precondition assertions to internal assertions
Philippe Proulx [Thu, 16 Apr 2020 13:53:01 +0000 (09:53 -0400)] 
lib: object.h: convert precondition assertions to internal assertions

The `object.h` API is completely internal.

We used to have only two public reference counting modification
functions (to get and put references), but since c5b9b4417 ("lib: make
public reference count functions have strict types"), each shared object
type has its own reference counting modification functions. Therefore
it's impossible that bt_object_get_ref() or bt_object_put_ref() be
called with a unique object without at least getting a compiler warning.

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

4 weeks agolib: move code only used by create_event() to `message/event.c`
Philippe Proulx [Thu, 16 Apr 2020 12:55:56 +0000 (08:55 -0400)] 
lib: move code only used by create_event() to `message/event.c`

Those functions, bt_event_set_packet() and bt_event_set_stream(), used
to exist in the Babeltrace 1 to 2 transition. But now it seems like
they're internal and only used by the also internal create_event().

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

4 weeks agolib: merge `assert-pre.h` and `assert-post.h` into `assert-cond.h`
Philippe Proulx [Wed, 15 Apr 2020 20:47:18 +0000 (16:47 -0400)] 
lib: merge `assert-pre.h` and `assert-post.h` into `assert-cond.h`

Merge both files into a single one to make it possible to reuse code.

Specific `BT_ASSERT_PRE*` and `BT_ASSERT_POST*` macros which were
identical are merged into a single one with the `BT_ASSERT_COND*` prefix

No functional changes intended.

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

4 weeks agoFix: sink.text.pretty: assign status at the end of pretty_consume
Simon Marchi [Wed, 15 Apr 2020 01:23:52 +0000 (21:23 -0400)] 
Fix: sink.text.pretty: assign status at the end of pretty_consume

The compiler on SLES 12 reports:

pretty.c:200:2: warning: 'status' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return status;

We are indeed missing an assignment of status at the end, if everything
went well.  In practice, status has the right value (_OK) from the last
call of handle_message.  But if, for some reason,
bt_message_iterator_next returns OK with 0 messages, then it would stay
unset.  So assigning it explicitly at the end doesn't hurt.

Change-Id: Ic3bf018388f006c919173f9e8942a8ab2384c0f1
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
5 weeks agosink.text.pretty: append error causes where applicable
Simon Marchi [Tue, 14 Apr 2020 18:28:23 +0000 (14:28 -0400)] 
sink.text.pretty: append error causes where applicable

Change-Id: I34a01f4647538ec09b26588335a708ff0e739fa8
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
5 weeks agosink.text.pretty: simplify error handling in pretty_consume
Simon Marchi [Tue, 14 Apr 2020 18:33:24 +0000 (14:33 -0400)] 
sink.text.pretty: simplify error handling in pretty_consume

Replace the switch with a simple condition.  On _END, it is not
necessary to put the message iterator, that will be done in

Change-Id: Ia0bd20e0d119cae155c03cc5d7656a5c4619ebb8
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
5 weeks agosink.text.pretty: update logging macros
Simon Marchi [Tue, 14 Apr 2020 17:02:00 +0000 (13:02 -0400)] 
sink.text.pretty: update logging macros

Change the logging macros to be more in sync with how it's done in other
component classes of the project

Add the `self_comp` and `log_level` fields to the pretty_component
structure, and change the BT_COMP_LOG_SELF_COMP and BT_LOG_OUTPUT_LEVEL
to assume there's always a pointer to such a structure named `pretty`.

Change-Id: I6292f3c9b6b7f238e335cfcc90259a1f0047313d
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
5 weeks 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 <>
5 weeks agodoc: bindings: python: lttng version referenced is out of date
Jonathan Rajotte [Tue, 14 Apr 2020 20:28:59 +0000 (16:28 -0400)] 
doc: bindings: python: lttng version referenced is out of date

Use the "latest" link instead.

Signed-off-by: Jonathan Rajotte <>
Change-Id: I229ebb3e2e4e9711f6022370d83194d110c937e5
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
5 weeks agoCleanup: src.ctf.lttng-live: clarify comment
Francis Deslauriers [Mon, 17 Feb 2020 20:00:07 +0000 (15:00 -0500)] 
Cleanup: src.ctf.lttng-live: clarify comment

Signed-off-by: Francis Deslauriers <>
Change-Id: If6841b7e1c06dacbb46f7b6419291d2057fc6c2c
Reviewed-by: Philippe Proulx <>
5 weeks agolib: add precondition checks that count of discarded events/packets is greater than 0
Simon Marchi [Thu, 9 Apr 2020 20:44:07 +0000 (16:44 -0400)] 
lib: add precondition checks that count of discarded events/packets is greater than 0

It does not make sense to send a discarded packet or discarded event
message with the count 0.  That would mean that there is no discarded
event or packet, so the message must simply not be sent.  If the number
of packets or events that were discarded is unknown, the count must not
be set, in which case it will stay "unavailable".

A precondition failure looks like:

    04-12 00:17:25.171 680020 680020 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_packets_set_count@discarded-items.c:317 Babeltrace 2 library precondition not satisfied; error is:
    04-12 00:17:25.171 680020 680020 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_packets_set_count@discarded-items.c:317 Discarded packet count is 0.
    04-12 00:17:25.171 680020 680020 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_packets_set_count@discarded-items.c:317 Aborting...

The equivalent checks are added to the Python bindings, as well as

Change-Id: I3b56f2635df5d918ec35e9756b0a9658e1a1668d
Signed-off-by: Simon Marchi <>
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
5 weeks agobt2: check that port is connected when creating message iterator
Simon Marchi [Sun, 12 Apr 2020 18:52:20 +0000 (14:52 -0400)] 
bt2: check that port is connected when creating message iterator

Creating a message iterator for a non-connected input port hits a
precondition assertion.  Add some checks in the Python bindings to raise
a more friendly ValueError in that case.

Change-Id: I323e49c7408f5df8e1702eb993933ffc251b6c63
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
5 weeks agolib, bt2: add precondition check for port name unicity
Simon Marchi [Thu, 9 Apr 2020 20:23:47 +0000 (16:23 -0400)] 
lib, bt2: add precondition check for port name unicity

The documentation for the _add_input_port API functions state that there
must be no other input port with the same name.  Ditto for output ports.

This patch adds some precondition checks for that.  A failed assertion looks
like this:

    04-09 16:29:23.968 2961462 2961462 F LIB/COMPONENT-SINK bt_self_component_sink_add_input_port@component-sink.c:132 Babeltrace 2 library precondition not satisfied; error is:
    04-09 16:29:23.968 2961462 2961462 F LIB/COMPONENT-SINK bt_self_component_sink_add_input_port@component-sink.c:132 Input port name is not unique: name="bob", comp-addr=0x60c000001e40, comp-name="mon sink", comp-log-level=NONE, comp-class-type=SINK, comp-class-name="MySink", comp-class-partial-descr=""
    04-09 16:29:23.968 2961462 2961462 F LIB/COMPONENT-SINK bt_self_component_sink_add_input_port@component-sink.c:132 Aborting...

Equivalent checks are added to the Python bindings, as well as tests.

Change-Id: I12f5a16b6b5efc46f2b50f27e338cc57b8487ff6
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
5 weeks agolib: add precond. check for begin <= end on pkt./ev. disc. msg. creation
Simon Marchi [Thu, 9 Apr 2020 21:33:55 +0000 (17:33 -0400)] 
lib: add precond. check for begin <= end on pkt./ev. disc. msg.  creation

Add a precondition check in:

- bt_message_discarded_events_create_with_default_clock_snapshots
- bt_message_discarded_packets_create_with_default_clock_snapshots

Verify that the beginning clock snapshot value is less-than or equal-to
the end clock snapshot.

A failure looks like this:

    04-12 00:01:37.519 653088 653088 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_events_create_with_default_clock_snapshots@discarded-items.c:221 Babeltrace 2 library precondition not satisfied; error is:
    04-12 00:01:37.519 653088 653088 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_events_create_with_default_clock_snapshots@discarded-items.c:221 Beginning default clock snapshot value is greater than end default clock snapshot value: cs-begin-val=20, cs-end-val=10, msg-iter-addr=0x611000001bc0, msg-iter-upstream-comp-name="ze source", msg-iter-upstream-comp-log-level=NONE, msg-iter-upstream-comp-class-type=SOURCE, msg-iter-upstream-comp-class-name="MySrc", msg-iter-upstream-comp-class-partial-descr=""
    04-12 00:01:37.519 653088 653088 F LIB/MSG-DISCARDED-ITEMS bt_message_discarded_events_create_with_default_clock_snapshots@discarded-items.c:221 Aborting...

Change-Id: I1d4cc820d9daeff0fd3a80262c36609fe10a1958
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
5 weeks 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 <>
5 weeks 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 <>
5 weeks 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 <>
Change-Id: I4811336d567ff379cbe9e789099af8d6c7661a62
Tested-by: jenkins <>
6 weeks 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 <>
6 weeks agosource.text.dmesg: use BT_COMP_LOGE_APPEND_CAUSE
Simon Marchi [Tue, 17 Mar 2020 17:19:37 +0000 (13:19 -0400)] 
source.text.dmesg: use BT_COMP_LOGE_APPEND_CAUSE

Use BT_COMP_LOGE_APPEND_CAUSE where possible, when returning error
statuses.  Some errors paths due to allocation failure now return MEMORY_ERROR,
rather than ERROR.

Change-Id: I32a15d64538a23406114ef661990928f6f9ed296
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks agosource.text.dmesg: replace switch to convert status with cast
Simon Marchi [Sat, 11 Apr 2020 17:16:54 +0000 (13:16 -0400)] 
source.text.dmesg: replace switch to convert status with cast

Replace the switch currently used in create_port, to convert the status of
bt_self_component_source_add_output_port, with a simple cast, as per standard
procedure.  Since create_port becomes trivial, remove it and inline the code in dmesg_init.

Change-Id: Iccdf0ba298c73616b7c86b14e5208de4519b77d8
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks agoconfigure: remove -Wno-format-nonliteral
Simon Marchi [Sun, 15 Mar 2020 20:12:52 +0000 (16:12 -0400)] 
configure: remove -Wno-format-nonliteral

This patch removes all the offending instances of -Wformat-nonliteral
and removes -Wno-format-nonliteral from the warning flags we enable.

In cases where we re-use the same format string multiple times, like:

    const char *const msg = "Hello %d\n";

    if (something) {
        pass(msg, value);
    } else {
        fail(msg, value);

... my compiler (gcc (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130)
complains that the format string is not a literal, even though the `msg`
variable is const and assigned a literal.  I've replaced these with a

In other places, we manually manipulate and craft format strings, to
I've just disabled the warning there.

The generated SWIG wrapper for the error appending functions cause some
warnings like this:

    bt2/native_bt.c: In function ‘_wrap_current_thread_error_append_cause_from_component__varargs__’:
    bt2/native_bt.c:7839:3: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
     7839 |   result = (bt_current_thread_error_append_cause_status)bt_current_thread_error_append_cause_from_component(arg1,(char const *)arg2,arg3,(char const *)arg4,ar
          |   ^~~~~~

Since we don't actually need these functions from the Python bindings,
I've made SWIG not generate a wrapper for them.

Change-Id: Ic6834dc44abce7be8e113e9cbf3f33a3f09809e2
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
6 weeks agosink.text.details: sprinkle BT_COMP_LOGE_APPEND_CAUSE liberally
Simon Marchi [Thu, 12 Mar 2020 15:10:40 +0000 (11:10 -0400)] 
sink.text.details: sprinkle BT_COMP_LOGE_APPEND_CAUSE liberally

Add some BT_COMP_LOGE_APPEND_CAUSE where we would return an error
without logging, or replace existing BT_COMP_LOGE with

Change-Id: I6eeaaa713fe9b4112df82b3c0fccb16a4f54f6c4
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks agosink.text.details: replace switch to convert status with cast
Simon Marchi [Sat, 11 Apr 2020 17:08:54 +0000 (13:08 -0400)] 
sink.text.details: replace switch to convert status with cast

Replace the switch currently used in details_consume, to convert the
status of bt_message_iterator_next, with a simple cast, as per standard

Change-Id: Iea35bd26f4af983d7cca37fc01b2b2f903cc73da
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks agoflt-utils.muxer: use BT_COMP_LOGE_APPEND_CAUSE
Simon Marchi [Tue, 24 Mar 2020 19:16:04 +0000 (15:16 -0400)] 
flt-utils.muxer: use BT_COMP_LOGE_APPEND_CAUSE


Change-Id: I7436a0d37f3d3c193c400ed55ef41310ab2ec1f0
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks 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 <>
6 weeks agolib: add `size >= 1` pre-condition to bt_field_class_integer_set_field_value_range
Simon Marchi [Thu, 9 Apr 2020 19:32:13 +0000 (15:32 -0400)] 
lib: add `size >= 1` pre-condition to bt_field_class_integer_set_field_value_range

An integer of 0 bits is not very useful.

Change-Id: I00a4114dc4a949a4876f810f603226a1c5936751
Signed-off-by: Simon Marchi <>
Reviewed-by: Philippe Proulx <>
6 weeks 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 <>
6 weeks 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 <>
6 weeks agoMove to kernel style SPDX license identifiers
Michael Jeanson [Tue, 10 Mar 2020 16:25:12 +0000 (12:25 -0400)] 
Move to kernel style SPDX license identifiers

The SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

See for details.

Change-Id: I7c25a3bc48ee328500a604cb276877d4cadfa997
Signed-off-by: Michael Jeanson <>
CI-Build: Philippe Proulx <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
6 weeks 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 <>
Reviewed-by: Philippe Proulx <>
Tested-by: jenkins <>
6 weeks agobt2: make `_EventConst` a mapping
Philippe Proulx [Tue, 7 Apr 2020 00:22:16 +0000 (20:22 -0400)] 
bt2: make `_EventConst` a mapping

The `_EventConst` class already implemented the __getitem__() method
to make it easy to access a payload, specific context, common context,
or packet context field (in this order) by name, for example:


If two root fields contain fields which share the same name, one of them
has the priority and the other one is not accessible through this

This patch makes the `_EventConst` class a full mapping protocol,
inheriting ``. This patch implements the
__iter__() and __len__() methods so as to let ``
implement __contains__(), keys(), items(), values(), get(), __eq__(),
and __ne__(). Now you can do, for example:

    if 'next_prio' in event:

__iter__() keeps a set of yielded field names so as to avoid repeating
field names.

__len__() simply reuses __iter__().

`` is updated to test the new features.

Signed-off-by: Philippe Proulx <>
Change-Id: I2485e0df2373005fada0d0732c6269acbce5457c
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
6 weeks agoFix: bt2: _EventConst.__getitem__(): check if event has a packet
Philippe Proulx [Tue, 7 Apr 2020 13:41:55 +0000 (09:41 -0400)] 
Fix: bt2: _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 <>
7 weeks agobt2: honor build system compiler/linker preferences
Jérémie Galarneau [Wed, 1 Apr 2020 14:55:04 +0000 (10:55 -0400)] 
bt2: honor build system compiler/linker preferences

This is an attempt to fix the dreaded "compiling the Python native
module with a custom compiler or compiler-specific flag" problem.

The problem may arise when building with a CC different than what the
Python interpreter was compiled with.  It can manifests itself in two
different ways, as far as I know.  But in both cases, it's due to us
overriding the compiler and compiler flags when invoking to
build the native modules, and how distutils invokes the compiler and
linker to build the native modules.

Scenario 1

Things fail when trying to compile with a compiler other than what
Python has been compiled with, and using in `CFLAGS` a compiler flag
unknown to the compiler Python has been compiled with.

For example, on Ubuntu 18.04, we get this when building with CC=clang
(the -Wtautological-constant-out-of-range-compare is a clang-specific
warning flag currently specified in

    x86_64-linux-gnu-gcc ... -Wtautological-constant-out-of-range-compare ... -o build/build_lib/bt2/
    x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-Wtautological-constant-out-of-range-compare’
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

This is due to the fact that:

- The default link command used by distutils to link shared objects uses
  its default compiler driver (gcc on Linux)
- It passes `CFLAGS` to the linker

Because of this, we end up passing a clang-specific warning flag to gcc,
which proceeds to error out.

To fix this, I have considered setting the LDSHARED variable to
override the command used for linking shared objects.  If the compiler
driver used to drive the linking is the same as the compiler driver used
for compiling, it should understand all the passed flags.

However, it is not obvious to do this right, especially, considering the
various platforms.  But most importantly, it is doesn't help with the
next scenario.

Scenario 2

On Arch Linux (and presumably on Fedora too [1]), the flags passed by
distutils to the compiler contain `-fno-semantic-interposition`, which
is a gcc-specific flag.  When building with CC=clang, we therefore get
this when compiling:

    building 'bt2._native_bt' extension
    clang ... -fno-semantic-interposition ... -c bt2/native_bt.c -o build/temp.linux-x86_64-3.8/bt2/native_bt.o
    clang-9: error: unknown argument: '-fno-semantic-interposition'

clang errors out, because it gets passed a gcc-specific flag.


The fix

Two important distutils configuration variables are at play in this
  - LDSHARED: defines a command to link a build target
  - CFLAGS: contains the compiler flags used to build the python

The configuration variables are changed on access by overriding
distutils' get_config_vars().

In the case of `LDSHARED`, distutils allows it to be specified as an
environment variable which would probably be cleaner (if it actually
works, I haven't tested). distutils seems to honor the environment
`CC` _sometimes_ (depending on whether or not it has performed the
`customize_compiler` step?)

The override always uses the environment `CC` and completely foregoes
the `LDSHARED` configuration variable if `LDFLAGS` are provided. If no
`LDFLAGS` are specified, the compiler is replaced in the LDSHARED

Unfortunately, the CFLAGS environment variable is only appended to
the Python interpreter's build-time CFLAGS, which doesn't solve our
problem. get_cflags() completely overrides the CFLAGS configuration
variable to use babeltrace's build system-specified CFLAGS.


I can't think of a scenario where this doesn't work, but I'm afraid
this will break in non-trivial build environments.

Signed-off-by: Jérémie Galarneau <>
Change-Id: If3142ddb228758e63a986e735cb8f9d89dd39b67
Tested-by: jenkins <>
2 months agoconfigure: enable -Wsuggest-attribute=format
Simon Marchi [Mon, 16 Mar 2020 22:38:45 +0000 (18:38 -0400)] 
configure: enable -Wsuggest-attribute=format

The -Wsuggest-attribute=format warning makes the compiler suggest places
where __attribute__((format(...))) would likely be useful.  This patch
turns it on and adds such attributes everywhere my compiler (GCC 9)
suggested to add them.

In cases where we re-use the same format string multiple times, like:

    const char *const msg = "Hello %d\n";

    BT_LOGE(msg, some_value);

... my compiler (gcc (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130)
complains that the format string is not a literal, even though the `msg`
variable is const and assigned a literal.  I've replaced these with a

Change-Id: I40dd2e70649ec2b651e0109097c217ca9557ad69
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
2 months agoconfigure: simplify warning flags detection
Simon Marchi [Tue, 18 Feb 2020 18:14:22 +0000 (13:14 -0500)] 
configure: simplify warning flags detection

We currently use the AX_COMPILER_FLAGS macro to detect the warning flags
that the current compiler supports.  It works, but is quite invasive.
It unconditionally enables a bunch of warnings we don't want, which
forces us to disable them with many -Wno-foo switches.

Instead of using AX_COMPILER_FLAGS, we can use the slightly lower lever
macro AX_APPEND_COMPILE_FLAGS to achieve our goal of detecting which
warning flags are supported.  This is what we ended up using in
lttng-tools (a completely unrelated project, but that has a suspiciously
high ratio of contributors in common with Babeltrace).

I looked in our git history to see which warning flags were mentioned in
commit messages.  I have added the flags that did find actual problems
and are not enabled by default to the AX_APPEND_COMPILE_FLAGS invocation.
I have also added the flags that AX_COMPILER_FLAGS did provide, which we
didn't need to disable.

The --{enable,disable}-Werror flag is added using an explicit
AC_ARG_ENABLE.  In lttng-tools, it was decided to _not_ have -Werror by
default, so I suggest we do the same in Babeltrace, for consistency
(although it saddens me very much).  Developers who want to build with
-Werror will need to pass --enable-Werror.

Note that with this patch, we lose the following configure switch, that
is provided by AX_COMPILER_FLAGS:


Change-Id: If968f7385a7f5c48d27f402c76bc26241a8f505a
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Michael Jeanson <>
2 months agosink.text.details: remove LOG_WRONG_PARAM_TYPE
Simon Marchi [Thu, 12 Mar 2020 15:09:48 +0000 (11:09 -0400)] 
sink.text.details: remove LOG_WRONG_PARAM_TYPE

It is unused since we have added the more sophisticated parameter
validation utility.

Change-Id: I7ed57026903fd891f2118b6c6bd03841e07f5954
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
2 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

2 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

2 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 <>
2 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 <>
2 months agosink.text.pretty: remove error checks for bt_field_borrow_class_const results
Simon Marchi [Mon, 2 Mar 2020 19:18:30 +0000 (14:18 -0500)] 
sink.text.pretty: remove error checks for bt_field_borrow_class_const results

bt_field_borrow_class_const can't fail, so these error checks are
unnecessary.  Removing them reveals that some of these variables were in
fact unused, so remove them.

Change-Id: I57867e0eb01db3bd7c73dfedc9d1772cbfad02d5
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Philippe Proulx <>
2 months agopy-common: clean-up: unreachable error handling code
Jérémie Galarneau [Fri, 28 Feb 2020 23:54:55 +0000 (18:54 -0500)] 
py-common: clean-up: unreachable error handling code

Both `bt_py_common_format_exception()` and `bt_py_common_format_tb()`
use the same error handling pattern of defining an `error` label and
free-ing `msg_buf` if it has been created before jumping there.

In both cases, the creation of `msg_buf` is the last operation that
can fail, which makes the check, and clean-up, unrechable.

From Coverity's report:
1408326 Logically dead code

The indicated dead code may have performed some action; that action
will never occur.

In bt_py_common_format_tb: Code can never be reached because of a
logical contradiction (CWE-561)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <>
Change-Id: I81b5a2db2cefe1fe08e25819bfa2d8e0fd78ee82
Reviewed-by: Simon Marchi <>
Tested-by: jenkins <>
2 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 <>
2 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 <>
2 months agoconfigure: Add flags as hints when option is disabled
Geneviève Bastien [Wed, 26 Feb 2020 20:48:34 +0000 (15:48 -0500)] 
configure: Add flags as hints when option is disabled

This helps user discover the options after running ./configure, to see
how to enable more options, without having to read the documentation

Change-Id: I5684c14c7eec8f7dc37f3eb8493ea821e18a8365
Signed-off-by: Geneviève Bastien <>
CI-Build: Simon Marchi <>
Tested-by: jenkins <>
Reviewed-by: Simon Marchi <>
2 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 <>
2 months agotests: fix shellcheck warnings in cli/convert/test_auto_source_discovery_{log_level...
Simon Marchi [Tue, 25 Feb 2020 20:08:24 +0000 (15:08 -0500)] 
tests: fix shellcheck warnings in cli/convert/test_auto_source_discovery_{log_level,params}

shellcheck complains:

    In test_auto_source_discovery_params line 42:
    print_test_params="--params what=\"test-params\""
                       ^---------------------------^ SC2089: Quotes/backslashes will be treated literally. Use an array.

    In test_auto_source_discovery_params line 68:
     "${dir_ab}" --params 'test-allo="madame"' ${print_test_params} \
                                                      ^------------------^ SC2090: Quotes/backslashes in this variable will not be respected.
                                                      ^------------------^ SC2086: Double quote to prevent globbing and word splitting.

    Did you mean:
     "${dir_ab}" --params 'test-allo="madame"' "${print_test_params}" \

It would be cleaner to make it print_test_params an array, like we do
for details_sink.

Consistently double-quotes references to print_test_params and
details_sink to avoid the "word splitting" warnings.

Change-Id: I6b18effc29f3c453949b4c181e528e2a60cea4e4
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in cli/convert/test_convert_args
Simon Marchi [Tue, 25 Feb 2020 20:05:21 +0000 (15:05 -0500)] 
tests: fix shellcheck warnings in cli/convert/test_convert_args


    In test_convert_args line 98:
    test_bt_convert_run_args 'path non-option arg + user source named `auto-disc-source-ctf-fs`' "--component $path_to_trace" "--component --component auto-disc-source-ctf-fs-0:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect auto-disc-source-ctf-fs-0:muxer --connect muxer:pretty"
                             ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

    In test_convert_args line 99:
    test_bt_convert_run_args 'path non-option arg + user sink named `pretty`' "--component $path_to_trace" "--component --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
                             ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

    In test_convert_args line 100:
    test_bt_convert_run_args 'path non-option arg + user filter named `muxer`' "--component $path_to_trace" "--component --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer-0:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer-0 --connect muxer-0:muxer --connect muxer:pretty"
                             ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

    In test_convert_args line 101:
    test_bt_convert_run_args 'path non-option arg + --begin + user filter named `trimmer`' "$path_to_trace --component --begin=abc" "--component --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component trimmer-0:filter.utils.trimmer --params 'begin=\"abc\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:trimmer-0 --connect trimmer-0:trimmer --connect trimmer:pretty"
                             ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

Because we have backticks in single quotes, like:

  'hello `you`'

shellcheck thinks that we want to execute the command "you".  So it
warns us that this is not going to happen, given that it is between
single quotes.  This is fine though, as we actually want a string with
backticks in it.

Circumvent it by using double quotes, but escaping the backticks.

Change-Id: Iead2f7842463167969d52f9324b3954896b87686
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: add expected error strings cli/convert/test_convert_args
Simon Marchi [Tue, 25 Feb 2020 21:37:14 +0000 (16:37 -0500)] 
tests: add expected error strings cli/convert/test_convert_args

It looks like this test was meant to optionally check the error strings,
the in the "failure" test cases, but it's not used at the moment.  This
patch adds an error string to check for each use of

Change-Id: I253743fdd174be5ba09c0b07f4fd1bc4dbf767da
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 months agotests: cleanup cli/convert/test_convert_args
Simon Marchi [Tue, 25 Feb 2020 19:55:34 +0000 (14:55 -0500)] 
tests: cleanup cli/convert/test_convert_args

A few cleanups:

- Use bt_cli instead of running the babeltrace binary by hand.
- Give a base name to the temporary files.
- Split CLI arguments into an array before passing them to bt_cli (this
  avoids a shellcheck warning).

bt_cli prints the executed command line, so it becomes unnecessary to
print it manually in this test, which allows simplifying things a bit.

Change-Id: I043099b460ba4ab428beb305de4fe0ad51c20de7
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 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 <>
2 months agotests: fix shellcheck warnings in plugins/sink.ctf.fs/succeed/test_succeed
Simon Marchi [Tue, 25 Feb 2020 19:33:53 +0000 (14:33 -0500)] 
tests: fix shellcheck warnings in plugins/sink.ctf.fs/succeed/test_succeed


    In test_succeed line 44:
    local temp_out_trace_dir="$(mktemp -d)"
  ^----------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 73:
    local temp_gen_trace_dir="$(mktemp -d)"
  ^----------------^ SC2155: Declare and assign separately to avoid masking return values.

Change-Id: I1d7d419d8a11458200d6bf97b1558c8183315dce
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warning in plugins/src.ctf.lttng-live/test_live
Simon Marchi [Tue, 25 Feb 2020 19:29:28 +0000 (14:29 -0500)] 
tests: fix shellcheck warning in plugins/src.ctf.lttng-live/test_live

shellcheck says:

    In test_live line 143:
            if ! "$BT_TESTS_BT2_BIN" $cli_args 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then
                                     ^-------^ SC2086: Double quote to prevent globbing and word splitting.

    Did you mean:
            if ! "$BT_TESTS_BT2_BIN" "$cli_args" 1>"$cli_stdout_file" 2>"$cli_stderr_file"; then

In this case, we do want to pass the $cli_args string as multiple
arguments, so we don't want to just double-quote it.  Circumvent the
warning by splitting it explicitly into an array, then passing the array
using array expansion.  I think this is clearer anyway, as it shows the
intent of splitting the arguments more explicitly than relying in the
implicit splitting done by the shell.

Also, change it to use bt_cli, instead of running the babeltrace binary
by hand.

Change-Id: Idd277fc792e9a426213932566c3c096a53b56d9e
Signed-off-by: Simon Marchi <>
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in plugins/src.ctf.fs/test_deterministic_ordering
Simon Marchi [Tue, 25 Feb 2020 19:10:07 +0000 (14:10 -0500)] 
tests: fix shellcheck warnings in plugins/src.ctf.fs/test_deterministic_ordering

Fix the path to, so that shellcheck finds it.

Change-Id: Ifa592f6e62ccc6df991ffe2ec7afd9c9ea53f136
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in plugins/src.ctf.fs/query/test_query_metadata_info
Simon Marchi [Tue, 25 Feb 2020 19:08:47 +0000 (14:08 -0500)] 
tests: fix shellcheck warnings in plugins/src.ctf.fs/query/test_query_metadata_info


    In test_query_metadata_info line 32:
    ^------------^ SC2034: this_dir_build appears unused. Verify use (or export if used externally).

    In test_query_metadata_info line 41:
    local temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_query_metadata_info line 42:
    local temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

Change-Id: I747d8092bf4625a748afb313b094e6782824c407
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in plugins/src.ctf.fs/succeed/test_succeed
Simon Marchi [Tue, 25 Feb 2020 19:06:14 +0000 (14:06 -0500)] 
tests: fix shellcheck warnings in plugins/src.ctf.fs/succeed/test_succeed

Fix the path to, so that shellcheck finds it.  Then, fix:

    In test_succeed line 69:
            local temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
                  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 70:
            local temp_greped_stdout_output_file="$(mktemp -t greped_stdout.XXXXXX)"
                  ^----------------------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 71:
            local temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
                  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 103:
            local temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)"
                  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 104:
            local temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
                  ^---------------------^ SC2155: Declare and assign separately to avoid masking return values.

Change-Id: Ia67e0726aa898df7a761a3284fdd2919ac2570e8
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in plugins/flt.lttng-utils.debug-info/test_succeed
Simon Marchi [Tue, 25 Feb 2020 19:04:18 +0000 (14:04 -0500)] 
tests: fix shellcheck warnings in plugins/flt.lttng-utils.debug-info/test_succeed

Fix the path to, so that shellcheck finds it.  Then, fix:

    In test_succeed line 38:
    ^------------^ SC2034: this_dir_build appears unused. Verify use (or export if used externally).

    In test_succeed line 70:
            local actual_stdout=$(mktemp -t test_debug_info_stdout_actual.XXXXXX)
                  ^-----------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 71:
            local actual_stderr=$(mktemp -t test_debug_info_stderr_actual.XXXXXX)
                  ^-----------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 72:
            local expected_stdout=$(mktemp -t test_debug_info_stdout_expected.XXXXXX)
                  ^-------------^ SC2155: Declare and assign separately to avoid masking return values.

    In test_succeed line 73:
            local expected_stderr=$(mktemp -t test_debug_info_stderr_expected.XXXXXX)
                  ^-------------^ SC2155: Declare and assign separately to avoid masking return values.

Change-Id: Id9f0d3be21ef215a416946b702f915d98fb539d2
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
2 months agotests: fix shellcheck warnings in plugins/flt.utils.muxer/succeed/test_succeed
Simon Marchi [Tue, 25 Feb 2020 18:55:03 +0000 (13:55 -0500)] 
tests: fix shellcheck warnings in plugins/flt.utils.muxer/succeed/test_succeed

Fix the path to, so that shellcheck finds it.  Then, fix:

    In test_succeed line 70:
            run_test $i
                     ^-- SC2086: Double quote to prevent globbing and word splitting.

    Did you mean:
            run_test "$i"

Change-Id: I76e1fdf5569c5acc487d0b55abcf1d9babd242cd
Signed-off-by: Simon Marchi <>
Reported-by: shellcheck
Tested-by: jenkins <>
3 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 <>
3 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 <>
3 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 <>
3 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 <>
3 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 <>
3 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

3 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

3 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 <>
3 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 <>
3 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 <>
3 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 <>
3 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 <>
3 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

3 months agoUpdate working version to Babeltrace 2.1.0-rc1
Jérémie Galarneau [Tue, 21 Jan 2020 22:16:37 +0000 (17:16 -0500)] 
Update working version to Babeltrace 2.1.0-rc1

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

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

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia868892bd611ff11bba5b01399a78f6cb5c7f6c2
Reviewed-by: Philippe Proulx <>
4 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 <>
4 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 <>
4 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 <>
4 months agoRelease: Babeltrace 2.0.0 "Amqui"
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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months, 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>
4 months 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 <>