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.
Josh Stone [Wed, 26 Aug 2009 00:23:28 +0000 (17:23 -0700)]
Index cu_inl_function_cache_t by function->addr
Again, avoid needless string construction for map indexing.
* dwflpp.h (cu_inl_function_cache_t): Index by the void* function->addr.
* dwflpp.cxx (dwflpp::iterate_over_inline_instances): Index
cu_inl_function_cache by function->addr.
Josh Stone [Tue, 25 Aug 2009 23:58:20 +0000 (16:58 -0700)]
Index mod_cu_function_cache_t by cu->addr
Rather than constructing a "module:cu" string all the time, we can just
index the cache by the cu die's addr field. The addr will never change
as long as the Dwarf object is still alive.
This has a quite noticeable performance impact for scripts that iterate
over lots of cus (like for syscall.*).
* dwflpp.h (stap_map): Allow void* keys too.
(mod_cu_function_cache_t): Index by the void* cu->addr.
* dwflpp.cxx (dwflpp::iterate_over_functions): Index cu_function_cache
by addr, and build the verbose strings manually when needed.
(dwflpp::declaration_resolve): Index global_alias_cache by addr.
Josh Stone [Tue, 25 Aug 2009 00:54:40 +0000 (17:54 -0700)]
PR2475: Filter filenames against the decl_file
We used to only check that a CU contains at least one srcfile matching
the user's file spec. This patch ensures that the selected function was
actually defined in one of the matching srcfiles.
* tapsets.cxx (struct dwarf_query): Make filtered_srcfiles carry
strings, so we can easily lookup matches later.
(query_dwarf_func): Check that the decl_file is in filtered_srcfiles.
(query_cu): Adjust to using set<string>.
* dwflpp.cxx (dwflpp::collect_srcfiles_matching): Take a set<string>.
Mark Wielaard [Mon, 24 Aug 2009 15:09:29 +0000 (17:09 +0200)]
Fix failing uprobes.exp -p5 failures by removing trailing spaces in $$ vars.
* tapsets.cxx (dwarf_var_expanding_visitor::visit_target_symbol_context):
Don't add extra space at end of list, only add space between symbols.
* testsuite/systemtap.base/uprobes.exp: Use more specific expect regex.
* testsuite/systemtap.base/vars.exp: Don't just chop off last char of printf
output string.
Frank Ch. Eigler [Mon, 24 Aug 2009 14:34:45 +0000 (10:34 -0400)]
PR4186: cross-architecture probe building
* main.cxx (main): Add 'a:' and 'B:' options.
* session.h (kbuildflags): New place to store -B args.
* testsuite/systemtap.base/cmd_parse.exp: Test them lightly.
* buildrun.cxx (run_make_cmd): Use "--no-print-directory"
rather than ">/dev/null" in kbuild invocations. Pass
'-a' and '-B' flags along.
* hash.cxx (find_script_hash): Add them.
* NEWS, stap.1.in: Mention this.
Mark Wielaard [Mon, 24 Aug 2009 13:07:19 +0000 (15:07 +0200)]
Initialize sdt_types testcase arr_char so that it is always null terminated.
* testsuite/systemtap.base/sdt_types.c: Initialize char arr_char [], not
with (too small) constant length, to make sure the string is always
null terminated.
Josh Stone [Sat, 22 Aug 2009 02:16:18 +0000 (19:16 -0700)]
PR10461: Add support for C++ classes and references
* dwarf_wrappers.cxx (dwarf_type_name): Name class and reference types.
* dwflpp.cxx (dwflpp::iterate_over_globals): Capture class names.
(dwflpp::print_members): Permit classes, and dig into inheritance.
(dwflpp::find_struct_member): Ditto.
(dwflpp::translate_components): Handle classes and references.
(dwflpp::translate_final_fetch_or_store): Ditto.
* loc2c.c (c_translate_pointer): Treat references as simple pointers.
Frank Ch. Eigler [Fri, 21 Aug 2009 21:16:13 +0000 (17:16 -0400)]
PR10507: tweak MAXUPROBES calculation to shrink table for small static number of probes
* tapsets.cxx (uprobe_derived_probe_group::emit_module_decls): Use
geometric mean rather than arithmetic mean. Add a comment to explain
relative harmlessness of exceeding the "minimum" or "maximum" values.
Mark Wielaard [Thu, 20 Aug 2009 14:31:55 +0000 (16:31 +0200)]
PR10537 process().function().label() should select multiple inlined instances.
This is less useful than one would hope. gcc will often emit a label with
a DW_AT_low_pc that is not really in the neighbourhood of where one would
expect it when the label is inlined and gcc can proof the label isn't really
used in the optimized code. dwflpp::iterate_over_labels will now really
iterate recursively through the die, even for dies without a name (like
lexical blocks). This means we should now always find the concrete inlined
label instances that have a real DW_AT_low_pc and so we don't need the trick
to use the line table to get at the actual address.
* dwflpp.cxx (iterate_over_labels): Accept dies without a name. Don't handle
labels without a name or without a lowpc attribute.
* testsuite/systemtap.base/inlinedvars.c (m): Trick gcc into thinking label
is always used.
(call, call2): Activate.
(main): Call call and call2.
* testsuite/systemtap.base/inlinedvars.exp: New result_string.
Test both unoptimized and optimized (inlined) builds.
Josh Stone [Thu, 20 Aug 2009 01:19:53 +0000 (18:19 -0700)]
PR10538: Give a file:line hint for anonymous types
When we list the possible members for an anonymous struct/union, the
user may want to go look at the source for the type. That's hard
without a type name, so we now list the decl file:line for them.
* dwflpp.cxx (dwflpp::translate_components): List file:line for anon.
Josh Stone [Thu, 20 Aug 2009 00:27:18 +0000 (17:27 -0700)]
Create a dwarf_attr_die idiom
We commonly do a dwarf_attr_integrate followed by dwarf_formref_die,
with no care for the Dwarf_Attribute, so I captured that idiom in an
inline function.
Josh Stone [Thu, 20 Aug 2009 00:07:30 +0000 (17:07 -0700)]
Use dwarf_diename instead of a DW_AT_name lookup
We should always use the canonical dwarf_diename. The code being
replaced here wasn't even using dwarf_attr_integrate, so it may have
been missing the accessibility of some names.
* dwflpp.cxx (dwflpp::iterate_over_labels): Use dwarf_diename.
Josh Stone [Wed, 19 Aug 2009 23:48:53 +0000 (16:48 -0700)]
Use dwarf_type_name in more places
* dwarf_wrappers.cxx (dwarf_type_name): Moved here from tapsets.cxx, and
added a variant that returns a string for easier ostreaming.
* dwflpp.cxx (dwflpp::print_members): Use dwarf_type_name for errors.
(dwflpp::find_struct_member): Ditto.
(dwflpp::translate_components): Ditto.
(dwflpp::translate_final_fetch_or_store): Ditto.
(dwflpp::literal_stmt_for_pointer): Ditto.
* tapsets.cxx (dwarf_derived_probe::saveargs): Pass die to
dwarf_type_name by pointer instead of reference.
(uprobe_derived_probe::saveargs): Ditto.
(resolve_tracepoint_arg_type): Ditto.
David Smith [Wed, 19 Aug 2009 21:01:45 +0000 (16:01 -0500)]
Updated with latest code.
* runtime/transport/ring_buffer.c (_stp_ring_buffer_disable_cpu): New
function.
(_stp_ring_buffer_enable_cpu): Ditto.
(_stp_ring_buffer_cpu_disabled): Ditto.
(_stp_ring_buffer_empty_cpu): Only checks online cpus (instead of all
possible cpus).
(_stp_find_next_event): Ditto.
(_stp_ring_buffer_iterator_increment): Calls
_stp_ring_buffer_disable_cpu()/_stp_ring_buffer_enable_cpu() around
ring_buffer_* calls.
(_stp_ring_buffer_consume): Ditto.
(_stp_peek_next_event): Ditto.
(_stp_buffer_iter_finish): New function.
(_stp_buffer_iter_start): Ditto.
(_stp_data_read_trace): Uses
_stp_buffer_iter_start()/_stp_buffer_iter_finish().
(_stp_data_write_reserve): Checks to see if the cpu is disabled (with
_stp_ring_buffer_cpu_disabled() before reserving memory. Uses
_stp_buffer_iter_start()/_stp_buffer_iter_finish().
(_stp_transport_data_fs_init): Initializes buffer iterators.
Josh Stone [Wed, 19 Aug 2009 20:30:31 +0000 (13:30 -0700)]
PR10538: Improve location lookup for unions
We had a bug that the starting call to find_struct_member used the same
memory for the parentdie and the resulting member. If parentdie is a
union, then the first member probably won't have a location, and we
actually assert that it must be a union. Since we wrote the result in
the same memory, we lost the real info about the parent, and so the
assertion failed.
* dwflpp.cxx (dwflpp::translate_components): Use distinct memory for the
parent and resulting member in the call to find_struct_member.
(dwflpp::find_struct_member): Remove the needless parentdie copy.
Stan Cox [Wed, 19 Aug 2009 20:11:09 +0000 (16:11 -0400)]
* testsuite/systemtap.base/postgres.exp: New test for checking sdt
marker support as used by postgres. Currently assumes, and
verifies, that postgres is installed in /usr/local
Frank Ch. Eigler [Wed, 19 Aug 2009 16:18:48 +0000 (12:18 -0400)]
PR10228: fix non-utrace building regression
* translate.cxx (dump_unwindsyms): Decide based on modname[] not
mainfile[] to emit a vmcb.
* runtime/task_finder.c (non-UTRACE): Include dummy stap_{start,stop}_*
functions.
Mark Wielaard [Tue, 18 Aug 2009 20:01:53 +0000 (22:01 +0200)]
Add testcase for PR10533 (inlined vars) and 10537 (inlined labels - disabled)
Partial testcase for PR10533 (inlined vars) and 10537 (inlined labels)
currently we cannot use the full testcase since stap doesn't support
probing multiple instances of inlined labels.
* testsuite/systemtap.base/inlinedvars.exp: New file.
* testsuite/systemtap.base/inlinedvars.stp: Likewise.
* testsuite/systemtap.base/inlinedvars.c: Likewise.
Mark Wielaard [Tue, 18 Aug 2009 19:54:54 +0000 (21:54 +0200)]
PR10533 inlined vars are not always found (dwflpp).
dwflpp::find_variable_and_frame_base switched too early to "pyshical view"
of die tree. We need to lookup the var in the "syntactical view" of the die
tree first. Then when we see a DW_TAG_inlined_subroutine while walking the
syntactical die tree as returned by dwarf_getscopes for a given variable
to retrieve the frame base, then we need to switch to walking the physical
die tree where the subroutine is inlined.
* dwflpp.cxx (find_variable_and_frame_base): Don't immediately go to
die_scopes, but lookup var first based on pc. Then switch "die branches"
when searching for frame base and a DW_TAG_inlined_subroutine is
encountered.
Frank Ch. Eigler [Tue, 18 Aug 2009 19:52:02 +0000 (15:52 -0400)]
PR10518: context shrinkage with function recursion analysis feeding MAXNESTING
* translate.cxx (emit_common_header, translate_pass): Use new
recursion_info visitor to calculate appropriate MAXNESTING value for
scripts with or without recursion.
* tapsets.cxx (common_probe_entryfn_prologue): Initialize c->nesting = -1.
* stap.1.in: Clarify MAXNESTING value.
Josh Stone [Tue, 18 Aug 2009 17:54:11 +0000 (10:54 -0700)]
Adapt tracepoints to the new probe_locals union
* tapsets.cxx (tracepoint_derived_probe_group::emit_module_decls): Use
probe_locals to set the tracepoint arguments for the probe.
* testsuite/systemtap.base/tracepoints.exp: Include the arguments in the
pass-4 tracepoint test.
Mark Wielaard [Tue, 18 Aug 2009 13:50:40 +0000 (15:50 +0200)]
PR10533 loc2c doesn't resolve frame base correctly for inlined vars.
When we see a DW_TAG_inlined_subroutine while walking the syntactical
die tree as returned by dwarf_getscopes for a given variable to retrieve
the frame base, then we need to switch to walking the physical die tree
where the subroutine is inlined.
* loc2c-test.c (handle_variable): Switch "die branches" when searching
for frame base and a DW_TAG_inlined_subroutine is encountered.
David Smith [Mon, 17 Aug 2009 17:27:15 +0000 (12:27 -0500)]
Unlocks global variables, then calls _stp_print_flush().
* translate.cxx (c_unparser::emit_probe): Unlocks global variables, then
calls _stp_print_flush() (instead of the other way around).
Josh Stone [Sat, 15 Aug 2009 00:56:46 +0000 (17:56 -0700)]
Cache failed tracepoint headers too
Rather than re-attempting a tracepoint header that fails to compile, we
now save an empty file into the cache to indicate "nothing to see here."
See also PR10424.
* tapsets.cxx (tracepoint_builder::get_tracequery_module): Use /dev/null
as the empty result file if make_tracequery fails.
(tracepoint_builder::init_dw): Ignore empty tracequery modules.
Josh Stone [Wed, 12 Aug 2009 00:01:35 +0000 (17:01 -0700)]
PR10461: Probe identical functions only once
In C++ especially, a function definition in a header may be compiled
into multiple CUs, but the linker will merge those into a single output
function. We don't want to place multiple probes on the same function.
The dupe-detection from the alias code (commit 1c6b77e5) already tracks
identical functions within a CU, so I've just lifted this to instead
track function entrypcs at the module level.
* dwflpp.cxx (dwflpp::iterate_over_functions): Remove dupe checks.
* tapsets.cxx (dwarf_query): Add alias_dupes set to the query.
(dwarf_query::handle_query_module): Reset the dupes for each module.
(query_dwarf_func): Check that we only probe each entrypc once.