Re: [GIT PULL] tracing: Add __string_len() and __assign_str_len() helpers
From: Steven Rostedt
Date: Wed Jul 14 2021 - 18:03:47 EST
On Wed, 14 Jul 2021 17:56:33 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> static inline notrace int trace_event_get_offsets_foo(
> struct trace_event_data_offsets_foo *__data_offsets, const char *foobar, int len)
> {
> int __data_size = 0;
> int __maybe_unused __item_length;
> struct trace_event_raw_foo __maybe_unused *entry;
>
> // The "(len)+1" will be used to calculate the __item_length below
>
> __item_length = (len + 1) * sizeof(char);
>
> // the dynamic fields (strings and such) are located after the static
> // fields in the trace event, and the offset is recorded in the bottom
> // 16 bits of a 32 bit word, and the size in the top 16 bits.
>
> __data_offsets->item = __data_size +
> offsetof(typeof(*entry), __data);
> __data_offsets->item |= __item_length << 16;
I missed a manual substitution of the macro. This should have been:
__data_offsets->str = __data_size +
offsetof(typeof(*entry), __data);
__data_offsets->str |= __item_length << 16;
As the macro creates the trace_event_data_offsets_foo structure (which
__data_offsets is declared as), which contains a field for every
__string/__string_len/__dynamic_array() in TP_STRUCT__entry.
The -">str" comes from the "str" in "__string_len(str, foobar, len)".
-- Steve
> __data_size += __item_length;
>
>
> // Each "__string_len()" or "__string()" in the TP_STRUCT__entry is inserted
> // into this macro created function. Thus, the above code is duplicated for
> // each field that uses __string(), __string_len() or __dynamic_array().
>
>
> return __data_size;
> }