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