dwarf-regs.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Mapping of DWARF debug register numbers into register names.
  3. *
  4. * Copyright (C) 2010 Will Deacon, ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <stddef.h>
  11. #include <dwarf-regs.h>
  12. struct pt_regs_dwarfnum {
  13. const char *name;
  14. unsigned int dwarfnum;
  15. };
  16. #define STR(s) #s
  17. #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
  18. #define GPR_DWARFNUM_NAME(num) \
  19. {.name = STR(%x##num), .dwarfnum = num}
  20. #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
  21. /*
  22. * Reference:
  23. * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0057b/IHI0057B_aadwarf64.pdf
  24. */
  25. static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
  26. GPR_DWARFNUM_NAME(0),
  27. GPR_DWARFNUM_NAME(1),
  28. GPR_DWARFNUM_NAME(2),
  29. GPR_DWARFNUM_NAME(3),
  30. GPR_DWARFNUM_NAME(4),
  31. GPR_DWARFNUM_NAME(5),
  32. GPR_DWARFNUM_NAME(6),
  33. GPR_DWARFNUM_NAME(7),
  34. GPR_DWARFNUM_NAME(8),
  35. GPR_DWARFNUM_NAME(9),
  36. GPR_DWARFNUM_NAME(10),
  37. GPR_DWARFNUM_NAME(11),
  38. GPR_DWARFNUM_NAME(12),
  39. GPR_DWARFNUM_NAME(13),
  40. GPR_DWARFNUM_NAME(14),
  41. GPR_DWARFNUM_NAME(15),
  42. GPR_DWARFNUM_NAME(16),
  43. GPR_DWARFNUM_NAME(17),
  44. GPR_DWARFNUM_NAME(18),
  45. GPR_DWARFNUM_NAME(19),
  46. GPR_DWARFNUM_NAME(20),
  47. GPR_DWARFNUM_NAME(21),
  48. GPR_DWARFNUM_NAME(22),
  49. GPR_DWARFNUM_NAME(23),
  50. GPR_DWARFNUM_NAME(24),
  51. GPR_DWARFNUM_NAME(25),
  52. GPR_DWARFNUM_NAME(26),
  53. GPR_DWARFNUM_NAME(27),
  54. GPR_DWARFNUM_NAME(28),
  55. GPR_DWARFNUM_NAME(29),
  56. REG_DWARFNUM_NAME("%lr", 30),
  57. REG_DWARFNUM_NAME("%sp", 31),
  58. REG_DWARFNUM_END,
  59. };
  60. /**
  61. * get_arch_regstr() - lookup register name from it's DWARF register number
  62. * @n: the DWARF register number
  63. *
  64. * get_arch_regstr() returns the name of the register in struct
  65. * regdwarfnum_table from it's DWARF register number. If the register is not
  66. * found in the table, this returns NULL;
  67. */
  68. const char *get_arch_regstr(unsigned int n)
  69. {
  70. const struct pt_regs_dwarfnum *roff;
  71. for (roff = regdwarfnum_table; roff->name != NULL; roff++)
  72. if (roff->dwarfnum == n)
  73. return roff->name;
  74. return NULL;
  75. }