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


Hi

This patch allows you to get syscall arguments from
process.syscall probes. This just uses _stp_user_syscall_arg()
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 |    5 ++-
 tapsets.cxx       |   80 +++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 74 insertions(+), 11 deletions(-)

Index: systemtap/tapsets.cxx
===================================================================
--- systemtap.orig/tapsets.cxx	2008-09-03 15:14:37.000000000 -0400
+++ systemtap/tapsets.cxx	2008-09-03 16:00:27.000000000 -0400
@@ -5842,6 +5842,8 @@
   enum utrace_derived_probe_flags flags;
   bool target_symbol_seen;
 
+  void visit_target_symbol_arg (target_symbol* e);
+  void visit_target_symbol_syscall (target_symbol* e);
   void visit_target_symbol (target_symbol* e);
 };
 
@@ -5916,18 +5918,58 @@
 
 
 void
-utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e)
+utrace_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e)
 {
-  assert(e->base_name.size() > 0 && e->base_name[0] == '$');
+  string argnum_s = e->base_name.substr(4,e->base_name.length()-4);
+  int argnum = atoi (argnum_s.c_str());
 
-  if (flags != UDPF_SYSCALL && flags != UDPF_SYSCALL_RETURN)
-    throw semantic_error ("only \"process(PATH_OR_PID).syscall\" and \"process(PATH_OR_PID).syscall.return\" probes support target symbols",
-			  e->tok);
+  if (e->components.size() > 0)
+    {
+      switch (e->components[0].first)
+	{
+	case target_symbol::comp_literal_array_index:
+	  throw semantic_error("utrace target variable '$argN' may not be used as array",
+			       e->tok);
+	  break;
+	case target_symbol::comp_struct_member:
+	  throw semantic_error("utrace target variable '$argN' may not be used as a structure",
+			       e->tok);
+	  break;
+	default:
+	  throw semantic_error ("invalid use of utrace target variable '$argN'",
+				e->tok);
+	  break;
+	}
+    }
 
-  if (e->base_name != "$syscall")
-    throw semantic_error ("invalid target symbol for utrace probe, $syscall expected",
-			  e->tok);
+  // FIXME: max argnument number should not be hardcoded.
+  if (argnum < 1 || argnum > 6)
+    throw semantic_error ("invalid syscall argument number (1-6)", e->tok);
+
+  bool lvalue = is_active_lvalue(e);
+  if (lvalue)
+    throw semantic_error("utrace '$argN' variable is read-only", e->tok);
 
+  // Remember that we've seen a target variable.
+  target_symbol_seen = true;
+
+  // We're going to substitute a synthesized '_utrace_syscall_arg'
+  // function call for the '$argN' reference.
+  functioncall* n = new functioncall;
+  n->tok = e->tok;
+  n->function = "_utrace_syscall_arg";
+  n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session
+
+  literal_number *num = new literal_number(argnum - 1);
+  num->tok = e->tok;
+  n->args.push_back(num);
+
+  provide <functioncall*> (this, n);
+}
+
+void
+utrace_var_expanding_copy_visitor::visit_target_symbol_syscall (target_symbol* e)
+{
   if (e->components.size() > 0)
     {
       switch (e->components[0].first)
@@ -5949,12 +5991,12 @@
 
   bool lvalue = is_active_lvalue(e);
   if (lvalue)
-    throw semantic_error("utrace $syscall variable is read-only", e->tok);
+    throw semantic_error("utrace '$syscall' variable is read-only", e->tok);
 
   // Remember that we've seen a target variable.
   target_symbol_seen = true;
 
-  // We're going to substitute a synthesized '_syscall_nr_get'
+  // We're going to substitute a synthesized '_utrace_syscall_nr'
   // function call for the '$syscall' reference.
   functioncall* n = new functioncall;
   n->tok = e->tok;
@@ -5964,6 +6006,24 @@
   provide <functioncall*> (this, n);
 }
 
+void
+utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e)
+{
+  assert(e->base_name.size() > 0 && e->base_name[0] == '$');
+
+  if (flags != UDPF_SYSCALL && flags != UDPF_SYSCALL_RETURN)
+    throw semantic_error ("only \"process(PATH_OR_PID).syscall\" and \"process(PATH_OR_PID).syscall.return\" probes support target symbols",
+			  e->tok);
+
+  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
+    throw semantic_error ("invalid target symbol for utrace probe, $syscall or $argN expected",
+			  e->tok);
+}
+
 
 struct utrace_builder: public derived_probe_builder
 {
Index: systemtap/tapset/utrace.stp
===================================================================
--- systemtap.orig/tapset/utrace.stp	2008-09-03 15:14:34.000000000 -0400
+++ systemtap/tapset/utrace.stp	2008-09-03 15:59:44.000000000 -0400
@@ -5,7 +5,10 @@
 #include "syscall.h"
 %}
 
-
 function _utrace_syscall_nr:long () %{
    THIS->__retvalue = __stp_user_syscall_nr(CONTEXT->regs); /* pure */
 %}
+
+function _utrace_syscall_arg:long (n:long) %{
+   THIS->__retvalue = *__stp_user_syscall_arg(current, CONTEXT->regs, (int)THIS->n); /* pure */
+%}

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