gdb/infcmd.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Memory-access and commands for "inferior" process, for GDB.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "arch-utils.h"
  16. #include <signal.h>
  17. #include "symtab.h"
  18. #include "gdbtypes.h"
  19. #include "frame.h"
  20. #include "inferior.h"
  21. #include "infrun.h"
  22. #include "environ.h"
  23. #include "value.h"
  24. #include "gdbcmd.h"
  25. #include "symfile.h"
  26. #include "gdbcore.h"
  27. #include "target.h"
  28. #include "language.h"
  29. #include "objfiles.h"
  30. #include "completer.h"
  31. #include "ui-out.h"
  32. #include "event-top.h"
  33. #include "parser-defs.h"
  34. #include "regcache.h"
  35. #include "reggroups.h"
  36. #include "block.h"
  37. #include "solib.h"
  38. #include <ctype.h>
  39. #include "observer.h"
  40. #include "target-descriptions.h"
  41. #include "user-regs.h"
  42. #include "cli/cli-decode.h"
  43. #include "gdbthread.h"
  44. #include "valprint.h"
  45. #include "inline-frame.h"
  46. #include "tracepoint.h"
  47. #include "inf-loop.h"
  48. #include "continuations.h"
  49. #include "linespec.h"
  50. #include "cli/cli-utils.h"

  51. /* Local functions: */

  52. static void nofp_registers_info (char *, int);

  53. static void print_return_value (struct value *function,
  54.                                 struct type *value_type);

  55. static void until_next_command (int);

  56. static void until_command (char *, int);

  57. static void path_info (char *, int);

  58. static void path_command (char *, int);

  59. static void unset_command (char *, int);

  60. static void float_info (char *, int);

  61. static void disconnect_command (char *, int);

  62. static void unset_environment_command (char *, int);

  63. static void set_environment_command (char *, int);

  64. static void environment_info (char *, int);

  65. static void program_info (char *, int);

  66. static void finish_command (char *, int);

  67. static void signal_command (char *, int);

  68. static void jump_command (char *, int);

  69. static void step_1 (int, int, char *);
  70. static void step_once (int skip_subroutines, int single_inst,
  71.                        int count, int thread);

  72. static void next_command (char *, int);

  73. static void step_command (char *, int);

  74. static void run_command (char *, int);

  75. static void run_no_args_command (char *args, int from_tty);

  76. static void go_command (char *line_no, int from_tty);

  77. void _initialize_infcmd (void);

  78. #define ERROR_NO_INFERIOR \
  79.    if (!target_has_execution) error (_("The program is not being run."));

  80. /* Scratch area where string containing arguments to give to the
  81.    program will be stored by 'set args'.  As soon as anything is
  82.    stored, notice_args_set will move it into per-inferior storage.
  83.    Arguments are separated by spaces.  Empty string (pointer to '\0')
  84.    means no args.  */

  85. static char *inferior_args_scratch;

  86. /* Scratch area where 'set inferior-tty' will store user-provided value.
  87.    We'll immediate copy it into per-inferior storage.  */

  88. static char *inferior_io_terminal_scratch;

  89. /* Pid of our debugged inferior, or 0 if no inferior now.
  90.    Since various parts of infrun.c test this to see whether there is a program
  91.    being debugged it should be nonzero (currently 3 is used) for remote
  92.    debugging.  */

  93. ptid_t inferior_ptid;

  94. /* Address at which inferior stopped.  */

  95. CORE_ADDR stop_pc;

  96. /* Nonzero if stopped due to completion of a stack dummy routine.  */

  97. enum stop_stack_kind stop_stack_dummy;

  98. /* Nonzero if stopped due to a random (unexpected) signal in inferior
  99.    process.  */

  100. int stopped_by_random_signal;

  101. /* See inferior.h.  */

  102. int startup_with_shell = 1;


  103. /* Accessor routines.  */

  104. /* Set the io terminal for the current inferior.  Ownership of
  105.    TERMINAL_NAME is not transferred.  */

  106. void
  107. set_inferior_io_terminal (const char *terminal_name)
  108. {
  109.   xfree (current_inferior ()->terminal);
  110.   current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
  111. }

  112. const char *
  113. get_inferior_io_terminal (void)
  114. {
  115.   return current_inferior ()->terminal;
  116. }

  117. static void
  118. set_inferior_tty_command (char *args, int from_tty,
  119.                           struct cmd_list_element *c)
  120. {
  121.   /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
  122.      Now route it to current inferior.  */
  123.   set_inferior_io_terminal (inferior_io_terminal_scratch);
  124. }

  125. static void
  126. show_inferior_tty_command (struct ui_file *file, int from_tty,
  127.                            struct cmd_list_element *c, const char *value)
  128. {
  129.   /* Note that we ignore the passed-in value in favor of computing it
  130.      directly.  */
  131.   const char *inferior_io_terminal = get_inferior_io_terminal ();

  132.   if (inferior_io_terminal == NULL)
  133.     inferior_io_terminal = "";
  134.   fprintf_filtered (gdb_stdout,
  135.                     _("Terminal for future runs of program being debugged "
  136.                       "is \"%s\".\n"), inferior_io_terminal);
  137. }

  138. char *
  139. get_inferior_args (void)
  140. {
  141.   if (current_inferior ()->argc != 0)
  142.     {
  143.       char *n;

  144.       n = construct_inferior_arguments (current_inferior ()->argc,
  145.                                         current_inferior ()->argv);
  146.       set_inferior_args (n);
  147.       xfree (n);
  148.     }

  149.   if (current_inferior ()->args == NULL)
  150.     current_inferior ()->args = xstrdup ("");

  151.   return current_inferior ()->args;
  152. }

  153. /* Set the arguments for the current inferior.  Ownership of
  154.    NEWARGS is not transferred.  */

  155. void
  156. set_inferior_args (char *newargs)
  157. {
  158.   xfree (current_inferior ()->args);
  159.   current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
  160.   current_inferior ()->argc = 0;
  161.   current_inferior ()->argv = 0;
  162. }

  163. void
  164. set_inferior_args_vector (int argc, char **argv)
  165. {
  166.   current_inferior ()->argc = argc;
  167.   current_inferior ()->argv = argv;
  168. }

  169. /* Notice when `set args' is run.  */

  170. static void
  171. set_args_command (char *args, int from_tty, struct cmd_list_element *c)
  172. {
  173.   /* CLI has assigned the user-provided value to inferior_args_scratch.
  174.      Now route it to current inferior.  */
  175.   set_inferior_args (inferior_args_scratch);
  176. }

  177. /* Notice when `show args' is run.  */

  178. static void
  179. show_args_command (struct ui_file *file, int from_tty,
  180.                    struct cmd_list_element *c, const char *value)
  181. {
  182.   /* Note that we ignore the passed-in value in favor of computing it
  183.      directly.  */
  184.   deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
  185. }


  186. /* Compute command-line string given argument vector.  This does the
  187.    same shell processing as fork_inferior.  */

  188. char *
  189. construct_inferior_arguments (int argc, char **argv)
  190. {
  191.   char *result;

  192.   if (startup_with_shell)
  193.     {
  194. #ifdef __MINGW32__
  195.       /* This holds all the characters considered special to the
  196.          Windows shells.  */
  197.       char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
  198.       const char quote = '"';
  199. #else
  200.       /* This holds all the characters considered special to the
  201.          typical Unix shells.  We include `^' because the SunOS
  202.          /bin/sh treats it as a synonym for `|'.  */
  203.       char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
  204.       const char quote = '\'';
  205. #endif
  206.       int i;
  207.       int length = 0;
  208.       char *out, *cp;

  209.       /* We over-compute the size.  It shouldn't matter.  */
  210.       for (i = 0; i < argc; ++i)
  211.         length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');

  212.       result = (char *) xmalloc (length);
  213.       out = result;

  214.       for (i = 0; i < argc; ++i)
  215.         {
  216.           if (i > 0)
  217.             *out++ = ' ';

  218.           /* Need to handle empty arguments specially.  */
  219.           if (argv[i][0] == '\0')
  220.             {
  221.               *out++ = quote;
  222.               *out++ = quote;
  223.             }
  224.           else
  225.             {
  226. #ifdef __MINGW32__
  227.               int quoted = 0;

  228.               if (strpbrk (argv[i], special))
  229.                 {
  230.                   quoted = 1;
  231.                   *out++ = quote;
  232.                 }
  233. #endif
  234.               for (cp = argv[i]; *cp; ++cp)
  235.                 {
  236.                   if (*cp == '\n')
  237.                     {
  238.                       /* A newline cannot be quoted with a backslash (it
  239.                          just disappears), only by putting it inside
  240.                          quotes.  */
  241.                       *out++ = quote;
  242.                       *out++ = '\n';
  243.                       *out++ = quote;
  244.                     }
  245.                   else
  246.                     {
  247. #ifdef __MINGW32__
  248.                       if (*cp == quote)
  249. #else
  250.                       if (strchr (special, *cp) != NULL)
  251. #endif
  252.                         *out++ = '\\';
  253.                       *out++ = *cp;
  254.                     }
  255.                 }
  256. #ifdef __MINGW32__
  257.               if (quoted)
  258.                 *out++ = quote;
  259. #endif
  260.             }
  261.         }
  262.       *out = '\0';
  263.     }
  264.   else
  265.     {
  266.       /* In this case we can't handle arguments that contain spaces,
  267.          tabs, or newlines -- see breakup_args().  */
  268.       int i;
  269.       int length = 0;

  270.       for (i = 0; i < argc; ++i)
  271.         {
  272.           char *cp = strchr (argv[i], ' ');
  273.           if (cp == NULL)
  274.             cp = strchr (argv[i], '\t');
  275.           if (cp == NULL)
  276.             cp = strchr (argv[i], '\n');
  277.           if (cp != NULL)
  278.             error (_("can't handle command-line "
  279.                      "argument containing whitespace"));
  280.           length += strlen (argv[i]) + 1;
  281.         }

  282.       result = (char *) xmalloc (length);
  283.       result[0] = '\0';
  284.       for (i = 0; i < argc; ++i)
  285.         {
  286.           if (i > 0)
  287.             strcat (result, " ");
  288.           strcat (result, argv[i]);
  289.         }
  290.     }

  291.   return result;
  292. }


  293. /* This function strips the '&' character (indicating background
  294.    execution) that is added as *the last* of the arguments ARGS of a
  295.    command.  A copy of the incoming ARGS without the '&' is returned,
  296.    unless the resulting string after stripping is empty, in which case
  297.    NULL is returned.  *BG_CHAR_P is an output boolean that indicates
  298.    whether the '&' character was found.  */

  299. static char *
  300. strip_bg_char (const char *args, int *bg_char_p)
  301. {
  302.   const char *p;

  303.   if (args == NULL || *args == '\0')
  304.     {
  305.       *bg_char_p = 0;
  306.       return NULL;
  307.     }

  308.   p = args + strlen (args);
  309.   if (p[-1] == '&')
  310.     {
  311.       p--;
  312.       while (p > args && isspace (p[-1]))
  313.         p--;

  314.       *bg_char_p = 1;
  315.       if (p != args)
  316.         return savestring (args, p - args);
  317.       else
  318.         return NULL;
  319.     }

  320.   *bg_char_p = 0;
  321.   return xstrdup (args);
  322. }

  323. /* Common actions to take after creating any sort of inferior, by any
  324.    means (running, attaching, connecting, et cetera).  The target
  325.    should be stopped.  */

  326. void
  327. post_create_inferior (struct target_ops *target, int from_tty)
  328. {
  329.   volatile struct gdb_exception ex;

  330.   /* Be sure we own the terminal in case write operations are performed.  */
  331.   target_terminal_ours ();

  332.   /* If the target hasn't taken care of this already, do it now.
  333.      Targets which need to access registers during to_open,
  334.      to_create_inferior, or to_attach should do it earlier; but many
  335.      don't need to.  */
  336.   target_find_description ();

  337.   /* Now that we know the register layout, retrieve current PC.  But
  338.      if the PC is unavailable (e.g., we're opening a core file with
  339.      missing registers info), ignore it.  */
  340.   stop_pc = 0;
  341.   TRY_CATCH (ex, RETURN_MASK_ERROR)
  342.     {
  343.       stop_pc = regcache_read_pc (get_current_regcache ());
  344.     }
  345.   if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
  346.     throw_exception (ex);

  347.   if (exec_bfd)
  348.     {
  349.       const unsigned solib_add_generation
  350.         = current_program_space->solib_add_generation;

  351.       /* Create the hooks to handle shared library load and unload
  352.          events.  */
  353.       solib_create_inferior_hook (from_tty);

  354.       if (current_program_space->solib_add_generation == solib_add_generation)
  355.         {
  356.           /* The platform-specific hook should load initial shared libraries,
  357.              but didn't.  FROM_TTY will be incorrectly 0 but such solib
  358.              targets should be fixed anyway.  Call it only after the solib
  359.              target has been initialized by solib_create_inferior_hook.  */

  360.           if (info_verbose)
  361.             warning (_("platform-specific solib_create_inferior_hook did "
  362.                        "not load initial shared libraries."));

  363.           /* If the solist is global across processes, there's no need to
  364.              refetch it here.  */
  365.           if (!gdbarch_has_global_solist (target_gdbarch ()))
  366.             solib_add (NULL, 0, target, auto_solib_add);
  367.         }
  368.     }

  369.   /* If the user sets watchpoints before execution having started,
  370.      then she gets software watchpoints, because GDB can't know which
  371.      target will end up being pushed, or if it supports hardware
  372.      watchpoints or not.  breakpoint_re_set takes care of promoting
  373.      watchpoints to hardware watchpoints if possible, however, if this
  374.      new inferior doesn't load shared libraries or we don't pull in
  375.      symbols from any other source on this target/arch,
  376.      breakpoint_re_set is never called.  Call it now so that software
  377.      watchpoints get a chance to be promoted to hardware watchpoints
  378.      if the now pushed target supports hardware watchpoints.  */
  379.   breakpoint_re_set ();

  380.   observer_notify_inferior_created (target, from_tty);
  381. }

  382. /* Kill the inferior if already running.  This function is designed
  383.    to be called when we are about to start the execution of the program
  384.    from the beginning.  Ask the user to confirm that he wants to restart
  385.    the program being debugged when FROM_TTY is non-null.  */

  386. static void
  387. kill_if_already_running (int from_tty)
  388. {
  389.   if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
  390.     {
  391.       /* Bail out before killing the program if we will not be able to
  392.          restart it.  */
  393.       target_require_runnable ();

  394.       if (from_tty
  395.           && !query (_("The program being debugged has been started already.\n\
  396. Start it from the beginning? ")))
  397.         error (_("Program not restarted."));
  398.       target_kill ();
  399.     }
  400. }

  401. /* See inferior.h.  */

  402. void
  403. prepare_execution_command (struct target_ops *target, int background)
  404. {
  405.   /* If we get a request for running in the bg but the target
  406.      doesn't support it, error out.  */
  407.   if (background && !target->to_can_async_p (target))
  408.     error (_("Asynchronous execution not supported on this target."));

  409.   /* If we don't get a request of running in the bg, then we need
  410.      to simulate synchronous (fg) execution.  */
  411.   if (!background && target->to_can_async_p (target))
  412.     {
  413.       /* Simulate synchronous execution.  Note no cleanup is necessary
  414.          for this.  stdin is re-enabled whenever an error reaches the
  415.          top level.  */
  416.       async_disable_stdin ();
  417.     }
  418. }

  419. /* Implement the "run" command.  If TBREAK_AT_MAIN is set, then insert
  420.    a temporary breakpoint at the begining of the main program before
  421.    running the program.  */

  422. static void
  423. run_command_1 (char *args, int from_tty, int tbreak_at_main)
  424. {
  425.   char *exec_file;
  426.   struct cleanup *old_chain;
  427.   ptid_t ptid;
  428.   struct ui_out *uiout = current_uiout;
  429.   struct target_ops *run_target;
  430.   int async_exec;
  431.   struct cleanup *args_chain;

  432.   dont_repeat ();

  433.   kill_if_already_running (from_tty);

  434.   init_wait_for_inferior ();
  435.   clear_breakpoint_hit_counts ();

  436.   /* Clean up any leftovers from other runs.  Some other things from
  437.      this function should probably be moved into target_pre_inferior.  */
  438.   target_pre_inferior (from_tty);

  439.   /* The comment here used to read, "The exec file is re-read every
  440.      time we do a generic_mourn_inferior, so we just have to worry
  441.      about the symbol file."  The `generic_mourn_inferior' function
  442.      gets called whenever the program exits.  However, suppose the
  443.      program exits, and *then* the executable file changes?  We need
  444.      to check again here.  Since reopen_exec_file doesn't do anything
  445.      if the timestamp hasn't changed, I don't see the harm.  */
  446.   reopen_exec_file ();
  447.   reread_symbols ();

  448.   args = strip_bg_char (args, &async_exec);
  449.   args_chain = make_cleanup (xfree, args);

  450.   /* Do validation and preparation before possibly changing anything
  451.      in the inferior.  */

  452.   run_target = find_run_target ();

  453.   prepare_execution_command (run_target, async_exec);

  454.   if (non_stop && !run_target->to_supports_non_stop (run_target))
  455.     error (_("The target does not support running in non-stop mode."));

  456.   /* Done.  Can now set breakpoints, change inferior args, etc.  */

  457.   /* Insert the temporary breakpoint if a location was specified.  */
  458.   if (tbreak_at_main)
  459.     tbreak_command (main_name (), 0);

  460.   exec_file = (char *) get_exec_file (0);

  461.   /* We keep symbols from add-symbol-file, on the grounds that the
  462.      user might want to add some symbols before running the program
  463.      (right?).  But sometimes (dynamic loading where the user manually
  464.      introduces the new symbols with add-symbol-file), the code which
  465.      the symbols describe does not persist between runs.  Currently
  466.      the user has to manually nuke all symbols between runs if they
  467.      want them to go away (PR 2207).  This is probably reasonable.  */

  468.   /* If there were other args, beside '&', process them.  */
  469.   if (args != NULL)
  470.     set_inferior_args (args);

  471.   if (from_tty)
  472.     {
  473.       ui_out_field_string (uiout, NULL, "Starting program");
  474.       ui_out_text (uiout, ": ");
  475.       if (exec_file)
  476.         ui_out_field_string (uiout, "execfile", exec_file);
  477.       ui_out_spaces (uiout, 1);
  478.       /* We call get_inferior_args() because we might need to compute
  479.          the value now.  */
  480.       ui_out_field_string (uiout, "infargs", get_inferior_args ());
  481.       ui_out_text (uiout, "\n");
  482.       ui_out_flush (uiout);
  483.     }

  484.   /* Done with ARGS.  */
  485.   do_cleanups (args_chain);

  486.   /* We call get_inferior_args() because we might need to compute
  487.      the value now.  */
  488.   run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
  489.                                   environ_vector (current_inferior ()->environment),
  490.                                   from_tty);
  491.   /* to_create_inferior should push the target, so after this point we
  492.      shouldn't refer to run_target again.  */
  493.   run_target = NULL;

  494.   /* We're starting off a new process.  When we get out of here, in
  495.      non-stop mode, finish the state of all threads of that process,
  496.      but leave other threads alone, as they may be stopped in internal
  497.      events --- the frontend shouldn't see them as stopped.  In
  498.      all-stop, always finish the state of all threads, as we may be
  499.      resuming more than just the new process.  */
  500.   if (non_stop)
  501.     ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
  502.   else
  503.     ptid = minus_one_ptid;
  504.   old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);

  505.   /* Pass zero for FROM_TTY, because at this point the "run" command
  506.      has done its thing; now we are setting up the running program.  */
  507.   post_create_inferior (&current_target, 0);

  508.   /* Start the target running.  Do not use -1 continuation as it would skip
  509.      breakpoint right at the entry point.  */
  510.   proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0, 0);

  511.   /* Since there was no error, there's no need to finish the thread
  512.      states here.  */
  513.   discard_cleanups (old_chain);
  514. }

  515. static void
  516. run_command (char *args, int from_tty)
  517. {
  518.   run_command_1 (args, from_tty, 0);
  519. }

  520. static void
  521. run_no_args_command (char *args, int from_tty)
  522. {
  523.   set_inferior_args ("");
  524. }


  525. /* Start the execution of the program up until the beginning of the main
  526.    program.  */

  527. static void
  528. start_command (char *args, int from_tty)
  529. {
  530.   /* Some languages such as Ada need to search inside the program
  531.      minimal symbols for the location where to put the temporary
  532.      breakpoint before starting.  */
  533.   if (!have_minimal_symbols ())
  534.     error (_("No symbol table loaded.  Use the \"file\" command."));

  535.   /* Run the program until reaching the main procedure...  */
  536.   run_command_1 (args, from_tty, 1);
  537. }

  538. static int
  539. proceed_thread_callback (struct thread_info *thread, void *arg)
  540. {
  541.   /* We go through all threads individually instead of compressing
  542.      into a single target `resume_all' request, because some threads
  543.      may be stopped in internal breakpoints/events, or stopped waiting
  544.      for its turn in the displaced stepping queue (that is, they are
  545.      running && !executing).  The target side has no idea about why
  546.      the thread is stopped, so a `resume_all' command would resume too
  547.      much.  If/when GDB gains a way to tell the target `hold this
  548.      thread stopped until I say otherwise', then we can optimize
  549.      this.  */
  550.   if (!is_stopped (thread->ptid))
  551.     return 0;

  552.   switch_to_thread (thread->ptid);
  553.   clear_proceed_status (0);
  554.   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
  555.   return 0;
  556. }

  557. static void
  558. ensure_valid_thread (void)
  559. {
  560.   if (ptid_equal (inferior_ptid, null_ptid)
  561.       || is_exited (inferior_ptid))
  562.     error (_("Cannot execute this command without a live selected thread."));
  563. }

  564. /* If the user is looking at trace frames, any resumption of execution
  565.    is likely to mix up recorded and live target data.  So simply
  566.    disallow those commands.  */

  567. static void
  568. ensure_not_tfind_mode (void)
  569. {
  570.   if (get_traceframe_number () >= 0)
  571.     error (_("Cannot execute this command while looking at trace frames."));
  572. }

  573. /* Throw an error indicating the current thread is running.  */

  574. static void
  575. error_is_running (void)
  576. {
  577.   error (_("Cannot execute this command while "
  578.            "the selected thread is running."));
  579. }

  580. /* Calls error_is_running if the current thread is running.  */

  581. static void
  582. ensure_not_running (void)
  583. {
  584.   if (is_running (inferior_ptid))
  585.     error_is_running ();
  586. }

  587. void
  588. continue_1 (int all_threads)
  589. {
  590.   ERROR_NO_INFERIOR;
  591.   ensure_not_tfind_mode ();

  592.   if (non_stop && all_threads)
  593.     {
  594.       /* Don't error out if the current thread is running, because
  595.          there may be other stopped threads.  */
  596.       struct cleanup *old_chain;

  597.       /* Backup current thread and selected frame.  */
  598.       old_chain = make_cleanup_restore_current_thread ();

  599.       iterate_over_threads (proceed_thread_callback, NULL);

  600.       if (sync_execution)
  601.         {
  602.           /* If all threads in the target were already running,
  603.              proceed_thread_callback ends up never calling proceed,
  604.              and so nothing calls this to put the inferior's terminal
  605.              settings in effect and remove stdin from the event loop,
  606.              which we must when running a foreground command.  E.g.:

  607.               (gdb) c -a&
  608.               Continuing.
  609.               <all threads are running now>
  610.               (gdb) c -a
  611.               Continuing.
  612.               <no thread was resumed, but the inferior now owns the terminal>
  613.           */
  614.           target_terminal_inferior ();
  615.         }

  616.       /* Restore selected ptid.  */
  617.       do_cleanups (old_chain);
  618.     }
  619.   else
  620.     {
  621.       ensure_valid_thread ();
  622.       ensure_not_running ();
  623.       clear_proceed_status (0);
  624.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
  625.     }
  626. }

  627. /* continue [-a] [proceed-count] [&]  */

  628. static void
  629. continue_command (char *args, int from_tty)
  630. {
  631.   int async_exec;
  632.   int all_threads = 0;
  633.   struct cleanup *args_chain;

  634.   ERROR_NO_INFERIOR;

  635.   /* Find out whether we must run in the background.  */
  636.   args = strip_bg_char (args, &async_exec);
  637.   args_chain = make_cleanup (xfree, args);

  638.   prepare_execution_command (&current_target, async_exec);

  639.   if (args != NULL)
  640.     {
  641.       if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
  642.         {
  643.           all_threads = 1;
  644.           args += sizeof ("-a") - 1;
  645.           if (*args == '\0')
  646.             args = NULL;
  647.         }
  648.     }

  649.   if (!non_stop && all_threads)
  650.     error (_("`-a' is meaningless in all-stop mode."));

  651.   if (args != NULL && all_threads)
  652.     error (_("Can't resume all threads and specify "
  653.              "proceed count simultaneously."));

  654.   /* If we have an argument left, set proceed count of breakpoint we
  655.      stopped at.  */
  656.   if (args != NULL)
  657.     {
  658.       bpstat bs = NULL;
  659.       int num, stat;
  660.       int stopped = 0;
  661.       struct thread_info *tp;

  662.       if (non_stop)
  663.         tp = find_thread_ptid (inferior_ptid);
  664.       else
  665.         {
  666.           ptid_t last_ptid;
  667.           struct target_waitstatus ws;

  668.           get_last_target_status (&last_ptid, &ws);
  669.           tp = find_thread_ptid (last_ptid);
  670.         }
  671.       if (tp != NULL)
  672.         bs = tp->control.stop_bpstat;

  673.       while ((stat = bpstat_num (&bs, &num)) != 0)
  674.         if (stat > 0)
  675.           {
  676.             set_ignore_count (num,
  677.                               parse_and_eval_long (args) - 1,
  678.                               from_tty);
  679.             /* set_ignore_count prints a message ending with a period.
  680.                So print two spaces before "Continuing.".  */
  681.             if (from_tty)
  682.               printf_filtered ("  ");
  683.             stopped = 1;
  684.           }

  685.       if (!stopped && from_tty)
  686.         {
  687.           printf_filtered
  688.             ("Not stopped at any breakpoint; argument ignored.\n");
  689.         }
  690.     }

  691.   /* Done with ARGS.  */
  692.   do_cleanups (args_chain);

  693.   if (from_tty)
  694.     printf_filtered (_("Continuing.\n"));

  695.   continue_1 (all_threads);
  696. }

  697. /* Record the starting point of a "step" or "next" command.  */

  698. static void
  699. set_step_frame (void)
  700. {
  701.   struct symtab_and_line sal;

  702.   find_frame_sal (get_current_frame (), &sal);
  703.   set_step_info (get_current_frame (), sal);
  704. }

  705. /* Step until outside of current statement.  */

  706. static void
  707. step_command (char *count_string, int from_tty)
  708. {
  709.   step_1 (0, 0, count_string);
  710. }

  711. /* Likewise, but skip over subroutine calls as if single instructions.  */

  712. static void
  713. next_command (char *count_string, int from_tty)
  714. {
  715.   step_1 (1, 0, count_string);
  716. }

  717. /* Likewise, but step only one instruction.  */

  718. static void
  719. stepi_command (char *count_string, int from_tty)
  720. {
  721.   step_1 (0, 1, count_string);
  722. }

  723. static void
  724. nexti_command (char *count_string, int from_tty)
  725. {
  726.   step_1 (1, 1, count_string);
  727. }

  728. void
  729. delete_longjmp_breakpoint_cleanup (void *arg)
  730. {
  731.   int thread = * (int *) arg;
  732.   delete_longjmp_breakpoint (thread);
  733. }

  734. static void
  735. step_1 (int skip_subroutines, int single_inst, char *count_string)
  736. {
  737.   int count = 1;
  738.   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
  739.   int async_exec;
  740.   int thread = -1;
  741.   struct cleanup *args_chain;

  742.   ERROR_NO_INFERIOR;
  743.   ensure_not_tfind_mode ();
  744.   ensure_valid_thread ();
  745.   ensure_not_running ();

  746.   count_string = strip_bg_char (count_string, &async_exec);
  747.   args_chain = make_cleanup (xfree, count_string);

  748.   prepare_execution_command (&current_target, async_exec);

  749.   count = count_string ? parse_and_eval_long (count_string) : 1;

  750.   /* Done with ARGS.  */
  751.   do_cleanups (args_chain);

  752.   if (!single_inst || skip_subroutines)                /* Leave si command alone.  */
  753.     {
  754.       struct thread_info *tp = inferior_thread ();

  755.       if (in_thread_list (inferior_ptid))
  756.          thread = pid_to_thread_id (inferior_ptid);

  757.       set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));

  758.       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
  759.     }

  760.   /* In synchronous case, all is well; each step_once call will step once.  */
  761.   if (!target_can_async_p ())
  762.     {
  763.       for (; count > 0; count--)
  764.         {
  765.           step_once (skip_subroutines, single_inst, count, thread);

  766.           if (!target_has_execution)
  767.             break;
  768.           else
  769.             {
  770.               struct thread_info *tp = inferior_thread ();

  771.               if (!tp->control.stop_step || !tp->step_multi)
  772.                 {
  773.                   /* If we stopped for some reason that is not stepping
  774.                      there are no further steps to make.  */
  775.                   tp->step_multi = 0;
  776.                   break;
  777.                 }
  778.             }
  779.         }

  780.       do_cleanups (cleanups);
  781.     }
  782.   else
  783.     {
  784.       /* In the case of an asynchronous target things get complicated;
  785.          do only one step for now, before returning control to the
  786.          event loop.  Let the continuation figure out how many other
  787.          steps we need to do, and handle them one at the time, through
  788.          step_once.  */
  789.       step_once (skip_subroutines, single_inst, count, thread);

  790.       /* We are running, and the continuation is installed.  It will
  791.          disable the longjmp breakpoint as appropriate.  */
  792.       discard_cleanups (cleanups);
  793.     }
  794. }

  795. struct step_1_continuation_args
  796. {
  797.   int count;
  798.   int skip_subroutines;
  799.   int single_inst;
  800.   int thread;
  801. };

  802. /* Called after we are done with one step operation, to check whether
  803.    we need to step again, before we print the prompt and return control
  804.    to the user.  If count is > 1, we will need to do one more call to
  805.    proceed(), via step_once().  Basically it is like step_once and
  806.    step_1_continuation are co-recursive.  */

  807. static void
  808. step_1_continuation (void *args, int err)
  809. {
  810.   struct step_1_continuation_args *a = args;

  811.   if (target_has_execution)
  812.     {
  813.       struct thread_info *tp;

  814.       tp = inferior_thread ();
  815.       if (!err
  816.           && tp->step_multi && tp->control.stop_step)
  817.         {
  818.           /* There are more steps to make, and we did stop due to
  819.              ending a stepping range.  Do another step.  */
  820.           step_once (a->skip_subroutines, a->single_inst,
  821.                      a->count - 1, a->thread);
  822.           return;
  823.         }
  824.       tp->step_multi = 0;
  825.     }

  826.   /* We either hit an error, or stopped for some reason that is
  827.      not stepping, or there are no further steps to make.
  828.      Cleanup.  */
  829.   if (!a->single_inst || a->skip_subroutines)
  830.     delete_longjmp_breakpoint (a->thread);
  831. }

  832. /* Do just one step operation.  This is useful to implement the 'step
  833.    n' kind of commands.  In case of asynchronous targets, we will have
  834.    to set up a continuation to be done after the target stops (after
  835.    this one step).  For synch targets, the caller handles further
  836.    stepping.  */

  837. static void
  838. step_once (int skip_subroutines, int single_inst, int count, int thread)
  839. {
  840.   struct frame_info *frame = get_current_frame ();

  841.   if (count > 0)
  842.     {
  843.       /* Don't assume THREAD is a valid thread id.  It is set to -1 if
  844.          the longjmp breakpoint was not required.  Use the
  845.          INFERIOR_PTID thread instead, which is the same thread when
  846.          THREAD is set.  */
  847.       struct thread_info *tp = inferior_thread ();

  848.       clear_proceed_status (!skip_subroutines);
  849.       set_step_frame ();

  850.       if (!single_inst)
  851.         {
  852.           CORE_ADDR pc;

  853.           /* Step at an inlined function behaves like "down".  */
  854.           if (!skip_subroutines
  855.               && inline_skipped_frames (inferior_ptid))
  856.             {
  857.               ptid_t resume_ptid;

  858.               /* Pretend that we've ran.  */
  859.               resume_ptid = user_visible_resume_ptid (1);
  860.               set_running (resume_ptid, 1);

  861.               step_into_inline_frame (inferior_ptid);
  862.               if (count > 1)
  863.                 step_once (skip_subroutines, single_inst, count - 1, thread);
  864.               else
  865.                 {
  866.                   /* Pretend that we've stopped.  */
  867.                   normal_stop ();

  868.                   if (target_can_async_p ())
  869.                     inferior_event_handler (INF_EXEC_COMPLETE, NULL);
  870.                 }
  871.               return;
  872.             }

  873.           pc = get_frame_pc (frame);
  874.           find_pc_line_pc_range (pc,
  875.                                  &tp->control.step_range_start,
  876.                                  &tp->control.step_range_end);

  877.           tp->control.may_range_step = 1;

  878.           /* If we have no line info, switch to stepi mode.  */
  879.           if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
  880.             {
  881.               tp->control.step_range_start = tp->control.step_range_end = 1;
  882.               tp->control.may_range_step = 0;
  883.             }
  884.           else if (tp->control.step_range_end == 0)
  885.             {
  886.               const char *name;

  887.               if (find_pc_partial_function (pc, &name,
  888.                                             &tp->control.step_range_start,
  889.                                             &tp->control.step_range_end) == 0)
  890.                 error (_("Cannot find bounds of current function"));

  891.               target_terminal_ours ();
  892.               printf_filtered (_("Single stepping until exit from function %s,"
  893.                                  "\nwhich has no line number information.\n"),
  894.                                name);
  895.             }
  896.         }
  897.       else
  898.         {
  899.           /* Say we are stepping, but stop after one insn whatever it does.  */
  900.           tp->control.step_range_start = tp->control.step_range_end = 1;
  901.           if (!skip_subroutines)
  902.             /* It is stepi.
  903.                Don't step over function calls, not even to functions lacking
  904.                line numbers.  */
  905.             tp->control.step_over_calls = STEP_OVER_NONE;
  906.         }

  907.       if (skip_subroutines)
  908.         tp->control.step_over_calls = STEP_OVER_ALL;

  909.       tp->step_multi = (count > 1);
  910.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);

  911.       /* For async targets, register a continuation to do any
  912.          additional steps.  For sync targets, the caller will handle
  913.          further stepping.  */
  914.       if (target_can_async_p ())
  915.         {
  916.           struct step_1_continuation_args *args;

  917.           args = xmalloc (sizeof (*args));
  918.           args->skip_subroutines = skip_subroutines;
  919.           args->single_inst = single_inst;
  920.           args->count = count;
  921.           args->thread = thread;

  922.           add_intermediate_continuation (tp, step_1_continuation, args, xfree);
  923.         }
  924.     }
  925. }


  926. /* Continue program at specified address.  */

  927. static void
  928. jump_command (char *arg, int from_tty)
  929. {
  930.   struct gdbarch *gdbarch = get_current_arch ();
  931.   CORE_ADDR addr;
  932.   struct symtabs_and_lines sals;
  933.   struct symtab_and_line sal;
  934.   struct symbol *fn;
  935.   struct symbol *sfn;
  936.   int async_exec;
  937.   struct cleanup *args_chain;

  938.   ERROR_NO_INFERIOR;
  939.   ensure_not_tfind_mode ();
  940.   ensure_valid_thread ();
  941.   ensure_not_running ();

  942.   /* Find out whether we must run in the background.  */
  943.   arg = strip_bg_char (arg, &async_exec);
  944.   args_chain = make_cleanup (xfree, arg);

  945.   prepare_execution_command (&current_target, async_exec);

  946.   if (!arg)
  947.     error_no_arg (_("starting address"));

  948.   sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
  949.   if (sals.nelts != 1)
  950.     {
  951.       error (_("Unreasonable jump request"));
  952.     }

  953.   sal = sals.sals[0];
  954.   xfree (sals.sals);

  955.   /* Done with ARGS.  */
  956.   do_cleanups (args_chain);

  957.   if (sal.symtab == 0 && sal.pc == 0)
  958.     error (_("No source file has been specified."));

  959.   resolve_sal_pc (&sal);        /* May error out.  */

  960.   /* See if we are trying to jump to another function.  */
  961.   fn = get_frame_function (get_current_frame ());
  962.   sfn = find_pc_function (sal.pc);
  963.   if (fn != NULL && sfn != fn)
  964.     {
  965.       if (!query (_("Line %d is not in `%s'.  Jump anyway? "), sal.line,
  966.                   SYMBOL_PRINT_NAME (fn)))
  967.         {
  968.           error (_("Not confirmed."));
  969.           /* NOTREACHED */
  970.         }
  971.     }

  972.   if (sfn != NULL)
  973.     {
  974.       struct obj_section *section;

  975.       fixup_symbol_section (sfn, 0);
  976.       section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
  977.       if (section_is_overlay (section)
  978.           && !section_is_mapped (section))
  979.         {
  980.           if (!query (_("WARNING!!!  Destination is in "
  981.                         "unmapped overlay!  Jump anyway? ")))
  982.             {
  983.               error (_("Not confirmed."));
  984.               /* NOTREACHED */
  985.             }
  986.         }
  987.     }

  988.   addr = sal.pc;

  989.   if (from_tty)
  990.     {
  991.       printf_filtered (_("Continuing at "));
  992.       fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
  993.       printf_filtered (".\n");
  994.     }

  995.   clear_proceed_status (0);
  996.   proceed (addr, GDB_SIGNAL_0, 0);
  997. }


  998. /* Go to line or address in current procedure.  */

  999. static void
  1000. go_command (char *line_no, int from_tty)
  1001. {
  1002.   if (line_no == (char *) NULL || !*line_no)
  1003.     printf_filtered (_("Usage: go <location>\n"));
  1004.   else
  1005.     {
  1006.       tbreak_command (line_no, from_tty);
  1007.       jump_command (line_no, from_tty);
  1008.     }
  1009. }


  1010. /* Continue program giving it specified signal.  */

  1011. static void
  1012. signal_command (char *signum_exp, int from_tty)
  1013. {
  1014.   enum gdb_signal oursig;
  1015.   int async_exec;
  1016.   struct cleanup *args_chain;

  1017.   dont_repeat ();                /* Too dangerous.  */
  1018.   ERROR_NO_INFERIOR;
  1019.   ensure_not_tfind_mode ();
  1020.   ensure_valid_thread ();
  1021.   ensure_not_running ();

  1022.   /* Find out whether we must run in the background.  */
  1023.   signum_exp = strip_bg_char (signum_exp, &async_exec);
  1024.   args_chain = make_cleanup (xfree, signum_exp);

  1025.   prepare_execution_command (&current_target, async_exec);

  1026.   if (!signum_exp)
  1027.     error_no_arg (_("signal number"));

  1028.   /* It would be even slicker to make signal names be valid expressions,
  1029.      (the type could be "enum $signal" or some such), then the user could
  1030.      assign them to convenience variables.  */
  1031.   oursig = gdb_signal_from_name (signum_exp);

  1032.   if (oursig == GDB_SIGNAL_UNKNOWN)
  1033.     {
  1034.       /* No, try numeric.  */
  1035.       int num = parse_and_eval_long (signum_exp);

  1036.       if (num == 0)
  1037.         oursig = GDB_SIGNAL_0;
  1038.       else
  1039.         oursig = gdb_signal_from_command (num);
  1040.     }

  1041.   /* Look for threads other than the current that this command ends up
  1042.      resuming too (due to schedlock off), and warn if they'll get a
  1043.      signal delivered.  "signal 0" is used to suppress a previous
  1044.      signal, but if the current thread is no longer the one that got
  1045.      the signal, then the user is potentially suppressing the signal
  1046.      of the wrong thread.  */
  1047.   if (!non_stop)
  1048.     {
  1049.       struct thread_info *tp;
  1050.       ptid_t resume_ptid;
  1051.       int must_confirm = 0;

  1052.       /* This indicates what will be resumed.  Either a single thread,
  1053.          a whole process, or all threads of all processes.  */
  1054.       resume_ptid = user_visible_resume_ptid (0);

  1055.       ALL_NON_EXITED_THREADS (tp)
  1056.         {
  1057.           if (ptid_equal (tp->ptid, inferior_ptid))
  1058.             continue;
  1059.           if (!ptid_match (tp->ptid, resume_ptid))
  1060.             continue;

  1061.           if (tp->suspend.stop_signal != GDB_SIGNAL_0
  1062.               && signal_pass_state (tp->suspend.stop_signal))
  1063.             {
  1064.               if (!must_confirm)
  1065.                 printf_unfiltered (_("Note:\n"));
  1066.               printf_unfiltered (_("  Thread %d previously stopped with signal %s, %s.\n"),
  1067.                                  tp->num,
  1068.                                  gdb_signal_to_name (tp->suspend.stop_signal),
  1069.                                  gdb_signal_to_string (tp->suspend.stop_signal));
  1070.               must_confirm = 1;
  1071.             }
  1072.         }

  1073.       if (must_confirm
  1074.           && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
  1075.                        "still deliver the signals noted above to their respective threads.\n"
  1076.                        "Continue anyway? "),
  1077.                      inferior_thread ()->num))
  1078.         error (_("Not confirmed."));
  1079.     }

  1080.   if (from_tty)
  1081.     {
  1082.       if (oursig == GDB_SIGNAL_0)
  1083.         printf_filtered (_("Continuing with no signal.\n"));
  1084.       else
  1085.         printf_filtered (_("Continuing with signal %s.\n"),
  1086.                          gdb_signal_to_name (oursig));
  1087.     }

  1088.   clear_proceed_status (0);
  1089.   proceed ((CORE_ADDR) -1, oursig, 0);
  1090. }

  1091. /* Queue a signal to be delivered to the current thread.  */

  1092. static void
  1093. queue_signal_command (char *signum_exp, int from_tty)
  1094. {
  1095.   enum gdb_signal oursig;
  1096.   struct thread_info *tp;

  1097.   ERROR_NO_INFERIOR;
  1098.   ensure_not_tfind_mode ();
  1099.   ensure_valid_thread ();
  1100.   ensure_not_running ();

  1101.   if (signum_exp == NULL)
  1102.     error_no_arg (_("signal number"));

  1103.   /* It would be even slicker to make signal names be valid expressions,
  1104.      (the type could be "enum $signal" or some such), then the user could
  1105.      assign them to convenience variables.  */
  1106.   oursig = gdb_signal_from_name (signum_exp);

  1107.   if (oursig == GDB_SIGNAL_UNKNOWN)
  1108.     {
  1109.       /* No, try numeric.  */
  1110.       int num = parse_and_eval_long (signum_exp);

  1111.       if (num == 0)
  1112.         oursig = GDB_SIGNAL_0;
  1113.       else
  1114.         oursig = gdb_signal_from_command (num);
  1115.     }

  1116.   if (oursig != GDB_SIGNAL_0
  1117.       && !signal_pass_state (oursig))
  1118.     error (_("Signal handling set to not pass this signal to the program."));

  1119.   tp = inferior_thread ();
  1120.   tp->suspend.stop_signal = oursig;
  1121. }

  1122. /* Continuation args to be passed to the "until" command
  1123.    continuation.  */
  1124. struct until_next_continuation_args
  1125. {
  1126.   /* The thread that was current when the command was executed.  */
  1127.   int thread;
  1128. };

  1129. /* A continuation callback for until_next_command.  */

  1130. static void
  1131. until_next_continuation (void *arg, int err)
  1132. {
  1133.   struct until_next_continuation_args *a = arg;

  1134.   delete_longjmp_breakpoint (a->thread);
  1135. }

  1136. /* Proceed until we reach a different source line with pc greater than
  1137.    our current one or exit the function.  We skip calls in both cases.

  1138.    Note that eventually this command should probably be changed so
  1139.    that only source lines are printed out when we hit the breakpoint
  1140.    we set.  This may involve changes to wait_for_inferior and the
  1141.    proceed status code.  */

  1142. static void
  1143. until_next_command (int from_tty)
  1144. {
  1145.   struct frame_info *frame;
  1146.   CORE_ADDR pc;
  1147.   struct symbol *func;
  1148.   struct symtab_and_line sal;
  1149.   struct thread_info *tp = inferior_thread ();
  1150.   int thread = tp->num;
  1151.   struct cleanup *old_chain;

  1152.   clear_proceed_status (0);
  1153.   set_step_frame ();

  1154.   frame = get_current_frame ();

  1155.   /* Step until either exited from this function or greater
  1156.      than the current line (if in symbolic section) or pc (if
  1157.      not).  */

  1158.   pc = get_frame_pc (frame);
  1159.   func = find_pc_function (pc);

  1160.   if (!func)
  1161.     {
  1162.       struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);

  1163.       if (msymbol.minsym == NULL)
  1164.         error (_("Execution is not within a known function."));

  1165.       tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
  1166.       /* The upper-bound of step_range is exclusive.  In order to make PC
  1167.          within the range, set the step_range_end with PC + 1.  */
  1168.       tp->control.step_range_end = pc + 1;
  1169.     }
  1170.   else
  1171.     {
  1172.       sal = find_pc_line (pc, 0);

  1173.       tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
  1174.       tp->control.step_range_end = sal.end;
  1175.     }
  1176.   tp->control.may_range_step = 1;

  1177.   tp->control.step_over_calls = STEP_OVER_ALL;

  1178.   tp->step_multi = 0;                /* Only one call to proceed */

  1179.   set_longjmp_breakpoint (tp, get_frame_id (frame));
  1180.   old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);

  1181.   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);

  1182.   if (target_can_async_p () && is_running (inferior_ptid))
  1183.     {
  1184.       struct until_next_continuation_args *cont_args;

  1185.       discard_cleanups (old_chain);
  1186.       cont_args = XNEW (struct until_next_continuation_args);
  1187.       cont_args->thread = inferior_thread ()->num;

  1188.       add_continuation (tp, until_next_continuation, cont_args, xfree);
  1189.     }
  1190.   else
  1191.     do_cleanups (old_chain);
  1192. }

  1193. static void
  1194. until_command (char *arg, int from_tty)
  1195. {
  1196.   int async_exec;
  1197.   struct cleanup *args_chain;

  1198.   ERROR_NO_INFERIOR;
  1199.   ensure_not_tfind_mode ();
  1200.   ensure_valid_thread ();
  1201.   ensure_not_running ();

  1202.   /* Find out whether we must run in the background.  */
  1203.   arg = strip_bg_char (arg, &async_exec);
  1204.   args_chain = make_cleanup (xfree, arg);

  1205.   prepare_execution_command (&current_target, async_exec);

  1206.   if (arg)
  1207.     until_break_command (arg, from_tty, 0);
  1208.   else
  1209.     until_next_command (from_tty);

  1210.   /* Done with ARGS.  */
  1211.   do_cleanups (args_chain);
  1212. }

  1213. static void
  1214. advance_command (char *arg, int from_tty)
  1215. {
  1216.   int async_exec;
  1217.   struct cleanup *args_chain;

  1218.   ERROR_NO_INFERIOR;
  1219.   ensure_not_tfind_mode ();
  1220.   ensure_valid_thread ();
  1221.   ensure_not_running ();

  1222.   if (arg == NULL)
  1223.     error_no_arg (_("a location"));

  1224.   /* Find out whether we must run in the background.  */
  1225.   arg = strip_bg_char (arg, &async_exec);
  1226.   args_chain = make_cleanup (xfree, arg);

  1227.   prepare_execution_command (&current_target, async_exec);

  1228.   until_break_command (arg, from_tty, 1);

  1229.   /* Done with ARGS.  */
  1230.   do_cleanups (args_chain);
  1231. }

  1232. /* Return the value of the result of a function at the end of a 'finish'
  1233.    command/BP.  */

  1234. struct value *
  1235. get_return_value (struct value *function, struct type *value_type)
  1236. {
  1237.   struct regcache *stop_regs = stop_registers;
  1238.   struct gdbarch *gdbarch;
  1239.   struct value *value;
  1240.   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);

  1241.   /* If stop_registers were not saved, use the current registers.  */
  1242.   if (!stop_regs)
  1243.     {
  1244.       stop_regs = regcache_dup (get_current_regcache ());
  1245.       make_cleanup_regcache_xfree (stop_regs);
  1246.     }

  1247.   gdbarch = get_regcache_arch (stop_regs);

  1248.   CHECK_TYPEDEF (value_type);
  1249.   gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);

  1250.   /* FIXME: 2003-09-27: When returning from a nested inferior function
  1251.      call, it's possible (with no help from the architecture vector)
  1252.      to locate and return/print a "struct return" value.  This is just
  1253.      a more complicated case of what is already being done in the
  1254.      inferior function call code.  In fact, when inferior function
  1255.      calls are made async, this will likely be made the norm.  */

  1256.   switch (gdbarch_return_value (gdbarch, function, value_type,
  1257.                                   NULL, NULL, NULL))
  1258.     {
  1259.     case RETURN_VALUE_REGISTER_CONVENTION:
  1260.     case RETURN_VALUE_ABI_RETURNS_ADDRESS:
  1261.     case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
  1262.       value = allocate_value (value_type);
  1263.       gdbarch_return_value (gdbarch, function, value_type, stop_regs,
  1264.                             value_contents_raw (value), NULL);
  1265.       break;
  1266.     case RETURN_VALUE_STRUCT_CONVENTION:
  1267.       value = NULL;
  1268.       break;
  1269.     default:
  1270.       internal_error (__FILE__, __LINE__, _("bad switch"));
  1271.     }

  1272.   do_cleanups (cleanup);

  1273.   return value;
  1274. }

  1275. /* Print the result of a function at the end of a 'finish' command.  */

  1276. static void
  1277. print_return_value (struct value *function, struct type *value_type)
  1278. {
  1279.   struct value *value = get_return_value (function, value_type);
  1280.   struct ui_out *uiout = current_uiout;

  1281.   if (value)
  1282.     {
  1283.       struct value_print_options opts;
  1284.       struct ui_file *stb;
  1285.       struct cleanup *old_chain;

  1286.       /* Print it.  */
  1287.       stb = mem_fileopen ();
  1288.       old_chain = make_cleanup_ui_file_delete (stb);
  1289.       ui_out_text (uiout, "Value returned is ");
  1290.       ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
  1291.                         record_latest_value (value));
  1292.       ui_out_text (uiout, " = ");
  1293.       get_no_prettyformat_print_options (&opts);
  1294.       value_print (value, stb, &opts);
  1295.       ui_out_field_stream (uiout, "return-value", stb);
  1296.       ui_out_text (uiout, "\n");
  1297.       do_cleanups (old_chain);
  1298.     }
  1299.   else
  1300.     {
  1301.       ui_out_text (uiout, "Value returned has type: ");
  1302.       ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
  1303.       ui_out_text (uiout, ".");
  1304.       ui_out_text (uiout, " Cannot determine contents\n");
  1305.     }
  1306. }

  1307. /* Stuff that needs to be done by the finish command after the target
  1308.    has stopped.  In asynchronous mode, we wait for the target to stop
  1309.    in the call to poll or select in the event loop, so it is
  1310.    impossible to do all the stuff as part of the finish_command
  1311.    function itself.  The only chance we have to complete this command
  1312.    is in fetch_inferior_event, which is called by the event loop as
  1313.    soon as it detects that the target has stopped.  */

  1314. struct finish_command_continuation_args
  1315. {
  1316.   /* The thread that as current when the command was executed.  */
  1317.   int thread;
  1318.   struct breakpoint *breakpoint;
  1319.   struct symbol *function;
  1320. };

  1321. static void
  1322. finish_command_continuation (void *arg, int err)
  1323. {
  1324.   struct finish_command_continuation_args *a = arg;

  1325.   if (!err)
  1326.     {
  1327.       struct thread_info *tp = NULL;
  1328.       bpstat bs = NULL;

  1329.       if (!ptid_equal (inferior_ptid, null_ptid)
  1330.           && target_has_execution
  1331.           && is_stopped (inferior_ptid))
  1332.         {
  1333.           tp = inferior_thread ();
  1334.           bs = tp->control.stop_bpstat;
  1335.         }

  1336.       if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
  1337.           && a->function != NULL)
  1338.         {
  1339.           struct type *value_type;

  1340.           value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
  1341.           if (!value_type)
  1342.             internal_error (__FILE__, __LINE__,
  1343.                             _("finish_command: function has no target type"));

  1344.           if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
  1345.             {
  1346.               volatile struct gdb_exception ex;
  1347.               struct value *func;

  1348.               func = read_var_value (a->function, get_current_frame ());
  1349.               TRY_CATCH (ex, RETURN_MASK_ALL)
  1350.                 {
  1351.                   /* print_return_value can throw an exception in some
  1352.                      circumstances.  We need to catch this so that we still
  1353.                      delete the breakpoint.  */
  1354.                   print_return_value (func, value_type);
  1355.                 }
  1356.               if (ex.reason < 0)
  1357.                 exception_print (gdb_stdout, ex);
  1358.             }
  1359.         }

  1360.       /* We suppress normal call of normal_stop observer and do it
  1361.          here so that the *stopped notification includes the return
  1362.          value.  */
  1363.       if (bs != NULL && tp->control.proceed_to_finish)
  1364.         observer_notify_normal_stop (bs, 1 /* print frame */);
  1365.     }

  1366.   delete_breakpoint (a->breakpoint);
  1367.   delete_longjmp_breakpoint (a->thread);
  1368. }

  1369. static void
  1370. finish_command_continuation_free_arg (void *arg)
  1371. {
  1372.   xfree (arg);
  1373. }

  1374. /* finish_backward -- helper function for finish_command.  */

  1375. static void
  1376. finish_backward (struct symbol *function)
  1377. {
  1378.   struct symtab_and_line sal;
  1379.   struct thread_info *tp = inferior_thread ();
  1380.   CORE_ADDR pc;
  1381.   CORE_ADDR func_addr;

  1382.   pc = get_frame_pc (get_current_frame ());

  1383.   if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
  1384.     error (_("Cannot find bounds of current function"));

  1385.   sal = find_pc_line (func_addr, 0);

  1386.   tp->control.proceed_to_finish = 1;
  1387.   /* Special case: if we're sitting at the function entry point,
  1388.      then all we need to do is take a reverse singlestep.  We
  1389.      don't need to set a breakpoint, and indeed it would do us
  1390.      no good to do so.

  1391.      Note that this can only happen at frame #0, since there's
  1392.      no way that a function up the stack can have a return address
  1393.      that's equal to its entry point.  */

  1394.   if (sal.pc != pc)
  1395.     {
  1396.       struct frame_info *frame = get_selected_frame (NULL);
  1397.       struct gdbarch *gdbarch = get_frame_arch (frame);
  1398.       struct symtab_and_line sr_sal;

  1399.       /* Set a step-resume at the function's entry point.  Once that's
  1400.          hit, we'll do one more step backwards.  */
  1401.       init_sal (&sr_sal);
  1402.       sr_sal.pc = sal.pc;
  1403.       sr_sal.pspace = get_frame_program_space (frame);
  1404.       insert_step_resume_breakpoint_at_sal (gdbarch,
  1405.                                             sr_sal, null_frame_id);

  1406.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
  1407.     }
  1408.   else
  1409.     {
  1410.       /* We're almost there -- we just need to back up by one more
  1411.          single-step.  */
  1412.       tp->control.step_range_start = tp->control.step_range_end = 1;
  1413.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
  1414.     }
  1415. }

  1416. /* finish_forward -- helper function for finish_command.  */

  1417. static void
  1418. finish_forward (struct symbol *function, struct frame_info *frame)
  1419. {
  1420.   struct frame_id frame_id = get_frame_id (frame);
  1421.   struct gdbarch *gdbarch = get_frame_arch (frame);
  1422.   struct symtab_and_line sal;
  1423.   struct thread_info *tp = inferior_thread ();
  1424.   struct breakpoint *breakpoint;
  1425.   struct cleanup *old_chain;
  1426.   struct finish_command_continuation_args *cargs;
  1427.   int thread = tp->num;

  1428.   sal = find_pc_line (get_frame_pc (frame), 0);
  1429.   sal.pc = get_frame_pc (frame);

  1430.   breakpoint = set_momentary_breakpoint (gdbarch, sal,
  1431.                                          get_stack_frame_id (frame),
  1432.                                          bp_finish);

  1433.   /* set_momentary_breakpoint invalidates FRAME.  */
  1434.   frame = NULL;

  1435.   old_chain = make_cleanup_delete_breakpoint (breakpoint);

  1436.   set_longjmp_breakpoint (tp, frame_id);
  1437.   make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);

  1438.   /* We want stop_registers, please...  */
  1439.   tp->control.proceed_to_finish = 1;
  1440.   cargs = xmalloc (sizeof (*cargs));

  1441.   cargs->thread = thread;
  1442.   cargs->breakpoint = breakpoint;
  1443.   cargs->function = function;
  1444.   add_continuation (tp, finish_command_continuation, cargs,
  1445.                     finish_command_continuation_free_arg);
  1446.   proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);

  1447.   discard_cleanups (old_chain);
  1448.   if (!target_can_async_p ())
  1449.     do_all_continuations (0);
  1450. }

  1451. /* "finish": Set a temporary breakpoint at the place the selected
  1452.    frame will return to, then continue.  */

  1453. static void
  1454. finish_command (char *arg, int from_tty)
  1455. {
  1456.   struct frame_info *frame;
  1457.   struct symbol *function;
  1458.   int async_exec;
  1459.   struct cleanup *args_chain;

  1460.   ERROR_NO_INFERIOR;
  1461.   ensure_not_tfind_mode ();
  1462.   ensure_valid_thread ();
  1463.   ensure_not_running ();

  1464.   /* Find out whether we must run in the background.  */
  1465.   arg = strip_bg_char (arg, &async_exec);
  1466.   args_chain = make_cleanup (xfree, arg);

  1467.   prepare_execution_command (&current_target, async_exec);

  1468.   if (arg)
  1469.     error (_("The \"finish\" command does not take any arguments."));

  1470.   /* Done with ARGS.  */
  1471.   do_cleanups (args_chain);

  1472.   frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
  1473.   if (frame == 0)
  1474.     error (_("\"finish\" not meaningful in the outermost frame."));

  1475.   clear_proceed_status (0);

  1476.   /* Finishing from an inline frame is completely different.  We don't
  1477.      try to show the "return value" - no way to locate it.  So we do
  1478.      not need a completion.  */
  1479.   if (get_frame_type (get_selected_frame (_("No selected frame.")))
  1480.       == INLINE_FRAME)
  1481.     {
  1482.       /* Claim we are stepping in the calling frame.  An empty step
  1483.          range means that we will stop once we aren't in a function
  1484.          called by that frame.  We don't use the magic "1" value for
  1485.          step_range_end, because then infrun will think this is nexti,
  1486.          and not step over the rest of this inlined function call.  */
  1487.       struct thread_info *tp = inferior_thread ();
  1488.       struct symtab_and_line empty_sal;

  1489.       init_sal (&empty_sal);
  1490.       set_step_info (frame, empty_sal);
  1491.       tp->control.step_range_start = get_frame_pc (frame);
  1492.       tp->control.step_range_end = tp->control.step_range_start;
  1493.       tp->control.step_over_calls = STEP_OVER_ALL;

  1494.       /* Print info on the selected frame, including level number but not
  1495.          source.  */
  1496.       if (from_tty)
  1497.         {
  1498.           printf_filtered (_("Run till exit from "));
  1499.           print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
  1500.         }

  1501.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 1);
  1502.       return;
  1503.     }

  1504.   /* Ignore TAILCALL_FRAME type frames, they were executed already before
  1505.      entering THISFRAME.  */
  1506.   while (get_frame_type (frame) == TAILCALL_FRAME)
  1507.     frame = get_prev_frame (frame);

  1508.   /* Find the function we will return from.  */

  1509.   function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));

  1510.   /* Print info on the selected frame, including level number but not
  1511.      source.  */
  1512.   if (from_tty)
  1513.     {
  1514.       if (execution_direction == EXEC_REVERSE)
  1515.         printf_filtered (_("Run back to call of "));
  1516.       else
  1517.         printf_filtered (_("Run till exit from "));

  1518.       print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
  1519.     }

  1520.   if (execution_direction == EXEC_REVERSE)
  1521.     finish_backward (function);
  1522.   else
  1523.     finish_forward (function, frame);
  1524. }


  1525. static void
  1526. program_info (char *args, int from_tty)
  1527. {
  1528.   bpstat bs;
  1529.   int num, stat;
  1530.   struct thread_info *tp;
  1531.   ptid_t ptid;

  1532.   if (!target_has_execution)
  1533.     {
  1534.       printf_filtered (_("The program being debugged is not being run.\n"));
  1535.       return;
  1536.     }

  1537.   if (non_stop)
  1538.     ptid = inferior_ptid;
  1539.   else
  1540.     {
  1541.       struct target_waitstatus ws;

  1542.       get_last_target_status (&ptid, &ws);
  1543.     }

  1544.   if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
  1545.     error (_("Invalid selected thread."));
  1546.   else if (is_running (ptid))
  1547.     error (_("Selected thread is running."));

  1548.   tp = find_thread_ptid (ptid);
  1549.   bs = tp->control.stop_bpstat;
  1550.   stat = bpstat_num (&bs, &num);

  1551.   target_files_info ();
  1552.   printf_filtered (_("Program stopped at %s.\n"),
  1553.                    paddress (target_gdbarch (), stop_pc));
  1554.   if (tp->control.stop_step)
  1555.     printf_filtered (_("It stopped after being stepped.\n"));
  1556.   else if (stat != 0)
  1557.     {
  1558.       /* There may be several breakpoints in the same place, so this
  1559.          isn't as strange as it seems.  */
  1560.       while (stat != 0)
  1561.         {
  1562.           if (stat < 0)
  1563.             {
  1564.               printf_filtered (_("It stopped at a breakpoint "
  1565.                                  "that has since been deleted.\n"));
  1566.             }
  1567.           else
  1568.             printf_filtered (_("It stopped at breakpoint %d.\n"), num);
  1569.           stat = bpstat_num (&bs, &num);
  1570.         }
  1571.     }
  1572.   else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
  1573.     {
  1574.       printf_filtered (_("It stopped with signal %s, %s.\n"),
  1575.                        gdb_signal_to_name (tp->suspend.stop_signal),
  1576.                        gdb_signal_to_string (tp->suspend.stop_signal));
  1577.     }

  1578.   if (from_tty)
  1579.     {
  1580.       printf_filtered (_("Type \"info stack\" or \"info "
  1581.                          "registers\" for more information.\n"));
  1582.     }
  1583. }

  1584. static void
  1585. environment_info (char *var, int from_tty)
  1586. {
  1587.   if (var)
  1588.     {
  1589.       char *val = get_in_environ (current_inferior ()->environment, var);

  1590.       if (val)
  1591.         {
  1592.           puts_filtered (var);
  1593.           puts_filtered (" = ");
  1594.           puts_filtered (val);
  1595.           puts_filtered ("\n");
  1596.         }
  1597.       else
  1598.         {
  1599.           puts_filtered ("Environment variable \"");
  1600.           puts_filtered (var);
  1601.           puts_filtered ("\" not defined.\n");
  1602.         }
  1603.     }
  1604.   else
  1605.     {
  1606.       char **vector = environ_vector (current_inferior ()->environment);

  1607.       while (*vector)
  1608.         {
  1609.           puts_filtered (*vector++);
  1610.           puts_filtered ("\n");
  1611.         }
  1612.     }
  1613. }

  1614. static void
  1615. set_environment_command (char *arg, int from_tty)
  1616. {
  1617.   char *p, *val, *var;
  1618.   int nullset = 0;

  1619.   if (arg == 0)
  1620.     error_no_arg (_("environment variable and value"));

  1621.   /* Find seperation between variable name and value.  */
  1622.   p = (char *) strchr (arg, '=');
  1623.   val = (char *) strchr (arg, ' ');

  1624.   if (p != 0 && val != 0)
  1625.     {
  1626.       /* We have both a space and an equals.  If the space is before the
  1627.          equals, walk forward over the spaces til we see a nonspace
  1628.          (possibly the equals).  */
  1629.       if (p > val)
  1630.         while (*val == ' ')
  1631.           val++;

  1632.       /* Now if the = is after the char following the spaces,
  1633.          take the char following the spaces.  */
  1634.       if (p > val)
  1635.         p = val - 1;
  1636.     }
  1637.   else if (val != 0 && p == 0)
  1638.     p = val;

  1639.   if (p == arg)
  1640.     error_no_arg (_("environment variable to set"));

  1641.   if (p == 0 || p[1] == 0)
  1642.     {
  1643.       nullset = 1;
  1644.       if (p == 0)
  1645.         p = arg + strlen (arg);        /* So that savestring below will work.  */
  1646.     }
  1647.   else
  1648.     {
  1649.       /* Not setting variable value to null.  */
  1650.       val = p + 1;
  1651.       while (*val == ' ' || *val == '\t')
  1652.         val++;
  1653.     }

  1654.   while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
  1655.     p--;

  1656.   var = savestring (arg, p - arg);
  1657.   if (nullset)
  1658.     {
  1659.       printf_filtered (_("Setting environment variable "
  1660.                          "\"%s\" to null value.\n"),
  1661.                        var);
  1662.       set_in_environ (current_inferior ()->environment, var, "");
  1663.     }
  1664.   else
  1665.     set_in_environ (current_inferior ()->environment, var, val);
  1666.   xfree (var);
  1667. }

  1668. static void
  1669. unset_environment_command (char *var, int from_tty)
  1670. {
  1671.   if (var == 0)
  1672.     {
  1673.       /* If there is no argument, delete all environment variables.
  1674.          Ask for confirmation if reading from the terminal.  */
  1675.       if (!from_tty || query (_("Delete all environment variables? ")))
  1676.         {
  1677.           free_environ (current_inferior ()->environment);
  1678.           current_inferior ()->environment = make_environ ();
  1679.         }
  1680.     }
  1681.   else
  1682.     unset_in_environ (current_inferior ()->environment, var);
  1683. }

  1684. /* Handle the execution path (PATH variable).  */

  1685. static const char path_var_name[] = "PATH";

  1686. static void
  1687. path_info (char *args, int from_tty)
  1688. {
  1689.   puts_filtered ("Executable and object file path: ");
  1690.   puts_filtered (get_in_environ (current_inferior ()->environment,
  1691.                                  path_var_name));
  1692.   puts_filtered ("\n");
  1693. }

  1694. /* Add zero or more directories to the front of the execution path.  */

  1695. static void
  1696. path_command (char *dirname, int from_tty)
  1697. {
  1698.   char *exec_path;
  1699.   char *env;

  1700.   dont_repeat ();
  1701.   env = get_in_environ (current_inferior ()->environment, path_var_name);
  1702.   /* Can be null if path is not set.  */
  1703.   if (!env)
  1704.     env = "";
  1705.   exec_path = xstrdup (env);
  1706.   mod_path (dirname, &exec_path);
  1707.   set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
  1708.   xfree (exec_path);
  1709.   if (from_tty)
  1710.     path_info ((char *) NULL, from_tty);
  1711. }


  1712. /* Print out the register NAME with value VAL, to FILE, in the default
  1713.    fashion.  */

  1714. static void
  1715. default_print_one_register_info (struct ui_file *file,
  1716.                                  const char *name,
  1717.                                  struct value *val)
  1718. {
  1719.   struct type *regtype = value_type (val);
  1720.   int print_raw_format;

  1721.   fputs_filtered (name, file);
  1722.   print_spaces_filtered (15 - strlen (name), file);

  1723.   print_raw_format = (value_entirely_available (val)
  1724.                       && !value_optimized_out (val));

  1725.   /* If virtual format is floating, print it that way, and in raw
  1726.      hex.  */
  1727.   if (TYPE_CODE (regtype) == TYPE_CODE_FLT
  1728.       || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
  1729.     {
  1730.       int j;
  1731.       struct value_print_options opts;
  1732.       const gdb_byte *valaddr = value_contents_for_printing (val);
  1733.       enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));

  1734.       get_user_print_options (&opts);
  1735.       opts.deref_ref = 1;

  1736.       val_print (regtype,
  1737.                  value_contents_for_printing (val),
  1738.                  value_embedded_offset (val), 0,
  1739.                  file, 0, val, &opts, current_language);

  1740.       if (print_raw_format)
  1741.         {
  1742.           fprintf_filtered (file, "\t(raw ");
  1743.           print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
  1744.           fprintf_filtered (file, ")");
  1745.         }
  1746.     }
  1747.   else
  1748.     {
  1749.       struct value_print_options opts;

  1750.       /* Print the register in hex.  */
  1751.       get_formatted_print_options (&opts, 'x');
  1752.       opts.deref_ref = 1;
  1753.       val_print (regtype,
  1754.                  value_contents_for_printing (val),
  1755.                  value_embedded_offset (val), 0,
  1756.                  file, 0, val, &opts, current_language);
  1757.       /* If not a vector register, print it also according to its
  1758.          natural format.  */
  1759.       if (print_raw_format && TYPE_VECTOR (regtype) == 0)
  1760.         {
  1761.           get_user_print_options (&opts);
  1762.           opts.deref_ref = 1;
  1763.           fprintf_filtered (file, "\t");
  1764.           val_print (regtype,
  1765.                      value_contents_for_printing (val),
  1766.                      value_embedded_offset (val), 0,
  1767.                      file, 0, val, &opts, current_language);
  1768.         }
  1769.     }

  1770.   fprintf_filtered (file, "\n");
  1771. }

  1772. /* Print out the machine register regnum.  If regnum is -1, print all
  1773.    registers (print_all == 1) or all non-float and non-vector
  1774.    registers (print_all == 0).

  1775.    For most machines, having all_registers_info() print the
  1776.    register(s) one per line is good enough.  If a different format is
  1777.    required, (eg, for MIPS or Pyramid 90x, which both have lots of
  1778.    regs), or there is an existing convention for showing all the
  1779.    registers, define the architecture method PRINT_REGISTERS_INFO to
  1780.    provide that format.  */

  1781. void
  1782. default_print_registers_info (struct gdbarch *gdbarch,
  1783.                               struct ui_file *file,
  1784.                               struct frame_info *frame,
  1785.                               int regnum, int print_all)
  1786. {
  1787.   int i;
  1788.   const int numregs = gdbarch_num_regs (gdbarch)
  1789.                       + gdbarch_num_pseudo_regs (gdbarch);

  1790.   for (i = 0; i < numregs; i++)
  1791.     {
  1792.       /* Decide between printing all regs, non-float / vector regs, or
  1793.          specific reg.  */
  1794.       if (regnum == -1)
  1795.         {
  1796.           if (print_all)
  1797.             {
  1798.               if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
  1799.                 continue;
  1800.             }
  1801.           else
  1802.             {
  1803.               if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
  1804.                 continue;
  1805.             }
  1806.         }
  1807.       else
  1808.         {
  1809.           if (i != regnum)
  1810.             continue;
  1811.         }

  1812.       /* If the register name is empty, it is undefined for this
  1813.          processor, so don't display anything.  */
  1814.       if (gdbarch_register_name (gdbarch, i) == NULL
  1815.           || *(gdbarch_register_name (gdbarch, i)) == '\0')
  1816.         continue;

  1817.       default_print_one_register_info (file,
  1818.                                        gdbarch_register_name (gdbarch, i),
  1819.                                        value_of_register (i, frame));
  1820.     }
  1821. }

  1822. void
  1823. registers_info (char *addr_exp, int fpregs)
  1824. {
  1825.   struct frame_info *frame;
  1826.   struct gdbarch *gdbarch;

  1827.   if (!target_has_registers)
  1828.     error (_("The program has no registers now."));
  1829.   frame = get_selected_frame (NULL);
  1830.   gdbarch = get_frame_arch (frame);

  1831.   if (!addr_exp)
  1832.     {
  1833.       gdbarch_print_registers_info (gdbarch, gdb_stdout,
  1834.                                     frame, -1, fpregs);
  1835.       return;
  1836.     }

  1837.   while (*addr_exp != '\0')
  1838.     {
  1839.       char *start;
  1840.       const char *end;

  1841.       /* Skip leading white space.  */
  1842.       addr_exp = skip_spaces (addr_exp);

  1843.       /* Discard any leading ``$''.  Check that there is something
  1844.          resembling a register following it.  */
  1845.       if (addr_exp[0] == '$')
  1846.         addr_exp++;
  1847.       if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
  1848.         error (_("Missing register name"));

  1849.       /* Find the start/end of this register name/num/group.  */
  1850.       start = addr_exp;
  1851.       while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
  1852.         addr_exp++;
  1853.       end = addr_exp;

  1854.       /* Figure out what we've found and display it.  */

  1855.       /* A register name?  */
  1856.       {
  1857.         int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);

  1858.         if (regnum >= 0)
  1859.           {
  1860.             /* User registers lie completely outside of the range of
  1861.                normal registers.  Catch them early so that the target
  1862.                never sees them.  */
  1863.             if (regnum >= gdbarch_num_regs (gdbarch)
  1864.                           + gdbarch_num_pseudo_regs (gdbarch))
  1865.               {
  1866.                 struct value *regval = value_of_user_reg (regnum, frame);
  1867.                 const char *regname = user_reg_map_regnum_to_name (gdbarch,
  1868.                                                                    regnum);

  1869.                 /* Print in the same fashion
  1870.                    gdbarch_print_registers_info's default
  1871.                    implementation prints.  */
  1872.                 default_print_one_register_info (gdb_stdout,
  1873.                                                  regname,
  1874.                                                  regval);
  1875.               }
  1876.             else
  1877.               gdbarch_print_registers_info (gdbarch, gdb_stdout,
  1878.                                             frame, regnum, fpregs);
  1879.             continue;
  1880.           }
  1881.       }

  1882.       /* A register group?  */
  1883.       {
  1884.         struct reggroup *group;

  1885.         for (group = reggroup_next (gdbarch, NULL);
  1886.              group != NULL;
  1887.              group = reggroup_next (gdbarch, group))
  1888.           {
  1889.             /* Don't bother with a length check.  Should the user
  1890.                enter a short register group name, go with the first
  1891.                group that matches.  */
  1892.             if (strncmp (start, reggroup_name (group), end - start) == 0)
  1893.               break;
  1894.           }
  1895.         if (group != NULL)
  1896.           {
  1897.             int regnum;

  1898.             for (regnum = 0;
  1899.                  regnum < gdbarch_num_regs (gdbarch)
  1900.                           + gdbarch_num_pseudo_regs (gdbarch);
  1901.                  regnum++)
  1902.               {
  1903.                 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
  1904.                   gdbarch_print_registers_info (gdbarch,
  1905.                                                 gdb_stdout, frame,
  1906.                                                 regnum, fpregs);
  1907.               }
  1908.             continue;
  1909.           }
  1910.       }

  1911.       /* Nothing matched.  */
  1912.       error (_("Invalid register `%.*s'"), (int) (end - start), start);
  1913.     }
  1914. }

  1915. static void
  1916. all_registers_info (char *addr_exp, int from_tty)
  1917. {
  1918.   registers_info (addr_exp, 1);
  1919. }

  1920. static void
  1921. nofp_registers_info (char *addr_exp, int from_tty)
  1922. {
  1923.   registers_info (addr_exp, 0);
  1924. }

  1925. static void
  1926. print_vector_info (struct ui_file *file,
  1927.                    struct frame_info *frame, const char *args)
  1928. {
  1929.   struct gdbarch *gdbarch = get_frame_arch (frame);

  1930.   if (gdbarch_print_vector_info_p (gdbarch))
  1931.     gdbarch_print_vector_info (gdbarch, file, frame, args);
  1932.   else
  1933.     {
  1934.       int regnum;
  1935.       int printed_something = 0;

  1936.       for (regnum = 0;
  1937.            regnum < gdbarch_num_regs (gdbarch)
  1938.                     + gdbarch_num_pseudo_regs (gdbarch);
  1939.            regnum++)
  1940.         {
  1941.           if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
  1942.             {
  1943.               printed_something = 1;
  1944.               gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
  1945.             }
  1946.         }
  1947.       if (!printed_something)
  1948.         fprintf_filtered (file, "No vector information\n");
  1949.     }
  1950. }

  1951. static void
  1952. vector_info (char *args, int from_tty)
  1953. {
  1954.   if (!target_has_registers)
  1955.     error (_("The program has no registers now."));

  1956.   print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
  1957. }

  1958. /* Kill the inferior process.  Make us have no inferior.  */

  1959. static void
  1960. kill_command (char *arg, int from_tty)
  1961. {
  1962.   /* FIXME:  This should not really be inferior_ptid (or target_has_execution).
  1963.      It should be a distinct flag that indicates that a target is active, cuz
  1964.      some targets don't have processes!  */

  1965.   if (ptid_equal (inferior_ptid, null_ptid))
  1966.     error (_("The program is not being run."));
  1967.   if (!query (_("Kill the program being debugged? ")))
  1968.     error (_("Not confirmed."));
  1969.   target_kill ();

  1970.   /* If we still have other inferiors to debug, then don't mess with
  1971.      with their threads.  */
  1972.   if (!have_inferiors ())
  1973.     {
  1974.       init_thread_list ();                /* Destroy thread info.  */

  1975.       /* Killing off the inferior can leave us with a core file.  If
  1976.          so, print the state we are left in.  */
  1977.       if (target_has_stack)
  1978.         {
  1979.           printf_filtered (_("In %s,\n"), target_longname);
  1980.           print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
  1981.         }
  1982.     }
  1983.   bfd_cache_close_all ();
  1984. }

  1985. /* Used in `attach&' command.  ARG is a point to an integer
  1986.    representing a process id.  Proceed threads of this process iff
  1987.    they stopped due to debugger request, and when they did, they
  1988.    reported a clean stop (GDB_SIGNAL_0).  Do not proceed threads
  1989.    that have been explicitly been told to stop.  */

  1990. static int
  1991. proceed_after_attach_callback (struct thread_info *thread,
  1992.                                void *arg)
  1993. {
  1994.   int pid = * (int *) arg;

  1995.   if (ptid_get_pid (thread->ptid) == pid
  1996.       && !is_exited (thread->ptid)
  1997.       && !is_executing (thread->ptid)
  1998.       && !thread->stop_requested
  1999.       && thread->suspend.stop_signal == GDB_SIGNAL_0)
  2000.     {
  2001.       switch_to_thread (thread->ptid);
  2002.       clear_proceed_status (0);
  2003.       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
  2004.     }

  2005.   return 0;
  2006. }

  2007. static void
  2008. proceed_after_attach (int pid)
  2009. {
  2010.   /* Don't error out if the current thread is running, because
  2011.      there may be other stopped threads.  */
  2012.   struct cleanup *old_chain;

  2013.   /* Backup current thread and selected frame.  */
  2014.   old_chain = make_cleanup_restore_current_thread ();

  2015.   iterate_over_threads (proceed_after_attach_callback, &pid);

  2016.   /* Restore selected ptid.  */
  2017.   do_cleanups (old_chain);
  2018. }

  2019. /* attach_command --
  2020.    takes a program started up outside of gdb and ``attaches'' to it.
  2021.    This stops it cold in its tracks and allows us to start debugging it.
  2022.    and wait for the trace-trap that results from attaching.  */

  2023. static void
  2024. attach_command_post_wait (char *args, int from_tty, int async_exec)
  2025. {
  2026.   char *exec_file;
  2027.   char *full_exec_path = NULL;
  2028.   struct inferior *inferior;

  2029.   inferior = current_inferior ();
  2030.   inferior->control.stop_soon = NO_STOP_QUIETLY;

  2031.   /* If no exec file is yet known, try to determine it from the
  2032.      process itself.  */
  2033.   exec_file = (char *) get_exec_file (0);
  2034.   if (!exec_file)
  2035.     {
  2036.       exec_file = target_pid_to_exec_file (ptid_get_pid (inferior_ptid));
  2037.       if (exec_file)
  2038.         {
  2039.           /* It's possible we don't have a full path, but rather just a
  2040.              filename.  Some targets, such as HP-UX, don't provide the
  2041.              full path, sigh.

  2042.              Attempt to qualify the filename against the source path.
  2043.              (If that fails, we'll just fall back on the original
  2044.              filename.  Not much more we can do...)  */

  2045.           if (!source_full_path_of (exec_file, &full_exec_path))
  2046.             full_exec_path = xstrdup (exec_file);

  2047.           exec_file_attach (full_exec_path, from_tty);
  2048.           symbol_file_add_main (full_exec_path, from_tty);
  2049.         }
  2050.     }
  2051.   else
  2052.     {
  2053.       reopen_exec_file ();
  2054.       reread_symbols ();
  2055.     }

  2056.   /* Take any necessary post-attaching actions for this platform.  */
  2057.   target_post_attach (ptid_get_pid (inferior_ptid));

  2058.   post_create_inferior (&current_target, from_tty);

  2059.   if (async_exec)
  2060.     {
  2061.       /* The user requested an `attach&', so be sure to leave threads
  2062.          that didn't get a signal running.  */

  2063.       /* Immediatelly resume all suspended threads of this inferior,
  2064.          and this inferior only.  This should have no effect on
  2065.          already running threads.  If a thread has been stopped with a
  2066.          signal, leave it be.  */
  2067.       if (non_stop)
  2068.         proceed_after_attach (inferior->pid);
  2069.       else
  2070.         {
  2071.           if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
  2072.             {
  2073.               clear_proceed_status (0);
  2074.               proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
  2075.             }
  2076.         }
  2077.     }
  2078.   else
  2079.     {
  2080.       /* The user requested a plain `attach', so be sure to leave
  2081.          the inferior stopped.  */

  2082.       if (target_can_async_p ())
  2083.         async_enable_stdin ();

  2084.       /* At least the current thread is already stopped.  */

  2085.       /* In all-stop, by definition, all threads have to be already
  2086.          stopped at this point.  In non-stop, however, although the
  2087.          selected thread is stopped, others may still be executing.
  2088.          Be sure to explicitly stop all threads of the process.  This
  2089.          should have no effect on already stopped threads.  */
  2090.       if (non_stop)
  2091.         target_stop (pid_to_ptid (inferior->pid));

  2092.       /* Tell the user/frontend where we're stopped.  */
  2093.       normal_stop ();
  2094.       if (deprecated_attach_hook)
  2095.         deprecated_attach_hook ();
  2096.     }
  2097. }

  2098. struct attach_command_continuation_args
  2099. {
  2100.   char *args;
  2101.   int from_tty;
  2102.   int async_exec;
  2103. };

  2104. static void
  2105. attach_command_continuation (void *args, int err)
  2106. {
  2107.   struct attach_command_continuation_args *a = args;

  2108.   if (err)
  2109.     return;

  2110.   attach_command_post_wait (a->args, a->from_tty, a->async_exec);
  2111. }

  2112. static void
  2113. attach_command_continuation_free_args (void *args)
  2114. {
  2115.   struct attach_command_continuation_args *a = args;

  2116.   xfree (a->args);
  2117.   xfree (a);
  2118. }

  2119. void
  2120. attach_command (char *args, int from_tty)
  2121. {
  2122.   int async_exec;
  2123.   struct cleanup *args_chain;
  2124.   struct target_ops *attach_target;

  2125.   dont_repeat ();                /* Not for the faint of heart */

  2126.   if (gdbarch_has_global_solist (target_gdbarch ()))
  2127.     /* Don't complain if all processes share the same symbol
  2128.        space.  */
  2129.     ;
  2130.   else if (target_has_execution)
  2131.     {
  2132.       if (query (_("A program is being debugged already.  Kill it? ")))
  2133.         target_kill ();
  2134.       else
  2135.         error (_("Not killed."));
  2136.     }

  2137.   /* Clean up any leftovers from other runs.  Some other things from
  2138.      this function should probably be moved into target_pre_inferior.  */
  2139.   target_pre_inferior (from_tty);

  2140.   args = strip_bg_char (args, &async_exec);
  2141.   args_chain = make_cleanup (xfree, args);

  2142.   attach_target = find_attach_target ();

  2143.   prepare_execution_command (attach_target, async_exec);

  2144.   if (non_stop && !attach_target->to_supports_non_stop (attach_target))
  2145.     error (_("Cannot attach to this target in non-stop mode"));

  2146.   attach_target->to_attach (attach_target, args, from_tty);
  2147.   /* to_attach should push the target, so after this point we
  2148.      shouldn't refer to attach_target again.  */
  2149.   attach_target = NULL;

  2150.   /* Done with ARGS.  */
  2151.   do_cleanups (args_chain);

  2152.   /* Set up the "saved terminal modes" of the inferior
  2153.      based on what modes we are starting it with.  */
  2154.   target_terminal_init ();

  2155.   /* Install inferior's terminal modes.  This may look like a no-op,
  2156.      as we've just saved them above, however, this does more than
  2157.      restore terminal settings:

  2158.      - installs a SIGINT handler that forwards SIGINT to the inferior.
  2159.        Otherwise a Ctrl-C pressed just while waiting for the initial
  2160.        stop would end up as a spurious Quit.

  2161.      - removes stdin from the event loop, which we need if attaching
  2162.        in the foreground, otherwise on targets that report an initial
  2163.        stop on attach (which are most) we'd process input/commands
  2164.        while we're in the event loop waiting for that stop.  That is,
  2165.        before the attach continuation runs and the command is really
  2166.        finished.  */
  2167.   target_terminal_inferior ();

  2168.   /* Set up execution context to know that we should return from
  2169.      wait_for_inferior as soon as the target reports a stop.  */
  2170.   init_wait_for_inferior ();
  2171.   clear_proceed_status (0);

  2172.   if (non_stop)
  2173.     {
  2174.       /* If we find that the current thread isn't stopped, explicitly
  2175.          do so now, because we're going to install breakpoints and
  2176.          poke at memory.  */

  2177.       if (async_exec)
  2178.         /* The user requested an `attach&'; stop just one thread.  */
  2179.         target_stop (inferior_ptid);
  2180.       else
  2181.         /* The user requested an `attach', so stop all threads of this
  2182.            inferior.  */
  2183.         target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
  2184.     }

  2185.   /* Some system don't generate traps when attaching to inferior.
  2186.      E.g. Mach 3 or GNU hurd.  */
  2187.   if (!target_attach_no_wait)
  2188.     {
  2189.       struct inferior *inferior = current_inferior ();

  2190.       /* Careful here.  See comments in inferior.h.  Basically some
  2191.          OSes don't ignore SIGSTOPs on continue requests anymore.  We
  2192.          need a way for handle_inferior_event to reset the stop_signal
  2193.          variable after an attach, and this is what
  2194.          STOP_QUIETLY_NO_SIGSTOP is for.  */
  2195.       inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;

  2196.       if (target_can_async_p ())
  2197.         {
  2198.           /* sync_execution mode.  Wait for stop.  */
  2199.           struct attach_command_continuation_args *a;

  2200.           a = xmalloc (sizeof (*a));
  2201.           a->args = xstrdup (args);
  2202.           a->from_tty = from_tty;
  2203.           a->async_exec = async_exec;
  2204.           add_inferior_continuation (attach_command_continuation, a,
  2205.                                      attach_command_continuation_free_args);
  2206.           return;
  2207.         }

  2208.       wait_for_inferior ();
  2209.     }

  2210.   attach_command_post_wait (args, from_tty, async_exec);
  2211. }

  2212. /* We had just found out that the target was already attached to an
  2213.    inferior.  PTID points at a thread of this new inferior, that is
  2214.    the most likely to be stopped right now, but not necessarily so.
  2215.    The new inferior is assumed to be already added to the inferior
  2216.    list at this point.  If LEAVE_RUNNING, then leave the threads of
  2217.    this inferior running, except those we've explicitly seen reported
  2218.    as stopped.  */

  2219. void
  2220. notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
  2221. {
  2222.   struct cleanup* old_chain;
  2223.   int async_exec;

  2224.   old_chain = make_cleanup (null_cleanup, NULL);

  2225.   /* If in non-stop, leave threads as running as they were.  If
  2226.      they're stopped for some reason other than us telling it to, the
  2227.      target reports a signal != GDB_SIGNAL_0.  We don't try to
  2228.      resume threads with such a stop signal.  */
  2229.   async_exec = non_stop;

  2230.   if (!ptid_equal (inferior_ptid, null_ptid))
  2231.     make_cleanup_restore_current_thread ();

  2232.   switch_to_thread (ptid);

  2233.   /* When we "notice" a new inferior we need to do all the things we
  2234.      would normally do if we had just attached to it.  */

  2235.   if (is_executing (inferior_ptid))
  2236.     {
  2237.       struct inferior *inferior = current_inferior ();

  2238.       /* We're going to install breakpoints, and poke at memory,
  2239.          ensure that the inferior is stopped for a moment while we do
  2240.          that.  */
  2241.       target_stop (inferior_ptid);

  2242.       inferior->control.stop_soon = STOP_QUIETLY_REMOTE;

  2243.       /* Wait for stop before proceeding.  */
  2244.       if (target_can_async_p ())
  2245.         {
  2246.           struct attach_command_continuation_args *a;

  2247.           a = xmalloc (sizeof (*a));
  2248.           a->args = xstrdup ("");
  2249.           a->from_tty = from_tty;
  2250.           a->async_exec = async_exec;
  2251.           add_inferior_continuation (attach_command_continuation, a,
  2252.                                      attach_command_continuation_free_args);

  2253.           do_cleanups (old_chain);
  2254.           return;
  2255.         }
  2256.       else
  2257.         wait_for_inferior ();
  2258.     }

  2259.   async_exec = leave_running;
  2260.   attach_command_post_wait ("" /* args */, from_tty, async_exec);

  2261.   do_cleanups (old_chain);
  2262. }

  2263. /*
  2264. * detach_command --
  2265. * takes a program previously attached to and detaches it.
  2266. * The program resumes execution and will no longer stop
  2267. * on signals, etc.  We better not have left any breakpoints
  2268. * in the program or it'll die when it hits one.  For this
  2269. * to work, it may be necessary for the process to have been
  2270. * previously attached.  It *might* work if the program was
  2271. * started via the normal ptrace (PTRACE_TRACEME).
  2272. */

  2273. void
  2274. detach_command (char *args, int from_tty)
  2275. {
  2276.   dont_repeat ();                /* Not for the faint of heart.  */

  2277.   if (ptid_equal (inferior_ptid, null_ptid))
  2278.     error (_("The program is not being run."));

  2279.   query_if_trace_running (from_tty);

  2280.   disconnect_tracing ();

  2281.   target_detach (args, from_tty);

  2282.   /* If the solist is global across inferiors, don't clear it when we
  2283.      detach from a single inferior.  */
  2284.   if (!gdbarch_has_global_solist (target_gdbarch ()))
  2285.     no_shared_libraries (NULL, from_tty);

  2286.   /* If we still have inferiors to debug, then don't mess with their
  2287.      threads.  */
  2288.   if (!have_inferiors ())
  2289.     init_thread_list ();

  2290.   if (deprecated_detach_hook)
  2291.     deprecated_detach_hook ();
  2292. }

  2293. /* Disconnect from the current target without resuming it (leaving it
  2294.    waiting for a debugger).

  2295.    We'd better not have left any breakpoints in the program or the
  2296.    next debugger will get confused.  Currently only supported for some
  2297.    remote targets, since the normal attach mechanisms don't work on
  2298.    stopped processes on some native platforms (e.g. GNU/Linux).  */

  2299. static void
  2300. disconnect_command (char *args, int from_tty)
  2301. {
  2302.   dont_repeat ();                /* Not for the faint of heart.  */
  2303.   query_if_trace_running (from_tty);
  2304.   disconnect_tracing ();
  2305.   target_disconnect (args, from_tty);
  2306.   no_shared_libraries (NULL, from_tty);
  2307.   init_thread_list ();
  2308.   if (deprecated_detach_hook)
  2309.     deprecated_detach_hook ();
  2310. }

  2311. void
  2312. interrupt_target_1 (int all_threads)
  2313. {
  2314.   ptid_t ptid;

  2315.   if (all_threads)
  2316.     ptid = minus_one_ptid;
  2317.   else
  2318.     ptid = inferior_ptid;
  2319.   target_stop (ptid);

  2320.   /* Tag the thread as having been explicitly requested to stop, so
  2321.      other parts of gdb know not to resume this thread automatically,
  2322.      if it was stopped due to an internal event.  Limit this to
  2323.      non-stop mode, as when debugging a multi-threaded application in
  2324.      all-stop mode, we will only get one stop event --- it's undefined
  2325.      which thread will report the event.  */
  2326.   if (non_stop)
  2327.     set_stop_requested (ptid, 1);
  2328. }

  2329. /* interrupt [-a]
  2330.    Stop the execution of the target while running in async mode, in
  2331.    the backgound.  In all-stop, stop the whole process.  In non-stop
  2332.    mode, stop the current thread only by default, or stop all threads
  2333.    if the `-a' switch is used.  */

  2334. static void
  2335. interrupt_command (char *args, int from_tty)
  2336. {
  2337.   if (target_can_async_p ())
  2338.     {
  2339.       int all_threads = 0;

  2340.       dont_repeat ();                /* Not for the faint of heart.  */

  2341.       if (args != NULL
  2342.           && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
  2343.         all_threads = 1;

  2344.       if (!non_stop && all_threads)
  2345.         error (_("-a is meaningless in all-stop mode."));

  2346.       interrupt_target_1 (all_threads);
  2347.     }
  2348. }

  2349. /* See inferior.h.  */

  2350. void
  2351. default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
  2352.                           struct frame_info *frame, const char *args)
  2353. {
  2354.   int regnum;
  2355.   int printed_something = 0;

  2356.   for (regnum = 0;
  2357.        regnum < gdbarch_num_regs (gdbarch)
  2358.          + gdbarch_num_pseudo_regs (gdbarch);
  2359.        regnum++)
  2360.     {
  2361.       if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
  2362.         {
  2363.           printed_something = 1;
  2364.           gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
  2365.         }
  2366.     }
  2367.   if (!printed_something)
  2368.     fprintf_filtered (file, "No floating-point info "
  2369.                       "available for this processor.\n");
  2370. }

  2371. static void
  2372. float_info (char *args, int from_tty)
  2373. {
  2374.   struct frame_info *frame;

  2375.   if (!target_has_registers)
  2376.     error (_("The program has no registers now."));

  2377.   frame = get_selected_frame (NULL);
  2378.   gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
  2379. }

  2380. static void
  2381. unset_command (char *args, int from_tty)
  2382. {
  2383.   printf_filtered (_("\"unset\" must be followed by the "
  2384.                      "name of an unset subcommand.\n"));
  2385.   help_list (unsetlist, "unset ", all_commands, gdb_stdout);
  2386. }

  2387. /* Implement `info proc' family of commands.  */

  2388. static void
  2389. info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
  2390. {
  2391.   struct gdbarch *gdbarch = get_current_arch ();

  2392.   if (!target_info_proc (args, what))
  2393.     {
  2394.       if (gdbarch_info_proc_p (gdbarch))
  2395.         gdbarch_info_proc (gdbarch, args, what);
  2396.       else
  2397.         error (_("Not supported on this target."));
  2398.     }
  2399. }

  2400. /* Implement `info proc' when given without any futher parameters.  */

  2401. static void
  2402. info_proc_cmd (char *args, int from_tty)
  2403. {
  2404.   info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
  2405. }

  2406. /* Implement `info proc mappings'.  */

  2407. static void
  2408. info_proc_cmd_mappings (char *args, int from_tty)
  2409. {
  2410.   info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
  2411. }

  2412. /* Implement `info proc stat'.  */

  2413. static void
  2414. info_proc_cmd_stat (char *args, int from_tty)
  2415. {
  2416.   info_proc_cmd_1 (args, IP_STAT, from_tty);
  2417. }

  2418. /* Implement `info proc status'.  */

  2419. static void
  2420. info_proc_cmd_status (char *args, int from_tty)
  2421. {
  2422.   info_proc_cmd_1 (args, IP_STATUS, from_tty);
  2423. }

  2424. /* Implement `info proc cwd'.  */

  2425. static void
  2426. info_proc_cmd_cwd (char *args, int from_tty)
  2427. {
  2428.   info_proc_cmd_1 (args, IP_CWD, from_tty);
  2429. }

  2430. /* Implement `info proc cmdline'.  */

  2431. static void
  2432. info_proc_cmd_cmdline (char *args, int from_tty)
  2433. {
  2434.   info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
  2435. }

  2436. /* Implement `info proc exe'.  */

  2437. static void
  2438. info_proc_cmd_exe (char *args, int from_tty)
  2439. {
  2440.   info_proc_cmd_1 (args, IP_EXE, from_tty);
  2441. }

  2442. /* Implement `info proc all'.  */

  2443. static void
  2444. info_proc_cmd_all (char *args, int from_tty)
  2445. {
  2446.   info_proc_cmd_1 (args, IP_ALL, from_tty);
  2447. }

  2448. void
  2449. _initialize_infcmd (void)
  2450. {
  2451.   static struct cmd_list_element *info_proc_cmdlist;
  2452.   struct cmd_list_element *c = NULL;
  2453.   const char *cmd_name;

  2454.   /* Add the filename of the terminal connected to inferior I/O.  */
  2455.   add_setshow_filename_cmd ("inferior-tty", class_run,
  2456.                             &inferior_io_terminal_scratch, _("\
  2457. Set terminal for future runs of program being debugged."), _("\
  2458. Show terminal for future runs of program being debugged."), _("\
  2459. Usage: set inferior-tty /dev/pts/1"),
  2460.                             set_inferior_tty_command,
  2461.                             show_inferior_tty_command,
  2462.                             &setlist, &showlist);
  2463.   add_com_alias ("tty", "set inferior-tty", class_alias, 0);

  2464.   cmd_name = "args";
  2465.   add_setshow_string_noescape_cmd (cmd_name, class_run,
  2466.                                    &inferior_args_scratch, _("\
  2467. Set argument list to give program being debugged when it is started."), _("\
  2468. Show argument list to give program being debugged when it is started."), _("\
  2469. Follow this command with any number of args, to be passed to the program."),
  2470.                                    set_args_command,
  2471.                                    show_args_command,
  2472.                                    &setlist, &showlist);
  2473.   c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
  2474.   gdb_assert (c != NULL);
  2475.   set_cmd_completer (c, filename_completer);

  2476.   c = add_cmd ("environment", no_class, environment_info, _("\
  2477. The environment to give the program, or one variable's value.\n\
  2478. With an argument VAR, prints the value of environment variable VAR to\n\
  2479. give the program being debugged.  With no arguments, prints the entire\n\
  2480. environment to be given to the program."), &showlist);
  2481.   set_cmd_completer (c, noop_completer);

  2482.   add_prefix_cmd ("unset", no_class, unset_command,
  2483.                   _("Complement to certain \"set\" commands."),
  2484.                   &unsetlist, "unset ", 0, &cmdlist);

  2485.   c = add_cmd ("environment", class_run, unset_environment_command, _("\
  2486. Cancel environment variable VAR for the program.\n\
  2487. This does not affect the program until the next \"run\" command."),
  2488.                &unsetlist);
  2489.   set_cmd_completer (c, noop_completer);

  2490.   c = add_cmd ("environment", class_run, set_environment_command, _("\
  2491. Set environment variable value to give the program.\n\
  2492. Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
  2493. VALUES of environment variables are uninterpreted strings.\n\
  2494. This does not affect the program until the next \"run\" command."),
  2495.                &setlist);
  2496.   set_cmd_completer (c, noop_completer);

  2497.   c = add_com ("path", class_files, path_command, _("\
  2498. Add directory DIR(s) to beginning of search path for object files.\n\
  2499. $cwd in the path means the current working directory.\n\
  2500. This path is equivalent to the $PATH shell variable.  It is a list of\n\
  2501. directories, separated by colons.  These directories are searched to find\n\
  2502. fully linked executable files and separately compiled object files as \
  2503. needed."));
  2504.   set_cmd_completer (c, filename_completer);

  2505.   c = add_cmd ("paths", no_class, path_info, _("\
  2506. Current search path for finding object files.\n\
  2507. $cwd in the path means the current working directory.\n\
  2508. This path is equivalent to the $PATH shell variable.  It is a list of\n\
  2509. directories, separated by colons.  These directories are searched to find\n\
  2510. fully linked executable files and separately compiled object files as \
  2511. needed."),
  2512.                &showlist);
  2513.   set_cmd_completer (c, noop_completer);

  2514.   add_prefix_cmd ("kill", class_run, kill_command,
  2515.                   _("Kill execution of program being debugged."),
  2516.                   &killlist, "kill ", 0, &cmdlist);

  2517.   add_com ("attach", class_run, attach_command, _("\
  2518. Attach to a process or file outside of GDB.\n\
  2519. This command attaches to another target, of the same type as your last\n\
  2520. \"target\" command (\"info files\" will show your target stack).\n\
  2521. The command may take as argument a process id or a device file.\n\
  2522. For a process id, you must have permission to send the process a signal,\n\
  2523. and it must have the same effective uid as the debugger.\n\
  2524. When using \"attach\" with a process id, the debugger finds the\n\
  2525. program running in the process, looking first in the current working\n\
  2526. directory, or (if not found there) using the source file search path\n\
  2527. (see the \"directory\" command).  You can also use the \"file\" command\n\
  2528. to specify the program, and to load its symbol table."));

  2529.   add_prefix_cmd ("detach", class_run, detach_command, _("\
  2530. Detach a process or file previously attached.\n\
  2531. If a process, it is no longer traced, and it continues its execution.  If\n\
  2532. you were debugging a file, the file is closed and gdb no longer accesses it."),
  2533.                   &detachlist, "detach ", 0, &cmdlist);

  2534.   add_com ("disconnect", class_run, disconnect_command, _("\
  2535. Disconnect from a target.\n\
  2536. The target will wait for another debugger to connect.  Not available for\n\
  2537. all targets."));

  2538.   c = add_com ("signal", class_run, signal_command, _("\
  2539. Continue program with the specified signal.\n\
  2540. Usage: signal SIGNAL\n\
  2541. The SIGNAL argument is processed the same as the handle command.\n\
  2542. \n\
  2543. An argument of \"0\" means continue the program without sending it a signal.\n\
  2544. This is useful in cases where the program stopped because of a signal,\n\
  2545. and you want to resume the program while discarding the signal.\n\
  2546. \n\
  2547. In a multi-threaded program the signal is delivered to, or discarded from,\n\
  2548. the current thread only."));
  2549.   set_cmd_completer (c, signal_completer);

  2550.   c = add_com ("queue-signal", class_run, queue_signal_command, _("\
  2551. Queue a signal to be delivered to the current thread when it is resumed.\n\
  2552. Usage: queue-signal SIGNAL\n\
  2553. The SIGNAL argument is processed the same as the handle command.\n\
  2554. It is an error if the handling state of SIGNAL is \"nopass\".\n\
  2555. \n\
  2556. An argument of \"0\" means remove any currently queued signal from\n\
  2557. the current thread.  This is useful in cases where the program stopped\n\
  2558. because of a signal, and you want to resume it while discarding the signal.\n\
  2559. \n\
  2560. In a multi-threaded program the signal is queued with, or discarded from,\n\
  2561. the current thread only."));
  2562.   set_cmd_completer (c, signal_completer);

  2563.   add_com ("stepi", class_run, stepi_command, _("\
  2564. Step one instruction exactly.\n\
  2565. Usage: stepi [N]\n\
  2566. Argument N means step N times (or till program stops for another \
  2567. reason)."));
  2568.   add_com_alias ("si", "stepi", class_alias, 0);

  2569.   add_com ("nexti", class_run, nexti_command, _("\
  2570. Step one instruction, but proceed through subroutine calls.\n\
  2571. Usage: nexti [N]\n\
  2572. Argument N means step N times (or till program stops for another \
  2573. reason)."));
  2574.   add_com_alias ("ni", "nexti", class_alias, 0);

  2575.   add_com ("finish", class_run, finish_command, _("\
  2576. Execute until selected stack frame returns.\n\
  2577. Usage: finish\n\
  2578. Upon return, the value returned is printed and put in the value history."));
  2579.   add_com_alias ("fin", "finish", class_run, 1);

  2580.   add_com ("next", class_run, next_command, _("\
  2581. Step program, proceeding through subroutine calls.\n\
  2582. Usage: next [N]\n\
  2583. Unlike \"step\", if the current source line calls a subroutine,\n\
  2584. this command does not enter the subroutine, but instead steps over\n\
  2585. the call, in effect treating it as a single source line."));
  2586.   add_com_alias ("n", "next", class_run, 1);
  2587.   if (xdb_commands)
  2588.     add_com_alias ("S", "next", class_run, 1);

  2589.   add_com ("step", class_run, step_command, _("\
  2590. Step program until it reaches a different source line.\n\
  2591. Usage: step [N]\n\
  2592. Argument N means step N times (or till program stops for another \
  2593. reason)."));
  2594.   add_com_alias ("s", "step", class_run, 1);

  2595.   c = add_com ("until", class_run, until_command, _("\
  2596. Execute until the program reaches a source line greater than the current\n\
  2597. or a specified location (same args as break command) within the current \
  2598. frame."));
  2599.   set_cmd_completer (c, location_completer);
  2600.   add_com_alias ("u", "until", class_run, 1);

  2601.   c = add_com ("advance", class_run, advance_command, _("\
  2602. Continue the program up to the given location (same form as args for break \
  2603. command).\n\
  2604. Execution will also stop upon exit from the current stack frame."));
  2605.   set_cmd_completer (c, location_completer);

  2606.   c = add_com ("jump", class_run, jump_command, _("\
  2607. Continue program being debugged at specified line or address.\n\
  2608. Usage: jump <location>\n\
  2609. Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
  2610. for an address to start at."));
  2611.   set_cmd_completer (c, location_completer);
  2612.   add_com_alias ("j", "jump", class_run, 1);

  2613.   if (xdb_commands)
  2614.     {
  2615.       c = add_com ("go", class_run, go_command, _("\
  2616. Usage: go <location>\n\
  2617. Continue program being debugged, stopping at specified line or \n\
  2618. address.\n\
  2619. Give as argument either LINENUM or *ADDR, where ADDR is an \n\
  2620. expression for an address to start at.\n\
  2621. This command is a combination of tbreak and jump."));
  2622.       set_cmd_completer (c, location_completer);
  2623.     }

  2624.   if (xdb_commands)
  2625.     add_com_alias ("g", "go", class_run, 1);

  2626.   add_com ("continue", class_run, continue_command, _("\
  2627. Continue program being debugged, after signal or breakpoint.\n\
  2628. Usage: continue [N]\n\
  2629. If proceeding from breakpoint, a number N may be used as an argument,\n\
  2630. which means to set the ignore count of that breakpoint to N - 1 (so that\n\
  2631. the breakpoint won't break until the Nth time it is reached).\n\
  2632. \n\
  2633. If non-stop mode is enabled, continue only the current thread,\n\
  2634. otherwise all the threads in the program are continued.  To \n\
  2635. continue all stopped threads in non-stop mode, use the -a option.\n\
  2636. Specifying -a and an ignore count simultaneously is an error."));
  2637.   add_com_alias ("c", "cont", class_run, 1);
  2638.   add_com_alias ("fg", "cont", class_run, 1);

  2639.   c = add_com ("run", class_run, run_command, _("\
  2640. Start debugged program.  You may specify arguments to give it.\n\
  2641. Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
  2642. Input and output redirection with \">\", \"<\", or \">>\" are also \
  2643. allowed.\n\n\
  2644. With no arguments, uses arguments last specified (with \"run\" \
  2645. or \"set args\").\n\
  2646. To cancel previous arguments and run with no arguments,\n\
  2647. use \"set args\" without arguments."));
  2648.   set_cmd_completer (c, filename_completer);
  2649.   add_com_alias ("r", "run", class_run, 1);
  2650.   if (xdb_commands)
  2651.     add_com ("R", class_run, run_no_args_command,
  2652.              _("Start debugged program with no arguments."));

  2653.   c = add_com ("start", class_run, start_command, _("\
  2654. Run the debugged program until the beginning of the main procedure.\n\
  2655. You may specify arguments to give to your program, just as with the\n\
  2656. \"run\" command."));
  2657.   set_cmd_completer (c, filename_completer);

  2658.   add_com ("interrupt", class_run, interrupt_command,
  2659.            _("Interrupt the execution of the debugged program.\n\
  2660. If non-stop mode is enabled, interrupt only the current thread,\n\
  2661. otherwise all the threads in the program are stopped.  To \n\
  2662. interrupt all running threads in non-stop mode, use the -a option."));

  2663.   c = add_info ("registers", nofp_registers_info, _("\
  2664. List of integer registers and their contents, for selected stack frame.\n\
  2665. Register name as argument means describe only that register."));
  2666.   add_info_alias ("r", "registers", 1);
  2667.   set_cmd_completer (c, reg_or_group_completer);

  2668.   if (xdb_commands)
  2669.     {
  2670.       c = add_com ("lr", class_info, nofp_registers_info, _("\
  2671. List of integer registers and their contents, for selected stack frame.\n\
  2672. Register name as argument means describe only that register."));
  2673.       set_cmd_completer (c, reg_or_group_completer);
  2674.     }

  2675.   c = add_info ("all-registers", all_registers_info, _("\
  2676. List of all registers and their contents, for selected stack frame.\n\
  2677. Register name as argument means describe only that register."));
  2678.   set_cmd_completer (c, reg_or_group_completer);

  2679.   add_info ("program", program_info,
  2680.             _("Execution status of the program."));

  2681.   add_info ("float", float_info,
  2682.             _("Print the status of the floating point unit\n"));

  2683.   add_info ("vector", vector_info,
  2684.             _("Print the status of the vector unit\n"));

  2685.   add_prefix_cmd ("proc", class_info, info_proc_cmd,
  2686.                   _("\
  2687. Show /proc process information about any running process.\n\
  2688. Specify any process id, or use the program being debugged by default."),
  2689.                   &info_proc_cmdlist, "info proc ",
  2690.                   1/*allow-unknown*/, &infolist);

  2691.   add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
  2692. List of mapped memory regions."),
  2693.            &info_proc_cmdlist);

  2694.   add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
  2695. List process info from /proc/PID/stat."),
  2696.            &info_proc_cmdlist);

  2697.   add_cmd ("status", class_info, info_proc_cmd_status, _("\
  2698. List process info from /proc/PID/status."),
  2699.            &info_proc_cmdlist);

  2700.   add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
  2701. List current working directory of the process."),
  2702.            &info_proc_cmdlist);

  2703.   add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
  2704. List command line arguments of the process."),
  2705.            &info_proc_cmdlist);

  2706.   add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
  2707. List absolute filename for executable of the process."),
  2708.            &info_proc_cmdlist);

  2709.   add_cmd ("all", class_info, info_proc_cmd_all, _("\
  2710. List all available /proc info."),
  2711.            &info_proc_cmdlist);
  2712. }