gdb.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. extern int bpsize;
  25. enum bptype {
  26. BP_BREAKPOINT = 0,
  27. BP_HARDWARE_BREAKPOINT,
  28. BP_WRITE_WATCHPOINT,
  29. BP_READ_WATCHPOINT,
  30. BP_ACCESS_WATCHPOINT,
  31. BP_POKE_BREAKPOINT,
  32. };
  33. enum bpstate {
  34. BP_UNDEFINED = 0,
  35. BP_REMOVED,
  36. BP_SET,
  37. BP_ACTIVE
  38. };
  39. /*
  40. * Copyright (C) 2001-2004 Amit S. Kale
  41. */
  42. /*
  43. * BUFMAX defines the maximum number of characters in inbound/outbound
  44. * buffers at least NUMREGBYTES*2 are needed for register packets
  45. * Longer buffer is needed to list all threads
  46. */
  47. #define BUFMAX 1024
  48. /*
  49. * Note that this register image is in a different order than
  50. * the register image that Linux produces at interrupt time.
  51. *
  52. * Linux's register image is defined by struct pt_regs in ptrace.h.
  53. * Just why GDB uses a different order is a historical mystery.
  54. */
  55. /* this is very x86_64 specific. Later, all code that messes with such things
  56. * needs to be in amd64.c
  57. * Please don't add an #ifdef here. Please
  58. */
  59. enum regnames {
  60. GDB_AX, /* 0 */
  61. GDB_BX, /* 1 */
  62. GDB_CX, /* 2 */
  63. GDB_DX, /* 3 */
  64. GDB_SI, /* 4 */
  65. GDB_DI, /* 5 */
  66. GDB_BP, /* 6 */
  67. GDB_SP, /* 7 */
  68. GDB_R8, /* 8 */
  69. GDB_R9, /* 9 */
  70. GDB_R10, /* 10 */
  71. GDB_R11, /* 11 */
  72. GDB_R12, /* 12 */
  73. GDB_R13, /* 13 */
  74. GDB_R14, /* 14 */
  75. GDB_R15, /* 15 */
  76. GDB_PC, /* 16 */
  77. GDB_PS, /* 17 */
  78. GDB_CS, /* 18 */
  79. GDB_SS, /* 19 */
  80. GDB_DS, /* 20 */
  81. GDB_ES, /* 21 */
  82. GDB_FS, /* 22 */
  83. GDB_GS, /* 23 */
  84. };
  85. #define GDB_ORIG_AX 57
  86. #define DBG_MAX_REG_NUM 24
  87. /* 17 64 bit regs and 5 32 bit regs */
  88. #define NUMREGBYTES ((17 * 8) + (5 * 4))
  89. struct bkpt {
  90. unsigned long bpt_addr;
  91. unsigned char saved_instr[16];
  92. enum bptype type;
  93. enum bpstate state;
  94. };
  95. extern char *dbg_get_reg(int regno, void *mem, uintptr_t *regs);
  96. extern int dbg_set_reg(int regno, void *mem, uintptr_t *regs);
  97. /**
  98. * arch_handle_exception - Handle architecture specific GDB packets.
  99. * @vector: The error vector of the exception that happened.
  100. * @signo: The signal number of the exception that happened.
  101. * @err_code: The error code of the exception that happened.
  102. * @remcom_in_buffer: The buffer of the packet we have read.
  103. * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
  104. * @regs: The &struct pt_regs of the current process.
  105. *
  106. * This function MUST handle the 'c' and 's' command packets,
  107. * as well packets to set / remove a hardware breakpoint, if used.
  108. * If there are additional packets which the hardware needs to handle,
  109. * they are handled here. The code should return -1 if it wants to
  110. * process more packets, and a %0 or %1 if it wants to exit from the
  111. * kgdb callback.
  112. */
  113. extern int
  114. arch_handle_exception(int vector, int signo, int err_code,
  115. char *remcom_in_buffer,
  116. char *remcom_out_buffer,
  117. uintptr_t*regs);
  118. /**
  119. * arch_set_pc - Generic call back to the program counter
  120. * @regs: Current &struct pt_regs.
  121. * @pc: The new value for the program counter
  122. *
  123. * This function handles updating the program counter and requires an
  124. * architecture specific implementation.
  125. */
  126. extern void arch_set_pc(uintptr_t *regs, unsigned long pc);
  127. /* Optional functions. */
  128. extern int validate_break_address(unsigned long addr);
  129. extern char *arch_set_breakpoint(struct state *ks, struct bkpt *bpt);
  130. extern char *arch_remove_breakpoint(struct state *ks, struct bkpt *bpt);
  131. // I'm pretty sure we don't need this. In the kernel these will be defined in the arch.c file.
  132. // I can't see the need for ops. That's some weird linux thinking artifact I guess.
  133. /**
  134. * struct arch - Describe architecture specific values.
  135. * @gdb_bpt_instr: The instruction to trigger a breakpoint.
  136. * @flags: Flags for the breakpoint, currently just %HW_BREAKPOINT.
  137. * @set_breakpoint: Allow an architecture to specify how to set a software
  138. * breakpoint.
  139. * @remove_breakpoint: Allow an architecture to specify how to remove a
  140. * software breakpoint.
  141. * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
  142. * breakpoint.
  143. * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
  144. * hardware breakpoint.
  145. * @disable_hw_break: Allow an architecture to specify how to disable
  146. * hardware breakpoints for a single cpu.
  147. * @remove_all_hw_break: Allow an architecture to specify how to remove all
  148. * hardware breakpoints.
  149. * @correct_hw_break: Allow an architecture to specify how to correct the
  150. * hardware debug registers.
  151. * @enable_nmi: Manage NMI-triggered entry to KGDB
  152. */
  153. struct arch {
  154. unsigned char gdb_bpt_instr[16];
  155. unsigned long flags;
  156. int (*set_breakpoint)(unsigned long, char *);
  157. int (*remove_breakpoint)(unsigned long, char *);
  158. int (*set_hw_breakpoint)(unsigned long, int, enum bptype);
  159. int (*remove_hw_breakpoint)(unsigned long, int, enum bptype);
  160. void (*disable_hw_break)(uintptr_t *regs);
  161. void (*remove_all_hw_break)(void);
  162. void (*correct_hw_break)(void);
  163. };
  164. // Leave this for now but we should probably just use the chan abstraction
  165. // for this nonsense.
  166. /**
  167. * struct io - Describe the interface for an I/O driver to talk with KGDB.
  168. * @name: Name of the I/O driver.
  169. * @read_char: Pointer to a function that will return one char.
  170. * @write_char: Pointer to a function that will write one char.
  171. * @flush: Pointer to a function that will flush any pending writes.
  172. * @init: Pointer to a function that will initialize the device.
  173. * @pre_exception: Pointer to a function that will do any prep work for
  174. * the I/O driver.
  175. * @post_exception: Pointer to a function that will do any cleanup work
  176. * for the I/O driver.
  177. * @is_console: 1 if the end device is a console 0 if the I/O device is
  178. * not a console
  179. */
  180. struct io {
  181. const char *name;
  182. int (*read_char) (void);
  183. void (*write_char) (uint8_t);
  184. void (*flush) (void);
  185. int (*init) (void);
  186. void (*pre_exception) (void);
  187. void (*post_exception) (void);
  188. int is_console;
  189. };
  190. int hex2long(char **ptr, unsigned long *long_val);
  191. char *mem2hex(unsigned char *mem, char *buf, int count);
  192. char *hex2mem(char *buf, unsigned char *mem, int count);
  193. void gdb_cmd_reg_get(struct state *ks);
  194. void gdb_cmd_reg_set(struct state *ks);
  195. extern int isremovedbreak(unsigned long addr);
  196. extern void schedule_breakpoint(void);
  197. extern int
  198. handle_exception(int ex_vector, int signo, int err_code,
  199. uintptr_t *regs);
  200. extern int single_step;
  201. extern int active;
  202. void gdbinit(void);