Skip to content

Commit 64ea7a4

Browse files
namhyungacmel
authored andcommitted
perf annotate: Fix register usage in data type profiling
On data type profiling, it tried to match register name with a partial string. For example, it allowed to match with "%rbp)" or "%rdi,8)". But with recent change in the area, it doesn't match anymore and break the data type profiling. Let's pass the correct register name by removing the unwanted part. Add arch__dwarf_regnum() to handle it in a single place. Closes: 7d3n23li6drroxrdlpxn7ixehdeszkjdftah3zyngjl2qs22ef@yelcjv53v42o Reported-by: Dmitry Dolgov <[email protected]> Reviewed-by: Ian Rogers <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Zecheng Li <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent bb5a920 commit 64ea7a4

1 file changed

Lines changed: 30 additions & 31 deletions

File tree

tools/perf/util/annotate.c

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,29 @@ int annotate_check_args(void)
24472447
return 0;
24482448
}
24492449

2450+
static int arch__dwarf_regnum(const struct arch *arch, const char *str)
2451+
{
2452+
const char *p;
2453+
char *regname, *q;
2454+
int reg;
2455+
2456+
p = strchr(str, arch->objdump.register_char);
2457+
if (p == NULL)
2458+
return -1;
2459+
2460+
regname = strdup(p);
2461+
if (regname == NULL)
2462+
return -1;
2463+
2464+
q = strpbrk(regname, ",) ");
2465+
if (q)
2466+
*q = '\0';
2467+
2468+
reg = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
2469+
free(regname);
2470+
return reg;
2471+
}
2472+
24502473
/*
24512474
* Get register number and access offset from the given instruction.
24522475
* It assumes AT&T x86 asm format like OFFSET(REG). Maybe it needs
@@ -2457,7 +2480,6 @@ static int extract_reg_offset(const struct arch *arch, const char *str,
24572480
struct annotated_op_loc *op_loc)
24582481
{
24592482
char *p;
2460-
char *regname;
24612483

24622484
if (arch->objdump.register_char == 0)
24632485
return -1;
@@ -2482,31 +2504,14 @@ static int extract_reg_offset(const struct arch *arch, const char *str,
24822504
}
24832505

24842506
op_loc->offset = strtol(str, &p, 0);
2485-
2486-
p = strchr(p, arch->objdump.register_char);
2487-
if (p == NULL)
2507+
op_loc->reg1 = arch__dwarf_regnum(arch, p);
2508+
if (op_loc->reg1 == -1)
24882509
return -1;
24892510

2490-
regname = strdup(p);
2491-
if (regname == NULL)
2492-
return -1;
2493-
2494-
op_loc->reg1 = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
2495-
free(regname);
2496-
24972511
/* Get the second register */
2498-
if (op_loc->multi_regs) {
2499-
p = strchr(p + 1, arch->objdump.register_char);
2500-
if (p == NULL)
2501-
return -1;
2502-
2503-
regname = strdup(p);
2504-
if (regname == NULL)
2505-
return -1;
2512+
if (op_loc->multi_regs)
2513+
op_loc->reg2 = arch__dwarf_regnum(arch, p + 1);
25062514

2507-
op_loc->reg2 = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
2508-
free(regname);
2509-
}
25102515
return 0;
25112516
}
25122517

@@ -2585,7 +2590,8 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
25852590
op_loc->multi_regs = multi_regs;
25862591
extract_reg_offset(arch, insn_str, op_loc);
25872592
} else {
2588-
char *s, *p = NULL;
2593+
const char *s = insn_str;
2594+
char *p = NULL;
25892595

25902596
if (arch__is_x86(arch)) {
25912597
/* FIXME: Handle other segment registers */
@@ -2599,21 +2605,14 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
25992605
}
26002606
}
26012607

2602-
s = strdup(insn_str);
2603-
if (s == NULL)
2604-
return -1;
2605-
26062608
if (*s == arch->objdump.register_char) {
2607-
op_loc->reg1 = get_dwarf_regnum(s,
2608-
arch->id.e_machine,
2609-
arch->id.e_flags);
2609+
op_loc->reg1 = arch__dwarf_regnum(arch, s);
26102610
}
26112611
else if (*s == arch->objdump.imm_char) {
26122612
op_loc->offset = strtol(s + 1, &p, 0);
26132613
if (p && p != s + 1)
26142614
op_loc->imm = true;
26152615
}
2616-
free(s);
26172616
}
26182617
}
26192618

0 commit comments

Comments
 (0)