gdb.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * This provides the callbacks and functions that KGDB needs to share between
  3. * the core, I/O and arch-specific portions.
  4. *
  5. * Author: Amit Kale <amitkale@linsyssoft.com> and
  6. * Tom Rini <trini@kernel.crashing.org>
  7. *
  8. * Copyright (C) 2008 Wind River Systems, Inc. *
  9. * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
  10. * This file is licensed under the terms of the GNU General Public License
  11. * version 2. This program is licensed "as is" without any warranty of any
  12. * kind, whether express or implied.
  13. */
  14. /* and, since gdb can't do error strings, well, we have this bullshit. */
  15. #define Einval "22"
  16. #define Enoent "02"
  17. #define Eio "05"
  18. extern int connected;
  19. extern int setting_breakpoint;
  20. extern int cpu_doing_single_step;
  21. extern struct task_struct *usethread;
  22. extern struct task_struct *contthread;
  23. extern char breakpoint[], ebreakpoint[];
  24. enum bptype {
  25. BP_BREAKPOINT = 0,
  26. BP_HARDWARE_BREAKPOINT,
  27. BP_WRITE_WATCHPOINT,
  28. BP_READ_WATCHPOINT,
  29. BP_ACCESS_WATCHPOINT,
  30. BP_POKE_BREAKPOINT,
  31. };
  32. enum bpstate {
  33. BP_UNDEFINED = 0,
  34. BP_REMOVED,
  35. BP_SET,
  36. BP_ACTIVE
  37. };
  38. /*
  39. * Copyright (C) 2001-2004 Amit S. Kale
  40. */
  41. /*
  42. * BUFMAX defines the maximum number of characters in inbound/outbound
  43. * buffers at least NUMREGBYTES*2 are needed for register packets
  44. * Longer buffer is needed to list all threads
  45. */
  46. #define BUFMAX 1024
  47. /*
  48. * Note that this register image is in a different order than
  49. * the register image that Linux produces at interrupt time.
  50. *
  51. * Linux's register image is defined by struct pt_regs in ptrace.h.
  52. * Just why GDB uses a different order is a historical mystery.
  53. */
  54. /* this is very x86_64 specific. Later, all code that messes with such things
  55. * needs to be in amd64.c
  56. * Please don't add an #ifdef here. Please
  57. */
  58. enum regnames {
  59. GDB_AX, /* 0 */
  60. GDB_BX, /* 1 */
  61. GDB_CX, /* 2 */
  62. GDB_DX, /* 3 */
  63. GDB_SI, /* 4 */
  64. GDB_DI, /* 5 */
  65. GDB_BP, /* 6 */
  66. GDB_SP, /* 7 */
  67. GDB_R8, /* 8 */
  68. GDB_R9, /* 9 */
  69. GDB_R10, /* 10 */
  70. GDB_R11, /* 11 */
  71. GDB_R12, /* 12 */
  72. GDB_R13, /* 13 */
  73. GDB_R14, /* 14 */
  74. GDB_R15, /* 15 */
  75. GDB_PC, /* 16 */
  76. GDB_PS, /* 17 */
  77. GDB_CS, /* 18 */
  78. GDB_SS, /* 19 */
  79. GDB_DS, /* 20 */
  80. GDB_ES, /* 21 */
  81. GDB_FS, /* 22 */
  82. GDB_GS, /* 23 */
  83. };
  84. // Again, this is very gdb-specific.
  85. extern char* regstrs[];
  86. #define GDB_ORIG_AX 57
  87. #define DBG_MAX_REG_NUM 24
  88. /* 17 64 bit regs and 5 32 bit regs */
  89. #define NUMREGBYTES ((17 * 8) + (5 * 4))
  90. struct bkpt {
  91. unsigned long bpt_addr;
  92. unsigned char saved_instr[16];
  93. enum bptype type;
  94. enum bpstate state;
  95. };
  96. extern uint64_t arch_get_pc(struct state *ks);
  97. extern char *dbg_get_reg(int regno, void *mem, uintptr_t *regs);
  98. extern int dbg_set_reg(int regno, void *mem, uintptr_t *regs);
  99. /**
  100. * arch_handle_exception - Handle architecture specific GDB packets.
  101. * @vector: The error vector of the exception that happened.
  102. * @signo: The signal number of the exception that happened.
  103. * @err_code: The error code of the exception that happened.
  104. * @remcom_in_buffer: The buffer of the packet we have read.
  105. * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
  106. * @regs: The &struct pt_regs of the current process.
  107. *
  108. * This function MUST handle the 'c' and 's' command packets,
  109. * as well packets to set / remove a hardware breakpoint, if used.
  110. * If there are additional packets which the hardware needs to handle,
  111. * they are handled here. The code should return -1 if it wants to
  112. * process more packets, and a %0 or %1 if it wants to exit from the
  113. * kgdb callback.
  114. */
  115. extern int
  116. arch_handle_exception(int vector, int signo, int err_code,
  117. char *remcom_in_buffer,
  118. char *remcom_out_buffer,
  119. uintptr_t*regs);
  120. /**
  121. * arch_set_pc - Generic call back to the program counter
  122. * @regs: Current &struct pt_regs.
  123. * @pc: The new value for the program counter
  124. *
  125. * This function handles updating the program counter and requires an
  126. * architecture specific implementation.
  127. */
  128. extern void arch_set_pc(uintptr_t *regs, unsigned long pc);
  129. /* Optional functions. */
  130. extern int validate_break_address(unsigned long addr);
  131. extern char *arch_set_breakpoint(struct state *ks, struct bkpt *bpt);
  132. extern char *arch_remove_breakpoint(struct state *ks, struct bkpt *bpt);
  133. // Leave this for now but we should probably just use the chan abstraction
  134. // for this nonsense.
  135. /**
  136. * struct io - Describe the interface for an I/O driver to talk with KGDB.
  137. * @name: Name of the I/O driver.
  138. * @read_char: Pointer to a function that will return one char.
  139. * @write_char: Pointer to a function that will write one char.
  140. * @flush: Pointer to a function that will flush any pending writes.
  141. * @init: Pointer to a function that will initialize the device.
  142. * @pre_exception: Pointer to a function that will do any prep work for
  143. * the I/O driver.
  144. * @post_exception: Pointer to a function that will do any cleanup work
  145. * for the I/O driver.
  146. * @is_console: 1 if the end device is a console 0 if the I/O device is
  147. * not a console
  148. */
  149. struct io {
  150. const char *name;
  151. int (*read_char) (void);
  152. void (*write_char) (uint8_t);
  153. void (*flush) (void);
  154. int (*init) (void);
  155. void (*pre_exception) (void);
  156. void (*post_exception) (void);
  157. int is_console;
  158. };
  159. int hex2long(char **ptr, unsigned long *long_val);
  160. char *mem2hex(unsigned char *mem, char *buf, int count);
  161. char *hex2mem(char *buf, unsigned char *mem, int count);
  162. void gdb_cmd_reg_get(struct state *ks);
  163. void gdb_cmd_reg_set(struct state *ks);
  164. uint64_t arch_get_reg(struct state *ks, int regnum);
  165. extern int isremovedbreak(unsigned long addr);
  166. extern void schedule_breakpoint(void);
  167. extern int
  168. handle_exception(int ex_vector, int signo, int err_code,
  169. uintptr_t *regs);