dwarf-regs.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <stdlib.h>
  11. #ifndef __UCLIBC__
  12. #include <libio.h>
  13. #endif
  14. #include <dwarf-regs.h>
  15. struct pt_regs_dwarfnum {
  16. const char *name;
  17. unsigned int dwarfnum;
  18. };
  19. #define STR(s) #s
  20. #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
  21. #define GPR_DWARFNUM_NAME(num) \
  22. {.name = STR(%r##num), .dwarfnum = num}
  23. #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
  24. /*
  25. * Reference:
  26. * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
  27. */
  28. static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
  29. GPR_DWARFNUM_NAME(0),
  30. GPR_DWARFNUM_NAME(1),
  31. GPR_DWARFNUM_NAME(2),
  32. GPR_DWARFNUM_NAME(3),
  33. GPR_DWARFNUM_NAME(4),
  34. GPR_DWARFNUM_NAME(5),
  35. GPR_DWARFNUM_NAME(6),
  36. GPR_DWARFNUM_NAME(7),
  37. GPR_DWARFNUM_NAME(8),
  38. GPR_DWARFNUM_NAME(9),
  39. GPR_DWARFNUM_NAME(10),
  40. REG_DWARFNUM_NAME("%fp", 11),
  41. REG_DWARFNUM_NAME("%ip", 12),
  42. REG_DWARFNUM_NAME("%sp", 13),
  43. REG_DWARFNUM_NAME("%lr", 14),
  44. REG_DWARFNUM_NAME("%pc", 15),
  45. REG_DWARFNUM_END,
  46. };
  47. /**
  48. * get_arch_regstr() - lookup register name from it's DWARF register number
  49. * @n: the DWARF register number
  50. *
  51. * get_arch_regstr() returns the name of the register in struct
  52. * regdwarfnum_table from it's DWARF register number. If the register is not
  53. * found in the table, this returns NULL;
  54. */
  55. const char *get_arch_regstr(unsigned int n)
  56. {
  57. const struct pt_regs_dwarfnum *roff;
  58. for (roff = regdwarfnum_table; roff->name != NULL; roff++)
  59. if (roff->dwarfnum == n)
  60. return roff->name;
  61. return NULL;
  62. }