A dynamic tracer for Linux

arch-x86_64.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <assert.h>
  2. #include "type.h"
  3. #define arch_typedef(_a, _t) { \
  4. .ttype = T_TYPEDEF, \
  5. .tdef = { .name = #_a, .type = _t }, \
  6. }
  7. struct type t_s8 = arch_typedef(s8, &t_schar);
  8. struct type t_u8 = arch_typedef(u8, &t_uchar);
  9. struct type t_s16 = arch_typedef(s16, &t_sshort);
  10. struct type t_u16 = arch_typedef(u16, &t_ushort);
  11. struct type t_s32 = arch_typedef(s32, &t_sint);
  12. struct type t_u32 = arch_typedef(u32, &t_uint);
  13. struct type t_s64 = arch_typedef(s64, &t_slong);
  14. struct type t_u64 = arch_typedef(u64, &t_ulong);
  15. struct tfield f_pt_regs_fields[] = {
  16. { .name = "r15", .type = &t_ulong },
  17. { .name = "r14", .type = &t_ulong },
  18. { .name = "r13", .type = &t_ulong },
  19. { .name = "r12", .type = &t_ulong },
  20. { .name = "rbp", .type = &t_ulong },
  21. { .name = "rbx", .type = &t_ulong },
  22. { .name = "r11", .type = &t_ulong },
  23. { .name = "r10", .type = &t_ulong },
  24. { .name = "r9", .type = &t_ulong },
  25. { .name = "r8", .type = &t_ulong },
  26. { .name = "rax", .type = &t_ulong },
  27. { .name = "rcx", .type = &t_ulong },
  28. { .name = "rdx", .type = &t_ulong },
  29. { .name = "rsi", .type = &t_ulong },
  30. { .name = "rdi", .type = &t_ulong },
  31. { .name = "orig_rax", .type = &t_ulong },
  32. { .name = "rip", .type = &t_ulong },
  33. { .name = "cs", .type = &t_ulong },
  34. { .name = "eflags", .type = &t_ulong },
  35. { .name = "rsp", .type = &t_ulong },
  36. { .name = "ss", .type = &t_ulong },
  37. { .type = NULL }
  38. };
  39. struct type t_pt_regs = {
  40. .ttype = T_STRUCT,
  41. .sou = {
  42. .name = "pt_regs",
  43. .fields = f_pt_regs_fields,
  44. },
  45. };
  46. struct type *arch_types[] = {
  47. &t_s8, &t_u8,
  48. &t_s16, &t_u16,
  49. &t_s32, &t_u32,
  50. &t_s64, &t_u64,
  51. &t_pt_regs,
  52. NULL
  53. };
  54. const char *arch_register_argument(int num)
  55. {
  56. switch (num) {
  57. case 0: return "rdi";
  58. case 1: return "rsi";
  59. case 2: return "rdx";
  60. case 3: return "r10";
  61. case 4: return "r8";
  62. case 5: return "r9";
  63. }
  64. return NULL;
  65. }
  66. const char *arch_register_pc(void)
  67. {
  68. return "rip";
  69. }
  70. const char *arch_register_return(void)
  71. {
  72. return "rax";
  73. }
  74. __attribute__((constructor))
  75. static void arch_init(void)
  76. {
  77. type_add_list(arch_types);
  78. }