deliverable/babeltrace.git
2 years agocpp-common: add SharedObj::release
Simon Marchi [Sat, 28 May 2022 14:01:44 +0000 (10:01 -0400)] 
cpp-common: add SharedObj::release

It will sometimes be needed to extract the ownership of a lib object
from a SharedObj, and get the underlying lib object pointer.  For
example:

 - The value returned by queries
 - Messages returned by iterators

Add a SharedObj::release method for that.  The return type is a borrowed
object (e.g. bt2::Value::Shared::release returns a bt2::Value), but
conceptually the caller then owns the reference and is responsible for
manually managing it.

After a release, a Shared object becomes invalid, same as when it is moved
from.

Change-Id: Id31855512b8dd3d5223f2e759ff48f81ceadbfbf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8169
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf: use unique_ptr to manage ctf_metadata_decoder lifetime
Simon Marchi [Tue, 26 Jul 2022 21:00:01 +0000 (17:00 -0400)] 
ctf: use unique_ptr to manage ctf_metadata_decoder lifetime

Introduce the ctf_metadata_decoder_up type, a unique_ptr with a deleter
that calls ctf_metadata_decoder_destroy.  Change
ctf_metadata_decoder_create to return a ctf_metadata_decoder_up, and
adjust callers / callees accordingly.

Note that this is temporary, ctf_metadata_decoder is going to be deleted
in a future refactor.  But in the mean time, it helps make the callers
use RAII and become more exception-safe.

Change-Id: Ia0e24b425c47b90dc71b10d1c7fd0a3000c89180
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8167
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: manage lifetime of open file with FileUP
Simon Marchi [Tue, 26 Jul 2022 20:59:25 +0000 (16:59 -0400)] 
src.ctf.fs: manage lifetime of open file with FileUP

Change-Id: Ic1c5d8be3761e449a154e1fd8cc1f0ec7c957197
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8173
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add FileUP
Simon Marchi [Sat, 28 May 2022 18:18:17 +0000 (14:18 -0400)] 
cpp-common: add FileUP

Add a unique_ptr type to manage the lifetime of a `FILE *`, with a
custom deleter that calls fclose.

Change-Id: Idded4546d2a709cd0652975ef83c3ad6a0f511bc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8172
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: use GCharUP to hold metadata path
Simon Marchi [Sat, 28 May 2022 18:15:14 +0000 (14:15 -0400)] 
src.ctf.fs: use GCharUP to hold metadata path

Change-Id: I2cf43f7da567da3af2786a87026e25272925ed6f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8171
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: make ctf_fs_make_port_name return a GCharUP
Simon Marchi [Tue, 26 Jul 2022 20:59:09 +0000 (16:59 -0400)] 
src.ctf.fs: make ctf_fs_make_port_name return a GCharUP

Introduce GCharUP, a unique_ptr type with a deleter that calls g_free.
It can be used to manage g_char buffer allocated by GLib.

Make ctf_fs_make_port_name return a GCharUP, which then helps use
automatic memory management in the callers.

Change-Id: I9191ddbafa86a4788fc5e16fc561dfda7696cfa6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8166
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add GCharUP
Simon Marchi [Sat, 28 May 2022 14:36:08 +0000 (10:36 -0400)] 
cpp-common: add GCharUP

Add GCharUP, a unique_ptr type that wraps a g_char pointer and has a
deleter that calls g_free.  It can be used to provide automatic memory
management of buffers returned by the GLib API.

Change-Id: I9d98be2f972cc008877b55a20eceeb3dce256cdb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8170
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: use unique_ptr to manage ctf_fs_component lifetime
Simon Marchi [Fri, 10 Jun 2022 16:41:15 +0000 (12:41 -0400)] 
src.ctf.fs: use unique_ptr to manage ctf_fs_component lifetime

Define ctf_fs_component::UP to be a unique_ptr with a deleter that calls
ctf_fs_destroy.  Change ctf_fs_component_create to return a
ctf_fs_component::UP and adjust the appropriate callers / callees.

Move where the ctf_fs_component instance is assigned as the "data" of
the self component.  Make it so it's assigned in ctf_fs_init (the
component initialization entry point), as the very last step.  This way,
ctf_fs_create can return a unique_ptr, and there's no ambiguity on who
owns the ctf_fs_component instance at any given time, and what happens
in case of failure.

Change-Id: I3ab1d70b0e7aa7772b7fa09deec70db7ea5a022c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8164
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf: use unique_ptr to manage ctf_visitor_generate_ir lifetime
Simon Marchi [Tue, 26 Jul 2022 20:58:53 +0000 (16:58 -0400)] 
ctf: use unique_ptr to manage ctf_visitor_generate_ir lifetime

Define ctf_visitor_generate_ir::UP as a unique_ptr type with a custome
deleter that calls ctf_visitor_generate_ir_destroy.  Make
ctf_visitor_generate_ir_create return a ctf_visitor_generate_ir::UP and
adjust relevant callers / callees.

Change-Id: I9db22bd66e69473e67c2571e0b2bb7682863cff7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8163
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf: move ctf_visitor_generate_ir to header file
Simon Marchi [Sat, 28 May 2022 01:51:27 +0000 (21:51 -0400)] 
ctf: move ctf_visitor_generate_ir to header file

Move ctf_visitor_generate_ir to the `ast.h` header file, the header file
containing all the declarations for the CTF 1 metadata visitors.  This
will allow exposing it as a proper C++ class and remove the accessor
functions.

Change-Id: Ic13494d0040ee9e2214ecca45d8ea2e7b75ec4fa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8162
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common/bt2: use classes from `cpp-common/exc.hpp`
Philippe Proulx [Mon, 30 May 2022 11:46:26 +0000 (07:46 -0400)] 
cpp-common/bt2: use classes from `cpp-common/exc.hpp`

This patch:

* Renames `lib-error.hpp` to `exc.hpp` as this could contain non-error
  exceptions in the future.

* Changes `bt2::Error`, `bt2::MemoryError`, and `bt2::OverflowError` to
  be aliases of `bt2_common::Error`, `bt2_common::MemoryError`, and
  `bt2_common::OverflowError`.

  This makes it possible for some code to catch only the common
  `bt2_common` errors to handle both library and user/internal
  exceptions.

  Note that those exceptions don't carry much information themselves;
  they're usually just a signal that an exception occurred, while the
  details are part of the libbabeltrace2 error of the current thread.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5bc1d39c8d978c21604614c68012509edc1776d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8176
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoAdd `bt2_common::OverflowError`
Philippe Proulx [Mon, 30 May 2022 11:41:01 +0000 (07:41 -0400)] 
Add `bt2_common::OverflowError`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c524bed2374b7472e5603740c1c146f49371fe5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8175
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoctf: add try/catch at entry points
Simon Marchi [Wed, 3 Aug 2022 01:29:22 +0000 (21:29 -0400)] 
ctf: add try/catch at entry points

Add try / catch at the entry points of the CTF component classes to
convert thrown exceptions in the proper statuses.  The handled
exceptions are:

 - std::bad_alloc: converted to MEMORY_ERROR
 - bt2_common::Error: converted to ERROR

Any other exception (for example, coming from a third-party library we
would eventually use) should be caught and converted to a
bt2_common::Error.

Change-Id: I06c2ccb43947f5a9e61568967f2812ccb0821b36
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agosink.ctf.fs: use LogCfg
Simon Marchi [Fri, 27 May 2022 15:50:41 +0000 (11:50 -0400)] 
sink.ctf.fs: use LogCfg

Change-Id: I6ab259c8db526a3b4c0de9295a4360180c56b398
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agosink.ctf.fs: initialize TraceIrToCtfIrCtx fields, remove memset
Simon Marchi [Fri, 27 May 2022 15:53:51 +0000 (11:53 -0400)] 
sink.ctf.fs: initialize TraceIrToCtfIrCtx fields, remove memset

This is in preparation to using some C++ objects as fields.

Change-Id: Ib473d43a7991e8363df5efc8eb18604799e2dc0e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agosrc.ctf.sink: allocate fs_sink_comp with new
Simon Marchi [Fri, 27 May 2022 15:38:44 +0000 (11:38 -0400)] 
src.ctf.sink: allocate fs_sink_comp with new

In preparation to using some C++ objects as fields.

Change-Id: I924a6088b17e1d3ae4b8a239cf059fc3a7ecc8c6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoctf: rename `ctx` structures
Simon Marchi [Fri, 27 May 2022 15:30:28 +0000 (11:30 -0400)] 
ctf: rename `ctx` structures

Rename the various structures named `ctx` to something else, to avoid
ODR problems when C++-ifying them.

Change-Id: I1b30c38ba6b88687b5baa5b965b805b0a9097ffe
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoCleanup: src.ctf.fs: remove unused decoder functions
Francis Deslauriers [Wed, 11 May 2022 22:00:24 +0000 (18:00 -0400)] 
Cleanup: src.ctf.fs: remove unused decoder functions

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I8c2610883c8730a36e3e4336c2dc48b67d3e6236
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8038
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.*: add old CTF IR const functions
Francis Deslauriers [Tue, 10 May 2022 21:22:47 +0000 (17:22 -0400)] 
src.ctf.*: add old CTF IR const functions

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I73f825b4127cff772904579c90806bd367a7fe36
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8012
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc.ctf.fs: implement `MetadataStreamDecoder` class
Francis Deslauriers [Tue, 17 May 2022 18:17:29 +0000 (14:17 -0400)] 
src.ctf.fs: implement `MetadataStreamDecoder` class

This class offers a `decode()` method that decodes a potentially
packetized metadata stream as a `std::string`.

After decoding a buffer, the `pktInfo()` method may return packet
information of the packetized metadata stream.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iee867271fe6493b19c4bd77151409886b7c01ed9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8050
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add `readFixedLenInt()` function
Francis Deslauriers [Wed, 25 May 2022 15:20:53 +0000 (11:20 -0400)] 
cpp-common: add `readFixedLenInt()` function

This function template reads an integer from a buffer without assuming
its byte order.

For example, this is needed when reading the magic number from a data
buffer of unknown byte order. If needed, the user then has to manually
swap byte order of that integer to get its native byte order

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ia94ee3a3ffc7caaa46a46defead3e23da0a4c2b2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8111
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/plugins/ctf/common/src: add item sequence iterator API
Philippe Proulx [Mon, 25 Apr 2022 15:16:46 +0000 (11:16 -0400)] 
src/plugins/ctf/common/src: add item sequence iterator API

This patch adds the item sequence iterator API, internal to the `ctf`
plugin, to be used by the source components (`src.ctf.fs` and
`sink.ctf.fs`).

An item sequence iterator can decode a sequence of packets using:

* A medium, which provides binary stream data to the iterator.
* A CTF IR trace class, which describes how to decode said data.

This makes it possible to completely decode CTF data streams without
ever needing to create trace IR objects. In other words, it's a
standalone CTF decoding library which, minus a few utilities borrowed
from the Babeltrace project, could even be reused in other projects.

The value of an item sequence iterator is an item. The item sequence
iterator doesn't actually create items as it advances: it has one
instance of each concrete item class and sets a pointer to one of
those as it advances (it's a single-pass input iterator).

Seek a specific packet beginning with the seekPkt() method.

Methods which make the iterator decode may append a cause to the error
of the current thread and throw `bt2_common::Error`.

NOTE: Currently, this isn't an STL-compliant iterator class: you
can't copy an instance and you can't get an end iterator, because
there's no item sequence (container) class (you need to use the
isEnded() method). Also, the typical STL type aliases such as `value`
and `reference` aren't part of the class.

This API and its implementation are inspired by the yactfr
(<https://github.com/eepp/yactfr>) element sequence iterator API,
conveniently written by the same author.

Please read the class comments of `ctf::src::ItemSeqIter` and
`ctf::src::Medium` to learn how to use this API and how it works
internally.

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

2 years agoAdd CTF IR classes specific to `src.ctf.*`
Philippe Proulx [Wed, 13 Apr 2022 01:03:21 +0000 (21:03 -0400)] 
Add CTF IR classes specific to `src.ctf.*`

This patch uses the `ctf::ir` API to expose a source-specific CTF IR API
under the `ctf::src` namespace, to be used by both the `src.ctf.fs` and
the `src.ctf.lttng-live` component classes.

This specific CTF IR API augments the common `ctf::ir` API with
user mixins to add the following:

* Any field class has a "deep type".

  See the comment of `ctf::src::FcDeepType` to understand why we need
  such an enumeration.

* The field class, clock class, event record class, data stream class,
  and trace class classes have an optional equivalent libbabeltrace2
  class object.

  This is a bridge between the CTF IR world and the libbabeltrace2 world
  to be able to create corresponding libbabeltrace2 messages when
  decoding a data stream with the CTF IR classes.

  If a field class has no equivalent libbabeltrace2 class, then the
  values of its instances aren't transported through messages as field
  objects.

* A clock class object may hold its equivalent libbabeltrace2 class
  (owned, shared reference).

* A trace class object may hold its equivalent libbabeltrace2 class
  (owned, shared reference).

* Boolean and integer field classes have an optional value saving
  index.

  See the comment of `ctf::src::ValSavingIndexes` to learn more.

* Dynamic-length, optional, and variant field classes have a
  saved dependency value index.

  Again, see the comment of `ctf::src::ValSavingIndexes` to learn more.

* A trace class contains the maximum number of saved values for its
  instance.

  Once more, see the comment of `ctf::src::ValSavingIndexes` to learn
  more.

The new API adds templateless aliases for all the configurable CTF IR
types, for example `src::ctf::FixedLenIntFc`.

The new API also offers user mixin agnostic functions to create all its
CTF IR objects. For example, call ctf::src::createDynLenBlobFc() to
create a `ctf::src` dynamic-length BLOB field class.

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

2 years agoAdd common `ctf::ir` CTF IR classes
Philippe Proulx [Wed, 30 Mar 2022 20:17:10 +0000 (16:17 -0400)] 
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 both `src.ctf.fs` and `sink.ctf.fs`. 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
        FixedLengthBitArrayFc
          FixedLengthBoolFc
          FixedLengthFloatFc
          FixedLengthIntFc
            FixedLengthUIntFc
              FixedLengthUEnumFc
            FixedLengthSIntFc
              FixedLengthSEnumFc
        VarLengthIntFc
          VarLengthUIntFc
            VarLengthUEnumFc
          VarLengthSIntFc
            FixedLengthSEnumFc
        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):

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

* 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 in 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,
  FixedLenUEnumFc::FixedLenUEnumFc() accepts four mixins: field class,
  fixed-length bit array field class, fixed-length integer field class,
  and fixed-length unsigned 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:

  `WithUserAttrsMixin`:
      Optional user attributes.

  `IntFcMixin`:
      Preferred display base.

  `UIntFcMixin`:
      Unsigned integer field roles.

  `EnumFcMixin`:
      Mappings.

  `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 "ctf-2-meta.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",
            bt2_common::makeUnique<MyNullTerminatedStrFc>(MyMixins::Fc {}));

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

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

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

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

2 years agofield-class.hpp: add missing support for user attributes
Philippe Proulx [Fri, 20 May 2022 13:11:40 +0000 (09:11 -0400)] 
field-class.hpp: add missing support for user attributes

This patch adds the missing
bt2::CommonStructureFieldClassMember::userAttributes() and
bt2::CommonVariantFieldClassOption::userAttributes() methods to set and
borrow user attributes of structure field member classes and variant
field class options.

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

2 years agoAdd bt2::Common{Field,FieldClass,Value,Message}<>::as<>()
Philippe Proulx [Fri, 20 May 2022 01:50:36 +0000 (21:50 -0400)] 
Add bt2::Common{Field,FieldClass,Value,Message}<>::as<>()

Those new as() method templates conceptually cast their object to the
first template parameter. Those are shorthands to use specific types
within a template function, for example:

    template <typename FieldT, typename ValT>
    void g(bt2::Field field, const ValT val)
    {
        // ...
        field.as<FieldT>() = val;
        // ...
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifc1f49487ac6ef9c143bf4c2faa3373f4eaccd9e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8099
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
2 years agobt2_common::UuidView::str(): make bt_uuid_to_str() write to ret. val.
Philippe Proulx [Thu, 19 May 2022 18:17:33 +0000 (14:17 -0400)] 
bt2_common::UuidView::str(): make bt_uuid_to_str() write to ret. val.

No copy!

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

2 years agobt2::internal::BorrowedObj: add static assertions for generic copy ops.
Philippe Proulx [Thu, 19 May 2022 16:22:29 +0000 (12:22 -0400)] 
bt2::internal::BorrowedObj: add static assertions for generic copy ops.

This patch adds static assertions to `borrowed-obj.hpp` so as to make
compiler errors more readable when assigning a const wrapper to a
non-const wrapper, for example:

    bt2::Value v = bt2::ConstMapValue {somePtr};

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

2 years agobt2::internal::BorrowedObj: use default copy operations explicitly
Philippe Proulx [Thu, 19 May 2022 16:11:40 +0000 (12:11 -0400)] 
bt2::internal::BorrowedObj: use default copy operations explicitly

What was called the generic copy constructor and assignment operator
are in fact constructor templates, not true copy operations.

This is because C++ requires that a copy constructor/assignment operator
be a "non-template non-static member function".

This patch is not a fix because the generated default copy operations
were fine (just copy the underlying libbabeltrace2 pointer). Just use
the default ones explicitly and fix the comments so that we know what's
going on.

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

2 years agosrc/cpp-common/bt2/internal/*-obj.hpp: template param. names not needed
Philippe Proulx [Thu, 19 May 2022 16:06:59 +0000 (12:06 -0400)] 
src/cpp-common/bt2/internal/*-obj.hpp: template param. names not needed

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

2 years agofield-class.hpp: support optional variant FC option name
Philippe Proulx [Tue, 17 May 2022 18:09:05 +0000 (14:09 -0400)] 
field-class.hpp: support optional variant FC option name

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

2 years agocpp-common: add `begin()` and `end()` to bt2::ConstFieldLocation
Francis Deslauriers [Tue, 17 May 2022 20:51:38 +0000 (16:51 -0400)] 
cpp-common: add `begin()` and `end()` to bt2::ConstFieldLocation

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I720ec0c30141ce48e7465cf0eccaecffc08597e6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8054
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoFix: bt2::internal::SharedObj: add real copy/move ctor./operator=()
Philippe Proulx [Sat, 14 May 2022 16:28:52 +0000 (12:28 -0400)] 
Fix: bt2::internal::SharedObj: add real copy/move ctor./operator=()

Observed issue
==============
Given the type S, some `bt2::internal::SharedObj` class template
instantiation:

* Constructing an S object A from another S object doesn't increment the
  internal reference count of the libbabeltrace2 object which A wraps.

* Assigning an S object A from an S object B:

  * Doesn't increment the internal reference count of the libbabeltrace2
    object which B wraps.

  * Doesn't decrement the internal reference count of the libbabeltrace2
    object which A wraps.

* Constructing an S object from another moved S object B doesn't
  reset B.

* Assigning an S object A from a moved S object B:

  * Doesn't reset B.

  * Doesn't decrement the internal reference count of the libbabeltrace2
    object which A wraps.

Cause
=====
What I thought were copy/move constructor and assignment operators in
`bt2::internal::SharedObj` are in fact simple constructor and assignment
operator templates. In other words, they don't qualify as copy/move
constructor and assignment operators, so the compiler uses default ones.

From [1]:

> A copy constructor of class `T` is a non-template constructor whose
> first parameter is `T&‍`, `const T&‍`, `volatile T&‍`, or `const
> volatile T&‍`, and either there are no other parameters, or the rest
> of the parameters all have default values.

The same condition (non-template) holds for a move constructor, a copy
assignment operator, and a move assignment operator.

Solution
========
Add copy/move constructors and assignment operators to
`bt2::internal::SharedObj`.

Although you may call an operator=() method template like this:

    this->operator=<ObjT, LibObjT>(other)

you can't specify the template parameters when you call a constructor
template: the types of all its parameters need to be deduced.

This is why, to avoid redundant code, I added two common "copy" and
"move" (not real copy/move constructors) private constructor templates
to which the true copy/move constructors and the generic "copy"/"move"
constructors delegate. Those common ones accept a second, unused `int`
parameter to differentiate them from the public, generic "copy"/"move"
constructors.

Known drawbacks
===============
None.

References
==========
[1]: https://en.cppreference.com/w/cpp/language/copy_constructor

Change-Id: I6d8cb7c16da0a79296a482f8d130ab40468cc1a5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8041
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
2 years agoAdd bt2::internal::SharedObj::create{With,Without}Ref() methods
Philippe Proulx [Fri, 13 May 2022 17:29:36 +0000 (13:29 -0400)] 
Add bt2::internal::SharedObj::create{With,Without}Ref() methods

It seems like there were some confusion regarding the reference
acquisition of the `bt2::internal::SharedObj` constructor vs. its
createWithInitialRef() static method.

Make it clear with a private constructor and two public static methods:

* createWithoutRef() creates a shared object without getting a
  reference.

* createWithRef() creates a shared object, immediately getting a new
  reference.

Both methods have two versions: one which accepts a wrapper and one
which accepts a raw libbabeltrace2 pointer.

Update all the `src/cpp-common/bt2` code to use those methods.

The pattern for a non-static shared() method is:

    Shared shared() const noexcept
    {
        return Shared::createWithRef(*this);
    }

This means if you have a borrowed wrapper `obj`, then `obj.shared()`
returns a shared object, incrementing the reference count.

The pattern for a creation method is:

    return Shared::createWithoutRef(libObjPtr);

where `libObjPtr` is a raw libbabeltrace2 pointer to an object of which
the reference count is one.

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

2 years agoFix: bt2::CommonStreamClass: use correct memory error status
Philippe Proulx [Thu, 12 May 2022 17:23:48 +0000 (13:23 -0400)] 
Fix: bt2::CommonStreamClass: use correct memory error status

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

2 years agocpp-common: Add Blob, StaticBlob, and DynamicBlob FC
Francis Deslauriers [Thu, 17 Mar 2022 01:51:14 +0000 (21:51 -0400)] 
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]
      DYNAMIC_BLOB = 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]
      DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD = 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]
      DYNAMIC_BLOB_WITH_LENGTH_FIELD = 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>
2 years agoctf: use LogCfg throughout `src.ctf.fs`, `src.ctf.lttng-live` and common
Simon Marchi [Fri, 10 Jun 2022 16:38:30 +0000 (12:38 -0400)] 
ctf: use LogCfg throughout `src.ctf.fs`, `src.ctf.lttng-live` and common

A lot of functions and structures have parameters or fields of type
bt_self_component, bt_self_component_class and bt_logging_level for the
sole purpose of logging.  This becomes quite verbose, especially when a
function can be used in both self component and self component class
context, then it will have both of these parameters.

The `ctf::LogCfg` class is used to encapsulate this context in a single
value that can be passed around.  Use that class as much as practically
possible throughout the sources of the ctf plugin, as well as in the
common directory that they depend on.

Remove meta_log_config, which was a structure serving the same purpose.

Change-Id: I0f6844d2cb83d2bf52b81ae9dee4179c7b1f2e12
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoctf: allocate some structures with new
Simon Marchi [Wed, 11 May 2022 13:21:52 +0000 (09:21 -0400)] 
ctf: allocate some structures with new

Allocate some key structures in the ctf plugin with new (and free with
delete), so we can start using non-POD fields in them.  Initialize all
fields to 0 / nullptr to replicate what g_new0 did.

Add ctf_fs_ds_index_entry_destroy, to abstract how this object is
destroyed (it is currently being g_free'd at multiple places) and to use
it as a g_ptr_array_new_with_free_func callback.

Change-Id: Ic0f893655db22c964641639aa0625d820af71587
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8021
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoctf: remove unused ctf_metadata_decoder struct
Simon Marchi [Wed, 11 May 2022 14:08:43 +0000 (10:08 -0400)] 
ctf: remove unused ctf_metadata_decoder struct

I noticed this struct was unused.  There is another `struct
ctf_metadata_decoder` in src/plugins/ctf/decoder.cpp, that is actually
used.

Change-Id: Ief9a4e37e7414b8fcd729581bb040c1100722327
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8020
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agointeger-range-set.hpp: add `begin()` and `end()` to bt2::CommonIntegerRangeSet
Francis Deslauriers [Fri, 11 Mar 2022 17:30:06 +0000 (12:30 -0500)] 
integer-range-set.hpp: add `begin()` and `end()` to bt2::CommonIntegerRangeSet

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I85d92d27f90f25b2f86780180b248bde3c394b20
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7568
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/cpp-common/bt2: wrap variant with selector field loc. FC API
Philippe Proulx [Wed, 11 May 2022 16:26:49 +0000 (12:26 -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

2 years 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

2 years agosrc/cpp-common/bt2: wrap dynamic array with length field loc. FC API
Philippe Proulx [Wed, 11 May 2022 16:07:13 +0000 (12:07 -0400)] 
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

2 years agocpp-common: add `begin()` and `end()` to VariantWithIntegerSelector FC
Francis Deslauriers [Thu, 17 Mar 2022 01:12:49 +0000 (21:12 -0400)] 
cpp-common: add `begin()` and `end()` to VariantWithIntegerSelector FC

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ice31d346102258a6af593bd38fc3f123179482f4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7619
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add `begin()` and `end()` to bt2::CommonEnumerationFieldClass
Francis Deslauriers [Wed, 16 Mar 2022 19:24:03 +0000 (15:24 -0400)] 
cpp-common: add `begin()` and `end()` to  bt2::CommonEnumerationFieldClass

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Id8b001611288121dd1adc1c3ae5bb698722b5bca
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7618
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add `begin()` and `end()` to bt2::ConstFieldPath
Francis Deslauriers [Wed, 9 Mar 2022 22:42:44 +0000 (17:42 -0500)] 
cpp-common: add `begin()` and `end()` to bt2::ConstFieldPath

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie442f80bf1d5b055f6707ff516a8094417ff6c1d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7553
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/cpp-common/bt2: add field location support
Philippe Proulx [Tue, 10 May 2022 17:48:15 +0000 (13:48 -0400)] 
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 vector of strings
(either `const char *` or `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.

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

2 years agosrc/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`
Philippe Proulx [Mon, 9 May 2022 20:08:23 +0000 (16:08 -0400)] 
src/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`

This patch adds the `bt2::AddConst` and `bt2::RemoveConst` structure
templates in `src/cpp-common/bt2/type-traits.hpp` which both provide the
`Type` type alias to transform a const object type into a non-const
object type and vice versa.

For example, `bt2::AddConst<bt2::ClockClass>::Type` is
`bt2::ConstClockClass` and `bt2::RemoveConst<bt2::ConstMapValue>::Type`
is `bt2::MapValue`.

I needed this to call something like

    bt2::RemoveConst<typename LibFcT::Mapping::RangeSet>::Type::create()

where `LibFcT` is some non-const enumeration field class, but I decided
to implement it for all the types right now.

Internally, we add something like this for all type pairs:

    namespace internal {

    struct XyzTypeDescr
    {
        using Const = ConstXyz;
        using NonConst = Xyz;
    };

    template <>
    struct TypeDescr<Xyz> : public XyzTypeDescr
    {
    };

    template <>
    struct TypeDescr<ConstXyz> : public XyzTypeDescr
    {
    };

    } /* namespace internal */

The type trait structure templates in `type-traits.hpp` just use
`internal::TypeDescr`, for example:

    template <typename ObjT>
    struct RemoveConst
    {
        using Type = typename internal::TypeDescr<ObjT>::NonConst;
    };

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

2 years agoAdd bt2::CommonEnumerationFieldClass::addMapping() methods
Philippe Proulx [Mon, 9 May 2022 19:34:33 +0000 (15:34 -0400)] 
Add bt2::CommonEnumerationFieldClass::addMapping() methods

They make it possible to add mappings to an enumeration field class.

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

2 years agoFix: bt2::CommonIntegerFieldClass::fieldValueRange(): use correct func.
Philippe Proulx [Mon, 9 May 2022 19:33:39 +0000 (15:33 -0400)] 
Fix: bt2::CommonIntegerFieldClass::fieldValueRange(): use correct func.

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

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

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

2 years agosrc/cpp-common/bt2/trace-ir.hpp: add nameSpace() methods where needed
Philippe Proulx [Mon, 9 May 2022 18:10:35 +0000 (14:10 -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

2 years agocli: Rename `logging.c` to `logging.cpp` to force C++ linking
Francis Deslauriers [Thu, 28 Apr 2022 14:15:26 +0000 (10:15 -0400)] 
cli: Rename `logging.c` to `logging.cpp` to force C++ linking

This is to force the linking of the babeltrace2 binary using a C++
linker. This is necessary to support the Babeltrace2 static build since
the CTF plugin now has C++ symbols.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ife9967d9362c7648b6ea031f453262a10aa03483
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7954
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosrc/cpp-common: improve C++ UUID utilities
Francis Deslauriers [Fri, 29 Apr 2022 16:01:48 +0000 (12:01 -0400)] 
src/cpp-common: improve C++ UUID utilities

Philippe Proulx writing below.

This patch improves the C++ common UUID utilities.

Francis wrote the initial version of `bt2_common::Uuid`, and then we
worked together to improve many little things at once, leading to this
patch.

His original message was:

> Add `bt2_common::Uuid`
>
> This patch adds the `bt2_common::Uuid` class which represent UUIDs.
>
> `Uuid` instances can be created from byte array, strings, or
> bt2_common::UuidView objects.
>
> The generate() static method returns a Uuid object with newly
> generated UUID.
>
> The operator UuidView() method returns a bt2_common::UuidView object
> representing the entire content of the UUID.
>
> The data() method returns a const pointer to the underlying
> std::array<>.
>
> The str() method returns a new `std::string` instance containing the
> canonical string representation of the UUID.

The final improvements are:

* Add said `bt2_common::Uuid` class.

  I also added the operator[](), operator=(), isNil(), begin(), and
  end() methods, the `Val` and `ConstIter` aliases, and the fact that
  most of the class relies on creating a `bt2_common::UuidView` to wrap
  itself when needed.

  data() just returns `const Val *`.

* In `bt2_common::UuidView`:

  * Make the class `final`.

  * Add the `Val` and `ConstIter` aliases.

  * Add operator<(): makes it possible to use a `bt2_common::UuidView`
    as an `std::set` value type or as an `std::map` key type, and to use
    it with STL algorithms.

  * Make size() `constexpr`.

  * Rename string() to str() for consistency with internal C++ naming.

  * Add begin() and end().

  * Add operator=() which accepts a UUID pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id049953aecc51562e5939db546cb7d82bbaf88eb

2 years agocpp-common: Expose BorrowedObj::libObjPtr() as public method
Francis Deslauriers [Tue, 26 Apr 2022 15:39:11 +0000 (11:39 -0400)] 
cpp-common: Expose BorrowedObj::libObjPtr() as public method

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iea93caa6b47ce1afeb7977fee26dffdd3f97013e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7948
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agoMake `bt2_common::UuidView` final
Philippe Proulx [Mon, 2 May 2022 14:08:03 +0000 (10:08 -0400)] 
Make `bt2_common::UuidView` final

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

2 years agoRename bt2_common::UuidView::string() -> str()
Philippe Proulx [Mon, 2 May 2022 14:07:30 +0000 (10:07 -0400)] 
Rename bt2_common::UuidView::string() -> str()

More consistent with other internal C++ naming.

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

2 years agoAdd bt2_common::UuidView::operator<()
Philippe Proulx [Mon, 2 May 2022 14:01:54 +0000 (10:01 -0400)] 
Add bt2_common::UuidView::operator<()

Makes it possible to use a `bt2_common::UuidView` as an `std::set` value
type or an `std::map` key type.

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

2 years agoMake bt2_common::UuidView::size() `constexpr`
Philippe Proulx [Mon, 2 May 2022 13:59:42 +0000 (09:59 -0400)] 
Make bt2_common::UuidView::size() `constexpr`

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

2 years agosrc/cpp-common: add fixed-length integer reading functions
Philippe Proulx [Mon, 25 Apr 2022 15:10:04 +0000 (11:10 -0400)] 
src/cpp-common: add fixed-length integer reading functions

This patch adds `src/cpp-common/read-fixed-len-int.hpp` which offers
function templates to read fixed-length integers from a buffer.

The bt2_common::readFixedLenIntLe() (little endian) and
bt2_common::readFixedLenIntBe() (big endian) function templates accept
one template parameter which is the integral type of the integer to read
(and the return type of the function). For example,
bt2_common::readFixedLenIntLe<std::int32_t>() reads a 32-bit signed
little-endian integer and returns it.

The function templates use bt2_common::littleEndianToNative() and
bt2_common::bigEndianToNative() as needed.

You may combine this with `bt2_common::StdIntT` to have the length in
bits and the signedness as independent template parameters, for
example:

    const auto val = readFixedLenIntBe<StdIntT<16, true>>(myBuf);

which is equivalent to:

    const auto val = readFixedLenIntBe<std::int16_t>(myBuf);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c684bede60f7b6324a3140c5fd498c21ad513ab
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7939
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
2 years agoAdd `src/cpp-common/std-int.hpp`
Philippe Proulx [Thu, 19 May 2022 12:38:05 +0000 (08:38 -0400)] 
Add `src/cpp-common/std-int.hpp`

This new header contains the `StdIntT` trait structure to get the
standard integer type from a length (bits) and a signedness.

For example, `bt2_common::StdIntT<32, true>::Type` is `std::int32_t`.

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

2 years agosrc/cpp-common: add bt2_common::align()
Philippe Proulx [Fri, 22 Apr 2022 12:11:22 +0000 (08:11 -0400)] 
src/cpp-common: add bt2_common::align()

This is a templated C++ version of the BT_ALIGN() macro found in
`src/common/align.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0062778831d20cf19fe28bfa82c867473f7cf50b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7928
Tested-by: jenkins <jenkins@lttng.org>
2 years agosrc/cpp-common: add bt2_common::{little,big}ToNative()
Philippe Proulx [Fri, 22 Apr 2022 12:09:21 +0000 (08:09 -0400)] 
src/cpp-common: add bt2_common::{little,big}ToNative()

Those are C++ versions (using overloads) of the {le,be}{16,32,64}toh()
functions found in `src/compat/endian.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iab826bb633388d5ce506b4462b7a0417c2c05ad4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7927
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
2 years ago`ctf` plugin: add `ctf::IntRangeSet` class template
Philippe Proulx [Thu, 21 Apr 2022 16:44:27 +0000 (12:44 -0400)] 
`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>
2 years ago`ctf` plugin: add `ctf::IntRange` class template
Philippe Proulx [Thu, 21 Apr 2022 16:38:27 +0000 (12:38 -0400)] 
`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

2 years agosrc/plugins/ctf/common: restructure subtree
Philippe Proulx [Wed, 13 Apr 2022 00:32:39 +0000 (20:32 -0400)] 
src/plugins/ctf/common: restructure subtree

This patch restructures the `src/plugins/ctf/common` subtree as such:

`src`:
    Everything common to source component classes.

`src/metadata/tsdl`:
    TSDL-specific code.

    As of this patch, everything which was part of
    `src/plugins/ctf/common/metadata` is moved here, but some code will
    be shared with CTF 2 sources eventually and move back to
    `src/plugins/ctf/common/src/metadata`.

`print.hpp` isn't needed anymore.

The dummy `ctf-common-src.cpp` exists to make sure the
`libbabeltrace2-plugin-ctf-common-src.la` convenience library has at
least one source file.

This new structure will make it easier to add common `ctf` plugin code
for both source and sink component classes, as well as to add code
specific to CTF 2 and common to both CTF 1 and CTF 2.

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

2 years agoFix: field-path.hpp: add missing `shared-obj.hpp` include
Francis Deslauriers [Wed, 16 Mar 2022 15:30:54 +0000 (11:30 -0400)] 
Fix: field-path.hpp: add missing `shared-obj.hpp` include

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

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

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

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idf62a2a8d1eb52799c71dee37f08e44af277b15a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7621
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
2 years agoAdd `bt2_common::DataLen` class (general-purpose data length)
Philippe Proulx [Fri, 1 Apr 2022 19:47:50 +0000 (15:47 -0400)] 
Add `bt2_common::DataLen` class (general-purpose data length)

This patch adds the `bt2_common::DataLen` class so that you can make
sure your function accepts an expected data length instead of specifying
that you need bits or bytes:

    Something buildSomething(bt2_common::DataLen len, ...)
    {
        using namespace bt2_common::literals::datalen;

        if (...) {
            len += 16_MiBytes;
        } else {
            len *= 2;
        }

        // ...
    }

    // ...

    const auto something = buildSomething(DataLen::fromBytes(sz), ...);

As you can see above, you can use the `bt2_common::literals::datalen`
namespace to access handy data length user literals.

The `bt2_common::DataLen` constructor is private: you need to use the
bt2_common::DataLen::fromBits() and bt2_common::DataLen::fromBytes()
static methods to build an instance.

Because a `bt2_common::DataLen` instance is just an `unsigned long long`
value in memory, the intention of this API is to copy data length
instances as much as possible. Therefore, I suppose it's cheaper to
accept a `const bt2_common::DataLen` parameter than
`const bt2_common::DataLen&` which would add an indirection.

The constructor and many methods are `constexpr` to make this useable in
constant context.

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

2 years agosrc/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()
Philippe Proulx [Fri, 15 Apr 2022 17:08:10 +0000 (13:08 -0400)] 
src/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()

This patch adds the following function templates, under the `bt2_common`
namespace, within the new `src/cpp-common/safe-ops.hpp` header:

safeToMul():
    Returns whether or not you can safely multiply two numbers without
    causing an overflow.

safeToAdd():
    Returns whether or not you can safely add two numbers without
    causing an overflow.

safeToSub():
    Returns whether or not you can safely subtract two numbers without
    causing an underflow.

safeMul():
    Multiplies some number by another, asserting that it's safe to do
    so, and returns the result.

safeAdd():
    Adds some number and another, asserting that it's safe to do so, and
    returns the result.

safeSub():
    Subtract some number from another, asserting that it's safe to do
    so, and returns the result.

Those are similar to the existing bt_safe_*() C functions, except that:

* They're function templates, so you can use any numeric type.

* The safeTo*() function templates are `constexpr`.

* They only work with unsigned types; signed types introduce some
  complexity (negative values) which I don't need to deal with right
  now.

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

2 years agosrc/cpp-common: add JSON value requirement aliases
Philippe Proulx [Wed, 9 Mar 2022 16:11:24 +0000 (11:11 -0500)] 
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

2 years agoAdd `bt2_common::ValReq` class template system
Philippe Proulx [Fri, 3 Jun 2022 12:24:17 +0000 (08:24 -0400)] 
Add `bt2_common::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 `bt2_common::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‑SPECRC‑5.0 [1] metadata
  stream within the `ctf` plugin.

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

A value requirement (`bt2_common::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.

`StrValMatchesRegexReq`:
    Validates the type of V and that the raw value of V matches a given
    regular expression.

`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`.

Semantic version:
    Code:
        JsonStrValMatchesRegexReq {"\\d+\\.\\d+\\.\\d+"}

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

        [1:1] Invalid string `2.14`.

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.

CTF 2 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.

CTF 2 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/files/CTF2-SPECRC-5.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

2 years agoplugins: make text and utils component classes report support for MIP 1
Simon Marchi [Wed, 9 Mar 2022 21:13:37 +0000 (16:13 -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>
2 years 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>
2 years agosink.text.pretty: abort on unknown field class type
Simon Marchi [Fri, 11 Mar 2022 17:03:35 +0000 (12:03 -0500)] 
sink.text.pretty: abort on unknown field class type

I don't think there a legimitate case for the print_field function to
encounter an invalid field class type.  Change it to abort instead of
returning an error.

Change-Id: I333d2221b828841aff38a7d8b0a17032af3aafb1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7580
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agograph/mip: make bt_get_greatest_operative_mip_version compute operative MIP version
Simon Marchi [Fri, 11 Mar 2022 02:42:32 +0000 (21:42 -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>
2 years 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

2 years 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>
2 years 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):

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>
2 years 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>
2 years agofield-class.hpp: remove redundant template parameters
Francis Deslauriers [Tue, 8 Mar 2022 21:41:24 +0000 (16:41 -0500)] 
field-class.hpp: remove redundant template parameters

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I1c0c104431f7cf57806a66ed1bce964c007f2c47
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7527
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agofield-class.hpp: Add CommonVariantWithSelectorFieldClass
Francis Deslauriers [Mon, 7 Mar 2022 22:17:46 +0000 (17:17 -0500)] 
field-class.hpp: Add CommonVariantWithSelectorFieldClass

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

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

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I952fc54c015f8548489aab74e85cded23f9841f7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7510
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agocpp-common: add `begin()` and `end()` to Variant and Struct FC
Francis Deslauriers [Thu, 10 Feb 2022 22:06:27 +0000 (17:06 -0500)] 
cpp-common: add `begin()` and `end()` to Variant and Struct FC

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

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

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie3bbc05a20368b8b1388b484ef02da4fb4b68a2d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7497
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agofield-class.hpp: add missing #include
Francis Deslauriers [Fri, 4 Mar 2022 15:08:18 +0000 (10:08 -0500)] 
field-class.hpp: add missing #include

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I5dedb44d393fe318253f5912c032ad313fd1c455
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7495
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agosink.ctf.fs: remove unused `index_in_parent` field in Ctx struct
Francis Deslauriers [Thu, 24 Feb 2022 20:06:03 +0000 (15:06 -0500)] 
sink.ctf.fs: remove unused `index_in_parent` field in Ctx struct

This field is not used anywhere and looks like a leftover from a
previous iteration of the sink. Let's remove it.

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I420462ccfd78c06d7b496f4650af77cd2d2e57b7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7385
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years agouuid-view.hpp: add missing #include's
Francis Deslauriers [Wed, 23 Feb 2022 15:42:49 +0000 (10:42 -0500)] 
uuid-view.hpp: add missing #include's

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

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

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I4e018ece9ea4ca755f6612cd9adec408667b202d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7356
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
2 years 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>
2 years 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-SPECRC-5.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.

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

2 years agolib: add namespace property to event classes
Simon Marchi [Thu, 24 Feb 2022 16:31:35 +0000 (11:31 -0500)] 
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 [1].

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

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

[1] https://diamon.org/ctf/files/CTF2-SPECRC-3.0.html#dsc-frag

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>
2 years agolib: add namespace property to stream classes
Simon Marchi [Thu, 24 Feb 2022 16:08:12 +0000 (11:08 -0500)] 
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 [1].

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

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

[1] https://diamon.org/ctf/files/CTF2-SPECRC-3.0.html#dsc-frag

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>
2 years 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'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.

[1] https://diamon.org/ctf/files/CTF2-SPECRC-3.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>
2 years agosrc/cpp-common: add bt2_common::bt2ValueFromJsonVal() function
Philippe Proulx [Thu, 3 Mar 2022 18:36:34 +0000 (13:36 -0500)] 
src/cpp-common: add bt2_common::bt2ValueFromJsonVal() function

This patch adds the bt2_common::bt2ValueFromJsonVal() function which
converts a JSON value object (`bt2_common::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 `bt2_common::JsonNullVal` class, whereas
libbabeltrace2 uses a null value singleton, and `bt2_common::JsonVal`
has a text location member.

This is part of an effort to support CTF2‑SPECRC‑4.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/files/CTF2-SPECRC-4.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>
2 years agosrc/cpp-common: make `bt2_common::JsonVal` visitable
Philippe Proulx [Thu, 3 Mar 2022 18:34:44 +0000 (13:34 -0500)] 
src/cpp-common: make `bt2_common::JsonVal` visitable

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

This is part of an effort to support CTF2‑SPECRC‑4.0 [1].

[1]: https://diamon.org/ctf/files/CTF2-SPECRC-4.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>
This page took 0.056049 seconds and 5 git commands to generate.