Josh Stone [Wed, 25 Nov 2015 22:10:17 +0000 (14:10 -0800)]
Remove functioncall::var_assigned_to_retval
It's unusual to have a value specific to one visitor stored in the tree
node itself. This particular value is only used by c_unparser. Make it
a c_unparser member instead, saved and restored as necessary to allow
for nested calls.
Josh Stone [Wed, 25 Nov 2015 01:12:35 +0000 (17:12 -0800)]
PR18884: skip tmps for any literal, not by tok->type
Some literal expressions get created dynamically, like const-folding an
expression of two literals. Those will probably not have a tok->type
that looks like a literal, but they're still reasonable candidates to
skip temporary storage and output directly into C.
Add a new c_assign for any tmpvar=expression, which will check for
literals to override the tmp, or else assign them as normal. Literals
are detected with a dynamic_cast of the expression, without looking at
the token at all. In many places that were roughly doing this based on
tok->type, use the new c_assign to handle it automatically.
The new test transok/literal_tmp.stp compares the PR18884 examples,
asserting that they now have *exactly* the same generated code.
Josh Stone [Tue, 24 Nov 2015 22:55:56 +0000 (14:55 -0800)]
Restrict optimization of literals in "%s\n" to streams only
This "use_print" optimization is only effective for printing to streams
with _stp_print(). Then a literal string argument to "%s\n" can just
have that literal token-pasted with the newline string. But when
printing to strings, like sprintln, that optimization isn't actually
taken, so it was getting the newline twice.
Add new tests with sprint and sprintln on string literals, then clean up
the code that does the optimization -- for streams only.
William Cohen [Tue, 24 Nov 2015 01:22:26 +0000 (20:22 -0500)]
Eliminate the use of tex(nomencl.sty) in TeX documentation files
RHEL 7 does not package the nomencl.sty file and having this style
file used in systemtap makes it difficult to build the documentation.
The only place it was being used was in the tutorial.tex and it was
not generating a useful glossary. The glossary generation of
tutorial.tex has been disabled for the time being.
Felix Lu [Mon, 23 Nov 2015 18:53:26 +0000 (13:53 -0500)]
Fix monitor mode to be compatible with the private global feature.
The synthetic functions and variables did not have a __global_
prefix, causing the symbol resolution to fail at finding them.
Commit 0c7e069fe82 assumes that there is a token for every probe
while two synthetic probes are generated in monitor mode with
null context. parse_synthetic_probe uses "<synthetic>" again
if no token is found for the probe. The __global_ prefix is shown
in monitor mode where global variables are shown so they needed
to be unmangled as done in commit 8f54215ef850c809.
* elaborate.cxx: above changes
* parse.cxx: fall back to "<synthetic>" if token is nullptr
* staprun/monitor.c: use return values of function calls
* staptree.cxx: check for token nullptr in functiondecl::printsig
The pipe used in monitor mode was not being read the moment
data was available, causing an overflow. pselect now watches
the pipe fd for data to read. The UI now cuts off the probe name
if terminal size is not wide enough.
Felix Lu [Mon, 16 Nov 2015 16:40:36 +0000 (11:40 -0500)]
PR18848: Fix json parsing error
Quotes in the probe names for the json string were not escaped to
form a valid json object. They had to be escaped once for the
systemtap parser and once more for the json parser.
* elaborate.cxx: escape quotes twice when generating json string
* staprun/monitor.c: check for correct parse result
Felix Lu [Mon, 9 Nov 2015 16:00:48 +0000 (11:00 -0500)]
PR18848: add module output scrollback, status window now refreshed
on input
Users can now use the u and d keys to scroll back and forward through
the output. The scrollback uses a moving window approach over a queue.
The status window is now updated upon input for a smoother experience.
Felix Lu [Wed, 28 Oct 2015 18:44:35 +0000 (14:44 -0400)]
PR18848: add most functionality to curses interface
Currently, a file is used to redirect stp_print output to curses window.
Previous curses interface code in mainloop got refactored into monitor.c.
* runtime/monitor.c: New file. procfs functions for stp_print redirection
* runtime/print_flush.c: Redirect stp_print to curses interface in
monitor mode
* staprun/monitor.c: New file implementing curses interface
* staprun/mainloop.c: Move code into monitor.c
* staprun/Makefile.*: Link json-c and curses library, include monitor.c
to source list
* translate.cxx: Create procfs file for stp_print redirection
Felix Lu [Thu, 15 Oct 2015 18:51:24 +0000 (14:51 -0400)]
PR18848: new command line argument -M for staprun
Pass stap --monitor command to staprun.
* buildrun.cxx: add -M argument to flags
* staprun/common.c: -M option to parse_args
* staprun/mainloop.c: add a timeout to pselect in monitor mode
to prevent blocking and allow the procfs monitor interface to
be polled.
* staprun/staprun.h: monitor extern declaration
Felix Lu [Wed, 7 Oct 2015 15:33:59 +0000 (11:33 -0400)]
PR18848: use jiffies tapset function
Switch the implementation of uptime to use the jiffies and hz tapset
functions instead of using embedded C
* elaborate.cxx: remove old embedded C function to get uptime. Added
a synthetic begin probe to obtain starting time. Synthetic variables
are now hidden in monitor mode and not reset.
* translate.cxx: remove jiffies inclusion in monitor mode.
Felix Lu [Tue, 6 Oct 2015 20:15:07 +0000 (16:15 -0400)]
PR18848: new procfs monitor mode option
Presents a procfs read interface to obtain data about the running
script and another procfs write interface to control the script
* cmdline.cxx: new "monitor" option
* cmdline.h: new field in enum
* elaborate.cxx: new functions monitor_mode_read and monitor_mode_write
synthesizes procfs probes for the interfaces
* session.cxx: new monitor flag
* session.h: new monitor flag
* translate.cxx: extra code is generated to provide statistics for
monitor mode, function emission is delayed to allow stap_probes to
be first defined
Martin Cermak [Fri, 20 Nov 2015 11:22:05 +0000 (12:22 +0100)]
Update the PR19241 fix so that 'out_fd' gets correctly handled.
This is an update to commit d879410b. Before this update, stap
in "stream mode" was using invalid output file descriptor per
https://sourceware.org/bugzilla/show_bug.cgi?id=19241#c2.
Martin Cermak [Fri, 20 Nov 2015 10:00:30 +0000 (11:00 +0100)]
Allow buildok/{rpc-all-probes,rpc-detailed} to access private var.
Tests buildok/rpc-all-probes.stp and buildok/rpc-detailed.stp are
examining '@__private30 global __rpc_create_args' array. That can
only be accessed using '--compatible=2.9' by the test script.
This approach to testing private stuff will probably need to change
in the future. For now, this update aligns buildok/{rpc-all-probes,\
rpc-detailed}.stp to other buildok tests examining private variables
or functions.
Josh Stone [Fri, 20 Nov 2015 02:01:20 +0000 (18:01 -0800)]
Remove the last visitors from c_tmpcounter
Now c_tmpcounter doesn't doesn't have any duplicated visitors at all.
It only overrides a few key virtual methods in c_unparser to get the
functionality it needs.
Josh Stone [Fri, 20 Nov 2015 00:25:22 +0000 (16:25 -0800)]
Subclass c_tmpcounter directly from c_unparser
The c_tmpcounter is meant to be a shadow of c_unparser, walking the same
walk to declare the temps that c_unparser will need. But this was done
manually in a fragile balancing act, with a lot of duplicated logic and
little to ensure it was correct unless it failed to compile at all.
Now c_tmpcounter is a subclass of c_unparser so it can be a real shadow,
truly walking the same walk via the exact same code. The normal output
is just dumped into a nulled ostream for this pass. When a var is
accessed the first time through its value(), c_tmpcounter writes its
declaration to the real ostream. A var that's created but not used will
be left out automatically, like a tmpvar that gets an override().
William Cohen [Thu, 19 Nov 2015 22:05:12 +0000 (17:05 -0500)]
Avoid using the nomencl compatible option
Some versions of nomencl such as the one on RHEL 5 are missing the
compatible option. Thus, tutorial.tex should avoid using it so the
documentation can be built.
David Smith [Thu, 19 Nov 2015 18:38:09 +0000 (12:38 -0600)]
Improve kmodule.exp by adding tests that load the module after stap.
* testsuite/systemtap.base/kmodule.exp: Add subtests that see if the same
scripts work if the module is loaded after the systemtap module is
loaded. This currently fails for non-dwarf kprobe probes (PR19216).
David Smith [Wed, 18 Nov 2015 19:03:44 +0000 (13:03 -0600)]
Refix PR18889 by switching to symbol_name+offset module probing.
* tapsets.cxx: Add symbol_name+offset support for dwarf kprobes present in
modules. This is somewhat based on work by James Bottomley from the
following email:
<https://sourceware.org/ml/systemtap/2008-q3/msg00182.html>
* runtime/transport/symbols.c (_stp_module_notifier): On kernel's >= 3.16,
use symbol_name+offset probing for modules.
* runtime/linux/kprobes.c: Switch to using symbol_name+offset probing for
modules.
David Smith [Wed, 18 Nov 2015 18:53:33 +0000 (12:53 -0600)]
Revert "PR18889 part: module-init notification via module_{load,free} tracepoints"
This reverts commit 2278079efc01124dd509241f6c6eadbd6e19cb2a. This code
will be replaced with a new method for handling probes in kernel module's
init sections.
David Smith [Wed, 18 Nov 2015 18:52:08 +0000 (12:52 -0600)]
Revert "PR18889: switch to STP_TRACEPOINT* frontend for kernel tracepoint registration"
This reverts commit 2e67c14dad1c661d2ce0b0ed218b371c1af218ba. This code
will be replaced with a different method for handling probes in kernel
module's init sections.
Martin Cermak [Wed, 18 Nov 2015 10:00:07 +0000 (11:00 +0100)]
Make the "shebang trick" work for RPM packaged testcases.
Some testcases use the "shebang trick" described in stap_run_batch()
testsuite function. Commit d2995e6f breaks this for RPM packaged
testcases by putting the absolute path to stap into the shebang.
This update reverts cb69017 update to stap_run_batch() and fixes the
specfile shebang rewriter instead, so that it only applies to
systemtap examples contained in the systemtap-client package, where
the "shebang trick" is unwelcome. With this update, testcases
contained in the systemtap-testsuite RPM remain unchanged, so that
the "shebang trick" works for them.
Josh Stone [Tue, 17 Nov 2015 23:31:00 +0000 (15:31 -0800)]
Compact print_format and its format_component
The delimiter doesn't need to be a full component -- just a simple
interned_string will do. The format_component can compact its flags and
enum fields down to a single byte each, taking it from 48 bytes on
x86_64 to just 32 bytes.
Josh Stone [Tue, 17 Nov 2015 02:29:51 +0000 (18:29 -0800)]
Store tok_junk messages as an additional enum
There's a limited corpus of messages for tok_junk to use. Rather than
wasting space for an empty string on every single token, which takes 32
bytes on Fedora 23 x86_64, we can store just an int-sized enum and
produce a string message from this.
This reduces struct token from 80 bytes to 48, saving 20% memory overall
when parsing large tapsets like qemu's.
Josh Stone [Tue, 17 Nov 2015 01:58:13 +0000 (17:58 -0800)]
Drop the string name from struct probe
The name is only used occasionally, so saving the string is wasting
space. It's simply "probe_"+index, so let's store the index as an
identifier, and generate the name on the fly. This saves noticeable
time and space when parsing large tapsets like qemu's.
Josh Stone [Tue, 17 Nov 2015 00:05:58 +0000 (16:05 -0800)]
Move trivial interned_string conversions into the header
This doesn't actually change much in performance, as they still have to
call the proper intern() function, but it does make backtraces from
intern() a little more direct to the source.
Need to increase --rlimit-cpu, since especially certain buildok
tests seem to reach the old value easily. It turns out that not
only "32-bit arm machines are quite slow", so not distinguishing
the machine type any more and just raising the treshold:
The goal is to raise the limit for low cost. Note that the
"-E 'probe timer.s(900) ...'' limit affects the generated source
that some testcases rely on verbatimely. So setting --rlimit-cpu
just slightly under 15 mins should improve test results without
need to modify those testcases source.
The stap_run_batch() update is needed to deal properly with RPM
packaged testcases, which have slightly modified source code
compared to their git versions due to commit d2995e6f. This update
is an addition to commit 6b131ba7 making it work with RPM packaged
testcases too.
Martin Cermak [Sat, 14 Nov 2015 18:17:27 +0000 (19:17 +0100)]
Terminate parsing on duplicate variable or function declaration.
This fixes condition that makes the parser stop on attempt to
declare duplicate global variable or function. It also (newly)
makes the parser terminate on global versus private variable or
function declaration attempt.
This update makes parseko/eleven.stp and parseko/twelve.stp
expectedly fail. It also adds parseko/private0[12].stp that
expectedly fail on attempt do declare conflicting global versus
private variable or function.
Josh Stone [Sat, 14 Nov 2015 02:15:40 +0000 (18:15 -0800)]
Construct print_format::print_format_string with an intern
Since it's ending up as an interned_string, it's best to construct it as
such to pass through sharing from any source. Now print_format::create
can pass through its t->content directly for this.
Josh Stone [Sat, 14 Nov 2015 02:12:51 +0000 (18:12 -0800)]
Take a plain string for print_format::string_to_components
This is mostly called with print_format::raw_components, which is a string,
and an interned value isn't needed for sharing within, so avoid it.
It might be nicer to make raw_components an interned_string itself, but a
few places in tapsets.cxx are building that string incrementally, so they'd
need a bit of refactoring to use separate string buffers first.
Josh Stone [Sat, 14 Nov 2015 01:49:04 +0000 (17:49 -0800)]
Add special treatment for single-char string interns
A large number of interned strings are just one character, mostly from
lexer tokens that aren't really sharing substrings yet. Add a small
chartable to provide static memory for any given char to turn into a
string_ref(&c, 1).
Martin Cermak [Fri, 13 Nov 2015 15:21:15 +0000 (16:21 +0100)]
Fix PR19241 by scanning for available CPUs.
Per PR19241/rhbz1280321, staprun was failing to start when CPU0
was offline or offline. In bulk mode, staprun was failing if
any CPU but the last one was offline. This patch fixes it by
scanning for available online CPUS up to NR_CPUS.
Martin Cermak [Fri, 13 Nov 2015 13:10:36 +0000 (14:10 +0100)]
Update user_string_n2_quoted() so that semok/context-globals.stp is happy.
Rename the local 'str' variable within user_string_n2_quoted() to '__str'
so that it doesn't collide with global variable of the same name defined
in the semok/context-globals.stp testcase.
For the most part, c_str() is just used for "%s" in warnings, errors,
and debug messages. We can afford to pay the cost of to_string() there,
while allowing string_ref to share memory the rest of the time.
NB: when using `to_string().c_str()`, it's important not to let that
pointer outlive the string temporary! It's good only for the range of
its full expression; if you need it longer, bind the string to a local
reference first.
Martin Cermak [Wed, 11 Nov 2015 09:23:16 +0000 (10:23 +0100)]
Fix synthetic probes generation for written and unread private globals.
Mangling a private global happens based on the name of the file where the
variable got defined. Stap automatically prints written and unread globals
and private globals at the end of the session. For autogeneration purposes
of respective derived synthetic probes, we need to keep track of the file
where given variable got defined.
Josh Stone [Wed, 11 Nov 2015 02:03:08 +0000 (18:03 -0800)]
Avoid undefined behavior in get_number_param
An uninitialized assignment led the compiler to assume it must be
initialized after all, which led to an optimization reversing the
conditions of an '&&'. This triggered valgrind when the condition
actually was uninitialized after all. See GCC PR68281.
Ditch the long and long long get_number_param for just int64_t, which is
just a pass-through to get_param. A few fields are now int64_t to
match, so they can never truncate input values on 32-bit systems. The
other Dwarf_Addr get_number_param is now careful to only copy good
values from get_param.
Just to be paranoid, all base_query and dwarf_query POD members are now
zeroed in the initializer lists, even when the constructor will set a
better value right away.
Martin Cermak [Tue, 10 Nov 2015 07:32:05 +0000 (08:32 +0100)]
Mark selected internal tapset global vars as '@__private30'.
Mark tapset global vars, that are only intended to be used
internally within given tapset, as '@__private30'. This
restriction appears to have no imparct from the testsuite
perspective. However, it's still possible that some user
script may rely on one of those. This restriction can be
worked around using 'stap --compatible=2.9' setting.
Martin Cermak [Sat, 7 Nov 2015 14:43:29 +0000 (09:43 -0500)]
Mark internal tapset functions as '@__private30' where possible.
Add '@__private30' macro that gives 'private' keyword for compatibility
mode 3.0 and higher. Mark internal tapset functions as private using
it where possible. Testcases examining private tapset functions must
now use the --compatible=2.9 option.
Martin Cermak [Thu, 5 Nov 2015 20:50:55 +0000 (15:50 -0500)]
Prefix global functions in the generated code.
Add '__global_' prefix to global functions in the generated code.
Treat selected internal synthetic functions as private.
Fix using a private function in user script and test-cover it.
* elaborate.cxx: Correctly match global function names to respective
functiondecls. Match synthetic private functions coming from
tapset-procfs.cxx (*_procfs_value_*), and tapsets.cxx
(_sdt_arg_get_addr_) to respective functiondecls.
* main.cxx: Update the --dump-functions feature to correctly deal with
new internal function names.
* parse.cxx: Add the "__global_" prefix to global functions in the
generated code.
* staptree.cxx: Update functiondecl::printsig() so that it outputs
unmangled function name.
* tapset-procfs.cxx: Treat internal synthetic functions
'*_procfs_value_get*', '*_procfs_value_set*', '*_procfs_value_append*'
as private.
* tapsets.cxx: Treat internal synthetic functions '*_sdt_arg_get_addr_*'
as private.
* optim_arridx.exp: Adapt the testcase to new naming.
* private.exp: Add subtest examining use of a private function in
user script.