perf script brstackinsn: Fix recovery from LBR/binary mismatch
authorAndi Kleen <ak@linux.intel.com>
Fri, 27 Sep 2019 23:35:44 +0000 (16:35 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 30 Sep 2019 20:29:52 +0000 (17:29 -0300)
commite98df280bc2a499fd41d7f9e2d6733884de69902
treea8d0d0604f6737168e3792fe31eb92e9746df14a
parent2657983b4c0d81632c6a73bae469951b0d341251
perf script brstackinsn: Fix recovery from LBR/binary mismatch

When the LBR data and the instructions in a binary do not match the loop
printing instructions could get confused and print a long stream of
bogus <bad> instructions.

The problem was that if the instruction decoder cannot decode an
instruction it ilen wasn't initialized, so the loop going through the
basic block would continue with the previous value.

Harden the code to avoid such problems:

- Make sure ilen is always freshly initialized and is 0 for bad
  instructions.

- Do not overrun the code buffer while printing instructions

- Print a warning message if the final jump is not on an instruction
  boundary.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20190927233546.11533-1-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-script.c