perf annotate: Split out util/disasm.c

The util/annotate.c code has both disassembly and sample annotation
related codes.  Factor out the disasm part so that it can be handled
more easily.

No functional changes intended.

Committer notes:

Add missing include env.h, util.h, bpf-event.h and bpf-util.h to
disasm.c, to fix things like:

  util/disasm.c: In function ‘symbol__disassemble_bpf’:
  util/disasm.c:1203:9: error: implicit declaration of function ‘perf_exe’ [-Werror=implicit-function-declaration]
   1203 |         perf_exe(tpath, sizeof(tpath));
        |         ^~~~~~~~

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240329215812.537846-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim 2024-03-29 14:58:10 -07:00 committed by Arnaldo Carvalho de Melo
parent 10adbf7776
commit 98f69a573c
5 changed files with 1709 additions and 1657 deletions

View File

@ -12,6 +12,7 @@ perf-y += config.o
perf-y += copyfile.o
perf-y += ctype.o
perf-y += db-export.o
perf-y += disasm.o
perf-y += env.o
perf-y += event.o
perf-y += evlist.o

File diff suppressed because it is too large Load Diff

View File

@ -13,10 +13,10 @@
#include "mutex.h"
#include "spark.h"
#include "hashmap.h"
#include "disasm.h"
struct hist_browser_timer;
struct hist_entry;
struct ins_ops;
struct map;
struct map_symbol;
struct addr_map_symbol;
@ -26,60 +26,6 @@ struct evsel;
struct symbol;
struct annotated_data_type;
struct ins {
const char *name;
struct ins_ops *ops;
};
struct ins_operands {
char *raw;
struct {
char *raw;
char *name;
struct symbol *sym;
u64 addr;
s64 offset;
bool offset_avail;
bool outside;
bool multi_regs;
} target;
union {
struct {
char *raw;
char *name;
u64 addr;
bool multi_regs;
} source;
struct {
struct ins ins;
struct ins_operands *ops;
} locked;
struct {
char *raw_comment;
char *raw_func_start;
} jump;
};
};
struct arch;
bool arch__is(struct arch *arch, const char *name);
struct ins_ops {
void (*free)(struct ins_operands *ops);
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
int (*scnprintf)(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, int max_ins_name);
};
bool ins__is_jump(const struct ins *ins);
bool ins__is_call(const struct ins *ins);
bool ins__is_nop(const struct ins *ins);
bool ins__is_ret(const struct ins *ins);
bool ins__is_lock(const struct ins *ins);
int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
#define ANNOTATION__IPC_WIDTH 6
#define ANNOTATION__CYCLES_WIDTH 6
#define ANNOTATION__MINMAX_CYCLES_WIDTH 19
@ -172,6 +118,8 @@ struct disasm_line {
struct annotation_line al;
};
void annotation_line__add(struct annotation_line *al, struct list_head *head);
static inline double annotation_data__percent(struct annotation_data *data,
unsigned int which)
{
@ -213,7 +161,6 @@ static inline bool disasm_line__has_local_offset(const struct disasm_line *dl)
*/
bool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol *sym);
void disasm_line__free(struct disasm_line *dl);
struct annotation_line *
annotation_line__next(struct annotation_line *pos, struct list_head *head);
@ -236,7 +183,6 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,
struct evsel *evsel,
bool show_freq);
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
size_t disasm__fprintf(struct list_head *head, FILE *fp);
void symbol__calc_percent(struct symbol *sym, struct evsel *evsel);

1591
tools/perf/util/disasm.c Normal file

File diff suppressed because it is too large Load Diff

112
tools/perf/util/disasm.h Normal file
View File

@ -0,0 +1,112 @@
// SPDX-License-Identifier: GPL-2.0
#ifndef __PERF_UTIL_DISASM_H
#define __PERF_UTIL_DISASM_H
#include "map_symbol.h"
struct annotation_options;
struct disasm_line;
struct ins;
struct evsel;
struct symbol;
struct arch {
const char *name;
struct ins *instructions;
size_t nr_instructions;
size_t nr_instructions_allocated;
struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name);
bool sorted_instructions;
bool initialized;
const char *insn_suffix;
void *priv;
unsigned int model;
unsigned int family;
int (*init)(struct arch *arch, char *cpuid);
bool (*ins_is_fused)(struct arch *arch, const char *ins1,
const char *ins2);
struct {
char comment_char;
char skip_functions_char;
char register_char;
char memory_ref_char;
char imm_char;
} objdump;
};
struct ins {
const char *name;
struct ins_ops *ops;
};
struct ins_operands {
char *raw;
struct {
char *raw;
char *name;
struct symbol *sym;
u64 addr;
s64 offset;
bool offset_avail;
bool outside;
bool multi_regs;
} target;
union {
struct {
char *raw;
char *name;
u64 addr;
bool multi_regs;
} source;
struct {
struct ins ins;
struct ins_operands *ops;
} locked;
struct {
char *raw_comment;
char *raw_func_start;
} jump;
};
};
struct ins_ops {
void (*free)(struct ins_operands *ops);
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
int (*scnprintf)(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, int max_ins_name);
};
struct annotate_args {
struct arch *arch;
struct map_symbol ms;
struct evsel *evsel;
struct annotation_options *options;
s64 offset;
char *line;
int line_nr;
char *fileloc;
};
struct arch *arch__find(const char *name);
bool arch__is(struct arch *arch, const char *name);
struct ins_ops *ins__find(struct arch *arch, const char *name);
int ins__scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, int max_ins_name);
bool ins__is_call(const struct ins *ins);
bool ins__is_jump(const struct ins *ins);
bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
bool ins__is_nop(const struct ins *ins);
bool ins__is_ret(const struct ins *ins);
bool ins__is_lock(const struct ins *ins);
struct disasm_line *disasm_line__new(struct annotate_args *args);
void disasm_line__free(struct disasm_line *dl);
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size,
bool raw, int max_ins_name);
int symbol__disassemble(struct symbol *sym, struct annotate_args *args);
#endif /* __PERF_UTIL_DISASM_H */