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 #include "continuations.h"
62 /* Functions exported for general use, in inferior.h: */
64 void all_registers_info (char *, int);
66 void registers_info (char *, int);
68 void nexti_command (char *, int);
70 void stepi_command (char *, int);
72 void continue_command (char *, int);
74 void interrupt_target_command (char *args
, int from_tty
);
76 /* Local functions: */
78 static void nofp_registers_info (char *, int);
80 static void print_return_value (struct type
*func_type
,
81 struct type
*value_type
);
83 static void until_next_command (int);
85 static void until_command (char *, int);
87 static void path_info (char *, int);
89 static void path_command (char *, int);
91 static void unset_command (char *, int);
93 static void float_info (char *, int);
95 static void disconnect_command (char *, int);
97 static void unset_environment_command (char *, int);
99 static void set_environment_command (char *, int);
101 static void environment_info (char *, int);
103 static void program_info (char *, int);
105 static void finish_command (char *, int);
107 static void signal_command (char *, int);
109 static void jump_command (char *, int);
111 static void step_1 (int, int, char *);
112 static void step_once (int skip_subroutines
, int single_inst
,
113 int count
, int thread
);
115 static void next_command (char *, int);
117 static void step_command (char *, int);
119 static void run_command (char *, int);
121 static void run_no_args_command (char *args
, int from_tty
);
123 static void go_command (char *line_no
, int from_tty
);
125 static int strip_bg_char (char **);
127 void _initialize_infcmd (void);
129 #define ERROR_NO_INFERIOR \
130 if (!target_has_execution) error (_("The program is not being run."));
132 /* Scratch area where string containing arguments to give to the
133 program will be stored by 'set args'. As soon as anything is
134 stored, notice_args_set will move it into per-inferior storage.
135 Arguments are separated by spaces. Empty string (pointer to '\0')
138 static char *inferior_args_scratch
;
140 /* Scratch area where 'set inferior-tty' will store user-provided value.
141 We'll immediate copy it into per-inferior storage. */
143 static char *inferior_io_terminal_scratch
;
145 /* Pid of our debugged inferior, or 0 if no inferior now.
146 Since various parts of infrun.c test this to see whether there is a program
147 being debugged it should be nonzero (currently 3 is used) for remote
150 ptid_t inferior_ptid
;
152 /* Address at which inferior stopped. */
156 /* Flag indicating that a command has proceeded the inferior past the
157 current breakpoint. */
159 int breakpoint_proceeded
;
161 /* Nonzero if stopped due to completion of a stack dummy routine. */
163 enum stop_stack_kind stop_stack_dummy
;
165 /* Nonzero if stopped due to a random (unexpected) signal in inferior
168 int stopped_by_random_signal
;
171 /* Accessor routines. */
173 /* Set the io terminal for the current inferior. Ownership of
174 TERMINAL_NAME is not transferred. */
177 set_inferior_io_terminal (const char *terminal_name
)
179 xfree (current_inferior ()->terminal
);
180 current_inferior ()->terminal
= terminal_name
? xstrdup (terminal_name
) : 0;
184 get_inferior_io_terminal (void)
186 return current_inferior ()->terminal
;
190 set_inferior_tty_command (char *args
, int from_tty
,
191 struct cmd_list_element
*c
)
193 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
194 Now route it to current inferior. */
195 set_inferior_io_terminal (inferior_io_terminal_scratch
);
199 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
200 struct cmd_list_element
*c
, const char *value
)
202 /* Note that we ignore the passed-in value in favor of computing it
204 const char *inferior_io_terminal
= get_inferior_io_terminal ();
206 if (inferior_io_terminal
== NULL
)
207 inferior_io_terminal
= "";
208 fprintf_filtered (gdb_stdout
,
209 _("Terminal for future runs of program being debugged "
210 "is \"%s\".\n"), inferior_io_terminal
);
214 get_inferior_args (void)
216 if (current_inferior ()->argc
!= 0)
220 n
= construct_inferior_arguments (current_inferior ()->argc
,
221 current_inferior ()->argv
);
222 set_inferior_args (n
);
226 if (current_inferior ()->args
== NULL
)
227 current_inferior ()->args
= xstrdup ("");
229 return current_inferior ()->args
;
232 /* Set the arguments for the current inferior. Ownership of
233 NEWARGS is not transferred. */
236 set_inferior_args (char *newargs
)
238 xfree (current_inferior ()->args
);
239 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
240 current_inferior ()->argc
= 0;
241 current_inferior ()->argv
= 0;
245 set_inferior_args_vector (int argc
, char **argv
)
247 current_inferior ()->argc
= argc
;
248 current_inferior ()->argv
= argv
;
251 /* Notice when `set args' is run. */
253 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
255 /* CLI has assigned the user-provided value to inferior_args_scratch.
256 Now route it to current inferior. */
257 set_inferior_args (inferior_args_scratch
);
260 /* Notice when `show args' is run. */
262 show_args_command (struct ui_file
*file
, int from_tty
,
263 struct cmd_list_element
*c
, const char *value
)
265 /* Note that we ignore the passed-in value in favor of computing it
267 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
271 /* Compute command-line string given argument vector. This does the
272 same shell processing as fork_inferior. */
274 construct_inferior_arguments (int argc
, char **argv
)
278 if (STARTUP_WITH_SHELL
)
280 /* This holds all the characters considered special to the
281 typical Unix shells. We include `^' because the SunOS
282 /bin/sh treats it as a synonym for `|'. */
283 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
288 /* We over-compute the size. It shouldn't matter. */
289 for (i
= 0; i
< argc
; ++i
)
290 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
292 result
= (char *) xmalloc (length
);
295 for (i
= 0; i
< argc
; ++i
)
300 /* Need to handle empty arguments specially. */
301 if (argv
[i
][0] == '\0')
308 for (cp
= argv
[i
]; *cp
; ++cp
)
312 /* A newline cannot be quoted with a backslash (it
313 just disappears), only by putting it inside
321 if (strchr (special
, *cp
) != NULL
)
332 /* In this case we can't handle arguments that contain spaces,
333 tabs, or newlines -- see breakup_args(). */
337 for (i
= 0; i
< argc
; ++i
)
339 char *cp
= strchr (argv
[i
], ' ');
341 cp
= strchr (argv
[i
], '\t');
343 cp
= strchr (argv
[i
], '\n');
345 error (_("can't handle command-line "
346 "argument containing whitespace"));
347 length
+= strlen (argv
[i
]) + 1;
350 result
= (char *) xmalloc (length
);
352 for (i
= 0; i
< argc
; ++i
)
355 strcat (result
, " ");
356 strcat (result
, argv
[i
]);
364 /* This function detects whether or not a '&' character (indicating
365 background execution) has been added as *the last* of the arguments ARGS
366 of a command. If it has, it removes it and returns 1. Otherwise it
367 does nothing and returns 0. */
369 strip_bg_char (char **args
)
373 p
= strchr (*args
, '&');
377 if (p
== (*args
+ strlen (*args
) - 1))
379 if (strlen (*args
) > 1)
383 while (*p
== ' ' || *p
== '\t');
394 /* Common actions to take after creating any sort of inferior, by any
395 means (running, attaching, connecting, et cetera). The target
396 should be stopped. */
399 post_create_inferior (struct target_ops
*target
, int from_tty
)
401 volatile struct gdb_exception ex
;
403 /* Be sure we own the terminal in case write operations are performed. */
404 target_terminal_ours ();
406 /* If the target hasn't taken care of this already, do it now.
407 Targets which need to access registers during to_open,
408 to_create_inferior, or to_attach should do it earlier; but many
410 target_find_description ();
412 /* Now that we know the register layout, retrieve current PC. But
413 if the PC is unavailable (e.g., we're opening a core file with
414 missing registers info), ignore it. */
416 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
418 stop_pc
= regcache_read_pc (get_current_regcache ());
420 if (ex
.reason
< 0 && ex
.error
!= NOT_AVAILABLE_ERROR
)
421 throw_exception (ex
);
425 const unsigned solib_add_generation
426 = current_program_space
->solib_add_generation
;
428 /* Create the hooks to handle shared library load and unload
430 #ifdef SOLIB_CREATE_INFERIOR_HOOK
431 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
433 solib_create_inferior_hook (from_tty
);
436 if (current_program_space
->solib_add_generation
== solib_add_generation
)
438 /* The platform-specific hook should load initial shared libraries,
439 but didn't. FROM_TTY will be incorrectly 0 but such solib
440 targets should be fixed anyway. Call it only after the solib
441 target has been initialized by solib_create_inferior_hook. */
444 warning (_("platform-specific solib_create_inferior_hook did "
445 "not load initial shared libraries."));
447 /* If the solist is global across processes, there's no need to
449 if (!gdbarch_has_global_solist (target_gdbarch
))
452 SOLIB_ADD (NULL
, 0, target
, auto_solib_add
);
454 solib_add (NULL
, 0, target
, auto_solib_add
);
460 /* If the user sets watchpoints before execution having started,
461 then she gets software watchpoints, because GDB can't know which
462 target will end up being pushed, or if it supports hardware
463 watchpoints or not. breakpoint_re_set takes care of promoting
464 watchpoints to hardware watchpoints if possible, however, if this
465 new inferior doesn't load shared libraries or we don't pull in
466 symbols from any other source on this target/arch,
467 breakpoint_re_set is never called. Call it now so that software
468 watchpoints get a chance to be promoted to hardware watchpoints
469 if the now pushed target supports hardware watchpoints. */
470 breakpoint_re_set ();
472 observer_notify_inferior_created (target
, from_tty
);
475 /* Kill the inferior if already running. This function is designed
476 to be called when we are about to start the execution of the program
477 from the beginning. Ask the user to confirm that he wants to restart
478 the program being debugged when FROM_TTY is non-null. */
481 kill_if_already_running (int from_tty
)
483 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
485 /* Bail out before killing the program if we will not be able to
487 target_require_runnable ();
490 && !query (_("The program being debugged has been started already.\n\
491 Start it from the beginning? ")))
492 error (_("Program not restarted."));
497 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
498 a temporary breakpoint at the begining of the main program before
499 running the program. */
502 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
505 struct cleanup
*old_chain
;
507 struct ui_out
*uiout
= current_uiout
;
511 kill_if_already_running (from_tty
);
513 init_wait_for_inferior ();
514 clear_breakpoint_hit_counts ();
516 /* Clean up any leftovers from other runs. Some other things from
517 this function should probably be moved into target_pre_inferior. */
518 target_pre_inferior (from_tty
);
520 /* The comment here used to read, "The exec file is re-read every
521 time we do a generic_mourn_inferior, so we just have to worry
522 about the symbol file." The `generic_mourn_inferior' function
523 gets called whenever the program exits. However, suppose the
524 program exits, and *then* the executable file changes? We need
525 to check again here. Since reopen_exec_file doesn't do anything
526 if the timestamp hasn't changed, I don't see the harm. */
530 /* Insert the temporary breakpoint if a location was specified. */
532 tbreak_command (main_name (), 0);
534 exec_file
= (char *) get_exec_file (0);
536 if (non_stop
&& !target_supports_non_stop ())
537 error (_("The target does not support running in non-stop mode."));
539 /* We keep symbols from add-symbol-file, on the grounds that the
540 user might want to add some symbols before running the program
541 (right?). But sometimes (dynamic loading where the user manually
542 introduces the new symbols with add-symbol-file), the code which
543 the symbols describe does not persist between runs. Currently
544 the user has to manually nuke all symbols between runs if they
545 want them to go away (PR 2207). This is probably reasonable. */
549 if (target_can_async_p ())
550 async_disable_stdin ();
554 int async_exec
= strip_bg_char (&args
);
556 /* If we get a request for running in the bg but the target
557 doesn't support it, error out. */
558 if (async_exec
&& !target_can_async_p ())
559 error (_("Asynchronous execution not supported on this target."));
561 /* If we don't get a request of running in the bg, then we need
562 to simulate synchronous (fg) execution. */
563 if (!async_exec
&& target_can_async_p ())
565 /* Simulate synchronous execution. */
566 async_disable_stdin ();
569 /* If there were other args, beside '&', process them. */
571 set_inferior_args (args
);
576 ui_out_field_string (uiout
, NULL
, "Starting program");
577 ui_out_text (uiout
, ": ");
579 ui_out_field_string (uiout
, "execfile", exec_file
);
580 ui_out_spaces (uiout
, 1);
581 /* We call get_inferior_args() because we might need to compute
583 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
584 ui_out_text (uiout
, "\n");
585 ui_out_flush (uiout
);
588 /* We call get_inferior_args() because we might need to compute
590 target_create_inferior (exec_file
, get_inferior_args (),
591 environ_vector (current_inferior ()->environment
),
594 /* We're starting off a new process. When we get out of here, in
595 non-stop mode, finish the state of all threads of that process,
596 but leave other threads alone, as they may be stopped in internal
597 events --- the frontend shouldn't see them as stopped. In
598 all-stop, always finish the state of all threads, as we may be
599 resuming more than just the new process. */
601 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
603 ptid
= minus_one_ptid
;
604 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
606 /* Pass zero for FROM_TTY, because at this point the "run" command
607 has done its thing; now we are setting up the running program. */
608 post_create_inferior (¤t_target
, 0);
610 /* Start the target running. Do not use -1 continuation as it would skip
611 breakpoint right at the entry point. */
612 proceed (regcache_read_pc (get_current_regcache ()), TARGET_SIGNAL_0
, 0);
614 /* Since there was no error, there's no need to finish the thread
616 discard_cleanups (old_chain
);
620 run_command (char *args
, int from_tty
)
622 run_command_1 (args
, from_tty
, 0);
626 run_no_args_command (char *args
, int from_tty
)
628 set_inferior_args ("");
632 /* Start the execution of the program up until the beginning of the main
636 start_command (char *args
, int from_tty
)
638 /* Some languages such as Ada need to search inside the program
639 minimal symbols for the location where to put the temporary
640 breakpoint before starting. */
641 if (!have_minimal_symbols ())
642 error (_("No symbol table loaded. Use the \"file\" command."));
644 /* Run the program until reaching the main procedure... */
645 run_command_1 (args
, from_tty
, 1);
649 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
651 /* We go through all threads individually instead of compressing
652 into a single target `resume_all' request, because some threads
653 may be stopped in internal breakpoints/events, or stopped waiting
654 for its turn in the displaced stepping queue (that is, they are
655 running && !executing). The target side has no idea about why
656 the thread is stopped, so a `resume_all' command would resume too
657 much. If/when GDB gains a way to tell the target `hold this
658 thread stopped until I say otherwise', then we can optimize
660 if (!is_stopped (thread
->ptid
))
663 switch_to_thread (thread
->ptid
);
664 clear_proceed_status ();
665 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
670 ensure_valid_thread (void)
672 if (ptid_equal (inferior_ptid
, null_ptid
)
673 || is_exited (inferior_ptid
))
674 error (_("Cannot execute this command without a live selected thread."));
677 /* If the user is looking at trace frames, any resumption of execution
678 is likely to mix up recorded and live target data. So simply
679 disallow those commands. */
682 ensure_not_tfind_mode (void)
684 if (get_traceframe_number () >= 0)
685 error (_("Cannot execute this command while looking at trace frames."));
689 continue_1 (int all_threads
)
692 ensure_not_tfind_mode ();
694 if (non_stop
&& all_threads
)
696 /* Don't error out if the current thread is running, because
697 there may be other stopped threads. */
698 struct cleanup
*old_chain
;
700 /* Backup current thread and selected frame. */
701 old_chain
= make_cleanup_restore_current_thread ();
703 iterate_over_threads (proceed_thread_callback
, NULL
);
705 /* Restore selected ptid. */
706 do_cleanups (old_chain
);
710 ensure_valid_thread ();
711 ensure_not_running ();
712 clear_proceed_status ();
713 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
717 /* continue [-a] [proceed-count] [&] */
719 continue_command (char *args
, int from_tty
)
725 /* Find out whether we must run in the background. */
727 async_exec
= strip_bg_char (&args
);
729 /* If we must run in the background, but the target can't do it,
731 if (async_exec
&& !target_can_async_p ())
732 error (_("Asynchronous execution not supported on this target."));
734 /* If we are not asked to run in the bg, then prepare to run in the
735 foreground, synchronously. */
736 if (!async_exec
&& target_can_async_p ())
738 /* Simulate synchronous execution. */
739 async_disable_stdin ();
744 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
747 args
+= sizeof ("-a") - 1;
753 if (!non_stop
&& all_threads
)
754 error (_("`-a' is meaningless in all-stop mode."));
756 if (args
!= NULL
&& all_threads
)
757 error (_("Can't resume all threads and specify "
758 "proceed count simultaneously."));
760 /* If we have an argument left, set proceed count of breakpoint we
767 struct thread_info
*tp
;
770 tp
= find_thread_ptid (inferior_ptid
);
774 struct target_waitstatus ws
;
776 get_last_target_status (&last_ptid
, &ws
);
777 tp
= find_thread_ptid (last_ptid
);
780 bs
= tp
->control
.stop_bpstat
;
782 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
785 set_ignore_count (num
,
786 parse_and_eval_long (args
) - 1,
788 /* set_ignore_count prints a message ending with a period.
789 So print two spaces before "Continuing.". */
791 printf_filtered (" ");
795 if (!stopped
&& from_tty
)
798 ("Not stopped at any breakpoint; argument ignored.\n");
803 printf_filtered (_("Continuing.\n"));
805 continue_1 (all_threads
);
808 /* Record the starting point of a "step" or "next" command. */
811 set_step_frame (void)
813 struct symtab_and_line sal
;
815 find_frame_sal (get_current_frame (), &sal
);
816 set_step_info (get_current_frame (), sal
);
819 /* Step until outside of current statement. */
822 step_command (char *count_string
, int from_tty
)
824 step_1 (0, 0, count_string
);
827 /* Likewise, but skip over subroutine calls as if single instructions. */
830 next_command (char *count_string
, int from_tty
)
832 step_1 (1, 0, count_string
);
835 /* Likewise, but step only one instruction. */
838 stepi_command (char *count_string
, int from_tty
)
840 step_1 (0, 1, count_string
);
844 nexti_command (char *count_string
, int from_tty
)
846 step_1 (1, 1, count_string
);
850 delete_longjmp_breakpoint_cleanup (void *arg
)
852 int thread
= * (int *) arg
;
853 delete_longjmp_breakpoint (thread
);
857 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
860 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
865 ensure_not_tfind_mode ();
866 ensure_valid_thread ();
867 ensure_not_running ();
870 async_exec
= strip_bg_char (&count_string
);
872 /* If we get a request for running in the bg but the target
873 doesn't support it, error out. */
874 if (async_exec
&& !target_can_async_p ())
875 error (_("Asynchronous execution not supported on this target."));
877 /* If we don't get a request of running in the bg, then we need
878 to simulate synchronous (fg) execution. */
879 if (!async_exec
&& target_can_async_p ())
881 /* Simulate synchronous execution. */
882 async_disable_stdin ();
885 count
= count_string
? parse_and_eval_long (count_string
) : 1;
887 if (!single_inst
|| skip_subroutines
) /* Leave si command alone. */
889 struct thread_info
*tp
= inferior_thread ();
891 if (in_thread_list (inferior_ptid
))
892 thread
= pid_to_thread_id (inferior_ptid
);
894 set_longjmp_breakpoint (tp
, get_frame_id (get_current_frame ()));
896 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
899 /* In synchronous case, all is well; each step_once call will step once. */
900 if (!target_can_async_p ())
902 for (; count
> 0; count
--)
904 step_once (skip_subroutines
, single_inst
, count
, thread
);
906 if (!target_has_execution
)
910 struct thread_info
*tp
= inferior_thread ();
912 if (!tp
->control
.stop_step
|| !tp
->step_multi
)
914 /* If we stopped for some reason that is not stepping
915 there are no further steps to make. */
922 do_cleanups (cleanups
);
926 /* In the case of an asynchronous target things get complicated;
927 do only one step for now, before returning control to the
928 event loop. Let the continuation figure out how many other
929 steps we need to do, and handle them one at the time, through
931 step_once (skip_subroutines
, single_inst
, count
, thread
);
933 /* We are running, and the continuation is installed. It will
934 disable the longjmp breakpoint as appropriate. */
935 discard_cleanups (cleanups
);
939 struct step_1_continuation_args
942 int skip_subroutines
;
947 /* Called after we are done with one step operation, to check whether
948 we need to step again, before we print the prompt and return control
949 to the user. If count is > 1, we will need to do one more call to
950 proceed(), via step_once(). Basically it is like step_once and
951 step_1_continuation are co-recursive. */
953 step_1_continuation (void *args
, int err
)
955 struct step_1_continuation_args
*a
= args
;
957 if (target_has_execution
)
959 struct thread_info
*tp
;
961 tp
= inferior_thread ();
963 && tp
->step_multi
&& tp
->control
.stop_step
)
965 /* There are more steps to make, and we did stop due to
966 ending a stepping range. Do another step. */
967 step_once (a
->skip_subroutines
, a
->single_inst
,
968 a
->count
- 1, a
->thread
);
974 /* We either hit an error, or stopped for some reason that is
975 not stepping, or there are no further steps to make.
977 if (!a
->single_inst
|| a
->skip_subroutines
)
978 delete_longjmp_breakpoint (a
->thread
);
981 /* Do just one step operation. This is useful to implement the 'step
982 n' kind of commands. In case of asynchronous targets, we will have
983 to set up a continuation to be done after the target stops (after
984 this one step). For synch targets, the caller handles further
988 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
990 struct frame_info
*frame
= get_current_frame ();
994 /* Don't assume THREAD is a valid thread id. It is set to -1 if
995 the longjmp breakpoint was not required. Use the
996 INFERIOR_PTID thread instead, which is the same thread when
998 struct thread_info
*tp
= inferior_thread ();
1000 clear_proceed_status ();
1007 /* Step at an inlined function behaves like "down". */
1008 if (!skip_subroutines
&& !single_inst
1009 && inline_skipped_frames (inferior_ptid
))
1013 /* Pretend that we've ran. */
1014 resume_ptid
= user_visible_resume_ptid (1);
1015 set_running (resume_ptid
, 1);
1017 step_into_inline_frame (inferior_ptid
);
1019 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
1022 /* Pretend that we've stopped. */
1025 if (target_can_async_p ())
1026 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1031 pc
= get_frame_pc (frame
);
1032 find_pc_line_pc_range (pc
,
1033 &tp
->control
.step_range_start
,
1034 &tp
->control
.step_range_end
);
1036 /* If we have no line info, switch to stepi mode. */
1037 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1038 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1039 else if (tp
->control
.step_range_end
== 0)
1043 if (find_pc_partial_function (pc
, &name
,
1044 &tp
->control
.step_range_start
,
1045 &tp
->control
.step_range_end
) == 0)
1046 error (_("Cannot find bounds of current function"));
1048 target_terminal_ours ();
1049 printf_filtered (_("Single stepping until exit from function %s,"
1050 "\nwhich has no line number information.\n"),
1056 /* Say we are stepping, but stop after one insn whatever it does. */
1057 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1058 if (!skip_subroutines
)
1060 Don't step over function calls, not even to functions lacking
1062 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1065 if (skip_subroutines
)
1066 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1068 tp
->step_multi
= (count
> 1);
1069 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1071 /* For async targets, register a continuation to do any
1072 additional steps. For sync targets, the caller will handle
1073 further stepping. */
1074 if (target_can_async_p ())
1076 struct step_1_continuation_args
*args
;
1078 args
= xmalloc (sizeof (*args
));
1079 args
->skip_subroutines
= skip_subroutines
;
1080 args
->single_inst
= single_inst
;
1081 args
->count
= count
;
1082 args
->thread
= thread
;
1084 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
1090 /* Continue program at specified address. */
1093 jump_command (char *arg
, int from_tty
)
1095 struct gdbarch
*gdbarch
= get_current_arch ();
1097 struct symtabs_and_lines sals
;
1098 struct symtab_and_line sal
;
1104 ensure_not_tfind_mode ();
1105 ensure_valid_thread ();
1106 ensure_not_running ();
1108 /* Find out whether we must run in the background. */
1110 async_exec
= strip_bg_char (&arg
);
1112 /* If we must run in the background, but the target can't do it,
1114 if (async_exec
&& !target_can_async_p ())
1115 error (_("Asynchronous execution not supported on this target."));
1118 error_no_arg (_("starting address"));
1120 sals
= decode_line_spec_1 (arg
, DECODE_LINE_FUNFIRSTLINE
);
1121 if (sals
.nelts
!= 1)
1123 error (_("Unreasonable jump request"));
1129 if (sal
.symtab
== 0 && sal
.pc
== 0)
1130 error (_("No source file has been specified."));
1132 resolve_sal_pc (&sal
); /* May error out. */
1134 /* See if we are trying to jump to another function. */
1135 fn
= get_frame_function (get_current_frame ());
1136 sfn
= find_pc_function (sal
.pc
);
1137 if (fn
!= NULL
&& sfn
!= fn
)
1139 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1140 SYMBOL_PRINT_NAME (fn
)))
1142 error (_("Not confirmed."));
1149 fixup_symbol_section (sfn
, 0);
1150 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn
)) &&
1151 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn
)))
1153 if (!query (_("WARNING!!! Destination is in "
1154 "unmapped overlay! Jump anyway? ")))
1156 error (_("Not confirmed."));
1166 printf_filtered (_("Continuing at "));
1167 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1168 printf_filtered (".\n");
1171 /* If we are not asked to run in the bg, then prepare to run in the
1172 foreground, synchronously. */
1173 if (!async_exec
&& target_can_async_p ())
1175 /* Simulate synchronous execution. */
1176 async_disable_stdin ();
1179 clear_proceed_status ();
1180 proceed (addr
, TARGET_SIGNAL_0
, 0);
1184 /* Go to line or address in current procedure. */
1186 go_command (char *line_no
, int from_tty
)
1188 if (line_no
== (char *) NULL
|| !*line_no
)
1189 printf_filtered (_("Usage: go <location>\n"));
1192 tbreak_command (line_no
, from_tty
);
1193 jump_command (line_no
, from_tty
);
1198 /* Continue program giving it specified signal. */
1201 signal_command (char *signum_exp
, int from_tty
)
1203 enum target_signal oursig
;
1206 dont_repeat (); /* Too dangerous. */
1208 ensure_not_tfind_mode ();
1209 ensure_valid_thread ();
1210 ensure_not_running ();
1212 /* Find out whether we must run in the background. */
1213 if (signum_exp
!= NULL
)
1214 async_exec
= strip_bg_char (&signum_exp
);
1216 /* If we must run in the background, but the target can't do it,
1218 if (async_exec
&& !target_can_async_p ())
1219 error (_("Asynchronous execution not supported on this target."));
1221 /* If we are not asked to run in the bg, then prepare to run in the
1222 foreground, synchronously. */
1223 if (!async_exec
&& target_can_async_p ())
1225 /* Simulate synchronous execution. */
1226 async_disable_stdin ();
1230 error_no_arg (_("signal number"));
1232 /* It would be even slicker to make signal names be valid expressions,
1233 (the type could be "enum $signal" or some such), then the user could
1234 assign them to convenience variables. */
1235 oursig
= target_signal_from_name (signum_exp
);
1237 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1239 /* No, try numeric. */
1240 int num
= parse_and_eval_long (signum_exp
);
1243 oursig
= TARGET_SIGNAL_0
;
1245 oursig
= target_signal_from_command (num
);
1250 if (oursig
== TARGET_SIGNAL_0
)
1251 printf_filtered (_("Continuing with no signal.\n"));
1253 printf_filtered (_("Continuing with signal %s.\n"),
1254 target_signal_to_name (oursig
));
1257 clear_proceed_status ();
1258 proceed ((CORE_ADDR
) -1, oursig
, 0);
1261 /* Continuation args to be passed to the "until" command
1263 struct until_next_continuation_args
1265 /* The thread that was current when the command was executed. */
1269 /* A continuation callback for until_next_command. */
1272 until_next_continuation (void *arg
, int err
)
1274 struct until_next_continuation_args
*a
= arg
;
1276 delete_longjmp_breakpoint (a
->thread
);
1279 /* Proceed until we reach a different source line with pc greater than
1280 our current one or exit the function. We skip calls in both cases.
1282 Note that eventually this command should probably be changed so
1283 that only source lines are printed out when we hit the breakpoint
1284 we set. This may involve changes to wait_for_inferior and the
1285 proceed status code. */
1288 until_next_command (int from_tty
)
1290 struct frame_info
*frame
;
1292 struct symbol
*func
;
1293 struct symtab_and_line sal
;
1294 struct thread_info
*tp
= inferior_thread ();
1295 int thread
= tp
->num
;
1296 struct cleanup
*old_chain
;
1298 clear_proceed_status ();
1301 frame
= get_current_frame ();
1303 /* Step until either exited from this function or greater
1304 than the current line (if in symbolic section) or pc (if
1307 pc
= get_frame_pc (frame
);
1308 func
= find_pc_function (pc
);
1312 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1314 if (msymbol
== NULL
)
1315 error (_("Execution is not within a known function."));
1317 tp
->control
.step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1318 tp
->control
.step_range_end
= pc
;
1322 sal
= find_pc_line (pc
, 0);
1324 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1325 tp
->control
.step_range_end
= sal
.end
;
1328 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1330 tp
->step_multi
= 0; /* Only one call to proceed */
1332 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1333 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1335 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1337 if (target_can_async_p () && is_running (inferior_ptid
))
1339 struct until_next_continuation_args
*cont_args
;
1341 discard_cleanups (old_chain
);
1342 cont_args
= XNEW (struct until_next_continuation_args
);
1343 cont_args
->thread
= inferior_thread ()->num
;
1345 add_continuation (tp
, until_next_continuation
, cont_args
, xfree
);
1348 do_cleanups (old_chain
);
1352 until_command (char *arg
, int from_tty
)
1357 ensure_not_tfind_mode ();
1358 ensure_valid_thread ();
1359 ensure_not_running ();
1361 /* Find out whether we must run in the background. */
1363 async_exec
= strip_bg_char (&arg
);
1365 /* If we must run in the background, but the target can't do it,
1367 if (async_exec
&& !target_can_async_p ())
1368 error (_("Asynchronous execution not supported on this target."));
1370 /* If we are not asked to run in the bg, then prepare to run in the
1371 foreground, synchronously. */
1372 if (!async_exec
&& target_can_async_p ())
1374 /* Simulate synchronous execution. */
1375 async_disable_stdin ();
1379 until_break_command (arg
, from_tty
, 0);
1381 until_next_command (from_tty
);
1385 advance_command (char *arg
, int from_tty
)
1390 ensure_not_tfind_mode ();
1391 ensure_valid_thread ();
1392 ensure_not_running ();
1395 error_no_arg (_("a location"));
1397 /* Find out whether we must run in the background. */
1399 async_exec
= strip_bg_char (&arg
);
1401 /* If we must run in the background, but the target can't do it,
1403 if (async_exec
&& !target_can_async_p ())
1404 error (_("Asynchronous execution not supported on this target."));
1406 /* If we are not asked to run in the bg, then prepare to run in the
1407 foreground, synchronously. */
1408 if (!async_exec
&& target_can_async_p ())
1410 /* Simulate synchronous execution. */
1411 async_disable_stdin ();
1414 until_break_command (arg
, from_tty
, 1);
1417 /* Return the value of the result of a function at the end of a 'finish'
1421 get_return_value (struct type
*func_type
, struct type
*value_type
)
1423 struct regcache
*stop_regs
= stop_registers
;
1424 struct gdbarch
*gdbarch
;
1425 struct value
*value
;
1426 struct ui_out
*uiout
= current_uiout
;
1427 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
1429 /* If stop_registers were not saved, use the current registers. */
1432 stop_regs
= regcache_dup (get_current_regcache ());
1433 cleanup
= make_cleanup_regcache_xfree (stop_regs
);
1436 gdbarch
= get_regcache_arch (stop_regs
);
1438 CHECK_TYPEDEF (value_type
);
1439 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1441 /* FIXME: 2003-09-27: When returning from a nested inferior function
1442 call, it's possible (with no help from the architecture vector)
1443 to locate and return/print a "struct return" value. This is just
1444 a more complicated case of what is already being done in the
1445 inferior function call code. In fact, when inferior function
1446 calls are made async, this will likely be made the norm. */
1448 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1451 case RETURN_VALUE_REGISTER_CONVENTION
:
1452 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1453 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1454 value
= allocate_value (value_type
);
1455 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_regs
,
1456 value_contents_raw (value
), NULL
);
1458 case RETURN_VALUE_STRUCT_CONVENTION
:
1462 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1465 do_cleanups (cleanup
);
1470 /* Print the result of a function at the end of a 'finish' command. */
1473 print_return_value (struct type
*func_type
, struct type
*value_type
)
1475 struct value
*value
= get_return_value (func_type
, value_type
);
1476 struct cleanup
*old_chain
;
1477 struct ui_stream
*stb
;
1478 struct ui_out
*uiout
= current_uiout
;
1482 struct value_print_options opts
;
1485 stb
= ui_out_stream_new (uiout
);
1486 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1487 ui_out_text (uiout
, "Value returned is ");
1488 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1489 record_latest_value (value
));
1490 ui_out_text (uiout
, " = ");
1491 get_raw_print_options (&opts
);
1492 value_print (value
, stb
->stream
, &opts
);
1493 ui_out_field_stream (uiout
, "return-value", stb
);
1494 ui_out_text (uiout
, "\n");
1495 do_cleanups (old_chain
);
1499 ui_out_text (uiout
, "Value returned has type: ");
1500 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1501 ui_out_text (uiout
, ".");
1502 ui_out_text (uiout
, " Cannot determine contents\n");
1506 /* Stuff that needs to be done by the finish command after the target
1507 has stopped. In asynchronous mode, we wait for the target to stop
1508 in the call to poll or select in the event loop, so it is
1509 impossible to do all the stuff as part of the finish_command
1510 function itself. The only chance we have to complete this command
1511 is in fetch_inferior_event, which is called by the event loop as
1512 soon as it detects that the target has stopped. */
1514 struct finish_command_continuation_args
1516 /* The thread that as current when the command was executed. */
1518 struct breakpoint
*breakpoint
;
1519 struct symbol
*function
;
1523 finish_command_continuation (void *arg
, int err
)
1525 struct finish_command_continuation_args
*a
= arg
;
1529 struct thread_info
*tp
= NULL
;
1532 if (!ptid_equal (inferior_ptid
, null_ptid
)
1533 && target_has_execution
1534 && is_stopped (inferior_ptid
))
1536 tp
= inferior_thread ();
1537 bs
= tp
->control
.stop_bpstat
;
1540 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1541 && a
->function
!= NULL
)
1543 struct type
*value_type
;
1545 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1547 internal_error (__FILE__
, __LINE__
,
1548 _("finish_command: function has no target type"));
1550 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1552 volatile struct gdb_exception ex
;
1554 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1556 /* print_return_value can throw an exception in some
1557 circumstances. We need to catch this so that we still
1558 delete the breakpoint. */
1559 print_return_value (SYMBOL_TYPE (a
->function
), value_type
);
1562 exception_print (gdb_stdout
, ex
);
1566 /* We suppress normal call of normal_stop observer and do it
1567 here so that the *stopped notification includes the return
1569 if (bs
!= NULL
&& tp
->control
.proceed_to_finish
)
1570 observer_notify_normal_stop (bs
, 1 /* print frame */);
1573 delete_breakpoint (a
->breakpoint
);
1574 delete_longjmp_breakpoint (a
->thread
);
1578 finish_command_continuation_free_arg (void *arg
)
1583 /* finish_backward -- helper function for finish_command. */
1586 finish_backward (struct symbol
*function
)
1588 struct symtab_and_line sal
;
1589 struct thread_info
*tp
= inferior_thread ();
1591 CORE_ADDR func_addr
;
1593 pc
= get_frame_pc (get_current_frame ());
1595 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1596 internal_error (__FILE__
, __LINE__
,
1597 _("Finish: couldn't find function."));
1599 sal
= find_pc_line (func_addr
, 0);
1601 tp
->control
.proceed_to_finish
= 1;
1602 /* Special case: if we're sitting at the function entry point,
1603 then all we need to do is take a reverse singlestep. We
1604 don't need to set a breakpoint, and indeed it would do us
1607 Note that this can only happen at frame #0, since there's
1608 no way that a function up the stack can have a return address
1609 that's equal to its entry point. */
1613 struct frame_info
*frame
= get_selected_frame (NULL
);
1614 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1615 struct symtab_and_line sr_sal
;
1617 /* Set a step-resume at the function's entry point. Once that's
1618 hit, we'll do one more step backwards. */
1621 sr_sal
.pspace
= get_frame_program_space (frame
);
1622 insert_step_resume_breakpoint_at_sal (gdbarch
,
1623 sr_sal
, null_frame_id
);
1625 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1629 /* We're almost there -- we just need to back up by one more
1631 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1632 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1636 /* finish_forward -- helper function for finish_command. */
1639 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1641 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1642 struct symtab_and_line sal
;
1643 struct thread_info
*tp
= inferior_thread ();
1644 struct breakpoint
*breakpoint
;
1645 struct cleanup
*old_chain
;
1646 struct finish_command_continuation_args
*cargs
;
1647 int thread
= tp
->num
;
1649 sal
= find_pc_line (get_frame_pc (frame
), 0);
1650 sal
.pc
= get_frame_pc (frame
);
1652 breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1653 get_stack_frame_id (frame
),
1656 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1658 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1659 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1661 /* We want stop_registers, please... */
1662 tp
->control
.proceed_to_finish
= 1;
1663 cargs
= xmalloc (sizeof (*cargs
));
1665 cargs
->thread
= thread
;
1666 cargs
->breakpoint
= breakpoint
;
1667 cargs
->function
= function
;
1668 add_continuation (tp
, finish_command_continuation
, cargs
,
1669 finish_command_continuation_free_arg
);
1670 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1672 discard_cleanups (old_chain
);
1673 if (!target_can_async_p ())
1674 do_all_continuations (0);
1677 /* "finish": Set a temporary breakpoint at the place the selected
1678 frame will return to, then continue. */
1681 finish_command (char *arg
, int from_tty
)
1683 struct frame_info
*frame
;
1684 struct symbol
*function
;
1689 ensure_not_tfind_mode ();
1690 ensure_valid_thread ();
1691 ensure_not_running ();
1693 /* Find out whether we must run in the background. */
1695 async_exec
= strip_bg_char (&arg
);
1697 /* If we must run in the background, but the target can't do it,
1699 if (async_exec
&& !target_can_async_p ())
1700 error (_("Asynchronous execution not supported on this target."));
1702 /* If we are not asked to run in the bg, then prepare to run in the
1703 foreground, synchronously. */
1704 if (!async_exec
&& target_can_async_p ())
1706 /* Simulate synchronous execution. */
1707 async_disable_stdin ();
1711 error (_("The \"finish\" command does not take any arguments."));
1713 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1715 error (_("\"finish\" not meaningful in the outermost frame."));
1717 clear_proceed_status ();
1719 /* Finishing from an inline frame is completely different. We don't
1720 try to show the "return value" - no way to locate it. So we do
1721 not need a completion. */
1722 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1725 /* Claim we are stepping in the calling frame. An empty step
1726 range means that we will stop once we aren't in a function
1727 called by that frame. We don't use the magic "1" value for
1728 step_range_end, because then infrun will think this is nexti,
1729 and not step over the rest of this inlined function call. */
1730 struct thread_info
*tp
= inferior_thread ();
1731 struct symtab_and_line empty_sal
;
1733 init_sal (&empty_sal
);
1734 set_step_info (frame
, empty_sal
);
1735 tp
->control
.step_range_start
= get_frame_pc (frame
);
1736 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1737 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1739 /* Print info on the selected frame, including level number but not
1743 printf_filtered (_("Run till exit from "));
1744 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1747 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1751 /* Find the function we will return from. */
1753 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1755 /* Print info on the selected frame, including level number but not
1759 if (execution_direction
== EXEC_REVERSE
)
1760 printf_filtered (_("Run back to call of "));
1762 printf_filtered (_("Run till exit from "));
1764 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1767 if (execution_direction
== EXEC_REVERSE
)
1768 finish_backward (function
);
1770 finish_forward (function
, frame
);
1775 program_info (char *args
, int from_tty
)
1779 struct thread_info
*tp
;
1782 if (!target_has_execution
)
1784 printf_filtered (_("The program being debugged is not being run.\n"));
1789 ptid
= inferior_ptid
;
1792 struct target_waitstatus ws
;
1794 get_last_target_status (&ptid
, &ws
);
1797 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1798 error (_("Invalid selected thread."));
1799 else if (is_running (ptid
))
1800 error (_("Selected thread is running."));
1802 tp
= find_thread_ptid (ptid
);
1803 bs
= tp
->control
.stop_bpstat
;
1804 stat
= bpstat_num (&bs
, &num
);
1806 target_files_info ();
1807 printf_filtered (_("Program stopped at %s.\n"),
1808 paddress (target_gdbarch
, stop_pc
));
1809 if (tp
->control
.stop_step
)
1810 printf_filtered (_("It stopped after being stepped.\n"));
1813 /* There may be several breakpoints in the same place, so this
1814 isn't as strange as it seems. */
1819 printf_filtered (_("It stopped at a breakpoint "
1820 "that has since been deleted.\n"));
1823 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1824 stat
= bpstat_num (&bs
, &num
);
1827 else if (tp
->suspend
.stop_signal
!= TARGET_SIGNAL_0
)
1829 printf_filtered (_("It stopped with signal %s, %s.\n"),
1830 target_signal_to_name (tp
->suspend
.stop_signal
),
1831 target_signal_to_string (tp
->suspend
.stop_signal
));
1836 printf_filtered (_("Type \"info stack\" or \"info "
1837 "registers\" for more information.\n"));
1842 environment_info (char *var
, int from_tty
)
1846 char *val
= get_in_environ (current_inferior ()->environment
, var
);
1850 puts_filtered (var
);
1851 puts_filtered (" = ");
1852 puts_filtered (val
);
1853 puts_filtered ("\n");
1857 puts_filtered ("Environment variable \"");
1858 puts_filtered (var
);
1859 puts_filtered ("\" not defined.\n");
1864 char **vector
= environ_vector (current_inferior ()->environment
);
1868 puts_filtered (*vector
++);
1869 puts_filtered ("\n");
1875 set_environment_command (char *arg
, int from_tty
)
1877 char *p
, *val
, *var
;
1881 error_no_arg (_("environment variable and value"));
1883 /* Find seperation between variable name and value. */
1884 p
= (char *) strchr (arg
, '=');
1885 val
= (char *) strchr (arg
, ' ');
1887 if (p
!= 0 && val
!= 0)
1889 /* We have both a space and an equals. If the space is before the
1890 equals, walk forward over the spaces til we see a nonspace
1891 (possibly the equals). */
1896 /* Now if the = is after the char following the spaces,
1897 take the char following the spaces. */
1901 else if (val
!= 0 && p
== 0)
1905 error_no_arg (_("environment variable to set"));
1907 if (p
== 0 || p
[1] == 0)
1911 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
1915 /* Not setting variable value to null. */
1917 while (*val
== ' ' || *val
== '\t')
1921 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1924 var
= savestring (arg
, p
- arg
);
1927 printf_filtered (_("Setting environment variable "
1928 "\"%s\" to null value.\n"),
1930 set_in_environ (current_inferior ()->environment
, var
, "");
1933 set_in_environ (current_inferior ()->environment
, var
, val
);
1938 unset_environment_command (char *var
, int from_tty
)
1942 /* If there is no argument, delete all environment variables.
1943 Ask for confirmation if reading from the terminal. */
1944 if (!from_tty
|| query (_("Delete all environment variables? ")))
1946 free_environ (current_inferior ()->environment
);
1947 current_inferior ()->environment
= make_environ ();
1951 unset_in_environ (current_inferior ()->environment
, var
);
1954 /* Handle the execution path (PATH variable). */
1956 static const char path_var_name
[] = "PATH";
1959 path_info (char *args
, int from_tty
)
1961 puts_filtered ("Executable and object file path: ");
1962 puts_filtered (get_in_environ (current_inferior ()->environment
,
1964 puts_filtered ("\n");
1967 /* Add zero or more directories to the front of the execution path. */
1970 path_command (char *dirname
, int from_tty
)
1976 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
1977 /* Can be null if path is not set. */
1980 exec_path
= xstrdup (env
);
1981 mod_path (dirname
, &exec_path
);
1982 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
1985 path_info ((char *) NULL
, from_tty
);
1989 /* Print out the machine register regnum. If regnum is -1, print all
1990 registers (print_all == 1) or all non-float and non-vector
1991 registers (print_all == 0).
1993 For most machines, having all_registers_info() print the
1994 register(s) one per line is good enough. If a different format is
1995 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1996 regs), or there is an existing convention for showing all the
1997 registers, define the architecture method PRINT_REGISTERS_INFO to
1998 provide that format. */
2001 default_print_registers_info (struct gdbarch
*gdbarch
,
2002 struct ui_file
*file
,
2003 struct frame_info
*frame
,
2004 int regnum
, int print_all
)
2007 const int numregs
= gdbarch_num_regs (gdbarch
)
2008 + gdbarch_num_pseudo_regs (gdbarch
);
2010 for (i
= 0; i
< numregs
; i
++)
2012 struct type
*regtype
;
2015 /* Decide between printing all regs, non-float / vector regs, or
2021 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2026 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2036 /* If the register name is empty, it is undefined for this
2037 processor, so don't display anything. */
2038 if (gdbarch_register_name (gdbarch
, i
) == NULL
2039 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2042 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
2043 print_spaces_filtered (15 - strlen (gdbarch_register_name
2044 (gdbarch
, i
)), file
);
2046 regtype
= register_type (gdbarch
, i
);
2047 val
= allocate_value (regtype
);
2049 /* Get the data in raw format. */
2050 if (! frame_register_read (frame
, i
, value_contents_raw (val
)))
2052 fprintf_filtered (file
, "*value not available*\n");
2056 /* If virtual format is floating, print it that way, and in raw
2058 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
2059 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2062 struct value_print_options opts
;
2063 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2065 get_user_print_options (&opts
);
2069 value_contents_for_printing (val
),
2070 value_embedded_offset (val
), 0,
2071 file
, 0, val
, &opts
, current_language
);
2073 fprintf_filtered (file
, "\t(raw 0x");
2074 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
2078 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
2081 idx
= register_size (gdbarch
, i
) - 1 - j
;
2082 fprintf_filtered (file
, "%02x", (unsigned char) valaddr
[idx
]);
2084 fprintf_filtered (file
, ")");
2088 struct value_print_options opts
;
2090 /* Print the register in hex. */
2091 get_formatted_print_options (&opts
, 'x');
2094 value_contents_for_printing (val
),
2095 value_embedded_offset (val
), 0,
2096 file
, 0, val
, &opts
, current_language
);
2097 /* If not a vector register, print it also according to its
2099 if (TYPE_VECTOR (regtype
) == 0)
2101 get_user_print_options (&opts
);
2103 fprintf_filtered (file
, "\t");
2105 value_contents_for_printing (val
),
2106 value_embedded_offset (val
), 0,
2107 file
, 0, val
, &opts
, current_language
);
2111 fprintf_filtered (file
, "\n");
2116 registers_info (char *addr_exp
, int fpregs
)
2118 struct frame_info
*frame
;
2119 struct gdbarch
*gdbarch
;
2121 if (!target_has_registers
)
2122 error (_("The program has no registers now."));
2123 frame
= get_selected_frame (NULL
);
2124 gdbarch
= get_frame_arch (frame
);
2128 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2133 while (*addr_exp
!= '\0')
2138 /* Keep skipping leading white space. */
2139 if (isspace ((*addr_exp
)))
2145 /* Discard any leading ``$''. Check that there is something
2146 resembling a register following it. */
2147 if (addr_exp
[0] == '$')
2149 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2150 error (_("Missing register name"));
2152 /* Find the start/end of this register name/num/group. */
2154 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2158 /* Figure out what we've found and display it. */
2160 /* A register name? */
2162 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2166 /* User registers lie completely outside of the range of
2167 normal registers. Catch them early so that the target
2169 if (regnum
>= gdbarch_num_regs (gdbarch
)
2170 + gdbarch_num_pseudo_regs (gdbarch
))
2172 struct value_print_options opts
;
2173 struct value
*val
= value_of_user_reg (regnum
, frame
);
2175 printf_filtered ("%s: ", start
);
2176 get_formatted_print_options (&opts
, 'x');
2177 val_print_scalar_formatted (check_typedef (value_type (val
)),
2178 value_contents_for_printing (val
),
2179 value_embedded_offset (val
),
2181 &opts
, 0, gdb_stdout
);
2182 printf_filtered ("\n");
2185 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2186 frame
, regnum
, fpregs
);
2191 /* A register group? */
2193 struct reggroup
*group
;
2195 for (group
= reggroup_next (gdbarch
, NULL
);
2197 group
= reggroup_next (gdbarch
, group
))
2199 /* Don't bother with a length check. Should the user
2200 enter a short register group name, go with the first
2201 group that matches. */
2202 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2210 regnum
< gdbarch_num_regs (gdbarch
)
2211 + gdbarch_num_pseudo_regs (gdbarch
);
2214 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2215 gdbarch_print_registers_info (gdbarch
,
2223 /* Nothing matched. */
2224 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2229 all_registers_info (char *addr_exp
, int from_tty
)
2231 registers_info (addr_exp
, 1);
2235 nofp_registers_info (char *addr_exp
, int from_tty
)
2237 registers_info (addr_exp
, 0);
2241 print_vector_info (struct ui_file
*file
,
2242 struct frame_info
*frame
, const char *args
)
2244 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2246 if (gdbarch_print_vector_info_p (gdbarch
))
2247 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2251 int printed_something
= 0;
2254 regnum
< gdbarch_num_regs (gdbarch
)
2255 + gdbarch_num_pseudo_regs (gdbarch
);
2258 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2260 printed_something
= 1;
2261 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2264 if (!printed_something
)
2265 fprintf_filtered (file
, "No vector information\n");
2270 vector_info (char *args
, int from_tty
)
2272 if (!target_has_registers
)
2273 error (_("The program has no registers now."));
2275 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2278 /* Kill the inferior process. Make us have no inferior. */
2281 kill_command (char *arg
, int from_tty
)
2283 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2284 It should be a distinct flag that indicates that a target is active, cuz
2285 some targets don't have processes! */
2287 if (ptid_equal (inferior_ptid
, null_ptid
))
2288 error (_("The program is not being run."));
2289 if (!query (_("Kill the program being debugged? ")))
2290 error (_("Not confirmed."));
2293 /* If we still have other inferiors to debug, then don't mess with
2294 with their threads. */
2295 if (!have_inferiors ())
2297 init_thread_list (); /* Destroy thread info. */
2299 /* Killing off the inferior can leave us with a core file. If
2300 so, print the state we are left in. */
2301 if (target_has_stack
)
2303 printf_filtered (_("In %s,\n"), target_longname
);
2304 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2307 bfd_cache_close_all ();
2310 /* Used in `attach&' command. ARG is a point to an integer
2311 representing a process id. Proceed threads of this process iff
2312 they stopped due to debugger request, and when they did, they
2313 reported a clean stop (TARGET_SIGNAL_0). Do not proceed threads
2314 that have been explicitly been told to stop. */
2317 proceed_after_attach_callback (struct thread_info
*thread
,
2320 int pid
= * (int *) arg
;
2322 if (ptid_get_pid (thread
->ptid
) == pid
2323 && !is_exited (thread
->ptid
)
2324 && !is_executing (thread
->ptid
)
2325 && !thread
->stop_requested
2326 && thread
->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2328 switch_to_thread (thread
->ptid
);
2329 clear_proceed_status ();
2330 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2337 proceed_after_attach (int pid
)
2339 /* Don't error out if the current thread is running, because
2340 there may be other stopped threads. */
2341 struct cleanup
*old_chain
;
2343 /* Backup current thread and selected frame. */
2344 old_chain
= make_cleanup_restore_current_thread ();
2346 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2348 /* Restore selected ptid. */
2349 do_cleanups (old_chain
);
2354 * Should save/restore the tty state since it might be that the
2355 * program to be debugged was started on this tty and it wants
2356 * the tty in some state other than what we want. If it's running
2357 * on another terminal or without a terminal, then saving and
2358 * restoring the tty state is a harmless no-op.
2359 * This only needs to be done if we are attaching to a process.
2362 /* attach_command --
2363 takes a program started up outside of gdb and ``attaches'' to it.
2364 This stops it cold in its tracks and allows us to start debugging it.
2365 and wait for the trace-trap that results from attaching. */
2368 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2371 char *full_exec_path
= NULL
;
2372 struct inferior
*inferior
;
2374 inferior
= current_inferior ();
2375 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2377 /* If no exec file is yet known, try to determine it from the
2379 exec_file
= (char *) get_exec_file (0);
2382 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
2385 /* It's possible we don't have a full path, but rather just a
2386 filename. Some targets, such as HP-UX, don't provide the
2389 Attempt to qualify the filename against the source path.
2390 (If that fails, we'll just fall back on the original
2391 filename. Not much more we can do...) */
2393 if (!source_full_path_of (exec_file
, &full_exec_path
))
2394 full_exec_path
= xstrdup (exec_file
);
2396 exec_file_attach (full_exec_path
, from_tty
);
2397 symbol_file_add_main (full_exec_path
, from_tty
);
2402 reopen_exec_file ();
2406 /* Take any necessary post-attaching actions for this platform. */
2407 target_post_attach (PIDGET (inferior_ptid
));
2409 post_create_inferior (¤t_target
, from_tty
);
2411 /* Install inferior's terminal modes. */
2412 target_terminal_inferior ();
2416 /* The user requested an `attach&', so be sure to leave threads
2417 that didn't get a signal running. */
2419 /* Immediatelly resume all suspended threads of this inferior,
2420 and this inferior only. This should have no effect on
2421 already running threads. If a thread has been stopped with a
2422 signal, leave it be. */
2424 proceed_after_attach (inferior
->pid
);
2427 if (inferior_thread ()->suspend
.stop_signal
== TARGET_SIGNAL_0
)
2429 clear_proceed_status ();
2430 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2436 /* The user requested a plain `attach', so be sure to leave
2437 the inferior stopped. */
2439 if (target_can_async_p ())
2440 async_enable_stdin ();
2442 /* At least the current thread is already stopped. */
2444 /* In all-stop, by definition, all threads have to be already
2445 stopped at this point. In non-stop, however, although the
2446 selected thread is stopped, others may still be executing.
2447 Be sure to explicitly stop all threads of the process. This
2448 should have no effect on already stopped threads. */
2450 target_stop (pid_to_ptid (inferior
->pid
));
2452 /* Tell the user/frontend where we're stopped. */
2454 if (deprecated_attach_hook
)
2455 deprecated_attach_hook ();
2459 struct attach_command_continuation_args
2467 attach_command_continuation (void *args
, int err
)
2469 struct attach_command_continuation_args
*a
= args
;
2474 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2478 attach_command_continuation_free_args (void *args
)
2480 struct attach_command_continuation_args
*a
= args
;
2487 attach_command (char *args
, int from_tty
)
2490 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2492 dont_repeat (); /* Not for the faint of heart */
2494 if (gdbarch_has_global_solist (target_gdbarch
))
2495 /* Don't complain if all processes share the same symbol
2498 else if (target_has_execution
)
2500 if (query (_("A program is being debugged already. Kill it? ")))
2503 error (_("Not killed."));
2506 /* Clean up any leftovers from other runs. Some other things from
2507 this function should probably be moved into target_pre_inferior. */
2508 target_pre_inferior (from_tty
);
2510 if (non_stop
&& !target_supports_non_stop ())
2511 error (_("Cannot attach to this target in non-stop mode"));
2515 async_exec
= strip_bg_char (&args
);
2517 /* If we get a request for running in the bg but the target
2518 doesn't support it, error out. */
2519 if (async_exec
&& !target_can_async_p ())
2520 error (_("Asynchronous execution not supported on this target."));
2523 /* If we don't get a request of running in the bg, then we need
2524 to simulate synchronous (fg) execution. */
2525 if (!async_exec
&& target_can_async_p ())
2527 /* Simulate synchronous execution. */
2528 async_disable_stdin ();
2529 make_cleanup ((make_cleanup_ftype
*)async_enable_stdin
, NULL
);
2532 target_attach (args
, from_tty
);
2534 /* Set up the "saved terminal modes" of the inferior
2535 based on what modes we are starting it with. */
2536 target_terminal_init ();
2538 /* Set up execution context to know that we should return from
2539 wait_for_inferior as soon as the target reports a stop. */
2540 init_wait_for_inferior ();
2541 clear_proceed_status ();
2545 /* If we find that the current thread isn't stopped, explicitly
2546 do so now, because we're going to install breakpoints and
2550 /* The user requested an `attach&'; stop just one thread. */
2551 target_stop (inferior_ptid
);
2553 /* The user requested an `attach', so stop all threads of this
2555 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2558 /* Some system don't generate traps when attaching to inferior.
2559 E.g. Mach 3 or GNU hurd. */
2560 if (!target_attach_no_wait
)
2562 struct inferior
*inferior
= current_inferior ();
2564 /* Careful here. See comments in inferior.h. Basically some
2565 OSes don't ignore SIGSTOPs on continue requests anymore. We
2566 need a way for handle_inferior_event to reset the stop_signal
2567 variable after an attach, and this is what
2568 STOP_QUIETLY_NO_SIGSTOP is for. */
2569 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2571 if (target_can_async_p ())
2573 /* sync_execution mode. Wait for stop. */
2574 struct attach_command_continuation_args
*a
;
2576 a
= xmalloc (sizeof (*a
));
2577 a
->args
= xstrdup (args
);
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
);
2582 discard_cleanups (back_to
);
2586 wait_for_inferior ();
2589 attach_command_post_wait (args
, from_tty
, async_exec
);
2590 discard_cleanups (back_to
);
2593 /* We had just found out that the target was already attached to an
2594 inferior. PTID points at a thread of this new inferior, that is
2595 the most likely to be stopped right now, but not necessarily so.
2596 The new inferior is assumed to be already added to the inferior
2597 list at this point. If LEAVE_RUNNING, then leave the threads of
2598 this inferior running, except those we've explicitly seen reported
2602 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2604 struct cleanup
* old_chain
;
2607 old_chain
= make_cleanup (null_cleanup
, NULL
);
2609 /* If in non-stop, leave threads as running as they were. If
2610 they're stopped for some reason other than us telling it to, the
2611 target reports a signal != TARGET_SIGNAL_0. We don't try to
2612 resume threads with such a stop signal. */
2613 async_exec
= non_stop
;
2615 if (!ptid_equal (inferior_ptid
, null_ptid
))
2616 make_cleanup_restore_current_thread ();
2618 switch_to_thread (ptid
);
2620 /* When we "notice" a new inferior we need to do all the things we
2621 would normally do if we had just attached to it. */
2623 if (is_executing (inferior_ptid
))
2625 struct inferior
*inferior
= current_inferior ();
2627 /* We're going to install breakpoints, and poke at memory,
2628 ensure that the inferior is stopped for a moment while we do
2630 target_stop (inferior_ptid
);
2632 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2634 /* Wait for stop before proceeding. */
2635 if (target_can_async_p ())
2637 struct attach_command_continuation_args
*a
;
2639 a
= xmalloc (sizeof (*a
));
2640 a
->args
= xstrdup ("");
2641 a
->from_tty
= from_tty
;
2642 a
->async_exec
= async_exec
;
2643 add_inferior_continuation (attach_command_continuation
, a
,
2644 attach_command_continuation_free_args
);
2646 do_cleanups (old_chain
);
2650 wait_for_inferior ();
2653 async_exec
= leave_running
;
2654 attach_command_post_wait ("" /* args */, from_tty
, async_exec
);
2656 do_cleanups (old_chain
);
2661 * takes a program previously attached to and detaches it.
2662 * The program resumes execution and will no longer stop
2663 * on signals, etc. We better not have left any breakpoints
2664 * in the program or it'll die when it hits one. For this
2665 * to work, it may be necessary for the process to have been
2666 * previously attached. It *might* work if the program was
2667 * started via the normal ptrace (PTRACE_TRACEME).
2671 detach_command (char *args
, int from_tty
)
2673 dont_repeat (); /* Not for the faint of heart. */
2675 if (ptid_equal (inferior_ptid
, null_ptid
))
2676 error (_("The program is not being run."));
2678 disconnect_tracing (from_tty
);
2680 target_detach (args
, from_tty
);
2682 /* If the solist is global across inferiors, don't clear it when we
2683 detach from a single inferior. */
2684 if (!gdbarch_has_global_solist (target_gdbarch
))
2685 no_shared_libraries (NULL
, from_tty
);
2687 /* If we still have inferiors to debug, then don't mess with their
2689 if (!have_inferiors ())
2690 init_thread_list ();
2692 if (deprecated_detach_hook
)
2693 deprecated_detach_hook ();
2696 /* Disconnect from the current target without resuming it (leaving it
2697 waiting for a debugger).
2699 We'd better not have left any breakpoints in the program or the
2700 next debugger will get confused. Currently only supported for some
2701 remote targets, since the normal attach mechanisms don't work on
2702 stopped processes on some native platforms (e.g. GNU/Linux). */
2705 disconnect_command (char *args
, int from_tty
)
2707 dont_repeat (); /* Not for the faint of heart. */
2708 disconnect_tracing (from_tty
);
2709 target_disconnect (args
, from_tty
);
2710 no_shared_libraries (NULL
, from_tty
);
2711 init_thread_list ();
2712 if (deprecated_detach_hook
)
2713 deprecated_detach_hook ();
2717 interrupt_target_1 (int all_threads
)
2722 ptid
= minus_one_ptid
;
2724 ptid
= inferior_ptid
;
2727 /* Tag the thread as having been explicitly requested to stop, so
2728 other parts of gdb know not to resume this thread automatically,
2729 if it was stopped due to an internal event. Limit this to
2730 non-stop mode, as when debugging a multi-threaded application in
2731 all-stop mode, we will only get one stop event --- it's undefined
2732 which thread will report the event. */
2734 set_stop_requested (ptid
, 1);
2737 /* Stop the execution of the target while running in async mode, in
2738 the backgound. In all-stop, stop the whole process. In non-stop
2739 mode, stop the current thread only by default, or stop all threads
2740 if the `-a' switch is used. */
2742 /* interrupt [-a] */
2744 interrupt_target_command (char *args
, int from_tty
)
2746 if (target_can_async_p ())
2748 int all_threads
= 0;
2750 dont_repeat (); /* Not for the faint of heart. */
2753 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2756 if (!non_stop
&& all_threads
)
2757 error (_("-a is meaningless in all-stop mode."));
2759 interrupt_target_1 (all_threads
);
2764 print_float_info (struct ui_file
*file
,
2765 struct frame_info
*frame
, const char *args
)
2767 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2769 if (gdbarch_print_float_info_p (gdbarch
))
2770 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2774 int printed_something
= 0;
2777 regnum
< gdbarch_num_regs (gdbarch
)
2778 + gdbarch_num_pseudo_regs (gdbarch
);
2781 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2783 printed_something
= 1;
2784 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2787 if (!printed_something
)
2788 fprintf_filtered (file
, "No floating-point info "
2789 "available for this processor.\n");
2794 float_info (char *args
, int from_tty
)
2796 if (!target_has_registers
)
2797 error (_("The program has no registers now."));
2799 print_float_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2803 unset_command (char *args
, int from_tty
)
2805 printf_filtered (_("\"unset\" must be followed by the "
2806 "name of an unset subcommand.\n"));
2807 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2811 _initialize_infcmd (void)
2813 struct cmd_list_element
*c
= NULL
;
2815 /* Add the filename of the terminal connected to inferior I/O. */
2816 add_setshow_filename_cmd ("inferior-tty", class_run
,
2817 &inferior_io_terminal_scratch
, _("\
2818 Set terminal for future runs of program being debugged."), _("\
2819 Show terminal for future runs of program being debugged."), _("\
2820 Usage: set inferior-tty /dev/pts/1"),
2821 set_inferior_tty_command
,
2822 show_inferior_tty_command
,
2823 &setlist
, &showlist
);
2824 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2826 add_setshow_optional_filename_cmd ("args", class_run
,
2827 &inferior_args_scratch
, _("\
2828 Set argument list to give program being debugged when it is started."), _("\
2829 Show argument list to give program being debugged when it is started."), _("\
2830 Follow this command with any number of args, to be passed to the program."),
2833 &setlist
, &showlist
);
2835 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2836 The environment to give the program, or one variable's value.\n\
2837 With an argument VAR, prints the value of environment variable VAR to\n\
2838 give the program being debugged. With no arguments, prints the entire\n\
2839 environment to be given to the program."), &showlist
);
2840 set_cmd_completer (c
, noop_completer
);
2842 add_prefix_cmd ("unset", no_class
, unset_command
,
2843 _("Complement to certain \"set\" commands."),
2844 &unsetlist
, "unset ", 0, &cmdlist
);
2846 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2847 Cancel environment variable VAR for the program.\n\
2848 This does not affect the program until the next \"run\" command."),
2850 set_cmd_completer (c
, noop_completer
);
2852 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2853 Set environment variable value to give the program.\n\
2854 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2855 VALUES of environment variables are uninterpreted strings.\n\
2856 This does not affect the program until the next \"run\" command."),
2858 set_cmd_completer (c
, noop_completer
);
2860 c
= add_com ("path", class_files
, path_command
, _("\
2861 Add directory DIR(s) to beginning of search path for object files.\n\
2862 $cwd in the path means the current working directory.\n\
2863 This path is equivalent to the $PATH shell variable. It is a list of\n\
2864 directories, separated by colons. These directories are searched to find\n\
2865 fully linked executable files and separately compiled object files as \
2867 set_cmd_completer (c
, filename_completer
);
2869 c
= add_cmd ("paths", no_class
, path_info
, _("\
2870 Current search path for finding object files.\n\
2871 $cwd in the path means the current working directory.\n\
2872 This path is equivalent to the $PATH shell variable. It is a list of\n\
2873 directories, separated by colons. These directories are searched to find\n\
2874 fully linked executable files and separately compiled object files as \
2877 set_cmd_completer (c
, noop_completer
);
2879 add_prefix_cmd ("kill", class_run
, kill_command
,
2880 _("Kill execution of program being debugged."),
2881 &killlist
, "kill ", 0, &cmdlist
);
2883 add_com ("attach", class_run
, attach_command
, _("\
2884 Attach to a process or file outside of GDB.\n\
2885 This command attaches to another target, of the same type as your last\n\
2886 \"target\" command (\"info files\" will show your target stack).\n\
2887 The command may take as argument a process id or a device file.\n\
2888 For a process id, you must have permission to send the process a signal,\n\
2889 and it must have the same effective uid as the debugger.\n\
2890 When using \"attach\" with a process id, the debugger finds the\n\
2891 program running in the process, looking first in the current working\n\
2892 directory, or (if not found there) using the source file search path\n\
2893 (see the \"directory\" command). You can also use the \"file\" command\n\
2894 to specify the program, and to load its symbol table."));
2896 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2897 Detach a process or file previously attached.\n\
2898 If a process, it is no longer traced, and it continues its execution. If\n\
2899 you were debugging a file, the file is closed and gdb no longer accesses it."),
2900 &detachlist
, "detach ", 0, &cmdlist
);
2902 add_com ("disconnect", class_run
, disconnect_command
, _("\
2903 Disconnect from a target.\n\
2904 The target will wait for another debugger to connect. Not available for\n\
2907 add_com ("signal", class_run
, signal_command
, _("\
2908 Continue program giving it signal specified by the argument.\n\
2909 An argument of \"0\" means continue program without giving it a signal."));
2911 add_com ("stepi", class_run
, stepi_command
, _("\
2912 Step one instruction exactly.\n\
2913 Argument N means do this N times (or till program stops for another \
2915 add_com_alias ("si", "stepi", class_alias
, 0);
2917 add_com ("nexti", class_run
, nexti_command
, _("\
2918 Step one instruction, but proceed through subroutine calls.\n\
2919 Argument N means do this N times (or till program stops for another \
2921 add_com_alias ("ni", "nexti", class_alias
, 0);
2923 add_com ("finish", class_run
, finish_command
, _("\
2924 Execute until selected stack frame returns.\n\
2925 Upon return, the value returned is printed and put in the value history."));
2926 add_com_alias ("fin", "finish", class_run
, 1);
2928 add_com ("next", class_run
, next_command
, _("\
2929 Step program, proceeding through subroutine calls.\n\
2930 Like the \"step\" command as long as subroutine calls do not happen;\n\
2931 when they do, the call is treated as one instruction.\n\
2932 Argument N means do this N times (or till program stops for another \
2934 add_com_alias ("n", "next", class_run
, 1);
2936 add_com_alias ("S", "next", class_run
, 1);
2938 add_com ("step", class_run
, step_command
, _("\
2939 Step program until it reaches a different source line.\n\
2940 Argument N means do this N times (or till program stops for another \
2942 add_com_alias ("s", "step", class_run
, 1);
2944 c
= add_com ("until", class_run
, until_command
, _("\
2945 Execute until the program reaches a source line greater than the current\n\
2946 or a specified location (same args as break command) within the current \
2948 set_cmd_completer (c
, location_completer
);
2949 add_com_alias ("u", "until", class_run
, 1);
2951 c
= add_com ("advance", class_run
, advance_command
, _("\
2952 Continue the program up to the given location (same form as args for break \
2954 Execution will also stop upon exit from the current stack frame."));
2955 set_cmd_completer (c
, location_completer
);
2957 c
= add_com ("jump", class_run
, jump_command
, _("\
2958 Continue program being debugged at specified line or address.\n\
2959 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2960 for an address to start at."));
2961 set_cmd_completer (c
, location_completer
);
2965 c
= add_com ("go", class_run
, go_command
, _("\
2966 Usage: go <location>\n\
2967 Continue program being debugged, stopping at specified line or \n\
2969 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2970 expression for an address to start at.\n\
2971 This command is a combination of tbreak and jump."));
2972 set_cmd_completer (c
, location_completer
);
2976 add_com_alias ("g", "go", class_run
, 1);
2978 add_com ("continue", class_run
, continue_command
, _("\
2979 Continue program being debugged, after signal or breakpoint.\n\
2980 If proceeding from breakpoint, a number N may be used as an argument,\n\
2981 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2982 the breakpoint won't break until the Nth time it is reached).\n\
2984 If non-stop mode is enabled, continue only the current thread,\n\
2985 otherwise all the threads in the program are continued. To \n\
2986 continue all stopped threads in non-stop mode, use the -a option.\n\
2987 Specifying -a and an ignore count simultaneously is an error."));
2988 add_com_alias ("c", "cont", class_run
, 1);
2989 add_com_alias ("fg", "cont", class_run
, 1);
2991 c
= add_com ("run", class_run
, run_command
, _("\
2992 Start debugged program. You may specify arguments to give it.\n\
2993 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2994 Input and output redirection with \">\", \"<\", or \">>\" are also \
2996 With no arguments, uses arguments last specified (with \"run\" \
2997 or \"set args\").\n\
2998 To cancel previous arguments and run with no arguments,\n\
2999 use \"set args\" without arguments."));
3000 set_cmd_completer (c
, filename_completer
);
3001 add_com_alias ("r", "run", class_run
, 1);
3003 add_com ("R", class_run
, run_no_args_command
,
3004 _("Start debugged program with no arguments."));
3006 c
= add_com ("start", class_run
, start_command
, _("\
3007 Run the debugged program until the beginning of the main procedure.\n\
3008 You may specify arguments to give to your program, just as with the\n\
3009 \"run\" command."));
3010 set_cmd_completer (c
, filename_completer
);
3012 add_com ("interrupt", class_run
, interrupt_target_command
,
3013 _("Interrupt the execution of the debugged program.\n\
3014 If non-stop mode is enabled, interrupt only the current thread,\n\
3015 otherwise all the threads in the program are stopped. To \n\
3016 interrupt all running threads in non-stop mode, use the -a option."));
3018 add_info ("registers", nofp_registers_info
, _("\
3019 List of integer registers and their contents, for selected stack frame.\n\
3020 Register name as argument means describe only that register."));
3021 add_info_alias ("r", "registers", 1);
3024 add_com ("lr", class_info
, nofp_registers_info
, _("\
3025 List of integer registers and their contents, for selected stack frame.\n\
3026 Register name as argument means describe only that register."));
3027 add_info ("all-registers", all_registers_info
, _("\
3028 List of all registers and their contents, for selected stack frame.\n\
3029 Register name as argument means describe only that register."));
3031 add_info ("program", program_info
,
3032 _("Execution status of the program."));
3034 add_info ("float", float_info
,
3035 _("Print the status of the floating point unit\n"));
3037 add_info ("vector", vector_info
,
3038 _("Print the status of the vector unit\n"));