babeltrace.git
17 months agoRevert "Fix: lib: add missing BT_ASSERT_PRE_NO_ERROR in trace-ir/clock-class.c"
Simon Marchi [Wed, 17 May 2023 19:41:04 +0000 (15:41 -0400)] 
Revert "Fix: lib: add missing BT_ASSERT_PRE_NO_ERROR in trace-ir/clock-class.c"

This reverts commit bbc5046d02a09977fb1743ad26b7fcedeb888850.

After further discussion, we concluded that the existing behavior
(before the reverted patch) is desirable.  It should only be forbidden
to call an API function while there is a current error for API functions
that can fail and set a current error themselves.

The documentation currently says:

    You cannot call any libbabeltrace2 function when the current thread
    has an error, except the reference counting functions (ending with
    _get_ref() or _put_ref()).

It will later be updated to reflect the fact that it's allowed to call
API functions that can't fail while there is a current error.

Change-Id: Id7d1419862066e0e3d9fd537198b7e630a9c2dc8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10034
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
17 months agolib: remove unneeded forward declarations in trace-ir/field-class.h
Simon Marchi [Tue, 15 Feb 2022 15:47:53 +0000 (10:47 -0500)] 
lib: remove unneeded forward declarations in trace-ir/field-class.h

`struct bt_field` is not used in this file.  `struct bt_field_class` is
not needed, as the struct is defined right there below.

Change-Id: I4f4da1b32fd80eefecc6205febf51e3e0dd5a365
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7318
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7297

17 months agoFix: lib: add missing BT_ASSERT_PRE_NO_ERROR in trace-ir/clock-class.c
Simon Marchi [Mon, 15 May 2023 17:51:08 +0000 (13:51 -0400)] 
Fix: lib: add missing BT_ASSERT_PRE_NO_ERROR in trace-ir/clock-class.c

I spotted some API functions missing BT_ASSERT_PRE_NO_ERROR calls, fix
that.

Change-Id: I3ad30b0d2865afae1ce554ad7e93d03bf8cb3dc8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9995
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
17 months agodebug-info: fix -Wenum-int-mismatch problem in copy_field_class_content_internal
Simon Marchi [Sat, 6 May 2023 02:59:47 +0000 (22:59 -0400)] 
debug-info: fix -Wenum-int-mismatch problem in copy_field_class_content_internal

GCC 13 points out that the return value differs between the declaration
and definition of copy_field_class_content_internal, fix that.

      CC       trace-ir-metadata-field-class-copy.lo
    cc1: warning: command-line option '-Wsuggest-override' is valid for C++/ObjC++ but not for C
    /home/smarchi/src/babeltrace/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c:885:41: error: conflicting types for 'copy_field_class_content_internal' due to enum/integer mismatch; have 'enum debug_info_trace_ir_mapping_status(struct trace_ir_metadata_maps *, const bt_field_class *, bt_field_class *)' [-Werror=enum-int-mismatch]
      885 | enum debug_info_trace_ir_mapping_status copy_field_class_content_internal(
          |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /home/smarchi/src/babeltrace/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c:22:
    /home/smarchi/src/babeltrace/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.h:17:5: note: previous declaration of 'copy_field_class_content_internal' with type 'int(struct trace_ir_metadata_maps *, const bt_field_class *, bt_field_class *)'
       17 | int copy_field_class_content_internal(struct trace_ir_metadata_maps *trace_ir_metadata_maps,
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I9c0dd3ffc3ba1a2e9fbbca948a391357ae28a483
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9986
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 months agoAdd .editorconfig entry for .h and .c files
Simon Marchi [Fri, 5 May 2023 17:44:09 +0000 (13:44 -0400)] 
Add .editorconfig entry for .h and .c files

Change-Id: Ie892477b6d1d42dab969bfb75a5900a71634a50a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9971
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
18 months agotools/format-cpp: run `xargs` with `-P$(nproc)` (format in parallel)
Philippe Proulx [Wed, 3 May 2023 19:28:41 +0000 (15:28 -0400)] 
tools/format-cpp: run `xargs` with `-P$(nproc)` (format in parallel)

This saves many seconds per run.

Note that some implementations of xargs might not accept the `-P`
option, therefore `tools/format-cpp` now requires something like
GNU xargs.

`nproc` is also a GNU (Coreutils) thing.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie7113dae32cff506b716c3b590bbe58eac5f1586
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9950
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
18 months agoChange required clang-format version to 15
Philippe Proulx [Tue, 2 May 2023 18:35:26 +0000 (14:35 -0400)] 
Change required clang-format version to 15

No changes between clang-format 14 and 15 when running
`tools/format-cpp`.

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

18 months agoconfigure: add --enable-ubsan configure flag
Simon Marchi [Mon, 3 Apr 2023 00:44:57 +0000 (20:44 -0400)] 
configure: add --enable-ubsan configure flag

Just like we have --enable-asan.

Change-Id: I9fb5a625ba366e41d7055fa06c0b2870f5dbdbee
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9729
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 months agofix: document proper Bison version requirement
Michael Jeanson [Wed, 5 Apr 2023 14:40:31 +0000 (10:40 -0400)] 
fix: document proper Bison version requirement

The minimum version of Bison was bumped to 2.5 a while ago, update the
documentation and help messages that still refer to 2.4.

Change-Id: I3daef3eb51f24ff0194c43e3e13575eaa6de4f56
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9734
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 months agofix: pass exec-prefix to python bindings install
Michael Jeanson [Wed, 22 Mar 2023 21:57:09 +0000 (17:57 -0400)] 
fix: pass exec-prefix to python bindings install

Some systems will split the arch independent files from the arch
specific using a different value for 'prefix' and 'exec-prefix'. Pass
this information from the Makefile to the python build system.

Change-Id: I2f26ba1d8c8252e5a1c49fb54733e02ae336f157
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9695
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 months agobabeltrace2-query(1): erroneous parameter used in example
Jérémie Galarneau [Tue, 25 Apr 2023 19:14:59 +0000 (15:14 -0400)] 
babeltrace2-query(1): erroneous parameter used in example

The src.ctf.fs component class expects the `inputs` parameter (an array
of strings) rather than `path` (a string).

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id716d68cbb289fe7b52f10c22ed6bc5c9914e2e4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9867
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 months agocli: use return value of g_string_free
Simon Marchi [Mon, 3 Apr 2023 01:09:56 +0000 (21:09 -0400)] 
cli: use return value of g_string_free

When building against glib 2.76, I see:

      CC       babeltrace2-cfg-cli-args.o
    In file included from /usr/include/glib-2.0/glib/giochannel.h:36,
                     from /usr/include/glib-2.0/glib.h:56,
                     from /home/simark/src/babeltrace/src/common/assert.h:12,
                     from /home/simark/src/babeltrace/src/logging/log.h:27,
                     from /home/simark/src/babeltrace/src/cli/logging.h:11,
                     from /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:10:
    /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c: In function ‘plugin_comp_cls_names’:
    /usr/include/glib-2.0/glib/gstring.h:72:5: error: ignoring return value of ‘g_string_free_and_steal’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
       68 |   (__builtin_constant_p (free_segment) ?        \
          |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       69 |     ((free_segment) ?                           \
          |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       70 |       (g_string_free) ((str), (free_segment)) : \
          |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       71 |       g_string_free_and_steal (str))            \
          |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       72 |     :                                           \
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       73 |     (g_string_free) ((str), (free_segment)))
          |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/simark/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:136:25: note: in expansion of macro ‘g_string_free’
      136 |                         g_string_free(gs_name, FALSE);
          |                         ^~~~~~~~~~~~~

glib made g_string_free warn about unused results in this commit:

  https://gitlab.gnome.org/GNOME/glib/-/commit/c3d07a625a407b56432f4b8c60295fd32ee1ee2b

Fix that by changing our code to get the released value from the return
value of g_string_free, rather than doing it in two steps..  No
functional changes intended.

Change-Id: I62f4002d0487165b7c9d33f471937185f3bc0f82
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9728
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 months agoFix: mark (again) section start/end symbols as hidden
Simon Marchi [Fri, 31 Mar 2023 15:47:33 +0000 (11:47 -0400)] 
Fix: mark (again) section start/end symbols as hidden

Commit 1353b066072e ("Visibility hidden by default") broke the plugin
loading on RHEL 7 (and probably other Linux systems with an older
linker).  The ld version on RHEL 7 is 2.27-44.base.el7_9.1.

The symptom is that plugins aren't loaded:

    $ ./src/cli/babeltrace2 list-plugins
    From the following plugin paths:

      - /home/mjeanson/Git/babeltrace/src/plugins/ctf
      - /home/mjeanson/Git/babeltrace/src/plugins/text
      - /home/mjeanson/Git/babeltrace/src/plugins/utils
      - /home/mjeanson/Git/babeltrace/src/plugins/lttng-utils

    No plugins found.

While debugging, I found this strange behavior that I am unable to
explain:

    (gdb) frame
    #0  __bt_get_begin_section_plugin_descriptors () at /home/mjeanson/Git/babeltrace/src/plugins/ctf/plugin.cpp:16
    16 BT_PLUGIN_MODULE();
    (gdb) disassemble
    Dump of assembler code for function __bt_get_begin_section_plugin_descriptors():
       0x00007ffff57b0045 <+0>: push   %rbp
       0x00007ffff57b0046 <+1>: mov    %rsp,%rbp
    => 0x00007ffff57b0049 <+4>: mov    0x2b8f68(%rip),%rax        # 0x7ffff5a68fb8
       0x00007ffff57b0050 <+11>: pop    %rbp
       0x00007ffff57b0051 <+12>: retq
    End of assembler dump.
    (gdb) si
    0x00007ffff57b0050 16 BT_PLUGIN_MODULE();
    (gdb) p/x $rax
    $2 = 0x7ffff7bc6dd0

We are in the function that is supposed to return the beginning of the
__bt_plugin_descriptor section for the babeltrace-plugin-ctf.so shared
object (the address of the __start___bt_plugin_descriptor symbol).  The
address displayed by the disassembler (0x7ffff5a68fb8) appears correct.
It is the sum of 0x2b8f68 and the (next instruction's) PC,
0x7ffff57b0050.  However, after stepping, we see that rax contains a
different value, 0x7ffff7bc6dd0.  I do not understand how it's possible
for this instruction to give that result.  But this address
(0x7ffff7bc6dd0) is the beginning of the __bt_plugin_descriptor section
of libbabeltrace2.so.  So, the symbol from libbabeltrace2.so seems to
hide the symbol of the same name in babeltrace-plugin-ctf.so.  The
function that is supposed to return the start of the plugin descriptor
section in babeltrace-plugin-ctf.so actually returns the start of that
section but in libbabeltrace2.so.

I checked the properties of the special section start/end symbols, both
on RHEL7 and on a more recent system (Arch), for both before and after
1353b066072e.  Here are the results:

RHEL7 before:  00000000002c9768     0 NOTYPE  LOCAL  DEFAULT   26 __start___bt_plugin_descriptors
RHEL7 after :  00000000002c86c8     0 NOTYPE  GLOBAL DEFAULT   26 __start___bt_plugin_descriptors
Arch  before:  0000000000236a00     0 NOTYPE  GLOBAL HIDDEN    27 __start___bt_plugin_descriptors
Arch  after :  00000000002326c0     0 NOTYPE  GLOBAL PROTECTED   27 __start___bt_plugin_descriptors

On RHEL7 the symbols originally had LOCAL binding, meaning they weren't
used for relocation outside their object.  The
__start___bt_plugin_descriptor symbol from libbabeltrace2.so therefore
didn't override the one in babeltrace-plugin-ctf.so.  Similarly, on
Arch, the symbols had HIDDEN visibility, so they also didn't cross
shared object boundary.

After 1353b066072e, the symbols on RHEL7 were "GLOBAL DEFAULT", meaning
the symbols from libbabeltrace2.so would override the symbols with the
same names in plugin (which are necessarily loaded after the main
library).  On Arch, things kept working because the symbols use the
PROTECTED visibility.  ld started to use PROTECTED visibility at some
point for these special section start/end symbols, because it makes no
sense to make them overridable (which they are with the DEFAULT
visibility).  The code in a given file always wants to refer to the
section start/end symbols of its own file.

Note that starting with ld 2.35, we can use the "-z
start-stop-visibility" option to control the visibility of those
symbols.  In some way, it is the linker equivalent of
-fvisibility=hidden for the compiler (just for these start/stop
symbols).  But it doesn't help us for these older systems.

Here are the relevant changes I found in the ld history:

 * This commit (included in binutils 2.29) made the symbols hidden:

   Always define referenced __start_SECNAME/__stop_SECNAME
   https://inbox.sourceware.org/binutils/20170610224649.GA12339@gmail.com/
   https://gitlab.com/gnutools/binutils-gdb/-/commit/cbd0eecf261c2447781f8c89b0d955ee66fae7e9

 * This commit (included in binutils 2.29.1 and binutils 2.30) made the
   symbols protected, after people complained they couldn't look them
   up:

   Make __start/__stop symbols protected visibility
   https://inbox.sourceware.org/binutils/CAMe9rOq5vJzAw0-Quy-J_-UZH9tpoxa4jXWdks255nuFoph7zA@mail.gmail.com/
   https://gitlab.com/gnutools/binutils-gdb/-/commit/487b6440dad57440939fab7afdd84a218b612796

 * This commit (included in binutils 2.35) added the option to control
   the visibility:

   gold, ld: Implement -z start-stop-visibility=... option.
   https://inbox.sourceware.org/binutils/CAB=4xhqb63g_b8K_BJiKne8N+X9zRO_0sYZw+0UNTTFTbdV3OA@mail.gmail.com/
   https://gitlab.com/gnutools/binutils-gdb/-/commit/cae64165f47b64898c4f1982d294862cfae89a47

Fix all this by making these symbols explicitly hidden again, as they
were before 1353b066072e.

Change-Id: Iad6c07691bbfdcbd56948cdc7ccd241d3d8311e3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9726
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 months agofix: visibility of bt_plugin_python_create_all_from_file
Michael Jeanson [Thu, 30 Mar 2023 18:07:05 +0000 (14:07 -0400)] 
fix: visibility of bt_plugin_python_create_all_from_file

With glib2 < 2.52, G_MODULE_EXPORT is defined to nothing on platforms
other than Windows instead of __attribute__((visibility("default")))
which results in an hidden symbol and the failure to load the python
plugin provider.

Use our own macro to export this symbol.

Change-Id: I83ac515c573d92e22021759bf23a1a9615bd3e07
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9724
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
19 months agoShow python bindings install output in verbose builds
Michael Jeanson [Wed, 22 Mar 2023 21:34:51 +0000 (17:34 -0400)] 
Show python bindings install output in verbose builds

When running 'make V=1' print the output of the python bindings install
command to help with debugging.

Change-Id: I33ffa5de1ce4d1957877630662615965a6c78b6f
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9694
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
19 months agoVisibility hidden by default
Simon Marchi [Mon, 4 Jul 2022 13:43:27 +0000 (09:43 -0400)] 
Visibility hidden by default

Change the default visibility of functions to be hidden.  Tag the
functions we want exported as "BT_EXPORT", rather than tagging the ones
we want hidden as "BT_HIDDEN".

The benefits of this method are explained here:

  https://gcc.gnu.org/wiki/Visibility

This is the only practical way to avoid some C++ symbols to be
externally visible (for example, the
bt_param_validation_map_value_entry_descr symbol below).

Change configure.ac to add -fvisibility=hidden to CFLAGS and CXXFLAGS,
and -fvisibility-inlines-hidden to CXXFLAGS.  Remove all mentions of
BT_HIDDEN and its definition.  Add BT_EXPORT, and tag all functions
meant to be exported with it.

Using the abidiff tool, I confirmed that there is not change in exported
symbols for these two libraries:

  - ./src/lib/.libs/libbabeltrace2.so
  - ./src/ctf-writer/.libs/libbabeltrace2-ctf-writer.so

In the CTF plugin, some symbols that used to be exported are now hidden.
There are some C++ symbols like:

  [D] 'method bt_param_validation_map_value_entry_descr::bt_param_validation_map_value_entry_descr()'    {_ZN41bt_param_validation_map_value_entry_descrC2Ev, aliases _ZN41bt_param_validation_map_value_entry_descrC1Ev}

And some bison/flex symbols like:

  [D] 'function void bt_yyset_out(FILE*, yyscan_t)'    {_Z12bt_yyset_outP8_IO_FILEPv}

I think this is OK, it is extremely unlikely that anybody is relying on
this, and the plugins do not claim to offer a stable ABI anyway.

In plugins "with id", the following symbol becomes not visible:

  [D] '__bt_plugin_descriptor __bt_plugin_descriptor_lttng_utils' {__bt_plugin_descriptor_lttng_utils}

I think this is OK, this symbol is only referenced internally, its
address is put in the plugin descriptors table.  But its address is
never looked up by an external party.  The equivalent symbol for plugins
without an explicit id (__bt_plugin_descriptor_auto) was already local,
I'm not sure why.

Change-Id: I2dcb41af9bf9ff6aec4f1f950da4bad52707ada9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8543
Tested-by: jenkins <jenkins@lttng.org>
19 months agoFix: tests: print real values in a fixed format
Simon Marchi [Wed, 15 Mar 2023 19:44:02 +0000 (15:44 -0400)] 
Fix: tests: print real values in a fixed format

The cli_params_to_string.to_string function converts float values
(bt2._RealValueConst) to string using the str function.  The format of
that seems to differ across platform.  On a 32-bit powerpcspe platform,
we see this failure in the cli/params/test_params test:

  -{a=10500000.0, b=10500000.0, c=1.05e-05, d=1.05e-05}
  +{a=10500000.0, b=10500000.0, c=1.0499999999999999e-05, d=1.0499999999999999e-05}

Fix that by doing an explicit string conversion for _RealValueConst objects,
with a constant 7 decimal places after the decimal point.  The 7 is chosen so
that the numbers in tests in cli/params/test_params are not truncated.

Change-Id: Ie4fcb8eb422c3d44eeec1201169dc8a995536d4a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9651
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
19 months agoFix: ctf: verify that field class is int before calling ctf_field_class_as_int
Simon Marchi [Mon, 20 Feb 2023 20:40:35 +0000 (15:40 -0500)] 
Fix: ctf: verify that field class is int before calling ctf_field_class_as_int

Some code paths call ctf_field_class_as_int functions before confirming
that the field class is indeed an int (or enum, which is a sub-type of
int).  This causes assertion failures, because these functions assert
that the field class they receive have the right type.

One case can be hit using the invalid-sequence-length-field-class trace,
included with this patch:

    $ /home/smarchi/build/babeltrace/tests/../src/cli/babeltrace2 -c sink.text.details -p with-trace-name=no,with-stream-name=no /home/smarchi/src/babeltrace/tests/data/ctf-traces/fail/invalid-sequence-length-field-class

     (╯°□°)╯︵ ┻━┻  /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta.hpp:355: ctf_field_class_as_int(): Assertion `!fc || (fc->type == CTF_FIELD_CLASS_TYPE_INT || fc->type == CTF_FIELD_CLASS_TYPE_ENUM)` failed.

This particular crash happens here:

    #4  0x00007ffff535de9d in bt_common_assert_failed (file=0x7ffff5374a60 "/home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta.hpp",
        line=355, func=0x7ffff5374a20 "ctf_field_class_as_int",
        assertion=0x7ffff53749a0 "!fc || (fc->type == CTF_FIELD_CLASS_TYPE_INT || fc->type == CTF_FIELD_CLASS_TYPE_ENUM)")
        at /home/smarchi/src/babeltrace/src/common/assert.c:40
    #5  0x00007ffff5271cca in ctf_field_class_as_int (fc=0x603000002b60) at /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta.hpp:355
    #6  0x00007ffff527a54b in validate_target_field_path (target_field_path=0x7fffffffce60, target_fc=0x603000002b60, ctx=0x7fffffffd050)
        at /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:877
    #7  0x00007ffff527bb7f in resolve_sequence_or_variant_field_class (fc=0x607000000950, ctx=0x7fffffffd050)
        at /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:969

In validate_target_field_path, when handing a sequence, we call
ctf_field_class_as_int on target_fc (the length field class) before
confirming it is really an int.  Fix that by moving the call to
ctf_field_class_as_int below that check.

I went around and looked at all the uses of ctf_field_class_as_int, and
fixed some more instances of the same problem.

In some cases, I moved calls to ctf_field_class_as_int after
BT_COMP_LOGT calls.  While not necessary, my thinking is that should the
assert in ctf_field_class_as_int ever fail for these calls, it could be
able to see the output of the BT_COMP_LOGT, before crashing.

Add a test with a sequence whose length specifier is not an integer.

I also wrote an equivalent test for a variant whose selector is not an
enumeration.  It doesn't cause a crash, but I thought it would be a good
test to have anyway, I don't think we exercise that.

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

19 months agodoc: fix uptream -> upstream typos
Simon Marchi [Wed, 24 Aug 2022 15:41:31 +0000 (11:41 -0400)] 
doc: fix uptream -> upstream typos

Change-Id: Ic52f47c1b3fbbeb2db6da260c1d75570ec6542d5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8742
CI-Build: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 months agofix: python: monkey patch the proper sysconfig implementation
Michael Jeanson [Wed, 8 Mar 2023 16:06:37 +0000 (11:06 -0500)] 
fix: python: monkey patch the proper sysconfig implementation

Since we monkey patch sysconfig, use the distutils implementation when
building with distutils and the upstream one when building with
setuptools.

This ensures the properly patched version is used to build the
extension.

Change-Id: I66eb2d02519d585a15721b2bd77007672e895d7a
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9621
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoFix: tests: free message iterator class in test_graph_topo.c
Simon Marchi [Wed, 8 Mar 2023 21:54:25 +0000 (16:54 -0500)] 
Fix: tests: free message iterator class in test_graph_topo.c

In a build with --enable-asan and optimizations (-O2), I see:

    Direct leak of 112 byte(s) in 1 object(s) allocated from:
        #0 0x7fc88d6bf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
        #1 0x7fc88d3b4631 in g_malloc0 (/usr/lib/libglib-2.0.so.0+0x53631)
        #2 0x563fdbbb98c7 in init_test /home/smarchi/src/babeltrace/tests/lib/test_graph_topo.c:330
        #3 0x563fdbbb98c7 in main /home/smarchi/src/babeltrace/tests/lib/test_graph_topo.c:711
        #4 0x7fc88d19d78f  (/usr/lib/libc.so.6+0x2378f)

For some reason, that leak does not show up on a -O0 build.  Anyhow,
call BT_MESSAGE_ITERATOR_CLASS_PUT_REF_AND_RESET, it's the right thing
to do to clean things up.

Change-Id: I875d8961c2eb4915fbc13706b9148151e82e26d8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9626
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agopython: replace distutils with setuptools
Michael Jeanson [Mon, 27 Feb 2023 18:40:08 +0000 (13:40 -0500)] 
python: replace distutils with setuptools

Since 'distutils' will be removed in Python 3.12, use setuptools instead
to build the bindings. Thanks to the python devs that removed the only
facility to build native extensions from the core distribution.

See https://peps.python.org/pep-0632/

Change-Id: Ib515931d2352416bcc92e18be6b5a3981fb3f067
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8846
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agopython: Use standalone 'sysconfig' module
Michael Jeanson [Mon, 27 Feb 2023 18:38:42 +0000 (13:38 -0500)] 
python: Use standalone 'sysconfig' module

Since 'distutils' will be removed in Python 3.12, use the standalone
'sysconfig' module that was introduced in Python 3.2.

See https://peps.python.org/pep-0632/

Change-Id: I7a89516b03af01cb7ca5178c210bef8248c55c26
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9591
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agofix: 1 byte overflow in UuidView
Michael Jeanson [Mon, 27 Feb 2023 22:35:30 +0000 (17:35 -0500)] 
fix: 1 byte overflow in UuidView

The string() method of UuidView allocates a buffer of BT_UUID_STR_LEN
bytes and then calls bt_uuid_to_str() that prints a C string of
BT_UUID_STR_LEN + 1 bytes (including the terminating null byte ('\0'))
which results in a 1 byte overflow.

Directly use an std::string instead of a char array, resize it to
BT_UUID_STR_LEN which implicitly adds the terminating null byte and then
use the data method to write to the underlying C string.

Change-Id: Ifa6f0322c219e28dec78b8680763b3126a1e513a
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9594
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoerror.c: clean-up: remove dead error cause clean-up code
Jérémie Galarneau [Tue, 7 Mar 2023 18:59:39 +0000 (13:59 -0500)] 
error.c: clean-up: remove dead error cause clean-up code

Coverity warns of logically dead code in error.c:
  1506395 Logically dead code
  The indicated dead code may have performed some action; that action will never occur.

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

`cause` is indeed always NULL at the `end` label since it either failed
to be allocated or its ownership was transferred to the `causes` array.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie1c746b9fe6d6202cd6c3baaef39516a5e902471
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9614
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agoctf-writer: avoid using NULL pointer in BT_CTF_TO_COMMON
Simon Marchi [Sat, 18 Feb 2023 03:44:26 +0000 (22:44 -0500)] 
ctf-writer: avoid using NULL pointer in BT_CTF_TO_COMMON

When running the test tests/ctf-writer/test_ctf_writer in a build with
-fsanitize=undefined, I see:

    /home/simark/src/babeltrace/src/ctf-writer/trace.c:1457:9: runtime error: member access within null pointer of type 'struct bt_ctf_trace'
        #0 0x7f8f57e34ab4 in bt_ctf_trace_set_environment_field_integer /home/simark/src/babeltrace/src/ctf-writer/trace.c:1457
        #1 0x563de0f9234a in main /home/simark/src/babeltrace/tests/ctf-writer/ctf_writer.c:1659
        #2 0x7f8f5723c78f  (/usr/lib/libc.so.6+0x2378f)
        #3 0x7f8f5723c849 in __libc_start_main (/usr/lib/libc.so.6+0x23849)
        #4 0x563de0f87834 in _start (/home/simark/build/babeltrace/tests/ctf-writer/.libs/ctf_writer+0x44834)

This happens within the BT_CTF_TO_COMMON macro.  My first attempt was
something like this:

    #define BT_CTF_TO_COMMON(_obj) \
            ({ typeof(_obj) _obj_local = _obj; _obj_local ? &_obj_local->common : NULL; })

However, it gives this warning, which I did not find a way to work
around:

    /home/simark/src/babeltrace/src/ctf-writer/fields.c: In function 'bt_ctf_field_variant_create':
    /home/simark/src/babeltrace/src/ctf-writer/utils.h:17:57: error: declaration of '_obj_local' shadows a previous local [-Werror=shadow]
       17 | #define BT_CTF_TO_COMMON(_obj)          ({ typeof(_obj) _obj_local = _obj; _obj_local ? &_obj_local->common : NULL; })
          |                                                         ^~~~~~~~~~

Since the BT_CTF_FROM_COMMON macro already appears to assume that the
common field is at offset 0, I think we can do the same for
BT_CTF_TO_COMMON, and just cast the pointer directly the other way
around.

Although `_obj` is mentioned twice in the macro definition, one of them
is in the typeof expression.  So, should there be any side-effects in
`_obj`, they will be executed only once.  At least, that's my
understanding from this SO answer:

  https://stackoverflow.com/questions/11504629/side-effects-within-a-typeof-expression

Change-Id: I595fe888ef99daa0f0a4d657aa227c2b52457941
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9587
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agoctf-writer: avoid undefined behavior left shift
Simon Marchi [Sat, 18 Feb 2023 03:13:16 +0000 (22:13 -0500)] 
ctf-writer: avoid undefined behavior left shift

Running the plugins/src.ctf.fs/succeed/test_succeed test in a build with
-fsanitize=undefined, I get a failure:

    # Generating trace 'simple'
    ERROR: "/home/simark/build/babeltrace/tests/plugins/src.ctf.fs/succeed/gen-trace-simple" "/tmp/tmp.QvrLAHYWXw" failed
    not ok 3 - Generated trace 'simple' gives the expected output

This is because of this undefined behavior error:

    $ /home/simark/build/babeltrace/tests/plugins/src.ctf.fs/succeed/gen-trace-simple /tmp/yo
    /home/simark/src/babeltrace/src/ctf-writer/stream.c:483:29: runtime error: shift exponent 64 is too large for 64-bit type 'long long unsigned int'
        #0 0x7feddba0c21d in update_clock_value /home/simark/src/babeltrace/src/ctf-writer/stream.c:483
        #1 0x7feddba0c918 in visit_field_update_clock_value /home/simark/src/babeltrace/src/ctf-writer/stream.c:555
        #2 0x7feddba0cd74 in visit_field_update_clock_value /home/simark/src/babeltrace/src/ctf-writer/stream.c:626
        #3 0x7feddba0ced2 in visit_event_update_clock_value /home/simark/src/babeltrace/src/ctf-writer/stream.c:663
        #4 0x7feddba0e129 in set_packet_context_timestamps /home/simark/src/babeltrace/src/ctf-writer/stream.c:818
        #5 0x7feddba0ebca in auto_populate_packet_context /home/simark/src/babeltrace/src/ctf-writer/stream.c:908
        #6 0x7feddba146aa in bt_ctf_stream_flush /home/simark/src/babeltrace/src/ctf-writer/stream.c:1650
        #7 0x55940807b535 in write_stream /home/simark/src/babeltrace/tests/plugins/src.ctf.fs/succeed/gen-trace-simple.c:109
        #8 0x55940807b75b in main /home/simark/src/babeltrace/tests/plugins/src.ctf.fs/succeed/gen-trace-simple.c:119
        #9 0x7feddae3c78f  (/usr/lib/libc.so.6+0x2378f)
        #10 0x7feddae3c849 in __libc_start_main (/usr/lib/libc.so.6+0x23849)
        #11 0x559408079f74 in _start (/home/simark/build/babeltrace/tests/plugins/src.ctf.fs/succeed/.libs/gen-trace-simple+0x2af74)

Fix that by avoiding the left shift if new_val_size is 64.  If
new_val_size is 64, leave pow2 at 0, which is what I suppose is the
behavior we are relying on.

Change-Id: I8814773e24c53094be5af613664e6ed4b9ef2d82
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9586
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agoctf: avoid using computing offset from nullptr pointer
Simon Marchi [Sat, 18 Feb 2023 02:17:15 +0000 (21:17 -0500)] 
ctf: avoid using computing offset from nullptr pointer

When running the test_trace_collection_message_iterator.py test in a
build with -fsanitize=undefined, I see:

  /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp:1143:30: runtime error: member access within null pointer of type 'struct ctf_node'

This happens when `node_field_class_declarator` is nullptr.  Avoid this
by using `node_field_class_declarator` once we know it's non-nullptr.

Change-Id: I585e5b17af7e1a16a217ef46c0a49fae901dcae8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9513
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agolib: remove one BT_LIB_LOGD from init_error_cause
Simon Marchi [Sun, 22 Jan 2023 19:49:27 +0000 (14:49 -0500)] 
lib: remove one BT_LIB_LOGD from init_error_cause

This BT_LIB_LOGD is problematic when debug logging is enabled.  It
prints a half-constructed bt_error_cause object, which may cause an
assertion failure, as seen here:

    #3  0x00007f6defd91105 in bt_common_abort () at common.c:2111
    #4  0x00007f6defd995c6 in bt_common_field_class_type_string (class_type=<optimized out>) at ../../src/common/common.h:547
    #5  format_field (field=<optimized out>, prefix=<optimized out>, extended=<optimized out>, buf_ch=<optimized out>) at lib-logging.c:366
    #6  handle_conversion_specifier_bt (priv_data=priv_data@entry=0x0, buf_ch=buf_ch@entry=0x7fff0bf60d80, avail_size=<optimized out>, out_fmt_ch=out_fmt_ch@entry=0x7fff0bf60d78, args=args@entry=0x7fff0bf60e40) at lib-logging.c:1401
    #7  0x00007f6defdcddd4 in bt_common_custom_vsnprintf (buf=0x7f6def96a740 "Initialized error cause: addr=0x55c0f6232340, actor-type=COMPONENT, module-name=\"\", partial-msg=\"\", comp-name=\"(null)\"", buf_size=16384, intro=33 '!', handle_specifier=0x7f6defd99320 <handle_conversion_specifier_bt>, priv_data=0x0,
        fmt=<optimized out>, args=0x7fff0bf60e40) at common.c:1728
    #8  0x00007f6defd9c275 in bt_lib_log_v (func=0x7f6defdd0190 <__func__.28> "init_error_cause", file=0x7f6defdcf6b0 "error.c", line=158, lvl=2, tag=0x7f6defdcf6b8 "LIB/ERROR", fmt=0x7f6defdcf6c2 "Initialized error cause: %!+r", args=0x7fff0bf60e40) at lib-logging.c:1491
    #9  0x00007f6defd9c35c in bt_lib_log (func=func@entry=0x7f6defdd0190 <__func__.28> "init_error_cause", file=file@entry=0x7f6defdcf6b0 "error.c", line=line@entry=158, lvl=lvl@entry=2, tag=tag@entry=0x7f6defdcf6b8 "LIB/ERROR", fmt=fmt@entry=0x7f6defdcf6c2 "Initialized error cause: %!+r") at lib-logging.c:1503
    #10 0x00007f6defd928d2 in init_error_cause (cause=cause@entry=0x55c0f6232340, actor_type=actor_type@entry=BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT) at error.c:158
    #11 0x00007f6defd93296 in create_error_cause_component_actor (line_no=102, file_name=0x7f6dedfb7638 "bt2/native_bt_log_and_append_error.h", comp=0x55c0f66f18d0) at error.c:277
    #12 bt_error_append_cause_from_component (error=0x55c0f66f1d10, self_comp=self_comp@entry=0x55c0f66f18d0, file_name=file_name@entry=0x7f6dedfb7638 "bt2/native_bt_log_and_append_error.h", line_no=line_no@entry=102, msg_fmt=msg_fmt@entry=0x7f6dedfb70da "%s", args=args@entry=0x7fff0bf60fa0) at error.c:512

In this specific case, the component class type value passed to
bt_common_component_class_type_string is uninitialized and invalid.

Remove that logging statement.  Each caller already calls BT_LIB_LOGD
again with the fully constructed object, so this BT_LIB_LOGD in
init_error_cause would not bring anything useful anyway.

Change-Id: I8a56142e6a1d70017f1a50f6c93dff623a08f3bf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9585
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
20 months agolib: add null checks before "casting" to "base class"
Simon Marchi [Sun, 22 Jan 2023 19:35:32 +0000 (14:35 -0500)] 
lib: add null checks before "casting" to "base class"

With -fsanitize=undefined, I see:

    /home/simark/src/babeltrace/src/lib/error.c:526:2: runtime error: member access within null pointer of type 'struct bt_error_cause_component_actor'

This is because doing `&cause->base` is undefined behavior if cause is
NULL.  Add NULL checks around these expressions, when cause may be NULL.

Change-Id: Ie11273a24aa17a96bfccf10b121838e48c61984b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9584
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agom4: bump ax_pkg_swig to 15
Simon Marchi [Fri, 24 Feb 2023 03:13:59 +0000 (22:13 -0500)] 
m4: bump ax_pkg_swig to 15

If you happen to install the mingw-w64-x86_64-swig package on mingw64,
instead of just swig (the msys package), the swig lib is:

    $ /mingw64/bin/swig -swiglib
    C:\msys64\mingw64\bin\Lib
    C:/msys64/mingw64/share/swig/4.1.1

rather than:

    $ /usr/bin/swig -swiglib
    /usr/share/swig/4.0.2

The two lines are printed with a \r\n between them, which is not handled
well by the current AX_PKG_SWIG macro.  This results in this in
Makefiles:

    SWIG_LIB = C:\msys64\mingw64\bin\Lib
    C:/msys64/mingw64/share/swig/4.1.1

and these errors at the end of configure:

    config.status:1764: $? = 2
    config.status:1759: cd tests/param-validation       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/GmbY8tiu:351: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1759: cd tests/plugins/src.ctf.fs/succeed       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/Gmg5rHoG:346: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1759: cd tests/plugins/sink.ctf.fs/succeed       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/GmxjJjqn:350: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1759: cd tests/plugins/flt.lttng-utils.debug-info       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/GmA652OJ:370: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1759: cd tests/utils       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/GmzIx4FT:388: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1759: cd tests/utils/tap       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
    /tmp/GmtBtVgx:347: *** missing separator.  Stop.
    config.status:1764: $? = 2
    config.status:1768: error: in `/c/cygwin64/home/Baube/src/babeltrace':
    config.status:1770: error: Something went wrong bootstrapping makefile fragments
        for automatic dependency tracking.  If GNU make was not used, consider
        re-running the configure script with MAKE="gmake" (or whatever is
        necessary).  You can also try re-running configure with the
        '--disable-dependency-tracking' option to at least be able to build
        the package (albeit without support for automatic dependency tracking).
    See `config.log' for more details

It was fixed here:

  https://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=commit;h=1168996c4cbf6d529d90f66bbf6b06e412bc4452

Import the latest version of the file as of today.

Change-Id: I19cdbdcca4fb3bd5a4ba3b54fbf3a29c2f4fc53f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9583
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoport: fix -Wdeprecated-declarations warning about sprintf on macOS clang 14
Michael Jeanson [Mon, 27 Feb 2023 20:16:03 +0000 (15:16 -0500)] 
port: fix -Wdeprecated-declarations warning about sprintf on macOS clang 14

Remove uses of sprintf to fix this warning:

    warning: 'sprintf' is deprecated: This function is provided for
    compatibility reasons only.  Due to security concerns inherent in the
    design of sprintf(3), it is highly recommended that you use snprintf(3)
    instead. [-Wdeprecated-declarations]

Change-Id: I69dff6379623aefcfd60d6ad1ad96b48ae637155
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9592
Tested-by: jenkins <jenkins@lttng.org>
20 months agocli: Rename `logging.c` to `logging.cpp` to force C++ linking
Francis Deslauriers [Thu, 28 Apr 2022 14:15:26 +0000 (10:15 -0400)] 
cli: Rename `logging.c` to `logging.cpp` to force C++ linking

This is to force the linking of the babeltrace2 binary using a C++
linker. This is necessary to support the Babeltrace2 static build
once we start depending on C++ symbols.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ife9967d9362c7648b6ea031f453262a10aa03483
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7954
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9597
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: Simon Marchi <simon.marchi@efficios.com>
20 months agobt2: ignore -Wredundant-decls warning
Simon Marchi [Thu, 23 Feb 2023 19:29:42 +0000 (14:29 -0500)] 
bt2: ignore -Wredundant-decls warning

The ppc builder on the CI, which uses Python 3.11 + gcc 12.2.0, shows
this warning:

    In file included from /usr/include/python3.11/Python.h:91,
                     from bt2/native_bt.c:168:
    /usr/include/python3.11/modsupport.h:37:24: error: redundant redeclaration of ‘_Py_BuildValue_SizeT’ [-Werror=redundant-decls]
       37 | PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
          |                        ^~~~~~~~~~~~~~~~~~~~
    /usr/include/python3.11/modsupport.h:20:41: note: previous declaration of ‘_Py_BuildValue_SizeT’ with type ‘PyObject *(const char *, ...)’ {aka ‘struct _object *(const char *, ...)’}
       20 | #define Py_BuildValue                   _Py_BuildValue_SizeT
          |                                         ^~~~~~~~~~~~~~~~~~~~
    /usr/include/python3.11/modsupport.h:36:24: note: in expansion of macro ‘Py_BuildValue’
       36 | PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
          |                        ^~~~~~~~~~~~~

I tried fixing it by placing some push/ignored/pop diagnostic pragmas in
the SWIG sections %begin and %runtime, which would be around the
Python.h including in the generated native_bt.c file, but it doesn't
silence the warning for some reason.

Ignore the warning for the whole native_bt.c compilation instead.

Change-Id: Idae04fb30af8108ad14647d9b8f85b2d01a568be
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoctf: fix -Wformat-overflow error in ctf-meta-resolve.cpp
Simon Marchi [Thu, 23 Feb 2023 19:19:10 +0000 (14:19 -0500)] 
ctf: fix -Wformat-overflow error in ctf-meta-resolve.cpp

Fix this, seen when building with -O2 with gcc 12.2.1:

      CXX      ctf-meta-resolve.lo
    In file included from ../../../../../src/logging/comp-logging.h:16,
                     from ctf-meta-resolve.cpp:12:
    In function 'int pathstr_to_field_path(const char*, ctf_field_path*, resolve_context*)',
        inlined from 'int resolve_sequence_or_variant_field_class(ctf_field_class*, resolve_context*)' at ctf-meta-resolve.cpp:948:32,
        inlined from 'int resolve_field_class(ctf_field_class*, resolve_context*)' at ctf-meta-resolve.cpp:1026:54:
    ../../../../../src/logging/comp-logging.h:18:41: error: '%s' directive argument is null [-Werror=format-overflow=]
       18 | #define _BT_COMP_LOG_COMP_PREFIX        "[%s] "
    ../../../../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE'
      815 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    ../../../../../src/logging/comp-logging.h:23:42: note: in expansion of macro '_BT_COMP_LOG_COMP_PREFIX'
       23 |         BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \
          |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
    ../../../../../src/logging/comp-logging.h:83:9: note: in expansion of macro 'BT_COMP_LOG'
       83 |         BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__)
          |         ^~~~~~~~~~~
    ctf-meta-resolve.cpp:650:9: note: in expansion of macro 'BT_COMP_LOGD'
      650 |         BT_COMP_LOGD("Found field path: path=\"%s\", field-path=\"%s\"", pathstr,
          |         ^~~~~~~~~~~~

Change-Id: Ib311185359a531f3e14bfbbbe6726aa633ceb3e4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoctf-writer: fix -Wformat-overflow errors in resolve.c
Simon Marchi [Thu, 23 Feb 2023 19:11:38 +0000 (14:11 -0500)] 
ctf-writer: fix -Wformat-overflow errors in resolve.c

Fix these, seen when building with -O2 with gcc 12.2.1:

      CC       resolve.lo
    In file included from logging.h:11,
                     from resolve.c:11:
    In function 'pathstr_to_field_path',
        inlined from 'resolve_sequence_or_variant_type' at resolve.c:1004:22,
        inlined from 'resolve_type' at resolve.c:1105:9:
    resolve.c:667:25: error: '%s' directive argument is null [-Werror=format-overflow=]
      667 |                 BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"",
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE'
      815 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    resolve.c:667:17: note: in expansion of macro 'BT_LOGT'
      667 |                 BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"",
          |                 ^~~~~~~
    resolve.c: In function 'resolve_type':
    resolve.c:667:70: note: format string is defined here
      667 |                 BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"",
          |                                                                      ^~
    In function 'get_field_paths_lca_index',
        inlined from 'validate_target_field_path' at resolve.c:901:15,
        inlined from 'resolve_sequence_or_variant_type' at resolve.c:1026:8,
        inlined from 'resolve_type' at resolve.c:1105:9:
    resolve.c:792:25: error: '%s' directive argument is null [-Werror=format-overflow=]
      792 |                 BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: "
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE'
      815 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    resolve.c:792:17: note: in expansion of macro 'BT_LOGT'
      792 |                 BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: "
          |                 ^~~~~~~
    resolve.c:792:25: error: '%s' directive argument is null [-Werror=format-overflow=]
      792 |                 BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: "
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE'
      815 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    resolve.c:792:17: note: in expansion of macro 'BT_LOGT'
      792 |                 BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: "
          |                 ^~~~~~~

Change-Id: I91608a4e782a4059225986dd974130ccbaf54207
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoFix: ctf-writer: null dereference in bt_ctf_trace_common_add_stream_class
Jérémie Galarneau [Wed, 18 May 2022 15:49:34 +0000 (11:49 -0400)] 
Fix: ctf-writer: null dereference in bt_ctf_trace_common_add_stream_class

gcc 12.1.0 reports that:
In file included from object-pool.h:38,
                 from clock-class.h:11,
                 from trace.c:27:
In function 'bt_ctf_object_set_parent',
    inlined from 'bt_ctf_object_set_parent' at object.h:102:6,
    inlined from 'bt_ctf_trace_common_add_stream_class' at trace.c:1227:3:
object.h:123:26: warning: null pointer dereference [-Wnull-dereference]
  123 |                 if (child->parent) {
      |                     ~~~~~^~~~~~~~
object.h:123:26: warning: null pointer dereference [-Wnull-dereference]

This can indeed happen if bt_ctf_trace_common_add_stream_class is called
with a nil stream class argument. A null check is added in the error
path.

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

2 years agoconfigure: enable -Wshadow-field
Simon Marchi [Thu, 30 Jun 2022 17:29:17 +0000 (13:29 -0400)] 
configure: enable -Wshadow-field

This warning exists in clang and warns about fields in classes shadowing
fields in base classes.  I hit one bug that this warning would have
caught.  I don't think there are many legitimate / useful cases to have
derived and base classes with fields of the same name.

Change-Id: Ifab0bc03bce2b84a4a186fcc98da8b68ef61e771
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8514
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: compat: include common/macros.h in mman.h
Simon Marchi [Fri, 12 Aug 2022 00:56:12 +0000 (20:56 -0400)] 
Fix: compat: include common/macros.h in mman.h

When building on Windows, this mman.h must include common/macros.h to
see the definition of BT_EXTERN_C.  The build works in current master,
but I got some build failures that uncovered this problem which working
on some unrelated changes.

Change-Id: Ia81714d6d278724a0bc1fd20817e675f0167f2a1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8661
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agoSilence -Wunused-but-set-variable error with clang
Simon Marchi [Thu, 4 Aug 2022 18:28:25 +0000 (14:28 -0400)] 
Silence -Wunused-but-set-variable error with clang

When building with clang-15, I get:

      CXX      libctf_parser_la-parser.lo
    parser.cpp:2920:9: error: variable 'yynerrs' set but not used [-Werror,-Wunused-but-set-variable]
        int yynerrs;
            ^

This is because it warns for something like this:

    int n;
    n = 0;
    ++n;

whereas previous versions do not.

This is generated code, so there's not much more we can do other than
silence the warning for the file.

Change-Id: If2cffe9042b743ffe4b4b23f751216f67b58e5fa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8655
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/common/align.h: remove unused macros
Philippe Proulx [Fri, 22 Apr 2022 12:05:18 +0000 (08:05 -0400)] 
src/common/align.h: remove unused macros

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I111b1f94d4627cd370081e9652273ba635057363
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7926
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 years agotests: fix shellcheck warnings in plugins/sink.ctf.fs
Simon Marchi [Tue, 2 Aug 2022 19:40:58 +0000 (15:40 -0400)] 
tests: fix shellcheck warnings in plugins/sink.ctf.fs

Fix:

    In test_stream_names line 43:
            echo "Created CTF trace \`$(cygpath -m ${temp_output_dir})\\trace\`." > "$temp_expected_stdout"
                 ^-- SC2028 (info): echo may not expand escape sequences. Use printf.
                                                   ^----------------^ SC2086 (info): Double quote to prevent globbing and word splitting.

    Did you mean:
            echo "Created CTF trace \`$(cygpath -m "${temp_output_dir}")\\trace\`." > "$temp_expected_stdout"

    In test_assume_single_trace line 41:
            echo "Created CTF trace \`$(cygpath -m ${trace_dir})\`." > "$temp_expected_stdout"
                                                   ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

    Did you mean:
            echo "Created CTF trace \`$(cygpath -m "${trace_dir}")\`." > "$temp_expected_stdout"

Change-Id: I483ce2ba6c35c2ca191bf5ca1352ac97a0a9c157
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8637

2 years agotests: fix shellcheck errors in plugins/sink.text.pretty/test_enum
Simon Marchi [Tue, 2 Aug 2022 19:36:44 +0000 (15:36 -0400)] 
tests: fix shellcheck errors in plugins/sink.text.pretty/test_enum

Fix:

    In test_enum line 22:
    temp_stderr_expected="/dev/null"
    ^------------------^ SC2034 (warning): temp_stderr_expected appears unused. Verify use (or export if used externally).

    In test_enum line 40:
                    "$(cat $expected_file)" "$(cat $actual_file)"
                           ^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
                                                   ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

    Did you mean:
                    "$(cat "$expected_file")" "$(cat "$actual_file")"

    In test_enum line 49:
            local test_text=
                  ^-------^ SC2034 (warning): test_text appears unused. Verify use (or export if used externally).

    In test_enum line 80:
            if (($expected_to_fail)); then
                 ^---------------^ SC2004 (style): $/${} is unnecessary on arithmetic variables.

Change-Id: I1956a395dd8638b5e7ee9d4a91301243a6ad76ee
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8636
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
2 years agotests: use -z / -n to test for string empty / non-empty
Simon Marchi [Tue, 2 Aug 2022 19:21:21 +0000 (15:21 -0400)] 
tests: use -z / -n to test for string empty / non-empty

shellcheck gives many warnings of this kind

    In env.sh.in line 44:
    if [ "x${BT_TESTS_CC_BIN:-}" = "x" ]; then
         ^---------------------^ SC2268 (style): Avoid x-prefix in comparisons as it no longer serves a purpose.

    Did you mean:
    if [ "${BT_TESTS_CC_BIN:-}" = "" ]; then

Fix them by using test's -z and -n switches, which test for empty and
non-empty strings, respectively.  In some cases, we are checking for the
string to have a specific value ( = "x1"), in which case I left the
comparison, but just removed the leading x's.

Change-Id: I3cd841d881916696419d540ed629e685d2edce9d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8635
Tested-by: jenkins <jenkins@lttng.org>
2 years agotests: shorten names of session-rotation trace
Simon Marchi [Mon, 15 Aug 2022 21:50:51 +0000 (17:50 -0400)] 
tests: shorten names of session-rotation trace

Filenames of this trace on the CI are too long for Windows, causing test
failures.  Shorten some directory names to avoid that

Change-Id: I8d936af3efca894d55a94a57e3a3d4d5b0441305
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8694
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
2 years agoFix: autodisc: make sure auto_discover_source_for_input_as_dir_or_file_rec closes dir
Simon Marchi [Wed, 27 Jul 2022 03:31:06 +0000 (23:31 -0400)] 
Fix: autodisc: make sure auto_discover_source_for_input_as_dir_or_file_rec closes dir

The `dir` variable does not get released if the code goes to the `end`
or `error` labels, leaking the GDir.  Move the variable to the function
scope and release it before returning.

Fixes this, found by Valgrind:

    ==2456047== 32,824 (8 direct, 32,816 indirect) bytes in 1 blocks are definitely lost in loss record 36 of 37
    ==2456047==    at 0x4845888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==2456047==    by 0x49A9B19: g_malloc (gmem.c:125)
    ==2456047==    by 0x49BEDD4: UnknownInlinedFun (gstrfuncs.c:424)
    ==2456047==    by 0x49BEDD4: g_memdup2 (gstrfuncs.c:417)
    ==2456047==    by 0x498D0D7: UnknownInlinedFun (gdir.c:117)
    ==2456047==    by 0x498D0D7: g_dir_open (gdir.c:145)
    ==2456047==    by 0x12BE5A: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:613)
    ==2456047==    by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
    ==2456047==    by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
    ==2456047==    by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
    ==2456047==    by 0x12C1B9: auto_discover_source_for_input_as_dir_or_file (autodisc.c:710)
    ==2456047==    by 0x12C2BA: auto_discover_source_components (autodisc.c:753)
    ==2456047==    by 0x1247A6: bt_config_convert_from_args (babeltrace2-cfg-cli-args.c:4270)
    ==2456047==    by 0x1262B7: bt_config_cli_args_create (babeltrace2-cfg-cli-args.c:4951)

Change-Id: I2145d588c80fb47b5f3475a6a68cc67bb683edb6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8612
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoChange required clang-format version to 14
Simon Marchi [Fri, 22 Jul 2022 00:36:08 +0000 (20:36 -0400)] 
Change required clang-format version to 14

Change-Id: Idb1fc10f0d3c60043c0238e5f8c4283d57c6f90f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8601
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: bt2: autodisc: remove thread error while inserting status in map
Simon Marchi [Thu, 30 Jun 2022 14:46:53 +0000 (10:46 -0400)] 
Fix: bt2: autodisc: remove thread error while inserting status in map

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This does not exist.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Performance results I get locally:

Before:

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

After:

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

This is with Babeltrace configured with:

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

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

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

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

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

And after:

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

This is with babeltrace configured with:

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

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

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

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

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

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

Running:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

... when I run:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #1237

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

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

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

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

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

After:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fix this clang-tidy warning:

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

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

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

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

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

Fix this clang-tidy warning:

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

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

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

By doing this change, to simulate an allocation failure:

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

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

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

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

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

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

This assignment of token_type is not used, remove it.

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

Replace the various constructors of bt_param_validation_value_descr with
equivalent static methods.

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

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

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

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

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

The class hierarchy is:

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

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

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

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

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

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

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

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

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

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

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

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

The new creation methods are:

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

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

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

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

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

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

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

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

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

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

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

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

The class hierarchy is:

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

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

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

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

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

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

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

The class hierarchy is:

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

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

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

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

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

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

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

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

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

The new available classes are:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The four new available types are:

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

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

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

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

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

    auto myRange = myRangeSet[3];

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

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

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

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

Those methods can throw a `LibMemoryError` instance.

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

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

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

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

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

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

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

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

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

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

The class hierarchy is:

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

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

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

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

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

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

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

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

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

    bt2::NullValue {}

or

    bt2::ConstNullValue {}

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

    bt2::NullValue {}.shared()

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

    auto myBoolVal = myVal.asBool();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    #include "cpp-common/string_view.hpp"

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

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

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

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

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

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

    #include "cpp-common/optional.hpp"

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

This page took 0.060289 seconds and 4 git commands to generate.