Josh Stone [Fri, 11 Sep 2009 00:06:11 +0000 (17:06 -0700)]
PR10594 cont'd: Use parent die cache for variable lookup
Variable lookup is usually done through the scopes from dwarf_getscopes
at a particular pc. This requires an expensive traversal to find the
inner-most die containing the pc. For cases where that containing die
is known, e.g. at a particular function entry, we can do much better
with our die_parent_cache.
This may also help get more accurate variable scopes in cases where
multiple dies contain a pc and the innermost isn't what we're trying to
probe. For example, an inlined call chain of foo->bar->baz may all have
the same entry pc, but if the probe was on function("bar"), we would
want the variables in bar's scope, not baz's.
* dwflpp.h (struct dwflpp): Remove pc_cached_scopes, num_cached_scopes,
and cached_scopes, as they are now remembered by the caller.
* dwflpp.cxx (dwflpp::getscopes): New - the DIE version uses the parent
cache, and the pc version just defers to dwarf_getscopes.
(dwflpp::print_locals, literal_stmt_for_local): Take a scopes vector.
(dwflpp::find_variable_and_frame_base): Take a scopes vector from the
caller instead of computing it every time.
(dwflpp::dwarf_getscopes_cached): Removed.
* tapsets.cxx (dwarf_var_expanding_visitor::getscopes): New cached
lookup function which gets the scopes from the DIE if possible.
(dwarf_var_expanding_visitor::visit_target_symbol): Call getscopes.
Josh Stone [Wed, 9 Sep 2009 22:45:28 +0000 (15:45 -0700)]
PR10594: Provide a cached dwarf_getscopes_die
This avoids repeated DIE traversal by caching all parents on the first
call, so future calls are just a simple walk up parent links.
* dwflpp.cxx (dwflpp::getscopes_die): New cached function that mimics
libdw's dwarf_getscopes_die using cached parent links.
(dwflpp::cache_die_parents): New function to build the parent cache.
(dwflpp::~dwflpp): Clean up the parent caches.
(dwflpp::iterate_over_labels): Use the cached getscopes_die.
(dwflpp::find_variable_and_frame_base): Ditto.
* tapsets.cxx (dwarf_derived_probe::saveargs): Ditto.
(uprobe_derived_probe::saveargs): Ditto.
(dwarf_var_expanding_visitor::visit_target_symbol_context): Ditto.
Fix relay_old implementation of fsize_max and fnum_max.
With old relayfs, out_fd is used only when non-bulk mode. However,
open_oldoutfile and open_relayfs_files open files with fopen and
set only percpu_tmpfile. This will cause a problem with -S option,
that out_fd will be closed when the file size reaches fsize_max
and new fd will be opened only on percpu_tmpfile.
So, out_fd should be synchronized with percpu_tmpfile.
* runtime/staprun/relay_old.c (open_oldoutfile): Set fd of output file
to out_fd[cpu].
(open_relayfs_files): Ditto.
The general approach is to rip out task_finder_tgt's from all over the
place (including the unwindsym vmcbs, and the stap_uprobe_specs), and
instead have a small handful of them: one for all unwindsyms, and one
per abstract probed process (PID or NAME). These are in turn shared
by all new stap_unwind_specs by index.
Before: probe process("./stap").function("*")
-rw-r--r--. 1 fche users 11775283 2009-09-08 20:26 /var/tmp/fche/systemtap/cache/96/stap_96c0479d674db55ec98d8a8750a790e7_7989596.ko
text data bss dec hex filename
445158 8351944430647213103574 c7f1d6 /var/tmp/fche/systemtap/cache/96/stap_96c0479d674db55ec98d8a8750a790e7_7989596.ko
After: (Note how data shrank, though text gained a bit in const-init-data.)
-rw-r--r--. 1 fche users 4021569 2009-09-08 20:27 /var/tmp/fche/systemtap/cache/e4/stap_e46e88634efd850b1586e81c231c239a_8058419.ko
text data bss dec hex filename 1896511 2192 43248086223511 5ef697 /var/tmp/fche/systemtap/cache/e4/stap_e46e88634efd850b1586e81c231c239a_8058419.ko
task_finder diagnostics: emit start_task_finder dbug message at end of fn.
* task_finder.c (stap_start_task_finder): Emit _stp_dbug message at end
rather at beginning, so printed utrace-engine attach counts reflect
status at end of initialization rather than at beginning.
* runtime/io.c (_stp_vlog): Don't put ansi highlighting into debugging
messages. #if STAP_DEBUG_PRINTK, direct all diagnostics to appropriate
printk channel instead of runtime trace buffer.
Mark Wielaard [Mon, 7 Sep 2009 15:06:27 +0000 (17:06 +0200)]
bz10475.exp: Use filp_open which has a constant const char argument for test.
For some reason the do_filp_open const char *pathname argument has changed
its name between different kernel versions. Luckily filp_open has a cont char
*filename argument that is constant between versions (the test needs a
const char* argument to do an array operation on).
* testsuite/semok/bz10475.stp: Use filp_open instead of do_filp_open.
Save offset of build id relative to _stext instead of absolute
address for kernel and apply relocations at run-time. This fixes
Debian bug #545277 (http://bugs.debian.org/545277).
Dave Brolley [Thu, 3 Sep 2009 21:19:05 +0000 (17:19 -0400)]
Disallow kernel space memory access when unprivileged.
2009-09-03 Dave Brolley <brolley@redhat.com>
* runtime/addr-map.c (lookup_addr_aux): Now takes size argument.
Consider the size when looking for overlapping range with the map
entries.
(lookup_bad_addr): Now takes size argument. Disallow kernel space access
when STP_PRIVILEGED is not defined. Pass size to lookup_addr_aux.
<asm/processor.h>: #include it when STP_PRIVILEGED is not defined.
(add_bad_addr_entry): Supply a size of 1 to calls to lookup_addr_aux.
* runtime/loc2c-runtime.h (kread): Pass sizeof (*(ptr)) to
lookup_bad_addr.
(kwrite): Likewise.
(deref): Pass size to lookup_bad_addr.
(store_deref): Likewise.
Josh Stone [Thu, 3 Sep 2009 18:32:59 +0000 (11:32 -0700)]
PR10573: Squash duplicate inline instances
In C++, identical functions included in multiple CUs will get merged at
link time into a single instance. We need to make sure that inlines
within those merged functions are not probed multiple times.
* tapsets.cxx (inline_instance_info::operator<): Used for set support.
(dwarf_query::handle_query_module): Clear inline_dupes on each module.
(query_dwarf_inline_instance): Squash this inline instance if it's
already in the inline_dupes set.
Josh Stone [Thu, 3 Sep 2009 02:09:50 +0000 (19:09 -0700)]
PR10572: Allow duplicate function names in a CU
We can't assume that a given function name will only appear once in a
CU. In C++, two functions may have the same name in different classes
or namespaces, or even in the same scope with overloaded parameters.
Even in C, the compiler may generate multiple copies of a single
function with different optimizations.
We now use a multimap for function names, so we shouldn't miss any.
* dwflpp.h (cu_type_cache_t, mod_cu_type_cache_t): New typedef to keep a
normal map for the global_alias_cache.
(cu_function_cache_t): Use a multimap for function names.
* dwflpp.cxx (dwflpp::iterate_over_functions): Walk over the range of
exactly-matching functions.
* tapsets.cxx (query_dwarf_func): Don't abort after seeing an exact
match -- there could be more to come.
Josh Stone [Wed, 2 Sep 2009 23:43:58 +0000 (16:43 -0700)]
Provide backward-compatible unordered_map/set
We were defining our own stap_map with a ::type to let us use typedefs
to use the new unordered_map if available, or hash_map otherwise. Since
unordered_map is the future direction, I'm changing our code to use that
directly. The backward-compatible version is a #define to hash_map,
which has a compatible interface.
While I'm at it, let's also define unordered_multimap, unordered_set,
and unordered_multiset.
* unordered.h: New.
* dwflpp.h (stap_map): Removed.
(cache typedefs): Use the unordered name now.
Josh Stone [Wed, 2 Sep 2009 23:14:08 +0000 (16:14 -0700)]
Unify lex_cast* and avoid string copies
We always use lex_cast either to string or from string, so I made that
explicit, and got rid of some string copies in the process. There was
also stringify(), which was redundant to lex_cast<string>.
We also always used lex_cast_hex to string, so that's now hard-coded and
again eliminated a string copy.
For lex_cast_qstring<string>, there's no need to write the streamify the
input, so a specialization now operates directly on the input.
Hopefully this is a bit cleaner, and I do measure it to be a little
faster on scripts with many probes.
Josh Stone [Tue, 1 Sep 2009 16:38:12 +0000 (09:38 -0700)]
PR10581: Use ARCH for tracepoints and kernel typequeries
These are kernel modules that we generate for querying debuginfo, so
they need to use the same ARCH settings that we put in the main script
module.
* buildrun.cxx (make_tracequery, make_typequery_kmod): Add the arch and
kbuild flags to make_cmd.
* hash.cxx (find_stapconf_hash, find_tracequery_hash,
find_typequery_hash): The arch is in the base hash already, but add
the kbuild flags too.
Josh Stone [Mon, 31 Aug 2009 22:22:33 +0000 (15:22 -0700)]
Use a header-cast in nd_syscall.sigaltstack
The nd_syscalls tapset is meant to run with no debuginfo, so using a
@cast into a module type defeats the purpose. We should use a @cast
with a header name instead, so debuginfo is generated.
* tapset/i386/nd_syscalls.stp (nd_syscall.sigaltstack): Get the pt_regs
type definition from "kernel<asm/ptrace.h>".
Mark Wielaard [Sat, 29 Aug 2009 14:49:44 +0000 (16:49 +0200)]
Fix overlapping statement probe error in warnings.stp.
Instead of generating a warning the current kernel.statement probe
produced a warning on some 386 kernels that had optimized that
particular line:
semantic error: multiple addresses for fs/bio.c:282
(try fs/bio.c:278 or fs/bio.c:284)
semantic error: no match while resolving probe point
kernel.statement("bio_init@fs/bio.c+3")
So do as told to just get the expected warnings for this probe.
Josh Stone [Sat, 29 Aug 2009 01:01:51 +0000 (18:01 -0700)]
Cache inline instance lookups
We used to call dwarf_func_inline_instances to get the locations where
inlines are used. This function has to iterate through nearly all DIEs
to find instances, which is a lot of redundant work when we're probing
multiple inline functions.
Now we have our own dwarf iterator to cache all inline instances back to
their origin. This only needs to be called once for each CU, and all
further inlines are just a map lookup. Some quick benchmarks:
stap -l Before After
kernel.function("*") 25010ms 2110ms
module("*").function("*") 86550ms 16920ms
process("stap").function("*") 41330ms 580ms
* dwflpp.cxx (dwflpp::cu_inl_function_caching_callback): Removed.
(dwflpp::cache_inline_instances): New caching iterator.
(dwflpp::iterate_over_inline_instances): Cache each CU once.
Dave Brolley [Fri, 28 Aug 2009 20:47:20 +0000 (16:47 -0400)]
stap-client will now always choose a compatible server even for phases 1-3.
Always start a local server needed by the test suite (make {install}check).
David Smith [Fri, 28 Aug 2009 18:59:27 +0000 (13:59 -0500)]
Added test for pr10568.
* testsuite/systemtap.base/alias_tapset.exp: New file.
* testsuite/systemtap.base/alias_tapset.stp: Ditto.
* testsuite/systemtap.base/alias_tapset/tapset_test.stp: Ditto.
Josh Stone [Thu, 27 Aug 2009 22:43:51 +0000 (15:43 -0700)]
PR10568: Ensure that aliases pull in their tapset
When a probe alias is resolved in a tapset, the contents of that tapset
should be included in the compiled script, just as we do for global
variables and functions.
* elaborate.cxx (alias_expansion_builder::build): When an alias is
instantiated, add its stapfile to the session files.
* testsuite/systemtap.base/tapset_includes.exp: New test.
* testsuite/systemtap.base/tapset/*.stp: Testing tapsets for above.
Josh Stone [Thu, 27 Aug 2009 03:09:48 +0000 (20:09 -0700)]
Reorganize iterate_over_labels
I noticed that iterate_over_labels was using a static variable as a
recursion variable, which isn't a safe thing to do since it will only be
initialized once. While fixing that, I also reorganized the function
quite a bit.
* dwflpp.cxx (dwflpp::iterate_over_labels): Take the current function as
a parameter instead of using a static local. Rewrite some of the code
as well to try to make it more obvious.
* tapsets.cxx (add_label_name): Remove in favor of query_label.
(query_label): New, to check decl_file and fix probe listing.
(query_srcfile_label, query_cu): Adjust to iterate_over_labels change
and start using query_label as the callback.
Josh Stone [Thu, 27 Aug 2009 00:35:54 +0000 (17:35 -0700)]
Remove unnecessary static members
When a static class member is only used by a single method, it's more
concise to use a static local variable instead.
* staptree.cxx (probe::probe): Make last_probeidx a static local.
* tapset-perfmon.cxx (perfmon_derived_probe::perfmon_derived_probe):
Make probes_allocated a static local.
Josh Stone [Thu, 27 Aug 2009 00:05:29 +0000 (17:05 -0700)]
Cleanup some deref handling in the task tapset
Some of this is just cosmetic, but there is one big takeaway: there's a
error-goto between kread calls and the CATCH_DEREF_FAULT. You must not
allow this to bypass any resource management, like unlocking a resource
that you grabbed!
* tapset/task.stp (pid2task): No derefs, so remove the CATCH.
(task_gid, task_egid, task_uid, task_euid): Move the CATCH within the
#ifdef branch that actually needs it.
(task_open_file_handles, task_max_file_handles): Ensure that we always
call rcu_read_unlock if we locked it!
Josh Stone [Wed, 26 Aug 2009 01:53:40 +0000 (18:53 -0700)]
Compute cu_name dynamically
We only need cu_name for errors and verbose messages, so it's a waste to
always construct it in focus_on_cu. It's now built only as-needed.
* dwflpp.cxx (dwflpp::cu_name): Now a method instead of a data member.
(dwflpp::focus_on_module): No cu_name to clear now.
(dwflpp::focus_on_cu): No cu_name to set now.
(dwflpp::declaration_resolve): Adjust to call cu_name() now.
(dwflpp::iterate_over_functions): Ditto.
* tapsets.cxx (query_cu): Ditto.
Josh Stone [Wed, 26 Aug 2009 01:20:39 +0000 (18:20 -0700)]
Avoid needless Dwarf_Die copying
* dwflpp.cxx (dwflpp::iterate_over_cus): Use the Dwarf_Die as a
pointer directly into the vector.
(dwflpp::iterate_over_inline_instances): Ditto.
(dwflpp::iterate_over_functions): Ditto in a map.