11d5310766ce077755669461685f5875786e417b
[external/binutils.git] / gdb / infcmd.c
1 /* Memory-access and commands for "inferior" process, for GDB.
2
3    Copyright (C) 1986-2015 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include <signal.h>
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "infrun.h"
28 #include "environ.h"
29 #include "value.h"
30 #include "gdbcmd.h"
31 #include "symfile.h"
32 #include "gdbcore.h"
33 #include "target.h"
34 #include "language.h"
35 #include "objfiles.h"
36 #include "completer.h"
37 #include "ui-out.h"
38 #include "event-top.h"
39 #include "parser-defs.h"
40 #include "regcache.h"
41 #include "reggroups.h"
42 #include "block.h"
43 #include "solib.h"
44 #include <ctype.h>
45 #include "observer.h"
46 #include "target-descriptions.h"
47 #include "user-regs.h"
48 #include "cli/cli-decode.h"
49 #include "gdbthread.h"
50 #include "valprint.h"
51 #include "inline-frame.h"
52 #include "tracepoint.h"
53 #include "inf-loop.h"
54 #include "continuations.h"
55 #include "linespec.h"
56 #include "cli/cli-utils.h"
57
58 /* Local functions: */
59
60 static void nofp_registers_info (char *, int);
61
62 static void until_next_command (int);
63
64 static void until_command (char *, int);
65
66 static void path_info (char *, int);
67
68 static void path_command (char *, int);
69
70 static void unset_command (char *, int);
71
72 static void float_info (char *, int);
73
74 static void disconnect_command (char *, int);
75
76 static void unset_environment_command (char *, int);
77
78 static void set_environment_command (char *, int);
79
80 static void environment_info (char *, int);
81
82 static void program_info (char *, int);
83
84 static void finish_command (char *, int);
85
86 static void signal_command (char *, int);
87
88 static void jump_command (char *, int);
89
90 static void step_1 (int, int, char *);
91 static void step_once (int skip_subroutines, int single_inst,
92                        int count, int thread);
93
94 static void next_command (char *, int);
95
96 static void step_command (char *, int);
97
98 static void run_command (char *, int);
99
100 void _initialize_infcmd (void);
101
102 #define ERROR_NO_INFERIOR \
103    if (!target_has_execution) error (_("The program is not being run."));
104
105 /* Scratch area where string containing arguments to give to the
106    program will be stored by 'set args'.  As soon as anything is
107    stored, notice_args_set will move it into per-inferior storage.
108    Arguments are separated by spaces.  Empty string (pointer to '\0')
109    means no args.  */
110
111 static char *inferior_args_scratch;
112
113 /* Scratch area where 'set inferior-tty' will store user-provided value.
114    We'll immediate copy it into per-inferior storage.  */
115
116 static char *inferior_io_terminal_scratch;
117
118 /* Pid of our debugged inferior, or 0 if no inferior now.
119    Since various parts of infrun.c test this to see whether there is a program
120    being debugged it should be nonzero (currently 3 is used) for remote
121    debugging.  */
122
123 ptid_t inferior_ptid;
124
125 /* Address at which inferior stopped.  */
126
127 CORE_ADDR stop_pc;
128
129 /* Nonzero if stopped due to completion of a stack dummy routine.  */
130
131 enum stop_stack_kind stop_stack_dummy;
132
133 /* Nonzero if stopped due to a random (unexpected) signal in inferior
134    process.  */
135
136 int stopped_by_random_signal;
137
138 /* See inferior.h.  */
139
140 int startup_with_shell = 1;
141
142 \f
143 /* Accessor routines.  */
144
145 /* Set the io terminal for the current inferior.  Ownership of
146    TERMINAL_NAME is not transferred.  */
147
148 void 
149 set_inferior_io_terminal (const char *terminal_name)
150 {
151   xfree (current_inferior ()->terminal);
152   current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
153 }
154
155 const char *
156 get_inferior_io_terminal (void)
157 {
158   return current_inferior ()->terminal;
159 }
160
161 static void
162 set_inferior_tty_command (char *args, int from_tty,
163                           struct cmd_list_element *c)
164 {
165   /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
166      Now route it to current inferior.  */
167   set_inferior_io_terminal (inferior_io_terminal_scratch);
168 }
169
170 static void
171 show_inferior_tty_command (struct ui_file *file, int from_tty,
172                            struct cmd_list_element *c, const char *value)
173 {
174   /* Note that we ignore the passed-in value in favor of computing it
175      directly.  */
176   const char *inferior_io_terminal = get_inferior_io_terminal ();
177
178   if (inferior_io_terminal == NULL)
179     inferior_io_terminal = "";
180   fprintf_filtered (gdb_stdout,
181                     _("Terminal for future runs of program being debugged "
182                       "is \"%s\".\n"), inferior_io_terminal);
183 }
184
185 char *
186 get_inferior_args (void)
187 {
188   if (current_inferior ()->argc != 0)
189     {
190       char *n;
191
192       n = construct_inferior_arguments (current_inferior ()->argc,
193                                         current_inferior ()->argv);
194       set_inferior_args (n);
195       xfree (n);
196     }
197
198   if (current_inferior ()->args == NULL)
199     current_inferior ()->args = xstrdup ("");
200
201   return current_inferior ()->args;
202 }
203
204 /* Set the arguments for the current inferior.  Ownership of
205    NEWARGS is not transferred.  */
206
207 void
208 set_inferior_args (char *newargs)
209 {
210   xfree (current_inferior ()->args);
211   current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
212   current_inferior ()->argc = 0;
213   current_inferior ()->argv = 0;
214 }
215
216 void
217 set_inferior_args_vector (int argc, char **argv)
218 {
219   current_inferior ()->argc = argc;
220   current_inferior ()->argv = argv;
221 }
222
223 /* Notice when `set args' is run.  */
224
225 static void
226 set_args_command (char *args, int from_tty, struct cmd_list_element *c)
227 {
228   /* CLI has assigned the user-provided value to inferior_args_scratch.
229      Now route it to current inferior.  */
230   set_inferior_args (inferior_args_scratch);
231 }
232
233 /* Notice when `show args' is run.  */
234
235 static void
236 show_args_command (struct ui_file *file, int from_tty,
237                    struct cmd_list_element *c, const char *value)
238 {
239   /* Note that we ignore the passed-in value in favor of computing it
240      directly.  */
241   deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
242 }
243
244 \f
245 /* Compute command-line string given argument vector.  This does the
246    same shell processing as fork_inferior.  */
247
248 char *
249 construct_inferior_arguments (int argc, char **argv)
250 {
251   char *result;
252
253   if (startup_with_shell)
254     {
255 #ifdef __MINGW32__
256       /* This holds all the characters considered special to the
257          Windows shells.  */
258       char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
259       const char quote = '"';
260 #else
261       /* This holds all the characters considered special to the
262          typical Unix shells.  We include `^' because the SunOS
263          /bin/sh treats it as a synonym for `|'.  */
264       char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
265       const char quote = '\'';
266 #endif
267       int i;
268       int length = 0;
269       char *out, *cp;
270
271       /* We over-compute the size.  It shouldn't matter.  */
272       for (i = 0; i < argc; ++i)
273         length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
274
275       result = (char *) xmalloc (length);
276       out = result;
277
278       for (i = 0; i < argc; ++i)
279         {
280           if (i > 0)
281             *out++ = ' ';
282
283           /* Need to handle empty arguments specially.  */
284           if (argv[i][0] == '\0')
285             {
286               *out++ = quote;
287               *out++ = quote;
288             }
289           else
290             {
291 #ifdef __MINGW32__
292               int quoted = 0;
293
294               if (strpbrk (argv[i], special))
295                 {
296                   quoted = 1;
297                   *out++ = quote;
298                 }
299 #endif
300               for (cp = argv[i]; *cp; ++cp)
301                 {
302                   if (*cp == '\n')
303                     {
304                       /* A newline cannot be quoted with a backslash (it
305                          just disappears), only by putting it inside
306                          quotes.  */
307                       *out++ = quote;
308                       *out++ = '\n';
309                       *out++ = quote;
310                     }
311                   else
312                     {
313 #ifdef __MINGW32__
314                       if (*cp == quote)
315 #else
316                       if (strchr (special, *cp) != NULL)
317 #endif
318                         *out++ = '\\';
319                       *out++ = *cp;
320                     }
321                 }
322 #ifdef __MINGW32__
323               if (quoted)
324                 *out++ = quote;
325 #endif
326             }
327         }
328       *out = '\0';
329     }
330   else
331     {
332       /* In this case we can't handle arguments that contain spaces,
333          tabs, or newlines -- see breakup_args().  */
334       int i;
335       int length = 0;
336
337       for (i = 0; i < argc; ++i)
338         {
339           char *cp = strchr (argv[i], ' ');
340           if (cp == NULL)
341             cp = strchr (argv[i], '\t');
342           if (cp == NULL)
343             cp = strchr (argv[i], '\n');
344           if (cp != NULL)
345             error (_("can't handle command-line "
346                      "argument containing whitespace"));
347           length += strlen (argv[i]) + 1;
348         }
349
350       result = (char *) xmalloc (length);
351       result[0] = '\0';
352       for (i = 0; i < argc; ++i)
353         {
354           if (i > 0)
355             strcat (result, " ");
356           strcat (result, argv[i]);
357         }
358     }
359
360   return result;
361 }
362 \f
363
364 /* This function strips the '&' character (indicating background
365    execution) that is added as *the last* of the arguments ARGS of a
366    command.  A copy of the incoming ARGS without the '&' is returned,
367    unless the resulting string after stripping is empty, in which case
368    NULL is returned.  *BG_CHAR_P is an output boolean that indicates
369    whether the '&' character was found.  */
370
371 static char *
372 strip_bg_char (const char *args, int *bg_char_p)
373 {
374   const char *p;
375
376   if (args == NULL || *args == '\0')
377     {
378       *bg_char_p = 0;
379       return NULL;
380     }
381
382   p = args + strlen (args);
383   if (p[-1] == '&')
384     {
385       p--;
386       while (p > args && isspace (p[-1]))
387         p--;
388
389       *bg_char_p = 1;
390       if (p != args)
391         return savestring (args, p - args);
392       else
393         return NULL;
394     }
395
396   *bg_char_p = 0;
397   return xstrdup (args);
398 }
399
400 /* Common actions to take after creating any sort of inferior, by any
401    means (running, attaching, connecting, et cetera).  The target
402    should be stopped.  */
403
404 void
405 post_create_inferior (struct target_ops *target, int from_tty)
406 {
407
408   /* Be sure we own the terminal in case write operations are performed.  */ 
409   target_terminal_ours ();
410
411   /* If the target hasn't taken care of this already, do it now.
412      Targets which need to access registers during to_open,
413      to_create_inferior, or to_attach should do it earlier; but many
414      don't need to.  */
415   target_find_description ();
416
417   /* Now that we know the register layout, retrieve current PC.  But
418      if the PC is unavailable (e.g., we're opening a core file with
419      missing registers info), ignore it.  */
420   stop_pc = 0;
421   TRY
422     {
423       stop_pc = regcache_read_pc (get_current_regcache ());
424     }
425   CATCH (ex, RETURN_MASK_ERROR)
426     {
427       if (ex.error != NOT_AVAILABLE_ERROR)
428         throw_exception (ex);
429     }
430   END_CATCH
431
432   if (exec_bfd)
433     {
434       const unsigned solib_add_generation
435         = current_program_space->solib_add_generation;
436
437       /* Create the hooks to handle shared library load and unload
438          events.  */
439       solib_create_inferior_hook (from_tty);
440
441       if (current_program_space->solib_add_generation == solib_add_generation)
442         {
443           /* The platform-specific hook should load initial shared libraries,
444              but didn't.  FROM_TTY will be incorrectly 0 but such solib
445              targets should be fixed anyway.  Call it only after the solib
446              target has been initialized by solib_create_inferior_hook.  */
447
448           if (info_verbose)
449             warning (_("platform-specific solib_create_inferior_hook did "
450                        "not load initial shared libraries."));
451
452           /* If the solist is global across processes, there's no need to
453              refetch it here.  */
454           if (!gdbarch_has_global_solist (target_gdbarch ()))
455             solib_add (NULL, 0, target, auto_solib_add);
456         }
457     }
458
459   /* If the user sets watchpoints before execution having started,
460      then she gets software watchpoints, because GDB can't know which
461      target will end up being pushed, or if it supports hardware
462      watchpoints or not.  breakpoint_re_set takes care of promoting
463      watchpoints to hardware watchpoints if possible, however, if this
464      new inferior doesn't load shared libraries or we don't pull in
465      symbols from any other source on this target/arch,
466      breakpoint_re_set is never called.  Call it now so that software
467      watchpoints get a chance to be promoted to hardware watchpoints
468      if the now pushed target supports hardware watchpoints.  */
469   breakpoint_re_set ();
470
471   observer_notify_inferior_created (target, from_tty);
472 }
473
474 /* Kill the inferior if already running.  This function is designed
475    to be called when we are about to start the execution of the program
476    from the beginning.  Ask the user to confirm that he wants to restart
477    the program being debugged when FROM_TTY is non-null.  */
478
479 static void
480 kill_if_already_running (int from_tty)
481 {
482   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
483     {
484       /* Bail out before killing the program if we will not be able to
485          restart it.  */
486       target_require_runnable ();
487
488       if (from_tty
489           && !query (_("The program being debugged has been started already.\n\
490 Start it from the beginning? ")))
491         error (_("Program not restarted."));
492       target_kill ();
493     }
494 }
495
496 /* See inferior.h.  */
497
498 void
499 prepare_execution_command (struct target_ops *target, int background)
500 {
501   /* If we get a request for running in the bg but the target
502      doesn't support it, error out.  */
503   if (background && !target->to_can_async_p (target))
504     error (_("Asynchronous execution not supported on this target."));
505
506   /* If we don't get a request of running in the bg, then we need
507      to simulate synchronous (fg) execution.  */
508   if (!background && target->to_can_async_p (target))
509     {
510       /* Simulate synchronous execution.  Note no cleanup is necessary
511          for this.  stdin is re-enabled whenever an error reaches the
512          top level.  */
513       async_disable_stdin ();
514     }
515 }
516
517 /* Implement the "run" command.  If TBREAK_AT_MAIN is set, then insert
518    a temporary breakpoint at the begining of the main program before
519    running the program.  */
520
521 static void
522 run_command_1 (char *args, int from_tty, int tbreak_at_main)
523 {
524   char *exec_file;
525   struct cleanup *old_chain;
526   ptid_t ptid;
527   struct ui_out *uiout = current_uiout;
528   struct target_ops *run_target;
529   int async_exec;
530   struct cleanup *args_chain;
531
532   dont_repeat ();
533
534   kill_if_already_running (from_tty);
535
536   init_wait_for_inferior ();
537   clear_breakpoint_hit_counts ();
538
539   /* Clean up any leftovers from other runs.  Some other things from
540      this function should probably be moved into target_pre_inferior.  */
541   target_pre_inferior (from_tty);
542
543   /* The comment here used to read, "The exec file is re-read every
544      time we do a generic_mourn_inferior, so we just have to worry
545      about the symbol file."  The `generic_mourn_inferior' function
546      gets called whenever the program exits.  However, suppose the
547      program exits, and *then* the executable file changes?  We need
548      to check again here.  Since reopen_exec_file doesn't do anything
549      if the timestamp hasn't changed, I don't see the harm.  */
550   reopen_exec_file ();
551   reread_symbols ();
552
553   args = strip_bg_char (args, &async_exec);
554   args_chain = make_cleanup (xfree, args);
555
556   /* Do validation and preparation before possibly changing anything
557      in the inferior.  */
558
559   run_target = find_run_target ();
560
561   prepare_execution_command (run_target, async_exec);
562
563   if (non_stop && !run_target->to_supports_non_stop (run_target))
564     error (_("The target does not support running in non-stop mode."));
565
566   /* Done.  Can now set breakpoints, change inferior args, etc.  */
567
568   /* Insert the temporary breakpoint if a location was specified.  */
569   if (tbreak_at_main)
570     tbreak_command (main_name (), 0);
571
572   exec_file = (char *) get_exec_file (0);
573
574   /* We keep symbols from add-symbol-file, on the grounds that the
575      user might want to add some symbols before running the program
576      (right?).  But sometimes (dynamic loading where the user manually
577      introduces the new symbols with add-symbol-file), the code which
578      the symbols describe does not persist between runs.  Currently
579      the user has to manually nuke all symbols between runs if they
580      want them to go away (PR 2207).  This is probably reasonable.  */
581
582   /* If there were other args, beside '&', process them.  */
583   if (args != NULL)
584     set_inferior_args (args);
585
586   if (from_tty)
587     {
588       ui_out_field_string (uiout, NULL, "Starting program");
589       ui_out_text (uiout, ": ");
590       if (exec_file)
591         ui_out_field_string (uiout, "execfile", exec_file);
592       ui_out_spaces (uiout, 1);
593       /* We call get_inferior_args() because we might need to compute
594          the value now.  */
595       ui_out_field_string (uiout, "infargs", get_inferior_args ());
596       ui_out_text (uiout, "\n");
597       ui_out_flush (uiout);
598     }
599
600   /* Done with ARGS.  */
601   do_cleanups (args_chain);
602
603   /* We call get_inferior_args() because we might need to compute
604      the value now.  */
605   run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
606                                   environ_vector (current_inferior ()->environment),
607                                   from_tty);
608   /* to_create_inferior should push the target, so after this point we
609      shouldn't refer to run_target again.  */
610   run_target = NULL;
611
612   /* We're starting off a new process.  When we get out of here, in
613      non-stop mode, finish the state of all threads of that process,
614      but leave other threads alone, as they may be stopped in internal
615      events --- the frontend shouldn't see them as stopped.  In
616      all-stop, always finish the state of all threads, as we may be
617      resuming more than just the new process.  */
618   if (non_stop)
619     ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
620   else
621     ptid = minus_one_ptid;
622   old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
623
624   /* Pass zero for FROM_TTY, because at this point the "run" command
625      has done its thing; now we are setting up the running program.  */
626   post_create_inferior (&current_target, 0);
627
628   /* Start the target running.  Do not use -1 continuation as it would skip
629      breakpoint right at the entry point.  */
630   proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
631
632   /* Since there was no error, there's no need to finish the thread
633      states here.  */
634   discard_cleanups (old_chain);
635 }
636
637 static void
638 run_command (char *args, int from_tty)
639 {
640   run_command_1 (args, from_tty, 0);
641 }
642
643 /* Start the execution of the program up until the beginning of the main
644    program.  */
645
646 static void
647 start_command (char *args, int from_tty)
648 {
649   /* Some languages such as Ada need to search inside the program
650      minimal symbols for the location where to put the temporary
651      breakpoint before starting.  */
652   if (!have_minimal_symbols ())
653     error (_("No symbol table loaded.  Use the \"file\" command."));
654
655   /* Run the program until reaching the main procedure...  */
656   run_command_1 (args, from_tty, 1);
657
658
659 static int
660 proceed_thread_callback (struct thread_info *thread, void *arg)
661 {
662   /* We go through all threads individually instead of compressing
663      into a single target `resume_all' request, because some threads
664      may be stopped in internal breakpoints/events, or stopped waiting
665      for its turn in the displaced stepping queue (that is, they are
666      running && !executing).  The target side has no idea about why
667      the thread is stopped, so a `resume_all' command would resume too
668      much.  If/when GDB gains a way to tell the target `hold this
669      thread stopped until I say otherwise', then we can optimize
670      this.  */
671   if (!is_stopped (thread->ptid))
672     return 0;
673
674   switch_to_thread (thread->ptid);
675   clear_proceed_status (0);
676   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
677   return 0;
678 }
679
680 static void
681 ensure_valid_thread (void)
682 {
683   if (ptid_equal (inferior_ptid, null_ptid)
684       || is_exited (inferior_ptid))
685     error (_("Cannot execute this command without a live selected thread."));
686 }
687
688 /* If the user is looking at trace frames, any resumption of execution
689    is likely to mix up recorded and live target data.  So simply
690    disallow those commands.  */
691
692 static void
693 ensure_not_tfind_mode (void)
694 {
695   if (get_traceframe_number () >= 0)
696     error (_("Cannot execute this command while looking at trace frames."));
697 }
698
699 /* Throw an error indicating the current thread is running.  */
700
701 static void
702 error_is_running (void)
703 {
704   error (_("Cannot execute this command while "
705            "the selected thread is running."));
706 }
707
708 /* Calls error_is_running if the current thread is running.  */
709
710 static void
711 ensure_not_running (void)
712 {
713   if (is_running (inferior_ptid))
714     error_is_running ();
715 }
716
717 void
718 continue_1 (int all_threads)
719 {
720   ERROR_NO_INFERIOR;
721   ensure_not_tfind_mode ();
722
723   if (non_stop && all_threads)
724     {
725       /* Don't error out if the current thread is running, because
726          there may be other stopped threads.  */
727       struct cleanup *old_chain;
728
729       /* Backup current thread and selected frame.  */
730       old_chain = make_cleanup_restore_current_thread ();
731
732       iterate_over_threads (proceed_thread_callback, NULL);
733
734       if (sync_execution)
735         {
736           /* If all threads in the target were already running,
737              proceed_thread_callback ends up never calling proceed,
738              and so nothing calls this to put the inferior's terminal
739              settings in effect and remove stdin from the event loop,
740              which we must when running a foreground command.  E.g.:
741
742               (gdb) c -a&
743               Continuing.
744               <all threads are running now>
745               (gdb) c -a
746               Continuing.
747               <no thread was resumed, but the inferior now owns the terminal>
748           */
749           target_terminal_inferior ();
750         }
751
752       /* Restore selected ptid.  */
753       do_cleanups (old_chain);
754     }
755   else
756     {
757       ensure_valid_thread ();
758       ensure_not_running ();
759       clear_proceed_status (0);
760       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
761     }
762 }
763
764 /* continue [-a] [proceed-count] [&]  */
765
766 static void
767 continue_command (char *args, int from_tty)
768 {
769   int async_exec;
770   int all_threads = 0;
771   struct cleanup *args_chain;
772
773   ERROR_NO_INFERIOR;
774
775   /* Find out whether we must run in the background.  */
776   args = strip_bg_char (args, &async_exec);
777   args_chain = make_cleanup (xfree, args);
778
779   prepare_execution_command (&current_target, async_exec);
780
781   if (args != NULL)
782     {
783       if (startswith (args, "-a"))
784         {
785           all_threads = 1;
786           args += sizeof ("-a") - 1;
787           if (*args == '\0')
788             args = NULL;
789         }
790     }
791
792   if (!non_stop && all_threads)
793     error (_("`-a' is meaningless in all-stop mode."));
794
795   if (args != NULL && all_threads)
796     error (_("Can't resume all threads and specify "
797              "proceed count simultaneously."));
798
799   /* If we have an argument left, set proceed count of breakpoint we
800      stopped at.  */
801   if (args != NULL)
802     {
803       bpstat bs = NULL;
804       int num, stat;
805       int stopped = 0;
806       struct thread_info *tp;
807
808       if (non_stop)
809         tp = find_thread_ptid (inferior_ptid);
810       else
811         {
812           ptid_t last_ptid;
813           struct target_waitstatus ws;
814
815           get_last_target_status (&last_ptid, &ws);
816           tp = find_thread_ptid (last_ptid);
817         }
818       if (tp != NULL)
819         bs = tp->control.stop_bpstat;
820
821       while ((stat = bpstat_num (&bs, &num)) != 0)
822         if (stat > 0)
823           {
824             set_ignore_count (num,
825                               parse_and_eval_long (args) - 1,
826                               from_tty);
827             /* set_ignore_count prints a message ending with a period.
828                So print two spaces before "Continuing.".  */
829             if (from_tty)
830               printf_filtered ("  ");
831             stopped = 1;
832           }
833
834       if (!stopped && from_tty)
835         {
836           printf_filtered
837             ("Not stopped at any breakpoint; argument ignored.\n");
838         }
839     }
840
841   /* Done with ARGS.  */
842   do_cleanups (args_chain);
843
844   if (from_tty)
845     printf_filtered (_("Continuing.\n"));
846
847   continue_1 (all_threads);
848 }
849 \f
850 /* Record the starting point of a "step" or "next" command.  */
851
852 static void
853 set_step_frame (void)
854 {
855   struct symtab_and_line sal;
856   CORE_ADDR pc;
857   struct frame_info *frame = get_current_frame ();
858   struct thread_info *tp = inferior_thread ();
859
860   find_frame_sal (frame, &sal);
861   set_step_info (frame, sal);
862   pc = get_frame_pc (frame);
863   tp->control.step_start_function = find_pc_function (pc);
864 }
865
866 /* Step until outside of current statement.  */
867
868 static void
869 step_command (char *count_string, int from_tty)
870 {
871   step_1 (0, 0, count_string);
872 }
873
874 /* Likewise, but skip over subroutine calls as if single instructions.  */
875
876 static void
877 next_command (char *count_string, int from_tty)
878 {
879   step_1 (1, 0, count_string);
880 }
881
882 /* Likewise, but step only one instruction.  */
883
884 static void
885 stepi_command (char *count_string, int from_tty)
886 {
887   step_1 (0, 1, count_string);
888 }
889
890 static void
891 nexti_command (char *count_string, int from_tty)
892 {
893   step_1 (1, 1, count_string);
894 }
895
896 void
897 delete_longjmp_breakpoint_cleanup (void *arg)
898 {
899   int thread = * (int *) arg;
900   delete_longjmp_breakpoint (thread);
901 }
902
903 static void
904 step_1 (int skip_subroutines, int single_inst, char *count_string)
905 {
906   int count = 1;
907   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
908   int async_exec;
909   int thread = -1;
910   struct cleanup *args_chain;
911
912   ERROR_NO_INFERIOR;
913   ensure_not_tfind_mode ();
914   ensure_valid_thread ();
915   ensure_not_running ();
916
917   count_string = strip_bg_char (count_string, &async_exec);
918   args_chain = make_cleanup (xfree, count_string);
919
920   prepare_execution_command (&current_target, async_exec);
921
922   count = count_string ? parse_and_eval_long (count_string) : 1;
923
924   /* Done with ARGS.  */
925   do_cleanups (args_chain);
926
927   if (!single_inst || skip_subroutines)         /* Leave si command alone.  */
928     {
929       struct thread_info *tp = inferior_thread ();
930
931       if (in_thread_list (inferior_ptid))
932         thread = pid_to_thread_id (inferior_ptid);
933
934       set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));
935
936       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
937     }
938
939   /* In synchronous case, all is well; each step_once call will step once.  */
940   if (!target_can_async_p ())
941     {
942       for (; count > 0; count--)
943         {
944           step_once (skip_subroutines, single_inst, count, thread);
945
946           if (!target_has_execution)
947             break;
948           else
949             {
950               struct thread_info *tp = inferior_thread ();
951
952               if (!tp->control.stop_step || !tp->step_multi)
953                 {
954                   /* If we stopped for some reason that is not stepping
955                      there are no further steps to make.  */
956                   tp->step_multi = 0;
957                   break;
958                 }
959             }
960         }
961
962       do_cleanups (cleanups);
963     }
964   else
965     {
966       /* In the case of an asynchronous target things get complicated;
967          do only one step for now, before returning control to the
968          event loop.  Let the continuation figure out how many other
969          steps we need to do, and handle them one at the time, through
970          step_once.  */
971       step_once (skip_subroutines, single_inst, count, thread);
972
973       /* We are running, and the continuation is installed.  It will
974          disable the longjmp breakpoint as appropriate.  */
975       discard_cleanups (cleanups);
976     }
977 }
978
979 struct step_1_continuation_args
980 {
981   int count;
982   int skip_subroutines;
983   int single_inst;
984   int thread;
985 };
986
987 /* Called after we are done with one step operation, to check whether
988    we need to step again, before we print the prompt and return control
989    to the user.  If count is > 1, we will need to do one more call to
990    proceed(), via step_once().  Basically it is like step_once and
991    step_1_continuation are co-recursive.  */
992
993 static void
994 step_1_continuation (void *args, int err)
995 {
996   struct step_1_continuation_args *a = args;
997
998   if (target_has_execution)
999     {
1000       struct thread_info *tp;
1001
1002       tp = inferior_thread ();
1003       if (!err
1004           && tp->step_multi && tp->control.stop_step)
1005         {
1006           /* There are more steps to make, and we did stop due to
1007              ending a stepping range.  Do another step.  */
1008           step_once (a->skip_subroutines, a->single_inst,
1009                      a->count - 1, a->thread);
1010           return;
1011         }
1012       tp->step_multi = 0;
1013     }
1014
1015   /* We either hit an error, or stopped for some reason that is
1016      not stepping, or there are no further steps to make.
1017      Cleanup.  */
1018   if (!a->single_inst || a->skip_subroutines)
1019     delete_longjmp_breakpoint (a->thread);
1020 }
1021
1022 /* Do just one step operation.  This is useful to implement the 'step
1023    n' kind of commands.  In case of asynchronous targets, we will have
1024    to set up a continuation to be done after the target stops (after
1025    this one step).  For synch targets, the caller handles further
1026    stepping.  */
1027
1028 static void
1029 step_once (int skip_subroutines, int single_inst, int count, int thread)
1030 {
1031   struct frame_info *frame = get_current_frame ();
1032
1033   if (count > 0)
1034     {
1035       /* Don't assume THREAD is a valid thread id.  It is set to -1 if
1036          the longjmp breakpoint was not required.  Use the
1037          INFERIOR_PTID thread instead, which is the same thread when
1038          THREAD is set.  */
1039       struct thread_info *tp = inferior_thread ();
1040
1041       clear_proceed_status (1);
1042       set_step_frame ();
1043
1044       if (!single_inst)
1045         {
1046           CORE_ADDR pc;
1047
1048           /* Step at an inlined function behaves like "down".  */
1049           if (!skip_subroutines
1050               && inline_skipped_frames (inferior_ptid))
1051             {
1052               ptid_t resume_ptid;
1053
1054               /* Pretend that we've ran.  */
1055               resume_ptid = user_visible_resume_ptid (1);
1056               set_running (resume_ptid, 1);
1057
1058               step_into_inline_frame (inferior_ptid);
1059               if (count > 1)
1060                 step_once (skip_subroutines, single_inst, count - 1, thread);
1061               else
1062                 {
1063                   /* Pretend that we've stopped.  */
1064                   normal_stop ();
1065
1066                   if (target_can_async_p ())
1067                     inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1068                 }
1069               return;
1070             }
1071
1072           pc = get_frame_pc (frame);
1073           find_pc_line_pc_range (pc,
1074                                  &tp->control.step_range_start,
1075                                  &tp->control.step_range_end);
1076
1077           tp->control.may_range_step = 1;
1078
1079           /* If we have no line info, switch to stepi mode.  */
1080           if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
1081             {
1082               tp->control.step_range_start = tp->control.step_range_end = 1;
1083               tp->control.may_range_step = 0;
1084             }
1085           else if (tp->control.step_range_end == 0)
1086             {
1087               const char *name;
1088
1089               if (find_pc_partial_function (pc, &name,
1090                                             &tp->control.step_range_start,
1091                                             &tp->control.step_range_end) == 0)
1092                 error (_("Cannot find bounds of current function"));
1093
1094               target_terminal_ours ();
1095               printf_filtered (_("Single stepping until exit from function %s,"
1096                                  "\nwhich has no line number information.\n"),
1097                                name);
1098             }
1099         }
1100       else
1101         {
1102           /* Say we are stepping, but stop after one insn whatever it does.  */
1103           tp->control.step_range_start = tp->control.step_range_end = 1;
1104           if (!skip_subroutines)
1105             /* It is stepi.
1106                Don't step over function calls, not even to functions lacking
1107                line numbers.  */
1108             tp->control.step_over_calls = STEP_OVER_NONE;
1109         }
1110
1111       if (skip_subroutines)
1112         tp->control.step_over_calls = STEP_OVER_ALL;
1113
1114       tp->step_multi = (count > 1);
1115       tp->control.stepping_command = 1;
1116       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1117
1118       /* For async targets, register a continuation to do any
1119          additional steps.  For sync targets, the caller will handle
1120          further stepping.  */
1121       if (target_can_async_p ())
1122         {
1123           struct step_1_continuation_args *args;
1124
1125           args = xmalloc (sizeof (*args));
1126           args->skip_subroutines = skip_subroutines;
1127           args->single_inst = single_inst;
1128           args->count = count;
1129           args->thread = thread;
1130
1131           add_intermediate_continuation (tp, step_1_continuation, args, xfree);
1132         }
1133     }
1134 }
1135
1136 \f
1137 /* Continue program at specified address.  */
1138
1139 static void
1140 jump_command (char *arg, int from_tty)
1141 {
1142   struct gdbarch *gdbarch = get_current_arch ();
1143   CORE_ADDR addr;
1144   struct symtabs_and_lines sals;
1145   struct symtab_and_line sal;
1146   struct symbol *fn;
1147   struct symbol *sfn;
1148   int async_exec;
1149   struct cleanup *args_chain;
1150
1151   ERROR_NO_INFERIOR;
1152   ensure_not_tfind_mode ();
1153   ensure_valid_thread ();
1154   ensure_not_running ();
1155
1156   /* Find out whether we must run in the background.  */
1157   arg = strip_bg_char (arg, &async_exec);
1158   args_chain = make_cleanup (xfree, arg);
1159
1160   prepare_execution_command (&current_target, async_exec);
1161
1162   if (!arg)
1163     error_no_arg (_("starting address"));
1164
1165   sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1166   if (sals.nelts != 1)
1167     {
1168       error (_("Unreasonable jump request"));
1169     }
1170
1171   sal = sals.sals[0];
1172   xfree (sals.sals);
1173
1174   /* Done with ARGS.  */
1175   do_cleanups (args_chain);
1176
1177   if (sal.symtab == 0 && sal.pc == 0)
1178     error (_("No source file has been specified."));
1179
1180   resolve_sal_pc (&sal);        /* May error out.  */
1181
1182   /* See if we are trying to jump to another function.  */
1183   fn = get_frame_function (get_current_frame ());
1184   sfn = find_pc_function (sal.pc);
1185   if (fn != NULL && sfn != fn)
1186     {
1187       if (!query (_("Line %d is not in `%s'.  Jump anyway? "), sal.line,
1188                   SYMBOL_PRINT_NAME (fn)))
1189         {
1190           error (_("Not confirmed."));
1191           /* NOTREACHED */
1192         }
1193     }
1194
1195   if (sfn != NULL)
1196     {
1197       struct obj_section *section;
1198
1199       fixup_symbol_section (sfn, 0);
1200       section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
1201       if (section_is_overlay (section)
1202           && !section_is_mapped (section))
1203         {
1204           if (!query (_("WARNING!!!  Destination is in "
1205                         "unmapped overlay!  Jump anyway? ")))
1206             {
1207               error (_("Not confirmed."));
1208               /* NOTREACHED */
1209             }
1210         }
1211     }
1212
1213   addr = sal.pc;
1214
1215   if (from_tty)
1216     {
1217       printf_filtered (_("Continuing at "));
1218       fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1219       printf_filtered (".\n");
1220     }
1221
1222   clear_proceed_status (0);
1223   proceed (addr, GDB_SIGNAL_0);
1224 }
1225 \f
1226 /* Continue program giving it specified signal.  */
1227
1228 static void
1229 signal_command (char *signum_exp, int from_tty)
1230 {
1231   enum gdb_signal oursig;
1232   int async_exec;
1233   struct cleanup *args_chain;
1234
1235   dont_repeat ();               /* Too dangerous.  */
1236   ERROR_NO_INFERIOR;
1237   ensure_not_tfind_mode ();
1238   ensure_valid_thread ();
1239   ensure_not_running ();
1240
1241   /* Find out whether we must run in the background.  */
1242   signum_exp = strip_bg_char (signum_exp, &async_exec);
1243   args_chain = make_cleanup (xfree, signum_exp);
1244
1245   prepare_execution_command (&current_target, async_exec);
1246
1247   if (!signum_exp)
1248     error_no_arg (_("signal number"));
1249
1250   /* It would be even slicker to make signal names be valid expressions,
1251      (the type could be "enum $signal" or some such), then the user could
1252      assign them to convenience variables.  */
1253   oursig = gdb_signal_from_name (signum_exp);
1254
1255   if (oursig == GDB_SIGNAL_UNKNOWN)
1256     {
1257       /* No, try numeric.  */
1258       int num = parse_and_eval_long (signum_exp);
1259
1260       if (num == 0)
1261         oursig = GDB_SIGNAL_0;
1262       else
1263         oursig = gdb_signal_from_command (num);
1264     }
1265
1266   /* Look for threads other than the current that this command ends up
1267      resuming too (due to schedlock off), and warn if they'll get a
1268      signal delivered.  "signal 0" is used to suppress a previous
1269      signal, but if the current thread is no longer the one that got
1270      the signal, then the user is potentially suppressing the signal
1271      of the wrong thread.  */
1272   if (!non_stop)
1273     {
1274       struct thread_info *tp;
1275       ptid_t resume_ptid;
1276       int must_confirm = 0;
1277
1278       /* This indicates what will be resumed.  Either a single thread,
1279          a whole process, or all threads of all processes.  */
1280       resume_ptid = user_visible_resume_ptid (0);
1281
1282       ALL_NON_EXITED_THREADS (tp)
1283         {
1284           if (ptid_equal (tp->ptid, inferior_ptid))
1285             continue;
1286           if (!ptid_match (tp->ptid, resume_ptid))
1287             continue;
1288
1289           if (tp->suspend.stop_signal != GDB_SIGNAL_0
1290               && signal_pass_state (tp->suspend.stop_signal))
1291             {
1292               if (!must_confirm)
1293                 printf_unfiltered (_("Note:\n"));
1294               printf_unfiltered (_("  Thread %d previously stopped with signal %s, %s.\n"),
1295                                  tp->num,
1296                                  gdb_signal_to_name (tp->suspend.stop_signal),
1297                                  gdb_signal_to_string (tp->suspend.stop_signal));
1298               must_confirm = 1;
1299             }
1300         }
1301
1302       if (must_confirm
1303           && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1304                        "still deliver the signals noted above to their respective threads.\n"
1305                        "Continue anyway? "),
1306                      inferior_thread ()->num))
1307         error (_("Not confirmed."));
1308     }
1309
1310   if (from_tty)
1311     {
1312       if (oursig == GDB_SIGNAL_0)
1313         printf_filtered (_("Continuing with no signal.\n"));
1314       else
1315         printf_filtered (_("Continuing with signal %s.\n"),
1316                          gdb_signal_to_name (oursig));
1317     }
1318
1319   clear_proceed_status (0);
1320   proceed ((CORE_ADDR) -1, oursig);
1321 }
1322
1323 /* Queue a signal to be delivered to the current thread.  */
1324
1325 static void
1326 queue_signal_command (char *signum_exp, int from_tty)
1327 {
1328   enum gdb_signal oursig;
1329   struct thread_info *tp;
1330
1331   ERROR_NO_INFERIOR;
1332   ensure_not_tfind_mode ();
1333   ensure_valid_thread ();
1334   ensure_not_running ();
1335
1336   if (signum_exp == NULL)
1337     error_no_arg (_("signal number"));
1338
1339   /* It would be even slicker to make signal names be valid expressions,
1340      (the type could be "enum $signal" or some such), then the user could
1341      assign them to convenience variables.  */
1342   oursig = gdb_signal_from_name (signum_exp);
1343
1344   if (oursig == GDB_SIGNAL_UNKNOWN)
1345     {
1346       /* No, try numeric.  */
1347       int num = parse_and_eval_long (signum_exp);
1348
1349       if (num == 0)
1350         oursig = GDB_SIGNAL_0;
1351       else
1352         oursig = gdb_signal_from_command (num);
1353     }
1354
1355   if (oursig != GDB_SIGNAL_0
1356       && !signal_pass_state (oursig))
1357     error (_("Signal handling set to not pass this signal to the program."));
1358
1359   tp = inferior_thread ();
1360   tp->suspend.stop_signal = oursig;
1361 }
1362
1363 /* Continuation args to be passed to the "until" command
1364    continuation.  */
1365 struct until_next_continuation_args
1366 {
1367   /* The thread that was current when the command was executed.  */
1368   int thread;
1369 };
1370
1371 /* A continuation callback for until_next_command.  */
1372
1373 static void
1374 until_next_continuation (void *arg, int err)
1375 {
1376   struct until_next_continuation_args *a = arg;
1377
1378   delete_longjmp_breakpoint (a->thread);
1379 }
1380
1381 /* Proceed until we reach a different source line with pc greater than
1382    our current one or exit the function.  We skip calls in both cases.
1383
1384    Note that eventually this command should probably be changed so
1385    that only source lines are printed out when we hit the breakpoint
1386    we set.  This may involve changes to wait_for_inferior and the
1387    proceed status code.  */
1388
1389 static void
1390 until_next_command (int from_tty)
1391 {
1392   struct frame_info *frame;
1393   CORE_ADDR pc;
1394   struct symbol *func;
1395   struct symtab_and_line sal;
1396   struct thread_info *tp = inferior_thread ();
1397   int thread = tp->num;
1398   struct cleanup *old_chain;
1399
1400   clear_proceed_status (0);
1401   set_step_frame ();
1402
1403   frame = get_current_frame ();
1404
1405   /* Step until either exited from this function or greater
1406      than the current line (if in symbolic section) or pc (if
1407      not).  */
1408
1409   pc = get_frame_pc (frame);
1410   func = find_pc_function (pc);
1411
1412   if (!func)
1413     {
1414       struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
1415
1416       if (msymbol.minsym == NULL)
1417         error (_("Execution is not within a known function."));
1418
1419       tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
1420       /* The upper-bound of step_range is exclusive.  In order to make PC
1421          within the range, set the step_range_end with PC + 1.  */
1422       tp->control.step_range_end = pc + 1;
1423     }
1424   else
1425     {
1426       sal = find_pc_line (pc, 0);
1427
1428       tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1429       tp->control.step_range_end = sal.end;
1430     }
1431   tp->control.may_range_step = 1;
1432
1433   tp->control.step_over_calls = STEP_OVER_ALL;
1434
1435   tp->step_multi = 0;           /* Only one call to proceed */
1436
1437   set_longjmp_breakpoint (tp, get_frame_id (frame));
1438   old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1439
1440   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1441
1442   if (target_can_async_p () && is_running (inferior_ptid))
1443     {
1444       struct until_next_continuation_args *cont_args;
1445
1446       discard_cleanups (old_chain);
1447       cont_args = XNEW (struct until_next_continuation_args);
1448       cont_args->thread = inferior_thread ()->num;
1449
1450       add_continuation (tp, until_next_continuation, cont_args, xfree);
1451     }
1452   else
1453     do_cleanups (old_chain);
1454 }
1455
1456 static void
1457 until_command (char *arg, int from_tty)
1458 {
1459   int async_exec;
1460   struct cleanup *args_chain;
1461
1462   ERROR_NO_INFERIOR;
1463   ensure_not_tfind_mode ();
1464   ensure_valid_thread ();
1465   ensure_not_running ();
1466
1467   /* Find out whether we must run in the background.  */
1468   arg = strip_bg_char (arg, &async_exec);
1469   args_chain = make_cleanup (xfree, arg);
1470
1471   prepare_execution_command (&current_target, async_exec);
1472
1473   if (arg)
1474     until_break_command (arg, from_tty, 0);
1475   else
1476     until_next_command (from_tty);
1477
1478   /* Done with ARGS.  */
1479   do_cleanups (args_chain);
1480 }
1481
1482 static void
1483 advance_command (char *arg, int from_tty)
1484 {
1485   int async_exec;
1486   struct cleanup *args_chain;
1487
1488   ERROR_NO_INFERIOR;
1489   ensure_not_tfind_mode ();
1490   ensure_valid_thread ();
1491   ensure_not_running ();
1492
1493   if (arg == NULL)
1494     error_no_arg (_("a location"));
1495
1496   /* Find out whether we must run in the background.  */
1497   arg = strip_bg_char (arg, &async_exec);
1498   args_chain = make_cleanup (xfree, arg);
1499
1500   prepare_execution_command (&current_target, async_exec);
1501
1502   until_break_command (arg, from_tty, 1);
1503
1504   /* Done with ARGS.  */
1505   do_cleanups (args_chain);
1506 }
1507 \f
1508 /* Return the value of the result of a function at the end of a 'finish'
1509    command/BP.  */
1510
1511 struct value *
1512 get_return_value (struct value *function, struct type *value_type)
1513 {
1514   struct regcache *stop_regs = stop_registers;
1515   struct gdbarch *gdbarch;
1516   struct value *value;
1517   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1518
1519   /* If stop_registers were not saved, use the current registers.  */
1520   if (!stop_regs)
1521     {
1522       stop_regs = regcache_dup (get_current_regcache ());
1523       make_cleanup_regcache_xfree (stop_regs);
1524     }
1525
1526   gdbarch = get_regcache_arch (stop_regs);
1527
1528   CHECK_TYPEDEF (value_type);
1529   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1530
1531   /* FIXME: 2003-09-27: When returning from a nested inferior function
1532      call, it's possible (with no help from the architecture vector)
1533      to locate and return/print a "struct return" value.  This is just
1534      a more complicated case of what is already being done in the
1535      inferior function call code.  In fact, when inferior function
1536      calls are made async, this will likely be made the norm.  */
1537
1538   switch (gdbarch_return_value (gdbarch, function, value_type,
1539                                 NULL, NULL, NULL))
1540     {
1541     case RETURN_VALUE_REGISTER_CONVENTION:
1542     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1543     case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1544       value = allocate_value (value_type);
1545       gdbarch_return_value (gdbarch, function, value_type, stop_regs,
1546                             value_contents_raw (value), NULL);
1547       break;
1548     case RETURN_VALUE_STRUCT_CONVENTION:
1549       value = NULL;
1550       break;
1551     default:
1552       internal_error (__FILE__, __LINE__, _("bad switch"));
1553     }
1554
1555   do_cleanups (cleanup);
1556
1557   return value;
1558 }
1559
1560 /* Print the result of a function at the end of a 'finish' command.  */
1561
1562 static void
1563 print_return_value (struct value *function, struct type *value_type)
1564 {
1565   struct value *value = get_return_value (function, value_type);
1566   struct ui_out *uiout = current_uiout;
1567
1568   if (value)
1569     {
1570       struct value_print_options opts;
1571       struct ui_file *stb;
1572       struct cleanup *old_chain;
1573
1574       /* Print it.  */
1575       stb = mem_fileopen ();
1576       old_chain = make_cleanup_ui_file_delete (stb);
1577       ui_out_text (uiout, "Value returned is ");
1578       ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1579                         record_latest_value (value));
1580       ui_out_text (uiout, " = ");
1581       get_no_prettyformat_print_options (&opts);
1582       value_print (value, stb, &opts);
1583       ui_out_field_stream (uiout, "return-value", stb);
1584       ui_out_text (uiout, "\n");
1585       do_cleanups (old_chain);
1586     }
1587   else
1588     {
1589       struct cleanup *oldchain;
1590       char *type_name;
1591
1592       type_name = type_to_string (value_type);
1593       oldchain = make_cleanup (xfree, type_name);
1594       ui_out_text (uiout, "Value returned has type: ");
1595       ui_out_field_string (uiout, "return-type", type_name);
1596       ui_out_text (uiout, ".");
1597       ui_out_text (uiout, " Cannot determine contents\n");
1598       do_cleanups (oldchain);
1599     }
1600 }
1601
1602 /* Stuff that needs to be done by the finish command after the target
1603    has stopped.  In asynchronous mode, we wait for the target to stop
1604    in the call to poll or select in the event loop, so it is
1605    impossible to do all the stuff as part of the finish_command
1606    function itself.  The only chance we have to complete this command
1607    is in fetch_inferior_event, which is called by the event loop as
1608    soon as it detects that the target has stopped.  */
1609
1610 struct finish_command_continuation_args
1611 {
1612   /* The thread that as current when the command was executed.  */
1613   int thread;
1614   struct breakpoint *breakpoint;
1615   struct symbol *function;
1616 };
1617
1618 static void
1619 finish_command_continuation (void *arg, int err)
1620 {
1621   struct finish_command_continuation_args *a = arg;
1622
1623   if (!err)
1624     {
1625       struct thread_info *tp = NULL;
1626       bpstat bs = NULL;
1627
1628       if (!ptid_equal (inferior_ptid, null_ptid)
1629           && target_has_execution
1630           && is_stopped (inferior_ptid))
1631         {
1632           tp = inferior_thread ();
1633           bs = tp->control.stop_bpstat;
1634         }
1635
1636       if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1637           && a->function != NULL)
1638         {
1639           struct type *value_type;
1640
1641           value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1642           if (!value_type)
1643             internal_error (__FILE__, __LINE__,
1644                             _("finish_command: function has no target type"));
1645
1646           if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1647             {
1648               struct value *func;
1649
1650               func = read_var_value (a->function, get_current_frame ());
1651               TRY
1652                 {
1653                   /* print_return_value can throw an exception in some
1654                      circumstances.  We need to catch this so that we still
1655                      delete the breakpoint.  */
1656                   print_return_value (func, value_type);
1657                 }
1658               CATCH (ex, RETURN_MASK_ALL)
1659                 {
1660                   exception_print (gdb_stdout, ex);
1661                 }
1662               END_CATCH
1663             }
1664         }
1665
1666       /* We suppress normal call of normal_stop observer and do it
1667          here so that the *stopped notification includes the return
1668          value.  */
1669       if (bs != NULL && tp->control.proceed_to_finish)
1670         observer_notify_normal_stop (bs, 1 /* print frame */);
1671     }
1672
1673   delete_breakpoint (a->breakpoint);
1674   delete_longjmp_breakpoint (a->thread);
1675 }
1676
1677 static void
1678 finish_command_continuation_free_arg (void *arg)
1679 {
1680   xfree (arg);
1681 }
1682
1683 /* finish_backward -- helper function for finish_command.  */
1684
1685 static void
1686 finish_backward (struct symbol *function)
1687 {
1688   struct symtab_and_line sal;
1689   struct thread_info *tp = inferior_thread ();
1690   CORE_ADDR pc;
1691   CORE_ADDR func_addr;
1692
1693   pc = get_frame_pc (get_current_frame ());
1694
1695   if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1696     error (_("Cannot find bounds of current function"));
1697
1698   sal = find_pc_line (func_addr, 0);
1699
1700   tp->control.proceed_to_finish = 1;
1701   /* Special case: if we're sitting at the function entry point,
1702      then all we need to do is take a reverse singlestep.  We
1703      don't need to set a breakpoint, and indeed it would do us
1704      no good to do so.
1705
1706      Note that this can only happen at frame #0, since there's
1707      no way that a function up the stack can have a return address
1708      that's equal to its entry point.  */
1709
1710   if (sal.pc != pc)
1711     {
1712       struct frame_info *frame = get_selected_frame (NULL);
1713       struct gdbarch *gdbarch = get_frame_arch (frame);
1714       struct symtab_and_line sr_sal;
1715
1716       /* Set a step-resume at the function's entry point.  Once that's
1717          hit, we'll do one more step backwards.  */
1718       init_sal (&sr_sal);
1719       sr_sal.pc = sal.pc;
1720       sr_sal.pspace = get_frame_program_space (frame);
1721       insert_step_resume_breakpoint_at_sal (gdbarch,
1722                                             sr_sal, null_frame_id);
1723
1724       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1725     }
1726   else
1727     {
1728       /* We're almost there -- we just need to back up by one more
1729          single-step.  */
1730       tp->control.step_range_start = tp->control.step_range_end = 1;
1731       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1732     }
1733 }
1734
1735 /* finish_forward -- helper function for finish_command.  */
1736
1737 static void
1738 finish_forward (struct symbol *function, struct frame_info *frame)
1739 {
1740   struct frame_id frame_id = get_frame_id (frame);
1741   struct gdbarch *gdbarch = get_frame_arch (frame);
1742   struct symtab_and_line sal;
1743   struct thread_info *tp = inferior_thread ();
1744   struct breakpoint *breakpoint;
1745   struct cleanup *old_chain;
1746   struct finish_command_continuation_args *cargs;
1747   int thread = tp->num;
1748
1749   sal = find_pc_line (get_frame_pc (frame), 0);
1750   sal.pc = get_frame_pc (frame);
1751
1752   breakpoint = set_momentary_breakpoint (gdbarch, sal,
1753                                          get_stack_frame_id (frame),
1754                                          bp_finish);
1755
1756   /* set_momentary_breakpoint invalidates FRAME.  */
1757   frame = NULL;
1758
1759   old_chain = make_cleanup_delete_breakpoint (breakpoint);
1760
1761   set_longjmp_breakpoint (tp, frame_id);
1762   make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1763
1764   /* We want stop_registers, please...  */
1765   tp->control.proceed_to_finish = 1;
1766   cargs = xmalloc (sizeof (*cargs));
1767
1768   cargs->thread = thread;
1769   cargs->breakpoint = breakpoint;
1770   cargs->function = function;
1771   add_continuation (tp, finish_command_continuation, cargs,
1772                     finish_command_continuation_free_arg);
1773   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1774
1775   discard_cleanups (old_chain);
1776   if (!target_can_async_p ())
1777     do_all_continuations (0);
1778 }
1779
1780 /* "finish": Set a temporary breakpoint at the place the selected
1781    frame will return to, then continue.  */
1782
1783 static void
1784 finish_command (char *arg, int from_tty)
1785 {
1786   struct frame_info *frame;
1787   struct symbol *function;
1788   int async_exec;
1789   struct cleanup *args_chain;
1790
1791   ERROR_NO_INFERIOR;
1792   ensure_not_tfind_mode ();
1793   ensure_valid_thread ();
1794   ensure_not_running ();
1795
1796   /* Find out whether we must run in the background.  */
1797   arg = strip_bg_char (arg, &async_exec);
1798   args_chain = make_cleanup (xfree, arg);
1799
1800   prepare_execution_command (&current_target, async_exec);
1801
1802   if (arg)
1803     error (_("The \"finish\" command does not take any arguments."));
1804
1805   /* Done with ARGS.  */
1806   do_cleanups (args_chain);
1807
1808   frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1809   if (frame == 0)
1810     error (_("\"finish\" not meaningful in the outermost frame."));
1811
1812   clear_proceed_status (0);
1813
1814   /* Finishing from an inline frame is completely different.  We don't
1815      try to show the "return value" - no way to locate it.  So we do
1816      not need a completion.  */
1817   if (get_frame_type (get_selected_frame (_("No selected frame.")))
1818       == INLINE_FRAME)
1819     {
1820       /* Claim we are stepping in the calling frame.  An empty step
1821          range means that we will stop once we aren't in a function
1822          called by that frame.  We don't use the magic "1" value for
1823          step_range_end, because then infrun will think this is nexti,
1824          and not step over the rest of this inlined function call.  */
1825       struct thread_info *tp = inferior_thread ();
1826       struct symtab_and_line empty_sal;
1827
1828       init_sal (&empty_sal);
1829       set_step_info (frame, empty_sal);
1830       tp->control.step_range_start = get_frame_pc (frame);
1831       tp->control.step_range_end = tp->control.step_range_start;
1832       tp->control.step_over_calls = STEP_OVER_ALL;
1833
1834       /* Print info on the selected frame, including level number but not
1835          source.  */
1836       if (from_tty)
1837         {
1838           printf_filtered (_("Run till exit from "));
1839           print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1840         }
1841
1842       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1843       return;
1844     }
1845
1846   /* Ignore TAILCALL_FRAME type frames, they were executed already before
1847      entering THISFRAME.  */
1848   while (get_frame_type (frame) == TAILCALL_FRAME)
1849     frame = get_prev_frame (frame);
1850
1851   /* Find the function we will return from.  */
1852
1853   function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1854
1855   /* Print info on the selected frame, including level number but not
1856      source.  */
1857   if (from_tty)
1858     {
1859       if (execution_direction == EXEC_REVERSE)
1860         printf_filtered (_("Run back to call of "));
1861       else
1862         {
1863           if (function != NULL && TYPE_NO_RETURN (function->type)
1864               && !query (_("warning: Function %s does not return normally.\n"
1865                            "Try to finish anyway? "),
1866                          SYMBOL_PRINT_NAME (function)))
1867             error (_("Not confirmed."));
1868           printf_filtered (_("Run till exit from "));
1869         }
1870
1871       print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1872     }
1873
1874   if (execution_direction == EXEC_REVERSE)
1875     finish_backward (function);
1876   else
1877     finish_forward (function, frame);
1878 }
1879 \f
1880
1881 static void
1882 program_info (char *args, int from_tty)
1883 {
1884   bpstat bs;
1885   int num, stat;
1886   struct thread_info *tp;
1887   ptid_t ptid;
1888
1889   if (!target_has_execution)
1890     {
1891       printf_filtered (_("The program being debugged is not being run.\n"));
1892       return;
1893     }
1894
1895   if (non_stop)
1896     ptid = inferior_ptid;
1897   else
1898     {
1899       struct target_waitstatus ws;
1900
1901       get_last_target_status (&ptid, &ws);
1902     }
1903
1904   if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1905     error (_("Invalid selected thread."));
1906   else if (is_running (ptid))
1907     error (_("Selected thread is running."));
1908
1909   tp = find_thread_ptid (ptid);
1910   bs = tp->control.stop_bpstat;
1911   stat = bpstat_num (&bs, &num);
1912
1913   target_files_info ();
1914   printf_filtered (_("Program stopped at %s.\n"),
1915                    paddress (target_gdbarch (), stop_pc));
1916   if (tp->control.stop_step)
1917     printf_filtered (_("It stopped after being stepped.\n"));
1918   else if (stat != 0)
1919     {
1920       /* There may be several breakpoints in the same place, so this
1921          isn't as strange as it seems.  */
1922       while (stat != 0)
1923         {
1924           if (stat < 0)
1925             {
1926               printf_filtered (_("It stopped at a breakpoint "
1927                                  "that has since been deleted.\n"));
1928             }
1929           else
1930             printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1931           stat = bpstat_num (&bs, &num);
1932         }
1933     }
1934   else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
1935     {
1936       printf_filtered (_("It stopped with signal %s, %s.\n"),
1937                        gdb_signal_to_name (tp->suspend.stop_signal),
1938                        gdb_signal_to_string (tp->suspend.stop_signal));
1939     }
1940
1941   if (from_tty)
1942     {
1943       printf_filtered (_("Type \"info stack\" or \"info "
1944                          "registers\" for more information.\n"));
1945     }
1946 }
1947 \f
1948 static void
1949 environment_info (char *var, int from_tty)
1950 {
1951   if (var)
1952     {
1953       char *val = get_in_environ (current_inferior ()->environment, var);
1954
1955       if (val)
1956         {
1957           puts_filtered (var);
1958           puts_filtered (" = ");
1959           puts_filtered (val);
1960           puts_filtered ("\n");
1961         }
1962       else
1963         {
1964           puts_filtered ("Environment variable \"");
1965           puts_filtered (var);
1966           puts_filtered ("\" not defined.\n");
1967         }
1968     }
1969   else
1970     {
1971       char **vector = environ_vector (current_inferior ()->environment);
1972
1973       while (*vector)
1974         {
1975           puts_filtered (*vector++);
1976           puts_filtered ("\n");
1977         }
1978     }
1979 }
1980
1981 static void
1982 set_environment_command (char *arg, int from_tty)
1983 {
1984   char *p, *val, *var;
1985   int nullset = 0;
1986
1987   if (arg == 0)
1988     error_no_arg (_("environment variable and value"));
1989
1990   /* Find seperation between variable name and value.  */
1991   p = (char *) strchr (arg, '=');
1992   val = (char *) strchr (arg, ' ');
1993
1994   if (p != 0 && val != 0)
1995     {
1996       /* We have both a space and an equals.  If the space is before the
1997          equals, walk forward over the spaces til we see a nonspace 
1998          (possibly the equals).  */
1999       if (p > val)
2000         while (*val == ' ')
2001           val++;
2002
2003       /* Now if the = is after the char following the spaces,
2004          take the char following the spaces.  */
2005       if (p > val)
2006         p = val - 1;
2007     }
2008   else if (val != 0 && p == 0)
2009     p = val;
2010
2011   if (p == arg)
2012     error_no_arg (_("environment variable to set"));
2013
2014   if (p == 0 || p[1] == 0)
2015     {
2016       nullset = 1;
2017       if (p == 0)
2018         p = arg + strlen (arg); /* So that savestring below will work.  */
2019     }
2020   else
2021     {
2022       /* Not setting variable value to null.  */
2023       val = p + 1;
2024       while (*val == ' ' || *val == '\t')
2025         val++;
2026     }
2027
2028   while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2029     p--;
2030
2031   var = savestring (arg, p - arg);
2032   if (nullset)
2033     {
2034       printf_filtered (_("Setting environment variable "
2035                          "\"%s\" to null value.\n"),
2036                        var);
2037       set_in_environ (current_inferior ()->environment, var, "");
2038     }
2039   else
2040     set_in_environ (current_inferior ()->environment, var, val);
2041   xfree (var);
2042 }
2043
2044 static void
2045 unset_environment_command (char *var, int from_tty)
2046 {
2047   if (var == 0)
2048     {
2049       /* If there is no argument, delete all environment variables.
2050          Ask for confirmation if reading from the terminal.  */
2051       if (!from_tty || query (_("Delete all environment variables? ")))
2052         {
2053           free_environ (current_inferior ()->environment);
2054           current_inferior ()->environment = make_environ ();
2055         }
2056     }
2057   else
2058     unset_in_environ (current_inferior ()->environment, var);
2059 }
2060
2061 /* Handle the execution path (PATH variable).  */
2062
2063 static const char path_var_name[] = "PATH";
2064
2065 static void
2066 path_info (char *args, int from_tty)
2067 {
2068   puts_filtered ("Executable and object file path: ");
2069   puts_filtered (get_in_environ (current_inferior ()->environment,
2070                                  path_var_name));
2071   puts_filtered ("\n");
2072 }
2073
2074 /* Add zero or more directories to the front of the execution path.  */
2075
2076 static void
2077 path_command (char *dirname, int from_tty)
2078 {
2079   char *exec_path;
2080   char *env;
2081
2082   dont_repeat ();
2083   env = get_in_environ (current_inferior ()->environment, path_var_name);
2084   /* Can be null if path is not set.  */
2085   if (!env)
2086     env = "";
2087   exec_path = xstrdup (env);
2088   mod_path (dirname, &exec_path);
2089   set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
2090   xfree (exec_path);
2091   if (from_tty)
2092     path_info ((char *) NULL, from_tty);
2093 }
2094 \f
2095
2096 /* Print out the register NAME with value VAL, to FILE, in the default
2097    fashion.  */
2098
2099 static void
2100 default_print_one_register_info (struct ui_file *file,
2101                                  const char *name,
2102                                  struct value *val)
2103 {
2104   struct type *regtype = value_type (val);
2105   int print_raw_format;
2106
2107   fputs_filtered (name, file);
2108   print_spaces_filtered (15 - strlen (name), file);
2109
2110   print_raw_format = (value_entirely_available (val)
2111                       && !value_optimized_out (val));
2112
2113   /* If virtual format is floating, print it that way, and in raw
2114      hex.  */
2115   if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2116       || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2117     {
2118       int j;
2119       struct value_print_options opts;
2120       const gdb_byte *valaddr = value_contents_for_printing (val);
2121       enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2122
2123       get_user_print_options (&opts);
2124       opts.deref_ref = 1;
2125
2126       val_print (regtype,
2127                  value_contents_for_printing (val),
2128                  value_embedded_offset (val), 0,
2129                  file, 0, val, &opts, current_language);
2130
2131       if (print_raw_format)
2132         {
2133           fprintf_filtered (file, "\t(raw ");
2134           print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
2135           fprintf_filtered (file, ")");
2136         }
2137     }
2138   else
2139     {
2140       struct value_print_options opts;
2141
2142       /* Print the register in hex.  */
2143       get_formatted_print_options (&opts, 'x');
2144       opts.deref_ref = 1;
2145       val_print (regtype,
2146                  value_contents_for_printing (val),
2147                  value_embedded_offset (val), 0,
2148                  file, 0, val, &opts, current_language);
2149       /* If not a vector register, print it also according to its
2150          natural format.  */
2151       if (print_raw_format && TYPE_VECTOR (regtype) == 0)
2152         {
2153           get_user_print_options (&opts);
2154           opts.deref_ref = 1;
2155           fprintf_filtered (file, "\t");
2156           val_print (regtype,
2157                      value_contents_for_printing (val),
2158                      value_embedded_offset (val), 0,
2159                      file, 0, val, &opts, current_language);
2160         }
2161     }
2162
2163   fprintf_filtered (file, "\n");
2164 }
2165
2166 /* Print out the machine register regnum.  If regnum is -1, print all
2167    registers (print_all == 1) or all non-float and non-vector
2168    registers (print_all == 0).
2169
2170    For most machines, having all_registers_info() print the
2171    register(s) one per line is good enough.  If a different format is
2172    required, (eg, for MIPS or Pyramid 90x, which both have lots of
2173    regs), or there is an existing convention for showing all the
2174    registers, define the architecture method PRINT_REGISTERS_INFO to
2175    provide that format.  */
2176
2177 void
2178 default_print_registers_info (struct gdbarch *gdbarch,
2179                               struct ui_file *file,
2180                               struct frame_info *frame,
2181                               int regnum, int print_all)
2182 {
2183   int i;
2184   const int numregs = gdbarch_num_regs (gdbarch)
2185                       + gdbarch_num_pseudo_regs (gdbarch);
2186
2187   for (i = 0; i < numregs; i++)
2188     {
2189       /* Decide between printing all regs, non-float / vector regs, or
2190          specific reg.  */
2191       if (regnum == -1)
2192         {
2193           if (print_all)
2194             {
2195               if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
2196                 continue;
2197             }
2198           else
2199             {
2200               if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
2201                 continue;
2202             }
2203         }
2204       else
2205         {
2206           if (i != regnum)
2207             continue;
2208         }
2209
2210       /* If the register name is empty, it is undefined for this
2211          processor, so don't display anything.  */
2212       if (gdbarch_register_name (gdbarch, i) == NULL
2213           || *(gdbarch_register_name (gdbarch, i)) == '\0')
2214         continue;
2215
2216       default_print_one_register_info (file,
2217                                        gdbarch_register_name (gdbarch, i),
2218                                        value_of_register (i, frame));
2219     }
2220 }
2221
2222 void
2223 registers_info (char *addr_exp, int fpregs)
2224 {
2225   struct frame_info *frame;
2226   struct gdbarch *gdbarch;
2227
2228   if (!target_has_registers)
2229     error (_("The program has no registers now."));
2230   frame = get_selected_frame (NULL);
2231   gdbarch = get_frame_arch (frame);
2232
2233   if (!addr_exp)
2234     {
2235       gdbarch_print_registers_info (gdbarch, gdb_stdout,
2236                                     frame, -1, fpregs);
2237       return;
2238     }
2239
2240   while (*addr_exp != '\0')
2241     {
2242       char *start;
2243       const char *end;
2244
2245       /* Skip leading white space.  */
2246       addr_exp = skip_spaces (addr_exp);
2247
2248       /* Discard any leading ``$''.  Check that there is something
2249          resembling a register following it.  */
2250       if (addr_exp[0] == '$')
2251         addr_exp++;
2252       if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2253         error (_("Missing register name"));
2254
2255       /* Find the start/end of this register name/num/group.  */
2256       start = addr_exp;
2257       while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2258         addr_exp++;
2259       end = addr_exp;
2260
2261       /* Figure out what we've found and display it.  */
2262
2263       /* A register name?  */
2264       {
2265         int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2266
2267         if (regnum >= 0)
2268           {
2269             /* User registers lie completely outside of the range of
2270                normal registers.  Catch them early so that the target
2271                never sees them.  */
2272             if (regnum >= gdbarch_num_regs (gdbarch)
2273                           + gdbarch_num_pseudo_regs (gdbarch))
2274               {
2275                 struct value *regval = value_of_user_reg (regnum, frame);
2276                 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2277                                                                    regnum);
2278
2279                 /* Print in the same fashion
2280                    gdbarch_print_registers_info's default
2281                    implementation prints.  */
2282                 default_print_one_register_info (gdb_stdout,
2283                                                  regname,
2284                                                  regval);
2285               }
2286             else
2287               gdbarch_print_registers_info (gdbarch, gdb_stdout,
2288                                             frame, regnum, fpregs);
2289             continue;
2290           }
2291       }
2292
2293       /* A register group?  */
2294       {
2295         struct reggroup *group;
2296
2297         for (group = reggroup_next (gdbarch, NULL);
2298              group != NULL;
2299              group = reggroup_next (gdbarch, group))
2300           {
2301             /* Don't bother with a length check.  Should the user
2302                enter a short register group name, go with the first
2303                group that matches.  */
2304             if (strncmp (start, reggroup_name (group), end - start) == 0)
2305               break;
2306           }
2307         if (group != NULL)
2308           {
2309             int regnum;
2310
2311             for (regnum = 0;
2312                  regnum < gdbarch_num_regs (gdbarch)
2313                           + gdbarch_num_pseudo_regs (gdbarch);
2314                  regnum++)
2315               {
2316                 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2317                   gdbarch_print_registers_info (gdbarch,
2318                                                 gdb_stdout, frame,
2319                                                 regnum, fpregs);
2320               }
2321             continue;
2322           }
2323       }
2324
2325       /* Nothing matched.  */
2326       error (_("Invalid register `%.*s'"), (int) (end - start), start);
2327     }
2328 }
2329
2330 static void
2331 all_registers_info (char *addr_exp, int from_tty)
2332 {
2333   registers_info (addr_exp, 1);
2334 }
2335
2336 static void
2337 nofp_registers_info (char *addr_exp, int from_tty)
2338 {
2339   registers_info (addr_exp, 0);
2340 }
2341
2342 static void
2343 print_vector_info (struct ui_file *file,
2344                    struct frame_info *frame, const char *args)
2345 {
2346   struct gdbarch *gdbarch = get_frame_arch (frame);
2347
2348   if (gdbarch_print_vector_info_p (gdbarch))
2349     gdbarch_print_vector_info (gdbarch, file, frame, args);
2350   else
2351     {
2352       int regnum;
2353       int printed_something = 0;
2354
2355       for (regnum = 0;
2356            regnum < gdbarch_num_regs (gdbarch)
2357                     + gdbarch_num_pseudo_regs (gdbarch);
2358            regnum++)
2359         {
2360           if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2361             {
2362               printed_something = 1;
2363               gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2364             }
2365         }
2366       if (!printed_something)
2367         fprintf_filtered (file, "No vector information\n");
2368     }
2369 }
2370
2371 static void
2372 vector_info (char *args, int from_tty)
2373 {
2374   if (!target_has_registers)
2375     error (_("The program has no registers now."));
2376
2377   print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2378 }
2379 \f
2380 /* Kill the inferior process.  Make us have no inferior.  */
2381
2382 static void
2383 kill_command (char *arg, int from_tty)
2384 {
2385   /* FIXME:  This should not really be inferior_ptid (or target_has_execution).
2386      It should be a distinct flag that indicates that a target is active, cuz
2387      some targets don't have processes!  */
2388
2389   if (ptid_equal (inferior_ptid, null_ptid))
2390     error (_("The program is not being run."));
2391   if (!query (_("Kill the program being debugged? ")))
2392     error (_("Not confirmed."));
2393   target_kill ();
2394
2395   /* If we still have other inferiors to debug, then don't mess with
2396      with their threads.  */
2397   if (!have_inferiors ())
2398     {
2399       init_thread_list ();              /* Destroy thread info.  */
2400
2401       /* Killing off the inferior can leave us with a core file.  If
2402          so, print the state we are left in.  */
2403       if (target_has_stack)
2404         {
2405           printf_filtered (_("In %s,\n"), target_longname);
2406           print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2407         }
2408     }
2409   bfd_cache_close_all ();
2410 }
2411
2412 /* Used in `attach&' command.  ARG is a point to an integer
2413    representing a process id.  Proceed threads of this process iff
2414    they stopped due to debugger request, and when they did, they
2415    reported a clean stop (GDB_SIGNAL_0).  Do not proceed threads
2416    that have been explicitly been told to stop.  */
2417
2418 static int
2419 proceed_after_attach_callback (struct thread_info *thread,
2420                                void *arg)
2421 {
2422   int pid = * (int *) arg;
2423
2424   if (ptid_get_pid (thread->ptid) == pid
2425       && !is_exited (thread->ptid)
2426       && !is_executing (thread->ptid)
2427       && !thread->stop_requested
2428       && thread->suspend.stop_signal == GDB_SIGNAL_0)
2429     {
2430       switch_to_thread (thread->ptid);
2431       clear_proceed_status (0);
2432       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2433     }
2434
2435   return 0;
2436 }
2437
2438 static void
2439 proceed_after_attach (int pid)
2440 {
2441   /* Don't error out if the current thread is running, because
2442      there may be other stopped threads.  */
2443   struct cleanup *old_chain;
2444
2445   /* Backup current thread and selected frame.  */
2446   old_chain = make_cleanup_restore_current_thread ();
2447
2448   iterate_over_threads (proceed_after_attach_callback, &pid);
2449
2450   /* Restore selected ptid.  */
2451   do_cleanups (old_chain);
2452 }
2453
2454 /* attach_command --
2455    takes a program started up outside of gdb and ``attaches'' to it.
2456    This stops it cold in its tracks and allows us to start debugging it.
2457    and wait for the trace-trap that results from attaching.  */
2458
2459 static void
2460 attach_command_post_wait (char *args, int from_tty, int async_exec)
2461 {
2462   struct inferior *inferior;
2463
2464   inferior = current_inferior ();
2465   inferior->control.stop_soon = NO_STOP_QUIETLY;
2466
2467   /* If no exec file is yet known, try to determine it from the
2468      process itself.  */
2469   if (get_exec_file (0) == NULL)
2470     exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
2471   else
2472     {
2473       reopen_exec_file ();
2474       reread_symbols ();
2475     }
2476
2477   /* Take any necessary post-attaching actions for this platform.  */
2478   target_post_attach (ptid_get_pid (inferior_ptid));
2479
2480   post_create_inferior (&current_target, from_tty);
2481
2482   if (async_exec)
2483     {
2484       /* The user requested an `attach&', so be sure to leave threads
2485          that didn't get a signal running.  */
2486
2487       /* Immediatelly resume all suspended threads of this inferior,
2488          and this inferior only.  This should have no effect on
2489          already running threads.  If a thread has been stopped with a
2490          signal, leave it be.  */
2491       if (non_stop)
2492         proceed_after_attach (inferior->pid);
2493       else
2494         {
2495           if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
2496             {
2497               clear_proceed_status (0);
2498               proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2499             }
2500         }
2501     }
2502   else
2503     {
2504       /* The user requested a plain `attach', so be sure to leave
2505          the inferior stopped.  */
2506
2507       if (target_can_async_p ())
2508         async_enable_stdin ();
2509
2510       /* At least the current thread is already stopped.  */
2511
2512       /* In all-stop, by definition, all threads have to be already
2513          stopped at this point.  In non-stop, however, although the
2514          selected thread is stopped, others may still be executing.
2515          Be sure to explicitly stop all threads of the process.  This
2516          should have no effect on already stopped threads.  */
2517       if (non_stop)
2518         target_stop (pid_to_ptid (inferior->pid));
2519
2520       /* Tell the user/frontend where we're stopped.  */
2521       normal_stop ();
2522       if (deprecated_attach_hook)
2523         deprecated_attach_hook ();
2524     }
2525 }
2526
2527 struct attach_command_continuation_args
2528 {
2529   char *args;
2530   int from_tty;
2531   int async_exec;
2532 };
2533
2534 static void
2535 attach_command_continuation (void *args, int err)
2536 {
2537   struct attach_command_continuation_args *a = args;
2538
2539   if (err)
2540     return;
2541
2542   attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2543 }
2544
2545 static void
2546 attach_command_continuation_free_args (void *args)
2547 {
2548   struct attach_command_continuation_args *a = args;
2549
2550   xfree (a->args);
2551   xfree (a);
2552 }
2553
2554 void
2555 attach_command (char *args, int from_tty)
2556 {
2557   int async_exec;
2558   struct cleanup *args_chain;
2559   struct target_ops *attach_target;
2560
2561   dont_repeat ();               /* Not for the faint of heart */
2562
2563   if (gdbarch_has_global_solist (target_gdbarch ()))
2564     /* Don't complain if all processes share the same symbol
2565        space.  */
2566     ;
2567   else if (target_has_execution)
2568     {
2569       if (query (_("A program is being debugged already.  Kill it? ")))
2570         target_kill ();
2571       else
2572         error (_("Not killed."));
2573     }
2574
2575   /* Clean up any leftovers from other runs.  Some other things from
2576      this function should probably be moved into target_pre_inferior.  */
2577   target_pre_inferior (from_tty);
2578
2579   args = strip_bg_char (args, &async_exec);
2580   args_chain = make_cleanup (xfree, args);
2581
2582   attach_target = find_attach_target ();
2583
2584   prepare_execution_command (attach_target, async_exec);
2585
2586   if (non_stop && !attach_target->to_supports_non_stop (attach_target))
2587     error (_("Cannot attach to this target in non-stop mode"));
2588
2589   attach_target->to_attach (attach_target, args, from_tty);
2590   /* to_attach should push the target, so after this point we
2591      shouldn't refer to attach_target again.  */
2592   attach_target = NULL;
2593
2594   /* Done with ARGS.  */
2595   do_cleanups (args_chain);
2596
2597   /* Set up the "saved terminal modes" of the inferior
2598      based on what modes we are starting it with.  */
2599   target_terminal_init ();
2600
2601   /* Install inferior's terminal modes.  This may look like a no-op,
2602      as we've just saved them above, however, this does more than
2603      restore terminal settings:
2604
2605      - installs a SIGINT handler that forwards SIGINT to the inferior.
2606        Otherwise a Ctrl-C pressed just while waiting for the initial
2607        stop would end up as a spurious Quit.
2608
2609      - removes stdin from the event loop, which we need if attaching
2610        in the foreground, otherwise on targets that report an initial
2611        stop on attach (which are most) we'd process input/commands
2612        while we're in the event loop waiting for that stop.  That is,
2613        before the attach continuation runs and the command is really
2614        finished.  */
2615   target_terminal_inferior ();
2616
2617   /* Set up execution context to know that we should return from
2618      wait_for_inferior as soon as the target reports a stop.  */
2619   init_wait_for_inferior ();
2620   clear_proceed_status (0);
2621
2622   if (non_stop)
2623     {
2624       /* If we find that the current thread isn't stopped, explicitly
2625          do so now, because we're going to install breakpoints and
2626          poke at memory.  */
2627
2628       if (async_exec)
2629         /* The user requested an `attach&'; stop just one thread.  */
2630         target_stop (inferior_ptid);
2631       else
2632         /* The user requested an `attach', so stop all threads of this
2633            inferior.  */
2634         target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2635     }
2636
2637   /* Some system don't generate traps when attaching to inferior.
2638      E.g. Mach 3 or GNU hurd.  */
2639   if (!target_attach_no_wait)
2640     {
2641       struct inferior *inferior = current_inferior ();
2642
2643       /* Careful here.  See comments in inferior.h.  Basically some
2644          OSes don't ignore SIGSTOPs on continue requests anymore.  We
2645          need a way for handle_inferior_event to reset the stop_signal
2646          variable after an attach, and this is what
2647          STOP_QUIETLY_NO_SIGSTOP is for.  */
2648       inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2649
2650       if (target_can_async_p ())
2651         {
2652           /* sync_execution mode.  Wait for stop.  */
2653           struct attach_command_continuation_args *a;
2654
2655           a = xmalloc (sizeof (*a));
2656           a->args = xstrdup (args);
2657           a->from_tty = from_tty;
2658           a->async_exec = async_exec;
2659           add_inferior_continuation (attach_command_continuation, a,
2660                                      attach_command_continuation_free_args);
2661           return;
2662         }
2663
2664       wait_for_inferior ();
2665     }
2666
2667   attach_command_post_wait (args, from_tty, async_exec);
2668 }
2669
2670 /* We had just found out that the target was already attached to an
2671    inferior.  PTID points at a thread of this new inferior, that is
2672    the most likely to be stopped right now, but not necessarily so.
2673    The new inferior is assumed to be already added to the inferior
2674    list at this point.  If LEAVE_RUNNING, then leave the threads of
2675    this inferior running, except those we've explicitly seen reported
2676    as stopped.  */
2677
2678 void
2679 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2680 {
2681   struct cleanup* old_chain;
2682   int async_exec;
2683
2684   old_chain = make_cleanup (null_cleanup, NULL);
2685
2686   /* If in non-stop, leave threads as running as they were.  If
2687      they're stopped for some reason other than us telling it to, the
2688      target reports a signal != GDB_SIGNAL_0.  We don't try to
2689      resume threads with such a stop signal.  */
2690   async_exec = non_stop;
2691
2692   if (!ptid_equal (inferior_ptid, null_ptid))
2693     make_cleanup_restore_current_thread ();
2694
2695   switch_to_thread (ptid);
2696
2697   /* When we "notice" a new inferior we need to do all the things we
2698      would normally do if we had just attached to it.  */
2699
2700   if (is_executing (inferior_ptid))
2701     {
2702       struct inferior *inferior = current_inferior ();
2703
2704       /* We're going to install breakpoints, and poke at memory,
2705          ensure that the inferior is stopped for a moment while we do
2706          that.  */
2707       target_stop (inferior_ptid);
2708
2709       inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2710
2711       /* Wait for stop before proceeding.  */
2712       if (target_can_async_p ())
2713         {
2714           struct attach_command_continuation_args *a;
2715
2716           a = xmalloc (sizeof (*a));
2717           a->args = xstrdup ("");
2718           a->from_tty = from_tty;
2719           a->async_exec = async_exec;
2720           add_inferior_continuation (attach_command_continuation, a,
2721                                      attach_command_continuation_free_args);
2722
2723           do_cleanups (old_chain);
2724           return;
2725         }
2726       else
2727         wait_for_inferior ();
2728     }
2729
2730   async_exec = leave_running;
2731   attach_command_post_wait ("" /* args */, from_tty, async_exec);
2732
2733   do_cleanups (old_chain);
2734 }
2735
2736 /*
2737  * detach_command --
2738  * takes a program previously attached to and detaches it.
2739  * The program resumes execution and will no longer stop
2740  * on signals, etc.  We better not have left any breakpoints
2741  * in the program or it'll die when it hits one.  For this
2742  * to work, it may be necessary for the process to have been
2743  * previously attached.  It *might* work if the program was
2744  * started via the normal ptrace (PTRACE_TRACEME).
2745  */
2746
2747 void
2748 detach_command (char *args, int from_tty)
2749 {
2750   dont_repeat ();               /* Not for the faint of heart.  */
2751
2752   if (ptid_equal (inferior_ptid, null_ptid))
2753     error (_("The program is not being run."));
2754
2755   query_if_trace_running (from_tty);
2756
2757   disconnect_tracing ();
2758
2759   target_detach (args, from_tty);
2760
2761   /* If the solist is global across inferiors, don't clear it when we
2762      detach from a single inferior.  */
2763   if (!gdbarch_has_global_solist (target_gdbarch ()))
2764     no_shared_libraries (NULL, from_tty);
2765
2766   /* If we still have inferiors to debug, then don't mess with their
2767      threads.  */
2768   if (!have_inferiors ())
2769     init_thread_list ();
2770
2771   if (deprecated_detach_hook)
2772     deprecated_detach_hook ();
2773 }
2774
2775 /* Disconnect from the current target without resuming it (leaving it
2776    waiting for a debugger).
2777
2778    We'd better not have left any breakpoints in the program or the
2779    next debugger will get confused.  Currently only supported for some
2780    remote targets, since the normal attach mechanisms don't work on
2781    stopped processes on some native platforms (e.g. GNU/Linux).  */
2782
2783 static void
2784 disconnect_command (char *args, int from_tty)
2785 {
2786   dont_repeat ();               /* Not for the faint of heart.  */
2787   query_if_trace_running (from_tty);
2788   disconnect_tracing ();
2789   target_disconnect (args, from_tty);
2790   no_shared_libraries (NULL, from_tty);
2791   init_thread_list ();
2792   if (deprecated_detach_hook)
2793     deprecated_detach_hook ();
2794 }
2795
2796 void 
2797 interrupt_target_1 (int all_threads)
2798 {
2799   ptid_t ptid;
2800
2801   if (all_threads)
2802     ptid = minus_one_ptid;
2803   else
2804     ptid = inferior_ptid;
2805   target_stop (ptid);
2806
2807   /* Tag the thread as having been explicitly requested to stop, so
2808      other parts of gdb know not to resume this thread automatically,
2809      if it was stopped due to an internal event.  Limit this to
2810      non-stop mode, as when debugging a multi-threaded application in
2811      all-stop mode, we will only get one stop event --- it's undefined
2812      which thread will report the event.  */
2813   if (non_stop)
2814     set_stop_requested (ptid, 1);
2815 }
2816
2817 /* interrupt [-a]
2818    Stop the execution of the target while running in async mode, in
2819    the backgound.  In all-stop, stop the whole process.  In non-stop
2820    mode, stop the current thread only by default, or stop all threads
2821    if the `-a' switch is used.  */
2822
2823 static void
2824 interrupt_command (char *args, int from_tty)
2825 {
2826   if (target_can_async_p ())
2827     {
2828       int all_threads = 0;
2829
2830       dont_repeat ();           /* Not for the faint of heart.  */
2831
2832       if (args != NULL
2833           && startswith (args, "-a"))
2834         all_threads = 1;
2835
2836       if (!non_stop && all_threads)
2837         error (_("-a is meaningless in all-stop mode."));
2838
2839       interrupt_target_1 (all_threads);
2840     }
2841 }
2842
2843 /* See inferior.h.  */
2844
2845 void
2846 default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2847                           struct frame_info *frame, const char *args)
2848 {
2849   int regnum;
2850   int printed_something = 0;
2851
2852   for (regnum = 0;
2853        regnum < gdbarch_num_regs (gdbarch)
2854          + gdbarch_num_pseudo_regs (gdbarch);
2855        regnum++)
2856     {
2857       if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2858         {
2859           printed_something = 1;
2860           gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2861         }
2862     }
2863   if (!printed_something)
2864     fprintf_filtered (file, "No floating-point info "
2865                       "available for this processor.\n");
2866 }
2867
2868 static void
2869 float_info (char *args, int from_tty)
2870 {
2871   struct frame_info *frame;
2872
2873   if (!target_has_registers)
2874     error (_("The program has no registers now."));
2875
2876   frame = get_selected_frame (NULL);
2877   gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
2878 }
2879 \f
2880 static void
2881 unset_command (char *args, int from_tty)
2882 {
2883   printf_filtered (_("\"unset\" must be followed by the "
2884                      "name of an unset subcommand.\n"));
2885   help_list (unsetlist, "unset ", all_commands, gdb_stdout);
2886 }
2887
2888 /* Implement `info proc' family of commands.  */
2889
2890 static void
2891 info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
2892 {
2893   struct gdbarch *gdbarch = get_current_arch ();
2894
2895   if (!target_info_proc (args, what))
2896     {
2897       if (gdbarch_info_proc_p (gdbarch))
2898         gdbarch_info_proc (gdbarch, args, what);
2899       else
2900         error (_("Not supported on this target."));
2901     }
2902 }
2903
2904 /* Implement `info proc' when given without any futher parameters.  */
2905
2906 static void
2907 info_proc_cmd (char *args, int from_tty)
2908 {
2909   info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
2910 }
2911
2912 /* Implement `info proc mappings'.  */
2913
2914 static void
2915 info_proc_cmd_mappings (char *args, int from_tty)
2916 {
2917   info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
2918 }
2919
2920 /* Implement `info proc stat'.  */
2921
2922 static void
2923 info_proc_cmd_stat (char *args, int from_tty)
2924 {
2925   info_proc_cmd_1 (args, IP_STAT, from_tty);
2926 }
2927
2928 /* Implement `info proc status'.  */
2929
2930 static void
2931 info_proc_cmd_status (char *args, int from_tty)
2932 {
2933   info_proc_cmd_1 (args, IP_STATUS, from_tty);
2934 }
2935
2936 /* Implement `info proc cwd'.  */
2937
2938 static void
2939 info_proc_cmd_cwd (char *args, int from_tty)
2940 {
2941   info_proc_cmd_1 (args, IP_CWD, from_tty);
2942 }
2943
2944 /* Implement `info proc cmdline'.  */
2945
2946 static void
2947 info_proc_cmd_cmdline (char *args, int from_tty)
2948 {
2949   info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
2950 }
2951
2952 /* Implement `info proc exe'.  */
2953
2954 static void
2955 info_proc_cmd_exe (char *args, int from_tty)
2956 {
2957   info_proc_cmd_1 (args, IP_EXE, from_tty);
2958 }
2959
2960 /* Implement `info proc all'.  */
2961
2962 static void
2963 info_proc_cmd_all (char *args, int from_tty)
2964 {
2965   info_proc_cmd_1 (args, IP_ALL, from_tty);
2966 }
2967
2968 void
2969 _initialize_infcmd (void)
2970 {
2971   static struct cmd_list_element *info_proc_cmdlist;
2972   struct cmd_list_element *c = NULL;
2973   const char *cmd_name;
2974
2975   /* Add the filename of the terminal connected to inferior I/O.  */
2976   add_setshow_filename_cmd ("inferior-tty", class_run,
2977                             &inferior_io_terminal_scratch, _("\
2978 Set terminal for future runs of program being debugged."), _("\
2979 Show terminal for future runs of program being debugged."), _("\
2980 Usage: set inferior-tty /dev/pts/1"),
2981                             set_inferior_tty_command,
2982                             show_inferior_tty_command,
2983                             &setlist, &showlist);
2984   add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2985
2986   cmd_name = "args";
2987   add_setshow_string_noescape_cmd (cmd_name, class_run,
2988                                    &inferior_args_scratch, _("\
2989 Set argument list to give program being debugged when it is started."), _("\
2990 Show argument list to give program being debugged when it is started."), _("\
2991 Follow this command with any number of args, to be passed to the program."),
2992                                    set_args_command,
2993                                    show_args_command,
2994                                    &setlist, &showlist);
2995   c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
2996   gdb_assert (c != NULL);
2997   set_cmd_completer (c, filename_completer);
2998
2999   c = add_cmd ("environment", no_class, environment_info, _("\
3000 The environment to give the program, or one variable's value.\n\
3001 With an argument VAR, prints the value of environment variable VAR to\n\
3002 give the program being debugged.  With no arguments, prints the entire\n\
3003 environment to be given to the program."), &showlist);
3004   set_cmd_completer (c, noop_completer);
3005
3006   add_prefix_cmd ("unset", no_class, unset_command,
3007                   _("Complement to certain \"set\" commands."),
3008                   &unsetlist, "unset ", 0, &cmdlist);
3009
3010   c = add_cmd ("environment", class_run, unset_environment_command, _("\
3011 Cancel environment variable VAR for the program.\n\
3012 This does not affect the program until the next \"run\" command."),
3013                &unsetlist);
3014   set_cmd_completer (c, noop_completer);
3015
3016   c = add_cmd ("environment", class_run, set_environment_command, _("\
3017 Set environment variable value to give the program.\n\
3018 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3019 VALUES of environment variables are uninterpreted strings.\n\
3020 This does not affect the program until the next \"run\" command."),
3021                &setlist);
3022   set_cmd_completer (c, noop_completer);
3023
3024   c = add_com ("path", class_files, path_command, _("\
3025 Add directory DIR(s) to beginning of search path for object files.\n\
3026 $cwd in the path means the current working directory.\n\
3027 This path is equivalent to the $PATH shell variable.  It is a list of\n\
3028 directories, separated by colons.  These directories are searched to find\n\
3029 fully linked executable files and separately compiled object files as \
3030 needed."));
3031   set_cmd_completer (c, filename_completer);
3032
3033   c = add_cmd ("paths", no_class, path_info, _("\
3034 Current search path for finding object files.\n\
3035 $cwd in the path means the current working directory.\n\
3036 This path is equivalent to the $PATH shell variable.  It is a list of\n\
3037 directories, separated by colons.  These directories are searched to find\n\
3038 fully linked executable files and separately compiled object files as \
3039 needed."),
3040                &showlist);
3041   set_cmd_completer (c, noop_completer);
3042
3043   add_prefix_cmd ("kill", class_run, kill_command,
3044                   _("Kill execution of program being debugged."),
3045                   &killlist, "kill ", 0, &cmdlist);
3046
3047   add_com ("attach", class_run, attach_command, _("\
3048 Attach to a process or file outside of GDB.\n\
3049 This command attaches to another target, of the same type as your last\n\
3050 \"target\" command (\"info files\" will show your target stack).\n\
3051 The command may take as argument a process id or a device file.\n\
3052 For a process id, you must have permission to send the process a signal,\n\
3053 and it must have the same effective uid as the debugger.\n\
3054 When using \"attach\" with a process id, the debugger finds the\n\
3055 program running in the process, looking first in the current working\n\
3056 directory, or (if not found there) using the source file search path\n\
3057 (see the \"directory\" command).  You can also use the \"file\" command\n\
3058 to specify the program, and to load its symbol table."));
3059
3060   add_prefix_cmd ("detach", class_run, detach_command, _("\
3061 Detach a process or file previously attached.\n\
3062 If a process, it is no longer traced, and it continues its execution.  If\n\
3063 you were debugging a file, the file is closed and gdb no longer accesses it."),
3064                   &detachlist, "detach ", 0, &cmdlist);
3065
3066   add_com ("disconnect", class_run, disconnect_command, _("\
3067 Disconnect from a target.\n\
3068 The target will wait for another debugger to connect.  Not available for\n\
3069 all targets."));
3070
3071   c = add_com ("signal", class_run, signal_command, _("\
3072 Continue program with the specified signal.\n\
3073 Usage: signal SIGNAL\n\
3074 The SIGNAL argument is processed the same as the handle command.\n\
3075 \n\
3076 An argument of \"0\" means continue the program without sending it a signal.\n\
3077 This is useful in cases where the program stopped because of a signal,\n\
3078 and you want to resume the program while discarding the signal.\n\
3079 \n\
3080 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3081 the current thread only."));
3082   set_cmd_completer (c, signal_completer);
3083
3084   c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3085 Queue a signal to be delivered to the current thread when it is resumed.\n\
3086 Usage: queue-signal SIGNAL\n\
3087 The SIGNAL argument is processed the same as the handle command.\n\
3088 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3089 \n\
3090 An argument of \"0\" means remove any currently queued signal from\n\
3091 the current thread.  This is useful in cases where the program stopped\n\
3092 because of a signal, and you want to resume it while discarding the signal.\n\
3093 \n\
3094 In a multi-threaded program the signal is queued with, or discarded from,\n\
3095 the current thread only."));
3096   set_cmd_completer (c, signal_completer);
3097
3098   add_com ("stepi", class_run, stepi_command, _("\
3099 Step one instruction exactly.\n\
3100 Usage: stepi [N]\n\
3101 Argument N means step N times (or till program stops for another \
3102 reason)."));
3103   add_com_alias ("si", "stepi", class_alias, 0);
3104
3105   add_com ("nexti", class_run, nexti_command, _("\
3106 Step one instruction, but proceed through subroutine calls.\n\
3107 Usage: nexti [N]\n\
3108 Argument N means step N times (or till program stops for another \
3109 reason)."));
3110   add_com_alias ("ni", "nexti", class_alias, 0);
3111
3112   add_com ("finish", class_run, finish_command, _("\
3113 Execute until selected stack frame returns.\n\
3114 Usage: finish\n\
3115 Upon return, the value returned is printed and put in the value history."));
3116   add_com_alias ("fin", "finish", class_run, 1);
3117
3118   add_com ("next", class_run, next_command, _("\
3119 Step program, proceeding through subroutine calls.\n\
3120 Usage: next [N]\n\
3121 Unlike \"step\", if the current source line calls a subroutine,\n\
3122 this command does not enter the subroutine, but instead steps over\n\
3123 the call, in effect treating it as a single source line."));
3124   add_com_alias ("n", "next", class_run, 1);
3125
3126   add_com ("step", class_run, step_command, _("\
3127 Step program until it reaches a different source line.\n\
3128 Usage: step [N]\n\
3129 Argument N means step N times (or till program stops for another \
3130 reason)."));
3131   add_com_alias ("s", "step", class_run, 1);
3132
3133   c = add_com ("until", class_run, until_command, _("\
3134 Execute until the program reaches a source line greater than the current\n\
3135 or a specified location (same args as break command) within the current \
3136 frame."));
3137   set_cmd_completer (c, location_completer);
3138   add_com_alias ("u", "until", class_run, 1);
3139
3140   c = add_com ("advance", class_run, advance_command, _("\
3141 Continue the program up to the given location (same form as args for break \
3142 command).\n\
3143 Execution will also stop upon exit from the current stack frame."));
3144   set_cmd_completer (c, location_completer);
3145
3146   c = add_com ("jump", class_run, jump_command, _("\
3147 Continue program being debugged at specified line or address.\n\
3148 Usage: jump <location>\n\
3149 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3150 for an address to start at."));
3151   set_cmd_completer (c, location_completer);
3152   add_com_alias ("j", "jump", class_run, 1);
3153
3154   add_com ("continue", class_run, continue_command, _("\
3155 Continue program being debugged, after signal or breakpoint.\n\
3156 Usage: continue [N]\n\
3157 If proceeding from breakpoint, a number N may be used as an argument,\n\
3158 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3159 the breakpoint won't break until the Nth time it is reached).\n\
3160 \n\
3161 If non-stop mode is enabled, continue only the current thread,\n\
3162 otherwise all the threads in the program are continued.  To \n\
3163 continue all stopped threads in non-stop mode, use the -a option.\n\
3164 Specifying -a and an ignore count simultaneously is an error."));
3165   add_com_alias ("c", "cont", class_run, 1);
3166   add_com_alias ("fg", "cont", class_run, 1);
3167
3168   c = add_com ("run", class_run, run_command, _("\
3169 Start debugged program.  You may specify arguments to give it.\n\
3170 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3171 Input and output redirection with \">\", \"<\", or \">>\" are also \
3172 allowed.\n\n\
3173 With no arguments, uses arguments last specified (with \"run\" \
3174 or \"set args\").\n\
3175 To cancel previous arguments and run with no arguments,\n\
3176 use \"set args\" without arguments."));
3177   set_cmd_completer (c, filename_completer);
3178   add_com_alias ("r", "run", class_run, 1);
3179
3180   c = add_com ("start", class_run, start_command, _("\
3181 Run the debugged program until the beginning of the main procedure.\n\
3182 You may specify arguments to give to your program, just as with the\n\
3183 \"run\" command."));
3184   set_cmd_completer (c, filename_completer);
3185
3186   add_com ("interrupt", class_run, interrupt_command,
3187            _("Interrupt the execution of the debugged program.\n\
3188 If non-stop mode is enabled, interrupt only the current thread,\n\
3189 otherwise all the threads in the program are stopped.  To \n\
3190 interrupt all running threads in non-stop mode, use the -a option."));
3191
3192   c = add_info ("registers", nofp_registers_info, _("\
3193 List of integer registers and their contents, for selected stack frame.\n\
3194 Register name as argument means describe only that register."));
3195   add_info_alias ("r", "registers", 1);
3196   set_cmd_completer (c, reg_or_group_completer);
3197
3198   c = add_info ("all-registers", all_registers_info, _("\
3199 List of all registers and their contents, for selected stack frame.\n\
3200 Register name as argument means describe only that register."));
3201   set_cmd_completer (c, reg_or_group_completer);
3202
3203   add_info ("program", program_info,
3204             _("Execution status of the program."));
3205
3206   add_info ("float", float_info,
3207             _("Print the status of the floating point unit\n"));
3208
3209   add_info ("vector", vector_info,
3210             _("Print the status of the vector unit\n"));
3211
3212   add_prefix_cmd ("proc", class_info, info_proc_cmd,
3213                   _("\
3214 Show /proc process information about any running process.\n\
3215 Specify any process id, or use the program being debugged by default."),
3216                   &info_proc_cmdlist, "info proc ",
3217                   1/*allow-unknown*/, &infolist);
3218
3219   add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3220 List of mapped memory regions."),
3221            &info_proc_cmdlist);
3222
3223   add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3224 List process info from /proc/PID/stat."),
3225            &info_proc_cmdlist);
3226
3227   add_cmd ("status", class_info, info_proc_cmd_status, _("\
3228 List process info from /proc/PID/status."),
3229            &info_proc_cmdlist);
3230
3231   add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3232 List current working directory of the process."),
3233            &info_proc_cmdlist);
3234
3235   add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3236 List command line arguments of the process."),
3237            &info_proc_cmdlist);
3238
3239   add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3240 List absolute filename for executable of the process."),
3241            &info_proc_cmdlist);
3242
3243   add_cmd ("all", class_info, info_proc_cmd_all, _("\
3244 List all available /proc info."),
3245            &info_proc_cmdlist);
3246 }