1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
36 #include "completer.h"
38 #include "event-top.h"
39 #include "parser-defs.h"
41 #include "reggroups.h"
46 #include "target-descriptions.h"
47 #include "user-regs.h"
48 #include "cli/cli-decode.h"
49 #include "gdbthread.h"
51 #include "inline-frame.h"
52 #include "tracepoint.h"
54 #include "continuations.h"
56 #include "cli/cli-utils.h"
58 #include "thread-fsm.h"
60 /* Local functions: */
62 static void nofp_registers_info (char *, int);
64 static void until_next_command (int);
66 static void until_command (char *, int);
68 static void path_info (char *, int);
70 static void path_command (char *, int);
72 static void unset_command (char *, int);
74 static void float_info (char *, int);
76 static void disconnect_command (char *, int);
78 static void unset_environment_command (char *, int);
80 static void set_environment_command (char *, int);
82 static void environment_info (char *, int);
84 static void program_info (char *, int);
86 static void finish_command (char *, int);
88 static void signal_command (char *, int);
90 static void jump_command (char *, int);
92 static void step_1 (int, int, char *);
94 static void next_command (char *, int);
96 static void step_command (char *, int);
98 static void run_command (char *, int);
100 void _initialize_infcmd (void);
102 #define ERROR_NO_INFERIOR \
103 if (!target_has_execution) error (_("The program is not being run."));
105 /* Scratch area where string containing arguments to give to the
106 program will be stored by 'set args'. As soon as anything is
107 stored, notice_args_set will move it into per-inferior storage.
108 Arguments are separated by spaces. Empty string (pointer to '\0')
111 static char *inferior_args_scratch;
113 /* Scratch area where 'set inferior-tty' will store user-provided value.
114 We'll immediate copy it into per-inferior storage. */
116 static char *inferior_io_terminal_scratch;
118 /* Pid of our debugged inferior, or 0 if no inferior now.
119 Since various parts of infrun.c test this to see whether there is a program
120 being debugged it should be nonzero (currently 3 is used) for remote
123 ptid_t inferior_ptid;
125 /* Address at which inferior stopped. */
129 /* Nonzero if stopped due to completion of a stack dummy routine. */
131 enum stop_stack_kind stop_stack_dummy;
133 /* Nonzero if stopped due to a random (unexpected) signal in inferior
136 int stopped_by_random_signal;
138 /* See inferior.h. */
140 int startup_with_shell = 1;
143 /* Accessor routines. */
145 /* Set the io terminal for the current inferior. Ownership of
146 TERMINAL_NAME is not transferred. */
149 set_inferior_io_terminal (const char *terminal_name)
151 xfree (current_inferior ()->terminal);
152 current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
156 get_inferior_io_terminal (void)
158 return current_inferior ()->terminal;
162 set_inferior_tty_command (char *args, int from_tty,
163 struct cmd_list_element *c)
165 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
166 Now route it to current inferior. */
167 set_inferior_io_terminal (inferior_io_terminal_scratch);
171 show_inferior_tty_command (struct ui_file *file, int from_tty,
172 struct cmd_list_element *c, const char *value)
174 /* Note that we ignore the passed-in value in favor of computing it
176 const char *inferior_io_terminal = get_inferior_io_terminal ();
178 if (inferior_io_terminal == NULL)
179 inferior_io_terminal = "";
180 fprintf_filtered (gdb_stdout,
181 _("Terminal for future runs of program being debugged "
182 "is \"%s\".\n"), inferior_io_terminal);
186 get_inferior_args (void)
188 if (current_inferior ()->argc != 0)
192 n = construct_inferior_arguments (current_inferior ()->argc,
193 current_inferior ()->argv);
194 set_inferior_args (n);
198 if (current_inferior ()->args == NULL)
199 current_inferior ()->args = xstrdup ("");
201 return current_inferior ()->args;
204 /* Set the arguments for the current inferior. Ownership of
205 NEWARGS is not transferred. */
208 set_inferior_args (char *newargs)
210 xfree (current_inferior ()->args);
211 current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
212 current_inferior ()->argc = 0;
213 current_inferior ()->argv = 0;
217 set_inferior_args_vector (int argc, char **argv)
219 current_inferior ()->argc = argc;
220 current_inferior ()->argv = argv;
223 /* Notice when `set args' is run. */
226 set_args_command (char *args, int from_tty, struct cmd_list_element *c)
228 /* CLI has assigned the user-provided value to inferior_args_scratch.
229 Now route it to current inferior. */
230 set_inferior_args (inferior_args_scratch);
233 /* Notice when `show args' is run. */
236 show_args_command (struct ui_file *file, int from_tty,
237 struct cmd_list_element *c, const char *value)
239 /* Note that we ignore the passed-in value in favor of computing it
241 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
245 /* Compute command-line string given argument vector. This does the
246 same shell processing as fork_inferior. */
249 construct_inferior_arguments (int argc, char **argv)
253 if (startup_with_shell)
256 /* This holds all the characters considered special to the
258 char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
259 const char quote = '"';
261 /* This holds all the characters considered special to the
262 typical Unix shells. We include `^' because the SunOS
263 /bin/sh treats it as a synonym for `|'. */
264 char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
265 const char quote = '\'';
271 /* We over-compute the size. It shouldn't matter. */
272 for (i = 0; i < argc; ++i)
273 length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
275 result = (char *) xmalloc (length);
278 for (i = 0; i < argc; ++i)
283 /* Need to handle empty arguments specially. */
284 if (argv[i][0] == '\0')
294 if (strpbrk (argv[i], special))
300 for (cp = argv[i]; *cp; ++cp)
304 /* A newline cannot be quoted with a backslash (it
305 just disappears), only by putting it inside
316 if (strchr (special, *cp) != NULL)
332 /* In this case we can't handle arguments that contain spaces,
333 tabs, or newlines -- see breakup_args(). */
337 for (i = 0; i < argc; ++i)
339 char *cp = strchr (argv[i], ' ');
341 cp = strchr (argv[i], '\t');
343 cp = strchr (argv[i], '\n');
345 error (_("can't handle command-line "
346 "argument containing whitespace"));
347 length += strlen (argv[i]) + 1;
350 result = (char *) xmalloc (length);
352 for (i = 0; i < argc; ++i)
355 strcat (result, " ");
356 strcat (result, argv[i]);
364 /* This function strips the '&' character (indicating background
365 execution) that is added as *the last* of the arguments ARGS of a
366 command. A copy of the incoming ARGS without the '&' is returned,
367 unless the resulting string after stripping is empty, in which case
368 NULL is returned. *BG_CHAR_P is an output boolean that indicates
369 whether the '&' character was found. */
372 strip_bg_char (const char *args, int *bg_char_p)
376 if (args == NULL || *args == '\0')
382 p = args + strlen (args);
386 while (p > args && isspace (p[-1]))
391 return savestring (args, p - args);
397 return xstrdup (args);
400 /* Common actions to take after creating any sort of inferior, by any
401 means (running, attaching, connecting, et cetera). The target
402 should be stopped. */
405 post_create_inferior (struct target_ops *target, int from_tty)
408 /* Be sure we own the terminal in case write operations are performed. */
409 target_terminal_ours ();
411 /* If the target hasn't taken care of this already, do it now.
412 Targets which need to access registers during to_open,
413 to_create_inferior, or to_attach should do it earlier; but many
415 target_find_description ();
417 /* Now that we know the register layout, retrieve current PC. But
418 if the PC is unavailable (e.g., we're opening a core file with
419 missing registers info), ignore it. */
423 stop_pc = regcache_read_pc (get_current_regcache ());
425 CATCH (ex, RETURN_MASK_ERROR)
427 if (ex.error != NOT_AVAILABLE_ERROR)
428 throw_exception (ex);
434 const unsigned solib_add_generation
435 = current_program_space->solib_add_generation;
437 /* Create the hooks to handle shared library load and unload
439 solib_create_inferior_hook (from_tty);
441 if (current_program_space->solib_add_generation == solib_add_generation)
443 /* The platform-specific hook should load initial shared libraries,
444 but didn't. FROM_TTY will be incorrectly 0 but such solib
445 targets should be fixed anyway. Call it only after the solib
446 target has been initialized by solib_create_inferior_hook. */
449 warning (_("platform-specific solib_create_inferior_hook did "
450 "not load initial shared libraries."));
452 /* If the solist is global across processes, there's no need to
454 if (!gdbarch_has_global_solist (target_gdbarch ()))
455 solib_add (NULL, 0, target, auto_solib_add);
459 /* If the user sets watchpoints before execution having started,
460 then she gets software watchpoints, because GDB can't know which
461 target will end up being pushed, or if it supports hardware
462 watchpoints or not. breakpoint_re_set takes care of promoting
463 watchpoints to hardware watchpoints if possible, however, if this
464 new inferior doesn't load shared libraries or we don't pull in
465 symbols from any other source on this target/arch,
466 breakpoint_re_set is never called. Call it now so that software
467 watchpoints get a chance to be promoted to hardware watchpoints
468 if the now pushed target supports hardware watchpoints. */
469 breakpoint_re_set ();
471 observer_notify_inferior_created (target, from_tty);
474 /* Kill the inferior if already running. This function is designed
475 to be called when we are about to start the execution of the program
476 from the beginning. Ask the user to confirm that he wants to restart
477 the program being debugged when FROM_TTY is non-null. */
480 kill_if_already_running (int from_tty)
482 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
484 /* Bail out before killing the program if we will not be able to
486 target_require_runnable ();
489 && !query (_("The program being debugged has been started already.\n\
490 Start it from the beginning? ")))
491 error (_("Program not restarted."));
496 /* See inferior.h. */
499 prepare_execution_command (struct target_ops *target, int background)
501 /* If we get a request for running in the bg but the target
502 doesn't support it, error out. */
503 if (background && !target->to_can_async_p (target))
504 error (_("Asynchronous execution not supported on this target."));
508 /* If we get a request for running in the fg, then we need to
509 simulate synchronous (fg) execution. Note no cleanup is
510 necessary for this. stdin is re-enabled whenever an error
511 reaches the top level. */
512 async_disable_stdin ();
516 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
517 a temporary breakpoint at the begining of the main program before
518 running the program. */
521 run_command_1 (char *args, int from_tty, int tbreak_at_main)
524 struct cleanup *old_chain;
526 struct ui_out *uiout = current_uiout;
527 struct target_ops *run_target;
529 struct cleanup *args_chain;
533 kill_if_already_running (from_tty);
535 init_wait_for_inferior ();
536 clear_breakpoint_hit_counts ();
538 /* Clean up any leftovers from other runs. Some other things from
539 this function should probably be moved into target_pre_inferior. */
540 target_pre_inferior (from_tty);
542 /* The comment here used to read, "The exec file is re-read every
543 time we do a generic_mourn_inferior, so we just have to worry
544 about the symbol file." The `generic_mourn_inferior' function
545 gets called whenever the program exits. However, suppose the
546 program exits, and *then* the executable file changes? We need
547 to check again here. Since reopen_exec_file doesn't do anything
548 if the timestamp hasn't changed, I don't see the harm. */
552 args = strip_bg_char (args, &async_exec);
553 args_chain = make_cleanup (xfree, args);
555 /* Do validation and preparation before possibly changing anything
558 run_target = find_run_target ();
560 prepare_execution_command (run_target, async_exec);
562 if (non_stop && !run_target->to_supports_non_stop (run_target))
563 error (_("The target does not support running in non-stop mode."));
565 /* Done. Can now set breakpoints, change inferior args, etc. */
567 /* Insert the temporary breakpoint if a location was specified. */
569 tbreak_command (main_name (), 0);
571 exec_file = (char *) get_exec_file (0);
573 /* We keep symbols from add-symbol-file, on the grounds that the
574 user might want to add some symbols before running the program
575 (right?). But sometimes (dynamic loading where the user manually
576 introduces the new symbols with add-symbol-file), the code which
577 the symbols describe does not persist between runs. Currently
578 the user has to manually nuke all symbols between runs if they
579 want them to go away (PR 2207). This is probably reasonable. */
581 /* If there were other args, beside '&', process them. */
583 set_inferior_args (args);
587 ui_out_field_string (uiout, NULL, "Starting program");
588 ui_out_text (uiout, ": ");
590 ui_out_field_string (uiout, "execfile", exec_file);
591 ui_out_spaces (uiout, 1);
592 /* We call get_inferior_args() because we might need to compute
594 ui_out_field_string (uiout, "infargs", get_inferior_args ());
595 ui_out_text (uiout, "\n");
596 ui_out_flush (uiout);
599 /* Done with ARGS. */
600 do_cleanups (args_chain);
602 /* We call get_inferior_args() because we might need to compute
604 run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
605 environ_vector (current_inferior ()->environment),
607 /* to_create_inferior should push the target, so after this point we
608 shouldn't refer to run_target again. */
611 /* We're starting off a new process. When we get out of here, in
612 non-stop mode, finish the state of all threads of that process,
613 but leave other threads alone, as they may be stopped in internal
614 events --- the frontend shouldn't see them as stopped. In
615 all-stop, always finish the state of all threads, as we may be
616 resuming more than just the new process. */
618 ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
620 ptid = minus_one_ptid;
621 old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
623 /* Pass zero for FROM_TTY, because at this point the "run" command
624 has done its thing; now we are setting up the running program. */
625 post_create_inferior (¤t_target, 0);
627 /* Start the target running. Do not use -1 continuation as it would skip
628 breakpoint right at the entry point. */
629 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
631 /* Since there was no error, there's no need to finish the thread
633 discard_cleanups (old_chain);
637 run_command (char *args, int from_tty)
639 run_command_1 (args, from_tty, 0);
642 /* Start the execution of the program up until the beginning of the main
646 start_command (char *args, int from_tty)
648 /* Some languages such as Ada need to search inside the program
649 minimal symbols for the location where to put the temporary
650 breakpoint before starting. */
651 if (!have_minimal_symbols ())
652 error (_("No symbol table loaded. Use the \"file\" command."));
654 /* Run the program until reaching the main procedure... */
655 run_command_1 (args, from_tty, 1);
659 proceed_thread_callback (struct thread_info *thread, void *arg)
661 /* We go through all threads individually instead of compressing
662 into a single target `resume_all' request, because some threads
663 may be stopped in internal breakpoints/events, or stopped waiting
664 for its turn in the displaced stepping queue (that is, they are
665 running && !executing). The target side has no idea about why
666 the thread is stopped, so a `resume_all' command would resume too
667 much. If/when GDB gains a way to tell the target `hold this
668 thread stopped until I say otherwise', then we can optimize
670 if (!is_stopped (thread->ptid))
673 switch_to_thread (thread->ptid);
674 clear_proceed_status (0);
675 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
680 ensure_valid_thread (void)
682 if (ptid_equal (inferior_ptid, null_ptid)
683 || is_exited (inferior_ptid))
684 error (_("Cannot execute this command without a live selected thread."));
687 /* If the user is looking at trace frames, any resumption of execution
688 is likely to mix up recorded and live target data. So simply
689 disallow those commands. */
692 ensure_not_tfind_mode (void)
694 if (get_traceframe_number () >= 0)
695 error (_("Cannot execute this command while looking at trace frames."));
698 /* Throw an error indicating the current thread is running. */
701 error_is_running (void)
703 error (_("Cannot execute this command while "
704 "the selected thread is running."));
707 /* Calls error_is_running if the current thread is running. */
710 ensure_not_running (void)
712 if (is_running (inferior_ptid))
717 continue_1 (int all_threads)
720 ensure_not_tfind_mode ();
722 if (non_stop && all_threads)
724 /* Don't error out if the current thread is running, because
725 there may be other stopped threads. */
726 struct cleanup *old_chain;
728 /* Backup current thread and selected frame. */
729 old_chain = make_cleanup_restore_current_thread ();
731 iterate_over_threads (proceed_thread_callback, NULL);
735 /* If all threads in the target were already running,
736 proceed_thread_callback ends up never calling proceed,
737 and so nothing calls this to put the inferior's terminal
738 settings in effect and remove stdin from the event loop,
739 which we must when running a foreground command. E.g.:
743 <all threads are running now>
746 <no thread was resumed, but the inferior now owns the terminal>
748 target_terminal_inferior ();
751 /* Restore selected ptid. */
752 do_cleanups (old_chain);
756 ensure_valid_thread ();
757 ensure_not_running ();
758 clear_proceed_status (0);
759 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
763 /* continue [-a] [proceed-count] [&] */
766 continue_command (char *args, int from_tty)
770 struct cleanup *args_chain;
774 /* Find out whether we must run in the background. */
775 args = strip_bg_char (args, &async_exec);
776 args_chain = make_cleanup (xfree, args);
778 prepare_execution_command (¤t_target, async_exec);
782 if (startswith (args, "-a"))
785 args += sizeof ("-a") - 1;
791 if (!non_stop && all_threads)
792 error (_("`-a' is meaningless in all-stop mode."));
794 if (args != NULL && all_threads)
795 error (_("Can't resume all threads and specify "
796 "proceed count simultaneously."));
798 /* If we have an argument left, set proceed count of breakpoint we
805 struct thread_info *tp;
808 tp = find_thread_ptid (inferior_ptid);
812 struct target_waitstatus ws;
814 get_last_target_status (&last_ptid, &ws);
815 tp = find_thread_ptid (last_ptid);
818 bs = tp->control.stop_bpstat;
820 while ((stat = bpstat_num (&bs, &num)) != 0)
823 set_ignore_count (num,
824 parse_and_eval_long (args) - 1,
826 /* set_ignore_count prints a message ending with a period.
827 So print two spaces before "Continuing.". */
829 printf_filtered (" ");
833 if (!stopped && from_tty)
836 ("Not stopped at any breakpoint; argument ignored.\n");
840 /* Done with ARGS. */
841 do_cleanups (args_chain);
844 printf_filtered (_("Continuing.\n"));
846 continue_1 (all_threads);
849 /* Record the starting point of a "step" or "next" command. */
852 set_step_frame (void)
854 struct symtab_and_line sal;
856 struct frame_info *frame = get_current_frame ();
857 struct thread_info *tp = inferior_thread ();
859 find_frame_sal (frame, &sal);
860 set_step_info (frame, sal);
861 pc = get_frame_pc (frame);
862 tp->control.step_start_function = find_pc_function (pc);
865 /* Step until outside of current statement. */
868 step_command (char *count_string, int from_tty)
870 step_1 (0, 0, count_string);
873 /* Likewise, but skip over subroutine calls as if single instructions. */
876 next_command (char *count_string, int from_tty)
878 step_1 (1, 0, count_string);
881 /* Likewise, but step only one instruction. */
884 stepi_command (char *count_string, int from_tty)
886 step_1 (0, 1, count_string);
890 nexti_command (char *count_string, int from_tty)
892 step_1 (1, 1, count_string);
896 delete_longjmp_breakpoint_cleanup (void *arg)
898 int thread = * (int *) arg;
899 delete_longjmp_breakpoint (thread);
902 /* Data for the FSM that manages the step/next/stepi/nexti
905 struct step_command_fsm
907 /* The base class. */
908 struct thread_fsm thread_fsm;
910 /* How many steps left in a "step N"-like command. */
913 /* If true, this is a next/nexti, otherwise a step/stepi. */
914 int skip_subroutines;
916 /* If true, this is a stepi/nexti, otherwise a step/step. */
919 /* The thread that the command was run on. */
923 static void step_command_fsm_clean_up (struct thread_fsm *self);
924 static int step_command_fsm_should_stop (struct thread_fsm *self);
925 static enum async_reply_reason
926 step_command_fsm_async_reply_reason (struct thread_fsm *self);
928 /* step_command_fsm's vtable. */
930 static struct thread_fsm_ops step_command_fsm_ops =
933 step_command_fsm_clean_up,
934 step_command_fsm_should_stop,
935 NULL, /* return_value */
936 step_command_fsm_async_reply_reason,
939 /* Allocate a new step_command_fsm. */
941 static struct step_command_fsm *
942 new_step_command_fsm (void)
944 struct step_command_fsm *sm;
946 sm = XCNEW (struct step_command_fsm);
947 thread_fsm_ctor (&sm->thread_fsm, &step_command_fsm_ops);
952 /* Prepare for a step/next/etc. command. Any target resource
953 allocated here is undone in the FSM's clean_up method. */
956 step_command_fsm_prepare (struct step_command_fsm *sm,
957 int skip_subroutines, int single_inst,
958 int count, struct thread_info *thread)
960 sm->skip_subroutines = skip_subroutines;
961 sm->single_inst = single_inst;
963 sm->thread = thread->num;
965 /* Leave the si command alone. */
966 if (!sm->single_inst || sm->skip_subroutines)
967 set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ()));
969 thread->control.stepping_command = 1;
972 static int prepare_one_step (struct step_command_fsm *sm);
975 step_1 (int skip_subroutines, int single_inst, char *count_string)
979 struct cleanup *args_chain;
980 struct thread_info *thr;
981 struct step_command_fsm *step_sm;
984 ensure_not_tfind_mode ();
985 ensure_valid_thread ();
986 ensure_not_running ();
988 count_string = strip_bg_char (count_string, &async_exec);
989 args_chain = make_cleanup (xfree, count_string);
991 prepare_execution_command (¤t_target, async_exec);
993 count = count_string ? parse_and_eval_long (count_string) : 1;
995 /* Done with ARGS. */
996 do_cleanups (args_chain);
998 clear_proceed_status (1);
1000 /* Setup the execution command state machine to handle all the COUNT
1002 thr = inferior_thread ();
1003 step_sm = new_step_command_fsm ();
1004 thr->thread_fsm = &step_sm->thread_fsm;
1006 step_command_fsm_prepare (step_sm, skip_subroutines,
1007 single_inst, count, thr);
1009 /* Do only one step for now, before returning control to the event
1010 loop. Let the continuation figure out how many other steps we
1011 need to do, and handle them one at the time, through
1013 if (!prepare_one_step (step_sm))
1014 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1017 /* Stepped into an inline frame. Pretend that we've
1019 thread_fsm_clean_up (thr->thread_fsm);
1021 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1025 /* Implementation of the 'should_stop' FSM method for stepping
1026 commands. Called after we are done with one step operation, to
1027 check whether we need to step again, before we print the prompt and
1028 return control to the user. If count is > 1, returns false, as we
1029 will need to keep going. */
1032 step_command_fsm_should_stop (struct thread_fsm *self)
1034 struct step_command_fsm *sm = (struct step_command_fsm *) self;
1035 struct thread_info *tp = find_thread_id (sm->thread);
1037 if (tp->control.stop_step)
1039 /* There are more steps to make, and we did stop due to
1040 ending a stepping range. Do another step. */
1041 if (--sm->count > 0)
1042 return prepare_one_step (sm);
1044 thread_fsm_set_finished (self);
1050 /* Implementation of the 'clean_up' FSM method for stepping commands. */
1053 step_command_fsm_clean_up (struct thread_fsm *self)
1055 struct step_command_fsm *sm = (struct step_command_fsm *) self;
1057 if (!sm->single_inst || sm->skip_subroutines)
1058 delete_longjmp_breakpoint (sm->thread);
1061 /* Implementation of the 'async_reply_reason' FSM method for stepping
1064 static enum async_reply_reason
1065 step_command_fsm_async_reply_reason (struct thread_fsm *self)
1067 return EXEC_ASYNC_END_STEPPING_RANGE;
1070 /* Prepare for one step in "step N". The actual target resumption is
1071 done by the caller. Return true if we're done and should thus
1072 report a stop to the user. Returns false if the target needs to be
1076 prepare_one_step (struct step_command_fsm *sm)
1080 struct frame_info *frame = get_current_frame ();
1082 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1083 the longjmp breakpoint was not required. Use the
1084 INFERIOR_PTID thread instead, which is the same thread when
1086 struct thread_info *tp = inferior_thread ();
1090 if (!sm->single_inst)
1094 /* Step at an inlined function behaves like "down". */
1095 if (!sm->skip_subroutines
1096 && inline_skipped_frames (inferior_ptid))
1100 /* Pretend that we've ran. */
1101 resume_ptid = user_visible_resume_ptid (1);
1102 set_running (resume_ptid, 1);
1104 step_into_inline_frame (inferior_ptid);
1106 return prepare_one_step (sm);
1109 pc = get_frame_pc (frame);
1110 find_pc_line_pc_range (pc,
1111 &tp->control.step_range_start,
1112 &tp->control.step_range_end);
1114 tp->control.may_range_step = 1;
1116 /* If we have no line info, switch to stepi mode. */
1117 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
1119 tp->control.step_range_start = tp->control.step_range_end = 1;
1120 tp->control.may_range_step = 0;
1122 else if (tp->control.step_range_end == 0)
1126 if (find_pc_partial_function (pc, &name,
1127 &tp->control.step_range_start,
1128 &tp->control.step_range_end) == 0)
1129 error (_("Cannot find bounds of current function"));
1131 target_terminal_ours ();
1132 printf_filtered (_("Single stepping until exit from function %s,"
1133 "\nwhich has no line number information.\n"),
1139 /* Say we are stepping, but stop after one insn whatever it does. */
1140 tp->control.step_range_start = tp->control.step_range_end = 1;
1141 if (!sm->skip_subroutines)
1143 Don't step over function calls, not even to functions lacking
1145 tp->control.step_over_calls = STEP_OVER_NONE;
1148 if (sm->skip_subroutines)
1149 tp->control.step_over_calls = STEP_OVER_ALL;
1155 thread_fsm_set_finished (&sm->thread_fsm);
1160 /* Continue program at specified address. */
1163 jump_command (char *arg, int from_tty)
1165 struct gdbarch *gdbarch = get_current_arch ();
1167 struct symtabs_and_lines sals;
1168 struct symtab_and_line sal;
1172 struct cleanup *args_chain;
1175 ensure_not_tfind_mode ();
1176 ensure_valid_thread ();
1177 ensure_not_running ();
1179 /* Find out whether we must run in the background. */
1180 arg = strip_bg_char (arg, &async_exec);
1181 args_chain = make_cleanup (xfree, arg);
1183 prepare_execution_command (¤t_target, async_exec);
1186 error_no_arg (_("starting address"));
1188 sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1189 if (sals.nelts != 1)
1191 error (_("Unreasonable jump request"));
1197 /* Done with ARGS. */
1198 do_cleanups (args_chain);
1200 if (sal.symtab == 0 && sal.pc == 0)
1201 error (_("No source file has been specified."));
1203 resolve_sal_pc (&sal); /* May error out. */
1205 /* See if we are trying to jump to another function. */
1206 fn = get_frame_function (get_current_frame ());
1207 sfn = find_pc_function (sal.pc);
1208 if (fn != NULL && sfn != fn)
1210 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
1211 SYMBOL_PRINT_NAME (fn)))
1213 error (_("Not confirmed."));
1220 struct obj_section *section;
1222 fixup_symbol_section (sfn, 0);
1223 section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
1224 if (section_is_overlay (section)
1225 && !section_is_mapped (section))
1227 if (!query (_("WARNING!!! Destination is in "
1228 "unmapped overlay! Jump anyway? ")))
1230 error (_("Not confirmed."));
1240 printf_filtered (_("Continuing at "));
1241 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1242 printf_filtered (".\n");
1245 clear_proceed_status (0);
1246 proceed (addr, GDB_SIGNAL_0);
1249 /* Continue program giving it specified signal. */
1252 signal_command (char *signum_exp, int from_tty)
1254 enum gdb_signal oursig;
1256 struct cleanup *args_chain;
1258 dont_repeat (); /* Too dangerous. */
1260 ensure_not_tfind_mode ();
1261 ensure_valid_thread ();
1262 ensure_not_running ();
1264 /* Find out whether we must run in the background. */
1265 signum_exp = strip_bg_char (signum_exp, &async_exec);
1266 args_chain = make_cleanup (xfree, signum_exp);
1268 prepare_execution_command (¤t_target, async_exec);
1271 error_no_arg (_("signal number"));
1273 /* It would be even slicker to make signal names be valid expressions,
1274 (the type could be "enum $signal" or some such), then the user could
1275 assign them to convenience variables. */
1276 oursig = gdb_signal_from_name (signum_exp);
1278 if (oursig == GDB_SIGNAL_UNKNOWN)
1280 /* No, try numeric. */
1281 int num = parse_and_eval_long (signum_exp);
1284 oursig = GDB_SIGNAL_0;
1286 oursig = gdb_signal_from_command (num);
1289 do_cleanups (args_chain);
1291 /* Look for threads other than the current that this command ends up
1292 resuming too (due to schedlock off), and warn if they'll get a
1293 signal delivered. "signal 0" is used to suppress a previous
1294 signal, but if the current thread is no longer the one that got
1295 the signal, then the user is potentially suppressing the signal
1296 of the wrong thread. */
1299 struct thread_info *tp;
1301 int must_confirm = 0;
1303 /* This indicates what will be resumed. Either a single thread,
1304 a whole process, or all threads of all processes. */
1305 resume_ptid = user_visible_resume_ptid (0);
1307 ALL_NON_EXITED_THREADS (tp)
1309 if (ptid_equal (tp->ptid, inferior_ptid))
1311 if (!ptid_match (tp->ptid, resume_ptid))
1314 if (tp->suspend.stop_signal != GDB_SIGNAL_0
1315 && signal_pass_state (tp->suspend.stop_signal))
1318 printf_unfiltered (_("Note:\n"));
1319 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1321 gdb_signal_to_name (tp->suspend.stop_signal),
1322 gdb_signal_to_string (tp->suspend.stop_signal));
1328 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1329 "still deliver the signals noted above to their respective threads.\n"
1330 "Continue anyway? "),
1331 inferior_thread ()->num))
1332 error (_("Not confirmed."));
1337 if (oursig == GDB_SIGNAL_0)
1338 printf_filtered (_("Continuing with no signal.\n"));
1340 printf_filtered (_("Continuing with signal %s.\n"),
1341 gdb_signal_to_name (oursig));
1344 clear_proceed_status (0);
1345 proceed ((CORE_ADDR) -1, oursig);
1348 /* Queue a signal to be delivered to the current thread. */
1351 queue_signal_command (char *signum_exp, int from_tty)
1353 enum gdb_signal oursig;
1354 struct thread_info *tp;
1357 ensure_not_tfind_mode ();
1358 ensure_valid_thread ();
1359 ensure_not_running ();
1361 if (signum_exp == NULL)
1362 error_no_arg (_("signal number"));
1364 /* It would be even slicker to make signal names be valid expressions,
1365 (the type could be "enum $signal" or some such), then the user could
1366 assign them to convenience variables. */
1367 oursig = gdb_signal_from_name (signum_exp);
1369 if (oursig == GDB_SIGNAL_UNKNOWN)
1371 /* No, try numeric. */
1372 int num = parse_and_eval_long (signum_exp);
1375 oursig = GDB_SIGNAL_0;
1377 oursig = gdb_signal_from_command (num);
1380 if (oursig != GDB_SIGNAL_0
1381 && !signal_pass_state (oursig))
1382 error (_("Signal handling set to not pass this signal to the program."));
1384 tp = inferior_thread ();
1385 tp->suspend.stop_signal = oursig;
1388 /* Continuation args to be passed to the "until" command
1390 struct until_next_continuation_args
1392 /* The thread that was current when the command was executed. */
1396 /* A continuation callback for until_next_command. */
1399 until_next_continuation (void *arg, int err)
1401 struct until_next_continuation_args *a = arg;
1403 delete_longjmp_breakpoint (a->thread);
1406 /* Proceed until we reach a different source line with pc greater than
1407 our current one or exit the function. We skip calls in both cases.
1409 Note that eventually this command should probably be changed so
1410 that only source lines are printed out when we hit the breakpoint
1411 we set. This may involve changes to wait_for_inferior and the
1412 proceed status code. */
1415 until_next_command (int from_tty)
1417 struct frame_info *frame;
1419 struct symbol *func;
1420 struct symtab_and_line sal;
1421 struct thread_info *tp = inferior_thread ();
1422 int thread = tp->num;
1423 struct cleanup *old_chain;
1425 clear_proceed_status (0);
1428 frame = get_current_frame ();
1430 /* Step until either exited from this function or greater
1431 than the current line (if in symbolic section) or pc (if
1434 pc = get_frame_pc (frame);
1435 func = find_pc_function (pc);
1439 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
1441 if (msymbol.minsym == NULL)
1442 error (_("Execution is not within a known function."));
1444 tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
1445 /* The upper-bound of step_range is exclusive. In order to make PC
1446 within the range, set the step_range_end with PC + 1. */
1447 tp->control.step_range_end = pc + 1;
1451 sal = find_pc_line (pc, 0);
1453 tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1454 tp->control.step_range_end = sal.end;
1456 tp->control.may_range_step = 1;
1458 tp->control.step_over_calls = STEP_OVER_ALL;
1460 set_longjmp_breakpoint (tp, get_frame_id (frame));
1461 old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1463 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1465 if (is_running (inferior_ptid))
1467 struct until_next_continuation_args *cont_args;
1469 discard_cleanups (old_chain);
1470 cont_args = XNEW (struct until_next_continuation_args);
1471 cont_args->thread = inferior_thread ()->num;
1473 add_continuation (tp, until_next_continuation, cont_args, xfree);
1476 do_cleanups (old_chain);
1480 until_command (char *arg, int from_tty)
1483 struct cleanup *args_chain;
1486 ensure_not_tfind_mode ();
1487 ensure_valid_thread ();
1488 ensure_not_running ();
1490 /* Find out whether we must run in the background. */
1491 arg = strip_bg_char (arg, &async_exec);
1492 args_chain = make_cleanup (xfree, arg);
1494 prepare_execution_command (¤t_target, async_exec);
1497 until_break_command (arg, from_tty, 0);
1499 until_next_command (from_tty);
1501 /* Done with ARGS. */
1502 do_cleanups (args_chain);
1506 advance_command (char *arg, int from_tty)
1509 struct cleanup *args_chain;
1512 ensure_not_tfind_mode ();
1513 ensure_valid_thread ();
1514 ensure_not_running ();
1517 error_no_arg (_("a location"));
1519 /* Find out whether we must run in the background. */
1520 arg = strip_bg_char (arg, &async_exec);
1521 args_chain = make_cleanup (xfree, arg);
1523 prepare_execution_command (¤t_target, async_exec);
1525 until_break_command (arg, from_tty, 1);
1527 /* Done with ARGS. */
1528 do_cleanups (args_chain);
1531 /* Return the value of the result of a function at the end of a 'finish'
1532 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1533 right after an inferior call has finished. */
1536 get_return_value (struct value *function, struct type *value_type,
1537 struct dummy_frame_context_saver *ctx_saver)
1539 struct regcache *stop_regs = NULL;
1540 struct gdbarch *gdbarch;
1541 struct value *value;
1542 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1544 /* If registers were not saved, use the current registers. */
1545 if (ctx_saver != NULL)
1546 stop_regs = dummy_frame_context_saver_get_regs (ctx_saver);
1549 stop_regs = regcache_dup (get_current_regcache ());
1550 make_cleanup_regcache_xfree (stop_regs);
1553 gdbarch = get_regcache_arch (stop_regs);
1555 value_type = check_typedef (value_type);
1556 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1558 /* FIXME: 2003-09-27: When returning from a nested inferior function
1559 call, it's possible (with no help from the architecture vector)
1560 to locate and return/print a "struct return" value. This is just
1561 a more complicated case of what is already being done in the
1562 inferior function call code. In fact, when inferior function
1563 calls are made async, this will likely be made the norm. */
1565 switch (gdbarch_return_value (gdbarch, function, value_type,
1568 case RETURN_VALUE_REGISTER_CONVENTION:
1569 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1570 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1571 value = allocate_value (value_type);
1572 gdbarch_return_value (gdbarch, function, value_type, stop_regs,
1573 value_contents_raw (value), NULL);
1575 case RETURN_VALUE_STRUCT_CONVENTION:
1579 internal_error (__FILE__, __LINE__, _("bad switch"));
1582 do_cleanups (cleanup);
1587 /* The captured function return value/type and its position in the
1590 struct return_value_info
1592 /* The captured return value. May be NULL if we weren't able to
1593 retrieve it. See get_return_value. */
1594 struct value *value;
1596 /* The return type. In some cases, we'll not be able extract the
1597 return value, but we always know the type. */
1600 /* If we captured a value, this is the value history index. */
1601 int value_history_index;
1604 /* Helper for print_return_value. */
1607 print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
1609 if (rv->value != NULL)
1611 struct value_print_options opts;
1612 struct ui_file *stb;
1613 struct cleanup *old_chain;
1616 stb = mem_fileopen ();
1617 old_chain = make_cleanup_ui_file_delete (stb);
1618 ui_out_text (uiout, "Value returned is ");
1619 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1620 rv->value_history_index);
1621 ui_out_text (uiout, " = ");
1622 get_no_prettyformat_print_options (&opts);
1623 value_print (rv->value, stb, &opts);
1624 ui_out_field_stream (uiout, "return-value", stb);
1625 ui_out_text (uiout, "\n");
1626 do_cleanups (old_chain);
1630 struct cleanup *oldchain;
1633 type_name = type_to_string (rv->type);
1634 oldchain = make_cleanup (xfree, type_name);
1635 ui_out_text (uiout, "Value returned has type: ");
1636 ui_out_field_string (uiout, "return-type", type_name);
1637 ui_out_text (uiout, ".");
1638 ui_out_text (uiout, " Cannot determine contents\n");
1639 do_cleanups (oldchain);
1643 /* Print the result of a function at the end of a 'finish' command.
1644 RV points at an object representing the captured return value/type
1645 and its position in the value history. */
1648 print_return_value (struct ui_out *uiout, struct return_value_info *rv)
1650 if (rv->type == NULL || TYPE_CODE (rv->type) == TYPE_CODE_VOID)
1655 /* print_return_value_1 can throw an exception in some
1656 circumstances. We need to catch this so that we still
1657 delete the breakpoint. */
1658 print_return_value_1 (uiout, rv);
1660 CATCH (ex, RETURN_MASK_ALL)
1662 exception_print (gdb_stdout, ex);
1667 /* Data for the FSM that manages the finish command. */
1669 struct finish_command_fsm
1671 /* The base class. */
1672 struct thread_fsm thread_fsm;
1674 /* The thread that was current when the command was executed. */
1677 /* The momentary breakpoint set at the function's return address in
1679 struct breakpoint *breakpoint;
1681 /* The function that we're stepping out of. */
1682 struct symbol *function;
1684 /* If the FSM finishes successfully, this stores the function's
1686 struct return_value_info return_value;
1689 static int finish_command_fsm_should_stop (struct thread_fsm *self);
1690 static void finish_command_fsm_clean_up (struct thread_fsm *self);
1691 static struct return_value_info *
1692 finish_command_fsm_return_value (struct thread_fsm *self);
1693 static enum async_reply_reason
1694 finish_command_fsm_async_reply_reason (struct thread_fsm *self);
1696 /* finish_command_fsm's vtable. */
1698 static struct thread_fsm_ops finish_command_fsm_ops =
1701 finish_command_fsm_clean_up,
1702 finish_command_fsm_should_stop,
1703 finish_command_fsm_return_value,
1704 finish_command_fsm_async_reply_reason,
1707 /* Allocate a new finish_command_fsm. */
1709 static struct finish_command_fsm *
1710 new_finish_command_fsm (int thread)
1712 struct finish_command_fsm *sm;
1714 sm = XCNEW (struct finish_command_fsm);
1715 thread_fsm_ctor (&sm->thread_fsm, &finish_command_fsm_ops);
1717 sm->thread = thread;
1722 /* Implementation of the 'should_stop' FSM method for the finish
1723 commands. Detects whether the thread stepped out of the function
1724 successfully, and if so, captures the function's return value and
1725 marks the FSM finished. */
1728 finish_command_fsm_should_stop (struct thread_fsm *self)
1730 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1731 struct return_value_info *rv = &f->return_value;
1732 struct thread_info *tp = find_thread_id (f->thread);
1734 if (f->function != NULL
1735 && bpstat_find_breakpoint (tp->control.stop_bpstat,
1736 f->breakpoint) != NULL)
1739 thread_fsm_set_finished (self);
1741 rv->type = TYPE_TARGET_TYPE (SYMBOL_TYPE (f->function));
1742 if (rv->type == NULL)
1743 internal_error (__FILE__, __LINE__,
1744 _("finish_command: function has no target type"));
1746 if (TYPE_CODE (rv->type) != TYPE_CODE_VOID)
1750 func = read_var_value (f->function, NULL, get_current_frame ());
1751 rv->value = get_return_value (func, rv->type, NULL);
1752 rv->value_history_index = record_latest_value (rv->value);
1755 else if (tp->control.stop_step)
1757 /* Finishing from an inline frame, or reverse finishing. In
1758 either case, there's no way to retrieve the return value. */
1759 thread_fsm_set_finished (self);
1765 /* Implementation of the 'clean_up' FSM method for the finish
1769 finish_command_fsm_clean_up (struct thread_fsm *self)
1771 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1773 if (f->breakpoint != NULL)
1775 delete_breakpoint (f->breakpoint);
1776 f->breakpoint = NULL;
1778 delete_longjmp_breakpoint (f->thread);
1781 /* Implementation of the 'return_value' FSM method for the finish
1784 static struct return_value_info *
1785 finish_command_fsm_return_value (struct thread_fsm *self)
1787 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1789 return &f->return_value;
1792 /* Implementation of the 'async_reply_reason' FSM method for the
1795 static enum async_reply_reason
1796 finish_command_fsm_async_reply_reason (struct thread_fsm *self)
1798 struct finish_command_fsm *f = (struct finish_command_fsm *) self;
1800 if (execution_direction == EXEC_REVERSE)
1801 return EXEC_ASYNC_END_STEPPING_RANGE;
1803 return EXEC_ASYNC_FUNCTION_FINISHED;
1806 /* finish_backward -- helper function for finish_command. */
1809 finish_backward (struct finish_command_fsm *sm)
1811 struct symtab_and_line sal;
1812 struct thread_info *tp = inferior_thread ();
1814 CORE_ADDR func_addr;
1816 pc = get_frame_pc (get_current_frame ());
1818 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1819 error (_("Cannot find bounds of current function"));
1821 sal = find_pc_line (func_addr, 0);
1823 tp->control.proceed_to_finish = 1;
1824 /* Special case: if we're sitting at the function entry point,
1825 then all we need to do is take a reverse singlestep. We
1826 don't need to set a breakpoint, and indeed it would do us
1829 Note that this can only happen at frame #0, since there's
1830 no way that a function up the stack can have a return address
1831 that's equal to its entry point. */
1835 struct frame_info *frame = get_selected_frame (NULL);
1836 struct gdbarch *gdbarch = get_frame_arch (frame);
1837 struct symtab_and_line sr_sal;
1839 /* Set a step-resume at the function's entry point. Once that's
1840 hit, we'll do one more step backwards. */
1843 sr_sal.pspace = get_frame_program_space (frame);
1844 insert_step_resume_breakpoint_at_sal (gdbarch,
1845 sr_sal, null_frame_id);
1847 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1851 /* We're almost there -- we just need to back up by one more
1853 tp->control.step_range_start = tp->control.step_range_end = 1;
1854 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1858 /* finish_forward -- helper function for finish_command. FRAME is the
1859 frame that called the function we're about to step out of. */
1862 finish_forward (struct finish_command_fsm *sm, struct frame_info *frame)
1864 struct frame_id frame_id = get_frame_id (frame);
1865 struct gdbarch *gdbarch = get_frame_arch (frame);
1866 struct symtab_and_line sal;
1867 struct thread_info *tp = inferior_thread ();
1869 sal = find_pc_line (get_frame_pc (frame), 0);
1870 sal.pc = get_frame_pc (frame);
1872 sm->breakpoint = set_momentary_breakpoint (gdbarch, sal,
1873 get_stack_frame_id (frame),
1876 /* set_momentary_breakpoint invalidates FRAME. */
1879 set_longjmp_breakpoint (tp, frame_id);
1881 /* We want to print return value, please... */
1882 tp->control.proceed_to_finish = 1;
1884 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1887 /* "finish": Set a temporary breakpoint at the place the selected
1888 frame will return to, then continue. */
1891 finish_command (char *arg, int from_tty)
1893 struct frame_info *frame;
1895 struct cleanup *args_chain;
1896 struct finish_command_fsm *sm;
1897 struct thread_info *tp;
1900 ensure_not_tfind_mode ();
1901 ensure_valid_thread ();
1902 ensure_not_running ();
1904 /* Find out whether we must run in the background. */
1905 arg = strip_bg_char (arg, &async_exec);
1906 args_chain = make_cleanup (xfree, arg);
1908 prepare_execution_command (¤t_target, async_exec);
1911 error (_("The \"finish\" command does not take any arguments."));
1913 /* Done with ARGS. */
1914 do_cleanups (args_chain);
1916 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1918 error (_("\"finish\" not meaningful in the outermost frame."));
1920 clear_proceed_status (0);
1922 tp = inferior_thread ();
1924 sm = new_finish_command_fsm (tp->num);
1926 tp->thread_fsm = &sm->thread_fsm;
1928 /* Finishing from an inline frame is completely different. We don't
1929 try to show the "return value" - no way to locate it. */
1930 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1933 /* Claim we are stepping in the calling frame. An empty step
1934 range means that we will stop once we aren't in a function
1935 called by that frame. We don't use the magic "1" value for
1936 step_range_end, because then infrun will think this is nexti,
1937 and not step over the rest of this inlined function call. */
1938 struct symtab_and_line empty_sal;
1940 init_sal (&empty_sal);
1941 set_step_info (frame, empty_sal);
1942 tp->control.step_range_start = get_frame_pc (frame);
1943 tp->control.step_range_end = tp->control.step_range_start;
1944 tp->control.step_over_calls = STEP_OVER_ALL;
1946 /* Print info on the selected frame, including level number but not
1950 printf_filtered (_("Run till exit from "));
1951 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1954 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1958 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1959 entering THISFRAME. */
1960 while (get_frame_type (frame) == TAILCALL_FRAME)
1961 frame = get_prev_frame (frame);
1963 /* Find the function we will return from. */
1965 sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1967 /* Print info on the selected frame, including level number but not
1971 if (execution_direction == EXEC_REVERSE)
1972 printf_filtered (_("Run back to call of "));
1975 if (sm->function != NULL && TYPE_NO_RETURN (sm->function->type)
1976 && !query (_("warning: Function %s does not return normally.\n"
1977 "Try to finish anyway? "),
1978 SYMBOL_PRINT_NAME (sm->function)))
1979 error (_("Not confirmed."));
1980 printf_filtered (_("Run till exit from "));
1983 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1986 if (execution_direction == EXEC_REVERSE)
1987 finish_backward (sm);
1989 finish_forward (sm, frame);
1994 program_info (char *args, int from_tty)
1998 struct thread_info *tp;
2001 if (!target_has_execution)
2003 printf_filtered (_("The program being debugged is not being run.\n"));
2008 ptid = inferior_ptid;
2011 struct target_waitstatus ws;
2013 get_last_target_status (&ptid, &ws);
2016 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
2017 error (_("Invalid selected thread."));
2018 else if (is_running (ptid))
2019 error (_("Selected thread is running."));
2021 tp = find_thread_ptid (ptid);
2022 bs = tp->control.stop_bpstat;
2023 stat = bpstat_num (&bs, &num);
2025 target_files_info ();
2026 printf_filtered (_("Program stopped at %s.\n"),
2027 paddress (target_gdbarch (), stop_pc));
2028 if (tp->control.stop_step)
2029 printf_filtered (_("It stopped after being stepped.\n"));
2032 /* There may be several breakpoints in the same place, so this
2033 isn't as strange as it seems. */
2038 printf_filtered (_("It stopped at a breakpoint "
2039 "that has since been deleted.\n"));
2042 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
2043 stat = bpstat_num (&bs, &num);
2046 else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
2048 printf_filtered (_("It stopped with signal %s, %s.\n"),
2049 gdb_signal_to_name (tp->suspend.stop_signal),
2050 gdb_signal_to_string (tp->suspend.stop_signal));
2055 printf_filtered (_("Type \"info stack\" or \"info "
2056 "registers\" for more information.\n"));
2061 environment_info (char *var, int from_tty)
2065 char *val = get_in_environ (current_inferior ()->environment, var);
2069 puts_filtered (var);
2070 puts_filtered (" = ");
2071 puts_filtered (val);
2072 puts_filtered ("\n");
2076 puts_filtered ("Environment variable \"");
2077 puts_filtered (var);
2078 puts_filtered ("\" not defined.\n");
2083 char **vector = environ_vector (current_inferior ()->environment);
2087 puts_filtered (*vector++);
2088 puts_filtered ("\n");
2094 set_environment_command (char *arg, int from_tty)
2096 char *p, *val, *var;
2100 error_no_arg (_("environment variable and value"));
2102 /* Find seperation between variable name and value. */
2103 p = (char *) strchr (arg, '=');
2104 val = (char *) strchr (arg, ' ');
2106 if (p != 0 && val != 0)
2108 /* We have both a space and an equals. If the space is before the
2109 equals, walk forward over the spaces til we see a nonspace
2110 (possibly the equals). */
2115 /* Now if the = is after the char following the spaces,
2116 take the char following the spaces. */
2120 else if (val != 0 && p == 0)
2124 error_no_arg (_("environment variable to set"));
2126 if (p == 0 || p[1] == 0)
2130 p = arg + strlen (arg); /* So that savestring below will work. */
2134 /* Not setting variable value to null. */
2136 while (*val == ' ' || *val == '\t')
2140 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2143 var = savestring (arg, p - arg);
2146 printf_filtered (_("Setting environment variable "
2147 "\"%s\" to null value.\n"),
2149 set_in_environ (current_inferior ()->environment, var, "");
2152 set_in_environ (current_inferior ()->environment, var, val);
2157 unset_environment_command (char *var, int from_tty)
2161 /* If there is no argument, delete all environment variables.
2162 Ask for confirmation if reading from the terminal. */
2163 if (!from_tty || query (_("Delete all environment variables? ")))
2165 free_environ (current_inferior ()->environment);
2166 current_inferior ()->environment = make_environ ();
2170 unset_in_environ (current_inferior ()->environment, var);
2173 /* Handle the execution path (PATH variable). */
2175 static const char path_var_name[] = "PATH";
2178 path_info (char *args, int from_tty)
2180 puts_filtered ("Executable and object file path: ");
2181 puts_filtered (get_in_environ (current_inferior ()->environment,
2183 puts_filtered ("\n");
2186 /* Add zero or more directories to the front of the execution path. */
2189 path_command (char *dirname, int from_tty)
2195 env = get_in_environ (current_inferior ()->environment, path_var_name);
2196 /* Can be null if path is not set. */
2199 exec_path = xstrdup (env);
2200 mod_path (dirname, &exec_path);
2201 set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
2204 path_info ((char *) NULL, from_tty);
2208 /* Print out the register NAME with value VAL, to FILE, in the default
2212 default_print_one_register_info (struct ui_file *file,
2216 struct type *regtype = value_type (val);
2217 int print_raw_format;
2219 fputs_filtered (name, file);
2220 print_spaces_filtered (15 - strlen (name), file);
2222 print_raw_format = (value_entirely_available (val)
2223 && !value_optimized_out (val));
2225 /* If virtual format is floating, print it that way, and in raw
2227 if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2228 || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2231 struct value_print_options opts;
2232 const gdb_byte *valaddr = value_contents_for_printing (val);
2233 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2235 get_user_print_options (&opts);
2239 value_contents_for_printing (val),
2240 value_embedded_offset (val), 0,
2241 file, 0, val, &opts, current_language);
2243 if (print_raw_format)
2245 fprintf_filtered (file, "\t(raw ");
2246 print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
2247 fprintf_filtered (file, ")");
2252 struct value_print_options opts;
2254 /* Print the register in hex. */
2255 get_formatted_print_options (&opts, 'x');
2258 value_contents_for_printing (val),
2259 value_embedded_offset (val), 0,
2260 file, 0, val, &opts, current_language);
2261 /* If not a vector register, print it also according to its
2263 if (print_raw_format && TYPE_VECTOR (regtype) == 0)
2265 get_user_print_options (&opts);
2267 fprintf_filtered (file, "\t");
2269 value_contents_for_printing (val),
2270 value_embedded_offset (val), 0,
2271 file, 0, val, &opts, current_language);
2275 fprintf_filtered (file, "\n");
2278 /* Print out the machine register regnum. If regnum is -1, print all
2279 registers (print_all == 1) or all non-float and non-vector
2280 registers (print_all == 0).
2282 For most machines, having all_registers_info() print the
2283 register(s) one per line is good enough. If a different format is
2284 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2285 regs), or there is an existing convention for showing all the
2286 registers, define the architecture method PRINT_REGISTERS_INFO to
2287 provide that format. */
2290 default_print_registers_info (struct gdbarch *gdbarch,
2291 struct ui_file *file,
2292 struct frame_info *frame,
2293 int regnum, int print_all)
2296 const int numregs = gdbarch_num_regs (gdbarch)
2297 + gdbarch_num_pseudo_regs (gdbarch);
2299 for (i = 0; i < numregs; i++)
2301 /* Decide between printing all regs, non-float / vector regs, or
2307 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
2312 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
2322 /* If the register name is empty, it is undefined for this
2323 processor, so don't display anything. */
2324 if (gdbarch_register_name (gdbarch, i) == NULL
2325 || *(gdbarch_register_name (gdbarch, i)) == '\0')
2328 default_print_one_register_info (file,
2329 gdbarch_register_name (gdbarch, i),
2330 value_of_register (i, frame));
2335 registers_info (char *addr_exp, int fpregs)
2337 struct frame_info *frame;
2338 struct gdbarch *gdbarch;
2340 if (!target_has_registers)
2341 error (_("The program has no registers now."));
2342 frame = get_selected_frame (NULL);
2343 gdbarch = get_frame_arch (frame);
2347 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2352 while (*addr_exp != '\0')
2357 /* Skip leading white space. */
2358 addr_exp = skip_spaces (addr_exp);
2360 /* Discard any leading ``$''. Check that there is something
2361 resembling a register following it. */
2362 if (addr_exp[0] == '$')
2364 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2365 error (_("Missing register name"));
2367 /* Find the start/end of this register name/num/group. */
2369 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2373 /* Figure out what we've found and display it. */
2375 /* A register name? */
2377 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2381 /* User registers lie completely outside of the range of
2382 normal registers. Catch them early so that the target
2384 if (regnum >= gdbarch_num_regs (gdbarch)
2385 + gdbarch_num_pseudo_regs (gdbarch))
2387 struct value *regval = value_of_user_reg (regnum, frame);
2388 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2391 /* Print in the same fashion
2392 gdbarch_print_registers_info's default
2393 implementation prints. */
2394 default_print_one_register_info (gdb_stdout,
2399 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2400 frame, regnum, fpregs);
2405 /* A register group? */
2407 struct reggroup *group;
2409 for (group = reggroup_next (gdbarch, NULL);
2411 group = reggroup_next (gdbarch, group))
2413 /* Don't bother with a length check. Should the user
2414 enter a short register group name, go with the first
2415 group that matches. */
2416 if (strncmp (start, reggroup_name (group), end - start) == 0)
2424 regnum < gdbarch_num_regs (gdbarch)
2425 + gdbarch_num_pseudo_regs (gdbarch);
2428 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2429 gdbarch_print_registers_info (gdbarch,
2437 /* Nothing matched. */
2438 error (_("Invalid register `%.*s'"), (int) (end - start), start);
2443 all_registers_info (char *addr_exp, int from_tty)
2445 registers_info (addr_exp, 1);
2449 nofp_registers_info (char *addr_exp, int from_tty)
2451 registers_info (addr_exp, 0);
2455 print_vector_info (struct ui_file *file,
2456 struct frame_info *frame, const char *args)
2458 struct gdbarch *gdbarch = get_frame_arch (frame);
2460 if (gdbarch_print_vector_info_p (gdbarch))
2461 gdbarch_print_vector_info (gdbarch, file, frame, args);
2465 int printed_something = 0;
2468 regnum < gdbarch_num_regs (gdbarch)
2469 + gdbarch_num_pseudo_regs (gdbarch);
2472 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2474 printed_something = 1;
2475 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2478 if (!printed_something)
2479 fprintf_filtered (file, "No vector information\n");
2484 vector_info (char *args, int from_tty)
2486 if (!target_has_registers)
2487 error (_("The program has no registers now."));
2489 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2492 /* Kill the inferior process. Make us have no inferior. */
2495 kill_command (char *arg, int from_tty)
2497 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2498 It should be a distinct flag that indicates that a target is active, cuz
2499 some targets don't have processes! */
2501 if (ptid_equal (inferior_ptid, null_ptid))
2502 error (_("The program is not being run."));
2503 if (!query (_("Kill the program being debugged? ")))
2504 error (_("Not confirmed."));
2507 /* If we still have other inferiors to debug, then don't mess with
2508 with their threads. */
2509 if (!have_inferiors ())
2511 init_thread_list (); /* Destroy thread info. */
2513 /* Killing off the inferior can leave us with a core file. If
2514 so, print the state we are left in. */
2515 if (target_has_stack)
2517 printf_filtered (_("In %s,\n"), target_longname);
2518 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2521 bfd_cache_close_all ();
2524 /* Used in `attach&' command. ARG is a point to an integer
2525 representing a process id. Proceed threads of this process iff
2526 they stopped due to debugger request, and when they did, they
2527 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
2528 that have been explicitly been told to stop. */
2531 proceed_after_attach_callback (struct thread_info *thread,
2534 int pid = * (int *) arg;
2536 if (ptid_get_pid (thread->ptid) == pid
2537 && !is_exited (thread->ptid)
2538 && !is_executing (thread->ptid)
2539 && !thread->stop_requested
2540 && thread->suspend.stop_signal == GDB_SIGNAL_0)
2542 switch_to_thread (thread->ptid);
2543 clear_proceed_status (0);
2544 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2551 proceed_after_attach (int pid)
2553 /* Don't error out if the current thread is running, because
2554 there may be other stopped threads. */
2555 struct cleanup *old_chain;
2557 /* Backup current thread and selected frame. */
2558 old_chain = make_cleanup_restore_current_thread ();
2560 iterate_over_threads (proceed_after_attach_callback, &pid);
2562 /* Restore selected ptid. */
2563 do_cleanups (old_chain);
2566 /* attach_command --
2567 takes a program started up outside of gdb and ``attaches'' to it.
2568 This stops it cold in its tracks and allows us to start debugging it.
2569 and wait for the trace-trap that results from attaching. */
2572 attach_command_post_wait (char *args, int from_tty, int async_exec)
2574 struct inferior *inferior;
2576 inferior = current_inferior ();
2577 inferior->control.stop_soon = NO_STOP_QUIETLY;
2579 /* If no exec file is yet known, try to determine it from the
2581 if (get_exec_file (0) == NULL)
2582 exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
2585 reopen_exec_file ();
2589 /* Take any necessary post-attaching actions for this platform. */
2590 target_post_attach (ptid_get_pid (inferior_ptid));
2592 post_create_inferior (¤t_target, from_tty);
2596 /* The user requested an `attach&', so be sure to leave threads
2597 that didn't get a signal running. */
2599 /* Immediatelly resume all suspended threads of this inferior,
2600 and this inferior only. This should have no effect on
2601 already running threads. If a thread has been stopped with a
2602 signal, leave it be. */
2604 proceed_after_attach (inferior->pid);
2607 if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
2609 clear_proceed_status (0);
2610 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2616 /* The user requested a plain `attach', so be sure to leave
2617 the inferior stopped. */
2619 async_enable_stdin ();
2621 /* At least the current thread is already stopped. */
2623 /* In all-stop, by definition, all threads have to be already
2624 stopped at this point. In non-stop, however, although the
2625 selected thread is stopped, others may still be executing.
2626 Be sure to explicitly stop all threads of the process. This
2627 should have no effect on already stopped threads. */
2628 if (target_is_non_stop_p ())
2629 target_stop (pid_to_ptid (inferior->pid));
2631 /* Tell the user/frontend where we're stopped. */
2633 if (deprecated_attach_hook)
2634 deprecated_attach_hook ();
2638 struct attach_command_continuation_args
2646 attach_command_continuation (void *args, int err)
2648 struct attach_command_continuation_args *a = args;
2653 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2657 attach_command_continuation_free_args (void *args)
2659 struct attach_command_continuation_args *a = args;
2666 attach_command (char *args, int from_tty)
2669 struct cleanup *args_chain;
2670 struct target_ops *attach_target;
2672 dont_repeat (); /* Not for the faint of heart */
2674 if (gdbarch_has_global_solist (target_gdbarch ()))
2675 /* Don't complain if all processes share the same symbol
2678 else if (target_has_execution)
2680 if (query (_("A program is being debugged already. Kill it? ")))
2683 error (_("Not killed."));
2686 /* Clean up any leftovers from other runs. Some other things from
2687 this function should probably be moved into target_pre_inferior. */
2688 target_pre_inferior (from_tty);
2690 args = strip_bg_char (args, &async_exec);
2691 args_chain = make_cleanup (xfree, args);
2693 attach_target = find_attach_target ();
2695 prepare_execution_command (attach_target, async_exec);
2697 if (non_stop && !attach_target->to_supports_non_stop (attach_target))
2698 error (_("Cannot attach to this target in non-stop mode"));
2700 attach_target->to_attach (attach_target, args, from_tty);
2701 /* to_attach should push the target, so after this point we
2702 shouldn't refer to attach_target again. */
2703 attach_target = NULL;
2705 /* Set up the "saved terminal modes" of the inferior
2706 based on what modes we are starting it with. */
2707 target_terminal_init ();
2709 /* Install inferior's terminal modes. This may look like a no-op,
2710 as we've just saved them above, however, this does more than
2711 restore terminal settings:
2713 - installs a SIGINT handler that forwards SIGINT to the inferior.
2714 Otherwise a Ctrl-C pressed just while waiting for the initial
2715 stop would end up as a spurious Quit.
2717 - removes stdin from the event loop, which we need if attaching
2718 in the foreground, otherwise on targets that report an initial
2719 stop on attach (which are most) we'd process input/commands
2720 while we're in the event loop waiting for that stop. That is,
2721 before the attach continuation runs and the command is really
2723 target_terminal_inferior ();
2725 /* Set up execution context to know that we should return from
2726 wait_for_inferior as soon as the target reports a stop. */
2727 init_wait_for_inferior ();
2728 clear_proceed_status (0);
2730 if (target_is_non_stop_p ())
2732 /* If we find that the current thread isn't stopped, explicitly
2733 do so now, because we're going to install breakpoints and
2737 /* The user requested an `attach&'; stop just one thread. */
2738 target_stop (inferior_ptid);
2740 /* The user requested an `attach', so stop all threads of this
2742 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2745 /* Some system don't generate traps when attaching to inferior.
2746 E.g. Mach 3 or GNU hurd. */
2747 if (!target_attach_no_wait)
2749 struct attach_command_continuation_args *a;
2750 struct inferior *inferior = current_inferior ();
2752 /* Careful here. See comments in inferior.h. Basically some
2753 OSes don't ignore SIGSTOPs on continue requests anymore. We
2754 need a way for handle_inferior_event to reset the stop_signal
2755 variable after an attach, and this is what
2756 STOP_QUIETLY_NO_SIGSTOP is for. */
2757 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2759 /* sync_execution mode. Wait for stop. */
2760 a = XNEW (struct attach_command_continuation_args);
2761 a->args = xstrdup (args);
2762 a->from_tty = from_tty;
2763 a->async_exec = async_exec;
2764 add_inferior_continuation (attach_command_continuation, a,
2765 attach_command_continuation_free_args);
2766 /* Done with ARGS. */
2767 do_cleanups (args_chain);
2769 if (!target_is_async_p ())
2770 mark_infrun_async_event_handler ();
2774 /* Done with ARGS. */
2775 do_cleanups (args_chain);
2777 attach_command_post_wait (args, from_tty, async_exec);
2780 /* We had just found out that the target was already attached to an
2781 inferior. PTID points at a thread of this new inferior, that is
2782 the most likely to be stopped right now, but not necessarily so.
2783 The new inferior is assumed to be already added to the inferior
2784 list at this point. If LEAVE_RUNNING, then leave the threads of
2785 this inferior running, except those we've explicitly seen reported
2789 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2791 struct cleanup* old_chain;
2794 old_chain = make_cleanup (null_cleanup, NULL);
2796 /* If in non-stop, leave threads as running as they were. If
2797 they're stopped for some reason other than us telling it to, the
2798 target reports a signal != GDB_SIGNAL_0. We don't try to
2799 resume threads with such a stop signal. */
2800 async_exec = non_stop;
2802 if (!ptid_equal (inferior_ptid, null_ptid))
2803 make_cleanup_restore_current_thread ();
2805 switch_to_thread (ptid);
2807 /* When we "notice" a new inferior we need to do all the things we
2808 would normally do if we had just attached to it. */
2810 if (is_executing (inferior_ptid))
2812 struct attach_command_continuation_args *a;
2813 struct inferior *inferior = current_inferior ();
2815 /* We're going to install breakpoints, and poke at memory,
2816 ensure that the inferior is stopped for a moment while we do
2818 target_stop (inferior_ptid);
2820 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2822 /* Wait for stop before proceeding. */
2823 a = XNEW (struct attach_command_continuation_args);
2824 a->args = xstrdup ("");
2825 a->from_tty = from_tty;
2826 a->async_exec = async_exec;
2827 add_inferior_continuation (attach_command_continuation, a,
2828 attach_command_continuation_free_args);
2830 do_cleanups (old_chain);
2834 async_exec = leave_running;
2835 attach_command_post_wait ("" /* args */, from_tty, async_exec);
2837 do_cleanups (old_chain);
2842 * takes a program previously attached to and detaches it.
2843 * The program resumes execution and will no longer stop
2844 * on signals, etc. We better not have left any breakpoints
2845 * in the program or it'll die when it hits one. For this
2846 * to work, it may be necessary for the process to have been
2847 * previously attached. It *might* work if the program was
2848 * started via the normal ptrace (PTRACE_TRACEME).
2852 detach_command (char *args, int from_tty)
2854 dont_repeat (); /* Not for the faint of heart. */
2856 if (ptid_equal (inferior_ptid, null_ptid))
2857 error (_("The program is not being run."));
2859 query_if_trace_running (from_tty);
2861 disconnect_tracing ();
2863 target_detach (args, from_tty);
2865 /* If the solist is global across inferiors, don't clear it when we
2866 detach from a single inferior. */
2867 if (!gdbarch_has_global_solist (target_gdbarch ()))
2868 no_shared_libraries (NULL, from_tty);
2870 /* If we still have inferiors to debug, then don't mess with their
2872 if (!have_inferiors ())
2873 init_thread_list ();
2875 if (deprecated_detach_hook)
2876 deprecated_detach_hook ();
2879 /* Disconnect from the current target without resuming it (leaving it
2880 waiting for a debugger).
2882 We'd better not have left any breakpoints in the program or the
2883 next debugger will get confused. Currently only supported for some
2884 remote targets, since the normal attach mechanisms don't work on
2885 stopped processes on some native platforms (e.g. GNU/Linux). */
2888 disconnect_command (char *args, int from_tty)
2890 dont_repeat (); /* Not for the faint of heart. */
2891 query_if_trace_running (from_tty);
2892 disconnect_tracing ();
2893 target_disconnect (args, from_tty);
2894 no_shared_libraries (NULL, from_tty);
2895 init_thread_list ();
2896 if (deprecated_detach_hook)
2897 deprecated_detach_hook ();
2901 interrupt_target_1 (int all_threads)
2906 ptid = minus_one_ptid;
2908 ptid = inferior_ptid;
2909 target_interrupt (ptid);
2911 /* Tag the thread as having been explicitly requested to stop, so
2912 other parts of gdb know not to resume this thread automatically,
2913 if it was stopped due to an internal event. Limit this to
2914 non-stop mode, as when debugging a multi-threaded application in
2915 all-stop mode, we will only get one stop event --- it's undefined
2916 which thread will report the event. */
2918 set_stop_requested (ptid, 1);
2922 Stop the execution of the target while running in async mode, in
2923 the backgound. In all-stop, stop the whole process. In non-stop
2924 mode, stop the current thread only by default, or stop all threads
2925 if the `-a' switch is used. */
2928 interrupt_command (char *args, int from_tty)
2930 if (target_can_async_p ())
2932 int all_threads = 0;
2934 dont_repeat (); /* Not for the faint of heart. */
2937 && startswith (args, "-a"))
2940 if (!non_stop && all_threads)
2941 error (_("-a is meaningless in all-stop mode."));
2943 interrupt_target_1 (all_threads);
2947 /* See inferior.h. */
2950 default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2951 struct frame_info *frame, const char *args)
2954 int printed_something = 0;
2957 regnum < gdbarch_num_regs (gdbarch)
2958 + gdbarch_num_pseudo_regs (gdbarch);
2961 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2963 printed_something = 1;
2964 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2967 if (!printed_something)
2968 fprintf_filtered (file, "No floating-point info "
2969 "available for this processor.\n");
2973 float_info (char *args, int from_tty)
2975 struct frame_info *frame;
2977 if (!target_has_registers)
2978 error (_("The program has no registers now."));
2980 frame = get_selected_frame (NULL);
2981 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
2985 unset_command (char *args, int from_tty)
2987 printf_filtered (_("\"unset\" must be followed by the "
2988 "name of an unset subcommand.\n"));
2989 help_list (unsetlist, "unset ", all_commands, gdb_stdout);
2992 /* Implement `info proc' family of commands. */
2995 info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
2997 struct gdbarch *gdbarch = get_current_arch ();
2999 if (!target_info_proc (args, what))
3001 if (gdbarch_info_proc_p (gdbarch))
3002 gdbarch_info_proc (gdbarch, args, what);
3004 error (_("Not supported on this target."));
3008 /* Implement `info proc' when given without any futher parameters. */
3011 info_proc_cmd (char *args, int from_tty)
3013 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
3016 /* Implement `info proc mappings'. */
3019 info_proc_cmd_mappings (char *args, int from_tty)
3021 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
3024 /* Implement `info proc stat'. */
3027 info_proc_cmd_stat (char *args, int from_tty)
3029 info_proc_cmd_1 (args, IP_STAT, from_tty);
3032 /* Implement `info proc status'. */
3035 info_proc_cmd_status (char *args, int from_tty)
3037 info_proc_cmd_1 (args, IP_STATUS, from_tty);
3040 /* Implement `info proc cwd'. */
3043 info_proc_cmd_cwd (char *args, int from_tty)
3045 info_proc_cmd_1 (args, IP_CWD, from_tty);
3048 /* Implement `info proc cmdline'. */
3051 info_proc_cmd_cmdline (char *args, int from_tty)
3053 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
3056 /* Implement `info proc exe'. */
3059 info_proc_cmd_exe (char *args, int from_tty)
3061 info_proc_cmd_1 (args, IP_EXE, from_tty);
3064 /* Implement `info proc all'. */
3067 info_proc_cmd_all (char *args, int from_tty)
3069 info_proc_cmd_1 (args, IP_ALL, from_tty);
3073 _initialize_infcmd (void)
3075 static struct cmd_list_element *info_proc_cmdlist;
3076 struct cmd_list_element *c = NULL;
3077 const char *cmd_name;
3079 /* Add the filename of the terminal connected to inferior I/O. */
3080 add_setshow_filename_cmd ("inferior-tty", class_run,
3081 &inferior_io_terminal_scratch, _("\
3082 Set terminal for future runs of program being debugged."), _("\
3083 Show terminal for future runs of program being debugged."), _("\
3084 Usage: set inferior-tty /dev/pts/1"),
3085 set_inferior_tty_command,
3086 show_inferior_tty_command,
3087 &setlist, &showlist);
3088 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
3091 add_setshow_string_noescape_cmd (cmd_name, class_run,
3092 &inferior_args_scratch, _("\
3093 Set argument list to give program being debugged when it is started."), _("\
3094 Show argument list to give program being debugged when it is started."), _("\
3095 Follow this command with any number of args, to be passed to the program."),
3098 &setlist, &showlist);
3099 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
3100 gdb_assert (c != NULL);
3101 set_cmd_completer (c, filename_completer);
3103 c = add_cmd ("environment", no_class, environment_info, _("\
3104 The environment to give the program, or one variable's value.\n\
3105 With an argument VAR, prints the value of environment variable VAR to\n\
3106 give the program being debugged. With no arguments, prints the entire\n\
3107 environment to be given to the program."), &showlist);
3108 set_cmd_completer (c, noop_completer);
3110 add_prefix_cmd ("unset", no_class, unset_command,
3111 _("Complement to certain \"set\" commands."),
3112 &unsetlist, "unset ", 0, &cmdlist);
3114 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3115 Cancel environment variable VAR for the program.\n\
3116 This does not affect the program until the next \"run\" command."),
3118 set_cmd_completer (c, noop_completer);
3120 c = add_cmd ("environment", class_run, set_environment_command, _("\
3121 Set environment variable value to give the program.\n\
3122 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3123 VALUES of environment variables are uninterpreted strings.\n\
3124 This does not affect the program until the next \"run\" command."),
3126 set_cmd_completer (c, noop_completer);
3128 c = add_com ("path", class_files, path_command, _("\
3129 Add directory DIR(s) to beginning of search path for object files.\n\
3130 $cwd in the path means the current working directory.\n\
3131 This path is equivalent to the $PATH shell variable. It is a list of\n\
3132 directories, separated by colons. These directories are searched to find\n\
3133 fully linked executable files and separately compiled object files as \
3135 set_cmd_completer (c, filename_completer);
3137 c = add_cmd ("paths", no_class, path_info, _("\
3138 Current search path for finding object files.\n\
3139 $cwd in the path means the current working directory.\n\
3140 This path is equivalent to the $PATH shell variable. It is a list of\n\
3141 directories, separated by colons. These directories are searched to find\n\
3142 fully linked executable files and separately compiled object files as \
3145 set_cmd_completer (c, noop_completer);
3147 add_prefix_cmd ("kill", class_run, kill_command,
3148 _("Kill execution of program being debugged."),
3149 &killlist, "kill ", 0, &cmdlist);
3151 add_com ("attach", class_run, attach_command, _("\
3152 Attach to a process or file outside of GDB.\n\
3153 This command attaches to another target, of the same type as your last\n\
3154 \"target\" command (\"info files\" will show your target stack).\n\
3155 The command may take as argument a process id or a device file.\n\
3156 For a process id, you must have permission to send the process a signal,\n\
3157 and it must have the same effective uid as the debugger.\n\
3158 When using \"attach\" with a process id, the debugger finds the\n\
3159 program running in the process, looking first in the current working\n\
3160 directory, or (if not found there) using the source file search path\n\
3161 (see the \"directory\" command). You can also use the \"file\" command\n\
3162 to specify the program, and to load its symbol table."));
3164 add_prefix_cmd ("detach", class_run, detach_command, _("\
3165 Detach a process or file previously attached.\n\
3166 If a process, it is no longer traced, and it continues its execution. If\n\
3167 you were debugging a file, the file is closed and gdb no longer accesses it."),
3168 &detachlist, "detach ", 0, &cmdlist);
3170 add_com ("disconnect", class_run, disconnect_command, _("\
3171 Disconnect from a target.\n\
3172 The target will wait for another debugger to connect. Not available for\n\
3175 c = add_com ("signal", class_run, signal_command, _("\
3176 Continue program with the specified signal.\n\
3177 Usage: signal SIGNAL\n\
3178 The SIGNAL argument is processed the same as the handle command.\n\
3180 An argument of \"0\" means continue the program without sending it a signal.\n\
3181 This is useful in cases where the program stopped because of a signal,\n\
3182 and you want to resume the program while discarding the signal.\n\
3184 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3185 the current thread only."));
3186 set_cmd_completer (c, signal_completer);
3188 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3189 Queue a signal to be delivered to the current thread when it is resumed.\n\
3190 Usage: queue-signal SIGNAL\n\
3191 The SIGNAL argument is processed the same as the handle command.\n\
3192 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3194 An argument of \"0\" means remove any currently queued signal from\n\
3195 the current thread. This is useful in cases where the program stopped\n\
3196 because of a signal, and you want to resume it while discarding the signal.\n\
3198 In a multi-threaded program the signal is queued with, or discarded from,\n\
3199 the current thread only."));
3200 set_cmd_completer (c, signal_completer);
3202 add_com ("stepi", class_run, stepi_command, _("\
3203 Step one instruction exactly.\n\
3205 Argument N means step N times (or till program stops for another \
3207 add_com_alias ("si", "stepi", class_alias, 0);
3209 add_com ("nexti", class_run, nexti_command, _("\
3210 Step one instruction, but proceed through subroutine calls.\n\
3212 Argument N means step N times (or till program stops for another \
3214 add_com_alias ("ni", "nexti", class_alias, 0);
3216 add_com ("finish", class_run, finish_command, _("\
3217 Execute until selected stack frame returns.\n\
3219 Upon return, the value returned is printed and put in the value history."));
3220 add_com_alias ("fin", "finish", class_run, 1);
3222 add_com ("next", class_run, next_command, _("\
3223 Step program, proceeding through subroutine calls.\n\
3225 Unlike \"step\", if the current source line calls a subroutine,\n\
3226 this command does not enter the subroutine, but instead steps over\n\
3227 the call, in effect treating it as a single source line."));
3228 add_com_alias ("n", "next", class_run, 1);
3230 add_com ("step", class_run, step_command, _("\
3231 Step program until it reaches a different source line.\n\
3233 Argument N means step N times (or till program stops for another \
3235 add_com_alias ("s", "step", class_run, 1);
3237 c = add_com ("until", class_run, until_command, _("\
3238 Execute until the program reaches a source line greater than the current\n\
3239 or a specified location (same args as break command) within the current \
3241 set_cmd_completer (c, location_completer);
3242 add_com_alias ("u", "until", class_run, 1);
3244 c = add_com ("advance", class_run, advance_command, _("\
3245 Continue the program up to the given location (same form as args for break \
3247 Execution will also stop upon exit from the current stack frame."));
3248 set_cmd_completer (c, location_completer);
3250 c = add_com ("jump", class_run, jump_command, _("\
3251 Continue program being debugged at specified line or address.\n\
3252 Usage: jump <location>\n\
3253 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3254 for an address to start at."));
3255 set_cmd_completer (c, location_completer);
3256 add_com_alias ("j", "jump", class_run, 1);
3258 add_com ("continue", class_run, continue_command, _("\
3259 Continue program being debugged, after signal or breakpoint.\n\
3260 Usage: continue [N]\n\
3261 If proceeding from breakpoint, a number N may be used as an argument,\n\
3262 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3263 the breakpoint won't break until the Nth time it is reached).\n\
3265 If non-stop mode is enabled, continue only the current thread,\n\
3266 otherwise all the threads in the program are continued. To \n\
3267 continue all stopped threads in non-stop mode, use the -a option.\n\
3268 Specifying -a and an ignore count simultaneously is an error."));
3269 add_com_alias ("c", "cont", class_run, 1);
3270 add_com_alias ("fg", "cont", class_run, 1);
3272 c = add_com ("run", class_run, run_command, _("\
3273 Start debugged program. You may specify arguments to give it.\n\
3274 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3275 Input and output redirection with \">\", \"<\", or \">>\" are also \
3277 With no arguments, uses arguments last specified (with \"run\" \
3278 or \"set args\").\n\
3279 To cancel previous arguments and run with no arguments,\n\
3280 use \"set args\" without arguments."));
3281 set_cmd_completer (c, filename_completer);
3282 add_com_alias ("r", "run", class_run, 1);
3284 c = add_com ("start", class_run, start_command, _("\
3285 Run the debugged program until the beginning of the main procedure.\n\
3286 You may specify arguments to give to your program, just as with the\n\
3287 \"run\" command."));
3288 set_cmd_completer (c, filename_completer);
3290 add_com ("interrupt", class_run, interrupt_command,
3291 _("Interrupt the execution of the debugged program.\n\
3292 If non-stop mode is enabled, interrupt only the current thread,\n\
3293 otherwise all the threads in the program are stopped. To \n\
3294 interrupt all running threads in non-stop mode, use the -a option."));
3296 c = add_info ("registers", nofp_registers_info, _("\
3297 List of integer registers and their contents, for selected stack frame.\n\
3298 Register name as argument means describe only that register."));
3299 add_info_alias ("r", "registers", 1);
3300 set_cmd_completer (c, reg_or_group_completer);
3302 c = add_info ("all-registers", all_registers_info, _("\
3303 List of all registers and their contents, for selected stack frame.\n\
3304 Register name as argument means describe only that register."));
3305 set_cmd_completer (c, reg_or_group_completer);
3307 add_info ("program", program_info,
3308 _("Execution status of the program."));
3310 add_info ("float", float_info,
3311 _("Print the status of the floating point unit\n"));
3313 add_info ("vector", vector_info,
3314 _("Print the status of the vector unit\n"));
3316 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3318 Show /proc process information about any running process.\n\
3319 Specify any process id, or use the program being debugged by default."),
3320 &info_proc_cmdlist, "info proc ",
3321 1/*allow-unknown*/, &infolist);
3323 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3324 List of mapped memory regions."),
3325 &info_proc_cmdlist);
3327 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3328 List process info from /proc/PID/stat."),
3329 &info_proc_cmdlist);
3331 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3332 List process info from /proc/PID/status."),
3333 &info_proc_cmdlist);
3335 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3336 List current working directory of the process."),
3337 &info_proc_cmdlist);
3339 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3340 List command line arguments of the process."),
3341 &info_proc_cmdlist);
3343 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3344 List absolute filename for executable of the process."),
3345 &info_proc_cmdlist);
3347 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3348 List all available /proc info."),
3349 &info_proc_cmdlist);