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 finish_command_continuation (struct continuation_arg *,
79 static void until_next_command (int);
81 static void until_command (char *, int);
83 static void path_info (char *, int);
85 static void path_command (char *, int);
87 static void unset_command (char *, int);
89 static void float_info (char *, int);
91 static void detach_command (char *, int);
93 static void disconnect_command (char *, int);
95 static void unset_environment_command (char *, int);
97 static void set_environment_command (char *, int);
99 static void environment_info (char *, int);
101 static void program_info (char *, int);
103 static void finish_command (char *, int);
105 static void signal_command (char *, int);
107 static void jump_command (char *, int);
109 static void step_1 (int, int, char *);
110 static void step_once (int skip_subroutines, int single_inst, int count, int thread);
111 static void step_1_continuation (struct continuation_arg *arg, int error_p);
113 static void next_command (char *, int);
115 static void step_command (char *, int);
117 static void run_command (char *, int);
119 static void run_no_args_command (char *args, int from_tty);
121 static void go_command (char *line_no, int from_tty);
123 static int strip_bg_char (char **);
125 void _initialize_infcmd (void);
127 #define GO_USAGE "Usage: go <location>\n"
129 #define ERROR_NO_INFERIOR \
130 if (!target_has_execution) error (_("The program is not being run."));
132 /* String containing arguments to give to the program, separated by spaces.
133 Empty string (pointer to '\0') means no args. */
135 static char *inferior_args;
137 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
138 then we must compute INFERIOR_ARGS from this (via the target). */
140 static int inferior_argc;
141 static char **inferior_argv;
143 /* File name for default use for standard in/out in the inferior. */
145 static char *inferior_io_terminal;
147 /* Pid of our debugged inferior, or 0 if no inferior now.
148 Since various parts of infrun.c test this to see whether there is a program
149 being debugged it should be nonzero (currently 3 is used) for remote
152 ptid_t inferior_ptid;
154 /* Last signal that the inferior received (why it stopped). */
156 enum target_signal stop_signal;
158 /* Address at which inferior stopped. */
162 /* Chain containing status of breakpoint(s) that we have stopped at. */
166 /* Flag indicating that a command has proceeded the inferior past the
167 current breakpoint. */
169 int breakpoint_proceeded;
171 /* Nonzero if stopped due to a step command. */
175 /* Nonzero if stopped due to completion of a stack dummy routine. */
177 int stop_stack_dummy;
179 /* Nonzero if stopped due to a random (unexpected) signal in inferior
182 int stopped_by_random_signal;
184 /* Range to single step within.
185 If this is nonzero, respond to a single-step signal
186 by continuing to step if the pc is in this range. */
188 CORE_ADDR step_range_start; /* Inclusive */
189 CORE_ADDR step_range_end; /* Exclusive */
191 /* Stack frame address as of when stepping command was issued.
192 This is how we know when we step into a subroutine call,
193 and how to set the frame for the breakpoint used to step out. */
195 struct frame_id step_frame_id;
197 enum step_over_calls_kind step_over_calls;
199 /* If stepping, nonzero means step count is > 1
200 so don't print frame next time inferior stops
201 if it stops due to stepping. */
205 /* Environment to use for running inferior,
206 in format described in environ.h. */
208 struct gdb_environ *inferior_environ;
210 /* When set, normal_stop will not call the normal_stop observer. */
211 int suppress_normal_stop_observer = 0;
213 /* Accessor routines. */
216 set_inferior_io_terminal (const char *terminal_name)
218 if (inferior_io_terminal)
219 xfree (inferior_io_terminal);
222 inferior_io_terminal = NULL;
224 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
228 get_inferior_io_terminal (void)
230 return inferior_io_terminal;
234 get_inferior_args (void)
236 if (inferior_argc != 0)
240 n = gdbarch_construct_inferior_arguments (current_gdbarch,
241 inferior_argc, inferior_argv);
242 old = set_inferior_args (n);
246 if (inferior_args == NULL)
247 inferior_args = xstrdup ("");
249 return inferior_args;
253 set_inferior_args (char *newargs)
255 char *saved_args = inferior_args;
257 inferior_args = newargs;
265 set_inferior_args_vector (int argc, char **argv)
267 inferior_argc = argc;
268 inferior_argv = argv;
271 /* Notice when `set args' is run. */
273 notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
279 /* Notice when `show args' is run. */
281 notice_args_read (struct ui_file *file, int from_tty,
282 struct cmd_list_element *c, const char *value)
284 /* Note that we ignore the passed-in value in favor of computing it
286 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
290 /* Compute command-line string given argument vector. This does the
291 same shell processing as fork_inferior. */
293 construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
297 if (STARTUP_WITH_SHELL)
299 /* This holds all the characters considered special to the
300 typical Unix shells. We include `^' because the SunOS
301 /bin/sh treats it as a synonym for `|'. */
302 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
307 /* We over-compute the size. It shouldn't matter. */
308 for (i = 0; i < argc; ++i)
309 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
311 result = (char *) xmalloc (length);
314 for (i = 0; i < argc; ++i)
319 /* Need to handle empty arguments specially. */
320 if (argv[i][0] == '\0')
327 for (cp = argv[i]; *cp; ++cp)
329 if (strchr (special, *cp) != NULL)
339 /* In this case we can't handle arguments that contain spaces,
340 tabs, or newlines -- see breakup_args(). */
344 for (i = 0; i < argc; ++i)
346 char *cp = strchr (argv[i], ' ');
348 cp = strchr (argv[i], '\t');
350 cp = strchr (argv[i], '\n');
352 error (_("can't handle command-line argument containing whitespace"));
353 length += strlen (argv[i]) + 1;
356 result = (char *) xmalloc (length);
358 for (i = 0; i < argc; ++i)
361 strcat (result, " ");
362 strcat (result, argv[i]);
370 /* This function detects whether or not a '&' character (indicating
371 background execution) has been added as *the last* of the arguments ARGS
372 of a command. If it has, it removes it and returns 1. Otherwise it
373 does nothing and returns 0. */
375 strip_bg_char (char **args)
379 p = strchr (*args, '&');
383 if (p == (*args + strlen (*args) - 1))
385 if (strlen (*args) > 1)
389 while (*p == ' ' || *p == '\t');
401 tty_command (char *file, int from_tty)
404 error_no_arg (_("terminal name for running target process"));
406 set_inferior_io_terminal (file);
409 /* Common actions to take after creating any sort of inferior, by any
410 means (running, attaching, connecting, et cetera). The target
411 should be stopped. */
414 post_create_inferior (struct target_ops *target, int from_tty)
416 /* Be sure we own the terminal in case write operations are performed. */
417 target_terminal_ours ();
419 /* If the target hasn't taken care of this already, do it now.
420 Targets which need to access registers during to_open,
421 to_create_inferior, or to_attach should do it earlier; but many
423 target_find_description ();
427 /* Sometimes the platform-specific hook loads initial shared
428 libraries, and sometimes it doesn't. Try to do so first, so
429 that we can add them with the correct value for FROM_TTY.
430 If we made all the inferior hook methods consistent,
431 this call could be removed. */
433 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
435 solib_add (NULL, from_tty, target, auto_solib_add);
438 /* Create the hooks to handle shared library load and unload
440 #ifdef SOLIB_CREATE_INFERIOR_HOOK
441 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
443 solib_create_inferior_hook ();
447 observer_notify_inferior_created (target, from_tty);
450 /* Kill the inferior if already running. This function is designed
451 to be called when we are about to start the execution of the program
452 from the beginning. Ask the user to confirm that he wants to restart
453 the program being debugged when FROM_TTY is non-null. */
456 kill_if_already_running (int from_tty)
458 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
460 /* Bail out before killing the program if we will not be able to
462 target_require_runnable ();
465 && !query ("The program being debugged has been started already.\n\
466 Start it from the beginning? "))
467 error (_("Program not restarted."));
469 no_shared_libraries (NULL, from_tty);
470 init_wait_for_inferior ();
474 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
475 a temporary breakpoint at the begining of the main program before
476 running the program. */
479 run_command_1 (char *args, int from_tty, int tbreak_at_main)
485 kill_if_already_running (from_tty);
486 clear_breakpoint_hit_counts ();
488 /* Clean up any leftovers from other runs. Some other things from
489 this function should probably be moved into target_pre_inferior. */
490 target_pre_inferior (from_tty);
492 /* Purge old solib objfiles. */
493 objfile_purge_solibs ();
497 /* The comment here used to read, "The exec file is re-read every
498 time we do a generic_mourn_inferior, so we just have to worry
499 about the symbol file." The `generic_mourn_inferior' function
500 gets called whenever the program exits. However, suppose the
501 program exits, and *then* the executable file changes? We need
502 to check again here. Since reopen_exec_file doesn't do anything
503 if the timestamp hasn't changed, I don't see the harm. */
507 /* Insert the temporary breakpoint if a location was specified. */
509 tbreak_command (main_name (), 0);
511 exec_file = (char *) get_exec_file (0);
513 /* We keep symbols from add-symbol-file, on the grounds that the
514 user might want to add some symbols before running the program
515 (right?). But sometimes (dynamic loading where the user manually
516 introduces the new symbols with add-symbol-file), the code which
517 the symbols describe does not persist between runs. Currently
518 the user has to manually nuke all symbols between runs if they
519 want them to go away (PR 2207). This is probably reasonable. */
523 if (target_can_async_p ())
524 async_disable_stdin ();
528 int async_exec = strip_bg_char (&args);
530 /* If we get a request for running in the bg but the target
531 doesn't support it, error out. */
532 if (async_exec && !target_can_async_p ())
533 error (_("Asynchronous execution not supported on this target."));
535 /* If we don't get a request of running in the bg, then we need
536 to simulate synchronous (fg) execution. */
537 if (!async_exec && target_can_async_p ())
539 /* Simulate synchronous execution */
540 async_disable_stdin ();
543 /* If there were other args, beside '&', process them. */
546 char *old_args = set_inferior_args (xstrdup (args));
553 ui_out_field_string (uiout, NULL, "Starting program");
554 ui_out_text (uiout, ": ");
556 ui_out_field_string (uiout, "execfile", exec_file);
557 ui_out_spaces (uiout, 1);
558 /* We call get_inferior_args() because we might need to compute
560 ui_out_field_string (uiout, "infargs", get_inferior_args ());
561 ui_out_text (uiout, "\n");
562 ui_out_flush (uiout);
565 /* We call get_inferior_args() because we might need to compute
567 target_create_inferior (exec_file, get_inferior_args (),
568 environ_vector (inferior_environ), from_tty);
570 /* Pass zero for FROM_TTY, because at this point the "run" command
571 has done its thing; now we are setting up the running program. */
572 post_create_inferior (¤t_target, 0);
574 /* Start the target running. */
575 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
580 run_command (char *args, int from_tty)
582 run_command_1 (args, from_tty, 0);
586 run_no_args_command (char *args, int from_tty)
588 char *old_args = set_inferior_args (xstrdup (""));
593 /* Start the execution of the program up until the beginning of the main
597 start_command (char *args, int from_tty)
599 /* Some languages such as Ada need to search inside the program
600 minimal symbols for the location where to put the temporary
601 breakpoint before starting. */
602 if (!have_minimal_symbols ())
603 error (_("No symbol table loaded. Use the \"file\" command."));
605 /* Run the program until reaching the main procedure... */
606 run_command_1 (args, from_tty, 1);
610 continue_command (char *proc_count_exp, int from_tty)
615 /* Find out whether we must run in the background. */
616 if (proc_count_exp != NULL)
617 async_exec = strip_bg_char (&proc_count_exp);
619 /* If we must run in the background, but the target can't do it,
621 if (async_exec && !target_can_async_p ())
622 error (_("Asynchronous execution not supported on this target."));
624 /* If we are not asked to run in the bg, then prepare to run in the
625 foreground, synchronously. */
626 if (!async_exec && target_can_async_p ())
628 /* Simulate synchronous execution */
629 async_disable_stdin ();
632 /* If have argument (besides '&'), set proceed count of breakpoint
634 if (proc_count_exp != NULL)
636 bpstat bs = stop_bpstat;
640 while ((stat = bpstat_num (&bs, &num)) != 0)
643 set_ignore_count (num,
644 parse_and_eval_long (proc_count_exp) - 1,
646 /* set_ignore_count prints a message ending with a period.
647 So print two spaces before "Continuing.". */
649 printf_filtered (" ");
653 if (!stopped && from_tty)
656 ("Not stopped at any breakpoint; argument ignored.\n");
661 printf_filtered (_("Continuing.\n"));
663 clear_proceed_status ();
665 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
668 /* Step until outside of current statement. */
671 step_command (char *count_string, int from_tty)
673 step_1 (0, 0, count_string);
676 /* Likewise, but skip over subroutine calls as if single instructions. */
679 next_command (char *count_string, int from_tty)
681 step_1 (1, 0, count_string);
684 /* Likewise, but step only one instruction. */
687 stepi_command (char *count_string, int from_tty)
689 step_1 (0, 1, count_string);
693 nexti_command (char *count_string, int from_tty)
695 step_1 (1, 1, count_string);
699 delete_longjmp_breakpoint_cleanup (void *arg)
701 int thread = * (int *) arg;
702 delete_longjmp_breakpoint (thread);
706 step_1 (int skip_subroutines, int single_inst, char *count_string)
709 struct frame_info *frame;
710 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
717 async_exec = strip_bg_char (&count_string);
719 /* If we get a request for running in the bg but the target
720 doesn't support it, error out. */
721 if (async_exec && !target_can_async_p ())
722 error (_("Asynchronous execution not supported on this target."));
724 /* If we don't get a request of running in the bg, then we need
725 to simulate synchronous (fg) execution. */
726 if (!async_exec && target_can_async_p ())
728 /* Simulate synchronous execution */
729 async_disable_stdin ();
732 count = count_string ? parse_and_eval_long (count_string) : 1;
734 if (!single_inst || skip_subroutines) /* leave si command alone */
736 if (in_thread_list (inferior_ptid))
737 thread = pid_to_thread_id (inferior_ptid);
739 set_longjmp_breakpoint ();
741 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
744 /* In synchronous case, all is well, just use the regular for loop. */
745 if (!target_can_async_p ())
747 for (; count > 0; count--)
749 clear_proceed_status ();
751 frame = get_current_frame ();
752 if (!frame) /* Avoid coredump here. Why tho? */
753 error (_("No current frame"));
754 step_frame_id = get_frame_id (frame);
758 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
759 if (step_range_end == 0)
762 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
763 &step_range_end) == 0)
764 error (_("Cannot find bounds of current function"));
766 target_terminal_ours ();
767 printf_filtered (_("\
768 Single stepping until exit from function %s, \n\
769 which has no line number information.\n"), name);
774 /* Say we are stepping, but stop after one insn whatever it does. */
775 step_range_start = step_range_end = 1;
776 if (!skip_subroutines)
778 Don't step over function calls, not even to functions lacking
780 step_over_calls = STEP_OVER_NONE;
783 if (skip_subroutines)
784 step_over_calls = STEP_OVER_ALL;
786 step_multi = (count > 1);
787 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
793 do_cleanups (cleanups);
796 /* In case of asynchronous target things get complicated, do only
797 one step for now, before returning control to the event loop. Let
798 the continuation figure out how many other steps we need to do,
799 and handle them one at the time, through step_once(). */
802 step_once (skip_subroutines, single_inst, count, thread);
803 /* We are running, and the continuation is installed. It will
804 disable the longjmp breakpoint as appropriate. */
805 discard_cleanups (cleanups);
809 /* Called after we are done with one step operation, to check whether
810 we need to step again, before we print the prompt and return control
811 to the user. If count is > 1, we will need to do one more call to
812 proceed(), via step_once(). Basically it is like step_once and
813 step_1_continuation are co-recursive. */
815 step_1_continuation (struct continuation_arg *arg, int error_p)
818 int skip_subroutines;
822 skip_subroutines = arg->data.integer;
823 single_inst = arg->next->data.integer;
824 count = arg->next->next->data.integer;
825 thread = arg->next->next->next->data.integer;
827 if (error_p || !step_multi || !stop_step)
829 /* We either hit an error, or stopped for some reason
830 that is not stepping, or there are no further steps
832 if (!single_inst || skip_subroutines)
833 delete_longjmp_breakpoint (thread);
837 step_once (skip_subroutines, single_inst, count - 1, thread);
840 /* Do just one step operation. If count >1 we will have to set up a
841 continuation to be done after the target stops (after this one
842 step). This is useful to implement the 'step n' kind of commands, in
843 case of asynchronous targets. We had to split step_1 into two parts,
844 one to be done before proceed() and one afterwards. This function is
845 called in case of step n with n>1, after the first step operation has
848 step_once (int skip_subroutines, int single_inst, int count, int thread)
850 struct continuation_arg *arg1;
851 struct continuation_arg *arg2;
852 struct continuation_arg *arg3;
853 struct continuation_arg *arg4;
854 struct frame_info *frame;
858 clear_proceed_status ();
860 frame = get_current_frame ();
861 if (!frame) /* Avoid coredump here. Why tho? */
862 error (_("No current frame"));
863 step_frame_id = get_frame_id (frame);
867 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
869 /* If we have no line info, switch to stepi mode. */
870 if (step_range_end == 0 && step_stop_if_no_debug)
872 step_range_start = step_range_end = 1;
874 else if (step_range_end == 0)
877 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
878 &step_range_end) == 0)
879 error (_("Cannot find bounds of current function"));
881 target_terminal_ours ();
882 printf_filtered (_("\
883 Single stepping until exit from function %s, \n\
884 which has no line number information.\n"), name);
889 /* Say we are stepping, but stop after one insn whatever it does. */
890 step_range_start = step_range_end = 1;
891 if (!skip_subroutines)
893 Don't step over function calls, not even to functions lacking
895 step_over_calls = STEP_OVER_NONE;
898 if (skip_subroutines)
899 step_over_calls = STEP_OVER_ALL;
901 step_multi = (count > 1);
902 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
904 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
906 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
908 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
910 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
912 arg1->data.integer = skip_subroutines;
914 arg2->data.integer = single_inst;
916 arg3->data.integer = count;
918 arg4->data.integer = thread;
919 add_intermediate_continuation (step_1_continuation, arg1);
924 /* Continue program at specified address. */
927 jump_command (char *arg, int from_tty)
930 struct symtabs_and_lines sals;
931 struct symtab_and_line sal;
938 /* Find out whether we must run in the background. */
940 async_exec = strip_bg_char (&arg);
942 /* If we must run in the background, but the target can't do it,
944 if (async_exec && !target_can_async_p ())
945 error (_("Asynchronous execution not supported on this target."));
948 error_no_arg (_("starting address"));
950 sals = decode_line_spec_1 (arg, 1);
953 error (_("Unreasonable jump request"));
959 if (sal.symtab == 0 && sal.pc == 0)
960 error (_("No source file has been specified."));
962 resolve_sal_pc (&sal); /* May error out */
964 /* See if we are trying to jump to another function. */
965 fn = get_frame_function (get_current_frame ());
966 sfn = find_pc_function (sal.pc);
967 if (fn != NULL && sfn != fn)
969 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
970 SYMBOL_PRINT_NAME (fn)))
972 error (_("Not confirmed."));
979 fixup_symbol_section (sfn, 0);
980 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
981 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
983 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
985 error (_("Not confirmed."));
995 printf_filtered (_("Continuing at "));
996 fputs_filtered (paddress (addr), gdb_stdout);
997 printf_filtered (".\n");
1000 /* If we are not asked to run in the bg, then prepare to run in the
1001 foreground, synchronously. */
1002 if (!async_exec && target_can_async_p ())
1004 /* Simulate synchronous execution */
1005 async_disable_stdin ();
1008 clear_proceed_status ();
1009 proceed (addr, TARGET_SIGNAL_0, 0);
1013 /* Go to line or address in current procedure */
1015 go_command (char *line_no, int from_tty)
1017 if (line_no == (char *) NULL || !*line_no)
1018 printf_filtered (GO_USAGE);
1021 tbreak_command (line_no, from_tty);
1022 jump_command (line_no, from_tty);
1027 /* Continue program giving it specified signal. */
1030 signal_command (char *signum_exp, int from_tty)
1032 enum target_signal oursig;
1035 dont_repeat (); /* Too dangerous. */
1038 /* Find out whether we must run in the background. */
1039 if (signum_exp != NULL)
1040 async_exec = strip_bg_char (&signum_exp);
1042 /* If we must run in the background, but the target can't do it,
1044 if (async_exec && !target_can_async_p ())
1045 error (_("Asynchronous execution not supported on this target."));
1047 /* If we are not asked to run in the bg, then prepare to run in the
1048 foreground, synchronously. */
1049 if (!async_exec && target_can_async_p ())
1051 /* Simulate synchronous execution. */
1052 async_disable_stdin ();
1056 error_no_arg (_("signal number"));
1058 /* It would be even slicker to make signal names be valid expressions,
1059 (the type could be "enum $signal" or some such), then the user could
1060 assign them to convenience variables. */
1061 oursig = target_signal_from_name (signum_exp);
1063 if (oursig == TARGET_SIGNAL_UNKNOWN)
1065 /* No, try numeric. */
1066 int num = parse_and_eval_long (signum_exp);
1069 oursig = TARGET_SIGNAL_0;
1071 oursig = target_signal_from_command (num);
1076 if (oursig == TARGET_SIGNAL_0)
1077 printf_filtered (_("Continuing with no signal.\n"));
1079 printf_filtered (_("Continuing with signal %s.\n"),
1080 target_signal_to_name (oursig));
1083 clear_proceed_status ();
1084 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1085 FIXME: Neither should "signal foo" but when I tried passing
1086 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1087 tried to track down yet. */
1088 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
1091 /* Proceed until we reach a different source line with pc greater than
1092 our current one or exit the function. We skip calls in both cases.
1094 Note that eventually this command should probably be changed so
1095 that only source lines are printed out when we hit the breakpoint
1096 we set. This may involve changes to wait_for_inferior and the
1097 proceed status code. */
1100 until_next_command (int from_tty)
1102 struct frame_info *frame;
1104 struct symbol *func;
1105 struct symtab_and_line sal;
1107 clear_proceed_status ();
1109 frame = get_current_frame ();
1111 /* Step until either exited from this function or greater
1112 than the current line (if in symbolic section) or pc (if
1116 func = find_pc_function (pc);
1120 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1122 if (msymbol == NULL)
1123 error (_("Execution is not within a known function."));
1125 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1126 step_range_end = pc;
1130 sal = find_pc_line (pc, 0);
1132 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1133 step_range_end = sal.end;
1136 step_over_calls = STEP_OVER_ALL;
1137 step_frame_id = get_frame_id (frame);
1139 step_multi = 0; /* Only one call to proceed */
1141 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1145 until_command (char *arg, int from_tty)
1149 if (!target_has_execution)
1150 error (_("The program is not running."));
1152 /* Find out whether we must run in the background. */
1154 async_exec = strip_bg_char (&arg);
1156 /* If we must run in the background, but the target can't do it,
1158 if (async_exec && !target_can_async_p ())
1159 error (_("Asynchronous execution not supported on this target."));
1161 /* If we are not asked to run in the bg, then prepare to run in the
1162 foreground, synchronously. */
1163 if (!async_exec && target_can_async_p ())
1165 /* Simulate synchronous execution */
1166 async_disable_stdin ();
1170 until_break_command (arg, from_tty, 0);
1172 until_next_command (from_tty);
1176 advance_command (char *arg, int from_tty)
1180 if (!target_has_execution)
1181 error (_("The program is not running."));
1184 error_no_arg (_("a location"));
1186 /* Find out whether we must run in the background. */
1188 async_exec = strip_bg_char (&arg);
1190 /* If we must run in the background, but the target can't do it,
1192 if (async_exec && !target_can_async_p ())
1193 error (_("Asynchronous execution not supported on this target."));
1195 /* If we are not asked to run in the bg, then prepare to run in the
1196 foreground, synchronously. */
1197 if (!async_exec && target_can_async_p ())
1199 /* Simulate synchronous execution. */
1200 async_disable_stdin ();
1203 until_break_command (arg, from_tty, 1);
1206 /* Print the result of a function at the end of a 'finish' command. */
1209 print_return_value (struct type *func_type, struct type *value_type)
1211 struct gdbarch *gdbarch = current_gdbarch;
1212 struct cleanup *old_chain;
1213 struct ui_stream *stb;
1214 struct value *value;
1216 CHECK_TYPEDEF (value_type);
1217 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1219 /* FIXME: 2003-09-27: When returning from a nested inferior function
1220 call, it's possible (with no help from the architecture vector)
1221 to locate and return/print a "struct return" value. This is just
1222 a more complicated case of what is already being done in in the
1223 inferior function call code. In fact, when inferior function
1224 calls are made async, this will likely be made the norm. */
1226 switch (gdbarch_return_value (gdbarch, func_type, value_type,
1229 case RETURN_VALUE_REGISTER_CONVENTION:
1230 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1231 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1232 value = allocate_value (value_type);
1233 gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
1234 value_contents_raw (value), NULL);
1236 case RETURN_VALUE_STRUCT_CONVENTION:
1240 internal_error (__FILE__, __LINE__, _("bad switch"));
1246 stb = ui_out_stream_new (uiout);
1247 old_chain = make_cleanup_ui_out_stream_delete (stb);
1248 ui_out_text (uiout, "Value returned is ");
1249 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1250 record_latest_value (value));
1251 ui_out_text (uiout, " = ");
1252 value_print (value, stb->stream, 0, Val_no_prettyprint);
1253 ui_out_field_stream (uiout, "return-value", stb);
1254 ui_out_text (uiout, "\n");
1255 do_cleanups (old_chain);
1259 ui_out_text (uiout, "Value returned has type: ");
1260 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1261 ui_out_text (uiout, ".");
1262 ui_out_text (uiout, " Cannot determine contents\n");
1266 /* Stuff that needs to be done by the finish command after the target
1267 has stopped. In asynchronous mode, we wait for the target to stop
1268 in the call to poll or select in the event loop, so it is
1269 impossible to do all the stuff as part of the finish_command
1270 function itself. The only chance we have to complete this command
1271 is in fetch_inferior_event, which is called by the event loop as
1272 soon as it detects that the target has stopped. This function is
1273 called via the cmd_continuation pointer. */
1276 finish_command_continuation (struct continuation_arg *arg, int error_p)
1278 struct symbol *function;
1279 struct breakpoint *breakpoint;
1280 struct cleanup *cleanups;
1282 breakpoint = (struct breakpoint *) arg->data.pointer;
1283 function = (struct symbol *) arg->next->data.pointer;
1287 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1288 && function != NULL)
1290 struct type *value_type;
1292 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1294 internal_error (__FILE__, __LINE__,
1295 _("finish_command: function has no target type"));
1297 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1298 print_return_value (SYMBOL_TYPE (function), value_type);
1301 /* We suppress normal call of normal_stop observer and do it here so that
1302 that *stopped notification includes the return value. */
1303 observer_notify_normal_stop (stop_bpstat);
1306 suppress_normal_stop_observer = 0;
1307 delete_breakpoint (breakpoint);
1310 /* "finish": Set a temporary breakpoint at the place the selected
1311 frame will return to, then continue. */
1314 finish_command (char *arg, int from_tty)
1316 struct symtab_and_line sal;
1317 struct frame_info *frame;
1318 struct symbol *function;
1319 struct breakpoint *breakpoint;
1320 struct cleanup *old_chain;
1321 struct continuation_arg *arg1, *arg2, *arg3;
1325 /* Find out whether we must run in the background. */
1327 async_exec = strip_bg_char (&arg);
1329 /* If we must run in the background, but the target can't do it,
1331 if (async_exec && !target_can_async_p ())
1332 error (_("Asynchronous execution not supported on this target."));
1334 /* If we are not asked to run in the bg, then prepare to run in the
1335 foreground, synchronously. */
1336 if (!async_exec && target_can_async_p ())
1338 /* Simulate synchronous execution. */
1339 async_disable_stdin ();
1343 error (_("The \"finish\" command does not take any arguments."));
1344 if (!target_has_execution)
1345 error (_("The program is not running."));
1347 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1349 error (_("\"finish\" not meaningful in the outermost frame."));
1351 clear_proceed_status ();
1353 sal = find_pc_line (get_frame_pc (frame), 0);
1354 sal.pc = get_frame_pc (frame);
1356 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
1358 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1360 /* Find the function we will return from. */
1362 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1364 /* Print info on the selected frame, including level number but not
1368 printf_filtered (_("Run till exit from "));
1369 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1372 proceed_to_finish = 1; /* We want stop_registers, please... */
1373 make_cleanup_restore_integer (&suppress_normal_stop_observer);
1374 suppress_normal_stop_observer = 1;
1375 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1378 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1380 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1383 arg1->data.pointer = breakpoint;
1384 arg2->data.pointer = function;
1385 add_continuation (finish_command_continuation, arg1);
1387 discard_cleanups (old_chain);
1388 if (!target_can_async_p ())
1389 do_all_continuations (0);
1394 program_info (char *args, int from_tty)
1396 bpstat bs = stop_bpstat;
1398 int stat = bpstat_num (&bs, &num);
1400 if (!target_has_execution)
1402 printf_filtered (_("The program being debugged is not being run.\n"));
1406 target_files_info ();
1407 printf_filtered (_("Program stopped at %s.\n"),
1408 hex_string ((unsigned long) stop_pc));
1410 printf_filtered (_("It stopped after being stepped.\n"));
1413 /* There may be several breakpoints in the same place, so this
1414 isn't as strange as it seems. */
1419 printf_filtered (_("\
1420 It stopped at a breakpoint that has since been deleted.\n"));
1423 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1424 stat = bpstat_num (&bs, &num);
1427 else if (stop_signal != TARGET_SIGNAL_0)
1429 printf_filtered (_("It stopped with signal %s, %s.\n"),
1430 target_signal_to_name (stop_signal),
1431 target_signal_to_string (stop_signal));
1436 printf_filtered (_("\
1437 Type \"info stack\" or \"info registers\" for more information.\n"));
1442 environment_info (char *var, int from_tty)
1446 char *val = get_in_environ (inferior_environ, var);
1449 puts_filtered (var);
1450 puts_filtered (" = ");
1451 puts_filtered (val);
1452 puts_filtered ("\n");
1456 puts_filtered ("Environment variable \"");
1457 puts_filtered (var);
1458 puts_filtered ("\" not defined.\n");
1463 char **vector = environ_vector (inferior_environ);
1466 puts_filtered (*vector++);
1467 puts_filtered ("\n");
1473 set_environment_command (char *arg, int from_tty)
1475 char *p, *val, *var;
1479 error_no_arg (_("environment variable and value"));
1481 /* Find seperation between variable name and value */
1482 p = (char *) strchr (arg, '=');
1483 val = (char *) strchr (arg, ' ');
1485 if (p != 0 && val != 0)
1487 /* We have both a space and an equals. If the space is before the
1488 equals, walk forward over the spaces til we see a nonspace
1489 (possibly the equals). */
1494 /* Now if the = is after the char following the spaces,
1495 take the char following the spaces. */
1499 else if (val != 0 && p == 0)
1503 error_no_arg (_("environment variable to set"));
1505 if (p == 0 || p[1] == 0)
1509 p = arg + strlen (arg); /* So that savestring below will work */
1513 /* Not setting variable value to null */
1515 while (*val == ' ' || *val == '\t')
1519 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1522 var = savestring (arg, p - arg);
1525 printf_filtered (_("\
1526 Setting environment variable \"%s\" to null value.\n"),
1528 set_in_environ (inferior_environ, var, "");
1531 set_in_environ (inferior_environ, var, val);
1536 unset_environment_command (char *var, int from_tty)
1540 /* If there is no argument, delete all environment variables.
1541 Ask for confirmation if reading from the terminal. */
1542 if (!from_tty || query (_("Delete all environment variables? ")))
1544 free_environ (inferior_environ);
1545 inferior_environ = make_environ ();
1549 unset_in_environ (inferior_environ, var);
1552 /* Handle the execution path (PATH variable) */
1554 static const char path_var_name[] = "PATH";
1557 path_info (char *args, int from_tty)
1559 puts_filtered ("Executable and object file path: ");
1560 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1561 puts_filtered ("\n");
1564 /* Add zero or more directories to the front of the execution path. */
1567 path_command (char *dirname, int from_tty)
1572 env = get_in_environ (inferior_environ, path_var_name);
1573 /* Can be null if path is not set */
1576 exec_path = xstrdup (env);
1577 mod_path (dirname, &exec_path);
1578 set_in_environ (inferior_environ, path_var_name, exec_path);
1581 path_info ((char *) NULL, from_tty);
1585 /* Print out the machine register regnum. If regnum is -1, print all
1586 registers (print_all == 1) or all non-float and non-vector
1587 registers (print_all == 0).
1589 For most machines, having all_registers_info() print the
1590 register(s) one per line is good enough. If a different format is
1591 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1592 regs), or there is an existing convention for showing all the
1593 registers, define the architecture method PRINT_REGISTERS_INFO to
1594 provide that format. */
1597 default_print_registers_info (struct gdbarch *gdbarch,
1598 struct ui_file *file,
1599 struct frame_info *frame,
1600 int regnum, int print_all)
1603 const int numregs = gdbarch_num_regs (gdbarch)
1604 + gdbarch_num_pseudo_regs (gdbarch);
1605 gdb_byte buffer[MAX_REGISTER_SIZE];
1607 for (i = 0; i < numregs; i++)
1609 /* Decide between printing all regs, non-float / vector regs, or
1615 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1620 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1630 /* If the register name is empty, it is undefined for this
1631 processor, so don't display anything. */
1632 if (gdbarch_register_name (gdbarch, i) == NULL
1633 || *(gdbarch_register_name (gdbarch, i)) == '\0')
1636 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1637 print_spaces_filtered (15 - strlen (gdbarch_register_name
1638 (gdbarch, i)), file);
1640 /* Get the data in raw format. */
1641 if (! frame_register_read (frame, i, buffer))
1643 fprintf_filtered (file, "*value not available*\n");
1647 /* If virtual format is floating, print it that way, and in raw
1649 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1650 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1654 val_print (register_type (gdbarch, i), buffer, 0, 0,
1655 file, 0, 1, 0, Val_pretty_default, current_language);
1657 fprintf_filtered (file, "\t(raw 0x");
1658 for (j = 0; j < register_size (gdbarch, i); j++)
1661 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1664 idx = register_size (gdbarch, i) - 1 - j;
1665 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1667 fprintf_filtered (file, ")");
1671 /* Print the register in hex. */
1672 val_print (register_type (gdbarch, i), buffer, 0, 0,
1673 file, 'x', 1, 0, Val_pretty_default, current_language);
1674 /* If not a vector register, print it also according to its
1676 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1678 fprintf_filtered (file, "\t");
1679 val_print (register_type (gdbarch, i), buffer, 0, 0,
1680 file, 0, 1, 0, Val_pretty_default, current_language);
1684 fprintf_filtered (file, "\n");
1689 registers_info (char *addr_exp, int fpregs)
1691 struct frame_info *frame;
1692 struct gdbarch *gdbarch;
1693 int regnum, numregs;
1696 if (!target_has_registers)
1697 error (_("The program has no registers now."));
1698 frame = get_selected_frame (NULL);
1699 gdbarch = get_frame_arch (frame);
1703 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1708 while (*addr_exp != '\0')
1713 /* Keep skipping leading white space. */
1714 if (isspace ((*addr_exp)))
1720 /* Discard any leading ``$''. Check that there is something
1721 resembling a register following it. */
1722 if (addr_exp[0] == '$')
1724 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1725 error (_("Missing register name"));
1727 /* Find the start/end of this register name/num/group. */
1729 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1733 /* Figure out what we've found and display it. */
1735 /* A register name? */
1737 int regnum = frame_map_name_to_regnum (frame, start, end - start);
1740 /* User registers lie completely outside of the range of
1741 normal registers. Catch them early so that the target
1743 if (regnum >= gdbarch_num_regs (gdbarch)
1744 + gdbarch_num_pseudo_regs (gdbarch))
1746 struct value *val = value_of_user_reg (regnum, frame);
1748 printf_filtered ("%s: ", start);
1749 print_scalar_formatted (value_contents (val),
1750 check_typedef (value_type (val)),
1751 'x', 0, gdb_stdout);
1752 printf_filtered ("\n");
1755 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1756 frame, regnum, fpregs);
1761 /* A register number? (how portable is this one?). */
1764 int regnum = strtol (start, &endptr, 0);
1767 && regnum < gdbarch_num_regs (gdbarch)
1768 + gdbarch_num_pseudo_regs (gdbarch))
1770 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1771 frame, regnum, fpregs);
1776 /* A register group? */
1778 struct reggroup *group;
1779 for (group = reggroup_next (gdbarch, NULL);
1781 group = reggroup_next (gdbarch, group))
1783 /* Don't bother with a length check. Should the user
1784 enter a short register group name, go with the first
1785 group that matches. */
1786 if (strncmp (start, reggroup_name (group), end - start) == 0)
1793 regnum < gdbarch_num_regs (gdbarch)
1794 + gdbarch_num_pseudo_regs (gdbarch);
1797 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1798 gdbarch_print_registers_info (gdbarch,
1806 /* Nothing matched. */
1807 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1812 all_registers_info (char *addr_exp, int from_tty)
1814 registers_info (addr_exp, 1);
1818 nofp_registers_info (char *addr_exp, int from_tty)
1820 registers_info (addr_exp, 0);
1824 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1825 struct frame_info *frame, const char *args)
1827 if (gdbarch_print_vector_info_p (gdbarch))
1828 gdbarch_print_vector_info (gdbarch, file, frame, args);
1832 int printed_something = 0;
1835 regnum < gdbarch_num_regs (gdbarch)
1836 + gdbarch_num_pseudo_regs (gdbarch);
1839 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1841 printed_something = 1;
1842 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1845 if (!printed_something)
1846 fprintf_filtered (file, "No vector information\n");
1851 vector_info (char *args, int from_tty)
1853 if (!target_has_registers)
1854 error (_("The program has no registers now."));
1856 print_vector_info (current_gdbarch, gdb_stdout,
1857 get_selected_frame (NULL), args);
1863 * Should save/restore the tty state since it might be that the
1864 * program to be debugged was started on this tty and it wants
1865 * the tty in some state other than what we want. If it's running
1866 * on another terminal or without a terminal, then saving and
1867 * restoring the tty state is a harmless no-op.
1868 * This only needs to be done if we are attaching to a process.
1873 takes a program started up outside of gdb and ``attaches'' to it.
1874 This stops it cold in its tracks and allows us to start debugging it.
1875 and wait for the trace-trap that results from attaching. */
1878 attach_command_post_wait (char *args, int from_tty, int async_exec)
1881 char *full_exec_path = NULL;
1883 stop_soon = NO_STOP_QUIETLY;
1885 /* If no exec file is yet known, try to determine it from the
1887 exec_file = (char *) get_exec_file (0);
1890 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1893 /* It's possible we don't have a full path, but rather just a
1894 filename. Some targets, such as HP-UX, don't provide the
1897 Attempt to qualify the filename against the source path.
1898 (If that fails, we'll just fall back on the original
1899 filename. Not much more we can do...)
1901 if (!source_full_path_of (exec_file, &full_exec_path))
1902 full_exec_path = savestring (exec_file, strlen (exec_file));
1904 exec_file_attach (full_exec_path, from_tty);
1905 symbol_file_add_main (full_exec_path, from_tty);
1910 reopen_exec_file ();
1914 /* Take any necessary post-attaching actions for this platform. */
1915 target_post_attach (PIDGET (inferior_ptid));
1917 post_create_inferior (¤t_target, from_tty);
1919 /* Install inferior's terminal modes. */
1920 target_terminal_inferior ();
1923 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
1926 if (target_can_async_p ())
1927 async_enable_stdin ();
1929 if (deprecated_attach_hook)
1930 deprecated_attach_hook ();
1935 attach_command_continuation (struct continuation_arg *arg, int error_p)
1941 args = (char *) arg->data.pointer;
1942 from_tty = arg->next->data.integer;
1943 async_exec = arg->next->next->data.integer;
1945 attach_command_post_wait (args, from_tty, async_exec);
1949 attach_command (char *args, int from_tty)
1952 char *full_exec_path = NULL;
1955 dont_repeat (); /* Not for the faint of heart */
1957 if (target_has_execution)
1959 if (query ("A program is being debugged already. Kill it? "))
1962 error (_("Not killed."));
1965 /* Clean up any leftovers from other runs. Some other things from
1966 this function should probably be moved into target_pre_inferior. */
1967 target_pre_inferior (from_tty);
1969 /* Clear out solib state. Otherwise the solib state of the previous
1970 inferior might have survived and is entirely wrong for the new
1971 target. This has been observed on GNU/Linux using glibc 2.3. How
1983 Cannot access memory at address 0xdeadbeef
1989 async_exec = strip_bg_char (&args);
1991 /* If we get a request for running in the bg but the target
1992 doesn't support it, error out. */
1993 if (async_exec && !target_can_async_p ())
1994 error (_("Asynchronous execution not supported on this target."));
1997 /* If we don't get a request of running in the bg, then we need
1998 to simulate synchronous (fg) execution. */
1999 if (!async_exec && target_can_async_p ())
2001 /* Simulate synchronous execution */
2002 async_disable_stdin ();
2005 target_attach (args, from_tty);
2007 /* Set up the "saved terminal modes" of the inferior
2008 based on what modes we are starting it with. */
2009 target_terminal_init ();
2011 /* Set up execution context to know that we should return from
2012 wait_for_inferior as soon as the target reports a stop. */
2013 init_wait_for_inferior ();
2014 clear_proceed_status ();
2016 /* No traps are generated when attaching to inferior under Mach 3
2018 #ifndef ATTACH_NO_WAIT
2019 /* Careful here. See comments in inferior.h. Basically some OSes
2020 don't ignore SIGSTOPs on continue requests anymore. We need a
2021 way for handle_inferior_event to reset the stop_signal variable
2022 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
2023 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2025 if (target_can_async_p ())
2027 /* sync_execution mode. Wait for stop. */
2028 struct continuation_arg *arg1, *arg2, *arg3;
2031 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2033 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2035 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2039 arg1->data.pointer = args;
2040 arg2->data.integer = from_tty;
2041 arg3->data.integer = async_exec;
2042 add_continuation (attach_command_continuation, arg1);
2046 wait_for_inferior (0);
2049 attach_command_post_wait (args, from_tty, async_exec);
2054 * takes a program previously attached to and detaches it.
2055 * The program resumes execution and will no longer stop
2056 * on signals, etc. We better not have left any breakpoints
2057 * in the program or it'll die when it hits one. For this
2058 * to work, it may be necessary for the process to have been
2059 * previously attached. It *might* work if the program was
2060 * started via the normal ptrace (PTRACE_TRACEME).
2064 detach_command (char *args, int from_tty)
2066 dont_repeat (); /* Not for the faint of heart. */
2067 target_detach (args, from_tty);
2068 no_shared_libraries (NULL, from_tty);
2069 init_thread_list ();
2070 if (deprecated_detach_hook)
2071 deprecated_detach_hook ();
2074 /* Disconnect from the current target without resuming it (leaving it
2075 waiting for a debugger).
2077 We'd better not have left any breakpoints in the program or the
2078 next debugger will get confused. Currently only supported for some
2079 remote targets, since the normal attach mechanisms don't work on
2080 stopped processes on some native platforms (e.g. GNU/Linux). */
2083 disconnect_command (char *args, int from_tty)
2085 dont_repeat (); /* Not for the faint of heart */
2086 target_disconnect (args, from_tty);
2087 no_shared_libraries (NULL, from_tty);
2088 init_thread_list ();
2089 if (deprecated_detach_hook)
2090 deprecated_detach_hook ();
2093 /* Stop the execution of the target while running in async mode, in
2096 interrupt_target_command (char *args, int from_tty)
2098 if (target_can_async_p ())
2100 dont_repeat (); /* Not for the faint of heart */
2106 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2107 struct frame_info *frame, const char *args)
2109 if (gdbarch_print_float_info_p (gdbarch))
2110 gdbarch_print_float_info (gdbarch, file, frame, args);
2114 int printed_something = 0;
2117 regnum < gdbarch_num_regs (gdbarch)
2118 + gdbarch_num_pseudo_regs (gdbarch);
2121 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2123 printed_something = 1;
2124 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2127 if (!printed_something)
2128 fprintf_filtered (file, "\
2129 No floating-point info available for this processor.\n");
2134 float_info (char *args, int from_tty)
2136 if (!target_has_registers)
2137 error (_("The program has no registers now."));
2139 print_float_info (current_gdbarch, gdb_stdout,
2140 get_selected_frame (NULL), args);
2144 unset_command (char *args, int from_tty)
2146 printf_filtered (_("\
2147 \"unset\" must be followed by the name of an unset subcommand.\n"));
2148 help_list (unsetlist, "unset ", -1, gdb_stdout);
2152 _initialize_infcmd (void)
2154 struct cmd_list_element *c = NULL;
2156 /* add the filename of the terminal connected to inferior I/O */
2157 add_setshow_filename_cmd ("inferior-tty", class_run,
2158 &inferior_io_terminal, _("\
2159 Set terminal for future runs of program being debugged."), _("\
2160 Show terminal for future runs of program being debugged."), _("\
2161 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2162 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2164 add_setshow_optional_filename_cmd ("args", class_run,
2165 &inferior_args, _("\
2166 Set argument list to give program being debugged when it is started."), _("\
2167 Show argument list to give program being debugged when it is started."), _("\
2168 Follow this command with any number of args, to be passed to the program."),
2171 &setlist, &showlist);
2173 c = add_cmd ("environment", no_class, environment_info, _("\
2174 The environment to give the program, or one variable's value.\n\
2175 With an argument VAR, prints the value of environment variable VAR to\n\
2176 give the program being debugged. With no arguments, prints the entire\n\
2177 environment to be given to the program."), &showlist);
2178 set_cmd_completer (c, noop_completer);
2180 add_prefix_cmd ("unset", no_class, unset_command,
2181 _("Complement to certain \"set\" commands."),
2182 &unsetlist, "unset ", 0, &cmdlist);
2184 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2185 Cancel environment variable VAR for the program.\n\
2186 This does not affect the program until the next \"run\" command."),
2188 set_cmd_completer (c, noop_completer);
2190 c = add_cmd ("environment", class_run, set_environment_command, _("\
2191 Set environment variable value to give the program.\n\
2192 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2193 VALUES of environment variables are uninterpreted strings.\n\
2194 This does not affect the program until the next \"run\" command."),
2196 set_cmd_completer (c, noop_completer);
2198 c = add_com ("path", class_files, path_command, _("\
2199 Add directory DIR(s) to beginning of search path for object files.\n\
2200 $cwd in the path means the current working directory.\n\
2201 This path is equivalent to the $PATH shell variable. It is a list of\n\
2202 directories, separated by colons. These directories are searched to find\n\
2203 fully linked executable files and separately compiled object files as needed."));
2204 set_cmd_completer (c, filename_completer);
2206 c = add_cmd ("paths", no_class, path_info, _("\
2207 Current search path for finding object files.\n\
2208 $cwd in the path means the current working directory.\n\
2209 This path is equivalent to the $PATH shell variable. It is a list of\n\
2210 directories, separated by colons. These directories are searched to find\n\
2211 fully linked executable files and separately compiled object files as needed."),
2213 set_cmd_completer (c, noop_completer);
2215 add_com ("attach", class_run, attach_command, _("\
2216 Attach to a process or file outside of GDB.\n\
2217 This command attaches to another target, of the same type as your last\n\
2218 \"target\" command (\"info files\" will show your target stack).\n\
2219 The command may take as argument a process id or a device file.\n\
2220 For a process id, you must have permission to send the process a signal,\n\
2221 and it must have the same effective uid as the debugger.\n\
2222 When using \"attach\" with a process id, the debugger finds the\n\
2223 program running in the process, looking first in the current working\n\
2224 directory, or (if not found there) using the source file search path\n\
2225 (see the \"directory\" command). You can also use the \"file\" command\n\
2226 to specify the program, and to load its symbol table."));
2228 add_prefix_cmd ("detach", class_run, detach_command, _("\
2229 Detach a process or file previously attached.\n\
2230 If a process, it is no longer traced, and it continues its execution. If\n\
2231 you were debugging a file, the file is closed and gdb no longer accesses it."),
2232 &detachlist, "detach ", 0, &cmdlist);
2234 add_com ("disconnect", class_run, disconnect_command, _("\
2235 Disconnect from a target.\n\
2236 The target will wait for another debugger to connect. Not available for\n\
2239 add_com ("signal", class_run, signal_command, _("\
2240 Continue program giving it signal specified by the argument.\n\
2241 An argument of \"0\" means continue program without giving it a signal."));
2243 add_com ("stepi", class_run, stepi_command, _("\
2244 Step one instruction exactly.\n\
2245 Argument N means do this N times (or till program stops for another reason)."));
2246 add_com_alias ("si", "stepi", class_alias, 0);
2248 add_com ("nexti", class_run, nexti_command, _("\
2249 Step one instruction, but proceed through subroutine calls.\n\
2250 Argument N means do this N times (or till program stops for another reason)."));
2251 add_com_alias ("ni", "nexti", class_alias, 0);
2253 add_com ("finish", class_run, finish_command, _("\
2254 Execute until selected stack frame returns.\n\
2255 Upon return, the value returned is printed and put in the value history."));
2256 add_com_alias ("fin", "finish", class_run, 1);
2258 add_com ("next", class_run, next_command, _("\
2259 Step program, proceeding through subroutine calls.\n\
2260 Like the \"step\" command as long as subroutine calls do not happen;\n\
2261 when they do, the call is treated as one instruction.\n\
2262 Argument N means do this N times (or till program stops for another reason)."));
2263 add_com_alias ("n", "next", class_run, 1);
2265 add_com_alias ("S", "next", class_run, 1);
2267 add_com ("step", class_run, step_command, _("\
2268 Step program until it reaches a different source line.\n\
2269 Argument N means do this N times (or till program stops for another reason)."));
2270 add_com_alias ("s", "step", class_run, 1);
2272 c = add_com ("until", class_run, until_command, _("\
2273 Execute until the program reaches a source line greater than the current\n\
2274 or a specified location (same args as break command) within the current frame."));
2275 set_cmd_completer (c, location_completer);
2276 add_com_alias ("u", "until", class_run, 1);
2278 c = add_com ("advance", class_run, advance_command, _("\
2279 Continue the program up to the given location (same form as args for break command).\n\
2280 Execution will also stop upon exit from the current stack frame."));
2281 set_cmd_completer (c, location_completer);
2283 c = add_com ("jump", class_run, jump_command, _("\
2284 Continue program being debugged at specified line or address.\n\
2285 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2286 for an address to start at."));
2287 set_cmd_completer (c, location_completer);
2291 c = add_com ("go", class_run, go_command, _("\
2292 Usage: go <location>\n\
2293 Continue program being debugged, stopping at specified line or \n\
2295 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2296 expression for an address to start at.\n\
2297 This command is a combination of tbreak and jump."));
2298 set_cmd_completer (c, location_completer);
2302 add_com_alias ("g", "go", class_run, 1);
2304 add_com ("continue", class_run, continue_command, _("\
2305 Continue program being debugged, after signal or breakpoint.\n\
2306 If proceeding from breakpoint, a number N may be used as an argument,\n\
2307 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2308 the breakpoint won't break until the Nth time it is reached)."));
2309 add_com_alias ("c", "cont", class_run, 1);
2310 add_com_alias ("fg", "cont", class_run, 1);
2312 c = add_com ("run", class_run, run_command, _("\
2313 Start debugged program. You may specify arguments to give it.\n\
2314 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2315 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2316 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2317 To cancel previous arguments and run with no arguments,\n\
2318 use \"set args\" without arguments."));
2319 set_cmd_completer (c, filename_completer);
2320 add_com_alias ("r", "run", class_run, 1);
2322 add_com ("R", class_run, run_no_args_command,
2323 _("Start debugged program with no arguments."));
2325 c = add_com ("start", class_run, start_command, _("\
2326 Run the debugged program until the beginning of the main procedure.\n\
2327 You may specify arguments to give to your program, just as with the\n\
2328 \"run\" command."));
2329 set_cmd_completer (c, filename_completer);
2331 c = add_com ("interrupt", class_run, interrupt_target_command,
2332 _("Interrupt the execution of the debugged program."));
2333 set_cmd_async_ok (c);
2335 add_info ("registers", nofp_registers_info, _("\
2336 List of integer registers and their contents, for selected stack frame.\n\
2337 Register name as argument means describe only that register."));
2338 add_info_alias ("r", "registers", 1);
2341 add_com ("lr", class_info, nofp_registers_info, _("\
2342 List of integer registers and their contents, for selected stack frame.\n\
2343 Register name as argument means describe only that register."));
2344 add_info ("all-registers", all_registers_info, _("\
2345 List of all registers and their contents, for selected stack frame.\n\
2346 Register name as argument means describe only that register."));
2348 add_info ("program", program_info,
2349 _("Execution status of the program."));
2351 add_info ("float", float_info,
2352 _("Print the status of the floating point unit\n"));
2354 add_info ("vector", vector_info,
2355 _("Print the status of the vector unit\n"));
2357 inferior_environ = make_environ ();
2358 init_environ (inferior_environ);