Skip to content

Commit 9fc4489

Browse files
captain5050namhyung
authored andcommitted
perf dwarf-regs: Pass accurate disassembly machine to get_dwarf_regnum
Rather than pass 0/EM_NONE, use the value computed in the disasm struct arch. Switch the EM_NONE case to EM_HOST, rewriting EM_NONE if it were passed to get_dwarf_regnum. Pass a flags value as architectures like csky need the flags to determine the ABI variant. Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Anup Patel <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: David S. Miller <[email protected]> Cc: Albert Ou <[email protected]> Cc: Shenlin Liang <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Guilherme Amadio <[email protected]> Cc: Steinar H. Gunderson <[email protected]> Cc: Changbin Du <[email protected]> Cc: Alexander Lobakin <[email protected]> Cc: Przemek Kitszel <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Guo Ren <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Clark <[email protected]> Cc: Mike Leach <[email protected]> Cc: Chen Pei <[email protected]> Cc: Leo Yan <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Aditya Gupta <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Bibo Mao <[email protected]> Cc: John Garry <[email protected]> Cc: Atish Patra <[email protected]> Cc: Dima Kogan <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent cd6c9dc commit 9fc4489

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

tools/perf/util/annotate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ static int extract_reg_offset(struct arch *arch, const char *str,
22922292
if (regname == NULL)
22932293
return -1;
22942294

2295-
op_loc->reg1 = get_dwarf_regnum(regname, 0);
2295+
op_loc->reg1 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags);
22962296
free(regname);
22972297

22982298
/* Get the second register */
@@ -2305,7 +2305,7 @@ static int extract_reg_offset(struct arch *arch, const char *str,
23052305
if (regname == NULL)
23062306
return -1;
23072307

2308-
op_loc->reg2 = get_dwarf_regnum(regname, 0);
2308+
op_loc->reg2 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags);
23092309
free(regname);
23102310
}
23112311
return 0;
@@ -2405,7 +2405,7 @@ int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl,
24052405
return -1;
24062406

24072407
if (*s == arch->objdump.register_char)
2408-
op_loc->reg1 = get_dwarf_regnum(s, 0);
2408+
op_loc->reg1 = get_dwarf_regnum(s, arch->e_machine, arch->e_flags);
24092409
else if (*s == arch->objdump.imm_char) {
24102410
op_loc->offset = strtol(s + 1, &p, 0);
24112411
if (p && p != s + 1)

tools/perf/util/dwarf-regs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ __weak int get_arch_regnum(const char *name __maybe_unused)
7070
}
7171

7272
/* Return DWARF register number from architecture register name */
73-
int get_dwarf_regnum(const char *name, unsigned int machine)
73+
int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags __maybe_unused)
7474
{
7575
char *regname = strdup(name);
7676
int reg = -1;
@@ -84,8 +84,12 @@ int get_dwarf_regnum(const char *name, unsigned int machine)
8484
if (p)
8585
*p = '\0';
8686

87+
if (machine == EM_NONE) {
88+
/* Generic arch - use host arch */
89+
machine = EM_HOST;
90+
}
8791
switch (machine) {
88-
case EM_NONE: /* Generic arch - use host arch */
92+
case EM_HOST:
8993
reg = get_arch_regnum(regname);
9094
break;
9195
default:

tools/perf/util/include/dwarf-regs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ int get_arch_regnum(const char *name);
103103
* name: architecture register name
104104
* machine: ELF machine signature (EM_*)
105105
*/
106-
int get_dwarf_regnum(const char *name, unsigned int machine);
106+
int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags);
107107

108108
#else /* HAVE_LIBDW_SUPPORT */
109109

110110
static inline int get_dwarf_regnum(const char *name __maybe_unused,
111-
unsigned int machine __maybe_unused)
111+
unsigned int machine __maybe_unused,
112+
unsigned int flags __maybe_unused)
112113
{
113114
return -1;
114115
}

0 commit comments

Comments
 (0)