]> sourceware.org Git - systemtap.git/commitdiff
PR17741: add a try_assign macro
authorAbegail Jakop <ajakop@redhat.com>
Tue, 19 Jan 2016 20:35:09 +0000 (15:35 -0500)
committerAbegail Jakop <ajakop@redhat.com>
Tue, 19 Jan 2016 22:18:23 +0000 (17:18 -0500)
add a try_assign macro that stores in a provided variable the value
from evaluating the body of the try or catch statement.

tapset/try_assign.stpm:    define a try_assign macro
testsuite/../try_assign.*: basic testcase checking that the try_assign
macro's functionality works as expected.

tapset/try_assign.stpm [new file with mode: 0644]
testsuite/systemtap.base/try_assign.exp [new file with mode: 0644]
testsuite/systemtap.base/try_assign.stp [new file with mode: 0644]

diff --git a/tapset/try_assign.stpm b/tapset/try_assign.stpm
new file mode 100644 (file)
index 0000000..b18eb6f
--- /dev/null
@@ -0,0 +1,14 @@
+// define a macro that executes a try catch statement. If there was no error,
+// a provided variable is assigned to the evaluation of the try body,
+// otherwise to the evaluation of the catch body. This assumes that the try and
+// catch body are meant to return a value. If they do not, then do not use this
+// macro. If either of the bodies do not return a value, then a compilation
+// error occurs.
+
+@define try_assign(assign_to, try_body, catch_body) %(
+  try {
+    @assign_to = @try_body
+  } catch {
+    @assign_to = @catch_body
+  }
+%)
diff --git a/testsuite/systemtap.base/try_assign.exp b/testsuite/systemtap.base/try_assign.exp
new file mode 100644 (file)
index 0000000..df9c1d6
--- /dev/null
@@ -0,0 +1,17 @@
+set test_file_name "try_assign"
+set test test_file_name
+
+if {! [installtest_p]} { untested $test_file_name; return }
+
+foreach runtime [get_runtime_list] {
+    if {$runtime != ""} {
+        lappend test "($runtime)"
+        stap_run $srcdir/$subdir/$test_file_name.stp no_load $all_pass_string \
+        --runtime=$runtime
+    } else {
+        stap_run $srcdir/$subdir/$test_file_name.stp no_load $all_pass_string
+    }
+}
+
+
+
diff --git a/testsuite/systemtap.base/try_assign.stp b/testsuite/systemtap.base/try_assign.stp
new file mode 100644 (file)
index 0000000..24bd757
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env stap
+
+function func (a){
+  if (a == 1)
+    error("This message should not appear")
+  else
+    return "systemtap test success"
+}
+
+probe begin {
+       println("systemtap starting probe")
+  exit()
+}
+probe end {
+       println("systemtap ending probe")
+  @try_assign(msg, func(1), func(0))
+  println(msg)
+}
This page took 0.039322 seconds and 5 git commands to generate.