| 1 | /* Select target systems and architectures at runtime for GDB. |
| 2 | Copyright 1990, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support. |
| 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, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include <errno.h> |
| 23 | #include <ctype.h> |
| 24 | #include "gdb_string.h" |
| 25 | #include "target.h" |
| 26 | #include "gdbcmd.h" |
| 27 | #include "symtab.h" |
| 28 | #include "inferior.h" |
| 29 | #include "bfd.h" |
| 30 | #include "symfile.h" |
| 31 | #include "objfiles.h" |
| 32 | #include "wait.h" |
| 33 | #include <signal.h> |
| 34 | |
| 35 | extern int errno; |
| 36 | |
| 37 | static void |
| 38 | target_info PARAMS ((char *, int)); |
| 39 | |
| 40 | static void |
| 41 | cleanup_target PARAMS ((struct target_ops *)); |
| 42 | |
| 43 | static void |
| 44 | maybe_kill_then_create_inferior PARAMS ((char *, char *, char **)); |
| 45 | |
| 46 | static void |
| 47 | maybe_kill_then_attach PARAMS ((char *, int)); |
| 48 | |
| 49 | static void |
| 50 | kill_or_be_killed PARAMS ((int)); |
| 51 | |
| 52 | static void |
| 53 | default_terminal_info PARAMS ((char *, int)); |
| 54 | |
| 55 | static int |
| 56 | nosymbol PARAMS ((char *, CORE_ADDR *)); |
| 57 | |
| 58 | static void |
| 59 | tcomplain PARAMS ((void)); |
| 60 | |
| 61 | static int |
| 62 | nomemory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *)); |
| 63 | |
| 64 | static int |
| 65 | return_zero PARAMS ((void)); |
| 66 | |
| 67 | static void |
| 68 | ignore PARAMS ((void)); |
| 69 | |
| 70 | static void |
| 71 | target_command PARAMS ((char *, int)); |
| 72 | |
| 73 | static struct target_ops * |
| 74 | find_default_run_target PARAMS ((char *)); |
| 75 | |
| 76 | /* Pointer to array of target architecture structures; the size of the |
| 77 | array; the current index into the array; the allocated size of the |
| 78 | array. */ |
| 79 | struct target_ops **target_structs; |
| 80 | unsigned target_struct_size; |
| 81 | unsigned target_struct_index; |
| 82 | unsigned target_struct_allocsize; |
| 83 | #define DEFAULT_ALLOCSIZE 10 |
| 84 | |
| 85 | /* The initial current target, so that there is always a semi-valid |
| 86 | current target. */ |
| 87 | |
| 88 | struct target_ops dummy_target = { |
| 89 | "None", /* to_shortname */ |
| 90 | "None", /* to_longname */ |
| 91 | "", /* to_doc */ |
| 92 | 0, /* to_open */ |
| 93 | 0, /* to_close */ |
| 94 | find_default_attach, /* to_attach */ |
| 95 | 0, /* to_detach */ |
| 96 | 0, /* to_resume */ |
| 97 | 0, /* to_wait */ |
| 98 | 0, /* to_fetch_registers */ |
| 99 | 0, /* to_store_registers */ |
| 100 | 0, /* to_prepare_to_store */ |
| 101 | 0, /* to_xfer_memory */ |
| 102 | 0, /* to_files_info */ |
| 103 | 0, /* to_insert_breakpoint */ |
| 104 | 0, /* to_remove_breakpoint */ |
| 105 | 0, /* to_terminal_init */ |
| 106 | 0, /* to_terminal_inferior */ |
| 107 | 0, /* to_terminal_ours_for_output */ |
| 108 | 0, /* to_terminal_ours */ |
| 109 | 0, /* to_terminal_info */ |
| 110 | 0, /* to_kill */ |
| 111 | 0, /* to_load */ |
| 112 | 0, /* to_lookup_symbol */ |
| 113 | find_default_create_inferior, /* to_create_inferior */ |
| 114 | 0, /* to_mourn_inferior */ |
| 115 | 0, /* to_can_run */ |
| 116 | 0, /* to_notice_signals */ |
| 117 | 0, /* to_thread_alive */ |
| 118 | 0, /* to_stop */ |
| 119 | dummy_stratum, /* to_stratum */ |
| 120 | 0, /* to_next */ |
| 121 | 0, /* to_next */ |
| 122 | 0, /* to_has_all_memory */ |
| 123 | 0, /* to_has_memory */ |
| 124 | 0, /* to_has_registers */ |
| 125 | 0, /* to_has_execution */ |
| 126 | 0, /* to_sections */ |
| 127 | 0, /* to_sections_end */ |
| 128 | OPS_MAGIC, /* to_magic */ |
| 129 | }; |
| 130 | |
| 131 | /* Top of target stack. */ |
| 132 | |
| 133 | struct target_stack_item *target_stack; |
| 134 | |
| 135 | /* The target structure we are currently using to talk to a process |
| 136 | or file or whatever "inferior" we have. */ |
| 137 | |
| 138 | struct target_ops current_target; |
| 139 | |
| 140 | /* Command list for target. */ |
| 141 | |
| 142 | static struct cmd_list_element *targetlist = NULL; |
| 143 | |
| 144 | /* Nonzero if we are debugging an attached outside process |
| 145 | rather than an inferior. */ |
| 146 | |
| 147 | int attach_flag; |
| 148 | |
| 149 | #ifdef MAINTENANCE_CMDS |
| 150 | /* Non-zero if we want to see trace of target level stuff. */ |
| 151 | |
| 152 | static int targetdebug = 0; |
| 153 | |
| 154 | static void setup_target_debug PARAMS ((void)); |
| 155 | |
| 156 | #endif |
| 157 | |
| 158 | /* The user just typed 'target' without the name of a target. */ |
| 159 | |
| 160 | /* ARGSUSED */ |
| 161 | static void |
| 162 | target_command (arg, from_tty) |
| 163 | char *arg; |
| 164 | int from_tty; |
| 165 | { |
| 166 | fputs_filtered ("Argument required (target name). Try `help target'\n", |
| 167 | gdb_stdout); |
| 168 | } |
| 169 | |
| 170 | /* Add a possible target architecture to the list. */ |
| 171 | |
| 172 | void |
| 173 | add_target (t) |
| 174 | struct target_ops *t; |
| 175 | { |
| 176 | if (!target_structs) |
| 177 | { |
| 178 | target_struct_allocsize = DEFAULT_ALLOCSIZE; |
| 179 | target_structs = (struct target_ops **) xmalloc |
| 180 | (target_struct_allocsize * sizeof (*target_structs)); |
| 181 | } |
| 182 | if (target_struct_size >= target_struct_allocsize) |
| 183 | { |
| 184 | target_struct_allocsize *= 2; |
| 185 | target_structs = (struct target_ops **) |
| 186 | xrealloc ((char *) target_structs, |
| 187 | target_struct_allocsize * sizeof (*target_structs)); |
| 188 | } |
| 189 | target_structs[target_struct_size++] = t; |
| 190 | /* cleanup_target (t);*/ |
| 191 | |
| 192 | if (targetlist == NULL) |
| 193 | add_prefix_cmd ("target", class_run, target_command, |
| 194 | "Connect to a target machine or process.\n\ |
| 195 | The first argument is the type or protocol of the target machine.\n\ |
| 196 | Remaining arguments are interpreted by the target protocol. For more\n\ |
| 197 | information on the arguments for a particular protocol, type\n\ |
| 198 | `help target ' followed by the protocol name.", |
| 199 | &targetlist, "target ", 0, &cmdlist); |
| 200 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); |
| 201 | } |
| 202 | |
| 203 | /* Stub functions */ |
| 204 | |
| 205 | static void |
| 206 | ignore () |
| 207 | { |
| 208 | } |
| 209 | |
| 210 | /* ARGSUSED */ |
| 211 | static int |
| 212 | nomemory (memaddr, myaddr, len, write, t) |
| 213 | CORE_ADDR memaddr; |
| 214 | char *myaddr; |
| 215 | int len; |
| 216 | int write; |
| 217 | struct target_ops *t; |
| 218 | { |
| 219 | errno = EIO; /* Can't read/write this location */ |
| 220 | return 0; /* No bytes handled */ |
| 221 | } |
| 222 | |
| 223 | static void |
| 224 | tcomplain () |
| 225 | { |
| 226 | error ("You can't do that when your target is `%s'", |
| 227 | current_target.to_shortname); |
| 228 | } |
| 229 | |
| 230 | void |
| 231 | noprocess () |
| 232 | { |
| 233 | error ("You can't do that without a process to debug"); |
| 234 | } |
| 235 | |
| 236 | /* ARGSUSED */ |
| 237 | static int |
| 238 | nosymbol (name, addrp) |
| 239 | char *name; |
| 240 | CORE_ADDR *addrp; |
| 241 | { |
| 242 | return 1; /* Symbol does not exist in target env */ |
| 243 | } |
| 244 | |
| 245 | /* ARGSUSED */ |
| 246 | static void |
| 247 | default_terminal_info (args, from_tty) |
| 248 | char *args; |
| 249 | int from_tty; |
| 250 | { |
| 251 | printf_unfiltered("No saved terminal information.\n"); |
| 252 | } |
| 253 | |
| 254 | /* This is the default target_create_inferior and target_attach function. |
| 255 | If the current target is executing, it asks whether to kill it off. |
| 256 | If this function returns without calling error(), it has killed off |
| 257 | the target, and the operation should be attempted. */ |
| 258 | |
| 259 | static void |
| 260 | kill_or_be_killed (from_tty) |
| 261 | int from_tty; |
| 262 | { |
| 263 | if (target_has_execution) |
| 264 | { |
| 265 | printf_unfiltered ("You are already running a program:\n"); |
| 266 | target_files_info (); |
| 267 | if (query ("Kill it? ")) { |
| 268 | target_kill (); |
| 269 | if (target_has_execution) |
| 270 | error ("Killing the program did not help."); |
| 271 | return; |
| 272 | } else { |
| 273 | error ("Program not killed."); |
| 274 | } |
| 275 | } |
| 276 | tcomplain(); |
| 277 | } |
| 278 | |
| 279 | static void |
| 280 | maybe_kill_then_attach (args, from_tty) |
| 281 | char *args; |
| 282 | int from_tty; |
| 283 | { |
| 284 | kill_or_be_killed (from_tty); |
| 285 | target_attach (args, from_tty); |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | maybe_kill_then_create_inferior (exec, args, env) |
| 290 | char *exec; |
| 291 | char *args; |
| 292 | char **env; |
| 293 | { |
| 294 | kill_or_be_killed (0); |
| 295 | target_create_inferior (exec, args, env); |
| 296 | } |
| 297 | |
| 298 | /* Clean up a target struct so it no longer has any zero pointers in it. |
| 299 | We default entries, at least to stubs that print error messages. */ |
| 300 | |
| 301 | static void |
| 302 | cleanup_target (t) |
| 303 | struct target_ops *t; |
| 304 | { |
| 305 | |
| 306 | #define de_fault(field, value) \ |
| 307 | if (!t->field) t->field = value |
| 308 | |
| 309 | /* FIELD DEFAULT VALUE */ |
| 310 | |
| 311 | de_fault (to_open, (void (*)())tcomplain); |
| 312 | de_fault (to_close, (void (*)())ignore); |
| 313 | de_fault (to_attach, maybe_kill_then_attach); |
| 314 | de_fault (to_detach, (void (*)())ignore); |
| 315 | de_fault (to_resume, (void (*)())noprocess); |
| 316 | de_fault (to_wait, (int (*)())noprocess); |
| 317 | de_fault (to_fetch_registers, (void (*)())ignore); |
| 318 | de_fault (to_store_registers, (void (*)())noprocess); |
| 319 | de_fault (to_prepare_to_store, (void (*)())noprocess); |
| 320 | de_fault (to_xfer_memory, (int (*)())nomemory); |
| 321 | de_fault (to_files_info, (void (*)())ignore); |
| 322 | de_fault (to_insert_breakpoint, memory_insert_breakpoint); |
| 323 | de_fault (to_remove_breakpoint, memory_remove_breakpoint); |
| 324 | de_fault (to_terminal_init, ignore); |
| 325 | de_fault (to_terminal_inferior, ignore); |
| 326 | de_fault (to_terminal_ours_for_output,ignore); |
| 327 | de_fault (to_terminal_ours, ignore); |
| 328 | de_fault (to_terminal_info, default_terminal_info); |
| 329 | de_fault (to_kill, (void (*)())noprocess); |
| 330 | de_fault (to_load, (void (*)())tcomplain); |
| 331 | de_fault (to_lookup_symbol, nosymbol); |
| 332 | de_fault (to_create_inferior, maybe_kill_then_create_inferior); |
| 333 | de_fault (to_mourn_inferior, (void (*)())noprocess); |
| 334 | de_fault (to_can_run, return_zero); |
| 335 | de_fault (to_notice_signals, (void (*)())ignore); |
| 336 | de_fault (to_thread_alive, (int (*)())ignore); |
| 337 | de_fault (to_stop, (void (*)())ignore); |
| 338 | |
| 339 | #undef de_fault |
| 340 | } |
| 341 | |
| 342 | /* Go through the target stack from top to bottom, copying over zero entries in |
| 343 | current_target. In effect, we are doing class inheritance through the |
| 344 | pushed target vectors. */ |
| 345 | |
| 346 | static void |
| 347 | update_current_target () |
| 348 | { |
| 349 | struct target_stack_item *item; |
| 350 | struct target_ops *t; |
| 351 | |
| 352 | /* First, reset current_target */ |
| 353 | memset (¤t_target, 0, sizeof current_target); |
| 354 | |
| 355 | for (item = target_stack; item; item = item->next) |
| 356 | { |
| 357 | t = item->target_ops; |
| 358 | |
| 359 | #define INHERIT(FIELD, TARGET) \ |
| 360 | if (!current_target.FIELD) \ |
| 361 | current_target.FIELD = TARGET->FIELD |
| 362 | |
| 363 | INHERIT (to_shortname, t); |
| 364 | INHERIT (to_longname, t); |
| 365 | INHERIT (to_doc, t); |
| 366 | INHERIT (to_open, t); |
| 367 | INHERIT (to_close, t); |
| 368 | INHERIT (to_attach, t); |
| 369 | INHERIT (to_detach, t); |
| 370 | INHERIT (to_resume, t); |
| 371 | INHERIT (to_wait, t); |
| 372 | INHERIT (to_fetch_registers, t); |
| 373 | INHERIT (to_store_registers, t); |
| 374 | INHERIT (to_prepare_to_store, t); |
| 375 | INHERIT (to_xfer_memory, t); |
| 376 | INHERIT (to_files_info, t); |
| 377 | INHERIT (to_insert_breakpoint, t); |
| 378 | INHERIT (to_remove_breakpoint, t); |
| 379 | INHERIT (to_terminal_init, t); |
| 380 | INHERIT (to_terminal_inferior, t); |
| 381 | INHERIT (to_terminal_ours_for_output, t); |
| 382 | INHERIT (to_terminal_ours, t); |
| 383 | INHERIT (to_terminal_info, t); |
| 384 | INHERIT (to_kill, t); |
| 385 | INHERIT (to_load, t); |
| 386 | INHERIT (to_lookup_symbol, t); |
| 387 | INHERIT (to_create_inferior, t); |
| 388 | INHERIT (to_mourn_inferior, t); |
| 389 | INHERIT (to_can_run, t); |
| 390 | INHERIT (to_notice_signals, t); |
| 391 | INHERIT (to_thread_alive, t); |
| 392 | INHERIT (to_stop, t); |
| 393 | INHERIT (to_stratum, t); |
| 394 | INHERIT (DONT_USE, t); |
| 395 | INHERIT (to_has_all_memory, t); |
| 396 | INHERIT (to_has_memory, t); |
| 397 | INHERIT (to_has_stack, t); |
| 398 | INHERIT (to_has_registers, t); |
| 399 | INHERIT (to_has_execution, t); |
| 400 | INHERIT (to_sections, t); |
| 401 | INHERIT (to_sections_end, t); |
| 402 | INHERIT (to_magic, t); |
| 403 | |
| 404 | #undef INHERIT |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /* Push a new target type into the stack of the existing target accessors, |
| 409 | possibly superseding some of the existing accessors. |
| 410 | |
| 411 | Result is zero if the pushed target ended up on top of the stack, |
| 412 | nonzero if at least one target is on top of it. |
| 413 | |
| 414 | Rather than allow an empty stack, we always have the dummy target at |
| 415 | the bottom stratum, so we can call the function vectors without |
| 416 | checking them. */ |
| 417 | |
| 418 | int |
| 419 | push_target (t) |
| 420 | struct target_ops *t; |
| 421 | { |
| 422 | struct target_stack_item *cur, *prev, *tmp; |
| 423 | |
| 424 | /* Check magic number. If wrong, it probably means someone changed |
| 425 | the struct definition, but not all the places that initialize one. */ |
| 426 | if (t->to_magic != OPS_MAGIC) |
| 427 | { |
| 428 | fprintf_unfiltered(gdb_stderr, |
| 429 | "Magic number of %s target struct wrong\n", |
| 430 | t->to_shortname); |
| 431 | abort(); |
| 432 | } |
| 433 | |
| 434 | /* Find the proper stratum to install this target in. */ |
| 435 | |
| 436 | for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next) |
| 437 | { |
| 438 | if ((int)(t->to_stratum) >= (int)(cur->target_ops->to_stratum)) |
| 439 | break; |
| 440 | } |
| 441 | |
| 442 | /* If there's already targets at this stratum, remove them. */ |
| 443 | |
| 444 | if (cur) |
| 445 | while (t->to_stratum == cur->target_ops->to_stratum) |
| 446 | { |
| 447 | /* There's already something on this stratum. Close it off. */ |
| 448 | if (cur->target_ops->to_close) |
| 449 | (cur->target_ops->to_close) (0); |
| 450 | if (prev) |
| 451 | prev->next = cur->next; /* Unchain old target_ops */ |
| 452 | else |
| 453 | target_stack = cur->next; /* Unchain first on list */ |
| 454 | tmp = cur->next; |
| 455 | free (cur); |
| 456 | cur = tmp; |
| 457 | } |
| 458 | |
| 459 | /* We have removed all targets in our stratum, now add the new one. */ |
| 460 | |
| 461 | tmp = (struct target_stack_item *) |
| 462 | xmalloc (sizeof (struct target_stack_item)); |
| 463 | tmp->next = cur; |
| 464 | tmp->target_ops = t; |
| 465 | |
| 466 | if (prev) |
| 467 | prev->next = tmp; |
| 468 | else |
| 469 | target_stack = tmp; |
| 470 | |
| 471 | update_current_target (); |
| 472 | |
| 473 | cleanup_target (¤t_target); /* Fill in the gaps */ |
| 474 | |
| 475 | #ifdef MAINTENANCE_CMDS |
| 476 | if (targetdebug) |
| 477 | setup_target_debug (); |
| 478 | #endif |
| 479 | |
| 480 | return prev != 0; |
| 481 | } |
| 482 | |
| 483 | /* Remove a target_ops vector from the stack, wherever it may be. |
| 484 | Return how many times it was removed (0 or 1). */ |
| 485 | |
| 486 | int |
| 487 | unpush_target (t) |
| 488 | struct target_ops *t; |
| 489 | { |
| 490 | struct target_stack_item *cur, *prev; |
| 491 | |
| 492 | if (t->to_close) |
| 493 | t->to_close (0); /* Let it clean up */ |
| 494 | |
| 495 | /* Look for the specified target. Note that we assume that a target |
| 496 | can only occur once in the target stack. */ |
| 497 | |
| 498 | for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next) |
| 499 | if (cur->target_ops == t) |
| 500 | break; |
| 501 | |
| 502 | if (!cur) |
| 503 | return 0; /* Didn't find target_ops, quit now */ |
| 504 | |
| 505 | /* Unchain the target */ |
| 506 | |
| 507 | if (!prev) |
| 508 | target_stack = cur->next; |
| 509 | else |
| 510 | prev->next = cur->next; |
| 511 | |
| 512 | free (cur); /* Release the target_stack_item */ |
| 513 | |
| 514 | update_current_target (); |
| 515 | cleanup_target (¤t_target); |
| 516 | |
| 517 | return 1; |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | pop_target () |
| 522 | { |
| 523 | (current_target.to_close)(0); /* Let it clean up */ |
| 524 | if (unpush_target (target_stack->target_ops) == 1) |
| 525 | return; |
| 526 | |
| 527 | fprintf_unfiltered(gdb_stderr, |
| 528 | "pop_target couldn't find target %s\n", |
| 529 | current_target.to_shortname); |
| 530 | abort(); |
| 531 | } |
| 532 | |
| 533 | #undef MIN |
| 534 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) |
| 535 | |
| 536 | /* target_read_string -- read a null terminated string, up to LEN bytes, |
| 537 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. |
| 538 | Set *STRING to a pointer to malloc'd memory containing the data; the caller |
| 539 | is responsible for freeing it. Return the number of bytes successfully |
| 540 | read. */ |
| 541 | |
| 542 | int |
| 543 | target_read_string (memaddr, string, len, errnop) |
| 544 | CORE_ADDR memaddr; |
| 545 | char **string; |
| 546 | int len; |
| 547 | int *errnop; |
| 548 | { |
| 549 | int tlen, origlen, offset, i; |
| 550 | char buf[4]; |
| 551 | int errcode = 0; |
| 552 | char *buffer; |
| 553 | int buffer_allocated; |
| 554 | char *bufptr; |
| 555 | unsigned int nbytes_read = 0; |
| 556 | |
| 557 | /* Small for testing. */ |
| 558 | buffer_allocated = 4; |
| 559 | buffer = xmalloc (buffer_allocated); |
| 560 | bufptr = buffer; |
| 561 | |
| 562 | origlen = len; |
| 563 | |
| 564 | while (len > 0) |
| 565 | { |
| 566 | tlen = MIN (len, 4 - (memaddr & 3)); |
| 567 | offset = memaddr & 3; |
| 568 | |
| 569 | errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0); |
| 570 | if (errcode != 0) |
| 571 | goto done; |
| 572 | |
| 573 | if (bufptr - buffer + tlen > buffer_allocated) |
| 574 | { |
| 575 | unsigned int bytes; |
| 576 | bytes = bufptr - buffer; |
| 577 | buffer_allocated *= 2; |
| 578 | buffer = xrealloc (buffer, buffer_allocated); |
| 579 | bufptr = buffer + bytes; |
| 580 | } |
| 581 | |
| 582 | for (i = 0; i < tlen; i++) |
| 583 | { |
| 584 | *bufptr++ = buf[i + offset]; |
| 585 | if (buf[i + offset] == '\000') |
| 586 | { |
| 587 | nbytes_read += i + 1; |
| 588 | goto done; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | memaddr += tlen; |
| 593 | len -= tlen; |
| 594 | nbytes_read += tlen; |
| 595 | } |
| 596 | done: |
| 597 | if (errnop != NULL) |
| 598 | *errnop = errcode; |
| 599 | if (string != NULL) |
| 600 | *string = buffer; |
| 601 | return nbytes_read; |
| 602 | } |
| 603 | |
| 604 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
| 605 | GDB's memory at MYADDR. Returns either 0 for success or an errno value |
| 606 | if any error occurs. |
| 607 | |
| 608 | If an error occurs, no guarantee is made about the contents of the data at |
| 609 | MYADDR. In particular, the caller should not depend upon partial reads |
| 610 | filling the buffer with good data. There is no way for the caller to know |
| 611 | how much good data might have been transfered anyway. Callers that can |
| 612 | deal with partial reads should call target_read_memory_partial. */ |
| 613 | |
| 614 | int |
| 615 | target_read_memory (memaddr, myaddr, len) |
| 616 | CORE_ADDR memaddr; |
| 617 | char *myaddr; |
| 618 | int len; |
| 619 | { |
| 620 | return target_xfer_memory (memaddr, myaddr, len, 0); |
| 621 | } |
| 622 | |
| 623 | /* Read LEN bytes of target memory at address MEMADDR, placing the results |
| 624 | in GDB's memory at MYADDR. Returns a count of the bytes actually read, |
| 625 | and optionally an errno value in the location pointed to by ERRNOPTR |
| 626 | if ERRNOPTR is non-null. */ |
| 627 | |
| 628 | int |
| 629 | target_read_memory_partial (memaddr, myaddr, len, errnoptr) |
| 630 | CORE_ADDR memaddr; |
| 631 | char *myaddr; |
| 632 | int len; |
| 633 | int *errnoptr; |
| 634 | { |
| 635 | int nread; /* Number of bytes actually read. */ |
| 636 | int errcode; /* Error from last read. */ |
| 637 | |
| 638 | /* First try a complete read. */ |
| 639 | errcode = target_xfer_memory (memaddr, myaddr, len, 0); |
| 640 | if (errcode == 0) |
| 641 | { |
| 642 | /* Got it all. */ |
| 643 | nread = len; |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | /* Loop, reading one byte at a time until we get as much as we can. */ |
| 648 | for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--) |
| 649 | { |
| 650 | errcode = target_xfer_memory (memaddr++, myaddr++, 1, 0); |
| 651 | } |
| 652 | /* If an error, the last read was unsuccessful, so adjust count. */ |
| 653 | if (errcode != 0) |
| 654 | { |
| 655 | nread--; |
| 656 | } |
| 657 | } |
| 658 | if (errnoptr != NULL) |
| 659 | { |
| 660 | *errnoptr = errcode; |
| 661 | } |
| 662 | return (nread); |
| 663 | } |
| 664 | |
| 665 | int |
| 666 | target_write_memory (memaddr, myaddr, len) |
| 667 | CORE_ADDR memaddr; |
| 668 | char *myaddr; |
| 669 | int len; |
| 670 | { |
| 671 | return target_xfer_memory (memaddr, myaddr, len, 1); |
| 672 | } |
| 673 | |
| 674 | /* Move memory to or from the targets. Iterate until all of it has |
| 675 | been moved, if necessary. The top target gets priority; anything |
| 676 | it doesn't want, is offered to the next one down, etc. Note the |
| 677 | business with curlen: if an early target says "no, but I have a |
| 678 | boundary overlapping this xfer" then we shorten what we offer to |
| 679 | the subsequent targets so the early guy will get a chance at the |
| 680 | tail before the subsequent ones do. |
| 681 | |
| 682 | Result is 0 or errno value. */ |
| 683 | |
| 684 | int |
| 685 | target_xfer_memory (memaddr, myaddr, len, write) |
| 686 | CORE_ADDR memaddr; |
| 687 | char *myaddr; |
| 688 | int len; |
| 689 | int write; |
| 690 | { |
| 691 | int curlen; |
| 692 | int res; |
| 693 | struct target_ops *t; |
| 694 | struct target_stack_item *item; |
| 695 | |
| 696 | /* to_xfer_memory is not guaranteed to set errno, even when it returns |
| 697 | 0. */ |
| 698 | errno = 0; |
| 699 | |
| 700 | /* The quick case is that the top target does it all. */ |
| 701 | res = current_target.to_xfer_memory |
| 702 | (memaddr, myaddr, len, write, ¤t_target); |
| 703 | if (res == len) |
| 704 | return 0; |
| 705 | |
| 706 | if (res > 0) |
| 707 | goto bump; |
| 708 | /* If res <= 0 then we call it again in the loop. Ah well. */ |
| 709 | |
| 710 | for (; len > 0;) |
| 711 | { |
| 712 | curlen = len; /* Want to do it all */ |
| 713 | for (item = target_stack; item; item = item->next) |
| 714 | { |
| 715 | t = item->target_ops; |
| 716 | if (!t->to_has_memory) |
| 717 | continue; |
| 718 | |
| 719 | res = t->to_xfer_memory (memaddr, myaddr, curlen, write, t); |
| 720 | if (res > 0) |
| 721 | break; /* Handled all or part of xfer */ |
| 722 | if (t->to_has_all_memory) |
| 723 | break; |
| 724 | } |
| 725 | |
| 726 | if (res <= 0) |
| 727 | { |
| 728 | /* If this address is for nonexistent memory, |
| 729 | read zeros if reading, or do nothing if writing. Return error. */ |
| 730 | if (!write) |
| 731 | memset (myaddr, 0, len); |
| 732 | if (errno == 0) |
| 733 | return EIO; |
| 734 | else |
| 735 | return errno; |
| 736 | } |
| 737 | bump: |
| 738 | memaddr += res; |
| 739 | myaddr += res; |
| 740 | len -= res; |
| 741 | } |
| 742 | return 0; /* We managed to cover it all somehow. */ |
| 743 | } |
| 744 | |
| 745 | |
| 746 | /* ARGSUSED */ |
| 747 | static void |
| 748 | target_info (args, from_tty) |
| 749 | char *args; |
| 750 | int from_tty; |
| 751 | { |
| 752 | struct target_ops *t; |
| 753 | struct target_stack_item *item; |
| 754 | int has_all_mem = 0; |
| 755 | |
| 756 | if (symfile_objfile != NULL) |
| 757 | printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name); |
| 758 | |
| 759 | #ifdef FILES_INFO_HOOK |
| 760 | if (FILES_INFO_HOOK ()) |
| 761 | return; |
| 762 | #endif |
| 763 | |
| 764 | for (item = target_stack; item; item = item->next) |
| 765 | { |
| 766 | t = item->target_ops; |
| 767 | |
| 768 | if (!t->to_has_memory) |
| 769 | continue; |
| 770 | |
| 771 | if ((int)(t->to_stratum) <= (int)dummy_stratum) |
| 772 | continue; |
| 773 | if (has_all_mem) |
| 774 | printf_unfiltered("\tWhile running this, GDB does not access memory from...\n"); |
| 775 | printf_unfiltered("%s:\n", t->to_longname); |
| 776 | (t->to_files_info)(t); |
| 777 | has_all_mem = t->to_has_all_memory; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /* This is to be called by the open routine before it does |
| 782 | anything. */ |
| 783 | |
| 784 | void |
| 785 | target_preopen (from_tty) |
| 786 | int from_tty; |
| 787 | { |
| 788 | dont_repeat(); |
| 789 | |
| 790 | if (target_has_execution) |
| 791 | { |
| 792 | if (query ("A program is being debugged already. Kill it? ")) |
| 793 | target_kill (); |
| 794 | else |
| 795 | error ("Program not killed."); |
| 796 | } |
| 797 | |
| 798 | /* Calling target_kill may remove the target from the stack. But if |
| 799 | it doesn't (which seems like a win for UDI), remove it now. */ |
| 800 | |
| 801 | if (target_has_execution) |
| 802 | pop_target (); |
| 803 | } |
| 804 | |
| 805 | /* Detach a target after doing deferred register stores. */ |
| 806 | |
| 807 | void |
| 808 | target_detach (args, from_tty) |
| 809 | char *args; |
| 810 | int from_tty; |
| 811 | { |
| 812 | /* Handle any optimized stores to the inferior. */ |
| 813 | #ifdef DO_DEFERRED_STORES |
| 814 | DO_DEFERRED_STORES; |
| 815 | #endif |
| 816 | (current_target.to_detach) (args, from_tty); |
| 817 | } |
| 818 | |
| 819 | void |
| 820 | target_link (modname, t_reloc) |
| 821 | char *modname; |
| 822 | CORE_ADDR *t_reloc; |
| 823 | { |
| 824 | if (STREQ(current_target.to_shortname, "rombug")) |
| 825 | { |
| 826 | (current_target.to_lookup_symbol) (modname, t_reloc); |
| 827 | if (*t_reloc == 0) |
| 828 | error("Unable to link to %s and get relocation in rombug", modname); |
| 829 | } |
| 830 | else |
| 831 | *t_reloc = (CORE_ADDR)-1; |
| 832 | } |
| 833 | |
| 834 | /* Look through the list of possible targets for a target that can |
| 835 | execute a run or attach command without any other data. This is |
| 836 | used to locate the default process stratum. |
| 837 | |
| 838 | Result is always valid (error() is called for errors). */ |
| 839 | |
| 840 | static struct target_ops * |
| 841 | find_default_run_target (do_mesg) |
| 842 | char *do_mesg; |
| 843 | { |
| 844 | struct target_ops **t; |
| 845 | struct target_ops *runable = NULL; |
| 846 | int count; |
| 847 | |
| 848 | count = 0; |
| 849 | |
| 850 | for (t = target_structs; t < target_structs + target_struct_size; |
| 851 | ++t) |
| 852 | { |
| 853 | if ((*t)->to_can_run && target_can_run(*t)) |
| 854 | { |
| 855 | runable = *t; |
| 856 | ++count; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | if (count != 1) |
| 861 | error ("Don't know how to %s. Try \"help target\".", do_mesg); |
| 862 | |
| 863 | return runable; |
| 864 | } |
| 865 | |
| 866 | void |
| 867 | find_default_attach (args, from_tty) |
| 868 | char *args; |
| 869 | int from_tty; |
| 870 | { |
| 871 | struct target_ops *t; |
| 872 | |
| 873 | t = find_default_run_target("attach"); |
| 874 | (t->to_attach) (args, from_tty); |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | void |
| 879 | find_default_create_inferior (exec_file, allargs, env) |
| 880 | char *exec_file; |
| 881 | char *allargs; |
| 882 | char **env; |
| 883 | { |
| 884 | struct target_ops *t; |
| 885 | |
| 886 | t = find_default_run_target("run"); |
| 887 | (t->to_create_inferior) (exec_file, allargs, env); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | static int |
| 892 | return_zero () |
| 893 | { |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | struct target_ops * |
| 898 | find_core_target () |
| 899 | { |
| 900 | struct target_ops **t; |
| 901 | struct target_ops *runable = NULL; |
| 902 | int count; |
| 903 | |
| 904 | count = 0; |
| 905 | |
| 906 | for (t = target_structs; t < target_structs + target_struct_size; |
| 907 | ++t) |
| 908 | { |
| 909 | if ((*t)->to_stratum == core_stratum) |
| 910 | { |
| 911 | runable = *t; |
| 912 | ++count; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | return(count == 1 ? runable : NULL); |
| 917 | } |
| 918 | \f |
| 919 | /* The inferior process has died. Long live the inferior! */ |
| 920 | |
| 921 | void |
| 922 | generic_mourn_inferior () |
| 923 | { |
| 924 | extern int show_breakpoint_hit_counts; |
| 925 | |
| 926 | inferior_pid = 0; |
| 927 | attach_flag = 0; |
| 928 | breakpoint_init_inferior (); |
| 929 | registers_changed (); |
| 930 | |
| 931 | #ifdef CLEAR_DEFERRED_STORES |
| 932 | /* Delete any pending stores to the inferior... */ |
| 933 | CLEAR_DEFERRED_STORES; |
| 934 | #endif |
| 935 | |
| 936 | reopen_exec_file (); |
| 937 | reinit_frame_cache (); |
| 938 | |
| 939 | /* It is confusing to the user for ignore counts to stick around |
| 940 | from previous runs of the inferior. So clear them. */ |
| 941 | /* However, it is more confusing for the ignore counts to disappear when |
| 942 | using hit counts. So don't clear them if we're counting hits. */ |
| 943 | if (!show_breakpoint_hit_counts) |
| 944 | breakpoint_clear_ignore_counts (); |
| 945 | } |
| 946 | \f |
| 947 | /* This table must match in order and size the signals in enum target_signal |
| 948 | in target.h. */ |
| 949 | static struct { |
| 950 | char *name; |
| 951 | char *string; |
| 952 | } signals [] = |
| 953 | { |
| 954 | {"0", "Signal 0"}, |
| 955 | {"SIGHUP", "Hangup"}, |
| 956 | {"SIGINT", "Interrupt"}, |
| 957 | {"SIGQUIT", "Quit"}, |
| 958 | {"SIGILL", "Illegal instruction"}, |
| 959 | {"SIGTRAP", "Trace/breakpoint trap"}, |
| 960 | {"SIGABRT", "Aborted"}, |
| 961 | {"SIGEMT", "Emulation trap"}, |
| 962 | {"SIGFPE", "Arithmetic exception"}, |
| 963 | {"SIGKILL", "Killed"}, |
| 964 | {"SIGBUS", "Bus error"}, |
| 965 | {"SIGSEGV", "Segmentation fault"}, |
| 966 | {"SIGSYS", "Bad system call"}, |
| 967 | {"SIGPIPE", "Broken pipe"}, |
| 968 | {"SIGALRM", "Alarm clock"}, |
| 969 | {"SIGTERM", "Terminated"}, |
| 970 | {"SIGURG", "Urgent I/O condition"}, |
| 971 | {"SIGSTOP", "Stopped (signal)"}, |
| 972 | {"SIGTSTP", "Stopped (user)"}, |
| 973 | {"SIGCONT", "Continued"}, |
| 974 | {"SIGCHLD", "Child status changed"}, |
| 975 | {"SIGTTIN", "Stopped (tty input)"}, |
| 976 | {"SIGTTOU", "Stopped (tty output)"}, |
| 977 | {"SIGIO", "I/O possible"}, |
| 978 | {"SIGXCPU", "CPU time limit exceeded"}, |
| 979 | {"SIGXFSZ", "File size limit exceeded"}, |
| 980 | {"SIGVTALRM", "Virtual timer expired"}, |
| 981 | {"SIGPROF", "Profiling timer expired"}, |
| 982 | {"SIGWINCH", "Window size changed"}, |
| 983 | {"SIGLOST", "Resource lost"}, |
| 984 | {"SIGUSR1", "User defined signal 1"}, |
| 985 | {"SIGUSR2", "User defined signal 2"}, |
| 986 | {"SIGPWR", "Power fail/restart"}, |
| 987 | {"SIGPOLL", "Pollable event occurred"}, |
| 988 | {"SIGWIND", "SIGWIND"}, |
| 989 | {"SIGPHONE", "SIGPHONE"}, |
| 990 | {"SIGWAITING", "Process's LWPs are blocked"}, |
| 991 | {"SIGLWP", "Signal LWP"}, |
| 992 | {"SIGDANGER", "Swap space dangerously low"}, |
| 993 | {"SIGGRANT", "Monitor mode granted"}, |
| 994 | {"SIGRETRACT", "Need to relinguish monitor mode"}, |
| 995 | {"SIGMSG", "Monitor mode data available"}, |
| 996 | {"SIGSOUND", "Sound completed"}, |
| 997 | {"SIGSAK", "Secure attention"}, |
| 998 | {"SIGPRIO", "SIGPRIO"}, |
| 999 | {"SIG33", "Real-time event 33"}, |
| 1000 | {"SIG34", "Real-time event 34"}, |
| 1001 | {"SIG35", "Real-time event 35"}, |
| 1002 | {"SIG36", "Real-time event 36"}, |
| 1003 | {"SIG37", "Real-time event 37"}, |
| 1004 | {"SIG38", "Real-time event 38"}, |
| 1005 | {"SIG39", "Real-time event 39"}, |
| 1006 | {"SIG40", "Real-time event 40"}, |
| 1007 | {"SIG41", "Real-time event 41"}, |
| 1008 | {"SIG42", "Real-time event 42"}, |
| 1009 | {"SIG43", "Real-time event 43"}, |
| 1010 | {"SIG44", "Real-time event 44"}, |
| 1011 | {"SIG45", "Real-time event 45"}, |
| 1012 | {"SIG46", "Real-time event 46"}, |
| 1013 | {"SIG47", "Real-time event 47"}, |
| 1014 | {"SIG48", "Real-time event 48"}, |
| 1015 | {"SIG49", "Real-time event 49"}, |
| 1016 | {"SIG50", "Real-time event 50"}, |
| 1017 | {"SIG51", "Real-time event 51"}, |
| 1018 | {"SIG52", "Real-time event 52"}, |
| 1019 | {"SIG53", "Real-time event 53"}, |
| 1020 | {"SIG54", "Real-time event 54"}, |
| 1021 | {"SIG55", "Real-time event 55"}, |
| 1022 | {"SIG56", "Real-time event 56"}, |
| 1023 | {"SIG57", "Real-time event 57"}, |
| 1024 | {"SIG58", "Real-time event 58"}, |
| 1025 | {"SIG59", "Real-time event 59"}, |
| 1026 | {"SIG60", "Real-time event 60"}, |
| 1027 | {"SIG61", "Real-time event 61"}, |
| 1028 | {"SIG62", "Real-time event 62"}, |
| 1029 | {"SIG63", "Real-time event 63"}, |
| 1030 | |
| 1031 | {NULL, "Unknown signal"}, |
| 1032 | {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"}, |
| 1033 | |
| 1034 | /* Last entry, used to check whether the table is the right size. */ |
| 1035 | {NULL, "TARGET_SIGNAL_MAGIC"} |
| 1036 | }; |
| 1037 | |
| 1038 | /* Return the string for a signal. */ |
| 1039 | char * |
| 1040 | target_signal_to_string (sig) |
| 1041 | enum target_signal sig; |
| 1042 | { |
| 1043 | return signals[sig].string; |
| 1044 | } |
| 1045 | |
| 1046 | /* Return the name for a signal. */ |
| 1047 | char * |
| 1048 | target_signal_to_name (sig) |
| 1049 | enum target_signal sig; |
| 1050 | { |
| 1051 | if (sig == TARGET_SIGNAL_UNKNOWN) |
| 1052 | /* I think the code which prints this will always print it along with |
| 1053 | the string, so no need to be verbose. */ |
| 1054 | return "?"; |
| 1055 | return signals[sig].name; |
| 1056 | } |
| 1057 | |
| 1058 | /* Given a name, return its signal. */ |
| 1059 | enum target_signal |
| 1060 | target_signal_from_name (name) |
| 1061 | char *name; |
| 1062 | { |
| 1063 | enum target_signal sig; |
| 1064 | |
| 1065 | /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" |
| 1066 | for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more |
| 1067 | questionable; seems like by now people should call it SIGABRT |
| 1068 | instead. */ |
| 1069 | |
| 1070 | /* This ugly cast brought to you by the native VAX compiler. */ |
| 1071 | for (sig = TARGET_SIGNAL_HUP; |
| 1072 | signals[sig].name != NULL; |
| 1073 | sig = (enum target_signal)((int)sig + 1)) |
| 1074 | if (STREQ (name, signals[sig].name)) |
| 1075 | return sig; |
| 1076 | return TARGET_SIGNAL_UNKNOWN; |
| 1077 | } |
| 1078 | \f |
| 1079 | /* The following functions are to help certain targets deal |
| 1080 | with the signal/waitstatus stuff. They could just as well be in |
| 1081 | a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ |
| 1082 | |
| 1083 | /* Convert host signal to our signals. */ |
| 1084 | enum target_signal |
| 1085 | target_signal_from_host (hostsig) |
| 1086 | int hostsig; |
| 1087 | { |
| 1088 | /* A switch statement would make sense but would require special kludges |
| 1089 | to deal with the cases where more than one signal has the same number. */ |
| 1090 | |
| 1091 | if (hostsig == 0) return TARGET_SIGNAL_0; |
| 1092 | |
| 1093 | #if defined (SIGHUP) |
| 1094 | if (hostsig == SIGHUP) return TARGET_SIGNAL_HUP; |
| 1095 | #endif |
| 1096 | #if defined (SIGINT) |
| 1097 | if (hostsig == SIGINT) return TARGET_SIGNAL_INT; |
| 1098 | #endif |
| 1099 | #if defined (SIGQUIT) |
| 1100 | if (hostsig == SIGQUIT) return TARGET_SIGNAL_QUIT; |
| 1101 | #endif |
| 1102 | #if defined (SIGILL) |
| 1103 | if (hostsig == SIGILL) return TARGET_SIGNAL_ILL; |
| 1104 | #endif |
| 1105 | #if defined (SIGTRAP) |
| 1106 | if (hostsig == SIGTRAP) return TARGET_SIGNAL_TRAP; |
| 1107 | #endif |
| 1108 | #if defined (SIGABRT) |
| 1109 | if (hostsig == SIGABRT) return TARGET_SIGNAL_ABRT; |
| 1110 | #endif |
| 1111 | #if defined (SIGEMT) |
| 1112 | if (hostsig == SIGEMT) return TARGET_SIGNAL_EMT; |
| 1113 | #endif |
| 1114 | #if defined (SIGFPE) |
| 1115 | if (hostsig == SIGFPE) return TARGET_SIGNAL_FPE; |
| 1116 | #endif |
| 1117 | #if defined (SIGKILL) |
| 1118 | if (hostsig == SIGKILL) return TARGET_SIGNAL_KILL; |
| 1119 | #endif |
| 1120 | #if defined (SIGBUS) |
| 1121 | if (hostsig == SIGBUS) return TARGET_SIGNAL_BUS; |
| 1122 | #endif |
| 1123 | #if defined (SIGSEGV) |
| 1124 | if (hostsig == SIGSEGV) return TARGET_SIGNAL_SEGV; |
| 1125 | #endif |
| 1126 | #if defined (SIGSYS) |
| 1127 | if (hostsig == SIGSYS) return TARGET_SIGNAL_SYS; |
| 1128 | #endif |
| 1129 | #if defined (SIGPIPE) |
| 1130 | if (hostsig == SIGPIPE) return TARGET_SIGNAL_PIPE; |
| 1131 | #endif |
| 1132 | #if defined (SIGALRM) |
| 1133 | if (hostsig == SIGALRM) return TARGET_SIGNAL_ALRM; |
| 1134 | #endif |
| 1135 | #if defined (SIGTERM) |
| 1136 | if (hostsig == SIGTERM) return TARGET_SIGNAL_TERM; |
| 1137 | #endif |
| 1138 | #if defined (SIGUSR1) |
| 1139 | if (hostsig == SIGUSR1) return TARGET_SIGNAL_USR1; |
| 1140 | #endif |
| 1141 | #if defined (SIGUSR2) |
| 1142 | if (hostsig == SIGUSR2) return TARGET_SIGNAL_USR2; |
| 1143 | #endif |
| 1144 | #if defined (SIGCLD) |
| 1145 | if (hostsig == SIGCLD) return TARGET_SIGNAL_CHLD; |
| 1146 | #endif |
| 1147 | #if defined (SIGCHLD) |
| 1148 | if (hostsig == SIGCHLD) return TARGET_SIGNAL_CHLD; |
| 1149 | #endif |
| 1150 | #if defined (SIGPWR) |
| 1151 | if (hostsig == SIGPWR) return TARGET_SIGNAL_PWR; |
| 1152 | #endif |
| 1153 | #if defined (SIGWINCH) |
| 1154 | if (hostsig == SIGWINCH) return TARGET_SIGNAL_WINCH; |
| 1155 | #endif |
| 1156 | #if defined (SIGURG) |
| 1157 | if (hostsig == SIGURG) return TARGET_SIGNAL_URG; |
| 1158 | #endif |
| 1159 | #if defined (SIGIO) |
| 1160 | if (hostsig == SIGIO) return TARGET_SIGNAL_IO; |
| 1161 | #endif |
| 1162 | #if defined (SIGPOLL) |
| 1163 | if (hostsig == SIGPOLL) return TARGET_SIGNAL_POLL; |
| 1164 | #endif |
| 1165 | #if defined (SIGSTOP) |
| 1166 | if (hostsig == SIGSTOP) return TARGET_SIGNAL_STOP; |
| 1167 | #endif |
| 1168 | #if defined (SIGTSTP) |
| 1169 | if (hostsig == SIGTSTP) return TARGET_SIGNAL_TSTP; |
| 1170 | #endif |
| 1171 | #if defined (SIGCONT) |
| 1172 | if (hostsig == SIGCONT) return TARGET_SIGNAL_CONT; |
| 1173 | #endif |
| 1174 | #if defined (SIGTTIN) |
| 1175 | if (hostsig == SIGTTIN) return TARGET_SIGNAL_TTIN; |
| 1176 | #endif |
| 1177 | #if defined (SIGTTOU) |
| 1178 | if (hostsig == SIGTTOU) return TARGET_SIGNAL_TTOU; |
| 1179 | #endif |
| 1180 | #if defined (SIGVTALRM) |
| 1181 | if (hostsig == SIGVTALRM) return TARGET_SIGNAL_VTALRM; |
| 1182 | #endif |
| 1183 | #if defined (SIGPROF) |
| 1184 | if (hostsig == SIGPROF) return TARGET_SIGNAL_PROF; |
| 1185 | #endif |
| 1186 | #if defined (SIGXCPU) |
| 1187 | if (hostsig == SIGXCPU) return TARGET_SIGNAL_XCPU; |
| 1188 | #endif |
| 1189 | #if defined (SIGXFSZ) |
| 1190 | if (hostsig == SIGXFSZ) return TARGET_SIGNAL_XFSZ; |
| 1191 | #endif |
| 1192 | #if defined (SIGWIND) |
| 1193 | if (hostsig == SIGWIND) return TARGET_SIGNAL_WIND; |
| 1194 | #endif |
| 1195 | #if defined (SIGPHONE) |
| 1196 | if (hostsig == SIGPHONE) return TARGET_SIGNAL_PHONE; |
| 1197 | #endif |
| 1198 | #if defined (SIGLOST) |
| 1199 | if (hostsig == SIGLOST) return TARGET_SIGNAL_LOST; |
| 1200 | #endif |
| 1201 | #if defined (SIGWAITING) |
| 1202 | if (hostsig == SIGWAITING) return TARGET_SIGNAL_WAITING; |
| 1203 | #endif |
| 1204 | #if defined (SIGLWP) |
| 1205 | if (hostsig == SIGLWP) return TARGET_SIGNAL_LWP; |
| 1206 | #endif |
| 1207 | #if defined (SIGDANGER) |
| 1208 | if (hostsig == SIGDANGER) return TARGET_SIGNAL_DANGER; |
| 1209 | #endif |
| 1210 | #if defined (SIGGRANT) |
| 1211 | if (hostsig == SIGGRANT) return TARGET_SIGNAL_GRANT; |
| 1212 | #endif |
| 1213 | #if defined (SIGRETRACT) |
| 1214 | if (hostsig == SIGRETRACT) return TARGET_SIGNAL_RETRACT; |
| 1215 | #endif |
| 1216 | #if defined (SIGMSG) |
| 1217 | if (hostsig == SIGMSG) return TARGET_SIGNAL_MSG; |
| 1218 | #endif |
| 1219 | #if defined (SIGSOUND) |
| 1220 | if (hostsig == SIGSOUND) return TARGET_SIGNAL_SOUND; |
| 1221 | #endif |
| 1222 | #if defined (SIGSAK) |
| 1223 | if (hostsig == SIGSAK) return TARGET_SIGNAL_SAK; |
| 1224 | #endif |
| 1225 | #if defined (SIGPRIO) |
| 1226 | if (hostsig == SIGPRIO) return TARGET_SIGNAL_PRIO; |
| 1227 | #endif |
| 1228 | #if defined (REALTIME_LO) |
| 1229 | if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) |
| 1230 | return (enum target_signal) |
| 1231 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); |
| 1232 | #endif |
| 1233 | return TARGET_SIGNAL_UNKNOWN; |
| 1234 | } |
| 1235 | |
| 1236 | int |
| 1237 | target_signal_to_host (oursig) |
| 1238 | enum target_signal oursig; |
| 1239 | { |
| 1240 | switch (oursig) |
| 1241 | { |
| 1242 | case TARGET_SIGNAL_0: return 0; |
| 1243 | |
| 1244 | #if defined (SIGHUP) |
| 1245 | case TARGET_SIGNAL_HUP: return SIGHUP; |
| 1246 | #endif |
| 1247 | #if defined (SIGINT) |
| 1248 | case TARGET_SIGNAL_INT: return SIGINT; |
| 1249 | #endif |
| 1250 | #if defined (SIGQUIT) |
| 1251 | case TARGET_SIGNAL_QUIT: return SIGQUIT; |
| 1252 | #endif |
| 1253 | #if defined (SIGILL) |
| 1254 | case TARGET_SIGNAL_ILL: return SIGILL; |
| 1255 | #endif |
| 1256 | #if defined (SIGTRAP) |
| 1257 | case TARGET_SIGNAL_TRAP: return SIGTRAP; |
| 1258 | #endif |
| 1259 | #if defined (SIGABRT) |
| 1260 | case TARGET_SIGNAL_ABRT: return SIGABRT; |
| 1261 | #endif |
| 1262 | #if defined (SIGEMT) |
| 1263 | case TARGET_SIGNAL_EMT: return SIGEMT; |
| 1264 | #endif |
| 1265 | #if defined (SIGFPE) |
| 1266 | case TARGET_SIGNAL_FPE: return SIGFPE; |
| 1267 | #endif |
| 1268 | #if defined (SIGKILL) |
| 1269 | case TARGET_SIGNAL_KILL: return SIGKILL; |
| 1270 | #endif |
| 1271 | #if defined (SIGBUS) |
| 1272 | case TARGET_SIGNAL_BUS: return SIGBUS; |
| 1273 | #endif |
| 1274 | #if defined (SIGSEGV) |
| 1275 | case TARGET_SIGNAL_SEGV: return SIGSEGV; |
| 1276 | #endif |
| 1277 | #if defined (SIGSYS) |
| 1278 | case TARGET_SIGNAL_SYS: return SIGSYS; |
| 1279 | #endif |
| 1280 | #if defined (SIGPIPE) |
| 1281 | case TARGET_SIGNAL_PIPE: return SIGPIPE; |
| 1282 | #endif |
| 1283 | #if defined (SIGALRM) |
| 1284 | case TARGET_SIGNAL_ALRM: return SIGALRM; |
| 1285 | #endif |
| 1286 | #if defined (SIGTERM) |
| 1287 | case TARGET_SIGNAL_TERM: return SIGTERM; |
| 1288 | #endif |
| 1289 | #if defined (SIGUSR1) |
| 1290 | case TARGET_SIGNAL_USR1: return SIGUSR1; |
| 1291 | #endif |
| 1292 | #if defined (SIGUSR2) |
| 1293 | case TARGET_SIGNAL_USR2: return SIGUSR2; |
| 1294 | #endif |
| 1295 | #if defined (SIGCHLD) || defined (SIGCLD) |
| 1296 | case TARGET_SIGNAL_CHLD: |
| 1297 | #if defined (SIGCHLD) |
| 1298 | return SIGCHLD; |
| 1299 | #else |
| 1300 | return SIGCLD; |
| 1301 | #endif |
| 1302 | #endif /* SIGCLD or SIGCHLD */ |
| 1303 | #if defined (SIGPWR) |
| 1304 | case TARGET_SIGNAL_PWR: return SIGPWR; |
| 1305 | #endif |
| 1306 | #if defined (SIGWINCH) |
| 1307 | case TARGET_SIGNAL_WINCH: return SIGWINCH; |
| 1308 | #endif |
| 1309 | #if defined (SIGURG) |
| 1310 | case TARGET_SIGNAL_URG: return SIGURG; |
| 1311 | #endif |
| 1312 | #if defined (SIGIO) |
| 1313 | case TARGET_SIGNAL_IO: return SIGIO; |
| 1314 | #endif |
| 1315 | #if defined (SIGPOLL) |
| 1316 | case TARGET_SIGNAL_POLL: return SIGPOLL; |
| 1317 | #endif |
| 1318 | #if defined (SIGSTOP) |
| 1319 | case TARGET_SIGNAL_STOP: return SIGSTOP; |
| 1320 | #endif |
| 1321 | #if defined (SIGTSTP) |
| 1322 | case TARGET_SIGNAL_TSTP: return SIGTSTP; |
| 1323 | #endif |
| 1324 | #if defined (SIGCONT) |
| 1325 | case TARGET_SIGNAL_CONT: return SIGCONT; |
| 1326 | #endif |
| 1327 | #if defined (SIGTTIN) |
| 1328 | case TARGET_SIGNAL_TTIN: return SIGTTIN; |
| 1329 | #endif |
| 1330 | #if defined (SIGTTOU) |
| 1331 | case TARGET_SIGNAL_TTOU: return SIGTTOU; |
| 1332 | #endif |
| 1333 | #if defined (SIGVTALRM) |
| 1334 | case TARGET_SIGNAL_VTALRM: return SIGVTALRM; |
| 1335 | #endif |
| 1336 | #if defined (SIGPROF) |
| 1337 | case TARGET_SIGNAL_PROF: return SIGPROF; |
| 1338 | #endif |
| 1339 | #if defined (SIGXCPU) |
| 1340 | case TARGET_SIGNAL_XCPU: return SIGXCPU; |
| 1341 | #endif |
| 1342 | #if defined (SIGXFSZ) |
| 1343 | case TARGET_SIGNAL_XFSZ: return SIGXFSZ; |
| 1344 | #endif |
| 1345 | #if defined (SIGWIND) |
| 1346 | case TARGET_SIGNAL_WIND: return SIGWIND; |
| 1347 | #endif |
| 1348 | #if defined (SIGPHONE) |
| 1349 | case TARGET_SIGNAL_PHONE: return SIGPHONE; |
| 1350 | #endif |
| 1351 | #if defined (SIGLOST) |
| 1352 | case TARGET_SIGNAL_LOST: return SIGLOST; |
| 1353 | #endif |
| 1354 | #if defined (SIGWAITING) |
| 1355 | case TARGET_SIGNAL_WAITING: return SIGWAITING; |
| 1356 | #endif |
| 1357 | #if defined (SIGLWP) |
| 1358 | case TARGET_SIGNAL_LWP: return SIGLWP; |
| 1359 | #endif |
| 1360 | #if defined (SIGDANGER) |
| 1361 | case TARGET_SIGNAL_DANGER: return SIGDANGER; |
| 1362 | #endif |
| 1363 | #if defined (SIGGRANT) |
| 1364 | case TARGET_SIGNAL_GRANT: return SIGGRANT; |
| 1365 | #endif |
| 1366 | #if defined (SIGRETRACT) |
| 1367 | case TARGET_SIGNAL_RETRACT: return SIGRETRACT; |
| 1368 | #endif |
| 1369 | #if defined (SIGMSG) |
| 1370 | case TARGET_SIGNAL_MSG: return SIGMSG; |
| 1371 | #endif |
| 1372 | #if defined (SIGSOUND) |
| 1373 | case TARGET_SIGNAL_SOUND: return SIGSOUND; |
| 1374 | #endif |
| 1375 | #if defined (SIGSAK) |
| 1376 | case TARGET_SIGNAL_SAK: return SIGSAK; |
| 1377 | #endif |
| 1378 | #if defined (SIGPRIO) |
| 1379 | case TARGET_SIGNAL_PRIO: return SIGPRIO; |
| 1380 | #endif |
| 1381 | default: |
| 1382 | #if defined (REALTIME_LO) |
| 1383 | if (oursig >= TARGET_SIGNAL_REALTIME_33 |
| 1384 | && oursig <= TARGET_SIGNAL_REALTIME_63) |
| 1385 | { |
| 1386 | int retsig = |
| 1387 | (int)oursig - (int)TARGET_SIGNAL_REALTIME_33 + REALTIME_LO; |
| 1388 | if (retsig < REALTIME_HI) |
| 1389 | return retsig; |
| 1390 | } |
| 1391 | #endif |
| 1392 | /* The user might be trying to do "signal SIGSAK" where this system |
| 1393 | doesn't have SIGSAK. */ |
| 1394 | warning ("Signal %s does not exist on this system.\n", |
| 1395 | target_signal_to_name (oursig)); |
| 1396 | return 0; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | /* Helper function for child_wait and the Lynx derivatives of child_wait. |
| 1401 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our |
| 1402 | translation of that in OURSTATUS. */ |
| 1403 | void |
| 1404 | store_waitstatus (ourstatus, hoststatus) |
| 1405 | struct target_waitstatus *ourstatus; |
| 1406 | int hoststatus; |
| 1407 | { |
| 1408 | #ifdef CHILD_SPECIAL_WAITSTATUS |
| 1409 | /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS |
| 1410 | if it wants to deal with hoststatus. */ |
| 1411 | if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus)) |
| 1412 | return; |
| 1413 | #endif |
| 1414 | |
| 1415 | if (WIFEXITED (hoststatus)) |
| 1416 | { |
| 1417 | ourstatus->kind = TARGET_WAITKIND_EXITED; |
| 1418 | ourstatus->value.integer = WEXITSTATUS (hoststatus); |
| 1419 | } |
| 1420 | else if (!WIFSTOPPED (hoststatus)) |
| 1421 | { |
| 1422 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; |
| 1423 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); |
| 1424 | } |
| 1425 | else |
| 1426 | { |
| 1427 | ourstatus->kind = TARGET_WAITKIND_STOPPED; |
| 1428 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); |
| 1429 | } |
| 1430 | } |
| 1431 | \f |
| 1432 | /* In some circumstances we allow a command to specify a numeric |
| 1433 | signal. The idea is to keep these circumstances limited so that |
| 1434 | users (and scripts) develop portable habits. For comparison, |
| 1435 | POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a |
| 1436 | numeric signal at all is obscelescent. We are slightly more |
| 1437 | lenient and allow 1-15 which should match host signal numbers on |
| 1438 | most systems. Use of symbolic signal names is strongly encouraged. */ |
| 1439 | |
| 1440 | enum target_signal |
| 1441 | target_signal_from_command (num) |
| 1442 | int num; |
| 1443 | { |
| 1444 | if (num >= 1 && num <= 15) |
| 1445 | return (enum target_signal)num; |
| 1446 | error ("Only signals 1-15 are valid as numeric signals.\n\ |
| 1447 | Use \"info signals\" for a list of symbolic signals."); |
| 1448 | } |
| 1449 | \f |
| 1450 | /* Returns zero to leave the inferior alone, one to interrupt it. */ |
| 1451 | int (*target_activity_function) PARAMS ((void)); |
| 1452 | int target_activity_fd; |
| 1453 | \f |
| 1454 | /* Convert a normal process ID to a string. Returns the string in a static |
| 1455 | buffer. */ |
| 1456 | |
| 1457 | char * |
| 1458 | normal_pid_to_str (pid) |
| 1459 | int pid; |
| 1460 | { |
| 1461 | static char buf[30]; |
| 1462 | |
| 1463 | if (STREQ (current_target.to_shortname, "remote")) |
| 1464 | sprintf (buf, "thread %d", pid); |
| 1465 | else |
| 1466 | sprintf (buf, "process %d", pid); |
| 1467 | |
| 1468 | return buf; |
| 1469 | } |
| 1470 | \f |
| 1471 | #ifdef MAINTENANCE_CMDS |
| 1472 | static struct target_ops debug_target; |
| 1473 | |
| 1474 | static void |
| 1475 | debug_to_open (args, from_tty) |
| 1476 | char *args; |
| 1477 | int from_tty; |
| 1478 | { |
| 1479 | debug_target.to_open (args, from_tty); |
| 1480 | |
| 1481 | fprintf_unfiltered (stderr, "target_open (%s, %d)\n", args, from_tty); |
| 1482 | } |
| 1483 | |
| 1484 | static void |
| 1485 | debug_to_close (quitting) |
| 1486 | int quitting; |
| 1487 | { |
| 1488 | debug_target.to_close (quitting); |
| 1489 | |
| 1490 | fprintf_unfiltered (stderr, "target_close (%d)\n", quitting); |
| 1491 | } |
| 1492 | |
| 1493 | static void |
| 1494 | debug_to_attach (args, from_tty) |
| 1495 | char *args; |
| 1496 | int from_tty; |
| 1497 | { |
| 1498 | debug_target.to_attach (args, from_tty); |
| 1499 | |
| 1500 | fprintf_unfiltered (stderr, "target_attach (%s, %d)\n", args, from_tty); |
| 1501 | } |
| 1502 | |
| 1503 | static void |
| 1504 | debug_to_detach (args, from_tty) |
| 1505 | char *args; |
| 1506 | int from_tty; |
| 1507 | { |
| 1508 | debug_target.to_detach (args, from_tty); |
| 1509 | |
| 1510 | fprintf_unfiltered (stderr, "target_detach (%s, %d)\n", args, from_tty); |
| 1511 | } |
| 1512 | |
| 1513 | static void |
| 1514 | debug_to_resume (pid, step, siggnal) |
| 1515 | int pid; |
| 1516 | int step; |
| 1517 | enum target_signal siggnal; |
| 1518 | { |
| 1519 | debug_target.to_resume (pid, step, siggnal); |
| 1520 | |
| 1521 | fprintf_unfiltered (stderr, "target_resume (%d, %s, %s)\n", pid, |
| 1522 | step ? "step" : "continue", |
| 1523 | target_signal_to_name (siggnal)); |
| 1524 | } |
| 1525 | |
| 1526 | static int |
| 1527 | debug_to_wait (pid, status) |
| 1528 | int pid; |
| 1529 | struct target_waitstatus *status; |
| 1530 | { |
| 1531 | int retval; |
| 1532 | |
| 1533 | retval = debug_target.to_wait (pid, status); |
| 1534 | |
| 1535 | fprintf_unfiltered (stderr, "target_wait (%d, status) = %d, ", pid, retval); |
| 1536 | fprintf_unfiltered (stderr, "status->kind = "); |
| 1537 | switch (status->kind) |
| 1538 | { |
| 1539 | case TARGET_WAITKIND_EXITED: |
| 1540 | fprintf_unfiltered (stderr, "exited, status = %d\n", status->value.integer); |
| 1541 | break; |
| 1542 | case TARGET_WAITKIND_STOPPED: |
| 1543 | fprintf_unfiltered (stderr, "stopped, signal = %s\n", |
| 1544 | target_signal_to_name (status->value.sig)); |
| 1545 | break; |
| 1546 | case TARGET_WAITKIND_SIGNALLED: |
| 1547 | fprintf_unfiltered (stderr, "signalled, signal = %s\n", |
| 1548 | target_signal_to_name (status->value.sig)); |
| 1549 | break; |
| 1550 | case TARGET_WAITKIND_LOADED: |
| 1551 | fprintf_unfiltered (stderr, "loaded\n"); |
| 1552 | break; |
| 1553 | case TARGET_WAITKIND_SPURIOUS: |
| 1554 | fprintf_unfiltered (stderr, "spurious\n"); |
| 1555 | break; |
| 1556 | default: |
| 1557 | fprintf_unfiltered (stderr, "unknown???\n"); |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | return retval; |
| 1562 | } |
| 1563 | |
| 1564 | static void |
| 1565 | debug_to_fetch_registers (regno) |
| 1566 | int regno; |
| 1567 | { |
| 1568 | debug_target.to_fetch_registers (regno); |
| 1569 | |
| 1570 | fprintf_unfiltered (stderr, "target_fetch_registers (%s)", |
| 1571 | regno != -1 ? reg_names[regno] : "-1"); |
| 1572 | if (regno != -1) |
| 1573 | fprintf_unfiltered (stderr, " = 0x%x %d", read_register (regno), |
| 1574 | read_register (regno)); |
| 1575 | fprintf_unfiltered (stderr, "\n"); |
| 1576 | } |
| 1577 | |
| 1578 | static void |
| 1579 | debug_to_store_registers (regno) |
| 1580 | int regno; |
| 1581 | { |
| 1582 | debug_target.to_store_registers (regno); |
| 1583 | |
| 1584 | if (regno >= 0 && regno < NUM_REGS) |
| 1585 | fprintf_unfiltered (stderr, "target_store_registers (%s) = 0x%x %d\n", |
| 1586 | reg_names[regno], read_register (regno), |
| 1587 | read_register (regno)); |
| 1588 | else |
| 1589 | fprintf_unfiltered (stderr, "target_store_registers (%d)\n", regno); |
| 1590 | } |
| 1591 | |
| 1592 | static void |
| 1593 | debug_to_prepare_to_store () |
| 1594 | { |
| 1595 | debug_target.to_prepare_to_store (); |
| 1596 | |
| 1597 | fprintf_unfiltered (stderr, "target_prepare_to_store ()\n"); |
| 1598 | } |
| 1599 | |
| 1600 | static int |
| 1601 | debug_to_xfer_memory (memaddr, myaddr, len, write, target) |
| 1602 | CORE_ADDR memaddr; |
| 1603 | char *myaddr; |
| 1604 | int len; |
| 1605 | int write; |
| 1606 | struct target_ops *target; |
| 1607 | { |
| 1608 | int retval; |
| 1609 | |
| 1610 | retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, target); |
| 1611 | |
| 1612 | fprintf_unfiltered (stderr, "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
| 1613 | memaddr, len, write ? "write" : "read", retval); |
| 1614 | |
| 1615 | if (retval > 0) |
| 1616 | { |
| 1617 | int i; |
| 1618 | |
| 1619 | fputs_unfiltered (", bytes =", gdb_stderr); |
| 1620 | for (i = 0; i < retval; i++) |
| 1621 | fprintf_unfiltered (stderr, " %02x", myaddr[i] & 0xff); |
| 1622 | } |
| 1623 | |
| 1624 | fputc_unfiltered ('\n', gdb_stderr); |
| 1625 | |
| 1626 | return retval; |
| 1627 | } |
| 1628 | |
| 1629 | static void |
| 1630 | debug_to_files_info (target) |
| 1631 | struct target_ops *target; |
| 1632 | { |
| 1633 | debug_target.to_files_info (target); |
| 1634 | |
| 1635 | fprintf_unfiltered (stderr, "target_files_info (xxx)\n"); |
| 1636 | } |
| 1637 | |
| 1638 | static int |
| 1639 | debug_to_insert_breakpoint (addr, save) |
| 1640 | CORE_ADDR addr; |
| 1641 | char *save; |
| 1642 | { |
| 1643 | int retval; |
| 1644 | |
| 1645 | retval = debug_target.to_insert_breakpoint (addr, save); |
| 1646 | |
| 1647 | fprintf_unfiltered (stderr, "target_insert_breakpoint (0x%x, xxx) = %d\n", |
| 1648 | addr, retval); |
| 1649 | return retval; |
| 1650 | } |
| 1651 | |
| 1652 | static int |
| 1653 | debug_to_remove_breakpoint (addr, save) |
| 1654 | CORE_ADDR addr; |
| 1655 | char *save; |
| 1656 | { |
| 1657 | int retval; |
| 1658 | |
| 1659 | retval = debug_target.to_remove_breakpoint (addr, save); |
| 1660 | |
| 1661 | fprintf_unfiltered (stderr, "target_remove_breakpoint (0x%x, xxx) = %d\n", |
| 1662 | addr, retval); |
| 1663 | return retval; |
| 1664 | } |
| 1665 | |
| 1666 | static void |
| 1667 | debug_to_terminal_init () |
| 1668 | { |
| 1669 | debug_target.to_terminal_init (); |
| 1670 | |
| 1671 | fprintf_unfiltered (stderr, "target_terminal_init ()\n"); |
| 1672 | } |
| 1673 | |
| 1674 | static void |
| 1675 | debug_to_terminal_inferior () |
| 1676 | { |
| 1677 | debug_target.to_terminal_inferior (); |
| 1678 | |
| 1679 | fprintf_unfiltered (stderr, "target_terminal_inferior ()\n"); |
| 1680 | } |
| 1681 | |
| 1682 | static void |
| 1683 | debug_to_terminal_ours_for_output () |
| 1684 | { |
| 1685 | debug_target.to_terminal_ours_for_output (); |
| 1686 | |
| 1687 | fprintf_unfiltered (stderr, "target_terminal_ours_for_output ()\n"); |
| 1688 | } |
| 1689 | |
| 1690 | static void |
| 1691 | debug_to_terminal_ours () |
| 1692 | { |
| 1693 | debug_target.to_terminal_ours (); |
| 1694 | |
| 1695 | fprintf_unfiltered (stderr, "target_terminal_ours ()\n"); |
| 1696 | } |
| 1697 | |
| 1698 | static void |
| 1699 | debug_to_terminal_info (arg, from_tty) |
| 1700 | char *arg; |
| 1701 | int from_tty; |
| 1702 | { |
| 1703 | debug_target.to_terminal_info (arg, from_tty); |
| 1704 | |
| 1705 | fprintf_unfiltered (stderr, "target_terminal_info (%s, %d)\n", arg, |
| 1706 | from_tty); |
| 1707 | } |
| 1708 | |
| 1709 | static void |
| 1710 | debug_to_kill () |
| 1711 | { |
| 1712 | debug_target.to_kill (); |
| 1713 | |
| 1714 | fprintf_unfiltered (stderr, "target_kill ()\n"); |
| 1715 | } |
| 1716 | |
| 1717 | static void |
| 1718 | debug_to_load (args, from_tty) |
| 1719 | char *args; |
| 1720 | int from_tty; |
| 1721 | { |
| 1722 | debug_target.to_load (args, from_tty); |
| 1723 | |
| 1724 | fprintf_unfiltered (stderr, "target_load (%s, %d)\n", args, from_tty); |
| 1725 | } |
| 1726 | |
| 1727 | static int |
| 1728 | debug_to_lookup_symbol (name, addrp) |
| 1729 | char *name; |
| 1730 | CORE_ADDR *addrp; |
| 1731 | { |
| 1732 | int retval; |
| 1733 | |
| 1734 | retval = debug_target.to_lookup_symbol (name, addrp); |
| 1735 | |
| 1736 | fprintf_unfiltered (stderr, "target_lookup_symbol (%s, xxx)\n", name); |
| 1737 | |
| 1738 | return retval; |
| 1739 | } |
| 1740 | |
| 1741 | static void |
| 1742 | debug_to_create_inferior (exec_file, args, env) |
| 1743 | char *exec_file; |
| 1744 | char *args; |
| 1745 | char **env; |
| 1746 | { |
| 1747 | debug_target.to_create_inferior (exec_file, args, env); |
| 1748 | |
| 1749 | fprintf_unfiltered (stderr, "target_create_inferior (%s, %s, xxx)\n", |
| 1750 | exec_file, args); |
| 1751 | } |
| 1752 | |
| 1753 | static void |
| 1754 | debug_to_mourn_inferior () |
| 1755 | { |
| 1756 | debug_target.to_mourn_inferior (); |
| 1757 | |
| 1758 | fprintf_unfiltered (stderr, "target_mourn_inferior ()\n"); |
| 1759 | } |
| 1760 | |
| 1761 | static int |
| 1762 | debug_to_can_run () |
| 1763 | { |
| 1764 | int retval; |
| 1765 | |
| 1766 | retval = debug_target.to_can_run (); |
| 1767 | |
| 1768 | fprintf_unfiltered (stderr, "target_can_run () = %d\n", retval); |
| 1769 | |
| 1770 | return retval; |
| 1771 | } |
| 1772 | |
| 1773 | static void |
| 1774 | debug_to_notice_signals (pid) |
| 1775 | int pid; |
| 1776 | { |
| 1777 | debug_target.to_notice_signals (pid); |
| 1778 | |
| 1779 | fprintf_unfiltered (stderr, "target_notice_signals (%d)\n", pid); |
| 1780 | } |
| 1781 | |
| 1782 | static int |
| 1783 | debug_to_thread_alive (pid) |
| 1784 | int pid; |
| 1785 | { |
| 1786 | debug_target.to_thread_alive (pid); |
| 1787 | |
| 1788 | fprintf_unfiltered (stderr, "target_thread_alive (%d)\n", pid); |
| 1789 | return (0); |
| 1790 | } |
| 1791 | |
| 1792 | static void |
| 1793 | debug_to_stop () |
| 1794 | { |
| 1795 | debug_target.to_stop (); |
| 1796 | |
| 1797 | fprintf_unfiltered (stderr, "target_stop ()\n"); |
| 1798 | } |
| 1799 | |
| 1800 | static void |
| 1801 | setup_target_debug () |
| 1802 | { |
| 1803 | memcpy (&debug_target, ¤t_target, sizeof debug_target); |
| 1804 | |
| 1805 | current_target.to_open = debug_to_open; |
| 1806 | current_target.to_close = debug_to_close; |
| 1807 | current_target.to_attach = debug_to_attach; |
| 1808 | current_target.to_detach = debug_to_detach; |
| 1809 | current_target.to_resume = debug_to_resume; |
| 1810 | current_target.to_wait = debug_to_wait; |
| 1811 | current_target.to_fetch_registers = debug_to_fetch_registers; |
| 1812 | current_target.to_store_registers = debug_to_store_registers; |
| 1813 | current_target.to_prepare_to_store = debug_to_prepare_to_store; |
| 1814 | current_target.to_xfer_memory = debug_to_xfer_memory; |
| 1815 | current_target.to_files_info = debug_to_files_info; |
| 1816 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; |
| 1817 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; |
| 1818 | current_target.to_terminal_init = debug_to_terminal_init; |
| 1819 | current_target.to_terminal_inferior = debug_to_terminal_inferior; |
| 1820 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; |
| 1821 | current_target.to_terminal_ours = debug_to_terminal_ours; |
| 1822 | current_target.to_terminal_info = debug_to_terminal_info; |
| 1823 | current_target.to_kill = debug_to_kill; |
| 1824 | current_target.to_load = debug_to_load; |
| 1825 | current_target.to_lookup_symbol = debug_to_lookup_symbol; |
| 1826 | current_target.to_create_inferior = debug_to_create_inferior; |
| 1827 | current_target.to_mourn_inferior = debug_to_mourn_inferior; |
| 1828 | current_target.to_can_run = debug_to_can_run; |
| 1829 | current_target.to_notice_signals = debug_to_notice_signals; |
| 1830 | current_target.to_thread_alive = debug_to_thread_alive; |
| 1831 | current_target.to_stop = debug_to_stop; |
| 1832 | } |
| 1833 | #endif /* MAINTENANCE_CMDS */ |
| 1834 | \f |
| 1835 | static char targ_desc[] = |
| 1836 | "Names of targets and files being debugged.\n\ |
| 1837 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
| 1838 | core-file, and process, if any), as well as the symbol file name."; |
| 1839 | |
| 1840 | void |
| 1841 | initialize_targets () |
| 1842 | { |
| 1843 | push_target (&dummy_target); |
| 1844 | |
| 1845 | add_info ("target", target_info, targ_desc); |
| 1846 | add_info ("files", target_info, targ_desc); |
| 1847 | |
| 1848 | #ifdef MAINTENANCE_CMDS |
| 1849 | add_show_from_set ( |
| 1850 | add_set_cmd ("targetdebug", class_maintenance, var_zinteger, |
| 1851 | (char *)&targetdebug, |
| 1852 | "Set target debugging.\n\ |
| 1853 | When non-zero, target debugging is enabled.", &setlist), |
| 1854 | &showlist); |
| 1855 | #endif |
| 1856 | |
| 1857 | if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC")) |
| 1858 | abort (); |
| 1859 | } |