[Q] Bit field/array/pointer output formatting disambiguation

Eugene Syromyatnikov evgsyr at gmail.com
Mon Sep 20 16:27:27 UTC 2021


Reanimating this old thread. I have yet another proposal for bit set
syntax that aims at unification of currently employed syntaxes, while
maintaining visual distinction.
Currently, the following visual representations are used for printing bit sets:
sigset: [KILL USR1 73 74 75], ~[HUP]
evdev: [EV_ABS EV_MSC EV_LED EV_SND EV_PWR]
affinity: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
netlink: 1<<ICMP_ECHOREPLY|1<<ICMP_DEST_UNREACH|1<<ICMP_SOURCE_QUENCH|1<<ICMP_REDIRECT|1<<ICMP_TIME_EXCEEDED|1<<ICMP_PARAMETERPROB,
1<<(INET_DIAG_CONG-1)|1<<(INET_DIAG_TOS-1)

I'd like to suggest {[...]} syntax, more specifically, {PREFIX[NAMED
BITS]SUFFIX [UNNAMED BITS]}.  Some examples:
sigset: {SIG[KILL USR1] [73-75]}, ~{SIG[HUP]}
evdev: {EV_[ABS MSC LED SND PWR]}
affinity: {[0-11]}
netlink: {ICMP_[ECHOREPLY DEST_UNREACH SOURCE_QUENCH REDIRECT
TIME_EXCEEDED PARAMETERPROB]}, {INET_DIAG_[CONG TOS]-1}
The benefit is that it seems to capture all the existing use cases,
while being visually distinct (it differs from an array within a
structure by the lack of the equal sign between the opening curly and
square brackets).

One possibility for wiggle room here is to add some qualifier for
enabling old output, something like -eprint=bitset:{legacy|new}.

What do you think?

On Wed, Oct 17, 2018 at 6:13 AM Eugene Syromyatnikov <evgsyr at gmail.com> wrote:
>
> Hello.
>
> There are some questions about strace users' preference regarding
> formatting of bit fields, arrays, and pointers in strace's output. As
> of now, square brackets are used for designating all these things,
> with the only difference in a separator used for delimiting items in
> arrays and bit masks (a combination of comma and space is used for
> delimiting array items, and a space is used for bit fields). Examples
> from strace(1):
>            getgroups(32, [100, 0]) = 2
>            sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
>
> A special case of an array is a pointer reference, which is also
> printed using square brackets:
>            futex([0x2] /* 0x7fbf7bd730c8 */, FUTEX_WAKE_PRIVATE, 2147483647) = 0
>
> The issue is that an array that contains only a single item may be
> confused with a bit mask that has only one bit set. As a solution to
> this, it is proposed to add spaces around elements in bit mask output:
>            getgroups(32, [100]) = 2
>            getgroups(32, []) = 2
>            sigprocmask(SIG_BLOCK, [ CHLD ], [  ]) = 0
>            sigprocmask(SIG_UNBLOCK, ~[  ], NULL) = 0
>
> The main problem associated with that change is that It breaks
> established output formatting rules that are likely being relied upon
> by some. Other significant problem is within the fact that such kind
> of output formatting is somewhat unorthodox (having syntactically
> significant whitespace).
>
> The other slightly relevant issue is that, as of now, there is no
> distinction in the formatting of structures that are referenced by
> pointer compared to embedded structures (e.g., no difference of fields
> A and B in the output of the following structure: struct { struct
> timespec *A; struct timespec B; };); it is proposed to print square
> brackets around structures that are referenced by pointer, and the
> issue is the same: it will change a lot of exiting output and likely
> will break a lot of assumptions.
>
> The solution I can see is to add an option that enables more regular
> output, but that would be yet another option some have to pass for
> each interactive strace session, and will create the need to have
> significant amount of code for handling both legacy and regular output
> formatting, which doesn't really help maintainability of the project.
>
> So, maybe someone has any ideas in this regard (a completely different
> syntax for bit sets that considers the fact that there are stripped
> prefixes for bit constants, for example)?
>
> --
> Eugene Syromyatnikov
> mailto:evgsyr at gmail.com
> xmpp:esyr at jabber.{ru|org}



--
Eugene Syromyatnikov
mailto:evgsyr at gmail.com
xmpp:esyr at jabber.{ru|org}


More information about the Strace-devel mailing list