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, 2009, 2010, 2011 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/>. */
23 #include "arch-utils.h"
25 #include "gdb_string.h"
39 #include "completer.h"
41 #include "event-top.h"
42 #include "parser-defs.h"
44 #include "reggroups.h"
48 #include "gdb_assert.h"
50 #include "target-descriptions.h"
51 #include "user-regs.h"
52 #include "exceptions.h"
53 #include "cli/cli-decode.h"
54 #include "gdbthread.h"
56 #include "inline-frame.h"
57 #include "tracepoint.h"
60 /* Functions exported for general use, in inferior.h: */
62 void all_registers_info (char *, int);
64 void registers_info (char *, int);
66 void nexti_command (char *, int);
68 void stepi_command (char *, int);
70 void continue_command (char *, int);
72 void interrupt_target_command (char *args
, int from_tty
);
74 /* Local functions: */
76 static void nofp_registers_info (char *, int);
78 static void print_return_value (struct type
*func_type
,
79 struct type
*value_type
);
81 static void until_next_command (int);
83 static void until_command (char *, int);
85 static void path_info (char *, int);
87 static void path_command (char *, int);
89 static void unset_command (char *, int);
91 static void float_info (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
,
111 int count
, int thread
);
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 ERROR_NO_INFERIOR \
128 if (!target_has_execution) error (_("The program is not being run."));
130 /* Scratch area where string containing arguments to give to the
131 program will be stored by 'set args'. As soon as anything is
132 stored, notice_args_set will move it into per-inferior storage.
133 Arguments are separated by spaces. Empty string (pointer to '\0')
136 static char *inferior_args_scratch
;
138 /* Scratch area where 'set inferior-tty' will store user-provided value.
139 We'll immediate copy it into per-inferior storage. */
141 static char *inferior_io_terminal_scratch
;
143 /* Pid of our debugged inferior, or 0 if no inferior now.
144 Since various parts of infrun.c test this to see whether there is a program
145 being debugged it should be nonzero (currently 3 is used) for remote
148 ptid_t inferior_ptid
;
150 /* Address at which inferior stopped. */
154 /* Flag indicating that a command has proceeded the inferior past the
155 current breakpoint. */
157 int breakpoint_proceeded
;
159 /* Nonzero if stopped due to completion of a stack dummy routine. */
161 enum stop_stack_kind stop_stack_dummy
;
163 /* Nonzero if stopped due to a random (unexpected) signal in inferior
166 int stopped_by_random_signal
;
169 /* Accessor routines. */
171 /* Set the io terminal for the current inferior. Ownership of
172 TERMINAL_NAME is not transferred. */
175 set_inferior_io_terminal (const char *terminal_name
)
177 xfree (current_inferior ()->terminal
);
178 current_inferior ()->terminal
= terminal_name
? xstrdup (terminal_name
) : 0;
182 get_inferior_io_terminal (void)
184 return current_inferior ()->terminal
;
188 set_inferior_tty_command (char *args
, int from_tty
,
189 struct cmd_list_element
*c
)
191 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
192 Now route it to current inferior. */
193 set_inferior_io_terminal (inferior_io_terminal_scratch
);
197 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
198 struct cmd_list_element
*c
, const char *value
)
200 /* Note that we ignore the passed-in value in favor of computing it
202 const char *inferior_io_terminal
= get_inferior_io_terminal ();
204 if (inferior_io_terminal
== NULL
)
205 inferior_io_terminal
= "";
206 fprintf_filtered (gdb_stdout
,
207 _("Terminal for future runs of program being debugged "
208 "is \"%s\".\n"), inferior_io_terminal
);
212 get_inferior_args (void)
214 if (current_inferior ()->argc
!= 0)
218 n
= construct_inferior_arguments (current_inferior ()->argc
,
219 current_inferior ()->argv
);
220 set_inferior_args (n
);
224 if (current_inferior ()->args
== NULL
)
225 current_inferior ()->args
= xstrdup ("");
227 return current_inferior ()->args
;
230 /* Set the arguments for the current inferior. Ownership of
231 NEWARGS is not transferred. */
234 set_inferior_args (char *newargs
)
236 xfree (current_inferior ()->args
);
237 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
238 current_inferior ()->argc
= 0;
239 current_inferior ()->argv
= 0;
243 set_inferior_args_vector (int argc
, char **argv
)
245 current_inferior ()->argc
= argc
;
246 current_inferior ()->argv
= argv
;
249 /* Notice when `set args' is run. */
251 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
253 /* CLI has assigned the user-provided value to inferior_args_scratch.
254 Now route it to current inferior. */
255 set_inferior_args (inferior_args_scratch
);
258 /* Notice when `show args' is run. */
260 show_args_command (struct ui_file
*file
, int from_tty
,
261 struct cmd_list_element
*c
, const char *value
)
263 /* Note that we ignore the passed-in value in favor of computing it
265 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
269 /* Compute command-line string given argument vector. This does the
270 same shell processing as fork_inferior. */
272 construct_inferior_arguments (int argc
, char **argv
)
276 if (STARTUP_WITH_SHELL
)
278 /* This holds all the characters considered special to the
279 typical Unix shells. We include `^' because the SunOS
280 /bin/sh treats it as a synonym for `|'. */
281 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
286 /* We over-compute the size. It shouldn't matter. */
287 for (i
= 0; i
< argc
; ++i
)
288 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
290 result
= (char *) xmalloc (length
);
293 for (i
= 0; i
< argc
; ++i
)
298 /* Need to handle empty arguments specially. */
299 if (argv
[i
][0] == '\0')
306 for (cp
= argv
[i
]; *cp
; ++cp
)
310 /* A newline cannot be quoted with a backslash (it
311 just disappears), only by putting it inside
319 if (strchr (special
, *cp
) != NULL
)
330 /* In this case we can't handle arguments that contain spaces,
331 tabs, or newlines -- see breakup_args(). */
335 for (i
= 0; i
< argc
; ++i
)
337 char *cp
= strchr (argv
[i
], ' ');
339 cp
= strchr (argv
[i
], '\t');
341 cp
= strchr (argv
[i
], '\n');
343 error (_("can't handle command-line "
344 "argument containing whitespace"));
345 length
+= strlen (argv
[i
]) + 1;
348 result
= (char *) xmalloc (length
);
350 for (i
= 0; i
< argc
; ++i
)
353 strcat (result
, " ");
354 strcat (result
, argv
[i
]);
362 /* This function detects whether or not a '&' character (indicating
363 background execution) has been added as *the last* of the arguments ARGS
364 of a command. If it has, it removes it and returns 1. Otherwise it
365 does nothing and returns 0. */
367 strip_bg_char (char **args
)
371 p
= strchr (*args
, '&');
375 if (p
== (*args
+ strlen (*args
) - 1))
377 if (strlen (*args
) > 1)
381 while (*p
== ' ' || *p
== '\t');
392 /* Common actions to take after creating any sort of inferior, by any
393 means (running, attaching, connecting, et cetera). The target
394 should be stopped. */
397 post_create_inferior (struct target_ops
*target
, int from_tty
)
399 volatile struct gdb_exception ex
;
401 /* Be sure we own the terminal in case write operations are performed. */
402 target_terminal_ours ();
404 /* If the target hasn't taken care of this already, do it now.
405 Targets which need to access registers during to_open,
406 to_create_inferior, or to_attach should do it earlier; but many
408 target_find_description ();
410 /* Now that we know the register layout, retrieve current PC. But
411 if the PC is unavailable (e.g., we're opening a core file with
412 missing registers info), ignore it. */
414 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
416 stop_pc
= regcache_read_pc (get_current_regcache ());
418 if (ex
.reason
< 0 && ex
.error
!= NOT_AVAILABLE_ERROR
)
419 throw_exception (ex
);
423 /* Create the hooks to handle shared library load and unload
425 #ifdef SOLIB_CREATE_INFERIOR_HOOK
426 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
428 solib_create_inferior_hook (from_tty
);
432 /* If the solist is global across processes, there's no need to
434 if (exec_bfd
&& !gdbarch_has_global_solist (target_gdbarch
))
436 /* Sometimes the platform-specific hook loads initial shared
437 libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be
438 incorrectly 0 but such solib targets should be fixed anyway. If we
439 made all the inferior hook methods consistent, this call could be
440 removed. Call it only after the solib target has been initialized by
441 solib_create_inferior_hook. */
444 SOLIB_ADD (NULL
, 0, target
, auto_solib_add
);
446 solib_add (NULL
, 0, target
, auto_solib_add
);
450 /* If the user sets watchpoints before execution having started,
451 then she gets software watchpoints, because GDB can't know which
452 target will end up being pushed, or if it supports hardware
453 watchpoints or not. breakpoint_re_set takes care of promoting
454 watchpoints to hardware watchpoints if possible, however, if this
455 new inferior doesn't load shared libraries or we don't pull in
456 symbols from any other source on this target/arch,
457 breakpoint_re_set is never called. Call it now so that software
458 watchpoints get a chance to be promoted to hardware watchpoints
459 if the now pushed target supports hardware watchpoints. */
460 breakpoint_re_set ();
462 observer_notify_inferior_created (target
, from_tty
);
465 /* Kill the inferior if already running. This function is designed
466 to be called when we are about to start the execution of the program
467 from the beginning. Ask the user to confirm that he wants to restart
468 the program being debugged when FROM_TTY is non-null. */
471 kill_if_already_running (int from_tty
)
473 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
475 /* Bail out before killing the program if we will not be able to
477 target_require_runnable ();
480 && !query (_("The program being debugged has been started already.\n\
481 Start it from the beginning? ")))
482 error (_("Program not restarted."));
487 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
488 a temporary breakpoint at the begining of the main program before
489 running the program. */
492 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
495 struct cleanup
*old_chain
;
500 kill_if_already_running (from_tty
);
502 init_wait_for_inferior ();
503 clear_breakpoint_hit_counts ();
505 /* Clean up any leftovers from other runs. Some other things from
506 this function should probably be moved into target_pre_inferior. */
507 target_pre_inferior (from_tty
);
509 /* The comment here used to read, "The exec file is re-read every
510 time we do a generic_mourn_inferior, so we just have to worry
511 about the symbol file." The `generic_mourn_inferior' function
512 gets called whenever the program exits. However, suppose the
513 program exits, and *then* the executable file changes? We need
514 to check again here. Since reopen_exec_file doesn't do anything
515 if the timestamp hasn't changed, I don't see the harm. */
519 /* Insert the temporary breakpoint if a location was specified. */
521 tbreak_command (main_name (), 0);
523 exec_file
= (char *) get_exec_file (0);
525 if (non_stop
&& !target_supports_non_stop ())
526 error (_("The target does not support running in non-stop mode."));
528 /* We keep symbols from add-symbol-file, on the grounds that the
529 user might want to add some symbols before running the program
530 (right?). But sometimes (dynamic loading where the user manually
531 introduces the new symbols with add-symbol-file), the code which
532 the symbols describe does not persist between runs. Currently
533 the user has to manually nuke all symbols between runs if they
534 want them to go away (PR 2207). This is probably reasonable. */
538 if (target_can_async_p ())
539 async_disable_stdin ();
543 int async_exec
= strip_bg_char (&args
);
545 /* If we get a request for running in the bg but the target
546 doesn't support it, error out. */
547 if (async_exec
&& !target_can_async_p ())
548 error (_("Asynchronous execution not supported on this target."));
550 /* If we don't get a request of running in the bg, then we need
551 to simulate synchronous (fg) execution. */
552 if (!async_exec
&& target_can_async_p ())
554 /* Simulate synchronous execution. */
555 async_disable_stdin ();
558 /* If there were other args, beside '&', process them. */
560 set_inferior_args (args
);
565 ui_out_field_string (uiout
, NULL
, "Starting program");
566 ui_out_text (uiout
, ": ");
568 ui_out_field_string (uiout
, "execfile", exec_file
);
569 ui_out_spaces (uiout
, 1);
570 /* We call get_inferior_args() because we might need to compute
572 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
573 ui_out_text (uiout
, "\n");
574 ui_out_flush (uiout
);
577 /* We call get_inferior_args() because we might need to compute
579 target_create_inferior (exec_file
, get_inferior_args (),
580 environ_vector (current_inferior ()->environment
),
583 /* We're starting off a new process. When we get out of here, in
584 non-stop mode, finish the state of all threads of that process,
585 but leave other threads alone, as they may be stopped in internal
586 events --- the frontend shouldn't see them as stopped. In
587 all-stop, always finish the state of all threads, as we may be
588 resuming more than just the new process. */
590 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
592 ptid
= minus_one_ptid
;
593 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
595 /* Pass zero for FROM_TTY, because at this point the "run" command
596 has done its thing; now we are setting up the running program. */
597 post_create_inferior (¤t_target
, 0);
599 /* Start the target running. Do not use -1 continuation as it would skip
600 breakpoint right at the entry point. */
601 proceed (regcache_read_pc (get_current_regcache ()), TARGET_SIGNAL_0
, 0);
603 /* Since there was no error, there's no need to finish the thread
605 discard_cleanups (old_chain
);
609 run_command (char *args
, int from_tty
)
611 run_command_1 (args
, from_tty
, 0);
615 run_no_args_command (char *args
, int from_tty
)
617 set_inferior_args ("");
621 /* Start the execution of the program up until the beginning of the main
625 start_command (char *args
, int from_tty
)
627 /* Some languages such as Ada need to search inside the program
628 minimal symbols for the location where to put the temporary
629 breakpoint before starting. */
630 if (!have_minimal_symbols ())
631 error (_("No symbol table loaded. Use the \"file\" command."));
633 /* Run the program until reaching the main procedure... */
634 run_command_1 (args
, from_tty
, 1);
638 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
640 /* We go through all threads individually instead of compressing
641 into a single target `resume_all' request, because some threads
642 may be stopped in internal breakpoints/events, or stopped waiting
643 for its turn in the displaced stepping queue (that is, they are
644 running && !executing). The target side has no idea about why
645 the thread is stopped, so a `resume_all' command would resume too
646 much. If/when GDB gains a way to tell the target `hold this
647 thread stopped until I say otherwise', then we can optimize
649 if (!is_stopped (thread
->ptid
))
652 switch_to_thread (thread
->ptid
);
653 clear_proceed_status ();
654 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
659 ensure_valid_thread (void)
661 if (ptid_equal (inferior_ptid
, null_ptid
)
662 || is_exited (inferior_ptid
))
663 error (_("Cannot execute this command without a live selected thread."));
666 /* If the user is looking at trace frames, any resumption of execution
667 is likely to mix up recorded and live target data. So simply
668 disallow those commands. */
671 ensure_not_tfind_mode (void)
673 if (get_traceframe_number () >= 0)
674 error (_("Cannot execute this command while looking at trace frames."));
678 continue_1 (int all_threads
)
681 ensure_not_tfind_mode ();
683 if (non_stop
&& all_threads
)
685 /* Don't error out if the current thread is running, because
686 there may be other stopped threads. */
687 struct cleanup
*old_chain
;
689 /* Backup current thread and selected frame. */
690 old_chain
= make_cleanup_restore_current_thread ();
692 iterate_over_threads (proceed_thread_callback
, NULL
);
694 /* Restore selected ptid. */
695 do_cleanups (old_chain
);
699 ensure_valid_thread ();
700 ensure_not_running ();
701 clear_proceed_status ();
702 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
706 /* continue [-a] [proceed-count] [&] */
708 continue_command (char *args
, int from_tty
)
714 /* Find out whether we must run in the background. */
716 async_exec
= strip_bg_char (&args
);
718 /* If we must run in the background, but the target can't do it,
720 if (async_exec
&& !target_can_async_p ())
721 error (_("Asynchronous execution not supported on this target."));
723 /* If we are not asked to run in the bg, then prepare to run in the
724 foreground, synchronously. */
725 if (!async_exec
&& target_can_async_p ())
727 /* Simulate synchronous execution. */
728 async_disable_stdin ();
733 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
736 args
+= sizeof ("-a") - 1;
742 if (!non_stop
&& all_threads
)
743 error (_("`-a' is meaningless in all-stop mode."));
745 if (args
!= NULL
&& all_threads
)
746 error (_("Can't resume all threads and specify "
747 "proceed count simultaneously."));
749 /* If we have an argument left, set proceed count of breakpoint we
756 struct thread_info
*tp
;
759 tp
= find_thread_ptid (inferior_ptid
);
763 struct target_waitstatus ws
;
765 get_last_target_status (&last_ptid
, &ws
);
766 tp
= find_thread_ptid (last_ptid
);
769 bs
= tp
->control
.stop_bpstat
;
771 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
774 set_ignore_count (num
,
775 parse_and_eval_long (args
) - 1,
777 /* set_ignore_count prints a message ending with a period.
778 So print two spaces before "Continuing.". */
780 printf_filtered (" ");
784 if (!stopped
&& from_tty
)
787 ("Not stopped at any breakpoint; argument ignored.\n");
792 printf_filtered (_("Continuing.\n"));
794 continue_1 (all_threads
);
797 /* Record the starting point of a "step" or "next" command. */
800 set_step_frame (void)
802 struct symtab_and_line sal
;
804 find_frame_sal (get_current_frame (), &sal
);
805 set_step_info (get_current_frame (), sal
);
808 /* Step until outside of current statement. */
811 step_command (char *count_string
, int from_tty
)
813 step_1 (0, 0, count_string
);
816 /* Likewise, but skip over subroutine calls as if single instructions. */
819 next_command (char *count_string
, int from_tty
)
821 step_1 (1, 0, count_string
);
824 /* Likewise, but step only one instruction. */
827 stepi_command (char *count_string
, int from_tty
)
829 step_1 (0, 1, count_string
);
833 nexti_command (char *count_string
, int from_tty
)
835 step_1 (1, 1, count_string
);
839 delete_longjmp_breakpoint_cleanup (void *arg
)
841 int thread
= * (int *) arg
;
842 delete_longjmp_breakpoint (thread
);
846 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
849 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
854 ensure_not_tfind_mode ();
855 ensure_valid_thread ();
856 ensure_not_running ();
859 async_exec
= strip_bg_char (&count_string
);
861 /* If we get a request for running in the bg but the target
862 doesn't support it, error out. */
863 if (async_exec
&& !target_can_async_p ())
864 error (_("Asynchronous execution not supported on this target."));
866 /* If we don't get a request of running in the bg, then we need
867 to simulate synchronous (fg) execution. */
868 if (!async_exec
&& target_can_async_p ())
870 /* Simulate synchronous execution. */
871 async_disable_stdin ();
874 count
= count_string
? parse_and_eval_long (count_string
) : 1;
876 if (!single_inst
|| skip_subroutines
) /* Leave si command alone. */
878 struct thread_info
*tp
= inferior_thread ();
880 if (in_thread_list (inferior_ptid
))
881 thread
= pid_to_thread_id (inferior_ptid
);
883 set_longjmp_breakpoint (tp
, get_frame_id (get_current_frame ()));
885 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
888 /* In synchronous case, all is well; each step_once call will step once. */
889 if (!target_can_async_p ())
891 for (; count
> 0; count
--)
893 step_once (skip_subroutines
, single_inst
, count
, thread
);
895 if (!target_has_execution
)
899 struct thread_info
*tp
= inferior_thread ();
901 if (!tp
->control
.stop_step
|| !tp
->step_multi
)
903 /* If we stopped for some reason that is not stepping
904 there are no further steps to make. */
911 do_cleanups (cleanups
);
915 /* In the case of an asynchronous target things get complicated;
916 do only one step for now, before returning control to the
917 event loop. Let the continuation figure out how many other
918 steps we need to do, and handle them one at the time, through
920 step_once (skip_subroutines
, single_inst
, count
, thread
);
922 /* We are running, and the continuation is installed. It will
923 disable the longjmp breakpoint as appropriate. */
924 discard_cleanups (cleanups
);
928 struct step_1_continuation_args
931 int skip_subroutines
;
936 /* Called after we are done with one step operation, to check whether
937 we need to step again, before we print the prompt and return control
938 to the user. If count is > 1, we will need to do one more call to
939 proceed(), via step_once(). Basically it is like step_once and
940 step_1_continuation are co-recursive. */
942 step_1_continuation (void *args
)
944 struct step_1_continuation_args
*a
= args
;
946 if (target_has_execution
)
948 struct thread_info
*tp
;
950 tp
= inferior_thread ();
951 if (tp
->step_multi
&& tp
->control
.stop_step
)
953 /* There are more steps to make, and we did stop due to
954 ending a stepping range. Do another step. */
955 step_once (a
->skip_subroutines
, a
->single_inst
,
956 a
->count
- 1, a
->thread
);
962 /* We either stopped for some reason that is not stepping, or there
963 are no further steps to make. Cleanup. */
964 if (!a
->single_inst
|| a
->skip_subroutines
)
965 delete_longjmp_breakpoint (a
->thread
);
968 /* Do just one step operation. This is useful to implement the 'step
969 n' kind of commands. In case of asynchronous targets, we will have
970 to set up a continuation to be done after the target stops (after
971 this one step). For synch targets, the caller handles further
975 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
977 struct frame_info
*frame
= get_current_frame ();
981 /* Don't assume THREAD is a valid thread id. It is set to -1 if
982 the longjmp breakpoint was not required. Use the
983 INFERIOR_PTID thread instead, which is the same thread when
985 struct thread_info
*tp
= inferior_thread ();
987 clear_proceed_status ();
994 /* Step at an inlined function behaves like "down". */
995 if (!skip_subroutines
&& !single_inst
996 && inline_skipped_frames (inferior_ptid
))
1000 /* Pretend that we've ran. */
1001 resume_ptid
= user_visible_resume_ptid (1);
1002 set_running (resume_ptid
, 1);
1004 step_into_inline_frame (inferior_ptid
);
1006 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
1009 /* Pretend that we've stopped. */
1012 if (target_can_async_p ())
1013 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1018 pc
= get_frame_pc (frame
);
1019 find_pc_line_pc_range (pc
,
1020 &tp
->control
.step_range_start
,
1021 &tp
->control
.step_range_end
);
1023 /* If we have no line info, switch to stepi mode. */
1024 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1025 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1026 else if (tp
->control
.step_range_end
== 0)
1030 if (find_pc_partial_function (pc
, &name
,
1031 &tp
->control
.step_range_start
,
1032 &tp
->control
.step_range_end
) == 0)
1033 error (_("Cannot find bounds of current function"));
1035 target_terminal_ours ();
1036 printf_filtered (_("Single stepping until exit from function %s,"
1037 "\nwhich has no line number information.\n"),
1043 /* Say we are stepping, but stop after one insn whatever it does. */
1044 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1045 if (!skip_subroutines
)
1047 Don't step over function calls, not even to functions lacking
1049 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1052 if (skip_subroutines
)
1053 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1055 tp
->step_multi
= (count
> 1);
1056 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1058 /* For async targets, register a continuation to do any
1059 additional steps. For sync targets, the caller will handle
1060 further stepping. */
1061 if (target_can_async_p ())
1063 struct step_1_continuation_args
*args
;
1065 args
= xmalloc (sizeof (*args
));
1066 args
->skip_subroutines
= skip_subroutines
;
1067 args
->single_inst
= single_inst
;
1068 args
->count
= count
;
1069 args
->thread
= thread
;
1071 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
1077 /* Continue program at specified address. */
1080 jump_command (char *arg
, int from_tty
)
1082 struct gdbarch
*gdbarch
= get_current_arch ();
1084 struct symtabs_and_lines sals
;
1085 struct symtab_and_line sal
;
1091 ensure_not_tfind_mode ();
1092 ensure_valid_thread ();
1093 ensure_not_running ();
1095 /* Find out whether we must run in the background. */
1097 async_exec
= strip_bg_char (&arg
);
1099 /* If we must run in the background, but the target can't do it,
1101 if (async_exec
&& !target_can_async_p ())
1102 error (_("Asynchronous execution not supported on this target."));
1105 error_no_arg (_("starting address"));
1107 sals
= decode_line_spec_1 (arg
, 1);
1108 if (sals
.nelts
!= 1)
1110 error (_("Unreasonable jump request"));
1116 if (sal
.symtab
== 0 && sal
.pc
== 0)
1117 error (_("No source file has been specified."));
1119 resolve_sal_pc (&sal
); /* May error out. */
1121 /* See if we are trying to jump to another function. */
1122 fn
= get_frame_function (get_current_frame ());
1123 sfn
= find_pc_function (sal
.pc
);
1124 if (fn
!= NULL
&& sfn
!= fn
)
1126 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1127 SYMBOL_PRINT_NAME (fn
)))
1129 error (_("Not confirmed."));
1136 fixup_symbol_section (sfn
, 0);
1137 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn
)) &&
1138 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn
)))
1140 if (!query (_("WARNING!!! Destination is in "
1141 "unmapped overlay! Jump anyway? ")))
1143 error (_("Not confirmed."));
1153 printf_filtered (_("Continuing at "));
1154 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1155 printf_filtered (".\n");
1158 /* If we are not asked to run in the bg, then prepare to run in the
1159 foreground, synchronously. */
1160 if (!async_exec
&& target_can_async_p ())
1162 /* Simulate synchronous execution. */
1163 async_disable_stdin ();
1166 clear_proceed_status ();
1167 proceed (addr
, TARGET_SIGNAL_0
, 0);
1171 /* Go to line or address in current procedure. */
1173 go_command (char *line_no
, int from_tty
)
1175 if (line_no
== (char *) NULL
|| !*line_no
)
1176 printf_filtered (_("Usage: go <location>\n"));
1179 tbreak_command (line_no
, from_tty
);
1180 jump_command (line_no
, from_tty
);
1185 /* Continue program giving it specified signal. */
1188 signal_command (char *signum_exp
, int from_tty
)
1190 enum target_signal oursig
;
1193 dont_repeat (); /* Too dangerous. */
1195 ensure_not_tfind_mode ();
1196 ensure_valid_thread ();
1197 ensure_not_running ();
1199 /* Find out whether we must run in the background. */
1200 if (signum_exp
!= NULL
)
1201 async_exec
= strip_bg_char (&signum_exp
);
1203 /* If we must run in the background, but the target can't do it,
1205 if (async_exec
&& !target_can_async_p ())
1206 error (_("Asynchronous execution not supported on this target."));
1208 /* If we are not asked to run in the bg, then prepare to run in the
1209 foreground, synchronously. */
1210 if (!async_exec
&& target_can_async_p ())
1212 /* Simulate synchronous execution. */
1213 async_disable_stdin ();
1217 error_no_arg (_("signal number"));
1219 /* It would be even slicker to make signal names be valid expressions,
1220 (the type could be "enum $signal" or some such), then the user could
1221 assign them to convenience variables. */
1222 oursig
= target_signal_from_name (signum_exp
);
1224 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1226 /* No, try numeric. */
1227 int num
= parse_and_eval_long (signum_exp
);
1230 oursig
= TARGET_SIGNAL_0
;
1232 oursig
= target_signal_from_command (num
);
1237 if (oursig
== TARGET_SIGNAL_0
)
1238 printf_filtered (_("Continuing with no signal.\n"));
1240 printf_filtered (_("Continuing with signal %s.\n"),
1241 target_signal_to_name (oursig
));
1244 clear_proceed_status ();
1245 proceed ((CORE_ADDR
) -1, oursig
, 0);
1248 /* A continuation callback for until_next_command. */
1251 until_next_continuation (void *arg
)
1253 struct thread_info
*tp
= arg
;
1255 delete_longjmp_breakpoint (tp
->num
);
1258 /* Proceed until we reach a different source line with pc greater than
1259 our current one or exit the function. We skip calls in both cases.
1261 Note that eventually this command should probably be changed so
1262 that only source lines are printed out when we hit the breakpoint
1263 we set. This may involve changes to wait_for_inferior and the
1264 proceed status code. */
1267 until_next_command (int from_tty
)
1269 struct frame_info
*frame
;
1271 struct symbol
*func
;
1272 struct symtab_and_line sal
;
1273 struct thread_info
*tp
= inferior_thread ();
1274 int thread
= tp
->num
;
1275 struct cleanup
*old_chain
;
1277 clear_proceed_status ();
1280 frame
= get_current_frame ();
1282 /* Step until either exited from this function or greater
1283 than the current line (if in symbolic section) or pc (if
1286 pc
= get_frame_pc (frame
);
1287 func
= find_pc_function (pc
);
1291 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1293 if (msymbol
== NULL
)
1294 error (_("Execution is not within a known function."));
1296 tp
->control
.step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1297 tp
->control
.step_range_end
= pc
;
1301 sal
= find_pc_line (pc
, 0);
1303 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1304 tp
->control
.step_range_end
= sal
.end
;
1307 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1309 tp
->step_multi
= 0; /* Only one call to proceed */
1311 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1312 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1314 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1316 if (target_can_async_p () && is_running (inferior_ptid
))
1318 discard_cleanups (old_chain
);
1319 add_continuation (tp
, until_next_continuation
, tp
, NULL
);
1322 do_cleanups (old_chain
);
1326 until_command (char *arg
, int from_tty
)
1331 ensure_not_tfind_mode ();
1332 ensure_valid_thread ();
1333 ensure_not_running ();
1335 /* Find out whether we must run in the background. */
1337 async_exec
= strip_bg_char (&arg
);
1339 /* If we must run in the background, but the target can't do it,
1341 if (async_exec
&& !target_can_async_p ())
1342 error (_("Asynchronous execution not supported on this target."));
1344 /* If we are not asked to run in the bg, then prepare to run in the
1345 foreground, synchronously. */
1346 if (!async_exec
&& target_can_async_p ())
1348 /* Simulate synchronous execution. */
1349 async_disable_stdin ();
1353 until_break_command (arg
, from_tty
, 0);
1355 until_next_command (from_tty
);
1359 advance_command (char *arg
, int from_tty
)
1364 ensure_not_tfind_mode ();
1365 ensure_valid_thread ();
1366 ensure_not_running ();
1369 error_no_arg (_("a location"));
1371 /* Find out whether we must run in the background. */
1373 async_exec
= strip_bg_char (&arg
);
1375 /* If we must run in the background, but the target can't do it,
1377 if (async_exec
&& !target_can_async_p ())
1378 error (_("Asynchronous execution not supported on this target."));
1380 /* If we are not asked to run in the bg, then prepare to run in the
1381 foreground, synchronously. */
1382 if (!async_exec
&& target_can_async_p ())
1384 /* Simulate synchronous execution. */
1385 async_disable_stdin ();
1388 until_break_command (arg
, from_tty
, 1);
1391 /* Print the result of a function at the end of a 'finish' command. */
1394 print_return_value (struct type
*func_type
, struct type
*value_type
)
1396 struct gdbarch
*gdbarch
= get_regcache_arch (stop_registers
);
1397 struct cleanup
*old_chain
;
1398 struct ui_stream
*stb
;
1399 struct value
*value
;
1401 CHECK_TYPEDEF (value_type
);
1402 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1404 /* FIXME: 2003-09-27: When returning from a nested inferior function
1405 call, it's possible (with no help from the architecture vector)
1406 to locate and return/print a "struct return" value. This is just
1407 a more complicated case of what is already being done in the
1408 inferior function call code. In fact, when inferior function
1409 calls are made async, this will likely be made the norm. */
1411 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1414 case RETURN_VALUE_REGISTER_CONVENTION
:
1415 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1416 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1417 value
= allocate_value (value_type
);
1418 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1419 value_contents_raw (value
), NULL
);
1421 case RETURN_VALUE_STRUCT_CONVENTION
:
1425 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1430 struct value_print_options opts
;
1433 stb
= ui_out_stream_new (uiout
);
1434 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1435 ui_out_text (uiout
, "Value returned is ");
1436 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1437 record_latest_value (value
));
1438 ui_out_text (uiout
, " = ");
1439 get_raw_print_options (&opts
);
1440 value_print (value
, stb
->stream
, &opts
);
1441 ui_out_field_stream (uiout
, "return-value", stb
);
1442 ui_out_text (uiout
, "\n");
1443 do_cleanups (old_chain
);
1447 ui_out_text (uiout
, "Value returned has type: ");
1448 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1449 ui_out_text (uiout
, ".");
1450 ui_out_text (uiout
, " Cannot determine contents\n");
1454 /* Stuff that needs to be done by the finish command after the target
1455 has stopped. In asynchronous mode, we wait for the target to stop
1456 in the call to poll or select in the event loop, so it is
1457 impossible to do all the stuff as part of the finish_command
1458 function itself. The only chance we have to complete this command
1459 is in fetch_inferior_event, which is called by the event loop as
1460 soon as it detects that the target has stopped. This function is
1461 called via the cmd_continuation pointer. */
1463 struct finish_command_continuation_args
1465 struct breakpoint
*breakpoint
;
1466 struct symbol
*function
;
1470 finish_command_continuation (void *arg
)
1472 struct finish_command_continuation_args
*a
= arg
;
1473 struct thread_info
*tp
= NULL
;
1476 if (!ptid_equal (inferior_ptid
, null_ptid
)
1477 && target_has_execution
1478 && is_stopped (inferior_ptid
))
1480 tp
= inferior_thread ();
1481 bs
= tp
->control
.stop_bpstat
;
1484 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1485 && a
->function
!= NULL
)
1487 struct type
*value_type
;
1489 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1491 internal_error (__FILE__
, __LINE__
,
1492 _("finish_command: function has no target type"));
1494 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1496 volatile struct gdb_exception ex
;
1498 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1500 /* print_return_value can throw an exception in some
1501 circumstances. We need to catch this so that we still
1502 delete the breakpoint. */
1503 print_return_value (SYMBOL_TYPE (a
->function
), value_type
);
1506 exception_print (gdb_stdout
, ex
);
1510 /* We suppress normal call of normal_stop observer and do it here so
1511 that the *stopped notification includes the return value. */
1512 if (bs
!= NULL
&& tp
->control
.proceed_to_finish
)
1513 observer_notify_normal_stop (bs
, 1 /* print frame */);
1514 delete_breakpoint (a
->breakpoint
);
1515 delete_longjmp_breakpoint (inferior_thread ()->num
);
1519 finish_command_continuation_free_arg (void *arg
)
1524 /* finish_backward -- helper function for finish_command. */
1527 finish_backward (struct symbol
*function
)
1529 struct symtab_and_line sal
;
1530 struct thread_info
*tp
= inferior_thread ();
1532 CORE_ADDR func_addr
;
1534 pc
= get_frame_pc (get_current_frame ());
1536 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1537 internal_error (__FILE__
, __LINE__
,
1538 _("Finish: couldn't find function."));
1540 sal
= find_pc_line (func_addr
, 0);
1542 tp
->control
.proceed_to_finish
= 1;
1543 /* Special case: if we're sitting at the function entry point,
1544 then all we need to do is take a reverse singlestep. We
1545 don't need to set a breakpoint, and indeed it would do us
1548 Note that this can only happen at frame #0, since there's
1549 no way that a function up the stack can have a return address
1550 that's equal to its entry point. */
1554 struct frame_info
*frame
= get_selected_frame (NULL
);
1555 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1556 struct symtab_and_line sr_sal
;
1558 /* Set a step-resume at the function's entry point. Once that's
1559 hit, we'll do one more step backwards. */
1562 sr_sal
.pspace
= get_frame_program_space (frame
);
1563 insert_step_resume_breakpoint_at_sal (gdbarch
,
1564 sr_sal
, null_frame_id
);
1566 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1570 /* We're almost there -- we just need to back up by one more
1572 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1573 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1577 /* finish_forward -- helper function for finish_command. */
1580 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1582 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1583 struct symtab_and_line sal
;
1584 struct thread_info
*tp
= inferior_thread ();
1585 struct breakpoint
*breakpoint
;
1586 struct cleanup
*old_chain
;
1587 struct finish_command_continuation_args
*cargs
;
1588 int thread
= tp
->num
;
1590 sal
= find_pc_line (get_frame_pc (frame
), 0);
1591 sal
.pc
= get_frame_pc (frame
);
1593 breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1594 get_stack_frame_id (frame
),
1597 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1599 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1600 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1602 /* We want stop_registers, please... */
1603 tp
->control
.proceed_to_finish
= 1;
1604 cargs
= xmalloc (sizeof (*cargs
));
1606 cargs
->breakpoint
= breakpoint
;
1607 cargs
->function
= function
;
1608 add_continuation (tp
, finish_command_continuation
, cargs
,
1609 finish_command_continuation_free_arg
);
1610 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1612 discard_cleanups (old_chain
);
1613 if (!target_can_async_p ())
1614 do_all_continuations ();
1617 /* "finish": Set a temporary breakpoint at the place the selected
1618 frame will return to, then continue. */
1621 finish_command (char *arg
, int from_tty
)
1623 struct frame_info
*frame
;
1624 struct symbol
*function
;
1629 ensure_not_tfind_mode ();
1630 ensure_valid_thread ();
1631 ensure_not_running ();
1633 /* Find out whether we must run in the background. */
1635 async_exec
= strip_bg_char (&arg
);
1637 /* If we must run in the background, but the target can't do it,
1639 if (async_exec
&& !target_can_async_p ())
1640 error (_("Asynchronous execution not supported on this target."));
1642 /* If we are not asked to run in the bg, then prepare to run in the
1643 foreground, synchronously. */
1644 if (!async_exec
&& target_can_async_p ())
1646 /* Simulate synchronous execution. */
1647 async_disable_stdin ();
1651 error (_("The \"finish\" command does not take any arguments."));
1653 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1655 error (_("\"finish\" not meaningful in the outermost frame."));
1657 clear_proceed_status ();
1659 /* Finishing from an inline frame is completely different. We don't
1660 try to show the "return value" - no way to locate it. So we do
1661 not need a completion. */
1662 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1665 /* Claim we are stepping in the calling frame. An empty step
1666 range means that we will stop once we aren't in a function
1667 called by that frame. We don't use the magic "1" value for
1668 step_range_end, because then infrun will think this is nexti,
1669 and not step over the rest of this inlined function call. */
1670 struct thread_info
*tp
= inferior_thread ();
1671 struct symtab_and_line empty_sal
;
1673 init_sal (&empty_sal
);
1674 set_step_info (frame
, empty_sal
);
1675 tp
->control
.step_range_start
= get_frame_pc (frame
);
1676 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1677 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1679 /* Print info on the selected frame, including level number but not
1683 printf_filtered (_("Run till exit from "));
1684 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1687 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1691 /* Find the function we will return from. */
1693 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1695 /* Print info on the selected frame, including level number but not
1699 if (execution_direction
== EXEC_REVERSE
)
1700 printf_filtered (_("Run back to call of "));
1702 printf_filtered (_("Run till exit from "));
1704 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1707 if (execution_direction
== EXEC_REVERSE
)
1708 finish_backward (function
);
1710 finish_forward (function
, frame
);
1715 program_info (char *args
, int from_tty
)
1719 struct thread_info
*tp
;
1722 if (!target_has_execution
)
1724 printf_filtered (_("The program being debugged is not being run.\n"));
1729 ptid
= inferior_ptid
;
1732 struct target_waitstatus ws
;
1734 get_last_target_status (&ptid
, &ws
);
1737 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1738 error (_("Invalid selected thread."));
1739 else if (is_running (ptid
))
1740 error (_("Selected thread is running."));
1742 tp
= find_thread_ptid (ptid
);
1743 bs
= tp
->control
.stop_bpstat
;
1744 stat
= bpstat_num (&bs
, &num
);
1746 target_files_info ();
1747 printf_filtered (_("Program stopped at %s.\n"),
1748 paddress (target_gdbarch
, stop_pc
));
1749 if (tp
->control
.stop_step
)
1750 printf_filtered (_("It stopped after being stepped.\n"));
1753 /* There may be several breakpoints in the same place, so this
1754 isn't as strange as it seems. */
1759 printf_filtered (_("It stopped at a breakpoint "
1760 "that has since been deleted.\n"));
1763 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1764 stat
= bpstat_num (&bs
, &num
);
1767 else if (tp
->suspend
.stop_signal
!= TARGET_SIGNAL_0
)
1769 printf_filtered (_("It stopped with signal %s, %s.\n"),
1770 target_signal_to_name (tp
->suspend
.stop_signal
),
1771 target_signal_to_string (tp
->suspend
.stop_signal
));
1776 printf_filtered (_("Type \"info stack\" or \"info "
1777 "registers\" for more information.\n"));
1782 environment_info (char *var
, int from_tty
)
1786 char *val
= get_in_environ (current_inferior ()->environment
, var
);
1790 puts_filtered (var
);
1791 puts_filtered (" = ");
1792 puts_filtered (val
);
1793 puts_filtered ("\n");
1797 puts_filtered ("Environment variable \"");
1798 puts_filtered (var
);
1799 puts_filtered ("\" not defined.\n");
1804 char **vector
= environ_vector (current_inferior ()->environment
);
1808 puts_filtered (*vector
++);
1809 puts_filtered ("\n");
1815 set_environment_command (char *arg
, int from_tty
)
1817 char *p
, *val
, *var
;
1821 error_no_arg (_("environment variable and value"));
1823 /* Find seperation between variable name and value. */
1824 p
= (char *) strchr (arg
, '=');
1825 val
= (char *) strchr (arg
, ' ');
1827 if (p
!= 0 && val
!= 0)
1829 /* We have both a space and an equals. If the space is before the
1830 equals, walk forward over the spaces til we see a nonspace
1831 (possibly the equals). */
1836 /* Now if the = is after the char following the spaces,
1837 take the char following the spaces. */
1841 else if (val
!= 0 && p
== 0)
1845 error_no_arg (_("environment variable to set"));
1847 if (p
== 0 || p
[1] == 0)
1851 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
1855 /* Not setting variable value to null. */
1857 while (*val
== ' ' || *val
== '\t')
1861 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1864 var
= savestring (arg
, p
- arg
);
1867 printf_filtered (_("Setting environment variable "
1868 "\"%s\" to null value.\n"),
1870 set_in_environ (current_inferior ()->environment
, var
, "");
1873 set_in_environ (current_inferior ()->environment
, var
, val
);
1878 unset_environment_command (char *var
, int from_tty
)
1882 /* If there is no argument, delete all environment variables.
1883 Ask for confirmation if reading from the terminal. */
1884 if (!from_tty
|| query (_("Delete all environment variables? ")))
1886 free_environ (current_inferior ()->environment
);
1887 current_inferior ()->environment
= make_environ ();
1891 unset_in_environ (current_inferior ()->environment
, var
);
1894 /* Handle the execution path (PATH variable). */
1896 static const char path_var_name
[] = "PATH";
1899 path_info (char *args
, int from_tty
)
1901 puts_filtered ("Executable and object file path: ");
1902 puts_filtered (get_in_environ (current_inferior ()->environment
,
1904 puts_filtered ("\n");
1907 /* Add zero or more directories to the front of the execution path. */
1910 path_command (char *dirname
, int from_tty
)
1916 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
1917 /* Can be null if path is not set. */
1920 exec_path
= xstrdup (env
);
1921 mod_path (dirname
, &exec_path
);
1922 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
1925 path_info ((char *) NULL
, from_tty
);
1929 /* Print out the machine register regnum. If regnum is -1, print all
1930 registers (print_all == 1) or all non-float and non-vector
1931 registers (print_all == 0).
1933 For most machines, having all_registers_info() print the
1934 register(s) one per line is good enough. If a different format is
1935 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1936 regs), or there is an existing convention for showing all the
1937 registers, define the architecture method PRINT_REGISTERS_INFO to
1938 provide that format. */
1941 default_print_registers_info (struct gdbarch
*gdbarch
,
1942 struct ui_file
*file
,
1943 struct frame_info
*frame
,
1944 int regnum
, int print_all
)
1947 const int numregs
= gdbarch_num_regs (gdbarch
)
1948 + gdbarch_num_pseudo_regs (gdbarch
);
1950 for (i
= 0; i
< numregs
; i
++)
1952 struct type
*regtype
;
1955 /* Decide between printing all regs, non-float / vector regs, or
1961 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1966 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1976 /* If the register name is empty, it is undefined for this
1977 processor, so don't display anything. */
1978 if (gdbarch_register_name (gdbarch
, i
) == NULL
1979 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1982 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1983 print_spaces_filtered (15 - strlen (gdbarch_register_name
1984 (gdbarch
, i
)), file
);
1986 regtype
= register_type (gdbarch
, i
);
1987 val
= allocate_value (regtype
);
1989 /* Get the data in raw format. */
1990 if (! frame_register_read (frame
, i
, value_contents_raw (val
)))
1992 fprintf_filtered (file
, "*value not available*\n");
1996 /* If virtual format is floating, print it that way, and in raw
1998 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
1999 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2002 struct value_print_options opts
;
2003 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2005 get_user_print_options (&opts
);
2009 value_contents_for_printing (val
),
2010 value_embedded_offset (val
), 0,
2011 file
, 0, val
, &opts
, current_language
);
2013 fprintf_filtered (file
, "\t(raw 0x");
2014 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
2018 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
2021 idx
= register_size (gdbarch
, i
) - 1 - j
;
2022 fprintf_filtered (file
, "%02x", (unsigned char) valaddr
[idx
]);
2024 fprintf_filtered (file
, ")");
2028 struct value_print_options opts
;
2030 /* Print the register in hex. */
2031 get_formatted_print_options (&opts
, 'x');
2034 value_contents_for_printing (val
),
2035 value_embedded_offset (val
), 0,
2036 file
, 0, val
, &opts
, current_language
);
2037 /* If not a vector register, print it also according to its
2039 if (TYPE_VECTOR (regtype
) == 0)
2041 get_user_print_options (&opts
);
2043 fprintf_filtered (file
, "\t");
2045 value_contents_for_printing (val
),
2046 value_embedded_offset (val
), 0,
2047 file
, 0, val
, &opts
, current_language
);
2051 fprintf_filtered (file
, "\n");
2056 registers_info (char *addr_exp
, int fpregs
)
2058 struct frame_info
*frame
;
2059 struct gdbarch
*gdbarch
;
2061 if (!target_has_registers
)
2062 error (_("The program has no registers now."));
2063 frame
= get_selected_frame (NULL
);
2064 gdbarch
= get_frame_arch (frame
);
2068 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2073 while (*addr_exp
!= '\0')
2078 /* Keep skipping leading white space. */
2079 if (isspace ((*addr_exp
)))
2085 /* Discard any leading ``$''. Check that there is something
2086 resembling a register following it. */
2087 if (addr_exp
[0] == '$')
2089 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2090 error (_("Missing register name"));
2092 /* Find the start/end of this register name/num/group. */
2094 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2098 /* Figure out what we've found and display it. */
2100 /* A register name? */
2102 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2106 /* User registers lie completely outside of the range of
2107 normal registers. Catch them early so that the target
2109 if (regnum
>= gdbarch_num_regs (gdbarch
)
2110 + gdbarch_num_pseudo_regs (gdbarch
))
2112 struct value_print_options opts
;
2113 struct value
*val
= value_of_user_reg (regnum
, frame
);
2115 printf_filtered ("%s: ", start
);
2116 get_formatted_print_options (&opts
, 'x');
2117 val_print_scalar_formatted (check_typedef (value_type (val
)),
2118 value_contents_for_printing (val
),
2119 value_embedded_offset (val
),
2121 &opts
, 0, gdb_stdout
);
2122 printf_filtered ("\n");
2125 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2126 frame
, regnum
, fpregs
);
2131 /* A register group? */
2133 struct reggroup
*group
;
2135 for (group
= reggroup_next (gdbarch
, NULL
);
2137 group
= reggroup_next (gdbarch
, group
))
2139 /* Don't bother with a length check. Should the user
2140 enter a short register group name, go with the first
2141 group that matches. */
2142 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2150 regnum
< gdbarch_num_regs (gdbarch
)
2151 + gdbarch_num_pseudo_regs (gdbarch
);
2154 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2155 gdbarch_print_registers_info (gdbarch
,
2163 /* Nothing matched. */
2164 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2169 all_registers_info (char *addr_exp
, int from_tty
)
2171 registers_info (addr_exp
, 1);
2175 nofp_registers_info (char *addr_exp
, int from_tty
)
2177 registers_info (addr_exp
, 0);
2181 print_vector_info (struct ui_file
*file
,
2182 struct frame_info
*frame
, const char *args
)
2184 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2186 if (gdbarch_print_vector_info_p (gdbarch
))
2187 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2191 int printed_something
= 0;
2194 regnum
< gdbarch_num_regs (gdbarch
)
2195 + gdbarch_num_pseudo_regs (gdbarch
);
2198 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2200 printed_something
= 1;
2201 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2204 if (!printed_something
)
2205 fprintf_filtered (file
, "No vector information\n");
2210 vector_info (char *args
, int from_tty
)
2212 if (!target_has_registers
)
2213 error (_("The program has no registers now."));
2215 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2218 /* Kill the inferior process. Make us have no inferior. */
2221 kill_command (char *arg
, int from_tty
)
2223 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2224 It should be a distinct flag that indicates that a target is active, cuz
2225 some targets don't have processes! */
2227 if (ptid_equal (inferior_ptid
, null_ptid
))
2228 error (_("The program is not being run."));
2229 if (!query (_("Kill the program being debugged? ")))
2230 error (_("Not confirmed."));
2233 /* If we still have other inferiors to debug, then don't mess with
2234 with their threads. */
2235 if (!have_inferiors ())
2237 init_thread_list (); /* Destroy thread info. */
2239 /* Killing off the inferior can leave us with a core file. If
2240 so, print the state we are left in. */
2241 if (target_has_stack
)
2243 printf_filtered (_("In %s,\n"), target_longname
);
2244 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2247 bfd_cache_close_all ();
2250 /* Used in `attach&' command. ARG is a point to an integer
2251 representing a process id. Proceed threads of this process iff
2252 they stopped due to debugger request, and when they did, they
2253 reported a clean stop (TARGET_SIGNAL_0). Do not proceed threads
2254 that have been explicitly been told to stop. */
2257 proceed_after_attach_callback (struct thread_info
*thread
,
2260 int pid
= * (int *) arg
;
2262 if (ptid_get_pid (thread
->ptid
) == pid
2263 && !is_exited (thread
->ptid
)
2264 && !is_executing (thread
->ptid
)
2265 && !thread
->stop_requested
2266 && thread
->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2268 switch_to_thread (thread
->ptid
);
2269 clear_proceed_status ();
2270 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2277 proceed_after_attach (int pid
)
2279 /* Don't error out if the current thread is running, because
2280 there may be other stopped threads. */
2281 struct cleanup
*old_chain
;
2283 /* Backup current thread and selected frame. */
2284 old_chain
= make_cleanup_restore_current_thread ();
2286 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2288 /* Restore selected ptid. */
2289 do_cleanups (old_chain
);
2294 * Should save/restore the tty state since it might be that the
2295 * program to be debugged was started on this tty and it wants
2296 * the tty in some state other than what we want. If it's running
2297 * on another terminal or without a terminal, then saving and
2298 * restoring the tty state is a harmless no-op.
2299 * This only needs to be done if we are attaching to a process.
2302 /* attach_command --
2303 takes a program started up outside of gdb and ``attaches'' to it.
2304 This stops it cold in its tracks and allows us to start debugging it.
2305 and wait for the trace-trap that results from attaching. */
2308 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2311 char *full_exec_path
= NULL
;
2312 struct inferior
*inferior
;
2314 inferior
= current_inferior ();
2315 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2317 /* If no exec file is yet known, try to determine it from the
2319 exec_file
= (char *) get_exec_file (0);
2322 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
2325 /* It's possible we don't have a full path, but rather just a
2326 filename. Some targets, such as HP-UX, don't provide the
2329 Attempt to qualify the filename against the source path.
2330 (If that fails, we'll just fall back on the original
2331 filename. Not much more we can do...) */
2333 if (!source_full_path_of (exec_file
, &full_exec_path
))
2334 full_exec_path
= xstrdup (exec_file
);
2336 exec_file_attach (full_exec_path
, from_tty
);
2337 symbol_file_add_main (full_exec_path
, from_tty
);
2342 reopen_exec_file ();
2346 /* Take any necessary post-attaching actions for this platform. */
2347 target_post_attach (PIDGET (inferior_ptid
));
2349 post_create_inferior (¤t_target
, from_tty
);
2351 /* Install inferior's terminal modes. */
2352 target_terminal_inferior ();
2356 /* The user requested an `attach&', so be sure to leave threads
2357 that didn't get a signal running. */
2359 /* Immediatelly resume all suspended threads of this inferior,
2360 and this inferior only. This should have no effect on
2361 already running threads. If a thread has been stopped with a
2362 signal, leave it be. */
2364 proceed_after_attach (inferior
->pid
);
2367 if (inferior_thread ()->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2369 clear_proceed_status ();
2370 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2376 /* The user requested a plain `attach', so be sure to leave
2377 the inferior stopped. */
2379 if (target_can_async_p ())
2380 async_enable_stdin ();
2382 /* At least the current thread is already stopped. */
2384 /* In all-stop, by definition, all threads have to be already
2385 stopped at this point. In non-stop, however, although the
2386 selected thread is stopped, others may still be executing.
2387 Be sure to explicitly stop all threads of the process. This
2388 should have no effect on already stopped threads. */
2390 target_stop (pid_to_ptid (inferior
->pid
));
2392 /* Tell the user/frontend where we're stopped. */
2394 if (deprecated_attach_hook
)
2395 deprecated_attach_hook ();
2399 struct attach_command_continuation_args
2407 attach_command_continuation (void *args
)
2409 struct attach_command_continuation_args
*a
= args
;
2411 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2415 attach_command_continuation_free_args (void *args
)
2417 struct attach_command_continuation_args
*a
= args
;
2424 attach_command (char *args
, int from_tty
)
2427 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2429 dont_repeat (); /* Not for the faint of heart */
2431 if (gdbarch_has_global_solist (target_gdbarch
))
2432 /* Don't complain if all processes share the same symbol
2435 else if (target_has_execution
)
2437 if (query (_("A program is being debugged already. Kill it? ")))
2440 error (_("Not killed."));
2443 /* Clean up any leftovers from other runs. Some other things from
2444 this function should probably be moved into target_pre_inferior. */
2445 target_pre_inferior (from_tty
);
2447 if (non_stop
&& !target_supports_non_stop ())
2448 error (_("Cannot attach to this target in non-stop mode"));
2452 async_exec
= strip_bg_char (&args
);
2454 /* If we get a request for running in the bg but the target
2455 doesn't support it, error out. */
2456 if (async_exec
&& !target_can_async_p ())
2457 error (_("Asynchronous execution not supported on this target."));
2460 /* If we don't get a request of running in the bg, then we need
2461 to simulate synchronous (fg) execution. */
2462 if (!async_exec
&& target_can_async_p ())
2464 /* Simulate synchronous execution. */
2465 async_disable_stdin ();
2466 make_cleanup ((make_cleanup_ftype
*)async_enable_stdin
, NULL
);
2469 target_attach (args
, from_tty
);
2471 /* Set up the "saved terminal modes" of the inferior
2472 based on what modes we are starting it with. */
2473 target_terminal_init ();
2475 /* Set up execution context to know that we should return from
2476 wait_for_inferior as soon as the target reports a stop. */
2477 init_wait_for_inferior ();
2478 clear_proceed_status ();
2482 /* If we find that the current thread isn't stopped, explicitly
2483 do so now, because we're going to install breakpoints and
2487 /* The user requested an `attach&'; stop just one thread. */
2488 target_stop (inferior_ptid
);
2490 /* The user requested an `attach', so stop all threads of this
2492 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2495 /* Some system don't generate traps when attaching to inferior.
2496 E.g. Mach 3 or GNU hurd. */
2497 if (!target_attach_no_wait
)
2499 struct inferior
*inferior
= current_inferior ();
2501 /* Careful here. See comments in inferior.h. Basically some
2502 OSes don't ignore SIGSTOPs on continue requests anymore. We
2503 need a way for handle_inferior_event to reset the stop_signal
2504 variable after an attach, and this is what
2505 STOP_QUIETLY_NO_SIGSTOP is for. */
2506 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2508 if (target_can_async_p ())
2510 /* sync_execution mode. Wait for stop. */
2511 struct attach_command_continuation_args
*a
;
2513 a
= xmalloc (sizeof (*a
));
2514 a
->args
= xstrdup (args
);
2515 a
->from_tty
= from_tty
;
2516 a
->async_exec
= async_exec
;
2517 add_inferior_continuation (attach_command_continuation
, a
,
2518 attach_command_continuation_free_args
);
2519 discard_cleanups (back_to
);
2523 wait_for_inferior ();
2526 attach_command_post_wait (args
, from_tty
, async_exec
);
2527 discard_cleanups (back_to
);
2530 /* We had just found out that the target was already attached to an
2531 inferior. PTID points at a thread of this new inferior, that is
2532 the most likely to be stopped right now, but not necessarily so.
2533 The new inferior is assumed to be already added to the inferior
2534 list at this point. If LEAVE_RUNNING, then leave the threads of
2535 this inferior running, except those we've explicitly seen reported
2539 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2541 struct cleanup
* old_chain
;
2544 old_chain
= make_cleanup (null_cleanup
, NULL
);
2546 /* If in non-stop, leave threads as running as they were. If
2547 they're stopped for some reason other than us telling it to, the
2548 target reports a signal != TARGET_SIGNAL_0. We don't try to
2549 resume threads with such a stop signal. */
2550 async_exec
= non_stop
;
2552 if (!ptid_equal (inferior_ptid
, null_ptid
))
2553 make_cleanup_restore_current_thread ();
2555 switch_to_thread (ptid
);
2557 /* When we "notice" a new inferior we need to do all the things we
2558 would normally do if we had just attached to it. */
2560 if (is_executing (inferior_ptid
))
2562 struct inferior
*inferior
= current_inferior ();
2564 /* We're going to install breakpoints, and poke at memory,
2565 ensure that the inferior is stopped for a moment while we do
2567 target_stop (inferior_ptid
);
2569 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2571 /* Wait for stop before proceeding. */
2572 if (target_can_async_p ())
2574 struct attach_command_continuation_args
*a
;
2576 a
= xmalloc (sizeof (*a
));
2577 a
->args
= xstrdup ("");
2578 a
->from_tty
= from_tty
;
2579 a
->async_exec
= async_exec
;
2580 add_inferior_continuation (attach_command_continuation
, a
,
2581 attach_command_continuation_free_args
);
2583 do_cleanups (old_chain
);
2587 wait_for_inferior ();
2590 async_exec
= leave_running
;
2591 attach_command_post_wait ("" /* args */, from_tty
, async_exec
);
2593 do_cleanups (old_chain
);
2598 * takes a program previously attached to and detaches it.
2599 * The program resumes execution and will no longer stop
2600 * on signals, etc. We better not have left any breakpoints
2601 * in the program or it'll die when it hits one. For this
2602 * to work, it may be necessary for the process to have been
2603 * previously attached. It *might* work if the program was
2604 * started via the normal ptrace (PTRACE_TRACEME).
2608 detach_command (char *args
, int from_tty
)
2610 dont_repeat (); /* Not for the faint of heart. */
2612 if (ptid_equal (inferior_ptid
, null_ptid
))
2613 error (_("The program is not being run."));
2615 disconnect_tracing (from_tty
);
2617 target_detach (args
, from_tty
);
2619 /* If the solist is global across inferiors, don't clear it when we
2620 detach from a single inferior. */
2621 if (!gdbarch_has_global_solist (target_gdbarch
))
2622 no_shared_libraries (NULL
, from_tty
);
2624 /* If we still have inferiors to debug, then don't mess with their
2626 if (!have_inferiors ())
2627 init_thread_list ();
2629 if (deprecated_detach_hook
)
2630 deprecated_detach_hook ();
2633 /* Disconnect from the current target without resuming it (leaving it
2634 waiting for a debugger).
2636 We'd better not have left any breakpoints in the program or the
2637 next debugger will get confused. Currently only supported for some
2638 remote targets, since the normal attach mechanisms don't work on
2639 stopped processes on some native platforms (e.g. GNU/Linux). */
2642 disconnect_command (char *args
, int from_tty
)
2644 dont_repeat (); /* Not for the faint of heart. */
2645 target_disconnect (args
, from_tty
);
2646 no_shared_libraries (NULL
, from_tty
);
2647 init_thread_list ();
2648 if (deprecated_detach_hook
)
2649 deprecated_detach_hook ();
2653 interrupt_target_1 (int all_threads
)
2658 ptid
= minus_one_ptid
;
2660 ptid
= inferior_ptid
;
2663 /* Tag the thread as having been explicitly requested to stop, so
2664 other parts of gdb know not to resume this thread automatically,
2665 if it was stopped due to an internal event. Limit this to
2666 non-stop mode, as when debugging a multi-threaded application in
2667 all-stop mode, we will only get one stop event --- it's undefined
2668 which thread will report the event. */
2670 set_stop_requested (ptid
, 1);
2673 /* Stop the execution of the target while running in async mode, in
2674 the backgound. In all-stop, stop the whole process. In non-stop
2675 mode, stop the current thread only by default, or stop all threads
2676 if the `-a' switch is used. */
2678 /* interrupt [-a] */
2680 interrupt_target_command (char *args
, int from_tty
)
2682 if (target_can_async_p ())
2684 int all_threads
= 0;
2686 dont_repeat (); /* Not for the faint of heart. */
2689 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2692 if (!non_stop
&& all_threads
)
2693 error (_("-a is meaningless in all-stop mode."));
2695 interrupt_target_1 (all_threads
);
2700 print_float_info (struct ui_file
*file
,
2701 struct frame_info
*frame
, const char *args
)
2703 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2705 if (gdbarch_print_float_info_p (gdbarch
))
2706 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2710 int printed_something
= 0;
2713 regnum
< gdbarch_num_regs (gdbarch
)
2714 + gdbarch_num_pseudo_regs (gdbarch
);
2717 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2719 printed_something
= 1;
2720 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2723 if (!printed_something
)
2724 fprintf_filtered (file
, "No floating-point info "
2725 "available for this processor.\n");
2730 float_info (char *args
, int from_tty
)
2732 if (!target_has_registers
)
2733 error (_("The program has no registers now."));
2735 print_float_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2739 unset_command (char *args
, int from_tty
)
2741 printf_filtered (_("\"unset\" must be followed by the "
2742 "name of an unset subcommand.\n"));
2743 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2747 _initialize_infcmd (void)
2749 struct cmd_list_element
*c
= NULL
;
2751 /* Add the filename of the terminal connected to inferior I/O. */
2752 add_setshow_filename_cmd ("inferior-tty", class_run
,
2753 &inferior_io_terminal_scratch
, _("\
2754 Set terminal for future runs of program being debugged."), _("\
2755 Show terminal for future runs of program being debugged."), _("\
2756 Usage: set inferior-tty /dev/pts/1"),
2757 set_inferior_tty_command
,
2758 show_inferior_tty_command
,
2759 &setlist
, &showlist
);
2760 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2762 add_setshow_optional_filename_cmd ("args", class_run
,
2763 &inferior_args_scratch
, _("\
2764 Set argument list to give program being debugged when it is started."), _("\
2765 Show argument list to give program being debugged when it is started."), _("\
2766 Follow this command with any number of args, to be passed to the program."),
2769 &setlist
, &showlist
);
2771 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2772 The environment to give the program, or one variable's value.\n\
2773 With an argument VAR, prints the value of environment variable VAR to\n\
2774 give the program being debugged. With no arguments, prints the entire\n\
2775 environment to be given to the program."), &showlist
);
2776 set_cmd_completer (c
, noop_completer
);
2778 add_prefix_cmd ("unset", no_class
, unset_command
,
2779 _("Complement to certain \"set\" commands."),
2780 &unsetlist
, "unset ", 0, &cmdlist
);
2782 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2783 Cancel environment variable VAR for the program.\n\
2784 This does not affect the program until the next \"run\" command."),
2786 set_cmd_completer (c
, noop_completer
);
2788 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2789 Set environment variable value to give the program.\n\
2790 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2791 VALUES of environment variables are uninterpreted strings.\n\
2792 This does not affect the program until the next \"run\" command."),
2794 set_cmd_completer (c
, noop_completer
);
2796 c
= add_com ("path", class_files
, path_command
, _("\
2797 Add directory DIR(s) to beginning of search path for object files.\n\
2798 $cwd in the path means the current working directory.\n\
2799 This path is equivalent to the $PATH shell variable. It is a list of\n\
2800 directories, separated by colons. These directories are searched to find\n\
2801 fully linked executable files and separately compiled object files as \
2803 set_cmd_completer (c
, filename_completer
);
2805 c
= add_cmd ("paths", no_class
, path_info
, _("\
2806 Current search path for finding object files.\n\
2807 $cwd in the path means the current working directory.\n\
2808 This path is equivalent to the $PATH shell variable. It is a list of\n\
2809 directories, separated by colons. These directories are searched to find\n\
2810 fully linked executable files and separately compiled object files as \
2813 set_cmd_completer (c
, noop_completer
);
2815 add_prefix_cmd ("kill", class_run
, kill_command
,
2816 _("Kill execution of program being debugged."),
2817 &killlist
, "kill ", 0, &cmdlist
);
2819 add_com ("attach", class_run
, attach_command
, _("\
2820 Attach to a process or file outside of GDB.\n\
2821 This command attaches to another target, of the same type as your last\n\
2822 \"target\" command (\"info files\" will show your target stack).\n\
2823 The command may take as argument a process id or a device file.\n\
2824 For a process id, you must have permission to send the process a signal,\n\
2825 and it must have the same effective uid as the debugger.\n\
2826 When using \"attach\" with a process id, the debugger finds the\n\
2827 program running in the process, looking first in the current working\n\
2828 directory, or (if not found there) using the source file search path\n\
2829 (see the \"directory\" command). You can also use the \"file\" command\n\
2830 to specify the program, and to load its symbol table."));
2832 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2833 Detach a process or file previously attached.\n\
2834 If a process, it is no longer traced, and it continues its execution. If\n\
2835 you were debugging a file, the file is closed and gdb no longer accesses it."),
2836 &detachlist
, "detach ", 0, &cmdlist
);
2838 add_com ("disconnect", class_run
, disconnect_command
, _("\
2839 Disconnect from a target.\n\
2840 The target will wait for another debugger to connect. Not available for\n\
2843 add_com ("signal", class_run
, signal_command
, _("\
2844 Continue program giving it signal specified by the argument.\n\
2845 An argument of \"0\" means continue program without giving it a signal."));
2847 add_com ("stepi", class_run
, stepi_command
, _("\
2848 Step one instruction exactly.\n\
2849 Argument N means do this N times (or till program stops for another \
2851 add_com_alias ("si", "stepi", class_alias
, 0);
2853 add_com ("nexti", class_run
, nexti_command
, _("\
2854 Step one instruction, but proceed through subroutine calls.\n\
2855 Argument N means do this N times (or till program stops for another \
2857 add_com_alias ("ni", "nexti", class_alias
, 0);
2859 add_com ("finish", class_run
, finish_command
, _("\
2860 Execute until selected stack frame returns.\n\
2861 Upon return, the value returned is printed and put in the value history."));
2862 add_com_alias ("fin", "finish", class_run
, 1);
2864 add_com ("next", class_run
, next_command
, _("\
2865 Step program, proceeding through subroutine calls.\n\
2866 Like the \"step\" command as long as subroutine calls do not happen;\n\
2867 when they do, the call is treated as one instruction.\n\
2868 Argument N means do this N times (or till program stops for another \
2870 add_com_alias ("n", "next", class_run
, 1);
2872 add_com_alias ("S", "next", class_run
, 1);
2874 add_com ("step", class_run
, step_command
, _("\
2875 Step program until it reaches a different source line.\n\
2876 Argument N means do this N times (or till program stops for another \
2878 add_com_alias ("s", "step", class_run
, 1);
2880 c
= add_com ("until", class_run
, until_command
, _("\
2881 Execute until the program reaches a source line greater than the current\n\
2882 or a specified location (same args as break command) within the current \
2884 set_cmd_completer (c
, location_completer
);
2885 add_com_alias ("u", "until", class_run
, 1);
2887 c
= add_com ("advance", class_run
, advance_command
, _("\
2888 Continue the program up to the given location (same form as args for break \
2890 Execution will also stop upon exit from the current stack frame."));
2891 set_cmd_completer (c
, location_completer
);
2893 c
= add_com ("jump", class_run
, jump_command
, _("\
2894 Continue program being debugged at specified line or address.\n\
2895 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2896 for an address to start at."));
2897 set_cmd_completer (c
, location_completer
);
2901 c
= add_com ("go", class_run
, go_command
, _("\
2902 Usage: go <location>\n\
2903 Continue program being debugged, stopping at specified line or \n\
2905 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2906 expression for an address to start at.\n\
2907 This command is a combination of tbreak and jump."));
2908 set_cmd_completer (c
, location_completer
);
2912 add_com_alias ("g", "go", class_run
, 1);
2914 add_com ("continue", class_run
, continue_command
, _("\
2915 Continue program being debugged, after signal or breakpoint.\n\
2916 If proceeding from breakpoint, a number N may be used as an argument,\n\
2917 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2918 the breakpoint won't break until the Nth time it is reached).\n\
2920 If non-stop mode is enabled, continue only the current thread,\n\
2921 otherwise all the threads in the program are continued. To \n\
2922 continue all stopped threads in non-stop mode, use the -a option.\n\
2923 Specifying -a and an ignore count simultaneously is an error."));
2924 add_com_alias ("c", "cont", class_run
, 1);
2925 add_com_alias ("fg", "cont", class_run
, 1);
2927 c
= add_com ("run", class_run
, run_command
, _("\
2928 Start debugged program. You may specify arguments to give it.\n\
2929 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2930 Input and output redirection with \">\", \"<\", or \">>\" are also \
2932 With no arguments, uses arguments last specified (with \"run\" \
2933 or \"set args\").\n\
2934 To cancel previous arguments and run with no arguments,\n\
2935 use \"set args\" without arguments."));
2936 set_cmd_completer (c
, filename_completer
);
2937 add_com_alias ("r", "run", class_run
, 1);
2939 add_com ("R", class_run
, run_no_args_command
,
2940 _("Start debugged program with no arguments."));
2942 c
= add_com ("start", class_run
, start_command
, _("\
2943 Run the debugged program until the beginning of the main procedure.\n\
2944 You may specify arguments to give to your program, just as with the\n\
2945 \"run\" command."));
2946 set_cmd_completer (c
, filename_completer
);
2948 add_com ("interrupt", class_run
, interrupt_target_command
,
2949 _("Interrupt the execution of the debugged program.\n\
2950 If non-stop mode is enabled, interrupt only the current thread,\n\
2951 otherwise all the threads in the program are stopped. To \n\
2952 interrupt all running threads in non-stop mode, use the -a option."));
2954 add_info ("registers", nofp_registers_info
, _("\
2955 List of integer registers and their contents, for selected stack frame.\n\
2956 Register name as argument means describe only that register."));
2957 add_info_alias ("r", "registers", 1);
2960 add_com ("lr", class_info
, nofp_registers_info
, _("\
2961 List of integer registers and their contents, for selected stack frame.\n\
2962 Register name as argument means describe only that register."));
2963 add_info ("all-registers", all_registers_info
, _("\
2964 List of all registers and their contents, for selected stack frame.\n\
2965 Register name as argument means describe only that register."));
2967 add_info ("program", program_info
,
2968 _("Execution status of the program."));
2970 add_info ("float", float_info
,
2971 _("Print the status of the floating point unit\n"));
2973 add_info ("vector", vector_info
,
2974 _("Print the status of the vector unit\n"));