Lukas Berk [Wed, 31 Oct 2012 14:41:47 +0000 (10:41 -0400)]
Allow spin-rawhide to be run from any directory
* scripts/spin-rawhide: replace HASH suffix with mktemp function
reposition constant/variable definitions to draw
from newly cloned systemtap.git vs pwd
make STAP_MAJOR_VERSION grep more specific
make Source grep more specific
Josh Stone [Tue, 30 Oct 2012 22:03:38 +0000 (15:03 -0700)]
PR14665: Start handling signals in stapdyn
This works somewhat to receives signals and kill the target process, but
sometimes it hangs. I think it may work better when the notification FD
is resolved.
Josh Stone [Tue, 30 Oct 2012 19:14:53 +0000 (12:14 -0700)]
stapdyn: Sketch out support for polling on Dyninst
By polling instead of waitForStatusChange, we can let signals break us
out of the run loop too. However, the notification FD currently appears
broken in Dyninst, so this is "#if 0" for now.
* util.cxx (ppoll): Move the fallback ppoll() to a general location.
* remote.cxx (ppoll): Moved ppoll() from here.
* stapdyn/mutator.cxx: Add the #if 0 stub of notification FD support.
Josh Stone [Tue, 30 Oct 2012 02:06:30 +0000 (19:06 -0700)]
stapdyn: Add some support for removing instrumentation
We'll need this for signal-handling cleanup, and for detaching from
-x PID target processes.
* stapdyn/mutatee.h (mutatee::snippets): New vector for all the handles
to code that we've added with Dyninst insertSnippet.
* stapdyn/mutatee.cxx (mutatee::instrument_dynprobe_target): Save the
insertSnippet handle in snippets.
(mutatee::remove_instrumentation): New, remove all the snippets.
(mutatee::unload_stap_dso): New placeholder for unloading our module
from the target process. Dyninst can't do this yet...
(mutatee::~mutatee): Call remove_instrumentation and unload_stap_dso.
Josh Stone [Tue, 30 Oct 2012 01:58:58 +0000 (18:58 -0700)]
stapdyn: Manage mutatee lifetimes better
It will be more convenient to manage mutatee resources if there's one
clear owner of the process, so stop allowing implicit copies.
* stapdyn/mutatee.h (mutatee::mutatee): Don't implement copy ctors.
* stapdyn/mutator.h (mutator::mutatees): Use shared_ptr for this list.
* stapdyn/mutator.cxx (mutator::create_process): Save a shared_ptr.
(mutator::run): Use pointer indirection for mutatees.
(mutator::dynamic_library_callback): Ditto.
Josh Stone [Tue, 30 Oct 2012 01:53:59 +0000 (18:53 -0700)]
stapdyn: Manage mutator lifetime better
We need to have a global record of mutators in order for dyninst
callbacks to work, since they have no context attached. But rather than
some singleton factory style, just keep a global list of all mutators
we've seen.
* stapdyn/mutator.cxx (g_mutators): New vector for all mutators.
(g_dynamic_library_callback): Iterate callbacks for all g_mutators.
(mutator::dynamic_library_callback): Do the individual work.
(mutator::mutator): Add this to g_mutators.
(mutator::~mutator): Remove this from g_mutators.
(mutator::create, mutator::g_mutator): Removed.
* stapdyn/stapdyn.cxx (main): Use mutator new and auto_ptr delete.
Frank Ch. Eigler [Mon, 29 Oct 2012 02:39:36 +0000 (22:39 -0400)]
testsuite: make stap_run[23] more verbose when failing
If a stap_run[23] test case fails, in that the actual output varies
from the expected output, all remaining actual output lines were
neither compared nor reported in systemtap.log.
* testsuite/lib/stap_run2.exp (stap_run3): In case of a line mismatch,
report any remaining actual lines.
Frank Ch. Eigler [Mon, 29 Oct 2012 00:53:11 +0000 (20:53 -0400)]
PR14781: use kmem_cache_create with unique name
* runtime/stp_utrace.c (utrace_init): Instead of using the KMEM_CACHE macro,
invoke kmem_cache_create directly, with cache names that are going to be
unique across concurrent systemtap sessions.
Frank Ch. Eigler [Mon, 29 Oct 2012 00:16:55 +0000 (20:16 -0400)]
PR14781 part 1: don't panic
* runtime/stp_utrace.stp (utrace_init): Don't SLAB_PANIC on duplicate
kmem_cache names, as is sadly likely for concurrent inode-uprobes
scripts running on CONFIG_DEBUG_VM kernels.
* runtime/linux/task_finder2.c (stap_start_task_finder): Deign to check
the utrace_init return code, and fail with a touch of grey grace.
David Smith [Tue, 23 Oct 2012 21:21:10 +0000 (16:21 -0500)]
(PR14571 partial fix) Rework dyninst stat/map data storage.
* runtime/map.c: Switched from TLS to just an array of map data for
dyninst mode. Pushed most of the kernel vs. dyninst code down to
runtime/{linux,dyninst}/map_runtime.h.
* runtime/map-stat.c (_stp_map_new_hstat_log): Ditto.
* runtime/map.h: Ditto.
* runtime/pmap-gen.c: Ditto.
* runtime/stat.c (_stp_stat_add): Switched from TLS to just an array of
stat data for dyninst mode. Pushed most of the kernel vs. dyninst code
down to runtime/{linux,dyninst}/stat_runtime.h.
* runtime/stat-common.c: Ditto.
* runtime/stat.h: Ditto.
* runtime/dyninst/map_runtime.h: New file.
* runtime/dyninst/stat_runtime.h: New file.
* runtime/linux/map_runtime.h: New file.
* runtime/linux/stat_runtime.h: New file.
* runtime/dyninst/tls_data.c: Deleted file.
Josh Stone [Mon, 22 Oct 2012 23:35:19 +0000 (16:35 -0700)]
runtime: fix timers for old kernels
This is a regression from commit 2b5ecaf, which split the hrtimer code
into the runtime. The kernel portion needs to vary the return type of
the callback function for old kernels, using int instead of the enum.
This patch defines hrtimer_return_t to abstract the difference.
Josh Stone [Mon, 22 Oct 2012 20:55:49 +0000 (13:55 -0700)]
tapset: Add the macro @choose_defined and use it
This returns the first parameter if it's @defined, otherwise it returns
the second parameter, replacing the common @defined(x)?x:y pattern.
I only updated the tapsets to use this, as I feel that's where we should
show off good code practice. There are opportunities in the testsuite
that could use it too, but it's not necessary, and probably better to
leave existing tests undisturbed when possible.
Mark Wielaard [Sun, 21 Oct 2012 23:00:40 +0000 (01:00 +0200)]
PR14742 - more complete dwz / DW_TAG_partial_unit support
Don't use DW_TAG_partial_units directly in dwflpp::iterate_over_cus
and dwarf_var_expanding_visitor::getcuscope. Descent into imported_units
in has_only_decl_members, dwflpp::iterate_over_globals,
dwflpp::iterate_over_types, dwflpp::iterate_over_labels
dwflpp::inner_die_containing_pc, dwflpp::print_locals,
dwflpp::print_members, dwflpp::find_struct_member and
dwarf_pretty_print::recurse_struct_members.
Josh Stone [Tue, 16 Oct 2012 23:11:07 +0000 (16:11 -0700)]
stapdyn: Big refactoring
The main additions are the "mutator" class working with the overall
session, and the "mutatee" class working with the individual targets.
This is a bit of code churn, with no functional change, but it should
make it easier to keep track of our current state and add new features.
Frank Ch. Eigler [Tue, 16 Oct 2012 18:43:52 +0000 (14:43 -0400)]
PR14731: fix PR12022 regression for synthetic foreach()
* elaborate.cxx (add_global_var_display): For foreach_loop created
for otherwise-unused global, initialize sort_aggr => sc_none, the
same way the parser would.
David Smith [Mon, 15 Oct 2012 21:28:28 +0000 (16:28 -0500)]
Fixed PR14701 by adding dyninst timer probe support.
* tapset-timers.cxx (hrtimer_derived_probe_group::emit_interval): Removed
function.
(hrtimer_derived_probe_group::emit_module_decls): Pushed some code down
to the runtime and added dyninst support.
(hrtimer_derived_probe_group::emit_module_init): Ditto.
(hrtimer_derived_probe_group::emit_module_exit): Ditto.
(timer_builder::build): Throw semantic errors if 'timer.jiffies' or
'timer.profile' probes are used in dyninst mode.
(register_tapset_timers): Add fake privilege for 'timer.profile' probes
when in dyninst mode (so we get a semantic error, not a privilege error).
* buildrun.cxx (compile_dyninst): Added '-lrt' for timer functions.
* testsuite/systemtap.pass1-4/buildok-dyninst.exp: Move some tests to the
kfail list.
* runtime/timer.c: New file.
* runtime/dyninst/timer.c: Ditto.
* runtime/linux/timer.c: Ditto.
Frank Ch. Eigler [Sat, 13 Oct 2012 16:13:35 +0000 (12:13 -0400)]
PR12022: support foreach sorting by user-selected aggregate operator
The syntax goes:
foreach ([x,y] in array @avg -) { }
inserting the desired sorting aggregator between the array name and
the +/- The runtime has been ready for this for a long time (see the
runtime/map.c SORT_* macros), finally time for the translator to let
users enjoy it.
Josh Stone [Fri, 12 Oct 2012 21:45:55 +0000 (14:45 -0700)]
PR14172: Fix for kernels without VM_EXECUTABLE
We were using VM_EXECUTABLE in two ways:
1) In task_finder for locating the process executable among all the
vmas. Since around 2.6.26 there is also mm->exe_file, which will serve
this purpose just fine.
2) In uprobes to avoid relocation offset for semaphores in ET_EXEC
files. This is actually incorrect, but harmless, because the callback
path for ET_EXEC targets already sets relocation=offset=0 anyway. So we
can just remove the special case for VM_EXECUTABLE altogether.
* runtime/task_finder_vma.c (stap_find_exe_file): New, locate the
process executable either by VM_EXECUTABLE or mm->exe_file.
* runtime/linux/task_finder.c (__stp_get_mm_path): Use stap_find_exe_file.
* runtime/linux/task_finder2.c (__stp_get_mm_path): Ditto.
* runtime/linux/uprobes-common.c (stap_uprobe_change_plus): Don't
special case for VM_EXECUTABLE (and add a comment why).
* runtime/linux/uprobes-inode.c (stapiu_change_plus): Ditto.
(stapiu_get_task_inode): Use stap_find_exe_file.
Frank Ch. Eigler [Fri, 12 Oct 2012 16:27:42 +0000 (12:27 -0400)]
testsuite: tweak net-sanity.exp test
It shouldn't use stap -vv, ashat creates too much noise in the .log file.
It shouldn't use 0xd34db33f as a known-bad address, because sometimes it's good.
Really good. Mmmm, tasty, BBQ goodness good. Honey, time to warm up the burners!
Frank Ch. Eigler [Fri, 12 Oct 2012 03:28:30 +0000 (23:28 -0400)]
PR14245 clean up error messages for staprun -d SOMETHING_AWFUL
jistone reported that the previously moved
"ERROR: no access to debugfs; try "chmod 0755 /sys/kernel/debug" as root"
message was appearing for erroneous staprun -d FOOBAR cases.
* ctl.c (init_ctl_channel): Print a more general error for any .ctl-file
opening failure.
Josh Stone [Thu, 11 Oct 2012 17:42:10 +0000 (10:42 -0700)]
Set staprun's verbosity one less than stap
Prior to commit e520ea8, staprun would get one -v for s.verbosity>1 and
a second -v for s.verbosity>2. That commit unbounded the number of -v
for staprun, but changed the off-by-one, and staprun and stapio are too
chatty for that.
This also now sets stapdyn verbosity the same way.
* buildrun.cxx (make_run_command): Give one less -v flag.
(make_dyninst_run_command): Set stapdyn -v flags the same way.
David Smith [Thu, 11 Oct 2012 15:55:58 +0000 (10:55 -0500)]
Fixed PR14659 so that ptrace can be used on tasks probed with systemtap.
* runtime/stp_utrace.c (utrace_set_events): No longer set
TIF_SYSCALL_TRACE on the target task.
(utrace_reset): No longer clear TIF_SYSCALL_TRACE on the target task.
* testsuite/systemtap.base/ptrace.exp: New testcase.
Frank Ch. Eigler [Wed, 10 Oct 2012 22:10:40 +0000 (18:10 -0400)]
PR14245: support /sys/kernel/debug mounted 0700
This is done by staprun passing a file descriptor for the
/sys/kernel/debug/systemtap/stap_MODULE directory from staprun
(running setuid) to stapio (running unprivileged, previously unable to
traverse to that path itself). This FD passing is done with a new
option -F<fd> for stapio (though by accident staprun also accepts (and
rejects) this option).
Since openat(2) is relatively recent, autoconf macros are used to back
down to graceful failure on older kernels, and to hide the new code.
New staprun always uses -F<fd> to stapio, even if permissions on
/sys/kernel/debug do not require it.
* staprun/common.c (relay_basedir_fd): New variable.
(parse_args): Parse new -F: option.
(usage): Document it.
* staprun/staprun.h: Corresponding changes.
* staprun/ctl.c (init_ctl_channel): Reorganize to try an incoming
relay_basedir_fd first (with a faccessat cross-user check) first.
Try to compute a relay_basedir_fd if not already set.
* staprun/mainloop.c (read_buffer_info): Note ignoring of this PR facility on
RHEL4-era old_transport.
* staprun/relayfs.c (init_relayfs): Attempt to open relay_fd[] using
relay_basedir_fd if specified.
* staprun/stapio.c: Top secret.
* staprun/staprun.c (main): Don't allow staprun itself to take -F, for it
could be misused by a very bad person (tm). However, arrange to pass
it to stapio, if we have incidentally discovered a good relay_basedir_fd.
* staprun/staprun_funcs.c (mountfs): Drop access_debugfs() check at this
point, as init_ctl_channel() will do the check later.
PR14555: handle 0 _stext relocs from userspace by kallsyms_lookup_name fallback
* runtime/transport/symbols.c (_stp_do_relocation): For an incoming
_stext=0 relocation (such as for /proc/sys/kernel/kptr_restrict = 2),
fall back to kallsyms_lookup_name.
William Cohen [Tue, 9 Oct 2012 20:30:48 +0000 (16:30 -0400)]
Make the tapcheck.sh look for all .stp files in the tapset directory
With the reorganization of the tapset directory there were some tapsets
multiple directories down. tapcheck.sh was only checking the top level
of the tapset directory. This meant that is was missing a many of the
tapsets that were in subdirectories. This change makes the results more
accurate.
Josh Stone [Tue, 9 Oct 2012 16:43:34 +0000 (09:43 -0700)]
PR14572: Set s.privilege = unprivileged for stapdyn
When running under Dyninst, we are effectively unprivileged by nature,
so setting s.privilege to reflect that helps restrict the available
probe types.
However, we still want to allow guru mode for setting target variables
and using embedded-C, so let systemtapr_:session::is_usermodea() pass.
* session.cxx (systemtap_session::parse_cmdline): For --runtime=dyninst,
set the privilege level too.
(systemtap_session::check_options): Allow -g for is_usermode().
* staptree.cxx (varuse_collecting_visitor::visit_embeddedcode): Allow
embedded-C unrestricted for is_usermode().
(varuse_collecting_visitor::visit_embedded_expr): Ditto.
commit 82523f19 changed the error-exit path of _stp_pmap_agg, but was
confused by the multiple (three!) levels of nested loops in effect at
the point of failure. While the prior "return;" skipped an overall
(newly needed) aggregate-unlock; the current "break;" skipped too
little. Switch to a proper simple goto to almost but not quite
return;.
Josh Stone [Sat, 6 Oct 2012 00:02:56 +0000 (17:02 -0700)]
stapdyn: Limit functions searches to the stap module
This is slightly more efficient because we already know which object we
expect to have the functions, so we don't need to search the whole app.
* stapdyn/stapdyn.cxx (call_inferior_function): Take the BPatch_object
in which we're searching for functions as a parameter.
(instrument_uprobe_target, instrument_uprobes): Ditto.
(dynamic_library_callback): Pass the stap dso from global.
(main): Save the stap dso into a global, and pass it as needed.
Josh Stone [Fri, 5 Oct 2012 23:27:27 +0000 (16:27 -0700)]
stapdyn: track dlopened objects for probes
* stapdyn/stapdyn.cxx (instrument_uprobe_target): New, factored out the
code to write all the probes from one target to one object.
(instrument_uprobes): Use instrument_uprobe_target for each.
(dynamic_library_callback): New, identify if a new object is a target,
and call instrument_uprobe_target if so.
(find_uprobes): Fill the vector as a parameter, and then return a
success status directly instead of floating the exception.
(main): Register the dynamic_library_callback for dlopens.
David Smith [Fri, 5 Oct 2012 17:52:43 +0000 (12:52 -0500)]
(PR14637 partial fix) Improve stapdyn locking.
* runtime/dyninst/runtime.h: Remove the 'stapdyn_big_dumb_lock' and make
preempt_disable() and preempt_enable_no_resched() do nothing for
dyninst.
* runtime/dyninst/tls_data.c: Change the mutex in tls_data_container_t to
a rwlock.
(_stp_tls_free_per_thread_ptr): Write lock the container before remove
the object from the list (and reduce the amount of time the container is
locked).
(_stp_tls_get_per_thread_ptr): Write lock the container before adding
the object from the list (and reduce the amount of time the container is
locked).
* runtime/map.c (_stp_pmap_agg): Be sure to unlock the map in error
conditions.
* runtime/pmap-gen.c (KEYSYM(_stp_pmap_get)): Be sure to unlock the
container in an error condition.
Josh Stone [Fri, 5 Oct 2012 02:04:14 +0000 (19:04 -0700)]
PR14573 (partial): Pass some registers into stapdyn
There doesn't seem to be a way to create and pass the pt_regs structure
from the Dyninst API, but we can still get most registers. This patch
adds a new enter_dyninst_uprobe_regs() to receive registers and fill
them into a pt_regs from there.
XXX Dyninst is currently limited in how many individual function
arguments it can pass, so for now I'm cutting it down to the first 8.
* runtime/dyninst/stapdyn.h: Declare enter_dyninst_uprobe_regs.
* runtime/dyninst/uprobes.c: Implement it, filling all dwarf registers
into a local struct pt_regs.
* runtime/dyninst/regs.c: Include regs.h to get SET_REG_IP.
* stapdyn/stapdyn.cxx (get_dwarf_registers): Create BPatch_snippets for
as many of the DWARF registers as possible (bug-limited to 8).
(instrument_uprobes): Look for the new entry function and use it.
Josh Stone [Thu, 4 Oct 2012 23:19:10 +0000 (16:19 -0700)]
PR14179: Split up loc2c-runtime.h for linux|dyninst
* runtime/loc2c-runtime.h: Remove deref functions and special register
handling from this shared base, and rename k_dwarf_register_N to
pt_dwarf_register_N to be more neutral.
* runtime/linux/loc2c-runtime.h: Move the deref functions and special
register handling here. Nothing new, just transplanted.
* runtime/dyninst/loc2c-runtime.h: Add deref and register functions.
* runtime/dyninst/copy.c (__copy_from_user, __copy_to_user): Move from
linux_def.h, since these are custom implementations, not kernel copies.
(_stp_strncpy_from_user, _stp_copy_from_user): New implementations.