From 4227f98d2100dbae5009a39e05177c090886ed3f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 19 Feb 2010 00:11:18 +0100 Subject: Allow CONFIG_foo COMPARISON-OP CONFIG_bar in preprocessor conditionals. * parse.cxx (eval_pp_conditional): If rhs and lhs are both CONFIG_... identifiers try to convert them both to numbers or otherwise threat them both as strings for eval_comparison. * testsuite/semok/config_config.stp: New test. --- parse.cxx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index a7b3ebd7..ad4f93f0 100644 --- a/parse.cxx +++ b/parse.cxx @@ -185,6 +185,7 @@ bool eval_comparison (const OPERAND& lhs, const token* op, const OPERAND& rhs) // or: arch COMPARISON-OP "arch-string" // or: CONFIG_foo COMPARISON-OP "config-string" // or: CONFIG_foo COMPARISON-OP number +// or: CONFIG_foo COMPARISON-OP CONFIG_bar // or: "string1" COMPARISON-OP "string2" // or: number1 COMPARISON-OP number2 // The %: ELSE-TOKENS part is optional. @@ -304,9 +305,32 @@ bool eval_pp_conditional (systemtap_session& s, int64_t rhs = lex_cast(r->content); return eval_comparison (lhs, op, rhs); } + else if (r->type == tok_identifier + && r->content.substr(0,7) == "CONFIG_") + { + // First try to convert both to numbers, + // otherwise threat both as strings. + const char* startp = s.kernel_config[l->content].c_str (); + char* endp = (char*) startp; + errno = 0; + int64_t val = (int64_t) strtoll (startp, & endp, 0); + if (errno != ERANGE && errno != EINVAL && *endp == '\0') + { + int64_t lhs = val; + startp = s.kernel_config[r->content].c_str (); + endp = (char*) startp; + errno = 0; + int64_t rhs = (int64_t) strtoll (startp, & endp, 0); + if (errno != ERANGE && errno != EINVAL && *endp == '\0') + return eval_comparison (lhs, op, rhs); + } + + string lhs = s.kernel_config[l->content]; + string rhs = s.kernel_config[r->content]; + return eval_comparison (lhs, op, rhs); + } else - throw parse_error ("expected string or number literal as right value", - r); + throw parse_error ("expected string, number literal or other CONFIG_... as right value", r); } else if (l->type == tok_string && r->type == tok_string) { -- cgit