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