]> sourceware.org Git - systemtap.git/commitdiff
Fix @cast translation for stapbpf tracepoint probes
authorAaron Merey <amerey@redhat.com>
Tue, 30 Jan 2018 22:55:22 +0000 (17:55 -0500)
committerAaron Merey <amerey@redhat.com>
Tue, 30 Jan 2018 23:19:02 +0000 (18:19 -0500)
* tapsets.cxx (synthetic_embedded_deref_call): remove an unnecessary
  condition from an if statement.

  (dwarf_cast_query::handle_query_module): if the current expression
  includes a bpf_context_vardecl, call location_context::adapt_pointer_to_bpf

  (tracepoint_var_expanding_visitor::visit_target_symbol_arg): use a
  bpf_context_vardecl even if the arg has no components.

* bpf_tests/cast_op_tracepoint.stp: tests whether a tracepoint probe
  containing @cast compiles and runs.

* bpf_tests/tracepoint1.stp: removed unused globals.

tapsets.cxx
testsuite/systemtap.bpf/bpf_tests/cast_op_tracepoint.stp [new file with mode: 0644]
testsuite/systemtap.bpf/bpf_tests/tracepoint1.stp

index ed55af4cdef156fcfdba513dd67a351485321c37..28296b14fea3484ce6c339cf3546f86d45224b68 100644 (file)
@@ -3723,7 +3723,7 @@ synthetic_embedded_deref_call(dwflpp& dw, location_context &ctx,
 
   // If this code snippet uses a precomputed pointer,
   // pass that as the first argument.
-  if (pointer && dw.sess.runtime_mode != systemtap_session::bpf_runtime)
+  if (pointer)
     {
       assert(ctx.pointer);
       fdecl->formal_args.push_back(ctx.pointer);
@@ -4733,6 +4733,13 @@ dwarf_cast_query::handle_query_module()
   location_context ctx(&e, e.operand);
   ctx.userspace_p = userspace_p;
 
+  // ctx may require extra information for --runtime=bpf
+  symbol *s;
+  bpf_context_vardecl *v;
+  if ((s = dynamic_cast<symbol *>(e.operand))
+      && (v = dynamic_cast<bpf_context_vardecl *>(s->referent)))
+    ctx.adapt_pointer_to_bpf(v->size, v->offset, v->is_signed);
+
   Dwarf_Die endtype;
   bool ok = false;
 
@@ -10721,6 +10728,17 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
       sym->tok = e->tok;
       sym->name = "__tracepoint_arg_" + arg->name;
       sym->type_details = make_shared<exp_type_dwarf>(&dw, &arg->type_die, false, false);
+
+      if (sess.runtime_mode == systemtap_session::bpf_runtime)
+        {
+          bpf_context_vardecl *v = new bpf_context_vardecl;
+
+          v->size = arg->size;
+          v->offset = arg->offset;
+          v->is_signed = arg->is_signed;
+          sym->referent = v;
+        }
+
       provide (sym);
     }
   else
diff --git a/testsuite/systemtap.bpf/bpf_tests/cast_op_tracepoint.stp b/testsuite/systemtap.bpf/bpf_tests/cast_op_tracepoint.stp
new file mode 100644 (file)
index 0000000..604b7bb
--- /dev/null
@@ -0,0 +1,16 @@
+// Test nested @casts. If this script compiles and runs then the test passes.
+probe begin {
+       printf("BEGIN\n")
+}
+
+probe kernel.trace("timer_start") {
+       printf("%d\n", @cast(@cast($timer, "timer_list", "kernel<linux/timer.h>")->function, "u_int8_t", "kernel<linux/types.h>")[2])
+}
+
+probe timer.s(1) {
+       exit()
+}
+
+probe end {
+       printf("END PASS\n")
+}
index 1c92df47db24f61d1b7511b314f10c929440a6cd..12d76bdb7c2a32b5c0e4b1234556b85614fde7fe 100644 (file)
@@ -1,4 +1,4 @@
-global flag, y, z, x
+global flag
 
 probe begin {
        printf("BEGIN\n")
This page took 0.044986 seconds and 5 git commands to generate.