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"
59 /* Functions exported for general use, in inferior.h: */
61 void all_registers_info (char *, int);
63 void registers_info (char *, int);
65 void nexti_command (char *, int);
67 void stepi_command (char *, int);
69 void continue_command (char *, int);
71 void interrupt_target_command (char *args
, int from_tty
);
73 /* Local functions: */
75 static void nofp_registers_info (char *, int);
77 static void print_return_value (struct type
*func_type
,
78 struct type
*value_type
);
80 static void until_next_command (int);
82 static void until_command (char *, int);
84 static void path_info (char *, int);
86 static void path_command (char *, int);
88 static void unset_command (char *, int);
90 static void float_info (char *, int);
92 static void disconnect_command (char *, int);
94 static void unset_environment_command (char *, int);
96 static void set_environment_command (char *, int);
98 static void environment_info (char *, int);
100 static void program_info (char *, int);
102 static void finish_command (char *, int);
104 static void signal_command (char *, int);
106 static void jump_command (char *, int);
108 static void step_1 (int, int, char *);
109 static void step_once (int skip_subroutines
, int single_inst
,
110 int count
, int thread
);
112 static void next_command (char *, int);
114 static void step_command (char *, int);
116 static void run_command (char *, int);
118 static void run_no_args_command (char *args
, int from_tty
);
120 static void go_command (char *line_no
, int from_tty
);
122 static int strip_bg_char (char **);
124 void _initialize_infcmd (void);
126 #define ERROR_NO_INFERIOR \
127 if (!target_has_execution) error (_("The program is not being run."));
129 /* Scratch area where string containing arguments to give to the
130 program will be stored by 'set args'. As soon as anything is
131 stored, notice_args_set will move it into per-inferior storage.
132 Arguments are separated by spaces. Empty string (pointer to '\0')
135 static char *inferior_args_scratch
;
137 /* Scratch area where 'set inferior-tty' will store user-provided value.
138 We'll immediate copy it into per-inferior storage. */
140 static char *inferior_io_terminal_scratch
;
142 /* Pid of our debugged inferior, or 0 if no inferior now.
143 Since various parts of infrun.c test this to see whether there is a program
144 being debugged it should be nonzero (currently 3 is used) for remote
147 ptid_t inferior_ptid
;
149 /* Address at which inferior stopped. */
153 /* Flag indicating that a command has proceeded the inferior past the
154 current breakpoint. */
156 int breakpoint_proceeded
;
158 /* Nonzero if stopped due to completion of a stack dummy routine. */
160 enum stop_stack_kind stop_stack_dummy
;
162 /* Nonzero if stopped due to a random (unexpected) signal in inferior
165 int stopped_by_random_signal
;
168 /* Accessor routines. */
170 /* Set the io terminal for the current inferior. Ownership of
171 TERMINAL_NAME is not transferred. */
174 set_inferior_io_terminal (const char *terminal_name
)
176 xfree (current_inferior ()->terminal
);
177 current_inferior ()->terminal
= terminal_name
? xstrdup (terminal_name
) : 0;
181 get_inferior_io_terminal (void)
183 return current_inferior ()->terminal
;
187 set_inferior_tty_command (char *args
, int from_tty
,
188 struct cmd_list_element
*c
)
190 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
191 Now route it to current inferior. */
192 set_inferior_io_terminal (inferior_io_terminal_scratch
);
196 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
197 struct cmd_list_element
*c
, const char *value
)
199 /* Note that we ignore the passed-in value in favor of computing it
201 const char *inferior_io_terminal
= get_inferior_io_terminal ();
203 if (inferior_io_terminal
== NULL
)
204 inferior_io_terminal
= "";
205 fprintf_filtered (gdb_stdout
,
206 _("Terminal for future runs of program being debugged "
207 "is \"%s\".\n"), inferior_io_terminal
);
211 get_inferior_args (void)
213 if (current_inferior ()->argc
!= 0)
217 n
= construct_inferior_arguments (current_inferior ()->argc
,
218 current_inferior ()->argv
);
219 set_inferior_args (n
);
223 if (current_inferior ()->args
== NULL
)
224 current_inferior ()->args
= xstrdup ("");
226 return current_inferior ()->args
;
229 /* Set the arguments for the current inferior. Ownership of
230 NEWARGS is not transferred. */
233 set_inferior_args (char *newargs
)
235 xfree (current_inferior ()->args
);
236 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
237 current_inferior ()->argc
= 0;
238 current_inferior ()->argv
= 0;
242 set_inferior_args_vector (int argc
, char **argv
)
244 current_inferior ()->argc
= argc
;
245 current_inferior ()->argv
= argv
;
248 /* Notice when `set args' is run. */
250 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
252 /* CLI has assigned the user-provided value to inferior_args_scratch.
253 Now route it to current inferior. */
254 set_inferior_args (inferior_args_scratch
);
257 /* Notice when `show args' is run. */
259 show_args_command (struct ui_file
*file
, int from_tty
,
260 struct cmd_list_element
*c
, const char *value
)
262 /* Note that we ignore the passed-in value in favor of computing it
264 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
268 /* Compute command-line string given argument vector. This does the
269 same shell processing as fork_inferior. */
271 construct_inferior_arguments (int argc
, char **argv
)
275 if (STARTUP_WITH_SHELL
)
277 /* This holds all the characters considered special to the
278 typical Unix shells. We include `^' because the SunOS
279 /bin/sh treats it as a synonym for `|'. */
280 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
285 /* We over-compute the size. It shouldn't matter. */
286 for (i
= 0; i
< argc
; ++i
)
287 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
289 result
= (char *) xmalloc (length
);
292 for (i
= 0; i
< argc
; ++i
)
297 /* Need to handle empty arguments specially. */
298 if (argv
[i
][0] == '\0')
305 for (cp
= argv
[i
]; *cp
; ++cp
)
309 /* A newline cannot be quoted with a backslash (it
310 just disappears), only by putting it inside
318 if (strchr (special
, *cp
) != NULL
)
329 /* In this case we can't handle arguments that contain spaces,
330 tabs, or newlines -- see breakup_args(). */
334 for (i
= 0; i
< argc
; ++i
)
336 char *cp
= strchr (argv
[i
], ' ');
338 cp
= strchr (argv
[i
], '\t');
340 cp
= strchr (argv
[i
], '\n');
342 error (_("can't handle command-line "
343 "argument containing whitespace"));
344 length
+= strlen (argv
[i
]) + 1;
347 result
= (char *) xmalloc (length
);
349 for (i
= 0; i
< argc
; ++i
)
352 strcat (result
, " ");
353 strcat (result
, argv
[i
]);
361 /* This function detects whether or not a '&' character (indicating
362 background execution) has been added as *the last* of the arguments ARGS
363 of a command. If it has, it removes it and returns 1. Otherwise it
364 does nothing and returns 0. */
366 strip_bg_char (char **args
)
370 p
= strchr (*args
, '&');
374 if (p
== (*args
+ strlen (*args
) - 1))
376 if (strlen (*args
) > 1)
380 while (*p
== ' ' || *p
== '\t');
391 /* Common actions to take after creating any sort of inferior, by any
392 means (running, attaching, connecting, et cetera). The target
393 should be stopped. */
396 post_create_inferior (struct target_ops
*target
, int from_tty
)
398 /* Be sure we own the terminal in case write operations are performed. */
399 target_terminal_ours ();
401 /* If the target hasn't taken care of this already, do it now.
402 Targets which need to access registers during to_open,
403 to_create_inferior, or to_attach should do it earlier; but many
405 target_find_description ();
407 /* Now that we know the register layout, retrieve current PC. */
408 stop_pc
= regcache_read_pc (get_current_regcache ());
412 /* Create the hooks to handle shared library load and unload
414 #ifdef SOLIB_CREATE_INFERIOR_HOOK
415 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
417 solib_create_inferior_hook (from_tty
);
421 /* If the solist is global across processes, there's no need to
423 if (exec_bfd
&& !gdbarch_has_global_solist (target_gdbarch
))
425 /* Sometimes the platform-specific hook loads initial shared
426 libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be
427 incorrectly 0 but such solib targets should be fixed anyway. If we
428 made all the inferior hook methods consistent, this call could be
429 removed. Call it only after the solib target has been initialized by
430 solib_create_inferior_hook. */
433 SOLIB_ADD (NULL
, 0, target
, auto_solib_add
);
435 solib_add (NULL
, 0, target
, auto_solib_add
);
439 /* If the user sets watchpoints before execution having started,
440 then she gets software watchpoints, because GDB can't know which
441 target will end up being pushed, or if it supports hardware
442 watchpoints or not. breakpoint_re_set takes care of promoting
443 watchpoints to hardware watchpoints if possible, however, if this
444 new inferior doesn't load shared libraries or we don't pull in
445 symbols from any other source on this target/arch,
446 breakpoint_re_set is never called. Call it now so that software
447 watchpoints get a chance to be promoted to hardware watchpoints
448 if the now pushed target supports hardware watchpoints. */
449 breakpoint_re_set ();
451 observer_notify_inferior_created (target
, from_tty
);
454 /* Kill the inferior if already running. This function is designed
455 to be called when we are about to start the execution of the program
456 from the beginning. Ask the user to confirm that he wants to restart
457 the program being debugged when FROM_TTY is non-null. */
460 kill_if_already_running (int from_tty
)
462 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
464 /* Bail out before killing the program if we will not be able to
466 target_require_runnable ();
469 && !query (_("The program being debugged has been started already.\n\
470 Start it from the beginning? ")))
471 error (_("Program not restarted."));
476 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
477 a temporary breakpoint at the begining of the main program before
478 running the program. */
481 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
484 struct cleanup
*old_chain
;
489 kill_if_already_running (from_tty
);
491 init_wait_for_inferior ();
492 clear_breakpoint_hit_counts ();
494 /* Clean up any leftovers from other runs. Some other things from
495 this function should probably be moved into target_pre_inferior. */
496 target_pre_inferior (from_tty
);
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 if (non_stop
&& !target_supports_non_stop ())
515 error (_("The target does not support running in non-stop mode."));
517 /* We keep symbols from add-symbol-file, on the grounds that the
518 user might want to add some symbols before running the program
519 (right?). But sometimes (dynamic loading where the user manually
520 introduces the new symbols with add-symbol-file), the code which
521 the symbols describe does not persist between runs. Currently
522 the user has to manually nuke all symbols between runs if they
523 want them to go away (PR 2207). This is probably reasonable. */
527 if (target_can_async_p ())
528 async_disable_stdin ();
532 int async_exec
= strip_bg_char (&args
);
534 /* If we get a request for running in the bg but the target
535 doesn't support it, error out. */
536 if (async_exec
&& !target_can_async_p ())
537 error (_("Asynchronous execution not supported on this target."));
539 /* If we don't get a request of running in the bg, then we need
540 to simulate synchronous (fg) execution. */
541 if (!async_exec
&& target_can_async_p ())
543 /* Simulate synchronous execution. */
544 async_disable_stdin ();
547 /* If there were other args, beside '&', process them. */
549 set_inferior_args (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 (current_inferior ()->environment
),
572 /* We're starting off a new process. When we get out of here, in
573 non-stop mode, finish the state of all threads of that process,
574 but leave other threads alone, as they may be stopped in internal
575 events --- the frontend shouldn't see them as stopped. In
576 all-stop, always finish the state of all threads, as we may be
577 resuming more than just the new process. */
579 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
581 ptid
= minus_one_ptid
;
582 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
584 /* Pass zero for FROM_TTY, because at this point the "run" command
585 has done its thing; now we are setting up the running program. */
586 post_create_inferior (¤t_target
, 0);
588 /* Start the target running. Do not use -1 continuation as it would skip
589 breakpoint right at the entry point. */
590 proceed (regcache_read_pc (get_current_regcache ()), TARGET_SIGNAL_0
, 0);
592 /* Since there was no error, there's no need to finish the thread
594 discard_cleanups (old_chain
);
598 run_command (char *args
, int from_tty
)
600 run_command_1 (args
, from_tty
, 0);
604 run_no_args_command (char *args
, int from_tty
)
606 set_inferior_args ("");
610 /* Start the execution of the program up until the beginning of the main
614 start_command (char *args
, int from_tty
)
616 /* Some languages such as Ada need to search inside the program
617 minimal symbols for the location where to put the temporary
618 breakpoint before starting. */
619 if (!have_minimal_symbols ())
620 error (_("No symbol table loaded. Use the \"file\" command."));
622 /* Run the program until reaching the main procedure... */
623 run_command_1 (args
, from_tty
, 1);
627 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
629 /* We go through all threads individually instead of compressing
630 into a single target `resume_all' request, because some threads
631 may be stopped in internal breakpoints/events, or stopped waiting
632 for its turn in the displaced stepping queue (that is, they are
633 running && !executing). The target side has no idea about why
634 the thread is stopped, so a `resume_all' command would resume too
635 much. If/when GDB gains a way to tell the target `hold this
636 thread stopped until I say otherwise', then we can optimize
638 if (!is_stopped (thread
->ptid
))
641 switch_to_thread (thread
->ptid
);
642 clear_proceed_status ();
643 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
648 ensure_valid_thread (void)
650 if (ptid_equal (inferior_ptid
, null_ptid
)
651 || is_exited (inferior_ptid
))
652 error (_("Cannot execute this command without a live selected thread."));
655 /* If the user is looking at trace frames, any resumption of execution
656 is likely to mix up recorded and live target data. So simply
657 disallow those commands. */
660 ensure_not_tfind_mode (void)
662 if (get_traceframe_number () >= 0)
663 error (_("Cannot execute this command while looking at trace frames."));
667 continue_1 (int all_threads
)
670 ensure_not_tfind_mode ();
672 if (non_stop
&& all_threads
)
674 /* Don't error out if the current thread is running, because
675 there may be other stopped threads. */
676 struct cleanup
*old_chain
;
678 /* Backup current thread and selected frame. */
679 old_chain
= make_cleanup_restore_current_thread ();
681 iterate_over_threads (proceed_thread_callback
, NULL
);
683 /* Restore selected ptid. */
684 do_cleanups (old_chain
);
688 ensure_valid_thread ();
689 ensure_not_running ();
690 clear_proceed_status ();
691 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
695 /* continue [-a] [proceed-count] [&] */
697 continue_command (char *args
, int from_tty
)
703 /* Find out whether we must run in the background. */
705 async_exec
= strip_bg_char (&args
);
707 /* If we must run in the background, but the target can't do it,
709 if (async_exec
&& !target_can_async_p ())
710 error (_("Asynchronous execution not supported on this target."));
712 /* If we are not asked to run in the bg, then prepare to run in the
713 foreground, synchronously. */
714 if (!async_exec
&& target_can_async_p ())
716 /* Simulate synchronous execution. */
717 async_disable_stdin ();
722 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
725 args
+= sizeof ("-a") - 1;
731 if (!non_stop
&& all_threads
)
732 error (_("`-a' is meaningless in all-stop mode."));
734 if (args
!= NULL
&& all_threads
)
735 error (_("Can't resume all threads and specify "
736 "proceed count simultaneously."));
738 /* If we have an argument left, set proceed count of breakpoint we
745 struct thread_info
*tp
;
748 tp
= find_thread_ptid (inferior_ptid
);
752 struct target_waitstatus ws
;
754 get_last_target_status (&last_ptid
, &ws
);
755 tp
= find_thread_ptid (last_ptid
);
758 bs
= tp
->control
.stop_bpstat
;
760 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
763 set_ignore_count (num
,
764 parse_and_eval_long (args
) - 1,
766 /* set_ignore_count prints a message ending with a period.
767 So print two spaces before "Continuing.". */
769 printf_filtered (" ");
773 if (!stopped
&& from_tty
)
776 ("Not stopped at any breakpoint; argument ignored.\n");
781 printf_filtered (_("Continuing.\n"));
783 continue_1 (all_threads
);
786 /* Record the starting point of a "step" or "next" command. */
789 set_step_frame (void)
791 struct symtab_and_line sal
;
793 find_frame_sal (get_current_frame (), &sal
);
794 set_step_info (get_current_frame (), sal
);
797 /* Step until outside of current statement. */
800 step_command (char *count_string
, int from_tty
)
802 step_1 (0, 0, count_string
);
805 /* Likewise, but skip over subroutine calls as if single instructions. */
808 next_command (char *count_string
, int from_tty
)
810 step_1 (1, 0, count_string
);
813 /* Likewise, but step only one instruction. */
816 stepi_command (char *count_string
, int from_tty
)
818 step_1 (0, 1, count_string
);
822 nexti_command (char *count_string
, int from_tty
)
824 step_1 (1, 1, count_string
);
828 delete_longjmp_breakpoint_cleanup (void *arg
)
830 int thread
= * (int *) arg
;
831 delete_longjmp_breakpoint (thread
);
835 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
838 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
843 ensure_not_tfind_mode ();
844 ensure_valid_thread ();
845 ensure_not_running ();
848 async_exec
= strip_bg_char (&count_string
);
850 /* If we get a request for running in the bg but the target
851 doesn't support it, error out. */
852 if (async_exec
&& !target_can_async_p ())
853 error (_("Asynchronous execution not supported on this target."));
855 /* If we don't get a request of running in the bg, then we need
856 to simulate synchronous (fg) execution. */
857 if (!async_exec
&& target_can_async_p ())
859 /* Simulate synchronous execution. */
860 async_disable_stdin ();
863 count
= count_string
? parse_and_eval_long (count_string
) : 1;
865 if (!single_inst
|| skip_subroutines
) /* Leave si command alone. */
867 struct thread_info
*tp
= inferior_thread ();
869 if (in_thread_list (inferior_ptid
))
870 thread
= pid_to_thread_id (inferior_ptid
);
872 set_longjmp_breakpoint (tp
, get_frame_id (get_current_frame ()));
874 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
877 /* In synchronous case, all is well; each step_once call will step once. */
878 if (!target_can_async_p ())
880 for (; count
> 0; count
--)
882 struct thread_info
*tp
;
884 step_once (skip_subroutines
, single_inst
, count
, thread
);
886 if (target_has_execution
887 && !ptid_equal (inferior_ptid
, null_ptid
))
888 tp
= inferior_thread ();
892 if (!tp
|| !tp
->control
.stop_step
|| !tp
->step_multi
)
894 /* If we stopped for some reason that is not stepping
895 there are no further steps to make. */
902 do_cleanups (cleanups
);
906 /* In the case of an asynchronous target things get complicated;
907 do only one step for now, before returning control to the
908 event loop. Let the continuation figure out how many other
909 steps we need to do, and handle them one at the time, through
911 step_once (skip_subroutines
, single_inst
, count
, thread
);
913 /* We are running, and the continuation is installed. It will
914 disable the longjmp breakpoint as appropriate. */
915 discard_cleanups (cleanups
);
919 struct step_1_continuation_args
922 int skip_subroutines
;
927 /* Called after we are done with one step operation, to check whether
928 we need to step again, before we print the prompt and return control
929 to the user. If count is > 1, we will need to do one more call to
930 proceed(), via step_once(). Basically it is like step_once and
931 step_1_continuation are co-recursive. */
933 step_1_continuation (void *args
)
935 struct step_1_continuation_args
*a
= args
;
937 if (target_has_execution
)
939 struct thread_info
*tp
;
941 tp
= inferior_thread ();
942 if (tp
->step_multi
&& tp
->control
.stop_step
)
944 /* There are more steps to make, and we did stop due to
945 ending a stepping range. Do another step. */
946 step_once (a
->skip_subroutines
, a
->single_inst
,
947 a
->count
- 1, a
->thread
);
953 /* We either stopped for some reason that is not stepping, or there
954 are no further steps to make. Cleanup. */
955 if (!a
->single_inst
|| a
->skip_subroutines
)
956 delete_longjmp_breakpoint (a
->thread
);
959 /* Do just one step operation. This is useful to implement the 'step
960 n' kind of commands. In case of asynchronous targets, we will have
961 to set up a continuation to be done after the target stops (after
962 this one step). For synch targets, the caller handles further
966 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
968 struct frame_info
*frame
= get_current_frame ();
972 /* Don't assume THREAD is a valid thread id. It is set to -1 if
973 the longjmp breakpoint was not required. Use the
974 INFERIOR_PTID thread instead, which is the same thread when
976 struct thread_info
*tp
= inferior_thread ();
978 clear_proceed_status ();
985 /* Step at an inlined function behaves like "down". */
986 if (!skip_subroutines
&& !single_inst
987 && inline_skipped_frames (inferior_ptid
))
989 step_into_inline_frame (inferior_ptid
);
991 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
993 /* Pretend that we've stopped. */
998 pc
= get_frame_pc (frame
);
999 find_pc_line_pc_range (pc
,
1000 &tp
->control
.step_range_start
,
1001 &tp
->control
.step_range_end
);
1003 /* If we have no line info, switch to stepi mode. */
1004 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1005 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1006 else if (tp
->control
.step_range_end
== 0)
1010 if (find_pc_partial_function (pc
, &name
,
1011 &tp
->control
.step_range_start
,
1012 &tp
->control
.step_range_end
) == 0)
1013 error (_("Cannot find bounds of current function"));
1015 target_terminal_ours ();
1016 printf_filtered (_("Single stepping until exit from function %s,"
1017 "\nwhich has no line number information.\n"),
1023 /* Say we are stepping, but stop after one insn whatever it does. */
1024 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1025 if (!skip_subroutines
)
1027 Don't step over function calls, not even to functions lacking
1029 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1032 if (skip_subroutines
)
1033 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1035 tp
->step_multi
= (count
> 1);
1036 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1038 /* For async targets, register a continuation to do any
1039 additional steps. For sync targets, the caller will handle
1040 further stepping. */
1041 if (target_can_async_p ())
1043 struct step_1_continuation_args
*args
;
1045 args
= xmalloc (sizeof (*args
));
1046 args
->skip_subroutines
= skip_subroutines
;
1047 args
->single_inst
= single_inst
;
1048 args
->count
= count
;
1049 args
->thread
= thread
;
1051 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
1057 /* Continue program at specified address. */
1060 jump_command (char *arg
, int from_tty
)
1062 struct gdbarch
*gdbarch
= get_current_arch ();
1064 struct symtabs_and_lines sals
;
1065 struct symtab_and_line sal
;
1071 ensure_not_tfind_mode ();
1072 ensure_valid_thread ();
1073 ensure_not_running ();
1075 /* Find out whether we must run in the background. */
1077 async_exec
= strip_bg_char (&arg
);
1079 /* If we must run in the background, but the target can't do it,
1081 if (async_exec
&& !target_can_async_p ())
1082 error (_("Asynchronous execution not supported on this target."));
1085 error_no_arg (_("starting address"));
1087 sals
= decode_line_spec_1 (arg
, 1);
1088 if (sals
.nelts
!= 1)
1090 error (_("Unreasonable jump request"));
1096 if (sal
.symtab
== 0 && sal
.pc
== 0)
1097 error (_("No source file has been specified."));
1099 resolve_sal_pc (&sal
); /* May error out. */
1101 /* See if we are trying to jump to another function. */
1102 fn
= get_frame_function (get_current_frame ());
1103 sfn
= find_pc_function (sal
.pc
);
1104 if (fn
!= NULL
&& sfn
!= fn
)
1106 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1107 SYMBOL_PRINT_NAME (fn
)))
1109 error (_("Not confirmed."));
1116 fixup_symbol_section (sfn
, 0);
1117 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn
)) &&
1118 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn
)))
1120 if (!query (_("WARNING!!! Destination is in "
1121 "unmapped overlay! Jump anyway? ")))
1123 error (_("Not confirmed."));
1133 printf_filtered (_("Continuing at "));
1134 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1135 printf_filtered (".\n");
1138 /* If we are not asked to run in the bg, then prepare to run in the
1139 foreground, synchronously. */
1140 if (!async_exec
&& target_can_async_p ())
1142 /* Simulate synchronous execution. */
1143 async_disable_stdin ();
1146 clear_proceed_status ();
1147 proceed (addr
, TARGET_SIGNAL_0
, 0);
1151 /* Go to line or address in current procedure. */
1153 go_command (char *line_no
, int from_tty
)
1155 if (line_no
== (char *) NULL
|| !*line_no
)
1156 printf_filtered (_("Usage: go <location>\n"));
1159 tbreak_command (line_no
, from_tty
);
1160 jump_command (line_no
, from_tty
);
1165 /* Continue program giving it specified signal. */
1168 signal_command (char *signum_exp
, int from_tty
)
1170 enum target_signal oursig
;
1173 dont_repeat (); /* Too dangerous. */
1175 ensure_not_tfind_mode ();
1176 ensure_valid_thread ();
1177 ensure_not_running ();
1179 /* Find out whether we must run in the background. */
1180 if (signum_exp
!= NULL
)
1181 async_exec
= strip_bg_char (&signum_exp
);
1183 /* If we must run in the background, but the target can't do it,
1185 if (async_exec
&& !target_can_async_p ())
1186 error (_("Asynchronous execution not supported on this target."));
1188 /* If we are not asked to run in the bg, then prepare to run in the
1189 foreground, synchronously. */
1190 if (!async_exec
&& target_can_async_p ())
1192 /* Simulate synchronous execution. */
1193 async_disable_stdin ();
1197 error_no_arg (_("signal number"));
1199 /* It would be even slicker to make signal names be valid expressions,
1200 (the type could be "enum $signal" or some such), then the user could
1201 assign them to convenience variables. */
1202 oursig
= target_signal_from_name (signum_exp
);
1204 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1206 /* No, try numeric. */
1207 int num
= parse_and_eval_long (signum_exp
);
1210 oursig
= TARGET_SIGNAL_0
;
1212 oursig
= target_signal_from_command (num
);
1217 if (oursig
== TARGET_SIGNAL_0
)
1218 printf_filtered (_("Continuing with no signal.\n"));
1220 printf_filtered (_("Continuing with signal %s.\n"),
1221 target_signal_to_name (oursig
));
1224 clear_proceed_status ();
1225 proceed ((CORE_ADDR
) -1, oursig
, 0);
1228 /* A continuation callback for until_next_command. */
1231 until_next_continuation (void *arg
)
1233 struct thread_info
*tp
= arg
;
1235 delete_longjmp_breakpoint (tp
->num
);
1238 /* Proceed until we reach a different source line with pc greater than
1239 our current one or exit the function. We skip calls in both cases.
1241 Note that eventually this command should probably be changed so
1242 that only source lines are printed out when we hit the breakpoint
1243 we set. This may involve changes to wait_for_inferior and the
1244 proceed status code. */
1247 until_next_command (int from_tty
)
1249 struct frame_info
*frame
;
1251 struct symbol
*func
;
1252 struct symtab_and_line sal
;
1253 struct thread_info
*tp
= inferior_thread ();
1254 int thread
= tp
->num
;
1255 struct cleanup
*old_chain
;
1257 clear_proceed_status ();
1260 frame
= get_current_frame ();
1262 /* Step until either exited from this function or greater
1263 than the current line (if in symbolic section) or pc (if
1266 pc
= get_frame_pc (frame
);
1267 func
= find_pc_function (pc
);
1271 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1273 if (msymbol
== NULL
)
1274 error (_("Execution is not within a known function."));
1276 tp
->control
.step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1277 tp
->control
.step_range_end
= pc
;
1281 sal
= find_pc_line (pc
, 0);
1283 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1284 tp
->control
.step_range_end
= sal
.end
;
1287 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1289 tp
->step_multi
= 0; /* Only one call to proceed */
1291 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1292 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1294 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1296 if (target_can_async_p () && is_running (inferior_ptid
))
1298 discard_cleanups (old_chain
);
1299 add_continuation (tp
, until_next_continuation
, tp
, NULL
);
1302 do_cleanups (old_chain
);
1306 until_command (char *arg
, int from_tty
)
1311 ensure_not_tfind_mode ();
1312 ensure_valid_thread ();
1313 ensure_not_running ();
1315 /* Find out whether we must run in the background. */
1317 async_exec
= strip_bg_char (&arg
);
1319 /* If we must run in the background, but the target can't do it,
1321 if (async_exec
&& !target_can_async_p ())
1322 error (_("Asynchronous execution not supported on this target."));
1324 /* If we are not asked to run in the bg, then prepare to run in the
1325 foreground, synchronously. */
1326 if (!async_exec
&& target_can_async_p ())
1328 /* Simulate synchronous execution. */
1329 async_disable_stdin ();
1333 until_break_command (arg
, from_tty
, 0);
1335 until_next_command (from_tty
);
1339 advance_command (char *arg
, int from_tty
)
1344 ensure_not_tfind_mode ();
1345 ensure_valid_thread ();
1346 ensure_not_running ();
1349 error_no_arg (_("a location"));
1351 /* Find out whether we must run in the background. */
1353 async_exec
= strip_bg_char (&arg
);
1355 /* If we must run in the background, but the target can't do it,
1357 if (async_exec
&& !target_can_async_p ())
1358 error (_("Asynchronous execution not supported on this target."));
1360 /* If we are not asked to run in the bg, then prepare to run in the
1361 foreground, synchronously. */
1362 if (!async_exec
&& target_can_async_p ())
1364 /* Simulate synchronous execution. */
1365 async_disable_stdin ();
1368 until_break_command (arg
, from_tty
, 1);
1371 /* Print the result of a function at the end of a 'finish' command. */
1374 print_return_value (struct type
*func_type
, struct type
*value_type
)
1376 struct gdbarch
*gdbarch
= get_regcache_arch (stop_registers
);
1377 struct cleanup
*old_chain
;
1378 struct ui_stream
*stb
;
1379 struct value
*value
;
1381 CHECK_TYPEDEF (value_type
);
1382 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1384 /* FIXME: 2003-09-27: When returning from a nested inferior function
1385 call, it's possible (with no help from the architecture vector)
1386 to locate and return/print a "struct return" value. This is just
1387 a more complicated case of what is already being done in in the
1388 inferior function call code. In fact, when inferior function
1389 calls are made async, this will likely be made the norm. */
1391 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1394 case RETURN_VALUE_REGISTER_CONVENTION
:
1395 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1396 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1397 value
= allocate_value (value_type
);
1398 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1399 value_contents_raw (value
), NULL
);
1401 case RETURN_VALUE_STRUCT_CONVENTION
:
1405 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1410 struct value_print_options opts
;
1413 stb
= ui_out_stream_new (uiout
);
1414 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1415 ui_out_text (uiout
, "Value returned is ");
1416 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1417 record_latest_value (value
));
1418 ui_out_text (uiout
, " = ");
1419 get_raw_print_options (&opts
);
1420 value_print (value
, stb
->stream
, &opts
);
1421 ui_out_field_stream (uiout
, "return-value", stb
);
1422 ui_out_text (uiout
, "\n");
1423 do_cleanups (old_chain
);
1427 ui_out_text (uiout
, "Value returned has type: ");
1428 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1429 ui_out_text (uiout
, ".");
1430 ui_out_text (uiout
, " Cannot determine contents\n");
1434 /* Stuff that needs to be done by the finish command after the target
1435 has stopped. In asynchronous mode, we wait for the target to stop
1436 in the call to poll or select in the event loop, so it is
1437 impossible to do all the stuff as part of the finish_command
1438 function itself. The only chance we have to complete this command
1439 is in fetch_inferior_event, which is called by the event loop as
1440 soon as it detects that the target has stopped. This function is
1441 called via the cmd_continuation pointer. */
1443 struct finish_command_continuation_args
1445 struct breakpoint
*breakpoint
;
1446 struct symbol
*function
;
1450 finish_command_continuation (void *arg
)
1452 struct finish_command_continuation_args
*a
= arg
;
1453 struct thread_info
*tp
= NULL
;
1456 if (!ptid_equal (inferior_ptid
, null_ptid
)
1457 && target_has_execution
1458 && is_stopped (inferior_ptid
))
1460 tp
= inferior_thread ();
1461 bs
= tp
->control
.stop_bpstat
;
1464 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1465 && a
->function
!= NULL
)
1467 struct type
*value_type
;
1469 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1471 internal_error (__FILE__
, __LINE__
,
1472 _("finish_command: function has no target type"));
1474 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1476 volatile struct gdb_exception ex
;
1478 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1480 /* print_return_value can throw an exception in some
1481 circumstances. We need to catch this so that we still
1482 delete the breakpoint. */
1483 print_return_value (SYMBOL_TYPE (a
->function
), value_type
);
1486 exception_print (gdb_stdout
, ex
);
1490 /* We suppress normal call of normal_stop observer and do it here so
1491 that the *stopped notification includes the return value. */
1492 if (bs
!= NULL
&& tp
->control
.proceed_to_finish
)
1493 observer_notify_normal_stop (bs
, 1 /* print frame */);
1494 delete_breakpoint (a
->breakpoint
);
1495 delete_longjmp_breakpoint (inferior_thread ()->num
);
1499 finish_command_continuation_free_arg (void *arg
)
1504 /* finish_backward -- helper function for finish_command. */
1507 finish_backward (struct symbol
*function
)
1509 struct symtab_and_line sal
;
1510 struct thread_info
*tp
= inferior_thread ();
1511 struct breakpoint
*breakpoint
;
1512 struct cleanup
*old_chain
;
1514 CORE_ADDR func_addr
;
1517 pc
= get_frame_pc (get_current_frame ());
1519 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1520 internal_error (__FILE__
, __LINE__
,
1521 _("Finish: couldn't find function."));
1523 sal
= find_pc_line (func_addr
, 0);
1525 /* We don't need a return value. */
1526 tp
->control
.proceed_to_finish
= 0;
1527 /* Special case: if we're sitting at the function entry point,
1528 then all we need to do is take a reverse singlestep. We
1529 don't need to set a breakpoint, and indeed it would do us
1532 Note that this can only happen at frame #0, since there's
1533 no way that a function up the stack can have a return address
1534 that's equal to its entry point. */
1538 struct frame_info
*frame
= get_selected_frame (NULL
);
1539 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1541 /* Set breakpoint and continue. */
1543 set_momentary_breakpoint (gdbarch
, sal
,
1544 get_stack_frame_id (frame
),
1546 /* Tell the breakpoint to keep quiet. We won't be done
1547 until we've done another reverse single-step. */
1548 make_breakpoint_silent (breakpoint
);
1549 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1550 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1551 /* We will be stopped when proceed returns. */
1552 back_up
= (bpstat_find_breakpoint (tp
->control
.stop_bpstat
, breakpoint
)
1554 do_cleanups (old_chain
);
1560 /* If in fact we hit the step-resume breakpoint (and not
1561 some other breakpoint), then we're almost there --
1562 we just need to back up by one more single-step. */
1563 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1564 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1569 /* finish_forward -- helper function for finish_command. */
1572 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1574 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1575 struct symtab_and_line sal
;
1576 struct thread_info
*tp
= inferior_thread ();
1577 struct breakpoint
*breakpoint
;
1578 struct cleanup
*old_chain
;
1579 struct finish_command_continuation_args
*cargs
;
1580 int thread
= tp
->num
;
1582 sal
= find_pc_line (get_frame_pc (frame
), 0);
1583 sal
.pc
= get_frame_pc (frame
);
1585 breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1586 get_stack_frame_id (frame
),
1589 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1591 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1592 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1594 /* We want stop_registers, please... */
1595 tp
->control
.proceed_to_finish
= 1;
1596 cargs
= xmalloc (sizeof (*cargs
));
1598 cargs
->breakpoint
= breakpoint
;
1599 cargs
->function
= function
;
1600 add_continuation (tp
, finish_command_continuation
, cargs
,
1601 finish_command_continuation_free_arg
);
1602 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1604 discard_cleanups (old_chain
);
1605 if (!target_can_async_p ())
1606 do_all_continuations ();
1609 /* "finish": Set a temporary breakpoint at the place the selected
1610 frame will return to, then continue. */
1613 finish_command (char *arg
, int from_tty
)
1615 struct frame_info
*frame
;
1616 struct symbol
*function
;
1621 ensure_not_tfind_mode ();
1622 ensure_valid_thread ();
1623 ensure_not_running ();
1625 /* Find out whether we must run in the background. */
1627 async_exec
= strip_bg_char (&arg
);
1629 /* If we must run in the background, but the target can't do it,
1631 if (async_exec
&& !target_can_async_p ())
1632 error (_("Asynchronous execution not supported on this target."));
1634 /* Don't try to async in reverse. */
1635 if (async_exec
&& execution_direction
== EXEC_REVERSE
)
1636 error (_("Asynchronous 'finish' not supported in reverse."));
1638 /* If we are not asked to run in the bg, then prepare to run in the
1639 foreground, synchronously. */
1640 if (!async_exec
&& target_can_async_p ())
1642 /* Simulate synchronous execution. */
1643 async_disable_stdin ();
1647 error (_("The \"finish\" command does not take any arguments."));
1649 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1651 error (_("\"finish\" not meaningful in the outermost frame."));
1653 clear_proceed_status ();
1655 /* Finishing from an inline frame is completely different. We don't
1656 try to show the "return value" - no way to locate it. So we do
1657 not need a completion. */
1658 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1661 /* Claim we are stepping in the calling frame. An empty step
1662 range means that we will stop once we aren't in a function
1663 called by that frame. We don't use the magic "1" value for
1664 step_range_end, because then infrun will think this is nexti,
1665 and not step over the rest of this inlined function call. */
1666 struct thread_info
*tp
= inferior_thread ();
1667 struct symtab_and_line empty_sal
;
1669 init_sal (&empty_sal
);
1670 set_step_info (frame
, empty_sal
);
1671 tp
->control
.step_range_start
= get_frame_pc (frame
);
1672 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1673 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1675 /* Print info on the selected frame, including level number but not
1679 printf_filtered (_("Run till exit from "));
1680 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1683 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1687 /* Find the function we will return from. */
1689 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1691 /* Print info on the selected frame, including level number but not
1695 if (execution_direction
== EXEC_REVERSE
)
1696 printf_filtered (_("Run back to call of "));
1698 printf_filtered (_("Run till exit from "));
1700 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1703 if (execution_direction
== EXEC_REVERSE
)
1704 finish_backward (function
);
1706 finish_forward (function
, frame
);
1711 program_info (char *args
, int from_tty
)
1715 struct thread_info
*tp
;
1718 if (!target_has_execution
)
1720 printf_filtered (_("The program being debugged is not being run.\n"));
1725 ptid
= inferior_ptid
;
1728 struct target_waitstatus ws
;
1730 get_last_target_status (&ptid
, &ws
);
1733 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1734 error (_("Invalid selected thread."));
1735 else if (is_running (ptid
))
1736 error (_("Selected thread is running."));
1738 tp
= find_thread_ptid (ptid
);
1739 bs
= tp
->control
.stop_bpstat
;
1740 stat
= bpstat_num (&bs
, &num
);
1742 target_files_info ();
1743 printf_filtered (_("Program stopped at %s.\n"),
1744 paddress (target_gdbarch
, stop_pc
));
1745 if (tp
->control
.stop_step
)
1746 printf_filtered (_("It stopped after being stepped.\n"));
1749 /* There may be several breakpoints in the same place, so this
1750 isn't as strange as it seems. */
1755 printf_filtered (_("It stopped at a breakpoint "
1756 "that has since been deleted.\n"));
1759 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1760 stat
= bpstat_num (&bs
, &num
);
1763 else if (tp
->suspend
.stop_signal
!= TARGET_SIGNAL_0
)
1765 printf_filtered (_("It stopped with signal %s, %s.\n"),
1766 target_signal_to_name (tp
->suspend
.stop_signal
),
1767 target_signal_to_string (tp
->suspend
.stop_signal
));
1772 printf_filtered (_("Type \"info stack\" or \"info "
1773 "registers\" for more information.\n"));
1778 environment_info (char *var
, int from_tty
)
1782 char *val
= get_in_environ (current_inferior ()->environment
, var
);
1786 puts_filtered (var
);
1787 puts_filtered (" = ");
1788 puts_filtered (val
);
1789 puts_filtered ("\n");
1793 puts_filtered ("Environment variable \"");
1794 puts_filtered (var
);
1795 puts_filtered ("\" not defined.\n");
1800 char **vector
= environ_vector (current_inferior ()->environment
);
1804 puts_filtered (*vector
++);
1805 puts_filtered ("\n");
1811 set_environment_command (char *arg
, int from_tty
)
1813 char *p
, *val
, *var
;
1817 error_no_arg (_("environment variable and value"));
1819 /* Find seperation between variable name and value. */
1820 p
= (char *) strchr (arg
, '=');
1821 val
= (char *) strchr (arg
, ' ');
1823 if (p
!= 0 && val
!= 0)
1825 /* We have both a space and an equals. If the space is before the
1826 equals, walk forward over the spaces til we see a nonspace
1827 (possibly the equals). */
1832 /* Now if the = is after the char following the spaces,
1833 take the char following the spaces. */
1837 else if (val
!= 0 && p
== 0)
1841 error_no_arg (_("environment variable to set"));
1843 if (p
== 0 || p
[1] == 0)
1847 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
1851 /* Not setting variable value to null. */
1853 while (*val
== ' ' || *val
== '\t')
1857 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1860 var
= savestring (arg
, p
- arg
);
1863 printf_filtered (_("Setting environment variable "
1864 "\"%s\" to null value.\n"),
1866 set_in_environ (current_inferior ()->environment
, var
, "");
1869 set_in_environ (current_inferior ()->environment
, var
, val
);
1874 unset_environment_command (char *var
, int from_tty
)
1878 /* If there is no argument, delete all environment variables.
1879 Ask for confirmation if reading from the terminal. */
1880 if (!from_tty
|| query (_("Delete all environment variables? ")))
1882 free_environ (current_inferior ()->environment
);
1883 current_inferior ()->environment
= make_environ ();
1887 unset_in_environ (current_inferior ()->environment
, var
);
1890 /* Handle the execution path (PATH variable). */
1892 static const char path_var_name
[] = "PATH";
1895 path_info (char *args
, int from_tty
)
1897 puts_filtered ("Executable and object file path: ");
1898 puts_filtered (get_in_environ (current_inferior ()->environment
,
1900 puts_filtered ("\n");
1903 /* Add zero or more directories to the front of the execution path. */
1906 path_command (char *dirname
, int from_tty
)
1912 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
1913 /* Can be null if path is not set. */
1916 exec_path
= xstrdup (env
);
1917 mod_path (dirname
, &exec_path
);
1918 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
1921 path_info ((char *) NULL
, from_tty
);
1925 /* Print out the machine register regnum. If regnum is -1, print all
1926 registers (print_all == 1) or all non-float and non-vector
1927 registers (print_all == 0).
1929 For most machines, having all_registers_info() print the
1930 register(s) one per line is good enough. If a different format is
1931 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1932 regs), or there is an existing convention for showing all the
1933 registers, define the architecture method PRINT_REGISTERS_INFO to
1934 provide that format. */
1937 default_print_registers_info (struct gdbarch
*gdbarch
,
1938 struct ui_file
*file
,
1939 struct frame_info
*frame
,
1940 int regnum
, int print_all
)
1943 const int numregs
= gdbarch_num_regs (gdbarch
)
1944 + gdbarch_num_pseudo_regs (gdbarch
);
1945 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1947 for (i
= 0; i
< numregs
; i
++)
1949 /* Decide between printing all regs, non-float / vector regs, or
1955 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1960 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1970 /* If the register name is empty, it is undefined for this
1971 processor, so don't display anything. */
1972 if (gdbarch_register_name (gdbarch
, i
) == NULL
1973 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1976 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1977 print_spaces_filtered (15 - strlen (gdbarch_register_name
1978 (gdbarch
, i
)), file
);
1980 /* Get the data in raw format. */
1981 if (! frame_register_read (frame
, i
, buffer
))
1983 fprintf_filtered (file
, "*value not available*\n");
1987 /* If virtual format is floating, print it that way, and in raw
1989 if (TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_FLT
1990 || TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_DECFLOAT
)
1993 struct value_print_options opts
;
1995 get_user_print_options (&opts
);
1997 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1998 file
, 0, NULL
, &opts
, current_language
);
2000 fprintf_filtered (file
, "\t(raw 0x");
2001 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
2005 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
2008 idx
= register_size (gdbarch
, i
) - 1 - j
;
2009 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
2011 fprintf_filtered (file
, ")");
2015 struct value_print_options opts
;
2017 /* Print the register in hex. */
2018 get_formatted_print_options (&opts
, 'x');
2020 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
2021 file
, 0, NULL
, &opts
, current_language
);
2022 /* If not a vector register, print it also according to its
2024 if (TYPE_VECTOR (register_type (gdbarch
, i
)) == 0)
2026 get_user_print_options (&opts
);
2028 fprintf_filtered (file
, "\t");
2029 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
2030 file
, 0, NULL
, &opts
, current_language
);
2034 fprintf_filtered (file
, "\n");
2039 registers_info (char *addr_exp
, int fpregs
)
2041 struct frame_info
*frame
;
2042 struct gdbarch
*gdbarch
;
2044 if (!target_has_registers
)
2045 error (_("The program has no registers now."));
2046 frame
= get_selected_frame (NULL
);
2047 gdbarch
= get_frame_arch (frame
);
2051 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2056 while (*addr_exp
!= '\0')
2061 /* Keep skipping leading white space. */
2062 if (isspace ((*addr_exp
)))
2068 /* Discard any leading ``$''. Check that there is something
2069 resembling a register following it. */
2070 if (addr_exp
[0] == '$')
2072 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2073 error (_("Missing register name"));
2075 /* Find the start/end of this register name/num/group. */
2077 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2081 /* Figure out what we've found and display it. */
2083 /* A register name? */
2085 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2089 /* User registers lie completely outside of the range of
2090 normal registers. Catch them early so that the target
2092 if (regnum
>= gdbarch_num_regs (gdbarch
)
2093 + gdbarch_num_pseudo_regs (gdbarch
))
2095 struct value_print_options opts
;
2096 struct value
*val
= value_of_user_reg (regnum
, frame
);
2098 printf_filtered ("%s: ", start
);
2099 get_formatted_print_options (&opts
, 'x');
2100 print_scalar_formatted (value_contents (val
),
2101 check_typedef (value_type (val
)),
2102 &opts
, 0, gdb_stdout
);
2103 printf_filtered ("\n");
2106 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2107 frame
, regnum
, fpregs
);
2112 /* A register group? */
2114 struct reggroup
*group
;
2116 for (group
= reggroup_next (gdbarch
, NULL
);
2118 group
= reggroup_next (gdbarch
, group
))
2120 /* Don't bother with a length check. Should the user
2121 enter a short register group name, go with the first
2122 group that matches. */
2123 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2131 regnum
< gdbarch_num_regs (gdbarch
)
2132 + gdbarch_num_pseudo_regs (gdbarch
);
2135 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2136 gdbarch_print_registers_info (gdbarch
,
2144 /* Nothing matched. */
2145 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2150 all_registers_info (char *addr_exp
, int from_tty
)
2152 registers_info (addr_exp
, 1);
2156 nofp_registers_info (char *addr_exp
, int from_tty
)
2158 registers_info (addr_exp
, 0);
2162 print_vector_info (struct ui_file
*file
,
2163 struct frame_info
*frame
, const char *args
)
2165 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2167 if (gdbarch_print_vector_info_p (gdbarch
))
2168 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2172 int printed_something
= 0;
2175 regnum
< gdbarch_num_regs (gdbarch
)
2176 + gdbarch_num_pseudo_regs (gdbarch
);
2179 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2181 printed_something
= 1;
2182 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2185 if (!printed_something
)
2186 fprintf_filtered (file
, "No vector information\n");
2191 vector_info (char *args
, int from_tty
)
2193 if (!target_has_registers
)
2194 error (_("The program has no registers now."));
2196 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2199 /* Kill the inferior process. Make us have no inferior. */
2202 kill_command (char *arg
, int from_tty
)
2204 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2205 It should be a distinct flag that indicates that a target is active, cuz
2206 some targets don't have processes! */
2208 if (ptid_equal (inferior_ptid
, null_ptid
))
2209 error (_("The program is not being run."));
2210 if (!query (_("Kill the program being debugged? ")))
2211 error (_("Not confirmed."));
2214 /* If we still have other inferiors to debug, then don't mess with
2215 with their threads. */
2216 if (!have_inferiors ())
2218 init_thread_list (); /* Destroy thread info. */
2220 /* Killing off the inferior can leave us with a core file. If
2221 so, print the state we are left in. */
2222 if (target_has_stack
)
2224 printf_filtered (_("In %s,\n"), target_longname
);
2225 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2228 bfd_cache_close_all ();
2231 /* Used in `attach&' command. ARG is a point to an integer
2232 representing a process id. Proceed threads of this process iff
2233 they stopped due to debugger request, and when they did, they
2234 reported a clean stop (TARGET_SIGNAL_0). Do not proceed threads
2235 that have been explicitly been told to stop. */
2238 proceed_after_attach_callback (struct thread_info
*thread
,
2241 int pid
= * (int *) arg
;
2243 if (ptid_get_pid (thread
->ptid
) == pid
2244 && !is_exited (thread
->ptid
)
2245 && !is_executing (thread
->ptid
)
2246 && !thread
->stop_requested
2247 && thread
->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2249 switch_to_thread (thread
->ptid
);
2250 clear_proceed_status ();
2251 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2258 proceed_after_attach (int pid
)
2260 /* Don't error out if the current thread is running, because
2261 there may be other stopped threads. */
2262 struct cleanup
*old_chain
;
2264 /* Backup current thread and selected frame. */
2265 old_chain
= make_cleanup_restore_current_thread ();
2267 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2269 /* Restore selected ptid. */
2270 do_cleanups (old_chain
);
2275 * Should save/restore the tty state since it might be that the
2276 * program to be debugged was started on this tty and it wants
2277 * the tty in some state other than what we want. If it's running
2278 * on another terminal or without a terminal, then saving and
2279 * restoring the tty state is a harmless no-op.
2280 * This only needs to be done if we are attaching to a process.
2283 /* attach_command --
2284 takes a program started up outside of gdb and ``attaches'' to it.
2285 This stops it cold in its tracks and allows us to start debugging it.
2286 and wait for the trace-trap that results from attaching. */
2289 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2292 char *full_exec_path
= NULL
;
2293 struct inferior
*inferior
;
2295 inferior
= current_inferior ();
2296 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2298 /* If no exec file is yet known, try to determine it from the
2300 exec_file
= (char *) get_exec_file (0);
2303 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
2306 /* It's possible we don't have a full path, but rather just a
2307 filename. Some targets, such as HP-UX, don't provide the
2310 Attempt to qualify the filename against the source path.
2311 (If that fails, we'll just fall back on the original
2312 filename. Not much more we can do...) */
2314 if (!source_full_path_of (exec_file
, &full_exec_path
))
2315 full_exec_path
= xstrdup (exec_file
);
2317 exec_file_attach (full_exec_path
, from_tty
);
2318 symbol_file_add_main (full_exec_path
, from_tty
);
2323 reopen_exec_file ();
2327 /* Take any necessary post-attaching actions for this platform. */
2328 target_post_attach (PIDGET (inferior_ptid
));
2330 post_create_inferior (¤t_target
, from_tty
);
2332 /* Install inferior's terminal modes. */
2333 target_terminal_inferior ();
2337 /* The user requested an `attach&', so be sure to leave threads
2338 that didn't get a signal running. */
2340 /* Immediatelly resume all suspended threads of this inferior,
2341 and this inferior only. This should have no effect on
2342 already running threads. If a thread has been stopped with a
2343 signal, leave it be. */
2345 proceed_after_attach (inferior
->pid
);
2348 if (inferior_thread ()->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2350 clear_proceed_status ();
2351 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2357 /* The user requested a plain `attach', so be sure to leave
2358 the inferior stopped. */
2360 if (target_can_async_p ())
2361 async_enable_stdin ();
2363 /* At least the current thread is already stopped. */
2365 /* In all-stop, by definition, all threads have to be already
2366 stopped at this point. In non-stop, however, although the
2367 selected thread is stopped, others may still be executing.
2368 Be sure to explicitly stop all threads of the process. This
2369 should have no effect on already stopped threads. */
2371 target_stop (pid_to_ptid (inferior
->pid
));
2373 /* Tell the user/frontend where we're stopped. */
2375 if (deprecated_attach_hook
)
2376 deprecated_attach_hook ();
2380 struct attach_command_continuation_args
2388 attach_command_continuation (void *args
)
2390 struct attach_command_continuation_args
*a
= args
;
2392 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2396 attach_command_continuation_free_args (void *args
)
2398 struct attach_command_continuation_args
*a
= args
;
2405 attach_command (char *args
, int from_tty
)
2408 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2410 dont_repeat (); /* Not for the faint of heart */
2412 if (gdbarch_has_global_solist (target_gdbarch
))
2413 /* Don't complain if all processes share the same symbol
2416 else if (target_has_execution
)
2418 if (query (_("A program is being debugged already. Kill it? ")))
2421 error (_("Not killed."));
2424 /* Clean up any leftovers from other runs. Some other things from
2425 this function should probably be moved into target_pre_inferior. */
2426 target_pre_inferior (from_tty
);
2428 if (non_stop
&& !target_supports_non_stop ())
2429 error (_("Cannot attach to this target in non-stop mode"));
2433 async_exec
= strip_bg_char (&args
);
2435 /* If we get a request for running in the bg but the target
2436 doesn't support it, error out. */
2437 if (async_exec
&& !target_can_async_p ())
2438 error (_("Asynchronous execution not supported on this target."));
2441 /* If we don't get a request of running in the bg, then we need
2442 to simulate synchronous (fg) execution. */
2443 if (!async_exec
&& target_can_async_p ())
2445 /* Simulate synchronous execution. */
2446 async_disable_stdin ();
2447 make_cleanup ((make_cleanup_ftype
*)async_enable_stdin
, NULL
);
2450 target_attach (args
, from_tty
);
2452 /* Set up the "saved terminal modes" of the inferior
2453 based on what modes we are starting it with. */
2454 target_terminal_init ();
2456 /* Set up execution context to know that we should return from
2457 wait_for_inferior as soon as the target reports a stop. */
2458 init_wait_for_inferior ();
2459 clear_proceed_status ();
2463 /* If we find that the current thread isn't stopped, explicitly
2464 do so now, because we're going to install breakpoints and
2468 /* The user requested an `attach&'; stop just one thread. */
2469 target_stop (inferior_ptid
);
2471 /* The user requested an `attach', so stop all threads of this
2473 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2476 /* Some system don't generate traps when attaching to inferior.
2477 E.g. Mach 3 or GNU hurd. */
2478 if (!target_attach_no_wait
)
2480 struct inferior
*inferior
= current_inferior ();
2482 /* Careful here. See comments in inferior.h. Basically some
2483 OSes don't ignore SIGSTOPs on continue requests anymore. We
2484 need a way for handle_inferior_event to reset the stop_signal
2485 variable after an attach, and this is what
2486 STOP_QUIETLY_NO_SIGSTOP is for. */
2487 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2489 if (target_can_async_p ())
2491 /* sync_execution mode. Wait for stop. */
2492 struct attach_command_continuation_args
*a
;
2494 a
= xmalloc (sizeof (*a
));
2495 a
->args
= xstrdup (args
);
2496 a
->from_tty
= from_tty
;
2497 a
->async_exec
= async_exec
;
2498 add_inferior_continuation (attach_command_continuation
, a
,
2499 attach_command_continuation_free_args
);
2500 discard_cleanups (back_to
);
2504 wait_for_inferior (0);
2507 attach_command_post_wait (args
, from_tty
, async_exec
);
2508 discard_cleanups (back_to
);
2511 /* We had just found out that the target was already attached to an
2512 inferior. PTID points at a thread of this new inferior, that is
2513 the most likely to be stopped right now, but not necessarily so.
2514 The new inferior is assumed to be already added to the inferior
2515 list at this point. If LEAVE_RUNNING, then leave the threads of
2516 this inferior running, except those we've explicitly seen reported
2520 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2522 struct cleanup
* old_chain
;
2525 old_chain
= make_cleanup (null_cleanup
, NULL
);
2527 /* If in non-stop, leave threads as running as they were. If
2528 they're stopped for some reason other than us telling it to, the
2529 target reports a signal != TARGET_SIGNAL_0. We don't try to
2530 resume threads with such a stop signal. */
2531 async_exec
= non_stop
;
2533 if (!ptid_equal (inferior_ptid
, null_ptid
))
2534 make_cleanup_restore_current_thread ();
2536 switch_to_thread (ptid
);
2538 /* When we "notice" a new inferior we need to do all the things we
2539 would normally do if we had just attached to it. */
2541 if (is_executing (inferior_ptid
))
2543 struct inferior
*inferior
= current_inferior ();
2545 /* We're going to install breakpoints, and poke at memory,
2546 ensure that the inferior is stopped for a moment while we do
2548 target_stop (inferior_ptid
);
2550 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2552 /* Wait for stop before proceeding. */
2553 if (target_can_async_p ())
2555 struct attach_command_continuation_args
*a
;
2557 a
= xmalloc (sizeof (*a
));
2558 a
->args
= xstrdup ("");
2559 a
->from_tty
= from_tty
;
2560 a
->async_exec
= async_exec
;
2561 add_inferior_continuation (attach_command_continuation
, a
,
2562 attach_command_continuation_free_args
);
2564 do_cleanups (old_chain
);
2568 wait_for_inferior (0);
2571 async_exec
= leave_running
;
2572 attach_command_post_wait ("" /* args */, from_tty
, async_exec
);
2574 do_cleanups (old_chain
);
2579 * takes a program previously attached to and detaches it.
2580 * The program resumes execution and will no longer stop
2581 * on signals, etc. We better not have left any breakpoints
2582 * in the program or it'll die when it hits one. For this
2583 * to work, it may be necessary for the process to have been
2584 * previously attached. It *might* work if the program was
2585 * started via the normal ptrace (PTRACE_TRACEME).
2589 detach_command (char *args
, int from_tty
)
2591 dont_repeat (); /* Not for the faint of heart. */
2593 if (ptid_equal (inferior_ptid
, null_ptid
))
2594 error (_("The program is not being run."));
2596 disconnect_tracing (from_tty
);
2598 target_detach (args
, from_tty
);
2600 /* If the solist is global across inferiors, don't clear it when we
2601 detach from a single inferior. */
2602 if (!gdbarch_has_global_solist (target_gdbarch
))
2603 no_shared_libraries (NULL
, from_tty
);
2605 /* If we still have inferiors to debug, then don't mess with their
2607 if (!have_inferiors ())
2608 init_thread_list ();
2610 if (deprecated_detach_hook
)
2611 deprecated_detach_hook ();
2614 /* Disconnect from the current target without resuming it (leaving it
2615 waiting for a debugger).
2617 We'd better not have left any breakpoints in the program or the
2618 next debugger will get confused. Currently only supported for some
2619 remote targets, since the normal attach mechanisms don't work on
2620 stopped processes on some native platforms (e.g. GNU/Linux). */
2623 disconnect_command (char *args
, int from_tty
)
2625 dont_repeat (); /* Not for the faint of heart. */
2626 target_disconnect (args
, from_tty
);
2627 no_shared_libraries (NULL
, from_tty
);
2628 init_thread_list ();
2629 if (deprecated_detach_hook
)
2630 deprecated_detach_hook ();
2634 interrupt_target_1 (int all_threads
)
2639 ptid
= minus_one_ptid
;
2641 ptid
= inferior_ptid
;
2644 /* Tag the thread as having been explicitly requested to stop, so
2645 other parts of gdb know not to resume this thread automatically,
2646 if it was stopped due to an internal event. Limit this to
2647 non-stop mode, as when debugging a multi-threaded application in
2648 all-stop mode, we will only get one stop event --- it's undefined
2649 which thread will report the event. */
2651 set_stop_requested (ptid
, 1);
2654 /* Stop the execution of the target while running in async mode, in
2655 the backgound. In all-stop, stop the whole process. In non-stop
2656 mode, stop the current thread only by default, or stop all threads
2657 if the `-a' switch is used. */
2659 /* interrupt [-a] */
2661 interrupt_target_command (char *args
, int from_tty
)
2663 if (target_can_async_p ())
2665 int all_threads
= 0;
2667 dont_repeat (); /* Not for the faint of heart. */
2670 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2673 if (!non_stop
&& all_threads
)
2674 error (_("-a is meaningless in all-stop mode."));
2676 interrupt_target_1 (all_threads
);
2681 print_float_info (struct ui_file
*file
,
2682 struct frame_info
*frame
, const char *args
)
2684 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2686 if (gdbarch_print_float_info_p (gdbarch
))
2687 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2691 int printed_something
= 0;
2694 regnum
< gdbarch_num_regs (gdbarch
)
2695 + gdbarch_num_pseudo_regs (gdbarch
);
2698 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2700 printed_something
= 1;
2701 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2704 if (!printed_something
)
2705 fprintf_filtered (file
, "No floating-point info "
2706 "available for this processor.\n");
2711 float_info (char *args
, int from_tty
)
2713 if (!target_has_registers
)
2714 error (_("The program has no registers now."));
2716 print_float_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2720 unset_command (char *args
, int from_tty
)
2722 printf_filtered (_("\"unset\" must be followed by the "
2723 "name of an unset subcommand.\n"));
2724 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2728 _initialize_infcmd (void)
2730 struct cmd_list_element
*c
= NULL
;
2732 /* Add the filename of the terminal connected to inferior I/O. */
2733 add_setshow_filename_cmd ("inferior-tty", class_run
,
2734 &inferior_io_terminal_scratch
, _("\
2735 Set terminal for future runs of program being debugged."), _("\
2736 Show terminal for future runs of program being debugged."), _("\
2737 Usage: set inferior-tty /dev/pts/1"),
2738 set_inferior_tty_command
,
2739 show_inferior_tty_command
,
2740 &setlist
, &showlist
);
2741 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2743 add_setshow_optional_filename_cmd ("args", class_run
,
2744 &inferior_args_scratch
, _("\
2745 Set argument list to give program being debugged when it is started."), _("\
2746 Show argument list to give program being debugged when it is started."), _("\
2747 Follow this command with any number of args, to be passed to the program."),
2750 &setlist
, &showlist
);
2752 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2753 The environment to give the program, or one variable's value.\n\
2754 With an argument VAR, prints the value of environment variable VAR to\n\
2755 give the program being debugged. With no arguments, prints the entire\n\
2756 environment to be given to the program."), &showlist
);
2757 set_cmd_completer (c
, noop_completer
);
2759 add_prefix_cmd ("unset", no_class
, unset_command
,
2760 _("Complement to certain \"set\" commands."),
2761 &unsetlist
, "unset ", 0, &cmdlist
);
2763 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2764 Cancel environment variable VAR for the program.\n\
2765 This does not affect the program until the next \"run\" command."),
2767 set_cmd_completer (c
, noop_completer
);
2769 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2770 Set environment variable value to give the program.\n\
2771 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2772 VALUES of environment variables are uninterpreted strings.\n\
2773 This does not affect the program until the next \"run\" command."),
2775 set_cmd_completer (c
, noop_completer
);
2777 c
= add_com ("path", class_files
, path_command
, _("\
2778 Add directory DIR(s) to beginning of search path for object files.\n\
2779 $cwd in the path means the current working directory.\n\
2780 This path is equivalent to the $PATH shell variable. It is a list of\n\
2781 directories, separated by colons. These directories are searched to find\n\
2782 fully linked executable files and separately compiled object files as \
2784 set_cmd_completer (c
, filename_completer
);
2786 c
= add_cmd ("paths", no_class
, path_info
, _("\
2787 Current search path for finding object files.\n\
2788 $cwd in the path means the current working directory.\n\
2789 This path is equivalent to the $PATH shell variable. It is a list of\n\
2790 directories, separated by colons. These directories are searched to find\n\
2791 fully linked executable files and separately compiled object files as \
2794 set_cmd_completer (c
, noop_completer
);
2796 add_prefix_cmd ("kill", class_run
, kill_command
,
2797 _("Kill execution of program being debugged."),
2798 &killlist
, "kill ", 0, &cmdlist
);
2800 add_com ("attach", class_run
, attach_command
, _("\
2801 Attach to a process or file outside of GDB.\n\
2802 This command attaches to another target, of the same type as your last\n\
2803 \"target\" command (\"info files\" will show your target stack).\n\
2804 The command may take as argument a process id or a device file.\n\
2805 For a process id, you must have permission to send the process a signal,\n\
2806 and it must have the same effective uid as the debugger.\n\
2807 When using \"attach\" with a process id, the debugger finds the\n\
2808 program running in the process, looking first in the current working\n\
2809 directory, or (if not found there) using the source file search path\n\
2810 (see the \"directory\" command). You can also use the \"file\" command\n\
2811 to specify the program, and to load its symbol table."));
2813 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2814 Detach a process or file previously attached.\n\
2815 If a process, it is no longer traced, and it continues its execution. If\n\
2816 you were debugging a file, the file is closed and gdb no longer accesses it."),
2817 &detachlist
, "detach ", 0, &cmdlist
);
2819 add_com ("disconnect", class_run
, disconnect_command
, _("\
2820 Disconnect from a target.\n\
2821 The target will wait for another debugger to connect. Not available for\n\
2824 add_com ("signal", class_run
, signal_command
, _("\
2825 Continue program giving it signal specified by the argument.\n\
2826 An argument of \"0\" means continue program without giving it a signal."));
2828 add_com ("stepi", class_run
, stepi_command
, _("\
2829 Step one instruction exactly.\n\
2830 Argument N means do this N times (or till program stops for another \
2832 add_com_alias ("si", "stepi", class_alias
, 0);
2834 add_com ("nexti", class_run
, nexti_command
, _("\
2835 Step one instruction, but proceed through subroutine calls.\n\
2836 Argument N means do this N times (or till program stops for another \
2838 add_com_alias ("ni", "nexti", class_alias
, 0);
2840 add_com ("finish", class_run
, finish_command
, _("\
2841 Execute until selected stack frame returns.\n\
2842 Upon return, the value returned is printed and put in the value history."));
2843 add_com_alias ("fin", "finish", class_run
, 1);
2845 add_com ("next", class_run
, next_command
, _("\
2846 Step program, proceeding through subroutine calls.\n\
2847 Like the \"step\" command as long as subroutine calls do not happen;\n\
2848 when they do, the call is treated as one instruction.\n\
2849 Argument N means do this N times (or till program stops for another \
2851 add_com_alias ("n", "next", class_run
, 1);
2853 add_com_alias ("S", "next", class_run
, 1);
2855 add_com ("step", class_run
, step_command
, _("\
2856 Step program until it reaches a different source line.\n\
2857 Argument N means do this N times (or till program stops for another \
2859 add_com_alias ("s", "step", class_run
, 1);
2861 c
= add_com ("until", class_run
, until_command
, _("\
2862 Execute until the program reaches a source line greater than the current\n\
2863 or a specified location (same args as break command) within the current \
2865 set_cmd_completer (c
, location_completer
);
2866 add_com_alias ("u", "until", class_run
, 1);
2868 c
= add_com ("advance", class_run
, advance_command
, _("\
2869 Continue the program up to the given location (same form as args for break \
2871 Execution will also stop upon exit from the current stack frame."));
2872 set_cmd_completer (c
, location_completer
);
2874 c
= add_com ("jump", class_run
, jump_command
, _("\
2875 Continue program being debugged at specified line or address.\n\
2876 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2877 for an address to start at."));
2878 set_cmd_completer (c
, location_completer
);
2882 c
= add_com ("go", class_run
, go_command
, _("\
2883 Usage: go <location>\n\
2884 Continue program being debugged, stopping at specified line or \n\
2886 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2887 expression for an address to start at.\n\
2888 This command is a combination of tbreak and jump."));
2889 set_cmd_completer (c
, location_completer
);
2893 add_com_alias ("g", "go", class_run
, 1);
2895 c
= add_com ("continue", class_run
, continue_command
, _("\
2896 Continue program being debugged, after signal or breakpoint.\n\
2897 If proceeding from breakpoint, a number N may be used as an argument,\n\
2898 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2899 the breakpoint won't break until the Nth time it is reached).\n\
2901 If non-stop mode is enabled, continue only the current thread,\n\
2902 otherwise all the threads in the program are continued. To \n\
2903 continue all stopped threads in non-stop mode, use the -a option.\n\
2904 Specifying -a and an ignore count simultaneously is an error."));
2905 add_com_alias ("c", "cont", class_run
, 1);
2906 add_com_alias ("fg", "cont", class_run
, 1);
2908 c
= add_com ("run", class_run
, run_command
, _("\
2909 Start debugged program. You may specify arguments to give it.\n\
2910 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2911 Input and output redirection with \">\", \"<\", or \">>\" are also \
2913 With no arguments, uses arguments last specified (with \"run\" \
2914 or \"set args\").\n\
2915 To cancel previous arguments and run with no arguments,\n\
2916 use \"set args\" without arguments."));
2917 set_cmd_completer (c
, filename_completer
);
2918 add_com_alias ("r", "run", class_run
, 1);
2920 add_com ("R", class_run
, run_no_args_command
,
2921 _("Start debugged program with no arguments."));
2923 c
= add_com ("start", class_run
, start_command
, _("\
2924 Run the debugged program until the beginning of the main procedure.\n\
2925 You may specify arguments to give to your program, just as with the\n\
2926 \"run\" command."));
2927 set_cmd_completer (c
, filename_completer
);
2929 c
= add_com ("interrupt", class_run
, interrupt_target_command
,
2930 _("Interrupt the execution of the debugged program.\n\
2931 If non-stop mode is enabled, interrupt only the current thread,\n\
2932 otherwise all the threads in the program are stopped. To \n\
2933 interrupt all running threads in non-stop mode, use the -a option."));
2935 add_info ("registers", nofp_registers_info
, _("\
2936 List of integer registers and their contents, for selected stack frame.\n\
2937 Register name as argument means describe only that register."));
2938 add_info_alias ("r", "registers", 1);
2941 add_com ("lr", class_info
, nofp_registers_info
, _("\
2942 List of integer registers and their contents, for selected stack frame.\n\
2943 Register name as argument means describe only that register."));
2944 add_info ("all-registers", all_registers_info
, _("\
2945 List of all registers and their contents, for selected stack frame.\n\
2946 Register name as argument means describe only that register."));
2948 add_info ("program", program_info
,
2949 _("Execution status of the program."));
2951 add_info ("float", float_info
,
2952 _("Print the status of the floating point unit\n"));
2954 add_info ("vector", vector_info
,
2955 _("Print the status of the vector unit\n"));