diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2009-10-08 09:57:43 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2009-10-08 09:57:43 -0400 |
commit | 561079c8601d7ded6fe958b4cec3d0f7aec1ee63 (patch) | |
tree | b6481615519c60f87314319c1828eb6645833b19 /parse.cxx | |
parent | e4cf148d68fe01b680856ad39739faf99bfc29b4 (diff) | |
download | systemtap-steved-561079c8601d7ded6fe958b4cec3d0f7aec1ee63.tar.gz systemtap-steved-561079c8601d7ded6fe958b4cec3d0f7aec1ee63.tar.xz systemtap-steved-561079c8601d7ded6fe958b4cec3d0f7aec1ee63.zip |
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.
Diffstat (limited to 'parse.cxx')
-rw-r--r-- | parse.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -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 @@ -270,6 +272,23 @@ bool eval_pp_conditional (systemtap_session& s, 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; + else if (op->type == tok_operator && op->content == "!=") + result = nomatch; + else + throw parse_error ("expected '==' or '!='", op); + + return result; + } else if (l->type == tok_string && r->type == tok_string) { string lhs = l->content; @@ -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); } |