babeltrace.git
8 months agoFix: src/cpp-common/bt2/trace-ir.hpp: use correct variable name
Philippe Proulx [Mon, 9 May 2022 18:12:28 +0000 (14:12 -0400)] 
Fix: src/cpp-common/bt2/trace-ir.hpp: use correct variable name

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic6fec0fbe90b5528a37ef34e67c4789c61fb7ad6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8004
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10788
Tested-by: jenkins <jenkins@lttng.org>
8 months agocpp-common: Expose BorrowedObj::libObjPtr() as public method
Francis Deslauriers [Tue, 26 Apr 2022 15:39:11 +0000 (11:39 -0400)] 
cpp-common: Expose BorrowedObj::libObjPtr() as public method

This will be useful for component class queries that may use bt2::Value
C++ wrappers but must return a `bt_value` at the moment.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iea93caa6b47ce1afeb7977fee26dffdd3f97013e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7948
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10787
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agoFix: field-path.hpp: add missing `shared-obj.hpp` include
Francis Deslauriers [Wed, 16 Mar 2022 15:30:54 +0000 (11:30 -0400)] 
Fix: field-path.hpp: add missing `shared-obj.hpp` include

gcc 9.3 emits the following warning when including the `field-path.hpp`
file by itself:
  ../../../../src/cpp-common/bt2/field-path.hpp:180:5: error: return type ‘using Shared = class bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’ {aka ‘class bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’} is incomplete
    180 |     {
        |     ^
  ../../../../src/cpp-common/bt2/field-path.hpp: In member function ‘void bt2::ConstFieldPath::shared() const’:
  ../../../../src/cpp-common/bt2/field-path.hpp:181:29: error: too many initializers for ‘bt2::ConstFieldPath::Shared’ {aka ‘bt2::internal::SharedObj<bt2::ConstFieldPath, const bt_field_path, bt2::internal::FieldPathRefFuncs>’}
    181 |         return Shared {*this};
        |                             ^

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: If18d48f16eb6ecb5b14e12a9c8314392c3f3698e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7604
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10786
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agoFix: cpp-common: add missing argument to bt_field_class_variant_create call
Simon Marchi [Thu, 17 Mar 2022 19:10:09 +0000 (15:10 -0400)] 
Fix: cpp-common: add missing argument to bt_field_class_variant_create call

Change-Id: I582fb40180e2d34b5890e13ae517566945ec3a15
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7641
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10765
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agoFix: cpp-common: remove unexpected parameter to createStructureFieldClass
Simon Marchi [Thu, 17 Mar 2022 18:54:03 +0000 (14:54 -0400)] 
Fix: cpp-common: remove unexpected parameter to createStructureFieldClass

Change-Id: Ib9e050b109df596f7c7198a80fed6c1cd9c20cea
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7640
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10764
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agoCleanup: cpp-common: typo: clkSnapshot -> fieldPath
Francis Deslauriers [Thu, 17 Mar 2022 02:09:34 +0000 (22:09 -0400)] 
Cleanup: cpp-common: typo: clkSnapshot -> fieldPath

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idf62a2a8d1eb52799c71dee37f08e44af277b15a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7621
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10763
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

8 months agofield-class.hpp: remove redundant template parameters
Francis Deslauriers [Tue, 8 Mar 2022 21:41:24 +0000 (16:41 -0500)] 
field-class.hpp: remove redundant template parameters

C++ Standard excerpt:
  14.6.1 Locally declared names [temp.local]
  Like normal (non-template) classes, class templates have an
  injected-class-name (Clause 9). The injected-class-name can be used
  with or without a template-argument-list. When it is used without a
  template-argument-list, it is equivalent to the injected-class-name
  followed by the template-parameters of the class template enclosed in
  <>. When it is used with a template-argument-list, it refers to the
  specified class template specialization, which could be the current
  specialization or another specialization.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I1c0c104431f7cf57806a66ed1bce964c007f2c47
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7527
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10762
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

8 months agofield-class.hpp: Add CommonVariantWithSelectorFieldClass
Francis Deslauriers [Mon, 7 Mar 2022 22:17:46 +0000 (17:17 -0500)] 
field-class.hpp: Add CommonVariantWithSelectorFieldClass

This is useful to call the `selectorFieldPath()` method without knowing
if the variant field class has a signed or unsigned selector.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib54bfa31d8f818430ec378c7c0e0c9258e20e450
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7511
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10761
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agofield-class.hpp: Add CommonBaseEnumerationFieldClass
Francis Deslauriers [Mon, 7 Mar 2022 21:54:34 +0000 (16:54 -0500)] 
field-class.hpp: Add CommonBaseEnumerationFieldClass

This is useful to call the `size()` method without knowing if the
enumeration field class is of the signed or unsigned type.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I952fc54c015f8548489aab74e85cded23f9841f7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7510
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10760
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

8 months agocpp-common: add `begin()` and `end()` to Variant and Struct FC
Francis Deslauriers [Thu, 10 Feb 2022 22:06:27 +0000 (17:06 -0500)] 
cpp-common: add `begin()` and `end()` to Variant and Struct FC

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic78e9a06ec86b3a1749c1763698408964f34ec27
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7323
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7290
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agocpp-common: template ArrayValueIterator for reuse with other containers
Francis Deslauriers [Tue, 8 Mar 2022 17:16:27 +0000 (12:16 -0500)] 
cpp-common: template ArrayValueIterator for reuse with other containers

This pattern will be reused for Structure and Variant field class.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I8b6521e41dcc2ebdb81b6348de916544176dbf20
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7518
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10759
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agoFix: field-class.cpp: calling _option_fc lib function on VariantFieldClass
Francis Deslauriers [Fri, 4 Mar 2022 19:52:08 +0000 (14:52 -0500)] 
Fix: field-class.cpp: calling _option_fc lib function on VariantFieldClass

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie3bbc05a20368b8b1388b484ef02da4fb4b68a2d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7497
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10758
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

8 months agofield-class.hpp: add missing #include
Francis Deslauriers [Fri, 4 Mar 2022 15:08:18 +0000 (10:08 -0500)] 
field-class.hpp: add missing #include

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I5dedb44d393fe318253f5912c032ad313fd1c455
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7495
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10757
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agocpp-common: Add `CommonFieldClass::isReal()` method
Francis Deslauriers [Thu, 24 Feb 2022 19:37:29 +0000 (14:37 -0500)] 
cpp-common: Add `CommonFieldClass::isReal()` method

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I420462ccfd78c06d7b496f4650af77cd2d2e57b7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7385
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10756
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agocpp-common: Add hash() and isSame() methods to BorrowedObj
Francis Deslauriers [Tue, 22 Feb 2022 20:43:46 +0000 (15:43 -0500)] 
cpp-common: Add hash() and isSame() methods to BorrowedObj

This will allow us to use the C++ wrapper objects in
`std::unordered_map` by using these methods in custom hasher and isEqual
objects.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I4e018ece9ea4ca755f6612cd9adec408667b202d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7356
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10755
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agosrc/cpp-common: use C-style comments in C++ files
Philippe Proulx [Tue, 1 Mar 2022 16:25:05 +0000 (11:25 -0500)] 
src/cpp-common: use C-style comments in C++ files

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I63b73d110e59f39afc59e83fcf7b59e61db78dbc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7434
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10754
Tested-by: jenkins <jenkins@lttng.org>
8 months agoAdd `bt2::CommonArrayValueIterator` to iterate on `bt2::CommonArrayValue` container
Francis Deslauriers [Tue, 1 Feb 2022 14:05:18 +0000 (09:05 -0500)] 
Add `bt2::CommonArrayValueIterator` to iterate on `bt2::CommonArrayValue` container

This commit implements an array value input iterator and adds `begin()` and
`end()` methods to the `CommonArrayValue` container class.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I2e3c502bd5b11a507fc4643cee27b48b06a6c4a8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7322
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7193
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

8 months agoctf: fix -Wformat-overflow warning in ctf-meta-resolve.cpp
Simon Marchi [Mon, 11 Sep 2023 13:48:14 +0000 (09:48 -0400)] 
ctf: fix -Wformat-overflow warning in ctf-meta-resolve.cpp

Compiling with gcc 13.2.1 (Arch's gcc version as of today) and -O2, I
get:

    libtool: compile:  ccache g++ -std=c++11 -DHAVE_CONFIG_H -I/home/smarchi/src/babeltrace/include -I../../../../../src -I/home/smarchi/src/babeltrace/src -include common/config.h -I. -I/home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata -fvisibility=hidden -fvisibility-inlines-hidden -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -pthread -Wall -Wextra -Wmissing-prototypes -Wmissing-declarations -Wnull-dereference -Wundef -Wredundant-decls -Wshadow -Wjump-misses-init -Wsuggest-attribute=format -Wnested-externs -Wwrite-strings -Wformat=2 -Wstrict-aliasing -Wmissing-noreturn -Winit-self -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wsuggest-override -Wno-unused-parameter -Wno-sign-compare -Wno-cast-function-type -Wno-missing-field-initializers -Wno-maybe-uninitialized -Werror -g3 -O2 -fmax-errors=1 -fdiagnostics-color=always -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28 -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28 -D_GLIBCXX_DEBUG=1 -MT ctf-meta-resolve.lo -MD -MP -MF .deps/ctf-meta-resolve.Tpo -c /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp  -fPIC -DPIC -o .libs/ctf-meta-resolve.o
    In file included from /home/smarchi/src/babeltrace/src/logging/comp-logging.h:16,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:12:
    /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp: In function 'int64_t get_field_paths_lca_index(ctf_field_path*, ctf_field_path*, resolve_context*)':
    /home/smarchi/src/babeltrace/src/logging/comp-logging.h:18:41: error: '%s' directive argument is null [-Werror=format-overflow=]
       18 | #define _BT_COMP_LOG_COMP_PREFIX        "[%s] "
    /home/smarchi/src/babeltrace/src/logging/log.h:807:67: note: in definition of macro 'BT_LOG_WRITE'
      807 |                                                         lvl, tag, __VA_ARGS__); \
          |                                                                   ^~~~~~~~~~~
    /home/smarchi/src/babeltrace/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, \
          |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/babeltrace/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__)
          |         ^~~~~~~~~~~
    /home/smarchi/src/babeltrace/src/plugins/ctf/common/metadata/ctf-meta-resolve.cpp:734:9: note: in expansion of macro 'BT_COMP_LOGD'
      734 |         BT_COMP_LOGD("Finding lowest common ancestor (LCA) between two field paths: "
          |         ^~~~~~~~~~~~

It is undefined what happens when %s receives NULL.  Use the literal
string "(null)" instead of NULL.

Change-Id: I4f53165ff9fc08fb373f7c1cdf87a63f2b792532
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10856
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
8 months agodoc/man: make default values of boolean init. params. clearer
Philippe Proulx [Fri, 1 Sep 2023 18:17:28 +0000 (14:17 -0400)] 
doc/man: make default values of boolean init. params. clearer

This patch answers to <https://bugs.lttng.org/issues/1387>, removing the
"=`yes`" and "=`no`" in the component class manual pages to replace them
with "='VAL'" and indicate the behaviour depending on "'VAL'", as well
as the default value.

Fixes: https://bugs.lttng.org/issues/1387
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie7439fa397e2a9a5818152a68073f7bf87385675
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10709

8 months agobuild: gen-version-i.sh: make it an error if git describe fails
Simon Marchi [Fri, 26 May 2023 16:17:19 +0000 (12:17 -0400)] 
build: gen-version-i.sh: make it an error if git describe fails

When doing `make` as a regular user, building from the git repo, the
src/common/version.i file may contain:

    #define BT_VERSION_GIT "v1.2.0-3717-ga7074326ba9a"

Then, doing `make` as root, when logged in with `su -`, generates a new
version.i with an empty version string:

    #define BT_VERSION_GIT ""

This is because the `git describe --tags --dirty --abbrev=12` command
fails with:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      GEN      version.i
    fatal: detected dubious ownership in repository at '/home/smarchi/src/babeltrace'
    To add an exception for this directory, call:

            git config --global --add safe.directory /home/smarchi/src/babeltrace

By default, git refuses to work on a git repository owned by a different
user.  Note that running a command under sudo doesn't hit this problem,
because git honors the SUDO_UID & co variables.

I think that the current state is buggy, because it results in the
installed library having an empty version string, and it happens almost
silently.  I suggest making it an error if that `git describe` command
fails, since the script can't work correctly in those conditions.  The
user would then need to adjust their setup: either add the directory to
git's safe.directory variable (as the git command suggested) or run the
command under sudo.

Doing "make install" as root not under sudo is one use case, but another
one would be to do the complete build as a regular user from a source
git repository that is owned by another reguar user.  In that case, the
script wouldn't be able to generate a version string in the first
place.  I think that the right thing to do is to error out.  And in that
case, the only solution I see if or the user to use the git
safe.directory variable.

Note that the second git describe command is expected to fail in normal
situations, when it doesn't find an exact tag match, so the `|| true`
there is fine.

Change-Id: I879ddc2184223266829afceca252fe971795f395
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Fixes: https://bugs.lttng.org/issues/1376
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10104
Tested-by: jenkins <jenkins@lttng.org>
8 months agobuild: gen-version-i.sh: use a fixed abbrev length
Simon Marchi [Fri, 26 May 2023 16:17:01 +0000 (12:17 -0400)] 
build: gen-version-i.sh: use a fixed abbrev length

When doing:

 - make
 - sudo make install

... it is possible for the `sudo make install` command to generate a new
src/common/version.i file, if the regular user has a custom value for
the `core.abbrev` git configuration variable.

The version.i file generated by `make` contains a version number with a
hash of a certain length.  Then `sudo make install` generates an
equivalent version number, but with a hash of a different length.  This
then causes some object files that depended on it to be rebuilt, which
is not expected for the install target.

To avoid this, add --abbrev=12 to the git describe command that
genenerates the version string, so that the same hash representation is
generated during both "make" and "sudo make install".

Change-Id: I979d6a9d627f133909dc026e0d2820b52f409d98
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Fixes: https://bugs.lttng.org/issues/1376
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10098
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 months agobuild: gen-version-i.sh: use errexit option
Simon Marchi [Tue, 20 Jun 2023 01:28:12 +0000 (21:28 -0400)] 
build: gen-version-i.sh: use errexit option

Use `set -o errexit` in gen-version-i.sh, so that any unexpected
command failures stops the script.

The first `git describe` command can unexpectedly fail when the script
is ran by a user other than the owner of the git repository (and sudo
wasn't used, so SUDO_UID & co are not set):

    # git describe --tags --dirty
    fatal: detected dubious ownership in repository at '/home/smarchi/src/babeltrace'
    To add an exception for this directory, call:

            git config --global --add safe.directory /home/smarchi/src/babeltrace

For instance, this happens if the git repository is owned by a regular
user, and `make install` is ran in a root shell started with `su`.  Add
`|| true` to that command, to keep the existing behavior (even if
it's not ideal).

Change-Id: Idfbcb3a86158bcddff11a34a18a5d004def37742
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10103
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: use `mv -f`
Simon Marchi [Fri, 26 May 2023 12:50:55 +0000 (08:50 -0400)] 
build: gen-version-i.sh: use `mv -f`

When file src/common/version.i happens to be owned by root (there are
known bugs that causes version.i to be rebuilt when doing `make install`
as root), doing `make` as a regular user gives an interactive prompt:

    make[3]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      GEN      version.i
    mv: replace 'version.i', overriding mode 0644 (rw-r--r--)?

Pass -f to mv to avoid this.

Change-Id: I3ac19cff615fd52db1c025b08c046d34814fb50a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10102
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: use `command` to check if git exists
Simon Marchi [Fri, 26 May 2023 16:14:04 +0000 (12:14 -0400)] 
build: gen-version-i.sh: use `command` to check if git exists

Use the shell builtin `command` to check if git is a valid command,
instead of `which`.

Change-Id: I2e3b4cc178383be1e34dfddbff0794e6fc7ddf86
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10105
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: gen-version-i.sh: make shellcheck-clean
Simon Marchi [Fri, 26 May 2023 12:35:37 +0000 (08:35 -0400)] 
build: gen-version-i.sh: make shellcheck-clean

Fix all the warnings below.

    In src/common/gen-version-i.sh line 27:
    if (test ! -f version.i && test -f "$TOP_SRCDIR/include/version.i"); then
       ^-- SC2233 (style): Remove superfluous (..) around condition to avoid subshell overhead.

    In src/common/gen-version-i.sh line 39:
    if (test -r "$TOP_SRCDIR/bootstrap" && test -r "$TOP_SRCDIR/.git") &&
       ^-- SC2235 (style): Use { ..; } instead of (..) to avoid subshell overhead.

    In src/common/gen-version-i.sh line 40:
     test -x "`which git 2>&1;true`"; then
                             ^-------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     test -x "$(which git 2>&1;true)"; then

    In src/common/gen-version-i.sh line 41:
     GIT_VERSION_STR="`cd "$TOP_SRCDIR" && git describe --tags --dirty`"
                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --tags --dirty)"

    In src/common/gen-version-i.sh line 42:
     GIT_CURRENT_TAG="`cd "$TOP_SRCDIR" && git describe --tags --exact-match --match="v[0-9]*" HEAD || true 2> /dev/null`"
                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                               ^-- SC2015 (info): Note that A && B || C is not if-then-else. C may run when A is true.

    Did you mean:
     GIT_CURRENT_TAG="$(cd "$TOP_SRCDIR" && git describe --tags --exact-match --match="v[0-9]*" HEAD || true 2> /dev/null)"

    In src/common/gen-version-i.sh line 64:
    echo "#define BT_VERSION_EXTRA_NAME \"`$SED -n '1p' "$TOP_SRCDIR/version/extra_version_name" 2> /dev/null`\"" >> version.i.tmp
    ^-- SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects.
                                          ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_NAME \"$($SED -n '1p' "$TOP_SRCDIR/version/extra_version_name" 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 70:
    echo "#define BT_VERSION_EXTRA_DESCRIPTION \"`$SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$TOP_SRCDIR/version/extra_version_description" 2> /dev/null`\"" >> version.i.tmp
                                                 ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_DESCRIPTION \"$($SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$TOP_SRCDIR/version/extra_version_description" 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 80:
    echo "#define BT_VERSION_EXTRA_PATCHES \"`ls -1 "$TOP_SRCDIR/version/extra_patches" | $GREP -v '^README.adoc' | $SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null`\"" >> version.i.tmp
                                             ^-- SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                              ^-- SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames.

    Did you mean:
    echo "#define BT_VERSION_EXTRA_PATCHES \"$(ls -1 "$TOP_SRCDIR/version/extra_patches" | $GREP -v '^README.adoc' | $SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null)\"" >> version.i.tmp

    In src/common/gen-version-i.sh line 87:
     test x"`cat version.i.tmp`" != x"`cat version.i`"; then
                           ^-----------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
                                                     ^-------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

    Did you mean:
     test x"$(cat version.i.tmp)" != x"$(cat version.i)"; then

    For more information:
      https://www.shellcheck.net/wiki/SC2012 -- Use find instead of ls to better ...
      https://www.shellcheck.net/wiki/SC2015 -- Note that A && B || C is not if-t...
      https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...

Change-Id: I519fd427b248bc8f460aa1e5b592aed0ea6858c2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10096
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agobuild: move script to generate version.i to its own file
Simon Marchi [Thu, 25 May 2023 18:36:49 +0000 (14:36 -0400)] 
build: move script to generate version.i to its own file

Move the script from src/common/Makefile.am to its own file.  This will
make it easier to read, modify and lint.

I inlined the big comment from Makefile.am in the new script.  I tried
to keep the code as-is as much as possible, but I needed to tweak a few
things.

 - Replace $(FOO) with $FOO
 - The script expects to get the top srcdir and the grep and sed
   binaries through the TOP_SRCDIR, GREP and SED env var.  GREP and SED
   are optional, to make it easier to run the script by hand

Change-Id: Iaa8948018785e0de4250285110b78ccea1abaedb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10095
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
8 months agoBump minimum supported automake version to 1.13
Erica Bugden [Thu, 10 Aug 2023 20:32:12 +0000 (16:32 -0400)] 
Bump minimum supported automake version to 1.13

since 1.13.4 is the earliest version of automake that we currently build
with regularly in the CI. Build tests are not currently run with 1.12 so
it is risky to claim supporting it.

Change-Id: I353a60f39c9ac8e1d279745b3225d64e40eab4cc
Signed-off-by: Erica Bugden <ebugden@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10586
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agofix: make flake8 6.x happy
Michael Jeanson [Tue, 15 Aug 2023 20:43:03 +0000 (16:43 -0400)] 
fix: make flake8 6.x happy

./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:143:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:151:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:156:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:160:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:164:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./src/bindings/python/bt2/bt2/trace_collection_message_iterator.py:168:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py:33:20: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`

Change-Id: I388dfe9b1c8fa7030a805e6c6e0e487e56947616
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10612
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
8 months agofix: running black on python 3.11
Michael Jeanson [Tue, 15 Aug 2023 18:29:22 +0000 (14:29 -0400)] 
fix: running black on python 3.11

Black 22.0 is incompatible with click >= 8.1 [1], pin it to a working
version.

Traceback (most recent call last):
  File ".pyenv/bin/black", line 8, in <module>
    sys.exit(patched_main())
             ^^^^^^^^^^^^^^
  File ".pyenv/lib/python3.11/site-packages/black/__init__.py", line 6606, in patched_main
    patch_click()
  File ".pyenv/lib/python3.11/site-packages/black/__init__.py", line 6595, in patch_click
    from click import _unicodefun  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name '_unicodefun' from 'click' (.pyenv/lib/python3.11/site-packages/click/__init__.py)

[1] https://github.com/psf/black/issues/2964

Change-Id: I502f10e4cdedae4c431a243fc621fa10ab8bc5cf
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10604
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
9 months agobt_query_executor_create_with_method_data(): fix docs note
Philippe Proulx [Wed, 9 Aug 2023 08:01:01 +0000 (04:01 -0400)] 
bt_query_executor_create_with_method_data(): fix docs note

The bt_graph_add_*_component*() functions accept a `params` parameter,
not the bt_graph_add_*_component_*_port_added_listener() ones.

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

10 months agobuild: correct alignment of "GEN version.i"
Simon Marchi [Thu, 25 May 2023 18:37:55 +0000 (14:37 -0400)] 
build: correct alignment of "GEN version.i"

Before:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      CC       assert.lo
      CC       common.lo
      CC       uuid.lo
      CCLD     libbabeltrace2-common.la
      GEN        version.i

After:

    make[1]: Entering directory '/home/smarchi/build/babeltrace/src/common'
      CC       assert.lo
      CC       common.lo
      CC       uuid.lo
      CCLD     libbabeltrace2-common.la
      GEN      version.i

Change-Id: Ia4968e5209ef1afc83c287797f4d88756fe30b2f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10094
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months ago.gitignore: add missing '/tests/lib/test_fields_bin'
Michael Jeanson [Thu, 15 Jun 2023 19:59:52 +0000 (15:59 -0400)] 
.gitignore: add missing '/tests/lib/test_fields_bin'

Change-Id: Ia77516852a3d4aeca443a7d42b7c2ea4922d0195
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10375
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
11 months agopython: make all _get_ref/_put_ref proper static methods
Simon Marchi [Thu, 8 Jun 2023 14:57:48 +0000 (10:57 -0400)] 
python: make all _get_ref/_put_ref proper static methods

The pyright static type checker doesn't like for these methods in
_SharedObject:

    @staticmethod
    def _get_ref(ptr):
        raise NotImplementedError

    @staticmethod
    def _put_ref(ptr):
        raise NotImplementedError

... to be overriden by assignment like this:

    _get_ref = staticmethod(native_bt.field_class_get_ref)
    _put_ref = staticmethod(native_bt.field_class_put_ref)

The warnings it gives are:

    /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:48:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:49:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

So, it's just the parameter name that it doesn't like.  The obvious
solution would be to rename the `ptr` parameters of
_SharedObject._{get,put}_ref to `field_class`, in _SharedObject, to
match the names in native_bt.py.  However, I don't want us to be tied to
the names in native_bt.py (which originally come from the C header
files), as in Python we often want to use `ptr` in the name to
differentiate the SWIG wrapper around the pointer and the higher-level.
Another solution might be to use SWIG code to rename function parameters
in the SWIG-generated code, but I'm not so well-versed in SWIG, I
couldn't find how to do that.

So, I propose to just use the standard syntax for methods instead, the
type checker seems to be happy with that.

Change-Id: Ife5ad007aea4fb315d3ff4f8da67c48f4bf3e96d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10240
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agopython: mark _SharedObject._{get,put}_ref as abstract methods
Simon Marchi [Thu, 8 Jun 2023 15:21:31 +0000 (11:21 -0400)] 
python: mark _SharedObject._{get,put}_ref as abstract methods

_get_ref and _put_ref must be implemented by any sub-class of
_SharedObject, marking them as abstract methods could help find
mistakes.

Change-Id: I0e161a0bbc1c432d9ed59279d3e4b1b6f6a26215
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10239
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agotests/lib/utils/run-in.cpp: apply BT 2 C++ coding style
Philippe Proulx [Mon, 5 Jun 2023 18:11:41 +0000 (14:11 -0400)] 
tests/lib/utils/run-in.cpp: apply BT 2 C++ coding style

• Separate declarative and other statements.
• Use an anonymous namespace.
• Fix a comment.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic755d5a05b31e8408a69a4443caf0e0823e9fa21
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10201
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: fix formatting of run-in.cpp
Simon Marchi [Thu, 1 Jun 2023 00:59:54 +0000 (20:59 -0400)] 
tests: fix formatting of run-in.cpp

Done by running `tools/format-cpp`.

Change-Id: I6b07f4bc24176e5bd7f4a9f164b0ba3ee4c00fac
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10189
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: add bt_field_string_clear test
Simon Marchi [Wed, 24 May 2023 16:43:49 +0000 (12:43 -0400)] 
tests: add bt_field_string_clear test

Add a test for bt_field_string_clear, exercising the fix done in commit
0022a87819b0 ("Fix: clear_string_field(): set first character to 0").
The test sets the field to a non-empty value, clears it with
bt_field_string_clear, and verifies that the value returned by
bt_field_string_get_value is an empty string, and that the length
returned by bt_field_string_get_length is 0.

When reverting 0022a87819b0, the test gives:

    1..2
    not ok 1 - string field is empty
    #     Failed test (/home/smarchi/src/babeltrace/tests/lib/test_fields.cpp:operator()() at line 36)
    ok 2 - string field length is 0
    # Looks like you failed 1 test of 2.

Change-Id: I46800a93a7290fe72618081efdc5cdcd944c8567
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10068
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: make pre/post-condition assertions test use the run-in framework
Simon Marchi [Tue, 23 May 2023 21:45:45 +0000 (17:45 -0400)] 
tests: make pre/post-condition assertions test use the run-in framework

Change this test to use the new "run-in" framework, instead of
implementing its own "run in component class" util.

Change-Id: If6c84cef632c11fabdbf386a6adabf95e5aac658
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10061
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: add extern "C" to tap.h
Simon Marchi [Wed, 24 May 2023 16:40:15 +0000 (12:40 -0400)] 
tests: add extern "C" to tap.h

This makes it possible to use it from C++ programs.

Change-Id: Ic111f493b0b048b8e491b824af293f0742bda35a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10067
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: add framework to run code in comp cls / comp / msg iter context
Simon Marchi [Tue, 23 May 2023 18:19:42 +0000 (14:19 -0400)] 
tests: add framework to run code in comp cls / comp / msg iter context

Add a little framework to make it easier to write tests that need a
bt_self_component_class, bt_self_component or bt_self_message_iterator.
This is inspired from what we have already in
tests/lib/conds/utils.{hpp,cpp}, but decoupled from the
pre/post-condition assertion tests.  A subsequent commit will change
this test to use the new framework.

The framework exposes the run_in function, which accepts three callbacks
that are executed at three different points in the graph's lifecycle,
providing access to all three contexts.  Each callback may be nullptr.

For convenience, there are also three functions to run code in each
individual context:

 - runInCompClsQuery
 - runInCompClsInitFunc
 - runInMsgIterClsInitFunc

If needed, some additional hook points can be added later, to access
other points of the graph's lifecycle.

The run_in function makes an end-to-end run:

 - creates a graph
 - creates a source component class
 - makes a query on that component class
 - adds a source component
 - adds a dummy sink component, connects the ports of the two components
 - runs the graph

Even for a test that only needs to run code in component class context,
for instance, we still run the whole enchilada.  This is a bit
inefficient, but given that this is just for testing, we don't really
care, as it still runs quick.

Change-Id: Ie532b316dc330758b60fd5f6fe9499f0555f8a8a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10060
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: use nlohmann's json lib to generate conds list
Simon Marchi [Tue, 23 May 2023 19:47:30 +0000 (15:47 -0400)] 
tests: use nlohmann's json lib to generate conds list

Change lib/conds/utils.cpp to use nlohmann to dump the test list in
JSON, rather than dumping it by hand.

Change-Id: I7641a3fcdf118b3787abd76c395c098e1f991717
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10059
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agocpp-common: add nlohmann/json header-only dependency
Francis Deslauriers [Thu, 20 Jan 2022 15:31:33 +0000 (10:31 -0500)] 
cpp-common: add nlohmann/json header-only dependency

This commit adds the C++ nlohmann JSON library which comes from the
MIT-licensed <https://github.com/nlohmann/json/> project [1].

Babeltrace 2 will be using this library to encode JSON strings during
the generation of CTF 2 traces.

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

    #include "cpp-common/nlohmann/json.hpp"

[1] https://raw.githubusercontent.com/nlohmann/json/a0c1318830519eac027a31edec1a99ce1ae5670e/single_include/nlohmann/json.hpp

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I139ea0c0763a129a8d4db351f8ece2edb1c112dd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7321
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7138
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: include babeltrace.h in conds/utils.hpp
Simon Marchi [Tue, 23 May 2023 14:50:54 +0000 (10:50 -0400)] 
tests: include babeltrace.h in conds/utils.hpp

This file uses bt_self_component, so it should include
babeltrace2/babeltrace.h.  In practice, this removes errors when editing
this file in a woke editor.

Change-Id: I72b24b603e878d0773ecc827f73192123e596f05
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10055
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agotests: re-format conds C++ files
Simon Marchi [Tue, 23 May 2023 14:49:37 +0000 (10:49 -0400)] 
tests: re-format conds C++ files

Run tools/format-cpp to format the new C++ files.

Change-Id: Ia919658ed83e8ade0ade02709774caf57b1ee455
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10054
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agotests: convert lib conds test to C++
Simon Marchi [Tue, 23 May 2023 14:40:41 +0000 (10:40 -0400)] 
tests: convert lib conds test to C++

Rename the files from .c/.h to .cpp/.hpp.  Do some minor adjustments so
that it builds.

Change-Id: I4ab79151428ecaf37396e0da891ecd5fa10e19e9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10053
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agotests: add a basic pre-condition assertion test
Simon Marchi [Tue, 23 May 2023 15:44:36 +0000 (11:44 -0400)] 
tests: add a basic pre-condition assertion test

There is currently no "basic" pre-condition assertion test, even though
we have the support for it.  Add one, so that the support code is
exercised.  The new test checks that passing a wrong MIP version to
bt_grbt_graph_create triggers an assertion.

Change-Id: Iddaa7905684e1bda3a731ab215a0e42b5eb62633
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10056
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agotests: remove unused forward declaration
Simon Marchi [Tue, 23 May 2023 14:30:19 +0000 (10:30 -0400)] 
tests: remove unused forward declaration

Change-Id: I4f5a3496e67f0db6f4c850deec58c34ba0df7c77
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10052
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agolib: remove TODO in add_port
Simon Marchi [Wed, 17 May 2023 19:38:27 +0000 (15:38 -0400)] 
lib: remove TODO in add_port

I think that the {input,output}-port-name-is-unique assertions basically
check that this TODO is about.

Change-Id: Ib5029697114f46fd5485d902068ca912b658ebc9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10038
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agolib: de-duplicate assertions in bt_component_add_{input,output}_port
Simon Marchi [Fri, 19 May 2023 21:24:39 +0000 (17:24 -0400)] 
lib: de-duplicate assertions in bt_component_add_{input,output}_port

Move assertions from bt_component_add_input_port and
bt_component_add_output_port to add_port.  Add a parameter to indicate
to add_port if it's adding an input or output port.  This is only used
to select the correct strings for the "no duplicate name" pre-condition
check.  I think this de-duplication helps ensure both the input and
output paths are equivalent.

Change-Id: I217794719231251bf73d0347d6208af9fcaf6a0d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10037
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 months agolib: de-duplicate "no error" assertion in add port functions
Simon Marchi [Wed, 17 May 2023 19:29:38 +0000 (15:29 -0400)] 
lib: de-duplicate "no error" assertion in add port functions

Add BT_ASSERT_PRE_NO_ERROR_FROM_FUNC calls in
bt_component_add_output_port and bt_component_add_input_port, and remove
the equivalent calls in their callers.  This moves the assertion check
next to the other existing assertions.

Change-Id: Ia251510ce2b6ba369cfc1f4afae50e8e46060957
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10036
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
11 months agolib: remove duplicated assertion in bt_self_component_source_add_output_port
Simon Marchi [Wed, 17 May 2023 19:25:41 +0000 (15:25 -0400)] 
lib: remove duplicated assertion in bt_self_component_source_add_output_port

The use of BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE in
bt_self_component_source_add_output_port is not necessary, as
bt_component_add_output_port checks the same thing:

BT_ASSERT_PRE_FROM_FUNC(api_func, "output-port-name-is-unique",
bt_component_port_name_is_unique(component->output_ports, name),
"Output port name is not unique: name=\"%s\", %![comp-]c",
name, component);

Remove this use of BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE, and then
remove BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE itself.  Then, make
bt_component_port_name_is_unique static to component.c, since it's only
used in that file now.

Change-Id: Ia341be570596d798179d1937b40726f829cbebfe
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10035
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
11 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>
12 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

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

12 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>
12 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>
12 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>
12 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>
13 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>
13 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>
13 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>
13 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>
13 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>
14 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>
14 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>

14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
14 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>
17 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

20 months 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>
20 months 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>
20 months 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>
20 months 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>
21 months 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

21 months 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>
21 months 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>
21 months 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>
21 months 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>
21 months 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>
22 months agoFix: bt2: autodisc: remove thread error while inserting status in map
Simon Marchi [Thu, 30 Jun 2022 14:46:53 +0000 (10:46 -0400)] 
Fix: bt2: autodisc: remove thread error while inserting status in map

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

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

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

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

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

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

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

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

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