1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5 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 2 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
26 #include "gdb_string.h"
40 #include "completer.h"
42 #include "event-top.h"
43 #include "parser-defs.h"
45 #include "reggroups.h"
49 #include "gdb_assert.h"
52 /* Functions exported for general use, in inferior.h: */
54 void all_registers_info (char *, int);
56 void registers_info (char *, int);
58 void nexti_command (char *, int);
60 void stepi_command (char *, int);
62 void continue_command (char *, int);
64 void interrupt_target_command (char *args
, int from_tty
);
66 /* Local functions: */
68 static void nofp_registers_info (char *, int);
70 static void print_return_value (int struct_return
, struct type
*value_type
);
72 static void finish_command_continuation (struct continuation_arg
*);
74 static void until_next_command (int);
76 static void until_command (char *, int);
78 static void path_info (char *, int);
80 static void path_command (char *, int);
82 static void unset_command (char *, int);
84 static void float_info (char *, int);
86 static void detach_command (char *, int);
88 static void disconnect_command (char *, int);
90 static void unset_environment_command (char *, int);
92 static void set_environment_command (char *, int);
94 static void environment_info (char *, int);
96 static void program_info (char *, int);
98 static void finish_command (char *, int);
100 static void signal_command (char *, int);
102 static void jump_command (char *, int);
104 static void step_1 (int, int, char *);
105 static void step_once (int skip_subroutines
, int single_inst
, int count
);
106 static void step_1_continuation (struct continuation_arg
*arg
);
108 static void next_command (char *, int);
110 static void step_command (char *, int);
112 static void run_command (char *, int);
114 static void run_no_args_command (char *args
, int from_tty
);
116 static void go_command (char *line_no
, int from_tty
);
118 static int strip_bg_char (char **);
120 void _initialize_infcmd (void);
122 #define GO_USAGE "Usage: go <location>\n"
124 #define ERROR_NO_INFERIOR \
125 if (!target_has_execution) error (_("The program is not being run."));
127 /* String containing arguments to give to the program, separated by spaces.
128 Empty string (pointer to '\0') means no args. */
130 static char *inferior_args
;
132 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
133 then we must compute INFERIOR_ARGS from this (via the target). */
135 static int inferior_argc
;
136 static char **inferior_argv
;
138 /* File name for default use for standard in/out in the inferior. */
140 static char *inferior_io_terminal
;
142 /* Pid of our debugged inferior, or 0 if no inferior now.
143 Since various parts of infrun.c test this to see whether there is a program
144 being debugged it should be nonzero (currently 3 is used) for remote
147 ptid_t inferior_ptid
;
149 /* Last signal that the inferior received (why it stopped). */
151 enum target_signal stop_signal
;
153 /* Address at which inferior stopped. */
157 /* Chain containing status of breakpoint(s) that we have stopped at. */
161 /* Flag indicating that a command has proceeded the inferior past the
162 current breakpoint. */
164 int breakpoint_proceeded
;
166 /* Nonzero if stopped due to a step command. */
170 /* Nonzero if stopped due to completion of a stack dummy routine. */
172 int stop_stack_dummy
;
174 /* Nonzero if stopped due to a random (unexpected) signal in inferior
177 int stopped_by_random_signal
;
179 /* Range to single step within.
180 If this is nonzero, respond to a single-step signal
181 by continuing to step if the pc is in this range. */
183 CORE_ADDR step_range_start
; /* Inclusive */
184 CORE_ADDR step_range_end
; /* Exclusive */
186 /* Stack frame address as of when stepping command was issued.
187 This is how we know when we step into a subroutine call,
188 and how to set the frame for the breakpoint used to step out. */
190 struct frame_id step_frame_id
;
192 enum step_over_calls_kind step_over_calls
;
194 /* If stepping, nonzero means step count is > 1
195 so don't print frame next time inferior stops
196 if it stops due to stepping. */
200 /* Environment to use for running inferior,
201 in format described in environ.h. */
203 struct gdb_environ
*inferior_environ
;
205 /* Accessor routines. */
208 set_inferior_io_terminal (const char *terminal_name
)
210 if (inferior_io_terminal
)
211 xfree (inferior_io_terminal
);
214 inferior_io_terminal
= NULL
;
216 inferior_io_terminal
= savestring (terminal_name
, strlen (terminal_name
));
220 get_inferior_io_terminal (void)
222 return inferior_io_terminal
;
226 get_inferior_args (void)
228 if (inferior_argc
!= 0)
232 n
= gdbarch_construct_inferior_arguments (current_gdbarch
,
233 inferior_argc
, inferior_argv
);
234 old
= set_inferior_args (n
);
238 if (inferior_args
== NULL
)
239 inferior_args
= xstrdup ("");
241 return inferior_args
;
245 set_inferior_args (char *newargs
)
247 char *saved_args
= inferior_args
;
249 inferior_args
= newargs
;
257 set_inferior_args_vector (int argc
, char **argv
)
259 inferior_argc
= argc
;
260 inferior_argv
= argv
;
263 /* Notice when `set args' is run. */
265 notice_args_set (char *args
, int from_tty
, struct cmd_list_element
*c
)
271 /* Notice when `show args' is run. */
273 notice_args_read (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
, const char *value
)
276 deprecated_show_value_hack (file
, from_tty
, c
, value
);
277 /* Might compute the value. */
278 get_inferior_args ();
282 /* Compute command-line string given argument vector. This does the
283 same shell processing as fork_inferior. */
285 construct_inferior_arguments (struct gdbarch
*gdbarch
, int argc
, char **argv
)
289 if (STARTUP_WITH_SHELL
)
291 /* This holds all the characters considered special to the
292 typical Unix shells. We include `^' because the SunOS
293 /bin/sh treats it as a synonym for `|'. */
294 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
299 /* We over-compute the size. It shouldn't matter. */
300 for (i
= 0; i
< argc
; ++i
)
301 length
+= 2 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
303 result
= (char *) xmalloc (length
);
306 for (i
= 0; i
< argc
; ++i
)
311 /* Need to handle empty arguments specially. */
312 if (argv
[i
][0] == '\0')
319 for (cp
= argv
[i
]; *cp
; ++cp
)
321 if (strchr (special
, *cp
) != NULL
)
331 /* In this case we can't handle arguments that contain spaces,
332 tabs, or newlines -- see breakup_args(). */
336 for (i
= 0; i
< argc
; ++i
)
338 char *cp
= strchr (argv
[i
], ' ');
340 cp
= strchr (argv
[i
], '\t');
342 cp
= strchr (argv
[i
], '\n');
344 error (_("can't handle command-line argument containing whitespace"));
345 length
+= strlen (argv
[i
]) + 1;
348 result
= (char *) xmalloc (length
);
350 for (i
= 0; i
< argc
; ++i
)
353 strcat (result
, " ");
354 strcat (result
, argv
[i
]);
362 /* This function detects whether or not a '&' character (indicating
363 background execution) has been added as *the last* of the arguments ARGS
364 of a command. If it has, it removes it and returns 1. Otherwise it
365 does nothing and returns 0. */
367 strip_bg_char (char **args
)
371 p
= strchr (*args
, '&');
375 if (p
== (*args
+ strlen (*args
) - 1))
377 if (strlen (*args
) > 1)
381 while (*p
== ' ' || *p
== '\t');
393 tty_command (char *file
, int from_tty
)
396 error_no_arg (_("terminal name for running target process"));
398 set_inferior_io_terminal (file
);
401 /* Common actions to take after creating any sort of inferior, by any
402 means (running, attaching, connecting, et cetera). The target
403 should be stopped. */
406 post_create_inferior (struct target_ops
*target
, int from_tty
)
410 /* Sometimes the platform-specific hook loads initial shared
411 libraries, and sometimes it doesn't. Try to do so first, so
412 that we can add them with the correct value for FROM_TTY. */
414 SOLIB_ADD (NULL
, from_tty
, target
, auto_solib_add
);
416 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
419 /* Create the hooks to handle shared library load and unload
421 #ifdef SOLIB_CREATE_INFERIOR_HOOK
422 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
424 solib_create_inferior_hook ();
427 /* Enable any breakpoints which were disabled when the
428 underlying shared library was deleted. */
429 re_enable_breakpoints_in_shlibs ();
432 observer_notify_inferior_created (target
, from_tty
);
435 /* Kill the inferior if already running. This function is designed
436 to be called when we are about to start the execution of the program
437 from the beginning. Ask the user to confirm that he wants to restart
438 the program being debugged when FROM_TTY is non-null. */
441 kill_if_already_running (int from_tty
)
443 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
446 && !query ("The program being debugged has been started already.\n\
447 Start it from the beginning? "))
448 error (_("Program not restarted."));
450 #if defined(SOLIB_RESTART)
453 init_wait_for_inferior ();
457 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
458 a temporary breakpoint at the begining of the main program before
459 running the program. */
462 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
468 kill_if_already_running (from_tty
);
469 clear_breakpoint_hit_counts ();
471 /* Purge old solib objfiles. */
472 objfile_purge_solibs ();
474 do_run_cleanups (NULL
);
476 /* The comment here used to read, "The exec file is re-read every
477 time we do a generic_mourn_inferior, so we just have to worry
478 about the symbol file." The `generic_mourn_inferior' function
479 gets called whenever the program exits. However, suppose the
480 program exits, and *then* the executable file changes? We need
481 to check again here. Since reopen_exec_file doesn't do anything
482 if the timestamp hasn't changed, I don't see the harm. */
486 /* Insert the temporary breakpoint if a location was specified. */
488 tbreak_command (main_name (), 0);
490 exec_file
= (char *) get_exec_file (0);
492 /* We keep symbols from add-symbol-file, on the grounds that the
493 user might want to add some symbols before running the program
494 (right?). But sometimes (dynamic loading where the user manually
495 introduces the new symbols with add-symbol-file), the code which
496 the symbols describe does not persist between runs. Currently
497 the user has to manually nuke all symbols between runs if they
498 want them to go away (PR 2207). This is probably reasonable. */
502 if (target_can_async_p ())
503 async_disable_stdin ();
507 int async_exec
= strip_bg_char (&args
);
509 /* If we get a request for running in the bg but the target
510 doesn't support it, error out. */
511 if (async_exec
&& !target_can_async_p ())
512 error (_("Asynchronous execution not supported on this target."));
514 /* If we don't get a request of running in the bg, then we need
515 to simulate synchronous (fg) execution. */
516 if (!async_exec
&& target_can_async_p ())
518 /* Simulate synchronous execution */
519 async_disable_stdin ();
522 /* If there were other args, beside '&', process them. */
525 char *old_args
= set_inferior_args (xstrdup (args
));
532 ui_out_field_string (uiout
, NULL
, "Starting program");
533 ui_out_text (uiout
, ": ");
535 ui_out_field_string (uiout
, "execfile", exec_file
);
536 ui_out_spaces (uiout
, 1);
537 /* We call get_inferior_args() because we might need to compute
539 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
540 ui_out_text (uiout
, "\n");
541 ui_out_flush (uiout
);
544 /* We call get_inferior_args() because we might need to compute
546 target_create_inferior (exec_file
, get_inferior_args (),
547 environ_vector (inferior_environ
), from_tty
);
549 post_create_inferior (¤t_target
, from_tty
);
551 /* Start the target running. */
552 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
557 run_command (char *args
, int from_tty
)
559 run_command_1 (args
, from_tty
, 0);
563 run_no_args_command (char *args
, int from_tty
)
565 char *old_args
= set_inferior_args (xstrdup (""));
570 /* Start the execution of the program up until the beginning of the main
574 start_command (char *args
, int from_tty
)
576 /* Some languages such as Ada need to search inside the program
577 minimal symbols for the location where to put the temporary
578 breakpoint before starting. */
579 if (!have_minimal_symbols ())
580 error (_("No symbol table loaded. Use the \"file\" command."));
582 /* Run the program until reaching the main procedure... */
583 run_command_1 (args
, from_tty
, 1);
587 continue_command (char *proc_count_exp
, int from_tty
)
592 /* Find out whether we must run in the background. */
593 if (proc_count_exp
!= NULL
)
594 async_exec
= strip_bg_char (&proc_count_exp
);
596 /* If we must run in the background, but the target can't do it,
598 if (async_exec
&& !target_can_async_p ())
599 error (_("Asynchronous execution not supported on this target."));
601 /* If we are not asked to run in the bg, then prepare to run in the
602 foreground, synchronously. */
603 if (!async_exec
&& target_can_async_p ())
605 /* Simulate synchronous execution */
606 async_disable_stdin ();
609 /* If have argument (besides '&'), set proceed count of breakpoint
611 if (proc_count_exp
!= NULL
)
613 bpstat bs
= stop_bpstat
;
614 int num
= bpstat_num (&bs
);
615 if (num
== 0 && from_tty
)
618 ("Not stopped at any breakpoint; argument ignored.\n");
622 set_ignore_count (num
,
623 parse_and_eval_long (proc_count_exp
) - 1,
625 /* set_ignore_count prints a message ending with a period.
626 So print two spaces before "Continuing.". */
628 printf_filtered (" ");
629 num
= bpstat_num (&bs
);
634 printf_filtered (_("Continuing.\n"));
636 clear_proceed_status ();
638 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
641 /* Step until outside of current statement. */
644 step_command (char *count_string
, int from_tty
)
646 step_1 (0, 0, count_string
);
649 /* Likewise, but skip over subroutine calls as if single instructions. */
652 next_command (char *count_string
, int from_tty
)
654 step_1 (1, 0, count_string
);
657 /* Likewise, but step only one instruction. */
660 stepi_command (char *count_string
, int from_tty
)
662 step_1 (0, 1, count_string
);
666 nexti_command (char *count_string
, int from_tty
)
668 step_1 (1, 1, count_string
);
672 disable_longjmp_breakpoint_cleanup (void *ignore
)
674 disable_longjmp_breakpoint ();
678 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
681 struct frame_info
*frame
;
682 struct cleanup
*cleanups
= 0;
688 async_exec
= strip_bg_char (&count_string
);
690 /* If we get a request for running in the bg but the target
691 doesn't support it, error out. */
692 if (async_exec
&& !target_can_async_p ())
693 error (_("Asynchronous execution not supported on this target."));
695 /* If we don't get a request of running in the bg, then we need
696 to simulate synchronous (fg) execution. */
697 if (!async_exec
&& target_can_async_p ())
699 /* Simulate synchronous execution */
700 async_disable_stdin ();
703 count
= count_string
? parse_and_eval_long (count_string
) : 1;
705 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
707 enable_longjmp_breakpoint ();
708 if (!target_can_async_p ())
709 cleanups
= make_cleanup (disable_longjmp_breakpoint_cleanup
, 0 /*ignore*/);
711 make_exec_cleanup (disable_longjmp_breakpoint_cleanup
, 0 /*ignore*/);
714 /* In synchronous case, all is well, just use the regular for loop. */
715 if (!target_can_async_p ())
717 for (; count
> 0; count
--)
719 clear_proceed_status ();
721 frame
= get_current_frame ();
722 if (!frame
) /* Avoid coredump here. Why tho? */
723 error (_("No current frame"));
724 step_frame_id
= get_frame_id (frame
);
728 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
729 if (step_range_end
== 0)
732 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
733 &step_range_end
) == 0)
734 error (_("Cannot find bounds of current function"));
736 target_terminal_ours ();
737 printf_filtered (_("\
738 Single stepping until exit from function %s, \n\
739 which has no line number information.\n"), name
);
744 /* Say we are stepping, but stop after one insn whatever it does. */
745 step_range_start
= step_range_end
= 1;
746 if (!skip_subroutines
)
748 Don't step over function calls, not even to functions lacking
750 step_over_calls
= STEP_OVER_NONE
;
753 if (skip_subroutines
)
754 step_over_calls
= STEP_OVER_ALL
;
756 step_multi
= (count
> 1);
757 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
763 if (!single_inst
|| skip_subroutines
)
764 do_cleanups (cleanups
);
767 /* In case of asynchronous target things get complicated, do only
768 one step for now, before returning control to the event loop. Let
769 the continuation figure out how many other steps we need to do,
770 and handle them one at the time, through step_once(). */
773 if (target_can_async_p ())
774 step_once (skip_subroutines
, single_inst
, count
);
778 /* Called after we are done with one step operation, to check whether
779 we need to step again, before we print the prompt and return control
780 to the user. If count is > 1, we will need to do one more call to
781 proceed(), via step_once(). Basically it is like step_once and
782 step_1_continuation are co-recursive. */
784 step_1_continuation (struct continuation_arg
*arg
)
787 int skip_subroutines
;
790 skip_subroutines
= arg
->data
.integer
;
791 single_inst
= arg
->next
->data
.integer
;
792 count
= arg
->next
->next
->data
.integer
;
795 step_once (skip_subroutines
, single_inst
, count
- 1);
797 if (!single_inst
|| skip_subroutines
)
798 do_exec_cleanups (ALL_CLEANUPS
);
801 /* Do just one step operation. If count >1 we will have to set up a
802 continuation to be done after the target stops (after this one
803 step). This is useful to implement the 'step n' kind of commands, in
804 case of asynchronous targets. We had to split step_1 into two parts,
805 one to be done before proceed() and one afterwards. This function is
806 called in case of step n with n>1, after the first step operation has
809 step_once (int skip_subroutines
, int single_inst
, int count
)
811 struct continuation_arg
*arg1
;
812 struct continuation_arg
*arg2
;
813 struct continuation_arg
*arg3
;
814 struct frame_info
*frame
;
818 clear_proceed_status ();
820 frame
= get_current_frame ();
821 if (!frame
) /* Avoid coredump here. Why tho? */
822 error (_("No current frame"));
823 step_frame_id
= get_frame_id (frame
);
827 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
829 /* If we have no line info, switch to stepi mode. */
830 if (step_range_end
== 0 && step_stop_if_no_debug
)
832 step_range_start
= step_range_end
= 1;
834 else if (step_range_end
== 0)
837 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
838 &step_range_end
) == 0)
839 error (_("Cannot find bounds of current function"));
841 target_terminal_ours ();
842 printf_filtered (_("\
843 Single stepping until exit from function %s, \n\
844 which has no line number information.\n"), name
);
849 /* Say we are stepping, but stop after one insn whatever it does. */
850 step_range_start
= step_range_end
= 1;
851 if (!skip_subroutines
)
853 Don't step over function calls, not even to functions lacking
855 step_over_calls
= STEP_OVER_NONE
;
858 if (skip_subroutines
)
859 step_over_calls
= STEP_OVER_ALL
;
861 step_multi
= (count
> 1);
863 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
865 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
867 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
869 arg1
->data
.integer
= skip_subroutines
;
871 arg2
->data
.integer
= single_inst
;
873 arg3
->data
.integer
= count
;
874 add_intermediate_continuation (step_1_continuation
, arg1
);
875 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
880 /* Continue program at specified address. */
883 jump_command (char *arg
, int from_tty
)
886 struct symtabs_and_lines sals
;
887 struct symtab_and_line sal
;
894 /* Find out whether we must run in the background. */
896 async_exec
= strip_bg_char (&arg
);
898 /* If we must run in the background, but the target can't do it,
900 if (async_exec
&& !target_can_async_p ())
901 error (_("Asynchronous execution not supported on this target."));
903 /* If we are not asked to run in the bg, then prepare to run in the
904 foreground, synchronously. */
905 if (!async_exec
&& target_can_async_p ())
907 /* Simulate synchronous execution */
908 async_disable_stdin ();
912 error_no_arg (_("starting address"));
914 sals
= decode_line_spec_1 (arg
, 1);
917 error (_("Unreasonable jump request"));
923 if (sal
.symtab
== 0 && sal
.pc
== 0)
924 error (_("No source file has been specified."));
926 resolve_sal_pc (&sal
); /* May error out */
928 /* See if we are trying to jump to another function. */
929 fn
= get_frame_function (get_current_frame ());
930 sfn
= find_pc_function (sal
.pc
);
931 if (fn
!= NULL
&& sfn
!= fn
)
933 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
934 SYMBOL_PRINT_NAME (fn
)))
936 error (_("Not confirmed."));
943 fixup_symbol_section (sfn
, 0);
944 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn
)) &&
945 !section_is_mapped (SYMBOL_BFD_SECTION (sfn
)))
947 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
949 error (_("Not confirmed."));
959 printf_filtered (_("Continuing at "));
960 deprecated_print_address_numeric (addr
, 1, gdb_stdout
);
961 printf_filtered (".\n");
964 clear_proceed_status ();
965 proceed (addr
, TARGET_SIGNAL_0
, 0);
969 /* Go to line or address in current procedure */
971 go_command (char *line_no
, int from_tty
)
973 if (line_no
== (char *) NULL
|| !*line_no
)
974 printf_filtered (GO_USAGE
);
977 tbreak_command (line_no
, from_tty
);
978 jump_command (line_no
, from_tty
);
983 /* Continue program giving it specified signal. */
986 signal_command (char *signum_exp
, int from_tty
)
988 enum target_signal oursig
;
990 dont_repeat (); /* Too dangerous. */
994 error_no_arg (_("signal number"));
996 /* It would be even slicker to make signal names be valid expressions,
997 (the type could be "enum $signal" or some such), then the user could
998 assign them to convenience variables. */
999 oursig
= target_signal_from_name (signum_exp
);
1001 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1003 /* No, try numeric. */
1004 int num
= parse_and_eval_long (signum_exp
);
1007 oursig
= TARGET_SIGNAL_0
;
1009 oursig
= target_signal_from_command (num
);
1014 if (oursig
== TARGET_SIGNAL_0
)
1015 printf_filtered (_("Continuing with no signal.\n"));
1017 printf_filtered (_("Continuing with signal %s.\n"),
1018 target_signal_to_name (oursig
));
1021 clear_proceed_status ();
1022 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1023 FIXME: Neither should "signal foo" but when I tried passing
1024 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1025 tried to track down yet. */
1026 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
1029 /* Proceed until we reach a different source line with pc greater than
1030 our current one or exit the function. We skip calls in both cases.
1032 Note that eventually this command should probably be changed so
1033 that only source lines are printed out when we hit the breakpoint
1034 we set. This may involve changes to wait_for_inferior and the
1035 proceed status code. */
1038 until_next_command (int from_tty
)
1040 struct frame_info
*frame
;
1042 struct symbol
*func
;
1043 struct symtab_and_line sal
;
1045 clear_proceed_status ();
1047 frame
= get_current_frame ();
1049 /* Step until either exited from this function or greater
1050 than the current line (if in symbolic section) or pc (if
1054 func
= find_pc_function (pc
);
1058 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1060 if (msymbol
== NULL
)
1061 error (_("Execution is not within a known function."));
1063 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1064 step_range_end
= pc
;
1068 sal
= find_pc_line (pc
, 0);
1070 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1071 step_range_end
= sal
.end
;
1074 step_over_calls
= STEP_OVER_ALL
;
1075 step_frame_id
= get_frame_id (frame
);
1077 step_multi
= 0; /* Only one call to proceed */
1079 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1083 until_command (char *arg
, int from_tty
)
1087 if (!target_has_execution
)
1088 error (_("The program is not running."));
1090 /* Find out whether we must run in the background. */
1092 async_exec
= strip_bg_char (&arg
);
1094 /* If we must run in the background, but the target can't do it,
1096 if (async_exec
&& !target_can_async_p ())
1097 error (_("Asynchronous execution not supported on this target."));
1099 /* If we are not asked to run in the bg, then prepare to run in the
1100 foreground, synchronously. */
1101 if (!async_exec
&& target_can_async_p ())
1103 /* Simulate synchronous execution */
1104 async_disable_stdin ();
1108 until_break_command (arg
, from_tty
, 0);
1110 until_next_command (from_tty
);
1114 advance_command (char *arg
, int from_tty
)
1118 if (!target_has_execution
)
1119 error (_("The program is not running."));
1122 error_no_arg (_("a location"));
1124 /* Find out whether we must run in the background. */
1126 async_exec
= strip_bg_char (&arg
);
1128 /* If we must run in the background, but the target can't do it,
1130 if (async_exec
&& !target_can_async_p ())
1131 error (_("Asynchronous execution not supported on this target."));
1133 /* If we are not asked to run in the bg, then prepare to run in the
1134 foreground, synchronously. */
1135 if (!async_exec
&& target_can_async_p ())
1137 /* Simulate synchronous execution. */
1138 async_disable_stdin ();
1141 until_break_command (arg
, from_tty
, 1);
1144 /* Print the result of a function at the end of a 'finish' command. */
1147 print_return_value (int struct_return
, struct type
*value_type
)
1149 struct gdbarch
*gdbarch
= current_gdbarch
;
1150 struct cleanup
*old_chain
;
1151 struct ui_stream
*stb
;
1152 struct value
*value
;
1154 CHECK_TYPEDEF (value_type
);
1155 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1157 /* FIXME: 2003-09-27: When returning from a nested inferior function
1158 call, it's possible (with no help from the architecture vector)
1159 to locate and return/print a "struct return" value. This is just
1160 a more complicated case of what is already being done in in the
1161 inferior function call code. In fact, when inferior function
1162 calls are made async, this will likely be made the norm. */
1164 switch (gdbarch_return_value (gdbarch
, value_type
, NULL
, NULL
, NULL
))
1166 case RETURN_VALUE_REGISTER_CONVENTION
:
1167 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1168 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1169 value
= allocate_value (value_type
);
1170 gdbarch_return_value (current_gdbarch
, value_type
, stop_registers
,
1171 value_contents_raw (value
), NULL
);
1173 case RETURN_VALUE_STRUCT_CONVENTION
:
1177 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1183 stb
= ui_out_stream_new (uiout
);
1184 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1185 ui_out_text (uiout
, "Value returned is ");
1186 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1187 record_latest_value (value
));
1188 ui_out_text (uiout
, " = ");
1189 value_print (value
, stb
->stream
, 0, Val_no_prettyprint
);
1190 ui_out_field_stream (uiout
, "return-value", stb
);
1191 ui_out_text (uiout
, "\n");
1192 do_cleanups (old_chain
);
1196 ui_out_text (uiout
, "Value returned has type: ");
1197 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1198 ui_out_text (uiout
, ".");
1199 ui_out_text (uiout
, " Cannot determine contents\n");
1203 /* Stuff that needs to be done by the finish command after the target
1204 has stopped. In asynchronous mode, we wait for the target to stop
1205 in the call to poll or select in the event loop, so it is
1206 impossible to do all the stuff as part of the finish_command
1207 function itself. The only chance we have to complete this command
1208 is in fetch_inferior_event, which is called by the event loop as
1209 soon as it detects that the target has stopped. This function is
1210 called via the cmd_continuation pointer. */
1213 finish_command_continuation (struct continuation_arg
*arg
)
1215 struct symbol
*function
;
1216 struct breakpoint
*breakpoint
;
1217 struct cleanup
*cleanups
;
1219 breakpoint
= (struct breakpoint
*) arg
->data
.pointer
;
1220 function
= (struct symbol
*) arg
->next
->data
.pointer
;
1221 cleanups
= (struct cleanup
*) arg
->next
->next
->data
.pointer
;
1223 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1224 && function
!= NULL
)
1226 struct type
*value_type
;
1230 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1232 internal_error (__FILE__
, __LINE__
,
1233 _("finish_command: function has no target type"));
1235 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
1237 do_exec_cleanups (cleanups
);
1241 CHECK_TYPEDEF (value_type
);
1242 gcc_compiled
= BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
));
1243 struct_return
= using_struct_return (value_type
, gcc_compiled
);
1245 print_return_value (struct_return
, value_type
);
1248 do_exec_cleanups (cleanups
);
1251 /* "finish": Set a temporary breakpoint at the place the selected
1252 frame will return to, then continue. */
1255 finish_command (char *arg
, int from_tty
)
1257 struct symtab_and_line sal
;
1258 struct frame_info
*frame
;
1259 struct symbol
*function
;
1260 struct breakpoint
*breakpoint
;
1261 struct cleanup
*old_chain
;
1262 struct continuation_arg
*arg1
, *arg2
, *arg3
;
1266 /* Find out whether we must run in the background. */
1268 async_exec
= strip_bg_char (&arg
);
1270 /* If we must run in the background, but the target can't do it,
1272 if (async_exec
&& !target_can_async_p ())
1273 error (_("Asynchronous execution not supported on this target."));
1275 /* If we are not asked to run in the bg, then prepare to run in the
1276 foreground, synchronously. */
1277 if (!async_exec
&& target_can_async_p ())
1279 /* Simulate synchronous execution. */
1280 async_disable_stdin ();
1284 error (_("The \"finish\" command does not take any arguments."));
1285 if (!target_has_execution
)
1286 error (_("The program is not running."));
1287 if (deprecated_selected_frame
== NULL
)
1288 error (_("No selected frame."));
1290 frame
= get_prev_frame (deprecated_selected_frame
);
1292 error (_("\"finish\" not meaningful in the outermost frame."));
1294 clear_proceed_status ();
1296 sal
= find_pc_line (get_frame_pc (frame
), 0);
1297 sal
.pc
= get_frame_pc (frame
);
1299 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
), bp_finish
);
1301 if (!target_can_async_p ())
1302 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1304 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
1306 /* Find the function we will return from. */
1308 function
= find_pc_function (get_frame_pc (deprecated_selected_frame
));
1310 /* Print info on the selected frame, including level number but not
1314 printf_filtered (_("Run till exit from "));
1315 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1318 /* If running asynchronously and the target support asynchronous
1319 execution, set things up for the rest of the finish command to be
1320 completed later on, when gdb has detected that the target has
1321 stopped, in fetch_inferior_event. */
1322 if (target_can_async_p ())
1325 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1327 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1329 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1333 arg1
->data
.pointer
= breakpoint
;
1334 arg2
->data
.pointer
= function
;
1335 arg3
->data
.pointer
= old_chain
;
1336 add_continuation (finish_command_continuation
, arg1
);
1339 proceed_to_finish
= 1; /* We want stop_registers, please... */
1340 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1342 /* Do this only if not running asynchronously or if the target
1343 cannot do async execution. Otherwise, complete this command when
1344 the target actually stops, in fetch_inferior_event. */
1345 if (!target_can_async_p ())
1347 /* Did we stop at our breakpoint? */
1348 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1349 && function
!= NULL
)
1351 struct type
*value_type
;
1355 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1357 internal_error (__FILE__
, __LINE__
,
1358 _("finish_command: function has no target type"));
1360 /* FIXME: Shouldn't we do the cleanups before returning? */
1361 if (TYPE_CODE (value_type
) == TYPE_CODE_VOID
)
1364 CHECK_TYPEDEF (value_type
);
1365 gcc_compiled
= BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function
));
1366 struct_return
= using_struct_return (value_type
, gcc_compiled
);
1368 print_return_value (struct_return
, value_type
);
1371 do_cleanups (old_chain
);
1377 program_info (char *args
, int from_tty
)
1379 bpstat bs
= stop_bpstat
;
1380 int num
= bpstat_num (&bs
);
1382 if (!target_has_execution
)
1384 printf_filtered (_("The program being debugged is not being run.\n"));
1388 target_files_info ();
1389 printf_filtered (_("Program stopped at %s.\n"),
1390 hex_string ((unsigned long) stop_pc
));
1392 printf_filtered (_("It stopped after being stepped.\n"));
1395 /* There may be several breakpoints in the same place, so this
1396 isn't as strange as it seems. */
1401 printf_filtered (_("\
1402 It stopped at a breakpoint that has since been deleted.\n"));
1405 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1406 num
= bpstat_num (&bs
);
1409 else if (stop_signal
!= TARGET_SIGNAL_0
)
1411 printf_filtered (_("It stopped with signal %s, %s.\n"),
1412 target_signal_to_name (stop_signal
),
1413 target_signal_to_string (stop_signal
));
1418 printf_filtered (_("\
1419 Type \"info stack\" or \"info registers\" for more information.\n"));
1424 environment_info (char *var
, int from_tty
)
1428 char *val
= get_in_environ (inferior_environ
, var
);
1431 puts_filtered (var
);
1432 puts_filtered (" = ");
1433 puts_filtered (val
);
1434 puts_filtered ("\n");
1438 puts_filtered ("Environment variable \"");
1439 puts_filtered (var
);
1440 puts_filtered ("\" not defined.\n");
1445 char **vector
= environ_vector (inferior_environ
);
1448 puts_filtered (*vector
++);
1449 puts_filtered ("\n");
1455 set_environment_command (char *arg
, int from_tty
)
1457 char *p
, *val
, *var
;
1461 error_no_arg (_("environment variable and value"));
1463 /* Find seperation between variable name and value */
1464 p
= (char *) strchr (arg
, '=');
1465 val
= (char *) strchr (arg
, ' ');
1467 if (p
!= 0 && val
!= 0)
1469 /* We have both a space and an equals. If the space is before the
1470 equals, walk forward over the spaces til we see a nonspace
1471 (possibly the equals). */
1476 /* Now if the = is after the char following the spaces,
1477 take the char following the spaces. */
1481 else if (val
!= 0 && p
== 0)
1485 error_no_arg (_("environment variable to set"));
1487 if (p
== 0 || p
[1] == 0)
1491 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1495 /* Not setting variable value to null */
1497 while (*val
== ' ' || *val
== '\t')
1501 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1504 var
= savestring (arg
, p
- arg
);
1507 printf_filtered (_("\
1508 Setting environment variable \"%s\" to null value.\n"),
1510 set_in_environ (inferior_environ
, var
, "");
1513 set_in_environ (inferior_environ
, var
, val
);
1518 unset_environment_command (char *var
, int from_tty
)
1522 /* If there is no argument, delete all environment variables.
1523 Ask for confirmation if reading from the terminal. */
1524 if (!from_tty
|| query (_("Delete all environment variables? ")))
1526 free_environ (inferior_environ
);
1527 inferior_environ
= make_environ ();
1531 unset_in_environ (inferior_environ
, var
);
1534 /* Handle the execution path (PATH variable) */
1536 static const char path_var_name
[] = "PATH";
1539 path_info (char *args
, int from_tty
)
1541 puts_filtered ("Executable and object file path: ");
1542 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1543 puts_filtered ("\n");
1546 /* Add zero or more directories to the front of the execution path. */
1549 path_command (char *dirname
, int from_tty
)
1554 env
= get_in_environ (inferior_environ
, path_var_name
);
1555 /* Can be null if path is not set */
1558 exec_path
= xstrdup (env
);
1559 mod_path (dirname
, &exec_path
);
1560 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1563 path_info ((char *) NULL
, from_tty
);
1567 /* Print out the machine register regnum. If regnum is -1, print all
1568 registers (print_all == 1) or all non-float and non-vector
1569 registers (print_all == 0).
1571 For most machines, having all_registers_info() print the
1572 register(s) one per line is good enough. If a different format is
1573 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1574 regs), or there is an existing convention for showing all the
1575 registers, define the architecture method PRINT_REGISTERS_INFO to
1576 provide that format. */
1579 default_print_registers_info (struct gdbarch
*gdbarch
,
1580 struct ui_file
*file
,
1581 struct frame_info
*frame
,
1582 int regnum
, int print_all
)
1585 const int numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
1586 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1588 for (i
= 0; i
< numregs
; i
++)
1590 /* Decide between printing all regs, non-float / vector regs, or
1596 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1601 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1611 /* If the register name is empty, it is undefined for this
1612 processor, so don't display anything. */
1613 if (REGISTER_NAME (i
) == NULL
|| *(REGISTER_NAME (i
)) == '\0')
1616 fputs_filtered (REGISTER_NAME (i
), file
);
1617 print_spaces_filtered (15 - strlen (REGISTER_NAME (i
)), file
);
1619 /* Get the data in raw format. */
1620 if (! frame_register_read (frame
, i
, buffer
))
1622 fprintf_filtered (file
, "*value not available*\n");
1626 /* If virtual format is floating, print it that way, and in raw
1628 if (TYPE_CODE (register_type (current_gdbarch
, i
)) == TYPE_CODE_FLT
)
1632 val_print (register_type (current_gdbarch
, i
), buffer
, 0, 0,
1633 file
, 0, 1, 0, Val_pretty_default
);
1635 fprintf_filtered (file
, "\t(raw 0x");
1636 for (j
= 0; j
< register_size (current_gdbarch
, i
); j
++)
1639 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
1642 idx
= register_size (current_gdbarch
, i
) - 1 - j
;
1643 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
1645 fprintf_filtered (file
, ")");
1649 /* Print the register in hex. */
1650 val_print (register_type (current_gdbarch
, i
), buffer
, 0, 0,
1651 file
, 'x', 1, 0, Val_pretty_default
);
1652 /* If not a vector register, print it also according to its
1654 if (TYPE_VECTOR (register_type (current_gdbarch
, i
)) == 0)
1656 fprintf_filtered (file
, "\t");
1657 val_print (register_type (current_gdbarch
, i
), buffer
, 0, 0,
1658 file
, 0, 1, 0, Val_pretty_default
);
1662 fprintf_filtered (file
, "\n");
1667 registers_info (char *addr_exp
, int fpregs
)
1669 int regnum
, numregs
;
1672 if (!target_has_registers
)
1673 error (_("The program has no registers now."));
1674 if (deprecated_selected_frame
== NULL
)
1675 error (_("No selected frame."));
1679 gdbarch_print_registers_info (current_gdbarch
, gdb_stdout
,
1680 deprecated_selected_frame
, -1, fpregs
);
1684 while (*addr_exp
!= '\0')
1689 /* Keep skipping leading white space. */
1690 if (isspace ((*addr_exp
)))
1696 /* Discard any leading ``$''. Check that there is something
1697 resembling a register following it. */
1698 if (addr_exp
[0] == '$')
1700 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
1701 error (_("Missing register name"));
1703 /* Find the start/end of this register name/num/group. */
1705 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
1709 /* Figure out what we've found and display it. */
1711 /* A register name? */
1713 int regnum
= frame_map_name_to_regnum (deprecated_selected_frame
,
1714 start
, end
- start
);
1717 gdbarch_print_registers_info (current_gdbarch
, gdb_stdout
,
1718 deprecated_selected_frame
, regnum
, fpregs
);
1723 /* A register number? (how portable is this one?). */
1726 int regnum
= strtol (start
, &endptr
, 0);
1729 && regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
)
1731 gdbarch_print_registers_info (current_gdbarch
, gdb_stdout
,
1732 deprecated_selected_frame
, regnum
, fpregs
);
1737 /* A register group? */
1739 struct reggroup
*group
;
1740 for (group
= reggroup_next (current_gdbarch
, NULL
);
1742 group
= reggroup_next (current_gdbarch
, group
))
1744 /* Don't bother with a length check. Should the user
1745 enter a short register group name, go with the first
1746 group that matches. */
1747 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
1753 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
1755 if (gdbarch_register_reggroup_p (current_gdbarch
, regnum
,
1757 gdbarch_print_registers_info (current_gdbarch
,
1758 gdb_stdout
, deprecated_selected_frame
,
1765 /* Nothing matched. */
1766 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
1771 all_registers_info (char *addr_exp
, int from_tty
)
1773 registers_info (addr_exp
, 1);
1777 nofp_registers_info (char *addr_exp
, int from_tty
)
1779 registers_info (addr_exp
, 0);
1783 print_vector_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1784 struct frame_info
*frame
, const char *args
)
1786 if (!target_has_registers
)
1787 error (_("The program has no registers now."));
1788 if (deprecated_selected_frame
== NULL
)
1789 error (_("No selected frame."));
1791 if (gdbarch_print_vector_info_p (gdbarch
))
1792 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
1796 int printed_something
= 0;
1798 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
1800 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
1802 printed_something
= 1;
1803 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
1806 if (!printed_something
)
1807 fprintf_filtered (file
, "No vector information\n");
1812 vector_info (char *args
, int from_tty
)
1814 print_vector_info (current_gdbarch
, gdb_stdout
, deprecated_selected_frame
, args
);
1820 * Should save/restore the tty state since it might be that the
1821 * program to be debugged was started on this tty and it wants
1822 * the tty in some state other than what we want. If it's running
1823 * on another terminal or without a terminal, then saving and
1824 * restoring the tty state is a harmless no-op.
1825 * This only needs to be done if we are attaching to a process.
1830 takes a program started up outside of gdb and ``attaches'' to it.
1831 This stops it cold in its tracks and allows us to start debugging it.
1832 and wait for the trace-trap that results from attaching. */
1835 attach_command (char *args
, int from_tty
)
1838 char *full_exec_path
= NULL
;
1840 dont_repeat (); /* Not for the faint of heart */
1842 if (target_has_execution
)
1844 if (query ("A program is being debugged already. Kill it? "))
1847 error (_("Not killed."));
1850 /* Clear out solib state. Otherwise the solib state of the previous
1851 inferior might have survived and is entirely wrong for the new
1852 target. This has been observed on Linux using glibc 2.3. How to
1864 Cannot access memory at address 0xdeadbeef
1872 target_attach (args
, from_tty
);
1874 /* Set up the "saved terminal modes" of the inferior
1875 based on what modes we are starting it with. */
1876 target_terminal_init ();
1878 /* Set up execution context to know that we should return from
1879 wait_for_inferior as soon as the target reports a stop. */
1880 init_wait_for_inferior ();
1881 clear_proceed_status ();
1883 /* No traps are generated when attaching to inferior under Mach 3
1885 #ifndef ATTACH_NO_WAIT
1886 /* Careful here. See comments in inferior.h. Basically some OSes
1887 don't ignore SIGSTOPs on continue requests anymore. We need a
1888 way for handle_inferior_event to reset the stop_signal variable
1889 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
1890 stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
1891 wait_for_inferior ();
1892 stop_soon
= NO_STOP_QUIETLY
;
1896 * If no exec file is yet known, try to determine it from the
1899 exec_file
= (char *) get_exec_file (0);
1902 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
1905 /* It's possible we don't have a full path, but rather just a
1906 filename. Some targets, such as HP-UX, don't provide the
1909 Attempt to qualify the filename against the source path.
1910 (If that fails, we'll just fall back on the original
1911 filename. Not much more we can do...)
1913 if (!source_full_path_of (exec_file
, &full_exec_path
))
1914 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
1916 exec_file_attach (full_exec_path
, from_tty
);
1917 symbol_file_add_main (full_exec_path
, from_tty
);
1922 reopen_exec_file ();
1926 /* Take any necessary post-attaching actions for this platform.
1928 target_post_attach (PIDGET (inferior_ptid
));
1930 post_create_inferior (¤t_target
, from_tty
);
1932 /* Install inferior's terminal modes. */
1933 target_terminal_inferior ();
1937 if (deprecated_attach_hook
)
1938 deprecated_attach_hook ();
1943 * takes a program previously attached to and detaches it.
1944 * The program resumes execution and will no longer stop
1945 * on signals, etc. We better not have left any breakpoints
1946 * in the program or it'll die when it hits one. For this
1947 * to work, it may be necessary for the process to have been
1948 * previously attached. It *might* work if the program was
1949 * started via the normal ptrace (PTRACE_TRACEME).
1953 detach_command (char *args
, int from_tty
)
1955 dont_repeat (); /* Not for the faint of heart. */
1956 target_detach (args
, from_tty
);
1957 #if defined(SOLIB_RESTART)
1960 if (deprecated_detach_hook
)
1961 deprecated_detach_hook ();
1964 /* Disconnect from the current target without resuming it (leaving it
1965 waiting for a debugger).
1967 We'd better not have left any breakpoints in the program or the
1968 next debugger will get confused. Currently only supported for some
1969 remote targets, since the normal attach mechanisms don't work on
1970 stopped processes on some native platforms (e.g. GNU/Linux). */
1973 disconnect_command (char *args
, int from_tty
)
1975 dont_repeat (); /* Not for the faint of heart */
1976 target_disconnect (args
, from_tty
);
1977 #if defined(SOLIB_RESTART)
1980 if (deprecated_detach_hook
)
1981 deprecated_detach_hook ();
1984 /* Stop the execution of the target while running in async mode, in
1987 interrupt_target_command (char *args
, int from_tty
)
1989 if (target_can_async_p ())
1991 dont_repeat (); /* Not for the faint of heart */
1997 print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1998 struct frame_info
*frame
, const char *args
)
2000 if (!target_has_registers
)
2001 error (_("The program has no registers now."));
2002 if (deprecated_selected_frame
== NULL
)
2003 error (_("No selected frame."));
2005 if (gdbarch_print_float_info_p (gdbarch
))
2006 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2010 int printed_something
= 0;
2012 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
2014 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2016 printed_something
= 1;
2017 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2020 if (!printed_something
)
2021 fprintf_filtered (file
, "\
2022 No floating-point info available for this processor.\n");
2027 float_info (char *args
, int from_tty
)
2029 print_float_info (current_gdbarch
, gdb_stdout
,
2030 deprecated_selected_frame
, args
);
2034 unset_command (char *args
, int from_tty
)
2036 printf_filtered (_("\
2037 \"unset\" must be followed by the name of an unset subcommand.\n"));
2038 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2042 _initialize_infcmd (void)
2044 struct cmd_list_element
*c
= NULL
;
2046 /* add the filename of the terminal connected to inferior I/O */
2047 add_setshow_filename_cmd ("inferior-tty", class_run
,
2048 &inferior_io_terminal
, _("\
2049 Set terminal for future runs of program being debugged."), _("\
2050 Show terminal for future runs of program being debugged."), _("\
2051 Usage: set inferior-tty /dev/pts/1"), NULL
, NULL
, &setlist
, &showlist
);
2052 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2054 add_setshow_optional_filename_cmd ("args", class_run
,
2055 &inferior_args
, _("\
2056 Set argument list to give program being debugged when it is started."), _("\
2057 Show argument list to give program being debugged when it is started."), _("\
2058 Follow this command with any number of args, to be passed to the program."),
2061 &setlist
, &showlist
);
2063 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2064 The environment to give the program, or one variable's value.\n\
2065 With an argument VAR, prints the value of environment variable VAR to\n\
2066 give the program being debugged. With no arguments, prints the entire\n\
2067 environment to be given to the program."), &showlist
);
2068 set_cmd_completer (c
, noop_completer
);
2070 add_prefix_cmd ("unset", no_class
, unset_command
,
2071 _("Complement to certain \"set\" commands."),
2072 &unsetlist
, "unset ", 0, &cmdlist
);
2074 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2075 Cancel environment variable VAR for the program.\n\
2076 This does not affect the program until the next \"run\" command."),
2078 set_cmd_completer (c
, noop_completer
);
2080 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2081 Set environment variable value to give the program.\n\
2082 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2083 VALUES of environment variables are uninterpreted strings.\n\
2084 This does not affect the program until the next \"run\" command."),
2086 set_cmd_completer (c
, noop_completer
);
2088 c
= add_com ("path", class_files
, path_command
, _("\
2089 Add directory DIR(s) to beginning of search path for object files.\n\
2090 $cwd in the path means the current working directory.\n\
2091 This path is equivalent to the $PATH shell variable. It is a list of\n\
2092 directories, separated by colons. These directories are searched to find\n\
2093 fully linked executable files and separately compiled object files as needed."));
2094 set_cmd_completer (c
, filename_completer
);
2096 c
= add_cmd ("paths", no_class
, path_info
, _("\
2097 Current search path for finding object files.\n\
2098 $cwd in the path means the current working directory.\n\
2099 This path is equivalent to the $PATH shell variable. It is a list of\n\
2100 directories, separated by colons. These directories are searched to find\n\
2101 fully linked executable files and separately compiled object files as needed."),
2103 set_cmd_completer (c
, noop_completer
);
2105 add_com ("attach", class_run
, attach_command
, _("\
2106 Attach to a process or file outside of GDB.\n\
2107 This command attaches to another target, of the same type as your last\n\
2108 \"target\" command (\"info files\" will show your target stack).\n\
2109 The command may take as argument a process id or a device file.\n\
2110 For a process id, you must have permission to send the process a signal,\n\
2111 and it must have the same effective uid as the debugger.\n\
2112 When using \"attach\" with a process id, the debugger finds the\n\
2113 program running in the process, looking first in the current working\n\
2114 directory, or (if not found there) using the source file search path\n\
2115 (see the \"directory\" command). You can also use the \"file\" command\n\
2116 to specify the program, and to load its symbol table."));
2118 add_com ("detach", class_run
, detach_command
, _("\
2119 Detach a process or file previously attached.\n\
2120 If a process, it is no longer traced, and it continues its execution. If\n\
2121 you were debugging a file, the file is closed and gdb no longer accesses it."));
2123 add_com ("disconnect", class_run
, disconnect_command
, _("\
2124 Disconnect from a target.\n\
2125 The target will wait for another debugger to connect. Not available for\n\
2128 add_com ("signal", class_run
, signal_command
, _("\
2129 Continue program giving it signal specified by the argument.\n\
2130 An argument of \"0\" means continue program without giving it a signal."));
2132 add_com ("stepi", class_run
, stepi_command
, _("\
2133 Step one instruction exactly.\n\
2134 Argument N means do this N times (or till program stops for another reason)."));
2135 add_com_alias ("si", "stepi", class_alias
, 0);
2137 add_com ("nexti", class_run
, nexti_command
, _("\
2138 Step one instruction, but proceed through subroutine calls.\n\
2139 Argument N means do this N times (or till program stops for another reason)."));
2140 add_com_alias ("ni", "nexti", class_alias
, 0);
2142 add_com ("finish", class_run
, finish_command
, _("\
2143 Execute until selected stack frame returns.\n\
2144 Upon return, the value returned is printed and put in the value history."));
2146 add_com ("next", class_run
, next_command
, _("\
2147 Step program, proceeding through subroutine calls.\n\
2148 Like the \"step\" command as long as subroutine calls do not happen;\n\
2149 when they do, the call is treated as one instruction.\n\
2150 Argument N means do this N times (or till program stops for another reason)."));
2151 add_com_alias ("n", "next", class_run
, 1);
2153 add_com_alias ("S", "next", class_run
, 1);
2155 add_com ("step", class_run
, step_command
, _("\
2156 Step program until it reaches a different source line.\n\
2157 Argument N means do this N times (or till program stops for another reason)."));
2158 add_com_alias ("s", "step", class_run
, 1);
2160 c
= add_com ("until", class_run
, until_command
, _("\
2161 Execute until the program reaches a source line greater than the current\n\
2162 or a specified location (same args as break command) within the current frame."));
2163 set_cmd_completer (c
, location_completer
);
2164 add_com_alias ("u", "until", class_run
, 1);
2166 c
= add_com ("advance", class_run
, advance_command
, _("\
2167 Continue the program up to the given location (same form as args for break command).\n\
2168 Execution will also stop upon exit from the current stack frame."));
2169 set_cmd_completer (c
, location_completer
);
2171 c
= add_com ("jump", class_run
, jump_command
, _("\
2172 Continue program being debugged at specified line or address.\n\
2173 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2174 for an address to start at."));
2175 set_cmd_completer (c
, location_completer
);
2179 c
= add_com ("go", class_run
, go_command
, _("\
2180 Usage: go <location>\n\
2181 Continue program being debugged, stopping at specified line or \n\
2183 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2184 expression for an address to start at.\n\
2185 This command is a combination of tbreak and jump."));
2186 set_cmd_completer (c
, location_completer
);
2190 add_com_alias ("g", "go", class_run
, 1);
2192 add_com ("continue", class_run
, continue_command
, _("\
2193 Continue program being debugged, after signal or breakpoint.\n\
2194 If proceeding from breakpoint, a number N may be used as an argument,\n\
2195 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2196 the breakpoint won't break until the Nth time it is reached)."));
2197 add_com_alias ("c", "cont", class_run
, 1);
2198 add_com_alias ("fg", "cont", class_run
, 1);
2200 c
= add_com ("run", class_run
, run_command
, _("\
2201 Start debugged program. You may specify arguments to give it.\n\
2202 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2203 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2204 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2205 To cancel previous arguments and run with no arguments,\n\
2206 use \"set args\" without arguments."));
2207 set_cmd_completer (c
, filename_completer
);
2208 add_com_alias ("r", "run", class_run
, 1);
2210 add_com ("R", class_run
, run_no_args_command
,
2211 _("Start debugged program with no arguments."));
2213 c
= add_com ("start", class_run
, start_command
, _("\
2214 Run the debugged program until the beginning of the main procedure.\n\
2215 You may specify arguments to give to your program, just as with the\n\
2216 \"run\" command."));
2217 set_cmd_completer (c
, filename_completer
);
2219 add_com ("interrupt", class_run
, interrupt_target_command
,
2220 _("Interrupt the execution of the debugged program."));
2222 add_info ("registers", nofp_registers_info
, _("\
2223 List of integer registers and their contents, for selected stack frame.\n\
2224 Register name as argument means describe only that register."));
2225 add_info_alias ("r", "registers", 1);
2228 add_com ("lr", class_info
, nofp_registers_info
, _("\
2229 List of integer registers and their contents, for selected stack frame.\n\
2230 Register name as argument means describe only that register."));
2231 add_info ("all-registers", all_registers_info
, _("\
2232 List of all registers and their contents, for selected stack frame.\n\
2233 Register name as argument means describe only that register."));
2235 add_info ("program", program_info
,
2236 _("Execution status of the program."));
2238 add_info ("float", float_info
,
2239 _("Print the status of the floating point unit\n"));
2241 add_info ("vector", vector_info
,
2242 _("Print the status of the vector unit\n"));
2244 inferior_environ
= make_environ ();
2245 init_environ (inferior_environ
);