From 561079c8601d7ded6fe958b4cec3d0f7aec1ee63 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Thu, 8 Oct 2009 09:57:43 -0400 Subject: PR10702: preprocessor conditional for kernel CONFIG_foo * session.h (kernel_config[]): New session field. * main.cxx (parse_kernel_config): Populate it. * parse.cxx (eval_comparison): Use it. * testsuite/buildok/utrace.stp, testsuite/parseok/kconfig.stp: New tests. * NEWS, stap.1.in, doc/langref.tex: Mention it. --- parse.cxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index bfd7600f..b88ef7ff 100644 --- a/parse.cxx +++ b/parse.cxx @@ -183,12 +183,14 @@ bool eval_comparison (const OPERAND& lhs, const token* op, const OPERAND& rhs) // The basic form is %( CONDITION %? THEN-TOKENS %: ELSE-TOKENS %) // where CONDITION is: kernel_v[r] COMPARISON-OP "version-string" // or: arch COMPARISON-OP "arch-string" +// or: CONFIG_foo COMPARISON-OP "config-string" // or: "string1" COMPARISON-OP "string2" // or: number1 COMPARISON-OP number2 // The %: ELSE-TOKENS part is optional. // // e.g. %( kernel_v > "2.5" %? "foo" %: "baz" %) // e.g. %( arch != "i?86" %? "foo" %: "baz" %) +// e.g. %( CONFIG_foo %? "foo" %: "baz" %) // // Up to an entire %( ... %) expression is processed by a single call // to this function. Tokens included by any nested conditions are @@ -260,6 +262,23 @@ bool eval_pp_conditional (systemtap_session& s, target_architecture.c_str(), FNM_NOESCAPE); // still spooky + bool result; + if (op->type == tok_operator && op->content == "==") + result = !nomatch; + else if (op->type == tok_operator && op->content == "!=") + result = nomatch; + else + throw parse_error ("expected '==' or '!='", op); + + return result; + } + else if (l->type == tok_identifier && l->content.substr(0,7) == "CONFIG_" && r->type == tok_string) + { + string lhs = s.kernel_config[l->content]; // may be empty + string rhs = r->content; + + int nomatch = fnmatch (lhs.c_str(), rhs.c_str(), FNM_NOESCAPE); // still spooky + bool result; if (op->type == tok_operator && op->content == "==") result = !nomatch; @@ -291,10 +310,8 @@ bool eval_pp_conditional (systemtap_session& s, && op->type == tok_operator) throw parse_error ("expected number literal as right value", r); - // XXX: support other forms? "CONFIG_SMP" ? - else - throw parse_error ("expected 'arch' or 'kernel_v' or 'kernel_vr'\n" + throw parse_error ("expected 'arch' or 'kernel_v' or 'kernel_vr' or 'CONFIG_...'\n" " or comparison between strings or integers", l); } -- cgit