xref: /openbsd-src/gnu/usr.bin/binutils/gdb/infcmd.c (revision 63addd46c1e40ca0f49488ddcdc4ab598023b0c1)
1e93f7393Sniklas /* Memory-access and commands for "inferior" process, for GDB.
2b725ae77Skettenis    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3b725ae77Skettenis    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4b725ae77Skettenis    Free Software Foundation, Inc.
5e93f7393Sniklas 
6e93f7393Sniklas    This file is part of GDB.
7e93f7393Sniklas 
8e93f7393Sniklas    This program is free software; you can redistribute it and/or modify
9e93f7393Sniklas    it under the terms of the GNU General Public License as published by
10e93f7393Sniklas    the Free Software Foundation; either version 2 of the License, or
11e93f7393Sniklas    (at your option) any later version.
12e93f7393Sniklas 
13e93f7393Sniklas    This program is distributed in the hope that it will be useful,
14e93f7393Sniklas    but WITHOUT ANY WARRANTY; without even the implied warranty of
15e93f7393Sniklas    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e93f7393Sniklas    GNU General Public License for more details.
17e93f7393Sniklas 
18e93f7393Sniklas    You should have received a copy of the GNU General Public License
19e93f7393Sniklas    along with this program; if not, write to the Free Software
20b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
21b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
22e93f7393Sniklas 
23e93f7393Sniklas #include "defs.h"
24e93f7393Sniklas #include <signal.h>
25e93f7393Sniklas #include "gdb_string.h"
26e93f7393Sniklas #include "symtab.h"
27e93f7393Sniklas #include "gdbtypes.h"
28e93f7393Sniklas #include "frame.h"
29e93f7393Sniklas #include "inferior.h"
30e93f7393Sniklas #include "environ.h"
31e93f7393Sniklas #include "value.h"
32e93f7393Sniklas #include "gdbcmd.h"
33b725ae77Skettenis #include "symfile.h"
34e93f7393Sniklas #include "gdbcore.h"
35e93f7393Sniklas #include "target.h"
36e93f7393Sniklas #include "language.h"
37b725ae77Skettenis #include "symfile.h"
38b725ae77Skettenis #include "objfiles.h"
39b725ae77Skettenis #include "completer.h"
40b725ae77Skettenis #include "ui-out.h"
41b725ae77Skettenis #include "event-top.h"
42b725ae77Skettenis #include "parser-defs.h"
43b725ae77Skettenis #include "regcache.h"
44b725ae77Skettenis #include "reggroups.h"
45b725ae77Skettenis #include "block.h"
46b725ae77Skettenis #include <ctype.h>
47b725ae77Skettenis #include "gdb_assert.h"
48e93f7393Sniklas 
49b725ae77Skettenis /* Functions exported for general use, in inferior.h: */
50e93f7393Sniklas 
51b725ae77Skettenis void all_registers_info (char *, int);
52e93f7393Sniklas 
53b725ae77Skettenis void registers_info (char *, int);
54e93f7393Sniklas 
55b725ae77Skettenis void nexti_command (char *, int);
56e93f7393Sniklas 
57b725ae77Skettenis void stepi_command (char *, int);
58e93f7393Sniklas 
59b725ae77Skettenis void continue_command (char *, int);
60e93f7393Sniklas 
61b725ae77Skettenis void interrupt_target_command (char *args, int from_tty);
62e93f7393Sniklas 
63b725ae77Skettenis /* Local functions: */
64e93f7393Sniklas 
65b725ae77Skettenis static void nofp_registers_info (char *, int);
66e93f7393Sniklas 
67b725ae77Skettenis static void print_return_value (int struct_return, struct type *value_type);
68e93f7393Sniklas 
69b725ae77Skettenis static void finish_command_continuation (struct continuation_arg *);
70e93f7393Sniklas 
71b725ae77Skettenis static void until_next_command (int);
72e93f7393Sniklas 
73b725ae77Skettenis static void until_command (char *, int);
74e93f7393Sniklas 
75b725ae77Skettenis static void path_info (char *, int);
76e93f7393Sniklas 
77b725ae77Skettenis static void path_command (char *, int);
78e93f7393Sniklas 
79b725ae77Skettenis static void unset_command (char *, int);
80e93f7393Sniklas 
81b725ae77Skettenis static void float_info (char *, int);
82e93f7393Sniklas 
83b725ae77Skettenis static void detach_command (char *, int);
84e93f7393Sniklas 
85b725ae77Skettenis static void disconnect_command (char *, int);
86e93f7393Sniklas 
87b725ae77Skettenis static void unset_environment_command (char *, int);
88e93f7393Sniklas 
89b725ae77Skettenis static void set_environment_command (char *, int);
90e93f7393Sniklas 
91b725ae77Skettenis static void environment_info (char *, int);
92e93f7393Sniklas 
93b725ae77Skettenis static void program_info (char *, int);
94e93f7393Sniklas 
95b725ae77Skettenis static void finish_command (char *, int);
96e93f7393Sniklas 
97b725ae77Skettenis static void signal_command (char *, int);
98e93f7393Sniklas 
99b725ae77Skettenis static void jump_command (char *, int);
100b725ae77Skettenis 
101b725ae77Skettenis static void step_1 (int, int, char *);
102b725ae77Skettenis static void step_once (int skip_subroutines, int single_inst, int count);
103b725ae77Skettenis static void step_1_continuation (struct continuation_arg *arg);
104b725ae77Skettenis 
105b725ae77Skettenis static void next_command (char *, int);
106b725ae77Skettenis 
107b725ae77Skettenis static void step_command (char *, int);
108b725ae77Skettenis 
109b725ae77Skettenis static void run_command (char *, int);
110b725ae77Skettenis 
111b725ae77Skettenis static void run_no_args_command (char *args, int from_tty);
112b725ae77Skettenis 
113b725ae77Skettenis static void go_command (char *line_no, int from_tty);
114b725ae77Skettenis 
115b725ae77Skettenis static int strip_bg_char (char **);
116b725ae77Skettenis 
117b725ae77Skettenis void _initialize_infcmd (void);
118b725ae77Skettenis 
119b725ae77Skettenis #define GO_USAGE   "Usage: go <location>\n"
120e93f7393Sniklas 
121e93f7393Sniklas #define ERROR_NO_INFERIOR \
122e93f7393Sniklas    if (!target_has_execution) error ("The program is not being run.");
123e93f7393Sniklas 
124e93f7393Sniklas /* String containing arguments to give to the program, separated by spaces.
125e93f7393Sniklas    Empty string (pointer to '\0') means no args.  */
126e93f7393Sniklas 
127e93f7393Sniklas static char *inferior_args;
128e93f7393Sniklas 
129b725ae77Skettenis /* The inferior arguments as a vector.  If INFERIOR_ARGC is nonzero,
130b725ae77Skettenis    then we must compute INFERIOR_ARGS from this (via the target).  */
131b725ae77Skettenis 
132b725ae77Skettenis static int inferior_argc;
133b725ae77Skettenis static char **inferior_argv;
134b725ae77Skettenis 
135e93f7393Sniklas /* File name for default use for standard in/out in the inferior.  */
136e93f7393Sniklas 
137e93f7393Sniklas char *inferior_io_terminal;
138e93f7393Sniklas 
139e93f7393Sniklas /* Pid of our debugged inferior, or 0 if no inferior now.
140e93f7393Sniklas    Since various parts of infrun.c test this to see whether there is a program
141e93f7393Sniklas    being debugged it should be nonzero (currently 3 is used) for remote
142e93f7393Sniklas    debugging.  */
143e93f7393Sniklas 
144b725ae77Skettenis ptid_t inferior_ptid;
145e93f7393Sniklas 
146e93f7393Sniklas /* Last signal that the inferior received (why it stopped).  */
147e93f7393Sniklas 
148e93f7393Sniklas enum target_signal stop_signal;
149e93f7393Sniklas 
150e93f7393Sniklas /* Address at which inferior stopped.  */
151e93f7393Sniklas 
152e93f7393Sniklas CORE_ADDR stop_pc;
153e93f7393Sniklas 
154e93f7393Sniklas /* Chain containing status of breakpoint(s) that we have stopped at.  */
155e93f7393Sniklas 
156e93f7393Sniklas bpstat stop_bpstat;
157e93f7393Sniklas 
158e93f7393Sniklas /* Flag indicating that a command has proceeded the inferior past the
159e93f7393Sniklas    current breakpoint.  */
160e93f7393Sniklas 
161e93f7393Sniklas int breakpoint_proceeded;
162e93f7393Sniklas 
163e93f7393Sniklas /* Nonzero if stopped due to a step command.  */
164e93f7393Sniklas 
165e93f7393Sniklas int stop_step;
166e93f7393Sniklas 
167e93f7393Sniklas /* Nonzero if stopped due to completion of a stack dummy routine.  */
168e93f7393Sniklas 
169e93f7393Sniklas int stop_stack_dummy;
170e93f7393Sniklas 
171e93f7393Sniklas /* Nonzero if stopped due to a random (unexpected) signal in inferior
172e93f7393Sniklas    process.  */
173e93f7393Sniklas 
174e93f7393Sniklas int stopped_by_random_signal;
175e93f7393Sniklas 
176e93f7393Sniklas /* Range to single step within.
177e93f7393Sniklas    If this is nonzero, respond to a single-step signal
178e93f7393Sniklas    by continuing to step if the pc is in this range.  */
179e93f7393Sniklas 
180e93f7393Sniklas CORE_ADDR step_range_start;	/* Inclusive */
181e93f7393Sniklas CORE_ADDR step_range_end;	/* Exclusive */
182e93f7393Sniklas 
183e93f7393Sniklas /* Stack frame address as of when stepping command was issued.
184e93f7393Sniklas    This is how we know when we step into a subroutine call,
185e93f7393Sniklas    and how to set the frame for the breakpoint used to step out.  */
186e93f7393Sniklas 
187b725ae77Skettenis struct frame_id step_frame_id;
188e93f7393Sniklas 
189b725ae77Skettenis enum step_over_calls_kind step_over_calls;
190e93f7393Sniklas 
191e93f7393Sniklas /* If stepping, nonzero means step count is > 1
192e93f7393Sniklas    so don't print frame next time inferior stops
193e93f7393Sniklas    if it stops due to stepping.  */
194e93f7393Sniklas 
195e93f7393Sniklas int step_multi;
196e93f7393Sniklas 
197e93f7393Sniklas /* Environment to use for running inferior,
198e93f7393Sniklas    in format described in environ.h.  */
199e93f7393Sniklas 
200e93f7393Sniklas struct environ *inferior_environ;
201b725ae77Skettenis 
202b725ae77Skettenis /* Accessor routines. */
203b725ae77Skettenis 
204b725ae77Skettenis char *
get_inferior_args(void)205b725ae77Skettenis get_inferior_args (void)
206b725ae77Skettenis {
207b725ae77Skettenis   if (inferior_argc != 0)
208b725ae77Skettenis     {
209b725ae77Skettenis       char *n, *old;
210b725ae77Skettenis 
211b725ae77Skettenis       n = gdbarch_construct_inferior_arguments (current_gdbarch,
212b725ae77Skettenis 						inferior_argc, inferior_argv);
213b725ae77Skettenis       old = set_inferior_args (n);
214b725ae77Skettenis       xfree (old);
215b725ae77Skettenis     }
216b725ae77Skettenis 
217b725ae77Skettenis   if (inferior_args == NULL)
218b725ae77Skettenis     inferior_args = xstrdup ("");
219b725ae77Skettenis 
220b725ae77Skettenis   return inferior_args;
221b725ae77Skettenis }
222b725ae77Skettenis 
223b725ae77Skettenis char *
set_inferior_args(char * newargs)224b725ae77Skettenis set_inferior_args (char *newargs)
225b725ae77Skettenis {
226b725ae77Skettenis   char *saved_args = inferior_args;
227b725ae77Skettenis 
228b725ae77Skettenis   inferior_args = newargs;
229b725ae77Skettenis   inferior_argc = 0;
230b725ae77Skettenis   inferior_argv = 0;
231b725ae77Skettenis 
232b725ae77Skettenis   return saved_args;
233b725ae77Skettenis }
234b725ae77Skettenis 
235b725ae77Skettenis void
set_inferior_args_vector(int argc,char ** argv)236b725ae77Skettenis set_inferior_args_vector (int argc, char **argv)
237b725ae77Skettenis {
238b725ae77Skettenis   inferior_argc = argc;
239b725ae77Skettenis   inferior_argv = argv;
240b725ae77Skettenis }
241b725ae77Skettenis 
242b725ae77Skettenis /* Notice when `set args' is run.  */
243b725ae77Skettenis static void
notice_args_set(char * args,int from_tty,struct cmd_list_element * c)244b725ae77Skettenis notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
245b725ae77Skettenis {
246b725ae77Skettenis   inferior_argc = 0;
247b725ae77Skettenis   inferior_argv = 0;
248b725ae77Skettenis }
249b725ae77Skettenis 
250b725ae77Skettenis /* Notice when `show args' is run.  */
251b725ae77Skettenis static void
notice_args_read(char * args,int from_tty,struct cmd_list_element * c)252b725ae77Skettenis notice_args_read (char *args, int from_tty, struct cmd_list_element *c)
253b725ae77Skettenis {
254b725ae77Skettenis   /* Might compute the value.  */
255b725ae77Skettenis   get_inferior_args ();
256b725ae77Skettenis }
257e93f7393Sniklas 
258e93f7393Sniklas 
259b725ae77Skettenis /* Compute command-line string given argument vector.  This does the
260b725ae77Skettenis    same shell processing as fork_inferior.  */
261b725ae77Skettenis char *
construct_inferior_arguments(struct gdbarch * gdbarch,int argc,char ** argv)262b725ae77Skettenis construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
263b725ae77Skettenis {
264b725ae77Skettenis   char *result;
265b725ae77Skettenis 
266b725ae77Skettenis   if (STARTUP_WITH_SHELL)
267b725ae77Skettenis     {
268b725ae77Skettenis       /* This holds all the characters considered special to the
269b725ae77Skettenis 	 typical Unix shells.  We include `^' because the SunOS
270b725ae77Skettenis 	 /bin/sh treats it as a synonym for `|'.  */
271b725ae77Skettenis       char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
272b725ae77Skettenis       int i;
273b725ae77Skettenis       int length = 0;
274b725ae77Skettenis       char *out, *cp;
275b725ae77Skettenis 
276b725ae77Skettenis       /* We over-compute the size.  It shouldn't matter.  */
277b725ae77Skettenis       for (i = 0; i < argc; ++i)
278b725ae77Skettenis 	length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
279b725ae77Skettenis 
280b725ae77Skettenis       result = (char *) xmalloc (length);
281b725ae77Skettenis       out = result;
282b725ae77Skettenis 
283b725ae77Skettenis       for (i = 0; i < argc; ++i)
284b725ae77Skettenis 	{
285b725ae77Skettenis 	  if (i > 0)
286b725ae77Skettenis 	    *out++ = ' ';
287b725ae77Skettenis 
288b725ae77Skettenis 	  /* Need to handle empty arguments specially.  */
289b725ae77Skettenis 	  if (argv[i][0] == '\0')
290b725ae77Skettenis 	    {
291b725ae77Skettenis 	      *out++ = '\'';
292b725ae77Skettenis 	      *out++ = '\'';
293b725ae77Skettenis 	    }
294b725ae77Skettenis 	  else
295b725ae77Skettenis 	    {
296b725ae77Skettenis 	      for (cp = argv[i]; *cp; ++cp)
297b725ae77Skettenis 		{
298b725ae77Skettenis 		  if (strchr (special, *cp) != NULL)
299b725ae77Skettenis 		    *out++ = '\\';
300b725ae77Skettenis 		  *out++ = *cp;
301b725ae77Skettenis 		}
302b725ae77Skettenis 	    }
303b725ae77Skettenis 	}
304b725ae77Skettenis       *out = '\0';
305b725ae77Skettenis     }
306b725ae77Skettenis   else
307b725ae77Skettenis     {
308b725ae77Skettenis       /* In this case we can't handle arguments that contain spaces,
309b725ae77Skettenis 	 tabs, or newlines -- see breakup_args().  */
310b725ae77Skettenis       int i;
311b725ae77Skettenis       int length = 0;
312b725ae77Skettenis 
313b725ae77Skettenis       for (i = 0; i < argc; ++i)
314b725ae77Skettenis 	{
315b725ae77Skettenis 	  char *cp = strchr (argv[i], ' ');
316b725ae77Skettenis 	  if (cp == NULL)
317b725ae77Skettenis 	    cp = strchr (argv[i], '\t');
318b725ae77Skettenis 	  if (cp == NULL)
319b725ae77Skettenis 	    cp = strchr (argv[i], '\n');
320b725ae77Skettenis 	  if (cp != NULL)
321b725ae77Skettenis 	    error ("can't handle command-line argument containing whitespace");
322b725ae77Skettenis 	  length += strlen (argv[i]) + 1;
323b725ae77Skettenis 	}
324b725ae77Skettenis 
325b725ae77Skettenis       result = (char *) xmalloc (length);
326b725ae77Skettenis       result[0] = '\0';
327b725ae77Skettenis       for (i = 0; i < argc; ++i)
328b725ae77Skettenis 	{
329b725ae77Skettenis 	  if (i > 0)
330b725ae77Skettenis 	    strcat (result, " ");
331b725ae77Skettenis 	  strcat (result, argv[i]);
332b725ae77Skettenis 	}
333b725ae77Skettenis     }
334b725ae77Skettenis 
335b725ae77Skettenis   return result;
336b725ae77Skettenis }
337b725ae77Skettenis 
338b725ae77Skettenis 
339b725ae77Skettenis /* This function detects whether or not a '&' character (indicating
340b725ae77Skettenis    background execution) has been added as *the last* of the arguments ARGS
341b725ae77Skettenis    of a command. If it has, it removes it and returns 1. Otherwise it
342b725ae77Skettenis    does nothing and returns 0. */
343b725ae77Skettenis static int
strip_bg_char(char ** args)344b725ae77Skettenis strip_bg_char (char **args)
345b725ae77Skettenis {
346b725ae77Skettenis   char *p = NULL;
347b725ae77Skettenis 
348b725ae77Skettenis   p = strchr (*args, '&');
349b725ae77Skettenis 
350b725ae77Skettenis   if (p)
351b725ae77Skettenis     {
352b725ae77Skettenis       if (p == (*args + strlen (*args) - 1))
353b725ae77Skettenis 	{
354b725ae77Skettenis 	  if (strlen (*args) > 1)
355b725ae77Skettenis 	    {
356b725ae77Skettenis 	      do
357b725ae77Skettenis 		p--;
358b725ae77Skettenis 	      while (*p == ' ' || *p == '\t');
359b725ae77Skettenis 	      *(p + 1) = '\0';
360b725ae77Skettenis 	    }
361b725ae77Skettenis 	  else
362b725ae77Skettenis 	    *args = 0;
363b725ae77Skettenis 	  return 1;
364b725ae77Skettenis 	}
365b725ae77Skettenis     }
366b725ae77Skettenis   return 0;
367b725ae77Skettenis }
368b725ae77Skettenis 
369e93f7393Sniklas void
tty_command(char * file,int from_tty)370b725ae77Skettenis tty_command (char *file, int from_tty)
371e93f7393Sniklas {
372e93f7393Sniklas   if (file == 0)
373e93f7393Sniklas     error_no_arg ("terminal name for running target process");
374e93f7393Sniklas 
375e93f7393Sniklas   inferior_io_terminal = savestring (file, strlen (file));
376e93f7393Sniklas }
377e93f7393Sniklas 
378*63addd46Skettenis /* Kill the inferior if already running.  This function is designed
379*63addd46Skettenis    to be called when we are about to start the execution of the program
380*63addd46Skettenis    from the beginning.  Ask the user to confirm that he wants to restart
381*63addd46Skettenis    the program being debugged when FROM_TTY is non-null.  */
382*63addd46Skettenis 
383*63addd46Skettenis void
kill_if_already_running(int from_tty)384*63addd46Skettenis kill_if_already_running (int from_tty)
385e93f7393Sniklas {
386b725ae77Skettenis   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
387e93f7393Sniklas     {
388b725ae77Skettenis       if (from_tty
389b725ae77Skettenis 	  && !query ("The program being debugged has been started already.\n\
390e93f7393Sniklas Start it from the beginning? "))
391e93f7393Sniklas 	error ("Program not restarted.");
392e93f7393Sniklas       target_kill ();
393b725ae77Skettenis #if defined(SOLIB_RESTART)
394b725ae77Skettenis       SOLIB_RESTART ();
395b725ae77Skettenis #endif
396b725ae77Skettenis       init_wait_for_inferior ();
397e93f7393Sniklas     }
398*63addd46Skettenis }
399e93f7393Sniklas 
400*63addd46Skettenis static void
run_command(char * args,int from_tty)401*63addd46Skettenis run_command (char *args, int from_tty)
402*63addd46Skettenis {
403*63addd46Skettenis   char *exec_file;
404*63addd46Skettenis 
405*63addd46Skettenis   dont_repeat ();
406*63addd46Skettenis 
407*63addd46Skettenis   kill_if_already_running (from_tty);
408e93f7393Sniklas   clear_breakpoint_hit_counts ();
409e93f7393Sniklas 
410b725ae77Skettenis   /* Purge old solib objfiles. */
411b725ae77Skettenis   objfile_purge_solibs ();
412e93f7393Sniklas 
413b725ae77Skettenis   do_run_cleanups (NULL);
414b725ae77Skettenis 
415b725ae77Skettenis   /* The comment here used to read, "The exec file is re-read every
416b725ae77Skettenis      time we do a generic_mourn_inferior, so we just have to worry
417b725ae77Skettenis      about the symbol file."  The `generic_mourn_inferior' function
418b725ae77Skettenis      gets called whenever the program exits.  However, suppose the
419b725ae77Skettenis      program exits, and *then* the executable file changes?  We need
420b725ae77Skettenis      to check again here.  Since reopen_exec_file doesn't do anything
421b725ae77Skettenis      if the timestamp hasn't changed, I don't see the harm.  */
422b725ae77Skettenis   reopen_exec_file ();
423e93f7393Sniklas   reread_symbols ();
424e93f7393Sniklas 
425b725ae77Skettenis   exec_file = (char *) get_exec_file (0);
426b725ae77Skettenis 
427e93f7393Sniklas   /* We keep symbols from add-symbol-file, on the grounds that the
428e93f7393Sniklas      user might want to add some symbols before running the program
429e93f7393Sniklas      (right?).  But sometimes (dynamic loading where the user manually
430e93f7393Sniklas      introduces the new symbols with add-symbol-file), the code which
431e93f7393Sniklas      the symbols describe does not persist between runs.  Currently
432e93f7393Sniklas      the user has to manually nuke all symbols between runs if they
433e93f7393Sniklas      want them to go away (PR 2207).  This is probably reasonable.  */
434e93f7393Sniklas 
435b725ae77Skettenis   if (!args)
436b725ae77Skettenis     {
437*63addd46Skettenis       if (target_can_async_p ())
438b725ae77Skettenis 	async_disable_stdin ();
439b725ae77Skettenis     }
440b725ae77Skettenis   else
441b725ae77Skettenis     {
442b725ae77Skettenis       int async_exec = strip_bg_char (&args);
443b725ae77Skettenis 
444b725ae77Skettenis       /* If we get a request for running in the bg but the target
445b725ae77Skettenis          doesn't support it, error out. */
446*63addd46Skettenis       if (async_exec && !target_can_async_p ())
447b725ae77Skettenis 	error ("Asynchronous execution not supported on this target.");
448b725ae77Skettenis 
449b725ae77Skettenis       /* If we don't get a request of running in the bg, then we need
450b725ae77Skettenis          to simulate synchronous (fg) execution. */
451*63addd46Skettenis       if (!async_exec && target_can_async_p ())
452b725ae77Skettenis 	{
453b725ae77Skettenis 	  /* Simulate synchronous execution */
454b725ae77Skettenis 	  async_disable_stdin ();
455b725ae77Skettenis 	}
456b725ae77Skettenis 
457b725ae77Skettenis       /* If there were other args, beside '&', process them. */
458e93f7393Sniklas       if (args)
459e93f7393Sniklas 	{
460b725ae77Skettenis           char *old_args = set_inferior_args (xstrdup (args));
461b725ae77Skettenis           xfree (old_args);
462b725ae77Skettenis 	}
463e93f7393Sniklas     }
464e93f7393Sniklas 
465e93f7393Sniklas   if (from_tty)
466e93f7393Sniklas     {
467b725ae77Skettenis       ui_out_field_string (uiout, NULL, "Starting program");
468b725ae77Skettenis       ui_out_text (uiout, ": ");
469e93f7393Sniklas       if (exec_file)
470b725ae77Skettenis 	ui_out_field_string (uiout, "execfile", exec_file);
471b725ae77Skettenis       ui_out_spaces (uiout, 1);
472b725ae77Skettenis       /* We call get_inferior_args() because we might need to compute
473b725ae77Skettenis 	 the value now.  */
474b725ae77Skettenis       ui_out_field_string (uiout, "infargs", get_inferior_args ());
475b725ae77Skettenis       ui_out_text (uiout, "\n");
476b725ae77Skettenis       ui_out_flush (uiout);
477e93f7393Sniklas     }
478e93f7393Sniklas 
479b725ae77Skettenis   /* We call get_inferior_args() because we might need to compute
480b725ae77Skettenis      the value now.  */
481b725ae77Skettenis   target_create_inferior (exec_file, get_inferior_args (),
482*63addd46Skettenis 			  environ_vector (inferior_environ), from_tty);
483e93f7393Sniklas }
484b725ae77Skettenis 
485b725ae77Skettenis 
486e93f7393Sniklas static void
run_no_args_command(char * args,int from_tty)487b725ae77Skettenis run_no_args_command (char *args, int from_tty)
488e93f7393Sniklas {
489b725ae77Skettenis   char *old_args = set_inferior_args (xstrdup (""));
490b725ae77Skettenis   xfree (old_args);
491b725ae77Skettenis }
492b725ae77Skettenis 
493b725ae77Skettenis 
494*63addd46Skettenis /* Start the execution of the program up until the beginning of the main
495*63addd46Skettenis    program.  */
496*63addd46Skettenis 
497*63addd46Skettenis static void
start_command(char * args,int from_tty)498*63addd46Skettenis start_command (char *args, int from_tty)
499*63addd46Skettenis {
500*63addd46Skettenis   /* Some languages such as Ada need to search inside the program
501*63addd46Skettenis      minimal symbols for the location where to put the temporary
502*63addd46Skettenis      breakpoint before starting.  */
503*63addd46Skettenis   if (!have_minimal_symbols ())
504*63addd46Skettenis     error ("No symbol table loaded.  Use the \"file\" command.");
505*63addd46Skettenis 
506*63addd46Skettenis   /* If the inferior is already running, we want to ask the user if we
507*63addd46Skettenis      should restart it or not before we insert the temporary breakpoint.
508*63addd46Skettenis      This makes sure that this command doesn't have any side effect if
509*63addd46Skettenis      the user changes its mind.  */
510*63addd46Skettenis   kill_if_already_running (from_tty);
511*63addd46Skettenis 
512*63addd46Skettenis   /* Insert the temporary breakpoint, and run...  */
513*63addd46Skettenis   tbreak_command (main_name (), 0);
514*63addd46Skettenis   run_command (args, from_tty);
515*63addd46Skettenis }
516*63addd46Skettenis 
517b725ae77Skettenis void
continue_command(char * proc_count_exp,int from_tty)518b725ae77Skettenis continue_command (char *proc_count_exp, int from_tty)
519b725ae77Skettenis {
520b725ae77Skettenis   int async_exec = 0;
521e93f7393Sniklas   ERROR_NO_INFERIOR;
522e93f7393Sniklas 
523b725ae77Skettenis   /* Find out whether we must run in the background. */
524b725ae77Skettenis   if (proc_count_exp != NULL)
525b725ae77Skettenis     async_exec = strip_bg_char (&proc_count_exp);
526e93f7393Sniklas 
527b725ae77Skettenis   /* If we must run in the background, but the target can't do it,
528b725ae77Skettenis      error out. */
529*63addd46Skettenis   if (async_exec && !target_can_async_p ())
530b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
531b725ae77Skettenis 
532b725ae77Skettenis   /* If we are not asked to run in the bg, then prepare to run in the
533b725ae77Skettenis      foreground, synchronously. */
534*63addd46Skettenis   if (!async_exec && target_can_async_p ())
535b725ae77Skettenis     {
536b725ae77Skettenis       /* Simulate synchronous execution */
537b725ae77Skettenis       async_disable_stdin ();
538b725ae77Skettenis     }
539b725ae77Skettenis 
540b725ae77Skettenis   /* If have argument (besides '&'), set proceed count of breakpoint
541b725ae77Skettenis      we stopped at.  */
542e93f7393Sniklas   if (proc_count_exp != NULL)
543e93f7393Sniklas     {
544e93f7393Sniklas       bpstat bs = stop_bpstat;
545e93f7393Sniklas       int num = bpstat_num (&bs);
546e93f7393Sniklas       if (num == 0 && from_tty)
547e93f7393Sniklas 	{
548e93f7393Sniklas 	  printf_filtered
549e93f7393Sniklas 	    ("Not stopped at any breakpoint; argument ignored.\n");
550e93f7393Sniklas 	}
551e93f7393Sniklas       while (num != 0)
552e93f7393Sniklas 	{
553e93f7393Sniklas 	  set_ignore_count (num,
554b725ae77Skettenis 			    parse_and_eval_long (proc_count_exp) - 1,
555e93f7393Sniklas 			    from_tty);
556e93f7393Sniklas 	  /* set_ignore_count prints a message ending with a period.
557e93f7393Sniklas 	     So print two spaces before "Continuing.".  */
558e93f7393Sniklas 	  if (from_tty)
559e93f7393Sniklas 	    printf_filtered ("  ");
560e93f7393Sniklas 	  num = bpstat_num (&bs);
561e93f7393Sniklas 	}
562e93f7393Sniklas     }
563e93f7393Sniklas 
564e93f7393Sniklas   if (from_tty)
565e93f7393Sniklas     printf_filtered ("Continuing.\n");
566e93f7393Sniklas 
567e93f7393Sniklas   clear_proceed_status ();
568e93f7393Sniklas 
569e93f7393Sniklas   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
570e93f7393Sniklas }
571e93f7393Sniklas 
572e93f7393Sniklas /* Step until outside of current statement.  */
573e93f7393Sniklas 
574e93f7393Sniklas static void
step_command(char * count_string,int from_tty)575b725ae77Skettenis step_command (char *count_string, int from_tty)
576e93f7393Sniklas {
577e93f7393Sniklas   step_1 (0, 0, count_string);
578e93f7393Sniklas }
579e93f7393Sniklas 
580e93f7393Sniklas /* Likewise, but skip over subroutine calls as if single instructions.  */
581e93f7393Sniklas 
582e93f7393Sniklas static void
next_command(char * count_string,int from_tty)583b725ae77Skettenis next_command (char *count_string, int from_tty)
584e93f7393Sniklas {
585e93f7393Sniklas   step_1 (1, 0, count_string);
586e93f7393Sniklas }
587e93f7393Sniklas 
588e93f7393Sniklas /* Likewise, but step only one instruction.  */
589e93f7393Sniklas 
590b725ae77Skettenis void
stepi_command(char * count_string,int from_tty)591b725ae77Skettenis stepi_command (char *count_string, int from_tty)
592e93f7393Sniklas {
593e93f7393Sniklas   step_1 (0, 1, count_string);
594e93f7393Sniklas }
595e93f7393Sniklas 
596b725ae77Skettenis void
nexti_command(char * count_string,int from_tty)597b725ae77Skettenis nexti_command (char *count_string, int from_tty)
598e93f7393Sniklas {
599e93f7393Sniklas   step_1 (1, 1, count_string);
600e93f7393Sniklas }
601e93f7393Sniklas 
602e93f7393Sniklas static void
disable_longjmp_breakpoint_cleanup(void * ignore)603b725ae77Skettenis disable_longjmp_breakpoint_cleanup (void *ignore)
604e93f7393Sniklas {
605b725ae77Skettenis   disable_longjmp_breakpoint ();
606b725ae77Skettenis }
607b725ae77Skettenis 
608b725ae77Skettenis static void
step_1(int skip_subroutines,int single_inst,char * count_string)609b725ae77Skettenis step_1 (int skip_subroutines, int single_inst, char *count_string)
610b725ae77Skettenis {
611b725ae77Skettenis   int count = 1;
612e93f7393Sniklas   struct frame_info *frame;
613e93f7393Sniklas   struct cleanup *cleanups = 0;
614b725ae77Skettenis   int async_exec = 0;
615e93f7393Sniklas 
616e93f7393Sniklas   ERROR_NO_INFERIOR;
617b725ae77Skettenis 
618b725ae77Skettenis   if (count_string)
619b725ae77Skettenis     async_exec = strip_bg_char (&count_string);
620b725ae77Skettenis 
621b725ae77Skettenis   /* If we get a request for running in the bg but the target
622b725ae77Skettenis      doesn't support it, error out. */
623*63addd46Skettenis   if (async_exec && !target_can_async_p ())
624b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
625b725ae77Skettenis 
626b725ae77Skettenis   /* If we don't get a request of running in the bg, then we need
627b725ae77Skettenis      to simulate synchronous (fg) execution. */
628*63addd46Skettenis   if (!async_exec && target_can_async_p ())
629b725ae77Skettenis     {
630b725ae77Skettenis       /* Simulate synchronous execution */
631b725ae77Skettenis       async_disable_stdin ();
632b725ae77Skettenis     }
633b725ae77Skettenis 
634b725ae77Skettenis   count = count_string ? parse_and_eval_long (count_string) : 1;
635e93f7393Sniklas 
636e93f7393Sniklas   if (!single_inst || skip_subroutines)		/* leave si command alone */
637e93f7393Sniklas     {
638e93f7393Sniklas       enable_longjmp_breakpoint ();
639*63addd46Skettenis       if (!target_can_async_p ())
640b725ae77Skettenis 	cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
641b725ae77Skettenis       else
642b725ae77Skettenis         make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
643e93f7393Sniklas     }
644e93f7393Sniklas 
645b725ae77Skettenis   /* In synchronous case, all is well, just use the regular for loop. */
646*63addd46Skettenis   if (!target_can_async_p ())
647b725ae77Skettenis     {
648e93f7393Sniklas       for (; count > 0; count--)
649e93f7393Sniklas 	{
650e93f7393Sniklas 	  clear_proceed_status ();
651e93f7393Sniklas 
652e93f7393Sniklas 	  frame = get_current_frame ();
653e93f7393Sniklas 	  if (!frame)		/* Avoid coredump here.  Why tho? */
654e93f7393Sniklas 	    error ("No current frame");
655b725ae77Skettenis 	  step_frame_id = get_frame_id (frame);
656e93f7393Sniklas 
657e93f7393Sniklas 	  if (!single_inst)
658e93f7393Sniklas 	    {
659e93f7393Sniklas 	      find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
660e93f7393Sniklas 	      if (step_range_end == 0)
661e93f7393Sniklas 		{
662e93f7393Sniklas 		  char *name;
663e93f7393Sniklas 		  if (find_pc_partial_function (stop_pc, &name, &step_range_start,
664e93f7393Sniklas 						&step_range_end) == 0)
665e93f7393Sniklas 		    error ("Cannot find bounds of current function");
666e93f7393Sniklas 
667e93f7393Sniklas 		  target_terminal_ours ();
668e93f7393Sniklas 		  printf_filtered ("\
669e93f7393Sniklas Single stepping until exit from function %s, \n\
670e93f7393Sniklas which has no line number information.\n", name);
671e93f7393Sniklas 		}
672e93f7393Sniklas 	    }
673e93f7393Sniklas 	  else
674e93f7393Sniklas 	    {
675e93f7393Sniklas 	      /* Say we are stepping, but stop after one insn whatever it does.  */
676e93f7393Sniklas 	      step_range_start = step_range_end = 1;
677e93f7393Sniklas 	      if (!skip_subroutines)
678e93f7393Sniklas 		/* It is stepi.
679e93f7393Sniklas 		   Don't step over function calls, not even to functions lacking
680e93f7393Sniklas 		   line numbers.  */
681b725ae77Skettenis 		step_over_calls = STEP_OVER_NONE;
682e93f7393Sniklas 	    }
683e93f7393Sniklas 
684e93f7393Sniklas 	  if (skip_subroutines)
685b725ae77Skettenis 	    step_over_calls = STEP_OVER_ALL;
686e93f7393Sniklas 
687e93f7393Sniklas 	  step_multi = (count > 1);
688e93f7393Sniklas 	  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
689b725ae77Skettenis 
690e93f7393Sniklas 	  if (!stop_step)
691e93f7393Sniklas 	    break;
692e93f7393Sniklas 	}
693e93f7393Sniklas 
694e93f7393Sniklas       if (!single_inst || skip_subroutines)
695e93f7393Sniklas 	do_cleanups (cleanups);
696b725ae77Skettenis       return;
697e93f7393Sniklas     }
698b725ae77Skettenis   /* In case of asynchronous target things get complicated, do only
699b725ae77Skettenis      one step for now, before returning control to the event loop. Let
700b725ae77Skettenis      the continuation figure out how many other steps we need to do,
701b725ae77Skettenis      and handle them one at the time, through step_once(). */
702b725ae77Skettenis   else
703b725ae77Skettenis     {
704*63addd46Skettenis       if (target_can_async_p ())
705b725ae77Skettenis 	step_once (skip_subroutines, single_inst, count);
706b725ae77Skettenis     }
707b725ae77Skettenis }
708b725ae77Skettenis 
709b725ae77Skettenis /* Called after we are done with one step operation, to check whether
710b725ae77Skettenis    we need to step again, before we print the prompt and return control
711b725ae77Skettenis    to the user. If count is > 1, we will need to do one more call to
712b725ae77Skettenis    proceed(), via step_once(). Basically it is like step_once and
713b725ae77Skettenis    step_1_continuation are co-recursive. */
714b725ae77Skettenis static void
step_1_continuation(struct continuation_arg * arg)715b725ae77Skettenis step_1_continuation (struct continuation_arg *arg)
716b725ae77Skettenis {
717b725ae77Skettenis   int count;
718b725ae77Skettenis   int skip_subroutines;
719b725ae77Skettenis   int single_inst;
720b725ae77Skettenis 
721b725ae77Skettenis   skip_subroutines = arg->data.integer;
722b725ae77Skettenis   single_inst      = arg->next->data.integer;
723b725ae77Skettenis   count            = arg->next->next->data.integer;
724b725ae77Skettenis 
725b725ae77Skettenis   if (stop_step)
726b725ae77Skettenis     step_once (skip_subroutines, single_inst, count - 1);
727b725ae77Skettenis   else
728b725ae77Skettenis     if (!single_inst || skip_subroutines)
729b725ae77Skettenis       do_exec_cleanups (ALL_CLEANUPS);
730b725ae77Skettenis }
731b725ae77Skettenis 
732b725ae77Skettenis /* Do just one step operation. If count >1 we will have to set up a
733b725ae77Skettenis    continuation to be done after the target stops (after this one
734b725ae77Skettenis    step). This is useful to implement the 'step n' kind of commands, in
735b725ae77Skettenis    case of asynchronous targets. We had to split step_1 into two parts,
736b725ae77Skettenis    one to be done before proceed() and one afterwards. This function is
737b725ae77Skettenis    called in case of step n with n>1, after the first step operation has
738b725ae77Skettenis    been completed.*/
739b725ae77Skettenis static void
step_once(int skip_subroutines,int single_inst,int count)740b725ae77Skettenis step_once (int skip_subroutines, int single_inst, int count)
741b725ae77Skettenis {
742b725ae77Skettenis   struct continuation_arg *arg1;
743b725ae77Skettenis   struct continuation_arg *arg2;
744b725ae77Skettenis   struct continuation_arg *arg3;
745b725ae77Skettenis   struct frame_info *frame;
746b725ae77Skettenis 
747b725ae77Skettenis   if (count > 0)
748b725ae77Skettenis     {
749b725ae77Skettenis       clear_proceed_status ();
750b725ae77Skettenis 
751b725ae77Skettenis       frame = get_current_frame ();
752b725ae77Skettenis       if (!frame)		/* Avoid coredump here.  Why tho? */
753b725ae77Skettenis 	error ("No current frame");
754b725ae77Skettenis       step_frame_id = get_frame_id (frame);
755b725ae77Skettenis 
756b725ae77Skettenis       if (!single_inst)
757b725ae77Skettenis 	{
758b725ae77Skettenis 	  find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
759b725ae77Skettenis 
760b725ae77Skettenis 	  /* If we have no line info, switch to stepi mode.  */
761b725ae77Skettenis 	  if (step_range_end == 0 && step_stop_if_no_debug)
762b725ae77Skettenis 	    {
763b725ae77Skettenis 	      step_range_start = step_range_end = 1;
764b725ae77Skettenis 	    }
765b725ae77Skettenis 	  else if (step_range_end == 0)
766b725ae77Skettenis 	    {
767b725ae77Skettenis 	      char *name;
768b725ae77Skettenis 	      if (find_pc_partial_function (stop_pc, &name, &step_range_start,
769b725ae77Skettenis 					    &step_range_end) == 0)
770b725ae77Skettenis 		error ("Cannot find bounds of current function");
771b725ae77Skettenis 
772b725ae77Skettenis 	      target_terminal_ours ();
773b725ae77Skettenis 	      printf_filtered ("\
774b725ae77Skettenis Single stepping until exit from function %s, \n\
775b725ae77Skettenis which has no line number information.\n", name);
776b725ae77Skettenis 	    }
777b725ae77Skettenis 	}
778b725ae77Skettenis       else
779b725ae77Skettenis 	{
780b725ae77Skettenis 	  /* Say we are stepping, but stop after one insn whatever it does.  */
781b725ae77Skettenis 	  step_range_start = step_range_end = 1;
782b725ae77Skettenis 	  if (!skip_subroutines)
783b725ae77Skettenis 	    /* It is stepi.
784b725ae77Skettenis 	       Don't step over function calls, not even to functions lacking
785b725ae77Skettenis 	       line numbers.  */
786b725ae77Skettenis 	    step_over_calls = STEP_OVER_NONE;
787b725ae77Skettenis 	}
788b725ae77Skettenis 
789b725ae77Skettenis       if (skip_subroutines)
790b725ae77Skettenis 	step_over_calls = STEP_OVER_ALL;
791b725ae77Skettenis 
792b725ae77Skettenis       step_multi = (count > 1);
793b725ae77Skettenis       arg1 =
794b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
795b725ae77Skettenis       arg2 =
796b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
797b725ae77Skettenis       arg3 =
798b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
799b725ae77Skettenis       arg1->next = arg2;
800b725ae77Skettenis       arg1->data.integer = skip_subroutines;
801b725ae77Skettenis       arg2->next = arg3;
802b725ae77Skettenis       arg2->data.integer = single_inst;
803b725ae77Skettenis       arg3->next = NULL;
804b725ae77Skettenis       arg3->data.integer = count;
805b725ae77Skettenis       add_intermediate_continuation (step_1_continuation, arg1);
806b725ae77Skettenis       proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
807b725ae77Skettenis     }
808b725ae77Skettenis }
809b725ae77Skettenis 
810e93f7393Sniklas 
811e93f7393Sniklas /* Continue program at specified address.  */
812e93f7393Sniklas 
813e93f7393Sniklas static void
jump_command(char * arg,int from_tty)814b725ae77Skettenis jump_command (char *arg, int from_tty)
815e93f7393Sniklas {
816b725ae77Skettenis   CORE_ADDR addr;
817e93f7393Sniklas   struct symtabs_and_lines sals;
818e93f7393Sniklas   struct symtab_and_line sal;
819e93f7393Sniklas   struct symbol *fn;
820e93f7393Sniklas   struct symbol *sfn;
821b725ae77Skettenis   int async_exec = 0;
822e93f7393Sniklas 
823e93f7393Sniklas   ERROR_NO_INFERIOR;
824e93f7393Sniklas 
825b725ae77Skettenis   /* Find out whether we must run in the background. */
826b725ae77Skettenis   if (arg != NULL)
827b725ae77Skettenis     async_exec = strip_bg_char (&arg);
828b725ae77Skettenis 
829b725ae77Skettenis   /* If we must run in the background, but the target can't do it,
830b725ae77Skettenis      error out. */
831*63addd46Skettenis   if (async_exec && !target_can_async_p ())
832b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
833b725ae77Skettenis 
834b725ae77Skettenis   /* If we are not asked to run in the bg, then prepare to run in the
835b725ae77Skettenis      foreground, synchronously. */
836*63addd46Skettenis   if (!async_exec && target_can_async_p ())
837b725ae77Skettenis     {
838b725ae77Skettenis       /* Simulate synchronous execution */
839b725ae77Skettenis       async_disable_stdin ();
840b725ae77Skettenis     }
841b725ae77Skettenis 
842e93f7393Sniklas   if (!arg)
843e93f7393Sniklas     error_no_arg ("starting address");
844e93f7393Sniklas 
845e93f7393Sniklas   sals = decode_line_spec_1 (arg, 1);
846e93f7393Sniklas   if (sals.nelts != 1)
847e93f7393Sniklas     {
848e93f7393Sniklas       error ("Unreasonable jump request");
849e93f7393Sniklas     }
850e93f7393Sniklas 
851e93f7393Sniklas   sal = sals.sals[0];
852b725ae77Skettenis   xfree (sals.sals);
853e93f7393Sniklas 
854e93f7393Sniklas   if (sal.symtab == 0 && sal.pc == 0)
855e93f7393Sniklas     error ("No source file has been specified.");
856e93f7393Sniklas 
857e93f7393Sniklas   resolve_sal_pc (&sal);	/* May error out */
858e93f7393Sniklas 
859e93f7393Sniklas   /* See if we are trying to jump to another function. */
860e93f7393Sniklas   fn = get_frame_function (get_current_frame ());
861e93f7393Sniklas   sfn = find_pc_function (sal.pc);
862e93f7393Sniklas   if (fn != NULL && sfn != fn)
863e93f7393Sniklas     {
864e93f7393Sniklas       if (!query ("Line %d is not in `%s'.  Jump anyway? ", sal.line,
865b725ae77Skettenis 		  SYMBOL_PRINT_NAME (fn)))
866e93f7393Sniklas 	{
867e93f7393Sniklas 	  error ("Not confirmed.");
868e93f7393Sniklas 	  /* NOTREACHED */
869e93f7393Sniklas 	}
870e93f7393Sniklas     }
871e93f7393Sniklas 
872b725ae77Skettenis   if (sfn != NULL)
873b725ae77Skettenis     {
874b725ae77Skettenis       fixup_symbol_section (sfn, 0);
875b725ae77Skettenis       if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
876b725ae77Skettenis 	  !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
877b725ae77Skettenis 	{
878b725ae77Skettenis 	  if (!query ("WARNING!!!  Destination is in unmapped overlay!  Jump anyway? "))
879b725ae77Skettenis 	    {
880b725ae77Skettenis 	      error ("Not confirmed.");
881b725ae77Skettenis 	      /* NOTREACHED */
882b725ae77Skettenis 	    }
883b725ae77Skettenis 	}
884b725ae77Skettenis     }
885b725ae77Skettenis 
886e93f7393Sniklas   addr = sal.pc;
887e93f7393Sniklas 
888e93f7393Sniklas   if (from_tty)
889e93f7393Sniklas     {
890e93f7393Sniklas       printf_filtered ("Continuing at ");
891e93f7393Sniklas       print_address_numeric (addr, 1, gdb_stdout);
892e93f7393Sniklas       printf_filtered (".\n");
893e93f7393Sniklas     }
894e93f7393Sniklas 
895e93f7393Sniklas   clear_proceed_status ();
896e93f7393Sniklas   proceed (addr, TARGET_SIGNAL_0, 0);
897e93f7393Sniklas }
898b725ae77Skettenis 
899b725ae77Skettenis 
900b725ae77Skettenis /* Go to line or address in current procedure */
901b725ae77Skettenis static void
go_command(char * line_no,int from_tty)902b725ae77Skettenis go_command (char *line_no, int from_tty)
903b725ae77Skettenis {
904b725ae77Skettenis   if (line_no == (char *) NULL || !*line_no)
905b725ae77Skettenis     printf_filtered (GO_USAGE);
906b725ae77Skettenis   else
907b725ae77Skettenis     {
908b725ae77Skettenis       tbreak_command (line_no, from_tty);
909b725ae77Skettenis       jump_command (line_no, from_tty);
910b725ae77Skettenis     }
911b725ae77Skettenis }
912b725ae77Skettenis 
913e93f7393Sniklas 
914e93f7393Sniklas /* Continue program giving it specified signal.  */
915e93f7393Sniklas 
916e93f7393Sniklas static void
signal_command(char * signum_exp,int from_tty)917b725ae77Skettenis signal_command (char *signum_exp, int from_tty)
918e93f7393Sniklas {
919e93f7393Sniklas   enum target_signal oursig;
920e93f7393Sniklas 
921e93f7393Sniklas   dont_repeat ();		/* Too dangerous.  */
922e93f7393Sniklas   ERROR_NO_INFERIOR;
923e93f7393Sniklas 
924e93f7393Sniklas   if (!signum_exp)
925e93f7393Sniklas     error_no_arg ("signal number");
926e93f7393Sniklas 
927e93f7393Sniklas   /* It would be even slicker to make signal names be valid expressions,
928e93f7393Sniklas      (the type could be "enum $signal" or some such), then the user could
929e93f7393Sniklas      assign them to convenience variables.  */
930e93f7393Sniklas   oursig = target_signal_from_name (signum_exp);
931e93f7393Sniklas 
932e93f7393Sniklas   if (oursig == TARGET_SIGNAL_UNKNOWN)
933e93f7393Sniklas     {
934e93f7393Sniklas       /* No, try numeric.  */
935b725ae77Skettenis       int num = parse_and_eval_long (signum_exp);
936e93f7393Sniklas 
937e93f7393Sniklas       if (num == 0)
938e93f7393Sniklas 	oursig = TARGET_SIGNAL_0;
939e93f7393Sniklas       else
940e93f7393Sniklas 	oursig = target_signal_from_command (num);
941e93f7393Sniklas     }
942e93f7393Sniklas 
943e93f7393Sniklas   if (from_tty)
944e93f7393Sniklas     {
945e93f7393Sniklas       if (oursig == TARGET_SIGNAL_0)
946e93f7393Sniklas 	printf_filtered ("Continuing with no signal.\n");
947e93f7393Sniklas       else
948e93f7393Sniklas 	printf_filtered ("Continuing with signal %s.\n",
949e93f7393Sniklas 			 target_signal_to_name (oursig));
950e93f7393Sniklas     }
951e93f7393Sniklas 
952e93f7393Sniklas   clear_proceed_status ();
953e93f7393Sniklas   /* "signal 0" should not get stuck if we are stopped at a breakpoint.
954e93f7393Sniklas      FIXME: Neither should "signal foo" but when I tried passing
955e93f7393Sniklas      (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
956e93f7393Sniklas      tried to track down yet.  */
957e93f7393Sniklas   proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
958e93f7393Sniklas }
959e93f7393Sniklas 
960e93f7393Sniklas /* Proceed until we reach a different source line with pc greater than
961e93f7393Sniklas    our current one or exit the function.  We skip calls in both cases.
962e93f7393Sniklas 
963e93f7393Sniklas    Note that eventually this command should probably be changed so
964e93f7393Sniklas    that only source lines are printed out when we hit the breakpoint
965e93f7393Sniklas    we set.  This may involve changes to wait_for_inferior and the
966e93f7393Sniklas    proceed status code.  */
967e93f7393Sniklas 
968e93f7393Sniklas static void
until_next_command(int from_tty)969b725ae77Skettenis until_next_command (int from_tty)
970e93f7393Sniklas {
971e93f7393Sniklas   struct frame_info *frame;
972e93f7393Sniklas   CORE_ADDR pc;
973e93f7393Sniklas   struct symbol *func;
974e93f7393Sniklas   struct symtab_and_line sal;
975e93f7393Sniklas 
976e93f7393Sniklas   clear_proceed_status ();
977e93f7393Sniklas 
978e93f7393Sniklas   frame = get_current_frame ();
979e93f7393Sniklas 
980e93f7393Sniklas   /* Step until either exited from this function or greater
981e93f7393Sniklas      than the current line (if in symbolic section) or pc (if
982e93f7393Sniklas      not). */
983e93f7393Sniklas 
984e93f7393Sniklas   pc = read_pc ();
985e93f7393Sniklas   func = find_pc_function (pc);
986e93f7393Sniklas 
987e93f7393Sniklas   if (!func)
988e93f7393Sniklas     {
989e93f7393Sniklas       struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
990e93f7393Sniklas 
991e93f7393Sniklas       if (msymbol == NULL)
992e93f7393Sniklas 	error ("Execution is not within a known function.");
993e93f7393Sniklas 
994e93f7393Sniklas       step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
995e93f7393Sniklas       step_range_end = pc;
996e93f7393Sniklas     }
997e93f7393Sniklas   else
998e93f7393Sniklas     {
999e93f7393Sniklas       sal = find_pc_line (pc, 0);
1000e93f7393Sniklas 
1001e93f7393Sniklas       step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1002e93f7393Sniklas       step_range_end = sal.end;
1003e93f7393Sniklas     }
1004e93f7393Sniklas 
1005b725ae77Skettenis   step_over_calls = STEP_OVER_ALL;
1006b725ae77Skettenis   step_frame_id = get_frame_id (frame);
1007e93f7393Sniklas 
1008e93f7393Sniklas   step_multi = 0;		/* Only one call to proceed */
1009e93f7393Sniklas 
1010e93f7393Sniklas   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1011e93f7393Sniklas }
1012e93f7393Sniklas 
1013e93f7393Sniklas static void
until_command(char * arg,int from_tty)1014b725ae77Skettenis until_command (char *arg, int from_tty)
1015e93f7393Sniklas {
1016b725ae77Skettenis   int async_exec = 0;
1017b725ae77Skettenis 
1018e93f7393Sniklas   if (!target_has_execution)
1019e93f7393Sniklas     error ("The program is not running.");
1020b725ae77Skettenis 
1021b725ae77Skettenis   /* Find out whether we must run in the background. */
1022b725ae77Skettenis   if (arg != NULL)
1023b725ae77Skettenis     async_exec = strip_bg_char (&arg);
1024b725ae77Skettenis 
1025b725ae77Skettenis   /* If we must run in the background, but the target can't do it,
1026b725ae77Skettenis      error out. */
1027*63addd46Skettenis   if (async_exec && !target_can_async_p ())
1028b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
1029b725ae77Skettenis 
1030b725ae77Skettenis   /* If we are not asked to run in the bg, then prepare to run in the
1031b725ae77Skettenis      foreground, synchronously. */
1032*63addd46Skettenis   if (!async_exec && target_can_async_p ())
1033b725ae77Skettenis     {
1034b725ae77Skettenis       /* Simulate synchronous execution */
1035b725ae77Skettenis       async_disable_stdin ();
1036b725ae77Skettenis     }
1037b725ae77Skettenis 
1038e93f7393Sniklas   if (arg)
1039b725ae77Skettenis     until_break_command (arg, from_tty, 0);
1040e93f7393Sniklas   else
1041e93f7393Sniklas     until_next_command (from_tty);
1042e93f7393Sniklas }
1043e93f7393Sniklas 
1044e93f7393Sniklas static void
advance_command(char * arg,int from_tty)1045b725ae77Skettenis advance_command (char *arg, int from_tty)
1046b725ae77Skettenis {
1047b725ae77Skettenis   int async_exec = 0;
1048b725ae77Skettenis 
1049b725ae77Skettenis   if (!target_has_execution)
1050b725ae77Skettenis     error ("The program is not running.");
1051b725ae77Skettenis 
1052b725ae77Skettenis   if (arg == NULL)
1053b725ae77Skettenis     error_no_arg ("a location");
1054b725ae77Skettenis 
1055b725ae77Skettenis   /* Find out whether we must run in the background.  */
1056b725ae77Skettenis   if (arg != NULL)
1057b725ae77Skettenis     async_exec = strip_bg_char (&arg);
1058b725ae77Skettenis 
1059b725ae77Skettenis   /* If we must run in the background, but the target can't do it,
1060b725ae77Skettenis      error out.  */
1061*63addd46Skettenis   if (async_exec && !target_can_async_p ())
1062b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
1063b725ae77Skettenis 
1064b725ae77Skettenis   /* If we are not asked to run in the bg, then prepare to run in the
1065b725ae77Skettenis      foreground, synchronously.  */
1066*63addd46Skettenis   if (!async_exec && target_can_async_p ())
1067b725ae77Skettenis     {
1068b725ae77Skettenis       /* Simulate synchronous execution.  */
1069b725ae77Skettenis       async_disable_stdin ();
1070b725ae77Skettenis     }
1071b725ae77Skettenis 
1072b725ae77Skettenis   until_break_command (arg, from_tty, 1);
1073b725ae77Skettenis }
1074b725ae77Skettenis 
1075b725ae77Skettenis /* Print the result of a function at the end of a 'finish' command.  */
1076b725ae77Skettenis 
1077b725ae77Skettenis static void
print_return_value(int struct_return,struct type * value_type)1078b725ae77Skettenis print_return_value (int struct_return, struct type *value_type)
1079b725ae77Skettenis {
1080*63addd46Skettenis   struct gdbarch *gdbarch = current_gdbarch;
1081b725ae77Skettenis   struct cleanup *old_chain;
1082b725ae77Skettenis   struct ui_stream *stb;
1083b725ae77Skettenis   struct value *value;
1084b725ae77Skettenis 
1085*63addd46Skettenis   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1086*63addd46Skettenis 
1087b725ae77Skettenis   /* FIXME: 2003-09-27: When returning from a nested inferior function
1088b725ae77Skettenis      call, it's possible (with no help from the architecture vector)
1089b725ae77Skettenis      to locate and return/print a "struct return" value.  This is just
1090b725ae77Skettenis      a more complicated case of what is already being done in in the
1091b725ae77Skettenis      inferior function call code.  In fact, when inferior function
1092b725ae77Skettenis      calls are made async, this will likely be made the norm.  */
1093*63addd46Skettenis 
1094*63addd46Skettenis   switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
1095b725ae77Skettenis     {
1096*63addd46Skettenis     case RETURN_VALUE_REGISTER_CONVENTION:
1097*63addd46Skettenis     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1098b725ae77Skettenis       value = allocate_value (value_type);
1099b725ae77Skettenis       CHECK_TYPEDEF (value_type);
1100*63addd46Skettenis       gdbarch_return_value (current_gdbarch, value_type, stop_registers,
1101*63addd46Skettenis 			    VALUE_CONTENTS_RAW (value), NULL);
1102*63addd46Skettenis       break;
1103*63addd46Skettenis     case RETURN_VALUE_STRUCT_CONVENTION:
1104*63addd46Skettenis       value = NULL;
1105*63addd46Skettenis       break;
1106*63addd46Skettenis     default:
1107*63addd46Skettenis       internal_error (__FILE__, __LINE__, "bad switch");
1108b725ae77Skettenis     }
1109b725ae77Skettenis 
1110*63addd46Skettenis   if (value)
1111*63addd46Skettenis     {
1112b725ae77Skettenis       /* Print it.  */
1113b725ae77Skettenis       stb = ui_out_stream_new (uiout);
1114b725ae77Skettenis       old_chain = make_cleanup_ui_out_stream_delete (stb);
1115b725ae77Skettenis       ui_out_text (uiout, "Value returned is ");
1116b725ae77Skettenis       ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1117b725ae77Skettenis 			record_latest_value (value));
1118b725ae77Skettenis       ui_out_text (uiout, " = ");
1119b725ae77Skettenis       value_print (value, stb->stream, 0, Val_no_prettyprint);
1120b725ae77Skettenis       ui_out_field_stream (uiout, "return-value", stb);
1121b725ae77Skettenis       ui_out_text (uiout, "\n");
1122b725ae77Skettenis       do_cleanups (old_chain);
1123b725ae77Skettenis     }
1124*63addd46Skettenis   else
1125*63addd46Skettenis     {
1126*63addd46Skettenis       ui_out_text (uiout, "Value returned has type: ");
1127*63addd46Skettenis       ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1128*63addd46Skettenis       ui_out_text (uiout, ".");
1129*63addd46Skettenis       ui_out_text (uiout, " Cannot determine contents\n");
1130*63addd46Skettenis     }
1131*63addd46Skettenis }
1132b725ae77Skettenis 
1133b725ae77Skettenis /* Stuff that needs to be done by the finish command after the target
1134b725ae77Skettenis    has stopped.  In asynchronous mode, we wait for the target to stop
1135b725ae77Skettenis    in the call to poll or select in the event loop, so it is
1136b725ae77Skettenis    impossible to do all the stuff as part of the finish_command
1137b725ae77Skettenis    function itself.  The only chance we have to complete this command
1138b725ae77Skettenis    is in fetch_inferior_event, which is called by the event loop as
1139b725ae77Skettenis    soon as it detects that the target has stopped. This function is
1140b725ae77Skettenis    called via the cmd_continuation pointer.  */
1141b725ae77Skettenis 
1142b725ae77Skettenis static void
finish_command_continuation(struct continuation_arg * arg)1143b725ae77Skettenis finish_command_continuation (struct continuation_arg *arg)
1144b725ae77Skettenis {
1145b725ae77Skettenis   struct symbol *function;
1146b725ae77Skettenis   struct breakpoint *breakpoint;
1147b725ae77Skettenis   struct cleanup *cleanups;
1148b725ae77Skettenis 
1149b725ae77Skettenis   breakpoint = (struct breakpoint *) arg->data.pointer;
1150b725ae77Skettenis   function = (struct symbol *) arg->next->data.pointer;
1151b725ae77Skettenis   cleanups = (struct cleanup *) arg->next->next->data.pointer;
1152b725ae77Skettenis 
1153b725ae77Skettenis   if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1154b725ae77Skettenis       && function != NULL)
1155b725ae77Skettenis     {
1156b725ae77Skettenis       struct type *value_type;
1157b725ae77Skettenis       int struct_return;
1158b725ae77Skettenis       int gcc_compiled;
1159b725ae77Skettenis 
1160b725ae77Skettenis       value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1161b725ae77Skettenis       if (!value_type)
1162b725ae77Skettenis 	internal_error (__FILE__, __LINE__,
1163b725ae77Skettenis 			"finish_command: function has no target type");
1164b725ae77Skettenis 
1165b725ae77Skettenis       if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1166b725ae77Skettenis 	{
1167b725ae77Skettenis 	  do_exec_cleanups (cleanups);
1168b725ae77Skettenis 	  return;
1169b725ae77Skettenis 	}
1170b725ae77Skettenis 
1171b725ae77Skettenis       CHECK_TYPEDEF (value_type);
1172b725ae77Skettenis       gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1173b725ae77Skettenis       struct_return = using_struct_return (value_type, gcc_compiled);
1174b725ae77Skettenis 
1175b725ae77Skettenis       print_return_value (struct_return, value_type);
1176b725ae77Skettenis     }
1177b725ae77Skettenis 
1178b725ae77Skettenis   do_exec_cleanups (cleanups);
1179b725ae77Skettenis }
1180b725ae77Skettenis 
1181b725ae77Skettenis /* "finish": Set a temporary breakpoint at the place the selected
1182b725ae77Skettenis    frame will return to, then continue.  */
1183b725ae77Skettenis 
1184b725ae77Skettenis static void
finish_command(char * arg,int from_tty)1185b725ae77Skettenis finish_command (char *arg, int from_tty)
1186e93f7393Sniklas {
1187e93f7393Sniklas   struct symtab_and_line sal;
1188b725ae77Skettenis   struct frame_info *frame;
1189b725ae77Skettenis   struct symbol *function;
1190e93f7393Sniklas   struct breakpoint *breakpoint;
1191e93f7393Sniklas   struct cleanup *old_chain;
1192b725ae77Skettenis   struct continuation_arg *arg1, *arg2, *arg3;
1193b725ae77Skettenis 
1194b725ae77Skettenis   int async_exec = 0;
1195b725ae77Skettenis 
1196b725ae77Skettenis   /* Find out whether we must run in the background.  */
1197b725ae77Skettenis   if (arg != NULL)
1198b725ae77Skettenis     async_exec = strip_bg_char (&arg);
1199b725ae77Skettenis 
1200b725ae77Skettenis   /* If we must run in the background, but the target can't do it,
1201b725ae77Skettenis      error out.  */
1202*63addd46Skettenis   if (async_exec && !target_can_async_p ())
1203b725ae77Skettenis     error ("Asynchronous execution not supported on this target.");
1204b725ae77Skettenis 
1205b725ae77Skettenis   /* If we are not asked to run in the bg, then prepare to run in the
1206b725ae77Skettenis      foreground, synchronously.  */
1207*63addd46Skettenis   if (!async_exec && target_can_async_p ())
1208b725ae77Skettenis     {
1209b725ae77Skettenis       /* Simulate synchronous execution.  */
1210b725ae77Skettenis       async_disable_stdin ();
1211b725ae77Skettenis     }
1212e93f7393Sniklas 
1213e93f7393Sniklas   if (arg)
1214e93f7393Sniklas     error ("The \"finish\" command does not take any arguments.");
1215e93f7393Sniklas   if (!target_has_execution)
1216e93f7393Sniklas     error ("The program is not running.");
1217b725ae77Skettenis   if (deprecated_selected_frame == NULL)
1218e93f7393Sniklas     error ("No selected frame.");
1219e93f7393Sniklas 
1220b725ae77Skettenis   frame = get_prev_frame (deprecated_selected_frame);
1221e93f7393Sniklas   if (frame == 0)
1222e93f7393Sniklas     error ("\"finish\" not meaningful in the outermost frame.");
1223e93f7393Sniklas 
1224e93f7393Sniklas   clear_proceed_status ();
1225e93f7393Sniklas 
1226b725ae77Skettenis   sal = find_pc_line (get_frame_pc (frame), 0);
1227b725ae77Skettenis   sal.pc = get_frame_pc (frame);
1228e93f7393Sniklas 
1229b725ae77Skettenis   breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
1230e93f7393Sniklas 
1231*63addd46Skettenis   if (!target_can_async_p ())
1232b725ae77Skettenis     old_chain = make_cleanup_delete_breakpoint (breakpoint);
1233b725ae77Skettenis   else
1234b725ae77Skettenis     old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
1235e93f7393Sniklas 
1236e93f7393Sniklas   /* Find the function we will return from.  */
1237e93f7393Sniklas 
1238b725ae77Skettenis   function = find_pc_function (get_frame_pc (deprecated_selected_frame));
1239e93f7393Sniklas 
1240b725ae77Skettenis   /* Print info on the selected frame, including level number but not
1241b725ae77Skettenis      source.  */
1242e93f7393Sniklas   if (from_tty)
1243e93f7393Sniklas     {
1244e93f7393Sniklas       printf_filtered ("Run till exit from ");
1245*63addd46Skettenis       print_stack_frame (get_selected_frame (), 1, LOCATION);
1246b725ae77Skettenis     }
1247b725ae77Skettenis 
1248b725ae77Skettenis   /* If running asynchronously and the target support asynchronous
1249b725ae77Skettenis      execution, set things up for the rest of the finish command to be
1250b725ae77Skettenis      completed later on, when gdb has detected that the target has
1251b725ae77Skettenis      stopped, in fetch_inferior_event.  */
1252*63addd46Skettenis   if (target_can_async_p ())
1253b725ae77Skettenis     {
1254b725ae77Skettenis       arg1 =
1255b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1256b725ae77Skettenis       arg2 =
1257b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1258b725ae77Skettenis       arg3 =
1259b725ae77Skettenis 	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1260b725ae77Skettenis       arg1->next = arg2;
1261b725ae77Skettenis       arg2->next = arg3;
1262b725ae77Skettenis       arg3->next = NULL;
1263b725ae77Skettenis       arg1->data.pointer = breakpoint;
1264b725ae77Skettenis       arg2->data.pointer = function;
1265b725ae77Skettenis       arg3->data.pointer = old_chain;
1266b725ae77Skettenis       add_continuation (finish_command_continuation, arg1);
1267e93f7393Sniklas     }
1268e93f7393Sniklas 
1269e93f7393Sniklas   proceed_to_finish = 1;	/* We want stop_registers, please...  */
1270e93f7393Sniklas   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1271e93f7393Sniklas 
1272b725ae77Skettenis   /* Do this only if not running asynchronously or if the target
1273b725ae77Skettenis      cannot do async execution.  Otherwise, complete this command when
1274b725ae77Skettenis      the target actually stops, in fetch_inferior_event.  */
1275*63addd46Skettenis   if (!target_can_async_p ())
1276b725ae77Skettenis     {
1277e93f7393Sniklas       /* Did we stop at our breakpoint?  */
1278e93f7393Sniklas       if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1279b725ae77Skettenis 	  && function != NULL)
1280e93f7393Sniklas 	{
1281e93f7393Sniklas 	  struct type *value_type;
1282b725ae77Skettenis 	  int struct_return;
1283b725ae77Skettenis 	  int gcc_compiled;
1284e93f7393Sniklas 
1285e93f7393Sniklas 	  value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1286e93f7393Sniklas 	  if (!value_type)
1287b725ae77Skettenis 	    internal_error (__FILE__, __LINE__,
1288b725ae77Skettenis 			    "finish_command: function has no target type");
1289e93f7393Sniklas 
1290b725ae77Skettenis 	  /* FIXME: Shouldn't we do the cleanups before returning?  */
1291e93f7393Sniklas 	  if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1292e93f7393Sniklas 	    return;
1293e93f7393Sniklas 
1294b725ae77Skettenis 	  CHECK_TYPEDEF (value_type);
1295b725ae77Skettenis 	  gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1296b725ae77Skettenis 	  struct_return = using_struct_return (value_type, gcc_compiled);
1297e93f7393Sniklas 
1298b725ae77Skettenis 	  print_return_value (struct_return, value_type);
1299e93f7393Sniklas 	}
1300b725ae77Skettenis 
1301e93f7393Sniklas       do_cleanups (old_chain);
1302e93f7393Sniklas     }
1303b725ae77Skettenis }
1304e93f7393Sniklas 
1305b725ae77Skettenis 
1306e93f7393Sniklas static void
program_info(char * args,int from_tty)1307b725ae77Skettenis program_info (char *args, int from_tty)
1308e93f7393Sniklas {
1309e93f7393Sniklas   bpstat bs = stop_bpstat;
1310e93f7393Sniklas   int num = bpstat_num (&bs);
1311e93f7393Sniklas 
1312e93f7393Sniklas   if (!target_has_execution)
1313e93f7393Sniklas     {
1314e93f7393Sniklas       printf_filtered ("The program being debugged is not being run.\n");
1315e93f7393Sniklas       return;
1316e93f7393Sniklas     }
1317e93f7393Sniklas 
1318e93f7393Sniklas   target_files_info ();
1319e93f7393Sniklas   printf_filtered ("Program stopped at %s.\n",
1320*63addd46Skettenis 		   hex_string ((unsigned long) stop_pc));
1321e93f7393Sniklas   if (stop_step)
1322e93f7393Sniklas     printf_filtered ("It stopped after being stepped.\n");
1323e93f7393Sniklas   else if (num != 0)
1324e93f7393Sniklas     {
1325e93f7393Sniklas       /* There may be several breakpoints in the same place, so this
1326e93f7393Sniklas          isn't as strange as it seems.  */
1327e93f7393Sniklas       while (num != 0)
1328e93f7393Sniklas 	{
1329e93f7393Sniklas 	  if (num < 0)
1330b725ae77Skettenis 	    {
1331b725ae77Skettenis 	      printf_filtered ("It stopped at a breakpoint that has ");
1332b725ae77Skettenis 	      printf_filtered ("since been deleted.\n");
1333b725ae77Skettenis 	    }
1334e93f7393Sniklas 	  else
1335e93f7393Sniklas 	    printf_filtered ("It stopped at breakpoint %d.\n", num);
1336e93f7393Sniklas 	  num = bpstat_num (&bs);
1337e93f7393Sniklas 	}
1338e93f7393Sniklas     }
1339e93f7393Sniklas   else if (stop_signal != TARGET_SIGNAL_0)
1340e93f7393Sniklas     {
1341e93f7393Sniklas       printf_filtered ("It stopped with signal %s, %s.\n",
1342e93f7393Sniklas 		       target_signal_to_name (stop_signal),
1343e93f7393Sniklas 		       target_signal_to_string (stop_signal));
1344e93f7393Sniklas     }
1345e93f7393Sniklas 
1346e93f7393Sniklas   if (!from_tty)
1347b725ae77Skettenis     {
1348b725ae77Skettenis       printf_filtered ("Type \"info stack\" or \"info registers\" ");
1349b725ae77Skettenis       printf_filtered ("for more information.\n");
1350b725ae77Skettenis     }
1351e93f7393Sniklas }
1352e93f7393Sniklas 
1353e93f7393Sniklas static void
environment_info(char * var,int from_tty)1354b725ae77Skettenis environment_info (char *var, int from_tty)
1355e93f7393Sniklas {
1356e93f7393Sniklas   if (var)
1357e93f7393Sniklas     {
1358b725ae77Skettenis       char *val = get_in_environ (inferior_environ, var);
1359e93f7393Sniklas       if (val)
1360e93f7393Sniklas 	{
1361e93f7393Sniklas 	  puts_filtered (var);
1362e93f7393Sniklas 	  puts_filtered (" = ");
1363e93f7393Sniklas 	  puts_filtered (val);
1364e93f7393Sniklas 	  puts_filtered ("\n");
1365e93f7393Sniklas 	}
1366e93f7393Sniklas       else
1367e93f7393Sniklas 	{
1368e93f7393Sniklas 	  puts_filtered ("Environment variable \"");
1369e93f7393Sniklas 	  puts_filtered (var);
1370e93f7393Sniklas 	  puts_filtered ("\" not defined.\n");
1371e93f7393Sniklas 	}
1372e93f7393Sniklas     }
1373e93f7393Sniklas   else
1374e93f7393Sniklas     {
1375b725ae77Skettenis       char **vector = environ_vector (inferior_environ);
1376e93f7393Sniklas       while (*vector)
1377e93f7393Sniklas 	{
1378e93f7393Sniklas 	  puts_filtered (*vector++);
1379e93f7393Sniklas 	  puts_filtered ("\n");
1380e93f7393Sniklas 	}
1381e93f7393Sniklas     }
1382e93f7393Sniklas }
1383e93f7393Sniklas 
1384e93f7393Sniklas static void
set_environment_command(char * arg,int from_tty)1385b725ae77Skettenis set_environment_command (char *arg, int from_tty)
1386e93f7393Sniklas {
1387b725ae77Skettenis   char *p, *val, *var;
1388e93f7393Sniklas   int nullset = 0;
1389e93f7393Sniklas 
1390e93f7393Sniklas   if (arg == 0)
1391e93f7393Sniklas     error_no_arg ("environment variable and value");
1392e93f7393Sniklas 
1393e93f7393Sniklas   /* Find seperation between variable name and value */
1394e93f7393Sniklas   p = (char *) strchr (arg, '=');
1395e93f7393Sniklas   val = (char *) strchr (arg, ' ');
1396e93f7393Sniklas 
1397e93f7393Sniklas   if (p != 0 && val != 0)
1398e93f7393Sniklas     {
1399e93f7393Sniklas       /* We have both a space and an equals.  If the space is before the
1400e93f7393Sniklas          equals, walk forward over the spaces til we see a nonspace
1401e93f7393Sniklas          (possibly the equals). */
1402e93f7393Sniklas       if (p > val)
1403e93f7393Sniklas 	while (*val == ' ')
1404e93f7393Sniklas 	  val++;
1405e93f7393Sniklas 
1406e93f7393Sniklas       /* Now if the = is after the char following the spaces,
1407e93f7393Sniklas          take the char following the spaces.  */
1408e93f7393Sniklas       if (p > val)
1409e93f7393Sniklas 	p = val - 1;
1410e93f7393Sniklas     }
1411e93f7393Sniklas   else if (val != 0 && p == 0)
1412e93f7393Sniklas     p = val;
1413e93f7393Sniklas 
1414e93f7393Sniklas   if (p == arg)
1415e93f7393Sniklas     error_no_arg ("environment variable to set");
1416e93f7393Sniklas 
1417e93f7393Sniklas   if (p == 0 || p[1] == 0)
1418e93f7393Sniklas     {
1419e93f7393Sniklas       nullset = 1;
1420e93f7393Sniklas       if (p == 0)
1421e93f7393Sniklas 	p = arg + strlen (arg);	/* So that savestring below will work */
1422e93f7393Sniklas     }
1423e93f7393Sniklas   else
1424e93f7393Sniklas     {
1425e93f7393Sniklas       /* Not setting variable value to null */
1426e93f7393Sniklas       val = p + 1;
1427e93f7393Sniklas       while (*val == ' ' || *val == '\t')
1428e93f7393Sniklas 	val++;
1429e93f7393Sniklas     }
1430e93f7393Sniklas 
1431b725ae77Skettenis   while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1432b725ae77Skettenis     p--;
1433e93f7393Sniklas 
1434e93f7393Sniklas   var = savestring (arg, p - arg);
1435e93f7393Sniklas   if (nullset)
1436e93f7393Sniklas     {
1437b725ae77Skettenis       printf_filtered ("Setting environment variable ");
1438b725ae77Skettenis       printf_filtered ("\"%s\" to null value.\n", var);
1439e93f7393Sniklas       set_in_environ (inferior_environ, var, "");
1440e93f7393Sniklas     }
1441e93f7393Sniklas   else
1442e93f7393Sniklas     set_in_environ (inferior_environ, var, val);
1443b725ae77Skettenis   xfree (var);
1444e93f7393Sniklas }
1445e93f7393Sniklas 
1446e93f7393Sniklas static void
unset_environment_command(char * var,int from_tty)1447b725ae77Skettenis unset_environment_command (char *var, int from_tty)
1448e93f7393Sniklas {
1449e93f7393Sniklas   if (var == 0)
1450e93f7393Sniklas     {
1451e93f7393Sniklas       /* If there is no argument, delete all environment variables.
1452e93f7393Sniklas          Ask for confirmation if reading from the terminal.  */
1453e93f7393Sniklas       if (!from_tty || query ("Delete all environment variables? "))
1454e93f7393Sniklas 	{
1455e93f7393Sniklas 	  free_environ (inferior_environ);
1456e93f7393Sniklas 	  inferior_environ = make_environ ();
1457e93f7393Sniklas 	}
1458e93f7393Sniklas     }
1459e93f7393Sniklas   else
1460e93f7393Sniklas     unset_in_environ (inferior_environ, var);
1461e93f7393Sniklas }
1462e93f7393Sniklas 
1463e93f7393Sniklas /* Handle the execution path (PATH variable) */
1464e93f7393Sniklas 
1465e93f7393Sniklas static const char path_var_name[] = "PATH";
1466e93f7393Sniklas 
1467e93f7393Sniklas static void
path_info(char * args,int from_tty)1468b725ae77Skettenis path_info (char *args, int from_tty)
1469e93f7393Sniklas {
1470e93f7393Sniklas   puts_filtered ("Executable and object file path: ");
1471e93f7393Sniklas   puts_filtered (get_in_environ (inferior_environ, path_var_name));
1472e93f7393Sniklas   puts_filtered ("\n");
1473e93f7393Sniklas }
1474e93f7393Sniklas 
1475e93f7393Sniklas /* Add zero or more directories to the front of the execution path.  */
1476e93f7393Sniklas 
1477e93f7393Sniklas static void
path_command(char * dirname,int from_tty)1478b725ae77Skettenis path_command (char *dirname, int from_tty)
1479e93f7393Sniklas {
1480e93f7393Sniklas   char *exec_path;
1481e93f7393Sniklas   char *env;
1482e93f7393Sniklas   dont_repeat ();
1483e93f7393Sniklas   env = get_in_environ (inferior_environ, path_var_name);
1484e93f7393Sniklas   /* Can be null if path is not set */
1485e93f7393Sniklas   if (!env)
1486e93f7393Sniklas     env = "";
1487b725ae77Skettenis   exec_path = xstrdup (env);
1488e93f7393Sniklas   mod_path (dirname, &exec_path);
1489e93f7393Sniklas   set_in_environ (inferior_environ, path_var_name, exec_path);
1490b725ae77Skettenis   xfree (exec_path);
1491e93f7393Sniklas   if (from_tty)
1492e93f7393Sniklas     path_info ((char *) NULL, from_tty);
1493e93f7393Sniklas }
1494e93f7393Sniklas 
1495e93f7393Sniklas 
1496b725ae77Skettenis /* Print out the machine register regnum. If regnum is -1, print all
1497b725ae77Skettenis    registers (print_all == 1) or all non-float and non-vector
1498b725ae77Skettenis    registers (print_all == 0).
1499e93f7393Sniklas 
1500e93f7393Sniklas    For most machines, having all_registers_info() print the
1501b725ae77Skettenis    register(s) one per line is good enough.  If a different format is
1502b725ae77Skettenis    required, (eg, for MIPS or Pyramid 90x, which both have lots of
1503b725ae77Skettenis    regs), or there is an existing convention for showing all the
1504b725ae77Skettenis    registers, define the architecture method PRINT_REGISTERS_INFO to
1505b725ae77Skettenis    provide that format.  */
1506e93f7393Sniklas 
1507b725ae77Skettenis void
default_print_registers_info(struct gdbarch * gdbarch,struct ui_file * file,struct frame_info * frame,int regnum,int print_all)1508b725ae77Skettenis default_print_registers_info (struct gdbarch *gdbarch,
1509b725ae77Skettenis 			      struct ui_file *file,
1510b725ae77Skettenis 			      struct frame_info *frame,
1511b725ae77Skettenis 			      int regnum, int print_all)
1512e93f7393Sniklas {
1513b725ae77Skettenis   int i;
1514b725ae77Skettenis   const int numregs = NUM_REGS + NUM_PSEUDO_REGS;
1515*63addd46Skettenis   char buffer[MAX_REGISTER_SIZE];
1516e93f7393Sniklas 
1517e93f7393Sniklas   for (i = 0; i < numregs; i++)
1518e93f7393Sniklas     {
1519b725ae77Skettenis       /* Decide between printing all regs, non-float / vector regs, or
1520b725ae77Skettenis          specific reg.  */
1521b725ae77Skettenis       if (regnum == -1)
1522b725ae77Skettenis 	{
1523b725ae77Skettenis 	  if (print_all)
1524b725ae77Skettenis 	    {
1525b725ae77Skettenis 	      if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1526e93f7393Sniklas 		continue;
1527b725ae77Skettenis 	    }
1528b725ae77Skettenis 	  else
1529b725ae77Skettenis 	    {
1530b725ae77Skettenis 	      if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1531b725ae77Skettenis 		continue;
1532b725ae77Skettenis 	    }
1533b725ae77Skettenis 	}
1534b725ae77Skettenis       else
1535b725ae77Skettenis 	{
1536e93f7393Sniklas 	  if (i != regnum)
1537e93f7393Sniklas 	    continue;
1538e93f7393Sniklas 	}
1539e93f7393Sniklas 
1540e93f7393Sniklas       /* If the register name is empty, it is undefined for this
1541e93f7393Sniklas          processor, so don't display anything.  */
1542b725ae77Skettenis       if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1543e93f7393Sniklas 	continue;
1544e93f7393Sniklas 
1545b725ae77Skettenis       fputs_filtered (REGISTER_NAME (i), file);
1546b725ae77Skettenis       print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), file);
1547e93f7393Sniklas 
1548e93f7393Sniklas       /* Get the data in raw format.  */
1549*63addd46Skettenis       if (! frame_register_read (frame, i, buffer))
1550e93f7393Sniklas 	{
1551b725ae77Skettenis 	  fprintf_filtered (file, "*value not available*\n");
1552e93f7393Sniklas 	  continue;
1553e93f7393Sniklas 	}
1554e93f7393Sniklas 
1555b725ae77Skettenis       /* If virtual format is floating, print it that way, and in raw
1556b725ae77Skettenis          hex.  */
1557b725ae77Skettenis       if (TYPE_CODE (register_type (current_gdbarch, i)) == TYPE_CODE_FLT)
1558e93f7393Sniklas 	{
1559b725ae77Skettenis 	  int j;
1560e93f7393Sniklas 
1561*63addd46Skettenis 	  val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1562b725ae77Skettenis 		     file, 0, 1, 0, Val_pretty_default);
1563b725ae77Skettenis 
1564b725ae77Skettenis 	  fprintf_filtered (file, "\t(raw 0x");
1565*63addd46Skettenis 	  for (j = 0; j < register_size (current_gdbarch, i); j++)
1566b725ae77Skettenis 	    {
1567b725ae77Skettenis 	      int idx;
1568b725ae77Skettenis 	      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1569b725ae77Skettenis 		idx = j;
1570e93f7393Sniklas 	      else
1571*63addd46Skettenis 		idx = register_size (current_gdbarch, i) - 1 - j;
1572*63addd46Skettenis 	      fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1573e93f7393Sniklas 	    }
1574b725ae77Skettenis 	  fprintf_filtered (file, ")");
1575e93f7393Sniklas 	}
1576e93f7393Sniklas       else
1577e93f7393Sniklas 	{
1578b725ae77Skettenis 	  /* Print the register in hex.  */
1579*63addd46Skettenis 	  val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1580b725ae77Skettenis 		     file, 'x', 1, 0, Val_pretty_default);
1581b725ae77Skettenis           /* If not a vector register, print it also according to its
1582b725ae77Skettenis              natural format.  */
1583b725ae77Skettenis 	  if (TYPE_VECTOR (register_type (current_gdbarch, i)) == 0)
1584b725ae77Skettenis 	    {
1585b725ae77Skettenis 	      fprintf_filtered (file, "\t");
1586*63addd46Skettenis 	      val_print (register_type (current_gdbarch, i), buffer, 0, 0,
1587b725ae77Skettenis 			 file, 0, 1, 0, Val_pretty_default);
1588e93f7393Sniklas 	    }
1589e93f7393Sniklas 	}
1590e93f7393Sniklas 
1591b725ae77Skettenis       fprintf_filtered (file, "\n");
1592b725ae77Skettenis     }
1593b725ae77Skettenis }
1594b725ae77Skettenis 
1595b725ae77Skettenis void
registers_info(char * addr_exp,int fpregs)1596b725ae77Skettenis registers_info (char *addr_exp, int fpregs)
1597e93f7393Sniklas {
1598e93f7393Sniklas   int regnum, numregs;
1599b725ae77Skettenis   char *end;
1600e93f7393Sniklas 
1601e93f7393Sniklas   if (!target_has_registers)
1602e93f7393Sniklas     error ("The program has no registers now.");
1603b725ae77Skettenis   if (deprecated_selected_frame == NULL)
1604e93f7393Sniklas     error ("No selected frame.");
1605e93f7393Sniklas 
1606e93f7393Sniklas   if (!addr_exp)
1607e93f7393Sniklas     {
1608b725ae77Skettenis       gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1609b725ae77Skettenis 				    deprecated_selected_frame, -1, fpregs);
1610e93f7393Sniklas       return;
1611e93f7393Sniklas     }
1612e93f7393Sniklas 
1613b725ae77Skettenis   while (*addr_exp != '\0')
1614e93f7393Sniklas     {
1615b725ae77Skettenis       char *start;
1616b725ae77Skettenis       const char *end;
1617b725ae77Skettenis 
1618b725ae77Skettenis       /* Keep skipping leading white space.  */
1619b725ae77Skettenis       if (isspace ((*addr_exp)))
1620b725ae77Skettenis 	{
1621e93f7393Sniklas 	  addr_exp++;
1622b725ae77Skettenis 	  continue;
1623e93f7393Sniklas 	}
1624e93f7393Sniklas 
1625b725ae77Skettenis       /* Discard any leading ``$''.  Check that there is something
1626b725ae77Skettenis          resembling a register following it.  */
1627b725ae77Skettenis       if (addr_exp[0] == '$')
1628b725ae77Skettenis 	addr_exp++;
1629b725ae77Skettenis       if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1630b725ae77Skettenis 	error ("Missing register name");
1631b725ae77Skettenis 
1632b725ae77Skettenis       /* Find the start/end of this register name/num/group.  */
1633b725ae77Skettenis       start = addr_exp;
1634b725ae77Skettenis       while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1635b725ae77Skettenis 	addr_exp++;
1636b725ae77Skettenis       end = addr_exp;
1637b725ae77Skettenis 
1638b725ae77Skettenis       /* Figure out what we've found and display it.  */
1639b725ae77Skettenis 
1640b725ae77Skettenis       /* A register name?  */
1641b725ae77Skettenis       {
1642b725ae77Skettenis 	int regnum = frame_map_name_to_regnum (deprecated_selected_frame,
1643b725ae77Skettenis 					       start, end - start);
1644b725ae77Skettenis 	if (regnum >= 0)
1645b725ae77Skettenis 	  {
1646b725ae77Skettenis 	    gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1647b725ae77Skettenis 					  deprecated_selected_frame, regnum, fpregs);
1648b725ae77Skettenis 	    continue;
1649b725ae77Skettenis 	  }
1650b725ae77Skettenis       }
1651b725ae77Skettenis 
1652b725ae77Skettenis       /* A register number?  (how portable is this one?).  */
1653b725ae77Skettenis       {
1654b725ae77Skettenis 	char *endptr;
1655b725ae77Skettenis 	int regnum = strtol (start, &endptr, 0);
1656b725ae77Skettenis 	if (endptr == end
1657b725ae77Skettenis 	    && regnum >= 0
1658b725ae77Skettenis 	    && regnum < NUM_REGS + NUM_PSEUDO_REGS)
1659b725ae77Skettenis 	  {
1660b725ae77Skettenis 	    gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1661b725ae77Skettenis 					  deprecated_selected_frame, regnum, fpregs);
1662b725ae77Skettenis 	    continue;
1663b725ae77Skettenis 	  }
1664b725ae77Skettenis       }
1665b725ae77Skettenis 
1666b725ae77Skettenis       /* A register group?  */
1667b725ae77Skettenis       {
1668b725ae77Skettenis 	struct reggroup *group;
1669b725ae77Skettenis 	for (group = reggroup_next (current_gdbarch, NULL);
1670b725ae77Skettenis 	     group != NULL;
1671b725ae77Skettenis 	     group = reggroup_next (current_gdbarch, group))
1672b725ae77Skettenis 	  {
1673b725ae77Skettenis 	    /* Don't bother with a length check.  Should the user
1674b725ae77Skettenis 	       enter a short register group name, go with the first
1675b725ae77Skettenis 	       group that matches.  */
1676b725ae77Skettenis 	    if (strncmp (start, reggroup_name (group), end - start) == 0)
1677b725ae77Skettenis 	      break;
1678b725ae77Skettenis 	  }
1679b725ae77Skettenis 	if (group != NULL)
1680b725ae77Skettenis 	  {
1681b725ae77Skettenis 	    int regnum;
1682b725ae77Skettenis 	    for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1683b725ae77Skettenis 	      {
1684b725ae77Skettenis 		if (gdbarch_register_reggroup_p (current_gdbarch, regnum,
1685b725ae77Skettenis 						 group))
1686b725ae77Skettenis 		  gdbarch_print_registers_info (current_gdbarch,
1687b725ae77Skettenis 						gdb_stdout, deprecated_selected_frame,
1688b725ae77Skettenis 						regnum, fpregs);
1689b725ae77Skettenis 	      }
1690b725ae77Skettenis 	    continue;
1691b725ae77Skettenis 	  }
1692b725ae77Skettenis       }
1693b725ae77Skettenis 
1694b725ae77Skettenis       /* Nothing matched.  */
1695b725ae77Skettenis       error ("Invalid register `%.*s'", (int) (end - start), start);
1696b725ae77Skettenis     }
1697b725ae77Skettenis }
1698b725ae77Skettenis 
1699b725ae77Skettenis void
all_registers_info(char * addr_exp,int from_tty)1700b725ae77Skettenis all_registers_info (char *addr_exp, int from_tty)
1701e93f7393Sniklas {
1702e93f7393Sniklas   registers_info (addr_exp, 1);
1703e93f7393Sniklas }
1704e93f7393Sniklas 
1705e93f7393Sniklas static void
nofp_registers_info(char * addr_exp,int from_tty)1706b725ae77Skettenis nofp_registers_info (char *addr_exp, int from_tty)
1707e93f7393Sniklas {
1708e93f7393Sniklas   registers_info (addr_exp, 0);
1709e93f7393Sniklas }
1710b725ae77Skettenis 
1711b725ae77Skettenis static void
print_vector_info(struct gdbarch * gdbarch,struct ui_file * file,struct frame_info * frame,const char * args)1712b725ae77Skettenis print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1713b725ae77Skettenis 		   struct frame_info *frame, const char *args)
1714b725ae77Skettenis {
1715b725ae77Skettenis   if (!target_has_registers)
1716b725ae77Skettenis     error ("The program has no registers now.");
1717b725ae77Skettenis   if (deprecated_selected_frame == NULL)
1718b725ae77Skettenis     error ("No selected frame.");
1719b725ae77Skettenis 
1720b725ae77Skettenis   if (gdbarch_print_vector_info_p (gdbarch))
1721b725ae77Skettenis     gdbarch_print_vector_info (gdbarch, file, frame, args);
1722b725ae77Skettenis   else
1723b725ae77Skettenis     {
1724b725ae77Skettenis       int regnum;
1725b725ae77Skettenis       int printed_something = 0;
1726b725ae77Skettenis 
1727b725ae77Skettenis       for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1728b725ae77Skettenis 	{
1729b725ae77Skettenis 	  if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1730b725ae77Skettenis 	    {
1731b725ae77Skettenis 	      printed_something = 1;
1732b725ae77Skettenis 	      gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1733b725ae77Skettenis 	    }
1734b725ae77Skettenis 	}
1735b725ae77Skettenis       if (!printed_something)
1736b725ae77Skettenis 	fprintf_filtered (file, "No vector information\n");
1737b725ae77Skettenis     }
1738b725ae77Skettenis }
1739b725ae77Skettenis 
1740b725ae77Skettenis static void
vector_info(char * args,int from_tty)1741b725ae77Skettenis vector_info (char *args, int from_tty)
1742b725ae77Skettenis {
1743b725ae77Skettenis   print_vector_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
1744b725ae77Skettenis }
1745e93f7393Sniklas 
1746b725ae77Skettenis 
1747e93f7393Sniklas /*
1748e93f7393Sniklas  * TODO:
1749e93f7393Sniklas  * Should save/restore the tty state since it might be that the
1750e93f7393Sniklas  * program to be debugged was started on this tty and it wants
1751e93f7393Sniklas  * the tty in some state other than what we want.  If it's running
1752e93f7393Sniklas  * on another terminal or without a terminal, then saving and
1753e93f7393Sniklas  * restoring the tty state is a harmless no-op.
1754e93f7393Sniklas  * This only needs to be done if we are attaching to a process.
1755e93f7393Sniklas  */
1756e93f7393Sniklas 
1757e93f7393Sniklas /*
1758e93f7393Sniklas    attach_command --
1759e93f7393Sniklas    takes a program started up outside of gdb and ``attaches'' to it.
1760e93f7393Sniklas    This stops it cold in its tracks and allows us to start debugging it.
1761e93f7393Sniklas    and wait for the trace-trap that results from attaching.  */
1762e93f7393Sniklas 
1763e93f7393Sniklas void
attach_command(char * args,int from_tty)1764b725ae77Skettenis attach_command (char *args, int from_tty)
1765e93f7393Sniklas {
1766b725ae77Skettenis   char *exec_file;
1767b725ae77Skettenis   char *full_exec_path = NULL;
1768e93f7393Sniklas 
1769e93f7393Sniklas   dont_repeat ();		/* Not for the faint of heart */
1770e93f7393Sniklas 
1771e93f7393Sniklas   if (target_has_execution)
1772e93f7393Sniklas     {
1773e93f7393Sniklas       if (query ("A program is being debugged already.  Kill it? "))
1774e93f7393Sniklas 	target_kill ();
1775e93f7393Sniklas       else
1776e93f7393Sniklas 	error ("Not killed.");
1777e93f7393Sniklas     }
1778e93f7393Sniklas 
1779e93f7393Sniklas   target_attach (args, from_tty);
1780e93f7393Sniklas 
1781e93f7393Sniklas   /* Set up the "saved terminal modes" of the inferior
1782e93f7393Sniklas      based on what modes we are starting it with.  */
1783e93f7393Sniklas   target_terminal_init ();
1784e93f7393Sniklas 
1785e93f7393Sniklas   /* Set up execution context to know that we should return from
1786e93f7393Sniklas      wait_for_inferior as soon as the target reports a stop.  */
1787e93f7393Sniklas   init_wait_for_inferior ();
1788e93f7393Sniklas   clear_proceed_status ();
1789e93f7393Sniklas 
1790e93f7393Sniklas   /* No traps are generated when attaching to inferior under Mach 3
1791e93f7393Sniklas      or GNU hurd.  */
1792e93f7393Sniklas #ifndef ATTACH_NO_WAIT
1793b725ae77Skettenis   /* Careful here. See comments in inferior.h.  Basically some OSes
1794b725ae77Skettenis      don't ignore SIGSTOPs on continue requests anymore.  We need a
1795b725ae77Skettenis      way for handle_inferior_event to reset the stop_signal variable
1796b725ae77Skettenis      after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for.  */
1797b725ae77Skettenis   stop_soon = STOP_QUIETLY_NO_SIGSTOP;
1798e93f7393Sniklas   wait_for_inferior ();
1799b725ae77Skettenis   stop_soon = NO_STOP_QUIETLY;
1800e93f7393Sniklas #endif
1801e93f7393Sniklas 
1802b725ae77Skettenis   /*
1803b725ae77Skettenis    * If no exec file is yet known, try to determine it from the
1804b725ae77Skettenis    * process itself.
1805b725ae77Skettenis    */
1806b725ae77Skettenis   exec_file = (char *) get_exec_file (0);
1807b725ae77Skettenis   if (!exec_file)
1808b725ae77Skettenis     {
1809b725ae77Skettenis       exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1810b725ae77Skettenis       if (exec_file)
1811b725ae77Skettenis 	{
1812b725ae77Skettenis 	  /* It's possible we don't have a full path, but rather just a
1813b725ae77Skettenis 	     filename.  Some targets, such as HP-UX, don't provide the
1814b725ae77Skettenis 	     full path, sigh.
1815b725ae77Skettenis 
1816b725ae77Skettenis 	     Attempt to qualify the filename against the source path.
1817b725ae77Skettenis 	     (If that fails, we'll just fall back on the original
1818b725ae77Skettenis 	     filename.  Not much more we can do...)
1819b725ae77Skettenis 	   */
1820b725ae77Skettenis 	  if (!source_full_path_of (exec_file, &full_exec_path))
1821b725ae77Skettenis 	    full_exec_path = savestring (exec_file, strlen (exec_file));
1822b725ae77Skettenis 
1823b725ae77Skettenis 	  exec_file_attach (full_exec_path, from_tty);
1824b725ae77Skettenis 	  symbol_file_add_main (full_exec_path, from_tty);
1825b725ae77Skettenis 	}
1826b725ae77Skettenis     }
1827*63addd46Skettenis   else
1828*63addd46Skettenis     {
1829*63addd46Skettenis       reopen_exec_file ();
1830*63addd46Skettenis       reread_symbols ();
1831*63addd46Skettenis     }
1832b725ae77Skettenis 
1833e93f7393Sniklas #ifdef SOLIB_ADD
1834e93f7393Sniklas   /* Add shared library symbols from the newly attached process, if any.  */
1835b725ae77Skettenis   SOLIB_ADD ((char *) 0, from_tty, &current_target, auto_solib_add);
1836e93f7393Sniklas   re_enable_breakpoints_in_shlibs ();
1837e93f7393Sniklas #endif
1838e93f7393Sniklas 
1839b725ae77Skettenis   /* Take any necessary post-attaching actions for this platform.
1840b725ae77Skettenis    */
1841b725ae77Skettenis   target_post_attach (PIDGET (inferior_ptid));
1842b725ae77Skettenis 
1843*63addd46Skettenis   /* Install inferior's terminal modes.  */
1844*63addd46Skettenis   target_terminal_inferior ();
1845*63addd46Skettenis 
1846e93f7393Sniklas   normal_stop ();
1847b725ae77Skettenis 
1848*63addd46Skettenis   if (deprecated_attach_hook)
1849*63addd46Skettenis     deprecated_attach_hook ();
1850e93f7393Sniklas }
1851e93f7393Sniklas 
1852e93f7393Sniklas /*
1853e93f7393Sniklas  * detach_command --
1854e93f7393Sniklas  * takes a program previously attached to and detaches it.
1855e93f7393Sniklas  * The program resumes execution and will no longer stop
1856e93f7393Sniklas  * on signals, etc.  We better not have left any breakpoints
1857e93f7393Sniklas  * in the program or it'll die when it hits one.  For this
1858e93f7393Sniklas  * to work, it may be necessary for the process to have been
1859e93f7393Sniklas  * previously attached.  It *might* work if the program was
1860e93f7393Sniklas  * started via the normal ptrace (PTRACE_TRACEME).
1861e93f7393Sniklas  */
1862e93f7393Sniklas 
1863e93f7393Sniklas static void
detach_command(char * args,int from_tty)1864b725ae77Skettenis detach_command (char *args, int from_tty)
1865e93f7393Sniklas {
1866e93f7393Sniklas   dont_repeat ();		/* Not for the faint of heart */
1867e93f7393Sniklas   target_detach (args, from_tty);
1868b725ae77Skettenis #if defined(SOLIB_RESTART)
1869b725ae77Skettenis   SOLIB_RESTART ();
1870b725ae77Skettenis #endif
1871*63addd46Skettenis   if (deprecated_detach_hook)
1872*63addd46Skettenis     deprecated_detach_hook ();
1873e93f7393Sniklas }
1874e93f7393Sniklas 
1875b725ae77Skettenis /* Disconnect from the current target without resuming it (leaving it
1876b725ae77Skettenis    waiting for a debugger).
1877b725ae77Skettenis 
1878b725ae77Skettenis    We'd better not have left any breakpoints in the program or the
1879b725ae77Skettenis    next debugger will get confused.  Currently only supported for some
1880b725ae77Skettenis    remote targets, since the normal attach mechanisms don't work on
1881b725ae77Skettenis    stopped processes on some native platforms (e.g. GNU/Linux).  */
1882b725ae77Skettenis 
1883e93f7393Sniklas static void
disconnect_command(char * args,int from_tty)1884b725ae77Skettenis disconnect_command (char *args, int from_tty)
1885e93f7393Sniklas {
1886b725ae77Skettenis   dont_repeat ();		/* Not for the faint of heart */
1887b725ae77Skettenis   target_disconnect (args, from_tty);
1888b725ae77Skettenis #if defined(SOLIB_RESTART)
1889b725ae77Skettenis   SOLIB_RESTART ();
1890e93f7393Sniklas #endif
1891*63addd46Skettenis   if (deprecated_detach_hook)
1892*63addd46Skettenis     deprecated_detach_hook ();
1893b725ae77Skettenis }
1894b725ae77Skettenis 
1895b725ae77Skettenis /* Stop the execution of the target while running in async mode, in
1896b725ae77Skettenis    the backgound. */
1897b725ae77Skettenis void
interrupt_target_command(char * args,int from_tty)1898b725ae77Skettenis interrupt_target_command (char *args, int from_tty)
1899b725ae77Skettenis {
1900*63addd46Skettenis   if (target_can_async_p ())
1901b725ae77Skettenis     {
1902b725ae77Skettenis       dont_repeat ();		/* Not for the faint of heart */
1903b725ae77Skettenis       target_stop ();
1904b725ae77Skettenis     }
1905b725ae77Skettenis }
1906b725ae77Skettenis 
1907b725ae77Skettenis static void
print_float_info(struct gdbarch * gdbarch,struct ui_file * file,struct frame_info * frame,const char * args)1908b725ae77Skettenis print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1909b725ae77Skettenis 		  struct frame_info *frame, const char *args)
1910b725ae77Skettenis {
1911b725ae77Skettenis   if (!target_has_registers)
1912b725ae77Skettenis     error ("The program has no registers now.");
1913b725ae77Skettenis   if (deprecated_selected_frame == NULL)
1914b725ae77Skettenis     error ("No selected frame.");
1915b725ae77Skettenis 
1916b725ae77Skettenis   if (gdbarch_print_float_info_p (gdbarch))
1917b725ae77Skettenis     gdbarch_print_float_info (gdbarch, file, frame, args);
1918b725ae77Skettenis   else
1919b725ae77Skettenis     {
1920b725ae77Skettenis       int regnum;
1921b725ae77Skettenis       int printed_something = 0;
1922b725ae77Skettenis 
1923b725ae77Skettenis       for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1924b725ae77Skettenis 	{
1925b725ae77Skettenis 	  if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
1926b725ae77Skettenis 	    {
1927b725ae77Skettenis 	      printed_something = 1;
1928b725ae77Skettenis 	      gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1929b725ae77Skettenis 	    }
1930b725ae77Skettenis 	}
1931b725ae77Skettenis       if (!printed_something)
1932b725ae77Skettenis 	fprintf_filtered (file, "\
1933b725ae77Skettenis No floating-point info available for this processor.\n");
1934b725ae77Skettenis     }
1935b725ae77Skettenis }
1936b725ae77Skettenis 
1937b725ae77Skettenis static void
float_info(char * args,int from_tty)1938b725ae77Skettenis float_info (char *args, int from_tty)
1939b725ae77Skettenis {
1940b725ae77Skettenis   print_float_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
1941e93f7393Sniklas }
1942e93f7393Sniklas 
1943e93f7393Sniklas static void
unset_command(char * args,int from_tty)1944b725ae77Skettenis unset_command (char *args, int from_tty)
1945e93f7393Sniklas {
1946b725ae77Skettenis   printf_filtered ("\"unset\" must be followed by the name of ");
1947b725ae77Skettenis   printf_filtered ("an unset subcommand.\n");
1948e93f7393Sniklas   help_list (unsetlist, "unset ", -1, gdb_stdout);
1949e93f7393Sniklas }
1950e93f7393Sniklas 
1951e93f7393Sniklas void
_initialize_infcmd(void)1952b725ae77Skettenis _initialize_infcmd (void)
1953e93f7393Sniklas {
1954e93f7393Sniklas   struct cmd_list_element *c;
1955e93f7393Sniklas 
1956b725ae77Skettenis   c = add_com ("tty", class_run, tty_command,
1957e93f7393Sniklas 	       "Set terminal for future runs of program being debugged.");
1958b725ae77Skettenis   set_cmd_completer (c, filename_completer);
1959e93f7393Sniklas 
1960b725ae77Skettenis   c = add_set_cmd ("args", class_run, var_string_noescape,
1961b725ae77Skettenis 		   (char *) &inferior_args,
1962b725ae77Skettenis 		   "Set argument list to give program being debugged when it is started.\n\
1963e93f7393Sniklas Follow this command with any number of args, to be passed to the program.",
1964b725ae77Skettenis 		   &setlist);
1965b725ae77Skettenis   set_cmd_completer (c, filename_completer);
1966b725ae77Skettenis   set_cmd_sfunc (c, notice_args_set);
1967*63addd46Skettenis   c = deprecated_add_show_from_set (c, &showlist);
1968b725ae77Skettenis   set_cmd_sfunc (c, notice_args_read);
1969e93f7393Sniklas 
1970e93f7393Sniklas   c = add_cmd
1971e93f7393Sniklas     ("environment", no_class, environment_info,
1972e93f7393Sniklas      "The environment to give the program, or one variable's value.\n\
1973e93f7393Sniklas With an argument VAR, prints the value of environment variable VAR to\n\
1974e93f7393Sniklas give the program being debugged.  With no arguments, prints the entire\n\
1975e93f7393Sniklas environment to be given to the program.", &showlist);
1976b725ae77Skettenis   set_cmd_completer (c, noop_completer);
1977e93f7393Sniklas 
1978e93f7393Sniklas   add_prefix_cmd ("unset", no_class, unset_command,
1979b725ae77Skettenis 		  "Complement to certain \"set\" commands.",
1980e93f7393Sniklas 		  &unsetlist, "unset ", 0, &cmdlist);
1981e93f7393Sniklas 
1982e93f7393Sniklas   c = add_cmd ("environment", class_run, unset_environment_command,
1983e93f7393Sniklas 	       "Cancel environment variable VAR for the program.\n\
1984e93f7393Sniklas This does not affect the program until the next \"run\" command.",
1985e93f7393Sniklas 	       &unsetlist);
1986b725ae77Skettenis   set_cmd_completer (c, noop_completer);
1987e93f7393Sniklas 
1988e93f7393Sniklas   c = add_cmd ("environment", class_run, set_environment_command,
1989e93f7393Sniklas 	       "Set environment variable value to give the program.\n\
1990e93f7393Sniklas Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1991e93f7393Sniklas VALUES of environment variables are uninterpreted strings.\n\
1992e93f7393Sniklas This does not affect the program until the next \"run\" command.",
1993e93f7393Sniklas 	       &setlist);
1994b725ae77Skettenis   set_cmd_completer (c, noop_completer);
1995e93f7393Sniklas 
1996b725ae77Skettenis   c = add_com ("path", class_files, path_command,
1997e93f7393Sniklas 	       "Add directory DIR(s) to beginning of search path for object files.\n\
1998e93f7393Sniklas $cwd in the path means the current working directory.\n\
1999e93f7393Sniklas This path is equivalent to the $PATH shell variable.  It is a list of\n\
2000e93f7393Sniklas directories, separated by colons.  These directories are searched to find\n\
2001e93f7393Sniklas fully linked executable files and separately compiled object files as needed.");
2002b725ae77Skettenis   set_cmd_completer (c, filename_completer);
2003e93f7393Sniklas 
2004e93f7393Sniklas   c = add_cmd ("paths", no_class, path_info,
2005e93f7393Sniklas 	       "Current search path for finding object files.\n\
2006e93f7393Sniklas $cwd in the path means the current working directory.\n\
2007e93f7393Sniklas This path is equivalent to the $PATH shell variable.  It is a list of\n\
2008e93f7393Sniklas directories, separated by colons.  These directories are searched to find\n\
2009b725ae77Skettenis fully linked executable files and separately compiled object files as needed.",
2010b725ae77Skettenis 	       &showlist);
2011b725ae77Skettenis   set_cmd_completer (c, noop_completer);
2012e93f7393Sniklas 
2013e93f7393Sniklas   add_com ("attach", class_run, attach_command,
2014e93f7393Sniklas 	   "Attach to a process or file outside of GDB.\n\
2015e93f7393Sniklas This command attaches to another target, of the same type as your last\n\
2016b725ae77Skettenis \"target\" command (\"info files\" will show your target stack).\n\
2017e93f7393Sniklas The command may take as argument a process id or a device file.\n\
2018e93f7393Sniklas For a process id, you must have permission to send the process a signal,\n\
2019e93f7393Sniklas and it must have the same effective uid as the debugger.\n\
2020b725ae77Skettenis When using \"attach\" with a process id, the debugger finds the\n\
2021b725ae77Skettenis program running in the process, looking first in the current working\n\
2022b725ae77Skettenis directory, or (if not found there) using the source file search path\n\
2023b725ae77Skettenis (see the \"directory\" command).  You can also use the \"file\" command\n\
2024b725ae77Skettenis to specify the program, and to load its symbol table.");
2025e93f7393Sniklas 
2026e93f7393Sniklas   add_com ("detach", class_run, detach_command,
2027e93f7393Sniklas 	   "Detach a process or file previously attached.\n\
2028b725ae77Skettenis If a process, it is no longer traced, and it continues its execution.  If\n\
2029b725ae77Skettenis you were debugging a file, the file is closed and gdb no longer accesses it.");
2030b725ae77Skettenis 
2031b725ae77Skettenis   add_com ("disconnect", class_run, disconnect_command,
2032b725ae77Skettenis 	   "Disconnect from a target.\n\
2033b725ae77Skettenis The target will wait for another debugger to connect.  Not available for\n\
2034b725ae77Skettenis all targets.");
2035e93f7393Sniklas 
2036e93f7393Sniklas   add_com ("signal", class_run, signal_command,
2037e93f7393Sniklas 	   "Continue program giving it signal specified by the argument.\n\
2038e93f7393Sniklas An argument of \"0\" means continue program without giving it a signal.");
2039e93f7393Sniklas 
2040e93f7393Sniklas   add_com ("stepi", class_run, stepi_command,
2041e93f7393Sniklas 	   "Step one instruction exactly.\n\
2042e93f7393Sniklas Argument N means do this N times (or till program stops for another reason).");
2043e93f7393Sniklas   add_com_alias ("si", "stepi", class_alias, 0);
2044e93f7393Sniklas 
2045e93f7393Sniklas   add_com ("nexti", class_run, nexti_command,
2046e93f7393Sniklas 	   "Step one instruction, but proceed through subroutine calls.\n\
2047e93f7393Sniklas Argument N means do this N times (or till program stops for another reason).");
2048e93f7393Sniklas   add_com_alias ("ni", "nexti", class_alias, 0);
2049e93f7393Sniklas 
2050e93f7393Sniklas   add_com ("finish", class_run, finish_command,
2051e93f7393Sniklas 	   "Execute until selected stack frame returns.\n\
2052e93f7393Sniklas Upon return, the value returned is printed and put in the value history.");
2053e93f7393Sniklas 
2054e93f7393Sniklas   add_com ("next", class_run, next_command,
2055e93f7393Sniklas 	   "Step program, proceeding through subroutine calls.\n\
2056e93f7393Sniklas Like the \"step\" command as long as subroutine calls do not happen;\n\
2057e93f7393Sniklas when they do, the call is treated as one instruction.\n\
2058e93f7393Sniklas Argument N means do this N times (or till program stops for another reason).");
2059e93f7393Sniklas   add_com_alias ("n", "next", class_run, 1);
2060b725ae77Skettenis   if (xdb_commands)
2061b725ae77Skettenis     add_com_alias ("S", "next", class_run, 1);
2062e93f7393Sniklas 
2063e93f7393Sniklas   add_com ("step", class_run, step_command,
2064e93f7393Sniklas 	   "Step program until it reaches a different source line.\n\
2065e93f7393Sniklas Argument N means do this N times (or till program stops for another reason).");
2066e93f7393Sniklas   add_com_alias ("s", "step", class_run, 1);
2067e93f7393Sniklas 
2068b725ae77Skettenis   c = add_com ("until", class_run, until_command,
2069e93f7393Sniklas 	       "Execute until the program reaches a source line greater than the current\n\
2070b725ae77Skettenis or a specified location (same args as break command) within the current frame.");
2071b725ae77Skettenis   set_cmd_completer (c, location_completer);
2072e93f7393Sniklas   add_com_alias ("u", "until", class_run, 1);
2073e93f7393Sniklas 
2074b725ae77Skettenis   c = add_com ("advance", class_run, advance_command,
2075b725ae77Skettenis 	       "Continue the program up to the given location (same form as args for break command).\n\
2076b725ae77Skettenis Execution will also stop upon exit from the current stack frame.");
2077b725ae77Skettenis   set_cmd_completer (c, location_completer);
2078b725ae77Skettenis 
2079b725ae77Skettenis   c = add_com ("jump", class_run, jump_command,
2080e93f7393Sniklas 	       "Continue program being debugged at specified line or address.\n\
2081e93f7393Sniklas Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2082e93f7393Sniklas for an address to start at.");
2083b725ae77Skettenis   set_cmd_completer (c, location_completer);
2084b725ae77Skettenis 
2085b725ae77Skettenis   if (xdb_commands)
2086b725ae77Skettenis     {
2087b725ae77Skettenis       c = add_com ("go", class_run, go_command,
2088b725ae77Skettenis 		   "Usage: go <location>\n\
2089b725ae77Skettenis Continue program being debugged, stopping at specified line or \n\
2090b725ae77Skettenis address.\n\
2091b725ae77Skettenis Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2092b725ae77Skettenis expression for an address to start at.\n\
2093b725ae77Skettenis This command is a combination of tbreak and jump.");
2094b725ae77Skettenis       set_cmd_completer (c, location_completer);
2095b725ae77Skettenis     }
2096b725ae77Skettenis 
2097b725ae77Skettenis   if (xdb_commands)
2098b725ae77Skettenis     add_com_alias ("g", "go", class_run, 1);
2099e93f7393Sniklas 
2100e93f7393Sniklas   add_com ("continue", class_run, continue_command,
2101e93f7393Sniklas 	   "Continue program being debugged, after signal or breakpoint.\n\
2102e93f7393Sniklas If proceeding from breakpoint, a number N may be used as an argument,\n\
2103e93f7393Sniklas which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2104e93f7393Sniklas the breakpoint won't break until the Nth time it is reached).");
2105e93f7393Sniklas   add_com_alias ("c", "cont", class_run, 1);
2106e93f7393Sniklas   add_com_alias ("fg", "cont", class_run, 1);
2107e93f7393Sniklas 
2108b725ae77Skettenis   c = add_com ("run", class_run, run_command,
2109e93f7393Sniklas 	   "Start debugged program.  You may specify arguments to give it.\n\
2110e93f7393Sniklas Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2111e93f7393Sniklas Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2112e93f7393Sniklas With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2113e93f7393Sniklas To cancel previous arguments and run with no arguments,\n\
2114e93f7393Sniklas use \"set args\" without arguments.");
2115b725ae77Skettenis   set_cmd_completer (c, filename_completer);
2116e93f7393Sniklas   add_com_alias ("r", "run", class_run, 1);
2117b725ae77Skettenis   if (xdb_commands)
2118b725ae77Skettenis     add_com ("R", class_run, run_no_args_command,
2119b725ae77Skettenis 	     "Start debugged program with no arguments.");
2120b725ae77Skettenis 
2121*63addd46Skettenis   c = add_com ("start", class_run, start_command,
2122*63addd46Skettenis                "\
2123*63addd46Skettenis Run the debugged program until the beginning of the main procedure.\n\
2124*63addd46Skettenis You may specify arguments to give to your program, just as with the\n\
2125*63addd46Skettenis \"run\" command.");
2126*63addd46Skettenis   set_cmd_completer (c, filename_completer);
2127*63addd46Skettenis 
2128b725ae77Skettenis   add_com ("interrupt", class_run, interrupt_target_command,
2129b725ae77Skettenis 	   "Interrupt the execution of the debugged program.");
2130e93f7393Sniklas 
2131e93f7393Sniklas   add_info ("registers", nofp_registers_info,
2132e93f7393Sniklas 	    "List of integer registers and their contents, for selected stack frame.\n\
2133e93f7393Sniklas Register name as argument means describe only that register.");
2134b725ae77Skettenis   add_info_alias ("r", "registers", 1);
2135e93f7393Sniklas 
2136b725ae77Skettenis   if (xdb_commands)
2137b725ae77Skettenis     add_com ("lr", class_info, nofp_registers_info,
2138b725ae77Skettenis 	     "List of integer registers and their contents, for selected stack frame.\n\
2139b725ae77Skettenis   Register name as argument means describe only that register.");
2140e93f7393Sniklas   add_info ("all-registers", all_registers_info,
2141e93f7393Sniklas 	    "List of all registers and their contents, for selected stack frame.\n\
2142e93f7393Sniklas Register name as argument means describe only that register.");
2143e93f7393Sniklas 
2144e93f7393Sniklas   add_info ("program", program_info,
2145e93f7393Sniklas 	    "Execution status of the program.");
2146e93f7393Sniklas 
2147e93f7393Sniklas   add_info ("float", float_info,
2148e93f7393Sniklas 	    "Print the status of the floating point unit\n");
2149e93f7393Sniklas 
2150b725ae77Skettenis   add_info ("vector", vector_info,
2151b725ae77Skettenis 	    "Print the status of the vector unit\n");
2152b725ae77Skettenis 
2153e93f7393Sniklas   inferior_environ = make_environ ();
2154e93f7393Sniklas   init_environ (inferior_environ);
2155e93f7393Sniklas }
2156