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.
--- /dev/null
+// 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
+ }
+%)
--- /dev/null
+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
+ }
+}
+
+
+
--- /dev/null
+#!/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)
+}