For helping diagnose crashes that may occur during a testsuite,
set $SYSTEMTAP_SYNC, which is handled by staprun, just before it
does the module-insertion. This will make tests slower, sorry.
Josh Stone [Mon, 24 Sep 2012 23:15:55 +0000 (16:15 -0700)]
stapdyn: Enable end/error probes
The dyninst exit hook runs too late for us to still call anything in the
mutatee, so the systemtap_module_exit() call which should run all of the
end/error probes wasn't happening.
Now we use a destructor function in the mutatee, so our exit path always
runs after main() returns or after an exit() call. Functions like
_exit() are still problematic though.
This now also makes a distinction between initializing process-local vs.
session resources, so we are more ready for operating with multiple
mutatees at once. See dyninst/runtime.h for design comments.
David Smith [Fri, 21 Sep 2012 20:13:28 +0000 (15:13 -0500)]
(PR14571 partial fix) For dyninst, use TLS for map and stat data.
* runtime/dyninst/tls_data.c: New file.
* runtime/stat.c (struct _Stat): Add a tls_data_container_t structure.
(_stp_stat_tls_object_init): New function.
(_stp_stat_tls_object_free): Ditto.
(_stp_stat_init): Instead of directly allocating percpu data, for
dyninst set up tls data to be created when accessed by calling
_stp_tls_data_container_init().
(_stp_stat_del): For dyninst, call _stp_tls_data_container_cleanup() to
remove all the tls data.
(_stp_stat_add): For dyninst, get the proper tls stat object.
(_stp_stat_get_cpu): Deleted unused function.
(_stp_stat_get): For dyninst, get the proper tls stat objects.
(_stp_stat_clear): For dyninst, clear the stat in each thread's tls data.
* runtime/stat.h (struct stat_data): Add a tls_data_object_t structure.
* runtime/map.c (_stp_map_tls_object_init): New function.
(_stp_map_tls_object_free): Ditto.
(_stp_pmap_new): Instead of directly allocating percpu data, for dyninst
set up tls data to be created when accessed by calling
_stp_tls_data_container_init().
(_stp_pmap_clear): For dyninst, clear the map in each thread's tls data.
(_stp_pmap_del): For dyninst, call _stp_tls_data_container_cleanup() to
remove all the tls data.
(_stp_pmap_agg): Add dyninst support.
* runtime/map.h (struct map_root): Add a tls_data_object_t structure.
(struct pmap): Add a tls_data_container_t structure.
* runtime/map-stat.c (_stp_hstat_tls_object_init): New function.
(_stp_pmap_new_hstat_linear): For dyninst, override the standard tls
data object init function with _stp_hstat_tls_object_init(), which knows
how to handle hstats.
(_stp_pmap_new_hstat_log): Ditto.
* runtime/pmap-gen.c (_stp_pmap_tls_object_init): New function.
(_stp_pmap_new): For dyninst, override the standard tls
data object init function with _stp_pmap_tls_object_init(), which knows
how to handle pmaps.
(_stp_pmap_set): For dyninst, get the proper tls pmap object.
(_stp_pmap_add): Ditto.
(_stp_pmap_get_cpu): Ditto.
(_stp_pmap_get): Ditto.
(_stp_pmap_del): Ditto.
* runtime/dyninst/linux_defs.h: Added container_of(), list_entry(),
list_for_each_entry(), and list_for_each_entry_safe().
Mark Wielaard [Wed, 19 Sep 2012 08:33:29 +0000 (10:33 +0200)]
parse.cxx swallow tokens we are definitely not using.
The tokens produced by expect_* () were immediately dropped on the floor
after inspection. And a lot of places in the parser called next () just
to get passed the current token without using it. Those tokens could
immediately be cleaned up saving ~3MB of "lost memory".
valgrind stap -v -k -p4 -e 'probe begin { log("Hello, World!"); exit(); }'
Before:
==12545== definitely lost: 2,470,128 bytes in 51,408 blocks
==12545== indirectly lost: 14,180,805 bytes in 319,624 blocks
After:
==14782== definitely lost: 18,856 bytes in 220 blocks
==14782== indirectly lost: 12,432,436 bytes in 264,176 blocks
Implements a cached unwinder, allowing most backtrace tapset functions
to be implemented in terms of stack() without loss of performance.
stack() calls can be made repeatedly and in any order, and they will
use the results of a single unwind. (Works only with the DWARF
unwinder).
_stp_stack_kernel_print et. al. retain their prior behaviour,
including a number of fallbacks not available to the incremental
unwind. These fallbacks only emit backtrace strings, which can be
tokenized on the tapset end as a last resort.
* runtime/unwind/unwind.h -- define struct unwind_cache to store PCs
obtained from unwinder.
* runtime/common_probe_context.h -- include two sets of unwinder
context and cache, one for user side, one for kernel.
* tapsets.cxx -- probe prologue includes a small thing to mark
the unwind caches as being in an uninitialized state.
* runtime/stack.c -- incremental unwinder implementation.
* runtime/stack-dwarf.c -- deleted. Code moved to stack.c since
this is now the preferred unwind method.
* tapset/linux/[u]context-symbols.stp -- change stack(), ustack()
to directly call incremental unwinder.
David Smith [Fri, 14 Sep 2012 15:13:19 +0000 (10:13 -0500)]
(PR14571 partial fix) For dyninst, use TLS for the context structure.
* translate.cxx (c_unparser::emit_common_header): Update to use thread
local storage in dyninst mode for context structure.
(c_unparser::emit_global_param): Since there are no module parameters
with dyninst, don't bother emitting code.
(c_unparser::emit_module_init): Don't bother emitting kernel-only code
in dyninst mode.
* runtime/vsprintf.c (_stp_vsprint_memory): For dyninst, use thread local
storage to get correct context structure.
* tapsets.cxx (common_probe_entryfn_prologue): Take a 'systemtap_sesion'
argument instead of a 'translator_output' argument. This allows access
to the s.is_usermode() function (so we can avoid outputting kernel code
when using dyninst).
(dwarf_derived_probe_group::emit_module_decls): Update
common_probe_entryfn_prologue() call.
(uprobe_derived_probe_group::emit_module_utrace_decls): Ditto.
(uprobe_derived_probe_group::emit_module_inode_decls): Ditto.
(uprobe_derived_probe_group::emit_module_dyninst_decls): Ditto.
(kprobe_derived_probe_group::emit_module_decls): Ditto.
(hwbkpt_derived_probe_group::emit_module_decls): Ditto.
(tracepoint_derived_probe_group::emit_module_decls): Ditto.
* tapset-been.cxx (be_derived_probe_group::emit_module_decls): Ditto.
* tapset-itrace.cxx (itrace_derived_probe_group::emit_module_decls): Ditto.
* tapset-mark.cxx (mark_derived_probe_group::emit_module_decls): Ditto.
* tapset-netfilter.cxx (netfilter_derived_probe_group::emit_module_decls):
Ditto.
* tapset-perfmon.cxx (perf_derived_probe_group::emit_module_decls): Ditto.
* tapset-procfs.cxx (procfs_derived_probe_group::emit_module_decls):
Ditto.
* tapset-timers.cxx (profile_derived_probe_group::emit_module_decls):
Ditto.
* tapset-utrace.cxx (utrace_derived_probe_group::emit_module_decls):
Ditto.
* tapsets.h: Updated common_probe_entryfn_prologue() declaration.
Mark Wielaard [Mon, 10 Sep 2012 08:29:15 +0000 (10:29 +0200)]
dflpp.cxx (find_variable_and_frame_base): Remove extra bracket in error.
Before:
semantic error: unable to find local 'task', dieoffset 0x111604 in nfs,
near pc 0x78863 in nfs_read_done fs/nfs/proc.c ( (alternatives: $data):
identifier '$task' at [...]
After:
semantic error: unable to find local 'task', dieoffset 0x111604 in nfs,
near pc 0x78863 in nfs_read_done fs/nfs/proc.c (alternatives: $data):
identifier '$task' at [...]
David Smith [Fri, 7 Sep 2012 19:57:18 +0000 (14:57 -0500)]
(PR14488 partial fix) Make memory reading more robust.
* runtime/dyninst/runtime.h (assert_is_myproc): New dummy macro.
(stp_dummy_init): Opens the /proc/self/mem file.
(stp_dummy_exit): Close the file.
* runtime/dyninst/linux_defs.h (user_mode): New dummy macro.
(__copy_from_user): Rewrote to read memory from /proc/self/mem, to be
able to catch errors.
* runtime/stp_string.h (__stp_get_user): Always use __get_user(), no
matter what arch we're on in dyninst mode.
* tapset/uconversions.stp: Moved from tapset/linux/uconversions.stp, since
the dyninst runtime can use the functions also.
Mark Wielaard [Wed, 5 Sep 2012 19:09:43 +0000 (21:09 +0200)]
PR14546 Only copy registers of initial state.
The DWARF unwinder was copying too much information into the cie_regs
state possibly overwriting ~18 bytes after the unwind_context. Just copy
the registers.
Serguei Makarov [Mon, 27 Aug 2012 18:13:39 +0000 (14:13 -0400)]
PR14524: support old embedded-locals notation on a per-function basis
Adding the pragma /* unmangled */ to an embedded-C function now enables
the use of the pre-1.8 local names, i.e. THIS->n instead of STAP_ARG_n.
This aids migration of pre-1.8 scripts and tapsets by allowing mixing
two kinds of embedded functions (pre- and post-1.8) in the same code.
Josh Stone [Wed, 22 Aug 2012 22:41:49 +0000 (15:41 -0700)]
langref: Mention 'delete' in the Arrays and Statistics sections
When reading just the sections on Arrays and Statistics, it was not
apparent that the 'delete' statement is applicable to each. These
sections now have a mention and back-reference to the delete statement.
Josh Stone [Tue, 21 Aug 2012 18:46:30 +0000 (11:46 -0700)]
runtime: Use typedef-typeof for safer function pointers
We use kallsyms_lookup_name to access several functions that are
publicly declared but not exported. We were manually recreating the
call signatures for function pointers though, which is begging for
trouble. This patch updates all those typedefs to use typeof on the
original function declaration, so we hopefully get compile-time breakage
if the call signature ever changes on us.
David Smith [Fri, 17 Aug 2012 18:31:24 +0000 (13:31 -0500)]
Fixed PR14463 by changing error handling of utrace_control().
* runtime/stp_utrace.c (utrace_barrier): Add a 'might_sleep()' call since
it calls schedule_timeout_interruptible(), which sleeps.
* runtime/linux/task_finder2.c (__stp_utrace_attach): Ignore
EINPROGRESS errors from utrace_control() when passed UTRACE_STOP, since
that just means the task hasn't stopped yet.
* runtime/linux/task_finder.c (__stp_utrace_attach_flags): Ditto.
Chris Meek [Wed, 15 Aug 2012 19:44:55 +0000 (15:44 -0400)]
PR11659: Hook into the panic_notifier_list
This feature lets stap dump the trace buffers to the serial console on a
kernel panic. The basic functionality is there, but it could use some
tweeking including adding a summary report at the end of the dump.
Currently it only works for the relay buffer V2.
Serguei Makarov [Wed, 15 Aug 2012 15:31:59 +0000 (11:31 -0400)]
PR14313: rewrite alias suffix example in langref.tex.
The rewrite avoids possible confusion due to the fact that there is
a syscall.read.return alias defined in the tapset (which changes how
the suffix is resolved in the real code vs. in the example with
only one custom syscall.read alias).
David Smith [Wed, 15 Aug 2012 15:11:12 +0000 (10:11 -0500)]
Fix PR14026 by updating the IP before calling the inode-uprobe handler.
* tapsets.cxx (uprobe_derived_probe_group::emit_module_inode_decls): Fix
the IP before calling the real probe handler using
uprobe_get_swbp_addr().
* buildrun.cxx (compile_pass): Added
STAPCONF_UPROBE_GET_SWBP_ADDR_EXPORTED autoconf.
* runtime/linux/runtime.h: Add kallsyms_uprobe_get_swbp_addr declaration.
* runtime/linux/uprobes-inode.c: Ditto.
* runtime/transport/transport.c (_stp_transport_init): If
STAPCONF_UPROBE_GET_SWBP_ADDR_EXPORTED isn't defined, use
kallsyms_lookup_name() to find the address of 'uprbe_get_swbp_addr'.
David Smith [Tue, 14 Aug 2012 15:38:14 +0000 (10:38 -0500)]
Improve PR14463 by avoiding sleeping in the clone handler.
* runtime/linux/task_finder2.c (__stp_tf_alloc_task_work): Change
parameter to a void pointer.
(__stp_tf_clone_worker): New function.
(__stp_utrace_task_finder_report_clone): Uses stp_task_work_add() to
call __stp_tf_clone_worker() when we can safely sleep.
Josh Stone [Tue, 14 Aug 2012 01:32:40 +0000 (18:32 -0700)]
PR14396: Truncate UTF strings silently
The UTF-16 and UTF-32 conversion functions were correctly refusing to
write a partial UTF-8 sequence into the buffer, but they were treating
that case as an error. It should just silently stop processing, so the
result is truncated just as any other string concatenation does.
* tapset/linux/conversions.stp (kernel_string_utf32): Treat only rc<0
from _stp_convert_utf32 as an error; rc==0 is truncation.
(kernel_string_utf16): Ditto.
* tapset/linux/uconversions.stp (user_string_utf32): Ditto.
(user_string_utf16): Ditto.
* testsuite/systemtap.base/utf_kernel_trunc.*: Test a broad range of
truncation points within kernel UTF strings.
* testsuite/systemtap.base/utf_user_trunc.*: Same test for userspace.
(The duplication is unfortunate, but it's not too crazy.)
Josh Stone [Mon, 13 Aug 2012 22:45:23 +0000 (15:45 -0700)]
Don't report non-git if we have an extra-version
When we're not building from git, but we do have --with-extra-version,
just let that suffice in our version strings. But when we do have a git
repo, still print the fullest information possible.
* version.h: Define STAP_EXTENDED_VERSION with this scheme.
* session.cxx, stapdyn/stapdyn.cxx, staprun/common.c: Use it.
Frank Ch. Eigler [Mon, 13 Aug 2012 00:05:46 +0000 (20:05 -0400)]
PR14460 try 1
Switch to tcl's [socket HOST PORT] facilities as a netcat client
substitute. Except tcl 8.5* doesn't speak ipv6 jive. Also, switch to
port 8079 for tests, expecting to conflict less with normal ongoings
than good old 8080.
Josh Stone [Sat, 11 Aug 2012 00:46:13 +0000 (17:46 -0700)]
PR14396: Add pretty-printing support for UTF
* dwarf_wrappers.h: Define DW_ATE_UTF if elfutils < 0.155.
* tapsets.cxx (dwarf_pretty_print::recurse_base): Print UTF with %#c
too. This will generally only work with the ASCII subset for now...
(dwarf_pretty_print::print_chars): Match strings by char/UTF encoding
types, rather than by type name, and use the byte_size to select the
correct string dereferencing function.
* testsuite/systemtap.base/utf_pretty.*: Test it!
Josh Stone [Fri, 10 Aug 2012 22:15:29 +0000 (15:15 -0700)]
PR14396: Add UTF-16/32 conversion functions
* runtime/stp_string.c (_stp_convert_utf32): New, write the given
UTF-32 code point as UTF-8 in the given buffer.
* tapset/linux/conversions.stp (kernel_string_utf32): New, read and
convert a UTF-32 string from kernel memory.
(kernel_string_utf16): Same for UTF-16, handling surrogate pairs.
(kernel_string2_utf32, kernel_string2_utf16): Same w/ custom error.
* tapset/linux/uconversions.stp: All of the above for user memory.
* testsuite/buildok/conversions*.stp: Add build tests.
* testsuite/systemtap.base/utf_*: New runtime tests.
Josh Stone [Fri, 10 Aug 2012 21:50:41 +0000 (14:50 -0700)]
loc2c-runtime.h: Add uread() and uwrite()
These are the userspace equivalents to kread() and kwrite().
For the (unused) STAPCONF_PROBE_KERNEL case, just define them as direct
equivalents. Also add in missing kderef and store_kderef the same way.
For the architecture-implemented case, they are nearly identical to
kread and kwrite, just s/kderef/uderef/. So to avoid duplication, I've
added in a layer of macro indirection to pass in the appropriate deref
function. (Nevermind that the [ku]derefs are often identical -- oh,
what a tangled web we weave...)
David Smith [Fri, 10 Aug 2012 13:39:51 +0000 (08:39 -0500)]
Improve task_finder/task_finder2 error handling.
* runtime/linux/task_finder.c (stap_start_task_finder): When we ignore
EPERM or ENOENT errors, be sure to not accidently return the ignored
error.
* runtime/linux/task_finder2.c (stap_start_task_finder): Ditto.
David Smith [Tue, 7 Aug 2012 22:32:01 +0000 (17:32 -0500)]
Fix problems with varargs macros in dyninst/io.c.
* runtime/dyninst/io.c: Convert _stp_warn(), _stp_error(),
_stp_softerror(), and _stp_dbug() from varargs macros into varargs
functions so that calling _stp_warn() (for example) with just a format
argument works correctly.