Linux Perf
dwarf-regs.c
Go to the documentation of this file.
1 /*
2  * Mapping of DWARF debug register numbers into register names.
3  *
4  * Copyright (C) 2010 Ian Munsie, IBM Corporation.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 
12 #include <stddef.h>
13 #include <errno.h>
14 #include <string.h>
15 #include <dwarf-regs.h>
16 #include <linux/ptrace.h>
17 #include <linux/kernel.h>
18 #include <linux/stringify.h>
19 #include "util.h"
20 
21 struct pt_regs_dwarfnum {
22  const char *name;
23  unsigned int dwarfnum;
24  unsigned int ptregs_offset;
25 };
26 
27 #define REG_DWARFNUM_NAME(r, num) \
28  {.name = __stringify(%)__stringify(r), .dwarfnum = num, \
29  .ptregs_offset = offsetof(struct pt_regs, r)}
30 #define GPR_DWARFNUM_NAME(num) \
31  {.name = __stringify(%gpr##num), .dwarfnum = num, \
32  .ptregs_offset = offsetof(struct pt_regs, gpr[num])}
33 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
34 
35 /*
36  * Reference:
37  * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
38  */
39 static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
72  REG_DWARFNUM_NAME(msr, 66),
73  REG_DWARFNUM_NAME(ctr, 109),
74  REG_DWARFNUM_NAME(link, 108),
75  REG_DWARFNUM_NAME(xer, 101),
76  REG_DWARFNUM_NAME(dar, 119),
77  REG_DWARFNUM_NAME(dsisr, 118),
79 };
80 
89 const char *get_arch_regstr(unsigned int n)
90 {
91  const struct pt_regs_dwarfnum *roff;
92  for (roff = regdwarfnum_table; roff->name != NULL; roff++)
93  if (roff->dwarfnum == n)
94  return roff->name;
95  return NULL;
96 }
97 
99 {
100  const struct pt_regs_dwarfnum *roff;
101  for (roff = regdwarfnum_table; roff->name != NULL; roff++)
102  if (!strcmp(roff->name, name))
103  return roff->ptregs_offset;
104  return -EINVAL;
105 }
unsigned int dwarfnum
Definition: dwarf-regs.c:17
unsigned int ptregs_offset
Definition: dwarf-regs.c:24
static const struct pt_regs_dwarfnum regdwarfnum_table[]
Definition: dwarf-regs.c:39
int regs_query_register_offset(const char *name)
Definition: dwarf-regs.c:88
#define REG_DWARFNUM_NAME(r, num)
Definition: dwarf-regs.c:27
#define GPR_DWARFNUM_NAME(num)
Definition: dwarf-regs.c:30
const char * name
Definition: dwarf-regs.c:16
#define REG_DWARFNUM_END
Definition: dwarf-regs.c:33
const char * get_arch_regstr(unsigned int n)
Definition: dwarf-regs.c:57