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 /* Do this only if not running asynchronously or if the target
1388 cannot do async execution. Otherwise, complete this command when
1389 the target actually stops, in fetch_inferior_event. */
1390 discard_cleanups (old_chain);
1391 if (!target_can_async_p ())
1392 do_all_continuations (0);
1397 program_info (char *args, int from_tty)
1399 bpstat bs = stop_bpstat;
1401 int stat = bpstat_num (&bs, &num);
1403 if (!target_has_execution)
1405 printf_filtered (_("The program being debugged is not being run.\n"));
1409 target_files_info ();
1410 printf_filtered (_("Program stopped at %s.\n"),
1411 hex_string ((unsigned long) stop_pc));
1413 printf_filtered (_("It stopped after being stepped.\n"));
1416 /* There may be several breakpoints in the same place, so this
1417 isn't as strange as it seems. */
1422 printf_filtered (_("\
1423 It stopped at a breakpoint that has since been deleted.\n"));
1426 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1427 stat = bpstat_num (&bs, &num);
1430 else if (stop_signal != TARGET_SIGNAL_0)
1432 printf_filtered (_("It stopped with signal %s, %s.\n"),
1433 target_signal_to_name (stop_signal),
1434 target_signal_to_string (stop_signal));
1439 printf_filtered (_("\
1440 Type \"info stack\" or \"info registers\" for more information.\n"));
1445 environment_info (char *var, int from_tty)
1449 char *val = get_in_environ (inferior_environ, var);
1452 puts_filtered (var);
1453 puts_filtered (" = ");
1454 puts_filtered (val);
1455 puts_filtered ("\n");
1459 puts_filtered ("Environment variable \"");
1460 puts_filtered (var);
1461 puts_filtered ("\" not defined.\n");
1466 char **vector = environ_vector (inferior_environ);
1469 puts_filtered (*vector++);
1470 puts_filtered ("\n");
1476 set_environment_command (char *arg, int from_tty)
1478 char *p, *val, *var;
1482 error_no_arg (_("environment variable and value"));
1484 /* Find seperation between variable name and value */
1485 p = (char *) strchr (arg, '=');
1486 val = (char *) strchr (arg, ' ');
1488 if (p != 0 && val != 0)
1490 /* We have both a space and an equals. If the space is before the
1491 equals, walk forward over the spaces til we see a nonspace
1492 (possibly the equals). */
1497 /* Now if the = is after the char following the spaces,
1498 take the char following the spaces. */
1502 else if (val != 0 && p == 0)
1506 error_no_arg (_("environment variable to set"));
1508 if (p == 0 || p[1] == 0)
1512 p = arg + strlen (arg); /* So that savestring below will work */
1516 /* Not setting variable value to null */
1518 while (*val == ' ' || *val == '\t')
1522 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1525 var = savestring (arg, p - arg);
1528 printf_filtered (_("\
1529 Setting environment variable \"%s\" to null value.\n"),
1531 set_in_environ (inferior_environ, var, "");
1534 set_in_environ (inferior_environ, var, val);
1539 unset_environment_command (char *var, int from_tty)
1543 /* If there is no argument, delete all environment variables.
1544 Ask for confirmation if reading from the terminal. */
1545 if (!from_tty || query (_("Delete all environment variables? ")))
1547 free_environ (inferior_environ);
1548 inferior_environ = make_environ ();
1552 unset_in_environ (inferior_environ, var);
1555 /* Handle the execution path (PATH variable) */
1557 static const char path_var_name[] = "PATH";
1560 path_info (char *args, int from_tty)
1562 puts_filtered ("Executable and object file path: ");
1563 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1564 puts_filtered ("\n");
1567 /* Add zero or more directories to the front of the execution path. */
1570 path_command (char *dirname, int from_tty)
1575 env = get_in_environ (inferior_environ, path_var_name);
1576 /* Can be null if path is not set */
1579 exec_path = xstrdup (env);
1580 mod_path (dirname, &exec_path);
1581 set_in_environ (inferior_environ, path_var_name, exec_path);
1584 path_info ((char *) NULL, from_tty);
1588 /* Print out the machine register regnum. If regnum is -1, print all
1589 registers (print_all == 1) or all non-float and non-vector
1590 registers (print_all == 0).
1592 For most machines, having all_registers_info() print the
1593 register(s) one per line is good enough. If a different format is
1594 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1595 regs), or there is an existing convention for showing all the
1596 registers, define the architecture method PRINT_REGISTERS_INFO to
1597 provide that format. */
1600 default_print_registers_info (struct gdbarch *gdbarch,
1601 struct ui_file *file,
1602 struct frame_info *frame,
1603 int regnum, int print_all)
1606 const int numregs = gdbarch_num_regs (gdbarch)
1607 + gdbarch_num_pseudo_regs (gdbarch);
1608 gdb_byte buffer[MAX_REGISTER_SIZE];
1610 for (i = 0; i < numregs; i++)
1612 /* Decide between printing all regs, non-float / vector regs, or
1618 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1623 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1633 /* If the register name is empty, it is undefined for this
1634 processor, so don't display anything. */
1635 if (gdbarch_register_name (gdbarch, i) == NULL
1636 || *(gdbarch_register_name (gdbarch, i)) == '\0')
1639 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1640 print_spaces_filtered (15 - strlen (gdbarch_register_name
1641 (gdbarch, i)), file);
1643 /* Get the data in raw format. */
1644 if (! frame_register_read (frame, i, buffer))
1646 fprintf_filtered (file, "*value not available*\n");
1650 /* If virtual format is floating, print it that way, and in raw
1652 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1653 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1657 val_print (register_type (gdbarch, i), buffer, 0, 0,
1658 file, 0, 1, 0, Val_pretty_default, current_language);
1660 fprintf_filtered (file, "\t(raw 0x");
1661 for (j = 0; j < register_size (gdbarch, i); j++)
1664 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1667 idx = register_size (gdbarch, i) - 1 - j;
1668 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1670 fprintf_filtered (file, ")");
1674 /* Print the register in hex. */
1675 val_print (register_type (gdbarch, i), buffer, 0, 0,
1676 file, 'x', 1, 0, Val_pretty_default, current_language);
1677 /* If not a vector register, print it also according to its
1679 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1681 fprintf_filtered (file, "\t");
1682 val_print (register_type (gdbarch, i), buffer, 0, 0,
1683 file, 0, 1, 0, Val_pretty_default, current_language);
1687 fprintf_filtered (file, "\n");
1692 registers_info (char *addr_exp, int fpregs)
1694 struct frame_info *frame;
1695 struct gdbarch *gdbarch;
1696 int regnum, numregs;
1699 if (!target_has_registers)
1700 error (_("The program has no registers now."));
1701 frame = get_selected_frame (NULL);
1702 gdbarch = get_frame_arch (frame);
1706 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1711 while (*addr_exp != '\0')
1716 /* Keep skipping leading white space. */
1717 if (isspace ((*addr_exp)))
1723 /* Discard any leading ``$''. Check that there is something
1724 resembling a register following it. */
1725 if (addr_exp[0] == '$')
1727 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1728 error (_("Missing register name"));
1730 /* Find the start/end of this register name/num/group. */
1732 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1736 /* Figure out what we've found and display it. */
1738 /* A register name? */
1740 int regnum = frame_map_name_to_regnum (frame, start, end - start);
1743 /* User registers lie completely outside of the range of
1744 normal registers. Catch them early so that the target
1746 if (regnum >= gdbarch_num_regs (gdbarch)
1747 + gdbarch_num_pseudo_regs (gdbarch))
1749 struct value *val = value_of_user_reg (regnum, frame);
1751 printf_filtered ("%s: ", start);
1752 print_scalar_formatted (value_contents (val),
1753 check_typedef (value_type (val)),
1754 'x', 0, gdb_stdout);
1755 printf_filtered ("\n");
1758 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1759 frame, regnum, fpregs);
1764 /* A register number? (how portable is this one?). */
1767 int regnum = strtol (start, &endptr, 0);
1770 && regnum < gdbarch_num_regs (gdbarch)
1771 + gdbarch_num_pseudo_regs (gdbarch))
1773 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1774 frame, regnum, fpregs);
1779 /* A register group? */
1781 struct reggroup *group;
1782 for (group = reggroup_next (gdbarch, NULL);
1784 group = reggroup_next (gdbarch, group))
1786 /* Don't bother with a length check. Should the user
1787 enter a short register group name, go with the first
1788 group that matches. */
1789 if (strncmp (start, reggroup_name (group), end - start) == 0)
1796 regnum < gdbarch_num_regs (gdbarch)
1797 + gdbarch_num_pseudo_regs (gdbarch);
1800 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1801 gdbarch_print_registers_info (gdbarch,
1809 /* Nothing matched. */
1810 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1815 all_registers_info (char *addr_exp, int from_tty)
1817 registers_info (addr_exp, 1);
1821 nofp_registers_info (char *addr_exp, int from_tty)
1823 registers_info (addr_exp, 0);
1827 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1828 struct frame_info *frame, const char *args)
1830 if (gdbarch_print_vector_info_p (gdbarch))
1831 gdbarch_print_vector_info (gdbarch, file, frame, args);
1835 int printed_something = 0;
1838 regnum < gdbarch_num_regs (gdbarch)
1839 + gdbarch_num_pseudo_regs (gdbarch);
1842 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1844 printed_something = 1;
1845 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1848 if (!printed_something)
1849 fprintf_filtered (file, "No vector information\n");
1854 vector_info (char *args, int from_tty)
1856 if (!target_has_registers)
1857 error (_("The program has no registers now."));
1859 print_vector_info (current_gdbarch, gdb_stdout,
1860 get_selected_frame (NULL), args);
1866 * Should save/restore the tty state since it might be that the
1867 * program to be debugged was started on this tty and it wants
1868 * the tty in some state other than what we want. If it's running
1869 * on another terminal or without a terminal, then saving and
1870 * restoring the tty state is a harmless no-op.
1871 * This only needs to be done if we are attaching to a process.
1876 takes a program started up outside of gdb and ``attaches'' to it.
1877 This stops it cold in its tracks and allows us to start debugging it.
1878 and wait for the trace-trap that results from attaching. */
1881 attach_command_post_wait (char *args, int from_tty, int async_exec)
1884 char *full_exec_path = NULL;
1886 stop_soon = NO_STOP_QUIETLY;
1888 /* If no exec file is yet known, try to determine it from the
1890 exec_file = (char *) get_exec_file (0);
1893 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1896 /* It's possible we don't have a full path, but rather just a
1897 filename. Some targets, such as HP-UX, don't provide the
1900 Attempt to qualify the filename against the source path.
1901 (If that fails, we'll just fall back on the original
1902 filename. Not much more we can do...)
1904 if (!source_full_path_of (exec_file, &full_exec_path))
1905 full_exec_path = savestring (exec_file, strlen (exec_file));
1907 exec_file_attach (full_exec_path, from_tty);
1908 symbol_file_add_main (full_exec_path, from_tty);
1913 reopen_exec_file ();
1917 /* Take any necessary post-attaching actions for this platform. */
1918 target_post_attach (PIDGET (inferior_ptid));
1920 post_create_inferior (¤t_target, from_tty);
1922 /* Install inferior's terminal modes. */
1923 target_terminal_inferior ();
1926 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
1929 if (target_can_async_p ())
1930 async_enable_stdin ();
1932 if (deprecated_attach_hook)
1933 deprecated_attach_hook ();
1938 attach_command_continuation (struct continuation_arg *arg, int error_p)
1944 args = (char *) arg->data.pointer;
1945 from_tty = arg->next->data.integer;
1946 async_exec = arg->next->next->data.integer;
1948 attach_command_post_wait (args, from_tty, async_exec);
1952 attach_command (char *args, int from_tty)
1955 char *full_exec_path = NULL;
1958 dont_repeat (); /* Not for the faint of heart */
1960 if (target_has_execution)
1962 if (query ("A program is being debugged already. Kill it? "))
1965 error (_("Not killed."));
1968 /* Clean up any leftovers from other runs. Some other things from
1969 this function should probably be moved into target_pre_inferior. */
1970 target_pre_inferior (from_tty);
1972 /* Clear out solib state. Otherwise the solib state of the previous
1973 inferior might have survived and is entirely wrong for the new
1974 target. This has been observed on GNU/Linux using glibc 2.3. How
1986 Cannot access memory at address 0xdeadbeef
1992 async_exec = strip_bg_char (&args);
1994 /* If we get a request for running in the bg but the target
1995 doesn't support it, error out. */
1996 if (async_exec && !target_can_async_p ())
1997 error (_("Asynchronous execution not supported on this target."));
2000 /* If we don't get a request of running in the bg, then we need
2001 to simulate synchronous (fg) execution. */
2002 if (!async_exec && target_can_async_p ())
2004 /* Simulate synchronous execution */
2005 async_disable_stdin ();
2008 target_attach (args, from_tty);
2010 /* Set up the "saved terminal modes" of the inferior
2011 based on what modes we are starting it with. */
2012 target_terminal_init ();
2014 /* Set up execution context to know that we should return from
2015 wait_for_inferior as soon as the target reports a stop. */
2016 init_wait_for_inferior ();
2017 clear_proceed_status ();
2019 /* No traps are generated when attaching to inferior under Mach 3
2021 #ifndef ATTACH_NO_WAIT
2022 /* Careful here. See comments in inferior.h. Basically some OSes
2023 don't ignore SIGSTOPs on continue requests anymore. We need a
2024 way for handle_inferior_event to reset the stop_signal variable
2025 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
2026 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2028 if (target_can_async_p ())
2030 /* sync_execution mode. Wait for stop. */
2031 struct continuation_arg *arg1, *arg2, *arg3;
2034 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2036 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2038 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2042 arg1->data.pointer = args;
2043 arg2->data.integer = from_tty;
2044 arg3->data.integer = async_exec;
2045 add_continuation (attach_command_continuation, arg1);
2049 wait_for_inferior (0);
2052 attach_command_post_wait (args, from_tty, async_exec);
2057 * takes a program previously attached to and detaches it.
2058 * The program resumes execution and will no longer stop
2059 * on signals, etc. We better not have left any breakpoints
2060 * in the program or it'll die when it hits one. For this
2061 * to work, it may be necessary for the process to have been
2062 * previously attached. It *might* work if the program was
2063 * started via the normal ptrace (PTRACE_TRACEME).
2067 detach_command (char *args, int from_tty)
2069 dont_repeat (); /* Not for the faint of heart. */
2070 target_detach (args, from_tty);
2071 no_shared_libraries (NULL, from_tty);
2072 init_thread_list ();
2073 if (deprecated_detach_hook)
2074 deprecated_detach_hook ();
2077 /* Disconnect from the current target without resuming it (leaving it
2078 waiting for a debugger).
2080 We'd better not have left any breakpoints in the program or the
2081 next debugger will get confused. Currently only supported for some
2082 remote targets, since the normal attach mechanisms don't work on
2083 stopped processes on some native platforms (e.g. GNU/Linux). */
2086 disconnect_command (char *args, int from_tty)
2088 dont_repeat (); /* Not for the faint of heart */
2089 target_disconnect (args, from_tty);
2090 no_shared_libraries (NULL, from_tty);
2091 init_thread_list ();
2092 if (deprecated_detach_hook)
2093 deprecated_detach_hook ();
2096 /* Stop the execution of the target while running in async mode, in
2099 interrupt_target_command (char *args, int from_tty)
2101 if (target_can_async_p ())
2103 dont_repeat (); /* Not for the faint of heart */
2109 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2110 struct frame_info *frame, const char *args)
2112 if (gdbarch_print_float_info_p (gdbarch))
2113 gdbarch_print_float_info (gdbarch, file, frame, args);
2117 int printed_something = 0;
2120 regnum < gdbarch_num_regs (gdbarch)
2121 + gdbarch_num_pseudo_regs (gdbarch);
2124 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2126 printed_something = 1;
2127 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2130 if (!printed_something)
2131 fprintf_filtered (file, "\
2132 No floating-point info available for this processor.\n");
2137 float_info (char *args, int from_tty)
2139 if (!target_has_registers)
2140 error (_("The program has no registers now."));
2142 print_float_info (current_gdbarch, gdb_stdout,
2143 get_selected_frame (NULL), args);
2147 unset_command (char *args, int from_tty)
2149 printf_filtered (_("\
2150 \"unset\" must be followed by the name of an unset subcommand.\n"));
2151 help_list (unsetlist, "unset ", -1, gdb_stdout);
2155 _initialize_infcmd (void)
2157 struct cmd_list_element *c = NULL;
2159 /* add the filename of the terminal connected to inferior I/O */
2160 add_setshow_filename_cmd ("inferior-tty", class_run,
2161 &inferior_io_terminal, _("\
2162 Set terminal for future runs of program being debugged."), _("\
2163 Show terminal for future runs of program being debugged."), _("\
2164 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2165 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2167 add_setshow_optional_filename_cmd ("args", class_run,
2168 &inferior_args, _("\
2169 Set argument list to give program being debugged when it is started."), _("\
2170 Show argument list to give program being debugged when it is started."), _("\
2171 Follow this command with any number of args, to be passed to the program."),
2174 &setlist, &showlist);
2176 c = add_cmd ("environment", no_class, environment_info, _("\
2177 The environment to give the program, or one variable's value.\n\
2178 With an argument VAR, prints the value of environment variable VAR to\n\
2179 give the program being debugged. With no arguments, prints the entire\n\
2180 environment to be given to the program."), &showlist);
2181 set_cmd_completer (c, noop_completer);
2183 add_prefix_cmd ("unset", no_class, unset_command,
2184 _("Complement to certain \"set\" commands."),
2185 &unsetlist, "unset ", 0, &cmdlist);
2187 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2188 Cancel environment variable VAR for the program.\n\
2189 This does not affect the program until the next \"run\" command."),
2191 set_cmd_completer (c, noop_completer);
2193 c = add_cmd ("environment", class_run, set_environment_command, _("\
2194 Set environment variable value to give the program.\n\
2195 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2196 VALUES of environment variables are uninterpreted strings.\n\
2197 This does not affect the program until the next \"run\" command."),
2199 set_cmd_completer (c, noop_completer);
2201 c = add_com ("path", class_files, path_command, _("\
2202 Add directory DIR(s) to beginning of search path for object files.\n\
2203 $cwd in the path means the current working directory.\n\
2204 This path is equivalent to the $PATH shell variable. It is a list of\n\
2205 directories, separated by colons. These directories are searched to find\n\
2206 fully linked executable files and separately compiled object files as needed."));
2207 set_cmd_completer (c, filename_completer);
2209 c = add_cmd ("paths", no_class, path_info, _("\
2210 Current search path for finding object files.\n\
2211 $cwd in the path means the current working directory.\n\
2212 This path is equivalent to the $PATH shell variable. It is a list of\n\
2213 directories, separated by colons. These directories are searched to find\n\
2214 fully linked executable files and separately compiled object files as needed."),
2216 set_cmd_completer (c, noop_completer);
2218 add_com ("attach", class_run, attach_command, _("\
2219 Attach to a process or file outside of GDB.\n\
2220 This command attaches to another target, of the same type as your last\n\
2221 \"target\" command (\"info files\" will show your target stack).\n\
2222 The command may take as argument a process id or a device file.\n\
2223 For a process id, you must have permission to send the process a signal,\n\
2224 and it must have the same effective uid as the debugger.\n\
2225 When using \"attach\" with a process id, the debugger finds the\n\
2226 program running in the process, looking first in the current working\n\
2227 directory, or (if not found there) using the source file search path\n\
2228 (see the \"directory\" command). You can also use the \"file\" command\n\
2229 to specify the program, and to load its symbol table."));
2231 add_prefix_cmd ("detach", class_run, detach_command, _("\
2232 Detach a process or file previously attached.\n\
2233 If a process, it is no longer traced, and it continues its execution. If\n\
2234 you were debugging a file, the file is closed and gdb no longer accesses it."),
2235 &detachlist, "detach ", 0, &cmdlist);
2237 add_com ("disconnect", class_run, disconnect_command, _("\
2238 Disconnect from a target.\n\
2239 The target will wait for another debugger to connect. Not available for\n\
2242 add_com ("signal", class_run, signal_command, _("\
2243 Continue program giving it signal specified by the argument.\n\
2244 An argument of \"0\" means continue program without giving it a signal."));
2246 add_com ("stepi", class_run, stepi_command, _("\
2247 Step one instruction exactly.\n\
2248 Argument N means do this N times (or till program stops for another reason)."));
2249 add_com_alias ("si", "stepi", class_alias, 0);
2251 add_com ("nexti", class_run, nexti_command, _("\
2252 Step one instruction, but proceed through subroutine calls.\n\
2253 Argument N means do this N times (or till program stops for another reason)."));
2254 add_com_alias ("ni", "nexti", class_alias, 0);
2256 add_com ("finish", class_run, finish_command, _("\
2257 Execute until selected stack frame returns.\n\
2258 Upon return, the value returned is printed and put in the value history."));
2259 add_com_alias ("fin", "finish", class_run, 1);
2261 add_com ("next", class_run, next_command, _("\
2262 Step program, proceeding through subroutine calls.\n\
2263 Like the \"step\" command as long as subroutine calls do not happen;\n\
2264 when they do, the call is treated as one instruction.\n\
2265 Argument N means do this N times (or till program stops for another reason)."));
2266 add_com_alias ("n", "next", class_run, 1);
2268 add_com_alias ("S", "next", class_run, 1);
2270 add_com ("step", class_run, step_command, _("\
2271 Step program until it reaches a different source line.\n\
2272 Argument N means do this N times (or till program stops for another reason)."));
2273 add_com_alias ("s", "step", class_run, 1);
2275 c = add_com ("until", class_run, until_command, _("\
2276 Execute until the program reaches a source line greater than the current\n\
2277 or a specified location (same args as break command) within the current frame."));
2278 set_cmd_completer (c, location_completer);
2279 add_com_alias ("u", "until", class_run, 1);
2281 c = add_com ("advance", class_run, advance_command, _("\
2282 Continue the program up to the given location (same form as args for break command).\n\
2283 Execution will also stop upon exit from the current stack frame."));
2284 set_cmd_completer (c, location_completer);
2286 c = add_com ("jump", class_run, jump_command, _("\
2287 Continue program being debugged at specified line or address.\n\
2288 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2289 for an address to start at."));
2290 set_cmd_completer (c, location_completer);
2294 c = add_com ("go", class_run, go_command, _("\
2295 Usage: go <location>\n\
2296 Continue program being debugged, stopping at specified line or \n\
2298 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2299 expression for an address to start at.\n\
2300 This command is a combination of tbreak and jump."));
2301 set_cmd_completer (c, location_completer);
2305 add_com_alias ("g", "go", class_run, 1);
2307 add_com ("continue", class_run, continue_command, _("\
2308 Continue program being debugged, after signal or breakpoint.\n\
2309 If proceeding from breakpoint, a number N may be used as an argument,\n\
2310 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2311 the breakpoint won't break until the Nth time it is reached)."));
2312 add_com_alias ("c", "cont", class_run, 1);
2313 add_com_alias ("fg", "cont", class_run, 1);
2315 c = add_com ("run", class_run, run_command, _("\
2316 Start debugged program. You may specify arguments to give it.\n\
2317 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2318 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2319 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2320 To cancel previous arguments and run with no arguments,\n\
2321 use \"set args\" without arguments."));
2322 set_cmd_completer (c, filename_completer);
2323 add_com_alias ("r", "run", class_run, 1);
2325 add_com ("R", class_run, run_no_args_command,
2326 _("Start debugged program with no arguments."));
2328 c = add_com ("start", class_run, start_command, _("\
2329 Run the debugged program until the beginning of the main procedure.\n\
2330 You may specify arguments to give to your program, just as with the\n\
2331 \"run\" command."));
2332 set_cmd_completer (c, filename_completer);
2334 c = add_com ("interrupt", class_run, interrupt_target_command,
2335 _("Interrupt the execution of the debugged program."));
2336 set_cmd_async_ok (c);
2338 add_info ("registers", nofp_registers_info, _("\
2339 List of integer registers and their contents, for selected stack frame.\n\
2340 Register name as argument means describe only that register."));
2341 add_info_alias ("r", "registers", 1);
2344 add_com ("lr", class_info, nofp_registers_info, _("\
2345 List of integer registers and their contents, for selected stack frame.\n\
2346 Register name as argument means describe only that register."));
2347 add_info ("all-registers", all_registers_info, _("\
2348 List of all registers and their contents, for selected stack frame.\n\
2349 Register name as argument means describe only that register."));
2351 add_info ("program", program_info,
2352 _("Execution status of the program."));
2354 add_info ("float", float_info,
2355 _("Print the status of the floating point unit\n"));
2357 add_info ("vector", vector_info,
2358 _("Print the status of the vector unit\n"));
2360 inferior_environ = make_environ ();
2361 init_environ (inferior_environ);