Fix: src.ctf.fs: Not resolving event common ctx
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 4 Aug 2021 15:19:14 +0000 (11:19 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 6 Aug 2021 13:16:08 +0000 (09:16 -0400)
Issue
=====
An assertion fails when creating the trace class with a sequence in the
event common context with the following callstack:
  #0  0x00007ffff7bf118b in raise () from /lib/x86_64-linux-gnu/libc.so.6
  #1  0x00007ffff7bd0859 in abort () from /lib/x86_64-linux-gnu/libc.so.6
  #2  0x00007ffff73e2d86 in bt_common_abort () at common.c:2111
  #3  0x00007ffff73ddec4 in bt_common_assert_failed (file=0x7ffff73ec268 "ctf-meta-update-value-storing-indexes.c", line=57, func=0x7ffff73ec300 <__func__.16976> "update_field_class_stored_value_index", assertion=0x7ffff73ec260 "tgt_fc") at assert.c:40
  #4  0x00007ffff738a396 in update_field_class_stored_value_index (fc=0x5555555d9c00, tc=0x555555598000, sc=0x555555598690, ec=0x0) at ctf-meta-update-value-storing-indexes.c:57
  #5  0x00007ffff738a4a0 in update_field_class_stored_value_index (fc=0x5555555d8ee0, tc=0x555555598000, sc=0x555555598690, ec=0x0) at ctf-meta-update-value-storing-indexes.c:81
  #6  0x00007ffff738a63b in ctf_trace_class_update_value_storing_indexes (ctf_tc=0x555555598000) at ctf-meta-update-value-storing-indexes.c:148
  #7  0x00007ffff73a0e95 in ctf_visitor_generate_ir_visit_node (visitor=0x55555559ce60, node=0x5555555ad100) at visitor-generate-ir.c:4900
  #8  0x00007ffff738e583 in ctf_metadata_decoder_append_content (mdec=0x55555559f380, fp=0x5555555aba00) at decoder.c:316
  #9  0x00007ffff73c9fda in ctf_fs_metadata_set_trace_class (self_comp=0x5555555a21b0, ctf_fs_trace=0x5555555981d0, config=0x55555559ee08) at metadata.c:107
  #10 0x00007ffff73c5e2f in ctf_fs_trace_create (self_comp=0x5555555a21b0, self_comp_class=0x0, path=0x555555597d40 "/home/frdeso/lttng-traces/auto-20210804-093702/kernel", name=0x0, metadata_config=0x55555559ee08, log_level=BT_LOGGING_LEVEL_WARNING) at fs.c:1072
  #11 0x00007ffff73c65cc in ctf_fs_component_create_ctf_fs_trace_one_path (ctf_fs=0x55555559edf0, path_param=0x5555555a1e50 "/home/frdeso/lttng-traces/auto-20210804-093702/kernel", trace_name=0x0, traces=0x555555597a80, self_comp=0x5555555a21b0, self_comp_class=0x0) at fs.c:1183
  #12 0x00007ffff73c8a4d in ctf_fs_component_create_ctf_fs_trace (ctf_fs=0x55555559edf0, paths_value=0x5555555ac4d0, trace_name_value=0x0, self_comp=0x5555555a21b0, self_comp_class=0x0) at fs.c:2097
  #13 0x00007ffff73c9a97 in ctf_fs_create (params=0x5555555abf70, self_comp_src=0x5555555a21b0) at fs.c:2397
  #14 0x00007ffff73c9b52 in ctf_fs_init (self_comp_src=0x5555555a21b0, config=0x0, params=0x5555555abf70, init_method_data=0x0) at fs.c:2431
  #15 0x00007ffff7f20b60 in add_component_with_init_method_data (graph=0x5555555a20a0, comp_cls=0x5555555a9580, init_method=0x7ffff73c9b1c <ctf_fs_init>, name=0x5555555abf40 "auto-disc-source-ctf-fs", params=0x5555555abf70, init_method_data=0x0, log_level=BT_LOGGING_LEVEL_WARNING, user_component=0x7fffffffe308, api_func=0x7ffff7f63880 <__func__.17336> "bt_graph_add_source_component", init_method_name=0x7ffff7f633a8 "bt_component_class_source_initialize_method") at graph.c:1048
  #16 0x00007ffff7f20e3d in add_source_component_with_initialize_method_data (graph=0x5555555a20a0, comp_cls=0x5555555a9580, name=0x5555555abf40 "auto-disc-source-ctf-fs", params=0x5555555abf70, init_method_data=0x0, log_level=BT_LOGGING_LEVEL_WARNING, component=0x7fffffffe308, api_func=0x7ffff7f63880 <__func__.17336> "bt_graph_add_source_component") at graph.c:1127
  #17 0x00007ffff7f20eec in bt_graph_add_source_component (graph=0x5555555a20a0, comp_cls=0x5555555a9580, name=0x5555555abf40 "auto-disc-source-ctf-fs", params=0x5555555abf70, log_level=BT_LOGGING_LEVEL_WARNING, component=0x7fffffffe308) at graph.c:1152
  #18 0x000055555556251a in cmd_run_ctx_create_components_from_config_components (ctx=0x7fffffffe390, cfg_components=0x5555555ab0c0) at babeltrace2.c:2252
  #19 0x00005555555628ec in cmd_run_ctx_create_components (ctx=0x7fffffffe390) at babeltrace2.c:2347
  #20 0x0000555555562cb5 in cmd_run (cfg=0x5555555a1b80) at babeltrace2.c:2461
  #21 0x00005555555635ef in main (argc=2, argv=0x7fffffffe508) at babeltrace2.c:2673

This is due to the fact that the event context field class containing a
sequence is never resolved by calling `resolve_root_class()`. This leads
to the `ctf_field_class_sequence::length_fc` field never being
initialized.

Looking at the `resolve_stream_class_field_classes()` function, it looks
like there is a typo where the `CTF_SCOPE_EVENT_SPECIFIC_CONTEXT` enum
label was used where the intention was to use
`CTF_SCOPE_EVENT_COMMON_CONTEXT` according to the surrounding code.

Fix
===
Replace `CTF_SCOPE_EVENT_SPECIFIC_CONTEXT` by `CTF_SCOPE_EVENT_COMMON_CONTEXT`.

Test
====
This commit adds a minimal testcase with a sequence in the event and
packet contexts.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I370a620855f2dcdf51d02db80b9df22b0f043f3a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6257
CI-Build: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/common/metadata/ctf-meta-resolve.c
tests/cli/test_trace_copy
tests/data/ctf-traces/succeed/meta-ctx-sequence/metadata [new file with mode: 0644]
tests/data/ctf-traces/succeed/meta-ctx-sequence/stream [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/succeed/trace-meta-ctx-sequence.expect [new file with mode: 0644]
tests/plugins/src.ctf.fs/succeed/test_succeed

index 1fd9d399ac71112d902f532820b94ad435fed200..1f81f38480f94f7eb973137aa307c86c42215e17 100644 (file)
@@ -1219,7 +1219,7 @@ int resolve_stream_class_field_classes(struct resolve_context *ctx,
                }
 
                ctx->scopes.event_common_context = sc->event_common_context_fc;
                }
 
                ctx->scopes.event_common_context = sc->event_common_context_fc;
-               ret = resolve_root_class(CTF_SCOPE_EVENT_SPECIFIC_CONTEXT, ctx);
+               ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx);
                if (ret) {
                        BT_COMP_LOGE("Cannot resolve event common context field class: "
                                "ret=%d", ret);
                if (ret) {
                        BT_COMP_LOGE("Cannot resolve event common context field class: "
                                "ret=%d", ret);
index 628812c6398bb39ee4d556ac69eee13699d9f8e5..761465e5da9c43b503018bf8ee4bccabe6af8175 100755 (executable)
@@ -22,8 +22,8 @@ clean_tmp() {
 
 SUCCESS_TRACES=("${BT_CTF_TRACES_PATH}/succeed/"*)
 
 
 SUCCESS_TRACES=("${BT_CTF_TRACES_PATH}/succeed/"*)
 
-# -2 because there is an empty trace that we skip
-NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 2))
+# -4 because there are two empty traces that we skip
+NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 4))
 
 plan_tests $NUM_TESTS
 
 
 plan_tests $NUM_TESTS
 
diff --git a/tests/data/ctf-traces/succeed/meta-ctx-sequence/metadata b/tests/data/ctf-traces/succeed/meta-ctx-sequence/metadata
new file mode 100644 (file)
index 0000000..247e5f3
--- /dev/null
@@ -0,0 +1,19 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+
+trace {
+       major = 1;
+       minor = 8;
+       byte_order = le;
+};
+
+stream {
+       event.context := struct {
+               uint8_t __evt_ctx_seq_length;
+               uint8_t _evt_ctx_seq[ __evt_ctx_seq_length ];
+       };
+       packet.context := struct {
+               uint8_t __pkt_ctx_seq_length;
+               uint8_t _pkt_ctx_seq[ __pkt_ctx_seq_length ];
+       };
+};
diff --git a/tests/data/ctf-traces/succeed/meta-ctx-sequence/stream b/tests/data/ctf-traces/succeed/meta-ctx-sequence/stream
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/data/plugins/src.ctf.fs/succeed/trace-meta-ctx-sequence.expect b/tests/data/plugins/src.ctf.fs/succeed/trace-meta-ctx-sequence.expect
new file mode 100644 (file)
index 0000000..e69de29
index b73b41b72e71c2b98f5e95bc610813bb96b43132..16fac9abd5b5ccf579110395a5c23608286eff31 100755 (executable)
@@ -125,7 +125,7 @@ test_force_origin_unix_epoch() {
        rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
 }
 
        rm -f "$temp_stdout_output_file" "$temp_stderr_output_file"
 }
 
-plan_tests 12
+plan_tests 13
 
 test_force_origin_unix_epoch 2packets barectf-event-before-packet
 test_ctf_gen_single simple
 
 test_force_origin_unix_epoch 2packets barectf-event-before-packet
 test_ctf_gen_single simple
@@ -136,5 +136,6 @@ test_ctf_single session-rotation
 test_ctf_single lttng-tracefile-rotation
 test_ctf_single array-align-elem
 test_ctf_single struct-array-align-elem
 test_ctf_single lttng-tracefile-rotation
 test_ctf_single array-align-elem
 test_ctf_single struct-array-align-elem
+test_ctf_single meta-ctx-sequence
 test_packet_end lttng-event-after-packet
 test_packet_end lttng-crash
 test_packet_end lttng-event-after-packet
 test_packet_end lttng-crash
This page took 0.028118 seconds and 4 git commands to generate.