1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
36 #include "completer.h"
38 #include "event-top.h"
39 #include "parser-defs.h"
41 #include "reggroups.h"
46 #include "target-descriptions.h"
47 #include "user-regs.h"
48 #include "cli/cli-decode.h"
49 #include "gdbthread.h"
51 #include "inline-frame.h"
52 #include "tracepoint.h"
54 #include "continuations.h"
56 #include "cli/cli-utils.h"
58 #include "thread-fsm.h"
62 /* Local functions: */
64 static void nofp_registers_info (char *, int);
66 static void until_next_command (int);
68 static void until_command (char *, int);
70 static void path_info (char *, int);
72 static void path_command (char *, int);
74 static void unset_command (char *, int);
76 static void float_info (char *, int);
78 static void disconnect_command (char *, int);
80 static void unset_environment_command (char *, int);
82 static void set_environment_command (char *, int);
84 static void environment_info (char *, int);
86 static void program_info (char *, int);
88 static void finish_command (char *, int);
90 static void signal_command (char *, int);
92 static void jump_command (char *, int);
94 static void step_1 (int, int, char *);
96 static void next_command (char *, int);
98 static void step_command (char *, int);
100 static void run_command (char *, int);
102 void _initialize_infcmd (void);
104 #define ERROR_NO_INFERIOR \
105 if (!target_has_execution) error (_("The program is not being run."));
107 /* Scratch area where string containing arguments to give to the
108 program will be stored by 'set args'. As soon as anything is
109 stored, notice_args_set will move it into per-inferior storage.
110 Arguments are separated by spaces. Empty string (pointer to '\0')
113 static char *inferior_args_scratch
;
115 /* Scratch area where 'set inferior-tty' will store user-provided value.
116 We'll immediate copy it into per-inferior storage. */
118 static char *inferior_io_terminal_scratch
;
120 /* Pid of our debugged inferior, or 0 if no inferior now.
121 Since various parts of infrun.c test this to see whether there is a program
122 being debugged it should be nonzero (currently 3 is used) for remote
125 ptid_t inferior_ptid
;
127 /* Address at which inferior stopped. */
131 /* Nonzero if stopped due to completion of a stack dummy routine. */
133 enum stop_stack_kind stop_stack_dummy
;
135 /* Nonzero if stopped due to a random (unexpected) signal in inferior
138 int stopped_by_random_signal
;
140 /* See inferior.h. */
142 int startup_with_shell
= 1;
145 /* Accessor routines. */
147 /* Set the io terminal for the current inferior. Ownership of
148 TERMINAL_NAME is not transferred. */
151 set_inferior_io_terminal (const char *terminal_name
)
153 xfree (current_inferior ()->terminal
);
155 if (terminal_name
!= NULL
&& *terminal_name
!= '\0')
156 current_inferior ()->terminal
= xstrdup (terminal_name
);
158 current_inferior ()->terminal
= NULL
;
162 get_inferior_io_terminal (void)
164 return current_inferior ()->terminal
;
168 set_inferior_tty_command (char *args
, int from_tty
,
169 struct cmd_list_element
*c
)
171 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
172 Now route it to current inferior. */
173 set_inferior_io_terminal (inferior_io_terminal_scratch
);
177 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
178 struct cmd_list_element
*c
, const char *value
)
180 /* Note that we ignore the passed-in value in favor of computing it
182 const char *inferior_io_terminal
= get_inferior_io_terminal ();
184 if (inferior_io_terminal
== NULL
)
185 inferior_io_terminal
= "";
186 fprintf_filtered (gdb_stdout
,
187 _("Terminal for future runs of program being debugged "
188 "is \"%s\".\n"), inferior_io_terminal
);
192 get_inferior_args (void)
194 if (current_inferior ()->argc
!= 0)
198 n
= construct_inferior_arguments (current_inferior ()->argc
,
199 current_inferior ()->argv
);
200 set_inferior_args (n
);
204 if (current_inferior ()->args
== NULL
)
205 current_inferior ()->args
= xstrdup ("");
207 return current_inferior ()->args
;
210 /* Set the arguments for the current inferior. Ownership of
211 NEWARGS is not transferred. */
214 set_inferior_args (char *newargs
)
216 xfree (current_inferior ()->args
);
217 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
218 current_inferior ()->argc
= 0;
219 current_inferior ()->argv
= 0;
223 set_inferior_args_vector (int argc
, char **argv
)
225 current_inferior ()->argc
= argc
;
226 current_inferior ()->argv
= argv
;
229 /* Notice when `set args' is run. */
232 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
234 /* CLI has assigned the user-provided value to inferior_args_scratch.
235 Now route it to current inferior. */
236 set_inferior_args (inferior_args_scratch
);
239 /* Notice when `show args' is run. */
242 show_args_command (struct ui_file
*file
, int from_tty
,
243 struct cmd_list_element
*c
, const char *value
)
245 /* Note that we ignore the passed-in value in favor of computing it
247 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
251 /* Compute command-line string given argument vector. This does the
252 same shell processing as fork_inferior. */
255 construct_inferior_arguments (int argc
, char **argv
)
259 if (startup_with_shell
)
262 /* This holds all the characters considered special to the
264 static const char special
[] = "\"!&*|[]{}<>?`~^=;, \t\n";
265 static const char quote
= '"';
267 /* This holds all the characters considered special to the
268 typical Unix shells. We include `^' because the SunOS
269 /bin/sh treats it as a synonym for `|'. */
270 static const char special
[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
271 static const char quote
= '\'';
277 /* We over-compute the size. It shouldn't matter. */
278 for (i
= 0; i
< argc
; ++i
)
279 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
281 result
= (char *) xmalloc (length
);
284 for (i
= 0; i
< argc
; ++i
)
289 /* Need to handle empty arguments specially. */
290 if (argv
[i
][0] == '\0')
300 if (strpbrk (argv
[i
], special
))
306 for (cp
= argv
[i
]; *cp
; ++cp
)
310 /* A newline cannot be quoted with a backslash (it
311 just disappears), only by putting it inside
322 if (strchr (special
, *cp
) != NULL
)
338 /* In this case we can't handle arguments that contain spaces,
339 tabs, or newlines -- see breakup_args(). */
343 for (i
= 0; i
< argc
; ++i
)
345 char *cp
= strchr (argv
[i
], ' ');
347 cp
= strchr (argv
[i
], '\t');
349 cp
= strchr (argv
[i
], '\n');
351 error (_("can't handle command-line "
352 "argument containing whitespace"));
353 length
+= strlen (argv
[i
]) + 1;
356 result
= (char *) xmalloc (length
);
358 for (i
= 0; i
< argc
; ++i
)
361 strcat (result
, " ");
362 strcat (result
, argv
[i
]);
370 /* This function strips the '&' character (indicating background
371 execution) that is added as *the last* of the arguments ARGS of a
372 command. A copy of the incoming ARGS without the '&' is returned,
373 unless the resulting string after stripping is empty, in which case
374 NULL is returned. *BG_CHAR_P is an output boolean that indicates
375 whether the '&' character was found. */
378 strip_bg_char (const char *args
, int *bg_char_p
)
382 if (args
== NULL
|| *args
== '\0')
388 p
= args
+ strlen (args
);
392 while (p
> args
&& isspace (p
[-1]))
397 return savestring (args
, p
- args
);
403 return xstrdup (args
);
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
)
414 /* Be sure we own the terminal in case write operations are performed. */
415 target_terminal_ours_for_output ();
417 /* If the target hasn't taken care of this already, do it now.
418 Targets which need to access registers during to_open,
419 to_create_inferior, or to_attach should do it earlier; but many
421 target_find_description ();
423 /* Now that we know the register layout, retrieve current PC. But
424 if the PC is unavailable (e.g., we're opening a core file with
425 missing registers info), ignore it. */
429 stop_pc
= regcache_read_pc (get_current_regcache ());
431 CATCH (ex
, RETURN_MASK_ERROR
)
433 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
434 throw_exception (ex
);
440 const unsigned solib_add_generation
441 = current_program_space
->solib_add_generation
;
443 /* Create the hooks to handle shared library load and unload
445 solib_create_inferior_hook (from_tty
);
447 if (current_program_space
->solib_add_generation
== solib_add_generation
)
449 /* The platform-specific hook should load initial shared libraries,
450 but didn't. FROM_TTY will be incorrectly 0 but such solib
451 targets should be fixed anyway. Call it only after the solib
452 target has been initialized by solib_create_inferior_hook. */
455 warning (_("platform-specific solib_create_inferior_hook did "
456 "not load initial shared libraries."));
458 /* If the solist is global across processes, there's no need to
460 if (!gdbarch_has_global_solist (target_gdbarch ()))
461 solib_add (NULL
, 0, auto_solib_add
);
465 /* If the user sets watchpoints before execution having started,
466 then she gets software watchpoints, because GDB can't know which
467 target will end up being pushed, or if it supports hardware
468 watchpoints or not. breakpoint_re_set takes care of promoting
469 watchpoints to hardware watchpoints if possible, however, if this
470 new inferior doesn't load shared libraries or we don't pull in
471 symbols from any other source on this target/arch,
472 breakpoint_re_set is never called. Call it now so that software
473 watchpoints get a chance to be promoted to hardware watchpoints
474 if the now pushed target supports hardware watchpoints. */
475 breakpoint_re_set ();
477 observer_notify_inferior_created (target
, from_tty
);
480 /* Kill the inferior if already running. This function is designed
481 to be called when we are about to start the execution of the program
482 from the beginning. Ask the user to confirm that he wants to restart
483 the program being debugged when FROM_TTY is non-null. */
486 kill_if_already_running (int from_tty
)
488 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
490 /* Bail out before killing the program if we will not be able to
492 target_require_runnable ();
495 && !query (_("The program being debugged has been started already.\n\
496 Start it from the beginning? ")))
497 error (_("Program not restarted."));
502 /* See inferior.h. */
505 prepare_execution_command (struct target_ops
*target
, int background
)
507 /* If we get a request for running in the bg but the target
508 doesn't support it, error out. */
509 if (background
&& !target
->to_can_async_p (target
))
510 error (_("Asynchronous execution not supported on this target."));
514 /* If we get a request for running in the fg, then we need to
515 simulate synchronous (fg) execution. Note no cleanup is
516 necessary for this. stdin is re-enabled whenever an error
517 reaches the top level. */
518 all_uis_on_sync_execution_starting ();
522 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
523 a temporary breakpoint at the begining of the main program before
524 running the program. */
527 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
530 struct cleanup
*old_chain
;
532 struct ui_out
*uiout
= current_uiout
;
533 struct target_ops
*run_target
;
535 struct cleanup
*args_chain
;
539 kill_if_already_running (from_tty
);
541 init_wait_for_inferior ();
542 clear_breakpoint_hit_counts ();
544 /* Clean up any leftovers from other runs. Some other things from
545 this function should probably be moved into target_pre_inferior. */
546 target_pre_inferior (from_tty
);
548 /* The comment here used to read, "The exec file is re-read every
549 time we do a generic_mourn_inferior, so we just have to worry
550 about the symbol file." The `generic_mourn_inferior' function
551 gets called whenever the program exits. However, suppose the
552 program exits, and *then* the executable file changes? We need
553 to check again here. Since reopen_exec_file doesn't do anything
554 if the timestamp hasn't changed, I don't see the harm. */
558 args
= strip_bg_char (args
, &async_exec
);
559 args_chain
= make_cleanup (xfree
, args
);
561 /* Do validation and preparation before possibly changing anything
564 run_target
= find_run_target ();
566 prepare_execution_command (run_target
, async_exec
);
568 if (non_stop
&& !run_target
->to_supports_non_stop (run_target
))
569 error (_("The target does not support running in non-stop mode."));
571 /* Done. Can now set breakpoints, change inferior args, etc. */
573 /* Insert the temporary breakpoint if a location was specified. */
575 tbreak_command (main_name (), 0);
577 exec_file
= (char *) get_exec_file (0);
579 /* We keep symbols from add-symbol-file, on the grounds that the
580 user might want to add some symbols before running the program
581 (right?). But sometimes (dynamic loading where the user manually
582 introduces the new symbols with add-symbol-file), the code which
583 the symbols describe does not persist between runs. Currently
584 the user has to manually nuke all symbols between runs if they
585 want them to go away (PR 2207). This is probably reasonable. */
587 /* If there were other args, beside '&', process them. */
589 set_inferior_args (args
);
593 uiout
->field_string (NULL
, "Starting program");
596 uiout
->field_string ("execfile", exec_file
);
598 /* We call get_inferior_args() because we might need to compute
600 uiout
->field_string ("infargs", get_inferior_args ());
605 /* Done with ARGS. */
606 do_cleanups (args_chain
);
608 /* We call get_inferior_args() because we might need to compute
610 run_target
->to_create_inferior (run_target
, exec_file
, get_inferior_args (),
611 environ_vector (current_inferior ()->environment
),
613 /* to_create_inferior should push the target, so after this point we
614 shouldn't refer to run_target again. */
617 /* We're starting off a new process. When we get out of here, in
618 non-stop mode, finish the state of all threads of that process,
619 but leave other threads alone, as they may be stopped in internal
620 events --- the frontend shouldn't see them as stopped. In
621 all-stop, always finish the state of all threads, as we may be
622 resuming more than just the new process. */
624 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
626 ptid
= minus_one_ptid
;
627 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
629 /* Pass zero for FROM_TTY, because at this point the "run" command
630 has done its thing; now we are setting up the running program. */
631 post_create_inferior (¤t_target
, 0);
633 /* Start the target running. Do not use -1 continuation as it would skip
634 breakpoint right at the entry point. */
635 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
637 /* Since there was no error, there's no need to finish the thread
639 discard_cleanups (old_chain
);
643 run_command (char *args
, int from_tty
)
645 run_command_1 (args
, from_tty
, 0);
648 /* Start the execution of the program up until the beginning of the main
652 start_command (char *args
, int from_tty
)
654 /* Some languages such as Ada need to search inside the program
655 minimal symbols for the location where to put the temporary
656 breakpoint before starting. */
657 if (!have_minimal_symbols ())
658 error (_("No symbol table loaded. Use the \"file\" command."));
660 /* Run the program until reaching the main procedure... */
661 run_command_1 (args
, from_tty
, 1);
665 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
667 /* We go through all threads individually instead of compressing
668 into a single target `resume_all' request, because some threads
669 may be stopped in internal breakpoints/events, or stopped waiting
670 for its turn in the displaced stepping queue (that is, they are
671 running && !executing). The target side has no idea about why
672 the thread is stopped, so a `resume_all' command would resume too
673 much. If/when GDB gains a way to tell the target `hold this
674 thread stopped until I say otherwise', then we can optimize
676 if (!is_stopped (thread
->ptid
))
679 switch_to_thread (thread
->ptid
);
680 clear_proceed_status (0);
681 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
686 ensure_valid_thread (void)
688 if (ptid_equal (inferior_ptid
, null_ptid
)
689 || is_exited (inferior_ptid
))
690 error (_("Cannot execute this command without a live selected thread."));
693 /* If the user is looking at trace frames, any resumption of execution
694 is likely to mix up recorded and live target data. So simply
695 disallow those commands. */
698 ensure_not_tfind_mode (void)
700 if (get_traceframe_number () >= 0)
701 error (_("Cannot execute this command while looking at trace frames."));
704 /* Throw an error indicating the current thread is running. */
707 error_is_running (void)
709 error (_("Cannot execute this command while "
710 "the selected thread is running."));
713 /* Calls error_is_running if the current thread is running. */
716 ensure_not_running (void)
718 if (is_running (inferior_ptid
))
723 continue_1 (int all_threads
)
726 ensure_not_tfind_mode ();
728 if (non_stop
&& all_threads
)
730 /* Don't error out if the current thread is running, because
731 there may be other stopped threads. */
732 struct cleanup
*old_chain
;
734 /* Backup current thread and selected frame. */
735 old_chain
= make_cleanup_restore_current_thread ();
737 iterate_over_threads (proceed_thread_callback
, NULL
);
739 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
741 /* If all threads in the target were already running,
742 proceed_thread_callback ends up never calling proceed,
743 and so nothing calls this to put the inferior's terminal
744 settings in effect and remove stdin from the event loop,
745 which we must when running a foreground command. E.g.:
749 <all threads are running now>
752 <no thread was resumed, but the inferior now owns the terminal>
754 target_terminal_inferior ();
757 /* Restore selected ptid. */
758 do_cleanups (old_chain
);
762 ensure_valid_thread ();
763 ensure_not_running ();
764 clear_proceed_status (0);
765 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
769 /* continue [-a] [proceed-count] [&] */
772 continue_command (char *args
, int from_tty
)
776 struct cleanup
*args_chain
;
780 /* Find out whether we must run in the background. */
781 args
= strip_bg_char (args
, &async_exec
);
782 args_chain
= make_cleanup (xfree
, args
);
786 if (startswith (args
, "-a"))
789 args
+= sizeof ("-a") - 1;
795 if (!non_stop
&& all_threads
)
796 error (_("`-a' is meaningless in all-stop mode."));
798 if (args
!= NULL
&& all_threads
)
799 error (_("Can't resume all threads and specify "
800 "proceed count simultaneously."));
802 /* If we have an argument left, set proceed count of breakpoint we
809 struct thread_info
*tp
;
812 tp
= find_thread_ptid (inferior_ptid
);
816 struct target_waitstatus ws
;
818 get_last_target_status (&last_ptid
, &ws
);
819 tp
= find_thread_ptid (last_ptid
);
822 bs
= tp
->control
.stop_bpstat
;
824 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
827 set_ignore_count (num
,
828 parse_and_eval_long (args
) - 1,
830 /* set_ignore_count prints a message ending with a period.
831 So print two spaces before "Continuing.". */
833 printf_filtered (" ");
837 if (!stopped
&& from_tty
)
840 ("Not stopped at any breakpoint; argument ignored.\n");
844 /* Done with ARGS. */
845 do_cleanups (args_chain
);
848 ensure_not_tfind_mode ();
850 if (!non_stop
|| !all_threads
)
852 ensure_valid_thread ();
853 ensure_not_running ();
856 prepare_execution_command (¤t_target
, async_exec
);
859 printf_filtered (_("Continuing.\n"));
861 continue_1 (all_threads
);
864 /* Record the starting point of a "step" or "next" command. */
867 set_step_frame (void)
869 struct symtab_and_line sal
;
871 struct frame_info
*frame
= get_current_frame ();
872 struct thread_info
*tp
= inferior_thread ();
874 find_frame_sal (frame
, &sal
);
875 set_step_info (frame
, sal
);
876 pc
= get_frame_pc (frame
);
877 tp
->control
.step_start_function
= find_pc_function (pc
);
880 /* Step until outside of current statement. */
883 step_command (char *count_string
, int from_tty
)
885 step_1 (0, 0, count_string
);
888 /* Likewise, but skip over subroutine calls as if single instructions. */
891 next_command (char *count_string
, int from_tty
)
893 step_1 (1, 0, count_string
);
896 /* Likewise, but step only one instruction. */
899 stepi_command (char *count_string
, int from_tty
)
901 step_1 (0, 1, count_string
);
905 nexti_command (char *count_string
, int from_tty
)
907 step_1 (1, 1, count_string
);
911 delete_longjmp_breakpoint_cleanup (void *arg
)
913 int thread
= * (int *) arg
;
914 delete_longjmp_breakpoint (thread
);
917 /* Data for the FSM that manages the step/next/stepi/nexti
920 struct step_command_fsm
922 /* The base class. */
923 struct thread_fsm thread_fsm
;
925 /* How many steps left in a "step N"-like command. */
928 /* If true, this is a next/nexti, otherwise a step/stepi. */
929 int skip_subroutines
;
931 /* If true, this is a stepi/nexti, otherwise a step/step. */
935 static void step_command_fsm_clean_up (struct thread_fsm
*self
,
936 struct thread_info
*thread
);
937 static int step_command_fsm_should_stop (struct thread_fsm
*self
,
938 struct thread_info
*thread
);
939 static enum async_reply_reason
940 step_command_fsm_async_reply_reason (struct thread_fsm
*self
);
942 /* step_command_fsm's vtable. */
944 static struct thread_fsm_ops step_command_fsm_ops
=
947 step_command_fsm_clean_up
,
948 step_command_fsm_should_stop
,
949 NULL
, /* return_value */
950 step_command_fsm_async_reply_reason
,
953 /* Allocate a new step_command_fsm. */
955 static struct step_command_fsm
*
956 new_step_command_fsm (struct interp
*cmd_interp
)
958 struct step_command_fsm
*sm
;
960 sm
= XCNEW (struct step_command_fsm
);
961 thread_fsm_ctor (&sm
->thread_fsm
, &step_command_fsm_ops
, cmd_interp
);
966 /* Prepare for a step/next/etc. command. Any target resource
967 allocated here is undone in the FSM's clean_up method. */
970 step_command_fsm_prepare (struct step_command_fsm
*sm
,
971 int skip_subroutines
, int single_inst
,
972 int count
, struct thread_info
*thread
)
974 sm
->skip_subroutines
= skip_subroutines
;
975 sm
->single_inst
= single_inst
;
978 /* Leave the si command alone. */
979 if (!sm
->single_inst
|| sm
->skip_subroutines
)
980 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
982 thread
->control
.stepping_command
= 1;
985 static int prepare_one_step (struct step_command_fsm
*sm
);
988 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
992 struct cleanup
*args_chain
;
993 struct thread_info
*thr
;
994 struct step_command_fsm
*step_sm
;
997 ensure_not_tfind_mode ();
998 ensure_valid_thread ();
999 ensure_not_running ();
1001 count_string
= strip_bg_char (count_string
, &async_exec
);
1002 args_chain
= make_cleanup (xfree
, count_string
);
1004 prepare_execution_command (¤t_target
, async_exec
);
1006 count
= count_string
? parse_and_eval_long (count_string
) : 1;
1008 /* Done with ARGS. */
1009 do_cleanups (args_chain
);
1011 clear_proceed_status (1);
1013 /* Setup the execution command state machine to handle all the COUNT
1015 thr
= inferior_thread ();
1016 step_sm
= new_step_command_fsm (command_interp ());
1017 thr
->thread_fsm
= &step_sm
->thread_fsm
;
1019 step_command_fsm_prepare (step_sm
, skip_subroutines
,
1020 single_inst
, count
, thr
);
1022 /* Do only one step for now, before returning control to the event
1023 loop. Let the continuation figure out how many other steps we
1024 need to do, and handle them one at the time, through
1026 if (!prepare_one_step (step_sm
))
1027 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1032 /* Stepped into an inline frame. Pretend that we've
1034 thread_fsm_clean_up (thr
->thread_fsm
, thr
);
1035 proceeded
= normal_stop ();
1037 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1038 all_uis_check_sync_execution_done ();
1042 /* Implementation of the 'should_stop' FSM method for stepping
1043 commands. Called after we are done with one step operation, to
1044 check whether we need to step again, before we print the prompt and
1045 return control to the user. If count is > 1, returns false, as we
1046 will need to keep going. */
1049 step_command_fsm_should_stop (struct thread_fsm
*self
, struct thread_info
*tp
)
1051 struct step_command_fsm
*sm
= (struct step_command_fsm
*) self
;
1053 if (tp
->control
.stop_step
)
1055 /* There are more steps to make, and we did stop due to
1056 ending a stepping range. Do another step. */
1057 if (--sm
->count
> 0)
1058 return prepare_one_step (sm
);
1060 thread_fsm_set_finished (self
);
1066 /* Implementation of the 'clean_up' FSM method for stepping commands. */
1069 step_command_fsm_clean_up (struct thread_fsm
*self
, struct thread_info
*thread
)
1071 struct step_command_fsm
*sm
= (struct step_command_fsm
*) self
;
1073 if (!sm
->single_inst
|| sm
->skip_subroutines
)
1074 delete_longjmp_breakpoint (thread
->global_num
);
1077 /* Implementation of the 'async_reply_reason' FSM method for stepping
1080 static enum async_reply_reason
1081 step_command_fsm_async_reply_reason (struct thread_fsm
*self
)
1083 return EXEC_ASYNC_END_STEPPING_RANGE
;
1086 /* Prepare for one step in "step N". The actual target resumption is
1087 done by the caller. Return true if we're done and should thus
1088 report a stop to the user. Returns false if the target needs to be
1092 prepare_one_step (struct step_command_fsm
*sm
)
1096 struct frame_info
*frame
= get_current_frame ();
1098 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1099 the longjmp breakpoint was not required. Use the
1100 INFERIOR_PTID thread instead, which is the same thread when
1102 struct thread_info
*tp
= inferior_thread ();
1106 if (!sm
->single_inst
)
1110 /* Step at an inlined function behaves like "down". */
1111 if (!sm
->skip_subroutines
1112 && inline_skipped_frames (inferior_ptid
))
1116 /* Pretend that we've ran. */
1117 resume_ptid
= user_visible_resume_ptid (1);
1118 set_running (resume_ptid
, 1);
1120 step_into_inline_frame (inferior_ptid
);
1122 return prepare_one_step (sm
);
1125 pc
= get_frame_pc (frame
);
1126 find_pc_line_pc_range (pc
,
1127 &tp
->control
.step_range_start
,
1128 &tp
->control
.step_range_end
);
1130 tp
->control
.may_range_step
= 1;
1132 /* If we have no line info, switch to stepi mode. */
1133 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1135 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1136 tp
->control
.may_range_step
= 0;
1138 else if (tp
->control
.step_range_end
== 0)
1142 if (find_pc_partial_function (pc
, &name
,
1143 &tp
->control
.step_range_start
,
1144 &tp
->control
.step_range_end
) == 0)
1145 error (_("Cannot find bounds of current function"));
1147 target_terminal_ours_for_output ();
1148 printf_filtered (_("Single stepping until exit from function %s,"
1149 "\nwhich has no line number information.\n"),
1155 /* Say we are stepping, but stop after one insn whatever it does. */
1156 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1157 if (!sm
->skip_subroutines
)
1159 Don't step over function calls, not even to functions lacking
1161 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1164 if (sm
->skip_subroutines
)
1165 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1171 thread_fsm_set_finished (&sm
->thread_fsm
);
1176 /* Continue program at specified address. */
1179 jump_command (char *arg
, int from_tty
)
1181 struct gdbarch
*gdbarch
= get_current_arch ();
1183 struct symtabs_and_lines sals
;
1184 struct symtab_and_line sal
;
1188 struct cleanup
*args_chain
;
1191 ensure_not_tfind_mode ();
1192 ensure_valid_thread ();
1193 ensure_not_running ();
1195 /* Find out whether we must run in the background. */
1196 arg
= strip_bg_char (arg
, &async_exec
);
1197 args_chain
= make_cleanup (xfree
, arg
);
1199 prepare_execution_command (¤t_target
, async_exec
);
1202 error_no_arg (_("starting address"));
1204 sals
= decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1205 if (sals
.nelts
!= 1)
1207 error (_("Unreasonable jump request"));
1213 /* Done with ARGS. */
1214 do_cleanups (args_chain
);
1216 if (sal
.symtab
== 0 && sal
.pc
== 0)
1217 error (_("No source file has been specified."));
1219 resolve_sal_pc (&sal
); /* May error out. */
1221 /* See if we are trying to jump to another function. */
1222 fn
= get_frame_function (get_current_frame ());
1223 sfn
= find_pc_function (sal
.pc
);
1224 if (fn
!= NULL
&& sfn
!= fn
)
1226 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1227 SYMBOL_PRINT_NAME (fn
)))
1229 error (_("Not confirmed."));
1236 struct obj_section
*section
;
1238 fixup_symbol_section (sfn
, 0);
1239 section
= SYMBOL_OBJ_SECTION (symbol_objfile (sfn
), sfn
);
1240 if (section_is_overlay (section
)
1241 && !section_is_mapped (section
))
1243 if (!query (_("WARNING!!! Destination is in "
1244 "unmapped overlay! Jump anyway? ")))
1246 error (_("Not confirmed."));
1256 printf_filtered (_("Continuing at "));
1257 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1258 printf_filtered (".\n");
1261 clear_proceed_status (0);
1262 proceed (addr
, GDB_SIGNAL_0
);
1265 /* Continue program giving it specified signal. */
1268 signal_command (char *signum_exp
, int from_tty
)
1270 enum gdb_signal oursig
;
1272 struct cleanup
*args_chain
;
1274 dont_repeat (); /* Too dangerous. */
1276 ensure_not_tfind_mode ();
1277 ensure_valid_thread ();
1278 ensure_not_running ();
1280 /* Find out whether we must run in the background. */
1281 signum_exp
= strip_bg_char (signum_exp
, &async_exec
);
1282 args_chain
= make_cleanup (xfree
, signum_exp
);
1284 prepare_execution_command (¤t_target
, async_exec
);
1287 error_no_arg (_("signal number"));
1289 /* It would be even slicker to make signal names be valid expressions,
1290 (the type could be "enum $signal" or some such), then the user could
1291 assign them to convenience variables. */
1292 oursig
= gdb_signal_from_name (signum_exp
);
1294 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1296 /* No, try numeric. */
1297 int num
= parse_and_eval_long (signum_exp
);
1300 oursig
= GDB_SIGNAL_0
;
1302 oursig
= gdb_signal_from_command (num
);
1305 do_cleanups (args_chain
);
1307 /* Look for threads other than the current that this command ends up
1308 resuming too (due to schedlock off), and warn if they'll get a
1309 signal delivered. "signal 0" is used to suppress a previous
1310 signal, but if the current thread is no longer the one that got
1311 the signal, then the user is potentially suppressing the signal
1312 of the wrong thread. */
1315 struct thread_info
*tp
;
1317 int must_confirm
= 0;
1319 /* This indicates what will be resumed. Either a single thread,
1320 a whole process, or all threads of all processes. */
1321 resume_ptid
= user_visible_resume_ptid (0);
1323 ALL_NON_EXITED_THREADS (tp
)
1325 if (ptid_equal (tp
->ptid
, inferior_ptid
))
1327 if (!ptid_match (tp
->ptid
, resume_ptid
))
1330 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1331 && signal_pass_state (tp
->suspend
.stop_signal
))
1334 printf_unfiltered (_("Note:\n"));
1335 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1336 print_thread_id (tp
),
1337 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1338 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1344 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1345 "still deliver the signals noted above to their respective threads.\n"
1346 "Continue anyway? "),
1347 print_thread_id (inferior_thread ())))
1348 error (_("Not confirmed."));
1353 if (oursig
== GDB_SIGNAL_0
)
1354 printf_filtered (_("Continuing with no signal.\n"));
1356 printf_filtered (_("Continuing with signal %s.\n"),
1357 gdb_signal_to_name (oursig
));
1360 clear_proceed_status (0);
1361 proceed ((CORE_ADDR
) -1, oursig
);
1364 /* Queue a signal to be delivered to the current thread. */
1367 queue_signal_command (char *signum_exp
, int from_tty
)
1369 enum gdb_signal oursig
;
1370 struct thread_info
*tp
;
1373 ensure_not_tfind_mode ();
1374 ensure_valid_thread ();
1375 ensure_not_running ();
1377 if (signum_exp
== NULL
)
1378 error_no_arg (_("signal number"));
1380 /* It would be even slicker to make signal names be valid expressions,
1381 (the type could be "enum $signal" or some such), then the user could
1382 assign them to convenience variables. */
1383 oursig
= gdb_signal_from_name (signum_exp
);
1385 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1387 /* No, try numeric. */
1388 int num
= parse_and_eval_long (signum_exp
);
1391 oursig
= GDB_SIGNAL_0
;
1393 oursig
= gdb_signal_from_command (num
);
1396 if (oursig
!= GDB_SIGNAL_0
1397 && !signal_pass_state (oursig
))
1398 error (_("Signal handling set to not pass this signal to the program."));
1400 tp
= inferior_thread ();
1401 tp
->suspend
.stop_signal
= oursig
;
1404 /* Data for the FSM that manages the until (with no argument)
1407 struct until_next_fsm
1409 /* The base class. */
1410 struct thread_fsm thread_fsm
;
1412 /* The thread that as current when the command was executed. */
1416 static int until_next_fsm_should_stop (struct thread_fsm
*self
,
1417 struct thread_info
*thread
);
1418 static void until_next_fsm_clean_up (struct thread_fsm
*self
,
1419 struct thread_info
*thread
);
1420 static enum async_reply_reason
1421 until_next_fsm_async_reply_reason (struct thread_fsm
*self
);
1423 /* until_next_fsm's vtable. */
1425 static struct thread_fsm_ops until_next_fsm_ops
=
1428 until_next_fsm_clean_up
,
1429 until_next_fsm_should_stop
,
1430 NULL
, /* return_value */
1431 until_next_fsm_async_reply_reason
,
1434 /* Allocate a new until_next_fsm. */
1436 static struct until_next_fsm
*
1437 new_until_next_fsm (struct interp
*cmd_interp
, int thread
)
1439 struct until_next_fsm
*sm
;
1441 sm
= XCNEW (struct until_next_fsm
);
1442 thread_fsm_ctor (&sm
->thread_fsm
, &until_next_fsm_ops
, cmd_interp
);
1444 sm
->thread
= thread
;
1449 /* Implementation of the 'should_stop' FSM method for the until (with
1453 until_next_fsm_should_stop (struct thread_fsm
*self
,
1454 struct thread_info
*tp
)
1456 if (tp
->control
.stop_step
)
1457 thread_fsm_set_finished (self
);
1462 /* Implementation of the 'clean_up' FSM method for the until (with no
1466 until_next_fsm_clean_up (struct thread_fsm
*self
, struct thread_info
*thread
)
1468 struct until_next_fsm
*sm
= (struct until_next_fsm
*) self
;
1470 delete_longjmp_breakpoint (thread
->global_num
);
1473 /* Implementation of the 'async_reply_reason' FSM method for the until
1474 (with no arg) command. */
1476 static enum async_reply_reason
1477 until_next_fsm_async_reply_reason (struct thread_fsm
*self
)
1479 return EXEC_ASYNC_END_STEPPING_RANGE
;
1482 /* Proceed until we reach a different source line with pc greater than
1483 our current one or exit the function. We skip calls in both cases.
1485 Note that eventually this command should probably be changed so
1486 that only source lines are printed out when we hit the breakpoint
1487 we set. This may involve changes to wait_for_inferior and the
1488 proceed status code. */
1491 until_next_command (int from_tty
)
1493 struct frame_info
*frame
;
1495 struct symbol
*func
;
1496 struct symtab_and_line sal
;
1497 struct thread_info
*tp
= inferior_thread ();
1498 int thread
= tp
->global_num
;
1499 struct cleanup
*old_chain
;
1500 struct until_next_fsm
*sm
;
1502 clear_proceed_status (0);
1505 frame
= get_current_frame ();
1507 /* Step until either exited from this function or greater
1508 than the current line (if in symbolic section) or pc (if
1511 pc
= get_frame_pc (frame
);
1512 func
= find_pc_function (pc
);
1516 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1518 if (msymbol
.minsym
== NULL
)
1519 error (_("Execution is not within a known function."));
1521 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1522 /* The upper-bound of step_range is exclusive. In order to make PC
1523 within the range, set the step_range_end with PC + 1. */
1524 tp
->control
.step_range_end
= pc
+ 1;
1528 sal
= find_pc_line (pc
, 0);
1530 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1531 tp
->control
.step_range_end
= sal
.end
;
1533 tp
->control
.may_range_step
= 1;
1535 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1537 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1538 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1540 sm
= new_until_next_fsm (command_interp (), tp
->global_num
);
1541 tp
->thread_fsm
= &sm
->thread_fsm
;
1542 discard_cleanups (old_chain
);
1544 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1548 until_command (char *arg
, int from_tty
)
1551 struct cleanup
*args_chain
;
1554 ensure_not_tfind_mode ();
1555 ensure_valid_thread ();
1556 ensure_not_running ();
1558 /* Find out whether we must run in the background. */
1559 arg
= strip_bg_char (arg
, &async_exec
);
1560 args_chain
= make_cleanup (xfree
, arg
);
1562 prepare_execution_command (¤t_target
, async_exec
);
1565 until_break_command (arg
, from_tty
, 0);
1567 until_next_command (from_tty
);
1569 /* Done with ARGS. */
1570 do_cleanups (args_chain
);
1574 advance_command (char *arg
, int from_tty
)
1577 struct cleanup
*args_chain
;
1580 ensure_not_tfind_mode ();
1581 ensure_valid_thread ();
1582 ensure_not_running ();
1585 error_no_arg (_("a location"));
1587 /* Find out whether we must run in the background. */
1588 arg
= strip_bg_char (arg
, &async_exec
);
1589 args_chain
= make_cleanup (xfree
, arg
);
1591 prepare_execution_command (¤t_target
, async_exec
);
1593 until_break_command (arg
, from_tty
, 1);
1595 /* Done with ARGS. */
1596 do_cleanups (args_chain
);
1599 /* Return the value of the result of a function at the end of a 'finish'
1600 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1601 right after an inferior call has finished. */
1604 get_return_value (struct value
*function
, struct type
*value_type
)
1606 struct regcache
*stop_regs
;
1607 struct gdbarch
*gdbarch
;
1608 struct value
*value
;
1609 struct cleanup
*cleanup
;
1611 stop_regs
= regcache_dup (get_current_regcache ());
1612 cleanup
= make_cleanup_regcache_xfree (stop_regs
);
1614 gdbarch
= get_regcache_arch (stop_regs
);
1616 value_type
= check_typedef (value_type
);
1617 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1619 /* FIXME: 2003-09-27: When returning from a nested inferior function
1620 call, it's possible (with no help from the architecture vector)
1621 to locate and return/print a "struct return" value. This is just
1622 a more complicated case of what is already being done in the
1623 inferior function call code. In fact, when inferior function
1624 calls are made async, this will likely be made the norm. */
1626 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1629 case RETURN_VALUE_REGISTER_CONVENTION
:
1630 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1631 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1632 value
= allocate_value (value_type
);
1633 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1634 value_contents_raw (value
), NULL
);
1636 case RETURN_VALUE_STRUCT_CONVENTION
:
1640 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1643 do_cleanups (cleanup
);
1648 /* The captured function return value/type and its position in the
1651 struct return_value_info
1653 /* The captured return value. May be NULL if we weren't able to
1654 retrieve it. See get_return_value. */
1655 struct value
*value
;
1657 /* The return type. In some cases, we'll not be able extract the
1658 return value, but we always know the type. */
1661 /* If we captured a value, this is the value history index. */
1662 int value_history_index
;
1665 /* Helper for print_return_value. */
1668 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1670 if (rv
->value
!= NULL
)
1672 struct value_print_options opts
;
1675 uiout
->text ("Value returned is ");
1676 uiout
->field_fmt ("gdb-result-var", "$%d",
1677 rv
->value_history_index
);
1678 uiout
->text (" = ");
1679 get_no_prettyformat_print_options (&opts
);
1683 value_print (rv
->value
, &stb
, &opts
);
1684 uiout
->field_stream ("return-value", stb
);
1689 std::string type_name
= type_to_string (rv
->type
);
1690 uiout
->text ("Value returned has type: ");
1691 uiout
->field_string ("return-type", type_name
.c_str ());
1693 uiout
->text (" Cannot determine contents\n");
1697 /* Print the result of a function at the end of a 'finish' command.
1698 RV points at an object representing the captured return value/type
1699 and its position in the value history. */
1702 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1704 if (rv
->type
== NULL
|| TYPE_CODE (rv
->type
) == TYPE_CODE_VOID
)
1709 /* print_return_value_1 can throw an exception in some
1710 circumstances. We need to catch this so that we still
1711 delete the breakpoint. */
1712 print_return_value_1 (uiout
, rv
);
1714 CATCH (ex
, RETURN_MASK_ALL
)
1716 exception_print (gdb_stdout
, ex
);
1721 /* Data for the FSM that manages the finish command. */
1723 struct finish_command_fsm
1725 /* The base class. */
1726 struct thread_fsm thread_fsm
;
1728 /* The momentary breakpoint set at the function's return address in
1730 struct breakpoint
*breakpoint
;
1732 /* The function that we're stepping out of. */
1733 struct symbol
*function
;
1735 /* If the FSM finishes successfully, this stores the function's
1737 struct return_value_info return_value
;
1740 static int finish_command_fsm_should_stop (struct thread_fsm
*self
,
1741 struct thread_info
*thread
);
1742 static void finish_command_fsm_clean_up (struct thread_fsm
*self
,
1743 struct thread_info
*thread
);
1744 static struct return_value_info
*
1745 finish_command_fsm_return_value (struct thread_fsm
*self
);
1746 static enum async_reply_reason
1747 finish_command_fsm_async_reply_reason (struct thread_fsm
*self
);
1749 /* finish_command_fsm's vtable. */
1751 static struct thread_fsm_ops finish_command_fsm_ops
=
1754 finish_command_fsm_clean_up
,
1755 finish_command_fsm_should_stop
,
1756 finish_command_fsm_return_value
,
1757 finish_command_fsm_async_reply_reason
,
1758 NULL
, /* should_notify_stop */
1761 /* Allocate a new finish_command_fsm. */
1763 static struct finish_command_fsm
*
1764 new_finish_command_fsm (struct interp
*cmd_interp
)
1766 struct finish_command_fsm
*sm
;
1768 sm
= XCNEW (struct finish_command_fsm
);
1769 thread_fsm_ctor (&sm
->thread_fsm
, &finish_command_fsm_ops
, cmd_interp
);
1774 /* Implementation of the 'should_stop' FSM method for the finish
1775 commands. Detects whether the thread stepped out of the function
1776 successfully, and if so, captures the function's return value and
1777 marks the FSM finished. */
1780 finish_command_fsm_should_stop (struct thread_fsm
*self
,
1781 struct thread_info
*tp
)
1783 struct finish_command_fsm
*f
= (struct finish_command_fsm
*) self
;
1784 struct return_value_info
*rv
= &f
->return_value
;
1786 if (f
->function
!= NULL
1787 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1788 f
->breakpoint
) != NULL
)
1791 thread_fsm_set_finished (self
);
1793 rv
->type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (f
->function
));
1794 if (rv
->type
== NULL
)
1795 internal_error (__FILE__
, __LINE__
,
1796 _("finish_command: function has no target type"));
1798 if (TYPE_CODE (rv
->type
) != TYPE_CODE_VOID
)
1802 func
= read_var_value (f
->function
, NULL
, get_current_frame ());
1803 rv
->value
= get_return_value (func
, rv
->type
);
1804 if (rv
->value
!= NULL
)
1805 rv
->value_history_index
= record_latest_value (rv
->value
);
1808 else if (tp
->control
.stop_step
)
1810 /* Finishing from an inline frame, or reverse finishing. In
1811 either case, there's no way to retrieve the return value. */
1812 thread_fsm_set_finished (self
);
1818 /* Implementation of the 'clean_up' FSM method for the finish
1822 finish_command_fsm_clean_up (struct thread_fsm
*self
,
1823 struct thread_info
*thread
)
1825 struct finish_command_fsm
*f
= (struct finish_command_fsm
*) self
;
1827 if (f
->breakpoint
!= NULL
)
1829 delete_breakpoint (f
->breakpoint
);
1830 f
->breakpoint
= NULL
;
1832 delete_longjmp_breakpoint (thread
->global_num
);
1835 /* Implementation of the 'return_value' FSM method for the finish
1838 static struct return_value_info
*
1839 finish_command_fsm_return_value (struct thread_fsm
*self
)
1841 struct finish_command_fsm
*f
= (struct finish_command_fsm
*) self
;
1843 return &f
->return_value
;
1846 /* Implementation of the 'async_reply_reason' FSM method for the
1849 static enum async_reply_reason
1850 finish_command_fsm_async_reply_reason (struct thread_fsm
*self
)
1852 if (execution_direction
== EXEC_REVERSE
)
1853 return EXEC_ASYNC_END_STEPPING_RANGE
;
1855 return EXEC_ASYNC_FUNCTION_FINISHED
;
1858 /* finish_backward -- helper function for finish_command. */
1861 finish_backward (struct finish_command_fsm
*sm
)
1863 struct symtab_and_line sal
;
1864 struct thread_info
*tp
= inferior_thread ();
1866 CORE_ADDR func_addr
;
1868 pc
= get_frame_pc (get_current_frame ());
1870 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1871 error (_("Cannot find bounds of current function"));
1873 sal
= find_pc_line (func_addr
, 0);
1875 tp
->control
.proceed_to_finish
= 1;
1876 /* Special case: if we're sitting at the function entry point,
1877 then all we need to do is take a reverse singlestep. We
1878 don't need to set a breakpoint, and indeed it would do us
1881 Note that this can only happen at frame #0, since there's
1882 no way that a function up the stack can have a return address
1883 that's equal to its entry point. */
1887 struct frame_info
*frame
= get_selected_frame (NULL
);
1888 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1889 struct symtab_and_line sr_sal
;
1891 /* Set a step-resume at the function's entry point. Once that's
1892 hit, we'll do one more step backwards. */
1895 sr_sal
.pspace
= get_frame_program_space (frame
);
1896 insert_step_resume_breakpoint_at_sal (gdbarch
,
1897 sr_sal
, null_frame_id
);
1899 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1903 /* We're almost there -- we just need to back up by one more
1905 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1906 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1910 /* finish_forward -- helper function for finish_command. FRAME is the
1911 frame that called the function we're about to step out of. */
1914 finish_forward (struct finish_command_fsm
*sm
, struct frame_info
*frame
)
1916 struct frame_id frame_id
= get_frame_id (frame
);
1917 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1918 struct symtab_and_line sal
;
1919 struct thread_info
*tp
= inferior_thread ();
1921 sal
= find_pc_line (get_frame_pc (frame
), 0);
1922 sal
.pc
= get_frame_pc (frame
);
1924 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1925 get_stack_frame_id (frame
),
1928 /* set_momentary_breakpoint invalidates FRAME. */
1931 set_longjmp_breakpoint (tp
, frame_id
);
1933 /* We want to print return value, please... */
1934 tp
->control
.proceed_to_finish
= 1;
1936 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1939 /* Skip frames for "finish". */
1941 static struct frame_info
*
1942 skip_finish_frames (struct frame_info
*frame
)
1944 struct frame_info
*start
;
1950 frame
= skip_tailcall_frames (frame
);
1954 frame
= skip_unwritable_frames (frame
);
1958 while (start
!= frame
);
1963 /* "finish": Set a temporary breakpoint at the place the selected
1964 frame will return to, then continue. */
1967 finish_command (char *arg
, int from_tty
)
1969 struct frame_info
*frame
;
1971 struct cleanup
*args_chain
;
1972 struct finish_command_fsm
*sm
;
1973 struct thread_info
*tp
;
1976 ensure_not_tfind_mode ();
1977 ensure_valid_thread ();
1978 ensure_not_running ();
1980 /* Find out whether we must run in the background. */
1981 arg
= strip_bg_char (arg
, &async_exec
);
1982 args_chain
= make_cleanup (xfree
, arg
);
1984 prepare_execution_command (¤t_target
, async_exec
);
1987 error (_("The \"finish\" command does not take any arguments."));
1989 /* Done with ARGS. */
1990 do_cleanups (args_chain
);
1992 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1994 error (_("\"finish\" not meaningful in the outermost frame."));
1996 clear_proceed_status (0);
1998 tp
= inferior_thread ();
2000 sm
= new_finish_command_fsm (command_interp ());
2002 tp
->thread_fsm
= &sm
->thread_fsm
;
2004 /* Finishing from an inline frame is completely different. We don't
2005 try to show the "return value" - no way to locate it. */
2006 if (get_frame_type (get_selected_frame (_("No selected frame.")))
2009 /* Claim we are stepping in the calling frame. An empty step
2010 range means that we will stop once we aren't in a function
2011 called by that frame. We don't use the magic "1" value for
2012 step_range_end, because then infrun will think this is nexti,
2013 and not step over the rest of this inlined function call. */
2014 struct symtab_and_line empty_sal
;
2016 init_sal (&empty_sal
);
2017 set_step_info (frame
, empty_sal
);
2018 tp
->control
.step_range_start
= get_frame_pc (frame
);
2019 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
2020 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
2022 /* Print info on the selected frame, including level number but not
2026 printf_filtered (_("Run till exit from "));
2027 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
2030 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2034 /* Find the function we will return from. */
2036 sm
->function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
2038 /* Print info on the selected frame, including level number but not
2042 if (execution_direction
== EXEC_REVERSE
)
2043 printf_filtered (_("Run back to call of "));
2046 if (sm
->function
!= NULL
&& TYPE_NO_RETURN (sm
->function
->type
)
2047 && !query (_("warning: Function %s does not return normally.\n"
2048 "Try to finish anyway? "),
2049 SYMBOL_PRINT_NAME (sm
->function
)))
2050 error (_("Not confirmed."));
2051 printf_filtered (_("Run till exit from "));
2054 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
2057 if (execution_direction
== EXEC_REVERSE
)
2058 finish_backward (sm
);
2061 frame
= skip_finish_frames (frame
);
2064 error (_("Cannot find the caller frame."));
2066 finish_forward (sm
, frame
);
2072 program_info (char *args
, int from_tty
)
2076 struct thread_info
*tp
;
2079 if (!target_has_execution
)
2081 printf_filtered (_("The program being debugged is not being run.\n"));
2086 ptid
= inferior_ptid
;
2089 struct target_waitstatus ws
;
2091 get_last_target_status (&ptid
, &ws
);
2094 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
2095 error (_("Invalid selected thread."));
2096 else if (is_running (ptid
))
2097 error (_("Selected thread is running."));
2099 tp
= find_thread_ptid (ptid
);
2100 bs
= tp
->control
.stop_bpstat
;
2101 stat
= bpstat_num (&bs
, &num
);
2103 target_files_info ();
2104 printf_filtered (_("Program stopped at %s.\n"),
2105 paddress (target_gdbarch (), stop_pc
));
2106 if (tp
->control
.stop_step
)
2107 printf_filtered (_("It stopped after being stepped.\n"));
2110 /* There may be several breakpoints in the same place, so this
2111 isn't as strange as it seems. */
2116 printf_filtered (_("It stopped at a breakpoint "
2117 "that has since been deleted.\n"));
2120 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
2121 stat
= bpstat_num (&bs
, &num
);
2124 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
2126 printf_filtered (_("It stopped with signal %s, %s.\n"),
2127 gdb_signal_to_name (tp
->suspend
.stop_signal
),
2128 gdb_signal_to_string (tp
->suspend
.stop_signal
));
2133 printf_filtered (_("Type \"info stack\" or \"info "
2134 "registers\" for more information.\n"));
2139 environment_info (char *var
, int from_tty
)
2143 char *val
= get_in_environ (current_inferior ()->environment
, var
);
2147 puts_filtered (var
);
2148 puts_filtered (" = ");
2149 puts_filtered (val
);
2150 puts_filtered ("\n");
2154 puts_filtered ("Environment variable \"");
2155 puts_filtered (var
);
2156 puts_filtered ("\" not defined.\n");
2161 char **vector
= environ_vector (current_inferior ()->environment
);
2165 puts_filtered (*vector
++);
2166 puts_filtered ("\n");
2172 set_environment_command (char *arg
, int from_tty
)
2174 char *p
, *val
, *var
;
2178 error_no_arg (_("environment variable and value"));
2180 /* Find seperation between variable name and value. */
2181 p
= (char *) strchr (arg
, '=');
2182 val
= (char *) strchr (arg
, ' ');
2184 if (p
!= 0 && val
!= 0)
2186 /* We have both a space and an equals. If the space is before the
2187 equals, walk forward over the spaces til we see a nonspace
2188 (possibly the equals). */
2193 /* Now if the = is after the char following the spaces,
2194 take the char following the spaces. */
2198 else if (val
!= 0 && p
== 0)
2202 error_no_arg (_("environment variable to set"));
2204 if (p
== 0 || p
[1] == 0)
2208 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2212 /* Not setting variable value to null. */
2214 while (*val
== ' ' || *val
== '\t')
2218 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2221 var
= savestring (arg
, p
- arg
);
2224 printf_filtered (_("Setting environment variable "
2225 "\"%s\" to null value.\n"),
2227 set_in_environ (current_inferior ()->environment
, var
, "");
2230 set_in_environ (current_inferior ()->environment
, var
, val
);
2235 unset_environment_command (char *var
, int from_tty
)
2239 /* If there is no argument, delete all environment variables.
2240 Ask for confirmation if reading from the terminal. */
2241 if (!from_tty
|| query (_("Delete all environment variables? ")))
2243 free_environ (current_inferior ()->environment
);
2244 current_inferior ()->environment
= make_environ ();
2248 unset_in_environ (current_inferior ()->environment
, var
);
2251 /* Handle the execution path (PATH variable). */
2253 static const char path_var_name
[] = "PATH";
2256 path_info (char *args
, int from_tty
)
2258 puts_filtered ("Executable and object file path: ");
2259 puts_filtered (get_in_environ (current_inferior ()->environment
,
2261 puts_filtered ("\n");
2264 /* Add zero or more directories to the front of the execution path. */
2267 path_command (char *dirname
, int from_tty
)
2273 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
2274 /* Can be null if path is not set. */
2277 exec_path
= xstrdup (env
);
2278 mod_path (dirname
, &exec_path
);
2279 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
2282 path_info ((char *) NULL
, from_tty
);
2286 /* Print out the register NAME with value VAL, to FILE, in the default
2290 default_print_one_register_info (struct ui_file
*file
,
2294 struct type
*regtype
= value_type (val
);
2295 int print_raw_format
;
2297 fputs_filtered (name
, file
);
2298 print_spaces_filtered (15 - strlen (name
), file
);
2300 print_raw_format
= (value_entirely_available (val
)
2301 && !value_optimized_out (val
));
2303 /* If virtual format is floating, print it that way, and in raw
2305 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
2306 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2308 struct value_print_options opts
;
2309 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2310 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (regtype
));
2312 get_user_print_options (&opts
);
2316 value_embedded_offset (val
), 0,
2317 file
, 0, val
, &opts
, current_language
);
2319 if (print_raw_format
)
2321 fprintf_filtered (file
, "\t(raw ");
2322 print_hex_chars (file
, valaddr
, TYPE_LENGTH (regtype
), byte_order
);
2323 fprintf_filtered (file
, ")");
2328 struct value_print_options opts
;
2330 /* Print the register in hex. */
2331 get_formatted_print_options (&opts
, 'x');
2334 value_embedded_offset (val
), 0,
2335 file
, 0, val
, &opts
, current_language
);
2336 /* If not a vector register, print it also according to its
2338 if (print_raw_format
&& TYPE_VECTOR (regtype
) == 0)
2340 get_user_print_options (&opts
);
2342 fprintf_filtered (file
, "\t");
2344 value_embedded_offset (val
), 0,
2345 file
, 0, val
, &opts
, current_language
);
2349 fprintf_filtered (file
, "\n");
2352 /* Print out the machine register regnum. If regnum is -1, print all
2353 registers (print_all == 1) or all non-float and non-vector
2354 registers (print_all == 0).
2356 For most machines, having all_registers_info() print the
2357 register(s) one per line is good enough. If a different format is
2358 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2359 regs), or there is an existing convention for showing all the
2360 registers, define the architecture method PRINT_REGISTERS_INFO to
2361 provide that format. */
2364 default_print_registers_info (struct gdbarch
*gdbarch
,
2365 struct ui_file
*file
,
2366 struct frame_info
*frame
,
2367 int regnum
, int print_all
)
2370 const int numregs
= gdbarch_num_regs (gdbarch
)
2371 + gdbarch_num_pseudo_regs (gdbarch
);
2373 for (i
= 0; i
< numregs
; i
++)
2375 /* Decide between printing all regs, non-float / vector regs, or
2381 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2386 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2396 /* If the register name is empty, it is undefined for this
2397 processor, so don't display anything. */
2398 if (gdbarch_register_name (gdbarch
, i
) == NULL
2399 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2402 default_print_one_register_info (file
,
2403 gdbarch_register_name (gdbarch
, i
),
2404 value_of_register (i
, frame
));
2409 registers_info (char *addr_exp
, int fpregs
)
2411 struct frame_info
*frame
;
2412 struct gdbarch
*gdbarch
;
2414 if (!target_has_registers
)
2415 error (_("The program has no registers now."));
2416 frame
= get_selected_frame (NULL
);
2417 gdbarch
= get_frame_arch (frame
);
2421 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2426 while (*addr_exp
!= '\0')
2431 /* Skip leading white space. */
2432 addr_exp
= skip_spaces (addr_exp
);
2434 /* Discard any leading ``$''. Check that there is something
2435 resembling a register following it. */
2436 if (addr_exp
[0] == '$')
2438 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2439 error (_("Missing register name"));
2441 /* Find the start/end of this register name/num/group. */
2443 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2447 /* Figure out what we've found and display it. */
2449 /* A register name? */
2451 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2455 /* User registers lie completely outside of the range of
2456 normal registers. Catch them early so that the target
2458 if (regnum
>= gdbarch_num_regs (gdbarch
)
2459 + gdbarch_num_pseudo_regs (gdbarch
))
2461 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2462 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2465 /* Print in the same fashion
2466 gdbarch_print_registers_info's default
2467 implementation prints. */
2468 default_print_one_register_info (gdb_stdout
,
2473 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2474 frame
, regnum
, fpregs
);
2479 /* A register group? */
2481 struct reggroup
*group
;
2483 for (group
= reggroup_next (gdbarch
, NULL
);
2485 group
= reggroup_next (gdbarch
, group
))
2487 /* Don't bother with a length check. Should the user
2488 enter a short register group name, go with the first
2489 group that matches. */
2490 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2498 regnum
< gdbarch_num_regs (gdbarch
)
2499 + gdbarch_num_pseudo_regs (gdbarch
);
2502 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2503 gdbarch_print_registers_info (gdbarch
,
2511 /* Nothing matched. */
2512 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2517 all_registers_info (char *addr_exp
, int from_tty
)
2519 registers_info (addr_exp
, 1);
2523 nofp_registers_info (char *addr_exp
, int from_tty
)
2525 registers_info (addr_exp
, 0);
2529 print_vector_info (struct ui_file
*file
,
2530 struct frame_info
*frame
, const char *args
)
2532 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2534 if (gdbarch_print_vector_info_p (gdbarch
))
2535 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2539 int printed_something
= 0;
2542 regnum
< gdbarch_num_regs (gdbarch
)
2543 + gdbarch_num_pseudo_regs (gdbarch
);
2546 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2548 printed_something
= 1;
2549 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2552 if (!printed_something
)
2553 fprintf_filtered (file
, "No vector information\n");
2558 vector_info (char *args
, int from_tty
)
2560 if (!target_has_registers
)
2561 error (_("The program has no registers now."));
2563 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2566 /* Kill the inferior process. Make us have no inferior. */
2569 kill_command (char *arg
, int from_tty
)
2571 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2572 It should be a distinct flag that indicates that a target is active, cuz
2573 some targets don't have processes! */
2575 if (ptid_equal (inferior_ptid
, null_ptid
))
2576 error (_("The program is not being run."));
2577 if (!query (_("Kill the program being debugged? ")))
2578 error (_("Not confirmed."));
2581 /* If we still have other inferiors to debug, then don't mess with
2582 with their threads. */
2583 if (!have_inferiors ())
2585 init_thread_list (); /* Destroy thread info. */
2587 /* Killing off the inferior can leave us with a core file. If
2588 so, print the state we are left in. */
2589 if (target_has_stack
)
2591 printf_filtered (_("In %s,\n"), target_longname
);
2592 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2595 bfd_cache_close_all ();
2598 /* Used in `attach&' command. ARG is a point to an integer
2599 representing a process id. Proceed threads of this process iff
2600 they stopped due to debugger request, and when they did, they
2601 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
2602 that have been explicitly been told to stop. */
2605 proceed_after_attach_callback (struct thread_info
*thread
,
2608 int pid
= * (int *) arg
;
2610 if (ptid_get_pid (thread
->ptid
) == pid
2611 && !is_exited (thread
->ptid
)
2612 && !is_executing (thread
->ptid
)
2613 && !thread
->stop_requested
2614 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2616 switch_to_thread (thread
->ptid
);
2617 clear_proceed_status (0);
2618 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2625 proceed_after_attach (int pid
)
2627 /* Don't error out if the current thread is running, because
2628 there may be other stopped threads. */
2629 struct cleanup
*old_chain
;
2631 /* Backup current thread and selected frame. */
2632 old_chain
= make_cleanup_restore_current_thread ();
2634 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2636 /* Restore selected ptid. */
2637 do_cleanups (old_chain
);
2640 /* See inferior.h. */
2643 setup_inferior (int from_tty
)
2645 struct inferior
*inferior
;
2647 inferior
= current_inferior ();
2648 inferior
->needs_setup
= 0;
2650 /* If no exec file is yet known, try to determine it from the
2652 if (get_exec_file (0) == NULL
)
2653 exec_file_locate_attach (ptid_get_pid (inferior_ptid
), 1, from_tty
);
2656 reopen_exec_file ();
2660 /* Take any necessary post-attaching actions for this platform. */
2661 target_post_attach (ptid_get_pid (inferior_ptid
));
2663 post_create_inferior (¤t_target
, from_tty
);
2666 /* What to do after the first program stops after attaching. */
2667 enum attach_post_wait_mode
2669 /* Do nothing. Leaves threads as they are. */
2670 ATTACH_POST_WAIT_NOTHING
,
2672 /* Re-resume threads that are marked running. */
2673 ATTACH_POST_WAIT_RESUME
,
2675 /* Stop all threads. */
2676 ATTACH_POST_WAIT_STOP
,
2679 /* Called after we've attached to a process and we've seen it stop for
2680 the first time. If ASYNC_EXEC is true, re-resume threads that
2681 should be running. Else if ATTACH, */
2684 attach_post_wait (const char *args
, int from_tty
, enum attach_post_wait_mode mode
)
2686 struct inferior
*inferior
;
2688 inferior
= current_inferior ();
2689 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2691 if (inferior
->needs_setup
)
2692 setup_inferior (from_tty
);
2694 if (mode
== ATTACH_POST_WAIT_RESUME
)
2696 /* The user requested an `attach&', so be sure to leave threads
2697 that didn't get a signal running. */
2699 /* Immediatelly resume all suspended threads of this inferior,
2700 and this inferior only. This should have no effect on
2701 already running threads. If a thread has been stopped with a
2702 signal, leave it be. */
2704 proceed_after_attach (inferior
->pid
);
2707 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2709 clear_proceed_status (0);
2710 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2714 else if (mode
== ATTACH_POST_WAIT_STOP
)
2716 /* The user requested a plain `attach', so be sure to leave
2717 the inferior stopped. */
2719 /* At least the current thread is already stopped. */
2721 /* In all-stop, by definition, all threads have to be already
2722 stopped at this point. In non-stop, however, although the
2723 selected thread is stopped, others may still be executing.
2724 Be sure to explicitly stop all threads of the process. This
2725 should have no effect on already stopped threads. */
2727 target_stop (pid_to_ptid (inferior
->pid
));
2728 else if (target_is_non_stop_p ())
2730 struct thread_info
*thread
;
2731 struct thread_info
*lowest
= inferior_thread ();
2732 int pid
= current_inferior ()->pid
;
2734 stop_all_threads ();
2736 /* It's not defined which thread will report the attach
2737 stop. For consistency, always select the thread with
2738 lowest GDB number, which should be the main thread, if it
2740 ALL_NON_EXITED_THREADS (thread
)
2742 if (ptid_get_pid (thread
->ptid
) == pid
)
2744 if (thread
->inf
->num
< lowest
->inf
->num
2745 || thread
->per_inf_num
< lowest
->per_inf_num
)
2750 switch_to_thread (lowest
->ptid
);
2753 /* Tell the user/frontend where we're stopped. */
2755 if (deprecated_attach_hook
)
2756 deprecated_attach_hook ();
2760 struct attach_command_continuation_args
2764 enum attach_post_wait_mode mode
;
2768 attach_command_continuation (void *args
, int err
)
2770 struct attach_command_continuation_args
*a
2771 = (struct attach_command_continuation_args
*) args
;
2776 attach_post_wait (a
->args
, a
->from_tty
, a
->mode
);
2780 attach_command_continuation_free_args (void *args
)
2782 struct attach_command_continuation_args
*a
2783 = (struct attach_command_continuation_args
*) args
;
2789 /* "attach" command entry point. Takes a program started up outside
2790 of gdb and ``attaches'' to it. This stops it cold in its tracks
2791 and allows us to start debugging it. */
2794 attach_command (char *args
, int from_tty
)
2797 struct cleanup
*args_chain
;
2798 struct target_ops
*attach_target
;
2799 struct inferior
*inferior
= current_inferior ();
2800 enum attach_post_wait_mode mode
;
2802 dont_repeat (); /* Not for the faint of heart */
2804 if (gdbarch_has_global_solist (target_gdbarch ()))
2805 /* Don't complain if all processes share the same symbol
2808 else if (target_has_execution
)
2810 if (query (_("A program is being debugged already. Kill it? ")))
2813 error (_("Not killed."));
2816 /* Clean up any leftovers from other runs. Some other things from
2817 this function should probably be moved into target_pre_inferior. */
2818 target_pre_inferior (from_tty
);
2820 args
= strip_bg_char (args
, &async_exec
);
2821 args_chain
= make_cleanup (xfree
, args
);
2823 attach_target
= find_attach_target ();
2825 prepare_execution_command (attach_target
, async_exec
);
2827 if (non_stop
&& !attach_target
->to_supports_non_stop (attach_target
))
2828 error (_("Cannot attach to this target in non-stop mode"));
2830 attach_target
->to_attach (attach_target
, args
, from_tty
);
2831 /* to_attach should push the target, so after this point we
2832 shouldn't refer to attach_target again. */
2833 attach_target
= NULL
;
2835 /* Set up the "saved terminal modes" of the inferior
2836 based on what modes we are starting it with. */
2837 target_terminal_init ();
2839 /* Install inferior's terminal modes. This may look like a no-op,
2840 as we've just saved them above, however, this does more than
2841 restore terminal settings:
2843 - installs a SIGINT handler that forwards SIGINT to the inferior.
2844 Otherwise a Ctrl-C pressed just while waiting for the initial
2845 stop would end up as a spurious Quit.
2847 - removes stdin from the event loop, which we need if attaching
2848 in the foreground, otherwise on targets that report an initial
2849 stop on attach (which are most) we'd process input/commands
2850 while we're in the event loop waiting for that stop. That is,
2851 before the attach continuation runs and the command is really
2853 target_terminal_inferior ();
2855 /* Set up execution context to know that we should return from
2856 wait_for_inferior as soon as the target reports a stop. */
2857 init_wait_for_inferior ();
2858 clear_proceed_status (0);
2860 inferior
->needs_setup
= 1;
2862 if (target_is_non_stop_p ())
2864 /* If we find that the current thread isn't stopped, explicitly
2865 do so now, because we're going to install breakpoints and
2869 /* The user requested an `attach&'; stop just one thread. */
2870 target_stop (inferior_ptid
);
2872 /* The user requested an `attach', so stop all threads of this
2874 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2877 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2879 /* Some system don't generate traps when attaching to inferior.
2880 E.g. Mach 3 or GNU hurd. */
2881 if (!target_attach_no_wait
)
2883 struct attach_command_continuation_args
*a
;
2885 /* Careful here. See comments in inferior.h. Basically some
2886 OSes don't ignore SIGSTOPs on continue requests anymore. We
2887 need a way for handle_inferior_event to reset the stop_signal
2888 variable after an attach, and this is what
2889 STOP_QUIETLY_NO_SIGSTOP is for. */
2890 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2892 /* Wait for stop. */
2893 a
= XNEW (struct attach_command_continuation_args
);
2894 a
->args
= xstrdup (args
);
2895 a
->from_tty
= from_tty
;
2897 add_inferior_continuation (attach_command_continuation
, a
,
2898 attach_command_continuation_free_args
);
2899 /* Done with ARGS. */
2900 do_cleanups (args_chain
);
2902 if (!target_is_async_p ())
2903 mark_infrun_async_event_handler ();
2907 /* Done with ARGS. */
2908 do_cleanups (args_chain
);
2910 attach_post_wait (args
, from_tty
, mode
);
2913 /* We had just found out that the target was already attached to an
2914 inferior. PTID points at a thread of this new inferior, that is
2915 the most likely to be stopped right now, but not necessarily so.
2916 The new inferior is assumed to be already added to the inferior
2917 list at this point. If LEAVE_RUNNING, then leave the threads of
2918 this inferior running, except those we've explicitly seen reported
2922 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2924 struct cleanup
* old_chain
;
2925 enum attach_post_wait_mode mode
;
2927 old_chain
= make_cleanup (null_cleanup
, NULL
);
2929 mode
= leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2931 if (!ptid_equal (inferior_ptid
, null_ptid
))
2932 make_cleanup_restore_current_thread ();
2934 /* Avoid reading registers -- we haven't fetched the target
2936 switch_to_thread_no_regs (find_thread_ptid (ptid
));
2938 /* When we "notice" a new inferior we need to do all the things we
2939 would normally do if we had just attached to it. */
2941 if (is_executing (inferior_ptid
))
2943 struct attach_command_continuation_args
*a
;
2944 struct inferior
*inferior
= current_inferior ();
2946 /* We're going to install breakpoints, and poke at memory,
2947 ensure that the inferior is stopped for a moment while we do
2949 target_stop (inferior_ptid
);
2951 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2953 /* Wait for stop before proceeding. */
2954 a
= XNEW (struct attach_command_continuation_args
);
2955 a
->args
= xstrdup ("");
2956 a
->from_tty
= from_tty
;
2958 add_inferior_continuation (attach_command_continuation
, a
,
2959 attach_command_continuation_free_args
);
2961 do_cleanups (old_chain
);
2965 attach_post_wait ("" /* args */, from_tty
, mode
);
2967 do_cleanups (old_chain
);
2972 * takes a program previously attached to and detaches it.
2973 * The program resumes execution and will no longer stop
2974 * on signals, etc. We better not have left any breakpoints
2975 * in the program or it'll die when it hits one. For this
2976 * to work, it may be necessary for the process to have been
2977 * previously attached. It *might* work if the program was
2978 * started via the normal ptrace (PTRACE_TRACEME).
2982 detach_command (char *args
, int from_tty
)
2984 dont_repeat (); /* Not for the faint of heart. */
2986 if (ptid_equal (inferior_ptid
, null_ptid
))
2987 error (_("The program is not being run."));
2989 query_if_trace_running (from_tty
);
2991 disconnect_tracing ();
2993 target_detach (args
, from_tty
);
2995 /* The current inferior process was just detached successfully. Get
2996 rid of breakpoints that no longer make sense. Note we don't do
2997 this within target_detach because that is also used when
2998 following child forks, and in that case we will want to transfer
2999 breakpoints to the child, not delete them. */
3000 breakpoint_init_inferior (inf_exited
);
3002 /* If the solist is global across inferiors, don't clear it when we
3003 detach from a single inferior. */
3004 if (!gdbarch_has_global_solist (target_gdbarch ()))
3005 no_shared_libraries (NULL
, from_tty
);
3007 /* If we still have inferiors to debug, then don't mess with their
3009 if (!have_inferiors ())
3010 init_thread_list ();
3012 if (deprecated_detach_hook
)
3013 deprecated_detach_hook ();
3016 /* Disconnect from the current target without resuming it (leaving it
3017 waiting for a debugger).
3019 We'd better not have left any breakpoints in the program or the
3020 next debugger will get confused. Currently only supported for some
3021 remote targets, since the normal attach mechanisms don't work on
3022 stopped processes on some native platforms (e.g. GNU/Linux). */
3025 disconnect_command (char *args
, int from_tty
)
3027 dont_repeat (); /* Not for the faint of heart. */
3028 query_if_trace_running (from_tty
);
3029 disconnect_tracing ();
3030 target_disconnect (args
, from_tty
);
3031 no_shared_libraries (NULL
, from_tty
);
3032 init_thread_list ();
3033 if (deprecated_detach_hook
)
3034 deprecated_detach_hook ();
3038 interrupt_target_1 (int all_threads
)
3043 ptid
= minus_one_ptid
;
3045 ptid
= inferior_ptid
;
3050 target_interrupt (ptid
);
3052 /* Tag the thread as having been explicitly requested to stop, so
3053 other parts of gdb know not to resume this thread automatically,
3054 if it was stopped due to an internal event. Limit this to
3055 non-stop mode, as when debugging a multi-threaded application in
3056 all-stop mode, we will only get one stop event --- it's undefined
3057 which thread will report the event. */
3059 set_stop_requested (ptid
, 1);
3063 Stop the execution of the target while running in async mode, in
3064 the background. In all-stop, stop the whole process. In non-stop
3065 mode, stop the current thread only by default, or stop all threads
3066 if the `-a' switch is used. */
3069 interrupt_command (char *args
, int from_tty
)
3071 if (target_can_async_p ())
3073 int all_threads
= 0;
3075 dont_repeat (); /* Not for the faint of heart. */
3078 && startswith (args
, "-a"))
3081 if (!non_stop
&& all_threads
)
3082 error (_("-a is meaningless in all-stop mode."));
3084 interrupt_target_1 (all_threads
);
3088 /* See inferior.h. */
3091 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
3092 struct frame_info
*frame
, const char *args
)
3095 int printed_something
= 0;
3098 regnum
< gdbarch_num_regs (gdbarch
)
3099 + gdbarch_num_pseudo_regs (gdbarch
);
3102 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
3104 printed_something
= 1;
3105 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
3108 if (!printed_something
)
3109 fprintf_filtered (file
, "No floating-point info "
3110 "available for this processor.\n");
3114 float_info (char *args
, int from_tty
)
3116 struct frame_info
*frame
;
3118 if (!target_has_registers
)
3119 error (_("The program has no registers now."));
3121 frame
= get_selected_frame (NULL
);
3122 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
3126 unset_command (char *args
, int from_tty
)
3128 printf_filtered (_("\"unset\" must be followed by the "
3129 "name of an unset subcommand.\n"));
3130 help_list (unsetlist
, "unset ", all_commands
, gdb_stdout
);
3133 /* Implement `info proc' family of commands. */
3136 info_proc_cmd_1 (char *args
, enum info_proc_what what
, int from_tty
)
3138 struct gdbarch
*gdbarch
= get_current_arch ();
3140 if (!target_info_proc (args
, what
))
3142 if (gdbarch_info_proc_p (gdbarch
))
3143 gdbarch_info_proc (gdbarch
, args
, what
);
3145 error (_("Not supported on this target."));
3149 /* Implement `info proc' when given without any futher parameters. */
3152 info_proc_cmd (char *args
, int from_tty
)
3154 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
3157 /* Implement `info proc mappings'. */
3160 info_proc_cmd_mappings (char *args
, int from_tty
)
3162 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
3165 /* Implement `info proc stat'. */
3168 info_proc_cmd_stat (char *args
, int from_tty
)
3170 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
3173 /* Implement `info proc status'. */
3176 info_proc_cmd_status (char *args
, int from_tty
)
3178 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
3181 /* Implement `info proc cwd'. */
3184 info_proc_cmd_cwd (char *args
, int from_tty
)
3186 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
3189 /* Implement `info proc cmdline'. */
3192 info_proc_cmd_cmdline (char *args
, int from_tty
)
3194 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
3197 /* Implement `info proc exe'. */
3200 info_proc_cmd_exe (char *args
, int from_tty
)
3202 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
3205 /* Implement `info proc all'. */
3208 info_proc_cmd_all (char *args
, int from_tty
)
3210 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
3214 _initialize_infcmd (void)
3216 static struct cmd_list_element
*info_proc_cmdlist
;
3217 struct cmd_list_element
*c
= NULL
;
3218 const char *cmd_name
;
3220 /* Add the filename of the terminal connected to inferior I/O. */
3221 add_setshow_optional_filename_cmd ("inferior-tty", class_run
,
3222 &inferior_io_terminal_scratch
, _("\
3223 Set terminal for future runs of program being debugged."), _("\
3224 Show terminal for future runs of program being debugged."), _("\
3225 Usage: set inferior-tty [TTY]\n\n\
3226 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3228 set_inferior_tty_command
,
3229 show_inferior_tty_command
,
3230 &setlist
, &showlist
);
3231 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
3234 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3235 &inferior_args_scratch
, _("\
3236 Set argument list to give program being debugged when it is started."), _("\
3237 Show argument list to give program being debugged when it is started."), _("\
3238 Follow this command with any number of args, to be passed to the program."),
3241 &setlist
, &showlist
);
3242 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3243 gdb_assert (c
!= NULL
);
3244 set_cmd_completer (c
, filename_completer
);
3246 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3247 The environment to give the program, or one variable's value.\n\
3248 With an argument VAR, prints the value of environment variable VAR to\n\
3249 give the program being debugged. With no arguments, prints the entire\n\
3250 environment to be given to the program."), &showlist
);
3251 set_cmd_completer (c
, noop_completer
);
3253 add_prefix_cmd ("unset", no_class
, unset_command
,
3254 _("Complement to certain \"set\" commands."),
3255 &unsetlist
, "unset ", 0, &cmdlist
);
3257 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3258 Cancel environment variable VAR for the program.\n\
3259 This does not affect the program until the next \"run\" command."),
3261 set_cmd_completer (c
, noop_completer
);
3263 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3264 Set environment variable value to give the program.\n\
3265 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3266 VALUES of environment variables are uninterpreted strings.\n\
3267 This does not affect the program until the next \"run\" command."),
3269 set_cmd_completer (c
, noop_completer
);
3271 c
= add_com ("path", class_files
, path_command
, _("\
3272 Add directory DIR(s) to beginning of search path for object files.\n\
3273 $cwd in the path means the current working directory.\n\
3274 This path is equivalent to the $PATH shell variable. It is a list of\n\
3275 directories, separated by colons. These directories are searched to find\n\
3276 fully linked executable files and separately compiled object files as \
3278 set_cmd_completer (c
, filename_completer
);
3280 c
= add_cmd ("paths", no_class
, path_info
, _("\
3281 Current search path for finding object files.\n\
3282 $cwd in the path means the current working directory.\n\
3283 This path is equivalent to the $PATH shell variable. It is a list of\n\
3284 directories, separated by colons. These directories are searched to find\n\
3285 fully linked executable files and separately compiled object files as \
3288 set_cmd_completer (c
, noop_completer
);
3290 add_prefix_cmd ("kill", class_run
, kill_command
,
3291 _("Kill execution of program being debugged."),
3292 &killlist
, "kill ", 0, &cmdlist
);
3294 add_com ("attach", class_run
, attach_command
, _("\
3295 Attach to a process or file outside of GDB.\n\
3296 This command attaches to another target, of the same type as your last\n\
3297 \"target\" command (\"info files\" will show your target stack).\n\
3298 The command may take as argument a process id or a device file.\n\
3299 For a process id, you must have permission to send the process a signal,\n\
3300 and it must have the same effective uid as the debugger.\n\
3301 When using \"attach\" with a process id, the debugger finds the\n\
3302 program running in the process, looking first in the current working\n\
3303 directory, or (if not found there) using the source file search path\n\
3304 (see the \"directory\" command). You can also use the \"file\" command\n\
3305 to specify the program, and to load its symbol table."));
3307 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3308 Detach a process or file previously attached.\n\
3309 If a process, it is no longer traced, and it continues its execution. If\n\
3310 you were debugging a file, the file is closed and gdb no longer accesses it."),
3311 &detachlist
, "detach ", 0, &cmdlist
);
3313 add_com ("disconnect", class_run
, disconnect_command
, _("\
3314 Disconnect from a target.\n\
3315 The target will wait for another debugger to connect. Not available for\n\
3318 c
= add_com ("signal", class_run
, signal_command
, _("\
3319 Continue program with the specified signal.\n\
3320 Usage: signal SIGNAL\n\
3321 The SIGNAL argument is processed the same as the handle command.\n\
3323 An argument of \"0\" means continue the program without sending it a signal.\n\
3324 This is useful in cases where the program stopped because of a signal,\n\
3325 and you want to resume the program while discarding the signal.\n\
3327 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3328 the current thread only."));
3329 set_cmd_completer (c
, signal_completer
);
3331 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3332 Queue a signal to be delivered to the current thread when it is resumed.\n\
3333 Usage: queue-signal SIGNAL\n\
3334 The SIGNAL argument is processed the same as the handle command.\n\
3335 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3337 An argument of \"0\" means remove any currently queued signal from\n\
3338 the current thread. This is useful in cases where the program stopped\n\
3339 because of a signal, and you want to resume it while discarding the signal.\n\
3341 In a multi-threaded program the signal is queued with, or discarded from,\n\
3342 the current thread only."));
3343 set_cmd_completer (c
, signal_completer
);
3345 add_com ("stepi", class_run
, stepi_command
, _("\
3346 Step one instruction exactly.\n\
3348 Argument N means step N times (or till program stops for another \
3350 add_com_alias ("si", "stepi", class_alias
, 0);
3352 add_com ("nexti", class_run
, nexti_command
, _("\
3353 Step one instruction, but proceed through subroutine calls.\n\
3355 Argument N means step N times (or till program stops for another \
3357 add_com_alias ("ni", "nexti", class_alias
, 0);
3359 add_com ("finish", class_run
, finish_command
, _("\
3360 Execute until selected stack frame returns.\n\
3362 Upon return, the value returned is printed and put in the value history."));
3363 add_com_alias ("fin", "finish", class_run
, 1);
3365 add_com ("next", class_run
, next_command
, _("\
3366 Step program, proceeding through subroutine calls.\n\
3368 Unlike \"step\", if the current source line calls a subroutine,\n\
3369 this command does not enter the subroutine, but instead steps over\n\
3370 the call, in effect treating it as a single source line."));
3371 add_com_alias ("n", "next", class_run
, 1);
3373 add_com ("step", class_run
, step_command
, _("\
3374 Step program until it reaches a different source line.\n\
3376 Argument N means step N times (or till program stops for another \
3378 add_com_alias ("s", "step", class_run
, 1);
3380 c
= add_com ("until", class_run
, until_command
, _("\
3381 Execute until the program reaches a source line greater than the current\n\
3382 or a specified location (same args as break command) within the current \
3384 set_cmd_completer (c
, location_completer
);
3385 add_com_alias ("u", "until", class_run
, 1);
3387 c
= add_com ("advance", class_run
, advance_command
, _("\
3388 Continue the program up to the given location (same form as args for break \
3390 Execution will also stop upon exit from the current stack frame."));
3391 set_cmd_completer (c
, location_completer
);
3393 c
= add_com ("jump", class_run
, jump_command
, _("\
3394 Continue program being debugged at specified line or address.\n\
3395 Usage: jump <location>\n\
3396 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3397 for an address to start at."));
3398 set_cmd_completer (c
, location_completer
);
3399 add_com_alias ("j", "jump", class_run
, 1);
3401 add_com ("continue", class_run
, continue_command
, _("\
3402 Continue program being debugged, after signal or breakpoint.\n\
3403 Usage: continue [N]\n\
3404 If proceeding from breakpoint, a number N may be used as an argument,\n\
3405 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3406 the breakpoint won't break until the Nth time it is reached).\n\
3408 If non-stop mode is enabled, continue only the current thread,\n\
3409 otherwise all the threads in the program are continued. To \n\
3410 continue all stopped threads in non-stop mode, use the -a option.\n\
3411 Specifying -a and an ignore count simultaneously is an error."));
3412 add_com_alias ("c", "cont", class_run
, 1);
3413 add_com_alias ("fg", "cont", class_run
, 1);
3415 c
= add_com ("run", class_run
, run_command
, _("\
3416 Start debugged program. You may specify arguments to give it.\n\
3417 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3418 Input and output redirection with \">\", \"<\", or \">>\" are also \
3420 With no arguments, uses arguments last specified (with \"run\" \
3421 or \"set args\").\n\
3422 To cancel previous arguments and run with no arguments,\n\
3423 use \"set args\" without arguments."));
3424 set_cmd_completer (c
, filename_completer
);
3425 add_com_alias ("r", "run", class_run
, 1);
3427 c
= add_com ("start", class_run
, start_command
, _("\
3428 Run the debugged program until the beginning of the main procedure.\n\
3429 You may specify arguments to give to your program, just as with the\n\
3430 \"run\" command."));
3431 set_cmd_completer (c
, filename_completer
);
3433 add_com ("interrupt", class_run
, interrupt_command
,
3434 _("Interrupt the execution of the debugged program.\n\
3435 If non-stop mode is enabled, interrupt only the current thread,\n\
3436 otherwise all the threads in the program are stopped. To \n\
3437 interrupt all running threads in non-stop mode, use the -a option."));
3439 c
= add_info ("registers", nofp_registers_info
, _("\
3440 List of integer registers and their contents, for selected stack frame.\n\
3441 Register name as argument means describe only that register."));
3442 add_info_alias ("r", "registers", 1);
3443 set_cmd_completer (c
, reg_or_group_completer
);
3445 c
= add_info ("all-registers", all_registers_info
, _("\
3446 List of all registers and their contents, for selected stack frame.\n\
3447 Register name as argument means describe only that register."));
3448 set_cmd_completer (c
, reg_or_group_completer
);
3450 add_info ("program", program_info
,
3451 _("Execution status of the program."));
3453 add_info ("float", float_info
,
3454 _("Print the status of the floating point unit\n"));
3456 add_info ("vector", vector_info
,
3457 _("Print the status of the vector unit\n"));
3459 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3461 Show /proc process information about any running process.\n\
3462 Specify any process id, or use the program being debugged by default."),
3463 &info_proc_cmdlist
, "info proc ",
3464 1/*allow-unknown*/, &infolist
);
3466 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3467 List of mapped memory regions."),
3468 &info_proc_cmdlist
);
3470 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3471 List process info from /proc/PID/stat."),
3472 &info_proc_cmdlist
);
3474 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3475 List process info from /proc/PID/status."),
3476 &info_proc_cmdlist
);
3478 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3479 List current working directory of the process."),
3480 &info_proc_cmdlist
);
3482 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3483 List command line arguments of the process."),
3484 &info_proc_cmdlist
);
3486 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3487 List absolute filename for executable of the process."),
3488 &info_proc_cmdlist
);
3490 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3491 List all available /proc info."),
3492 &info_proc_cmdlist
);