3
3
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4
4
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5
2008, 2009 Free Software Foundation, Inc.
5
2008, 2009, 2010 Free Software Foundation, Inc.
7
7
This file is part of GDB.
124
126
#define ERROR_NO_INFERIOR \
125
127
if (!target_has_execution) error (_("The program is not being run."));
127
/* String containing arguments to give to the program, separated by spaces.
128
Empty string (pointer to '\0') means no args. */
130
static char *inferior_args;
132
/* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
133
then we must compute INFERIOR_ARGS from this (via the target). */
135
static int inferior_argc;
136
static char **inferior_argv;
138
/* File name for default use for standard in/out in the inferior. */
140
static char *inferior_io_terminal;
129
/* Scratch area where string containing arguments to give to the program will be
130
stored by 'set args'. As soon as anything is stored, notice_args_set will
131
move it into per-inferior storage. Arguments are separated by spaces. Empty
132
string (pointer to '\0') means no args. */
134
static char *inferior_args_scratch;
136
/* Scratch area where 'set inferior-tty' will store user-provided value.
137
We'll immediate copy it into per-inferior storage. */
139
static char *inferior_io_terminal_scratch;
142
141
/* Pid of our debugged inferior, or 0 if no inferior now.
143
142
Since various parts of infrun.c test this to see whether there is a program
165
164
int stopped_by_random_signal;
167
/* Environment to use for running inferior,
168
in format described in environ.h. */
170
struct gdb_environ *inferior_environ;
172
167
/* Accessor routines. */
169
/* Set the io terminal for the current inferior. Ownership of
170
TERMINAL_NAME is not transferred. */
175
173
set_inferior_io_terminal (const char *terminal_name)
177
if (inferior_io_terminal)
178
xfree (inferior_io_terminal);
181
inferior_io_terminal = NULL;
183
inferior_io_terminal = xstrdup (terminal_name);
175
xfree (current_inferior ()->terminal);
176
current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
187
180
get_inferior_io_terminal (void)
189
return inferior_io_terminal;
182
return current_inferior ()->terminal;
186
set_inferior_tty_command (char *args, int from_tty,
187
struct cmd_list_element *c)
189
/* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
190
Now route it to current inferior. */
191
set_inferior_io_terminal (inferior_io_terminal_scratch);
195
show_inferior_tty_command (struct ui_file *file, int from_tty,
196
struct cmd_list_element *c, const char *value)
198
/* Note that we ignore the passed-in value in favor of computing it
200
const char *inferior_io_terminal = get_inferior_io_terminal ();
201
if (inferior_io_terminal == NULL)
202
inferior_io_terminal = "";
203
fprintf_filtered (gdb_stdout,
204
_("Terminal for future runs of program being debugged "
205
"is \"%s\".\n"), inferior_io_terminal);
193
209
get_inferior_args (void)
195
if (inferior_argc != 0)
211
if (current_inferior ()->argc != 0)
199
n = construct_inferior_arguments (inferior_argc, inferior_argv);
200
old = set_inferior_args (n);
215
n = construct_inferior_arguments (current_inferior ()->argc,
216
current_inferior ()->argv);
217
set_inferior_args (n);
204
if (inferior_args == NULL)
205
inferior_args = xstrdup ("");
221
if (current_inferior ()->args == NULL)
222
current_inferior ()->args = xstrdup ("");
207
return inferior_args;
224
return current_inferior ()->args;
227
/* Set the arguments for the current inferior. Ownership of
228
NEWARGS is not transferred. */
211
231
set_inferior_args (char *newargs)
213
char *saved_args = inferior_args;
215
inferior_args = newargs;
233
xfree (current_inferior ()->args);
234
current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
235
current_inferior ()->argc = 0;
236
current_inferior ()->argv = 0;
223
240
set_inferior_args_vector (int argc, char **argv)
225
inferior_argc = argc;
226
inferior_argv = argv;
242
current_inferior ()->argc = argc;
243
current_inferior ()->argv = argv;
229
246
/* Notice when `set args' is run. */
231
notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
248
set_args_command (char *args, int from_tty, struct cmd_list_element *c)
250
/* CLI has assigned the user-provided value to inferior_args_scratch.
251
Now route it to current inferior. */
252
set_inferior_args (inferior_args_scratch);
237
255
/* Notice when `show args' is run. */
239
notice_args_read (struct ui_file *file, int from_tty,
240
struct cmd_list_element *c, const char *value)
257
show_args_command (struct ui_file *file, int from_tty,
258
struct cmd_list_element *c, const char *value)
242
260
/* Note that we ignore the passed-in value in favor of computing it
395
404
/* Now that we know the register layout, retrieve current PC. */
396
405
stop_pc = regcache_read_pc (get_current_regcache ());
409
/* Create the hooks to handle shared library load and unload
411
#ifdef SOLIB_CREATE_INFERIOR_HOOK
412
SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
414
solib_create_inferior_hook (from_tty);
398
418
/* If the solist is global across processes, there's no need to
399
419
refetch it here. */
400
420
if (exec_bfd && !gdbarch_has_global_solist (target_gdbarch))
402
422
/* Sometimes the platform-specific hook loads initial shared
403
libraries, and sometimes it doesn't. Try to do so first, so
404
that we can add them with the correct value for FROM_TTY.
405
If we made all the inferior hook methods consistent,
406
this call could be removed. */
423
libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be
424
incorrectly 0 but such solib targets should be fixed anyway. If we
425
made all the inferior hook methods consistent, this call could be
426
removed. Call it only after the solib target has been initialized by
427
solib_create_inferior_hook. */
408
SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
410
solib_add (NULL, from_tty, target, auto_solib_add);
416
/* Create the hooks to handle shared library load and unload
418
#ifdef SOLIB_CREATE_INFERIOR_HOOK
419
SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
421
solib_create_inferior_hook ();
430
SOLIB_ADD (NULL, 0, target, auto_solib_add);
432
solib_add (NULL, 0, target, auto_solib_add);
1515
1522
old_chain = make_cleanup_delete_breakpoint (breakpoint);
1517
1524
tp->proceed_to_finish = 1; /* We want stop_registers, please... */
1518
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1520
1525
cargs = xmalloc (sizeof (*cargs));
1522
1527
cargs->breakpoint = breakpoint;
1523
1528
cargs->function = function;
1524
1529
add_continuation (tp, finish_command_continuation, cargs,
1525
1530
finish_command_continuation_free_arg);
1531
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1527
1533
discard_cleanups (old_chain);
1528
1534
if (!target_can_async_p ())
1822
1828
char *exec_path;
1824
1830
dont_repeat ();
1825
env = get_in_environ (inferior_environ, path_var_name);
1831
env = get_in_environ (current_inferior ()->environment, path_var_name);
1826
1832
/* Can be null if path is not set */
1829
1835
exec_path = xstrdup (env);
1830
1836
mod_path (dirname, &exec_path);
1831
set_in_environ (inferior_environ, path_var_name, exec_path);
1837
set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
1832
1838
xfree (exec_path);
1834
1840
path_info ((char *) NULL, from_tty);
2642
2650
/* add the filename of the terminal connected to inferior I/O */
2643
2651
add_setshow_filename_cmd ("inferior-tty", class_run,
2644
&inferior_io_terminal, _("\
2652
&inferior_io_terminal_scratch, _("\
2645
2653
Set terminal for future runs of program being debugged."), _("\
2646
2654
Show terminal for future runs of program being debugged."), _("\
2647
Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2655
Usage: set inferior-tty /dev/pts/1"),
2656
set_inferior_tty_command,
2657
show_inferior_tty_command,
2658
&setlist, &showlist);
2648
2659
add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2650
2661
add_setshow_optional_filename_cmd ("args", class_run,
2651
&inferior_args, _("\
2662
&inferior_args_scratch, _("\
2652
2663
Set argument list to give program being debugged when it is started."), _("\
2653
2664
Show argument list to give program being debugged when it is started."), _("\
2654
2665
Follow this command with any number of args, to be passed to the program."),
2657
2668
&setlist, &showlist);
2659
2670
c = add_cmd ("environment", no_class, environment_info, _("\