From 92585d32aad4d48340071e8557de245d553adf4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20Kjellstr=C3=B6m?= Date: Wed, 26 Feb 2014 18:35:48 +0100 Subject: [PATCH] Add 'guru_mode' preprocessor conditional. * parse.cxx (eval_pp_conditional): Added 'guru_mode' preprocessor conditional. * man/stap.1: Added 'guru_mode' preprocessor conditional documentation. * testsuite/parseok/fourteen.stp: Added 'guru_mode' preprocessor conditional test. * testsuite/parseko/preprocess20.stp: New file. * testsuite/parseko/preprocess21.stp: Ditto. * testsuite/parseko/preprocess22.stp: Ditto. --- man/stap.1 | 7 +++++++ parse.cxx | 16 +++++++++++++++- testsuite/parseko/preprocess20.stp | 6 ++++++ testsuite/parseko/preprocess21.stp | 6 ++++++ testsuite/parseko/preprocess22.stp | 6 ++++++ testsuite/parseok/fourteen.stp | 7 +++++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 testsuite/parseko/preprocess20.stp create mode 100755 testsuite/parseko/preprocess21.stp create mode 100755 testsuite/parseko/preprocess22.stp diff --git a/man/stap.1 b/man/stap.1 index 420b13514..95be35b1c 100644 --- a/man/stap.1 +++ b/man/stap.1 @@ -770,6 +770,13 @@ and the third part is a string literal, either "stapusr" or "stapsys" or "stapdev". .PP If the first part is the identifier +.BR guru_mode , +the test refers to if the systemtap script is +compiled with guru_mode. Here the second part is +.BR == " or " != , +and the third part is a number, either 1 or 0. +.PP +If the first part is the identifier .BR runtime , the test refers to the systemtap runtime mode. See .BR ALTERNATE\ RUNTIMES diff --git a/parse.cxx b/parse.cxx index 6c1598e7c..720f8fb07 100644 --- a/parse.cxx +++ b/parse.cxx @@ -2,6 +2,7 @@ // Copyright (C) 2005-2013 Red Hat Inc. // Copyright (C) 2006 Intel Corporation. // Copyright (C) 2007 Bull S.A.S +// Copyright (C) 2014 Peter Kjellstrom // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General @@ -835,7 +836,6 @@ bool eval_pp_conditional (systemtap_session& s, else if (l->type == tok_identifier && l->content == "systemtap_privilege") { string target_privilege = - /* XXX perhaps include a "guru" state */ pr_contains(s.privilege, pr_stapdev) ? "stapdev" : pr_contains(s.privilege, pr_stapsys) ? "stapsys" : pr_contains(s.privilege, pr_stapusr) ? "stapusr" @@ -859,6 +859,20 @@ bool eval_pp_conditional (systemtap_session& s, return result; } + else if (l->type == tok_identifier && l->content == "guru_mode") + { + if (! (r->type == tok_number)) + throw PARSE_ERROR (_("expected number"), r); + int64_t lhs = (int64_t) s.guru_mode; + int64_t rhs = lex_cast(r->content); + if (!((rhs == 0)||(rhs == 1))) + throw PARSE_ERROR (_("expected 0 or 1"), op); + if (!((op->type == tok_operator && op->content == "==") || + (op->type == tok_operator && op->content == "!="))) + throw PARSE_ERROR (_("expected '==' or '!='"), op); + + return eval_comparison (lhs, op, rhs); + } else if (l->type == tok_identifier && l->content == "arch") { string target_architecture = s.architecture; diff --git a/testsuite/parseko/preprocess20.stp b/testsuite/parseko/preprocess20.stp new file mode 100755 index 000000000..e1d97e042 --- /dev/null +++ b/testsuite/parseko/preprocess20.stp @@ -0,0 +1,6 @@ +#! stap -p1 + +# bad guru_mode value - not 0 or 1 +%( guru_mode == 2 %? + probe begin { } +%) diff --git a/testsuite/parseko/preprocess21.stp b/testsuite/parseko/preprocess21.stp new file mode 100755 index 000000000..d69cb0ea4 --- /dev/null +++ b/testsuite/parseko/preprocess21.stp @@ -0,0 +1,6 @@ +#! stap -p1 + +# bad guru_mode value - not a number +%( guru_mode == "bad" %? + probe begin { } +%) diff --git a/testsuite/parseko/preprocess22.stp b/testsuite/parseko/preprocess22.stp new file mode 100755 index 000000000..703509bf1 --- /dev/null +++ b/testsuite/parseko/preprocess22.stp @@ -0,0 +1,6 @@ +#! stap -p1 + +# bad guru_mode comparison operator - not '==' or '!=' +%( guru_mode >= 0 %? + probe begin { } +%) diff --git a/testsuite/parseok/fourteen.stp b/testsuite/parseok/fourteen.stp index 756cc4a81..621e0c5aa 100755 --- a/testsuite/parseok/fourteen.stp +++ b/testsuite/parseok/fourteen.stp @@ -33,3 +33,10 @@ global %: "FAIL10" %) %) + +global +%( guru_mode == 1 %? guru_mode +%: %( guru_mode == 0 %? not_guru_mode + %: "FAIL11" + %) +%) -- 2.43.5