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]

Re: conditional probes


Frank Ch. Eigler wrote:
> Hi -
> 
>> I think the problem is that from within the utrace .report_signal 
>> handler I want to call the function that corresponds to "if (condition) 
>> { ... }" which is represented as say probe_1064(struct context *), but I 
>> don't know where I would find the "struct context *" argument that the 
>> probe_1064() requires. [...]
> 
> Look at the "stap -p3" code generated from
> 
>     probe begin { println("hello") }
> or  probe kernel.function("sys_open") { println("hello") }
> or  probe process("bash").begin { println("hello") }
> 
> You'll see that context allocation is done by the systemtap-generated
> function that receives the callback from the kernel facility that
> represents the event source.  That function -- usually just one per
> derived_probe_group -- then invokes the appropriate probe handler
> function ("probe_NNNN (struct context *)") through a function pointer.

Dave,

Frank gave you a good overview, but I thought I fill in a few more
details.  If you want to specifically see how utrace probes get called,
you can look at the output of the following:

# stap -p3 -e 'probe process("/bin/bash").syscall { printf("hello\n") }'

The routine you'll want to study is 'stap_utrace_probe_syscall'.
There's a lot of code in that routine, but most of it is boilerplate.
That C routine gets output in the translator by
utrace_derived_probe_group::emit_module_decls().  For instance, here's
the code that generates 'stap_utrace_probe_syscall':

      s.op->newline() << "static u32 stap_utrace_probe_syscall(struct
utrace_attached_engine *engine, struct task_struct *tsk, struct pt_regs
*regs) {";
      s.op->indent(1);
      s.op->newline() << "struct stap_utrace_probe *p = (struct
stap_utrace_probe *)engine->data;";

      common_probe_entryfn_prologue (s.op, "STAP_SESSION_RUNNING");
      s.op->newline() << "c->probe_point = p->pp;";
      s.op->newline() << "c->regs = regs;";

      // call probe function
      s.op->newline() << "(*p->ph) (c);";
      common_probe_entryfn_epilogue (s.op);

      s.op->newline() << "return UTRACE_ACTION_RESUME;";
      s.op->newline(-1) << "}";

The utrace_derived_probe_group::emit_module_decls() function outputs all
the .report_* related functions that the utrace probes need.

-- 
David Smith
dsmith@redhat.com
Red Hat
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)


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