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