tools/perf: Convert to insn_decode()
Simplify code, no functional changes. Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Link: https://lkml.kernel.org/r/20210304174237.31945-20-bp@alien8.de
This commit is contained in:
parent
a277ce601c
commit
62660b0fd2
@ -96,13 +96,12 @@ static int get_branch(const char *branch_str)
|
||||
static int test_data_item(struct test_data *dat, int x86_64)
|
||||
{
|
||||
struct intel_pt_insn intel_pt_insn;
|
||||
int op, branch, ret;
|
||||
struct insn insn;
|
||||
int op, branch;
|
||||
|
||||
insn_init(&insn, dat->data, MAX_INSN_SIZE, x86_64);
|
||||
insn_get_length(&insn);
|
||||
|
||||
if (!insn_complete(&insn)) {
|
||||
ret = insn_decode(&insn, dat->data, MAX_INSN_SIZE,
|
||||
x86_64 ? INSN_MODE_64 : INSN_MODE_32);
|
||||
if (ret < 0) {
|
||||
pr_debug("Failed to decode: %s\n", dat->asm_rep);
|
||||
return -1;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ void arch_fetch_insn(struct perf_sample *sample,
|
||||
struct machine *machine)
|
||||
{
|
||||
struct insn insn;
|
||||
int len;
|
||||
int len, ret;
|
||||
bool is64bit = false;
|
||||
|
||||
if (!sample->ip)
|
||||
@ -19,8 +19,9 @@ void arch_fetch_insn(struct perf_sample *sample,
|
||||
len = thread__memcpy(thread, machine, sample->insn, sample->ip, sizeof(sample->insn), &is64bit);
|
||||
if (len <= 0)
|
||||
return;
|
||||
insn_init(&insn, sample->insn, len, is64bit);
|
||||
insn_get_length(&insn);
|
||||
if (insn_complete(&insn) && insn.length <= len)
|
||||
|
||||
ret = insn_decode(&insn, sample->insn, len,
|
||||
is64bit ? INSN_MODE_64 : INSN_MODE_32);
|
||||
if (ret >= 0 && insn.length <= len)
|
||||
sample->insn_len = insn.length;
|
||||
}
|
||||
|
@ -169,11 +169,13 @@ int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
|
||||
struct intel_pt_insn *intel_pt_insn)
|
||||
{
|
||||
struct insn insn;
|
||||
int ret;
|
||||
|
||||
insn_init(&insn, buf, len, x86_64);
|
||||
insn_get_length(&insn);
|
||||
if (!insn_complete(&insn) || insn.length > len)
|
||||
ret = insn_decode(&insn, buf, len,
|
||||
x86_64 ? INSN_MODE_64 : INSN_MODE_32);
|
||||
if (ret < 0 || insn.length > len)
|
||||
return -1;
|
||||
|
||||
intel_pt_insn_decoder(&insn, intel_pt_insn);
|
||||
if (insn.length < INTEL_PT_INSN_BUF_SZ)
|
||||
memcpy(intel_pt_insn->buf, buf, insn.length);
|
||||
@ -194,12 +196,13 @@ const char *dump_insn(struct perf_insn *x, uint64_t ip __maybe_unused,
|
||||
u8 *inbuf, int inlen, int *lenp)
|
||||
{
|
||||
struct insn insn;
|
||||
int n, i;
|
||||
int n, i, ret;
|
||||
int left;
|
||||
|
||||
insn_init(&insn, inbuf, inlen, x->is64bit);
|
||||
insn_get_length(&insn);
|
||||
if (!insn_complete(&insn) || insn.length > inlen)
|
||||
ret = insn_decode(&insn, inbuf, inlen,
|
||||
x->is64bit ? INSN_MODE_64 : INSN_MODE_32);
|
||||
|
||||
if (ret < 0 || insn.length > inlen)
|
||||
return "<bad>";
|
||||
if (lenp)
|
||||
*lenp = insn.length;
|
||||
|
Loading…
x
Reference in New Issue
Block a user