[lttng-dev] decoding tracef msg string via babeltrace API

Milian Wolff milian.wolff at kdab.com
Tue Apr 2 15:03:41 EDT 2019


Hey all

I added a tracef tracepoint and want to decode it's `msg` field in the 
BT_EVENT_FIELDS scope. Babeltrace on the command line seems to handle this 
nicely, but whatever I try, it doesn't work with the API.

I'm using babeltrace from the stable-1.5 branch.

First, the output from babeltrace on the command line:

```
event {
        name = "lttng_ust_tracef:event";
        id = 9;
        stream_id = 0;
        loglevel = 14;
        fields := struct {
                integer { size = 32; align = 8; signed = 0; encoding = none; 
base = 10; } __msg_length;
                integer { size = 8; align = 8; signed = 1; encoding = UTF8; 
base = 10; } _msg[ __msg_length ];
        };
};
...
timestamp = 15:56:15.404973865, delta = +0.000023594, trace = 1000/64-bit, 
trace:hostname = agathebauer, trace:domain = ust, loglevel = TRACE_DEBUG (14), 
name = lttng_ust_tracef:event, stream.packet.context = { timestamp_begin = 
4382372875047, timestamp_end = 4462741641629, content_size = 47177888, 
packet_size = 47185920, packet_seq_num = 0, events_discarded = 0, cpu_id = 3 
}, stream.event.header = { id = ( "compact" : container = 9 ), v = { compact = 
{ timestamp = 70385656 } } }, event.fields = { _msg_length = 33, msg = 
"run_event_entry: ImageCache, 1000" }
...
```

Now, in my code I find the event and then I've tried:

```
            auto definition = bt_ctf_get_field(event, scope, "msg");
            auto declaration = bt_ctf_get_decl_from_def(definition);
            auto type = bt_ctf_field_type(declaration);
            auto encoding = bt_ctf_get_encoding(declaration);
            auto string = bt_ctf_get_string(definition);
            auto char_array = bt_ctf_get_char_array(definition);
            const bt_definition* const* list = nullptr;
            unsigned num_list = 0;
            auto field_list_ret = bt_ctf_get_field_list(ctf_event, definition, 
&list, &num_list);
            fprintf(stderr, "tracef dbg: %p %p | %d %d | %s | %s | %p %u 
%d\n", definition, declaration, type, encoding, string, char_array, list, 
num_list, field_list_ret);
```

the output is:

```
tracef dbg: 0x55e4c5b084f0 0x55e4c5b3f220 | 9 1 | (null) | (null) | (nil) 0 -1

```

So, it's a sequence (type 9), but I can't get the sequence... Actually, when I 
tried this the firs ttime without patching babeltrace, then it crashed in 
events.c:256 [1]. The def_sequence is non-null, but def_sequence->elems is 
null and that's not checked...

[1]: https://github.com/efficios/babeltrace/blob/stable-1.5/formats/ctf/
events.c#L256

I'm quite stumped - what am I doing wrong? How does babeltrace handle the 
string-decoding of tracef's msg arg?

Thanks
-- 
Milian Wolff | milian.wolff at kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH, a KDAB Group company
Tel: +49-30-521325470
IKDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3826 bytes
Desc: not available
URL: <https://lists.lttng.org/pipermail/lttng-dev/attachments/20190402/1aa53102/attachment.bin>


More information about the lttng-dev mailing list