1 #include <sys/types.h> 2 #include <regex.h> 3 4 struct arm_annotate { 5 regex_t call_insn, 6 jump_insn; 7 }; 8 9 static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name) 10 { 11 struct arm_annotate *arm = arch->priv; 12 struct ins_ops *ops; 13 regmatch_t match[2]; 14 15 if (!regexec(&arm->call_insn, name, 2, match, 0)) 16 ops = &call_ops; 17 else if (!regexec(&arm->jump_insn, name, 2, match, 0)) 18 ops = &jump_ops; 19 else 20 return NULL; 21 22 arch__associate_ins_ops(arch, name, ops); 23 return ops; 24 } 25 26 static int arm__annotate_init(struct arch *arch) 27 { 28 struct arm_annotate *arm; 29 int err; 30 31 if (arch->initialized) 32 return 0; 33 34 arm = zalloc(sizeof(*arm)); 35 if (!arm) 36 return -1; 37 38 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)" 39 err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED); 40 if (err) 41 goto out_free_arm; 42 err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED); 43 if (err) 44 goto out_free_call; 45 #undef ARM_CONDS 46 47 arch->initialized = true; 48 arch->priv = arm; 49 arch->associate_instruction_ops = arm__associate_instruction_ops; 50 arch->objdump.comment_char = ';'; 51 arch->objdump.skip_functions_char = '+'; 52 return 0; 53 54 out_free_call: 55 regfree(&arm->call_insn); 56 out_free_arm: 57 free(arm); 58 return -1; 59 } 60