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"
59 /* Local functions: */
61 static void nofp_registers_info (char *, int);
63 static void until_next_command (int);
65 static void until_command (char *, int);
67 static void path_info (char *, int);
69 static void path_command (char *, int);
71 static void unset_command (char *, int);
73 static void float_info (char *, int);
75 static void disconnect_command (char *, int);
77 static void unset_environment_command (char *, int);
79 static void set_environment_command (char *, int);
81 static void environment_info (char *, int);
83 static void program_info (char *, int);
85 static void finish_command (char *, int);
87 static void signal_command (char *, int);
89 static void jump_command (char *, int);
91 static void step_1 (int, int, char *);
92 static void step_once (int skip_subroutines, int single_inst,
93 int count, int thread);
95 static void next_command (char *, int);
97 static void step_command (char *, int);
99 static void run_command (char *, int);
101 void _initialize_infcmd (void);
103 #define ERROR_NO_INFERIOR \
104 if (!target_has_execution) error (_("The program is not being run."));
106 /* Scratch area where string containing arguments to give to the
107 program will be stored by 'set args'. As soon as anything is
108 stored, notice_args_set will move it into per-inferior storage.
109 Arguments are separated by spaces. Empty string (pointer to '\0')
112 static char *inferior_args_scratch;
114 /* Scratch area where 'set inferior-tty' will store user-provided value.
115 We'll immediate copy it into per-inferior storage. */
117 static char *inferior_io_terminal_scratch;
119 /* Pid of our debugged inferior, or 0 if no inferior now.
120 Since various parts of infrun.c test this to see whether there is a program
121 being debugged it should be nonzero (currently 3 is used) for remote
124 ptid_t inferior_ptid;
126 /* Address at which inferior stopped. */
130 /* Nonzero if stopped due to completion of a stack dummy routine. */
132 enum stop_stack_kind stop_stack_dummy;
134 /* Nonzero if stopped due to a random (unexpected) signal in inferior
137 int stopped_by_random_signal;
139 /* See inferior.h. */
141 int startup_with_shell = 1;
144 /* Accessor routines. */
146 /* Set the io terminal for the current inferior. Ownership of
147 TERMINAL_NAME is not transferred. */
150 set_inferior_io_terminal (const char *terminal_name)
152 xfree (current_inferior ()->terminal);
153 current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
157 get_inferior_io_terminal (void)
159 return current_inferior ()->terminal;
163 set_inferior_tty_command (char *args, int from_tty,
164 struct cmd_list_element *c)
166 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
167 Now route it to current inferior. */
168 set_inferior_io_terminal (inferior_io_terminal_scratch);
172 show_inferior_tty_command (struct ui_file *file, int from_tty,
173 struct cmd_list_element *c, const char *value)
175 /* Note that we ignore the passed-in value in favor of computing it
177 const char *inferior_io_terminal = get_inferior_io_terminal ();
179 if (inferior_io_terminal == NULL)
180 inferior_io_terminal = "";
181 fprintf_filtered (gdb_stdout,
182 _("Terminal for future runs of program being debugged "
183 "is \"%s\".\n"), inferior_io_terminal);
187 get_inferior_args (void)
189 if (current_inferior ()->argc != 0)
193 n = construct_inferior_arguments (current_inferior ()->argc,
194 current_inferior ()->argv);
195 set_inferior_args (n);
199 if (current_inferior ()->args == NULL)
200 current_inferior ()->args = xstrdup ("");
202 return current_inferior ()->args;
205 /* Set the arguments for the current inferior. Ownership of
206 NEWARGS is not transferred. */
209 set_inferior_args (char *newargs)
211 xfree (current_inferior ()->args);
212 current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
213 current_inferior ()->argc = 0;
214 current_inferior ()->argv = 0;
218 set_inferior_args_vector (int argc, char **argv)
220 current_inferior ()->argc = argc;
221 current_inferior ()->argv = argv;
224 /* Notice when `set args' is run. */
227 set_args_command (char *args, int from_tty, struct cmd_list_element *c)
229 /* CLI has assigned the user-provided value to inferior_args_scratch.
230 Now route it to current inferior. */
231 set_inferior_args (inferior_args_scratch);
234 /* Notice when `show args' is run. */
237 show_args_command (struct ui_file *file, int from_tty,
238 struct cmd_list_element *c, const char *value)
240 /* Note that we ignore the passed-in value in favor of computing it
242 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
246 /* Compute command-line string given argument vector. This does the
247 same shell processing as fork_inferior. */
250 construct_inferior_arguments (int argc, char **argv)
254 if (startup_with_shell)
257 /* This holds all the characters considered special to the
259 char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
260 const char quote = '"';
262 /* This holds all the characters considered special to the
263 typical Unix shells. We include `^' because the SunOS
264 /bin/sh treats it as a synonym for `|'. */
265 char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
266 const char quote = '\'';
272 /* We over-compute the size. It shouldn't matter. */
273 for (i = 0; i < argc; ++i)
274 length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
276 result = (char *) xmalloc (length);
279 for (i = 0; i < argc; ++i)
284 /* Need to handle empty arguments specially. */
285 if (argv[i][0] == '\0')
295 if (strpbrk (argv[i], special))
301 for (cp = argv[i]; *cp; ++cp)
305 /* A newline cannot be quoted with a backslash (it
306 just disappears), only by putting it inside
317 if (strchr (special, *cp) != NULL)
333 /* In this case we can't handle arguments that contain spaces,
334 tabs, or newlines -- see breakup_args(). */
338 for (i = 0; i < argc; ++i)
340 char *cp = strchr (argv[i], ' ');
342 cp = strchr (argv[i], '\t');
344 cp = strchr (argv[i], '\n');
346 error (_("can't handle command-line "
347 "argument containing whitespace"));
348 length += strlen (argv[i]) + 1;
351 result = (char *) xmalloc (length);
353 for (i = 0; i < argc; ++i)
356 strcat (result, " ");
357 strcat (result, argv[i]);
365 /* This function strips the '&' character (indicating background
366 execution) that is added as *the last* of the arguments ARGS of a
367 command. A copy of the incoming ARGS without the '&' is returned,
368 unless the resulting string after stripping is empty, in which case
369 NULL is returned. *BG_CHAR_P is an output boolean that indicates
370 whether the '&' character was found. */
373 strip_bg_char (const char *args, int *bg_char_p)
377 if (args == NULL || *args == '\0')
383 p = args + strlen (args);
387 while (p > args && isspace (p[-1]))
392 return savestring (args, p - args);
398 return xstrdup (args);
401 /* Common actions to take after creating any sort of inferior, by any
402 means (running, attaching, connecting, et cetera). The target
403 should be stopped. */
406 post_create_inferior (struct target_ops *target, int from_tty)
409 /* Be sure we own the terminal in case write operations are performed. */
410 target_terminal_ours ();
412 /* If the target hasn't taken care of this already, do it now.
413 Targets which need to access registers during to_open,
414 to_create_inferior, or to_attach should do it earlier; but many
416 target_find_description ();
418 /* Now that we know the register layout, retrieve current PC. But
419 if the PC is unavailable (e.g., we're opening a core file with
420 missing registers info), ignore it. */
424 stop_pc = regcache_read_pc (get_current_regcache ());
426 CATCH (ex, RETURN_MASK_ERROR)
428 if (ex.error != NOT_AVAILABLE_ERROR)
429 throw_exception (ex);
435 const unsigned solib_add_generation
436 = current_program_space->solib_add_generation;
438 /* Create the hooks to handle shared library load and unload
440 solib_create_inferior_hook (from_tty);
442 if (current_program_space->solib_add_generation == solib_add_generation)
444 /* The platform-specific hook should load initial shared libraries,
445 but didn't. FROM_TTY will be incorrectly 0 but such solib
446 targets should be fixed anyway. Call it only after the solib
447 target has been initialized by solib_create_inferior_hook. */
450 warning (_("platform-specific solib_create_inferior_hook did "
451 "not load initial shared libraries."));
453 /* If the solist is global across processes, there's no need to
455 if (!gdbarch_has_global_solist (target_gdbarch ()))
456 solib_add (NULL, 0, target, auto_solib_add);
460 /* If the user sets watchpoints before execution having started,
461 then she gets software watchpoints, because GDB can't know which
462 target will end up being pushed, or if it supports hardware
463 watchpoints or not. breakpoint_re_set takes care of promoting
464 watchpoints to hardware watchpoints if possible, however, if this
465 new inferior doesn't load shared libraries or we don't pull in
466 symbols from any other source on this target/arch,
467 breakpoint_re_set is never called. Call it now so that software
468 watchpoints get a chance to be promoted to hardware watchpoints
469 if the now pushed target supports hardware watchpoints. */
470 breakpoint_re_set ();
472 observer_notify_inferior_created (target, from_tty);
475 /* Kill the inferior if already running. This function is designed
476 to be called when we are about to start the execution of the program
477 from the beginning. Ask the user to confirm that he wants to restart
478 the program being debugged when FROM_TTY is non-null. */
481 kill_if_already_running (int from_tty)
483 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
485 /* Bail out before killing the program if we will not be able to
487 target_require_runnable ();
490 && !query (_("The program being debugged has been started already.\n\
491 Start it from the beginning? ")))
492 error (_("Program not restarted."));
497 /* See inferior.h. */
500 prepare_execution_command (struct target_ops *target, int background)
502 /* If we get a request for running in the bg but the target
503 doesn't support it, error out. */
504 if (background && !target->to_can_async_p (target))
505 error (_("Asynchronous execution not supported on this target."));
507 /* If we don't get a request of running in the bg, then we need
508 to simulate synchronous (fg) execution. */
509 if (!background && target->to_can_async_p (target))
511 /* Simulate synchronous execution. Note no cleanup is necessary
512 for this. stdin is re-enabled whenever an error reaches the
514 async_disable_stdin ();
518 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
519 a temporary breakpoint at the begining of the main program before
520 running the program. */
523 run_command_1 (char *args, int from_tty, int tbreak_at_main)
526 struct cleanup *old_chain;
528 struct ui_out *uiout = current_uiout;
529 struct target_ops *run_target;
531 struct cleanup *args_chain;
535 kill_if_already_running (from_tty);
537 init_wait_for_inferior ();
538 clear_breakpoint_hit_counts ();
540 /* Clean up any leftovers from other runs. Some other things from
541 this function should probably be moved into target_pre_inferior. */
542 target_pre_inferior (from_tty);
544 /* The comment here used to read, "The exec file is re-read every
545 time we do a generic_mourn_inferior, so we just have to worry
546 about the symbol file." The `generic_mourn_inferior' function
547 gets called whenever the program exits. However, suppose the
548 program exits, and *then* the executable file changes? We need
549 to check again here. Since reopen_exec_file doesn't do anything
550 if the timestamp hasn't changed, I don't see the harm. */
554 args = strip_bg_char (args, &async_exec);
555 args_chain = make_cleanup (xfree, args);
557 /* Do validation and preparation before possibly changing anything
560 run_target = find_run_target ();
562 prepare_execution_command (run_target, async_exec);
564 if (non_stop && !run_target->to_supports_non_stop (run_target))
565 error (_("The target does not support running in non-stop mode."));
567 /* Done. Can now set breakpoints, change inferior args, etc. */
569 /* Insert the temporary breakpoint if a location was specified. */
571 tbreak_command (main_name (), 0);
573 exec_file = (char *) get_exec_file (0);
575 /* We keep symbols from add-symbol-file, on the grounds that the
576 user might want to add some symbols before running the program
577 (right?). But sometimes (dynamic loading where the user manually
578 introduces the new symbols with add-symbol-file), the code which
579 the symbols describe does not persist between runs. Currently
580 the user has to manually nuke all symbols between runs if they
581 want them to go away (PR 2207). This is probably reasonable. */
583 /* If there were other args, beside '&', process them. */
585 set_inferior_args (args);
589 ui_out_field_string (uiout, NULL, "Starting program");
590 ui_out_text (uiout, ": ");
592 ui_out_field_string (uiout, "execfile", exec_file);
593 ui_out_spaces (uiout, 1);
594 /* We call get_inferior_args() because we might need to compute
596 ui_out_field_string (uiout, "infargs", get_inferior_args ());
597 ui_out_text (uiout, "\n");
598 ui_out_flush (uiout);
601 /* Done with ARGS. */
602 do_cleanups (args_chain);
604 /* We call get_inferior_args() because we might need to compute
606 run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
607 environ_vector (current_inferior ()->environment),
609 /* to_create_inferior should push the target, so after this point we
610 shouldn't refer to run_target again. */
613 /* We're starting off a new process. When we get out of here, in
614 non-stop mode, finish the state of all threads of that process,
615 but leave other threads alone, as they may be stopped in internal
616 events --- the frontend shouldn't see them as stopped. In
617 all-stop, always finish the state of all threads, as we may be
618 resuming more than just the new process. */
620 ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
622 ptid = minus_one_ptid;
623 old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
625 /* Pass zero for FROM_TTY, because at this point the "run" command
626 has done its thing; now we are setting up the running program. */
627 post_create_inferior (¤t_target, 0);
629 /* Start the target running. Do not use -1 continuation as it would skip
630 breakpoint right at the entry point. */
631 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
633 /* Since there was no error, there's no need to finish the thread
635 discard_cleanups (old_chain);
639 run_command (char *args, int from_tty)
641 run_command_1 (args, from_tty, 0);
644 /* Start the execution of the program up until the beginning of the main
648 start_command (char *args, int from_tty)
650 /* Some languages such as Ada need to search inside the program
651 minimal symbols for the location where to put the temporary
652 breakpoint before starting. */
653 if (!have_minimal_symbols ())
654 error (_("No symbol table loaded. Use the \"file\" command."));
656 /* Run the program until reaching the main procedure... */
657 run_command_1 (args, from_tty, 1);
661 proceed_thread_callback (struct thread_info *thread, void *arg)
663 /* We go through all threads individually instead of compressing
664 into a single target `resume_all' request, because some threads
665 may be stopped in internal breakpoints/events, or stopped waiting
666 for its turn in the displaced stepping queue (that is, they are
667 running && !executing). The target side has no idea about why
668 the thread is stopped, so a `resume_all' command would resume too
669 much. If/when GDB gains a way to tell the target `hold this
670 thread stopped until I say otherwise', then we can optimize
672 if (!is_stopped (thread->ptid))
675 switch_to_thread (thread->ptid);
676 clear_proceed_status (0);
677 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
682 ensure_valid_thread (void)
684 if (ptid_equal (inferior_ptid, null_ptid)
685 || is_exited (inferior_ptid))
686 error (_("Cannot execute this command without a live selected thread."));
689 /* If the user is looking at trace frames, any resumption of execution
690 is likely to mix up recorded and live target data. So simply
691 disallow those commands. */
694 ensure_not_tfind_mode (void)
696 if (get_traceframe_number () >= 0)
697 error (_("Cannot execute this command while looking at trace frames."));
700 /* Throw an error indicating the current thread is running. */
703 error_is_running (void)
705 error (_("Cannot execute this command while "
706 "the selected thread is running."));
709 /* Calls error_is_running if the current thread is running. */
712 ensure_not_running (void)
714 if (is_running (inferior_ptid))
719 continue_1 (int all_threads)
722 ensure_not_tfind_mode ();
724 if (non_stop && all_threads)
726 /* Don't error out if the current thread is running, because
727 there may be other stopped threads. */
728 struct cleanup *old_chain;
730 /* Backup current thread and selected frame. */
731 old_chain = make_cleanup_restore_current_thread ();
733 iterate_over_threads (proceed_thread_callback, NULL);
737 /* If all threads in the target were already running,
738 proceed_thread_callback ends up never calling proceed,
739 and so nothing calls this to put the inferior's terminal
740 settings in effect and remove stdin from the event loop,
741 which we must when running a foreground command. E.g.:
745 <all threads are running now>
748 <no thread was resumed, but the inferior now owns the terminal>
750 target_terminal_inferior ();
753 /* Restore selected ptid. */
754 do_cleanups (old_chain);
758 ensure_valid_thread ();
759 ensure_not_running ();
760 clear_proceed_status (0);
761 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
765 /* continue [-a] [proceed-count] [&] */
768 continue_command (char *args, int from_tty)
772 struct cleanup *args_chain;
776 /* Find out whether we must run in the background. */
777 args = strip_bg_char (args, &async_exec);
778 args_chain = make_cleanup (xfree, args);
780 prepare_execution_command (¤t_target, async_exec);
784 if (startswith (args, "-a"))
787 args += sizeof ("-a") - 1;
793 if (!non_stop && all_threads)
794 error (_("`-a' is meaningless in all-stop mode."));
796 if (args != NULL && all_threads)
797 error (_("Can't resume all threads and specify "
798 "proceed count simultaneously."));
800 /* If we have an argument left, set proceed count of breakpoint we
807 struct thread_info *tp;
810 tp = find_thread_ptid (inferior_ptid);
814 struct target_waitstatus ws;
816 get_last_target_status (&last_ptid, &ws);
817 tp = find_thread_ptid (last_ptid);
820 bs = tp->control.stop_bpstat;
822 while ((stat = bpstat_num (&bs, &num)) != 0)
825 set_ignore_count (num,
826 parse_and_eval_long (args) - 1,
828 /* set_ignore_count prints a message ending with a period.
829 So print two spaces before "Continuing.". */
831 printf_filtered (" ");
835 if (!stopped && from_tty)
838 ("Not stopped at any breakpoint; argument ignored.\n");
842 /* Done with ARGS. */
843 do_cleanups (args_chain);
846 printf_filtered (_("Continuing.\n"));
848 continue_1 (all_threads);
851 /* Record the starting point of a "step" or "next" command. */
854 set_step_frame (void)
856 struct symtab_and_line sal;
858 struct frame_info *frame = get_current_frame ();
859 struct thread_info *tp = inferior_thread ();
861 find_frame_sal (frame, &sal);
862 set_step_info (frame, sal);
863 pc = get_frame_pc (frame);
864 tp->control.step_start_function = find_pc_function (pc);
867 /* Step until outside of current statement. */
870 step_command (char *count_string, int from_tty)
872 step_1 (0, 0, count_string);
875 /* Likewise, but skip over subroutine calls as if single instructions. */
878 next_command (char *count_string, int from_tty)
880 step_1 (1, 0, count_string);
883 /* Likewise, but step only one instruction. */
886 stepi_command (char *count_string, int from_tty)
888 step_1 (0, 1, count_string);
892 nexti_command (char *count_string, int from_tty)
894 step_1 (1, 1, count_string);
898 delete_longjmp_breakpoint_cleanup (void *arg)
900 int thread = * (int *) arg;
901 delete_longjmp_breakpoint (thread);
905 step_1 (int skip_subroutines, int single_inst, char *count_string)
908 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
911 struct cleanup *args_chain;
914 ensure_not_tfind_mode ();
915 ensure_valid_thread ();
916 ensure_not_running ();
918 count_string = strip_bg_char (count_string, &async_exec);
919 args_chain = make_cleanup (xfree, count_string);
921 prepare_execution_command (¤t_target, async_exec);
923 count = count_string ? parse_and_eval_long (count_string) : 1;
925 /* Done with ARGS. */
926 do_cleanups (args_chain);
928 if (!single_inst || skip_subroutines) /* Leave si command alone. */
930 struct thread_info *tp = inferior_thread ();
932 if (in_thread_list (inferior_ptid))
933 thread = pid_to_thread_id (inferior_ptid);
935 set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));
937 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
940 /* In synchronous case, all is well; each step_once call will step once. */
941 if (!target_can_async_p ())
943 for (; count > 0; count--)
945 step_once (skip_subroutines, single_inst, count, thread);
947 if (!target_has_execution)
951 struct thread_info *tp = inferior_thread ();
953 if (!tp->control.stop_step || !tp->step_multi)
955 /* If we stopped for some reason that is not stepping
956 there are no further steps to make. */
963 do_cleanups (cleanups);
967 /* In the case of an asynchronous target things get complicated;
968 do only one step for now, before returning control to the
969 event loop. Let the continuation figure out how many other
970 steps we need to do, and handle them one at the time, through
972 step_once (skip_subroutines, single_inst, count, thread);
974 /* We are running, and the continuation is installed. It will
975 disable the longjmp breakpoint as appropriate. */
976 discard_cleanups (cleanups);
980 struct step_1_continuation_args
983 int skip_subroutines;
988 /* Called after we are done with one step operation, to check whether
989 we need to step again, before we print the prompt and return control
990 to the user. If count is > 1, we will need to do one more call to
991 proceed(), via step_once(). Basically it is like step_once and
992 step_1_continuation are co-recursive. */
995 step_1_continuation (void *args, int err)
997 struct step_1_continuation_args *a = args;
999 if (target_has_execution)
1001 struct thread_info *tp;
1003 tp = inferior_thread ();
1005 && tp->step_multi && tp->control.stop_step)
1007 /* There are more steps to make, and we did stop due to
1008 ending a stepping range. Do another step. */
1009 step_once (a->skip_subroutines, a->single_inst,
1010 a->count - 1, a->thread);
1016 /* We either hit an error, or stopped for some reason that is
1017 not stepping, or there are no further steps to make.
1019 if (!a->single_inst || a->skip_subroutines)
1020 delete_longjmp_breakpoint (a->thread);
1023 /* Do just one step operation. This is useful to implement the 'step
1024 n' kind of commands. In case of asynchronous targets, we will have
1025 to set up a continuation to be done after the target stops (after
1026 this one step). For synch targets, the caller handles further
1030 step_once (int skip_subroutines, int single_inst, int count, int thread)
1032 struct frame_info *frame = get_current_frame ();
1036 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1037 the longjmp breakpoint was not required. Use the
1038 INFERIOR_PTID thread instead, which is the same thread when
1040 struct thread_info *tp = inferior_thread ();
1042 clear_proceed_status (1);
1049 /* Step at an inlined function behaves like "down". */
1050 if (!skip_subroutines
1051 && inline_skipped_frames (inferior_ptid))
1055 /* Pretend that we've ran. */
1056 resume_ptid = user_visible_resume_ptid (1);
1057 set_running (resume_ptid, 1);
1059 step_into_inline_frame (inferior_ptid);
1061 step_once (skip_subroutines, single_inst, count - 1, thread);
1064 /* Pretend that we've stopped. */
1067 if (target_can_async_p ())
1068 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1073 pc = get_frame_pc (frame);
1074 find_pc_line_pc_range (pc,
1075 &tp->control.step_range_start,
1076 &tp->control.step_range_end);
1078 tp->control.may_range_step = 1;
1080 /* If we have no line info, switch to stepi mode. */
1081 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
1083 tp->control.step_range_start = tp->control.step_range_end = 1;
1084 tp->control.may_range_step = 0;
1086 else if (tp->control.step_range_end == 0)
1090 if (find_pc_partial_function (pc, &name,
1091 &tp->control.step_range_start,
1092 &tp->control.step_range_end) == 0)
1093 error (_("Cannot find bounds of current function"));
1095 target_terminal_ours ();
1096 printf_filtered (_("Single stepping until exit from function %s,"
1097 "\nwhich has no line number information.\n"),
1103 /* Say we are stepping, but stop after one insn whatever it does. */
1104 tp->control.step_range_start = tp->control.step_range_end = 1;
1105 if (!skip_subroutines)
1107 Don't step over function calls, not even to functions lacking
1109 tp->control.step_over_calls = STEP_OVER_NONE;
1112 if (skip_subroutines)
1113 tp->control.step_over_calls = STEP_OVER_ALL;
1115 tp->step_multi = (count > 1);
1116 tp->control.stepping_command = 1;
1117 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1119 /* For async targets, register a continuation to do any
1120 additional steps. For sync targets, the caller will handle
1121 further stepping. */
1122 if (target_can_async_p ())
1124 struct step_1_continuation_args *args;
1126 args = xmalloc (sizeof (*args));
1127 args->skip_subroutines = skip_subroutines;
1128 args->single_inst = single_inst;
1129 args->count = count;
1130 args->thread = thread;
1132 add_intermediate_continuation (tp, step_1_continuation, args, xfree);
1138 /* Continue program at specified address. */
1141 jump_command (char *arg, int from_tty)
1143 struct gdbarch *gdbarch = get_current_arch ();
1145 struct symtabs_and_lines sals;
1146 struct symtab_and_line sal;
1150 struct cleanup *args_chain;
1153 ensure_not_tfind_mode ();
1154 ensure_valid_thread ();
1155 ensure_not_running ();
1157 /* Find out whether we must run in the background. */
1158 arg = strip_bg_char (arg, &async_exec);
1159 args_chain = make_cleanup (xfree, arg);
1161 prepare_execution_command (¤t_target, async_exec);
1164 error_no_arg (_("starting address"));
1166 sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1167 if (sals.nelts != 1)
1169 error (_("Unreasonable jump request"));
1175 /* Done with ARGS. */
1176 do_cleanups (args_chain);
1178 if (sal.symtab == 0 && sal.pc == 0)
1179 error (_("No source file has been specified."));
1181 resolve_sal_pc (&sal); /* May error out. */
1183 /* See if we are trying to jump to another function. */
1184 fn = get_frame_function (get_current_frame ());
1185 sfn = find_pc_function (sal.pc);
1186 if (fn != NULL && sfn != fn)
1188 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
1189 SYMBOL_PRINT_NAME (fn)))
1191 error (_("Not confirmed."));
1198 struct obj_section *section;
1200 fixup_symbol_section (sfn, 0);
1201 section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
1202 if (section_is_overlay (section)
1203 && !section_is_mapped (section))
1205 if (!query (_("WARNING!!! Destination is in "
1206 "unmapped overlay! Jump anyway? ")))
1208 error (_("Not confirmed."));
1218 printf_filtered (_("Continuing at "));
1219 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1220 printf_filtered (".\n");
1223 clear_proceed_status (0);
1224 proceed (addr, GDB_SIGNAL_0);
1227 /* Continue program giving it specified signal. */
1230 signal_command (char *signum_exp, int from_tty)
1232 enum gdb_signal oursig;
1234 struct cleanup *args_chain;
1236 dont_repeat (); /* Too dangerous. */
1238 ensure_not_tfind_mode ();
1239 ensure_valid_thread ();
1240 ensure_not_running ();
1242 /* Find out whether we must run in the background. */
1243 signum_exp = strip_bg_char (signum_exp, &async_exec);
1244 args_chain = make_cleanup (xfree, signum_exp);
1246 prepare_execution_command (¤t_target, async_exec);
1249 error_no_arg (_("signal number"));
1251 /* It would be even slicker to make signal names be valid expressions,
1252 (the type could be "enum $signal" or some such), then the user could
1253 assign them to convenience variables. */
1254 oursig = gdb_signal_from_name (signum_exp);
1256 if (oursig == GDB_SIGNAL_UNKNOWN)
1258 /* No, try numeric. */
1259 int num = parse_and_eval_long (signum_exp);
1262 oursig = GDB_SIGNAL_0;
1264 oursig = gdb_signal_from_command (num);
1267 /* Look for threads other than the current that this command ends up
1268 resuming too (due to schedlock off), and warn if they'll get a
1269 signal delivered. "signal 0" is used to suppress a previous
1270 signal, but if the current thread is no longer the one that got
1271 the signal, then the user is potentially suppressing the signal
1272 of the wrong thread. */
1275 struct thread_info *tp;
1277 int must_confirm = 0;
1279 /* This indicates what will be resumed. Either a single thread,
1280 a whole process, or all threads of all processes. */
1281 resume_ptid = user_visible_resume_ptid (0);
1283 ALL_NON_EXITED_THREADS (tp)
1285 if (ptid_equal (tp->ptid, inferior_ptid))
1287 if (!ptid_match (tp->ptid, resume_ptid))
1290 if (tp->suspend.stop_signal != GDB_SIGNAL_0
1291 && signal_pass_state (tp->suspend.stop_signal))
1294 printf_unfiltered (_("Note:\n"));
1295 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1297 gdb_signal_to_name (tp->suspend.stop_signal),
1298 gdb_signal_to_string (tp->suspend.stop_signal));
1304 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1305 "still deliver the signals noted above to their respective threads.\n"
1306 "Continue anyway? "),
1307 inferior_thread ()->num))
1308 error (_("Not confirmed."));
1313 if (oursig == GDB_SIGNAL_0)
1314 printf_filtered (_("Continuing with no signal.\n"));
1316 printf_filtered (_("Continuing with signal %s.\n"),
1317 gdb_signal_to_name (oursig));
1320 clear_proceed_status (0);
1321 proceed ((CORE_ADDR) -1, oursig);
1324 /* Queue a signal to be delivered to the current thread. */
1327 queue_signal_command (char *signum_exp, int from_tty)
1329 enum gdb_signal oursig;
1330 struct thread_info *tp;
1333 ensure_not_tfind_mode ();
1334 ensure_valid_thread ();
1335 ensure_not_running ();
1337 if (signum_exp == NULL)
1338 error_no_arg (_("signal number"));
1340 /* It would be even slicker to make signal names be valid expressions,
1341 (the type could be "enum $signal" or some such), then the user could
1342 assign them to convenience variables. */
1343 oursig = gdb_signal_from_name (signum_exp);
1345 if (oursig == GDB_SIGNAL_UNKNOWN)
1347 /* No, try numeric. */
1348 int num = parse_and_eval_long (signum_exp);
1351 oursig = GDB_SIGNAL_0;
1353 oursig = gdb_signal_from_command (num);
1356 if (oursig != GDB_SIGNAL_0
1357 && !signal_pass_state (oursig))
1358 error (_("Signal handling set to not pass this signal to the program."));
1360 tp = inferior_thread ();
1361 tp->suspend.stop_signal = oursig;
1364 /* Continuation args to be passed to the "until" command
1366 struct until_next_continuation_args
1368 /* The thread that was current when the command was executed. */
1372 /* A continuation callback for until_next_command. */
1375 until_next_continuation (void *arg, int err)
1377 struct until_next_continuation_args *a = arg;
1379 delete_longjmp_breakpoint (a->thread);
1382 /* Proceed until we reach a different source line with pc greater than
1383 our current one or exit the function. We skip calls in both cases.
1385 Note that eventually this command should probably be changed so
1386 that only source lines are printed out when we hit the breakpoint
1387 we set. This may involve changes to wait_for_inferior and the
1388 proceed status code. */
1391 until_next_command (int from_tty)
1393 struct frame_info *frame;
1395 struct symbol *func;
1396 struct symtab_and_line sal;
1397 struct thread_info *tp = inferior_thread ();
1398 int thread = tp->num;
1399 struct cleanup *old_chain;
1401 clear_proceed_status (0);
1404 frame = get_current_frame ();
1406 /* Step until either exited from this function or greater
1407 than the current line (if in symbolic section) or pc (if
1410 pc = get_frame_pc (frame);
1411 func = find_pc_function (pc);
1415 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
1417 if (msymbol.minsym == NULL)
1418 error (_("Execution is not within a known function."));
1420 tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
1421 /* The upper-bound of step_range is exclusive. In order to make PC
1422 within the range, set the step_range_end with PC + 1. */
1423 tp->control.step_range_end = pc + 1;
1427 sal = find_pc_line (pc, 0);
1429 tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1430 tp->control.step_range_end = sal.end;
1432 tp->control.may_range_step = 1;
1434 tp->control.step_over_calls = STEP_OVER_ALL;
1436 tp->step_multi = 0; /* Only one call to proceed */
1438 set_longjmp_breakpoint (tp, get_frame_id (frame));
1439 old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1441 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1443 if (target_can_async_p () && is_running (inferior_ptid))
1445 struct until_next_continuation_args *cont_args;
1447 discard_cleanups (old_chain);
1448 cont_args = XNEW (struct until_next_continuation_args);
1449 cont_args->thread = inferior_thread ()->num;
1451 add_continuation (tp, until_next_continuation, cont_args, xfree);
1454 do_cleanups (old_chain);
1458 until_command (char *arg, int from_tty)
1461 struct cleanup *args_chain;
1464 ensure_not_tfind_mode ();
1465 ensure_valid_thread ();
1466 ensure_not_running ();
1468 /* Find out whether we must run in the background. */
1469 arg = strip_bg_char (arg, &async_exec);
1470 args_chain = make_cleanup (xfree, arg);
1472 prepare_execution_command (¤t_target, async_exec);
1475 until_break_command (arg, from_tty, 0);
1477 until_next_command (from_tty);
1479 /* Done with ARGS. */
1480 do_cleanups (args_chain);
1484 advance_command (char *arg, int from_tty)
1487 struct cleanup *args_chain;
1490 ensure_not_tfind_mode ();
1491 ensure_valid_thread ();
1492 ensure_not_running ();
1495 error_no_arg (_("a location"));
1497 /* Find out whether we must run in the background. */
1498 arg = strip_bg_char (arg, &async_exec);
1499 args_chain = make_cleanup (xfree, arg);
1501 prepare_execution_command (¤t_target, async_exec);
1503 until_break_command (arg, from_tty, 1);
1505 /* Done with ARGS. */
1506 do_cleanups (args_chain);
1509 /* Return the value of the result of a function at the end of a 'finish'
1510 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1511 right after an inferior call has finished. */
1514 get_return_value (struct value *function, struct type *value_type,
1515 struct dummy_frame_context_saver *ctx_saver)
1517 struct regcache *stop_regs = NULL;
1518 struct gdbarch *gdbarch;
1519 struct value *value;
1520 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1522 /* If registers were not saved, use the current registers. */
1523 if (ctx_saver != NULL)
1524 stop_regs = dummy_frame_context_saver_get_regs (ctx_saver);
1527 stop_regs = regcache_dup (get_current_regcache ());
1528 make_cleanup_regcache_xfree (stop_regs);
1531 gdbarch = get_regcache_arch (stop_regs);
1533 value_type = check_typedef (value_type);
1534 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1536 /* FIXME: 2003-09-27: When returning from a nested inferior function
1537 call, it's possible (with no help from the architecture vector)
1538 to locate and return/print a "struct return" value. This is just
1539 a more complicated case of what is already being done in the
1540 inferior function call code. In fact, when inferior function
1541 calls are made async, this will likely be made the norm. */
1543 switch (gdbarch_return_value (gdbarch, function, value_type,
1546 case RETURN_VALUE_REGISTER_CONVENTION:
1547 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1548 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1549 value = allocate_value (value_type);
1550 gdbarch_return_value (gdbarch, function, value_type, stop_regs,
1551 value_contents_raw (value), NULL);
1553 case RETURN_VALUE_STRUCT_CONVENTION:
1557 internal_error (__FILE__, __LINE__, _("bad switch"));
1560 do_cleanups (cleanup);
1565 /* Print the result of a function at the end of a 'finish' command.
1566 DTOR_DATA (if not NULL) can represent inferior registers right after
1567 an inferior call has finished. */
1570 print_return_value (struct value *function, struct type *value_type,
1571 struct dummy_frame_context_saver *ctx_saver)
1573 struct value *value = get_return_value (function, value_type, ctx_saver);
1574 struct ui_out *uiout = current_uiout;
1578 struct value_print_options opts;
1579 struct ui_file *stb;
1580 struct cleanup *old_chain;
1583 stb = mem_fileopen ();
1584 old_chain = make_cleanup_ui_file_delete (stb);
1585 ui_out_text (uiout, "Value returned is ");
1586 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1587 record_latest_value (value));
1588 ui_out_text (uiout, " = ");
1589 get_no_prettyformat_print_options (&opts);
1590 value_print (value, stb, &opts);
1591 ui_out_field_stream (uiout, "return-value", stb);
1592 ui_out_text (uiout, "\n");
1593 do_cleanups (old_chain);
1597 struct cleanup *oldchain;
1600 type_name = type_to_string (value_type);
1601 oldchain = make_cleanup (xfree, type_name);
1602 ui_out_text (uiout, "Value returned has type: ");
1603 ui_out_field_string (uiout, "return-type", type_name);
1604 ui_out_text (uiout, ".");
1605 ui_out_text (uiout, " Cannot determine contents\n");
1606 do_cleanups (oldchain);
1610 /* Stuff that needs to be done by the finish command after the target
1611 has stopped. In asynchronous mode, we wait for the target to stop
1612 in the call to poll or select in the event loop, so it is
1613 impossible to do all the stuff as part of the finish_command
1614 function itself. The only chance we have to complete this command
1615 is in fetch_inferior_event, which is called by the event loop as
1616 soon as it detects that the target has stopped. */
1618 struct finish_command_continuation_args
1620 /* The thread that as current when the command was executed. */
1622 struct breakpoint *breakpoint;
1623 struct symbol *function;
1625 /* Inferior registers stored right before dummy_frame has been freed
1626 after an inferior call. It can be NULL if no inferior call was
1627 involved, GDB will then use current inferior registers. */
1628 struct dummy_frame_context_saver *ctx_saver;
1632 finish_command_continuation (void *arg, int err)
1634 struct finish_command_continuation_args *a = arg;
1638 struct thread_info *tp = NULL;
1641 if (!ptid_equal (inferior_ptid, null_ptid)
1642 && target_has_execution
1643 && is_stopped (inferior_ptid))
1645 tp = inferior_thread ();
1646 bs = tp->control.stop_bpstat;
1649 if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1650 && a->function != NULL)
1652 struct type *value_type;
1654 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1656 internal_error (__FILE__, __LINE__,
1657 _("finish_command: function has no target type"));
1659 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1663 func = read_var_value (a->function, get_current_frame ());
1666 /* print_return_value can throw an exception in some
1667 circumstances. We need to catch this so that we still
1668 delete the breakpoint. */
1669 print_return_value (func, value_type, a->ctx_saver);
1671 CATCH (ex, RETURN_MASK_ALL)
1673 exception_print (gdb_stdout, ex);
1679 /* We suppress normal call of normal_stop observer and do it
1680 here so that the *stopped notification includes the return
1682 if (bs != NULL && tp->control.proceed_to_finish)
1683 observer_notify_normal_stop (bs, 1 /* print frame */);
1686 delete_breakpoint (a->breakpoint);
1687 delete_longjmp_breakpoint (a->thread);
1691 finish_command_continuation_free_arg (void *arg)
1693 struct finish_command_continuation_args *cargs = arg;
1695 if (cargs->ctx_saver != NULL)
1696 dummy_frame_context_saver_drop (cargs->ctx_saver);
1700 /* finish_backward -- helper function for finish_command. */
1703 finish_backward (struct symbol *function)
1705 struct symtab_and_line sal;
1706 struct thread_info *tp = inferior_thread ();
1708 CORE_ADDR func_addr;
1710 pc = get_frame_pc (get_current_frame ());
1712 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1713 error (_("Cannot find bounds of current function"));
1715 sal = find_pc_line (func_addr, 0);
1717 tp->control.proceed_to_finish = 1;
1718 /* Special case: if we're sitting at the function entry point,
1719 then all we need to do is take a reverse singlestep. We
1720 don't need to set a breakpoint, and indeed it would do us
1723 Note that this can only happen at frame #0, since there's
1724 no way that a function up the stack can have a return address
1725 that's equal to its entry point. */
1729 struct frame_info *frame = get_selected_frame (NULL);
1730 struct gdbarch *gdbarch = get_frame_arch (frame);
1731 struct symtab_and_line sr_sal;
1733 /* Set a step-resume at the function's entry point. Once that's
1734 hit, we'll do one more step backwards. */
1737 sr_sal.pspace = get_frame_program_space (frame);
1738 insert_step_resume_breakpoint_at_sal (gdbarch,
1739 sr_sal, null_frame_id);
1741 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1745 /* We're almost there -- we just need to back up by one more
1747 tp->control.step_range_start = tp->control.step_range_end = 1;
1748 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1752 /* finish_forward -- helper function for finish_command. */
1755 finish_forward (struct symbol *function, struct frame_info *frame)
1757 struct frame_id frame_id = get_frame_id (frame);
1758 struct gdbarch *gdbarch = get_frame_arch (frame);
1759 struct symtab_and_line sal;
1760 struct thread_info *tp = inferior_thread ();
1761 struct breakpoint *breakpoint;
1762 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
1763 struct finish_command_continuation_args *cargs;
1764 int thread = tp->num;
1765 struct dummy_frame_context_saver *saver = NULL;
1767 sal = find_pc_line (get_frame_pc (frame), 0);
1768 sal.pc = get_frame_pc (frame);
1770 if (get_frame_type (frame) == DUMMY_FRAME)
1772 saver = dummy_frame_context_saver_setup (get_stack_frame_id (frame),
1774 make_cleanup (dummy_frame_context_saver_cleanup, saver);
1777 breakpoint = set_momentary_breakpoint (gdbarch, sal,
1778 get_stack_frame_id (frame),
1781 /* set_momentary_breakpoint invalidates FRAME. */
1784 make_cleanup_delete_breakpoint (breakpoint);
1786 set_longjmp_breakpoint (tp, frame_id);
1787 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1789 /* We want to print return value, please... */
1790 tp->control.proceed_to_finish = 1;
1791 cargs = xmalloc (sizeof (*cargs));
1793 cargs->thread = thread;
1794 cargs->breakpoint = breakpoint;
1795 cargs->function = function;
1796 cargs->ctx_saver = saver;
1797 add_continuation (tp, finish_command_continuation, cargs,
1798 finish_command_continuation_free_arg);
1799 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1801 discard_cleanups (old_chain);
1802 if (!target_can_async_p ())
1803 do_all_continuations (0);
1806 /* "finish": Set a temporary breakpoint at the place the selected
1807 frame will return to, then continue. */
1810 finish_command (char *arg, int from_tty)
1812 struct frame_info *frame;
1813 struct symbol *function;
1815 struct cleanup *args_chain;
1818 ensure_not_tfind_mode ();
1819 ensure_valid_thread ();
1820 ensure_not_running ();
1822 /* Find out whether we must run in the background. */
1823 arg = strip_bg_char (arg, &async_exec);
1824 args_chain = make_cleanup (xfree, arg);
1826 prepare_execution_command (¤t_target, async_exec);
1829 error (_("The \"finish\" command does not take any arguments."));
1831 /* Done with ARGS. */
1832 do_cleanups (args_chain);
1834 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1836 error (_("\"finish\" not meaningful in the outermost frame."));
1838 clear_proceed_status (0);
1840 /* Finishing from an inline frame is completely different. We don't
1841 try to show the "return value" - no way to locate it. So we do
1842 not need a completion. */
1843 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1846 /* Claim we are stepping in the calling frame. An empty step
1847 range means that we will stop once we aren't in a function
1848 called by that frame. We don't use the magic "1" value for
1849 step_range_end, because then infrun will think this is nexti,
1850 and not step over the rest of this inlined function call. */
1851 struct thread_info *tp = inferior_thread ();
1852 struct symtab_and_line empty_sal;
1854 init_sal (&empty_sal);
1855 set_step_info (frame, empty_sal);
1856 tp->control.step_range_start = get_frame_pc (frame);
1857 tp->control.step_range_end = tp->control.step_range_start;
1858 tp->control.step_over_calls = STEP_OVER_ALL;
1860 /* Print info on the selected frame, including level number but not
1864 printf_filtered (_("Run till exit from "));
1865 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1868 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1872 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1873 entering THISFRAME. */
1874 while (get_frame_type (frame) == TAILCALL_FRAME)
1875 frame = get_prev_frame (frame);
1877 /* Find the function we will return from. */
1879 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1881 /* Print info on the selected frame, including level number but not
1885 if (execution_direction == EXEC_REVERSE)
1886 printf_filtered (_("Run back to call of "));
1889 if (function != NULL && TYPE_NO_RETURN (function->type)
1890 && !query (_("warning: Function %s does not return normally.\n"
1891 "Try to finish anyway? "),
1892 SYMBOL_PRINT_NAME (function)))
1893 error (_("Not confirmed."));
1894 printf_filtered (_("Run till exit from "));
1897 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1900 if (execution_direction == EXEC_REVERSE)
1901 finish_backward (function);
1903 finish_forward (function, frame);
1908 program_info (char *args, int from_tty)
1912 struct thread_info *tp;
1915 if (!target_has_execution)
1917 printf_filtered (_("The program being debugged is not being run.\n"));
1922 ptid = inferior_ptid;
1925 struct target_waitstatus ws;
1927 get_last_target_status (&ptid, &ws);
1930 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1931 error (_("Invalid selected thread."));
1932 else if (is_running (ptid))
1933 error (_("Selected thread is running."));
1935 tp = find_thread_ptid (ptid);
1936 bs = tp->control.stop_bpstat;
1937 stat = bpstat_num (&bs, &num);
1939 target_files_info ();
1940 printf_filtered (_("Program stopped at %s.\n"),
1941 paddress (target_gdbarch (), stop_pc));
1942 if (tp->control.stop_step)
1943 printf_filtered (_("It stopped after being stepped.\n"));
1946 /* There may be several breakpoints in the same place, so this
1947 isn't as strange as it seems. */
1952 printf_filtered (_("It stopped at a breakpoint "
1953 "that has since been deleted.\n"));
1956 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1957 stat = bpstat_num (&bs, &num);
1960 else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
1962 printf_filtered (_("It stopped with signal %s, %s.\n"),
1963 gdb_signal_to_name (tp->suspend.stop_signal),
1964 gdb_signal_to_string (tp->suspend.stop_signal));
1969 printf_filtered (_("Type \"info stack\" or \"info "
1970 "registers\" for more information.\n"));
1975 environment_info (char *var, int from_tty)
1979 char *val = get_in_environ (current_inferior ()->environment, var);
1983 puts_filtered (var);
1984 puts_filtered (" = ");
1985 puts_filtered (val);
1986 puts_filtered ("\n");
1990 puts_filtered ("Environment variable \"");
1991 puts_filtered (var);
1992 puts_filtered ("\" not defined.\n");
1997 char **vector = environ_vector (current_inferior ()->environment);
2001 puts_filtered (*vector++);
2002 puts_filtered ("\n");
2008 set_environment_command (char *arg, int from_tty)
2010 char *p, *val, *var;
2014 error_no_arg (_("environment variable and value"));
2016 /* Find seperation between variable name and value. */
2017 p = (char *) strchr (arg, '=');
2018 val = (char *) strchr (arg, ' ');
2020 if (p != 0 && val != 0)
2022 /* We have both a space and an equals. If the space is before the
2023 equals, walk forward over the spaces til we see a nonspace
2024 (possibly the equals). */
2029 /* Now if the = is after the char following the spaces,
2030 take the char following the spaces. */
2034 else if (val != 0 && p == 0)
2038 error_no_arg (_("environment variable to set"));
2040 if (p == 0 || p[1] == 0)
2044 p = arg + strlen (arg); /* So that savestring below will work. */
2048 /* Not setting variable value to null. */
2050 while (*val == ' ' || *val == '\t')
2054 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2057 var = savestring (arg, p - arg);
2060 printf_filtered (_("Setting environment variable "
2061 "\"%s\" to null value.\n"),
2063 set_in_environ (current_inferior ()->environment, var, "");
2066 set_in_environ (current_inferior ()->environment, var, val);
2071 unset_environment_command (char *var, int from_tty)
2075 /* If there is no argument, delete all environment variables.
2076 Ask for confirmation if reading from the terminal. */
2077 if (!from_tty || query (_("Delete all environment variables? ")))
2079 free_environ (current_inferior ()->environment);
2080 current_inferior ()->environment = make_environ ();
2084 unset_in_environ (current_inferior ()->environment, var);
2087 /* Handle the execution path (PATH variable). */
2089 static const char path_var_name[] = "PATH";
2092 path_info (char *args, int from_tty)
2094 puts_filtered ("Executable and object file path: ");
2095 puts_filtered (get_in_environ (current_inferior ()->environment,
2097 puts_filtered ("\n");
2100 /* Add zero or more directories to the front of the execution path. */
2103 path_command (char *dirname, int from_tty)
2109 env = get_in_environ (current_inferior ()->environment, path_var_name);
2110 /* Can be null if path is not set. */
2113 exec_path = xstrdup (env);
2114 mod_path (dirname, &exec_path);
2115 set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
2118 path_info ((char *) NULL, from_tty);
2122 /* Print out the register NAME with value VAL, to FILE, in the default
2126 default_print_one_register_info (struct ui_file *file,
2130 struct type *regtype = value_type (val);
2131 int print_raw_format;
2133 fputs_filtered (name, file);
2134 print_spaces_filtered (15 - strlen (name), file);
2136 print_raw_format = (value_entirely_available (val)
2137 && !value_optimized_out (val));
2139 /* If virtual format is floating, print it that way, and in raw
2141 if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2142 || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2145 struct value_print_options opts;
2146 const gdb_byte *valaddr = value_contents_for_printing (val);
2147 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2149 get_user_print_options (&opts);
2153 value_contents_for_printing (val),
2154 value_embedded_offset (val), 0,
2155 file, 0, val, &opts, current_language);
2157 if (print_raw_format)
2159 fprintf_filtered (file, "\t(raw ");
2160 print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
2161 fprintf_filtered (file, ")");
2166 struct value_print_options opts;
2168 /* Print the register in hex. */
2169 get_formatted_print_options (&opts, 'x');
2172 value_contents_for_printing (val),
2173 value_embedded_offset (val), 0,
2174 file, 0, val, &opts, current_language);
2175 /* If not a vector register, print it also according to its
2177 if (print_raw_format && TYPE_VECTOR (regtype) == 0)
2179 get_user_print_options (&opts);
2181 fprintf_filtered (file, "\t");
2183 value_contents_for_printing (val),
2184 value_embedded_offset (val), 0,
2185 file, 0, val, &opts, current_language);
2189 fprintf_filtered (file, "\n");
2192 /* Print out the machine register regnum. If regnum is -1, print all
2193 registers (print_all == 1) or all non-float and non-vector
2194 registers (print_all == 0).
2196 For most machines, having all_registers_info() print the
2197 register(s) one per line is good enough. If a different format is
2198 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2199 regs), or there is an existing convention for showing all the
2200 registers, define the architecture method PRINT_REGISTERS_INFO to
2201 provide that format. */
2204 default_print_registers_info (struct gdbarch *gdbarch,
2205 struct ui_file *file,
2206 struct frame_info *frame,
2207 int regnum, int print_all)
2210 const int numregs = gdbarch_num_regs (gdbarch)
2211 + gdbarch_num_pseudo_regs (gdbarch);
2213 for (i = 0; i < numregs; i++)
2215 /* Decide between printing all regs, non-float / vector regs, or
2221 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
2226 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
2236 /* If the register name is empty, it is undefined for this
2237 processor, so don't display anything. */
2238 if (gdbarch_register_name (gdbarch, i) == NULL
2239 || *(gdbarch_register_name (gdbarch, i)) == '\0')
2242 default_print_one_register_info (file,
2243 gdbarch_register_name (gdbarch, i),
2244 value_of_register (i, frame));
2249 registers_info (char *addr_exp, int fpregs)
2251 struct frame_info *frame;
2252 struct gdbarch *gdbarch;
2254 if (!target_has_registers)
2255 error (_("The program has no registers now."));
2256 frame = get_selected_frame (NULL);
2257 gdbarch = get_frame_arch (frame);
2261 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2266 while (*addr_exp != '\0')
2271 /* Skip leading white space. */
2272 addr_exp = skip_spaces (addr_exp);
2274 /* Discard any leading ``$''. Check that there is something
2275 resembling a register following it. */
2276 if (addr_exp[0] == '$')
2278 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2279 error (_("Missing register name"));
2281 /* Find the start/end of this register name/num/group. */
2283 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2287 /* Figure out what we've found and display it. */
2289 /* A register name? */
2291 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2295 /* User registers lie completely outside of the range of
2296 normal registers. Catch them early so that the target
2298 if (regnum >= gdbarch_num_regs (gdbarch)
2299 + gdbarch_num_pseudo_regs (gdbarch))
2301 struct value *regval = value_of_user_reg (regnum, frame);
2302 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2305 /* Print in the same fashion
2306 gdbarch_print_registers_info's default
2307 implementation prints. */
2308 default_print_one_register_info (gdb_stdout,
2313 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2314 frame, regnum, fpregs);
2319 /* A register group? */
2321 struct reggroup *group;
2323 for (group = reggroup_next (gdbarch, NULL);
2325 group = reggroup_next (gdbarch, group))
2327 /* Don't bother with a length check. Should the user
2328 enter a short register group name, go with the first
2329 group that matches. */
2330 if (strncmp (start, reggroup_name (group), end - start) == 0)
2338 regnum < gdbarch_num_regs (gdbarch)
2339 + gdbarch_num_pseudo_regs (gdbarch);
2342 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2343 gdbarch_print_registers_info (gdbarch,
2351 /* Nothing matched. */
2352 error (_("Invalid register `%.*s'"), (int) (end - start), start);
2357 all_registers_info (char *addr_exp, int from_tty)
2359 registers_info (addr_exp, 1);
2363 nofp_registers_info (char *addr_exp, int from_tty)
2365 registers_info (addr_exp, 0);
2369 print_vector_info (struct ui_file *file,
2370 struct frame_info *frame, const char *args)
2372 struct gdbarch *gdbarch = get_frame_arch (frame);
2374 if (gdbarch_print_vector_info_p (gdbarch))
2375 gdbarch_print_vector_info (gdbarch, file, frame, args);
2379 int printed_something = 0;
2382 regnum < gdbarch_num_regs (gdbarch)
2383 + gdbarch_num_pseudo_regs (gdbarch);
2386 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2388 printed_something = 1;
2389 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2392 if (!printed_something)
2393 fprintf_filtered (file, "No vector information\n");
2398 vector_info (char *args, int from_tty)
2400 if (!target_has_registers)
2401 error (_("The program has no registers now."));
2403 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2406 /* Kill the inferior process. Make us have no inferior. */
2409 kill_command (char *arg, int from_tty)
2411 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2412 It should be a distinct flag that indicates that a target is active, cuz
2413 some targets don't have processes! */
2415 if (ptid_equal (inferior_ptid, null_ptid))
2416 error (_("The program is not being run."));
2417 if (!query (_("Kill the program being debugged? ")))
2418 error (_("Not confirmed."));
2421 /* If we still have other inferiors to debug, then don't mess with
2422 with their threads. */
2423 if (!have_inferiors ())
2425 init_thread_list (); /* Destroy thread info. */
2427 /* Killing off the inferior can leave us with a core file. If
2428 so, print the state we are left in. */
2429 if (target_has_stack)
2431 printf_filtered (_("In %s,\n"), target_longname);
2432 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2435 bfd_cache_close_all ();
2438 /* Used in `attach&' command. ARG is a point to an integer
2439 representing a process id. Proceed threads of this process iff
2440 they stopped due to debugger request, and when they did, they
2441 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
2442 that have been explicitly been told to stop. */
2445 proceed_after_attach_callback (struct thread_info *thread,
2448 int pid = * (int *) arg;
2450 if (ptid_get_pid (thread->ptid) == pid
2451 && !is_exited (thread->ptid)
2452 && !is_executing (thread->ptid)
2453 && !thread->stop_requested
2454 && thread->suspend.stop_signal == GDB_SIGNAL_0)
2456 switch_to_thread (thread->ptid);
2457 clear_proceed_status (0);
2458 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2465 proceed_after_attach (int pid)
2467 /* Don't error out if the current thread is running, because
2468 there may be other stopped threads. */
2469 struct cleanup *old_chain;
2471 /* Backup current thread and selected frame. */
2472 old_chain = make_cleanup_restore_current_thread ();
2474 iterate_over_threads (proceed_after_attach_callback, &pid);
2476 /* Restore selected ptid. */
2477 do_cleanups (old_chain);
2480 /* attach_command --
2481 takes a program started up outside of gdb and ``attaches'' to it.
2482 This stops it cold in its tracks and allows us to start debugging it.
2483 and wait for the trace-trap that results from attaching. */
2486 attach_command_post_wait (char *args, int from_tty, int async_exec)
2488 struct inferior *inferior;
2490 inferior = current_inferior ();
2491 inferior->control.stop_soon = NO_STOP_QUIETLY;
2493 /* If no exec file is yet known, try to determine it from the
2495 if (get_exec_file (0) == NULL)
2496 exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
2499 reopen_exec_file ();
2503 /* Take any necessary post-attaching actions for this platform. */
2504 target_post_attach (ptid_get_pid (inferior_ptid));
2506 post_create_inferior (¤t_target, from_tty);
2510 /* The user requested an `attach&', so be sure to leave threads
2511 that didn't get a signal running. */
2513 /* Immediatelly resume all suspended threads of this inferior,
2514 and this inferior only. This should have no effect on
2515 already running threads. If a thread has been stopped with a
2516 signal, leave it be. */
2518 proceed_after_attach (inferior->pid);
2521 if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
2523 clear_proceed_status (0);
2524 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2530 /* The user requested a plain `attach', so be sure to leave
2531 the inferior stopped. */
2533 if (target_can_async_p ())
2534 async_enable_stdin ();
2536 /* At least the current thread is already stopped. */
2538 /* In all-stop, by definition, all threads have to be already
2539 stopped at this point. In non-stop, however, although the
2540 selected thread is stopped, others may still be executing.
2541 Be sure to explicitly stop all threads of the process. This
2542 should have no effect on already stopped threads. */
2544 target_stop (pid_to_ptid (inferior->pid));
2546 /* Tell the user/frontend where we're stopped. */
2548 if (deprecated_attach_hook)
2549 deprecated_attach_hook ();
2553 struct attach_command_continuation_args
2561 attach_command_continuation (void *args, int err)
2563 struct attach_command_continuation_args *a = args;
2568 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2572 attach_command_continuation_free_args (void *args)
2574 struct attach_command_continuation_args *a = args;
2581 attach_command (char *args, int from_tty)
2584 struct cleanup *args_chain;
2585 struct target_ops *attach_target;
2587 dont_repeat (); /* Not for the faint of heart */
2589 if (gdbarch_has_global_solist (target_gdbarch ()))
2590 /* Don't complain if all processes share the same symbol
2593 else if (target_has_execution)
2595 if (query (_("A program is being debugged already. Kill it? ")))
2598 error (_("Not killed."));
2601 /* Clean up any leftovers from other runs. Some other things from
2602 this function should probably be moved into target_pre_inferior. */
2603 target_pre_inferior (from_tty);
2605 args = strip_bg_char (args, &async_exec);
2606 args_chain = make_cleanup (xfree, args);
2608 attach_target = find_attach_target ();
2610 prepare_execution_command (attach_target, async_exec);
2612 if (non_stop && !attach_target->to_supports_non_stop (attach_target))
2613 error (_("Cannot attach to this target in non-stop mode"));
2615 attach_target->to_attach (attach_target, args, from_tty);
2616 /* to_attach should push the target, so after this point we
2617 shouldn't refer to attach_target again. */
2618 attach_target = NULL;
2620 /* Set up the "saved terminal modes" of the inferior
2621 based on what modes we are starting it with. */
2622 target_terminal_init ();
2624 /* Install inferior's terminal modes. This may look like a no-op,
2625 as we've just saved them above, however, this does more than
2626 restore terminal settings:
2628 - installs a SIGINT handler that forwards SIGINT to the inferior.
2629 Otherwise a Ctrl-C pressed just while waiting for the initial
2630 stop would end up as a spurious Quit.
2632 - removes stdin from the event loop, which we need if attaching
2633 in the foreground, otherwise on targets that report an initial
2634 stop on attach (which are most) we'd process input/commands
2635 while we're in the event loop waiting for that stop. That is,
2636 before the attach continuation runs and the command is really
2638 target_terminal_inferior ();
2640 /* Set up execution context to know that we should return from
2641 wait_for_inferior as soon as the target reports a stop. */
2642 init_wait_for_inferior ();
2643 clear_proceed_status (0);
2647 /* If we find that the current thread isn't stopped, explicitly
2648 do so now, because we're going to install breakpoints and
2652 /* The user requested an `attach&'; stop just one thread. */
2653 target_stop (inferior_ptid);
2655 /* The user requested an `attach', so stop all threads of this
2657 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2660 /* Some system don't generate traps when attaching to inferior.
2661 E.g. Mach 3 or GNU hurd. */
2662 if (!target_attach_no_wait)
2664 struct inferior *inferior = current_inferior ();
2666 /* Careful here. See comments in inferior.h. Basically some
2667 OSes don't ignore SIGSTOPs on continue requests anymore. We
2668 need a way for handle_inferior_event to reset the stop_signal
2669 variable after an attach, and this is what
2670 STOP_QUIETLY_NO_SIGSTOP is for. */
2671 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2673 if (target_can_async_p ())
2675 /* sync_execution mode. Wait for stop. */
2676 struct attach_command_continuation_args *a;
2678 a = xmalloc (sizeof (*a));
2679 a->args = xstrdup (args);
2680 a->from_tty = from_tty;
2681 a->async_exec = async_exec;
2682 add_inferior_continuation (attach_command_continuation, a,
2683 attach_command_continuation_free_args);
2685 /* Done with ARGS. */
2686 do_cleanups (args_chain);
2691 wait_for_inferior ();
2694 /* Done with ARGS. */
2695 do_cleanups (args_chain);
2697 attach_command_post_wait (args, from_tty, async_exec);
2700 /* We had just found out that the target was already attached to an
2701 inferior. PTID points at a thread of this new inferior, that is
2702 the most likely to be stopped right now, but not necessarily so.
2703 The new inferior is assumed to be already added to the inferior
2704 list at this point. If LEAVE_RUNNING, then leave the threads of
2705 this inferior running, except those we've explicitly seen reported
2709 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2711 struct cleanup* old_chain;
2714 old_chain = make_cleanup (null_cleanup, NULL);
2716 /* If in non-stop, leave threads as running as they were. If
2717 they're stopped for some reason other than us telling it to, the
2718 target reports a signal != GDB_SIGNAL_0. We don't try to
2719 resume threads with such a stop signal. */
2720 async_exec = non_stop;
2722 if (!ptid_equal (inferior_ptid, null_ptid))
2723 make_cleanup_restore_current_thread ();
2725 switch_to_thread (ptid);
2727 /* When we "notice" a new inferior we need to do all the things we
2728 would normally do if we had just attached to it. */
2730 if (is_executing (inferior_ptid))
2732 struct inferior *inferior = current_inferior ();
2734 /* We're going to install breakpoints, and poke at memory,
2735 ensure that the inferior is stopped for a moment while we do
2737 target_stop (inferior_ptid);
2739 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2741 /* Wait for stop before proceeding. */
2742 if (target_can_async_p ())
2744 struct attach_command_continuation_args *a;
2746 a = xmalloc (sizeof (*a));
2747 a->args = xstrdup ("");
2748 a->from_tty = from_tty;
2749 a->async_exec = async_exec;
2750 add_inferior_continuation (attach_command_continuation, a,
2751 attach_command_continuation_free_args);
2753 do_cleanups (old_chain);
2757 wait_for_inferior ();
2760 async_exec = leave_running;
2761 attach_command_post_wait ("" /* args */, from_tty, async_exec);
2763 do_cleanups (old_chain);
2768 * takes a program previously attached to and detaches it.
2769 * The program resumes execution and will no longer stop
2770 * on signals, etc. We better not have left any breakpoints
2771 * in the program or it'll die when it hits one. For this
2772 * to work, it may be necessary for the process to have been
2773 * previously attached. It *might* work if the program was
2774 * started via the normal ptrace (PTRACE_TRACEME).
2778 detach_command (char *args, int from_tty)
2780 dont_repeat (); /* Not for the faint of heart. */
2782 if (ptid_equal (inferior_ptid, null_ptid))
2783 error (_("The program is not being run."));
2785 query_if_trace_running (from_tty);
2787 disconnect_tracing ();
2789 target_detach (args, from_tty);
2791 /* If the solist is global across inferiors, don't clear it when we
2792 detach from a single inferior. */
2793 if (!gdbarch_has_global_solist (target_gdbarch ()))
2794 no_shared_libraries (NULL, from_tty);
2796 /* If we still have inferiors to debug, then don't mess with their
2798 if (!have_inferiors ())
2799 init_thread_list ();
2801 if (deprecated_detach_hook)
2802 deprecated_detach_hook ();
2805 /* Disconnect from the current target without resuming it (leaving it
2806 waiting for a debugger).
2808 We'd better not have left any breakpoints in the program or the
2809 next debugger will get confused. Currently only supported for some
2810 remote targets, since the normal attach mechanisms don't work on
2811 stopped processes on some native platforms (e.g. GNU/Linux). */
2814 disconnect_command (char *args, int from_tty)
2816 dont_repeat (); /* Not for the faint of heart. */
2817 query_if_trace_running (from_tty);
2818 disconnect_tracing ();
2819 target_disconnect (args, from_tty);
2820 no_shared_libraries (NULL, from_tty);
2821 init_thread_list ();
2822 if (deprecated_detach_hook)
2823 deprecated_detach_hook ();
2827 interrupt_target_1 (int all_threads)
2832 ptid = minus_one_ptid;
2834 ptid = inferior_ptid;
2837 /* Tag the thread as having been explicitly requested to stop, so
2838 other parts of gdb know not to resume this thread automatically,
2839 if it was stopped due to an internal event. Limit this to
2840 non-stop mode, as when debugging a multi-threaded application in
2841 all-stop mode, we will only get one stop event --- it's undefined
2842 which thread will report the event. */
2844 set_stop_requested (ptid, 1);
2848 Stop the execution of the target while running in async mode, in
2849 the backgound. In all-stop, stop the whole process. In non-stop
2850 mode, stop the current thread only by default, or stop all threads
2851 if the `-a' switch is used. */
2854 interrupt_command (char *args, int from_tty)
2856 if (target_can_async_p ())
2858 int all_threads = 0;
2860 dont_repeat (); /* Not for the faint of heart. */
2863 && startswith (args, "-a"))
2866 if (!non_stop && all_threads)
2867 error (_("-a is meaningless in all-stop mode."));
2869 interrupt_target_1 (all_threads);
2873 /* See inferior.h. */
2876 default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2877 struct frame_info *frame, const char *args)
2880 int printed_something = 0;
2883 regnum < gdbarch_num_regs (gdbarch)
2884 + gdbarch_num_pseudo_regs (gdbarch);
2887 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2889 printed_something = 1;
2890 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2893 if (!printed_something)
2894 fprintf_filtered (file, "No floating-point info "
2895 "available for this processor.\n");
2899 float_info (char *args, int from_tty)
2901 struct frame_info *frame;
2903 if (!target_has_registers)
2904 error (_("The program has no registers now."));
2906 frame = get_selected_frame (NULL);
2907 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
2911 unset_command (char *args, int from_tty)
2913 printf_filtered (_("\"unset\" must be followed by the "
2914 "name of an unset subcommand.\n"));
2915 help_list (unsetlist, "unset ", all_commands, gdb_stdout);
2918 /* Implement `info proc' family of commands. */
2921 info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
2923 struct gdbarch *gdbarch = get_current_arch ();
2925 if (!target_info_proc (args, what))
2927 if (gdbarch_info_proc_p (gdbarch))
2928 gdbarch_info_proc (gdbarch, args, what);
2930 error (_("Not supported on this target."));
2934 /* Implement `info proc' when given without any futher parameters. */
2937 info_proc_cmd (char *args, int from_tty)
2939 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
2942 /* Implement `info proc mappings'. */
2945 info_proc_cmd_mappings (char *args, int from_tty)
2947 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
2950 /* Implement `info proc stat'. */
2953 info_proc_cmd_stat (char *args, int from_tty)
2955 info_proc_cmd_1 (args, IP_STAT, from_tty);
2958 /* Implement `info proc status'. */
2961 info_proc_cmd_status (char *args, int from_tty)
2963 info_proc_cmd_1 (args, IP_STATUS, from_tty);
2966 /* Implement `info proc cwd'. */
2969 info_proc_cmd_cwd (char *args, int from_tty)
2971 info_proc_cmd_1 (args, IP_CWD, from_tty);
2974 /* Implement `info proc cmdline'. */
2977 info_proc_cmd_cmdline (char *args, int from_tty)
2979 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
2982 /* Implement `info proc exe'. */
2985 info_proc_cmd_exe (char *args, int from_tty)
2987 info_proc_cmd_1 (args, IP_EXE, from_tty);
2990 /* Implement `info proc all'. */
2993 info_proc_cmd_all (char *args, int from_tty)
2995 info_proc_cmd_1 (args, IP_ALL, from_tty);
2999 _initialize_infcmd (void)
3001 static struct cmd_list_element *info_proc_cmdlist;
3002 struct cmd_list_element *c = NULL;
3003 const char *cmd_name;
3005 /* Add the filename of the terminal connected to inferior I/O. */
3006 add_setshow_filename_cmd ("inferior-tty", class_run,
3007 &inferior_io_terminal_scratch, _("\
3008 Set terminal for future runs of program being debugged."), _("\
3009 Show terminal for future runs of program being debugged."), _("\
3010 Usage: set inferior-tty /dev/pts/1"),
3011 set_inferior_tty_command,
3012 show_inferior_tty_command,
3013 &setlist, &showlist);
3014 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
3017 add_setshow_string_noescape_cmd (cmd_name, class_run,
3018 &inferior_args_scratch, _("\
3019 Set argument list to give program being debugged when it is started."), _("\
3020 Show argument list to give program being debugged when it is started."), _("\
3021 Follow this command with any number of args, to be passed to the program."),
3024 &setlist, &showlist);
3025 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
3026 gdb_assert (c != NULL);
3027 set_cmd_completer (c, filename_completer);
3029 c = add_cmd ("environment", no_class, environment_info, _("\
3030 The environment to give the program, or one variable's value.\n\
3031 With an argument VAR, prints the value of environment variable VAR to\n\
3032 give the program being debugged. With no arguments, prints the entire\n\
3033 environment to be given to the program."), &showlist);
3034 set_cmd_completer (c, noop_completer);
3036 add_prefix_cmd ("unset", no_class, unset_command,
3037 _("Complement to certain \"set\" commands."),
3038 &unsetlist, "unset ", 0, &cmdlist);
3040 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3041 Cancel environment variable VAR for the program.\n\
3042 This does not affect the program until the next \"run\" command."),
3044 set_cmd_completer (c, noop_completer);
3046 c = add_cmd ("environment", class_run, set_environment_command, _("\
3047 Set environment variable value to give the program.\n\
3048 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3049 VALUES of environment variables are uninterpreted strings.\n\
3050 This does not affect the program until the next \"run\" command."),
3052 set_cmd_completer (c, noop_completer);
3054 c = add_com ("path", class_files, path_command, _("\
3055 Add directory DIR(s) to beginning of search path for object files.\n\
3056 $cwd in the path means the current working directory.\n\
3057 This path is equivalent to the $PATH shell variable. It is a list of\n\
3058 directories, separated by colons. These directories are searched to find\n\
3059 fully linked executable files and separately compiled object files as \
3061 set_cmd_completer (c, filename_completer);
3063 c = add_cmd ("paths", no_class, path_info, _("\
3064 Current search path for finding object files.\n\
3065 $cwd in the path means the current working directory.\n\
3066 This path is equivalent to the $PATH shell variable. It is a list of\n\
3067 directories, separated by colons. These directories are searched to find\n\
3068 fully linked executable files and separately compiled object files as \
3071 set_cmd_completer (c, noop_completer);
3073 add_prefix_cmd ("kill", class_run, kill_command,
3074 _("Kill execution of program being debugged."),
3075 &killlist, "kill ", 0, &cmdlist);
3077 add_com ("attach", class_run, attach_command, _("\
3078 Attach to a process or file outside of GDB.\n\
3079 This command attaches to another target, of the same type as your last\n\
3080 \"target\" command (\"info files\" will show your target stack).\n\
3081 The command may take as argument a process id or a device file.\n\
3082 For a process id, you must have permission to send the process a signal,\n\
3083 and it must have the same effective uid as the debugger.\n\
3084 When using \"attach\" with a process id, the debugger finds the\n\
3085 program running in the process, looking first in the current working\n\
3086 directory, or (if not found there) using the source file search path\n\
3087 (see the \"directory\" command). You can also use the \"file\" command\n\
3088 to specify the program, and to load its symbol table."));
3090 add_prefix_cmd ("detach", class_run, detach_command, _("\
3091 Detach a process or file previously attached.\n\
3092 If a process, it is no longer traced, and it continues its execution. If\n\
3093 you were debugging a file, the file is closed and gdb no longer accesses it."),
3094 &detachlist, "detach ", 0, &cmdlist);
3096 add_com ("disconnect", class_run, disconnect_command, _("\
3097 Disconnect from a target.\n\
3098 The target will wait for another debugger to connect. Not available for\n\
3101 c = add_com ("signal", class_run, signal_command, _("\
3102 Continue program with the specified signal.\n\
3103 Usage: signal SIGNAL\n\
3104 The SIGNAL argument is processed the same as the handle command.\n\
3106 An argument of \"0\" means continue the program without sending it a signal.\n\
3107 This is useful in cases where the program stopped because of a signal,\n\
3108 and you want to resume the program while discarding the signal.\n\
3110 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3111 the current thread only."));
3112 set_cmd_completer (c, signal_completer);
3114 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3115 Queue a signal to be delivered to the current thread when it is resumed.\n\
3116 Usage: queue-signal SIGNAL\n\
3117 The SIGNAL argument is processed the same as the handle command.\n\
3118 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3120 An argument of \"0\" means remove any currently queued signal from\n\
3121 the current thread. This is useful in cases where the program stopped\n\
3122 because of a signal, and you want to resume it while discarding the signal.\n\
3124 In a multi-threaded program the signal is queued with, or discarded from,\n\
3125 the current thread only."));
3126 set_cmd_completer (c, signal_completer);
3128 add_com ("stepi", class_run, stepi_command, _("\
3129 Step one instruction exactly.\n\
3131 Argument N means step N times (or till program stops for another \
3133 add_com_alias ("si", "stepi", class_alias, 0);
3135 add_com ("nexti", class_run, nexti_command, _("\
3136 Step one instruction, but proceed through subroutine calls.\n\
3138 Argument N means step N times (or till program stops for another \
3140 add_com_alias ("ni", "nexti", class_alias, 0);
3142 add_com ("finish", class_run, finish_command, _("\
3143 Execute until selected stack frame returns.\n\
3145 Upon return, the value returned is printed and put in the value history."));
3146 add_com_alias ("fin", "finish", class_run, 1);
3148 add_com ("next", class_run, next_command, _("\
3149 Step program, proceeding through subroutine calls.\n\
3151 Unlike \"step\", if the current source line calls a subroutine,\n\
3152 this command does not enter the subroutine, but instead steps over\n\
3153 the call, in effect treating it as a single source line."));
3154 add_com_alias ("n", "next", class_run, 1);
3156 add_com ("step", class_run, step_command, _("\
3157 Step program until it reaches a different source line.\n\
3159 Argument N means step N times (or till program stops for another \
3161 add_com_alias ("s", "step", class_run, 1);
3163 c = add_com ("until", class_run, until_command, _("\
3164 Execute until the program reaches a source line greater than the current\n\
3165 or a specified location (same args as break command) within the current \
3167 set_cmd_completer (c, location_completer);
3168 add_com_alias ("u", "until", class_run, 1);
3170 c = add_com ("advance", class_run, advance_command, _("\
3171 Continue the program up to the given location (same form as args for break \
3173 Execution will also stop upon exit from the current stack frame."));
3174 set_cmd_completer (c, location_completer);
3176 c = add_com ("jump", class_run, jump_command, _("\
3177 Continue program being debugged at specified line or address.\n\
3178 Usage: jump <location>\n\
3179 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3180 for an address to start at."));
3181 set_cmd_completer (c, location_completer);
3182 add_com_alias ("j", "jump", class_run, 1);
3184 add_com ("continue", class_run, continue_command, _("\
3185 Continue program being debugged, after signal or breakpoint.\n\
3186 Usage: continue [N]\n\
3187 If proceeding from breakpoint, a number N may be used as an argument,\n\
3188 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3189 the breakpoint won't break until the Nth time it is reached).\n\
3191 If non-stop mode is enabled, continue only the current thread,\n\
3192 otherwise all the threads in the program are continued. To \n\
3193 continue all stopped threads in non-stop mode, use the -a option.\n\
3194 Specifying -a and an ignore count simultaneously is an error."));
3195 add_com_alias ("c", "cont", class_run, 1);
3196 add_com_alias ("fg", "cont", class_run, 1);
3198 c = add_com ("run", class_run, run_command, _("\
3199 Start debugged program. You may specify arguments to give it.\n\
3200 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3201 Input and output redirection with \">\", \"<\", or \">>\" are also \
3203 With no arguments, uses arguments last specified (with \"run\" \
3204 or \"set args\").\n\
3205 To cancel previous arguments and run with no arguments,\n\
3206 use \"set args\" without arguments."));
3207 set_cmd_completer (c, filename_completer);
3208 add_com_alias ("r", "run", class_run, 1);
3210 c = add_com ("start", class_run, start_command, _("\
3211 Run the debugged program until the beginning of the main procedure.\n\
3212 You may specify arguments to give to your program, just as with the\n\
3213 \"run\" command."));
3214 set_cmd_completer (c, filename_completer);
3216 add_com ("interrupt", class_run, interrupt_command,
3217 _("Interrupt the execution of the debugged program.\n\
3218 If non-stop mode is enabled, interrupt only the current thread,\n\
3219 otherwise all the threads in the program are stopped. To \n\
3220 interrupt all running threads in non-stop mode, use the -a option."));
3222 c = add_info ("registers", nofp_registers_info, _("\
3223 List of integer registers and their contents, for selected stack frame.\n\
3224 Register name as argument means describe only that register."));
3225 add_info_alias ("r", "registers", 1);
3226 set_cmd_completer (c, reg_or_group_completer);
3228 c = add_info ("all-registers", all_registers_info, _("\
3229 List of all registers and their contents, for selected stack frame.\n\
3230 Register name as argument means describe only that register."));
3231 set_cmd_completer (c, reg_or_group_completer);
3233 add_info ("program", program_info,
3234 _("Execution status of the program."));
3236 add_info ("float", float_info,
3237 _("Print the status of the floating point unit\n"));
3239 add_info ("vector", vector_info,
3240 _("Print the status of the vector unit\n"));
3242 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3244 Show /proc process information about any running process.\n\
3245 Specify any process id, or use the program being debugged by default."),
3246 &info_proc_cmdlist, "info proc ",
3247 1/*allow-unknown*/, &infolist);
3249 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3250 List of mapped memory regions."),
3251 &info_proc_cmdlist);
3253 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3254 List process info from /proc/PID/stat."),
3255 &info_proc_cmdlist);
3257 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3258 List process info from /proc/PID/status."),
3259 &info_proc_cmdlist);
3261 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3262 List current working directory of the process."),
3263 &info_proc_cmdlist);
3265 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3266 List command line arguments of the process."),
3267 &info_proc_cmdlist);
3269 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3270 List absolute filename for executable of the process."),
3271 &info_proc_cmdlist);
3273 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3274 List all available /proc info."),
3275 &info_proc_cmdlist);