13ab481a1SAndi Kleen // SPDX-License-Identifier: GPL-2.0
23ab481a1SAndi Kleen #include "archinsn.h"
3ea49e01cSArnaldo Carvalho de Melo #include "event.h"
43ab481a1SAndi Kleen #include "machine.h"
53ab481a1SAndi Kleen #include "thread.h"
63ab481a1SAndi Kleen #include "symbol.h"
7c1f272dfSArnaldo Carvalho de Melo #include "../../../../arch/x86/include/asm/insn.h"
83ab481a1SAndi Kleen
arch_fetch_insn(struct perf_sample * sample,struct thread * thread,struct machine * machine)93ab481a1SAndi Kleen void arch_fetch_insn(struct perf_sample *sample,
103ab481a1SAndi Kleen struct thread *thread,
113ab481a1SAndi Kleen struct machine *machine)
123ab481a1SAndi Kleen {
133ab481a1SAndi Kleen struct insn insn;
14*62660b0fSBorislav Petkov int len, ret;
153ab481a1SAndi Kleen bool is64bit = false;
163ab481a1SAndi Kleen
173ab481a1SAndi Kleen if (!sample->ip)
183ab481a1SAndi Kleen return;
193ab481a1SAndi Kleen len = thread__memcpy(thread, machine, sample->insn, sample->ip, sizeof(sample->insn), &is64bit);
203ab481a1SAndi Kleen if (len <= 0)
213ab481a1SAndi Kleen return;
22*62660b0fSBorislav Petkov
23*62660b0fSBorislav Petkov ret = insn_decode(&insn, sample->insn, len,
24*62660b0fSBorislav Petkov is64bit ? INSN_MODE_64 : INSN_MODE_32);
25*62660b0fSBorislav Petkov if (ret >= 0 && insn.length <= len)
263ab481a1SAndi Kleen sample->insn_len = insn.length;
273ab481a1SAndi Kleen }
28