babeltrace.git
2 weeks agoAdd common `ctf::ir` CTF IR classes
Philippe Proulx [Fri, 3 Nov 2023 18:32:50 +0000 (18:32 +0000)] 
Add common `ctf::ir` CTF IR classes

This patch adds common CTF IR class templates to the new
`src/plugins/ctf/common/metadata/ctf-ir.hpp` header.

The purpose of those new class templates is to have a common CTF IR
class hierarchy for all the `ctf` plugin component classes. This CTF IR
model is based on the CTF 2 model.

Although the file looks intimidating, it's pretty straightforward:

• The class hierarchy, under the `ctf::ir` namespace, (omitting template
  parameters) is as such:

      TraceCls
      DataStreamCls
      EventRecordCls
      ClkCls
      FieldLoc
      StructFieldMemberCls
      VariantFcOpt
      Fc
        FixedLenBitArrayFc
          FixedLenBitMapFc
          FixedLenBoolFc
          FixedLenFloatFc
          FixedLenIntFc
            FixedLenUIntFc
            FixedLenSIntFc
        VarLengthIntFc
          VarLengthUIntFc
          VarLengthSIntFc
        StrFc
          NullTerminatedStrFc
          NonNullTerminatedStrFc
            StaticLenStrFc
            DynLenStrFc
        BlobFc
          StaticLenBlobFc
          DynLenBlobFc
        ArrayFc
          StaticLenArrayFc
          DynLenArrayFc
        StructFc
        OptionalFc
          OptionalWithBoolSelFc
          OptionalWithIntSelFc
            OptionalWithUIntSelFc
            OptionalWithSIntSelFc
        VariantFc
          VariantWithUIntSelFc
          VariantWithSIntSelFc

• Each class template has the `UserMixinsT` template parameter.

  `UserMixinsT` is expected to be a user mixin container, a type
  defining the following nested types (user mixins):

  ‣ `ClkCls`
  ‣ `DataStreamCls`
  ‣ `DynLenArrayFc`
  ‣ `DynLenBlobFc`
  ‣ `DynLenStrFc`
  ‣ `EventRecordCls`
  ‣ `Fc`
  ‣ `FieldLoc`
  ‣ `FixedLenBitArrayFc`
  ‣ `FixedLenBitMapFc`
  ‣ `FixedLenBoolFc`
  ‣ `FixedLenIntFc`
  ‣ `FixedLenUIntFc`
  ‣ `OptionalFc`
  ‣ `OptionalWithBoolSelFc`
  ‣ `OptionalWithSIntSelFc`
  ‣ `OptionalWithUIntSelFc`
  ‣ `StaticLenArrayFc`
  ‣ `StaticLenBlobFc`
  ‣ `StaticLenStrFc`
  ‣ `StructFc`
  ‣ `StructFieldMemberCls`
  ‣ `TraceCls`
  ‣ `VariantFcOpt`
  ‣ `VariantWithSIntSelFc`
  ‣ `VariantWithUIntSelFc`
  ‣ `VarLenIntFc`
  ‣ `VarLenUIntFc`

• Most class templates inherit a given user mixin. For example,
  `FixedLenBoolFc` inherits `UserMixinsT::FixedLenBoolFc`. This makes it
  possible for the user to inject data and methods into the class while
  keeping the hierarchy and common features.

• A class template which inherits a user mixin M has a constructor which
  accepts an instance of M by value to initialize this part of
  the object.

  If a class template C which inherits a user mixin also inherits
  another class template inheriting another user mixin, then the
  constructor of C accepts both mixins. For example,
  FixedLenUIntFc::FixedLenUIntFc() accepts three mixins: field class,
  fixed-length bit array field class, and fixed-length integer
  field class.

• `Fc` has the typical asXyz() and isXyz() methods.

  To make isXyz() methods more efficient, `FcType` enumerators are
  bitwise compositions of `FcTypeTraits` values (traits/features).

• The `FcVisitor` and `ConstFcVisitor` base classes are available to
  visit field classes through the virtual Fc::accept() methods.

• There are a few internal mixins to share common members:

  `WithAttrsMixin`:
      Optional attributes.

  `WithPrefDispBaseMixin`:
      Preferred display base.

  `WithMappingsMixin`:
      Integer mappings.

  `WithLibCls`:
      libbabeltrace2 class.

  `UIntFcMixin`:
      Unsigned integer field roles.

  `StaticLenFcMixin`:
      Integral length.

  `DynLenFcMixin`:
      Length field location.

• The API offers `DefUserMixins` which defines empty user mixins to act
  as a base user mixin container structure.

Now, this is how you would use this API:

• Define your own user mixin container structure which inherits
  `ctf::ir::DefUserMixins`, defining the user mixins you need to add
  data and methods to specific common classes.

• Define aliases for each `ctf::ir` class template you need, using your
  user mixin container structure as the `UserMixinsT`
  template parameter.

• Create convenient object creation functions to construct specific CTF
  IR objects from parameters, hiding the internal user mixin details.

As an example, this builds and works as expected:

    #include <string>
    #include <iostream>

    #include "plugins/ctf/common/metadata/ctf-ir.hpp"

    // user mixin container
    struct MyMixins : ctf::ir::DefUserMixins
    {
        // structure field class mixin
        class StructFc
        {
        public:
            explicit StructFc(std::string favoriteKebSinger) :
                _mFavoriteKebSinger {std::move(favoriteKebSinger)}
            {
            }

            const std::string& favoriteKebSinger() const noexcept
            {
                return _mFavoriteKebSinger;
            }

        private:
            std::string _mFavoriteKebSinger;
        };
    };

    // custom object aliases
    using MyNullTerminatedStrFc = ctf::ir::NullTerminatedStrFc<MyMixins>;
    using MyStructFc = ctf::ir::StructFc<MyMixins>;
    using MyTraceCls = ctf::ir::TraceCls<MyMixins>;

    int main()
    {
        // create structure field class, constructing a `MyMixins::StructFc`
        MyStructFc::MemberClasses memberClasses;

        memberClasses.emplace_back(
            MyMixins::StructFieldMemberCls {}, "meow",
            bt2c::makeUnique<MyNullTerminatedStrFc>(MyMixins::Fc {}));

        auto pktHeaderFc = bt2c::makeUnique<MyStructFc>(
            MyMixins::Fc {},
            MyMixins::StructFc {"Claude Dubois"},
            std::move(memberClasses)
        );

        // create trace class
        MyTraceCls tc {
            MyMixins::TraceCls {},
            bt2s::nullopt, bt2s::nullopt, bt2s::nullopt,
            {}, std::move(pktHeaderFc)
        };

        // read custom user property
        std::cout << tc.pktHeaderFc()->favoriteKebSinger() << '\n';
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib4785c9a2f675bdc1415b149e9b57de1339f475e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7708
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12253
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agocpp-common: Add Blob, StaticBlob, and DynamicBlob FC
Francis Deslauriers [Mon, 11 Dec 2023 17:14:13 +0000 (12:14 -0500)] 
cpp-common: Add Blob, StaticBlob, and DynamicBlob FC

This commit copies the implementation of the static and dynamic array
field class wrappers.

The FieldClassType enum size is specified to 64 bits to accommodate for
enumerator value larger than 32 bits. (e.g.
BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD)

Here is the clang++ error
In file included from ../../../../src/cpp-common/bt2/trace-ir.hpp:19:
  ../../../../src/cpp-common/bt2/field-class.hpp:170:20: error: enumerator value evaluates to 2684354560, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
      DynamicBlob = BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB,
                    ^
  ../../../../src/cpp-common/bt2/field-class.hpp:171:41: error: enumerator value evaluates to 6979321856, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
      DynamicBlobWithoutLengthField = BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD,
                                      ^
  ../../../../src/cpp-common/bt2/field-class.hpp:172:38: error: enumerator value evaluates to 11274289152, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
      DynamicBlobWithLengthField = BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD,
                                   ^

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

2 weeks agosrc/cpp-common/bt2: wrap variant with selector field loc. FC API
Philippe Proulx [Tue, 26 Mar 2024 20:04:49 +0000 (16:04 -0400)] 
src/cpp-common/bt2: wrap variant with selector field loc. FC API

This patch adds what's needed to the C++ libbabeltrace2 wrappers to
wrap:

* bt_field_class_variant_with_selector_field_borrow_selector_field_location_const()
* bt_field_class_variant_with_selector_field_location_integer_unsigned_create()
* bt_field_class_variant_with_selector_field_location_integer_signed_create()

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

2 weeks agosrc/cpp-common/bt2: wrap option with selector field loc. FC API
Philippe Proulx [Wed, 11 May 2022 16:21:15 +0000 (12:21 -0400)] 
src/cpp-common/bt2: wrap option with selector field loc. FC API

This patch adds what's needed to the C++ libbabeltrace2 wrappers to
wrap:

* bt_field_class_option_with_selector_field_borrow_selector_field_location_const()
* bt_field_class_option_without_selector_field_location_create()
* bt_field_class_option_with_selector_field_location_bool_create()
* bt_field_class_option_with_selector_field_location_integer_unsigned_create()
* bt_field_class_option_with_selector_field_location_integer_signed_create()

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iaf20856ee2533a061560abf79c91a69b2dab20b5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8018
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12701
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agosrc/cpp-common/bt2: wrap dynamic array with length field loc. FC API
Philippe Proulx [Thu, 7 Dec 2023 20:26:27 +0000 (20:26 +0000)] 
src/cpp-common/bt2: wrap dynamic array with length field loc. FC API

This patch adds what's needed to the C++ libbabeltrace2 wrappers to
wrap:

* bt_field_class_array_dynamic_with_length_field_borrow_length_field_location_const()
* bt_field_class_array_dynamic_without_length_field_location_create()
* bt_field_class_array_dynamic_with_length_field_location_create()

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

2 weeks agosrc/cpp-common/bt2: add field location support
Philippe Proulx [Fri, 8 Dec 2023 18:50:58 +0000 (18:50 +0000)] 
src/cpp-common/bt2: add field location support

This patch adds the `bt2::ConstFieldLocation` wrapper class as well as
bt2::TraceClass::createFieldLocation().

I didn't implement a `bt2::CommonFieldLocation` template class because a
field location is immutable anyway, so we only need the const version.
bt2::TraceClass::createFieldLocation() returns a shared const field
location.

bt2::TraceClass::createFieldLocation() accepts a span of strings (either
`const char * const` or `const std::string`) to make the interface a
little nicer than a raw array of `const char *` and a matching size.
Creating a field location is a slow-path operation anyway.

Also adding bt2::wrap() accepting `const bt_field_location *`.

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

2 weeks agosrc/cpp-common/bt2/trace-ir.hpp: add nameSpace() methods where needed
Philippe Proulx [Tue, 26 Mar 2024 20:02:15 +0000 (16:02 -0400)] 
src/cpp-common/bt2/trace-ir.hpp: add nameSpace() methods where needed

The bt2::CommonEventClass::nameSpace() and
bt2::CommonStreamClass::nameSpace() methods make it possible to set and
get the namespace of event classes and stream classes (new feature
starting with MIP 1).

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

2 weeks ago`ctf` plugin: add `ctf::IntRangeSet` class template
Philippe Proulx [Fri, 3 Nov 2023 15:44:35 +0000 (15:44 +0000)] 
`ctf` plugin: add `ctf::IntRangeSet` class template

This new class template is conceptually the same as the libbabeltrace2
equivalent (`bt2::CommonIntegerRangeSet`), but it's templated and avoids
having to make libbabeltrace2 function calls to access data.

That being said, the contains() and intersects() methods don't have
their libbabeltrace2 equivalent.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I494dd1b236463eaf7c24d1143ed21afdd5e498b0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7923
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12252

2 weeks ago`ctf` plugin: add `ctf::IntRange` class template
Philippe Proulx [Thu, 30 Nov 2023 03:00:06 +0000 (03:00 +0000)] 
`ctf` plugin: add `ctf::IntRange` class template

This new class template is conceptually the same as the libbabeltrace2
equivalent (`bt2::ConstIntegerRange`), but it's templated and avoids
having to make libbabeltrace2 function calls to access data.

That being said, the contains() and intersects() methods don't have
their libbabeltrace2 equivalent.

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

2 weeks agosrc/cpp-common: add JSON value requirement aliases
Philippe Proulx [Fri, 8 Dec 2023 18:47:41 +0000 (18:47 +0000)] 
src/cpp-common: add JSON value requirement aliases

This patch defines JSON value requirement aliases of the generic value
requirement class templates (`val-req.hpp`) to validate JSON values.

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

2 weeks agoAdd `bt2c::ValReq` class template system
Philippe Proulx [Thu, 28 Mar 2024 17:53:31 +0000 (13:53 -0400)] 
Add `bt2c::ValReq` class template system

This set of class templates makes it possible to get basic requirement
classes to validate JSON-like value objects, that is, a system of null,
boolean, unsigned/signed integer, real, string, array, and object value
objects.

All the class templates accept a `ValT` parameter which is the base type
of the objects to validate, as well as `ValOpsT`, a structure which
defines specific value operations. See the `bt2c::ValReq` class template
comment to learn the requirements of `ValOpsT`.

Having class templates will make it possible to create both:

• JSON value requirements, to validate a CTF2‑SPEC‑2.0 [1] metadata
  stream within the `ctf` plugin.

• libbabeltrace2 value object (`bt2::ConstValue`) requirements, to
  validate component initialization parameters, for example.

A value requirement (`bt2c::ValReq` instance; omitting the namespace for
the rest of this message) is an object which offers the validate()
method to validate some value object.

The current concrete requirement class templates are (validating some
value V):

`ValHasTypeReq`:
`AnyIntValReq`:
`UIntValReq`:
    Validates the type of V.

`SIntValReq`:
    Validates the type of V (unsigned or signed integer) and that the
    raw value of V is between -9,223,372,036,854,775,808 and
    9,223,372,036,854,775,807.

`IntValInRangeReq`:
    Validates the type of V and that the raw value of the integer value
    object V is within a given range.

`ScalarValInSetReq`:
    Validates the type of V and that the raw value of the scalar value
    object V is an element of a given set.

`ArrayValReq`:
    Validates the type of V, that the size of V is within a given range,
    and, optionally, that all the elements of V satisfy a given value
    requirement.

`ObjValReq`:
    Validates the type of V and that the properties of V satisfy a given
    set of property requirements (no missing mandatory property, no
    unknown property if not allowed, valid property value).

ValReq::validate() throws `TextParseError` using the text location
of the value (provided by `ValOpsT`) to validate when it fails.

`ArrayValReq` and `ObjValReq` accept zero or more shared value
requirements: a user of this API may extend `ValReq` to create a custom
value requirement (just implement the virtual _validate() method). A
custom value requirement may reuse existing value requirements
internally.

Each value requirement class C has its static shared() method which
accepts the same parameters as the constructor(s) of C and returns a
`ValReq::SP` instance. Those shared() methods are helpers to make the
usage site clearer, for example (assuming some custom aliases for
specific value object types):

    MyUIntValInRangeReq::shared(0, 255)

    // vs.

    std::make_shared<MyUIntValInRangeReq>(0, 255)

Of course this system is not meant to semantically validate some value.
Even JSON Schema [2], which barectf pushes to its limit for example [3],
cannot do that. But those value requirement classes can certainly remove
a lot of redundant code.

Here are a few examples of value requirement object construction and
corresponding error messages to grasp how to use this API (assume some
custom aliases starting with `Json`):

Simple type check:
    Code:
        JsonValHasTypeReq {ValType::Str}

    Error example:
        [1:1] Expecting a string.

Exactly `true`:
    Code:
        JsonBoolValInSetReq {true}

    Error examples:
        [1:1] Expecting a boolean.

        [1:1] Unexpected value `false`: expecting `true`.

Byte:
    Code:
        JsonUIntValInRangeReq {0, 255}

    Error examples:
        [1:1] Expecting an unsigned integer.

        [1:1] Integer 256 is too large: expecting at most 255.

Display base:
    Code:
        JsonUIntValInSetReq {{2, 8, 10, 16}}

    Error examples:
        [1:1] Expecting an unsigned integer.

        [1:1] Unexpected value 5: expecting 2, 8, 10, or 16.

Choice amongst three strings:
    Code:
        JsonStrValInSetReq {JsonStrValInSetReq::Set {
            "Patrick", "Alec", "Annie"
        }}

    Error examples:
        [1:1] Expecting a string.

        [1:1] Unexpected value `Yves`: expecting `Alec`, `Annie`, or
              `Patrick`.

CTF 2 UUID:
    Code:
        JsonArrayValReq {
            16,
            JsonUIntValInRangeReq::shared(0, 255)
        }

    Error examples:
        [1:1] Expecting an array.

        [1:1] Size of array (2) is too small: expecting at least 16
              elements.

        [1:1] Size of array (19) is too large: expecting at most 16
              elements.

        [1:36] In array element #11:
        [1:36] Expecting an unsigned integer.

        [1:42] In array element #13:
        [1:42] Integer 257 is too large: expecting at most 255.

CTF2-SPECRC-5.0 field location:
    Code:
        JsonArrayValReq {
            2, nonstd::nullopt,
            JsonValHasTypeReq::shared(ValType::Str)
        }

    Error examples:
        [1:1] Expecting an array.

        [1:1] Size of array (1) is too small: expecting at least 2
              elements.

        [1:11] In array element #2:
        [1:11] Expecting a string.

CTF2-SPECRC-5.0 clock class fragment:
    Code:
        JsonObjValReq {
            {
                {"type", {
                    JsonStrValInSetReq::shared("clock-class"),
                    true
                }},

                {"frequency", {
                    JsonUIntValInRangeReq::shared(1, nonstd::nullopt),
                    true
                }},

                {"name", {
                    JsonValHasTypeReq::shared(ValType::Str)
                }},

                {"description", {
                    JsonValHasTypeReq::shared(ValType::Str)
                }},

                {"uuid", {
                    JsonArrayValReq::shared(
                        16,
                        JsonUIntValInRangeReq::shared(0, 255)
                    )
                }},

                {"origin-is-unix-epoch", {
                    JsonValHasTypeReq::shared(ValType::Bool)
                }},

                {"offset", {
                    JsonObjValReq::shared({
                        {"seconds", {
                            JsonValHasTypeReq::shared(ValType::UInt)
                        }},

                        {"cycles", {
                            JsonValHasTypeReq::shared(ValType::UInt)
                        }},
                    })
                }},

                {"precision", {
                    JsonValHasTypeReq::shared(ValType::UInt)
                }},

                {"user-attributes", {
                    JsonValHasTypeReq::shared(ValType::Obj)
                }},

                {"extensions", {
                    JsonValHasTypeReq::shared(ValType::Obj)
                }},
            }
        }

    Error examples:
        [1:1] Expecting an object.

        [1:1] Missing mandatory object property `type`.

        [1:1] Missing mandatory object property `frequency`.

        [1:22] Unknown object property `meow`.

        [1:10] In object property `type`:
        [1:10] Unexpected value `salut`: expecting `clock-class`.

        [1:38] In object property `frequency`:
        [1:32] Expecting an unsigned integer.

        [1:54] In object property `offset`:
        [1:63] Unknown object property `meow`.

        [1:54] In object property `offset`:
        [1:66] In object property `seconds`:
        [1:66] Expecting an unsigned integer.

        [1:50] In object property `uuid`:
        [1:63] In array element #5:
        [1:63] Integer 301 is too large: expecting at most 255.

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html
[2]: https://json-schema.org/
[3]: https://github.com/efficios/barectf/tree/stable-3.0/barectf/schemas/config

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

2 weeks agoplugins: make text and utils component classes report support for MIP 1
Simon Marchi [Tue, 28 Nov 2023 05:18:52 +0000 (00:18 -0500)] 
plugins: make text and utils component classes report support for MIP 1

Make the following component classes report they support MIP 1
(everything from the text and utils plugins):

 - sink.text.details
 - source.text.dmesg
 - sink.text.pretty
 - sink.utils.counter
 - sink.utils.dummy
 - filter.utils.muxer
 - filter.utils.trimmer

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

2 weeks agosrc.text.pretty: handle BLOB fields
Simon Marchi [Fri, 11 Mar 2022 20:56:09 +0000 (15:56 -0500)] 
src.text.pretty: handle BLOB fields

Make the `src.text.pretty` components handle BLOB fields, by naively
printing all bytes in hex (without a 0x prefix).  Example output:

    da-ec-name: { blob_without_len = { 23 69 6e 63 6c 75 64 65 20 3c } }

It would be nice to limit the number of bytes dumped (and provide an
option to control it), because at some point it's useless for the user
to dump thousands of bytes on one line.  But this is enough to say that
the `src.text.pretty` component class supports BLOB field classes (and
MIP 1).

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

2 weeks agograph/mip: make bt_get_greatest_operative_mip_version compute operative MIP version
Simon Marchi [Fri, 9 Feb 2024 21:25:24 +0000 (16:25 -0500)] 
graph/mip: make bt_get_greatest_operative_mip_version compute operative MIP version

bt_get_greatest_operative_mip_version is currently implemented assuming
that the only existing MIP version is 0.  It only checks that all
component descriptors support version 0, and then returns 0 as the
computed operative MIP version.

Since the library now supports MIP versions 0 and 1,
bt_get_greatest_operative_mip_version needs to actually compute the
greatest commonly supported version.  Implement something that will work
for any number of MIP versions.

Change validate_operative_mip_version_in_array to
get_supported_mip_version_ranges, make it is solely reponsible for
calling the component class' get_supported_mip_versions method and
append the resulting range set to the `supported_ranges` array.  Or, if
the component class doesn't implement that method, append a range set
with only `[0, 0]`.

Once this is done, we have an array with range sets representing the
supported MIP versions for each soon-to-be component.  Compute (in the
new function find_greatest_compatible_mip_version) the greatest commonly
supported version, if any.

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

2 weeks agosink.text.details: handle missing variant field class option name
Philippe Proulx [Tue, 17 May 2022 17:50:07 +0000 (13:50 -0400)] 
sink.text.details: handle missing variant field class option name

Starting with MIP 1, a variant field class option name is optional.
Handle this in `write.c`, showing "Unnamed" with the
"none"/"missing"/"empty" color.

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

2 weeks agosink.text.details: show event class namespace
Simon Marchi [Wed, 9 Mar 2022 16:47:04 +0000 (11:47 -0500)] 
sink.text.details: show event class namespace

If the event class has namespace (a property introduced with MIP 1),
show it when dumping the event class info.

Example output:

    Event class `da-ec-name` (Namespace `da-ec-namespace`, ID 0):

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

2 weeks agosink.text.details: show stream class namespace
Simon Marchi [Wed, 9 Mar 2022 16:47:04 +0000 (11:47 -0500)] 
sink.text.details: show stream class namespace

If the stream class has a namespace (a property introduced with MIP 1),
show it when dumping the stream class info.

Add a `with-stream-class-namespace` parameter to the component class,
controlling whether to show the namespace or not.

Example output:

    Trace class:
      Stream class `da-name` (Namespace `da-namespace`, ID 0):

Philippe updated the manual page to document the
`with-stream-class-namespace` parameter.

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

2 weeks agosink.text.details: handle BLOB field class type
Simon Marchi [Sat, 5 Mar 2022 03:28:14 +0000 (22:28 -0500)] 
sink.text.details: handle BLOB field class type

Make the `sink.text.details` component class handle the BLOB field class
type, introduced in MIP 1.

When dumping the field class details, print the names of the new field
classes.  For the static BLOB field class, print the static length
value (similar to static arrays).

For BLOB fields:

 - if it is empty, print "Empty" (like a few other existing field kinds)
 - if it is not empty, print bytes as hex (without the 0x prefix), 16
   bytes per line.  This is similar to what `od -t x1` outputs, minus
   the address/offset column.

The output looks like this.  The field class part:

        static_blob: Static BLOB (Length 1)
        blob_without_len: Dynamic BLOB (no length field)
        blob_with_len: Dynamic BLOB (with length field)

The field part:

    static_blob: Length 1:
      fe
    blob_without_len: Length 2048:
      46 72 6f 6d 20 36 34 64 62 36 31 36 36 35 65 32
      38 62 62 63 39 63 62 64 32 62 64 32 62 34 39 31
      <snip>
    blob_with_len: Empty

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

2 weeks agosink.text.details: handle field classes with field locations
Simon Marchi [Fri, 4 Mar 2022 21:46:09 +0000 (16:46 -0500)] 
sink.text.details: handle field classes with field locations

Handle MIP 1 variant, option and dynamic array field classes.  They
have field locations instead of field paths.

The format used by write_field_location is based on write_field_path.

Change-Id: Ic2f6e1ed233a34ea4cc647f50eaf4027b9e5bff8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7500
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12691

2 weeks agolib: make variant field class option name optional with MIP > 0
Philippe Proulx [Tue, 17 May 2022 17:46:52 +0000 (13:46 -0400)] 
lib: make variant field class option name optional with MIP > 0

CTF2-SPEC-2.0 [1] calls for optionally named variant field class
option, therefore libbabeltrace2 should support this.

Before this patch, having a variant field class option name is a
precondition. This patch relaxes said precondition when the MIP version
is greater than zero.

Note that a structure field member class must still have a name.

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

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

2 weeks agolib: add namespace property to event classes
Simon Marchi [Tue, 7 May 2024 20:01:42 +0000 (16:01 -0400)] 
lib: add namespace property to event classes

Add the namespace property to event classes, with the intent to support
namespace properties on event record classes in CTF2‑SPEC‑2.0 [1].

Copy everything from the existing name property, and rename it to
"namespace."

Both new public functions have a `MIP >= 1` pre-condition check.

Philippe updated the documentation.

[1] https://diamon.org/ctf/CTF2-SPEC-2.0.html

Change-Id: I644446087b6071f2ccc70027b079615f3a33a2a7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7381
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12689

2 weeks agolib: add namespace property to stream classes
Simon Marchi [Tue, 7 May 2024 19:51:03 +0000 (15:51 -0400)] 
lib: add namespace property to stream classes

Add the namespace property to stream classes, with the intent to support
namespace properties on data stream classes in CTF2‑SPEC‑2.0 [1].

Copy everything from the existing name property, and rename it to
"namespace."

Both new public functions have a `MIP >= 1` pre-condition check.

Philippe updated the documentation.

[1] https://diamon.org/ctf/CTF2-SPEC-2.0.html

Change-Id: Ibdfc9c924fc6347f5020c5ba06f14a7737cbf76b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7380
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12688

2 weeks agolib: add BLOB field class types
Simon Marchi [Tue, 22 Feb 2022 00:54:51 +0000 (19:54 -0500)] 
lib: add BLOB field class types

Add support for BLOB field classes and fields, with the intent of
supporting CTF2‑SPEC‑2.0's BLOB field class types [1].

A BLOB is a sequence of binary data included as-is in the trace.

A BLOB field class has a media type property, which describes the kind
of content its instances hold.

There are three variations of a BLOB field class, analogous to the array
field classes:

 - static length BLOB
 - dynamic length BLOB without a length field
 - dynamic length BLOB with a length field

Static length BLOBs have a fixed length, set in the field class.

Dynamic length BLOBs have a variable length, set in each field instance
of the field class.

Dynamic length BLOBs with a length field have a length field location,
set in the field class, pointing to a preceding field that holds the
length of the BLOB.

Philippe updated the documentation.

[1] https://diamon.org/ctf/CTF2-SPEC-2.0.html#blob-fc

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

2 weeks agosrc/cpp-common: add bt2c::bt2ValueFromJsonVal() function
Philippe Proulx [Fri, 8 Dec 2023 20:55:05 +0000 (20:55 +0000)] 
src/cpp-common: add bt2c::bt2ValueFromJsonVal() function

This patch adds the bt2c::bt2ValueFromJsonVal() function which
converts a JSON value object (`bt2c::JsonVal`) to a Babeltrace 2
value object (`bt2::Value::Shared`, wrapping a shared `bt_value *`).

The JSON value classes are a superset of the Babeltrace 2 value ones:
there's a dedicated `bt2c::JsonNullVal` class, whereas
libbabeltrace2 uses a null value singleton, and `bt2c::JsonVal`
has a text location member.

This is part of an effort to support CTF2‑SPEC‑2.0 [1]. This function
will be useful to convert JSON user attributes to Babeltrace 2 values
directly (this step doesn't need validation).

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

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

2 weeks agosrc/cpp-common: make `bt2c::JsonVal` visitable
Philippe Proulx [Tue, 21 May 2024 16:52:08 +0000 (12:52 -0400)] 
src/cpp-common: make `bt2c::JsonVal` visitable

This patch adds the bt2c::JsonVal::accept() method which accepts a JSON
value visitor (`bt2c::JsonValVisitor`), dispatching to the virtual
bt2c::JsonVal::_accept() method.

This is part of an effort to support CTF2‑SPEC‑2.0 [1].

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I75462799f9433ee868b618ecba4ba63b5822b96c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7485
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12685

2 weeks agosrc/cpp-common: add bt2c::parseJson() functions (value mode)
Philippe Proulx [Sun, 10 Dec 2023 05:18:46 +0000 (05:18 +0000)] 
src/cpp-common: add bt2c::parseJson() functions (value mode)

This patch adds two new versions of bt2c::parseJson() which accept the
same parameters as the current "listener mode" versions, except for a
missing listener, and return some resulting
JSON value (`bt2c::JsonVal`).

This is part of an effort to support CTF2‑SPEC‑2.0 [1]. It will be
easier to convert CTF 2 metadata stream fragments using JSON value
objects than using the listener mode version of bt2c::parseJson()
directly.

`baseOffset` is also added to the offset of a text location when
creating the text location of any JSON value object to create. This will
be needed when parsing a CTF 2 fragment: the line and column numbers are
local to the fragment, but the offset is from the beginning of the whole
metadata stream. Kind of confusing, but I wouldn't know what an RS byte
means in terms of lines/columns anyway (different text editor could
interpret it in different ways).

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3e9662f6632d10f11c08c178342785886f664797
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7480
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12684

2 weeks agosrc/cpp-common: add `bt2c::JsonVal` class and derived classes
Philippe Proulx [Fri, 8 Dec 2023 18:32:28 +0000 (18:32 +0000)] 
src/cpp-common: add `bt2c::JsonVal` class and derived classes

This patch adds a simple set of classes to contain decoded JSON values.

All the new classes inherit the abstract base `JsonVal`. A `JsonVal`
instance contains its type (enumeration) as well as a text location
(`TextLoc`) which indicates where the JSON value is located within some
original JSON text.

The complete class hierarchy is:

    JsonVal
      JsonNullVal
      JsonBoolVal
      JsonSIntVal
      JsonUIntVal
      JsonRealVal
      JsonStrVal
      JsonCompoundVal (template)
        ArrayJsonVal
        ObjJsonVal

In reality, `JsonNullVal`, `JsonBoolVal`, `JsonSIntVal`, `JsonUIntVal`,
`JsonRealVal`, and `JsonStrVal` are aliases of `JsonScalarVal` with
specific template parameters.

Each of the classes above has its own inner `UP` alias which is the type
of a unique pointer to a specific `const` JSON value.

`json-val.hpp` also offers various createJsonVal() functions which rely
on their parameter count and types to create specific JSON values.

Here's a simple usage example using default text locations:

    bt2c::JsonArrayVal::Container vals;

    // Append JSON signed integer value
    vals.push_back(bt2c::createJsonVal(23LL, bt2c::TextLoc {}));

    // Append JSON boolean value
    vals.push_back(bt2c::createJsonVal(true, bt2c::TextLoc {}));

    // Append JSON null value
    vals.push_back(bt2c::createJsonVal(bt2c::TextLoc {}));

    // Append JSON string value
    vals.push_back(bt2c::createJsonVal("salut la gang",
                                       bt2c::TextLoc {}));

    // Create JSON array value, moving `vals`
    auto arrayJsonVal = bt2c::createJsonVal(std::move(vals),
                                            bt2c::TextLoc {});

    // Inspect JSON array value, printing only JSON signed int. values
    for (auto& val : *arrayJsonVal) {
        // Type of `val` is `const Json::UP&`
        if (val->isSInt()) {
            std::cout << *val->asSInt() << std::endl;
        }
    }

This is part of an effort to support CTF2‑SPEC‑2.0 [1]. It will be
easier to convert CTF 2 metadata stream fragments using JSON value
objects than using the listener mode version of bt2c::parseJson()
directly.

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

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

2 weeks agosrc/cpp-common: add bt2c::parseJson() functions (listener mode)
Philippe Proulx [Fri, 8 Dec 2023 18:30:18 +0000 (18:30 +0000)] 
src/cpp-common: add bt2c::parseJson() functions (listener mode)

This patch adds the bt2c::parseJson() functions in `parse-json.hpp`.

Those functions wrap the file-internal `bt2c::internal::JsonParser`
class of which an instance can parse a single JSON value, calling
specific methods of a JSON event listener as it processes. Internally,
`bt2c::internal::JsonParser` uses a string scanner (`bt2c::StrScanner`).

In searching for a simple JSON parsing solution, I could not find, as of
this date, any project which satisfies the following requirements out of
the box:

• Is well known, well documented, and well tested.

• Has an MIT-compatible license.

• Parses both unsigned and signed 64-bit integers (range
  -9,223,372,036,854,775,808 to 18,446,744,073,709,551,615).

• Provides an exact text location (offset, line number, column number)
  on parsing error (through logging and the message of an error cause).

• Provides an exact text location (offset, line number, column number)
  for each parsed value.

I believe the text locations are essential as this JSON parser will be
used to decode CTF2‑SPEC‑2.0 [1] metadata streams: because Babeltrace 2
will be a reference implementation of CTF 2, it makes sense to make an
effort to pinpoint the exact location of syntactic and semantic errors.

More specifically:

• JSON for Modern C++ (by Niels Lohmann) [2] doesn't support text
  location access, although there's a pending pull request (draft as of
  this date) to add such support [3].

• The exceptions of JsonCpp [4] don't contain a text location, only
  a message.

• SimpleJSON [5] doesn't offer text location access and seems to be an
  archived project.

• RapidJSON [6] doesn't offer text location access.

• yajl [7] could offer some form of text location access (offset, at
  least) with yajl_get_bytes_consumed(), remembering the last offset on
  our side, although I don't know how nice it would play
  with whitespaces.

  That being said, regarding integers, the `yajl_callbacks`
  structure [8] only contains a `yajl_integer` function pointer which
  receives a `long long` value (no direct 64-bit unsigned integer
  support). It's possible to set the `yajl_number` callback for any
  number, but the `yajl_double` callback gets disabled in that case, and
  the callback receives a string which needs further parsing on our
  side: this is pretty much what's implemented `bt2c::StrScanner`
  anyway.

At this point I stopped searching as I already had a working and tested
string scanner and, as you can see, without comments, `parse-json.hpp`
is only 231 lines of effective code and satisfies all the
requirements above.

You can test bt2c::parseJson() with a simple program like this:

    #include <iostream>
    #include <cstring>

    #include "parse-json.hpp"

    struct Printer
    {
        void onNull(const bt2c::TextLoc&)
        {
            std::cout << "null\n";
        }

        template <typename ValT>
        void onScalarVal(const ValT& val, const bt2c::TextLoc&)
        {
            std::cout << val << '\n';
        }

        void onArrayBegin(const bt2c::TextLoc&)
        {
            std::cout << "[\n";
        }

        void onArrayEnd(const bt2c::TextLoc&)
        {
            std::cout << "]\n";
        }

        void onObjBegin(const bt2c::TextLoc&)
        {
            std::cout << "{\n";
        }

        void onObjKey(const std::string& key,
                      const bt2c::TextLoc&)
        {
            std::cout << key << ": ";
        }

        void onObjEnd(const bt2c::TextLoc&)
        {
            std::cout << "}\n";
        }
    };

    int main(const int, const char * const * const argv)
    {
        Printer printer;

        bt2c::parseJson(argv[1], printer);
    }

Then:

    $ ./test-parse-json 23
    $ ./test-parse-json '"\u03c9 represents angular velocity"'
    $ ./test-parse-json '{"salut": [23, true, 42.4e-9, {"meow": null}]}'
    $ ./test-parse-json 18446744073709551615
    $ ./test-parse-json -9223372036854775808

Also try some parsing errors:

    $ ./test-parse-json '{"salut": [false, 42.4e-9, "meow": null}]}'
    $ ./test-parse-json 18446744073709551616
    $ ./test-parse-json -9223372036854775809
    $ ./test-parse-json '"invalid \u8dkf codepoint"'

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html
[2]: https://github.com/nlohmann/json
[3]: https://github.com/nlohmann/json/pull/3165
[4]: https://github.com/open-source-parsers/jsoncpp
[5]: https://github.com/nbsdx/SimpleJSON
[6]: https://rapidjson.org/
[7]: https://github.com/lloyd/yajl
[8]: https://lloyd.github.io/yajl/yajl-2.1.0/structyajl__callbacks.html

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

2 weeks agosrc/cpp-common: add `bt2c::StrScanner` class
Philippe Proulx [Fri, 27 Oct 2023 19:21:05 +0000 (19:21 +0000)] 
src/cpp-common: add `bt2c::StrScanner` class

This patch adds the `bt2c::StrScanner` class, defined in
`str-scanner.hpp` and implemented in `str-scanner.cpp`.

A string scanner is a simple lexical scanner. This one is a
stripped-down version of yactfr's `yactfr::internal::StrScanner`,
stripped-down because yactfr uses this to parse TSDL, therefore it needs
more features.

What's left for the `bt2c::StrScanner` version is:

tryScanLitStr():
    Tries to scan a double-quoted literal string, possibly containing
    escape sequences.

tryScanConstInt():
    Tries to scan a constant unsigned or signed decimal integer string.

tryScanConstReal():
    Tries to scan a real number string.

tryScanToken():
    Tries to scan an exact string.

skipWhitespaces():
    Skips the next whitespaces.

See the specific comments in `str-scanner.hpp` for more details.

I could have used the `GScanner` API [1], as we do to parse the value of
the `--params` CLI option of `babeltrace2`, but:

• `yactfr::internal::StrScanner` is already working, tested,
  and documented.

  `bt2c::StrScanner` is a much lighter version of it.

• Should we ever make an effort to remove the GLib dependency, this part
  will already be done.

• The `GScanner` API doesn't support `\u` escape sequences in literal
  strings (needed for JSON strings) out of the box, so we'd need this
  part on our side anyway.

`bt2c::StrScanner` could eventually replace `GScanner` elsewhere in the
tree, but it would require a few more features (which already exist
in `yactfr::internal::StrScanner`, that is).

This is part of an effort to implement a JSON parser to
support CTF2‑SPEC‑2.0 [2].

[1]: https://docs.gtk.org/glib/struct.Scanner.html
[2]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

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

2 weeks agocpp-common/bt2c: add `Regex`
Simon Marchi [Fri, 31 May 2024 19:40:15 +0000 (15:40 -0400)] 
cpp-common/bt2c: add `Regex`

Add `Regex`, a class wrapping some features of `GRegex` (from glib).

The constructor aborts if the regex pattern fails to compile.  There is
a single `match()` method that returns whether or not the given string
matches the regex.

Change-Id: Ia4cb1542efa91fcf3849d82d047c871d9bf2dbd2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12837
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agocpp-common/bt2c/logging.hpp: add text location logging
Simon Marchi [Mon, 27 May 2024 14:08:01 +0000 (10:08 -0400)] 
cpp-common/bt2c/logging.hpp: add text location logging

This patch makes a `bt2c::Logger` instance hold a text location string
format (`bt2c::TextLocStrFmt`) and adds the logTextLoc(),
logErrorTextLocAndThrow(), and logErrorTextLocAndRethrow() methods which
accept a text location (`bt2c::TextLoc`) and make its equivalent
formatted string a prefix of the log message, for example:

    [13:38 @ 4776 bytes] Failed to parse this and that.

Because the text location string format member is specific to the text
location logging methods, it has an arbitrary default value
(`TextLocStrFmt::LineColNosAndOffset`) at construction time. You may
change it at any time with the textLocStrFmt() method.

Also adding the typical BT_CPPLOG*() macros to use the new methods with
`__FILE__`, `__func__`, and `__LINE__`.

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

2 weeks agosrc/cpp-common: add bt2c::textLocStr() function
Philippe Proulx [Fri, 8 Dec 2023 18:28:53 +0000 (18:28 +0000)] 
src/cpp-common: add bt2c::textLocStr() function

This new function formats a text location (`bt2c::TextLoc`) according
to some format amongst:

`bt2c::TextLocStrFmt::Offset`:
    Offset only.

`bt2c::TextLocStrFmt::LineColNosAndOffset`:
    Line/column numbers and offset.

`bt2c::TextLocStrFmt::LineColNos`:
    Line/column numbers only.

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

2 weeks agosrc/cpp-common: add `bt2c::TextLoc` class
Philippe Proulx [Wed, 17 Apr 2024 17:49:55 +0000 (13:49 -0400)] 
src/cpp-common: add `bt2c::TextLoc` class

This patch adds the `bt2c::TextLoc` class, defined in `text-loc.hpp` and
implemented in `text-loc.cpp`.

A text location is a location within some text: an offset (in bytes), a
line number, and a column number.

This is part of an effort to implement a JSON parser to
support CTF2‑SPEC‑2.0 [1].

[1]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

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

2 weeks agolib: add enum bt_resolve_field_xref_status
Simon Marchi [Wed, 16 Feb 2022 17:28:53 +0000 (12:28 -0500)] 
lib: add enum bt_resolve_field_xref_status

Add the bt_resolve_field_xref_status enumeration, and use it throughout
the resolve-field-path.c file to make error handling more explicit, and
clearer, in my opinion.

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

2 weeks agolib: rename bt_resolve_field_path_context to bt_resolve_field_xref_context
Simon Marchi [Fri, 9 Feb 2024 21:24:07 +0000 (16:24 -0500)] 
lib: rename bt_resolve_field_path_context to bt_resolve_field_xref_context

In preparation to sharing some code with the field location resolving,
rename bt_resolve_field_path_context to bt_resolve_field_xref_context,
which will be used by both kinds of field cross-reference resolving.
Move it to its own file, which will be included by both.

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

2 weeks agolib: add new clock class origin API
Simon Marchi [Thu, 23 May 2024 20:23:40 +0000 (16:23 -0400)] 
lib: add new clock class origin API

Add the new API set define the origin of clock classes.  The origin is
now defined as a (namespace, name, unique-id) tuple.

If all three tuple elements are NULL, it means the origin is unknown or
undefined.  Otherwise, the origin is defined, and the name and unique-id
be non-NULL (namespace may be NULL).  There is one well-known origin,
the UNIX epoch, which is represented with the tuple
("babeltrace.org,2020", "unix-epoch", "").

The new API functions are (the numbers in square brackets represent the
MIP versions where these functions are allowed):

 - bt_clock_class_set_origin_unknown [0, 1]
 - bt_clock_class_set_origin_unix_epoch [0, 1]
 - bt_clock_class_set_origin [1]
 - bt_clock_class_get_origin_namespace [1]
 - bt_clock_class_get_origin_name [1]
 - bt_clock_class_get_origin_uid [1]

The existing function bt_clock_class_set_origin_is_unix_epoch (which
accepts a boolean) can still be used with MIP 1.  If passed true, it is
equivalent to bt_clock_class_set_origin_unix_epoch.  If passed false, it
is equivalent to bt_clock_class_set_origin_unknown.

The existing function bt_clock_class_origin_is_unix_epoch can still be
used with MIP 1.

Implementation-wise, replace the origin_is_unix_epoch boolean in struct
clock_class with the tuple of three strings.  The behavior of the API
for MIP 0 doesn't change, even if the underlying implementation does.
With MIP 0, the user is still restricted to set or get whether the
origin is the UNIX epoch or is unknown, and can't access the individual
components of the origin.

Philippe updated the documentation.

Change-Id: I1225b89a679952e877583ec8147008928a16eb45
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12677
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agolib: restrict bt_clock_class_{g,s}et_uuid to MIP 0
Simon Marchi [Fri, 5 May 2023 17:44:25 +0000 (13:44 -0400)] 
lib: restrict bt_clock_class_{g,s}et_uuid to MIP 0

Change-Id: Id689c9b470f03837355216a56e8e44b2724fd7cd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12676
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agolib: record MIP version in clock class
Simon Marchi [Fri, 5 May 2023 17:41:02 +0000 (13:41 -0400)] 
lib: record MIP version in clock class

Record the graph's MIP version in struct bt_clock_class, so that we can
check in in clock class API functions.

Change-Id: I88b6a2f79c24706a5e9eae9199ff7c3862afc0dc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12675
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agolib: add bt_trace_{get,set}_uid
Simon Marchi [Thu, 23 May 2024 20:23:06 +0000 (16:23 -0400)] 
lib: add bt_trace_{get,set}_uid

In MIP 1, the trace UID replaces the trace UUID.  A trace UID is an
arbitrary string.  When the trace UID is unset, its value is NULL.

 - Add bt_trace_get_uid and bt_trace_set_uid, to be used with MIP >= 1.

 - Make bt_trace_get_uuid and bt_trace_set_uuid only available with
   MIP == 0.

 - Add BT_ASSERT_PRE_UID_NON_NULL, for use in bt_trace_set_uid.

 - Handle the trace UID in lib-logging.c:format_trace.

 - Free the UID in destroy_trace.

Philippe updated the documentation.

Change-Id: I3d84a9e6f04d632d187c8adfc4d625ce4c4357c0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9972
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agolib: add field location-related functions
Simon Marchi [Thu, 23 May 2024 20:22:52 +0000 (16:22 -0400)] 
lib: add field location-related functions

For each API function accepting a bt_field_class to refer to a length or
selector field, to create a variant, dynamic array or option field
class, add one or more equivalent ones accepting a bt_field_location.
For symmetry between the various field classes, go with separate
functions for "with" and "without" length/selector field locations,
rather than having one function that can take a NULL field location.

Add functions to borrow a field location from a variant, option or
dynamic array field class.

All the new functions have preconditions to require MIP version >= 1.
All the old functions dealing with field paths have preconditions to
require MIP version == 0.

Philippe updated the documentation.

Variants
--------

The existing bt_field_class_variant_create function deduces the type of
variant (without selector, with unsigned int selector, with signed int
selector) by looking at the selector field class' type.  This is not
possible by looking at a selector field location, since the field
class(es) the field location points to is/are not known at this time.
So, introduce three new functions to create a variant field class
(without, with unsigned, with signed).

Dynamic arrays
--------------

For symmetry with the other field classes, go with two separate
functions for with a length field location and without a length field
location, rather than a single function that can accept a NULL field
location.

Options
-------

For consistency in the naming with the other field classes, add the
bt_field_class_option_without_selector_field_location_create function.
It is functionally equivalent to the existing
bt_field_class_option_without_selector_create function.  Add three other
functions to match the three existing ones (with bool, with unsigned,
with signed).

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

2 weeks agolib: add logging format specifier for bt_field_location
Simon Marchi [Thu, 2 Nov 2023 19:58:28 +0000 (19:58 +0000)] 
lib: add logging format specifier for bt_field_location

Add the `format_field_location` function, to format a bt_field_location
object in logging messages.  Add the format specifier `L`, to format
bt_field_location objects in lib-logging format strings.

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

2 weeks agolib: add field location API
Simon Marchi [Fri, 27 Oct 2023 19:18:06 +0000 (19:18 +0000)] 
lib: add field location API

Add API functions to create field location objects.

Field locations are created using bt_field_location_create.  The caller
must pass a trace class, which is used to verify that the MIP version
of the graph is >= 1.  The caller passes a (root) scope, and an array of
components, which are the names to get from the root of the scope to the
desired field.

Accessor functions are:

 - bt_field_location_get_scope
 - bt_field_location_get_component_count
 - bt_field_location_get_component_by_index

They are intended to be used by a component consuming a trace.

Philippe updated the documentation.

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

2 weeks agolib: add MIP 1 pre-conditions for functions taking a selector / length field class
Simon Marchi [Mon, 29 Jan 2024 17:04:24 +0000 (17:04 +0000)] 
lib: add MIP 1 pre-conditions for functions taking a selector / length field class

MIP 1 deprecates referring to selector and length fields by passing a
field class pointer.

Add pre-condition checks for all functions that accept a selector or
length field class, to verify that the graph's MIP version is 0.

Add new macros in assert-cond.h to check for MIP version equality.

Philippe updated the documentation.

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

2 weeks agolib: record effective MIP version in field and trace classes
Simon Marchi [Sat, 5 Feb 2022 03:19:50 +0000 (22:19 -0500)] 
lib: record effective MIP version in field and trace classes

We will need access to the MIP version in order to add MIP version
preconditions in various functions.

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

2 weeks agolib: increase maximal MIP version number
Simon Marchi [Thu, 30 Jun 2022 17:15:24 +0000 (13:15 -0400)] 
lib: increase maximal MIP version number

We are going to introduce MIP version 1, so adjust
bt_get_maximal_mip_version accordingly.

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

2 weeks agoctf: silence some -Wnull-dereference errors
Simon Marchi [Fri, 24 May 2024 21:16:16 +0000 (17:16 -0400)] 
ctf: silence some -Wnull-dereference errors

Building with gcc 14.1.1 (Arch Linux package 14.1.1+r58+gfc9fb69ad62-1),
I get some `-Wnull-dereference` errors that seem bogus:

      CXX      plugins/ctf/fs-src/fs.lo
    In file included from /usr/include/c++/14.1.1/memory:78,
                     from /home/simark/src/babeltrace/src/cpp-common/bt2c/glib-up.hpp:10,
                     from /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:19:
    In member function 'std::__uniq_ptr_impl<_Tp, _Dp>::pointer std::__uniq_ptr_impl<_Tp, _Dp>::release() [with _Tp = ctf_fs_trace; _Dp = std::default_delete<ctf_fs_trace>]',
        inlined from 'std::__uniq_ptr_impl<_Tp, _Dp>& std::__uniq_ptr_impl<_Tp, _Dp>::operator=(std::__uniq_ptr_impl<_Tp, _Dp>&&) [with _Tp = ctf_fs_trace; _Dp = std::default_delete<ctf_fs_trace>]' at /usr/include/c++/14.1.1/bits/unique_ptr.h:185:7,
        inlined from 'std::__uniq_ptr_data<_Tp, _Dp, <anonymous>, <anonymous> >& std::__uniq_ptr_data<_Tp, _Dp, <anonymous>, <anonymous> >::operator=(std::__uniq_ptr_data<_Tp, _Dp, <anonymous>, <anonymous> >&&) [with _Tp = ctf_fs_trace; _Dp = std::default_delete<ctf_fs_trace>; bool <anonymous> = true; bool <anonymous> = true]' at /usr/include/c++/14.1.1/bits/unique_ptr.h:237:24,
        inlined from 'std::unique_ptr<_Tp, _Dp>& std::unique_ptr<_Tp, _Dp>::operator=(std::unique_ptr<_Tp, _Dp>&&) [with _Tp = ctf_fs_trace; _Dp = std::default_delete<ctf_fs_trace>]' at /usr/include/c++/14.1.1/bits/unique_ptr.h:408:19,
        inlined from 'int ctf_fs_component_create_ctf_fs_trace(ctf_fs_component*, bt2::ConstArrayValue, const char*, bt_self_component*)' at /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:1415:44:
    /usr/include/c++/14.1.1/bits/unique_ptr.h:211:17: error: potential null pointer dereference [-Werror=null-dereference]
      211 |         pointer __p = _M_ptr();
          |                 ^~~

      CXX      plugins/ctf/lttng-live/viewer-connection.lo
    In file included from /usr/include/c++/14.1.1/bits/stl_tempbuf.h:61,
                     from /usr/include/c++/14.1.1/memory:66,
                     from /home/simark/src/babeltrace/src/cpp-common/bt2s/make-unique.hpp:10,
                     from /home/simark/src/babeltrace/src/plugins/ctf/lttng-live/viewer-connection.cpp:16:
    In function 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = char; _Args = {}]',
        inlined from 'static _ForwardIterator std::__uninitialized_default_n_1<true>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = char*; _Size = long unsigned int]' at /usr/include/c++/14.1.1/bits/stl_uninitialized.h:666:23,
        inlined from 'static _ForwardIterator std::__uninitialized_default_n_1<true>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = char*; _Size = long unsigned int]' at /usr/include/c++/14.1.1/bits/stl_uninitialized.h:660:9,
        inlined from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = char*; _Size = long unsigned int]' at /usr/include/c++/14.1.1/bits/stl_uninitialized.h:712:20,
        inlined from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = char*; _Size = long unsigned int; _Tp = char]' at /usr/include/c++/14.1.1/bits/stl_uninitialized.h:779:44,
        inlined from 'void std::vector<_Tp, _Alloc>::_M_default_append(size_type) [with _Tp = char; _Alloc = std::allocator<char>]' at /usr/include/c++/14.1.1/bits/vector.tcc:863:35,
        inlined from 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = char; _Alloc = std::allocator<char>]' at /usr/include/c++/14.1.1/bits/stl_vector.h:1016:21,
        inlined from 'lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet(lttng_live_trace*, std::vector<char>&)' at /home/simark/src/babeltrace/src/plugins/ctf/lttng-live/viewer-connection.cpp:1028:16:
    /usr/include/c++/14.1.1/bits/stl_construct.h:119:7: error: null pointer dereference [-Werror=null-dereference]
      119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
          |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Silence the warning at these specific spots to get the build going.

Change-Id: Ia46b4f420cfdd00202d0b915825ac3b995128291
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12776
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agotests/lib: convert `test-plugins` to C++
Simon Marchi [Fri, 31 May 2024 17:08:18 +0000 (13:08 -0400)] 
tests/lib: convert `test-plugins` to C++

Convert the code to C++.  Re-write using the bt2 wrappers, use {fmt} for
string formatting.

Change-Id: I9b1925d6a2143ed1e23a5d1c0f70e35f143ff206
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12828
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agotests/lib: compile `test-plugins` as C++
Simon Marchi [Fri, 31 May 2024 17:06:03 +0000 (13:06 -0400)] 
tests/lib: compile `test-plugins` as C++

Change-Id: Iecc2fcb29c0b2f4405739c9e0964094ebdf8886d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12832
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agocpp-common/bt2: add shared() methods on component classes
Simon Marchi [Fri, 31 May 2024 20:08:00 +0000 (16:08 -0400)] 
cpp-common/bt2: add shared() methods on component classes

Change-Id: I5d2e264904bb54b65a41fb0dfe653fb7eb3e54b2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12838
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 weeks agocpp-common/bt2c: add {fmt} formatter for `bt2::ConstValue`
Simon Marchi [Fri, 31 May 2024 17:02:28 +0000 (13:02 -0400)] 
cpp-common/bt2c: add {fmt} formatter for `bt2::ConstValue`

I found this useful for debugging, but I suppose it could be used for
logging as well.

Change-Id: I83b8af3ed706c64f2f66347cf085d0291c9c09fe
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12831
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agocpp-common/bt2: add `findAllPluginsFromFile()`
Simon Marchi [Fri, 31 May 2024 17:01:46 +0000 (13:01 -0400)] 
cpp-common/bt2: add `findAllPluginsFromFile()`

Add `findAllPluginsFromFile()`, a wrapper around
`bt_plugin_find_all_from_file()`.

Change-Id: I4794afe368dcb99c4c2441de58d9497d2cf40f38
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12830
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agoFix: cpp-common/bt2: make QueryExecutor take ConstValue params
Simon Marchi [Fri, 31 May 2024 16:32:14 +0000 (12:32 -0400)] 
Fix: cpp-common/bt2: make QueryExecutor take ConstValue params

Query executors can take values of any kind, not specifically map
values.  From the doc [1]:

    Unlike the params parameter of the
    bt_graph_add_*_component_*_port_added_listener() functions (see
    Graph), this parameter does not need to be a map value.

Change `ConstMapValue` to `ConstValue`.

[1] https://babeltrace.org/docs/v2.0/libbabeltrace2/group__api-qexec.html#gafb5d324988c2870d66d96c1eeda6f87a

Change-Id: I370182c4aa5df8957c025f59018e359463674156
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12829
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 weeks agocpp-common/bt2: add plugin accessors to `bt2::ConstPluginSet`
Simon Marchi [Fri, 31 May 2024 13:54:21 +0000 (09:54 -0400)] 
cpp-common/bt2: add plugin accessors to `bt2::ConstPluginSet`

Add the functionality to index and iterate a plugin set to get
plugins.

Change-Id: Ibfece01a234813a7571f26fd6b00cc4e319689a5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12827
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agotests: remove problematic (and unnecessary) type annotation
Simon Marchi [Thu, 30 May 2024 18:12:22 +0000 (14:12 -0400)] 
tests: remove problematic (and unnecessary) type annotation

With Python 3.4, we get:

    smarchi@ci-node-sles12sp5-amd64-1b-01:~/src/babeltrace> tests/utils/run-in-py-env.sh /usr/bin/python3 /home/smarchi/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py /home/smarchi/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/list-sessions.json --port-file /tmp/test-live-list-sessions-server-port.AYNVeY --trace-path-prefix /home/smarchi/src/babeltrace/tests/data/ctf-traces
      File "/home/smarchi/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py", line 807
        self._creation_timestamp: int = creation_timestamp
                                ^
    SyntaxError: invalid syntax

This annotation is not necessary anyway, it can be inferred from the
right-hand side.

Change-Id: Ia613b1e6d2d2a7e5d7629f847db71b440a35d1fb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12809
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
2 months agoChange syntax of some initialization lists to please g++ 4.8
Simon Marchi [Wed, 29 May 2024 19:49:09 +0000 (15:49 -0400)] 
Change syntax of some initialization lists to please g++ 4.8

Fixes errors of this kind:

      CXX      plugins/ctf/fs-src/data-stream-file.lo
    In file included from /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/data-stream-file.cpp:20:0:
    /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/data-stream-file.hpp: In constructor 'ctf_fs_ds_file_group::ctf_fs_ds_file_group(ctf_fs_trace*, ctf_stream_class*, uint64_t, ctf_fs_ds_index)':
    /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/data-stream-file.hpp:129:88: error: could not convert 'std::move<ctf_fs_ds_index&>((* & indexParam))' from 'std::remove_reference<ctf_fs_ds_index&>::type {aka ctf_fs_ds_index}' to 'std::vector<ctf_fs_ds_index_entry>'
             stream_id(streamInstanceId), ctf_fs_trace {trace}, index {std::move(indexParam)}
                                                                                            ^

It looks like g++ 4.8 thinks that we want to initialize the fields of
`ctf_fs_ds_index`, instead of calling the constructor.

Change-Id: I0c081506d75de4c5556917d7be85f079f6bd996d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12795
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 months agocpp-common/bt2c: adjust syntax of operator"" to please g++ 4.8
Simon Marchi [Tue, 28 May 2024 15:55:17 +0000 (11:55 -0400)] 
cpp-common/bt2c: adjust syntax of operator"" to please g++ 4.8

Fixes:

      CXX      plugins/ctf/fs-src/data-stream-file.lo
    In file included from /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/data-stream-file.hpp:20:0,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/data-stream-file.cpp:20:
    /home/smarchi/src/babeltrace/src/cpp-common/bt2c/data-len.hpp:179:23: error: missing space between '""' and suffix identifier
     static inline DataLen operator""_bits(const unsigned long long val) noexcept
                           ^

Change-Id: Iab7ab1273f13dd55735310f786a0bb4df63c967c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12794
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 months ago.gitignore: add some more IDE / tools related file
Simon Marchi [Fri, 24 May 2024 16:40:53 +0000 (12:40 -0400)] 
.gitignore: add some more IDE / tools related file

Change-Id: I223c98e0b94dceb879dbf9273e7bc3c23e17f780
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12774
Tested-by: jenkins <jenkins@lttng.org>
3 months agoRe-format with clang-format 16
Simon Marchi [Thu, 9 May 2024 15:16:40 +0000 (11:16 -0400)] 
Re-format with clang-format 16

Change-Id: I5ea29c62b4fb8be6cd00acae8e75b4fa6c292325
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12536
Tested-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 months agoNormalize C/C++ include guards
Simon Marchi [Tue, 14 May 2024 18:26:37 +0000 (14:26 -0400)] 
Normalize C/C++ include guards

Fix all C/C++ include guards so that they satisfy
`tools/check-include-guard.py`:

    $ tools/check-include-guards.sh &> /dev/null && echo 🎆
    🎆

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

3 months agotools: add include guard check script
Simon Marchi [Tue, 14 May 2024 18:08:23 +0000 (14:08 -0400)] 
tools: add include guard check script

Add `tools/check-include-guard.py`, whose task is to verify that the
include guards in a given file is formatted as we want.  Example:

    $ ./tools/check-include-guard.py ./src/plugins/ctf/fs-sink/fs-sink-trace.hpp
    In `#ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_TRACE_H` include guard line: expecting `#ifndef BABELTRACE_PLUGINS_CTF_FS_SINK_FS_SINK_TRACE_HPP`

`tools/check-include-guard.py` supports the `--fix` option, which makes
it try to fix the include guards in-place (mostly useful for that
initial pass where we have a lot of stuff to fix).

Add `tools/check-include-guards.sh`, whose task is to find all the
files we want to check include guards for, and call
`tools/check-include-guard.py` on them.

Limitations:

 - Only tested on GNU/Linux

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

4 months agodoc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab
Philippe Proulx [Mon, 13 May 2024 17:08:50 +0000 (13:08 -0400)] 
doc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab

It looks like the Doxygen project decided [1] to use the "topic"
terminology instead of "module" to avoid confusion with C++20 modules.

Add a `topics` tab to `DoxygenLayout.xml` because otherwise that
navigation tab won't show up.

Leaving `modules` for older Doxygen versions.

Also changing all the "module" terms to "API"/"page" in the actual
documentation to completely part from the old "module" Doxygen concept.

[1]: https://github.com/doxygen/doxygen/commit/6d80fc7e5d03c259b1a7280972e0b28884217655

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

4 months agotest-field.sh: make sure bt_run_in_py_env() and bt_cli() succeed
Philippe Proulx [Thu, 9 May 2024 04:48:35 +0000 (00:48 -0400)] 
test-field.sh: make sure bt_run_in_py_env() and bt_cli() succeed

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I26c033a56d2c214087db058bdc19d20312a6f0e1
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12535
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agotests/utils/utils.sh: bt_diff(): validate that both files exist
Philippe Proulx [Thu, 9 May 2024 04:44:34 +0000 (00:44 -0400)] 
tests/utils/utils.sh: bt_diff(): validate that both files exist

Otherwise bt_diff() returns 0 (happy) with a nonexistent file.

This change reveals that `tests/plugins/src.ctf.fs/field/test-field.sh`
passes, but for the wrong reason: run_python() doesn't exist (I replaced
it with bt_run_in_py_env() a while ago), therefore that line doesn't
create any expectation file and bt_diff() returns 0. Change it to
use bt_run_in_py_env().

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I259123f5c0946ece7f58e4ef185313bf26354b46
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12534
Tested-by: jenkins <jenkins@lttng.org>
4 months agocommon: remove `prio-heap.{c,h}`
Simon Marchi [Thu, 9 May 2024 16:03:58 +0000 (12:03 -0400)] 
common: remove `prio-heap.{c,h}`

Change-Id: Iec4f0a14efceb21aa67bedd58153e14bdd9662d9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12538
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocommon: remove `BT_MOVE_REF`
Simon Marchi [Thu, 9 May 2024 16:03:31 +0000 (12:03 -0400)] 
common: remove `BT_MOVE_REF`

Change-Id: I458cbcdf8829a99f3290e0d76db2e13c23b1776f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12537
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agolib: remove some unnecessary uses of `GString`
Simon Marchi [Mon, 6 May 2024 18:59:50 +0000 (14:59 -0400)] 
lib: remove some unnecessary uses of `GString`

The use of `GString` is unnecessary for these fields.  In fact, I think
it just makes things more complicated for nothing.  Change to use
`gchar *`, allocated with `g_strdup()` and freed with `g_free()`.

Change-Id: I03c6662e97d9cad6e0395fa1e3b29154604e786e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12523
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agospan-lite: backport fix to avoid -Wundef error in C++20
Simon Marchi [Mon, 6 May 2024 19:58:14 +0000 (15:58 -0400)] 
span-lite: backport fix to avoid -Wundef error in C++20

When building babeltrace as C++20, I get:

      CXX      clock-correlation-validator/clock-correlation-validator.lo
    In file included from /home/smarchi/src/babeltrace/src/cpp-common/bt2s/span.hpp:18,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2c/logging.hpp:25,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/component-class-dev.hpp:15,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/component-class.hpp:15,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/error.hpp:20,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/wrap.hpp:15,
                     from /home/smarchi/src/babeltrace/src/clock-correlation-validator/clock-correlation-validator.cpp:9:
    /home/smarchi/src/babeltrace/src/cpp-common/vendor/span-lite/span.hpp:43:33: error: "span_HAVE_STRUCT_BINDING" is not defined, evaluates to 0 [-Werror=undef]
       43 | #define span_HAVE( feature )  ( span_HAVE_##feature )
          |                                 ^~~~~~~~~~
    /home/smarchi/src/babeltrace/src/cpp-common/vendor/span-lite/span.hpp:1873:5: note: in expansion of macro 'span_HAVE'
     1873 | #if span_HAVE( STRUCT_BINDING )
          |     ^~~~~~~~~

Backport commit b8921715cd71 ("Guard section for tuple interface to only
use with nonstd::span; fixes #84 (thanks @simark)") from the upstream
repo [1]

[1] https://github.com/martinmoene/span-lite/commit/b8921715cd71997bdab120a8ced526b78d300196

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

4 months agosrc.ctf.fs: remove stray `}` in fmt format string
Simon Marchi [Mon, 6 May 2024 19:59:49 +0000 (15:59 -0400)] 
src.ctf.fs: remove stray `}` in fmt format string

Found by compiling as C++20:

    /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/query.cpp:76:9:   in 'constexpr' expansion of 'fmt::v10::basic_format_string<char, const bt2c::CStringView&>(("Cannot create metadata decoder: path=\"{}}\"."))'
    ...
     2509 |           return handler_.on_error("unmatched '}' in format string");
          |                  ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I75b1429857638a00cfd18202061689710e8ea304
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12524
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2c/logging.hpp: change type of `fmt` parameters to `fmt::format_string`
Simon Marchi [Mon, 29 Apr 2024 19:45:47 +0000 (19:45 +0000)] 
cpp-common/bt2c/logging.hpp: change type of `fmt` parameters to `fmt::format_string`

When compiled as C++20, this will enable doing some compile-time checks
of fmt format strings.  I don't think there will be a negative impact
when building as C++11.

Even though `fmt::format_string` is lightweight (it consists of just a
string view), I chose to `std::move` it when passing it across
functions, even if it doesn't change anything today.  It's not our type,
so it is subject to change without us knowing, perhaps it will gain a
move constructor one day.

Change-Id: Ib8761d4249c6c10b9978f7177f219914b6782f76
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12498
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
Simon Marchi [Mon, 29 Apr 2024 19:42:14 +0000 (19:42 +0000)] 
cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition

wise_enum uses `const char *` as the string type for C++11/14 and
`std::string_view` for C++ >= 17.  Change `EnableIfIsWiseEnum` to use
`wise_enum::string_type` instead of a hard-coded `const char *`, to make
compilation in C++17 possible.

Change-Id: Ie179e1f5585128950ecdc095f7b136d93ea39e41
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12497
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agobt2c::Logger: remove unused cLevel() method
Philippe Proulx [Thu, 25 Apr 2024 19:27:02 +0000 (15:27 -0400)] 
bt2c::Logger: remove unused cLevel() method

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I59fb2fd48bb2166b725d8236bbf113f2fe993f99
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12485
Tested-by: jenkins <jenkins@lttng.org>
4 months ago.clang-tidy: add some checks
Simon Marchi [Thu, 25 Apr 2024 14:56:54 +0000 (14:56 +0000)] 
.clang-tidy: add some checks

These checks seem reasonable, enable them.

Change-Id: I4ed416a9deee2385af38c305a125cd616ec94aa0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12482
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agobt2::CommonEnumerationFieldClass::addMapping(): add missing static assertion
Philippe Proulx [Mon, 18 Mar 2024 21:20:34 +0000 (17:20 -0400)] 
bt2::CommonEnumerationFieldClass::addMapping(): add missing static assertion

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

4 months agocpp-common/bt2c/logging.hpp: remove no-formatting ("str") alternatives
Philippe Proulx [Thu, 25 Apr 2024 04:05:09 +0000 (00:05 -0400)] 
cpp-common/bt2c/logging.hpp: remove no-formatting ("str") alternatives

This patch removes everything named bt2c::Logger::log*Str*() and
BT_CPPLOG*STR*().

The no-formatting versions existed to avoid a call to fmt::format_to()
when you need to log a literal string as is, without any formatting. It
was also useful to pass a user string as is.

However, in the end, I don't think such an optimization is necessary:

• We don't use the no-formatting versions that much compared to messages
  with a format string.

• fmt::format_to() is pretty fast without any replacement field.

• We're talking about logging performance.

• This patch removes a lot of often redudant code from `logging.hpp`.

Adapt the current no-formatting logging calls accordingly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie02ea492e220c7ce9b72aaf8728fb7d2211e0bc0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12479
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agoFix: cpp-common/bt2c/logging.hpp: add missing `template` keyword
Philippe Proulx [Wed, 24 Apr 2024 21:11:48 +0000 (17:11 -0400)] 
Fix: cpp-common/bt2c/logging.hpp: add missing `template` keyword

In very specific contexts, it's possible that a `bt2c::Logger` reference
is a dependent type, for example:

    template <typename T>
    struct X
    {
        const bt2c::Logger& logger() const noexcept
        {
            return /* some logger reference */;
        }

        void log()
        {
            BT_CPPLOGI_SPEC(this->logger(), "Hello!");
        }
    };

In that case, the BT_CPPLOGI_SPEC() macro eventually expands to
something like:

    this->logger().log<bt2c::Logger::Level::Info,
                       false>(__FILE__, __func__, __LINE__, "Hello!");

`this->logger()` is basically `X<T>::logger()`. Therefore, from the
log() method template point of view, the type of `this` depends on `T`,
that is, it's a dependent name. This example above won't build.

In that case, we need the `template` keyword to call the method:

    this->logger().template log<bt2c::Logger::Level::Info,
                                false>(__FILE__, __func__,
                                       __LINE__, "Hello!");

Using the `template` keyword or not would normally be a per-call
decision, but those BT_CPPLOG*() macros do the call themselves.

Knowing this, this patch adds the `template` keyword to all the logging
method calls from the BT_CPPLOG*() macros, just in case.

The current project builds because it doesn't have this specific
situation, but it could happen in the future.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2847105746825d94cf71ed3abbd56fac0f160a2d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12477
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agoKeep a single `.gitignore` file
Philippe Proulx [Wed, 24 Apr 2024 07:00:19 +0000 (03:00 -0400)] 
Keep a single `.gitignore` file

We have a few arbitrary directory-specific `.gitignore` files and I'd
like to keep things consistent here: either dedicated `.gitignore` files
or a single root `.gitignore` file.

Choose the latter as it's simpler to maintain.

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

4 months ago.gitignore: categorize rules and sort them per category
Philippe Proulx [Wed, 24 Apr 2024 06:51:27 +0000 (02:51 -0400)] 
.gitignore: categorize rules and sort them per category

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

4 months ago.gitignore: ignore all `*.egg-info`
Philippe Proulx [Wed, 24 Apr 2024 06:30:52 +0000 (02:30 -0400)] 
.gitignore: ignore all `*.egg-info`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I804bbb158ba2ccb5dbe326b4eb12d5e13d06c62a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12469
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months ago.gitignore: ignore all `/src/plugins/ctf/[...]/tsdl/parser.*pp`
Philippe Proulx [Wed, 24 Apr 2024 06:30:20 +0000 (02:30 -0400)] 
.gitignore: ignore all `/src/plugins/ctf/[...]/tsdl/parser.*pp`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3d8e45d6a8482552d11c7292ddcdb21514e683b9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12468
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months ago.gitignore: ignore all `/src/cli/*.bin`
Philippe Proulx [Wed, 24 Apr 2024 06:28:33 +0000 (02:28 -0400)] 
.gitignore: ignore all `/src/cli/*.bin`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie1c0138d2a1d766c386b4c237545b21a9903c027
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12467
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months ago.gitignore: cleanup test files
Philippe Proulx [Wed, 24 Apr 2024 06:25:33 +0000 (02:25 -0400)] 
.gitignore: cleanup test files

Given that, under the `tests` directory:

✔ All shell file names end with `.sh`.
✔ All C file names end with `.c` or `.h`.
✔ All C++ file names end with `.cpp` or `.hpp`.
✔ No Python file name contains `-`.

Then it's safe to ignore everything named `test-` except the files of
which the name ends with one of the extensions above.

Also sort the list of remaining specific file names.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2a4d541bd9624ed48051c944789c0b5f075a917b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12466
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agotests: test_dwarf.c: initialize `tag` variable
Simon Marchi [Wed, 24 Apr 2024 19:45:50 +0000 (15:45 -0400)] 
tests: test_dwarf.c: initialize `tag` variable

On Arch Linux, When configuring with:

    $ /home/smarchi/src/babeltrace/configure CFLAGS='-O2 -flto=auto' LDFLAGS='-flto=auto'

I get:

      CCLD     test_dwarf
    In function 'test_bt_dwarf',
        inlined from 'main' at /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:163:2:
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:136:9: error: 'tag' may be used uninitialized [-Werror=maybe-uninitialized]
      136 |         ok(tag == DW_TAG_typedef, "bt_dwarf_die_get_tag - correct tag value");
          |         ^
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c: In function 'main':
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:79:22: note: 'tag' was declared here
       79 |         int fd, ret, tag;
          |                      ^

Indeed, `tag` is not set if `bt_dwarf_die_get_tag()` fails, and I
suppose that LTO is able to "see" through the function call, despite the
implementation being in another compilation unit.

Fix this by initializing `tag` to an invalid DIE tag value.

For some reason, I only see this error on the stable-2.0 branch, not on
master.  But I think it wouldn't hurt to merge this patch to both master
and stable-2.0.

I caught this when trying to build the 2.0.6 release as an Arch package,
using the official PKGBUILD as a base.

[1] https://gitlab.archlinux.org/archlinux/packaging/packages/babeltrace2/-/blob/d6c58a3a8e0dbbbac7424dec28212f0fd1720eb7/PKGBUILD

Change-Id: I5475efdf095511404ecf8a214ab33358b41230fa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12473
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2c: remove `dummy.cpp`
Simon Marchi [Wed, 17 Apr 2024 17:45:47 +0000 (13:45 -0400)] 
cpp-common/bt2c: remove `dummy.cpp`

There is another source file (file-utils.cpp), so dummy.cpp is no longer
needed.

Change-Id: I7429a005c49498d6d2e500c5afe4b3d07640d654
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12413
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months ago.gitignore: add missing test binaries
Philippe Proulx [Tue, 23 Apr 2024 17:02:48 +0000 (13:02 -0400)] 
.gitignore: add missing test binaries

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

4 months agobt2c/logging.hpp: use `std::span<const std::uint8_t>` for mem. data
Philippe Proulx [Tue, 23 Apr 2024 17:07:55 +0000 (13:07 -0400)] 
bt2c/logging.hpp: use `std::span<const std::uint8_t>` for mem. data

`std::span<const std::uint8_t>` is also the `bt2c::Logger::MemData`
alias.

Adapt `src/plugins/ctf/common/src/msg-iter/msg-iter.cpp` accordingly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I553c0bbb0fb532bd23506a9760155371820e773d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12456
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agoCONTRIBUTING.adoc: mention bt2c::makeSpan()
Philippe Proulx [Tue, 23 Apr 2024 16:50:13 +0000 (12:50 -0400)] 
CONTRIBUTING.adoc: mention bt2c::makeSpan()

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6b5340fd353cbd4ef40f9e75322588842f10a788
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12455
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agosrc/cpp-common/bt2c: rename `span.hpp` -> `make-span.hpp`
Philippe Proulx [Tue, 23 Apr 2024 16:49:05 +0000 (12:49 -0400)] 
src/cpp-common/bt2c: rename `span.hpp` -> `make-span.hpp`

bt2c::makeSpan() is the only thing `make-span.hpp` offers.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3a4a9cb0712cc97d11e9c9adf26f77539f5bb76c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12454
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agoCONTRIBUTING.adoc: "make_unique" -> "make-unique"
Philippe Proulx [Tue, 23 Apr 2024 16:40:57 +0000 (12:40 -0400)] 
CONTRIBUTING.adoc: "make_unique" -> "make-unique"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2528ff4bfbb0cb101e34373d36a50b4b27100f1c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12453
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2c/logging.hpp: use camel case for param. names
Philippe Proulx [Tue, 23 Apr 2024 16:15:12 +0000 (12:15 -0400)] 
cpp-common/bt2c/logging.hpp: use camel case for param. names

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1d73559b1512d60d9e0ed87870cb8f375138e3d0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12452
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agobt2c::Logger: make `Level` enumerators more readable
Philippe Proulx [Tue, 23 Apr 2024 16:13:07 +0000 (12:13 -0400)] 
bt2c::Logger: make `Level` enumerators more readable

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7f69a587af353446a25392684b85939afe8d1210
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12451
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agotests: LD_PRELOAD libstdc++.so in bt_run_in_py_env
Simon Marchi [Tue, 23 Apr 2024 03:44:04 +0000 (23:44 -0400)] 
tests: LD_PRELOAD libstdc++.so in bt_run_in_py_env

With an ASan build on Debian 12 or Ubuntu 22.04 (and probably others),
some tests (test-query-trace-info.sh, test-python-bt2.sh), fail because
of what boils down to this:

    $ /home/smarchi/src/babeltrace/tests/utils/run-in-py-env.sh  python3 /home/smarchi/src/babeltrace/tests/plugins/src.ctf.fs/query/test_query_trace_info.py
    ..AddressSanitizer: CHECK failed: asan_interceptors.cpp:320 "((__interception::real___cxa_throw)) != (0)" (0x0, 0x0) (tid=139166)
        #0 0x7fc2bbf9b2aa in CheckUnwind ../../../../src/libsanitizer/asan/asan_rtl.cpp:67
        #1 0x7fc2bbfbbc55 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:86
        #2 0x7fc2bbf22924 in __interceptor___cxa_throw ../../../../src/libsanitizer/asan/asan_interceptors.cpp:320
        #3 0x7fc2b8f5ea05 in void bt2c::Logger::logErrorAndThrow<true, bt2c::Error, char*&>(char const*, char const*, unsigned int, char const*, char*&) const /home/smarchi/src/babeltrace/src/cpp-common/bt2c/logging.hpp:316
        #4 0x7fc2b8f5ea05 in read_src_fs_parameters(bt2::CommonMapValue<bt_value const>, bt2c::Logger const&) /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:1516
        #5 0x7fc2b903e4ca in trace_infos_query(bt2::CommonMapValue<bt_value const>, bt2c::Logger const&) /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/query.cpp:168
        #6 0x7fc2b9019206 in ctf_fs_query(bt_self_component_class_source*, bt_private_query_executor*, char const*, bt_value const*, void*, bt_value const**) /home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:1609
        #7 0x7fc2b980eed0 in bt_query_executor_query /home/smarchi/src/babeltrace/src/lib/graph/query-executor.c:221
        #8 0x7fc2ba2d8c86 in _wrap_query_executor_query bt2/native_bt.c:19262
        #9 0x5458a2 in cfunction_vectorcall_O ../Objects/methodobject.c:514
... lots of Python stack frames ...
        #75 0x64f90e in pymain_run_file_obj ../Modules/main.c:360
        #76 0x64f90e in pymain_run_file ../Modules/main.c:379
        #77 0x64f90e in pymain_run_python ../Modules/main.c:601
        #78 0x64f90e in Py_RunMain ../Modules/main.c:680
        #79 0x6275c6 in Py_BytesMain ../Modules/main.c:734
        #80 0x7fc2bbbf0249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
        #81 0x7fc2bbbf0304 in __libc_start_main_impl ../csu/libc-start.c:360
        #82 0x627460 in _start (/usr/bin/python3.11+0x627460)

The problem is documented here [1].

The summary is (to the best of my understanding):

 - we run python3 with a script that imports the bt2 Python module,
   which eventually loads libbabeltrace2.so
 - libbabeltrace2.so is built with ASan, so depends on libasan.so
 - if we just try to run this as is, libasan.so complains that it's not
   the first loaded shared library, so we LD_PRELOAD it
 - now, when libasan.so is initialized, libstdc++ is not loaded, so some
   things related to C++ (like the __interception::real___cxa_throw
   variable) are not initialized
 - libbabeltrace2.so and libstdc++.so are eventually loaded, something
   in the test happens to throw an exception
 - this is intercepted by libasan.so (through symbol interposition of
   __cxa_throw I suppose)
 - the assertion that real___cxa_throw must not be NULL fails

Debian and Ubuntu systems are affected because of their use of
-Wl,--as-needed.  The build system of ASan makes libasan.so link against
libstdc++ (to ensure that libstdc++ is loaded along with libasan.so),
but that dependency is dropped du to -Wl,--as-needed.

A solution I used during development (and this is why I failed to see
the problem sooner I suppose) was to add a libstdc++ dependency in
/usr/bin/python3.  This is obviously not possible at large.

The only applicable solution I see to keep ASan builds working is to
LD_PRELOAD libstdc++.so along with libasan.so.  This emulates the
missing libasan.so -> libstdc++.so dependency.

[1] https://github.com/google/sanitizers/issues/934

Change-Id: I10c53347167a7f68cb2fb2e8c08a98ff2b638ffc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12446
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: remove some goto error-handling
Simon Marchi [Thu, 7 Dec 2023 17:00:23 +0000 (17:00 +0000)] 
src.ctf.lttng-live: remove some goto error-handling

Change-Id: I9b6d967d54c63d7f7544bb0d1a1eb778a8df64d4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12396
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: viewer-connection.cpp: remove goto error-handling
Simon Marchi [Tue, 26 Mar 2024 19:47:31 +0000 (15:47 -0400)] 
src.ctf.lttng-live: viewer-connection.cpp: remove goto error-handling

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I87b05835a268fef92f906c16bb35a84c1df0a27f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8485
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12395
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: use viewer_connection_close_socket more
Simon Marchi [Thu, 7 Dec 2023 16:36:41 +0000 (16:36 +0000)] 
src.ctf.lttng-live: use viewer_connection_close_socket more

Use viewer_connection_close_socket at all spots we close the control
socket, to de-duplicate code a little bit.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I47ce5bf00edd367792a8f8262d746a61b0c474fd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8484
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12394
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: make queries report errors with exceptions
Simon Marchi [Tue, 12 Dec 2023 16:32:37 +0000 (16:32 +0000)] 
src.ctf.lttng-live: make queries report errors with exceptions

Change-Id: Ibf633312304a6353842baa569860a2e1216785b0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8478
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12393
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: make queries output a bt2::Value
Simon Marchi [Thu, 7 Dec 2023 16:12:49 +0000 (16:12 +0000)] 
src.ctf.lttng-live: make queries output a bt2::Value

Change-Id: If0baec1ca712e75e5873cc6c3e88cec18bb4f424
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8477
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12392
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: use C++ value wrappers for query parameters
Simon Marchi [Tue, 12 Dec 2023 16:28:06 +0000 (16:28 +0000)] 
src.ctf.lttng-live: use C++ value wrappers for query parameters

Change-Id: Ie64cef32650dbc62238429b10c30a0c8ffd5dac3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8476
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12391
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: add bt_common_lttng_live_url_parts_deleter
Simon Marchi [Thu, 2 Nov 2023 18:57:32 +0000 (18:57 +0000)] 
src.ctf.lttng-live: add bt_common_lttng_live_url_parts_deleter

bt_common_lttng_live_url_parts can't be made a C++ object that
automatically manages its memory yet, since it's used in
babeltrace2-cfg-cli-args.c (C code).  Add an RAII type in lttng-live to
automatically call bt_common_destroy_lttng_live_url_parts in two places.

Change-Id: I233a5ba5a2829f4577c4ebbcc1ab0e630d039174
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8475
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12390
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: introduce lttng_live_msg_iter::UP and use it
Simon Marchi [Thu, 7 Dec 2023 15:53:32 +0000 (15:53 +0000)] 
src.ctf.lttng-live: introduce lttng_live_msg_iter::UP and use it

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ie87efb7a6599a738dad60cc3533f8440c283da6c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8474
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12389
Tested-by: jenkins <jenkins@lttng.org>
5 months agosrc.ctf.lttng-live: add lttng_live_msg_iter destructor
Simon Marchi [Thu, 7 Dec 2023 15:49:29 +0000 (15:49 +0000)] 
src.ctf.lttng-live: add lttng_live_msg_iter destructor

Convert lttng_live_msg_iter_destroy to a destructor.

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