David Smith [Fri, 15 Nov 2013 19:52:03 +0000 (13:52 -0600)]
PR15219 partial fix. Several syscall.clock_* probes longer nest.
* tapset/linux/syscalls.stp: Add __syscall_get() macro calls to
syscall.clock_nanosleep and syscall.clock_nanosleep.return to reject
nested syscalls. Added compat_sys_clock_settime support to
syscall.clock_settime and syscall.clock_settime.return.
* tapset/linux/nd_syscalls.stp: Similar changes as above.
* tapset/linux/syscalls.stpm: New file.
* tapset/linux/aux_syscalls.stp (_stp_syscall_nr): New function.
Jonathan Lebon [Fri, 15 Nov 2013 19:35:43 +0000 (14:35 -0500)]
also suggest function aliases on unresolved dwarf probes
This patch does two things:
1. It removes sym_seen and replaces it with inlined_funcs, which only
picks up inlined functions.
2. suggest_dwarf_functions() now aggregates functions from both
inlined_funcs and the module_info symtab function cache.
The net result is that (1) we're no longer storing duplicate
information, and (2) we now also suggest function aliases (which are in
the cache).
Jonathan Lebon [Wed, 13 Nov 2013 22:34:56 +0000 (17:34 -0500)]
PR16165: extend print_format::create
In an effort to restrict token creation, we change the
print_format::create() function to accept a string to denote the type of
print statement we want, rather than always deriving it from the token's
content. This allows us to skip the creation of tokens in a few places
that synthesize print statements.
- staptree.h: update print_format::create() declaration to accept new
parameter and add new member print_format_type
- staptree.cxx: update print_format::create() and use print_format_type
in print_format::print()
- elaborate.cxx: don't create token, use new parameter instead
- tapset-mark.cxx: ditto
- tapset-utrace.cxx: ditto
- tapsets.cxx: ditto
Josh Stone [Thu, 14 Nov 2013 01:46:22 +0000 (17:46 -0800)]
testsuite: Support prelink even on NFS paths
We had an issue that prelink would fail trying to restore selinux
context if the file is on NFS, e.g. for someone working in NFS $HOME.
It turns out prelink see nfs_t on the source, but isn't allowed to set
nfs_t on the destination (even though it will already be nfs_t).
Now we have a [prelink] proc for test to run prelink though a mktemp
file. The source is copied to tmp, prelinked, and copied back.
Josh Stone [Thu, 14 Nov 2013 01:04:19 +0000 (17:04 -0800)]
PR16162: Support .plt probes on prelinked libraries
There were a few bias issues in how plt addresses were handled, which
broke in the face of prelink offsets. This patch tries to standardize
how these addresses are handled.
* tapsets.cxx (query_plt_statement): New function to fix plt addresses,
both adding dwfl's elf bias and subtracting the dw bias, so it will
work with dwflpp::relocate_address like everything else.
(base_query::base_query): Leave session::consult_symtab alone!
(dwarf_query::query_module_symtab): PLT doesn't fake a path through
the symbol table anymore.
(dwarf_query::handle_query_module): Direct PLT to query_plt_statement.
(dwarf_query::add_probe_point): Remove the relocate exemption for plt.
* testsuite/systemtap.base/plt.exp: Update with a prelink test, and
refactor a lot of the test on the way.
Josh Stone [Wed, 13 Nov 2013 02:20:44 +0000 (18:20 -0800)]
stapdyn: warn on !isInstrumentable functions
The most common reason I've found that Dyninst won't allow us to
instrument a function is an indirect jump. This prevents them from
creating a control-flow graph, so they conservatively refuse.
Explicit indirect jumps are rare, like in the internals of longjmp, but
they may also occur for switches that are implemented with a jump table,
or tail calls to a vtable function, for instance.
Jonathan Lebon [Mon, 11 Nov 2013 17:19:35 +0000 (12:19 -0500)]
add mismatch_complexity
The mismatch_complexity variable allows us to only print out the most
complex kind of mismatch, and skip over simpler mismatches, in order to
keep the mismatch reporting as simple to understand as possible.
When assert_resolvability is false, mismatch_complexity simply remembers
the most complex mismatch we've met so far during each pass (e.g.
unresolved() is 0, mismatch(e) is 1, mismatch(tok, t1, t2) is 2, and
mismatch(tok, t, decl, index) is 3).
Once we turn on assert_resolvability, we check mismatch_complexity in
mismatch() and unresolved() to determine whether to print out an error
or not. If mismatch_complexity is higher than our own complexity, then
we don't print anything since we know that there is a better-suited
mismatch coming up.
Jonathan Lebon [Mon, 11 Nov 2013 17:05:42 +0000 (12:05 -0500)]
implement resolved() and mismatch() and use them
We finally complete the new function bodies. In resolved(), we add items
to the resolved_types vector, while in mismatch(), we retrieve from the
vector to print out exactly where the decl type was initially resolved.
Jonathan Lebon [Mon, 11 Nov 2013 16:34:39 +0000 (11:34 -0500)]
new resolved_type struct and mismatch/resolved functions
The resolved_type struct holds all the information about a newly
resolved decl. The token 'tok' holds where the resolution occurred, and
'index' is the position of the function-argument/array-index of the
decl.
The vector resolved_types will hold all the decls we resolve. A new
resolved() function is introduced which will add elements to the vector,
while an analogous mismatch() function will be used to report mismatches
between type and resolved decl.
* runtime/linux/uprobes-common.c (stap_uprobe_change_plus): The outer if
statement use curly braces to create a block, however the ending
curly brace ended up outside macro conditional.
David Smith [Fri, 8 Nov 2013 17:01:20 +0000 (11:01 -0600)]
Revert commit 65ddca0 since s390x can get get syscall arguments 7+.
* tapset/linux/nd_syscalls2.stp (nd_syscall.pselect7): Since the fix for
PR15913, s390x systems can get arguments 7 (and following) off the
stack. Revert commit 65ddca0 which hardcoded argument 7 to -1.
(nd_syscall.compat_pselect7): Ditto.
Josh Stone [Thu, 7 Nov 2013 23:30:42 +0000 (15:30 -0800)]
stapdyn: Tighten BPatch insertion sets
We were doing insertion sets in instrument_object_dynprobes(),
regardless of whether there was even a target match. This sometimes
triggers bad corner cases in Dyninst when the finalize tries to go do
things in a nascent process, with no action actually needed. While this
gets investigated in Dyninst, we can narrow down our insertion sets to
instrument_dynprobe_target(), where at least we know it's a match.
PR16132: staprun: fix fallback for openat/open modes for debugfs trace%d
Previous code got confused as to how many trace%d files to open and
where. Now we openat() only from the incoming staprun/stapio -F fd
directory, or open() right from /sys/kernel/debug/systemtap/..., with
no hanky panky between them.
stap-server ssl: enable all cipher suites manually
On some versions of NSS, NSS_SetDomesticPolicy doesn't work right,
so let's use lower-level functions with the appropriate (zero)
level of return-code checking.
The stap runtime doesn't play that well with k[gu]id_t and namespaces.
$SUBJECT kconfig option highlights the extent to which we use [ug]id_t.
An earlier commit 857163157b8 papered over the problem to some extent;
the present commit adds anothet coat of slop to cover the cracks.
Jonathan Lebon [Tue, 5 Nov 2013 16:16:16 +0000 (11:16 -0500)]
don't test uprobes_filtering.exp on RHEL5/6
We don't want to run this test on RHEL5/6, where we compile our own
uprobes module (there's no filtering possible anyway, since these
kernels don't support UPROBE_HANDLER_REMOVE).
Jonathan Lebon [Tue, 5 Nov 2013 15:17:12 +0000 (10:17 -0500)]
update user_string_n_quoted.exp test case
With commit 7bec2c2, the default behaviour of user_string_n_quoted() has
changed. The test case is now updated to test that
user_string_n_quoted() trims strings according to input length and that
user_string_n2_quoted() trims strings according to output length given
the inverse parameters.
David Smith [Mon, 4 Nov 2013 17:18:39 +0000 (11:18 -0600)]
Fix BZ1020853 by fixing procfs probe compile problems on newer kernels.
* runtime/procfs.c (_stp_mkdir_proc_module): Support kern_path(), along
with vfs_path_lookup().
* buildrun.cxx (compile_pass): Added 'exportconf' for kern_path().
Jonathan Lebon [Fri, 1 Nov 2013 18:57:40 +0000 (14:57 -0400)]
improve levenshtein performance
Doing this simple bypass has drastic performance consequences. E.g. when
matching against small-ish strings, we see ~10 time speed improvements,
while with larger strings we see slightly more than twice the speed.
Jonathan Lebon [Fri, 1 Nov 2013 15:19:55 +0000 (11:19 -0400)]
improve function arity mismatch error msg
The symbolic semantic_pass now prints a clearer error when a function
matches by name, but not by arity. Previously, there was no distinction
between referencing a non-existent function and one that exists but does
not match arity.
Upon arity mismatch, we print both where the function call occurred, and
where the function was defined.
Jonathan Lebon [Fri, 1 Nov 2013 13:21:49 +0000 (09:21 -0400)]
move visited_modules from dwarf_query to base_query
The visited_modules set is now part of base_query. This helps us
centralize the place where modules are added to the set (in
query_module) and will be needed for implementing suggestions for
non-dwarf-related probes.
Jonathan Lebon [Thu, 31 Oct 2013 19:38:29 +0000 (15:38 -0400)]
levensh suggest unresolved probe points
This patch adds Levenshtein suggestion to match_node::find_and_build().
Suggestions are made in three cases:
- Unresolved double-glob (e.g. syscall.poen**)
- Unresolved glob (e.g. syscall.poen*)
- Unresolved no-glob (e.g. kernel.functoin("bla"))
Note that suggestions for globby functors are based on the prefix part
only (part of functor prior to the **) to increase meaningfulness.
Jonathan Lebon [Thu, 31 Oct 2013 17:45:58 +0000 (13:45 -0400)]
refactor levenshtein suggesting
In anticipation for a wider use of levenshtein(), we factor out the
common part into a new function levenshtein_suggest(). We then change
suggest_functions() to use levenshtein_suggest().
Josh Stone [Thu, 31 Oct 2013 22:03:34 +0000 (15:03 -0700)]
Flip user_string_n_quoted to limit the input count
The documentation of that function implies that it's counting n from the
input string, but in fact that limit was being applied to the output,
including quotes and escaping.
Now _stp_text_str takes two length parameters to limit the input count
and output size separately. A new user_string_n2_quoted() lets you
specify both of these lengths, and user_string_n_quoted now uses that to
limit input length, or output still in compatibility mode.
Several syscall tapsets which read user buffers of known length will now
use user_string_n2_quoted to fit that. This was seen in syscall.write
which may not necessarily have any '\0' at the end of its buffer.
Jonathan Lebon [Wed, 30 Oct 2013 15:12:45 +0000 (11:12 -0400)]
PR16019: treat errors from tapsets/functions as non-critical
Since we now include parsing errors in seen_errors, we get an increase
in num_errors() which we didn't have before. This would cause the
function passes_0_4() to stop at pass 1 even when parsing errors only
occurred in tapset/macro files (previously, we simply issued a warning
and kept going).
We now pass a new flag, errs_as_warnings, to the parsing methods so that
whenever any parsing errors occur while parsing tapset or macro files,
systemtap_session::print_error() will not count the error towards the
num_errors() value.
The net effect is that prior to pass 1b (user script parsing), any error
is printed (along with a warning) but not counted. Warnings are still
emitted, so that -W will still stop everything.
Thus, from the user's standpoint, there is no change in behaviour prior
to these series of patches.
Jonathan Lebon [Mon, 21 Oct 2013 13:35:48 +0000 (09:35 -0400)]
PR16019: improve duplicate error elimination
Previously, we relied on exact string matching when considering whether
to print an error or not. This had the disadvantage of not filtering out
whenever the same error occurred on many different lines. Also, error
chains, which often provided context, were cut off, causing errors to be
more cryptic.
With this series of patches, this is how behaviour is modified:
1. Errors are filtered out based on their source, i.e. the function
and line at which the error was thrown. This means that slightly
different error messages are still considered equivalent and
eligible for duplicate elimination.
2. Errors that get passed the filter are always printed with thei
full chain to provide maximum context.
3. When in verbose mode (just one -v), filtering is completely turned
off and all errors are printed out.
This patch simply installs the mechanisms through which these
modifications will take place in the next patches.
- main.cxx: print out number of suppressed errors on cleanup
- session.cxx: rework the print_error() functions to account for
chaining
- session.h: new function and variable declarations and modify
parse_error object to hold errsrc
- staptree.h: modify semantic_error object to hold errsrc
- util.h: add helper macros for throwing errors which include source
You can use the SEMANTIC_ERROR and PARSE_ERROR macros to ease error
throwing. These macros automatically pass the the function and line
number to the error constructor.
William Cohen [Tue, 29 Oct 2013 19:00:58 +0000 (15:00 -0400)]
Make the ARM _stp_store_deref and _stp_deref more like kernel ARM uaccess.h macros
The ARM uaccess.h macros for put_user and get_user do an explicit
typecast of the address into an unsigned long. This typecast is
important for the __stp_get_user_asm_half and __stp_put_user_asm_half
macros. Without it these macros attempt to do pointer and get an
incorrect address for the second byte of a 16-bit value.
William Cohen [Tue, 29 Oct 2013 16:44:49 +0000 (12:44 -0400)]
Make the 32-bit ARM get_user() and put_user() work for 16-bit quantities
The 32-bit ARM does not have instructions to perform 16-bit loads or
stores. The __get_user_asm_half and __put_user_asm_half macros
sythesize those operations. However, in most cases the pointers
passed into these macros are pointers to 16-bit types and the pointer
arithmetic will end up pointing at the next 16-bit quantity rather
than the second half (byte) of the 16-bit quantity. The macros need
to explicitly typecast the pointers as pointers to 8-bit quantities to
make the pointer arithmetic work out properly.
Josh Stone [Mon, 28 Oct 2013 22:42:46 +0000 (15:42 -0700)]
Add an example for tracking shared futexes
The existing futexes.stp does show shared futexes, but only by the
$uaddr which is specific to any given process. This futexes2.stp tries
to show shared futexes by the inode path+offset of the mapping. I found
this useful in examining stapdyn's pthread_mutexes in shm.
This also adds an inode_path() tapset function which tries to locate the
vfsmount containing an inode in the current namespace, and if found uses
task_dentry_path() to get a full path.
David Smith [Mon, 28 Oct 2013 21:35:43 +0000 (16:35 -0500)]
Fix 'syscall.accept' probe alias.
* tapset/linux/syscalls.stp (syscall.accept): Make sure optional probe
points are marked as optional at the top, since optionalness passes down
along alias definitions, not up.
David Smith [Mon, 28 Oct 2013 21:33:05 +0000 (16:33 -0500)]
Refix PR16058 by updating the old syscall.mmap2/nd_syscall.mmap2 probes.
* tapset/linux/i386/syscalls.stp: Make sure optional probe points are
marked as optional at the top, since optionalness passes down along
alias definitions, not up.
* tapset/linux/i386/nd_syscalls.stp: Ditto.
* tapset/linux/s390/nd_syscalls.stp:
* tapset/linux/s390/syscalls.stp: Ditto.
* tapset/linux/x86_64/nd_syscalls.stp: Ditto.
* tapset/linux/x86_64/syscalls.stp: Ditto.
Josh Stone [Fri, 25 Oct 2013 00:02:53 +0000 (17:02 -0700)]
Allow "read-mostly" stats to elide locks
In c_unparser::emit_lock_decls, we invert read/write locks for stats
types, since they only need a shared lock for writing updates but an
exclusive lock for aggregation to read. However, we didn't invert our
view of vcv_needs_global_locks across all probes, so it was impossible
for stats to ever get counted as "read-mostly" and elide locks.
Now the sense of vcv_needs_global_locks.read/written is swapped for
stats too, so those that are only aggregated in lock-free probes
(begin/end) can be completely lock-free.
Josh Stone [Thu, 24 Oct 2013 23:47:17 +0000 (16:47 -0700)]
stapdyn: Print dbug/warn/error messages with libc vsnprintf
The kernel runtime uses vscnprintf for these, which roughly follows
C99 rules, but the dyninst runtime was using _stp_vsnprintf, which is
not quite the same. Since some runtime code is shared, we need
compatible format strings, so just use libc's vsnprintf here.
Also, one shm_dbug was using %zi for off_t, which isn't always correct
since we #define _FILE_OFFSET_BITS 64, so use PRIi64 instead.
Josh Stone [Thu, 24 Oct 2013 23:00:38 +0000 (16:00 -0700)]
stapdyn: send context-free DBUG messages to stderr
Some debug messages occur outside of probe context, like shm_dbug,
so they would get an error trying to allocate the print buffer. In
the particular case of shm initialization, the transport memory
doesn't even exist yet!
Now if there's not an active context, DBUG just goes to stderr.
Josh Stone [Thu, 24 Oct 2013 22:44:19 +0000 (15:44 -0700)]
Filter duplicates out of globbed process names
For example, process("/lib64/libpthread*") matches libpthread-2.17.so
and libpthread.so.0, but the latter is just a symlink to the former. We
already canonicalized those names, but still had double the probes.
* tapsets.cxx (dwarf_builder::build): Track canonicalized name in a set
so we can skip globbed names that resolve to the same thing.