Mark Wielaard [Tue, 29 Nov 2011 11:32:05 +0000 (12:32 +0100)]
Support fallback kernel dump_stack() with or without bp argument.
There has been some flip-flopping in the kernel whether or not dump_stack()
takes a bp argument. We now support either with or without.
See linux commits v2.6.36-9872-g9c0729d and v2.6.38-793-ge8e999c.
Mark Wielaard [Tue, 29 Nov 2011 11:32:05 +0000 (12:32 +0100)]
Support fallback kernel dump_stack() with or without bp argument.
There has been some flip-flopping in the kernel whether or not dump_stack()
takes a bp argument. We now support either with or without.
See linux commits v2.6.36-9872-g9c0729d and v2.6.38-793-ge8e999c.
Josh Stone [Mon, 28 Nov 2011 21:06:15 +0000 (13:06 -0800)]
PR13440: Use real userspace addresses in @cast tests
Some architectures make a harder distinction between user/kernel
addresses, so we shouldn't be faking our user memory.
* testsuite/systemtap.base/cast.*: Remove userspace @cast.
* testsuite/systemtap.base/cast-user.*: Add a new test for userspace
@casts with an honest userspace address.
Josh Stone [Mon, 28 Nov 2011 21:02:16 +0000 (13:02 -0800)]
PR13354: Add a type cast to satisfy old compilers
RHEL4-era gcc tried to make "fake_remote?-1:i" unsigned (as 'i' is), and
then complained about making -1 unsigned. Since remote::create just
wants an int anyway, cast "i" in the ternary.
Mark Wielaard [Mon, 28 Nov 2011 11:06:39 +0000 (12:06 +0100)]
_stp_vma_mmap_cb: Really mean that we are only interested in the first load.
There was a chance our test for whether this was the first load of the
whole module that is executable could miss a second load, which would
override the original start address. Fix that by explicitly checking
whether we already registered this module or not.
Frank Ch. Eigler [Sun, 27 Nov 2011 22:26:44 +0000 (17:26 -0500)]
PR13354: remote_id() and remote_uri() tapset functions
This little thing required changes all through the stack!
* main.cxx (main): Pass the explicit --remote option index to the
remote::create invocations.
* remote.cxx (remote::create): Pass incoming index/uri to build staprun_r_arg.
(direct::start): Use value.
(stapsh::start): Use value if remote end is believed to be >= v1.7.
(ssh_legacy_remote::start): Don't use value, as remote end may not know staprun -r.
* remote.h (remote): New field staprun_r_arg.
* runtime/transport/transport_msgs.h: Define new STP_REMOTE_ID message type.
* runtime/staprun/common.c (parse_args, usage): Support new -r option.
* runtime/staprun/staprun.8: Document it.
* runtime/staprun/staprun.c: Pass remote id/uri to runtime via
new STP_REMOTE_URI message.
* runtime/staprun/staprun.h: Declare new variables.
* runtime/transport/control.c (_stp_ctl_write_cmd): Accept STP_REMOTE_ID message
from euid=0.
* runtime/transport/transport.c (_stp_handle_remote_id): Process it.
* tapset/context.stp (remote_id, remote_uri): New functions.
* testsuite/systemtap.base/remote.exp: Extend to print/check those functions' values.
Mark Wielaard [Sat, 26 Nov 2011 21:21:22 +0000 (22:21 +0100)]
Pass through user flag into all of unwinder.
runtime/unwind.c relied on passing of struct task being not NULL
to see whether to access user space. In practice tsk was always
either NULL or current. And not all bits of the unwinder checked
it. Now we just pass a user flag and push it down to every
function that needs it.
Mark Wielaard [Sat, 26 Nov 2011 01:29:57 +0000 (02:29 +0100)]
Use __get_user and __put_user for s390 uderef/kderef.
Replace costum s390 [store_][uk]deref() implementations with standard
s390 kernel __get_user() and __put_user() functions. Wrapped in get_fs()
set_fs() calls to switch between user/kernel space addresses.
Mark Wielaard [Fri, 25 Nov 2011 14:11:00 +0000 (15:11 +0100)]
loc2c-runtime.h: Split deref and store_deref into user and kernel version.
All references to deref have been updated to use either the user or kernel
variant where appropriate, but kderef is currently still defined as uderef,
and store_kderef as store_uderef. Which should work fine for all arches
except s390.
Dave Brolley [Tue, 22 Nov 2011 16:13:28 +0000 (11:13 -0500)]
PR 13128: Implement the new --privilege=stapsys
- Users belonging to the group stapsys can use all probe points and tapset
functions (including those which contain embedded C), but cannot
use the -g option.
- Loading of modules for stapsys users requires signing by a trusted compile-server.
- Add testing for stapsys throughout as appropriate.
- Update existing unprivileged test suites to test stapsys as appropriate.
- New test suite tests -g against all privilege levels.
William Cohen [Mon, 21 Nov 2011 22:21:20 +0000 (17:21 -0500)]
Add autoconf check for the addition of the pte argument for alloc_vm_area
Linux Kernel commit cd12909cb5 add the pt argument to the alloc_vm_area
function. Need to check whether that pte argument exists and sets a define
as required.
David Smith [Mon, 21 Nov 2011 18:03:03 +0000 (12:03 -0600)]
Update testsuite to check for new utrace requirements.
* testsuite/lib/systemtap.exp (utrace_p): Properly tests for the new
utrace requirements.
* runtime/task_finder.c: Remove code that hardcoded new utrace.
* runtime/uprobes/uprobes.h: Reset to "normal" version.
Mark Wielaard [Sat, 19 Nov 2011 19:45:49 +0000 (20:45 +0100)]
Add testsuite/lib/compile_flags.exp and use it in tests.
testsuite/lib/compile_flags.exp defines all_compile_flags(),
all_compile_flag(INDEX) and all_compile_flag_name(INDEX) which return
the number, actual flag and extra test name to use in tests that use
target_compile for use space testing. On architectures that support
multiple ABIs it will return all combinations of all optimizations
(none, -O, -O2) and the ABI flags (-m64, -m32 or -m31).
Use in a for loop like: for {set i 0} {$i < [all_compile_flags]} {incr i} {
set extra_flag [all_compile_flag $i] # Add to target_compile flags
set extra_name [all_compile_flag_name $i] # Add to test pass/fail message
...
}
David Smith [Fri, 18 Nov 2011 20:37:11 +0000 (14:37 -0600)]
Check for the new task_finder config variable requirement.
* tapsets.cxx (check_process_probe_kernel_support): Add support for the
requirements of the new task_finder (and even look ahead to the new
uprobes).
* tapset-utrace.cxx (utrace_derived_probe_group::emit_module_decls): Minor
change to match "real" tapset-utrace.cxx.
David Smith [Fri, 18 Nov 2011 19:28:54 +0000 (13:28 -0600)]
Move common CONFIG_UTRACE check to its own function.
* tapsets.cxx (check_process_probe_kernel_support): New function.
(dwarf_builder::build): Moved CONFIG_UTRACE check to
check_process_probe_kernel_support() which we call instead.
* tapset-utrace.cxx (utrace_derived_probe::utrace_derived_probe): Call
check_process_probe_kernel_support() instead of doing CONFIG_UTRACE
check.
* tapsets.h: Declare check_process_probe_kernel_support().
Josh Stone [Thu, 17 Nov 2011 21:10:55 +0000 (13:10 -0800)]
PR12136: Tweak the cast-scope testcase
- Use unnamed process.* to allow -c to guarantee the right path
- Specify the function probe's file, so we don't accidentally pick up
any other length(), like string::length().
David Smith [Wed, 16 Nov 2011 21:23:46 +0000 (15:23 -0600)]
Add UTRACE_API_VERSION to determine which utrace version we've got.
* runtime/stp_utrace.h: Added UTRACE_API_VERSION back.
* tapset-utrace.cxx (utrace_derived_probe_group::emit_module_decls): Use
UTRACE_API_VERSION, which stp_utrace.h now provides, so that we don't
have to check STP_TASK_FINDER2.
Mark Wielaard [Wed, 16 Nov 2011 12:33:26 +0000 (13:33 +0100)]
Don't use dwfl_module bias in either emit_address() and vardie_from_symtable().
dwflpp::emit_address() is called by loc2c for emitting DW_OP_addr.
DW_OP_addr could come from the actual dwarf location description or
could be synthetically generated from through vardie_from_symtable().
vardie_from_symtable() would keep the dwfl module bias (if there was one),
but the DW_OP_addr from real dwarf debuginfo would not have it.
Now we are consistently not having the module bias added.
Add some variants of the externalvar.exp testcase, which previously
failed with older GCC versions (where we would pick up the DW_OP_addr
from the dwarf location description), while newer GCCs emit dwarf DIEs
for these variables that only have the external flag set. The new
testcase variants use static vars, which will have DW_OP_addr emitted
in both old and new GCC versions.
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.
David Smith [Wed, 9 Nov 2011 22:08:58 +0000 (16:08 -0600)]
Fix memory leak in new utrace code.
* runtime/stp_utrace.c: Removed some unused code.
(utrace_cleanup): Renamed from utrace_free() and added comments.
(utrace_free): Renamed from utrace_free_task() and now takes a 'struct
utrace' pointer instead of a 'task_struct' pointer.
(utrace_report_death): To avoid a memory leak, call utrace_free().
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.
David Smith [Tue, 8 Nov 2011 19:28:10 +0000 (13:28 -0600)]
Switch UTRACE_EVENT(EXIT) support to UTRACE_EVENT(DEATH) support.
* runtime/stp_utrace.c: Switch UTRACE_EVENT(EXIT) support to
UTRACE_EVENT(DEATH) support to avoid leading utrace engines.
* runtime/stp_utrace.h: Turn off UTRACE_EVENT(EXIT) support and turn on
UTRACE_EVENT(DEATH) support.
* runtime/task_finder2.c: Switch from UTRACE_EVENT(EXIT) handlers to
UTRACE_EVENT(DEATH) handlers.
* tapset-utrace.cxx (utrace_derived_probe_group::emit_probe_decl): Removed
special STP_TASK_FINDER2 code.
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").