dwarf-regs.c 2.4 KB

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