Skip to content

Commit 1f7393a

Browse files
committed
perf disasm: Define stubs for the LLVM and capstone disassemblers
This reduces the number of ifdefs in the main symbol__disassemble() method and paves the way for allowing the user to configure the disassemblers of preference. Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Aditya Bodkhe <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Steinar H. Gunderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Applied fixes from Masami Hiramatsu and Aditya Bodkhe for when capstone devel files are not available ] Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/173145729034.2747044.453926054000880254.stgit@mhiramat.roam.corp.google.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4c1d8f0 commit 1f7393a

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

tools/perf/util/disasm.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,15 @@ read_symbol(const char *filename, struct map *map, struct symbol *sym,
14241424
}
14251425
#endif
14261426

1427+
#if !defined(HAVE_LIBCAPSTONE_SUPPORT) || !defined(HAVE_LIBLLVM_SUPPORT)
1428+
static void symbol__disassembler_missing(const char *disassembler, const char *filename,
1429+
struct symbol *sym)
1430+
{
1431+
pr_debug("The %s disassembler isn't linked in for %s in %s\n",
1432+
disassembler, sym->name, filename);
1433+
}
1434+
#endif
1435+
14271436
#ifdef HAVE_LIBCAPSTONE_SUPPORT
14281437
static void print_capstone_detail(cs_insn *insn, char *buf, size_t len,
14291438
struct annotate_args *args, u64 addr)
@@ -1715,7 +1724,21 @@ static int symbol__disassemble_capstone(char *filename, struct symbol *sym,
17151724
count = -1;
17161725
goto out;
17171726
}
1718-
#endif
1727+
#else // HAVE_LIBCAPSTONE_SUPPORT
1728+
static int symbol__disassemble_capstone(char *filename, struct symbol *sym,
1729+
struct annotate_args *args __maybe_unused)
1730+
{
1731+
symbol__disassembler_missing("capstone", filename, sym);
1732+
return -1;
1733+
}
1734+
1735+
static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *sym,
1736+
struct annotate_args *args __maybe_unused)
1737+
{
1738+
symbol__disassembler_missing("capstone powerpc", filename, sym);
1739+
return -1;
1740+
}
1741+
#endif // HAVE_LIBCAPSTONE_SUPPORT
17191742

17201743
static int symbol__disassemble_raw(char *filename, struct symbol *sym,
17211744
struct annotate_args *args)
@@ -1983,7 +2006,14 @@ static int symbol__disassemble_llvm(char *filename, struct symbol *sym,
19832006
free(line_storage);
19842007
return ret;
19852008
}
1986-
#endif
2009+
#else // HAVE_LIBLLVM_SUPPORT
2010+
static int symbol__disassemble_llvm(char *filename, struct symbol *sym,
2011+
struct annotate_args *args __maybe_unused)
2012+
{
2013+
symbol__disassembler_missing("LLVM", filename, sym);
2014+
return -1;
2015+
}
2016+
#endif // HAVE_LIBLLVM_SUPPORT
19872017

19882018
/*
19892019
* Possibly create a new version of line with tabs expanded. Returns the
@@ -2242,24 +2272,21 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
22422272
err = symbol__disassemble_raw(symfs_filename, sym, args);
22432273
if (err == 0)
22442274
goto out_remove_tmp;
2245-
#ifdef HAVE_LIBCAPSTONE_SUPPORT
2275+
22462276
err = symbol__disassemble_capstone_powerpc(symfs_filename, sym, args);
22472277
if (err == 0)
22482278
goto out_remove_tmp;
2249-
#endif
22502279
}
22512280
}
22522281

2253-
#ifdef HAVE_LIBLLVM_SUPPORT
22542282
err = symbol__disassemble_llvm(symfs_filename, sym, args);
22552283
if (err == 0)
22562284
goto out_remove_tmp;
2257-
#endif
2258-
#ifdef HAVE_LIBCAPSTONE_SUPPORT
2285+
22592286
err = symbol__disassemble_capstone(symfs_filename, sym, args);
22602287
if (err == 0)
22612288
goto out_remove_tmp;
2262-
#endif
2289+
22632290
err = symbol__disassemble_objdump(symfs_filename, sym, args);
22642291

22652292
out_remove_tmp:

0 commit comments

Comments
 (0)