dwarf-regs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <stddef.h>
  12. #include <errno.h>
  13. #include <string.h>
  14. #include <dwarf-regs.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/kernel.h>
  17. #include <linux/stringify.h>
  18. #include "util.h"
  19. struct pt_regs_dwarfnum {
  20. const char *name;
  21. unsigned int dwarfnum;
  22. unsigned int ptregs_offset;
  23. };
  24. #define REG_DWARFNUM_NAME(r, num) \
  25. {.name = __stringify(%)__stringify(r), .dwarfnum = num, \
  26. .ptregs_offset = offsetof(struct pt_regs, r)}
  27. #define GPR_DWARFNUM_NAME(num) \
  28. {.name = __stringify(%gpr##num), .dwarfnum = num, \
  29. .ptregs_offset = offsetof(struct pt_regs, gpr[num])}
  30. #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
  31. /*
  32. * Reference:
  33. * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
  34. */
  35. static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
  36. GPR_DWARFNUM_NAME(0),
  37. GPR_DWARFNUM_NAME(1),
  38. GPR_DWARFNUM_NAME(2),
  39. GPR_DWARFNUM_NAME(3),
  40. GPR_DWARFNUM_NAME(4),
  41. GPR_DWARFNUM_NAME(5),
  42. GPR_DWARFNUM_NAME(6),
  43. GPR_DWARFNUM_NAME(7),
  44. GPR_DWARFNUM_NAME(8),
  45. GPR_DWARFNUM_NAME(9),
  46. GPR_DWARFNUM_NAME(10),
  47. GPR_DWARFNUM_NAME(11),
  48. GPR_DWARFNUM_NAME(12),
  49. GPR_DWARFNUM_NAME(13),
  50. GPR_DWARFNUM_NAME(14),
  51. GPR_DWARFNUM_NAME(15),
  52. GPR_DWARFNUM_NAME(16),
  53. GPR_DWARFNUM_NAME(17),
  54. GPR_DWARFNUM_NAME(18),
  55. GPR_DWARFNUM_NAME(19),
  56. GPR_DWARFNUM_NAME(20),
  57. GPR_DWARFNUM_NAME(21),
  58. GPR_DWARFNUM_NAME(22),
  59. GPR_DWARFNUM_NAME(23),
  60. GPR_DWARFNUM_NAME(24),
  61. GPR_DWARFNUM_NAME(25),
  62. GPR_DWARFNUM_NAME(26),
  63. GPR_DWARFNUM_NAME(27),
  64. GPR_DWARFNUM_NAME(28),
  65. GPR_DWARFNUM_NAME(29),
  66. GPR_DWARFNUM_NAME(30),
  67. GPR_DWARFNUM_NAME(31),
  68. REG_DWARFNUM_NAME(msr, 66),
  69. REG_DWARFNUM_NAME(ctr, 109),
  70. REG_DWARFNUM_NAME(link, 108),
  71. REG_DWARFNUM_NAME(xer, 101),
  72. REG_DWARFNUM_NAME(dar, 119),
  73. REG_DWARFNUM_NAME(dsisr, 118),
  74. REG_DWARFNUM_END,
  75. };
  76. /**
  77. * get_arch_regstr() - lookup register name from it's DWARF register number
  78. * @n: the DWARF register number
  79. *
  80. * get_arch_regstr() returns the name of the register in struct
  81. * regdwarfnum_table from it's DWARF register number. If the register is not
  82. * found in the table, this returns NULL;
  83. */
  84. const char *get_arch_regstr(unsigned int n)
  85. {
  86. const struct pt_regs_dwarfnum *roff;
  87. for (roff = regdwarfnum_table; roff->name != NULL; roff++)
  88. if (roff->dwarfnum == n)
  89. return roff->name;
  90. return NULL;
  91. }
  92. int regs_query_register_offset(const char *name)
  93. {
  94. const struct pt_regs_dwarfnum *roff;
  95. for (roff = regdwarfnum_table; roff->name != NULL; roff++)
  96. if (!strcmp(roff->name, name))
  97. return roff->ptregs_offset;
  98. return -EINVAL;
  99. }