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 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
614 if (is_running (thread
->ptid
))
617 context_switch_to (thread
->ptid
);
618 clear_proceed_status ();
619 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
623 /* continue [-a] [proceed-count] [&] */
625 continue_command (char *args
, int from_tty
)
631 /* Find out whether we must run in the background. */
633 async_exec
= strip_bg_char (&args
);
635 /* If we must run in the background, but the target can't do it,
637 if (async_exec
&& !target_can_async_p ())
638 error (_("Asynchronous execution not supported on this target."));
640 /* If we are not asked to run in the bg, then prepare to run in the
641 foreground, synchronously. */
642 if (!async_exec
&& target_can_async_p ())
644 /* Simulate synchronous execution */
645 async_disable_stdin ();
650 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
653 args
+= sizeof ("-a") - 1;
659 if (!non_stop
&& all_threads
)
660 error (_("`-a' is meaningless in all-stop mode."));
662 if (args
!= NULL
&& all_threads
)
664 Can't resume all threads and specify proceed count simultaneously."));
666 /* If we have an argument left, set proceed count of breakpoint we
670 bpstat bs
= stop_bpstat
;
674 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
677 set_ignore_count (num
,
678 parse_and_eval_long (args
) - 1,
680 /* set_ignore_count prints a message ending with a period.
681 So print two spaces before "Continuing.". */
683 printf_filtered (" ");
687 if (!stopped
&& from_tty
)
690 ("Not stopped at any breakpoint; argument ignored.\n");
695 printf_filtered (_("Continuing.\n"));
697 if (non_stop
&& all_threads
)
699 struct cleanup
*old_chain
;
700 struct frame_id saved_frame_id
;
702 /* Don't error out if the current thread is running, because
703 there may be other stopped threads. */
705 /* Backup current thread and selected frame. */
706 if (!is_running (inferior_ptid
))
707 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
709 saved_frame_id
= null_frame_id
;
711 old_chain
= make_cleanup_restore_current_thread (inferior_ptid
, saved_frame_id
);
712 iterate_over_threads (proceed_thread_callback
, NULL
);
714 /* Restore selected ptid. */
715 do_cleanups (old_chain
);
719 ensure_not_running ();
720 clear_proceed_status ();
721 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
725 /* Step until outside of current statement. */
728 step_command (char *count_string
, int from_tty
)
730 step_1 (0, 0, count_string
);
733 /* Likewise, but skip over subroutine calls as if single instructions. */
736 next_command (char *count_string
, int from_tty
)
738 step_1 (1, 0, count_string
);
741 /* Likewise, but step only one instruction. */
744 stepi_command (char *count_string
, int from_tty
)
746 step_1 (0, 1, count_string
);
750 nexti_command (char *count_string
, int from_tty
)
752 step_1 (1, 1, count_string
);
756 delete_longjmp_breakpoint_cleanup (void *arg
)
758 int thread
= * (int *) arg
;
759 delete_longjmp_breakpoint (thread
);
763 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
766 struct frame_info
*frame
;
767 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
772 ensure_not_running ();
775 async_exec
= strip_bg_char (&count_string
);
777 /* If we get a request for running in the bg but the target
778 doesn't support it, error out. */
779 if (async_exec
&& !target_can_async_p ())
780 error (_("Asynchronous execution not supported on this target."));
782 /* If we don't get a request of running in the bg, then we need
783 to simulate synchronous (fg) execution. */
784 if (!async_exec
&& target_can_async_p ())
786 /* Simulate synchronous execution */
787 async_disable_stdin ();
790 count
= count_string
? parse_and_eval_long (count_string
) : 1;
792 if (!single_inst
|| skip_subroutines
) /* leave si command alone */
794 if (in_thread_list (inferior_ptid
))
795 thread
= pid_to_thread_id (inferior_ptid
);
797 set_longjmp_breakpoint ();
799 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
802 /* In synchronous case, all is well, just use the regular for loop. */
803 if (!target_can_async_p ())
805 for (; count
> 0; count
--)
807 clear_proceed_status ();
809 frame
= get_current_frame ();
810 if (!frame
) /* Avoid coredump here. Why tho? */
811 error (_("No current frame"));
812 step_frame_id
= get_frame_id (frame
);
816 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
817 if (step_range_end
== 0)
820 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
821 &step_range_end
) == 0)
822 error (_("Cannot find bounds of current function"));
824 target_terminal_ours ();
825 printf_filtered (_("\
826 Single stepping until exit from function %s, \n\
827 which has no line number information.\n"), name
);
832 /* Say we are stepping, but stop after one insn whatever it does. */
833 step_range_start
= step_range_end
= 1;
834 if (!skip_subroutines
)
836 Don't step over function calls, not even to functions lacking
838 step_over_calls
= STEP_OVER_NONE
;
841 if (skip_subroutines
)
842 step_over_calls
= STEP_OVER_ALL
;
844 step_multi
= (count
> 1);
845 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
851 do_cleanups (cleanups
);
854 /* In case of asynchronous target things get complicated, do only
855 one step for now, before returning control to the event loop. Let
856 the continuation figure out how many other steps we need to do,
857 and handle them one at the time, through step_once(). */
860 step_once (skip_subroutines
, single_inst
, count
, thread
);
861 /* We are running, and the continuation is installed. It will
862 disable the longjmp breakpoint as appropriate. */
863 discard_cleanups (cleanups
);
867 /* Called after we are done with one step operation, to check whether
868 we need to step again, before we print the prompt and return control
869 to the user. If count is > 1, we will need to do one more call to
870 proceed(), via step_once(). Basically it is like step_once and
871 step_1_continuation are co-recursive. */
873 step_1_continuation (struct continuation_arg
*arg
, int error_p
)
876 int skip_subroutines
;
880 skip_subroutines
= arg
->data
.integer
;
881 single_inst
= arg
->next
->data
.integer
;
882 count
= arg
->next
->next
->data
.integer
;
883 thread
= arg
->next
->next
->next
->data
.integer
;
885 if (error_p
|| !step_multi
|| !stop_step
)
887 /* We either hit an error, or stopped for some reason
888 that is not stepping, or there are no further steps
890 if (!single_inst
|| skip_subroutines
)
891 delete_longjmp_breakpoint (thread
);
895 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
898 /* Do just one step operation. If count >1 we will have to set up a
899 continuation to be done after the target stops (after this one
900 step). This is useful to implement the 'step n' kind of commands, in
901 case of asynchronous targets. We had to split step_1 into two parts,
902 one to be done before proceed() and one afterwards. This function is
903 called in case of step n with n>1, after the first step operation has
906 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
908 struct continuation_arg
*arg1
;
909 struct continuation_arg
*arg2
;
910 struct continuation_arg
*arg3
;
911 struct continuation_arg
*arg4
;
912 struct frame_info
*frame
;
916 clear_proceed_status ();
918 frame
= get_current_frame ();
919 if (!frame
) /* Avoid coredump here. Why tho? */
920 error (_("No current frame"));
921 step_frame_id
= get_frame_id (frame
);
925 find_pc_line_pc_range (stop_pc
, &step_range_start
, &step_range_end
);
927 /* If we have no line info, switch to stepi mode. */
928 if (step_range_end
== 0 && step_stop_if_no_debug
)
930 step_range_start
= step_range_end
= 1;
932 else if (step_range_end
== 0)
935 if (find_pc_partial_function (stop_pc
, &name
, &step_range_start
,
936 &step_range_end
) == 0)
937 error (_("Cannot find bounds of current function"));
939 target_terminal_ours ();
940 printf_filtered (_("\
941 Single stepping until exit from function %s, \n\
942 which has no line number information.\n"), name
);
947 /* Say we are stepping, but stop after one insn whatever it does. */
948 step_range_start
= step_range_end
= 1;
949 if (!skip_subroutines
)
951 Don't step over function calls, not even to functions lacking
953 step_over_calls
= STEP_OVER_NONE
;
956 if (skip_subroutines
)
957 step_over_calls
= STEP_OVER_ALL
;
959 step_multi
= (count
> 1);
960 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
962 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
964 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
966 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
968 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
970 arg1
->data
.integer
= skip_subroutines
;
972 arg2
->data
.integer
= single_inst
;
974 arg3
->data
.integer
= count
;
976 arg4
->data
.integer
= thread
;
977 add_intermediate_continuation (step_1_continuation
, arg1
);
982 /* Continue program at specified address. */
985 jump_command (char *arg
, int from_tty
)
988 struct symtabs_and_lines sals
;
989 struct symtab_and_line sal
;
995 ensure_not_running ();
997 /* Find out whether we must run in the background. */
999 async_exec
= strip_bg_char (&arg
);
1001 /* If we must run in the background, but the target can't do it,
1003 if (async_exec
&& !target_can_async_p ())
1004 error (_("Asynchronous execution not supported on this target."));
1007 error_no_arg (_("starting address"));
1009 sals
= decode_line_spec_1 (arg
, 1);
1010 if (sals
.nelts
!= 1)
1012 error (_("Unreasonable jump request"));
1018 if (sal
.symtab
== 0 && sal
.pc
== 0)
1019 error (_("No source file has been specified."));
1021 resolve_sal_pc (&sal
); /* May error out */
1023 /* See if we are trying to jump to another function. */
1024 fn
= get_frame_function (get_current_frame ());
1025 sfn
= find_pc_function (sal
.pc
);
1026 if (fn
!= NULL
&& sfn
!= fn
)
1028 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal
.line
,
1029 SYMBOL_PRINT_NAME (fn
)))
1031 error (_("Not confirmed."));
1038 fixup_symbol_section (sfn
, 0);
1039 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn
)) &&
1040 !section_is_mapped (SYMBOL_BFD_SECTION (sfn
)))
1042 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
1044 error (_("Not confirmed."));
1054 printf_filtered (_("Continuing at "));
1055 fputs_filtered (paddress (addr
), gdb_stdout
);
1056 printf_filtered (".\n");
1059 /* If we are not asked to run in the bg, then prepare to run in the
1060 foreground, synchronously. */
1061 if (!async_exec
&& target_can_async_p ())
1063 /* Simulate synchronous execution */
1064 async_disable_stdin ();
1067 clear_proceed_status ();
1068 proceed (addr
, TARGET_SIGNAL_0
, 0);
1072 /* Go to line or address in current procedure */
1074 go_command (char *line_no
, int from_tty
)
1076 if (line_no
== (char *) NULL
|| !*line_no
)
1077 printf_filtered (GO_USAGE
);
1080 tbreak_command (line_no
, from_tty
);
1081 jump_command (line_no
, from_tty
);
1086 /* Continue program giving it specified signal. */
1089 signal_command (char *signum_exp
, int from_tty
)
1091 enum target_signal oursig
;
1094 dont_repeat (); /* Too dangerous. */
1096 ensure_not_running ();
1098 /* Find out whether we must run in the background. */
1099 if (signum_exp
!= NULL
)
1100 async_exec
= strip_bg_char (&signum_exp
);
1102 /* If we must run in the background, but the target can't do it,
1104 if (async_exec
&& !target_can_async_p ())
1105 error (_("Asynchronous execution not supported on this target."));
1107 /* If we are not asked to run in the bg, then prepare to run in the
1108 foreground, synchronously. */
1109 if (!async_exec
&& target_can_async_p ())
1111 /* Simulate synchronous execution. */
1112 async_disable_stdin ();
1116 error_no_arg (_("signal number"));
1118 /* It would be even slicker to make signal names be valid expressions,
1119 (the type could be "enum $signal" or some such), then the user could
1120 assign them to convenience variables. */
1121 oursig
= target_signal_from_name (signum_exp
);
1123 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
1125 /* No, try numeric. */
1126 int num
= parse_and_eval_long (signum_exp
);
1129 oursig
= TARGET_SIGNAL_0
;
1131 oursig
= target_signal_from_command (num
);
1136 if (oursig
== TARGET_SIGNAL_0
)
1137 printf_filtered (_("Continuing with no signal.\n"));
1139 printf_filtered (_("Continuing with signal %s.\n"),
1140 target_signal_to_name (oursig
));
1143 clear_proceed_status ();
1144 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1145 FIXME: Neither should "signal foo" but when I tried passing
1146 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1147 tried to track down yet. */
1148 proceed (oursig
== TARGET_SIGNAL_0
? (CORE_ADDR
) -1 : stop_pc
, oursig
, 0);
1151 /* Proceed until we reach a different source line with pc greater than
1152 our current one or exit the function. We skip calls in both cases.
1154 Note that eventually this command should probably be changed so
1155 that only source lines are printed out when we hit the breakpoint
1156 we set. This may involve changes to wait_for_inferior and the
1157 proceed status code. */
1160 until_next_command (int from_tty
)
1162 struct frame_info
*frame
;
1164 struct symbol
*func
;
1165 struct symtab_and_line sal
;
1167 clear_proceed_status ();
1169 frame
= get_current_frame ();
1171 /* Step until either exited from this function or greater
1172 than the current line (if in symbolic section) or pc (if
1176 func
= find_pc_function (pc
);
1180 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
1182 if (msymbol
== NULL
)
1183 error (_("Execution is not within a known function."));
1185 step_range_start
= SYMBOL_VALUE_ADDRESS (msymbol
);
1186 step_range_end
= pc
;
1190 sal
= find_pc_line (pc
, 0);
1192 step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1193 step_range_end
= sal
.end
;
1196 step_over_calls
= STEP_OVER_ALL
;
1197 step_frame_id
= get_frame_id (frame
);
1199 step_multi
= 0; /* Only one call to proceed */
1201 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 1);
1205 until_command (char *arg
, int from_tty
)
1209 if (!target_has_execution
)
1210 error (_("The program is not running."));
1212 /* Find out whether we must run in the background. */
1214 async_exec
= strip_bg_char (&arg
);
1216 /* If we must run in the background, but the target can't do it,
1218 if (async_exec
&& !target_can_async_p ())
1219 error (_("Asynchronous execution not supported on this target."));
1221 /* If we are not asked to run in the bg, then prepare to run in the
1222 foreground, synchronously. */
1223 if (!async_exec
&& target_can_async_p ())
1225 /* Simulate synchronous execution */
1226 async_disable_stdin ();
1230 until_break_command (arg
, from_tty
, 0);
1232 until_next_command (from_tty
);
1236 advance_command (char *arg
, int from_tty
)
1240 if (!target_has_execution
)
1241 error (_("The program is not running."));
1244 error_no_arg (_("a location"));
1246 /* Find out whether we must run in the background. */
1248 async_exec
= strip_bg_char (&arg
);
1250 /* If we must run in the background, but the target can't do it,
1252 if (async_exec
&& !target_can_async_p ())
1253 error (_("Asynchronous execution not supported on this target."));
1255 /* If we are not asked to run in the bg, then prepare to run in the
1256 foreground, synchronously. */
1257 if (!async_exec
&& target_can_async_p ())
1259 /* Simulate synchronous execution. */
1260 async_disable_stdin ();
1263 until_break_command (arg
, from_tty
, 1);
1266 /* Print the result of a function at the end of a 'finish' command. */
1269 print_return_value (struct type
*func_type
, struct type
*value_type
)
1271 struct gdbarch
*gdbarch
= current_gdbarch
;
1272 struct cleanup
*old_chain
;
1273 struct ui_stream
*stb
;
1274 struct value
*value
;
1276 CHECK_TYPEDEF (value_type
);
1277 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1279 /* FIXME: 2003-09-27: When returning from a nested inferior function
1280 call, it's possible (with no help from the architecture vector)
1281 to locate and return/print a "struct return" value. This is just
1282 a more complicated case of what is already being done in in the
1283 inferior function call code. In fact, when inferior function
1284 calls are made async, this will likely be made the norm. */
1286 switch (gdbarch_return_value (gdbarch
, func_type
, value_type
,
1289 case RETURN_VALUE_REGISTER_CONVENTION
:
1290 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1291 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1292 value
= allocate_value (value_type
);
1293 gdbarch_return_value (gdbarch
, func_type
, value_type
, stop_registers
,
1294 value_contents_raw (value
), NULL
);
1296 case RETURN_VALUE_STRUCT_CONVENTION
:
1300 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1306 stb
= ui_out_stream_new (uiout
);
1307 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1308 ui_out_text (uiout
, "Value returned is ");
1309 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1310 record_latest_value (value
));
1311 ui_out_text (uiout
, " = ");
1312 value_print (value
, stb
->stream
, 0, Val_no_prettyprint
);
1313 ui_out_field_stream (uiout
, "return-value", stb
);
1314 ui_out_text (uiout
, "\n");
1315 do_cleanups (old_chain
);
1319 ui_out_text (uiout
, "Value returned has type: ");
1320 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1321 ui_out_text (uiout
, ".");
1322 ui_out_text (uiout
, " Cannot determine contents\n");
1326 /* Stuff that needs to be done by the finish command after the target
1327 has stopped. In asynchronous mode, we wait for the target to stop
1328 in the call to poll or select in the event loop, so it is
1329 impossible to do all the stuff as part of the finish_command
1330 function itself. The only chance we have to complete this command
1331 is in fetch_inferior_event, which is called by the event loop as
1332 soon as it detects that the target has stopped. This function is
1333 called via the cmd_continuation pointer. */
1336 finish_command_continuation (struct continuation_arg
*arg
, int error_p
)
1338 struct symbol
*function
;
1339 struct breakpoint
*breakpoint
;
1340 struct cleanup
*cleanups
;
1342 breakpoint
= (struct breakpoint
*) arg
->data
.pointer
;
1343 function
= (struct symbol
*) arg
->next
->data
.pointer
;
1347 if (bpstat_find_breakpoint (stop_bpstat
, breakpoint
) != NULL
1348 && function
!= NULL
)
1350 struct type
*value_type
;
1352 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1354 internal_error (__FILE__
, __LINE__
,
1355 _("finish_command: function has no target type"));
1357 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1358 print_return_value (SYMBOL_TYPE (function
), value_type
);
1361 /* We suppress normal call of normal_stop observer and do it here so that
1362 that *stopped notification includes the return value. */
1363 observer_notify_normal_stop (stop_bpstat
);
1366 suppress_stop_observer
= 0;
1367 delete_breakpoint (breakpoint
);
1370 /* "finish": Set a temporary breakpoint at the place the selected
1371 frame will return to, then continue. */
1374 finish_command (char *arg
, int from_tty
)
1376 struct symtab_and_line sal
;
1377 struct frame_info
*frame
;
1378 struct symbol
*function
;
1379 struct breakpoint
*breakpoint
;
1380 struct cleanup
*old_chain
;
1381 struct continuation_arg
*arg1
, *arg2
, *arg3
;
1385 /* Find out whether we must run in the background. */
1387 async_exec
= strip_bg_char (&arg
);
1389 /* If we must run in the background, but the target can't do it,
1391 if (async_exec
&& !target_can_async_p ())
1392 error (_("Asynchronous execution not supported on this target."));
1394 /* If we are not asked to run in the bg, then prepare to run in the
1395 foreground, synchronously. */
1396 if (!async_exec
&& target_can_async_p ())
1398 /* Simulate synchronous execution. */
1399 async_disable_stdin ();
1403 error (_("The \"finish\" command does not take any arguments."));
1404 if (!target_has_execution
)
1405 error (_("The program is not running."));
1407 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1409 error (_("\"finish\" not meaningful in the outermost frame."));
1411 clear_proceed_status ();
1413 sal
= find_pc_line (get_frame_pc (frame
), 0);
1414 sal
.pc
= get_frame_pc (frame
);
1416 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
), bp_finish
);
1418 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1420 /* Find the function we will return from. */
1422 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1424 /* Print info on the selected frame, including level number but not
1428 printf_filtered (_("Run till exit from "));
1429 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
);
1432 proceed_to_finish
= 1; /* We want stop_registers, please... */
1433 make_cleanup_restore_integer (&suppress_stop_observer
);
1434 suppress_stop_observer
= 1;
1435 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
1438 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1440 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
1443 arg1
->data
.pointer
= breakpoint
;
1444 arg2
->data
.pointer
= function
;
1445 add_continuation (finish_command_continuation
, arg1
);
1447 discard_cleanups (old_chain
);
1448 if (!target_can_async_p ())
1449 do_all_continuations (0);
1454 program_info (char *args
, int from_tty
)
1456 bpstat bs
= stop_bpstat
;
1458 int stat
= bpstat_num (&bs
, &num
);
1460 if (!target_has_execution
)
1462 printf_filtered (_("The program being debugged is not being run.\n"));
1466 target_files_info ();
1467 printf_filtered (_("Program stopped at %s.\n"),
1468 hex_string ((unsigned long) stop_pc
));
1470 printf_filtered (_("It stopped after being stepped.\n"));
1473 /* There may be several breakpoints in the same place, so this
1474 isn't as strange as it seems. */
1479 printf_filtered (_("\
1480 It stopped at a breakpoint that has since been deleted.\n"));
1483 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1484 stat
= bpstat_num (&bs
, &num
);
1487 else if (stop_signal
!= TARGET_SIGNAL_0
)
1489 printf_filtered (_("It stopped with signal %s, %s.\n"),
1490 target_signal_to_name (stop_signal
),
1491 target_signal_to_string (stop_signal
));
1496 printf_filtered (_("\
1497 Type \"info stack\" or \"info registers\" for more information.\n"));
1502 environment_info (char *var
, int from_tty
)
1506 char *val
= get_in_environ (inferior_environ
, var
);
1509 puts_filtered (var
);
1510 puts_filtered (" = ");
1511 puts_filtered (val
);
1512 puts_filtered ("\n");
1516 puts_filtered ("Environment variable \"");
1517 puts_filtered (var
);
1518 puts_filtered ("\" not defined.\n");
1523 char **vector
= environ_vector (inferior_environ
);
1526 puts_filtered (*vector
++);
1527 puts_filtered ("\n");
1533 set_environment_command (char *arg
, int from_tty
)
1535 char *p
, *val
, *var
;
1539 error_no_arg (_("environment variable and value"));
1541 /* Find seperation between variable name and value */
1542 p
= (char *) strchr (arg
, '=');
1543 val
= (char *) strchr (arg
, ' ');
1545 if (p
!= 0 && val
!= 0)
1547 /* We have both a space and an equals. If the space is before the
1548 equals, walk forward over the spaces til we see a nonspace
1549 (possibly the equals). */
1554 /* Now if the = is after the char following the spaces,
1555 take the char following the spaces. */
1559 else if (val
!= 0 && p
== 0)
1563 error_no_arg (_("environment variable to set"));
1565 if (p
== 0 || p
[1] == 0)
1569 p
= arg
+ strlen (arg
); /* So that savestring below will work */
1573 /* Not setting variable value to null */
1575 while (*val
== ' ' || *val
== '\t')
1579 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1582 var
= savestring (arg
, p
- arg
);
1585 printf_filtered (_("\
1586 Setting environment variable \"%s\" to null value.\n"),
1588 set_in_environ (inferior_environ
, var
, "");
1591 set_in_environ (inferior_environ
, var
, val
);
1596 unset_environment_command (char *var
, int from_tty
)
1600 /* If there is no argument, delete all environment variables.
1601 Ask for confirmation if reading from the terminal. */
1602 if (!from_tty
|| query (_("Delete all environment variables? ")))
1604 free_environ (inferior_environ
);
1605 inferior_environ
= make_environ ();
1609 unset_in_environ (inferior_environ
, var
);
1612 /* Handle the execution path (PATH variable) */
1614 static const char path_var_name
[] = "PATH";
1617 path_info (char *args
, int from_tty
)
1619 puts_filtered ("Executable and object file path: ");
1620 puts_filtered (get_in_environ (inferior_environ
, path_var_name
));
1621 puts_filtered ("\n");
1624 /* Add zero or more directories to the front of the execution path. */
1627 path_command (char *dirname
, int from_tty
)
1632 env
= get_in_environ (inferior_environ
, path_var_name
);
1633 /* Can be null if path is not set */
1636 exec_path
= xstrdup (env
);
1637 mod_path (dirname
, &exec_path
);
1638 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
1641 path_info ((char *) NULL
, from_tty
);
1645 /* Print out the machine register regnum. If regnum is -1, print all
1646 registers (print_all == 1) or all non-float and non-vector
1647 registers (print_all == 0).
1649 For most machines, having all_registers_info() print the
1650 register(s) one per line is good enough. If a different format is
1651 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1652 regs), or there is an existing convention for showing all the
1653 registers, define the architecture method PRINT_REGISTERS_INFO to
1654 provide that format. */
1657 default_print_registers_info (struct gdbarch
*gdbarch
,
1658 struct ui_file
*file
,
1659 struct frame_info
*frame
,
1660 int regnum
, int print_all
)
1663 const int numregs
= gdbarch_num_regs (gdbarch
)
1664 + gdbarch_num_pseudo_regs (gdbarch
);
1665 gdb_byte buffer
[MAX_REGISTER_SIZE
];
1667 for (i
= 0; i
< numregs
; i
++)
1669 /* Decide between printing all regs, non-float / vector regs, or
1675 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1680 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
1690 /* If the register name is empty, it is undefined for this
1691 processor, so don't display anything. */
1692 if (gdbarch_register_name (gdbarch
, i
) == NULL
1693 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
1696 fputs_filtered (gdbarch_register_name (gdbarch
, i
), file
);
1697 print_spaces_filtered (15 - strlen (gdbarch_register_name
1698 (gdbarch
, i
)), file
);
1700 /* Get the data in raw format. */
1701 if (! frame_register_read (frame
, i
, buffer
))
1703 fprintf_filtered (file
, "*value not available*\n");
1707 /* If virtual format is floating, print it that way, and in raw
1709 if (TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_FLT
1710 || TYPE_CODE (register_type (gdbarch
, i
)) == TYPE_CODE_DECFLOAT
)
1714 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1715 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1717 fprintf_filtered (file
, "\t(raw 0x");
1718 for (j
= 0; j
< register_size (gdbarch
, i
); j
++)
1721 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1724 idx
= register_size (gdbarch
, i
) - 1 - j
;
1725 fprintf_filtered (file
, "%02x", (unsigned char) buffer
[idx
]);
1727 fprintf_filtered (file
, ")");
1731 /* Print the register in hex. */
1732 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1733 file
, 'x', 1, 0, Val_pretty_default
, current_language
);
1734 /* If not a vector register, print it also according to its
1736 if (TYPE_VECTOR (register_type (gdbarch
, i
)) == 0)
1738 fprintf_filtered (file
, "\t");
1739 val_print (register_type (gdbarch
, i
), buffer
, 0, 0,
1740 file
, 0, 1, 0, Val_pretty_default
, current_language
);
1744 fprintf_filtered (file
, "\n");
1749 registers_info (char *addr_exp
, int fpregs
)
1751 struct frame_info
*frame
;
1752 struct gdbarch
*gdbarch
;
1753 int regnum
, numregs
;
1756 if (!target_has_registers
)
1757 error (_("The program has no registers now."));
1758 frame
= get_selected_frame (NULL
);
1759 gdbarch
= get_frame_arch (frame
);
1763 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1768 while (*addr_exp
!= '\0')
1773 /* Keep skipping leading white space. */
1774 if (isspace ((*addr_exp
)))
1780 /* Discard any leading ``$''. Check that there is something
1781 resembling a register following it. */
1782 if (addr_exp
[0] == '$')
1784 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
1785 error (_("Missing register name"));
1787 /* Find the start/end of this register name/num/group. */
1789 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
1793 /* Figure out what we've found and display it. */
1795 /* A register name? */
1797 int regnum
= frame_map_name_to_regnum (frame
, start
, end
- start
);
1800 /* User registers lie completely outside of the range of
1801 normal registers. Catch them early so that the target
1803 if (regnum
>= gdbarch_num_regs (gdbarch
)
1804 + gdbarch_num_pseudo_regs (gdbarch
))
1806 struct value
*val
= value_of_user_reg (regnum
, frame
);
1808 printf_filtered ("%s: ", start
);
1809 print_scalar_formatted (value_contents (val
),
1810 check_typedef (value_type (val
)),
1811 'x', 0, gdb_stdout
);
1812 printf_filtered ("\n");
1815 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1816 frame
, regnum
, fpregs
);
1821 /* A register number? (how portable is this one?). */
1824 int regnum
= strtol (start
, &endptr
, 0);
1827 && regnum
< gdbarch_num_regs (gdbarch
)
1828 + gdbarch_num_pseudo_regs (gdbarch
))
1830 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
1831 frame
, regnum
, fpregs
);
1836 /* A register group? */
1838 struct reggroup
*group
;
1839 for (group
= reggroup_next (gdbarch
, NULL
);
1841 group
= reggroup_next (gdbarch
, group
))
1843 /* Don't bother with a length check. Should the user
1844 enter a short register group name, go with the first
1845 group that matches. */
1846 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
1853 regnum
< gdbarch_num_regs (gdbarch
)
1854 + gdbarch_num_pseudo_regs (gdbarch
);
1857 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1858 gdbarch_print_registers_info (gdbarch
,
1866 /* Nothing matched. */
1867 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
1872 all_registers_info (char *addr_exp
, int from_tty
)
1874 registers_info (addr_exp
, 1);
1878 nofp_registers_info (char *addr_exp
, int from_tty
)
1880 registers_info (addr_exp
, 0);
1884 print_vector_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1885 struct frame_info
*frame
, const char *args
)
1887 if (gdbarch_print_vector_info_p (gdbarch
))
1888 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
1892 int printed_something
= 0;
1895 regnum
< gdbarch_num_regs (gdbarch
)
1896 + gdbarch_num_pseudo_regs (gdbarch
);
1899 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
1901 printed_something
= 1;
1902 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
1905 if (!printed_something
)
1906 fprintf_filtered (file
, "No vector information\n");
1911 vector_info (char *args
, int from_tty
)
1913 if (!target_has_registers
)
1914 error (_("The program has no registers now."));
1916 print_vector_info (current_gdbarch
, gdb_stdout
,
1917 get_selected_frame (NULL
), args
);
1923 * Should save/restore the tty state since it might be that the
1924 * program to be debugged was started on this tty and it wants
1925 * the tty in some state other than what we want. If it's running
1926 * on another terminal or without a terminal, then saving and
1927 * restoring the tty state is a harmless no-op.
1928 * This only needs to be done if we are attaching to a process.
1933 takes a program started up outside of gdb and ``attaches'' to it.
1934 This stops it cold in its tracks and allows us to start debugging it.
1935 and wait for the trace-trap that results from attaching. */
1938 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
1941 char *full_exec_path
= NULL
;
1943 stop_soon
= NO_STOP_QUIETLY
;
1945 /* If no exec file is yet known, try to determine it from the
1947 exec_file
= (char *) get_exec_file (0);
1950 exec_file
= target_pid_to_exec_file (PIDGET (inferior_ptid
));
1953 /* It's possible we don't have a full path, but rather just a
1954 filename. Some targets, such as HP-UX, don't provide the
1957 Attempt to qualify the filename against the source path.
1958 (If that fails, we'll just fall back on the original
1959 filename. Not much more we can do...)
1961 if (!source_full_path_of (exec_file
, &full_exec_path
))
1962 full_exec_path
= savestring (exec_file
, strlen (exec_file
));
1964 exec_file_attach (full_exec_path
, from_tty
);
1965 symbol_file_add_main (full_exec_path
, from_tty
);
1970 reopen_exec_file ();
1974 /* Take any necessary post-attaching actions for this platform. */
1975 target_post_attach (PIDGET (inferior_ptid
));
1977 post_create_inferior (¤t_target
, from_tty
);
1979 /* Install inferior's terminal modes. */
1980 target_terminal_inferior ();
1983 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_0
, 0);
1986 if (target_can_async_p ())
1987 async_enable_stdin ();
1989 if (deprecated_attach_hook
)
1990 deprecated_attach_hook ();
1995 attach_command_continuation (struct continuation_arg
*arg
, int error_p
)
2001 args
= (char *) arg
->data
.pointer
;
2002 from_tty
= arg
->next
->data
.integer
;
2003 async_exec
= arg
->next
->next
->data
.integer
;
2005 attach_command_post_wait (args
, from_tty
, async_exec
);
2009 attach_command (char *args
, int from_tty
)
2012 char *full_exec_path
= NULL
;
2015 dont_repeat (); /* Not for the faint of heart */
2017 if (target_has_execution
)
2019 if (query ("A program is being debugged already. Kill it? "))
2022 error (_("Not killed."));
2025 /* Clean up any leftovers from other runs. Some other things from
2026 this function should probably be moved into target_pre_inferior. */
2027 target_pre_inferior (from_tty
);
2029 /* Clear out solib state. Otherwise the solib state of the previous
2030 inferior might have survived and is entirely wrong for the new
2031 target. This has been observed on GNU/Linux using glibc 2.3. How
2043 Cannot access memory at address 0xdeadbeef
2049 async_exec
= strip_bg_char (&args
);
2051 /* If we get a request for running in the bg but the target
2052 doesn't support it, error out. */
2053 if (async_exec
&& !target_can_async_p ())
2054 error (_("Asynchronous execution not supported on this target."));
2057 /* If we don't get a request of running in the bg, then we need
2058 to simulate synchronous (fg) execution. */
2059 if (!async_exec
&& target_can_async_p ())
2061 /* Simulate synchronous execution */
2062 async_disable_stdin ();
2065 target_attach (args
, from_tty
);
2067 /* Set up the "saved terminal modes" of the inferior
2068 based on what modes we are starting it with. */
2069 target_terminal_init ();
2071 /* Set up execution context to know that we should return from
2072 wait_for_inferior as soon as the target reports a stop. */
2073 init_wait_for_inferior ();
2074 clear_proceed_status ();
2076 /* Some system don't generate traps when attaching to inferior.
2077 E.g. Mach 3 or GNU hurd. */
2078 if (!target_attach_no_wait
)
2080 /* Careful here. See comments in inferior.h. Basically some
2081 OSes don't ignore SIGSTOPs on continue requests anymore. We
2082 need a way for handle_inferior_event to reset the stop_signal
2083 variable after an attach, and this is what
2084 STOP_QUIETLY_NO_SIGSTOP is for. */
2085 stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2087 if (target_can_async_p ())
2089 /* sync_execution mode. Wait for stop. */
2090 struct continuation_arg
*arg1
, *arg2
, *arg3
;
2093 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2095 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2097 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
2101 arg1
->data
.pointer
= args
;
2102 arg2
->data
.integer
= from_tty
;
2103 arg3
->data
.integer
= async_exec
;
2104 add_continuation (attach_command_continuation
, arg1
);
2108 wait_for_inferior (0);
2111 attach_command_post_wait (args
, from_tty
, async_exec
);
2116 * takes a program previously attached to and detaches it.
2117 * The program resumes execution and will no longer stop
2118 * on signals, etc. We better not have left any breakpoints
2119 * in the program or it'll die when it hits one. For this
2120 * to work, it may be necessary for the process to have been
2121 * previously attached. It *might* work if the program was
2122 * started via the normal ptrace (PTRACE_TRACEME).
2126 detach_command (char *args
, int from_tty
)
2128 dont_repeat (); /* Not for the faint of heart. */
2129 target_detach (args
, from_tty
);
2130 no_shared_libraries (NULL
, from_tty
);
2131 init_thread_list ();
2132 if (deprecated_detach_hook
)
2133 deprecated_detach_hook ();
2136 /* Disconnect from the current target without resuming it (leaving it
2137 waiting for a debugger).
2139 We'd better not have left any breakpoints in the program or the
2140 next debugger will get confused. Currently only supported for some
2141 remote targets, since the normal attach mechanisms don't work on
2142 stopped processes on some native platforms (e.g. GNU/Linux). */
2145 disconnect_command (char *args
, int from_tty
)
2147 dont_repeat (); /* Not for the faint of heart */
2148 target_disconnect (args
, from_tty
);
2149 no_shared_libraries (NULL
, from_tty
);
2150 init_thread_list ();
2151 if (deprecated_detach_hook
)
2152 deprecated_detach_hook ();
2155 /* Stop the execution of the target while running in async mode, in
2156 the backgound. In all-stop, stop the whole process. In non-stop
2157 mode, stop the current thread only by default, or stop all threads
2158 if the `-a' switch is used. */
2160 /* interrupt [-a] */
2162 interrupt_target_command (char *args
, int from_tty
)
2164 if (target_can_async_p ())
2167 int all_threads
= 0;
2169 dont_repeat (); /* Not for the faint of heart */
2172 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2175 if (!non_stop
&& all_threads
)
2176 error (_("-a is meaningless in all-stop mode."));
2179 ptid
= minus_one_ptid
;
2181 ptid
= inferior_ptid
;
2188 print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2189 struct frame_info
*frame
, const char *args
)
2191 if (gdbarch_print_float_info_p (gdbarch
))
2192 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2196 int printed_something
= 0;
2199 regnum
< gdbarch_num_regs (gdbarch
)
2200 + gdbarch_num_pseudo_regs (gdbarch
);
2203 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2205 printed_something
= 1;
2206 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2209 if (!printed_something
)
2210 fprintf_filtered (file
, "\
2211 No floating-point info available for this processor.\n");
2216 float_info (char *args
, int from_tty
)
2218 if (!target_has_registers
)
2219 error (_("The program has no registers now."));
2221 print_float_info (current_gdbarch
, gdb_stdout
,
2222 get_selected_frame (NULL
), args
);
2226 unset_command (char *args
, int from_tty
)
2228 printf_filtered (_("\
2229 \"unset\" must be followed by the name of an unset subcommand.\n"));
2230 help_list (unsetlist
, "unset ", -1, gdb_stdout
);
2234 _initialize_infcmd (void)
2236 struct cmd_list_element
*c
= NULL
;
2238 /* add the filename of the terminal connected to inferior I/O */
2239 add_setshow_filename_cmd ("inferior-tty", class_run
,
2240 &inferior_io_terminal
, _("\
2241 Set terminal for future runs of program being debugged."), _("\
2242 Show terminal for future runs of program being debugged."), _("\
2243 Usage: set inferior-tty /dev/pts/1"), NULL
, NULL
, &setlist
, &showlist
);
2244 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2246 add_setshow_optional_filename_cmd ("args", class_run
,
2247 &inferior_args
, _("\
2248 Set argument list to give program being debugged when it is started."), _("\
2249 Show argument list to give program being debugged when it is started."), _("\
2250 Follow this command with any number of args, to be passed to the program."),
2253 &setlist
, &showlist
);
2255 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2256 The environment to give the program, or one variable's value.\n\
2257 With an argument VAR, prints the value of environment variable VAR to\n\
2258 give the program being debugged. With no arguments, prints the entire\n\
2259 environment to be given to the program."), &showlist
);
2260 set_cmd_completer (c
, noop_completer
);
2262 add_prefix_cmd ("unset", no_class
, unset_command
,
2263 _("Complement to certain \"set\" commands."),
2264 &unsetlist
, "unset ", 0, &cmdlist
);
2266 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2267 Cancel environment variable VAR for the program.\n\
2268 This does not affect the program until the next \"run\" command."),
2270 set_cmd_completer (c
, noop_completer
);
2272 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2273 Set environment variable value to give the program.\n\
2274 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2275 VALUES of environment variables are uninterpreted strings.\n\
2276 This does not affect the program until the next \"run\" command."),
2278 set_cmd_completer (c
, noop_completer
);
2280 c
= add_com ("path", class_files
, path_command
, _("\
2281 Add directory DIR(s) to beginning of search path for object files.\n\
2282 $cwd in the path means the current working directory.\n\
2283 This path is equivalent to the $PATH shell variable. It is a list of\n\
2284 directories, separated by colons. These directories are searched to find\n\
2285 fully linked executable files and separately compiled object files as needed."));
2286 set_cmd_completer (c
, filename_completer
);
2288 c
= add_cmd ("paths", no_class
, path_info
, _("\
2289 Current search path for finding object files.\n\
2290 $cwd in the path means the current working directory.\n\
2291 This path is equivalent to the $PATH shell variable. It is a list of\n\
2292 directories, separated by colons. These directories are searched to find\n\
2293 fully linked executable files and separately compiled object files as needed."),
2295 set_cmd_completer (c
, noop_completer
);
2297 add_com ("attach", class_run
, attach_command
, _("\
2298 Attach to a process or file outside of GDB.\n\
2299 This command attaches to another target, of the same type as your last\n\
2300 \"target\" command (\"info files\" will show your target stack).\n\
2301 The command may take as argument a process id or a device file.\n\
2302 For a process id, you must have permission to send the process a signal,\n\
2303 and it must have the same effective uid as the debugger.\n\
2304 When using \"attach\" with a process id, the debugger finds the\n\
2305 program running in the process, looking first in the current working\n\
2306 directory, or (if not found there) using the source file search path\n\
2307 (see the \"directory\" command). You can also use the \"file\" command\n\
2308 to specify the program, and to load its symbol table."));
2310 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
2311 Detach a process or file previously attached.\n\
2312 If a process, it is no longer traced, and it continues its execution. If\n\
2313 you were debugging a file, the file is closed and gdb no longer accesses it."),
2314 &detachlist
, "detach ", 0, &cmdlist
);
2316 add_com ("disconnect", class_run
, disconnect_command
, _("\
2317 Disconnect from a target.\n\
2318 The target will wait for another debugger to connect. Not available for\n\
2321 add_com ("signal", class_run
, signal_command
, _("\
2322 Continue program giving it signal specified by the argument.\n\
2323 An argument of \"0\" means continue program without giving it a signal."));
2325 add_com ("stepi", class_run
, stepi_command
, _("\
2326 Step one instruction exactly.\n\
2327 Argument N means do this N times (or till program stops for another reason)."));
2328 add_com_alias ("si", "stepi", class_alias
, 0);
2330 add_com ("nexti", class_run
, nexti_command
, _("\
2331 Step one instruction, but proceed through subroutine calls.\n\
2332 Argument N means do this N times (or till program stops for another reason)."));
2333 add_com_alias ("ni", "nexti", class_alias
, 0);
2335 add_com ("finish", class_run
, finish_command
, _("\
2336 Execute until selected stack frame returns.\n\
2337 Upon return, the value returned is printed and put in the value history."));
2338 add_com_alias ("fin", "finish", class_run
, 1);
2340 add_com ("next", class_run
, next_command
, _("\
2341 Step program, proceeding through subroutine calls.\n\
2342 Like the \"step\" command as long as subroutine calls do not happen;\n\
2343 when they do, the call is treated as one instruction.\n\
2344 Argument N means do this N times (or till program stops for another reason)."));
2345 add_com_alias ("n", "next", class_run
, 1);
2347 add_com_alias ("S", "next", class_run
, 1);
2349 add_com ("step", class_run
, step_command
, _("\
2350 Step program until it reaches a different source line.\n\
2351 Argument N means do this N times (or till program stops for another reason)."));
2352 add_com_alias ("s", "step", class_run
, 1);
2354 c
= add_com ("until", class_run
, until_command
, _("\
2355 Execute until the program reaches a source line greater than the current\n\
2356 or a specified location (same args as break command) within the current frame."));
2357 set_cmd_completer (c
, location_completer
);
2358 add_com_alias ("u", "until", class_run
, 1);
2360 c
= add_com ("advance", class_run
, advance_command
, _("\
2361 Continue the program up to the given location (same form as args for break command).\n\
2362 Execution will also stop upon exit from the current stack frame."));
2363 set_cmd_completer (c
, location_completer
);
2365 c
= add_com ("jump", class_run
, jump_command
, _("\
2366 Continue program being debugged at specified line or address.\n\
2367 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2368 for an address to start at."));
2369 set_cmd_completer (c
, location_completer
);
2373 c
= add_com ("go", class_run
, go_command
, _("\
2374 Usage: go <location>\n\
2375 Continue program being debugged, stopping at specified line or \n\
2377 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2378 expression for an address to start at.\n\
2379 This command is a combination of tbreak and jump."));
2380 set_cmd_completer (c
, location_completer
);
2384 add_com_alias ("g", "go", class_run
, 1);
2386 c
= add_com ("continue", class_run
, continue_command
, _("\
2387 Continue program being debugged, after signal or breakpoint.\n\
2388 If proceeding from breakpoint, a number N may be used as an argument,\n\
2389 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2390 the breakpoint won't break until the Nth time it is reached).\n\
2392 If non-stop mode is enabled, continue only the current thread,\n\
2393 otherwise all the threads in the program are continued. To \n\
2394 continue all stopped threads in non-stop mode, use the -a option.\n\
2395 Specifying -a and an ignore count simultaneously is an error."));
2396 add_com_alias ("c", "cont", class_run
, 1);
2397 add_com_alias ("fg", "cont", class_run
, 1);
2398 set_cmd_async_ok (c
);
2400 c
= add_com ("run", class_run
, run_command
, _("\
2401 Start debugged program. You may specify arguments to give it.\n\
2402 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2403 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2404 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2405 To cancel previous arguments and run with no arguments,\n\
2406 use \"set args\" without arguments."));
2407 set_cmd_completer (c
, filename_completer
);
2408 add_com_alias ("r", "run", class_run
, 1);
2410 add_com ("R", class_run
, run_no_args_command
,
2411 _("Start debugged program with no arguments."));
2413 c
= add_com ("start", class_run
, start_command
, _("\
2414 Run the debugged program until the beginning of the main procedure.\n\
2415 You may specify arguments to give to your program, just as with the\n\
2416 \"run\" command."));
2417 set_cmd_completer (c
, filename_completer
);
2419 c
= add_com ("interrupt", class_run
, interrupt_target_command
,
2420 _("Interrupt the execution of the debugged program.\n\
2421 If non-stop mode is enabled, interrupt only the current thread,\n\
2422 otherwise all the threads in the program are stopped. To \n\
2423 interrupt all running threads in non-stop mode, use the -a option."));
2424 set_cmd_async_ok (c
);
2426 add_info ("registers", nofp_registers_info
, _("\
2427 List of integer registers and their contents, for selected stack frame.\n\
2428 Register name as argument means describe only that register."));
2429 add_info_alias ("r", "registers", 1);
2432 add_com ("lr", class_info
, nofp_registers_info
, _("\
2433 List of integer registers and their contents, for selected stack frame.\n\
2434 Register name as argument means describe only that register."));
2435 add_info ("all-registers", all_registers_info
, _("\
2436 List of all registers and their contents, for selected stack frame.\n\
2437 Register name as argument means describe only that register."));
2439 add_info ("program", program_info
,
2440 _("Execution status of the program."));
2442 add_info ("float", float_info
,
2443 _("Print the status of the floating point unit\n"));
2445 add_info ("vector", vector_info
,
2446 _("Print the status of the vector unit\n"));
2448 inferior_environ
= make_environ ();
2449 init_environ (inferior_environ
);