OSDN Git Service

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