Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Remote target communications for serial-line targets in custom GDB protocol |
8926118c | 2 | |
197e01b6 | 3 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, |
24b06219 | 4 | 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
29182b13 | 5 | Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b JM |
7 | This file is part of GDB. |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 | Boston, MA 02110-1301, USA. */ | |
c5aa993b | 23 | |
23860348 | 24 | /* See the GDB User Guide for details of the GDB remote protocol. */ |
c5aa993b | 25 | |
c906108c SS |
26 | #include "defs.h" |
27 | #include "gdb_string.h" | |
28 | #include <ctype.h> | |
29 | #include <fcntl.h> | |
c906108c SS |
30 | #include "inferior.h" |
31 | #include "bfd.h" | |
32 | #include "symfile.h" | |
60250e8b | 33 | #include "exceptions.h" |
c906108c | 34 | #include "target.h" |
c5aa993b | 35 | /*#include "terminal.h" */ |
c906108c SS |
36 | #include "gdbcmd.h" |
37 | #include "objfiles.h" | |
38 | #include "gdb-stabs.h" | |
39 | #include "gdbthread.h" | |
c2c6d25f | 40 | #include "remote.h" |
4e052eda | 41 | #include "regcache.h" |
fd0407d6 | 42 | #include "value.h" |
1ff9c3d6 | 43 | #include "gdb_assert.h" |
6867ae3e | 44 | #include "observer.h" |
a77053c2 | 45 | #include "solib.h" |
c906108c | 46 | |
7a292a7a | 47 | #include <ctype.h> |
9846de1b | 48 | #include <sys/time.h> |
c906108c | 49 | |
43ff13b4 | 50 | #include "event-loop.h" |
c2c6d25f | 51 | #include "event-top.h" |
2acceee2 | 52 | #include "inf-loop.h" |
43ff13b4 | 53 | |
c906108c SS |
54 | #include <signal.h> |
55 | #include "serial.h" | |
56 | ||
6240bebf MS |
57 | #include "gdbcore.h" /* for exec_bfd */ |
58 | ||
449092f6 CV |
59 | #include "remote-fileio.h" |
60 | ||
23860348 | 61 | /* Prototypes for local functions. */ |
6426a772 JM |
62 | static void cleanup_sigint_signal_handler (void *dummy); |
63 | static void initialize_sigint_signal_handler (void); | |
d9fcf2fb | 64 | static int getpkt_sane (char *buf, long sizeof_buf, int forever); |
6426a772 | 65 | |
a14ed312 KB |
66 | static void handle_remote_sigint (int); |
67 | static void handle_remote_sigint_twice (int); | |
68 | static void async_remote_interrupt (gdb_client_data); | |
69 | void async_remote_interrupt_twice (gdb_client_data); | |
43ff13b4 | 70 | |
a14ed312 | 71 | static void build_remote_gdbarch_data (void); |
0f71a2f6 | 72 | |
a14ed312 | 73 | static void remote_files_info (struct target_ops *ignore); |
c906108c | 74 | |
a14ed312 | 75 | static void remote_prepare_to_store (void); |
c906108c | 76 | |
a14ed312 | 77 | static void remote_fetch_registers (int regno); |
c906108c | 78 | |
39f77062 KB |
79 | static void remote_resume (ptid_t ptid, int step, |
80 | enum target_signal siggnal); | |
81 | static void remote_async_resume (ptid_t ptid, int step, | |
a14ed312 | 82 | enum target_signal siggnal); |
a14ed312 KB |
83 | static void remote_open (char *name, int from_tty); |
84 | static void remote_async_open (char *name, int from_tty); | |
c906108c | 85 | |
a14ed312 KB |
86 | static void extended_remote_open (char *name, int from_tty); |
87 | static void extended_remote_async_open (char *name, int from_tty); | |
c906108c | 88 | |
92d1e331 DJ |
89 | static void remote_open_1 (char *, int, struct target_ops *, int extended_p, |
90 | int async_p); | |
c906108c | 91 | |
a14ed312 | 92 | static void remote_close (int quitting); |
c906108c | 93 | |
a14ed312 | 94 | static void remote_store_registers (int regno); |
c906108c | 95 | |
a14ed312 KB |
96 | static void remote_mourn (void); |
97 | static void remote_async_mourn (void); | |
c906108c | 98 | |
a14ed312 | 99 | static void extended_remote_restart (void); |
c906108c | 100 | |
a14ed312 | 101 | static void extended_remote_mourn (void); |
c906108c | 102 | |
a14ed312 | 103 | static void remote_mourn_1 (struct target_ops *); |
c906108c | 104 | |
c2d11a7d | 105 | static void remote_send (char *buf, long sizeof_buf); |
c906108c | 106 | |
a14ed312 | 107 | static int readchar (int timeout); |
c906108c | 108 | |
39f77062 KB |
109 | static ptid_t remote_wait (ptid_t ptid, |
110 | struct target_waitstatus *status); | |
111 | static ptid_t remote_async_wait (ptid_t ptid, | |
112 | struct target_waitstatus *status); | |
c906108c | 113 | |
a14ed312 KB |
114 | static void remote_kill (void); |
115 | static void remote_async_kill (void); | |
c906108c | 116 | |
a14ed312 | 117 | static int tohex (int nib); |
c906108c | 118 | |
a14ed312 | 119 | static void remote_detach (char *args, int from_tty); |
c906108c | 120 | |
a14ed312 | 121 | static void remote_interrupt (int signo); |
c906108c | 122 | |
a14ed312 | 123 | static void remote_interrupt_twice (int signo); |
7a292a7a | 124 | |
a14ed312 | 125 | static void interrupt_query (void); |
c906108c | 126 | |
a14ed312 | 127 | static void set_thread (int, int); |
c906108c | 128 | |
39f77062 | 129 | static int remote_thread_alive (ptid_t); |
c906108c | 130 | |
a14ed312 | 131 | static void get_offsets (void); |
c906108c | 132 | |
c2d11a7d | 133 | static long read_frame (char *buf, long sizeof_buf); |
c906108c | 134 | |
5a168c78 | 135 | static int remote_insert_breakpoint (CORE_ADDR, bfd_byte *); |
c906108c | 136 | |
5a168c78 | 137 | static int remote_remove_breakpoint (CORE_ADDR, bfd_byte *); |
c906108c | 138 | |
a14ed312 | 139 | static int hexnumlen (ULONGEST num); |
c906108c | 140 | |
a14ed312 | 141 | static void init_remote_ops (void); |
c906108c | 142 | |
a14ed312 | 143 | static void init_extended_remote_ops (void); |
c906108c | 144 | |
a14ed312 | 145 | static void remote_stop (void); |
c906108c | 146 | |
a14ed312 | 147 | static int ishex (int ch, int *val); |
c906108c | 148 | |
a14ed312 | 149 | static int stubhex (int ch); |
c906108c | 150 | |
a14ed312 | 151 | static int hexnumstr (char *, ULONGEST); |
c906108c | 152 | |
a14ed312 | 153 | static int hexnumnstr (char *, ULONGEST, int); |
2df3850c | 154 | |
a14ed312 | 155 | static CORE_ADDR remote_address_masked (CORE_ADDR); |
c906108c | 156 | |
a14ed312 | 157 | static void print_packet (char *); |
c906108c | 158 | |
a14ed312 | 159 | static unsigned long crc32 (unsigned char *, int, unsigned int); |
c906108c | 160 | |
a14ed312 | 161 | static void compare_sections_command (char *, int); |
c906108c | 162 | |
a14ed312 | 163 | static void packet_command (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static int stub_unpack_int (char *buff, int fieldlength); |
c906108c | 166 | |
39f77062 | 167 | static ptid_t remote_current_thread (ptid_t oldptid); |
c906108c | 168 | |
a14ed312 | 169 | static void remote_find_new_threads (void); |
c906108c | 170 | |
a14ed312 | 171 | static void record_currthread (int currthread); |
c906108c | 172 | |
30559e10 | 173 | static int fromhex (int a); |
c906108c | 174 | |
cfd77fa1 | 175 | static int hex2bin (const char *hex, gdb_byte *bin, int count); |
c906108c | 176 | |
cfd77fa1 | 177 | static int bin2hex (const gdb_byte *bin, char *hex, int count); |
234fa6d1 | 178 | |
a14ed312 | 179 | static int putpkt_binary (char *buf, int cnt); |
c906108c | 180 | |
a14ed312 | 181 | static void check_binary_download (CORE_ADDR addr); |
c906108c | 182 | |
5a2468f5 | 183 | struct packet_config; |
5a2468f5 | 184 | |
a14ed312 | 185 | static void show_packet_config_cmd (struct packet_config *config); |
5a2468f5 | 186 | |
d471ea57 | 187 | static void update_packet_config (struct packet_config *config); |
5a2468f5 | 188 | |
a14ed312 | 189 | void _initialize_remote (void); |
c906108c | 190 | |
694f61fb | 191 | /* Description of the remote protocol. Strictly speaking, when the |
d01949b6 AC |
192 | target is open()ed, remote.c should create a per-target description |
193 | of the remote protocol using that target's architecture. | |
ce2826aa | 194 | Unfortunately, the target stack doesn't include local state. For |
d01949b6 AC |
195 | the moment keep the information in the target's architecture |
196 | object. Sigh.. */ | |
197 | ||
ad10f812 AC |
198 | struct packet_reg |
199 | { | |
200 | long offset; /* Offset into G packet. */ | |
201 | long regnum; /* GDB's internal register number. */ | |
202 | LONGEST pnum; /* Remote protocol register number. */ | |
b323314b | 203 | int in_g_packet; /* Always part of G packet. */ |
23860348 MS |
204 | /* long size in bytes; == register_size (current_gdbarch, regnum); |
205 | at present. */ | |
ad10f812 AC |
206 | /* char *name; == REGISTER_NAME (regnum); at present. */ |
207 | }; | |
208 | ||
d01949b6 AC |
209 | struct remote_state |
210 | { | |
ad10f812 AC |
211 | /* Description of the remote protocol registers. */ |
212 | long sizeof_g_packet; | |
b323314b AC |
213 | |
214 | /* Description of the remote protocol registers indexed by REGNUM | |
215 | (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */ | |
216 | struct packet_reg *regs; | |
ad10f812 | 217 | |
d01949b6 AC |
218 | /* This is the size (in chars) of the first response to the ``g'' |
219 | packet. It is used as a heuristic when determining the maximum | |
220 | size of memory-read and memory-write packets. A target will | |
221 | typically only reserve a buffer large enough to hold the ``g'' | |
222 | packet. The size does not include packet overhead (headers and | |
23860348 | 223 | trailers). */ |
d01949b6 AC |
224 | long actual_register_packet_size; |
225 | ||
226 | /* This is the maximum size (in chars) of a non read/write packet. | |
23860348 | 227 | It is also used as a cap on the size of read/write packets. */ |
d01949b6 AC |
228 | long remote_packet_size; |
229 | }; | |
230 | ||
3c3bea1c | 231 | |
d01949b6 AC |
232 | /* Handle for retreving the remote protocol data from gdbarch. */ |
233 | static struct gdbarch_data *remote_gdbarch_data_handle; | |
234 | ||
235 | static struct remote_state * | |
5ae5f592 | 236 | get_remote_state (void) |
d01949b6 | 237 | { |
451fbdda | 238 | return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle); |
d01949b6 AC |
239 | } |
240 | ||
241 | static void * | |
242 | init_remote_state (struct gdbarch *gdbarch) | |
243 | { | |
244 | int regnum; | |
e5e78edc | 245 | struct remote_state *rs = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_state); |
d01949b6 | 246 | |
46845f5e | 247 | rs->sizeof_g_packet = 0; |
ad10f812 | 248 | |
b323314b | 249 | /* Assume a 1:1 regnum<->pnum table. */ |
e5e78edc AC |
250 | rs->regs = GDBARCH_OBSTACK_CALLOC (gdbarch, NUM_REGS + NUM_PSEUDO_REGS, |
251 | struct packet_reg); | |
b323314b | 252 | for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
ad10f812 | 253 | { |
b323314b AC |
254 | struct packet_reg *r = &rs->regs[regnum]; |
255 | r->pnum = regnum; | |
256 | r->regnum = regnum; | |
62700349 | 257 | r->offset = DEPRECATED_REGISTER_BYTE (regnum); |
b323314b | 258 | r->in_g_packet = (regnum < NUM_REGS); |
ad10f812 | 259 | /* ...name = REGISTER_NAME (regnum); */ |
7d58c67d | 260 | |
23860348 | 261 | /* Compute packet size by accumulating the size of all registers. */ |
46845f5e KB |
262 | if (regnum < NUM_REGS) |
263 | rs->sizeof_g_packet += register_size (current_gdbarch, regnum); | |
ad10f812 AC |
264 | } |
265 | ||
d01949b6 AC |
266 | /* Default maximum number of characters in a packet body. Many |
267 | remote stubs have a hardwired buffer size of 400 bytes | |
268 | (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used | |
269 | as the maximum packet-size to ensure that the packet and an extra | |
270 | NUL character can always fit in the buffer. This stops GDB | |
271 | trashing stubs that try to squeeze an extra NUL into what is | |
23860348 | 272 | already a full buffer (As of 1999-12-04 that was most stubs. */ |
d01949b6 AC |
273 | rs->remote_packet_size = 400 - 1; |
274 | ||
ad10f812 AC |
275 | /* Should rs->sizeof_g_packet needs more space than the |
276 | default, adjust the size accordingly. Remember that each byte is | |
277 | encoded as two characters. 32 is the overhead for the packet | |
278 | header / footer. NOTE: cagney/1999-10-26: I suspect that 8 | |
d01949b6 | 279 | (``$NN:G...#NN'') is a better guess, the below has been padded a |
23860348 | 280 | little. */ |
ad10f812 AC |
281 | if (rs->sizeof_g_packet > ((rs->remote_packet_size - 32) / 2)) |
282 | rs->remote_packet_size = (rs->sizeof_g_packet * 2 + 32); | |
802188a7 | 283 | |
23860348 | 284 | /* This one is filled in when a ``g'' packet is received. */ |
d01949b6 AC |
285 | rs->actual_register_packet_size = 0; |
286 | ||
287 | return rs; | |
288 | } | |
289 | ||
ad10f812 AC |
290 | static struct packet_reg * |
291 | packet_reg_from_regnum (struct remote_state *rs, long regnum) | |
292 | { | |
b323314b AC |
293 | if (regnum < 0 && regnum >= NUM_REGS + NUM_PSEUDO_REGS) |
294 | return NULL; | |
295 | else | |
ad10f812 | 296 | { |
b323314b AC |
297 | struct packet_reg *r = &rs->regs[regnum]; |
298 | gdb_assert (r->regnum == regnum); | |
299 | return r; | |
ad10f812 | 300 | } |
ad10f812 AC |
301 | } |
302 | ||
303 | static struct packet_reg * | |
304 | packet_reg_from_pnum (struct remote_state *rs, LONGEST pnum) | |
305 | { | |
b323314b AC |
306 | int i; |
307 | for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) | |
ad10f812 | 308 | { |
b323314b AC |
309 | struct packet_reg *r = &rs->regs[i]; |
310 | if (r->pnum == pnum) | |
311 | return r; | |
ad10f812 AC |
312 | } |
313 | return NULL; | |
d01949b6 AC |
314 | } |
315 | ||
3c3bea1c GS |
316 | /* FIXME: graces/2002-08-08: These variables should eventually be |
317 | bound to an instance of the target object (as in gdbarch-tdep()), | |
318 | when such a thing exists. */ | |
319 | ||
320 | /* This is set to the data address of the access causing the target | |
321 | to stop for a watchpoint. */ | |
322 | static CORE_ADDR remote_watch_data_address; | |
323 | ||
23860348 | 324 | /* This is non-zero if taregt stopped for a watchpoint. */ |
3c3bea1c GS |
325 | static int remote_stopped_by_watchpoint_p; |
326 | ||
c906108c SS |
327 | |
328 | static struct target_ops remote_ops; | |
329 | ||
330 | static struct target_ops extended_remote_ops; | |
331 | ||
43ff13b4 | 332 | /* Temporary target ops. Just like the remote_ops and |
23860348 | 333 | extended_remote_ops, but with asynchronous support. */ |
43ff13b4 JM |
334 | static struct target_ops remote_async_ops; |
335 | ||
336 | static struct target_ops extended_async_remote_ops; | |
337 | ||
6426a772 JM |
338 | /* FIXME: cagney/1999-09-23: Even though getpkt was called with |
339 | ``forever'' still use the normal timeout mechanism. This is | |
340 | currently used by the ASYNC code to guarentee that target reads | |
341 | during the initial connect always time-out. Once getpkt has been | |
342 | modified to return a timeout indication and, in turn | |
343 | remote_wait()/wait_for_inferior() have gained a timeout parameter | |
23860348 | 344 | this can go away. */ |
6426a772 JM |
345 | static int wait_forever_enabled_p = 1; |
346 | ||
347 | ||
c906108c SS |
348 | /* This variable chooses whether to send a ^C or a break when the user |
349 | requests program interruption. Although ^C is usually what remote | |
350 | systems expect, and that is the default here, sometimes a break is | |
351 | preferable instead. */ | |
352 | ||
353 | static int remote_break; | |
354 | ||
c906108c SS |
355 | /* Descriptor for I/O to remote machine. Initialize it to NULL so that |
356 | remote_open knows that we don't have a file open when the program | |
357 | starts. */ | |
819cc324 | 358 | static struct serial *remote_desc = NULL; |
c906108c | 359 | |
c906108c SS |
360 | /* This variable sets the number of bits in an address that are to be |
361 | sent in a memory ("M" or "m") packet. Normally, after stripping | |
362 | leading zeros, the entire address would be sent. This variable | |
363 | restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The | |
364 | initial implementation of remote.c restricted the address sent in | |
365 | memory packets to ``host::sizeof long'' bytes - (typically 32 | |
366 | bits). Consequently, for 64 bit targets, the upper 32 bits of an | |
367 | address was never sent. Since fixing this bug may cause a break in | |
368 | some remote targets this variable is principly provided to | |
23860348 | 369 | facilitate backward compatibility. */ |
c906108c SS |
370 | |
371 | static int remote_address_size; | |
372 | ||
6426a772 JM |
373 | /* Tempoary to track who currently owns the terminal. See |
374 | target_async_terminal_* for more details. */ | |
375 | ||
376 | static int remote_async_terminal_ours_p; | |
377 | ||
11cf8741 | 378 | \f |
11cf8741 | 379 | /* User configurable variables for the number of characters in a |
24b06219 | 380 | memory read/write packet. MIN (rs->remote_packet_size, |
ad10f812 | 381 | rs->sizeof_g_packet) is the default. Some targets need smaller |
24b06219 | 382 | values (fifo overruns, et.al.) and some users need larger values |
ad10f812 AC |
383 | (speed up transfers). The variables ``preferred_*'' (the user |
384 | request), ``current_*'' (what was actually set) and ``forced_*'' | |
23860348 | 385 | (Positive - a soft limit, negative - a hard limit). */ |
11cf8741 JM |
386 | |
387 | struct memory_packet_config | |
388 | { | |
389 | char *name; | |
390 | long size; | |
391 | int fixed_p; | |
392 | }; | |
393 | ||
394 | /* Compute the current size of a read/write packet. Since this makes | |
395 | use of ``actual_register_packet_size'' the computation is dynamic. */ | |
396 | ||
397 | static long | |
398 | get_memory_packet_size (struct memory_packet_config *config) | |
399 | { | |
d01949b6 | 400 | struct remote_state *rs = get_remote_state (); |
11cf8741 JM |
401 | /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk |
402 | law?) that some hosts don't cope very well with large alloca() | |
403 | calls. Eventually the alloca() code will be replaced by calls to | |
404 | xmalloc() and make_cleanups() allowing this restriction to either | |
23860348 | 405 | be lifted or removed. */ |
11cf8741 JM |
406 | #ifndef MAX_REMOTE_PACKET_SIZE |
407 | #define MAX_REMOTE_PACKET_SIZE 16384 | |
408 | #endif | |
3de11b2e | 409 | /* NOTE: 20 ensures we can write at least one byte. */ |
11cf8741 | 410 | #ifndef MIN_REMOTE_PACKET_SIZE |
3de11b2e | 411 | #define MIN_REMOTE_PACKET_SIZE 20 |
11cf8741 JM |
412 | #endif |
413 | long what_they_get; | |
414 | if (config->fixed_p) | |
415 | { | |
416 | if (config->size <= 0) | |
417 | what_they_get = MAX_REMOTE_PACKET_SIZE; | |
418 | else | |
419 | what_they_get = config->size; | |
420 | } | |
421 | else | |
422 | { | |
24b06219 | 423 | what_they_get = rs->remote_packet_size; |
23860348 | 424 | /* Limit the packet to the size specified by the user. */ |
11cf8741 JM |
425 | if (config->size > 0 |
426 | && what_they_get > config->size) | |
427 | what_they_get = config->size; | |
23860348 | 428 | /* Limit it to the size of the targets ``g'' response. */ |
d01949b6 AC |
429 | if ((rs->actual_register_packet_size) > 0 |
430 | && what_they_get > (rs->actual_register_packet_size)) | |
431 | what_they_get = (rs->actual_register_packet_size); | |
11cf8741 JM |
432 | } |
433 | if (what_they_get > MAX_REMOTE_PACKET_SIZE) | |
434 | what_they_get = MAX_REMOTE_PACKET_SIZE; | |
435 | if (what_they_get < MIN_REMOTE_PACKET_SIZE) | |
436 | what_they_get = MIN_REMOTE_PACKET_SIZE; | |
437 | return what_they_get; | |
438 | } | |
439 | ||
440 | /* Update the size of a read/write packet. If they user wants | |
23860348 | 441 | something really big then do a sanity check. */ |
11cf8741 JM |
442 | |
443 | static void | |
444 | set_memory_packet_size (char *args, struct memory_packet_config *config) | |
445 | { | |
446 | int fixed_p = config->fixed_p; | |
447 | long size = config->size; | |
448 | if (args == NULL) | |
8a3fe4f8 | 449 | error (_("Argument required (integer, `fixed' or `limited').")); |
11cf8741 JM |
450 | else if (strcmp (args, "hard") == 0 |
451 | || strcmp (args, "fixed") == 0) | |
452 | fixed_p = 1; | |
453 | else if (strcmp (args, "soft") == 0 | |
454 | || strcmp (args, "limit") == 0) | |
455 | fixed_p = 0; | |
456 | else | |
457 | { | |
458 | char *end; | |
459 | size = strtoul (args, &end, 0); | |
460 | if (args == end) | |
8a3fe4f8 | 461 | error (_("Invalid %s (bad syntax)."), config->name); |
11cf8741 JM |
462 | #if 0 |
463 | /* Instead of explicitly capping the size of a packet to | |
464 | MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is | |
465 | instead allowed to set the size to something arbitrarily | |
23860348 | 466 | large. */ |
11cf8741 | 467 | if (size > MAX_REMOTE_PACKET_SIZE) |
8a3fe4f8 | 468 | error (_("Invalid %s (too large)."), config->name); |
11cf8741 JM |
469 | #endif |
470 | } | |
23860348 | 471 | /* Extra checks? */ |
11cf8741 JM |
472 | if (fixed_p && !config->fixed_p) |
473 | { | |
e2e0b3e5 AC |
474 | if (! query (_("The target may not be able to correctly handle a %s\n" |
475 | "of %ld bytes. Change the packet size? "), | |
11cf8741 | 476 | config->name, size)) |
8a3fe4f8 | 477 | error (_("Packet size not changed.")); |
11cf8741 | 478 | } |
23860348 | 479 | /* Update the config. */ |
11cf8741 JM |
480 | config->fixed_p = fixed_p; |
481 | config->size = size; | |
482 | } | |
483 | ||
484 | static void | |
485 | show_memory_packet_size (struct memory_packet_config *config) | |
486 | { | |
a3f17187 | 487 | printf_filtered (_("The %s is %ld. "), config->name, config->size); |
11cf8741 | 488 | if (config->fixed_p) |
a3f17187 | 489 | printf_filtered (_("Packets are fixed at %ld bytes.\n"), |
11cf8741 JM |
490 | get_memory_packet_size (config)); |
491 | else | |
a3f17187 | 492 | printf_filtered (_("Packets are limited to %ld bytes.\n"), |
11cf8741 JM |
493 | get_memory_packet_size (config)); |
494 | } | |
495 | ||
496 | static struct memory_packet_config memory_write_packet_config = | |
497 | { | |
498 | "memory-write-packet-size", | |
499 | }; | |
500 | ||
501 | static void | |
502 | set_memory_write_packet_size (char *args, int from_tty) | |
503 | { | |
504 | set_memory_packet_size (args, &memory_write_packet_config); | |
505 | } | |
506 | ||
507 | static void | |
508 | show_memory_write_packet_size (char *args, int from_tty) | |
509 | { | |
510 | show_memory_packet_size (&memory_write_packet_config); | |
511 | } | |
512 | ||
513 | static long | |
514 | get_memory_write_packet_size (void) | |
515 | { | |
516 | return get_memory_packet_size (&memory_write_packet_config); | |
517 | } | |
518 | ||
519 | static struct memory_packet_config memory_read_packet_config = | |
520 | { | |
521 | "memory-read-packet-size", | |
522 | }; | |
523 | ||
524 | static void | |
525 | set_memory_read_packet_size (char *args, int from_tty) | |
526 | { | |
527 | set_memory_packet_size (args, &memory_read_packet_config); | |
528 | } | |
529 | ||
530 | static void | |
531 | show_memory_read_packet_size (char *args, int from_tty) | |
532 | { | |
533 | show_memory_packet_size (&memory_read_packet_config); | |
534 | } | |
535 | ||
536 | static long | |
537 | get_memory_read_packet_size (void) | |
538 | { | |
d01949b6 | 539 | struct remote_state *rs = get_remote_state (); |
11cf8741 JM |
540 | long size = get_memory_packet_size (&memory_read_packet_config); |
541 | /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an | |
542 | extra buffer size argument before the memory read size can be | |
24b06219 MK |
543 | increased beyond RS->remote_packet_size. */ |
544 | if (size > rs->remote_packet_size) | |
545 | size = rs->remote_packet_size; | |
11cf8741 JM |
546 | return size; |
547 | } | |
548 | ||
11cf8741 | 549 | \f |
5a2468f5 JM |
550 | /* Generic configuration support for packets the stub optionally |
551 | supports. Allows the user to specify the use of the packet as well | |
23860348 | 552 | as allowing GDB to auto-detect support in the remote stub. */ |
5a2468f5 JM |
553 | |
554 | enum packet_support | |
555 | { | |
556 | PACKET_SUPPORT_UNKNOWN = 0, | |
557 | PACKET_ENABLE, | |
558 | PACKET_DISABLE | |
559 | }; | |
560 | ||
5a2468f5 JM |
561 | struct packet_config |
562 | { | |
5a2468f5 JM |
563 | char *name; |
564 | char *title; | |
7f19b9a2 | 565 | enum auto_boolean detect; |
5a2468f5 JM |
566 | enum packet_support support; |
567 | }; | |
568 | ||
d471ea57 | 569 | /* Analyze a packet's return value and update the packet config |
23860348 | 570 | accordingly. */ |
d471ea57 AC |
571 | |
572 | enum packet_result | |
573 | { | |
574 | PACKET_ERROR, | |
575 | PACKET_OK, | |
576 | PACKET_UNKNOWN | |
577 | }; | |
578 | ||
5a2468f5 | 579 | static void |
d471ea57 | 580 | update_packet_config (struct packet_config *config) |
5a2468f5 | 581 | { |
d471ea57 AC |
582 | switch (config->detect) |
583 | { | |
7f19b9a2 | 584 | case AUTO_BOOLEAN_TRUE: |
d471ea57 AC |
585 | config->support = PACKET_ENABLE; |
586 | break; | |
7f19b9a2 | 587 | case AUTO_BOOLEAN_FALSE: |
d471ea57 AC |
588 | config->support = PACKET_DISABLE; |
589 | break; | |
7f19b9a2 | 590 | case AUTO_BOOLEAN_AUTO: |
d471ea57 AC |
591 | config->support = PACKET_SUPPORT_UNKNOWN; |
592 | break; | |
593 | } | |
5a2468f5 JM |
594 | } |
595 | ||
596 | static void | |
fba45db2 | 597 | show_packet_config_cmd (struct packet_config *config) |
5a2468f5 JM |
598 | { |
599 | char *support = "internal-error"; | |
600 | switch (config->support) | |
601 | { | |
602 | case PACKET_ENABLE: | |
603 | support = "enabled"; | |
604 | break; | |
605 | case PACKET_DISABLE: | |
606 | support = "disabled"; | |
607 | break; | |
608 | case PACKET_SUPPORT_UNKNOWN: | |
609 | support = "unknown"; | |
610 | break; | |
611 | } | |
612 | switch (config->detect) | |
613 | { | |
7f19b9a2 | 614 | case AUTO_BOOLEAN_AUTO: |
a3f17187 | 615 | printf_filtered (_("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n"), |
5a2468f5 JM |
616 | config->name, config->title, support); |
617 | break; | |
7f19b9a2 AC |
618 | case AUTO_BOOLEAN_TRUE: |
619 | case AUTO_BOOLEAN_FALSE: | |
a3f17187 | 620 | printf_filtered (_("Support for remote protocol `%s' (%s) packet is currently %s.\n"), |
5a2468f5 | 621 | config->name, config->title, support); |
8e248173 | 622 | break; |
5a2468f5 JM |
623 | } |
624 | } | |
625 | ||
626 | static void | |
d471ea57 AC |
627 | add_packet_config_cmd (struct packet_config *config, |
628 | char *name, | |
629 | char *title, | |
e9e68a56 | 630 | cmd_sfunc_ftype *set_func, |
08546159 | 631 | show_value_ftype *show_func, |
d471ea57 AC |
632 | struct cmd_list_element **set_remote_list, |
633 | struct cmd_list_element **show_remote_list, | |
634 | int legacy) | |
635 | { | |
5a2468f5 JM |
636 | char *set_doc; |
637 | char *show_doc; | |
d471ea57 | 638 | char *cmd_name; |
3ed07be4 | 639 | |
5a2468f5 JM |
640 | config->name = name; |
641 | config->title = title; | |
7f19b9a2 | 642 | config->detect = AUTO_BOOLEAN_AUTO; |
8e248173 | 643 | config->support = PACKET_SUPPORT_UNKNOWN; |
b435e160 AC |
644 | set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet", |
645 | name, title); | |
646 | show_doc = xstrprintf ("Show current use of remote protocol `%s' (%s) packet", | |
647 | name, title); | |
d471ea57 | 648 | /* set/show TITLE-packet {auto,on,off} */ |
b435e160 | 649 | cmd_name = xstrprintf ("%s-packet", title); |
e9e68a56 | 650 | add_setshow_auto_boolean_cmd (cmd_name, class_obscure, |
2c5b56ce | 651 | &config->detect, set_doc, show_doc, NULL, /* help_doc */ |
e9e68a56 AC |
652 | set_func, show_func, |
653 | set_remote_list, show_remote_list); | |
23860348 | 654 | /* set/show remote NAME-packet {auto,on,off} -- legacy. */ |
d471ea57 AC |
655 | if (legacy) |
656 | { | |
657 | char *legacy_name; | |
b435e160 | 658 | legacy_name = xstrprintf ("%s-packet", name); |
d471ea57 AC |
659 | add_alias_cmd (legacy_name, cmd_name, class_obscure, 0, |
660 | set_remote_list); | |
661 | add_alias_cmd (legacy_name, cmd_name, class_obscure, 0, | |
662 | show_remote_list); | |
663 | } | |
5a2468f5 JM |
664 | } |
665 | ||
d471ea57 AC |
666 | static enum packet_result |
667 | packet_ok (const char *buf, struct packet_config *config) | |
5a2468f5 | 668 | { |
d471ea57 | 669 | if (buf[0] != '\0') |
5a2468f5 | 670 | { |
d471ea57 | 671 | /* The stub recognized the packet request. Check that the |
23860348 | 672 | operation succeeded. */ |
d471ea57 AC |
673 | switch (config->support) |
674 | { | |
675 | case PACKET_SUPPORT_UNKNOWN: | |
676 | if (remote_debug) | |
677 | fprintf_unfiltered (gdb_stdlog, | |
678 | "Packet %s (%s) is supported\n", | |
679 | config->name, config->title); | |
680 | config->support = PACKET_ENABLE; | |
681 | break; | |
682 | case PACKET_DISABLE: | |
8e65ff28 | 683 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 684 | _("packet_ok: attempt to use a disabled packet")); |
d471ea57 AC |
685 | break; |
686 | case PACKET_ENABLE: | |
687 | break; | |
688 | } | |
689 | if (buf[0] == 'O' && buf[1] == 'K' && buf[2] == '\0') | |
23860348 | 690 | /* "OK" - definitly OK. */ |
d471ea57 AC |
691 | return PACKET_OK; |
692 | if (buf[0] == 'E' | |
693 | && isxdigit (buf[1]) && isxdigit (buf[2]) | |
694 | && buf[3] == '\0') | |
23860348 | 695 | /* "Enn" - definitly an error. */ |
d471ea57 | 696 | return PACKET_ERROR; |
23860348 | 697 | /* The packet may or may not be OK. Just assume it is. */ |
d471ea57 AC |
698 | return PACKET_OK; |
699 | } | |
700 | else | |
701 | { | |
23860348 | 702 | /* The stub does not support the packet. */ |
d471ea57 AC |
703 | switch (config->support) |
704 | { | |
705 | case PACKET_ENABLE: | |
7f19b9a2 | 706 | if (config->detect == AUTO_BOOLEAN_AUTO) |
d471ea57 | 707 | /* If the stub previously indicated that the packet was |
23860348 | 708 | supported then there is a protocol error.. */ |
8a3fe4f8 | 709 | error (_("Protocol error: %s (%s) conflicting enabled responses."), |
d471ea57 AC |
710 | config->name, config->title); |
711 | else | |
23860348 | 712 | /* The user set it wrong. */ |
8a3fe4f8 | 713 | error (_("Enabled packet %s (%s) not recognized by stub"), |
d471ea57 AC |
714 | config->name, config->title); |
715 | break; | |
716 | case PACKET_SUPPORT_UNKNOWN: | |
717 | if (remote_debug) | |
718 | fprintf_unfiltered (gdb_stdlog, | |
719 | "Packet %s (%s) is NOT supported\n", | |
720 | config->name, config->title); | |
721 | config->support = PACKET_DISABLE; | |
722 | break; | |
723 | case PACKET_DISABLE: | |
724 | break; | |
725 | } | |
726 | return PACKET_UNKNOWN; | |
5a2468f5 JM |
727 | } |
728 | } | |
729 | ||
23860348 | 730 | /* Should we try the 'vCont' (descriptive resume) request? */ |
506fb367 DJ |
731 | static struct packet_config remote_protocol_vcont; |
732 | ||
733 | static void | |
734 | set_remote_protocol_vcont_packet_cmd (char *args, int from_tty, | |
735 | struct cmd_list_element *c) | |
736 | { | |
737 | update_packet_config (&remote_protocol_vcont); | |
738 | } | |
739 | ||
740 | static void | |
08546159 AC |
741 | show_remote_protocol_vcont_packet_cmd (struct ui_file *file, int from_tty, |
742 | struct cmd_list_element *c, | |
743 | const char *value) | |
506fb367 DJ |
744 | { |
745 | show_packet_config_cmd (&remote_protocol_vcont); | |
746 | } | |
747 | ||
23860348 | 748 | /* Should we try the 'qSymbol' (target symbol lookup service) request? */ |
dc8acb97 MS |
749 | static struct packet_config remote_protocol_qSymbol; |
750 | ||
751 | static void | |
752 | set_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty, | |
753 | struct cmd_list_element *c) | |
754 | { | |
755 | update_packet_config (&remote_protocol_qSymbol); | |
756 | } | |
757 | ||
758 | static void | |
08546159 AC |
759 | show_remote_protocol_qSymbol_packet_cmd (struct ui_file *file, int from_tty, |
760 | struct cmd_list_element *c, | |
761 | const char *value) | |
dc8acb97 MS |
762 | { |
763 | show_packet_config_cmd (&remote_protocol_qSymbol); | |
764 | } | |
765 | ||
5a2468f5 JM |
766 | /* Should we try the 'P' (set register) request? */ |
767 | ||
768 | static struct packet_config remote_protocol_P; | |
769 | ||
770 | static void | |
fba45db2 KB |
771 | set_remote_protocol_P_packet_cmd (char *args, int from_tty, |
772 | struct cmd_list_element *c) | |
5a2468f5 | 773 | { |
d471ea57 | 774 | update_packet_config (&remote_protocol_P); |
5a2468f5 JM |
775 | } |
776 | ||
777 | static void | |
08546159 AC |
778 | show_remote_protocol_P_packet_cmd (struct ui_file *file, int from_tty, |
779 | struct cmd_list_element *c, | |
780 | const char *value) | |
5a2468f5 JM |
781 | { |
782 | show_packet_config_cmd (&remote_protocol_P); | |
783 | } | |
784 | ||
d471ea57 AC |
785 | /* Should we try one of the 'Z' requests? */ |
786 | ||
787 | enum Z_packet_type | |
788 | { | |
789 | Z_PACKET_SOFTWARE_BP, | |
790 | Z_PACKET_HARDWARE_BP, | |
791 | Z_PACKET_WRITE_WP, | |
792 | Z_PACKET_READ_WP, | |
793 | Z_PACKET_ACCESS_WP, | |
794 | NR_Z_PACKET_TYPES | |
795 | }; | |
96baa820 | 796 | |
d471ea57 AC |
797 | static struct packet_config remote_protocol_Z[NR_Z_PACKET_TYPES]; |
798 | ||
799 | /* FIXME: Instead of having all these boiler plate functions, the | |
23860348 | 800 | command callback should include a context argument. */ |
d471ea57 AC |
801 | |
802 | static void | |
803 | set_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty, | |
804 | struct cmd_list_element *c) | |
805 | { | |
806 | update_packet_config (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]); | |
807 | } | |
808 | ||
809 | static void | |
08546159 AC |
810 | show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file *file, int from_tty, |
811 | struct cmd_list_element *c, | |
812 | const char *value) | |
d471ea57 AC |
813 | { |
814 | show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]); | |
815 | } | |
816 | ||
817 | static void | |
818 | set_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty, | |
819 | struct cmd_list_element *c) | |
820 | { | |
821 | update_packet_config (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]); | |
822 | } | |
823 | ||
824 | static void | |
08546159 AC |
825 | show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file *file, int from_tty, |
826 | struct cmd_list_element *c, | |
827 | const char *value) | |
d471ea57 AC |
828 | { |
829 | show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]); | |
830 | } | |
831 | ||
832 | static void | |
833 | set_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty, | |
834 | struct cmd_list_element *c) | |
835 | { | |
836 | update_packet_config (&remote_protocol_Z[Z_PACKET_WRITE_WP]); | |
837 | } | |
838 | ||
839 | static void | |
08546159 AC |
840 | show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file *file, int from_tty, |
841 | struct cmd_list_element *c, | |
842 | const char *value) | |
d471ea57 AC |
843 | { |
844 | show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP]); | |
845 | } | |
846 | ||
847 | static void | |
848 | set_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty, | |
849 | struct cmd_list_element *c) | |
850 | { | |
851 | update_packet_config (&remote_protocol_Z[Z_PACKET_READ_WP]); | |
852 | } | |
853 | ||
854 | static void | |
08546159 AC |
855 | show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file *file, int from_tty, |
856 | struct cmd_list_element *c, | |
857 | const char *value) | |
d471ea57 AC |
858 | { |
859 | show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP]); | |
860 | } | |
861 | ||
862 | static void | |
863 | set_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty, | |
864 | struct cmd_list_element *c) | |
865 | { | |
866 | update_packet_config (&remote_protocol_Z[Z_PACKET_ACCESS_WP]); | |
867 | } | |
868 | ||
869 | static void | |
08546159 AC |
870 | show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file *file, int from_tty, |
871 | struct cmd_list_element *c, | |
872 | const char *value) | |
d471ea57 AC |
873 | { |
874 | show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP]); | |
875 | } | |
876 | ||
877 | /* For compatibility with older distributions. Provide a ``set remote | |
23860348 | 878 | Z-packet ...'' command that updates all the Z packet types. */ |
d471ea57 | 879 | |
7f19b9a2 | 880 | static enum auto_boolean remote_Z_packet_detect; |
96baa820 JM |
881 | |
882 | static void | |
fba45db2 KB |
883 | set_remote_protocol_Z_packet_cmd (char *args, int from_tty, |
884 | struct cmd_list_element *c) | |
96baa820 | 885 | { |
d471ea57 AC |
886 | int i; |
887 | for (i = 0; i < NR_Z_PACKET_TYPES; i++) | |
888 | { | |
889 | remote_protocol_Z[i].detect = remote_Z_packet_detect; | |
890 | update_packet_config (&remote_protocol_Z[i]); | |
891 | } | |
96baa820 JM |
892 | } |
893 | ||
894 | static void | |
08546159 AC |
895 | show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty, |
896 | struct cmd_list_element *c, | |
897 | const char *value) | |
96baa820 | 898 | { |
d471ea57 AC |
899 | int i; |
900 | for (i = 0; i < NR_Z_PACKET_TYPES; i++) | |
901 | { | |
902 | show_packet_config_cmd (&remote_protocol_Z[i]); | |
903 | } | |
96baa820 JM |
904 | } |
905 | ||
906 | /* Should we try the 'X' (remote binary download) packet? | |
907 | ||
908 | This variable (available to the user via "set remote X-packet") | |
909 | dictates whether downloads are sent in binary (via the 'X' packet). | |
910 | We assume that the stub can, and attempt to do it. This will be | |
911 | cleared if the stub does not understand it. This switch is still | |
912 | needed, though in cases when the packet is supported in the stub, | |
913 | but the connection does not allow it (i.e., 7-bit serial connection | |
23860348 | 914 | only). */ |
96baa820 JM |
915 | |
916 | static struct packet_config remote_protocol_binary_download; | |
917 | ||
9d1f7ab2 MS |
918 | /* Should we try the 'ThreadInfo' query packet? |
919 | ||
920 | This variable (NOT available to the user: auto-detect only!) | |
921 | determines whether GDB will use the new, simpler "ThreadInfo" | |
922 | query or the older, more complex syntax for thread queries. | |
802188a7 | 923 | This is an auto-detect variable (set to true at each connect, |
9d1f7ab2 MS |
924 | and set to false when the target fails to recognize it). */ |
925 | ||
926 | static int use_threadinfo_query; | |
927 | static int use_threadextra_query; | |
928 | ||
96baa820 JM |
929 | static void |
930 | set_remote_protocol_binary_download_cmd (char *args, | |
931 | int from_tty, | |
932 | struct cmd_list_element *c) | |
933 | { | |
d471ea57 | 934 | update_packet_config (&remote_protocol_binary_download); |
96baa820 JM |
935 | } |
936 | ||
937 | static void | |
08546159 AC |
938 | show_remote_protocol_binary_download_cmd (struct ui_file *file, int from_tty, |
939 | struct cmd_list_element *c, | |
940 | const char *value) | |
96baa820 JM |
941 | { |
942 | show_packet_config_cmd (&remote_protocol_binary_download); | |
943 | } | |
944 | ||
23860348 | 945 | /* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */ |
802188a7 RM |
946 | static struct packet_config remote_protocol_qPart_auxv; |
947 | ||
948 | static void | |
949 | set_remote_protocol_qPart_auxv_packet_cmd (char *args, int from_tty, | |
950 | struct cmd_list_element *c) | |
951 | { | |
952 | update_packet_config (&remote_protocol_qPart_auxv); | |
953 | } | |
954 | ||
955 | static void | |
08546159 AC |
956 | show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file *file, int from_tty, |
957 | struct cmd_list_element *c, | |
958 | const char *value) | |
802188a7 RM |
959 | { |
960 | show_packet_config_cmd (&remote_protocol_qPart_auxv); | |
961 | } | |
962 | ||
38691318 KB |
963 | /* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */ |
964 | static struct packet_config remote_protocol_qGetTLSAddr; | |
965 | ||
966 | static void | |
967 | set_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty, | |
968 | struct cmd_list_element *c) | |
969 | { | |
970 | update_packet_config (&remote_protocol_qGetTLSAddr); | |
971 | } | |
972 | ||
973 | static void | |
974 | show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file *file, int from_tty, | |
975 | struct cmd_list_element *c, | |
976 | const char *value) | |
977 | { | |
978 | show_packet_config_cmd (&remote_protocol_qGetTLSAddr); | |
979 | } | |
980 | ||
b96ec7ac AC |
981 | static struct packet_config remote_protocol_p; |
982 | ||
983 | static void | |
984 | set_remote_protocol_p_packet_cmd (char *args, int from_tty, | |
985 | struct cmd_list_element *c) | |
986 | { | |
987 | update_packet_config (&remote_protocol_p); | |
988 | } | |
989 | ||
990 | static void | |
08546159 AC |
991 | show_remote_protocol_p_packet_cmd (struct ui_file *file, int from_tty, |
992 | struct cmd_list_element *c, | |
993 | const char *value) | |
b96ec7ac AC |
994 | { |
995 | show_packet_config_cmd (&remote_protocol_p); | |
996 | } | |
997 | ||
998 | ||
c906108c | 999 | |
23860348 | 1000 | /* Tokens for use by the asynchronous signal handlers for SIGINT. */ |
ae44c0c4 AC |
1001 | static void *sigint_remote_twice_token; |
1002 | static void *sigint_remote_token; | |
43ff13b4 | 1003 | |
c906108c SS |
1004 | /* These are pointers to hook functions that may be set in order to |
1005 | modify resume/wait behavior for a particular architecture. */ | |
1006 | ||
9a4105ab AC |
1007 | void (*deprecated_target_resume_hook) (void); |
1008 | void (*deprecated_target_wait_loop_hook) (void); | |
c906108c SS |
1009 | \f |
1010 | ||
c5aa993b | 1011 | |
c906108c SS |
1012 | /* These are the threads which we last sent to the remote system. |
1013 | -1 for all or -2 for not sent yet. */ | |
1014 | static int general_thread; | |
cce74817 | 1015 | static int continue_thread; |
c906108c SS |
1016 | |
1017 | /* Call this function as a result of | |
1018 | 1) A halt indication (T packet) containing a thread id | |
1019 | 2) A direct query of currthread | |
1020 | 3) Successful execution of set thread | |
1021 | */ | |
1022 | ||
1023 | static void | |
fba45db2 | 1024 | record_currthread (int currthread) |
c906108c | 1025 | { |
c906108c | 1026 | general_thread = currthread; |
cce74817 | 1027 | |
c906108c SS |
1028 | /* If this is a new thread, add it to GDB's thread list. |
1029 | If we leave it up to WFI to do this, bad things will happen. */ | |
39f77062 | 1030 | if (!in_thread_list (pid_to_ptid (currthread))) |
0f71a2f6 | 1031 | { |
39f77062 | 1032 | add_thread (pid_to_ptid (currthread)); |
8b93c638 | 1033 | ui_out_text (uiout, "[New "); |
39f77062 | 1034 | ui_out_text (uiout, target_pid_to_str (pid_to_ptid (currthread))); |
8b93c638 | 1035 | ui_out_text (uiout, "]\n"); |
0f71a2f6 | 1036 | } |
c906108c SS |
1037 | } |
1038 | ||
1039 | #define MAGIC_NULL_PID 42000 | |
1040 | ||
1041 | static void | |
fba45db2 | 1042 | set_thread (int th, int gen) |
c906108c | 1043 | { |
d01949b6 AC |
1044 | struct remote_state *rs = get_remote_state (); |
1045 | char *buf = alloca (rs->remote_packet_size); | |
cce74817 | 1046 | int state = gen ? general_thread : continue_thread; |
c906108c SS |
1047 | |
1048 | if (state == th) | |
1049 | return; | |
1050 | ||
1051 | buf[0] = 'H'; | |
1052 | buf[1] = gen ? 'g' : 'c'; | |
1053 | if (th == MAGIC_NULL_PID) | |
1054 | { | |
1055 | buf[2] = '0'; | |
1056 | buf[3] = '\0'; | |
1057 | } | |
1058 | else if (th < 0) | |
ecbc58df | 1059 | xsnprintf (&buf[2], rs->remote_packet_size - 2, "-%x", -th); |
c906108c | 1060 | else |
ecbc58df | 1061 | xsnprintf (&buf[2], rs->remote_packet_size - 2, "%x", th); |
c906108c | 1062 | putpkt (buf); |
24b06219 | 1063 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c | 1064 | if (gen) |
c5aa993b | 1065 | general_thread = th; |
c906108c | 1066 | else |
cce74817 | 1067 | continue_thread = th; |
c906108c SS |
1068 | } |
1069 | \f | |
1070 | /* Return nonzero if the thread TH is still alive on the remote system. */ | |
1071 | ||
1072 | static int | |
39f77062 | 1073 | remote_thread_alive (ptid_t ptid) |
c906108c | 1074 | { |
39f77062 | 1075 | int tid = PIDGET (ptid); |
cce74817 | 1076 | char buf[16]; |
c906108c | 1077 | |
cce74817 | 1078 | if (tid < 0) |
ecbc58df | 1079 | xsnprintf (buf, sizeof (buf), "T-%08x", -tid); |
c906108c | 1080 | else |
ecbc58df | 1081 | xsnprintf (buf, sizeof (buf), "T%08x", tid); |
c906108c | 1082 | putpkt (buf); |
c2d11a7d | 1083 | getpkt (buf, sizeof (buf), 0); |
c906108c SS |
1084 | return (buf[0] == 'O' && buf[1] == 'K'); |
1085 | } | |
1086 | ||
1087 | /* About these extended threadlist and threadinfo packets. They are | |
1088 | variable length packets but, the fields within them are often fixed | |
1089 | length. They are redundent enough to send over UDP as is the | |
1090 | remote protocol in general. There is a matching unit test module | |
1091 | in libstub. */ | |
1092 | ||
cce74817 JM |
1093 | #define OPAQUETHREADBYTES 8 |
1094 | ||
1095 | /* a 64 bit opaque identifier */ | |
1096 | typedef unsigned char threadref[OPAQUETHREADBYTES]; | |
1097 | ||
23860348 MS |
1098 | /* WARNING: This threadref data structure comes from the remote O.S., |
1099 | libstub protocol encoding, and remote.c. it is not particularly | |
1100 | changable. */ | |
cce74817 JM |
1101 | |
1102 | /* Right now, the internal structure is int. We want it to be bigger. | |
1103 | Plan to fix this. | |
c5aa993b | 1104 | */ |
cce74817 | 1105 | |
23860348 | 1106 | typedef int gdb_threadref; /* Internal GDB thread reference. */ |
cce74817 | 1107 | |
9d1f7ab2 | 1108 | /* gdb_ext_thread_info is an internal GDB data structure which is |
23860348 | 1109 | equivalint to the reply of the remote threadinfo packet. */ |
cce74817 JM |
1110 | |
1111 | struct gdb_ext_thread_info | |
c5aa993b | 1112 | { |
23860348 MS |
1113 | threadref threadid; /* External form of thread reference. */ |
1114 | int active; /* Has state interesting to GDB? | |
1115 | regs, stack. */ | |
1116 | char display[256]; /* Brief state display, name, | |
cedea757 | 1117 | blocked/suspended. */ |
23860348 MS |
1118 | char shortname[32]; /* To be used to name threads. */ |
1119 | char more_display[256]; /* Long info, statistics, queue depth, | |
1120 | whatever. */ | |
c5aa993b | 1121 | }; |
cce74817 JM |
1122 | |
1123 | /* The volume of remote transfers can be limited by submitting | |
1124 | a mask containing bits specifying the desired information. | |
1125 | Use a union of these values as the 'selection' parameter to | |
1126 | get_thread_info. FIXME: Make these TAG names more thread specific. | |
c5aa993b | 1127 | */ |
cce74817 JM |
1128 | |
1129 | #define TAG_THREADID 1 | |
1130 | #define TAG_EXISTS 2 | |
1131 | #define TAG_DISPLAY 4 | |
1132 | #define TAG_THREADNAME 8 | |
c5aa993b | 1133 | #define TAG_MOREDISPLAY 16 |
cce74817 | 1134 | |
23860348 | 1135 | #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2) |
c906108c | 1136 | |
b2dd6311 | 1137 | char *unpack_varlen_hex (char *buff, ULONGEST *result); |
cce74817 | 1138 | |
a14ed312 | 1139 | static char *unpack_nibble (char *buf, int *val); |
cce74817 | 1140 | |
a14ed312 | 1141 | static char *pack_nibble (char *buf, int nibble); |
cce74817 | 1142 | |
23860348 | 1143 | static char *pack_hex_byte (char *pkt, int /* unsigned char */ byte); |
cce74817 | 1144 | |
a14ed312 | 1145 | static char *unpack_byte (char *buf, int *value); |
cce74817 | 1146 | |
a14ed312 | 1147 | static char *pack_int (char *buf, int value); |
cce74817 | 1148 | |
a14ed312 | 1149 | static char *unpack_int (char *buf, int *value); |
cce74817 | 1150 | |
a14ed312 | 1151 | static char *unpack_string (char *src, char *dest, int length); |
cce74817 | 1152 | |
23860348 | 1153 | static char *pack_threadid (char *pkt, threadref *id); |
cce74817 | 1154 | |
23860348 | 1155 | static char *unpack_threadid (char *inbuf, threadref *id); |
cce74817 | 1156 | |
23860348 | 1157 | void int_to_threadref (threadref *id, int value); |
cce74817 | 1158 | |
23860348 | 1159 | static int threadref_to_int (threadref *ref); |
cce74817 | 1160 | |
23860348 | 1161 | static void copy_threadref (threadref *dest, threadref *src); |
cce74817 | 1162 | |
23860348 | 1163 | static int threadmatch (threadref *dest, threadref *src); |
cce74817 | 1164 | |
23860348 MS |
1165 | static char *pack_threadinfo_request (char *pkt, int mode, |
1166 | threadref *id); | |
cce74817 | 1167 | |
a14ed312 | 1168 | static int remote_unpack_thread_info_response (char *pkt, |
23860348 | 1169 | threadref *expectedref, |
a14ed312 KB |
1170 | struct gdb_ext_thread_info |
1171 | *info); | |
cce74817 JM |
1172 | |
1173 | ||
23860348 MS |
1174 | static int remote_get_threadinfo (threadref *threadid, |
1175 | int fieldset, /*TAG mask */ | |
a14ed312 | 1176 | struct gdb_ext_thread_info *info); |
cce74817 | 1177 | |
a14ed312 KB |
1178 | static char *pack_threadlist_request (char *pkt, int startflag, |
1179 | int threadcount, | |
23860348 | 1180 | threadref *nextthread); |
cce74817 | 1181 | |
a14ed312 KB |
1182 | static int parse_threadlist_response (char *pkt, |
1183 | int result_limit, | |
23860348 MS |
1184 | threadref *original_echo, |
1185 | threadref *resultlist, | |
1186 | int *doneflag); | |
cce74817 | 1187 | |
a14ed312 | 1188 | static int remote_get_threadlist (int startflag, |
23860348 | 1189 | threadref *nextthread, |
a14ed312 KB |
1190 | int result_limit, |
1191 | int *done, | |
23860348 MS |
1192 | int *result_count, |
1193 | threadref *threadlist); | |
cce74817 | 1194 | |
23860348 | 1195 | typedef int (*rmt_thread_action) (threadref *ref, void *context); |
cce74817 | 1196 | |
a14ed312 KB |
1197 | static int remote_threadlist_iterator (rmt_thread_action stepfunction, |
1198 | void *context, int looplimit); | |
cce74817 | 1199 | |
23860348 | 1200 | static int remote_newthread_step (threadref *ref, void *context); |
cce74817 | 1201 | |
23860348 | 1202 | /* Encode 64 bits in 16 chars of hex. */ |
c906108c SS |
1203 | |
1204 | static const char hexchars[] = "0123456789abcdef"; | |
1205 | ||
1206 | static int | |
fba45db2 | 1207 | ishex (int ch, int *val) |
c906108c SS |
1208 | { |
1209 | if ((ch >= 'a') && (ch <= 'f')) | |
1210 | { | |
1211 | *val = ch - 'a' + 10; | |
1212 | return 1; | |
1213 | } | |
1214 | if ((ch >= 'A') && (ch <= 'F')) | |
1215 | { | |
1216 | *val = ch - 'A' + 10; | |
1217 | return 1; | |
1218 | } | |
1219 | if ((ch >= '0') && (ch <= '9')) | |
1220 | { | |
1221 | *val = ch - '0'; | |
1222 | return 1; | |
1223 | } | |
1224 | return 0; | |
1225 | } | |
1226 | ||
1227 | static int | |
fba45db2 | 1228 | stubhex (int ch) |
c906108c SS |
1229 | { |
1230 | if (ch >= 'a' && ch <= 'f') | |
1231 | return ch - 'a' + 10; | |
1232 | if (ch >= '0' && ch <= '9') | |
1233 | return ch - '0'; | |
1234 | if (ch >= 'A' && ch <= 'F') | |
1235 | return ch - 'A' + 10; | |
1236 | return -1; | |
1237 | } | |
1238 | ||
1239 | static int | |
fba45db2 | 1240 | stub_unpack_int (char *buff, int fieldlength) |
c906108c SS |
1241 | { |
1242 | int nibble; | |
1243 | int retval = 0; | |
1244 | ||
1245 | while (fieldlength) | |
1246 | { | |
1247 | nibble = stubhex (*buff++); | |
1248 | retval |= nibble; | |
1249 | fieldlength--; | |
1250 | if (fieldlength) | |
1251 | retval = retval << 4; | |
1252 | } | |
1253 | return retval; | |
1254 | } | |
1255 | ||
1256 | char * | |
fba45db2 | 1257 | unpack_varlen_hex (char *buff, /* packet to parse */ |
b2dd6311 | 1258 | ULONGEST *result) |
c906108c SS |
1259 | { |
1260 | int nibble; | |
1261 | int retval = 0; | |
1262 | ||
1263 | while (ishex (*buff, &nibble)) | |
1264 | { | |
1265 | buff++; | |
1266 | retval = retval << 4; | |
1267 | retval |= nibble & 0x0f; | |
1268 | } | |
1269 | *result = retval; | |
1270 | return buff; | |
1271 | } | |
1272 | ||
1273 | static char * | |
fba45db2 | 1274 | unpack_nibble (char *buf, int *val) |
c906108c SS |
1275 | { |
1276 | ishex (*buf++, val); | |
1277 | return buf; | |
1278 | } | |
1279 | ||
1280 | static char * | |
fba45db2 | 1281 | pack_nibble (char *buf, int nibble) |
c906108c SS |
1282 | { |
1283 | *buf++ = hexchars[(nibble & 0x0f)]; | |
1284 | return buf; | |
1285 | } | |
1286 | ||
1287 | static char * | |
fba45db2 | 1288 | pack_hex_byte (char *pkt, int byte) |
c906108c SS |
1289 | { |
1290 | *pkt++ = hexchars[(byte >> 4) & 0xf]; | |
1291 | *pkt++ = hexchars[(byte & 0xf)]; | |
1292 | return pkt; | |
1293 | } | |
1294 | ||
1295 | static char * | |
fba45db2 | 1296 | unpack_byte (char *buf, int *value) |
c906108c SS |
1297 | { |
1298 | *value = stub_unpack_int (buf, 2); | |
1299 | return buf + 2; | |
1300 | } | |
1301 | ||
1302 | static char * | |
fba45db2 | 1303 | pack_int (char *buf, int value) |
c906108c SS |
1304 | { |
1305 | buf = pack_hex_byte (buf, (value >> 24) & 0xff); | |
1306 | buf = pack_hex_byte (buf, (value >> 16) & 0xff); | |
1307 | buf = pack_hex_byte (buf, (value >> 8) & 0x0ff); | |
1308 | buf = pack_hex_byte (buf, (value & 0xff)); | |
1309 | return buf; | |
1310 | } | |
1311 | ||
1312 | static char * | |
fba45db2 | 1313 | unpack_int (char *buf, int *value) |
c906108c SS |
1314 | { |
1315 | *value = stub_unpack_int (buf, 8); | |
1316 | return buf + 8; | |
1317 | } | |
1318 | ||
23860348 | 1319 | #if 0 /* Currently unused, uncomment when needed. */ |
a14ed312 | 1320 | static char *pack_string (char *pkt, char *string); |
c906108c SS |
1321 | |
1322 | static char * | |
fba45db2 | 1323 | pack_string (char *pkt, char *string) |
c906108c SS |
1324 | { |
1325 | char ch; | |
1326 | int len; | |
1327 | ||
1328 | len = strlen (string); | |
1329 | if (len > 200) | |
23860348 | 1330 | len = 200; /* Bigger than most GDB packets, junk??? */ |
c906108c SS |
1331 | pkt = pack_hex_byte (pkt, len); |
1332 | while (len-- > 0) | |
1333 | { | |
1334 | ch = *string++; | |
1335 | if ((ch == '\0') || (ch == '#')) | |
23860348 | 1336 | ch = '*'; /* Protect encapsulation. */ |
c906108c SS |
1337 | *pkt++ = ch; |
1338 | } | |
1339 | return pkt; | |
1340 | } | |
1341 | #endif /* 0 (unused) */ | |
1342 | ||
1343 | static char * | |
fba45db2 | 1344 | unpack_string (char *src, char *dest, int length) |
c906108c SS |
1345 | { |
1346 | while (length--) | |
1347 | *dest++ = *src++; | |
1348 | *dest = '\0'; | |
1349 | return src; | |
1350 | } | |
1351 | ||
1352 | static char * | |
fba45db2 | 1353 | pack_threadid (char *pkt, threadref *id) |
c906108c SS |
1354 | { |
1355 | char *limit; | |
1356 | unsigned char *altid; | |
1357 | ||
1358 | altid = (unsigned char *) id; | |
1359 | limit = pkt + BUF_THREAD_ID_SIZE; | |
1360 | while (pkt < limit) | |
1361 | pkt = pack_hex_byte (pkt, *altid++); | |
1362 | return pkt; | |
1363 | } | |
1364 | ||
1365 | ||
1366 | static char * | |
fba45db2 | 1367 | unpack_threadid (char *inbuf, threadref *id) |
c906108c SS |
1368 | { |
1369 | char *altref; | |
1370 | char *limit = inbuf + BUF_THREAD_ID_SIZE; | |
1371 | int x, y; | |
1372 | ||
1373 | altref = (char *) id; | |
1374 | ||
1375 | while (inbuf < limit) | |
1376 | { | |
1377 | x = stubhex (*inbuf++); | |
1378 | y = stubhex (*inbuf++); | |
1379 | *altref++ = (x << 4) | y; | |
1380 | } | |
1381 | return inbuf; | |
1382 | } | |
1383 | ||
1384 | /* Externally, threadrefs are 64 bits but internally, they are still | |
1385 | ints. This is due to a mismatch of specifications. We would like | |
1386 | to use 64bit thread references internally. This is an adapter | |
1387 | function. */ | |
1388 | ||
1389 | void | |
fba45db2 | 1390 | int_to_threadref (threadref *id, int value) |
c906108c SS |
1391 | { |
1392 | unsigned char *scan; | |
1393 | ||
1394 | scan = (unsigned char *) id; | |
1395 | { | |
1396 | int i = 4; | |
1397 | while (i--) | |
1398 | *scan++ = 0; | |
1399 | } | |
1400 | *scan++ = (value >> 24) & 0xff; | |
1401 | *scan++ = (value >> 16) & 0xff; | |
1402 | *scan++ = (value >> 8) & 0xff; | |
1403 | *scan++ = (value & 0xff); | |
1404 | } | |
1405 | ||
1406 | static int | |
fba45db2 | 1407 | threadref_to_int (threadref *ref) |
c906108c SS |
1408 | { |
1409 | int i, value = 0; | |
1410 | unsigned char *scan; | |
1411 | ||
cfd77fa1 | 1412 | scan = *ref; |
c906108c SS |
1413 | scan += 4; |
1414 | i = 4; | |
1415 | while (i-- > 0) | |
1416 | value = (value << 8) | ((*scan++) & 0xff); | |
1417 | return value; | |
1418 | } | |
1419 | ||
1420 | static void | |
fba45db2 | 1421 | copy_threadref (threadref *dest, threadref *src) |
c906108c SS |
1422 | { |
1423 | int i; | |
1424 | unsigned char *csrc, *cdest; | |
1425 | ||
1426 | csrc = (unsigned char *) src; | |
1427 | cdest = (unsigned char *) dest; | |
1428 | i = 8; | |
1429 | while (i--) | |
1430 | *cdest++ = *csrc++; | |
1431 | } | |
1432 | ||
1433 | static int | |
fba45db2 | 1434 | threadmatch (threadref *dest, threadref *src) |
c906108c | 1435 | { |
23860348 | 1436 | /* Things are broken right now, so just assume we got a match. */ |
c906108c SS |
1437 | #if 0 |
1438 | unsigned char *srcp, *destp; | |
1439 | int i, result; | |
1440 | srcp = (char *) src; | |
1441 | destp = (char *) dest; | |
1442 | ||
1443 | result = 1; | |
1444 | while (i-- > 0) | |
1445 | result &= (*srcp++ == *destp++) ? 1 : 0; | |
1446 | return result; | |
1447 | #endif | |
1448 | return 1; | |
1449 | } | |
1450 | ||
1451 | /* | |
c5aa993b JM |
1452 | threadid:1, # always request threadid |
1453 | context_exists:2, | |
1454 | display:4, | |
1455 | unique_name:8, | |
1456 | more_display:16 | |
1457 | */ | |
c906108c SS |
1458 | |
1459 | /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */ | |
1460 | ||
1461 | static char * | |
fba45db2 | 1462 | pack_threadinfo_request (char *pkt, int mode, threadref *id) |
c906108c | 1463 | { |
23860348 MS |
1464 | *pkt++ = 'q'; /* Info Query */ |
1465 | *pkt++ = 'P'; /* process or thread info */ | |
1466 | pkt = pack_int (pkt, mode); /* mode */ | |
c906108c | 1467 | pkt = pack_threadid (pkt, id); /* threadid */ |
23860348 | 1468 | *pkt = '\0'; /* terminate */ |
c906108c SS |
1469 | return pkt; |
1470 | } | |
1471 | ||
23860348 | 1472 | /* These values tag the fields in a thread info response packet. */ |
c906108c | 1473 | /* Tagging the fields allows us to request specific fields and to |
23860348 | 1474 | add more fields as time goes by. */ |
c906108c | 1475 | |
23860348 | 1476 | #define TAG_THREADID 1 /* Echo the thread identifier. */ |
c5aa993b | 1477 | #define TAG_EXISTS 2 /* Is this process defined enough to |
23860348 | 1478 | fetch registers and its stack? */ |
c5aa993b | 1479 | #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */ |
23860348 | 1480 | #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */ |
802188a7 | 1481 | #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about |
23860348 | 1482 | the process. */ |
c906108c SS |
1483 | |
1484 | static int | |
fba45db2 KB |
1485 | remote_unpack_thread_info_response (char *pkt, threadref *expectedref, |
1486 | struct gdb_ext_thread_info *info) | |
c906108c | 1487 | { |
d01949b6 | 1488 | struct remote_state *rs = get_remote_state (); |
c906108c | 1489 | int mask, length; |
cfd77fa1 | 1490 | int tag; |
c906108c | 1491 | threadref ref; |
24b06219 | 1492 | char *limit = pkt + rs->remote_packet_size; /* Plausible parsing limit. */ |
c906108c SS |
1493 | int retval = 1; |
1494 | ||
23860348 | 1495 | /* info->threadid = 0; FIXME: implement zero_threadref. */ |
c906108c SS |
1496 | info->active = 0; |
1497 | info->display[0] = '\0'; | |
1498 | info->shortname[0] = '\0'; | |
1499 | info->more_display[0] = '\0'; | |
1500 | ||
23860348 MS |
1501 | /* Assume the characters indicating the packet type have been |
1502 | stripped. */ | |
c906108c SS |
1503 | pkt = unpack_int (pkt, &mask); /* arg mask */ |
1504 | pkt = unpack_threadid (pkt, &ref); | |
1505 | ||
1506 | if (mask == 0) | |
8a3fe4f8 | 1507 | warning (_("Incomplete response to threadinfo request.")); |
c906108c | 1508 | if (!threadmatch (&ref, expectedref)) |
23860348 | 1509 | { /* This is an answer to a different request. */ |
8a3fe4f8 | 1510 | warning (_("ERROR RMT Thread info mismatch.")); |
c906108c SS |
1511 | return 0; |
1512 | } | |
1513 | copy_threadref (&info->threadid, &ref); | |
1514 | ||
23860348 | 1515 | /* Loop on tagged fields , try to bail if somthing goes wrong. */ |
c906108c | 1516 | |
23860348 MS |
1517 | /* Packets are terminated with nulls. */ |
1518 | while ((pkt < limit) && mask && *pkt) | |
c906108c SS |
1519 | { |
1520 | pkt = unpack_int (pkt, &tag); /* tag */ | |
23860348 MS |
1521 | pkt = unpack_byte (pkt, &length); /* length */ |
1522 | if (!(tag & mask)) /* Tags out of synch with mask. */ | |
c906108c | 1523 | { |
8a3fe4f8 | 1524 | warning (_("ERROR RMT: threadinfo tag mismatch.")); |
c906108c SS |
1525 | retval = 0; |
1526 | break; | |
1527 | } | |
1528 | if (tag == TAG_THREADID) | |
1529 | { | |
1530 | if (length != 16) | |
1531 | { | |
8a3fe4f8 | 1532 | warning (_("ERROR RMT: length of threadid is not 16.")); |
c906108c SS |
1533 | retval = 0; |
1534 | break; | |
1535 | } | |
1536 | pkt = unpack_threadid (pkt, &ref); | |
1537 | mask = mask & ~TAG_THREADID; | |
1538 | continue; | |
1539 | } | |
1540 | if (tag == TAG_EXISTS) | |
1541 | { | |
1542 | info->active = stub_unpack_int (pkt, length); | |
1543 | pkt += length; | |
1544 | mask = mask & ~(TAG_EXISTS); | |
1545 | if (length > 8) | |
1546 | { | |
8a3fe4f8 | 1547 | warning (_("ERROR RMT: 'exists' length too long.")); |
c906108c SS |
1548 | retval = 0; |
1549 | break; | |
1550 | } | |
1551 | continue; | |
1552 | } | |
1553 | if (tag == TAG_THREADNAME) | |
1554 | { | |
1555 | pkt = unpack_string (pkt, &info->shortname[0], length); | |
1556 | mask = mask & ~TAG_THREADNAME; | |
1557 | continue; | |
1558 | } | |
1559 | if (tag == TAG_DISPLAY) | |
1560 | { | |
1561 | pkt = unpack_string (pkt, &info->display[0], length); | |
1562 | mask = mask & ~TAG_DISPLAY; | |
1563 | continue; | |
1564 | } | |
1565 | if (tag == TAG_MOREDISPLAY) | |
1566 | { | |
1567 | pkt = unpack_string (pkt, &info->more_display[0], length); | |
1568 | mask = mask & ~TAG_MOREDISPLAY; | |
1569 | continue; | |
1570 | } | |
8a3fe4f8 | 1571 | warning (_("ERROR RMT: unknown thread info tag.")); |
23860348 | 1572 | break; /* Not a tag we know about. */ |
c906108c SS |
1573 | } |
1574 | return retval; | |
1575 | } | |
1576 | ||
1577 | static int | |
fba45db2 KB |
1578 | remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */ |
1579 | struct gdb_ext_thread_info *info) | |
c906108c | 1580 | { |
d01949b6 | 1581 | struct remote_state *rs = get_remote_state (); |
c906108c | 1582 | int result; |
d01949b6 | 1583 | char *threadinfo_pkt = alloca (rs->remote_packet_size); |
c906108c SS |
1584 | |
1585 | pack_threadinfo_request (threadinfo_pkt, fieldset, threadid); | |
1586 | putpkt (threadinfo_pkt); | |
24b06219 | 1587 | getpkt (threadinfo_pkt, rs->remote_packet_size, 0); |
23860348 MS |
1588 | result = remote_unpack_thread_info_response (threadinfo_pkt + 2, |
1589 | threadid, info); | |
c906108c SS |
1590 | return result; |
1591 | } | |
1592 | ||
c906108c SS |
1593 | /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */ |
1594 | ||
1595 | static char * | |
fba45db2 KB |
1596 | pack_threadlist_request (char *pkt, int startflag, int threadcount, |
1597 | threadref *nextthread) | |
c906108c SS |
1598 | { |
1599 | *pkt++ = 'q'; /* info query packet */ | |
1600 | *pkt++ = 'L'; /* Process LIST or threadLIST request */ | |
23860348 | 1601 | pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */ |
c906108c SS |
1602 | pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */ |
1603 | pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */ | |
1604 | *pkt = '\0'; | |
1605 | return pkt; | |
1606 | } | |
1607 | ||
1608 | /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */ | |
1609 | ||
1610 | static int | |
fba45db2 KB |
1611 | parse_threadlist_response (char *pkt, int result_limit, |
1612 | threadref *original_echo, threadref *resultlist, | |
1613 | int *doneflag) | |
c906108c | 1614 | { |
d01949b6 | 1615 | struct remote_state *rs = get_remote_state (); |
c906108c SS |
1616 | char *limit; |
1617 | int count, resultcount, done; | |
1618 | ||
1619 | resultcount = 0; | |
1620 | /* Assume the 'q' and 'M chars have been stripped. */ | |
24b06219 | 1621 | limit = pkt + (rs->remote_packet_size - BUF_THREAD_ID_SIZE); |
23860348 | 1622 | /* done parse past here */ |
c906108c SS |
1623 | pkt = unpack_byte (pkt, &count); /* count field */ |
1624 | pkt = unpack_nibble (pkt, &done); | |
1625 | /* The first threadid is the argument threadid. */ | |
1626 | pkt = unpack_threadid (pkt, original_echo); /* should match query packet */ | |
1627 | while ((count-- > 0) && (pkt < limit)) | |
1628 | { | |
1629 | pkt = unpack_threadid (pkt, resultlist++); | |
1630 | if (resultcount++ >= result_limit) | |
1631 | break; | |
1632 | } | |
1633 | if (doneflag) | |
1634 | *doneflag = done; | |
1635 | return resultcount; | |
1636 | } | |
1637 | ||
1638 | static int | |
fba45db2 KB |
1639 | remote_get_threadlist (int startflag, threadref *nextthread, int result_limit, |
1640 | int *done, int *result_count, threadref *threadlist) | |
c906108c | 1641 | { |
d01949b6 | 1642 | struct remote_state *rs = get_remote_state (); |
c906108c | 1643 | static threadref echo_nextthread; |
d01949b6 AC |
1644 | char *threadlist_packet = alloca (rs->remote_packet_size); |
1645 | char *t_response = alloca (rs->remote_packet_size); | |
c906108c SS |
1646 | int result = 1; |
1647 | ||
23860348 | 1648 | /* Trancate result limit to be smaller than the packet size. */ |
24b06219 MK |
1649 | if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= rs->remote_packet_size) |
1650 | result_limit = (rs->remote_packet_size / BUF_THREAD_ID_SIZE) - 2; | |
c906108c SS |
1651 | |
1652 | pack_threadlist_request (threadlist_packet, | |
1653 | startflag, result_limit, nextthread); | |
1654 | putpkt (threadlist_packet); | |
24b06219 | 1655 | getpkt (t_response, rs->remote_packet_size, 0); |
c906108c SS |
1656 | |
1657 | *result_count = | |
1658 | parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread, | |
1659 | threadlist, done); | |
1660 | ||
1661 | if (!threadmatch (&echo_nextthread, nextthread)) | |
1662 | { | |
23860348 MS |
1663 | /* FIXME: This is a good reason to drop the packet. */ |
1664 | /* Possably, there is a duplicate response. */ | |
c906108c SS |
1665 | /* Possabilities : |
1666 | retransmit immediatly - race conditions | |
1667 | retransmit after timeout - yes | |
1668 | exit | |
1669 | wait for packet, then exit | |
1670 | */ | |
8a3fe4f8 | 1671 | warning (_("HMM: threadlist did not echo arg thread, dropping it.")); |
23860348 | 1672 | return 0; /* I choose simply exiting. */ |
c906108c SS |
1673 | } |
1674 | if (*result_count <= 0) | |
1675 | { | |
1676 | if (*done != 1) | |
1677 | { | |
8a3fe4f8 | 1678 | warning (_("RMT ERROR : failed to get remote thread list.")); |
c906108c SS |
1679 | result = 0; |
1680 | } | |
1681 | return result; /* break; */ | |
1682 | } | |
1683 | if (*result_count > result_limit) | |
1684 | { | |
1685 | *result_count = 0; | |
8a3fe4f8 | 1686 | warning (_("RMT ERROR: threadlist response longer than requested.")); |
c906108c SS |
1687 | return 0; |
1688 | } | |
1689 | return result; | |
1690 | } | |
1691 | ||
23860348 MS |
1692 | /* This is the interface between remote and threads, remotes upper |
1693 | interface. */ | |
c906108c SS |
1694 | |
1695 | /* remote_find_new_threads retrieves the thread list and for each | |
1696 | thread in the list, looks up the thread in GDB's internal list, | |
1697 | ading the thread if it does not already exist. This involves | |
1698 | getting partial thread lists from the remote target so, polling the | |
1699 | quit_flag is required. */ | |
1700 | ||
1701 | ||
23860348 | 1702 | /* About this many threadisds fit in a packet. */ |
c906108c SS |
1703 | |
1704 | #define MAXTHREADLISTRESULTS 32 | |
1705 | ||
1706 | static int | |
fba45db2 KB |
1707 | remote_threadlist_iterator (rmt_thread_action stepfunction, void *context, |
1708 | int looplimit) | |
c906108c SS |
1709 | { |
1710 | int done, i, result_count; | |
1711 | int startflag = 1; | |
1712 | int result = 1; | |
1713 | int loopcount = 0; | |
1714 | static threadref nextthread; | |
1715 | static threadref resultthreadlist[MAXTHREADLISTRESULTS]; | |
1716 | ||
1717 | done = 0; | |
1718 | while (!done) | |
1719 | { | |
1720 | if (loopcount++ > looplimit) | |
1721 | { | |
1722 | result = 0; | |
8a3fe4f8 | 1723 | warning (_("Remote fetch threadlist -infinite loop-.")); |
c906108c SS |
1724 | break; |
1725 | } | |
1726 | if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS, | |
1727 | &done, &result_count, resultthreadlist)) | |
1728 | { | |
1729 | result = 0; | |
1730 | break; | |
1731 | } | |
23860348 | 1732 | /* Clear for later iterations. */ |
c906108c SS |
1733 | startflag = 0; |
1734 | /* Setup to resume next batch of thread references, set nextthread. */ | |
1735 | if (result_count >= 1) | |
1736 | copy_threadref (&nextthread, &resultthreadlist[result_count - 1]); | |
1737 | i = 0; | |
1738 | while (result_count--) | |
1739 | if (!(result = (*stepfunction) (&resultthreadlist[i++], context))) | |
1740 | break; | |
1741 | } | |
1742 | return result; | |
1743 | } | |
1744 | ||
1745 | static int | |
fba45db2 | 1746 | remote_newthread_step (threadref *ref, void *context) |
c906108c | 1747 | { |
39f77062 | 1748 | ptid_t ptid; |
c906108c | 1749 | |
39f77062 KB |
1750 | ptid = pid_to_ptid (threadref_to_int (ref)); |
1751 | ||
1752 | if (!in_thread_list (ptid)) | |
1753 | add_thread (ptid); | |
c906108c SS |
1754 | return 1; /* continue iterator */ |
1755 | } | |
1756 | ||
1757 | #define CRAZY_MAX_THREADS 1000 | |
1758 | ||
39f77062 KB |
1759 | static ptid_t |
1760 | remote_current_thread (ptid_t oldpid) | |
c906108c | 1761 | { |
d01949b6 AC |
1762 | struct remote_state *rs = get_remote_state (); |
1763 | char *buf = alloca (rs->remote_packet_size); | |
c906108c SS |
1764 | |
1765 | putpkt ("qC"); | |
24b06219 | 1766 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c | 1767 | if (buf[0] == 'Q' && buf[1] == 'C') |
c273b20f JB |
1768 | /* Use strtoul here, so we'll correctly parse values whose highest |
1769 | bit is set. The protocol carries them as a simple series of | |
1770 | hex digits; in the absence of a sign, strtol will see such | |
1771 | values as positive numbers out of range for signed 'long', and | |
1772 | return LONG_MAX to indicate an overflow. */ | |
1773 | return pid_to_ptid (strtoul (&buf[2], NULL, 16)); | |
c906108c SS |
1774 | else |
1775 | return oldpid; | |
1776 | } | |
1777 | ||
802188a7 RM |
1778 | /* Find new threads for info threads command. |
1779 | * Original version, using John Metzler's thread protocol. | |
9d1f7ab2 | 1780 | */ |
cce74817 JM |
1781 | |
1782 | static void | |
fba45db2 | 1783 | remote_find_new_threads (void) |
c906108c | 1784 | { |
c5aa993b JM |
1785 | remote_threadlist_iterator (remote_newthread_step, 0, |
1786 | CRAZY_MAX_THREADS); | |
39f77062 KB |
1787 | if (PIDGET (inferior_ptid) == MAGIC_NULL_PID) /* ack ack ack */ |
1788 | inferior_ptid = remote_current_thread (inferior_ptid); | |
c906108c SS |
1789 | } |
1790 | ||
9d1f7ab2 MS |
1791 | /* |
1792 | * Find all threads for info threads command. | |
1793 | * Uses new thread protocol contributed by Cisco. | |
1794 | * Falls back and attempts to use the older method (above) | |
1795 | * if the target doesn't respond to the new method. | |
1796 | */ | |
1797 | ||
0f71a2f6 JM |
1798 | static void |
1799 | remote_threads_info (void) | |
1800 | { | |
d01949b6 AC |
1801 | struct remote_state *rs = get_remote_state (); |
1802 | char *buf = alloca (rs->remote_packet_size); | |
085dd6e6 | 1803 | char *bufp; |
0f71a2f6 JM |
1804 | int tid; |
1805 | ||
1806 | if (remote_desc == 0) /* paranoia */ | |
8a3fe4f8 | 1807 | error (_("Command can only be used when connected to the remote target.")); |
0f71a2f6 | 1808 | |
9d1f7ab2 MS |
1809 | if (use_threadinfo_query) |
1810 | { | |
1811 | putpkt ("qfThreadInfo"); | |
1812 | bufp = buf; | |
24b06219 | 1813 | getpkt (bufp, rs->remote_packet_size, 0); |
9d1f7ab2 | 1814 | if (bufp[0] != '\0') /* q packet recognized */ |
802188a7 | 1815 | { |
9d1f7ab2 MS |
1816 | while (*bufp++ == 'm') /* reply contains one or more TID */ |
1817 | { | |
1818 | do | |
1819 | { | |
c273b20f JB |
1820 | /* Use strtoul here, so we'll correctly parse values |
1821 | whose highest bit is set. The protocol carries | |
1822 | them as a simple series of hex digits; in the | |
1823 | absence of a sign, strtol will see such values as | |
1824 | positive numbers out of range for signed 'long', | |
1825 | and return LONG_MAX to indicate an overflow. */ | |
1826 | tid = strtoul (bufp, &bufp, 16); | |
39f77062 KB |
1827 | if (tid != 0 && !in_thread_list (pid_to_ptid (tid))) |
1828 | add_thread (pid_to_ptid (tid)); | |
9d1f7ab2 MS |
1829 | } |
1830 | while (*bufp++ == ','); /* comma-separated list */ | |
1831 | putpkt ("qsThreadInfo"); | |
1832 | bufp = buf; | |
24b06219 | 1833 | getpkt (bufp, rs->remote_packet_size, 0); |
9d1f7ab2 MS |
1834 | } |
1835 | return; /* done */ | |
1836 | } | |
1837 | } | |
1838 | ||
23860348 | 1839 | /* Else fall back to old method based on jmetzler protocol. */ |
9d1f7ab2 MS |
1840 | use_threadinfo_query = 0; |
1841 | remote_find_new_threads (); | |
1842 | return; | |
1843 | } | |
1844 | ||
802188a7 | 1845 | /* |
9d1f7ab2 MS |
1846 | * Collect a descriptive string about the given thread. |
1847 | * The target may say anything it wants to about the thread | |
1848 | * (typically info about its blocked / runnable state, name, etc.). | |
1849 | * This string will appear in the info threads display. | |
802188a7 | 1850 | * |
9d1f7ab2 MS |
1851 | * Optional: targets are not required to implement this function. |
1852 | */ | |
1853 | ||
1854 | static char * | |
1855 | remote_threads_extra_info (struct thread_info *tp) | |
1856 | { | |
d01949b6 | 1857 | struct remote_state *rs = get_remote_state (); |
9d1f7ab2 MS |
1858 | int result; |
1859 | int set; | |
1860 | threadref id; | |
1861 | struct gdb_ext_thread_info threadinfo; | |
23860348 | 1862 | static char display_buf[100]; /* arbitrary... */ |
d01949b6 | 1863 | char *bufp = alloca (rs->remote_packet_size); |
9d1f7ab2 MS |
1864 | int n = 0; /* position in display_buf */ |
1865 | ||
1866 | if (remote_desc == 0) /* paranoia */ | |
8e65ff28 | 1867 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1868 | _("remote_threads_extra_info")); |
9d1f7ab2 MS |
1869 | |
1870 | if (use_threadextra_query) | |
1871 | { | |
ecbc58df WZ |
1872 | xsnprintf (bufp, rs->remote_packet_size, "qThreadExtraInfo,%x", |
1873 | PIDGET (tp->ptid)); | |
9d1f7ab2 | 1874 | putpkt (bufp); |
24b06219 | 1875 | getpkt (bufp, rs->remote_packet_size, 0); |
9d1f7ab2 MS |
1876 | if (bufp[0] != 0) |
1877 | { | |
30559e10 | 1878 | n = min (strlen (bufp) / 2, sizeof (display_buf)); |
cfd77fa1 | 1879 | result = hex2bin (bufp, (gdb_byte *) display_buf, n); |
30559e10 | 1880 | display_buf [result] = '\0'; |
9d1f7ab2 MS |
1881 | return display_buf; |
1882 | } | |
0f71a2f6 | 1883 | } |
9d1f7ab2 MS |
1884 | |
1885 | /* If the above query fails, fall back to the old method. */ | |
1886 | use_threadextra_query = 0; | |
1887 | set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME | |
1888 | | TAG_MOREDISPLAY | TAG_DISPLAY; | |
39f77062 | 1889 | int_to_threadref (&id, PIDGET (tp->ptid)); |
9d1f7ab2 MS |
1890 | if (remote_get_threadinfo (&id, set, &threadinfo)) |
1891 | if (threadinfo.active) | |
0f71a2f6 | 1892 | { |
9d1f7ab2 | 1893 | if (*threadinfo.shortname) |
ecbc58df WZ |
1894 | n += xsnprintf (&display_buf[0], sizeof (display_buf) - n, |
1895 | " Name: %s,", threadinfo.shortname); | |
9d1f7ab2 | 1896 | if (*threadinfo.display) |
ecbc58df WZ |
1897 | n += xsnprintf (&display_buf[n], sizeof (display_buf) - n, |
1898 | " State: %s,", threadinfo.display); | |
9d1f7ab2 | 1899 | if (*threadinfo.more_display) |
ecbc58df WZ |
1900 | n += xsnprintf (&display_buf[n], sizeof (display_buf) - n, |
1901 | " Priority: %s", threadinfo.more_display); | |
9d1f7ab2 MS |
1902 | |
1903 | if (n > 0) | |
c5aa993b | 1904 | { |
23860348 | 1905 | /* For purely cosmetic reasons, clear up trailing commas. */ |
9d1f7ab2 MS |
1906 | if (',' == display_buf[n-1]) |
1907 | display_buf[n-1] = ' '; | |
1908 | return display_buf; | |
c5aa993b | 1909 | } |
0f71a2f6 | 1910 | } |
9d1f7ab2 | 1911 | return NULL; |
0f71a2f6 | 1912 | } |
c906108c | 1913 | \f |
c5aa993b | 1914 | |
24b06219 | 1915 | /* Restart the remote side; this is an extended protocol operation. */ |
c906108c SS |
1916 | |
1917 | static void | |
fba45db2 | 1918 | extended_remote_restart (void) |
c906108c | 1919 | { |
d01949b6 AC |
1920 | struct remote_state *rs = get_remote_state (); |
1921 | char *buf = alloca (rs->remote_packet_size); | |
c906108c SS |
1922 | |
1923 | /* Send the restart command; for reasons I don't understand the | |
1924 | remote side really expects a number after the "R". */ | |
c8d511af | 1925 | xsnprintf (buf, rs->remote_packet_size, "R%x", 0); |
c906108c SS |
1926 | putpkt (buf); |
1927 | ||
1928 | /* Now query for status so this looks just like we restarted | |
1929 | gdbserver from scratch. */ | |
1930 | putpkt ("?"); | |
24b06219 | 1931 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c SS |
1932 | } |
1933 | \f | |
1934 | /* Clean up connection to a remote debugger. */ | |
1935 | ||
c906108c | 1936 | static void |
fba45db2 | 1937 | remote_close (int quitting) |
c906108c SS |
1938 | { |
1939 | if (remote_desc) | |
2cd58942 | 1940 | serial_close (remote_desc); |
c906108c SS |
1941 | remote_desc = NULL; |
1942 | } | |
1943 | ||
23860348 | 1944 | /* Query the remote side for the text, data and bss offsets. */ |
c906108c SS |
1945 | |
1946 | static void | |
fba45db2 | 1947 | get_offsets (void) |
c906108c | 1948 | { |
d01949b6 AC |
1949 | struct remote_state *rs = get_remote_state (); |
1950 | char *buf = alloca (rs->remote_packet_size); | |
085dd6e6 | 1951 | char *ptr; |
c906108c SS |
1952 | int lose; |
1953 | CORE_ADDR text_addr, data_addr, bss_addr; | |
1954 | struct section_offsets *offs; | |
1955 | ||
1956 | putpkt ("qOffsets"); | |
24b06219 | 1957 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c SS |
1958 | |
1959 | if (buf[0] == '\000') | |
1960 | return; /* Return silently. Stub doesn't support | |
23860348 | 1961 | this command. */ |
c906108c SS |
1962 | if (buf[0] == 'E') |
1963 | { | |
8a3fe4f8 | 1964 | warning (_("Remote failure reply: %s"), buf); |
c906108c SS |
1965 | return; |
1966 | } | |
1967 | ||
1968 | /* Pick up each field in turn. This used to be done with scanf, but | |
1969 | scanf will make trouble if CORE_ADDR size doesn't match | |
1970 | conversion directives correctly. The following code will work | |
1971 | with any size of CORE_ADDR. */ | |
1972 | text_addr = data_addr = bss_addr = 0; | |
1973 | ptr = buf; | |
1974 | lose = 0; | |
1975 | ||
1976 | if (strncmp (ptr, "Text=", 5) == 0) | |
1977 | { | |
1978 | ptr += 5; | |
1979 | /* Don't use strtol, could lose on big values. */ | |
1980 | while (*ptr && *ptr != ';') | |
1981 | text_addr = (text_addr << 4) + fromhex (*ptr++); | |
1982 | } | |
1983 | else | |
1984 | lose = 1; | |
1985 | ||
1986 | if (!lose && strncmp (ptr, ";Data=", 6) == 0) | |
1987 | { | |
1988 | ptr += 6; | |
1989 | while (*ptr && *ptr != ';') | |
1990 | data_addr = (data_addr << 4) + fromhex (*ptr++); | |
1991 | } | |
1992 | else | |
1993 | lose = 1; | |
1994 | ||
1995 | if (!lose && strncmp (ptr, ";Bss=", 5) == 0) | |
1996 | { | |
1997 | ptr += 5; | |
1998 | while (*ptr && *ptr != ';') | |
1999 | bss_addr = (bss_addr << 4) + fromhex (*ptr++); | |
2000 | } | |
2001 | else | |
2002 | lose = 1; | |
2003 | ||
2004 | if (lose) | |
8a3fe4f8 | 2005 | error (_("Malformed response to offset query, %s"), buf); |
c906108c SS |
2006 | |
2007 | if (symfile_objfile == NULL) | |
2008 | return; | |
2009 | ||
802188a7 | 2010 | offs = ((struct section_offsets *) |
a39a16c4 | 2011 | alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections))); |
802188a7 | 2012 | memcpy (offs, symfile_objfile->section_offsets, |
a39a16c4 | 2013 | SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)); |
c906108c | 2014 | |
a4c8257b | 2015 | offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr; |
c906108c SS |
2016 | |
2017 | /* This is a temporary kludge to force data and bss to use the same offsets | |
2018 | because that's what nlmconv does now. The real solution requires changes | |
2019 | to the stub and remote.c that I don't have time to do right now. */ | |
2020 | ||
a4c8257b EZ |
2021 | offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr; |
2022 | offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr; | |
c906108c SS |
2023 | |
2024 | objfile_relocate (symfile_objfile, offs); | |
2025 | } | |
2026 | ||
2027 | /* Stub for catch_errors. */ | |
2028 | ||
0f71a2f6 | 2029 | static int |
36918e70 | 2030 | remote_start_remote_dummy (struct ui_out *uiout, void *dummy) |
0f71a2f6 | 2031 | { |
23860348 | 2032 | start_remote (); /* Initialize gdb process mechanisms. */ |
36918e70 AC |
2033 | /* NOTE: Return something >=0. A -ve value is reserved for |
2034 | catch_exceptions. */ | |
0f71a2f6 JM |
2035 | return 1; |
2036 | } | |
2037 | ||
9cbc821d | 2038 | static void |
36918e70 | 2039 | remote_start_remote (struct ui_out *uiout, void *dummy) |
c906108c | 2040 | { |
23860348 | 2041 | immediate_quit++; /* Allow user to interrupt it. */ |
c906108c SS |
2042 | |
2043 | /* Ack any packet which the remote side has already sent. */ | |
2cd58942 | 2044 | serial_write (remote_desc, "+", 1); |
c906108c SS |
2045 | |
2046 | /* Let the stub know that we want it to return the thread. */ | |
2047 | set_thread (-1, 0); | |
2048 | ||
39f77062 | 2049 | inferior_ptid = remote_current_thread (inferior_ptid); |
c906108c | 2050 | |
23860348 | 2051 | get_offsets (); /* Get text, data & bss offsets. */ |
c906108c | 2052 | |
23860348 | 2053 | putpkt ("?"); /* Initiate a query from remote machine. */ |
8edbea78 | 2054 | immediate_quit--; |
c906108c | 2055 | |
9cbc821d | 2056 | remote_start_remote_dummy (uiout, dummy); |
c906108c SS |
2057 | } |
2058 | ||
2059 | /* Open a connection to a remote debugger. | |
2060 | NAME is the filename used for communication. */ | |
2061 | ||
2062 | static void | |
fba45db2 | 2063 | remote_open (char *name, int from_tty) |
c906108c | 2064 | { |
92d1e331 | 2065 | remote_open_1 (name, from_tty, &remote_ops, 0, 0); |
c906108c SS |
2066 | } |
2067 | ||
23860348 | 2068 | /* Just like remote_open, but with asynchronous support. */ |
43ff13b4 | 2069 | static void |
fba45db2 | 2070 | remote_async_open (char *name, int from_tty) |
43ff13b4 | 2071 | { |
92d1e331 | 2072 | remote_open_1 (name, from_tty, &remote_async_ops, 0, 1); |
43ff13b4 JM |
2073 | } |
2074 | ||
c906108c SS |
2075 | /* Open a connection to a remote debugger using the extended |
2076 | remote gdb protocol. NAME is the filename used for communication. */ | |
2077 | ||
2078 | static void | |
fba45db2 | 2079 | extended_remote_open (char *name, int from_tty) |
c906108c | 2080 | { |
92d1e331 DJ |
2081 | remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */, |
2082 | 0 /* async_p */); | |
c906108c SS |
2083 | } |
2084 | ||
23860348 | 2085 | /* Just like extended_remote_open, but with asynchronous support. */ |
43ff13b4 | 2086 | static void |
fba45db2 | 2087 | extended_remote_async_open (char *name, int from_tty) |
43ff13b4 | 2088 | { |
92d1e331 DJ |
2089 | remote_open_1 (name, from_tty, &extended_async_remote_ops, |
2090 | 1 /*extended_p */, 1 /* async_p */); | |
43ff13b4 JM |
2091 | } |
2092 | ||
c906108c SS |
2093 | /* Generic code for opening a connection to a remote target. */ |
2094 | ||
d471ea57 AC |
2095 | static void |
2096 | init_all_packet_configs (void) | |
2097 | { | |
2098 | int i; | |
2099 | update_packet_config (&remote_protocol_P); | |
b96ec7ac | 2100 | update_packet_config (&remote_protocol_p); |
dc8acb97 | 2101 | update_packet_config (&remote_protocol_qSymbol); |
506fb367 | 2102 | update_packet_config (&remote_protocol_vcont); |
d471ea57 AC |
2103 | for (i = 0; i < NR_Z_PACKET_TYPES; i++) |
2104 | update_packet_config (&remote_protocol_Z[i]); | |
2105 | /* Force remote_write_bytes to check whether target supports binary | |
23860348 | 2106 | downloading. */ |
d471ea57 | 2107 | update_packet_config (&remote_protocol_binary_download); |
802188a7 | 2108 | update_packet_config (&remote_protocol_qPart_auxv); |
38691318 | 2109 | update_packet_config (&remote_protocol_qGetTLSAddr); |
d471ea57 AC |
2110 | } |
2111 | ||
23860348 | 2112 | /* Symbol look-up. */ |
dc8acb97 MS |
2113 | |
2114 | static void | |
2115 | remote_check_symbols (struct objfile *objfile) | |
2116 | { | |
d01949b6 | 2117 | struct remote_state *rs = get_remote_state (); |
dc8acb97 MS |
2118 | char *msg, *reply, *tmp; |
2119 | struct minimal_symbol *sym; | |
2120 | int end; | |
2121 | ||
2122 | if (remote_protocol_qSymbol.support == PACKET_DISABLE) | |
2123 | return; | |
2124 | ||
d01949b6 AC |
2125 | msg = alloca (rs->remote_packet_size); |
2126 | reply = alloca (rs->remote_packet_size); | |
dc8acb97 | 2127 | |
23860348 | 2128 | /* Invite target to request symbol lookups. */ |
dc8acb97 MS |
2129 | |
2130 | putpkt ("qSymbol::"); | |
24b06219 | 2131 | getpkt (reply, rs->remote_packet_size, 0); |
dc8acb97 MS |
2132 | packet_ok (reply, &remote_protocol_qSymbol); |
2133 | ||
2134 | while (strncmp (reply, "qSymbol:", 8) == 0) | |
2135 | { | |
2136 | tmp = &reply[8]; | |
cfd77fa1 | 2137 | end = hex2bin (tmp, (gdb_byte *) msg, strlen (tmp) / 2); |
dc8acb97 MS |
2138 | msg[end] = '\0'; |
2139 | sym = lookup_minimal_symbol (msg, NULL, NULL); | |
2140 | if (sym == NULL) | |
ecbc58df | 2141 | xsnprintf (msg, rs->remote_packet_size, "qSymbol::%s", &reply[8]); |
dc8acb97 | 2142 | else |
ecbc58df WZ |
2143 | xsnprintf (msg, rs->remote_packet_size, "qSymbol:%s:%s", |
2144 | paddr_nz (SYMBOL_VALUE_ADDRESS (sym)), | |
2145 | &reply[8]); | |
dc8acb97 | 2146 | putpkt (msg); |
24b06219 | 2147 | getpkt (reply, rs->remote_packet_size, 0); |
dc8acb97 MS |
2148 | } |
2149 | } | |
2150 | ||
9db8d71f DJ |
2151 | static struct serial * |
2152 | remote_serial_open (char *name) | |
2153 | { | |
2154 | static int udp_warning = 0; | |
2155 | ||
2156 | /* FIXME: Parsing NAME here is a hack. But we want to warn here instead | |
2157 | of in ser-tcp.c, because it is the remote protocol assuming that the | |
2158 | serial connection is reliable and not the serial connection promising | |
2159 | to be. */ | |
2160 | if (!udp_warning && strncmp (name, "udp:", 4) == 0) | |
2161 | { | |
8a3fe4f8 AC |
2162 | warning (_("\ |
2163 | The remote protocol may be unreliable over UDP.\n\ | |
2164 | Some events may be lost, rendering further debugging impossible.")); | |
9db8d71f DJ |
2165 | udp_warning = 1; |
2166 | } | |
2167 | ||
2168 | return serial_open (name); | |
2169 | } | |
2170 | ||
c906108c | 2171 | static void |
fba45db2 | 2172 | remote_open_1 (char *name, int from_tty, struct target_ops *target, |
92d1e331 | 2173 | int extended_p, int async_p) |
c906108c | 2174 | { |
d01949b6 | 2175 | struct remote_state *rs = get_remote_state (); |
c906108c | 2176 | if (name == 0) |
8a3fe4f8 | 2177 | error (_("To open a remote debug connection, you need to specify what\n" |
22e04375 | 2178 | "serial device is attached to the remote system\n" |
8a3fe4f8 | 2179 | "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).")); |
c906108c | 2180 | |
23860348 | 2181 | /* See FIXME above. */ |
92d1e331 DJ |
2182 | if (!async_p) |
2183 | wait_forever_enabled_p = 1; | |
6426a772 | 2184 | |
00cac895 DJ |
2185 | reopen_exec_file (); |
2186 | reread_symbols (); | |
2187 | ||
c906108c SS |
2188 | target_preopen (from_tty); |
2189 | ||
2190 | unpush_target (target); | |
2191 | ||
9db8d71f | 2192 | remote_desc = remote_serial_open (name); |
c906108c SS |
2193 | if (!remote_desc) |
2194 | perror_with_name (name); | |
2195 | ||
2196 | if (baud_rate != -1) | |
2197 | { | |
2cd58942 | 2198 | if (serial_setbaudrate (remote_desc, baud_rate)) |
c906108c | 2199 | { |
9b74d5d3 KB |
2200 | /* The requested speed could not be set. Error out to |
2201 | top level after closing remote_desc. Take care to | |
2202 | set remote_desc to NULL to avoid closing remote_desc | |
2203 | more than once. */ | |
2cd58942 | 2204 | serial_close (remote_desc); |
9b74d5d3 | 2205 | remote_desc = NULL; |
c906108c SS |
2206 | perror_with_name (name); |
2207 | } | |
2208 | } | |
2209 | ||
2cd58942 | 2210 | serial_raw (remote_desc); |
c906108c SS |
2211 | |
2212 | /* If there is something sitting in the buffer we might take it as a | |
2213 | response to a command, which would be bad. */ | |
2cd58942 | 2214 | serial_flush_input (remote_desc); |
c906108c SS |
2215 | |
2216 | if (from_tty) | |
2217 | { | |
2218 | puts_filtered ("Remote debugging using "); | |
2219 | puts_filtered (name); | |
2220 | puts_filtered ("\n"); | |
2221 | } | |
23860348 | 2222 | push_target (target); /* Switch to using remote target now. */ |
c906108c | 2223 | |
d471ea57 | 2224 | init_all_packet_configs (); |
802188a7 | 2225 | |
c5aa993b | 2226 | general_thread = -2; |
cce74817 | 2227 | continue_thread = -2; |
c906108c | 2228 | |
9d1f7ab2 MS |
2229 | /* Probe for ability to use "ThreadInfo" query, as required. */ |
2230 | use_threadinfo_query = 1; | |
2231 | use_threadextra_query = 1; | |
2232 | ||
c906108c SS |
2233 | /* Without this, some commands which require an active target (such |
2234 | as kill) won't work. This variable serves (at least) double duty | |
2235 | as both the pid of the target process (if it has such), and as a | |
2236 | flag indicating that a target is active. These functions should | |
2237 | be split out into seperate variables, especially since GDB will | |
2238 | someday have a notion of debugging several processes. */ | |
2239 | ||
39f77062 | 2240 | inferior_ptid = pid_to_ptid (MAGIC_NULL_PID); |
92d1e331 DJ |
2241 | |
2242 | if (async_p) | |
2243 | { | |
23860348 | 2244 | /* With this target we start out by owning the terminal. */ |
92d1e331 DJ |
2245 | remote_async_terminal_ours_p = 1; |
2246 | ||
2247 | /* FIXME: cagney/1999-09-23: During the initial connection it is | |
2248 | assumed that the target is already ready and able to respond to | |
2249 | requests. Unfortunately remote_start_remote() eventually calls | |
2250 | wait_for_inferior() with no timeout. wait_forever_enabled_p gets | |
2251 | around this. Eventually a mechanism that allows | |
2252 | wait_for_inferior() to expect/get timeouts will be | |
23860348 | 2253 | implemented. */ |
92d1e331 DJ |
2254 | wait_forever_enabled_p = 0; |
2255 | } | |
2256 | ||
23860348 | 2257 | /* First delete any symbols previously loaded from shared libraries. */ |
f78f6cf1 | 2258 | no_shared_libraries (NULL, 0); |
f78f6cf1 | 2259 | |
36918e70 | 2260 | /* Start the remote connection. If error() or QUIT, discard this |
165b8e33 AC |
2261 | target (we'd otherwise be in an inconsistent state) and then |
2262 | propogate the error on up the exception chain. This ensures that | |
2263 | the caller doesn't stumble along blindly assuming that the | |
2264 | function succeeded. The CLI doesn't have this problem but other | |
2265 | UI's, such as MI do. | |
36918e70 AC |
2266 | |
2267 | FIXME: cagney/2002-05-19: Instead of re-throwing the exception, | |
2268 | this function should return an error indication letting the | |
ce2826aa | 2269 | caller restore the previous state. Unfortunately the command |
36918e70 AC |
2270 | ``target remote'' is directly wired to this function making that |
2271 | impossible. On a positive note, the CLI side of this problem has | |
2272 | been fixed - the function set_cmd_context() makes it possible for | |
2273 | all the ``target ....'' commands to share a common callback | |
2274 | function. See cli-dump.c. */ | |
109c3e39 AC |
2275 | { |
2276 | struct gdb_exception ex | |
2277 | = catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL); | |
2278 | if (ex.reason < 0) | |
2279 | { | |
2280 | pop_target (); | |
2281 | if (async_p) | |
2282 | wait_forever_enabled_p = 1; | |
2283 | throw_exception (ex); | |
2284 | } | |
2285 | } | |
c906108c | 2286 | |
92d1e331 DJ |
2287 | if (async_p) |
2288 | wait_forever_enabled_p = 1; | |
6426a772 JM |
2289 | |
2290 | if (extended_p) | |
43ff13b4 | 2291 | { |
6240bebf | 2292 | /* Tell the remote that we are using the extended protocol. */ |
d01949b6 | 2293 | char *buf = alloca (rs->remote_packet_size); |
6426a772 | 2294 | putpkt ("!"); |
24b06219 | 2295 | getpkt (buf, rs->remote_packet_size, 0); |
43ff13b4 | 2296 | } |
a77053c2 | 2297 | |
9353355f | 2298 | post_create_inferior (¤t_target, from_tty); |
f78f6cf1 | 2299 | |
23860348 | 2300 | if (exec_bfd) /* No use without an exec file. */ |
9353355f | 2301 | remote_check_symbols (symfile_objfile); |
43ff13b4 JM |
2302 | } |
2303 | ||
c906108c SS |
2304 | /* This takes a program previously attached to and detaches it. After |
2305 | this is done, GDB can be used to debug some other program. We | |
2306 | better not have left any breakpoints in the target program or it'll | |
2307 | die when it hits one. */ | |
2308 | ||
2309 | static void | |
fba45db2 | 2310 | remote_detach (char *args, int from_tty) |
c906108c | 2311 | { |
d01949b6 AC |
2312 | struct remote_state *rs = get_remote_state (); |
2313 | char *buf = alloca (rs->remote_packet_size); | |
c906108c SS |
2314 | |
2315 | if (args) | |
8a3fe4f8 | 2316 | error (_("Argument given to \"detach\" when remotely debugging.")); |
c906108c SS |
2317 | |
2318 | /* Tell the remote target to detach. */ | |
2319 | strcpy (buf, "D"); | |
24b06219 | 2320 | remote_send (buf, rs->remote_packet_size); |
c906108c | 2321 | |
23860348 | 2322 | /* Unregister the file descriptor from the event loop. */ |
6ad8ae5c DJ |
2323 | if (target_is_async_p ()) |
2324 | serial_async (remote_desc, NULL, 0); | |
2325 | ||
cca728d0 | 2326 | target_mourn_inferior (); |
c906108c SS |
2327 | if (from_tty) |
2328 | puts_filtered ("Ending remote debugging.\n"); | |
2329 | } | |
2330 | ||
6ad8ae5c DJ |
2331 | /* Same as remote_detach, but don't send the "D" packet; just disconnect. */ |
2332 | ||
43ff13b4 | 2333 | static void |
6ad8ae5c | 2334 | remote_disconnect (char *args, int from_tty) |
43ff13b4 | 2335 | { |
43ff13b4 | 2336 | if (args) |
8a3fe4f8 | 2337 | error (_("Argument given to \"detach\" when remotely debugging.")); |
43ff13b4 | 2338 | |
23860348 | 2339 | /* Unregister the file descriptor from the event loop. */ |
ed9a39eb | 2340 | if (target_is_async_p ()) |
2cd58942 | 2341 | serial_async (remote_desc, NULL, 0); |
43ff13b4 | 2342 | |
cca728d0 | 2343 | target_mourn_inferior (); |
43ff13b4 JM |
2344 | if (from_tty) |
2345 | puts_filtered ("Ending remote debugging.\n"); | |
2346 | } | |
2347 | ||
c906108c SS |
2348 | /* Convert hex digit A to a number. */ |
2349 | ||
30559e10 | 2350 | static int |
fba45db2 | 2351 | fromhex (int a) |
c906108c SS |
2352 | { |
2353 | if (a >= '0' && a <= '9') | |
2354 | return a - '0'; | |
2355 | else if (a >= 'a' && a <= 'f') | |
2356 | return a - 'a' + 10; | |
2357 | else if (a >= 'A' && a <= 'F') | |
2358 | return a - 'A' + 10; | |
c5aa993b | 2359 | else |
8a3fe4f8 | 2360 | error (_("Reply contains invalid hex digit %d"), a); |
c906108c SS |
2361 | } |
2362 | ||
30559e10 | 2363 | static int |
cfd77fa1 | 2364 | hex2bin (const char *hex, gdb_byte *bin, int count) |
30559e10 MS |
2365 | { |
2366 | int i; | |
2367 | ||
30559e10 MS |
2368 | for (i = 0; i < count; i++) |
2369 | { | |
2370 | if (hex[0] == 0 || hex[1] == 0) | |
2371 | { | |
2372 | /* Hex string is short, or of uneven length. | |
23860348 | 2373 | Return the count that has been converted so far. */ |
30559e10 MS |
2374 | return i; |
2375 | } | |
2376 | *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]); | |
2377 | hex += 2; | |
2378 | } | |
2379 | return i; | |
2380 | } | |
2381 | ||
c906108c SS |
2382 | /* Convert number NIB to a hex digit. */ |
2383 | ||
2384 | static int | |
fba45db2 | 2385 | tohex (int nib) |
c906108c SS |
2386 | { |
2387 | if (nib < 10) | |
c5aa993b | 2388 | return '0' + nib; |
c906108c | 2389 | else |
c5aa993b | 2390 | return 'a' + nib - 10; |
c906108c | 2391 | } |
30559e10 MS |
2392 | |
2393 | static int | |
cfd77fa1 | 2394 | bin2hex (const gdb_byte *bin, char *hex, int count) |
30559e10 MS |
2395 | { |
2396 | int i; | |
23860348 | 2397 | /* May use a length, or a nul-terminated string as input. */ |
30559e10 | 2398 | if (count == 0) |
cfd77fa1 | 2399 | count = strlen ((char *) bin); |
30559e10 MS |
2400 | |
2401 | for (i = 0; i < count; i++) | |
2402 | { | |
2403 | *hex++ = tohex ((*bin >> 4) & 0xf); | |
2404 | *hex++ = tohex (*bin++ & 0xf); | |
2405 | } | |
2406 | *hex = 0; | |
2407 | return i; | |
2408 | } | |
c906108c | 2409 | \f |
506fb367 DJ |
2410 | /* Check for the availability of vCont. This function should also check |
2411 | the response. */ | |
c906108c SS |
2412 | |
2413 | static void | |
506fb367 | 2414 | remote_vcont_probe (struct remote_state *rs, char *buf) |
c906108c | 2415 | { |
506fb367 DJ |
2416 | strcpy (buf, "vCont?"); |
2417 | putpkt (buf); | |
2418 | getpkt (buf, rs->remote_packet_size, 0); | |
c906108c | 2419 | |
506fb367 DJ |
2420 | /* Make sure that the features we assume are supported. */ |
2421 | if (strncmp (buf, "vCont", 5) == 0) | |
2422 | { | |
2423 | char *p = &buf[5]; | |
2424 | int support_s, support_S, support_c, support_C; | |
2425 | ||
2426 | support_s = 0; | |
2427 | support_S = 0; | |
2428 | support_c = 0; | |
2429 | support_C = 0; | |
2430 | while (p && *p == ';') | |
2431 | { | |
2432 | p++; | |
2433 | if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0)) | |
2434 | support_s = 1; | |
2435 | else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0)) | |
2436 | support_S = 1; | |
2437 | else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0)) | |
2438 | support_c = 1; | |
2439 | else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0)) | |
2440 | support_C = 1; | |
2441 | ||
2442 | p = strchr (p, ';'); | |
2443 | } | |
c906108c | 2444 | |
506fb367 DJ |
2445 | /* If s, S, c, and C are not all supported, we can't use vCont. Clearing |
2446 | BUF will make packet_ok disable the packet. */ | |
2447 | if (!support_s || !support_S || !support_c || !support_C) | |
2448 | buf[0] = 0; | |
2449 | } | |
c906108c | 2450 | |
506fb367 DJ |
2451 | packet_ok (buf, &remote_protocol_vcont); |
2452 | } | |
c906108c | 2453 | |
506fb367 DJ |
2454 | /* Resume the remote inferior by using a "vCont" packet. The thread |
2455 | to be resumed is PTID; STEP and SIGGNAL indicate whether the | |
2456 | resumed thread should be single-stepped and/or signalled. If PTID's | |
2457 | PID is -1, then all threads are resumed; the thread to be stepped and/or | |
2458 | signalled is given in the global INFERIOR_PTID. This function returns | |
2459 | non-zero iff it resumes the inferior. | |
44eaed12 | 2460 | |
506fb367 DJ |
2461 | This function issues a strict subset of all possible vCont commands at the |
2462 | moment. */ | |
44eaed12 | 2463 | |
506fb367 DJ |
2464 | static int |
2465 | remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal) | |
2466 | { | |
2467 | struct remote_state *rs = get_remote_state (); | |
2468 | int pid = PIDGET (ptid); | |
2963ee1d | 2469 | char *buf = NULL, *outbuf; |
506fb367 | 2470 | struct cleanup *old_cleanup; |
44eaed12 | 2471 | |
506fb367 DJ |
2472 | buf = xmalloc (rs->remote_packet_size); |
2473 | old_cleanup = make_cleanup (xfree, buf); | |
44eaed12 | 2474 | |
506fb367 DJ |
2475 | if (remote_protocol_vcont.support == PACKET_SUPPORT_UNKNOWN) |
2476 | remote_vcont_probe (rs, buf); | |
44eaed12 | 2477 | |
506fb367 DJ |
2478 | if (remote_protocol_vcont.support == PACKET_DISABLE) |
2479 | { | |
2480 | do_cleanups (old_cleanup); | |
2481 | return 0; | |
44eaed12 C |
2482 | } |
2483 | ||
506fb367 DJ |
2484 | /* If we could generate a wider range of packets, we'd have to worry |
2485 | about overflowing BUF. Should there be a generic | |
2486 | "multi-part-packet" packet? */ | |
2487 | ||
2488 | if (PIDGET (inferior_ptid) == MAGIC_NULL_PID) | |
c906108c | 2489 | { |
506fb367 DJ |
2490 | /* MAGIC_NULL_PTID means that we don't have any active threads, so we |
2491 | don't have any PID numbers the inferior will understand. Make sure | |
2492 | to only send forms that do not specify a PID. */ | |
2493 | if (step && siggnal != TARGET_SIGNAL_0) | |
2963ee1d | 2494 | outbuf = xstrprintf ("vCont;S%02x", siggnal); |
506fb367 | 2495 | else if (step) |
2963ee1d | 2496 | outbuf = xstrprintf ("vCont;s"); |
506fb367 | 2497 | else if (siggnal != TARGET_SIGNAL_0) |
2963ee1d | 2498 | outbuf = xstrprintf ("vCont;C%02x", siggnal); |
506fb367 | 2499 | else |
2963ee1d | 2500 | outbuf = xstrprintf ("vCont;c"); |
506fb367 DJ |
2501 | } |
2502 | else if (pid == -1) | |
2503 | { | |
2504 | /* Resume all threads, with preference for INFERIOR_PTID. */ | |
2505 | if (step && siggnal != TARGET_SIGNAL_0) | |
2963ee1d DJ |
2506 | outbuf = xstrprintf ("vCont;S%02x:%x;c", siggnal, |
2507 | PIDGET (inferior_ptid)); | |
506fb367 | 2508 | else if (step) |
2963ee1d | 2509 | outbuf = xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid)); |
506fb367 | 2510 | else if (siggnal != TARGET_SIGNAL_0) |
2963ee1d DJ |
2511 | outbuf = xstrprintf ("vCont;C%02x:%x;c", siggnal, |
2512 | PIDGET (inferior_ptid)); | |
506fb367 | 2513 | else |
2963ee1d | 2514 | outbuf = xstrprintf ("vCont;c"); |
c906108c SS |
2515 | } |
2516 | else | |
506fb367 DJ |
2517 | { |
2518 | /* Scheduler locking; resume only PTID. */ | |
2519 | if (step && siggnal != TARGET_SIGNAL_0) | |
2963ee1d | 2520 | outbuf = xstrprintf ("vCont;S%02x:%x", siggnal, pid); |
506fb367 | 2521 | else if (step) |
2963ee1d | 2522 | outbuf = xstrprintf ("vCont;s:%x", pid); |
506fb367 | 2523 | else if (siggnal != TARGET_SIGNAL_0) |
2963ee1d | 2524 | outbuf = xstrprintf ("vCont;C%02x:%x", siggnal, pid); |
506fb367 | 2525 | else |
2963ee1d | 2526 | outbuf = xstrprintf ("vCont;c:%x", pid); |
506fb367 | 2527 | } |
c906108c | 2528 | |
2963ee1d DJ |
2529 | gdb_assert (outbuf && strlen (outbuf) < rs->remote_packet_size); |
2530 | make_cleanup (xfree, outbuf); | |
2531 | ||
2532 | putpkt (outbuf); | |
506fb367 DJ |
2533 | |
2534 | do_cleanups (old_cleanup); | |
2535 | ||
2536 | return 1; | |
c906108c | 2537 | } |
43ff13b4 | 2538 | |
506fb367 DJ |
2539 | /* Tell the remote machine to resume. */ |
2540 | ||
2541 | static enum target_signal last_sent_signal = TARGET_SIGNAL_0; | |
2542 | ||
2543 | static int last_sent_step; | |
2544 | ||
43ff13b4 | 2545 | static void |
506fb367 | 2546 | remote_resume (ptid_t ptid, int step, enum target_signal siggnal) |
43ff13b4 | 2547 | { |
d01949b6 AC |
2548 | struct remote_state *rs = get_remote_state (); |
2549 | char *buf = alloca (rs->remote_packet_size); | |
39f77062 | 2550 | int pid = PIDGET (ptid); |
43ff13b4 | 2551 | |
43ff13b4 JM |
2552 | last_sent_signal = siggnal; |
2553 | last_sent_step = step; | |
2554 | ||
2555 | /* A hook for when we need to do something at the last moment before | |
2556 | resumption. */ | |
9a4105ab AC |
2557 | if (deprecated_target_resume_hook) |
2558 | (*deprecated_target_resume_hook) (); | |
43ff13b4 | 2559 | |
506fb367 DJ |
2560 | /* The vCont packet doesn't need to specify threads via Hc. */ |
2561 | if (remote_vcont_resume (ptid, step, siggnal)) | |
2562 | return; | |
2563 | ||
2564 | /* All other supported resume packets do use Hc, so call set_thread. */ | |
2565 | if (pid == -1) | |
23860348 | 2566 | set_thread (0, 0); /* Run any thread. */ |
506fb367 | 2567 | else |
23860348 | 2568 | set_thread (pid, 0); /* Run this thread. */ |
506fb367 | 2569 | |
43ff13b4 JM |
2570 | if (siggnal != TARGET_SIGNAL_0) |
2571 | { | |
2572 | buf[0] = step ? 'S' : 'C'; | |
c5aa993b | 2573 | buf[1] = tohex (((int) siggnal >> 4) & 0xf); |
506fb367 | 2574 | buf[2] = tohex (((int) siggnal) & 0xf); |
43ff13b4 JM |
2575 | buf[3] = '\0'; |
2576 | } | |
2577 | else | |
c5aa993b | 2578 | strcpy (buf, step ? "s" : "c"); |
506fb367 | 2579 | |
44eaed12 | 2580 | putpkt (buf); |
506fb367 DJ |
2581 | } |
2582 | ||
23860348 | 2583 | /* Same as remote_resume, but with async support. */ |
506fb367 DJ |
2584 | static void |
2585 | remote_async_resume (ptid_t ptid, int step, enum target_signal siggnal) | |
2586 | { | |
2587 | remote_resume (ptid, step, siggnal); | |
43ff13b4 | 2588 | |
2acceee2 JM |
2589 | /* We are about to start executing the inferior, let's register it |
2590 | with the event loop. NOTE: this is the one place where all the | |
2591 | execution commands end up. We could alternatively do this in each | |
23860348 | 2592 | of the execution commands in infcmd.c. */ |
2acceee2 JM |
2593 | /* FIXME: ezannoni 1999-09-28: We may need to move this out of here |
2594 | into infcmd.c in order to allow inferior function calls to work | |
23860348 | 2595 | NOT asynchronously. */ |
362646f5 | 2596 | if (target_can_async_p ()) |
2acceee2 | 2597 | target_async (inferior_event_handler, 0); |
23860348 | 2598 | /* Tell the world that the target is now executing. */ |
2acceee2 JM |
2599 | /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set |
2600 | this? Instead, should the client of target just assume (for | |
2601 | async targets) that the target is going to start executing? Is | |
2602 | this information already found in the continuation block? */ | |
ed9a39eb | 2603 | if (target_is_async_p ()) |
2acceee2 | 2604 | target_executing = 1; |
43ff13b4 | 2605 | } |
c906108c | 2606 | \f |
43ff13b4 JM |
2607 | |
2608 | /* Set up the signal handler for SIGINT, while the target is | |
23860348 | 2609 | executing, ovewriting the 'regular' SIGINT signal handler. */ |
43ff13b4 | 2610 | static void |
fba45db2 | 2611 | initialize_sigint_signal_handler (void) |
43ff13b4 | 2612 | { |
c5aa993b | 2613 | sigint_remote_token = |
43ff13b4 JM |
2614 | create_async_signal_handler (async_remote_interrupt, NULL); |
2615 | signal (SIGINT, handle_remote_sigint); | |
2616 | } | |
2617 | ||
23860348 | 2618 | /* Signal handler for SIGINT, while the target is executing. */ |
43ff13b4 | 2619 | static void |
fba45db2 | 2620 | handle_remote_sigint (int sig) |
43ff13b4 JM |
2621 | { |
2622 | signal (sig, handle_remote_sigint_twice); | |
c5aa993b | 2623 | sigint_remote_twice_token = |
43ff13b4 JM |
2624 | create_async_signal_handler (async_remote_interrupt_twice, NULL); |
2625 | mark_async_signal_handler_wrapper (sigint_remote_token); | |
2626 | } | |
2627 | ||
2628 | /* Signal handler for SIGINT, installed after SIGINT has already been | |
2629 | sent once. It will take effect the second time that the user sends | |
23860348 | 2630 | a ^C. */ |
43ff13b4 | 2631 | static void |
fba45db2 | 2632 | handle_remote_sigint_twice (int sig) |
43ff13b4 JM |
2633 | { |
2634 | signal (sig, handle_sigint); | |
c5aa993b | 2635 | sigint_remote_twice_token = |
2df3850c | 2636 | create_async_signal_handler (inferior_event_handler_wrapper, NULL); |
43ff13b4 JM |
2637 | mark_async_signal_handler_wrapper (sigint_remote_twice_token); |
2638 | } | |
2639 | ||
6426a772 | 2640 | /* Perform the real interruption of the target execution, in response |
23860348 | 2641 | to a ^C. */ |
c5aa993b | 2642 | static void |
fba45db2 | 2643 | async_remote_interrupt (gdb_client_data arg) |
43ff13b4 JM |
2644 | { |
2645 | if (remote_debug) | |
2646 | fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n"); | |
2647 | ||
2648 | target_stop (); | |
2649 | } | |
2650 | ||
2651 | /* Perform interrupt, if the first attempt did not succeed. Just give | |
23860348 | 2652 | up on the target alltogether. */ |
2df3850c | 2653 | void |
fba45db2 | 2654 | async_remote_interrupt_twice (gdb_client_data arg) |
43ff13b4 | 2655 | { |
2df3850c JM |
2656 | if (remote_debug) |
2657 | fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n"); | |
6426a772 | 2658 | /* Do something only if the target was not killed by the previous |
23860348 | 2659 | cntl-C. */ |
6426a772 JM |
2660 | if (target_executing) |
2661 | { | |
2662 | interrupt_query (); | |
2663 | signal (SIGINT, handle_remote_sigint); | |
2664 | } | |
43ff13b4 JM |
2665 | } |
2666 | ||
2667 | /* Reinstall the usual SIGINT handlers, after the target has | |
23860348 | 2668 | stopped. */ |
6426a772 JM |
2669 | static void |
2670 | cleanup_sigint_signal_handler (void *dummy) | |
43ff13b4 JM |
2671 | { |
2672 | signal (SIGINT, handle_sigint); | |
2673 | if (sigint_remote_twice_token) | |
23860348 MS |
2674 | delete_async_signal_handler ((struct async_signal_handler **) |
2675 | &sigint_remote_twice_token); | |
43ff13b4 | 2676 | if (sigint_remote_token) |
23860348 MS |
2677 | delete_async_signal_handler ((struct async_signal_handler **) |
2678 | &sigint_remote_token); | |
43ff13b4 JM |
2679 | } |
2680 | ||
c906108c SS |
2681 | /* Send ^C to target to halt it. Target will respond, and send us a |
2682 | packet. */ | |
507f3c78 | 2683 | static void (*ofunc) (int); |
c906108c | 2684 | |
7a292a7a SS |
2685 | /* The command line interface's stop routine. This function is installed |
2686 | as a signal handler for SIGINT. The first time a user requests a | |
2687 | stop, we call remote_stop to send a break or ^C. If there is no | |
2688 | response from the target (it didn't stop when the user requested it), | |
23860348 | 2689 | we ask the user if he'd like to detach from the target. */ |
c906108c | 2690 | static void |
fba45db2 | 2691 | remote_interrupt (int signo) |
c906108c | 2692 | { |
23860348 | 2693 | /* If this doesn't work, try more severe steps. */ |
7a292a7a SS |
2694 | signal (signo, remote_interrupt_twice); |
2695 | ||
2696 | if (remote_debug) | |
0f71a2f6 | 2697 | fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n"); |
7a292a7a SS |
2698 | |
2699 | target_stop (); | |
2700 | } | |
2701 | ||
2702 | /* The user typed ^C twice. */ | |
2703 | ||
2704 | static void | |
fba45db2 | 2705 | remote_interrupt_twice (int signo) |
7a292a7a SS |
2706 | { |
2707 | signal (signo, ofunc); | |
2708 | interrupt_query (); | |
c906108c SS |
2709 | signal (signo, remote_interrupt); |
2710 | } | |
7a292a7a SS |
2711 | |
2712 | /* This is the generic stop called via the target vector. When a target | |
2713 | interrupt is requested, either by the command line or the GUI, we | |
23860348 | 2714 | will eventually end up here. */ |
c906108c | 2715 | static void |
fba45db2 | 2716 | remote_stop (void) |
c906108c | 2717 | { |
7a292a7a SS |
2718 | /* Send a break or a ^C, depending on user preference. */ |
2719 | if (remote_debug) | |
0f71a2f6 | 2720 | fprintf_unfiltered (gdb_stdlog, "remote_stop called\n"); |
c906108c | 2721 | |
7a292a7a | 2722 | if (remote_break) |
2cd58942 | 2723 | serial_send_break (remote_desc); |
c906108c | 2724 | else |
2cd58942 | 2725 | serial_write (remote_desc, "\003", 1); |
c906108c SS |
2726 | } |
2727 | ||
2728 | /* Ask the user what to do when an interrupt is received. */ | |
2729 | ||
2730 | static void | |
fba45db2 | 2731 | interrupt_query (void) |
c906108c SS |
2732 | { |
2733 | target_terminal_ours (); | |
2734 | ||
2735 | if (query ("Interrupted while waiting for the program.\n\ | |
2736 | Give up (and stop debugging it)? ")) | |
2737 | { | |
2738 | target_mourn_inferior (); | |
315a522e | 2739 | deprecated_throw_reason (RETURN_QUIT); |
c906108c SS |
2740 | } |
2741 | ||
2742 | target_terminal_inferior (); | |
2743 | } | |
2744 | ||
6426a772 JM |
2745 | /* Enable/disable target terminal ownership. Most targets can use |
2746 | terminal groups to control terminal ownership. Remote targets are | |
2747 | different in that explicit transfer of ownership to/from GDB/target | |
23860348 | 2748 | is required. */ |
6426a772 JM |
2749 | |
2750 | static void | |
2751 | remote_async_terminal_inferior (void) | |
2752 | { | |
2753 | /* FIXME: cagney/1999-09-27: Shouldn't need to test for | |
2754 | sync_execution here. This function should only be called when | |
2755 | GDB is resuming the inferior in the forground. A background | |
2756 | resume (``run&'') should leave GDB in control of the terminal and | |
23860348 | 2757 | consequently should not call this code. */ |
6426a772 JM |
2758 | if (!sync_execution) |
2759 | return; | |
2760 | /* FIXME: cagney/1999-09-27: Closely related to the above. Make | |
2761 | calls target_terminal_*() idenpotent. The event-loop GDB talking | |
2762 | to an asynchronous target with a synchronous command calls this | |
2763 | function from both event-top.c and infrun.c/infcmd.c. Once GDB | |
2764 | stops trying to transfer the terminal to the target when it | |
2765 | shouldn't this guard can go away. */ | |
2766 | if (!remote_async_terminal_ours_p) | |
2767 | return; | |
2768 | delete_file_handler (input_fd); | |
2769 | remote_async_terminal_ours_p = 0; | |
2770 | initialize_sigint_signal_handler (); | |
2771 | /* NOTE: At this point we could also register our selves as the | |
2772 | recipient of all input. Any characters typed could then be | |
23860348 | 2773 | passed on down to the target. */ |
6426a772 JM |
2774 | } |
2775 | ||
2776 | static void | |
2777 | remote_async_terminal_ours (void) | |
2778 | { | |
23860348 | 2779 | /* See FIXME in remote_async_terminal_inferior. */ |
6426a772 JM |
2780 | if (!sync_execution) |
2781 | return; | |
23860348 | 2782 | /* See FIXME in remote_async_terminal_inferior. */ |
6426a772 JM |
2783 | if (remote_async_terminal_ours_p) |
2784 | return; | |
2785 | cleanup_sigint_signal_handler (NULL); | |
2786 | add_file_handler (input_fd, stdin_event_handler, 0); | |
2787 | remote_async_terminal_ours_p = 1; | |
2788 | } | |
2789 | ||
c906108c SS |
2790 | /* If nonzero, ignore the next kill. */ |
2791 | ||
2792 | int kill_kludge; | |
2793 | ||
2794 | void | |
917317f4 | 2795 | remote_console_output (char *msg) |
c906108c SS |
2796 | { |
2797 | char *p; | |
2798 | ||
c5aa993b | 2799 | for (p = msg; p[0] && p[1]; p += 2) |
c906108c SS |
2800 | { |
2801 | char tb[2]; | |
2802 | char c = fromhex (p[0]) * 16 + fromhex (p[1]); | |
2803 | tb[0] = c; | |
2804 | tb[1] = 0; | |
43ff13b4 | 2805 | fputs_unfiltered (tb, gdb_stdtarg); |
c906108c | 2806 | } |
917317f4 | 2807 | gdb_flush (gdb_stdtarg); |
c906108c SS |
2808 | } |
2809 | ||
0f71a2f6 JM |
2810 | /* Wait until the remote machine stops, then return, |
2811 | storing status in STATUS just as `wait' would. | |
802188a7 | 2812 | Returns "pid", which in the case of a multi-threaded |
0f71a2f6 | 2813 | remote OS, is the thread-id. */ |
c906108c | 2814 | |
39f77062 KB |
2815 | static ptid_t |
2816 | remote_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c | 2817 | { |
d01949b6 | 2818 | struct remote_state *rs = get_remote_state (); |
cfd77fa1 | 2819 | char *buf = alloca (rs->remote_packet_size); |
b2dd6311 | 2820 | ULONGEST thread_num = -1; |
3c3bea1c | 2821 | ULONGEST addr; |
c906108c SS |
2822 | |
2823 | status->kind = TARGET_WAITKIND_EXITED; | |
2824 | status->value.integer = 0; | |
2825 | ||
2826 | while (1) | |
2827 | { | |
cfd77fa1 | 2828 | char *p; |
c906108c | 2829 | |
c906108c | 2830 | ofunc = signal (SIGINT, remote_interrupt); |
24b06219 | 2831 | getpkt (buf, rs->remote_packet_size, 1); |
c906108c SS |
2832 | signal (SIGINT, ofunc); |
2833 | ||
2834 | /* This is a hook for when we need to do something (perhaps the | |
c5aa993b | 2835 | collection of trace data) every time the target stops. */ |
9a4105ab AC |
2836 | if (deprecated_target_wait_loop_hook) |
2837 | (*deprecated_target_wait_loop_hook) (); | |
c906108c | 2838 | |
3c3bea1c GS |
2839 | remote_stopped_by_watchpoint_p = 0; |
2840 | ||
c906108c SS |
2841 | switch (buf[0]) |
2842 | { | |
23860348 | 2843 | case 'E': /* Error of some sort. */ |
8a3fe4f8 | 2844 | warning (_("Remote failure reply: %s"), buf); |
c906108c | 2845 | continue; |
23860348 | 2846 | case 'F': /* File-I/O request. */ |
449092f6 CV |
2847 | remote_fileio_request (buf); |
2848 | continue; | |
23860348 | 2849 | case 'T': /* Status with PC, SP, FP, ... */ |
c906108c | 2850 | { |
cfd77fa1 | 2851 | gdb_byte regs[MAX_REGISTER_SIZE]; |
c906108c | 2852 | |
23860348 | 2853 | /* Expedited reply, containing Signal, {regno, reg} repeat. */ |
c906108c | 2854 | /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where |
c5aa993b JM |
2855 | ss = signal number |
2856 | n... = register number | |
2857 | r... = register contents | |
2858 | */ | |
c906108c SS |
2859 | p = &buf[3]; /* after Txx */ |
2860 | ||
2861 | while (*p) | |
2862 | { | |
cfd77fa1 | 2863 | char *p1; |
c906108c | 2864 | char *p_temp; |
97345198 | 2865 | int fieldsize; |
3c3bea1c GS |
2866 | LONGEST pnum = 0; |
2867 | ||
23860348 MS |
2868 | /* If the packet contains a register number save it in |
2869 | pnum and set p1 to point to the character following | |
2870 | it. Otherwise p1 points to p. */ | |
c906108c | 2871 | |
23860348 MS |
2872 | /* If this packet is an awatch packet, don't parse the |
2873 | 'a' as a register number. */ | |
3c3bea1c GS |
2874 | |
2875 | if (strncmp (p, "awatch", strlen("awatch")) != 0) | |
2876 | { | |
2877 | /* Read the ``P'' register number. */ | |
2878 | pnum = strtol (p, &p_temp, 16); | |
cfd77fa1 | 2879 | p1 = p_temp; |
3c3bea1c | 2880 | } |
802188a7 | 2881 | else |
3c3bea1c | 2882 | p1 = p; |
c906108c | 2883 | |
23860348 | 2884 | if (p1 == p) /* No register number present here. */ |
c906108c | 2885 | { |
cfd77fa1 | 2886 | p1 = strchr (p, ':'); |
c906108c | 2887 | if (p1 == NULL) |
8a3fe4f8 AC |
2888 | warning (_("Malformed packet(a) (missing colon): %s\n\ |
2889 | Packet: '%s'\n"), | |
c906108c | 2890 | p, buf); |
3c3bea1c | 2891 | if (strncmp (p, "thread", p1 - p) == 0) |
c906108c SS |
2892 | { |
2893 | p_temp = unpack_varlen_hex (++p1, &thread_num); | |
2894 | record_currthread (thread_num); | |
cfd77fa1 | 2895 | p = p_temp; |
c906108c | 2896 | } |
3c3bea1c GS |
2897 | else if ((strncmp (p, "watch", p1 - p) == 0) |
2898 | || (strncmp (p, "rwatch", p1 - p) == 0) | |
2899 | || (strncmp (p, "awatch", p1 - p) == 0)) | |
2900 | { | |
2901 | remote_stopped_by_watchpoint_p = 1; | |
2902 | p = unpack_varlen_hex (++p1, &addr); | |
2903 | remote_watch_data_address = (CORE_ADDR)addr; | |
2904 | } | |
2905 | else | |
2906 | { | |
2907 | /* Silently skip unknown optional info. */ | |
2908 | p_temp = strchr (p1 + 1, ';'); | |
2909 | if (p_temp) | |
cfd77fa1 | 2910 | p = p_temp; |
3c3bea1c | 2911 | } |
c906108c SS |
2912 | } |
2913 | else | |
2914 | { | |
ad10f812 | 2915 | struct packet_reg *reg = packet_reg_from_pnum (rs, pnum); |
c906108c SS |
2916 | p = p1; |
2917 | ||
2918 | if (*p++ != ':') | |
8a3fe4f8 AC |
2919 | error (_("Malformed packet(b) (missing colon): %s\n\ |
2920 | Packet: '%s'\n"), | |
3fcb8548 | 2921 | p, buf); |
c906108c | 2922 | |
ad10f812 | 2923 | if (reg == NULL) |
8a3fe4f8 AC |
2924 | error (_("Remote sent bad register number %s: %s\n\ |
2925 | Packet: '%s'\n"), | |
3fcb8548 | 2926 | phex_nz (pnum, 0), p, buf); |
c906108c | 2927 | |
cfd77fa1 | 2928 | fieldsize = hex2bin (p, regs, |
23860348 MS |
2929 | register_size (current_gdbarch, |
2930 | reg->regnum)); | |
97345198 | 2931 | p += 2 * fieldsize; |
23860348 MS |
2932 | if (fieldsize < register_size (current_gdbarch, |
2933 | reg->regnum)) | |
8a3fe4f8 | 2934 | warning (_("Remote reply is too short: %s"), buf); |
23860348 MS |
2935 | regcache_raw_supply (current_regcache, |
2936 | reg->regnum, regs); | |
c906108c SS |
2937 | } |
2938 | ||
2939 | if (*p++ != ';') | |
8a3fe4f8 | 2940 | error (_("Remote register badly formatted: %s\nhere: %s"), |
23860348 | 2941 | buf, p); |
c906108c SS |
2942 | } |
2943 | } | |
2944 | /* fall through */ | |
23860348 | 2945 | case 'S': /* Old style status, just signal only. */ |
c906108c SS |
2946 | status->kind = TARGET_WAITKIND_STOPPED; |
2947 | status->value.sig = (enum target_signal) | |
2948 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); | |
2949 | ||
0f71a2f6 JM |
2950 | if (buf[3] == 'p') |
2951 | { | |
0f71a2f6 JM |
2952 | thread_num = strtol ((const char *) &buf[4], NULL, 16); |
2953 | record_currthread (thread_num); | |
2954 | } | |
c906108c | 2955 | goto got_status; |
23860348 | 2956 | case 'W': /* Target exited. */ |
c906108c SS |
2957 | { |
2958 | /* The remote process exited. */ | |
2959 | status->kind = TARGET_WAITKIND_EXITED; | |
2960 | status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]); | |
2961 | goto got_status; | |
2962 | } | |
2963 | case 'X': | |
2964 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
2965 | status->value.sig = (enum target_signal) | |
2966 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); | |
2967 | kill_kludge = 1; | |
2968 | ||
2969 | goto got_status; | |
23860348 | 2970 | case 'O': /* Console output. */ |
c906108c SS |
2971 | remote_console_output (buf + 1); |
2972 | continue; | |
2973 | case '\0': | |
2974 | if (last_sent_signal != TARGET_SIGNAL_0) | |
2975 | { | |
2976 | /* Zero length reply means that we tried 'S' or 'C' and | |
c5aa993b | 2977 | the remote system doesn't support it. */ |
c906108c SS |
2978 | target_terminal_ours_for_output (); |
2979 | printf_filtered | |
2980 | ("Can't send signals to this remote system. %s not sent.\n", | |
2981 | target_signal_to_name (last_sent_signal)); | |
2982 | last_sent_signal = TARGET_SIGNAL_0; | |
2983 | target_terminal_inferior (); | |
2984 | ||
2985 | strcpy ((char *) buf, last_sent_step ? "s" : "c"); | |
2986 | putpkt ((char *) buf); | |
2987 | continue; | |
2988 | } | |
2989 | /* else fallthrough */ | |
2990 | default: | |
8a3fe4f8 | 2991 | warning (_("Invalid remote reply: %s"), buf); |
c906108c SS |
2992 | continue; |
2993 | } | |
2994 | } | |
c5aa993b | 2995 | got_status: |
c906108c SS |
2996 | if (thread_num != -1) |
2997 | { | |
39f77062 | 2998 | return pid_to_ptid (thread_num); |
c906108c | 2999 | } |
39f77062 | 3000 | return inferior_ptid; |
c906108c SS |
3001 | } |
3002 | ||
23860348 | 3003 | /* Async version of remote_wait. */ |
39f77062 KB |
3004 | static ptid_t |
3005 | remote_async_wait (ptid_t ptid, struct target_waitstatus *status) | |
43ff13b4 | 3006 | { |
d01949b6 | 3007 | struct remote_state *rs = get_remote_state (); |
cfd77fa1 | 3008 | char *buf = alloca (rs->remote_packet_size); |
b2dd6311 | 3009 | ULONGEST thread_num = -1; |
3c3bea1c | 3010 | ULONGEST addr; |
43ff13b4 JM |
3011 | |
3012 | status->kind = TARGET_WAITKIND_EXITED; | |
3013 | status->value.integer = 0; | |
3014 | ||
3c3bea1c GS |
3015 | remote_stopped_by_watchpoint_p = 0; |
3016 | ||
43ff13b4 JM |
3017 | while (1) |
3018 | { | |
cfd77fa1 | 3019 | char *p; |
c5aa993b | 3020 | |
ed9a39eb | 3021 | if (!target_is_async_p ()) |
43ff13b4 | 3022 | ofunc = signal (SIGINT, remote_interrupt); |
6426a772 JM |
3023 | /* FIXME: cagney/1999-09-27: If we're in async mode we should |
3024 | _never_ wait for ever -> test on target_is_async_p(). | |
3025 | However, before we do that we need to ensure that the caller | |
23860348 | 3026 | knows how to take the target into/out of async mode. */ |
24b06219 | 3027 | getpkt (buf, rs->remote_packet_size, wait_forever_enabled_p); |
ed9a39eb | 3028 | if (!target_is_async_p ()) |
43ff13b4 JM |
3029 | signal (SIGINT, ofunc); |
3030 | ||
3031 | /* This is a hook for when we need to do something (perhaps the | |
c5aa993b | 3032 | collection of trace data) every time the target stops. */ |
9a4105ab AC |
3033 | if (deprecated_target_wait_loop_hook) |
3034 | (*deprecated_target_wait_loop_hook) (); | |
43ff13b4 JM |
3035 | |
3036 | switch (buf[0]) | |
3037 | { | |
23860348 | 3038 | case 'E': /* Error of some sort. */ |
8a3fe4f8 | 3039 | warning (_("Remote failure reply: %s"), buf); |
43ff13b4 | 3040 | continue; |
23860348 | 3041 | case 'F': /* File-I/O request. */ |
449092f6 CV |
3042 | remote_fileio_request (buf); |
3043 | continue; | |
23860348 | 3044 | case 'T': /* Status with PC, SP, FP, ... */ |
43ff13b4 | 3045 | { |
cfd77fa1 | 3046 | gdb_byte regs[MAX_REGISTER_SIZE]; |
43ff13b4 | 3047 | |
23860348 | 3048 | /* Expedited reply, containing Signal, {regno, reg} repeat. */ |
43ff13b4 | 3049 | /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where |
c5aa993b JM |
3050 | ss = signal number |
3051 | n... = register number | |
3052 | r... = register contents | |
3053 | */ | |
43ff13b4 JM |
3054 | p = &buf[3]; /* after Txx */ |
3055 | ||
3056 | while (*p) | |
3057 | { | |
cfd77fa1 | 3058 | char *p1; |
43ff13b4 | 3059 | char *p_temp; |
6c3f2dbf | 3060 | int fieldsize; |
3c3bea1c | 3061 | long pnum = 0; |
43ff13b4 | 3062 | |
23860348 MS |
3063 | /* If the packet contains a register number, save it |
3064 | in pnum and set p1 to point to the character | |
3065 | following it. Otherwise p1 points to p. */ | |
3c3bea1c GS |
3066 | |
3067 | /* If this packet is an awatch packet, don't parse the 'a' | |
3068 | as a register number. */ | |
802188a7 | 3069 | |
3c3bea1c GS |
3070 | if (!strncmp (p, "awatch", strlen ("awatch")) != 0) |
3071 | { | |
3072 | /* Read the register number. */ | |
3073 | pnum = strtol (p, &p_temp, 16); | |
cfd77fa1 | 3074 | p1 = p_temp; |
3c3bea1c | 3075 | } |
802188a7 | 3076 | else |
3c3bea1c | 3077 | p1 = p; |
43ff13b4 | 3078 | |
23860348 | 3079 | if (p1 == p) /* No register number present here. */ |
43ff13b4 | 3080 | { |
cfd77fa1 | 3081 | p1 = strchr (p, ':'); |
43ff13b4 | 3082 | if (p1 == NULL) |
8a3fe4f8 AC |
3083 | error (_("Malformed packet(a) (missing colon): %s\n\ |
3084 | Packet: '%s'\n"), | |
3fcb8548 | 3085 | p, buf); |
3c3bea1c | 3086 | if (strncmp (p, "thread", p1 - p) == 0) |
43ff13b4 JM |
3087 | { |
3088 | p_temp = unpack_varlen_hex (++p1, &thread_num); | |
3089 | record_currthread (thread_num); | |
cfd77fa1 | 3090 | p = p_temp; |
43ff13b4 | 3091 | } |
3c3bea1c GS |
3092 | else if ((strncmp (p, "watch", p1 - p) == 0) |
3093 | || (strncmp (p, "rwatch", p1 - p) == 0) | |
3094 | || (strncmp (p, "awatch", p1 - p) == 0)) | |
3095 | { | |
3096 | remote_stopped_by_watchpoint_p = 1; | |
3097 | p = unpack_varlen_hex (++p1, &addr); | |
3098 | remote_watch_data_address = (CORE_ADDR)addr; | |
3099 | } | |
3100 | else | |
3101 | { | |
3102 | /* Silently skip unknown optional info. */ | |
cfd77fa1 | 3103 | p_temp = strchr (p1 + 1, ';'); |
3c3bea1c GS |
3104 | if (p_temp) |
3105 | p = p_temp; | |
3106 | } | |
43ff13b4 | 3107 | } |
802188a7 | 3108 | |
43ff13b4 JM |
3109 | else |
3110 | { | |
ad10f812 | 3111 | struct packet_reg *reg = packet_reg_from_pnum (rs, pnum); |
43ff13b4 | 3112 | p = p1; |
43ff13b4 | 3113 | if (*p++ != ':') |
8a3fe4f8 AC |
3114 | error (_("Malformed packet(b) (missing colon): %s\n\ |
3115 | Packet: '%s'\n"), | |
3fcb8548 | 3116 | p, buf); |
43ff13b4 | 3117 | |
ad10f812 | 3118 | if (reg == NULL) |
8a3fe4f8 AC |
3119 | error (_("Remote sent bad register number %ld: %s\n\ |
3120 | Packet: '%s'\n"), | |
3fcb8548 | 3121 | pnum, p, buf); |
43ff13b4 | 3122 | |
cfd77fa1 | 3123 | fieldsize = hex2bin (p, regs, |
23860348 MS |
3124 | register_size (current_gdbarch, |
3125 | reg->regnum)); | |
6c3f2dbf | 3126 | p += 2 * fieldsize; |
23860348 MS |
3127 | if (fieldsize < register_size (current_gdbarch, |
3128 | reg->regnum)) | |
8a3fe4f8 | 3129 | warning (_("Remote reply is too short: %s"), buf); |
23a6d369 | 3130 | regcache_raw_supply (current_regcache, reg->regnum, regs); |
43ff13b4 JM |
3131 | } |
3132 | ||
3133 | if (*p++ != ';') | |
8a3fe4f8 | 3134 | error (_("Remote register badly formatted: %s\nhere: %s"), |
0a2cfde4 | 3135 | buf, p); |
43ff13b4 JM |
3136 | } |
3137 | } | |
3138 | /* fall through */ | |
23860348 | 3139 | case 'S': /* Old style status, just signal only. */ |
43ff13b4 JM |
3140 | status->kind = TARGET_WAITKIND_STOPPED; |
3141 | status->value.sig = (enum target_signal) | |
3142 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); | |
3143 | ||
3144 | if (buf[3] == 'p') | |
3145 | { | |
43ff13b4 JM |
3146 | thread_num = strtol ((const char *) &buf[4], NULL, 16); |
3147 | record_currthread (thread_num); | |
3148 | } | |
43ff13b4 | 3149 | goto got_status; |
23860348 | 3150 | case 'W': /* Target exited. */ |
43ff13b4 JM |
3151 | { |
3152 | /* The remote process exited. */ | |
3153 | status->kind = TARGET_WAITKIND_EXITED; | |
3154 | status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]); | |
3155 | goto got_status; | |
3156 | } | |
3157 | case 'X': | |
3158 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
3159 | status->value.sig = (enum target_signal) | |
3160 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); | |
3161 | kill_kludge = 1; | |
3162 | ||
3163 | goto got_status; | |
23860348 | 3164 | case 'O': /* Console output. */ |
43ff13b4 | 3165 | remote_console_output (buf + 1); |
c4093a6a | 3166 | /* Return immediately to the event loop. The event loop will |
23860348 | 3167 | still be waiting on the inferior afterwards. */ |
c4093a6a JM |
3168 | status->kind = TARGET_WAITKIND_IGNORE; |
3169 | goto got_status; | |
43ff13b4 JM |
3170 | case '\0': |
3171 | if (last_sent_signal != TARGET_SIGNAL_0) | |
3172 | { | |
3173 | /* Zero length reply means that we tried 'S' or 'C' and | |
c5aa993b | 3174 | the remote system doesn't support it. */ |
43ff13b4 JM |
3175 | target_terminal_ours_for_output (); |
3176 | printf_filtered | |
3177 | ("Can't send signals to this remote system. %s not sent.\n", | |
3178 | target_signal_to_name (last_sent_signal)); | |
3179 | last_sent_signal = TARGET_SIGNAL_0; | |
3180 | target_terminal_inferior (); | |
3181 | ||
3182 | strcpy ((char *) buf, last_sent_step ? "s" : "c"); | |
3183 | putpkt ((char *) buf); | |
3184 | continue; | |
3185 | } | |
3186 | /* else fallthrough */ | |
3187 | default: | |
8a3fe4f8 | 3188 | warning (_("Invalid remote reply: %s"), buf); |
43ff13b4 JM |
3189 | continue; |
3190 | } | |
3191 | } | |
c5aa993b | 3192 | got_status: |
43ff13b4 JM |
3193 | if (thread_num != -1) |
3194 | { | |
39f77062 | 3195 | return pid_to_ptid (thread_num); |
43ff13b4 | 3196 | } |
39f77062 | 3197 | return inferior_ptid; |
43ff13b4 JM |
3198 | } |
3199 | ||
c906108c SS |
3200 | /* Number of bytes of registers this stub implements. */ |
3201 | ||
3202 | static int register_bytes_found; | |
3203 | ||
3204 | /* Read the remote registers into the block REGS. */ | |
ad10f812 | 3205 | /* Currently we just read all the registers, so we don't use regnum. */ |
c906108c | 3206 | |
b96ec7ac AC |
3207 | static int |
3208 | fetch_register_using_p (int regnum) | |
3209 | { | |
3210 | struct remote_state *rs = get_remote_state (); | |
3211 | char *buf = alloca (rs->remote_packet_size), *p; | |
3212 | char regp[MAX_REGISTER_SIZE]; | |
3213 | int i; | |
3214 | ||
fcad0fa4 JB |
3215 | p = buf; |
3216 | *p++ = 'p'; | |
3217 | p += hexnumstr (p, regnum); | |
3218 | *p++ = '\0'; | |
b96ec7ac | 3219 | remote_send (buf, rs->remote_packet_size); |
3f9a994c JB |
3220 | |
3221 | /* If the stub didn't recognize the packet, or if we got an error, | |
3222 | tell our caller. */ | |
3223 | if (buf[0] == '\0' || buf[0] == 'E') | |
3224 | return 0; | |
3225 | ||
3226 | /* If this register is unfetchable, tell the regcache. */ | |
3227 | if (buf[0] == 'x') | |
8480adf2 | 3228 | { |
3f9a994c JB |
3229 | regcache_raw_supply (current_regcache, regnum, NULL); |
3230 | set_register_cached (regnum, -1); | |
8480adf2 | 3231 | return 1; |
b96ec7ac | 3232 | } |
b96ec7ac | 3233 | |
3f9a994c JB |
3234 | /* Otherwise, parse and supply the value. */ |
3235 | p = buf; | |
3236 | i = 0; | |
3237 | while (p[0] != 0) | |
3238 | { | |
3239 | if (p[1] == 0) | |
3240 | { | |
8a3fe4f8 | 3241 | error (_("fetch_register_using_p: early buf termination")); |
3f9a994c JB |
3242 | return 0; |
3243 | } | |
3244 | ||
3245 | regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]); | |
3246 | p += 2; | |
3247 | } | |
3248 | regcache_raw_supply (current_regcache, regnum, regp); | |
3249 | return 1; | |
b96ec7ac AC |
3250 | } |
3251 | ||
c906108c | 3252 | static void |
ad10f812 | 3253 | remote_fetch_registers (int regnum) |
c906108c | 3254 | { |
d01949b6 AC |
3255 | struct remote_state *rs = get_remote_state (); |
3256 | char *buf = alloca (rs->remote_packet_size); | |
c906108c SS |
3257 | int i; |
3258 | char *p; | |
ad10f812 | 3259 | char *regs = alloca (rs->sizeof_g_packet); |
c906108c | 3260 | |
39f77062 | 3261 | set_thread (PIDGET (inferior_ptid), 1); |
c906108c | 3262 | |
b323314b AC |
3263 | if (regnum >= 0) |
3264 | { | |
3265 | struct packet_reg *reg = packet_reg_from_regnum (rs, regnum); | |
3266 | gdb_assert (reg != NULL); | |
3267 | if (!reg->in_g_packet) | |
3268 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
3269 | _("Attempt to fetch a non G-packet register when this " |
3270 | "remote.c does not support the p-packet.")); | |
b323314b | 3271 | } |
b96ec7ac AC |
3272 | switch (remote_protocol_p.support) |
3273 | { | |
3274 | case PACKET_DISABLE: | |
3275 | break; | |
3276 | case PACKET_ENABLE: | |
3277 | if (fetch_register_using_p (regnum)) | |
3278 | return; | |
3279 | else | |
8a3fe4f8 | 3280 | error (_("Protocol error: p packet not recognized by stub")); |
b96ec7ac AC |
3281 | case PACKET_SUPPORT_UNKNOWN: |
3282 | if (fetch_register_using_p (regnum)) | |
3283 | { | |
3284 | /* The stub recognized the 'p' packet. Remember this. */ | |
3285 | remote_protocol_p.support = PACKET_ENABLE; | |
3286 | return; | |
3287 | } | |
3288 | else | |
3289 | { | |
3290 | /* The stub does not support the 'P' packet. Use 'G' | |
3291 | instead, and don't try using 'P' in the future (it | |
3292 | will just waste our time). */ | |
3293 | remote_protocol_p.support = PACKET_DISABLE; | |
3294 | break; | |
3295 | } | |
3296 | } | |
b323314b | 3297 | |
c906108c | 3298 | sprintf (buf, "g"); |
24b06219 | 3299 | remote_send (buf, rs->remote_packet_size); |
c906108c | 3300 | |
11cf8741 JM |
3301 | /* Save the size of the packet sent to us by the target. Its used |
3302 | as a heuristic when determining the max size of packets that the | |
23860348 | 3303 | target can safely receive. */ |
d01949b6 AC |
3304 | if ((rs->actual_register_packet_size) == 0) |
3305 | (rs->actual_register_packet_size) = strlen (buf); | |
c906108c SS |
3306 | |
3307 | /* Unimplemented registers read as all bits zero. */ | |
ad10f812 | 3308 | memset (regs, 0, rs->sizeof_g_packet); |
c906108c SS |
3309 | |
3310 | /* We can get out of synch in various cases. If the first character | |
3311 | in the buffer is not a hex character, assume that has happened | |
3312 | and try to fetch another packet to read. */ | |
3313 | while ((buf[0] < '0' || buf[0] > '9') | |
3de11b2e | 3314 | && (buf[0] < 'A' || buf[0] > 'F') |
c906108c | 3315 | && (buf[0] < 'a' || buf[0] > 'f') |
23860348 | 3316 | && buf[0] != 'x') /* New: unavailable register value. */ |
c906108c SS |
3317 | { |
3318 | if (remote_debug) | |
0f71a2f6 JM |
3319 | fprintf_unfiltered (gdb_stdlog, |
3320 | "Bad register packet; fetching a new packet\n"); | |
24b06219 | 3321 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c SS |
3322 | } |
3323 | ||
3324 | /* Reply describes registers byte by byte, each byte encoded as two | |
3325 | hex characters. Suck them all up, then supply them to the | |
3326 | register cacheing/storage mechanism. */ | |
3327 | ||
3328 | p = buf; | |
ad10f812 | 3329 | for (i = 0; i < rs->sizeof_g_packet; i++) |
c906108c SS |
3330 | { |
3331 | if (p[0] == 0) | |
3332 | break; | |
3333 | if (p[1] == 0) | |
3334 | { | |
8a3fe4f8 | 3335 | warning (_("Remote reply is of odd length: %s"), buf); |
c906108c SS |
3336 | /* Don't change register_bytes_found in this case, and don't |
3337 | print a second warning. */ | |
3338 | goto supply_them; | |
3339 | } | |
3340 | if (p[0] == 'x' && p[1] == 'x') | |
c5aa993b | 3341 | regs[i] = 0; /* 'x' */ |
c906108c SS |
3342 | else |
3343 | regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]); | |
3344 | p += 2; | |
3345 | } | |
3346 | ||
3347 | if (i != register_bytes_found) | |
3348 | { | |
3349 | register_bytes_found = i; | |
2649061d AC |
3350 | if (REGISTER_BYTES_OK_P () |
3351 | && !REGISTER_BYTES_OK (i)) | |
8a3fe4f8 | 3352 | warning (_("Remote reply is too short: %s"), buf); |
c906108c | 3353 | } |
c5aa993b | 3354 | |
b323314b | 3355 | supply_them: |
ad10f812 | 3356 | { |
b323314b AC |
3357 | int i; |
3358 | for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) | |
ad10f812 | 3359 | { |
b323314b AC |
3360 | struct packet_reg *r = &rs->regs[i]; |
3361 | if (r->in_g_packet) | |
3362 | { | |
8ccc1287 AC |
3363 | if (r->offset * 2 >= strlen (buf)) |
3364 | /* A short packet that didn't include the register's | |
3365 | value, this implies that the register is zero (and | |
3366 | not that the register is unavailable). Supply that | |
3367 | zero value. */ | |
3368 | regcache_raw_supply (current_regcache, r->regnum, NULL); | |
3369 | else if (buf[r->offset * 2] == 'x') | |
3370 | { | |
3371 | gdb_assert (r->offset * 2 < strlen (buf)); | |
3372 | /* The register isn't available, mark it as such (at | |
3373 | the same time setting the value to zero). */ | |
3374 | regcache_raw_supply (current_regcache, r->regnum, NULL); | |
3375 | set_register_cached (i, -1); | |
3376 | } | |
3377 | else | |
3378 | regcache_raw_supply (current_regcache, r->regnum, | |
3379 | regs + r->offset); | |
b323314b | 3380 | } |
ad10f812 AC |
3381 | } |
3382 | } | |
c906108c SS |
3383 | } |
3384 | ||
3385 | /* Prepare to store registers. Since we may send them all (using a | |
3386 | 'G' request), we have to read out the ones we don't want to change | |
3387 | first. */ | |
3388 | ||
c5aa993b | 3389 | static void |
fba45db2 | 3390 | remote_prepare_to_store (void) |
c906108c | 3391 | { |
cf0e1e0d DJ |
3392 | struct remote_state *rs = get_remote_state (); |
3393 | int i; | |
cfd77fa1 | 3394 | gdb_byte buf[MAX_REGISTER_SIZE]; |
cf0e1e0d | 3395 | |
c906108c | 3396 | /* Make sure the entire registers array is valid. */ |
5a2468f5 JM |
3397 | switch (remote_protocol_P.support) |
3398 | { | |
3399 | case PACKET_DISABLE: | |
3400 | case PACKET_SUPPORT_UNKNOWN: | |
cf0e1e0d DJ |
3401 | /* Make sure all the necessary registers are cached. */ |
3402 | for (i = 0; i < NUM_REGS; i++) | |
3403 | if (rs->regs[i].in_g_packet) | |
3404 | regcache_raw_read (current_regcache, rs->regs[i].regnum, buf); | |
5a2468f5 JM |
3405 | break; |
3406 | case PACKET_ENABLE: | |
3407 | break; | |
3408 | } | |
3409 | } | |
3410 | ||
ad10f812 | 3411 | /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF |
23860348 | 3412 | packet was not recognized. */ |
5a2468f5 JM |
3413 | |
3414 | static int | |
ad10f812 | 3415 | store_register_using_P (int regnum) |
5a2468f5 | 3416 | { |
d01949b6 | 3417 | struct remote_state *rs = get_remote_state (); |
ad10f812 | 3418 | struct packet_reg *reg = packet_reg_from_regnum (rs, regnum); |
5a2468f5 | 3419 | /* Try storing a single register. */ |
d01949b6 | 3420 | char *buf = alloca (rs->remote_packet_size); |
cfd77fa1 | 3421 | gdb_byte regp[MAX_REGISTER_SIZE]; |
5a2468f5 | 3422 | char *p; |
5a2468f5 | 3423 | |
ecbc58df | 3424 | xsnprintf (buf, rs->remote_packet_size, "P%s=", phex_nz (reg->pnum, 0)); |
5a2468f5 | 3425 | p = buf + strlen (buf); |
822c9732 | 3426 | regcache_raw_collect (current_regcache, reg->regnum, regp); |
3acba339 | 3427 | bin2hex (regp, p, register_size (current_gdbarch, reg->regnum)); |
ad10f812 | 3428 | remote_send (buf, rs->remote_packet_size); |
5a2468f5 JM |
3429 | |
3430 | return buf[0] != '\0'; | |
c906108c SS |
3431 | } |
3432 | ||
5a2468f5 | 3433 | |
23860348 MS |
3434 | /* Store register REGNUM, or all registers if REGNUM == -1, from the |
3435 | contents of the register cache buffer. FIXME: ignores errors. */ | |
c906108c SS |
3436 | |
3437 | static void | |
ad10f812 | 3438 | remote_store_registers (int regnum) |
c906108c | 3439 | { |
d01949b6 | 3440 | struct remote_state *rs = get_remote_state (); |
193cb69f | 3441 | char *buf; |
cfd77fa1 | 3442 | gdb_byte *regs; |
c906108c SS |
3443 | char *p; |
3444 | ||
39f77062 | 3445 | set_thread (PIDGET (inferior_ptid), 1); |
c906108c | 3446 | |
ad10f812 | 3447 | if (regnum >= 0) |
c906108c | 3448 | { |
5a2468f5 | 3449 | switch (remote_protocol_P.support) |
c906108c | 3450 | { |
5a2468f5 JM |
3451 | case PACKET_DISABLE: |
3452 | break; | |
3453 | case PACKET_ENABLE: | |
ad10f812 | 3454 | if (store_register_using_P (regnum)) |
5a2468f5 JM |
3455 | return; |
3456 | else | |
8a3fe4f8 | 3457 | error (_("Protocol error: P packet not recognized by stub")); |
5a2468f5 | 3458 | case PACKET_SUPPORT_UNKNOWN: |
ad10f812 | 3459 | if (store_register_using_P (regnum)) |
5a2468f5 JM |
3460 | { |
3461 | /* The stub recognized the 'P' packet. Remember this. */ | |
3462 | remote_protocol_P.support = PACKET_ENABLE; | |
3463 | return; | |
3464 | } | |
3465 | else | |
3466 | { | |
3467 | /* The stub does not support the 'P' packet. Use 'G' | |
3468 | instead, and don't try using 'P' in the future (it | |
3469 | will just waste our time). */ | |
3470 | remote_protocol_P.support = PACKET_DISABLE; | |
3471 | break; | |
3472 | } | |
c906108c | 3473 | } |
c906108c SS |
3474 | } |
3475 | ||
193cb69f AC |
3476 | /* Extract all the registers in the regcache copying them into a |
3477 | local buffer. */ | |
3478 | { | |
b323314b | 3479 | int i; |
ad10f812 | 3480 | regs = alloca (rs->sizeof_g_packet); |
170cd118 | 3481 | memset (regs, 0, rs->sizeof_g_packet); |
b323314b | 3482 | for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) |
193cb69f | 3483 | { |
b323314b AC |
3484 | struct packet_reg *r = &rs->regs[i]; |
3485 | if (r->in_g_packet) | |
822c9732 | 3486 | regcache_raw_collect (current_regcache, r->regnum, regs + r->offset); |
193cb69f AC |
3487 | } |
3488 | } | |
c906108c SS |
3489 | |
3490 | /* Command describes registers byte by byte, | |
3491 | each byte encoded as two hex characters. */ | |
193cb69f AC |
3492 | buf = alloca (rs->remote_packet_size); |
3493 | p = buf; | |
3494 | *p++ = 'G'; | |
c906108c | 3495 | /* remote_prepare_to_store insures that register_bytes_found gets set. */ |
30559e10 | 3496 | bin2hex (regs, p, register_bytes_found); |
24b06219 | 3497 | remote_send (buf, rs->remote_packet_size); |
c906108c | 3498 | } |
c906108c SS |
3499 | \f |
3500 | ||
3501 | /* Return the number of hex digits in num. */ | |
3502 | ||
3503 | static int | |
fba45db2 | 3504 | hexnumlen (ULONGEST num) |
c906108c SS |
3505 | { |
3506 | int i; | |
3507 | ||
3508 | for (i = 0; num != 0; i++) | |
3509 | num >>= 4; | |
3510 | ||
3511 | return max (i, 1); | |
3512 | } | |
3513 | ||
2df3850c | 3514 | /* Set BUF to the minimum number of hex digits representing NUM. */ |
c906108c SS |
3515 | |
3516 | static int | |
fba45db2 | 3517 | hexnumstr (char *buf, ULONGEST num) |
c906108c | 3518 | { |
c906108c | 3519 | int len = hexnumlen (num); |
2df3850c JM |
3520 | return hexnumnstr (buf, num, len); |
3521 | } | |
3522 | ||
c906108c | 3523 | |
2df3850c | 3524 | /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */ |
c906108c | 3525 | |
2df3850c | 3526 | static int |
fba45db2 | 3527 | hexnumnstr (char *buf, ULONGEST num, int width) |
2df3850c JM |
3528 | { |
3529 | int i; | |
3530 | ||
3531 | buf[width] = '\0'; | |
3532 | ||
3533 | for (i = width - 1; i >= 0; i--) | |
c906108c | 3534 | { |
c5aa993b | 3535 | buf[i] = "0123456789abcdef"[(num & 0xf)]; |
c906108c SS |
3536 | num >>= 4; |
3537 | } | |
3538 | ||
2df3850c | 3539 | return width; |
c906108c SS |
3540 | } |
3541 | ||
23860348 | 3542 | /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */ |
c906108c SS |
3543 | |
3544 | static CORE_ADDR | |
fba45db2 | 3545 | remote_address_masked (CORE_ADDR addr) |
c906108c SS |
3546 | { |
3547 | if (remote_address_size > 0 | |
3548 | && remote_address_size < (sizeof (ULONGEST) * 8)) | |
3549 | { | |
3550 | /* Only create a mask when that mask can safely be constructed | |
23860348 | 3551 | in a ULONGEST variable. */ |
c906108c SS |
3552 | ULONGEST mask = 1; |
3553 | mask = (mask << remote_address_size) - 1; | |
3554 | addr &= mask; | |
3555 | } | |
3556 | return addr; | |
3557 | } | |
3558 | ||
3559 | /* Determine whether the remote target supports binary downloading. | |
3560 | This is accomplished by sending a no-op memory write of zero length | |
3561 | to the target at the specified address. It does not suffice to send | |
23860348 MS |
3562 | the whole packet, since many stubs strip the eighth bit and |
3563 | subsequently compute a wrong checksum, which causes real havoc with | |
3564 | remote_write_bytes. | |
7a292a7a | 3565 | |
96baa820 JM |
3566 | NOTE: This can still lose if the serial line is not eight-bit |
3567 | clean. In cases like this, the user should clear "remote | |
23860348 | 3568 | X-packet". */ |
96baa820 | 3569 | |
c906108c | 3570 | static void |
fba45db2 | 3571 | check_binary_download (CORE_ADDR addr) |
c906108c | 3572 | { |
d01949b6 | 3573 | struct remote_state *rs = get_remote_state (); |
24b06219 | 3574 | |
96baa820 | 3575 | switch (remote_protocol_binary_download.support) |
c906108c | 3576 | { |
96baa820 JM |
3577 | case PACKET_DISABLE: |
3578 | break; | |
3579 | case PACKET_ENABLE: | |
3580 | break; | |
3581 | case PACKET_SUPPORT_UNKNOWN: | |
3582 | { | |
d01949b6 | 3583 | char *buf = alloca (rs->remote_packet_size); |
96baa820 | 3584 | char *p; |
802188a7 | 3585 | |
96baa820 JM |
3586 | p = buf; |
3587 | *p++ = 'X'; | |
3588 | p += hexnumstr (p, (ULONGEST) addr); | |
3589 | *p++ = ','; | |
3590 | p += hexnumstr (p, (ULONGEST) 0); | |
3591 | *p++ = ':'; | |
3592 | *p = '\0'; | |
802188a7 | 3593 | |
96baa820 | 3594 | putpkt_binary (buf, (int) (p - buf)); |
24b06219 | 3595 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c | 3596 | |
96baa820 JM |
3597 | if (buf[0] == '\0') |
3598 | { | |
3599 | if (remote_debug) | |
3600 | fprintf_unfiltered (gdb_stdlog, | |
3601 | "binary downloading NOT suppported by target\n"); | |
3602 | remote_protocol_binary_download.support = PACKET_DISABLE; | |
3603 | } | |
3604 | else | |
3605 | { | |
3606 | if (remote_debug) | |
3607 | fprintf_unfiltered (gdb_stdlog, | |
3608 | "binary downloading suppported by target\n"); | |
3609 | remote_protocol_binary_download.support = PACKET_ENABLE; | |
3610 | } | |
3611 | break; | |
3612 | } | |
c906108c SS |
3613 | } |
3614 | } | |
3615 | ||
3616 | /* Write memory data directly to the remote machine. | |
3617 | This does not inform the data cache; the data cache uses this. | |
3618 | MEMADDR is the address in the remote memory space. | |
3619 | MYADDR is the address of the buffer in our space. | |
3620 | LEN is the number of bytes. | |
3621 | ||
917317f4 | 3622 | Returns number of bytes transferred, or 0 (setting errno) for |
23860348 | 3623 | error. Only transfer a single packet. */ |
c906108c | 3624 | |
449092f6 | 3625 | int |
cfd77fa1 | 3626 | remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
c906108c | 3627 | { |
cfd77fa1 DJ |
3628 | char *buf; |
3629 | char *p; | |
3630 | char *plen; | |
c2d11a7d | 3631 | long sizeof_buf; |
917317f4 JM |
3632 | int plenlen; |
3633 | int todo; | |
3634 | int nr_bytes; | |
a257b5bb | 3635 | int payload_size; |
cfd77fa1 | 3636 | char *payload_start; |
c906108c | 3637 | |
a257b5bb | 3638 | /* Verify that the target can support a binary download. */ |
c906108c SS |
3639 | check_binary_download (memaddr); |
3640 | ||
3de11b2e NS |
3641 | payload_size = get_memory_write_packet_size (); |
3642 | ||
a257b5bb | 3643 | /* Compute the size, and then allocate space for the largest |
3de11b2e NS |
3644 | possible packet. Include space for an extra trailing NUL. */ |
3645 | sizeof_buf = payload_size + 1; | |
c2d11a7d | 3646 | buf = alloca (sizeof_buf); |
c906108c | 3647 | |
a257b5bb | 3648 | /* Compute the size of the actual payload by subtracting out the |
3de11b2e NS |
3649 | packet header and footer overhead: "$M<memaddr>,<len>:...#nn". |
3650 | */ | |
3651 | payload_size -= strlen ("$M,:#NN"); | |
3652 | payload_size -= hexnumlen (memaddr); | |
c906108c | 3653 | |
a257b5bb | 3654 | /* Construct the packet header: "[MX]<memaddr>,<len>:". */ |
917317f4 | 3655 | |
a257b5bb | 3656 | /* Append "[XM]". Compute a best guess of the number of bytes |
23860348 | 3657 | actually transfered. */ |
a257b5bb | 3658 | p = buf; |
917317f4 | 3659 | switch (remote_protocol_binary_download.support) |
c906108c | 3660 | { |
917317f4 JM |
3661 | case PACKET_ENABLE: |
3662 | *p++ = 'X'; | |
23860348 | 3663 | /* Best guess at number of bytes that will fit. */ |
a257b5bb | 3664 | todo = min (len, payload_size); |
3de11b2e NS |
3665 | payload_size -= hexnumlen (todo); |
3666 | todo = min (todo, payload_size); | |
917317f4 JM |
3667 | break; |
3668 | case PACKET_DISABLE: | |
3669 | *p++ = 'M'; | |
23860348 | 3670 | /* Num bytes that will fit. */ |
a257b5bb | 3671 | todo = min (len, payload_size / 2); |
3de11b2e NS |
3672 | payload_size -= hexnumlen (todo); |
3673 | todo = min (todo, payload_size / 2); | |
917317f4 JM |
3674 | break; |
3675 | case PACKET_SUPPORT_UNKNOWN: | |
8e65ff28 | 3676 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3677 | _("remote_write_bytes: bad internal state")); |
7f7e9482 | 3678 | default: |
e2e0b3e5 | 3679 | internal_error (__FILE__, __LINE__, _("bad switch")); |
917317f4 | 3680 | } |
3de11b2e NS |
3681 | if (todo <= 0) |
3682 | internal_error (__FILE__, __LINE__, | |
3683 | _("minumum packet size too small to write data")); | |
802188a7 | 3684 | |
a257b5bb | 3685 | /* Append "<memaddr>". */ |
917317f4 JM |
3686 | memaddr = remote_address_masked (memaddr); |
3687 | p += hexnumstr (p, (ULONGEST) memaddr); | |
a257b5bb AC |
3688 | |
3689 | /* Append ",". */ | |
917317f4 | 3690 | *p++ = ','; |
802188a7 | 3691 | |
a257b5bb AC |
3692 | /* Append <len>. Retain the location/size of <len>. It may need to |
3693 | be adjusted once the packet body has been created. */ | |
917317f4 JM |
3694 | plen = p; |
3695 | plenlen = hexnumstr (p, (ULONGEST) todo); | |
3696 | p += plenlen; | |
a257b5bb AC |
3697 | |
3698 | /* Append ":". */ | |
917317f4 JM |
3699 | *p++ = ':'; |
3700 | *p = '\0'; | |
802188a7 | 3701 | |
a257b5bb AC |
3702 | /* Append the packet body. */ |
3703 | payload_start = p; | |
917317f4 JM |
3704 | switch (remote_protocol_binary_download.support) |
3705 | { | |
3706 | case PACKET_ENABLE: | |
3707 | /* Binary mode. Send target system values byte by byte, in | |
3708 | increasing byte addresses. Only escape certain critical | |
3709 | characters. */ | |
3710 | for (nr_bytes = 0; | |
a257b5bb | 3711 | (nr_bytes < todo) && (p - payload_start) < payload_size; |
917317f4 | 3712 | nr_bytes++) |
c906108c | 3713 | { |
917317f4 JM |
3714 | switch (myaddr[nr_bytes] & 0xff) |
3715 | { | |
3716 | case '$': | |
3717 | case '#': | |
3718 | case 0x7d: | |
23860348 | 3719 | /* These must be escaped. */ |
917317f4 JM |
3720 | *p++ = 0x7d; |
3721 | *p++ = (myaddr[nr_bytes] & 0xff) ^ 0x20; | |
3722 | break; | |
3723 | default: | |
3724 | *p++ = myaddr[nr_bytes] & 0xff; | |
3725 | break; | |
3726 | } | |
c906108c | 3727 | } |
917317f4 | 3728 | if (nr_bytes < todo) |
c906108c | 3729 | { |
802188a7 | 3730 | /* Escape chars have filled up the buffer prematurely, |
917317f4 JM |
3731 | and we have actually sent fewer bytes than planned. |
3732 | Fix-up the length field of the packet. Use the same | |
3733 | number of characters as before. */ | |
917317f4 JM |
3734 | plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen); |
3735 | *plen = ':'; /* overwrite \0 from hexnumnstr() */ | |
c906108c | 3736 | } |
917317f4 JM |
3737 | break; |
3738 | case PACKET_DISABLE: | |
3739 | /* Normal mode: Send target system values byte by byte, in | |
3740 | increasing byte addresses. Each byte is encoded as a two hex | |
3741 | value. */ | |
2644f393 | 3742 | nr_bytes = bin2hex (myaddr, p, todo); |
aa6c0017 | 3743 | p += 2 * nr_bytes; |
917317f4 JM |
3744 | break; |
3745 | case PACKET_SUPPORT_UNKNOWN: | |
8e65ff28 | 3746 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3747 | _("remote_write_bytes: bad internal state")); |
7f7e9482 | 3748 | default: |
e2e0b3e5 | 3749 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c | 3750 | } |
802188a7 | 3751 | |
917317f4 | 3752 | putpkt_binary (buf, (int) (p - buf)); |
c2d11a7d | 3753 | getpkt (buf, sizeof_buf, 0); |
802188a7 | 3754 | |
917317f4 JM |
3755 | if (buf[0] == 'E') |
3756 | { | |
3757 | /* There is no correspondance between what the remote protocol | |
3758 | uses for errors and errno codes. We would like a cleaner way | |
3759 | of representing errors (big enough to include errno codes, | |
3760 | bfd_error codes, and others). But for now just return EIO. */ | |
3761 | errno = EIO; | |
3762 | return 0; | |
3763 | } | |
802188a7 | 3764 | |
23860348 MS |
3765 | /* Return NR_BYTES, not TODO, in case escape chars caused us to send |
3766 | fewer bytes than we'd planned. */ | |
917317f4 | 3767 | return nr_bytes; |
c906108c SS |
3768 | } |
3769 | ||
3770 | /* Read memory data directly from the remote machine. | |
3771 | This does not use the data cache; the data cache uses this. | |
3772 | MEMADDR is the address in the remote memory space. | |
3773 | MYADDR is the address of the buffer in our space. | |
3774 | LEN is the number of bytes. | |
3775 | ||
3776 | Returns number of bytes transferred, or 0 for error. */ | |
3777 | ||
917317f4 JM |
3778 | /* NOTE: cagney/1999-10-18: This function (and its siblings in other |
3779 | remote targets) shouldn't attempt to read the entire buffer. | |
3780 | Instead it should read a single packet worth of data and then | |
3781 | return the byte size of that packet to the caller. The caller (its | |
3782 | caller and its callers caller ;-) already contains code for | |
23860348 | 3783 | handling partial reads. */ |
917317f4 | 3784 | |
449092f6 | 3785 | int |
cfd77fa1 | 3786 | remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
c906108c | 3787 | { |
11cf8741 | 3788 | char *buf; |
23860348 | 3789 | int max_buf_size; /* Max size of packet output buffer. */ |
c2d11a7d | 3790 | long sizeof_buf; |
c906108c SS |
3791 | int origlen; |
3792 | ||
23860348 | 3793 | /* Create a buffer big enough for this packet. */ |
11cf8741 | 3794 | max_buf_size = get_memory_read_packet_size (); |
23860348 | 3795 | sizeof_buf = max_buf_size + 1; /* Space for trailing NULL. */ |
c2d11a7d | 3796 | buf = alloca (sizeof_buf); |
c906108c SS |
3797 | |
3798 | origlen = len; | |
3799 | while (len > 0) | |
3800 | { | |
c906108c SS |
3801 | char *p; |
3802 | int todo; | |
3803 | int i; | |
3804 | ||
c5aa993b | 3805 | todo = min (len, max_buf_size / 2); /* num bytes that will fit */ |
c906108c SS |
3806 | |
3807 | /* construct "m"<memaddr>","<len>" */ | |
3808 | /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */ | |
3809 | memaddr = remote_address_masked (memaddr); | |
3810 | p = buf; | |
3811 | *p++ = 'm'; | |
3812 | p += hexnumstr (p, (ULONGEST) memaddr); | |
3813 | *p++ = ','; | |
3814 | p += hexnumstr (p, (ULONGEST) todo); | |
3815 | *p = '\0'; | |
3816 | ||
3817 | putpkt (buf); | |
c2d11a7d | 3818 | getpkt (buf, sizeof_buf, 0); |
c906108c | 3819 | |
66504d44 MS |
3820 | if (buf[0] == 'E' |
3821 | && isxdigit (buf[1]) && isxdigit (buf[2]) | |
3822 | && buf[3] == '\0') | |
c906108c | 3823 | { |
23860348 MS |
3824 | /* There is no correspondance between what the remote |
3825 | protocol uses for errors and errno codes. We would like | |
3826 | a cleaner way of representing errors (big enough to | |
3827 | include errno codes, bfd_error codes, and others). But | |
3828 | for now just return EIO. */ | |
c906108c SS |
3829 | errno = EIO; |
3830 | return 0; | |
3831 | } | |
3832 | ||
c5aa993b JM |
3833 | /* Reply describes memory byte by byte, |
3834 | each byte encoded as two hex characters. */ | |
c906108c SS |
3835 | |
3836 | p = buf; | |
30559e10 | 3837 | if ((i = hex2bin (p, myaddr, todo)) < todo) |
c906108c | 3838 | { |
30559e10 | 3839 | /* Reply is short. This means that we were able to read |
23860348 | 3840 | only part of what we wanted to. */ |
30559e10 | 3841 | return i + (origlen - len); |
c906108c SS |
3842 | } |
3843 | myaddr += todo; | |
3844 | memaddr += todo; | |
3845 | len -= todo; | |
3846 | } | |
3847 | return origlen; | |
3848 | } | |
3849 | \f | |
3850 | /* Read or write LEN bytes from inferior memory at MEMADDR, | |
23860348 MS |
3851 | transferring to or from debugger address BUFFER. Write to inferior |
3852 | if SHOULD_WRITE is nonzero. Returns length of data written or | |
3853 | read; 0 for error. TARGET is unused. */ | |
392a587b | 3854 | |
c906108c | 3855 | static int |
961cb7b5 | 3856 | remote_xfer_memory (CORE_ADDR mem_addr, gdb_byte *buffer, int mem_len, |
0a65a603 | 3857 | int should_write, struct mem_attrib *attrib, |
29e57380 | 3858 | struct target_ops *target) |
c906108c | 3859 | { |
392a587b JM |
3860 | CORE_ADDR targ_addr; |
3861 | int targ_len; | |
4930751a C |
3862 | int res; |
3863 | ||
f6684c31 | 3864 | /* Should this be the selected frame? */ |
23860348 MS |
3865 | gdbarch_remote_translate_xfer_address (current_gdbarch, |
3866 | current_regcache, | |
f6684c31 AC |
3867 | mem_addr, mem_len, |
3868 | &targ_addr, &targ_len); | |
392a587b | 3869 | if (targ_len <= 0) |
c906108c | 3870 | return 0; |
c906108c | 3871 | |
4930751a C |
3872 | if (should_write) |
3873 | res = remote_write_bytes (targ_addr, buffer, targ_len); | |
3874 | else | |
3875 | res = remote_read_bytes (targ_addr, buffer, targ_len); | |
3876 | ||
3877 | return res; | |
c906108c SS |
3878 | } |
3879 | ||
c906108c | 3880 | static void |
fba45db2 | 3881 | remote_files_info (struct target_ops *ignore) |
c906108c SS |
3882 | { |
3883 | puts_filtered ("Debugging a target over a serial line.\n"); | |
3884 | } | |
3885 | \f | |
3886 | /* Stuff for dealing with the packets which are part of this protocol. | |
3887 | See comment at top of file for details. */ | |
3888 | ||
23860348 MS |
3889 | /* Read a single character from the remote end, masking it down to 7 |
3890 | bits. */ | |
c906108c SS |
3891 | |
3892 | static int | |
fba45db2 | 3893 | readchar (int timeout) |
c906108c SS |
3894 | { |
3895 | int ch; | |
3896 | ||
2cd58942 | 3897 | ch = serial_readchar (remote_desc, timeout); |
c906108c | 3898 | |
2acceee2 JM |
3899 | if (ch >= 0) |
3900 | return (ch & 0x7f); | |
3901 | ||
3902 | switch ((enum serial_rc) ch) | |
c906108c SS |
3903 | { |
3904 | case SERIAL_EOF: | |
2acceee2 | 3905 | target_mourn_inferior (); |
8a3fe4f8 | 3906 | error (_("Remote connection closed")); |
2acceee2 | 3907 | /* no return */ |
c906108c | 3908 | case SERIAL_ERROR: |
e2e0b3e5 | 3909 | perror_with_name (_("Remote communication error")); |
2acceee2 | 3910 | /* no return */ |
c906108c | 3911 | case SERIAL_TIMEOUT: |
2acceee2 | 3912 | break; |
c906108c | 3913 | } |
2acceee2 | 3914 | return ch; |
c906108c SS |
3915 | } |
3916 | ||
3917 | /* Send the command in BUF to the remote machine, and read the reply | |
3918 | into BUF. Report an error if we get an error reply. */ | |
3919 | ||
3920 | static void | |
c2d11a7d JM |
3921 | remote_send (char *buf, |
3922 | long sizeof_buf) | |
c906108c SS |
3923 | { |
3924 | putpkt (buf); | |
c2d11a7d | 3925 | getpkt (buf, sizeof_buf, 0); |
c906108c SS |
3926 | |
3927 | if (buf[0] == 'E') | |
8a3fe4f8 | 3928 | error (_("Remote failure reply: %s"), buf); |
c906108c SS |
3929 | } |
3930 | ||
3931 | /* Display a null-terminated packet on stdout, for debugging, using C | |
3932 | string notation. */ | |
3933 | ||
3934 | static void | |
fba45db2 | 3935 | print_packet (char *buf) |
c906108c SS |
3936 | { |
3937 | puts_filtered ("\""); | |
43e526b9 | 3938 | fputstr_filtered (buf, '"', gdb_stdout); |
c906108c SS |
3939 | puts_filtered ("\""); |
3940 | } | |
3941 | ||
3942 | int | |
fba45db2 | 3943 | putpkt (char *buf) |
c906108c SS |
3944 | { |
3945 | return putpkt_binary (buf, strlen (buf)); | |
3946 | } | |
3947 | ||
3948 | /* Send a packet to the remote machine, with error checking. The data | |
23860348 | 3949 | of the packet is in BUF. The string in BUF can be at most |
24b06219 | 3950 | RS->remote_packet_size - 5 to account for the $, # and checksum, |
23860348 MS |
3951 | and for a possible /0 if we are debugging (remote_debug) and want |
3952 | to print the sent packet as a string. */ | |
c906108c SS |
3953 | |
3954 | static int | |
fba45db2 | 3955 | putpkt_binary (char *buf, int cnt) |
c906108c | 3956 | { |
d01949b6 | 3957 | struct remote_state *rs = get_remote_state (); |
c906108c SS |
3958 | int i; |
3959 | unsigned char csum = 0; | |
11cf8741 | 3960 | char *buf2 = alloca (cnt + 6); |
24b06219 | 3961 | long sizeof_junkbuf = rs->remote_packet_size; |
c2d11a7d | 3962 | char *junkbuf = alloca (sizeof_junkbuf); |
085dd6e6 | 3963 | |
c906108c SS |
3964 | int ch; |
3965 | int tcount = 0; | |
3966 | char *p; | |
3967 | ||
3968 | /* Copy the packet into buffer BUF2, encapsulating it | |
3969 | and giving it a checksum. */ | |
3970 | ||
c906108c SS |
3971 | p = buf2; |
3972 | *p++ = '$'; | |
3973 | ||
3974 | for (i = 0; i < cnt; i++) | |
3975 | { | |
3976 | csum += buf[i]; | |
3977 | *p++ = buf[i]; | |
3978 | } | |
3979 | *p++ = '#'; | |
3980 | *p++ = tohex ((csum >> 4) & 0xf); | |
3981 | *p++ = tohex (csum & 0xf); | |
3982 | ||
3983 | /* Send it over and over until we get a positive ack. */ | |
3984 | ||
3985 | while (1) | |
3986 | { | |
3987 | int started_error_output = 0; | |
3988 | ||
3989 | if (remote_debug) | |
3990 | { | |
3991 | *p = '\0'; | |
43e526b9 JM |
3992 | fprintf_unfiltered (gdb_stdlog, "Sending packet: "); |
3993 | fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog); | |
d4f3574e | 3994 | fprintf_unfiltered (gdb_stdlog, "..."); |
0f71a2f6 | 3995 | gdb_flush (gdb_stdlog); |
c906108c | 3996 | } |
2cd58942 | 3997 | if (serial_write (remote_desc, buf2, p - buf2)) |
e2e0b3e5 | 3998 | perror_with_name (_("putpkt: write failed")); |
c906108c | 3999 | |
23860348 | 4000 | /* Read until either a timeout occurs (-2) or '+' is read. */ |
c906108c SS |
4001 | while (1) |
4002 | { | |
4003 | ch = readchar (remote_timeout); | |
4004 | ||
c5aa993b | 4005 | if (remote_debug) |
c906108c SS |
4006 | { |
4007 | switch (ch) | |
4008 | { | |
4009 | case '+': | |
1216fa2c | 4010 | case '-': |
c906108c SS |
4011 | case SERIAL_TIMEOUT: |
4012 | case '$': | |
4013 | if (started_error_output) | |
4014 | { | |
4015 | putchar_unfiltered ('\n'); | |
4016 | started_error_output = 0; | |
4017 | } | |
4018 | } | |
4019 | } | |
4020 | ||
4021 | switch (ch) | |
4022 | { | |
4023 | case '+': | |
4024 | if (remote_debug) | |
0f71a2f6 | 4025 | fprintf_unfiltered (gdb_stdlog, "Ack\n"); |
c906108c | 4026 | return 1; |
1216fa2c AC |
4027 | case '-': |
4028 | if (remote_debug) | |
4029 | fprintf_unfiltered (gdb_stdlog, "Nak\n"); | |
c906108c | 4030 | case SERIAL_TIMEOUT: |
c5aa993b | 4031 | tcount++; |
c906108c SS |
4032 | if (tcount > 3) |
4033 | return 0; | |
23860348 | 4034 | break; /* Retransmit buffer. */ |
c906108c SS |
4035 | case '$': |
4036 | { | |
40e3f985 | 4037 | if (remote_debug) |
23860348 MS |
4038 | fprintf_unfiltered (gdb_stdlog, |
4039 | "Packet instead of Ack, ignoring it\n"); | |
d6f7abdf AC |
4040 | /* It's probably an old response sent because an ACK |
4041 | was lost. Gobble up the packet and ack it so it | |
4042 | doesn't get retransmitted when we resend this | |
4043 | packet. */ | |
40e3f985 | 4044 | read_frame (junkbuf, sizeof_junkbuf); |
d6f7abdf | 4045 | serial_write (remote_desc, "+", 1); |
23860348 | 4046 | continue; /* Now, go look for +. */ |
c906108c SS |
4047 | } |
4048 | default: | |
4049 | if (remote_debug) | |
4050 | { | |
4051 | if (!started_error_output) | |
4052 | { | |
4053 | started_error_output = 1; | |
0f71a2f6 | 4054 | fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: "); |
c906108c | 4055 | } |
0f71a2f6 | 4056 | fputc_unfiltered (ch & 0177, gdb_stdlog); |
c906108c SS |
4057 | } |
4058 | continue; | |
4059 | } | |
23860348 | 4060 | break; /* Here to retransmit. */ |
c906108c SS |
4061 | } |
4062 | ||
4063 | #if 0 | |
4064 | /* This is wrong. If doing a long backtrace, the user should be | |
c5aa993b JM |
4065 | able to get out next time we call QUIT, without anything as |
4066 | violent as interrupt_query. If we want to provide a way out of | |
4067 | here without getting to the next QUIT, it should be based on | |
4068 | hitting ^C twice as in remote_wait. */ | |
c906108c SS |
4069 | if (quit_flag) |
4070 | { | |
4071 | quit_flag = 0; | |
4072 | interrupt_query (); | |
4073 | } | |
4074 | #endif | |
4075 | } | |
4076 | } | |
4077 | ||
4078 | /* Come here after finding the start of the frame. Collect the rest | |
4079 | into BUF, verifying the checksum, length, and handling run-length | |
c2d11a7d JM |
4080 | compression. No more than sizeof_buf-1 characters are read so that |
4081 | the buffer can be NUL terminated. | |
c906108c | 4082 | |
c2d11a7d JM |
4083 | Returns -1 on error, number of characters in buffer (ignoring the |
4084 | trailing NULL) on success. (could be extended to return one of the | |
23860348 | 4085 | SERIAL status indications). */ |
c2d11a7d JM |
4086 | |
4087 | static long | |
4088 | read_frame (char *buf, | |
4089 | long sizeof_buf) | |
c906108c SS |
4090 | { |
4091 | unsigned char csum; | |
c2d11a7d | 4092 | long bc; |
c906108c SS |
4093 | int c; |
4094 | ||
4095 | csum = 0; | |
c2d11a7d | 4096 | bc = 0; |
c906108c SS |
4097 | |
4098 | while (1) | |
4099 | { | |
23860348 | 4100 | /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */ |
c906108c | 4101 | c = readchar (remote_timeout); |
c906108c SS |
4102 | switch (c) |
4103 | { | |
4104 | case SERIAL_TIMEOUT: | |
4105 | if (remote_debug) | |
0f71a2f6 | 4106 | fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog); |
c2d11a7d | 4107 | return -1; |
c906108c SS |
4108 | case '$': |
4109 | if (remote_debug) | |
0f71a2f6 JM |
4110 | fputs_filtered ("Saw new packet start in middle of old one\n", |
4111 | gdb_stdlog); | |
23860348 | 4112 | return -1; /* Start a new packet, count retries. */ |
c906108c SS |
4113 | case '#': |
4114 | { | |
4115 | unsigned char pktcsum; | |
e1b09194 AC |
4116 | int check_0 = 0; |
4117 | int check_1 = 0; | |
c906108c | 4118 | |
c2d11a7d | 4119 | buf[bc] = '\0'; |
c906108c | 4120 | |
e1b09194 AC |
4121 | check_0 = readchar (remote_timeout); |
4122 | if (check_0 >= 0) | |
4123 | check_1 = readchar (remote_timeout); | |
802188a7 | 4124 | |
e1b09194 AC |
4125 | if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT) |
4126 | { | |
4127 | if (remote_debug) | |
23860348 MS |
4128 | fputs_filtered ("Timeout in checksum, retrying\n", |
4129 | gdb_stdlog); | |
e1b09194 AC |
4130 | return -1; |
4131 | } | |
4132 | else if (check_0 < 0 || check_1 < 0) | |
40e3f985 FN |
4133 | { |
4134 | if (remote_debug) | |
23860348 MS |
4135 | fputs_filtered ("Communication error in checksum\n", |
4136 | gdb_stdlog); | |
40e3f985 FN |
4137 | return -1; |
4138 | } | |
c906108c | 4139 | |
e1b09194 | 4140 | pktcsum = (fromhex (check_0) << 4) | fromhex (check_1); |
c906108c | 4141 | if (csum == pktcsum) |
c2d11a7d | 4142 | return bc; |
c906108c | 4143 | |
c5aa993b | 4144 | if (remote_debug) |
c906108c | 4145 | { |
0f71a2f6 | 4146 | fprintf_filtered (gdb_stdlog, |
c5aa993b | 4147 | "Bad checksum, sentsum=0x%x, csum=0x%x, buf=", |
0f71a2f6 JM |
4148 | pktcsum, csum); |
4149 | fputs_filtered (buf, gdb_stdlog); | |
4150 | fputs_filtered ("\n", gdb_stdlog); | |
c906108c | 4151 | } |
c2d11a7d | 4152 | /* Number of characters in buffer ignoring trailing |
23860348 | 4153 | NULL. */ |
c2d11a7d | 4154 | return -1; |
c906108c | 4155 | } |
23860348 | 4156 | case '*': /* Run length encoding. */ |
c2c6d25f JM |
4157 | { |
4158 | int repeat; | |
4159 | csum += c; | |
c906108c | 4160 | |
b4501125 AC |
4161 | c = readchar (remote_timeout); |
4162 | csum += c; | |
23860348 | 4163 | repeat = c - ' ' + 3; /* Compute repeat count. */ |
c906108c | 4164 | |
23860348 | 4165 | /* The character before ``*'' is repeated. */ |
c2d11a7d | 4166 | |
802188a7 | 4167 | if (repeat > 0 && repeat <= 255 |
c2d11a7d | 4168 | && bc > 0 |
fb6e5c55 | 4169 | && bc + repeat - 1 < sizeof_buf - 1) |
c2c6d25f | 4170 | { |
c2d11a7d JM |
4171 | memset (&buf[bc], buf[bc - 1], repeat); |
4172 | bc += repeat; | |
c2c6d25f JM |
4173 | continue; |
4174 | } | |
4175 | ||
c2d11a7d | 4176 | buf[bc] = '\0'; |
a3f17187 | 4177 | printf_filtered (_("Repeat count %d too large for buffer: "), |
23860348 | 4178 | repeat); |
c2c6d25f JM |
4179 | puts_filtered (buf); |
4180 | puts_filtered ("\n"); | |
c2d11a7d | 4181 | return -1; |
c2c6d25f | 4182 | } |
c906108c | 4183 | default: |
c2d11a7d | 4184 | if (bc < sizeof_buf - 1) |
c906108c | 4185 | { |
c2d11a7d | 4186 | buf[bc++] = c; |
c906108c SS |
4187 | csum += c; |
4188 | continue; | |
4189 | } | |
4190 | ||
c2d11a7d | 4191 | buf[bc] = '\0'; |
c906108c SS |
4192 | puts_filtered ("Remote packet too long: "); |
4193 | puts_filtered (buf); | |
4194 | puts_filtered ("\n"); | |
4195 | ||
c2d11a7d | 4196 | return -1; |
c906108c SS |
4197 | } |
4198 | } | |
4199 | } | |
4200 | ||
4201 | /* Read a packet from the remote machine, with error checking, and | |
c2d11a7d JM |
4202 | store it in BUF. If FOREVER, wait forever rather than timing out; |
4203 | this is used (in synchronous mode) to wait for a target that is is | |
4204 | executing user code to stop. */ | |
d9fcf2fb JM |
4205 | /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we |
4206 | don't have to change all the calls to getpkt to deal with the | |
4207 | return value, because at the moment I don't know what the right | |
23860348 | 4208 | thing to do it for those. */ |
c906108c | 4209 | void |
c2d11a7d JM |
4210 | getpkt (char *buf, |
4211 | long sizeof_buf, | |
4212 | int forever) | |
d9fcf2fb JM |
4213 | { |
4214 | int timed_out; | |
4215 | ||
4216 | timed_out = getpkt_sane (buf, sizeof_buf, forever); | |
4217 | } | |
4218 | ||
4219 | ||
4220 | /* Read a packet from the remote machine, with error checking, and | |
4221 | store it in BUF. If FOREVER, wait forever rather than timing out; | |
4222 | this is used (in synchronous mode) to wait for a target that is is | |
4223 | executing user code to stop. If FOREVER == 0, this function is | |
4224 | allowed to time out gracefully and return an indication of this to | |
23860348 | 4225 | the caller. */ |
3172dc30 | 4226 | static int |
d9fcf2fb JM |
4227 | getpkt_sane (char *buf, |
4228 | long sizeof_buf, | |
4229 | int forever) | |
c906108c SS |
4230 | { |
4231 | int c; | |
4232 | int tries; | |
4233 | int timeout; | |
4234 | int val; | |
4235 | ||
c5aa993b | 4236 | strcpy (buf, "timeout"); |
c906108c SS |
4237 | |
4238 | if (forever) | |
4239 | { | |
c906108c | 4240 | timeout = watchdog > 0 ? watchdog : -1; |
c906108c SS |
4241 | } |
4242 | ||
4243 | else | |
4244 | timeout = remote_timeout; | |
4245 | ||
4246 | #define MAX_TRIES 3 | |
4247 | ||
4248 | for (tries = 1; tries <= MAX_TRIES; tries++) | |
4249 | { | |
4250 | /* This can loop forever if the remote side sends us characters | |
23860348 MS |
4251 | continuously, but if it pauses, we'll get a zero from |
4252 | readchar because of timeout. Then we'll count that as a | |
4253 | retry. */ | |
c906108c | 4254 | |
23860348 MS |
4255 | /* Note that we will only wait forever prior to the start of a |
4256 | packet. After that, we expect characters to arrive at a | |
4257 | brisk pace. They should show up within remote_timeout | |
4258 | intervals. */ | |
c906108c SS |
4259 | |
4260 | do | |
4261 | { | |
4262 | c = readchar (timeout); | |
4263 | ||
4264 | if (c == SERIAL_TIMEOUT) | |
4265 | { | |
23860348 | 4266 | if (forever) /* Watchdog went off? Kill the target. */ |
c906108c | 4267 | { |
2acceee2 | 4268 | QUIT; |
c906108c | 4269 | target_mourn_inferior (); |
8a3fe4f8 | 4270 | error (_("Watchdog has expired. Target detached.")); |
c906108c | 4271 | } |
c906108c | 4272 | if (remote_debug) |
0f71a2f6 | 4273 | fputs_filtered ("Timed out.\n", gdb_stdlog); |
c906108c SS |
4274 | goto retry; |
4275 | } | |
4276 | } | |
4277 | while (c != '$'); | |
4278 | ||
4279 | /* We've found the start of a packet, now collect the data. */ | |
4280 | ||
c2d11a7d | 4281 | val = read_frame (buf, sizeof_buf); |
c906108c | 4282 | |
c2d11a7d | 4283 | if (val >= 0) |
c906108c SS |
4284 | { |
4285 | if (remote_debug) | |
43e526b9 JM |
4286 | { |
4287 | fprintf_unfiltered (gdb_stdlog, "Packet received: "); | |
4288 | fputstr_unfiltered (buf, 0, gdb_stdlog); | |
4289 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
4290 | } | |
2cd58942 | 4291 | serial_write (remote_desc, "+", 1); |
d9fcf2fb | 4292 | return 0; |
c906108c SS |
4293 | } |
4294 | ||
4295 | /* Try the whole thing again. */ | |
4296 | retry: | |
2cd58942 | 4297 | serial_write (remote_desc, "-", 1); |
c906108c SS |
4298 | } |
4299 | ||
23860348 MS |
4300 | /* We have tried hard enough, and just can't receive the packet. |
4301 | Give up. */ | |
c906108c | 4302 | |
a3f17187 | 4303 | printf_unfiltered (_("Ignoring packet error, continuing...\n")); |
2cd58942 | 4304 | serial_write (remote_desc, "+", 1); |
d9fcf2fb | 4305 | return 1; |
c906108c SS |
4306 | } |
4307 | \f | |
4308 | static void | |
fba45db2 | 4309 | remote_kill (void) |
c906108c SS |
4310 | { |
4311 | /* For some mysterious reason, wait_for_inferior calls kill instead of | |
4312 | mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */ | |
4313 | if (kill_kludge) | |
4314 | { | |
4315 | kill_kludge = 0; | |
4316 | target_mourn_inferior (); | |
4317 | return; | |
4318 | } | |
4319 | ||
4320 | /* Use catch_errors so the user can quit from gdb even when we aren't on | |
4321 | speaking terms with the remote system. */ | |
c5aa993b | 4322 | catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR); |
c906108c SS |
4323 | |
4324 | /* Don't wait for it to die. I'm not really sure it matters whether | |
4325 | we do or not. For the existing stubs, kill is a noop. */ | |
4326 | target_mourn_inferior (); | |
4327 | } | |
4328 | ||
23860348 | 4329 | /* Async version of remote_kill. */ |
43ff13b4 | 4330 | static void |
fba45db2 | 4331 | remote_async_kill (void) |
43ff13b4 | 4332 | { |
23860348 | 4333 | /* Unregister the file descriptor from the event loop. */ |
ed9a39eb | 4334 | if (target_is_async_p ()) |
2cd58942 | 4335 | serial_async (remote_desc, NULL, 0); |
43ff13b4 JM |
4336 | |
4337 | /* For some mysterious reason, wait_for_inferior calls kill instead of | |
4338 | mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */ | |
4339 | if (kill_kludge) | |
4340 | { | |
4341 | kill_kludge = 0; | |
4342 | target_mourn_inferior (); | |
4343 | return; | |
4344 | } | |
4345 | ||
23860348 MS |
4346 | /* Use catch_errors so the user can quit from gdb even when we |
4347 | aren't on speaking terms with the remote system. */ | |
c5aa993b | 4348 | catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR); |
43ff13b4 JM |
4349 | |
4350 | /* Don't wait for it to die. I'm not really sure it matters whether | |
4351 | we do or not. For the existing stubs, kill is a noop. */ | |
4352 | target_mourn_inferior (); | |
4353 | } | |
4354 | ||
c906108c | 4355 | static void |
fba45db2 | 4356 | remote_mourn (void) |
c906108c SS |
4357 | { |
4358 | remote_mourn_1 (&remote_ops); | |
4359 | } | |
4360 | ||
53a5351d | 4361 | static void |
fba45db2 | 4362 | remote_async_mourn (void) |
53a5351d JM |
4363 | { |
4364 | remote_mourn_1 (&remote_async_ops); | |
4365 | } | |
4366 | ||
c906108c | 4367 | static void |
fba45db2 | 4368 | extended_remote_mourn (void) |
c906108c SS |
4369 | { |
4370 | /* We do _not_ want to mourn the target like this; this will | |
4371 | remove the extended remote target from the target stack, | |
802188a7 | 4372 | and the next time the user says "run" it'll fail. |
c906108c SS |
4373 | |
4374 | FIXME: What is the right thing to do here? */ | |
4375 | #if 0 | |
4376 | remote_mourn_1 (&extended_remote_ops); | |
4377 | #endif | |
4378 | } | |
4379 | ||
4380 | /* Worker function for remote_mourn. */ | |
4381 | static void | |
fba45db2 | 4382 | remote_mourn_1 (struct target_ops *target) |
c906108c SS |
4383 | { |
4384 | unpush_target (target); | |
4385 | generic_mourn_inferior (); | |
4386 | } | |
4387 | ||
4388 | /* In the extended protocol we want to be able to do things like | |
4389 | "run" and have them basically work as expected. So we need | |
802188a7 | 4390 | a special create_inferior function. |
c906108c SS |
4391 | |
4392 | FIXME: One day add support for changing the exec file | |
4393 | we're debugging, arguments and an environment. */ | |
4394 | ||
4395 | static void | |
23860348 MS |
4396 | extended_remote_create_inferior (char *exec_file, char *args, |
4397 | char **env, int from_tty) | |
c906108c SS |
4398 | { |
4399 | /* Rip out the breakpoints; we'll reinsert them after restarting | |
4400 | the remote server. */ | |
4401 | remove_breakpoints (); | |
4402 | ||
4403 | /* Now restart the remote server. */ | |
4404 | extended_remote_restart (); | |
4405 | ||
4406 | /* Now put the breakpoints back in. This way we're safe if the | |
4407 | restart function works via a unix fork on the remote side. */ | |
4408 | insert_breakpoints (); | |
4409 | ||
4410 | /* Clean up from the last time we were running. */ | |
4411 | clear_proceed_status (); | |
c906108c SS |
4412 | } |
4413 | ||
23860348 | 4414 | /* Async version of extended_remote_create_inferior. */ |
43ff13b4 | 4415 | static void |
23860348 MS |
4416 | extended_remote_async_create_inferior (char *exec_file, char *args, |
4417 | char **env, int from_tty) | |
43ff13b4 JM |
4418 | { |
4419 | /* Rip out the breakpoints; we'll reinsert them after restarting | |
4420 | the remote server. */ | |
4421 | remove_breakpoints (); | |
4422 | ||
4423 | /* If running asynchronously, register the target file descriptor | |
23860348 | 4424 | with the event loop. */ |
362646f5 | 4425 | if (target_can_async_p ()) |
2acceee2 | 4426 | target_async (inferior_event_handler, 0); |
43ff13b4 JM |
4427 | |
4428 | /* Now restart the remote server. */ | |
4429 | extended_remote_restart (); | |
4430 | ||
4431 | /* Now put the breakpoints back in. This way we're safe if the | |
4432 | restart function works via a unix fork on the remote side. */ | |
4433 | insert_breakpoints (); | |
4434 | ||
4435 | /* Clean up from the last time we were running. */ | |
4436 | clear_proceed_status (); | |
43ff13b4 | 4437 | } |
c906108c | 4438 | \f |
c5aa993b | 4439 | |
aaab4dba | 4440 | /* On some machines, e.g. 68k, we may use a different breakpoint |
7fec2c59 AC |
4441 | instruction than other targets; in those use |
4442 | DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC. | |
4443 | Also, bi-endian targets may define | |
4444 | DEPRECATED_LITTLE_REMOTE_BREAKPOINT and | |
4445 | DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we | |
4446 | just call the standard routines that are in mem-break.c. */ | |
4447 | ||
4448 | /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator | |
4449 | target should use an identical BREAKPOINT_FROM_PC. As for native, | |
4450 | the ARCH-OS-tdep.c code can override the default. */ | |
4451 | ||
4452 | #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT) | |
4453 | #define DEPRECATED_REMOTE_BREAKPOINT | |
c906108c SS |
4454 | #endif |
4455 | ||
7fec2c59 | 4456 | #ifdef DEPRECATED_REMOTE_BREAKPOINT |
c906108c SS |
4457 | |
4458 | /* If the target isn't bi-endian, just pretend it is. */ | |
7fec2c59 AC |
4459 | #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) |
4460 | #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT | |
4461 | #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT | |
c906108c SS |
4462 | #endif |
4463 | ||
7fec2c59 AC |
4464 | static unsigned char big_break_insn[] = DEPRECATED_BIG_REMOTE_BREAKPOINT; |
4465 | static unsigned char little_break_insn[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT; | |
c906108c | 4466 | |
7fec2c59 | 4467 | #endif /* DEPRECATED_REMOTE_BREAKPOINT */ |
c906108c | 4468 | |
aaab4dba AC |
4469 | /* Insert a breakpoint on targets that don't have any better |
4470 | breakpoint support. We read the contents of the target location | |
4471 | and stash it, then overwrite it with a breakpoint instruction. | |
4472 | ADDR is the target location in the target machine. CONTENTS_CACHE | |
4473 | is a pointer to memory allocated for saving the target contents. | |
4474 | It is guaranteed by the caller to be long enough to save the number | |
4475 | of bytes returned by BREAKPOINT_FROM_PC. */ | |
c906108c SS |
4476 | |
4477 | static int | |
5a168c78 | 4478 | remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
c906108c | 4479 | { |
d01949b6 | 4480 | struct remote_state *rs = get_remote_state (); |
7fec2c59 | 4481 | #ifdef DEPRECATED_REMOTE_BREAKPOINT |
c906108c | 4482 | int val; |
802188a7 | 4483 | #endif |
96baa820 JM |
4484 | int bp_size; |
4485 | ||
d471ea57 AC |
4486 | /* Try the "Z" s/w breakpoint packet if it is not already disabled. |
4487 | If it succeeds, then set the support to PACKET_ENABLE. If it | |
4488 | fails, and the user has explicitly requested the Z support then | |
23860348 | 4489 | report an error, otherwise, mark it disabled and go on. */ |
802188a7 | 4490 | |
d471ea57 | 4491 | if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE) |
96baa820 | 4492 | { |
d01949b6 | 4493 | char *buf = alloca (rs->remote_packet_size); |
e514a9d6 | 4494 | char *p = buf; |
802188a7 | 4495 | |
0caabb7e | 4496 | addr = remote_address_masked (addr); |
96baa820 JM |
4497 | *(p++) = 'Z'; |
4498 | *(p++) = '0'; | |
4499 | *(p++) = ','; | |
0caabb7e AC |
4500 | p += hexnumstr (p, (ULONGEST) addr); |
4501 | BREAKPOINT_FROM_PC (&addr, &bp_size); | |
96baa820 | 4502 | sprintf (p, ",%d", bp_size); |
802188a7 | 4503 | |
96baa820 | 4504 | putpkt (buf); |
24b06219 | 4505 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 | 4506 | |
d471ea57 | 4507 | switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP])) |
96baa820 | 4508 | { |
d471ea57 AC |
4509 | case PACKET_ERROR: |
4510 | return -1; | |
4511 | case PACKET_OK: | |
4512 | return 0; | |
4513 | case PACKET_UNKNOWN: | |
4514 | break; | |
96baa820 JM |
4515 | } |
4516 | } | |
c906108c | 4517 | |
802188a7 | 4518 | #ifdef DEPRECATED_REMOTE_BREAKPOINT |
c906108c SS |
4519 | val = target_read_memory (addr, contents_cache, sizeof big_break_insn); |
4520 | ||
4521 | if (val == 0) | |
4522 | { | |
d7449b42 | 4523 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
4524 | val = target_write_memory (addr, (char *) big_break_insn, |
4525 | sizeof big_break_insn); | |
4526 | else | |
4527 | val = target_write_memory (addr, (char *) little_break_insn, | |
4528 | sizeof little_break_insn); | |
4529 | } | |
4530 | ||
4531 | return val; | |
4532 | #else | |
4533 | return memory_insert_breakpoint (addr, contents_cache); | |
7fec2c59 | 4534 | #endif /* DEPRECATED_REMOTE_BREAKPOINT */ |
c906108c SS |
4535 | } |
4536 | ||
4537 | static int | |
5a168c78 | 4538 | remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
c906108c | 4539 | { |
d01949b6 | 4540 | struct remote_state *rs = get_remote_state (); |
96baa820 JM |
4541 | int bp_size; |
4542 | ||
d471ea57 | 4543 | if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE) |
96baa820 | 4544 | { |
d01949b6 | 4545 | char *buf = alloca (rs->remote_packet_size); |
e514a9d6 | 4546 | char *p = buf; |
802188a7 | 4547 | |
96baa820 JM |
4548 | *(p++) = 'z'; |
4549 | *(p++) = '0'; | |
4550 | *(p++) = ','; | |
4551 | ||
0caabb7e AC |
4552 | addr = remote_address_masked (addr); |
4553 | p += hexnumstr (p, (ULONGEST) addr); | |
4554 | BREAKPOINT_FROM_PC (&addr, &bp_size); | |
96baa820 | 4555 | sprintf (p, ",%d", bp_size); |
802188a7 | 4556 | |
96baa820 | 4557 | putpkt (buf); |
24b06219 | 4558 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 JM |
4559 | |
4560 | return (buf[0] == 'E'); | |
4561 | } | |
4562 | ||
7fec2c59 | 4563 | #ifdef DEPRECATED_REMOTE_BREAKPOINT |
c906108c SS |
4564 | return target_write_memory (addr, contents_cache, sizeof big_break_insn); |
4565 | #else | |
4566 | return memory_remove_breakpoint (addr, contents_cache); | |
7fec2c59 | 4567 | #endif /* DEPRECATED_REMOTE_BREAKPOINT */ |
c906108c SS |
4568 | } |
4569 | ||
d471ea57 AC |
4570 | static int |
4571 | watchpoint_to_Z_packet (int type) | |
4572 | { | |
4573 | switch (type) | |
4574 | { | |
4575 | case hw_write: | |
4576 | return 2; | |
4577 | break; | |
4578 | case hw_read: | |
4579 | return 3; | |
4580 | break; | |
4581 | case hw_access: | |
4582 | return 4; | |
4583 | break; | |
4584 | default: | |
8e65ff28 | 4585 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4586 | _("hw_bp_to_z: bad watchpoint type %d"), type); |
d471ea57 AC |
4587 | } |
4588 | } | |
4589 | ||
3c3bea1c | 4590 | static int |
fba45db2 | 4591 | remote_insert_watchpoint (CORE_ADDR addr, int len, int type) |
96baa820 | 4592 | { |
d01949b6 AC |
4593 | struct remote_state *rs = get_remote_state (); |
4594 | char *buf = alloca (rs->remote_packet_size); | |
e514a9d6 | 4595 | char *p; |
d471ea57 | 4596 | enum Z_packet_type packet = watchpoint_to_Z_packet (type); |
96baa820 | 4597 | |
d471ea57 | 4598 | if (remote_protocol_Z[packet].support == PACKET_DISABLE) |
8a3fe4f8 | 4599 | error (_("Can't set hardware watchpoints without the '%s' (%s) packet."), |
d471ea57 AC |
4600 | remote_protocol_Z[packet].name, |
4601 | remote_protocol_Z[packet].title); | |
802188a7 | 4602 | |
d471ea57 | 4603 | sprintf (buf, "Z%x,", packet); |
96baa820 JM |
4604 | p = strchr (buf, '\0'); |
4605 | addr = remote_address_masked (addr); | |
4606 | p += hexnumstr (p, (ULONGEST) addr); | |
d4f3574e | 4607 | sprintf (p, ",%x", len); |
802188a7 | 4608 | |
96baa820 | 4609 | putpkt (buf); |
24b06219 | 4610 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 | 4611 | |
d471ea57 AC |
4612 | switch (packet_ok (buf, &remote_protocol_Z[packet])) |
4613 | { | |
4614 | case PACKET_ERROR: | |
4615 | case PACKET_UNKNOWN: | |
4616 | return -1; | |
4617 | case PACKET_OK: | |
4618 | return 0; | |
4619 | } | |
8e65ff28 | 4620 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4621 | _("remote_insert_watchpoint: reached end of function")); |
96baa820 JM |
4622 | } |
4623 | ||
d471ea57 | 4624 | |
3c3bea1c | 4625 | static int |
fba45db2 | 4626 | remote_remove_watchpoint (CORE_ADDR addr, int len, int type) |
96baa820 | 4627 | { |
d01949b6 AC |
4628 | struct remote_state *rs = get_remote_state (); |
4629 | char *buf = alloca (rs->remote_packet_size); | |
e514a9d6 | 4630 | char *p; |
d471ea57 AC |
4631 | enum Z_packet_type packet = watchpoint_to_Z_packet (type); |
4632 | ||
4633 | if (remote_protocol_Z[packet].support == PACKET_DISABLE) | |
8a3fe4f8 | 4634 | error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."), |
d471ea57 AC |
4635 | remote_protocol_Z[packet].name, |
4636 | remote_protocol_Z[packet].title); | |
802188a7 | 4637 | |
d471ea57 | 4638 | sprintf (buf, "z%x,", packet); |
96baa820 JM |
4639 | p = strchr (buf, '\0'); |
4640 | addr = remote_address_masked (addr); | |
4641 | p += hexnumstr (p, (ULONGEST) addr); | |
d4f3574e | 4642 | sprintf (p, ",%x", len); |
96baa820 | 4643 | putpkt (buf); |
24b06219 | 4644 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 | 4645 | |
d471ea57 AC |
4646 | switch (packet_ok (buf, &remote_protocol_Z[packet])) |
4647 | { | |
4648 | case PACKET_ERROR: | |
4649 | case PACKET_UNKNOWN: | |
4650 | return -1; | |
4651 | case PACKET_OK: | |
4652 | return 0; | |
4653 | } | |
8e65ff28 | 4654 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4655 | _("remote_remove_watchpoint: reached end of function")); |
96baa820 JM |
4656 | } |
4657 | ||
3c3bea1c | 4658 | |
501eef12 AC |
4659 | int remote_hw_watchpoint_limit = -1; |
4660 | int remote_hw_breakpoint_limit = -1; | |
d471ea57 | 4661 | |
b9362cc7 | 4662 | static int |
3c3bea1c | 4663 | remote_check_watch_resources (int type, int cnt, int ot) |
96baa820 | 4664 | { |
3c3bea1c GS |
4665 | if (type == bp_hardware_breakpoint) |
4666 | { | |
4667 | if (remote_hw_breakpoint_limit == 0) | |
4668 | return 0; | |
501eef12 AC |
4669 | else if (remote_hw_breakpoint_limit < 0) |
4670 | return 1; | |
3c3bea1c GS |
4671 | else if (cnt <= remote_hw_breakpoint_limit) |
4672 | return 1; | |
4673 | } | |
4674 | else | |
4675 | { | |
4676 | if (remote_hw_watchpoint_limit == 0) | |
4677 | return 0; | |
501eef12 AC |
4678 | else if (remote_hw_watchpoint_limit < 0) |
4679 | return 1; | |
3c3bea1c GS |
4680 | else if (ot) |
4681 | return -1; | |
4682 | else if (cnt <= remote_hw_watchpoint_limit) | |
4683 | return 1; | |
4684 | } | |
4685 | return -1; | |
4686 | } | |
4687 | ||
b9362cc7 | 4688 | static int |
3c3bea1c GS |
4689 | remote_stopped_by_watchpoint (void) |
4690 | { | |
4691 | return remote_stopped_by_watchpoint_p; | |
4692 | } | |
4693 | ||
7270d8f2 OF |
4694 | extern int stepped_after_stopped_by_watchpoint; |
4695 | ||
4aa7a7f5 JJ |
4696 | static int |
4697 | remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p) | |
3c3bea1c | 4698 | { |
4aa7a7f5 | 4699 | int rc = 0; |
7270d8f2 OF |
4700 | if (remote_stopped_by_watchpoint () |
4701 | || stepped_after_stopped_by_watchpoint) | |
4aa7a7f5 JJ |
4702 | { |
4703 | *addr_p = remote_watch_data_address; | |
4704 | rc = 1; | |
4705 | } | |
4706 | ||
4707 | return rc; | |
3c3bea1c GS |
4708 | } |
4709 | ||
4710 | ||
4711 | static int | |
c6826062 | 4712 | remote_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow) |
3c3bea1c GS |
4713 | { |
4714 | int len = 0; | |
d01949b6 AC |
4715 | struct remote_state *rs = get_remote_state (); |
4716 | char *buf = alloca (rs->remote_packet_size); | |
e514a9d6 | 4717 | char *p = buf; |
802188a7 | 4718 | |
c8189ed1 GS |
4719 | /* The length field should be set to the size of a breakpoint |
4720 | instruction. */ | |
4721 | ||
802188a7 | 4722 | BREAKPOINT_FROM_PC (&addr, &len); |
3c3bea1c | 4723 | |
d471ea57 | 4724 | if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE) |
8a3fe4f8 | 4725 | error (_("Can't set hardware breakpoint without the '%s' (%s) packet."), |
d471ea57 AC |
4726 | remote_protocol_Z[Z_PACKET_HARDWARE_BP].name, |
4727 | remote_protocol_Z[Z_PACKET_HARDWARE_BP].title); | |
802188a7 | 4728 | |
96baa820 JM |
4729 | *(p++) = 'Z'; |
4730 | *(p++) = '1'; | |
4731 | *(p++) = ','; | |
802188a7 | 4732 | |
96baa820 JM |
4733 | addr = remote_address_masked (addr); |
4734 | p += hexnumstr (p, (ULONGEST) addr); | |
ad6525fc | 4735 | sprintf (p, ",%x", len); |
96baa820 JM |
4736 | |
4737 | putpkt (buf); | |
24b06219 | 4738 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 | 4739 | |
d471ea57 AC |
4740 | switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP])) |
4741 | { | |
4742 | case PACKET_ERROR: | |
4743 | case PACKET_UNKNOWN: | |
4744 | return -1; | |
4745 | case PACKET_OK: | |
4746 | return 0; | |
4747 | } | |
8e65ff28 | 4748 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4749 | _("remote_insert_hw_breakpoint: reached end of function")); |
96baa820 JM |
4750 | } |
4751 | ||
d471ea57 | 4752 | |
802188a7 | 4753 | static int |
c6826062 | 4754 | remote_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow) |
96baa820 | 4755 | { |
3c3bea1c | 4756 | int len; |
d01949b6 AC |
4757 | struct remote_state *rs = get_remote_state (); |
4758 | char *buf = alloca (rs->remote_packet_size); | |
e514a9d6 | 4759 | char *p = buf; |
c8189ed1 GS |
4760 | |
4761 | /* The length field should be set to the size of a breakpoint | |
4762 | instruction. */ | |
4763 | ||
4764 | BREAKPOINT_FROM_PC (&addr, &len); | |
4765 | ||
d471ea57 | 4766 | if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE) |
8a3fe4f8 | 4767 | error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."), |
d471ea57 AC |
4768 | remote_protocol_Z[Z_PACKET_HARDWARE_BP].name, |
4769 | remote_protocol_Z[Z_PACKET_HARDWARE_BP].title); | |
802188a7 | 4770 | |
96baa820 JM |
4771 | *(p++) = 'z'; |
4772 | *(p++) = '1'; | |
4773 | *(p++) = ','; | |
802188a7 | 4774 | |
96baa820 JM |
4775 | addr = remote_address_masked (addr); |
4776 | p += hexnumstr (p, (ULONGEST) addr); | |
ad6525fc | 4777 | sprintf (p, ",%x", len); |
96baa820 JM |
4778 | |
4779 | putpkt(buf); | |
24b06219 | 4780 | getpkt (buf, rs->remote_packet_size, 0); |
802188a7 | 4781 | |
d471ea57 AC |
4782 | switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP])) |
4783 | { | |
4784 | case PACKET_ERROR: | |
4785 | case PACKET_UNKNOWN: | |
4786 | return -1; | |
4787 | case PACKET_OK: | |
4788 | return 0; | |
4789 | } | |
8e65ff28 | 4790 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4791 | _("remote_remove_hw_breakpoint: reached end of function")); |
96baa820 | 4792 | } |
96baa820 | 4793 | |
c906108c SS |
4794 | /* Some targets are only capable of doing downloads, and afterwards |
4795 | they switch to the remote serial protocol. This function provides | |
4796 | a clean way to get from the download target to the remote target. | |
4797 | It's basically just a wrapper so that we don't have to expose any | |
4798 | of the internal workings of remote.c. | |
4799 | ||
4800 | Prior to calling this routine, you should shutdown the current | |
4801 | target code, else you will get the "A program is being debugged | |
4802 | already..." message. Usually a call to pop_target() suffices. */ | |
4803 | ||
4804 | void | |
fba45db2 | 4805 | push_remote_target (char *name, int from_tty) |
c906108c | 4806 | { |
a3f17187 | 4807 | printf_filtered (_("Switching to remote protocol\n")); |
c906108c SS |
4808 | remote_open (name, from_tty); |
4809 | } | |
4810 | ||
23860348 | 4811 | /* Table used by the crc32 function to calcuate the checksum. */ |
c906108c | 4812 | |
c5aa993b JM |
4813 | static unsigned long crc32_table[256] = |
4814 | {0, 0}; | |
c906108c SS |
4815 | |
4816 | static unsigned long | |
fba45db2 | 4817 | crc32 (unsigned char *buf, int len, unsigned int crc) |
c906108c | 4818 | { |
c5aa993b | 4819 | if (!crc32_table[1]) |
c906108c | 4820 | { |
23860348 | 4821 | /* Initialize the CRC table and the decoding table. */ |
c906108c SS |
4822 | int i, j; |
4823 | unsigned int c; | |
4824 | ||
4825 | for (i = 0; i < 256; i++) | |
c5aa993b JM |
4826 | { |
4827 | for (c = i << 24, j = 8; j > 0; --j) | |
4828 | c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); | |
4829 | crc32_table[i] = c; | |
4830 | } | |
c906108c SS |
4831 | } |
4832 | ||
4833 | while (len--) | |
4834 | { | |
4835 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255]; | |
4836 | buf++; | |
4837 | } | |
4838 | return crc; | |
4839 | } | |
4840 | ||
4841 | /* compare-sections command | |
4842 | ||
4843 | With no arguments, compares each loadable section in the exec bfd | |
4844 | with the same memory range on the target, and reports mismatches. | |
4845 | Useful for verifying the image on the target against the exec file. | |
4846 | Depends on the target understanding the new "qCRC:" request. */ | |
4847 | ||
e514a9d6 JM |
4848 | /* FIXME: cagney/1999-10-26: This command should be broken down into a |
4849 | target method (target verify memory) and generic version of the | |
4850 | actual command. This will allow other high-level code (especially | |
23860348 | 4851 | generic_load()) to make use of this target functionality. */ |
e514a9d6 | 4852 | |
c906108c | 4853 | static void |
fba45db2 | 4854 | compare_sections_command (char *args, int from_tty) |
c906108c | 4855 | { |
d01949b6 | 4856 | struct remote_state *rs = get_remote_state (); |
c906108c SS |
4857 | asection *s; |
4858 | unsigned long host_crc, target_crc; | |
4859 | extern bfd *exec_bfd; | |
4860 | struct cleanup *old_chain; | |
085dd6e6 JM |
4861 | char *tmp; |
4862 | char *sectdata; | |
ce359b09 | 4863 | const char *sectname; |
d01949b6 | 4864 | char *buf = alloca (rs->remote_packet_size); |
c906108c SS |
4865 | bfd_size_type size; |
4866 | bfd_vma lma; | |
4867 | int matched = 0; | |
4868 | int mismatched = 0; | |
4869 | ||
4870 | if (!exec_bfd) | |
8a3fe4f8 | 4871 | error (_("command cannot be used without an exec file")); |
c906108c SS |
4872 | if (!current_target.to_shortname || |
4873 | strcmp (current_target.to_shortname, "remote") != 0) | |
8a3fe4f8 | 4874 | error (_("command can only be used with remote target")); |
c906108c | 4875 | |
c5aa993b | 4876 | for (s = exec_bfd->sections; s; s = s->next) |
c906108c SS |
4877 | { |
4878 | if (!(s->flags & SEC_LOAD)) | |
c5aa993b | 4879 | continue; /* skip non-loadable section */ |
c906108c | 4880 | |
2c500098 | 4881 | size = bfd_get_section_size (s); |
c906108c | 4882 | if (size == 0) |
c5aa993b | 4883 | continue; /* skip zero-length section */ |
c906108c | 4884 | |
ce359b09 | 4885 | sectname = bfd_get_section_name (exec_bfd, s); |
c906108c | 4886 | if (args && strcmp (args, sectname) != 0) |
c5aa993b | 4887 | continue; /* not the section selected by user */ |
c906108c | 4888 | |
c5aa993b | 4889 | matched = 1; /* do this section */ |
c906108c | 4890 | lma = s->lma; |
23860348 | 4891 | /* FIXME: assumes lma can fit into long. */ |
ecbc58df WZ |
4892 | xsnprintf (buf, rs->remote_packet_size, "qCRC:%lx,%lx", |
4893 | (long) lma, (long) size); | |
c906108c SS |
4894 | putpkt (buf); |
4895 | ||
23860348 MS |
4896 | /* Be clever; compute the host_crc before waiting for target |
4897 | reply. */ | |
c906108c | 4898 | sectdata = xmalloc (size); |
b8c9b27d | 4899 | old_chain = make_cleanup (xfree, sectdata); |
c906108c SS |
4900 | bfd_get_section_contents (exec_bfd, s, sectdata, 0, size); |
4901 | host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff); | |
4902 | ||
24b06219 | 4903 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c | 4904 | if (buf[0] == 'E') |
8a3fe4f8 | 4905 | error (_("target memory fault, section %s, range 0x%s -- 0x%s"), |
823ca731 | 4906 | sectname, paddr (lma), paddr (lma + size)); |
c906108c | 4907 | if (buf[0] != 'C') |
8a3fe4f8 | 4908 | error (_("remote target does not support this operation")); |
c906108c SS |
4909 | |
4910 | for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++) | |
4911 | target_crc = target_crc * 16 + fromhex (*tmp); | |
4912 | ||
d4f3574e SS |
4913 | printf_filtered ("Section %s, range 0x%s -- 0x%s: ", |
4914 | sectname, paddr (lma), paddr (lma + size)); | |
c906108c SS |
4915 | if (host_crc == target_crc) |
4916 | printf_filtered ("matched.\n"); | |
4917 | else | |
c5aa993b JM |
4918 | { |
4919 | printf_filtered ("MIS-MATCHED!\n"); | |
4920 | mismatched++; | |
4921 | } | |
c906108c SS |
4922 | |
4923 | do_cleanups (old_chain); | |
4924 | } | |
4925 | if (mismatched > 0) | |
8a3fe4f8 AC |
4926 | warning (_("One or more sections of the remote executable does not match\n\ |
4927 | the loaded file\n")); | |
c906108c | 4928 | if (args && !matched) |
a3f17187 | 4929 | printf_filtered (_("No loaded section named '%s'.\n"), args); |
c906108c SS |
4930 | } |
4931 | ||
1e3ff5ad | 4932 | static LONGEST |
4b8a223f | 4933 | remote_xfer_partial (struct target_ops *ops, enum target_object object, |
961cb7b5 MK |
4934 | const char *annex, gdb_byte *readbuf, |
4935 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) | |
c906108c | 4936 | { |
d01949b6 | 4937 | struct remote_state *rs = get_remote_state (); |
c906108c | 4938 | int i; |
d01949b6 | 4939 | char *buf2 = alloca (rs->remote_packet_size); |
c906108c | 4940 | char *p2 = &buf2[0]; |
1e3ff5ad | 4941 | char query_type; |
c906108c | 4942 | |
21e3b9b9 DJ |
4943 | /* Handle memory using remote_xfer_memory. */ |
4944 | if (object == TARGET_OBJECT_MEMORY) | |
4945 | { | |
4946 | int xfered; | |
4947 | errno = 0; | |
4948 | ||
4949 | if (writebuf != NULL) | |
4950 | { | |
4951 | void *buffer = xmalloc (len); | |
4952 | struct cleanup *cleanup = make_cleanup (xfree, buffer); | |
4953 | memcpy (buffer, writebuf, len); | |
4954 | xfered = remote_xfer_memory (offset, buffer, len, 1, NULL, ops); | |
4955 | do_cleanups (cleanup); | |
4956 | } | |
4957 | else | |
4958 | xfered = remote_xfer_memory (offset, readbuf, len, 0, NULL, ops); | |
4959 | ||
4960 | if (xfered > 0) | |
4961 | return xfered; | |
4962 | else if (xfered == 0 && errno == 0) | |
4963 | return 0; | |
4964 | else | |
4965 | return -1; | |
4966 | } | |
4967 | ||
4b8a223f AC |
4968 | /* Only handle reads. */ |
4969 | if (writebuf != NULL || readbuf == NULL) | |
4970 | return -1; | |
4971 | ||
1e3ff5ad AC |
4972 | /* Map pre-existing objects onto letters. DO NOT do this for new |
4973 | objects!!! Instead specify new query packets. */ | |
4974 | switch (object) | |
c906108c | 4975 | { |
1e3ff5ad AC |
4976 | case TARGET_OBJECT_KOD: |
4977 | query_type = 'K'; | |
4978 | break; | |
4979 | case TARGET_OBJECT_AVR: | |
4980 | query_type = 'R'; | |
4981 | break; | |
802188a7 RM |
4982 | |
4983 | case TARGET_OBJECT_AUXV: | |
4984 | if (remote_protocol_qPart_auxv.support != PACKET_DISABLE) | |
4985 | { | |
4986 | unsigned int total = 0; | |
4987 | while (len > 0) | |
4988 | { | |
4989 | LONGEST n = min ((rs->remote_packet_size - 2) / 2, len); | |
4990 | snprintf (buf2, rs->remote_packet_size, | |
4991 | "qPart:auxv:read::%s,%s", | |
4992 | phex_nz (offset, sizeof offset), | |
4993 | phex_nz (n, sizeof n)); | |
4994 | i = putpkt (buf2); | |
4995 | if (i < 0) | |
4996 | return total > 0 ? total : i; | |
4997 | buf2[0] = '\0'; | |
4998 | getpkt (buf2, rs->remote_packet_size, 0); | |
4999 | if (packet_ok (buf2, &remote_protocol_qPart_auxv) != PACKET_OK) | |
5000 | return total > 0 ? total : -1; | |
5001 | if (buf2[0] == 'O' && buf2[1] == 'K' && buf2[2] == '\0') | |
5002 | break; /* Got EOF indicator. */ | |
5003 | /* Got some data. */ | |
5004 | i = hex2bin (buf2, readbuf, len); | |
5005 | if (i > 0) | |
5006 | { | |
5007 | readbuf = (void *) ((char *) readbuf + i); | |
5008 | offset += i; | |
5009 | len -= i; | |
5010 | total += i; | |
5011 | } | |
5012 | } | |
5013 | return total; | |
5014 | } | |
5015 | return -1; | |
5016 | ||
1e3ff5ad | 5017 | default: |
c906108c SS |
5018 | return -1; |
5019 | } | |
5020 | ||
4b8a223f | 5021 | /* Note: a zero OFFSET and LEN can be used to query the minimum |
1e3ff5ad | 5022 | buffer size. */ |
4b8a223f | 5023 | if (offset == 0 && len == 0) |
1e3ff5ad | 5024 | return (rs->remote_packet_size); |
24b06219 MK |
5025 | /* Minimum outbuf size is RS->remote_packet_size. If LEN is not |
5026 | large enough let the caller deal with it. */ | |
5027 | if (len < rs->remote_packet_size) | |
1e3ff5ad AC |
5028 | return -1; |
5029 | len = rs->remote_packet_size; | |
5030 | ||
23860348 | 5031 | /* Except for querying the minimum buffer size, target must be open. */ |
c5aa993b | 5032 | if (!remote_desc) |
8a3fe4f8 | 5033 | error (_("remote query is only available after target open")); |
c906108c | 5034 | |
1e3ff5ad | 5035 | gdb_assert (annex != NULL); |
4b8a223f | 5036 | gdb_assert (readbuf != NULL); |
c906108c SS |
5037 | |
5038 | *p2++ = 'q'; | |
5039 | *p2++ = query_type; | |
5040 | ||
23860348 MS |
5041 | /* We used one buffer char for the remote protocol q command and |
5042 | another for the query type. As the remote protocol encapsulation | |
5043 | uses 4 chars plus one extra in case we are debugging | |
5044 | (remote_debug), we have PBUFZIZ - 7 left to pack the query | |
5045 | string. */ | |
c906108c | 5046 | i = 0; |
24b06219 | 5047 | while (annex[i] && (i < (rs->remote_packet_size - 8))) |
c906108c | 5048 | { |
1e3ff5ad AC |
5049 | /* Bad caller may have sent forbidden characters. */ |
5050 | gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#'); | |
5051 | *p2++ = annex[i]; | |
c906108c SS |
5052 | i++; |
5053 | } | |
1e3ff5ad AC |
5054 | *p2 = '\0'; |
5055 | gdb_assert (annex[i] == '\0'); | |
c906108c SS |
5056 | |
5057 | i = putpkt (buf2); | |
c5aa993b JM |
5058 | if (i < 0) |
5059 | return i; | |
c906108c | 5060 | |
cfd77fa1 | 5061 | getpkt ((char *) readbuf, len, 0); |
c906108c | 5062 | |
cfd77fa1 | 5063 | return strlen ((char *) readbuf); |
c906108c SS |
5064 | } |
5065 | ||
96baa820 JM |
5066 | static void |
5067 | remote_rcmd (char *command, | |
d9fcf2fb | 5068 | struct ui_file *outbuf) |
96baa820 | 5069 | { |
d01949b6 | 5070 | struct remote_state *rs = get_remote_state (); |
d01949b6 | 5071 | char *buf = alloca (rs->remote_packet_size); |
96baa820 JM |
5072 | char *p = buf; |
5073 | ||
5074 | if (!remote_desc) | |
8a3fe4f8 | 5075 | error (_("remote rcmd is only available after target open")); |
96baa820 | 5076 | |
23860348 | 5077 | /* Send a NULL command across as an empty command. */ |
7be570e7 JM |
5078 | if (command == NULL) |
5079 | command = ""; | |
5080 | ||
23860348 | 5081 | /* The query prefix. */ |
96baa820 JM |
5082 | strcpy (buf, "qRcmd,"); |
5083 | p = strchr (buf, '\0'); | |
5084 | ||
24b06219 | 5085 | if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > rs->remote_packet_size) |
8a3fe4f8 | 5086 | error (_("\"monitor\" command ``%s'' is too long."), command); |
96baa820 | 5087 | |
23860348 | 5088 | /* Encode the actual command. */ |
cfd77fa1 | 5089 | bin2hex ((gdb_byte *) command, p, 0); |
96baa820 JM |
5090 | |
5091 | if (putpkt (buf) < 0) | |
8a3fe4f8 | 5092 | error (_("Communication problem with target.")); |
96baa820 JM |
5093 | |
5094 | /* get/display the response */ | |
5095 | while (1) | |
5096 | { | |
23860348 | 5097 | /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */ |
96baa820 | 5098 | buf[0] = '\0'; |
24b06219 | 5099 | getpkt (buf, rs->remote_packet_size, 0); |
96baa820 | 5100 | if (buf[0] == '\0') |
8a3fe4f8 | 5101 | error (_("Target does not support this command.")); |
96baa820 JM |
5102 | if (buf[0] == 'O' && buf[1] != 'K') |
5103 | { | |
23860348 | 5104 | remote_console_output (buf + 1); /* 'O' message from stub. */ |
96baa820 JM |
5105 | continue; |
5106 | } | |
5107 | if (strcmp (buf, "OK") == 0) | |
5108 | break; | |
7be570e7 JM |
5109 | if (strlen (buf) == 3 && buf[0] == 'E' |
5110 | && isdigit (buf[1]) && isdigit (buf[2])) | |
5111 | { | |
8a3fe4f8 | 5112 | error (_("Protocol error with Rcmd")); |
7be570e7 | 5113 | } |
96baa820 JM |
5114 | for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2) |
5115 | { | |
5116 | char c = (fromhex (p[0]) << 4) + fromhex (p[1]); | |
5117 | fputc_unfiltered (c, outbuf); | |
5118 | } | |
5119 | break; | |
5120 | } | |
5121 | } | |
5122 | ||
c906108c | 5123 | static void |
fba45db2 | 5124 | packet_command (char *args, int from_tty) |
c906108c | 5125 | { |
d01949b6 AC |
5126 | struct remote_state *rs = get_remote_state (); |
5127 | char *buf = alloca (rs->remote_packet_size); | |
c906108c | 5128 | |
c5aa993b | 5129 | if (!remote_desc) |
8a3fe4f8 | 5130 | error (_("command can only be used with remote target")); |
c906108c | 5131 | |
c5aa993b | 5132 | if (!args) |
8a3fe4f8 | 5133 | error (_("remote-packet command requires packet text as argument")); |
c906108c SS |
5134 | |
5135 | puts_filtered ("sending: "); | |
5136 | print_packet (args); | |
5137 | puts_filtered ("\n"); | |
5138 | putpkt (args); | |
5139 | ||
24b06219 | 5140 | getpkt (buf, rs->remote_packet_size, 0); |
c906108c SS |
5141 | puts_filtered ("received: "); |
5142 | print_packet (buf); | |
5143 | puts_filtered ("\n"); | |
5144 | } | |
5145 | ||
5146 | #if 0 | |
23860348 | 5147 | /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */ |
c906108c | 5148 | |
a14ed312 | 5149 | static void display_thread_info (struct gdb_ext_thread_info *info); |
c906108c | 5150 | |
a14ed312 | 5151 | static void threadset_test_cmd (char *cmd, int tty); |
c906108c | 5152 | |
a14ed312 | 5153 | static void threadalive_test (char *cmd, int tty); |
c906108c | 5154 | |
a14ed312 | 5155 | static void threadlist_test_cmd (char *cmd, int tty); |
c906108c | 5156 | |
23860348 | 5157 | int get_and_display_threadinfo (threadref *ref); |
c906108c | 5158 | |
a14ed312 | 5159 | static void threadinfo_test_cmd (char *cmd, int tty); |
c906108c | 5160 | |
23860348 | 5161 | static int thread_display_step (threadref *ref, void *context); |
c906108c | 5162 | |
a14ed312 | 5163 | static void threadlist_update_test_cmd (char *cmd, int tty); |
c906108c | 5164 | |
a14ed312 | 5165 | static void init_remote_threadtests (void); |
c906108c | 5166 | |
23860348 | 5167 | #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */ |
c906108c SS |
5168 | |
5169 | static void | |
fba45db2 | 5170 | threadset_test_cmd (char *cmd, int tty) |
c906108c SS |
5171 | { |
5172 | int sample_thread = SAMPLE_THREAD; | |
5173 | ||
a3f17187 | 5174 | printf_filtered (_("Remote threadset test\n")); |
c906108c SS |
5175 | set_thread (sample_thread, 1); |
5176 | } | |
5177 | ||
5178 | ||
5179 | static void | |
fba45db2 | 5180 | threadalive_test (char *cmd, int tty) |
c906108c SS |
5181 | { |
5182 | int sample_thread = SAMPLE_THREAD; | |
5183 | ||
39f77062 | 5184 | if (remote_thread_alive (pid_to_ptid (sample_thread))) |
c906108c SS |
5185 | printf_filtered ("PASS: Thread alive test\n"); |
5186 | else | |
5187 | printf_filtered ("FAIL: Thread alive test\n"); | |
5188 | } | |
5189 | ||
23860348 | 5190 | void output_threadid (char *title, threadref *ref); |
c906108c SS |
5191 | |
5192 | void | |
fba45db2 | 5193 | output_threadid (char *title, threadref *ref) |
c906108c SS |
5194 | { |
5195 | char hexid[20]; | |
5196 | ||
23860348 | 5197 | pack_threadid (&hexid[0], ref); /* Convert threead id into hex. */ |
c906108c SS |
5198 | hexid[16] = 0; |
5199 | printf_filtered ("%s %s\n", title, (&hexid[0])); | |
5200 | } | |
5201 | ||
5202 | static void | |
fba45db2 | 5203 | threadlist_test_cmd (char *cmd, int tty) |
c906108c SS |
5204 | { |
5205 | int startflag = 1; | |
5206 | threadref nextthread; | |
5207 | int done, result_count; | |
5208 | threadref threadlist[3]; | |
5209 | ||
5210 | printf_filtered ("Remote Threadlist test\n"); | |
5211 | if (!remote_get_threadlist (startflag, &nextthread, 3, &done, | |
5212 | &result_count, &threadlist[0])) | |
5213 | printf_filtered ("FAIL: threadlist test\n"); | |
5214 | else | |
5215 | { | |
5216 | threadref *scan = threadlist; | |
5217 | threadref *limit = scan + result_count; | |
5218 | ||
5219 | while (scan < limit) | |
5220 | output_threadid (" thread ", scan++); | |
5221 | } | |
5222 | } | |
5223 | ||
5224 | void | |
fba45db2 | 5225 | display_thread_info (struct gdb_ext_thread_info *info) |
c906108c SS |
5226 | { |
5227 | output_threadid ("Threadid: ", &info->threadid); | |
5228 | printf_filtered ("Name: %s\n ", info->shortname); | |
5229 | printf_filtered ("State: %s\n", info->display); | |
5230 | printf_filtered ("other: %s\n\n", info->more_display); | |
5231 | } | |
5232 | ||
5233 | int | |
fba45db2 | 5234 | get_and_display_threadinfo (threadref *ref) |
c906108c SS |
5235 | { |
5236 | int result; | |
5237 | int set; | |
5238 | struct gdb_ext_thread_info threadinfo; | |
5239 | ||
5240 | set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME | |
5241 | | TAG_MOREDISPLAY | TAG_DISPLAY; | |
5242 | if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo))) | |
5243 | display_thread_info (&threadinfo); | |
5244 | return result; | |
5245 | } | |
5246 | ||
5247 | static void | |
fba45db2 | 5248 | threadinfo_test_cmd (char *cmd, int tty) |
c906108c SS |
5249 | { |
5250 | int athread = SAMPLE_THREAD; | |
5251 | threadref thread; | |
5252 | int set; | |
5253 | ||
5254 | int_to_threadref (&thread, athread); | |
5255 | printf_filtered ("Remote Threadinfo test\n"); | |
5256 | if (!get_and_display_threadinfo (&thread)) | |
5257 | printf_filtered ("FAIL cannot get thread info\n"); | |
5258 | } | |
5259 | ||
5260 | static int | |
fba45db2 | 5261 | thread_display_step (threadref *ref, void *context) |
c906108c SS |
5262 | { |
5263 | /* output_threadid(" threadstep ",ref); *//* simple test */ | |
5264 | return get_and_display_threadinfo (ref); | |
5265 | } | |
5266 | ||
5267 | static void | |
fba45db2 | 5268 | threadlist_update_test_cmd (char *cmd, int tty) |
c906108c SS |
5269 | { |
5270 | printf_filtered ("Remote Threadlist update test\n"); | |
5271 | remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS); | |
5272 | } | |
5273 | ||
5274 | static void | |
5275 | init_remote_threadtests (void) | |
5276 | { | |
1bedd215 AC |
5277 | add_com ("tlist", class_obscure, threadlist_test_cmd, _("\ |
5278 | Fetch and print the remote list of thread identifiers, one pkt only")); | |
c906108c | 5279 | add_com ("tinfo", class_obscure, threadinfo_test_cmd, |
1bedd215 | 5280 | _("Fetch and display info about one thread")); |
c906108c | 5281 | add_com ("tset", class_obscure, threadset_test_cmd, |
1bedd215 | 5282 | _("Test setting to a different thread")); |
c906108c | 5283 | add_com ("tupd", class_obscure, threadlist_update_test_cmd, |
1bedd215 | 5284 | _("Iterate through updating all remote thread info")); |
c906108c | 5285 | add_com ("talive", class_obscure, threadalive_test, |
1bedd215 | 5286 | _(" Remote thread alive test ")); |
c906108c SS |
5287 | } |
5288 | ||
5289 | #endif /* 0 */ | |
5290 | ||
f3fb8c85 MS |
5291 | /* Convert a thread ID to a string. Returns the string in a static |
5292 | buffer. */ | |
5293 | ||
5294 | static char * | |
39f77062 | 5295 | remote_pid_to_str (ptid_t ptid) |
f3fb8c85 | 5296 | { |
fd0a2a6f | 5297 | static char buf[32]; |
f3fb8c85 | 5298 | |
6c76e4a1 | 5299 | xsnprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid)); |
f3fb8c85 MS |
5300 | return buf; |
5301 | } | |
5302 | ||
38691318 KB |
5303 | /* Get the address of the thread local variable in OBJFILE which is |
5304 | stored at OFFSET within the thread local storage for thread PTID. */ | |
5305 | ||
5306 | static CORE_ADDR | |
5307 | remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset) | |
5308 | { | |
5309 | if (remote_protocol_qGetTLSAddr.support != PACKET_DISABLE) | |
5310 | { | |
5311 | struct remote_state *rs = get_remote_state (); | |
5312 | char *buf = alloca (rs->remote_packet_size); | |
5313 | char *p = buf; | |
571dd617 | 5314 | enum packet_result result; |
38691318 KB |
5315 | |
5316 | strcpy (p, "qGetTLSAddr:"); | |
5317 | p += strlen (p); | |
5318 | p += hexnumstr (p, PIDGET (ptid)); | |
5319 | *p++ = ','; | |
5320 | p += hexnumstr (p, offset); | |
5321 | *p++ = ','; | |
5322 | p += hexnumstr (p, lm); | |
5323 | *p++ = '\0'; | |
5324 | ||
5325 | putpkt (buf); | |
5326 | getpkt (buf, rs->remote_packet_size, 0); | |
571dd617 KB |
5327 | result = packet_ok (buf, &remote_protocol_qGetTLSAddr); |
5328 | if (result == PACKET_OK) | |
38691318 KB |
5329 | { |
5330 | ULONGEST result; | |
5331 | ||
5332 | unpack_varlen_hex (buf, &result); | |
5333 | return result; | |
5334 | } | |
571dd617 | 5335 | else if (result == PACKET_UNKNOWN) |
109c3e39 AC |
5336 | throw_error (TLS_GENERIC_ERROR, |
5337 | _("Remote target doesn't support qGetTLSAddr packet")); | |
38691318 | 5338 | else |
109c3e39 AC |
5339 | throw_error (TLS_GENERIC_ERROR, |
5340 | _("Remote target failed to process qGetTLSAddr request")); | |
38691318 KB |
5341 | } |
5342 | else | |
109c3e39 AC |
5343 | throw_error (TLS_GENERIC_ERROR, |
5344 | _("TLS not supported or disabled on this target")); | |
38691318 KB |
5345 | /* Not reached. */ |
5346 | return 0; | |
5347 | } | |
5348 | ||
c906108c | 5349 | static void |
fba45db2 | 5350 | init_remote_ops (void) |
c906108c | 5351 | { |
c5aa993b | 5352 | remote_ops.to_shortname = "remote"; |
c906108c | 5353 | remote_ops.to_longname = "Remote serial target in gdb-specific protocol"; |
c5aa993b | 5354 | remote_ops.to_doc = |
c906108c | 5355 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
0d06e24b JM |
5356 | Specify the serial device it is connected to\n\ |
5357 | (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."; | |
c5aa993b JM |
5358 | remote_ops.to_open = remote_open; |
5359 | remote_ops.to_close = remote_close; | |
c906108c | 5360 | remote_ops.to_detach = remote_detach; |
6ad8ae5c | 5361 | remote_ops.to_disconnect = remote_disconnect; |
c5aa993b | 5362 | remote_ops.to_resume = remote_resume; |
c906108c SS |
5363 | remote_ops.to_wait = remote_wait; |
5364 | remote_ops.to_fetch_registers = remote_fetch_registers; | |
5365 | remote_ops.to_store_registers = remote_store_registers; | |
5366 | remote_ops.to_prepare_to_store = remote_prepare_to_store; | |
c8e73a31 | 5367 | remote_ops.deprecated_xfer_memory = remote_xfer_memory; |
c5aa993b | 5368 | remote_ops.to_files_info = remote_files_info; |
c906108c SS |
5369 | remote_ops.to_insert_breakpoint = remote_insert_breakpoint; |
5370 | remote_ops.to_remove_breakpoint = remote_remove_breakpoint; | |
3c3bea1c GS |
5371 | remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint; |
5372 | remote_ops.to_stopped_data_address = remote_stopped_data_address; | |
5373 | remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources; | |
5374 | remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint; | |
5375 | remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint; | |
5376 | remote_ops.to_insert_watchpoint = remote_insert_watchpoint; | |
5377 | remote_ops.to_remove_watchpoint = remote_remove_watchpoint; | |
c5aa993b JM |
5378 | remote_ops.to_kill = remote_kill; |
5379 | remote_ops.to_load = generic_load; | |
c906108c SS |
5380 | remote_ops.to_mourn_inferior = remote_mourn; |
5381 | remote_ops.to_thread_alive = remote_thread_alive; | |
0f71a2f6 | 5382 | remote_ops.to_find_new_threads = remote_threads_info; |
0caabb7e | 5383 | remote_ops.to_pid_to_str = remote_pid_to_str; |
cf759d3b | 5384 | remote_ops.to_extra_thread_info = remote_threads_extra_info; |
c906108c | 5385 | remote_ops.to_stop = remote_stop; |
4b8a223f | 5386 | remote_ops.to_xfer_partial = remote_xfer_partial; |
96baa820 | 5387 | remote_ops.to_rcmd = remote_rcmd; |
38691318 | 5388 | remote_ops.to_get_thread_local_address = remote_get_thread_local_address; |
c906108c | 5389 | remote_ops.to_stratum = process_stratum; |
c5aa993b JM |
5390 | remote_ops.to_has_all_memory = 1; |
5391 | remote_ops.to_has_memory = 1; | |
5392 | remote_ops.to_has_stack = 1; | |
5393 | remote_ops.to_has_registers = 1; | |
5394 | remote_ops.to_has_execution = 1; | |
5395 | remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */ | |
5396 | remote_ops.to_magic = OPS_MAGIC; | |
c906108c SS |
5397 | } |
5398 | ||
5399 | /* Set up the extended remote vector by making a copy of the standard | |
5400 | remote vector and adding to it. */ | |
5401 | ||
5402 | static void | |
fba45db2 | 5403 | init_extended_remote_ops (void) |
c906108c SS |
5404 | { |
5405 | extended_remote_ops = remote_ops; | |
5406 | ||
0f71a2f6 | 5407 | extended_remote_ops.to_shortname = "extended-remote"; |
c5aa993b | 5408 | extended_remote_ops.to_longname = |
c906108c | 5409 | "Extended remote serial target in gdb-specific protocol"; |
c5aa993b | 5410 | extended_remote_ops.to_doc = |
c906108c SS |
5411 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
5412 | Specify the serial device it is connected to (e.g. /dev/ttya).", | |
c5aa993b | 5413 | extended_remote_ops.to_open = extended_remote_open; |
c906108c SS |
5414 | extended_remote_ops.to_create_inferior = extended_remote_create_inferior; |
5415 | extended_remote_ops.to_mourn_inferior = extended_remote_mourn; | |
0f71a2f6 JM |
5416 | } |
5417 | ||
6426a772 JM |
5418 | static int |
5419 | remote_can_async_p (void) | |
5420 | { | |
23860348 | 5421 | /* We're async whenever the serial device is. */ |
2cd58942 | 5422 | return (current_target.to_async_mask_value) && serial_can_async_p (remote_desc); |
6426a772 JM |
5423 | } |
5424 | ||
5425 | static int | |
5426 | remote_is_async_p (void) | |
5427 | { | |
23860348 | 5428 | /* We're async whenever the serial device is. */ |
2cd58942 | 5429 | return (current_target.to_async_mask_value) && serial_is_async_p (remote_desc); |
6426a772 JM |
5430 | } |
5431 | ||
2acceee2 JM |
5432 | /* Pass the SERIAL event on and up to the client. One day this code |
5433 | will be able to delay notifying the client of an event until the | |
23860348 | 5434 | point where an entire packet has been received. */ |
2acceee2 | 5435 | |
23860348 MS |
5436 | static void (*async_client_callback) (enum inferior_event_type event_type, |
5437 | void *context); | |
2acceee2 JM |
5438 | static void *async_client_context; |
5439 | static serial_event_ftype remote_async_serial_handler; | |
5440 | ||
6426a772 | 5441 | static void |
819cc324 | 5442 | remote_async_serial_handler (struct serial *scb, void *context) |
6426a772 | 5443 | { |
2acceee2 JM |
5444 | /* Don't propogate error information up to the client. Instead let |
5445 | the client find out about the error by querying the target. */ | |
5446 | async_client_callback (INF_REG_EVENT, async_client_context); | |
5447 | } | |
5448 | ||
5449 | static void | |
23860348 MS |
5450 | remote_async (void (*callback) (enum inferior_event_type event_type, |
5451 | void *context), void *context) | |
2acceee2 | 5452 | { |
ed9a39eb | 5453 | if (current_target.to_async_mask_value == 0) |
8e65ff28 | 5454 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 5455 | _("Calling remote_async when async is masked")); |
ed9a39eb | 5456 | |
2acceee2 JM |
5457 | if (callback != NULL) |
5458 | { | |
2cd58942 | 5459 | serial_async (remote_desc, remote_async_serial_handler, NULL); |
2acceee2 JM |
5460 | async_client_callback = callback; |
5461 | async_client_context = context; | |
5462 | } | |
5463 | else | |
2cd58942 | 5464 | serial_async (remote_desc, NULL, NULL); |
6426a772 JM |
5465 | } |
5466 | ||
43ff13b4 JM |
5467 | /* Target async and target extended-async. |
5468 | ||
5469 | This are temporary targets, until it is all tested. Eventually | |
5470 | async support will be incorporated int the usual 'remote' | |
23860348 | 5471 | target. */ |
43ff13b4 JM |
5472 | |
5473 | static void | |
c2d11a7d | 5474 | init_remote_async_ops (void) |
43ff13b4 JM |
5475 | { |
5476 | remote_async_ops.to_shortname = "async"; | |
23860348 MS |
5477 | remote_async_ops.to_longname = |
5478 | "Remote serial target in async version of the gdb-specific protocol"; | |
c5aa993b | 5479 | remote_async_ops.to_doc = |
43ff13b4 JM |
5480 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
5481 | Specify the serial device it is connected to (e.g. /dev/ttya)."; | |
c5aa993b JM |
5482 | remote_async_ops.to_open = remote_async_open; |
5483 | remote_async_ops.to_close = remote_close; | |
6ad8ae5c DJ |
5484 | remote_async_ops.to_detach = remote_detach; |
5485 | remote_async_ops.to_disconnect = remote_disconnect; | |
c5aa993b JM |
5486 | remote_async_ops.to_resume = remote_async_resume; |
5487 | remote_async_ops.to_wait = remote_async_wait; | |
5488 | remote_async_ops.to_fetch_registers = remote_fetch_registers; | |
5489 | remote_async_ops.to_store_registers = remote_store_registers; | |
5490 | remote_async_ops.to_prepare_to_store = remote_prepare_to_store; | |
c8e73a31 | 5491 | remote_async_ops.deprecated_xfer_memory = remote_xfer_memory; |
c5aa993b | 5492 | remote_async_ops.to_files_info = remote_files_info; |
43ff13b4 JM |
5493 | remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint; |
5494 | remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint; | |
3c3bea1c GS |
5495 | remote_async_ops.to_can_use_hw_breakpoint = remote_check_watch_resources; |
5496 | remote_async_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint; | |
5497 | remote_async_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint; | |
5498 | remote_async_ops.to_insert_watchpoint = remote_insert_watchpoint; | |
5499 | remote_async_ops.to_remove_watchpoint = remote_remove_watchpoint; | |
5500 | remote_async_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint; | |
5501 | remote_async_ops.to_stopped_data_address = remote_stopped_data_address; | |
6426a772 JM |
5502 | remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior; |
5503 | remote_async_ops.to_terminal_ours = remote_async_terminal_ours; | |
c5aa993b JM |
5504 | remote_async_ops.to_kill = remote_async_kill; |
5505 | remote_async_ops.to_load = generic_load; | |
53a5351d | 5506 | remote_async_ops.to_mourn_inferior = remote_async_mourn; |
c5aa993b JM |
5507 | remote_async_ops.to_thread_alive = remote_thread_alive; |
5508 | remote_async_ops.to_find_new_threads = remote_threads_info; | |
cf759d3b ND |
5509 | remote_async_ops.to_pid_to_str = remote_pid_to_str; |
5510 | remote_async_ops.to_extra_thread_info = remote_threads_extra_info; | |
43ff13b4 | 5511 | remote_async_ops.to_stop = remote_stop; |
4b8a223f | 5512 | remote_async_ops.to_xfer_partial = remote_xfer_partial; |
96baa820 | 5513 | remote_async_ops.to_rcmd = remote_rcmd; |
c5aa993b JM |
5514 | remote_async_ops.to_stratum = process_stratum; |
5515 | remote_async_ops.to_has_all_memory = 1; | |
5516 | remote_async_ops.to_has_memory = 1; | |
5517 | remote_async_ops.to_has_stack = 1; | |
5518 | remote_async_ops.to_has_registers = 1; | |
5519 | remote_async_ops.to_has_execution = 1; | |
5520 | remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */ | |
6426a772 JM |
5521 | remote_async_ops.to_can_async_p = remote_can_async_p; |
5522 | remote_async_ops.to_is_async_p = remote_is_async_p; | |
5523 | remote_async_ops.to_async = remote_async; | |
ed9a39eb | 5524 | remote_async_ops.to_async_mask_value = 1; |
c5aa993b | 5525 | remote_async_ops.to_magic = OPS_MAGIC; |
43ff13b4 JM |
5526 | } |
5527 | ||
5528 | /* Set up the async extended remote vector by making a copy of the standard | |
5529 | remote vector and adding to it. */ | |
5530 | ||
5531 | static void | |
c2d11a7d | 5532 | init_extended_async_remote_ops (void) |
43ff13b4 JM |
5533 | { |
5534 | extended_async_remote_ops = remote_async_ops; | |
5535 | ||
5536 | extended_async_remote_ops.to_shortname = "extended-async"; | |
c5aa993b | 5537 | extended_async_remote_ops.to_longname = |
43ff13b4 | 5538 | "Extended remote serial target in async gdb-specific protocol"; |
c5aa993b | 5539 | extended_async_remote_ops.to_doc = |
43ff13b4 JM |
5540 | "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\ |
5541 | Specify the serial device it is connected to (e.g. /dev/ttya).", | |
c5aa993b | 5542 | extended_async_remote_ops.to_open = extended_remote_async_open; |
43ff13b4 JM |
5543 | extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior; |
5544 | extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn; | |
5545 | } | |
5546 | ||
5a2468f5 | 5547 | static void |
c2d11a7d | 5548 | set_remote_cmd (char *args, int from_tty) |
5a2468f5 | 5549 | { |
5a2468f5 JM |
5550 | } |
5551 | ||
d471ea57 AC |
5552 | static void |
5553 | show_remote_cmd (char *args, int from_tty) | |
5554 | { | |
e9e68a56 AC |
5555 | /* FIXME: cagney/2002-06-15: This function should iterate over |
5556 | remote_show_cmdlist for a list of sub commands to show. */ | |
08546159 AC |
5557 | show_remote_protocol_Z_packet_cmd (gdb_stdout, from_tty, NULL, NULL); |
5558 | show_remote_protocol_P_packet_cmd (gdb_stdout, from_tty, NULL, NULL); | |
5559 | show_remote_protocol_p_packet_cmd (gdb_stdout, from_tty, NULL, NULL); | |
5560 | show_remote_protocol_qSymbol_packet_cmd (gdb_stdout, from_tty, NULL, NULL); | |
5561 | show_remote_protocol_vcont_packet_cmd (gdb_stdout, from_tty, NULL, NULL); | |
5562 | show_remote_protocol_binary_download_cmd (gdb_stdout, from_tty, NULL, NULL); | |
5563 | show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout, from_tty, NULL, NULL); | |
38691318 | 5564 | show_remote_protocol_qGetTLSAddr_packet_cmd (gdb_stdout, from_tty, NULL, NULL); |
d471ea57 | 5565 | } |
5a2468f5 | 5566 | |
0f71a2f6 | 5567 | static void |
fba45db2 | 5568 | build_remote_gdbarch_data (void) |
0f71a2f6 | 5569 | { |
d696208f | 5570 | remote_address_size = TARGET_ADDR_BIT; |
0f71a2f6 JM |
5571 | } |
5572 | ||
23860348 | 5573 | /* Saved pointer to previous owner of the new_objfile event. */ |
dc8acb97 MS |
5574 | static void (*remote_new_objfile_chain) (struct objfile *); |
5575 | ||
23860348 | 5576 | /* Function to be called whenever a new objfile (shlib) is detected. */ |
dc8acb97 MS |
5577 | static void |
5578 | remote_new_objfile (struct objfile *objfile) | |
5579 | { | |
23860348 | 5580 | if (remote_desc != 0) /* Have a remote connection. */ |
dc8acb97 MS |
5581 | { |
5582 | remote_check_symbols (objfile); | |
5583 | } | |
23860348 | 5584 | /* Call predecessor on chain, if any. */ |
dc8acb97 MS |
5585 | if (remote_new_objfile_chain != 0 && |
5586 | remote_desc == 0) | |
5587 | remote_new_objfile_chain (objfile); | |
5588 | } | |
5589 | ||
c906108c | 5590 | void |
fba45db2 | 5591 | _initialize_remote (void) |
c906108c | 5592 | { |
5a2468f5 JM |
5593 | static struct cmd_list_element *remote_set_cmdlist; |
5594 | static struct cmd_list_element *remote_show_cmdlist; | |
5595 | ||
0f71a2f6 | 5596 | /* architecture specific data */ |
23860348 MS |
5597 | remote_gdbarch_data_handle = |
5598 | gdbarch_data_register_post_init (init_remote_state); | |
d01949b6 AC |
5599 | |
5600 | /* Old tacky stuff. NOTE: This comes after the remote protocol so | |
5601 | that the remote protocol has been initialized. */ | |
046a4708 AC |
5602 | DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size); |
5603 | deprecated_register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data); | |
0f71a2f6 | 5604 | |
c906108c SS |
5605 | init_remote_ops (); |
5606 | add_target (&remote_ops); | |
5607 | ||
5608 | init_extended_remote_ops (); | |
5609 | add_target (&extended_remote_ops); | |
cce74817 | 5610 | |
43ff13b4 JM |
5611 | init_remote_async_ops (); |
5612 | add_target (&remote_async_ops); | |
5613 | ||
5614 | init_extended_async_remote_ops (); | |
5615 | add_target (&extended_async_remote_ops); | |
5616 | ||
dc8acb97 | 5617 | /* Hook into new objfile notification. */ |
9a4105ab AC |
5618 | remote_new_objfile_chain = deprecated_target_new_objfile_hook; |
5619 | deprecated_target_new_objfile_hook = remote_new_objfile; | |
dc8acb97 | 5620 | |
c906108c SS |
5621 | #if 0 |
5622 | init_remote_threadtests (); | |
5623 | #endif | |
5624 | ||
23860348 | 5625 | /* set/show remote ... */ |
d471ea57 | 5626 | |
1bedd215 | 5627 | add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, _("\ |
5a2468f5 JM |
5628 | Remote protocol specific variables\n\ |
5629 | Configure various remote-protocol specific variables such as\n\ | |
1bedd215 | 5630 | the packets being used"), |
cff3e48b | 5631 | &remote_set_cmdlist, "set remote ", |
23860348 | 5632 | 0 /* allow-unknown */, &setlist); |
1bedd215 | 5633 | add_prefix_cmd ("remote", class_maintenance, show_remote_cmd, _("\ |
5a2468f5 JM |
5634 | Remote protocol specific variables\n\ |
5635 | Configure various remote-protocol specific variables such as\n\ | |
1bedd215 | 5636 | the packets being used"), |
cff3e48b | 5637 | &remote_show_cmdlist, "show remote ", |
23860348 | 5638 | 0 /* allow-unknown */, &showlist); |
5a2468f5 | 5639 | |
1a966eab AC |
5640 | add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\ |
5641 | Compare section data on target to the exec file.\n\ | |
5642 | Argument is a single section name (default: all loaded sections)."), | |
c906108c SS |
5643 | &cmdlist); |
5644 | ||
1a966eab AC |
5645 | add_cmd ("packet", class_maintenance, packet_command, _("\ |
5646 | Send an arbitrary packet to a remote target.\n\ | |
c906108c SS |
5647 | maintenance packet TEXT\n\ |
5648 | If GDB is talking to an inferior via the GDB serial protocol, then\n\ | |
5649 | this command sends the string TEXT to the inferior, and displays the\n\ | |
5650 | response packet. GDB supplies the initial `$' character, and the\n\ | |
1a966eab | 5651 | terminating `#' character and checksum."), |
c906108c SS |
5652 | &maintenancelist); |
5653 | ||
7915a72c AC |
5654 | add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\ |
5655 | Set whether to send break if interrupted."), _("\ | |
5656 | Show whether to send break if interrupted."), _("\ | |
5657 | If set, a break, instead of a cntrl-c, is sent to the remote target."), | |
2c5b56ce | 5658 | NULL, NULL, /* FIXME: i18n: Whether to send break if interrupted is %s. */ |
e707bbc2 | 5659 | &setlist, &showlist); |
c906108c | 5660 | |
23860348 | 5661 | /* Install commands for configuring memory read/write packets. */ |
11cf8741 | 5662 | |
1a966eab AC |
5663 | add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\ |
5664 | Set the maximum number of bytes per memory write packet (deprecated)."), | |
11cf8741 | 5665 | &setlist); |
1a966eab AC |
5666 | add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\ |
5667 | Show the maximum number of bytes per memory write packet (deprecated)."), | |
11cf8741 JM |
5668 | &showlist); |
5669 | add_cmd ("memory-write-packet-size", no_class, | |
1a966eab AC |
5670 | set_memory_write_packet_size, _("\ |
5671 | Set the maximum number of bytes per memory-write packet.\n\ | |
5672 | Specify the number of bytes in a packet or 0 (zero) for the\n\ | |
5673 | default packet size. The actual limit is further reduced\n\ | |
5674 | dependent on the target. Specify ``fixed'' to disable the\n\ | |
5675 | further restriction and ``limit'' to enable that restriction."), | |
11cf8741 JM |
5676 | &remote_set_cmdlist); |
5677 | add_cmd ("memory-read-packet-size", no_class, | |
1a966eab AC |
5678 | set_memory_read_packet_size, _("\ |
5679 | Set the maximum number of bytes per memory-read packet.\n\ | |
5680 | Specify the number of bytes in a packet or 0 (zero) for the\n\ | |
5681 | default packet size. The actual limit is further reduced\n\ | |
5682 | dependent on the target. Specify ``fixed'' to disable the\n\ | |
5683 | further restriction and ``limit'' to enable that restriction."), | |
11cf8741 JM |
5684 | &remote_set_cmdlist); |
5685 | add_cmd ("memory-write-packet-size", no_class, | |
5686 | show_memory_write_packet_size, | |
1a966eab | 5687 | _("Show the maximum number of bytes per memory-write packet."), |
11cf8741 JM |
5688 | &remote_show_cmdlist); |
5689 | add_cmd ("memory-read-packet-size", no_class, | |
5690 | show_memory_read_packet_size, | |
1a966eab | 5691 | _("Show the maximum number of bytes per memory-read packet."), |
11cf8741 | 5692 | &remote_show_cmdlist); |
c906108c | 5693 | |
b3f42336 | 5694 | add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class, |
7915a72c AC |
5695 | &remote_hw_watchpoint_limit, _("\ |
5696 | Set the maximum number of target hardware watchpoints."), _("\ | |
5697 | Show the maximum number of target hardware watchpoints."), _("\ | |
5698 | Specify a negative limit for unlimited."), | |
2c5b56ce | 5699 | NULL, NULL, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */ |
b3f42336 AC |
5700 | &remote_set_cmdlist, &remote_show_cmdlist); |
5701 | add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class, | |
7915a72c AC |
5702 | &remote_hw_breakpoint_limit, _("\ |
5703 | Set the maximum number of target hardware breakpoints."), _("\ | |
5704 | Show the maximum number of target hardware breakpoints."), _("\ | |
5705 | Specify a negative limit for unlimited."), | |
2c5b56ce | 5706 | NULL, NULL, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */ |
b3f42336 | 5707 | &remote_set_cmdlist, &remote_show_cmdlist); |
501eef12 | 5708 | |
4d28ad1e AC |
5709 | add_setshow_integer_cmd ("remoteaddresssize", class_obscure, |
5710 | &remote_address_size, _("\ | |
5711 | Set the maximum size of the address (in bits) in a memory packet."), _("\ | |
5712 | Show the maximum size of the address (in bits) in a memory packet."), NULL, | |
5713 | NULL, | |
5714 | NULL, /* FIXME: i18n: */ | |
5715 | &setlist, &showlist); | |
c906108c | 5716 | |
96baa820 JM |
5717 | add_packet_config_cmd (&remote_protocol_binary_download, |
5718 | "X", "binary-download", | |
5719 | set_remote_protocol_binary_download_cmd, | |
5720 | show_remote_protocol_binary_download_cmd, | |
d471ea57 AC |
5721 | &remote_set_cmdlist, &remote_show_cmdlist, |
5722 | 1); | |
0f71a2f6 | 5723 | |
506fb367 DJ |
5724 | add_packet_config_cmd (&remote_protocol_vcont, |
5725 | "vCont", "verbose-resume", | |
5726 | set_remote_protocol_vcont_packet_cmd, | |
5727 | show_remote_protocol_vcont_packet_cmd, | |
5728 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5729 | 0); | |
5730 | ||
dc8acb97 MS |
5731 | add_packet_config_cmd (&remote_protocol_qSymbol, |
5732 | "qSymbol", "symbol-lookup", | |
5733 | set_remote_protocol_qSymbol_packet_cmd, | |
5734 | show_remote_protocol_qSymbol_packet_cmd, | |
5735 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5736 | 0); | |
5737 | ||
d471ea57 AC |
5738 | add_packet_config_cmd (&remote_protocol_P, |
5739 | "P", "set-register", | |
5a2468f5 JM |
5740 | set_remote_protocol_P_packet_cmd, |
5741 | show_remote_protocol_P_packet_cmd, | |
d471ea57 AC |
5742 | &remote_set_cmdlist, &remote_show_cmdlist, |
5743 | 1); | |
5744 | ||
b96ec7ac AC |
5745 | add_packet_config_cmd (&remote_protocol_p, |
5746 | "p", "fetch-register", | |
5747 | set_remote_protocol_p_packet_cmd, | |
5748 | show_remote_protocol_p_packet_cmd, | |
5749 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5750 | 1); | |
5751 | ||
d471ea57 AC |
5752 | add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP], |
5753 | "Z0", "software-breakpoint", | |
5754 | set_remote_protocol_Z_software_bp_packet_cmd, | |
5755 | show_remote_protocol_Z_software_bp_packet_cmd, | |
5756 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5757 | 0); | |
5758 | ||
5759 | add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP], | |
5760 | "Z1", "hardware-breakpoint", | |
5761 | set_remote_protocol_Z_hardware_bp_packet_cmd, | |
5762 | show_remote_protocol_Z_hardware_bp_packet_cmd, | |
5763 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5764 | 0); | |
5765 | ||
5766 | add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP], | |
5767 | "Z2", "write-watchpoint", | |
5768 | set_remote_protocol_Z_write_wp_packet_cmd, | |
5769 | show_remote_protocol_Z_write_wp_packet_cmd, | |
5770 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5771 | 0); | |
5772 | ||
5773 | add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP], | |
5774 | "Z3", "read-watchpoint", | |
5775 | set_remote_protocol_Z_read_wp_packet_cmd, | |
5776 | show_remote_protocol_Z_read_wp_packet_cmd, | |
5777 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5778 | 0); | |
5779 | ||
5780 | add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP], | |
5781 | "Z4", "access-watchpoint", | |
5782 | set_remote_protocol_Z_access_wp_packet_cmd, | |
5783 | show_remote_protocol_Z_access_wp_packet_cmd, | |
5784 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5785 | 0); | |
5786 | ||
802188a7 RM |
5787 | add_packet_config_cmd (&remote_protocol_qPart_auxv, |
5788 | "qPart_auxv", "read-aux-vector", | |
5789 | set_remote_protocol_qPart_auxv_packet_cmd, | |
5790 | show_remote_protocol_qPart_auxv_packet_cmd, | |
5791 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5792 | 0); | |
5793 | ||
38691318 KB |
5794 | add_packet_config_cmd (&remote_protocol_qGetTLSAddr, |
5795 | "qGetTLSAddr", "get-thread-local-storage-address", | |
5796 | set_remote_protocol_qGetTLSAddr_packet_cmd, | |
5797 | show_remote_protocol_qGetTLSAddr_packet_cmd, | |
5798 | &remote_set_cmdlist, &remote_show_cmdlist, | |
5799 | 0); | |
5800 | ||
23860348 | 5801 | /* Keep the old ``set remote Z-packet ...'' working. */ |
e9e68a56 | 5802 | add_setshow_auto_boolean_cmd ("Z-packet", class_obscure, |
7915a72c AC |
5803 | &remote_Z_packet_detect, _("\ |
5804 | Set use of remote protocol `Z' packets"), _("\ | |
5805 | Show use of remote protocol `Z' packets "), _("\ | |
3b64bf98 | 5806 | When set, GDB will attempt to use the remote breakpoint and watchpoint\n\ |
7915a72c | 5807 | packets."), |
e9e68a56 | 5808 | set_remote_protocol_Z_packet_cmd, |
2c5b56ce | 5809 | show_remote_protocol_Z_packet_cmd, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */ |
e9e68a56 | 5810 | &remote_set_cmdlist, &remote_show_cmdlist); |
449092f6 CV |
5811 | |
5812 | /* Eventually initialize fileio. See fileio.c */ | |
5813 | initialize_remote_fileio (remote_set_cmdlist, remote_show_cmdlist); | |
c906108c | 5814 | } |