GDB (API)
/home/stan/gdb/src/gdb/infcmd.c
Go to the documentation of this file.
00001 /* Memory-access and commands for "inferior" process, for GDB.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include <signal.h>
00023 #include "gdb_string.h"
00024 #include "symtab.h"
00025 #include "gdbtypes.h"
00026 #include "frame.h"
00027 #include "inferior.h"
00028 #include "environ.h"
00029 #include "value.h"
00030 #include "gdbcmd.h"
00031 #include "symfile.h"
00032 #include "gdbcore.h"
00033 #include "target.h"
00034 #include "language.h"
00035 #include "symfile.h"
00036 #include "objfiles.h"
00037 #include "completer.h"
00038 #include "ui-out.h"
00039 #include "event-top.h"
00040 #include "parser-defs.h"
00041 #include "regcache.h"
00042 #include "reggroups.h"
00043 #include "block.h"
00044 #include "solib.h"
00045 #include <ctype.h>
00046 #include "gdb_assert.h"
00047 #include "observer.h"
00048 #include "target-descriptions.h"
00049 #include "user-regs.h"
00050 #include "exceptions.h"
00051 #include "cli/cli-decode.h"
00052 #include "gdbthread.h"
00053 #include "valprint.h"
00054 #include "inline-frame.h"
00055 #include "tracepoint.h"
00056 #include "inf-loop.h"
00057 #include "continuations.h"
00058 #include "linespec.h"
00059 #include "cli/cli-utils.h"
00060 
00061 /* Local functions: */
00062 
00063 static void nofp_registers_info (char *, int);
00064 
00065 static void print_return_value (struct value *function,
00066                                 struct type *value_type);
00067 
00068 static void until_next_command (int);
00069 
00070 static void until_command (char *, int);
00071 
00072 static void path_info (char *, int);
00073 
00074 static void path_command (char *, int);
00075 
00076 static void unset_command (char *, int);
00077 
00078 static void float_info (char *, int);
00079 
00080 static void disconnect_command (char *, int);
00081 
00082 static void unset_environment_command (char *, int);
00083 
00084 static void set_environment_command (char *, int);
00085 
00086 static void environment_info (char *, int);
00087 
00088 static void program_info (char *, int);
00089 
00090 static void finish_command (char *, int);
00091 
00092 static void signal_command (char *, int);
00093 
00094 static void jump_command (char *, int);
00095 
00096 static void step_1 (int, int, char *);
00097 static void step_once (int skip_subroutines, int single_inst,
00098                        int count, int thread);
00099 
00100 static void next_command (char *, int);
00101 
00102 static void step_command (char *, int);
00103 
00104 static void run_command (char *, int);
00105 
00106 static void run_no_args_command (char *args, int from_tty);
00107 
00108 static void go_command (char *line_no, int from_tty);
00109 
00110 static int strip_bg_char (char **);
00111 
00112 void _initialize_infcmd (void);
00113 
00114 #define ERROR_NO_INFERIOR \
00115    if (!target_has_execution) error (_("The program is not being run."));
00116 
00117 /* Scratch area where string containing arguments to give to the
00118    program will be stored by 'set args'.  As soon as anything is
00119    stored, notice_args_set will move it into per-inferior storage.
00120    Arguments are separated by spaces.  Empty string (pointer to '\0')
00121    means no args.  */
00122 
00123 static char *inferior_args_scratch;
00124 
00125 /* Scratch area where 'set inferior-tty' will store user-provided value.
00126    We'll immediate copy it into per-inferior storage.  */
00127 
00128 static char *inferior_io_terminal_scratch;
00129 
00130 /* Pid of our debugged inferior, or 0 if no inferior now.
00131    Since various parts of infrun.c test this to see whether there is a program
00132    being debugged it should be nonzero (currently 3 is used) for remote
00133    debugging.  */
00134 
00135 ptid_t inferior_ptid;
00136 
00137 /* Address at which inferior stopped.  */
00138 
00139 CORE_ADDR stop_pc;
00140 
00141 /* Nonzero if stopped due to completion of a stack dummy routine.  */
00142 
00143 enum stop_stack_kind stop_stack_dummy;
00144 
00145 /* Nonzero if stopped due to a random (unexpected) signal in inferior
00146    process.  */
00147 
00148 int stopped_by_random_signal;
00149 
00150 
00151 /* Accessor routines.  */
00152 
00153 /* Set the io terminal for the current inferior.  Ownership of
00154    TERMINAL_NAME is not transferred.  */
00155 
00156 void 
00157 set_inferior_io_terminal (const char *terminal_name)
00158 {
00159   xfree (current_inferior ()->terminal);
00160   current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
00161 }
00162 
00163 const char *
00164 get_inferior_io_terminal (void)
00165 {
00166   return current_inferior ()->terminal;
00167 }
00168 
00169 static void
00170 set_inferior_tty_command (char *args, int from_tty,
00171                           struct cmd_list_element *c)
00172 {
00173   /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
00174      Now route it to current inferior.  */
00175   set_inferior_io_terminal (inferior_io_terminal_scratch);
00176 }
00177 
00178 static void
00179 show_inferior_tty_command (struct ui_file *file, int from_tty,
00180                            struct cmd_list_element *c, const char *value)
00181 {
00182   /* Note that we ignore the passed-in value in favor of computing it
00183      directly.  */
00184   const char *inferior_io_terminal = get_inferior_io_terminal ();
00185 
00186   if (inferior_io_terminal == NULL)
00187     inferior_io_terminal = "";
00188   fprintf_filtered (gdb_stdout,
00189                     _("Terminal for future runs of program being debugged "
00190                       "is \"%s\".\n"), inferior_io_terminal);
00191 }
00192 
00193 char *
00194 get_inferior_args (void)
00195 {
00196   if (current_inferior ()->argc != 0)
00197     {
00198       char *n;
00199 
00200       n = construct_inferior_arguments (current_inferior ()->argc,
00201                                         current_inferior ()->argv);
00202       set_inferior_args (n);
00203       xfree (n);
00204     }
00205 
00206   if (current_inferior ()->args == NULL)
00207     current_inferior ()->args = xstrdup ("");
00208 
00209   return current_inferior ()->args;
00210 }
00211 
00212 /* Set the arguments for the current inferior.  Ownership of
00213    NEWARGS is not transferred.  */
00214 
00215 void
00216 set_inferior_args (char *newargs)
00217 {
00218   xfree (current_inferior ()->args);
00219   current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
00220   current_inferior ()->argc = 0;
00221   current_inferior ()->argv = 0;
00222 }
00223 
00224 void
00225 set_inferior_args_vector (int argc, char **argv)
00226 {
00227   current_inferior ()->argc = argc;
00228   current_inferior ()->argv = argv;
00229 }
00230 
00231 /* Notice when `set args' is run.  */
00232 static void
00233 set_args_command (char *args, int from_tty, struct cmd_list_element *c)
00234 {
00235   /* CLI has assigned the user-provided value to inferior_args_scratch.
00236      Now route it to current inferior.  */
00237   set_inferior_args (inferior_args_scratch);
00238 }
00239 
00240 /* Notice when `show args' is run.  */
00241 static void
00242 show_args_command (struct ui_file *file, int from_tty,
00243                    struct cmd_list_element *c, const char *value)
00244 {
00245   /* Note that we ignore the passed-in value in favor of computing it
00246      directly.  */
00247   deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
00248 }
00249 
00250 
00251 /* Compute command-line string given argument vector.  This does the
00252    same shell processing as fork_inferior.  */
00253 char *
00254 construct_inferior_arguments (int argc, char **argv)
00255 {
00256   char *result;
00257 
00258   if (STARTUP_WITH_SHELL)
00259     {
00260 #ifdef __MINGW32__
00261       /* This holds all the characters considered special to the
00262          Windows shells.  */
00263       char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
00264       const char quote = '"';
00265 #else
00266       /* This holds all the characters considered special to the
00267          typical Unix shells.  We include `^' because the SunOS
00268          /bin/sh treats it as a synonym for `|'.  */
00269       char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
00270       const char quote = '\'';
00271 #endif
00272       int i;
00273       int length = 0;
00274       char *out, *cp;
00275 
00276       /* We over-compute the size.  It shouldn't matter.  */
00277       for (i = 0; i < argc; ++i)
00278         length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
00279 
00280       result = (char *) xmalloc (length);
00281       out = result;
00282 
00283       for (i = 0; i < argc; ++i)
00284         {
00285           if (i > 0)
00286             *out++ = ' ';
00287 
00288           /* Need to handle empty arguments specially.  */
00289           if (argv[i][0] == '\0')
00290             {
00291               *out++ = quote;
00292               *out++ = quote;
00293             }
00294           else
00295             {
00296 #ifdef __MINGW32__
00297               int quoted = 0;
00298 
00299               if (strpbrk (argv[i], special))
00300                 {
00301                   quoted = 1;
00302                   *out++ = quote;
00303                 }
00304 #endif
00305               for (cp = argv[i]; *cp; ++cp)
00306                 {
00307                   if (*cp == '\n')
00308                     {
00309                       /* A newline cannot be quoted with a backslash (it
00310                          just disappears), only by putting it inside
00311                          quotes.  */
00312                       *out++ = quote;
00313                       *out++ = '\n';
00314                       *out++ = quote;
00315                     }
00316                   else
00317                     {
00318 #ifdef __MINGW32__
00319                       if (*cp == quote)
00320 #else
00321                       if (strchr (special, *cp) != NULL)
00322 #endif
00323                         *out++ = '\\';
00324                       *out++ = *cp;
00325                     }
00326                 }
00327 #ifdef __MINGW32__
00328               if (quoted)
00329                 *out++ = quote;
00330 #endif
00331             }
00332         }
00333       *out = '\0';
00334     }
00335   else
00336     {
00337       /* In this case we can't handle arguments that contain spaces,
00338          tabs, or newlines -- see breakup_args().  */
00339       int i;
00340       int length = 0;
00341 
00342       for (i = 0; i < argc; ++i)
00343         {
00344           char *cp = strchr (argv[i], ' ');
00345           if (cp == NULL)
00346             cp = strchr (argv[i], '\t');
00347           if (cp == NULL)
00348             cp = strchr (argv[i], '\n');
00349           if (cp != NULL)
00350             error (_("can't handle command-line "
00351                      "argument containing whitespace"));
00352           length += strlen (argv[i]) + 1;
00353         }
00354 
00355       result = (char *) xmalloc (length);
00356       result[0] = '\0';
00357       for (i = 0; i < argc; ++i)
00358         {
00359           if (i > 0)
00360             strcat (result, " ");
00361           strcat (result, argv[i]);
00362         }
00363     }
00364 
00365   return result;
00366 }
00367 
00368 
00369 /* This function detects whether or not a '&' character (indicating
00370    background execution) has been added as *the last* of the arguments ARGS
00371    of a command.  If it has, it removes it and returns 1.  Otherwise it
00372    does nothing and returns 0.  */
00373 static int
00374 strip_bg_char (char **args)
00375 {
00376   char *p = NULL;
00377 
00378   p = strchr (*args, '&');
00379 
00380   if (p)
00381     {
00382       if (p == (*args + strlen (*args) - 1))
00383         {
00384           if (strlen (*args) > 1)
00385             {
00386               do
00387                 p--;
00388               while (*p == ' ' || *p == '\t');
00389               *(p + 1) = '\0';
00390             }
00391           else
00392             *args = 0;
00393           return 1;
00394         }
00395     }
00396   return 0;
00397 }
00398 
00399 /* Common actions to take after creating any sort of inferior, by any
00400    means (running, attaching, connecting, et cetera).  The target
00401    should be stopped.  */
00402 
00403 void
00404 post_create_inferior (struct target_ops *target, int from_tty)
00405 {
00406   volatile struct gdb_exception ex;
00407 
00408   /* Be sure we own the terminal in case write operations are performed.  */ 
00409   target_terminal_ours ();
00410 
00411   /* If the target hasn't taken care of this already, do it now.
00412      Targets which need to access registers during to_open,
00413      to_create_inferior, or to_attach should do it earlier; but many
00414      don't need to.  */
00415   target_find_description ();
00416 
00417   /* Now that we know the register layout, retrieve current PC.  But
00418      if the PC is unavailable (e.g., we're opening a core file with
00419      missing registers info), ignore it.  */
00420   stop_pc = 0;
00421   TRY_CATCH (ex, RETURN_MASK_ERROR)
00422     {
00423       stop_pc = regcache_read_pc (get_current_regcache ());
00424     }
00425   if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
00426     throw_exception (ex);
00427 
00428   if (exec_bfd)
00429     {
00430       const unsigned solib_add_generation
00431         = current_program_space->solib_add_generation;
00432 
00433       /* Create the hooks to handle shared library load and unload
00434          events.  */
00435       solib_create_inferior_hook (from_tty);
00436 
00437       if (current_program_space->solib_add_generation == solib_add_generation)
00438         {
00439           /* The platform-specific hook should load initial shared libraries,
00440              but didn't.  FROM_TTY will be incorrectly 0 but such solib
00441              targets should be fixed anyway.  Call it only after the solib
00442              target has been initialized by solib_create_inferior_hook.  */
00443 
00444           if (info_verbose)
00445             warning (_("platform-specific solib_create_inferior_hook did "
00446                        "not load initial shared libraries."));
00447 
00448           /* If the solist is global across processes, there's no need to
00449              refetch it here.  */
00450           if (!gdbarch_has_global_solist (target_gdbarch ()))
00451             solib_add (NULL, 0, target, auto_solib_add);
00452         }
00453     }
00454 
00455   /* If the user sets watchpoints before execution having started,
00456      then she gets software watchpoints, because GDB can't know which
00457      target will end up being pushed, or if it supports hardware
00458      watchpoints or not.  breakpoint_re_set takes care of promoting
00459      watchpoints to hardware watchpoints if possible, however, if this
00460      new inferior doesn't load shared libraries or we don't pull in
00461      symbols from any other source on this target/arch,
00462      breakpoint_re_set is never called.  Call it now so that software
00463      watchpoints get a chance to be promoted to hardware watchpoints
00464      if the now pushed target supports hardware watchpoints.  */
00465   breakpoint_re_set ();
00466 
00467   observer_notify_inferior_created (target, from_tty);
00468 }
00469 
00470 /* Kill the inferior if already running.  This function is designed
00471    to be called when we are about to start the execution of the program
00472    from the beginning.  Ask the user to confirm that he wants to restart
00473    the program being debugged when FROM_TTY is non-null.  */
00474 
00475 static void
00476 kill_if_already_running (int from_tty)
00477 {
00478   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
00479     {
00480       /* Bail out before killing the program if we will not be able to
00481          restart it.  */
00482       target_require_runnable ();
00483 
00484       if (from_tty
00485           && !query (_("The program being debugged has been started already.\n\
00486 Start it from the beginning? ")))
00487         error (_("Program not restarted."));
00488       target_kill ();
00489     }
00490 }
00491 
00492 /* Implement the "run" command.  If TBREAK_AT_MAIN is set, then insert
00493    a temporary breakpoint at the begining of the main program before
00494    running the program.  */
00495 
00496 static void
00497 run_command_1 (char *args, int from_tty, int tbreak_at_main)
00498 {
00499   char *exec_file;
00500   struct cleanup *old_chain;
00501   ptid_t ptid;
00502   struct ui_out *uiout = current_uiout;
00503 
00504   dont_repeat ();
00505 
00506   kill_if_already_running (from_tty);
00507 
00508   init_wait_for_inferior ();
00509   clear_breakpoint_hit_counts ();
00510 
00511   /* Clean up any leftovers from other runs.  Some other things from
00512      this function should probably be moved into target_pre_inferior.  */
00513   target_pre_inferior (from_tty);
00514 
00515   /* The comment here used to read, "The exec file is re-read every
00516      time we do a generic_mourn_inferior, so we just have to worry
00517      about the symbol file."  The `generic_mourn_inferior' function
00518      gets called whenever the program exits.  However, suppose the
00519      program exits, and *then* the executable file changes?  We need
00520      to check again here.  Since reopen_exec_file doesn't do anything
00521      if the timestamp hasn't changed, I don't see the harm.  */
00522   reopen_exec_file ();
00523   reread_symbols ();
00524 
00525   /* Insert the temporary breakpoint if a location was specified.  */
00526   if (tbreak_at_main)
00527     tbreak_command (main_name (), 0);
00528 
00529   exec_file = (char *) get_exec_file (0);
00530 
00531   if (non_stop && !target_supports_non_stop ())
00532     error (_("The target does not support running in non-stop mode."));
00533 
00534   /* We keep symbols from add-symbol-file, on the grounds that the
00535      user might want to add some symbols before running the program
00536      (right?).  But sometimes (dynamic loading where the user manually
00537      introduces the new symbols with add-symbol-file), the code which
00538      the symbols describe does not persist between runs.  Currently
00539      the user has to manually nuke all symbols between runs if they
00540      want them to go away (PR 2207).  This is probably reasonable.  */
00541 
00542   if (!args)
00543     {
00544       if (target_can_async_p ())
00545         async_disable_stdin ();
00546     }
00547   else
00548     {
00549       int async_exec = strip_bg_char (&args);
00550 
00551       /* If we get a request for running in the bg but the target
00552          doesn't support it, error out.  */
00553       if (async_exec && !target_can_async_p ())
00554         error (_("Asynchronous execution not supported on this target."));
00555 
00556       /* If we don't get a request of running in the bg, then we need
00557          to simulate synchronous (fg) execution.  */
00558       if (!async_exec && target_can_async_p ())
00559         {
00560           /* Simulate synchronous execution.  */
00561           async_disable_stdin ();
00562         }
00563 
00564       /* If there were other args, beside '&', process them.  */
00565       if (args)
00566         set_inferior_args (args);
00567     }
00568 
00569   if (from_tty)
00570     {
00571       ui_out_field_string (uiout, NULL, "Starting program");
00572       ui_out_text (uiout, ": ");
00573       if (exec_file)
00574         ui_out_field_string (uiout, "execfile", exec_file);
00575       ui_out_spaces (uiout, 1);
00576       /* We call get_inferior_args() because we might need to compute
00577          the value now.  */
00578       ui_out_field_string (uiout, "infargs", get_inferior_args ());
00579       ui_out_text (uiout, "\n");
00580       ui_out_flush (uiout);
00581     }
00582 
00583   /* We call get_inferior_args() because we might need to compute
00584      the value now.  */
00585   target_create_inferior (exec_file, get_inferior_args (),
00586                           environ_vector (current_inferior ()->environment),
00587                           from_tty);
00588 
00589   /* We're starting off a new process.  When we get out of here, in
00590      non-stop mode, finish the state of all threads of that process,
00591      but leave other threads alone, as they may be stopped in internal
00592      events --- the frontend shouldn't see them as stopped.  In
00593      all-stop, always finish the state of all threads, as we may be
00594      resuming more than just the new process.  */
00595   if (non_stop)
00596     ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
00597   else
00598     ptid = minus_one_ptid;
00599   old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
00600 
00601   /* Pass zero for FROM_TTY, because at this point the "run" command
00602      has done its thing; now we are setting up the running program.  */
00603   post_create_inferior (&current_target, 0);
00604 
00605   /* Start the target running.  Do not use -1 continuation as it would skip
00606      breakpoint right at the entry point.  */
00607   proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0, 0);
00608 
00609   /* Since there was no error, there's no need to finish the thread
00610      states here.  */
00611   discard_cleanups (old_chain);
00612 }
00613 
00614 static void
00615 run_command (char *args, int from_tty)
00616 {
00617   run_command_1 (args, from_tty, 0);
00618 }
00619 
00620 static void
00621 run_no_args_command (char *args, int from_tty)
00622 {
00623   set_inferior_args ("");
00624 }
00625 
00626 
00627 /* Start the execution of the program up until the beginning of the main
00628    program.  */
00629 
00630 static void
00631 start_command (char *args, int from_tty)
00632 {
00633   /* Some languages such as Ada need to search inside the program
00634      minimal symbols for the location where to put the temporary
00635      breakpoint before starting.  */
00636   if (!have_minimal_symbols ())
00637     error (_("No symbol table loaded.  Use the \"file\" command."));
00638 
00639   /* Run the program until reaching the main procedure...  */
00640   run_command_1 (args, from_tty, 1);
00641 } 
00642 
00643 static int
00644 proceed_thread_callback (struct thread_info *thread, void *arg)
00645 {
00646   /* We go through all threads individually instead of compressing
00647      into a single target `resume_all' request, because some threads
00648      may be stopped in internal breakpoints/events, or stopped waiting
00649      for its turn in the displaced stepping queue (that is, they are
00650      running && !executing).  The target side has no idea about why
00651      the thread is stopped, so a `resume_all' command would resume too
00652      much.  If/when GDB gains a way to tell the target `hold this
00653      thread stopped until I say otherwise', then we can optimize
00654      this.  */
00655   if (!is_stopped (thread->ptid))
00656     return 0;
00657 
00658   switch_to_thread (thread->ptid);
00659   clear_proceed_status ();
00660   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
00661   return 0;
00662 }
00663 
00664 static void
00665 ensure_valid_thread (void)
00666 {
00667   if (ptid_equal (inferior_ptid, null_ptid)
00668       || is_exited (inferior_ptid))
00669     error (_("Cannot execute this command without a live selected thread."));
00670 }
00671 
00672 /* If the user is looking at trace frames, any resumption of execution
00673    is likely to mix up recorded and live target data.  So simply
00674    disallow those commands.  */
00675 
00676 static void
00677 ensure_not_tfind_mode (void)
00678 {
00679   if (get_traceframe_number () >= 0)
00680     error (_("Cannot execute this command while looking at trace frames."));
00681 }
00682 
00683 /* Throw an error indicating the current thread is running.  */
00684 
00685 static void
00686 error_is_running (void)
00687 {
00688   error (_("Cannot execute this command while "
00689            "the selected thread is running."));
00690 }
00691 
00692 /* Calls error_is_running if the current thread is running.  */
00693 
00694 static void
00695 ensure_not_running (void)
00696 {
00697   if (is_running (inferior_ptid))
00698     error_is_running ();
00699 }
00700 
00701 void
00702 continue_1 (int all_threads)
00703 {
00704   ERROR_NO_INFERIOR;
00705   ensure_not_tfind_mode ();
00706 
00707   if (non_stop && all_threads)
00708     {
00709       /* Don't error out if the current thread is running, because
00710          there may be other stopped threads.  */
00711       struct cleanup *old_chain;
00712 
00713       /* Backup current thread and selected frame.  */
00714       old_chain = make_cleanup_restore_current_thread ();
00715 
00716       iterate_over_threads (proceed_thread_callback, NULL);
00717 
00718       /* Restore selected ptid.  */
00719       do_cleanups (old_chain);
00720     }
00721   else
00722     {
00723       ensure_valid_thread ();
00724       ensure_not_running ();
00725       clear_proceed_status ();
00726       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
00727     }
00728 }
00729 
00730 /* continue [-a] [proceed-count] [&]  */
00731 static void
00732 continue_command (char *args, int from_tty)
00733 {
00734   int async_exec = 0;
00735   int all_threads = 0;
00736   ERROR_NO_INFERIOR;
00737 
00738   /* Find out whether we must run in the background.  */
00739   if (args != NULL)
00740     async_exec = strip_bg_char (&args);
00741 
00742   /* If we must run in the background, but the target can't do it,
00743      error out.  */
00744   if (async_exec && !target_can_async_p ())
00745     error (_("Asynchronous execution not supported on this target."));
00746 
00747   /* If we are not asked to run in the bg, then prepare to run in the
00748      foreground, synchronously.  */
00749   if (!async_exec && target_can_async_p ())
00750     {
00751       /* Simulate synchronous execution.  */
00752       async_disable_stdin ();
00753     }
00754 
00755   if (args != NULL)
00756     {
00757       if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
00758         {
00759           all_threads = 1;
00760           args += sizeof ("-a") - 1;
00761           if (*args == '\0')
00762             args = NULL;
00763         }
00764     }
00765 
00766   if (!non_stop && all_threads)
00767     error (_("`-a' is meaningless in all-stop mode."));
00768 
00769   if (args != NULL && all_threads)
00770     error (_("Can't resume all threads and specify "
00771              "proceed count simultaneously."));
00772 
00773   /* If we have an argument left, set proceed count of breakpoint we
00774      stopped at.  */
00775   if (args != NULL)
00776     {
00777       bpstat bs = NULL;
00778       int num, stat;
00779       int stopped = 0;
00780       struct thread_info *tp;
00781 
00782       if (non_stop)
00783         tp = find_thread_ptid (inferior_ptid);
00784       else
00785         {
00786           ptid_t last_ptid;
00787           struct target_waitstatus ws;
00788 
00789           get_last_target_status (&last_ptid, &ws);
00790           tp = find_thread_ptid (last_ptid);
00791         }
00792       if (tp != NULL)
00793         bs = tp->control.stop_bpstat;
00794 
00795       while ((stat = bpstat_num (&bs, &num)) != 0)
00796         if (stat > 0)
00797           {
00798             set_ignore_count (num,
00799                               parse_and_eval_long (args) - 1,
00800                               from_tty);
00801             /* set_ignore_count prints a message ending with a period.
00802                So print two spaces before "Continuing.".  */
00803             if (from_tty)
00804               printf_filtered ("  ");
00805             stopped = 1;
00806           }
00807 
00808       if (!stopped && from_tty)
00809         {
00810           printf_filtered
00811             ("Not stopped at any breakpoint; argument ignored.\n");
00812         }
00813     }
00814 
00815   if (from_tty)
00816     printf_filtered (_("Continuing.\n"));
00817 
00818   continue_1 (all_threads);
00819 }
00820 
00821 /* Record the starting point of a "step" or "next" command.  */
00822 
00823 static void
00824 set_step_frame (void)
00825 {
00826   struct symtab_and_line sal;
00827 
00828   find_frame_sal (get_current_frame (), &sal);
00829   set_step_info (get_current_frame (), sal);
00830 }
00831 
00832 /* Step until outside of current statement.  */
00833 
00834 static void
00835 step_command (char *count_string, int from_tty)
00836 {
00837   step_1 (0, 0, count_string);
00838 }
00839 
00840 /* Likewise, but skip over subroutine calls as if single instructions.  */
00841 
00842 static void
00843 next_command (char *count_string, int from_tty)
00844 {
00845   step_1 (1, 0, count_string);
00846 }
00847 
00848 /* Likewise, but step only one instruction.  */
00849 
00850 static void
00851 stepi_command (char *count_string, int from_tty)
00852 {
00853   step_1 (0, 1, count_string);
00854 }
00855 
00856 static void
00857 nexti_command (char *count_string, int from_tty)
00858 {
00859   step_1 (1, 1, count_string);
00860 }
00861 
00862 void
00863 delete_longjmp_breakpoint_cleanup (void *arg)
00864 {
00865   int thread = * (int *) arg;
00866   delete_longjmp_breakpoint (thread);
00867 }
00868 
00869 static void
00870 step_1 (int skip_subroutines, int single_inst, char *count_string)
00871 {
00872   int count = 1;
00873   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
00874   int async_exec = 0;
00875   int thread = -1;
00876 
00877   ERROR_NO_INFERIOR;
00878   ensure_not_tfind_mode ();
00879   ensure_valid_thread ();
00880   ensure_not_running ();
00881 
00882   if (count_string)
00883     async_exec = strip_bg_char (&count_string);
00884 
00885   /* If we get a request for running in the bg but the target
00886      doesn't support it, error out.  */
00887   if (async_exec && !target_can_async_p ())
00888     error (_("Asynchronous execution not supported on this target."));
00889 
00890   /* If we don't get a request of running in the bg, then we need
00891      to simulate synchronous (fg) execution.  */
00892   if (!async_exec && target_can_async_p ())
00893     {
00894       /* Simulate synchronous execution.  */
00895       async_disable_stdin ();
00896     }
00897 
00898   count = count_string ? parse_and_eval_long (count_string) : 1;
00899 
00900   if (!single_inst || skip_subroutines)         /* Leave si command alone.  */
00901     {
00902       struct thread_info *tp = inferior_thread ();
00903 
00904       if (in_thread_list (inferior_ptid))
00905         thread = pid_to_thread_id (inferior_ptid);
00906 
00907       set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));
00908 
00909       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
00910     }
00911 
00912   /* In synchronous case, all is well; each step_once call will step once.  */
00913   if (!target_can_async_p ())
00914     {
00915       for (; count > 0; count--)
00916         {
00917           step_once (skip_subroutines, single_inst, count, thread);
00918 
00919           if (!target_has_execution)
00920             break;
00921           else
00922             {
00923               struct thread_info *tp = inferior_thread ();
00924 
00925               if (!tp->control.stop_step || !tp->step_multi)
00926                 {
00927                   /* If we stopped for some reason that is not stepping
00928                      there are no further steps to make.  */
00929                   tp->step_multi = 0;
00930                   break;
00931                 }
00932             }
00933         }
00934 
00935       do_cleanups (cleanups);
00936     }
00937   else
00938     {
00939       /* In the case of an asynchronous target things get complicated;
00940          do only one step for now, before returning control to the
00941          event loop.  Let the continuation figure out how many other
00942          steps we need to do, and handle them one at the time, through
00943          step_once.  */
00944       step_once (skip_subroutines, single_inst, count, thread);
00945 
00946       /* We are running, and the continuation is installed.  It will
00947          disable the longjmp breakpoint as appropriate.  */
00948       discard_cleanups (cleanups);
00949     }
00950 }
00951 
00952 struct step_1_continuation_args
00953 {
00954   int count;
00955   int skip_subroutines;
00956   int single_inst;
00957   int thread;
00958 };
00959 
00960 /* Called after we are done with one step operation, to check whether
00961    we need to step again, before we print the prompt and return control
00962    to the user.  If count is > 1, we will need to do one more call to
00963    proceed(), via step_once().  Basically it is like step_once and
00964    step_1_continuation are co-recursive.  */
00965 static void
00966 step_1_continuation (void *args, int err)
00967 {
00968   struct step_1_continuation_args *a = args;
00969 
00970   if (target_has_execution)
00971     {
00972       struct thread_info *tp;
00973 
00974       tp = inferior_thread ();
00975       if (!err
00976           && tp->step_multi && tp->control.stop_step)
00977         {
00978           /* There are more steps to make, and we did stop due to
00979              ending a stepping range.  Do another step.  */
00980           step_once (a->skip_subroutines, a->single_inst,
00981                      a->count - 1, a->thread);
00982           return;
00983         }
00984       tp->step_multi = 0;
00985     }
00986 
00987   /* We either hit an error, or stopped for some reason that is
00988      not stepping, or there are no further steps to make.
00989      Cleanup.  */
00990   if (!a->single_inst || a->skip_subroutines)
00991     delete_longjmp_breakpoint (a->thread);
00992 }
00993 
00994 /* Do just one step operation.  This is useful to implement the 'step
00995    n' kind of commands.  In case of asynchronous targets, we will have
00996    to set up a continuation to be done after the target stops (after
00997    this one step).  For synch targets, the caller handles further
00998    stepping.  */
00999 
01000 static void
01001 step_once (int skip_subroutines, int single_inst, int count, int thread)
01002 {
01003   struct frame_info *frame = get_current_frame ();
01004 
01005   if (count > 0)
01006     {
01007       /* Don't assume THREAD is a valid thread id.  It is set to -1 if
01008          the longjmp breakpoint was not required.  Use the
01009          INFERIOR_PTID thread instead, which is the same thread when
01010          THREAD is set.  */
01011       struct thread_info *tp = inferior_thread ();
01012 
01013       clear_proceed_status ();
01014       set_step_frame ();
01015 
01016       if (!single_inst)
01017         {
01018           CORE_ADDR pc;
01019 
01020           /* Step at an inlined function behaves like "down".  */
01021           if (!skip_subroutines
01022               && inline_skipped_frames (inferior_ptid))
01023             {
01024               ptid_t resume_ptid;
01025 
01026               /* Pretend that we've ran.  */
01027               resume_ptid = user_visible_resume_ptid (1);
01028               set_running (resume_ptid, 1);
01029 
01030               step_into_inline_frame (inferior_ptid);
01031               if (count > 1)
01032                 step_once (skip_subroutines, single_inst, count - 1, thread);
01033               else
01034                 {
01035                   /* Pretend that we've stopped.  */
01036                   normal_stop ();
01037 
01038                   if (target_can_async_p ())
01039                     inferior_event_handler (INF_EXEC_COMPLETE, NULL);
01040                 }
01041               return;
01042             }
01043 
01044           pc = get_frame_pc (frame);
01045           find_pc_line_pc_range (pc,
01046                                  &tp->control.step_range_start,
01047                                  &tp->control.step_range_end);
01048 
01049           tp->control.may_range_step = 1;
01050 
01051           /* If we have no line info, switch to stepi mode.  */
01052           if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
01053             {
01054               tp->control.step_range_start = tp->control.step_range_end = 1;
01055               tp->control.may_range_step = 0;
01056             }
01057           else if (tp->control.step_range_end == 0)
01058             {
01059               const char *name;
01060 
01061               if (find_pc_partial_function (pc, &name,
01062                                             &tp->control.step_range_start,
01063                                             &tp->control.step_range_end) == 0)
01064                 error (_("Cannot find bounds of current function"));
01065 
01066               target_terminal_ours ();
01067               printf_filtered (_("Single stepping until exit from function %s,"
01068                                  "\nwhich has no line number information.\n"),
01069                                name);
01070             }
01071         }
01072       else
01073         {
01074           /* Say we are stepping, but stop after one insn whatever it does.  */
01075           tp->control.step_range_start = tp->control.step_range_end = 1;
01076           if (!skip_subroutines)
01077             /* It is stepi.
01078                Don't step over function calls, not even to functions lacking
01079                line numbers.  */
01080             tp->control.step_over_calls = STEP_OVER_NONE;
01081         }
01082 
01083       if (skip_subroutines)
01084         tp->control.step_over_calls = STEP_OVER_ALL;
01085 
01086       tp->step_multi = (count > 1);
01087       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
01088 
01089       /* For async targets, register a continuation to do any
01090          additional steps.  For sync targets, the caller will handle
01091          further stepping.  */
01092       if (target_can_async_p ())
01093         {
01094           struct step_1_continuation_args *args;
01095 
01096           args = xmalloc (sizeof (*args));
01097           args->skip_subroutines = skip_subroutines;
01098           args->single_inst = single_inst;
01099           args->count = count;
01100           args->thread = thread;
01101 
01102           add_intermediate_continuation (tp, step_1_continuation, args, xfree);
01103         }
01104     }
01105 }
01106 
01107 
01108 /* Continue program at specified address.  */
01109 
01110 static void
01111 jump_command (char *arg, int from_tty)
01112 {
01113   struct gdbarch *gdbarch = get_current_arch ();
01114   CORE_ADDR addr;
01115   struct symtabs_and_lines sals;
01116   struct symtab_and_line sal;
01117   struct symbol *fn;
01118   struct symbol *sfn;
01119   int async_exec = 0;
01120 
01121   ERROR_NO_INFERIOR;
01122   ensure_not_tfind_mode ();
01123   ensure_valid_thread ();
01124   ensure_not_running ();
01125 
01126   /* Find out whether we must run in the background.  */
01127   if (arg != NULL)
01128     async_exec = strip_bg_char (&arg);
01129 
01130   /* If we must run in the background, but the target can't do it,
01131      error out.  */
01132   if (async_exec && !target_can_async_p ())
01133     error (_("Asynchronous execution not supported on this target."));
01134 
01135   if (!arg)
01136     error_no_arg (_("starting address"));
01137 
01138   sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
01139   if (sals.nelts != 1)
01140     {
01141       error (_("Unreasonable jump request"));
01142     }
01143 
01144   sal = sals.sals[0];
01145   xfree (sals.sals);
01146 
01147   if (sal.symtab == 0 && sal.pc == 0)
01148     error (_("No source file has been specified."));
01149 
01150   resolve_sal_pc (&sal);        /* May error out.  */
01151 
01152   /* See if we are trying to jump to another function.  */
01153   fn = get_frame_function (get_current_frame ());
01154   sfn = find_pc_function (sal.pc);
01155   if (fn != NULL && sfn != fn)
01156     {
01157       if (!query (_("Line %d is not in `%s'.  Jump anyway? "), sal.line,
01158                   SYMBOL_PRINT_NAME (fn)))
01159         {
01160           error (_("Not confirmed."));
01161           /* NOTREACHED */
01162         }
01163     }
01164 
01165   if (sfn != NULL)
01166     {
01167       fixup_symbol_section (sfn, 0);
01168       if (section_is_overlay (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn), sfn)) &&
01169           !section_is_mapped (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn), sfn)))
01170         {
01171           if (!query (_("WARNING!!!  Destination is in "
01172                         "unmapped overlay!  Jump anyway? ")))
01173             {
01174               error (_("Not confirmed."));
01175               /* NOTREACHED */
01176             }
01177         }
01178     }
01179 
01180   addr = sal.pc;
01181 
01182   if (from_tty)
01183     {
01184       printf_filtered (_("Continuing at "));
01185       fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
01186       printf_filtered (".\n");
01187     }
01188 
01189   /* If we are not asked to run in the bg, then prepare to run in the
01190      foreground, synchronously.  */
01191   if (!async_exec && target_can_async_p ())
01192     {
01193       /* Simulate synchronous execution.  */
01194       async_disable_stdin ();
01195     }
01196 
01197   clear_proceed_status ();
01198   proceed (addr, GDB_SIGNAL_0, 0);
01199 }
01200 
01201 
01202 /* Go to line or address in current procedure.  */
01203 static void
01204 go_command (char *line_no, int from_tty)
01205 {
01206   if (line_no == (char *) NULL || !*line_no)
01207     printf_filtered (_("Usage: go <location>\n"));
01208   else
01209     {
01210       tbreak_command (line_no, from_tty);
01211       jump_command (line_no, from_tty);
01212     }
01213 }
01214 
01215 
01216 /* Continue program giving it specified signal.  */
01217 
01218 static void
01219 signal_command (char *signum_exp, int from_tty)
01220 {
01221   enum gdb_signal oursig;
01222   int async_exec = 0;
01223 
01224   dont_repeat ();               /* Too dangerous.  */
01225   ERROR_NO_INFERIOR;
01226   ensure_not_tfind_mode ();
01227   ensure_valid_thread ();
01228   ensure_not_running ();
01229 
01230   /* Find out whether we must run in the background.  */
01231   if (signum_exp != NULL)
01232     async_exec = strip_bg_char (&signum_exp);
01233 
01234   /* If we must run in the background, but the target can't do it,
01235      error out.  */
01236   if (async_exec && !target_can_async_p ())
01237     error (_("Asynchronous execution not supported on this target."));
01238 
01239   /* If we are not asked to run in the bg, then prepare to run in the
01240      foreground, synchronously.  */
01241   if (!async_exec && target_can_async_p ())
01242     {
01243       /* Simulate synchronous execution.  */
01244       async_disable_stdin ();
01245     }
01246 
01247   if (!signum_exp)
01248     error_no_arg (_("signal number"));
01249 
01250   /* It would be even slicker to make signal names be valid expressions,
01251      (the type could be "enum $signal" or some such), then the user could
01252      assign them to convenience variables.  */
01253   oursig = gdb_signal_from_name (signum_exp);
01254 
01255   if (oursig == GDB_SIGNAL_UNKNOWN)
01256     {
01257       /* No, try numeric.  */
01258       int num = parse_and_eval_long (signum_exp);
01259 
01260       if (num == 0)
01261         oursig = GDB_SIGNAL_0;
01262       else
01263         oursig = gdb_signal_from_command (num);
01264     }
01265 
01266   if (from_tty)
01267     {
01268       if (oursig == GDB_SIGNAL_0)
01269         printf_filtered (_("Continuing with no signal.\n"));
01270       else
01271         printf_filtered (_("Continuing with signal %s.\n"),
01272                          gdb_signal_to_name (oursig));
01273     }
01274 
01275   clear_proceed_status ();
01276   proceed ((CORE_ADDR) -1, oursig, 0);
01277 }
01278 
01279 /* Continuation args to be passed to the "until" command
01280    continuation.  */
01281 struct until_next_continuation_args
01282 {
01283   /* The thread that was current when the command was executed.  */
01284   int thread;
01285 };
01286 
01287 /* A continuation callback for until_next_command.  */
01288 
01289 static void
01290 until_next_continuation (void *arg, int err)
01291 {
01292   struct until_next_continuation_args *a = arg;
01293 
01294   delete_longjmp_breakpoint (a->thread);
01295 }
01296 
01297 /* Proceed until we reach a different source line with pc greater than
01298    our current one or exit the function.  We skip calls in both cases.
01299 
01300    Note that eventually this command should probably be changed so
01301    that only source lines are printed out when we hit the breakpoint
01302    we set.  This may involve changes to wait_for_inferior and the
01303    proceed status code.  */
01304 
01305 static void
01306 until_next_command (int from_tty)
01307 {
01308   struct frame_info *frame;
01309   CORE_ADDR pc;
01310   struct symbol *func;
01311   struct symtab_and_line sal;
01312   struct thread_info *tp = inferior_thread ();
01313   int thread = tp->num;
01314   struct cleanup *old_chain;
01315 
01316   clear_proceed_status ();
01317   set_step_frame ();
01318 
01319   frame = get_current_frame ();
01320 
01321   /* Step until either exited from this function or greater
01322      than the current line (if in symbolic section) or pc (if
01323      not).  */
01324 
01325   pc = get_frame_pc (frame);
01326   func = find_pc_function (pc);
01327 
01328   if (!func)
01329     {
01330       struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
01331 
01332       if (msymbol.minsym == NULL)
01333         error (_("Execution is not within a known function."));
01334 
01335       tp->control.step_range_start = SYMBOL_VALUE_ADDRESS (msymbol.minsym);
01336       tp->control.step_range_end = pc;
01337     }
01338   else
01339     {
01340       sal = find_pc_line (pc, 0);
01341 
01342       tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
01343       tp->control.step_range_end = sal.end;
01344     }
01345   tp->control.may_range_step = 1;
01346 
01347   tp->control.step_over_calls = STEP_OVER_ALL;
01348 
01349   tp->step_multi = 0;           /* Only one call to proceed */
01350 
01351   set_longjmp_breakpoint (tp, get_frame_id (frame));
01352   old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
01353 
01354   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
01355 
01356   if (target_can_async_p () && is_running (inferior_ptid))
01357     {
01358       struct until_next_continuation_args *cont_args;
01359 
01360       discard_cleanups (old_chain);
01361       cont_args = XNEW (struct until_next_continuation_args);
01362       cont_args->thread = inferior_thread ()->num;
01363 
01364       add_continuation (tp, until_next_continuation, cont_args, xfree);
01365     }
01366   else
01367     do_cleanups (old_chain);
01368 }
01369 
01370 static void
01371 until_command (char *arg, int from_tty)
01372 {
01373   int async_exec = 0;
01374 
01375   ERROR_NO_INFERIOR;
01376   ensure_not_tfind_mode ();
01377   ensure_valid_thread ();
01378   ensure_not_running ();
01379 
01380   /* Find out whether we must run in the background.  */
01381   if (arg != NULL)
01382     async_exec = strip_bg_char (&arg);
01383 
01384   /* If we must run in the background, but the target can't do it,
01385      error out.  */
01386   if (async_exec && !target_can_async_p ())
01387     error (_("Asynchronous execution not supported on this target."));
01388 
01389   /* If we are not asked to run in the bg, then prepare to run in the
01390      foreground, synchronously.  */
01391   if (!async_exec && target_can_async_p ())
01392     {
01393       /* Simulate synchronous execution.  */
01394       async_disable_stdin ();
01395     }
01396 
01397   if (arg)
01398     until_break_command (arg, from_tty, 0);
01399   else
01400     until_next_command (from_tty);
01401 }
01402 
01403 static void
01404 advance_command (char *arg, int from_tty)
01405 {
01406   int async_exec = 0;
01407 
01408   ERROR_NO_INFERIOR;
01409   ensure_not_tfind_mode ();
01410   ensure_valid_thread ();
01411   ensure_not_running ();
01412 
01413   if (arg == NULL)
01414     error_no_arg (_("a location"));
01415 
01416   /* Find out whether we must run in the background.  */
01417   if (arg != NULL)
01418     async_exec = strip_bg_char (&arg);
01419 
01420   /* If we must run in the background, but the target can't do it,
01421      error out.  */
01422   if (async_exec && !target_can_async_p ())
01423     error (_("Asynchronous execution not supported on this target."));
01424 
01425   /* If we are not asked to run in the bg, then prepare to run in the
01426      foreground, synchronously.  */
01427   if (!async_exec && target_can_async_p ())
01428     {
01429       /* Simulate synchronous execution.  */
01430       async_disable_stdin ();
01431     }
01432 
01433   until_break_command (arg, from_tty, 1);
01434 }
01435 
01436 /* Return the value of the result of a function at the end of a 'finish'
01437    command/BP.  */
01438 
01439 struct value *
01440 get_return_value (struct value *function, struct type *value_type)
01441 {
01442   struct regcache *stop_regs = stop_registers;
01443   struct gdbarch *gdbarch;
01444   struct value *value;
01445   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
01446 
01447   /* If stop_registers were not saved, use the current registers.  */
01448   if (!stop_regs)
01449     {
01450       stop_regs = regcache_dup (get_current_regcache ());
01451       make_cleanup_regcache_xfree (stop_regs);
01452     }
01453 
01454   gdbarch = get_regcache_arch (stop_regs);
01455 
01456   CHECK_TYPEDEF (value_type);
01457   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
01458 
01459   /* FIXME: 2003-09-27: When returning from a nested inferior function
01460      call, it's possible (with no help from the architecture vector)
01461      to locate and return/print a "struct return" value.  This is just
01462      a more complicated case of what is already being done in the
01463      inferior function call code.  In fact, when inferior function
01464      calls are made async, this will likely be made the norm.  */
01465 
01466   switch (gdbarch_return_value (gdbarch, function, value_type,
01467                                 NULL, NULL, NULL))
01468     {
01469     case RETURN_VALUE_REGISTER_CONVENTION:
01470     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
01471     case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
01472       value = allocate_value (value_type);
01473       gdbarch_return_value (gdbarch, function, value_type, stop_regs,
01474                             value_contents_raw (value), NULL);
01475       break;
01476     case RETURN_VALUE_STRUCT_CONVENTION:
01477       value = NULL;
01478       break;
01479     default:
01480       internal_error (__FILE__, __LINE__, _("bad switch"));
01481     }
01482 
01483   do_cleanups (cleanup);
01484 
01485   return value;
01486 }
01487 
01488 /* Print the result of a function at the end of a 'finish' command.  */
01489 
01490 static void
01491 print_return_value (struct value *function, struct type *value_type)
01492 {
01493   struct value *value = get_return_value (function, value_type);
01494   struct ui_out *uiout = current_uiout;
01495 
01496   if (value)
01497     {
01498       struct value_print_options opts;
01499       struct ui_file *stb;
01500       struct cleanup *old_chain;
01501 
01502       /* Print it.  */
01503       stb = mem_fileopen ();
01504       old_chain = make_cleanup_ui_file_delete (stb);
01505       ui_out_text (uiout, "Value returned is ");
01506       ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
01507                         record_latest_value (value));
01508       ui_out_text (uiout, " = ");
01509       get_no_prettyformat_print_options (&opts);
01510       value_print (value, stb, &opts);
01511       ui_out_field_stream (uiout, "return-value", stb);
01512       ui_out_text (uiout, "\n");
01513       do_cleanups (old_chain);
01514     }
01515   else
01516     {
01517       ui_out_text (uiout, "Value returned has type: ");
01518       ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
01519       ui_out_text (uiout, ".");
01520       ui_out_text (uiout, " Cannot determine contents\n");
01521     }
01522 }
01523 
01524 /* Stuff that needs to be done by the finish command after the target
01525    has stopped.  In asynchronous mode, we wait for the target to stop
01526    in the call to poll or select in the event loop, so it is
01527    impossible to do all the stuff as part of the finish_command
01528    function itself.  The only chance we have to complete this command
01529    is in fetch_inferior_event, which is called by the event loop as
01530    soon as it detects that the target has stopped.  */
01531 
01532 struct finish_command_continuation_args
01533 {
01534   /* The thread that as current when the command was executed.  */
01535   int thread;
01536   struct breakpoint *breakpoint;
01537   struct symbol *function;
01538 };
01539 
01540 static void
01541 finish_command_continuation (void *arg, int err)
01542 {
01543   struct finish_command_continuation_args *a = arg;
01544 
01545   if (!err)
01546     {
01547       struct thread_info *tp = NULL;
01548       bpstat bs = NULL;
01549 
01550       if (!ptid_equal (inferior_ptid, null_ptid)
01551           && target_has_execution
01552           && is_stopped (inferior_ptid))
01553         {
01554           tp = inferior_thread ();
01555           bs = tp->control.stop_bpstat;
01556         }
01557 
01558       if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
01559           && a->function != NULL)
01560         {
01561           struct type *value_type;
01562 
01563           value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
01564           if (!value_type)
01565             internal_error (__FILE__, __LINE__,
01566                             _("finish_command: function has no target type"));
01567 
01568           if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
01569             {
01570               volatile struct gdb_exception ex;
01571               struct value *func;
01572 
01573               func = read_var_value (a->function, get_current_frame ());
01574               TRY_CATCH (ex, RETURN_MASK_ALL)
01575                 {
01576                   /* print_return_value can throw an exception in some
01577                      circumstances.  We need to catch this so that we still
01578                      delete the breakpoint.  */
01579                   print_return_value (func, value_type);
01580                 }
01581               if (ex.reason < 0)
01582                 exception_print (gdb_stdout, ex);
01583             }
01584         }
01585 
01586       /* We suppress normal call of normal_stop observer and do it
01587          here so that the *stopped notification includes the return
01588          value.  */
01589       if (bs != NULL && tp->control.proceed_to_finish)
01590         observer_notify_normal_stop (bs, 1 /* print frame */);
01591     }
01592 
01593   delete_breakpoint (a->breakpoint);
01594   delete_longjmp_breakpoint (a->thread);
01595 }
01596 
01597 static void
01598 finish_command_continuation_free_arg (void *arg)
01599 {
01600   xfree (arg);
01601 }
01602 
01603 /* finish_backward -- helper function for finish_command.  */
01604 
01605 static void
01606 finish_backward (struct symbol *function)
01607 {
01608   struct symtab_and_line sal;
01609   struct thread_info *tp = inferior_thread ();
01610   CORE_ADDR pc;
01611   CORE_ADDR func_addr;
01612 
01613   pc = get_frame_pc (get_current_frame ());
01614 
01615   if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
01616     internal_error (__FILE__, __LINE__,
01617                     _("Finish: couldn't find function."));
01618 
01619   sal = find_pc_line (func_addr, 0);
01620 
01621   tp->control.proceed_to_finish = 1;
01622   /* Special case: if we're sitting at the function entry point,
01623      then all we need to do is take a reverse singlestep.  We
01624      don't need to set a breakpoint, and indeed it would do us
01625      no good to do so.
01626 
01627      Note that this can only happen at frame #0, since there's
01628      no way that a function up the stack can have a return address
01629      that's equal to its entry point.  */
01630 
01631   if (sal.pc != pc)
01632     {
01633       struct frame_info *frame = get_selected_frame (NULL);
01634       struct gdbarch *gdbarch = get_frame_arch (frame);
01635       struct symtab_and_line sr_sal;
01636 
01637       /* Set a step-resume at the function's entry point.  Once that's
01638          hit, we'll do one more step backwards.  */
01639       init_sal (&sr_sal);
01640       sr_sal.pc = sal.pc;
01641       sr_sal.pspace = get_frame_program_space (frame);
01642       insert_step_resume_breakpoint_at_sal (gdbarch,
01643                                             sr_sal, null_frame_id);
01644 
01645       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
01646     }
01647   else
01648     {
01649       /* We're almost there -- we just need to back up by one more
01650          single-step.  */
01651       tp->control.step_range_start = tp->control.step_range_end = 1;
01652       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
01653     }
01654 }
01655 
01656 /* finish_forward -- helper function for finish_command.  */
01657 
01658 static void
01659 finish_forward (struct symbol *function, struct frame_info *frame)
01660 {
01661   struct frame_id frame_id = get_frame_id (frame);
01662   struct gdbarch *gdbarch = get_frame_arch (frame);
01663   struct symtab_and_line sal;
01664   struct thread_info *tp = inferior_thread ();
01665   struct breakpoint *breakpoint;
01666   struct cleanup *old_chain;
01667   struct finish_command_continuation_args *cargs;
01668   int thread = tp->num;
01669 
01670   sal = find_pc_line (get_frame_pc (frame), 0);
01671   sal.pc = get_frame_pc (frame);
01672 
01673   breakpoint = set_momentary_breakpoint (gdbarch, sal,
01674                                          get_stack_frame_id (frame),
01675                                          bp_finish);
01676 
01677   /* set_momentary_breakpoint invalidates FRAME.  */
01678   frame = NULL;
01679 
01680   old_chain = make_cleanup_delete_breakpoint (breakpoint);
01681 
01682   set_longjmp_breakpoint (tp, frame_id);
01683   make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
01684 
01685   /* We want stop_registers, please...  */
01686   tp->control.proceed_to_finish = 1;
01687   cargs = xmalloc (sizeof (*cargs));
01688 
01689   cargs->thread = thread;
01690   cargs->breakpoint = breakpoint;
01691   cargs->function = function;
01692   add_continuation (tp, finish_command_continuation, cargs,
01693                     finish_command_continuation_free_arg);
01694   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
01695 
01696   discard_cleanups (old_chain);
01697   if (!target_can_async_p ())
01698     do_all_continuations (0);
01699 }
01700 
01701 /* "finish": Set a temporary breakpoint at the place the selected
01702    frame will return to, then continue.  */
01703 
01704 static void
01705 finish_command (char *arg, int from_tty)
01706 {
01707   struct frame_info *frame;
01708   struct symbol *function;
01709 
01710   int async_exec = 0;
01711 
01712   ERROR_NO_INFERIOR;
01713   ensure_not_tfind_mode ();
01714   ensure_valid_thread ();
01715   ensure_not_running ();
01716 
01717   /* Find out whether we must run in the background.  */
01718   if (arg != NULL)
01719     async_exec = strip_bg_char (&arg);
01720 
01721   /* If we must run in the background, but the target can't do it,
01722      error out.  */
01723   if (async_exec && !target_can_async_p ())
01724     error (_("Asynchronous execution not supported on this target."));
01725 
01726   /* If we are not asked to run in the bg, then prepare to run in the
01727      foreground, synchronously.  */
01728   if (!async_exec && target_can_async_p ())
01729     {
01730       /* Simulate synchronous execution.  */
01731       async_disable_stdin ();
01732     }
01733 
01734   if (arg)
01735     error (_("The \"finish\" command does not take any arguments."));
01736 
01737   frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
01738   if (frame == 0)
01739     error (_("\"finish\" not meaningful in the outermost frame."));
01740 
01741   clear_proceed_status ();
01742 
01743   /* Finishing from an inline frame is completely different.  We don't
01744      try to show the "return value" - no way to locate it.  So we do
01745      not need a completion.  */
01746   if (get_frame_type (get_selected_frame (_("No selected frame.")))
01747       == INLINE_FRAME)
01748     {
01749       /* Claim we are stepping in the calling frame.  An empty step
01750          range means that we will stop once we aren't in a function
01751          called by that frame.  We don't use the magic "1" value for
01752          step_range_end, because then infrun will think this is nexti,
01753          and not step over the rest of this inlined function call.  */
01754       struct thread_info *tp = inferior_thread ();
01755       struct symtab_and_line empty_sal;
01756 
01757       init_sal (&empty_sal);
01758       set_step_info (frame, empty_sal);
01759       tp->control.step_range_start = get_frame_pc (frame);
01760       tp->control.step_range_end = tp->control.step_range_start;
01761       tp->control.step_over_calls = STEP_OVER_ALL;
01762 
01763       /* Print info on the selected frame, including level number but not
01764          source.  */
01765       if (from_tty)
01766         {
01767           printf_filtered (_("Run till exit from "));
01768           print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
01769         }
01770 
01771       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
01772       return;
01773     }
01774 
01775   /* Ignore TAILCALL_FRAME type frames, they were executed already before
01776      entering THISFRAME.  */
01777   while (get_frame_type (frame) == TAILCALL_FRAME)
01778     frame = get_prev_frame (frame);
01779 
01780   /* Find the function we will return from.  */
01781 
01782   function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
01783 
01784   /* Print info on the selected frame, including level number but not
01785      source.  */
01786   if (from_tty)
01787     {
01788       if (execution_direction == EXEC_REVERSE)
01789         printf_filtered (_("Run back to call of "));
01790       else
01791         printf_filtered (_("Run till exit from "));
01792 
01793       print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
01794     }
01795 
01796   if (execution_direction == EXEC_REVERSE)
01797     finish_backward (function);
01798   else
01799     finish_forward (function, frame);
01800 }
01801 
01802 
01803 static void
01804 program_info (char *args, int from_tty)
01805 {
01806   bpstat bs;
01807   int num, stat;
01808   struct thread_info *tp;
01809   ptid_t ptid;
01810 
01811   if (!target_has_execution)
01812     {
01813       printf_filtered (_("The program being debugged is not being run.\n"));
01814       return;
01815     }
01816 
01817   if (non_stop)
01818     ptid = inferior_ptid;
01819   else
01820     {
01821       struct target_waitstatus ws;
01822 
01823       get_last_target_status (&ptid, &ws);
01824     }
01825 
01826   if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
01827     error (_("Invalid selected thread."));
01828   else if (is_running (ptid))
01829     error (_("Selected thread is running."));
01830 
01831   tp = find_thread_ptid (ptid);
01832   bs = tp->control.stop_bpstat;
01833   stat = bpstat_num (&bs, &num);
01834 
01835   target_files_info ();
01836   printf_filtered (_("Program stopped at %s.\n"),
01837                    paddress (target_gdbarch (), stop_pc));
01838   if (tp->control.stop_step)
01839     printf_filtered (_("It stopped after being stepped.\n"));
01840   else if (stat != 0)
01841     {
01842       /* There may be several breakpoints in the same place, so this
01843          isn't as strange as it seems.  */
01844       while (stat != 0)
01845         {
01846           if (stat < 0)
01847             {
01848               printf_filtered (_("It stopped at a breakpoint "
01849                                  "that has since been deleted.\n"));
01850             }
01851           else
01852             printf_filtered (_("It stopped at breakpoint %d.\n"), num);
01853           stat = bpstat_num (&bs, &num);
01854         }
01855     }
01856   else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
01857     {
01858       printf_filtered (_("It stopped with signal %s, %s.\n"),
01859                        gdb_signal_to_name (tp->suspend.stop_signal),
01860                        gdb_signal_to_string (tp->suspend.stop_signal));
01861     }
01862 
01863   if (!from_tty)
01864     {
01865       printf_filtered (_("Type \"info stack\" or \"info "
01866                          "registers\" for more information.\n"));
01867     }
01868 }
01869 
01870 static void
01871 environment_info (char *var, int from_tty)
01872 {
01873   if (var)
01874     {
01875       char *val = get_in_environ (current_inferior ()->environment, var);
01876 
01877       if (val)
01878         {
01879           puts_filtered (var);
01880           puts_filtered (" = ");
01881           puts_filtered (val);
01882           puts_filtered ("\n");
01883         }
01884       else
01885         {
01886           puts_filtered ("Environment variable \"");
01887           puts_filtered (var);
01888           puts_filtered ("\" not defined.\n");
01889         }
01890     }
01891   else
01892     {
01893       char **vector = environ_vector (current_inferior ()->environment);
01894 
01895       while (*vector)
01896         {
01897           puts_filtered (*vector++);
01898           puts_filtered ("\n");
01899         }
01900     }
01901 }
01902 
01903 static void
01904 set_environment_command (char *arg, int from_tty)
01905 {
01906   char *p, *val, *var;
01907   int nullset = 0;
01908 
01909   if (arg == 0)
01910     error_no_arg (_("environment variable and value"));
01911 
01912   /* Find seperation between variable name and value.  */
01913   p = (char *) strchr (arg, '=');
01914   val = (char *) strchr (arg, ' ');
01915 
01916   if (p != 0 && val != 0)
01917     {
01918       /* We have both a space and an equals.  If the space is before the
01919          equals, walk forward over the spaces til we see a nonspace 
01920          (possibly the equals).  */
01921       if (p > val)
01922         while (*val == ' ')
01923           val++;
01924 
01925       /* Now if the = is after the char following the spaces,
01926          take the char following the spaces.  */
01927       if (p > val)
01928         p = val - 1;
01929     }
01930   else if (val != 0 && p == 0)
01931     p = val;
01932 
01933   if (p == arg)
01934     error_no_arg (_("environment variable to set"));
01935 
01936   if (p == 0 || p[1] == 0)
01937     {
01938       nullset = 1;
01939       if (p == 0)
01940         p = arg + strlen (arg); /* So that savestring below will work.  */
01941     }
01942   else
01943     {
01944       /* Not setting variable value to null.  */
01945       val = p + 1;
01946       while (*val == ' ' || *val == '\t')
01947         val++;
01948     }
01949 
01950   while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
01951     p--;
01952 
01953   var = savestring (arg, p - arg);
01954   if (nullset)
01955     {
01956       printf_filtered (_("Setting environment variable "
01957                          "\"%s\" to null value.\n"),
01958                        var);
01959       set_in_environ (current_inferior ()->environment, var, "");
01960     }
01961   else
01962     set_in_environ (current_inferior ()->environment, var, val);
01963   xfree (var);
01964 }
01965 
01966 static void
01967 unset_environment_command (char *var, int from_tty)
01968 {
01969   if (var == 0)
01970     {
01971       /* If there is no argument, delete all environment variables.
01972          Ask for confirmation if reading from the terminal.  */
01973       if (!from_tty || query (_("Delete all environment variables? ")))
01974         {
01975           free_environ (current_inferior ()->environment);
01976           current_inferior ()->environment = make_environ ();
01977         }
01978     }
01979   else
01980     unset_in_environ (current_inferior ()->environment, var);
01981 }
01982 
01983 /* Handle the execution path (PATH variable).  */
01984 
01985 static const char path_var_name[] = "PATH";
01986 
01987 static void
01988 path_info (char *args, int from_tty)
01989 {
01990   puts_filtered ("Executable and object file path: ");
01991   puts_filtered (get_in_environ (current_inferior ()->environment,
01992                                  path_var_name));
01993   puts_filtered ("\n");
01994 }
01995 
01996 /* Add zero or more directories to the front of the execution path.  */
01997 
01998 static void
01999 path_command (char *dirname, int from_tty)
02000 {
02001   char *exec_path;
02002   char *env;
02003 
02004   dont_repeat ();
02005   env = get_in_environ (current_inferior ()->environment, path_var_name);
02006   /* Can be null if path is not set.  */
02007   if (!env)
02008     env = "";
02009   exec_path = xstrdup (env);
02010   mod_path (dirname, &exec_path);
02011   set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
02012   xfree (exec_path);
02013   if (from_tty)
02014     path_info ((char *) NULL, from_tty);
02015 }
02016 
02017 
02018 /* Print out the register NAME with value VAL, to FILE, in the default
02019    fashion.  */
02020 
02021 static void
02022 default_print_one_register_info (struct ui_file *file,
02023                                  const char *name,
02024                                  struct value *val)
02025 {
02026   struct type *regtype = value_type (val);
02027 
02028   fputs_filtered (name, file);
02029   print_spaces_filtered (15 - strlen (name), file);
02030 
02031   if (!value_entirely_available (val))
02032     {
02033       fprintf_filtered (file, "*value not available*\n");
02034       return;
02035     }
02036   else if (value_optimized_out (val))
02037     {
02038       val_print_optimized_out (val, file);
02039       fprintf_filtered (file, "\n");
02040       return;
02041     }
02042 
02043   /* If virtual format is floating, print it that way, and in raw
02044      hex.  */
02045   if (TYPE_CODE (regtype) == TYPE_CODE_FLT
02046       || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
02047     {
02048       int j;
02049       struct value_print_options opts;
02050       const gdb_byte *valaddr = value_contents_for_printing (val);
02051       enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
02052 
02053       get_user_print_options (&opts);
02054       opts.deref_ref = 1;
02055 
02056       val_print (regtype,
02057                  value_contents_for_printing (val),
02058                  value_embedded_offset (val), 0,
02059                  file, 0, val, &opts, current_language);
02060 
02061       fprintf_filtered (file, "\t(raw ");
02062       print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
02063       fprintf_filtered (file, ")");
02064     }
02065   else
02066     {
02067       struct value_print_options opts;
02068 
02069       /* Print the register in hex.  */
02070       get_formatted_print_options (&opts, 'x');
02071       opts.deref_ref = 1;
02072       val_print (regtype,
02073                  value_contents_for_printing (val),
02074                  value_embedded_offset (val), 0,
02075                  file, 0, val, &opts, current_language);
02076       /* If not a vector register, print it also according to its
02077          natural format.  */
02078       if (TYPE_VECTOR (regtype) == 0)
02079         {
02080           get_user_print_options (&opts);
02081           opts.deref_ref = 1;
02082           fprintf_filtered (file, "\t");
02083           val_print (regtype,
02084                      value_contents_for_printing (val),
02085                      value_embedded_offset (val), 0,
02086                      file, 0, val, &opts, current_language);
02087         }
02088     }
02089 
02090   fprintf_filtered (file, "\n");
02091 }
02092 
02093 /* Print out the machine register regnum.  If regnum is -1, print all
02094    registers (print_all == 1) or all non-float and non-vector
02095    registers (print_all == 0).
02096 
02097    For most machines, having all_registers_info() print the
02098    register(s) one per line is good enough.  If a different format is
02099    required, (eg, for MIPS or Pyramid 90x, which both have lots of
02100    regs), or there is an existing convention for showing all the
02101    registers, define the architecture method PRINT_REGISTERS_INFO to
02102    provide that format.  */
02103 
02104 void
02105 default_print_registers_info (struct gdbarch *gdbarch,
02106                               struct ui_file *file,
02107                               struct frame_info *frame,
02108                               int regnum, int print_all)
02109 {
02110   int i;
02111   const int numregs = gdbarch_num_regs (gdbarch)
02112                       + gdbarch_num_pseudo_regs (gdbarch);
02113 
02114   for (i = 0; i < numregs; i++)
02115     {
02116       /* Decide between printing all regs, non-float / vector regs, or
02117          specific reg.  */
02118       if (regnum == -1)
02119         {
02120           if (print_all)
02121             {
02122               if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
02123                 continue;
02124             }
02125           else
02126             {
02127               if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
02128                 continue;
02129             }
02130         }
02131       else
02132         {
02133           if (i != regnum)
02134             continue;
02135         }
02136 
02137       /* If the register name is empty, it is undefined for this
02138          processor, so don't display anything.  */
02139       if (gdbarch_register_name (gdbarch, i) == NULL
02140           || *(gdbarch_register_name (gdbarch, i)) == '\0')
02141         continue;
02142 
02143       default_print_one_register_info (file,
02144                                        gdbarch_register_name (gdbarch, i),
02145                                        value_of_register (i, frame));
02146     }
02147 }
02148 
02149 void
02150 registers_info (char *addr_exp, int fpregs)
02151 {
02152   struct frame_info *frame;
02153   struct gdbarch *gdbarch;
02154 
02155   if (!target_has_registers)
02156     error (_("The program has no registers now."));
02157   frame = get_selected_frame (NULL);
02158   gdbarch = get_frame_arch (frame);
02159 
02160   if (!addr_exp)
02161     {
02162       gdbarch_print_registers_info (gdbarch, gdb_stdout,
02163                                     frame, -1, fpregs);
02164       return;
02165     }
02166 
02167   while (*addr_exp != '\0')
02168     {
02169       char *start;
02170       const char *end;
02171 
02172       /* Skip leading white space.  */
02173       addr_exp = skip_spaces (addr_exp);
02174 
02175       /* Discard any leading ``$''.  Check that there is something
02176          resembling a register following it.  */
02177       if (addr_exp[0] == '$')
02178         addr_exp++;
02179       if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
02180         error (_("Missing register name"));
02181 
02182       /* Find the start/end of this register name/num/group.  */
02183       start = addr_exp;
02184       while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
02185         addr_exp++;
02186       end = addr_exp;
02187 
02188       /* Figure out what we've found and display it.  */
02189 
02190       /* A register name?  */
02191       {
02192         int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
02193 
02194         if (regnum >= 0)
02195           {
02196             /* User registers lie completely outside of the range of
02197                normal registers.  Catch them early so that the target
02198                never sees them.  */
02199             if (regnum >= gdbarch_num_regs (gdbarch)
02200                           + gdbarch_num_pseudo_regs (gdbarch))
02201               {
02202                 struct value *regval = value_of_user_reg (regnum, frame);
02203                 const char *regname = user_reg_map_regnum_to_name (gdbarch,
02204                                                                    regnum);
02205 
02206                 /* Print in the same fashion
02207                    gdbarch_print_registers_info's default
02208                    implementation prints.  */
02209                 default_print_one_register_info (gdb_stdout,
02210                                                  regname,
02211                                                  regval);
02212               }
02213             else
02214               gdbarch_print_registers_info (gdbarch, gdb_stdout,
02215                                             frame, regnum, fpregs);
02216             continue;
02217           }
02218       }
02219 
02220       /* A register group?  */
02221       {
02222         struct reggroup *group;
02223 
02224         for (group = reggroup_next (gdbarch, NULL);
02225              group != NULL;
02226              group = reggroup_next (gdbarch, group))
02227           {
02228             /* Don't bother with a length check.  Should the user
02229                enter a short register group name, go with the first
02230                group that matches.  */
02231             if (strncmp (start, reggroup_name (group), end - start) == 0)
02232               break;
02233           }
02234         if (group != NULL)
02235           {
02236             int regnum;
02237 
02238             for (regnum = 0;
02239                  regnum < gdbarch_num_regs (gdbarch)
02240                           + gdbarch_num_pseudo_regs (gdbarch);
02241                  regnum++)
02242               {
02243                 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
02244                   gdbarch_print_registers_info (gdbarch,
02245                                                 gdb_stdout, frame,
02246                                                 regnum, fpregs);
02247               }
02248             continue;
02249           }
02250       }
02251 
02252       /* Nothing matched.  */
02253       error (_("Invalid register `%.*s'"), (int) (end - start), start);
02254     }
02255 }
02256 
02257 static void
02258 all_registers_info (char *addr_exp, int from_tty)
02259 {
02260   registers_info (addr_exp, 1);
02261 }
02262 
02263 static void
02264 nofp_registers_info (char *addr_exp, int from_tty)
02265 {
02266   registers_info (addr_exp, 0);
02267 }
02268 
02269 static void
02270 print_vector_info (struct ui_file *file,
02271                    struct frame_info *frame, const char *args)
02272 {
02273   struct gdbarch *gdbarch = get_frame_arch (frame);
02274 
02275   if (gdbarch_print_vector_info_p (gdbarch))
02276     gdbarch_print_vector_info (gdbarch, file, frame, args);
02277   else
02278     {
02279       int regnum;
02280       int printed_something = 0;
02281 
02282       for (regnum = 0;
02283            regnum < gdbarch_num_regs (gdbarch)
02284                     + gdbarch_num_pseudo_regs (gdbarch);
02285            regnum++)
02286         {
02287           if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
02288             {
02289               printed_something = 1;
02290               gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
02291             }
02292         }
02293       if (!printed_something)
02294         fprintf_filtered (file, "No vector information\n");
02295     }
02296 }
02297 
02298 static void
02299 vector_info (char *args, int from_tty)
02300 {
02301   if (!target_has_registers)
02302     error (_("The program has no registers now."));
02303 
02304   print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
02305 }
02306 
02307 /* Kill the inferior process.  Make us have no inferior.  */
02308 
02309 static void
02310 kill_command (char *arg, int from_tty)
02311 {
02312   /* FIXME:  This should not really be inferior_ptid (or target_has_execution).
02313      It should be a distinct flag that indicates that a target is active, cuz
02314      some targets don't have processes!  */
02315 
02316   if (ptid_equal (inferior_ptid, null_ptid))
02317     error (_("The program is not being run."));
02318   if (!query (_("Kill the program being debugged? ")))
02319     error (_("Not confirmed."));
02320   target_kill ();
02321 
02322   /* If we still have other inferiors to debug, then don't mess with
02323      with their threads.  */
02324   if (!have_inferiors ())
02325     {
02326       init_thread_list ();              /* Destroy thread info.  */
02327 
02328       /* Killing off the inferior can leave us with a core file.  If
02329          so, print the state we are left in.  */
02330       if (target_has_stack)
02331         {
02332           printf_filtered (_("In %s,\n"), target_longname);
02333           print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
02334         }
02335     }
02336   bfd_cache_close_all ();
02337 }
02338 
02339 /* Used in `attach&' command.  ARG is a point to an integer
02340    representing a process id.  Proceed threads of this process iff
02341    they stopped due to debugger request, and when they did, they
02342    reported a clean stop (GDB_SIGNAL_0).  Do not proceed threads
02343    that have been explicitly been told to stop.  */
02344 
02345 static int
02346 proceed_after_attach_callback (struct thread_info *thread,
02347                                void *arg)
02348 {
02349   int pid = * (int *) arg;
02350 
02351   if (ptid_get_pid (thread->ptid) == pid
02352       && !is_exited (thread->ptid)
02353       && !is_executing (thread->ptid)
02354       && !thread->stop_requested
02355       && thread->suspend.stop_signal == GDB_SIGNAL_0)
02356     {
02357       switch_to_thread (thread->ptid);
02358       clear_proceed_status ();
02359       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
02360     }
02361 
02362   return 0;
02363 }
02364 
02365 static void
02366 proceed_after_attach (int pid)
02367 {
02368   /* Don't error out if the current thread is running, because
02369      there may be other stopped threads.  */
02370   struct cleanup *old_chain;
02371 
02372   /* Backup current thread and selected frame.  */
02373   old_chain = make_cleanup_restore_current_thread ();
02374 
02375   iterate_over_threads (proceed_after_attach_callback, &pid);
02376 
02377   /* Restore selected ptid.  */
02378   do_cleanups (old_chain);
02379 }
02380 
02381 /*
02382  * TODO:
02383  * Should save/restore the tty state since it might be that the
02384  * program to be debugged was started on this tty and it wants
02385  * the tty in some state other than what we want.  If it's running
02386  * on another terminal or without a terminal, then saving and
02387  * restoring the tty state is a harmless no-op.
02388  * This only needs to be done if we are attaching to a process.
02389  */
02390 
02391 /* attach_command --
02392    takes a program started up outside of gdb and ``attaches'' to it.
02393    This stops it cold in its tracks and allows us to start debugging it.
02394    and wait for the trace-trap that results from attaching.  */
02395 
02396 static void
02397 attach_command_post_wait (char *args, int from_tty, int async_exec)
02398 {
02399   char *exec_file;
02400   char *full_exec_path = NULL;
02401   struct inferior *inferior;
02402 
02403   inferior = current_inferior ();
02404   inferior->control.stop_soon = NO_STOP_QUIETLY;
02405 
02406   /* If no exec file is yet known, try to determine it from the
02407      process itself.  */
02408   exec_file = (char *) get_exec_file (0);
02409   if (!exec_file)
02410     {
02411       exec_file = target_pid_to_exec_file (ptid_get_pid (inferior_ptid));
02412       if (exec_file)
02413         {
02414           /* It's possible we don't have a full path, but rather just a
02415              filename.  Some targets, such as HP-UX, don't provide the
02416              full path, sigh.
02417 
02418              Attempt to qualify the filename against the source path.
02419              (If that fails, we'll just fall back on the original
02420              filename.  Not much more we can do...)  */
02421 
02422           if (!source_full_path_of (exec_file, &full_exec_path))
02423             full_exec_path = xstrdup (exec_file);
02424 
02425           exec_file_attach (full_exec_path, from_tty);
02426           symbol_file_add_main (full_exec_path, from_tty);
02427         }
02428     }
02429   else
02430     {
02431       reopen_exec_file ();
02432       reread_symbols ();
02433     }
02434 
02435   /* Take any necessary post-attaching actions for this platform.  */
02436   target_post_attach (ptid_get_pid (inferior_ptid));
02437 
02438   post_create_inferior (&current_target, from_tty);
02439 
02440   /* Install inferior's terminal modes.  */
02441   target_terminal_inferior ();
02442 
02443   if (async_exec)
02444     {
02445       /* The user requested an `attach&', so be sure to leave threads
02446          that didn't get a signal running.  */
02447 
02448       /* Immediatelly resume all suspended threads of this inferior,
02449          and this inferior only.  This should have no effect on
02450          already running threads.  If a thread has been stopped with a
02451          signal, leave it be.  */
02452       if (non_stop)
02453         proceed_after_attach (inferior->pid);
02454       else
02455         {
02456           if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
02457             {
02458               clear_proceed_status ();
02459               proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
02460             }
02461         }
02462     }
02463   else
02464     {
02465       /* The user requested a plain `attach', so be sure to leave
02466          the inferior stopped.  */
02467 
02468       if (target_can_async_p ())
02469         async_enable_stdin ();
02470 
02471       /* At least the current thread is already stopped.  */
02472 
02473       /* In all-stop, by definition, all threads have to be already
02474          stopped at this point.  In non-stop, however, although the
02475          selected thread is stopped, others may still be executing.
02476          Be sure to explicitly stop all threads of the process.  This
02477          should have no effect on already stopped threads.  */
02478       if (non_stop)
02479         target_stop (pid_to_ptid (inferior->pid));
02480 
02481       /* Tell the user/frontend where we're stopped.  */
02482       normal_stop ();
02483       if (deprecated_attach_hook)
02484         deprecated_attach_hook ();
02485     }
02486 }
02487 
02488 struct attach_command_continuation_args
02489 {
02490   char *args;
02491   int from_tty;
02492   int async_exec;
02493 };
02494 
02495 static void
02496 attach_command_continuation (void *args, int err)
02497 {
02498   struct attach_command_continuation_args *a = args;
02499 
02500   if (err)
02501     return;
02502 
02503   attach_command_post_wait (a->args, a->from_tty, a->async_exec);
02504 }
02505 
02506 static void
02507 attach_command_continuation_free_args (void *args)
02508 {
02509   struct attach_command_continuation_args *a = args;
02510 
02511   xfree (a->args);
02512   xfree (a);
02513 }
02514 
02515 void
02516 attach_command (char *args, int from_tty)
02517 {
02518   int async_exec = 0;
02519   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
02520 
02521   dont_repeat ();               /* Not for the faint of heart */
02522 
02523   if (gdbarch_has_global_solist (target_gdbarch ()))
02524     /* Don't complain if all processes share the same symbol
02525        space.  */
02526     ;
02527   else if (target_has_execution)
02528     {
02529       if (query (_("A program is being debugged already.  Kill it? ")))
02530         target_kill ();
02531       else
02532         error (_("Not killed."));
02533     }
02534 
02535   /* Clean up any leftovers from other runs.  Some other things from
02536      this function should probably be moved into target_pre_inferior.  */
02537   target_pre_inferior (from_tty);
02538 
02539   if (non_stop && !target_supports_non_stop ())
02540     error (_("Cannot attach to this target in non-stop mode"));
02541 
02542   if (args)
02543     {
02544       async_exec = strip_bg_char (&args);
02545 
02546       /* If we get a request for running in the bg but the target
02547          doesn't support it, error out.  */
02548       if (async_exec && !target_can_async_p ())
02549         error (_("Asynchronous execution not supported on this target."));
02550     }
02551 
02552   /* If we don't get a request of running in the bg, then we need
02553      to simulate synchronous (fg) execution.  */
02554   if (!async_exec && target_can_async_p ())
02555     {
02556       /* Simulate synchronous execution.  */
02557       async_disable_stdin ();
02558       make_cleanup ((make_cleanup_ftype *)async_enable_stdin, NULL);
02559     }
02560 
02561   target_attach (args, from_tty);
02562 
02563   /* Set up the "saved terminal modes" of the inferior
02564      based on what modes we are starting it with.  */
02565   target_terminal_init ();
02566 
02567   /* Set up execution context to know that we should return from
02568      wait_for_inferior as soon as the target reports a stop.  */
02569   init_wait_for_inferior ();
02570   clear_proceed_status ();
02571 
02572   if (non_stop)
02573     {
02574       /* If we find that the current thread isn't stopped, explicitly
02575          do so now, because we're going to install breakpoints and
02576          poke at memory.  */
02577 
02578       if (async_exec)
02579         /* The user requested an `attach&'; stop just one thread.  */
02580         target_stop (inferior_ptid);
02581       else
02582         /* The user requested an `attach', so stop all threads of this
02583            inferior.  */
02584         target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
02585     }
02586 
02587   /* Some system don't generate traps when attaching to inferior.
02588      E.g. Mach 3 or GNU hurd.  */
02589   if (!target_attach_no_wait)
02590     {
02591       struct inferior *inferior = current_inferior ();
02592 
02593       /* Careful here.  See comments in inferior.h.  Basically some
02594          OSes don't ignore SIGSTOPs on continue requests anymore.  We
02595          need a way for handle_inferior_event to reset the stop_signal
02596          variable after an attach, and this is what
02597          STOP_QUIETLY_NO_SIGSTOP is for.  */
02598       inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
02599 
02600       if (target_can_async_p ())
02601         {
02602           /* sync_execution mode.  Wait for stop.  */
02603           struct attach_command_continuation_args *a;
02604 
02605           a = xmalloc (sizeof (*a));
02606           a->args = xstrdup (args);
02607           a->from_tty = from_tty;
02608           a->async_exec = async_exec;
02609           add_inferior_continuation (attach_command_continuation, a,
02610                                      attach_command_continuation_free_args);
02611           discard_cleanups (back_to);
02612           return;
02613         }
02614 
02615       wait_for_inferior ();
02616     }
02617 
02618   attach_command_post_wait (args, from_tty, async_exec);
02619   discard_cleanups (back_to);
02620 }
02621 
02622 /* We had just found out that the target was already attached to an
02623    inferior.  PTID points at a thread of this new inferior, that is
02624    the most likely to be stopped right now, but not necessarily so.
02625    The new inferior is assumed to be already added to the inferior
02626    list at this point.  If LEAVE_RUNNING, then leave the threads of
02627    this inferior running, except those we've explicitly seen reported
02628    as stopped.  */
02629 
02630 void
02631 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
02632 {
02633   struct cleanup* old_chain;
02634   int async_exec;
02635 
02636   old_chain = make_cleanup (null_cleanup, NULL);
02637 
02638   /* If in non-stop, leave threads as running as they were.  If
02639      they're stopped for some reason other than us telling it to, the
02640      target reports a signal != GDB_SIGNAL_0.  We don't try to
02641      resume threads with such a stop signal.  */
02642   async_exec = non_stop;
02643 
02644   if (!ptid_equal (inferior_ptid, null_ptid))
02645     make_cleanup_restore_current_thread ();
02646 
02647   switch_to_thread (ptid);
02648 
02649   /* When we "notice" a new inferior we need to do all the things we
02650      would normally do if we had just attached to it.  */
02651 
02652   if (is_executing (inferior_ptid))
02653     {
02654       struct inferior *inferior = current_inferior ();
02655 
02656       /* We're going to install breakpoints, and poke at memory,
02657          ensure that the inferior is stopped for a moment while we do
02658          that.  */
02659       target_stop (inferior_ptid);
02660 
02661       inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
02662 
02663       /* Wait for stop before proceeding.  */
02664       if (target_can_async_p ())
02665         {
02666           struct attach_command_continuation_args *a;
02667 
02668           a = xmalloc (sizeof (*a));
02669           a->args = xstrdup ("");
02670           a->from_tty = from_tty;
02671           a->async_exec = async_exec;
02672           add_inferior_continuation (attach_command_continuation, a,
02673                                      attach_command_continuation_free_args);
02674 
02675           do_cleanups (old_chain);
02676           return;
02677         }
02678       else
02679         wait_for_inferior ();
02680     }
02681 
02682   async_exec = leave_running;
02683   attach_command_post_wait ("" /* args */, from_tty, async_exec);
02684 
02685   do_cleanups (old_chain);
02686 }
02687 
02688 /*
02689  * detach_command --
02690  * takes a program previously attached to and detaches it.
02691  * The program resumes execution and will no longer stop
02692  * on signals, etc.  We better not have left any breakpoints
02693  * in the program or it'll die when it hits one.  For this
02694  * to work, it may be necessary for the process to have been
02695  * previously attached.  It *might* work if the program was
02696  * started via the normal ptrace (PTRACE_TRACEME).
02697  */
02698 
02699 void
02700 detach_command (char *args, int from_tty)
02701 {
02702   dont_repeat ();               /* Not for the faint of heart.  */
02703 
02704   if (ptid_equal (inferior_ptid, null_ptid))
02705     error (_("The program is not being run."));
02706 
02707   query_if_trace_running (from_tty);
02708 
02709   disconnect_tracing ();
02710 
02711   target_detach (args, from_tty);
02712 
02713   /* If the solist is global across inferiors, don't clear it when we
02714      detach from a single inferior.  */
02715   if (!gdbarch_has_global_solist (target_gdbarch ()))
02716     no_shared_libraries (NULL, from_tty);
02717 
02718   /* If we still have inferiors to debug, then don't mess with their
02719      threads.  */
02720   if (!have_inferiors ())
02721     init_thread_list ();
02722 
02723   if (deprecated_detach_hook)
02724     deprecated_detach_hook ();
02725 }
02726 
02727 /* Disconnect from the current target without resuming it (leaving it
02728    waiting for a debugger).
02729 
02730    We'd better not have left any breakpoints in the program or the
02731    next debugger will get confused.  Currently only supported for some
02732    remote targets, since the normal attach mechanisms don't work on
02733    stopped processes on some native platforms (e.g. GNU/Linux).  */
02734 
02735 static void
02736 disconnect_command (char *args, int from_tty)
02737 {
02738   dont_repeat ();               /* Not for the faint of heart.  */
02739   query_if_trace_running (from_tty);
02740   disconnect_tracing ();
02741   target_disconnect (args, from_tty);
02742   no_shared_libraries (NULL, from_tty);
02743   init_thread_list ();
02744   if (deprecated_detach_hook)
02745     deprecated_detach_hook ();
02746 }
02747 
02748 void 
02749 interrupt_target_1 (int all_threads)
02750 {
02751   ptid_t ptid;
02752 
02753   if (all_threads)
02754     ptid = minus_one_ptid;
02755   else
02756     ptid = inferior_ptid;
02757   target_stop (ptid);
02758 
02759   /* Tag the thread as having been explicitly requested to stop, so
02760      other parts of gdb know not to resume this thread automatically,
02761      if it was stopped due to an internal event.  Limit this to
02762      non-stop mode, as when debugging a multi-threaded application in
02763      all-stop mode, we will only get one stop event --- it's undefined
02764      which thread will report the event.  */
02765   if (non_stop)
02766     set_stop_requested (ptid, 1);
02767 }
02768 
02769 /* Stop the execution of the target while running in async mode, in
02770    the backgound.  In all-stop, stop the whole process.  In non-stop
02771    mode, stop the current thread only by default, or stop all threads
02772    if the `-a' switch is used.  */
02773 
02774 /* interrupt [-a]  */
02775 static void
02776 interrupt_target_command (char *args, int from_tty)
02777 {
02778   if (target_can_async_p ())
02779     {
02780       int all_threads = 0;
02781 
02782       dont_repeat ();           /* Not for the faint of heart.  */
02783 
02784       if (args != NULL
02785           && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
02786         all_threads = 1;
02787 
02788       if (!non_stop && all_threads)
02789         error (_("-a is meaningless in all-stop mode."));
02790 
02791       interrupt_target_1 (all_threads);
02792     }
02793 }
02794 
02795 static void
02796 print_float_info (struct ui_file *file,
02797                   struct frame_info *frame, const char *args)
02798 {
02799   struct gdbarch *gdbarch = get_frame_arch (frame);
02800 
02801   if (gdbarch_print_float_info_p (gdbarch))
02802     gdbarch_print_float_info (gdbarch, file, frame, args);
02803   else
02804     {
02805       int regnum;
02806       int printed_something = 0;
02807 
02808       for (regnum = 0;
02809            regnum < gdbarch_num_regs (gdbarch)
02810                     + gdbarch_num_pseudo_regs (gdbarch);
02811            regnum++)
02812         {
02813           if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
02814             {
02815               printed_something = 1;
02816               gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
02817             }
02818         }
02819       if (!printed_something)
02820         fprintf_filtered (file, "No floating-point info "
02821                           "available for this processor.\n");
02822     }
02823 }
02824 
02825 static void
02826 float_info (char *args, int from_tty)
02827 {
02828   if (!target_has_registers)
02829     error (_("The program has no registers now."));
02830 
02831   print_float_info (gdb_stdout, get_selected_frame (NULL), args);
02832 }
02833 
02834 static void
02835 unset_command (char *args, int from_tty)
02836 {
02837   printf_filtered (_("\"unset\" must be followed by the "
02838                      "name of an unset subcommand.\n"));
02839   help_list (unsetlist, "unset ", -1, gdb_stdout);
02840 }
02841 
02842 /* Implement `info proc' family of commands.  */
02843 
02844 static void
02845 info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
02846 {
02847   struct gdbarch *gdbarch = get_current_arch ();
02848 
02849   if (!target_info_proc (args, what))
02850     {
02851       if (gdbarch_info_proc_p (gdbarch))
02852         gdbarch_info_proc (gdbarch, args, what);
02853       else
02854         error (_("Not supported on this target."));
02855     }
02856 }
02857 
02858 /* Implement `info proc' when given without any futher parameters.  */
02859 
02860 static void
02861 info_proc_cmd (char *args, int from_tty)
02862 {
02863   info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
02864 }
02865 
02866 /* Implement `info proc mappings'.  */
02867 
02868 static void
02869 info_proc_cmd_mappings (char *args, int from_tty)
02870 {
02871   info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
02872 }
02873 
02874 /* Implement `info proc stat'.  */
02875 
02876 static void
02877 info_proc_cmd_stat (char *args, int from_tty)
02878 {
02879   info_proc_cmd_1 (args, IP_STAT, from_tty);
02880 }
02881 
02882 /* Implement `info proc status'.  */
02883 
02884 static void
02885 info_proc_cmd_status (char *args, int from_tty)
02886 {
02887   info_proc_cmd_1 (args, IP_STATUS, from_tty);
02888 }
02889 
02890 /* Implement `info proc cwd'.  */
02891 
02892 static void
02893 info_proc_cmd_cwd (char *args, int from_tty)
02894 {
02895   info_proc_cmd_1 (args, IP_CWD, from_tty);
02896 }
02897 
02898 /* Implement `info proc cmdline'.  */
02899 
02900 static void
02901 info_proc_cmd_cmdline (char *args, int from_tty)
02902 {
02903   info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
02904 }
02905 
02906 /* Implement `info proc exe'.  */
02907 
02908 static void
02909 info_proc_cmd_exe (char *args, int from_tty)
02910 {
02911   info_proc_cmd_1 (args, IP_EXE, from_tty);
02912 }
02913 
02914 /* Implement `info proc all'.  */
02915 
02916 static void
02917 info_proc_cmd_all (char *args, int from_tty)
02918 {
02919   info_proc_cmd_1 (args, IP_ALL, from_tty);
02920 }
02921 
02922 void
02923 _initialize_infcmd (void)
02924 {
02925   static struct cmd_list_element *info_proc_cmdlist;
02926   struct cmd_list_element *c = NULL;
02927   const char *cmd_name;
02928 
02929   /* Add the filename of the terminal connected to inferior I/O.  */
02930   add_setshow_filename_cmd ("inferior-tty", class_run,
02931                             &inferior_io_terminal_scratch, _("\
02932 Set terminal for future runs of program being debugged."), _("\
02933 Show terminal for future runs of program being debugged."), _("\
02934 Usage: set inferior-tty /dev/pts/1"),
02935                             set_inferior_tty_command,
02936                             show_inferior_tty_command,
02937                             &setlist, &showlist);
02938   add_com_alias ("tty", "set inferior-tty", class_alias, 0);
02939 
02940   cmd_name = "args";
02941   add_setshow_string_noescape_cmd (cmd_name, class_run,
02942                                    &inferior_args_scratch, _("\
02943 Set argument list to give program being debugged when it is started."), _("\
02944 Show argument list to give program being debugged when it is started."), _("\
02945 Follow this command with any number of args, to be passed to the program."),
02946                                    set_args_command,
02947                                    show_args_command,
02948                                    &setlist, &showlist);
02949   c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
02950   gdb_assert (c != NULL);
02951   set_cmd_completer (c, filename_completer);
02952 
02953   c = add_cmd ("environment", no_class, environment_info, _("\
02954 The environment to give the program, or one variable's value.\n\
02955 With an argument VAR, prints the value of environment variable VAR to\n\
02956 give the program being debugged.  With no arguments, prints the entire\n\
02957 environment to be given to the program."), &showlist);
02958   set_cmd_completer (c, noop_completer);
02959 
02960   add_prefix_cmd ("unset", no_class, unset_command,
02961                   _("Complement to certain \"set\" commands."),
02962                   &unsetlist, "unset ", 0, &cmdlist);
02963 
02964   c = add_cmd ("environment", class_run, unset_environment_command, _("\
02965 Cancel environment variable VAR for the program.\n\
02966 This does not affect the program until the next \"run\" command."),
02967                &unsetlist);
02968   set_cmd_completer (c, noop_completer);
02969 
02970   c = add_cmd ("environment", class_run, set_environment_command, _("\
02971 Set environment variable value to give the program.\n\
02972 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
02973 VALUES of environment variables are uninterpreted strings.\n\
02974 This does not affect the program until the next \"run\" command."),
02975                &setlist);
02976   set_cmd_completer (c, noop_completer);
02977 
02978   c = add_com ("path", class_files, path_command, _("\
02979 Add directory DIR(s) to beginning of search path for object files.\n\
02980 $cwd in the path means the current working directory.\n\
02981 This path is equivalent to the $PATH shell variable.  It is a list of\n\
02982 directories, separated by colons.  These directories are searched to find\n\
02983 fully linked executable files and separately compiled object files as \
02984 needed."));
02985   set_cmd_completer (c, filename_completer);
02986 
02987   c = add_cmd ("paths", no_class, path_info, _("\
02988 Current search path for finding object files.\n\
02989 $cwd in the path means the current working directory.\n\
02990 This path is equivalent to the $PATH shell variable.  It is a list of\n\
02991 directories, separated by colons.  These directories are searched to find\n\
02992 fully linked executable files and separately compiled object files as \
02993 needed."),
02994                &showlist);
02995   set_cmd_completer (c, noop_completer);
02996 
02997   add_prefix_cmd ("kill", class_run, kill_command,
02998                   _("Kill execution of program being debugged."),
02999                   &killlist, "kill ", 0, &cmdlist);
03000 
03001   add_com ("attach", class_run, attach_command, _("\
03002 Attach to a process or file outside of GDB.\n\
03003 This command attaches to another target, of the same type as your last\n\
03004 \"target\" command (\"info files\" will show your target stack).\n\
03005 The command may take as argument a process id or a device file.\n\
03006 For a process id, you must have permission to send the process a signal,\n\
03007 and it must have the same effective uid as the debugger.\n\
03008 When using \"attach\" with a process id, the debugger finds the\n\
03009 program running in the process, looking first in the current working\n\
03010 directory, or (if not found there) using the source file search path\n\
03011 (see the \"directory\" command).  You can also use the \"file\" command\n\
03012 to specify the program, and to load its symbol table."));
03013 
03014   add_prefix_cmd ("detach", class_run, detach_command, _("\
03015 Detach a process or file previously attached.\n\
03016 If a process, it is no longer traced, and it continues its execution.  If\n\
03017 you were debugging a file, the file is closed and gdb no longer accesses it."),
03018                   &detachlist, "detach ", 0, &cmdlist);
03019 
03020   add_com ("disconnect", class_run, disconnect_command, _("\
03021 Disconnect from a target.\n\
03022 The target will wait for another debugger to connect.  Not available for\n\
03023 all targets."));
03024 
03025   c = add_com ("signal", class_run, signal_command, _("\
03026 Continue program with the specified signal.\n\
03027 Usage: signal SIGNAL\n\
03028 The SIGNAL argument is processed the same as the handle command.\n\
03029 \n\
03030 An argument of \"0\" means continue the program without sending it a signal.\n\
03031 This is useful in cases where the program stopped because of a signal,\n\
03032 and you want to resume the program while discarding the signal."));
03033   set_cmd_completer (c, signal_completer);
03034 
03035   add_com ("stepi", class_run, stepi_command, _("\
03036 Step one instruction exactly.\n\
03037 Usage: stepi [N]\n\
03038 Argument N means step N times (or till program stops for another \
03039 reason)."));
03040   add_com_alias ("si", "stepi", class_alias, 0);
03041 
03042   add_com ("nexti", class_run, nexti_command, _("\
03043 Step one instruction, but proceed through subroutine calls.\n\
03044 Usage: nexti [N]\n\
03045 Argument N means step N times (or till program stops for another \
03046 reason)."));
03047   add_com_alias ("ni", "nexti", class_alias, 0);
03048 
03049   add_com ("finish", class_run, finish_command, _("\
03050 Execute until selected stack frame returns.\n\
03051 Usage: finish\n\
03052 Upon return, the value returned is printed and put in the value history."));
03053   add_com_alias ("fin", "finish", class_run, 1);
03054 
03055   add_com ("next", class_run, next_command, _("\
03056 Step program, proceeding through subroutine calls.\n\
03057 Usage: next [N]\n\
03058 Unlike \"step\", if the current source line calls a subroutine,\n\
03059 this command does not enter the subroutine, but instead steps over\n\
03060 the call, in effect treating it as a single source line."));
03061   add_com_alias ("n", "next", class_run, 1);
03062   if (xdb_commands)
03063     add_com_alias ("S", "next", class_run, 1);
03064 
03065   add_com ("step", class_run, step_command, _("\
03066 Step program until it reaches a different source line.\n\
03067 Usage: step [N]\n\
03068 Argument N means step N times (or till program stops for another \
03069 reason)."));
03070   add_com_alias ("s", "step", class_run, 1);
03071 
03072   c = add_com ("until", class_run, until_command, _("\
03073 Execute until the program reaches a source line greater than the current\n\
03074 or a specified location (same args as break command) within the current \
03075 frame."));
03076   set_cmd_completer (c, location_completer);
03077   add_com_alias ("u", "until", class_run, 1);
03078 
03079   c = add_com ("advance", class_run, advance_command, _("\
03080 Continue the program up to the given location (same form as args for break \
03081 command).\n\
03082 Execution will also stop upon exit from the current stack frame."));
03083   set_cmd_completer (c, location_completer);
03084 
03085   c = add_com ("jump", class_run, jump_command, _("\
03086 Continue program being debugged at specified line or address.\n\
03087 Usage: jump <location>\n\
03088 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
03089 for an address to start at."));
03090   set_cmd_completer (c, location_completer);
03091   add_com_alias ("j", "jump", class_run, 1);
03092 
03093   if (xdb_commands)
03094     {
03095       c = add_com ("go", class_run, go_command, _("\
03096 Usage: go <location>\n\
03097 Continue program being debugged, stopping at specified line or \n\
03098 address.\n\
03099 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
03100 expression for an address to start at.\n\
03101 This command is a combination of tbreak and jump."));
03102       set_cmd_completer (c, location_completer);
03103     }
03104 
03105   if (xdb_commands)
03106     add_com_alias ("g", "go", class_run, 1);
03107 
03108   add_com ("continue", class_run, continue_command, _("\
03109 Continue program being debugged, after signal or breakpoint.\n\
03110 Usage: continue [N]\n\
03111 If proceeding from breakpoint, a number N may be used as an argument,\n\
03112 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
03113 the breakpoint won't break until the Nth time it is reached).\n\
03114 \n\
03115 If non-stop mode is enabled, continue only the current thread,\n\
03116 otherwise all the threads in the program are continued.  To \n\
03117 continue all stopped threads in non-stop mode, use the -a option.\n\
03118 Specifying -a and an ignore count simultaneously is an error."));
03119   add_com_alias ("c", "cont", class_run, 1);
03120   add_com_alias ("fg", "cont", class_run, 1);
03121 
03122   c = add_com ("run", class_run, run_command, _("\
03123 Start debugged program.  You may specify arguments to give it.\n\
03124 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
03125 Input and output redirection with \">\", \"<\", or \">>\" are also \
03126 allowed.\n\n\
03127 With no arguments, uses arguments last specified (with \"run\" \
03128 or \"set args\").\n\
03129 To cancel previous arguments and run with no arguments,\n\
03130 use \"set args\" without arguments."));
03131   set_cmd_completer (c, filename_completer);
03132   add_com_alias ("r", "run", class_run, 1);
03133   if (xdb_commands)
03134     add_com ("R", class_run, run_no_args_command,
03135              _("Start debugged program with no arguments."));
03136 
03137   c = add_com ("start", class_run, start_command, _("\
03138 Run the debugged program until the beginning of the main procedure.\n\
03139 You may specify arguments to give to your program, just as with the\n\
03140 \"run\" command."));
03141   set_cmd_completer (c, filename_completer);
03142 
03143   add_com ("interrupt", class_run, interrupt_target_command,
03144            _("Interrupt the execution of the debugged program.\n\
03145 If non-stop mode is enabled, interrupt only the current thread,\n\
03146 otherwise all the threads in the program are stopped.  To \n\
03147 interrupt all running threads in non-stop mode, use the -a option."));
03148 
03149   add_info ("registers", nofp_registers_info, _("\
03150 List of integer registers and their contents, for selected stack frame.\n\
03151 Register name as argument means describe only that register."));
03152   add_info_alias ("r", "registers", 1);
03153 
03154   if (xdb_commands)
03155     add_com ("lr", class_info, nofp_registers_info, _("\
03156 List of integer registers and their contents, for selected stack frame.\n\
03157 Register name as argument means describe only that register."));
03158   add_info ("all-registers", all_registers_info, _("\
03159 List of all registers and their contents, for selected stack frame.\n\
03160 Register name as argument means describe only that register."));
03161 
03162   add_info ("program", program_info,
03163             _("Execution status of the program."));
03164 
03165   add_info ("float", float_info,
03166             _("Print the status of the floating point unit\n"));
03167 
03168   add_info ("vector", vector_info,
03169             _("Print the status of the vector unit\n"));
03170 
03171   add_prefix_cmd ("proc", class_info, info_proc_cmd,
03172                   _("\
03173 Show /proc process information about any running process.\n\
03174 Specify any process id, or use the program being debugged by default."),
03175                   &info_proc_cmdlist, "info proc ",
03176                   1/*allow-unknown*/, &infolist);
03177 
03178   add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
03179 List of mapped memory regions."),
03180            &info_proc_cmdlist);
03181 
03182   add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
03183 List process info from /proc/PID/stat."),
03184            &info_proc_cmdlist);
03185 
03186   add_cmd ("status", class_info, info_proc_cmd_status, _("\
03187 List process info from /proc/PID/status."),
03188            &info_proc_cmdlist);
03189 
03190   add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
03191 List current working directory of the process."),
03192            &info_proc_cmdlist);
03193 
03194   add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
03195 List command line arguments of the process."),
03196            &info_proc_cmdlist);
03197 
03198   add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
03199 List absolute filename for executable of the process."),
03200            &info_proc_cmdlist);
03201 
03202   add_cmd ("all", class_info, info_proc_cmd_all, _("\
03203 List all available /proc info."),
03204            &info_proc_cmdlist);
03205 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines