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