Commit 1fe86bc2 authored by Athira Rajeev's avatar Athira Rajeev Committed by Arnaldo Carvalho de Melo
Browse files

perf annotate: Make capstone_init non-static so that it can be used during symbol disassemble



symbol__disassemble_capstone in util/disasm.c calls function
open_capstone_handle to open/init the capstone.

We already have a capstone_init function in "util/print_insn.c". But
capstone_init is defined as a static function in util/print_insn.c.

Change this and also add the function in print_insn.h

The open_capstone_handle checks the disassembler_style option from
annotation_options to decide whether to set CS_OPT_SYNTAX_ATT.

Add that logic in capstone_init also and by default set it to true.

Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Akanksha J N <akanksha@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Link: https://lore.kernel.org/lkml/20240718084358.72242-13-atrajeev@linux.vnet.ibm.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 88444952
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
#ifdef HAVE_LIBCAPSTONE_SUPPORT
#include <capstone/capstone.h>

static int capstone_init(struct machine *machine, csh *cs_handle, bool is64)
int capstone_init(struct machine *machine, csh *cs_handle, bool is64, bool disassembler_style)
{
	cs_arch arch;
	cs_mode mode;
@@ -62,6 +62,12 @@ static int capstone_init(struct machine *machine, csh *cs_handle, bool is64)
	}

	if (machine__normalized_is(machine, "x86")) {
		/*
		 * In case of using capstone_init while symbol__disassemble
		 * setting CS_OPT_SYNTAX_ATT depends if disassembler_style opts
		 * is set via annotation args
		 */
		if (disassembler_style)
			cs_option(*cs_handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT);
		/*
		 * Resolving address operands to symbols is implemented
@@ -122,7 +128,7 @@ ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u8 cpum
	int ret;

	/* TODO: Try to initiate capstone only once but need a proper place. */
	ret = capstone_init(machine, &cs_handle, is64bit);
	ret = capstone_init(machine, &cs_handle, is64bit, true);
	if (ret < 0)
		return ret;

+5 −0
Original line number Diff line number Diff line
@@ -19,4 +19,9 @@ ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u8 cpum
			 bool is64bit, const uint8_t *code, size_t code_size,
			 uint64_t ip, int *lenp, int print_opts, FILE *fp);

#ifdef HAVE_LIBCAPSTONE_SUPPORT
#include <capstone/capstone.h>
int capstone_init(struct machine *machine, csh *cs_handle, bool is64, bool disassembler_style);
#endif

#endif /* PERF_PRINT_INSN_H */