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 finish_command_continuation (struct continuation_arg
*,
79 static void until_next_command (int);
81 static void until_command (char *, int);
83 static void path_info (char *, int);
85 static void path_command (char *, int);
87 static void unset_command (char *, int);
89 static void float_info (char *, int);
91 static void detach_command (char *, int);
93 static void disconnect_command (char *, int);
95 static void unset_environment_command (char *, int);
97 static void set_environment_command (char *, int);
99 static void environment_info (char *, int);
101 static void program_info (char *, int);
103 static void finish_command (char *, int);
105 static void signal_command (char *, int);
107 static void jump_command (char *, int);
109 static void step_1 (int, int, char *);
110 static void step_once (int skip_subroutines
, int single_inst
, int count
, int thread
);
111 static void step_1_continuation (struct continuation_arg
*arg
, int error_p
);
113 static void next_command (char *, int);
115 static void step_command (char *, int);
117 static void run_command (char *, int);
119 static void run_no_args_command (char *args
, int from_tty
);
121 static void go_command (char *line_no
, int from_tty
);
123 static int strip_bg_char (char **);
125 void _initialize_infcmd (void);
127 #define GO_USAGE "Usage: go <location>\n"
129 #define ERROR_NO_INFERIOR \
130 if (!target_has_execution) error (_("The program is not being run."));
132 /* String containing arguments to give to the program, separated by spaces.
133 Empty string (pointer to '\0') means no args. */
135 static char *inferior_args
;
137 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
138 then we must compute INFERIOR_ARGS from this (via the target). */
140 static int inferior_argc
;
141 static char **inferior_argv
;
143 /* File name for default use for standard in/out in the inferior. */
145 static char *inferior_io_terminal
;
147 /* Pid of our debugged inferior, or 0 if no inferior now.
148 Since various parts of infrun.c test this to see whether there is a program
149 being debugged it should be nonzero (currently 3 is used) for remote
152 ptid_t inferior_ptid
;
154 /* Last signal that the inferior received (why it stopped). */
156 enum target_signal stop_signal
;
158 /* Address at which inferior stopped. */
162 /* Chain containing status of breakpoint(s) that we have stopped at. */
166 /* Flag indicating that a command has proceeded the inferior past the
167 current breakpoint. */
169 int breakpoint_proceeded
;
171 /* Nonzero if stopped due to a step command. */
175 /* Nonzero if stopped due to completion of a stack dummy routine. */
177 int stop_stack_dummy
;
179 /* Nonzero if stopped due to a random (unexpected) signal in inferior
182 int stopped_by_random_signal
;
184 /* Range to single step within.
185 If this is nonzero, respond to a single-step signal
186 by continuing to step if the pc is in this range. */
188 CORE_ADDR step_range_start
; /* Inclusive */
189 CORE_ADDR step_range_end
; /* Exclusive */
191 /* Stack frame address as of when stepping command was issued.
192 This is how we know when we step into a subroutine call,
193 and how to set the frame for the breakpoint used to step out. */
195 struct frame_id step_frame_id
;
197 enum step_over_calls_kind step_over_calls
;
199 /* If stepping, nonzero means step count is > 1
200 so don't print frame next time inferior stops
201 if it stops due to stepping. */
205 /* Environment to use for running inferior,
206 in format described in environ.h. */
208 struct gdb_environ
*inferior_environ
;
210 /* When set, no calls to target_resumed observer will be made. */
211 int suppress_resume_observer
= 0;
212 /* When set, normal_stop will not call the normal_stop observer. */
213 int suppress_stop_observer
= 0;
215 /* Accessor routines. */
218 set_inferior_io_terminal (const char *terminal_name
)
220 if (inferior_io_terminal
)
221 xfree (inferior_io_terminal
);
224 inferior_io_terminal
= NULL
;
226 inferior_io_terminal
= savestring (terminal_name
, strlen (terminal_name
));
230 get_inferior_io_terminal (void)
232 return inferior_io_terminal
;
236 get_inferior_args (void)
238 if (inferior_argc
!= 0)
242 n
= gdbarch_construct_inferior_arguments (current_gdbarch
,
243 inferior_argc
, inferior_argv
);
244 old
= set_inferior_args (n
);
248 if (inferior_args
== NULL
)
249 inferior_args
= xstrdup ("");
251 return inferior_args
;
255 set_inferior_args (char *newargs
)
257 char *saved_args
= inferior_args
;
259 inferior_args
= newargs
;
267 set_inferior_args_vector (int argc
, char **argv
)
269 inferior_argc
= argc
;
270 inferior_argv
= argv
;
273 /* Notice when `set args' is run. */
275 notice_args_set (char *args
, int from_tty
, struct cmd_list_element
*c
)
281 /* Notice when `show args' is run. */
283 notice_args_read (struct ui_file
*file
, int from_tty
,
284 struct cmd_list_element
*c
, const char *value
)
286 /* Note that we ignore the passed-in value in favor of computing it
288 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
292 /* Compute command-line string given argument vector. This does the
293 same shell processing as fork_inferior. */
295 construct_inferior_arguments (struct gdbarch
*gdbarch
, int argc
, char **argv
)
299 if (STARTUP_WITH_SHELL
)
301 /* This holds all the characters considered special to the
302 typical Unix shells. We include `^' because the SunOS
303 /bin/sh treats it as a synonym for `|'. */
304 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
309 /* We over-compute the size. It shouldn't matter. */
310 for (i
= 0; i
< argc
; ++i
)
311 length
+= 2 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
313 result
= (char *) xmalloc (length
);
316 for (i
= 0; i
< argc
; ++i
)
321 /* Need to handle empty arguments specially. */
322 if (argv
[i
][0] == '\0')
329 for (cp
= argv
[i
]; *cp
; ++cp
)
331 if (strchr (special
, *cp
) != NULL
)
341 /* In this case we can't handle arguments that contain spaces,
342 tabs, or newlines -- see breakup_args(). */
346 for (i
= 0; i
< argc
; ++i
)
348 char *cp
= strchr (argv
[i
], ' ');
350 cp
= strchr (argv
[i
], '\t');
352 cp
= strchr (argv
[i
], '\n');
354 error (_("can't handle command-line argument containing whitespace"));
355 length
+= strlen (argv
[i
]) + 1;
358 result
= (char *) xmalloc (length
);
360 for (i
= 0; i
< argc
; ++i
)
363 strcat (result
, " ");
364 strcat (result
, argv
[i
]);
372 /* This function detects whether or not a '&' character (indicating
373 background execution) has been added as *the last* of the arguments ARGS
374 of a command. If it has, it removes it and returns 1. Otherwise it
375 does nothing and returns 0. */
377 strip_bg_char (char **args
)
381 p
= strchr (*args
, '&');
385 if (p
== (*args
+ strlen (*args
) - 1))
387 if (strlen (*args
) > 1)
391 while (*p
== ' ' || *p
== '\t');
403 tty_command (char *file
, int from_tty
)
406 error_no_arg (_("terminal name for running target process"));
408 set_inferior_io_terminal (file
);
411 /* Common actions to take after creating any sort of inferior, by any
412 means (running, attaching, connecting, et cetera). The target
413 should be stopped. */
416 post_create_inferior (struct target_ops
*target
, int from_tty
)
418 /* Be sure we own the terminal in case write operations are performed. */
419 target_terminal_ours ();
421 /* If the target hasn't taken care of this already, do it now.
422 Targets which need to access registers during to_open,
423 to_create_inferior, or to_attach should do it earlier; but many
425 target_find_description ();
429 /* Sometimes the platform-specific hook loads initial shared
430 libraries, and sometimes it doesn't. Try to do so first, so
431 that we can add them with the correct value for FROM_TTY.
432 If we made all the inferior hook methods consistent,
433 this call could be removed. */
435 SOLIB_ADD (NULL
, from_tty
, target
, auto_solib_add
);
437 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
440 /* Create the hooks to handle shared library load and unload
442 #ifdef SOLIB_CREATE_INFERIOR_HOOK
443 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
445 solib_create_inferior_hook ();
449 observer_notify_inferior_created (target
, from_tty
);
452 /* Kill the inferior if already running. This function is designed
453 to be called when we are about to start the execution of the program
454 from the beginning. Ask the user to confirm that he wants to restart
455 the program being debugged when FROM_TTY is non-null. */
458 kill_if_already_running (int from_tty
)
460 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
462 /* Bail out before killing the program if we will not be able to
464 target_require_runnable ();
467 && !query ("The program being debugged has been started already.\n\
468 Start it from the beginning? "))
469 error (_("Program not restarted."));
471 no_shared_libraries (NULL
, from_tty
);
472 init_wait_for_inferior ();
476 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
477 a temporary breakpoint at the begining of the main program before
478 running the program. */
481 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
487 kill_if_already_running (from_tty
);
488 clear_breakpoint_hit_counts ();
490 /* Clean up any leftovers from other runs. Some other things from
491 this function should probably be moved into target_pre_inferior. */
492 target_pre_inferior (from_tty
);
494 /* Purge old solib objfiles. */
495 objfile_purge_solibs ();
499 /* The comment here used to read, "The exec file is re-read every
500 time we do a generic_mourn_inferior, so we just have to worry
501 about the symbol file." The `generic_mourn_inferior' function
502 gets called whenever the program exits. However, suppose the
503 program exits, and *then* the executable file changes? We need
504 to check again here. Since reopen_exec_file doesn't do anything
505 if the timestamp hasn't changed, I don't see the harm. */
509 /* Insert the temporary breakpoint if a location was specified. */
511 tbreak_command (main_name (), 0);
513 exec_file
= (char *) get_exec_file (0);
515 /* We keep symbols from add-symbol-file, on the grounds that the
516 user might want to add some symbols before running the program
517 (right?). But sometimes (dynamic loading where the user manually
518 introduces the new symbols with add-symbol-file), the code which
519 the symbols describe does not persist between runs. Currently
520 the user has to manually nuke all symbols between runs if they
521 want them to go away (PR 2207). This is probably reasonable. */
525 if (target_can_async_p ())
526 async_disable_stdin ();
530 int async_exec
= strip_bg_char (&args
);
532 /* If we get a request for running in the bg but the target
533 doesn't support it, error out. */
534 if (async_exec
&& !target_can_async_p ())
535 error (_("Asynchronous execution not supported on this target."));
537 /* If we don't get a request of running in the bg, then we need
538 to simulate synchronous (fg) execution. */
539 if (!async_exec
&& target_can_async_p ())
541 /* Simulate synchronous execution */
542 async_disable_stdin ();
545 /* If there were other args, beside '&', process them. */
548 char *old_args
= set_inferior_args (xstrdup (args
));
555 ui_out_field_string (uiout
, NULL
, "Starting program");
556 ui_out_text (uiout
, ": ");
558 ui_out_field_string (uiout
, "execfile", exec_file
);
559 ui_out_spaces (uiout
, 1);
560 /* We call get_inferior_args() because we might need to compute
562 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
563 ui_out_text (uiout
, "\n");
564 ui_out_flush (uiout
);
567 /* We call get_inferior_args() because we might need to compute
569 target_create_inferior (exec_file
, get_inferior_args (),
570 environ_vector (inferior_environ
), from_tty
);
572 /* Pass zero for FROM_TTY, because at this point the "run" command
573 has done its thing; now we are setting up the running program. */
574 post_create_inferior (¤t_target
, 0);
576 /* Start the target running. */
577 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
582 run_command (char *args
, int from_tty
)
584 run_command_1 (args
, from_tty
, 0);
588 run_no_args_command (char *args
, int from_tty
)
590 char *old_args
= set_inferior_args (xstrdup (""));
595 /* Start the execution of the program up until the beginning of the main
599 start_command (char *args
, int from_tty
)
601 /* Some languages such as Ada need to search inside the program
602 minimal symbols for the location where to put the temporary
603 breakpoint before starting. */
604 if (!have_minimal_symbols ())
605 error (_("No symbol table loaded. Use the \"file\" command."));
607 /* Run the program until reaching the main procedure... */
608 run_command_1 (args
, from_tty
, 1);
612 continue_command (char *proc_count_exp
, int from_tty
)
616 ensure_not_running ();
618 /* Find out whether we must run in the background. */
619 if (proc_count_exp
!= NULL
)
620 async_exec
= strip_bg_char (&proc_count_exp
);
622 /* If we must run in the background, but the target can't do it,
624 if (async_exec
&& !target_can_async_p ())
625 error (_("Asynchronous execution not supported on this target."));
627 /* If we are not asked to run in the bg, then prepare to run in the
628 foreground, synchronously. */
629 if (!async_exec
&& target_can_async_p ())
631 /* Simulate synchronous execution */
632 async_disable_stdin ();
635 /* If have argument (besides '&'), set proceed count of breakpoint
637 if (proc_count_exp
!= NULL
)
639 bpstat bs
= stop_bpstat
;
643 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
646 set_ignore_count (num
,
647 parse_and_eval_long (proc_count_exp
) - 1,
649 /* set_ignore_count prints a message ending with a period.
650 So print two spaces before "Continuing.". */
652 printf_filtered (" ");
656 if (!stopped
&& from_tty
)
659 ("Not stopped at any breakpoint; argument ignored.\n");
664 printf_filtered (_("Continuing.\n"));
666 clear_proceed_status ();
668 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
671 /* Step until outside of current statement. */
674 step_command (char *count_string
, int from_tty
)
676 step_1 (0, 0, count_string
);
679 /* Likewise, but skip over subroutine calls as if single instructions. */
682 next_command (char *count_string
, int from_tty
)
684 step_1 (1, 0, count_string
);
687 /* Likewise, but step only one instruction. */
690 stepi_command (char *count_string
, int from_tty
)
692 step_1 (0, 1, count_string
);
696 nexti_command (char *count_string
, int from_tty
)
698 step_1 (1, 1, count_string
);
702 delete_longjmp_breakpoint_cleanup (void *arg
)
704 int thread
= * (int *) arg
;
705 delete_longjmp_breakpoint (thread
);
709 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
712 struct frame_info
*frame
;
713 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
718 ensure_not_running ();
721 async_exec
= strip_bg_char (&count_string
);
723 /* If we get a request for running in the bg but the target
724 doesn't support it, error out. */
725 if (async_exec
&& !target_can_async_p ())
726 error (_("Asynchronous execution not supported on this target."));
728 /* If we don't get a request of running in the bg, then we need
729 to simulate synchronous (fg) execution. */
730 if (!async_exec
&& target_can_async_p ())
732 /* Simulate synchronous execution */
733 async_disable_stdin ();
736 count
= count_string
? parse_and_eval_long (count_string
) : 1;
738 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
740 if (in_thread_list (inferior_ptid
))
741 thread
= pid_to_thread_id (inferior_ptid
);
743 set_longjmp_breakpoint ();
745 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
748 /* In synchronous case, all is well, just use the regular for loop. */
749 if (!target_can_async_p ())
751 for (; count
> 0; count
--)
753 clear_proceed_status ();
755 frame
= get_current_frame ();
756 if (!frame
) /* Avoid coredump here. Why tho? */
757 error (_("No current frame"));
758 step_frame_id
= get_frame_id (frame
);
762 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
763 if (step_range_end
== 0)
766 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
767 &step_range_end
) == 0)
768 error (_("Cannot find bounds of current function"));
770 target_terminal_ours ();
771 printf_filtered (_("\
772 Single stepping until exit from function %s, \n\
773 which has no line number information.\n"), name
);
778 /* Say we are stepping, but stop after one insn whatever it does. */
779 step_range_start
= step_range_end
= 1;
780 if (!skip_subroutines
)
782 Don't step over function calls, not even to functions lacking
784 step_over_calls
= STEP_OVER_NONE
;
787 if (skip_subroutines
)
788 step_over_calls
= STEP_OVER_ALL
;
790 step_multi
= (count
> 1);
791 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
797 do_cleanups (cleanups
);
800 /* In case of asynchronous target things get complicated, do only
801 one step for now, before returning control to the event loop. Let
802 the continuation figure out how many other steps we need to do,
803 and handle them one at the time, through step_once(). */
806 step_once (skip_subroutines
, single_inst
, count
, thread
);
807 /* We are running, and the continuation is installed. It will
808 disable the longjmp breakpoint as appropriate. */
809 discard_cleanups (cleanups
);
813 /* Called after we are done with one step operation, to check whether
814 we need to step again, before we print the prompt and return control
815 to the user. If count is > 1, we will need to do one more call to
816 proceed(), via step_once(). Basically it is like step_once and
817 step_1_continuation are co-recursive. */
819 step_1_continuation (struct continuation_arg
*arg
, int error_p
)
822 int skip_subroutines
;
826 skip_subroutines
= arg
->data
.integer
;
827 single_inst
= arg
->next
->data
.integer
;
828 count
= arg
->next
->next
->data
.integer
;
829 thread
= arg
->next
->next
->next
->data
.integer
;
831 if (error_p
|| !step_multi
|| !stop_step
)
833 /* We either hit an error, or stopped for some reason
834 that is not stepping, or there are no further steps
836 if (!single_inst
|| skip_subroutines
)
837 delete_longjmp_breakpoint (thread
);
841 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
844 /* Do just one step operation. If count >1 we will have to set up a
845 continuation to be done after the target stops (after this one
846 step). This is useful to implement the 'step n' kind of commands, in
847 case of asynchronous targets. We had to split step_1 into two parts,
848 one to be done before proceed() and one afterwards. This function is
849 called in case of step n with n>1, after the first step operation has
852 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
854 struct continuation_arg
*arg1
;
855 struct continuation_arg
*arg2
;
856 struct continuation_arg
*arg3
;
857 struct continuation_arg
*arg4
;
858 struct frame_info
*frame
;
862 clear_proceed_status ();
864 frame
= get_current_frame ();
865 if (!frame
) /* Avoid coredump here. Why tho? */
866 error (_("No current frame"));
867 step_frame_id
= get_frame_id (frame
);
871 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
873 /* If we have no line info, switch to stepi mode. */
874 if (step_range_end
== 0 && step_stop_if_no_debug
)
876 step_range_start
= step_range_end
= 1;
878 else if (step_range_end
== 0)
881 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
882 &step_range_end
) == 0)
883 error (_("Cannot find bounds of current function"));
885 target_terminal_ours ();
886 printf_filtered (_("\
887 Single stepping until exit from function %s, \n\
888 which has no line number information.\n"), name
);
893 /* Say we are stepping, but stop after one insn whatever it does. */
894 step_range_start
= step_range_end
= 1;
895 if (!skip_subroutines
)
897 Don't step over function calls, not even to functions lacking
899 step_over_calls
= STEP_OVER_NONE
;
902 if (skip_subroutines
)
903 step_over_calls
= STEP_OVER_ALL
;
905 step_multi
= (count
> 1);
906 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
908 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
910 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
912 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
914 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
916 arg1
->data
.integer
= skip_subroutines
;
918 arg2
->data
.integer
= single_inst
;
920 arg3
->data
.integer
= count
;
922 arg4
->data
.integer
= thread
;
923 add_intermediate_continuation (step_1_continuation
, arg1
);
928 /* Continue program at specified address. */
931 jump_command (char *arg
, int from_tty
)
934 struct symtabs_and_lines sals
;
935 struct symtab_and_line sal
;
941 ensure_not_running ();
943 /* Find out whether we must run in the background. */
945 async_exec
= strip_bg_char (&arg
);
947 /* If we must run in the background, but the target can't do it,
949 if (async_exec
&& !target_can_async_p ())
950 error (_("Asynchronous execution not supported on this target."));
953 error_no_arg (_("starting address"));
955 sals
= decode_line_spec_1 (arg
, 1);
958 error (_("Unreasonable jump request"));
964 if (sal
.symtab
== 0 && sal
.pc
== 0)
965 error (_("No source file has been specified."));
967 resolve_sal_pc (&sal
); /* May error out */
969 /* See if we are trying to jump to another function. */
970 fn
= get_frame_function (get_current_frame ());
971 sfn
= find_pc_function (sal
.pc
);
972 if (fn
!= NULL
&& sfn
!= fn
)
974 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
975 SYMBOL_PRINT_NAME (fn
)))
977 error (_("Not confirmed."));
984 fixup_symbol_section (sfn
, 0);
985 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn
)) &&
986 !section_is_mapped (SYMBOL_BFD_SECTION (sfn
)))
988 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
990 error (_("Not confirmed."));
1000 printf_filtered (_("Continuing at "));
1001 fputs_filtered (paddress (addr
), gdb_stdout
);
1002 printf_filtered (".\n");
1005 /* If we are not asked to run in the bg, then prepare to run in the
1006 foreground, synchronously. */
1007 if (!async_exec
&& target_can_async_p ())
1009 /* Simulate synchronous execution */
1010 async_disable_stdin ();
1013 clear_proceed_status ();
1014 proceed (addr
, TARGET_SIGNAL_0
, 0);
1018 /* Go to line or address in current procedure */
1020 go_command (char *line_no
, int from_tty
)
1022 if (line_no
== (char *) NULL
|| !*line_no
)
1023 printf_filtered (GO_USAGE
);
1026 tbreak_command (line_no
, from_tty
);
1027 jump_command (line_no
, from_tty
);
1032 /* Continue program giving it specified signal. */
1035 signal_command (char *signum_exp
, int from_tty
)
1037 enum target_signal oursig
;
1040 dont_repeat (); /* Too dangerous. */
1042 ensure_not_running ();
1044 /* Find out whether we must run in the background. */
1045 if (signum_exp
!= NULL
)
1046 async_exec
= strip_bg_char (&signum_exp
);
1048 /* If we must run in the background, but the target can't do it,
1050 if (async_exec
&& !target_can_async_p ())
1051 error (_("Asynchronous execution not supported on this target."));
1053 /* If we are not asked to run in the bg, then prepare to run in the
1054 foreground, synchronously. */
1055 if (!async_exec
&& target_can_async_p ())
1057 /* Simulate synchronous execution. */
1058 async_disable_stdin ();
1062 error_no_arg (_("signal number"));
1064 /* It would be even slicker to make signal names be valid expressions,
1065 (the type could be "enum $signal" or some such), then the user could
1066 assign them to convenience variables. */
1067 oursig
= target_signal_from_name (signum_exp
);
1069 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1071 /* No, try numeric. */
1072 int num
= parse_and_eval_long (signum_exp
);
1075 oursig
= TARGET_SIGNAL_0
;
1077 oursig
= target_signal_from_command (num
);
1082 if (oursig
== TARGET_SIGNAL_0
)
1083 printf_filtered (_("Continuing with no signal.\n"));
1085 printf_filtered (_("Continuing with signal %s.\n"),
1086 target_signal_to_name (oursig
));
1089 clear_proceed_status ();
1090 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1091 FIXME: Neither should "signal foo" but when I tried passing
1092 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1093 tried to track down yet. */
1094 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
1097 /* Proceed until we reach a different source line with pc greater than
1098 our current one or exit the function. We skip calls in both cases.
1100 Note that eventually this command should probably be changed so
1101 that only source lines are printed out when we hit the breakpoint
1102 we set. This may involve changes to wait_for_inferior and the
1103 proceed status code. */
1106 until_next_command (int from_tty
)
1108 struct frame_info
*frame
;
1110 struct symbol
*func
;
1111 struct symtab_and_line sal
;
1113 clear_proceed_status ();
1115 frame
= get_current_frame ();
1117 /* Step until either exited from this function or greater
1118 than the current line (if in symbolic section) or pc (if
1122 func
= find_pc_function (pc
);
1126 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1128 if (msymbol
== NULL
)
1129 error (_("Execution is not within a known function."));
1131 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1132 step_range_end
= pc
;
1136 sal
= find_pc_line (pc
, 0);
1138 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1139 step_range_end
= sal
.end
;
1142 step_over_calls
= STEP_OVER_ALL
;
1143 step_frame_id
= get_frame_id (frame
);
1145 step_multi
= 0; /* Only one call to proceed */
1147 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1151 until_command (char *arg
, int from_tty
)
1155 if (!target_has_execution
)
1156 error (_("The program is not running."));
1158 /* Find out whether we must run in the background. */
1160 async_exec
= strip_bg_char (&arg
);
1162 /* If we must run in the background, but the target can't do it,
1164 if (async_exec
&& !target_can_async_p ())
1165 error (_("Asynchronous execution not supported on this target."));
1167 /* If we are not asked to run in the bg, then prepare to run in the
1168 foreground, synchronously. */
1169 if (!async_exec
&& target_can_async_p ())
1171 /* Simulate synchronous execution */
1172 async_disable_stdin ();
1176 until_break_command (arg
, from_tty
, 0);
1178 until_next_command (from_tty
);
1182 advance_command (char *arg
, int from_tty
)
1186 if (!target_has_execution
)
1187 error (_("The program is not running."));
1190 error_no_arg (_("a location"));
1192 /* Find out whether we must run in the background. */
1194 async_exec
= strip_bg_char (&arg
);
1196 /* If we must run in the background, but the target can't do it,
1198 if (async_exec
&& !target_can_async_p ())
1199 error (_("Asynchronous execution not supported on this target."));
1201 /* If we are not asked to run in the bg, then prepare to run in the
1202 foreground, synchronously. */
1203 if (!async_exec
&& target_can_async_p ())
1205 /* Simulate synchronous execution. */
1206 async_disable_stdin ();
1209 until_break_command (arg
, from_tty
, 1);
1212 /* Print the result of a function at the end of a 'finish' command. */
1215 print_return_value (struct type
*func_type
, struct type
*value_type
)
1217 struct gdbarch
*gdbarch
= current_gdbarch
;
1218 struct cleanup
*old_chain
;
1219 struct ui_stream
*stb
;
1220 struct value
*value
;
1222 CHECK_TYPEDEF (value_type
);
1223 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1225 /* FIXME: 2003-09-27: When returning from a nested inferior function
1226 call, it's possible (with no help from the architecture vector)
1227 to locate and return/print a "struct return" value. This is just
1228 a more complicated case of what is already being done in in the
1229 inferior function call code. In fact, when inferior function
1230 calls are made async, this will likely be made the norm. */
1232 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1235 case RETURN_VALUE_REGISTER_CONVENTION
:
1236 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1237 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1238 value
= allocate_value (value_type
);
1239 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1240 value_contents_raw (value
), NULL
);
1242 case RETURN_VALUE_STRUCT_CONVENTION
:
1246 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1252 stb
= ui_out_stream_new (uiout
);
1253 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1254 ui_out_text (uiout
, "Value returned is ");
1255 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1256 record_latest_value (value
));
1257 ui_out_text (uiout
, " = ");
1258 value_print (value
, stb
->stream
, 0, Val_no_prettyprint
);
1259 ui_out_field_stream (uiout
, "return-value", stb
);
1260 ui_out_text (uiout
, "\n");
1261 do_cleanups (old_chain
);
1265 ui_out_text (uiout
, "Value returned has type: ");
1266 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1267 ui_out_text (uiout
, ".");
1268 ui_out_text (uiout
, " Cannot determine contents\n");
1272 /* Stuff that needs to be done by the finish command after the target
1273 has stopped. In asynchronous mode, we wait for the target to stop
1274 in the call to poll or select in the event loop, so it is
1275 impossible to do all the stuff as part of the finish_command
1276 function itself. The only chance we have to complete this command
1277 is in fetch_inferior_event, which is called by the event loop as
1278 soon as it detects that the target has stopped. This function is
1279 called via the cmd_continuation pointer. */
1282 finish_command_continuation (struct continuation_arg
*arg
, int error_p
)
1284 struct symbol
*function
;
1285 struct breakpoint
*breakpoint
;
1286 struct cleanup
*cleanups
;
1288 breakpoint
= (struct breakpoint
*) arg
->data
.pointer
;
1289 function
= (struct symbol
*) arg
->next
->data
.pointer
;
1293 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1294 && function
!= NULL
)
1296 struct type
*value_type
;
1298 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1300 internal_error (__FILE__
, __LINE__
,
1301 _("finish_command: function has no target type"));
1303 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1304 print_return_value (SYMBOL_TYPE (function
), value_type
);
1307 /* We suppress normal call of normal_stop observer and do it here so that
1308 that *stopped notification includes the return value. */
1309 observer_notify_normal_stop (stop_bpstat
);
1312 suppress_stop_observer
= 0;
1313 delete_breakpoint (breakpoint
);
1316 /* "finish": Set a temporary breakpoint at the place the selected
1317 frame will return to, then continue. */
1320 finish_command (char *arg
, int from_tty
)
1322 struct symtab_and_line sal
;
1323 struct frame_info
*frame
;
1324 struct symbol
*function
;
1325 struct breakpoint
*breakpoint
;
1326 struct cleanup
*old_chain
;
1327 struct continuation_arg
*arg1
, *arg2
, *arg3
;
1331 /* Find out whether we must run in the background. */
1333 async_exec
= strip_bg_char (&arg
);
1335 /* If we must run in the background, but the target can't do it,
1337 if (async_exec
&& !target_can_async_p ())
1338 error (_("Asynchronous execution not supported on this target."));
1340 /* If we are not asked to run in the bg, then prepare to run in the
1341 foreground, synchronously. */
1342 if (!async_exec
&& target_can_async_p ())
1344 /* Simulate synchronous execution. */
1345 async_disable_stdin ();
1349 error (_("The \"finish\" command does not take any arguments."));
1350 if (!target_has_execution
)
1351 error (_("The program is not running."));
1353 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1355 error (_("\"finish\" not meaningful in the outermost frame."));
1357 clear_proceed_status ();
1359 sal
= find_pc_line (get_frame_pc (frame
), 0);
1360 sal
.pc
= get_frame_pc (frame
);
1362 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
), bp_finish
);
1364 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1366 /* Find the function we will return from. */
1368 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1370 /* Print info on the selected frame, including level number but not
1374 printf_filtered (_("Run till exit from "));
1375 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1378 proceed_to_finish
= 1; /* We want stop_registers, please... */
1379 make_cleanup_restore_integer (&suppress_stop_observer
);
1380 suppress_stop_observer
= 1;
1381 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1384 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1386 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1389 arg1
->data
.pointer
= breakpoint
;
1390 arg2
->data
.pointer
= function
;
1391 add_continuation (finish_command_continuation
, arg1
);
1393 discard_cleanups (old_chain
);
1394 if (!target_can_async_p ())
1395 do_all_continuations (0);
1400 program_info (char *args
, int from_tty
)
1402 bpstat bs
= stop_bpstat
;
1404 int stat
= bpstat_num (&bs
, &num
);
1406 if (!target_has_execution
)
1408 printf_filtered (_("The program being debugged is not being run.\n"));
1412 target_files_info ();
1413 printf_filtered (_("Program stopped at %s.\n"),
1414 hex_string ((unsigned long) stop_pc
));
1416 printf_filtered (_("It stopped after being stepped.\n"));
1419 /* There may be several breakpoints in the same place, so this
1420 isn't as strange as it seems. */
1425 printf_filtered (_("\
1426 It stopped at a breakpoint that has since been deleted.\n"));
1429 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1430 stat
= bpstat_num (&bs
, &num
);
1433 else if (stop_signal
!= TARGET_SIGNAL_0
)
1435 printf_filtered (_("It stopped with signal %s, %s.\n"),
1436 target_signal_to_name (stop_signal
),
1437 target_signal_to_string (stop_signal
));
1442 printf_filtered (_("\
1443 Type \"info stack\" or \"info registers\" for more information.\n"));
1448 environment_info (char *var
, int from_tty
)
1452 char *val
= get_in_environ (inferior_environ
, var
);
1455 puts_filtered (var
);
1456 puts_filtered (" = ");
1457 puts_filtered (val
);
1458 puts_filtered ("\n");
1462 puts_filtered ("Environment variable \"");
1463 puts_filtered (var
);
1464 puts_filtered ("\" not defined.\n");
1469 char **vector
= environ_vector (inferior_environ
);
1472 puts_filtered (*vector
++);
1473 puts_filtered ("\n");
1479 set_environment_command (char *arg
, int from_tty
)
1481 char *p
, *val
, *var
;
1485 error_no_arg (_("environment variable and value"));
1487 /* Find seperation between variable name and value */
1488 p
= (char *) strchr (arg
, '=');
1489 val
= (char *) strchr (arg
, ' ');
1491 if (p
!= 0 && val
!= 0)
1493 /* We have both a space and an equals. If the space is before the
1494 equals, walk forward over the spaces til we see a nonspace
1495 (possibly the equals). */
1500 /* Now if the = is after the char following the spaces,
1501 take the char following the spaces. */
1505 else if (val
!= 0 && p
== 0)
1509 error_no_arg (_("environment variable to set"));
1511 if (p
== 0 || p
[1] == 0)
1515 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1519 /* Not setting variable value to null */
1521 while (*val
== ' ' || *val
== '\t')
1525 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1528 var
= savestring (arg
, p
- arg
);
1531 printf_filtered (_("\
1532 Setting environment variable \"%s\" to null value.\n"),
1534 set_in_environ (inferior_environ
, var
, "");
1537 set_in_environ (inferior_environ
, var
, val
);
1542 unset_environment_command (char *var
, int from_tty
)
1546 /* If there is no argument, delete all environment variables.
1547 Ask for confirmation if reading from the terminal. */
1548 if (!from_tty
|| query (_("Delete all environment variables? ")))
1550 free_environ (inferior_environ
);
1551 inferior_environ
= make_environ ();
1555 unset_in_environ (inferior_environ
, var
);
1558 /* Handle the execution path (PATH variable) */
1560 static const char path_var_name
[] = "PATH";
1563 path_info (char *args
, int from_tty
)
1565 puts_filtered ("Executable and object file path: ");
1566 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1567 puts_filtered ("\n");
1570 /* Add zero or more directories to the front of the execution path. */
1573 path_command (char *dirname
, int from_tty
)
1578 env
= get_in_environ (inferior_environ
, path_var_name
);
1579 /* Can be null if path is not set */
1582 exec_path
= xstrdup (env
);
1583 mod_path (dirname
, &exec_path
);
1584 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1587 path_info ((char *) NULL
, from_tty
);
1591 /* Print out the machine register regnum. If regnum is -1, print all
1592 registers (print_all == 1) or all non-float and non-vector
1593 registers (print_all == 0).
1595 For most machines, having all_registers_info() print the
1596 register(s) one per line is good enough. If a different format is
1597 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1598 regs), or there is an existing convention for showing all the
1599 registers, define the architecture method PRINT_REGISTERS_INFO to
1600 provide that format. */
1603 default_print_registers_info (struct gdbarch
*gdbarch
,
1604 struct ui_file
*file
,
1605 struct frame_info
*frame
,
1606 int regnum
, int print_all
)
1609 const int numregs
= gdbarch_num_regs (gdbarch
)
1610 + gdbarch_num_pseudo_regs (gdbarch
);
1611 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1613 for (i
= 0; i
< numregs
; i
++)
1615 /* Decide between printing all regs, non-float / vector regs, or
1621 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1626 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1636 /* If the register name is empty, it is undefined for this
1637 processor, so don't display anything. */
1638 if (gdbarch_register_name (gdbarch
, i
) == NULL
1639 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1642 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1643 print_spaces_filtered (15 - strlen (gdbarch_register_name
1644 (gdbarch
, i
)), file
);
1646 /* Get the data in raw format. */
1647 if (! frame_register_read (frame
, i
, buffer
))
1649 fprintf_filtered (file
, "*value not available*\n");
1653 /* If virtual format is floating, print it that way, and in raw
1655 if (TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_FLT
1656 || TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_DECFLOAT
)
1660 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1661 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1663 fprintf_filtered (file
, "\t(raw 0x");
1664 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
1667 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1670 idx
= register_size (gdbarch
, i
) - 1 - j
;
1671 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
1673 fprintf_filtered (file
, ")");
1677 /* Print the register in hex. */
1678 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1679 file
, 'x', 1, 0, Val_pretty_default
, current_language
);
1680 /* If not a vector register, print it also according to its
1682 if (TYPE_VECTOR (register_type (gdbarch
, i
)) == 0)
1684 fprintf_filtered (file
, "\t");
1685 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1686 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1690 fprintf_filtered (file
, "\n");
1695 registers_info (char *addr_exp
, int fpregs
)
1697 struct frame_info
*frame
;
1698 struct gdbarch
*gdbarch
;
1699 int regnum
, numregs
;
1702 if (!target_has_registers
)
1703 error (_("The program has no registers now."));
1704 frame
= get_selected_frame (NULL
);
1705 gdbarch
= get_frame_arch (frame
);
1709 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1714 while (*addr_exp
!= '\0')
1719 /* Keep skipping leading white space. */
1720 if (isspace ((*addr_exp
)))
1726 /* Discard any leading ``$''. Check that there is something
1727 resembling a register following it. */
1728 if (addr_exp
[0] == '$')
1730 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
1731 error (_("Missing register name"));
1733 /* Find the start/end of this register name/num/group. */
1735 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
1739 /* Figure out what we've found and display it. */
1741 /* A register name? */
1743 int regnum
= frame_map_name_to_regnum (frame
, start
, end
- start
);
1746 /* User registers lie completely outside of the range of
1747 normal registers. Catch them early so that the target
1749 if (regnum
>= gdbarch_num_regs (gdbarch
)
1750 + gdbarch_num_pseudo_regs (gdbarch
))
1752 struct value
*val
= value_of_user_reg (regnum
, frame
);
1754 printf_filtered ("%s: ", start
);
1755 print_scalar_formatted (value_contents (val
),
1756 check_typedef (value_type (val
)),
1757 'x', 0, gdb_stdout
);
1758 printf_filtered ("\n");
1761 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1762 frame
, regnum
, fpregs
);
1767 /* A register number? (how portable is this one?). */
1770 int regnum
= strtol (start
, &endptr
, 0);
1773 && regnum
< gdbarch_num_regs (gdbarch
)
1774 + gdbarch_num_pseudo_regs (gdbarch
))
1776 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1777 frame
, regnum
, fpregs
);
1782 /* A register group? */
1784 struct reggroup
*group
;
1785 for (group
= reggroup_next (gdbarch
, NULL
);
1787 group
= reggroup_next (gdbarch
, group
))
1789 /* Don't bother with a length check. Should the user
1790 enter a short register group name, go with the first
1791 group that matches. */
1792 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
1799 regnum
< gdbarch_num_regs (gdbarch
)
1800 + gdbarch_num_pseudo_regs (gdbarch
);
1803 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1804 gdbarch_print_registers_info (gdbarch
,
1812 /* Nothing matched. */
1813 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
1818 all_registers_info (char *addr_exp
, int from_tty
)
1820 registers_info (addr_exp
, 1);
1824 nofp_registers_info (char *addr_exp
, int from_tty
)
1826 registers_info (addr_exp
, 0);
1830 print_vector_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1831 struct frame_info
*frame
, const char *args
)
1833 if (gdbarch_print_vector_info_p (gdbarch
))
1834 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
1838 int printed_something
= 0;
1841 regnum
< gdbarch_num_regs (gdbarch
)
1842 + gdbarch_num_pseudo_regs (gdbarch
);
1845 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
1847 printed_something
= 1;
1848 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
1851 if (!printed_something
)
1852 fprintf_filtered (file
, "No vector information\n");
1857 vector_info (char *args
, int from_tty
)
1859 if (!target_has_registers
)
1860 error (_("The program has no registers now."));
1862 print_vector_info (current_gdbarch
, gdb_stdout
,
1863 get_selected_frame (NULL
), args
);
1869 * Should save/restore the tty state since it might be that the
1870 * program to be debugged was started on this tty and it wants
1871 * the tty in some state other than what we want. If it's running
1872 * on another terminal or without a terminal, then saving and
1873 * restoring the tty state is a harmless no-op.
1874 * This only needs to be done if we are attaching to a process.
1879 takes a program started up outside of gdb and ``attaches'' to it.
1880 This stops it cold in its tracks and allows us to start debugging it.
1881 and wait for the trace-trap that results from attaching. */
1884 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
1887 char *full_exec_path
= NULL
;
1889 stop_soon
= NO_STOP_QUIETLY
;
1891 /* If no exec file is yet known, try to determine it from the
1893 exec_file
= (char *) get_exec_file (0);
1896 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
1899 /* It's possible we don't have a full path, but rather just a
1900 filename. Some targets, such as HP-UX, don't provide the
1903 Attempt to qualify the filename against the source path.
1904 (If that fails, we'll just fall back on the original
1905 filename. Not much more we can do...)
1907 if (!source_full_path_of (exec_file
, &full_exec_path
))
1908 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
1910 exec_file_attach (full_exec_path
, from_tty
);
1911 symbol_file_add_main (full_exec_path
, from_tty
);
1916 reopen_exec_file ();
1920 /* Take any necessary post-attaching actions for this platform. */
1921 target_post_attach (PIDGET (inferior_ptid
));
1923 post_create_inferior (¤t_target
, from_tty
);
1925 /* Install inferior's terminal modes. */
1926 target_terminal_inferior ();
1929 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
1932 if (target_can_async_p ())
1933 async_enable_stdin ();
1935 if (deprecated_attach_hook
)
1936 deprecated_attach_hook ();
1941 attach_command_continuation (struct continuation_arg
*arg
, int error_p
)
1947 args
= (char *) arg
->data
.pointer
;
1948 from_tty
= arg
->next
->data
.integer
;
1949 async_exec
= arg
->next
->next
->data
.integer
;
1951 attach_command_post_wait (args
, from_tty
, async_exec
);
1955 attach_command (char *args
, int from_tty
)
1958 char *full_exec_path
= NULL
;
1961 dont_repeat (); /* Not for the faint of heart */
1963 if (target_has_execution
)
1965 if (query ("A program is being debugged already. Kill it? "))
1968 error (_("Not killed."));
1971 /* Clean up any leftovers from other runs. Some other things from
1972 this function should probably be moved into target_pre_inferior. */
1973 target_pre_inferior (from_tty
);
1975 /* Clear out solib state. Otherwise the solib state of the previous
1976 inferior might have survived and is entirely wrong for the new
1977 target. This has been observed on GNU/Linux using glibc 2.3. How
1989 Cannot access memory at address 0xdeadbeef
1995 async_exec
= strip_bg_char (&args
);
1997 /* If we get a request for running in the bg but the target
1998 doesn't support it, error out. */
1999 if (async_exec
&& !target_can_async_p ())
2000 error (_("Asynchronous execution not supported on this target."));
2003 /* If we don't get a request of running in the bg, then we need
2004 to simulate synchronous (fg) execution. */
2005 if (!async_exec
&& target_can_async_p ())
2007 /* Simulate synchronous execution */
2008 async_disable_stdin ();
2011 target_attach (args
, from_tty
);
2013 /* Set up the "saved terminal modes" of the inferior
2014 based on what modes we are starting it with. */
2015 target_terminal_init ();
2017 /* Set up execution context to know that we should return from
2018 wait_for_inferior as soon as the target reports a stop. */
2019 init_wait_for_inferior ();
2020 clear_proceed_status ();
2022 /* Some system don't generate traps when attaching to inferior.
2023 E.g. Mach 3 or GNU hurd. */
2024 if (!target_attach_no_wait
)
2026 /* Careful here. See comments in inferior.h. Basically some
2027 OSes don't ignore SIGSTOPs on continue requests anymore. We
2028 need a way for handle_inferior_event to reset the stop_signal
2029 variable after an attach, and this is what
2030 STOP_QUIETLY_NO_SIGSTOP is for. */
2031 stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2033 if (target_can_async_p ())
2035 /* sync_execution mode. Wait for stop. */
2036 struct continuation_arg
*arg1
, *arg2
, *arg3
;
2039 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2041 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2043 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2047 arg1
->data
.pointer
= args
;
2048 arg2
->data
.integer
= from_tty
;
2049 arg3
->data
.integer
= async_exec
;
2050 add_continuation (attach_command_continuation
, arg1
);
2054 wait_for_inferior (0);
2057 attach_command_post_wait (args
, from_tty
, async_exec
);
2062 * takes a program previously attached to and detaches it.
2063 * The program resumes execution and will no longer stop
2064 * on signals, etc. We better not have left any breakpoints
2065 * in the program or it'll die when it hits one. For this
2066 * to work, it may be necessary for the process to have been
2067 * previously attached. It *might* work if the program was
2068 * started via the normal ptrace (PTRACE_TRACEME).
2072 detach_command (char *args
, int from_tty
)
2074 dont_repeat (); /* Not for the faint of heart. */
2075 target_detach (args
, from_tty
);
2076 no_shared_libraries (NULL
, from_tty
);
2077 init_thread_list ();
2078 if (deprecated_detach_hook
)
2079 deprecated_detach_hook ();
2082 /* Disconnect from the current target without resuming it (leaving it
2083 waiting for a debugger).
2085 We'd better not have left any breakpoints in the program or the
2086 next debugger will get confused. Currently only supported for some
2087 remote targets, since the normal attach mechanisms don't work on
2088 stopped processes on some native platforms (e.g. GNU/Linux). */
2091 disconnect_command (char *args
, int from_tty
)
2093 dont_repeat (); /* Not for the faint of heart */
2094 target_disconnect (args
, from_tty
);
2095 no_shared_libraries (NULL
, from_tty
);
2096 init_thread_list ();
2097 if (deprecated_detach_hook
)
2098 deprecated_detach_hook ();
2101 /* Stop the execution of the target while running in async mode, in
2104 interrupt_target_command (char *args
, int from_tty
)
2106 if (target_can_async_p ())
2108 dont_repeat (); /* Not for the faint of heart */
2110 target_stop (inferior_ptid
);
2115 print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2116 struct frame_info
*frame
, const char *args
)
2118 if (gdbarch_print_float_info_p (gdbarch
))
2119 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2123 int printed_something
= 0;
2126 regnum
< gdbarch_num_regs (gdbarch
)
2127 + gdbarch_num_pseudo_regs (gdbarch
);
2130 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2132 printed_something
= 1;
2133 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2136 if (!printed_something
)
2137 fprintf_filtered (file
, "\
2138 No floating-point info available for this processor.\n");
2143 float_info (char *args
, int from_tty
)
2145 if (!target_has_registers
)
2146 error (_("The program has no registers now."));
2148 print_float_info (current_gdbarch
, gdb_stdout
,
2149 get_selected_frame (NULL
), args
);
2153 unset_command (char *args
, int from_tty
)
2155 printf_filtered (_("\
2156 \"unset\" must be followed by the name of an unset subcommand.\n"));
2157 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2161 _initialize_infcmd (void)
2163 struct cmd_list_element
*c
= NULL
;
2165 /* add the filename of the terminal connected to inferior I/O */
2166 add_setshow_filename_cmd ("inferior-tty", class_run
,
2167 &inferior_io_terminal
, _("\
2168 Set terminal for future runs of program being debugged."), _("\
2169 Show terminal for future runs of program being debugged."), _("\
2170 Usage: set inferior-tty /dev/pts/1"), NULL
, NULL
, &setlist
, &showlist
);
2171 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2173 add_setshow_optional_filename_cmd ("args", class_run
,
2174 &inferior_args
, _("\
2175 Set argument list to give program being debugged when it is started."), _("\
2176 Show argument list to give program being debugged when it is started."), _("\
2177 Follow this command with any number of args, to be passed to the program."),
2180 &setlist
, &showlist
);
2182 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2183 The environment to give the program, or one variable's value.\n\
2184 With an argument VAR, prints the value of environment variable VAR to\n\
2185 give the program being debugged. With no arguments, prints the entire\n\
2186 environment to be given to the program."), &showlist
);
2187 set_cmd_completer (c
, noop_completer
);
2189 add_prefix_cmd ("unset", no_class
, unset_command
,
2190 _("Complement to certain \"set\" commands."),
2191 &unsetlist
, "unset ", 0, &cmdlist
);
2193 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2194 Cancel environment variable VAR for the program.\n\
2195 This does not affect the program until the next \"run\" command."),
2197 set_cmd_completer (c
, noop_completer
);
2199 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2200 Set environment variable value to give the program.\n\
2201 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2202 VALUES of environment variables are uninterpreted strings.\n\
2203 This does not affect the program until the next \"run\" command."),
2205 set_cmd_completer (c
, noop_completer
);
2207 c
= add_com ("path", class_files
, path_command
, _("\
2208 Add directory DIR(s) to beginning of search path for object files.\n\
2209 $cwd in the path means the current working directory.\n\
2210 This path is equivalent to the $PATH shell variable. It is a list of\n\
2211 directories, separated by colons. These directories are searched to find\n\
2212 fully linked executable files and separately compiled object files as needed."));
2213 set_cmd_completer (c
, filename_completer
);
2215 c
= add_cmd ("paths", no_class
, path_info
, _("\
2216 Current search path for finding object files.\n\
2217 $cwd in the path means the current working directory.\n\
2218 This path is equivalent to the $PATH shell variable. It is a list of\n\
2219 directories, separated by colons. These directories are searched to find\n\
2220 fully linked executable files and separately compiled object files as needed."),
2222 set_cmd_completer (c
, noop_completer
);
2224 add_com ("attach", class_run
, attach_command
, _("\
2225 Attach to a process or file outside of GDB.\n\
2226 This command attaches to another target, of the same type as your last\n\
2227 \"target\" command (\"info files\" will show your target stack).\n\
2228 The command may take as argument a process id or a device file.\n\
2229 For a process id, you must have permission to send the process a signal,\n\
2230 and it must have the same effective uid as the debugger.\n\
2231 When using \"attach\" with a process id, the debugger finds the\n\
2232 program running in the process, looking first in the current working\n\
2233 directory, or (if not found there) using the source file search path\n\
2234 (see the \"directory\" command). You can also use the \"file\" command\n\
2235 to specify the program, and to load its symbol table."));
2237 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2238 Detach a process or file previously attached.\n\
2239 If a process, it is no longer traced, and it continues its execution. If\n\
2240 you were debugging a file, the file is closed and gdb no longer accesses it."),
2241 &detachlist
, "detach ", 0, &cmdlist
);
2243 add_com ("disconnect", class_run
, disconnect_command
, _("\
2244 Disconnect from a target.\n\
2245 The target will wait for another debugger to connect. Not available for\n\
2248 add_com ("signal", class_run
, signal_command
, _("\
2249 Continue program giving it signal specified by the argument.\n\
2250 An argument of \"0\" means continue program without giving it a signal."));
2252 add_com ("stepi", class_run
, stepi_command
, _("\
2253 Step one instruction exactly.\n\
2254 Argument N means do this N times (or till program stops for another reason)."));
2255 add_com_alias ("si", "stepi", class_alias
, 0);
2257 add_com ("nexti", class_run
, nexti_command
, _("\
2258 Step one instruction, but proceed through subroutine calls.\n\
2259 Argument N means do this N times (or till program stops for another reason)."));
2260 add_com_alias ("ni", "nexti", class_alias
, 0);
2262 add_com ("finish", class_run
, finish_command
, _("\
2263 Execute until selected stack frame returns.\n\
2264 Upon return, the value returned is printed and put in the value history."));
2265 add_com_alias ("fin", "finish", class_run
, 1);
2267 add_com ("next", class_run
, next_command
, _("\
2268 Step program, proceeding through subroutine calls.\n\
2269 Like the \"step\" command as long as subroutine calls do not happen;\n\
2270 when they do, the call is treated as one instruction.\n\
2271 Argument N means do this N times (or till program stops for another reason)."));
2272 add_com_alias ("n", "next", class_run
, 1);
2274 add_com_alias ("S", "next", class_run
, 1);
2276 add_com ("step", class_run
, step_command
, _("\
2277 Step program until it reaches a different source line.\n\
2278 Argument N means do this N times (or till program stops for another reason)."));
2279 add_com_alias ("s", "step", class_run
, 1);
2281 c
= add_com ("until", class_run
, until_command
, _("\
2282 Execute until the program reaches a source line greater than the current\n\
2283 or a specified location (same args as break command) within the current frame."));
2284 set_cmd_completer (c
, location_completer
);
2285 add_com_alias ("u", "until", class_run
, 1);
2287 c
= add_com ("advance", class_run
, advance_command
, _("\
2288 Continue the program up to the given location (same form as args for break command).\n\
2289 Execution will also stop upon exit from the current stack frame."));
2290 set_cmd_completer (c
, location_completer
);
2292 c
= add_com ("jump", class_run
, jump_command
, _("\
2293 Continue program being debugged at specified line or address.\n\
2294 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2295 for an address to start at."));
2296 set_cmd_completer (c
, location_completer
);
2300 c
= add_com ("go", class_run
, go_command
, _("\
2301 Usage: go <location>\n\
2302 Continue program being debugged, stopping at specified line or \n\
2304 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2305 expression for an address to start at.\n\
2306 This command is a combination of tbreak and jump."));
2307 set_cmd_completer (c
, location_completer
);
2311 add_com_alias ("g", "go", class_run
, 1);
2313 add_com ("continue", class_run
, continue_command
, _("\
2314 Continue program being debugged, after signal or breakpoint.\n\
2315 If proceeding from breakpoint, a number N may be used as an argument,\n\
2316 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2317 the breakpoint won't break until the Nth time it is reached)."));
2318 add_com_alias ("c", "cont", class_run
, 1);
2319 add_com_alias ("fg", "cont", class_run
, 1);
2321 c
= add_com ("run", class_run
, run_command
, _("\
2322 Start debugged program. You may specify arguments to give it.\n\
2323 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2324 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2325 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2326 To cancel previous arguments and run with no arguments,\n\
2327 use \"set args\" without arguments."));
2328 set_cmd_completer (c
, filename_completer
);
2329 add_com_alias ("r", "run", class_run
, 1);
2331 add_com ("R", class_run
, run_no_args_command
,
2332 _("Start debugged program with no arguments."));
2334 c
= add_com ("start", class_run
, start_command
, _("\
2335 Run the debugged program until the beginning of the main procedure.\n\
2336 You may specify arguments to give to your program, just as with the\n\
2337 \"run\" command."));
2338 set_cmd_completer (c
, filename_completer
);
2340 c
= add_com ("interrupt", class_run
, interrupt_target_command
,
2341 _("Interrupt the execution of the debugged program."));
2342 set_cmd_async_ok (c
);
2344 add_info ("registers", nofp_registers_info
, _("\
2345 List of integer registers and their contents, for selected stack frame.\n\
2346 Register name as argument means describe only that register."));
2347 add_info_alias ("r", "registers", 1);
2350 add_com ("lr", class_info
, nofp_registers_info
, _("\
2351 List of integer registers and their contents, for selected stack frame.\n\
2352 Register name as argument means describe only that register."));
2353 add_info ("all-registers", all_registers_info
, _("\
2354 List of all registers and their contents, for selected stack frame.\n\
2355 Register name as argument means describe only that register."));
2357 add_info ("program", program_info
,
2358 _("Execution status of the program."));
2360 add_info ("float", float_info
,
2361 _("Print the status of the floating point unit\n"));
2363 add_info ("vector", vector_info
,
2364 _("Print the status of the vector unit\n"));
2366 inferior_environ
= make_environ ();
2367 init_environ (inferior_environ
);