| 1 | /* Select target systems and architectures at runtime for GDB. |
| 2 | Copyright 1990, 1992-1995, 1998-2000, 2001 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, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include <errno.h> |
| 24 | #include <ctype.h> |
| 25 | #include "gdb_string.h" |
| 26 | #include "target.h" |
| 27 | #include "gdbcmd.h" |
| 28 | #include "symtab.h" |
| 29 | #include "inferior.h" |
| 30 | #include "bfd.h" |
| 31 | #include "symfile.h" |
| 32 | #include "objfiles.h" |
| 33 | #include "gdb_wait.h" |
| 34 | #include "dcache.h" |
| 35 | #include <signal.h> |
| 36 | |
| 37 | extern int errno; |
| 38 | |
| 39 | static void target_info (char *, int); |
| 40 | |
| 41 | static void cleanup_target (struct target_ops *); |
| 42 | |
| 43 | static void maybe_kill_then_create_inferior (char *, char *, char **); |
| 44 | |
| 45 | static void default_clone_and_follow_inferior (int, int *); |
| 46 | |
| 47 | static void maybe_kill_then_attach (char *, int); |
| 48 | |
| 49 | static void kill_or_be_killed (int); |
| 50 | |
| 51 | static void default_terminal_info (char *, int); |
| 52 | |
| 53 | static int nosymbol (char *, CORE_ADDR *); |
| 54 | |
| 55 | static void tcomplain (void); |
| 56 | |
| 57 | static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); |
| 58 | |
| 59 | static int return_zero (void); |
| 60 | |
| 61 | static int return_one (void); |
| 62 | |
| 63 | void target_ignore (void); |
| 64 | |
| 65 | static void target_command (char *, int); |
| 66 | |
| 67 | static struct target_ops *find_default_run_target (char *); |
| 68 | |
| 69 | static void update_current_target (void); |
| 70 | |
| 71 | static void nosupport_runtime (void); |
| 72 | |
| 73 | static void normal_target_post_startup_inferior (int pid); |
| 74 | |
| 75 | /* Transfer LEN bytes between target address MEMADDR and GDB address |
| 76 | MYADDR. Returns 0 for success, errno code for failure (which |
| 77 | includes partial transfers -- if you want a more useful response to |
| 78 | partial transfers, try either target_read_memory_partial or |
| 79 | target_write_memory_partial). */ |
| 80 | |
| 81 | static int |
| 82 | target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write); |
| 83 | |
| 84 | static void init_dummy_target (void); |
| 85 | |
| 86 | static void debug_to_open (char *, int); |
| 87 | |
| 88 | static void debug_to_close (int); |
| 89 | |
| 90 | static void debug_to_attach (char *, int); |
| 91 | |
| 92 | static void debug_to_detach (char *, int); |
| 93 | |
| 94 | static void debug_to_resume (int, int, enum target_signal); |
| 95 | |
| 96 | static int debug_to_wait (int, struct target_waitstatus *); |
| 97 | |
| 98 | static void debug_to_fetch_registers (int); |
| 99 | |
| 100 | static void debug_to_store_registers (int); |
| 101 | |
| 102 | static void debug_to_prepare_to_store (void); |
| 103 | |
| 104 | static int |
| 105 | debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *, |
| 106 | struct target_ops *); |
| 107 | |
| 108 | static void debug_to_files_info (struct target_ops *); |
| 109 | |
| 110 | static int debug_to_insert_breakpoint (CORE_ADDR, char *); |
| 111 | |
| 112 | static int debug_to_remove_breakpoint (CORE_ADDR, char *); |
| 113 | |
| 114 | static void debug_to_terminal_init (void); |
| 115 | |
| 116 | static void debug_to_terminal_inferior (void); |
| 117 | |
| 118 | static void debug_to_terminal_ours_for_output (void); |
| 119 | |
| 120 | static void debug_to_terminal_ours (void); |
| 121 | |
| 122 | static void debug_to_terminal_info (char *, int); |
| 123 | |
| 124 | static void debug_to_kill (void); |
| 125 | |
| 126 | static void debug_to_load (char *, int); |
| 127 | |
| 128 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
| 129 | |
| 130 | static void debug_to_create_inferior (char *, char *, char **); |
| 131 | |
| 132 | static void debug_to_mourn_inferior (void); |
| 133 | |
| 134 | static int debug_to_can_run (void); |
| 135 | |
| 136 | static void debug_to_notice_signals (int); |
| 137 | |
| 138 | static int debug_to_thread_alive (int); |
| 139 | |
| 140 | static void debug_to_stop (void); |
| 141 | |
| 142 | static int debug_to_query (int /*char */ , char *, char *, int *); |
| 143 | |
| 144 | /* Pointer to array of target architecture structures; the size of the |
| 145 | array; the current index into the array; the allocated size of the |
| 146 | array. */ |
| 147 | struct target_ops **target_structs; |
| 148 | unsigned target_struct_size; |
| 149 | unsigned target_struct_index; |
| 150 | unsigned target_struct_allocsize; |
| 151 | #define DEFAULT_ALLOCSIZE 10 |
| 152 | |
| 153 | /* The initial current target, so that there is always a semi-valid |
| 154 | current target. */ |
| 155 | |
| 156 | static struct target_ops dummy_target; |
| 157 | |
| 158 | /* Top of target stack. */ |
| 159 | |
| 160 | struct target_stack_item *target_stack; |
| 161 | |
| 162 | /* The target structure we are currently using to talk to a process |
| 163 | or file or whatever "inferior" we have. */ |
| 164 | |
| 165 | struct target_ops current_target; |
| 166 | |
| 167 | /* Command list for target. */ |
| 168 | |
| 169 | static struct cmd_list_element *targetlist = NULL; |
| 170 | |
| 171 | /* Nonzero if we are debugging an attached outside process |
| 172 | rather than an inferior. */ |
| 173 | |
| 174 | int attach_flag; |
| 175 | |
| 176 | /* Non-zero if we want to see trace of target level stuff. */ |
| 177 | |
| 178 | static int targetdebug = 0; |
| 179 | |
| 180 | static void setup_target_debug (void); |
| 181 | |
| 182 | DCACHE *target_dcache; |
| 183 | |
| 184 | /* The user just typed 'target' without the name of a target. */ |
| 185 | |
| 186 | /* ARGSUSED */ |
| 187 | static void |
| 188 | target_command (char *arg, int from_tty) |
| 189 | { |
| 190 | fputs_filtered ("Argument required (target name). Try `help target'\n", |
| 191 | gdb_stdout); |
| 192 | } |
| 193 | |
| 194 | /* Add a possible target architecture to the list. */ |
| 195 | |
| 196 | void |
| 197 | add_target (struct target_ops *t) |
| 198 | { |
| 199 | if (!target_structs) |
| 200 | { |
| 201 | target_struct_allocsize = DEFAULT_ALLOCSIZE; |
| 202 | target_structs = (struct target_ops **) xmalloc |
| 203 | (target_struct_allocsize * sizeof (*target_structs)); |
| 204 | } |
| 205 | if (target_struct_size >= target_struct_allocsize) |
| 206 | { |
| 207 | target_struct_allocsize *= 2; |
| 208 | target_structs = (struct target_ops **) |
| 209 | xrealloc ((char *) target_structs, |
| 210 | target_struct_allocsize * sizeof (*target_structs)); |
| 211 | } |
| 212 | target_structs[target_struct_size++] = t; |
| 213 | /* cleanup_target (t); */ |
| 214 | |
| 215 | if (targetlist == NULL) |
| 216 | add_prefix_cmd ("target", class_run, target_command, |
| 217 | "Connect to a target machine or process.\n\ |
| 218 | The first argument is the type or protocol of the target machine.\n\ |
| 219 | Remaining arguments are interpreted by the target protocol. For more\n\ |
| 220 | information on the arguments for a particular protocol, type\n\ |
| 221 | `help target ' followed by the protocol name.", |
| 222 | &targetlist, "target ", 0, &cmdlist); |
| 223 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); |
| 224 | } |
| 225 | |
| 226 | /* Stub functions */ |
| 227 | |
| 228 | void |
| 229 | target_ignore (void) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | target_load (char *arg, int from_tty) |
| 235 | { |
| 236 | dcache_invalidate (target_dcache); |
| 237 | (*current_target.to_load) (arg, from_tty); |
| 238 | } |
| 239 | |
| 240 | /* ARGSUSED */ |
| 241 | static int |
| 242 | nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
| 243 | struct target_ops *t) |
| 244 | { |
| 245 | errno = EIO; /* Can't read/write this location */ |
| 246 | return 0; /* No bytes handled */ |
| 247 | } |
| 248 | |
| 249 | static void |
| 250 | tcomplain (void) |
| 251 | { |
| 252 | error ("You can't do that when your target is `%s'", |
| 253 | current_target.to_shortname); |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | noprocess (void) |
| 258 | { |
| 259 | error ("You can't do that without a process to debug."); |
| 260 | } |
| 261 | |
| 262 | /* ARGSUSED */ |
| 263 | static int |
| 264 | nosymbol (char *name, CORE_ADDR *addrp) |
| 265 | { |
| 266 | return 1; /* Symbol does not exist in target env */ |
| 267 | } |
| 268 | |
| 269 | /* ARGSUSED */ |
| 270 | static void |
| 271 | nosupport_runtime (void) |
| 272 | { |
| 273 | if (!inferior_pid) |
| 274 | noprocess (); |
| 275 | else |
| 276 | error ("No run-time support for this"); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | /* ARGSUSED */ |
| 281 | static void |
| 282 | default_terminal_info (char *args, int from_tty) |
| 283 | { |
| 284 | printf_unfiltered ("No saved terminal information.\n"); |
| 285 | } |
| 286 | |
| 287 | /* This is the default target_create_inferior and target_attach function. |
| 288 | If the current target is executing, it asks whether to kill it off. |
| 289 | If this function returns without calling error(), it has killed off |
| 290 | the target, and the operation should be attempted. */ |
| 291 | |
| 292 | static void |
| 293 | kill_or_be_killed (int from_tty) |
| 294 | { |
| 295 | if (target_has_execution) |
| 296 | { |
| 297 | printf_unfiltered ("You are already running a program:\n"); |
| 298 | target_files_info (); |
| 299 | if (query ("Kill it? ")) |
| 300 | { |
| 301 | target_kill (); |
| 302 | if (target_has_execution) |
| 303 | error ("Killing the program did not help."); |
| 304 | return; |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | error ("Program not killed."); |
| 309 | } |
| 310 | } |
| 311 | tcomplain (); |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | maybe_kill_then_attach (char *args, int from_tty) |
| 316 | { |
| 317 | kill_or_be_killed (from_tty); |
| 318 | target_attach (args, from_tty); |
| 319 | } |
| 320 | |
| 321 | static void |
| 322 | maybe_kill_then_create_inferior (char *exec, char *args, char **env) |
| 323 | { |
| 324 | kill_or_be_killed (0); |
| 325 | target_create_inferior (exec, args, env); |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | default_clone_and_follow_inferior (int child_pid, int *followed_child) |
| 330 | { |
| 331 | target_clone_and_follow_inferior (child_pid, followed_child); |
| 332 | } |
| 333 | |
| 334 | /* Clean up a target struct so it no longer has any zero pointers in it. |
| 335 | We default entries, at least to stubs that print error messages. */ |
| 336 | |
| 337 | static void |
| 338 | cleanup_target (struct target_ops *t) |
| 339 | { |
| 340 | |
| 341 | #define de_fault(field, value) \ |
| 342 | if (!t->field) \ |
| 343 | t->field = value |
| 344 | |
| 345 | de_fault (to_open, |
| 346 | (void (*) (char *, int)) |
| 347 | tcomplain); |
| 348 | de_fault (to_close, |
| 349 | (void (*) (int)) |
| 350 | target_ignore); |
| 351 | de_fault (to_attach, |
| 352 | maybe_kill_then_attach); |
| 353 | de_fault (to_post_attach, |
| 354 | (void (*) (int)) |
| 355 | target_ignore); |
| 356 | de_fault (to_require_attach, |
| 357 | maybe_kill_then_attach); |
| 358 | de_fault (to_detach, |
| 359 | (void (*) (char *, int)) |
| 360 | target_ignore); |
| 361 | de_fault (to_require_detach, |
| 362 | (void (*) (int, char *, int)) |
| 363 | target_ignore); |
| 364 | de_fault (to_resume, |
| 365 | (void (*) (int, int, enum target_signal)) |
| 366 | noprocess); |
| 367 | de_fault (to_wait, |
| 368 | (int (*) (int, struct target_waitstatus *)) |
| 369 | noprocess); |
| 370 | de_fault (to_post_wait, |
| 371 | (void (*) (int, int)) |
| 372 | target_ignore); |
| 373 | de_fault (to_fetch_registers, |
| 374 | (void (*) (int)) |
| 375 | target_ignore); |
| 376 | de_fault (to_store_registers, |
| 377 | (void (*) (int)) |
| 378 | noprocess); |
| 379 | de_fault (to_prepare_to_store, |
| 380 | (void (*) (void)) |
| 381 | noprocess); |
| 382 | de_fault (to_xfer_memory, |
| 383 | (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *)) |
| 384 | nomemory); |
| 385 | de_fault (to_files_info, |
| 386 | (void (*) (struct target_ops *)) |
| 387 | target_ignore); |
| 388 | de_fault (to_insert_breakpoint, |
| 389 | memory_insert_breakpoint); |
| 390 | de_fault (to_remove_breakpoint, |
| 391 | memory_remove_breakpoint); |
| 392 | de_fault (to_terminal_init, |
| 393 | (void (*) (void)) |
| 394 | target_ignore); |
| 395 | de_fault (to_terminal_inferior, |
| 396 | (void (*) (void)) |
| 397 | target_ignore); |
| 398 | de_fault (to_terminal_ours_for_output, |
| 399 | (void (*) (void)) |
| 400 | target_ignore); |
| 401 | de_fault (to_terminal_ours, |
| 402 | (void (*) (void)) |
| 403 | target_ignore); |
| 404 | de_fault (to_terminal_info, |
| 405 | default_terminal_info); |
| 406 | de_fault (to_kill, |
| 407 | (void (*) (void)) |
| 408 | noprocess); |
| 409 | de_fault (to_load, |
| 410 | (void (*) (char *, int)) |
| 411 | tcomplain); |
| 412 | de_fault (to_lookup_symbol, |
| 413 | (int (*) (char *, CORE_ADDR *)) |
| 414 | nosymbol); |
| 415 | de_fault (to_create_inferior, |
| 416 | maybe_kill_then_create_inferior); |
| 417 | de_fault (to_post_startup_inferior, |
| 418 | (void (*) (int)) |
| 419 | target_ignore); |
| 420 | de_fault (to_acknowledge_created_inferior, |
| 421 | (void (*) (int)) |
| 422 | target_ignore); |
| 423 | de_fault (to_clone_and_follow_inferior, |
| 424 | default_clone_and_follow_inferior); |
| 425 | de_fault (to_post_follow_inferior_by_clone, |
| 426 | (void (*) (void)) |
| 427 | target_ignore); |
| 428 | de_fault (to_insert_fork_catchpoint, |
| 429 | (int (*) (int)) |
| 430 | tcomplain); |
| 431 | de_fault (to_remove_fork_catchpoint, |
| 432 | (int (*) (int)) |
| 433 | tcomplain); |
| 434 | de_fault (to_insert_vfork_catchpoint, |
| 435 | (int (*) (int)) |
| 436 | tcomplain); |
| 437 | de_fault (to_remove_vfork_catchpoint, |
| 438 | (int (*) (int)) |
| 439 | tcomplain); |
| 440 | de_fault (to_has_forked, |
| 441 | (int (*) (int, int *)) |
| 442 | return_zero); |
| 443 | de_fault (to_has_vforked, |
| 444 | (int (*) (int, int *)) |
| 445 | return_zero); |
| 446 | de_fault (to_can_follow_vfork_prior_to_exec, |
| 447 | (int (*) (void)) |
| 448 | return_zero); |
| 449 | de_fault (to_post_follow_vfork, |
| 450 | (void (*) (int, int, int, int)) |
| 451 | target_ignore); |
| 452 | de_fault (to_insert_exec_catchpoint, |
| 453 | (int (*) (int)) |
| 454 | tcomplain); |
| 455 | de_fault (to_remove_exec_catchpoint, |
| 456 | (int (*) (int)) |
| 457 | tcomplain); |
| 458 | de_fault (to_has_execd, |
| 459 | (int (*) (int, char **)) |
| 460 | return_zero); |
| 461 | de_fault (to_reported_exec_events_per_exec_call, |
| 462 | (int (*) (void)) |
| 463 | return_one); |
| 464 | de_fault (to_has_syscall_event, |
| 465 | (int (*) (int, enum target_waitkind *, int *)) |
| 466 | return_zero); |
| 467 | de_fault (to_has_exited, |
| 468 | (int (*) (int, int, int *)) |
| 469 | return_zero); |
| 470 | de_fault (to_mourn_inferior, |
| 471 | (void (*) (void)) |
| 472 | noprocess); |
| 473 | de_fault (to_can_run, |
| 474 | return_zero); |
| 475 | de_fault (to_notice_signals, |
| 476 | (void (*) (int)) |
| 477 | target_ignore); |
| 478 | de_fault (to_thread_alive, |
| 479 | (int (*) (int)) |
| 480 | return_zero); |
| 481 | de_fault (to_find_new_threads, |
| 482 | (void (*) (void)) |
| 483 | target_ignore); |
| 484 | de_fault (to_extra_thread_info, |
| 485 | (char *(*) (struct thread_info *)) |
| 486 | return_zero); |
| 487 | de_fault (to_stop, |
| 488 | (void (*) (void)) |
| 489 | target_ignore); |
| 490 | de_fault (to_query, |
| 491 | (int (*) (int, char *, char *, int *)) |
| 492 | return_zero); |
| 493 | de_fault (to_rcmd, |
| 494 | (void (*) (char *, struct ui_file *)) |
| 495 | tcomplain); |
| 496 | de_fault (to_enable_exception_callback, |
| 497 | (struct symtab_and_line * (*) (enum exception_event_kind, int)) |
| 498 | nosupport_runtime); |
| 499 | de_fault (to_get_current_exception_event, |
| 500 | (struct exception_event_record * (*) (void)) |
| 501 | nosupport_runtime); |
| 502 | de_fault (to_pid_to_exec_file, |
| 503 | (char *(*) (int)) |
| 504 | return_zero); |
| 505 | de_fault (to_core_file_to_sym_file, |
| 506 | (char *(*) (char *)) |
| 507 | return_zero); |
| 508 | de_fault (to_can_async_p, |
| 509 | (int (*) (void)) |
| 510 | return_zero); |
| 511 | de_fault (to_is_async_p, |
| 512 | (int (*) (void)) |
| 513 | return_zero); |
| 514 | de_fault (to_async, |
| 515 | (void (*) (void (*) (enum inferior_event_type, void*), void*)) |
| 516 | tcomplain); |
| 517 | #undef de_fault |
| 518 | } |
| 519 | |
| 520 | /* Go through the target stack from top to bottom, copying over zero entries in |
| 521 | current_target. In effect, we are doing class inheritance through the |
| 522 | pushed target vectors. */ |
| 523 | |
| 524 | static void |
| 525 | update_current_target (void) |
| 526 | { |
| 527 | struct target_stack_item *item; |
| 528 | struct target_ops *t; |
| 529 | |
| 530 | /* First, reset current_target */ |
| 531 | memset (¤t_target, 0, sizeof current_target); |
| 532 | |
| 533 | for (item = target_stack; item; item = item->next) |
| 534 | { |
| 535 | t = item->target_ops; |
| 536 | |
| 537 | #define INHERIT(FIELD, TARGET) \ |
| 538 | if (!current_target.FIELD) \ |
| 539 | current_target.FIELD = TARGET->FIELD |
| 540 | |
| 541 | INHERIT (to_shortname, t); |
| 542 | INHERIT (to_longname, t); |
| 543 | INHERIT (to_doc, t); |
| 544 | INHERIT (to_open, t); |
| 545 | INHERIT (to_close, t); |
| 546 | INHERIT (to_attach, t); |
| 547 | INHERIT (to_post_attach, t); |
| 548 | INHERIT (to_require_attach, t); |
| 549 | INHERIT (to_detach, t); |
| 550 | INHERIT (to_require_detach, t); |
| 551 | INHERIT (to_resume, t); |
| 552 | INHERIT (to_wait, t); |
| 553 | INHERIT (to_post_wait, t); |
| 554 | INHERIT (to_fetch_registers, t); |
| 555 | INHERIT (to_store_registers, t); |
| 556 | INHERIT (to_prepare_to_store, t); |
| 557 | INHERIT (to_xfer_memory, t); |
| 558 | INHERIT (to_files_info, t); |
| 559 | INHERIT (to_insert_breakpoint, t); |
| 560 | INHERIT (to_remove_breakpoint, t); |
| 561 | INHERIT (to_terminal_init, t); |
| 562 | INHERIT (to_terminal_inferior, t); |
| 563 | INHERIT (to_terminal_ours_for_output, t); |
| 564 | INHERIT (to_terminal_ours, t); |
| 565 | INHERIT (to_terminal_info, t); |
| 566 | INHERIT (to_kill, t); |
| 567 | INHERIT (to_load, t); |
| 568 | INHERIT (to_lookup_symbol, t); |
| 569 | INHERIT (to_create_inferior, t); |
| 570 | INHERIT (to_post_startup_inferior, t); |
| 571 | INHERIT (to_acknowledge_created_inferior, t); |
| 572 | INHERIT (to_clone_and_follow_inferior, t); |
| 573 | INHERIT (to_post_follow_inferior_by_clone, t); |
| 574 | INHERIT (to_insert_fork_catchpoint, t); |
| 575 | INHERIT (to_remove_fork_catchpoint, t); |
| 576 | INHERIT (to_insert_vfork_catchpoint, t); |
| 577 | INHERIT (to_remove_vfork_catchpoint, t); |
| 578 | INHERIT (to_has_forked, t); |
| 579 | INHERIT (to_has_vforked, t); |
| 580 | INHERIT (to_can_follow_vfork_prior_to_exec, t); |
| 581 | INHERIT (to_post_follow_vfork, t); |
| 582 | INHERIT (to_insert_exec_catchpoint, t); |
| 583 | INHERIT (to_remove_exec_catchpoint, t); |
| 584 | INHERIT (to_has_execd, t); |
| 585 | INHERIT (to_reported_exec_events_per_exec_call, t); |
| 586 | INHERIT (to_has_syscall_event, t); |
| 587 | INHERIT (to_has_exited, t); |
| 588 | INHERIT (to_mourn_inferior, t); |
| 589 | INHERIT (to_can_run, t); |
| 590 | INHERIT (to_notice_signals, t); |
| 591 | INHERIT (to_thread_alive, t); |
| 592 | INHERIT (to_find_new_threads, t); |
| 593 | INHERIT (to_pid_to_str, t); |
| 594 | INHERIT (to_extra_thread_info, t); |
| 595 | INHERIT (to_stop, t); |
| 596 | INHERIT (to_query, t); |
| 597 | INHERIT (to_rcmd, t); |
| 598 | INHERIT (to_enable_exception_callback, t); |
| 599 | INHERIT (to_get_current_exception_event, t); |
| 600 | INHERIT (to_pid_to_exec_file, t); |
| 601 | INHERIT (to_core_file_to_sym_file, t); |
| 602 | INHERIT (to_stratum, t); |
| 603 | INHERIT (DONT_USE, t); |
| 604 | INHERIT (to_has_all_memory, t); |
| 605 | INHERIT (to_has_memory, t); |
| 606 | INHERIT (to_has_stack, t); |
| 607 | INHERIT (to_has_registers, t); |
| 608 | INHERIT (to_has_execution, t); |
| 609 | INHERIT (to_has_thread_control, t); |
| 610 | INHERIT (to_sections, t); |
| 611 | INHERIT (to_sections_end, t); |
| 612 | INHERIT (to_can_async_p, t); |
| 613 | INHERIT (to_is_async_p, t); |
| 614 | INHERIT (to_async, t); |
| 615 | INHERIT (to_async_mask_value, t); |
| 616 | INHERIT (to_magic, t); |
| 617 | |
| 618 | #undef INHERIT |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | /* Push a new target type into the stack of the existing target accessors, |
| 623 | possibly superseding some of the existing accessors. |
| 624 | |
| 625 | Result is zero if the pushed target ended up on top of the stack, |
| 626 | nonzero if at least one target is on top of it. |
| 627 | |
| 628 | Rather than allow an empty stack, we always have the dummy target at |
| 629 | the bottom stratum, so we can call the function vectors without |
| 630 | checking them. */ |
| 631 | |
| 632 | int |
| 633 | push_target (struct target_ops *t) |
| 634 | { |
| 635 | struct target_stack_item *cur, *prev, *tmp; |
| 636 | |
| 637 | /* Check magic number. If wrong, it probably means someone changed |
| 638 | the struct definition, but not all the places that initialize one. */ |
| 639 | if (t->to_magic != OPS_MAGIC) |
| 640 | { |
| 641 | fprintf_unfiltered (gdb_stderr, |
| 642 | "Magic number of %s target struct wrong\n", |
| 643 | t->to_shortname); |
| 644 | abort (); |
| 645 | } |
| 646 | |
| 647 | /* Find the proper stratum to install this target in. */ |
| 648 | |
| 649 | for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next) |
| 650 | { |
| 651 | if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum)) |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | /* If there's already targets at this stratum, remove them. */ |
| 656 | |
| 657 | if (cur) |
| 658 | while (t->to_stratum == cur->target_ops->to_stratum) |
| 659 | { |
| 660 | /* There's already something on this stratum. Close it off. */ |
| 661 | if (cur->target_ops->to_close) |
| 662 | (cur->target_ops->to_close) (0); |
| 663 | if (prev) |
| 664 | prev->next = cur->next; /* Unchain old target_ops */ |
| 665 | else |
| 666 | target_stack = cur->next; /* Unchain first on list */ |
| 667 | tmp = cur->next; |
| 668 | xfree (cur); |
| 669 | cur = tmp; |
| 670 | } |
| 671 | |
| 672 | /* We have removed all targets in our stratum, now add the new one. */ |
| 673 | |
| 674 | tmp = (struct target_stack_item *) |
| 675 | xmalloc (sizeof (struct target_stack_item)); |
| 676 | tmp->next = cur; |
| 677 | tmp->target_ops = t; |
| 678 | |
| 679 | if (prev) |
| 680 | prev->next = tmp; |
| 681 | else |
| 682 | target_stack = tmp; |
| 683 | |
| 684 | update_current_target (); |
| 685 | |
| 686 | cleanup_target (¤t_target); /* Fill in the gaps */ |
| 687 | |
| 688 | if (targetdebug) |
| 689 | setup_target_debug (); |
| 690 | |
| 691 | return prev != 0; |
| 692 | } |
| 693 | |
| 694 | /* Remove a target_ops vector from the stack, wherever it may be. |
| 695 | Return how many times it was removed (0 or 1). */ |
| 696 | |
| 697 | int |
| 698 | unpush_target (struct target_ops *t) |
| 699 | { |
| 700 | struct target_stack_item *cur, *prev; |
| 701 | |
| 702 | if (t->to_close) |
| 703 | t->to_close (0); /* Let it clean up */ |
| 704 | |
| 705 | /* Look for the specified target. Note that we assume that a target |
| 706 | can only occur once in the target stack. */ |
| 707 | |
| 708 | for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next) |
| 709 | if (cur->target_ops == t) |
| 710 | break; |
| 711 | |
| 712 | if (!cur) |
| 713 | return 0; /* Didn't find target_ops, quit now */ |
| 714 | |
| 715 | /* Unchain the target */ |
| 716 | |
| 717 | if (!prev) |
| 718 | target_stack = cur->next; |
| 719 | else |
| 720 | prev->next = cur->next; |
| 721 | |
| 722 | xfree (cur); /* Release the target_stack_item */ |
| 723 | |
| 724 | update_current_target (); |
| 725 | cleanup_target (¤t_target); |
| 726 | |
| 727 | return 1; |
| 728 | } |
| 729 | |
| 730 | void |
| 731 | pop_target (void) |
| 732 | { |
| 733 | (current_target.to_close) (0); /* Let it clean up */ |
| 734 | if (unpush_target (target_stack->target_ops) == 1) |
| 735 | return; |
| 736 | |
| 737 | fprintf_unfiltered (gdb_stderr, |
| 738 | "pop_target couldn't find target %s\n", |
| 739 | current_target.to_shortname); |
| 740 | abort (); |
| 741 | } |
| 742 | |
| 743 | #undef MIN |
| 744 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) |
| 745 | |
| 746 | /* target_read_string -- read a null terminated string, up to LEN bytes, |
| 747 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. |
| 748 | Set *STRING to a pointer to malloc'd memory containing the data; the caller |
| 749 | is responsible for freeing it. Return the number of bytes successfully |
| 750 | read. */ |
| 751 | |
| 752 | int |
| 753 | target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) |
| 754 | { |
| 755 | int tlen, origlen, offset, i; |
| 756 | char buf[4]; |
| 757 | int errcode = 0; |
| 758 | char *buffer; |
| 759 | int buffer_allocated; |
| 760 | char *bufptr; |
| 761 | unsigned int nbytes_read = 0; |
| 762 | |
| 763 | /* Small for testing. */ |
| 764 | buffer_allocated = 4; |
| 765 | buffer = xmalloc (buffer_allocated); |
| 766 | bufptr = buffer; |
| 767 | |
| 768 | origlen = len; |
| 769 | |
| 770 | while (len > 0) |
| 771 | { |
| 772 | tlen = MIN (len, 4 - (memaddr & 3)); |
| 773 | offset = memaddr & 3; |
| 774 | |
| 775 | errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0); |
| 776 | if (errcode != 0) |
| 777 | { |
| 778 | /* The transfer request might have crossed the boundary to an |
| 779 | unallocated region of memory. Retry the transfer, requesting |
| 780 | a single byte. */ |
| 781 | tlen = 1; |
| 782 | offset = 0; |
| 783 | errcode = target_xfer_memory (memaddr, buf, 1, 0); |
| 784 | if (errcode != 0) |
| 785 | goto done; |
| 786 | } |
| 787 | |
| 788 | if (bufptr - buffer + tlen > buffer_allocated) |
| 789 | { |
| 790 | unsigned int bytes; |
| 791 | bytes = bufptr - buffer; |
| 792 | buffer_allocated *= 2; |
| 793 | buffer = xrealloc (buffer, buffer_allocated); |
| 794 | bufptr = buffer + bytes; |
| 795 | } |
| 796 | |
| 797 | for (i = 0; i < tlen; i++) |
| 798 | { |
| 799 | *bufptr++ = buf[i + offset]; |
| 800 | if (buf[i + offset] == '\000') |
| 801 | { |
| 802 | nbytes_read += i + 1; |
| 803 | goto done; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | memaddr += tlen; |
| 808 | len -= tlen; |
| 809 | nbytes_read += tlen; |
| 810 | } |
| 811 | done: |
| 812 | if (errnop != NULL) |
| 813 | *errnop = errcode; |
| 814 | if (string != NULL) |
| 815 | *string = buffer; |
| 816 | return nbytes_read; |
| 817 | } |
| 818 | |
| 819 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
| 820 | GDB's memory at MYADDR. Returns either 0 for success or an errno value |
| 821 | if any error occurs. |
| 822 | |
| 823 | If an error occurs, no guarantee is made about the contents of the data at |
| 824 | MYADDR. In particular, the caller should not depend upon partial reads |
| 825 | filling the buffer with good data. There is no way for the caller to know |
| 826 | how much good data might have been transfered anyway. Callers that can |
| 827 | deal with partial reads should call target_read_memory_partial. */ |
| 828 | |
| 829 | int |
| 830 | target_read_memory (CORE_ADDR memaddr, char *myaddr, int len) |
| 831 | { |
| 832 | return target_xfer_memory (memaddr, myaddr, len, 0); |
| 833 | } |
| 834 | |
| 835 | int |
| 836 | target_write_memory (CORE_ADDR memaddr, char *myaddr, int len) |
| 837 | { |
| 838 | return target_xfer_memory (memaddr, myaddr, len, 1); |
| 839 | } |
| 840 | |
| 841 | /* Move memory to or from the targets. The top target gets priority; |
| 842 | if it cannot handle it, it is offered to the next one down, etc. |
| 843 | |
| 844 | Result is -1 on error, or the number of bytes transfered. */ |
| 845 | |
| 846 | int |
| 847 | do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
| 848 | struct mem_attrib *attrib) |
| 849 | { |
| 850 | int res; |
| 851 | int done = 0; |
| 852 | struct target_ops *t; |
| 853 | struct target_stack_item *item; |
| 854 | |
| 855 | /* Zero length requests are ok and require no work. */ |
| 856 | if (len == 0) |
| 857 | return 0; |
| 858 | |
| 859 | /* to_xfer_memory is not guaranteed to set errno, even when it returns |
| 860 | 0. */ |
| 861 | errno = 0; |
| 862 | |
| 863 | /* The quick case is that the top target can handle the transfer. */ |
| 864 | res = current_target.to_xfer_memory |
| 865 | (memaddr, myaddr, len, write, attrib, ¤t_target); |
| 866 | |
| 867 | /* If res <= 0 then we call it again in the loop. Ah well. */ |
| 868 | if (res <= 0) |
| 869 | { |
| 870 | for (item = target_stack; item; item = item->next) |
| 871 | { |
| 872 | t = item->target_ops; |
| 873 | if (!t->to_has_memory) |
| 874 | continue; |
| 875 | |
| 876 | res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t); |
| 877 | if (res > 0) |
| 878 | break; /* Handled all or part of xfer */ |
| 879 | if (t->to_has_all_memory) |
| 880 | break; |
| 881 | } |
| 882 | |
| 883 | if (res <= 0) |
| 884 | return -1; |
| 885 | } |
| 886 | |
| 887 | return res; |
| 888 | } |
| 889 | |
| 890 | |
| 891 | /* Perform a memory transfer. Iterate until the entire region has |
| 892 | been transfered. |
| 893 | |
| 894 | Result is 0 or errno value. */ |
| 895 | |
| 896 | static int |
| 897 | target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write) |
| 898 | { |
| 899 | int res; |
| 900 | int reg_len; |
| 901 | struct mem_region *region; |
| 902 | |
| 903 | /* Zero length requests are ok and require no work. */ |
| 904 | if (len == 0) |
| 905 | { |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | while (len > 0) |
| 910 | { |
| 911 | region = lookup_mem_region(memaddr); |
| 912 | if (memaddr + len < region->hi) |
| 913 | reg_len = len; |
| 914 | else |
| 915 | reg_len = region->hi - memaddr; |
| 916 | |
| 917 | switch (region->attrib.mode) |
| 918 | { |
| 919 | case MEM_RO: |
| 920 | if (write) |
| 921 | return EIO; |
| 922 | break; |
| 923 | |
| 924 | case MEM_WO: |
| 925 | if (!write) |
| 926 | return EIO; |
| 927 | break; |
| 928 | } |
| 929 | |
| 930 | while (reg_len > 0) |
| 931 | { |
| 932 | if (region->attrib.cache) |
| 933 | res = dcache_xfer_memory(target_dcache, memaddr, myaddr, |
| 934 | reg_len, write); |
| 935 | else |
| 936 | res = do_xfer_memory(memaddr, myaddr, reg_len, write, |
| 937 | ®ion->attrib); |
| 938 | |
| 939 | if (res <= 0) |
| 940 | { |
| 941 | /* If this address is for nonexistent memory, read zeros |
| 942 | if reading, or do nothing if writing. Return |
| 943 | error. */ |
| 944 | if (!write) |
| 945 | memset (myaddr, 0, len); |
| 946 | if (errno == 0) |
| 947 | return EIO; |
| 948 | else |
| 949 | return errno; |
| 950 | } |
| 951 | |
| 952 | memaddr += res; |
| 953 | myaddr += res; |
| 954 | len -= res; |
| 955 | reg_len -= res; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | return 0; /* We managed to cover it all somehow. */ |
| 960 | } |
| 961 | |
| 962 | |
| 963 | /* Perform a partial memory transfer. |
| 964 | |
| 965 | Result is -1 on error, or the number of bytes transfered. */ |
| 966 | |
| 967 | static int |
| 968 | target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len, |
| 969 | int write_p, int *err) |
| 970 | { |
| 971 | int res; |
| 972 | int reg_len; |
| 973 | struct mem_region *region; |
| 974 | |
| 975 | /* Zero length requests are ok and require no work. */ |
| 976 | if (len == 0) |
| 977 | { |
| 978 | *err = 0; |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | region = lookup_mem_region(memaddr); |
| 983 | if (memaddr + len < region->hi) |
| 984 | reg_len = len; |
| 985 | else |
| 986 | reg_len = region->hi - memaddr; |
| 987 | |
| 988 | switch (region->attrib.mode) |
| 989 | { |
| 990 | case MEM_RO: |
| 991 | if (write_p) |
| 992 | { |
| 993 | *err = EIO; |
| 994 | return 0; |
| 995 | } |
| 996 | break; |
| 997 | |
| 998 | case MEM_WO: |
| 999 | if (write_p) |
| 1000 | { |
| 1001 | *err = EIO; |
| 1002 | return 0; |
| 1003 | } |
| 1004 | break; |
| 1005 | } |
| 1006 | |
| 1007 | if (region->attrib.cache) |
| 1008 | res = dcache_xfer_memory (target_dcache, memaddr, myaddr, |
| 1009 | reg_len, write_p); |
| 1010 | else |
| 1011 | res = do_xfer_memory (memaddr, myaddr, reg_len, write_p, |
| 1012 | ®ion->attrib); |
| 1013 | |
| 1014 | if (res <= 0) |
| 1015 | { |
| 1016 | if (errno != 0) |
| 1017 | *err = errno; |
| 1018 | else |
| 1019 | *err = EIO; |
| 1020 | |
| 1021 | return -1; |
| 1022 | } |
| 1023 | |
| 1024 | *err = 0; |
| 1025 | return res; |
| 1026 | } |
| 1027 | |
| 1028 | int |
| 1029 | target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) |
| 1030 | { |
| 1031 | return target_xfer_memory_partial (memaddr, buf, len, 0, err); |
| 1032 | } |
| 1033 | |
| 1034 | int |
| 1035 | target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) |
| 1036 | { |
| 1037 | return target_xfer_memory_partial (memaddr, buf, len, 1, err); |
| 1038 | } |
| 1039 | |
| 1040 | /* ARGSUSED */ |
| 1041 | static void |
| 1042 | target_info (char *args, int from_tty) |
| 1043 | { |
| 1044 | struct target_ops *t; |
| 1045 | struct target_stack_item *item; |
| 1046 | int has_all_mem = 0; |
| 1047 | |
| 1048 | if (symfile_objfile != NULL) |
| 1049 | printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name); |
| 1050 | |
| 1051 | #ifdef FILES_INFO_HOOK |
| 1052 | if (FILES_INFO_HOOK ()) |
| 1053 | return; |
| 1054 | #endif |
| 1055 | |
| 1056 | for (item = target_stack; item; item = item->next) |
| 1057 | { |
| 1058 | t = item->target_ops; |
| 1059 | |
| 1060 | if (!t->to_has_memory) |
| 1061 | continue; |
| 1062 | |
| 1063 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
| 1064 | continue; |
| 1065 | if (has_all_mem) |
| 1066 | printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n"); |
| 1067 | printf_unfiltered ("%s:\n", t->to_longname); |
| 1068 | (t->to_files_info) (t); |
| 1069 | has_all_mem = t->to_has_all_memory; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | /* This is to be called by the open routine before it does |
| 1074 | anything. */ |
| 1075 | |
| 1076 | void |
| 1077 | target_preopen (int from_tty) |
| 1078 | { |
| 1079 | dont_repeat (); |
| 1080 | |
| 1081 | if (target_has_execution) |
| 1082 | { |
| 1083 | if (!from_tty |
| 1084 | || query ("A program is being debugged already. Kill it? ")) |
| 1085 | target_kill (); |
| 1086 | else |
| 1087 | error ("Program not killed."); |
| 1088 | } |
| 1089 | |
| 1090 | /* Calling target_kill may remove the target from the stack. But if |
| 1091 | it doesn't (which seems like a win for UDI), remove it now. */ |
| 1092 | |
| 1093 | if (target_has_execution) |
| 1094 | pop_target (); |
| 1095 | } |
| 1096 | |
| 1097 | /* Detach a target after doing deferred register stores. */ |
| 1098 | |
| 1099 | void |
| 1100 | target_detach (char *args, int from_tty) |
| 1101 | { |
| 1102 | /* Handle any optimized stores to the inferior. */ |
| 1103 | #ifdef DO_DEFERRED_STORES |
| 1104 | DO_DEFERRED_STORES; |
| 1105 | #endif |
| 1106 | (current_target.to_detach) (args, from_tty); |
| 1107 | } |
| 1108 | |
| 1109 | void |
| 1110 | target_link (char *modname, CORE_ADDR *t_reloc) |
| 1111 | { |
| 1112 | if (STREQ (current_target.to_shortname, "rombug")) |
| 1113 | { |
| 1114 | (current_target.to_lookup_symbol) (modname, t_reloc); |
| 1115 | if (*t_reloc == 0) |
| 1116 | error ("Unable to link to %s and get relocation in rombug", modname); |
| 1117 | } |
| 1118 | else |
| 1119 | *t_reloc = (CORE_ADDR) -1; |
| 1120 | } |
| 1121 | |
| 1122 | int |
| 1123 | target_async_mask (int mask) |
| 1124 | { |
| 1125 | int saved_async_masked_status = target_async_mask_value; |
| 1126 | target_async_mask_value = mask; |
| 1127 | return saved_async_masked_status; |
| 1128 | } |
| 1129 | |
| 1130 | /* Look through the list of possible targets for a target that can |
| 1131 | execute a run or attach command without any other data. This is |
| 1132 | used to locate the default process stratum. |
| 1133 | |
| 1134 | Result is always valid (error() is called for errors). */ |
| 1135 | |
| 1136 | static struct target_ops * |
| 1137 | find_default_run_target (char *do_mesg) |
| 1138 | { |
| 1139 | struct target_ops **t; |
| 1140 | struct target_ops *runable = NULL; |
| 1141 | int count; |
| 1142 | |
| 1143 | count = 0; |
| 1144 | |
| 1145 | for (t = target_structs; t < target_structs + target_struct_size; |
| 1146 | ++t) |
| 1147 | { |
| 1148 | if ((*t)->to_can_run && target_can_run (*t)) |
| 1149 | { |
| 1150 | runable = *t; |
| 1151 | ++count; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (count != 1) |
| 1156 | error ("Don't know how to %s. Try \"help target\".", do_mesg); |
| 1157 | |
| 1158 | return runable; |
| 1159 | } |
| 1160 | |
| 1161 | void |
| 1162 | find_default_attach (char *args, int from_tty) |
| 1163 | { |
| 1164 | struct target_ops *t; |
| 1165 | |
| 1166 | t = find_default_run_target ("attach"); |
| 1167 | (t->to_attach) (args, from_tty); |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | void |
| 1172 | find_default_require_attach (char *args, int from_tty) |
| 1173 | { |
| 1174 | struct target_ops *t; |
| 1175 | |
| 1176 | t = find_default_run_target ("require_attach"); |
| 1177 | (t->to_require_attach) (args, from_tty); |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | void |
| 1182 | find_default_require_detach (int pid, char *args, int from_tty) |
| 1183 | { |
| 1184 | struct target_ops *t; |
| 1185 | |
| 1186 | t = find_default_run_target ("require_detach"); |
| 1187 | (t->to_require_detach) (pid, args, from_tty); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
| 1191 | void |
| 1192 | find_default_create_inferior (char *exec_file, char *allargs, char **env) |
| 1193 | { |
| 1194 | struct target_ops *t; |
| 1195 | |
| 1196 | t = find_default_run_target ("run"); |
| 1197 | (t->to_create_inferior) (exec_file, allargs, env); |
| 1198 | return; |
| 1199 | } |
| 1200 | |
| 1201 | void |
| 1202 | find_default_clone_and_follow_inferior (int child_pid, int *followed_child) |
| 1203 | { |
| 1204 | struct target_ops *t; |
| 1205 | |
| 1206 | t = find_default_run_target ("run"); |
| 1207 | (t->to_clone_and_follow_inferior) (child_pid, followed_child); |
| 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | static int |
| 1212 | return_zero (void) |
| 1213 | { |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | static int |
| 1218 | return_one (void) |
| 1219 | { |
| 1220 | return 1; |
| 1221 | } |
| 1222 | |
| 1223 | /* |
| 1224 | * Resize the to_sections pointer. Also make sure that anyone that |
| 1225 | * was holding on to an old value of it gets updated. |
| 1226 | * Returns the old size. |
| 1227 | */ |
| 1228 | |
| 1229 | int |
| 1230 | target_resize_to_sections (struct target_ops *target, int num_added) |
| 1231 | { |
| 1232 | struct target_ops **t; |
| 1233 | struct section_table *old_value; |
| 1234 | int old_count; |
| 1235 | |
| 1236 | old_value = target->to_sections; |
| 1237 | |
| 1238 | if (target->to_sections) |
| 1239 | { |
| 1240 | old_count = target->to_sections_end - target->to_sections; |
| 1241 | target->to_sections = (struct section_table *) |
| 1242 | xrealloc ((char *) target->to_sections, |
| 1243 | (sizeof (struct section_table)) * (num_added + old_count)); |
| 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | old_count = 0; |
| 1248 | target->to_sections = (struct section_table *) |
| 1249 | xmalloc ((sizeof (struct section_table)) * num_added); |
| 1250 | } |
| 1251 | target->to_sections_end = target->to_sections + (num_added + old_count); |
| 1252 | |
| 1253 | /* Check to see if anyone else was pointing to this structure. |
| 1254 | If old_value was null, then no one was. */ |
| 1255 | |
| 1256 | if (old_value) |
| 1257 | { |
| 1258 | for (t = target_structs; t < target_structs + target_struct_size; |
| 1259 | ++t) |
| 1260 | { |
| 1261 | if ((*t)->to_sections == old_value) |
| 1262 | { |
| 1263 | (*t)->to_sections = target->to_sections; |
| 1264 | (*t)->to_sections_end = target->to_sections_end; |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | return old_count; |
| 1270 | |
| 1271 | } |
| 1272 | |
| 1273 | /* Remove all target sections taken from ABFD. |
| 1274 | |
| 1275 | Scan the current target stack for targets whose section tables |
| 1276 | refer to sections from BFD, and remove those sections. We use this |
| 1277 | when we notice that the inferior has unloaded a shared object, for |
| 1278 | example. */ |
| 1279 | void |
| 1280 | remove_target_sections (bfd *abfd) |
| 1281 | { |
| 1282 | struct target_ops **t; |
| 1283 | |
| 1284 | for (t = target_structs; t < target_structs + target_struct_size; t++) |
| 1285 | { |
| 1286 | struct section_table *src, *dest; |
| 1287 | |
| 1288 | dest = (*t)->to_sections; |
| 1289 | for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++) |
| 1290 | if (src->bfd != abfd) |
| 1291 | { |
| 1292 | /* Keep this section. */ |
| 1293 | if (dest < src) *dest = *src; |
| 1294 | dest++; |
| 1295 | } |
| 1296 | |
| 1297 | /* If we've dropped any sections, resize the section table. */ |
| 1298 | if (dest < src) |
| 1299 | target_resize_to_sections (*t, dest - src); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | /* Find a single runnable target in the stack and return it. If for |
| 1307 | some reason there is more than one, return NULL. */ |
| 1308 | |
| 1309 | struct target_ops * |
| 1310 | find_run_target (void) |
| 1311 | { |
| 1312 | struct target_ops **t; |
| 1313 | struct target_ops *runable = NULL; |
| 1314 | int count; |
| 1315 | |
| 1316 | count = 0; |
| 1317 | |
| 1318 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
| 1319 | { |
| 1320 | if ((*t)->to_can_run && target_can_run (*t)) |
| 1321 | { |
| 1322 | runable = *t; |
| 1323 | ++count; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | return (count == 1 ? runable : NULL); |
| 1328 | } |
| 1329 | |
| 1330 | /* Find a single core_stratum target in the list of targets and return it. |
| 1331 | If for some reason there is more than one, return NULL. */ |
| 1332 | |
| 1333 | struct target_ops * |
| 1334 | find_core_target (void) |
| 1335 | { |
| 1336 | struct target_ops **t; |
| 1337 | struct target_ops *runable = NULL; |
| 1338 | int count; |
| 1339 | |
| 1340 | count = 0; |
| 1341 | |
| 1342 | for (t = target_structs; t < target_structs + target_struct_size; |
| 1343 | ++t) |
| 1344 | { |
| 1345 | if ((*t)->to_stratum == core_stratum) |
| 1346 | { |
| 1347 | runable = *t; |
| 1348 | ++count; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | return (count == 1 ? runable : NULL); |
| 1353 | } |
| 1354 | |
| 1355 | /* |
| 1356 | * Find the next target down the stack from the specified target. |
| 1357 | */ |
| 1358 | |
| 1359 | struct target_ops * |
| 1360 | find_target_beneath (struct target_ops *t) |
| 1361 | { |
| 1362 | struct target_stack_item *cur; |
| 1363 | |
| 1364 | for (cur = target_stack; cur; cur = cur->next) |
| 1365 | if (cur->target_ops == t) |
| 1366 | break; |
| 1367 | |
| 1368 | if (cur == NULL || cur->next == NULL) |
| 1369 | return NULL; |
| 1370 | else |
| 1371 | return cur->next->target_ops; |
| 1372 | } |
| 1373 | |
| 1374 | \f |
| 1375 | /* The inferior process has died. Long live the inferior! */ |
| 1376 | |
| 1377 | void |
| 1378 | generic_mourn_inferior (void) |
| 1379 | { |
| 1380 | extern int show_breakpoint_hit_counts; |
| 1381 | |
| 1382 | inferior_pid = 0; |
| 1383 | attach_flag = 0; |
| 1384 | breakpoint_init_inferior (inf_exited); |
| 1385 | registers_changed (); |
| 1386 | |
| 1387 | #ifdef CLEAR_DEFERRED_STORES |
| 1388 | /* Delete any pending stores to the inferior... */ |
| 1389 | CLEAR_DEFERRED_STORES; |
| 1390 | #endif |
| 1391 | |
| 1392 | reopen_exec_file (); |
| 1393 | reinit_frame_cache (); |
| 1394 | |
| 1395 | /* It is confusing to the user for ignore counts to stick around |
| 1396 | from previous runs of the inferior. So clear them. */ |
| 1397 | /* However, it is more confusing for the ignore counts to disappear when |
| 1398 | using hit counts. So don't clear them if we're counting hits. */ |
| 1399 | if (!show_breakpoint_hit_counts) |
| 1400 | breakpoint_clear_ignore_counts (); |
| 1401 | |
| 1402 | if (detach_hook) |
| 1403 | detach_hook (); |
| 1404 | } |
| 1405 | \f |
| 1406 | /* This table must match in order and size the signals in enum target_signal |
| 1407 | in target.h. */ |
| 1408 | /* *INDENT-OFF* */ |
| 1409 | static struct { |
| 1410 | char *name; |
| 1411 | char *string; |
| 1412 | } signals [] = |
| 1413 | { |
| 1414 | {"0", "Signal 0"}, |
| 1415 | {"SIGHUP", "Hangup"}, |
| 1416 | {"SIGINT", "Interrupt"}, |
| 1417 | {"SIGQUIT", "Quit"}, |
| 1418 | {"SIGILL", "Illegal instruction"}, |
| 1419 | {"SIGTRAP", "Trace/breakpoint trap"}, |
| 1420 | {"SIGABRT", "Aborted"}, |
| 1421 | {"SIGEMT", "Emulation trap"}, |
| 1422 | {"SIGFPE", "Arithmetic exception"}, |
| 1423 | {"SIGKILL", "Killed"}, |
| 1424 | {"SIGBUS", "Bus error"}, |
| 1425 | {"SIGSEGV", "Segmentation fault"}, |
| 1426 | {"SIGSYS", "Bad system call"}, |
| 1427 | {"SIGPIPE", "Broken pipe"}, |
| 1428 | {"SIGALRM", "Alarm clock"}, |
| 1429 | {"SIGTERM", "Terminated"}, |
| 1430 | {"SIGURG", "Urgent I/O condition"}, |
| 1431 | {"SIGSTOP", "Stopped (signal)"}, |
| 1432 | {"SIGTSTP", "Stopped (user)"}, |
| 1433 | {"SIGCONT", "Continued"}, |
| 1434 | {"SIGCHLD", "Child status changed"}, |
| 1435 | {"SIGTTIN", "Stopped (tty input)"}, |
| 1436 | {"SIGTTOU", "Stopped (tty output)"}, |
| 1437 | {"SIGIO", "I/O possible"}, |
| 1438 | {"SIGXCPU", "CPU time limit exceeded"}, |
| 1439 | {"SIGXFSZ", "File size limit exceeded"}, |
| 1440 | {"SIGVTALRM", "Virtual timer expired"}, |
| 1441 | {"SIGPROF", "Profiling timer expired"}, |
| 1442 | {"SIGWINCH", "Window size changed"}, |
| 1443 | {"SIGLOST", "Resource lost"}, |
| 1444 | {"SIGUSR1", "User defined signal 1"}, |
| 1445 | {"SIGUSR2", "User defined signal 2"}, |
| 1446 | {"SIGPWR", "Power fail/restart"}, |
| 1447 | {"SIGPOLL", "Pollable event occurred"}, |
| 1448 | {"SIGWIND", "SIGWIND"}, |
| 1449 | {"SIGPHONE", "SIGPHONE"}, |
| 1450 | {"SIGWAITING", "Process's LWPs are blocked"}, |
| 1451 | {"SIGLWP", "Signal LWP"}, |
| 1452 | {"SIGDANGER", "Swap space dangerously low"}, |
| 1453 | {"SIGGRANT", "Monitor mode granted"}, |
| 1454 | {"SIGRETRACT", "Need to relinquish monitor mode"}, |
| 1455 | {"SIGMSG", "Monitor mode data available"}, |
| 1456 | {"SIGSOUND", "Sound completed"}, |
| 1457 | {"SIGSAK", "Secure attention"}, |
| 1458 | {"SIGPRIO", "SIGPRIO"}, |
| 1459 | {"SIG33", "Real-time event 33"}, |
| 1460 | {"SIG34", "Real-time event 34"}, |
| 1461 | {"SIG35", "Real-time event 35"}, |
| 1462 | {"SIG36", "Real-time event 36"}, |
| 1463 | {"SIG37", "Real-time event 37"}, |
| 1464 | {"SIG38", "Real-time event 38"}, |
| 1465 | {"SIG39", "Real-time event 39"}, |
| 1466 | {"SIG40", "Real-time event 40"}, |
| 1467 | {"SIG41", "Real-time event 41"}, |
| 1468 | {"SIG42", "Real-time event 42"}, |
| 1469 | {"SIG43", "Real-time event 43"}, |
| 1470 | {"SIG44", "Real-time event 44"}, |
| 1471 | {"SIG45", "Real-time event 45"}, |
| 1472 | {"SIG46", "Real-time event 46"}, |
| 1473 | {"SIG47", "Real-time event 47"}, |
| 1474 | {"SIG48", "Real-time event 48"}, |
| 1475 | {"SIG49", "Real-time event 49"}, |
| 1476 | {"SIG50", "Real-time event 50"}, |
| 1477 | {"SIG51", "Real-time event 51"}, |
| 1478 | {"SIG52", "Real-time event 52"}, |
| 1479 | {"SIG53", "Real-time event 53"}, |
| 1480 | {"SIG54", "Real-time event 54"}, |
| 1481 | {"SIG55", "Real-time event 55"}, |
| 1482 | {"SIG56", "Real-time event 56"}, |
| 1483 | {"SIG57", "Real-time event 57"}, |
| 1484 | {"SIG58", "Real-time event 58"}, |
| 1485 | {"SIG59", "Real-time event 59"}, |
| 1486 | {"SIG60", "Real-time event 60"}, |
| 1487 | {"SIG61", "Real-time event 61"}, |
| 1488 | {"SIG62", "Real-time event 62"}, |
| 1489 | {"SIG63", "Real-time event 63"}, |
| 1490 | {"SIGCANCEL", "LWP internal signal"}, |
| 1491 | {"SIG32", "Real-time event 32"}, |
| 1492 | {"SIG64", "Real-time event 64"}, |
| 1493 | |
| 1494 | #if defined(MACH) || defined(__MACH__) |
| 1495 | /* Mach exceptions */ |
| 1496 | {"EXC_BAD_ACCESS", "Could not access memory"}, |
| 1497 | {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"}, |
| 1498 | {"EXC_ARITHMETIC", "Arithmetic exception"}, |
| 1499 | {"EXC_EMULATION", "Emulation instruction"}, |
| 1500 | {"EXC_SOFTWARE", "Software generated exception"}, |
| 1501 | {"EXC_BREAKPOINT", "Breakpoint"}, |
| 1502 | #endif |
| 1503 | {"SIGINFO", "Information request"}, |
| 1504 | |
| 1505 | {NULL, "Unknown signal"}, |
| 1506 | {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"}, |
| 1507 | |
| 1508 | /* Last entry, used to check whether the table is the right size. */ |
| 1509 | {NULL, "TARGET_SIGNAL_MAGIC"} |
| 1510 | }; |
| 1511 | /* *INDENT-ON* */ |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | /* Return the string for a signal. */ |
| 1516 | char * |
| 1517 | target_signal_to_string (enum target_signal sig) |
| 1518 | { |
| 1519 | if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) |
| 1520 | return signals[sig].string; |
| 1521 | else |
| 1522 | return signals[TARGET_SIGNAL_UNKNOWN].string; |
| 1523 | } |
| 1524 | |
| 1525 | /* Return the name for a signal. */ |
| 1526 | char * |
| 1527 | target_signal_to_name (enum target_signal sig) |
| 1528 | { |
| 1529 | if (sig == TARGET_SIGNAL_UNKNOWN) |
| 1530 | /* I think the code which prints this will always print it along with |
| 1531 | the string, so no need to be verbose. */ |
| 1532 | return "?"; |
| 1533 | return signals[sig].name; |
| 1534 | } |
| 1535 | |
| 1536 | /* Given a name, return its signal. */ |
| 1537 | enum target_signal |
| 1538 | target_signal_from_name (char *name) |
| 1539 | { |
| 1540 | enum target_signal sig; |
| 1541 | |
| 1542 | /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" |
| 1543 | for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more |
| 1544 | questionable; seems like by now people should call it SIGABRT |
| 1545 | instead. */ |
| 1546 | |
| 1547 | /* This ugly cast brought to you by the native VAX compiler. */ |
| 1548 | for (sig = TARGET_SIGNAL_HUP; |
| 1549 | signals[sig].name != NULL; |
| 1550 | sig = (enum target_signal) ((int) sig + 1)) |
| 1551 | if (STREQ (name, signals[sig].name)) |
| 1552 | return sig; |
| 1553 | return TARGET_SIGNAL_UNKNOWN; |
| 1554 | } |
| 1555 | \f |
| 1556 | /* The following functions are to help certain targets deal |
| 1557 | with the signal/waitstatus stuff. They could just as well be in |
| 1558 | a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ |
| 1559 | |
| 1560 | /* Convert host signal to our signals. */ |
| 1561 | enum target_signal |
| 1562 | target_signal_from_host (int hostsig) |
| 1563 | { |
| 1564 | /* A switch statement would make sense but would require special kludges |
| 1565 | to deal with the cases where more than one signal has the same number. */ |
| 1566 | |
| 1567 | if (hostsig == 0) |
| 1568 | return TARGET_SIGNAL_0; |
| 1569 | |
| 1570 | #if defined (SIGHUP) |
| 1571 | if (hostsig == SIGHUP) |
| 1572 | return TARGET_SIGNAL_HUP; |
| 1573 | #endif |
| 1574 | #if defined (SIGINT) |
| 1575 | if (hostsig == SIGINT) |
| 1576 | return TARGET_SIGNAL_INT; |
| 1577 | #endif |
| 1578 | #if defined (SIGQUIT) |
| 1579 | if (hostsig == SIGQUIT) |
| 1580 | return TARGET_SIGNAL_QUIT; |
| 1581 | #endif |
| 1582 | #if defined (SIGILL) |
| 1583 | if (hostsig == SIGILL) |
| 1584 | return TARGET_SIGNAL_ILL; |
| 1585 | #endif |
| 1586 | #if defined (SIGTRAP) |
| 1587 | if (hostsig == SIGTRAP) |
| 1588 | return TARGET_SIGNAL_TRAP; |
| 1589 | #endif |
| 1590 | #if defined (SIGABRT) |
| 1591 | if (hostsig == SIGABRT) |
| 1592 | return TARGET_SIGNAL_ABRT; |
| 1593 | #endif |
| 1594 | #if defined (SIGEMT) |
| 1595 | if (hostsig == SIGEMT) |
| 1596 | return TARGET_SIGNAL_EMT; |
| 1597 | #endif |
| 1598 | #if defined (SIGFPE) |
| 1599 | if (hostsig == SIGFPE) |
| 1600 | return TARGET_SIGNAL_FPE; |
| 1601 | #endif |
| 1602 | #if defined (SIGKILL) |
| 1603 | if (hostsig == SIGKILL) |
| 1604 | return TARGET_SIGNAL_KILL; |
| 1605 | #endif |
| 1606 | #if defined (SIGBUS) |
| 1607 | if (hostsig == SIGBUS) |
| 1608 | return TARGET_SIGNAL_BUS; |
| 1609 | #endif |
| 1610 | #if defined (SIGSEGV) |
| 1611 | if (hostsig == SIGSEGV) |
| 1612 | return TARGET_SIGNAL_SEGV; |
| 1613 | #endif |
| 1614 | #if defined (SIGSYS) |
| 1615 | if (hostsig == SIGSYS) |
| 1616 | return TARGET_SIGNAL_SYS; |
| 1617 | #endif |
| 1618 | #if defined (SIGPIPE) |
| 1619 | if (hostsig == SIGPIPE) |
| 1620 | return TARGET_SIGNAL_PIPE; |
| 1621 | #endif |
| 1622 | #if defined (SIGALRM) |
| 1623 | if (hostsig == SIGALRM) |
| 1624 | return TARGET_SIGNAL_ALRM; |
| 1625 | #endif |
| 1626 | #if defined (SIGTERM) |
| 1627 | if (hostsig == SIGTERM) |
| 1628 | return TARGET_SIGNAL_TERM; |
| 1629 | #endif |
| 1630 | #if defined (SIGUSR1) |
| 1631 | if (hostsig == SIGUSR1) |
| 1632 | return TARGET_SIGNAL_USR1; |
| 1633 | #endif |
| 1634 | #if defined (SIGUSR2) |
| 1635 | if (hostsig == SIGUSR2) |
| 1636 | return TARGET_SIGNAL_USR2; |
| 1637 | #endif |
| 1638 | #if defined (SIGCLD) |
| 1639 | if (hostsig == SIGCLD) |
| 1640 | return TARGET_SIGNAL_CHLD; |
| 1641 | #endif |
| 1642 | #if defined (SIGCHLD) |
| 1643 | if (hostsig == SIGCHLD) |
| 1644 | return TARGET_SIGNAL_CHLD; |
| 1645 | #endif |
| 1646 | #if defined (SIGPWR) |
| 1647 | if (hostsig == SIGPWR) |
| 1648 | return TARGET_SIGNAL_PWR; |
| 1649 | #endif |
| 1650 | #if defined (SIGWINCH) |
| 1651 | if (hostsig == SIGWINCH) |
| 1652 | return TARGET_SIGNAL_WINCH; |
| 1653 | #endif |
| 1654 | #if defined (SIGURG) |
| 1655 | if (hostsig == SIGURG) |
| 1656 | return TARGET_SIGNAL_URG; |
| 1657 | #endif |
| 1658 | #if defined (SIGIO) |
| 1659 | if (hostsig == SIGIO) |
| 1660 | return TARGET_SIGNAL_IO; |
| 1661 | #endif |
| 1662 | #if defined (SIGPOLL) |
| 1663 | if (hostsig == SIGPOLL) |
| 1664 | return TARGET_SIGNAL_POLL; |
| 1665 | #endif |
| 1666 | #if defined (SIGSTOP) |
| 1667 | if (hostsig == SIGSTOP) |
| 1668 | return TARGET_SIGNAL_STOP; |
| 1669 | #endif |
| 1670 | #if defined (SIGTSTP) |
| 1671 | if (hostsig == SIGTSTP) |
| 1672 | return TARGET_SIGNAL_TSTP; |
| 1673 | #endif |
| 1674 | #if defined (SIGCONT) |
| 1675 | if (hostsig == SIGCONT) |
| 1676 | return TARGET_SIGNAL_CONT; |
| 1677 | #endif |
| 1678 | #if defined (SIGTTIN) |
| 1679 | if (hostsig == SIGTTIN) |
| 1680 | return TARGET_SIGNAL_TTIN; |
| 1681 | #endif |
| 1682 | #if defined (SIGTTOU) |
| 1683 | if (hostsig == SIGTTOU) |
| 1684 | return TARGET_SIGNAL_TTOU; |
| 1685 | #endif |
| 1686 | #if defined (SIGVTALRM) |
| 1687 | if (hostsig == SIGVTALRM) |
| 1688 | return TARGET_SIGNAL_VTALRM; |
| 1689 | #endif |
| 1690 | #if defined (SIGPROF) |
| 1691 | if (hostsig == SIGPROF) |
| 1692 | return TARGET_SIGNAL_PROF; |
| 1693 | #endif |
| 1694 | #if defined (SIGXCPU) |
| 1695 | if (hostsig == SIGXCPU) |
| 1696 | return TARGET_SIGNAL_XCPU; |
| 1697 | #endif |
| 1698 | #if defined (SIGXFSZ) |
| 1699 | if (hostsig == SIGXFSZ) |
| 1700 | return TARGET_SIGNAL_XFSZ; |
| 1701 | #endif |
| 1702 | #if defined (SIGWIND) |
| 1703 | if (hostsig == SIGWIND) |
| 1704 | return TARGET_SIGNAL_WIND; |
| 1705 | #endif |
| 1706 | #if defined (SIGPHONE) |
| 1707 | if (hostsig == SIGPHONE) |
| 1708 | return TARGET_SIGNAL_PHONE; |
| 1709 | #endif |
| 1710 | #if defined (SIGLOST) |
| 1711 | if (hostsig == SIGLOST) |
| 1712 | return TARGET_SIGNAL_LOST; |
| 1713 | #endif |
| 1714 | #if defined (SIGWAITING) |
| 1715 | if (hostsig == SIGWAITING) |
| 1716 | return TARGET_SIGNAL_WAITING; |
| 1717 | #endif |
| 1718 | #if defined (SIGCANCEL) |
| 1719 | if (hostsig == SIGCANCEL) |
| 1720 | return TARGET_SIGNAL_CANCEL; |
| 1721 | #endif |
| 1722 | #if defined (SIGLWP) |
| 1723 | if (hostsig == SIGLWP) |
| 1724 | return TARGET_SIGNAL_LWP; |
| 1725 | #endif |
| 1726 | #if defined (SIGDANGER) |
| 1727 | if (hostsig == SIGDANGER) |
| 1728 | return TARGET_SIGNAL_DANGER; |
| 1729 | #endif |
| 1730 | #if defined (SIGGRANT) |
| 1731 | if (hostsig == SIGGRANT) |
| 1732 | return TARGET_SIGNAL_GRANT; |
| 1733 | #endif |
| 1734 | #if defined (SIGRETRACT) |
| 1735 | if (hostsig == SIGRETRACT) |
| 1736 | return TARGET_SIGNAL_RETRACT; |
| 1737 | #endif |
| 1738 | #if defined (SIGMSG) |
| 1739 | if (hostsig == SIGMSG) |
| 1740 | return TARGET_SIGNAL_MSG; |
| 1741 | #endif |
| 1742 | #if defined (SIGSOUND) |
| 1743 | if (hostsig == SIGSOUND) |
| 1744 | return TARGET_SIGNAL_SOUND; |
| 1745 | #endif |
| 1746 | #if defined (SIGSAK) |
| 1747 | if (hostsig == SIGSAK) |
| 1748 | return TARGET_SIGNAL_SAK; |
| 1749 | #endif |
| 1750 | #if defined (SIGPRIO) |
| 1751 | if (hostsig == SIGPRIO) |
| 1752 | return TARGET_SIGNAL_PRIO; |
| 1753 | #endif |
| 1754 | |
| 1755 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ |
| 1756 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) |
| 1757 | if (hostsig == _NSIG + EXC_BAD_ACCESS) |
| 1758 | return TARGET_EXC_BAD_ACCESS; |
| 1759 | #endif |
| 1760 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) |
| 1761 | if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) |
| 1762 | return TARGET_EXC_BAD_INSTRUCTION; |
| 1763 | #endif |
| 1764 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) |
| 1765 | if (hostsig == _NSIG + EXC_ARITHMETIC) |
| 1766 | return TARGET_EXC_ARITHMETIC; |
| 1767 | #endif |
| 1768 | #if defined (EXC_EMULATION) && defined (_NSIG) |
| 1769 | if (hostsig == _NSIG + EXC_EMULATION) |
| 1770 | return TARGET_EXC_EMULATION; |
| 1771 | #endif |
| 1772 | #if defined (EXC_SOFTWARE) && defined (_NSIG) |
| 1773 | if (hostsig == _NSIG + EXC_SOFTWARE) |
| 1774 | return TARGET_EXC_SOFTWARE; |
| 1775 | #endif |
| 1776 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) |
| 1777 | if (hostsig == _NSIG + EXC_BREAKPOINT) |
| 1778 | return TARGET_EXC_BREAKPOINT; |
| 1779 | #endif |
| 1780 | |
| 1781 | #if defined (SIGINFO) |
| 1782 | if (hostsig == SIGINFO) |
| 1783 | return TARGET_SIGNAL_INFO; |
| 1784 | #endif |
| 1785 | |
| 1786 | #if defined (REALTIME_LO) |
| 1787 | if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) |
| 1788 | { |
| 1789 | /* This block of TARGET_SIGNAL_REALTIME value is in order. */ |
| 1790 | if (33 <= hostsig && hostsig <= 63) |
| 1791 | return (enum target_signal) |
| 1792 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); |
| 1793 | else if (hostsig == 32) |
| 1794 | return TARGET_SIGNAL_REALTIME_32; |
| 1795 | else |
| 1796 | error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal"); |
| 1797 | } |
| 1798 | #endif |
| 1799 | |
| 1800 | #if defined (SIGRTMIN) |
| 1801 | if (hostsig >= SIGRTMIN && hostsig <= SIGRTMAX) |
| 1802 | { |
| 1803 | /* This block of TARGET_SIGNAL_REALTIME value is in order. */ |
| 1804 | if (33 <= hostsig && hostsig <= 63) |
| 1805 | return (enum target_signal) |
| 1806 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); |
| 1807 | else if (hostsig == 64) |
| 1808 | return TARGET_SIGNAL_REALTIME_64; |
| 1809 | else |
| 1810 | error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal"); |
| 1811 | } |
| 1812 | #endif |
| 1813 | return TARGET_SIGNAL_UNKNOWN; |
| 1814 | } |
| 1815 | |
| 1816 | /* Convert a OURSIG (an enum target_signal) to the form used by the |
| 1817 | target operating system (refered to as the ``host'') or zero if the |
| 1818 | equivalent host signal is not available. Set/clear OURSIG_OK |
| 1819 | accordingly. */ |
| 1820 | |
| 1821 | static int |
| 1822 | do_target_signal_to_host (enum target_signal oursig, |
| 1823 | int *oursig_ok) |
| 1824 | { |
| 1825 | *oursig_ok = 1; |
| 1826 | switch (oursig) |
| 1827 | { |
| 1828 | case TARGET_SIGNAL_0: |
| 1829 | return 0; |
| 1830 | |
| 1831 | #if defined (SIGHUP) |
| 1832 | case TARGET_SIGNAL_HUP: |
| 1833 | return SIGHUP; |
| 1834 | #endif |
| 1835 | #if defined (SIGINT) |
| 1836 | case TARGET_SIGNAL_INT: |
| 1837 | return SIGINT; |
| 1838 | #endif |
| 1839 | #if defined (SIGQUIT) |
| 1840 | case TARGET_SIGNAL_QUIT: |
| 1841 | return SIGQUIT; |
| 1842 | #endif |
| 1843 | #if defined (SIGILL) |
| 1844 | case TARGET_SIGNAL_ILL: |
| 1845 | return SIGILL; |
| 1846 | #endif |
| 1847 | #if defined (SIGTRAP) |
| 1848 | case TARGET_SIGNAL_TRAP: |
| 1849 | return SIGTRAP; |
| 1850 | #endif |
| 1851 | #if defined (SIGABRT) |
| 1852 | case TARGET_SIGNAL_ABRT: |
| 1853 | return SIGABRT; |
| 1854 | #endif |
| 1855 | #if defined (SIGEMT) |
| 1856 | case TARGET_SIGNAL_EMT: |
| 1857 | return SIGEMT; |
| 1858 | #endif |
| 1859 | #if defined (SIGFPE) |
| 1860 | case TARGET_SIGNAL_FPE: |
| 1861 | return SIGFPE; |
| 1862 | #endif |
| 1863 | #if defined (SIGKILL) |
| 1864 | case TARGET_SIGNAL_KILL: |
| 1865 | return SIGKILL; |
| 1866 | #endif |
| 1867 | #if defined (SIGBUS) |
| 1868 | case TARGET_SIGNAL_BUS: |
| 1869 | return SIGBUS; |
| 1870 | #endif |
| 1871 | #if defined (SIGSEGV) |
| 1872 | case TARGET_SIGNAL_SEGV: |
| 1873 | return SIGSEGV; |
| 1874 | #endif |
| 1875 | #if defined (SIGSYS) |
| 1876 | case TARGET_SIGNAL_SYS: |
| 1877 | return SIGSYS; |
| 1878 | #endif |
| 1879 | #if defined (SIGPIPE) |
| 1880 | case TARGET_SIGNAL_PIPE: |
| 1881 | return SIGPIPE; |
| 1882 | #endif |
| 1883 | #if defined (SIGALRM) |
| 1884 | case TARGET_SIGNAL_ALRM: |
| 1885 | return SIGALRM; |
| 1886 | #endif |
| 1887 | #if defined (SIGTERM) |
| 1888 | case TARGET_SIGNAL_TERM: |
| 1889 | return SIGTERM; |
| 1890 | #endif |
| 1891 | #if defined (SIGUSR1) |
| 1892 | case TARGET_SIGNAL_USR1: |
| 1893 | return SIGUSR1; |
| 1894 | #endif |
| 1895 | #if defined (SIGUSR2) |
| 1896 | case TARGET_SIGNAL_USR2: |
| 1897 | return SIGUSR2; |
| 1898 | #endif |
| 1899 | #if defined (SIGCHLD) || defined (SIGCLD) |
| 1900 | case TARGET_SIGNAL_CHLD: |
| 1901 | #if defined (SIGCHLD) |
| 1902 | return SIGCHLD; |
| 1903 | #else |
| 1904 | return SIGCLD; |
| 1905 | #endif |
| 1906 | #endif /* SIGCLD or SIGCHLD */ |
| 1907 | #if defined (SIGPWR) |
| 1908 | case TARGET_SIGNAL_PWR: |
| 1909 | return SIGPWR; |
| 1910 | #endif |
| 1911 | #if defined (SIGWINCH) |
| 1912 | case TARGET_SIGNAL_WINCH: |
| 1913 | return SIGWINCH; |
| 1914 | #endif |
| 1915 | #if defined (SIGURG) |
| 1916 | case TARGET_SIGNAL_URG: |
| 1917 | return SIGURG; |
| 1918 | #endif |
| 1919 | #if defined (SIGIO) |
| 1920 | case TARGET_SIGNAL_IO: |
| 1921 | return SIGIO; |
| 1922 | #endif |
| 1923 | #if defined (SIGPOLL) |
| 1924 | case TARGET_SIGNAL_POLL: |
| 1925 | return SIGPOLL; |
| 1926 | #endif |
| 1927 | #if defined (SIGSTOP) |
| 1928 | case TARGET_SIGNAL_STOP: |
| 1929 | return SIGSTOP; |
| 1930 | #endif |
| 1931 | #if defined (SIGTSTP) |
| 1932 | case TARGET_SIGNAL_TSTP: |
| 1933 | return SIGTSTP; |
| 1934 | #endif |
| 1935 | #if defined (SIGCONT) |
| 1936 | case TARGET_SIGNAL_CONT: |
| 1937 | return SIGCONT; |
| 1938 | #endif |
| 1939 | #if defined (SIGTTIN) |
| 1940 | case TARGET_SIGNAL_TTIN: |
| 1941 | return SIGTTIN; |
| 1942 | #endif |
| 1943 | #if defined (SIGTTOU) |
| 1944 | case TARGET_SIGNAL_TTOU: |
| 1945 | return SIGTTOU; |
| 1946 | #endif |
| 1947 | #if defined (SIGVTALRM) |
| 1948 | case TARGET_SIGNAL_VTALRM: |
| 1949 | return SIGVTALRM; |
| 1950 | #endif |
| 1951 | #if defined (SIGPROF) |
| 1952 | case TARGET_SIGNAL_PROF: |
| 1953 | return SIGPROF; |
| 1954 | #endif |
| 1955 | #if defined (SIGXCPU) |
| 1956 | case TARGET_SIGNAL_XCPU: |
| 1957 | return SIGXCPU; |
| 1958 | #endif |
| 1959 | #if defined (SIGXFSZ) |
| 1960 | case TARGET_SIGNAL_XFSZ: |
| 1961 | return SIGXFSZ; |
| 1962 | #endif |
| 1963 | #if defined (SIGWIND) |
| 1964 | case TARGET_SIGNAL_WIND: |
| 1965 | return SIGWIND; |
| 1966 | #endif |
| 1967 | #if defined (SIGPHONE) |
| 1968 | case TARGET_SIGNAL_PHONE: |
| 1969 | return SIGPHONE; |
| 1970 | #endif |
| 1971 | #if defined (SIGLOST) |
| 1972 | case TARGET_SIGNAL_LOST: |
| 1973 | return SIGLOST; |
| 1974 | #endif |
| 1975 | #if defined (SIGWAITING) |
| 1976 | case TARGET_SIGNAL_WAITING: |
| 1977 | return SIGWAITING; |
| 1978 | #endif |
| 1979 | #if defined (SIGCANCEL) |
| 1980 | case TARGET_SIGNAL_CANCEL: |
| 1981 | return SIGCANCEL; |
| 1982 | #endif |
| 1983 | #if defined (SIGLWP) |
| 1984 | case TARGET_SIGNAL_LWP: |
| 1985 | return SIGLWP; |
| 1986 | #endif |
| 1987 | #if defined (SIGDANGER) |
| 1988 | case TARGET_SIGNAL_DANGER: |
| 1989 | return SIGDANGER; |
| 1990 | #endif |
| 1991 | #if defined (SIGGRANT) |
| 1992 | case TARGET_SIGNAL_GRANT: |
| 1993 | return SIGGRANT; |
| 1994 | #endif |
| 1995 | #if defined (SIGRETRACT) |
| 1996 | case TARGET_SIGNAL_RETRACT: |
| 1997 | return SIGRETRACT; |
| 1998 | #endif |
| 1999 | #if defined (SIGMSG) |
| 2000 | case TARGET_SIGNAL_MSG: |
| 2001 | return SIGMSG; |
| 2002 | #endif |
| 2003 | #if defined (SIGSOUND) |
| 2004 | case TARGET_SIGNAL_SOUND: |
| 2005 | return SIGSOUND; |
| 2006 | #endif |
| 2007 | #if defined (SIGSAK) |
| 2008 | case TARGET_SIGNAL_SAK: |
| 2009 | return SIGSAK; |
| 2010 | #endif |
| 2011 | #if defined (SIGPRIO) |
| 2012 | case TARGET_SIGNAL_PRIO: |
| 2013 | return SIGPRIO; |
| 2014 | #endif |
| 2015 | |
| 2016 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ |
| 2017 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) |
| 2018 | case TARGET_EXC_BAD_ACCESS: |
| 2019 | return _NSIG + EXC_BAD_ACCESS; |
| 2020 | #endif |
| 2021 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) |
| 2022 | case TARGET_EXC_BAD_INSTRUCTION: |
| 2023 | return _NSIG + EXC_BAD_INSTRUCTION; |
| 2024 | #endif |
| 2025 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) |
| 2026 | case TARGET_EXC_ARITHMETIC: |
| 2027 | return _NSIG + EXC_ARITHMETIC; |
| 2028 | #endif |
| 2029 | #if defined (EXC_EMULATION) && defined (_NSIG) |
| 2030 | case TARGET_EXC_EMULATION: |
| 2031 | return _NSIG + EXC_EMULATION; |
| 2032 | #endif |
| 2033 | #if defined (EXC_SOFTWARE) && defined (_NSIG) |
| 2034 | case TARGET_EXC_SOFTWARE: |
| 2035 | return _NSIG + EXC_SOFTWARE; |
| 2036 | #endif |
| 2037 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) |
| 2038 | case TARGET_EXC_BREAKPOINT: |
| 2039 | return _NSIG + EXC_BREAKPOINT; |
| 2040 | #endif |
| 2041 | |
| 2042 | #if defined (SIGINFO) |
| 2043 | case TARGET_SIGNAL_INFO: |
| 2044 | return SIGINFO; |
| 2045 | #endif |
| 2046 | |
| 2047 | default: |
| 2048 | #if defined (REALTIME_LO) |
| 2049 | if (oursig >= TARGET_SIGNAL_REALTIME_33 |
| 2050 | && oursig <= TARGET_SIGNAL_REALTIME_63) |
| 2051 | { |
| 2052 | /* This block of signals is continuous, and |
| 2053 | TARGET_SIGNAL_REALTIME_33 is 33 by definition. */ |
| 2054 | int retsig = |
| 2055 | (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33; |
| 2056 | if (retsig >= REALTIME_LO && retsig < REALTIME_HI) |
| 2057 | return retsig; |
| 2058 | } |
| 2059 | #if (REALTIME_LO < 33) |
| 2060 | else if (oursig == TARGET_SIGNAL_REALTIME_32) |
| 2061 | { |
| 2062 | /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with |
| 2063 | TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */ |
| 2064 | return 32; |
| 2065 | } |
| 2066 | #endif |
| 2067 | #endif |
| 2068 | |
| 2069 | #if defined (SIGRTMIN) |
| 2070 | if (oursig >= TARGET_SIGNAL_REALTIME_33 |
| 2071 | && oursig <= TARGET_SIGNAL_REALTIME_63) |
| 2072 | { |
| 2073 | /* This block of signals is continuous, and |
| 2074 | TARGET_SIGNAL_REALTIME_33 is 33 by definition. */ |
| 2075 | int retsig = |
| 2076 | (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33; |
| 2077 | if (retsig >= SIGRTMIN && retsig <= SIGRTMAX) |
| 2078 | return retsig; |
| 2079 | } |
| 2080 | else if (oursig == TARGET_SIGNAL_REALTIME_64) |
| 2081 | return 64; |
| 2082 | #endif |
| 2083 | *oursig_ok = 0; |
| 2084 | return 0; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | int |
| 2089 | target_signal_to_host_p (enum target_signal oursig) |
| 2090 | { |
| 2091 | int oursig_ok; |
| 2092 | do_target_signal_to_host (oursig, &oursig_ok); |
| 2093 | return oursig_ok; |
| 2094 | } |
| 2095 | |
| 2096 | int |
| 2097 | target_signal_to_host (enum target_signal oursig) |
| 2098 | { |
| 2099 | int oursig_ok; |
| 2100 | int targ_signo = do_target_signal_to_host (oursig, &oursig_ok); |
| 2101 | if (!oursig_ok) |
| 2102 | { |
| 2103 | /* The user might be trying to do "signal SIGSAK" where this system |
| 2104 | doesn't have SIGSAK. */ |
| 2105 | warning ("Signal %s does not exist on this system.\n", |
| 2106 | target_signal_to_name (oursig)); |
| 2107 | return 0; |
| 2108 | } |
| 2109 | else |
| 2110 | return targ_signo; |
| 2111 | } |
| 2112 | |
| 2113 | /* Helper function for child_wait and the Lynx derivatives of child_wait. |
| 2114 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our |
| 2115 | translation of that in OURSTATUS. */ |
| 2116 | void |
| 2117 | store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) |
| 2118 | { |
| 2119 | #ifdef CHILD_SPECIAL_WAITSTATUS |
| 2120 | /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS |
| 2121 | if it wants to deal with hoststatus. */ |
| 2122 | if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus)) |
| 2123 | return; |
| 2124 | #endif |
| 2125 | |
| 2126 | if (WIFEXITED (hoststatus)) |
| 2127 | { |
| 2128 | ourstatus->kind = TARGET_WAITKIND_EXITED; |
| 2129 | ourstatus->value.integer = WEXITSTATUS (hoststatus); |
| 2130 | } |
| 2131 | else if (!WIFSTOPPED (hoststatus)) |
| 2132 | { |
| 2133 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; |
| 2134 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); |
| 2135 | } |
| 2136 | else |
| 2137 | { |
| 2138 | ourstatus->kind = TARGET_WAITKIND_STOPPED; |
| 2139 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); |
| 2140 | } |
| 2141 | } |
| 2142 | \f |
| 2143 | /* In some circumstances we allow a command to specify a numeric |
| 2144 | signal. The idea is to keep these circumstances limited so that |
| 2145 | users (and scripts) develop portable habits. For comparison, |
| 2146 | POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a |
| 2147 | numeric signal at all is obsolescent. We are slightly more |
| 2148 | lenient and allow 1-15 which should match host signal numbers on |
| 2149 | most systems. Use of symbolic signal names is strongly encouraged. */ |
| 2150 | |
| 2151 | enum target_signal |
| 2152 | target_signal_from_command (int num) |
| 2153 | { |
| 2154 | if (num >= 1 && num <= 15) |
| 2155 | return (enum target_signal) num; |
| 2156 | error ("Only signals 1-15 are valid as numeric signals.\n\ |
| 2157 | Use \"info signals\" for a list of symbolic signals."); |
| 2158 | } |
| 2159 | \f |
| 2160 | /* Returns zero to leave the inferior alone, one to interrupt it. */ |
| 2161 | int (*target_activity_function) (void); |
| 2162 | int target_activity_fd; |
| 2163 | \f |
| 2164 | /* Convert a normal process ID to a string. Returns the string in a static |
| 2165 | buffer. */ |
| 2166 | |
| 2167 | char * |
| 2168 | normal_pid_to_str (int pid) |
| 2169 | { |
| 2170 | static char buf[30]; |
| 2171 | |
| 2172 | if (STREQ (current_target.to_shortname, "remote")) |
| 2173 | sprintf (buf, "thread %d", pid); |
| 2174 | else |
| 2175 | sprintf (buf, "process %d", pid); |
| 2176 | |
| 2177 | return buf; |
| 2178 | } |
| 2179 | |
| 2180 | /* Some targets (such as ttrace-based HPUX) don't allow us to request |
| 2181 | notification of inferior events such as fork and vork immediately |
| 2182 | after the inferior is created. (This because of how gdb gets an |
| 2183 | inferior created via invoking a shell to do it. In such a scenario, |
| 2184 | if the shell init file has commands in it, the shell will fork and |
| 2185 | exec for each of those commands, and we will see each such fork |
| 2186 | event. Very bad.) |
| 2187 | |
| 2188 | This function is used by all targets that allow us to request |
| 2189 | notification of forks, etc at inferior creation time; e.g., in |
| 2190 | target_acknowledge_forked_child. |
| 2191 | */ |
| 2192 | static void |
| 2193 | normal_target_post_startup_inferior (int pid) |
| 2194 | { |
| 2195 | /* This space intentionally left blank. */ |
| 2196 | } |
| 2197 | |
| 2198 | /* Set up the handful of non-empty slots needed by the dummy target |
| 2199 | vector. */ |
| 2200 | |
| 2201 | static void |
| 2202 | init_dummy_target (void) |
| 2203 | { |
| 2204 | dummy_target.to_shortname = "None"; |
| 2205 | dummy_target.to_longname = "None"; |
| 2206 | dummy_target.to_doc = ""; |
| 2207 | dummy_target.to_attach = find_default_attach; |
| 2208 | dummy_target.to_require_attach = find_default_require_attach; |
| 2209 | dummy_target.to_require_detach = find_default_require_detach; |
| 2210 | dummy_target.to_create_inferior = find_default_create_inferior; |
| 2211 | dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior; |
| 2212 | dummy_target.to_pid_to_str = normal_pid_to_str; |
| 2213 | dummy_target.to_stratum = dummy_stratum; |
| 2214 | dummy_target.to_magic = OPS_MAGIC; |
| 2215 | } |
| 2216 | \f |
| 2217 | |
| 2218 | static struct target_ops debug_target; |
| 2219 | |
| 2220 | static void |
| 2221 | debug_to_open (char *args, int from_tty) |
| 2222 | { |
| 2223 | debug_target.to_open (args, from_tty); |
| 2224 | |
| 2225 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
| 2226 | } |
| 2227 | |
| 2228 | static void |
| 2229 | debug_to_close (int quitting) |
| 2230 | { |
| 2231 | debug_target.to_close (quitting); |
| 2232 | |
| 2233 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); |
| 2234 | } |
| 2235 | |
| 2236 | static void |
| 2237 | debug_to_attach (char *args, int from_tty) |
| 2238 | { |
| 2239 | debug_target.to_attach (args, from_tty); |
| 2240 | |
| 2241 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty); |
| 2242 | } |
| 2243 | |
| 2244 | |
| 2245 | static void |
| 2246 | debug_to_post_attach (int pid) |
| 2247 | { |
| 2248 | debug_target.to_post_attach (pid); |
| 2249 | |
| 2250 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
| 2251 | } |
| 2252 | |
| 2253 | static void |
| 2254 | debug_to_require_attach (char *args, int from_tty) |
| 2255 | { |
| 2256 | debug_target.to_require_attach (args, from_tty); |
| 2257 | |
| 2258 | fprintf_unfiltered (gdb_stdlog, |
| 2259 | "target_require_attach (%s, %d)\n", args, from_tty); |
| 2260 | } |
| 2261 | |
| 2262 | static void |
| 2263 | debug_to_detach (char *args, int from_tty) |
| 2264 | { |
| 2265 | debug_target.to_detach (args, from_tty); |
| 2266 | |
| 2267 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty); |
| 2268 | } |
| 2269 | |
| 2270 | static void |
| 2271 | debug_to_require_detach (int pid, char *args, int from_tty) |
| 2272 | { |
| 2273 | debug_target.to_require_detach (pid, args, from_tty); |
| 2274 | |
| 2275 | fprintf_unfiltered (gdb_stdlog, |
| 2276 | "target_require_detach (%d, %s, %d)\n", pid, args, from_tty); |
| 2277 | } |
| 2278 | |
| 2279 | static void |
| 2280 | debug_to_resume (int pid, int step, enum target_signal siggnal) |
| 2281 | { |
| 2282 | debug_target.to_resume (pid, step, siggnal); |
| 2283 | |
| 2284 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid, |
| 2285 | step ? "step" : "continue", |
| 2286 | target_signal_to_name (siggnal)); |
| 2287 | } |
| 2288 | |
| 2289 | static int |
| 2290 | debug_to_wait (int pid, struct target_waitstatus *status) |
| 2291 | { |
| 2292 | int retval; |
| 2293 | |
| 2294 | retval = debug_target.to_wait (pid, status); |
| 2295 | |
| 2296 | fprintf_unfiltered (gdb_stdlog, |
| 2297 | "target_wait (%d, status) = %d, ", pid, retval); |
| 2298 | fprintf_unfiltered (gdb_stdlog, "status->kind = "); |
| 2299 | switch (status->kind) |
| 2300 | { |
| 2301 | case TARGET_WAITKIND_EXITED: |
| 2302 | fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n", |
| 2303 | status->value.integer); |
| 2304 | break; |
| 2305 | case TARGET_WAITKIND_STOPPED: |
| 2306 | fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n", |
| 2307 | target_signal_to_name (status->value.sig)); |
| 2308 | break; |
| 2309 | case TARGET_WAITKIND_SIGNALLED: |
| 2310 | fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n", |
| 2311 | target_signal_to_name (status->value.sig)); |
| 2312 | break; |
| 2313 | case TARGET_WAITKIND_LOADED: |
| 2314 | fprintf_unfiltered (gdb_stdlog, "loaded\n"); |
| 2315 | break; |
| 2316 | case TARGET_WAITKIND_FORKED: |
| 2317 | fprintf_unfiltered (gdb_stdlog, "forked\n"); |
| 2318 | break; |
| 2319 | case TARGET_WAITKIND_VFORKED: |
| 2320 | fprintf_unfiltered (gdb_stdlog, "vforked\n"); |
| 2321 | break; |
| 2322 | case TARGET_WAITKIND_EXECD: |
| 2323 | fprintf_unfiltered (gdb_stdlog, "execd\n"); |
| 2324 | break; |
| 2325 | case TARGET_WAITKIND_SPURIOUS: |
| 2326 | fprintf_unfiltered (gdb_stdlog, "spurious\n"); |
| 2327 | break; |
| 2328 | default: |
| 2329 | fprintf_unfiltered (gdb_stdlog, "unknown???\n"); |
| 2330 | break; |
| 2331 | } |
| 2332 | |
| 2333 | return retval; |
| 2334 | } |
| 2335 | |
| 2336 | static void |
| 2337 | debug_to_post_wait (int pid, int status) |
| 2338 | { |
| 2339 | debug_target.to_post_wait (pid, status); |
| 2340 | |
| 2341 | fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n", |
| 2342 | pid, status); |
| 2343 | } |
| 2344 | |
| 2345 | static void |
| 2346 | debug_to_fetch_registers (int regno) |
| 2347 | { |
| 2348 | debug_target.to_fetch_registers (regno); |
| 2349 | |
| 2350 | fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)", |
| 2351 | regno != -1 ? REGISTER_NAME (regno) : "-1"); |
| 2352 | if (regno != -1) |
| 2353 | fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld", |
| 2354 | (unsigned long) read_register (regno), |
| 2355 | (unsigned long) read_register (regno)); |
| 2356 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 2357 | } |
| 2358 | |
| 2359 | static void |
| 2360 | debug_to_store_registers (int regno) |
| 2361 | { |
| 2362 | debug_target.to_store_registers (regno); |
| 2363 | |
| 2364 | if (regno >= 0 && regno < NUM_REGS) |
| 2365 | fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n", |
| 2366 | REGISTER_NAME (regno), |
| 2367 | (unsigned long) read_register (regno), |
| 2368 | (unsigned long) read_register (regno)); |
| 2369 | else |
| 2370 | fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno); |
| 2371 | } |
| 2372 | |
| 2373 | static void |
| 2374 | debug_to_prepare_to_store (void) |
| 2375 | { |
| 2376 | debug_target.to_prepare_to_store (); |
| 2377 | |
| 2378 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
| 2379 | } |
| 2380 | |
| 2381 | static int |
| 2382 | debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
| 2383 | struct mem_attrib *attrib, |
| 2384 | struct target_ops *target) |
| 2385 | { |
| 2386 | int retval; |
| 2387 | |
| 2388 | retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, |
| 2389 | attrib, target); |
| 2390 | |
| 2391 | fprintf_unfiltered (gdb_stdlog, |
| 2392 | "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
| 2393 | (unsigned int) memaddr, /* possable truncate long long */ |
| 2394 | len, write ? "write" : "read", retval); |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | if (retval > 0) |
| 2399 | { |
| 2400 | int i; |
| 2401 | |
| 2402 | fputs_unfiltered (", bytes =", gdb_stdlog); |
| 2403 | for (i = 0; i < retval; i++) |
| 2404 | { |
| 2405 | if ((((long) &(myaddr[i])) & 0xf) == 0) |
| 2406 | fprintf_unfiltered (gdb_stdlog, "\n"); |
| 2407 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | fputc_unfiltered ('\n', gdb_stdlog); |
| 2412 | |
| 2413 | return retval; |
| 2414 | } |
| 2415 | |
| 2416 | static void |
| 2417 | debug_to_files_info (struct target_ops *target) |
| 2418 | { |
| 2419 | debug_target.to_files_info (target); |
| 2420 | |
| 2421 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
| 2422 | } |
| 2423 | |
| 2424 | static int |
| 2425 | debug_to_insert_breakpoint (CORE_ADDR addr, char *save) |
| 2426 | { |
| 2427 | int retval; |
| 2428 | |
| 2429 | retval = debug_target.to_insert_breakpoint (addr, save); |
| 2430 | |
| 2431 | fprintf_unfiltered (gdb_stdlog, |
| 2432 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
| 2433 | (unsigned long) addr, |
| 2434 | (unsigned long) retval); |
| 2435 | return retval; |
| 2436 | } |
| 2437 | |
| 2438 | static int |
| 2439 | debug_to_remove_breakpoint (CORE_ADDR addr, char *save) |
| 2440 | { |
| 2441 | int retval; |
| 2442 | |
| 2443 | retval = debug_target.to_remove_breakpoint (addr, save); |
| 2444 | |
| 2445 | fprintf_unfiltered (gdb_stdlog, |
| 2446 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
| 2447 | (unsigned long) addr, |
| 2448 | (unsigned long) retval); |
| 2449 | return retval; |
| 2450 | } |
| 2451 | |
| 2452 | static void |
| 2453 | debug_to_terminal_init (void) |
| 2454 | { |
| 2455 | debug_target.to_terminal_init (); |
| 2456 | |
| 2457 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
| 2458 | } |
| 2459 | |
| 2460 | static void |
| 2461 | debug_to_terminal_inferior (void) |
| 2462 | { |
| 2463 | debug_target.to_terminal_inferior (); |
| 2464 | |
| 2465 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
| 2466 | } |
| 2467 | |
| 2468 | static void |
| 2469 | debug_to_terminal_ours_for_output (void) |
| 2470 | { |
| 2471 | debug_target.to_terminal_ours_for_output (); |
| 2472 | |
| 2473 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
| 2474 | } |
| 2475 | |
| 2476 | static void |
| 2477 | debug_to_terminal_ours (void) |
| 2478 | { |
| 2479 | debug_target.to_terminal_ours (); |
| 2480 | |
| 2481 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
| 2482 | } |
| 2483 | |
| 2484 | static void |
| 2485 | debug_to_terminal_info (char *arg, int from_tty) |
| 2486 | { |
| 2487 | debug_target.to_terminal_info (arg, from_tty); |
| 2488 | |
| 2489 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
| 2490 | from_tty); |
| 2491 | } |
| 2492 | |
| 2493 | static void |
| 2494 | debug_to_kill (void) |
| 2495 | { |
| 2496 | debug_target.to_kill (); |
| 2497 | |
| 2498 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); |
| 2499 | } |
| 2500 | |
| 2501 | static void |
| 2502 | debug_to_load (char *args, int from_tty) |
| 2503 | { |
| 2504 | debug_target.to_load (args, from_tty); |
| 2505 | |
| 2506 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
| 2507 | } |
| 2508 | |
| 2509 | static int |
| 2510 | debug_to_lookup_symbol (char *name, CORE_ADDR *addrp) |
| 2511 | { |
| 2512 | int retval; |
| 2513 | |
| 2514 | retval = debug_target.to_lookup_symbol (name, addrp); |
| 2515 | |
| 2516 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
| 2517 | |
| 2518 | return retval; |
| 2519 | } |
| 2520 | |
| 2521 | static void |
| 2522 | debug_to_create_inferior (char *exec_file, char *args, char **env) |
| 2523 | { |
| 2524 | debug_target.to_create_inferior (exec_file, args, env); |
| 2525 | |
| 2526 | fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n", |
| 2527 | exec_file, args); |
| 2528 | } |
| 2529 | |
| 2530 | static void |
| 2531 | debug_to_post_startup_inferior (int pid) |
| 2532 | { |
| 2533 | debug_target.to_post_startup_inferior (pid); |
| 2534 | |
| 2535 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
| 2536 | pid); |
| 2537 | } |
| 2538 | |
| 2539 | static void |
| 2540 | debug_to_acknowledge_created_inferior (int pid) |
| 2541 | { |
| 2542 | debug_target.to_acknowledge_created_inferior (pid); |
| 2543 | |
| 2544 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
| 2545 | pid); |
| 2546 | } |
| 2547 | |
| 2548 | static void |
| 2549 | debug_to_clone_and_follow_inferior (int child_pid, int *followed_child) |
| 2550 | { |
| 2551 | debug_target.to_clone_and_follow_inferior (child_pid, followed_child); |
| 2552 | |
| 2553 | fprintf_unfiltered (gdb_stdlog, |
| 2554 | "target_clone_and_follow_inferior (%d, %d)\n", |
| 2555 | child_pid, *followed_child); |
| 2556 | } |
| 2557 | |
| 2558 | static void |
| 2559 | debug_to_post_follow_inferior_by_clone (void) |
| 2560 | { |
| 2561 | debug_target.to_post_follow_inferior_by_clone (); |
| 2562 | |
| 2563 | fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n"); |
| 2564 | } |
| 2565 | |
| 2566 | static int |
| 2567 | debug_to_insert_fork_catchpoint (int pid) |
| 2568 | { |
| 2569 | int retval; |
| 2570 | |
| 2571 | retval = debug_target.to_insert_fork_catchpoint (pid); |
| 2572 | |
| 2573 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n", |
| 2574 | pid, retval); |
| 2575 | |
| 2576 | return retval; |
| 2577 | } |
| 2578 | |
| 2579 | static int |
| 2580 | debug_to_remove_fork_catchpoint (int pid) |
| 2581 | { |
| 2582 | int retval; |
| 2583 | |
| 2584 | retval = debug_target.to_remove_fork_catchpoint (pid); |
| 2585 | |
| 2586 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
| 2587 | pid, retval); |
| 2588 | |
| 2589 | return retval; |
| 2590 | } |
| 2591 | |
| 2592 | static int |
| 2593 | debug_to_insert_vfork_catchpoint (int pid) |
| 2594 | { |
| 2595 | int retval; |
| 2596 | |
| 2597 | retval = debug_target.to_insert_vfork_catchpoint (pid); |
| 2598 | |
| 2599 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n", |
| 2600 | pid, retval); |
| 2601 | |
| 2602 | return retval; |
| 2603 | } |
| 2604 | |
| 2605 | static int |
| 2606 | debug_to_remove_vfork_catchpoint (int pid) |
| 2607 | { |
| 2608 | int retval; |
| 2609 | |
| 2610 | retval = debug_target.to_remove_vfork_catchpoint (pid); |
| 2611 | |
| 2612 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
| 2613 | pid, retval); |
| 2614 | |
| 2615 | return retval; |
| 2616 | } |
| 2617 | |
| 2618 | static int |
| 2619 | debug_to_has_forked (int pid, int *child_pid) |
| 2620 | { |
| 2621 | int has_forked; |
| 2622 | |
| 2623 | has_forked = debug_target.to_has_forked (pid, child_pid); |
| 2624 | |
| 2625 | fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n", |
| 2626 | pid, *child_pid, has_forked); |
| 2627 | |
| 2628 | return has_forked; |
| 2629 | } |
| 2630 | |
| 2631 | static int |
| 2632 | debug_to_has_vforked (int pid, int *child_pid) |
| 2633 | { |
| 2634 | int has_vforked; |
| 2635 | |
| 2636 | has_vforked = debug_target.to_has_vforked (pid, child_pid); |
| 2637 | |
| 2638 | fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n", |
| 2639 | pid, *child_pid, has_vforked); |
| 2640 | |
| 2641 | return has_vforked; |
| 2642 | } |
| 2643 | |
| 2644 | static int |
| 2645 | debug_to_can_follow_vfork_prior_to_exec (void) |
| 2646 | { |
| 2647 | int can_immediately_follow_vfork; |
| 2648 | |
| 2649 | can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec (); |
| 2650 | |
| 2651 | fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n", |
| 2652 | can_immediately_follow_vfork); |
| 2653 | |
| 2654 | return can_immediately_follow_vfork; |
| 2655 | } |
| 2656 | |
| 2657 | static void |
| 2658 | debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid, |
| 2659 | int followed_child) |
| 2660 | { |
| 2661 | debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child); |
| 2662 | |
| 2663 | fprintf_unfiltered (gdb_stdlog, |
| 2664 | "target_post_follow_vfork (%d, %d, %d, %d)\n", |
| 2665 | parent_pid, followed_parent, child_pid, followed_child); |
| 2666 | } |
| 2667 | |
| 2668 | static int |
| 2669 | debug_to_insert_exec_catchpoint (int pid) |
| 2670 | { |
| 2671 | int retval; |
| 2672 | |
| 2673 | retval = debug_target.to_insert_exec_catchpoint (pid); |
| 2674 | |
| 2675 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n", |
| 2676 | pid, retval); |
| 2677 | |
| 2678 | return retval; |
| 2679 | } |
| 2680 | |
| 2681 | static int |
| 2682 | debug_to_remove_exec_catchpoint (int pid) |
| 2683 | { |
| 2684 | int retval; |
| 2685 | |
| 2686 | retval = debug_target.to_remove_exec_catchpoint (pid); |
| 2687 | |
| 2688 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
| 2689 | pid, retval); |
| 2690 | |
| 2691 | return retval; |
| 2692 | } |
| 2693 | |
| 2694 | static int |
| 2695 | debug_to_has_execd (int pid, char **execd_pathname) |
| 2696 | { |
| 2697 | int has_execd; |
| 2698 | |
| 2699 | has_execd = debug_target.to_has_execd (pid, execd_pathname); |
| 2700 | |
| 2701 | fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n", |
| 2702 | pid, (*execd_pathname ? *execd_pathname : "<NULL>"), |
| 2703 | has_execd); |
| 2704 | |
| 2705 | return has_execd; |
| 2706 | } |
| 2707 | |
| 2708 | static int |
| 2709 | debug_to_reported_exec_events_per_exec_call (void) |
| 2710 | { |
| 2711 | int reported_exec_events; |
| 2712 | |
| 2713 | reported_exec_events = debug_target.to_reported_exec_events_per_exec_call (); |
| 2714 | |
| 2715 | fprintf_unfiltered (gdb_stdlog, |
| 2716 | "target_reported_exec_events_per_exec_call () = %d\n", |
| 2717 | reported_exec_events); |
| 2718 | |
| 2719 | return reported_exec_events; |
| 2720 | } |
| 2721 | |
| 2722 | static int |
| 2723 | debug_to_has_syscall_event (int pid, enum target_waitkind *kind, |
| 2724 | int *syscall_id) |
| 2725 | { |
| 2726 | int has_syscall_event; |
| 2727 | char *kind_spelling = "??"; |
| 2728 | |
| 2729 | has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id); |
| 2730 | if (has_syscall_event) |
| 2731 | { |
| 2732 | switch (*kind) |
| 2733 | { |
| 2734 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
| 2735 | kind_spelling = "SYSCALL_ENTRY"; |
| 2736 | break; |
| 2737 | case TARGET_WAITKIND_SYSCALL_RETURN: |
| 2738 | kind_spelling = "SYSCALL_RETURN"; |
| 2739 | break; |
| 2740 | default: |
| 2741 | break; |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | fprintf_unfiltered (gdb_stdlog, |
| 2746 | "target_has_syscall_event (%d, %s, %d) = %d\n", |
| 2747 | pid, kind_spelling, *syscall_id, has_syscall_event); |
| 2748 | |
| 2749 | return has_syscall_event; |
| 2750 | } |
| 2751 | |
| 2752 | static int |
| 2753 | debug_to_has_exited (int pid, int wait_status, int *exit_status) |
| 2754 | { |
| 2755 | int has_exited; |
| 2756 | |
| 2757 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); |
| 2758 | |
| 2759 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
| 2760 | pid, wait_status, *exit_status, has_exited); |
| 2761 | |
| 2762 | return has_exited; |
| 2763 | } |
| 2764 | |
| 2765 | static void |
| 2766 | debug_to_mourn_inferior (void) |
| 2767 | { |
| 2768 | debug_target.to_mourn_inferior (); |
| 2769 | |
| 2770 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); |
| 2771 | } |
| 2772 | |
| 2773 | static int |
| 2774 | debug_to_can_run (void) |
| 2775 | { |
| 2776 | int retval; |
| 2777 | |
| 2778 | retval = debug_target.to_can_run (); |
| 2779 | |
| 2780 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
| 2781 | |
| 2782 | return retval; |
| 2783 | } |
| 2784 | |
| 2785 | static void |
| 2786 | debug_to_notice_signals (int pid) |
| 2787 | { |
| 2788 | debug_target.to_notice_signals (pid); |
| 2789 | |
| 2790 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid); |
| 2791 | } |
| 2792 | |
| 2793 | static int |
| 2794 | debug_to_thread_alive (int pid) |
| 2795 | { |
| 2796 | int retval; |
| 2797 | |
| 2798 | retval = debug_target.to_thread_alive (pid); |
| 2799 | |
| 2800 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", |
| 2801 | pid, retval); |
| 2802 | |
| 2803 | return retval; |
| 2804 | } |
| 2805 | |
| 2806 | static void |
| 2807 | debug_to_find_new_threads (void) |
| 2808 | { |
| 2809 | debug_target.to_find_new_threads (); |
| 2810 | |
| 2811 | fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog); |
| 2812 | } |
| 2813 | |
| 2814 | static void |
| 2815 | debug_to_stop (void) |
| 2816 | { |
| 2817 | debug_target.to_stop (); |
| 2818 | |
| 2819 | fprintf_unfiltered (gdb_stdlog, "target_stop ()\n"); |
| 2820 | } |
| 2821 | |
| 2822 | static int |
| 2823 | debug_to_query (int type, char *req, char *resp, int *siz) |
| 2824 | { |
| 2825 | int retval; |
| 2826 | |
| 2827 | retval = debug_target.to_query (type, req, resp, siz); |
| 2828 | |
| 2829 | fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval); |
| 2830 | |
| 2831 | return retval; |
| 2832 | } |
| 2833 | |
| 2834 | static void |
| 2835 | debug_to_rcmd (char *command, |
| 2836 | struct ui_file *outbuf) |
| 2837 | { |
| 2838 | debug_target.to_rcmd (command, outbuf); |
| 2839 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); |
| 2840 | } |
| 2841 | |
| 2842 | static struct symtab_and_line * |
| 2843 | debug_to_enable_exception_callback (enum exception_event_kind kind, int enable) |
| 2844 | { |
| 2845 | struct symtab_and_line *result; |
| 2846 | result = debug_target.to_enable_exception_callback (kind, enable); |
| 2847 | fprintf_unfiltered (gdb_stdlog, |
| 2848 | "target get_exception_callback_sal (%d, %d)\n", |
| 2849 | kind, enable); |
| 2850 | return result; |
| 2851 | } |
| 2852 | |
| 2853 | static struct exception_event_record * |
| 2854 | debug_to_get_current_exception_event (void) |
| 2855 | { |
| 2856 | struct exception_event_record *result; |
| 2857 | result = debug_target.to_get_current_exception_event (); |
| 2858 | fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n"); |
| 2859 | return result; |
| 2860 | } |
| 2861 | |
| 2862 | static char * |
| 2863 | debug_to_pid_to_exec_file (int pid) |
| 2864 | { |
| 2865 | char *exec_file; |
| 2866 | |
| 2867 | exec_file = debug_target.to_pid_to_exec_file (pid); |
| 2868 | |
| 2869 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
| 2870 | pid, exec_file); |
| 2871 | |
| 2872 | return exec_file; |
| 2873 | } |
| 2874 | |
| 2875 | static char * |
| 2876 | debug_to_core_file_to_sym_file (char *core) |
| 2877 | { |
| 2878 | char *sym_file; |
| 2879 | |
| 2880 | sym_file = debug_target.to_core_file_to_sym_file (core); |
| 2881 | |
| 2882 | fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n", |
| 2883 | core, sym_file); |
| 2884 | |
| 2885 | return sym_file; |
| 2886 | } |
| 2887 | |
| 2888 | static void |
| 2889 | setup_target_debug (void) |
| 2890 | { |
| 2891 | memcpy (&debug_target, ¤t_target, sizeof debug_target); |
| 2892 | |
| 2893 | current_target.to_open = debug_to_open; |
| 2894 | current_target.to_close = debug_to_close; |
| 2895 | current_target.to_attach = debug_to_attach; |
| 2896 | current_target.to_post_attach = debug_to_post_attach; |
| 2897 | current_target.to_require_attach = debug_to_require_attach; |
| 2898 | current_target.to_detach = debug_to_detach; |
| 2899 | current_target.to_require_detach = debug_to_require_detach; |
| 2900 | current_target.to_resume = debug_to_resume; |
| 2901 | current_target.to_wait = debug_to_wait; |
| 2902 | current_target.to_post_wait = debug_to_post_wait; |
| 2903 | current_target.to_fetch_registers = debug_to_fetch_registers; |
| 2904 | current_target.to_store_registers = debug_to_store_registers; |
| 2905 | current_target.to_prepare_to_store = debug_to_prepare_to_store; |
| 2906 | current_target.to_xfer_memory = debug_to_xfer_memory; |
| 2907 | current_target.to_files_info = debug_to_files_info; |
| 2908 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; |
| 2909 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; |
| 2910 | current_target.to_terminal_init = debug_to_terminal_init; |
| 2911 | current_target.to_terminal_inferior = debug_to_terminal_inferior; |
| 2912 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; |
| 2913 | current_target.to_terminal_ours = debug_to_terminal_ours; |
| 2914 | current_target.to_terminal_info = debug_to_terminal_info; |
| 2915 | current_target.to_kill = debug_to_kill; |
| 2916 | current_target.to_load = debug_to_load; |
| 2917 | current_target.to_lookup_symbol = debug_to_lookup_symbol; |
| 2918 | current_target.to_create_inferior = debug_to_create_inferior; |
| 2919 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; |
| 2920 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; |
| 2921 | current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior; |
| 2922 | current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone; |
| 2923 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; |
| 2924 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; |
| 2925 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; |
| 2926 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; |
| 2927 | current_target.to_has_forked = debug_to_has_forked; |
| 2928 | current_target.to_has_vforked = debug_to_has_vforked; |
| 2929 | current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec; |
| 2930 | current_target.to_post_follow_vfork = debug_to_post_follow_vfork; |
| 2931 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; |
| 2932 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; |
| 2933 | current_target.to_has_execd = debug_to_has_execd; |
| 2934 | current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call; |
| 2935 | current_target.to_has_syscall_event = debug_to_has_syscall_event; |
| 2936 | current_target.to_has_exited = debug_to_has_exited; |
| 2937 | current_target.to_mourn_inferior = debug_to_mourn_inferior; |
| 2938 | current_target.to_can_run = debug_to_can_run; |
| 2939 | current_target.to_notice_signals = debug_to_notice_signals; |
| 2940 | current_target.to_thread_alive = debug_to_thread_alive; |
| 2941 | current_target.to_find_new_threads = debug_to_find_new_threads; |
| 2942 | current_target.to_stop = debug_to_stop; |
| 2943 | current_target.to_query = debug_to_query; |
| 2944 | current_target.to_rcmd = debug_to_rcmd; |
| 2945 | current_target.to_enable_exception_callback = debug_to_enable_exception_callback; |
| 2946 | current_target.to_get_current_exception_event = debug_to_get_current_exception_event; |
| 2947 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; |
| 2948 | current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file; |
| 2949 | |
| 2950 | } |
| 2951 | \f |
| 2952 | |
| 2953 | static char targ_desc[] = |
| 2954 | "Names of targets and files being debugged.\n\ |
| 2955 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
| 2956 | core-file, and process, if any), as well as the symbol file name."; |
| 2957 | |
| 2958 | static void |
| 2959 | do_monitor_command (char *cmd, |
| 2960 | int from_tty) |
| 2961 | { |
| 2962 | if ((current_target.to_rcmd |
| 2963 | == (void (*) (char *, struct ui_file *)) tcomplain) |
| 2964 | || (current_target.to_rcmd == debug_to_rcmd |
| 2965 | && (debug_target.to_rcmd |
| 2966 | == (void (*) (char *, struct ui_file *)) tcomplain))) |
| 2967 | { |
| 2968 | error ("\"monitor\" command not supported by this target.\n"); |
| 2969 | } |
| 2970 | target_rcmd (cmd, gdb_stdtarg); |
| 2971 | } |
| 2972 | |
| 2973 | void |
| 2974 | initialize_targets (void) |
| 2975 | { |
| 2976 | init_dummy_target (); |
| 2977 | push_target (&dummy_target); |
| 2978 | |
| 2979 | add_info ("target", target_info, targ_desc); |
| 2980 | add_info ("files", target_info, targ_desc); |
| 2981 | |
| 2982 | add_show_from_set ( |
| 2983 | add_set_cmd ("target", class_maintenance, var_zinteger, |
| 2984 | (char *) &targetdebug, |
| 2985 | "Set target debugging.\n\ |
| 2986 | When non-zero, target debugging is enabled.", &setdebuglist), |
| 2987 | &showdebuglist); |
| 2988 | |
| 2989 | |
| 2990 | add_com ("monitor", class_obscure, do_monitor_command, |
| 2991 | "Send a command to the remote monitor (remote targets only)."); |
| 2992 | |
| 2993 | target_dcache = dcache_init(); |
| 2994 | |
| 2995 | if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC")) |
| 2996 | abort (); |
| 2997 | } |