babeltrace.git
4 months agologging: strip down and clean `log.h` and `log.c`
Simon Marchi [Mon, 11 Dec 2023 20:04:49 +0000 (15:04 -0500)] 
logging: strip down and clean `log.h` and `log.c`

`log.h` slowly became a mix of the original zf_log [1] file and our own
changes over that.

I find that when I need to make changes to those files, I must consider
lots of features that we just never used and probably never will.
Amongst them are:

* Portability with MSVC and Android.

* Default values (`BT_LOG_DEF_*`).

* Tag prefix.

* Custom source location format.

* Censoring.

* All the global vs. local state, for example the global output level,
  all the BT_LOG*_AUX() macros.

* Library prefix (we just hardcoded `BT_` and `bt_` long ago).

* Mask of log message parts.

* Custom output callback.

Moreover, some of those features add execution time. For example,
logging always goes through vsnprintf(), even if you want to log a
simple string without any sophisticated formatting. Also, the actual
write() call is done through a callback because the output is
configurable. So is stuff like time formatting. We just don't need that.

This patch strips down those two files to make future changes easier. In
fact, it's pretty much a rewrite, but honors the current API, except for
the BT_LOG_WRITE*() functions (renamed, see below) and for
`BT_MINIMAL_LOG_LEVEL` which I renamed to `BT_LOG_MINIMAL_LEVEL` to keep
the same prefix.

This patch also moves everything which doesn't depend on user
definitions to `log-api.h`, and renames `log.c` to `log-api.c` for
consistency.

The user definitions are `BT_LOG_OUTPUT_LEVEL` and `BT_LOG_TAG`, which
you normally use as such:

    #define BT_LOG_OUTPUT_LEVEL my_level
    #define BT_LOG_TAG          "MY-TAG"
    #include "logging/log.h"

This gives access to BT_LOGI() and such which rely on those.

I think it's cleaner to separate the independent stuff. For example, not
that it's a true use case, but you could want to use the `log.h` macros
as well as another API which relies on `logging/log-api.h` at the same
time:

    #include "my-logger.hpp"

    #define BT_LOG_OUTPUT_LEVEL my_level
    #define BT_LOG_TAG          "MY-TAG"
    #include "logging/log.h"

Then an instance of some logger class in `my-logger.hpp` may have its
own independent output level and tag. Without this patch, you would need
to know that `my-logger.hpp` includes `logging/log.h` itself and
therefore make sure to define `BT_LOG_OUTPUT_LEVEL` and `BT_LOG_TAG`
before you include it:

    #define BT_LOG_OUTPUT_LEVEL my_level
    #define BT_LOG_TAG          "MY-TAG"
    #include "my-logger.hpp"

This works when you know it, but I believe it's less straightforward.

Now, the `log-api.h` interface is much simpler. The only mandatory
definition is `BT_LOG_MINIMAL_LEVEL`.

bt_log_write():
    Logs a message (no formatting).

bt_log_write_printf():
    Formats a message and logs it.

bt_log_write_mem():
    Logs a message (no formatting) and dumps a memory block.

bt_log_write_mem_printf():
    Formats a message, logs it, and dumps a memory block.

bt_log_write_errno():
    Logs an initial message, the string of the current `errno`, and
    a message (no formatting).

bt_log_write_errno_printf():
    Logs an initial message, the string of the current `errno`, and
    a formatted message.

All the functions above accept a file name, a function name, a line
number, a log level, and a tag. They log unconditionally, meaning they
don't check any current (run-time) log level. Use BT_LOG_ON_CUR_LVL() or
BT_LOG_ON() for that (unchanged).

All the BT_LOG_WRITE*() macros expand to calling the functions above. I
didn't change the BT_LOGT*(), BT_LOGD*(), BT_LOGI*(), BT_LOGW*(),
BT_LOGE*(), and BT_LOGF*() ones, but the BT_LOG_WRITE*() ones now have
`PRINTF` in their name when there's formatting (they didn't before):

* BT_LOG_WRITE_CUR_LVL()
* BT_LOG_WRITE()
* BT_LOG_WRITE_PRINTF_CUR_LVL()
* BT_LOG_WRITE_PRINTF()
* BT_LOG_WRITE_MEM_CUR_LVL()
* BT_LOG_WRITE_MEM()
* BT_LOG_WRITE_MEM_PRINTF_CUR_LVL()
* BT_LOG_WRITE_MEM_PRINTF()
* BT_LOG_WRITE_ERRNO_CUR_LVL()
* BT_LOG_WRITE_ERRNO()
* BT_LOG_WRITE_ERRNO_PRINTF_CUR_LVL()
* BT_LOG_WRITE_ERRNO_PRINTF()

Everything else is meant to work as before.

`log-api.c` is considerably simpler (than the previous `log.c`),
implementing exactly what we need in the project and no more. The only
output format is the current colored one (not configurable) and the only
destination is the standard error stream.

I did rewrite the memory block printing while being here. It used to
look like this:

    554889e5534883ec4864488b042528000000488945e831c04883ec086a17488d  UH??SH??HdH??%(???H?E?1?H???j?H?
    0520c900005068800000004c8d0dceffffff4c8d05f3c80000b903000000ba22  ? ???Ph????L??????L????????????"
    000000488d05e7c800004889c6488d05ecc800004889c7b800000000e8a6bb00  ???H??????H??H??????H???????????
    004883c420488d45d0be000000004889c7e88a090000488d45d04889c7e8e715  ?H?? H?E??????H???????H?E?H?????

and now looks like this:

    55 48 89 e5 53 48 83 ec 48 64 48 8b 04 25 28 00 | UH..SH..HdH..%(.
    00 00 48 89 45 e8 31 c0 48 83 ec 08 6a 17 48 8d | ..H.E.1.H...j.H.
    05 50 b9 00 00 50 6a 64 4c 8d 0d d1 ff ff ff 4c | .P...PjdL......L
    8d 05 26 b9 00 00 b9 03 00 00 00 ba 22 00 00 00 | ..&........."...
    48 8d 05 1a b9 00 00 48 89 c6 48 8d 05 15 b9 00 | H......H..H.....
    00 48 89 c7 b8 00 00 00 00 e8 98 ac 00 00 48 83 | .H............H.
    c4 20 48 8d                                     | . H.

I find that my version is more readable. The number of bytes/line is
fixed (16, like the default of `od` and `hexdump`).

I made the formatted date/time string cache much more simple, simply
using a TLS variable. Now it's just:

    struct date_time_cache {
        uint64_t s;
        uint32_t ms;
        char str[128];
    };

    static __thread struct date_time_cache date_time_cache = {0};

We're already using a TLS variable for the message buffer.

`log.c` used to call WriteFile(), GetLocalTime(), and
GetCurrentProcessId(), but I believe we have access to some MinGW magic
making it possible to call write(), gettimeofday(), and getpid(). The
TID part remains very platform-specific.

If we ever need new logging features, we can easily implement them, or
cherry-pick them from zf_log if they exist.

Project files are adapted here and there, mostly to match the few
renamed functions and macros.

[1]: https://github.com/wonder-mice/zf_log

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

4 months agocpp-common: move `nlohmann/json.hpp` to `vendor`
Philippe Proulx [Wed, 15 Nov 2023 06:10:16 +0000 (01:10 -0500)] 
cpp-common: move `nlohmann/json.hpp` to `vendor`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Idb5725a6a4655cee2f99300308b45236300134e2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11394
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common: add `bt2s::string_view`, alias of `bpstd::string_view`
Philippe Proulx [Wed, 15 Nov 2023 05:37:27 +0000 (00:37 -0500)] 
cpp-common: add `bt2s::string_view`, alias of `bpstd::string_view`

In order to avoid having all sorts of external namespaces, make
`bt2s::string_view` an alias of `nonstd::string_view`, and make sure
everything in the project uses `bt2s::string_view`.

Also add aliases for other STL types of `<string_view>`, like the
`bt2s::basic_string_view` class template.

This will make it possible to easily change the implementation without
changing the code using it indirectly (only
`cpp-common/bt2s/string-view.hpp` will change).

Move `cpp-common/string_view.hpp` to
`cpp-common/vendor/string_view-standalone/string_view.hpp` to make it
clear it's an external project.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5172f642f5490b4a7eb21ed7cca55039452dc9b8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11392
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common: add `bt2s::optional`, alias of `nonstd::optional`
Simon Marchi [Mon, 11 Dec 2023 21:07:18 +0000 (16:07 -0500)] 
cpp-common: add `bt2s::optional`, alias of `nonstd::optional`

In order to avoid having all sorts of external namespaces, make
`bt2s::optional` an alias of `nonstd::optional`, and make sure
everything in the project uses `bt2s::optional`.

Also add aliases for other STL types and functions of `<optional>`.

This will make it possible to easily change the implementation without
changing the code using it indirectly (only
`cpp-common/bt2s/optional.hpp` will change).

Move `cpp-common/optional.hpp` to
`cpp-common/vendor/optional-lite/optional.hpp` to make it clear it's an
external project.

Making everything under `cpp-common/vendor` an exception in
`tools/format-cpp.sh`.

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

4 months agocpp-common: rename bt2c::makeUnique() -> bt2s::make_unique()
Philippe Proulx [Wed, 15 Nov 2023 04:47:38 +0000 (23:47 -0500)] 
cpp-common: rename bt2c::makeUnique() -> bt2s::make_unique()

I now want everything mimicking the STL stuff to have the same names,
but I don't want to mix coding styles in `bt2c`.

Therefore introduce this new `bt2s` (the `s` stands for `std`) namespace
to contain everything acting as the STL (or Boost, if need be).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie24c11170cc650028f3ce50fcab2004f0195c12f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11393
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common: rename `bt2_common` namespace -> `bt2c`
Simon Marchi [Mon, 11 Dec 2023 21:05:13 +0000 (16:05 -0500)] 
cpp-common: rename `bt2_common` namespace -> `bt2c`

I always end up using the `bt2c` namespace alias in `*.cpp` files
anyway.

Also put all the `bt2c` stuff in `cpp-common/bt2c` to make it clear.

What remains in `cpp-common`, but outside `cpp-common/bt2c`, are the
libbabeltrace2 C++ bindings (`bt2` namespace) and external projects.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ife8527aa961025f28d06707eb9f374cafea572f5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11390
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common: remove `cfg-*.hpp` and `log-cfg.hpp`
Philippe Proulx [Tue, 14 Nov 2023 20:27:01 +0000 (15:27 -0500)] 
cpp-common: remove `cfg-*.hpp` and `log-cfg.hpp`

Those are not used currently and I plan to replace them with something
more woke for C++.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ied48a1f6a5c32426a8d85e32c6a5682c48dd4e42
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11389
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2: add bt2::wrap() overloads
Philippe Proulx [Sat, 4 Nov 2023 19:34:09 +0000 (15:34 -0400)] 
cpp-common/bt2: add bt2::wrap() overloads

You may now call bt2::wrap() with any libbabeltrace2 object pointer with
which you could build a borrowed object wrapper. Therefore, this
excludes `bt2::MessageArray` which is a special case (ownership is
transferred).

For example:

    void f(bt_value * const val)
    {
        const auto wrappedVal = bt2::wrap(val);

        if (wrappedVal.isUnsignedInteger()) {
            *wrappedVal = 23;
        }

        // ...
    }

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

4 months agocpp-common/bt2: add `bt2::SelfComponentClass`
Philippe Proulx [Fri, 1 Dec 2023 19:50:32 +0000 (14:50 -0500)] 
cpp-common/bt2: add `bt2::SelfComponentClass`

A very straightforward wrapper of `bt_self_component_class`.

I didn't bother wrapping the individual
`bt_self_component_class_source`, `bt_self_component_class_filter`, and
`bt_self_component_class_sink` as they don't offer anything more.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie96c61ba723d54ff720df9147279d7826dcf8fae
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11480
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2: add `bt2::PrivateQueryExecutor`
Philippe Proulx [Wed, 8 Nov 2023 14:53:39 +0000 (09:53 -0500)] 
cpp-common/bt2: add `bt2::PrivateQueryExecutor`

A very straightforward wrapper of `bt_private_query_executor`.

There should exist an asConstQueryExecutor() method, but
`bt2::ConstQueryExecutor` doesn't exist yet as we don't need it to write
plugins. Therefore the loggingLevel() and isInterrupted() use
bt_private_query_executor_as_query_executor_const() internally.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I87c26e14afa4aa7937692aefa981213ad6a7f566
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11298
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add `bt2::SelfMessageIteratorConfiguration`
Philippe Proulx [Mon, 6 Nov 2023 19:23:17 +0000 (14:23 -0500)] 
cpp-common/bt2: add `bt2::SelfMessageIteratorConfiguration`

A very straightforward wrapper of
`bt_self_message_iterator_configuration`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0a31ee1feb1eefc7f6de3d87a4f43963d75b3274
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11272
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2: add `bt2::SelfMessageIterator`
Philippe Proulx [Sat, 4 Nov 2023 17:40:43 +0000 (13:40 -0400)] 
cpp-common/bt2: add `bt2::SelfMessageIterator`

This patch introduces `bt2::SelfMessageIterator` which wraps
`bt_self_message_iterator`.

This is the last piece of C++ binding needed to write a complete
component class in C++, immediately wrapping the component class and
message iterator class methods parameters.

`bt2::SelfMessageIterator` offers:

createMessageIterator():
    Create a message iterator from this message iterator:

        auto msgIter = selfMsgIter.createMessageIterator(
                           selfMsgIter.component().inputPorts()["in"]);

component():
    Borrow the parent self component.

    This is usually used to retrieve some component data:

        selfMsgIter.component().data<MyComponentData>();

port():
    Borrow the output port from which this message iterator operates.

isInterrupted():
    Whether or not this message iterator is interrupted.

data():
    Get and set user data.

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

4 months agocpp-common/bt2: add `bt2::Self*Component` and `bt2::SelfComponent*Port`
Philippe Proulx [Thu, 2 Nov 2023 21:04:36 +0000 (17:04 -0400)] 
cpp-common/bt2: add `bt2::Self*Component` and `bt2::SelfComponent*Port`

This new file is an adaptation of `component-port.hpp` and works the
same way.

That being said, I didn't bother:

* Making equivalent objects in `component-port.hpp` accept the "self"
  versions.

  In theory, you could build a `bt2::ConstSourceComponent` from a
  `bt2::SelfSourceComponent`, for example, but I believe we won't do
  that often, if ever.

  Therefore you'll need to use the asConstComponent() and asConstPort()
  methods explicitly.

  However, I added aliases in the new classes to avoid going calling
  those in most situations. For example,
  bt2::SelfFilterComponent::name() calls bt2::SelfComponent::name()
  which calls bt2::ConstComponent::name().

* Implementing the constant versions of the new classes, for example
  `bt2::ConstSelfComponent`.

  For example, a method which would benefit this is
  bt2::SelfSinkComponent::isInterrupted().

  Again, I don't think we'll need this. The "self" wrappers are for the
  component class author, and she rarely needs a constant view of its
  own object.

Add a port to a self component with the addInputPort() or
addOutputPort() methods, which return a borrowed reference of the
created and added port. Those methods have an overload which accepts
user data to store into the returned port.

Create a message iterator from a self sink component with
bt2::SelfSinkComponent::createMessageIterator().

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id6bcbfcea4a562780eee0700cee507431c4e5661
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11235
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2: add `bt2::MessageIterator`
Philippe Proulx [Wed, 1 Nov 2023 20:33:19 +0000 (16:33 -0400)] 
cpp-common/bt2: add `bt2::MessageIterator`

This patch adds `bt2::MessageIterator` to wrap `bt_message_iterator`
objects.

`bt2::MessageIterator` offers:

component():
    Borrows the parent component of the message iterator.

next():
    Returns the next batch of messages.

    This method returns an optional message array: set if there are
    messages (`BT_MESSAGE_ITERATOR_NEXT_STATUS_OK`), or not set on end
    of iteration (`BT_MESSAGE_ITERATOR_NEXT_STATUS_END`).

    Throws otherwise.

    Example:

        if (const auto msgs = myMsgIter.next()) {
            for (const auto msg : *msgs) {
                if (msg.isEvent()) {
                    // ...
                }
            }
        } else {
            // This is the end, my only friend, the end
        }

canSeekBeginning():
    Wraps bt_message_iterator_can_seek_beginning().

seekBeginning():
    Wraps bt_message_iterator_seek_beginning().

canSeekNsFromOrigin():
    Wraps bt_message_iterator_can_seek_ns_from_origin().

seekNsFromOrigin():
    Wraps bt_message_iterator_seek_ns_from_origin().

canSeekForward():
    Wraps bt_message_iterator_can_seek_forward().

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

4 months agocpp-common/bt2: add `bt2::Const*Component` and `bt2::Const*Port`
Philippe Proulx [Wed, 1 Nov 2023 03:03:36 +0000 (23:03 -0400)] 
cpp-common/bt2: add `bt2::Const*Component` and `bt2::Const*Port`

This patch adds the `bt2::ConstComponent`, `bt2::ConstSourceComponent`,
`bt2::ConstFilterComponent`, and `bt2::ConstSinkComponent` wrapper
classes to wrap resp. `const bt_component`, `const bt_component_source`,
`const bt_component_filter`, and `const bt_component_sink`.

I didn't find a clever way to make `bt2::ConstSourceComponent`, for
example, inherit `bt2::ConstComponent`, because they manage different
library types (`const bt_component` vs. `const bt_component_source`). I
think this is a first in `src/cpp-common/bt2` for this situation: for
example, all value objects have the `bt_value` type, all field classes
have the `bt_field_class` type, and so on, making it possible to also
express the intended relations in C++.

I though about using a library upcasting function (for example,
bt_component_source_as_component_const()) to call the parent
constructor, but then there would be no "safe" way to return to
`const bt_component_source` because there aren't downcasting functions
(`reinterpret_cast<const bt_component_source *>()` would probably work,
but isn't super legit).

Therefore there's no relation between specific component wrapper classes
and `bt2::ConstComponent`. That being said, `bt2::ConstComponent` is
courteous and offers all the copy constructors and assignment operators
to copy and assign from specific component wrappers. For example:

    void f(const bt2::ConstComponent myComp)
    {
        // ...
    }

    void g(const bt_component_source * const libCompPtr)
    {
        const bt2::ConstComponent comp {libCompPtr};
        const bt2::ConstSourceComponent srcComp {libCompPtr};

        f(srcComp);
    }

However, the shared versions aren't directly compatible because the
reference count functions aren't the same (an obvious requirement to
construct a shared object from another one). To make things easier, each
specific component wrapper class has the sharedComponent() method which
returns a `bt2::ConstComponent::Shared` instance:

    void f(bt2::ConstComponent::Shared myComp)
    {
        // ...
    }

    void g(bt2::ConstSourceComponent::Shared srcComp)
    {
        f(srcComp->sharedComponent());
    }

Each specific component wrapper class kindly offers the name() and
loggingLevel() methods to avoid going to a `bt2::ConstComponent` by
hand.

Each specific component wrapper class has its inputPorts() and/or
outputPorts() method(s). Those return an instance of
`bt2::ConstComponentPorts` with the appropriate template arguments to
make things just work. `bt2::ConstComponentPorts` has the length()
method and various `[]` operators to access ports:

    mySrc.outputPorts()[3]

    myFlt.inputPorts()["file2"]

The returned object is one of `bt2::ConstInputPort` or
`bt2::ConstOutputPort` wrapping resp. `const bt_port_input` and
`const bt_port_output`.

Component and port wrapper classes are part of the same header,
`component-port.hpp`, for the same reason all high-level trace IR
wrapper classes are in the single `trace-ir.hpp`: a port object may
return a component (component() method) and a component object may
return a port (inputPorts()/outputPorts() methods), making it difficult,
if not impossible, to use two different headers because we don't know
the inclusion order of the user.

Because the libbabeltrace2 API always deals with specific (input or
output) port objects, there's no `const bt_port` wrapper class: you
always use `bt2::ConstInputPort` or `bt2::ConstOutputPort`. In other
words, no API function returns a general `const bt_port` pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1324a59c8291cb83a432eeb7477c6b3e353924f5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11184
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
4 months agocpp-common/bt2: add `bt2::ConstMessageArray`
Philippe Proulx [Thu, 26 Oct 2023 14:43:05 +0000 (10:43 -0400)] 
cpp-common/bt2: add `bt2::ConstMessageArray`

A `bt2::ConstMessageArray` instance wraps an array of `const` messages
(`bt_message_array_const`) which is used in everything related to "next"
message iterator methods.

There are two ways to build such a wrapper:

1. Use bt2::ConstMessageArray::wrapExisting() to wrap an existing
   library message array with a given length:

       bt_message_array_const libMsgs;
       uint64_t count;

       if (bt_message_iterator_next(myIter, &libMsgs, &count) !=
               BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) {
           // Handle special status
       }

       const auto msgs = bt2::ConstMessageArray::wrapExisting(libMsgs,
                                                              count);

       ⭐

       if (!msgs[0].isEvent()) {
           // ...
       }

       for (const auto msg : msgs) {
           // Handle `msg`
       }

   At ⭐, `msgs` is now the owner of the messages of `libMsgs`,
   meaning:

   a) Its destructor puts all the contained message references.

   b) Do NOT put the message references of `libMsgs` yourself with
      bt_message_put_ref().

   c) Do NOT make another `ConstMessageArray` wrap `libMsgs`.

2. Use bt2::ConstMessageArray::wrapEmpty() to wrap an empty library
   message array with an explicit capacity:

       bt_message_iterator_class_next_method_status myNext(
               bt_self_message_iterator * const libSelfMsgIter,
               const bt_message_array_const libMsgs,
               const uint64_t capacity, uint64_t * const count)
       {
           auto msgs = bt2::ConstMessageArray::wrapEmpty(libMsgs,
                                                         capacity);

           // Create messages and append with `msgs.append(...)`

           *count = msgs.release();
           return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
       }

   If there's any thrown exception during the message appending part,
   the destructor of `msgs` will put the references of its messages.

   Then when you call ConstMessageArray::release(), you become the owner
   of the library array again. The returned value is its length before
   the release.

As you can see, this wrapper is a bit fragile and really on the "you
know what you're doing" territory, but I believe it can be useful and
safer when used as intended.

Conceptually, only one `ConstMessageArray` at a time may manage the
underlying library array. Therefore, copy operations are disabled, but
move operations are implemented.

Because the copy constructor isn't implemented, we can't use
`CommonIterator`, so `ConstMessageArrayIterator` is a dedicated,
lightweight version of the latter.

Get a message array length and capacity with the length() and
capacity() methods.

Check if a message array is empty or full with the isEmpty() and
isFull() methods.

Append a message to a message array with the append() method.

Release a message array with the release() method.

Borrow a message from a message array with the `[]` operator.

Iterate a message array with the begin() and end() methods.

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

4 months agocpp-common/bt2/shared-object.hpp: add newlines around declaration
Philippe Proulx [Mon, 13 Nov 2023 21:19:15 +0000 (16:19 -0500)] 
cpp-common/bt2/shared-object.hpp: add newlines around declaration

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2b8057771965feda011f3112effabd31023fd0dc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11372
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: do not use `bpstd::string_view`
Philippe Proulx [Mon, 13 Nov 2023 20:43:31 +0000 (15:43 -0500)] 
cpp-common/bt2: do not use `bpstd::string_view`

Using `bpstd::string_view` in those contexts was a mistake: building a
`bpstd::string_view` object from a null-terminated string requires to
get its length (think strlen()), and an optional string view requires to
return `nonstd::optional<bpstd::string_view>` which means checking the
library pointer first.

All this means it's not a zero cost, and zero cost is what those C++
bindings aim to be.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib51fb9e326c4b4c450a381631b9db69f6cd0530b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11370
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/field-class.hpp: coalesce `internal` namespace
Philippe Proulx [Mon, 13 Nov 2023 18:09:05 +0000 (13:09 -0500)] 
cpp-common/bt2/field-class.hpp: coalesce `internal` namespace

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8c23478a99da52fc19dddf22547f6e9ed0d0466f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11369
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: remove useless copy operations
Philippe Proulx [Wed, 8 Nov 2023 20:57:04 +0000 (15:57 -0500)] 
cpp-common/bt2: remove useless copy operations

This patch removes useless copy constructors and assignment operators
from many wrapper classes in `cpp-common/bt2` where the compiler
generates some anyway.

Also, return by value (like everywhere else) from pseudo copy
operations.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9e5b5e956905681c3a834122b3f0ed8311b5a6ae
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11302
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/borrowed-object.hpp: use BT_ASSERT_DBG()
Philippe Proulx [Wed, 8 Nov 2023 19:53:57 +0000 (14:53 -0500)] 
cpp-common/bt2/borrowed-object.hpp: use BT_ASSERT_DBG()

bt2::BorrowedObject::BorrowedObject() obviously deserves a
BT_ASSERT_DBG() here because it's a common constructor for all wrapper
classes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I05879bf2e6993fe836b57645e1451247008ac2ea
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11301
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/field.hpp: use raw value proxy for scalar classes
Philippe Proulx [Mon, 13 Nov 2023 20:32:19 +0000 (15:32 -0500)] 
cpp-common/bt2/field.hpp: use raw value proxy for scalar classes

This patch makes field wrappers behave like value wrappers regarding
raw value access.

Now, the `*` operator of boolean, integer, floating point number, and
string fields return a raw value proxy to access the raw value:

    void f(const bt2::UnsignedIntegerField val) {
        *val = 23;
        std::cout << *val << std::endl;
    }

I didn't do it for `bt2::CommonBitArrayField` which is a scalar field,
but it's still an array, so it felt weird. Instead, use valueAsInteger()
or bitValue() depending on your use case.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3bbcdc79a6dea781f720b7da8e18aea285d792b5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11371
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: use raw value proxy for scalar value classes
Philippe Proulx [Sat, 11 Nov 2023 16:46:36 +0000 (11:46 -0500)] 
cpp-common/bt2: use raw value proxy for scalar value classes

This patch adds the `bt2::RawValueProxy` class of which an instance
contains a wrapper object `_mObj` and:

* Its `=` operator calls `_mObj.value()` to assign a value.
* Its raw value type operator returns what `_mObj.value()` returns.

Then, in scalar value wrapper classes of `value.hpp`:

* Remove the `=` operator which assigns a raw value.
* Add a value() method to assign a raw value.
* Add a `*` operator to return a raw value proxy containing this.

The goal of this patch is to avoid using the `=` operator on some value
object to both wrap another library object (pseudo copy assignment
operator) and assign a raw value. Now, to assign a raw value, you need
to "dereference" the wrapper object:

    void f(const bt2::UnsignedIntegerValue val) {
        *val = 23;
        std::cout << *val << std::endl;
    }

There's also `bt2::RawStringValueProxy` which adds the `=` operator to
`bt2::RawValueProxy` to assign a `const std::string&`.
`bt2::CommonStringValue` uses it.

Additionally, remove all the `=` operators to assign a raw value on
`bt2::CommonValue` and create a "master" raw value proxy class
(`CommonValueRawValueProxy`) to have all the `=` operators and raw value
type operators:

    void f(const bt2::Value val) {
        // We know it's a boolean value
        *val = true;
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia8559de36baba3021169b3d097ec83b914407f63
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11362
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/value.hpp: add proxy methods to `bt2::CommonValue`
Philippe Proulx [Sat, 4 Nov 2023 20:43:11 +0000 (16:43 -0400)] 
cpp-common/bt2/value.hpp: add proxy methods to `bt2::CommonValue`

Those new methods on `bt2::CommonValue` call the corresponding method
while "converting" the current object to another type for the user.

For example:

    void f(const bt2::Value val)
    {
        // We know it's a string value
        val = "mireille";
    }

This is just sugar for common value operations to avoid the redundancy
of calling as*().

The as*() methods already have BT_ASSERT_DBG() lines to make sure that
the conversion is valid.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I475bda3754a984cbd2eca98f5caa14c765ece956
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11241
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: remove useless `_ThisXyz` type aliases
Philippe Proulx [Sat, 4 Nov 2023 20:04:46 +0000 (16:04 -0400)] 
cpp-common/bt2: remove useless `_ThisXyz` type aliases

Name is injected so those private `_ThisXyz` type aliases are useless.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4313729f63f4fe74622517d19dd986bd3393766b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11239
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/value.hpp: move static assertion (wrong place)
Philippe Proulx [Sat, 4 Nov 2023 19:41:37 +0000 (15:41 -0400)] 
cpp-common/bt2/value.hpp: move static assertion (wrong place)

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3384fdcf4f570a2f15062bf64af3ac27d0caee72
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11238
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: rework `bt2::CommonIterator` (now `bt2::BorrowedObjectIterator`)
Simon Marchi [Mon, 11 Dec 2023 20:03:50 +0000 (15:03 -0500)] 
cpp-common/bt2: rework `bt2::CommonIterator` (now `bt2::BorrowedObjectIterator`)

We don't need all the STL stuff (and constraints) currently, therefore
this iterator class may be simpler, making operator*() call
ContainerT::operator[]() directly instead of keeping a temporary wrapper
object and having a conditional for each iteration increment.

Making operator->() return a proxy because the iterator instance has no
persistent wrapper instance.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1bdb254a37533b8524450b22aa7f25a4d8025c2c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11236
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add `bt2::BorrowedObjectProxy`
Philippe Proulx [Tue, 5 Dec 2023 14:46:25 +0000 (09:46 -0500)] 
cpp-common/bt2: add `bt2::BorrowedObjectProxy`

When bt2::Something::operator->() would need to return the address of
some `ObjT` instance, but none is available (because it only keeps the
libbabeltrace2 object pointer, not a built wrapper), then it can use
this new `bt2::BorrowedObjectProxy`.

This new class template accepts a library pointer at construction time,
constructs an internal `ObjT` instance, and its own operator->() method
returns the address of the latter.

Example:

    class Something
    {
        // ...

    public:
        BorrowedObjectProxy<SomeObject> operator->() const noexcept
        {
            return BorrowedObjectProxy<SomeObject> {_mLibObjPtr};
        }

    private:
        const bt_some_object *_mLibObjPtr;
    };

Then, with a `Something` instance `something`:

    something->methodOfSomeObject(...);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I67d63591fb6593080a15e2ab6804a53bd2d2aba8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11487
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add and use `bt2::internal::Dep*` type alias templates
Philippe Proulx [Fri, 3 Nov 2023 18:48:52 +0000 (14:48 -0400)] 
cpp-common/bt2: add and use `bt2::internal::Dep*` type alias templates

Those new templates take care of using `std::conditional` instead of
having to use it at each site. The template parameters of
`bt2::internal::DepType` are:

1. What to check for constness.
2. The effective type if `LibObjT` is NOT `const`.
3. The effective type if `LibObjT` is `const`.

Other `bt2::internal::Dep*` reuse `DepType` with specific types for
parameters 2 and 3 for common uses.

For example:

    using UserAttributes =
        typename std::conditional<std::is_const<LibObjT>::value,
                                  ConstMapValue,
                                  MapValue>::type;

gets replaced by:

    using UserAttributes = internal::DepUserAttrs<LibObjT>;

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I434b9ae82d170c6fe8359488e78c0e3e34a064cd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11234
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: use more specific static assertion messages
Philippe Proulx [Sat, 11 Nov 2023 03:36:09 +0000 (22:36 -0500)] 
cpp-common/bt2: use more specific static assertion messages

The current

    `LibObjT` must NOT be `const`.

static assertion message is pretty generic. For a typical
`bt2::ConstXyz` user, `LibObjT` actually means nothing, because she's
not using `bt2::CommonXyz` directly, only an alias.

Make the message specific, for example:

    Not available with `bt2::ConstBoolValue`.

For example, with:

    void lel(bt2::ConstBoolValue val)
    {
        val = false;
    }

I get:

    cpp-common/bt2/value.hpp: In instantiation of ‘bt2::CommonBoolValue<LibObjT>& bt2::CommonBoolValue<LibObjT>::operator=(Value) const [with LibObjT = const bt_value; Value = bool]’:
    test.cpp:61:11:   required from here
    cpp-common/bt2/value.hpp:349:48: error: static assertion failed: Not available with `bt2::ConstBoolValue`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4e96d4dcd1cc345d8b393aea6bb78fbc0000e9ba
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11361
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add asConst() methods
Philippe Proulx [Fri, 3 Nov 2023 17:26:55 +0000 (13:26 -0400)] 
cpp-common/bt2: add asConst() methods

Add many asConst() methods to get the `bt2::ConstXyz` version of a
`bt2::Xyz` wrapper instead of using the constructor directly.

Just some sugar.

For example:

    void f(const bt2::Value val) {
        {
            const auto cVal = val.asConst();

            // Operate on `cVal`
        }
    }

I only added those methods where it was easy to do so.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iabd9d6266fe75f33f2008c2320444624b842d9d2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11232
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: use the "length" term everywhere instead of "size"
Philippe Proulx [Fri, 3 Nov 2023 16:03:02 +0000 (12:03 -0400)] 
cpp-common/bt2: use the "length" term everywhere instead of "size"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I25ce7709679d016dff6b23aa323a0ca5ec738190
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11231
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: remove useless friend classes to access libObjPtr()
Philippe Proulx [Fri, 3 Nov 2023 15:56:49 +0000 (11:56 -0400)] 
cpp-common/bt2: remove useless friend classes to access libObjPtr()

Mr. Deslauriers made bt2::BorrowedObj::libObjPtr() public in 341a67c45
("cpp-common: Expose BorrowedObj::libObjPtr() as public method").

Therefore, all those friend classes aren't needed anymore.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie37bfa78e4cd29dd8e08af135ff6a0e597ebd0ae
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11230
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add `noexcept` to user attribute setters
Philippe Proulx [Fri, 3 Nov 2023 15:50:52 +0000 (11:50 -0400)] 
cpp-common/bt2: add `noexcept` to user attribute setters

The bt_*_set_user_attributes() functions never fail (they only increment
the reference count of the received value), therefore the user attribute
setters never throw.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5b9c05e6efd7b42965b9e075438b518df1a5da90
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11229
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: systematize the `const` method situation
Philippe Proulx [Fri, 3 Nov 2023 15:32:49 +0000 (11:32 -0400)] 
cpp-common/bt2: systematize the `const` method situation

This patch attempts to systematize the `const` situation regarding
methods (member functions and operators).

The current issue is that, because those wrappers are expected to be
passed and returned by copy (they only wrap a libbabeltrace2 pointer),
one cannot rely on the `const` qualifier to ensure immutability at the
library level. For example:

    void f(const bt2::ArrayValue val)
    {
        // Want to modify what `val` wraps? No problem:
        auto newVal = val;

        newVal += 23;
    }

The signature of f() here doesn't guarantee to the caller that what
`val` wraps is immutable. To achieve this, it needs to accept the
`Const` version of the wrapper:

    void f(bt2::ConstArrayValue val)
    {
        // Now there's no way to modify what `val` wraps
    }

Therefore, since using the `const` keyword is so fragile, this patch
makes `const` (almost) all the methods of wrapper classes: those methods
do not modify the wrapped pointer value, therefore they may be `const`.

This makes the wrapping system have this correspondence:

          bt_xyz *                    bt2::Xyz
          bt_xyz * const        const bt2::Xyz
    const bt_xyz *                    bt2::ConstXyz
    const bt_xyz * const        const bt2::ConstXyz

Because there were many overloads to return a `bt2::Const*` instance
when the object is `const`, this patch removes a lot of code, with the
added benefit of reducing code duplication.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie633e7e9d67a8eb0138800ad8ae14c8d9bd0ca4c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11228
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: add missing `noexcept` to static methods
Philippe Proulx [Wed, 1 Nov 2023 20:53:54 +0000 (16:53 -0400)] 
cpp-common/bt2: add missing `noexcept` to static methods

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3737dc68a270446e9eafee23afb24fc816ca2bbc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11193
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: rename `common-iter.hpp` to `common-iterator.hpp`
Philippe Proulx [Fri, 27 Oct 2023 18:52:32 +0000 (14:52 -0400)] 
cpp-common/bt2: rename `common-iter.hpp` to `common-iterator.hpp`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4816ab3ecf2b19423f8ab0a92924e62c438df4f9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11164
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: remove superfluous NL
Philippe Proulx [Fri, 27 Oct 2023 18:35:02 +0000 (14:35 -0400)] 
cpp-common/bt2: remove superfluous NL

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I96252e134bb355e2e1b0b43cf4f13a13b5ed4c7e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11163
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/common-iter.hpp: add missing NL
Philippe Proulx [Fri, 27 Oct 2023 18:33:40 +0000 (14:33 -0400)] 
cpp-common/bt2/common-iter.hpp: add missing NL

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I57b2b54a5181e1cee90cd9090d349bf058e9025b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11162
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: rename `bt2::SharedObj` -> `bt2::SharedObject`
Philippe Proulx [Mon, 13 Nov 2023 19:49:26 +0000 (14:49 -0500)] 
cpp-common/bt2: rename `bt2::SharedObj` -> `bt2::SharedObject`

This is public now, so use the full name without abbreviation like
everything else does.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1328a9c195061558ca442aed6e177ca43836b99c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11368
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: `bt2::internal::SharedObj` -> `bt2::SharedObj`
Philippe Proulx [Mon, 13 Nov 2023 18:52:39 +0000 (13:52 -0500)] 
cpp-common/bt2: `bt2::internal::SharedObj` -> `bt2::SharedObj`

`SharedObj` is not completely internal: it offers public methods,
including creation methods.

Also, we don't need to hide anything from the end user in this file.

Therefore make this class not internal.

Also apply to specific shared object aliases, for example
`bt2::SharedValue`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8bf1718a95de87b7c506ffab4868e63bc57a7391
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11367
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: rename `bt2::BorrowedObj` -> `bt2::BorrowedObject`
Philippe Proulx [Mon, 13 Nov 2023 19:15:33 +0000 (14:15 -0500)] 
cpp-common/bt2: rename `bt2::BorrowedObj` -> `bt2::BorrowedObject`

This is public now, so use the full name without abbreviation like
everything else does.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9716e1c5b60a06211f2292e71df574a2924e862f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11366
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2: `bt2::internal::BorrowedObj` -> `bt2::BorrowedObj`
Simon Marchi [Mon, 11 Dec 2023 20:03:04 +0000 (15:03 -0500)] 
cpp-common/bt2: `bt2::internal::BorrowedObj` -> `bt2::BorrowedObj`

`BorrowedObj` is not completely internal: it has public methods which
any concrete borrowed object inherits.

Also, we don't need to hide anything from the end user in this file.

Therefore make this base class not internal.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib3a396a1aa7794608a4ec938f9b141c553e36c97
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11365
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agocpp-common/bt2/borrowed-obj.hpp: remove unused `SharedObj` forward decl.
Philippe Proulx [Mon, 13 Nov 2023 19:55:13 +0000 (14:55 -0500)] 
cpp-common/bt2/borrowed-obj.hpp: remove unused `SharedObj` forward decl.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I59f9cdd1bfd98bd4e37b4045b4ecf0dbda5b222d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11364
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
4 months agoAdd IWYU keep pragmas when including some compat headers
Simon Marchi [Mon, 11 Dec 2023 18:59:38 +0000 (13:59 -0500)] 
Add IWYU keep pragmas when including some compat headers

When editing some on Linux, IWYU and clangd report some inclusions of
`compat/endian.h`, for instance, as unused.   This is because this
header defines some macros only on systems that lack them, and Linux
isn't one of them.  These includes should not be removed, so add some
pragmas to let tools (and even humans) know that they are important.

Change-Id: Id2cba11a568567e6a75d094df3567b0847dac690
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11518
Tested-by: jenkins <jenkins@lttng.org>
4 months agoAdd some includes in C++ header files
Simon Marchi [Sun, 10 Dec 2023 04:35:00 +0000 (23:35 -0500)] 
Add some includes in C++ header files

Add some includes to fix errors shown by clangd when editing header
files.  These don't fix compilation errors.

Change-Id: I1792b50c5808d9a9c3f045decea97745aac6a77f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11496
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agoRemove some unused includes in C++ files
Simon Marchi [Thu, 7 Dec 2023 21:54:24 +0000 (21:54 +0000)] 
Remove some unused includes in C++ files

Remove some unused include files.  This was done partly looking at
"unused-includes" warnings from clangd in my IDE, and partly with
include-what-you-use.

Whenever needed, add some includes to keep things compiling (where
some header files relied on previous inclusions).

Change-Id: I0bca7aba4c172a13474a76b08e4a0b543e152733
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11493
Tested-by: jenkins <jenkins@lttng.org>
4 months agoinclude: add IWYU pragmas in private header files
Simon Marchi [Thu, 7 Dec 2023 22:08:22 +0000 (22:08 +0000)] 
include: add IWYU pragmas in private header files

Add Include What You Use "private" pragmas in the private header files
exported by babeltrace 2, indicating that <babeltrace2/babeltrace.h>
should be used instead.

Change-Id: I7b7bdde4ab52012b4b57d5c7739e7910a5321f9c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11491
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
4 months agoRemove stdbool.h includes from C++ files
Simon Marchi [Thu, 7 Dec 2023 21:53:12 +0000 (21:53 +0000)] 
Remove stdbool.h includes from C++ files

This header is unnecessary in C++.

Change-Id: I4d3cbacc4805630181536069406d6eb8daded38f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11490
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 months agoSort includes in C++ files
Simon Marchi [Wed, 29 Nov 2023 15:48:40 +0000 (10:48 -0500)] 
Sort includes in C++ files

Set the `SortIncludes` option of clang-format to `Regroup`, meaning that
it will group include statements based on the categories in
`IncludeCategories`.

In `IncludeCategories`, define categories such that the groups are (in
order of priority):

  1. C++ system headers
  2. C system headers
  3. Babeltrace 2 public headers
  4. Logging headers (logging/log.h, as well as other header files
     including it): it might be important for these files to stay at the
     top, in case there is some logging in header files, so that things
     like log tags are properly set.
  5  Internal common headers (e.g. from common, cpp-common, compat,
     logging)
  6. Plugin common files (from plugins/common)
  7. Local headers
  8. tap/tap.h: it defines macros with common names, such as `ok` and
     `fail`, which may clash with identifiers in other headers.  It's
     safer to keep it last.

Includes in files parser.ypp and lexer.lpp were sorted by hand.  Due to
the change in inclusion order, parser.hpp (generated from parser.ypp)
did not see the definition of yyscan_t anymore.  Add an inclusion of
scanner.hpp in the `%code requires` section, which ends up in both the
generated .cpp and .hpp files.

Change-Id: I0568167065b90070ac03ea4daf4d0a1927bec4b5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11459
Tested-by: jenkins <jenkins@lttng.org>
5 months agotests: normalize inclusions of tap/tap.h
Simon Marchi [Wed, 29 Nov 2023 15:47:03 +0000 (10:47 -0500)] 
tests: normalize inclusions of tap/tap.h

Use "tap/tap.h" instead of <tap/tap.h> everywhere.

Move the inclusion at the end of the inclusion list everywhere.  tap.h
defines macros with common names like `ok` and `fail`, which can clash
if defined before including other files.  Let's establish the practice
of including tap.h last.

Change-Id: Ic06f59d146390d6fe21a6ac229972df02ce8d762
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11461
Tested-by: jenkins <jenkins@lttng.org>
5 months agoRemove unnecessary inclusions of "internal public" headers
Simon Marchi [Tue, 28 Nov 2023 20:40:47 +0000 (15:40 -0500)] 
Remove unnecessary inclusions of "internal public" headers

I believe that these spots don't really need to include files from
babeltrace2 other than babeltrace.h.  In fact, given the presence of:

    #ifndef __BT_IN_BABELTRACE_H
    # error "Please include <babeltrace2/babeltrace.h> instead."
    #endif

in those "internal public" header files and the fact that the including
files don't define __BT_IN_BABELTRACE_H, I believe that those inclusions
don't have an effect.  It must be that the included file was already
included earlier, as part of babeltrace.h.

Change-Id: I9f88123f12f916dea8c90641dd7b32c531f5c707
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11458
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 months agolib: validate iterator message sequence
Simon Marchi [Fri, 10 Nov 2023 20:26:15 +0000 (20:26 +0000)] 
lib: validate iterator message sequence

Validate that the sequence of messages produced by iterators respects
the sequence defined by the Message Interchange Protocol (MIP) [1].

    Without packets
        SB (E | DE)* SE

    With packets
        SB ((PB (E | DE)* PE) | DE | DP)* SE

Validate that when an iterator returns
BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END, all streams are
properly ended (we have received a stream end message for all streams).

Add an expected_msg_types field to the iterator's per_stream_state
structure, which holds a bit mask of the message types the iterator is
allowed to emit next.

Use the cur_packet field that is maintained by
message_packet_is_valid when processing a discarded events message.  We
need to know if we are in a packet or not to determine the following
valid message types (DE appears twice in the "With packets" sequence
above, once within a packet and once outside a packet).

It doesn't matter in which order the two assertions are placed, since
the "sequence is as expected" assertion doesn't use the cur_packet field
when handling the "packet beginning" and "packet end" messages.
However, I think that it is more useful to have the "sequence is as
expected" first.  Some mistakes, like the following sequence where a
packet beginning message is forgotten:

    ... PB E E PE E E PE ...

... would cause both assertions to fail.  But the "sequence is as
expected" assertion points closer to the root cause of the problem than
the "packet is expected" one, which points more to a symptom.  So, if
both assertions would fail, I prefer that we show the "sequence is
as expected" one.

Here's an example of the error message that is printed when an error is
detected.  In this case, a packet beginning message was forgotten.

    Babeltrace 2 library postcondition not satisfied.
    ------------------------------------------------------------------------
    Condition ID: `post:message-iterator-class-next-method:mip-message-sequence-is-expected`.
    Function: bt_message_iterator_class_next_method().
    ------------------------------------------------------------------------
    Error is:
    MIP message sequence is not expected: stream-addr=0x60d000001d80, stream-id=0, iterator-addr=0x611000004c80, iterator-upstream-comp-name="source.gpx.GpxSource", iterator-upstream-comp-log-level=WARNING, iterator-upstream-comp-class-type=SOURCE, iterator-upstream-comp-class-name="GpxSource", iterator-upstream-comp-class-partial-descr="", message-addr=0x607000004540, message-type=EVENT, expected-msg-types=STREAM_END|PACKET_BEGINNING
    Aborting...

[1] https://babeltrace.org/docs/v2.0/libbabeltrace2/group__api-msg.html#api-msg-seq

Change-Id: I25d3ff9b87c551dcced1ba25e0a8525f316a8050
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10450
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 months agolib: validate iterator message packets
Simon Marchi [Thu, 22 Jun 2023 19:52:41 +0000 (15:52 -0400)] 
lib: validate iterator message packets

Validate that messages coming out of iterators have sensible packet
values.  This applies to event and packet end messages: their packet
must match the packet of the previous packet beginning message.

Add a hash table to hold per-stream state, inside the
bt_message_iterator structure.  Since this state will only be used for
dev assertions, for the moment, only create it if BT_DEV_MODE is
defined.

Discard the per-stream state when the iterator seeks (after which the
iterator is expected to produce a new message sequence, starting from
scratch).

If the iterator uses auto-seek to implement "seek ns from origin", we
need to discard the per-stream state twice: once after seeking the
beginning, and once after consuming messages until the desired point.

When a wrong packet is detected, print an error logging message with
some details, before the failed assertion message:

    Babeltrace 2 library postcondition not satisfied.
    ------------------------------------------------------------------------
    Condition ID: `post:message-iterator-class-next-method:message-packet-is-expected`.
    Function: bt_message_iterator_class_next_method().
    ------------------------------------------------------------------------
    Error is:
    Message's packet is not expected: stream-addr=0x60d000001d80, stream-id=0, iterator-addr=0x611000004c80, iterator-upstream-comp-name="source.gpx.GpxSource", iterator-upstream-comp-log-level=WARNING, iterator-upstream-comp-class-type=SOURCE, iterator-upstream-comp-class-name="GpxSource", iterator-upstream-comp-class-partial-descr="", message-addr=0x607000004540, message-type=EVENT, received-packet-addr=0x607000004310, expected-packet-addr=(nil)
    Aborting...

The particular structure of the code is explained by the following
patch, which adds verification that the message sequence is as expected.
Both assertions (packet is expected, and message sequence is as
expected) need to know about the current packet (this state is
maintained by message_packet_is_valid), so must be in the same "for all
messages" loop.  Alternatively, they could both track the current packet
independently, but that would be redundant.

But this form also allows putting more info about the problematic
message in the abort notice, which I think is nice.

Change-Id: I176417d9ae7b04a9c16ff975e008e208b173e3d2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10448
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 months agoFix REUSE licensing/copyright issues in `tests/utils`
Philippe Proulx [Tue, 14 Nov 2023 16:10:30 +0000 (11:10 -0500)] 
Fix REUSE licensing/copyright issues in `tests/utils`

This patch makes `reuse lint` happy for the files in `tests/utils`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I472089852d8840653c0a4a2350a4d4981329f43e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11385
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoFix REUSE licensing/copyright issues in `src`
Philippe Proulx [Tue, 14 Nov 2023 16:07:26 +0000 (11:07 -0500)] 
Fix REUSE licensing/copyright issues in `src`

This patch makes `reuse lint` happy for the files in `src`.

Putting the info into a separate `.license` file for
`src/cpp-common/optional.hpp` to avoid modifying the original file which
comes from an external project.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I073afa1b5de0906f4f9f2a809ef387c05833ca17
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11384
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoAdd SPDX info for `tests/utils/python/typing/typing.py`
Philippe Proulx [Tue, 14 Nov 2023 16:03:38 +0000 (11:03 -0500)] 
Add SPDX info for `tests/utils/python/typing/typing.py`

Putting the info in a separate `.license` file to avoid modifying the
original one (which comes from the CPython project).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: If183d9662f239da27a00b7f8ba8887eaec489270
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11383
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoAdd SPDX info to Python bindings documentation
Philippe Proulx [Tue, 14 Nov 2023 15:58:11 +0000 (10:58 -0500)] 
Add SPDX info to Python bindings documentation

The text and images have the `CC-BY-SA-4.0` license.

`LICENSES/CC-BY-SA-4.0.txt` already exists, but wasn't used.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I66428778d69cc4b44816cb6588283984d16f3d78
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11382
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoAdd missing REUSE licenses
Philippe Proulx [Tue, 14 Nov 2023 15:56:56 +0000 (10:56 -0500)] 
Add missing REUSE licenses

`reuse lint` says:

    # MISSING LICENSES

    'FSFAP' found in:
    * m4/ax_append_compile_flags.m4
    * m4/ax_append_flag.m4
    * m4/ax_check_compile_flag.m4
    * m4/ax_cxx_compile_stdcxx.m4
    * m4/ax_require_defined.m4
    'FSFULLR' found in:
    * m4/ae_python_modules.m4
    'GPL-2.0-or-later' found in:
    * m4/ax_c___attribute__.m4
    * m4/ax_pthread.m4
    * tests/utils/tap-driver.sh
    'LicenseRef-Autoconf-exception-macro' found in:
    * m4/ax_c___attribute__.m4
    * m4/ax_pthread.m4

Download and add them.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I71576e2ed2281a1890a49a5cb9261c11fe30706e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11381
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoLICENSES: add `.txt` extension to license files
Philippe Proulx [Tue, 14 Nov 2023 15:51:21 +0000 (10:51 -0500)] 
LICENSES: add `.txt` extension to license files

`reuse lint` says:

    # LICENSES WITHOUT FILE EXTENSION

    The following licenses have no file extension:
    * BSD-2-Clause
    * BSD-4-Clause
    * BSL-1.0
    * CC-BY-SA-4.0
    * GPL-2.0-only
    * GPL-3.0-or-later
    * LGPL-2.1-only
    * MIT
    * PSF-2.0

Make it happy.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6c06d74c37fe4230e5c302783183211eeff2b8a5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11379
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Michael Jeanson <mjeanson@efficios.com>

5 months agoUse `LICENSES/GPL-3.0-or-later` (`GPL-3.0` is deprecated)
Philippe Proulx [Tue, 14 Nov 2023 15:48:49 +0000 (10:48 -0500)] 
Use `LICENSES/GPL-3.0-or-later` (`GPL-3.0` is deprecated)

As of this date, the SPDX website says [1] about "GNU General Public
License v3.0 only":

> This license identifier has been deprecated since license list
> version 3.0.

Therefore, use `GPL-3.0-or-later`.

That's already the short ID we use in `tests/utils/tap/tap.sh`, not
`GPL-3.0`.

[1]: https://spdx.org/licenses/GPL-3.0.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I72349b1631cabfa16a59e0228871205978d5dd91
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11378
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
5 months agoUse `LICENSES/GPL-2.0-only` (`GPL-2.0` is deprecated)
Philippe Proulx [Tue, 14 Nov 2023 15:44:39 +0000 (10:44 -0500)] 
Use `LICENSES/GPL-2.0-only` (`GPL-2.0` is deprecated)

As of this date, the SPDX website says [1] about "GNU General Public
License v2.0 only":

> This license identifier has been deprecated since license list
> version 3.0.

Therefore, use `GPL-2.0-only`.

That's already the short ID we use everywhere, not `GPL-2.0`.

[1]: https://spdx.org/licenses/GPL-2.0.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifa073ef2a833f5bc6fb1051d50146ca352965688
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11377
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoUse `LICENSES/LGPL-2.1-only` (`LGPL-2.1` is deprecated)
Philippe Proulx [Tue, 14 Nov 2023 15:38:30 +0000 (10:38 -0500)] 
Use `LICENSES/LGPL-2.1-only` (`LGPL-2.1` is deprecated)

As of this date, the SPDX website says [1] about "GNU Lesser General
Public License v2.1 only":

> This license identifier has been deprecated since license list
> version 3.0.

Therefore, use `LGPL-2.1-only`.

That's already the short ID we use in `src/common/list.h`.

[1]: https://spdx.org/licenses/LGPL-2.1.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I2a6193f9b9b03275505424ecebc9896d9faabb0e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11376
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agoRemove `src/plugins/ctf/common/bfcr/btr.gdb`
Philippe Proulx [Tue, 14 Nov 2023 15:23:35 +0000 (10:23 -0500)] 
Remove `src/plugins/ctf/common/bfcr/btr.gdb`

We don't use nor maintain that. I'm not even sure what it does. We used
it mostly while developing Babeltrace 2.0, but things are stable now.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3ced5c5e57ee55013820cac77cdb456f3f984b0a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11375
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agotests/utils/python/normand.py: add SPDX headers
Philippe Proulx [Tue, 14 Nov 2023 14:54:35 +0000 (09:54 -0500)] 
tests/utils/python/normand.py: add SPDX headers

This is still the file as is from the upstream project.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ide3014910bd169f7fdaf05e2bbafd517a6ff6a93
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11374
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
5 months agotools: add lint-py.sh
Simon Marchi [Mon, 6 Nov 2023 19:54:36 +0000 (19:54 +0000)] 
tools: add lint-py.sh

Add lint-py.sh, running the various static analysis tools we use for
Python.

Change-Id: I6ccd5f7fb484506a0f936d7fe276042cccd186a6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11269
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
5 months agoRe-format C++ files
Simon Marchi [Mon, 6 Nov 2023 19:40:56 +0000 (19:40 +0000)] 
Re-format C++ files

The last few commits introduced some formatting errors, re-formating
using `tools/format-cpp`.

Change-Id: Ib9e4075d52b95f505bc6cbe2a2d5cd70d6926f84
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11268
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: add and use bt_grep_ok
Simon Marchi [Mon, 6 Nov 2023 18:41:38 +0000 (18:41 +0000)] 
tests: add and use bt_grep_ok

When a test that consists of matching a pattern in a file using grep
fails (sometimes just in the CI), it would be useful to see the file
contents to understand what happened.  Add the `bt_grep_ok` utility
function.  It tries to match a pattern in a file using `grep`, then
issues a test result.  If the test failed, it prints the content of the
file on stderr.

Change-Id: I464e414b334052677799ce201483095fa9bff4c3
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/+/11169
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: add and use bt_grep
Simon Marchi [Mon, 6 Nov 2023 18:36:59 +0000 (18:36 +0000)] 
tests: add and use bt_grep

Add the `bt_grep` function, which passes all its arguments to the grep
binary specified by BT_TESTS_GREP_BIN.  Use everywhere where applicable
in the testsuite.

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

6 months agobuild: move common headers to common_libcommon_la_SOURCES
Simon Marchi [Tue, 7 Nov 2023 16:48:12 +0000 (16:48 +0000)] 
build: move common headers to common_libcommon_la_SOURCES

Since we have an libcommon convenience library, I think it would make
sense to put all common headers there, instead of in noinst_HEADERS.

Change-Id: I161e5dc234c46599efbaffcea4e759e2df0ffc96
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11291
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
6 months agofilter.utils.trimmer: remove unused parameter from set_bound_from_param
Simon Marchi [Thu, 2 Nov 2023 19:54:18 +0000 (19:54 +0000)] 
filter.utils.trimmer: remove unused parameter from set_bound_from_param

Change-Id: I17e3a3cb7542c292f7eaa5e349725e2dca664abc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11217
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosink.text.details: remove unused parameter from configure_bool_opt
Simon Marchi [Thu, 2 Nov 2023 19:52:55 +0000 (19:52 +0000)] 
sink.text.details: remove unused parameter from configure_bool_opt

Change-Id: I71601439e92bdd678b45731f7f08a7c4d59f66eb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11216
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoflt.lttng-utils.debug-info: remove unused parameter from handle_msg_iterator_inactivity
Simon Marchi [Thu, 2 Nov 2023 19:51:08 +0000 (19:51 +0000)] 
flt.lttng-utils.debug-info: remove unused parameter from handle_msg_iterator_inactivity

Change-Id: I007b1d2a121ce1cf15abffda7485aaa396c3c7b2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11215
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosrc.ctf.lttng-live: remove unused parameter from lttng_live_metadata_create_stream
Simon Marchi [Thu, 2 Nov 2023 19:50:22 +0000 (19:50 +0000)] 
src.ctf.lttng-live: remove unused parameter from lttng_live_metadata_create_stream

Change-Id: Id70429d549c25aca07e6b6819e0f6f0a5fe01e4d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11214
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosrc.ctf.lttng-live: remove unused parameter from live_get_msg_ts_ns
Simon Marchi [Thu, 2 Nov 2023 19:49:33 +0000 (19:49 +0000)] 
src.ctf.lttng-live: remove unused parameter from live_get_msg_ts_ns

Change-Id: I5cd8569817f83b080af0ca0ff9fdb9218d3f5b13
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11213
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosrc.ctf.fs: remove parameter from create_one_port_for_trace
Simon Marchi [Thu, 2 Nov 2023 19:48:41 +0000 (19:48 +0000)] 
src.ctf.fs: remove parameter from create_one_port_for_trace

Change-Id: Ia58cc038ba597dff3c5e2fc6d9d29e18f71d5c89
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11212
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosrc.ctf.fs: remove unused parameter from ctf_fs_component_create
Simon Marchi [Thu, 2 Nov 2023 19:47:53 +0000 (19:47 +0000)] 
src.ctf.fs: remove unused parameter from ctf_fs_component_create

Change-Id: I32ed8d398a1292a48ebccb27578dee9e20d3b4f3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11211
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosink.ctf.fs: remove unused parameter from append_string_field_class
Simon Marchi [Thu, 2 Nov 2023 19:46:15 +0000 (19:46 +0000)] 
sink.ctf.fs: remove unused parameter from append_string_field_class

Change-Id: I262bcd035bdbdc81b80c80dc74f8ca9aebf5af34
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11210
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agosink.ctf.fs: remove unused parameter from write_string_field
Simon Marchi [Thu, 2 Nov 2023 19:45:27 +0000 (19:45 +0000)] 
sink.ctf.fs: remove unused parameter from write_string_field

Change-Id: I5098245393516b4a37daae1d0c0fe37fcf9bb2f5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11209
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agolib: remove unused parameter from set_integer_value
Simon Marchi [Thu, 2 Nov 2023 19:43:49 +0000 (19:43 +0000)] 
lib: remove unused parameter from set_integer_value

Change-Id: I6334e430afce5170908f28a2d579806f87eff860
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11208
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agolib: remove unused parameters bt_util_ns_from_origin_inline
Simon Marchi [Thu, 2 Nov 2023 19:42:19 +0000 (19:42 +0000)] 
lib: remove unused parameters bt_util_ns_from_origin_inline

Change-Id: I54bb5b1677f9e5761cb9e394d25706086f1a38ec
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11207
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agolib: remove `extended` parameters from format_* functions
Simon Marchi [Thu, 2 Nov 2023 19:36:11 +0000 (19:36 +0000)] 
lib: remove `extended` parameters from format_* functions

Change-Id: Iad81577eebfc0306afbaf6b15b8f7ad398a84959
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11206
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agolib: remove unused internal component destroy functions
Simon Marchi [Thu, 2 Nov 2023 19:33:18 +0000 (19:33 +0000)] 
lib: remove unused internal component destroy functions

These destroy functions are empty, remove them.  They can always be
added back later if needed, but I don't see the value in keeping then
"just in case".

Change-Id: I5845d2834294583367c85a840b016a536bf0b120
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11205
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agocompat: remove unused `addr` parameter from bt_mmap
Simon Marchi [Thu, 2 Nov 2023 19:26:00 +0000 (19:26 +0000)] 
compat: remove unused `addr` parameter from bt_mmap

Change-Id: Iecf7764f5fd669369064aa3b3fafe2575d933f28
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11204
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/' by one more
Michael Jeanson [Thu, 2 Nov 2023 18:49:18 +0000 (14:49 -0400)] 
Reduce the number of Makefiles in 'src/' by one more

The libcommon Makefile was the only one left of the convenience library
Makefiles to ensure that the version header was generated before the
other libraries were built.

By using the 'BUILT_SOURCES' variable we can ensure that 'version.i' is
generated first and merge this in 'src/Makefile'.

Change-Id: I0a6510af65674d1c8bb6a3a08d9a10b07e00fdd7
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11203
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agolib: remove unused parameters in internal component creation functions
Simon Marchi [Thu, 2 Nov 2023 16:06:46 +0000 (12:06 -0400)] 
lib: remove unused parameters in internal component creation functions

I noticed that these 3 functions didn't use the `class` parameter,
remove it.

Change-Id: I34b798dfbd8b1e54e7ddf633b61d6d205c0132cb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10408
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoReduce the number of Makefiles in 'src/' even MOAR!
Michael Jeanson [Tue, 31 Oct 2023 19:26:15 +0000 (15:26 -0400)] 
Reduce the number of Makefiles in 'src/' even MOAR!

Change-Id: I3dbb16250f62513ba131592c596fbaaf1ba97ffe
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11192
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agodoc: fix passing non-event messages in distill examples
Simon Marchi [Thu, 22 Jun 2023 13:42:17 +0000 (09:42 -0400)] 
doc: fix passing non-event messages in distill examples

The distill filter example means to let non-event messages go through,
but it actually drops them.  Fix it so it actually lets them through.

Verified by sending the output of the filter to `sink.text.details`.
Before the patch, there is no stream beginning message.  After the
patch, there is.

Change-Id: I2414a37ca7fc5fa6e5ed0fe179ee39cadf261f31
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10444
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoconfigure: re-enable '-Wunused-parameter'
Michael Jeanson [Wed, 9 Mar 2022 22:52:21 +0000 (17:52 -0500)] 
configure: re-enable '-Wunused-parameter'

This warning is part of '-Wextra' in GCC.

Change-Id: Ifb514a41cb9c62cf703d415eeb2ccefc331dee77
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7559
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoconfigure: re-enable '-Wmissing-field-initializers'
Michael Jeanson [Wed, 9 Mar 2022 22:14:20 +0000 (17:14 -0500)] 
configure: re-enable '-Wmissing-field-initializers'

This warning is part of '-Wextra' in GCC.

Change-Id: Ie6170cb06900e93011ddedc102a9964c63edad55
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7558
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
6 months agoFix: tests: conditionally skip Python bindings test that requires Python plugins...
Simon Marchi [Sun, 7 Jun 2020 22:54:29 +0000 (18:54 -0400)] 
Fix: tests: conditionally skip Python bindings test that requires Python plugins support

As exposed by bug 1272 [1], there are some tests in
test_trace_collection_message_iterator.py that depend on Python plugins
being enabled.  Running the tests with `--enable-python-bindings` and
`--disable-python-plugins` therefore leads to these tests failing.

Fix it by skipping them if the support for Python plugins is not
enabled.

[1] https://bugs.lttng.org/issues/1272

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

6 months agotests: remove test dir in test-query-metadata-info.sh
Simon Marchi [Fri, 27 Oct 2023 20:27:07 +0000 (20:27 +0000)] 
tests: remove test dir in test-query-metadata-info.sh

Change-Id: Ib3415ae8370bec53d0eb1ffa807f011b6b0c933c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11182
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoFix: tests: use local typing.py for Python 3.5
Simon Marchi [Mon, 30 Oct 2023 15:35:41 +0000 (11:35 -0400)] 
Fix: tests: use local typing.py for Python 3.5

`typing.NoReturn` was introduced in Python 3.5.4.  Therefore, there are
releases of Python 3.5 with which we get errors like:

    # Running: python3 /home/smarchi/src/babeltrace/tests/utils/python/mctf.py --base-dir /tmp/test-stored-value.jJOHoog/stored-values /home/smarchi/src/babeltrace/tests/data/ctf-traces/live/stored-values.mctf
    Traceback (most recent call last):
      File "/home/smarchi/src/babeltrace/tests/utils/python/mctf.py", line 13, in <module>
        import normand
      File "/home/smarchi/src/babeltrace/tests/utils/python/normand.py", line 61, in <module>
        from typing import Any, Set, Dict, List, Union, Pattern, Callable, NoReturn, Optional
    ImportError: cannot import name 'NoReturn'

Fix that by using our local typing module for Python 3.5.

Change-Id: I5660a5e0e2014a71c5e6b98b6ce1970b5bb1226e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11172
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoFix: tests: use run_python in gen_mctf_trace
Simon Marchi [Mon, 30 Oct 2023 15:30:29 +0000 (11:30 -0400)] 
Fix: tests: use run_python in gen_mctf_trace

gen_mctf_trace calls the python3 interpreter, without using the
`run_python` wrapper.  PYTHONPATH is therefore not set appropriately
for Python to find our local `typing.py` module, if needed.

Add a call to `run_python` to fix that.

Change-Id: Id813169905d511e5600a70cebad681b00ebb49d8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11171
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: retry os.rename on PermissionError failure in lttng_live_server.py
Simon Marchi [Mon, 30 Oct 2023 18:38:57 +0000 (14:38 -0400)] 
tests: retry os.rename on PermissionError failure in lttng_live_server.py

On the Windows CI jobs, we get random failures like:

    # plugins/src.ctf.lttng-live/test-live.sh: python3 /c/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py /c/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/inactivity-discarded-packet.json --port-file /c/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/tmp/test-live-server-port.Rn2dyS --trace-path-prefix C:\Users\jenkins\workspace\dev_review_babeltrace_master_winbuild\build\std\conf\std\platform\msys2-mingw64\src\babeltrace\tests\data\ctf-traces
    Traceback (most recent call last):
      File "C:/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py", line 1951, in <module>
        LttngLiveServer(port, port_filename, sessions, max_query_data_response_size)
      File "C:/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py", line 1667, in __init__
        self._write_port_to_file(port_filename)
      File "C:/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/src/babeltrace/tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py", line 1792, in _write_port_to_file
        os.replace(tmp_port_file.name, port_filename)
    PermissionError: [WinError 5] Access is denied: 'C:/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/tmp/tmpt13jh6sp' -> 'C:/Users/jenkins/workspace/dev_review_babeltrace_master_winbuild/build/std/conf/std/platform/msys2-mingw64/tmp/test-live-server-port.Rn2dyS'

The PermissionError exception is raised when trying to move the port
file from its temporary location to its final location, where the bash
script expects it to appear.

I don't understand the root cause of the issue.  When exiting the `with`
scope, the temporary file is supposed to be closed, and it should be
fine to move it.  I suppose it's possible that something in the Windows
kernel hasn't completely finished using the file when we try to move it.

Implement a wait-and-retry scheme as a (bad) workaround.

Change-Id: Ia8dcefca9538aa5e58438bf84a3fa67e5e05a49a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11174
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agocleanup: tests: remove unused files from lf / crlf traces
Michael Jeanson [Mon, 30 Oct 2023 19:06:27 +0000 (15:06 -0400)] 
cleanup: tests: remove unused files from lf / crlf traces

Change-Id: I259bd6a88f48d00471bd6a779d0e15150d4c3d4e
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11175
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotools/format-cpp: add `.sh` extension to identify it
Philippe Proulx [Mon, 30 Oct 2023 18:12:41 +0000 (14:12 -0400)] 
tools/format-cpp: add `.sh` extension to identify it

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

6 months agotools/format-cpp: exclude generated `parser.*` and `lexer.*` files
Philippe Proulx [Thu, 26 Oct 2023 15:36:56 +0000 (11:36 -0400)] 
tools/format-cpp: exclude generated `parser.*` and `lexer.*` files

We don't need to format them because they're not tracked.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0df8ffe9cef64b62b9327ee05acc2f4c5d48401b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11150
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
6 months agotools/format-cpp: accept optional starting directory
Philippe Proulx [Thu, 26 Oct 2023 13:25:16 +0000 (09:25 -0400)] 
tools/format-cpp: accept optional starting directory

This patch makes `tools/format-cpp` accept an optional starting
directory (instead of the root directory of the project) as its first
argument:

    $ pwd
    /home/dboucher/Mes Logiciels/babeltrace/src/plugins/ctf

    $ ../../../tools/format-cpp .
    clang-format -i /home/eepp/dev/babeltrace/src/plugins/ctf/fs-src/fs.cpp
    clang-format -i /home/eepp/dev/babeltrace/src/plugins/ctf/fs-src/file.cpp
    clang-format -i /home/eepp/dev/babeltrace/src/plugins/ctf/fs-src/query.cpp
    ...
    clang-format -i /home/eepp/dev/babeltrace/src/plugins/ctf/lttng-live/metadata.hpp
    clang-format -i /home/eepp/dev/babeltrace/src/plugins/ctf/lttng-live/data-stream.hpp

Using realpath(1) to transform the starting directory because find(1)
will only consider file names relative to its starting point, therefore
if the starting point is `.` (and the CWD is `src/cpp-common`),
`*/src/cpp-common/optional.hpp` and so on don't match anything and the
script will format files to be excluded.

Using `-path` instead of `-wholename` which is more precise and also
seems more portable.

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

6 months agotools/format-cpp: use a group of `echo` lines with a single `>& 2`
Philippe Proulx [Thu, 26 Oct 2023 13:13:44 +0000 (09:13 -0400)] 
tools/format-cpp: use a group of `echo` lines with a single `>& 2`

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