OLD | NEW |
1 /* Fork a Unix child process, and set up to debug it, for GDB. | 1 /* Fork a Unix child process, and set up to debug it, for GDB. |
2 | 2 |
3 Copyright (C) 1990-1996, 1998-2001, 2004-2012 Free Software | 3 Copyright (C) 1990-1996, 1998-2001, 2004-2012 Free Software |
4 Foundation, Inc. | 4 Foundation, Inc. |
5 | 5 |
6 Contributed by Cygnus Support. | 6 Contributed by Cygnus Support. |
7 | 7 |
8 This file is part of GDB. | 8 This file is part of GDB. |
9 | 9 |
10 This program is free software; you can redistribute it and/or modify | 10 This program is free software; you can redistribute it and/or modify |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 shell, "-c" says to interpret the next arg as a shell command | 265 shell, "-c" says to interpret the next arg as a shell command |
266 to execute, and this command is "exec <target-program> | 266 to execute, and this command is "exec <target-program> |
267 <args>". */ | 267 <args>". */ |
268 argv = (char **) alloca (4 * sizeof (char *)); | 268 argv = (char **) alloca (4 * sizeof (char *)); |
269 argv[0] = shell_file; | 269 argv[0] = shell_file; |
270 argv[1] = "-c"; | 270 argv[1] = "-c"; |
271 argv[2] = shell_command; | 271 argv[2] = shell_command; |
272 argv[3] = (char *) 0; | 272 argv[3] = (char *) 0; |
273 } | 273 } |
274 | 274 |
275 /* On some systems an exec will fail if the executable is open. */ | |
276 close_exec_file (); | |
277 | |
278 /* Retain a copy of our environment variables, since the child will | 275 /* Retain a copy of our environment variables, since the child will |
279 replace the value of environ and if we're vforked, we have to | 276 replace the value of environ and if we're vforked, we have to |
280 restore it. */ | 277 restore it. */ |
281 save_our_env = environ; | 278 save_our_env = environ; |
282 | 279 |
283 /* Tell the terminal handling subsystem what tty we plan to run on; | 280 /* Tell the terminal handling subsystem what tty we plan to run on; |
284 it will just record the information for later. */ | 281 it will just record the information for later. */ |
285 new_tty_prefork (inferior_io_terminal); | 282 new_tty_prefork (inferior_io_terminal); |
286 | 283 |
287 /* It is generally good practice to flush any possible pending stdio | 284 /* It is generally good practice to flush any possible pending stdio |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 424 |
428 /* The process was started by the fork that created it, but it will | 425 /* The process was started by the fork that created it, but it will |
429 have stopped one instruction after execing the shell. Here we | 426 have stopped one instruction after execing the shell. Here we |
430 must get it up to actual execution of the real program. */ | 427 must get it up to actual execution of the real program. */ |
431 | 428 |
432 if (exec_wrapper) | 429 if (exec_wrapper) |
433 pending_execs++; | 430 pending_execs++; |
434 | 431 |
435 while (1) | 432 while (1) |
436 { | 433 { |
437 enum target_signal resume_signal = TARGET_SIGNAL_0; | 434 enum gdb_signal resume_signal = GDB_SIGNAL_0; |
438 ptid_t event_ptid; | 435 ptid_t event_ptid; |
439 | 436 |
440 struct target_waitstatus ws; | 437 struct target_waitstatus ws; |
441 memset (&ws, 0, sizeof (ws)); | 438 memset (&ws, 0, sizeof (ws)); |
442 event_ptid = target_wait (resume_ptid, &ws, 0); | 439 event_ptid = target_wait (resume_ptid, &ws, 0); |
443 | 440 |
444 if (ws.kind == TARGET_WAITKIND_IGNORE) | 441 if (ws.kind == TARGET_WAITKIND_IGNORE) |
445 /* The inferior didn't really stop, keep waiting. */ | 442 /* The inferior didn't really stop, keep waiting. */ |
446 continue; | 443 continue; |
447 | 444 |
448 switch (ws.kind) | 445 switch (ws.kind) |
449 { | 446 { |
450 case TARGET_WAITKIND_SPURIOUS: | 447 case TARGET_WAITKIND_SPURIOUS: |
451 case TARGET_WAITKIND_LOADED: | 448 case TARGET_WAITKIND_LOADED: |
452 case TARGET_WAITKIND_FORKED: | 449 case TARGET_WAITKIND_FORKED: |
453 case TARGET_WAITKIND_VFORKED: | 450 case TARGET_WAITKIND_VFORKED: |
454 case TARGET_WAITKIND_SYSCALL_ENTRY: | 451 case TARGET_WAITKIND_SYSCALL_ENTRY: |
455 case TARGET_WAITKIND_SYSCALL_RETURN: | 452 case TARGET_WAITKIND_SYSCALL_RETURN: |
456 /* Ignore gracefully during startup of the inferior. */ | 453 /* Ignore gracefully during startup of the inferior. */ |
457 switch_to_thread (event_ptid); | 454 switch_to_thread (event_ptid); |
458 break; | 455 break; |
459 | 456 |
460 case TARGET_WAITKIND_SIGNALLED: | 457 case TARGET_WAITKIND_SIGNALLED: |
461 target_terminal_ours (); | 458 target_terminal_ours (); |
462 target_mourn_inferior (); | 459 target_mourn_inferior (); |
463 error (_("During startup program terminated with signal %s, %s."), | 460 error (_("During startup program terminated with signal %s, %s."), |
464 » » target_signal_to_name (ws.value.sig), | 461 » » gdb_signal_to_name (ws.value.sig), |
465 » » target_signal_to_string (ws.value.sig)); | 462 » » gdb_signal_to_string (ws.value.sig)); |
466 return; | 463 return; |
467 | 464 |
468 case TARGET_WAITKIND_EXITED: | 465 case TARGET_WAITKIND_EXITED: |
469 target_terminal_ours (); | 466 target_terminal_ours (); |
470 target_mourn_inferior (); | 467 target_mourn_inferior (); |
471 if (ws.value.integer) | 468 if (ws.value.integer) |
472 error (_("During startup program exited with code %d."), | 469 error (_("During startup program exited with code %d."), |
473 ws.value.integer); | 470 ws.value.integer); |
474 else | 471 else |
475 error (_("During startup program exited normally.")); | 472 error (_("During startup program exited normally.")); |
476 return; | 473 return; |
477 | 474 |
478 case TARGET_WAITKIND_EXECD: | 475 case TARGET_WAITKIND_EXECD: |
479 /* Handle EXEC signals as if they were SIGTRAP signals. */ | 476 /* Handle EXEC signals as if they were SIGTRAP signals. */ |
480 xfree (ws.value.execd_pathname); | 477 xfree (ws.value.execd_pathname); |
481 » resume_signal = TARGET_SIGNAL_TRAP; | 478 » resume_signal = GDB_SIGNAL_TRAP; |
482 switch_to_thread (event_ptid); | 479 switch_to_thread (event_ptid); |
483 break; | 480 break; |
484 | 481 |
485 case TARGET_WAITKIND_STOPPED: | 482 case TARGET_WAITKIND_STOPPED: |
486 resume_signal = ws.value.sig; | 483 resume_signal = ws.value.sig; |
487 switch_to_thread (event_ptid); | 484 switch_to_thread (event_ptid); |
488 break; | 485 break; |
489 } | 486 } |
490 | 487 |
491 if (resume_signal != TARGET_SIGNAL_TRAP) | 488 if (resume_signal != GDB_SIGNAL_TRAP) |
492 { | 489 { |
493 /* Let shell child handle its own signals in its own way. */ | 490 /* Let shell child handle its own signals in its own way. */ |
494 target_resume (resume_ptid, 0, resume_signal); | 491 target_resume (resume_ptid, 0, resume_signal); |
495 } | 492 } |
496 else | 493 else |
497 { | 494 { |
498 /* We handle SIGTRAP, however; it means child did an exec. */ | 495 /* We handle SIGTRAP, however; it means child did an exec. */ |
499 if (!terminal_initted) | 496 if (!terminal_initted) |
500 { | 497 { |
501 /* Now that the child has exec'd we know it has already | 498 /* Now that the child has exec'd we know it has already |
502 set its process group. On POSIX systems, tcsetpgrp | 499 set its process group. On POSIX systems, tcsetpgrp |
503 will fail with EPERM if we try it before the child's | 500 will fail with EPERM if we try it before the child's |
504 setpgid. */ | 501 setpgid. */ |
505 | 502 |
506 /* Set up the "saved terminal modes" of the inferior | 503 /* Set up the "saved terminal modes" of the inferior |
507 based on what modes we are starting it with. */ | 504 based on what modes we are starting it with. */ |
508 target_terminal_init (); | 505 target_terminal_init (); |
509 | 506 |
510 /* Install inferior's terminal modes. */ | 507 /* Install inferior's terminal modes. */ |
511 target_terminal_inferior (); | 508 target_terminal_inferior (); |
512 | 509 |
513 terminal_initted = 1; | 510 terminal_initted = 1; |
514 } | 511 } |
515 | 512 |
516 if (--pending_execs == 0) | 513 if (--pending_execs == 0) |
517 break; | 514 break; |
518 | 515 |
519 /* Just make it go on. */ | 516 /* Just make it go on. */ |
520 » target_resume (resume_ptid, 0, TARGET_SIGNAL_0); | 517 » target_resume (resume_ptid, 0, GDB_SIGNAL_0); |
521 } | 518 } |
522 } | 519 } |
523 | 520 |
524 /* Mark all threads non-executing. */ | 521 /* Mark all threads non-executing. */ |
525 set_executing (resume_ptid, 0); | 522 set_executing (resume_ptid, 0); |
526 } | 523 } |
527 | 524 |
528 /* Implement the "unset exec-wrapper" command. */ | 525 /* Implement the "unset exec-wrapper" command. */ |
529 | 526 |
530 static void | 527 static void |
(...skipping 14 matching lines...) Expand all Loading... |
545 The wrapper prepares the system and environment for the new program."), | 542 The wrapper prepares the system and environment for the new program."), |
546 _("\ | 543 _("\ |
547 Show the wrapper for running programs."), NULL, | 544 Show the wrapper for running programs."), NULL, |
548 NULL, NULL, | 545 NULL, NULL, |
549 &setlist, &showlist); | 546 &setlist, &showlist); |
550 | 547 |
551 add_cmd ("exec-wrapper", class_run, unset_exec_wrapper_command, | 548 add_cmd ("exec-wrapper", class_run, unset_exec_wrapper_command, |
552 _("Disable use of an execution wrapper."), | 549 _("Disable use of an execution wrapper."), |
553 &unsetlist); | 550 &unsetlist); |
554 } | 551 } |
OLD | NEW |