1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2022 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"
51 #include "thread-fsm.h"
55 #include "gdbsupport/gdb_optional.h"
57 #include "cli/cli-style.h"
59 /* Local functions: */
61 static void until_next_command (int);
63 static void step_1 (int, int, const char *);
65 #define ERROR_NO_INFERIOR \
66 if (!target_has_execution ()) error (_("The program is not being run."));
68 /* Scratch area where string containing arguments to give to the
69 program will be stored by 'set args'. As soon as anything is
70 stored, notice_args_set will move it into per-inferior storage.
71 Arguments are separated by spaces. Empty string (pointer to '\0')
74 static std::string inferior_args_scratch
;
76 /* Scratch area where the new cwd will be stored by 'set cwd'. */
78 static std::string inferior_cwd_scratch
;
80 /* Scratch area where 'set inferior-tty' will store user-provided value.
81 We'll immediate copy it into per-inferior storage. */
83 static std::string inferior_io_terminal_scratch
;
85 /* Pid of our debugged inferior, or 0 if no inferior now.
86 Since various parts of infrun.c test this to see whether there is a program
87 being debugged it should be nonzero (currently 3 is used) for remote
92 /* Nonzero if stopped due to completion of a stack dummy routine. */
94 enum stop_stack_kind stop_stack_dummy
;
96 /* Nonzero if stopped due to a random (unexpected) signal in inferior
99 int stopped_by_random_signal
;
104 set_inferior_tty_command (const char *args
, int from_tty
,
105 struct cmd_list_element
*c
)
107 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
108 Now route it to current inferior. */
109 current_inferior ()->set_tty (inferior_io_terminal_scratch
);
113 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
114 struct cmd_list_element
*c
, const char *value
)
116 /* Note that we ignore the passed-in value in favor of computing it
118 const std::string
&inferior_tty
= current_inferior ()->tty ();
120 fprintf_filtered (file
,
121 _("Terminal for future runs of program being debugged "
122 "is \"%s\".\n"), inferior_tty
.c_str ());
126 set_inferior_args_vector (int argc
, char **argv
)
128 gdb::array_view
<char * const> args (argv
, argc
);
129 std::string n
= construct_inferior_arguments (args
);
130 current_inferior ()->set_args (std::move (n
));
133 /* Notice when `set args' is run. */
136 set_args_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
138 /* CLI has assigned the user-provided value to inferior_args_scratch.
139 Now route it to current inferior. */
140 current_inferior ()->set_args (inferior_args_scratch
);
143 /* Notice when `show args' is run. */
146 show_args_command (struct ui_file
*file
, int from_tty
,
147 struct cmd_list_element
*c
, const char *value
)
149 /* Note that we ignore the passed-in value in favor of computing it
151 deprecated_show_value_hack (file
, from_tty
, c
,
152 current_inferior ()->args ().c_str ());
155 /* See gdbsupport/common-inferior.h. */
160 return current_inferior ()->cwd ();
163 /* Handle the 'set cwd' command. */
166 set_cwd_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
168 current_inferior ()->set_cwd (inferior_cwd_scratch
);
171 /* Handle the 'show cwd' command. */
174 show_cwd_command (struct ui_file
*file
, int from_tty
,
175 struct cmd_list_element
*c
, const char *value
)
177 const std::string
&cwd
= current_inferior ()->cwd ();
180 fprintf_filtered (file
,
182 You have not set the inferior's current working directory.\n\
183 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
184 server's cwd if remote debugging.\n"));
186 fprintf_filtered (file
,
187 _("Current working directory that will be used "
188 "when starting the inferior is \"%s\".\n"),
193 /* This function strips the '&' character (indicating background
194 execution) that is added as *the last* of the arguments ARGS of a
195 command. A copy of the incoming ARGS without the '&' is returned,
196 unless the resulting string after stripping is empty, in which case
197 NULL is returned. *BG_CHAR_P is an output boolean that indicates
198 whether the '&' character was found. */
200 static gdb::unique_xmalloc_ptr
<char>
201 strip_bg_char (const char *args
, int *bg_char_p
)
205 if (args
== NULL
|| *args
== '\0')
211 p
= args
+ strlen (args
);
215 while (p
> args
&& isspace (p
[-1]))
220 return gdb::unique_xmalloc_ptr
<char>
221 (savestring (args
, p
- args
));
223 return gdb::unique_xmalloc_ptr
<char> (nullptr);
227 return make_unique_xstrdup (args
);
230 /* Common actions to take after creating any sort of inferior, by any
231 means (running, attaching, connecting, et cetera). The target
232 should be stopped. */
235 post_create_inferior (int from_tty
)
238 /* Be sure we own the terminal in case write operations are performed. */
239 target_terminal::ours_for_output ();
241 /* If the target hasn't taken care of this already, do it now.
242 Targets which need to access registers during to_open,
243 to_create_inferior, or to_attach should do it earlier; but many
245 target_find_description ();
247 /* Now that we know the register layout, retrieve current PC. But
248 if the PC is unavailable (e.g., we're opening a core file with
249 missing registers info), ignore it. */
250 thread_info
*thr
= inferior_thread ();
252 thr
->clear_stop_pc ();
255 regcache
*rc
= get_thread_regcache (thr
);
256 thr
->set_stop_pc (regcache_read_pc (rc
));
258 catch (const gdb_exception_error
&ex
)
260 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
264 if (current_program_space
->exec_bfd ())
266 const unsigned solib_add_generation
267 = current_program_space
->solib_add_generation
;
269 scoped_restore restore_in_initial_library_scan
270 = make_scoped_restore (¤t_inferior ()->in_initial_library_scan
,
273 /* Create the hooks to handle shared library load and unload
275 solib_create_inferior_hook (from_tty
);
277 if (current_program_space
->solib_add_generation
== solib_add_generation
)
279 /* The platform-specific hook should load initial shared libraries,
280 but didn't. FROM_TTY will be incorrectly 0 but such solib
281 targets should be fixed anyway. Call it only after the solib
282 target has been initialized by solib_create_inferior_hook. */
285 warning (_("platform-specific solib_create_inferior_hook did "
286 "not load initial shared libraries."));
288 /* If the solist is global across processes, there's no need to
290 if (!gdbarch_has_global_solist (target_gdbarch ()))
291 solib_add (NULL
, 0, auto_solib_add
);
295 /* If the user sets watchpoints before execution having started,
296 then she gets software watchpoints, because GDB can't know which
297 target will end up being pushed, or if it supports hardware
298 watchpoints or not. breakpoint_re_set takes care of promoting
299 watchpoints to hardware watchpoints if possible, however, if this
300 new inferior doesn't load shared libraries or we don't pull in
301 symbols from any other source on this target/arch,
302 breakpoint_re_set is never called. Call it now so that software
303 watchpoints get a chance to be promoted to hardware watchpoints
304 if the now pushed target supports hardware watchpoints. */
305 breakpoint_re_set ();
307 gdb::observers::inferior_created
.notify (current_inferior ());
310 /* Kill the inferior if already running. This function is designed
311 to be called when we are about to start the execution of the program
312 from the beginning. Ask the user to confirm that he wants to restart
313 the program being debugged when FROM_TTY is non-null. */
316 kill_if_already_running (int from_tty
)
318 if (inferior_ptid
!= null_ptid
&& target_has_execution ())
320 /* Bail out before killing the program if we will not be able to
322 target_require_runnable ();
325 && !query (_("The program being debugged has been started already.\n\
326 Start it from the beginning? ")))
327 error (_("Program not restarted."));
332 /* See inferior.h. */
335 prepare_execution_command (struct target_ops
*target
, int background
)
337 /* If we get a request for running in the bg but the target
338 doesn't support it, error out. */
339 if (background
&& !target_can_async_p (target
))
340 error (_("Asynchronous execution not supported on this target."));
344 /* If we get a request for running in the fg, then we need to
345 simulate synchronous (fg) execution. Note no cleanup is
346 necessary for this. stdin is re-enabled whenever an error
347 reaches the top level. */
348 all_uis_on_sync_execution_starting ();
352 /* Determine how the new inferior will behave. */
356 /* Run program without any explicit stop during startup. */
359 /* Stop at the beginning of the program's main function. */
362 /* Stop at the first instruction of the program. */
363 RUN_STOP_AT_FIRST_INSN
366 /* Implement the "run" command. Force a stop during program start if
367 requested by RUN_HOW. */
370 run_command_1 (const char *args
, int from_tty
, enum run_how run_how
)
372 const char *exec_file
;
373 struct ui_out
*uiout
= current_uiout
;
374 struct target_ops
*run_target
;
379 scoped_disable_commit_resumed
disable_commit_resumed ("running");
381 kill_if_already_running (from_tty
);
383 init_wait_for_inferior ();
384 clear_breakpoint_hit_counts ();
386 /* Clean up any leftovers from other runs. Some other things from
387 this function should probably be moved into target_pre_inferior. */
388 target_pre_inferior (from_tty
);
390 /* The comment here used to read, "The exec file is re-read every
391 time we do a generic_mourn_inferior, so we just have to worry
392 about the symbol file." The `generic_mourn_inferior' function
393 gets called whenever the program exits. However, suppose the
394 program exits, and *then* the executable file changes? We need
395 to check again here. Since reopen_exec_file doesn't do anything
396 if the timestamp hasn't changed, I don't see the harm. */
398 reread_symbols (from_tty
);
400 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
401 args
= stripped
.get ();
403 /* Do validation and preparation before possibly changing anything
406 run_target
= find_run_target ();
408 prepare_execution_command (run_target
, async_exec
);
410 if (non_stop
&& !run_target
->supports_non_stop ())
411 error (_("The target does not support running in non-stop mode."));
413 /* Done. Can now set breakpoints, change inferior args, etc. */
415 /* Insert temporary breakpoint in main function if requested. */
416 if (run_how
== RUN_STOP_AT_MAIN
)
418 std::string arg
= string_printf ("-qualified %s", main_name ());
419 tbreak_command (arg
.c_str (), 0);
422 exec_file
= get_exec_file (0);
424 /* We keep symbols from add-symbol-file, on the grounds that the
425 user might want to add some symbols before running the program
426 (right?). But sometimes (dynamic loading where the user manually
427 introduces the new symbols with add-symbol-file), the code which
428 the symbols describe does not persist between runs. Currently
429 the user has to manually nuke all symbols between runs if they
430 want them to go away (PR 2207). This is probably reasonable. */
432 /* If there were other args, beside '&', process them. */
434 current_inferior ()->set_args (args
);
438 uiout
->field_string (NULL
, "Starting program");
441 uiout
->field_string ("execfile", exec_file
);
443 uiout
->field_string ("infargs", current_inferior ()->args ());
448 run_target
->create_inferior (exec_file
,
449 current_inferior ()->args (),
450 current_inferior ()->environment
.envp (),
452 /* to_create_inferior should push the target, so after this point we
453 shouldn't refer to run_target again. */
456 /* We're starting off a new process. When we get out of here, in
457 non-stop mode, finish the state of all threads of that process,
458 but leave other threads alone, as they may be stopped in internal
459 events --- the frontend shouldn't see them as stopped. In
460 all-stop, always finish the state of all threads, as we may be
461 resuming more than just the new process. */
462 process_stratum_target
*finish_target
;
466 finish_target
= current_inferior ()->process_target ();
467 finish_ptid
= ptid_t (current_inferior ()->pid
);
471 finish_target
= nullptr;
472 finish_ptid
= minus_one_ptid
;
474 scoped_finish_thread_state
finish_state (finish_target
, finish_ptid
);
476 /* Pass zero for FROM_TTY, because at this point the "run" command
477 has done its thing; now we are setting up the running program. */
478 post_create_inferior (0);
480 /* Queue a pending event so that the program stops immediately. */
481 if (run_how
== RUN_STOP_AT_FIRST_INSN
)
483 thread_info
*thr
= inferior_thread ();
484 target_waitstatus ws
;
485 ws
.set_stopped (GDB_SIGNAL_0
);
486 thr
->set_pending_waitstatus (ws
);
489 /* Start the target running. Do not use -1 continuation as it would skip
490 breakpoint right at the entry point. */
491 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
493 /* Since there was no error, there's no need to finish the thread
495 finish_state
.release ();
497 disable_commit_resumed
.reset_and_commit ();
501 run_command (const char *args
, int from_tty
)
503 run_command_1 (args
, from_tty
, RUN_NORMAL
);
506 /* Start the execution of the program up until the beginning of the main
510 start_command (const char *args
, int from_tty
)
512 /* Some languages such as Ada need to search inside the program
513 minimal symbols for the location where to put the temporary
514 breakpoint before starting. */
515 if (!have_minimal_symbols ())
516 error (_("No symbol table loaded. Use the \"file\" command."));
518 /* Run the program until reaching the main procedure... */
519 run_command_1 (args
, from_tty
, RUN_STOP_AT_MAIN
);
522 /* Start the execution of the program stopping at the first
526 starti_command (const char *args
, int from_tty
)
528 run_command_1 (args
, from_tty
, RUN_STOP_AT_FIRST_INSN
);
532 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
534 /* We go through all threads individually instead of compressing
535 into a single target `resume_all' request, because some threads
536 may be stopped in internal breakpoints/events, or stopped waiting
537 for its turn in the displaced stepping queue (that is, they are
538 running && !executing). The target side has no idea about why
539 the thread is stopped, so a `resume_all' command would resume too
540 much. If/when GDB gains a way to tell the target `hold this
541 thread stopped until I say otherwise', then we can optimize
543 if (thread
->state
!= THREAD_STOPPED
)
546 if (!thread
->inf
->has_execution ())
549 switch_to_thread (thread
);
550 clear_proceed_status (0);
551 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
556 ensure_valid_thread (void)
558 if (inferior_ptid
== null_ptid
559 || inferior_thread ()->state
== THREAD_EXITED
)
560 error (_("Cannot execute this command without a live selected thread."));
563 /* If the user is looking at trace frames, any resumption of execution
564 is likely to mix up recorded and live target data. So simply
565 disallow those commands. */
568 ensure_not_tfind_mode (void)
570 if (get_traceframe_number () >= 0)
571 error (_("Cannot execute this command while looking at trace frames."));
574 /* Throw an error indicating the current thread is running. */
577 error_is_running (void)
579 error (_("Cannot execute this command while "
580 "the selected thread is running."));
583 /* Calls error_is_running if the current thread is running. */
586 ensure_not_running (void)
588 if (inferior_thread ()->state
== THREAD_RUNNING
)
593 continue_1 (int all_threads
)
596 ensure_not_tfind_mode ();
598 if (non_stop
&& all_threads
)
600 /* Don't error out if the current thread is running, because
601 there may be other stopped threads. */
603 /* Backup current thread and selected frame and restore on scope
605 scoped_restore_current_thread restore_thread
;
606 scoped_disable_commit_resumed disable_commit_resumed
607 ("continue all threads in non-stop");
609 iterate_over_threads (proceed_thread_callback
, NULL
);
611 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
613 /* If all threads in the target were already running,
614 proceed_thread_callback ends up never calling proceed,
615 and so nothing calls this to put the inferior's terminal
616 settings in effect and remove stdin from the event loop,
617 which we must when running a foreground command. E.g.:
621 <all threads are running now>
624 <no thread was resumed, but the inferior now owns the terminal>
626 target_terminal::inferior ();
629 disable_commit_resumed
.reset_and_commit ();
633 ensure_valid_thread ();
634 ensure_not_running ();
635 clear_proceed_status (0);
636 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
640 /* continue [-a] [proceed-count] [&] */
643 continue_command (const char *args
, int from_tty
)
646 bool all_threads_p
= false;
650 /* Find out whether we must run in the background. */
651 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
652 args
= stripped
.get ();
656 if (startswith (args
, "-a"))
658 all_threads_p
= true;
659 args
+= sizeof ("-a") - 1;
665 if (!non_stop
&& all_threads_p
)
666 error (_("`-a' is meaningless in all-stop mode."));
668 if (args
!= NULL
&& all_threads_p
)
669 error (_("Can't resume all threads and specify "
670 "proceed count simultaneously."));
672 /* If we have an argument left, set proceed count of breakpoint we
676 bpstat
*bs
= nullptr;
679 struct thread_info
*tp
;
682 tp
= inferior_thread ();
685 process_stratum_target
*last_target
;
688 get_last_target_status (&last_target
, &last_ptid
, nullptr);
689 tp
= find_thread_ptid (last_target
, last_ptid
);
692 bs
= tp
->control
.stop_bpstat
;
694 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
697 set_ignore_count (num
,
698 parse_and_eval_long (args
) - 1,
700 /* set_ignore_count prints a message ending with a period.
701 So print two spaces before "Continuing.". */
703 printf_filtered (" ");
707 if (!stopped
&& from_tty
)
710 ("Not stopped at any breakpoint; argument ignored.\n");
715 ensure_not_tfind_mode ();
717 if (!non_stop
|| !all_threads_p
)
719 ensure_valid_thread ();
720 ensure_not_running ();
723 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
726 printf_filtered (_("Continuing.\n"));
728 continue_1 (all_threads_p
);
731 /* Record in TP the starting point of a "step" or "next" command. */
734 set_step_frame (thread_info
*tp
)
736 /* This can be removed once this function no longer implicitly relies on the
737 inferior_ptid value. */
738 gdb_assert (inferior_ptid
== tp
->ptid
);
740 frame_info
*frame
= get_current_frame ();
742 symtab_and_line sal
= find_frame_sal (frame
);
743 set_step_info (tp
, frame
, sal
);
745 CORE_ADDR pc
= get_frame_pc (frame
);
746 tp
->control
.step_start_function
= find_pc_function (pc
);
749 /* Step until outside of current statement. */
752 step_command (const char *count_string
, int from_tty
)
754 step_1 (0, 0, count_string
);
757 /* Likewise, but skip over subroutine calls as if single instructions. */
760 next_command (const char *count_string
, int from_tty
)
762 step_1 (1, 0, count_string
);
765 /* Likewise, but step only one instruction. */
768 stepi_command (const char *count_string
, int from_tty
)
770 step_1 (0, 1, count_string
);
774 nexti_command (const char *count_string
, int from_tty
)
776 step_1 (1, 1, count_string
);
779 /* Data for the FSM that manages the step/next/stepi/nexti
782 struct step_command_fsm
: public thread_fsm
784 /* How many steps left in a "step N"-like command. */
787 /* If true, this is a next/nexti, otherwise a step/stepi. */
788 int skip_subroutines
;
790 /* If true, this is a stepi/nexti, otherwise a step/step. */
793 explicit step_command_fsm (struct interp
*cmd_interp
)
794 : thread_fsm (cmd_interp
)
798 void clean_up (struct thread_info
*thread
) override
;
799 bool should_stop (struct thread_info
*thread
) override
;
800 enum async_reply_reason
do_async_reply_reason () override
;
803 /* Prepare for a step/next/etc. command. Any target resource
804 allocated here is undone in the FSM's clean_up method. */
807 step_command_fsm_prepare (struct step_command_fsm
*sm
,
808 int skip_subroutines
, int single_inst
,
809 int count
, struct thread_info
*thread
)
811 sm
->skip_subroutines
= skip_subroutines
;
812 sm
->single_inst
= single_inst
;
815 /* Leave the si command alone. */
816 if (!sm
->single_inst
|| sm
->skip_subroutines
)
817 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
819 thread
->control
.stepping_command
= 1;
822 static int prepare_one_step (thread_info
*, struct step_command_fsm
*sm
);
825 step_1 (int skip_subroutines
, int single_inst
, const char *count_string
)
829 struct thread_info
*thr
;
830 struct step_command_fsm
*step_sm
;
833 ensure_not_tfind_mode ();
834 ensure_valid_thread ();
835 ensure_not_running ();
837 gdb::unique_xmalloc_ptr
<char> stripped
838 = strip_bg_char (count_string
, &async_exec
);
839 count_string
= stripped
.get ();
841 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
843 count
= count_string
? parse_and_eval_long (count_string
) : 1;
845 clear_proceed_status (1);
847 /* Setup the execution command state machine to handle all the COUNT
849 thr
= inferior_thread ();
850 step_sm
= new step_command_fsm (command_interp ());
851 thr
->thread_fsm
= step_sm
;
853 step_command_fsm_prepare (step_sm
, skip_subroutines
,
854 single_inst
, count
, thr
);
856 /* Do only one step for now, before returning control to the event
857 loop. Let the continuation figure out how many other steps we
858 need to do, and handle them one at the time, through
860 if (!prepare_one_step (thr
, step_sm
))
861 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
866 /* Stepped into an inline frame. Pretend that we've
868 thr
->thread_fsm
->clean_up (thr
);
869 proceeded
= normal_stop ();
871 inferior_event_handler (INF_EXEC_COMPLETE
);
872 all_uis_check_sync_execution_done ();
876 /* Implementation of the 'should_stop' FSM method for stepping
877 commands. Called after we are done with one step operation, to
878 check whether we need to step again, before we print the prompt and
879 return control to the user. If count is > 1, returns false, as we
880 will need to keep going. */
883 step_command_fsm::should_stop (struct thread_info
*tp
)
885 if (tp
->control
.stop_step
)
887 /* There are more steps to make, and we did stop due to
888 ending a stepping range. Do another step. */
890 return prepare_one_step (tp
, this);
898 /* Implementation of the 'clean_up' FSM method for stepping commands. */
901 step_command_fsm::clean_up (struct thread_info
*thread
)
903 if (!single_inst
|| skip_subroutines
)
904 delete_longjmp_breakpoint (thread
->global_num
);
907 /* Implementation of the 'async_reply_reason' FSM method for stepping
910 enum async_reply_reason
911 step_command_fsm::do_async_reply_reason ()
913 return EXEC_ASYNC_END_STEPPING_RANGE
;
916 /* Prepare for one step in "step N". The actual target resumption is
917 done by the caller. Return true if we're done and should thus
918 report a stop to the user. Returns false if the target needs to be
922 prepare_one_step (thread_info
*tp
, struct step_command_fsm
*sm
)
924 /* This can be removed once this function no longer implicitly relies on the
925 inferior_ptid value. */
926 gdb_assert (inferior_ptid
== tp
->ptid
);
930 struct frame_info
*frame
= get_current_frame ();
934 if (!sm
->single_inst
)
938 /* Step at an inlined function behaves like "down". */
939 if (!sm
->skip_subroutines
940 && inline_skipped_frames (tp
))
943 const char *fn
= NULL
;
947 /* Pretend that we've ran. */
948 resume_ptid
= user_visible_resume_ptid (1);
949 set_running (tp
->inf
->process_target (), resume_ptid
, true);
951 step_into_inline_frame (tp
);
953 frame
= get_current_frame ();
954 sal
= find_frame_sal (frame
);
955 sym
= get_frame_function (frame
);
958 fn
= sym
->print_name ();
961 || !function_name_is_marked_for_skip (fn
, sal
))
964 return prepare_one_step (tp
, sm
);
968 pc
= get_frame_pc (frame
);
969 find_pc_line_pc_range (pc
,
970 &tp
->control
.step_range_start
,
971 &tp
->control
.step_range_end
);
973 /* There's a problem in gcc (PR gcc/98780) that causes missing line
974 table entries, which results in a too large stepping range.
975 Use inlined_subroutine info to make the range more narrow. */
976 if (inline_skipped_frames (tp
) > 0)
978 symbol
*sym
= inline_skipped_symbol (tp
);
979 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
981 const block
*block
= SYMBOL_BLOCK_VALUE (sym
);
982 if (BLOCK_END (block
) < tp
->control
.step_range_end
)
983 tp
->control
.step_range_end
= BLOCK_END (block
);
987 tp
->control
.may_range_step
= 1;
989 /* If we have no line info, switch to stepi mode. */
990 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
992 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
993 tp
->control
.may_range_step
= 0;
995 else if (tp
->control
.step_range_end
== 0)
999 if (find_pc_partial_function (pc
, &name
,
1000 &tp
->control
.step_range_start
,
1001 &tp
->control
.step_range_end
) == 0)
1002 error (_("Cannot find bounds of current function"));
1004 target_terminal::ours_for_output ();
1005 printf_filtered (_("Single stepping until exit from function %s,"
1006 "\nwhich has no line number information.\n"),
1012 /* Say we are stepping, but stop after one insn whatever it does. */
1013 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1014 if (!sm
->skip_subroutines
)
1016 Don't step over function calls, not even to functions lacking
1018 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1021 if (sm
->skip_subroutines
)
1022 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1028 sm
->set_finished ();
1033 /* Continue program at specified address. */
1036 jump_command (const char *arg
, int from_tty
)
1038 struct gdbarch
*gdbarch
= get_current_arch ();
1045 ensure_not_tfind_mode ();
1046 ensure_valid_thread ();
1047 ensure_not_running ();
1049 /* Find out whether we must run in the background. */
1050 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1051 arg
= stripped
.get ();
1053 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1056 error_no_arg (_("starting address"));
1058 std::vector
<symtab_and_line
> sals
1059 = decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1060 if (sals
.size () != 1)
1061 error (_("Unreasonable jump request"));
1063 symtab_and_line
&sal
= sals
[0];
1065 if (sal
.symtab
== 0 && sal
.pc
== 0)
1066 error (_("No source file has been specified."));
1068 resolve_sal_pc (&sal
); /* May error out. */
1070 /* See if we are trying to jump to another function. */
1071 fn
= get_frame_function (get_current_frame ());
1072 sfn
= find_pc_function (sal
.pc
);
1073 if (fn
!= NULL
&& sfn
!= fn
)
1075 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1078 error (_("Not confirmed."));
1085 struct obj_section
*section
;
1087 fixup_symbol_section (sfn
, 0);
1088 section
= sfn
->obj_section (symbol_objfile (sfn
));
1089 if (section_is_overlay (section
)
1090 && !section_is_mapped (section
))
1092 if (!query (_("WARNING!!! Destination is in "
1093 "unmapped overlay! Jump anyway? ")))
1095 error (_("Not confirmed."));
1105 printf_filtered (_("Continuing at "));
1106 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1107 printf_filtered (".\n");
1110 clear_proceed_status (0);
1111 proceed (addr
, GDB_SIGNAL_0
);
1114 /* Continue program giving it specified signal. */
1117 signal_command (const char *signum_exp
, int from_tty
)
1119 enum gdb_signal oursig
;
1122 dont_repeat (); /* Too dangerous. */
1124 ensure_not_tfind_mode ();
1125 ensure_valid_thread ();
1126 ensure_not_running ();
1128 /* Find out whether we must run in the background. */
1129 gdb::unique_xmalloc_ptr
<char> stripped
1130 = strip_bg_char (signum_exp
, &async_exec
);
1131 signum_exp
= stripped
.get ();
1133 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1136 error_no_arg (_("signal number"));
1138 /* It would be even slicker to make signal names be valid expressions,
1139 (the type could be "enum $signal" or some such), then the user could
1140 assign them to convenience variables. */
1141 oursig
= gdb_signal_from_name (signum_exp
);
1143 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1145 /* No, try numeric. */
1146 int num
= parse_and_eval_long (signum_exp
);
1149 oursig
= GDB_SIGNAL_0
;
1151 oursig
= gdb_signal_from_command (num
);
1154 /* Look for threads other than the current that this command ends up
1155 resuming too (due to schedlock off), and warn if they'll get a
1156 signal delivered. "signal 0" is used to suppress a previous
1157 signal, but if the current thread is no longer the one that got
1158 the signal, then the user is potentially suppressing the signal
1159 of the wrong thread. */
1162 int must_confirm
= 0;
1164 /* This indicates what will be resumed. Either a single thread,
1165 a whole process, or all threads of all processes. */
1166 ptid_t resume_ptid
= user_visible_resume_ptid (0);
1167 process_stratum_target
*resume_target
1168 = user_visible_resume_target (resume_ptid
);
1170 thread_info
*current
= inferior_thread ();
1172 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
1177 if (tp
->stop_signal () != GDB_SIGNAL_0
1178 && signal_pass_state (tp
->stop_signal ()))
1181 printf_unfiltered (_("Note:\n"));
1182 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1183 print_thread_id (tp
),
1184 gdb_signal_to_name (tp
->stop_signal ()),
1185 gdb_signal_to_string (tp
->stop_signal ()));
1191 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1192 "still deliver the signals noted above to their respective threads.\n"
1193 "Continue anyway? "),
1194 print_thread_id (inferior_thread ())))
1195 error (_("Not confirmed."));
1200 if (oursig
== GDB_SIGNAL_0
)
1201 printf_filtered (_("Continuing with no signal.\n"));
1203 printf_filtered (_("Continuing with signal %s.\n"),
1204 gdb_signal_to_name (oursig
));
1207 clear_proceed_status (0);
1208 proceed ((CORE_ADDR
) -1, oursig
);
1211 /* Queue a signal to be delivered to the current thread. */
1214 queue_signal_command (const char *signum_exp
, int from_tty
)
1216 enum gdb_signal oursig
;
1217 struct thread_info
*tp
;
1220 ensure_not_tfind_mode ();
1221 ensure_valid_thread ();
1222 ensure_not_running ();
1224 if (signum_exp
== NULL
)
1225 error_no_arg (_("signal number"));
1227 /* It would be even slicker to make signal names be valid expressions,
1228 (the type could be "enum $signal" or some such), then the user could
1229 assign them to convenience variables. */
1230 oursig
= gdb_signal_from_name (signum_exp
);
1232 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1234 /* No, try numeric. */
1235 int num
= parse_and_eval_long (signum_exp
);
1238 oursig
= GDB_SIGNAL_0
;
1240 oursig
= gdb_signal_from_command (num
);
1243 if (oursig
!= GDB_SIGNAL_0
1244 && !signal_pass_state (oursig
))
1245 error (_("Signal handling set to not pass this signal to the program."));
1247 tp
= inferior_thread ();
1248 tp
->set_stop_signal (oursig
);
1251 /* Data for the FSM that manages the until (with no argument)
1254 struct until_next_fsm
: public thread_fsm
1256 /* The thread that as current when the command was executed. */
1259 until_next_fsm (struct interp
*cmd_interp
, int thread
)
1260 : thread_fsm (cmd_interp
),
1265 bool should_stop (struct thread_info
*thread
) override
;
1266 void clean_up (struct thread_info
*thread
) override
;
1267 enum async_reply_reason
do_async_reply_reason () override
;
1270 /* Implementation of the 'should_stop' FSM method for the until (with
1274 until_next_fsm::should_stop (struct thread_info
*tp
)
1276 if (tp
->control
.stop_step
)
1282 /* Implementation of the 'clean_up' FSM method for the until (with no
1286 until_next_fsm::clean_up (struct thread_info
*thread
)
1288 delete_longjmp_breakpoint (thread
->global_num
);
1291 /* Implementation of the 'async_reply_reason' FSM method for the until
1292 (with no arg) command. */
1294 enum async_reply_reason
1295 until_next_fsm::do_async_reply_reason ()
1297 return EXEC_ASYNC_END_STEPPING_RANGE
;
1300 /* Proceed until we reach a different source line with pc greater than
1301 our current one or exit the function. We skip calls in both cases.
1303 Note that eventually this command should probably be changed so
1304 that only source lines are printed out when we hit the breakpoint
1305 we set. This may involve changes to wait_for_inferior and the
1306 proceed status code. */
1309 until_next_command (int from_tty
)
1311 struct frame_info
*frame
;
1313 struct symbol
*func
;
1314 struct symtab_and_line sal
;
1315 struct thread_info
*tp
= inferior_thread ();
1316 int thread
= tp
->global_num
;
1317 struct until_next_fsm
*sm
;
1319 clear_proceed_status (0);
1320 set_step_frame (tp
);
1322 frame
= get_current_frame ();
1324 /* Step until either exited from this function or greater
1325 than the current line (if in symbolic section) or pc (if
1328 pc
= get_frame_pc (frame
);
1329 func
= find_pc_function (pc
);
1333 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1335 if (msymbol
.minsym
== NULL
)
1336 error (_("Execution is not within a known function."));
1338 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1339 /* The upper-bound of step_range is exclusive. In order to make PC
1340 within the range, set the step_range_end with PC + 1. */
1341 tp
->control
.step_range_end
= pc
+ 1;
1345 sal
= find_pc_line (pc
, 0);
1347 tp
->control
.step_range_start
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func
));
1348 tp
->control
.step_range_end
= sal
.end
;
1350 tp
->control
.may_range_step
= 1;
1352 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1354 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1355 delete_longjmp_breakpoint_cleanup
lj_deleter (thread
);
1357 sm
= new until_next_fsm (command_interp (), tp
->global_num
);
1358 tp
->thread_fsm
= sm
;
1359 lj_deleter
.release ();
1361 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1365 until_command (const char *arg
, int from_tty
)
1370 ensure_not_tfind_mode ();
1371 ensure_valid_thread ();
1372 ensure_not_running ();
1374 /* Find out whether we must run in the background. */
1375 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1376 arg
= stripped
.get ();
1378 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1381 until_break_command (arg
, from_tty
, 0);
1383 until_next_command (from_tty
);
1387 advance_command (const char *arg
, int from_tty
)
1392 ensure_not_tfind_mode ();
1393 ensure_valid_thread ();
1394 ensure_not_running ();
1397 error_no_arg (_("a location"));
1399 /* Find out whether we must run in the background. */
1400 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1401 arg
= stripped
.get ();
1403 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1405 until_break_command (arg
, from_tty
, 1);
1408 /* Return the value of the result of a function at the end of a 'finish'
1409 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1410 right after an inferior call has finished. */
1413 get_return_value (struct value
*function
, struct type
*value_type
)
1415 regcache
*stop_regs
= get_current_regcache ();
1416 struct gdbarch
*gdbarch
= stop_regs
->arch ();
1417 struct value
*value
;
1419 value_type
= check_typedef (value_type
);
1420 gdb_assert (value_type
->code () != TYPE_CODE_VOID
);
1422 /* FIXME: 2003-09-27: When returning from a nested inferior function
1423 call, it's possible (with no help from the architecture vector)
1424 to locate and return/print a "struct return" value. This is just
1425 a more complicated case of what is already being done in the
1426 inferior function call code. In fact, when inferior function
1427 calls are made async, this will likely be made the norm. */
1429 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1432 case RETURN_VALUE_REGISTER_CONVENTION
:
1433 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1434 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1435 value
= allocate_value (value_type
);
1436 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1437 value_contents_raw (value
).data (), NULL
);
1439 case RETURN_VALUE_STRUCT_CONVENTION
:
1443 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1449 /* The captured function return value/type and its position in the
1452 struct return_value_info
1454 /* The captured return value. May be NULL if we weren't able to
1455 retrieve it. See get_return_value. */
1456 struct value
*value
;
1458 /* The return type. In some cases, we'll not be able extract the
1459 return value, but we always know the type. */
1462 /* If we captured a value, this is the value history index. */
1463 int value_history_index
;
1466 /* Helper for print_return_value. */
1469 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1471 if (rv
->value
!= NULL
)
1473 struct value_print_options opts
;
1476 uiout
->text ("Value returned is ");
1477 uiout
->field_fmt ("gdb-result-var", "$%d",
1478 rv
->value_history_index
);
1479 uiout
->text (" = ");
1480 get_user_print_options (&opts
);
1482 if (opts
.finish_print
)
1485 value_print (rv
->value
, &stb
, &opts
);
1486 uiout
->field_stream ("return-value", stb
);
1489 uiout
->field_string ("return-value", _("<not displayed>"),
1490 metadata_style
.style ());
1495 std::string type_name
= type_to_string (rv
->type
);
1496 uiout
->text ("Value returned has type: ");
1497 uiout
->field_string ("return-type", type_name
);
1499 uiout
->text (" Cannot determine contents\n");
1503 /* Print the result of a function at the end of a 'finish' command.
1504 RV points at an object representing the captured return value/type
1505 and its position in the value history. */
1508 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1510 if (rv
->type
== NULL
1511 || check_typedef (rv
->type
)->code () == TYPE_CODE_VOID
)
1516 /* print_return_value_1 can throw an exception in some
1517 circumstances. We need to catch this so that we still
1518 delete the breakpoint. */
1519 print_return_value_1 (uiout
, rv
);
1521 catch (const gdb_exception
&ex
)
1523 exception_print (gdb_stdout
, ex
);
1527 /* Data for the FSM that manages the finish command. */
1529 struct finish_command_fsm
: public thread_fsm
1531 /* The momentary breakpoint set at the function's return address in
1533 breakpoint_up breakpoint
;
1535 /* The function that we're stepping out of. */
1536 struct symbol
*function
= nullptr;
1538 /* If the FSM finishes successfully, this stores the function's
1540 struct return_value_info return_value_info
{};
1542 explicit finish_command_fsm (struct interp
*cmd_interp
)
1543 : thread_fsm (cmd_interp
)
1547 bool should_stop (struct thread_info
*thread
) override
;
1548 void clean_up (struct thread_info
*thread
) override
;
1549 struct return_value_info
*return_value () override
;
1550 enum async_reply_reason
do_async_reply_reason () override
;
1553 /* Implementation of the 'should_stop' FSM method for the finish
1554 commands. Detects whether the thread stepped out of the function
1555 successfully, and if so, captures the function's return value and
1556 marks the FSM finished. */
1559 finish_command_fsm::should_stop (struct thread_info
*tp
)
1561 struct return_value_info
*rv
= &return_value_info
;
1563 if (function
!= NULL
1564 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1565 breakpoint
.get ()) != NULL
)
1570 rv
->type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1571 if (rv
->type
== NULL
)
1572 internal_error (__FILE__
, __LINE__
,
1573 _("finish_command: function has no target type"));
1575 if (check_typedef (rv
->type
)->code () != TYPE_CODE_VOID
)
1579 func
= read_var_value (function
, NULL
, get_current_frame ());
1580 rv
->value
= get_return_value (func
, rv
->type
);
1581 if (rv
->value
!= NULL
)
1582 rv
->value_history_index
= record_latest_value (rv
->value
);
1585 else if (tp
->control
.stop_step
)
1587 /* Finishing from an inline frame, or reverse finishing. In
1588 either case, there's no way to retrieve the return value. */
1595 /* Implementation of the 'clean_up' FSM method for the finish
1599 finish_command_fsm::clean_up (struct thread_info
*thread
)
1601 breakpoint
.reset ();
1602 delete_longjmp_breakpoint (thread
->global_num
);
1605 /* Implementation of the 'return_value' FSM method for the finish
1608 struct return_value_info
*
1609 finish_command_fsm::return_value ()
1611 return &return_value_info
;
1614 /* Implementation of the 'async_reply_reason' FSM method for the
1617 enum async_reply_reason
1618 finish_command_fsm::do_async_reply_reason ()
1620 if (execution_direction
== EXEC_REVERSE
)
1621 return EXEC_ASYNC_END_STEPPING_RANGE
;
1623 return EXEC_ASYNC_FUNCTION_FINISHED
;
1626 /* finish_backward -- helper function for finish_command. */
1629 finish_backward (struct finish_command_fsm
*sm
)
1631 struct symtab_and_line sal
;
1632 struct thread_info
*tp
= inferior_thread ();
1634 CORE_ADDR func_addr
;
1636 pc
= get_frame_pc (get_current_frame ());
1638 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1639 error (_("Cannot find bounds of current function"));
1641 sal
= find_pc_line (func_addr
, 0);
1643 tp
->control
.proceed_to_finish
= 1;
1644 /* Special case: if we're sitting at the function entry point,
1645 then all we need to do is take a reverse singlestep. We
1646 don't need to set a breakpoint, and indeed it would do us
1649 Note that this can only happen at frame #0, since there's
1650 no way that a function up the stack can have a return address
1651 that's equal to its entry point. */
1655 struct frame_info
*frame
= get_selected_frame (NULL
);
1656 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1658 /* Set a step-resume at the function's entry point. Once that's
1659 hit, we'll do one more step backwards. */
1660 symtab_and_line sr_sal
;
1662 sr_sal
.pspace
= get_frame_program_space (frame
);
1663 insert_step_resume_breakpoint_at_sal (gdbarch
,
1664 sr_sal
, null_frame_id
);
1666 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1670 /* We're almost there -- we just need to back up by one more
1672 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1673 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1677 /* finish_forward -- helper function for finish_command. FRAME is the
1678 frame that called the function we're about to step out of. */
1681 finish_forward (struct finish_command_fsm
*sm
, struct frame_info
*frame
)
1683 struct frame_id frame_id
= get_frame_id (frame
);
1684 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1685 struct symtab_and_line sal
;
1686 struct thread_info
*tp
= inferior_thread ();
1688 sal
= find_pc_line (get_frame_pc (frame
), 0);
1689 sal
.pc
= get_frame_pc (frame
);
1691 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1692 get_stack_frame_id (frame
),
1695 /* set_momentary_breakpoint invalidates FRAME. */
1698 set_longjmp_breakpoint (tp
, frame_id
);
1700 /* We want to print return value, please... */
1701 tp
->control
.proceed_to_finish
= 1;
1703 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1706 /* Skip frames for "finish". */
1708 static struct frame_info
*
1709 skip_finish_frames (struct frame_info
*frame
)
1711 struct frame_info
*start
;
1717 frame
= skip_tailcall_frames (frame
);
1721 frame
= skip_unwritable_frames (frame
);
1725 while (start
!= frame
);
1730 /* "finish": Set a temporary breakpoint at the place the selected
1731 frame will return to, then continue. */
1734 finish_command (const char *arg
, int from_tty
)
1736 struct frame_info
*frame
;
1738 struct finish_command_fsm
*sm
;
1739 struct thread_info
*tp
;
1742 ensure_not_tfind_mode ();
1743 ensure_valid_thread ();
1744 ensure_not_running ();
1746 /* Find out whether we must run in the background. */
1747 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1748 arg
= stripped
.get ();
1750 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1753 error (_("The \"finish\" command does not take any arguments."));
1755 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1757 error (_("\"finish\" not meaningful in the outermost frame."));
1759 clear_proceed_status (0);
1761 tp
= inferior_thread ();
1763 sm
= new finish_command_fsm (command_interp ());
1765 tp
->thread_fsm
= sm
;
1767 /* Finishing from an inline frame is completely different. We don't
1768 try to show the "return value" - no way to locate it. */
1769 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1772 /* Claim we are stepping in the calling frame. An empty step
1773 range means that we will stop once we aren't in a function
1774 called by that frame. We don't use the magic "1" value for
1775 step_range_end, because then infrun will think this is nexti,
1776 and not step over the rest of this inlined function call. */
1777 set_step_info (tp
, frame
, {});
1778 tp
->control
.step_range_start
= get_frame_pc (frame
);
1779 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1780 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1782 /* Print info on the selected frame, including level number but not
1786 printf_filtered (_("Run till exit from "));
1787 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1790 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1794 /* Find the function we will return from. */
1796 sm
->function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1798 /* Print info on the selected frame, including level number but not
1802 if (execution_direction
== EXEC_REVERSE
)
1803 printf_filtered (_("Run back to call of "));
1806 if (sm
->function
!= NULL
&& TYPE_NO_RETURN (sm
->function
->type
)
1807 && !query (_("warning: Function %s does not return normally.\n"
1808 "Try to finish anyway? "),
1809 sm
->function
->print_name ()))
1810 error (_("Not confirmed."));
1811 printf_filtered (_("Run till exit from "));
1814 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1817 if (execution_direction
== EXEC_REVERSE
)
1818 finish_backward (sm
);
1821 frame
= skip_finish_frames (frame
);
1824 error (_("Cannot find the caller frame."));
1826 finish_forward (sm
, frame
);
1832 info_program_command (const char *args
, int from_tty
)
1837 process_stratum_target
*proc_target
;
1839 if (!target_has_execution ())
1841 printf_filtered (_("The program being debugged is not being run.\n"));
1847 ptid
= inferior_ptid
;
1848 proc_target
= current_inferior ()->process_target ();
1851 get_last_target_status (&proc_target
, &ptid
, nullptr);
1853 if (ptid
== null_ptid
|| ptid
== minus_one_ptid
)
1854 error (_("No selected thread."));
1856 thread_info
*tp
= find_thread_ptid (proc_target
, ptid
);
1858 if (tp
->state
== THREAD_EXITED
)
1859 error (_("Invalid selected thread."));
1860 else if (tp
->state
== THREAD_RUNNING
)
1861 error (_("Selected thread is running."));
1863 bs
= tp
->control
.stop_bpstat
;
1864 stat
= bpstat_num (&bs
, &num
);
1866 target_files_info ();
1867 printf_filtered (_("Program stopped at %s.\n"),
1868 paddress (target_gdbarch (), tp
->stop_pc ()));
1869 if (tp
->control
.stop_step
)
1870 printf_filtered (_("It stopped after being stepped.\n"));
1873 /* There may be several breakpoints in the same place, so this
1874 isn't as strange as it seems. */
1879 printf_filtered (_("It stopped at a breakpoint "
1880 "that has since been deleted.\n"));
1883 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1884 stat
= bpstat_num (&bs
, &num
);
1887 else if (tp
->stop_signal () != GDB_SIGNAL_0
)
1889 printf_filtered (_("It stopped with signal %s, %s.\n"),
1890 gdb_signal_to_name (tp
->stop_signal ()),
1891 gdb_signal_to_string (tp
->stop_signal ()));
1896 printf_filtered (_("Type \"info stack\" or \"info "
1897 "registers\" for more information.\n"));
1902 environment_info (const char *var
, int from_tty
)
1906 const char *val
= current_inferior ()->environment
.get (var
);
1910 puts_filtered (var
);
1911 puts_filtered (" = ");
1912 puts_filtered (val
);
1913 puts_filtered ("\n");
1917 puts_filtered ("Environment variable \"");
1918 puts_filtered (var
);
1919 puts_filtered ("\" not defined.\n");
1924 char **envp
= current_inferior ()->environment
.envp ();
1926 for (int idx
= 0; envp
[idx
] != NULL
; ++idx
)
1928 puts_filtered (envp
[idx
]);
1929 puts_filtered ("\n");
1935 set_environment_command (const char *arg
, int from_tty
)
1937 const char *p
, *val
;
1941 error_no_arg (_("environment variable and value"));
1943 /* Find separation between variable name and value. */
1944 p
= (char *) strchr (arg
, '=');
1945 val
= (char *) strchr (arg
, ' ');
1947 if (p
!= 0 && val
!= 0)
1949 /* We have both a space and an equals. If the space is before the
1950 equals, walk forward over the spaces til we see a nonspace
1951 (possibly the equals). */
1956 /* Now if the = is after the char following the spaces,
1957 take the char following the spaces. */
1961 else if (val
!= 0 && p
== 0)
1965 error_no_arg (_("environment variable to set"));
1967 if (p
== 0 || p
[1] == 0)
1971 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
1975 /* Not setting variable value to null. */
1977 while (*val
== ' ' || *val
== '\t')
1981 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1984 std::string
var (arg
, p
- arg
);
1987 printf_filtered (_("Setting environment variable "
1988 "\"%s\" to null value.\n"),
1990 current_inferior ()->environment
.set (var
.c_str (), "");
1993 current_inferior ()->environment
.set (var
.c_str (), val
);
1997 unset_environment_command (const char *var
, int from_tty
)
2001 /* If there is no argument, delete all environment variables.
2002 Ask for confirmation if reading from the terminal. */
2003 if (!from_tty
|| query (_("Delete all environment variables? ")))
2004 current_inferior ()->environment
.clear ();
2007 current_inferior ()->environment
.unset (var
);
2010 /* Handle the execution path (PATH variable). */
2012 static const char path_var_name
[] = "PATH";
2015 path_info (const char *args
, int from_tty
)
2017 puts_filtered ("Executable and object file path: ");
2018 puts_filtered (current_inferior ()->environment
.get (path_var_name
));
2019 puts_filtered ("\n");
2022 /* Add zero or more directories to the front of the execution path. */
2025 path_command (const char *dirname
, int from_tty
)
2030 env
= current_inferior ()->environment
.get (path_var_name
);
2031 /* Can be null if path is not set. */
2034 std::string exec_path
= env
;
2035 mod_path (dirname
, exec_path
);
2036 current_inferior ()->environment
.set (path_var_name
, exec_path
.c_str ());
2038 path_info (NULL
, from_tty
);
2043 pad_to_column (string_file
&stream
, int col
)
2045 /* At least one space must be printed to separate columns. */
2047 const int size
= stream
.size ();
2049 stream
.puts (n_spaces (col
- size
));
2052 /* Print out the register NAME with value VAL, to FILE, in the default
2056 default_print_one_register_info (struct ui_file
*file
,
2060 struct type
*regtype
= value_type (val
);
2061 int print_raw_format
;
2062 string_file format_stream
;
2065 value_column_1
= 15,
2066 /* Give enough room for "0x", 16 hex digits and two spaces in
2067 preceding column. */
2068 value_column_2
= value_column_1
+ 2 + 16 + 2,
2071 format_stream
.puts (name
);
2072 pad_to_column (format_stream
, value_column_1
);
2074 print_raw_format
= (value_entirely_available (val
)
2075 && !value_optimized_out (val
));
2077 /* If virtual format is floating, print it that way, and in raw
2079 if (regtype
->code () == TYPE_CODE_FLT
2080 || regtype
->code () == TYPE_CODE_DECFLOAT
)
2082 struct value_print_options opts
;
2083 const gdb_byte
*valaddr
= value_contents_for_printing (val
).data ();
2084 enum bfd_endian byte_order
= type_byte_order (regtype
);
2086 get_user_print_options (&opts
);
2089 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2091 if (print_raw_format
)
2093 pad_to_column (format_stream
, value_column_2
);
2094 format_stream
.puts ("(raw ");
2095 print_hex_chars (&format_stream
, valaddr
, TYPE_LENGTH (regtype
),
2097 format_stream
.putc (')');
2102 struct value_print_options opts
;
2104 /* Print the register in hex. */
2105 get_formatted_print_options (&opts
, 'x');
2107 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2108 /* If not a vector register, print it also according to its
2110 if (print_raw_format
&& regtype
->is_vector () == 0)
2112 pad_to_column (format_stream
, value_column_2
);
2113 get_user_print_options (&opts
);
2115 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2119 fputs_filtered (format_stream
.c_str (), file
);
2120 fprintf_filtered (file
, "\n");
2123 /* Print out the machine register regnum. If regnum is -1, print all
2124 registers (print_all == 1) or all non-float and non-vector
2125 registers (print_all == 0).
2127 For most machines, having all_registers_info() print the
2128 register(s) one per line is good enough. If a different format is
2129 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2130 regs), or there is an existing convention for showing all the
2131 registers, define the architecture method PRINT_REGISTERS_INFO to
2132 provide that format. */
2135 default_print_registers_info (struct gdbarch
*gdbarch
,
2136 struct ui_file
*file
,
2137 struct frame_info
*frame
,
2138 int regnum
, int print_all
)
2141 const int numregs
= gdbarch_num_cooked_regs (gdbarch
);
2143 for (i
= 0; i
< numregs
; i
++)
2145 /* Decide between printing all regs, non-float / vector regs, or
2151 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2156 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2166 /* If the register name is empty, it is undefined for this
2167 processor, so don't display anything. */
2168 if (gdbarch_register_name (gdbarch
, i
) == NULL
2169 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2172 default_print_one_register_info (file
,
2173 gdbarch_register_name (gdbarch
, i
),
2174 value_of_register (i
, frame
));
2179 registers_info (const char *addr_exp
, int fpregs
)
2181 struct frame_info
*frame
;
2182 struct gdbarch
*gdbarch
;
2184 if (!target_has_registers ())
2185 error (_("The program has no registers now."));
2186 frame
= get_selected_frame (NULL
);
2187 gdbarch
= get_frame_arch (frame
);
2191 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2196 while (*addr_exp
!= '\0')
2201 /* Skip leading white space. */
2202 addr_exp
= skip_spaces (addr_exp
);
2204 /* Discard any leading ``$''. Check that there is something
2205 resembling a register following it. */
2206 if (addr_exp
[0] == '$')
2208 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2209 error (_("Missing register name"));
2211 /* Find the start/end of this register name/num/group. */
2213 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2217 /* Figure out what we've found and display it. */
2219 /* A register name? */
2221 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2225 /* User registers lie completely outside of the range of
2226 normal registers. Catch them early so that the target
2228 if (regnum
>= gdbarch_num_cooked_regs (gdbarch
))
2230 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2231 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2234 /* Print in the same fashion
2235 gdbarch_print_registers_info's default
2236 implementation prints. */
2237 default_print_one_register_info (gdb_stdout
,
2242 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2243 frame
, regnum
, fpregs
);
2248 /* A register group? */
2250 struct reggroup
*group
;
2252 for (group
= reggroup_next (gdbarch
, NULL
);
2254 group
= reggroup_next (gdbarch
, group
))
2256 /* Don't bother with a length check. Should the user
2257 enter a short register group name, go with the first
2258 group that matches. */
2259 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2267 regnum
< gdbarch_num_cooked_regs (gdbarch
);
2270 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2271 gdbarch_print_registers_info (gdbarch
,
2279 /* Nothing matched. */
2280 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2285 info_all_registers_command (const char *addr_exp
, int from_tty
)
2287 registers_info (addr_exp
, 1);
2291 info_registers_command (const char *addr_exp
, int from_tty
)
2293 registers_info (addr_exp
, 0);
2297 print_vector_info (struct ui_file
*file
,
2298 struct frame_info
*frame
, const char *args
)
2300 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2302 if (gdbarch_print_vector_info_p (gdbarch
))
2303 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2307 int printed_something
= 0;
2309 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2311 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2313 printed_something
= 1;
2314 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2317 if (!printed_something
)
2318 fprintf_filtered (file
, "No vector information\n");
2323 info_vector_command (const char *args
, int from_tty
)
2325 if (!target_has_registers ())
2326 error (_("The program has no registers now."));
2328 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2331 /* Kill the inferior process. Make us have no inferior. */
2334 kill_command (const char *arg
, int from_tty
)
2336 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2337 It should be a distinct flag that indicates that a target is active, cuz
2338 some targets don't have processes! */
2340 if (inferior_ptid
== null_ptid
)
2341 error (_("The program is not being run."));
2342 if (!query (_("Kill the program being debugged? ")))
2343 error (_("Not confirmed."));
2345 int pid
= current_inferior ()->pid
;
2346 /* Save the pid as a string before killing the inferior, since that
2347 may unpush the current target, and we need the string after. */
2348 std::string pid_str
= target_pid_to_str (ptid_t (pid
));
2349 int infnum
= current_inferior ()->num
;
2352 bfd_cache_close_all ();
2354 if (print_inferior_events
)
2355 printf_filtered (_("[Inferior %d (%s) killed]\n"),
2356 infnum
, pid_str
.c_str ());
2359 /* Used in `attach&' command. Proceed threads of inferior INF iff
2360 they stopped due to debugger request, and when they did, they
2361 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2362 have been explicitly been told to stop. */
2365 proceed_after_attach (inferior
*inf
)
2367 /* Don't error out if the current thread is running, because
2368 there may be other stopped threads. */
2370 /* Backup current thread and selected frame. */
2371 scoped_restore_current_thread restore_thread
;
2373 for (thread_info
*thread
: inf
->non_exited_threads ())
2374 if (!thread
->executing ()
2375 && !thread
->stop_requested
2376 && thread
->stop_signal () == GDB_SIGNAL_0
)
2378 switch_to_thread (thread
);
2379 clear_proceed_status (0);
2380 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2384 /* See inferior.h. */
2387 setup_inferior (int from_tty
)
2389 struct inferior
*inferior
;
2391 inferior
= current_inferior ();
2392 inferior
->needs_setup
= 0;
2394 /* If no exec file is yet known, try to determine it from the
2396 if (get_exec_file (0) == NULL
)
2397 exec_file_locate_attach (inferior_ptid
.pid (), 1, from_tty
);
2400 reopen_exec_file ();
2401 reread_symbols (from_tty
);
2404 /* Take any necessary post-attaching actions for this platform. */
2405 target_post_attach (inferior_ptid
.pid ());
2407 post_create_inferior (from_tty
);
2410 /* What to do after the first program stops after attaching. */
2411 enum attach_post_wait_mode
2413 /* Do nothing. Leaves threads as they are. */
2414 ATTACH_POST_WAIT_NOTHING
,
2416 /* Re-resume threads that are marked running. */
2417 ATTACH_POST_WAIT_RESUME
,
2419 /* Stop all threads. */
2420 ATTACH_POST_WAIT_STOP
,
2423 /* Called after we've attached to a process and we've seen it stop for
2424 the first time. Resume, stop, or don't touch the threads according
2428 attach_post_wait (int from_tty
, enum attach_post_wait_mode mode
)
2430 struct inferior
*inferior
;
2432 inferior
= current_inferior ();
2433 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2435 if (inferior
->needs_setup
)
2436 setup_inferior (from_tty
);
2438 if (mode
== ATTACH_POST_WAIT_RESUME
)
2440 /* The user requested an `attach&', so be sure to leave threads
2441 that didn't get a signal running. */
2443 /* Immediately resume all suspended threads of this inferior,
2444 and this inferior only. This should have no effect on
2445 already running threads. If a thread has been stopped with a
2446 signal, leave it be. */
2448 proceed_after_attach (inferior
);
2451 if (inferior_thread ()->stop_signal () == GDB_SIGNAL_0
)
2453 clear_proceed_status (0);
2454 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2458 else if (mode
== ATTACH_POST_WAIT_STOP
)
2460 /* The user requested a plain `attach', so be sure to leave
2461 the inferior stopped. */
2463 /* At least the current thread is already stopped. */
2465 /* In all-stop, by definition, all threads have to be already
2466 stopped at this point. In non-stop, however, although the
2467 selected thread is stopped, others may still be executing.
2468 Be sure to explicitly stop all threads of the process. This
2469 should have no effect on already stopped threads. */
2471 target_stop (ptid_t (inferior
->pid
));
2472 else if (target_is_non_stop_p ())
2474 struct thread_info
*lowest
= inferior_thread ();
2476 stop_all_threads ();
2478 /* It's not defined which thread will report the attach
2479 stop. For consistency, always select the thread with
2480 lowest GDB number, which should be the main thread, if it
2482 for (thread_info
*thread
: current_inferior ()->non_exited_threads ())
2483 if (thread
->inf
->num
< lowest
->inf
->num
2484 || thread
->per_inf_num
< lowest
->per_inf_num
)
2487 switch_to_thread (lowest
);
2490 /* Tell the user/frontend where we're stopped. */
2492 if (deprecated_attach_hook
)
2493 deprecated_attach_hook ();
2497 /* "attach" command entry point. Takes a program started up outside
2498 of gdb and ``attaches'' to it. This stops it cold in its tracks
2499 and allows us to start debugging it. */
2502 attach_command (const char *args
, int from_tty
)
2505 struct target_ops
*attach_target
;
2506 struct inferior
*inferior
= current_inferior ();
2507 enum attach_post_wait_mode mode
;
2509 dont_repeat (); /* Not for the faint of heart */
2511 scoped_disable_commit_resumed
disable_commit_resumed ("attaching");
2513 if (gdbarch_has_global_solist (target_gdbarch ()))
2514 /* Don't complain if all processes share the same symbol
2517 else if (target_has_execution ())
2519 if (query (_("A program is being debugged already. Kill it? ")))
2522 error (_("Not killed."));
2525 /* Clean up any leftovers from other runs. Some other things from
2526 this function should probably be moved into target_pre_inferior. */
2527 target_pre_inferior (from_tty
);
2529 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
2530 args
= stripped
.get ();
2532 attach_target
= find_attach_target ();
2534 prepare_execution_command (attach_target
, async_exec
);
2536 if (non_stop
&& !attach_target
->supports_non_stop ())
2537 error (_("Cannot attach to this target in non-stop mode"));
2539 attach_target
->attach (args
, from_tty
);
2540 /* to_attach should push the target, so after this point we
2541 shouldn't refer to attach_target again. */
2542 attach_target
= NULL
;
2544 /* Set up the "saved terminal modes" of the inferior
2545 based on what modes we are starting it with. */
2546 target_terminal::init ();
2548 /* Install inferior's terminal modes. This may look like a no-op,
2549 as we've just saved them above, however, this does more than
2550 restore terminal settings:
2552 - installs a SIGINT handler that forwards SIGINT to the inferior.
2553 Otherwise a Ctrl-C pressed just while waiting for the initial
2554 stop would end up as a spurious Quit.
2556 - removes stdin from the event loop, which we need if attaching
2557 in the foreground, otherwise on targets that report an initial
2558 stop on attach (which are most) we'd process input/commands
2559 while we're in the event loop waiting for that stop. That is,
2560 before the attach continuation runs and the command is really
2562 target_terminal::inferior ();
2564 /* Set up execution context to know that we should return from
2565 wait_for_inferior as soon as the target reports a stop. */
2566 init_wait_for_inferior ();
2568 inferior
->needs_setup
= 1;
2570 if (target_is_non_stop_p ())
2572 /* If we find that the current thread isn't stopped, explicitly
2573 do so now, because we're going to install breakpoints and
2577 /* The user requested an `attach&'; stop just one thread. */
2578 target_stop (inferior_ptid
);
2580 /* The user requested an `attach', so stop all threads of this
2582 target_stop (ptid_t (inferior_ptid
.pid ()));
2585 /* Check for exec file mismatch, and let the user solve it. */
2586 validate_exec_file (from_tty
);
2588 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2590 /* Some system don't generate traps when attaching to inferior.
2591 E.g. Mach 3 or GNU hurd. */
2592 if (!target_attach_no_wait ())
2594 /* Careful here. See comments in inferior.h. Basically some
2595 OSes don't ignore SIGSTOPs on continue requests anymore. We
2596 need a way for handle_inferior_event to reset the stop_signal
2597 variable after an attach, and this is what
2598 STOP_QUIETLY_NO_SIGSTOP is for. */
2599 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2601 /* Wait for stop. */
2602 inferior
->add_continuation ([=] ()
2604 attach_post_wait (from_tty
, mode
);
2607 /* Let infrun consider waiting for events out of this
2609 inferior
->process_target ()->threads_executing
= true;
2611 if (!target_is_async_p ())
2612 mark_infrun_async_event_handler ();
2616 attach_post_wait (from_tty
, mode
);
2618 disable_commit_resumed
.reset_and_commit ();
2621 /* We had just found out that the target was already attached to an
2622 inferior. PTID points at a thread of this new inferior, that is
2623 the most likely to be stopped right now, but not necessarily so.
2624 The new inferior is assumed to be already added to the inferior
2625 list at this point. If LEAVE_RUNNING, then leave the threads of
2626 this inferior running, except those we've explicitly seen reported
2630 notice_new_inferior (thread_info
*thr
, bool leave_running
, int from_tty
)
2632 enum attach_post_wait_mode mode
2633 = leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2635 gdb::optional
<scoped_restore_current_thread
> restore_thread
;
2637 if (inferior_ptid
!= null_ptid
)
2638 restore_thread
.emplace ();
2640 /* Avoid reading registers -- we haven't fetched the target
2642 switch_to_thread_no_regs (thr
);
2644 /* When we "notice" a new inferior we need to do all the things we
2645 would normally do if we had just attached to it. */
2647 if (thr
->executing ())
2649 struct inferior
*inferior
= current_inferior ();
2651 /* We're going to install breakpoints, and poke at memory,
2652 ensure that the inferior is stopped for a moment while we do
2654 target_stop (inferior_ptid
);
2656 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2658 /* Wait for stop before proceeding. */
2659 inferior
->add_continuation ([=] ()
2661 attach_post_wait (from_tty
, mode
);
2667 attach_post_wait (from_tty
, mode
);
2672 * takes a program previously attached to and detaches it.
2673 * The program resumes execution and will no longer stop
2674 * on signals, etc. We better not have left any breakpoints
2675 * in the program or it'll die when it hits one. For this
2676 * to work, it may be necessary for the process to have been
2677 * previously attached. It *might* work if the program was
2678 * started via the normal ptrace (PTRACE_TRACEME).
2682 detach_command (const char *args
, int from_tty
)
2684 dont_repeat (); /* Not for the faint of heart. */
2686 if (inferior_ptid
== null_ptid
)
2687 error (_("The program is not being run."));
2689 scoped_disable_commit_resumed
disable_commit_resumed ("detaching");
2691 query_if_trace_running (from_tty
);
2693 disconnect_tracing ();
2695 /* Hold a strong reference to the target while (maybe)
2696 detaching the parent. Otherwise detaching could close the
2699 = target_ops_ref::new_reference (current_inferior ()->process_target ());
2701 /* Save this before detaching, since detaching may unpush the
2702 process_stratum target. */
2703 bool was_non_stop_p
= target_is_non_stop_p ();
2705 target_detach (current_inferior (), from_tty
);
2707 /* The current inferior process was just detached successfully. Get
2708 rid of breakpoints that no longer make sense. Note we don't do
2709 this within target_detach because that is also used when
2710 following child forks, and in that case we will want to transfer
2711 breakpoints to the child, not delete them. */
2712 breakpoint_init_inferior (inf_exited
);
2714 /* If the solist is global across inferiors, don't clear it when we
2715 detach from a single inferior. */
2716 if (!gdbarch_has_global_solist (target_gdbarch ()))
2717 no_shared_libraries (NULL
, from_tty
);
2719 if (deprecated_detach_hook
)
2720 deprecated_detach_hook ();
2722 if (!was_non_stop_p
)
2723 restart_after_all_stop_detach (as_process_stratum_target (target_ref
.get ()));
2725 disable_commit_resumed
.reset_and_commit ();
2728 /* Disconnect from the current target without resuming it (leaving it
2729 waiting for a debugger).
2731 We'd better not have left any breakpoints in the program or the
2732 next debugger will get confused. Currently only supported for some
2733 remote targets, since the normal attach mechanisms don't work on
2734 stopped processes on some native platforms (e.g. GNU/Linux). */
2737 disconnect_command (const char *args
, int from_tty
)
2739 dont_repeat (); /* Not for the faint of heart. */
2740 query_if_trace_running (from_tty
);
2741 disconnect_tracing ();
2742 target_disconnect (args
, from_tty
);
2743 no_shared_libraries (NULL
, from_tty
);
2744 init_thread_list ();
2745 if (deprecated_detach_hook
)
2746 deprecated_detach_hook ();
2749 /* Stop PTID in the current target, and tag the PTID threads as having
2750 been explicitly requested to stop. PTID can be a thread, a
2751 process, or minus_one_ptid, meaning all threads of all inferiors of
2752 the current target. */
2755 stop_current_target_threads_ns (ptid_t ptid
)
2759 /* Tag the thread as having been explicitly requested to stop, so
2760 other parts of gdb know not to resume this thread automatically,
2761 if it was stopped due to an internal event. Limit this to
2762 non-stop mode, as when debugging a multi-threaded application in
2763 all-stop mode, we will only get one stop event --- it's undefined
2764 which thread will report the event. */
2765 set_stop_requested (current_inferior ()->process_target (),
2769 /* See inferior.h. */
2772 interrupt_target_1 (bool all_threads
)
2774 scoped_disable_commit_resumed
disable_commit_resumed ("interrupting");
2780 scoped_restore_current_thread restore_thread
;
2782 for (inferior
*inf
: all_inferiors ())
2784 switch_to_inferior_no_thread (inf
);
2785 stop_current_target_threads_ns (minus_one_ptid
);
2789 stop_current_target_threads_ns (inferior_ptid
);
2792 target_interrupt ();
2794 disable_commit_resumed
.reset_and_commit ();
2798 Stop the execution of the target while running in async mode, in
2799 the background. In all-stop, stop the whole process. In non-stop
2800 mode, stop the current thread only by default, or stop all threads
2801 if the `-a' switch is used. */
2804 interrupt_command (const char *args
, int from_tty
)
2806 if (target_can_async_p ())
2808 int all_threads
= 0;
2810 dont_repeat (); /* Not for the faint of heart. */
2813 && startswith (args
, "-a"))
2816 if (!non_stop
&& all_threads
)
2817 error (_("-a is meaningless in all-stop mode."));
2819 interrupt_target_1 (all_threads
);
2823 /* See inferior.h. */
2826 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2827 struct frame_info
*frame
, const char *args
)
2830 int printed_something
= 0;
2832 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2834 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2836 printed_something
= 1;
2837 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2840 if (!printed_something
)
2841 fprintf_filtered (file
, "No floating-point info "
2842 "available for this processor.\n");
2846 info_float_command (const char *args
, int from_tty
)
2848 struct frame_info
*frame
;
2850 if (!target_has_registers ())
2851 error (_("The program has no registers now."));
2853 frame
= get_selected_frame (NULL
);
2854 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
2857 /* Implement `info proc' family of commands. */
2860 info_proc_cmd_1 (const char *args
, enum info_proc_what what
, int from_tty
)
2862 struct gdbarch
*gdbarch
= get_current_arch ();
2864 if (!target_info_proc (args
, what
))
2866 if (gdbarch_info_proc_p (gdbarch
))
2867 gdbarch_info_proc (gdbarch
, args
, what
);
2869 error (_("Not supported on this target."));
2873 /* Implement `info proc' when given without any further parameters. */
2876 info_proc_cmd (const char *args
, int from_tty
)
2878 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
2881 /* Implement `info proc mappings'. */
2884 info_proc_cmd_mappings (const char *args
, int from_tty
)
2886 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
2889 /* Implement `info proc stat'. */
2892 info_proc_cmd_stat (const char *args
, int from_tty
)
2894 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
2897 /* Implement `info proc status'. */
2900 info_proc_cmd_status (const char *args
, int from_tty
)
2902 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
2905 /* Implement `info proc cwd'. */
2908 info_proc_cmd_cwd (const char *args
, int from_tty
)
2910 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
2913 /* Implement `info proc cmdline'. */
2916 info_proc_cmd_cmdline (const char *args
, int from_tty
)
2918 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
2921 /* Implement `info proc exe'. */
2924 info_proc_cmd_exe (const char *args
, int from_tty
)
2926 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
2929 /* Implement `info proc files'. */
2932 info_proc_cmd_files (const char *args
, int from_tty
)
2934 info_proc_cmd_1 (args
, IP_FILES
, from_tty
);
2937 /* Implement `info proc all'. */
2940 info_proc_cmd_all (const char *args
, int from_tty
)
2942 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
2945 /* Implement `show print finish'. */
2948 show_print_finish (struct ui_file
*file
, int from_tty
,
2949 struct cmd_list_element
*c
,
2952 fprintf_filtered (file
, _("\
2953 Printing of return value after `finish' is %s.\n"),
2958 /* This help string is used for the run, start, and starti commands.
2959 It is defined as a macro to prevent duplication. */
2961 #define RUN_ARGS_HELP \
2962 "You may specify arguments to give it.\n\
2963 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
2964 shell that will start the program (specified by the \"$SHELL\" environment\n\
2965 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
2966 are also allowed.\n\
2968 With no arguments, uses arguments last specified (with \"run\" or \n\
2969 \"set args\"). To cancel previous arguments and run with no arguments,\n\
2970 use \"set args\" without arguments.\n\
2972 To start the inferior without using a shell, use \"set startup-with-shell off\"."
2974 void _initialize_infcmd ();
2976 _initialize_infcmd ()
2978 static struct cmd_list_element
*info_proc_cmdlist
;
2979 struct cmd_list_element
*c
= NULL
;
2980 const char *cmd_name
;
2982 /* Add the filename of the terminal connected to inferior I/O. */
2983 add_setshow_optional_filename_cmd ("inferior-tty", class_run
,
2984 &inferior_io_terminal_scratch
, _("\
2985 Set terminal for future runs of program being debugged."), _("\
2986 Show terminal for future runs of program being debugged."), _("\
2987 Usage: set inferior-tty [TTY]\n\n\
2988 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
2990 set_inferior_tty_command
,
2991 show_inferior_tty_command
,
2992 &setlist
, &showlist
);
2993 cmd_name
= "inferior-tty";
2994 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
2995 gdb_assert (c
!= NULL
);
2996 add_alias_cmd ("tty", c
, class_run
, 0, &cmdlist
);
2999 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3000 &inferior_args_scratch
, _("\
3001 Set argument list to give program being debugged when it is started."), _("\
3002 Show argument list to give program being debugged when it is started."), _("\
3003 Follow this command with any number of args, to be passed to the program."),
3006 &setlist
, &showlist
);
3007 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
3008 gdb_assert (c
!= NULL
);
3009 set_cmd_completer (c
, filename_completer
);
3012 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3013 &inferior_cwd_scratch
, _("\
3014 Set the current working directory to be used when the inferior is started.\n\
3015 Changing this setting does not have any effect on inferiors that are\n\
3018 Show the current working directory that is used when the inferior is started."),
3020 Use this command to change the current working directory that will be used\n\
3021 when the inferior is started. This setting does not affect GDB's current\n\
3022 working directory."),
3025 &setlist
, &showlist
);
3026 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
3027 gdb_assert (c
!= NULL
);
3028 set_cmd_completer (c
, filename_completer
);
3030 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3031 The environment to give the program, or one variable's value.\n\
3032 With an argument VAR, prints the value of environment variable VAR to\n\
3033 give the program being debugged. With no arguments, prints the entire\n\
3034 environment to be given to the program."), &showlist
);
3035 set_cmd_completer (c
, noop_completer
);
3037 add_basic_prefix_cmd ("unset", no_class
,
3038 _("Complement to certain \"set\" commands."),
3039 &unsetlist
, 0, &cmdlist
);
3041 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3042 Cancel environment variable VAR for the program.\n\
3043 This does not affect the program until the next \"run\" command."),
3045 set_cmd_completer (c
, noop_completer
);
3047 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3048 Set environment variable value to give the program.\n\
3049 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3050 VALUES of environment variables are uninterpreted strings.\n\
3051 This does not affect the program until the next \"run\" command."),
3053 set_cmd_completer (c
, noop_completer
);
3055 c
= add_com ("path", class_files
, path_command
, _("\
3056 Add directory DIR(s) to beginning of search path for object files.\n\
3057 $cwd in the path means the current working directory.\n\
3058 This path is equivalent to the $PATH shell variable. It is a list of\n\
3059 directories, separated by colons. These directories are searched to find\n\
3060 fully linked executable files and separately compiled object files as \
3062 set_cmd_completer (c
, filename_completer
);
3064 c
= add_cmd ("paths", no_class
, path_info
, _("\
3065 Current search path for finding object files.\n\
3066 $cwd in the path means the current working directory.\n\
3067 This path is equivalent to the $PATH shell variable. It is a list of\n\
3068 directories, separated by colons. These directories are searched to find\n\
3069 fully linked executable files and separately compiled object files as \
3072 set_cmd_completer (c
, noop_completer
);
3074 add_prefix_cmd ("kill", class_run
, kill_command
,
3075 _("Kill execution of program being debugged."),
3076 &killlist
, 0, &cmdlist
);
3078 add_com ("attach", class_run
, attach_command
, _("\
3079 Attach to a process or file outside of GDB.\n\
3080 This command attaches to another target, of the same type as your last\n\
3081 \"target\" command (\"info files\" will show your target stack).\n\
3082 The command may take as argument a process id or a device file.\n\
3083 For a process id, you must have permission to send the process a signal,\n\
3084 and it must have the same effective uid as the debugger.\n\
3085 When using \"attach\" with a process id, the debugger finds the\n\
3086 program running in the process, looking first in the current working\n\
3087 directory, or (if not found there) using the source file search path\n\
3088 (see the \"directory\" command). You can also use the \"file\" command\n\
3089 to specify the program, and to load its symbol table."));
3091 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3092 Detach a process or file previously attached.\n\
3093 If a process, it is no longer traced, and it continues its execution. If\n\
3094 you were debugging a file, the file is closed and gdb no longer accesses it."),
3095 &detachlist
, 0, &cmdlist
);
3097 add_com ("disconnect", class_run
, disconnect_command
, _("\
3098 Disconnect from a target.\n\
3099 The target will wait for another debugger to connect. Not available for\n\
3102 c
= add_com ("signal", class_run
, signal_command
, _("\
3103 Continue program with the specified signal.\n\
3104 Usage: signal SIGNAL\n\
3105 The SIGNAL argument is processed the same as the handle command.\n\
3107 An argument of \"0\" means continue the program without sending it a signal.\n\
3108 This is useful in cases where the program stopped because of a signal,\n\
3109 and you want to resume the program while discarding the signal.\n\
3111 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3112 the current thread only."));
3113 set_cmd_completer (c
, signal_completer
);
3115 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3116 Queue a signal to be delivered to the current thread when it is resumed.\n\
3117 Usage: queue-signal SIGNAL\n\
3118 The SIGNAL argument is processed the same as the handle command.\n\
3119 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3121 An argument of \"0\" means remove any currently queued signal from\n\
3122 the current thread. This is useful in cases where the program stopped\n\
3123 because of a signal, and you want to resume it while discarding the signal.\n\
3125 In a multi-threaded program the signal is queued with, or discarded from,\n\
3126 the current thread only."));
3127 set_cmd_completer (c
, signal_completer
);
3129 cmd_list_element
*stepi_cmd
3130 = add_com ("stepi", class_run
, stepi_command
, _("\
3131 Step one instruction exactly.\n\
3133 Argument N means step N times (or till program stops for another \
3135 add_com_alias ("si", stepi_cmd
, class_run
, 0);
3137 cmd_list_element
*nexti_cmd
3138 = add_com ("nexti", class_run
, nexti_command
, _("\
3139 Step one instruction, but proceed through subroutine calls.\n\
3141 Argument N means step N times (or till program stops for another \
3143 add_com_alias ("ni", nexti_cmd
, class_run
, 0);
3145 cmd_list_element
*finish_cmd
3146 = add_com ("finish", class_run
, finish_command
, _("\
3147 Execute until selected stack frame returns.\n\
3149 Upon return, the value returned is printed and put in the value history."));
3150 add_com_alias ("fin", finish_cmd
, class_run
, 1);
3152 cmd_list_element
*next_cmd
3153 = add_com ("next", class_run
, next_command
, _("\
3154 Step program, proceeding through subroutine calls.\n\
3156 Unlike \"step\", if the current source line calls a subroutine,\n\
3157 this command does not enter the subroutine, but instead steps over\n\
3158 the call, in effect treating it as a single source line."));
3159 add_com_alias ("n", next_cmd
, class_run
, 1);
3161 cmd_list_element
*step_cmd
3162 = add_com ("step", class_run
, step_command
, _("\
3163 Step program until it reaches a different source line.\n\
3165 Argument N means step N times (or till program stops for another \
3167 add_com_alias ("s", step_cmd
, class_run
, 1);
3169 cmd_list_element
*until_cmd
3170 = add_com ("until", class_run
, until_command
, _("\
3171 Execute until past the current line or past a LOCATION.\n\
3172 Execute until the program reaches a source line greater than the current\n\
3173 or a specified location (same args as break command) within the current \
3175 set_cmd_completer (until_cmd
, location_completer
);
3176 add_com_alias ("u", until_cmd
, class_run
, 1);
3178 c
= add_com ("advance", class_run
, advance_command
, _("\
3179 Continue the program up to the given location (same form as args for break \
3181 Execution will also stop upon exit from the current stack frame."));
3182 set_cmd_completer (c
, location_completer
);
3184 cmd_list_element
*jump_cmd
3185 = add_com ("jump", class_run
, jump_command
, _("\
3186 Continue program being debugged at specified line or address.\n\
3187 Usage: jump LOCATION\n\
3188 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3189 for an address to start at."));
3190 set_cmd_completer (jump_cmd
, location_completer
);
3191 add_com_alias ("j", jump_cmd
, class_run
, 1);
3193 cmd_list_element
*continue_cmd
3194 = add_com ("continue", class_run
, continue_command
, _("\
3195 Continue program being debugged, after signal or breakpoint.\n\
3196 Usage: continue [N]\n\
3197 If proceeding from breakpoint, a number N may be used as an argument,\n\
3198 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3199 the breakpoint won't break until the Nth time it is reached).\n\
3201 If non-stop mode is enabled, continue only the current thread,\n\
3202 otherwise all the threads in the program are continued. To \n\
3203 continue all stopped threads in non-stop mode, use the -a option.\n\
3204 Specifying -a and an ignore count simultaneously is an error."));
3205 add_com_alias ("c", continue_cmd
, class_run
, 1);
3206 add_com_alias ("fg", continue_cmd
, class_run
, 1);
3208 cmd_list_element
*run_cmd
3209 = add_com ("run", class_run
, run_command
, _("\
3210 Start debugged program.\n"
3212 set_cmd_completer (run_cmd
, filename_completer
);
3213 add_com_alias ("r", run_cmd
, class_run
, 1);
3215 c
= add_com ("start", class_run
, start_command
, _("\
3216 Start the debugged program stopping at the beginning of the main procedure.\n"
3218 set_cmd_completer (c
, filename_completer
);
3220 c
= add_com ("starti", class_run
, starti_command
, _("\
3221 Start the debugged program stopping at the first instruction.\n"
3223 set_cmd_completer (c
, filename_completer
);
3225 add_com ("interrupt", class_run
, interrupt_command
,
3226 _("Interrupt the execution of the debugged program.\n\
3227 If non-stop mode is enabled, interrupt only the current thread,\n\
3228 otherwise all the threads in the program are stopped. To \n\
3229 interrupt all running threads in non-stop mode, use the -a option."));
3231 cmd_list_element
*info_registers_cmd
3232 = add_info ("registers", info_registers_command
, _("\
3233 List of integer registers and their contents, for selected stack frame.\n\
3234 One or more register names as argument means describe the given registers.\n\
3235 One or more register group names as argument means describe the registers\n\
3236 in the named register groups."));
3237 add_info_alias ("r", info_registers_cmd
, 1);
3238 set_cmd_completer (info_registers_cmd
, reg_or_group_completer
);
3240 c
= add_info ("all-registers", info_all_registers_command
, _("\
3241 List of all registers and their contents, for selected stack frame.\n\
3242 One or more register names as argument means describe the given registers.\n\
3243 One or more register group names as argument means describe the registers\n\
3244 in the named register groups."));
3245 set_cmd_completer (c
, reg_or_group_completer
);
3247 add_info ("program", info_program_command
,
3248 _("Execution status of the program."));
3250 add_info ("float", info_float_command
,
3251 _("Print the status of the floating point unit."));
3253 add_info ("vector", info_vector_command
,
3254 _("Print the status of the vector unit."));
3256 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3258 Show additional information about a process.\n\
3259 Specify any process id, or use the program being debugged by default."),
3261 1/*allow-unknown*/, &infolist
);
3263 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3264 List memory regions mapped by the specified process."),
3265 &info_proc_cmdlist
);
3267 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3268 List process info from /proc/PID/stat."),
3269 &info_proc_cmdlist
);
3271 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3272 List process info from /proc/PID/status."),
3273 &info_proc_cmdlist
);
3275 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3276 List current working directory of the specified process."),
3277 &info_proc_cmdlist
);
3279 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3280 List command line arguments of the specified process."),
3281 &info_proc_cmdlist
);
3283 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3284 List absolute filename for executable of the specified process."),
3285 &info_proc_cmdlist
);
3287 add_cmd ("files", class_info
, info_proc_cmd_files
, _("\
3288 List files opened by the specified process."),
3289 &info_proc_cmdlist
);
3291 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3292 List all available info about the specified process."),
3293 &info_proc_cmdlist
);
3295 add_setshow_boolean_cmd ("finish", class_support
,
3296 &user_print_options
.finish_print
, _("\
3297 Set whether `finish' prints the return value."), _("\
3298 Show whether `finish' prints the return value."), NULL
,
3301 &setprintlist
, &showprintlist
);