You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gdbmach.h 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef GDBMACH_H
  2. #define GDBMACH_H
  3. /** @file
  4. *
  5. * GDB architecture specifics
  6. *
  7. * This file declares functions for manipulating the machine state and
  8. * debugging context.
  9. *
  10. */
  11. #include <stdint.h>
  12. typedef unsigned long gdbreg_t;
  13. /* Register snapshot */
  14. enum {
  15. GDBMACH_RAX,
  16. GDBMACH_RBX,
  17. GDBMACH_RCX,
  18. GDBMACH_RDX,
  19. GDBMACH_RSI,
  20. GDBMACH_RDI,
  21. GDBMACH_RBP,
  22. GDBMACH_RSP,
  23. GDBMACH_R8,
  24. GDBMACH_R9,
  25. GDBMACH_R10,
  26. GDBMACH_R11,
  27. GDBMACH_R12,
  28. GDBMACH_R13,
  29. GDBMACH_R14,
  30. GDBMACH_R15,
  31. GDBMACH_RIP,
  32. GDBMACH_RFLAGS,
  33. GDBMACH_CS,
  34. GDBMACH_SS,
  35. GDBMACH_DS,
  36. GDBMACH_ES,
  37. GDBMACH_FS,
  38. GDBMACH_GS,
  39. GDBMACH_NREGS,
  40. };
  41. #define GDBMACH_SIZEOF_REGS ( GDBMACH_NREGS * sizeof ( gdbreg_t ) )
  42. /* Breakpoint types */
  43. enum {
  44. GDBMACH_BPMEM,
  45. GDBMACH_BPHW,
  46. GDBMACH_WATCH,
  47. GDBMACH_RWATCH,
  48. GDBMACH_AWATCH,
  49. };
  50. /* Exception vectors */
  51. extern void gdbmach_sigfpe ( void );
  52. extern void gdbmach_sigtrap ( void );
  53. extern void gdbmach_sigstkflt ( void );
  54. extern void gdbmach_sigill ( void );
  55. static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
  56. regs[GDBMACH_RIP] = pc;
  57. }
  58. static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
  59. regs[GDBMACH_RFLAGS] &= ~( 1 << 8 ); /* Trace Flag (TF) */
  60. regs[GDBMACH_RFLAGS] |= ( step << 8 );
  61. }
  62. static inline void gdbmach_breakpoint ( void ) {
  63. __asm__ __volatile__ ( "int $3\n" );
  64. }
  65. extern int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len,
  66. int enable );
  67. extern void gdbmach_init ( void );
  68. #endif /* GDBMACH_H */