lttng-tools.git
19 months agoFix: file-descriptor: missing include guards
Jérémie Galarneau [Wed, 29 Mar 2023 20:18:36 +0000 (16:18 -0400)] 
Fix: file-descriptor: missing include guards

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I05551e67a28e75b353f22e8df9f2ecde8dad5f5b

19 months agofile-desrcriptor: add assignment operator
Jérémie Galarneau [Wed, 29 Mar 2023 19:13:18 +0000 (15:13 -0400)] 
file-desrcriptor: add assignment operator

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I65ec468e0825801db47da6b1298d0bc09028415d

19 months agoFix: file-descriptor: unnecessary assert in move constructor
Jérémie Galarneau [Wed, 29 Mar 2023 17:41:26 +0000 (13:41 -0400)] 
Fix: file-descriptor: unnecessary assert in move constructor

There is no use in checking the current fd in the move constructor. This
is probably a left-over from the inital move assignment operator.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I416d2778784ddea448904118c940914c030bf399

19 months agoDocs: missing period at the end of comment
Jérémie Galarneau [Wed, 29 Mar 2023 17:32:02 +0000 (13:32 -0400)] 
Docs: missing period at the end of comment

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I62fcddcfa57289a2177acd25931fc1962abb206b

19 months agoPython bindings: silence warnings in generated code
Michael Jeanson [Tue, 4 Apr 2023 19:19:29 +0000 (15:19 -0400)] 
Python bindings: silence warnings in generated code

Add -Wnull-dereference to the list of ignored flags for swig generated
code. This triggers on SWIG 3.0.12.

Change-Id: Idf5da19666581ac97f7120520d5dcd03eb00d0a7
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoFix: leftover python inline type hint
Michael Jeanson [Tue, 28 Mar 2023 21:27:29 +0000 (17:27 -0400)] 
Fix: leftover python inline type hint

When rebasing the python 3.4 support patches, a leftover inline type
hint was introduced. Fix it to restore python 3.4 support.

Change-Id: Ieed4f555f757a6ee37285c0317659524ec97bfa8
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoPython bindings: warnings in generated code causes build failure
Jérémie Galarneau [Tue, 28 Mar 2023 18:41:15 +0000 (14:41 -0400)] 
Python bindings: warnings in generated code causes build failure

Swig regularily introduces new warnings in the generated code which
makes it difficult to maintain a buildable tree with -Werror. The option
is disabled for this sub-project.

The warnings that appear in the code generated by the current version of
Swig (4.1.0) are also silenced.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I008de07f67b2ce6ebedcf138de5a68c87d869af2

19 months agoBump minimal python3 version to 3.4
Michael Jeanson [Tue, 28 Mar 2023 14:43:51 +0000 (10:43 -0400)] 
Bump minimal python3 version to 3.4

Change-Id: If1e264d09fccba53d000211681de91d633fbd28f
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoTests: python: use quoted annotations to support python <= 3.6
Michael Jeanson [Mon, 27 Mar 2023 19:25:23 +0000 (15:25 -0400)] 
Tests: python: use quoted annotations to support python <= 3.6

Python 3.0 introduced syntax for parameter and return type annotations,
as specified in PEP 484. Python 3.6 introduced support for variable type
annotations, as specified in PEP 526.

Upstream recommends using quoted annotations for librairies that need to
support older python versions.

See https://typing.readthedocs.io/en/latest/source/libraries.html#compatibility-with-older-python-versions

Change-Id: Ifc6017a7baa9f0589e85d32005ac9ead18c1c9fb
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoTests: python: enum.auto() introduced in python 3.6
Michael Jeanson [Mon, 27 Mar 2023 19:37:24 +0000 (15:37 -0400)] 
Tests: python: enum.auto() introduced in python 3.6

Assign descriptive string values to the enumeration members instead of
using auto() and provide a repr() method that hides the value as
recommended upstream [1].

[1] https://docs.python.org/3.6/library/enum.html#omitting-values

Change-Id: I0bc8fcc19d68342ade1aeb587f07a9b483f81b3e
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 months agoTests: python: path-like object introduced in python 3.6
Michael Jeanson [Mon, 27 Mar 2023 19:25:07 +0000 (15:25 -0400)] 
Tests: python: path-like object introduced in python 3.6

Prior to python 3.6 the builtin open() function expected a string or
bytes object for the pathname. Add a compat method to convert the
path-like object to a string on interpreters that lack PEP-519 [1]
support.

[1] https://peps.python.org/pep-0519/

Change-Id: I23d1da1202e17db621f1fb89f7a79b12694dd4a6
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoFix: truncated len in lttng_event_rule_user_tracepoint_serialize()
Michael Jeanson [Thu, 23 Mar 2023 16:45:18 +0000 (12:45 -0400)] 
Fix: truncated len in lttng_event_rule_user_tracepoint_serialize()

Observed issue
==============

On 64-bit big-endian platforms, the serialization/deserialization tests
of tracepoint event rules fail since the length of individual exclusions
is truncated in lttng_event_rule_user_tracepoint_serialize and appear as
"0" on the receiving end.

Cause
=====

The length of the exclusion name string is stored in a variable of type
`size_t`. However, since the protocol expects it to be expressed as a
uint32_t, the value is added to the payload by copying the first 4 bytes
of the value.

On a 32-bit system this would be fine since `sizeof(size_t) == 4`. Even
worse, it would work most of the time (assuming an exclusion name string
< 4GiB) on a little-endian 64-bit system as the least significant bits
would be copied and correctly express the length of the string.

On a big-endian 64-bit platform, the most-significant 4 bytes are copied
to the payload buffer thus making the string length appear as "0".

Solution
========

A temporary variable is used to hold the "casted" value and make it safe
to copy to the payload buffer regardless of the platform's endianness.

Known drawbacks
===============

None.

Change-Id: I64c03345fff7ffea2f8fcb84692a085da31c421b
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoTests: remove leftover debug printing in test_add_trigger_cli
Michael Jeanson [Wed, 22 Mar 2023 19:08:10 +0000 (15:08 -0400)] 
Tests: remove leftover debug printing in test_add_trigger_cli

Change-Id: Ie5d0cc18ae35ff5848008fae5942d93eac5f2f70
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoFix: invalid syntax with python 3.5 in test_ust.py
Michael Jeanson [Wed, 22 Mar 2023 14:28:14 +0000 (10:28 -0400)] 
Fix: invalid syntax with python 3.5 in test_ust.py

The following error was encountered while running the test suite with
python 3.5 :

  File "./tools/context/test_ust.py", line 99
    client: lttngtest.Controller = lttngtest.LTTngClient(test_env, log=tap.diagnostic)
          ^
  SyntaxError: invalid syntax

Remove the type hint.

Change-Id: I2d8c39d092b8a1659208b89aaca1cf11ca53866a
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoBuild fix: brace-enclosed initlializer lists error with g++ 4.8
Michael Jeanson [Mon, 20 Mar 2023 19:05:04 +0000 (15:05 -0400)] 
Build fix: brace-enclosed initlializer lists error with g++ 4.8

A build error occurs when building using g++ 4.8 :

 In file included from session.hpp:18:0,
                  from lttng-sessiond.hpp:21,
                  from utils.cpp:10:
 ../../../src/common/pthread-lock.hpp: In constructor 'lttng::pthread::details::mutex::mutex(pthread_mutex_t&)':
 ../../../src/common/pthread-lock.hpp:29:61: error: invalid initialization of non-const reference of type 'pthread_mutex_t&' from an rvalue of type '<brace-enclosed initializer list>'
   explicit mutex(pthread_mutex_t& mutex_p) : _mutex{ mutex_p }

Use oldstyle initialization of references instead.

Change-Id: I2fd756b48fd8e70e30199c86527c025117bfb6ff
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoBuild fix: POD static_assert check fails on lttng_event_exclusions
Jérémie Galarneau [Tue, 21 Mar 2023 15:15:19 +0000 (11:15 -0400)] 
Build fix: POD static_assert check fails on lttng_event_exclusions

A build error occurs when building using g++ 6.4.0 on PPC32:

  In file included from ../../src/common/buffer-view.hpp:11:0,
                   from event.cpp:9:
  ../../src/common/macros.hpp: In instantiation of 'AllocatedType* zmalloc(size_t) [with AllocatedType = lttng_event_exclusion; size_t = unsigned int]':
  event.cpp:270:77:   required from here
  ../../src/common/macros.hpp:102:2: error: static assertion failed: type can be malloc'ed
    static_assert(can_malloc<AllocatedType>::value, "type can be malloc'ed");
    ^~~~~~~~~~~~~

A bug affecting gcc [6.1, 7.4] causes flexible array members to generate
a destructor for compound types. In turn, this makes any type that
contains a flexible array a non-POD object which is a problem under some
use-case (e.g., being allocated using C-style memory management
facilities).

Explicitly specifying a length of zero works around this bug, see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70932
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71147

The same bug affects re2 and they have fixed it in a similar way:
https://github.com/google/re2/blob/9049cd28d7496e05e7b7beaec89291d8bc6a31ee/re2/dfa.cc#L123

Change-Id: I730cdeb86bb39cdbfdc5165f854ab5906aeb2192
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
20 months agoport: add missing attributes in getrandom_nonblock() on macOS
Michael Jeanson [Tue, 7 Mar 2023 19:10:00 +0000 (14:10 -0500)] 
port: add missing attributes in getrandom_nonblock() on macOS

Change-Id: I2e4944cf17ba72c75b8c5cfd5ce0d7b806d14b67
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoFix: adding a user space probe fails on thumb functions
Olivier Dion [Wed, 22 Feb 2023 20:19:14 +0000 (15:19 -0500)] 
Fix: adding a user space probe fails on thumb functions

On some architectures, calling convention details are embedded in the
symbol addresses. Uprobe requires a "clean" symbol offset (or at least,
an address where an instruction boundary would be legal) to add
instrumentation. sanitize_uprobe_offset implements that sanitization
logic on a per-architecture basis.

The least significant bit is used when branching to switch to thumb ISA.
However, it's an invalid address for us; mask the least significant bit.

We were not masking the thumb bit, thus using the wrong address offset
by one.

Change-Id: Iaff8ccea3a319f9d9ad80501f1beccd74d1ef56d
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoFix: Tests that assume CPU 0 is present
Olivier Dion [Thu, 16 Feb 2023 20:34:26 +0000 (15:34 -0500)] 
Fix: Tests that assume CPU 0 is present

Add util_event_generator.sh to shellcheck test while at it.

Change-Id: I261452496827a5b9fc08b39a1132b13a39d0a7f5
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoFix: Wrong assumption about possible CPUs
Olivier Dion [Tue, 14 Feb 2023 19:35:34 +0000 (14:35 -0500)] 
Fix: Wrong assumption about possible CPUs

cpuset is not necessary contiguous.  Thus, we need to parse
/sys/devices/system/cpu/posssible correctly.

Also, the `get_exposed_cpus_list' utility functions is required for
taskset-ting on the correct CPUs available to the test environment.

Change-Id: I062ce8d311ff0e8c4b757fe6f36387e3007cfa27
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoport: fix -Wdeprecated-declarations warning about sprintf on macOS clang 14
Michael Jeanson [Tue, 7 Mar 2023 19:16:44 +0000 (14: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: Ifff3746c1cc4e51a8cf4c08ccd845c887d76c6be
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoTests: fix: parse-callback reports missing addr2line
Olivier Dion [Fri, 10 Mar 2023 18:17:46 +0000 (13:17 -0500)] 
Tests: fix: parse-callback reports missing addr2line

addr2line from binutils is required for this script to work correctly.
However, it silently fails. Fix this by using `subprocess.run' with
`check=True' instead of `subprocess.getoutput'. That way, an exception
is raised if an error occurs.

Fix the shebang by not assuming where python is installed while at it.

Change-Id: I5157b3dbccf6bfbe08a6b6840b38f5db9010fe96
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
20 months agoDocs: sessiond: document the role of an application's two sockets
Jérémie Galarneau [Tue, 7 Mar 2023 22:03:27 +0000 (17:03 -0500)] 
Docs: sessiond: document the role of an application's two sockets

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I355588af1b3408c8c209aae09c2897640d4ca5b4

20 months agoClean-up: coding style fix and missing method in lttng::ctl::error
Jérémie Galarneau [Tue, 28 Feb 2023 17:44:55 +0000 (12:44 -0500)] 
Clean-up: coding style fix and missing method in lttng::ctl::error

Methods must not contain get/set for trivial accessors. get_code() is
renamed to code() to follow this guideline.

Moreover, the method was not implemented. It is marked as noexcept and
the _error_code member is made `const` as there is no reason for it to
be mutated.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If0fca5cc91c1cb72fff183ee6d29588ff4b5c030

20 months agoFix: lttng remove-trigger -h fails
Olivier Dion [Wed, 22 Feb 2023 21:45:27 +0000 (16:45 -0500)] 
Fix: lttng remove-trigger -h fails

The error was that `argv' was incremented before passing it to
`argpar_iter_create'. However, the macro `SHOW_HELP' implicitly
deferences `argv[0]' to determine the command name.

Fix this by introducing a new variable `args' leaving `argv' untouched.

Change-Id: Id50fa2424550280a1e5e207429d643f5e8e00396
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoman/README.md: Update asciidoc url to asciidoc.org
Jérémie Galarneau [Wed, 22 Feb 2023 21:57:22 +0000 (16:57 -0500)] 
man/README.md: Update asciidoc url to asciidoc.org

Reported-by: Kamil Beker
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1e68fc6ff6e234eeab126a091b2b713e65697136

21 months agoREADME.adoc: Update asciidoc url to asciidoc.org
Jérémie Galarneau [Wed, 22 Feb 2023 21:56:01 +0000 (16:56 -0500)] 
README.adoc: Update asciidoc url to asciidoc.org

Reported-by: Kamil Beker
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib78323c82e81dbcaa577f3234e7cbbb2d5130086

21 months agocompat: off64_t is not defined by musl
Jérémie Galarneau [Tue, 17 Jan 2023 21:57:35 +0000 (16:57 -0500)] 
compat: off64_t is not defined by musl

This helps compile with latest musl, where off64_t is not defined unless
_LARGEFILE64_SOURCE is defined. On glibc, _LARGEFILE64_SOURCE is defined
if _GNU_SOURCE is defined, so the problem is only seen with musl.

Since the project uses AC_SYS_LARGEFILE, which from the autoconf doc:
"arrange for 64-bit file offsets, known as large-file support."

As such, it is safe to assume off_t is 64-bit wide. This is checked by a
static_assert to catch any platform where autoconf would let a 32-bit
off_t slip.

Reported-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If2c6007a8c85bc3f3065002af8a7538b882fb4a8

21 months agotests: make test_shellcheck depend on shellcheck
Michael Jeanson [Fri, 17 Feb 2023 19:04:31 +0000 (14:04 -0500)] 
tests: make test_shellcheck depend on shellcheck

Since this test is only useful for development, don't fail the build on
platforms that lack shellcheck.

Another approach could be to add a dedicated make target to run the meta
tests but this was easier as a quick fix.

Change-Id: If9d30c7c4e3ee526f028ad82545e631ace272354
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoFix: tests: add shellcheck test to distribution
Michael Jeanson [Thu, 16 Feb 2023 16:37:10 +0000 (11:37 -0500)] 
Fix: tests: add shellcheck test to distribution

Add the shellcheck test to the distribution, also copy it to the build
dir for oot builds and while where are here, rename it with the 'test_'
prefix to match the rest of the test suite.

Change-Id: Iaeff191022d16ea666c2145aa7e907aeebb6c5ff
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoTests: Add meta shellcheck test
Olivier Dion [Mon, 6 Feb 2023 19:21:07 +0000 (14:21 -0500)] 
Tests: Add meta shellcheck test

Pass shellcheck on a list of known correct shell scripts. The idea is to
add scripts to the list incrementally and avoid regressions.

Change-Id: If9b15879cfd4d3c3bdbc6b5fc3efb5638593ca74
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoBuild feature: Add pre-inst-env script
Olivier Dion [Fri, 3 Feb 2023 20:29:53 +0000 (15:29 -0500)] 
Build feature: Add pre-inst-env script

This script setup environment variables for running compiled binaries
from the project without having to install them.

Usage example:

  $ ./pre-inst-env lttng create

Change-Id: Ie7839f32cfdc32103db035e2189b6f8a4c5cabe4
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoTests: snapshot tests complain that nothing is output
Jérémie Galarneau [Mon, 13 Feb 2023 20:43:18 +0000 (15:43 -0500)] 
Tests: snapshot tests complain that nothing is output

The user space snapshot tests invoke a common script that runs the
actual tests. In doing so, the parent script's tap generator isn't
involved in the production of the tests' tap output and outputs an error
message as diagnostic.

  ok 134 - Wait after kill session daemon
  # Looks like your test died before it could output anything.

`exec`-ing the common script sidesteps the problem by replacing the
shell entirely.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I53783fa783eb5581bf41fc1a5504dbd4e14fa595

21 months agoTests: Test snapshot maximum size correctly
Olivier Dion [Wed, 1 Feb 2023 22:11:02 +0000 (17:11 -0500)] 
Tests: Test snapshot maximum size correctly

The minimum size for a channel is determined by:

  sub-buffer-size * sub-buffer-count * possible-cpus

where sub-buffer-size is the system page size and sub-buffer-count is 2.

We set a snapshot with a maximum size of the minimum size. From there,
we need to spam that amount of events, assuming each event to be one
byte, on every online CPUs. We can then ensure that the total snapshot's
size is equal to the minimum size for a channel. However, there's a
little bias if the number of possible cores is greater than the number
of online cores. In that case, the bias is one sub-buffer for each extra
ring buffer.

Change-Id: I4718e134684463789b4f7be9b12c9bf3d6cfec20
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoTests: Add get_possible_cpus_count utility
Olivier Dion [Wed, 1 Feb 2023 21:04:14 +0000 (16:04 -0500)] 
Tests: Add get_possible_cpus_count utility

lttng-ust uses the possible number of CPUs to allocate its ring buffers.
Certain tests have to take that into consideration in their calculation
instead of relying on online processors.

Thus, add the same logic for calculating the possible CPUs on the
system.

Change-Id: I9f14afba3e4adad9547cbd9386f8e1b1b55a3253
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoFix: lttng-disable-event: erroneous error code used in logging
Jérémie Galarneau [Fri, 3 Feb 2023 19:31:39 +0000 (14:31 -0500)] 
Fix: lttng-disable-event: erroneous error code used in logging

66cefebdc introduced `disable_ret` to hold the integral result of
lttng_disable_event_ext() instead of mixing enums and integers.

In doing so, one use site was left unmodified which resulted in the
wrong variable being used to log an error when the command failed.

This was spotted by clang:
  commands/disable_events.cpp:252:21: warning: result of comparison of
  constant -83 with expression of type 'enum   cmd_error_code' is always false [-Wtautological-constant-out-of-range-compare]
                                      command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME ?

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I282ebee0140f7044847aab6c43ba6bd0c185fc46

21 months agoAdd a .git-blame-ignore-revs file
Jérémie Galarneau [Fri, 3 Feb 2023 19:26:24 +0000 (14:26 -0500)] 
Add a .git-blame-ignore-revs file

The git-blame command supports the `--ignore-revs-file` option
since git 2.23. This option allows a file containing a list of revisions
that git-blame must ignore to be specified.

It can be used as such:
  git blame --ignore-revs-file=.git-blame-ignore-revs some-file.cpp

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I39692f9eda999703e3e3bacb6e02f6e714eeb8a8

21 months agoBuild fix: consumer: unused-but-set-variable warning
Jérémie Galarneau [Fri, 3 Feb 2023 19:05:05 +0000 (14:05 -0500)] 
Build fix: consumer: unused-but-set-variable warning

clang 15.0.7 produces the following warning, preventing the build of the
project with -Werror:

  consumer/consumer.cpp:2519:15: error: variable 'num_hup' set but not used [-Werror,-Wunused-but-set-variable]
          int num_rdy, num_hup, high_prio, ret, i, err = -1;
                       ^

num_hup is indeed not used, so remove its declaration and its
assignations.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iccd8aa7716602d6babd1ed5aa23d06268385480c

21 months agoBuild fix: filter parser fails to build with -Werror
Jérémie Galarneau [Fri, 3 Feb 2023 18:59:23 +0000 (13:59 -0500)] 
Build fix: filter parser fails to build with -Werror

Using bison 3.8.2 and clang 15.0.7, the project fails to build with
-Werror as building the generated parser results in the following
warning:

  CXX      filter/libfilter_la-filter-parser.lo
  filter/filter-parser.cpp:1552:9: error: variable 'yynerrs' set but not used [-Werror,-Wunused-but-set-variable]
      int yynerrs = 0;
          ^

A pragma directive is inserted to silence the warning and allow the
build to go through.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4c46a5df91bdeca6ad4e2a8ff7f2a98ee94c4f1d

21 months agotests: Execute perl using /usr/bin/env
Olivier Dion [Wed, 1 Feb 2023 18:28:50 +0000 (13:28 -0500)] 
tests: Execute perl using /usr/bin/env

Perl is not necessary installed under /bin.  Thus, use /usr/bin/env to
get the corretion location from PATH.

Change-Id: Ie5f037bcfa69c344b63cf04ec7374dc28218d1c7
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 months agoReplace explicit rcu_read_lock/unlock with lttng::urcu::read_lock_guard
Jérémie Galarneau [Sat, 28 Jan 2023 09:54:09 +0000 (04:54 -0500)] 
Replace explicit rcu_read_lock/unlock with lttng::urcu::read_lock_guard

The explicit use of rcu_read_lock/unlock() has been a frequent source of
bugs in the code base as the locks can often end-up imbalanced when
error paths are taken (through goto's).

Since lttng::urcu::read_lock_guard was implemented in a previous commit,
replace all usages of the rcu_read_lock/unlock() API with an RAII
lock_guard wrapper.

Essentially, lttng::urcu::read_lock_guard acquires the RCU reader lock
on construction, and releases it when it goes out of scope. This
automates what is accomplished in the various error paths by jumping to
error handling labels.

For more info, see: https://en.cppreference.com/w/cpp/thread/lock_guard

No user-visible change of behaviour is intended by this patch. The scope
of some critical sections has been reduced when possible and when it
didn't matter from a correctness standpoint. The RCU reader lock would
often be held longer than necessary to simplify the error paths.

Explicit scopes are used to limit the lifetime of the reader lock guards
when used in long functions or when it is only intended to protect the
iteration over cds_lfht instances. In those cases, the following pattern
is used:

```cpp
void foo()
{
  [...]
  {
    lttng::urcu::read_lock_guard read_guard;

    cds_lfht_for_each(...) {
      [...]
  }
  [...]
}
```

This explicitly bounds the critical section and also serves as a hint as
to why the read guard is being used. It is fairly verbose, but I think
it's a good compromise until we add an idiomatic urcu wrapper that
automates this stuff too.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie3ef8ddf0f1ab813971522176115688939696370

21 months agoClean-up: replace uses of `int enabled` with boolean flags
Jérémie Galarneau [Sat, 28 Jan 2023 18:18:32 +0000 (13:18 -0500)] 
Clean-up: replace uses of `int enabled` with boolean flags

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If9cf1b6e2db67d461479a43d8ed3c3e07c4133ba

21 months agoClean-up: replace uses of `int found` as bool by `bool found`
Jérémie Galarneau [Sat, 28 Jan 2023 18:10:39 +0000 (13:10 -0500)] 
Clean-up: replace uses of `int found` as bool by `bool found`

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I95c4cefdc0836203d3bf8e6b9c273cf5f1cbf3fc

21 months agoClean-up: ust-consumerd: remove stub of removed function
Jérémie Galarneau [Wed, 1 Feb 2023 19:22:32 +0000 (14:22 -0500)] 
Clean-up: ust-consumerd: remove stub of removed function

lttng_ustconsumer_allocate_channel() no longer exists. However,
it is still declared and a stub is present when building without
liblttng-ust. Remove both as they are no longer needed.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I33f357bf642822a4825b9d3ceba098f1421c0132

22 months agoBuild fix: missing cstdint include in time.hpp on macOS
Michael Jeanson [Wed, 18 Jan 2023 20:15:14 +0000 (15:15 -0500)] 
Build fix: missing cstdint include in time.hpp on macOS

The order of inclusions was changed and the build fails on macOS since
time.hpp doesn't include cstdint for its use of uint64_t.

Change-Id: Id992160bcc3320f093453c2e66b90cc0f55db1c7
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoclang-tidy: disable analysis for swig-generated code
Jérémie Galarneau [Tue, 17 Jan 2023 17:18:25 +0000 (12:18 -0500)] 
clang-tidy: disable analysis for swig-generated code

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Idd951400c20ee942b6c9a8fba197d106a3f3d02b

22 months agoclang-tidy: add a subset of cppcoreguidelines and other style checks
Jérémie Galarneau [Tue, 17 Jan 2023 03:00:38 +0000 (22:00 -0500)] 
clang-tidy: add a subset of cppcoreguidelines and other style checks

Enforce some of the coding style rules using clang-tidy. The changes to
the code concern cppcoreguidelines-special-member-functions.

Change-Id: I47ec220505a625814b18b42ae9a070b8bf413337
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoFix: ini parser: truncation of value name
Jérémie Galarneau [Mon, 16 Jan 2023 19:19:20 +0000 (14:19 -0500)] 
Fix: ini parser: truncation of value name

clang 14 reports the following:

  ini-config/ini.cpp:88:16: warning: 'char* strncpy(char*, const char*, size_t)' output may be truncated copying 49 bytes from a string of length 199 [-Wstringop-truncation]
     88 |         strncpy(dest, src, size - 1);
        |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Indeed, a silent truncation of `name` occurs whenever it is longer than
prev_name (49 characters, excluding the terminator).

Report an error when this condition occurs.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I973bd27185e0130d8e4a452525d9277de45ba200

22 months agoBuild fix: warning: clang warns that uuid_scan may be uninitialized
Jérémie Galarneau [Mon, 16 Jan 2023 19:12:41 +0000 (14:12 -0500)] 
Build fix: warning: clang warns that uuid_scan may be uninitialized

clang warns that uuid_scan may be uninitialized. While this can't
happen given the function's code flow, silence the warning by
initializing uuid_scan.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I143131663cde02234c47ec16c74ee9176e49c1cc

22 months agoClean-up: ensure all template parameter names end with Type
Jérémie Galarneau [Mon, 16 Jan 2023 19:12:28 +0000 (14:12 -0500)] 
Clean-up: ensure all template parameter names end with Type

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1d3f307b173fe5fd8796cdaa89a8405217e251db

22 months agoclang-tidy: add readability-simplify-boolean-expr
Jérémie Galarneau [Sat, 14 Jan 2023 04:56:05 +0000 (23:56 -0500)] 
clang-tidy: add readability-simplify-boolean-expr

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I2dc131c79b9014fe4d20a58ec83d69bd6986bb85

22 months agoClean-up: sessiond: remove useless LTTNG_ASSERT
Jérémie Galarneau [Sat, 14 Jan 2023 04:47:35 +0000 (23:47 -0500)] 
Clean-up: sessiond: remove useless LTTNG_ASSERT

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iaa232da2f2a6d50b47b2144befee4c66d45caf91

22 months agoclang-tidy: add most bugprone warnings
Jérémie Galarneau [Sat, 14 Jan 2023 00:34:42 +0000 (19:34 -0500)] 
clang-tidy: add most bugprone warnings

Most of the changes proposed by clang-tidy are explicit checks for the
result of strcmp() and adding parentheses for all macro parameters.

Change-Id: I6ce7384b6d96035454d5456ac920becbf2882e65
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoclang-tidy: add Chrome-inspired checks
Jérémie Galarneau [Fri, 13 Jan 2023 22:14:04 +0000 (17:14 -0500)] 
clang-tidy: add Chrome-inspired checks

Add the checks used by the Chrome project. Most of these changes
were produced and applied by clang-tidy.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4058dafbdef00e81ac04f202fdfe377384a99e6b

22 months agoAdd a basic .clang-tidy file and fix typedef warnings
Jérémie Galarneau [Fri, 13 Jan 2023 17:24:13 +0000 (12:24 -0500)] 
Add a basic .clang-tidy file and fix typedef warnings

This initial .clang-tidy file only enforces the use of 'using' instead
of 'typedef'.

Note that a second .clang-tidy is added to the filter sub-folder to
disable checks against generated code.

The entire tree can be checked by running `run-clang-tidy` after
generating a compilation command database. I personally use `bear`
to generate `compile_commands.json`.

$ ./configure
$ bear -- make -j$(nproc)
$ run-clang-tidy -fix

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I074b6f2724e1af9a2df311e07a2fcdacb689bcf5

22 months agoRun clang-format on the whole tree
Jérémie Galarneau [Fri, 13 Jan 2023 17:02:15 +0000 (12:02 -0500)] 
Run clang-format on the whole tree

Generated by running:

find -not \( -path "./src/vendor*" -prune \) -iname "*.h" -o -iname "*.hpp" -o -iname "*.c" -o -iname "*.cpp" -exec clang-format -i {} \;

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9557e7d84e305187475ef88124857cf2f438bbb1

22 months agoBuild fix: missing stdio.h include in signal-helper.hpp
Jérémie Galarneau [Thu, 15 Dec 2022 22:39:09 +0000 (17:39 -0500)] 
Build fix: missing stdio.h include in signal-helper.hpp

A follow-up commit changes the order of inclusions and fails to build
since signal-helper.hpp doesn't include stdio.h for its use of perror().

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id402346fcd727f23d382697d06d3886a915aa014

22 months agoBuild fix: missing unistd.h include in utils.h
Jérémie Galarneau [Thu, 15 Dec 2022 22:34:25 +0000 (17:34 -0500)] 
Build fix: missing unistd.h include in utils.h

A follow-up commit changes the order of inclusions and fails to
build since utils.h doesn't include unistd.h for its use
of `useconds_t`.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I34a03311bb4f0eb43be9c004a057b10f3168f117

22 months agoBuild fix: missing consumer.hpp include in lttng-consumerd.hpp
Jérémie Galarneau [Thu, 15 Dec 2022 22:24:19 +0000 (17:24 -0500)] 
Build fix: missing consumer.hpp include in lttng-consumerd.hpp

A follow-up commit changes the order of inclusions and fails to build
since lttng-consumerd.hpp doesn't include consumer.hpp for its use of
`enum lttng_consumer_type`.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I8eb6e9ab0e97624c3cae85057c15703873534c2c

22 months agoBuild fix: missing poll wrapper include in utils-poll.cpp
Jérémie Galarneau [Thu, 15 Dec 2022 22:22:15 +0000 (17:22 -0500)] 
Build fix: missing poll wrapper include in utils-poll.cpp

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7d751007af88416e4281be5af3c4a252eb8bfcde

22 months agoBuild fix: missing cstdlib include in filter-ir.hpp
Jérémie Galarneau [Thu, 15 Dec 2022 22:15:15 +0000 (17:15 -0500)] 
Build fix: missing cstdlib include in filter-ir.hpp

A follow-up commit changes the order of inclusions and fails to build
since filter-ir.hpp doesn't include cstdlib for its use of abort().

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7d96d183745c9c834d272cbbbbb4d9a17e1f281e

22 months agoBuild fix: missing cstdint include in futex.hpp
Jérémie Galarneau [Thu, 15 Dec 2022 22:12:31 +0000 (17:12 -0500)] 
Build fix: missing cstdint include in futex.hpp

A follow-up commit changes the order of inclusions and fails to build
since futex.hpp doesn't include cstdint for its use of int32_t.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia4a4be7902c024250717b3349055b9c8c3e44f8b

22 months agoUpdate .clang-format to match existing style
Jérémie Galarneau [Tue, 8 Nov 2022 20:55:58 +0000 (15:55 -0500)] 
Update .clang-format to match existing style

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I082446af8267dbd6c8b7eca3a35388722b804d8d

22 months agoUpdate CodingStyle to account for C++ migration
Jérémie Galarneau [Tue, 8 Nov 2022 20:55:25 +0000 (15:55 -0500)] 
Update CodingStyle to account for C++ migration

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ifd8a849e3a730ec709ef06633f127a8d1a8449d1

22 months agoClean-up: default_pipe_size_getter: coding style adjustments
Jérémie Galarneau [Fri, 13 Jan 2023 16:58:51 +0000 (11:58 -0500)] 
Clean-up: default_pipe_size_getter: coding style adjustments

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I24bbe1bbfa0608c1952ab1c86743320e77ea7c3c

22 months agoport: tests: F_GETPIPE_SZ is linux specific
Michael Jeanson [Fri, 16 Jul 2021 18:48:48 +0000 (14:48 -0400)] 
port: tests: F_GETPIPE_SZ is linux specific

Change-Id: Ifa6631cc72b8998e1331905ff851cd2477fab148
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoClean-up: remove unused _trace_abi field from the CTF2 trace class visitor
Jérémie Galarneau [Fri, 13 Jan 2023 16:41:32 +0000 (11:41 -0500)] 
Clean-up: remove unused _trace_abi field from the CTF2 trace class visitor

This unused field results in a build failure when using clang++ 14.0.6
with Werror.

  ./ctf2-trace-class-visitor.hpp:39:37: error: private field '_trace_abi' is not used [-Werror,-Wunused-private-field]
          const lttng::sessiond::trace::abi& _trace_abi;

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib85ad5c9c5affce123ee6300b8549f884a55df31

22 months agoClean-up: sessiond: rename public accessors
Jérémie Galarneau [Thu, 12 Jan 2023 22:09:05 +0000 (17:09 -0500)] 
Clean-up: sessiond: rename public accessors

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Icf87c518d632a176c7786a48b3921e0638545d9c

22 months agosessiond: rename transfer_* method to move_*
Jérémie Galarneau [Thu, 12 Jan 2023 21:40:32 +0000 (16:40 -0500)] 
sessiond: rename transfer_* method to move_*

Other similar methods use the 'move' terminology to express a transfer
of ownership.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ide2bc0f49ab8b40dd6af01b45c79e058f9c6b14a

22 months agosessiond: ust: conditionally enable the underscore prefix variant quirk
Jérémie Galarneau [Mon, 28 Nov 2022 23:02:44 +0000 (18:02 -0500)] 
sessiond: ust: conditionally enable the underscore prefix variant quirk

Application contexts are expressed as variants. LTTng-UST announces
those by registering an enumeration named `..._tag`. It then registers a
variant as part of the event context that contains the various possible
types.

Unfortunately, the names used in the enumeration and variant don't
match: the enumeration names are all prefixed with an underscore while
the variant type tag fields aren't.

While the CTF 1.8.3 specification mentions that
underscores *should* (not *must*) be removed by CTF readers. Babeltrace
1.x (and possibly others) expect a perfect match between the names used
by tags and variants.

When the UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS quirk is enabled,
the variant's fields are modified to match the mappings of its tag.

From ABI version >= 10.x, the variant fields and tag mapping names
correctly match, making this work-around unnecessary.

However, since the variants produced by LTTng-UST contain TSDL-unsafe
names, a variant/selector sanitization pass is performed before
serializing a trace class hierarchy to TSDL.

The variant_tsdl_keyword_sanitizer visitor is used to visit field before
it is handed-over to the actual TSDL-producing visitor.

As it visits fields, the variant_tsdl_keyword_sanitizer populates a
"type_overrider" with TSDL-safe replacements for any variant or
enumeration that uses TSDL-unsafe identifiers (reserved keywords).

The type_overrider, in turn, is used by the rest of the TSDL
serialization visitor (tsdl_field_visitor) to swap any TSDL-unsafe types
with their sanitized version.

The tsdl_field_visitor owns the type_overrider and only briefly shares
it with the variant_tsdl_keyword_sanitizer which takes a reference to
it.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib61eafc452338a99a02b9829cbd049cb6fa48ead
Depends-on: lttng-ust: Ia7e78096a9c31cd4c0574d599c961067d8f03791

22 months agoClean-up: coverity warns of uncaught exception during logging
Jérémie Galarneau [Fri, 6 Jan 2023 17:01:53 +0000 (12:01 -0500)] 
Clean-up: coverity warns of uncaught exception during logging

Coverity reports:

  1502349 Uncaught exception If the exception is ever thrown, the
  program will crash.

  In lttng::​file_descriptor::​~file_descriptor(): A C++ exception is
  thrown but never caught (CWE-248)

and

  1502348 Uncaught exception If the exception is ever thrown, the
  program will crash.

  In main: A C++ exception is thrown but never caught (CWE-248)

Both have the same cause: libfmt should not be used in "final" catch
blocks before returning to non exception-safe code in order to contain
all exceptions.

As we add custom formaters, it could be interesting to revisit this and
provide a noexcept wrapper for fmt::format. For the moment not much is
lost (beyond format string type safety) from using the existing logging
macros directly.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia70505517678ae182f6479feeb264c9402aa1381

22 months agoFix: sessiond: instance uuid is not sufficiently unique
Jérémie Galarneau [Tue, 3 Jan 2023 23:41:23 +0000 (18:41 -0500)] 
Fix: sessiond: instance uuid is not sufficiently unique

Observed issue
==============

Tracing a cluster of machines -- all launched simultaneously -- to the
same relay daemon occasionally produces corrupted traces.

The size of packets received (as seen from the relay daemon logs) and
that of those present in the on-disk stream occasionally didn't match.

The traces were observed to all relate to the same trace UUID, but
present packet begin timestamps that were not monotonic for a given
stream.

This causes both Babeltrace 1.x and 2.x to fail to open the traces with
different error messages related to clocks.

Cause
=====

On start, the session daemon generates a UUID to uniquely identify the
sessiond instance. Since the UUID generation utils use time() to seed
the random number generator, two session daemons launched within the
same second can end up with the same instance UUID.

Since the relay daemon relies on this UUID to uniquely identify a
session daemon accross its various connections, identifier clashes can
cause streams from the same `uid` or `pid` to become scrambled resulting
in corrupted traces.

Solution
========

The UUID utils now initializes its random seed using the getrandom() API
in non-blocking mode. If that fails -- most likely because the random
pool is depleted or the syscall is not available on the platform -- it
falls back to using a hash of two time readings (with nanosecond
precision), of the hostname, and the PID.

Known drawbacks
===============

This fix implements many fallbacks, each with their own caveats and we
don't have full test coverage for all of those for the moment.

This article presents the different drawbacks of using /dev/urandom vs
getrandom().

https://lwn.net/Articles/884875/

As for the pseudo-random time and configuration based fallback, it is
meant as a last resort for platforms or configurations where both
getrandom() (old kernels or non-Linux platforms) and /dev/urandom (e.g.
locked-down container) are not be available. I haven't done a formal
analysis of the entropy of this home-grown method. The practical
use-case we want to enable is launching multiple virtual machines (or
containers) at roughly the same time and ensure that they don't end up
using the same sessiond UUID.

In that respect, having a different host name and minute timing changes
seem enough to prevent a UUID clash.

Using the PID as part of the hash also helps when launching multiple
session daemons simultaneously for different users.

Change-Id: I064753b9ff0f5bf2279be0bd0cfbfd2b0dd19bfc
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
22 months agoLog uts information on launch of the session and relay daemon
Jérémie Galarneau [Tue, 3 Jan 2023 19:11:21 +0000 (14:11 -0500)] 
Log uts information on launch of the session and relay daemon

To make debugging easier, log uts information on launch of the daemons.

Produces an output of the following form when the daemons are launched
in verbose mode:
  DBG1 - 14:30:14.997217006 [Main]: System information: (in log_system_information() at logging-utils.cpp:23)
  DBG1 - 14:30:14.997221139 [Main]:  sysname: `Linux` (in log_system_information() at logging-utils.cpp:24)
  DBG1 - 14:30:14.997227199 [Main]:  nodename: `carbonara` (in log_system_information() at logging-utils.cpp:25)
  DBG1 - 14:30:14.997231284 [Main]:  release: `6.1.1-arch1-1` (in log_system_information() at logging-utils.cpp:26)
  DBG1 - 14:30:14.997235261 [Main]:  version: `#1 SMP PREEMPT_DYNAMIC Wed, 21 Dec 2022 22:27:55 +0000` (in log_system_information() at logging-utils.cpp:27)
  DBG1 - 14:30:14.997240214 [Main]:  machine: `x86_64` (in log_system_information() at logging-utils.cpp:28)

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I399fe8a88da8480e617cc33dd6b1dc2723c300c7

22 months agoBuild fix: g++ < 7.1 mishandles namespaces of specializations
Jérémie Galarneau [Thu, 5 Jan 2023 19:46:31 +0000 (14:46 -0500)] 
Build fix: g++ < 7.1 mishandles namespaces of specializations

Due to a bug in g++ < 7.1, these specializations must be explicitly
enclosed in the namespaces rather than using the usual
`namespace::namespace::function` notation.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480.

We already use this work-around in a number of places.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie0e6a3c4dcfb4bc1581c2d273d73ea3e65b2ccd6

23 months agoFix: lttng: poptGetArg doesn't provide string ownership
Michael Jeanson [Mon, 31 Oct 2022 19:52:46 +0000 (15:52 -0400)] 
Fix: lttng: poptGetArg doesn't provide string ownership

The string returned by poptGetArg() is 'const' because it is owned by
the popt librairy and is free'd by it when poptFreeContext() is called.
Copy those strings when we need to alter them to maintain proper
ownership.

The latest release of popt (v1.19) introduced a breaking
change (changing the ownership of left-over command line arguments) that
can cause double free()-s.

This is ultimately due to this upstream commit in popt 1.19:
https://github.com/rpm-software-management/popt/commit/7182e4618ad5a0186145fc2aa4a98c2229afdfa8

which is derived from a package patch:
https://src.fedoraproject.org/rpms/babeltrace/c/d48452beff87b145c038f070e7182358db04336c?branch=rawhide

Change-Id: Id2535d1534c0e47cc0747968d6dd60a587f0b810
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agoCleanup: lttng: remove unused 'session_name' variable
Michael Jeanson [Thu, 3 Nov 2022 16:02:49 +0000 (12:02 -0400)] 
Cleanup: lttng: remove unused 'session_name' variable

Change-Id: I46ef649b68d1d9dd22378d34e7d5900b26d827ce
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agoFix: tap.h conflicts with Clang C++ headers
Michael Jeanson [Thu, 27 Oct 2022 21:06:22 +0000 (17:06 -0400)] 
Fix: tap.h conflicts with Clang C++ headers

Always include tap.h last since it defines a 'fail' macro that clashes
with some version of the clang++ system headers.

Change-Id: I20938697045d00b467b12ca1e6dae159c634720a
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agoFix: relayd: missing space in trace creation logging statement
Jérémie Galarneau [Fri, 2 Dec 2022 22:11:00 +0000 (17:11 -0500)] 
Fix: relayd: missing space in trace creation logging statement

A missing space results in hard to read logging statements when a
ctf_trace is created:

[...] Created ctf_trace 15of session "hello" [...]

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3881ddfc17556f2300f2140939c45d49e3b18d2b

23 months agoTests: add basic ust context tests for $app, vpid, vuid, vgid
Jérémie Galarneau [Thu, 17 Nov 2022 16:44:09 +0000 (11:44 -0500)] 
Tests: add basic ust context tests for $app, vpid, vuid, vgid

Context tracing has very little testing coverage beyond the namespace
tests. This test is initially introduced to help troubleshoot an issue
with application contexts.

However, with the scaffolding now in place, it's trivial to exercise
some other context types.

This also adds a basic framework to write tests in Python.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I85be842fab252d8b853392d3f742b1461a69f0fe

23 months agoFix: sessiond: work-around mismatching variant type tag field and selector names
Jérémie Galarneau [Fri, 25 Nov 2022 21:18:42 +0000 (16:18 -0500)] 
Fix: sessiond: work-around mismatching variant type tag field and selector names

Observed issue
--------------

Applications fail to register to the session daemon when an application
context is used. The following error is printed by the session daemon:

Error: Failed to handle application context: Invalid variant choice: `none` does not match any mapping in `$app.mayo:ketchup_tag` enumeration [operator()() ust-field-convert.cpp:606]

Cause
-----

Application contexts are expressed as variants. LTTng-UST announces
those by registering an enumeration named `..._tag`. It then registers a
variant as part of the event context that contains the various possible
types.

Unfortunately, the names used in the enumeration and variant don't
match: the enumeration names are all prefixed with an underscore while
the variant type tag fields aren't.

In preparation for adding the support for the CTF 2 format, the session
daemon's handling of user space field class declarations was decoupled
from the generation of TSDL. Trace layouts are now expressed in an
internal intermediate representation that is used to generate TSDL or
CTF 2 independently.

As part of the conversion from liblttng-ust-ctl's communication
structures to the internal IR (see ust-field-convert.cpp), a certain
number of validations steps are taken. One of them ensures that variant
fields match a mapping within its '_tag' enumeration. This step fails
and produces the error message above.

While the CTF 1.8.3 specification mentions that
underscores *should* (not *must*) be removed by CTF readers. Babeltrace
1.x (and possibly others) expect a perfect match between the names used
by tags and variants.

The previous implementation of the TSDL producer always prepended '_' to
identifiers in order to side-step the problem of escaping TSDL keywords
and ensuring identifiers started with an alphabetic character.

This is not the case for enumeration mappings. Hence, I presume that the
underscores were added on the LTTng-UST side to coherce the session
daemon into producing a trace that Babeltrace 1.x would accept.

For reference, using LTTng 2.13 to trace the `$app:hey:you` application
context results in the following declaration in the TSDL metadata:

stream {
id = 0;
event.header := struct event_header_large;
packet.context := struct packet_context;
event.context := struct {
enum : integer { size = 8; align = 8; signed = 1; encoding = none; base = 10; } {
"_none" = 0,
"_int8" = 1,
"_int16" = 2,
"_int32" = 3,
"_int64" = 4,
"_uint8" = 5,
"_uint16" = 6,
"_uint32" = 7,
"_uint64" = 8,
"_float" = 9,
"_double" = 10,
"_string" = 11,
} __app_hey_you_tag;
variant <__app_hey_you_tag> {
struct {} _none;
integer { size = 8; align = 8; signed = 1; encoding = none; base = 10; } _int8;
integer { size = 16; align = 8; signed = 1; encoding = none; base = 10; } _int16;
integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _int32;
integer { size = 64; align = 8; signed = 1; encoding = none; base = 10; } _int64;
integer { size = 8; align = 8; signed = 0; encoding = none; base = 10; } _uint8;
integer { size = 16; align = 8; signed = 0; encoding = none; base = 10; } _uint16;
integer { size = 32; align = 8; signed = 0; encoding = none; base = 10; } _uint32;
integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } _uint64;
floating_point { exp_dig = 8; mant_dig = 24; align = 8; } _float;
floating_point { exp_dig = 11; mant_dig = 53; align = 8; } _double;
string _string;
} __app_hey_you;
};
};

Solution
--------

During the creation of variant field types, the check for matching
variant/tag names is made more permissive if the registering tracer has
an affected ABI major version, which is always true for the moment.

In that mode, the variant fields are renamed to match the mappings in
the tag field when they differ by a leading underscore. For a reader,
this results in the same apparent trace where mappings and variant
fields are prefixed with an underscore.

A change to LTTng-UST removing the underscores from the enumeration
mapping names has been submitted. That fix bumps the
LTTNG_UST_ABI_MAJOR_VERSION to 10. Once/if that fix is accepted, the
check will return to its original strict-ness.

This change ensures that CTF 2 traces don't carry the leading underscore
baggage when tracing applications built against LTTng-UST 2.14+.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0e3ad6668baefaea011a878746e041bd17f6373c

23 months agoCleanup: tsdl: fix misleading indentation
Jérémie Galarneau [Fri, 25 Nov 2022 20:59:05 +0000 (15:59 -0500)] 
Cleanup: tsdl: fix misleading indentation

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iedb85ce7692c19e373dbb9a80b1d85adc6c4f2bd

23 months agocommon: session load: use session descriptor for session creation
Jonathan Rajotte [Tue, 26 Apr 2022 18:40:21 +0000 (14:40 -0400)] 
common: session load: use session descriptor for session creation

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If6bc9ddf9c5cf252f8838f5793870d0ffdc4dfc8

23 months agolttng-ctl: use the parsed URI instead of raw string for override
Jonathan Rajotte [Tue, 26 Apr 2022 18:33:52 +0000 (14:33 -0400)] 
lttng-ctl: use the parsed URI instead of raw string for override

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0439c1ecdc935011036e3772e59f0caba017de34

23 months agosessiond: add a CTF 2-generating trace class visitor
Jérémie Galarneau [Mon, 4 Jul 2022 19:19:00 +0000 (15:19 -0400)] 
sessiond: add a CTF 2-generating trace class visitor

The enumeration_type class is modified to guarantee that a mapping is
present. Implicit (or auto) mappings provided by the tracer are
converted to an explicit mapping.

This results in a slightly more verbose TSDL output which can be fixed
later.

Change-Id: I4372ad528384c1b7d9321dd5183525e3bd60ded4
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agosessiond: add variant selector intervals
Jérémie Galarneau [Tue, 26 Jul 2022 21:06:30 +0000 (17:06 -0400)] 
sessiond: add variant selector intervals

In CTF 2, variant options are chosen using a set of ranges. This differs
from CTF 1.8 (and the current API) which assumed that a variant had
options that perfectly matched the selector enumeration's mappings.

Add integer mappings to variants and also carry a choice name that
becomes the name used by the TSDL producer.

Change-Id: Ib31cf9cc211dad36759bd73dc722c49d634c666b
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agosessiond: validate existence of field reference received from LTTng-UST
Jérémie Galarneau [Tue, 26 Jul 2022 22:34:44 +0000 (18:34 -0400)] 
sessiond: validate existence of field reference received from LTTng-UST

Some field descriptions received from traced applications refer to
other fields (a sequence's length field, a variant's selector field,
etc.)

Validate that those references are valid.

Change-Id: I73f5b464b007810beb228128d5bc3243e3b05157
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
23 months agosessiond: express field references as locations instead of names
Jérémie Galarneau [Tue, 26 Jul 2022 19:17:20 +0000 (15:17 -0400)] 
sessiond: express field references as locations instead of names

CTF2 requires type references (a sequence's length, a variant's
selector) to be expressed as absolute field locations.

The `field` API currently expresses these references as names directly
since those are provided by the tracer.

This change introduces the notion of a field location and adapts
the tsdl visitor to serialize those as expected.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I56f603062d6748051adf3fa31bc08422c47c144d

23 months agosessiond: return raw pointer to packet header
Jérémie Galarneau [Thu, 21 Jul 2022 19:41:43 +0000 (15:41 -0400)] 
sessiond: return raw pointer to packet header

There is no benefit to transfering the ownership of a new packet header
everytime it is serialized. Packet headers don't change after the
creation of a session; prefer allocating it once and provide a
raw (const) pointer to the session's instance.

While LTTng always produces one, a trace doesn't absolutely need a
packet header so a pointer is preferred over a reference.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I66b8f9ad74e332edcc8273c076137a7fff0d4d5e

23 months agosessiond: tsdl: remove useless std::move
Jérémie Galarneau [Wed, 13 Jul 2022 21:14:01 +0000 (17:14 -0400)] 
sessiond: tsdl: remove useless std::move

append_metadata_fragment accepts the string by reference and it is
passed as such all the way; there is no need for an ownership transfer.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I49baab00c333b97f0dde49bad34fee43e7e40a2b

23 months agosessiond: generate packet header, packet context and event header dynamically
Jérémie Galarneau [Thu, 7 Jul 2022 16:20:33 +0000 (12:20 -0400)] 
sessiond: generate packet header, packet context and event header dynamically

Instead of hardcoding event header and packet header/context layouts,
their layout is expressed using the lttng::sessiond::trace::field/type
API and serialized to TSDL using the visitor.

This reduces the duplication of code in the CTF2 visitor.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9a4255889e36e6861a59536ce70b1e708da06ac5

23 months agoFix: sessiond: tsdl: don't prepend underscore for stream_id
Jérémie Galarneau [Mon, 11 Jul 2022 19:48:49 +0000 (15:48 -0400)] 
Fix: sessiond: tsdl: don't prepend underscore for stream_id

Although the CTF v1.8 specification recommends ignoring any leading
underscore, Some readers, such as Babeltrace 1.x, expect special
identifiers without a prepended underscore.

This causes problems in a follow-up patch since packet header, context,
and event headers become dynamically generated.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0aeb24ab2e1c0ee1ea70d2fb9bb0eabbb2e9e035

23 months agosessiond: field: add field roles and blob types
Jérémie Galarneau [Mon, 4 Jul 2022 19:00:25 +0000 (15:00 -0400)] 
sessiond: field: add field roles and blob types

Extend the field/field type to include the blob field types that
are used to express the trace class uuid in CTF2.

Roles defined by the CTF2 specification are also added to allow a trace
class to define the layout of some scopes (e.g. packet header and
context) instead of hard-coding the serialized version of the layout
description.

The TSDL trace class visitor takes the new types into account by
converting them into arrays of "bytes" (uint8_t).

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ic9d976416ed765b157e951bf9b8b299abbe20e5b

23 months agoAdd nlohmann/json 3.10.5 to vendor libraries
Jérémie Galarneau [Mon, 13 Jun 2022 18:43:22 +0000 (14:43 -0400)] 
Add nlohmann/json 3.10.5 to vendor libraries

JSON is released under the MIT license. The MIT license text is already
under LICENCES.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1aab2c0af7e71248a8ce8b10240daf191d057e09

2 years agoFix: event field value: assertion fails on empty string
Mathieu Desnoyers [Mon, 26 Sep 2022 17:36:38 +0000 (13:36 -0400)] 
Fix: event field value: assertion fails on empty string

When converting msgpack objects to their event_field_value equivalent,
the following assertion fails: LTTNG_ASSERT(val);

 #4  0x00007f1f65349486 in __assert_fail () from /usr/lib/libc.so.6
 #5  0x00007f1f65584da7 in lttng_event_field_value_string_create_with_size (val=0x0, size=0) at event-field-value.cpp:186
 #6  0x00007f1f65576a1a in event_field_value_from_obj (obj=0x557f597ccdb8, field_val=0x7ffcc9675dd0)
     at conditions/event-rule-matches.cpp:1120
 #7  0x00007f1f65577176 in event_field_value_from_capture_payload (condition=0x557f597c8520,
     capture_payload=0x557f597c825b "\221\240", capture_payload_size=2) at conditions/event-rule-matches.cpp:1340
 #8  0x00007f1f655772ea in lttng_evaluation_event_rule_matches_create (condition=0x557f597c8520,
     capture_payload=0x557f597c825b "\221\240", capture_payload_size=2, decode_capture_payload=true)
     at conditions/event-rule-matches.cpp:1398
 #9  0x00007f1f655765fc in lttng_evaluation_event_rule_matches_create_from_payload (condition=0x557f597c8520,
     view=0x7ffcc9675ff0, _evaluation=0x7ffcc9676080) at conditions/event-rule-matches.cpp:990
 #10 0x00007f1f6557f273 in lttng_evaluation_create_from_payload (condition=0x557f597c8520, src_view=0x7ffcc9676100,
     evaluation=0x7ffcc9676080) at evaluation.cpp:120
 #11 0x00007f1f6559ba36 in lttng_notification_create_from_payload (src_view=0x7ffcc9676190, notification=0x7ffcc9676180)
     at notification.cpp:123
 #12 0x00007f1f65552577 in create_notification_from_current_message (channel=0x557f597c8ee0) at channel.cpp:124
 #13 0x00007f1f6555298c in lttng_notification_channel_get_next_notification (channel=0x557f597c8ee0, _notification=0x7ffcc9676280)
     at channel.cpp:292

The msgpack API represents string as p-style while the implementation of
event_field_value relies on null-terminated strings. When an empty
string is captured by a tracer, it is decoded as a msgpack_object with
`str = {size = 0, ptr = 0x0}`.

lttng_event_field_value_string_create_with_size does not require a
null-terminated string since it also receives the length. Hence, this
fix causes lttng_event_field_value_string_create_with_size to accept
null strings when their length is zero. A copy of an empty string is
made to accomodate the null-termination convention used by the rest of
that API.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7c3a839dbbeeb95a1b3bf6ddc3205a2f6b4538e3

2 years agoport: BSD cut doesn't support '\0' as a delimiter
Michael Jeanson [Tue, 20 Oct 2020 21:08:31 +0000 (17:08 -0400)] 
port: BSD cut doesn't support '\0' as a delimiter

Use a combination of 'tr' and 'head' instead which works with both the
GNU and BSD version of coreutils.

Change-Id: I5628863ed41030864ec08f45a3d4153c32fc5496
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
2 years agoCleanup: remove ignored flags from poll events bitmasks
Michael Jeanson [Wed, 11 Nov 2020 15:38:51 +0000 (10:38 -0500)] 
Cleanup: remove ignored flags from poll events bitmasks

The POLLHUP and POLLERR flags are only valid in 'revents', they are
implicitly enabled regardless of the fact they were set in 'events' or not.

As such remove those flags from all poll events to reduce possible
confusion as to which flags can be returned by poll.

Change-Id: Id22c78c38257d96dfc47e1337795f13c70dd5f91
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
2 years agoport: add support for BSD mktemp
Michael Jeanson [Fri, 16 Jul 2021 21:52:35 +0000 (17:52 -0400)] 
port: add support for BSD mktemp

Use '-t' which is portable instead of the GNU specific '--tmpdir'.

Change-Id: I430af6b96c27c2766a2cc4b5574af8563297d717
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
2 years agoFix: C++ syntax of FreeBSD compat code
Michael Jeanson [Thu, 27 Oct 2022 21:05:23 +0000 (17:05 -0400)] 
Fix: C++ syntax of FreeBSD compat code

Change-Id: I4c463bb965c34692718dadd1731f2a1fab7a1248
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
2 years agoTests: fix randstring() with BSD `tr`
Michael Jeanson [Fri, 13 Nov 2020 23:19:31 +0000 (18:19 -0500)] 
Tests: fix randstring() with BSD `tr`

On FreeBSD, `tr` will error out with an "Illegal byte sequence"
error when it is provided with an invalid multi-byte character.
This happens regularly when its input is random.

Forcing `tr` to use the 'C' locale works around this problem as
that locale only allows single-byte characters.

Change-Id: I8d8e84fb7f356205dd45479538e5bc0bff3c1668
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
2 years agoFix: tests: CFLAGS to CXXFLAGS when converting to C++
Michael Jeanson [Thu, 27 Oct 2022 20:57:18 +0000 (16:57 -0400)] 
Fix: tests: CFLAGS to CXXFLAGS when converting to C++

The test was converted to C++ but the custom flags used to build it were
left in the CFLAGS variable which doesn't apply to C++ code. This begs
the question of the usefulness of these flags, except for POPT_CFLAGS
which lead to this finding.

Change-Id: I87412ff0730b960b191d8725a13407c67f7b431d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
This page took 0.051891 seconds and 4 git commands to generate.