dtrace: parse sdpd_args to handle sdt_getargdesc() rather than hardwiring
This takes the new sdpd_args element in the sdt_probedesc_t and
translates it into argdesc array entries for sdt_getargdesc() to return.
This is not really a parser but a tokenizer, splitting the input string
into "tokens" which are arg strings, translators, etc; but tokenizers,
like parsers, are often fairly squirrelly and full of annoying special
cases, and that is no less true here. The most notable:
- you can have *no* arguments, either via an empty translation with
brackets "foo : ()" or without "foo : " or simply via having a
probe with zero arguments to start with: this might be represented
as an sdpd_args of NULL.
- arg strings often end in trailing commas because of details of the
macros that produce them, so arguments do not match up one-to-one
with commas, even ignoring the rare case of empty translations
(though, because translations also use commas for the same purpose,
they nearly do). It's OK to overcount a bit when allocating memory
for the array, but it has to be right by the time we're done.
- perf probes have their arg strings in a subtly different format to
native probes. The perf arg string is used by tracepoint.h to define
a function, so it's not a string of types, but rather a string of
arguments, complete with names. Thankfully you can't hand a perf
probe a function pointer, and arrays have decayed to pointers by this
stage, so we don't need to deal with the full horror of C declarator
syntax: rather, we just need to note if a probe name starts with
__perf_ and strip off the last run of alphanumeric and _ characters
from each argument if so (followed by any trailing whitespace thus
exposed).
- native probes with no arguments simply have no arg string (NULL).
Perf probes with no arguments have the string 'void', so identify
that and strip it off.
Once we have the argdesc constructed, adjusting sdt_getargdesc() is
simple: it actually gets quite a lot shorter and faster because we can
treat the sdp_argdesc array as an array rather than looping through it
comparing provider and probe names and indices: the index in the array
*is* the index of the (possibly translated) argument.
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Acked-by: Kris Van Hees <kris.van.hees@oracle.com>
Orabug:
24661801