119370Spst/* Memory-access and commands for "inferior" process, for GDB.
298944Sobrien   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3130803Smarcel   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
446283Sdfr   Free Software Foundation, Inc.
519370Spst
698944Sobrien   This file is part of GDB.
719370Spst
898944Sobrien   This program is free software; you can redistribute it and/or modify
998944Sobrien   it under the terms of the GNU General Public License as published by
1098944Sobrien   the Free Software Foundation; either version 2 of the License, or
1198944Sobrien   (at your option) any later version.
1219370Spst
1398944Sobrien   This program is distributed in the hope that it will be useful,
1498944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1598944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1698944Sobrien   GNU General Public License for more details.
1719370Spst
1898944Sobrien   You should have received a copy of the GNU General Public License
1998944Sobrien   along with this program; if not, write to the Free Software
2098944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2198944Sobrien   Boston, MA 02111-1307, USA.  */
2219370Spst
2319370Spst#include "defs.h"
2419370Spst#include <signal.h>
2519370Spst#include "gdb_string.h"
2619370Spst#include "symtab.h"
2719370Spst#include "gdbtypes.h"
2819370Spst#include "frame.h"
2919370Spst#include "inferior.h"
3019370Spst#include "environ.h"
3119370Spst#include "value.h"
3219370Spst#include "gdbcmd.h"
3398944Sobrien#include "symfile.h"
3419370Spst#include "gdbcore.h"
3519370Spst#include "target.h"
3619370Spst#include "language.h"
3746283Sdfr#include "symfile.h"
3846283Sdfr#include "objfiles.h"
3998944Sobrien#include "completer.h"
4098944Sobrien#include "ui-out.h"
4198944Sobrien#include "event-top.h"
4298944Sobrien#include "parser-defs.h"
43130803Smarcel#include "regcache.h"
44130803Smarcel#include "reggroups.h"
45130803Smarcel#include "block.h"
46130803Smarcel#include <ctype.h>
47130803Smarcel#include "gdb_assert.h"
4819370Spst
49130803Smarcel/* Functions exported for general use, in inferior.h: */
5019370Spst
5198944Sobrienvoid all_registers_info (char *, int);
5246283Sdfr
5398944Sobrienvoid registers_info (char *, int);
5446283Sdfr
55130803Smarcelvoid nexti_command (char *, int);
5646283Sdfr
57130803Smarcelvoid stepi_command (char *, int);
58130803Smarcel
5998944Sobrienvoid continue_command (char *, int);
6046283Sdfr
61130803Smarcelvoid interrupt_target_command (char *args, int from_tty);
62130803Smarcel
63130803Smarcel/* Local functions: */
64130803Smarcel
65130803Smarcelstatic void nofp_registers_info (char *, int);
66130803Smarcel
6798944Sobrienstatic void print_return_value (int struct_return, struct type *value_type);
6819370Spst
6998944Sobrienstatic void finish_command_continuation (struct continuation_arg *);
7019370Spst
7198944Sobrienstatic void until_next_command (int);
7219370Spst
7398944Sobrienstatic void until_command (char *, int);
7419370Spst
7598944Sobrienstatic void path_info (char *, int);
7619370Spst
7798944Sobrienstatic void path_command (char *, int);
7819370Spst
7998944Sobrienstatic void unset_command (char *, int);
8019370Spst
8198944Sobrienstatic void float_info (char *, int);
8219370Spst
8398944Sobrienstatic void detach_command (char *, int);
8419370Spst
85130803Smarcelstatic void disconnect_command (char *, int);
8619370Spst
8798944Sobrienstatic void unset_environment_command (char *, int);
8819370Spst
8998944Sobrienstatic void set_environment_command (char *, int);
9019370Spst
9198944Sobrienstatic void environment_info (char *, int);
9219370Spst
9398944Sobrienstatic void program_info (char *, int);
9419370Spst
9598944Sobrienstatic void finish_command (char *, int);
9619370Spst
9798944Sobrienstatic void signal_command (char *, int);
9819370Spst
9998944Sobrienstatic void jump_command (char *, int);
10019370Spst
10198944Sobrienstatic void step_1 (int, int, char *);
10298944Sobrienstatic void step_once (int skip_subroutines, int single_inst, int count);
10398944Sobrienstatic void step_1_continuation (struct continuation_arg *arg);
10419370Spst
10598944Sobrienstatic void next_command (char *, int);
10619370Spst
10798944Sobrienstatic void step_command (char *, int);
10846283Sdfr
10998944Sobrienstatic void run_command (char *, int);
11098944Sobrien
11198944Sobrienstatic void run_no_args_command (char *args, int from_tty);
11298944Sobrien
11398944Sobrienstatic void go_command (char *line_no, int from_tty);
11498944Sobrien
11598944Sobrienstatic int strip_bg_char (char **);
11698944Sobrien
11798944Sobrienvoid _initialize_infcmd (void);
11898944Sobrien
11946283Sdfr#define GO_USAGE   "Usage: go <location>\n"
12046283Sdfr
12119370Spst#define ERROR_NO_INFERIOR \
12219370Spst   if (!target_has_execution) error ("The program is not being run.");
12319370Spst
12419370Spst/* String containing arguments to give to the program, separated by spaces.
12519370Spst   Empty string (pointer to '\0') means no args.  */
12619370Spst
12719370Spststatic char *inferior_args;
12819370Spst
12998944Sobrien/* The inferior arguments as a vector.  If INFERIOR_ARGC is nonzero,
13098944Sobrien   then we must compute INFERIOR_ARGS from this (via the target).  */
13198944Sobrien
13298944Sobrienstatic int inferior_argc;
13398944Sobrienstatic char **inferior_argv;
13498944Sobrien
13519370Spst/* File name for default use for standard in/out in the inferior.  */
13619370Spst
13719370Spstchar *inferior_io_terminal;
13819370Spst
13919370Spst/* Pid of our debugged inferior, or 0 if no inferior now.
14019370Spst   Since various parts of infrun.c test this to see whether there is a program
14119370Spst   being debugged it should be nonzero (currently 3 is used) for remote
14219370Spst   debugging.  */
14319370Spst
14498944Sobrienptid_t inferior_ptid;
14519370Spst
14619370Spst/* Last signal that the inferior received (why it stopped).  */
14719370Spst
14819370Spstenum target_signal stop_signal;
14919370Spst
15019370Spst/* Address at which inferior stopped.  */
15119370Spst
15219370SpstCORE_ADDR stop_pc;
15319370Spst
15419370Spst/* Chain containing status of breakpoint(s) that we have stopped at.  */
15519370Spst
15619370Spstbpstat stop_bpstat;
15719370Spst
15819370Spst/* Flag indicating that a command has proceeded the inferior past the
15919370Spst   current breakpoint.  */
16019370Spst
16119370Spstint breakpoint_proceeded;
16219370Spst
16319370Spst/* Nonzero if stopped due to a step command.  */
16419370Spst
16519370Spstint stop_step;
16619370Spst
16719370Spst/* Nonzero if stopped due to completion of a stack dummy routine.  */
16819370Spst
16919370Spstint stop_stack_dummy;
17019370Spst
17119370Spst/* Nonzero if stopped due to a random (unexpected) signal in inferior
17219370Spst   process.  */
17319370Spst
17419370Spstint stopped_by_random_signal;
17519370Spst
17619370Spst/* Range to single step within.
17719370Spst   If this is nonzero, respond to a single-step signal
17819370Spst   by continuing to step if the pc is in this range.  */
17919370Spst
18098944SobrienCORE_ADDR step_range_start;	/* Inclusive */
18198944SobrienCORE_ADDR step_range_end;	/* Exclusive */
18219370Spst
18319370Spst/* Stack frame address as of when stepping command was issued.
18419370Spst   This is how we know when we step into a subroutine call,
18519370Spst   and how to set the frame for the breakpoint used to step out.  */
18619370Spst
187130803Smarcelstruct frame_id step_frame_id;
18819370Spst
18919370Spst/* Our notion of the current stack pointer.  */
19019370Spst
19119370SpstCORE_ADDR step_sp;
19219370Spst
19398944Sobrienenum step_over_calls_kind step_over_calls;
19419370Spst
19519370Spst/* If stepping, nonzero means step count is > 1
19619370Spst   so don't print frame next time inferior stops
19719370Spst   if it stops due to stepping.  */
19819370Spst
19919370Spstint step_multi;
20019370Spst
20119370Spst/* Environment to use for running inferior,
20219370Spst   in format described in environ.h.  */
20319370Spst
20419370Spststruct environ *inferior_environ;
20598944Sobrien
20698944Sobrien/* Accessor routines. */
20719370Spst
20898944Sobrienchar *
20998944Sobrienget_inferior_args (void)
21098944Sobrien{
21198944Sobrien  if (inferior_argc != 0)
21298944Sobrien    {
21398944Sobrien      char *n, *old;
21498944Sobrien
21598944Sobrien      n = gdbarch_construct_inferior_arguments (current_gdbarch,
21698944Sobrien						inferior_argc, inferior_argv);
21798944Sobrien      old = set_inferior_args (n);
21898944Sobrien      xfree (old);
21998944Sobrien    }
22098944Sobrien
22198944Sobrien  if (inferior_args == NULL)
22298944Sobrien    inferior_args = xstrdup ("");
22398944Sobrien
22498944Sobrien  return inferior_args;
22598944Sobrien}
22698944Sobrien
22798944Sobrienchar *
22898944Sobrienset_inferior_args (char *newargs)
22998944Sobrien{
23098944Sobrien  char *saved_args = inferior_args;
23198944Sobrien
23298944Sobrien  inferior_args = newargs;
23398944Sobrien  inferior_argc = 0;
23498944Sobrien  inferior_argv = 0;
23598944Sobrien
23698944Sobrien  return saved_args;
23798944Sobrien}
23898944Sobrien
23998944Sobrienvoid
24098944Sobrienset_inferior_args_vector (int argc, char **argv)
24198944Sobrien{
24298944Sobrien  inferior_argc = argc;
24398944Sobrien  inferior_argv = argv;
24498944Sobrien}
24598944Sobrien
24698944Sobrien/* Notice when `set args' is run.  */
24798944Sobrienstatic void
24898944Sobriennotice_args_set (char *args, int from_tty, struct cmd_list_element *c)
24998944Sobrien{
25098944Sobrien  inferior_argc = 0;
25198944Sobrien  inferior_argv = 0;
25298944Sobrien}
25398944Sobrien
25498944Sobrien/* Notice when `show args' is run.  */
25598944Sobrienstatic void
25698944Sobriennotice_args_read (char *args, int from_tty, struct cmd_list_element *c)
25798944Sobrien{
25898944Sobrien  /* Might compute the value.  */
25998944Sobrien  get_inferior_args ();
26098944Sobrien}
26198944Sobrien
26219370Spst
26398944Sobrien/* Compute command-line string given argument vector.  This does the
26498944Sobrien   same shell processing as fork_inferior.  */
26598944Sobrienchar *
26698944Sobrienconstruct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
26798944Sobrien{
26898944Sobrien  char *result;
26998944Sobrien
27098944Sobrien  if (STARTUP_WITH_SHELL)
27198944Sobrien    {
27298944Sobrien      /* This holds all the characters considered special to the
27398944Sobrien	 typical Unix shells.  We include `^' because the SunOS
27498944Sobrien	 /bin/sh treats it as a synonym for `|'.  */
27598944Sobrien      char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
27698944Sobrien      int i;
27798944Sobrien      int length = 0;
27898944Sobrien      char *out, *cp;
27998944Sobrien
28098944Sobrien      /* We over-compute the size.  It shouldn't matter.  */
28198944Sobrien      for (i = 0; i < argc; ++i)
282130803Smarcel	length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
28398944Sobrien
28498944Sobrien      result = (char *) xmalloc (length);
28598944Sobrien      out = result;
28698944Sobrien
28798944Sobrien      for (i = 0; i < argc; ++i)
28898944Sobrien	{
28998944Sobrien	  if (i > 0)
29098944Sobrien	    *out++ = ' ';
29198944Sobrien
292130803Smarcel	  /* Need to handle empty arguments specially.  */
293130803Smarcel	  if (argv[i][0] == '\0')
29498944Sobrien	    {
295130803Smarcel	      *out++ = '\'';
296130803Smarcel	      *out++ = '\'';
29798944Sobrien	    }
298130803Smarcel	  else
299130803Smarcel	    {
300130803Smarcel	      for (cp = argv[i]; *cp; ++cp)
301130803Smarcel		{
302130803Smarcel		  if (strchr (special, *cp) != NULL)
303130803Smarcel		    *out++ = '\\';
304130803Smarcel		  *out++ = *cp;
305130803Smarcel		}
306130803Smarcel	    }
30798944Sobrien	}
30898944Sobrien      *out = '\0';
30998944Sobrien    }
31098944Sobrien  else
31198944Sobrien    {
31298944Sobrien      /* In this case we can't handle arguments that contain spaces,
31398944Sobrien	 tabs, or newlines -- see breakup_args().  */
31498944Sobrien      int i;
31598944Sobrien      int length = 0;
31698944Sobrien
31798944Sobrien      for (i = 0; i < argc; ++i)
31898944Sobrien	{
31998944Sobrien	  char *cp = strchr (argv[i], ' ');
32098944Sobrien	  if (cp == NULL)
32198944Sobrien	    cp = strchr (argv[i], '\t');
32298944Sobrien	  if (cp == NULL)
32398944Sobrien	    cp = strchr (argv[i], '\n');
32498944Sobrien	  if (cp != NULL)
32598944Sobrien	    error ("can't handle command-line argument containing whitespace");
32698944Sobrien	  length += strlen (argv[i]) + 1;
32798944Sobrien	}
32898944Sobrien
32998944Sobrien      result = (char *) xmalloc (length);
33098944Sobrien      result[0] = '\0';
33198944Sobrien      for (i = 0; i < argc; ++i)
33298944Sobrien	{
33398944Sobrien	  if (i > 0)
33498944Sobrien	    strcat (result, " ");
33598944Sobrien	  strcat (result, argv[i]);
33698944Sobrien	}
33798944Sobrien    }
33898944Sobrien
33998944Sobrien  return result;
34098944Sobrien}
34198944Sobrien
34298944Sobrien
34398944Sobrien/* This function detects whether or not a '&' character (indicating
34498944Sobrien   background execution) has been added as *the last* of the arguments ARGS
34598944Sobrien   of a command. If it has, it removes it and returns 1. Otherwise it
34698944Sobrien   does nothing and returns 0. */
34798944Sobrienstatic int
34898944Sobrienstrip_bg_char (char **args)
34998944Sobrien{
35098944Sobrien  char *p = NULL;
35198944Sobrien
35298944Sobrien  p = strchr (*args, '&');
35398944Sobrien
35498944Sobrien  if (p)
35598944Sobrien    {
35698944Sobrien      if (p == (*args + strlen (*args) - 1))
35798944Sobrien	{
35898944Sobrien	  if (strlen (*args) > 1)
35998944Sobrien	    {
36098944Sobrien	      do
36198944Sobrien		p--;
36298944Sobrien	      while (*p == ' ' || *p == '\t');
36398944Sobrien	      *(p + 1) = '\0';
36498944Sobrien	    }
36598944Sobrien	  else
36698944Sobrien	    *args = 0;
36798944Sobrien	  return 1;
36898944Sobrien	}
36998944Sobrien    }
37098944Sobrien  return 0;
37198944Sobrien}
37298944Sobrien
37319370Spstvoid
37498944Sobrientty_command (char *file, int from_tty)
37519370Spst{
37619370Spst  if (file == 0)
37719370Spst    error_no_arg ("terminal name for running target process");
37819370Spst
37919370Spst  inferior_io_terminal = savestring (file, strlen (file));
38019370Spst}
38119370Spst
38219370Spststatic void
38398944Sobrienrun_command (char *args, int from_tty)
38419370Spst{
38519370Spst  char *exec_file;
38619370Spst
38719370Spst  dont_repeat ();
38819370Spst
38998944Sobrien  if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
39019370Spst    {
39198944Sobrien      if (from_tty
39298944Sobrien	  && !query ("The program being debugged has been started already.\n\
39319370SpstStart it from the beginning? "))
39419370Spst	error ("Program not restarted.");
39519370Spst      target_kill ();
39646283Sdfr#if defined(SOLIB_RESTART)
39746283Sdfr      SOLIB_RESTART ();
39846283Sdfr#endif
39946283Sdfr      init_wait_for_inferior ();
40019370Spst    }
40119370Spst
40219370Spst  clear_breakpoint_hit_counts ();
40319370Spst
40446283Sdfr  /* Purge old solib objfiles. */
40546283Sdfr  objfile_purge_solibs ();
40646283Sdfr
40746283Sdfr  do_run_cleanups (NULL);
40846283Sdfr
40998944Sobrien  /* The comment here used to read, "The exec file is re-read every
41098944Sobrien     time we do a generic_mourn_inferior, so we just have to worry
41198944Sobrien     about the symbol file."  The `generic_mourn_inferior' function
41298944Sobrien     gets called whenever the program exits.  However, suppose the
41398944Sobrien     program exits, and *then* the executable file changes?  We need
41498944Sobrien     to check again here.  Since reopen_exec_file doesn't do anything
41598944Sobrien     if the timestamp hasn't changed, I don't see the harm.  */
41698944Sobrien  reopen_exec_file ();
41719370Spst  reread_symbols ();
41819370Spst
41998944Sobrien  exec_file = (char *) get_exec_file (0);
42098944Sobrien
42119370Spst  /* We keep symbols from add-symbol-file, on the grounds that the
42219370Spst     user might want to add some symbols before running the program
42319370Spst     (right?).  But sometimes (dynamic loading where the user manually
42419370Spst     introduces the new symbols with add-symbol-file), the code which
42519370Spst     the symbols describe does not persist between runs.  Currently
42619370Spst     the user has to manually nuke all symbols between runs if they
42719370Spst     want them to go away (PR 2207).  This is probably reasonable.  */
42819370Spst
42998944Sobrien  if (!args)
43019370Spst    {
43198944Sobrien      if (event_loop_p && target_can_async_p ())
43298944Sobrien	async_disable_stdin ();
43319370Spst    }
43498944Sobrien  else
43598944Sobrien    {
43698944Sobrien      int async_exec = strip_bg_char (&args);
43719370Spst
43898944Sobrien      /* If we get a request for running in the bg but the target
43998944Sobrien         doesn't support it, error out. */
44098944Sobrien      if (event_loop_p && async_exec && !target_can_async_p ())
44198944Sobrien	error ("Asynchronous execution not supported on this target.");
44298944Sobrien
44398944Sobrien      /* If we don't get a request of running in the bg, then we need
44498944Sobrien         to simulate synchronous (fg) execution. */
44598944Sobrien      if (event_loop_p && !async_exec && target_can_async_p ())
44698944Sobrien	{
44798944Sobrien	  /* Simulate synchronous execution */
44898944Sobrien	  async_disable_stdin ();
44998944Sobrien	}
45098944Sobrien
45198944Sobrien      /* If there were other args, beside '&', process them. */
45298944Sobrien      if (args)
45398944Sobrien	{
45498944Sobrien          char *old_args = set_inferior_args (xstrdup (args));
45598944Sobrien          xfree (old_args);
45698944Sobrien	}
45798944Sobrien    }
45898944Sobrien
45919370Spst  if (from_tty)
46019370Spst    {
46198944Sobrien      ui_out_field_string (uiout, NULL, "Starting program");
46298944Sobrien      ui_out_text (uiout, ": ");
46319370Spst      if (exec_file)
46498944Sobrien	ui_out_field_string (uiout, "execfile", exec_file);
46598944Sobrien      ui_out_spaces (uiout, 1);
46698944Sobrien      /* We call get_inferior_args() because we might need to compute
46798944Sobrien	 the value now.  */
46898944Sobrien      ui_out_field_string (uiout, "infargs", get_inferior_args ());
46998944Sobrien      ui_out_text (uiout, "\n");
47098944Sobrien      ui_out_flush (uiout);
47119370Spst    }
47219370Spst
47398944Sobrien  /* We call get_inferior_args() because we might need to compute
47498944Sobrien     the value now.  */
47598944Sobrien  target_create_inferior (exec_file, get_inferior_args (),
47619370Spst			  environ_vector (inferior_environ));
47719370Spst}
47846283Sdfr
47946283Sdfr
48046283Sdfrstatic void
48198944Sobrienrun_no_args_command (char *args, int from_tty)
48246283Sdfr{
48398944Sobrien  char *old_args = set_inferior_args (xstrdup (""));
48498944Sobrien  xfree (old_args);
48546283Sdfr}
48698944Sobrien
48746283Sdfr
48846283Sdfrvoid
48998944Sobriencontinue_command (char *proc_count_exp, int from_tty)
49019370Spst{
49198944Sobrien  int async_exec = 0;
49219370Spst  ERROR_NO_INFERIOR;
49319370Spst
49498944Sobrien  /* Find out whether we must run in the background. */
49598944Sobrien  if (proc_count_exp != NULL)
49698944Sobrien    async_exec = strip_bg_char (&proc_count_exp);
49719370Spst
49898944Sobrien  /* If we must run in the background, but the target can't do it,
49998944Sobrien     error out. */
50098944Sobrien  if (event_loop_p && async_exec && !target_can_async_p ())
50198944Sobrien    error ("Asynchronous execution not supported on this target.");
50298944Sobrien
50398944Sobrien  /* If we are not asked to run in the bg, then prepare to run in the
50498944Sobrien     foreground, synchronously. */
50598944Sobrien  if (event_loop_p && !async_exec && target_can_async_p ())
50698944Sobrien    {
50798944Sobrien      /* Simulate synchronous execution */
50898944Sobrien      async_disable_stdin ();
50998944Sobrien    }
51098944Sobrien
51198944Sobrien  /* If have argument (besides '&'), set proceed count of breakpoint
51298944Sobrien     we stopped at.  */
51319370Spst  if (proc_count_exp != NULL)
51419370Spst    {
51519370Spst      bpstat bs = stop_bpstat;
51619370Spst      int num = bpstat_num (&bs);
51719370Spst      if (num == 0 && from_tty)
51819370Spst	{
51919370Spst	  printf_filtered
52019370Spst	    ("Not stopped at any breakpoint; argument ignored.\n");
52119370Spst	}
52219370Spst      while (num != 0)
52319370Spst	{
52419370Spst	  set_ignore_count (num,
52598944Sobrien			    parse_and_eval_long (proc_count_exp) - 1,
52619370Spst			    from_tty);
52719370Spst	  /* set_ignore_count prints a message ending with a period.
52819370Spst	     So print two spaces before "Continuing.".  */
52919370Spst	  if (from_tty)
53019370Spst	    printf_filtered ("  ");
53119370Spst	  num = bpstat_num (&bs);
53219370Spst	}
53319370Spst    }
53419370Spst
53519370Spst  if (from_tty)
53619370Spst    printf_filtered ("Continuing.\n");
53719370Spst
53819370Spst  clear_proceed_status ();
53919370Spst
54019370Spst  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
54119370Spst}
54219370Spst
54319370Spst/* Step until outside of current statement.  */
54419370Spst
54519370Spststatic void
54698944Sobrienstep_command (char *count_string, int from_tty)
54719370Spst{
54819370Spst  step_1 (0, 0, count_string);
54919370Spst}
55019370Spst
55119370Spst/* Likewise, but skip over subroutine calls as if single instructions.  */
55219370Spst
55319370Spststatic void
55498944Sobriennext_command (char *count_string, int from_tty)
55519370Spst{
55619370Spst  step_1 (1, 0, count_string);
55719370Spst}
55819370Spst
55919370Spst/* Likewise, but step only one instruction.  */
56019370Spst
56146283Sdfrvoid
56298944Sobrienstepi_command (char *count_string, int from_tty)
56319370Spst{
56419370Spst  step_1 (0, 1, count_string);
56519370Spst}
56619370Spst
56746283Sdfrvoid
56898944Sobriennexti_command (char *count_string, int from_tty)
56919370Spst{
57019370Spst  step_1 (1, 1, count_string);
57119370Spst}
57219370Spst
57319370Spststatic void
57498944Sobriendisable_longjmp_breakpoint_cleanup (void *ignore)
57519370Spst{
57698944Sobrien  disable_longjmp_breakpoint ();
57798944Sobrien}
57898944Sobrien
57998944Sobrienstatic void
58098944Sobrienstep_1 (int skip_subroutines, int single_inst, char *count_string)
58198944Sobrien{
582130803Smarcel  int count = 1;
58319370Spst  struct frame_info *frame;
58419370Spst  struct cleanup *cleanups = 0;
58598944Sobrien  int async_exec = 0;
58619370Spst
58719370Spst  ERROR_NO_INFERIOR;
58819370Spst
58998944Sobrien  if (count_string)
59098944Sobrien    async_exec = strip_bg_char (&count_string);
59198944Sobrien
59298944Sobrien  /* If we get a request for running in the bg but the target
59398944Sobrien     doesn't support it, error out. */
59498944Sobrien  if (event_loop_p && async_exec && !target_can_async_p ())
59598944Sobrien    error ("Asynchronous execution not supported on this target.");
59698944Sobrien
59798944Sobrien  /* If we don't get a request of running in the bg, then we need
59898944Sobrien     to simulate synchronous (fg) execution. */
59998944Sobrien  if (event_loop_p && !async_exec && target_can_async_p ())
60019370Spst    {
60198944Sobrien      /* Simulate synchronous execution */
60298944Sobrien      async_disable_stdin ();
60319370Spst    }
60419370Spst
60598944Sobrien  count = count_string ? parse_and_eval_long (count_string) : 1;
60698944Sobrien
60798944Sobrien  if (!single_inst || skip_subroutines)		/* leave si command alone */
60819370Spst    {
60998944Sobrien      enable_longjmp_breakpoint ();
61098944Sobrien      if (!event_loop_p || !target_can_async_p ())
61198944Sobrien	cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
61298944Sobrien      else
61398944Sobrien        make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
61498944Sobrien    }
61598944Sobrien
61698944Sobrien  /* In synchronous case, all is well, just use the regular for loop. */
61798944Sobrien  if (!event_loop_p || !target_can_async_p ())
61898944Sobrien    {
61998944Sobrien      for (; count > 0; count--)
62098944Sobrien	{
62198944Sobrien	  clear_proceed_status ();
62298944Sobrien
62398944Sobrien	  frame = get_current_frame ();
62498944Sobrien	  if (!frame)		/* Avoid coredump here.  Why tho? */
62598944Sobrien	    error ("No current frame");
626130803Smarcel	  step_frame_id = get_frame_id (frame);
62798944Sobrien	  step_sp = read_sp ();
62898944Sobrien
62998944Sobrien	  if (!single_inst)
63098944Sobrien	    {
63198944Sobrien	      find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
63298944Sobrien	      if (step_range_end == 0)
63398944Sobrien		{
63498944Sobrien		  char *name;
63598944Sobrien		  if (find_pc_partial_function (stop_pc, &name, &step_range_start,
63698944Sobrien						&step_range_end) == 0)
63798944Sobrien		    error ("Cannot find bounds of current function");
63898944Sobrien
63998944Sobrien		  target_terminal_ours ();
64098944Sobrien		  printf_filtered ("\
64198944SobrienSingle stepping until exit from function %s, \n\
64298944Sobrienwhich has no line number information.\n", name);
64398944Sobrien		}
64498944Sobrien	    }
64598944Sobrien	  else
64698944Sobrien	    {
64798944Sobrien	      /* Say we are stepping, but stop after one insn whatever it does.  */
64898944Sobrien	      step_range_start = step_range_end = 1;
64998944Sobrien	      if (!skip_subroutines)
65098944Sobrien		/* It is stepi.
65198944Sobrien		   Don't step over function calls, not even to functions lacking
65298944Sobrien		   line numbers.  */
65398944Sobrien		step_over_calls = STEP_OVER_NONE;
65498944Sobrien	    }
65598944Sobrien
65698944Sobrien	  if (skip_subroutines)
65798944Sobrien	    step_over_calls = STEP_OVER_ALL;
65898944Sobrien
65998944Sobrien	  step_multi = (count > 1);
66098944Sobrien	  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
66198944Sobrien
66298944Sobrien	  if (!stop_step)
66398944Sobrien	    break;
66498944Sobrien	}
66598944Sobrien
66698944Sobrien      if (!single_inst || skip_subroutines)
66798944Sobrien	do_cleanups (cleanups);
66898944Sobrien      return;
66998944Sobrien    }
67098944Sobrien  /* In case of asynchronous target things get complicated, do only
67198944Sobrien     one step for now, before returning control to the event loop. Let
67298944Sobrien     the continuation figure out how many other steps we need to do,
67398944Sobrien     and handle them one at the time, through step_once(). */
67498944Sobrien  else
67598944Sobrien    {
67698944Sobrien      if (event_loop_p && target_can_async_p ())
67798944Sobrien	step_once (skip_subroutines, single_inst, count);
67898944Sobrien    }
67998944Sobrien}
68098944Sobrien
68198944Sobrien/* Called after we are done with one step operation, to check whether
68298944Sobrien   we need to step again, before we print the prompt and return control
68398944Sobrien   to the user. If count is > 1, we will need to do one more call to
68498944Sobrien   proceed(), via step_once(). Basically it is like step_once and
68598944Sobrien   step_1_continuation are co-recursive. */
68698944Sobrienstatic void
68798944Sobrienstep_1_continuation (struct continuation_arg *arg)
68898944Sobrien{
68998944Sobrien  int count;
69098944Sobrien  int skip_subroutines;
69198944Sobrien  int single_inst;
69298944Sobrien
69398944Sobrien  skip_subroutines = arg->data.integer;
69498944Sobrien  single_inst      = arg->next->data.integer;
69598944Sobrien  count            = arg->next->next->data.integer;
69698944Sobrien
69798944Sobrien  if (stop_step)
698130803Smarcel    step_once (skip_subroutines, single_inst, count - 1);
69998944Sobrien  else
70098944Sobrien    if (!single_inst || skip_subroutines)
70198944Sobrien      do_exec_cleanups (ALL_CLEANUPS);
70298944Sobrien}
70398944Sobrien
70498944Sobrien/* Do just one step operation. If count >1 we will have to set up a
70598944Sobrien   continuation to be done after the target stops (after this one
70698944Sobrien   step). This is useful to implement the 'step n' kind of commands, in
70798944Sobrien   case of asynchronous targets. We had to split step_1 into two parts,
70898944Sobrien   one to be done before proceed() and one afterwards. This function is
70998944Sobrien   called in case of step n with n>1, after the first step operation has
71098944Sobrien   been completed.*/
71198944Sobrienstatic void
71298944Sobrienstep_once (int skip_subroutines, int single_inst, int count)
71398944Sobrien{
71498944Sobrien  struct continuation_arg *arg1;
71598944Sobrien  struct continuation_arg *arg2;
71698944Sobrien  struct continuation_arg *arg3;
71798944Sobrien  struct frame_info *frame;
71898944Sobrien
71998944Sobrien  if (count > 0)
72098944Sobrien    {
72119370Spst      clear_proceed_status ();
72219370Spst
72319370Spst      frame = get_current_frame ();
72498944Sobrien      if (!frame)		/* Avoid coredump here.  Why tho? */
72519370Spst	error ("No current frame");
726130803Smarcel      step_frame_id = get_frame_id (frame);
72719370Spst      step_sp = read_sp ();
72819370Spst
72998944Sobrien      if (!single_inst)
73019370Spst	{
73119370Spst	  find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
73298944Sobrien
73398944Sobrien	  /* If we have no line info, switch to stepi mode.  */
73498944Sobrien	  if (step_range_end == 0 && step_stop_if_no_debug)
73519370Spst	    {
73698944Sobrien	      step_range_start = step_range_end = 1;
73798944Sobrien	    }
73898944Sobrien	  else if (step_range_end == 0)
73998944Sobrien	    {
74019370Spst	      char *name;
74119370Spst	      if (find_pc_partial_function (stop_pc, &name, &step_range_start,
74219370Spst					    &step_range_end) == 0)
74319370Spst		error ("Cannot find bounds of current function");
74419370Spst
74519370Spst	      target_terminal_ours ();
74619370Spst	      printf_filtered ("\
74719370SpstSingle stepping until exit from function %s, \n\
74819370Spstwhich has no line number information.\n", name);
74919370Spst	    }
75019370Spst	}
75119370Spst      else
75219370Spst	{
75319370Spst	  /* Say we are stepping, but stop after one insn whatever it does.  */
75419370Spst	  step_range_start = step_range_end = 1;
75519370Spst	  if (!skip_subroutines)
75619370Spst	    /* It is stepi.
75719370Spst	       Don't step over function calls, not even to functions lacking
75819370Spst	       line numbers.  */
75998944Sobrien	    step_over_calls = STEP_OVER_NONE;
76019370Spst	}
76119370Spst
76219370Spst      if (skip_subroutines)
76398944Sobrien	step_over_calls = STEP_OVER_ALL;
76419370Spst
76519370Spst      step_multi = (count > 1);
76698944Sobrien      arg1 =
76798944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
76898944Sobrien      arg2 =
76998944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
77098944Sobrien      arg3 =
77198944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
77298944Sobrien      arg1->next = arg2;
77398944Sobrien      arg1->data.integer = skip_subroutines;
77498944Sobrien      arg2->next = arg3;
77598944Sobrien      arg2->data.integer = single_inst;
77698944Sobrien      arg3->next = NULL;
77798944Sobrien      arg3->data.integer = count;
77898944Sobrien      add_intermediate_continuation (step_1_continuation, arg1);
77919370Spst      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
78019370Spst    }
78198944Sobrien}
78219370Spst
78319370Spst
78419370Spst/* Continue program at specified address.  */
78519370Spst
78619370Spststatic void
78798944Sobrienjump_command (char *arg, int from_tty)
78819370Spst{
789130803Smarcel  CORE_ADDR addr;
79019370Spst  struct symtabs_and_lines sals;
79119370Spst  struct symtab_and_line sal;
79219370Spst  struct symbol *fn;
79319370Spst  struct symbol *sfn;
79498944Sobrien  int async_exec = 0;
79519370Spst
79619370Spst  ERROR_NO_INFERIOR;
79719370Spst
79898944Sobrien  /* Find out whether we must run in the background. */
79998944Sobrien  if (arg != NULL)
80098944Sobrien    async_exec = strip_bg_char (&arg);
80198944Sobrien
80298944Sobrien  /* If we must run in the background, but the target can't do it,
80398944Sobrien     error out. */
80498944Sobrien  if (event_loop_p && async_exec && !target_can_async_p ())
80598944Sobrien    error ("Asynchronous execution not supported on this target.");
80698944Sobrien
80798944Sobrien  /* If we are not asked to run in the bg, then prepare to run in the
80898944Sobrien     foreground, synchronously. */
80998944Sobrien  if (event_loop_p && !async_exec && target_can_async_p ())
81098944Sobrien    {
81198944Sobrien      /* Simulate synchronous execution */
81298944Sobrien      async_disable_stdin ();
81398944Sobrien    }
81498944Sobrien
81519370Spst  if (!arg)
81619370Spst    error_no_arg ("starting address");
81719370Spst
81819370Spst  sals = decode_line_spec_1 (arg, 1);
81919370Spst  if (sals.nelts != 1)
82019370Spst    {
82119370Spst      error ("Unreasonable jump request");
82219370Spst    }
82319370Spst
82419370Spst  sal = sals.sals[0];
82598944Sobrien  xfree (sals.sals);
82619370Spst
82719370Spst  if (sal.symtab == 0 && sal.pc == 0)
82819370Spst    error ("No source file has been specified.");
82919370Spst
83098944Sobrien  resolve_sal_pc (&sal);	/* May error out */
83119370Spst
83219370Spst  /* See if we are trying to jump to another function. */
83319370Spst  fn = get_frame_function (get_current_frame ());
83419370Spst  sfn = find_pc_function (sal.pc);
83519370Spst  if (fn != NULL && sfn != fn)
83619370Spst    {
83719370Spst      if (!query ("Line %d is not in `%s'.  Jump anyway? ", sal.line,
838130803Smarcel		  SYMBOL_PRINT_NAME (fn)))
83919370Spst	{
84019370Spst	  error ("Not confirmed.");
84119370Spst	  /* NOTREACHED */
84219370Spst	}
84319370Spst    }
84419370Spst
84598944Sobrien  if (sfn != NULL)
84646283Sdfr    {
84746283Sdfr      fixup_symbol_section (sfn, 0);
84898944Sobrien      if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
84946283Sdfr	  !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
85046283Sdfr	{
85146283Sdfr	  if (!query ("WARNING!!!  Destination is in unmapped overlay!  Jump anyway? "))
85246283Sdfr	    {
85346283Sdfr	      error ("Not confirmed.");
85446283Sdfr	      /* NOTREACHED */
85546283Sdfr	    }
85646283Sdfr	}
85746283Sdfr    }
85846283Sdfr
85919370Spst  addr = sal.pc;
86019370Spst
86119370Spst  if (from_tty)
86219370Spst    {
86319370Spst      printf_filtered ("Continuing at ");
86419370Spst      print_address_numeric (addr, 1, gdb_stdout);
86519370Spst      printf_filtered (".\n");
86619370Spst    }
86719370Spst
86819370Spst  clear_proceed_status ();
86919370Spst  proceed (addr, TARGET_SIGNAL_0, 0);
87019370Spst}
87198944Sobrien
87219370Spst
87346283Sdfr/* Go to line or address in current procedure */
87446283Sdfrstatic void
87598944Sobriengo_command (char *line_no, int from_tty)
87646283Sdfr{
87798944Sobrien  if (line_no == (char *) NULL || !*line_no)
87898944Sobrien    printf_filtered (GO_USAGE);
87946283Sdfr  else
88046283Sdfr    {
88198944Sobrien      tbreak_command (line_no, from_tty);
88298944Sobrien      jump_command (line_no, from_tty);
88346283Sdfr    }
88446283Sdfr}
88598944Sobrien
88646283Sdfr
88719370Spst/* Continue program giving it specified signal.  */
88819370Spst
88919370Spststatic void
89098944Sobriensignal_command (char *signum_exp, int from_tty)
89119370Spst{
89219370Spst  enum target_signal oursig;
89319370Spst
89419370Spst  dont_repeat ();		/* Too dangerous.  */
89519370Spst  ERROR_NO_INFERIOR;
89619370Spst
89719370Spst  if (!signum_exp)
89819370Spst    error_no_arg ("signal number");
89919370Spst
90019370Spst  /* It would be even slicker to make signal names be valid expressions,
90119370Spst     (the type could be "enum $signal" or some such), then the user could
90219370Spst     assign them to convenience variables.  */
90319370Spst  oursig = target_signal_from_name (signum_exp);
90419370Spst
90519370Spst  if (oursig == TARGET_SIGNAL_UNKNOWN)
90619370Spst    {
90719370Spst      /* No, try numeric.  */
90898944Sobrien      int num = parse_and_eval_long (signum_exp);
90919370Spst
91019370Spst      if (num == 0)
91119370Spst	oursig = TARGET_SIGNAL_0;
91219370Spst      else
91319370Spst	oursig = target_signal_from_command (num);
91419370Spst    }
91519370Spst
91619370Spst  if (from_tty)
91719370Spst    {
91819370Spst      if (oursig == TARGET_SIGNAL_0)
91919370Spst	printf_filtered ("Continuing with no signal.\n");
92019370Spst      else
92119370Spst	printf_filtered ("Continuing with signal %s.\n",
92219370Spst			 target_signal_to_name (oursig));
92319370Spst    }
92419370Spst
92519370Spst  clear_proceed_status ();
92619370Spst  /* "signal 0" should not get stuck if we are stopped at a breakpoint.
92719370Spst     FIXME: Neither should "signal foo" but when I tried passing
92819370Spst     (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
92919370Spst     tried to track down yet.  */
93019370Spst  proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
93119370Spst}
93219370Spst
93319370Spst/* Proceed until we reach a different source line with pc greater than
93419370Spst   our current one or exit the function.  We skip calls in both cases.
93519370Spst
93619370Spst   Note that eventually this command should probably be changed so
93719370Spst   that only source lines are printed out when we hit the breakpoint
93819370Spst   we set.  This may involve changes to wait_for_inferior and the
93919370Spst   proceed status code.  */
94019370Spst
94119370Spststatic void
94298944Sobrienuntil_next_command (int from_tty)
94319370Spst{
94419370Spst  struct frame_info *frame;
94519370Spst  CORE_ADDR pc;
94619370Spst  struct symbol *func;
94719370Spst  struct symtab_and_line sal;
94898944Sobrien
94919370Spst  clear_proceed_status ();
95019370Spst
95119370Spst  frame = get_current_frame ();
95219370Spst
95319370Spst  /* Step until either exited from this function or greater
95419370Spst     than the current line (if in symbolic section) or pc (if
95519370Spst     not). */
95619370Spst
95719370Spst  pc = read_pc ();
95819370Spst  func = find_pc_function (pc);
95998944Sobrien
96019370Spst  if (!func)
96119370Spst    {
96219370Spst      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
96398944Sobrien
96419370Spst      if (msymbol == NULL)
96519370Spst	error ("Execution is not within a known function.");
96698944Sobrien
96719370Spst      step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
96819370Spst      step_range_end = pc;
96919370Spst    }
97019370Spst  else
97119370Spst    {
97219370Spst      sal = find_pc_line (pc, 0);
97398944Sobrien
97419370Spst      step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
97519370Spst      step_range_end = sal.end;
97619370Spst    }
97798944Sobrien
97898944Sobrien  step_over_calls = STEP_OVER_ALL;
979130803Smarcel  step_frame_id = get_frame_id (frame);
98019370Spst  step_sp = read_sp ();
98119370Spst
98219370Spst  step_multi = 0;		/* Only one call to proceed */
98398944Sobrien
98419370Spst  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
98519370Spst}
98619370Spst
98798944Sobrienstatic void
98898944Sobrienuntil_command (char *arg, int from_tty)
98919370Spst{
99098944Sobrien  int async_exec = 0;
99198944Sobrien
99219370Spst  if (!target_has_execution)
99319370Spst    error ("The program is not running.");
99498944Sobrien
99598944Sobrien  /* Find out whether we must run in the background. */
99698944Sobrien  if (arg != NULL)
99798944Sobrien    async_exec = strip_bg_char (&arg);
99898944Sobrien
99998944Sobrien  /* If we must run in the background, but the target can't do it,
100098944Sobrien     error out. */
100198944Sobrien  if (event_loop_p && async_exec && !target_can_async_p ())
100298944Sobrien    error ("Asynchronous execution not supported on this target.");
100398944Sobrien
100498944Sobrien  /* If we are not asked to run in the bg, then prepare to run in the
100598944Sobrien     foreground, synchronously. */
100698944Sobrien  if (event_loop_p && !async_exec && target_can_async_p ())
100798944Sobrien    {
100898944Sobrien      /* Simulate synchronous execution */
100998944Sobrien      async_disable_stdin ();
101098944Sobrien    }
101198944Sobrien
101219370Spst  if (arg)
1013130803Smarcel    until_break_command (arg, from_tty, 0);
101419370Spst  else
101519370Spst    until_next_command (from_tty);
101619370Spst}
1017130803Smarcel
1018130803Smarcelstatic void
1019130803Smarceladvance_command (char *arg, int from_tty)
1020130803Smarcel{
1021130803Smarcel  int async_exec = 0;
1022130803Smarcel
1023130803Smarcel  if (!target_has_execution)
1024130803Smarcel    error ("The program is not running.");
1025130803Smarcel
1026130803Smarcel  if (arg == NULL)
1027130803Smarcel    error_no_arg ("a location");
1028130803Smarcel
1029130803Smarcel  /* Find out whether we must run in the background.  */
1030130803Smarcel  if (arg != NULL)
1031130803Smarcel    async_exec = strip_bg_char (&arg);
1032130803Smarcel
1033130803Smarcel  /* If we must run in the background, but the target can't do it,
1034130803Smarcel     error out.  */
1035130803Smarcel  if (event_loop_p && async_exec && !target_can_async_p ())
1036130803Smarcel    error ("Asynchronous execution not supported on this target.");
1037130803Smarcel
1038130803Smarcel  /* If we are not asked to run in the bg, then prepare to run in the
1039130803Smarcel     foreground, synchronously.  */
1040130803Smarcel  if (event_loop_p && !async_exec && target_can_async_p ())
1041130803Smarcel    {
1042130803Smarcel      /* Simulate synchronous execution.  */
1043130803Smarcel      async_disable_stdin ();
1044130803Smarcel    }
1045130803Smarcel
1046130803Smarcel  until_break_command (arg, from_tty, 1);
1047130803Smarcel}
104819370Spst
104998944Sobrien
1050130803Smarcel/* Print the result of a function at the end of a 'finish' command.  */
1051130803Smarcel
105298944Sobrienstatic void
1053130803Smarcelprint_return_value (int struct_return, struct type *value_type)
105498944Sobrien{
1055130803Smarcel  struct cleanup *old_chain;
1056130803Smarcel  struct ui_stream *stb;
105798944Sobrien  struct value *value;
105898944Sobrien
1059130803Smarcel  if (!struct_return)
106098944Sobrien    {
1061130803Smarcel      /* The return value can be found in the inferior's registers.  */
1062130803Smarcel      value = register_value_being_returned (value_type, stop_registers);
106398944Sobrien    }
1064130803Smarcel  /* FIXME: cagney/2004-01-17: When both return_value and
1065130803Smarcel     extract_returned_value_address are available, should use that to
1066130803Smarcel     find the address of and then extract the returned value.  */
1067130803Smarcel  /* FIXME: 2003-09-27: When returning from a nested inferior function
1068130803Smarcel     call, it's possible (with no help from the architecture vector)
1069130803Smarcel     to locate and return/print a "struct return" value.  This is just
1070130803Smarcel     a more complicated case of what is already being done in in the
1071130803Smarcel     inferior function call code.  In fact, when inferior function
1072130803Smarcel     calls are made async, this will likely be made the norm.  */
1073130803Smarcel  else if (gdbarch_return_value_p (current_gdbarch))
1074130803Smarcel    /* We cannot determine the contents of the structure because it is
1075130803Smarcel       on the stack, and we don't know where, since we did not
1076130803Smarcel       initiate the call, as opposed to the call_function_by_hand
1077130803Smarcel       case.  */
107898944Sobrien    {
1079130803Smarcel      gdb_assert (gdbarch_return_value (current_gdbarch, value_type,
1080130803Smarcel					NULL, NULL, NULL)
1081130803Smarcel		  == RETURN_VALUE_STRUCT_CONVENTION);
108298944Sobrien      ui_out_text (uiout, "Value returned has type: ");
108398944Sobrien      ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
108498944Sobrien      ui_out_text (uiout, ".");
108598944Sobrien      ui_out_text (uiout, " Cannot determine contents\n");
1086130803Smarcel      return;
108798944Sobrien    }
1088130803Smarcel  else
1089130803Smarcel    {
1090130803Smarcel      if (DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS_P ())
1091130803Smarcel	{
1092130803Smarcel	  CORE_ADDR addr = DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS (stop_registers);
1093130803Smarcel	  if (!addr)
1094130803Smarcel	    error ("Function return value unknown.");
1095130803Smarcel	  value = value_at (value_type, addr, NULL);
1096130803Smarcel	}
1097130803Smarcel      else
1098130803Smarcel	{
1099130803Smarcel	  /* It is "struct return" yet the value is being extracted,
1100130803Smarcel             presumably from registers, using EXTRACT_RETURN_VALUE.
1101130803Smarcel             This doesn't make sense.  Unfortunately, the legacy
1102130803Smarcel             interfaces allowed this behavior.  Sigh!  */
1103130803Smarcel	  value = allocate_value (value_type);
1104130803Smarcel	  CHECK_TYPEDEF (value_type);
1105130803Smarcel	  /* If the function returns void, don't bother fetching the
1106130803Smarcel	     return value.  */
1107130803Smarcel	  EXTRACT_RETURN_VALUE (value_type, stop_registers,
1108130803Smarcel				VALUE_CONTENTS_RAW (value));
1109130803Smarcel	}
1110130803Smarcel    }
1111130803Smarcel
1112130803Smarcel  /* Print it.  */
1113130803Smarcel  stb = ui_out_stream_new (uiout);
1114130803Smarcel  old_chain = make_cleanup_ui_out_stream_delete (stb);
1115130803Smarcel  ui_out_text (uiout, "Value returned is ");
1116130803Smarcel  ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1117130803Smarcel		    record_latest_value (value));
1118130803Smarcel  ui_out_text (uiout, " = ");
1119130803Smarcel  value_print (value, stb->stream, 0, Val_no_prettyprint);
1120130803Smarcel  ui_out_field_stream (uiout, "return-value", stb);
1121130803Smarcel  ui_out_text (uiout, "\n");
1122130803Smarcel  do_cleanups (old_chain);
112398944Sobrien}
112498944Sobrien
112598944Sobrien/* Stuff that needs to be done by the finish command after the target
1126130803Smarcel   has stopped.  In asynchronous mode, we wait for the target to stop
1127130803Smarcel   in the call to poll or select in the event loop, so it is
1128130803Smarcel   impossible to do all the stuff as part of the finish_command
1129130803Smarcel   function itself.  The only chance we have to complete this command
1130130803Smarcel   is in fetch_inferior_event, which is called by the event loop as
1131130803Smarcel   soon as it detects that the target has stopped. This function is
1132130803Smarcel   called via the cmd_continuation pointer.  */
1133130803Smarcel
1134130803Smarcelstatic void
113598944Sobrienfinish_command_continuation (struct continuation_arg *arg)
113698944Sobrien{
1137130803Smarcel  struct symbol *function;
113898944Sobrien  struct breakpoint *breakpoint;
113998944Sobrien  struct cleanup *cleanups;
114098944Sobrien
114198944Sobrien  breakpoint = (struct breakpoint *) arg->data.pointer;
1142130803Smarcel  function = (struct symbol *) arg->next->data.pointer;
1143130803Smarcel  cleanups = (struct cleanup *) arg->next->next->data.pointer;
114498944Sobrien
114598944Sobrien  if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1146130803Smarcel      && function != NULL)
114798944Sobrien    {
114898944Sobrien      struct type *value_type;
114998944Sobrien      int struct_return;
1150130803Smarcel      int gcc_compiled;
115198944Sobrien
115298944Sobrien      value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
115398944Sobrien      if (!value_type)
115498944Sobrien	internal_error (__FILE__, __LINE__,
115598944Sobrien			"finish_command: function has no target type");
115698944Sobrien
115798944Sobrien      if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
115898944Sobrien	{
115998944Sobrien	  do_exec_cleanups (cleanups);
116098944Sobrien	  return;
116198944Sobrien	}
116298944Sobrien
1163130803Smarcel      CHECK_TYPEDEF (value_type);
1164130803Smarcel      gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1165130803Smarcel      struct_return = using_struct_return (value_type, gcc_compiled);
116698944Sobrien
116798944Sobrien      print_return_value (struct_return, value_type);
116898944Sobrien    }
1169130803Smarcel
117098944Sobrien  do_exec_cleanups (cleanups);
117198944Sobrien}
117298944Sobrien
1173130803Smarcel/* "finish": Set a temporary breakpoint at the place the selected
1174130803Smarcel   frame will return to, then continue.  */
117519370Spst
117619370Spststatic void
117798944Sobrienfinish_command (char *arg, int from_tty)
117819370Spst{
117919370Spst  struct symtab_and_line sal;
1180130803Smarcel  struct frame_info *frame;
1181130803Smarcel  struct symbol *function;
118219370Spst  struct breakpoint *breakpoint;
118319370Spst  struct cleanup *old_chain;
118498944Sobrien  struct continuation_arg *arg1, *arg2, *arg3;
118519370Spst
118698944Sobrien  int async_exec = 0;
118798944Sobrien
1188130803Smarcel  /* Find out whether we must run in the background.  */
118998944Sobrien  if (arg != NULL)
119098944Sobrien    async_exec = strip_bg_char (&arg);
119198944Sobrien
119298944Sobrien  /* If we must run in the background, but the target can't do it,
1193130803Smarcel     error out.  */
119498944Sobrien  if (event_loop_p && async_exec && !target_can_async_p ())
119598944Sobrien    error ("Asynchronous execution not supported on this target.");
119698944Sobrien
119798944Sobrien  /* If we are not asked to run in the bg, then prepare to run in the
1198130803Smarcel     foreground, synchronously.  */
119998944Sobrien  if (event_loop_p && !async_exec && target_can_async_p ())
120098944Sobrien    {
1201130803Smarcel      /* Simulate synchronous execution.  */
120298944Sobrien      async_disable_stdin ();
120398944Sobrien    }
120498944Sobrien
120519370Spst  if (arg)
120619370Spst    error ("The \"finish\" command does not take any arguments.");
120719370Spst  if (!target_has_execution)
120819370Spst    error ("The program is not running.");
1209130803Smarcel  if (deprecated_selected_frame == NULL)
121019370Spst    error ("No selected frame.");
121119370Spst
1212130803Smarcel  frame = get_prev_frame (deprecated_selected_frame);
121319370Spst  if (frame == 0)
121419370Spst    error ("\"finish\" not meaningful in the outermost frame.");
121519370Spst
121619370Spst  clear_proceed_status ();
121719370Spst
1218130803Smarcel  sal = find_pc_line (get_frame_pc (frame), 0);
1219130803Smarcel  sal.pc = get_frame_pc (frame);
122019370Spst
1221130803Smarcel  breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
122219370Spst
122398944Sobrien  if (!event_loop_p || !target_can_async_p ())
122498944Sobrien    old_chain = make_cleanup_delete_breakpoint (breakpoint);
122598944Sobrien  else
122698944Sobrien    old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
122719370Spst
122819370Spst  /* Find the function we will return from.  */
122919370Spst
1230130803Smarcel  function = find_pc_function (get_frame_pc (deprecated_selected_frame));
123119370Spst
1232130803Smarcel  /* Print info on the selected frame, including level number but not
1233130803Smarcel     source.  */
123419370Spst  if (from_tty)
123519370Spst    {
123619370Spst      printf_filtered ("Run till exit from ");
1237130803Smarcel      print_stack_frame (deprecated_selected_frame,
1238130803Smarcel			 frame_relative_level (deprecated_selected_frame), 0);
123919370Spst    }
124019370Spst
124198944Sobrien  /* If running asynchronously and the target support asynchronous
124298944Sobrien     execution, set things up for the rest of the finish command to be
124398944Sobrien     completed later on, when gdb has detected that the target has
1244130803Smarcel     stopped, in fetch_inferior_event.  */
124598944Sobrien  if (event_loop_p && target_can_async_p ())
124698944Sobrien    {
124798944Sobrien      arg1 =
124898944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
124998944Sobrien      arg2 =
125098944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
125198944Sobrien      arg3 =
125298944Sobrien	(struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
125398944Sobrien      arg1->next = arg2;
125498944Sobrien      arg2->next = arg3;
125598944Sobrien      arg3->next = NULL;
125698944Sobrien      arg1->data.pointer = breakpoint;
125798944Sobrien      arg2->data.pointer = function;
125898944Sobrien      arg3->data.pointer = old_chain;
125998944Sobrien      add_continuation (finish_command_continuation, arg1);
126098944Sobrien    }
126198944Sobrien
1262130803Smarcel  proceed_to_finish = 1;	/* We want stop_registers, please...  */
126319370Spst  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
126419370Spst
126598944Sobrien  /* Do this only if not running asynchronously or if the target
1266130803Smarcel     cannot do async execution.  Otherwise, complete this command when
1267130803Smarcel     the target actually stops, in fetch_inferior_event.  */
126898944Sobrien  if (!event_loop_p || !target_can_async_p ())
126919370Spst    {
1270130803Smarcel      /* Did we stop at our breakpoint?  */
127198944Sobrien      if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1272130803Smarcel	  && function != NULL)
127398944Sobrien	{
127498944Sobrien	  struct type *value_type;
127598944Sobrien	  int struct_return;
1276130803Smarcel	  int gcc_compiled;
127719370Spst
127898944Sobrien	  value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
127998944Sobrien	  if (!value_type)
128098944Sobrien	    internal_error (__FILE__, __LINE__,
128198944Sobrien			    "finish_command: function has no target type");
128219370Spst
1283130803Smarcel	  /* FIXME: Shouldn't we do the cleanups before returning?  */
128498944Sobrien	  if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
128598944Sobrien	    return;
128646283Sdfr
1287130803Smarcel	  CHECK_TYPEDEF (value_type);
1288130803Smarcel	  gcc_compiled = BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function));
1289130803Smarcel	  struct_return = using_struct_return (value_type, gcc_compiled);
129019370Spst
129198944Sobrien	  print_return_value (struct_return, value_type);
129298944Sobrien	}
1293130803Smarcel
129498944Sobrien      do_cleanups (old_chain);
129519370Spst    }
129619370Spst}
129719370Spst
1298130803Smarcel
129919370Spststatic void
130098944Sobrienprogram_info (char *args, int from_tty)
130119370Spst{
130219370Spst  bpstat bs = stop_bpstat;
130319370Spst  int num = bpstat_num (&bs);
130498944Sobrien
130519370Spst  if (!target_has_execution)
130619370Spst    {
130719370Spst      printf_filtered ("The program being debugged is not being run.\n");
130819370Spst      return;
130919370Spst    }
131019370Spst
131119370Spst  target_files_info ();
131219370Spst  printf_filtered ("Program stopped at %s.\n",
131398944Sobrien		   local_hex_string ((unsigned long) stop_pc));
131419370Spst  if (stop_step)
131519370Spst    printf_filtered ("It stopped after being stepped.\n");
131619370Spst  else if (num != 0)
131719370Spst    {
131819370Spst      /* There may be several breakpoints in the same place, so this
131998944Sobrien         isn't as strange as it seems.  */
132019370Spst      while (num != 0)
132119370Spst	{
132219370Spst	  if (num < 0)
132346283Sdfr	    {
132446283Sdfr	      printf_filtered ("It stopped at a breakpoint that has ");
132546283Sdfr	      printf_filtered ("since been deleted.\n");
132646283Sdfr	    }
132719370Spst	  else
132819370Spst	    printf_filtered ("It stopped at breakpoint %d.\n", num);
132919370Spst	  num = bpstat_num (&bs);
133019370Spst	}
133119370Spst    }
133219370Spst  else if (stop_signal != TARGET_SIGNAL_0)
133319370Spst    {
133419370Spst      printf_filtered ("It stopped with signal %s, %s.\n",
133519370Spst		       target_signal_to_name (stop_signal),
133619370Spst		       target_signal_to_string (stop_signal));
133719370Spst    }
133819370Spst
133919370Spst  if (!from_tty)
134046283Sdfr    {
134146283Sdfr      printf_filtered ("Type \"info stack\" or \"info registers\" ");
134246283Sdfr      printf_filtered ("for more information.\n");
134346283Sdfr    }
134419370Spst}
134519370Spst
134619370Spststatic void
134798944Sobrienenvironment_info (char *var, int from_tty)
134819370Spst{
134919370Spst  if (var)
135019370Spst    {
1351130803Smarcel      char *val = get_in_environ (inferior_environ, var);
135219370Spst      if (val)
135319370Spst	{
135419370Spst	  puts_filtered (var);
135519370Spst	  puts_filtered (" = ");
135619370Spst	  puts_filtered (val);
135719370Spst	  puts_filtered ("\n");
135819370Spst	}
135919370Spst      else
136019370Spst	{
136119370Spst	  puts_filtered ("Environment variable \"");
136219370Spst	  puts_filtered (var);
136319370Spst	  puts_filtered ("\" not defined.\n");
136419370Spst	}
136519370Spst    }
136619370Spst  else
136719370Spst    {
1368130803Smarcel      char **vector = environ_vector (inferior_environ);
136919370Spst      while (*vector)
137019370Spst	{
137119370Spst	  puts_filtered (*vector++);
137219370Spst	  puts_filtered ("\n");
137319370Spst	}
137419370Spst    }
137519370Spst}
137619370Spst
137719370Spststatic void
137898944Sobrienset_environment_command (char *arg, int from_tty)
137919370Spst{
1380130803Smarcel  char *p, *val, *var;
138119370Spst  int nullset = 0;
138219370Spst
138319370Spst  if (arg == 0)
138419370Spst    error_no_arg ("environment variable and value");
138519370Spst
138619370Spst  /* Find seperation between variable name and value */
138719370Spst  p = (char *) strchr (arg, '=');
138819370Spst  val = (char *) strchr (arg, ' ');
138919370Spst
139019370Spst  if (p != 0 && val != 0)
139119370Spst    {
139219370Spst      /* We have both a space and an equals.  If the space is before the
139398944Sobrien         equals, walk forward over the spaces til we see a nonspace
139498944Sobrien         (possibly the equals). */
139519370Spst      if (p > val)
139619370Spst	while (*val == ' ')
139719370Spst	  val++;
139819370Spst
139919370Spst      /* Now if the = is after the char following the spaces,
140098944Sobrien         take the char following the spaces.  */
140119370Spst      if (p > val)
140219370Spst	p = val - 1;
140319370Spst    }
140419370Spst  else if (val != 0 && p == 0)
140519370Spst    p = val;
140619370Spst
140719370Spst  if (p == arg)
140819370Spst    error_no_arg ("environment variable to set");
140919370Spst
141019370Spst  if (p == 0 || p[1] == 0)
141119370Spst    {
141219370Spst      nullset = 1;
141319370Spst      if (p == 0)
141419370Spst	p = arg + strlen (arg);	/* So that savestring below will work */
141519370Spst    }
141619370Spst  else
141719370Spst    {
141819370Spst      /* Not setting variable value to null */
141919370Spst      val = p + 1;
142019370Spst      while (*val == ' ' || *val == '\t')
142119370Spst	val++;
142219370Spst    }
142319370Spst
142498944Sobrien  while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
142598944Sobrien    p--;
142619370Spst
142719370Spst  var = savestring (arg, p - arg);
142819370Spst  if (nullset)
142919370Spst    {
143046283Sdfr      printf_filtered ("Setting environment variable ");
143146283Sdfr      printf_filtered ("\"%s\" to null value.\n", var);
143219370Spst      set_in_environ (inferior_environ, var, "");
143319370Spst    }
143419370Spst  else
143519370Spst    set_in_environ (inferior_environ, var, val);
143698944Sobrien  xfree (var);
143719370Spst}
143819370Spst
143919370Spststatic void
144098944Sobrienunset_environment_command (char *var, int from_tty)
144119370Spst{
144219370Spst  if (var == 0)
144319370Spst    {
144419370Spst      /* If there is no argument, delete all environment variables.
144598944Sobrien         Ask for confirmation if reading from the terminal.  */
144619370Spst      if (!from_tty || query ("Delete all environment variables? "))
144719370Spst	{
144819370Spst	  free_environ (inferior_environ);
144919370Spst	  inferior_environ = make_environ ();
145019370Spst	}
145119370Spst    }
145219370Spst  else
145319370Spst    unset_in_environ (inferior_environ, var);
145419370Spst}
145519370Spst
145619370Spst/* Handle the execution path (PATH variable) */
145719370Spst
145819370Spststatic const char path_var_name[] = "PATH";
145919370Spst
146019370Spststatic void
146198944Sobrienpath_info (char *args, int from_tty)
146219370Spst{
146319370Spst  puts_filtered ("Executable and object file path: ");
146419370Spst  puts_filtered (get_in_environ (inferior_environ, path_var_name));
146519370Spst  puts_filtered ("\n");
146619370Spst}
146719370Spst
146819370Spst/* Add zero or more directories to the front of the execution path.  */
146919370Spst
147019370Spststatic void
147198944Sobrienpath_command (char *dirname, int from_tty)
147219370Spst{
147319370Spst  char *exec_path;
147419370Spst  char *env;
147519370Spst  dont_repeat ();
147619370Spst  env = get_in_environ (inferior_environ, path_var_name);
147719370Spst  /* Can be null if path is not set */
147819370Spst  if (!env)
147919370Spst    env = "";
148098944Sobrien  exec_path = xstrdup (env);
148119370Spst  mod_path (dirname, &exec_path);
148219370Spst  set_in_environ (inferior_environ, path_var_name, exec_path);
148398944Sobrien  xfree (exec_path);
148419370Spst  if (from_tty)
148598944Sobrien    path_info ((char *) NULL, from_tty);
148619370Spst}
148798944Sobrien
148846283Sdfr
1489130803Smarcel/* Print out the machine register regnum. If regnum is -1, print all
1490130803Smarcel   registers (print_all == 1) or all non-float and non-vector
1491130803Smarcel   registers (print_all == 0).
149219370Spst
149319370Spst   For most machines, having all_registers_info() print the
1494130803Smarcel   register(s) one per line is good enough.  If a different format is
1495130803Smarcel   required, (eg, for MIPS or Pyramid 90x, which both have lots of
1496130803Smarcel   regs), or there is an existing convention for showing all the
1497130803Smarcel   registers, define the architecture method PRINT_REGISTERS_INFO to
1498130803Smarcel   provide that format.  */
149919370Spst
150098944Sobrienvoid
1501130803Smarceldefault_print_registers_info (struct gdbarch *gdbarch,
1502130803Smarcel			      struct ui_file *file,
1503130803Smarcel			      struct frame_info *frame,
1504130803Smarcel			      int regnum, int print_all)
150519370Spst{
1506130803Smarcel  int i;
1507130803Smarcel  const int numregs = NUM_REGS + NUM_PSEUDO_REGS;
1508130803Smarcel  char raw_buffer[MAX_REGISTER_SIZE];
1509130803Smarcel  char virtual_buffer[MAX_REGISTER_SIZE];
151019370Spst
1511130803Smarcel  if (DEPRECATED_DO_REGISTERS_INFO_P ())
1512130803Smarcel    {
1513130803Smarcel      DEPRECATED_DO_REGISTERS_INFO (regnum, print_all);
1514130803Smarcel      return;
1515130803Smarcel    }
1516130803Smarcel
151719370Spst  for (i = 0; i < numregs; i++)
151819370Spst    {
1519130803Smarcel      /* Decide between printing all regs, non-float / vector regs, or
1520130803Smarcel         specific reg.  */
152198944Sobrien      if (regnum == -1)
152298944Sobrien	{
1523130803Smarcel	  if (print_all)
1524130803Smarcel	    {
1525130803Smarcel	      if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1526130803Smarcel		continue;
1527130803Smarcel	    }
1528130803Smarcel	  else
1529130803Smarcel	    {
1530130803Smarcel	      if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1531130803Smarcel		continue;
1532130803Smarcel	    }
153398944Sobrien	}
153498944Sobrien      else
153598944Sobrien	{
153698944Sobrien	  if (i != regnum)
153798944Sobrien	    continue;
153898944Sobrien	}
153919370Spst
154019370Spst      /* If the register name is empty, it is undefined for this
154198944Sobrien         processor, so don't display anything.  */
154246283Sdfr      if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
154319370Spst	continue;
154419370Spst
1545130803Smarcel      fputs_filtered (REGISTER_NAME (i), file);
1546130803Smarcel      print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), file);
154719370Spst
154819370Spst      /* Get the data in raw format.  */
1549130803Smarcel      if (! frame_register_read (frame, i, raw_buffer))
155019370Spst	{
1551130803Smarcel	  fprintf_filtered (file, "*value not available*\n");
155219370Spst	  continue;
155319370Spst	}
155419370Spst
1555130803Smarcel      /* FIXME: cagney/2002-08-03: This code shouldn't be necessary.
1556130803Smarcel         The function frame_register_read() should have returned the
1557130803Smarcel         pre-cooked register so no conversion is necessary.  */
155819370Spst      /* Convert raw data to virtual format if necessary.  */
1559130803Smarcel      if (DEPRECATED_REGISTER_CONVERTIBLE_P ()
1560130803Smarcel	  && DEPRECATED_REGISTER_CONVERTIBLE (i))
156119370Spst	{
1562130803Smarcel	  DEPRECATED_REGISTER_CONVERT_TO_VIRTUAL (i, register_type (current_gdbarch, i),
156319370Spst				       raw_buffer, virtual_buffer);
156419370Spst	}
156519370Spst      else
156698944Sobrien	{
156798944Sobrien	  memcpy (virtual_buffer, raw_buffer,
1568130803Smarcel		  DEPRECATED_REGISTER_VIRTUAL_SIZE (i));
156998944Sobrien	}
157019370Spst
1571130803Smarcel      /* If virtual format is floating, print it that way, and in raw
1572130803Smarcel         hex.  */
1573130803Smarcel      if (TYPE_CODE (register_type (current_gdbarch, i)) == TYPE_CODE_FLT)
157419370Spst	{
1575130803Smarcel	  int j;
157619370Spst
1577130803Smarcel	  val_print (register_type (current_gdbarch, i), virtual_buffer, 0, 0,
1578130803Smarcel		     file, 0, 1, 0, Val_pretty_default);
157919370Spst
1580130803Smarcel	  fprintf_filtered (file, "\t(raw 0x");
1581130803Smarcel	  for (j = 0; j < DEPRECATED_REGISTER_RAW_SIZE (i); j++)
158246283Sdfr	    {
1583130803Smarcel	      int idx;
1584130803Smarcel	      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1585130803Smarcel		idx = j;
1586130803Smarcel	      else
1587130803Smarcel		idx = DEPRECATED_REGISTER_RAW_SIZE (i) - 1 - j;
1588130803Smarcel	      fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[idx]);
158946283Sdfr	    }
1590130803Smarcel	  fprintf_filtered (file, ")");
159119370Spst	}
159219370Spst      else
159319370Spst	{
1594130803Smarcel	  /* Print the register in hex.  */
1595130803Smarcel	  val_print (register_type (current_gdbarch, i), virtual_buffer, 0, 0,
1596130803Smarcel		     file, 'x', 1, 0, Val_pretty_default);
1597130803Smarcel          /* If not a vector register, print it also according to its
1598130803Smarcel             natural format.  */
1599130803Smarcel	  if (TYPE_VECTOR (register_type (current_gdbarch, i)) == 0)
1600130803Smarcel	    {
1601130803Smarcel	      fprintf_filtered (file, "\t");
1602130803Smarcel	      val_print (register_type (current_gdbarch, i), virtual_buffer, 0, 0,
1603130803Smarcel			 file, 0, 1, 0, Val_pretty_default);
1604130803Smarcel	    }
160519370Spst	}
160619370Spst
1607130803Smarcel      fprintf_filtered (file, "\n");
160819370Spst    }
160919370Spst}
161019370Spst
161146283Sdfrvoid
161298944Sobrienregisters_info (char *addr_exp, int fpregs)
161319370Spst{
161419370Spst  int regnum, numregs;
1615130803Smarcel  char *end;
161619370Spst
161719370Spst  if (!target_has_registers)
161819370Spst    error ("The program has no registers now.");
1619130803Smarcel  if (deprecated_selected_frame == NULL)
162019370Spst    error ("No selected frame.");
162119370Spst
162219370Spst  if (!addr_exp)
162319370Spst    {
1624130803Smarcel      gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1625130803Smarcel				    deprecated_selected_frame, -1, fpregs);
162619370Spst      return;
162719370Spst    }
162819370Spst
1629130803Smarcel  while (*addr_exp != '\0')
163098944Sobrien    {
1631130803Smarcel      char *start;
1632130803Smarcel      const char *end;
1633130803Smarcel
1634130803Smarcel      /* Keep skipping leading white space.  */
1635130803Smarcel      if (isspace ((*addr_exp)))
1636130803Smarcel	{
1637130803Smarcel	  addr_exp++;
1638130803Smarcel	  continue;
1639130803Smarcel	}
1640130803Smarcel
1641130803Smarcel      /* Discard any leading ``$''.  Check that there is something
1642130803Smarcel         resembling a register following it.  */
164319370Spst      if (addr_exp[0] == '$')
164419370Spst	addr_exp++;
1645130803Smarcel      if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1646130803Smarcel	error ("Missing register name");
1647130803Smarcel
1648130803Smarcel      /* Find the start/end of this register name/num/group.  */
1649130803Smarcel      start = addr_exp;
1650130803Smarcel      while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1651130803Smarcel	addr_exp++;
165219370Spst      end = addr_exp;
1653130803Smarcel
1654130803Smarcel      /* Figure out what we've found and display it.  */
165546283Sdfr
1656130803Smarcel      /* A register name?  */
1657130803Smarcel      {
1658130803Smarcel	int regnum = frame_map_name_to_regnum (deprecated_selected_frame,
1659130803Smarcel					       start, end - start);
1660130803Smarcel	if (regnum >= 0)
1661130803Smarcel	  {
1662130803Smarcel	    gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1663130803Smarcel					  deprecated_selected_frame, regnum, fpregs);
1664130803Smarcel	    continue;
1665130803Smarcel	  }
1666130803Smarcel      }
1667130803Smarcel
1668130803Smarcel      /* A register number?  (how portable is this one?).  */
1669130803Smarcel      {
1670130803Smarcel	char *endptr;
1671130803Smarcel	int regnum = strtol (start, &endptr, 0);
1672130803Smarcel	if (endptr == end
1673130803Smarcel	    && regnum >= 0
1674130803Smarcel	    && regnum < NUM_REGS + NUM_PSEUDO_REGS)
1675130803Smarcel	  {
1676130803Smarcel	    gdbarch_print_registers_info (current_gdbarch, gdb_stdout,
1677130803Smarcel					  deprecated_selected_frame, regnum, fpregs);
1678130803Smarcel	    continue;
1679130803Smarcel	  }
1680130803Smarcel      }
168146283Sdfr
1682130803Smarcel      /* A register group?  */
1683130803Smarcel      {
1684130803Smarcel	struct reggroup *group;
1685130803Smarcel	for (group = reggroup_next (current_gdbarch, NULL);
1686130803Smarcel	     group != NULL;
1687130803Smarcel	     group = reggroup_next (current_gdbarch, group))
1688130803Smarcel	  {
1689130803Smarcel	    /* Don't bother with a length check.  Should the user
1690130803Smarcel	       enter a short register group name, go with the first
1691130803Smarcel	       group that matches.  */
1692130803Smarcel	    if (strncmp (start, reggroup_name (group), end - start) == 0)
1693130803Smarcel	      break;
1694130803Smarcel	  }
1695130803Smarcel	if (group != NULL)
1696130803Smarcel	  {
1697130803Smarcel	    int regnum;
1698130803Smarcel	    for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1699130803Smarcel	      {
1700130803Smarcel		if (gdbarch_register_reggroup_p (current_gdbarch, regnum,
1701130803Smarcel						 group))
1702130803Smarcel		  gdbarch_print_registers_info (current_gdbarch,
1703130803Smarcel						gdb_stdout, deprecated_selected_frame,
1704130803Smarcel						regnum, fpregs);
1705130803Smarcel	      }
1706130803Smarcel	    continue;
1707130803Smarcel	  }
1708130803Smarcel      }
170946283Sdfr
1710130803Smarcel      /* Nothing matched.  */
1711130803Smarcel      error ("Invalid register `%.*s'", (int) (end - start), start);
171298944Sobrien    }
171319370Spst}
171419370Spst
171546283Sdfrvoid
171698944Sobrienall_registers_info (char *addr_exp, int from_tty)
171719370Spst{
171819370Spst  registers_info (addr_exp, 1);
171919370Spst}
172019370Spst
1721130803Smarcelstatic void
172298944Sobriennofp_registers_info (char *addr_exp, int from_tty)
172319370Spst{
172419370Spst  registers_info (addr_exp, 0);
172519370Spst}
1726130803Smarcel
1727130803Smarcelstatic void
1728130803Smarcelprint_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1729130803Smarcel		   struct frame_info *frame, const char *args)
1730130803Smarcel{
1731130803Smarcel  if (!target_has_registers)
1732130803Smarcel    error ("The program has no registers now.");
1733130803Smarcel  if (deprecated_selected_frame == NULL)
1734130803Smarcel    error ("No selected frame.");
1735130803Smarcel
1736130803Smarcel  if (gdbarch_print_vector_info_p (gdbarch))
1737130803Smarcel    gdbarch_print_vector_info (gdbarch, file, frame, args);
1738130803Smarcel  else
1739130803Smarcel    {
1740130803Smarcel      int regnum;
1741130803Smarcel      int printed_something = 0;
1742130803Smarcel
1743130803Smarcel      for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1744130803Smarcel	{
1745130803Smarcel	  if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1746130803Smarcel	    {
1747130803Smarcel	      printed_something = 1;
1748130803Smarcel	      gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1749130803Smarcel	    }
1750130803Smarcel	}
1751130803Smarcel      if (!printed_something)
1752130803Smarcel	fprintf_filtered (file, "No vector information\n");
1753130803Smarcel    }
1754130803Smarcel}
1755130803Smarcel
1756130803Smarcelstatic void
1757130803Smarcelvector_info (char *args, int from_tty)
1758130803Smarcel{
1759130803Smarcel  print_vector_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
1760130803Smarcel}
176198944Sobrien
176246283Sdfr
176319370Spst/*
176419370Spst * TODO:
176519370Spst * Should save/restore the tty state since it might be that the
176619370Spst * program to be debugged was started on this tty and it wants
176719370Spst * the tty in some state other than what we want.  If it's running
176819370Spst * on another terminal or without a terminal, then saving and
176919370Spst * restoring the tty state is a harmless no-op.
177019370Spst * This only needs to be done if we are attaching to a process.
177119370Spst */
177219370Spst
177319370Spst/*
177419370Spst   attach_command --
177519370Spst   takes a program started up outside of gdb and ``attaches'' to it.
177619370Spst   This stops it cold in its tracks and allows us to start debugging it.
177719370Spst   and wait for the trace-trap that results from attaching.  */
177819370Spst
177919370Spstvoid
178098944Sobrienattach_command (char *args, int from_tty)
178119370Spst{
178298944Sobrien  char *exec_file;
178398944Sobrien  char *full_exec_path = NULL;
178419370Spst
178598944Sobrien  dont_repeat ();		/* Not for the faint of heart */
178646283Sdfr
178719370Spst  if (target_has_execution)
178819370Spst    {
178919370Spst      if (query ("A program is being debugged already.  Kill it? "))
179019370Spst	target_kill ();
179119370Spst      else
179219370Spst	error ("Not killed.");
179319370Spst    }
179419370Spst
179519370Spst  target_attach (args, from_tty);
179619370Spst
179719370Spst  /* Set up the "saved terminal modes" of the inferior
179819370Spst     based on what modes we are starting it with.  */
179919370Spst  target_terminal_init ();
180019370Spst
180119370Spst  /* Install inferior's terminal modes.  */
180219370Spst  target_terminal_inferior ();
180319370Spst
180419370Spst  /* Set up execution context to know that we should return from
180519370Spst     wait_for_inferior as soon as the target reports a stop.  */
180619370Spst  init_wait_for_inferior ();
180719370Spst  clear_proceed_status ();
180819370Spst
180919370Spst  /* No traps are generated when attaching to inferior under Mach 3
181019370Spst     or GNU hurd.  */
181119370Spst#ifndef ATTACH_NO_WAIT
1812130803Smarcel  /* Careful here. See comments in inferior.h.  Basically some OSes
1813130803Smarcel     don't ignore SIGSTOPs on continue requests anymore.  We need a
1814130803Smarcel     way for handle_inferior_event to reset the stop_signal variable
1815130803Smarcel     after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for.  */
1816130803Smarcel  stop_soon = STOP_QUIETLY_NO_SIGSTOP;
181719370Spst  wait_for_inferior ();
1818130803Smarcel  stop_soon = NO_STOP_QUIETLY;
181919370Spst#endif
182019370Spst
182146283Sdfr  /*
182246283Sdfr   * If no exec file is yet known, try to determine it from the
182346283Sdfr   * process itself.
182446283Sdfr   */
182546283Sdfr  exec_file = (char *) get_exec_file (0);
182698944Sobrien  if (!exec_file)
182798944Sobrien    {
182898944Sobrien      exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
182998944Sobrien      if (exec_file)
183098944Sobrien	{
183198944Sobrien	  /* It's possible we don't have a full path, but rather just a
183298944Sobrien	     filename.  Some targets, such as HP-UX, don't provide the
183398944Sobrien	     full path, sigh.
183446283Sdfr
183598944Sobrien	     Attempt to qualify the filename against the source path.
183698944Sobrien	     (If that fails, we'll just fall back on the original
183798944Sobrien	     filename.  Not much more we can do...)
183898944Sobrien	   */
183998944Sobrien	  if (!source_full_path_of (exec_file, &full_exec_path))
184098944Sobrien	    full_exec_path = savestring (exec_file, strlen (exec_file));
184146283Sdfr
184298944Sobrien	  exec_file_attach (full_exec_path, from_tty);
184398944Sobrien	  symbol_file_add_main (full_exec_path, from_tty);
184498944Sobrien	}
184546283Sdfr    }
184646283Sdfr
184719370Spst#ifdef SOLIB_ADD
184898944Sobrien  /* Add shared library symbols from the newly attached process, if any.  */
184998944Sobrien  SOLIB_ADD ((char *) 0, from_tty, &current_target, auto_solib_add);
185098944Sobrien  re_enable_breakpoints_in_shlibs ();
185119370Spst#endif
185219370Spst
185346283Sdfr  /* Take any necessary post-attaching actions for this platform.
185498944Sobrien   */
185598944Sobrien  target_post_attach (PIDGET (inferior_ptid));
185646283Sdfr
185719370Spst  normal_stop ();
185898944Sobrien
185998944Sobrien  if (attach_hook)
186098944Sobrien    attach_hook ();
186119370Spst}
186219370Spst
186319370Spst/*
186419370Spst * detach_command --
186519370Spst * takes a program previously attached to and detaches it.
186619370Spst * The program resumes execution and will no longer stop
186719370Spst * on signals, etc.  We better not have left any breakpoints
186819370Spst * in the program or it'll die when it hits one.  For this
186919370Spst * to work, it may be necessary for the process to have been
187019370Spst * previously attached.  It *might* work if the program was
187119370Spst * started via the normal ptrace (PTRACE_TRACEME).
187219370Spst */
187319370Spst
187419370Spststatic void
187598944Sobriendetach_command (char *args, int from_tty)
187619370Spst{
187798944Sobrien  dont_repeat ();		/* Not for the faint of heart */
187819370Spst  target_detach (args, from_tty);
187946283Sdfr#if defined(SOLIB_RESTART)
188046283Sdfr  SOLIB_RESTART ();
188146283Sdfr#endif
188298944Sobrien  if (detach_hook)
188398944Sobrien    detach_hook ();
188419370Spst}
188519370Spst
1886130803Smarcel/* Disconnect from the current target without resuming it (leaving it
1887130803Smarcel   waiting for a debugger).
188898944Sobrien
1889130803Smarcel   We'd better not have left any breakpoints in the program or the
1890130803Smarcel   next debugger will get confused.  Currently only supported for some
1891130803Smarcel   remote targets, since the normal attach mechanisms don't work on
1892130803Smarcel   stopped processes on some native platforms (e.g. GNU/Linux).  */
1893130803Smarcel
1894130803Smarcelstatic void
1895130803Smarceldisconnect_command (char *args, int from_tty)
189698944Sobrien{
1897130803Smarcel  dont_repeat ();		/* Not for the faint of heart */
1898130803Smarcel  target_disconnect (args, from_tty);
1899130803Smarcel#if defined(SOLIB_RESTART)
1900130803Smarcel  SOLIB_RESTART ();
1901130803Smarcel#endif
1902130803Smarcel  if (detach_hook)
1903130803Smarcel    detach_hook ();
190498944Sobrien}
190598944Sobrien
1906130803Smarcel/* Stop the execution of the target while running in async mode, in
1907130803Smarcel   the backgound. */
1908130803Smarcelvoid
190998944Sobrieninterrupt_target_command (char *args, int from_tty)
191098944Sobrien{
191198944Sobrien  if (event_loop_p && target_can_async_p ())
191298944Sobrien    {
191398944Sobrien      dont_repeat ();		/* Not for the faint of heart */
191498944Sobrien      target_stop ();
191598944Sobrien    }
191698944Sobrien}
191798944Sobrien
191819370Spststatic void
1919130803Smarcelprint_float_info (struct gdbarch *gdbarch, struct ui_file *file,
1920130803Smarcel		  struct frame_info *frame, const char *args)
192119370Spst{
1922130803Smarcel  if (!target_has_registers)
1923130803Smarcel    error ("The program has no registers now.");
1924130803Smarcel  if (deprecated_selected_frame == NULL)
1925130803Smarcel    error ("No selected frame.");
1926130803Smarcel
1927130803Smarcel  if (gdbarch_print_float_info_p (gdbarch))
1928130803Smarcel    gdbarch_print_float_info (gdbarch, file, frame, args);
1929130803Smarcel  else
1930130803Smarcel    {
1931130803Smarcel      int regnum;
1932130803Smarcel      int printed_something = 0;
1933130803Smarcel
1934130803Smarcel      for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1935130803Smarcel	{
1936130803Smarcel	  if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
1937130803Smarcel	    {
1938130803Smarcel	      printed_something = 1;
1939130803Smarcel	      gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1940130803Smarcel	    }
1941130803Smarcel	}
1942130803Smarcel      if (!printed_something)
1943130803Smarcel	fprintf_filtered (file, "\
1944130803SmarcelNo floating-point info available for this processor.\n");
1945130803Smarcel    }
194619370Spst}
1947130803Smarcel
1948130803Smarcelstatic void
1949130803Smarcelfloat_info (char *args, int from_tty)
1950130803Smarcel{
1951130803Smarcel  print_float_info (current_gdbarch, gdb_stdout, deprecated_selected_frame, args);
1952130803Smarcel}
195319370Spst
195419370Spststatic void
195598944Sobrienunset_command (char *args, int from_tty)
195619370Spst{
195746283Sdfr  printf_filtered ("\"unset\" must be followed by the name of ");
195846283Sdfr  printf_filtered ("an unset subcommand.\n");
195919370Spst  help_list (unsetlist, "unset ", -1, gdb_stdout);
196019370Spst}
196119370Spst
196219370Spstvoid
196398944Sobrien_initialize_infcmd (void)
196419370Spst{
196519370Spst  struct cmd_list_element *c;
196619370Spst
196798944Sobrien  c = add_com ("tty", class_run, tty_command,
196898944Sobrien	       "Set terminal for future runs of program being debugged.");
1969130803Smarcel  set_cmd_completer (c, filename_completer);
197098944Sobrien
197198944Sobrien  c = add_set_cmd ("args", class_run, var_string_noescape,
197298944Sobrien		   (char *) &inferior_args,
197398944Sobrien		   "Set argument list to give program being debugged when it is started.\n\
197419370SpstFollow this command with any number of args, to be passed to the program.",
197598944Sobrien		   &setlist);
1976130803Smarcel  set_cmd_completer (c, filename_completer);
197798944Sobrien  set_cmd_sfunc (c, notice_args_set);
197898944Sobrien  c = add_show_from_set (c, &showlist);
197998944Sobrien  set_cmd_sfunc (c, notice_args_read);
198019370Spst
198119370Spst  c = add_cmd
198219370Spst    ("environment", no_class, environment_info,
198319370Spst     "The environment to give the program, or one variable's value.\n\
198419370SpstWith an argument VAR, prints the value of environment variable VAR to\n\
198519370Spstgive the program being debugged.  With no arguments, prints the entire\n\
198619370Spstenvironment to be given to the program.", &showlist);
1987130803Smarcel  set_cmd_completer (c, noop_completer);
198819370Spst
198919370Spst  add_prefix_cmd ("unset", no_class, unset_command,
1990130803Smarcel		  "Complement to certain \"set\" commands.",
199119370Spst		  &unsetlist, "unset ", 0, &cmdlist);
199298944Sobrien
199319370Spst  c = add_cmd ("environment", class_run, unset_environment_command,
199498944Sobrien	       "Cancel environment variable VAR for the program.\n\
199519370SpstThis does not affect the program until the next \"run\" command.",
199698944Sobrien	       &unsetlist);
1997130803Smarcel  set_cmd_completer (c, noop_completer);
199819370Spst
199919370Spst  c = add_cmd ("environment", class_run, set_environment_command,
200019370Spst	       "Set environment variable value to give the program.\n\
200119370SpstArguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
200219370SpstVALUES of environment variables are uninterpreted strings.\n\
200319370SpstThis does not affect the program until the next \"run\" command.",
200498944Sobrien	       &setlist);
2005130803Smarcel  set_cmd_completer (c, noop_completer);
200698944Sobrien
200798944Sobrien  c = add_com ("path", class_files, path_command,
200898944Sobrien	       "Add directory DIR(s) to beginning of search path for object files.\n\
200919370Spst$cwd in the path means the current working directory.\n\
201019370SpstThis path is equivalent to the $PATH shell variable.  It is a list of\n\
201119370Spstdirectories, separated by colons.  These directories are searched to find\n\
201219370Spstfully linked executable files and separately compiled object files as needed.");
2013130803Smarcel  set_cmd_completer (c, filename_completer);
201419370Spst
201519370Spst  c = add_cmd ("paths", no_class, path_info,
201698944Sobrien	       "Current search path for finding object files.\n\
201719370Spst$cwd in the path means the current working directory.\n\
201819370SpstThis path is equivalent to the $PATH shell variable.  It is a list of\n\
201919370Spstdirectories, separated by colons.  These directories are searched to find\n\
202046283Sdfrfully linked executable files and separately compiled object files as needed.",
202146283Sdfr	       &showlist);
2022130803Smarcel  set_cmd_completer (c, noop_completer);
202319370Spst
202498944Sobrien  add_com ("attach", class_run, attach_command,
202598944Sobrien	   "Attach to a process or file outside of GDB.\n\
202619370SpstThis command attaches to another target, of the same type as your last\n\
202746283Sdfr\"target\" command (\"info files\" will show your target stack).\n\
202819370SpstThe command may take as argument a process id or a device file.\n\
202919370SpstFor a process id, you must have permission to send the process a signal,\n\
203019370Spstand it must have the same effective uid as the debugger.\n\
203146283SdfrWhen using \"attach\" with a process id, the debugger finds the\n\
203246283Sdfrprogram running in the process, looking first in the current working\n\
203346283Sdfrdirectory, or (if not found there) using the source file search path\n\
203446283Sdfr(see the \"directory\" command).  You can also use the \"file\" command\n\
203546283Sdfrto specify the program, and to load its symbol table.");
203619370Spst
203719370Spst  add_com ("detach", class_run, detach_command,
203819370Spst	   "Detach a process or file previously attached.\n\
203946283SdfrIf a process, it is no longer traced, and it continues its execution.  If\n\
204046283Sdfryou were debugging a file, the file is closed and gdb no longer accesses it.");
204119370Spst
2042130803Smarcel  add_com ("disconnect", class_run, disconnect_command,
2043130803Smarcel	   "Disconnect from a target.\n\
2044130803SmarcelThe target will wait for another debugger to connect.  Not available for\n\
2045130803Smarcelall targets.");
2046130803Smarcel
204719370Spst  add_com ("signal", class_run, signal_command,
204819370Spst	   "Continue program giving it signal specified by the argument.\n\
204919370SpstAn argument of \"0\" means continue program without giving it a signal.");
205019370Spst
205119370Spst  add_com ("stepi", class_run, stepi_command,
205219370Spst	   "Step one instruction exactly.\n\
205319370SpstArgument N means do this N times (or till program stops for another reason).");
205419370Spst  add_com_alias ("si", "stepi", class_alias, 0);
205519370Spst
205619370Spst  add_com ("nexti", class_run, nexti_command,
205719370Spst	   "Step one instruction, but proceed through subroutine calls.\n\
205819370SpstArgument N means do this N times (or till program stops for another reason).");
205919370Spst  add_com_alias ("ni", "nexti", class_alias, 0);
206019370Spst
206119370Spst  add_com ("finish", class_run, finish_command,
206219370Spst	   "Execute until selected stack frame returns.\n\
206319370SpstUpon return, the value returned is printed and put in the value history.");
206419370Spst
206519370Spst  add_com ("next", class_run, next_command,
206619370Spst	   "Step program, proceeding through subroutine calls.\n\
206719370SpstLike the \"step\" command as long as subroutine calls do not happen;\n\
206819370Spstwhen they do, the call is treated as one instruction.\n\
206919370SpstArgument N means do this N times (or till program stops for another reason).");
207019370Spst  add_com_alias ("n", "next", class_run, 1);
207146283Sdfr  if (xdb_commands)
207298944Sobrien    add_com_alias ("S", "next", class_run, 1);
207319370Spst
207419370Spst  add_com ("step", class_run, step_command,
207519370Spst	   "Step program until it reaches a different source line.\n\
207619370SpstArgument N means do this N times (or till program stops for another reason).");
207719370Spst  add_com_alias ("s", "step", class_run, 1);
207819370Spst
207998944Sobrien  c = add_com ("until", class_run, until_command,
208098944Sobrien	       "Execute until the program reaches a source line greater than the current\n\
2081130803Smarcelor a specified location (same args as break command) within the current frame.");
2082130803Smarcel  set_cmd_completer (c, location_completer);
208319370Spst  add_com_alias ("u", "until", class_run, 1);
208498944Sobrien
2085130803Smarcel  c = add_com ("advance", class_run, advance_command,
2086130803Smarcel	       "Continue the program up to the given location (same form as args for break command).\n\
2087130803SmarcelExecution will also stop upon exit from the current stack frame.");
2088130803Smarcel  set_cmd_completer (c, location_completer);
2089130803Smarcel
209098944Sobrien  c = add_com ("jump", class_run, jump_command,
209198944Sobrien	       "Continue program being debugged at specified line or address.\n\
209219370SpstGive as argument either LINENUM or *ADDR, where ADDR is an expression\n\
209319370Spstfor an address to start at.");
2094130803Smarcel  set_cmd_completer (c, location_completer);
209519370Spst
209698944Sobrien  if (xdb_commands)
209798944Sobrien    {
209898944Sobrien      c = add_com ("go", class_run, go_command,
209998944Sobrien		   "Usage: go <location>\n\
210046283SdfrContinue program being debugged, stopping at specified line or \n\
210146283Sdfraddress.\n\
210246283SdfrGive as argument either LINENUM or *ADDR, where ADDR is an \n\
210346283Sdfrexpression for an address to start at.\n\
210446283SdfrThis command is a combination of tbreak and jump.");
2105130803Smarcel      set_cmd_completer (c, location_completer);
210698944Sobrien    }
210798944Sobrien
210846283Sdfr  if (xdb_commands)
210998944Sobrien    add_com_alias ("g", "go", class_run, 1);
211046283Sdfr
211119370Spst  add_com ("continue", class_run, continue_command,
211219370Spst	   "Continue program being debugged, after signal or breakpoint.\n\
211319370SpstIf proceeding from breakpoint, a number N may be used as an argument,\n\
211419370Spstwhich means to set the ignore count of that breakpoint to N - 1 (so that\n\
211519370Spstthe breakpoint won't break until the Nth time it is reached).");
211619370Spst  add_com_alias ("c", "cont", class_run, 1);
211719370Spst  add_com_alias ("fg", "cont", class_run, 1);
211819370Spst
211998944Sobrien  c = add_com ("run", class_run, run_command,
212019370Spst	   "Start debugged program.  You may specify arguments to give it.\n\
212119370SpstArgs may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
212219370SpstInput and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
212319370SpstWith no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
212419370SpstTo cancel previous arguments and run with no arguments,\n\
212519370Spstuse \"set args\" without arguments.");
2126130803Smarcel  set_cmd_completer (c, filename_completer);
212719370Spst  add_com_alias ("r", "run", class_run, 1);
212846283Sdfr  if (xdb_commands)
212946283Sdfr    add_com ("R", class_run, run_no_args_command,
213098944Sobrien	     "Start debugged program with no arguments.");
213119370Spst
213298944Sobrien  add_com ("interrupt", class_run, interrupt_target_command,
213398944Sobrien	   "Interrupt the execution of the debugged program.");
213498944Sobrien
213519370Spst  add_info ("registers", nofp_registers_info,
213698944Sobrien	    "List of integer registers and their contents, for selected stack frame.\n\
213719370SpstRegister name as argument means describe only that register.");
213898944Sobrien  add_info_alias ("r", "registers", 1);
213919370Spst
214046283Sdfr  if (xdb_commands)
214198944Sobrien    add_com ("lr", class_info, nofp_registers_info,
214298944Sobrien	     "List of integer registers and their contents, for selected stack frame.\n\
214346283Sdfr  Register name as argument means describe only that register.");
214419370Spst  add_info ("all-registers", all_registers_info,
214598944Sobrien	    "List of all registers and their contents, for selected stack frame.\n\
214619370SpstRegister name as argument means describe only that register.");
214719370Spst
214819370Spst  add_info ("program", program_info,
214919370Spst	    "Execution status of the program.");
215019370Spst
215119370Spst  add_info ("float", float_info,
215219370Spst	    "Print the status of the floating point unit\n");
215319370Spst
2154130803Smarcel  add_info ("vector", vector_info,
2155130803Smarcel	    "Print the status of the vector unit\n");
2156130803Smarcel
215719370Spst  inferior_environ = make_environ ();
215819370Spst  init_environ (inferior_environ);
215919370Spst}
2160