Linux Perf
instructions.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <sys/types.h>
4 #include <regex.h>
5 
6 struct arm_annotate {
7  regex_t call_insn,
8  jump_insn;
9 };
10 
11 static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name)
12 {
13  struct arm_annotate *arm = arch->priv;
14  struct ins_ops *ops;
15  regmatch_t match[2];
16 
17  if (!regexec(&arm->call_insn, name, 2, match, 0))
18  ops = &call_ops;
19  else if (!regexec(&arm->jump_insn, name, 2, match, 0))
20  ops = &jump_ops;
21  else
22  return NULL;
23 
24  arch__associate_ins_ops(arch, name, ops);
25  return ops;
26 }
27 
28 static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
29 {
30  struct arm_annotate *arm;
31  int err;
32 
33  if (arch->initialized)
34  return 0;
35 
36  arm = zalloc(sizeof(*arm));
37  if (!arm)
38  return -1;
39 
40 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
41  err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
42  if (err)
43  goto out_free_arm;
44  err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED);
45  if (err)
46  goto out_free_call;
47 #undef ARM_CONDS
48 
49  arch->initialized = true;
50  arch->priv = arm;
52  arch->objdump.comment_char = ';';
53  arch->objdump.skip_functions_char = '+';
54  return 0;
55 
56 out_free_call:
57  regfree(&arm->call_insn);
58 out_free_arm:
59  free(arm);
60  return -1;
61 }
static struct ins_ops jump_ops
Definition: annotate.c:82
char skip_functions_char
Definition: annotate.c:76
void * priv
Definition: annotate.c:68
regex_t jump_insn
Definition: instructions.c:7
static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
Definition: instructions.c:28
int int err
Definition: 5sec.c:44
regex_t call_insn
Definition: instructions.c:7
struct arch::@33 objdump
const char * name
struct ins_ops *(* associate_instruction_ops)(struct arch *arch, const char *name)
Definition: annotate.c:65
bool initialized
Definition: annotate.c:67
static struct ins_ops * arm__associate_instruction_ops(struct arch *arch, const char *name)
Definition: instructions.c:11
Definition: annotate.c:60
static void cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d)
Definition: header.c:11
#define ARM_CONDS
void free(void *)
static int arch__associate_ins_ops(struct arch *arch, const char *name, struct ins_ops *ops)
Definition: annotate.c:116
static struct ins_ops call_ops
Definition: annotate.c:80
char comment_char
Definition: annotate.c:75
void static void * zalloc(size_t size)
Definition: util.h:20