1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
38 #include "completer.h"
40 #include "event-top.h"
41 #include "parser-defs.h"
43 #include "reggroups.h"
47 #include "gdb_assert.h"
49 #include "target-descriptions.h"
50 #include "user-regs.h"
51 #include "exceptions.h"
52 #include "cli/cli-decode.h"
53 #include "gdbthread.h"
55 /* Functions exported for general use, in inferior.h: */
57 void all_registers_info (char *, int);
59 void registers_info (char *, int);
61 void nexti_command (char *, int);
63 void stepi_command (char *, int);
65 void continue_command (char *, int);
67 void interrupt_target_command (char *args
, int from_tty
);
69 /* Local functions: */
71 static void nofp_registers_info (char *, int);
73 static void print_return_value (struct type
*func_type
,
74 struct type
*value_type
);
76 static void until_next_command (int);
78 static void until_command (char *, int);
80 static void path_info (char *, int);
82 static void path_command (char *, int);
84 static void unset_command (char *, int);
86 static void float_info (char *, int);
88 static void detach_command (char *, int);
90 static void disconnect_command (char *, int);
92 static void unset_environment_command (char *, int);
94 static void set_environment_command (char *, int);
96 static void environment_info (char *, int);
98 static void program_info (char *, int);
100 static void finish_command (char *, int);
102 static void signal_command (char *, int);
104 static void jump_command (char *, int);
106 static void step_1 (int, int, char *);
107 static void step_once (int skip_subroutines
, int single_inst
, int count
, int thread
);
109 static void next_command (char *, int);
111 static void step_command (char *, int);
113 static void run_command (char *, int);
115 static void run_no_args_command (char *args
, int from_tty
);
117 static void go_command (char *line_no
, int from_tty
);
119 static int strip_bg_char (char **);
121 void _initialize_infcmd (void);
123 #define ERROR_NO_INFERIOR \
124 if (!target_has_execution) error (_("The program is not being run."));
126 /* String containing arguments to give to the program, separated by spaces.
127 Empty string (pointer to '\0') means no args. */
129 static char *inferior_args
;
131 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
132 then we must compute INFERIOR_ARGS from this (via the target). */
134 static int inferior_argc
;
135 static char **inferior_argv
;
137 /* File name for default use for standard in/out in the inferior. */
139 static char *inferior_io_terminal
;
141 /* Pid of our debugged inferior, or 0 if no inferior now.
142 Since various parts of infrun.c test this to see whether there is a program
143 being debugged it should be nonzero (currently 3 is used) for remote
146 ptid_t inferior_ptid
;
148 /* Address at which inferior stopped. */
152 /* Flag indicating that a command has proceeded the inferior past the
153 current breakpoint. */
155 int breakpoint_proceeded
;
157 /* Nonzero if stopped due to completion of a stack dummy routine. */
159 int stop_stack_dummy
;
161 /* Nonzero if stopped due to a random (unexpected) signal in inferior
164 int stopped_by_random_signal
;
166 /* Environment to use for running inferior,
167 in format described in environ.h. */
169 struct gdb_environ
*inferior_environ
;
171 /* When set, no calls to target_resumed observer will be made. */
172 int suppress_resume_observer
= 0;
173 /* When set, normal_stop will not call the normal_stop observer. */
174 int suppress_stop_observer
= 0;
176 /* Accessor routines. */
179 set_inferior_io_terminal (const char *terminal_name
)
181 if (inferior_io_terminal
)
182 xfree (inferior_io_terminal
);
185 inferior_io_terminal
= NULL
;
187 inferior_io_terminal
= savestring (terminal_name
, strlen (terminal_name
));
191 get_inferior_io_terminal (void)
193 return inferior_io_terminal
;
197 get_inferior_args (void)
199 if (inferior_argc
!= 0)
203 n
= gdbarch_construct_inferior_arguments (current_gdbarch
,
204 inferior_argc
, inferior_argv
);
205 old
= set_inferior_args (n
);
209 if (inferior_args
== NULL
)
210 inferior_args
= xstrdup ("");
212 return inferior_args
;
216 set_inferior_args (char *newargs
)
218 char *saved_args
= inferior_args
;
220 inferior_args
= newargs
;
228 set_inferior_args_vector (int argc
, char **argv
)
230 inferior_argc
= argc
;
231 inferior_argv
= argv
;
234 /* Notice when `set args' is run. */
236 notice_args_set (char *args
, int from_tty
, struct cmd_list_element
*c
)
242 /* Notice when `show args' is run. */
244 notice_args_read (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
, const char *value
)
247 /* Note that we ignore the passed-in value in favor of computing it
249 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
253 /* Compute command-line string given argument vector. This does the
254 same shell processing as fork_inferior. */
256 construct_inferior_arguments (struct gdbarch
*gdbarch
, int argc
, char **argv
)
260 if (STARTUP_WITH_SHELL
)
262 /* This holds all the characters considered special to the
263 typical Unix shells. We include `^' because the SunOS
264 /bin/sh treats it as a synonym for `|'. */
265 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
270 /* We over-compute the size. It shouldn't matter. */
271 for (i
= 0; i
< argc
; ++i
)
272 length
+= 2 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
274 result
= (char *) xmalloc (length
);
277 for (i
= 0; i
< argc
; ++i
)
282 /* Need to handle empty arguments specially. */
283 if (argv
[i
][0] == '\0')
290 for (cp
= argv
[i
]; *cp
; ++cp
)
292 if (strchr (special
, *cp
) != NULL
)
302 /* In this case we can't handle arguments that contain spaces,
303 tabs, or newlines -- see breakup_args(). */
307 for (i
= 0; i
< argc
; ++i
)
309 char *cp
= strchr (argv
[i
], ' ');
311 cp
= strchr (argv
[i
], '\t');
313 cp
= strchr (argv
[i
], '\n');
315 error (_("can't handle command-line argument containing whitespace"));
316 length
+= strlen (argv
[i
]) + 1;
319 result
= (char *) xmalloc (length
);
321 for (i
= 0; i
< argc
; ++i
)
324 strcat (result
, " ");
325 strcat (result
, argv
[i
]);
333 /* This function detects whether or not a '&' character (indicating
334 background execution) has been added as *the last* of the arguments ARGS
335 of a command. If it has, it removes it and returns 1. Otherwise it
336 does nothing and returns 0. */
338 strip_bg_char (char **args
)
342 p
= strchr (*args
, '&');
346 if (p
== (*args
+ strlen (*args
) - 1))
348 if (strlen (*args
) > 1)
352 while (*p
== ' ' || *p
== '\t');
364 tty_command (char *file
, int from_tty
)
367 error_no_arg (_("terminal name for running target process"));
369 set_inferior_io_terminal (file
);
372 /* Common actions to take after creating any sort of inferior, by any
373 means (running, attaching, connecting, et cetera). The target
374 should be stopped. */
377 post_create_inferior (struct target_ops
*target
, int from_tty
)
379 /* Be sure we own the terminal in case write operations are performed. */
380 target_terminal_ours ();
382 /* If the target hasn't taken care of this already, do it now.
383 Targets which need to access registers during to_open,
384 to_create_inferior, or to_attach should do it earlier; but many
386 target_find_description ();
390 /* Sometimes the platform-specific hook loads initial shared
391 libraries, and sometimes it doesn't. Try to do so first, so
392 that we can add them with the correct value for FROM_TTY.
393 If we made all the inferior hook methods consistent,
394 this call could be removed. */
396 SOLIB_ADD (NULL
, from_tty
, target
, auto_solib_add
);
398 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
401 /* Create the hooks to handle shared library load and unload
403 #ifdef SOLIB_CREATE_INFERIOR_HOOK
404 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
406 solib_create_inferior_hook ();
410 observer_notify_inferior_created (target
, from_tty
);
413 /* Kill the inferior if already running. This function is designed
414 to be called when we are about to start the execution of the program
415 from the beginning. Ask the user to confirm that he wants to restart
416 the program being debugged when FROM_TTY is non-null. */
419 kill_if_already_running (int from_tty
)
421 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
423 /* Bail out before killing the program if we will not be able to
425 target_require_runnable ();
428 && !query ("The program being debugged has been started already.\n\
429 Start it from the beginning? "))
430 error (_("Program not restarted."));
435 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
436 a temporary breakpoint at the begining of the main program before
437 running the program. */
440 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
446 kill_if_already_running (from_tty
);
448 init_wait_for_inferior ();
449 clear_breakpoint_hit_counts ();
451 /* Clean up any leftovers from other runs. Some other things from
452 this function should probably be moved into target_pre_inferior. */
453 target_pre_inferior (from_tty
);
455 /* The comment here used to read, "The exec file is re-read every
456 time we do a generic_mourn_inferior, so we just have to worry
457 about the symbol file." The `generic_mourn_inferior' function
458 gets called whenever the program exits. However, suppose the
459 program exits, and *then* the executable file changes? We need
460 to check again here. Since reopen_exec_file doesn't do anything
461 if the timestamp hasn't changed, I don't see the harm. */
465 /* Insert the temporary breakpoint if a location was specified. */
467 tbreak_command (main_name (), 0);
469 exec_file
= (char *) get_exec_file (0);
471 if (non_stop
&& !target_supports_non_stop ())
472 error (_("The target does not support running in non-stop mode."));
474 /* We keep symbols from add-symbol-file, on the grounds that the
475 user might want to add some symbols before running the program
476 (right?). But sometimes (dynamic loading where the user manually
477 introduces the new symbols with add-symbol-file), the code which
478 the symbols describe does not persist between runs. Currently
479 the user has to manually nuke all symbols between runs if they
480 want them to go away (PR 2207). This is probably reasonable. */
484 if (target_can_async_p ())
485 async_disable_stdin ();
489 int async_exec
= strip_bg_char (&args
);
491 /* If we get a request for running in the bg but the target
492 doesn't support it, error out. */
493 if (async_exec
&& !target_can_async_p ())
494 error (_("Asynchronous execution not supported on this target."));
496 /* If we don't get a request of running in the bg, then we need
497 to simulate synchronous (fg) execution. */
498 if (!async_exec
&& target_can_async_p ())
500 /* Simulate synchronous execution */
501 async_disable_stdin ();
504 /* If there were other args, beside '&', process them. */
507 char *old_args
= set_inferior_args (xstrdup (args
));
514 ui_out_field_string (uiout
, NULL
, "Starting program");
515 ui_out_text (uiout
, ": ");
517 ui_out_field_string (uiout
, "execfile", exec_file
);
518 ui_out_spaces (uiout
, 1);
519 /* We call get_inferior_args() because we might need to compute
521 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
522 ui_out_text (uiout
, "\n");
523 ui_out_flush (uiout
);
526 /* We call get_inferior_args() because we might need to compute
528 target_create_inferior (exec_file
, get_inferior_args (),
529 environ_vector (inferior_environ
), from_tty
);
531 /* Pass zero for FROM_TTY, because at this point the "run" command
532 has done its thing; now we are setting up the running program. */
533 post_create_inferior (¤t_target
, 0);
535 /* Start the target running. */
536 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
541 run_command (char *args
, int from_tty
)
543 run_command_1 (args
, from_tty
, 0);
547 run_no_args_command (char *args
, int from_tty
)
549 char *old_args
= set_inferior_args (xstrdup (""));
554 /* Start the execution of the program up until the beginning of the main
558 start_command (char *args
, int from_tty
)
560 /* Some languages such as Ada need to search inside the program
561 minimal symbols for the location where to put the temporary
562 breakpoint before starting. */
563 if (!have_minimal_symbols ())
564 error (_("No symbol table loaded. Use the \"file\" command."));
566 /* Run the program until reaching the main procedure... */
567 run_command_1 (args
, from_tty
, 1);
571 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
573 /* We go through all threads individually instead of compressing
574 into a single target `resume_all' request, because some threads
575 may be stopped in internal breakpoints/events, or stopped waiting
576 for its turn in the displaced stepping queue (that is, they are
577 running && !executing). The target side has no idea about why
578 the thread is stopped, so a `resume_all' command would resume too
579 much. If/when GDB gains a way to tell the target `hold this
580 thread stopped until I say otherwise', then we can optimize
582 if (!is_stopped (thread
->ptid
))
585 switch_to_thread (thread
->ptid
);
586 clear_proceed_status ();
587 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
592 continue_1 (int all_threads
)
596 if (non_stop
&& all_threads
)
598 /* Don't error out if the current thread is running, because
599 there may be other stopped threads. */
600 struct cleanup
*old_chain
;
602 /* Backup current thread and selected frame. */
603 old_chain
= make_cleanup_restore_current_thread ();
605 iterate_over_threads (proceed_thread_callback
, NULL
);
607 /* Restore selected ptid. */
608 do_cleanups (old_chain
);
612 ensure_not_running ();
613 clear_proceed_status ();
614 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
618 /* continue [-a] [proceed-count] [&] */
620 continue_command (char *args
, int from_tty
)
626 /* Find out whether we must run in the background. */
628 async_exec
= strip_bg_char (&args
);
630 /* If we must run in the background, but the target can't do it,
632 if (async_exec
&& !target_can_async_p ())
633 error (_("Asynchronous execution not supported on this target."));
635 /* If we are not asked to run in the bg, then prepare to run in the
636 foreground, synchronously. */
637 if (!async_exec
&& target_can_async_p ())
639 /* Simulate synchronous execution */
640 async_disable_stdin ();
645 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
648 args
+= sizeof ("-a") - 1;
654 if (!non_stop
&& all_threads
)
655 error (_("`-a' is meaningless in all-stop mode."));
657 if (args
!= NULL
&& all_threads
)
659 Can't resume all threads and specify proceed count simultaneously."));
661 /* If we have an argument left, set proceed count of breakpoint we
668 struct thread_info
*tp
;
671 tp
= find_thread_pid (inferior_ptid
);
675 struct target_waitstatus ws
;
677 get_last_target_status (&last_ptid
, &ws
);
678 tp
= find_thread_pid (last_ptid
);
681 bs
= tp
->stop_bpstat
;
683 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
686 set_ignore_count (num
,
687 parse_and_eval_long (args
) - 1,
689 /* set_ignore_count prints a message ending with a period.
690 So print two spaces before "Continuing.". */
692 printf_filtered (" ");
696 if (!stopped
&& from_tty
)
699 ("Not stopped at any breakpoint; argument ignored.\n");
704 printf_filtered (_("Continuing.\n"));
706 continue_1 (all_threads
);
709 /* Step until outside of current statement. */
712 step_command (char *count_string
, int from_tty
)
714 step_1 (0, 0, count_string
);
717 /* Likewise, but skip over subroutine calls as if single instructions. */
720 next_command (char *count_string
, int from_tty
)
722 step_1 (1, 0, count_string
);
725 /* Likewise, but step only one instruction. */
728 stepi_command (char *count_string
, int from_tty
)
730 step_1 (0, 1, count_string
);
734 nexti_command (char *count_string
, int from_tty
)
736 step_1 (1, 1, count_string
);
740 delete_longjmp_breakpoint_cleanup (void *arg
)
742 int thread
= * (int *) arg
;
743 delete_longjmp_breakpoint (thread
);
747 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
750 struct frame_info
*frame
;
751 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
756 ensure_not_running ();
759 async_exec
= strip_bg_char (&count_string
);
761 /* If we get a request for running in the bg but the target
762 doesn't support it, error out. */
763 if (async_exec
&& !target_can_async_p ())
764 error (_("Asynchronous execution not supported on this target."));
766 /* If we don't get a request of running in the bg, then we need
767 to simulate synchronous (fg) execution. */
768 if (!async_exec
&& target_can_async_p ())
770 /* Simulate synchronous execution */
771 async_disable_stdin ();
774 count
= count_string
? parse_and_eval_long (count_string
) : 1;
776 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
778 if (in_thread_list (inferior_ptid
))
779 thread
= pid_to_thread_id (inferior_ptid
);
781 set_longjmp_breakpoint ();
783 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
786 /* In synchronous case, all is well, just use the regular for loop. */
787 if (!target_can_async_p ())
789 for (; count
> 0; count
--)
791 struct thread_info
*tp
= inferior_thread ();
792 clear_proceed_status ();
794 frame
= get_current_frame ();
795 tp
->step_frame_id
= get_frame_id (frame
);
799 find_pc_line_pc_range (stop_pc
,
800 &tp
->step_range_start
, &tp
->step_range_end
);
801 if (tp
->step_range_end
== 0)
804 if (find_pc_partial_function (stop_pc
, &name
,
805 &tp
->step_range_start
,
806 &tp
->step_range_end
) == 0)
807 error (_("Cannot find bounds of current function"));
809 target_terminal_ours ();
810 printf_filtered (_("\
811 Single stepping until exit from function %s, \n\
812 which has no line number information.\n"), name
);
817 /* Say we are stepping, but stop after one insn whatever it does. */
818 tp
->step_range_start
= tp
->step_range_end
= 1;
819 if (!skip_subroutines
)
821 Don't step over function calls, not even to functions lacking
823 tp
->step_over_calls
= STEP_OVER_NONE
;
826 if (skip_subroutines
)
827 tp
->step_over_calls
= STEP_OVER_ALL
;
829 tp
->step_multi
= (count
> 1);
830 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
832 if (!target_has_execution
833 || !inferior_thread ()->stop_step
)
837 do_cleanups (cleanups
);
840 /* In case of asynchronous target things get complicated, do only
841 one step for now, before returning control to the event loop. Let
842 the continuation figure out how many other steps we need to do,
843 and handle them one at the time, through step_once(). */
846 step_once (skip_subroutines
, single_inst
, count
, thread
);
847 /* We are running, and the continuation is installed. It will
848 disable the longjmp breakpoint as appropriate. */
849 discard_cleanups (cleanups
);
853 struct step_1_continuation_args
856 int skip_subroutines
;
861 /* Called after we are done with one step operation, to check whether
862 we need to step again, before we print the prompt and return control
863 to the user. If count is > 1, we will need to do one more call to
864 proceed(), via step_once(). Basically it is like step_once and
865 step_1_continuation are co-recursive. */
867 step_1_continuation (void *args
)
869 struct step_1_continuation_args
*a
= args
;
871 if (target_has_execution
)
873 struct thread_info
*tp
;
875 tp
= inferior_thread ();
876 if (tp
->step_multi
&& tp
->stop_step
)
878 /* There are more steps to make, and we did stop due to
879 ending a stepping range. Do another step. */
880 step_once (a
->skip_subroutines
, a
->single_inst
, a
->count
- 1, a
->thread
);
886 /* We either stopped for some reason that is not stepping, or there
887 are no further steps to make. Cleanup. */
888 if (!a
->single_inst
|| a
->skip_subroutines
)
889 delete_longjmp_breakpoint (a
->thread
);
892 /* Do just one step operation. If count >1 we will have to set up a
893 continuation to be done after the target stops (after this one
894 step). This is useful to implement the 'step n' kind of commands, in
895 case of asynchronous targets. We had to split step_1 into two parts,
896 one to be done before proceed() and one afterwards. This function is
897 called in case of step n with n>1, after the first step operation has
900 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
902 struct frame_info
*frame
;
903 struct step_1_continuation_args
*args
;
907 /* Don't assume THREAD is a valid thread id. It is set to -1 if
908 the longjmp breakpoint was not required. Use the
909 INFERIOR_PTID thread instead, which is the same thread when
911 struct thread_info
*tp
= inferior_thread ();
912 clear_proceed_status ();
914 frame
= get_current_frame ();
915 if (!frame
) /* Avoid coredump here. Why tho? */
916 error (_("No current frame"));
917 tp
->step_frame_id
= get_frame_id (frame
);
921 find_pc_line_pc_range (stop_pc
,
922 &tp
->step_range_start
, &tp
->step_range_end
);
924 /* If we have no line info, switch to stepi mode. */
925 if (tp
->step_range_end
== 0 && step_stop_if_no_debug
)
927 tp
->step_range_start
= tp
->step_range_end
= 1;
929 else if (tp
->step_range_end
== 0)
932 if (find_pc_partial_function (stop_pc
, &name
,
933 &tp
->step_range_start
,
934 &tp
->step_range_end
) == 0)
935 error (_("Cannot find bounds of current function"));
937 target_terminal_ours ();
938 printf_filtered (_("\
939 Single stepping until exit from function %s, \n\
940 which has no line number information.\n"), name
);
945 /* Say we are stepping, but stop after one insn whatever it does. */
946 tp
->step_range_start
= tp
->step_range_end
= 1;
947 if (!skip_subroutines
)
949 Don't step over function calls, not even to functions lacking
951 tp
->step_over_calls
= STEP_OVER_NONE
;
954 if (skip_subroutines
)
955 tp
->step_over_calls
= STEP_OVER_ALL
;
957 tp
->step_multi
= (count
> 1);
958 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
960 args
= xmalloc (sizeof (*args
));
961 args
->skip_subroutines
= skip_subroutines
;
962 args
->single_inst
= single_inst
;
964 args
->thread
= thread
;
965 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
970 /* Continue program at specified address. */
973 jump_command (char *arg
, int from_tty
)
976 struct symtabs_and_lines sals
;
977 struct symtab_and_line sal
;
983 ensure_not_running ();
985 /* Find out whether we must run in the background. */
987 async_exec
= strip_bg_char (&arg
);
989 /* If we must run in the background, but the target can't do it,
991 if (async_exec
&& !target_can_async_p ())
992 error (_("Asynchronous execution not supported on this target."));
995 error_no_arg (_("starting address"));
997 sals
= decode_line_spec_1 (arg
, 1);
1000 error (_("Unreasonable jump request"));
1006 if (sal
.symtab
== 0 && sal
.pc
== 0)
1007 error (_("No source file has been specified."));
1009 resolve_sal_pc (&sal
); /* May error out */
1011 /* See if we are trying to jump to another function. */
1012 fn
= get_frame_function (get_current_frame ());
1013 sfn
= find_pc_function (sal
.pc
);
1014 if (fn
!= NULL
&& sfn
!= fn
)
1016 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
1017 SYMBOL_PRINT_NAME (fn
)))
1019 error (_("Not confirmed."));
1026 fixup_symbol_section (sfn
, 0);
1027 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn
)) &&
1028 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn
)))
1030 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
1032 error (_("Not confirmed."));
1042 printf_filtered (_("Continuing at "));
1043 fputs_filtered (paddress (addr
), gdb_stdout
);
1044 printf_filtered (".\n");
1047 /* If we are not asked to run in the bg, then prepare to run in the
1048 foreground, synchronously. */
1049 if (!async_exec
&& target_can_async_p ())
1051 /* Simulate synchronous execution */
1052 async_disable_stdin ();
1055 clear_proceed_status ();
1056 proceed (addr
, TARGET_SIGNAL_0
, 0);
1060 /* Go to line or address in current procedure */
1062 go_command (char *line_no
, int from_tty
)
1064 if (line_no
== (char *) NULL
|| !*line_no
)
1065 printf_filtered (_("Usage: go <location>\n"));
1068 tbreak_command (line_no
, from_tty
);
1069 jump_command (line_no
, from_tty
);
1074 /* Continue program giving it specified signal. */
1077 signal_command (char *signum_exp
, int from_tty
)
1079 enum target_signal oursig
;
1082 dont_repeat (); /* Too dangerous. */
1084 ensure_not_running ();
1086 /* Find out whether we must run in the background. */
1087 if (signum_exp
!= NULL
)
1088 async_exec
= strip_bg_char (&signum_exp
);
1090 /* If we must run in the background, but the target can't do it,
1092 if (async_exec
&& !target_can_async_p ())
1093 error (_("Asynchronous execution not supported on this target."));
1095 /* If we are not asked to run in the bg, then prepare to run in the
1096 foreground, synchronously. */
1097 if (!async_exec
&& target_can_async_p ())
1099 /* Simulate synchronous execution. */
1100 async_disable_stdin ();
1104 error_no_arg (_("signal number"));
1106 /* It would be even slicker to make signal names be valid expressions,
1107 (the type could be "enum $signal" or some such), then the user could
1108 assign them to convenience variables. */
1109 oursig
= target_signal_from_name (signum_exp
);
1111 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1113 /* No, try numeric. */
1114 int num
= parse_and_eval_long (signum_exp
);
1117 oursig
= TARGET_SIGNAL_0
;
1119 oursig
= target_signal_from_command (num
);
1124 if (oursig
== TARGET_SIGNAL_0
)
1125 printf_filtered (_("Continuing with no signal.\n"));
1127 printf_filtered (_("Continuing with signal %s.\n"),
1128 target_signal_to_name (oursig
));
1131 clear_proceed_status ();
1132 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1133 FIXME: Neither should "signal foo" but when I tried passing
1134 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1135 tried to track down yet. */
1136 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
1139 /* Proceed until we reach a different source line with pc greater than
1140 our current one or exit the function. We skip calls in both cases.
1142 Note that eventually this command should probably be changed so
1143 that only source lines are printed out when we hit the breakpoint
1144 we set. This may involve changes to wait_for_inferior and the
1145 proceed status code. */
1148 until_next_command (int from_tty
)
1150 struct frame_info
*frame
;
1152 struct symbol
*func
;
1153 struct symtab_and_line sal
;
1154 struct thread_info
*tp
= inferior_thread ();
1156 clear_proceed_status ();
1158 frame
= get_current_frame ();
1160 /* Step until either exited from this function or greater
1161 than the current line (if in symbolic section) or pc (if
1165 func
= find_pc_function (pc
);
1169 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1171 if (msymbol
== NULL
)
1172 error (_("Execution is not within a known function."));
1174 tp
->step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1175 tp
->step_range_end
= pc
;
1179 sal
= find_pc_line (pc
, 0);
1181 tp
->step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1182 tp
->step_range_end
= sal
.end
;
1185 tp
->step_over_calls
= STEP_OVER_ALL
;
1186 tp
->step_frame_id
= get_frame_id (frame
);
1188 tp
->step_multi
= 0; /* Only one call to proceed */
1190 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1194 until_command (char *arg
, int from_tty
)
1198 if (!target_has_execution
)
1199 error (_("The program is not running."));
1201 /* Find out whether we must run in the background. */
1203 async_exec
= strip_bg_char (&arg
);
1205 /* If we must run in the background, but the target can't do it,
1207 if (async_exec
&& !target_can_async_p ())
1208 error (_("Asynchronous execution not supported on this target."));
1210 /* If we are not asked to run in the bg, then prepare to run in the
1211 foreground, synchronously. */
1212 if (!async_exec
&& target_can_async_p ())
1214 /* Simulate synchronous execution */
1215 async_disable_stdin ();
1219 until_break_command (arg
, from_tty
, 0);
1221 until_next_command (from_tty
);
1225 advance_command (char *arg
, int from_tty
)
1229 if (!target_has_execution
)
1230 error (_("The program is not running."));
1233 error_no_arg (_("a location"));
1235 /* Find out whether we must run in the background. */
1237 async_exec
= strip_bg_char (&arg
);
1239 /* If we must run in the background, but the target can't do it,
1241 if (async_exec
&& !target_can_async_p ())
1242 error (_("Asynchronous execution not supported on this target."));
1244 /* If we are not asked to run in the bg, then prepare to run in the
1245 foreground, synchronously. */
1246 if (!async_exec
&& target_can_async_p ())
1248 /* Simulate synchronous execution. */
1249 async_disable_stdin ();
1252 until_break_command (arg
, from_tty
, 1);
1255 /* Print the result of a function at the end of a 'finish' command. */
1258 print_return_value (struct type
*func_type
, struct type
*value_type
)
1260 struct gdbarch
*gdbarch
= current_gdbarch
;
1261 struct cleanup
*old_chain
;
1262 struct ui_stream
*stb
;
1263 struct value
*value
;
1265 CHECK_TYPEDEF (value_type
);
1266 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1268 /* FIXME: 2003-09-27: When returning from a nested inferior function
1269 call, it's possible (with no help from the architecture vector)
1270 to locate and return/print a "struct return" value. This is just
1271 a more complicated case of what is already being done in in the
1272 inferior function call code. In fact, when inferior function
1273 calls are made async, this will likely be made the norm. */
1275 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1278 case RETURN_VALUE_REGISTER_CONVENTION
:
1279 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1280 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1281 value
= allocate_value (value_type
);
1282 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1283 value_contents_raw (value
), NULL
);
1285 case RETURN_VALUE_STRUCT_CONVENTION
:
1289 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1295 stb
= ui_out_stream_new (uiout
);
1296 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1297 ui_out_text (uiout
, "Value returned is ");
1298 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1299 record_latest_value (value
));
1300 ui_out_text (uiout
, " = ");
1301 value_print (value
, stb
->stream
, 0, Val_no_prettyprint
);
1302 ui_out_field_stream (uiout
, "return-value", stb
);
1303 ui_out_text (uiout
, "\n");
1304 do_cleanups (old_chain
);
1308 ui_out_text (uiout
, "Value returned has type: ");
1309 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1310 ui_out_text (uiout
, ".");
1311 ui_out_text (uiout
, " Cannot determine contents\n");
1315 /* Stuff that needs to be done by the finish command after the target
1316 has stopped. In asynchronous mode, we wait for the target to stop
1317 in the call to poll or select in the event loop, so it is
1318 impossible to do all the stuff as part of the finish_command
1319 function itself. The only chance we have to complete this command
1320 is in fetch_inferior_event, which is called by the event loop as
1321 soon as it detects that the target has stopped. This function is
1322 called via the cmd_continuation pointer. */
1324 struct finish_command_continuation_args
1326 struct breakpoint
*breakpoint
;
1327 struct symbol
*function
;
1331 finish_command_continuation (void *arg
)
1333 struct finish_command_continuation_args
*a
= arg
;
1337 if (!ptid_equal (inferior_ptid
, null_ptid
)
1338 && target_has_execution
1339 && is_stopped (inferior_ptid
))
1340 bs
= inferior_thread ()->stop_bpstat
;
1342 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1343 && a
->function
!= NULL
)
1345 struct type
*value_type
;
1347 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1349 internal_error (__FILE__
, __LINE__
,
1350 _("finish_command: function has no target type"));
1352 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1353 print_return_value (SYMBOL_TYPE (a
->function
), value_type
);
1356 /* We suppress normal call of normal_stop observer and do it here so
1357 that that *stopped notification includes the return value. */
1358 /* NOTE: This is broken in non-stop mode. There is no guarantee the
1359 next stop will be in the same thread that we started doing a
1360 finish on. This suppressing (or some other replacement means)
1361 should be a thread property. */
1362 observer_notify_normal_stop (bs
);
1363 suppress_stop_observer
= 0;
1364 delete_breakpoint (a
->breakpoint
);
1368 finish_command_continuation_free_arg (void *arg
)
1370 /* NOTE: See finish_command_continuation. This would go away, if
1371 this suppressing is made a thread property. */
1372 suppress_stop_observer
= 0;
1376 /* finish_backward -- helper function for finish_command. */
1379 finish_backward (struct symbol
*function
)
1381 struct symtab_and_line sal
;
1382 struct thread_info
*tp
= inferior_thread ();
1383 struct breakpoint
*breakpoint
;
1384 struct cleanup
*old_chain
;
1385 CORE_ADDR func_addr
;
1388 if (find_pc_partial_function (get_frame_pc (get_current_frame ()),
1389 NULL
, &func_addr
, NULL
) == 0)
1390 internal_error (__FILE__
, __LINE__
,
1391 _("Finish: couldn't find function."));
1393 sal
= find_pc_line (func_addr
, 0);
1395 /* We don't need a return value. */
1396 tp
->proceed_to_finish
= 0;
1397 /* Special case: if we're sitting at the function entry point,
1398 then all we need to do is take a reverse singlestep. We
1399 don't need to set a breakpoint, and indeed it would do us
1402 Note that this can only happen at frame #0, since there's
1403 no way that a function up the stack can have a return address
1404 that's equal to its entry point. */
1406 if (sal
.pc
!= read_pc ())
1408 /* Set breakpoint and continue. */
1410 set_momentary_breakpoint (sal
,
1411 get_frame_id (get_selected_frame (NULL
)),
1413 /* Tell the breakpoint to keep quiet. We won't be done
1414 until we've done another reverse single-step. */
1415 make_breakpoint_silent (breakpoint
);
1416 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1417 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1418 /* We will be stopped when proceed returns. */
1419 back_up
= bpstat_find_breakpoint (tp
->stop_bpstat
, breakpoint
) != NULL
;
1420 do_cleanups (old_chain
);
1426 /* If in fact we hit the step-resume breakpoint (and not
1427 some other breakpoint), then we're almost there --
1428 we just need to back up by one more single-step. */
1429 tp
->step_range_start
= tp
->step_range_end
= 1;
1430 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1435 /* finish_forward -- helper function for finish_command. */
1438 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1440 struct symtab_and_line sal
;
1441 struct thread_info
*tp
= inferior_thread ();
1442 struct breakpoint
*breakpoint
;
1443 struct cleanup
*old_chain
;
1444 struct finish_command_continuation_args
*cargs
;
1446 sal
= find_pc_line (get_frame_pc (frame
), 0);
1447 sal
.pc
= get_frame_pc (frame
);
1449 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
1452 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1454 tp
->proceed_to_finish
= 1; /* We want stop_registers, please... */
1455 make_cleanup_restore_integer (&suppress_stop_observer
);
1456 suppress_stop_observer
= 1;
1457 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1459 cargs
= xmalloc (sizeof (*cargs
));
1461 cargs
->breakpoint
= breakpoint
;
1462 cargs
->function
= function
;
1463 add_continuation (tp
, finish_command_continuation
, cargs
,
1464 finish_command_continuation_free_arg
);
1466 discard_cleanups (old_chain
);
1467 if (!target_can_async_p ())
1468 do_all_continuations ();
1471 /* "finish": Set a temporary breakpoint at the place the selected
1472 frame will return to, then continue. */
1475 finish_command (char *arg
, int from_tty
)
1477 struct frame_info
*frame
;
1478 struct symbol
*function
;
1482 /* Find out whether we must run in the background. */
1484 async_exec
= strip_bg_char (&arg
);
1486 /* If we must run in the background, but the target can't do it,
1488 if (async_exec
&& !target_can_async_p ())
1489 error (_("Asynchronous execution not supported on this target."));
1491 /* Don't try to async in reverse. */
1492 if (async_exec
&& execution_direction
== EXEC_REVERSE
)
1493 error (_("Asynchronous 'finish' not supported in reverse."));
1495 /* If we are not asked to run in the bg, then prepare to run in the
1496 foreground, synchronously. */
1497 if (!async_exec
&& target_can_async_p ())
1499 /* Simulate synchronous execution. */
1500 async_disable_stdin ();
1504 error (_("The \"finish\" command does not take any arguments."));
1505 if (!target_has_execution
)
1506 error (_("The program is not running."));
1508 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1510 error (_("\"finish\" not meaningful in the outermost frame."));
1512 clear_proceed_status ();
1514 /* Find the function we will return from. */
1516 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1518 /* Print info on the selected frame, including level number but not
1522 if (execution_direction
== EXEC_REVERSE
)
1523 printf_filtered (_("Run back to call of "));
1525 printf_filtered (_("Run till exit from "));
1527 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1530 if (execution_direction
== EXEC_REVERSE
)
1531 finish_backward (function
);
1533 finish_forward (function
, frame
);
1538 program_info (char *args
, int from_tty
)
1542 struct thread_info
*tp
;
1545 if (!target_has_execution
)
1547 printf_filtered (_("The program being debugged is not being run.\n"));
1552 ptid
= inferior_ptid
;
1555 struct target_waitstatus ws
;
1556 get_last_target_status (&ptid
, &ws
);
1559 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1560 error (_("Invalid selected thread."));
1561 else if (is_running (ptid
))
1562 error (_("Selected thread is running."));
1564 tp
= find_thread_pid (ptid
);
1565 bs
= tp
->stop_bpstat
;
1566 stat
= bpstat_num (&bs
, &num
);
1568 target_files_info ();
1569 printf_filtered (_("Program stopped at %s.\n"),
1570 hex_string ((unsigned long) stop_pc
));
1572 printf_filtered (_("It stopped after being stepped.\n"));
1575 /* There may be several breakpoints in the same place, so this
1576 isn't as strange as it seems. */
1581 printf_filtered (_("\
1582 It stopped at a breakpoint that has since been deleted.\n"));
1585 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1586 stat
= bpstat_num (&bs
, &num
);
1589 else if (tp
->stop_signal
!= TARGET_SIGNAL_0
)
1591 printf_filtered (_("It stopped with signal %s, %s.\n"),
1592 target_signal_to_name (tp
->stop_signal
),
1593 target_signal_to_string (tp
->stop_signal
));
1598 printf_filtered (_("\
1599 Type \"info stack\" or \"info registers\" for more information.\n"));
1604 environment_info (char *var
, int from_tty
)
1608 char *val
= get_in_environ (inferior_environ
, var
);
1611 puts_filtered (var
);
1612 puts_filtered (" = ");
1613 puts_filtered (val
);
1614 puts_filtered ("\n");
1618 puts_filtered ("Environment variable \"");
1619 puts_filtered (var
);
1620 puts_filtered ("\" not defined.\n");
1625 char **vector
= environ_vector (inferior_environ
);
1628 puts_filtered (*vector
++);
1629 puts_filtered ("\n");
1635 set_environment_command (char *arg
, int from_tty
)
1637 char *p
, *val
, *var
;
1641 error_no_arg (_("environment variable and value"));
1643 /* Find seperation between variable name and value */
1644 p
= (char *) strchr (arg
, '=');
1645 val
= (char *) strchr (arg
, ' ');
1647 if (p
!= 0 && val
!= 0)
1649 /* We have both a space and an equals. If the space is before the
1650 equals, walk forward over the spaces til we see a nonspace
1651 (possibly the equals). */
1656 /* Now if the = is after the char following the spaces,
1657 take the char following the spaces. */
1661 else if (val
!= 0 && p
== 0)
1665 error_no_arg (_("environment variable to set"));
1667 if (p
== 0 || p
[1] == 0)
1671 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1675 /* Not setting variable value to null */
1677 while (*val
== ' ' || *val
== '\t')
1681 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1684 var
= savestring (arg
, p
- arg
);
1687 printf_filtered (_("\
1688 Setting environment variable \"%s\" to null value.\n"),
1690 set_in_environ (inferior_environ
, var
, "");
1693 set_in_environ (inferior_environ
, var
, val
);
1698 unset_environment_command (char *var
, int from_tty
)
1702 /* If there is no argument, delete all environment variables.
1703 Ask for confirmation if reading from the terminal. */
1704 if (!from_tty
|| query (_("Delete all environment variables? ")))
1706 free_environ (inferior_environ
);
1707 inferior_environ
= make_environ ();
1711 unset_in_environ (inferior_environ
, var
);
1714 /* Handle the execution path (PATH variable) */
1716 static const char path_var_name
[] = "PATH";
1719 path_info (char *args
, int from_tty
)
1721 puts_filtered ("Executable and object file path: ");
1722 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1723 puts_filtered ("\n");
1726 /* Add zero or more directories to the front of the execution path. */
1729 path_command (char *dirname
, int from_tty
)
1734 env
= get_in_environ (inferior_environ
, path_var_name
);
1735 /* Can be null if path is not set */
1738 exec_path
= xstrdup (env
);
1739 mod_path (dirname
, &exec_path
);
1740 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1743 path_info ((char *) NULL
, from_tty
);
1747 /* Print out the machine register regnum. If regnum is -1, print all
1748 registers (print_all == 1) or all non-float and non-vector
1749 registers (print_all == 0).
1751 For most machines, having all_registers_info() print the
1752 register(s) one per line is good enough. If a different format is
1753 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1754 regs), or there is an existing convention for showing all the
1755 registers, define the architecture method PRINT_REGISTERS_INFO to
1756 provide that format. */
1759 default_print_registers_info (struct gdbarch
*gdbarch
,
1760 struct ui_file
*file
,
1761 struct frame_info
*frame
,
1762 int regnum
, int print_all
)
1765 const int numregs
= gdbarch_num_regs (gdbarch
)
1766 + gdbarch_num_pseudo_regs (gdbarch
);
1767 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1769 for (i
= 0; i
< numregs
; i
++)
1771 /* Decide between printing all regs, non-float / vector regs, or
1777 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1782 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1792 /* If the register name is empty, it is undefined for this
1793 processor, so don't display anything. */
1794 if (gdbarch_register_name (gdbarch
, i
) == NULL
1795 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1798 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1799 print_spaces_filtered (15 - strlen (gdbarch_register_name
1800 (gdbarch
, i
)), file
);
1802 /* Get the data in raw format. */
1803 if (! frame_register_read (frame
, i
, buffer
))
1805 fprintf_filtered (file
, "*value not available*\n");
1809 /* If virtual format is floating, print it that way, and in raw
1811 if (TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_FLT
1812 || TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_DECFLOAT
)
1816 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1817 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1819 fprintf_filtered (file
, "\t(raw 0x");
1820 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
1823 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1826 idx
= register_size (gdbarch
, i
) - 1 - j
;
1827 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
1829 fprintf_filtered (file
, ")");
1833 /* Print the register in hex. */
1834 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1835 file
, 'x', 1, 0, Val_pretty_default
, current_language
);
1836 /* If not a vector register, print it also according to its
1838 if (TYPE_VECTOR (register_type (gdbarch
, i
)) == 0)
1840 fprintf_filtered (file
, "\t");
1841 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1842 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1846 fprintf_filtered (file
, "\n");
1851 registers_info (char *addr_exp
, int fpregs
)
1853 struct frame_info
*frame
;
1854 struct gdbarch
*gdbarch
;
1855 int regnum
, numregs
;
1858 if (!target_has_registers
)
1859 error (_("The program has no registers now."));
1860 frame
= get_selected_frame (NULL
);
1861 gdbarch
= get_frame_arch (frame
);
1865 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1870 while (*addr_exp
!= '\0')
1875 /* Keep skipping leading white space. */
1876 if (isspace ((*addr_exp
)))
1882 /* Discard any leading ``$''. Check that there is something
1883 resembling a register following it. */
1884 if (addr_exp
[0] == '$')
1886 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
1887 error (_("Missing register name"));
1889 /* Find the start/end of this register name/num/group. */
1891 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
1895 /* Figure out what we've found and display it. */
1897 /* A register name? */
1899 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
1902 /* User registers lie completely outside of the range of
1903 normal registers. Catch them early so that the target
1905 if (regnum
>= gdbarch_num_regs (gdbarch
)
1906 + gdbarch_num_pseudo_regs (gdbarch
))
1908 struct value
*val
= value_of_user_reg (regnum
, frame
);
1910 printf_filtered ("%s: ", start
);
1911 print_scalar_formatted (value_contents (val
),
1912 check_typedef (value_type (val
)),
1913 'x', 0, gdb_stdout
);
1914 printf_filtered ("\n");
1917 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1918 frame
, regnum
, fpregs
);
1923 /* A register number? (how portable is this one?). */
1926 int regnum
= strtol (start
, &endptr
, 0);
1929 && regnum
< gdbarch_num_regs (gdbarch
)
1930 + gdbarch_num_pseudo_regs (gdbarch
))
1932 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1933 frame
, regnum
, fpregs
);
1938 /* A register group? */
1940 struct reggroup
*group
;
1941 for (group
= reggroup_next (gdbarch
, NULL
);
1943 group
= reggroup_next (gdbarch
, group
))
1945 /* Don't bother with a length check. Should the user
1946 enter a short register group name, go with the first
1947 group that matches. */
1948 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
1955 regnum
< gdbarch_num_regs (gdbarch
)
1956 + gdbarch_num_pseudo_regs (gdbarch
);
1959 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1960 gdbarch_print_registers_info (gdbarch
,
1968 /* Nothing matched. */
1969 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
1974 all_registers_info (char *addr_exp
, int from_tty
)
1976 registers_info (addr_exp
, 1);
1980 nofp_registers_info (char *addr_exp
, int from_tty
)
1982 registers_info (addr_exp
, 0);
1986 print_vector_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1987 struct frame_info
*frame
, const char *args
)
1989 if (gdbarch_print_vector_info_p (gdbarch
))
1990 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
1994 int printed_something
= 0;
1997 regnum
< gdbarch_num_regs (gdbarch
)
1998 + gdbarch_num_pseudo_regs (gdbarch
);
2001 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2003 printed_something
= 1;
2004 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2007 if (!printed_something
)
2008 fprintf_filtered (file
, "No vector information\n");
2013 vector_info (char *args
, int from_tty
)
2015 if (!target_has_registers
)
2016 error (_("The program has no registers now."));
2018 print_vector_info (current_gdbarch
, gdb_stdout
,
2019 get_selected_frame (NULL
), args
);
2023 /* Used in `attach&' command. ARG is a point to an integer
2024 representing a process id. Proceed threads of this process iff
2025 they stopped due to debugger request, and when they did, they
2026 reported a clean stop (TARGET_SIGNAL_0). Do not proceed threads
2027 that have been explicitly been told to stop. */
2030 proceed_after_attach_callback (struct thread_info
*thread
,
2033 int pid
= * (int *) arg
;
2035 if (ptid_get_pid (thread
->ptid
) == pid
2036 && !is_exited (thread
->ptid
)
2037 && !is_executing (thread
->ptid
)
2038 && !thread
->stop_requested
2039 && thread
->stop_signal
== TARGET_SIGNAL_0
)
2041 switch_to_thread (thread
->ptid
);
2042 clear_proceed_status ();
2043 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2050 proceed_after_attach (int pid
)
2052 /* Don't error out if the current thread is running, because
2053 there may be other stopped threads. */
2054 struct cleanup
*old_chain
;
2056 /* Backup current thread and selected frame. */
2057 old_chain
= make_cleanup_restore_current_thread ();
2059 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2061 /* Restore selected ptid. */
2062 do_cleanups (old_chain
);
2067 * Should save/restore the tty state since it might be that the
2068 * program to be debugged was started on this tty and it wants
2069 * the tty in some state other than what we want. If it's running
2070 * on another terminal or without a terminal, then saving and
2071 * restoring the tty state is a harmless no-op.
2072 * This only needs to be done if we are attaching to a process.
2077 takes a program started up outside of gdb and ``attaches'' to it.
2078 This stops it cold in its tracks and allows us to start debugging it.
2079 and wait for the trace-trap that results from attaching. */
2082 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2085 char *full_exec_path
= NULL
;
2086 struct inferior
*inferior
;
2088 inferior
= current_inferior ();
2089 inferior
->stop_soon
= NO_STOP_QUIETLY
;
2091 /* If no exec file is yet known, try to determine it from the
2093 exec_file
= (char *) get_exec_file (0);
2096 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
2099 /* It's possible we don't have a full path, but rather just a
2100 filename. Some targets, such as HP-UX, don't provide the
2103 Attempt to qualify the filename against the source path.
2104 (If that fails, we'll just fall back on the original
2105 filename. Not much more we can do...)
2107 if (!source_full_path_of (exec_file
, &full_exec_path
))
2108 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
2110 exec_file_attach (full_exec_path
, from_tty
);
2111 symbol_file_add_main (full_exec_path
, from_tty
);
2116 reopen_exec_file ();
2120 /* Take any necessary post-attaching actions for this platform. */
2121 target_post_attach (PIDGET (inferior_ptid
));
2123 post_create_inferior (¤t_target
, from_tty
);
2125 /* Install inferior's terminal modes. */
2126 target_terminal_inferior ();
2130 /* The user requested an `attach&', so be sure to leave threads
2131 that didn't get a signal running. */
2133 /* Immediatelly resume all suspended threads of this inferior,
2134 and this inferior only. This should have no effect on
2135 already running threads. If a thread has been stopped with a
2136 signal, leave it be. */
2138 proceed_after_attach (inferior
->pid
);
2141 if (inferior_thread ()->stop_signal
== TARGET_SIGNAL_0
)
2143 clear_proceed_status ();
2144 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
2150 /* The user requested a plain `attach', so be sure to leave
2151 the inferior stopped. */
2153 if (target_can_async_p ())
2154 async_enable_stdin ();
2156 /* At least the current thread is already stopped. */
2158 /* In all-stop, by definition, all threads have to be already
2159 stopped at this point. In non-stop, however, although the
2160 selected thread is stopped, others may still be executing.
2161 Be sure to explicitly stop all threads of the process. This
2162 should have no effect on already stopped threads. */
2164 target_stop (pid_to_ptid (inferior
->pid
));
2166 /* Tell the user/frontend where we're stopped. */
2168 if (deprecated_attach_hook
)
2169 deprecated_attach_hook ();
2173 struct attach_command_continuation_args
2181 attach_command_continuation (void *args
)
2183 struct attach_command_continuation_args
*a
= args
;
2184 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2188 attach_command_continuation_free_args (void *args
)
2190 struct attach_command_continuation_args
*a
= args
;
2196 attach_command (char *args
, int from_tty
)
2199 char *full_exec_path
= NULL
;
2202 dont_repeat (); /* Not for the faint of heart */
2204 if (target_supports_multi_process ())
2205 /* Don't complain if we can be attached to multiple processes. */
2207 else if (target_has_execution
)
2209 if (query ("A program is being debugged already. Kill it? "))
2212 error (_("Not killed."));
2215 /* Clean up any leftovers from other runs. Some other things from
2216 this function should probably be moved into target_pre_inferior. */
2217 target_pre_inferior (from_tty
);
2219 if (non_stop
&& !target_supports_non_stop ())
2220 error (_("Cannot attach to this target in non-stop mode"));
2224 async_exec
= strip_bg_char (&args
);
2226 /* If we get a request for running in the bg but the target
2227 doesn't support it, error out. */
2228 if (async_exec
&& !target_can_async_p ())
2229 error (_("Asynchronous execution not supported on this target."));
2232 /* If we don't get a request of running in the bg, then we need
2233 to simulate synchronous (fg) execution. */
2234 if (!async_exec
&& target_can_async_p ())
2236 /* Simulate synchronous execution */
2237 async_disable_stdin ();
2240 target_attach (args
, from_tty
);
2242 /* Set up the "saved terminal modes" of the inferior
2243 based on what modes we are starting it with. */
2244 target_terminal_init ();
2246 /* Set up execution context to know that we should return from
2247 wait_for_inferior as soon as the target reports a stop. */
2248 init_wait_for_inferior ();
2249 clear_proceed_status ();
2253 /* If we find that the current thread isn't stopped, explicitly
2254 do so now, because we're going to install breakpoints and
2258 /* The user requested an `attach&'; stop just one thread. */
2259 target_stop (inferior_ptid
);
2261 /* The user requested an `attach', so stop all threads of this
2263 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2266 /* Some system don't generate traps when attaching to inferior.
2267 E.g. Mach 3 or GNU hurd. */
2268 if (!target_attach_no_wait
)
2270 struct inferior
*inferior
= current_inferior ();
2272 /* Careful here. See comments in inferior.h. Basically some
2273 OSes don't ignore SIGSTOPs on continue requests anymore. We
2274 need a way for handle_inferior_event to reset the stop_signal
2275 variable after an attach, and this is what
2276 STOP_QUIETLY_NO_SIGSTOP is for. */
2277 inferior
->stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2279 if (target_can_async_p ())
2281 /* sync_execution mode. Wait for stop. */
2282 struct attach_command_continuation_args
*a
;
2284 a
= xmalloc (sizeof (*a
));
2285 a
->args
= xstrdup (args
);
2286 a
->from_tty
= from_tty
;
2287 a
->async_exec
= async_exec
;
2288 add_continuation (inferior_thread (),
2289 attach_command_continuation
, a
,
2290 attach_command_continuation_free_args
);
2294 wait_for_inferior (0);
2297 attach_command_post_wait (args
, from_tty
, async_exec
);
2302 * takes a program previously attached to and detaches it.
2303 * The program resumes execution and will no longer stop
2304 * on signals, etc. We better not have left any breakpoints
2305 * in the program or it'll die when it hits one. For this
2306 * to work, it may be necessary for the process to have been
2307 * previously attached. It *might* work if the program was
2308 * started via the normal ptrace (PTRACE_TRACEME).
2312 detach_command (char *args
, int from_tty
)
2314 dont_repeat (); /* Not for the faint of heart. */
2315 target_detach (args
, from_tty
);
2316 no_shared_libraries (NULL
, from_tty
);
2318 /* If the current target interface claims there's still execution,
2319 then don't mess with threads of other processes. */
2320 if (!target_has_execution
)
2321 init_thread_list ();
2323 if (deprecated_detach_hook
)
2324 deprecated_detach_hook ();
2327 /* Disconnect from the current target without resuming it (leaving it
2328 waiting for a debugger).
2330 We'd better not have left any breakpoints in the program or the
2331 next debugger will get confused. Currently only supported for some
2332 remote targets, since the normal attach mechanisms don't work on
2333 stopped processes on some native platforms (e.g. GNU/Linux). */
2336 disconnect_command (char *args
, int from_tty
)
2338 dont_repeat (); /* Not for the faint of heart */
2339 target_disconnect (args
, from_tty
);
2340 no_shared_libraries (NULL
, from_tty
);
2341 init_thread_list ();
2342 if (deprecated_detach_hook
)
2343 deprecated_detach_hook ();
2347 interrupt_target_1 (int all_threads
)
2351 ptid
= minus_one_ptid
;
2353 ptid
= inferior_ptid
;
2356 /* Tag the thread as having been explicitly requested to stop, so
2357 other parts of gdb know not to resume this thread automatically,
2358 if it was stopped due to an internal event. Limit this to
2359 non-stop mode, as when debugging a multi-threaded application in
2360 all-stop mode, we will only get one stop event --- it's undefined
2361 which thread will report the event. */
2363 set_stop_requested (ptid
, 1);
2366 /* Stop the execution of the target while running in async mode, in
2367 the backgound. In all-stop, stop the whole process. In non-stop
2368 mode, stop the current thread only by default, or stop all threads
2369 if the `-a' switch is used. */
2371 /* interrupt [-a] */
2373 interrupt_target_command (char *args
, int from_tty
)
2375 if (target_can_async_p ())
2377 int all_threads
= 0;
2379 dont_repeat (); /* Not for the faint of heart */
2382 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2385 if (!non_stop
&& all_threads
)
2386 error (_("-a is meaningless in all-stop mode."));
2388 interrupt_target_1 (all_threads
);
2393 print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2394 struct frame_info
*frame
, const char *args
)
2396 if (gdbarch_print_float_info_p (gdbarch
))
2397 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2401 int printed_something
= 0;
2404 regnum
< gdbarch_num_regs (gdbarch
)
2405 + gdbarch_num_pseudo_regs (gdbarch
);
2408 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2410 printed_something
= 1;
2411 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2414 if (!printed_something
)
2415 fprintf_filtered (file
, "\
2416 No floating-point info available for this processor.\n");
2421 float_info (char *args
, int from_tty
)
2423 if (!target_has_registers
)
2424 error (_("The program has no registers now."));
2426 print_float_info (current_gdbarch
, gdb_stdout
,
2427 get_selected_frame (NULL
), args
);
2431 unset_command (char *args
, int from_tty
)
2433 printf_filtered (_("\
2434 \"unset\" must be followed by the name of an unset subcommand.\n"));
2435 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2439 _initialize_infcmd (void)
2441 struct cmd_list_element
*c
= NULL
;
2443 /* add the filename of the terminal connected to inferior I/O */
2444 add_setshow_filename_cmd ("inferior-tty", class_run
,
2445 &inferior_io_terminal
, _("\
2446 Set terminal for future runs of program being debugged."), _("\
2447 Show terminal for future runs of program being debugged."), _("\
2448 Usage: set inferior-tty /dev/pts/1"), NULL
, NULL
, &setlist
, &showlist
);
2449 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2451 add_setshow_optional_filename_cmd ("args", class_run
,
2452 &inferior_args
, _("\
2453 Set argument list to give program being debugged when it is started."), _("\
2454 Show argument list to give program being debugged when it is started."), _("\
2455 Follow this command with any number of args, to be passed to the program."),
2458 &setlist
, &showlist
);
2460 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2461 The environment to give the program, or one variable's value.\n\
2462 With an argument VAR, prints the value of environment variable VAR to\n\
2463 give the program being debugged. With no arguments, prints the entire\n\
2464 environment to be given to the program."), &showlist
);
2465 set_cmd_completer (c
, noop_completer
);
2467 add_prefix_cmd ("unset", no_class
, unset_command
,
2468 _("Complement to certain \"set\" commands."),
2469 &unsetlist
, "unset ", 0, &cmdlist
);
2471 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2472 Cancel environment variable VAR for the program.\n\
2473 This does not affect the program until the next \"run\" command."),
2475 set_cmd_completer (c
, noop_completer
);
2477 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2478 Set environment variable value to give the program.\n\
2479 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2480 VALUES of environment variables are uninterpreted strings.\n\
2481 This does not affect the program until the next \"run\" command."),
2483 set_cmd_completer (c
, noop_completer
);
2485 c
= add_com ("path", class_files
, path_command
, _("\
2486 Add directory DIR(s) to beginning of search path for object files.\n\
2487 $cwd in the path means the current working directory.\n\
2488 This path is equivalent to the $PATH shell variable. It is a list of\n\
2489 directories, separated by colons. These directories are searched to find\n\
2490 fully linked executable files and separately compiled object files as needed."));
2491 set_cmd_completer (c
, filename_completer
);
2493 c
= add_cmd ("paths", no_class
, path_info
, _("\
2494 Current search path for finding object files.\n\
2495 $cwd in the path means the current working directory.\n\
2496 This path is equivalent to the $PATH shell variable. It is a list of\n\
2497 directories, separated by colons. These directories are searched to find\n\
2498 fully linked executable files and separately compiled object files as needed."),
2500 set_cmd_completer (c
, noop_completer
);
2502 add_com ("attach", class_run
, attach_command
, _("\
2503 Attach to a process or file outside of GDB.\n\
2504 This command attaches to another target, of the same type as your last\n\
2505 \"target\" command (\"info files\" will show your target stack).\n\
2506 The command may take as argument a process id or a device file.\n\
2507 For a process id, you must have permission to send the process a signal,\n\
2508 and it must have the same effective uid as the debugger.\n\
2509 When using \"attach\" with a process id, the debugger finds the\n\
2510 program running in the process, looking first in the current working\n\
2511 directory, or (if not found there) using the source file search path\n\
2512 (see the \"directory\" command). You can also use the \"file\" command\n\
2513 to specify the program, and to load its symbol table."));
2515 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2516 Detach a process or file previously attached.\n\
2517 If a process, it is no longer traced, and it continues its execution. If\n\
2518 you were debugging a file, the file is closed and gdb no longer accesses it."),
2519 &detachlist
, "detach ", 0, &cmdlist
);
2521 add_com ("disconnect", class_run
, disconnect_command
, _("\
2522 Disconnect from a target.\n\
2523 The target will wait for another debugger to connect. Not available for\n\
2526 add_com ("signal", class_run
, signal_command
, _("\
2527 Continue program giving it signal specified by the argument.\n\
2528 An argument of \"0\" means continue program without giving it a signal."));
2530 add_com ("stepi", class_run
, stepi_command
, _("\
2531 Step one instruction exactly.\n\
2532 Argument N means do this N times (or till program stops for another reason)."));
2533 add_com_alias ("si", "stepi", class_alias
, 0);
2535 add_com ("nexti", class_run
, nexti_command
, _("\
2536 Step one instruction, but proceed through subroutine calls.\n\
2537 Argument N means do this N times (or till program stops for another reason)."));
2538 add_com_alias ("ni", "nexti", class_alias
, 0);
2540 add_com ("finish", class_run
, finish_command
, _("\
2541 Execute until selected stack frame returns.\n\
2542 Upon return, the value returned is printed and put in the value history."));
2543 add_com_alias ("fin", "finish", class_run
, 1);
2545 add_com ("next", class_run
, next_command
, _("\
2546 Step program, proceeding through subroutine calls.\n\
2547 Like the \"step\" command as long as subroutine calls do not happen;\n\
2548 when they do, the call is treated as one instruction.\n\
2549 Argument N means do this N times (or till program stops for another reason)."));
2550 add_com_alias ("n", "next", class_run
, 1);
2552 add_com_alias ("S", "next", class_run
, 1);
2554 add_com ("step", class_run
, step_command
, _("\
2555 Step program until it reaches a different source line.\n\
2556 Argument N means do this N times (or till program stops for another reason)."));
2557 add_com_alias ("s", "step", class_run
, 1);
2559 c
= add_com ("until", class_run
, until_command
, _("\
2560 Execute until the program reaches a source line greater than the current\n\
2561 or a specified location (same args as break command) within the current frame."));
2562 set_cmd_completer (c
, location_completer
);
2563 add_com_alias ("u", "until", class_run
, 1);
2565 c
= add_com ("advance", class_run
, advance_command
, _("\
2566 Continue the program up to the given location (same form as args for break command).\n\
2567 Execution will also stop upon exit from the current stack frame."));
2568 set_cmd_completer (c
, location_completer
);
2570 c
= add_com ("jump", class_run
, jump_command
, _("\
2571 Continue program being debugged at specified line or address.\n\
2572 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2573 for an address to start at."));
2574 set_cmd_completer (c
, location_completer
);
2578 c
= add_com ("go", class_run
, go_command
, _("\
2579 Usage: go <location>\n\
2580 Continue program being debugged, stopping at specified line or \n\
2582 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2583 expression for an address to start at.\n\
2584 This command is a combination of tbreak and jump."));
2585 set_cmd_completer (c
, location_completer
);
2589 add_com_alias ("g", "go", class_run
, 1);
2591 c
= add_com ("continue", class_run
, continue_command
, _("\
2592 Continue program being debugged, after signal or breakpoint.\n\
2593 If proceeding from breakpoint, a number N may be used as an argument,\n\
2594 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2595 the breakpoint won't break until the Nth time it is reached).\n\
2597 If non-stop mode is enabled, continue only the current thread,\n\
2598 otherwise all the threads in the program are continued. To \n\
2599 continue all stopped threads in non-stop mode, use the -a option.\n\
2600 Specifying -a and an ignore count simultaneously is an error."));
2601 add_com_alias ("c", "cont", class_run
, 1);
2602 add_com_alias ("fg", "cont", class_run
, 1);
2604 c
= add_com ("run", class_run
, run_command
, _("\
2605 Start debugged program. You may specify arguments to give it.\n\
2606 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2607 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2608 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2609 To cancel previous arguments and run with no arguments,\n\
2610 use \"set args\" without arguments."));
2611 set_cmd_completer (c
, filename_completer
);
2612 add_com_alias ("r", "run", class_run
, 1);
2614 add_com ("R", class_run
, run_no_args_command
,
2615 _("Start debugged program with no arguments."));
2617 c
= add_com ("start", class_run
, start_command
, _("\
2618 Run the debugged program until the beginning of the main procedure.\n\
2619 You may specify arguments to give to your program, just as with the\n\
2620 \"run\" command."));
2621 set_cmd_completer (c
, filename_completer
);
2623 c
= add_com ("interrupt", class_run
, interrupt_target_command
,
2624 _("Interrupt the execution of the debugged program.\n\
2625 If non-stop mode is enabled, interrupt only the current thread,\n\
2626 otherwise all the threads in the program are stopped. To \n\
2627 interrupt all running threads in non-stop mode, use the -a option."));
2629 add_info ("registers", nofp_registers_info
, _("\
2630 List of integer registers and their contents, for selected stack frame.\n\
2631 Register name as argument means describe only that register."));
2632 add_info_alias ("r", "registers", 1);
2635 add_com ("lr", class_info
, nofp_registers_info
, _("\
2636 List of integer registers and their contents, for selected stack frame.\n\
2637 Register name as argument means describe only that register."));
2638 add_info ("all-registers", all_registers_info
, _("\
2639 List of all registers and their contents, for selected stack frame.\n\
2640 Register name as argument means describe only that register."));
2642 add_info ("program", program_info
,
2643 _("Execution status of the program."));
2645 add_info ("float", float_info
,
2646 _("Print the status of the floating point unit\n"));
2648 add_info ("vector", vector_info
,
2649 _("Print the status of the vector unit\n"));
2651 inferior_environ
= make_environ ();
2652 init_environ (inferior_environ
);