Frank Ch. Eigler [Mon, 14 Nov 2011 19:34:56 +0000 (14:34 -0500)]
PR13313 cont'd, fix regexp for [+-]D[+-]D[+-]D(...) operand case
Our regexps used [+-]? for the second/third optional displacement
values, when in fact they are not optional. They are the only thing
that would separate the numbers.
Frank Ch. Eigler [Mon, 14 Nov 2011 14:44:52 +0000 (09:44 -0500)]
PR13313 redux, fix off-by-one error in disp+disp+disp(...) asm operand format
commit 8095a157 cleaned up regexp match parsing, but
included a bonus off-by-one error that resulted in
ignoring the third "disp" optional addend.
* tapsets.cxx (sdt_uprobe_var_expanding_visitor::visit_target_symbol_arg)
Make optional disp addends count up to three. Four shalt thou not
count, neither shalt thou count to two, excepting that thou then
proceed to three. Five is right out.
pthreadprobes.exp tested pthread_mutex_timedlock but didn't handle the
result which caused it to FAIL the mutex_timedlock_entry test each time.
pthread_mutex_timedlock is called with a timeout of 1 second in a
loop while the mutex is held by the other thread for about 5 seconds
resulting in a couple of entries resulting in a ETIMEDOUT before it
is actually acquired. Expect 2 till 6 tries before success.
Mark Wielaard [Sat, 12 Nov 2011 21:30:28 +0000 (22:30 +0100)]
sched_switch.stp parse arguments once, workaround name argument WARNINGs.
stap got smarter and now detects some arguments aren't used or used
"wrongly". Add a begin probe to parse the arguments, use strtol if
necessary, and add usage message in case wrong number of args were given.
This suppresses WARNINGs for 'stap sched_switch.stp name firefox':
WARNING: never-assigned local variable 'firefox' (alternatives: __tracepoint_arg_p name task task_pid task_tid task_priority task_cpu task_state): identifier 'firefox' at testsuite/systemtap.examples/profiling/sched_switch.stp:34:19
source: if (task_pid != $2 && pid() != $2)
^
WARNING: never-assigned local variable 'firefox' (alternatives: __tracepoint_arg_prev __tracepoint_arg_next next_pid next_tid next_task next_task_name nexttsk_state next_priority prev_priority prev_pid prev_tid prev_task prev_task_name prevtsk_state name): identifier 'firefox' at :53:19
source: if (next_pid != $2 && prev_pid != $2)
^
WARNING: Eliding unused variable 'firefox': identifier 'firefox' at :34:19
source: if (task_pid != $2 && pid() != $2)
^
Josh Stone [Fri, 11 Nov 2011 22:11:11 +0000 (11:11 -1100)]
PR13404: Dial SDT args up to twelve
This is SystëmTap, and eleven is so 1984...
* includes/sys/sdt.h: Expand all macros from 10 to 12.
* tapsets.cxx (sdt_uprobe_var_expanding_visitor): Allow 12 args now.
* testsuite/systemtap.base/sdt.*: Test 12 args for SDT v3 only.
* testsuite/systemtap.base/sdt_va_args.*: Test 12 in STAP_PROBEV.
Frank Ch. Eigler [Fri, 11 Nov 2011 16:59:11 +0000 (11:59 -0500)]
PR13313: parse x86 base+(index*scale)+displacement sdt.h asm operand format
* tapsets.cxx (sdt_uprobe_var_expanding_visitor::visit_target_symbol_arg): Parse
N(%r,%r,S) format with another regexp branch. Adjust regexp-parsing logic in N(%r)
to avoid iteration over regexp matches, as we know the indices directly.
Mark Wielaard [Fri, 11 Nov 2011 11:23:25 +0000 (12:23 +0100)]
testsuite/systemtap.base/vta-test.c: Tweaked to use variables.
GCC 4.6 was too smart. It saw we didn't actually use the a[] ever
so never stored its contents. Now we actually use the array so a
(constant) expresion location is put in the dwarf output.
Dave Brolley [Wed, 9 Nov 2011 20:39:47 +0000 (15:39 -0500)]
PR 13128: Implement --privilege option and correct privilege checking usage.
- In particular, don't assume only two privilege levels. All tests now test
for the specific privilege required in order to allow the construct.
- Update test suites
PR13373: unprivileged tests for plt / label probes
* libfoo.c, libloop.c: Add a dummy goto & label.
* unprivileged_probes.exp: Add missing probe point types. Add plt(string)
substitution.
* unprivileged_myproc.exp: Ditto, plus designate .plt.statement(N) probes
as xfail, since the naive sort of address (N) substitution does not
result in tripped probes.
Mark Wielaard [Wed, 9 Nov 2011 16:06:28 +0000 (17:06 +0100)]
testsuite/systemtap.base/plt.c: define _GNU_SOURCE for stpcpy.
stpcpy is strange. On some older systems it is only declared when
_GNU_SOURCE is defined. The STPCPY(3) manpage says:
This function is not part of the C or POSIX.1 standards, and is not
customary on Unix systems, but is not a GNU invention either. Perhaps
it comes from MS-DOS.
Dave Brolley [Tue, 8 Nov 2011 15:15:27 +0000 (10:15 -0500)]
PR 13128: Backward compatibility for stapusr and stapdev level modules.
If no privilege credentials are passed to the module, we can assume that
the module was loaded directly by a root level user (insmod) or by an
older version of staprun (less than 1.7). In the latter case, if the module
requires stapusr or stapdev credentials, we can assume that staprun did the
right thing and that the module is safe to run. Otherwise, the required
privilege level is unknown to the old staprun and we must abort.
Mark Wielaard [Tue, 8 Nov 2011 12:50:52 +0000 (13:50 +0100)]
Split printing of kernel and user stack in separate functions.
We used to do some "clever" tricks with passing around constants that
indicated which stack we really wanted. Partly this was so gcc could
optimize out uprobe_get_pc() calls when not necessary. Which was needed
to prevent WARNING: "uprobe_get_pc" undefined! when loading the module
if uprobes wasn't available (e.g. when wanting just a kernel stack).
This was too fragile, gcc didn't always optimize out the call when not
needed. And the code wasn't particular clear. This just splits
__stp_dwarf_stack_print() into __stp_dwarf_stack_kernel_print() and
__stp_dwarf_stack_user_print() and splits _stp_stack_print() into
_stp_stack_kernel_print() and _stp_stack_user_print() (including the
sprint variants). Only the user functions will ever call uprobe_get_pc().
PR13353: use session parameters to search for build-id.
Previous code used uname directly, which ignored the arch/machine
data already available in the incoming systemtap_session instance.
* session.h (native_build): New flag.
* session.cxx (check_options): Compute it.
(systemtap_session ctors): Heurstically estimate it.
* setupdwfl.cxx (get_kernel_build_id): Use incoming kernel_build_tree
to search for vmlinux.id. If native build suspected, check
/sys/kernel/notes.
Mark Wielaard [Mon, 7 Nov 2011 20:08:34 +0000 (21:08 +0100)]
Silence gtod.c -Wformat warnings. Arguments are long int (%ld), not int (%d).
Some gcc installs have -Wformat as default warning enabled...
gtod.c:21:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__time_t’ [-Wformat]
gtod.c:21:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘__suseconds_t’ [-Wformat]
gtod.c:22:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__time_t’ [-Wformat]
gtod.c:22:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘__suseconds_t’ [-Wformat]
PR13386: avoid _stp_printf() crash for null context / %M or %m
If _stp_printf() were invoked with %M or %m directive that resulted in
an error, it likes to write into the current stap probe handler
context about it. However, _stp_printf is sometimes used outside
probe handler context, in which case no context is actually available,
such as during module_exit(). So we tolerate a null context pointer
(it just having been deallocated). Note that there don't exist any
current %M/%m outputs in the runtime that could trigger this
NULL-deref, so this is only a prophylactic measure.
PR13386: disable preemption around printing-happy parts of *module_exit().
* translate.cxx (c_unparser::emit_module_exit): Since we use stp_printf
(that internally is preempt-sensitive), we need to disable preemption
(or at least cpu switching) during this stage.
This variant of the test case serializes the module coming/going
traffic, to work around what are assumed to be kernel kprobes
problems. With &'s wherever ;'s are, even manly, glutamine-fortified
bicept-curling kernels quiver with fear.
PR13193: disable kprobes-optimization at staprun startup time
* runtime/staprun/staprun.c (disable_kprobes_optimization): New function,
called from ...
(init_staprun): ... here, unless getenv("STAP_PR13193_OVERRIDE").
Chris Meek [Fri, 4 Nov 2011 18:07:07 +0000 (14:07 -0400)]
Simplified environ variable parsing in server
stap-serverd.cxx
No need to check for control characters in parsing, as it is only
passing the environ variables between stap-serverd and its child stap.
Mark Wielaard [Fri, 4 Nov 2011 16:26:43 +0000 (17:26 +0100)]
PPC64 Dwarf handle both .debug_frame and .eh_frame register mappings.
These are slightly strange since they don't really use dwarf register
mappings, but gcc internal register numbers. There is some confusion about
the numbering see http://gcc.gnu.org/ml/gcc/2004-01/msg00025.html
We just handle the 32 fixed point registers, mq, count and link and
ignore status registers, floating point, vectors and special registers
(most of which aren't available in pt_regs anyway). Also we placed nip
last since we use that as UNW_PC register and it needs to be filled in.
Note that we handle both the .eh_frame and .debug_frame numbering at
the same time. There is potential overlap though. 64 maps to cr in one
and mq in the other...
Mark Wielaard [Thu, 3 Nov 2011 20:20:47 +0000 (21:20 +0100)]
translate.cxx (get_unwind_data): Only get .eh_frame for SHT_PROGBITS sections.
This is really a bug somewhere in the toolchain. Only observed on s390x
for the kernel debuginfo vmlinux image. But it is a good sanity check in
general. See also rhbz#751197.
Chris Meek [Thu, 3 Nov 2011 19:37:45 +0000 (15:37 -0400)]
Fixed environ variable parsing in server
stap-serverd.cxx
Used regexp_match() to extract the environment variables from
environ, checking for embedded control characters. If found,
that variable is ignored, a warning is printed, and execution
continues.
PR13338: prevent infinite recursion during process glob expansion
Previously, it was possible for a process("/usr/bin/*") probe to
expand to a list that included process("/usr/bin/[") (or indeed
some other wildcard-containing filename), which would recursively
trigger glob expansion. Now we \-quote glob results, to prevent
this, and later \-unquote to undo the damage.
* tapsets.cxx (dwarf_builder::build): quote / unquote process globs.
* testsuite/systemtap.base/bz13338.exp: New test.
* util.cxx (*_glob_chars): New/revised functions for \-quoting
some glob metacharacters.
* util.h: Corresponding changes.
* staptree.h: Crucial whitespace change.
Mark Wielaard [Tue, 1 Nov 2011 16:32:23 +0000 (17:32 +0100)]
Be explicit about SP from CFA and PC from RA dwarf unwind rules.
There are subtle differences between architectures whether or not they
should unwind the stack pointer from the call frame address and the
instruction pointer from the return address given by the dwarf call
frame instructions. Make it so each arch explicitly encodes how it
does the unwinding of these two special registers.
Mark Wielaard [Mon, 31 Oct 2011 13:29:46 +0000 (14:29 +0100)]
Make --with-elfutils work with either a source release or git checkout.
Add configure check to see if this is a source release, or a source
checkout. We need --enable-maintainer-mode if it isn't a source release
to make sure some additional files are generated. This makes working
against non-released elfutils git checkout a lot easier.
Mark Wielaard [Mon, 31 Oct 2011 09:39:10 +0000 (10:39 +0100)]
Introduce and use STP_ALLOC_SLEEP_FLAGS for use with gfp alloc functions.
When in a context where we can wait we like to use normal GFP_KERNEL.
But this might trigger the oom-killer, which might kill out own stapio
process. To suppress this use __GFP_NORETRY. All _stp_[kmz]alloc_gfp
functions that are used in user context should use STP_ALLOC_SLEEP_FLAGS
if appropriate.
Note that the kernel itself may still use GFP_KERNEL. For example
__alloc_percpu() will always use GFP_KERNEL.
Josh Stone [Fri, 28 Oct 2011 22:42:02 +0000 (15:42 -0700)]
Add the pattern for label probes in libraries
* tapsets.cxx (dwarf_derived_probe::register_patterns): Refactor so that
all process[.library] variants get the same set of suffixes.
(dwarf_derived_probe::register_function_and_statement_variants): Add
the label pattern from here, just as .inline is done.
Josh Stone [Fri, 28 Oct 2011 22:11:17 +0000 (15:11 -0700)]
Refactor sdt & plt pattern registration
This factors the sdt and plt suffixes away from the various process and
process.library prefixes. As a result, we also gain process.plt for
probing -c commands.
* tapsets.cxx (dwarf_derived_probe::register_sdt_variants): New.
(dwarf_derived_probe::register_plt_variants): New.
(dwarf_derived_probe::register_patterns): Register sdt and plt for all
process/library combinations.
* testsuite/semok/plt2.stp: Test that process.plt succeeds with -c
* testsuite/semko/plt2.stp: Test that process.plt fails without -c
Mark Wielaard [Fri, 28 Oct 2011 21:47:53 +0000 (23:47 +0200)]
Just test up to -p2 for kernel-debuginfo smoke test.
We already do a -p4 kernel-devel smoke test just before this one.
We don't need another one. It slows down doing make installcheck
RUNTESTFLAGS=quick_test.exp runs. Especially on slow machines.
Josh Stone [Fri, 28 Oct 2011 21:42:23 +0000 (14:42 -0700)]
plt: Throw an appropriate error for missing $var
* tapsets.cxx (plt_expanding_visitor::visit_target_symbol): Throw a
semantic_error for missing $var, so it may be caught and chained for
later. This ensures that the visitor always has a provide() too.
* testsuite/semko/plt1.stp: New, check that missing $var is an error.
* testsuite/semok/plt1.stp: New, check that $$name works, as does
@defined on a missing $var.
David Smith [Thu, 27 Oct 2011 15:24:45 +0000 (10:24 -0500)]
More PR13083 fixes to avoid sleeping in the task_finder.
* runtime/task_finder.c (__stp_get_mm_path): Call down_read_trylock()
instead of down_read() to avoid the possibility of sleeping.
(stap_start_task_finder): Call task_lock() to make sure a task's mm
doesn't go away while we're looking at it.
Based on peer feedback:
- Compare privilege credentials as sets, not levels.
- Send privilege credentials as a ctl message at startup.
- Send startup ctl messages (tzinfo, relocations, privilege_credentials)
on the same control channel. Ensure channel is closed properly on error.
Mark Wielaard [Fri, 21 Oct 2011 14:49:02 +0000 (16:49 +0200)]
Extract addr_of for unprivileged_[my]probes.exp once and with optional dot.
Some architectures prefix function symbols with a '.', so accept an
optional dot prefix. Also extract each symbol only once instead of
for each pass over the list.
Mark Wielaard [Fri, 21 Oct 2011 11:34:21 +0000 (13:34 +0200)]
Extend vma_map entry vm_end range when additional segments are mapped.
Once registered, we may want to extend an earlier registered region.
A segment might be mapped with different flags for different offsets.
If so we want to record the extended range so we can address more
precisely to module names and symbols.
David Smith [Wed, 19 Oct 2011 15:00:45 +0000 (10:00 -0500)]
Fixed PR13158 by adding a staprun signal handler so modules don't remain.
* runtime/staprun/staprun.c (term_signal_handler): New function.
(setup_term_signals): Ditto.
(insert_stap_module): Remembers if insert_module() worked.
(main): Call setup_term_signals().
* testsuite/systemtap.base/rename_module.exp: Made test case more robust
by waiting on output from all stap scripts.
* testsuite/systemtap.base/pr13158.exp: New testcase.
* transport/relay_v2.c, relayfs.c (_stp_transport_data_fs_init):
Increment _stp_allocated_[net_]memory with relay buffers.
* transport/ring_buffer.c: Ditto. Plus fix scaling of the incoming -sNN
value, so NN represents megabytes consistently.
Frank Ch. Eigler [Tue, 18 Oct 2011 20:58:15 +0000 (16:58 -0400)]
PR13317: improve parse error recovery heuristics
This change changes the 10 parse errors reported by brendang for iostat-scsi.stp
to just six actually salient ones.
* parse.cxx (parser::parse): Reorder error recovery to skip
everything until next top-level keyword. Wrap try {} in
while {} rather than vice versa.
(parser::parse_stmt_block): Drop recovery loop.
Dave Brolley [Tue, 18 Oct 2011 17:54:20 +0000 (13:54 -0400)]
PR 13128: Pass user privilege credentials from staprun to the module.
- User's privilege credentials are determined by staprun and passed to the module
- Module contains generated code which checks the user's credentials against those
required to load/run the module (specified at compile time).
- module aborts if credentials are insufficient.
Mark Wielaard [Tue, 18 Oct 2011 12:28:59 +0000 (14:28 +0200)]
PR13284 Failure to resolve kernel global e.g. jiffies.
* dwflpp.cxx (vardie_from_symtable): Also accept STT_NOTYPE. Some global
don't have a type associated with them.
* testsuite/buildok/pr13284.stp: New testcase.
Josh Stone [Mon, 17 Oct 2011 22:18:06 +0000 (15:18 -0700)]
PR13283: Use a temporary string for comparisons
The reported issue was trying to directly compare the results of two
different kernel_string() calls, but they were always computed equal
even though they were known to be different. Inspection of pass-3
showed that both calls led to an expr-stmt ending in ...->__retvalue.
This is just a pointer though, and it happens here that both calls will
point to the same string buffer, so strncmp rightly calls them equal.
To fix this, we must introduce temporary storage for the intermediate
strings. Now we won't lose either value, and they can be properly
compared for equality.
* translate.cxx (c_tmpcounter::visit_comparison): Declare temporary
storage for the left operand if it's not a literal.
(c_unparser::visit_comparison): Use the left temporary.
* testsuite/systemtap.string/strcmp.*: Test string comparisons.