dwarf-regs.c 2.3 KB

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