[PATCH v3 08/18] perf cs-etm: Use instruction length in disassembly script

From: James Clark

Date: Mon Nov 02 2026 - 07:18:22 EST


The disassembly script adds four bytes to each branch sample's IP to
include the final instruction in the range. For an exception sample
whose IP identifies a faulting or interrupted instruction, this
incorrectly includes an instruction that did not execute.

Use the decoder-supplied insn_len to calculate the exclusive end
address. This preserves zero-length exception entries, includes executed
syscall instructions and also uses the decoded size for Thumb
instructions.

Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
tools/perf/python/arm-cs-trace-disasm.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/python/arm-cs-trace-disasm.py b/tools/perf/python/arm-cs-trace-disasm.py
index 5a7daf927bea..7cf0af5d2780 100755
--- a/tools/perf/python/arm-cs-trace-disasm.py
+++ b/tools/perf/python/arm-cs-trace-disasm.py
@@ -315,11 +315,12 @@ class TraceDisasm:
# [ sample_prev::addr .. sample_next::ip ]
#
# sample_prev::addr is stored into cpu_data and read back as
- # 'start_addr' when the new packet arrives, and sample_next::ip + 4 is
- # used for 'stop_addr' so objdump includes the branch instruction at
- # sample_next::ip.
+ # 'start_addr' when the new packet arrives. Add sample_next::insn_len
+ # to sample_next::ip so objdump includes the last executed instruction.
+ # The decoder supplies a zero length for an unexecuted instruction at
+ # an exception entry, excluding it from the range.
start_addr = self.cpu_data[str(cpu) + 'addr']
- stop_addr = ip + 4
+ stop_addr = ip + sample.insn_len

# Record for previous sample packet
self.cpu_data[str(cpu) + 'addr'] = addr

--
2.43.0