1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2020 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"
27 #include "gdbsupport/environ.h"
35 #include "completer.h"
38 #include "reggroups.h"
42 #include "observable.h"
43 #include "target-descriptions.h"
44 #include "user-regs.h"
45 #include "gdbthread.h"
47 #include "inline-frame.h"
48 #include "tracepoint.h"
50 #include "continuations.h"
52 #include "thread-fsm.h"
56 #include "gdbsupport/gdb_optional.h"
58 #include "cli/cli-style.h"
60 /* Local functions: */
62 static void until_next_command (int);
64 static void step_1 (int, int, const char *);
66 #define ERROR_NO_INFERIOR \
67 if (!target_has_execution) error (_("The program is not being run."));
69 /* Scratch area where string containing arguments to give to the
70 program will be stored by 'set args'. As soon as anything is
71 stored, notice_args_set will move it into per-inferior storage.
72 Arguments are separated by spaces. Empty string (pointer to '\0')
75 static char *inferior_args_scratch
;
77 /* Scratch area where the new cwd will be stored by 'set cwd'. */
79 static char *inferior_cwd_scratch
;
81 /* Scratch area where 'set inferior-tty' will store user-provided value.
82 We'll immediate copy it into per-inferior storage. */
84 static char *inferior_io_terminal_scratch
;
86 /* Pid of our debugged inferior, or 0 if no inferior now.
87 Since various parts of infrun.c test this to see whether there is a program
88 being debugged it should be nonzero (currently 3 is used) for remote
93 /* Nonzero if stopped due to completion of a stack dummy routine. */
95 enum stop_stack_kind stop_stack_dummy
;
97 /* Nonzero if stopped due to a random (unexpected) signal in inferior
100 int stopped_by_random_signal
;
103 /* Accessor routines. */
105 /* Set the io terminal for the current inferior. Ownership of
106 TERMINAL_NAME is not transferred. */
109 set_inferior_io_terminal (const char *terminal_name
)
111 xfree (current_inferior ()->terminal
);
113 if (terminal_name
!= NULL
&& *terminal_name
!= '\0')
114 current_inferior ()->terminal
= xstrdup (terminal_name
);
116 current_inferior ()->terminal
= NULL
;
120 get_inferior_io_terminal (void)
122 return current_inferior ()->terminal
;
126 set_inferior_tty_command (const char *args
, int from_tty
,
127 struct cmd_list_element
*c
)
129 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
130 Now route it to current inferior. */
131 set_inferior_io_terminal (inferior_io_terminal_scratch
);
135 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
136 struct cmd_list_element
*c
, const char *value
)
138 /* Note that we ignore the passed-in value in favor of computing it
140 const char *inferior_io_terminal
= get_inferior_io_terminal ();
142 if (inferior_io_terminal
== NULL
)
143 inferior_io_terminal
= "";
144 fprintf_filtered (gdb_stdout
,
145 _("Terminal for future runs of program being debugged "
146 "is \"%s\".\n"), inferior_io_terminal
);
150 get_inferior_args (void)
152 if (current_inferior ()->argc
!= 0)
156 n
= construct_inferior_arguments (current_inferior ()->argc
,
157 current_inferior ()->argv
);
158 set_inferior_args (n
);
162 if (current_inferior ()->args
== NULL
)
163 current_inferior ()->args
= xstrdup ("");
165 return current_inferior ()->args
;
168 /* Set the arguments for the current inferior. Ownership of
169 NEWARGS is not transferred. */
172 set_inferior_args (const char *newargs
)
174 xfree (current_inferior ()->args
);
175 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
176 current_inferior ()->argc
= 0;
177 current_inferior ()->argv
= 0;
181 set_inferior_args_vector (int argc
, char **argv
)
183 current_inferior ()->argc
= argc
;
184 current_inferior ()->argv
= argv
;
187 /* Notice when `set args' is run. */
190 set_args_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
192 /* CLI has assigned the user-provided value to inferior_args_scratch.
193 Now route it to current inferior. */
194 set_inferior_args (inferior_args_scratch
);
197 /* Notice when `show args' is run. */
200 show_args_command (struct ui_file
*file
, int from_tty
,
201 struct cmd_list_element
*c
, const char *value
)
203 /* Note that we ignore the passed-in value in favor of computing it
205 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
208 /* See gdbsupport/common-inferior.h. */
211 set_inferior_cwd (const char *cwd
)
213 struct inferior
*inf
= current_inferior ();
215 gdb_assert (inf
!= NULL
);
220 inf
->cwd
.reset (xstrdup (cwd
));
223 /* See gdbsupport/common-inferior.h. */
228 return current_inferior ()->cwd
.get ();
231 /* Handle the 'set cwd' command. */
234 set_cwd_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
236 if (*inferior_cwd_scratch
== '\0')
237 set_inferior_cwd (NULL
);
239 set_inferior_cwd (inferior_cwd_scratch
);
242 /* Handle the 'show cwd' command. */
245 show_cwd_command (struct ui_file
*file
, int from_tty
,
246 struct cmd_list_element
*c
, const char *value
)
248 const char *cwd
= get_inferior_cwd ();
251 fprintf_filtered (gdb_stdout
,
253 You have not set the inferior's current working directory.\n\
254 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
255 server's cwd if remote debugging.\n"));
257 fprintf_filtered (gdb_stdout
,
258 _("Current working directory that will be used "
259 "when starting the inferior is \"%s\".\n"), cwd
);
263 /* This function strips the '&' character (indicating background
264 execution) that is added as *the last* of the arguments ARGS of a
265 command. A copy of the incoming ARGS without the '&' is returned,
266 unless the resulting string after stripping is empty, in which case
267 NULL is returned. *BG_CHAR_P is an output boolean that indicates
268 whether the '&' character was found. */
270 static gdb::unique_xmalloc_ptr
<char>
271 strip_bg_char (const char *args
, int *bg_char_p
)
275 if (args
== NULL
|| *args
== '\0')
281 p
= args
+ strlen (args
);
285 while (p
> args
&& isspace (p
[-1]))
290 return gdb::unique_xmalloc_ptr
<char>
291 (savestring (args
, p
- args
));
293 return gdb::unique_xmalloc_ptr
<char> (nullptr);
297 return make_unique_xstrdup (args
);
300 /* Common actions to take after creating any sort of inferior, by any
301 means (running, attaching, connecting, et cetera). The target
302 should be stopped. */
305 post_create_inferior (struct target_ops
*target
, int from_tty
)
308 /* Be sure we own the terminal in case write operations are performed. */
309 target_terminal::ours_for_output ();
311 /* If the target hasn't taken care of this already, do it now.
312 Targets which need to access registers during to_open,
313 to_create_inferior, or to_attach should do it earlier; but many
315 target_find_description ();
317 /* Now that we know the register layout, retrieve current PC. But
318 if the PC is unavailable (e.g., we're opening a core file with
319 missing registers info), ignore it. */
320 thread_info
*thr
= inferior_thread ();
322 thr
->suspend
.stop_pc
= 0;
325 regcache
*rc
= get_thread_regcache (thr
);
326 thr
->suspend
.stop_pc
= regcache_read_pc (rc
);
328 catch (const gdb_exception_error
&ex
)
330 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
336 const unsigned solib_add_generation
337 = current_program_space
->solib_add_generation
;
339 /* Create the hooks to handle shared library load and unload
341 solib_create_inferior_hook (from_tty
);
343 if (current_program_space
->solib_add_generation
== solib_add_generation
)
345 /* The platform-specific hook should load initial shared libraries,
346 but didn't. FROM_TTY will be incorrectly 0 but such solib
347 targets should be fixed anyway. Call it only after the solib
348 target has been initialized by solib_create_inferior_hook. */
351 warning (_("platform-specific solib_create_inferior_hook did "
352 "not load initial shared libraries."));
354 /* If the solist is global across processes, there's no need to
356 if (!gdbarch_has_global_solist (target_gdbarch ()))
357 solib_add (NULL
, 0, auto_solib_add
);
361 /* If the user sets watchpoints before execution having started,
362 then she gets software watchpoints, because GDB can't know which
363 target will end up being pushed, or if it supports hardware
364 watchpoints or not. breakpoint_re_set takes care of promoting
365 watchpoints to hardware watchpoints if possible, however, if this
366 new inferior doesn't load shared libraries or we don't pull in
367 symbols from any other source on this target/arch,
368 breakpoint_re_set is never called. Call it now so that software
369 watchpoints get a chance to be promoted to hardware watchpoints
370 if the now pushed target supports hardware watchpoints. */
371 breakpoint_re_set ();
373 gdb::observers::inferior_created
.notify (target
, from_tty
);
376 /* Kill the inferior if already running. This function is designed
377 to be called when we are about to start the execution of the program
378 from the beginning. Ask the user to confirm that he wants to restart
379 the program being debugged when FROM_TTY is non-null. */
382 kill_if_already_running (int from_tty
)
384 if (inferior_ptid
!= null_ptid
&& target_has_execution
)
386 /* Bail out before killing the program if we will not be able to
388 target_require_runnable ();
391 && !query (_("The program being debugged has been started already.\n\
392 Start it from the beginning? ")))
393 error (_("Program not restarted."));
398 /* See inferior.h. */
401 prepare_execution_command (struct target_ops
*target
, int background
)
403 /* If we get a request for running in the bg but the target
404 doesn't support it, error out. */
405 if (background
&& !target
->can_async_p ())
406 error (_("Asynchronous execution not supported on this target."));
410 /* If we get a request for running in the fg, then we need to
411 simulate synchronous (fg) execution. Note no cleanup is
412 necessary for this. stdin is re-enabled whenever an error
413 reaches the top level. */
414 all_uis_on_sync_execution_starting ();
418 /* Determine how the new inferior will behave. */
422 /* Run program without any explicit stop during startup. */
425 /* Stop at the beginning of the program's main function. */
428 /* Stop at the first instruction of the program. */
429 RUN_STOP_AT_FIRST_INSN
432 /* Implement the "run" command. Force a stop during program start if
433 requested by RUN_HOW. */
436 run_command_1 (const char *args
, int from_tty
, enum run_how run_how
)
438 const char *exec_file
;
439 struct ui_out
*uiout
= current_uiout
;
440 struct target_ops
*run_target
;
445 kill_if_already_running (from_tty
);
447 init_wait_for_inferior ();
448 clear_breakpoint_hit_counts ();
450 /* Clean up any leftovers from other runs. Some other things from
451 this function should probably be moved into target_pre_inferior. */
452 target_pre_inferior (from_tty
);
454 /* The comment here used to read, "The exec file is re-read every
455 time we do a generic_mourn_inferior, so we just have to worry
456 about the symbol file." The `generic_mourn_inferior' function
457 gets called whenever the program exits. However, suppose the
458 program exits, and *then* the executable file changes? We need
459 to check again here. Since reopen_exec_file doesn't do anything
460 if the timestamp hasn't changed, I don't see the harm. */
464 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
465 args
= stripped
.get ();
467 /* Do validation and preparation before possibly changing anything
470 run_target
= find_run_target ();
472 prepare_execution_command (run_target
, async_exec
);
474 if (non_stop
&& !run_target
->supports_non_stop ())
475 error (_("The target does not support running in non-stop mode."));
477 /* Done. Can now set breakpoints, change inferior args, etc. */
479 /* Insert temporary breakpoint in main function if requested. */
480 if (run_how
== RUN_STOP_AT_MAIN
)
482 std::string arg
= string_printf ("-qualified %s", main_name ());
483 tbreak_command (arg
.c_str (), 0);
486 exec_file
= get_exec_file (0);
488 /* We keep symbols from add-symbol-file, on the grounds that the
489 user might want to add some symbols before running the program
490 (right?). But sometimes (dynamic loading where the user manually
491 introduces the new symbols with add-symbol-file), the code which
492 the symbols describe does not persist between runs. Currently
493 the user has to manually nuke all symbols between runs if they
494 want them to go away (PR 2207). This is probably reasonable. */
496 /* If there were other args, beside '&', process them. */
498 set_inferior_args (args
);
502 uiout
->field_string (NULL
, "Starting program");
505 uiout
->field_string ("execfile", exec_file
);
507 /* We call get_inferior_args() because we might need to compute
509 uiout
->field_string ("infargs", get_inferior_args ());
514 /* We call get_inferior_args() because we might need to compute
516 run_target
->create_inferior (exec_file
,
517 std::string (get_inferior_args ()),
518 current_inferior ()->environment
.envp (),
520 /* to_create_inferior should push the target, so after this point we
521 shouldn't refer to run_target again. */
524 /* We're starting off a new process. When we get out of here, in
525 non-stop mode, finish the state of all threads of that process,
526 but leave other threads alone, as they may be stopped in internal
527 events --- the frontend shouldn't see them as stopped. In
528 all-stop, always finish the state of all threads, as we may be
529 resuming more than just the new process. */
530 process_stratum_target
*finish_target
;
534 finish_target
= current_inferior ()->process_target ();
535 finish_ptid
= ptid_t (current_inferior ()->pid
);
539 finish_target
= nullptr;
540 finish_ptid
= minus_one_ptid
;
542 scoped_finish_thread_state
finish_state (finish_target
, finish_ptid
);
544 /* Pass zero for FROM_TTY, because at this point the "run" command
545 has done its thing; now we are setting up the running program. */
546 post_create_inferior (current_top_target (), 0);
548 /* Queue a pending event so that the program stops immediately. */
549 if (run_how
== RUN_STOP_AT_FIRST_INSN
)
551 thread_info
*thr
= inferior_thread ();
552 thr
->suspend
.waitstatus_pending_p
= 1;
553 thr
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
554 thr
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
557 /* Start the target running. Do not use -1 continuation as it would skip
558 breakpoint right at the entry point. */
559 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
561 /* Since there was no error, there's no need to finish the thread
563 finish_state
.release ();
567 run_command (const char *args
, int from_tty
)
569 run_command_1 (args
, from_tty
, RUN_NORMAL
);
572 /* Start the execution of the program up until the beginning of the main
576 start_command (const char *args
, int from_tty
)
578 /* Some languages such as Ada need to search inside the program
579 minimal symbols for the location where to put the temporary
580 breakpoint before starting. */
581 if (!have_minimal_symbols ())
582 error (_("No symbol table loaded. Use the \"file\" command."));
584 /* Run the program until reaching the main procedure... */
585 run_command_1 (args
, from_tty
, RUN_STOP_AT_MAIN
);
588 /* Start the execution of the program stopping at the first
592 starti_command (const char *args
, int from_tty
)
594 run_command_1 (args
, from_tty
, RUN_STOP_AT_FIRST_INSN
);
598 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
600 /* We go through all threads individually instead of compressing
601 into a single target `resume_all' request, because some threads
602 may be stopped in internal breakpoints/events, or stopped waiting
603 for its turn in the displaced stepping queue (that is, they are
604 running && !executing). The target side has no idea about why
605 the thread is stopped, so a `resume_all' command would resume too
606 much. If/when GDB gains a way to tell the target `hold this
607 thread stopped until I say otherwise', then we can optimize
609 if (thread
->state
!= THREAD_STOPPED
)
612 if (!thread
->inf
->has_execution ())
615 switch_to_thread (thread
);
616 clear_proceed_status (0);
617 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
622 ensure_valid_thread (void)
624 if (inferior_ptid
== null_ptid
625 || inferior_thread ()->state
== THREAD_EXITED
)
626 error (_("Cannot execute this command without a live selected thread."));
629 /* If the user is looking at trace frames, any resumption of execution
630 is likely to mix up recorded and live target data. So simply
631 disallow those commands. */
634 ensure_not_tfind_mode (void)
636 if (get_traceframe_number () >= 0)
637 error (_("Cannot execute this command while looking at trace frames."));
640 /* Throw an error indicating the current thread is running. */
643 error_is_running (void)
645 error (_("Cannot execute this command while "
646 "the selected thread is running."));
649 /* Calls error_is_running if the current thread is running. */
652 ensure_not_running (void)
654 if (inferior_thread ()->state
== THREAD_RUNNING
)
659 continue_1 (int all_threads
)
662 ensure_not_tfind_mode ();
664 if (non_stop
&& all_threads
)
666 /* Don't error out if the current thread is running, because
667 there may be other stopped threads. */
669 /* Backup current thread and selected frame and restore on scope
671 scoped_restore_current_thread restore_thread
;
673 iterate_over_threads (proceed_thread_callback
, NULL
);
675 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
677 /* If all threads in the target were already running,
678 proceed_thread_callback ends up never calling proceed,
679 and so nothing calls this to put the inferior's terminal
680 settings in effect and remove stdin from the event loop,
681 which we must when running a foreground command. E.g.:
685 <all threads are running now>
688 <no thread was resumed, but the inferior now owns the terminal>
690 target_terminal::inferior ();
695 ensure_valid_thread ();
696 ensure_not_running ();
697 clear_proceed_status (0);
698 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
702 /* continue [-a] [proceed-count] [&] */
705 continue_command (const char *args
, int from_tty
)
708 bool all_threads_p
= false;
712 /* Find out whether we must run in the background. */
713 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
714 args
= stripped
.get ();
718 if (startswith (args
, "-a"))
720 all_threads_p
= true;
721 args
+= sizeof ("-a") - 1;
727 if (!non_stop
&& all_threads_p
)
728 error (_("`-a' is meaningless in all-stop mode."));
730 if (args
!= NULL
&& all_threads_p
)
731 error (_("Can't resume all threads and specify "
732 "proceed count simultaneously."));
734 /* If we have an argument left, set proceed count of breakpoint we
741 struct thread_info
*tp
;
744 tp
= inferior_thread ();
747 process_stratum_target
*last_target
;
750 get_last_target_status (&last_target
, &last_ptid
, nullptr);
751 tp
= find_thread_ptid (last_target
, last_ptid
);
754 bs
= tp
->control
.stop_bpstat
;
756 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
759 set_ignore_count (num
,
760 parse_and_eval_long (args
) - 1,
762 /* set_ignore_count prints a message ending with a period.
763 So print two spaces before "Continuing.". */
765 printf_filtered (" ");
769 if (!stopped
&& from_tty
)
772 ("Not stopped at any breakpoint; argument ignored.\n");
777 ensure_not_tfind_mode ();
779 if (!non_stop
|| !all_threads_p
)
781 ensure_valid_thread ();
782 ensure_not_running ();
785 prepare_execution_command (current_top_target (), async_exec
);
788 printf_filtered (_("Continuing.\n"));
790 continue_1 (all_threads_p
);
793 /* Record in TP the starting point of a "step" or "next" command. */
796 set_step_frame (thread_info
*tp
)
798 /* This can be removed once this function no longer implicitly relies on the
799 inferior_ptid value. */
800 gdb_assert (inferior_ptid
== tp
->ptid
);
802 frame_info
*frame
= get_current_frame ();
804 symtab_and_line sal
= find_frame_sal (frame
);
805 set_step_info (tp
, frame
, sal
);
807 CORE_ADDR pc
= get_frame_pc (frame
);
808 tp
->control
.step_start_function
= find_pc_function (pc
);
811 /* Step until outside of current statement. */
814 step_command (const char *count_string
, int from_tty
)
816 step_1 (0, 0, count_string
);
819 /* Likewise, but skip over subroutine calls as if single instructions. */
822 next_command (const char *count_string
, int from_tty
)
824 step_1 (1, 0, count_string
);
827 /* Likewise, but step only one instruction. */
830 stepi_command (const char *count_string
, int from_tty
)
832 step_1 (0, 1, count_string
);
836 nexti_command (const char *count_string
, int from_tty
)
838 step_1 (1, 1, count_string
);
841 /* Data for the FSM that manages the step/next/stepi/nexti
844 struct step_command_fsm
: public thread_fsm
846 /* How many steps left in a "step N"-like command. */
849 /* If true, this is a next/nexti, otherwise a step/stepi. */
850 int skip_subroutines
;
852 /* If true, this is a stepi/nexti, otherwise a step/step. */
855 explicit step_command_fsm (struct interp
*cmd_interp
)
856 : thread_fsm (cmd_interp
)
860 void clean_up (struct thread_info
*thread
) override
;
861 bool should_stop (struct thread_info
*thread
) override
;
862 enum async_reply_reason
do_async_reply_reason () override
;
865 /* Prepare for a step/next/etc. command. Any target resource
866 allocated here is undone in the FSM's clean_up method. */
869 step_command_fsm_prepare (struct step_command_fsm
*sm
,
870 int skip_subroutines
, int single_inst
,
871 int count
, struct thread_info
*thread
)
873 sm
->skip_subroutines
= skip_subroutines
;
874 sm
->single_inst
= single_inst
;
877 /* Leave the si command alone. */
878 if (!sm
->single_inst
|| sm
->skip_subroutines
)
879 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
881 thread
->control
.stepping_command
= 1;
884 static int prepare_one_step (thread_info
*, struct step_command_fsm
*sm
);
887 step_1 (int skip_subroutines
, int single_inst
, const char *count_string
)
891 struct thread_info
*thr
;
892 struct step_command_fsm
*step_sm
;
895 ensure_not_tfind_mode ();
896 ensure_valid_thread ();
897 ensure_not_running ();
899 gdb::unique_xmalloc_ptr
<char> stripped
900 = strip_bg_char (count_string
, &async_exec
);
901 count_string
= stripped
.get ();
903 prepare_execution_command (current_top_target (), async_exec
);
905 count
= count_string
? parse_and_eval_long (count_string
) : 1;
907 clear_proceed_status (1);
909 /* Setup the execution command state machine to handle all the COUNT
911 thr
= inferior_thread ();
912 step_sm
= new step_command_fsm (command_interp ());
913 thr
->thread_fsm
= step_sm
;
915 step_command_fsm_prepare (step_sm
, skip_subroutines
,
916 single_inst
, count
, thr
);
918 /* Do only one step for now, before returning control to the event
919 loop. Let the continuation figure out how many other steps we
920 need to do, and handle them one at the time, through
922 if (!prepare_one_step (thr
, step_sm
))
923 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
928 /* Stepped into an inline frame. Pretend that we've
930 thr
->thread_fsm
->clean_up (thr
);
931 proceeded
= normal_stop ();
933 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
934 all_uis_check_sync_execution_done ();
938 /* Implementation of the 'should_stop' FSM method for stepping
939 commands. Called after we are done with one step operation, to
940 check whether we need to step again, before we print the prompt and
941 return control to the user. If count is > 1, returns false, as we
942 will need to keep going. */
945 step_command_fsm::should_stop (struct thread_info
*tp
)
947 if (tp
->control
.stop_step
)
949 /* There are more steps to make, and we did stop due to
950 ending a stepping range. Do another step. */
952 return prepare_one_step (tp
, this);
960 /* Implementation of the 'clean_up' FSM method for stepping commands. */
963 step_command_fsm::clean_up (struct thread_info
*thread
)
965 if (!single_inst
|| skip_subroutines
)
966 delete_longjmp_breakpoint (thread
->global_num
);
969 /* Implementation of the 'async_reply_reason' FSM method for stepping
972 enum async_reply_reason
973 step_command_fsm::do_async_reply_reason ()
975 return EXEC_ASYNC_END_STEPPING_RANGE
;
978 /* Prepare for one step in "step N". The actual target resumption is
979 done by the caller. Return true if we're done and should thus
980 report a stop to the user. Returns false if the target needs to be
984 prepare_one_step (thread_info
*tp
, struct step_command_fsm
*sm
)
986 /* This can be removed once this function no longer implicitly relies on the
987 inferior_ptid value. */
988 gdb_assert (inferior_ptid
== tp
->ptid
);
992 struct frame_info
*frame
= get_current_frame ();
996 if (!sm
->single_inst
)
1000 /* Step at an inlined function behaves like "down". */
1001 if (!sm
->skip_subroutines
1002 && inline_skipped_frames (tp
))
1005 const char *fn
= NULL
;
1006 symtab_and_line sal
;
1009 /* Pretend that we've ran. */
1010 resume_ptid
= user_visible_resume_ptid (1);
1011 set_running (tp
->inf
->process_target (), resume_ptid
, true);
1013 step_into_inline_frame (tp
);
1015 frame
= get_current_frame ();
1016 sal
= find_frame_sal (frame
);
1017 sym
= get_frame_function (frame
);
1020 fn
= sym
->print_name ();
1023 || !function_name_is_marked_for_skip (fn
, sal
))
1026 return prepare_one_step (tp
, sm
);
1030 pc
= get_frame_pc (frame
);
1031 find_pc_line_pc_range (pc
,
1032 &tp
->control
.step_range_start
,
1033 &tp
->control
.step_range_end
);
1035 tp
->control
.may_range_step
= 1;
1037 /* If we have no line info, switch to stepi mode. */
1038 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1040 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1041 tp
->control
.may_range_step
= 0;
1043 else if (tp
->control
.step_range_end
== 0)
1047 if (find_pc_partial_function (pc
, &name
,
1048 &tp
->control
.step_range_start
,
1049 &tp
->control
.step_range_end
) == 0)
1050 error (_("Cannot find bounds of current function"));
1052 target_terminal::ours_for_output ();
1053 printf_filtered (_("Single stepping until exit from function %s,"
1054 "\nwhich has no line number information.\n"),
1060 /* Say we are stepping, but stop after one insn whatever it does. */
1061 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1062 if (!sm
->skip_subroutines
)
1064 Don't step over function calls, not even to functions lacking
1066 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1069 if (sm
->skip_subroutines
)
1070 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1076 sm
->set_finished ();
1081 /* Continue program at specified address. */
1084 jump_command (const char *arg
, int from_tty
)
1086 struct gdbarch
*gdbarch
= get_current_arch ();
1093 ensure_not_tfind_mode ();
1094 ensure_valid_thread ();
1095 ensure_not_running ();
1097 /* Find out whether we must run in the background. */
1098 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1099 arg
= stripped
.get ();
1101 prepare_execution_command (current_top_target (), async_exec
);
1104 error_no_arg (_("starting address"));
1106 std::vector
<symtab_and_line
> sals
1107 = decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1108 if (sals
.size () != 1)
1109 error (_("Unreasonable jump request"));
1111 symtab_and_line
&sal
= sals
[0];
1113 if (sal
.symtab
== 0 && sal
.pc
== 0)
1114 error (_("No source file has been specified."));
1116 resolve_sal_pc (&sal
); /* May error out. */
1118 /* See if we are trying to jump to another function. */
1119 fn
= get_frame_function (get_current_frame ());
1120 sfn
= find_pc_function (sal
.pc
);
1121 if (fn
!= NULL
&& sfn
!= fn
)
1123 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1126 error (_("Not confirmed."));
1133 struct obj_section
*section
;
1135 fixup_symbol_section (sfn
, 0);
1136 section
= SYMBOL_OBJ_SECTION (symbol_objfile (sfn
), sfn
);
1137 if (section_is_overlay (section
)
1138 && !section_is_mapped (section
))
1140 if (!query (_("WARNING!!! Destination is in "
1141 "unmapped overlay! Jump anyway? ")))
1143 error (_("Not confirmed."));
1153 printf_filtered (_("Continuing at "));
1154 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1155 printf_filtered (".\n");
1158 clear_proceed_status (0);
1159 proceed (addr
, GDB_SIGNAL_0
);
1162 /* Continue program giving it specified signal. */
1165 signal_command (const char *signum_exp
, int from_tty
)
1167 enum gdb_signal oursig
;
1170 dont_repeat (); /* Too dangerous. */
1172 ensure_not_tfind_mode ();
1173 ensure_valid_thread ();
1174 ensure_not_running ();
1176 /* Find out whether we must run in the background. */
1177 gdb::unique_xmalloc_ptr
<char> stripped
1178 = strip_bg_char (signum_exp
, &async_exec
);
1179 signum_exp
= stripped
.get ();
1181 prepare_execution_command (current_top_target (), async_exec
);
1184 error_no_arg (_("signal number"));
1186 /* It would be even slicker to make signal names be valid expressions,
1187 (the type could be "enum $signal" or some such), then the user could
1188 assign them to convenience variables. */
1189 oursig
= gdb_signal_from_name (signum_exp
);
1191 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1193 /* No, try numeric. */
1194 int num
= parse_and_eval_long (signum_exp
);
1197 oursig
= GDB_SIGNAL_0
;
1199 oursig
= gdb_signal_from_command (num
);
1202 /* Look for threads other than the current that this command ends up
1203 resuming too (due to schedlock off), and warn if they'll get a
1204 signal delivered. "signal 0" is used to suppress a previous
1205 signal, but if the current thread is no longer the one that got
1206 the signal, then the user is potentially suppressing the signal
1207 of the wrong thread. */
1210 int must_confirm
= 0;
1212 /* This indicates what will be resumed. Either a single thread,
1213 a whole process, or all threads of all processes. */
1214 ptid_t resume_ptid
= user_visible_resume_ptid (0);
1215 process_stratum_target
*resume_target
1216 = user_visible_resume_target (resume_ptid
);
1218 thread_info
*current
= inferior_thread ();
1220 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
1225 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1226 && signal_pass_state (tp
->suspend
.stop_signal
))
1229 printf_unfiltered (_("Note:\n"));
1230 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1231 print_thread_id (tp
),
1232 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1233 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1239 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1240 "still deliver the signals noted above to their respective threads.\n"
1241 "Continue anyway? "),
1242 print_thread_id (inferior_thread ())))
1243 error (_("Not confirmed."));
1248 if (oursig
== GDB_SIGNAL_0
)
1249 printf_filtered (_("Continuing with no signal.\n"));
1251 printf_filtered (_("Continuing with signal %s.\n"),
1252 gdb_signal_to_name (oursig
));
1255 clear_proceed_status (0);
1256 proceed ((CORE_ADDR
) -1, oursig
);
1259 /* Queue a signal to be delivered to the current thread. */
1262 queue_signal_command (const char *signum_exp
, int from_tty
)
1264 enum gdb_signal oursig
;
1265 struct thread_info
*tp
;
1268 ensure_not_tfind_mode ();
1269 ensure_valid_thread ();
1270 ensure_not_running ();
1272 if (signum_exp
== NULL
)
1273 error_no_arg (_("signal number"));
1275 /* It would be even slicker to make signal names be valid expressions,
1276 (the type could be "enum $signal" or some such), then the user could
1277 assign them to convenience variables. */
1278 oursig
= gdb_signal_from_name (signum_exp
);
1280 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1282 /* No, try numeric. */
1283 int num
= parse_and_eval_long (signum_exp
);
1286 oursig
= GDB_SIGNAL_0
;
1288 oursig
= gdb_signal_from_command (num
);
1291 if (oursig
!= GDB_SIGNAL_0
1292 && !signal_pass_state (oursig
))
1293 error (_("Signal handling set to not pass this signal to the program."));
1295 tp
= inferior_thread ();
1296 tp
->suspend
.stop_signal
= oursig
;
1299 /* Data for the FSM that manages the until (with no argument)
1302 struct until_next_fsm
: public thread_fsm
1304 /* The thread that as current when the command was executed. */
1307 until_next_fsm (struct interp
*cmd_interp
, int thread
)
1308 : thread_fsm (cmd_interp
),
1313 bool should_stop (struct thread_info
*thread
) override
;
1314 void clean_up (struct thread_info
*thread
) override
;
1315 enum async_reply_reason
do_async_reply_reason () override
;
1318 /* Implementation of the 'should_stop' FSM method for the until (with
1322 until_next_fsm::should_stop (struct thread_info
*tp
)
1324 if (tp
->control
.stop_step
)
1330 /* Implementation of the 'clean_up' FSM method for the until (with no
1334 until_next_fsm::clean_up (struct thread_info
*thread
)
1336 delete_longjmp_breakpoint (thread
->global_num
);
1339 /* Implementation of the 'async_reply_reason' FSM method for the until
1340 (with no arg) command. */
1342 enum async_reply_reason
1343 until_next_fsm::do_async_reply_reason ()
1345 return EXEC_ASYNC_END_STEPPING_RANGE
;
1348 /* Proceed until we reach a different source line with pc greater than
1349 our current one or exit the function. We skip calls in both cases.
1351 Note that eventually this command should probably be changed so
1352 that only source lines are printed out when we hit the breakpoint
1353 we set. This may involve changes to wait_for_inferior and the
1354 proceed status code. */
1357 until_next_command (int from_tty
)
1359 struct frame_info
*frame
;
1361 struct symbol
*func
;
1362 struct symtab_and_line sal
;
1363 struct thread_info
*tp
= inferior_thread ();
1364 int thread
= tp
->global_num
;
1365 struct until_next_fsm
*sm
;
1367 clear_proceed_status (0);
1368 set_step_frame (tp
);
1370 frame
= get_current_frame ();
1372 /* Step until either exited from this function or greater
1373 than the current line (if in symbolic section) or pc (if
1376 pc
= get_frame_pc (frame
);
1377 func
= find_pc_function (pc
);
1381 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1383 if (msymbol
.minsym
== NULL
)
1384 error (_("Execution is not within a known function."));
1386 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1387 /* The upper-bound of step_range is exclusive. In order to make PC
1388 within the range, set the step_range_end with PC + 1. */
1389 tp
->control
.step_range_end
= pc
+ 1;
1393 sal
= find_pc_line (pc
, 0);
1395 tp
->control
.step_range_start
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func
));
1396 tp
->control
.step_range_end
= sal
.end
;
1398 tp
->control
.may_range_step
= 1;
1400 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1402 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1403 delete_longjmp_breakpoint_cleanup
lj_deleter (thread
);
1405 sm
= new until_next_fsm (command_interp (), tp
->global_num
);
1406 tp
->thread_fsm
= sm
;
1407 lj_deleter
.release ();
1409 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1413 until_command (const char *arg
, int from_tty
)
1418 ensure_not_tfind_mode ();
1419 ensure_valid_thread ();
1420 ensure_not_running ();
1422 /* Find out whether we must run in the background. */
1423 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1424 arg
= stripped
.get ();
1426 prepare_execution_command (current_top_target (), async_exec
);
1429 until_break_command (arg
, from_tty
, 0);
1431 until_next_command (from_tty
);
1435 advance_command (const char *arg
, int from_tty
)
1440 ensure_not_tfind_mode ();
1441 ensure_valid_thread ();
1442 ensure_not_running ();
1445 error_no_arg (_("a location"));
1447 /* Find out whether we must run in the background. */
1448 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1449 arg
= stripped
.get ();
1451 prepare_execution_command (current_top_target (), async_exec
);
1453 until_break_command (arg
, from_tty
, 1);
1456 /* Return the value of the result of a function at the end of a 'finish'
1457 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1458 right after an inferior call has finished. */
1461 get_return_value (struct value
*function
, struct type
*value_type
)
1463 regcache
*stop_regs
= get_current_regcache ();
1464 struct gdbarch
*gdbarch
= stop_regs
->arch ();
1465 struct value
*value
;
1467 value_type
= check_typedef (value_type
);
1468 gdb_assert (value_type
->code () != TYPE_CODE_VOID
);
1470 /* FIXME: 2003-09-27: When returning from a nested inferior function
1471 call, it's possible (with no help from the architecture vector)
1472 to locate and return/print a "struct return" value. This is just
1473 a more complicated case of what is already being done in the
1474 inferior function call code. In fact, when inferior function
1475 calls are made async, this will likely be made the norm. */
1477 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1480 case RETURN_VALUE_REGISTER_CONVENTION
:
1481 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1482 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1483 value
= allocate_value (value_type
);
1484 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1485 value_contents_raw (value
), NULL
);
1487 case RETURN_VALUE_STRUCT_CONVENTION
:
1491 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1497 /* The captured function return value/type and its position in the
1500 struct return_value_info
1502 /* The captured return value. May be NULL if we weren't able to
1503 retrieve it. See get_return_value. */
1504 struct value
*value
;
1506 /* The return type. In some cases, we'll not be able extract the
1507 return value, but we always know the type. */
1510 /* If we captured a value, this is the value history index. */
1511 int value_history_index
;
1514 /* Helper for print_return_value. */
1517 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1519 if (rv
->value
!= NULL
)
1521 struct value_print_options opts
;
1524 uiout
->text ("Value returned is ");
1525 uiout
->field_fmt ("gdb-result-var", "$%d",
1526 rv
->value_history_index
);
1527 uiout
->text (" = ");
1528 get_user_print_options (&opts
);
1530 if (opts
.finish_print
)
1533 value_print (rv
->value
, &stb
, &opts
);
1534 uiout
->field_stream ("return-value", stb
);
1537 uiout
->field_string ("return-value", _("<not displayed>"),
1538 metadata_style
.style ());
1543 std::string type_name
= type_to_string (rv
->type
);
1544 uiout
->text ("Value returned has type: ");
1545 uiout
->field_string ("return-type", type_name
.c_str ());
1547 uiout
->text (" Cannot determine contents\n");
1551 /* Print the result of a function at the end of a 'finish' command.
1552 RV points at an object representing the captured return value/type
1553 and its position in the value history. */
1556 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1558 if (rv
->type
== NULL
1559 || check_typedef (rv
->type
)->code () == TYPE_CODE_VOID
)
1564 /* print_return_value_1 can throw an exception in some
1565 circumstances. We need to catch this so that we still
1566 delete the breakpoint. */
1567 print_return_value_1 (uiout
, rv
);
1569 catch (const gdb_exception
&ex
)
1571 exception_print (gdb_stdout
, ex
);
1575 /* Data for the FSM that manages the finish command. */
1577 struct finish_command_fsm
: public thread_fsm
1579 /* The momentary breakpoint set at the function's return address in
1581 breakpoint_up breakpoint
;
1583 /* The function that we're stepping out of. */
1584 struct symbol
*function
= nullptr;
1586 /* If the FSM finishes successfully, this stores the function's
1588 struct return_value_info return_value_info
{};
1590 explicit finish_command_fsm (struct interp
*cmd_interp
)
1591 : thread_fsm (cmd_interp
)
1595 bool should_stop (struct thread_info
*thread
) override
;
1596 void clean_up (struct thread_info
*thread
) override
;
1597 struct return_value_info
*return_value () override
;
1598 enum async_reply_reason
do_async_reply_reason () override
;
1601 /* Implementation of the 'should_stop' FSM method for the finish
1602 commands. Detects whether the thread stepped out of the function
1603 successfully, and if so, captures the function's return value and
1604 marks the FSM finished. */
1607 finish_command_fsm::should_stop (struct thread_info
*tp
)
1609 struct return_value_info
*rv
= &return_value_info
;
1611 if (function
!= NULL
1612 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1613 breakpoint
.get ()) != NULL
)
1618 rv
->type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1619 if (rv
->type
== NULL
)
1620 internal_error (__FILE__
, __LINE__
,
1621 _("finish_command: function has no target type"));
1623 if (check_typedef (rv
->type
)->code () != TYPE_CODE_VOID
)
1627 func
= read_var_value (function
, NULL
, get_current_frame ());
1628 rv
->value
= get_return_value (func
, rv
->type
);
1629 if (rv
->value
!= NULL
)
1630 rv
->value_history_index
= record_latest_value (rv
->value
);
1633 else if (tp
->control
.stop_step
)
1635 /* Finishing from an inline frame, or reverse finishing. In
1636 either case, there's no way to retrieve the return value. */
1643 /* Implementation of the 'clean_up' FSM method for the finish
1647 finish_command_fsm::clean_up (struct thread_info
*thread
)
1649 breakpoint
.reset ();
1650 delete_longjmp_breakpoint (thread
->global_num
);
1653 /* Implementation of the 'return_value' FSM method for the finish
1656 struct return_value_info
*
1657 finish_command_fsm::return_value ()
1659 return &return_value_info
;
1662 /* Implementation of the 'async_reply_reason' FSM method for the
1665 enum async_reply_reason
1666 finish_command_fsm::do_async_reply_reason ()
1668 if (execution_direction
== EXEC_REVERSE
)
1669 return EXEC_ASYNC_END_STEPPING_RANGE
;
1671 return EXEC_ASYNC_FUNCTION_FINISHED
;
1674 /* finish_backward -- helper function for finish_command. */
1677 finish_backward (struct finish_command_fsm
*sm
)
1679 struct symtab_and_line sal
;
1680 struct thread_info
*tp
= inferior_thread ();
1682 CORE_ADDR func_addr
;
1684 pc
= get_frame_pc (get_current_frame ());
1686 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1687 error (_("Cannot find bounds of current function"));
1689 sal
= find_pc_line (func_addr
, 0);
1691 tp
->control
.proceed_to_finish
= 1;
1692 /* Special case: if we're sitting at the function entry point,
1693 then all we need to do is take a reverse singlestep. We
1694 don't need to set a breakpoint, and indeed it would do us
1697 Note that this can only happen at frame #0, since there's
1698 no way that a function up the stack can have a return address
1699 that's equal to its entry point. */
1703 struct frame_info
*frame
= get_selected_frame (NULL
);
1704 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1706 /* Set a step-resume at the function's entry point. Once that's
1707 hit, we'll do one more step backwards. */
1708 symtab_and_line sr_sal
;
1710 sr_sal
.pspace
= get_frame_program_space (frame
);
1711 insert_step_resume_breakpoint_at_sal (gdbarch
,
1712 sr_sal
, null_frame_id
);
1714 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1718 /* We're almost there -- we just need to back up by one more
1720 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1721 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1725 /* finish_forward -- helper function for finish_command. FRAME is the
1726 frame that called the function we're about to step out of. */
1729 finish_forward (struct finish_command_fsm
*sm
, struct frame_info
*frame
)
1731 struct frame_id frame_id
= get_frame_id (frame
);
1732 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1733 struct symtab_and_line sal
;
1734 struct thread_info
*tp
= inferior_thread ();
1736 sal
= find_pc_line (get_frame_pc (frame
), 0);
1737 sal
.pc
= get_frame_pc (frame
);
1739 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1740 get_stack_frame_id (frame
),
1743 /* set_momentary_breakpoint invalidates FRAME. */
1746 set_longjmp_breakpoint (tp
, frame_id
);
1748 /* We want to print return value, please... */
1749 tp
->control
.proceed_to_finish
= 1;
1751 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1754 /* Skip frames for "finish". */
1756 static struct frame_info
*
1757 skip_finish_frames (struct frame_info
*frame
)
1759 struct frame_info
*start
;
1765 frame
= skip_tailcall_frames (frame
);
1769 frame
= skip_unwritable_frames (frame
);
1773 while (start
!= frame
);
1778 /* "finish": Set a temporary breakpoint at the place the selected
1779 frame will return to, then continue. */
1782 finish_command (const char *arg
, int from_tty
)
1784 struct frame_info
*frame
;
1786 struct finish_command_fsm
*sm
;
1787 struct thread_info
*tp
;
1790 ensure_not_tfind_mode ();
1791 ensure_valid_thread ();
1792 ensure_not_running ();
1794 /* Find out whether we must run in the background. */
1795 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1796 arg
= stripped
.get ();
1798 prepare_execution_command (current_top_target (), async_exec
);
1801 error (_("The \"finish\" command does not take any arguments."));
1803 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1805 error (_("\"finish\" not meaningful in the outermost frame."));
1807 clear_proceed_status (0);
1809 tp
= inferior_thread ();
1811 sm
= new finish_command_fsm (command_interp ());
1813 tp
->thread_fsm
= sm
;
1815 /* Finishing from an inline frame is completely different. We don't
1816 try to show the "return value" - no way to locate it. */
1817 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1820 /* Claim we are stepping in the calling frame. An empty step
1821 range means that we will stop once we aren't in a function
1822 called by that frame. We don't use the magic "1" value for
1823 step_range_end, because then infrun will think this is nexti,
1824 and not step over the rest of this inlined function call. */
1825 set_step_info (tp
, frame
, {});
1826 tp
->control
.step_range_start
= get_frame_pc (frame
);
1827 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1828 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1830 /* Print info on the selected frame, including level number but not
1834 printf_filtered (_("Run till exit from "));
1835 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1838 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1842 /* Find the function we will return from. */
1844 sm
->function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1846 /* Print info on the selected frame, including level number but not
1850 if (execution_direction
== EXEC_REVERSE
)
1851 printf_filtered (_("Run back to call of "));
1854 if (sm
->function
!= NULL
&& TYPE_NO_RETURN (sm
->function
->type
)
1855 && !query (_("warning: Function %s does not return normally.\n"
1856 "Try to finish anyway? "),
1857 sm
->function
->print_name ()))
1858 error (_("Not confirmed."));
1859 printf_filtered (_("Run till exit from "));
1862 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1865 if (execution_direction
== EXEC_REVERSE
)
1866 finish_backward (sm
);
1869 frame
= skip_finish_frames (frame
);
1872 error (_("Cannot find the caller frame."));
1874 finish_forward (sm
, frame
);
1880 info_program_command (const char *args
, int from_tty
)
1885 process_stratum_target
*proc_target
;
1887 if (!target_has_execution
)
1889 printf_filtered (_("The program being debugged is not being run.\n"));
1895 ptid
= inferior_ptid
;
1896 proc_target
= current_inferior ()->process_target ();
1899 get_last_target_status (&proc_target
, &ptid
, nullptr);
1901 if (ptid
== null_ptid
|| ptid
== minus_one_ptid
)
1902 error (_("No selected thread."));
1904 thread_info
*tp
= find_thread_ptid (proc_target
, ptid
);
1906 if (tp
->state
== THREAD_EXITED
)
1907 error (_("Invalid selected thread."));
1908 else if (tp
->state
== THREAD_RUNNING
)
1909 error (_("Selected thread is running."));
1911 bs
= tp
->control
.stop_bpstat
;
1912 stat
= bpstat_num (&bs
, &num
);
1914 target_files_info ();
1915 printf_filtered (_("Program stopped at %s.\n"),
1916 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
1917 if (tp
->control
.stop_step
)
1918 printf_filtered (_("It stopped after being stepped.\n"));
1921 /* There may be several breakpoints in the same place, so this
1922 isn't as strange as it seems. */
1927 printf_filtered (_("It stopped at a breakpoint "
1928 "that has since been deleted.\n"));
1931 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1932 stat
= bpstat_num (&bs
, &num
);
1935 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
1937 printf_filtered (_("It stopped with signal %s, %s.\n"),
1938 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1939 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1944 printf_filtered (_("Type \"info stack\" or \"info "
1945 "registers\" for more information.\n"));
1950 environment_info (const char *var
, int from_tty
)
1954 const char *val
= current_inferior ()->environment
.get (var
);
1958 puts_filtered (var
);
1959 puts_filtered (" = ");
1960 puts_filtered (val
);
1961 puts_filtered ("\n");
1965 puts_filtered ("Environment variable \"");
1966 puts_filtered (var
);
1967 puts_filtered ("\" not defined.\n");
1972 char **envp
= current_inferior ()->environment
.envp ();
1974 for (int idx
= 0; envp
[idx
] != NULL
; ++idx
)
1976 puts_filtered (envp
[idx
]);
1977 puts_filtered ("\n");
1983 set_environment_command (const char *arg
, int from_tty
)
1985 const char *p
, *val
;
1989 error_no_arg (_("environment variable and value"));
1991 /* Find separation between variable name and value. */
1992 p
= (char *) strchr (arg
, '=');
1993 val
= (char *) strchr (arg
, ' ');
1995 if (p
!= 0 && val
!= 0)
1997 /* We have both a space and an equals. If the space is before the
1998 equals, walk forward over the spaces til we see a nonspace
1999 (possibly the equals). */
2004 /* Now if the = is after the char following the spaces,
2005 take the char following the spaces. */
2009 else if (val
!= 0 && p
== 0)
2013 error_no_arg (_("environment variable to set"));
2015 if (p
== 0 || p
[1] == 0)
2019 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2023 /* Not setting variable value to null. */
2025 while (*val
== ' ' || *val
== '\t')
2029 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2032 std::string
var (arg
, p
- arg
);
2035 printf_filtered (_("Setting environment variable "
2036 "\"%s\" to null value.\n"),
2038 current_inferior ()->environment
.set (var
.c_str (), "");
2041 current_inferior ()->environment
.set (var
.c_str (), val
);
2045 unset_environment_command (const char *var
, int from_tty
)
2049 /* If there is no argument, delete all environment variables.
2050 Ask for confirmation if reading from the terminal. */
2051 if (!from_tty
|| query (_("Delete all environment variables? ")))
2052 current_inferior ()->environment
.clear ();
2055 current_inferior ()->environment
.unset (var
);
2058 /* Handle the execution path (PATH variable). */
2060 static const char path_var_name
[] = "PATH";
2063 path_info (const char *args
, int from_tty
)
2065 puts_filtered ("Executable and object file path: ");
2066 puts_filtered (current_inferior ()->environment
.get (path_var_name
));
2067 puts_filtered ("\n");
2070 /* Add zero or more directories to the front of the execution path. */
2073 path_command (const char *dirname
, int from_tty
)
2079 env
= current_inferior ()->environment
.get (path_var_name
);
2080 /* Can be null if path is not set. */
2083 exec_path
= xstrdup (env
);
2084 mod_path (dirname
, &exec_path
);
2085 current_inferior ()->environment
.set (path_var_name
, exec_path
);
2088 path_info (NULL
, from_tty
);
2093 pad_to_column (string_file
&stream
, int col
)
2095 /* At least one space must be printed to separate columns. */
2097 const int size
= stream
.size ();
2099 stream
.puts (n_spaces (col
- size
));
2102 /* Print out the register NAME with value VAL, to FILE, in the default
2106 default_print_one_register_info (struct ui_file
*file
,
2110 struct type
*regtype
= value_type (val
);
2111 int print_raw_format
;
2112 string_file format_stream
;
2115 value_column_1
= 15,
2116 /* Give enough room for "0x", 16 hex digits and two spaces in
2117 preceding column. */
2118 value_column_2
= value_column_1
+ 2 + 16 + 2,
2121 format_stream
.puts (name
);
2122 pad_to_column (format_stream
, value_column_1
);
2124 print_raw_format
= (value_entirely_available (val
)
2125 && !value_optimized_out (val
));
2127 /* If virtual format is floating, print it that way, and in raw
2129 if (regtype
->code () == TYPE_CODE_FLT
2130 || regtype
->code () == TYPE_CODE_DECFLOAT
)
2132 struct value_print_options opts
;
2133 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2134 enum bfd_endian byte_order
= type_byte_order (regtype
);
2136 get_user_print_options (&opts
);
2139 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2141 if (print_raw_format
)
2143 pad_to_column (format_stream
, value_column_2
);
2144 format_stream
.puts ("(raw ");
2145 print_hex_chars (&format_stream
, valaddr
, TYPE_LENGTH (regtype
),
2147 format_stream
.putc (')');
2152 struct value_print_options opts
;
2154 /* Print the register in hex. */
2155 get_formatted_print_options (&opts
, 'x');
2157 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2158 /* If not a vector register, print it also according to its
2160 if (print_raw_format
&& TYPE_VECTOR (regtype
) == 0)
2162 pad_to_column (format_stream
, value_column_2
);
2163 get_user_print_options (&opts
);
2165 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2169 fputs_filtered (format_stream
.c_str (), file
);
2170 fprintf_filtered (file
, "\n");
2173 /* Print out the machine register regnum. If regnum is -1, print all
2174 registers (print_all == 1) or all non-float and non-vector
2175 registers (print_all == 0).
2177 For most machines, having all_registers_info() print the
2178 register(s) one per line is good enough. If a different format is
2179 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2180 regs), or there is an existing convention for showing all the
2181 registers, define the architecture method PRINT_REGISTERS_INFO to
2182 provide that format. */
2185 default_print_registers_info (struct gdbarch
*gdbarch
,
2186 struct ui_file
*file
,
2187 struct frame_info
*frame
,
2188 int regnum
, int print_all
)
2191 const int numregs
= gdbarch_num_cooked_regs (gdbarch
);
2193 for (i
= 0; i
< numregs
; i
++)
2195 /* Decide between printing all regs, non-float / vector regs, or
2201 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2206 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2216 /* If the register name is empty, it is undefined for this
2217 processor, so don't display anything. */
2218 if (gdbarch_register_name (gdbarch
, i
) == NULL
2219 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2222 default_print_one_register_info (file
,
2223 gdbarch_register_name (gdbarch
, i
),
2224 value_of_register (i
, frame
));
2229 registers_info (const char *addr_exp
, int fpregs
)
2231 struct frame_info
*frame
;
2232 struct gdbarch
*gdbarch
;
2234 if (!target_has_registers
)
2235 error (_("The program has no registers now."));
2236 frame
= get_selected_frame (NULL
);
2237 gdbarch
= get_frame_arch (frame
);
2241 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2246 while (*addr_exp
!= '\0')
2251 /* Skip leading white space. */
2252 addr_exp
= skip_spaces (addr_exp
);
2254 /* Discard any leading ``$''. Check that there is something
2255 resembling a register following it. */
2256 if (addr_exp
[0] == '$')
2258 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2259 error (_("Missing register name"));
2261 /* Find the start/end of this register name/num/group. */
2263 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2267 /* Figure out what we've found and display it. */
2269 /* A register name? */
2271 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2275 /* User registers lie completely outside of the range of
2276 normal registers. Catch them early so that the target
2278 if (regnum
>= gdbarch_num_cooked_regs (gdbarch
))
2280 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2281 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2284 /* Print in the same fashion
2285 gdbarch_print_registers_info's default
2286 implementation prints. */
2287 default_print_one_register_info (gdb_stdout
,
2292 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2293 frame
, regnum
, fpregs
);
2298 /* A register group? */
2300 struct reggroup
*group
;
2302 for (group
= reggroup_next (gdbarch
, NULL
);
2304 group
= reggroup_next (gdbarch
, group
))
2306 /* Don't bother with a length check. Should the user
2307 enter a short register group name, go with the first
2308 group that matches. */
2309 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2317 regnum
< gdbarch_num_cooked_regs (gdbarch
);
2320 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2321 gdbarch_print_registers_info (gdbarch
,
2329 /* Nothing matched. */
2330 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2335 info_all_registers_command (const char *addr_exp
, int from_tty
)
2337 registers_info (addr_exp
, 1);
2341 info_registers_command (const char *addr_exp
, int from_tty
)
2343 registers_info (addr_exp
, 0);
2347 print_vector_info (struct ui_file
*file
,
2348 struct frame_info
*frame
, const char *args
)
2350 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2352 if (gdbarch_print_vector_info_p (gdbarch
))
2353 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2357 int printed_something
= 0;
2359 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2361 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2363 printed_something
= 1;
2364 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2367 if (!printed_something
)
2368 fprintf_filtered (file
, "No vector information\n");
2373 info_vector_command (const char *args
, int from_tty
)
2375 if (!target_has_registers
)
2376 error (_("The program has no registers now."));
2378 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2381 /* Kill the inferior process. Make us have no inferior. */
2384 kill_command (const char *arg
, int from_tty
)
2386 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2387 It should be a distinct flag that indicates that a target is active, cuz
2388 some targets don't have processes! */
2390 if (inferior_ptid
== null_ptid
)
2391 error (_("The program is not being run."));
2392 if (!query (_("Kill the program being debugged? ")))
2393 error (_("Not confirmed."));
2395 int pid
= current_inferior ()->pid
;
2396 /* Save the pid as a string before killing the inferior, since that
2397 may unpush the current target, and we need the string after. */
2398 std::string pid_str
= target_pid_to_str (ptid_t (pid
));
2399 int infnum
= current_inferior ()->num
;
2403 if (print_inferior_events
)
2404 printf_unfiltered (_("[Inferior %d (%s) killed]\n"),
2405 infnum
, pid_str
.c_str ());
2407 bfd_cache_close_all ();
2410 /* Used in `attach&' command. Proceed threads of inferior INF iff
2411 they stopped due to debugger request, and when they did, they
2412 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2413 have been explicitly been told to stop. */
2416 proceed_after_attach (inferior
*inf
)
2418 /* Don't error out if the current thread is running, because
2419 there may be other stopped threads. */
2421 /* Backup current thread and selected frame. */
2422 scoped_restore_current_thread restore_thread
;
2424 for (thread_info
*thread
: inf
->non_exited_threads ())
2425 if (!thread
->executing
2426 && !thread
->stop_requested
2427 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2429 switch_to_thread (thread
);
2430 clear_proceed_status (0);
2431 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2435 /* See inferior.h. */
2438 setup_inferior (int from_tty
)
2440 struct inferior
*inferior
;
2442 inferior
= current_inferior ();
2443 inferior
->needs_setup
= 0;
2445 /* If no exec file is yet known, try to determine it from the
2447 if (get_exec_file (0) == NULL
)
2448 exec_file_locate_attach (inferior_ptid
.pid (), 1, from_tty
);
2451 reopen_exec_file ();
2455 /* Take any necessary post-attaching actions for this platform. */
2456 target_post_attach (inferior_ptid
.pid ());
2458 post_create_inferior (current_top_target (), from_tty
);
2461 /* What to do after the first program stops after attaching. */
2462 enum attach_post_wait_mode
2464 /* Do nothing. Leaves threads as they are. */
2465 ATTACH_POST_WAIT_NOTHING
,
2467 /* Re-resume threads that are marked running. */
2468 ATTACH_POST_WAIT_RESUME
,
2470 /* Stop all threads. */
2471 ATTACH_POST_WAIT_STOP
,
2474 /* Called after we've attached to a process and we've seen it stop for
2475 the first time. If ASYNC_EXEC is true, re-resume threads that
2476 should be running. Else if ATTACH, */
2479 attach_post_wait (const char *args
, int from_tty
, enum attach_post_wait_mode mode
)
2481 struct inferior
*inferior
;
2483 inferior
= current_inferior ();
2484 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2486 if (inferior
->needs_setup
)
2487 setup_inferior (from_tty
);
2489 if (mode
== ATTACH_POST_WAIT_RESUME
)
2491 /* The user requested an `attach&', so be sure to leave threads
2492 that didn't get a signal running. */
2494 /* Immediatelly resume all suspended threads of this inferior,
2495 and this inferior only. This should have no effect on
2496 already running threads. If a thread has been stopped with a
2497 signal, leave it be. */
2499 proceed_after_attach (inferior
);
2502 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2504 clear_proceed_status (0);
2505 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2509 else if (mode
== ATTACH_POST_WAIT_STOP
)
2511 /* The user requested a plain `attach', so be sure to leave
2512 the inferior stopped. */
2514 /* At least the current thread is already stopped. */
2516 /* In all-stop, by definition, all threads have to be already
2517 stopped at this point. In non-stop, however, although the
2518 selected thread is stopped, others may still be executing.
2519 Be sure to explicitly stop all threads of the process. This
2520 should have no effect on already stopped threads. */
2522 target_stop (ptid_t (inferior
->pid
));
2523 else if (target_is_non_stop_p ())
2525 struct thread_info
*lowest
= inferior_thread ();
2527 stop_all_threads ();
2529 /* It's not defined which thread will report the attach
2530 stop. For consistency, always select the thread with
2531 lowest GDB number, which should be the main thread, if it
2533 for (thread_info
*thread
: current_inferior ()->non_exited_threads ())
2534 if (thread
->inf
->num
< lowest
->inf
->num
2535 || thread
->per_inf_num
< lowest
->per_inf_num
)
2538 switch_to_thread (lowest
);
2541 /* Tell the user/frontend where we're stopped. */
2543 if (deprecated_attach_hook
)
2544 deprecated_attach_hook ();
2548 struct attach_command_continuation_args
2552 enum attach_post_wait_mode mode
;
2556 attach_command_continuation (void *args
, int err
)
2558 struct attach_command_continuation_args
*a
2559 = (struct attach_command_continuation_args
*) args
;
2564 attach_post_wait (a
->args
, a
->from_tty
, a
->mode
);
2568 attach_command_continuation_free_args (void *args
)
2570 struct attach_command_continuation_args
*a
2571 = (struct attach_command_continuation_args
*) args
;
2577 /* "attach" command entry point. Takes a program started up outside
2578 of gdb and ``attaches'' to it. This stops it cold in its tracks
2579 and allows us to start debugging it. */
2582 attach_command (const char *args
, int from_tty
)
2585 struct target_ops
*attach_target
;
2586 struct inferior
*inferior
= current_inferior ();
2587 enum attach_post_wait_mode mode
;
2589 dont_repeat (); /* Not for the faint of heart */
2591 if (gdbarch_has_global_solist (target_gdbarch ()))
2592 /* Don't complain if all processes share the same symbol
2595 else if (target_has_execution
)
2597 if (query (_("A program is being debugged already. Kill it? ")))
2600 error (_("Not killed."));
2603 /* Clean up any leftovers from other runs. Some other things from
2604 this function should probably be moved into target_pre_inferior. */
2605 target_pre_inferior (from_tty
);
2607 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
2608 args
= stripped
.get ();
2610 attach_target
= find_attach_target ();
2612 prepare_execution_command (attach_target
, async_exec
);
2614 if (non_stop
&& !attach_target
->supports_non_stop ())
2615 error (_("Cannot attach to this target in non-stop mode"));
2617 attach_target
->attach (args
, from_tty
);
2618 /* to_attach should push the target, so after this point we
2619 shouldn't refer to attach_target again. */
2620 attach_target
= NULL
;
2622 /* Set up the "saved terminal modes" of the inferior
2623 based on what modes we are starting it with. */
2624 target_terminal::init ();
2626 /* Install inferior's terminal modes. This may look like a no-op,
2627 as we've just saved them above, however, this does more than
2628 restore terminal settings:
2630 - installs a SIGINT handler that forwards SIGINT to the inferior.
2631 Otherwise a Ctrl-C pressed just while waiting for the initial
2632 stop would end up as a spurious Quit.
2634 - removes stdin from the event loop, which we need if attaching
2635 in the foreground, otherwise on targets that report an initial
2636 stop on attach (which are most) we'd process input/commands
2637 while we're in the event loop waiting for that stop. That is,
2638 before the attach continuation runs and the command is really
2640 target_terminal::inferior ();
2642 /* Set up execution context to know that we should return from
2643 wait_for_inferior as soon as the target reports a stop. */
2644 init_wait_for_inferior ();
2645 clear_proceed_status (0);
2647 inferior
->needs_setup
= 1;
2649 if (target_is_non_stop_p ())
2651 /* If we find that the current thread isn't stopped, explicitly
2652 do so now, because we're going to install breakpoints and
2656 /* The user requested an `attach&'; stop just one thread. */
2657 target_stop (inferior_ptid
);
2659 /* The user requested an `attach', so stop all threads of this
2661 target_stop (ptid_t (inferior_ptid
.pid ()));
2664 /* Check for exec file mismatch, and let the user solve it. */
2665 validate_exec_file (from_tty
);
2667 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2669 /* Some system don't generate traps when attaching to inferior.
2670 E.g. Mach 3 or GNU hurd. */
2671 if (!target_attach_no_wait ())
2673 struct attach_command_continuation_args
*a
;
2675 /* Careful here. See comments in inferior.h. Basically some
2676 OSes don't ignore SIGSTOPs on continue requests anymore. We
2677 need a way for handle_inferior_event to reset the stop_signal
2678 variable after an attach, and this is what
2679 STOP_QUIETLY_NO_SIGSTOP is for. */
2680 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2682 /* Wait for stop. */
2683 a
= XNEW (struct attach_command_continuation_args
);
2684 a
->args
= xstrdup (args
);
2685 a
->from_tty
= from_tty
;
2687 add_inferior_continuation (attach_command_continuation
, a
,
2688 attach_command_continuation_free_args
);
2690 /* Let infrun consider waiting for events out of this
2692 inferior
->process_target ()->threads_executing
= true;
2694 if (!target_is_async_p ())
2695 mark_infrun_async_event_handler ();
2699 attach_post_wait (args
, from_tty
, mode
);
2702 /* We had just found out that the target was already attached to an
2703 inferior. PTID points at a thread of this new inferior, that is
2704 the most likely to be stopped right now, but not necessarily so.
2705 The new inferior is assumed to be already added to the inferior
2706 list at this point. If LEAVE_RUNNING, then leave the threads of
2707 this inferior running, except those we've explicitly seen reported
2711 notice_new_inferior (thread_info
*thr
, int leave_running
, int from_tty
)
2713 enum attach_post_wait_mode mode
2714 = leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2716 gdb::optional
<scoped_restore_current_thread
> restore_thread
;
2718 if (inferior_ptid
!= null_ptid
)
2719 restore_thread
.emplace ();
2721 /* Avoid reading registers -- we haven't fetched the target
2723 switch_to_thread_no_regs (thr
);
2725 /* When we "notice" a new inferior we need to do all the things we
2726 would normally do if we had just attached to it. */
2730 struct attach_command_continuation_args
*a
;
2731 struct inferior
*inferior
= current_inferior ();
2733 /* We're going to install breakpoints, and poke at memory,
2734 ensure that the inferior is stopped for a moment while we do
2736 target_stop (inferior_ptid
);
2738 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2740 /* Wait for stop before proceeding. */
2741 a
= XNEW (struct attach_command_continuation_args
);
2742 a
->args
= xstrdup ("");
2743 a
->from_tty
= from_tty
;
2745 add_inferior_continuation (attach_command_continuation
, a
,
2746 attach_command_continuation_free_args
);
2751 attach_post_wait ("" /* args */, from_tty
, mode
);
2756 * takes a program previously attached to and detaches it.
2757 * The program resumes execution and will no longer stop
2758 * on signals, etc. We better not have left any breakpoints
2759 * in the program or it'll die when it hits one. For this
2760 * to work, it may be necessary for the process to have been
2761 * previously attached. It *might* work if the program was
2762 * started via the normal ptrace (PTRACE_TRACEME).
2766 detach_command (const char *args
, int from_tty
)
2768 dont_repeat (); /* Not for the faint of heart. */
2770 if (inferior_ptid
== null_ptid
)
2771 error (_("The program is not being run."));
2773 query_if_trace_running (from_tty
);
2775 disconnect_tracing ();
2777 target_detach (current_inferior (), from_tty
);
2779 /* The current inferior process was just detached successfully. Get
2780 rid of breakpoints that no longer make sense. Note we don't do
2781 this within target_detach because that is also used when
2782 following child forks, and in that case we will want to transfer
2783 breakpoints to the child, not delete them. */
2784 breakpoint_init_inferior (inf_exited
);
2786 /* If the solist is global across inferiors, don't clear it when we
2787 detach from a single inferior. */
2788 if (!gdbarch_has_global_solist (target_gdbarch ()))
2789 no_shared_libraries (NULL
, from_tty
);
2791 if (deprecated_detach_hook
)
2792 deprecated_detach_hook ();
2795 /* Disconnect from the current target without resuming it (leaving it
2796 waiting for a debugger).
2798 We'd better not have left any breakpoints in the program or the
2799 next debugger will get confused. Currently only supported for some
2800 remote targets, since the normal attach mechanisms don't work on
2801 stopped processes on some native platforms (e.g. GNU/Linux). */
2804 disconnect_command (const char *args
, int from_tty
)
2806 dont_repeat (); /* Not for the faint of heart. */
2807 query_if_trace_running (from_tty
);
2808 disconnect_tracing ();
2809 target_disconnect (args
, from_tty
);
2810 no_shared_libraries (NULL
, from_tty
);
2811 init_thread_list ();
2812 if (deprecated_detach_hook
)
2813 deprecated_detach_hook ();
2816 /* Stop PTID in the current target, and tag the PTID threads as having
2817 been explicitly requested to stop. PTID can be a thread, a
2818 process, or minus_one_ptid, meaning all threads of all inferiors of
2819 the current target. */
2822 stop_current_target_threads_ns (ptid_t ptid
)
2826 /* Tag the thread as having been explicitly requested to stop, so
2827 other parts of gdb know not to resume this thread automatically,
2828 if it was stopped due to an internal event. Limit this to
2829 non-stop mode, as when debugging a multi-threaded application in
2830 all-stop mode, we will only get one stop event --- it's undefined
2831 which thread will report the event. */
2832 set_stop_requested (current_inferior ()->process_target (),
2836 /* See inferior.h. */
2839 interrupt_target_1 (bool all_threads
)
2845 scoped_restore_current_thread restore_thread
;
2847 for (inferior
*inf
: all_inferiors ())
2849 switch_to_inferior_no_thread (inf
);
2850 stop_current_target_threads_ns (minus_one_ptid
);
2854 stop_current_target_threads_ns (inferior_ptid
);
2857 target_interrupt ();
2861 Stop the execution of the target while running in async mode, in
2862 the background. In all-stop, stop the whole process. In non-stop
2863 mode, stop the current thread only by default, or stop all threads
2864 if the `-a' switch is used. */
2867 interrupt_command (const char *args
, int from_tty
)
2869 if (target_can_async_p ())
2871 int all_threads
= 0;
2873 dont_repeat (); /* Not for the faint of heart. */
2876 && startswith (args
, "-a"))
2879 if (!non_stop
&& all_threads
)
2880 error (_("-a is meaningless in all-stop mode."));
2882 interrupt_target_1 (all_threads
);
2886 /* See inferior.h. */
2889 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2890 struct frame_info
*frame
, const char *args
)
2893 int printed_something
= 0;
2895 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2897 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2899 printed_something
= 1;
2900 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2903 if (!printed_something
)
2904 fprintf_filtered (file
, "No floating-point info "
2905 "available for this processor.\n");
2909 info_float_command (const char *args
, int from_tty
)
2911 struct frame_info
*frame
;
2913 if (!target_has_registers
)
2914 error (_("The program has no registers now."));
2916 frame
= get_selected_frame (NULL
);
2917 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
2920 /* Implement `info proc' family of commands. */
2923 info_proc_cmd_1 (const char *args
, enum info_proc_what what
, int from_tty
)
2925 struct gdbarch
*gdbarch
= get_current_arch ();
2927 if (!target_info_proc (args
, what
))
2929 if (gdbarch_info_proc_p (gdbarch
))
2930 gdbarch_info_proc (gdbarch
, args
, what
);
2932 error (_("Not supported on this target."));
2936 /* Implement `info proc' when given without any further parameters. */
2939 info_proc_cmd (const char *args
, int from_tty
)
2941 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
2944 /* Implement `info proc mappings'. */
2947 info_proc_cmd_mappings (const char *args
, int from_tty
)
2949 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
2952 /* Implement `info proc stat'. */
2955 info_proc_cmd_stat (const char *args
, int from_tty
)
2957 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
2960 /* Implement `info proc status'. */
2963 info_proc_cmd_status (const char *args
, int from_tty
)
2965 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
2968 /* Implement `info proc cwd'. */
2971 info_proc_cmd_cwd (const char *args
, int from_tty
)
2973 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
2976 /* Implement `info proc cmdline'. */
2979 info_proc_cmd_cmdline (const char *args
, int from_tty
)
2981 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
2984 /* Implement `info proc exe'. */
2987 info_proc_cmd_exe (const char *args
, int from_tty
)
2989 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
2992 /* Implement `info proc files'. */
2995 info_proc_cmd_files (const char *args
, int from_tty
)
2997 info_proc_cmd_1 (args
, IP_FILES
, from_tty
);
3000 /* Implement `info proc all'. */
3003 info_proc_cmd_all (const char *args
, int from_tty
)
3005 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
3008 /* Implement `show print finish'. */
3011 show_print_finish (struct ui_file
*file
, int from_tty
,
3012 struct cmd_list_element
*c
,
3015 fprintf_filtered (file
, _("\
3016 Printing of return value after `finish' is %s.\n"),
3021 /* This help string is used for the run, start, and starti commands.
3022 It is defined as a macro to prevent duplication. */
3024 #define RUN_ARGS_HELP \
3025 "You may specify arguments to give it.\n\
3026 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3027 shell that will start the program (specified by the \"$SHELL\" environment\n\
3028 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
3029 are also allowed.\n\
3031 With no arguments, uses arguments last specified (with \"run\" or \n\
3032 \"set args\"). To cancel previous arguments and run with no arguments,\n\
3033 use \"set args\" without arguments.\n\
3035 To start the inferior without using a shell, use \"set startup-with-shell off\"."
3037 void _initialize_infcmd ();
3039 _initialize_infcmd ()
3041 static struct cmd_list_element
*info_proc_cmdlist
;
3042 struct cmd_list_element
*c
= NULL
;
3043 const char *cmd_name
;
3045 /* Add the filename of the terminal connected to inferior I/O. */
3046 add_setshow_optional_filename_cmd ("inferior-tty", class_run
,
3047 &inferior_io_terminal_scratch
, _("\
3048 Set terminal for future runs of program being debugged."), _("\
3049 Show terminal for future runs of program being debugged."), _("\
3050 Usage: set inferior-tty [TTY]\n\n\
3051 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3053 set_inferior_tty_command
,
3054 show_inferior_tty_command
,
3055 &setlist
, &showlist
);
3056 cmd_name
= "inferior-tty";
3057 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3058 gdb_assert (c
!= NULL
);
3059 add_alias_cmd ("tty", c
, class_run
, 0, &cmdlist
);
3062 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3063 &inferior_args_scratch
, _("\
3064 Set argument list to give program being debugged when it is started."), _("\
3065 Show argument list to give program being debugged when it is started."), _("\
3066 Follow this command with any number of args, to be passed to the program."),
3069 &setlist
, &showlist
);
3070 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3071 gdb_assert (c
!= NULL
);
3072 set_cmd_completer (c
, filename_completer
);
3075 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3076 &inferior_cwd_scratch
, _("\
3077 Set the current working directory to be used when the inferior is started.\n\
3078 Changing this setting does not have any effect on inferiors that are\n\
3081 Show the current working directory that is used when the inferior is started."),
3083 Use this command to change the current working directory that will be used\n\
3084 when the inferior is started. This setting does not affect GDB's current\n\
3085 working directory."),
3088 &setlist
, &showlist
);
3089 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3090 gdb_assert (c
!= NULL
);
3091 set_cmd_completer (c
, filename_completer
);
3093 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3094 The environment to give the program, or one variable's value.\n\
3095 With an argument VAR, prints the value of environment variable VAR to\n\
3096 give the program being debugged. With no arguments, prints the entire\n\
3097 environment to be given to the program."), &showlist
);
3098 set_cmd_completer (c
, noop_completer
);
3100 add_basic_prefix_cmd ("unset", no_class
,
3101 _("Complement to certain \"set\" commands."),
3102 &unsetlist
, "unset ", 0, &cmdlist
);
3104 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3105 Cancel environment variable VAR for the program.\n\
3106 This does not affect the program until the next \"run\" command."),
3108 set_cmd_completer (c
, noop_completer
);
3110 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3111 Set environment variable value to give the program.\n\
3112 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3113 VALUES of environment variables are uninterpreted strings.\n\
3114 This does not affect the program until the next \"run\" command."),
3116 set_cmd_completer (c
, noop_completer
);
3118 c
= add_com ("path", class_files
, path_command
, _("\
3119 Add directory DIR(s) to beginning of search path for object files.\n\
3120 $cwd in the path means the current working directory.\n\
3121 This path is equivalent to the $PATH shell variable. It is a list of\n\
3122 directories, separated by colons. These directories are searched to find\n\
3123 fully linked executable files and separately compiled object files as \
3125 set_cmd_completer (c
, filename_completer
);
3127 c
= add_cmd ("paths", no_class
, path_info
, _("\
3128 Current search path for finding object files.\n\
3129 $cwd in the path means the current working directory.\n\
3130 This path is equivalent to the $PATH shell variable. It is a list of\n\
3131 directories, separated by colons. These directories are searched to find\n\
3132 fully linked executable files and separately compiled object files as \
3135 set_cmd_completer (c
, noop_completer
);
3137 add_prefix_cmd ("kill", class_run
, kill_command
,
3138 _("Kill execution of program being debugged."),
3139 &killlist
, "kill ", 0, &cmdlist
);
3141 add_com ("attach", class_run
, attach_command
, _("\
3142 Attach to a process or file outside of GDB.\n\
3143 This command attaches to another target, of the same type as your last\n\
3144 \"target\" command (\"info files\" will show your target stack).\n\
3145 The command may take as argument a process id or a device file.\n\
3146 For a process id, you must have permission to send the process a signal,\n\
3147 and it must have the same effective uid as the debugger.\n\
3148 When using \"attach\" with a process id, the debugger finds the\n\
3149 program running in the process, looking first in the current working\n\
3150 directory, or (if not found there) using the source file search path\n\
3151 (see the \"directory\" command). You can also use the \"file\" command\n\
3152 to specify the program, and to load its symbol table."));
3154 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3155 Detach a process or file previously attached.\n\
3156 If a process, it is no longer traced, and it continues its execution. If\n\
3157 you were debugging a file, the file is closed and gdb no longer accesses it."),
3158 &detachlist
, "detach ", 0, &cmdlist
);
3160 add_com ("disconnect", class_run
, disconnect_command
, _("\
3161 Disconnect from a target.\n\
3162 The target will wait for another debugger to connect. Not available for\n\
3165 c
= add_com ("signal", class_run
, signal_command
, _("\
3166 Continue program with the specified signal.\n\
3167 Usage: signal SIGNAL\n\
3168 The SIGNAL argument is processed the same as the handle command.\n\
3170 An argument of \"0\" means continue the program without sending it a signal.\n\
3171 This is useful in cases where the program stopped because of a signal,\n\
3172 and you want to resume the program while discarding the signal.\n\
3174 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3175 the current thread only."));
3176 set_cmd_completer (c
, signal_completer
);
3178 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3179 Queue a signal to be delivered to the current thread when it is resumed.\n\
3180 Usage: queue-signal SIGNAL\n\
3181 The SIGNAL argument is processed the same as the handle command.\n\
3182 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3184 An argument of \"0\" means remove any currently queued signal from\n\
3185 the current thread. This is useful in cases where the program stopped\n\
3186 because of a signal, and you want to resume it while discarding the signal.\n\
3188 In a multi-threaded program the signal is queued with, or discarded from,\n\
3189 the current thread only."));
3190 set_cmd_completer (c
, signal_completer
);
3192 add_com ("stepi", class_run
, stepi_command
, _("\
3193 Step one instruction exactly.\n\
3195 Argument N means step N times (or till program stops for another \
3197 add_com_alias ("si", "stepi", class_run
, 0);
3199 add_com ("nexti", class_run
, nexti_command
, _("\
3200 Step one instruction, but proceed through subroutine calls.\n\
3202 Argument N means step N times (or till program stops for another \
3204 add_com_alias ("ni", "nexti", class_run
, 0);
3206 add_com ("finish", class_run
, finish_command
, _("\
3207 Execute until selected stack frame returns.\n\
3209 Upon return, the value returned is printed and put in the value history."));
3210 add_com_alias ("fin", "finish", class_run
, 1);
3212 add_com ("next", class_run
, next_command
, _("\
3213 Step program, proceeding through subroutine calls.\n\
3215 Unlike \"step\", if the current source line calls a subroutine,\n\
3216 this command does not enter the subroutine, but instead steps over\n\
3217 the call, in effect treating it as a single source line."));
3218 add_com_alias ("n", "next", class_run
, 1);
3220 add_com ("step", class_run
, step_command
, _("\
3221 Step program until it reaches a different source line.\n\
3223 Argument N means step N times (or till program stops for another \
3225 add_com_alias ("s", "step", class_run
, 1);
3227 c
= add_com ("until", class_run
, until_command
, _("\
3228 Execute until past the current line or past a LOCATION.\n\
3229 Execute until the program reaches a source line greater than the current\n\
3230 or a specified location (same args as break command) within the current \
3232 set_cmd_completer (c
, location_completer
);
3233 add_com_alias ("u", "until", class_run
, 1);
3235 c
= add_com ("advance", class_run
, advance_command
, _("\
3236 Continue the program up to the given location (same form as args for break \
3238 Execution will also stop upon exit from the current stack frame."));
3239 set_cmd_completer (c
, location_completer
);
3241 c
= add_com ("jump", class_run
, jump_command
, _("\
3242 Continue program being debugged at specified line or address.\n\
3243 Usage: jump LOCATION\n\
3244 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3245 for an address to start at."));
3246 set_cmd_completer (c
, location_completer
);
3247 add_com_alias ("j", "jump", class_run
, 1);
3249 add_com ("continue", class_run
, continue_command
, _("\
3250 Continue program being debugged, after signal or breakpoint.\n\
3251 Usage: continue [N]\n\
3252 If proceeding from breakpoint, a number N may be used as an argument,\n\
3253 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3254 the breakpoint won't break until the Nth time it is reached).\n\
3256 If non-stop mode is enabled, continue only the current thread,\n\
3257 otherwise all the threads in the program are continued. To \n\
3258 continue all stopped threads in non-stop mode, use the -a option.\n\
3259 Specifying -a and an ignore count simultaneously is an error."));
3260 add_com_alias ("c", "cont", class_run
, 1);
3261 add_com_alias ("fg", "cont", class_run
, 1);
3263 c
= add_com ("run", class_run
, run_command
, _("\
3264 Start debugged program.\n"
3266 set_cmd_completer (c
, filename_completer
);
3267 add_com_alias ("r", "run", class_run
, 1);
3269 c
= add_com ("start", class_run
, start_command
, _("\
3270 Start the debugged program stopping at the beginning of the main procedure.\n"
3272 set_cmd_completer (c
, filename_completer
);
3274 c
= add_com ("starti", class_run
, starti_command
, _("\
3275 Start the debugged program stopping at the first instruction.\n"
3277 set_cmd_completer (c
, filename_completer
);
3279 add_com ("interrupt", class_run
, interrupt_command
,
3280 _("Interrupt the execution of the debugged program.\n\
3281 If non-stop mode is enabled, interrupt only the current thread,\n\
3282 otherwise all the threads in the program are stopped. To \n\
3283 interrupt all running threads in non-stop mode, use the -a option."));
3285 c
= add_info ("registers", info_registers_command
, _("\
3286 List of integer registers and their contents, for selected stack frame.\n\
3287 One or more register names as argument means describe the given registers.\n\
3288 One or more register group names as argument means describe the registers\n\
3289 in the named register groups."));
3290 add_info_alias ("r", "registers", 1);
3291 set_cmd_completer (c
, reg_or_group_completer
);
3293 c
= add_info ("all-registers", info_all_registers_command
, _("\
3294 List of all registers and their contents, for selected stack frame.\n\
3295 One or more register names as argument means describe the given registers.\n\
3296 One or more register group names as argument means describe the registers\n\
3297 in the named register groups."));
3298 set_cmd_completer (c
, reg_or_group_completer
);
3300 add_info ("program", info_program_command
,
3301 _("Execution status of the program."));
3303 add_info ("float", info_float_command
,
3304 _("Print the status of the floating point unit."));
3306 add_info ("vector", info_vector_command
,
3307 _("Print the status of the vector unit."));
3309 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3311 Show additional information about a process.\n\
3312 Specify any process id, or use the program being debugged by default."),
3313 &info_proc_cmdlist
, "info proc ",
3314 1/*allow-unknown*/, &infolist
);
3316 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3317 List memory regions mapped by the specified process."),
3318 &info_proc_cmdlist
);
3320 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3321 List process info from /proc/PID/stat."),
3322 &info_proc_cmdlist
);
3324 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3325 List process info from /proc/PID/status."),
3326 &info_proc_cmdlist
);
3328 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3329 List current working directory of the specified process."),
3330 &info_proc_cmdlist
);
3332 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3333 List command line arguments of the specified process."),
3334 &info_proc_cmdlist
);
3336 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3337 List absolute filename for executable of the specified process."),
3338 &info_proc_cmdlist
);
3340 add_cmd ("files", class_info
, info_proc_cmd_files
, _("\
3341 List files opened by the specified process."),
3342 &info_proc_cmdlist
);
3344 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3345 List all available info about the specified process."),
3346 &info_proc_cmdlist
);
3348 add_setshow_boolean_cmd ("finish", class_support
,
3349 &user_print_options
.finish_print
, _("\
3350 Set whether `finish' prints the return value."), _("\
3351 Show whether `finish' prints the return value."), NULL
,
3354 &setprintlist
, &showprintlist
);