This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add 'guru_mode' preprocessor conditional.


After discussions with fche on IRC I wrote up this initial support for a new
"guru_mode" preprocessor conditional. It allows you to do things such as:

 # stap  testguruprep.stp
 hello, guru-mode? nope
 # stap -g testguruprep.stp
 hello, guru-mode? yup

 # cat testguruprep.stp
 global foo = %( guru_mode == 1 %? "yup" %: "nope" %)

 probe begin {
   printf("hello, guru-mode? %s\n", foo)
   exit()
 }

Since this is my first real contribution to systemtap I tried to follow the
addition of the "runtime" preprocessor conditional as closely as possible.

Here follows the output of "git format-patch":


>From 52e7a2f342a4f26e82ef40126ff4296f8ba7ac3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20Kjellstr=C3=B6m?= <cap@nsc.liu.se>
Date: Wed, 26 Feb 2014 17:16:38 +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 420b135..95be35b 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 6c1598e..720f8fb 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 <cap@nsc.liu.se>
 //
 // 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<int64_t>(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 0000000..e1d97e0
--- /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 0000000..d69cb0e
--- /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 0000000..703509b
--- /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 756cc4a..621e0c5 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"
+   %)
+%)
-- 
1.8.5.3



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]