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 2/3] utrace-probe: add $return variable support on utrace-syscall-return probe


Hi

This patch allows you to get syscall return value from
process.syscall.return probes. This just uses
_stp_user_syscall_return_value() function declared
in syscall.h.

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

---
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>

 tapset/utrace.stp |    4 ++++
 tapsets.cxx       |   32 ++++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 10 deletions(-)

Index: systemtap/tapset/utrace.stp
===================================================================
--- systemtap.orig/tapset/utrace.stp	2008-09-03 15:59:44.000000000 -0400
+++ systemtap/tapset/utrace.stp	2008-09-03 16:00:39.000000000 -0400
@@ -12,3 +12,7 @@
 function _utrace_syscall_arg:long (n:long) %{
    THIS->__retvalue = *__stp_user_syscall_arg(current, CONTEXT->regs, (int)THIS->n); /* pure */
 %}
+
+function _utrace_syscall_return:long () %{
+   THIS->__retvalue = *__stp_user_syscall_return_value(current, CONTEXT->regs); /* pure */
+%}
Index: systemtap/tapsets.cxx
===================================================================
--- systemtap.orig/tapsets.cxx	2008-09-03 16:00:27.000000000 -0400
+++ systemtap/tapsets.cxx	2008-09-03 16:05:41.000000000 -0400
@@ -5843,7 +5843,7 @@
   bool target_symbol_seen;
 
   void visit_target_symbol_arg (target_symbol* e);
-  void visit_target_symbol_syscall (target_symbol* e);
+  void visit_target_symbol_context (target_symbol* e);
   void visit_target_symbol (target_symbol* e);
 };
 
@@ -5968,22 +5968,24 @@
 }
 
 void
-utrace_var_expanding_copy_visitor::visit_target_symbol_syscall (target_symbol* e)
+utrace_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e)
 {
+  string sname = e->base_name;
+
   if (e->components.size() > 0)
     {
       switch (e->components[0].first)
 	{
 	case target_symbol::comp_literal_array_index:
-	  throw semantic_error("utrace target variable '$syscall' may not be used as array",
+	  throw semantic_error("utrace target variable '" + sname + "' may not be used as array",
 			       e->tok);
 	  break;
 	case target_symbol::comp_struct_member:
-	  throw semantic_error("utrace target variable '$syscall' may not be used as a structure",
+	  throw semantic_error("utrace target variable '" + sname + "' may not be used as a structure",
 			       e->tok);
 	  break;
 	default:
-	  throw semantic_error ("invalid use of utrace target variable '$syscall'",
+	  throw semantic_error ("invalid use of utrace target variable '" + sname + "'",
 				e->tok);
 	  break;
 	}
@@ -5991,7 +5993,17 @@
 
   bool lvalue = is_active_lvalue(e);
   if (lvalue)
-    throw semantic_error("utrace '$syscall' variable is read-only", e->tok);
+    throw semantic_error("utrace '" + sname + "' variable is read-only", e->tok);
+
+  string fname;
+  if (sname == "$return")
+    {
+      if (flags != UDPF_SYSCALL_RETURN)
+	throw semantic_error ("only \"process(PATH_OR_PID).syscall.return\" support $return.", e->tok);
+      fname = "_utrace_syscall_return";
+    }
+  else
+    fname = "_utrace_syscall_nr";
 
   // Remember that we've seen a target variable.
   target_symbol_seen = true;
@@ -6000,7 +6012,7 @@
   // function call for the '$syscall' reference.
   functioncall* n = new functioncall;
   n->tok = e->tok;
-  n->function = "_utrace_syscall_nr";
+  n->function = fname;
   n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session
 
   provide <functioncall*> (this, n);
@@ -6017,10 +6029,10 @@
 
   if (e->base_name.substr(0,4) == "$arg")
     visit_target_symbol_arg(e);
-  else if (e->base_name == "$syscall")
-    visit_target_symbol_syscall(e);
+  else if (e->base_name == "$syscall" || e->base_name == "$return")
+    visit_target_symbol_context(e);
   else
-    throw semantic_error ("invalid target symbol for utrace probe, $syscall or $argN expected",
+    throw semantic_error ("invalid target symbol for utrace probe, $syscall, $return or $argN expected",
 			  e->tok);
 }
 

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