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 /* Accessor routines. */
213 set_inferior_io_terminal (const char *terminal_name
)
215 if (inferior_io_terminal
)
216 xfree (inferior_io_terminal
);
219 inferior_io_terminal
= NULL
;
221 inferior_io_terminal
= savestring (terminal_name
, strlen (terminal_name
));
225 get_inferior_io_terminal (void)
227 return inferior_io_terminal
;
231 get_inferior_args (void)
233 if (inferior_argc
!= 0)
237 n
= gdbarch_construct_inferior_arguments (current_gdbarch
,
238 inferior_argc
, inferior_argv
);
239 old
= set_inferior_args (n
);
243 if (inferior_args
== NULL
)
244 inferior_args
= xstrdup ("");
246 return inferior_args
;
250 set_inferior_args (char *newargs
)
252 char *saved_args
= inferior_args
;
254 inferior_args
= newargs
;
262 set_inferior_args_vector (int argc
, char **argv
)
264 inferior_argc
= argc
;
265 inferior_argv
= argv
;
268 /* Notice when `set args' is run. */
270 notice_args_set (char *args
, int from_tty
, struct cmd_list_element
*c
)
276 /* Notice when `show args' is run. */
278 notice_args_read (struct ui_file
*file
, int from_tty
,
279 struct cmd_list_element
*c
, const char *value
)
281 /* Note that we ignore the passed-in value in favor of computing it
283 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
287 /* Compute command-line string given argument vector. This does the
288 same shell processing as fork_inferior. */
290 construct_inferior_arguments (struct gdbarch
*gdbarch
, int argc
, char **argv
)
294 if (STARTUP_WITH_SHELL
)
296 /* This holds all the characters considered special to the
297 typical Unix shells. We include `^' because the SunOS
298 /bin/sh treats it as a synonym for `|'. */
299 char *special
= "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
304 /* We over-compute the size. It shouldn't matter. */
305 for (i
= 0; i
< argc
; ++i
)
306 length
+= 2 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
308 result
= (char *) xmalloc (length
);
311 for (i
= 0; i
< argc
; ++i
)
316 /* Need to handle empty arguments specially. */
317 if (argv
[i
][0] == '\0')
324 for (cp
= argv
[i
]; *cp
; ++cp
)
326 if (strchr (special
, *cp
) != NULL
)
336 /* In this case we can't handle arguments that contain spaces,
337 tabs, or newlines -- see breakup_args(). */
341 for (i
= 0; i
< argc
; ++i
)
343 char *cp
= strchr (argv
[i
], ' ');
345 cp
= strchr (argv
[i
], '\t');
347 cp
= strchr (argv
[i
], '\n');
349 error (_("can't handle command-line argument containing whitespace"));
350 length
+= strlen (argv
[i
]) + 1;
353 result
= (char *) xmalloc (length
);
355 for (i
= 0; i
< argc
; ++i
)
358 strcat (result
, " ");
359 strcat (result
, argv
[i
]);
367 /* This function detects whether or not a '&' character (indicating
368 background execution) has been added as *the last* of the arguments ARGS
369 of a command. If it has, it removes it and returns 1. Otherwise it
370 does nothing and returns 0. */
372 strip_bg_char (char **args
)
376 p
= strchr (*args
, '&');
380 if (p
== (*args
+ strlen (*args
) - 1))
382 if (strlen (*args
) > 1)
386 while (*p
== ' ' || *p
== '\t');
398 tty_command (char *file
, int from_tty
)
401 error_no_arg (_("terminal name for running target process"));
403 set_inferior_io_terminal (file
);
406 /* Common actions to take after creating any sort of inferior, by any
407 means (running, attaching, connecting, et cetera). The target
408 should be stopped. */
411 post_create_inferior (struct target_ops
*target
, int from_tty
)
413 /* Be sure we own the terminal in case write operations are performed. */
414 target_terminal_ours ();
416 /* If the target hasn't taken care of this already, do it now.
417 Targets which need to access registers during to_open,
418 to_create_inferior, or to_attach should do it earlier; but many
420 target_find_description ();
424 /* Sometimes the platform-specific hook loads initial shared
425 libraries, and sometimes it doesn't. Try to do so first, so
426 that we can add them with the correct value for FROM_TTY.
427 If we made all the inferior hook methods consistent,
428 this call could be removed. */
430 SOLIB_ADD (NULL
, from_tty
, target
, auto_solib_add
);
432 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
435 /* Create the hooks to handle shared library load and unload
437 #ifdef SOLIB_CREATE_INFERIOR_HOOK
438 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
440 solib_create_inferior_hook ();
444 observer_notify_inferior_created (target
, from_tty
);
447 /* Kill the inferior if already running. This function is designed
448 to be called when we are about to start the execution of the program
449 from the beginning. Ask the user to confirm that he wants to restart
450 the program being debugged when FROM_TTY is non-null. */
453 kill_if_already_running (int from_tty
)
455 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
457 /* Bail out before killing the program if we will not be able to
459 target_require_runnable ();
462 && !query ("The program being debugged has been started already.\n\
463 Start it from the beginning? "))
464 error (_("Program not restarted."));
466 no_shared_libraries (NULL
, from_tty
);
467 init_wait_for_inferior ();
471 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
472 a temporary breakpoint at the begining of the main program before
473 running the program. */
476 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
482 kill_if_already_running (from_tty
);
483 clear_breakpoint_hit_counts ();
485 /* Clean up any leftovers from other runs. Some other things from
486 this function should probably be moved into target_pre_inferior. */
487 target_pre_inferior (from_tty
);
489 /* Purge old solib objfiles. */
490 objfile_purge_solibs ();
494 /* The comment here used to read, "The exec file is re-read every
495 time we do a generic_mourn_inferior, so we just have to worry
496 about the symbol file." The `generic_mourn_inferior' function
497 gets called whenever the program exits. However, suppose the
498 program exits, and *then* the executable file changes? We need
499 to check again here. Since reopen_exec_file doesn't do anything
500 if the timestamp hasn't changed, I don't see the harm. */
504 /* Insert the temporary breakpoint if a location was specified. */
506 tbreak_command (main_name (), 0);
508 exec_file
= (char *) get_exec_file (0);
510 /* We keep symbols from add-symbol-file, on the grounds that the
511 user might want to add some symbols before running the program
512 (right?). But sometimes (dynamic loading where the user manually
513 introduces the new symbols with add-symbol-file), the code which
514 the symbols describe does not persist between runs. Currently
515 the user has to manually nuke all symbols between runs if they
516 want them to go away (PR 2207). This is probably reasonable. */
520 if (target_can_async_p ())
521 async_disable_stdin ();
525 int async_exec
= strip_bg_char (&args
);
527 /* If we get a request for running in the bg but the target
528 doesn't support it, error out. */
529 if (async_exec
&& !target_can_async_p ())
530 error (_("Asynchronous execution not supported on this target."));
532 /* If we don't get a request of running in the bg, then we need
533 to simulate synchronous (fg) execution. */
534 if (!async_exec
&& target_can_async_p ())
536 /* Simulate synchronous execution */
537 async_disable_stdin ();
540 /* If there were other args, beside '&', process them. */
543 char *old_args
= set_inferior_args (xstrdup (args
));
550 ui_out_field_string (uiout
, NULL
, "Starting program");
551 ui_out_text (uiout
, ": ");
553 ui_out_field_string (uiout
, "execfile", exec_file
);
554 ui_out_spaces (uiout
, 1);
555 /* We call get_inferior_args() because we might need to compute
557 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
558 ui_out_text (uiout
, "\n");
559 ui_out_flush (uiout
);
562 /* We call get_inferior_args() because we might need to compute
564 target_create_inferior (exec_file
, get_inferior_args (),
565 environ_vector (inferior_environ
), from_tty
);
567 /* Pass zero for FROM_TTY, because at this point the "run" command
568 has done its thing; now we are setting up the running program. */
569 post_create_inferior (¤t_target
, 0);
571 /* Start the target running. */
572 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
577 run_command (char *args
, int from_tty
)
579 run_command_1 (args
, from_tty
, 0);
583 run_no_args_command (char *args
, int from_tty
)
585 char *old_args
= set_inferior_args (xstrdup (""));
590 /* Start the execution of the program up until the beginning of the main
594 start_command (char *args
, int from_tty
)
596 /* Some languages such as Ada need to search inside the program
597 minimal symbols for the location where to put the temporary
598 breakpoint before starting. */
599 if (!have_minimal_symbols ())
600 error (_("No symbol table loaded. Use the \"file\" command."));
602 /* Run the program until reaching the main procedure... */
603 run_command_1 (args
, from_tty
, 1);
607 continue_command (char *proc_count_exp
, int from_tty
)
612 /* Find out whether we must run in the background. */
613 if (proc_count_exp
!= NULL
)
614 async_exec
= strip_bg_char (&proc_count_exp
);
616 /* If we must run in the background, but the target can't do it,
618 if (async_exec
&& !target_can_async_p ())
619 error (_("Asynchronous execution not supported on this target."));
621 /* If we are not asked to run in the bg, then prepare to run in the
622 foreground, synchronously. */
623 if (!async_exec
&& target_can_async_p ())
625 /* Simulate synchronous execution */
626 async_disable_stdin ();
629 /* If have argument (besides '&'), set proceed count of breakpoint
631 if (proc_count_exp
!= NULL
)
633 bpstat bs
= stop_bpstat
;
637 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
640 set_ignore_count (num
,
641 parse_and_eval_long (proc_count_exp
) - 1,
643 /* set_ignore_count prints a message ending with a period.
644 So print two spaces before "Continuing.". */
646 printf_filtered (" ");
650 if (!stopped
&& from_tty
)
653 ("Not stopped at any breakpoint; argument ignored.\n");
658 printf_filtered (_("Continuing.\n"));
660 clear_proceed_status ();
662 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
665 /* Step until outside of current statement. */
668 step_command (char *count_string
, int from_tty
)
670 step_1 (0, 0, count_string
);
673 /* Likewise, but skip over subroutine calls as if single instructions. */
676 next_command (char *count_string
, int from_tty
)
678 step_1 (1, 0, count_string
);
681 /* Likewise, but step only one instruction. */
684 stepi_command (char *count_string
, int from_tty
)
686 step_1 (0, 1, count_string
);
690 nexti_command (char *count_string
, int from_tty
)
692 step_1 (1, 1, count_string
);
696 delete_longjmp_breakpoint_cleanup (void *arg
)
698 int thread
= * (int *) arg
;
699 delete_longjmp_breakpoint (thread
);
703 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
706 struct frame_info
*frame
;
707 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
714 async_exec
= strip_bg_char (&count_string
);
716 /* If we get a request for running in the bg but the target
717 doesn't support it, error out. */
718 if (async_exec
&& !target_can_async_p ())
719 error (_("Asynchronous execution not supported on this target."));
721 /* If we don't get a request of running in the bg, then we need
722 to simulate synchronous (fg) execution. */
723 if (!async_exec
&& target_can_async_p ())
725 /* Simulate synchronous execution */
726 async_disable_stdin ();
729 count
= count_string
? parse_and_eval_long (count_string
) : 1;
731 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
733 if (in_thread_list (inferior_ptid
))
734 thread
= pid_to_thread_id (inferior_ptid
);
736 set_longjmp_breakpoint ();
738 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
741 /* In synchronous case, all is well, just use the regular for loop. */
742 if (!target_can_async_p ())
744 for (; count
> 0; count
--)
746 clear_proceed_status ();
748 frame
= get_current_frame ();
749 if (!frame
) /* Avoid coredump here. Why tho? */
750 error (_("No current frame"));
751 step_frame_id
= get_frame_id (frame
);
755 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
756 if (step_range_end
== 0)
759 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
760 &step_range_end
) == 0)
761 error (_("Cannot find bounds of current function"));
763 target_terminal_ours ();
764 printf_filtered (_("\
765 Single stepping until exit from function %s, \n\
766 which has no line number information.\n"), name
);
771 /* Say we are stepping, but stop after one insn whatever it does. */
772 step_range_start
= step_range_end
= 1;
773 if (!skip_subroutines
)
775 Don't step over function calls, not even to functions lacking
777 step_over_calls
= STEP_OVER_NONE
;
780 if (skip_subroutines
)
781 step_over_calls
= STEP_OVER_ALL
;
783 step_multi
= (count
> 1);
784 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
790 do_cleanups (cleanups
);
793 /* In case of asynchronous target things get complicated, do only
794 one step for now, before returning control to the event loop. Let
795 the continuation figure out how many other steps we need to do,
796 and handle them one at the time, through step_once(). */
799 step_once (skip_subroutines
, single_inst
, count
, thread
);
800 /* We are running, and the continuation is installed. It will
801 disable the longjmp breakpoint as appropriate. */
802 discard_cleanups (cleanups
);
806 /* Called after we are done with one step operation, to check whether
807 we need to step again, before we print the prompt and return control
808 to the user. If count is > 1, we will need to do one more call to
809 proceed(), via step_once(). Basically it is like step_once and
810 step_1_continuation are co-recursive. */
812 step_1_continuation (struct continuation_arg
*arg
, int error_p
)
815 int skip_subroutines
;
819 skip_subroutines
= arg
->data
.integer
;
820 single_inst
= arg
->next
->data
.integer
;
821 count
= arg
->next
->next
->data
.integer
;
822 thread
= arg
->next
->next
->next
->data
.integer
;
824 if (error_p
|| !step_multi
|| !stop_step
)
826 /* We either hit an error, or stopped for some reason
827 that is not stepping, or there are no further steps
829 if (!single_inst
|| skip_subroutines
)
830 delete_longjmp_breakpoint (thread
);
834 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
837 /* Do just one step operation. If count >1 we will have to set up a
838 continuation to be done after the target stops (after this one
839 step). This is useful to implement the 'step n' kind of commands, in
840 case of asynchronous targets. We had to split step_1 into two parts,
841 one to be done before proceed() and one afterwards. This function is
842 called in case of step n with n>1, after the first step operation has
845 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
847 struct continuation_arg
*arg1
;
848 struct continuation_arg
*arg2
;
849 struct continuation_arg
*arg3
;
850 struct continuation_arg
*arg4
;
851 struct frame_info
*frame
;
855 clear_proceed_status ();
857 frame
= get_current_frame ();
858 if (!frame
) /* Avoid coredump here. Why tho? */
859 error (_("No current frame"));
860 step_frame_id
= get_frame_id (frame
);
864 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
866 /* If we have no line info, switch to stepi mode. */
867 if (step_range_end
== 0 && step_stop_if_no_debug
)
869 step_range_start
= step_range_end
= 1;
871 else if (step_range_end
== 0)
874 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
875 &step_range_end
) == 0)
876 error (_("Cannot find bounds of current function"));
878 target_terminal_ours ();
879 printf_filtered (_("\
880 Single stepping until exit from function %s, \n\
881 which has no line number information.\n"), name
);
886 /* Say we are stepping, but stop after one insn whatever it does. */
887 step_range_start
= step_range_end
= 1;
888 if (!skip_subroutines
)
890 Don't step over function calls, not even to functions lacking
892 step_over_calls
= STEP_OVER_NONE
;
895 if (skip_subroutines
)
896 step_over_calls
= STEP_OVER_ALL
;
898 step_multi
= (count
> 1);
899 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
901 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
903 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
905 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
907 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
909 arg1
->data
.integer
= skip_subroutines
;
911 arg2
->data
.integer
= single_inst
;
913 arg3
->data
.integer
= count
;
915 arg4
->data
.integer
= thread
;
916 add_intermediate_continuation (step_1_continuation
, arg1
);
921 /* Continue program at specified address. */
924 jump_command (char *arg
, int from_tty
)
927 struct symtabs_and_lines sals
;
928 struct symtab_and_line sal
;
935 /* Find out whether we must run in the background. */
937 async_exec
= strip_bg_char (&arg
);
939 /* If we must run in the background, but the target can't do it,
941 if (async_exec
&& !target_can_async_p ())
942 error (_("Asynchronous execution not supported on this target."));
945 error_no_arg (_("starting address"));
947 sals
= decode_line_spec_1 (arg
, 1);
950 error (_("Unreasonable jump request"));
956 if (sal
.symtab
== 0 && sal
.pc
== 0)
957 error (_("No source file has been specified."));
959 resolve_sal_pc (&sal
); /* May error out */
961 /* See if we are trying to jump to another function. */
962 fn
= get_frame_function (get_current_frame ());
963 sfn
= find_pc_function (sal
.pc
);
964 if (fn
!= NULL
&& sfn
!= fn
)
966 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
967 SYMBOL_PRINT_NAME (fn
)))
969 error (_("Not confirmed."));
976 fixup_symbol_section (sfn
, 0);
977 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn
)) &&
978 !section_is_mapped (SYMBOL_BFD_SECTION (sfn
)))
980 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
982 error (_("Not confirmed."));
992 printf_filtered (_("Continuing at "));
993 fputs_filtered (paddress (addr
), gdb_stdout
);
994 printf_filtered (".\n");
997 /* If we are not asked to run in the bg, then prepare to run in the
998 foreground, synchronously. */
999 if (!async_exec
&& target_can_async_p ())
1001 /* Simulate synchronous execution */
1002 async_disable_stdin ();
1005 clear_proceed_status ();
1006 proceed (addr
, TARGET_SIGNAL_0
, 0);
1010 /* Go to line or address in current procedure */
1012 go_command (char *line_no
, int from_tty
)
1014 if (line_no
== (char *) NULL
|| !*line_no
)
1015 printf_filtered (GO_USAGE
);
1018 tbreak_command (line_no
, from_tty
);
1019 jump_command (line_no
, from_tty
);
1024 /* Continue program giving it specified signal. */
1027 signal_command (char *signum_exp
, int from_tty
)
1029 enum target_signal oursig
;
1032 dont_repeat (); /* Too dangerous. */
1035 /* Find out whether we must run in the background. */
1036 if (signum_exp
!= NULL
)
1037 async_exec
= strip_bg_char (&signum_exp
);
1039 /* If we must run in the background, but the target can't do it,
1041 if (async_exec
&& !target_can_async_p ())
1042 error (_("Asynchronous execution not supported on this target."));
1044 /* If we are not asked to run in the bg, then prepare to run in the
1045 foreground, synchronously. */
1046 if (!async_exec
&& target_can_async_p ())
1048 /* Simulate synchronous execution. */
1049 async_disable_stdin ();
1053 error_no_arg (_("signal number"));
1055 /* It would be even slicker to make signal names be valid expressions,
1056 (the type could be "enum $signal" or some such), then the user could
1057 assign them to convenience variables. */
1058 oursig
= target_signal_from_name (signum_exp
);
1060 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1062 /* No, try numeric. */
1063 int num
= parse_and_eval_long (signum_exp
);
1066 oursig
= TARGET_SIGNAL_0
;
1068 oursig
= target_signal_from_command (num
);
1073 if (oursig
== TARGET_SIGNAL_0
)
1074 printf_filtered (_("Continuing with no signal.\n"));
1076 printf_filtered (_("Continuing with signal %s.\n"),
1077 target_signal_to_name (oursig
));
1080 clear_proceed_status ();
1081 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1082 FIXME: Neither should "signal foo" but when I tried passing
1083 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1084 tried to track down yet. */
1085 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
1088 /* Proceed until we reach a different source line with pc greater than
1089 our current one or exit the function. We skip calls in both cases.
1091 Note that eventually this command should probably be changed so
1092 that only source lines are printed out when we hit the breakpoint
1093 we set. This may involve changes to wait_for_inferior and the
1094 proceed status code. */
1097 until_next_command (int from_tty
)
1099 struct frame_info
*frame
;
1101 struct symbol
*func
;
1102 struct symtab_and_line sal
;
1104 clear_proceed_status ();
1106 frame
= get_current_frame ();
1108 /* Step until either exited from this function or greater
1109 than the current line (if in symbolic section) or pc (if
1113 func
= find_pc_function (pc
);
1117 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1119 if (msymbol
== NULL
)
1120 error (_("Execution is not within a known function."));
1122 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1123 step_range_end
= pc
;
1127 sal
= find_pc_line (pc
, 0);
1129 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1130 step_range_end
= sal
.end
;
1133 step_over_calls
= STEP_OVER_ALL
;
1134 step_frame_id
= get_frame_id (frame
);
1136 step_multi
= 0; /* Only one call to proceed */
1138 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1142 until_command (char *arg
, int from_tty
)
1146 if (!target_has_execution
)
1147 error (_("The program is not running."));
1149 /* Find out whether we must run in the background. */
1151 async_exec
= strip_bg_char (&arg
);
1153 /* If we must run in the background, but the target can't do it,
1155 if (async_exec
&& !target_can_async_p ())
1156 error (_("Asynchronous execution not supported on this target."));
1158 /* If we are not asked to run in the bg, then prepare to run in the
1159 foreground, synchronously. */
1160 if (!async_exec
&& target_can_async_p ())
1162 /* Simulate synchronous execution */
1163 async_disable_stdin ();
1167 until_break_command (arg
, from_tty
, 0);
1169 until_next_command (from_tty
);
1173 advance_command (char *arg
, int from_tty
)
1177 if (!target_has_execution
)
1178 error (_("The program is not running."));
1181 error_no_arg (_("a location"));
1183 /* Find out whether we must run in the background. */
1185 async_exec
= strip_bg_char (&arg
);
1187 /* If we must run in the background, but the target can't do it,
1189 if (async_exec
&& !target_can_async_p ())
1190 error (_("Asynchronous execution not supported on this target."));
1192 /* If we are not asked to run in the bg, then prepare to run in the
1193 foreground, synchronously. */
1194 if (!async_exec
&& target_can_async_p ())
1196 /* Simulate synchronous execution. */
1197 async_disable_stdin ();
1200 until_break_command (arg
, from_tty
, 1);
1203 /* Print the result of a function at the end of a 'finish' command. */
1206 print_return_value (struct type
*func_type
, struct type
*value_type
)
1208 struct gdbarch
*gdbarch
= current_gdbarch
;
1209 struct cleanup
*old_chain
;
1210 struct ui_stream
*stb
;
1211 struct value
*value
;
1213 CHECK_TYPEDEF (value_type
);
1214 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1216 /* FIXME: 2003-09-27: When returning from a nested inferior function
1217 call, it's possible (with no help from the architecture vector)
1218 to locate and return/print a "struct return" value. This is just
1219 a more complicated case of what is already being done in in the
1220 inferior function call code. In fact, when inferior function
1221 calls are made async, this will likely be made the norm. */
1223 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1226 case RETURN_VALUE_REGISTER_CONVENTION
:
1227 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1228 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1229 value
= allocate_value (value_type
);
1230 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1231 value_contents_raw (value
), NULL
);
1233 case RETURN_VALUE_STRUCT_CONVENTION
:
1237 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1243 stb
= ui_out_stream_new (uiout
);
1244 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1245 ui_out_text (uiout
, "Value returned is ");
1246 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1247 record_latest_value (value
));
1248 ui_out_text (uiout
, " = ");
1249 value_print (value
, stb
->stream
, 0, Val_no_prettyprint
);
1250 ui_out_field_stream (uiout
, "return-value", stb
);
1251 ui_out_text (uiout
, "\n");
1252 do_cleanups (old_chain
);
1256 ui_out_text (uiout
, "Value returned has type: ");
1257 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1258 ui_out_text (uiout
, ".");
1259 ui_out_text (uiout
, " Cannot determine contents\n");
1263 /* Stuff that needs to be done by the finish command after the target
1264 has stopped. In asynchronous mode, we wait for the target to stop
1265 in the call to poll or select in the event loop, so it is
1266 impossible to do all the stuff as part of the finish_command
1267 function itself. The only chance we have to complete this command
1268 is in fetch_inferior_event, which is called by the event loop as
1269 soon as it detects that the target has stopped. This function is
1270 called via the cmd_continuation pointer. */
1273 finish_command_continuation (struct continuation_arg
*arg
, int error_p
)
1275 struct symbol
*function
;
1276 struct breakpoint
*breakpoint
;
1277 struct cleanup
*cleanups
;
1279 breakpoint
= (struct breakpoint
*) arg
->data
.pointer
;
1280 function
= (struct symbol
*) arg
->next
->data
.pointer
;
1284 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1285 && function
!= NULL
)
1287 struct type
*value_type
;
1289 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1291 internal_error (__FILE__
, __LINE__
,
1292 _("finish_command: function has no target type"));
1294 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1295 print_return_value (SYMBOL_TYPE (function
), value_type
);
1299 delete_breakpoint (breakpoint
);
1302 /* "finish": Set a temporary breakpoint at the place the selected
1303 frame will return to, then continue. */
1306 finish_command (char *arg
, int from_tty
)
1308 struct symtab_and_line sal
;
1309 struct frame_info
*frame
;
1310 struct symbol
*function
;
1311 struct breakpoint
*breakpoint
;
1312 struct cleanup
*old_chain
;
1313 struct continuation_arg
*arg1
, *arg2
, *arg3
;
1317 /* Find out whether we must run in the background. */
1319 async_exec
= strip_bg_char (&arg
);
1321 /* If we must run in the background, but the target can't do it,
1323 if (async_exec
&& !target_can_async_p ())
1324 error (_("Asynchronous execution not supported on this target."));
1326 /* If we are not asked to run in the bg, then prepare to run in the
1327 foreground, synchronously. */
1328 if (!async_exec
&& target_can_async_p ())
1330 /* Simulate synchronous execution. */
1331 async_disable_stdin ();
1335 error (_("The \"finish\" command does not take any arguments."));
1336 if (!target_has_execution
)
1337 error (_("The program is not running."));
1339 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1341 error (_("\"finish\" not meaningful in the outermost frame."));
1343 clear_proceed_status ();
1345 sal
= find_pc_line (get_frame_pc (frame
), 0);
1346 sal
.pc
= get_frame_pc (frame
);
1348 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
), bp_finish
);
1350 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1352 /* Find the function we will return from. */
1354 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1356 /* Print info on the selected frame, including level number but not
1360 printf_filtered (_("Run till exit from "));
1361 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1364 proceed_to_finish
= 1; /* We want stop_registers, please... */
1365 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1368 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1370 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1373 arg1
->data
.pointer
= breakpoint
;
1374 arg2
->data
.pointer
= function
;
1375 add_continuation (finish_command_continuation
, arg1
);
1377 /* Do this only if not running asynchronously or if the target
1378 cannot do async execution. Otherwise, complete this command when
1379 the target actually stops, in fetch_inferior_event. */
1380 discard_cleanups (old_chain
);
1381 if (!target_can_async_p ())
1382 do_all_continuations (0);
1387 program_info (char *args
, int from_tty
)
1389 bpstat bs
= stop_bpstat
;
1391 int stat
= bpstat_num (&bs
, &num
);
1393 if (!target_has_execution
)
1395 printf_filtered (_("The program being debugged is not being run.\n"));
1399 target_files_info ();
1400 printf_filtered (_("Program stopped at %s.\n"),
1401 hex_string ((unsigned long) stop_pc
));
1403 printf_filtered (_("It stopped after being stepped.\n"));
1406 /* There may be several breakpoints in the same place, so this
1407 isn't as strange as it seems. */
1412 printf_filtered (_("\
1413 It stopped at a breakpoint that has since been deleted.\n"));
1416 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1417 stat
= bpstat_num (&bs
, &num
);
1420 else if (stop_signal
!= TARGET_SIGNAL_0
)
1422 printf_filtered (_("It stopped with signal %s, %s.\n"),
1423 target_signal_to_name (stop_signal
),
1424 target_signal_to_string (stop_signal
));
1429 printf_filtered (_("\
1430 Type \"info stack\" or \"info registers\" for more information.\n"));
1435 environment_info (char *var
, int from_tty
)
1439 char *val
= get_in_environ (inferior_environ
, var
);
1442 puts_filtered (var
);
1443 puts_filtered (" = ");
1444 puts_filtered (val
);
1445 puts_filtered ("\n");
1449 puts_filtered ("Environment variable \"");
1450 puts_filtered (var
);
1451 puts_filtered ("\" not defined.\n");
1456 char **vector
= environ_vector (inferior_environ
);
1459 puts_filtered (*vector
++);
1460 puts_filtered ("\n");
1466 set_environment_command (char *arg
, int from_tty
)
1468 char *p
, *val
, *var
;
1472 error_no_arg (_("environment variable and value"));
1474 /* Find seperation between variable name and value */
1475 p
= (char *) strchr (arg
, '=');
1476 val
= (char *) strchr (arg
, ' ');
1478 if (p
!= 0 && val
!= 0)
1480 /* We have both a space and an equals. If the space is before the
1481 equals, walk forward over the spaces til we see a nonspace
1482 (possibly the equals). */
1487 /* Now if the = is after the char following the spaces,
1488 take the char following the spaces. */
1492 else if (val
!= 0 && p
== 0)
1496 error_no_arg (_("environment variable to set"));
1498 if (p
== 0 || p
[1] == 0)
1502 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1506 /* Not setting variable value to null */
1508 while (*val
== ' ' || *val
== '\t')
1512 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1515 var
= savestring (arg
, p
- arg
);
1518 printf_filtered (_("\
1519 Setting environment variable \"%s\" to null value.\n"),
1521 set_in_environ (inferior_environ
, var
, "");
1524 set_in_environ (inferior_environ
, var
, val
);
1529 unset_environment_command (char *var
, int from_tty
)
1533 /* If there is no argument, delete all environment variables.
1534 Ask for confirmation if reading from the terminal. */
1535 if (!from_tty
|| query (_("Delete all environment variables? ")))
1537 free_environ (inferior_environ
);
1538 inferior_environ
= make_environ ();
1542 unset_in_environ (inferior_environ
, var
);
1545 /* Handle the execution path (PATH variable) */
1547 static const char path_var_name
[] = "PATH";
1550 path_info (char *args
, int from_tty
)
1552 puts_filtered ("Executable and object file path: ");
1553 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1554 puts_filtered ("\n");
1557 /* Add zero or more directories to the front of the execution path. */
1560 path_command (char *dirname
, int from_tty
)
1565 env
= get_in_environ (inferior_environ
, path_var_name
);
1566 /* Can be null if path is not set */
1569 exec_path
= xstrdup (env
);
1570 mod_path (dirname
, &exec_path
);
1571 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1574 path_info ((char *) NULL
, from_tty
);
1578 /* Print out the machine register regnum. If regnum is -1, print all
1579 registers (print_all == 1) or all non-float and non-vector
1580 registers (print_all == 0).
1582 For most machines, having all_registers_info() print the
1583 register(s) one per line is good enough. If a different format is
1584 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1585 regs), or there is an existing convention for showing all the
1586 registers, define the architecture method PRINT_REGISTERS_INFO to
1587 provide that format. */
1590 default_print_registers_info (struct gdbarch
*gdbarch
,
1591 struct ui_file
*file
,
1592 struct frame_info
*frame
,
1593 int regnum
, int print_all
)
1596 const int numregs
= gdbarch_num_regs (gdbarch
)
1597 + gdbarch_num_pseudo_regs (gdbarch
);
1598 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1600 for (i
= 0; i
< numregs
; i
++)
1602 /* Decide between printing all regs, non-float / vector regs, or
1608 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1613 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1623 /* If the register name is empty, it is undefined for this
1624 processor, so don't display anything. */
1625 if (gdbarch_register_name (gdbarch
, i
) == NULL
1626 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1629 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1630 print_spaces_filtered (15 - strlen (gdbarch_register_name
1631 (gdbarch
, i
)), file
);
1633 /* Get the data in raw format. */
1634 if (! frame_register_read (frame
, i
, buffer
))
1636 fprintf_filtered (file
, "*value not available*\n");
1640 /* If virtual format is floating, print it that way, and in raw
1642 if (TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_FLT
1643 || TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_DECFLOAT
)
1647 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1648 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1650 fprintf_filtered (file
, "\t(raw 0x");
1651 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
1654 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1657 idx
= register_size (gdbarch
, i
) - 1 - j
;
1658 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
1660 fprintf_filtered (file
, ")");
1664 /* Print the register in hex. */
1665 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1666 file
, 'x', 1, 0, Val_pretty_default
, current_language
);
1667 /* If not a vector register, print it also according to its
1669 if (TYPE_VECTOR (register_type (gdbarch
, i
)) == 0)
1671 fprintf_filtered (file
, "\t");
1672 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1673 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1677 fprintf_filtered (file
, "\n");
1682 registers_info (char *addr_exp
, int fpregs
)
1684 struct frame_info
*frame
;
1685 struct gdbarch
*gdbarch
;
1686 int regnum
, numregs
;
1689 if (!target_has_registers
)
1690 error (_("The program has no registers now."));
1691 frame
= get_selected_frame (NULL
);
1692 gdbarch
= get_frame_arch (frame
);
1696 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1701 while (*addr_exp
!= '\0')
1706 /* Keep skipping leading white space. */
1707 if (isspace ((*addr_exp
)))
1713 /* Discard any leading ``$''. Check that there is something
1714 resembling a register following it. */
1715 if (addr_exp
[0] == '$')
1717 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
1718 error (_("Missing register name"));
1720 /* Find the start/end of this register name/num/group. */
1722 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
1726 /* Figure out what we've found and display it. */
1728 /* A register name? */
1730 int regnum
= frame_map_name_to_regnum (frame
, start
, end
- start
);
1733 /* User registers lie completely outside of the range of
1734 normal registers. Catch them early so that the target
1736 if (regnum
>= gdbarch_num_regs (gdbarch
)
1737 + gdbarch_num_pseudo_regs (gdbarch
))
1739 struct value
*val
= value_of_user_reg (regnum
, frame
);
1741 printf_filtered ("%s: ", start
);
1742 print_scalar_formatted (value_contents (val
),
1743 check_typedef (value_type (val
)),
1744 'x', 0, gdb_stdout
);
1745 printf_filtered ("\n");
1748 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1749 frame
, regnum
, fpregs
);
1754 /* A register number? (how portable is this one?). */
1757 int regnum
= strtol (start
, &endptr
, 0);
1760 && regnum
< gdbarch_num_regs (gdbarch
)
1761 + gdbarch_num_pseudo_regs (gdbarch
))
1763 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1764 frame
, regnum
, fpregs
);
1769 /* A register group? */
1771 struct reggroup
*group
;
1772 for (group
= reggroup_next (gdbarch
, NULL
);
1774 group
= reggroup_next (gdbarch
, group
))
1776 /* Don't bother with a length check. Should the user
1777 enter a short register group name, go with the first
1778 group that matches. */
1779 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
1786 regnum
< gdbarch_num_regs (gdbarch
)
1787 + gdbarch_num_pseudo_regs (gdbarch
);
1790 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1791 gdbarch_print_registers_info (gdbarch
,
1799 /* Nothing matched. */
1800 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
1805 all_registers_info (char *addr_exp
, int from_tty
)
1807 registers_info (addr_exp
, 1);
1811 nofp_registers_info (char *addr_exp
, int from_tty
)
1813 registers_info (addr_exp
, 0);
1817 print_vector_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1818 struct frame_info
*frame
, const char *args
)
1820 if (gdbarch_print_vector_info_p (gdbarch
))
1821 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
1825 int printed_something
= 0;
1828 regnum
< gdbarch_num_regs (gdbarch
)
1829 + gdbarch_num_pseudo_regs (gdbarch
);
1832 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
1834 printed_something
= 1;
1835 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
1838 if (!printed_something
)
1839 fprintf_filtered (file
, "No vector information\n");
1844 vector_info (char *args
, int from_tty
)
1846 if (!target_has_registers
)
1847 error (_("The program has no registers now."));
1849 print_vector_info (current_gdbarch
, gdb_stdout
,
1850 get_selected_frame (NULL
), args
);
1856 * Should save/restore the tty state since it might be that the
1857 * program to be debugged was started on this tty and it wants
1858 * the tty in some state other than what we want. If it's running
1859 * on another terminal or without a terminal, then saving and
1860 * restoring the tty state is a harmless no-op.
1861 * This only needs to be done if we are attaching to a process.
1866 takes a program started up outside of gdb and ``attaches'' to it.
1867 This stops it cold in its tracks and allows us to start debugging it.
1868 and wait for the trace-trap that results from attaching. */
1871 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
1874 char *full_exec_path
= NULL
;
1876 stop_soon
= NO_STOP_QUIETLY
;
1878 /* If no exec file is yet known, try to determine it from the
1880 exec_file
= (char *) get_exec_file (0);
1883 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
1886 /* It's possible we don't have a full path, but rather just a
1887 filename. Some targets, such as HP-UX, don't provide the
1890 Attempt to qualify the filename against the source path.
1891 (If that fails, we'll just fall back on the original
1892 filename. Not much more we can do...)
1894 if (!source_full_path_of (exec_file
, &full_exec_path
))
1895 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
1897 exec_file_attach (full_exec_path
, from_tty
);
1898 symbol_file_add_main (full_exec_path
, from_tty
);
1903 reopen_exec_file ();
1907 /* Take any necessary post-attaching actions for this platform. */
1908 target_post_attach (PIDGET (inferior_ptid
));
1910 post_create_inferior (¤t_target
, from_tty
);
1912 /* Install inferior's terminal modes. */
1913 target_terminal_inferior ();
1916 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
1919 if (target_can_async_p ())
1920 async_enable_stdin ();
1922 if (deprecated_attach_hook
)
1923 deprecated_attach_hook ();
1928 attach_command_continuation (struct continuation_arg
*arg
, int error_p
)
1934 args
= (char *) arg
->data
.pointer
;
1935 from_tty
= arg
->next
->data
.integer
;
1936 async_exec
= arg
->next
->next
->data
.integer
;
1938 attach_command_post_wait (args
, from_tty
, async_exec
);
1942 attach_command (char *args
, int from_tty
)
1945 char *full_exec_path
= NULL
;
1948 dont_repeat (); /* Not for the faint of heart */
1950 if (target_has_execution
)
1952 if (query ("A program is being debugged already. Kill it? "))
1955 error (_("Not killed."));
1958 /* Clean up any leftovers from other runs. Some other things from
1959 this function should probably be moved into target_pre_inferior. */
1960 target_pre_inferior (from_tty
);
1962 /* Clear out solib state. Otherwise the solib state of the previous
1963 inferior might have survived and is entirely wrong for the new
1964 target. This has been observed on GNU/Linux using glibc 2.3. How
1976 Cannot access memory at address 0xdeadbeef
1982 async_exec
= strip_bg_char (&args
);
1984 /* If we get a request for running in the bg but the target
1985 doesn't support it, error out. */
1986 if (async_exec
&& !target_can_async_p ())
1987 error (_("Asynchronous execution not supported on this target."));
1990 /* If we don't get a request of running in the bg, then we need
1991 to simulate synchronous (fg) execution. */
1992 if (!async_exec
&& target_can_async_p ())
1994 /* Simulate synchronous execution */
1995 async_disable_stdin ();
1998 target_attach (args
, from_tty
);
2000 /* Set up the "saved terminal modes" of the inferior
2001 based on what modes we are starting it with. */
2002 target_terminal_init ();
2004 /* Set up execution context to know that we should return from
2005 wait_for_inferior as soon as the target reports a stop. */
2006 init_wait_for_inferior ();
2007 clear_proceed_status ();
2009 /* No traps are generated when attaching to inferior under Mach 3
2011 #ifndef ATTACH_NO_WAIT
2012 /* Careful here. See comments in inferior.h. Basically some OSes
2013 don't ignore SIGSTOPs on continue requests anymore. We need a
2014 way for handle_inferior_event to reset the stop_signal variable
2015 after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for. */
2016 stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2018 if (target_can_async_p ())
2020 /* sync_execution mode. Wait for stop. */
2021 struct continuation_arg
*arg1
, *arg2
, *arg3
;
2024 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2026 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2028 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2032 arg1
->data
.pointer
= args
;
2033 arg2
->data
.integer
= from_tty
;
2034 arg3
->data
.integer
= async_exec
;
2035 add_continuation (attach_command_continuation
, arg1
);
2039 wait_for_inferior (0);
2042 attach_command_post_wait (args
, from_tty
, async_exec
);
2047 * takes a program previously attached to and detaches it.
2048 * The program resumes execution and will no longer stop
2049 * on signals, etc. We better not have left any breakpoints
2050 * in the program or it'll die when it hits one. For this
2051 * to work, it may be necessary for the process to have been
2052 * previously attached. It *might* work if the program was
2053 * started via the normal ptrace (PTRACE_TRACEME).
2057 detach_command (char *args
, int from_tty
)
2059 dont_repeat (); /* Not for the faint of heart. */
2060 target_detach (args
, from_tty
);
2061 no_shared_libraries (NULL
, from_tty
);
2062 init_thread_list ();
2063 if (deprecated_detach_hook
)
2064 deprecated_detach_hook ();
2067 /* Disconnect from the current target without resuming it (leaving it
2068 waiting for a debugger).
2070 We'd better not have left any breakpoints in the program or the
2071 next debugger will get confused. Currently only supported for some
2072 remote targets, since the normal attach mechanisms don't work on
2073 stopped processes on some native platforms (e.g. GNU/Linux). */
2076 disconnect_command (char *args
, int from_tty
)
2078 dont_repeat (); /* Not for the faint of heart */
2079 target_disconnect (args
, from_tty
);
2080 no_shared_libraries (NULL
, from_tty
);
2081 init_thread_list ();
2082 if (deprecated_detach_hook
)
2083 deprecated_detach_hook ();
2086 /* Stop the execution of the target while running in async mode, in
2089 interrupt_target_command (char *args
, int from_tty
)
2091 if (target_can_async_p ())
2093 dont_repeat (); /* Not for the faint of heart */
2099 print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2100 struct frame_info
*frame
, const char *args
)
2102 if (gdbarch_print_float_info_p (gdbarch
))
2103 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2107 int printed_something
= 0;
2110 regnum
< gdbarch_num_regs (gdbarch
)
2111 + gdbarch_num_pseudo_regs (gdbarch
);
2114 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2116 printed_something
= 1;
2117 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2120 if (!printed_something
)
2121 fprintf_filtered (file
, "\
2122 No floating-point info available for this processor.\n");
2127 float_info (char *args
, int from_tty
)
2129 if (!target_has_registers
)
2130 error (_("The program has no registers now."));
2132 print_float_info (current_gdbarch
, gdb_stdout
,
2133 get_selected_frame (NULL
), args
);
2137 unset_command (char *args
, int from_tty
)
2139 printf_filtered (_("\
2140 \"unset\" must be followed by the name of an unset subcommand.\n"));
2141 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2145 _initialize_infcmd (void)
2147 struct cmd_list_element
*c
= NULL
;
2149 /* add the filename of the terminal connected to inferior I/O */
2150 add_setshow_filename_cmd ("inferior-tty", class_run
,
2151 &inferior_io_terminal
, _("\
2152 Set terminal for future runs of program being debugged."), _("\
2153 Show terminal for future runs of program being debugged."), _("\
2154 Usage: set inferior-tty /dev/pts/1"), NULL
, NULL
, &setlist
, &showlist
);
2155 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2157 add_setshow_optional_filename_cmd ("args", class_run
,
2158 &inferior_args
, _("\
2159 Set argument list to give program being debugged when it is started."), _("\
2160 Show argument list to give program being debugged when it is started."), _("\
2161 Follow this command with any number of args, to be passed to the program."),
2164 &setlist
, &showlist
);
2166 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2167 The environment to give the program, or one variable's value.\n\
2168 With an argument VAR, prints the value of environment variable VAR to\n\
2169 give the program being debugged. With no arguments, prints the entire\n\
2170 environment to be given to the program."), &showlist
);
2171 set_cmd_completer (c
, noop_completer
);
2173 add_prefix_cmd ("unset", no_class
, unset_command
,
2174 _("Complement to certain \"set\" commands."),
2175 &unsetlist
, "unset ", 0, &cmdlist
);
2177 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2178 Cancel environment variable VAR for the program.\n\
2179 This does not affect the program until the next \"run\" command."),
2181 set_cmd_completer (c
, noop_completer
);
2183 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2184 Set environment variable value to give the program.\n\
2185 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2186 VALUES of environment variables are uninterpreted strings.\n\
2187 This does not affect the program until the next \"run\" command."),
2189 set_cmd_completer (c
, noop_completer
);
2191 c
= add_com ("path", class_files
, path_command
, _("\
2192 Add directory DIR(s) to beginning of search path for object files.\n\
2193 $cwd in the path means the current working directory.\n\
2194 This path is equivalent to the $PATH shell variable. It is a list of\n\
2195 directories, separated by colons. These directories are searched to find\n\
2196 fully linked executable files and separately compiled object files as needed."));
2197 set_cmd_completer (c
, filename_completer
);
2199 c
= add_cmd ("paths", no_class
, path_info
, _("\
2200 Current search path for finding object files.\n\
2201 $cwd in the path means the current working directory.\n\
2202 This path is equivalent to the $PATH shell variable. It is a list of\n\
2203 directories, separated by colons. These directories are searched to find\n\
2204 fully linked executable files and separately compiled object files as needed."),
2206 set_cmd_completer (c
, noop_completer
);
2208 add_com ("attach", class_run
, attach_command
, _("\
2209 Attach to a process or file outside of GDB.\n\
2210 This command attaches to another target, of the same type as your last\n\
2211 \"target\" command (\"info files\" will show your target stack).\n\
2212 The command may take as argument a process id or a device file.\n\
2213 For a process id, you must have permission to send the process a signal,\n\
2214 and it must have the same effective uid as the debugger.\n\
2215 When using \"attach\" with a process id, the debugger finds the\n\
2216 program running in the process, looking first in the current working\n\
2217 directory, or (if not found there) using the source file search path\n\
2218 (see the \"directory\" command). You can also use the \"file\" command\n\
2219 to specify the program, and to load its symbol table."));
2221 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2222 Detach a process or file previously attached.\n\
2223 If a process, it is no longer traced, and it continues its execution. If\n\
2224 you were debugging a file, the file is closed and gdb no longer accesses it."),
2225 &detachlist
, "detach ", 0, &cmdlist
);
2227 add_com ("disconnect", class_run
, disconnect_command
, _("\
2228 Disconnect from a target.\n\
2229 The target will wait for another debugger to connect. Not available for\n\
2232 add_com ("signal", class_run
, signal_command
, _("\
2233 Continue program giving it signal specified by the argument.\n\
2234 An argument of \"0\" means continue program without giving it a signal."));
2236 add_com ("stepi", class_run
, stepi_command
, _("\
2237 Step one instruction exactly.\n\
2238 Argument N means do this N times (or till program stops for another reason)."));
2239 add_com_alias ("si", "stepi", class_alias
, 0);
2241 add_com ("nexti", class_run
, nexti_command
, _("\
2242 Step one instruction, but proceed through subroutine calls.\n\
2243 Argument N means do this N times (or till program stops for another reason)."));
2244 add_com_alias ("ni", "nexti", class_alias
, 0);
2246 add_com ("finish", class_run
, finish_command
, _("\
2247 Execute until selected stack frame returns.\n\
2248 Upon return, the value returned is printed and put in the value history."));
2249 add_com_alias ("fin", "finish", class_run
, 1);
2251 add_com ("next", class_run
, next_command
, _("\
2252 Step program, proceeding through subroutine calls.\n\
2253 Like the \"step\" command as long as subroutine calls do not happen;\n\
2254 when they do, the call is treated as one instruction.\n\
2255 Argument N means do this N times (or till program stops for another reason)."));
2256 add_com_alias ("n", "next", class_run
, 1);
2258 add_com_alias ("S", "next", class_run
, 1);
2260 add_com ("step", class_run
, step_command
, _("\
2261 Step program until it reaches a different source line.\n\
2262 Argument N means do this N times (or till program stops for another reason)."));
2263 add_com_alias ("s", "step", class_run
, 1);
2265 c
= add_com ("until", class_run
, until_command
, _("\
2266 Execute until the program reaches a source line greater than the current\n\
2267 or a specified location (same args as break command) within the current frame."));
2268 set_cmd_completer (c
, location_completer
);
2269 add_com_alias ("u", "until", class_run
, 1);
2271 c
= add_com ("advance", class_run
, advance_command
, _("\
2272 Continue the program up to the given location (same form as args for break command).\n\
2273 Execution will also stop upon exit from the current stack frame."));
2274 set_cmd_completer (c
, location_completer
);
2276 c
= add_com ("jump", class_run
, jump_command
, _("\
2277 Continue program being debugged at specified line or address.\n\
2278 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2279 for an address to start at."));
2280 set_cmd_completer (c
, location_completer
);
2284 c
= add_com ("go", class_run
, go_command
, _("\
2285 Usage: go <location>\n\
2286 Continue program being debugged, stopping at specified line or \n\
2288 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2289 expression for an address to start at.\n\
2290 This command is a combination of tbreak and jump."));
2291 set_cmd_completer (c
, location_completer
);
2295 add_com_alias ("g", "go", class_run
, 1);
2297 add_com ("continue", class_run
, continue_command
, _("\
2298 Continue program being debugged, after signal or breakpoint.\n\
2299 If proceeding from breakpoint, a number N may be used as an argument,\n\
2300 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2301 the breakpoint won't break until the Nth time it is reached)."));
2302 add_com_alias ("c", "cont", class_run
, 1);
2303 add_com_alias ("fg", "cont", class_run
, 1);
2305 c
= add_com ("run", class_run
, run_command
, _("\
2306 Start debugged program. You may specify arguments to give it.\n\
2307 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2308 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2309 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2310 To cancel previous arguments and run with no arguments,\n\
2311 use \"set args\" without arguments."));
2312 set_cmd_completer (c
, filename_completer
);
2313 add_com_alias ("r", "run", class_run
, 1);
2315 add_com ("R", class_run
, run_no_args_command
,
2316 _("Start debugged program with no arguments."));
2318 c
= add_com ("start", class_run
, start_command
, _("\
2319 Run the debugged program until the beginning of the main procedure.\n\
2320 You may specify arguments to give to your program, just as with the\n\
2321 \"run\" command."));
2322 set_cmd_completer (c
, filename_completer
);
2324 c
= add_com ("interrupt", class_run
, interrupt_target_command
,
2325 _("Interrupt the execution of the debugged program."));
2326 set_cmd_async_ok (c
);
2328 add_info ("registers", nofp_registers_info
, _("\
2329 List of integer registers and their contents, for selected stack frame.\n\
2330 Register name as argument means describe only that register."));
2331 add_info_alias ("r", "registers", 1);
2334 add_com ("lr", class_info
, nofp_registers_info
, _("\
2335 List of integer registers and their contents, for selected stack frame.\n\
2336 Register name as argument means describe only that register."));
2337 add_info ("all-registers", all_registers_info
, _("\
2338 List of all registers and their contents, for selected stack frame.\n\
2339 Register name as argument means describe only that register."));
2341 add_info ("program", program_info
,
2342 _("Execution status of the program."));
2344 add_info ("float", float_info
,
2345 _("Print the status of the floating point unit\n"));
2347 add_info ("vector", vector_info
,
2348 _("Print the status of the vector unit\n"));
2350 inferior_environ
= make_environ ();
2351 init_environ (inferior_environ
);