1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
38 #include "completer.h"
40 #include "event-top.h"
41 #include "parser-defs.h"
43 #include "reggroups.h"
47 #include "gdb_assert.h"
49 #include "target-descriptions.h"
50 #include "user-regs.h"
51 #include "exceptions.h"
52 #include "cli/cli-decode.h"
53 #include "gdbthread.h"
55 /* Functions exported for general use, in inferior.h: */
57 void all_registers_info (char *, int);
59 void registers_info (char *, int);
61 void nexti_command (char *, int);
63 void stepi_command (char *, int);
65 void continue_command (char *, int);
67 void interrupt_target_command (char *args, int from_tty);
69 /* Local functions: */
71 static void nofp_registers_info (char *, int);
73 static void print_return_value (struct type *func_type,
74 struct type *value_type);
76 static void until_next_command (int);
78 static void until_command (char *, int);
80 static void path_info (char *, int);
82 static void path_command (char *, int);
84 static void unset_command (char *, int);
86 static void float_info (char *, int);
88 static void detach_command (char *, int);
90 static void disconnect_command (char *, int);
92 static void unset_environment_command (char *, int);
94 static void set_environment_command (char *, int);
96 static void environment_info (char *, int);
98 static void program_info (char *, int);
100 static void finish_command (char *, int);
102 static void signal_command (char *, int);
104 static void jump_command (char *, int);
106 static void step_1 (int, int, char *);
107 static void step_once (int skip_subroutines, int single_inst, int count, int thread);
109 static void next_command (char *, int);
111 static void step_command (char *, int);
113 static void run_command (char *, int);
115 static void run_no_args_command (char *args, int from_tty);
117 static void go_command (char *line_no, int from_tty);
119 static int strip_bg_char (char **);
121 void _initialize_infcmd (void);
123 #define ERROR_NO_INFERIOR \
124 if (!target_has_execution) error (_("The program is not being run."));
126 /* String containing arguments to give to the program, separated by spaces.
127 Empty string (pointer to '\0') means no args. */
129 static char *inferior_args;
131 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
132 then we must compute INFERIOR_ARGS from this (via the target). */
134 static int inferior_argc;
135 static char **inferior_argv;
137 /* File name for default use for standard in/out in the inferior. */
139 static char *inferior_io_terminal;
141 /* Pid of our debugged inferior, or 0 if no inferior now.
142 Since various parts of infrun.c test this to see whether there is a program
143 being debugged it should be nonzero (currently 3 is used) for remote
146 ptid_t inferior_ptid;
148 /* Address at which inferior stopped. */
152 /* Flag indicating that a command has proceeded the inferior past the
153 current breakpoint. */
155 int breakpoint_proceeded;
157 /* Nonzero if stopped due to completion of a stack dummy routine. */
159 int stop_stack_dummy;
161 /* Nonzero if stopped due to a random (unexpected) signal in inferior
164 int stopped_by_random_signal;
166 /* Environment to use for running inferior,
167 in format described in environ.h. */
169 struct gdb_environ *inferior_environ;
171 /* When set, no calls to target_resumed observer will be made. */
172 int suppress_resume_observer = 0;
173 /* When set, normal_stop will not call the normal_stop observer. */
174 int suppress_stop_observer = 0;
176 /* Accessor routines. */
179 set_inferior_io_terminal (const char *terminal_name)
181 if (inferior_io_terminal)
182 xfree (inferior_io_terminal);
185 inferior_io_terminal = NULL;
187 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
191 get_inferior_io_terminal (void)
193 return inferior_io_terminal;
197 get_inferior_args (void)
199 if (inferior_argc != 0)
203 n = gdbarch_construct_inferior_arguments (current_gdbarch,
204 inferior_argc, inferior_argv);
205 old = set_inferior_args (n);
209 if (inferior_args == NULL)
210 inferior_args = xstrdup ("");
212 return inferior_args;
216 set_inferior_args (char *newargs)
218 char *saved_args = inferior_args;
220 inferior_args = newargs;
228 set_inferior_args_vector (int argc, char **argv)
230 inferior_argc = argc;
231 inferior_argv = argv;
234 /* Notice when `set args' is run. */
236 notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
242 /* Notice when `show args' is run. */
244 notice_args_read (struct ui_file *file, int from_tty,
245 struct cmd_list_element *c, const char *value)
247 /* Note that we ignore the passed-in value in favor of computing it
249 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
253 /* Compute command-line string given argument vector. This does the
254 same shell processing as fork_inferior. */
256 construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
260 if (STARTUP_WITH_SHELL)
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";
270 /* We over-compute the size. It shouldn't matter. */
271 for (i = 0; i < argc; ++i)
272 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
274 result = (char *) xmalloc (length);
277 for (i = 0; i < argc; ++i)
282 /* Need to handle empty arguments specially. */
283 if (argv[i][0] == '\0')
290 for (cp = argv[i]; *cp; ++cp)
292 if (strchr (special, *cp) != NULL)
302 /* In this case we can't handle arguments that contain spaces,
303 tabs, or newlines -- see breakup_args(). */
307 for (i = 0; i < argc; ++i)
309 char *cp = strchr (argv[i], ' ');
311 cp = strchr (argv[i], '\t');
313 cp = strchr (argv[i], '\n');
315 error (_("can't handle command-line argument containing whitespace"));
316 length += strlen (argv[i]) + 1;
319 result = (char *) xmalloc (length);
321 for (i = 0; i < argc; ++i)
324 strcat (result, " ");
325 strcat (result, argv[i]);
333 /* This function detects whether or not a '&' character (indicating
334 background execution) has been added as *the last* of the arguments ARGS
335 of a command. If it has, it removes it and returns 1. Otherwise it
336 does nothing and returns 0. */
338 strip_bg_char (char **args)
342 p = strchr (*args, '&');
346 if (p == (*args + strlen (*args) - 1))
348 if (strlen (*args) > 1)
352 while (*p == ' ' || *p == '\t');
364 tty_command (char *file, int from_tty)
367 error_no_arg (_("terminal name for running target process"));
369 set_inferior_io_terminal (file);
372 /* Common actions to take after creating any sort of inferior, by any
373 means (running, attaching, connecting, et cetera). The target
374 should be stopped. */
377 post_create_inferior (struct target_ops *target, int from_tty)
379 /* Be sure we own the terminal in case write operations are performed. */
380 target_terminal_ours ();
382 /* If the target hasn't taken care of this already, do it now.
383 Targets which need to access registers during to_open,
384 to_create_inferior, or to_attach should do it earlier; but many
386 target_find_description ();
390 /* Sometimes the platform-specific hook loads initial shared
391 libraries, and sometimes it doesn't. Try to do so first, so
392 that we can add them with the correct value for FROM_TTY.
393 If we made all the inferior hook methods consistent,
394 this call could be removed. */
396 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
398 solib_add (NULL, from_tty, target, auto_solib_add);
401 /* Create the hooks to handle shared library load and unload
403 #ifdef SOLIB_CREATE_INFERIOR_HOOK
404 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
406 solib_create_inferior_hook ();
410 observer_notify_inferior_created (target, from_tty);
413 /* Kill the inferior if already running. This function is designed
414 to be called when we are about to start the execution of the program
415 from the beginning. Ask the user to confirm that he wants to restart
416 the program being debugged when FROM_TTY is non-null. */
419 kill_if_already_running (int from_tty)
421 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
423 /* Bail out before killing the program if we will not be able to
425 target_require_runnable ();
428 && !query ("The program being debugged has been started already.\n\
429 Start it from the beginning? "))
430 error (_("Program not restarted."));
435 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
436 a temporary breakpoint at the begining of the main program before
437 running the program. */
440 run_command_1 (char *args, int from_tty, int tbreak_at_main)
446 kill_if_already_running (from_tty);
448 init_wait_for_inferior ();
449 clear_breakpoint_hit_counts ();
451 /* Clean up any leftovers from other runs. Some other things from
452 this function should probably be moved into target_pre_inferior. */
453 target_pre_inferior (from_tty);
455 /* The comment here used to read, "The exec file is re-read every
456 time we do a generic_mourn_inferior, so we just have to worry
457 about the symbol file." The `generic_mourn_inferior' function
458 gets called whenever the program exits. However, suppose the
459 program exits, and *then* the executable file changes? We need
460 to check again here. Since reopen_exec_file doesn't do anything
461 if the timestamp hasn't changed, I don't see the harm. */
465 /* Insert the temporary breakpoint if a location was specified. */
467 tbreak_command (main_name (), 0);
469 exec_file = (char *) get_exec_file (0);
471 if (non_stop && !target_supports_non_stop ())
472 error (_("The target does not support running in non-stop mode."));
474 /* We keep symbols from add-symbol-file, on the grounds that the
475 user might want to add some symbols before running the program
476 (right?). But sometimes (dynamic loading where the user manually
477 introduces the new symbols with add-symbol-file), the code which
478 the symbols describe does not persist between runs. Currently
479 the user has to manually nuke all symbols between runs if they
480 want them to go away (PR 2207). This is probably reasonable. */
484 if (target_can_async_p ())
485 async_disable_stdin ();
489 int async_exec = strip_bg_char (&args);
491 /* If we get a request for running in the bg but the target
492 doesn't support it, error out. */
493 if (async_exec && !target_can_async_p ())
494 error (_("Asynchronous execution not supported on this target."));
496 /* If we don't get a request of running in the bg, then we need
497 to simulate synchronous (fg) execution. */
498 if (!async_exec && target_can_async_p ())
500 /* Simulate synchronous execution */
501 async_disable_stdin ();
504 /* If there were other args, beside '&', process them. */
507 char *old_args = set_inferior_args (xstrdup (args));
514 ui_out_field_string (uiout, NULL, "Starting program");
515 ui_out_text (uiout, ": ");
517 ui_out_field_string (uiout, "execfile", exec_file);
518 ui_out_spaces (uiout, 1);
519 /* We call get_inferior_args() because we might need to compute
521 ui_out_field_string (uiout, "infargs", get_inferior_args ());
522 ui_out_text (uiout, "\n");
523 ui_out_flush (uiout);
526 /* We call get_inferior_args() because we might need to compute
528 target_create_inferior (exec_file, get_inferior_args (),
529 environ_vector (inferior_environ), from_tty);
531 /* Pass zero for FROM_TTY, because at this point the "run" command
532 has done its thing; now we are setting up the running program. */
533 post_create_inferior (¤t_target, 0);
535 /* Start the target running. */
536 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
541 run_command (char *args, int from_tty)
543 run_command_1 (args, from_tty, 0);
547 run_no_args_command (char *args, int from_tty)
549 char *old_args = set_inferior_args (xstrdup (""));
554 /* Start the execution of the program up until the beginning of the main
558 start_command (char *args, int from_tty)
560 /* Some languages such as Ada need to search inside the program
561 minimal symbols for the location where to put the temporary
562 breakpoint before starting. */
563 if (!have_minimal_symbols ())
564 error (_("No symbol table loaded. Use the \"file\" command."));
566 /* Run the program until reaching the main procedure... */
567 run_command_1 (args, from_tty, 1);
571 proceed_thread_callback (struct thread_info *thread, void *arg)
573 if (!is_stopped (thread->ptid))
576 switch_to_thread (thread->ptid);
577 clear_proceed_status ();
578 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
583 continue_1 (int all_threads)
587 if (non_stop && all_threads)
589 /* Don't error out if the current thread is running, because
590 there may be other stopped threads. */
591 struct cleanup *old_chain;
593 /* Backup current thread and selected frame. */
594 old_chain = make_cleanup_restore_current_thread ();
596 iterate_over_threads (proceed_thread_callback, NULL);
598 /* Restore selected ptid. */
599 do_cleanups (old_chain);
603 ensure_not_running ();
604 clear_proceed_status ();
605 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
609 /* continue [-a] [proceed-count] [&] */
611 continue_command (char *args, int from_tty)
617 /* Find out whether we must run in the background. */
619 async_exec = strip_bg_char (&args);
621 /* If we must run in the background, but the target can't do it,
623 if (async_exec && !target_can_async_p ())
624 error (_("Asynchronous execution not supported on this target."));
626 /* If we are not asked to run in the bg, then prepare to run in the
627 foreground, synchronously. */
628 if (!async_exec && target_can_async_p ())
630 /* Simulate synchronous execution */
631 async_disable_stdin ();
636 if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
639 args += sizeof ("-a") - 1;
645 if (!non_stop && all_threads)
646 error (_("`-a' is meaningless in all-stop mode."));
648 if (args != NULL && all_threads)
650 Can't resume all threads and specify proceed count simultaneously."));
652 /* If we have an argument left, set proceed count of breakpoint we
659 struct thread_info *tp;
662 tp = find_thread_pid (inferior_ptid);
666 struct target_waitstatus ws;
668 get_last_target_status (&last_ptid, &ws);
669 tp = find_thread_pid (last_ptid);
672 bs = tp->stop_bpstat;
674 while ((stat = bpstat_num (&bs, &num)) != 0)
677 set_ignore_count (num,
678 parse_and_eval_long (args) - 1,
680 /* set_ignore_count prints a message ending with a period.
681 So print two spaces before "Continuing.". */
683 printf_filtered (" ");
687 if (!stopped && from_tty)
690 ("Not stopped at any breakpoint; argument ignored.\n");
695 printf_filtered (_("Continuing.\n"));
697 continue_1 (all_threads);
700 /* Step until outside of current statement. */
703 step_command (char *count_string, int from_tty)
705 step_1 (0, 0, count_string);
708 /* Likewise, but skip over subroutine calls as if single instructions. */
711 next_command (char *count_string, int from_tty)
713 step_1 (1, 0, count_string);
716 /* Likewise, but step only one instruction. */
719 stepi_command (char *count_string, int from_tty)
721 step_1 (0, 1, count_string);
725 nexti_command (char *count_string, int from_tty)
727 step_1 (1, 1, count_string);
731 delete_longjmp_breakpoint_cleanup (void *arg)
733 int thread = * (int *) arg;
734 delete_longjmp_breakpoint (thread);
738 step_1 (int skip_subroutines, int single_inst, char *count_string)
741 struct frame_info *frame;
742 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
747 ensure_not_running ();
750 async_exec = strip_bg_char (&count_string);
752 /* If we get a request for running in the bg but the target
753 doesn't support it, error out. */
754 if (async_exec && !target_can_async_p ())
755 error (_("Asynchronous execution not supported on this target."));
757 /* If we don't get a request of running in the bg, then we need
758 to simulate synchronous (fg) execution. */
759 if (!async_exec && target_can_async_p ())
761 /* Simulate synchronous execution */
762 async_disable_stdin ();
765 count = count_string ? parse_and_eval_long (count_string) : 1;
767 if (!single_inst || skip_subroutines) /* leave si command alone */
769 if (in_thread_list (inferior_ptid))
770 thread = pid_to_thread_id (inferior_ptid);
772 set_longjmp_breakpoint ();
774 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
777 /* In synchronous case, all is well, just use the regular for loop. */
778 if (!target_can_async_p ())
780 for (; count > 0; count--)
782 struct thread_info *tp = inferior_thread ();
783 clear_proceed_status ();
785 frame = get_current_frame ();
786 tp->step_frame_id = get_frame_id (frame);
790 find_pc_line_pc_range (stop_pc,
791 &tp->step_range_start, &tp->step_range_end);
792 if (tp->step_range_end == 0)
795 if (find_pc_partial_function (stop_pc, &name,
796 &tp->step_range_start,
797 &tp->step_range_end) == 0)
798 error (_("Cannot find bounds of current function"));
800 target_terminal_ours ();
801 printf_filtered (_("\
802 Single stepping until exit from function %s, \n\
803 which has no line number information.\n"), name);
808 /* Say we are stepping, but stop after one insn whatever it does. */
809 tp->step_range_start = tp->step_range_end = 1;
810 if (!skip_subroutines)
812 Don't step over function calls, not even to functions lacking
814 tp->step_over_calls = STEP_OVER_NONE;
817 if (skip_subroutines)
818 tp->step_over_calls = STEP_OVER_ALL;
820 tp->step_multi = (count > 1);
821 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
823 if (!target_has_execution
824 || !inferior_thread ()->stop_step)
828 do_cleanups (cleanups);
831 /* In case of asynchronous target things get complicated, do only
832 one step for now, before returning control to the event loop. Let
833 the continuation figure out how many other steps we need to do,
834 and handle them one at the time, through step_once(). */
837 step_once (skip_subroutines, single_inst, count, thread);
838 /* We are running, and the continuation is installed. It will
839 disable the longjmp breakpoint as appropriate. */
840 discard_cleanups (cleanups);
844 struct step_1_continuation_args
847 int skip_subroutines;
852 /* Called after we are done with one step operation, to check whether
853 we need to step again, before we print the prompt and return control
854 to the user. If count is > 1, we will need to do one more call to
855 proceed(), via step_once(). Basically it is like step_once and
856 step_1_continuation are co-recursive. */
858 step_1_continuation (void *args)
860 struct step_1_continuation_args *a = args;
862 if (target_has_execution)
864 struct thread_info *tp;
866 tp = inferior_thread ();
867 if (tp->step_multi && tp->stop_step)
869 /* There are more steps to make, and we did stop due to
870 ending a stepping range. Do another step. */
871 step_once (a->skip_subroutines, a->single_inst, a->count - 1, a->thread);
877 /* We either stopped for some reason that is not stepping, or there
878 are no further steps to make. Cleanup. */
879 if (!a->single_inst || a->skip_subroutines)
880 delete_longjmp_breakpoint (a->thread);
883 /* Do just one step operation. If count >1 we will have to set up a
884 continuation to be done after the target stops (after this one
885 step). This is useful to implement the 'step n' kind of commands, in
886 case of asynchronous targets. We had to split step_1 into two parts,
887 one to be done before proceed() and one afterwards. This function is
888 called in case of step n with n>1, after the first step operation has
891 step_once (int skip_subroutines, int single_inst, int count, int thread)
893 struct frame_info *frame;
894 struct step_1_continuation_args *args;
898 /* Don't assume THREAD is a valid thread id. It is set to -1 if
899 the longjmp breakpoint was not required. Use the
900 INFERIOR_PTID thread instead, which is the same thread when
902 struct thread_info *tp = inferior_thread ();
903 clear_proceed_status ();
905 frame = get_current_frame ();
906 if (!frame) /* Avoid coredump here. Why tho? */
907 error (_("No current frame"));
908 tp->step_frame_id = get_frame_id (frame);
912 find_pc_line_pc_range (stop_pc,
913 &tp->step_range_start, &tp->step_range_end);
915 /* If we have no line info, switch to stepi mode. */
916 if (tp->step_range_end == 0 && step_stop_if_no_debug)
918 tp->step_range_start = tp->step_range_end = 1;
920 else if (tp->step_range_end == 0)
923 if (find_pc_partial_function (stop_pc, &name,
924 &tp->step_range_start,
925 &tp->step_range_end) == 0)
926 error (_("Cannot find bounds of current function"));
928 target_terminal_ours ();
929 printf_filtered (_("\
930 Single stepping until exit from function %s, \n\
931 which has no line number information.\n"), name);
936 /* Say we are stepping, but stop after one insn whatever it does. */
937 tp->step_range_start = tp->step_range_end = 1;
938 if (!skip_subroutines)
940 Don't step over function calls, not even to functions lacking
942 tp->step_over_calls = STEP_OVER_NONE;
945 if (skip_subroutines)
946 tp->step_over_calls = STEP_OVER_ALL;
948 tp->step_multi = (count > 1);
949 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
951 args = xmalloc (sizeof (*args));
952 args->skip_subroutines = skip_subroutines;
953 args->single_inst = single_inst;
955 args->thread = thread;
956 add_intermediate_continuation (tp, step_1_continuation, args, xfree);
961 /* Continue program at specified address. */
964 jump_command (char *arg, int from_tty)
967 struct symtabs_and_lines sals;
968 struct symtab_and_line sal;
974 ensure_not_running ();
976 /* Find out whether we must run in the background. */
978 async_exec = strip_bg_char (&arg);
980 /* If we must run in the background, but the target can't do it,
982 if (async_exec && !target_can_async_p ())
983 error (_("Asynchronous execution not supported on this target."));
986 error_no_arg (_("starting address"));
988 sals = decode_line_spec_1 (arg, 1);
991 error (_("Unreasonable jump request"));
997 if (sal.symtab == 0 && sal.pc == 0)
998 error (_("No source file has been specified."));
1000 resolve_sal_pc (&sal); /* May error out */
1002 /* See if we are trying to jump to another function. */
1003 fn = get_frame_function (get_current_frame ());
1004 sfn = find_pc_function (sal.pc);
1005 if (fn != NULL && sfn != fn)
1007 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
1008 SYMBOL_PRINT_NAME (fn)))
1010 error (_("Not confirmed."));
1017 fixup_symbol_section (sfn, 0);
1018 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) &&
1019 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn)))
1021 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
1023 error (_("Not confirmed."));
1033 printf_filtered (_("Continuing at "));
1034 fputs_filtered (paddress (addr), gdb_stdout);
1035 printf_filtered (".\n");
1038 /* If we are not asked to run in the bg, then prepare to run in the
1039 foreground, synchronously. */
1040 if (!async_exec && target_can_async_p ())
1042 /* Simulate synchronous execution */
1043 async_disable_stdin ();
1046 clear_proceed_status ();
1047 proceed (addr, TARGET_SIGNAL_0, 0);
1051 /* Go to line or address in current procedure */
1053 go_command (char *line_no, int from_tty)
1055 if (line_no == (char *) NULL || !*line_no)
1056 printf_filtered (_("Usage: go <location>\n"));
1059 tbreak_command (line_no, from_tty);
1060 jump_command (line_no, from_tty);
1065 /* Continue program giving it specified signal. */
1068 signal_command (char *signum_exp, int from_tty)
1070 enum target_signal oursig;
1073 dont_repeat (); /* Too dangerous. */
1075 ensure_not_running ();
1077 /* Find out whether we must run in the background. */
1078 if (signum_exp != NULL)
1079 async_exec = strip_bg_char (&signum_exp);
1081 /* If we must run in the background, but the target can't do it,
1083 if (async_exec && !target_can_async_p ())
1084 error (_("Asynchronous execution not supported on this target."));
1086 /* If we are not asked to run in the bg, then prepare to run in the
1087 foreground, synchronously. */
1088 if (!async_exec && target_can_async_p ())
1090 /* Simulate synchronous execution. */
1091 async_disable_stdin ();
1095 error_no_arg (_("signal number"));
1097 /* It would be even slicker to make signal names be valid expressions,
1098 (the type could be "enum $signal" or some such), then the user could
1099 assign them to convenience variables. */
1100 oursig = target_signal_from_name (signum_exp);
1102 if (oursig == TARGET_SIGNAL_UNKNOWN)
1104 /* No, try numeric. */
1105 int num = parse_and_eval_long (signum_exp);
1108 oursig = TARGET_SIGNAL_0;
1110 oursig = target_signal_from_command (num);
1115 if (oursig == TARGET_SIGNAL_0)
1116 printf_filtered (_("Continuing with no signal.\n"));
1118 printf_filtered (_("Continuing with signal %s.\n"),
1119 target_signal_to_name (oursig));
1122 clear_proceed_status ();
1123 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1124 FIXME: Neither should "signal foo" but when I tried passing
1125 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1126 tried to track down yet. */
1127 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
1130 /* Proceed until we reach a different source line with pc greater than
1131 our current one or exit the function. We skip calls in both cases.
1133 Note that eventually this command should probably be changed so
1134 that only source lines are printed out when we hit the breakpoint
1135 we set. This may involve changes to wait_for_inferior and the
1136 proceed status code. */
1139 until_next_command (int from_tty)
1141 struct frame_info *frame;
1143 struct symbol *func;
1144 struct symtab_and_line sal;
1145 struct thread_info *tp = inferior_thread ();
1147 clear_proceed_status ();
1149 frame = get_current_frame ();
1151 /* Step until either exited from this function or greater
1152 than the current line (if in symbolic section) or pc (if
1156 func = find_pc_function (pc);
1160 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1162 if (msymbol == NULL)
1163 error (_("Execution is not within a known function."));
1165 tp->step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1166 tp->step_range_end = pc;
1170 sal = find_pc_line (pc, 0);
1172 tp->step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1173 tp->step_range_end = sal.end;
1176 tp->step_over_calls = STEP_OVER_ALL;
1177 tp->step_frame_id = get_frame_id (frame);
1179 tp->step_multi = 0; /* Only one call to proceed */
1181 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1185 until_command (char *arg, int from_tty)
1189 if (!target_has_execution)
1190 error (_("The program is not running."));
1192 /* Find out whether we must run in the background. */
1194 async_exec = strip_bg_char (&arg);
1196 /* If we must run in the background, but the target can't do it,
1198 if (async_exec && !target_can_async_p ())
1199 error (_("Asynchronous execution not supported on this target."));
1201 /* If we are not asked to run in the bg, then prepare to run in the
1202 foreground, synchronously. */
1203 if (!async_exec && target_can_async_p ())
1205 /* Simulate synchronous execution */
1206 async_disable_stdin ();
1210 until_break_command (arg, from_tty, 0);
1212 until_next_command (from_tty);
1216 advance_command (char *arg, int from_tty)
1220 if (!target_has_execution)
1221 error (_("The program is not running."));
1224 error_no_arg (_("a location"));
1226 /* Find out whether we must run in the background. */
1228 async_exec = strip_bg_char (&arg);
1230 /* If we must run in the background, but the target can't do it,
1232 if (async_exec && !target_can_async_p ())
1233 error (_("Asynchronous execution not supported on this target."));
1235 /* If we are not asked to run in the bg, then prepare to run in the
1236 foreground, synchronously. */
1237 if (!async_exec && target_can_async_p ())
1239 /* Simulate synchronous execution. */
1240 async_disable_stdin ();
1243 until_break_command (arg, from_tty, 1);
1246 /* Print the result of a function at the end of a 'finish' command. */
1249 print_return_value (struct type *func_type, struct type *value_type)
1251 struct gdbarch *gdbarch = current_gdbarch;
1252 struct cleanup *old_chain;
1253 struct ui_stream *stb;
1254 struct value *value;
1256 CHECK_TYPEDEF (value_type);
1257 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1259 /* FIXME: 2003-09-27: When returning from a nested inferior function
1260 call, it's possible (with no help from the architecture vector)
1261 to locate and return/print a "struct return" value. This is just
1262 a more complicated case of what is already being done in in the
1263 inferior function call code. In fact, when inferior function
1264 calls are made async, this will likely be made the norm. */
1266 switch (gdbarch_return_value (gdbarch, func_type, value_type,
1269 case RETURN_VALUE_REGISTER_CONVENTION:
1270 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1271 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1272 value = allocate_value (value_type);
1273 gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
1274 value_contents_raw (value), NULL);
1276 case RETURN_VALUE_STRUCT_CONVENTION:
1280 internal_error (__FILE__, __LINE__, _("bad switch"));
1286 stb = ui_out_stream_new (uiout);
1287 old_chain = make_cleanup_ui_out_stream_delete (stb);
1288 ui_out_text (uiout, "Value returned is ");
1289 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1290 record_latest_value (value));
1291 ui_out_text (uiout, " = ");
1292 value_print (value, stb->stream, 0, Val_no_prettyprint);
1293 ui_out_field_stream (uiout, "return-value", stb);
1294 ui_out_text (uiout, "\n");
1295 do_cleanups (old_chain);
1299 ui_out_text (uiout, "Value returned has type: ");
1300 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1301 ui_out_text (uiout, ".");
1302 ui_out_text (uiout, " Cannot determine contents\n");
1306 /* Stuff that needs to be done by the finish command after the target
1307 has stopped. In asynchronous mode, we wait for the target to stop
1308 in the call to poll or select in the event loop, so it is
1309 impossible to do all the stuff as part of the finish_command
1310 function itself. The only chance we have to complete this command
1311 is in fetch_inferior_event, which is called by the event loop as
1312 soon as it detects that the target has stopped. This function is
1313 called via the cmd_continuation pointer. */
1315 struct finish_command_continuation_args
1317 struct breakpoint *breakpoint;
1318 struct symbol *function;
1322 finish_command_continuation (void *arg)
1324 struct finish_command_continuation_args *a = arg;
1328 if (!ptid_equal (inferior_ptid, null_ptid)
1329 && target_has_execution
1330 && is_stopped (inferior_ptid))
1331 bs = inferior_thread ()->stop_bpstat;
1333 if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1334 && a->function != NULL)
1336 struct type *value_type;
1338 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1340 internal_error (__FILE__, __LINE__,
1341 _("finish_command: function has no target type"));
1343 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1344 print_return_value (SYMBOL_TYPE (a->function), value_type);
1347 /* We suppress normal call of normal_stop observer and do it here so
1348 that that *stopped notification includes the return value. */
1349 /* NOTE: This is broken in non-stop mode. There is no guarantee the
1350 next stop will be in the same thread that we started doing a
1351 finish on. This suppressing (or some other replacement means)
1352 should be a thread property. */
1353 observer_notify_normal_stop (bs);
1354 suppress_stop_observer = 0;
1355 delete_breakpoint (a->breakpoint);
1359 finish_command_continuation_free_arg (void *arg)
1361 /* NOTE: See finish_command_continuation. This would go away, if
1362 this suppressing is made a thread property. */
1363 suppress_stop_observer = 0;
1367 /* finish_backward -- helper function for finish_command. */
1370 finish_backward (struct symbol *function)
1372 struct symtab_and_line sal;
1373 struct thread_info *tp = inferior_thread ();
1374 struct breakpoint *breakpoint;
1375 struct cleanup *old_chain;
1376 CORE_ADDR func_addr;
1379 if (find_pc_partial_function (get_frame_pc (get_current_frame ()),
1380 NULL, &func_addr, NULL) == 0)
1381 internal_error (__FILE__, __LINE__,
1382 _("Finish: couldn't find function."));
1384 sal = find_pc_line (func_addr, 0);
1386 /* We don't need a return value. */
1387 tp->proceed_to_finish = 0;
1388 /* Special case: if we're sitting at the function entry point,
1389 then all we need to do is take a reverse singlestep. We
1390 don't need to set a breakpoint, and indeed it would do us
1393 Note that this can only happen at frame #0, since there's
1394 no way that a function up the stack can have a return address
1395 that's equal to its entry point. */
1397 if (sal.pc != read_pc ())
1399 /* Set breakpoint and continue. */
1401 set_momentary_breakpoint (sal,
1402 get_frame_id (get_selected_frame (NULL)),
1404 /* Tell the breakpoint to keep quiet. We won't be done
1405 until we've done another reverse single-step. */
1406 make_breakpoint_silent (breakpoint);
1407 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1408 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1409 /* We will be stopped when proceed returns. */
1410 back_up = bpstat_find_breakpoint (tp->stop_bpstat, breakpoint) != NULL;
1411 do_cleanups (old_chain);
1417 /* If in fact we hit the step-resume breakpoint (and not
1418 some other breakpoint), then we're almost there --
1419 we just need to back up by one more single-step. */
1420 tp->step_range_start = tp->step_range_end = 1;
1421 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1426 /* finish_forward -- helper function for finish_command. */
1429 finish_forward (struct symbol *function, struct frame_info *frame)
1431 struct symtab_and_line sal;
1432 struct thread_info *tp = inferior_thread ();
1433 struct breakpoint *breakpoint;
1434 struct cleanup *old_chain;
1435 struct finish_command_continuation_args *cargs;
1437 sal = find_pc_line (get_frame_pc (frame), 0);
1438 sal.pc = get_frame_pc (frame);
1440 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
1443 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1445 tp->proceed_to_finish = 1; /* We want stop_registers, please... */
1446 make_cleanup_restore_integer (&suppress_stop_observer);
1447 suppress_stop_observer = 1;
1448 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1450 cargs = xmalloc (sizeof (*cargs));
1452 cargs->breakpoint = breakpoint;
1453 cargs->function = function;
1454 add_continuation (tp, finish_command_continuation, cargs,
1455 finish_command_continuation_free_arg);
1457 discard_cleanups (old_chain);
1458 if (!target_can_async_p ())
1459 do_all_continuations ();
1462 /* "finish": Set a temporary breakpoint at the place the selected
1463 frame will return to, then continue. */
1466 finish_command (char *arg, int from_tty)
1468 struct frame_info *frame;
1469 struct symbol *function;
1473 /* Find out whether we must run in the background. */
1475 async_exec = strip_bg_char (&arg);
1477 /* If we must run in the background, but the target can't do it,
1479 if (async_exec && !target_can_async_p ())
1480 error (_("Asynchronous execution not supported on this target."));
1482 /* Don't try to async in reverse. */
1483 if (async_exec && execution_direction == EXEC_REVERSE)
1484 error (_("Asynchronous 'finish' not supported in reverse."));
1486 /* If we are not asked to run in the bg, then prepare to run in the
1487 foreground, synchronously. */
1488 if (!async_exec && target_can_async_p ())
1490 /* Simulate synchronous execution. */
1491 async_disable_stdin ();
1495 error (_("The \"finish\" command does not take any arguments."));
1496 if (!target_has_execution)
1497 error (_("The program is not running."));
1499 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1501 error (_("\"finish\" not meaningful in the outermost frame."));
1503 clear_proceed_status ();
1505 /* Find the function we will return from. */
1507 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1509 /* Print info on the selected frame, including level number but not
1513 if (execution_direction == EXEC_REVERSE)
1514 printf_filtered (_("Run back to call of "));
1516 printf_filtered (_("Run till exit from "));
1518 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1521 if (execution_direction == EXEC_REVERSE)
1522 finish_backward (function);
1524 finish_forward (function, frame);
1529 program_info (char *args, int from_tty)
1533 struct thread_info *tp;
1536 if (!target_has_execution)
1538 printf_filtered (_("The program being debugged is not being run.\n"));
1543 ptid = inferior_ptid;
1546 struct target_waitstatus ws;
1547 get_last_target_status (&ptid, &ws);
1550 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1551 error (_("Invalid selected thread."));
1552 else if (is_running (ptid))
1553 error (_("Selected thread is running."));
1555 tp = find_thread_pid (ptid);
1556 bs = tp->stop_bpstat;
1557 stat = bpstat_num (&bs, &num);
1559 target_files_info ();
1560 printf_filtered (_("Program stopped at %s.\n"),
1561 hex_string ((unsigned long) stop_pc));
1563 printf_filtered (_("It stopped after being stepped.\n"));
1566 /* There may be several breakpoints in the same place, so this
1567 isn't as strange as it seems. */
1572 printf_filtered (_("\
1573 It stopped at a breakpoint that has since been deleted.\n"));
1576 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1577 stat = bpstat_num (&bs, &num);
1580 else if (tp->stop_signal != TARGET_SIGNAL_0)
1582 printf_filtered (_("It stopped with signal %s, %s.\n"),
1583 target_signal_to_name (tp->stop_signal),
1584 target_signal_to_string (tp->stop_signal));
1589 printf_filtered (_("\
1590 Type \"info stack\" or \"info registers\" for more information.\n"));
1595 environment_info (char *var, int from_tty)
1599 char *val = get_in_environ (inferior_environ, var);
1602 puts_filtered (var);
1603 puts_filtered (" = ");
1604 puts_filtered (val);
1605 puts_filtered ("\n");
1609 puts_filtered ("Environment variable \"");
1610 puts_filtered (var);
1611 puts_filtered ("\" not defined.\n");
1616 char **vector = environ_vector (inferior_environ);
1619 puts_filtered (*vector++);
1620 puts_filtered ("\n");
1626 set_environment_command (char *arg, int from_tty)
1628 char *p, *val, *var;
1632 error_no_arg (_("environment variable and value"));
1634 /* Find seperation between variable name and value */
1635 p = (char *) strchr (arg, '=');
1636 val = (char *) strchr (arg, ' ');
1638 if (p != 0 && val != 0)
1640 /* We have both a space and an equals. If the space is before the
1641 equals, walk forward over the spaces til we see a nonspace
1642 (possibly the equals). */
1647 /* Now if the = is after the char following the spaces,
1648 take the char following the spaces. */
1652 else if (val != 0 && p == 0)
1656 error_no_arg (_("environment variable to set"));
1658 if (p == 0 || p[1] == 0)
1662 p = arg + strlen (arg); /* So that savestring below will work */
1666 /* Not setting variable value to null */
1668 while (*val == ' ' || *val == '\t')
1672 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1675 var = savestring (arg, p - arg);
1678 printf_filtered (_("\
1679 Setting environment variable \"%s\" to null value.\n"),
1681 set_in_environ (inferior_environ, var, "");
1684 set_in_environ (inferior_environ, var, val);
1689 unset_environment_command (char *var, int from_tty)
1693 /* If there is no argument, delete all environment variables.
1694 Ask for confirmation if reading from the terminal. */
1695 if (!from_tty || query (_("Delete all environment variables? ")))
1697 free_environ (inferior_environ);
1698 inferior_environ = make_environ ();
1702 unset_in_environ (inferior_environ, var);
1705 /* Handle the execution path (PATH variable) */
1707 static const char path_var_name[] = "PATH";
1710 path_info (char *args, int from_tty)
1712 puts_filtered ("Executable and object file path: ");
1713 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1714 puts_filtered ("\n");
1717 /* Add zero or more directories to the front of the execution path. */
1720 path_command (char *dirname, int from_tty)
1725 env = get_in_environ (inferior_environ, path_var_name);
1726 /* Can be null if path is not set */
1729 exec_path = xstrdup (env);
1730 mod_path (dirname, &exec_path);
1731 set_in_environ (inferior_environ, path_var_name, exec_path);
1734 path_info ((char *) NULL, from_tty);
1738 /* Print out the machine register regnum. If regnum is -1, print all
1739 registers (print_all == 1) or all non-float and non-vector
1740 registers (print_all == 0).
1742 For most machines, having all_registers_info() print the
1743 register(s) one per line is good enough. If a different format is
1744 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1745 regs), or there is an existing convention for showing all the
1746 registers, define the architecture method PRINT_REGISTERS_INFO to
1747 provide that format. */
1750 default_print_registers_info (struct gdbarch *gdbarch,
1751 struct ui_file *file,
1752 struct frame_info *frame,
1753 int regnum, int print_all)
1756 const int numregs = gdbarch_num_regs (gdbarch)
1757 + gdbarch_num_pseudo_regs (gdbarch);
1758 gdb_byte buffer[MAX_REGISTER_SIZE];
1760 for (i = 0; i < numregs; i++)
1762 /* Decide between printing all regs, non-float / vector regs, or
1768 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1773 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1783 /* If the register name is empty, it is undefined for this
1784 processor, so don't display anything. */
1785 if (gdbarch_register_name (gdbarch, i) == NULL
1786 || *(gdbarch_register_name (gdbarch, i)) == '\0')
1789 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1790 print_spaces_filtered (15 - strlen (gdbarch_register_name
1791 (gdbarch, i)), file);
1793 /* Get the data in raw format. */
1794 if (! frame_register_read (frame, i, buffer))
1796 fprintf_filtered (file, "*value not available*\n");
1800 /* If virtual format is floating, print it that way, and in raw
1802 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1803 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1807 val_print (register_type (gdbarch, i), buffer, 0, 0,
1808 file, 0, 1, 0, Val_pretty_default, current_language);
1810 fprintf_filtered (file, "\t(raw 0x");
1811 for (j = 0; j < register_size (gdbarch, i); j++)
1814 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1817 idx = register_size (gdbarch, i) - 1 - j;
1818 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1820 fprintf_filtered (file, ")");
1824 /* Print the register in hex. */
1825 val_print (register_type (gdbarch, i), buffer, 0, 0,
1826 file, 'x', 1, 0, Val_pretty_default, current_language);
1827 /* If not a vector register, print it also according to its
1829 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1831 fprintf_filtered (file, "\t");
1832 val_print (register_type (gdbarch, i), buffer, 0, 0,
1833 file, 0, 1, 0, Val_pretty_default, current_language);
1837 fprintf_filtered (file, "\n");
1842 registers_info (char *addr_exp, int fpregs)
1844 struct frame_info *frame;
1845 struct gdbarch *gdbarch;
1846 int regnum, numregs;
1849 if (!target_has_registers)
1850 error (_("The program has no registers now."));
1851 frame = get_selected_frame (NULL);
1852 gdbarch = get_frame_arch (frame);
1856 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1861 while (*addr_exp != '\0')
1866 /* Keep skipping leading white space. */
1867 if (isspace ((*addr_exp)))
1873 /* Discard any leading ``$''. Check that there is something
1874 resembling a register following it. */
1875 if (addr_exp[0] == '$')
1877 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1878 error (_("Missing register name"));
1880 /* Find the start/end of this register name/num/group. */
1882 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1886 /* Figure out what we've found and display it. */
1888 /* A register name? */
1890 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
1893 /* User registers lie completely outside of the range of
1894 normal registers. Catch them early so that the target
1896 if (regnum >= gdbarch_num_regs (gdbarch)
1897 + gdbarch_num_pseudo_regs (gdbarch))
1899 struct value *val = value_of_user_reg (regnum, frame);
1901 printf_filtered ("%s: ", start);
1902 print_scalar_formatted (value_contents (val),
1903 check_typedef (value_type (val)),
1904 'x', 0, gdb_stdout);
1905 printf_filtered ("\n");
1908 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1909 frame, regnum, fpregs);
1914 /* A register number? (how portable is this one?). */
1917 int regnum = strtol (start, &endptr, 0);
1920 && regnum < gdbarch_num_regs (gdbarch)
1921 + gdbarch_num_pseudo_regs (gdbarch))
1923 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1924 frame, regnum, fpregs);
1929 /* A register group? */
1931 struct reggroup *group;
1932 for (group = reggroup_next (gdbarch, NULL);
1934 group = reggroup_next (gdbarch, group))
1936 /* Don't bother with a length check. Should the user
1937 enter a short register group name, go with the first
1938 group that matches. */
1939 if (strncmp (start, reggroup_name (group), end - start) == 0)
1946 regnum < gdbarch_num_regs (gdbarch)
1947 + gdbarch_num_pseudo_regs (gdbarch);
1950 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1951 gdbarch_print_registers_info (gdbarch,
1959 /* Nothing matched. */
1960 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1965 all_registers_info (char *addr_exp, int from_tty)
1967 registers_info (addr_exp, 1);
1971 nofp_registers_info (char *addr_exp, int from_tty)
1973 registers_info (addr_exp, 0);
1977 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1978 struct frame_info *frame, const char *args)
1980 if (gdbarch_print_vector_info_p (gdbarch))
1981 gdbarch_print_vector_info (gdbarch, file, frame, args);
1985 int printed_something = 0;
1988 regnum < gdbarch_num_regs (gdbarch)
1989 + gdbarch_num_pseudo_regs (gdbarch);
1992 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1994 printed_something = 1;
1995 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1998 if (!printed_something)
1999 fprintf_filtered (file, "No vector information\n");
2004 vector_info (char *args, int from_tty)
2006 if (!target_has_registers)
2007 error (_("The program has no registers now."));
2009 print_vector_info (current_gdbarch, gdb_stdout,
2010 get_selected_frame (NULL), args);
2016 * Should save/restore the tty state since it might be that the
2017 * program to be debugged was started on this tty and it wants
2018 * the tty in some state other than what we want. If it's running
2019 * on another terminal or without a terminal, then saving and
2020 * restoring the tty state is a harmless no-op.
2021 * This only needs to be done if we are attaching to a process.
2026 takes a program started up outside of gdb and ``attaches'' to it.
2027 This stops it cold in its tracks and allows us to start debugging it.
2028 and wait for the trace-trap that results from attaching. */
2031 attach_command_post_wait (char *args, int from_tty, int async_exec)
2034 char *full_exec_path = NULL;
2035 struct inferior *inferior;
2037 inferior = current_inferior ();
2038 inferior->stop_soon = NO_STOP_QUIETLY;
2040 /* If no exec file is yet known, try to determine it from the
2042 exec_file = (char *) get_exec_file (0);
2045 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
2048 /* It's possible we don't have a full path, but rather just a
2049 filename. Some targets, such as HP-UX, don't provide the
2052 Attempt to qualify the filename against the source path.
2053 (If that fails, we'll just fall back on the original
2054 filename. Not much more we can do...)
2056 if (!source_full_path_of (exec_file, &full_exec_path))
2057 full_exec_path = savestring (exec_file, strlen (exec_file));
2059 exec_file_attach (full_exec_path, from_tty);
2060 symbol_file_add_main (full_exec_path, from_tty);
2065 reopen_exec_file ();
2069 /* Take any necessary post-attaching actions for this platform. */
2070 target_post_attach (PIDGET (inferior_ptid));
2072 post_create_inferior (¤t_target, from_tty);
2074 /* Install inferior's terminal modes. */
2075 target_terminal_inferior ();
2078 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
2081 if (target_can_async_p ())
2082 async_enable_stdin ();
2084 if (deprecated_attach_hook)
2085 deprecated_attach_hook ();
2089 struct attach_command_continuation_args
2097 attach_command_continuation (void *args)
2099 struct attach_command_continuation_args *a = args;
2100 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2104 attach_command_continuation_free_args (void *args)
2106 struct attach_command_continuation_args *a = args;
2112 attach_command (char *args, int from_tty)
2115 char *full_exec_path = NULL;
2118 dont_repeat (); /* Not for the faint of heart */
2120 if (target_has_execution)
2122 if (query ("A program is being debugged already. Kill it? "))
2125 error (_("Not killed."));
2128 /* Clean up any leftovers from other runs. Some other things from
2129 this function should probably be moved into target_pre_inferior. */
2130 target_pre_inferior (from_tty);
2132 if (non_stop && !target_supports_non_stop ())
2133 error (_("Cannot attach to this target in non-stop mode"));
2137 async_exec = strip_bg_char (&args);
2139 /* If we get a request for running in the bg but the target
2140 doesn't support it, error out. */
2141 if (async_exec && !target_can_async_p ())
2142 error (_("Asynchronous execution not supported on this target."));
2145 /* If we don't get a request of running in the bg, then we need
2146 to simulate synchronous (fg) execution. */
2147 if (!async_exec && target_can_async_p ())
2149 /* Simulate synchronous execution */
2150 async_disable_stdin ();
2153 target_attach (args, from_tty);
2155 /* Set up the "saved terminal modes" of the inferior
2156 based on what modes we are starting it with. */
2157 target_terminal_init ();
2159 /* Set up execution context to know that we should return from
2160 wait_for_inferior as soon as the target reports a stop. */
2161 init_wait_for_inferior ();
2162 clear_proceed_status ();
2164 /* Some system don't generate traps when attaching to inferior.
2165 E.g. Mach 3 or GNU hurd. */
2166 if (!target_attach_no_wait)
2168 struct inferior *inferior = current_inferior ();
2170 /* Careful here. See comments in inferior.h. Basically some
2171 OSes don't ignore SIGSTOPs on continue requests anymore. We
2172 need a way for handle_inferior_event to reset the stop_signal
2173 variable after an attach, and this is what
2174 STOP_QUIETLY_NO_SIGSTOP is for. */
2175 inferior->stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2177 if (target_can_async_p ())
2179 /* sync_execution mode. Wait for stop. */
2180 struct attach_command_continuation_args *a;
2182 a = xmalloc (sizeof (*a));
2183 a->args = xstrdup (args);
2184 a->from_tty = from_tty;
2185 a->async_exec = async_exec;
2186 add_continuation (inferior_thread (),
2187 attach_command_continuation, a,
2188 attach_command_continuation_free_args);
2192 wait_for_inferior (0);
2195 attach_command_post_wait (args, from_tty, async_exec);
2200 * takes a program previously attached to and detaches it.
2201 * The program resumes execution and will no longer stop
2202 * on signals, etc. We better not have left any breakpoints
2203 * in the program or it'll die when it hits one. For this
2204 * to work, it may be necessary for the process to have been
2205 * previously attached. It *might* work if the program was
2206 * started via the normal ptrace (PTRACE_TRACEME).
2210 detach_command (char *args, int from_tty)
2212 dont_repeat (); /* Not for the faint of heart. */
2213 target_detach (args, from_tty);
2214 no_shared_libraries (NULL, from_tty);
2215 init_thread_list ();
2216 if (deprecated_detach_hook)
2217 deprecated_detach_hook ();
2220 /* Disconnect from the current target without resuming it (leaving it
2221 waiting for a debugger).
2223 We'd better not have left any breakpoints in the program or the
2224 next debugger will get confused. Currently only supported for some
2225 remote targets, since the normal attach mechanisms don't work on
2226 stopped processes on some native platforms (e.g. GNU/Linux). */
2229 disconnect_command (char *args, int from_tty)
2231 dont_repeat (); /* Not for the faint of heart */
2232 target_disconnect (args, from_tty);
2233 no_shared_libraries (NULL, from_tty);
2234 init_thread_list ();
2235 if (deprecated_detach_hook)
2236 deprecated_detach_hook ();
2240 interrupt_target_1 (int all_threads)
2244 ptid = minus_one_ptid;
2246 ptid = inferior_ptid;
2249 /* Tag the thread as having been explicitly requested to stop, so
2250 other parts of gdb know not to resume this thread automatically,
2251 if it was stopped due to an internal event. Limit this to
2252 non-stop mode, as when debugging a multi-threaded application in
2253 all-stop mode, we will only get one stop event --- it's undefined
2254 which thread will report the event. */
2256 set_stop_requested (ptid, 1);
2259 /* Stop the execution of the target while running in async mode, in
2260 the backgound. In all-stop, stop the whole process. In non-stop
2261 mode, stop the current thread only by default, or stop all threads
2262 if the `-a' switch is used. */
2264 /* interrupt [-a] */
2266 interrupt_target_command (char *args, int from_tty)
2268 if (target_can_async_p ())
2270 int all_threads = 0;
2272 dont_repeat (); /* Not for the faint of heart */
2275 && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
2278 if (!non_stop && all_threads)
2279 error (_("-a is meaningless in all-stop mode."));
2281 interrupt_target_1 (all_threads);
2286 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2287 struct frame_info *frame, const char *args)
2289 if (gdbarch_print_float_info_p (gdbarch))
2290 gdbarch_print_float_info (gdbarch, file, frame, args);
2294 int printed_something = 0;
2297 regnum < gdbarch_num_regs (gdbarch)
2298 + gdbarch_num_pseudo_regs (gdbarch);
2301 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2303 printed_something = 1;
2304 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2307 if (!printed_something)
2308 fprintf_filtered (file, "\
2309 No floating-point info available for this processor.\n");
2314 float_info (char *args, int from_tty)
2316 if (!target_has_registers)
2317 error (_("The program has no registers now."));
2319 print_float_info (current_gdbarch, gdb_stdout,
2320 get_selected_frame (NULL), args);
2324 unset_command (char *args, int from_tty)
2326 printf_filtered (_("\
2327 \"unset\" must be followed by the name of an unset subcommand.\n"));
2328 help_list (unsetlist, "unset ", -1, gdb_stdout);
2332 _initialize_infcmd (void)
2334 struct cmd_list_element *c = NULL;
2336 /* add the filename of the terminal connected to inferior I/O */
2337 add_setshow_filename_cmd ("inferior-tty", class_run,
2338 &inferior_io_terminal, _("\
2339 Set terminal for future runs of program being debugged."), _("\
2340 Show terminal for future runs of program being debugged."), _("\
2341 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2342 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2344 add_setshow_optional_filename_cmd ("args", class_run,
2345 &inferior_args, _("\
2346 Set argument list to give program being debugged when it is started."), _("\
2347 Show argument list to give program being debugged when it is started."), _("\
2348 Follow this command with any number of args, to be passed to the program."),
2351 &setlist, &showlist);
2353 c = add_cmd ("environment", no_class, environment_info, _("\
2354 The environment to give the program, or one variable's value.\n\
2355 With an argument VAR, prints the value of environment variable VAR to\n\
2356 give the program being debugged. With no arguments, prints the entire\n\
2357 environment to be given to the program."), &showlist);
2358 set_cmd_completer (c, noop_completer);
2360 add_prefix_cmd ("unset", no_class, unset_command,
2361 _("Complement to certain \"set\" commands."),
2362 &unsetlist, "unset ", 0, &cmdlist);
2364 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2365 Cancel environment variable VAR for the program.\n\
2366 This does not affect the program until the next \"run\" command."),
2368 set_cmd_completer (c, noop_completer);
2370 c = add_cmd ("environment", class_run, set_environment_command, _("\
2371 Set environment variable value to give the program.\n\
2372 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2373 VALUES of environment variables are uninterpreted strings.\n\
2374 This does not affect the program until the next \"run\" command."),
2376 set_cmd_completer (c, noop_completer);
2378 c = add_com ("path", class_files, path_command, _("\
2379 Add directory DIR(s) to beginning of search path for object files.\n\
2380 $cwd in the path means the current working directory.\n\
2381 This path is equivalent to the $PATH shell variable. It is a list of\n\
2382 directories, separated by colons. These directories are searched to find\n\
2383 fully linked executable files and separately compiled object files as needed."));
2384 set_cmd_completer (c, filename_completer);
2386 c = add_cmd ("paths", no_class, path_info, _("\
2387 Current search path for finding object files.\n\
2388 $cwd in the path means the current working directory.\n\
2389 This path is equivalent to the $PATH shell variable. It is a list of\n\
2390 directories, separated by colons. These directories are searched to find\n\
2391 fully linked executable files and separately compiled object files as needed."),
2393 set_cmd_completer (c, noop_completer);
2395 add_com ("attach", class_run, attach_command, _("\
2396 Attach to a process or file outside of GDB.\n\
2397 This command attaches to another target, of the same type as your last\n\
2398 \"target\" command (\"info files\" will show your target stack).\n\
2399 The command may take as argument a process id or a device file.\n\
2400 For a process id, you must have permission to send the process a signal,\n\
2401 and it must have the same effective uid as the debugger.\n\
2402 When using \"attach\" with a process id, the debugger finds the\n\
2403 program running in the process, looking first in the current working\n\
2404 directory, or (if not found there) using the source file search path\n\
2405 (see the \"directory\" command). You can also use the \"file\" command\n\
2406 to specify the program, and to load its symbol table."));
2408 add_prefix_cmd ("detach", class_run, detach_command, _("\
2409 Detach a process or file previously attached.\n\
2410 If a process, it is no longer traced, and it continues its execution. If\n\
2411 you were debugging a file, the file is closed and gdb no longer accesses it."),
2412 &detachlist, "detach ", 0, &cmdlist);
2414 add_com ("disconnect", class_run, disconnect_command, _("\
2415 Disconnect from a target.\n\
2416 The target will wait for another debugger to connect. Not available for\n\
2419 add_com ("signal", class_run, signal_command, _("\
2420 Continue program giving it signal specified by the argument.\n\
2421 An argument of \"0\" means continue program without giving it a signal."));
2423 add_com ("stepi", class_run, stepi_command, _("\
2424 Step one instruction exactly.\n\
2425 Argument N means do this N times (or till program stops for another reason)."));
2426 add_com_alias ("si", "stepi", class_alias, 0);
2428 add_com ("nexti", class_run, nexti_command, _("\
2429 Step one instruction, but proceed through subroutine calls.\n\
2430 Argument N means do this N times (or till program stops for another reason)."));
2431 add_com_alias ("ni", "nexti", class_alias, 0);
2433 add_com ("finish", class_run, finish_command, _("\
2434 Execute until selected stack frame returns.\n\
2435 Upon return, the value returned is printed and put in the value history."));
2436 add_com_alias ("fin", "finish", class_run, 1);
2438 add_com ("next", class_run, next_command, _("\
2439 Step program, proceeding through subroutine calls.\n\
2440 Like the \"step\" command as long as subroutine calls do not happen;\n\
2441 when they do, the call is treated as one instruction.\n\
2442 Argument N means do this N times (or till program stops for another reason)."));
2443 add_com_alias ("n", "next", class_run, 1);
2445 add_com_alias ("S", "next", class_run, 1);
2447 add_com ("step", class_run, step_command, _("\
2448 Step program until it reaches a different source line.\n\
2449 Argument N means do this N times (or till program stops for another reason)."));
2450 add_com_alias ("s", "step", class_run, 1);
2452 c = add_com ("until", class_run, until_command, _("\
2453 Execute until the program reaches a source line greater than the current\n\
2454 or a specified location (same args as break command) within the current frame."));
2455 set_cmd_completer (c, location_completer);
2456 add_com_alias ("u", "until", class_run, 1);
2458 c = add_com ("advance", class_run, advance_command, _("\
2459 Continue the program up to the given location (same form as args for break command).\n\
2460 Execution will also stop upon exit from the current stack frame."));
2461 set_cmd_completer (c, location_completer);
2463 c = add_com ("jump", class_run, jump_command, _("\
2464 Continue program being debugged at specified line or address.\n\
2465 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2466 for an address to start at."));
2467 set_cmd_completer (c, location_completer);
2471 c = add_com ("go", class_run, go_command, _("\
2472 Usage: go <location>\n\
2473 Continue program being debugged, stopping at specified line or \n\
2475 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2476 expression for an address to start at.\n\
2477 This command is a combination of tbreak and jump."));
2478 set_cmd_completer (c, location_completer);
2482 add_com_alias ("g", "go", class_run, 1);
2484 c = add_com ("continue", class_run, continue_command, _("\
2485 Continue program being debugged, after signal or breakpoint.\n\
2486 If proceeding from breakpoint, a number N may be used as an argument,\n\
2487 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2488 the breakpoint won't break until the Nth time it is reached).\n\
2490 If non-stop mode is enabled, continue only the current thread,\n\
2491 otherwise all the threads in the program are continued. To \n\
2492 continue all stopped threads in non-stop mode, use the -a option.\n\
2493 Specifying -a and an ignore count simultaneously is an error."));
2494 add_com_alias ("c", "cont", class_run, 1);
2495 add_com_alias ("fg", "cont", class_run, 1);
2497 c = add_com ("run", class_run, run_command, _("\
2498 Start debugged program. You may specify arguments to give it.\n\
2499 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2500 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2501 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2502 To cancel previous arguments and run with no arguments,\n\
2503 use \"set args\" without arguments."));
2504 set_cmd_completer (c, filename_completer);
2505 add_com_alias ("r", "run", class_run, 1);
2507 add_com ("R", class_run, run_no_args_command,
2508 _("Start debugged program with no arguments."));
2510 c = add_com ("start", class_run, start_command, _("\
2511 Run the debugged program until the beginning of the main procedure.\n\
2512 You may specify arguments to give to your program, just as with the\n\
2513 \"run\" command."));
2514 set_cmd_completer (c, filename_completer);
2516 c = add_com ("interrupt", class_run, interrupt_target_command,
2517 _("Interrupt the execution of the debugged program.\n\
2518 If non-stop mode is enabled, interrupt only the current thread,\n\
2519 otherwise all the threads in the program are stopped. To \n\
2520 interrupt all running threads in non-stop mode, use the -a option."));
2522 add_info ("registers", nofp_registers_info, _("\
2523 List of integer registers and their contents, for selected stack frame.\n\
2524 Register name as argument means describe only that register."));
2525 add_info_alias ("r", "registers", 1);
2528 add_com ("lr", class_info, nofp_registers_info, _("\
2529 List of integer registers and their contents, for selected stack frame.\n\
2530 Register name as argument means describe only that register."));
2531 add_info ("all-registers", all_registers_info, _("\
2532 List of all registers and their contents, for selected stack frame.\n\
2533 Register name as argument means describe only that register."));
2535 add_info ("program", program_info,
2536 _("Execution status of the program."));
2538 add_info ("float", float_info,
2539 _("Print the status of the floating point unit\n"));
2541 add_info ("vector", vector_info,
2542 _("Print the status of the vector unit\n"));
2544 inferior_environ = make_environ ();
2545 init_environ (inferior_environ);