mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-09 02:57:42 -04:00
Capstone disassembly support was split between disasm.c and print_insn.c. Move support out of these files into capstone.[ch] and remove include capstone/capstone.h from those files. As disassembly routines can fail, make failure the only option without HAVE_LIBCAPSTONE_SUPPORT. For simplicity's sake, duplicate the read_symbol utility function. The intent with moving capstone support into a single file is that dynamic support, using dlopen for libcapstone, can be added in later patches. This can potentially always succeed or fail, so relying on ifdefs isn't sufficient. Using dlopen is a useful option to minimize the perf tools dependencies and potentially size. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.ibm.com> Cc: Bill Wendling <morbo@google.com> Cc: Charlie Jenkins <charlie@rivosinc.com> Cc: Collin Funk <collin.funk1@gmail.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Eric Biggers <ebiggers@kernel.org> Cc: Haibo Xu <haibo1.xu@intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Justin Stitt <justinstitt@google.com> Cc: Li Huafei <lihuafei1@huawei.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <song@kernel.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Instruction binary disassembler based on capstone.
|
|
*
|
|
* Author(s): Changbin Du <changbin.du@huawei.com>
|
|
*/
|
|
#include <inttypes.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include "capstone.h"
|
|
#include "debug.h"
|
|
#include "sample.h"
|
|
#include "symbol.h"
|
|
#include "machine.h"
|
|
#include "thread.h"
|
|
#include "print_insn.h"
|
|
#include "dump-insn.h"
|
|
#include "map.h"
|
|
#include "dso.h"
|
|
|
|
size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
|
|
{
|
|
int printed = 0;
|
|
|
|
for (int i = 0; i < sample->insn_len; i++) {
|
|
printed += fprintf(fp, "%02x", (unsigned char)sample->insn[i]);
|
|
if (sample->insn_len - i > 1)
|
|
printed += fprintf(fp, " ");
|
|
}
|
|
return printed;
|
|
}
|
|
|
|
static bool is64bitip(struct machine *machine, struct addr_location *al)
|
|
{
|
|
const struct dso *dso = al->map ? map__dso(al->map) : NULL;
|
|
|
|
if (dso)
|
|
return dso__is_64_bit(dso);
|
|
|
|
return machine__is(machine, "x86_64") ||
|
|
machine__normalized_is(machine, "arm64") ||
|
|
machine__normalized_is(machine, "s390");
|
|
}
|
|
|
|
ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u8 cpumode,
|
|
bool is64bit, const uint8_t *code, size_t code_size,
|
|
uint64_t ip, int *lenp, int print_opts, FILE *fp)
|
|
{
|
|
return capstone__fprintf_insn_asm(machine, thread, cpumode, is64bit, code, code_size,
|
|
ip, lenp, print_opts, fp);
|
|
}
|
|
|
|
size_t sample__fprintf_insn_asm(struct perf_sample *sample, struct thread *thread,
|
|
struct machine *machine, FILE *fp,
|
|
struct addr_location *al)
|
|
{
|
|
bool is64bit = is64bitip(machine, al);
|
|
ssize_t printed;
|
|
|
|
printed = fprintf_insn_asm(machine, thread, sample->cpumode, is64bit,
|
|
(uint8_t *)sample->insn, sample->insn_len,
|
|
sample->ip, NULL, 0, fp);
|
|
if (printed < 0)
|
|
return sample__fprintf_insn_raw(sample, fp);
|
|
|
|
return printed;
|
|
}
|