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 Resume observer likewise will not be called. */
212 int suppress_run_stop_observers = 0;
214 /* Accessor routines. */
217 set_inferior_io_terminal (const char *terminal_name)
219 if (inferior_io_terminal)
220 xfree (inferior_io_terminal);
223 inferior_io_terminal = NULL;
225 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
229 get_inferior_io_terminal (void)
231 return inferior_io_terminal;
235 get_inferior_args (void)
237 if (inferior_argc != 0)
241 n = gdbarch_construct_inferior_arguments (current_gdbarch,
242 inferior_argc, inferior_argv);
243 old = set_inferior_args (n);
247 if (inferior_args == NULL)
248 inferior_args = xstrdup ("");
250 return inferior_args;
254 set_inferior_args (char *newargs)
256 char *saved_args = inferior_args;
258 inferior_args = newargs;
266 set_inferior_args_vector (int argc, char **argv)
268 inferior_argc = argc;
269 inferior_argv = argv;
272 /* Notice when `set args' is run. */
274 notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
280 /* Notice when `show args' is run. */
282 notice_args_read (struct ui_file *file, int from_tty,
283 struct cmd_list_element *c, const char *value)
285 /* Note that we ignore the passed-in value in favor of computing it
287 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
291 /* Compute command-line string given argument vector. This does the
292 same shell processing as fork_inferior. */
294 construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
298 if (STARTUP_WITH_SHELL)
300 /* This holds all the characters considered special to the
301 typical Unix shells. We include `^' because the SunOS
302 /bin/sh treats it as a synonym for `|'. */
303 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
308 /* We over-compute the size. It shouldn't matter. */
309 for (i = 0; i < argc; ++i)
310 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
312 result = (char *) xmalloc (length);
315 for (i = 0; i < argc; ++i)
320 /* Need to handle empty arguments specially. */
321 if (argv[i][0] == '\0')
328 for (cp = argv[i]; *cp; ++cp)
330 if (strchr (special, *cp) != NULL)
340 /* In this case we can't handle arguments that contain spaces,
341 tabs, or newlines -- see breakup_args(). */
345 for (i = 0; i < argc; ++i)
347 char *cp = strchr (argv[i], ' ');
349 cp = strchr (argv[i], '\t');
351 cp = strchr (argv[i], '\n');
353 error (_("can't handle command-line argument containing whitespace"));
354 length += strlen (argv[i]) + 1;
357 result = (char *) xmalloc (length);
359 for (i = 0; i < argc; ++i)
362 strcat (result, " ");
363 strcat (result, argv[i]);
371 /* This function detects whether or not a '&' character (indicating
372 background execution) has been added as *the last* of the arguments ARGS
373 of a command. If it has, it removes it and returns 1. Otherwise it
374 does nothing and returns 0. */
376 strip_bg_char (char **args)
380 p = strchr (*args, '&');
384 if (p == (*args + strlen (*args) - 1))
386 if (strlen (*args) > 1)
390 while (*p == ' ' || *p == '\t');
402 tty_command (char *file, int from_tty)
405 error_no_arg (_("terminal name for running target process"));
407 set_inferior_io_terminal (file);
410 /* Common actions to take after creating any sort of inferior, by any
411 means (running, attaching, connecting, et cetera). The target
412 should be stopped. */
415 post_create_inferior (struct target_ops *target, int from_tty)
417 /* Be sure we own the terminal in case write operations are performed. */
418 target_terminal_ours ();
420 /* If the target hasn't taken care of this already, do it now.
421 Targets which need to access registers during to_open,
422 to_create_inferior, or to_attach should do it earlier; but many
424 target_find_description ();
428 /* Sometimes the platform-specific hook loads initial shared
429 libraries, and sometimes it doesn't. Try to do so first, so
430 that we can add them with the correct value for FROM_TTY.
431 If we made all the inferior hook methods consistent,
432 this call could be removed. */
434 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
436 solib_add (NULL, from_tty, target, auto_solib_add);
439 /* Create the hooks to handle shared library load and unload
441 #ifdef SOLIB_CREATE_INFERIOR_HOOK
442 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
444 solib_create_inferior_hook ();
448 observer_notify_inferior_created (target, from_tty);
451 /* Kill the inferior if already running. This function is designed
452 to be called when we are about to start the execution of the program
453 from the beginning. Ask the user to confirm that he wants to restart
454 the program being debugged when FROM_TTY is non-null. */
457 kill_if_already_running (int from_tty)
459 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
461 /* Bail out before killing the program if we will not be able to
463 target_require_runnable ();
466 && !query ("The program being debugged has been started already.\n\
467 Start it from the beginning? "))
468 error (_("Program not restarted."));
470 no_shared_libraries (NULL, from_tty);
471 init_wait_for_inferior ();
475 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
476 a temporary breakpoint at the begining of the main program before
477 running the program. */
480 run_command_1 (char *args, int from_tty, int tbreak_at_main)
486 kill_if_already_running (from_tty);
487 clear_breakpoint_hit_counts ();
489 /* Clean up any leftovers from other runs. Some other things from
490 this function should probably be moved into target_pre_inferior. */
491 target_pre_inferior (from_tty);
493 /* Purge old solib objfiles. */
494 objfile_purge_solibs ();
498 /* The comment here used to read, "The exec file is re-read every
499 time we do a generic_mourn_inferior, so we just have to worry
500 about the symbol file." The `generic_mourn_inferior' function
501 gets called whenever the program exits. However, suppose the
502 program exits, and *then* the executable file changes? We need
503 to check again here. Since reopen_exec_file doesn't do anything
504 if the timestamp hasn't changed, I don't see the harm. */
508 /* Insert the temporary breakpoint if a location was specified. */
510 tbreak_command (main_name (), 0);
512 exec_file = (char *) get_exec_file (0);
514 /* We keep symbols from add-symbol-file, on the grounds that the
515 user might want to add some symbols before running the program
516 (right?). But sometimes (dynamic loading where the user manually
517 introduces the new symbols with add-symbol-file), the code which
518 the symbols describe does not persist between runs. Currently
519 the user has to manually nuke all symbols between runs if they
520 want them to go away (PR 2207). This is probably reasonable. */
524 if (target_can_async_p ())
525 async_disable_stdin ();
529 int async_exec = strip_bg_char (&args);
531 /* If we get a request for running in the bg but the target
532 doesn't support it, error out. */
533 if (async_exec && !target_can_async_p ())
534 error (_("Asynchronous execution not supported on this target."));
536 /* If we don't get a request of running in the bg, then we need
537 to simulate synchronous (fg) execution. */
538 if (!async_exec && target_can_async_p ())
540 /* Simulate synchronous execution */
541 async_disable_stdin ();
544 /* If there were other args, beside '&', process them. */
547 char *old_args = set_inferior_args (xstrdup (args));
554 ui_out_field_string (uiout, NULL, "Starting program");
555 ui_out_text (uiout, ": ");
557 ui_out_field_string (uiout, "execfile", exec_file);
558 ui_out_spaces (uiout, 1);
559 /* We call get_inferior_args() because we might need to compute
561 ui_out_field_string (uiout, "infargs", get_inferior_args ());
562 ui_out_text (uiout, "\n");
563 ui_out_flush (uiout);
566 /* We call get_inferior_args() because we might need to compute
568 target_create_inferior (exec_file, get_inferior_args (),
569 environ_vector (inferior_environ), from_tty);
571 /* Pass zero for FROM_TTY, because at this point the "run" command
572 has done its thing; now we are setting up the running program. */
573 post_create_inferior (¤t_target, 0);
575 /* Start the target running. */
576 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
581 run_command (char *args, int from_tty)
583 run_command_1 (args, from_tty, 0);
587 run_no_args_command (char *args, int from_tty)
589 char *old_args = set_inferior_args (xstrdup (""));
594 /* Start the execution of the program up until the beginning of the main
598 start_command (char *args, int from_tty)
600 /* Some languages such as Ada need to search inside the program
601 minimal symbols for the location where to put the temporary
602 breakpoint before starting. */
603 if (!have_minimal_symbols ())
604 error (_("No symbol table loaded. Use the \"file\" command."));
606 /* Run the program until reaching the main procedure... */
607 run_command_1 (args, from_tty, 1);
611 continue_command (char *proc_count_exp, int from_tty)
616 /* Find out whether we must run in the background. */
617 if (proc_count_exp != NULL)
618 async_exec = strip_bg_char (&proc_count_exp);
620 /* If we must run in the background, but the target can't do it,
622 if (async_exec && !target_can_async_p ())
623 error (_("Asynchronous execution not supported on this target."));
625 /* If we are not asked to run in the bg, then prepare to run in the
626 foreground, synchronously. */
627 if (!async_exec && target_can_async_p ())
629 /* Simulate synchronous execution */
630 async_disable_stdin ();
633 /* If have argument (besides '&'), set proceed count of breakpoint
635 if (proc_count_exp != NULL)
637 bpstat bs = stop_bpstat;
641 while ((stat = bpstat_num (&bs, &num)) != 0)
644 set_ignore_count (num,
645 parse_and_eval_long (proc_count_exp) - 1,
647 /* set_ignore_count prints a message ending with a period.
648 So print two spaces before "Continuing.". */
650 printf_filtered (" ");
654 if (!stopped && from_tty)
657 ("Not stopped at any breakpoint; argument ignored.\n");
662 printf_filtered (_("Continuing.\n"));
664 clear_proceed_status ();
666 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
669 /* Step until outside of current statement. */
672 step_command (char *count_string, int from_tty)
674 step_1 (0, 0, count_string);
677 /* Likewise, but skip over subroutine calls as if single instructions. */
680 next_command (char *count_string, int from_tty)
682 step_1 (1, 0, count_string);
685 /* Likewise, but step only one instruction. */
688 stepi_command (char *count_string, int from_tty)
690 step_1 (0, 1, count_string);
694 nexti_command (char *count_string, int from_tty)
696 step_1 (1, 1, count_string);
700 delete_longjmp_breakpoint_cleanup (void *arg)
702 int thread = * (int *) arg;
703 delete_longjmp_breakpoint (thread);
707 step_1 (int skip_subroutines, int single_inst, char *count_string)
710 struct frame_info *frame;
711 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
718 async_exec = strip_bg_char (&count_string);
720 /* If we get a request for running in the bg but the target
721 doesn't support it, error out. */
722 if (async_exec && !target_can_async_p ())
723 error (_("Asynchronous execution not supported on this target."));
725 /* If we don't get a request of running in the bg, then we need
726 to simulate synchronous (fg) execution. */
727 if (!async_exec && target_can_async_p ())
729 /* Simulate synchronous execution */
730 async_disable_stdin ();
733 count = count_string ? parse_and_eval_long (count_string) : 1;
735 if (!single_inst || skip_subroutines) /* leave si command alone */
737 if (in_thread_list (inferior_ptid))
738 thread = pid_to_thread_id (inferior_ptid);
740 set_longjmp_breakpoint ();
742 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
745 /* In synchronous case, all is well, just use the regular for loop. */
746 if (!target_can_async_p ())
748 for (; count > 0; count--)
750 clear_proceed_status ();
752 frame = get_current_frame ();
753 if (!frame) /* Avoid coredump here. Why tho? */
754 error (_("No current frame"));
755 step_frame_id = get_frame_id (frame);
759 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
760 if (step_range_end == 0)
763 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
764 &step_range_end) == 0)
765 error (_("Cannot find bounds of current function"));
767 target_terminal_ours ();
768 printf_filtered (_("\
769 Single stepping until exit from function %s, \n\
770 which has no line number information.\n"), name);
775 /* Say we are stepping, but stop after one insn whatever it does. */
776 step_range_start = step_range_end = 1;
777 if (!skip_subroutines)
779 Don't step over function calls, not even to functions lacking
781 step_over_calls = STEP_OVER_NONE;
784 if (skip_subroutines)
785 step_over_calls = STEP_OVER_ALL;
787 step_multi = (count > 1);
788 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
794 do_cleanups (cleanups);
797 /* In case of asynchronous target things get complicated, do only
798 one step for now, before returning control to the event loop. Let
799 the continuation figure out how many other steps we need to do,
800 and handle them one at the time, through step_once(). */
803 step_once (skip_subroutines, single_inst, count, thread);
804 /* We are running, and the continuation is installed. It will
805 disable the longjmp breakpoint as appropriate. */
806 discard_cleanups (cleanups);
810 /* Called after we are done with one step operation, to check whether
811 we need to step again, before we print the prompt and return control
812 to the user. If count is > 1, we will need to do one more call to
813 proceed(), via step_once(). Basically it is like step_once and
814 step_1_continuation are co-recursive. */
816 step_1_continuation (struct continuation_arg *arg, int error_p)
819 int skip_subroutines;
823 skip_subroutines = arg->data.integer;
824 single_inst = arg->next->data.integer;
825 count = arg->next->next->data.integer;
826 thread = arg->next->next->next->data.integer;
828 if (error_p || !step_multi || !stop_step)
830 /* We either hit an error, or stopped for some reason
831 that is not stepping, or there are no further steps
833 if (!single_inst || skip_subroutines)
834 delete_longjmp_breakpoint (thread);
838 step_once (skip_subroutines, single_inst, count - 1, thread);
841 /* Do just one step operation. If count >1 we will have to set up a
842 continuation to be done after the target stops (after this one
843 step). This is useful to implement the 'step n' kind of commands, in
844 case of asynchronous targets. We had to split step_1 into two parts,
845 one to be done before proceed() and one afterwards. This function is
846 called in case of step n with n>1, after the first step operation has
849 step_once (int skip_subroutines, int single_inst, int count, int thread)
851 struct continuation_arg *arg1;
852 struct continuation_arg *arg2;
853 struct continuation_arg *arg3;
854 struct continuation_arg *arg4;
855 struct frame_info *frame;
859 clear_proceed_status ();
861 frame = get_current_frame ();
862 if (!frame) /* Avoid coredump here. Why tho? */
863 error (_("No current frame"));
864 step_frame_id = get_frame_id (frame);
868 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
870 /* If we have no line info, switch to stepi mode. */
871 if (step_range_end == 0 && step_stop_if_no_debug)
873 step_range_start = step_range_end = 1;
875 else if (step_range_end == 0)
878 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
879 &step_range_end) == 0)
880 error (_("Cannot find bounds of current function"));
882 target_terminal_ours ();
883 printf_filtered (_("\
884 Single stepping until exit from function %s, \n\
885 which has no line number information.\n"), name);
890 /* Say we are stepping, but stop after one insn whatever it does. */
891 step_range_start = step_range_end = 1;
892 if (!skip_subroutines)
894 Don't step over function calls, not even to functions lacking
896 step_over_calls = STEP_OVER_NONE;
899 if (skip_subroutines)
900 step_over_calls = STEP_OVER_ALL;
902 step_multi = (count > 1);
903 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
905 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
907 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
909 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
911 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
913 arg1->data.integer = skip_subroutines;
915 arg2->data.integer = single_inst;
917 arg3->data.integer = count;
919 arg4->data.integer = thread;
920 add_intermediate_continuation (step_1_continuation, arg1);
925 /* Continue program at specified address. */
928 jump_command (char *arg, int from_tty)
931 struct symtabs_and_lines sals;
932 struct symtab_and_line sal;
939 /* Find out whether we must run in the background. */
941 async_exec = strip_bg_char (&arg);
943 /* If we must run in the background, but the target can't do it,
945 if (async_exec && !target_can_async_p ())
946 error (_("Asynchronous execution not supported on this target."));
949 error_no_arg (_("starting address"));
951 sals = decode_line_spec_1 (arg, 1);
954 error (_("Unreasonable jump request"));
960 if (sal.symtab == 0 && sal.pc == 0)
961 error (_("No source file has been specified."));
963 resolve_sal_pc (&sal); /* May error out */
965 /* See if we are trying to jump to another function. */
966 fn = get_frame_function (get_current_frame ());
967 sfn = find_pc_function (sal.pc);
968 if (fn != NULL && sfn != fn)
970 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
971 SYMBOL_PRINT_NAME (fn)))
973 error (_("Not confirmed."));
980 fixup_symbol_section (sfn, 0);
981 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
982 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
984 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
986 error (_("Not confirmed."));
996 printf_filtered (_("Continuing at "));
997 fputs_filtered (paddress (addr), gdb_stdout);
998 printf_filtered (".\n");
1001 /* If we are not asked to run in the bg, then prepare to run in the
1002 foreground, synchronously. */
1003 if (!async_exec && target_can_async_p ())
1005 /* Simulate synchronous execution */
1006 async_disable_stdin ();
1009 clear_proceed_status ();
1010 proceed (addr, TARGET_SIGNAL_0, 0);
1014 /* Go to line or address in current procedure */
1016 go_command (char *line_no, int from_tty)
1018 if (line_no == (char *) NULL || !*line_no)
1019 printf_filtered (GO_USAGE);
1022 tbreak_command (line_no, from_tty);
1023 jump_command (line_no, from_tty);
1028 /* Continue program giving it specified signal. */
1031 signal_command (char *signum_exp, int from_tty)
1033 enum target_signal oursig;
1036 dont_repeat (); /* Too dangerous. */
1039 /* Find out whether we must run in the background. */
1040 if (signum_exp != NULL)
1041 async_exec = strip_bg_char (&signum_exp);
1043 /* If we must run in the background, but the target can't do it,
1045 if (async_exec && !target_can_async_p ())
1046 error (_("Asynchronous execution not supported on this target."));
1048 /* If we are not asked to run in the bg, then prepare to run in the
1049 foreground, synchronously. */
1050 if (!async_exec && target_can_async_p ())
1052 /* Simulate synchronous execution. */
1053 async_disable_stdin ();
1057 error_no_arg (_("signal number"));
1059 /* It would be even slicker to make signal names be valid expressions,
1060 (the type could be "enum $signal" or some such), then the user could
1061 assign them to convenience variables. */
1062 oursig = target_signal_from_name (signum_exp);
1064 if (oursig == TARGET_SIGNAL_UNKNOWN)
1066 /* No, try numeric. */
1067 int num = parse_and_eval_long (signum_exp);
1070 oursig = TARGET_SIGNAL_0;
1072 oursig = target_signal_from_command (num);
1077 if (oursig == TARGET_SIGNAL_0)
1078 printf_filtered (_("Continuing with no signal.\n"));
1080 printf_filtered (_("Continuing with signal %s.\n"),
1081 target_signal_to_name (oursig));
1084 clear_proceed_status ();
1085 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1086 FIXME: Neither should "signal foo" but when I tried passing
1087 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1088 tried to track down yet. */
1089 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
1092 /* Proceed until we reach a different source line with pc greater than
1093 our current one or exit the function. We skip calls in both cases.
1095 Note that eventually this command should probably be changed so
1096 that only source lines are printed out when we hit the breakpoint
1097 we set. This may involve changes to wait_for_inferior and the
1098 proceed status code. */
1101 until_next_command (int from_tty)
1103 struct frame_info *frame;
1105 struct symbol *func;
1106 struct symtab_and_line sal;
1108 clear_proceed_status ();
1110 frame = get_current_frame ();
1112 /* Step until either exited from this function or greater
1113 than the current line (if in symbolic section) or pc (if
1117 func = find_pc_function (pc);
1121 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1123 if (msymbol == NULL)
1124 error (_("Execution is not within a known function."));
1126 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1127 step_range_end = pc;
1131 sal = find_pc_line (pc, 0);
1133 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1134 step_range_end = sal.end;
1137 step_over_calls = STEP_OVER_ALL;
1138 step_frame_id = get_frame_id (frame);
1140 step_multi = 0; /* Only one call to proceed */
1142 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1146 until_command (char *arg, int from_tty)
1150 if (!target_has_execution)
1151 error (_("The program is not running."));
1153 /* Find out whether we must run in the background. */
1155 async_exec = strip_bg_char (&arg);
1157 /* If we must run in the background, but the target can't do it,
1159 if (async_exec && !target_can_async_p ())
1160 error (_("Asynchronous execution not supported on this target."));
1162 /* If we are not asked to run in the bg, then prepare to run in the
1163 foreground, synchronously. */
1164 if (!async_exec && target_can_async_p ())
1166 /* Simulate synchronous execution */
1167 async_disable_stdin ();
1171 until_break_command (arg, from_tty, 0);
1173 until_next_command (from_tty);
1177 advance_command (char *arg, int from_tty)
1181 if (!target_has_execution)
1182 error (_("The program is not running."));
1185 error_no_arg (_("a location"));
1187 /* Find out whether we must run in the background. */
1189 async_exec = strip_bg_char (&arg);
1191 /* If we must run in the background, but the target can't do it,
1193 if (async_exec && !target_can_async_p ())
1194 error (_("Asynchronous execution not supported on this target."));
1196 /* If we are not asked to run in the bg, then prepare to run in the
1197 foreground, synchronously. */
1198 if (!async_exec && target_can_async_p ())
1200 /* Simulate synchronous execution. */
1201 async_disable_stdin ();
1204 until_break_command (arg, from_tty, 1);
1207 /* Print the result of a function at the end of a 'finish' command. */
1210 print_return_value (struct type *func_type, struct type *value_type)
1212 struct gdbarch *gdbarch = current_gdbarch;
1213 struct cleanup *old_chain;
1214 struct ui_stream *stb;
1215 struct value *value;
1217 CHECK_TYPEDEF (value_type);
1218 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1220 /* FIXME: 2003-09-27: When returning from a nested inferior function
1221 call, it's possible (with no help from the architecture vector)
1222 to locate and return/print a "struct return" value. This is just
1223 a more complicated case of what is already being done in in the
1224 inferior function call code. In fact, when inferior function
1225 calls are made async, this will likely be made the norm. */
1227 switch (gdbarch_return_value (gdbarch, func_type, value_type,
1230 case RETURN_VALUE_REGISTER_CONVENTION:
1231 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1232 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1233 value = allocate_value (value_type);
1234 gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
1235 value_contents_raw (value), NULL);
1237 case RETURN_VALUE_STRUCT_CONVENTION:
1241 internal_error (__FILE__, __LINE__, _("bad switch"));
1247 stb = ui_out_stream_new (uiout);
1248 old_chain = make_cleanup_ui_out_stream_delete (stb);
1249 ui_out_text (uiout, "Value returned is ");
1250 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1251 record_latest_value (value));
1252 ui_out_text (uiout, " = ");
1253 value_print (value, stb->stream, 0, Val_no_prettyprint);
1254 ui_out_field_stream (uiout, "return-value", stb);
1255 ui_out_text (uiout, "\n");
1256 do_cleanups (old_chain);
1260 ui_out_text (uiout, "Value returned has type: ");
1261 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1262 ui_out_text (uiout, ".");
1263 ui_out_text (uiout, " Cannot determine contents\n");
1267 /* Stuff that needs to be done by the finish command after the target
1268 has stopped. In asynchronous mode, we wait for the target to stop
1269 in the call to poll or select in the event loop, so it is
1270 impossible to do all the stuff as part of the finish_command
1271 function itself. The only chance we have to complete this command
1272 is in fetch_inferior_event, which is called by the event loop as
1273 soon as it detects that the target has stopped. This function is
1274 called via the cmd_continuation pointer. */
1277 finish_command_continuation (struct continuation_arg *arg, int error_p)
1279 struct symbol *function;
1280 struct breakpoint *breakpoint;
1281 struct cleanup *cleanups;
1283 breakpoint = (struct breakpoint *) arg->data.pointer;
1284 function = (struct symbol *) arg->next->data.pointer;
1288 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1289 && function != NULL)
1291 struct type *value_type;
1293 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1295 internal_error (__FILE__, __LINE__,
1296 _("finish_command: function has no target type"));
1298 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1299 print_return_value (SYMBOL_TYPE (function), value_type);
1302 /* We suppress normal call of normal_stop observer and do it here so that
1303 that *stopped notification includes the return value. */
1304 observer_notify_normal_stop (stop_bpstat);
1307 suppress_run_stop_observers = 0;
1308 delete_breakpoint (breakpoint);
1311 /* "finish": Set a temporary breakpoint at the place the selected
1312 frame will return to, then continue. */
1315 finish_command (char *arg, int from_tty)
1317 struct symtab_and_line sal;
1318 struct frame_info *frame;
1319 struct symbol *function;
1320 struct breakpoint *breakpoint;
1321 struct cleanup *old_chain;
1322 struct continuation_arg *arg1, *arg2, *arg3;
1326 /* Find out whether we must run in the background. */
1328 async_exec = strip_bg_char (&arg);
1330 /* If we must run in the background, but the target can't do it,
1332 if (async_exec && !target_can_async_p ())
1333 error (_("Asynchronous execution not supported on this target."));
1335 /* If we are not asked to run in the bg, then prepare to run in the
1336 foreground, synchronously. */
1337 if (!async_exec && target_can_async_p ())
1339 /* Simulate synchronous execution. */
1340 async_disable_stdin ();
1344 error (_("The \"finish\" command does not take any arguments."));
1345 if (!target_has_execution)
1346 error (_("The program is not running."));
1348 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1350 error (_("\"finish\" not meaningful in the outermost frame."));
1352 clear_proceed_status ();
1354 sal = find_pc_line (get_frame_pc (frame), 0);
1355 sal.pc = get_frame_pc (frame);
1357 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
1359 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1361 /* Find the function we will return from. */
1363 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1365 /* Print info on the selected frame, including level number but not
1369 printf_filtered (_("Run till exit from "));
1370 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1373 proceed_to_finish = 1; /* We want stop_registers, please... */
1374 make_cleanup_restore_integer (&suppress_run_stop_observers);
1375 suppress_run_stop_observers = 1;
1376 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1379 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1381 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1384 arg1->data.pointer = breakpoint;
1385 arg2->data.pointer = function;
1386 add_continuation (finish_command_continuation, arg1);
1388 discard_cleanups (old_chain);
1389 if (!target_can_async_p ())
1390 do_all_continuations (0);
1395 program_info (char *args, int from_tty)
1397 bpstat bs = stop_bpstat;
1399 int stat = bpstat_num (&bs, &num);
1401 if (!target_has_execution)
1403 printf_filtered (_("The program being debugged is not being run.\n"));
1407 target_files_info ();
1408 printf_filtered (_("Program stopped at %s.\n"),
1409 hex_string ((unsigned long) stop_pc));
1411 printf_filtered (_("It stopped after being stepped.\n"));
1414 /* There may be several breakpoints in the same place, so this
1415 isn't as strange as it seems. */
1420 printf_filtered (_("\
1421 It stopped at a breakpoint that has since been deleted.\n"));
1424 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1425 stat = bpstat_num (&bs, &num);
1428 else if (stop_signal != TARGET_SIGNAL_0)
1430 printf_filtered (_("It stopped with signal %s, %s.\n"),
1431 target_signal_to_name (stop_signal),
1432 target_signal_to_string (stop_signal));
1437 printf_filtered (_("\
1438 Type \"info stack\" or \"info registers\" for more information.\n"));
1443 environment_info (char *var, int from_tty)
1447 char *val = get_in_environ (inferior_environ, var);
1450 puts_filtered (var);
1451 puts_filtered (" = ");
1452 puts_filtered (val);
1453 puts_filtered ("\n");
1457 puts_filtered ("Environment variable \"");
1458 puts_filtered (var);
1459 puts_filtered ("\" not defined.\n");
1464 char **vector = environ_vector (inferior_environ);
1467 puts_filtered (*vector++);
1468 puts_filtered ("\n");
1474 set_environment_command (char *arg, int from_tty)
1476 char *p, *val, *var;
1480 error_no_arg (_("environment variable and value"));
1482 /* Find seperation between variable name and value */
1483 p = (char *) strchr (arg, '=');
1484 val = (char *) strchr (arg, ' ');
1486 if (p != 0 && val != 0)
1488 /* We have both a space and an equals. If the space is before the
1489 equals, walk forward over the spaces til we see a nonspace
1490 (possibly the equals). */
1495 /* Now if the = is after the char following the spaces,
1496 take the char following the spaces. */
1500 else if (val != 0 && p == 0)
1504 error_no_arg (_("environment variable to set"));
1506 if (p == 0 || p[1] == 0)
1510 p = arg + strlen (arg); /* So that savestring below will work */
1514 /* Not setting variable value to null */
1516 while (*val == ' ' || *val == '\t')
1520 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1523 var = savestring (arg, p - arg);
1526 printf_filtered (_("\
1527 Setting environment variable \"%s\" to null value.\n"),
1529 set_in_environ (inferior_environ, var, "");
1532 set_in_environ (inferior_environ, var, val);
1537 unset_environment_command (char *var, int from_tty)
1541 /* If there is no argument, delete all environment variables.
1542 Ask for confirmation if reading from the terminal. */
1543 if (!from_tty || query (_("Delete all environment variables? ")))
1545 free_environ (inferior_environ);
1546 inferior_environ = make_environ ();
1550 unset_in_environ (inferior_environ, var);
1553 /* Handle the execution path (PATH variable) */
1555 static const char path_var_name[] = "PATH";
1558 path_info (char *args, int from_tty)
1560 puts_filtered ("Executable and object file path: ");
1561 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1562 puts_filtered ("\n");
1565 /* Add zero or more directories to the front of the execution path. */
1568 path_command (char *dirname, int from_tty)
1573 env = get_in_environ (inferior_environ, path_var_name);
1574 /* Can be null if path is not set */
1577 exec_path = xstrdup (env);
1578 mod_path (dirname, &exec_path);
1579 set_in_environ (inferior_environ, path_var_name, exec_path);
1582 path_info ((char *) NULL, from_tty);
1586 /* Print out the machine register regnum. If regnum is -1, print all
1587 registers (print_all == 1) or all non-float and non-vector
1588 registers (print_all == 0).
1590 For most machines, having all_registers_info() print the
1591 register(s) one per line is good enough. If a different format is
1592 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1593 regs), or there is an existing convention for showing all the
1594 registers, define the architecture method PRINT_REGISTERS_INFO to
1595 provide that format. */
1598 default_print_registers_info (struct gdbarch *gdbarch,
1599 struct ui_file *file,
1600 struct frame_info *frame,
1601 int regnum, int print_all)
1604 const int numregs = gdbarch_num_regs (gdbarch)
1605 + gdbarch_num_pseudo_regs (gdbarch);
1606 gdb_byte buffer[MAX_REGISTER_SIZE];
1608 for (i = 0; i < numregs; i++)
1610 /* Decide between printing all regs, non-float / vector regs, or
1616 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1621 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1631 /* If the register name is empty, it is undefined for this
1632 processor, so don't display anything. */
1633 if (gdbarch_register_name (gdbarch, i) == NULL
1634 || *(gdbarch_register_name (gdbarch, i)) == '\0')
1637 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1638 print_spaces_filtered (15 - strlen (gdbarch_register_name
1639 (gdbarch, i)), file);
1641 /* Get the data in raw format. */
1642 if (! frame_register_read (frame, i, buffer))
1644 fprintf_filtered (file, "*value not available*\n");
1648 /* If virtual format is floating, print it that way, and in raw
1650 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1651 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1655 val_print (register_type (gdbarch, i), buffer, 0, 0,
1656 file, 0, 1, 0, Val_pretty_default, current_language);
1658 fprintf_filtered (file, "\t(raw 0x");
1659 for (j = 0; j < register_size (gdbarch, i); j++)
1662 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1665 idx = register_size (gdbarch, i) - 1 - j;
1666 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1668 fprintf_filtered (file, ")");
1672 /* Print the register in hex. */
1673 val_print (register_type (gdbarch, i), buffer, 0, 0,
1674 file, 'x', 1, 0, Val_pretty_default, current_language);
1675 /* If not a vector register, print it also according to its
1677 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1679 fprintf_filtered (file, "\t");
1680 val_print (register_type (gdbarch, i), buffer, 0, 0,
1681 file, 0, 1, 0, Val_pretty_default, current_language);
1685 fprintf_filtered (file, "\n");
1690 registers_info (char *addr_exp, int fpregs)
1692 struct frame_info *frame;
1693 struct gdbarch *gdbarch;
1694 int regnum, numregs;
1697 if (!target_has_registers)
1698 error (_("The program has no registers now."));
1699 frame = get_selected_frame (NULL);
1700 gdbarch = get_frame_arch (frame);
1704 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1709 while (*addr_exp != '\0')
1714 /* Keep skipping leading white space. */
1715 if (isspace ((*addr_exp)))
1721 /* Discard any leading ``$''. Check that there is something
1722 resembling a register following it. */
1723 if (addr_exp[0] == '$')
1725 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1726 error (_("Missing register name"));
1728 /* Find the start/end of this register name/num/group. */
1730 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1734 /* Figure out what we've found and display it. */
1736 /* A register name? */
1738 int regnum = frame_map_name_to_regnum (frame, start, end - start);
1741 /* User registers lie completely outside of the range of
1742 normal registers. Catch them early so that the target
1744 if (regnum >= gdbarch_num_regs (gdbarch)
1745 + gdbarch_num_pseudo_regs (gdbarch))
1747 struct value *val = value_of_user_reg (regnum, frame);
1749 printf_filtered ("%s: ", start);
1750 print_scalar_formatted (value_contents (val),
1751 check_typedef (value_type (val)),
1752 'x', 0, gdb_stdout);
1753 printf_filtered ("\n");
1756 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1757 frame, regnum, fpregs);
1762 /* A register number? (how portable is this one?). */
1765 int regnum = strtol (start, &endptr, 0);
1768 && regnum < gdbarch_num_regs (gdbarch)
1769 + gdbarch_num_pseudo_regs (gdbarch))
1771 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1772 frame, regnum, fpregs);
1777 /* A register group? */
1779 struct reggroup *group;
1780 for (group = reggroup_next (gdbarch, NULL);
1782 group = reggroup_next (gdbarch, group))
1784 /* Don't bother with a length check. Should the user
1785 enter a short register group name, go with the first
1786 group that matches. */
1787 if (strncmp (start, reggroup_name (group), end - start) == 0)
1794 regnum < gdbarch_num_regs (gdbarch)
1795 + gdbarch_num_pseudo_regs (gdbarch);
1798 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1799 gdbarch_print_registers_info (gdbarch,
1807 /* Nothing matched. */
1808 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1813 all_registers_info (char *addr_exp, int from_tty)
1815 registers_info (addr_exp, 1);
1819 nofp_registers_info (char *addr_exp, int from_tty)
1821 registers_info (addr_exp, 0);
1825 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1826 struct frame_info *frame, const char *args)
1828 if (gdbarch_print_vector_info_p (gdbarch))
1829 gdbarch_print_vector_info (gdbarch, file, frame, args);
1833 int printed_something = 0;
1836 regnum < gdbarch_num_regs (gdbarch)
1837 + gdbarch_num_pseudo_regs (gdbarch);
1840 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1842 printed_something = 1;
1843 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1846 if (!printed_something)
1847 fprintf_filtered (file, "No vector information\n");
1852 vector_info (char *args, int from_tty)
1854 if (!target_has_registers)
1855 error (_("The program has no registers now."));
1857 print_vector_info (current_gdbarch, gdb_stdout,
1858 get_selected_frame (NULL), args);
1864 * Should save/restore the tty state since it might be that the
1865 * program to be debugged was started on this tty and it wants
1866 * the tty in some state other than what we want. If it's running
1867 * on another terminal or without a terminal, then saving and
1868 * restoring the tty state is a harmless no-op.
1869 * This only needs to be done if we are attaching to a process.
1874 takes a program started up outside of gdb and ``attaches'' to it.
1875 This stops it cold in its tracks and allows us to start debugging it.
1876 and wait for the trace-trap that results from attaching. */
1879 attach_command_post_wait (char *args, int from_tty, int async_exec)
1882 char *full_exec_path = NULL;
1884 stop_soon = NO_STOP_QUIETLY;
1886 /* If no exec file is yet known, try to determine it from the
1888 exec_file = (char *) get_exec_file (0);
1891 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1894 /* It's possible we don't have a full path, but rather just a
1895 filename. Some targets, such as HP-UX, don't provide the
1898 Attempt to qualify the filename against the source path.
1899 (If that fails, we'll just fall back on the original
1900 filename. Not much more we can do...)
1902 if (!source_full_path_of (exec_file, &full_exec_path))
1903 full_exec_path = savestring (exec_file, strlen (exec_file));
1905 exec_file_attach (full_exec_path, from_tty);
1906 symbol_file_add_main (full_exec_path, from_tty);
1911 reopen_exec_file ();
1915 /* Take any necessary post-attaching actions for this platform. */
1916 target_post_attach (PIDGET (inferior_ptid));
1918 post_create_inferior (¤t_target, from_tty);
1920 /* Install inferior's terminal modes. */
1921 target_terminal_inferior ();
1924 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
1927 if (target_can_async_p ())
1928 async_enable_stdin ();
1930 if (deprecated_attach_hook)
1931 deprecated_attach_hook ();
1936 attach_command_continuation (struct continuation_arg *arg, int error_p)
1942 args = (char *) arg->data.pointer;
1943 from_tty = arg->next->data.integer;
1944 async_exec = arg->next->next->data.integer;
1946 attach_command_post_wait (args, from_tty, async_exec);
1950 attach_command (char *args, int from_tty)
1953 char *full_exec_path = NULL;
1956 dont_repeat (); /* Not for the faint of heart */
1958 if (target_has_execution)
1960 if (query ("A program is being debugged already. Kill it? "))
1963 error (_("Not killed."));
1966 /* Clean up any leftovers from other runs. Some other things from
1967 this function should probably be moved into target_pre_inferior. */
1968 target_pre_inferior (from_tty);
1970 /* Clear out solib state. Otherwise the solib state of the previous
1971 inferior might have survived and is entirely wrong for the new
1972 target. This has been observed on GNU/Linux using glibc 2.3. How
1984 Cannot access memory at address 0xdeadbeef
1990 async_exec = strip_bg_char (&args);
1992 /* If we get a request for running in the bg but the target
1993 doesn't support it, error out. */
1994 if (async_exec && !target_can_async_p ())
1995 error (_("Asynchronous execution not supported on this target."));
1998 /* If we don't get a request of running in the bg, then we need
1999 to simulate synchronous (fg) execution. */
2000 if (!async_exec && target_can_async_p ())
2002 /* Simulate synchronous execution */
2003 async_disable_stdin ();
2006 target_attach (args, from_tty);
2008 /* Set up the "saved terminal modes" of the inferior
2009 based on what modes we are starting it with. */
2010 target_terminal_init ();
2012 /* Set up execution context to know that we should return from
2013 wait_for_inferior as soon as the target reports a stop. */
2014 init_wait_for_inferior ();
2015 clear_proceed_status ();
2017 /* No traps are generated when attaching to inferior under Mach 3
2019 #ifndef ATTACH_NO_WAIT
2020 /* Careful here. See comments in inferior.h. Basically some OSes
2021 don't ignore SIGSTOPs on continue requests anymore. We need a
2022 way for handle_inferior_event to reset the stop_signal variable
2023 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
2024 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2026 if (target_can_async_p ())
2028 /* sync_execution mode. Wait for stop. */
2029 struct continuation_arg *arg1, *arg2, *arg3;
2032 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2034 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2036 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2040 arg1->data.pointer = args;
2041 arg2->data.integer = from_tty;
2042 arg3->data.integer = async_exec;
2043 add_continuation (attach_command_continuation, arg1);
2047 wait_for_inferior (0);
2050 attach_command_post_wait (args, from_tty, async_exec);
2055 * takes a program previously attached to and detaches it.
2056 * The program resumes execution and will no longer stop
2057 * on signals, etc. We better not have left any breakpoints
2058 * in the program or it'll die when it hits one. For this
2059 * to work, it may be necessary for the process to have been
2060 * previously attached. It *might* work if the program was
2061 * started via the normal ptrace (PTRACE_TRACEME).
2065 detach_command (char *args, int from_tty)
2067 dont_repeat (); /* Not for the faint of heart. */
2068 target_detach (args, from_tty);
2069 no_shared_libraries (NULL, from_tty);
2070 init_thread_list ();
2071 if (deprecated_detach_hook)
2072 deprecated_detach_hook ();
2075 /* Disconnect from the current target without resuming it (leaving it
2076 waiting for a debugger).
2078 We'd better not have left any breakpoints in the program or the
2079 next debugger will get confused. Currently only supported for some
2080 remote targets, since the normal attach mechanisms don't work on
2081 stopped processes on some native platforms (e.g. GNU/Linux). */
2084 disconnect_command (char *args, int from_tty)
2086 dont_repeat (); /* Not for the faint of heart */
2087 target_disconnect (args, from_tty);
2088 no_shared_libraries (NULL, from_tty);
2089 init_thread_list ();
2090 if (deprecated_detach_hook)
2091 deprecated_detach_hook ();
2094 /* Stop the execution of the target while running in async mode, in
2097 interrupt_target_command (char *args, int from_tty)
2099 if (target_can_async_p ())
2101 dont_repeat (); /* Not for the faint of heart */
2107 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2108 struct frame_info *frame, const char *args)
2110 if (gdbarch_print_float_info_p (gdbarch))
2111 gdbarch_print_float_info (gdbarch, file, frame, args);
2115 int printed_something = 0;
2118 regnum < gdbarch_num_regs (gdbarch)
2119 + gdbarch_num_pseudo_regs (gdbarch);
2122 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2124 printed_something = 1;
2125 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2128 if (!printed_something)
2129 fprintf_filtered (file, "\
2130 No floating-point info available for this processor.\n");
2135 float_info (char *args, int from_tty)
2137 if (!target_has_registers)
2138 error (_("The program has no registers now."));
2140 print_float_info (current_gdbarch, gdb_stdout,
2141 get_selected_frame (NULL), args);
2145 unset_command (char *args, int from_tty)
2147 printf_filtered (_("\
2148 \"unset\" must be followed by the name of an unset subcommand.\n"));
2149 help_list (unsetlist, "unset ", -1, gdb_stdout);
2153 _initialize_infcmd (void)
2155 struct cmd_list_element *c = NULL;
2157 /* add the filename of the terminal connected to inferior I/O */
2158 add_setshow_filename_cmd ("inferior-tty", class_run,
2159 &inferior_io_terminal, _("\
2160 Set terminal for future runs of program being debugged."), _("\
2161 Show terminal for future runs of program being debugged."), _("\
2162 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2163 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2165 add_setshow_optional_filename_cmd ("args", class_run,
2166 &inferior_args, _("\
2167 Set argument list to give program being debugged when it is started."), _("\
2168 Show argument list to give program being debugged when it is started."), _("\
2169 Follow this command with any number of args, to be passed to the program."),
2172 &setlist, &showlist);
2174 c = add_cmd ("environment", no_class, environment_info, _("\
2175 The environment to give the program, or one variable's value.\n\
2176 With an argument VAR, prints the value of environment variable VAR to\n\
2177 give the program being debugged. With no arguments, prints the entire\n\
2178 environment to be given to the program."), &showlist);
2179 set_cmd_completer (c, noop_completer);
2181 add_prefix_cmd ("unset", no_class, unset_command,
2182 _("Complement to certain \"set\" commands."),
2183 &unsetlist, "unset ", 0, &cmdlist);
2185 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2186 Cancel environment variable VAR for the program.\n\
2187 This does not affect the program until the next \"run\" command."),
2189 set_cmd_completer (c, noop_completer);
2191 c = add_cmd ("environment", class_run, set_environment_command, _("\
2192 Set environment variable value to give the program.\n\
2193 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2194 VALUES of environment variables are uninterpreted strings.\n\
2195 This does not affect the program until the next \"run\" command."),
2197 set_cmd_completer (c, noop_completer);
2199 c = add_com ("path", class_files, path_command, _("\
2200 Add directory DIR(s) to beginning of search path for object files.\n\
2201 $cwd in the path means the current working directory.\n\
2202 This path is equivalent to the $PATH shell variable. It is a list of\n\
2203 directories, separated by colons. These directories are searched to find\n\
2204 fully linked executable files and separately compiled object files as needed."));
2205 set_cmd_completer (c, filename_completer);
2207 c = add_cmd ("paths", no_class, path_info, _("\
2208 Current search path for finding object files.\n\
2209 $cwd in the path means the current working directory.\n\
2210 This path is equivalent to the $PATH shell variable. It is a list of\n\
2211 directories, separated by colons. These directories are searched to find\n\
2212 fully linked executable files and separately compiled object files as needed."),
2214 set_cmd_completer (c, noop_completer);
2216 add_com ("attach", class_run, attach_command, _("\
2217 Attach to a process or file outside of GDB.\n\
2218 This command attaches to another target, of the same type as your last\n\
2219 \"target\" command (\"info files\" will show your target stack).\n\
2220 The command may take as argument a process id or a device file.\n\
2221 For a process id, you must have permission to send the process a signal,\n\
2222 and it must have the same effective uid as the debugger.\n\
2223 When using \"attach\" with a process id, the debugger finds the\n\
2224 program running in the process, looking first in the current working\n\
2225 directory, or (if not found there) using the source file search path\n\
2226 (see the \"directory\" command). You can also use the \"file\" command\n\
2227 to specify the program, and to load its symbol table."));
2229 add_prefix_cmd ("detach", class_run, detach_command, _("\
2230 Detach a process or file previously attached.\n\
2231 If a process, it is no longer traced, and it continues its execution. If\n\
2232 you were debugging a file, the file is closed and gdb no longer accesses it."),
2233 &detachlist, "detach ", 0, &cmdlist);
2235 add_com ("disconnect", class_run, disconnect_command, _("\
2236 Disconnect from a target.\n\
2237 The target will wait for another debugger to connect. Not available for\n\
2240 add_com ("signal", class_run, signal_command, _("\
2241 Continue program giving it signal specified by the argument.\n\
2242 An argument of \"0\" means continue program without giving it a signal."));
2244 add_com ("stepi", class_run, stepi_command, _("\
2245 Step one instruction exactly.\n\
2246 Argument N means do this N times (or till program stops for another reason)."));
2247 add_com_alias ("si", "stepi", class_alias, 0);
2249 add_com ("nexti", class_run, nexti_command, _("\
2250 Step one instruction, but proceed through subroutine calls.\n\
2251 Argument N means do this N times (or till program stops for another reason)."));
2252 add_com_alias ("ni", "nexti", class_alias, 0);
2254 add_com ("finish", class_run, finish_command, _("\
2255 Execute until selected stack frame returns.\n\
2256 Upon return, the value returned is printed and put in the value history."));
2257 add_com_alias ("fin", "finish", class_run, 1);
2259 add_com ("next", class_run, next_command, _("\
2260 Step program, proceeding through subroutine calls.\n\
2261 Like the \"step\" command as long as subroutine calls do not happen;\n\
2262 when they do, the call is treated as one instruction.\n\
2263 Argument N means do this N times (or till program stops for another reason)."));
2264 add_com_alias ("n", "next", class_run, 1);
2266 add_com_alias ("S", "next", class_run, 1);
2268 add_com ("step", class_run, step_command, _("\
2269 Step program until it reaches a different source line.\n\
2270 Argument N means do this N times (or till program stops for another reason)."));
2271 add_com_alias ("s", "step", class_run, 1);
2273 c = add_com ("until", class_run, until_command, _("\
2274 Execute until the program reaches a source line greater than the current\n\
2275 or a specified location (same args as break command) within the current frame."));
2276 set_cmd_completer (c, location_completer);
2277 add_com_alias ("u", "until", class_run, 1);
2279 c = add_com ("advance", class_run, advance_command, _("\
2280 Continue the program up to the given location (same form as args for break command).\n\
2281 Execution will also stop upon exit from the current stack frame."));
2282 set_cmd_completer (c, location_completer);
2284 c = add_com ("jump", class_run, jump_command, _("\
2285 Continue program being debugged at specified line or address.\n\
2286 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2287 for an address to start at."));
2288 set_cmd_completer (c, location_completer);
2292 c = add_com ("go", class_run, go_command, _("\
2293 Usage: go <location>\n\
2294 Continue program being debugged, stopping at specified line or \n\
2296 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2297 expression for an address to start at.\n\
2298 This command is a combination of tbreak and jump."));
2299 set_cmd_completer (c, location_completer);
2303 add_com_alias ("g", "go", class_run, 1);
2305 add_com ("continue", class_run, continue_command, _("\
2306 Continue program being debugged, after signal or breakpoint.\n\
2307 If proceeding from breakpoint, a number N may be used as an argument,\n\
2308 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2309 the breakpoint won't break until the Nth time it is reached)."));
2310 add_com_alias ("c", "cont", class_run, 1);
2311 add_com_alias ("fg", "cont", class_run, 1);
2313 c = add_com ("run", class_run, run_command, _("\
2314 Start debugged program. You may specify arguments to give it.\n\
2315 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2316 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2317 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2318 To cancel previous arguments and run with no arguments,\n\
2319 use \"set args\" without arguments."));
2320 set_cmd_completer (c, filename_completer);
2321 add_com_alias ("r", "run", class_run, 1);
2323 add_com ("R", class_run, run_no_args_command,
2324 _("Start debugged program with no arguments."));
2326 c = add_com ("start", class_run, start_command, _("\
2327 Run the debugged program until the beginning of the main procedure.\n\
2328 You may specify arguments to give to your program, just as with the\n\
2329 \"run\" command."));
2330 set_cmd_completer (c, filename_completer);
2332 c = add_com ("interrupt", class_run, interrupt_target_command,
2333 _("Interrupt the execution of the debugged program."));
2334 set_cmd_async_ok (c);
2336 add_info ("registers", nofp_registers_info, _("\
2337 List of integer registers and their contents, for selected stack frame.\n\
2338 Register name as argument means describe only that register."));
2339 add_info_alias ("r", "registers", 1);
2342 add_com ("lr", class_info, nofp_registers_info, _("\
2343 List of integer registers and their contents, for selected stack frame.\n\
2344 Register name as argument means describe only that register."));
2345 add_info ("all-registers", all_registers_info, _("\
2346 List of all registers and their contents, for selected stack frame.\n\
2347 Register name as argument means describe only that register."));
2349 add_info ("program", program_info,
2350 _("Execution status of the program."));
2352 add_info ("float", float_info,
2353 _("Print the status of the floating point unit\n"));
2355 add_info ("vector", vector_info,
2356 _("Print the status of the vector unit\n"));
2358 inferior_environ = make_environ ();
2359 init_environ (inferior_environ);