1999-04-16 03:35:26 +02:00
|
|
|
/* Fork a Unix child process, and set up to debug it, for GDB.
|
2004-09-30 22:15:39 +02:00
|
|
|
|
2007-01-09 18:59:20 +01:00
|
|
|
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
|
2009-01-03 06:58:08 +01:00
|
|
|
2001, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
2004-09-30 22:15:39 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
Contributed by Cygnus Support.
|
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This file is part of GDB.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 20:08:50 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-07 22:19:36 +02:00
|
|
|
(at your option) any later version.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-04-16 03:35:26 +02:00
|
|
|
|
1999-07-07 22:19:36 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 20:08:50 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdb_string.h"
|
|
|
|
#include "inferior.h"
|
2009-05-19 04:46:45 +02:00
|
|
|
#include "terminal.h"
|
1999-04-16 03:35:26 +02:00
|
|
|
#include "target.h"
|
2000-02-09 09:52:47 +01:00
|
|
|
#include "gdb_wait.h"
|
2001-01-31 03:08:23 +01:00
|
|
|
#include "gdb_vfork.h"
|
1999-04-16 03:35:26 +02:00
|
|
|
#include "gdbcore.h"
|
|
|
|
#include "terminal.h"
|
|
|
|
#include "gdbthread.h"
|
1999-12-07 04:56:43 +01:00
|
|
|
#include "command.h" /* for dont_repeat () */
|
2008-03-11 00:14:06 +01:00
|
|
|
#include "gdbcmd.h"
|
* solib.h (CLEAR_SOLIB, SOLIB_ADD)
(SOLIB_CREATE_INFERIOR_HOOK, SOLIB_REMOVE_INFERIOR_HOOK)
(SOLIB_IN_DYNAMIC_LINKER, SOLIB_RESTART)
(DISABLE_UNSETTABLE_BREAK, PC_SOLIB)
(IN_SOLIB_DYNSYM_RESOLVE_CODE): Remove defines and orphaned
comments.
* breakpoint.c: Include "solib.h".
(insert_bp_location) [!DISABLE_UNSETTABLE_BREAK]: Call
solib_address.
(remove_solib_event_breakpoints, create_solib_event_breakpoint)
(disable_breakpoints_in_shlibs)
(disable_breakpoints_in_unloaded_shlib)
(re_enable_breakpoints_in_shlibs): Compile if SOLIB_ADD isn't
defined. If PC_SOLIB isn't defined, call solib_address.
(_initialize_breakpoint): Unconditionally install observer.
* corelow.c: Include "solib.h".
[SOLIB_ADD] (solib_add_stub): Remove prototype.
(core_close) [!CLEAR_SOLIB]: Call clear_solib.
(solib_add_stub) [!SOLIB_ADD] Call solib_add.
(core_open): Unconditionally call solib_add_stub.
* fork-child.c: Include "solib.h".
(fork_inferior) [!SOLIB_CREATE_INFERIOR_HOOK]: Call
solib_create_inferior_hook.
* infcmd.c: Include "solib.h".
(attach_command) [!SOLIB_ADD]: Call shlib_rescan. Unconditionally
call re_enable_breakpoints_in_shlibs.
* infrun.c: Include "solib.h".
(SOLIB_IN_SYNSYM_RESOLVE_CODE): Don't define if not already
defined.
(stop_on_solib_events, show_stop_on_solib_events): Include
unconditionally.
(follow_exec) [!SOLIB_CREATE_INFERIOR_HOOK]: Call
solib_create_inferior_hook.
(handle_inferior_event) [!SOLIB_ADD]: Call shlib_add.
[!IN_SOLIB_DYNSYM_RESOLVE_CODE]: Call in_solib_dynsym_resolve_code.
(_initialize_infrun): Unconditionally add "stop_on_solib-events"
command.
* remote.c: Include "solib.h".
(remote_open_1): Unconditionally call no_shared_libraries.
[!SOLIB_CREATE_INFERIOR_HOOK] Call solib_create_inferior_hook.
* stack.c: Include "solib.h".
(print_frame) [!PC_SOLIB] Call shlib_for_pc.
* xcoffsolib.c (no_shared_libraries): Remove function.
* Makefile.in (SFILES): Add solib.c.
(ALLDEPFILES): Remove solib.c.
(COMMON_OBS): Add solib.o.
(breakpoint.o, corelow.o, fork-chiled.o, infcmd.o, infrun.o)
(remote.o, stack.o): Update dependencies.
2005-05-12 22:21:18 +02:00
|
|
|
#include "solib.h"
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* This just gets used as a default if we can't find SHELL. */
|
1999-04-16 03:35:26 +02:00
|
|
|
#define SHELL_FILE "/bin/sh"
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
2008-03-11 00:14:06 +01:00
|
|
|
static char *exec_wrapper;
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Break up SCRATCH into an argument vector suitable for passing to
|
|
|
|
execvp and store it in ARGV. E.g., on "run a b c d" this routine
|
|
|
|
would get as input the string "a b c d", and as output it would
|
|
|
|
fill in ARGV with the four arguments "a", "b", "c", "d". */
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
static void
|
2000-07-30 03:48:28 +02:00
|
|
|
breakup_args (char *scratch, char **argv)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
char *cp = scratch;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Scan past leading separators */
|
|
|
|
while (*cp == ' ' || *cp == '\t' || *cp == '\n')
|
2004-09-30 22:15:39 +02:00
|
|
|
cp++;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Break if at end of string. */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (*cp == '\0')
|
|
|
|
break;
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Take an arg. */
|
1999-04-16 03:35:26 +02:00
|
|
|
*argv++ = cp;
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Scan for next arg separator. */
|
1999-04-16 03:35:26 +02:00
|
|
|
cp = strchr (cp, ' ');
|
|
|
|
if (cp == NULL)
|
|
|
|
cp = strchr (cp, '\t');
|
|
|
|
if (cp == NULL)
|
|
|
|
cp = strchr (cp, '\n');
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* No separators => end of string => break. */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (cp == NULL)
|
|
|
|
break;
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Replace the separator with a terminator. */
|
1999-04-16 03:35:26 +02:00
|
|
|
*cp++ = '\0';
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Null-terminate the vector. */
|
1999-04-16 03:35:26 +02:00
|
|
|
*argv = NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* When executing a command under the given shell, return non-zero if
|
|
|
|
the '!' character should be escaped when embedded in a quoted
|
2003-05-08 20:08:57 +02:00
|
|
|
command-line argument. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
escape_bang_in_quoted_argument (const char *shell_file)
|
|
|
|
{
|
|
|
|
const int shell_file_len = strlen (shell_file);
|
2004-09-30 22:15:39 +02:00
|
|
|
|
2003-05-08 20:08:57 +02:00
|
|
|
/* Bang should be escaped only in C Shells. For now, simply check
|
|
|
|
that the shell name ends with 'csh', which covers at least csh
|
|
|
|
and tcsh. This should be good enough for now. */
|
|
|
|
|
|
|
|
if (shell_file_len < 3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (shell_file[shell_file_len - 3] == 'c'
|
|
|
|
&& shell_file[shell_file_len - 2] == 's'
|
|
|
|
&& shell_file[shell_file_len - 1] == 'h')
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Start an inferior Unix child process and sets inferior_ptid to its
|
|
|
|
pid. EXEC_FILE is the file to run. ALLARGS is a string containing
|
|
|
|
the arguments to the program. ENV is the environment vector to
|
|
|
|
pass. SHELL_FILE is the shell file, or NULL if we should pick
|
|
|
|
one. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* This function is NOT reentrant. Some of the variables have been
|
|
|
|
made static to ensure that they survive the vfork call. */
|
2001-03-23 23:48:44 +01:00
|
|
|
|
Kill pthread_ops_hack
* target.h (struct target_ops): Make to_attach, to_detach,
to_create_inferior and to_mourn_inferior accept a pointer
to struct target_ops.
(target_attach, target_create_inferior, target_create_inferior):
Convert from macros to function. Find the right target to
invoke a method of.
(find_default_attach, find_default_create_inferior): New parameter
ops.
* corefile.c (core_file_command): Pass target to to_detach.
* corelow.c (core_detach): Add 'ops' parameter.
* fork-child.c (fork_inferior): Return the pid. Allow
init_trace_fun to be NULL.
* inf-ptrace (ptrace_ops_hack): Remove.
(inf_ptrace_him): Remove, moving all logic into....
(inf_ptrace_create_inferior): ... here. Push the target
passed as parameter.
(inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach):
Push/pop target passed as parameter, no ptrace_ops_hack.
(inf_ptrace_target): Don't remember result.
* inferior.h (fork_inferior): Adjust prototype.
* linux-nat.c (linux_nat_create_inferior, linux_nat_attach)
(linux_nat_detach, linux_nat_mourn_inferior): New parameter ops.
Pass it to linux_ops target.
* linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior):
New parameter ops. Pass it to the target beneath.
* remote.c (remote_mourn, extended_remote_mourn, remote_detach)
(extended_remote_create_inferior): New parameter ops. Pass it
further.
* target.c (debug_to_attach, debug_to_detach)
(debug_to_mourn_inferior): New parameter ops.
(target_create_inferior): New.
(update_current_target): Do not inherit to_attach, to_detach,
to_create_inferiour, to_mourn_inferior. Do not default
to_detach and to_mourn_inferior.
(target_detach): Find the right target to use.
(target_mourn_inferior): New.
(find_default_attach, find_default_create_inferior): New parameter
ops. Pass the found target when calling its method.
(init_dummy_target): Provide fallback definition of to_detach.
(target_attach): New.
(debug_to_attach, debug_to_detach, debug_to_create_inferior)
(debug_to_mourn_inferiour): New parameter ops.
* aix-thread.c: Adjust.
* bsd-uthread.c: Adjust.
* gnu-nat.c: Adjust.
* go32-nat.c: Adjust.
* hpux-thread.c: Adjust.
* inf-ttrace.c: Ajust.
* monitor.c: Adjust.
* nto-procfs.c: Adjust.
* procfs.c: Adjust.
* remote-m32r-sdi.c: Adjust.
* remote-mips.c: Adjust.
* remote-sim.c: Adjust.
* rs6000-nat.c: Adjust.
* sol-thread.c: Adjust.
* win32-nat.c: Adjust.
* dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
|
|
|
int
|
2001-03-23 23:48:44 +01:00
|
|
|
fork_inferior (char *exec_file_arg, char *allargs, char **env,
|
2000-08-23 18:37:23 +02:00
|
|
|
void (*traceme_fun) (void), void (*init_trace_fun) (int),
|
2001-03-23 23:48:44 +01:00
|
|
|
void (*pre_trace_fun) (void), char *shell_file_arg)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
char *shell_command;
|
|
|
|
static char default_shell_file[] = SHELL_FILE;
|
|
|
|
int len;
|
|
|
|
/* Set debug_fork then attach to the child while it sleeps, to debug. */
|
|
|
|
static int debug_fork = 0;
|
|
|
|
/* This is set to the result of setpgrp, which if vforked, will be visible
|
|
|
|
to you in the parent process. It's only used by humans for debugging. */
|
|
|
|
static int debug_setpgrp = 657473;
|
2001-03-23 23:48:44 +01:00
|
|
|
static char *shell_file;
|
|
|
|
static char *exec_file;
|
1999-04-16 03:35:26 +02:00
|
|
|
char **save_our_env;
|
|
|
|
int shell = 0;
|
2001-03-23 23:48:44 +01:00
|
|
|
static char **argv;
|
2005-07-06 16:54:37 +02:00
|
|
|
const char *inferior_io_terminal = get_inferior_io_terminal ();
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* If no exec file handed to us, get it from the exec-file command
|
|
|
|
-- with a good, common error message if none is specified. */
|
2001-03-23 23:48:44 +01:00
|
|
|
exec_file = exec_file_arg;
|
1999-04-16 03:35:26 +02:00
|
|
|
if (exec_file == 0)
|
|
|
|
exec_file = get_exec_file (1);
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* STARTUP_WITH_SHELL is defined in inferior.h. If 0,e we'll just
|
|
|
|
do a fork/exec, no shell, so don't bother figuring out what
|
|
|
|
shell. */
|
2001-03-23 23:48:44 +01:00
|
|
|
shell_file = shell_file_arg;
|
1999-04-16 03:35:26 +02:00
|
|
|
if (STARTUP_WITH_SHELL)
|
|
|
|
{
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Figure out what shell to start up the user program under. */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (shell_file == NULL)
|
|
|
|
shell_file = getenv ("SHELL");
|
|
|
|
if (shell_file == NULL)
|
|
|
|
shell_file = default_shell_file;
|
|
|
|
shell = 1;
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Multiplying the length of exec_file by 4 is to account for the
|
|
|
|
fact that it may expand when quoted; it is a worst-case number
|
|
|
|
based on every character being '. */
|
1999-07-07 22:19:36 +02:00
|
|
|
len = 5 + 4 * strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop */ 12;
|
2008-03-11 00:14:06 +01:00
|
|
|
if (exec_wrapper)
|
|
|
|
len += strlen (exec_wrapper) + 1;
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
shell_command = (char *) alloca (len);
|
|
|
|
shell_command[0] = '\0';
|
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
{
|
2004-09-30 22:15:39 +02:00
|
|
|
/* We're going to call execvp. Create argument vector.
|
|
|
|
Calculate an upper bound on the length of the vector by
|
|
|
|
assuming that every other character is a separate
|
|
|
|
argument. */
|
|
|
|
int argc = (strlen (allargs) + 1) / 2 + 2;
|
|
|
|
argv = (char **) xmalloc (argc * sizeof (*argv));
|
1999-04-16 03:35:26 +02:00
|
|
|
argv[0] = exec_file;
|
|
|
|
breakup_args (allargs, &argv[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-30 22:15:39 +02:00
|
|
|
/* We're going to call a shell. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
char *p;
|
|
|
|
int need_to_quote;
|
2003-05-08 20:08:57 +02:00
|
|
|
const int escape_bang = escape_bang_in_quoted_argument (shell_file);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
strcat (shell_command, "exec ");
|
|
|
|
|
2008-03-11 00:14:06 +01:00
|
|
|
/* Add any exec wrapper. That may be a program name with arguments, so
|
|
|
|
the user must handle quoting. */
|
|
|
|
if (exec_wrapper)
|
|
|
|
{
|
|
|
|
strcat (shell_command, exec_wrapper);
|
|
|
|
strcat (shell_command, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now add exec_file, quoting as necessary. */
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Quoting in this style is said to work with all shells. But
|
|
|
|
csh on IRIX 4.0.1 can't deal with it. So we only quote it if
|
|
|
|
we need to. */
|
1999-04-16 03:35:26 +02:00
|
|
|
p = exec_file;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case '\'':
|
2002-02-07 07:11:55 +01:00
|
|
|
case '!':
|
1999-04-16 03:35:26 +02:00
|
|
|
case '"':
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case '$':
|
|
|
|
case '&':
|
|
|
|
case ';':
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
case ' ':
|
|
|
|
case '\n':
|
|
|
|
case '\t':
|
|
|
|
need_to_quote = 1;
|
|
|
|
goto end_scan;
|
|
|
|
|
|
|
|
case '\0':
|
|
|
|
need_to_quote = 0;
|
|
|
|
goto end_scan;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
end_scan:
|
|
|
|
if (need_to_quote)
|
|
|
|
{
|
|
|
|
strcat (shell_command, "'");
|
|
|
|
for (p = exec_file; *p != '\0'; ++p)
|
|
|
|
{
|
|
|
|
if (*p == '\'')
|
|
|
|
strcat (shell_command, "'\\''");
|
2003-05-08 20:08:57 +02:00
|
|
|
else if (*p == '!' && escape_bang)
|
2002-02-07 07:11:55 +01:00
|
|
|
strcat (shell_command, "\\!");
|
1999-04-16 03:35:26 +02:00
|
|
|
else
|
|
|
|
strncat (shell_command, p, 1);
|
|
|
|
}
|
|
|
|
strcat (shell_command, "'");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcat (shell_command, exec_file);
|
|
|
|
|
|
|
|
strcat (shell_command, " ");
|
|
|
|
strcat (shell_command, allargs);
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* On some systems an exec will fail if the executable is open. */
|
1999-04-16 03:35:26 +02:00
|
|
|
close_exec_file ();
|
|
|
|
|
|
|
|
/* Retain a copy of our environment variables, since the child will
|
2004-09-30 22:15:39 +02:00
|
|
|
replace the value of environ and if we're vforked, we have to
|
1999-04-16 03:35:26 +02:00
|
|
|
restore it. */
|
|
|
|
save_our_env = environ;
|
|
|
|
|
|
|
|
/* Tell the terminal handling subsystem what tty we plan to run on;
|
|
|
|
it will just record the information for later. */
|
|
|
|
new_tty_prefork (inferior_io_terminal);
|
|
|
|
|
|
|
|
/* It is generally good practice to flush any possible pending stdio
|
2004-09-30 22:15:39 +02:00
|
|
|
output prior to doing a fork, to avoid the possibility of both
|
|
|
|
the parent and child flushing the same data after the fork. */
|
1999-04-16 03:35:26 +02:00
|
|
|
gdb_flush (gdb_stdout);
|
|
|
|
gdb_flush (gdb_stderr);
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* If there's any initialization of the target layers that must
|
|
|
|
happen to prepare to handle the child we're about fork, do it
|
|
|
|
now... */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (pre_trace_fun != NULL)
|
|
|
|
(*pre_trace_fun) ();
|
|
|
|
|
2004-11-29 09:37:14 +01:00
|
|
|
/* Create the child process. Since the child process is going to
|
2006-09-07 18:22:57 +02:00
|
|
|
exec(3) shortly afterwards, try to reduce the overhead by
|
2004-11-29 09:37:14 +01:00
|
|
|
calling vfork(2). However, if PRE_TRACE_FUN is non-null, it's
|
|
|
|
likely that this optimization won't work since there's too much
|
|
|
|
work to do between the vfork(2) and the exec(3). This is known
|
|
|
|
to be the case on ttrace(2)-based HP-UX, where some handshaking
|
|
|
|
between parent and child needs to happen between fork(2) and
|
|
|
|
exec(2). However, since the parent is suspended in the vforked
|
|
|
|
state, this doesn't work. Also note that the vfork(2) call might
|
|
|
|
actually be a call to fork(2) due to the fact that autoconf will
|
|
|
|
``#define vfork fork'' on certain platforms. */
|
|
|
|
if (pre_trace_fun || debug_fork)
|
1999-04-16 03:35:26 +02:00
|
|
|
pid = fork ();
|
|
|
|
else
|
|
|
|
pid = vfork ();
|
|
|
|
|
|
|
|
if (pid < 0)
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 19:13:55 +01:00
|
|
|
perror_with_name (("vfork"));
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
if (debug_fork)
|
|
|
|
sleep (debug_fork);
|
|
|
|
|
2008-03-12 15:10:56 +01:00
|
|
|
/* Create a new session for the inferior process, if necessary.
|
|
|
|
It will also place the inferior in a separate process group. */
|
|
|
|
if (create_tty_session () <= 0)
|
|
|
|
{
|
|
|
|
/* No session was created, but we still want to run the inferior
|
|
|
|
in a separate process group. */
|
|
|
|
debug_setpgrp = gdb_setpgid ();
|
|
|
|
if (debug_setpgrp == -1)
|
|
|
|
perror ("setpgrp failed in child");
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Ask the tty subsystem to switch to the one we specified
|
|
|
|
earlier (or to share the current terminal, if none was
|
|
|
|
specified). */
|
1999-04-16 03:35:26 +02:00
|
|
|
new_tty ();
|
|
|
|
|
|
|
|
/* Changing the signal handlers for the inferior after
|
1999-07-07 22:19:36 +02:00
|
|
|
a vfork can also change them for the superior, so we don't mess
|
|
|
|
with signals here. See comments in
|
|
|
|
initialize_signals for how we get the right signal handlers
|
|
|
|
for the inferior. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/* "Trace me, Dr. Memory!" */
|
|
|
|
(*traceme_fun) ();
|
2004-09-30 22:15:39 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/* The call above set this process (the "child") as debuggable
|
2004-09-30 22:15:39 +02:00
|
|
|
by the original gdb process (the "parent"). Since processes
|
|
|
|
(unlike people) can have only one parent, if you are debugging
|
|
|
|
gdb itself (and your debugger is thus _already_ the
|
|
|
|
controller/parent for this child), code from here on out is
|
|
|
|
undebuggable. Indeed, you probably got an error message
|
|
|
|
saying "not parent". Sorry; you'll have to use print
|
|
|
|
statements! */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/* There is no execlpe call, so we have to set the environment
|
1999-07-07 22:19:36 +02:00
|
|
|
for our child in the global variable. If we've vforked, this
|
|
|
|
clobbers the parent, but environ is restored a few lines down
|
|
|
|
in the parent. By the way, yes we do need to look down the
|
|
|
|
path to find $SHELL. Rich Pixley says so, and I agree. */
|
1999-04-16 03:35:26 +02:00
|
|
|
environ = env;
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* If we decided above to start up with a shell, we exec the
|
2007-06-13 21:05:00 +02:00
|
|
|
shell, "-c" says to interpret the next arg as a shell command
|
|
|
|
to execute, and this command is "exec <target-program>
|
|
|
|
<args>". */
|
1999-04-16 03:35:26 +02:00
|
|
|
if (shell)
|
|
|
|
{
|
|
|
|
execlp (shell_file, shell_file, "-c", shell_command, (char *) 0);
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* If we get here, it's an error. */
|
1999-04-16 03:35:26 +02:00
|
|
|
fprintf_unfiltered (gdb_stderr, "Cannot exec %s: %s.\n", shell_file,
|
|
|
|
safe_strerror (errno));
|
|
|
|
gdb_flush (gdb_stderr);
|
|
|
|
_exit (0177);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Otherwise, we directly exec the target program with
|
|
|
|
execvp. */
|
1999-04-16 03:35:26 +02:00
|
|
|
int i;
|
|
|
|
char *errstring;
|
1999-06-07 21:19:32 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
execvp (exec_file, argv);
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* If we get here, it's an error. */
|
1999-04-16 03:35:26 +02:00
|
|
|
errstring = safe_strerror (errno);
|
|
|
|
fprintf_unfiltered (gdb_stderr, "Cannot exec %s ", exec_file);
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (argv[i] != NULL)
|
|
|
|
{
|
|
|
|
if (i != 1)
|
|
|
|
fprintf_unfiltered (gdb_stderr, " ");
|
|
|
|
fprintf_unfiltered (gdb_stderr, "%s", argv[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
fprintf_unfiltered (gdb_stderr, ".\n");
|
2004-09-30 22:15:39 +02:00
|
|
|
#if 0
|
|
|
|
/* This extra info seems to be useless. */
|
|
|
|
fprintf_unfiltered (gdb_stderr, "Got error %s.\n", errstring);
|
|
|
|
#endif
|
1999-04-16 03:35:26 +02:00
|
|
|
gdb_flush (gdb_stderr);
|
|
|
|
_exit (0177);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore our environment in case a vforked child clob'd it. */
|
|
|
|
environ = save_our_env;
|
|
|
|
|
* fork-child.c (fork_inferior): Only reset the thread list if this
is the first inferior.
(startup_inferior): If the target support multi-process, tell it
to resume only the new process.
* linux-nat.c (num_lwps): Delete global.
(purge_lwp_list): New function.
(num_lwps): New function.
(add_lwp, delete_lwp): Adjust.
(ptid_match): New.
(iterate_over_lwps): Add filter argument. Handle it.
(linux_nat_attach): Remove FIXME note.
(linux_nat_detach): Adjust to iterate over threads of the inferior
we're detaching from. Adjust to num_lwps being a function. Don't
assume the head of the lwp list is the main thread of the process
we're detaching from. Don't destroy the LWP list.
(resume_callback): Add debug output.
(linux_nat_resume): Handle resuming a single inferior. Allow a
wildcard resume in non-stop mode.
(linux_handle_extended_wait): Don't assume inferior_ptid is the
correct inferior of the parent LWP.
(status_callback): Also check lp->waitstatus.
(select_event_lwp): Add new filter parameter. Handle it.
(linux_nat_filter_event): Adjust to num_lwps being a function.
(linux_nat_wait_1): When adding the first lwp of the inferior, use
an is_lwp check instead of checking for the number of lwps.
(linux_nat_wait_1): Handle waiting for a specific tgid. Handle
pending process exit statuses.
(linux_nat_mourn_inferior): Don't destroy all the LWP info.
Instead delete LWPs of the inferior that we're mourning. Don't
unregister from the event loop here.
(linux_nat_pid_to_str): Use `num_lwps'.
(linux_nat_make_corefile_notes): Adjust to walk over lwps of a
single inferior.
(linux_nat_is_async_p): Check if async was masked out.
(linux_multi_process): New global.
(linux_nat_supports_multi_process): New.
(linux_nat_stop_lwp): Remove LWP filtering. It is done by the
caller.
(linux_nat_stop): Adjust to make iterate_over_lwps itself do the
LWP filtering.
(linux_nat_close): New.
(linux_nat_add_target): Register linux_nat_close and
linux_nat_supports_multi_process.
* linux-nat.h (iterate_over_lwps): Add filter argument.
* linux-thread-db.c (thread_db_handle): Delete.
(proc_handle, thread_agent, td_init_p, td_ta_new_p)
(td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p)
(td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p)
(td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p)
(td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No
longer globals, moved to...
(struct thread_db_info): ... this new structure.
(thread_db_list): New.
(add_thread_db_info, get_thread_db_info, delete_thread_db_info):
New.
(have_threads_callback): Filter out threads of all inferiors but
the one specified by the ARGS argument.
(have_threads): Add ptid argument specifying the inferior we're
interested in. Handle it.
(struct thread_get_info_inout): New.
(thread_get_info_callback, thread_from_lwp): Adjust to use it.
(thread_db_attach_lwp): Check that inferior of the passed in
thread is using thread-db. Adjust.
(enable_thread_event): Remove thread_agent parameter. Instead,
get it from the per-inferior thread-db info.
(dladdr_to_soname): Move higher up.
(enable_thread_event_reporting): Adjust to use per-inferior
thread-db info.
(try_thread_db_load_1): Replace `handle' parameter by a
thread_db_info parameter. Adjust to use per-inferior thread-db
info.
(try_thread_db_load): Adjust to use per-inferior thread-db info.
(thread_db_load, disable_thread_event_reporting): Ditto.
(check_for_thread_db): Remove conditional reporting of which
libthread_db is in use.
(thread_db_new_objfile): Add comment about inferior_ptid.
(attach_thread): Adjust to use per-inferior thread-db info.
(thread_db_detach): Adjust to use per-inferior thread-db info.
Remove thread event breakpoints of the current inferior. Only
unpush the thread-db target if there are no more processes using
it.
(check_event): Adjust to use per-inferior thread-db info.
(thread_db_wait): Adjust to use per-inferior thread-db info. Only
unpush the thread-db target if there are no more processes using
it.
(thread_db_mourn_inferior): Adjust to use per-inferior thread-db
info. Mark breakpoints of the current inferior out before
deleting them. Only unpush the thread-db target if there are no
more processes using it.
(find_new_threads_callback): Adjust to use per-inferior thread_db
info.
(thread_db_find_new_threads_1): Add new ptid argument. Adjust to
use per-inferior thread-db info.
(thread_db_find_new_threads): Adjust to use per-inferior thread-db
info.
(thread_db_get_thread_local_address): Adjust.
(thread_db_get_ada_task_ptid): Adjust.
* inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target
if there no more processes left to debug.
* thread.c (set_running, set_executing): Handle resuming all
threads of a single inferior.
* mi/mi-interp.c (mi_output_running_pid): New.
(mi_inferior_count): New.
(mi_on_resume): For backwards compatibility, if resuming all
threads of an inferior, and there is only one inferior, output
"all".
2009-05-18 16:07:18 +02:00
|
|
|
if (!have_inferiors ())
|
|
|
|
init_thread_list ();
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2008-09-22 17:16:51 +02:00
|
|
|
add_inferior (pid);
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Needed for wait_for_inferior stuff below. */
|
|
|
|
inferior_ptid = pid_to_ptid (pid);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2009-05-19 04:46:45 +02:00
|
|
|
new_tty_postfork ();
|
|
|
|
|
2008-09-08 23:22:49 +02:00
|
|
|
/* We have something that executes now. We'll be running through
|
|
|
|
the shell at this point, but the pid shouldn't change. Targets
|
|
|
|
supporting MT should fill this task's ptid with more data as soon
|
|
|
|
as they can. */
|
|
|
|
add_thread_silent (inferior_ptid);
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
/* Now that we have a child process, make it our target, and
|
2004-09-30 22:15:39 +02:00
|
|
|
initialize anything target-vector-specific that needs
|
|
|
|
initializing. */
|
Kill pthread_ops_hack
* target.h (struct target_ops): Make to_attach, to_detach,
to_create_inferior and to_mourn_inferior accept a pointer
to struct target_ops.
(target_attach, target_create_inferior, target_create_inferior):
Convert from macros to function. Find the right target to
invoke a method of.
(find_default_attach, find_default_create_inferior): New parameter
ops.
* corefile.c (core_file_command): Pass target to to_detach.
* corelow.c (core_detach): Add 'ops' parameter.
* fork-child.c (fork_inferior): Return the pid. Allow
init_trace_fun to be NULL.
* inf-ptrace (ptrace_ops_hack): Remove.
(inf_ptrace_him): Remove, moving all logic into....
(inf_ptrace_create_inferior): ... here. Push the target
passed as parameter.
(inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach):
Push/pop target passed as parameter, no ptrace_ops_hack.
(inf_ptrace_target): Don't remember result.
* inferior.h (fork_inferior): Adjust prototype.
* linux-nat.c (linux_nat_create_inferior, linux_nat_attach)
(linux_nat_detach, linux_nat_mourn_inferior): New parameter ops.
Pass it to linux_ops target.
* linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior):
New parameter ops. Pass it to the target beneath.
* remote.c (remote_mourn, extended_remote_mourn, remote_detach)
(extended_remote_create_inferior): New parameter ops. Pass it
further.
* target.c (debug_to_attach, debug_to_detach)
(debug_to_mourn_inferior): New parameter ops.
(target_create_inferior): New.
(update_current_target): Do not inherit to_attach, to_detach,
to_create_inferiour, to_mourn_inferior. Do not default
to_detach and to_mourn_inferior.
(target_detach): Find the right target to use.
(target_mourn_inferior): New.
(find_default_attach, find_default_create_inferior): New parameter
ops. Pass the found target when calling its method.
(init_dummy_target): Provide fallback definition of to_detach.
(target_attach): New.
(debug_to_attach, debug_to_detach, debug_to_create_inferior)
(debug_to_mourn_inferiour): New parameter ops.
* aix-thread.c: Adjust.
* bsd-uthread.c: Adjust.
* gnu-nat.c: Adjust.
* go32-nat.c: Adjust.
* hpux-thread.c: Adjust.
* inf-ttrace.c: Ajust.
* monitor.c: Adjust.
* nto-procfs.c: Adjust.
* procfs.c: Adjust.
* remote-m32r-sdi.c: Adjust.
* remote-mips.c: Adjust.
* remote-sim.c: Adjust.
* rs6000-nat.c: Adjust.
* sol-thread.c: Adjust.
* win32-nat.c: Adjust.
* dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
|
|
|
if (init_trace_fun)
|
|
|
|
(*init_trace_fun) (pid);
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/* We are now in the child process of interest, having exec'd the
|
|
|
|
correct program, and are poised at the first instruction of the
|
|
|
|
new program. */
|
Kill pthread_ops_hack
* target.h (struct target_ops): Make to_attach, to_detach,
to_create_inferior and to_mourn_inferior accept a pointer
to struct target_ops.
(target_attach, target_create_inferior, target_create_inferior):
Convert from macros to function. Find the right target to
invoke a method of.
(find_default_attach, find_default_create_inferior): New parameter
ops.
* corefile.c (core_file_command): Pass target to to_detach.
* corelow.c (core_detach): Add 'ops' parameter.
* fork-child.c (fork_inferior): Return the pid. Allow
init_trace_fun to be NULL.
* inf-ptrace (ptrace_ops_hack): Remove.
(inf_ptrace_him): Remove, moving all logic into....
(inf_ptrace_create_inferior): ... here. Push the target
passed as parameter.
(inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach):
Push/pop target passed as parameter, no ptrace_ops_hack.
(inf_ptrace_target): Don't remember result.
* inferior.h (fork_inferior): Adjust prototype.
* linux-nat.c (linux_nat_create_inferior, linux_nat_attach)
(linux_nat_detach, linux_nat_mourn_inferior): New parameter ops.
Pass it to linux_ops target.
* linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior):
New parameter ops. Pass it to the target beneath.
* remote.c (remote_mourn, extended_remote_mourn, remote_detach)
(extended_remote_create_inferior): New parameter ops. Pass it
further.
* target.c (debug_to_attach, debug_to_detach)
(debug_to_mourn_inferior): New parameter ops.
(target_create_inferior): New.
(update_current_target): Do not inherit to_attach, to_detach,
to_create_inferiour, to_mourn_inferior. Do not default
to_detach and to_mourn_inferior.
(target_detach): Find the right target to use.
(target_mourn_inferior): New.
(find_default_attach, find_default_create_inferior): New parameter
ops. Pass the found target when calling its method.
(init_dummy_target): Provide fallback definition of to_detach.
(target_attach): New.
(debug_to_attach, debug_to_detach, debug_to_create_inferior)
(debug_to_mourn_inferiour): New parameter ops.
* aix-thread.c: Adjust.
* bsd-uthread.c: Adjust.
* gnu-nat.c: Adjust.
* go32-nat.c: Adjust.
* hpux-thread.c: Adjust.
* inf-ttrace.c: Ajust.
* monitor.c: Adjust.
* nto-procfs.c: Adjust.
* procfs.c: Adjust.
* remote-m32r-sdi.c: Adjust.
* remote-mips.c: Adjust.
* remote-sim.c: Adjust.
* rs6000-nat.c: Adjust.
* sol-thread.c: Adjust.
* win32-nat.c: Adjust.
* dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
|
|
|
return pid;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Accept NTRAPS traps from the inferior. */
|
|
|
|
|
|
|
|
void
|
2000-07-30 03:48:28 +02:00
|
|
|
startup_inferior (int ntraps)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
|
|
|
int pending_execs = ntraps;
|
2004-09-30 22:15:39 +02:00
|
|
|
int terminal_initted = 0;
|
* fork-child.c (fork_inferior): Only reset the thread list if this
is the first inferior.
(startup_inferior): If the target support multi-process, tell it
to resume only the new process.
* linux-nat.c (num_lwps): Delete global.
(purge_lwp_list): New function.
(num_lwps): New function.
(add_lwp, delete_lwp): Adjust.
(ptid_match): New.
(iterate_over_lwps): Add filter argument. Handle it.
(linux_nat_attach): Remove FIXME note.
(linux_nat_detach): Adjust to iterate over threads of the inferior
we're detaching from. Adjust to num_lwps being a function. Don't
assume the head of the lwp list is the main thread of the process
we're detaching from. Don't destroy the LWP list.
(resume_callback): Add debug output.
(linux_nat_resume): Handle resuming a single inferior. Allow a
wildcard resume in non-stop mode.
(linux_handle_extended_wait): Don't assume inferior_ptid is the
correct inferior of the parent LWP.
(status_callback): Also check lp->waitstatus.
(select_event_lwp): Add new filter parameter. Handle it.
(linux_nat_filter_event): Adjust to num_lwps being a function.
(linux_nat_wait_1): When adding the first lwp of the inferior, use
an is_lwp check instead of checking for the number of lwps.
(linux_nat_wait_1): Handle waiting for a specific tgid. Handle
pending process exit statuses.
(linux_nat_mourn_inferior): Don't destroy all the LWP info.
Instead delete LWPs of the inferior that we're mourning. Don't
unregister from the event loop here.
(linux_nat_pid_to_str): Use `num_lwps'.
(linux_nat_make_corefile_notes): Adjust to walk over lwps of a
single inferior.
(linux_nat_is_async_p): Check if async was masked out.
(linux_multi_process): New global.
(linux_nat_supports_multi_process): New.
(linux_nat_stop_lwp): Remove LWP filtering. It is done by the
caller.
(linux_nat_stop): Adjust to make iterate_over_lwps itself do the
LWP filtering.
(linux_nat_close): New.
(linux_nat_add_target): Register linux_nat_close and
linux_nat_supports_multi_process.
* linux-nat.h (iterate_over_lwps): Add filter argument.
* linux-thread-db.c (thread_db_handle): Delete.
(proc_handle, thread_agent, td_init_p, td_ta_new_p)
(td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p)
(td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p)
(td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p)
(td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No
longer globals, moved to...
(struct thread_db_info): ... this new structure.
(thread_db_list): New.
(add_thread_db_info, get_thread_db_info, delete_thread_db_info):
New.
(have_threads_callback): Filter out threads of all inferiors but
the one specified by the ARGS argument.
(have_threads): Add ptid argument specifying the inferior we're
interested in. Handle it.
(struct thread_get_info_inout): New.
(thread_get_info_callback, thread_from_lwp): Adjust to use it.
(thread_db_attach_lwp): Check that inferior of the passed in
thread is using thread-db. Adjust.
(enable_thread_event): Remove thread_agent parameter. Instead,
get it from the per-inferior thread-db info.
(dladdr_to_soname): Move higher up.
(enable_thread_event_reporting): Adjust to use per-inferior
thread-db info.
(try_thread_db_load_1): Replace `handle' parameter by a
thread_db_info parameter. Adjust to use per-inferior thread-db
info.
(try_thread_db_load): Adjust to use per-inferior thread-db info.
(thread_db_load, disable_thread_event_reporting): Ditto.
(check_for_thread_db): Remove conditional reporting of which
libthread_db is in use.
(thread_db_new_objfile): Add comment about inferior_ptid.
(attach_thread): Adjust to use per-inferior thread-db info.
(thread_db_detach): Adjust to use per-inferior thread-db info.
Remove thread event breakpoints of the current inferior. Only
unpush the thread-db target if there are no more processes using
it.
(check_event): Adjust to use per-inferior thread-db info.
(thread_db_wait): Adjust to use per-inferior thread-db info. Only
unpush the thread-db target if there are no more processes using
it.
(thread_db_mourn_inferior): Adjust to use per-inferior thread-db
info. Mark breakpoints of the current inferior out before
deleting them. Only unpush the thread-db target if there are no
more processes using it.
(find_new_threads_callback): Adjust to use per-inferior thread_db
info.
(thread_db_find_new_threads_1): Add new ptid argument. Adjust to
use per-inferior thread-db info.
(thread_db_find_new_threads): Adjust to use per-inferior thread-db
info.
(thread_db_get_thread_local_address): Adjust.
(thread_db_get_ada_task_ptid): Adjust.
* inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target
if there no more processes left to debug.
* thread.c (set_running, set_executing): Handle resuming all
threads of a single inferior.
* mi/mi-interp.c (mi_output_running_pid): New.
(mi_inferior_count): New.
(mi_on_resume): For backwards compatibility, if resuming all
threads of an inferior, and there is only one inferior, output
"all".
2009-05-18 16:07:18 +02:00
|
|
|
ptid_t resume_ptid;
|
|
|
|
|
|
|
|
if (target_supports_multi_process ())
|
|
|
|
resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
|
|
|
|
else
|
|
|
|
resume_ptid = minus_one_ptid;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
/* The process was started by the fork that created it, but it will
|
|
|
|
have stopped one instruction after execing the shell. Here we
|
|
|
|
must get it up to actual execution of the real program. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2008-03-11 00:14:06 +01:00
|
|
|
if (exec_wrapper)
|
|
|
|
pending_execs++;
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2008-09-11 18:09:33 +02:00
|
|
|
int resume_signal = TARGET_SIGNAL_0;
|
2008-10-25 00:01:25 +02:00
|
|
|
ptid_t event_ptid;
|
2008-09-11 18:09:33 +02:00
|
|
|
|
|
|
|
struct target_waitstatus ws;
|
|
|
|
memset (&ws, 0, sizeof (ws));
|
2009-05-21 17:48:42 +02:00
|
|
|
event_ptid = target_wait (resume_ptid, &ws, 0);
|
2008-09-11 18:09:33 +02:00
|
|
|
|
2008-10-25 00:01:25 +02:00
|
|
|
if (ws.kind == TARGET_WAITKIND_IGNORE)
|
|
|
|
/* The inferior didn't really stop, keep waiting. */
|
|
|
|
continue;
|
2008-09-11 18:09:33 +02:00
|
|
|
|
|
|
|
switch (ws.kind)
|
|
|
|
{
|
|
|
|
case TARGET_WAITKIND_SPURIOUS:
|
|
|
|
case TARGET_WAITKIND_LOADED:
|
|
|
|
case TARGET_WAITKIND_FORKED:
|
|
|
|
case TARGET_WAITKIND_VFORKED:
|
|
|
|
case TARGET_WAITKIND_SYSCALL_ENTRY:
|
|
|
|
case TARGET_WAITKIND_SYSCALL_RETURN:
|
|
|
|
/* Ignore gracefully during startup of the inferior. */
|
2008-10-25 00:01:25 +02:00
|
|
|
switch_to_thread (event_ptid);
|
2008-09-11 18:09:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TARGET_WAITKIND_SIGNALLED:
|
|
|
|
target_terminal_ours ();
|
|
|
|
target_mourn_inferior ();
|
|
|
|
error (_("During startup program terminated with signal %s, %s."),
|
|
|
|
target_signal_to_name (ws.value.sig),
|
|
|
|
target_signal_to_string (ws.value.sig));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TARGET_WAITKIND_EXITED:
|
|
|
|
target_terminal_ours ();
|
|
|
|
target_mourn_inferior ();
|
|
|
|
if (ws.value.integer)
|
|
|
|
error (_("During startup program exited with code %d."),
|
|
|
|
ws.value.integer);
|
|
|
|
else
|
|
|
|
error (_("During startup program exited normally."));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TARGET_WAITKIND_EXECD:
|
|
|
|
/* Handle EXEC signals as if they were SIGTRAP signals. */
|
|
|
|
xfree (ws.value.execd_pathname);
|
|
|
|
resume_signal = TARGET_SIGNAL_TRAP;
|
2008-10-25 00:01:25 +02:00
|
|
|
switch_to_thread (event_ptid);
|
2008-09-11 18:09:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TARGET_WAITKIND_STOPPED:
|
|
|
|
resume_signal = ws.value.sig;
|
2008-10-25 00:01:25 +02:00
|
|
|
switch_to_thread (event_ptid);
|
2008-09-11 18:09:33 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-09-08 23:51:18 +02:00
|
|
|
|
2008-09-11 18:09:33 +02:00
|
|
|
if (resume_signal != TARGET_SIGNAL_TRAP)
|
1999-04-16 03:35:26 +02:00
|
|
|
{
|
2008-09-11 18:09:33 +02:00
|
|
|
/* Let shell child handle its own signals in its own way. */
|
|
|
|
target_resume (resume_ptid, 0, resume_signal);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We handle SIGTRAP, however; it means child did an exec. */
|
|
|
|
if (!terminal_initted)
|
|
|
|
{
|
2004-09-30 22:15:39 +02:00
|
|
|
/* Now that the child has exec'd we know it has already
|
|
|
|
set its process group. On POSIX systems, tcsetpgrp
|
|
|
|
will fail with EPERM if we try it before the child's
|
|
|
|
setpgid. */
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
/* Set up the "saved terminal modes" of the inferior
|
1999-07-07 22:19:36 +02:00
|
|
|
based on what modes we are starting it with. */
|
1999-04-16 03:35:26 +02:00
|
|
|
target_terminal_init ();
|
|
|
|
|
|
|
|
/* Install inferior's terminal modes. */
|
|
|
|
target_terminal_inferior ();
|
|
|
|
|
|
|
|
terminal_initted = 1;
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:15:39 +02:00
|
|
|
if (--pending_execs == 0)
|
1999-04-16 03:35:26 +02:00
|
|
|
break;
|
|
|
|
|
2008-09-11 18:09:33 +02:00
|
|
|
/* Just make it go on. */
|
|
|
|
target_resume (resume_ptid, 0, TARGET_SIGNAL_0);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-25 00:01:25 +02:00
|
|
|
|
|
|
|
/* Mark all threads non-executing. */
|
* fork-child.c (fork_inferior): Only reset the thread list if this
is the first inferior.
(startup_inferior): If the target support multi-process, tell it
to resume only the new process.
* linux-nat.c (num_lwps): Delete global.
(purge_lwp_list): New function.
(num_lwps): New function.
(add_lwp, delete_lwp): Adjust.
(ptid_match): New.
(iterate_over_lwps): Add filter argument. Handle it.
(linux_nat_attach): Remove FIXME note.
(linux_nat_detach): Adjust to iterate over threads of the inferior
we're detaching from. Adjust to num_lwps being a function. Don't
assume the head of the lwp list is the main thread of the process
we're detaching from. Don't destroy the LWP list.
(resume_callback): Add debug output.
(linux_nat_resume): Handle resuming a single inferior. Allow a
wildcard resume in non-stop mode.
(linux_handle_extended_wait): Don't assume inferior_ptid is the
correct inferior of the parent LWP.
(status_callback): Also check lp->waitstatus.
(select_event_lwp): Add new filter parameter. Handle it.
(linux_nat_filter_event): Adjust to num_lwps being a function.
(linux_nat_wait_1): When adding the first lwp of the inferior, use
an is_lwp check instead of checking for the number of lwps.
(linux_nat_wait_1): Handle waiting for a specific tgid. Handle
pending process exit statuses.
(linux_nat_mourn_inferior): Don't destroy all the LWP info.
Instead delete LWPs of the inferior that we're mourning. Don't
unregister from the event loop here.
(linux_nat_pid_to_str): Use `num_lwps'.
(linux_nat_make_corefile_notes): Adjust to walk over lwps of a
single inferior.
(linux_nat_is_async_p): Check if async was masked out.
(linux_multi_process): New global.
(linux_nat_supports_multi_process): New.
(linux_nat_stop_lwp): Remove LWP filtering. It is done by the
caller.
(linux_nat_stop): Adjust to make iterate_over_lwps itself do the
LWP filtering.
(linux_nat_close): New.
(linux_nat_add_target): Register linux_nat_close and
linux_nat_supports_multi_process.
* linux-nat.h (iterate_over_lwps): Add filter argument.
* linux-thread-db.c (thread_db_handle): Delete.
(proc_handle, thread_agent, td_init_p, td_ta_new_p)
(td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p)
(td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p)
(td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p)
(td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No
longer globals, moved to...
(struct thread_db_info): ... this new structure.
(thread_db_list): New.
(add_thread_db_info, get_thread_db_info, delete_thread_db_info):
New.
(have_threads_callback): Filter out threads of all inferiors but
the one specified by the ARGS argument.
(have_threads): Add ptid argument specifying the inferior we're
interested in. Handle it.
(struct thread_get_info_inout): New.
(thread_get_info_callback, thread_from_lwp): Adjust to use it.
(thread_db_attach_lwp): Check that inferior of the passed in
thread is using thread-db. Adjust.
(enable_thread_event): Remove thread_agent parameter. Instead,
get it from the per-inferior thread-db info.
(dladdr_to_soname): Move higher up.
(enable_thread_event_reporting): Adjust to use per-inferior
thread-db info.
(try_thread_db_load_1): Replace `handle' parameter by a
thread_db_info parameter. Adjust to use per-inferior thread-db
info.
(try_thread_db_load): Adjust to use per-inferior thread-db info.
(thread_db_load, disable_thread_event_reporting): Ditto.
(check_for_thread_db): Remove conditional reporting of which
libthread_db is in use.
(thread_db_new_objfile): Add comment about inferior_ptid.
(attach_thread): Adjust to use per-inferior thread-db info.
(thread_db_detach): Adjust to use per-inferior thread-db info.
Remove thread event breakpoints of the current inferior. Only
unpush the thread-db target if there are no more processes using
it.
(check_event): Adjust to use per-inferior thread-db info.
(thread_db_wait): Adjust to use per-inferior thread-db info. Only
unpush the thread-db target if there are no more processes using
it.
(thread_db_mourn_inferior): Adjust to use per-inferior thread-db
info. Mark breakpoints of the current inferior out before
deleting them. Only unpush the thread-db target if there are no
more processes using it.
(find_new_threads_callback): Adjust to use per-inferior thread_db
info.
(thread_db_find_new_threads_1): Add new ptid argument. Adjust to
use per-inferior thread-db info.
(thread_db_find_new_threads): Adjust to use per-inferior thread-db
info.
(thread_db_get_thread_local_address): Adjust.
(thread_db_get_ada_task_ptid): Adjust.
* inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target
if there no more processes left to debug.
* thread.c (set_running, set_executing): Handle resuming all
threads of a single inferior.
* mi/mi-interp.c (mi_output_running_pid): New.
(mi_inferior_count): New.
(mi_on_resume): For backwards compatibility, if resuming all
threads of an inferior, and there is only one inferior, output
"all".
2009-05-18 16:07:18 +02:00
|
|
|
set_executing (resume_ptid, 0);
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
2008-03-11 00:14:06 +01:00
|
|
|
|
|
|
|
/* Implement the "unset exec-wrapper" command. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
unset_exec_wrapper_command (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
xfree (exec_wrapper);
|
|
|
|
exec_wrapper = NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-21 Pedro Alves <pedro@codesorcery.com>
Silence a few -Wmissing-prototypes warnings.
PR build/9877:
* amd64-nat.c: Include "amd64-nat.h".
* fork-child.c (_initialize_fork_child): Ditto.
* gcore.c (_initialize_gcore): Ditto.
* inf-ptrace.c: Include "inf-ptrace.h".
(inf_ptrace_store_registers): Make it static.
* linux-nat.c (linux_nat_terminal_ours): Make it static.
(_initialize_linux_nat): Declare before definition.
* linux-tdep.c: Include "linux-tdep.h".
* linux-thread-db.c (_initialize_thread_db): Declare before
definition.
* proc-service.c (_initialize_proc_service): Ditto.
* remote.c (remote_send_printf): Make it static.
* solib.c: Include "solib.h".
* symfile-mem.c (_initialize_symfile_mem): Declare before
definition.
* ada-lang.c (ada_la_decode, ada_match_name)
(ada_suppress_symbol_printing, ada_is_array_type)
(ada_value_ptr_subscript, ada_array_length)
(ada_to_static_fixed_value): Make them static.
(_initialize_ada_language): Declare before definition.
* ada-tasks.c (ada_get_task_number, ada_get_environment_task)
(ada_task_list_changed, ada_new_objfile_observer): Make them
static.
(_initialize_tasks): Declare before definition.
* addrmap.c (_initialize_addrmap): Declare before definition.
* auxv.c (default_auxv_parse): Make it static.
* bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make
them static.
* breakpoint.c (remove_sal): Add line break.
(expand_line_sal_maybe): Make it static.
* cp-name-parser.y: Include "cp-support.h".
* cp-valprint.c (cp_find_class_member): Make it static.
* eval.c (value_f90_subarray): Ditto.
* exceptions.c (print_any_exception): Ditto.
* findcmd.c (_initialize_mem_search): Declare before definition.
* frame.c (frame_observer_target_changed): Make it static.
* gnu-v3-abi.c (gnuv3_find_method_in): Make it static.
* inf-child.c: Include "inf-child.h".
* inferior.h (valid_inferior_id): Rename to ...
(valid_gdb_inferior_id): ... this.
* infrun.c (infrun_thread_stop_requested, siginfo_make_value):
Make them static.
* jv-lang.c (java_language_arch_info): Make it static.
* m2-typeprint.c (m2_get_discrete_bounds): Ditto.
* osdata.c (info_osdata_command): Make it static.
* regcache.c (regcache_observer_target_changed): Make it static.
* reverse.c (_initialize_reverse): Declare before definition.
* stabsread.c (cleanup_undefined_types_noname)
(cleanup_undefined_types_1): Make them static.
* symfile.c (place_section): Make it static.
* symtab.c (find_pc_sect_psymtab_closer): Make it static.
* target-descriptions.c (_initialize_target_descriptions): Declare
before definition.
* target.c (default_get_ada_task_ptid, find_default_can_async_p)
(find_default_is_async_p, find_default_supports_non_stop): Make
them static.
(target_supports_non_stop): Add prototype.
(dummy_pid_to_str): Make it static.
* utils.c (_initialize_utils): Declare before definition.
* ada-exp.y (_initialize_ada_exp): Declare before definition.
* solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype.
* target.h (struct target_ops): Add a prototype to the
to_can_execute_reverse callback.
* macroscope.c (_initialize_macroscope): Declare before definition.
* cp-namespace.c (_initialize_cp_namespace): Declare before definition.
* python/python.c (_initialize_python): Declare before definition.
* tui/tui-command.c: Include "tui/tui-command.h".
* tui/tui-data.c (init_content_element, init_win_info): Make them
static.
* tui/tui-disasm.c: Include "tui/tui-disasm.h".
* tui/tui-interp.c (_initialize_tui_interp): Declare before
definition.
* tui/tui-layout.c: Include "tui/tui-layout.h".
(_initialize_tui_layout): Declare before definition.
* tui/tui-regs.c: Include "tui/tui-regs.h".
(tui_display_reg_element_at_line): Make it static.
(_initialize_tui_regs): Declare before definition.
* tui/tui-stack.c (_initialize_tui_stack): Declare before
definition.
* tui/tui-win.c: Include "tui/tui-win.h".
(_initialize_tui_win): Declare before definition.
(tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH.
* tui/tui-win.h (tui_sigwinch_handler): Delete declaration.
(tui_get_cmd_list): Add a prototype.
* tui/tui-windata.c: Include tui-windata.h.
* tui/tui-wingeneral.c (box_win): Make it static.
* cli/cli-logging.c (show_logging_command): Make it static.
(_initialize_cli_logging): Declare before definition.
* mi/mi-common.c (_initialize_gdb_mi_common): Declare before
definition.
2009-02-21 17:14:50 +01:00
|
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
|
|
|
extern initialize_file_ftype _initialize_fork_child;
|
|
|
|
|
2008-03-11 00:14:06 +01:00
|
|
|
void
|
|
|
|
_initialize_fork_child (void)
|
|
|
|
{
|
|
|
|
add_setshow_filename_cmd ("exec-wrapper", class_run, &exec_wrapper, _("\
|
|
|
|
Set a wrapper for running programs.\n\
|
|
|
|
The wrapper prepares the system and environment for the new program."),
|
|
|
|
_("\
|
|
|
|
Show the wrapper for running programs."), NULL,
|
|
|
|
NULL, NULL,
|
|
|
|
&setlist, &showlist);
|
|
|
|
|
|
|
|
add_cmd ("exec-wrapper", class_run, unset_exec_wrapper_command,
|
|
|
|
_("Disable use of an execution wrapper."),
|
|
|
|
&unsetlist);
|
|
|
|
}
|