From 4a0e1ceaed41df14fa3a4870c00c334a6dd8384f Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:00:58 -0400 Subject: Add ia64 utrace support --- runtime/ChangeLog | 4 ++++ runtime/syscall.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 71cd97e4..9cca0759 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Masami Hiramatsu + + * syscall.h: Added ia64 support. + 2008-09-09 Mark Wielaard * sym.c (_stp_kallsyms_lookup): Correct this_section_offset diff --git a/runtime/syscall.h b/runtime/syscall.h index 24e93463..8416fd1d 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -66,7 +66,15 @@ #define MUNMAP_SYSCALL_NO(tsk) 91 #define MREMAP_SYSCALL_NO(tsk) 163 #endif - + +#if defined(__ia64__) +#define MMAP_SYSCALL_NO(tsk) 1151 +#define MMAP2_SYSCALL_NO(tsk) 1172 +#define MPROTECT_SYSCALL_NO(tsk) 1155 +#define MUNMAP_SYSCALL_NO(tsk) 1152 +#define MREMAP_SYSCALL_NO(tsk) 1156 +#endif + #if !defined(MMAP_SYSCALL_NO) || !defined(MMAP2_SYSCALL_NO) \ || !defined(MPROTECT_SYSCALL_NO) || !defined(MUNMAP_SYSCALL_NO) \ || !defined(MREMAP_SYSCALL_NO) @@ -95,6 +103,14 @@ __stp_user_syscall_nr(struct pt_regs *regs) } #endif +#if defined(__ia64__) +static inline unsigned long +__stp_user_syscall_nr(struct pt_regs *regs) +{ + return regs->r15; +} +#endif + #if defined(__i386__) || defined(__x86_64__) static inline long * __stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) @@ -129,6 +145,14 @@ __stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) } #endif +#if defined(__ia64__) +static inline long * +__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +{ + return ®s->r8; +} +#endif + #if defined(__i386__) || defined(__x86_64__) static inline long * __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, @@ -211,4 +235,25 @@ __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, } #endif +#if defined(__ia64__) +static inline long * +__stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, + unsigned int n) +{ + struct ia64_stap_get_arbsp_param pa; + if (n > 5) { + _stp_error("syscall arg > 5"); + return NULL; + } + + pa.ip = regs->cr_iip; + unw_init_running(ia64_stap_get_arbsp, &pa); + if (pa.address == 0) + return NULL; + + return ia64_rse_skip_regs(pa.address, n); + +} +#endif + #endif /* _SYSCALL_H_ */ -- cgit From 901a409a01da22778ea15f7b9f938885bdc38847 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:01:37 -0400 Subject: Utrace on ia64 fast fetch-register support --- runtime/ChangeLog | 11 +++++++++++ runtime/regs-ia64.c | 21 +++++++++++++++------ runtime/syscall.h | 17 ++++++----------- runtime/task_finder.c | 6 ++++++ 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 9cca0759..f7a844d8 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,14 @@ +2008-09-09 Masami Hiramatsu + + * regs-ia64.c (__ia64_fetch_register): Return the address of the + register. + (ia64_fetch_register): Use __ia64_fetch_register. + * syscall.h (____stp_user_syscall_arg): Use __ia64_fetch_register. + (__stp_user_syscall_arg): Wrapping ____stp_user_syscall_arg to pass the + unwind address cache. + * task_finder.c (__stp_utrace_task_finder_target_syscall_): Added dummy + unwind address cache. + 2008-09-09 Masami Hiramatsu * syscall.h: Added ia64 support. diff --git a/runtime/regs-ia64.c b/runtime/regs-ia64.c index fd8d8ca8..8ce3e4c3 100644 --- a/runtime/regs-ia64.c +++ b/runtime/regs-ia64.c @@ -61,27 +61,36 @@ static void ia64_stap_get_arbsp(struct unw_frame_info *info, void *arg) -(__offset + (regs->cr_ifs & 127)));\ } -static long ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) +static long * +__ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) { struct ia64_stap_get_arbsp_param pa; if (regno == 12) - return pt_regs->r12; + return &pt_regs->r12; if (regno >= 8 && regno <= 11) - return *(unsigned long *)(&pt_regs->r8 + regno - 8); + return (long *)(&pt_regs->r8 + regno - 8); else if (regno < 32 || regno > 127) - return 0; + return NULL; if (!*cache) { pa.ip = pt_regs->cr_iip; unw_init_running(ia64_stap_get_arbsp, &pa); if (pa.address == 0) - return 0; + return NULL; *cache = pa.address; } - return *ia64_rse_skip_regs(*cache, regno-32); + return ia64_rse_skip_regs(*cache, regno-32); +} + +static long +ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) +{ + long *reg; + reg = __ia64_fetch_register(regno, pt_regs, cache); + return (reg != NULL)? *reg : 0; } static void ia64_store_register(int regno, diff --git a/runtime/syscall.h b/runtime/syscall.h index 8416fd1d..24fc7b1c 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -236,23 +236,18 @@ __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, #endif #if defined(__ia64__) +#define __stp_user_syscall_arg(task, regs, n) \ + ____stp_user_syscall_arg(task, regs, n, &c->unwaddr) + static inline long * -__stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, - unsigned int n) +____stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, + unsigned int n, unsigned long **cache) { - struct ia64_stap_get_arbsp_param pa; if (n > 5) { _stp_error("syscall arg > 5"); return NULL; } - - pa.ip = regs->cr_iip; - unw_init_running(ia64_stap_get_arbsp, &pa); - if (pa.address == 0) - return NULL; - - return ia64_rse_skip_regs(pa.address, n); - + return __ia64_fetch_register(n + 32, regs, cache); } #endif diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 2d4eed15..cbb10d35 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -843,6 +843,9 @@ __stp_utrace_task_finder_target_syscall_entry(enum utrace_resume_action action, struct vm_area_struct *vma; unsigned long *arg0_addr, arg0; int rc; +#if defined(__ia64__) + struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; +#endif if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { debug_task_finder_detach(); @@ -950,6 +953,9 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, struct mm_struct *mm; struct vm_area_struct *vma; struct __stp_tf_vma_entry *entry = NULL; +#if defined(__ia64__) + struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; +#endif if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { debug_task_finder_detach(); -- cgit From bc54e71c6747fa2c234737d3a715b0decc3663b2 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:02:21 -0400 Subject: Add $name context variable support on marker probes --- ChangeLog | 13 ++++++++++ stapprobes.5.in | 2 ++ tapset/ChangeLog | 4 +++ tapset/marker.stp | 22 +++++++++++++++++ tapsets.cxx | 49 +++++++++++++++---------------------- testsuite/ChangeLog | 4 +++ testsuite/systemtap.base/marker.exp | 45 ++++++++++++++++++++++++++++++++++ translate.cxx | 2 ++ 8 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 tapset/marker.stp diff --git a/ChangeLog b/ChangeLog index 09f661ae..cb5a6f4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-09-09 Masami Hiramatsu + + * stapprobes.5.in : Added a line for $name context variable. + * translate.cxx (c_unparser::emit_common_header): Add marker_name and + marker_format fields to context. + * tapsets.cxx (common_probe_entryfn_prologue) : Ditto. + (mark_derived_probe_group::emit_module_decls) : Ditto. + (mark_var_expanding_copy_visitor) : change visit_target_symbol_format + to visit_target_symbol_context. + (mark_var_expanding_copy_visitor::visit_target_symbol_context): handle + not only $format but also $name. + (mark_var_expanding_copy_visitor::visit_target_symbol): Ditto. + 2008-09-07 Frank Ch. Eigler * tapsets.cxx (build_blacklist): Add some x86 raw port-io spots. diff --git a/stapprobes.5.in b/stapprobes.5.in index 5281c40e..ecc6956c 100644 --- a/stapprobes.5.in +++ b/stapprobes.5.in @@ -520,6 +520,8 @@ and string parameters are passed in a type-safe manner. The marker format string associated with a marker is available in .BR $format . +And also the marker name string is avalable in +.BR $name . .SS PERFORMANCE MONITORING HARDWARE diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 39b6b93b..d3117620 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Masami Hiramatsu + + * marker.stp : New file, including marker context variable accessors. + 2008-09-01 Frank Ch. Eigler PR4225 merge. diff --git a/tapset/marker.stp b/tapset/marker.stp new file mode 100644 index 00000000..593ffaea --- /dev/null +++ b/tapset/marker.stp @@ -0,0 +1,22 @@ +// +// kernel marker tapset +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +/* marker-only context accessors */ + + +function _mark_name_get:string () %{ + strlcpy (THIS->__retvalue, + (CONTEXT->marker_name)?CONTEXT->marker_name:"", + MAXSTRINGLEN); /* pure */ +%} + +function _mark_format_get:string () %{ + strlcpy (THIS->__retvalue, + (CONTEXT->marker_format)?CONTEXT->marker_format:"", + MAXSTRINGLEN); /* pure */ +%} diff --git a/tapsets.cxx b/tapsets.cxx index 64fa9d34..4774c0f6 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -221,6 +221,8 @@ common_probe_entryfn_prologue (translator_output* o, string statestr, // reset unwound address cache o->newline() << "c->pi = 0;"; o->newline() << "c->regparm = 0;"; + o->newline() << "c->marker_name = NULL;"; + o->newline() << "c->marker_format = NULL;"; o->newline() << "c->probe_point = 0;"; if (! interruptible) o->newline() << "c->actionremaining = MAXACTION;"; @@ -7758,7 +7760,7 @@ struct mark_var_expanding_copy_visitor: public var_expanding_copy_visitor void visit_target_symbol (target_symbol* e); void visit_target_symbol_arg (target_symbol* e); - void visit_target_symbol_format (target_symbol* e); + void visit_target_symbol_context (target_symbol* e); }; @@ -7865,48 +7867,37 @@ mark_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) void -mark_var_expanding_copy_visitor::visit_target_symbol_format (target_symbol* e) +mark_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e) { - static bool function_synthesized = false; + string sname = e->base_name; if (is_active_lvalue (e)) - throw semantic_error("write to marker format not permitted", e->tok); + throw semantic_error("write to marker '" + sname + "' not permitted", e->tok); if (e->components.size() > 0) { switch (e->components[0].first) { case target_symbol::comp_literal_array_index: - throw semantic_error("marker format may not be used as array", + throw semantic_error("marker '" + sname + "' may not be used as array", e->tok); break; case target_symbol::comp_struct_member: - throw semantic_error("marker format may not be used as a structure", + throw semantic_error("marker '" + sname + "' may not be used as a structure", e->tok); break; default: - throw semantic_error ("invalid marker format use", e->tok); + throw semantic_error ("invalid marker '" + sname + "' use", e->tok); break; } } - string fname = string("_mark_format_get"); - - // Synthesize a function (if not already synthesized). - if (! function_synthesized) - { - function_synthesized = true; - functiondecl *fdecl = new functiondecl; - fdecl->tok = e->tok; - embeddedcode *ec = new embeddedcode; - ec->tok = e->tok; - - ec->code = string("strlcpy (THIS->__retvalue, CONTEXT->data, MAXSTRINGLEN); /* pure */"); - fdecl->name = fname; - fdecl->body = ec; - fdecl->type = pe_string; - sess.functions.push_back(fdecl); - } + string fname; + if (e->base_name == "$format") { + fname = string("_mark_format_get"); + } else { + fname = string("_mark_name_get"); + } // Synthesize a functioncall. functioncall* n = new functioncall; @@ -7923,10 +7914,10 @@ mark_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) if (e->base_name.substr(0,4) == "$arg") visit_target_symbol_arg (e); - else if (e->base_name == "$format") - visit_target_symbol_format (e); + else if (e->base_name == "$format" || e->base_name == "$name") + visit_target_symbol_context (e); else - throw semantic_error ("invalid target symbol for marker, $argN or $format expected", + throw semantic_error ("invalid target symbol for marker, $argN, $name or $format expected", e->tok); } @@ -8225,8 +8216,8 @@ mark_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(1) << "struct stap_marker_probe *smp = (struct stap_marker_probe *)probe_data;"; common_probe_entryfn_prologue (s.op, "STAP_SESSION_RUNNING"); s.op->newline() << "c->probe_point = smp->pp;"; - s.op->newline() << "c->data = (char *)smp->format;"; - + s.op->newline() << "c->marker_name = smp->name;"; + s.op->newline() << "c->marker_format = smp->format;"; s.op->newline() << "c->mark_va_list = args;"; s.op->newline() << "(*smp->ph) (c);"; s.op->newline() << "c->mark_va_list = NULL;"; diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 045772a3..52892e8d 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Masami Hiramatsu + + * systemtap.base/marker.exp : Added testcases of $name. + 2008-09-06 Frank Ch. Eigler * systemtap.base/cmd_parse.exp: Adapt to sh-c-less "stap -c" diff --git a/testsuite/systemtap.base/marker.exp b/testsuite/systemtap.base/marker.exp index 89c0b8c3..0cacf60d 100644 --- a/testsuite/systemtap.base/marker.exp +++ b/testsuite/systemtap.base/marker.exp @@ -230,3 +230,48 @@ if {$kernel_markers_found == 0} { [lindex $kernel_marker_names 0] "foo"] stap_compile $TEST_NAME 0 $script } + +set TEST_NAME "K_MARKER18" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that prints the name string of a + # marker. + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name}] + stap_compile $TEST_NAME 1 $script +} + +set TEST_NAME "K_MARKER19" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that writes to a marker name string + # (which isn't allowed). + set script [format $kernel_script_arg2 \ + [lindex $kernel_marker_names 0] {\$name}] + stap_compile $TEST_NAME 0 $script +} + +set TEST_NAME "K_MARKER20" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that treats the marker name string as a + # structure (which isn't allowed). + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name->foo}] + stap_compile $TEST_NAME 0 $script +} + +set TEST_NAME "K_MARKER21" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that treats the marker name string like + # an array (which isn't allowed). + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name\[0\]}] + stap_compile $TEST_NAME 0 $script +} + diff --git a/translate.cxx b/translate.cxx index 2fe33314..e5435fac 100644 --- a/translate.cxx +++ b/translate.cxx @@ -881,6 +881,8 @@ c_unparser::emit_common_header () o->newline() << "struct kretprobe_instance *pi;"; o->newline() << "int regparm;"; o->newline() << "va_list *mark_va_list;"; + o->newline() << "const char * marker_name;"; + o->newline() << "const char * marker_format;"; o->newline() << "void *data;"; o->newline() << "#ifdef STP_TIMING"; o->newline() << "Stat *statp;"; -- cgit From 6270adc1ec2b89a201c932b94fb8ec8abc4e977f Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:02:56 -0400 Subject: Add $argN context variables on per-process-syscall probes --- ChangeLog | 11 ++++++++ NEWS | 4 +++ stapprobes.5.in | 9 ++++-- tapset/ChangeLog | 4 +++ tapset/utrace.stp | 5 +++- tapsets.cxx | 83 ++++++++++++++++++++++++++++++++++++++++++++++++------- 6 files changed, 103 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb5a6f4b..df495cab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-09 Masami Hiramatsu + + * stapprobes.5.in: Added a description about $argN. + * NEWS: Ditto. + * tapsets.cxx (utrace_var_expanding_copy_visitor): Added + visit_target_symbol_arg() and visit_target_symbol_syscall(). + (visit_target_symbol_arg): New function for handling $argN. + (visit_target_symbol_syscall): New function for handling $syscall. + (visit_target_symbol): Use visit_target_symbol_arg() and + visit_target_symbol_syscall(). + 2008-09-09 Masami Hiramatsu * stapprobes.5.in : Added a line for $name context variable. diff --git a/NEWS b/NEWS index c7ddce45..b48870e2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ * What's new +- Additional context variables are available on user-space syscall probes. + - $argN ($arg1, $arg2, ... $arg6) in process(PATH_OR_PID).syscall + gives you the argument of the system call. + - Target process mode (stap -c CMD or -x PID) now implicitly restricts all "process.*" probes to the given child process. (It does not affect kernel.* or other probe types.) The CMD string is now executed directly, diff --git a/stapprobes.5.in b/stapprobes.5.in index ecc6956c..6e8c3ff2 100644 --- a/stapprobes.5.in +++ b/stapprobes.5.in @@ -421,8 +421,13 @@ probe gets called when a thread described by PID or PATH dies. A .B .syscall probe gets called when a thread described by PID or PATH makes a -system call. The system call number is available in the "$syscall" -context variable. +system call. The system call number is available in the +.BR $syscall +context variable, and the first 6 arguments of the system call +are available in the +.BR $argN +(ex. $arg1, $arg2, ...) context variable. + A .B .syscall.return probe gets called when a thread described by PID or PATH returns from a diff --git a/tapset/ChangeLog b/tapset/ChangeLog index d3117620..5a08ac63 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Masami Hiramatsu + + * utrace.stp: Added _utrace_syscall_arg(). + 2008-09-09 Masami Hiramatsu * marker.stp : New file, including marker context variable accessors. diff --git a/tapset/utrace.stp b/tapset/utrace.stp index 3831ca3c..2b661573 100644 --- a/tapset/utrace.stp +++ b/tapset/utrace.stp @@ -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 */ +%} diff --git a/tapsets.cxx b/tapsets.cxx index 4774c0f6..5941339c 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -5846,6 +5846,8 @@ struct utrace_var_expanding_copy_visitor: public var_expanding_copy_visitor 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); }; @@ -5923,18 +5925,61 @@ utrace_derived_probe::join_group (systemtap_session& s) 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 (flags != UDPF_SYSCALL) + throw semantic_error ("only \"process(PATH_OR_PID).syscall\" support $argN.", e->tok); - if (e->base_name != "$syscall") - throw semantic_error ("invalid target symbol for utrace probe, $syscall expected", - 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; + } + } + + // 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 (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) @@ -5956,12 +6001,12 @@ utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) 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; @@ -5971,6 +6016,24 @@ utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) provide (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 { -- cgit From 5d67b47ccd850e53c6c6c72a6f63327faa190966 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:16:30 -0400 Subject: Add $return context variables on per-process-syscall.return probes --- ChangeLog | 10 ++++++++++ NEWS | 2 ++ stapprobes.5.in | 7 +++++-- tapset/ChangeLog | 4 ++++ tapset/utrace.stp | 4 ++++ tapsets.cxx | 32 ++++++++++++++++++++++---------- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index df495cab..44cfc4cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-09-09 Masami Hiramatsu + + * stapprobes.5.in: Added a description about $return. + * NEWS: Ditto. + * tapsets.cxx (utrace_var_expanding_copy_visitor): Change + visit_target_symbol_syscall() to visit_target_symbol_context(). + (utrace_var_expanding_copy_visitor::visit_target_symbol_context): + Handle not only $syscall but also $return. + (utrace_var_expanding_copy_visitor::visit_target_symbol): Ditto. + 2008-09-09 Masami Hiramatsu * stapprobes.5.in: Added a description about $argN. diff --git a/NEWS b/NEWS index b48870e2..04ba292e 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ - Additional context variables are available on user-space syscall probes. - $argN ($arg1, $arg2, ... $arg6) in process(PATH_OR_PID).syscall gives you the argument of the system call. + - $return in process(PATH_OR_PID).syscall.return gives you the return + value of the system call. - Target process mode (stap -c CMD or -x PID) now implicitly restricts all "process.*" probes to the given child process. (It does not affect diff --git a/stapprobes.5.in b/stapprobes.5.in index 6e8c3ff2..36b36156 100644 --- a/stapprobes.5.in +++ b/stapprobes.5.in @@ -427,11 +427,14 @@ context variable, and the first 6 arguments of the system call are available in the .BR $argN (ex. $arg1, $arg2, ...) context variable. - A .B .syscall.return probe gets called when a thread described by PID or PATH returns from a -system call. The system call number is available in the "$syscall" +system call. The system call number is available in the +.BR $syscall +context variable, and the return value of the system call is available +in the +.BR $return context variable. A .B .itrace diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 5a08ac63..3e2ebaf7 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,7 @@ +2008-09-09 Masami Hiramatsu + + * utrace.stp: Added _utrace_syscall_return(). + 2008-09-09 Masami Hiramatsu * utrace.stp: Added _utrace_syscall_arg(). diff --git a/tapset/utrace.stp b/tapset/utrace.stp index 2b661573..34cb32c5 100644 --- a/tapset/utrace.stp +++ b/tapset/utrace.stp @@ -12,3 +12,7 @@ function _utrace_syscall_nr:long () %{ 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 */ +%} diff --git a/tapsets.cxx b/tapsets.cxx index 5941339c..28f945fe 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -5847,7 +5847,7 @@ struct utrace_var_expanding_copy_visitor: public var_expanding_copy_visitor 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); }; @@ -5978,22 +5978,24 @@ utrace_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) } 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; } @@ -6001,7 +6003,17 @@ utrace_var_expanding_copy_visitor::visit_target_symbol_syscall (target_symbol* e 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; @@ -6010,7 +6022,7 @@ utrace_var_expanding_copy_visitor::visit_target_symbol_syscall (target_symbol* e // 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 (this, n); @@ -6027,10 +6039,10 @@ utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) 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); } -- cgit From 256d22cfb336b4cf0ec5b35bab89ca55ff5ce9ee Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 9 Sep 2008 16:32:59 -0400 Subject: Added tests for utrace-syscall probe context variables. --- testsuite/ChangeLog | 12 ++++++++++++ testsuite/buildok/per-process-syscall.stp | 18 ++++++++++++++++++ testsuite/semko/utrace15.stp | 4 ++++ testsuite/semko/utrace16.stp | 4 ++++ testsuite/semko/utrace17.stp | 4 ++++ testsuite/semko/utrace18.stp | 4 ++++ testsuite/semko/utrace19.stp | 4 ++++ testsuite/semko/utrace20.stp | 4 ++++ testsuite/semko/utrace21.stp | 4 ++++ testsuite/semko/utrace22.stp | 4 ++++ 10 files changed, 62 insertions(+) create mode 100755 testsuite/buildok/per-process-syscall.stp create mode 100755 testsuite/semko/utrace15.stp create mode 100755 testsuite/semko/utrace16.stp create mode 100755 testsuite/semko/utrace17.stp create mode 100755 testsuite/semko/utrace18.stp create mode 100755 testsuite/semko/utrace19.stp create mode 100755 testsuite/semko/utrace20.stp create mode 100755 testsuite/semko/utrace21.stp create mode 100755 testsuite/semko/utrace22.stp diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 52892e8d..4f0f567d 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2008-09-09 Masami Hiramatsu + + * buildok/per-process-syscall.stp: New test, for process.syscall test. + * semko/utrace15.stp: Ditto. + * semko/utrace16.stp: Ditto. + * semko/utrace17.stp: Ditto. + * semko/utrace18.stp: Ditto. + * semko/utrace19.stp: Ditto. + * semko/utrace20.stp: Ditto. + * semko/utrace21.stp: Ditto. + * semko/utrace22.stp: Ditto. + 2008-09-09 Masami Hiramatsu * systemtap.base/marker.exp : Added testcases of $name. diff --git a/testsuite/buildok/per-process-syscall.stp b/testsuite/buildok/per-process-syscall.stp new file mode 100755 index 00000000..c2c41c0b --- /dev/null +++ b/testsuite/buildok/per-process-syscall.stp @@ -0,0 +1,18 @@ +#! stap -p4 +# +# per-process syscall trace test + +probe process.syscall { +print($syscall) +print($arg1) +print($arg2) +print($arg3) +print($arg4) +print($arg5) +print($arg6) +} + +probe process.syscall.return { +print($syscall) +print($return) +} diff --git a/testsuite/semko/utrace15.stp b/testsuite/semko/utrace15.stp new file mode 100755 index 00000000..56d91e89 --- /dev/null +++ b/testsuite/semko/utrace15.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# write to $argN +probe process("/bin/cat").syscall { $arg1 = 1 } diff --git a/testsuite/semko/utrace16.stp b/testsuite/semko/utrace16.stp new file mode 100755 index 00000000..f88923d6 --- /dev/null +++ b/testsuite/semko/utrace16.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $argN as a pointer +probe process("/bin/cat").syscall { print($arg1->foo) } diff --git a/testsuite/semko/utrace17.stp b/testsuite/semko/utrace17.stp new file mode 100755 index 00000000..3a296dff --- /dev/null +++ b/testsuite/semko/utrace17.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $argN as an array +probe process("/bin/cat").syscall { print($arg1[0]) } diff --git a/testsuite/semko/utrace18.stp b/testsuite/semko/utrace18.stp new file mode 100755 index 00000000..5d4960db --- /dev/null +++ b/testsuite/semko/utrace18.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# write to $return +probe process("/bin/cat").syscall.return { $return = 1 } diff --git a/testsuite/semko/utrace19.stp b/testsuite/semko/utrace19.stp new file mode 100755 index 00000000..3d30dc5e --- /dev/null +++ b/testsuite/semko/utrace19.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# access to $return from syscall entry +probe process("/bin/cat").syscall { print($return) } diff --git a/testsuite/semko/utrace20.stp b/testsuite/semko/utrace20.stp new file mode 100755 index 00000000..15fdc4c5 --- /dev/null +++ b/testsuite/semko/utrace20.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $return as an array +probe process("/bin/cat").syscall { print($return[0]) } diff --git a/testsuite/semko/utrace21.stp b/testsuite/semko/utrace21.stp new file mode 100755 index 00000000..aa29ec59 --- /dev/null +++ b/testsuite/semko/utrace21.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $return as a pointer/structure +probe process("/bin/cat").syscall.return { print($return->foo) } diff --git a/testsuite/semko/utrace22.stp b/testsuite/semko/utrace22.stp new file mode 100755 index 00000000..710810f6 --- /dev/null +++ b/testsuite/semko/utrace22.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# access to $argN from syscall return +probe process("/bin/cat").syscall.return { print($arg1) } -- cgit From 5ff217f44e1e069fcfbd59c27866afef35a61c9a Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Tue, 9 Sep 2008 19:58:38 -0400 Subject: uprobes test case tweak --- testsuite/ChangeLog | 5 +++++ testsuite/systemtap.base/uprobes.exp | 8 ++++++-- testsuite/systemtap.base/uprobes.stp | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 045772a3..14d20744 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-09-09 Frank Ch. Eigler + + * systemtap.base/uprobes.*: Tweak regexps for read-only src tree + tolerance. + 2008-09-06 Frank Ch. Eigler * systemtap.base/cmd_parse.exp: Adapt to sh-c-less "stap -c" diff --git a/testsuite/systemtap.base/uprobes.exp b/testsuite/systemtap.base/uprobes.exp index a0ae3e76..8fbe6da6 100644 --- a/testsuite/systemtap.base/uprobes.exp +++ b/testsuite/systemtap.base/uprobes.exp @@ -26,8 +26,12 @@ spawn sudo stap -v $srcdir/$subdir/uprobes.stp -c "./jennie 1 2 3 4" set ok 0 expect { -re {^Pass[^\r\n]*\r\n} { exp_continue } - -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*call[^\r\n]*\r\n} { incr ok; exp_continue } - -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*return[^\r\n]*\r\n} { incr ok; exp_continue } + -re {^Warning[^\r\n]*\r\n} { exp_continue } + -re {^Disabling[^\r\n]*\r\n} { exp_continue } + -re {^Uprobes[^\r\n]*\r\n} { exp_continue } + -re {^Cache[^\r\n]*\r\n} { exp_continue } + -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*call\r\n} { incr ok; exp_continue } + -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*return\r\n} { incr ok; exp_continue } -timeout 30 timeout { } eof { } diff --git a/testsuite/systemtap.base/uprobes.stp b/testsuite/systemtap.base/uprobes.stp index d7efb586..8e7dbe9d 100755 --- a/testsuite/systemtap.base/uprobes.stp +++ b/testsuite/systemtap.base/uprobes.stp @@ -1,3 +1,3 @@ #! stap -p4 -probe process("./jennie").function("main").call { log(pp()." "/*.$$parms*/) } -probe process("./jennie").function("main").return { log(pp()." "/*.$$return*/) } +probe process("./jennie").function("main").call { log(pp()/*." ".$$parms*/) } +probe process("./jennie").function("main").return { log(pp()/*." ".$$return*/) } -- cgit From 63265337e2b74c4a34fb9b4d67d0a695c88e7d5e Mon Sep 17 00:00:00 2001 From: ddomingo Date: Wed, 10 Sep 2008 16:25:23 +1000 Subject: added new content for Understanding, events --- doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml | 3 +- .../en-US/Introduction.xml | 11 ++- doc/SystemTap_Beginners_Guide/en-US/Scripts.xml | 106 +++++++++++++++++++-- 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml b/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml index 0058f768..09530ccc 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml @@ -5,10 +5,9 @@ SystemTap Beginners Guide For use with Red Hat Enterprise Linux 5 - 0.1 1.0 Red Hat Enterprise Linux - 5 + 5.3 1 This guide provides basic instructions on how to use SystemTap to monitor different subsystems of &PRODUCT; in finer detail. The SystemTap Beginners Guide is recommended for users who have taken RHCT or have a similar level of expertise in &PRODUCT;. diff --git a/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml b/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml index f60ab2f3..6f1b2a0a 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml @@ -19,13 +19,13 @@ -->
Goals - The goal of SystemTap is to provide infrastructure to monitor the running Linux kernel for detailed analysis. This can assist in identifying the underlying cause of a performance or functional problem. + SystemTap provides the infrastructure to monitor the running Linux kernel for detailed analysis. This can assist in identifying the underlying cause of a performance or functional problem. - Without SystemTap, monitoring the activity of a running kernel would require a tedious instrument, recompile, install, and reboot sequence. SystemTap is designed to eliminate this, allowing you to gather the same information by simply running its suite of tools against specific tapsets or SystemTap scripts. + Without SystemTap, monitoring the activity of a running kernel would require a tedious instrument, recompile, install, and reboot sequence. SystemTap is designed to eliminate this, allowing users to gather the same information by simply running its suite of tools against specific tapsets or SystemTap scripts. However, SystemTap was initially designed for users with intermediate to advanced knowledge of the kernel. This could present a steep learning curve for administrators or developers whose knowledge of the Linux kernel is little to none. - In line with that, the main goal of the SystemTap Beginner's Guide is two-fold: + In line with that, the main goals of the SystemTap Beginner's Guide are as follows: To introduce users to SystemTap, familiarize them with its architecture, and provide setup instructions for all kernel types. @@ -34,15 +34,16 @@ above, Short description on the underlying goals of SystemTap_Beginners_Guide, what we want to teach users. -
+ +
SystemTap Versus Other Monitoring Tools diff --git a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml index abb087bc..24ab8a83 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml @@ -6,7 +6,7 @@ SystemTap Scripts - For the most part, SystemTap scripts are the foundation of each SystemTap session. The SystemTap scripts you use or write yourself instruct SystemTap on what type of information to trap, and what to do once that information is trapped. + For the most part, SystemTap scripts are the foundation of each SystemTap session. SystemTap scripts instruct SystemTap on what type of information to trap, and what to do once that information is trapped. @@ -15,7 +15,7 @@ Note - An event and its corresponding handler is collectively called a probe. A SystemTap script can have multiple probes, in the same manner that each event can have multiple corresponding handlers. + An event and its corresponding handler is collectively called a probe. A SystemTap script can have multiple probes. @@ -26,13 +26,105 @@ SystemTap scripts go one step further by allowing you more flexibility with regard to handlers. Events serve as the triggers for handlers to run; handlers can be specified to trap specified data and print it in a certain manner. + + Format + + SystemTap scripts use the file extension .stp, and are written in the following format: + + + +probe [event], +[another event] + +{ + [handler] + + exit() +} + + The exit() condition is optional, but it is recommended since it safely terminates the session once the script successfully traps the required information. + + Important + + is designed to introduce readers to the basics of SystemTap scripts. To understand SystemTap scripts better, it is advisable that you refer to ; each section therein provides a detailed explanation of the script, its events, handlers, and expected output. + + +
+ Events + + + SystemTap supports multiple events per probe; as shown in , multiple events are delimited by a comma (,). Sample [event]s include: + + + + + begin + + The startup of a SystemTap session; i.e. as soon as the SystemTap script is run. + + + + + end + + The end of a SystemTap session. + + + + + kernel.function("[function]") + + The entry to the kernel function function. For example, kernel.function("sys_open") refers to the "event" that the kernel function sys_open is used. To specify the return of the kernel function sys_open, append the return string to the event statement; i.e. kernel.function("sys_open").return. + + When defining functions, you can use asterisk (*) for wildcards. You can also trace the entry/exit of a function in a kernel source file. Consider the following example: +Wildcards and Kernel Source Files in an Event + +probe kernel.function("*@net/socket.c") { } +probe kernel.function("*@net/socket.c").return { } + + + +In the previous example, the first probe's event specifies the entry of ALL functions in the kernel source file net/socket.c. The second probe specifies the exit of all those functions. Note that in this example, no handler was specified; as such, no information will be displayed. + + + + + syscall.[system_call] + + The entry to the system call [system_call]. Similar to kerne.function, appending a return to the statement specifies the exit of the system call. For example, to specify the entry of the system call close, use syscall.close.return. + + To identify what system calls are made by a specific program/command, use strace command. + + + + + + + +
+ +
+ Handlers + + + SystemTap supports a wide variety of functions that can trap data when triggered by events. One way to display these functions is to use the print() + + + + -
- Format - - SystemTap scripts use the following format: -