full-trace.sh: fix regexp in remove-spurious-uprobes()

The full-trace.sh script uses a regexp to identify uprobe events
in the ftrace output. The regexp, however, did not correctly match
uprobe events for two reasons: 1) it had extra spaces; 2) it checked
only for C-styled comments, which are also present in some ordinary
ftrace events. This patch fixes the issues by using a better regexp
and removing the extra spaces.

Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Reviewed-by: Serena Ziviani <senseriumi@gmail.com>
full-trace.sh: fix regexps in add-userspace-functions-duration()

The full-trace.sh script uses regexps to identify entry and exit
points for userspace functions. Unfortunately, both the regexps had
extra spaces and never matched. This patch fixes the issue.

Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Reviewed-by: Serena Ziviani <senseriumi@gmail.com>
wrapper.c: fix some small issues

This patch attempts to fix some small issues in the wrapper program.
* The initial check on the number of arguments has been fixed to
  return when the wrapper executable has been given less than two
  command-line arguments (the first always exists, as argv[0] is
  the executable name).
* About the write() system call used in the program:
  - the type of the return value has been modified to be ssize_t;
  - the type of the second parameter been modified to be void *;
  - the type of the third parameter has been modified to be size_t.
* The perror() function is used to print error messages.
* A die() function has been introduced to allow the process to
  cleanly exit when a write error is encountered (which means that
  a file is currently open and must be closed before exiting).

Reported-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: clear set_ftrace_pid tunable in ftrace_off()

The full-trace.sh script does not clear the PID filter of the ftrace
subsystem before exiting. This does not result in any error of the
fulltrace utility, as the filter is always cleared and re-set when
a trace is started, but it may give issues if someone uses the ftrace
subsystem for other purposes after running fulltrace. This patch
lets the ftrace_off() function clear the PID filter.

Reported-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: check if given executable exists

The full-trace.sh script uses the which command to determine the
full path of the executable that must be traced. However, it does
not perform any check on the existence of such an executable.
This may result in an erratic behavior of the script and in non
explicative errors. This patch attempts to fix the issue by checking
whether the which command actually finds the given executable and
printing the usage of the full-trace.sh script instead of an error
message of the which command.

Reported-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
wrapper.c: enable traces only after setting PID filter

Currently, the full-trace.sh script enables tracing before the
wrapper executable has any chance of setting the PID filter. This
results in a brief tracing window where any event from any process
will be traced. This patch lets wrapper.c decide when tracing should
be enabled. This also removes from full-trace.sh the lines that
enable the ftrace subsystem.

Reported-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: move the prompt for password after the initial checks

This patch attempts to reduce the number of cases in which a password
request is done right before a program failure.
This is done by moving "sudo -v" command from before to after the check
on the existence of the mandatory argument.
This patch also moves a variable declaration that also causes this behaviour.

Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Reviewed-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: check if the user wants to exit on "sudo -v" command

This patch adds a control on the exit state of "sudo -v" command
and make full-trace.sh exits if it's abnormal.
Before, an exit attempt on the first password prompt resulted in
a multiple password check due to the continuation of the program.
Now, an exit attempt on the first password propt results in
the termination of the program with code 1.

Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Reviewed-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: remove /tmp/tovisit, /tmp/visited and tmp/symbols before creating them

On an attempt to use "fulltrace -u" twice in a row, mkdir complains about
the existence of the said directories.
This patch removes those error messages by deleting the directories before
trying to create them.
This also prevents any undesired effects caused by the files present
in said directories.

Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Reviewed-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: save uprobes on the specified file

This patch adds the possibility to save the uprobes list on a file,
thus permitting to keep uprobes saved between traces of different files.
When used, this option will force the --uprobes option.

Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Reviewed-by: Arianna Avanzini <avanzini.arianna@gmail.com>
full-trace.sh: load uprobes config file

This patch adds the possibility to load an alternate uprobes list.
If the file doesn't exist, this option will force the uprobes generation,
else it will automatically disable the --uprobes option.
The behaviour of this option will also override the forcing made by
--save-uprobes option.

Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Reviewed-by: Arianna Avanzini <avanzini.arianna@gmail.com>
README.md: adapt to change in behavior about files in /tmp

Now the full-trace.sh script automatically removes all the temporary
files that could interfere with subsequent runs. This patch adapts
the README to this new behavior.
README.md: add usage and examples for the new "-s" and "-l" options

Now the full-trace.sh script can save generated uprobes to a file
and load uprobes from a file. This patch adapts the usage in the
README file to this new behavior and adds an example about these
newly introduces features.