| 1 | /* Remote target communications for serial-line targets in custom GDB protocol |
| 2 | Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | /* See the GDB User Guide for details of the GDB remote protocol. */ |
| 23 | |
| 24 | #include "defs.h" |
| 25 | #include "gdb_string.h" |
| 26 | #include <ctype.h> |
| 27 | #include <fcntl.h> |
| 28 | #include "frame.h" |
| 29 | #include "inferior.h" |
| 30 | #include "bfd.h" |
| 31 | #include "symfile.h" |
| 32 | #include "target.h" |
| 33 | #include "wait.h" |
| 34 | /*#include "terminal.h" */ |
| 35 | #include "gdbcmd.h" |
| 36 | #include "objfiles.h" |
| 37 | #include "gdb-stabs.h" |
| 38 | #include "gdbthread.h" |
| 39 | |
| 40 | #include "dcache.h" |
| 41 | |
| 42 | #include <ctype.h> |
| 43 | #include <sys/time.h> |
| 44 | #ifdef USG |
| 45 | #include <sys/types.h> |
| 46 | #endif |
| 47 | |
| 48 | #include "event-loop.h" |
| 49 | |
| 50 | #include <signal.h> |
| 51 | #include "serial.h" |
| 52 | |
| 53 | /* Prototypes for local functions */ |
| 54 | static void initialize_sigint_signal_handler PARAMS ((void)); |
| 55 | static void handle_remote_sigint PARAMS ((int)); |
| 56 | static void handle_remote_sigint_twice PARAMS ((int)); |
| 57 | static void async_remote_interrupt PARAMS ((gdb_client_data)); |
| 58 | static void async_remote_interrupt_twice PARAMS ((gdb_client_data)); |
| 59 | |
| 60 | static void set_extended_protocol PARAMS ((struct continuation_arg *)); |
| 61 | |
| 62 | static void build_remote_gdbarch_data PARAMS ((void)); |
| 63 | |
| 64 | static int remote_write_bytes PARAMS ((CORE_ADDR memaddr, |
| 65 | char *myaddr, int len)); |
| 66 | |
| 67 | static int remote_read_bytes PARAMS ((CORE_ADDR memaddr, |
| 68 | char *myaddr, int len)); |
| 69 | |
| 70 | static void remote_files_info PARAMS ((struct target_ops * ignore)); |
| 71 | |
| 72 | static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, |
| 73 | int len, int should_write, |
| 74 | struct target_ops * target)); |
| 75 | |
| 76 | static void remote_prepare_to_store PARAMS ((void)); |
| 77 | |
| 78 | static void remote_fetch_registers PARAMS ((int regno)); |
| 79 | |
| 80 | static void remote_resume PARAMS ((int pid, int step, |
| 81 | enum target_signal siggnal)); |
| 82 | static void remote_async_resume PARAMS ((int pid, int step, |
| 83 | enum target_signal siggnal)); |
| 84 | |
| 85 | static int remote_start_remote PARAMS ((PTR)); |
| 86 | |
| 87 | static void remote_open PARAMS ((char *name, int from_tty)); |
| 88 | static void remote_async_open PARAMS ((char *name, int from_tty)); |
| 89 | |
| 90 | static void extended_remote_open PARAMS ((char *name, int from_tty)); |
| 91 | static void extended_remote_async_open PARAMS ((char *name, int from_tty)); |
| 92 | |
| 93 | static void remote_open_1 PARAMS ((char *, int, struct target_ops *, |
| 94 | int extended_p)); |
| 95 | static void remote_async_open_1 PARAMS ((char *, int, struct target_ops *, |
| 96 | int extended_p)); |
| 97 | |
| 98 | static void remote_close PARAMS ((int quitting)); |
| 99 | |
| 100 | static void remote_store_registers PARAMS ((int regno)); |
| 101 | |
| 102 | static void remote_mourn PARAMS ((void)); |
| 103 | static void remote_async_mourn PARAMS ((void)); |
| 104 | |
| 105 | static void extended_remote_restart PARAMS ((void)); |
| 106 | |
| 107 | static void extended_remote_mourn PARAMS ((void)); |
| 108 | |
| 109 | static void extended_remote_create_inferior PARAMS ((char *, char *, char **)); |
| 110 | static void extended_remote_async_create_inferior PARAMS ((char *, char *, char **)); |
| 111 | |
| 112 | static void remote_mourn_1 PARAMS ((struct target_ops *)); |
| 113 | |
| 114 | static void remote_send PARAMS ((char *buf)); |
| 115 | |
| 116 | static int readchar PARAMS ((int timeout)); |
| 117 | |
| 118 | static int remote_wait PARAMS ((int pid, struct target_waitstatus * status)); |
| 119 | static int remote_async_wait PARAMS ((int pid, struct target_waitstatus * status)); |
| 120 | |
| 121 | static void remote_kill PARAMS ((void)); |
| 122 | static void remote_async_kill PARAMS ((void)); |
| 123 | |
| 124 | static int tohex PARAMS ((int nib)); |
| 125 | |
| 126 | static void remote_detach PARAMS ((char *args, int from_tty)); |
| 127 | static void remote_async_detach PARAMS ((char *args, int from_tty)); |
| 128 | |
| 129 | static void remote_interrupt PARAMS ((int signo)); |
| 130 | |
| 131 | static void remote_interrupt_twice PARAMS ((int signo)); |
| 132 | |
| 133 | static void interrupt_query PARAMS ((void)); |
| 134 | |
| 135 | static void set_thread PARAMS ((int, int)); |
| 136 | |
| 137 | static int remote_thread_alive PARAMS ((int)); |
| 138 | |
| 139 | static void get_offsets PARAMS ((void)); |
| 140 | |
| 141 | static int read_frame PARAMS ((char *)); |
| 142 | |
| 143 | static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *)); |
| 144 | |
| 145 | static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *)); |
| 146 | |
| 147 | static int hexnumlen PARAMS ((ULONGEST num)); |
| 148 | |
| 149 | static void init_remote_ops PARAMS ((void)); |
| 150 | |
| 151 | static void init_extended_remote_ops PARAMS ((void)); |
| 152 | |
| 153 | static void init_remote_cisco_ops PARAMS ((void)); |
| 154 | |
| 155 | static struct target_ops remote_cisco_ops; |
| 156 | |
| 157 | static void remote_stop PARAMS ((void)); |
| 158 | |
| 159 | static int ishex PARAMS ((int ch, int *val)); |
| 160 | |
| 161 | static int stubhex PARAMS ((int ch)); |
| 162 | |
| 163 | static int remote_query PARAMS ((int /*char */ , char *, char *, int *)); |
| 164 | |
| 165 | static int hexnumstr PARAMS ((char *, ULONGEST)); |
| 166 | |
| 167 | static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR)); |
| 168 | |
| 169 | static void print_packet PARAMS ((char *)); |
| 170 | |
| 171 | static unsigned long crc32 PARAMS ((unsigned char *, int, unsigned int)); |
| 172 | |
| 173 | static void compare_sections_command PARAMS ((char *, int)); |
| 174 | |
| 175 | static void packet_command PARAMS ((char *, int)); |
| 176 | |
| 177 | static int stub_unpack_int PARAMS ((char *buff, int fieldlength)); |
| 178 | |
| 179 | static int remote_current_thread PARAMS ((int oldpid)); |
| 180 | |
| 181 | static void remote_find_new_threads PARAMS ((void)); |
| 182 | |
| 183 | static void record_currthread PARAMS ((int currthread)); |
| 184 | |
| 185 | /* exported functions */ |
| 186 | |
| 187 | extern int fromhex PARAMS ((int a)); |
| 188 | |
| 189 | extern void getpkt PARAMS ((char *buf, int forever)); |
| 190 | |
| 191 | extern int putpkt PARAMS ((char *buf)); |
| 192 | |
| 193 | static int putpkt_binary PARAMS ((char *buf, int cnt)); |
| 194 | |
| 195 | void remote_console_output PARAMS ((char *)); |
| 196 | |
| 197 | static void check_binary_download PARAMS ((CORE_ADDR addr)); |
| 198 | |
| 199 | struct packet_config; |
| 200 | |
| 201 | static void show_packet_config_cmd PARAMS ((struct packet_config * config)); |
| 202 | |
| 203 | static void set_packet_config_cmd PARAMS ((struct packet_config * config, |
| 204 | struct cmd_list_element * c)); |
| 205 | |
| 206 | static void add_packet_config_cmd PARAMS ((struct packet_config * config, |
| 207 | char *name, |
| 208 | char *title, |
| 209 | void (*set_func) (char *args, int from_tty, struct cmd_list_element * c), |
| 210 | void (*show_func) (char *name, int from_tty), |
| 211 | struct cmd_list_element **setlist, |
| 212 | struct cmd_list_element **showlist)); |
| 213 | |
| 214 | static void init_packet_config PARAMS ((struct packet_config * config)); |
| 215 | |
| 216 | static void set_remote_protocol_P_packet_cmd PARAMS ((char *args, |
| 217 | int from_tty, |
| 218 | struct cmd_list_element * c)); |
| 219 | |
| 220 | static void show_remote_protocol_P_packet_cmd PARAMS ((char *args, |
| 221 | int from_tty)); |
| 222 | |
| 223 | static void set_remote_protocol_Z_packet_cmd PARAMS ((char *args, |
| 224 | int from_tty, |
| 225 | struct cmd_list_element * c)); |
| 226 | |
| 227 | static void show_remote_protocol_Z_packet_cmd PARAMS ((char *args, |
| 228 | int from_tty)); |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | /* Define the target subroutine names */ |
| 234 | |
| 235 | void open_remote_target PARAMS ((char *, int, struct target_ops *, int)); |
| 236 | |
| 237 | void _initialize_remote PARAMS ((void)); |
| 238 | |
| 239 | /* */ |
| 240 | |
| 241 | static struct target_ops remote_ops; |
| 242 | |
| 243 | static struct target_ops extended_remote_ops; |
| 244 | |
| 245 | /* Temporary target ops. Just like the remote_ops and |
| 246 | extended_remote_ops, but with asynchronous support. */ |
| 247 | static struct target_ops remote_async_ops; |
| 248 | |
| 249 | static struct target_ops extended_async_remote_ops; |
| 250 | |
| 251 | /* This was 5 seconds, which is a long time to sit and wait. |
| 252 | Unless this is going though some terminal server or multiplexer or |
| 253 | other form of hairy serial connection, I would think 2 seconds would |
| 254 | be plenty. */ |
| 255 | |
| 256 | /* Changed to allow option to set timeout value. |
| 257 | was static int remote_timeout = 2; */ |
| 258 | extern int remote_timeout; |
| 259 | |
| 260 | /* This variable chooses whether to send a ^C or a break when the user |
| 261 | requests program interruption. Although ^C is usually what remote |
| 262 | systems expect, and that is the default here, sometimes a break is |
| 263 | preferable instead. */ |
| 264 | |
| 265 | static int remote_break; |
| 266 | |
| 267 | /* Descriptor for I/O to remote machine. Initialize it to NULL so that |
| 268 | remote_open knows that we don't have a file open when the program |
| 269 | starts. */ |
| 270 | static serial_t remote_desc = NULL; |
| 271 | |
| 272 | /* This is set by the target (thru the 'S' message) |
| 273 | to denote that the target is in kernel mode. */ |
| 274 | static int cisco_kernel_mode = 0; |
| 275 | |
| 276 | /* Maximum number of bytes to read/write at once. The value here |
| 277 | is chosen to fill up a packet (the headers account for the 32). */ |
| 278 | #define MAXBUFBYTES(N) (((N)-32)/2) |
| 279 | |
| 280 | /* Having this larger than 400 causes us to be incompatible with m68k-stub.c |
| 281 | and i386-stub.c. Normally, no one would notice because it only matters |
| 282 | for writing large chunks of memory (e.g. in downloads). Also, this needs |
| 283 | to be more than 400 if required to hold the registers (see below, where |
| 284 | we round it up based on REGISTER_BYTES). */ |
| 285 | /* Round up PBUFSIZ to hold all the registers, at least. */ |
| 286 | #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \ |
| 287 | ? (REGISTER_BYTES * 2 + 32) \ |
| 288 | : 400) |
| 289 | |
| 290 | |
| 291 | /* This variable sets the number of bytes to be written to the target |
| 292 | in a single packet. Normally PBUFSIZ is satisfactory, but some |
| 293 | targets need smaller values (perhaps because the receiving end |
| 294 | is slow). */ |
| 295 | |
| 296 | static int remote_write_size; |
| 297 | |
| 298 | /* This variable sets the number of bits in an address that are to be |
| 299 | sent in a memory ("M" or "m") packet. Normally, after stripping |
| 300 | leading zeros, the entire address would be sent. This variable |
| 301 | restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The |
| 302 | initial implementation of remote.c restricted the address sent in |
| 303 | memory packets to ``host::sizeof long'' bytes - (typically 32 |
| 304 | bits). Consequently, for 64 bit targets, the upper 32 bits of an |
| 305 | address was never sent. Since fixing this bug may cause a break in |
| 306 | some remote targets this variable is principly provided to |
| 307 | facilitate backward compatibility. */ |
| 308 | |
| 309 | static int remote_address_size; |
| 310 | |
| 311 | /* This is the size (in chars) of the first response to the `g' command. This |
| 312 | is used to limit the size of the memory read and write commands to prevent |
| 313 | stub buffers from overflowing. The size does not include headers and |
| 314 | trailers, it is only the payload size. */ |
| 315 | |
| 316 | static int remote_register_buf_size = 0; |
| 317 | |
| 318 | /* Generic configuration support for packets the stub optionally |
| 319 | supports. Allows the user to specify the use of the packet as well |
| 320 | as allowing GDB to auto-detect support in the remote stub. */ |
| 321 | |
| 322 | enum packet_support |
| 323 | { |
| 324 | PACKET_SUPPORT_UNKNOWN = 0, |
| 325 | PACKET_ENABLE, |
| 326 | PACKET_DISABLE |
| 327 | }; |
| 328 | |
| 329 | enum packet_detect |
| 330 | { |
| 331 | PACKET_AUTO_DETECT = 0, |
| 332 | PACKET_MANUAL_DETECT |
| 333 | }; |
| 334 | |
| 335 | struct packet_config |
| 336 | { |
| 337 | char *state; |
| 338 | char *name; |
| 339 | char *title; |
| 340 | enum packet_detect detect; |
| 341 | enum packet_support support; |
| 342 | }; |
| 343 | |
| 344 | static char packet_support_auto[] = "auto"; |
| 345 | static char packet_enable[] = "enable"; |
| 346 | static char packet_disable[] = "disable"; |
| 347 | static char *packet_support_enums[] = |
| 348 | { |
| 349 | packet_support_auto, |
| 350 | packet_enable, |
| 351 | packet_disable, |
| 352 | 0, |
| 353 | }; |
| 354 | |
| 355 | static void |
| 356 | set_packet_config_cmd (config, c) |
| 357 | struct packet_config *config; |
| 358 | struct cmd_list_element *c; |
| 359 | { |
| 360 | if (config->state == packet_enable) |
| 361 | { |
| 362 | config->detect = PACKET_MANUAL_DETECT; |
| 363 | config->support = PACKET_ENABLE; |
| 364 | } |
| 365 | else if (config->state == packet_disable) |
| 366 | { |
| 367 | config->detect = PACKET_MANUAL_DETECT; |
| 368 | config->support = PACKET_DISABLE; |
| 369 | } |
| 370 | else if (config->state == packet_support_auto) |
| 371 | { |
| 372 | config->detect = PACKET_AUTO_DETECT; |
| 373 | config->support = PACKET_SUPPORT_UNKNOWN; |
| 374 | } |
| 375 | else |
| 376 | internal_error ("Bad enum value"); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | show_packet_config_cmd (config) |
| 381 | struct packet_config *config; |
| 382 | { |
| 383 | char *support = "internal-error"; |
| 384 | switch (config->support) |
| 385 | { |
| 386 | case PACKET_ENABLE: |
| 387 | support = "enabled"; |
| 388 | break; |
| 389 | case PACKET_DISABLE: |
| 390 | support = "disabled"; |
| 391 | break; |
| 392 | case PACKET_SUPPORT_UNKNOWN: |
| 393 | support = "unknown"; |
| 394 | break; |
| 395 | } |
| 396 | switch (config->detect) |
| 397 | { |
| 398 | case PACKET_AUTO_DETECT: |
| 399 | printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n", |
| 400 | config->name, config->title, support); |
| 401 | break; |
| 402 | case PACKET_MANUAL_DETECT: |
| 403 | printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n", |
| 404 | config->name, config->title, support); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static void |
| 409 | add_packet_config_cmd (config, name, title, set_func, show_func, |
| 410 | setlist, showlist) |
| 411 | struct packet_config *config; |
| 412 | char *name; |
| 413 | char *title; |
| 414 | void (*set_func) PARAMS ((char *args, int from_tty, |
| 415 | struct cmd_list_element * c)); |
| 416 | void (*show_func) PARAMS ((char *name, int from_tty)); |
| 417 | struct cmd_list_element **setlist; |
| 418 | struct cmd_list_element **showlist; |
| 419 | { |
| 420 | struct cmd_list_element *c; |
| 421 | char *set_doc; |
| 422 | char *show_doc; |
| 423 | char *full_name; |
| 424 | config->name = name; |
| 425 | config->title = title; |
| 426 | asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet", |
| 427 | name, title); |
| 428 | asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet", |
| 429 | name, title); |
| 430 | asprintf (&full_name, "%s-packet", name); |
| 431 | c = add_set_enum_cmd (full_name, |
| 432 | class_obscure, packet_support_enums, |
| 433 | (char *) &config->state, |
| 434 | set_doc, setlist); |
| 435 | c->function.sfunc = set_func; |
| 436 | add_cmd (full_name, class_obscure, show_func, show_doc, showlist); |
| 437 | } |
| 438 | |
| 439 | static void |
| 440 | init_packet_config (config) |
| 441 | struct packet_config *config; |
| 442 | { |
| 443 | switch (config->detect) |
| 444 | { |
| 445 | case PACKET_AUTO_DETECT: |
| 446 | config->support = PACKET_SUPPORT_UNKNOWN; |
| 447 | break; |
| 448 | case PACKET_MANUAL_DETECT: |
| 449 | /* let the user beware */ |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /* Should we try the 'P' (set register) request? */ |
| 455 | |
| 456 | static struct packet_config remote_protocol_P; |
| 457 | |
| 458 | static void |
| 459 | set_remote_protocol_P_packet_cmd (args, from_tty, c) |
| 460 | char *args; |
| 461 | int from_tty; |
| 462 | struct cmd_list_element *c; |
| 463 | { |
| 464 | set_packet_config_cmd (&remote_protocol_P, c); |
| 465 | } |
| 466 | |
| 467 | static void |
| 468 | show_remote_protocol_P_packet_cmd (args, from_tty) |
| 469 | char *args; |
| 470 | int from_tty; |
| 471 | { |
| 472 | show_packet_config_cmd (&remote_protocol_P); |
| 473 | } |
| 474 | |
| 475 | /* Should we try the 'Z' (set breakpoint) request? */ |
| 476 | |
| 477 | static struct packet_config remote_protocol_Z; |
| 478 | |
| 479 | static void |
| 480 | set_remote_protocol_Z_packet_cmd (args, from_tty, c) |
| 481 | char *args; |
| 482 | int from_tty; |
| 483 | struct cmd_list_element *c; |
| 484 | { |
| 485 | set_packet_config_cmd (&remote_protocol_Z, c); |
| 486 | } |
| 487 | |
| 488 | static void |
| 489 | show_remote_protocol_Z_packet_cmd (args, from_tty) |
| 490 | char *args; |
| 491 | int from_tty; |
| 492 | { |
| 493 | show_packet_config_cmd (&remote_protocol_Z); |
| 494 | } |
| 495 | |
| 496 | /* Should we try the 'X' (remote binary download) packet? |
| 497 | |
| 498 | This variable (available to the user via "set remote X-packet") |
| 499 | dictates whether downloads are sent in binary (via the 'X' packet). |
| 500 | We assume that the stub can, and attempt to do it. This will be |
| 501 | cleared if the stub does not understand it. This switch is still |
| 502 | needed, though in cases when the packet is supported in the stub, |
| 503 | but the connection does not allow it (i.e., 7-bit serial connection |
| 504 | only). */ |
| 505 | |
| 506 | static struct packet_config remote_protocol_binary_download; |
| 507 | |
| 508 | static void |
| 509 | set_remote_protocol_binary_download_cmd (char *args, |
| 510 | int from_tty, |
| 511 | struct cmd_list_element *c) |
| 512 | { |
| 513 | set_packet_config_cmd (&remote_protocol_binary_download, c); |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | show_remote_protocol_binary_download_cmd (char *args, |
| 518 | int from_tty) |
| 519 | { |
| 520 | show_packet_config_cmd (&remote_protocol_binary_download); |
| 521 | } |
| 522 | |
| 523 | |
| 524 | /* Tokens for use by the asynchronous signal handlers for SIGINT */ |
| 525 | PTR sigint_remote_twice_token; |
| 526 | PTR sigint_remote_token; |
| 527 | |
| 528 | /* These are pointers to hook functions that may be set in order to |
| 529 | modify resume/wait behavior for a particular architecture. */ |
| 530 | |
| 531 | void (*target_resume_hook) PARAMS ((void)); |
| 532 | void (*target_wait_loop_hook) PARAMS ((void)); |
| 533 | \f |
| 534 | |
| 535 | |
| 536 | /* These are the threads which we last sent to the remote system. |
| 537 | -1 for all or -2 for not sent yet. */ |
| 538 | static int general_thread; |
| 539 | static int continue_thread; |
| 540 | |
| 541 | /* Call this function as a result of |
| 542 | 1) A halt indication (T packet) containing a thread id |
| 543 | 2) A direct query of currthread |
| 544 | 3) Successful execution of set thread |
| 545 | */ |
| 546 | |
| 547 | static void |
| 548 | record_currthread (currthread) |
| 549 | int currthread; |
| 550 | { |
| 551 | general_thread = currthread; |
| 552 | |
| 553 | /* If this is a new thread, add it to GDB's thread list. |
| 554 | If we leave it up to WFI to do this, bad things will happen. */ |
| 555 | if (!in_thread_list (currthread)) |
| 556 | { |
| 557 | add_thread (currthread); |
| 558 | printf_filtered ("[New %s]\n", target_pid_to_str (currthread)); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | #define MAGIC_NULL_PID 42000 |
| 563 | |
| 564 | static void |
| 565 | set_thread (th, gen) |
| 566 | int th; |
| 567 | int gen; |
| 568 | { |
| 569 | char *buf = alloca (PBUFSIZ); |
| 570 | int state = gen ? general_thread : continue_thread; |
| 571 | |
| 572 | if (state == th) |
| 573 | return; |
| 574 | |
| 575 | buf[0] = 'H'; |
| 576 | buf[1] = gen ? 'g' : 'c'; |
| 577 | if (th == MAGIC_NULL_PID) |
| 578 | { |
| 579 | buf[2] = '0'; |
| 580 | buf[3] = '\0'; |
| 581 | } |
| 582 | else if (th < 0) |
| 583 | sprintf (&buf[2], "-%x", -th); |
| 584 | else |
| 585 | sprintf (&buf[2], "%x", th); |
| 586 | putpkt (buf); |
| 587 | getpkt (buf, 0); |
| 588 | if (gen) |
| 589 | general_thread = th; |
| 590 | else |
| 591 | continue_thread = th; |
| 592 | } |
| 593 | \f |
| 594 | /* Return nonzero if the thread TH is still alive on the remote system. */ |
| 595 | |
| 596 | static int |
| 597 | remote_thread_alive (tid) |
| 598 | int tid; |
| 599 | { |
| 600 | char buf[16]; |
| 601 | |
| 602 | if (tid < 0) |
| 603 | sprintf (buf, "T-%08x", -tid); |
| 604 | else |
| 605 | sprintf (buf, "T%08x", tid); |
| 606 | putpkt (buf); |
| 607 | getpkt (buf, 0); |
| 608 | return (buf[0] == 'O' && buf[1] == 'K'); |
| 609 | } |
| 610 | |
| 611 | /* About these extended threadlist and threadinfo packets. They are |
| 612 | variable length packets but, the fields within them are often fixed |
| 613 | length. They are redundent enough to send over UDP as is the |
| 614 | remote protocol in general. There is a matching unit test module |
| 615 | in libstub. */ |
| 616 | |
| 617 | #define OPAQUETHREADBYTES 8 |
| 618 | |
| 619 | /* a 64 bit opaque identifier */ |
| 620 | typedef unsigned char threadref[OPAQUETHREADBYTES]; |
| 621 | |
| 622 | /* WARNING: This threadref data structure comes from the remote O.S., libstub |
| 623 | protocol encoding, and remote.c. it is not particularly changable */ |
| 624 | |
| 625 | /* Right now, the internal structure is int. We want it to be bigger. |
| 626 | Plan to fix this. |
| 627 | */ |
| 628 | |
| 629 | typedef int gdb_threadref; /* internal GDB thread reference */ |
| 630 | |
| 631 | /* gdb_ext_thread_info is an internal GDB data structure which is |
| 632 | equivalint to the reply of the remote threadinfo packet */ |
| 633 | |
| 634 | struct gdb_ext_thread_info |
| 635 | { |
| 636 | threadref threadid; /* External form of thread reference */ |
| 637 | int active; /* Has state interesting to GDB? , regs, stack */ |
| 638 | char display[256]; /* Brief state display, name, blocked/syspended */ |
| 639 | char shortname[32]; /* To be used to name threads */ |
| 640 | char more_display[256]; /* Long info, statistics, queue depth, whatever */ |
| 641 | }; |
| 642 | |
| 643 | /* The volume of remote transfers can be limited by submitting |
| 644 | a mask containing bits specifying the desired information. |
| 645 | Use a union of these values as the 'selection' parameter to |
| 646 | get_thread_info. FIXME: Make these TAG names more thread specific. |
| 647 | */ |
| 648 | |
| 649 | #define TAG_THREADID 1 |
| 650 | #define TAG_EXISTS 2 |
| 651 | #define TAG_DISPLAY 4 |
| 652 | #define TAG_THREADNAME 8 |
| 653 | #define TAG_MOREDISPLAY 16 |
| 654 | |
| 655 | #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2) |
| 656 | |
| 657 | char *unpack_varlen_hex PARAMS ((char *buff, int *result)); |
| 658 | |
| 659 | static char *unpack_nibble PARAMS ((char *buf, int *val)); |
| 660 | |
| 661 | static char *pack_nibble PARAMS ((char *buf, int nibble)); |
| 662 | |
| 663 | static char *pack_hex_byte PARAMS ((char *pkt, int /*unsigned char */ byte)); |
| 664 | |
| 665 | static char *unpack_byte PARAMS ((char *buf, int *value)); |
| 666 | |
| 667 | static char *pack_int PARAMS ((char *buf, int value)); |
| 668 | |
| 669 | static char *unpack_int PARAMS ((char *buf, int *value)); |
| 670 | |
| 671 | static char *unpack_string PARAMS ((char *src, char *dest, int length)); |
| 672 | |
| 673 | static char *pack_threadid PARAMS ((char *pkt, threadref * id)); |
| 674 | |
| 675 | static char *unpack_threadid PARAMS ((char *inbuf, threadref * id)); |
| 676 | |
| 677 | void int_to_threadref PARAMS ((threadref * id, int value)); |
| 678 | |
| 679 | static int threadref_to_int PARAMS ((threadref * ref)); |
| 680 | |
| 681 | static void copy_threadref PARAMS ((threadref * dest, threadref * src)); |
| 682 | |
| 683 | static int threadmatch PARAMS ((threadref * dest, threadref * src)); |
| 684 | |
| 685 | static char *pack_threadinfo_request PARAMS ((char *pkt, int mode, |
| 686 | threadref * id)); |
| 687 | |
| 688 | static int remote_unpack_thread_info_response PARAMS ((char *pkt, |
| 689 | threadref * expectedref, |
| 690 | struct gdb_ext_thread_info * info)); |
| 691 | |
| 692 | |
| 693 | static int remote_get_threadinfo PARAMS ((threadref * threadid, |
| 694 | int fieldset, /*TAG mask */ |
| 695 | struct gdb_ext_thread_info * info)); |
| 696 | |
| 697 | static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref * ref, |
| 698 | int selection, |
| 699 | struct gdb_ext_thread_info * info)); |
| 700 | |
| 701 | static char *pack_threadlist_request PARAMS ((char *pkt, int startflag, |
| 702 | int threadcount, |
| 703 | threadref * nextthread)); |
| 704 | |
| 705 | static int parse_threadlist_response PARAMS ((char *pkt, |
| 706 | int result_limit, |
| 707 | threadref * original_echo, |
| 708 | threadref * resultlist, |
| 709 | int *doneflag)); |
| 710 | |
| 711 | static int remote_get_threadlist PARAMS ((int startflag, |
| 712 | threadref * nextthread, |
| 713 | int result_limit, |
| 714 | int *done, |
| 715 | int *result_count, |
| 716 | threadref * threadlist)); |
| 717 | |
| 718 | typedef int (*rmt_thread_action) (threadref * ref, void *context); |
| 719 | |
| 720 | static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction, |
| 721 | void *context, int looplimit)); |
| 722 | |
| 723 | static int remote_newthread_step PARAMS ((threadref * ref, void *context)); |
| 724 | |
| 725 | /* encode 64 bits in 16 chars of hex */ |
| 726 | |
| 727 | static const char hexchars[] = "0123456789abcdef"; |
| 728 | |
| 729 | static int |
| 730 | ishex (ch, val) |
| 731 | int ch; |
| 732 | int *val; |
| 733 | { |
| 734 | if ((ch >= 'a') && (ch <= 'f')) |
| 735 | { |
| 736 | *val = ch - 'a' + 10; |
| 737 | return 1; |
| 738 | } |
| 739 | if ((ch >= 'A') && (ch <= 'F')) |
| 740 | { |
| 741 | *val = ch - 'A' + 10; |
| 742 | return 1; |
| 743 | } |
| 744 | if ((ch >= '0') && (ch <= '9')) |
| 745 | { |
| 746 | *val = ch - '0'; |
| 747 | return 1; |
| 748 | } |
| 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | static int |
| 753 | stubhex (ch) |
| 754 | int ch; |
| 755 | { |
| 756 | if (ch >= 'a' && ch <= 'f') |
| 757 | return ch - 'a' + 10; |
| 758 | if (ch >= '0' && ch <= '9') |
| 759 | return ch - '0'; |
| 760 | if (ch >= 'A' && ch <= 'F') |
| 761 | return ch - 'A' + 10; |
| 762 | return -1; |
| 763 | } |
| 764 | |
| 765 | static int |
| 766 | stub_unpack_int (buff, fieldlength) |
| 767 | char *buff; |
| 768 | int fieldlength; |
| 769 | { |
| 770 | int nibble; |
| 771 | int retval = 0; |
| 772 | |
| 773 | while (fieldlength) |
| 774 | { |
| 775 | nibble = stubhex (*buff++); |
| 776 | retval |= nibble; |
| 777 | fieldlength--; |
| 778 | if (fieldlength) |
| 779 | retval = retval << 4; |
| 780 | } |
| 781 | return retval; |
| 782 | } |
| 783 | |
| 784 | char * |
| 785 | unpack_varlen_hex (buff, result) |
| 786 | char *buff; /* packet to parse */ |
| 787 | int *result; |
| 788 | { |
| 789 | int nibble; |
| 790 | int retval = 0; |
| 791 | |
| 792 | while (ishex (*buff, &nibble)) |
| 793 | { |
| 794 | buff++; |
| 795 | retval = retval << 4; |
| 796 | retval |= nibble & 0x0f; |
| 797 | } |
| 798 | *result = retval; |
| 799 | return buff; |
| 800 | } |
| 801 | |
| 802 | static char * |
| 803 | unpack_nibble (buf, val) |
| 804 | char *buf; |
| 805 | int *val; |
| 806 | { |
| 807 | ishex (*buf++, val); |
| 808 | return buf; |
| 809 | } |
| 810 | |
| 811 | static char * |
| 812 | pack_nibble (buf, nibble) |
| 813 | char *buf; |
| 814 | int nibble; |
| 815 | { |
| 816 | *buf++ = hexchars[(nibble & 0x0f)]; |
| 817 | return buf; |
| 818 | } |
| 819 | |
| 820 | static char * |
| 821 | pack_hex_byte (pkt, byte) |
| 822 | char *pkt; |
| 823 | int byte; |
| 824 | { |
| 825 | *pkt++ = hexchars[(byte >> 4) & 0xf]; |
| 826 | *pkt++ = hexchars[(byte & 0xf)]; |
| 827 | return pkt; |
| 828 | } |
| 829 | |
| 830 | static char * |
| 831 | unpack_byte (buf, value) |
| 832 | char *buf; |
| 833 | int *value; |
| 834 | { |
| 835 | *value = stub_unpack_int (buf, 2); |
| 836 | return buf + 2; |
| 837 | } |
| 838 | |
| 839 | static char * |
| 840 | pack_int (buf, value) |
| 841 | char *buf; |
| 842 | int value; |
| 843 | { |
| 844 | buf = pack_hex_byte (buf, (value >> 24) & 0xff); |
| 845 | buf = pack_hex_byte (buf, (value >> 16) & 0xff); |
| 846 | buf = pack_hex_byte (buf, (value >> 8) & 0x0ff); |
| 847 | buf = pack_hex_byte (buf, (value & 0xff)); |
| 848 | return buf; |
| 849 | } |
| 850 | |
| 851 | static char * |
| 852 | unpack_int (buf, value) |
| 853 | char *buf; |
| 854 | int *value; |
| 855 | { |
| 856 | *value = stub_unpack_int (buf, 8); |
| 857 | return buf + 8; |
| 858 | } |
| 859 | |
| 860 | #if 0 /* currently unused, uncomment when needed */ |
| 861 | static char *pack_string PARAMS ((char *pkt, char *string)); |
| 862 | |
| 863 | static char * |
| 864 | pack_string (pkt, string) |
| 865 | char *pkt; |
| 866 | char *string; |
| 867 | { |
| 868 | char ch; |
| 869 | int len; |
| 870 | |
| 871 | len = strlen (string); |
| 872 | if (len > 200) |
| 873 | len = 200; /* Bigger than most GDB packets, junk??? */ |
| 874 | pkt = pack_hex_byte (pkt, len); |
| 875 | while (len-- > 0) |
| 876 | { |
| 877 | ch = *string++; |
| 878 | if ((ch == '\0') || (ch == '#')) |
| 879 | ch = '*'; /* Protect encapsulation */ |
| 880 | *pkt++ = ch; |
| 881 | } |
| 882 | return pkt; |
| 883 | } |
| 884 | #endif /* 0 (unused) */ |
| 885 | |
| 886 | static char * |
| 887 | unpack_string (src, dest, length) |
| 888 | char *src; |
| 889 | char *dest; |
| 890 | int length; |
| 891 | { |
| 892 | while (length--) |
| 893 | *dest++ = *src++; |
| 894 | *dest = '\0'; |
| 895 | return src; |
| 896 | } |
| 897 | |
| 898 | static char * |
| 899 | pack_threadid (pkt, id) |
| 900 | char *pkt; |
| 901 | threadref *id; |
| 902 | { |
| 903 | char *limit; |
| 904 | unsigned char *altid; |
| 905 | |
| 906 | altid = (unsigned char *) id; |
| 907 | limit = pkt + BUF_THREAD_ID_SIZE; |
| 908 | while (pkt < limit) |
| 909 | pkt = pack_hex_byte (pkt, *altid++); |
| 910 | return pkt; |
| 911 | } |
| 912 | |
| 913 | |
| 914 | static char * |
| 915 | unpack_threadid (inbuf, id) |
| 916 | char *inbuf; |
| 917 | threadref *id; |
| 918 | { |
| 919 | char *altref; |
| 920 | char *limit = inbuf + BUF_THREAD_ID_SIZE; |
| 921 | int x, y; |
| 922 | |
| 923 | altref = (char *) id; |
| 924 | |
| 925 | while (inbuf < limit) |
| 926 | { |
| 927 | x = stubhex (*inbuf++); |
| 928 | y = stubhex (*inbuf++); |
| 929 | *altref++ = (x << 4) | y; |
| 930 | } |
| 931 | return inbuf; |
| 932 | } |
| 933 | |
| 934 | /* Externally, threadrefs are 64 bits but internally, they are still |
| 935 | ints. This is due to a mismatch of specifications. We would like |
| 936 | to use 64bit thread references internally. This is an adapter |
| 937 | function. */ |
| 938 | |
| 939 | void |
| 940 | int_to_threadref (id, value) |
| 941 | threadref *id; |
| 942 | int value; |
| 943 | { |
| 944 | unsigned char *scan; |
| 945 | |
| 946 | scan = (unsigned char *) id; |
| 947 | { |
| 948 | int i = 4; |
| 949 | while (i--) |
| 950 | *scan++ = 0; |
| 951 | } |
| 952 | *scan++ = (value >> 24) & 0xff; |
| 953 | *scan++ = (value >> 16) & 0xff; |
| 954 | *scan++ = (value >> 8) & 0xff; |
| 955 | *scan++ = (value & 0xff); |
| 956 | } |
| 957 | |
| 958 | static int |
| 959 | threadref_to_int (ref) |
| 960 | threadref *ref; |
| 961 | { |
| 962 | int i, value = 0; |
| 963 | unsigned char *scan; |
| 964 | |
| 965 | scan = (char *) ref; |
| 966 | scan += 4; |
| 967 | i = 4; |
| 968 | while (i-- > 0) |
| 969 | value = (value << 8) | ((*scan++) & 0xff); |
| 970 | return value; |
| 971 | } |
| 972 | |
| 973 | static void |
| 974 | copy_threadref (dest, src) |
| 975 | threadref *dest; |
| 976 | threadref *src; |
| 977 | { |
| 978 | int i; |
| 979 | unsigned char *csrc, *cdest; |
| 980 | |
| 981 | csrc = (unsigned char *) src; |
| 982 | cdest = (unsigned char *) dest; |
| 983 | i = 8; |
| 984 | while (i--) |
| 985 | *cdest++ = *csrc++; |
| 986 | } |
| 987 | |
| 988 | static int |
| 989 | threadmatch (dest, src) |
| 990 | threadref *dest; |
| 991 | threadref *src; |
| 992 | { |
| 993 | /* things are broken right now, so just assume we got a match */ |
| 994 | #if 0 |
| 995 | unsigned char *srcp, *destp; |
| 996 | int i, result; |
| 997 | srcp = (char *) src; |
| 998 | destp = (char *) dest; |
| 999 | |
| 1000 | result = 1; |
| 1001 | while (i-- > 0) |
| 1002 | result &= (*srcp++ == *destp++) ? 1 : 0; |
| 1003 | return result; |
| 1004 | #endif |
| 1005 | return 1; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | threadid:1, # always request threadid |
| 1010 | context_exists:2, |
| 1011 | display:4, |
| 1012 | unique_name:8, |
| 1013 | more_display:16 |
| 1014 | */ |
| 1015 | |
| 1016 | /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */ |
| 1017 | |
| 1018 | static char * |
| 1019 | pack_threadinfo_request (pkt, mode, id) |
| 1020 | char *pkt; |
| 1021 | int mode; |
| 1022 | threadref *id; |
| 1023 | { |
| 1024 | *pkt++ = 'q'; /* Info Query */ |
| 1025 | *pkt++ = 'P'; /* process or thread info */ |
| 1026 | pkt = pack_int (pkt, mode); /* mode */ |
| 1027 | pkt = pack_threadid (pkt, id); /* threadid */ |
| 1028 | *pkt = '\0'; /* terminate */ |
| 1029 | return pkt; |
| 1030 | } |
| 1031 | |
| 1032 | /* These values tag the fields in a thread info response packet */ |
| 1033 | /* Tagging the fields allows us to request specific fields and to |
| 1034 | add more fields as time goes by */ |
| 1035 | |
| 1036 | #define TAG_THREADID 1 /* Echo the thread identifier */ |
| 1037 | #define TAG_EXISTS 2 /* Is this process defined enough to |
| 1038 | fetch registers and its stack */ |
| 1039 | #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */ |
| 1040 | #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */ |
| 1041 | #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about |
| 1042 | the process */ |
| 1043 | |
| 1044 | static int |
| 1045 | remote_unpack_thread_info_response (pkt, expectedref, info) |
| 1046 | char *pkt; |
| 1047 | threadref *expectedref; |
| 1048 | struct gdb_ext_thread_info *info; |
| 1049 | { |
| 1050 | int mask, length; |
| 1051 | unsigned int tag; |
| 1052 | threadref ref; |
| 1053 | char *limit = pkt + PBUFSIZ; /* plausable parsing limit */ |
| 1054 | int retval = 1; |
| 1055 | |
| 1056 | /* info->threadid = 0; FIXME: implement zero_threadref */ |
| 1057 | info->active = 0; |
| 1058 | info->display[0] = '\0'; |
| 1059 | info->shortname[0] = '\0'; |
| 1060 | info->more_display[0] = '\0'; |
| 1061 | |
| 1062 | /* Assume the characters indicating the packet type have been stripped */ |
| 1063 | pkt = unpack_int (pkt, &mask); /* arg mask */ |
| 1064 | pkt = unpack_threadid (pkt, &ref); |
| 1065 | |
| 1066 | if (mask == 0) |
| 1067 | warning ("Incomplete response to threadinfo request\n"); |
| 1068 | if (!threadmatch (&ref, expectedref)) |
| 1069 | { /* This is an answer to a different request */ |
| 1070 | warning ("ERROR RMT Thread info mismatch\n"); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | copy_threadref (&info->threadid, &ref); |
| 1074 | |
| 1075 | /* Loop on tagged fields , try to bail if somthing goes wrong */ |
| 1076 | |
| 1077 | while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */ |
| 1078 | { |
| 1079 | pkt = unpack_int (pkt, &tag); /* tag */ |
| 1080 | pkt = unpack_byte (pkt, &length); /* length */ |
| 1081 | if (!(tag & mask)) /* tags out of synch with mask */ |
| 1082 | { |
| 1083 | warning ("ERROR RMT: threadinfo tag mismatch\n"); |
| 1084 | retval = 0; |
| 1085 | break; |
| 1086 | } |
| 1087 | if (tag == TAG_THREADID) |
| 1088 | { |
| 1089 | if (length != 16) |
| 1090 | { |
| 1091 | warning ("ERROR RMT: length of threadid is not 16\n"); |
| 1092 | retval = 0; |
| 1093 | break; |
| 1094 | } |
| 1095 | pkt = unpack_threadid (pkt, &ref); |
| 1096 | mask = mask & ~TAG_THREADID; |
| 1097 | continue; |
| 1098 | } |
| 1099 | if (tag == TAG_EXISTS) |
| 1100 | { |
| 1101 | info->active = stub_unpack_int (pkt, length); |
| 1102 | pkt += length; |
| 1103 | mask = mask & ~(TAG_EXISTS); |
| 1104 | if (length > 8) |
| 1105 | { |
| 1106 | warning ("ERROR RMT: 'exists' length too long\n"); |
| 1107 | retval = 0; |
| 1108 | break; |
| 1109 | } |
| 1110 | continue; |
| 1111 | } |
| 1112 | if (tag == TAG_THREADNAME) |
| 1113 | { |
| 1114 | pkt = unpack_string (pkt, &info->shortname[0], length); |
| 1115 | mask = mask & ~TAG_THREADNAME; |
| 1116 | continue; |
| 1117 | } |
| 1118 | if (tag == TAG_DISPLAY) |
| 1119 | { |
| 1120 | pkt = unpack_string (pkt, &info->display[0], length); |
| 1121 | mask = mask & ~TAG_DISPLAY; |
| 1122 | continue; |
| 1123 | } |
| 1124 | if (tag == TAG_MOREDISPLAY) |
| 1125 | { |
| 1126 | pkt = unpack_string (pkt, &info->more_display[0], length); |
| 1127 | mask = mask & ~TAG_MOREDISPLAY; |
| 1128 | continue; |
| 1129 | } |
| 1130 | warning ("ERROR RMT: unknown thread info tag\n"); |
| 1131 | break; /* Not a tag we know about */ |
| 1132 | } |
| 1133 | return retval; |
| 1134 | } |
| 1135 | |
| 1136 | static int |
| 1137 | remote_get_threadinfo (threadid, fieldset, info) |
| 1138 | threadref *threadid; |
| 1139 | int fieldset; /* TAG mask */ |
| 1140 | struct gdb_ext_thread_info *info; |
| 1141 | { |
| 1142 | int result; |
| 1143 | char *threadinfo_pkt = alloca (PBUFSIZ); |
| 1144 | |
| 1145 | pack_threadinfo_request (threadinfo_pkt, fieldset, threadid); |
| 1146 | putpkt (threadinfo_pkt); |
| 1147 | getpkt (threadinfo_pkt, 0); |
| 1148 | result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid, |
| 1149 | info); |
| 1150 | return result; |
| 1151 | } |
| 1152 | |
| 1153 | /* Unfortunately, 61 bit thread-ids are bigger than the internal |
| 1154 | representation of a threadid. */ |
| 1155 | |
| 1156 | static int |
| 1157 | adapt_remote_get_threadinfo (ref, selection, info) |
| 1158 | gdb_threadref *ref; |
| 1159 | int selection; |
| 1160 | struct gdb_ext_thread_info *info; |
| 1161 | { |
| 1162 | threadref lclref; |
| 1163 | |
| 1164 | int_to_threadref (&lclref, *ref); |
| 1165 | return remote_get_threadinfo (&lclref, selection, info); |
| 1166 | } |
| 1167 | |
| 1168 | /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */ |
| 1169 | |
| 1170 | static char * |
| 1171 | pack_threadlist_request (pkt, startflag, threadcount, nextthread) |
| 1172 | char *pkt; |
| 1173 | int startflag; |
| 1174 | int threadcount; |
| 1175 | threadref *nextthread; |
| 1176 | { |
| 1177 | *pkt++ = 'q'; /* info query packet */ |
| 1178 | *pkt++ = 'L'; /* Process LIST or threadLIST request */ |
| 1179 | pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */ |
| 1180 | pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */ |
| 1181 | pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */ |
| 1182 | *pkt = '\0'; |
| 1183 | return pkt; |
| 1184 | } |
| 1185 | |
| 1186 | /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */ |
| 1187 | |
| 1188 | static int |
| 1189 | parse_threadlist_response (pkt, result_limit, original_echo, resultlist, |
| 1190 | doneflag) |
| 1191 | char *pkt; |
| 1192 | int result_limit; |
| 1193 | threadref *original_echo; |
| 1194 | threadref *resultlist; |
| 1195 | int *doneflag; |
| 1196 | { |
| 1197 | char *limit; |
| 1198 | int count, resultcount, done; |
| 1199 | |
| 1200 | resultcount = 0; |
| 1201 | /* Assume the 'q' and 'M chars have been stripped. */ |
| 1202 | limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */ |
| 1203 | pkt = unpack_byte (pkt, &count); /* count field */ |
| 1204 | pkt = unpack_nibble (pkt, &done); |
| 1205 | /* The first threadid is the argument threadid. */ |
| 1206 | pkt = unpack_threadid (pkt, original_echo); /* should match query packet */ |
| 1207 | while ((count-- > 0) && (pkt < limit)) |
| 1208 | { |
| 1209 | pkt = unpack_threadid (pkt, resultlist++); |
| 1210 | if (resultcount++ >= result_limit) |
| 1211 | break; |
| 1212 | } |
| 1213 | if (doneflag) |
| 1214 | *doneflag = done; |
| 1215 | return resultcount; |
| 1216 | } |
| 1217 | |
| 1218 | static int |
| 1219 | remote_get_threadlist (startflag, nextthread, result_limit, |
| 1220 | done, result_count, threadlist) |
| 1221 | int startflag; |
| 1222 | threadref *nextthread; |
| 1223 | int result_limit; |
| 1224 | int *done; |
| 1225 | int *result_count; |
| 1226 | threadref *threadlist; |
| 1227 | |
| 1228 | { |
| 1229 | static threadref echo_nextthread; |
| 1230 | char *threadlist_packet = alloca (PBUFSIZ); |
| 1231 | char *t_response = alloca (PBUFSIZ); |
| 1232 | int result = 1; |
| 1233 | |
| 1234 | /* Trancate result limit to be smaller than the packet size */ |
| 1235 | if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ) |
| 1236 | result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2; |
| 1237 | |
| 1238 | pack_threadlist_request (threadlist_packet, |
| 1239 | startflag, result_limit, nextthread); |
| 1240 | putpkt (threadlist_packet); |
| 1241 | getpkt (t_response, 0); |
| 1242 | |
| 1243 | *result_count = |
| 1244 | parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread, |
| 1245 | threadlist, done); |
| 1246 | |
| 1247 | if (!threadmatch (&echo_nextthread, nextthread)) |
| 1248 | { |
| 1249 | /* FIXME: This is a good reason to drop the packet */ |
| 1250 | /* Possably, there is a duplicate response */ |
| 1251 | /* Possabilities : |
| 1252 | retransmit immediatly - race conditions |
| 1253 | retransmit after timeout - yes |
| 1254 | exit |
| 1255 | wait for packet, then exit |
| 1256 | */ |
| 1257 | warning ("HMM: threadlist did not echo arg thread, dropping it\n"); |
| 1258 | return 0; /* I choose simply exiting */ |
| 1259 | } |
| 1260 | if (*result_count <= 0) |
| 1261 | { |
| 1262 | if (*done != 1) |
| 1263 | { |
| 1264 | warning ("RMT ERROR : failed to get remote thread list\n"); |
| 1265 | result = 0; |
| 1266 | } |
| 1267 | return result; /* break; */ |
| 1268 | } |
| 1269 | if (*result_count > result_limit) |
| 1270 | { |
| 1271 | *result_count = 0; |
| 1272 | warning ("RMT ERROR: threadlist response longer than requested\n"); |
| 1273 | return 0; |
| 1274 | } |
| 1275 | return result; |
| 1276 | } |
| 1277 | |
| 1278 | /* This is the interface between remote and threads, remotes upper interface */ |
| 1279 | |
| 1280 | /* remote_find_new_threads retrieves the thread list and for each |
| 1281 | thread in the list, looks up the thread in GDB's internal list, |
| 1282 | ading the thread if it does not already exist. This involves |
| 1283 | getting partial thread lists from the remote target so, polling the |
| 1284 | quit_flag is required. */ |
| 1285 | |
| 1286 | |
| 1287 | /* About this many threadisds fit in a packet. */ |
| 1288 | |
| 1289 | #define MAXTHREADLISTRESULTS 32 |
| 1290 | |
| 1291 | static int |
| 1292 | remote_threadlist_iterator (stepfunction, context, looplimit) |
| 1293 | rmt_thread_action stepfunction; |
| 1294 | void *context; |
| 1295 | int looplimit; |
| 1296 | { |
| 1297 | int done, i, result_count; |
| 1298 | int startflag = 1; |
| 1299 | int result = 1; |
| 1300 | int loopcount = 0; |
| 1301 | static threadref nextthread; |
| 1302 | static threadref resultthreadlist[MAXTHREADLISTRESULTS]; |
| 1303 | |
| 1304 | done = 0; |
| 1305 | while (!done) |
| 1306 | { |
| 1307 | if (loopcount++ > looplimit) |
| 1308 | { |
| 1309 | result = 0; |
| 1310 | warning ("Remote fetch threadlist -infinite loop-\n"); |
| 1311 | break; |
| 1312 | } |
| 1313 | if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS, |
| 1314 | &done, &result_count, resultthreadlist)) |
| 1315 | { |
| 1316 | result = 0; |
| 1317 | break; |
| 1318 | } |
| 1319 | /* clear for later iterations */ |
| 1320 | startflag = 0; |
| 1321 | /* Setup to resume next batch of thread references, set nextthread. */ |
| 1322 | if (result_count >= 1) |
| 1323 | copy_threadref (&nextthread, &resultthreadlist[result_count - 1]); |
| 1324 | i = 0; |
| 1325 | while (result_count--) |
| 1326 | if (!(result = (*stepfunction) (&resultthreadlist[i++], context))) |
| 1327 | break; |
| 1328 | } |
| 1329 | return result; |
| 1330 | } |
| 1331 | |
| 1332 | static int |
| 1333 | remote_newthread_step (ref, context) |
| 1334 | threadref *ref; |
| 1335 | void *context; |
| 1336 | { |
| 1337 | int pid; |
| 1338 | |
| 1339 | pid = threadref_to_int (ref); |
| 1340 | if (!in_thread_list (pid)) |
| 1341 | add_thread (pid); |
| 1342 | return 1; /* continue iterator */ |
| 1343 | } |
| 1344 | |
| 1345 | #define CRAZY_MAX_THREADS 1000 |
| 1346 | |
| 1347 | static int |
| 1348 | remote_current_thread (oldpid) |
| 1349 | int oldpid; |
| 1350 | { |
| 1351 | char *buf = alloca (PBUFSIZ); |
| 1352 | |
| 1353 | putpkt ("qC"); |
| 1354 | getpkt (buf, 0); |
| 1355 | if (buf[0] == 'Q' && buf[1] == 'C') |
| 1356 | return strtol (&buf[2], NULL, 16); |
| 1357 | else |
| 1358 | return oldpid; |
| 1359 | } |
| 1360 | |
| 1361 | /* Find new threads for info threads command. */ |
| 1362 | |
| 1363 | static void |
| 1364 | remote_find_new_threads () |
| 1365 | { |
| 1366 | remote_threadlist_iterator (remote_newthread_step, 0, |
| 1367 | CRAZY_MAX_THREADS); |
| 1368 | if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */ |
| 1369 | inferior_pid = remote_current_thread (inferior_pid); |
| 1370 | } |
| 1371 | |
| 1372 | static void |
| 1373 | remote_threads_info (void) |
| 1374 | { |
| 1375 | char *buf = alloca (PBUFSIZ); |
| 1376 | char *bufp; |
| 1377 | int tid; |
| 1378 | |
| 1379 | if (remote_desc == 0) /* paranoia */ |
| 1380 | error ("Command can only be used when connected to the remote target."); |
| 1381 | |
| 1382 | putpkt ("qfThreadInfo"); |
| 1383 | getpkt (bufp = buf, 0); |
| 1384 | if (bufp[0] == '\0') /* q packet not recognized! */ |
| 1385 | { /* try old jmetzler method */ |
| 1386 | remote_find_new_threads (); |
| 1387 | return; |
| 1388 | } |
| 1389 | else /* try new 'q' method */ |
| 1390 | while (*bufp++ == 'm') /* reply contains one or more TID */ |
| 1391 | { |
| 1392 | do |
| 1393 | { |
| 1394 | tid = strtol (bufp, &bufp, 16); |
| 1395 | if (tid != 0 && !in_thread_list (tid)) |
| 1396 | add_thread (tid); |
| 1397 | } |
| 1398 | while (*bufp++ == ','); /* comma-separated list */ |
| 1399 | putpkt ("qsThreadInfo"); |
| 1400 | getpkt (bufp = buf, 0); |
| 1401 | } |
| 1402 | } |
| 1403 | \f |
| 1404 | |
| 1405 | /* Restart the remote side; this is an extended protocol operation. */ |
| 1406 | |
| 1407 | static void |
| 1408 | extended_remote_restart () |
| 1409 | { |
| 1410 | char *buf = alloca (PBUFSIZ); |
| 1411 | |
| 1412 | /* Send the restart command; for reasons I don't understand the |
| 1413 | remote side really expects a number after the "R". */ |
| 1414 | buf[0] = 'R'; |
| 1415 | sprintf (&buf[1], "%x", 0); |
| 1416 | putpkt (buf); |
| 1417 | |
| 1418 | /* Now query for status so this looks just like we restarted |
| 1419 | gdbserver from scratch. */ |
| 1420 | putpkt ("?"); |
| 1421 | getpkt (buf, 0); |
| 1422 | } |
| 1423 | \f |
| 1424 | /* Clean up connection to a remote debugger. */ |
| 1425 | |
| 1426 | /* ARGSUSED */ |
| 1427 | static void |
| 1428 | remote_close (quitting) |
| 1429 | int quitting; |
| 1430 | { |
| 1431 | if (remote_desc) |
| 1432 | SERIAL_CLOSE (remote_desc); |
| 1433 | remote_desc = NULL; |
| 1434 | } |
| 1435 | |
| 1436 | /* Query the remote side for the text, data and bss offsets. */ |
| 1437 | |
| 1438 | static void |
| 1439 | get_offsets () |
| 1440 | { |
| 1441 | char *buf = alloca (PBUFSIZ); |
| 1442 | char *ptr; |
| 1443 | int lose; |
| 1444 | CORE_ADDR text_addr, data_addr, bss_addr; |
| 1445 | struct section_offsets *offs; |
| 1446 | |
| 1447 | putpkt ("qOffsets"); |
| 1448 | |
| 1449 | getpkt (buf, 0); |
| 1450 | |
| 1451 | if (buf[0] == '\000') |
| 1452 | return; /* Return silently. Stub doesn't support |
| 1453 | this command. */ |
| 1454 | if (buf[0] == 'E') |
| 1455 | { |
| 1456 | warning ("Remote failure reply: %s", buf); |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | /* Pick up each field in turn. This used to be done with scanf, but |
| 1461 | scanf will make trouble if CORE_ADDR size doesn't match |
| 1462 | conversion directives correctly. The following code will work |
| 1463 | with any size of CORE_ADDR. */ |
| 1464 | text_addr = data_addr = bss_addr = 0; |
| 1465 | ptr = buf; |
| 1466 | lose = 0; |
| 1467 | |
| 1468 | if (strncmp (ptr, "Text=", 5) == 0) |
| 1469 | { |
| 1470 | ptr += 5; |
| 1471 | /* Don't use strtol, could lose on big values. */ |
| 1472 | while (*ptr && *ptr != ';') |
| 1473 | text_addr = (text_addr << 4) + fromhex (*ptr++); |
| 1474 | } |
| 1475 | else |
| 1476 | lose = 1; |
| 1477 | |
| 1478 | if (!lose && strncmp (ptr, ";Data=", 6) == 0) |
| 1479 | { |
| 1480 | ptr += 6; |
| 1481 | while (*ptr && *ptr != ';') |
| 1482 | data_addr = (data_addr << 4) + fromhex (*ptr++); |
| 1483 | } |
| 1484 | else |
| 1485 | lose = 1; |
| 1486 | |
| 1487 | if (!lose && strncmp (ptr, ";Bss=", 5) == 0) |
| 1488 | { |
| 1489 | ptr += 5; |
| 1490 | while (*ptr && *ptr != ';') |
| 1491 | bss_addr = (bss_addr << 4) + fromhex (*ptr++); |
| 1492 | } |
| 1493 | else |
| 1494 | lose = 1; |
| 1495 | |
| 1496 | if (lose) |
| 1497 | error ("Malformed response to offset query, %s", buf); |
| 1498 | |
| 1499 | if (symfile_objfile == NULL) |
| 1500 | return; |
| 1501 | |
| 1502 | offs = alloca (sizeof (struct section_offsets) |
| 1503 | + symfile_objfile->num_sections |
| 1504 | * sizeof (offs->offsets)); |
| 1505 | memcpy (offs, symfile_objfile->section_offsets, |
| 1506 | sizeof (struct section_offsets) |
| 1507 | + symfile_objfile->num_sections |
| 1508 | * sizeof (offs->offsets)); |
| 1509 | |
| 1510 | ANOFFSET (offs, SECT_OFF_TEXT) = text_addr; |
| 1511 | |
| 1512 | /* This is a temporary kludge to force data and bss to use the same offsets |
| 1513 | because that's what nlmconv does now. The real solution requires changes |
| 1514 | to the stub and remote.c that I don't have time to do right now. */ |
| 1515 | |
| 1516 | ANOFFSET (offs, SECT_OFF_DATA) = data_addr; |
| 1517 | ANOFFSET (offs, SECT_OFF_BSS) = data_addr; |
| 1518 | |
| 1519 | objfile_relocate (symfile_objfile, offs); |
| 1520 | } |
| 1521 | |
| 1522 | /* |
| 1523 | * Cisco version of section offsets: |
| 1524 | * |
| 1525 | * Instead of having GDB query the target for the section offsets, |
| 1526 | * Cisco lets the target volunteer the information! It's also in |
| 1527 | * a different format, so here are the functions that will decode |
| 1528 | * a section offset packet from a Cisco target. |
| 1529 | */ |
| 1530 | |
| 1531 | /* |
| 1532 | * Function: remote_cisco_section_offsets |
| 1533 | * |
| 1534 | * Returns: zero for success, non-zero for failure |
| 1535 | */ |
| 1536 | |
| 1537 | static int |
| 1538 | remote_cisco_section_offsets (text_addr, data_addr, bss_addr, |
| 1539 | text_offs, data_offs, bss_offs) |
| 1540 | bfd_vma text_addr; |
| 1541 | bfd_vma data_addr; |
| 1542 | bfd_vma bss_addr; |
| 1543 | bfd_signed_vma *text_offs; |
| 1544 | bfd_signed_vma *data_offs; |
| 1545 | bfd_signed_vma *bss_offs; |
| 1546 | { |
| 1547 | bfd_vma text_base, data_base, bss_base; |
| 1548 | struct minimal_symbol *start; |
| 1549 | asection *sect; |
| 1550 | bfd *abfd; |
| 1551 | int len; |
| 1552 | char *p; |
| 1553 | |
| 1554 | if (symfile_objfile == NULL) |
| 1555 | return -1; /* no can do nothin' */ |
| 1556 | |
| 1557 | start = lookup_minimal_symbol ("_start", NULL, NULL); |
| 1558 | if (start == NULL) |
| 1559 | return -1; /* Can't find "_start" symbol */ |
| 1560 | |
| 1561 | data_base = bss_base = 0; |
| 1562 | text_base = SYMBOL_VALUE_ADDRESS (start); |
| 1563 | |
| 1564 | abfd = symfile_objfile->obfd; |
| 1565 | for (sect = abfd->sections; |
| 1566 | sect != 0; |
| 1567 | sect = sect->next) |
| 1568 | { |
| 1569 | p = (unsigned char *) bfd_get_section_name (abfd, sect); |
| 1570 | len = strlen (p); |
| 1571 | if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */ |
| 1572 | if (data_base == 0 || |
| 1573 | data_base > bfd_get_section_vma (abfd, sect)) |
| 1574 | data_base = bfd_get_section_vma (abfd, sect); |
| 1575 | if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */ |
| 1576 | if (bss_base == 0 || |
| 1577 | bss_base > bfd_get_section_vma (abfd, sect)) |
| 1578 | bss_base = bfd_get_section_vma (abfd, sect); |
| 1579 | } |
| 1580 | *text_offs = text_addr - text_base; |
| 1581 | *data_offs = data_addr - data_base; |
| 1582 | *bss_offs = bss_addr - bss_base; |
| 1583 | if (remote_debug) |
| 1584 | { |
| 1585 | char tmp[128]; |
| 1586 | |
| 1587 | sprintf (tmp, "VMA: text = 0x"); |
| 1588 | sprintf_vma (tmp + strlen (tmp), text_addr); |
| 1589 | sprintf (tmp + strlen (tmp), " data = 0x"); |
| 1590 | sprintf_vma (tmp + strlen (tmp), data_addr); |
| 1591 | sprintf (tmp + strlen (tmp), " bss = 0x"); |
| 1592 | sprintf_vma (tmp + strlen (tmp), bss_addr); |
| 1593 | fprintf_filtered (gdb_stdlog, tmp); |
| 1594 | fprintf_filtered (gdb_stdlog, |
| 1595 | "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n", |
| 1596 | (long) *text_offs, (long) *data_offs, (long) *bss_offs); |
| 1597 | } |
| 1598 | |
| 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | /* |
| 1603 | * Function: remote_cisco_objfile_relocate |
| 1604 | * |
| 1605 | * Relocate the symbol file for a remote target. |
| 1606 | */ |
| 1607 | |
| 1608 | void |
| 1609 | remote_cisco_objfile_relocate (text_off, data_off, bss_off) |
| 1610 | bfd_signed_vma text_off; |
| 1611 | bfd_signed_vma data_off; |
| 1612 | bfd_signed_vma bss_off; |
| 1613 | { |
| 1614 | struct section_offsets *offs; |
| 1615 | |
| 1616 | if (text_off != 0 || data_off != 0 || bss_off != 0) |
| 1617 | { |
| 1618 | /* FIXME: This code assumes gdb-stabs.h is being used; it's |
| 1619 | broken for xcoff, dwarf, sdb-coff, etc. But there is no |
| 1620 | simple canonical representation for this stuff. */ |
| 1621 | |
| 1622 | offs = ((struct section_offsets *) |
| 1623 | alloca (sizeof (struct section_offsets) |
| 1624 | + (symfile_objfile->num_sections |
| 1625 | * sizeof (offs->offsets)))); |
| 1626 | |
| 1627 | memcpy (offs, symfile_objfile->section_offsets, |
| 1628 | (sizeof (struct section_offsets) |
| 1629 | + (symfile_objfile->num_sections |
| 1630 | * sizeof (offs->offsets)))); |
| 1631 | |
| 1632 | ANOFFSET (offs, SECT_OFF_TEXT) = text_off; |
| 1633 | ANOFFSET (offs, SECT_OFF_DATA) = data_off; |
| 1634 | ANOFFSET (offs, SECT_OFF_BSS) = bss_off; |
| 1635 | |
| 1636 | /* First call the standard objfile_relocate. */ |
| 1637 | objfile_relocate (symfile_objfile, offs); |
| 1638 | |
| 1639 | /* Now we need to fix up the section entries already attached to |
| 1640 | the exec target. These entries will control memory transfers |
| 1641 | from the exec file. */ |
| 1642 | |
| 1643 | exec_set_section_offsets (text_off, data_off, bss_off); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | /* Stub for catch_errors. */ |
| 1648 | |
| 1649 | static int |
| 1650 | remote_start_remote_dummy (dummy) |
| 1651 | char *dummy; |
| 1652 | { |
| 1653 | start_remote (); /* Initialize gdb process mechanisms */ |
| 1654 | return 1; |
| 1655 | } |
| 1656 | |
| 1657 | static int |
| 1658 | remote_start_remote (dummy) |
| 1659 | PTR dummy; |
| 1660 | { |
| 1661 | immediate_quit = 1; /* Allow user to interrupt it */ |
| 1662 | |
| 1663 | /* Ack any packet which the remote side has already sent. */ |
| 1664 | SERIAL_WRITE (remote_desc, "+", 1); |
| 1665 | |
| 1666 | /* Let the stub know that we want it to return the thread. */ |
| 1667 | set_thread (-1, 0); |
| 1668 | |
| 1669 | inferior_pid = remote_current_thread (inferior_pid); |
| 1670 | |
| 1671 | get_offsets (); /* Get text, data & bss offsets */ |
| 1672 | |
| 1673 | putpkt ("?"); /* initiate a query from remote machine */ |
| 1674 | immediate_quit = 0; |
| 1675 | |
| 1676 | return remote_start_remote_dummy (dummy); |
| 1677 | } |
| 1678 | |
| 1679 | /* Open a connection to a remote debugger. |
| 1680 | NAME is the filename used for communication. */ |
| 1681 | |
| 1682 | static void |
| 1683 | remote_open (name, from_tty) |
| 1684 | char *name; |
| 1685 | int from_tty; |
| 1686 | { |
| 1687 | remote_open_1 (name, from_tty, &remote_ops, 0); |
| 1688 | } |
| 1689 | |
| 1690 | /* Just like remote_open, but with asynchronous support. */ |
| 1691 | static void |
| 1692 | remote_async_open (name, from_tty) |
| 1693 | char *name; |
| 1694 | int from_tty; |
| 1695 | { |
| 1696 | remote_async_open_1 (name, from_tty, &remote_async_ops, 0); |
| 1697 | } |
| 1698 | |
| 1699 | /* Open a connection to a remote debugger using the extended |
| 1700 | remote gdb protocol. NAME is the filename used for communication. */ |
| 1701 | |
| 1702 | static void |
| 1703 | extended_remote_open (name, from_tty) |
| 1704 | char *name; |
| 1705 | int from_tty; |
| 1706 | { |
| 1707 | remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ ); |
| 1708 | } |
| 1709 | |
| 1710 | /* Just like extended_remote_open, but with asynchronous support. */ |
| 1711 | static void |
| 1712 | extended_remote_async_open (name, from_tty) |
| 1713 | char *name; |
| 1714 | int from_tty; |
| 1715 | { |
| 1716 | remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ ); |
| 1717 | } |
| 1718 | |
| 1719 | /* Generic code for opening a connection to a remote target. */ |
| 1720 | |
| 1721 | static DCACHE *remote_dcache; |
| 1722 | |
| 1723 | static void |
| 1724 | remote_open_1 (name, from_tty, target, extended_p) |
| 1725 | char *name; |
| 1726 | int from_tty; |
| 1727 | struct target_ops *target; |
| 1728 | int extended_p; |
| 1729 | { |
| 1730 | if (name == 0) |
| 1731 | error ("To open a remote debug connection, you need to specify what\n\ |
| 1732 | serial device is attached to the remote system (e.g. /dev/ttya)."); |
| 1733 | |
| 1734 | target_preopen (from_tty); |
| 1735 | |
| 1736 | unpush_target (target); |
| 1737 | |
| 1738 | remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes); |
| 1739 | |
| 1740 | remote_desc = SERIAL_OPEN (name); |
| 1741 | if (!remote_desc) |
| 1742 | perror_with_name (name); |
| 1743 | |
| 1744 | if (baud_rate != -1) |
| 1745 | { |
| 1746 | if (SERIAL_SETBAUDRATE (remote_desc, baud_rate)) |
| 1747 | { |
| 1748 | SERIAL_CLOSE (remote_desc); |
| 1749 | perror_with_name (name); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | SERIAL_RAW (remote_desc); |
| 1754 | |
| 1755 | /* If there is something sitting in the buffer we might take it as a |
| 1756 | response to a command, which would be bad. */ |
| 1757 | SERIAL_FLUSH_INPUT (remote_desc); |
| 1758 | |
| 1759 | if (from_tty) |
| 1760 | { |
| 1761 | puts_filtered ("Remote debugging using "); |
| 1762 | puts_filtered (name); |
| 1763 | puts_filtered ("\n"); |
| 1764 | } |
| 1765 | push_target (target); /* Switch to using remote target now */ |
| 1766 | |
| 1767 | init_packet_config (&remote_protocol_P); |
| 1768 | init_packet_config (&remote_protocol_Z); |
| 1769 | |
| 1770 | general_thread = -2; |
| 1771 | continue_thread = -2; |
| 1772 | |
| 1773 | /* Force remote_write_bytes to check whether target supports |
| 1774 | binary downloading. */ |
| 1775 | init_packet_config (&remote_protocol_binary_download); |
| 1776 | |
| 1777 | /* Without this, some commands which require an active target (such |
| 1778 | as kill) won't work. This variable serves (at least) double duty |
| 1779 | as both the pid of the target process (if it has such), and as a |
| 1780 | flag indicating that a target is active. These functions should |
| 1781 | be split out into seperate variables, especially since GDB will |
| 1782 | someday have a notion of debugging several processes. */ |
| 1783 | |
| 1784 | inferior_pid = MAGIC_NULL_PID; |
| 1785 | /* Start the remote connection; if error (0), discard this target. |
| 1786 | In particular, if the user quits, be sure to discard it |
| 1787 | (we'd be in an inconsistent state otherwise). */ |
| 1788 | if (!catch_errors (remote_start_remote, NULL, |
| 1789 | "Couldn't establish connection to remote target\n", |
| 1790 | RETURN_MASK_ALL)) |
| 1791 | { |
| 1792 | pop_target (); |
| 1793 | return; |
| 1794 | } |
| 1795 | |
| 1796 | if (extended_p) |
| 1797 | { |
| 1798 | /* tell the remote that we're using the extended protocol. */ |
| 1799 | char *buf = alloca (PBUFSIZ); |
| 1800 | putpkt ("!"); |
| 1801 | getpkt (buf, 0); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | /* Just like remote_open but with asynchronous support. */ |
| 1806 | static void |
| 1807 | remote_async_open_1 (name, from_tty, target, extended_p) |
| 1808 | char *name; |
| 1809 | int from_tty; |
| 1810 | struct target_ops *target; |
| 1811 | int extended_p; |
| 1812 | { |
| 1813 | if (name == 0) |
| 1814 | error ("To open a remote debug connection, you need to specify what\n\ |
| 1815 | serial device is attached to the remote system (e.g. /dev/ttya)."); |
| 1816 | |
| 1817 | target_preopen (from_tty); |
| 1818 | |
| 1819 | unpush_target (target); |
| 1820 | |
| 1821 | remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes); |
| 1822 | |
| 1823 | remote_desc = SERIAL_OPEN (name); |
| 1824 | if (!remote_desc) |
| 1825 | perror_with_name (name); |
| 1826 | |
| 1827 | if (baud_rate != -1) |
| 1828 | { |
| 1829 | if (SERIAL_SETBAUDRATE (remote_desc, baud_rate)) |
| 1830 | { |
| 1831 | SERIAL_CLOSE (remote_desc); |
| 1832 | perror_with_name (name); |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | SERIAL_RAW (remote_desc); |
| 1837 | |
| 1838 | /* If there is something sitting in the buffer we might take it as a |
| 1839 | response to a command, which would be bad. */ |
| 1840 | SERIAL_FLUSH_INPUT (remote_desc); |
| 1841 | |
| 1842 | if (from_tty) |
| 1843 | { |
| 1844 | puts_filtered ("Remote debugging using "); |
| 1845 | puts_filtered (name); |
| 1846 | puts_filtered ("\n"); |
| 1847 | } |
| 1848 | |
| 1849 | /* If running in asynchronous mode, register the target with the |
| 1850 | event loop. Set things up so that when there is an event on the |
| 1851 | file descriptor, the event loop will call fetch_inferior_event, |
| 1852 | which will do the proper analysis to determine what happened. */ |
| 1853 | if (async_p) |
| 1854 | add_file_handler (remote_desc->fd, fetch_inferior_event, 0); |
| 1855 | |
| 1856 | push_target (target); /* Switch to using remote target now */ |
| 1857 | |
| 1858 | init_packet_config (&remote_protocol_P); |
| 1859 | init_packet_config (&remote_protocol_Z); |
| 1860 | |
| 1861 | general_thread = -2; |
| 1862 | continue_thread = -2; |
| 1863 | |
| 1864 | /* Force remote_write_bytes to check whether target supports |
| 1865 | binary downloading. */ |
| 1866 | init_packet_config (&remote_protocol_binary_download); |
| 1867 | |
| 1868 | /* If running asynchronously, set things up for telling the target |
| 1869 | to use the extended protocol. This will happen only after the |
| 1870 | target has been connected to, in fetch_inferior_event. */ |
| 1871 | if (extended_p && async_p) |
| 1872 | add_continuation (set_extended_protocol, NULL); |
| 1873 | |
| 1874 | /* Without this, some commands which require an active target (such |
| 1875 | as kill) won't work. This variable serves (at least) double duty |
| 1876 | as both the pid of the target process (if it has such), and as a |
| 1877 | flag indicating that a target is active. These functions should |
| 1878 | be split out into seperate variables, especially since GDB will |
| 1879 | someday have a notion of debugging several processes. */ |
| 1880 | |
| 1881 | inferior_pid = MAGIC_NULL_PID; |
| 1882 | /* Start the remote connection; if error (0), discard this target. |
| 1883 | In particular, if the user quits, be sure to discard it |
| 1884 | (we'd be in an inconsistent state otherwise). */ |
| 1885 | if (!catch_errors (remote_start_remote, NULL, |
| 1886 | "Couldn't establish connection to remote target\n", |
| 1887 | RETURN_MASK_ALL)) |
| 1888 | { |
| 1889 | /* Unregister the file descriptor from the event loop. */ |
| 1890 | if (async_p) |
| 1891 | delete_file_handler (remote_desc->fd); |
| 1892 | pop_target (); |
| 1893 | return; |
| 1894 | } |
| 1895 | |
| 1896 | if (!async_p) |
| 1897 | { |
| 1898 | if (extended_p) |
| 1899 | { |
| 1900 | /* tell the remote that we're using the extended protocol. */ |
| 1901 | char *buf = alloca (PBUFSIZ); |
| 1902 | putpkt ("!"); |
| 1903 | getpkt (buf, 0); |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | /* This will be called by fetch_inferior_event, via the |
| 1909 | cmd_continuation pointer, only after the target has stopped. */ |
| 1910 | static void |
| 1911 | set_extended_protocol (arg) |
| 1912 | struct continuation_arg *arg; |
| 1913 | { |
| 1914 | /* tell the remote that we're using the extended protocol. */ |
| 1915 | char *buf = alloca (PBUFSIZ); |
| 1916 | putpkt ("!"); |
| 1917 | getpkt (buf, 0); |
| 1918 | } |
| 1919 | |
| 1920 | /* This takes a program previously attached to and detaches it. After |
| 1921 | this is done, GDB can be used to debug some other program. We |
| 1922 | better not have left any breakpoints in the target program or it'll |
| 1923 | die when it hits one. */ |
| 1924 | |
| 1925 | static void |
| 1926 | remote_detach (args, from_tty) |
| 1927 | char *args; |
| 1928 | int from_tty; |
| 1929 | { |
| 1930 | char *buf = alloca (PBUFSIZ); |
| 1931 | |
| 1932 | if (args) |
| 1933 | error ("Argument given to \"detach\" when remotely debugging."); |
| 1934 | |
| 1935 | /* Tell the remote target to detach. */ |
| 1936 | strcpy (buf, "D"); |
| 1937 | remote_send (buf); |
| 1938 | |
| 1939 | pop_target (); |
| 1940 | if (from_tty) |
| 1941 | puts_filtered ("Ending remote debugging.\n"); |
| 1942 | |
| 1943 | } |
| 1944 | |
| 1945 | /* Same as remote_detach, but with async support. */ |
| 1946 | static void |
| 1947 | remote_async_detach (args, from_tty) |
| 1948 | char *args; |
| 1949 | int from_tty; |
| 1950 | { |
| 1951 | char *buf = alloca (PBUFSIZ); |
| 1952 | |
| 1953 | if (args) |
| 1954 | error ("Argument given to \"detach\" when remotely debugging."); |
| 1955 | |
| 1956 | /* Tell the remote target to detach. */ |
| 1957 | strcpy (buf, "D"); |
| 1958 | remote_send (buf); |
| 1959 | |
| 1960 | /* Unregister the file descriptor from the event loop. */ |
| 1961 | if (async_p) |
| 1962 | delete_file_handler (remote_desc->fd); |
| 1963 | |
| 1964 | pop_target (); |
| 1965 | if (from_tty) |
| 1966 | puts_filtered ("Ending remote debugging.\n"); |
| 1967 | } |
| 1968 | |
| 1969 | /* Convert hex digit A to a number. */ |
| 1970 | |
| 1971 | int |
| 1972 | fromhex (a) |
| 1973 | int a; |
| 1974 | { |
| 1975 | if (a >= '0' && a <= '9') |
| 1976 | return a - '0'; |
| 1977 | else if (a >= 'a' && a <= 'f') |
| 1978 | return a - 'a' + 10; |
| 1979 | else if (a >= 'A' && a <= 'F') |
| 1980 | return a - 'A' + 10; |
| 1981 | else |
| 1982 | error ("Reply contains invalid hex digit %d", a); |
| 1983 | } |
| 1984 | |
| 1985 | /* Convert number NIB to a hex digit. */ |
| 1986 | |
| 1987 | static int |
| 1988 | tohex (nib) |
| 1989 | int nib; |
| 1990 | { |
| 1991 | if (nib < 10) |
| 1992 | return '0' + nib; |
| 1993 | else |
| 1994 | return 'a' + nib - 10; |
| 1995 | } |
| 1996 | \f |
| 1997 | /* Tell the remote machine to resume. */ |
| 1998 | |
| 1999 | static enum target_signal last_sent_signal = TARGET_SIGNAL_0; |
| 2000 | |
| 2001 | static int last_sent_step; |
| 2002 | |
| 2003 | static void |
| 2004 | remote_resume (pid, step, siggnal) |
| 2005 | int pid, step; |
| 2006 | enum target_signal siggnal; |
| 2007 | { |
| 2008 | char *buf = alloca (PBUFSIZ); |
| 2009 | |
| 2010 | if (pid == -1) |
| 2011 | set_thread (0, 0); /* run any thread */ |
| 2012 | else |
| 2013 | set_thread (pid, 0); /* run this thread */ |
| 2014 | |
| 2015 | dcache_flush (remote_dcache); |
| 2016 | |
| 2017 | last_sent_signal = siggnal; |
| 2018 | last_sent_step = step; |
| 2019 | |
| 2020 | /* A hook for when we need to do something at the last moment before |
| 2021 | resumption. */ |
| 2022 | if (target_resume_hook) |
| 2023 | (*target_resume_hook) (); |
| 2024 | |
| 2025 | if (siggnal != TARGET_SIGNAL_0) |
| 2026 | { |
| 2027 | buf[0] = step ? 'S' : 'C'; |
| 2028 | buf[1] = tohex (((int) siggnal >> 4) & 0xf); |
| 2029 | buf[2] = tohex ((int) siggnal & 0xf); |
| 2030 | buf[3] = '\0'; |
| 2031 | } |
| 2032 | else |
| 2033 | strcpy (buf, step ? "s" : "c"); |
| 2034 | |
| 2035 | putpkt (buf); |
| 2036 | } |
| 2037 | |
| 2038 | /* Same as remote_resume, but with async support. */ |
| 2039 | static void |
| 2040 | remote_async_resume (pid, step, siggnal) |
| 2041 | int pid, step; |
| 2042 | enum target_signal siggnal; |
| 2043 | { |
| 2044 | char *buf = alloca (PBUFSIZ); |
| 2045 | |
| 2046 | if (pid == -1) |
| 2047 | set_thread (0, 0); /* run any thread */ |
| 2048 | else |
| 2049 | set_thread (pid, 0); /* run this thread */ |
| 2050 | |
| 2051 | dcache_flush (remote_dcache); |
| 2052 | |
| 2053 | last_sent_signal = siggnal; |
| 2054 | last_sent_step = step; |
| 2055 | |
| 2056 | /* A hook for when we need to do something at the last moment before |
| 2057 | resumption. */ |
| 2058 | if (target_resume_hook) |
| 2059 | (*target_resume_hook) (); |
| 2060 | |
| 2061 | /* Set things up before execution starts for async commands. */ |
| 2062 | /* This function can be entered more than once for the same execution |
| 2063 | command, because it is also called by handle_inferior_event. So |
| 2064 | we make sure that we don't do the initialization for sync |
| 2065 | execution more than once. */ |
| 2066 | if (async_p && !target_executing) |
| 2067 | { |
| 2068 | target_executing = 1; |
| 2069 | |
| 2070 | /* If the command must look synchronous, fake it, by making gdb |
| 2071 | display an empty prompt after the command has completed. Also |
| 2072 | disable input. */ |
| 2073 | if (sync_execution) |
| 2074 | { |
| 2075 | push_prompt ("", "", ""); |
| 2076 | delete_file_handler (input_fd); |
| 2077 | initialize_sigint_signal_handler (); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | if (siggnal != TARGET_SIGNAL_0) |
| 2082 | { |
| 2083 | buf[0] = step ? 'S' : 'C'; |
| 2084 | buf[1] = tohex (((int) siggnal >> 4) & 0xf); |
| 2085 | buf[2] = tohex ((int) siggnal & 0xf); |
| 2086 | buf[3] = '\0'; |
| 2087 | } |
| 2088 | else |
| 2089 | strcpy (buf, step ? "s" : "c"); |
| 2090 | |
| 2091 | putpkt (buf); |
| 2092 | } |
| 2093 | \f |
| 2094 | |
| 2095 | /* Set up the signal handler for SIGINT, while the target is |
| 2096 | executing, ovewriting the 'regular' SIGINT signal handler. */ |
| 2097 | static void |
| 2098 | initialize_sigint_signal_handler () |
| 2099 | { |
| 2100 | sigint_remote_token = |
| 2101 | create_async_signal_handler (async_remote_interrupt, NULL); |
| 2102 | signal (SIGINT, handle_remote_sigint); |
| 2103 | } |
| 2104 | |
| 2105 | /* Signal handler for SIGINT, while the target is executing. */ |
| 2106 | static void |
| 2107 | handle_remote_sigint (sig) |
| 2108 | int sig; |
| 2109 | { |
| 2110 | signal (sig, handle_remote_sigint_twice); |
| 2111 | sigint_remote_twice_token = |
| 2112 | create_async_signal_handler (async_remote_interrupt_twice, NULL); |
| 2113 | mark_async_signal_handler_wrapper (sigint_remote_token); |
| 2114 | } |
| 2115 | |
| 2116 | /* Signal handler for SIGINT, installed after SIGINT has already been |
| 2117 | sent once. It will take effect the second time that the user sends |
| 2118 | a ^C. */ |
| 2119 | static void |
| 2120 | handle_remote_sigint_twice (sig) |
| 2121 | int sig; |
| 2122 | { |
| 2123 | signal (sig, handle_sigint); |
| 2124 | sigint_remote_twice_token = |
| 2125 | create_async_signal_handler (async_remote_interrupt, NULL); |
| 2126 | mark_async_signal_handler_wrapper (sigint_remote_twice_token); |
| 2127 | } |
| 2128 | |
| 2129 | /* Perform the real interruption of hte target execution, in response |
| 2130 | to a ^C. */ |
| 2131 | static void |
| 2132 | async_remote_interrupt (arg) |
| 2133 | gdb_client_data arg; |
| 2134 | { |
| 2135 | if (remote_debug) |
| 2136 | fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n"); |
| 2137 | |
| 2138 | target_stop (); |
| 2139 | } |
| 2140 | |
| 2141 | /* Perform interrupt, if the first attempt did not succeed. Just give |
| 2142 | up on the target alltogether. */ |
| 2143 | static void |
| 2144 | async_remote_interrupt_twice (arg) |
| 2145 | gdb_client_data arg; |
| 2146 | { |
| 2147 | interrupt_query (); |
| 2148 | signal (SIGINT, handle_remote_sigint); |
| 2149 | } |
| 2150 | |
| 2151 | /* Reinstall the usual SIGINT handlers, after the target has |
| 2152 | stopped. */ |
| 2153 | void |
| 2154 | cleanup_sigint_signal_handler () |
| 2155 | { |
| 2156 | signal (SIGINT, handle_sigint); |
| 2157 | if (sigint_remote_twice_token) |
| 2158 | delete_async_signal_handler ((async_signal_handler **) & sigint_remote_twice_token); |
| 2159 | if (sigint_remote_token) |
| 2160 | delete_async_signal_handler ((async_signal_handler **) & sigint_remote_token); |
| 2161 | } |
| 2162 | |
| 2163 | /* Send ^C to target to halt it. Target will respond, and send us a |
| 2164 | packet. */ |
| 2165 | static void (*ofunc) PARAMS ((int)); |
| 2166 | |
| 2167 | /* The command line interface's stop routine. This function is installed |
| 2168 | as a signal handler for SIGINT. The first time a user requests a |
| 2169 | stop, we call remote_stop to send a break or ^C. If there is no |
| 2170 | response from the target (it didn't stop when the user requested it), |
| 2171 | we ask the user if he'd like to detach from the target. */ |
| 2172 | static void |
| 2173 | remote_interrupt (signo) |
| 2174 | int signo; |
| 2175 | { |
| 2176 | /* If this doesn't work, try more severe steps. */ |
| 2177 | signal (signo, remote_interrupt_twice); |
| 2178 | |
| 2179 | if (remote_debug) |
| 2180 | fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n"); |
| 2181 | |
| 2182 | target_stop (); |
| 2183 | } |
| 2184 | |
| 2185 | /* The user typed ^C twice. */ |
| 2186 | |
| 2187 | static void |
| 2188 | remote_interrupt_twice (signo) |
| 2189 | int signo; |
| 2190 | { |
| 2191 | signal (signo, ofunc); |
| 2192 | interrupt_query (); |
| 2193 | signal (signo, remote_interrupt); |
| 2194 | } |
| 2195 | |
| 2196 | /* This is the generic stop called via the target vector. When a target |
| 2197 | interrupt is requested, either by the command line or the GUI, we |
| 2198 | will eventually end up here. */ |
| 2199 | static void |
| 2200 | remote_stop () |
| 2201 | { |
| 2202 | /* Send a break or a ^C, depending on user preference. */ |
| 2203 | if (remote_debug) |
| 2204 | fprintf_unfiltered (gdb_stdlog, "remote_stop called\n"); |
| 2205 | |
| 2206 | if (remote_break) |
| 2207 | SERIAL_SEND_BREAK (remote_desc); |
| 2208 | else |
| 2209 | SERIAL_WRITE (remote_desc, "\003", 1); |
| 2210 | } |
| 2211 | |
| 2212 | /* Ask the user what to do when an interrupt is received. */ |
| 2213 | |
| 2214 | static void |
| 2215 | interrupt_query () |
| 2216 | { |
| 2217 | target_terminal_ours (); |
| 2218 | |
| 2219 | if (query ("Interrupted while waiting for the program.\n\ |
| 2220 | Give up (and stop debugging it)? ")) |
| 2221 | { |
| 2222 | target_mourn_inferior (); |
| 2223 | return_to_top_level (RETURN_QUIT); |
| 2224 | } |
| 2225 | |
| 2226 | target_terminal_inferior (); |
| 2227 | } |
| 2228 | |
| 2229 | /* If nonzero, ignore the next kill. */ |
| 2230 | |
| 2231 | int kill_kludge; |
| 2232 | |
| 2233 | void |
| 2234 | remote_console_output (msg) |
| 2235 | char *msg; |
| 2236 | { |
| 2237 | char *p; |
| 2238 | |
| 2239 | for (p = msg; p[0] && p[1]; p += 2) |
| 2240 | { |
| 2241 | char tb[2]; |
| 2242 | char c = fromhex (p[0]) * 16 + fromhex (p[1]); |
| 2243 | tb[0] = c; |
| 2244 | tb[1] = 0; |
| 2245 | fputs_unfiltered (tb, gdb_stdtarg); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | /* Wait until the remote machine stops, then return, |
| 2250 | storing status in STATUS just as `wait' would. |
| 2251 | Returns "pid", which in the case of a multi-threaded |
| 2252 | remote OS, is the thread-id. */ |
| 2253 | |
| 2254 | static int |
| 2255 | remote_wait (pid, status) |
| 2256 | int pid; |
| 2257 | struct target_waitstatus *status; |
| 2258 | { |
| 2259 | unsigned char *buf = alloca (PBUFSIZ); |
| 2260 | int thread_num = -1; |
| 2261 | |
| 2262 | status->kind = TARGET_WAITKIND_EXITED; |
| 2263 | status->value.integer = 0; |
| 2264 | |
| 2265 | while (1) |
| 2266 | { |
| 2267 | unsigned char *p; |
| 2268 | |
| 2269 | ofunc = signal (SIGINT, remote_interrupt); |
| 2270 | getpkt ((char *) buf, 1); |
| 2271 | signal (SIGINT, ofunc); |
| 2272 | |
| 2273 | /* This is a hook for when we need to do something (perhaps the |
| 2274 | collection of trace data) every time the target stops. */ |
| 2275 | if (target_wait_loop_hook) |
| 2276 | (*target_wait_loop_hook) (); |
| 2277 | |
| 2278 | switch (buf[0]) |
| 2279 | { |
| 2280 | case 'E': /* Error of some sort */ |
| 2281 | warning ("Remote failure reply: %s", buf); |
| 2282 | continue; |
| 2283 | case 'T': /* Status with PC, SP, FP, ... */ |
| 2284 | { |
| 2285 | int i; |
| 2286 | long regno; |
| 2287 | char regs[MAX_REGISTER_RAW_SIZE]; |
| 2288 | |
| 2289 | /* Expedited reply, containing Signal, {regno, reg} repeat */ |
| 2290 | /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where |
| 2291 | ss = signal number |
| 2292 | n... = register number |
| 2293 | r... = register contents |
| 2294 | */ |
| 2295 | p = &buf[3]; /* after Txx */ |
| 2296 | |
| 2297 | while (*p) |
| 2298 | { |
| 2299 | unsigned char *p1; |
| 2300 | char *p_temp; |
| 2301 | |
| 2302 | /* Read the register number */ |
| 2303 | regno = strtol ((const char *) p, &p_temp, 16); |
| 2304 | p1 = (unsigned char *) p_temp; |
| 2305 | |
| 2306 | if (p1 == p) /* No register number present here */ |
| 2307 | { |
| 2308 | p1 = (unsigned char *) strchr ((const char *) p, ':'); |
| 2309 | if (p1 == NULL) |
| 2310 | warning ("Malformed packet(a) (missing colon): %s\n\ |
| 2311 | Packet: '%s'\n", |
| 2312 | p, buf); |
| 2313 | if (strncmp ((const char *) p, "thread", p1 - p) == 0) |
| 2314 | { |
| 2315 | p_temp = unpack_varlen_hex (++p1, &thread_num); |
| 2316 | record_currthread (thread_num); |
| 2317 | p = (unsigned char *) p_temp; |
| 2318 | } |
| 2319 | } |
| 2320 | else |
| 2321 | { |
| 2322 | p = p1; |
| 2323 | |
| 2324 | if (*p++ != ':') |
| 2325 | warning ("Malformed packet(b) (missing colon): %s\n\ |
| 2326 | Packet: '%s'\n", |
| 2327 | p, buf); |
| 2328 | |
| 2329 | if (regno >= NUM_REGS) |
| 2330 | warning ("Remote sent bad register number %ld: %s\n\ |
| 2331 | Packet: '%s'\n", |
| 2332 | regno, p, buf); |
| 2333 | |
| 2334 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i++) |
| 2335 | { |
| 2336 | if (p[0] == 0 || p[1] == 0) |
| 2337 | warning ("Remote reply is too short: %s", buf); |
| 2338 | regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]); |
| 2339 | p += 2; |
| 2340 | } |
| 2341 | supply_register (regno, regs); |
| 2342 | } |
| 2343 | |
| 2344 | if (*p++ != ';') |
| 2345 | { |
| 2346 | warning ("Remote register badly formatted: %s", buf); |
| 2347 | warning (" here: %s", p); |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | /* fall through */ |
| 2352 | case 'S': /* Old style status, just signal only */ |
| 2353 | status->kind = TARGET_WAITKIND_STOPPED; |
| 2354 | status->value.sig = (enum target_signal) |
| 2355 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2356 | |
| 2357 | if (buf[3] == 'p') |
| 2358 | { |
| 2359 | /* Export Cisco kernel mode as a convenience variable |
| 2360 | (so that it can be used in the GDB prompt if desired). */ |
| 2361 | |
| 2362 | if (cisco_kernel_mode == 1) |
| 2363 | set_internalvar (lookup_internalvar ("cisco_kernel_mode"), |
| 2364 | value_from_string ("PDEBUG-")); |
| 2365 | cisco_kernel_mode = 0; |
| 2366 | thread_num = strtol ((const char *) &buf[4], NULL, 16); |
| 2367 | record_currthread (thread_num); |
| 2368 | } |
| 2369 | else if (buf[3] == 'k') |
| 2370 | { |
| 2371 | /* Export Cisco kernel mode as a convenience variable |
| 2372 | (so that it can be used in the GDB prompt if desired). */ |
| 2373 | |
| 2374 | if (cisco_kernel_mode == 1) |
| 2375 | set_internalvar (lookup_internalvar ("cisco_kernel_mode"), |
| 2376 | value_from_string ("KDEBUG-")); |
| 2377 | cisco_kernel_mode = 1; |
| 2378 | } |
| 2379 | goto got_status; |
| 2380 | case 'N': /* Cisco special: status and offsets */ |
| 2381 | { |
| 2382 | bfd_vma text_addr, data_addr, bss_addr; |
| 2383 | bfd_signed_vma text_off, data_off, bss_off; |
| 2384 | unsigned char *p1; |
| 2385 | |
| 2386 | status->kind = TARGET_WAITKIND_STOPPED; |
| 2387 | status->value.sig = (enum target_signal) |
| 2388 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2389 | |
| 2390 | if (symfile_objfile == NULL) |
| 2391 | { |
| 2392 | warning ("Relocation packet recieved with no symbol file. \ |
| 2393 | Packet Dropped"); |
| 2394 | goto got_status; |
| 2395 | } |
| 2396 | |
| 2397 | /* Relocate object file. Buffer format is NAATT;DD;BB |
| 2398 | * where AA is the signal number, TT is the new text |
| 2399 | * address, DD * is the new data address, and BB is the |
| 2400 | * new bss address. */ |
| 2401 | |
| 2402 | p = &buf[3]; |
| 2403 | text_addr = strtoul (p, (char **) &p1, 16); |
| 2404 | if (p1 == p || *p1 != ';') |
| 2405 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2406 | p = p1 + 1; |
| 2407 | data_addr = strtoul (p, (char **) &p1, 16); |
| 2408 | if (p1 == p || *p1 != ';') |
| 2409 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2410 | p = p1 + 1; |
| 2411 | bss_addr = strtoul (p, (char **) &p1, 16); |
| 2412 | if (p1 == p) |
| 2413 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2414 | |
| 2415 | if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr, |
| 2416 | &text_off, &data_off, &bss_off) |
| 2417 | == 0) |
| 2418 | if (text_off != 0 || data_off != 0 || bss_off != 0) |
| 2419 | remote_cisco_objfile_relocate (text_off, data_off, bss_off); |
| 2420 | |
| 2421 | goto got_status; |
| 2422 | } |
| 2423 | case 'W': /* Target exited */ |
| 2424 | { |
| 2425 | /* The remote process exited. */ |
| 2426 | status->kind = TARGET_WAITKIND_EXITED; |
| 2427 | status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]); |
| 2428 | goto got_status; |
| 2429 | } |
| 2430 | case 'X': |
| 2431 | status->kind = TARGET_WAITKIND_SIGNALLED; |
| 2432 | status->value.sig = (enum target_signal) |
| 2433 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2434 | kill_kludge = 1; |
| 2435 | |
| 2436 | goto got_status; |
| 2437 | case 'O': /* Console output */ |
| 2438 | remote_console_output (buf + 1); |
| 2439 | continue; |
| 2440 | case '\0': |
| 2441 | if (last_sent_signal != TARGET_SIGNAL_0) |
| 2442 | { |
| 2443 | /* Zero length reply means that we tried 'S' or 'C' and |
| 2444 | the remote system doesn't support it. */ |
| 2445 | target_terminal_ours_for_output (); |
| 2446 | printf_filtered |
| 2447 | ("Can't send signals to this remote system. %s not sent.\n", |
| 2448 | target_signal_to_name (last_sent_signal)); |
| 2449 | last_sent_signal = TARGET_SIGNAL_0; |
| 2450 | target_terminal_inferior (); |
| 2451 | |
| 2452 | strcpy ((char *) buf, last_sent_step ? "s" : "c"); |
| 2453 | putpkt ((char *) buf); |
| 2454 | continue; |
| 2455 | } |
| 2456 | /* else fallthrough */ |
| 2457 | default: |
| 2458 | warning ("Invalid remote reply: %s", buf); |
| 2459 | continue; |
| 2460 | } |
| 2461 | } |
| 2462 | got_status: |
| 2463 | if (thread_num != -1) |
| 2464 | { |
| 2465 | return thread_num; |
| 2466 | } |
| 2467 | return inferior_pid; |
| 2468 | } |
| 2469 | |
| 2470 | /* Async version of remote_wait. */ |
| 2471 | static int |
| 2472 | remote_async_wait (pid, status) |
| 2473 | int pid; |
| 2474 | struct target_waitstatus *status; |
| 2475 | { |
| 2476 | unsigned char *buf = alloca (PBUFSIZ); |
| 2477 | int thread_num = -1; |
| 2478 | |
| 2479 | status->kind = TARGET_WAITKIND_EXITED; |
| 2480 | status->value.integer = 0; |
| 2481 | |
| 2482 | while (1) |
| 2483 | { |
| 2484 | unsigned char *p; |
| 2485 | |
| 2486 | if (!async_p) |
| 2487 | ofunc = signal (SIGINT, remote_interrupt); |
| 2488 | getpkt ((char *) buf, 1); |
| 2489 | if (!async_p) |
| 2490 | signal (SIGINT, ofunc); |
| 2491 | |
| 2492 | /* This is a hook for when we need to do something (perhaps the |
| 2493 | collection of trace data) every time the target stops. */ |
| 2494 | if (target_wait_loop_hook) |
| 2495 | (*target_wait_loop_hook) (); |
| 2496 | |
| 2497 | switch (buf[0]) |
| 2498 | { |
| 2499 | case 'E': /* Error of some sort */ |
| 2500 | warning ("Remote failure reply: %s", buf); |
| 2501 | continue; |
| 2502 | case 'T': /* Status with PC, SP, FP, ... */ |
| 2503 | { |
| 2504 | int i; |
| 2505 | long regno; |
| 2506 | char regs[MAX_REGISTER_RAW_SIZE]; |
| 2507 | |
| 2508 | /* Expedited reply, containing Signal, {regno, reg} repeat */ |
| 2509 | /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where |
| 2510 | ss = signal number |
| 2511 | n... = register number |
| 2512 | r... = register contents |
| 2513 | */ |
| 2514 | p = &buf[3]; /* after Txx */ |
| 2515 | |
| 2516 | while (*p) |
| 2517 | { |
| 2518 | unsigned char *p1; |
| 2519 | char *p_temp; |
| 2520 | |
| 2521 | /* Read the register number */ |
| 2522 | regno = strtol ((const char *) p, &p_temp, 16); |
| 2523 | p1 = (unsigned char *) p_temp; |
| 2524 | |
| 2525 | if (p1 == p) /* No register number present here */ |
| 2526 | { |
| 2527 | p1 = (unsigned char *) strchr ((const char *) p, ':'); |
| 2528 | if (p1 == NULL) |
| 2529 | warning ("Malformed packet(a) (missing colon): %s\n\ |
| 2530 | Packet: '%s'\n", |
| 2531 | p, buf); |
| 2532 | if (strncmp ((const char *) p, "thread", p1 - p) == 0) |
| 2533 | { |
| 2534 | p_temp = unpack_varlen_hex (++p1, &thread_num); |
| 2535 | record_currthread (thread_num); |
| 2536 | p = (unsigned char *) p_temp; |
| 2537 | } |
| 2538 | } |
| 2539 | else |
| 2540 | { |
| 2541 | p = p1; |
| 2542 | |
| 2543 | if (*p++ != ':') |
| 2544 | warning ("Malformed packet(b) (missing colon): %s\n\ |
| 2545 | Packet: '%s'\n", |
| 2546 | p, buf); |
| 2547 | |
| 2548 | if (regno >= NUM_REGS) |
| 2549 | warning ("Remote sent bad register number %ld: %s\n\ |
| 2550 | Packet: '%s'\n", |
| 2551 | regno, p, buf); |
| 2552 | |
| 2553 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i++) |
| 2554 | { |
| 2555 | if (p[0] == 0 || p[1] == 0) |
| 2556 | warning ("Remote reply is too short: %s", buf); |
| 2557 | regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]); |
| 2558 | p += 2; |
| 2559 | } |
| 2560 | supply_register (regno, regs); |
| 2561 | } |
| 2562 | |
| 2563 | if (*p++ != ';') |
| 2564 | { |
| 2565 | warning ("Remote register badly formatted: %s", buf); |
| 2566 | warning (" here: %s", p); |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | /* fall through */ |
| 2571 | case 'S': /* Old style status, just signal only */ |
| 2572 | status->kind = TARGET_WAITKIND_STOPPED; |
| 2573 | status->value.sig = (enum target_signal) |
| 2574 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2575 | |
| 2576 | if (buf[3] == 'p') |
| 2577 | { |
| 2578 | /* Export Cisco kernel mode as a convenience variable |
| 2579 | (so that it can be used in the GDB prompt if desired). */ |
| 2580 | |
| 2581 | if (cisco_kernel_mode == 1) |
| 2582 | set_internalvar (lookup_internalvar ("cisco_kernel_mode"), |
| 2583 | value_from_string ("PDEBUG-")); |
| 2584 | cisco_kernel_mode = 0; |
| 2585 | thread_num = strtol ((const char *) &buf[4], NULL, 16); |
| 2586 | record_currthread (thread_num); |
| 2587 | } |
| 2588 | else if (buf[3] == 'k') |
| 2589 | { |
| 2590 | /* Export Cisco kernel mode as a convenience variable |
| 2591 | (so that it can be used in the GDB prompt if desired). */ |
| 2592 | |
| 2593 | if (cisco_kernel_mode == 1) |
| 2594 | set_internalvar (lookup_internalvar ("cisco_kernel_mode"), |
| 2595 | value_from_string ("KDEBUG-")); |
| 2596 | cisco_kernel_mode = 1; |
| 2597 | } |
| 2598 | goto got_status; |
| 2599 | case 'N': /* Cisco special: status and offsets */ |
| 2600 | { |
| 2601 | bfd_vma text_addr, data_addr, bss_addr; |
| 2602 | bfd_signed_vma text_off, data_off, bss_off; |
| 2603 | unsigned char *p1; |
| 2604 | |
| 2605 | status->kind = TARGET_WAITKIND_STOPPED; |
| 2606 | status->value.sig = (enum target_signal) |
| 2607 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2608 | |
| 2609 | if (symfile_objfile == NULL) |
| 2610 | { |
| 2611 | warning ("Relocation packet recieved with no symbol file. \ |
| 2612 | Packet Dropped"); |
| 2613 | goto got_status; |
| 2614 | } |
| 2615 | |
| 2616 | /* Relocate object file. Buffer format is NAATT;DD;BB |
| 2617 | * where AA is the signal number, TT is the new text |
| 2618 | * address, DD * is the new data address, and BB is the |
| 2619 | * new bss address. */ |
| 2620 | |
| 2621 | p = &buf[3]; |
| 2622 | text_addr = strtoul (p, (char **) &p1, 16); |
| 2623 | if (p1 == p || *p1 != ';') |
| 2624 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2625 | p = p1 + 1; |
| 2626 | data_addr = strtoul (p, (char **) &p1, 16); |
| 2627 | if (p1 == p || *p1 != ';') |
| 2628 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2629 | p = p1 + 1; |
| 2630 | bss_addr = strtoul (p, (char **) &p1, 16); |
| 2631 | if (p1 == p) |
| 2632 | warning ("Malformed relocation packet: Packet '%s'", buf); |
| 2633 | |
| 2634 | if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr, |
| 2635 | &text_off, &data_off, &bss_off) |
| 2636 | == 0) |
| 2637 | if (text_off != 0 || data_off != 0 || bss_off != 0) |
| 2638 | remote_cisco_objfile_relocate (text_off, data_off, bss_off); |
| 2639 | |
| 2640 | goto got_status; |
| 2641 | } |
| 2642 | case 'W': /* Target exited */ |
| 2643 | { |
| 2644 | /* The remote process exited. */ |
| 2645 | status->kind = TARGET_WAITKIND_EXITED; |
| 2646 | status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]); |
| 2647 | goto got_status; |
| 2648 | } |
| 2649 | case 'X': |
| 2650 | status->kind = TARGET_WAITKIND_SIGNALLED; |
| 2651 | status->value.sig = (enum target_signal) |
| 2652 | (((fromhex (buf[1])) << 4) + (fromhex (buf[2]))); |
| 2653 | kill_kludge = 1; |
| 2654 | |
| 2655 | goto got_status; |
| 2656 | case 'O': /* Console output */ |
| 2657 | remote_console_output (buf + 1); |
| 2658 | continue; |
| 2659 | case '\0': |
| 2660 | if (last_sent_signal != TARGET_SIGNAL_0) |
| 2661 | { |
| 2662 | /* Zero length reply means that we tried 'S' or 'C' and |
| 2663 | the remote system doesn't support it. */ |
| 2664 | target_terminal_ours_for_output (); |
| 2665 | printf_filtered |
| 2666 | ("Can't send signals to this remote system. %s not sent.\n", |
| 2667 | target_signal_to_name (last_sent_signal)); |
| 2668 | last_sent_signal = TARGET_SIGNAL_0; |
| 2669 | target_terminal_inferior (); |
| 2670 | |
| 2671 | strcpy ((char *) buf, last_sent_step ? "s" : "c"); |
| 2672 | putpkt ((char *) buf); |
| 2673 | continue; |
| 2674 | } |
| 2675 | /* else fallthrough */ |
| 2676 | default: |
| 2677 | warning ("Invalid remote reply: %s", buf); |
| 2678 | continue; |
| 2679 | } |
| 2680 | } |
| 2681 | got_status: |
| 2682 | if (thread_num != -1) |
| 2683 | { |
| 2684 | return thread_num; |
| 2685 | } |
| 2686 | return inferior_pid; |
| 2687 | } |
| 2688 | |
| 2689 | /* Number of bytes of registers this stub implements. */ |
| 2690 | |
| 2691 | static int register_bytes_found; |
| 2692 | |
| 2693 | /* Read the remote registers into the block REGS. */ |
| 2694 | /* Currently we just read all the registers, so we don't use regno. */ |
| 2695 | |
| 2696 | /* ARGSUSED */ |
| 2697 | static void |
| 2698 | remote_fetch_registers (regno) |
| 2699 | int regno; |
| 2700 | { |
| 2701 | char *buf = alloca (PBUFSIZ); |
| 2702 | int i; |
| 2703 | char *p; |
| 2704 | char regs[REGISTER_BYTES]; |
| 2705 | |
| 2706 | set_thread (inferior_pid, 1); |
| 2707 | |
| 2708 | sprintf (buf, "g"); |
| 2709 | remote_send (buf); |
| 2710 | |
| 2711 | if (remote_register_buf_size == 0) |
| 2712 | remote_register_buf_size = strlen (buf); |
| 2713 | |
| 2714 | /* Unimplemented registers read as all bits zero. */ |
| 2715 | memset (regs, 0, REGISTER_BYTES); |
| 2716 | |
| 2717 | /* We can get out of synch in various cases. If the first character |
| 2718 | in the buffer is not a hex character, assume that has happened |
| 2719 | and try to fetch another packet to read. */ |
| 2720 | while ((buf[0] < '0' || buf[0] > '9') |
| 2721 | && (buf[0] < 'a' || buf[0] > 'f') |
| 2722 | && buf[0] != 'x') /* New: unavailable register value */ |
| 2723 | { |
| 2724 | if (remote_debug) |
| 2725 | fprintf_unfiltered (gdb_stdlog, |
| 2726 | "Bad register packet; fetching a new packet\n"); |
| 2727 | getpkt (buf, 0); |
| 2728 | } |
| 2729 | |
| 2730 | /* Reply describes registers byte by byte, each byte encoded as two |
| 2731 | hex characters. Suck them all up, then supply them to the |
| 2732 | register cacheing/storage mechanism. */ |
| 2733 | |
| 2734 | p = buf; |
| 2735 | for (i = 0; i < REGISTER_BYTES; i++) |
| 2736 | { |
| 2737 | if (p[0] == 0) |
| 2738 | break; |
| 2739 | if (p[1] == 0) |
| 2740 | { |
| 2741 | warning ("Remote reply is of odd length: %s", buf); |
| 2742 | /* Don't change register_bytes_found in this case, and don't |
| 2743 | print a second warning. */ |
| 2744 | goto supply_them; |
| 2745 | } |
| 2746 | if (p[0] == 'x' && p[1] == 'x') |
| 2747 | regs[i] = 0; /* 'x' */ |
| 2748 | else |
| 2749 | regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]); |
| 2750 | p += 2; |
| 2751 | } |
| 2752 | |
| 2753 | if (i != register_bytes_found) |
| 2754 | { |
| 2755 | register_bytes_found = i; |
| 2756 | #ifdef REGISTER_BYTES_OK |
| 2757 | if (!REGISTER_BYTES_OK (i)) |
| 2758 | warning ("Remote reply is too short: %s", buf); |
| 2759 | #endif |
| 2760 | } |
| 2761 | |
| 2762 | supply_them: |
| 2763 | for (i = 0; i < NUM_REGS; i++) |
| 2764 | { |
| 2765 | supply_register (i, ®s[REGISTER_BYTE (i)]); |
| 2766 | if (buf[REGISTER_BYTE (i) * 2] == 'x') |
| 2767 | register_valid[i] = -1; /* register value not available */ |
| 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | /* Prepare to store registers. Since we may send them all (using a |
| 2772 | 'G' request), we have to read out the ones we don't want to change |
| 2773 | first. */ |
| 2774 | |
| 2775 | static void |
| 2776 | remote_prepare_to_store () |
| 2777 | { |
| 2778 | /* Make sure the entire registers array is valid. */ |
| 2779 | switch (remote_protocol_P.support) |
| 2780 | { |
| 2781 | case PACKET_DISABLE: |
| 2782 | case PACKET_SUPPORT_UNKNOWN: |
| 2783 | read_register_bytes (0, (char *) NULL, REGISTER_BYTES); |
| 2784 | break; |
| 2785 | case PACKET_ENABLE: |
| 2786 | break; |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | /* Helper: Attempt to store REGNO using the P packet. Return fail IFF |
| 2791 | packet was not recognized. */ |
| 2792 | |
| 2793 | static int |
| 2794 | store_register_using_P (regno) |
| 2795 | int regno; |
| 2796 | { |
| 2797 | /* Try storing a single register. */ |
| 2798 | char *buf = alloca (PBUFSIZ); |
| 2799 | char *regp; |
| 2800 | char *p; |
| 2801 | int i; |
| 2802 | |
| 2803 | sprintf (buf, "P%x=", regno); |
| 2804 | p = buf + strlen (buf); |
| 2805 | regp = ®isters[REGISTER_BYTE (regno)]; |
| 2806 | for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i) |
| 2807 | { |
| 2808 | *p++ = tohex ((regp[i] >> 4) & 0xf); |
| 2809 | *p++ = tohex (regp[i] & 0xf); |
| 2810 | } |
| 2811 | *p = '\0'; |
| 2812 | remote_send (buf); |
| 2813 | |
| 2814 | return buf[0] != '\0'; |
| 2815 | } |
| 2816 | |
| 2817 | |
| 2818 | /* Store register REGNO, or all registers if REGNO == -1, from the contents |
| 2819 | of REGISTERS. FIXME: ignores errors. */ |
| 2820 | |
| 2821 | static void |
| 2822 | remote_store_registers (regno) |
| 2823 | int regno; |
| 2824 | { |
| 2825 | char *buf = alloca (PBUFSIZ); |
| 2826 | int i; |
| 2827 | char *p; |
| 2828 | |
| 2829 | set_thread (inferior_pid, 1); |
| 2830 | |
| 2831 | if (regno >= 0) |
| 2832 | { |
| 2833 | switch (remote_protocol_P.support) |
| 2834 | { |
| 2835 | case PACKET_DISABLE: |
| 2836 | break; |
| 2837 | case PACKET_ENABLE: |
| 2838 | if (store_register_using_P (regno)) |
| 2839 | return; |
| 2840 | else |
| 2841 | error ("Protocol error: P packet not recognized by stub"); |
| 2842 | case PACKET_SUPPORT_UNKNOWN: |
| 2843 | if (store_register_using_P (regno)) |
| 2844 | { |
| 2845 | /* The stub recognized the 'P' packet. Remember this. */ |
| 2846 | remote_protocol_P.support = PACKET_ENABLE; |
| 2847 | return; |
| 2848 | } |
| 2849 | else |
| 2850 | { |
| 2851 | /* The stub does not support the 'P' packet. Use 'G' |
| 2852 | instead, and don't try using 'P' in the future (it |
| 2853 | will just waste our time). */ |
| 2854 | remote_protocol_P.support = PACKET_DISABLE; |
| 2855 | break; |
| 2856 | } |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | buf[0] = 'G'; |
| 2861 | |
| 2862 | /* Command describes registers byte by byte, |
| 2863 | each byte encoded as two hex characters. */ |
| 2864 | |
| 2865 | p = buf + 1; |
| 2866 | /* remote_prepare_to_store insures that register_bytes_found gets set. */ |
| 2867 | for (i = 0; i < register_bytes_found; i++) |
| 2868 | { |
| 2869 | *p++ = tohex ((registers[i] >> 4) & 0xf); |
| 2870 | *p++ = tohex (registers[i] & 0xf); |
| 2871 | } |
| 2872 | *p = '\0'; |
| 2873 | |
| 2874 | remote_send (buf); |
| 2875 | } |
| 2876 | |
| 2877 | /* Use of the data cache *used* to be disabled because it loses for looking |
| 2878 | at and changing hardware I/O ports and the like. Accepting `volatile' |
| 2879 | would perhaps be one way to fix it. Another idea would be to use the |
| 2880 | executable file for the text segment (for all SEC_CODE sections? |
| 2881 | For all SEC_READONLY sections?). This has problems if you want to |
| 2882 | actually see what the memory contains (e.g. self-modifying code, |
| 2883 | clobbered memory, user downloaded the wrong thing). |
| 2884 | |
| 2885 | Because it speeds so much up, it's now enabled, if you're playing |
| 2886 | with registers you turn it of (set remotecache 0). */ |
| 2887 | |
| 2888 | /* Read a word from remote address ADDR and return it. |
| 2889 | This goes through the data cache. */ |
| 2890 | |
| 2891 | #if 0 /* unused? */ |
| 2892 | static int |
| 2893 | remote_fetch_word (addr) |
| 2894 | CORE_ADDR addr; |
| 2895 | { |
| 2896 | return dcache_fetch (remote_dcache, addr); |
| 2897 | } |
| 2898 | |
| 2899 | /* Write a word WORD into remote address ADDR. |
| 2900 | This goes through the data cache. */ |
| 2901 | |
| 2902 | static void |
| 2903 | remote_store_word (addr, word) |
| 2904 | CORE_ADDR addr; |
| 2905 | int word; |
| 2906 | { |
| 2907 | dcache_poke (remote_dcache, addr, word); |
| 2908 | } |
| 2909 | #endif /* 0 (unused?) */ |
| 2910 | \f |
| 2911 | |
| 2912 | |
| 2913 | /* Return the number of hex digits in num. */ |
| 2914 | |
| 2915 | static int |
| 2916 | hexnumlen (num) |
| 2917 | ULONGEST num; |
| 2918 | { |
| 2919 | int i; |
| 2920 | |
| 2921 | for (i = 0; num != 0; i++) |
| 2922 | num >>= 4; |
| 2923 | |
| 2924 | return max (i, 1); |
| 2925 | } |
| 2926 | |
| 2927 | /* Set BUF to the hex digits representing NUM. */ |
| 2928 | |
| 2929 | static int |
| 2930 | hexnumstr (buf, num) |
| 2931 | char *buf; |
| 2932 | ULONGEST num; |
| 2933 | { |
| 2934 | int i; |
| 2935 | int len = hexnumlen (num); |
| 2936 | |
| 2937 | buf[len] = '\0'; |
| 2938 | |
| 2939 | for (i = len - 1; i >= 0; i--) |
| 2940 | { |
| 2941 | buf[i] = "0123456789abcdef"[(num & 0xf)]; |
| 2942 | num >>= 4; |
| 2943 | } |
| 2944 | |
| 2945 | return len; |
| 2946 | } |
| 2947 | |
| 2948 | /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */ |
| 2949 | |
| 2950 | static CORE_ADDR |
| 2951 | remote_address_masked (addr) |
| 2952 | CORE_ADDR addr; |
| 2953 | { |
| 2954 | if (remote_address_size > 0 |
| 2955 | && remote_address_size < (sizeof (ULONGEST) * 8)) |
| 2956 | { |
| 2957 | /* Only create a mask when that mask can safely be constructed |
| 2958 | in a ULONGEST variable. */ |
| 2959 | ULONGEST mask = 1; |
| 2960 | mask = (mask << remote_address_size) - 1; |
| 2961 | addr &= mask; |
| 2962 | } |
| 2963 | return addr; |
| 2964 | } |
| 2965 | |
| 2966 | /* Determine whether the remote target supports binary downloading. |
| 2967 | This is accomplished by sending a no-op memory write of zero length |
| 2968 | to the target at the specified address. It does not suffice to send |
| 2969 | the whole packet, since many stubs strip the eighth bit and subsequently |
| 2970 | compute a wrong checksum, which causes real havoc with remote_write_bytes. |
| 2971 | |
| 2972 | NOTE: This can still lose if the serial line is not eight-bit |
| 2973 | clean. In cases like this, the user should clear "remote |
| 2974 | X-packet". */ |
| 2975 | |
| 2976 | static void |
| 2977 | check_binary_download (addr) |
| 2978 | CORE_ADDR addr; |
| 2979 | { |
| 2980 | switch (remote_protocol_binary_download.support) |
| 2981 | { |
| 2982 | case PACKET_DISABLE: |
| 2983 | break; |
| 2984 | case PACKET_ENABLE: |
| 2985 | break; |
| 2986 | case PACKET_SUPPORT_UNKNOWN: |
| 2987 | { |
| 2988 | char *buf = alloca (PBUFSIZ); |
| 2989 | char *p; |
| 2990 | |
| 2991 | p = buf; |
| 2992 | *p++ = 'X'; |
| 2993 | p += hexnumstr (p, (ULONGEST) addr); |
| 2994 | *p++ = ','; |
| 2995 | p += hexnumstr (p, (ULONGEST) 0); |
| 2996 | *p++ = ':'; |
| 2997 | *p = '\0'; |
| 2998 | |
| 2999 | putpkt_binary (buf, (int) (p - buf)); |
| 3000 | getpkt (buf, 0); |
| 3001 | |
| 3002 | if (buf[0] == '\0') |
| 3003 | { |
| 3004 | if (remote_debug) |
| 3005 | fprintf_unfiltered (gdb_stdlog, |
| 3006 | "binary downloading NOT suppported by target\n"); |
| 3007 | remote_protocol_binary_download.support = PACKET_DISABLE; |
| 3008 | } |
| 3009 | else |
| 3010 | { |
| 3011 | if (remote_debug) |
| 3012 | fprintf_unfiltered (gdb_stdlog, |
| 3013 | "binary downloading suppported by target\n"); |
| 3014 | remote_protocol_binary_download.support = PACKET_ENABLE; |
| 3015 | } |
| 3016 | break; |
| 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | /* Write memory data directly to the remote machine. |
| 3022 | This does not inform the data cache; the data cache uses this. |
| 3023 | MEMADDR is the address in the remote memory space. |
| 3024 | MYADDR is the address of the buffer in our space. |
| 3025 | LEN is the number of bytes. |
| 3026 | |
| 3027 | Returns number of bytes transferred, or 0 for error. */ |
| 3028 | |
| 3029 | static int |
| 3030 | remote_write_bytes (memaddr, myaddr, len) |
| 3031 | CORE_ADDR memaddr; |
| 3032 | char *myaddr; |
| 3033 | int len; |
| 3034 | { |
| 3035 | unsigned char *buf = alloca (PBUFSIZ); |
| 3036 | int max_buf_size; /* Max size of packet output buffer */ |
| 3037 | int origlen; |
| 3038 | |
| 3039 | /* Verify that the target can support a binary download */ |
| 3040 | check_binary_download (memaddr); |
| 3041 | |
| 3042 | /* Chop the transfer down if necessary */ |
| 3043 | |
| 3044 | max_buf_size = min (remote_write_size, PBUFSIZ); |
| 3045 | if (remote_register_buf_size != 0) |
| 3046 | max_buf_size = min (max_buf_size, remote_register_buf_size); |
| 3047 | |
| 3048 | /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */ |
| 3049 | max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4; |
| 3050 | |
| 3051 | origlen = len; |
| 3052 | while (len > 0) |
| 3053 | { |
| 3054 | unsigned char *p, *plen; |
| 3055 | int todo; |
| 3056 | int i; |
| 3057 | |
| 3058 | /* construct "M"<memaddr>","<len>":" */ |
| 3059 | /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */ |
| 3060 | memaddr = remote_address_masked (memaddr); |
| 3061 | p = buf; |
| 3062 | switch (remote_protocol_binary_download.support) |
| 3063 | { |
| 3064 | case PACKET_ENABLE: |
| 3065 | *p++ = 'X'; |
| 3066 | todo = min (len, max_buf_size); |
| 3067 | break; |
| 3068 | case PACKET_DISABLE: |
| 3069 | *p++ = 'M'; |
| 3070 | todo = min (len, max_buf_size / 2); /* num bytes that will fit */ |
| 3071 | break; |
| 3072 | case PACKET_SUPPORT_UNKNOWN: |
| 3073 | internal_error ("remote_write_bytes: bad switch"); |
| 3074 | } |
| 3075 | |
| 3076 | p += hexnumstr (p, (ULONGEST) memaddr); |
| 3077 | *p++ = ','; |
| 3078 | |
| 3079 | plen = p; /* remember where len field goes */ |
| 3080 | p += hexnumstr (p, (ULONGEST) todo); |
| 3081 | *p++ = ':'; |
| 3082 | *p = '\0'; |
| 3083 | |
| 3084 | /* We send target system values byte by byte, in increasing byte |
| 3085 | addresses, each byte encoded as two hex characters (or one |
| 3086 | binary character). */ |
| 3087 | switch (remote_protocol_binary_download.support) |
| 3088 | { |
| 3089 | case PACKET_ENABLE: |
| 3090 | { |
| 3091 | int escaped = 0; |
| 3092 | for (i = 0; |
| 3093 | (i < todo) && (i + escaped) < (max_buf_size - 2); |
| 3094 | i++) |
| 3095 | { |
| 3096 | switch (myaddr[i] & 0xff) |
| 3097 | { |
| 3098 | case '$': |
| 3099 | case '#': |
| 3100 | case 0x7d: |
| 3101 | /* These must be escaped */ |
| 3102 | escaped++; |
| 3103 | *p++ = 0x7d; |
| 3104 | *p++ = (myaddr[i] & 0xff) ^ 0x20; |
| 3105 | break; |
| 3106 | default: |
| 3107 | *p++ = myaddr[i] & 0xff; |
| 3108 | break; |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | if (i < todo) |
| 3113 | { |
| 3114 | /* Escape chars have filled up the buffer prematurely, |
| 3115 | and we have actually sent fewer bytes than planned. |
| 3116 | Fix-up the length field of the packet. */ |
| 3117 | |
| 3118 | /* FIXME: will fail if new len is a shorter string than |
| 3119 | old len. */ |
| 3120 | |
| 3121 | plen += hexnumstr (plen, (ULONGEST) i); |
| 3122 | *plen++ = ':'; |
| 3123 | } |
| 3124 | break; |
| 3125 | } |
| 3126 | case PACKET_DISABLE: |
| 3127 | { |
| 3128 | for (i = 0; i < todo; i++) |
| 3129 | { |
| 3130 | *p++ = tohex ((myaddr[i] >> 4) & 0xf); |
| 3131 | *p++ = tohex (myaddr[i] & 0xf); |
| 3132 | } |
| 3133 | *p = '\0'; |
| 3134 | break; |
| 3135 | } |
| 3136 | case PACKET_SUPPORT_UNKNOWN: |
| 3137 | internal_error ("remote_write_bytes: bad switch"); |
| 3138 | } |
| 3139 | |
| 3140 | putpkt_binary (buf, (int) (p - buf)); |
| 3141 | getpkt (buf, 0); |
| 3142 | |
| 3143 | if (buf[0] == 'E') |
| 3144 | { |
| 3145 | /* There is no correspondance between what the remote protocol uses |
| 3146 | for errors and errno codes. We would like a cleaner way of |
| 3147 | representing errors (big enough to include errno codes, bfd_error |
| 3148 | codes, and others). But for now just return EIO. */ |
| 3149 | errno = EIO; |
| 3150 | return 0; |
| 3151 | } |
| 3152 | |
| 3153 | /* Increment by i, not by todo, in case escape chars |
| 3154 | caused us to send fewer bytes than we'd planned. */ |
| 3155 | myaddr += i; |
| 3156 | memaddr += i; |
| 3157 | len -= i; |
| 3158 | } |
| 3159 | return origlen; |
| 3160 | } |
| 3161 | |
| 3162 | /* Read memory data directly from the remote machine. |
| 3163 | This does not use the data cache; the data cache uses this. |
| 3164 | MEMADDR is the address in the remote memory space. |
| 3165 | MYADDR is the address of the buffer in our space. |
| 3166 | LEN is the number of bytes. |
| 3167 | |
| 3168 | Returns number of bytes transferred, or 0 for error. */ |
| 3169 | |
| 3170 | static int |
| 3171 | remote_read_bytes (memaddr, myaddr, len) |
| 3172 | CORE_ADDR memaddr; |
| 3173 | char *myaddr; |
| 3174 | int len; |
| 3175 | { |
| 3176 | char *buf = alloca (PBUFSIZ); |
| 3177 | int max_buf_size; /* Max size of packet output buffer */ |
| 3178 | int origlen; |
| 3179 | |
| 3180 | /* Chop the transfer down if necessary */ |
| 3181 | |
| 3182 | max_buf_size = min (remote_write_size, PBUFSIZ); |
| 3183 | if (remote_register_buf_size != 0) |
| 3184 | max_buf_size = min (max_buf_size, remote_register_buf_size); |
| 3185 | |
| 3186 | origlen = len; |
| 3187 | while (len > 0) |
| 3188 | { |
| 3189 | char *p; |
| 3190 | int todo; |
| 3191 | int i; |
| 3192 | |
| 3193 | todo = min (len, max_buf_size / 2); /* num bytes that will fit */ |
| 3194 | |
| 3195 | /* construct "m"<memaddr>","<len>" */ |
| 3196 | /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */ |
| 3197 | memaddr = remote_address_masked (memaddr); |
| 3198 | p = buf; |
| 3199 | *p++ = 'm'; |
| 3200 | p += hexnumstr (p, (ULONGEST) memaddr); |
| 3201 | *p++ = ','; |
| 3202 | p += hexnumstr (p, (ULONGEST) todo); |
| 3203 | *p = '\0'; |
| 3204 | |
| 3205 | putpkt (buf); |
| 3206 | getpkt (buf, 0); |
| 3207 | |
| 3208 | if (buf[0] == 'E') |
| 3209 | { |
| 3210 | /* There is no correspondance between what the remote protocol uses |
| 3211 | for errors and errno codes. We would like a cleaner way of |
| 3212 | representing errors (big enough to include errno codes, bfd_error |
| 3213 | codes, and others). But for now just return EIO. */ |
| 3214 | errno = EIO; |
| 3215 | return 0; |
| 3216 | } |
| 3217 | |
| 3218 | /* Reply describes memory byte by byte, |
| 3219 | each byte encoded as two hex characters. */ |
| 3220 | |
| 3221 | p = buf; |
| 3222 | for (i = 0; i < todo; i++) |
| 3223 | { |
| 3224 | if (p[0] == 0 || p[1] == 0) |
| 3225 | /* Reply is short. This means that we were able to read |
| 3226 | only part of what we wanted to. */ |
| 3227 | return i + (origlen - len); |
| 3228 | myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]); |
| 3229 | p += 2; |
| 3230 | } |
| 3231 | myaddr += todo; |
| 3232 | memaddr += todo; |
| 3233 | len -= todo; |
| 3234 | } |
| 3235 | return origlen; |
| 3236 | } |
| 3237 | \f |
| 3238 | /* Read or write LEN bytes from inferior memory at MEMADDR, |
| 3239 | transferring to or from debugger address BUFFER. Write to inferior if |
| 3240 | SHOULD_WRITE is nonzero. Returns length of data written or read; 0 |
| 3241 | for error. */ |
| 3242 | |
| 3243 | #ifndef REMOTE_TRANSLATE_XFER_ADDRESS |
| 3244 | #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \ |
| 3245 | (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN)) |
| 3246 | #endif |
| 3247 | |
| 3248 | /* ARGSUSED */ |
| 3249 | static int |
| 3250 | remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target) |
| 3251 | CORE_ADDR mem_addr; |
| 3252 | char *buffer; |
| 3253 | int mem_len; |
| 3254 | int should_write; |
| 3255 | struct target_ops *target; /* ignored */ |
| 3256 | { |
| 3257 | CORE_ADDR targ_addr; |
| 3258 | int targ_len; |
| 3259 | REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len); |
| 3260 | if (targ_len <= 0) |
| 3261 | return 0; |
| 3262 | |
| 3263 | return dcache_xfer_memory (remote_dcache, targ_addr, buffer, |
| 3264 | targ_len, should_write); |
| 3265 | } |
| 3266 | |
| 3267 | |
| 3268 | #if 0 |
| 3269 | /* Enable after 4.12. */ |
| 3270 | |
| 3271 | void |
| 3272 | remote_search (len, data, mask, startaddr, increment, lorange, hirange |
| 3273 | addr_found, data_found) |
| 3274 | int len; |
| 3275 | char *data; |
| 3276 | char *mask; |
| 3277 | CORE_ADDR startaddr; |
| 3278 | int increment; |
| 3279 | CORE_ADDR lorange; |
| 3280 | CORE_ADDR hirange; |
| 3281 | CORE_ADDR *addr_found; |
| 3282 | char *data_found; |
| 3283 | { |
| 3284 | if (increment == -4 && len == 4) |
| 3285 | { |
| 3286 | long mask_long, data_long; |
| 3287 | long data_found_long; |
| 3288 | CORE_ADDR addr_we_found; |
| 3289 | char *buf = alloca (PBUFSIZ); |
| 3290 | long returned_long[2]; |
| 3291 | char *p; |
| 3292 | |
| 3293 | mask_long = extract_unsigned_integer (mask, len); |
| 3294 | data_long = extract_unsigned_integer (data, len); |
| 3295 | sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long); |
| 3296 | putpkt (buf); |
| 3297 | getpkt (buf, 0); |
| 3298 | if (buf[0] == '\0') |
| 3299 | { |
| 3300 | /* The stub doesn't support the 't' request. We might want to |
| 3301 | remember this fact, but on the other hand the stub could be |
| 3302 | switched on us. Maybe we should remember it only until |
| 3303 | the next "target remote". */ |
| 3304 | generic_search (len, data, mask, startaddr, increment, lorange, |
| 3305 | hirange, addr_found, data_found); |
| 3306 | return; |
| 3307 | } |
| 3308 | |
| 3309 | if (buf[0] == 'E') |
| 3310 | /* There is no correspondance between what the remote protocol uses |
| 3311 | for errors and errno codes. We would like a cleaner way of |
| 3312 | representing errors (big enough to include errno codes, bfd_error |
| 3313 | codes, and others). But for now just use EIO. */ |
| 3314 | memory_error (EIO, startaddr); |
| 3315 | p = buf; |
| 3316 | addr_we_found = 0; |
| 3317 | while (*p != '\0' && *p != ',') |
| 3318 | addr_we_found = (addr_we_found << 4) + fromhex (*p++); |
| 3319 | if (*p == '\0') |
| 3320 | error ("Protocol error: short return for search"); |
| 3321 | |
| 3322 | data_found_long = 0; |
| 3323 | while (*p != '\0' && *p != ',') |
| 3324 | data_found_long = (data_found_long << 4) + fromhex (*p++); |
| 3325 | /* Ignore anything after this comma, for future extensions. */ |
| 3326 | |
| 3327 | if (addr_we_found < lorange || addr_we_found >= hirange) |
| 3328 | { |
| 3329 | *addr_found = 0; |
| 3330 | return; |
| 3331 | } |
| 3332 | |
| 3333 | *addr_found = addr_we_found; |
| 3334 | *data_found = store_unsigned_integer (data_we_found, len); |
| 3335 | return; |
| 3336 | } |
| 3337 | generic_search (len, data, mask, startaddr, increment, lorange, |
| 3338 | hirange, addr_found, data_found); |
| 3339 | } |
| 3340 | #endif /* 0 */ |
| 3341 | \f |
| 3342 | static void |
| 3343 | remote_files_info (ignore) |
| 3344 | struct target_ops *ignore; |
| 3345 | { |
| 3346 | puts_filtered ("Debugging a target over a serial line.\n"); |
| 3347 | } |
| 3348 | \f |
| 3349 | /* Stuff for dealing with the packets which are part of this protocol. |
| 3350 | See comment at top of file for details. */ |
| 3351 | |
| 3352 | /* Read a single character from the remote end, masking it down to 7 bits. */ |
| 3353 | |
| 3354 | static int |
| 3355 | readchar (timeout) |
| 3356 | int timeout; |
| 3357 | { |
| 3358 | int ch; |
| 3359 | |
| 3360 | ch = SERIAL_READCHAR (remote_desc, timeout); |
| 3361 | |
| 3362 | switch (ch) |
| 3363 | { |
| 3364 | case SERIAL_EOF: |
| 3365 | error ("Remote connection closed"); |
| 3366 | case SERIAL_ERROR: |
| 3367 | perror_with_name ("Remote communication error"); |
| 3368 | case SERIAL_TIMEOUT: |
| 3369 | return ch; |
| 3370 | default: |
| 3371 | return ch & 0x7f; |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | /* Send the command in BUF to the remote machine, and read the reply |
| 3376 | into BUF. Report an error if we get an error reply. */ |
| 3377 | |
| 3378 | static void |
| 3379 | remote_send (buf) |
| 3380 | char *buf; |
| 3381 | { |
| 3382 | putpkt (buf); |
| 3383 | getpkt (buf, 0); |
| 3384 | |
| 3385 | if (buf[0] == 'E') |
| 3386 | error ("Remote failure reply: %s", buf); |
| 3387 | } |
| 3388 | |
| 3389 | /* Display a null-terminated packet on stdout, for debugging, using C |
| 3390 | string notation. */ |
| 3391 | |
| 3392 | static void |
| 3393 | print_packet (buf) |
| 3394 | char *buf; |
| 3395 | { |
| 3396 | puts_filtered ("\""); |
| 3397 | fputstr_filtered (buf, '"', gdb_stdout); |
| 3398 | puts_filtered ("\""); |
| 3399 | } |
| 3400 | |
| 3401 | int |
| 3402 | putpkt (buf) |
| 3403 | char *buf; |
| 3404 | { |
| 3405 | return putpkt_binary (buf, strlen (buf)); |
| 3406 | } |
| 3407 | |
| 3408 | /* Send a packet to the remote machine, with error checking. The data |
| 3409 | of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5 |
| 3410 | to account for the $, # and checksum, and for a possible /0 if we are |
| 3411 | debugging (remote_debug) and want to print the sent packet as a string */ |
| 3412 | |
| 3413 | static int |
| 3414 | putpkt_binary (buf, cnt) |
| 3415 | char *buf; |
| 3416 | int cnt; |
| 3417 | { |
| 3418 | int i; |
| 3419 | unsigned char csum = 0; |
| 3420 | char *buf2 = alloca (PBUFSIZ); |
| 3421 | char *junkbuf = alloca (PBUFSIZ); |
| 3422 | |
| 3423 | int ch; |
| 3424 | int tcount = 0; |
| 3425 | char *p; |
| 3426 | |
| 3427 | /* Copy the packet into buffer BUF2, encapsulating it |
| 3428 | and giving it a checksum. */ |
| 3429 | |
| 3430 | if (cnt > BUFSIZ - 5) /* Prosanity check */ |
| 3431 | abort (); |
| 3432 | |
| 3433 | p = buf2; |
| 3434 | *p++ = '$'; |
| 3435 | |
| 3436 | for (i = 0; i < cnt; i++) |
| 3437 | { |
| 3438 | csum += buf[i]; |
| 3439 | *p++ = buf[i]; |
| 3440 | } |
| 3441 | *p++ = '#'; |
| 3442 | *p++ = tohex ((csum >> 4) & 0xf); |
| 3443 | *p++ = tohex (csum & 0xf); |
| 3444 | |
| 3445 | /* Send it over and over until we get a positive ack. */ |
| 3446 | |
| 3447 | while (1) |
| 3448 | { |
| 3449 | int started_error_output = 0; |
| 3450 | |
| 3451 | if (remote_debug) |
| 3452 | { |
| 3453 | *p = '\0'; |
| 3454 | fprintf_unfiltered (gdb_stdlog, "Sending packet: "); |
| 3455 | fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog); |
| 3456 | fprintf_unfiltered (gdb_stdlog, "...", buf2); |
| 3457 | gdb_flush (gdb_stdlog); |
| 3458 | } |
| 3459 | if (SERIAL_WRITE (remote_desc, buf2, p - buf2)) |
| 3460 | perror_with_name ("putpkt: write failed"); |
| 3461 | |
| 3462 | /* read until either a timeout occurs (-2) or '+' is read */ |
| 3463 | while (1) |
| 3464 | { |
| 3465 | ch = readchar (remote_timeout); |
| 3466 | |
| 3467 | if (remote_debug) |
| 3468 | { |
| 3469 | switch (ch) |
| 3470 | { |
| 3471 | case '+': |
| 3472 | case SERIAL_TIMEOUT: |
| 3473 | case '$': |
| 3474 | if (started_error_output) |
| 3475 | { |
| 3476 | putchar_unfiltered ('\n'); |
| 3477 | started_error_output = 0; |
| 3478 | } |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | switch (ch) |
| 3483 | { |
| 3484 | case '+': |
| 3485 | if (remote_debug) |
| 3486 | fprintf_unfiltered (gdb_stdlog, "Ack\n"); |
| 3487 | return 1; |
| 3488 | case SERIAL_TIMEOUT: |
| 3489 | tcount++; |
| 3490 | if (tcount > 3) |
| 3491 | return 0; |
| 3492 | break; /* Retransmit buffer */ |
| 3493 | case '$': |
| 3494 | { |
| 3495 | /* It's probably an old response, and we're out of sync. |
| 3496 | Just gobble up the packet and ignore it. */ |
| 3497 | getpkt (junkbuf, 0); |
| 3498 | continue; /* Now, go look for + */ |
| 3499 | } |
| 3500 | default: |
| 3501 | if (remote_debug) |
| 3502 | { |
| 3503 | if (!started_error_output) |
| 3504 | { |
| 3505 | started_error_output = 1; |
| 3506 | fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: "); |
| 3507 | } |
| 3508 | fputc_unfiltered (ch & 0177, gdb_stdlog); |
| 3509 | } |
| 3510 | continue; |
| 3511 | } |
| 3512 | break; /* Here to retransmit */ |
| 3513 | } |
| 3514 | |
| 3515 | #if 0 |
| 3516 | /* This is wrong. If doing a long backtrace, the user should be |
| 3517 | able to get out next time we call QUIT, without anything as |
| 3518 | violent as interrupt_query. If we want to provide a way out of |
| 3519 | here without getting to the next QUIT, it should be based on |
| 3520 | hitting ^C twice as in remote_wait. */ |
| 3521 | if (quit_flag) |
| 3522 | { |
| 3523 | quit_flag = 0; |
| 3524 | interrupt_query (); |
| 3525 | } |
| 3526 | #endif |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | static int remote_cisco_mode; |
| 3531 | |
| 3532 | static void |
| 3533 | remote_cisco_expand (src, dest) |
| 3534 | char *src; |
| 3535 | char *dest; |
| 3536 | { |
| 3537 | int i; |
| 3538 | int repeat; |
| 3539 | |
| 3540 | do |
| 3541 | { |
| 3542 | if (*src == '*') |
| 3543 | { |
| 3544 | repeat = (fromhex (src[1]) << 4) + fromhex (src[2]); |
| 3545 | for (i = 0; i < repeat; i++) |
| 3546 | { |
| 3547 | *dest++ = *(src - 1); |
| 3548 | } |
| 3549 | src += 2; |
| 3550 | } |
| 3551 | else |
| 3552 | { |
| 3553 | *dest++ = *src; |
| 3554 | } |
| 3555 | } |
| 3556 | while (*src++); |
| 3557 | } |
| 3558 | |
| 3559 | /* Come here after finding the start of the frame. Collect the rest |
| 3560 | into BUF, verifying the checksum, length, and handling run-length |
| 3561 | compression. Returns 0 on any error, 1 on success. */ |
| 3562 | |
| 3563 | static int |
| 3564 | read_frame (buf) |
| 3565 | char *buf; |
| 3566 | { |
| 3567 | unsigned char csum; |
| 3568 | char *bp; |
| 3569 | int c; |
| 3570 | |
| 3571 | csum = 0; |
| 3572 | bp = buf; |
| 3573 | |
| 3574 | while (1) |
| 3575 | { |
| 3576 | c = readchar (remote_timeout); |
| 3577 | |
| 3578 | switch (c) |
| 3579 | { |
| 3580 | case SERIAL_TIMEOUT: |
| 3581 | if (remote_debug) |
| 3582 | fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog); |
| 3583 | return 0; |
| 3584 | case '$': |
| 3585 | if (remote_debug) |
| 3586 | fputs_filtered ("Saw new packet start in middle of old one\n", |
| 3587 | gdb_stdlog); |
| 3588 | return 0; /* Start a new packet, count retries */ |
| 3589 | case '#': |
| 3590 | { |
| 3591 | unsigned char pktcsum; |
| 3592 | |
| 3593 | *bp = '\000'; |
| 3594 | |
| 3595 | pktcsum = fromhex (readchar (remote_timeout)) << 4; |
| 3596 | pktcsum |= fromhex (readchar (remote_timeout)); |
| 3597 | |
| 3598 | if (csum == pktcsum) |
| 3599 | { |
| 3600 | if (remote_cisco_mode) /* variant run-length-encoding */ |
| 3601 | { |
| 3602 | char *tmp_buf = alloca (PBUFSIZ); |
| 3603 | |
| 3604 | remote_cisco_expand (buf, tmp_buf); |
| 3605 | strcpy (buf, tmp_buf); |
| 3606 | } |
| 3607 | return 1; |
| 3608 | } |
| 3609 | |
| 3610 | if (remote_debug) |
| 3611 | { |
| 3612 | fprintf_filtered (gdb_stdlog, |
| 3613 | "Bad checksum, sentsum=0x%x, csum=0x%x, buf=", |
| 3614 | pktcsum, csum); |
| 3615 | fputs_filtered (buf, gdb_stdlog); |
| 3616 | fputs_filtered ("\n", gdb_stdlog); |
| 3617 | } |
| 3618 | return 0; |
| 3619 | } |
| 3620 | case '*': /* Run length encoding */ |
| 3621 | if (remote_cisco_mode == 0) /* variant run-length-encoding */ |
| 3622 | { |
| 3623 | csum += c; |
| 3624 | c = readchar (remote_timeout); |
| 3625 | csum += c; |
| 3626 | c = c - ' ' + 3; /* Compute repeat count */ |
| 3627 | |
| 3628 | if (c > 0 && c < 255 && bp + c - 1 < buf + PBUFSIZ - 1) |
| 3629 | { |
| 3630 | memset (bp, *(bp - 1), c); |
| 3631 | bp += c; |
| 3632 | continue; |
| 3633 | } |
| 3634 | |
| 3635 | *bp = '\0'; |
| 3636 | printf_filtered ("Repeat count %d too large for buffer: ", c); |
| 3637 | puts_filtered (buf); |
| 3638 | puts_filtered ("\n"); |
| 3639 | return 0; |
| 3640 | } |
| 3641 | /* else fall thru to treat like default */ |
| 3642 | default: |
| 3643 | if (bp < buf + PBUFSIZ - 1) |
| 3644 | { |
| 3645 | *bp++ = c; |
| 3646 | csum += c; |
| 3647 | continue; |
| 3648 | } |
| 3649 | |
| 3650 | *bp = '\0'; |
| 3651 | puts_filtered ("Remote packet too long: "); |
| 3652 | puts_filtered (buf); |
| 3653 | puts_filtered ("\n"); |
| 3654 | |
| 3655 | return 0; |
| 3656 | } |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | /* Read a packet from the remote machine, with error checking, and |
| 3661 | store it in BUF. BUF is expected to be of size PBUFSIZ. If |
| 3662 | FOREVER, wait forever rather than timing out; this is used while |
| 3663 | the target is executing user code. */ |
| 3664 | |
| 3665 | void |
| 3666 | getpkt (buf, forever) |
| 3667 | char *buf; |
| 3668 | int forever; |
| 3669 | { |
| 3670 | int c; |
| 3671 | int tries; |
| 3672 | int timeout; |
| 3673 | int val; |
| 3674 | |
| 3675 | strcpy (buf, "timeout"); |
| 3676 | |
| 3677 | if (forever) |
| 3678 | { |
| 3679 | timeout = watchdog > 0 ? watchdog : -1; |
| 3680 | } |
| 3681 | |
| 3682 | else |
| 3683 | timeout = remote_timeout; |
| 3684 | |
| 3685 | #define MAX_TRIES 3 |
| 3686 | |
| 3687 | for (tries = 1; tries <= MAX_TRIES; tries++) |
| 3688 | { |
| 3689 | /* This can loop forever if the remote side sends us characters |
| 3690 | continuously, but if it pauses, we'll get a zero from readchar |
| 3691 | because of timeout. Then we'll count that as a retry. */ |
| 3692 | |
| 3693 | /* Note that we will only wait forever prior to the start of a packet. |
| 3694 | After that, we expect characters to arrive at a brisk pace. They |
| 3695 | should show up within remote_timeout intervals. */ |
| 3696 | |
| 3697 | do |
| 3698 | { |
| 3699 | c = readchar (timeout); |
| 3700 | |
| 3701 | if (c == SERIAL_TIMEOUT) |
| 3702 | { |
| 3703 | if (forever) /* Watchdog went off. Kill the target. */ |
| 3704 | { |
| 3705 | target_mourn_inferior (); |
| 3706 | error ("Watchdog has expired. Target detached.\n"); |
| 3707 | } |
| 3708 | if (remote_debug) |
| 3709 | fputs_filtered ("Timed out.\n", gdb_stdlog); |
| 3710 | goto retry; |
| 3711 | } |
| 3712 | } |
| 3713 | while (c != '$'); |
| 3714 | |
| 3715 | /* We've found the start of a packet, now collect the data. */ |
| 3716 | |
| 3717 | val = read_frame (buf); |
| 3718 | |
| 3719 | if (val == 1) |
| 3720 | { |
| 3721 | if (remote_debug) |
| 3722 | { |
| 3723 | fprintf_unfiltered (gdb_stdlog, "Packet received: "); |
| 3724 | fputstr_unfiltered (buf, 0, gdb_stdlog); |
| 3725 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 3726 | } |
| 3727 | SERIAL_WRITE (remote_desc, "+", 1); |
| 3728 | return; |
| 3729 | } |
| 3730 | |
| 3731 | /* Try the whole thing again. */ |
| 3732 | retry: |
| 3733 | SERIAL_WRITE (remote_desc, "-", 1); |
| 3734 | } |
| 3735 | |
| 3736 | /* We have tried hard enough, and just can't receive the packet. Give up. */ |
| 3737 | |
| 3738 | printf_unfiltered ("Ignoring packet error, continuing...\n"); |
| 3739 | SERIAL_WRITE (remote_desc, "+", 1); |
| 3740 | } |
| 3741 | \f |
| 3742 | static void |
| 3743 | remote_kill () |
| 3744 | { |
| 3745 | /* For some mysterious reason, wait_for_inferior calls kill instead of |
| 3746 | mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */ |
| 3747 | if (kill_kludge) |
| 3748 | { |
| 3749 | kill_kludge = 0; |
| 3750 | target_mourn_inferior (); |
| 3751 | return; |
| 3752 | } |
| 3753 | |
| 3754 | /* Use catch_errors so the user can quit from gdb even when we aren't on |
| 3755 | speaking terms with the remote system. */ |
| 3756 | catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR); |
| 3757 | |
| 3758 | /* Don't wait for it to die. I'm not really sure it matters whether |
| 3759 | we do or not. For the existing stubs, kill is a noop. */ |
| 3760 | target_mourn_inferior (); |
| 3761 | } |
| 3762 | |
| 3763 | /* Async version of remote_kill. */ |
| 3764 | static void |
| 3765 | remote_async_kill () |
| 3766 | { |
| 3767 | /* Unregister the file descriptor from the event loop. */ |
| 3768 | if (async_p) |
| 3769 | delete_file_handler (remote_desc->fd); |
| 3770 | |
| 3771 | /* For some mysterious reason, wait_for_inferior calls kill instead of |
| 3772 | mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */ |
| 3773 | if (kill_kludge) |
| 3774 | { |
| 3775 | kill_kludge = 0; |
| 3776 | target_mourn_inferior (); |
| 3777 | return; |
| 3778 | } |
| 3779 | |
| 3780 | /* Use catch_errors so the user can quit from gdb even when we aren't on |
| 3781 | speaking terms with the remote system. */ |
| 3782 | catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR); |
| 3783 | |
| 3784 | /* Don't wait for it to die. I'm not really sure it matters whether |
| 3785 | we do or not. For the existing stubs, kill is a noop. */ |
| 3786 | target_mourn_inferior (); |
| 3787 | } |
| 3788 | |
| 3789 | static void |
| 3790 | remote_mourn () |
| 3791 | { |
| 3792 | remote_mourn_1 (&remote_ops); |
| 3793 | } |
| 3794 | |
| 3795 | static void |
| 3796 | remote_async_mourn () |
| 3797 | { |
| 3798 | remote_mourn_1 (&remote_async_ops); |
| 3799 | } |
| 3800 | |
| 3801 | static void |
| 3802 | extended_remote_mourn () |
| 3803 | { |
| 3804 | /* We do _not_ want to mourn the target like this; this will |
| 3805 | remove the extended remote target from the target stack, |
| 3806 | and the next time the user says "run" it'll fail. |
| 3807 | |
| 3808 | FIXME: What is the right thing to do here? */ |
| 3809 | #if 0 |
| 3810 | remote_mourn_1 (&extended_remote_ops); |
| 3811 | #endif |
| 3812 | } |
| 3813 | |
| 3814 | /* Worker function for remote_mourn. */ |
| 3815 | static void |
| 3816 | remote_mourn_1 (target) |
| 3817 | struct target_ops *target; |
| 3818 | { |
| 3819 | unpush_target (target); |
| 3820 | generic_mourn_inferior (); |
| 3821 | } |
| 3822 | |
| 3823 | /* In the extended protocol we want to be able to do things like |
| 3824 | "run" and have them basically work as expected. So we need |
| 3825 | a special create_inferior function. |
| 3826 | |
| 3827 | FIXME: One day add support for changing the exec file |
| 3828 | we're debugging, arguments and an environment. */ |
| 3829 | |
| 3830 | static void |
| 3831 | extended_remote_create_inferior (exec_file, args, env) |
| 3832 | char *exec_file; |
| 3833 | char *args; |
| 3834 | char **env; |
| 3835 | { |
| 3836 | /* Rip out the breakpoints; we'll reinsert them after restarting |
| 3837 | the remote server. */ |
| 3838 | remove_breakpoints (); |
| 3839 | |
| 3840 | /* Now restart the remote server. */ |
| 3841 | extended_remote_restart (); |
| 3842 | |
| 3843 | /* Now put the breakpoints back in. This way we're safe if the |
| 3844 | restart function works via a unix fork on the remote side. */ |
| 3845 | insert_breakpoints (); |
| 3846 | |
| 3847 | /* Clean up from the last time we were running. */ |
| 3848 | clear_proceed_status (); |
| 3849 | |
| 3850 | /* Let the remote process run. */ |
| 3851 | proceed (-1, TARGET_SIGNAL_0, 0); |
| 3852 | } |
| 3853 | |
| 3854 | /* Async version of extended_remote_create_inferior. */ |
| 3855 | static void |
| 3856 | extended_remote_async_create_inferior (exec_file, args, env) |
| 3857 | char *exec_file; |
| 3858 | char *args; |
| 3859 | char **env; |
| 3860 | { |
| 3861 | /* Rip out the breakpoints; we'll reinsert them after restarting |
| 3862 | the remote server. */ |
| 3863 | remove_breakpoints (); |
| 3864 | |
| 3865 | /* If running asynchronously, register the target file descriptor |
| 3866 | with the event loop. */ |
| 3867 | if (async_p) |
| 3868 | add_file_handler (remote_desc->fd, fetch_inferior_event, 0); |
| 3869 | |
| 3870 | /* Now restart the remote server. */ |
| 3871 | extended_remote_restart (); |
| 3872 | |
| 3873 | /* Now put the breakpoints back in. This way we're safe if the |
| 3874 | restart function works via a unix fork on the remote side. */ |
| 3875 | insert_breakpoints (); |
| 3876 | |
| 3877 | /* Clean up from the last time we were running. */ |
| 3878 | clear_proceed_status (); |
| 3879 | |
| 3880 | /* Let the remote process run. */ |
| 3881 | proceed (-1, TARGET_SIGNAL_0, 0); |
| 3882 | } |
| 3883 | \f |
| 3884 | |
| 3885 | /* On some machines, e.g. 68k, we may use a different breakpoint instruction |
| 3886 | than other targets; in those use REMOTE_BREAKPOINT instead of just |
| 3887 | BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT |
| 3888 | and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call |
| 3889 | the standard routines that are in mem-break.c. */ |
| 3890 | |
| 3891 | /* FIXME, these ought to be done in a more dynamic fashion. For instance, |
| 3892 | the choice of breakpoint instruction affects target program design and |
| 3893 | vice versa, and by making it user-tweakable, the special code here |
| 3894 | goes away and we need fewer special GDB configurations. */ |
| 3895 | |
| 3896 | #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT) |
| 3897 | #define REMOTE_BREAKPOINT |
| 3898 | #endif |
| 3899 | |
| 3900 | #ifdef REMOTE_BREAKPOINT |
| 3901 | |
| 3902 | /* If the target isn't bi-endian, just pretend it is. */ |
| 3903 | #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT) |
| 3904 | #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT |
| 3905 | #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT |
| 3906 | #endif |
| 3907 | |
| 3908 | static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT; |
| 3909 | static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT; |
| 3910 | |
| 3911 | #endif /* REMOTE_BREAKPOINT */ |
| 3912 | |
| 3913 | /* Insert a breakpoint on targets that don't have any better breakpoint |
| 3914 | support. We read the contents of the target location and stash it, |
| 3915 | then overwrite it with a breakpoint instruction. ADDR is the target |
| 3916 | location in the target machine. CONTENTS_CACHE is a pointer to |
| 3917 | memory allocated for saving the target contents. It is guaranteed |
| 3918 | by the caller to be long enough to save sizeof BREAKPOINT bytes (this |
| 3919 | is accomplished via BREAKPOINT_MAX). */ |
| 3920 | |
| 3921 | static int |
| 3922 | remote_insert_breakpoint (addr, contents_cache) |
| 3923 | CORE_ADDR addr; |
| 3924 | char *contents_cache; |
| 3925 | { |
| 3926 | #ifdef REMOTE_BREAKPOINT |
| 3927 | int val; |
| 3928 | #endif |
| 3929 | int bp_size; |
| 3930 | |
| 3931 | /* Try the "Z" packet if it is not already disabled. |
| 3932 | If it succeeds, then set the support to PACKET_ENABLE. |
| 3933 | If it fails, and the user has explicitly requested the Z support |
| 3934 | then report an error, otherwise, mark it disabled and go on. */ |
| 3935 | |
| 3936 | if ((remote_protocol_Z.support == PACKET_ENABLE) |
| 3937 | || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN)) |
| 3938 | { |
| 3939 | char buf[PBUFSIZ], *p = buf; |
| 3940 | |
| 3941 | addr = remote_address_masked (addr); |
| 3942 | *(p++) = 'Z'; |
| 3943 | *(p++) = '0'; |
| 3944 | *(p++) = ','; |
| 3945 | p += hexnumstr (p, (ULONGEST) addr); |
| 3946 | BREAKPOINT_FROM_PC (&addr, &bp_size); |
| 3947 | sprintf (p, ",%d", bp_size); |
| 3948 | |
| 3949 | putpkt (buf); |
| 3950 | getpkt (buf, 0); |
| 3951 | |
| 3952 | if (buf[0] != '\0') |
| 3953 | { |
| 3954 | remote_protocol_Z.support = PACKET_ENABLE; |
| 3955 | return (buf[0] == 'E'); |
| 3956 | } |
| 3957 | |
| 3958 | /* The stub does not support the 'Z' request. If the user has |
| 3959 | explicitly requested the Z support, or if the stub previously |
| 3960 | said it supported the packet, this is an error, |
| 3961 | otherwise, mark it disabled. */ |
| 3962 | |
| 3963 | else if (remote_protocol_Z.support == PACKET_ENABLE) |
| 3964 | { |
| 3965 | error ("Protocol error: Z packet not recognized by stub"); |
| 3966 | } |
| 3967 | else |
| 3968 | { |
| 3969 | remote_protocol_Z.support = PACKET_DISABLE; |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | #ifdef REMOTE_BREAKPOINT |
| 3974 | val = target_read_memory (addr, contents_cache, sizeof big_break_insn); |
| 3975 | |
| 3976 | if (val == 0) |
| 3977 | { |
| 3978 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 3979 | val = target_write_memory (addr, (char *) big_break_insn, |
| 3980 | sizeof big_break_insn); |
| 3981 | else |
| 3982 | val = target_write_memory (addr, (char *) little_break_insn, |
| 3983 | sizeof little_break_insn); |
| 3984 | } |
| 3985 | |
| 3986 | return val; |
| 3987 | #else |
| 3988 | return memory_insert_breakpoint (addr, contents_cache); |
| 3989 | #endif /* REMOTE_BREAKPOINT */ |
| 3990 | } |
| 3991 | |
| 3992 | static int |
| 3993 | remote_remove_breakpoint (addr, contents_cache) |
| 3994 | CORE_ADDR addr; |
| 3995 | char *contents_cache; |
| 3996 | { |
| 3997 | char buf[PBUFSIZ]; |
| 3998 | int bp_size; |
| 3999 | |
| 4000 | if ((remote_protocol_Z.support == PACKET_ENABLE) |
| 4001 | || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN)) |
| 4002 | { |
| 4003 | char buf[PBUFSIZ], *p = buf; |
| 4004 | |
| 4005 | *(p++) = 'z'; |
| 4006 | *(p++) = '0'; |
| 4007 | *(p++) = ','; |
| 4008 | |
| 4009 | addr = remote_address_masked (addr); |
| 4010 | p += hexnumstr (p, (ULONGEST) addr); |
| 4011 | BREAKPOINT_FROM_PC (&addr, &bp_size); |
| 4012 | sprintf (p, ",%d", bp_size); |
| 4013 | |
| 4014 | putpkt (buf); |
| 4015 | getpkt (buf, 0); |
| 4016 | |
| 4017 | return (buf[0] == 'E'); |
| 4018 | } |
| 4019 | |
| 4020 | #ifdef REMOTE_BREAKPOINT |
| 4021 | return target_write_memory (addr, contents_cache, sizeof big_break_insn); |
| 4022 | #else |
| 4023 | return memory_remove_breakpoint (addr, contents_cache); |
| 4024 | #endif /* REMOTE_BREAKPOINT */ |
| 4025 | } |
| 4026 | |
| 4027 | #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS |
| 4028 | int |
| 4029 | remote_insert_watchpoint (addr, len, type) |
| 4030 | CORE_ADDR addr; |
| 4031 | int len; |
| 4032 | int type; |
| 4033 | { |
| 4034 | char buf[PBUFSIZ], *p; |
| 4035 | |
| 4036 | if (remote_protocol_Z.support == PACKET_DISABLE) |
| 4037 | error ("Can't set hardware watchpoints without the 'Z' packet\n"); |
| 4038 | |
| 4039 | sprintf (buf, "Z%x,", type + 2 ); |
| 4040 | p = strchr (buf, '\0'); |
| 4041 | addr = remote_address_masked (addr); |
| 4042 | p += hexnumstr (p, (ULONGEST) addr); |
| 4043 | sprintf (p, ",%lx", len); |
| 4044 | |
| 4045 | putpkt (buf); |
| 4046 | getpkt (buf, 0); |
| 4047 | |
| 4048 | if (buf[0] == '\0' || buf [0] == 'E') |
| 4049 | return -1; |
| 4050 | |
| 4051 | return 0; |
| 4052 | } |
| 4053 | |
| 4054 | int |
| 4055 | remote_remove_watchpoint (addr, len, type) |
| 4056 | CORE_ADDR addr; |
| 4057 | int len; |
| 4058 | int type; |
| 4059 | { |
| 4060 | char buf[PBUFSIZ], *p; |
| 4061 | |
| 4062 | sprintf (buf, "z%x,", type + 2 ); |
| 4063 | p = strchr (buf, '\0'); |
| 4064 | addr = remote_address_masked (addr); |
| 4065 | p += hexnumstr (p, (ULONGEST) addr); |
| 4066 | sprintf (p, ",%lx", len); |
| 4067 | putpkt (buf); |
| 4068 | getpkt (buf, 0); |
| 4069 | |
| 4070 | if (buf[0] == '\0' || buf [0] == 'E') |
| 4071 | return -1; |
| 4072 | |
| 4073 | return 0; |
| 4074 | } |
| 4075 | |
| 4076 | int |
| 4077 | remote_insert_hw_breakpoint (addr, len) |
| 4078 | CORE_ADDR addr; |
| 4079 | int len; |
| 4080 | { |
| 4081 | char buf[PBUFSIZ], *p = buf; |
| 4082 | |
| 4083 | if (remote_protocol_Z.support == PACKET_DISABLE) |
| 4084 | error ("Can't set hardware breakpoints without the 'Z' packet\n"); |
| 4085 | |
| 4086 | *(p++) = 'Z'; |
| 4087 | *(p++) = '1'; |
| 4088 | *(p++) = ','; |
| 4089 | |
| 4090 | addr = remote_address_masked (addr); |
| 4091 | p += hexnumstr (p, (ULONGEST) addr); |
| 4092 | *p = '\0'; |
| 4093 | |
| 4094 | putpkt (buf); |
| 4095 | getpkt (buf, 0); |
| 4096 | |
| 4097 | if (buf[0] == '\0' || buf [0] == 'E') |
| 4098 | return -1; |
| 4099 | |
| 4100 | return 0; |
| 4101 | } |
| 4102 | |
| 4103 | int |
| 4104 | remote_remove_hw_breakpoint (addr, len) |
| 4105 | CORE_ADDR addr; |
| 4106 | int len; |
| 4107 | { |
| 4108 | char buf[PBUFSIZ], *p = buf; |
| 4109 | |
| 4110 | *(p++) = 'z'; |
| 4111 | *(p++) = '1'; |
| 4112 | *(p++) = ','; |
| 4113 | |
| 4114 | addr = remote_address_masked (addr); |
| 4115 | p += hexnumstr (p, (ULONGEST) addr); |
| 4116 | *p = '\0'; |
| 4117 | |
| 4118 | putpkt(buf); |
| 4119 | getpkt (buf, 0); |
| 4120 | |
| 4121 | if (buf[0] == '\0' || buf [0] == 'E') |
| 4122 | return -1; |
| 4123 | |
| 4124 | return 0; |
| 4125 | } |
| 4126 | #endif |
| 4127 | |
| 4128 | /* Some targets are only capable of doing downloads, and afterwards |
| 4129 | they switch to the remote serial protocol. This function provides |
| 4130 | a clean way to get from the download target to the remote target. |
| 4131 | It's basically just a wrapper so that we don't have to expose any |
| 4132 | of the internal workings of remote.c. |
| 4133 | |
| 4134 | Prior to calling this routine, you should shutdown the current |
| 4135 | target code, else you will get the "A program is being debugged |
| 4136 | already..." message. Usually a call to pop_target() suffices. */ |
| 4137 | |
| 4138 | void |
| 4139 | push_remote_target (name, from_tty) |
| 4140 | char *name; |
| 4141 | int from_tty; |
| 4142 | { |
| 4143 | printf_filtered ("Switching to remote protocol\n"); |
| 4144 | remote_open (name, from_tty); |
| 4145 | } |
| 4146 | |
| 4147 | /* Other targets want to use the entire remote serial module but with |
| 4148 | certain remote_ops overridden. */ |
| 4149 | |
| 4150 | void |
| 4151 | open_remote_target (name, from_tty, target, extended_p) |
| 4152 | char *name; |
| 4153 | int from_tty; |
| 4154 | struct target_ops *target; |
| 4155 | int extended_p; |
| 4156 | { |
| 4157 | printf_filtered ("Selecting the %sremote protocol\n", |
| 4158 | (extended_p ? "extended-" : "")); |
| 4159 | remote_open_1 (name, from_tty, target, extended_p); |
| 4160 | } |
| 4161 | |
| 4162 | /* Table used by the crc32 function to calcuate the checksum. */ |
| 4163 | |
| 4164 | static unsigned long crc32_table[256] = |
| 4165 | {0, 0}; |
| 4166 | |
| 4167 | static unsigned long |
| 4168 | crc32 (buf, len, crc) |
| 4169 | unsigned char *buf; |
| 4170 | int len; |
| 4171 | unsigned int crc; |
| 4172 | { |
| 4173 | if (!crc32_table[1]) |
| 4174 | { |
| 4175 | /* Initialize the CRC table and the decoding table. */ |
| 4176 | int i, j; |
| 4177 | unsigned int c; |
| 4178 | |
| 4179 | for (i = 0; i < 256; i++) |
| 4180 | { |
| 4181 | for (c = i << 24, j = 8; j > 0; --j) |
| 4182 | c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); |
| 4183 | crc32_table[i] = c; |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | while (len--) |
| 4188 | { |
| 4189 | crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255]; |
| 4190 | buf++; |
| 4191 | } |
| 4192 | return crc; |
| 4193 | } |
| 4194 | |
| 4195 | /* compare-sections command |
| 4196 | |
| 4197 | With no arguments, compares each loadable section in the exec bfd |
| 4198 | with the same memory range on the target, and reports mismatches. |
| 4199 | Useful for verifying the image on the target against the exec file. |
| 4200 | Depends on the target understanding the new "qCRC:" request. */ |
| 4201 | |
| 4202 | static void |
| 4203 | compare_sections_command (args, from_tty) |
| 4204 | char *args; |
| 4205 | int from_tty; |
| 4206 | { |
| 4207 | asection *s; |
| 4208 | unsigned long host_crc, target_crc; |
| 4209 | extern bfd *exec_bfd; |
| 4210 | struct cleanup *old_chain; |
| 4211 | char *tmp; |
| 4212 | char *sectdata; |
| 4213 | char *sectname; |
| 4214 | char *buf = alloca (PBUFSIZ); |
| 4215 | bfd_size_type size; |
| 4216 | bfd_vma lma; |
| 4217 | int matched = 0; |
| 4218 | int mismatched = 0; |
| 4219 | |
| 4220 | if (!exec_bfd) |
| 4221 | error ("command cannot be used without an exec file"); |
| 4222 | if (!current_target.to_shortname || |
| 4223 | strcmp (current_target.to_shortname, "remote") != 0) |
| 4224 | error ("command can only be used with remote target"); |
| 4225 | |
| 4226 | for (s = exec_bfd->sections; s; s = s->next) |
| 4227 | { |
| 4228 | if (!(s->flags & SEC_LOAD)) |
| 4229 | continue; /* skip non-loadable section */ |
| 4230 | |
| 4231 | size = bfd_get_section_size_before_reloc (s); |
| 4232 | if (size == 0) |
| 4233 | continue; /* skip zero-length section */ |
| 4234 | |
| 4235 | sectname = (char *) bfd_get_section_name (exec_bfd, s); |
| 4236 | if (args && strcmp (args, sectname) != 0) |
| 4237 | continue; /* not the section selected by user */ |
| 4238 | |
| 4239 | matched = 1; /* do this section */ |
| 4240 | lma = s->lma; |
| 4241 | /* FIXME: assumes lma can fit into long */ |
| 4242 | sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size); |
| 4243 | putpkt (buf); |
| 4244 | |
| 4245 | /* be clever; compute the host_crc before waiting for target reply */ |
| 4246 | sectdata = xmalloc (size); |
| 4247 | old_chain = make_cleanup (free, sectdata); |
| 4248 | bfd_get_section_contents (exec_bfd, s, sectdata, 0, size); |
| 4249 | host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff); |
| 4250 | |
| 4251 | getpkt (buf, 0); |
| 4252 | if (buf[0] == 'E') |
| 4253 | error ("target memory fault, section %s, range 0x%08x -- 0x%08x", |
| 4254 | sectname, lma, lma + size); |
| 4255 | if (buf[0] != 'C') |
| 4256 | error ("remote target does not support this operation"); |
| 4257 | |
| 4258 | for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++) |
| 4259 | target_crc = target_crc * 16 + fromhex (*tmp); |
| 4260 | |
| 4261 | printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ", |
| 4262 | sectname, lma, lma + size); |
| 4263 | if (host_crc == target_crc) |
| 4264 | printf_filtered ("matched.\n"); |
| 4265 | else |
| 4266 | { |
| 4267 | printf_filtered ("MIS-MATCHED!\n"); |
| 4268 | mismatched++; |
| 4269 | } |
| 4270 | |
| 4271 | do_cleanups (old_chain); |
| 4272 | } |
| 4273 | if (mismatched > 0) |
| 4274 | warning ("One or more sections of the remote executable does not match\n\ |
| 4275 | the loaded file\n"); |
| 4276 | if (args && !matched) |
| 4277 | printf_filtered ("No loaded section named '%s'.\n", args); |
| 4278 | } |
| 4279 | |
| 4280 | static int |
| 4281 | remote_query (query_type, buf, outbuf, bufsiz) |
| 4282 | int query_type; |
| 4283 | char *buf; |
| 4284 | char *outbuf; |
| 4285 | int *bufsiz; |
| 4286 | { |
| 4287 | int i; |
| 4288 | char *buf2 = alloca (PBUFSIZ); |
| 4289 | char *p2 = &buf2[0]; |
| 4290 | char *p = buf; |
| 4291 | |
| 4292 | if (!bufsiz) |
| 4293 | error ("null pointer to remote bufer size specified"); |
| 4294 | |
| 4295 | /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let |
| 4296 | the caller know and return what the minimum size is */ |
| 4297 | /* Note: a zero bufsiz can be used to query the minimum buffer size */ |
| 4298 | if (*bufsiz < PBUFSIZ) |
| 4299 | { |
| 4300 | *bufsiz = PBUFSIZ; |
| 4301 | return -1; |
| 4302 | } |
| 4303 | |
| 4304 | /* except for querying the minimum buffer size, target must be open */ |
| 4305 | if (!remote_desc) |
| 4306 | error ("remote query is only available after target open"); |
| 4307 | |
| 4308 | /* we only take uppercase letters as query types, at least for now */ |
| 4309 | if ((query_type < 'A') || (query_type > 'Z')) |
| 4310 | error ("invalid remote query type"); |
| 4311 | |
| 4312 | if (!buf) |
| 4313 | error ("null remote query specified"); |
| 4314 | |
| 4315 | if (!outbuf) |
| 4316 | error ("remote query requires a buffer to receive data"); |
| 4317 | |
| 4318 | outbuf[0] = '\0'; |
| 4319 | |
| 4320 | *p2++ = 'q'; |
| 4321 | *p2++ = query_type; |
| 4322 | |
| 4323 | /* we used one buffer char for the remote protocol q command and another |
| 4324 | for the query type. As the remote protocol encapsulation uses 4 chars |
| 4325 | plus one extra in case we are debugging (remote_debug), |
| 4326 | we have PBUFZIZ - 7 left to pack the query string */ |
| 4327 | i = 0; |
| 4328 | while (buf[i] && (i < (PBUFSIZ - 8))) |
| 4329 | { |
| 4330 | /* bad caller may have sent forbidden characters */ |
| 4331 | if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#')) |
| 4332 | error ("illegal characters in query string"); |
| 4333 | |
| 4334 | *p2++ = buf[i]; |
| 4335 | i++; |
| 4336 | } |
| 4337 | *p2 = buf[i]; |
| 4338 | |
| 4339 | if (buf[i]) |
| 4340 | error ("query larger than available buffer"); |
| 4341 | |
| 4342 | i = putpkt (buf2); |
| 4343 | if (i < 0) |
| 4344 | return i; |
| 4345 | |
| 4346 | getpkt (outbuf, 0); |
| 4347 | |
| 4348 | return 0; |
| 4349 | } |
| 4350 | |
| 4351 | static void |
| 4352 | remote_rcmd (char *command, |
| 4353 | struct gdb_file *outbuf) |
| 4354 | { |
| 4355 | int i; |
| 4356 | char *buf = alloca (PBUFSIZ); |
| 4357 | char *p = buf; |
| 4358 | |
| 4359 | if (!remote_desc) |
| 4360 | error ("remote rcmd is only available after target open"); |
| 4361 | |
| 4362 | /* Send a NULL command across as an empty command */ |
| 4363 | if (command == NULL) |
| 4364 | command = ""; |
| 4365 | |
| 4366 | /* The query prefix */ |
| 4367 | strcpy (buf, "qRcmd,"); |
| 4368 | p = strchr (buf, '\0'); |
| 4369 | |
| 4370 | if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ) |
| 4371 | error ("\"monitor\" command ``%s'' is too long\n", command); |
| 4372 | |
| 4373 | /* Encode the actual command */ |
| 4374 | for (i = 0; command[i]; i++) |
| 4375 | { |
| 4376 | *p++ = tohex ((command[i] >> 4) & 0xf); |
| 4377 | *p++ = tohex (command[i] & 0xf); |
| 4378 | } |
| 4379 | *p = '\0'; |
| 4380 | |
| 4381 | if (putpkt (buf) < 0) |
| 4382 | error ("Communication problem with target\n"); |
| 4383 | |
| 4384 | /* get/display the response */ |
| 4385 | while (1) |
| 4386 | { |
| 4387 | /* XXX - see also tracepoint.c:remote_get_noisy_reply() */ |
| 4388 | buf[0] = '\0'; |
| 4389 | getpkt (buf, 0); |
| 4390 | if (buf[0] == '\0') |
| 4391 | error ("Target does not support this command\n"); |
| 4392 | if (buf[0] == 'O' && buf[1] != 'K') |
| 4393 | { |
| 4394 | remote_console_output (buf + 1); /* 'O' message from stub */ |
| 4395 | continue; |
| 4396 | } |
| 4397 | if (strcmp (buf, "OK") == 0) |
| 4398 | break; |
| 4399 | if (strlen (buf) == 3 && buf[0] == 'E' |
| 4400 | && isdigit (buf[1]) && isdigit (buf[2])) |
| 4401 | { |
| 4402 | error ("Protocol error with Rcmd"); |
| 4403 | } |
| 4404 | for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2) |
| 4405 | { |
| 4406 | char c = (fromhex (p[0]) << 4) + fromhex (p[1]); |
| 4407 | fputc_unfiltered (c, outbuf); |
| 4408 | } |
| 4409 | break; |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | static void |
| 4414 | packet_command (args, from_tty) |
| 4415 | char *args; |
| 4416 | int from_tty; |
| 4417 | { |
| 4418 | char *buf = alloca (PBUFSIZ); |
| 4419 | |
| 4420 | if (!remote_desc) |
| 4421 | error ("command can only be used with remote target"); |
| 4422 | |
| 4423 | if (!args) |
| 4424 | error ("remote-packet command requires packet text as argument"); |
| 4425 | |
| 4426 | puts_filtered ("sending: "); |
| 4427 | print_packet (args); |
| 4428 | puts_filtered ("\n"); |
| 4429 | putpkt (args); |
| 4430 | |
| 4431 | getpkt (buf, 0); |
| 4432 | puts_filtered ("received: "); |
| 4433 | print_packet (buf); |
| 4434 | puts_filtered ("\n"); |
| 4435 | } |
| 4436 | |
| 4437 | #if 0 |
| 4438 | /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */ |
| 4439 | |
| 4440 | static void display_thread_info PARAMS ((struct gdb_ext_thread_info * info)); |
| 4441 | |
| 4442 | static void threadset_test_cmd PARAMS ((char *cmd, int tty)); |
| 4443 | |
| 4444 | static void threadalive_test PARAMS ((char *cmd, int tty)); |
| 4445 | |
| 4446 | static void threadlist_test_cmd PARAMS ((char *cmd, int tty)); |
| 4447 | |
| 4448 | int get_and_display_threadinfo PARAMS ((threadref * ref)); |
| 4449 | |
| 4450 | static void threadinfo_test_cmd PARAMS ((char *cmd, int tty)); |
| 4451 | |
| 4452 | static int thread_display_step PARAMS ((threadref * ref, void *context)); |
| 4453 | |
| 4454 | static void threadlist_update_test_cmd PARAMS ((char *cmd, int tty)); |
| 4455 | |
| 4456 | static void init_remote_threadtests PARAMS ((void)); |
| 4457 | |
| 4458 | #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */ |
| 4459 | |
| 4460 | static void |
| 4461 | threadset_test_cmd (cmd, tty) |
| 4462 | char *cmd; |
| 4463 | int tty; |
| 4464 | { |
| 4465 | int sample_thread = SAMPLE_THREAD; |
| 4466 | |
| 4467 | printf_filtered ("Remote threadset test\n"); |
| 4468 | set_thread (sample_thread, 1); |
| 4469 | } |
| 4470 | |
| 4471 | |
| 4472 | static void |
| 4473 | threadalive_test (cmd, tty) |
| 4474 | char *cmd; |
| 4475 | int tty; |
| 4476 | { |
| 4477 | int sample_thread = SAMPLE_THREAD; |
| 4478 | |
| 4479 | if (remote_thread_alive (sample_thread)) |
| 4480 | printf_filtered ("PASS: Thread alive test\n"); |
| 4481 | else |
| 4482 | printf_filtered ("FAIL: Thread alive test\n"); |
| 4483 | } |
| 4484 | |
| 4485 | void output_threadid PARAMS ((char *title, threadref * ref)); |
| 4486 | |
| 4487 | void |
| 4488 | output_threadid (title, ref) |
| 4489 | char *title; |
| 4490 | threadref *ref; |
| 4491 | { |
| 4492 | char hexid[20]; |
| 4493 | |
| 4494 | pack_threadid (&hexid[0], ref); /* Convert threead id into hex */ |
| 4495 | hexid[16] = 0; |
| 4496 | printf_filtered ("%s %s\n", title, (&hexid[0])); |
| 4497 | } |
| 4498 | |
| 4499 | static void |
| 4500 | threadlist_test_cmd (cmd, tty) |
| 4501 | char *cmd; |
| 4502 | int tty; |
| 4503 | { |
| 4504 | int startflag = 1; |
| 4505 | threadref nextthread; |
| 4506 | int done, result_count; |
| 4507 | threadref threadlist[3]; |
| 4508 | |
| 4509 | printf_filtered ("Remote Threadlist test\n"); |
| 4510 | if (!remote_get_threadlist (startflag, &nextthread, 3, &done, |
| 4511 | &result_count, &threadlist[0])) |
| 4512 | printf_filtered ("FAIL: threadlist test\n"); |
| 4513 | else |
| 4514 | { |
| 4515 | threadref *scan = threadlist; |
| 4516 | threadref *limit = scan + result_count; |
| 4517 | |
| 4518 | while (scan < limit) |
| 4519 | output_threadid (" thread ", scan++); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | void |
| 4524 | display_thread_info (info) |
| 4525 | struct gdb_ext_thread_info *info; |
| 4526 | { |
| 4527 | output_threadid ("Threadid: ", &info->threadid); |
| 4528 | printf_filtered ("Name: %s\n ", info->shortname); |
| 4529 | printf_filtered ("State: %s\n", info->display); |
| 4530 | printf_filtered ("other: %s\n\n", info->more_display); |
| 4531 | } |
| 4532 | |
| 4533 | int |
| 4534 | get_and_display_threadinfo (ref) |
| 4535 | threadref *ref; |
| 4536 | { |
| 4537 | int result; |
| 4538 | int set; |
| 4539 | struct gdb_ext_thread_info threadinfo; |
| 4540 | |
| 4541 | set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME |
| 4542 | | TAG_MOREDISPLAY | TAG_DISPLAY; |
| 4543 | if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo))) |
| 4544 | display_thread_info (&threadinfo); |
| 4545 | return result; |
| 4546 | } |
| 4547 | |
| 4548 | static void |
| 4549 | threadinfo_test_cmd (cmd, tty) |
| 4550 | char *cmd; |
| 4551 | int tty; |
| 4552 | { |
| 4553 | int athread = SAMPLE_THREAD; |
| 4554 | threadref thread; |
| 4555 | int set; |
| 4556 | |
| 4557 | int_to_threadref (&thread, athread); |
| 4558 | printf_filtered ("Remote Threadinfo test\n"); |
| 4559 | if (!get_and_display_threadinfo (&thread)) |
| 4560 | printf_filtered ("FAIL cannot get thread info\n"); |
| 4561 | } |
| 4562 | |
| 4563 | static int |
| 4564 | thread_display_step (ref, context) |
| 4565 | threadref *ref; |
| 4566 | void *context; |
| 4567 | { |
| 4568 | /* output_threadid(" threadstep ",ref); *//* simple test */ |
| 4569 | return get_and_display_threadinfo (ref); |
| 4570 | } |
| 4571 | |
| 4572 | static void |
| 4573 | threadlist_update_test_cmd (cmd, tty) |
| 4574 | char *cmd; |
| 4575 | int tty; |
| 4576 | { |
| 4577 | printf_filtered ("Remote Threadlist update test\n"); |
| 4578 | remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS); |
| 4579 | } |
| 4580 | |
| 4581 | static void |
| 4582 | init_remote_threadtests (void) |
| 4583 | { |
| 4584 | add_com ("tlist", class_obscure, threadlist_test_cmd, |
| 4585 | "Fetch and print the remote list of thread identifiers, one pkt only"); |
| 4586 | add_com ("tinfo", class_obscure, threadinfo_test_cmd, |
| 4587 | "Fetch and display info about one thread"); |
| 4588 | add_com ("tset", class_obscure, threadset_test_cmd, |
| 4589 | "Test setting to a different thread"); |
| 4590 | add_com ("tupd", class_obscure, threadlist_update_test_cmd, |
| 4591 | "Iterate through updating all remote thread info"); |
| 4592 | add_com ("talive", class_obscure, threadalive_test, |
| 4593 | " Remote thread alive test "); |
| 4594 | } |
| 4595 | |
| 4596 | #endif /* 0 */ |
| 4597 | |
| 4598 | static void |
| 4599 | init_remote_ops () |
| 4600 | { |
| 4601 | remote_ops.to_shortname = "remote"; |
| 4602 | remote_ops.to_longname = "Remote serial target in gdb-specific protocol"; |
| 4603 | remote_ops.to_doc = |
| 4604 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
| 4605 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
| 4606 | remote_ops.to_open = remote_open; |
| 4607 | remote_ops.to_close = remote_close; |
| 4608 | remote_ops.to_detach = remote_detach; |
| 4609 | remote_ops.to_resume = remote_resume; |
| 4610 | remote_ops.to_wait = remote_wait; |
| 4611 | remote_ops.to_fetch_registers = remote_fetch_registers; |
| 4612 | remote_ops.to_store_registers = remote_store_registers; |
| 4613 | remote_ops.to_prepare_to_store = remote_prepare_to_store; |
| 4614 | remote_ops.to_xfer_memory = remote_xfer_memory; |
| 4615 | remote_ops.to_files_info = remote_files_info; |
| 4616 | remote_ops.to_insert_breakpoint = remote_insert_breakpoint; |
| 4617 | remote_ops.to_remove_breakpoint = remote_remove_breakpoint; |
| 4618 | remote_ops.to_kill = remote_kill; |
| 4619 | remote_ops.to_load = generic_load; |
| 4620 | remote_ops.to_mourn_inferior = remote_mourn; |
| 4621 | remote_ops.to_thread_alive = remote_thread_alive; |
| 4622 | remote_ops.to_find_new_threads = remote_threads_info; |
| 4623 | remote_ops.to_stop = remote_stop; |
| 4624 | remote_ops.to_query = remote_query; |
| 4625 | remote_ops.to_rcmd = remote_rcmd; |
| 4626 | remote_ops.to_stratum = process_stratum; |
| 4627 | remote_ops.to_has_all_memory = 1; |
| 4628 | remote_ops.to_has_memory = 1; |
| 4629 | remote_ops.to_has_stack = 1; |
| 4630 | remote_ops.to_has_registers = 1; |
| 4631 | remote_ops.to_has_execution = 1; |
| 4632 | remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */ |
| 4633 | remote_ops.to_magic = OPS_MAGIC; |
| 4634 | } |
| 4635 | |
| 4636 | /* Set up the extended remote vector by making a copy of the standard |
| 4637 | remote vector and adding to it. */ |
| 4638 | |
| 4639 | static void |
| 4640 | init_extended_remote_ops () |
| 4641 | { |
| 4642 | extended_remote_ops = remote_ops; |
| 4643 | |
| 4644 | extended_remote_ops.to_shortname = "extended-remote"; |
| 4645 | extended_remote_ops.to_longname = |
| 4646 | "Extended remote serial target in gdb-specific protocol"; |
| 4647 | extended_remote_ops.to_doc = |
| 4648 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
| 4649 | Specify the serial device it is connected to (e.g. /dev/ttya).", |
| 4650 | extended_remote_ops.to_open = extended_remote_open; |
| 4651 | extended_remote_ops.to_create_inferior = extended_remote_create_inferior; |
| 4652 | extended_remote_ops.to_mourn_inferior = extended_remote_mourn; |
| 4653 | } |
| 4654 | |
| 4655 | /* |
| 4656 | * Command: info remote-process |
| 4657 | * |
| 4658 | * This implements Cisco's version of the "info proc" command. |
| 4659 | * |
| 4660 | * This query allows the target stub to return an arbitrary string |
| 4661 | * (or strings) giving arbitrary information about the target process. |
| 4662 | * This is optional; the target stub isn't required to implement it. |
| 4663 | * |
| 4664 | * Syntax: qfProcessInfo request first string |
| 4665 | * qsProcessInfo request subsequent string |
| 4666 | * reply: 'O'<hex-encoded-string> |
| 4667 | * 'l' last reply (empty) |
| 4668 | */ |
| 4669 | |
| 4670 | static void |
| 4671 | remote_info_process (args, from_tty) |
| 4672 | char *args; |
| 4673 | int from_tty; |
| 4674 | { |
| 4675 | char *buf = alloca (PBUFSIZ); |
| 4676 | |
| 4677 | if (remote_desc == 0) |
| 4678 | error ("Command can only be used when connected to the remote target."); |
| 4679 | |
| 4680 | putpkt ("qfProcessInfo"); |
| 4681 | getpkt (buf, 0); |
| 4682 | if (buf[0] == 0) |
| 4683 | return; /* Silently: target does not support this feature. */ |
| 4684 | |
| 4685 | if (buf[0] == 'E') |
| 4686 | error ("info proc: target error."); |
| 4687 | |
| 4688 | while (buf[0] == 'O') /* Capitol-O packet */ |
| 4689 | { |
| 4690 | remote_console_output (&buf[1]); |
| 4691 | putpkt ("qsProcessInfo"); |
| 4692 | getpkt (buf, 0); |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | /* |
| 4697 | * Target Cisco |
| 4698 | */ |
| 4699 | |
| 4700 | static void |
| 4701 | remote_cisco_open (name, from_tty) |
| 4702 | char *name; |
| 4703 | int from_tty; |
| 4704 | { |
| 4705 | if (name == 0) |
| 4706 | error ( |
| 4707 | "To open a remote debug connection, you need to specify what \n\ |
| 4708 | device is attached to the remote system (e.g. host:port)."); |
| 4709 | |
| 4710 | target_preopen (from_tty); |
| 4711 | |
| 4712 | unpush_target (&remote_cisco_ops); |
| 4713 | |
| 4714 | remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes); |
| 4715 | |
| 4716 | remote_desc = SERIAL_OPEN (name); |
| 4717 | if (!remote_desc) |
| 4718 | perror_with_name (name); |
| 4719 | |
| 4720 | /* |
| 4721 | * If a baud rate was specified on the gdb command line it will |
| 4722 | * be greater than the initial value of -1. If it is, use it otherwise |
| 4723 | * default to 9600 |
| 4724 | */ |
| 4725 | |
| 4726 | baud_rate = (baud_rate > 0) ? baud_rate : 9600; |
| 4727 | if (SERIAL_SETBAUDRATE (remote_desc, baud_rate)) |
| 4728 | { |
| 4729 | SERIAL_CLOSE (remote_desc); |
| 4730 | perror_with_name (name); |
| 4731 | } |
| 4732 | |
| 4733 | SERIAL_RAW (remote_desc); |
| 4734 | |
| 4735 | /* If there is something sitting in the buffer we might take it as a |
| 4736 | response to a command, which would be bad. */ |
| 4737 | SERIAL_FLUSH_INPUT (remote_desc); |
| 4738 | |
| 4739 | if (from_tty) |
| 4740 | { |
| 4741 | puts_filtered ("Remote debugging using "); |
| 4742 | puts_filtered (name); |
| 4743 | puts_filtered ("\n"); |
| 4744 | } |
| 4745 | |
| 4746 | remote_cisco_mode = 1; |
| 4747 | |
| 4748 | push_target (&remote_cisco_ops); /* Switch to using cisco target now */ |
| 4749 | |
| 4750 | init_packet_config (&remote_protocol_P); |
| 4751 | init_packet_config (&remote_protocol_Z); |
| 4752 | |
| 4753 | general_thread = -2; |
| 4754 | continue_thread = -2; |
| 4755 | |
| 4756 | /* Force remote_write_bytes to check whether target supports |
| 4757 | binary downloading. */ |
| 4758 | init_packet_config (&remote_protocol_binary_download); |
| 4759 | |
| 4760 | /* Without this, some commands which require an active target (such |
| 4761 | as kill) won't work. This variable serves (at least) double duty |
| 4762 | as both the pid of the target process (if it has such), and as a |
| 4763 | flag indicating that a target is active. These functions should |
| 4764 | be split out into seperate variables, especially since GDB will |
| 4765 | someday have a notion of debugging several processes. */ |
| 4766 | inferior_pid = MAGIC_NULL_PID; |
| 4767 | |
| 4768 | /* Start the remote connection; if error (0), discard this target. */ |
| 4769 | |
| 4770 | if (!catch_errors (remote_start_remote_dummy, (char *) 0, |
| 4771 | "Couldn't establish connection to remote target\n", |
| 4772 | RETURN_MASK_ALL)) |
| 4773 | { |
| 4774 | pop_target (); |
| 4775 | return; |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | static void |
| 4780 | remote_cisco_close (quitting) |
| 4781 | int quitting; |
| 4782 | { |
| 4783 | remote_cisco_mode = 0; |
| 4784 | remote_close (quitting); |
| 4785 | } |
| 4786 | |
| 4787 | static void |
| 4788 | remote_cisco_mourn |
| 4789 | PARAMS ((void)) |
| 4790 | { |
| 4791 | remote_mourn_1 (&remote_cisco_ops); |
| 4792 | } |
| 4793 | |
| 4794 | enum |
| 4795 | { |
| 4796 | READ_MORE, |
| 4797 | FATAL_ERROR, |
| 4798 | ENTER_DEBUG, |
| 4799 | DISCONNECT_TELNET |
| 4800 | } |
| 4801 | minitelnet_return; |
| 4802 | |
| 4803 | /* shared between readsocket() and readtty() */ |
| 4804 | static char *tty_input; |
| 4805 | |
| 4806 | static int escape_count; |
| 4807 | static int echo_check; |
| 4808 | extern int quit_flag; |
| 4809 | |
| 4810 | static int |
| 4811 | readsocket () |
| 4812 | { |
| 4813 | int data; |
| 4814 | |
| 4815 | /* Loop until the socket doesn't have any more data */ |
| 4816 | |
| 4817 | while ((data = readchar (0)) >= 0) |
| 4818 | { |
| 4819 | /* Check for the escape sequence */ |
| 4820 | if (data == '|') |
| 4821 | { |
| 4822 | /* If this is the fourth escape, get out */ |
| 4823 | if (++escape_count == 4) |
| 4824 | { |
| 4825 | return ENTER_DEBUG; |
| 4826 | } |
| 4827 | else |
| 4828 | { /* This is a '|', but not the fourth in a row. |
| 4829 | Continue without echoing it. If it isn't actually |
| 4830 | one of four in a row, it'll be echoed later. */ |
| 4831 | continue; |
| 4832 | } |
| 4833 | } |
| 4834 | else |
| 4835 | /* Not a '|' */ |
| 4836 | { |
| 4837 | /* Ensure any pending '|'s are flushed. */ |
| 4838 | |
| 4839 | for (; escape_count > 0; escape_count--) |
| 4840 | putchar ('|'); |
| 4841 | } |
| 4842 | |
| 4843 | if (data == '\r') /* If this is a return character, */ |
| 4844 | continue; /* - just supress it. */ |
| 4845 | |
| 4846 | if (echo_check != -1) /* Check for echo of user input. */ |
| 4847 | { |
| 4848 | if (tty_input[echo_check] == data) |
| 4849 | { |
| 4850 | echo_check++; /* Character matched user input: */ |
| 4851 | continue; /* Continue without echoing it. */ |
| 4852 | } |
| 4853 | else if ((data == '\n') && (tty_input[echo_check] == '\r')) |
| 4854 | { /* End of the line (and of echo checking). */ |
| 4855 | echo_check = -1; /* No more echo supression */ |
| 4856 | continue; /* Continue without echoing. */ |
| 4857 | } |
| 4858 | else |
| 4859 | { /* Failed check for echo of user input. |
| 4860 | We now have some suppressed output to flush! */ |
| 4861 | int j; |
| 4862 | |
| 4863 | for (j = 0; j < echo_check; j++) |
| 4864 | putchar (tty_input[j]); |
| 4865 | echo_check = -1; |
| 4866 | } |
| 4867 | } |
| 4868 | putchar (data); /* Default case: output the char. */ |
| 4869 | } |
| 4870 | |
| 4871 | if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */ |
| 4872 | return READ_MORE; /* Try to read some more */ |
| 4873 | else |
| 4874 | return FATAL_ERROR; /* Trouble, bail out */ |
| 4875 | } |
| 4876 | |
| 4877 | static int |
| 4878 | readtty () |
| 4879 | { |
| 4880 | int status; |
| 4881 | int tty_bytecount; |
| 4882 | |
| 4883 | /* First, read a buffer full from the terminal */ |
| 4884 | tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1); |
| 4885 | if (tty_bytecount == -1) |
| 4886 | { |
| 4887 | perror ("readtty: read failed"); |
| 4888 | return FATAL_ERROR; |
| 4889 | } |
| 4890 | |
| 4891 | /* Remove a quoted newline. */ |
| 4892 | if (tty_input[tty_bytecount - 1] == '\n' && |
| 4893 | tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */ |
| 4894 | { |
| 4895 | tty_input[--tty_bytecount] = 0; /* remove newline */ |
| 4896 | tty_input[--tty_bytecount] = 0; /* remove backslash */ |
| 4897 | } |
| 4898 | |
| 4899 | /* Turn trailing newlines into returns */ |
| 4900 | if (tty_input[tty_bytecount - 1] == '\n') |
| 4901 | tty_input[tty_bytecount - 1] = '\r'; |
| 4902 | |
| 4903 | /* If the line consists of a ~, enter debugging mode. */ |
| 4904 | if ((tty_input[0] == '~') && (tty_bytecount == 2)) |
| 4905 | return ENTER_DEBUG; |
| 4906 | |
| 4907 | /* Make this a zero terminated string and write it out */ |
| 4908 | tty_input[tty_bytecount] = 0; |
| 4909 | if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount)) |
| 4910 | { |
| 4911 | perror_with_name ("readtty: write failed"); |
| 4912 | return FATAL_ERROR; |
| 4913 | } |
| 4914 | |
| 4915 | return READ_MORE; |
| 4916 | } |
| 4917 | |
| 4918 | static int |
| 4919 | minitelnet () |
| 4920 | { |
| 4921 | fd_set input; /* file descriptors for select */ |
| 4922 | int tablesize; /* max number of FDs for select */ |
| 4923 | int status; |
| 4924 | int quit_count = 0; |
| 4925 | |
| 4926 | extern int escape_count; /* global shared by readsocket */ |
| 4927 | extern int echo_check; /* ditto */ |
| 4928 | |
| 4929 | escape_count = 0; |
| 4930 | echo_check = -1; |
| 4931 | |
| 4932 | tablesize = 8 * sizeof (input); |
| 4933 | |
| 4934 | for (;;) |
| 4935 | { |
| 4936 | /* Check for anything from our socket - doesn't block. Note that |
| 4937 | this must be done *before* the select as there may be |
| 4938 | buffered I/O waiting to be processed. */ |
| 4939 | |
| 4940 | if ((status = readsocket ()) == FATAL_ERROR) |
| 4941 | { |
| 4942 | error ("Debugging terminated by communications error"); |
| 4943 | } |
| 4944 | else if (status != READ_MORE) |
| 4945 | { |
| 4946 | return (status); |
| 4947 | } |
| 4948 | |
| 4949 | fflush (stdout); /* Flush output before blocking */ |
| 4950 | |
| 4951 | /* Now block on more socket input or TTY input */ |
| 4952 | |
| 4953 | FD_ZERO (&input); |
| 4954 | FD_SET (fileno (stdin), &input); |
| 4955 | FD_SET (remote_desc->fd, &input); |
| 4956 | |
| 4957 | status = select (tablesize, &input, 0, 0, 0); |
| 4958 | if ((status == -1) && (errno != EINTR)) |
| 4959 | { |
| 4960 | error ("Communications error on select %d", errno); |
| 4961 | } |
| 4962 | |
| 4963 | /* Handle Control-C typed */ |
| 4964 | |
| 4965 | if (quit_flag) |
| 4966 | { |
| 4967 | if ((++quit_count) == 2) |
| 4968 | { |
| 4969 | if (query ("Interrupt GDB? ")) |
| 4970 | { |
| 4971 | printf_filtered ("Interrupted by user.\n"); |
| 4972 | return_to_top_level (RETURN_QUIT); |
| 4973 | } |
| 4974 | quit_count = 0; |
| 4975 | } |
| 4976 | quit_flag = 0; |
| 4977 | |
| 4978 | if (remote_break) |
| 4979 | SERIAL_SEND_BREAK (remote_desc); |
| 4980 | else |
| 4981 | SERIAL_WRITE (remote_desc, "\003", 1); |
| 4982 | |
| 4983 | continue; |
| 4984 | } |
| 4985 | |
| 4986 | /* Handle console input */ |
| 4987 | |
| 4988 | if (FD_ISSET (fileno (stdin), &input)) |
| 4989 | { |
| 4990 | quit_count = 0; |
| 4991 | echo_check = 0; |
| 4992 | status = readtty (); |
| 4993 | if (status == READ_MORE) |
| 4994 | continue; |
| 4995 | |
| 4996 | return status; /* telnet session ended */ |
| 4997 | } |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | static int |
| 5002 | remote_cisco_wait (pid, status) |
| 5003 | int pid; |
| 5004 | struct target_waitstatus *status; |
| 5005 | { |
| 5006 | if (minitelnet () != ENTER_DEBUG) |
| 5007 | { |
| 5008 | error ("Debugging session terminated by protocol error"); |
| 5009 | } |
| 5010 | putpkt ("?"); |
| 5011 | return remote_wait (pid, status); |
| 5012 | } |
| 5013 | |
| 5014 | static void |
| 5015 | init_remote_cisco_ops () |
| 5016 | { |
| 5017 | remote_cisco_ops.to_shortname = "cisco"; |
| 5018 | remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol"; |
| 5019 | remote_cisco_ops.to_doc = |
| 5020 | "Use a remote machine via TCP, using a cisco-specific protocol.\n\ |
| 5021 | Specify the serial device it is connected to (e.g. host:2020)."; |
| 5022 | remote_cisco_ops.to_open = remote_cisco_open; |
| 5023 | remote_cisco_ops.to_close = remote_cisco_close; |
| 5024 | remote_cisco_ops.to_detach = remote_detach; |
| 5025 | remote_cisco_ops.to_resume = remote_resume; |
| 5026 | remote_cisco_ops.to_wait = remote_cisco_wait; |
| 5027 | remote_cisco_ops.to_fetch_registers = remote_fetch_registers; |
| 5028 | remote_cisco_ops.to_store_registers = remote_store_registers; |
| 5029 | remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store; |
| 5030 | remote_cisco_ops.to_xfer_memory = remote_xfer_memory; |
| 5031 | remote_cisco_ops.to_files_info = remote_files_info; |
| 5032 | remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint; |
| 5033 | remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint; |
| 5034 | remote_cisco_ops.to_kill = remote_kill; |
| 5035 | remote_cisco_ops.to_load = generic_load; |
| 5036 | remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn; |
| 5037 | remote_cisco_ops.to_thread_alive = remote_thread_alive; |
| 5038 | remote_cisco_ops.to_find_new_threads = remote_threads_info; |
| 5039 | remote_cisco_ops.to_stratum = process_stratum; |
| 5040 | remote_cisco_ops.to_has_all_memory = 1; |
| 5041 | remote_cisco_ops.to_has_memory = 1; |
| 5042 | remote_cisco_ops.to_has_stack = 1; |
| 5043 | remote_cisco_ops.to_has_registers = 1; |
| 5044 | remote_cisco_ops.to_has_execution = 1; |
| 5045 | remote_cisco_ops.to_magic = OPS_MAGIC; |
| 5046 | } |
| 5047 | |
| 5048 | /* Target async and target extended-async. |
| 5049 | |
| 5050 | This are temporary targets, until it is all tested. Eventually |
| 5051 | async support will be incorporated int the usual 'remote' |
| 5052 | target. */ |
| 5053 | |
| 5054 | static void |
| 5055 | init_remote_async_ops () |
| 5056 | { |
| 5057 | remote_async_ops.to_shortname = "async"; |
| 5058 | remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol"; |
| 5059 | remote_async_ops.to_doc = |
| 5060 | "Use a remote computer via a serial line, using a gdb-specific protocol.\n\ |
| 5061 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
| 5062 | remote_async_ops.to_open = remote_async_open; |
| 5063 | remote_async_ops.to_close = remote_close; |
| 5064 | remote_async_ops.to_detach = remote_async_detach; |
| 5065 | remote_async_ops.to_resume = remote_async_resume; |
| 5066 | remote_async_ops.to_wait = remote_async_wait; |
| 5067 | remote_async_ops.to_fetch_registers = remote_fetch_registers; |
| 5068 | remote_async_ops.to_store_registers = remote_store_registers; |
| 5069 | remote_async_ops.to_prepare_to_store = remote_prepare_to_store; |
| 5070 | remote_async_ops.to_xfer_memory = remote_xfer_memory; |
| 5071 | remote_async_ops.to_files_info = remote_files_info; |
| 5072 | remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint; |
| 5073 | remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint; |
| 5074 | remote_async_ops.to_kill = remote_async_kill; |
| 5075 | remote_async_ops.to_load = generic_load; |
| 5076 | remote_async_ops.to_mourn_inferior = remote_async_mourn; |
| 5077 | remote_async_ops.to_thread_alive = remote_thread_alive; |
| 5078 | remote_async_ops.to_find_new_threads = remote_threads_info; |
| 5079 | remote_async_ops.to_stop = remote_stop; |
| 5080 | remote_async_ops.to_query = remote_query; |
| 5081 | remote_async_ops.to_rcmd = remote_rcmd; |
| 5082 | remote_async_ops.to_stratum = process_stratum; |
| 5083 | remote_async_ops.to_has_all_memory = 1; |
| 5084 | remote_async_ops.to_has_memory = 1; |
| 5085 | remote_async_ops.to_has_stack = 1; |
| 5086 | remote_async_ops.to_has_registers = 1; |
| 5087 | remote_async_ops.to_has_execution = 1; |
| 5088 | remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */ |
| 5089 | remote_async_ops.to_has_async_exec = 1; |
| 5090 | remote_async_ops.to_magic = OPS_MAGIC; |
| 5091 | } |
| 5092 | |
| 5093 | /* Set up the async extended remote vector by making a copy of the standard |
| 5094 | remote vector and adding to it. */ |
| 5095 | |
| 5096 | static void |
| 5097 | init_extended_async_remote_ops () |
| 5098 | { |
| 5099 | extended_async_remote_ops = remote_async_ops; |
| 5100 | |
| 5101 | extended_async_remote_ops.to_shortname = "extended-async"; |
| 5102 | extended_async_remote_ops.to_longname = |
| 5103 | "Extended remote serial target in async gdb-specific protocol"; |
| 5104 | extended_async_remote_ops.to_doc = |
| 5105 | "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\ |
| 5106 | Specify the serial device it is connected to (e.g. /dev/ttya).", |
| 5107 | extended_async_remote_ops.to_open = extended_remote_async_open; |
| 5108 | extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior; |
| 5109 | extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn; |
| 5110 | } |
| 5111 | |
| 5112 | static void |
| 5113 | set_remote_cmd (args, from_tty) |
| 5114 | char *args; |
| 5115 | int from_tty; |
| 5116 | { |
| 5117 | |
| 5118 | } |
| 5119 | |
| 5120 | |
| 5121 | static void |
| 5122 | build_remote_gdbarch_data () |
| 5123 | { |
| 5124 | tty_input = xmalloc (PBUFSIZ); |
| 5125 | } |
| 5126 | |
| 5127 | void |
| 5128 | _initialize_remote () |
| 5129 | { |
| 5130 | static struct cmd_list_element *remote_set_cmdlist; |
| 5131 | static struct cmd_list_element *remote_show_cmdlist; |
| 5132 | |
| 5133 | /* architecture specific data */ |
| 5134 | build_remote_gdbarch_data (); |
| 5135 | register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL); |
| 5136 | register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data); |
| 5137 | |
| 5138 | /* runtime constants - we retain the value of remote_write_size |
| 5139 | across architecture swaps. */ |
| 5140 | remote_write_size = PBUFSIZ; |
| 5141 | |
| 5142 | init_remote_ops (); |
| 5143 | add_target (&remote_ops); |
| 5144 | |
| 5145 | init_extended_remote_ops (); |
| 5146 | add_target (&extended_remote_ops); |
| 5147 | |
| 5148 | init_remote_async_ops (); |
| 5149 | add_target (&remote_async_ops); |
| 5150 | |
| 5151 | init_extended_async_remote_ops (); |
| 5152 | add_target (&extended_async_remote_ops); |
| 5153 | |
| 5154 | init_remote_cisco_ops (); |
| 5155 | add_target (&remote_cisco_ops); |
| 5156 | |
| 5157 | #if 0 |
| 5158 | init_remote_threadtests (); |
| 5159 | #endif |
| 5160 | |
| 5161 | add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\ |
| 5162 | Remote protocol specific variables\n\ |
| 5163 | Configure various remote-protocol specific variables such as\n\ |
| 5164 | the packets being used", |
| 5165 | &remote_set_cmdlist, "remote ", |
| 5166 | 0/*allow-unknown*/, &setlist); |
| 5167 | add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\ |
| 5168 | Remote protocol specific variables\n\ |
| 5169 | Configure various remote-protocol specific variables such as\n\ |
| 5170 | the packets being used", |
| 5171 | &remote_show_cmdlist, "remote ", |
| 5172 | 0/*allow-unknown*/, &showlist); |
| 5173 | |
| 5174 | add_cmd ("compare-sections", class_obscure, compare_sections_command, |
| 5175 | "Compare section data on target to the exec file.\n\ |
| 5176 | Argument is a single section name (default: all loaded sections).", |
| 5177 | &cmdlist); |
| 5178 | |
| 5179 | add_cmd ("packet", class_maintenance, packet_command, |
| 5180 | "Send an arbitrary packet to a remote target.\n\ |
| 5181 | maintenance packet TEXT\n\ |
| 5182 | If GDB is talking to an inferior via the GDB serial protocol, then\n\ |
| 5183 | this command sends the string TEXT to the inferior, and displays the\n\ |
| 5184 | response packet. GDB supplies the initial `$' character, and the\n\ |
| 5185 | terminating `#' character and checksum.", |
| 5186 | &maintenancelist); |
| 5187 | |
| 5188 | add_show_from_set |
| 5189 | (add_set_cmd ("remotetimeout", no_class, |
| 5190 | var_integer, (char *) &remote_timeout, |
| 5191 | "Set timeout value for remote read.\n", |
| 5192 | &setlist), |
| 5193 | &showlist); |
| 5194 | |
| 5195 | add_show_from_set |
| 5196 | (add_set_cmd ("remotebreak", no_class, |
| 5197 | var_boolean, (char *) &remote_break, |
| 5198 | "Set whether to send break if interrupted.\n", |
| 5199 | &setlist), |
| 5200 | &showlist); |
| 5201 | |
| 5202 | add_show_from_set |
| 5203 | (add_set_cmd ("remotewritesize", no_class, |
| 5204 | var_integer, (char *) &remote_write_size, |
| 5205 | "Set the maximum number of bytes per memory write packet.\n", |
| 5206 | &setlist), |
| 5207 | &showlist); |
| 5208 | |
| 5209 | remote_address_size = TARGET_PTR_BIT; |
| 5210 | add_show_from_set |
| 5211 | (add_set_cmd ("remoteaddresssize", class_obscure, |
| 5212 | var_integer, (char *) &remote_address_size, |
| 5213 | "Set the maximum size of the address (in bits) \ |
| 5214 | in a memory packet.\n", |
| 5215 | &setlist), |
| 5216 | &showlist); |
| 5217 | |
| 5218 | add_packet_config_cmd (&remote_protocol_binary_download, |
| 5219 | "X", "binary-download", |
| 5220 | set_remote_protocol_binary_download_cmd, |
| 5221 | show_remote_protocol_binary_download_cmd, |
| 5222 | &remote_set_cmdlist, &remote_show_cmdlist); |
| 5223 | #if 0 |
| 5224 | /* XXXX - should ``set remotebinarydownload'' be retained for |
| 5225 | compatibility. */ |
| 5226 | add_show_from_set |
| 5227 | (add_set_cmd ("remotebinarydownload", no_class, |
| 5228 | var_boolean, (char *) &remote_binary_download, |
| 5229 | "Set binary downloads.\n", &setlist), |
| 5230 | &showlist); |
| 5231 | #endif |
| 5232 | |
| 5233 | add_info ("remote-process", remote_info_process, |
| 5234 | "Query the remote system for process info."); |
| 5235 | |
| 5236 | add_packet_config_cmd (&remote_protocol_P, "P", "set-register", |
| 5237 | set_remote_protocol_P_packet_cmd, |
| 5238 | show_remote_protocol_P_packet_cmd, |
| 5239 | &remote_set_cmdlist, &remote_show_cmdlist); |
| 5240 | |
| 5241 | add_packet_config_cmd (&remote_protocol_Z, "Z", "breakpoint", |
| 5242 | set_remote_protocol_Z_packet_cmd, |
| 5243 | show_remote_protocol_Z_packet_cmd, |
| 5244 | &remote_set_cmdlist, &remote_show_cmdlist); |
| 5245 | } |