Re: [PATCH] libtraceevent plugins: Add plugin_net to handle bswap during print

Steven Rostedt <[email protected]> Wed, 9 Apr 2025 22:56:08 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
On Wed,  9 Apr 2025 13:07:05 +0200
Petr Malat <[email protected]> wrote:

> +static unsigned long long
> +process_builtin_bswap16(struct trace_seq *s, unsigned long long *args)
> +{
> +	return __builtin_bswap16((uint16_t)args[0]);
> +}
> +
> +static unsigned long long
> +process_builtin_bswap32(struct trace_seq *s, unsigned long long *args)
> +{
> +	return __builtin_bswap32((uint32_t)args[0]);
> +}
> +
> +static unsigned long long
> +process_builtin_bswap64(struct trace_seq *s, unsigned long long *args)
> +{
> +	return __builtin_bswap64(args[0]);
> +}
> +

These actually look useful to be built into the main parser itself and not
necessarily in a plugin.

But I'm not sure we can just translate it directly here.

What if the trace.dat is created on a big endian machine, but read on a
little endian machine? I don't think we want to do the byte swapping, do we?

I think this needs to check the file vs host endianess. If they don't match,
I think we don't want to do the swap!

  if (tep->file_bigendian == tep->host_bigendian)
	return __builtin_bswap*(args[0]);
  else
	return args[0];

?

As the else block will have args[0] already swapped wrt to host that's
reading the information. libtraceevent does a byte swap on values read when
the host and file do not match endianess.

-- Steve