From 3d49c6154591958c1e12f70aa5b89de70e8fb988 Mon Sep 17 00:00:00 2001 From: fche Date: Thu, 28 Jul 2005 18:42:58 +0000 Subject: 2005-07-28 Frank Ch. Eigler * translate.cxx: Add "pt_regs*" field to context. * tapsets.cxx (*): Correct kprobes API interface. * testsuite/buildok/three.stp: New test, copied from semok. * Makefile.am (install-data-local): Also install runtime/relayfs, so scripts can build against headers located thereunder. * Makefile.in: Regenerated. --- ChangeLog | 9 +++++++++ Makefile.am | 3 +++ Makefile.in | 3 +++ tapsets.cxx | 49 ++++++++++++++++++++++----------------------- testsuite/buildok/three.stp | 25 +++++++++++++++++++++++ translate.cxx | 1 + 6 files changed, 65 insertions(+), 25 deletions(-) create mode 100755 testsuite/buildok/three.stp diff --git a/ChangeLog b/ChangeLog index 84085e26..a8d5cb0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-07-28 Frank Ch. Eigler + + * translate.cxx: Add "pt_regs*" field to context. + * tapsets.cxx (*): Correct kprobes API interface. + * testsuite/buildok/three.stp: New test, copied from semok. + * Makefile.am (install-data-local): Also install runtime/relayfs, + so scripts can build against headers located thereunder. + * Makefile.in: Regenerated. + 2005-07-28 Frank Ch. Eigler translator/1120 diff --git a/Makefile.am b/Makefile.am index 327bdbaf..0da0a1bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,9 @@ install-data-local: tar -f - -c --exclude=CVS --exclude='*~' --exclude='.#*' \ -C $(srcdir)/runtime transport \ | (cd $(DESTDIR)$(pkgdatadir)/runtime && tar xpf -) + tar -f - -c --exclude=CVS --exclude='*~' --exclude='.#*' \ + -C $(srcdir)/runtime relayfs \ + | (cd $(DESTDIR)$(pkgdatadir)/runtime && tar xpf -) -mkdir $(DESTDIR)$(pkgdatadir)/tapset (cd $(srcdir)/tapset ; find . -name '*.stp' | cpio -pdmv $(DESTDIR)$(pkgdatadir)/tapset) diff --git a/Makefile.in b/Makefile.in index 53ec3b03..7e4d7c39 100644 --- a/Makefile.in +++ b/Makefile.in @@ -862,6 +862,9 @@ install-data-local: tar -f - -c --exclude=CVS --exclude='*~' --exclude='.#*' \ -C $(srcdir)/runtime transport \ | (cd $(DESTDIR)$(pkgdatadir)/runtime && tar xpf -) + tar -f - -c --exclude=CVS --exclude='*~' --exclude='.#*' \ + -C $(srcdir)/runtime relayfs \ + | (cd $(DESTDIR)$(pkgdatadir)/runtime && tar xpf -) -mkdir $(DESTDIR)$(pkgdatadir)/tapset (cd $(srcdir)/tapset ; find . -name '*.stp' | cpio -pdmv $(DESTDIR)$(pkgdatadir)/tapset) diff --git a/tapsets.cxx b/tapsets.cxx index 040c8424..bbe0481c 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -116,15 +116,16 @@ be_derived_probe::emit_probe_entries (translator_output* o, unsigned j) o->newline() << "c->errorcount = 0;"; o->newline() << "c->actioncount = 0;"; o->newline() << "c->nesting = 0;"; + o->newline() << "c->regs = 0;"; // NB: locals are initialized by probe function itself o->newline() << "probe_" << j << " (c);"; // see translate.cxx: visit_functioncall and elsewhere to see all the // possible context indications that a probe exited prematurely - o->newline() << "if (c->errorcount || c->actioncount > MAXACTION"; - o->newline(1) << "|| c->nesting+2 >= MAXNESTING) {"; - o->newline() << "printk (KERN_ERR \"probe execution failure (e%d,n%d,a%d)\","; + o->newline() << "if (c->errorcount || c->actioncount > MAXACTION" + << " || c->nesting+2 >= MAXNESTING) {"; + o->newline(1) << "printk (KERN_ERR \"probe execution failure (e%d,n%d,a%d)\","; o->newline(1) << "c->errorcount, c->nesting, c->actioncount);"; o->newline(-1) << "atomic_set (& session_state, STAP_SESSION_ERROR);"; o->newline(-1) << "}"; @@ -1069,8 +1070,8 @@ dwarf_derived_probe::emit_registrations (translator_output* o, unsigned probenum if (module_name.empty()) { o->newline() << probe_entry_struct_kprobe_name(probenum) - << ".addr = 0x" << hex << addr << ";"; - o->newline() << "register_probe (&" + << ".addr = (void *) 0x" << hex << addr << ";"; + o->newline() << "rc = register_kprobe (&" << probe_entry_struct_kprobe_name(probenum) << ");"; } @@ -1087,8 +1088,8 @@ dwarf_derived_probe::emit_registrations (translator_output* o, unsigned probenum o->newline() << "{"; o->indent(1); o->newline() << probe_entry_struct_kprobe_name(probenum) - << ".addr = mod->module_core + 0x" << hex << addr << ";"; - o->newline() << "register_probe (&" + << ".addr = (void *) (mod->module_core + 0x" << hex << addr << ");"; + o->newline() << "rc = register_kprobe (&" << probe_entry_struct_kprobe_name(probenum) << ");"; o->indent(-1); @@ -1102,7 +1103,7 @@ void dwarf_derived_probe::emit_deregistrations (translator_output* o, unsigned probenum) { o->newline(); - o->newline() << "deregister_probe (&" + o->newline() << "unregister_kprobe (& " << probe_entry_struct_kprobe_name(probenum) << ");"; } @@ -1114,22 +1115,20 @@ dwarf_derived_probe::emit_probe_entries (translator_output* o, unsigned probenum // Construct a single entry function, and a struct kprobe pointing into // the entry function. The entry function will call the probe function. o->newline(); - o->newline() << "static void "; - o->newline() << probe_entry_function_name(probenum) << " (void);"; - o->newline() << "void "; - o->newline() << probe_entry_function_name(probenum) << " ()"; - o->newline() << "{"; - o->newline(1) << "struct context* c = & contexts [smp_processor_id()];"; + o->newline() << "static int "; + o->newline() << probe_entry_function_name(probenum) + << " (struct kprobe *_ignored, struct pt_regs *regs) {"; + o->newline(1) << "struct context *c = & contexts [smp_processor_id()];"; o->newline(); // A precondition for running a probe handler is that we're in RUNNING // state (not ERROR), and that no one else is already using this context. o->newline() << "if (atomic_read (&session_state) != STAP_SESSION_RUNNING)"; - o->newline(1) << "return;"; + o->newline(1) << "return 0;"; o->newline(-1) << "if (c->busy) {"; o->newline(1) << "printk (KERN_ERR \"probe reentrancy\");"; o->newline() << "atomic_set (& session_state, STAP_SESSION_ERROR);"; - o->newline() << "return;"; + o->newline() << "return 0;"; o->newline(-1) << "}"; o->newline(); @@ -1138,14 +1137,15 @@ dwarf_derived_probe::emit_probe_entries (translator_output* o, unsigned probenum o->newline() << "c->errorcount = 0;"; o->newline() << "c->actioncount = 0;"; o->newline() << "c->nesting = 0;"; + o->newline() << "c->regs = regs;"; // NB: locals are initialized by probe function itself o->newline() << "probe_" << probenum << " (c);"; // see translate.cxx: visit_functioncall and elsewhere to see all the // possible context indications that a probe exited prematurely - o->newline() << "if (c->errorcount || c->actioncount > MAXACTION"; - o->newline(1) << "|| c->nesting+2 >= MAXNESTING) {"; - o->newline() << "printk (KERN_ERR \"probe execution failure (e%d,n%d,a%d)\","; + o->newline() << "if (c->errorcount || c->actioncount > MAXACTION" + << " || c->nesting+2 >= MAXNESTING) {"; + o->newline(1) << "printk (KERN_ERR \"probe execution failure (e%d,n%d,a%d)\","; o->newline(1) << "c->errorcount, c->nesting, c->actioncount);"; o->newline(-1) << "atomic_set (& session_state, STAP_SESSION_ERROR);"; o->newline(-1) << "}"; @@ -1153,17 +1153,16 @@ dwarf_derived_probe::emit_probe_entries (translator_output* o, unsigned probenum o->newline() << "c->busy --;"; o->newline() << "mb ();"; + o->newline() << "return 0;"; o->newline(-1) << "}" << endl; o->newline(); o->newline() << "static struct kprobe " - << probe_entry_struct_kprobe_name(probenum); - o->newline() << "{"; - o->indent(1); - o->newline() << ".addr = 0x0, /* filled in during module init */" ; + << probe_entry_struct_kprobe_name(probenum) + << "= {"; + o->newline(1) << ".addr = 0x0, /* filled in during module init */" ; o->newline() << ".pre_handler = &" << probe_entry_function_name(probenum) << ","; - o->indent(-1); - o->newline() << "}"; + o->newline(-1) << "};"; o->newline(); } diff --git a/testsuite/buildok/three.stp b/testsuite/buildok/three.stp new file mode 100755 index 00000000..013b5ac5 --- /dev/null +++ b/testsuite/buildok/three.stp @@ -0,0 +1,25 @@ +#! stap -p4 + +# define some aliases which resolve to kernel functions + +probe pipe_read = kernel.function("pipe_read") +{ + fname = "pipe_read" + reading_from_pipe = 1 +} + +probe pipe_write = kernel.function("pipe_write") +{ + fname = "pipe_write" + reading_from_pipe = 0 +} + +# use the aliases, including variables defined in them + +probe pipe_read, pipe_write +{ + if (reading_from_pipe) + log ("reading from pipe in " . fname) + else + log ("writing to pipe in " . fname) +} diff --git a/translate.cxx b/translate.cxx index 3623799c..2667d7ab 100644 --- a/translate.cxx +++ b/translate.cxx @@ -513,6 +513,7 @@ c_unparser::emit_common_header () o->newline() << "unsigned actioncount;"; o->newline() << "unsigned errorcount;"; o->newline() << "unsigned nesting;"; + o->newline() << "struct pt_regs *regs;"; o->newline() << "union {"; o->indent(1); // XXX: this handles only scalars! -- cgit