Fix: `ctf` plugin: use element FC's alignment as array/seq. FC alignment
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 21 Jul 2020 17:57:10 +0000 (13:57 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 10 Sep 2020 15:26:21 +0000 (11:26 -0400)
commit0e32706b330840cf012f97884a4c22ea34f278b4
treedb4c19f32a9d208c296e74606fdd6f4aae7f961a
parent6b1463e62b1281c335123beb0b0894bdbff8f90c
Fix: `ctf` plugin: use element FC's alignment as array/seq. FC alignment

Observed issue
==============
When reading some CTF trace with an empty array/sequence field,
Babeltrace 2 can fail.

More specifically, for the trace `tests/data/ctf-traces/succeed/array-align-elem`
(added by this patch):

The CLI's output is:

    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER request_medium_bytes@msg-iter.c:535 [auto-disc-source-ctf-fs] User function returned EOF, but message iterator is in an unexpected state: state=DSCOPE_EVENT_PAYLOAD_CONTINUE, cur-packet-size=-1, cur=24, packet-cur=24, last-eh-at=16
    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER read_dscope_continue_state@msg-iter.c:632 [auto-disc-source-ctf-fs] Cannot ensure that buffer has at least one byte: msg-addr=0x55d3b4e051f0, status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/CTF/MSG-ITER ctf_msg_iter_get_next_message@msg-iter.c:2881 [auto-disc-source-ctf-fs] Cannot handle state: msg-it-addr=0x55d3b4e051f0, state=DSCOPE_EVENT_PAYLOAD_CONTINUE
    07-21 14:00:24.636 73959 73959 E PLUGIN/SRC.CTF.FS ctf_fs_iterator_next_one@fs.c:90 [auto-disc-source-ctf-fs] Failed to get next message from CTF message iterator.
    07-21 14:00:24.636 73959 73959 W LIB/MSG-ITER bt_message_iterator_next@iterator.c:865 Component input port message iterator's "next" method failed: iter-addr=0x55d3b4e05000, iter-upstream-comp-name="auto-disc-source-ctf-fs", iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=SOURCE, iter-upstream-comp-class-name="fs", iter-upstream-comp-class-partial-descr="Read CTF traces from the file sy", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="array-align-elem | 0 | array-align-elem/stream", status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER muxer_upstream_msg_iter_next@muxer.c:446 [muxer] Upstream iterator's next method returned an error: status=ERROR
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER validate_muxer_upstream_msg_iters@muxer.c:989 [muxer] Cannot validate muxer's upstream message iterator wrapper: muxer-msg-iter-addr=0x55d3b4dcb830, muxer-upstream-msg-iter-wrap-addr=0x55d3b4e055c0
    ev: { a = 1, b = [ ], c = 2 }
    07-21 14:00:24.636 73959 73959 E PLUGIN/FLT.UTILS.MUXER muxer_msg_iter_next@muxer.c:1417 [muxer] Cannot get next message: comp-addr=0x55d3b4dcae70, muxer-comp-addr=0x55d3b4dcaef0, muxer-msg-iter-addr=0x55d3b4dcb830, msg-iter-addr=0x55d3b4dcb750, status=ERROR
    07-21 14:00:24.636 73959 73959 W LIB/MSG-ITER bt_message_iterator_next@iterator.c:865 Component input port message iterator's "next" method failed: iter-addr=0x55d3b4dcb750, iter-upstream-comp-name="muxer", iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=FILTER, iter-upstream-comp-class-name="muxer", iter-upstream-comp-class-partial-descr="Sort messages from multiple inpu", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
    07-21 14:00:24.636 73959 73959 W LIB/GRAPH consume_graph_sink@graph.c:462 Component's "consume" method failed: status=ERROR, comp-addr=0x55d3b4dcb070, comp-name="pretty", comp-log-level=WARNING, comp-class-type=SINK, comp-class-name="pretty", comp-class-partial-descr="Pretty-print messages (`text` fo", comp-class-is-frozen=1, comp-class-so-handle-addr=0x55d3b4dc7c50, comp-class-so-handle-path="/home/eepp/dev/babeltrace/install/lib/babeltrace2/plugins/babeltrace-plugin-text.la", comp-input-port-count=1, comp-output-port-count=0
    07-21 14:00:24.636 73959 73959 E CLI cmd_run@babeltrace2.c:2529 Graph failed to complete successfully

    ERROR:    [Babeltrace CLI] (babeltrace2.c:2529)
      Graph failed to complete successfully
    CAUSED BY [libbabeltrace2] (graph.c:462)
      Component's "consume" method failed: status=ERROR, comp-addr=0x55d3b4dcb070, comp-name="pretty", comp-log-level=WARNING, comp-class-type=SINK,
      comp-class-name="pretty", comp-class-partial-descr="Pretty-print messages (`text` fo", comp-class-is-frozen=1, comp-class-so-handle-addr=0x55d3b4dc7c50,
      comp-class-so-handle-path="/home/eepp/dev/babeltrace/install/lib/babeltrace2/plugins/babeltrace-plugin-text.la", comp-input-port-count=1,
      comp-output-port-count=0
    CAUSED BY [libbabeltrace2] (iterator.c:865)
      Component input port message iterator's "next" method failed: iter-addr=0x55d3b4dcb750, iter-upstream-comp-name="muxer",
      iter-upstream-comp-log-level=WARNING, iter-upstream-comp-class-type=FILTER, iter-upstream-comp-class-name="muxer",
      iter-upstream-comp-class-partial-descr="Sort messages from multiple inpu", iter-upstream-port-type=OUTPUT, iter-upstream-port-name="out", status=ERROR
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:1417)
      Cannot get next message: comp-addr=0x55d3b4dcae70, muxer-comp-addr=0x55d3b4dcaef0, muxer-msg-iter-addr=0x55d3b4dcb830, msg-iter-addr=0x55d3b4dcb750,
      status=ERROR
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:989)
      Cannot validate muxer's upstream message iterator wrapper: muxer-msg-iter-addr=0x55d3b4dcb830, muxer-upstream-msg-iter-wrap-addr=0x55d3b4e055c0
    CAUSED BY [muxer: 'filter.utils.muxer'] (muxer.c:446)
      Upstream iterator's next method returned an error: status=ERROR
    CAUSED BY [libbabeltrace2] (iterator.c:865)
      Component input port message iterator's "next" method failed: iter-addr=0x55d3b4e05000, iter-upstream-c

Cause
=====
The internal CTF IR array and sequence field classes do not have an
alignment which is equal to their element FC's alignment, although
CTF 1.8.3 requires it [1]:

> Arrays are always aligned on their element alignment requirement.

Solution
========
In `bfcr.c`, align_class_state() is already called for array/sequence
fields.

Add a CTF IR trace class visitor to set any array/sequence FC's
alignment to its element FC's alignment, recursively (postorder).

Also update, postorder, structure FC alignments since some of the
alignments of the field types of their members can change.

Note
====
This patch adds two minimalist CTF traces to test the fix as well as two
new corresponding tests in
`tests/plugins/src.ctf.fs/succeed/test_succeed`:

`array-align-elem`:
    Metadata:

        struct {
            integer { size = 8; } a;
            integer { size = 8; align = 16; } b[0];
            integer { size = 8; } c;
        };

    Taking the aligment of `b` into account, there's one byte of padding
    between `a` and `c`:

        a # c
          ^---- alignment of `b`

`struct-array-align-elem`:
    Metadata:

        struct {
            integer { size = 8; } x;
            struct {
                integer { size = 8; } a;
                integer { size = 8; align = 32; } b[0];
            } y;
            integer { size = 8; } z;
        };

    Taking the alignment of `y.b` into account, the `y` structure itself
    is 32-bit-aligned, making the outer structure also 32-bit-aligned.
    Therefore, there are three bytes of padding between `x` and `a`, and
    three other bytes of padding between `a` and `z`:

        x # # # a # # # z
          ^       ^-------- alignment of `b`
          '---------------- alignment of `y`

References
==========
[1]: https://diamon.org/ctf/v1.8.3/#spec4.2.3

Fixes: https://bugs.lttng.org/issues/1276
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I06b4fbeda9ffd5b87b4964dd567027d0bfd5e9c7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4056
src/plugins/ctf/common/metadata/Makefile.am
src/plugins/ctf/common/metadata/ctf-meta-update-alignments.c [new file with mode: 0644]
src/plugins/ctf/common/metadata/ctf-meta-visitors.h
src/plugins/ctf/common/metadata/visitor-generate-ir.c
tests/data/ctf-traces/succeed/array-align-elem/metadata [new file with mode: 0644]
tests/data/ctf-traces/succeed/array-align-elem/stream [new file with mode: 0644]
tests/data/ctf-traces/succeed/struct-array-align-elem/metadata [new file with mode: 0644]
tests/data/ctf-traces/succeed/struct-array-align-elem/stream [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/succeed/trace-array-align-elem.expect [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/succeed/trace-struct-array-align-elem.expect [new file with mode: 0644]
tests/plugins/src.ctf.fs/succeed/test_succeed
This page took 0.026761 seconds and 4 git commands to generate.