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