From: Aaron Merey Date: Tue, 30 Jan 2018 22:55:22 +0000 (-0500) Subject: Fix @cast translation for stapbpf tracepoint probes X-Git-Tag: release-3.3~136 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=66373b2e2aaa6f45ea8e7fbbb742b801aa892369;p=systemtap.git Fix @cast translation for stapbpf tracepoint probes * 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. --- diff --git a/tapsets.cxx b/tapsets.cxx index ed55af4cd..28296b14f 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -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(e.operand)) + && (v = dynamic_cast(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(&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 index 000000000..604b7bbde --- /dev/null +++ b/testsuite/systemtap.bpf/bpf_tests/cast_op_tracepoint.stp @@ -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")->function, "u_int8_t", "kernel")[2]) +} + +probe timer.s(1) { + exit() +} + +probe end { + printf("END PASS\n") +} diff --git a/testsuite/systemtap.bpf/bpf_tests/tracepoint1.stp b/testsuite/systemtap.bpf/bpf_tests/tracepoint1.stp index 1c92df47d..12d76bdb7 100644 --- a/testsuite/systemtap.bpf/bpf_tests/tracepoint1.stp +++ b/testsuite/systemtap.bpf/bpf_tests/tracepoint1.stp @@ -1,4 +1,4 @@ -global flag, y, z, x +global flag probe begin { printf("BEGIN\n")