This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
version-sensitive ifdef
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: systemtap at sources dot redhat dot com
- Date: Tue, 1 Nov 2005 11:13:18 -0500
- Subject: version-sensitive ifdef
Hi -
I'm committing code for PR 1425. It adds a baby preprocessor to the
parser, to allow a script to include or exclude tokens based on the
target kernel version. For now, the version string comparison is done
with a routine from rpmlib, which is henceforth a prerequisite. From
the amended man page:
A simple conditional preprocessing stage is run as a part of parsing.
The general form is similar to the cond ? exp1 : exp2 ternary opera-
tor:
%( CONDITION %? TRUE-TOKENS %)
%( CONDITION %? TRUE-TOKENS %: FALSE-TOKENS %)
The CONDITION is a very limited expression consisting of three parts.
The first part is the identifier kernel_vr or kernel_v to refer to the
kernel version number, with ("2.6.13-1.322FC3smp") or without
("2.6.13") the release code suffix. The second part is one of the six
standard numeric comparison operators <, <=, ==, !=, >, and >=. The
third part is a string literal that contains an RPM-style version-re-
lease value. The condition is deemed satisfied if the version of the
target kernel (as optionally overridden by the -r option) compares to
the given version string. The comparison is performed by the RPM li-
brary function rpmvercmp. The TRUE-TOKENS and FALSE-TOKENS are zero
or more general parser tokens (possibly including nested preprocessor
conditionals), and are pasted into the input stream if the condition
is true or false. For example, the following code induces a parse er-
ror unless the target kernel version is newer than 2.6.5:
%( kernel_v <= "2.6.5" %? **ERROR** %) # invalid token sequence
The following code might adapt to hypothetical kernel version drift:
probe kernel.function (
%( kernel_v <= "2.6.12" %? "__mm_do_fault" %:
%( kernel_vr == "2.6.13-1.8273FC3smp" %? "do_page_fault" %:
UNSUPPORTED %) %)
) { /* ... */ }