1 /* 2 * Copyright 2014 Google Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of 7 * the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but without any warranty; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14 15 #ifndef _GDB_H_ 16 #define _GDB_H_ 17 18 #include <stdint.h> 19 20 struct gdb_message 21 { 22 u8 *buf; 23 int used; 24 const int size; 25 }; 26 27 struct gdb_state 28 { 29 u8 signal; 30 u8 resumed : 1; 31 u8 connected : 1; 32 }; 33 extern struct gdb_state gdb_state; 34 35 typedef void (*gdb_command_handler)(struct gdb_message *command, 36 int offset, struct gdb_message *reply); 37 struct gdb_command 38 { 39 const char *str; 40 gdb_command_handler handler; 41 }; 42 extern struct gdb_command gdb_commands[]; 43 extern const int gdb_command_count; 44 45 /* arch/gdb.c */ 46 47 void gdb_arch_init(void); 48 void gdb_arch_enter(void); 49 50 int gdb_arch_set_single_step(int on); 51 52 void gdb_arch_encode_regs(struct gdb_message *message); 53 void gdb_arch_decode_regs(int offset, struct gdb_message *message); 54 55 /* gdb/transport.c */ 56 57 void gdb_transport_init(void); 58 void gdb_transport_teardown(void); 59 60 void gdb_message_encode_bytes(struct gdb_message *message, const void *data, 61 int length); 62 void gdb_message_decode_bytes(const struct gdb_message *message, int offset, 63 void *data, int length); 64 void gdb_message_encode_zero_bytes(struct gdb_message *message, int length); 65 66 void gdb_message_add_string(struct gdb_message *message, const char *string); 67 68 void gdb_message_encode_int(struct gdb_message *message, uintptr_t val); 69 uintptr_t gdb_message_decode_int(const struct gdb_message *message, int offset, 70 int length); 71 72 int gdb_message_tokenize(const struct gdb_message *message, int *offset); 73 74 void gdb_get_command(struct gdb_message *command); 75 void gdb_send_reply(const struct gdb_message *reply); 76 77 /* gdb/stub.c */ 78 79 void gdb_command_loop(uint8_t signal); 80 int gdb_handle_reentrant_exception(void); 81 82 enum { 83 GDB_SIG0 = 0, /* Signal 0 */ 84 GDB_SIGHUP = 1, /* Hangup */ 85 GDB_SIGINT = 2, /* Interrupt */ 86 GDB_SIGQUIT = 3, /* Quit */ 87 GDB_SIGILL = 4, /* Illegal instruction */ 88 GDB_SIGTRAP = 5, /* Trace/breakpoint trap */ 89 GDB_SIGABRT = 6, /* Aborted */ 90 GDB_SIGEMT = 7, /* Emulation trap */ 91 GDB_SIGFPE = 8, /* Arithmetic exception */ 92 GDB_SIGKILL = 9, /* Killed */ 93 GDB_SIGBUS = 10, /* Bus error */ 94 GDB_SIGSEGV = 11, /* Segmentation fault */ 95 GDB_SIGSYS = 12, /* Bad system call */ 96 GDB_SIGPIPE = 13, /* Broken pipe */ 97 GDB_SIGALRM = 14, /* Alarm clock */ 98 GDB_SIGTERM = 15, /* Terminated */ 99 GDB_SIGURG = 16, /* Urgent I/O condition */ 100 GDB_SIGSTOP = 17, /* Stopped (signal) */ 101 GDB_SIGTSTP = 18, /* Stopped (user) */ 102 GDB_SIGCONT = 19, /* Continued */ 103 GDB_SIGCHLD = 20, /* Child status changed */ 104 GDB_SIGTTIN = 21, /* Stopped (ttyinput) */ 105 GDB_SIGTTOU = 22, /* Stopped (ttyoutput) */ 106 GDB_SIGIO = 23, /* I/O possible */ 107 GDB_SIGXCPU = 24, /* CPU time limit exceeded */ 108 GDB_SIGXFSZ = 25, /* File size limit exceeded */ 109 GDB_SIGVTALRM = 26, /* Virtual timer expired */ 110 GDB_SIGPROF = 27, /* Profiling timer expired */ 111 GDB_SIGWINCH = 28, /* Window size changed */ 112 GDB_SIGLOST = 29, /* Resource lost */ 113 GDB_SIGUSR1 = 30, /* User defined signal1 */ 114 GDB_SUGUSR2 = 31, /* User defined signal2 */ 115 GDB_SIGPWR = 32, /* Powerfail/restart */ 116 GDB_SIGPOLL = 33, /* Pollable event occurred */ 117 GDB_SIGWIND = 34, /* SIGWIND */ 118 GDB_SIGPHONE = 35, /* SIGPHONE */ 119 GDB_SIGWAITING = 36, /* Process's LWPs are blocked */ 120 GDB_SIGLWP = 37, /* Signal LWP */ 121 GDB_SIGDANGER = 38, /* Swap space dangerously low */ 122 GDB_SIGGRANT = 39, /* Monitor mode granted */ 123 GDB_SIGRETRACT = 40, /* Need to relinquish monitor mode */ 124 GDB_SIGMSG = 41, /* Monitor mode data available */ 125 GDB_SIGSOUND = 42, /* Sound completed */ 126 GDB_SIGSAK = 43, /* Secure attention */ 127 GDB_SIGPRIO = 44, /* SIGPRIO */ 128 129 GDB_SIG33 = 45, /* Real-timeevent 33 */ 130 GDB_SIG34 = 46, /* Real-timeevent 34 */ 131 GDB_SIG35 = 47, /* Real-timeevent 35 */ 132 GDB_SIG36 = 48, /* Real-timeevent 36 */ 133 GDB_SIG37 = 49, /* Real-timeevent 37 */ 134 GDB_SIG38 = 50, /* Real-timeevent 38 */ 135 GDB_SIG39 = 51, /* Real-timeevent 39 */ 136 GDB_SIG40 = 52, /* Real-timeevent 40 */ 137 GDB_SIG41 = 53, /* Real-timeevent 41 */ 138 GDB_SIG42 = 54, /* Real-timeevent 42 */ 139 GDB_SIG43 = 55, /* Real-timeevent 43 */ 140 GDB_SIG44 = 56, /* Real-timeevent 44 */ 141 GDB_SIG45 = 57, /* Real-timeevent 45 */ 142 GDB_SIG46 = 58, /* Real-timeevent 46 */ 143 GDB_SIG47 = 59, /* Real-timeevent 47 */ 144 GDB_SIG48 = 60, /* Real-timeevent 48 */ 145 GDB_SIG49 = 61, /* Real-timeevent 49 */ 146 GDB_SIG50 = 62, /* Real-timeevent 50 */ 147 GDB_SIG51 = 63, /* Real-timeevent 51 */ 148 GDB_SIG52 = 64, /* Real-timeevent 52 */ 149 GDB_SIG53 = 65, /* Real-timeevent 53 */ 150 GDB_SIG54 = 66, /* Real-timeevent 54 */ 151 GDB_SIG55 = 67, /* Real-timeevent 55 */ 152 GDB_SIG56 = 68, /* Real-timeevent 56 */ 153 GDB_SIG57 = 69, /* Real-timeevent 57 */ 154 GDB_SIG58 = 70, /* Real-timeevent 58 */ 155 GDB_SIG59 = 71, /* Real-timeevent 59 */ 156 GDB_SIG60 = 72, /* Real-timeevent 60 */ 157 GDB_SIG61 = 73, /* Real-timeevent 61 */ 158 GDB_SIG62 = 74, /* Real-timeevent 62 */ 159 GDB_SIG63 = 75, /* Real-timeevent 63 */ 160 GDB_SIGCANCEL = 76, /* LWP internal signal */ 161 GDB_SIG32 = 77, /* Real-timeevent 32 */ 162 GDB_SIG64 = 78, /* Real-timeevent 64 */ 163 GDB_SIG65 = 79, /* Real-timeevent 65 */ 164 GDB_SIG66 = 80, /* Real-timeevent 66 */ 165 GDB_SIG67 = 81, /* Real-timeevent 67 */ 166 GDB_SIG68 = 82, /* Real-timeevent 68 */ 167 GDB_SIG69 = 83, /* Real-timeevent 69 */ 168 GDB_SIG70 = 84, /* Real-timeevent 70 */ 169 GDB_SIG71 = 85, /* Real-timeevent 71 */ 170 GDB_SIG72 = 86, /* Real-timeevent 72 */ 171 GDB_SIG73 = 87, /* Real-timeevent 73 */ 172 GDB_SIG74 = 88, /* Real-timeevent 74 */ 173 GDB_SIG75 = 89, /* Real-timeevent 75 */ 174 GDB_SIG76 = 90, /* Real-timeevent 76 */ 175 GDB_SIG77 = 91, /* Real-timeevent 77 */ 176 GDB_SIG78 = 92, /* Real-timeevent 78 */ 177 GDB_SIG79 = 93, /* Real-timeevent 79 */ 178 GDB_SIG80 = 94, /* Real-timeevent 80 */ 179 GDB_SIG81 = 95, /* Real-timeevent 81 */ 180 GDB_SIG82 = 96, /* Real-timeevent 82 */ 181 GDB_SIG83 = 97, /* Real-timeevent 83 */ 182 GDB_SIG84 = 98, /* Real-timeevent 84 */ 183 GDB_SIG85 = 99, /* Real-timeevent 85 */ 184 GDB_SIG86 = 100, /* Real-timeevent 86 */ 185 GDB_SIG87 = 101, /* Real-timeevent 87 */ 186 GDB_SIG88 = 102, /* Real-timeevent 88 */ 187 GDB_SIG89 = 103, /* Real-timeevent 89 */ 188 GDB_SIG90 = 104, /* Real-timeevent 90 */ 189 GDB_SIG91 = 105, /* Real-timeevent 91 */ 190 GDB_SIG92 = 106, /* Real-timeevent 92 */ 191 GDB_SIG93 = 107, /* Real-timeevent 93 */ 192 GDB_SIG94 = 108, /* Real-timeevent 94 */ 193 GDB_SIG95 = 109, /* Real-timeevent 95 */ 194 GDB_SIG96 = 110, /* Real-timeevent 96 */ 195 GDB_SIG97 = 111, /* Real-timeevent 97 */ 196 GDB_SIG98 = 112, /* Real-timeevent 98 */ 197 GDB_SIG99 = 113, /* Real-timeevent 99 */ 198 GDB_SIG100 = 114, /* Real-timeevent 100 */ 199 GDB_SIG101 = 115, /* Real-timeevent 101 */ 200 GDB_SIG102 = 116, /* Real-timeevent 102 */ 201 GDB_SIG103 = 117, /* Real-timeevent 103 */ 202 GDB_SIG104 = 118, /* Real-timeevent 104 */ 203 GDB_SIG105 = 119, /* Real-timeevent 105 */ 204 GDB_SIG106 = 120, /* Real-timeevent 106 */ 205 GDB_SIG107 = 121, /* Real-timeevent 107 */ 206 GDB_SIG108 = 122, /* Real-timeevent 108 */ 207 GDB_SIG109 = 123, /* Real-timeevent 109 */ 208 GDB_SIG110 = 124, /* Real-timeevent 110 */ 209 GDB_SIG111 = 125, /* Real-timeevent 111 */ 210 GDB_SIG112 = 126, /* Real-timeevent 112 */ 211 GDB_SIG113 = 127, /* Real-timeevent 113 */ 212 GDB_SIG114 = 128, /* Real-timeevent 114 */ 213 GDB_SIG115 = 129, /* Real-timeevent 115 */ 214 GDB_SIG116 = 130, /* Real-timeevent 116 */ 215 GDB_SIG117 = 131, /* Real-timeevent 117 */ 216 GDB_SIG118 = 132, /* Real-timeevent 118 */ 217 GDB_SIG119 = 133, /* Real-timeevent 119 */ 218 GDB_SIG120 = 134, /* Real-timeevent 120 */ 219 GDB_SIG121 = 135, /* Real-timeevent 121 */ 220 GDB_SIG122 = 136, /* Real-timeevent 122 */ 221 GDB_SIG123 = 137, /* Real-timeevent 123 */ 222 GDB_SIG124 = 138, /* Real-timeevent 124 */ 223 GDB_SIG125 = 139, /* Real-timeevent 125 */ 224 GDB_SIG126 = 140, /* Real-timeevent 126 */ 225 GDB_SIG127 = 141, /* Real-timeevent 127 */ 226 GDB_SIGINFO = 142, /* Information request */ 227 GDB_UNKNOWN1 = 43, /* Unknownsignal */ 228 GDB_DEFAULT = 144, /* error:defaultsignal */ 229 /* Machexceptions */ 230 GDB_EXC_BAD_ACCESS = 145, /* Could not access memory */ 231 GDB_EXC_BAD_INSTRCTION = 146, /* Illegal instruction/operand */ 232 GDB_EXC_ARITHMETIC = 147, /* Arithmetic exception */ 233 GDB_EXC_EMULATION = 148, /* Emulation instruction */ 234 GDB_EXC_SOFTWARE = 149, /* Software generated exception */ 235 GDB_EXC_BREAKPOINT = 150, /* Breakpoint */ 236 }; 237 238 #endif /* _GDB_H_ */ 239