]> www.infradead.org Git - users/jedix/linux-maple.git/commit
dtrace: parse sdpd_args to handle sdt_getargdesc() rather than hardwiring
authorNick Alcock <nick.alcock@oracle.com>
Wed, 14 Sep 2016 09:52:17 +0000 (10:52 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 28 Oct 2016 13:01:13 +0000 (14:01 +0100)
commit28da0b484fbfb78a3b995207583a94ed7bfc34df
treede2543eea581a87994a19b05b4cfeaa777d7dd40
parent329124e8066998e19415b9a0568ec0c3a4f02525
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
dtrace/sdt_dev.c
dtrace/sdt_impl.h