From 8b342140777881a3d9046643200b6ce6eec02068 Mon Sep 17 00:00:00 2001 From: Abegail Jakop Date: Tue, 19 Jan 2016 15:35:09 -0500 Subject: [PATCH] PR17741: add a try_assign macro 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 | 14 ++++++++++++++ testsuite/systemtap.base/try_assign.exp | 17 +++++++++++++++++ testsuite/systemtap.base/try_assign.stp | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tapset/try_assign.stpm create mode 100644 testsuite/systemtap.base/try_assign.exp create mode 100644 testsuite/systemtap.base/try_assign.stp diff --git a/tapset/try_assign.stpm b/tapset/try_assign.stpm new file mode 100644 index 000000000..b18eb6f2a --- /dev/null +++ b/tapset/try_assign.stpm @@ -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 index 000000000..df9c1d653 --- /dev/null +++ b/testsuite/systemtap.base/try_assign.exp @@ -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 index 000000000..24bd75762 --- /dev/null +++ b/testsuite/systemtap.base/try_assign.stp @@ -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) +} -- 2.43.5