full-trace.sh: check first and last indexes before trimming the trace

The full-trace.sh script, in its write_trace() function, trims the
trace output by searching for the first and last context switches of
the traced process. It may happen, though, that a trace does not
cover all the execution of the traced process, and therefore does not
include context switches, or they are not in the expected order. This
would result in an uncorrect trimming of the trace output. This patch
addresses some of the corner-case failures concerning those indexes.
The patch also lets the trace output keep the dashed line at the end
of the last context switch.

Reported-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Serena Ziviani <senseriumi@gmail.com>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>