1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2023 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"
58 #include "dwarf2/loc.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 /* Pid of our debugged inferior, or 0 if no inferior now.
70 Since various parts of infrun.c test this to see whether there is a program
71 being debugged it should be nonzero (currently 3 is used) for remote
76 /* Nonzero if stopped due to completion of a stack dummy routine. */
78 enum stop_stack_kind stop_stack_dummy
;
80 /* Nonzero if stopped due to a random (unexpected) signal in inferior
83 int stopped_by_random_signal
;
86 /* Whether "finish" should print the value. */
88 static bool finish_print
= true;
92 /* Store the new value passed to 'set inferior-tty'. */
95 set_tty_value (const std::string
&tty
)
97 current_inferior ()->set_tty (tty
);
100 /* Get the current 'inferior-tty' value. */
102 static const std::string
&
105 return current_inferior ()->tty ();
108 /* Implement 'show inferior-tty' command. */
111 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
112 struct cmd_list_element
*c
, const char *value
)
114 /* Note that we ignore the passed-in value in favor of computing it
116 const std::string
&inferior_tty
= current_inferior ()->tty ();
119 _("Terminal for future runs of program being debugged "
120 "is \"%s\".\n"), inferior_tty
.c_str ());
123 /* Store the new value passed to 'set args'. */
126 set_args_value (const std::string
&args
)
128 current_inferior ()->set_args (args
);
131 /* Return the value for 'show args' to display. */
133 static const std::string
&
136 return current_inferior ()->args ();
139 /* Callback to implement 'show args' command. */
142 show_args_command (struct ui_file
*file
, int from_tty
,
143 struct cmd_list_element
*c
, const char *value
)
145 /* Ignore the passed in value, pull the argument directly from the
146 inferior. However, these should always be the same. */
147 gdb_printf (file
, _("\
148 Argument list to give program being debugged when it is started is \"%s\".\n"),
149 current_inferior ()->args ().c_str ());
152 /* See gdbsupport/common-inferior.h. */
157 return current_inferior ()->cwd ();
160 /* Store the new value passed to 'set cwd'. */
163 set_cwd_value (const std::string
&args
)
165 current_inferior ()->set_cwd (args
);
168 /* Handle the 'show cwd' command. */
171 show_cwd_command (struct ui_file
*file
, int from_tty
,
172 struct cmd_list_element
*c
, const char *value
)
174 const std::string
&cwd
= current_inferior ()->cwd ();
179 You have not set the inferior's current working directory.\n\
180 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
181 server's cwd if remote debugging.\n"));
184 _("Current working directory that will be used "
185 "when starting the inferior is \"%s\".\n"),
190 /* This function strips the '&' character (indicating background
191 execution) that is added as *the last* of the arguments ARGS of a
192 command. A copy of the incoming ARGS without the '&' is returned,
193 unless the resulting string after stripping is empty, in which case
194 NULL is returned. *BG_CHAR_P is an output boolean that indicates
195 whether the '&' character was found. */
197 static gdb::unique_xmalloc_ptr
<char>
198 strip_bg_char (const char *args
, int *bg_char_p
)
202 if (args
== nullptr || *args
== '\0')
208 p
= args
+ strlen (args
);
212 while (p
> args
&& isspace (p
[-1]))
217 return gdb::unique_xmalloc_ptr
<char>
218 (savestring (args
, p
- args
));
220 return gdb::unique_xmalloc_ptr
<char> (nullptr);
224 return make_unique_xstrdup (args
);
227 /* Common actions to take after creating any sort of inferior, by any
228 means (running, attaching, connecting, et cetera). The target
229 should be stopped. */
232 post_create_inferior (int from_tty
)
235 /* Be sure we own the terminal in case write operations are performed. */
236 target_terminal::ours_for_output ();
238 infrun_debug_show_threads ("threads in the newly created inferior",
239 current_inferior ()->non_exited_threads ());
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 (nullptr, 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 /* To avoid other inferiors hitting this breakpoint, make it
419 inferior-specific using a condition. A better solution would be to
420 have proper inferior-specific breakpoint support, in the breakpoint
421 machinery. We could then avoid inserting a breakpoint in the program
422 spaces unrelated to this inferior. */
424 = ((current_language
->la_language
== language_ada
425 || current_language
->la_language
== language_pascal
426 || current_language
->la_language
== language_m2
) ? "=" : "==");
427 std::string arg
= string_printf
428 ("-qualified %s if $_inferior %s %d", main_name (), op
,
429 current_inferior ()->num
);
430 tbreak_command (arg
.c_str (), 0);
433 exec_file
= get_exec_file (0);
435 /* We keep symbols from add-symbol-file, on the grounds that the
436 user might want to add some symbols before running the program
437 (right?). But sometimes (dynamic loading where the user manually
438 introduces the new symbols with add-symbol-file), the code which
439 the symbols describe does not persist between runs. Currently
440 the user has to manually nuke all symbols between runs if they
441 want them to go away (PR 2207). This is probably reasonable. */
443 /* If there were other args, beside '&', process them. */
445 current_inferior ()->set_args (args
);
449 uiout
->field_string (nullptr, "Starting program");
452 uiout
->field_string ("execfile", exec_file
,
453 file_name_style
.style ());
455 uiout
->field_string ("infargs", current_inferior ()->args ());
460 run_target
->create_inferior (exec_file
,
461 current_inferior ()->args (),
462 current_inferior ()->environment
.envp (),
464 /* to_create_inferior should push the target, so after this point we
465 shouldn't refer to run_target again. */
466 run_target
= nullptr;
468 infrun_debug_show_threads ("immediately after create_process",
469 current_inferior ()->non_exited_threads ());
471 /* We're starting off a new process. When we get out of here, in
472 non-stop mode, finish the state of all threads of that process,
473 but leave other threads alone, as they may be stopped in internal
474 events --- the frontend shouldn't see them as stopped. In
475 all-stop, always finish the state of all threads, as we may be
476 resuming more than just the new process. */
477 process_stratum_target
*finish_target
;
481 finish_target
= current_inferior ()->process_target ();
482 finish_ptid
= ptid_t (current_inferior ()->pid
);
486 finish_target
= nullptr;
487 finish_ptid
= minus_one_ptid
;
489 scoped_finish_thread_state
finish_state (finish_target
, finish_ptid
);
491 /* Pass zero for FROM_TTY, because at this point the "run" command
492 has done its thing; now we are setting up the running program. */
493 post_create_inferior (0);
495 /* Queue a pending event so that the program stops immediately. */
496 if (run_how
== RUN_STOP_AT_FIRST_INSN
)
498 thread_info
*thr
= inferior_thread ();
499 target_waitstatus ws
;
500 ws
.set_stopped (GDB_SIGNAL_0
);
501 thr
->set_pending_waitstatus (ws
);
504 /* Start the target running. Do not use -1 continuation as it would skip
505 breakpoint right at the entry point. */
506 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
508 /* Since there was no error, there's no need to finish the thread
510 finish_state
.release ();
512 disable_commit_resumed
.reset_and_commit ();
516 run_command (const char *args
, int from_tty
)
518 run_command_1 (args
, from_tty
, RUN_NORMAL
);
521 /* Start the execution of the program up until the beginning of the main
525 start_command (const char *args
, int from_tty
)
527 /* Some languages such as Ada need to search inside the program
528 minimal symbols for the location where to put the temporary
529 breakpoint before starting. */
530 if (!have_minimal_symbols ())
531 error (_("No symbol table loaded. Use the \"file\" command."));
533 /* Run the program until reaching the main procedure... */
534 run_command_1 (args
, from_tty
, RUN_STOP_AT_MAIN
);
537 /* Start the execution of the program stopping at the first
541 starti_command (const char *args
, int from_tty
)
543 run_command_1 (args
, from_tty
, RUN_STOP_AT_FIRST_INSN
);
547 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
549 /* We go through all threads individually instead of compressing
550 into a single target `resume_all' request, because some threads
551 may be stopped in internal breakpoints/events, or stopped waiting
552 for its turn in the displaced stepping queue (that is, they are
553 running && !executing). The target side has no idea about why
554 the thread is stopped, so a `resume_all' command would resume too
555 much. If/when GDB gains a way to tell the target `hold this
556 thread stopped until I say otherwise', then we can optimize
558 if (thread
->state
!= THREAD_STOPPED
)
561 if (!thread
->inf
->has_execution ())
564 switch_to_thread (thread
);
565 clear_proceed_status (0);
566 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
571 ensure_valid_thread (void)
573 if (inferior_ptid
== null_ptid
574 || inferior_thread ()->state
== THREAD_EXITED
)
575 error (_("Cannot execute this command without a live selected thread."));
578 /* If the user is looking at trace frames, any resumption of execution
579 is likely to mix up recorded and live target data. So simply
580 disallow those commands. */
583 ensure_not_tfind_mode (void)
585 if (get_traceframe_number () >= 0)
586 error (_("Cannot execute this command while looking at trace frames."));
589 /* Throw an error indicating the current thread is running. */
592 error_is_running (void)
594 error (_("Cannot execute this command while "
595 "the selected thread is running."));
598 /* Calls error_is_running if the current thread is running. */
601 ensure_not_running (void)
603 if (inferior_thread ()->state
== THREAD_RUNNING
)
608 continue_1 (int all_threads
)
611 ensure_not_tfind_mode ();
613 if (non_stop
&& all_threads
)
615 /* Don't error out if the current thread is running, because
616 there may be other stopped threads. */
618 /* Backup current thread and selected frame and restore on scope
620 scoped_restore_current_thread restore_thread
;
621 scoped_disable_commit_resumed disable_commit_resumed
622 ("continue all threads in non-stop");
624 iterate_over_threads (proceed_thread_callback
, nullptr);
626 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
628 /* If all threads in the target were already running,
629 proceed_thread_callback ends up never calling proceed,
630 and so nothing calls this to put the inferior's terminal
631 settings in effect and remove stdin from the event loop,
632 which we must when running a foreground command. E.g.:
636 <all threads are running now>
639 <no thread was resumed, but the inferior now owns the terminal>
641 target_terminal::inferior ();
644 disable_commit_resumed
.reset_and_commit ();
648 ensure_valid_thread ();
649 ensure_not_running ();
650 clear_proceed_status (0);
651 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
655 /* continue [-a] [proceed-count] [&] */
658 continue_command (const char *args
, int from_tty
)
661 bool all_threads_p
= false;
665 /* Find out whether we must run in the background. */
666 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
667 args
= stripped
.get ();
671 if (startswith (args
, "-a"))
673 all_threads_p
= true;
674 args
+= sizeof ("-a") - 1;
680 if (!non_stop
&& all_threads_p
)
681 error (_("`-a' is meaningless in all-stop mode."));
683 if (args
!= nullptr && all_threads_p
)
684 error (_("Can't resume all threads and specify "
685 "proceed count simultaneously."));
687 /* If we have an argument left, set proceed count of breakpoint we
691 bpstat
*bs
= nullptr;
694 struct thread_info
*tp
;
697 tp
= inferior_thread ();
700 process_stratum_target
*last_target
;
703 get_last_target_status (&last_target
, &last_ptid
, nullptr);
704 tp
= last_target
->find_thread (last_ptid
);
707 bs
= tp
->control
.stop_bpstat
;
709 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
712 set_ignore_count (num
,
713 parse_and_eval_long (args
) - 1,
715 /* set_ignore_count prints a message ending with a period.
716 So print two spaces before "Continuing.". */
722 if (!stopped
&& from_tty
)
725 ("Not stopped at any breakpoint; argument ignored.\n");
729 ensure_not_tfind_mode ();
731 if (!non_stop
|| !all_threads_p
)
733 ensure_valid_thread ();
734 ensure_not_running ();
737 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
740 gdb_printf (_("Continuing.\n"));
742 continue_1 (all_threads_p
);
745 /* Record in TP the starting point of a "step" or "next" command. */
748 set_step_frame (thread_info
*tp
)
750 /* This can be removed once this function no longer implicitly relies on the
751 inferior_ptid value. */
752 gdb_assert (inferior_ptid
== tp
->ptid
);
754 frame_info_ptr frame
= get_current_frame ();
756 symtab_and_line sal
= find_frame_sal (frame
);
757 set_step_info (tp
, frame
, sal
);
759 CORE_ADDR pc
= get_frame_pc (frame
);
760 tp
->control
.step_start_function
= find_pc_function (pc
);
763 /* Step until outside of current statement. */
766 step_command (const char *count_string
, int from_tty
)
768 step_1 (0, 0, count_string
);
771 /* Likewise, but skip over subroutine calls as if single instructions. */
774 next_command (const char *count_string
, int from_tty
)
776 step_1 (1, 0, count_string
);
779 /* Likewise, but step only one instruction. */
782 stepi_command (const char *count_string
, int from_tty
)
784 step_1 (0, 1, count_string
);
788 nexti_command (const char *count_string
, int from_tty
)
790 step_1 (1, 1, count_string
);
793 /* Data for the FSM that manages the step/next/stepi/nexti
796 struct step_command_fsm
: public thread_fsm
798 /* How many steps left in a "step N"-like command. */
801 /* If true, this is a next/nexti, otherwise a step/stepi. */
802 int skip_subroutines
;
804 /* If true, this is a stepi/nexti, otherwise a step/step. */
807 explicit step_command_fsm (struct interp
*cmd_interp
)
808 : thread_fsm (cmd_interp
)
812 void clean_up (struct thread_info
*thread
) override
;
813 bool should_stop (struct thread_info
*thread
) override
;
814 enum async_reply_reason
do_async_reply_reason () override
;
817 /* Prepare for a step/next/etc. command. Any target resource
818 allocated here is undone in the FSM's clean_up method. */
821 step_command_fsm_prepare (struct step_command_fsm
*sm
,
822 int skip_subroutines
, int single_inst
,
823 int count
, struct thread_info
*thread
)
825 sm
->skip_subroutines
= skip_subroutines
;
826 sm
->single_inst
= single_inst
;
829 /* Leave the si command alone. */
830 if (!sm
->single_inst
|| sm
->skip_subroutines
)
831 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
833 thread
->control
.stepping_command
= 1;
836 static int prepare_one_step (thread_info
*, struct step_command_fsm
*sm
);
839 step_1 (int skip_subroutines
, int single_inst
, const char *count_string
)
843 struct thread_info
*thr
;
844 struct step_command_fsm
*step_sm
;
847 ensure_not_tfind_mode ();
848 ensure_valid_thread ();
849 ensure_not_running ();
851 gdb::unique_xmalloc_ptr
<char> stripped
852 = strip_bg_char (count_string
, &async_exec
);
853 count_string
= stripped
.get ();
855 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
857 count
= count_string
? parse_and_eval_long (count_string
) : 1;
859 clear_proceed_status (1);
861 /* Setup the execution command state machine to handle all the COUNT
863 thr
= inferior_thread ();
864 step_sm
= new step_command_fsm (command_interp ());
865 thr
->set_thread_fsm (std::unique_ptr
<thread_fsm
> (step_sm
));
867 step_command_fsm_prepare (step_sm
, skip_subroutines
,
868 single_inst
, count
, thr
);
870 /* Do only one step for now, before returning control to the event
871 loop. Let the continuation figure out how many other steps we
872 need to do, and handle them one at the time, through
874 if (!prepare_one_step (thr
, step_sm
))
875 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
878 /* Stepped into an inline frame. Pretend that we've
880 thr
->thread_fsm ()->clean_up (thr
);
881 bool proceeded
= normal_stop ();
883 inferior_event_handler (INF_EXEC_COMPLETE
);
884 all_uis_check_sync_execution_done ();
888 /* Implementation of the 'should_stop' FSM method for stepping
889 commands. Called after we are done with one step operation, to
890 check whether we need to step again, before we print the prompt and
891 return control to the user. If count is > 1, returns false, as we
892 will need to keep going. */
895 step_command_fsm::should_stop (struct thread_info
*tp
)
897 if (tp
->control
.stop_step
)
899 /* There are more steps to make, and we did stop due to
900 ending a stepping range. Do another step. */
902 return prepare_one_step (tp
, this);
910 /* Implementation of the 'clean_up' FSM method for stepping commands. */
913 step_command_fsm::clean_up (struct thread_info
*thread
)
915 if (!single_inst
|| skip_subroutines
)
916 delete_longjmp_breakpoint (thread
->global_num
);
919 /* Implementation of the 'async_reply_reason' FSM method for stepping
922 enum async_reply_reason
923 step_command_fsm::do_async_reply_reason ()
925 return EXEC_ASYNC_END_STEPPING_RANGE
;
928 /* Prepare for one step in "step N". The actual target resumption is
929 done by the caller. Return true if we're done and should thus
930 report a stop to the user. Returns false if the target needs to be
934 prepare_one_step (thread_info
*tp
, struct step_command_fsm
*sm
)
936 /* This can be removed once this function no longer implicitly relies on the
937 inferior_ptid value. */
938 gdb_assert (inferior_ptid
== tp
->ptid
);
942 frame_info_ptr frame
= get_current_frame ();
946 if (!sm
->single_inst
)
950 /* Step at an inlined function behaves like "down". */
951 if (!sm
->skip_subroutines
952 && inline_skipped_frames (tp
))
955 const char *fn
= nullptr;
959 /* Pretend that we've ran. */
960 resume_ptid
= user_visible_resume_ptid (1);
961 set_running (tp
->inf
->process_target (), resume_ptid
, true);
963 step_into_inline_frame (tp
);
965 frame
= get_current_frame ();
966 sal
= find_frame_sal (frame
);
967 sym
= get_frame_function (frame
);
970 fn
= sym
->print_name ();
973 || !function_name_is_marked_for_skip (fn
, sal
))
976 return prepare_one_step (tp
, sm
);
980 pc
= get_frame_pc (frame
);
981 find_pc_line_pc_range (pc
,
982 &tp
->control
.step_range_start
,
983 &tp
->control
.step_range_end
);
985 /* There's a problem in gcc (PR gcc/98780) that causes missing line
986 table entries, which results in a too large stepping range.
987 Use inlined_subroutine info to make the range more narrow. */
988 if (inline_skipped_frames (tp
) > 0)
990 symbol
*sym
= inline_skipped_symbol (tp
);
991 if (sym
->aclass () == LOC_BLOCK
)
993 const block
*block
= sym
->value_block ();
994 if (block
->end () < tp
->control
.step_range_end
)
995 tp
->control
.step_range_end
= block
->end ();
999 tp
->control
.may_range_step
= 1;
1001 /* If we have no line info, switch to stepi mode. */
1002 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1004 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1005 tp
->control
.may_range_step
= 0;
1007 else if (tp
->control
.step_range_end
== 0)
1011 if (find_pc_partial_function (pc
, &name
,
1012 &tp
->control
.step_range_start
,
1013 &tp
->control
.step_range_end
) == 0)
1014 error (_("Cannot find bounds of current function"));
1016 target_terminal::ours_for_output ();
1017 gdb_printf (_("Single stepping until exit from function %s,"
1018 "\nwhich has no line number information.\n"),
1024 /* Say we are stepping, but stop after one insn whatever it does. */
1025 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1026 if (!sm
->skip_subroutines
)
1028 Don't step over function calls, not even to functions lacking
1030 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1033 if (sm
->skip_subroutines
)
1034 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1040 sm
->set_finished ();
1045 /* Continue program at specified address. */
1048 jump_command (const char *arg
, int from_tty
)
1050 struct gdbarch
*gdbarch
= get_current_arch ();
1057 ensure_not_tfind_mode ();
1058 ensure_valid_thread ();
1059 ensure_not_running ();
1061 /* Find out whether we must run in the background. */
1062 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1063 arg
= stripped
.get ();
1065 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1068 error_no_arg (_("starting address"));
1070 std::vector
<symtab_and_line
> sals
1071 = decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1072 if (sals
.size () != 1)
1074 /* If multiple sal-objects were found, try dropping those that aren't
1075 from the current symtab. */
1076 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1077 sals
.erase (std::remove_if (sals
.begin (), sals
.end (),
1078 [&] (const symtab_and_line
&sal
)
1080 return sal
.symtab
!= cursal
.symtab
;
1082 if (sals
.size () != 1)
1083 error (_("Jump request is ambiguous: "
1084 "does not resolve to a single address"));
1087 symtab_and_line
&sal
= sals
[0];
1089 if (sal
.symtab
== 0 && sal
.pc
== 0)
1090 error (_("No source file has been specified."));
1092 resolve_sal_pc (&sal
); /* May error out. */
1094 /* See if we are trying to jump to another function. */
1095 fn
= get_frame_function (get_current_frame ());
1096 sfn
= find_pc_sect_containing_function (sal
.pc
,
1097 find_pc_mapped_section (sal
.pc
));
1098 if (fn
!= nullptr && sfn
!= fn
)
1100 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1103 error (_("Not confirmed."));
1110 struct obj_section
*section
;
1112 section
= sfn
->obj_section (sfn
->objfile ());
1113 if (section_is_overlay (section
)
1114 && !section_is_mapped (section
))
1116 if (!query (_("WARNING!!! Destination is in "
1117 "unmapped overlay! Jump anyway? ")))
1119 error (_("Not confirmed."));
1129 gdb_printf (_("Continuing at "));
1130 gdb_puts (paddress (gdbarch
, addr
));
1134 clear_proceed_status (0);
1135 proceed (addr
, GDB_SIGNAL_0
);
1138 /* Continue program giving it specified signal. */
1141 signal_command (const char *signum_exp
, int from_tty
)
1143 enum gdb_signal oursig
;
1146 dont_repeat (); /* Too dangerous. */
1148 ensure_not_tfind_mode ();
1149 ensure_valid_thread ();
1150 ensure_not_running ();
1152 /* Find out whether we must run in the background. */
1153 gdb::unique_xmalloc_ptr
<char> stripped
1154 = strip_bg_char (signum_exp
, &async_exec
);
1155 signum_exp
= stripped
.get ();
1157 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1160 error_no_arg (_("signal number"));
1162 /* It would be even slicker to make signal names be valid expressions,
1163 (the type could be "enum $signal" or some such), then the user could
1164 assign them to convenience variables. */
1165 oursig
= gdb_signal_from_name (signum_exp
);
1167 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1169 /* No, try numeric. */
1170 int num
= parse_and_eval_long (signum_exp
);
1173 oursig
= GDB_SIGNAL_0
;
1175 oursig
= gdb_signal_from_command (num
);
1178 /* Look for threads other than the current that this command ends up
1179 resuming too (due to schedlock off), and warn if they'll get a
1180 signal delivered. "signal 0" is used to suppress a previous
1181 signal, but if the current thread is no longer the one that got
1182 the signal, then the user is potentially suppressing the signal
1183 of the wrong thread. */
1186 int must_confirm
= 0;
1188 /* This indicates what will be resumed. Either a single thread,
1189 a whole process, or all threads of all processes. */
1190 ptid_t resume_ptid
= user_visible_resume_ptid (0);
1191 process_stratum_target
*resume_target
1192 = user_visible_resume_target (resume_ptid
);
1194 thread_info
*current
= inferior_thread ();
1196 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
1201 if (tp
->stop_signal () != GDB_SIGNAL_0
1202 && signal_pass_state (tp
->stop_signal ()))
1205 gdb_printf (_("Note:\n"));
1206 gdb_printf (_(" Thread %s previously stopped with signal %s, %s.\n"),
1207 print_thread_id (tp
),
1208 gdb_signal_to_name (tp
->stop_signal ()),
1209 gdb_signal_to_string (tp
->stop_signal ()));
1215 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1216 "still deliver the signals noted above to their respective threads.\n"
1217 "Continue anyway? "),
1218 print_thread_id (inferior_thread ())))
1219 error (_("Not confirmed."));
1224 if (oursig
== GDB_SIGNAL_0
)
1225 gdb_printf (_("Continuing with no signal.\n"));
1227 gdb_printf (_("Continuing with signal %s.\n"),
1228 gdb_signal_to_name (oursig
));
1231 clear_proceed_status (0);
1232 proceed ((CORE_ADDR
) -1, oursig
);
1235 /* Queue a signal to be delivered to the current thread. */
1238 queue_signal_command (const char *signum_exp
, int from_tty
)
1240 enum gdb_signal oursig
;
1241 struct thread_info
*tp
;
1244 ensure_not_tfind_mode ();
1245 ensure_valid_thread ();
1246 ensure_not_running ();
1248 if (signum_exp
== nullptr)
1249 error_no_arg (_("signal number"));
1251 /* It would be even slicker to make signal names be valid expressions,
1252 (the type could be "enum $signal" or some such), then the user could
1253 assign them to convenience variables. */
1254 oursig
= gdb_signal_from_name (signum_exp
);
1256 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1258 /* No, try numeric. */
1259 int num
= parse_and_eval_long (signum_exp
);
1262 oursig
= GDB_SIGNAL_0
;
1264 oursig
= gdb_signal_from_command (num
);
1267 if (oursig
!= GDB_SIGNAL_0
1268 && !signal_pass_state (oursig
))
1269 error (_("Signal handling set to not pass this signal to the program."));
1271 tp
= inferior_thread ();
1272 tp
->set_stop_signal (oursig
);
1275 /* Data for the FSM that manages the until (with no argument)
1278 struct until_next_fsm
: public thread_fsm
1280 /* The thread that as current when the command was executed. */
1283 until_next_fsm (struct interp
*cmd_interp
, int thread
)
1284 : thread_fsm (cmd_interp
),
1289 bool should_stop (struct thread_info
*thread
) override
;
1290 void clean_up (struct thread_info
*thread
) override
;
1291 enum async_reply_reason
do_async_reply_reason () override
;
1294 /* Implementation of the 'should_stop' FSM method for the until (with
1298 until_next_fsm::should_stop (struct thread_info
*tp
)
1300 if (tp
->control
.stop_step
)
1306 /* Implementation of the 'clean_up' FSM method for the until (with no
1310 until_next_fsm::clean_up (struct thread_info
*thread
)
1312 delete_longjmp_breakpoint (thread
->global_num
);
1315 /* Implementation of the 'async_reply_reason' FSM method for the until
1316 (with no arg) command. */
1318 enum async_reply_reason
1319 until_next_fsm::do_async_reply_reason ()
1321 return EXEC_ASYNC_END_STEPPING_RANGE
;
1324 /* Proceed until we reach a different source line with pc greater than
1325 our current one or exit the function. We skip calls in both cases.
1327 Note that eventually this command should probably be changed so
1328 that only source lines are printed out when we hit the breakpoint
1329 we set. This may involve changes to wait_for_inferior and the
1330 proceed status code. */
1333 until_next_command (int from_tty
)
1335 frame_info_ptr frame
;
1337 struct symbol
*func
;
1338 struct symtab_and_line sal
;
1339 struct thread_info
*tp
= inferior_thread ();
1340 int thread
= tp
->global_num
;
1341 struct until_next_fsm
*sm
;
1343 clear_proceed_status (0);
1344 set_step_frame (tp
);
1346 frame
= get_current_frame ();
1348 /* Step until either exited from this function or greater
1349 than the current line (if in symbolic section) or pc (if
1352 pc
= get_frame_pc (frame
);
1353 func
= find_pc_function (pc
);
1357 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1359 if (msymbol
.minsym
== nullptr)
1360 error (_("Execution is not within a known function."));
1362 tp
->control
.step_range_start
= msymbol
.value_address ();
1363 /* The upper-bound of step_range is exclusive. In order to make PC
1364 within the range, set the step_range_end with PC + 1. */
1365 tp
->control
.step_range_end
= pc
+ 1;
1369 sal
= find_pc_line (pc
, 0);
1371 tp
->control
.step_range_start
= func
->value_block ()->entry_pc ();
1372 tp
->control
.step_range_end
= sal
.end
;
1374 /* By setting the step_range_end based on the current pc, we are
1375 assuming that the last line table entry for any given source line
1376 will have is_stmt set to true. This is not necessarily the case,
1377 there may be additional entries for the same source line with
1378 is_stmt set false. Consider the following code:
1380 for (int i = 0; i < 10; i++)
1383 Clang-13, will generate multiple line table entries at the end of
1384 the loop all associated with the 'for' line. The first of these
1385 entries is marked is_stmt true, but the other entries are is_stmt
1388 If we only use the values in SAL, then our stepping range may not
1389 extend to the end of the loop. The until command will reach the
1390 end of the range, find a non is_stmt instruction, and step to the
1391 next is_stmt instruction. This stopping point, however, will be
1392 inside the loop, which is not what we wanted.
1394 Instead, we now check any subsequent line table entries to see if
1395 they are for the same line. If they are, and they are marked
1396 is_stmt false, then we extend the end of our stepping range.
1398 When we finish this process the end of the stepping range will
1399 point either to a line with a different line number, or, will
1400 point at an address for the same line number that is marked as a
1403 struct symtab_and_line final_sal
1404 = find_pc_line (tp
->control
.step_range_end
, 0);
1406 while (final_sal
.line
== sal
.line
&& final_sal
.symtab
== sal
.symtab
1407 && !final_sal
.is_stmt
)
1409 tp
->control
.step_range_end
= final_sal
.end
;
1410 final_sal
= find_pc_line (final_sal
.end
, 0);
1413 tp
->control
.may_range_step
= 1;
1415 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1417 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1418 delete_longjmp_breakpoint_cleanup
lj_deleter (thread
);
1420 sm
= new until_next_fsm (command_interp (), tp
->global_num
);
1421 tp
->set_thread_fsm (std::unique_ptr
<thread_fsm
> (sm
));
1422 lj_deleter
.release ();
1424 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1428 until_command (const char *arg
, int from_tty
)
1433 ensure_not_tfind_mode ();
1434 ensure_valid_thread ();
1435 ensure_not_running ();
1437 /* Find out whether we must run in the background. */
1438 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1439 arg
= stripped
.get ();
1441 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1444 until_break_command (arg
, from_tty
, 0);
1446 until_next_command (from_tty
);
1450 advance_command (const char *arg
, int from_tty
)
1455 ensure_not_tfind_mode ();
1456 ensure_valid_thread ();
1457 ensure_not_running ();
1460 error_no_arg (_("a location"));
1462 /* Find out whether we must run in the background. */
1463 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1464 arg
= stripped
.get ();
1466 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1468 until_break_command (arg
, from_tty
, 1);
1471 /* See inferior.h. */
1474 get_return_value (struct symbol
*func_symbol
, struct value
*function
)
1476 regcache
*stop_regs
= get_current_regcache ();
1477 struct gdbarch
*gdbarch
= stop_regs
->arch ();
1478 struct value
*value
;
1480 struct type
*value_type
1481 = check_typedef (func_symbol
->type ()->target_type ());
1482 gdb_assert (value_type
->code () != TYPE_CODE_VOID
);
1484 if (is_nocall_function (check_typedef (function
->type ())))
1486 warning (_("Function '%s' does not follow the target calling "
1487 "convention, cannot determine its returned value."),
1488 func_symbol
->print_name ());
1493 /* FIXME: 2003-09-27: When returning from a nested inferior function
1494 call, it's possible (with no help from the architecture vector)
1495 to locate and return/print a "struct return" value. This is just
1496 a more complicated case of what is already being done in the
1497 inferior function call code. In fact, when inferior function
1498 calls are made async, this will likely be made the norm. */
1500 switch (gdbarch_return_value_as_value (gdbarch
, function
, value_type
,
1501 nullptr, nullptr, nullptr))
1503 case RETURN_VALUE_REGISTER_CONVENTION
:
1504 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1505 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1506 gdbarch_return_value_as_value (gdbarch
, function
, value_type
, stop_regs
,
1509 case RETURN_VALUE_STRUCT_CONVENTION
:
1513 internal_error (_("bad switch"));
1519 /* The captured function return value/type and its position in the
1522 struct return_value_info
1524 /* The captured return value. May be NULL if we weren't able to
1525 retrieve it. See get_return_value. */
1526 struct value
*value
;
1528 /* The return type. In some cases, we'll not be able extract the
1529 return value, but we always know the type. */
1532 /* If we captured a value, this is the value history index. */
1533 int value_history_index
;
1536 /* Helper for print_return_value. */
1539 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1541 if (rv
->value
!= nullptr)
1544 uiout
->text ("Value returned is ");
1545 uiout
->field_fmt ("gdb-result-var", "$%d",
1546 rv
->value_history_index
);
1547 uiout
->text (" = ");
1551 struct value_print_options opts
;
1552 get_user_print_options (&opts
);
1555 value_print (rv
->value
, &stb
, &opts
);
1556 uiout
->field_stream ("return-value", stb
);
1559 uiout
->field_string ("return-value", _("<not displayed>"),
1560 metadata_style
.style ());
1565 std::string type_name
= type_to_string (rv
->type
);
1566 uiout
->text ("Value returned has type: ");
1567 uiout
->field_string ("return-type", type_name
);
1569 uiout
->text (" Cannot determine contents\n");
1573 /* Print the result of a function at the end of a 'finish' command.
1574 RV points at an object representing the captured return value/type
1575 and its position in the value history. */
1578 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1580 if (rv
->type
== nullptr
1581 || check_typedef (rv
->type
)->code () == TYPE_CODE_VOID
)
1586 /* print_return_value_1 can throw an exception in some
1587 circumstances. We need to catch this so that we still
1588 delete the breakpoint. */
1589 print_return_value_1 (uiout
, rv
);
1591 catch (const gdb_exception_error
&ex
)
1593 exception_print (gdb_stdout
, ex
);
1597 /* Data for the FSM that manages the finish command. */
1599 struct finish_command_fsm
: public thread_fsm
1601 /* The momentary breakpoint set at the function's return address in
1603 breakpoint_up breakpoint
;
1605 /* The function that we're stepping out of. */
1606 struct symbol
*function
= nullptr;
1608 /* If the FSM finishes successfully, this stores the function's
1610 struct return_value_info return_value_info
{};
1612 /* If the current function uses the "struct return convention",
1613 this holds the address at which the value being returned will
1614 be stored, or zero if that address could not be determined or
1615 the "struct return convention" is not being used. */
1616 CORE_ADDR return_buf
;
1618 explicit finish_command_fsm (struct interp
*cmd_interp
)
1619 : thread_fsm (cmd_interp
)
1623 bool should_stop (struct thread_info
*thread
) override
;
1624 void clean_up (struct thread_info
*thread
) override
;
1625 struct return_value_info
*return_value () override
;
1626 enum async_reply_reason
do_async_reply_reason () override
;
1629 /* Implementation of the 'should_stop' FSM method for the finish
1630 commands. Detects whether the thread stepped out of the function
1631 successfully, and if so, captures the function's return value and
1632 marks the FSM finished. */
1635 finish_command_fsm::should_stop (struct thread_info
*tp
)
1637 struct return_value_info
*rv
= &return_value_info
;
1639 if (function
!= nullptr
1640 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1641 breakpoint
.get ()) != nullptr)
1646 rv
->type
= function
->type ()->target_type ();
1647 if (rv
->type
== nullptr)
1648 internal_error (_("finish_command: function has no target type"));
1650 if (check_typedef (rv
->type
)->code () != TYPE_CODE_VOID
)
1654 func
= read_var_value (function
, nullptr, get_current_frame ());
1656 if (return_buf
!= 0)
1657 /* Retrieve return value from the buffer where it was saved. */
1658 rv
->value
= value_at (rv
->type
, return_buf
);
1660 rv
->value
= get_return_value (function
, func
);
1662 if (rv
->value
!= nullptr)
1663 rv
->value_history_index
= rv
->value
->record_latest ();
1666 else if (tp
->control
.stop_step
)
1668 /* Finishing from an inline frame, or reverse finishing. In
1669 either case, there's no way to retrieve the return value. */
1676 /* Implementation of the 'clean_up' FSM method for the finish
1680 finish_command_fsm::clean_up (struct thread_info
*thread
)
1682 breakpoint
.reset ();
1683 delete_longjmp_breakpoint (thread
->global_num
);
1686 /* Implementation of the 'return_value' FSM method for the finish
1689 struct return_value_info
*
1690 finish_command_fsm::return_value ()
1692 return &return_value_info
;
1695 /* Implementation of the 'async_reply_reason' FSM method for the
1698 enum async_reply_reason
1699 finish_command_fsm::do_async_reply_reason ()
1701 if (execution_direction
== EXEC_REVERSE
)
1702 return EXEC_ASYNC_END_STEPPING_RANGE
;
1704 return EXEC_ASYNC_FUNCTION_FINISHED
;
1707 /* finish_backward -- helper function for finish_command. */
1710 finish_backward (struct finish_command_fsm
*sm
)
1712 struct symtab_and_line sal
;
1713 struct thread_info
*tp
= inferior_thread ();
1715 CORE_ADDR func_addr
;
1716 CORE_ADDR alt_entry_point
;
1717 CORE_ADDR entry_point
;
1718 frame_info_ptr frame
= get_selected_frame (nullptr);
1719 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1721 pc
= get_frame_pc (get_current_frame ());
1723 if (find_pc_partial_function (pc
, nullptr, &func_addr
, nullptr) == 0)
1724 error (_("Cannot find bounds of current function"));
1726 sal
= find_pc_line (func_addr
, 0);
1727 alt_entry_point
= sal
.pc
;
1728 entry_point
= alt_entry_point
;
1730 if (gdbarch_skip_entrypoint_p (gdbarch
))
1731 /* Some architectures, like PowerPC use local and global entry points.
1732 There is only one Entry Point (GEP = LEP) for other architectures.
1733 The GEP is an alternate entry point. The LEP is the normal entry point.
1734 The value of entry_point was initialized to the alternate entry point
1735 (GEP). It will be adjusted to the normal entry point if the function
1736 has two entry points. */
1737 entry_point
= gdbarch_skip_entrypoint (gdbarch
, sal
.pc
);
1739 tp
->control
.proceed_to_finish
= 1;
1740 /* Special case: if we're sitting at the function entry point,
1741 then all we need to do is take a reverse singlestep. We
1742 don't need to set a breakpoint, and indeed it would do us
1745 Note that this can only happen at frame #0, since there's
1746 no way that a function up the stack can have a return address
1747 that's equal to its entry point. */
1749 if ((pc
< alt_entry_point
) || (pc
> entry_point
))
1751 /* We are in the body of the function. Set a breakpoint to go back to
1752 the normal entry point. */
1753 symtab_and_line sr_sal
;
1754 sr_sal
.pc
= entry_point
;
1755 sr_sal
.pspace
= get_frame_program_space (frame
);
1756 insert_step_resume_breakpoint_at_sal (gdbarch
,
1757 sr_sal
, null_frame_id
);
1759 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1763 /* We are either at one of the entry points or between the entry points.
1764 If we are not at the alt_entry point, go back to the alt_entry_point
1765 If we at the normal entry point step back one instruction, when we
1766 stop we will determine if we entered via the entry point or the
1767 alternate entry point. If we are at the alternate entry point,
1768 single step back to the function call. */
1769 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1770 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1774 /* finish_forward -- helper function for finish_command. FRAME is the
1775 frame that called the function we're about to step out of. */
1778 finish_forward (struct finish_command_fsm
*sm
, frame_info_ptr frame
)
1780 struct frame_id frame_id
= get_frame_id (frame
);
1781 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1782 struct symtab_and_line sal
;
1783 struct thread_info
*tp
= inferior_thread ();
1785 sal
= find_pc_line (get_frame_pc (frame
), 0);
1786 sal
.pc
= get_frame_pc (frame
);
1788 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1789 get_stack_frame_id (frame
),
1792 /* set_momentary_breakpoint invalidates FRAME. */
1795 set_longjmp_breakpoint (tp
, frame_id
);
1797 /* We want to print return value, please... */
1798 tp
->control
.proceed_to_finish
= 1;
1800 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1803 /* Skip frames for "finish". */
1805 static frame_info_ptr
1806 skip_finish_frames (frame_info_ptr frame
)
1808 frame_info_ptr start
;
1814 frame
= skip_tailcall_frames (frame
);
1815 if (frame
== nullptr)
1818 frame
= skip_unwritable_frames (frame
);
1819 if (frame
== nullptr)
1822 while (start
!= frame
);
1827 /* "finish": Set a temporary breakpoint at the place the selected
1828 frame will return to, then continue. */
1831 finish_command (const char *arg
, int from_tty
)
1833 frame_info_ptr frame
;
1835 struct finish_command_fsm
*sm
;
1836 struct thread_info
*tp
;
1839 ensure_not_tfind_mode ();
1840 ensure_valid_thread ();
1841 ensure_not_running ();
1843 /* Find out whether we must run in the background. */
1844 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1845 arg
= stripped
.get ();
1847 prepare_execution_command (current_inferior ()->top_target (), async_exec
);
1850 error (_("The \"finish\" command does not take any arguments."));
1852 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1854 error (_("\"finish\" not meaningful in the outermost frame."));
1856 clear_proceed_status (0);
1858 tp
= inferior_thread ();
1860 sm
= new finish_command_fsm (command_interp ());
1862 tp
->set_thread_fsm (std::unique_ptr
<thread_fsm
> (sm
));
1864 /* Finishing from an inline frame is completely different. We don't
1865 try to show the "return value" - no way to locate it. */
1866 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1869 /* Claim we are stepping in the calling frame. An empty step
1870 range means that we will stop once we aren't in a function
1871 called by that frame. We don't use the magic "1" value for
1872 step_range_end, because then infrun will think this is nexti,
1873 and not step over the rest of this inlined function call. */
1874 set_step_info (tp
, frame
, {});
1875 tp
->control
.step_range_start
= get_frame_pc (frame
);
1876 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1877 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1879 /* Print info on the selected frame, including level number but not
1883 gdb_printf (_("Run till exit from "));
1884 print_stack_frame (get_selected_frame (nullptr), 1, LOCATION
, 0);
1887 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1891 /* Find the function we will return from. */
1892 frame_info_ptr callee_frame
= get_selected_frame (nullptr);
1893 sm
->function
= find_pc_function (get_frame_pc (callee_frame
));
1894 sm
->return_buf
= 0; /* Initialize buffer address is not available. */
1896 /* Determine the return convention. If it is RETURN_VALUE_STRUCT_CONVENTION,
1897 attempt to determine the address of the return buffer. */
1898 if (sm
->function
!= nullptr)
1900 enum return_value_convention return_value
;
1901 struct gdbarch
*gdbarch
= get_frame_arch (callee_frame
);
1903 struct type
* val_type
1904 = check_typedef (sm
->function
->type ()->target_type ());
1907 = gdbarch_return_value_as_value (gdbarch
,
1908 read_var_value (sm
->function
, nullptr,
1910 val_type
, nullptr, nullptr, nullptr);
1912 if (return_value
== RETURN_VALUE_STRUCT_CONVENTION
1913 && val_type
->code () != TYPE_CODE_VOID
)
1914 sm
->return_buf
= gdbarch_get_return_buf_addr (gdbarch
, val_type
,
1918 /* Print info on the selected frame, including level number but not
1922 if (execution_direction
== EXEC_REVERSE
)
1923 gdb_printf (_("Run back to call of "));
1926 if (sm
->function
!= nullptr && TYPE_NO_RETURN (sm
->function
->type ())
1927 && !query (_("warning: Function %s does not return normally.\n"
1928 "Try to finish anyway? "),
1929 sm
->function
->print_name ()))
1930 error (_("Not confirmed."));
1931 gdb_printf (_("Run till exit from "));
1934 print_stack_frame (callee_frame
, 1, LOCATION
, 0);
1937 if (execution_direction
== EXEC_REVERSE
)
1938 finish_backward (sm
);
1941 frame
= skip_finish_frames (frame
);
1943 if (frame
== nullptr)
1944 error (_("Cannot find the caller frame."));
1946 finish_forward (sm
, frame
);
1952 info_program_command (const char *args
, int from_tty
)
1954 scoped_restore_current_thread restore_thread
;
1958 /* In non-stop, since every thread is controlled individually, we'll
1959 show execution info about the current thread. In all-stop, we'll
1960 show execution info about the last stop. */
1964 if (!target_has_execution ())
1966 gdb_printf (_("The program being debugged is not being run.\n"));
1970 if (inferior_ptid
== null_ptid
)
1971 error (_("No selected thread."));
1973 tp
= inferior_thread ();
1975 gdb_printf (_("Selected thread %s (%s).\n"),
1976 print_thread_id (tp
),
1977 target_pid_to_str (tp
->ptid
).c_str ());
1979 if (tp
->state
== THREAD_EXITED
)
1981 gdb_printf (_("Selected thread has exited.\n"));
1984 else if (tp
->state
== THREAD_RUNNING
)
1986 gdb_printf (_("Selected thread is running.\n"));
1992 tp
= get_previous_thread ();
1996 gdb_printf (_("The program being debugged is not being run.\n"));
2000 switch_to_thread (tp
);
2002 gdb_printf (_("Last stopped for thread %s (%s).\n"),
2003 print_thread_id (tp
),
2004 target_pid_to_str (tp
->ptid
).c_str ());
2006 if (tp
->state
== THREAD_EXITED
)
2008 gdb_printf (_("Thread has since exited.\n"));
2012 if (tp
->state
== THREAD_RUNNING
)
2014 gdb_printf (_("Thread is now running.\n"));
2020 bpstat
*bs
= tp
->control
.stop_bpstat
;
2021 int stat
= bpstat_num (&bs
, &num
);
2023 target_files_info ();
2024 gdb_printf (_("Program stopped at %s.\n"),
2025 paddress (target_gdbarch (), tp
->stop_pc ()));
2026 if (tp
->control
.stop_step
)
2027 gdb_printf (_("It stopped after being stepped.\n"));
2030 /* There may be several breakpoints in the same place, so this
2031 isn't as strange as it seems. */
2036 gdb_printf (_("It stopped at a breakpoint "
2037 "that has since been deleted.\n"));
2040 gdb_printf (_("It stopped at breakpoint %d.\n"), num
);
2041 stat
= bpstat_num (&bs
, &num
);
2044 else if (tp
->stop_signal () != GDB_SIGNAL_0
)
2046 gdb_printf (_("It stopped with signal %s, %s.\n"),
2047 gdb_signal_to_name (tp
->stop_signal ()),
2048 gdb_signal_to_string (tp
->stop_signal ()));
2053 gdb_printf (_("Type \"info stack\" or \"info "
2054 "registers\" for more information.\n"));
2059 environment_info (const char *var
, int from_tty
)
2063 const char *val
= current_inferior ()->environment
.get (var
);
2074 gdb_puts ("Environment variable \"");
2076 gdb_puts ("\" not defined.\n");
2081 char **envp
= current_inferior ()->environment
.envp ();
2083 for (int idx
= 0; envp
[idx
] != nullptr; ++idx
)
2085 gdb_puts (envp
[idx
]);
2092 set_environment_command (const char *arg
, int from_tty
)
2094 const char *p
, *val
;
2098 error_no_arg (_("environment variable and value"));
2100 /* Find separation between variable name and value. */
2101 p
= (char *) strchr (arg
, '=');
2102 val
= (char *) strchr (arg
, ' ');
2104 if (p
!= 0 && val
!= 0)
2106 /* We have both a space and an equals. If the space is before the
2107 equals, walk forward over the spaces til we see a nonspace
2108 (possibly the equals). */
2113 /* Now if the = is after the char following the spaces,
2114 take the char following the spaces. */
2118 else if (val
!= 0 && p
== 0)
2122 error_no_arg (_("environment variable to set"));
2124 if (p
== 0 || p
[1] == 0)
2128 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2132 /* Not setting variable value to null. */
2134 while (*val
== ' ' || *val
== '\t')
2138 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2141 std::string
var (arg
, p
- arg
);
2144 gdb_printf (_("Setting environment variable "
2145 "\"%s\" to null value.\n"),
2147 current_inferior ()->environment
.set (var
.c_str (), "");
2150 current_inferior ()->environment
.set (var
.c_str (), val
);
2154 unset_environment_command (const char *var
, int from_tty
)
2158 /* If there is no argument, delete all environment variables.
2159 Ask for confirmation if reading from the terminal. */
2160 if (!from_tty
|| query (_("Delete all environment variables? ")))
2161 current_inferior ()->environment
.clear ();
2164 current_inferior ()->environment
.unset (var
);
2167 /* Handle the execution path (PATH variable). */
2169 static const char path_var_name
[] = "PATH";
2172 path_info (const char *args
, int from_tty
)
2174 gdb_puts ("Executable and object file path: ");
2175 gdb_puts (current_inferior ()->environment
.get (path_var_name
));
2179 /* Add zero or more directories to the front of the execution path. */
2182 path_command (const char *dirname
, int from_tty
)
2187 env
= current_inferior ()->environment
.get (path_var_name
);
2188 /* Can be null if path is not set. */
2191 std::string exec_path
= env
;
2192 mod_path (dirname
, exec_path
);
2193 current_inferior ()->environment
.set (path_var_name
, exec_path
.c_str ());
2195 path_info (nullptr, from_tty
);
2200 pad_to_column (string_file
&stream
, int col
)
2202 /* At least one space must be printed to separate columns. */
2204 const int size
= stream
.size ();
2206 stream
.puts (n_spaces (col
- size
));
2209 /* Print out the register NAME with value VAL, to FILE, in the default
2213 default_print_one_register_info (struct ui_file
*file
,
2217 struct type
*regtype
= val
->type ();
2218 int print_raw_format
;
2219 string_file format_stream
;
2222 value_column_1
= 15,
2223 /* Give enough room for "0x", 16 hex digits and two spaces in
2224 preceding column. */
2225 value_column_2
= value_column_1
+ 2 + 16 + 2,
2228 format_stream
.puts (name
);
2229 pad_to_column (format_stream
, value_column_1
);
2231 print_raw_format
= (val
->entirely_available ()
2232 && !val
->optimized_out ());
2234 /* If virtual format is floating, print it that way, and in raw
2236 if (regtype
->code () == TYPE_CODE_FLT
2237 || regtype
->code () == TYPE_CODE_DECFLOAT
)
2239 struct value_print_options opts
;
2240 const gdb_byte
*valaddr
= val
->contents_for_printing ().data ();
2241 enum bfd_endian byte_order
= type_byte_order (regtype
);
2243 get_user_print_options (&opts
);
2244 opts
.deref_ref
= true;
2246 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2248 if (print_raw_format
)
2250 pad_to_column (format_stream
, value_column_2
);
2251 format_stream
.puts ("(raw ");
2252 print_hex_chars (&format_stream
, valaddr
, regtype
->length (),
2254 format_stream
.putc (')');
2259 struct value_print_options opts
;
2261 /* Print the register in hex. */
2262 get_formatted_print_options (&opts
, 'x');
2263 opts
.deref_ref
= true;
2264 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2265 /* If not a vector register, print it also according to its
2267 if (print_raw_format
&& regtype
->is_vector () == 0)
2269 pad_to_column (format_stream
, value_column_2
);
2270 get_user_print_options (&opts
);
2271 opts
.deref_ref
= true;
2272 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2276 gdb_puts (format_stream
.c_str (), file
);
2277 gdb_printf (file
, "\n");
2280 /* Print out the machine register regnum. If regnum is -1, print all
2281 registers (print_all == 1) or all non-float and non-vector
2282 registers (print_all == 0).
2284 For most machines, having all_registers_info() print the
2285 register(s) one per line is good enough. If a different format is
2286 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2287 regs), or there is an existing convention for showing all the
2288 registers, define the architecture method PRINT_REGISTERS_INFO to
2289 provide that format. */
2292 default_print_registers_info (struct gdbarch
*gdbarch
,
2293 struct ui_file
*file
,
2294 frame_info_ptr frame
,
2295 int regnum
, int print_all
)
2298 const int numregs
= gdbarch_num_cooked_regs (gdbarch
);
2300 for (i
= 0; i
< numregs
; i
++)
2302 /* Decide between printing all regs, non-float / vector regs, or
2308 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2313 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2323 /* If the register name is empty, it is undefined for this
2324 processor, so don't display anything. */
2325 if (*(gdbarch_register_name (gdbarch
, i
)) == '\0')
2328 default_print_one_register_info (file
,
2329 gdbarch_register_name (gdbarch
, i
),
2330 value_of_register (i
, frame
));
2335 registers_info (const char *addr_exp
, int fpregs
)
2337 frame_info_ptr frame
;
2338 struct gdbarch
*gdbarch
;
2340 if (!target_has_registers ())
2341 error (_("The program has no registers now."));
2342 frame
= get_selected_frame (nullptr);
2343 gdbarch
= get_frame_arch (frame
);
2347 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2352 while (*addr_exp
!= '\0')
2357 /* Skip leading white space. */
2358 addr_exp
= skip_spaces (addr_exp
);
2360 /* Discard any leading ``$''. Check that there is something
2361 resembling a register following it. */
2362 if (addr_exp
[0] == '$')
2364 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2365 error (_("Missing register name"));
2367 /* Find the start/end of this register name/num/group. */
2369 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2373 /* Figure out what we've found and display it. */
2375 /* A register name? */
2377 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2381 /* User registers lie completely outside of the range of
2382 normal registers. Catch them early so that the target
2384 if (regnum
>= gdbarch_num_cooked_regs (gdbarch
))
2386 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2387 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2390 /* Print in the same fashion
2391 gdbarch_print_registers_info's default
2392 implementation prints. */
2393 default_print_one_register_info (gdb_stdout
,
2398 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2399 frame
, regnum
, fpregs
);
2404 /* A register group? */
2406 const struct reggroup
*group
= nullptr;
2407 for (const struct reggroup
*g
: gdbarch_reggroups (gdbarch
))
2409 /* Don't bother with a length check. Should the user
2410 enter a short register group name, go with the first
2411 group that matches. */
2412 if (strncmp (start
, g
->name (), end
- start
) == 0)
2418 if (group
!= nullptr)
2423 regnum
< gdbarch_num_cooked_regs (gdbarch
);
2426 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2427 gdbarch_print_registers_info (gdbarch
,
2435 /* Nothing matched. */
2436 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2441 info_all_registers_command (const char *addr_exp
, int from_tty
)
2443 registers_info (addr_exp
, 1);
2447 info_registers_command (const char *addr_exp
, int from_tty
)
2449 registers_info (addr_exp
, 0);
2453 print_vector_info (struct ui_file
*file
,
2454 frame_info_ptr frame
, const char *args
)
2456 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2458 if (gdbarch_print_vector_info_p (gdbarch
))
2459 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2463 int printed_something
= 0;
2465 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2467 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2469 printed_something
= 1;
2470 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2473 if (!printed_something
)
2474 gdb_printf (file
, "No vector information\n");
2479 info_vector_command (const char *args
, int from_tty
)
2481 if (!target_has_registers ())
2482 error (_("The program has no registers now."));
2484 print_vector_info (gdb_stdout
, get_selected_frame (nullptr), args
);
2487 /* Kill the inferior process. Make us have no inferior. */
2490 kill_command (const char *arg
, int from_tty
)
2492 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2493 It should be a distinct flag that indicates that a target is active, cuz
2494 some targets don't have processes! */
2496 if (inferior_ptid
== null_ptid
)
2497 error (_("The program is not being run."));
2498 if (!query (_("Kill the program being debugged? ")))
2499 error (_("Not confirmed."));
2501 int pid
= current_inferior ()->pid
;
2502 /* Save the pid as a string before killing the inferior, since that
2503 may unpush the current target, and we need the string after. */
2504 std::string pid_str
= target_pid_to_str (ptid_t (pid
));
2505 int infnum
= current_inferior ()->num
;
2508 bfd_cache_close_all ();
2510 update_previous_thread ();
2512 if (print_inferior_events
)
2513 gdb_printf (_("[Inferior %d (%s) killed]\n"),
2514 infnum
, pid_str
.c_str ());
2517 /* Used in `attach&' command. Proceed threads of inferior INF iff
2518 they stopped due to debugger request, and when they did, they
2519 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2520 have been explicitly been told to stop. */
2523 proceed_after_attach (inferior
*inf
)
2525 /* Don't error out if the current thread is running, because
2526 there may be other stopped threads. */
2528 /* Backup current thread and selected frame. */
2529 scoped_restore_current_thread restore_thread
;
2531 for (thread_info
*thread
: inf
->non_exited_threads ())
2532 if (!thread
->executing ()
2533 && !thread
->stop_requested
2534 && thread
->stop_signal () == GDB_SIGNAL_0
)
2536 switch_to_thread (thread
);
2537 clear_proceed_status (0);
2538 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2542 /* See inferior.h. */
2545 setup_inferior (int from_tty
)
2547 struct inferior
*inferior
;
2549 inferior
= current_inferior ();
2550 inferior
->needs_setup
= false;
2552 /* If no exec file is yet known, try to determine it from the
2554 if (get_exec_file (0) == nullptr)
2555 exec_file_locate_attach (inferior_ptid
.pid (), 1, from_tty
);
2558 reopen_exec_file ();
2559 reread_symbols (from_tty
);
2562 /* Take any necessary post-attaching actions for this platform. */
2563 target_post_attach (inferior_ptid
.pid ());
2565 post_create_inferior (from_tty
);
2568 /* What to do after the first program stops after attaching. */
2569 enum attach_post_wait_mode
2571 /* Do nothing. Leaves threads as they are. */
2572 ATTACH_POST_WAIT_NOTHING
,
2574 /* Re-resume threads that are marked running. */
2575 ATTACH_POST_WAIT_RESUME
,
2577 /* Stop all threads. */
2578 ATTACH_POST_WAIT_STOP
,
2581 /* Called after we've attached to a process and we've seen it stop for
2582 the first time. Resume, stop, or don't touch the threads according
2586 attach_post_wait (int from_tty
, enum attach_post_wait_mode mode
)
2588 struct inferior
*inferior
;
2590 inferior
= current_inferior ();
2591 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2593 if (inferior
->needs_setup
)
2594 setup_inferior (from_tty
);
2596 if (mode
== ATTACH_POST_WAIT_RESUME
)
2598 /* The user requested an `attach&', so be sure to leave threads
2599 that didn't get a signal running. */
2601 /* Immediately resume all suspended threads of this inferior,
2602 and this inferior only. This should have no effect on
2603 already running threads. If a thread has been stopped with a
2604 signal, leave it be. */
2606 proceed_after_attach (inferior
);
2609 if (inferior_thread ()->stop_signal () == GDB_SIGNAL_0
)
2611 clear_proceed_status (0);
2612 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2616 else if (mode
== ATTACH_POST_WAIT_STOP
)
2618 /* The user requested a plain `attach', so be sure to leave
2619 the inferior stopped. */
2621 /* At least the current thread is already stopped. */
2623 /* In all-stop, by definition, all threads have to be already
2624 stopped at this point. In non-stop, however, although the
2625 selected thread is stopped, others may still be executing.
2626 Be sure to explicitly stop all threads of the process. This
2627 should have no effect on already stopped threads. */
2629 target_stop (ptid_t (inferior
->pid
));
2630 else if (target_is_non_stop_p ())
2632 struct thread_info
*lowest
= inferior_thread ();
2634 stop_all_threads ("attaching");
2636 /* It's not defined which thread will report the attach
2637 stop. For consistency, always select the thread with
2638 lowest GDB number, which should be the main thread, if it
2640 for (thread_info
*thread
: current_inferior ()->non_exited_threads ())
2641 if (thread
->inf
->num
< lowest
->inf
->num
2642 || thread
->per_inf_num
< lowest
->per_inf_num
)
2645 switch_to_thread (lowest
);
2648 /* Tell the user/frontend where we're stopped. */
2650 if (deprecated_attach_hook
)
2651 deprecated_attach_hook ();
2655 /* "attach" command entry point. Takes a program started up outside
2656 of gdb and ``attaches'' to it. This stops it cold in its tracks
2657 and allows us to start debugging it. */
2660 attach_command (const char *args
, int from_tty
)
2663 struct target_ops
*attach_target
;
2664 struct inferior
*inferior
= current_inferior ();
2665 enum attach_post_wait_mode mode
;
2667 dont_repeat (); /* Not for the faint of heart */
2669 scoped_disable_commit_resumed
disable_commit_resumed ("attaching");
2671 if (gdbarch_has_global_solist (target_gdbarch ()))
2672 /* Don't complain if all processes share the same symbol
2675 else if (target_has_execution ())
2677 if (query (_("A program is being debugged already. Kill it? ")))
2680 error (_("Not killed."));
2683 /* Clean up any leftovers from other runs. Some other things from
2684 this function should probably be moved into target_pre_inferior. */
2685 target_pre_inferior (from_tty
);
2687 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
2688 args
= stripped
.get ();
2690 attach_target
= find_attach_target ();
2692 prepare_execution_command (attach_target
, async_exec
);
2694 if (non_stop
&& !attach_target
->supports_non_stop ())
2695 error (_("Cannot attach to this target in non-stop mode"));
2697 attach_target
->attach (args
, from_tty
);
2698 /* to_attach should push the target, so after this point we
2699 shouldn't refer to attach_target again. */
2700 attach_target
= nullptr;
2702 infrun_debug_show_threads ("immediately after attach",
2703 current_inferior ()->non_exited_threads ());
2705 /* Enable async mode if it is supported by the target. */
2706 if (target_can_async_p ())
2707 target_async (true);
2709 /* Set up the "saved terminal modes" of the inferior
2710 based on what modes we are starting it with. */
2711 target_terminal::init ();
2713 /* Install inferior's terminal modes. This may look like a no-op,
2714 as we've just saved them above, however, this does more than
2715 restore terminal settings:
2717 - installs a SIGINT handler that forwards SIGINT to the inferior.
2718 Otherwise a Ctrl-C pressed just while waiting for the initial
2719 stop would end up as a spurious Quit.
2721 - removes stdin from the event loop, which we need if attaching
2722 in the foreground, otherwise on targets that report an initial
2723 stop on attach (which are most) we'd process input/commands
2724 while we're in the event loop waiting for that stop. That is,
2725 before the attach continuation runs and the command is really
2727 target_terminal::inferior ();
2729 /* Set up execution context to know that we should return from
2730 wait_for_inferior as soon as the target reports a stop. */
2731 init_wait_for_inferior ();
2733 inferior
->needs_setup
= true;
2735 if (target_is_non_stop_p ())
2737 /* If we find that the current thread isn't stopped, explicitly
2738 do so now, because we're going to install breakpoints and
2742 /* The user requested an `attach&'; stop just one thread. */
2743 target_stop (inferior_ptid
);
2745 /* The user requested an `attach', so stop all threads of this
2747 target_stop (ptid_t (inferior_ptid
.pid ()));
2750 /* Check for exec file mismatch, and let the user solve it. */
2751 validate_exec_file (from_tty
);
2753 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2755 /* Some system don't generate traps when attaching to inferior.
2756 E.g. Mach 3 or GNU hurd. */
2757 if (!target_attach_no_wait ())
2759 /* Careful here. See comments in inferior.h. Basically some
2760 OSes don't ignore SIGSTOPs on continue requests anymore. We
2761 need a way for handle_inferior_event to reset the stop_signal
2762 variable after an attach, and this is what
2763 STOP_QUIETLY_NO_SIGSTOP is for. */
2764 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2766 /* Wait for stop. */
2767 inferior
->add_continuation ([=] ()
2769 attach_post_wait (from_tty
, mode
);
2772 /* Let infrun consider waiting for events out of this
2774 inferior
->process_target ()->threads_executing
= true;
2776 if (!target_is_async_p ())
2777 mark_infrun_async_event_handler ();
2781 attach_post_wait (from_tty
, mode
);
2783 disable_commit_resumed
.reset_and_commit ();
2786 /* We had just found out that the target was already attached to an
2787 inferior. PTID points at a thread of this new inferior, that is
2788 the most likely to be stopped right now, but not necessarily so.
2789 The new inferior is assumed to be already added to the inferior
2790 list at this point. If LEAVE_RUNNING, then leave the threads of
2791 this inferior running, except those we've explicitly seen reported
2795 notice_new_inferior (thread_info
*thr
, bool leave_running
, int from_tty
)
2797 enum attach_post_wait_mode mode
2798 = leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2800 gdb::optional
<scoped_restore_current_thread
> restore_thread
;
2802 if (inferior_ptid
!= null_ptid
)
2803 restore_thread
.emplace ();
2805 /* Avoid reading registers -- we haven't fetched the target
2807 switch_to_thread_no_regs (thr
);
2809 /* When we "notice" a new inferior we need to do all the things we
2810 would normally do if we had just attached to it. */
2812 if (thr
->executing ())
2814 struct inferior
*inferior
= current_inferior ();
2816 /* We're going to install breakpoints, and poke at memory,
2817 ensure that the inferior is stopped for a moment while we do
2819 target_stop (inferior_ptid
);
2821 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2823 /* Wait for stop before proceeding. */
2824 inferior
->add_continuation ([=] ()
2826 attach_post_wait (from_tty
, mode
);
2832 attach_post_wait (from_tty
, mode
);
2837 * takes a program previously attached to and detaches it.
2838 * The program resumes execution and will no longer stop
2839 * on signals, etc. We better not have left any breakpoints
2840 * in the program or it'll die when it hits one. For this
2841 * to work, it may be necessary for the process to have been
2842 * previously attached. It *might* work if the program was
2843 * started via the normal ptrace (PTRACE_TRACEME).
2847 detach_command (const char *args
, int from_tty
)
2849 dont_repeat (); /* Not for the faint of heart. */
2851 if (inferior_ptid
== null_ptid
)
2852 error (_("The program is not being run."));
2854 scoped_disable_commit_resumed
disable_commit_resumed ("detaching");
2856 query_if_trace_running (from_tty
);
2858 disconnect_tracing ();
2860 /* Hold a strong reference to the target while (maybe)
2861 detaching the parent. Otherwise detaching could close the
2864 = target_ops_ref::new_reference (current_inferior ()->process_target ());
2866 /* Save this before detaching, since detaching may unpush the
2867 process_stratum target. */
2868 bool was_non_stop_p
= target_is_non_stop_p ();
2870 target_detach (current_inferior (), from_tty
);
2872 update_previous_thread ();
2874 /* The current inferior process was just detached successfully. Get
2875 rid of breakpoints that no longer make sense. Note we don't do
2876 this within target_detach because that is also used when
2877 following child forks, and in that case we will want to transfer
2878 breakpoints to the child, not delete them. */
2879 breakpoint_init_inferior (inf_exited
);
2881 /* If the solist is global across inferiors, don't clear it when we
2882 detach from a single inferior. */
2883 if (!gdbarch_has_global_solist (target_gdbarch ()))
2884 no_shared_libraries (nullptr, from_tty
);
2886 if (deprecated_detach_hook
)
2887 deprecated_detach_hook ();
2889 if (!was_non_stop_p
)
2890 restart_after_all_stop_detach (as_process_stratum_target (target_ref
.get ()));
2892 disable_commit_resumed
.reset_and_commit ();
2895 /* Disconnect from the current target without resuming it (leaving it
2896 waiting for a debugger).
2898 We'd better not have left any breakpoints in the program or the
2899 next debugger will get confused. Currently only supported for some
2900 remote targets, since the normal attach mechanisms don't work on
2901 stopped processes on some native platforms (e.g. GNU/Linux). */
2904 disconnect_command (const char *args
, int from_tty
)
2906 dont_repeat (); /* Not for the faint of heart. */
2907 query_if_trace_running (from_tty
);
2908 disconnect_tracing ();
2909 target_disconnect (args
, from_tty
);
2910 no_shared_libraries (nullptr, from_tty
);
2911 init_thread_list ();
2912 update_previous_thread ();
2913 if (deprecated_detach_hook
)
2914 deprecated_detach_hook ();
2917 /* Stop PTID in the current target, and tag the PTID threads as having
2918 been explicitly requested to stop. PTID can be a thread, a
2919 process, or minus_one_ptid, meaning all threads of all inferiors of
2920 the current target. */
2923 stop_current_target_threads_ns (ptid_t ptid
)
2927 /* Tag the thread as having been explicitly requested to stop, so
2928 other parts of gdb know not to resume this thread automatically,
2929 if it was stopped due to an internal event. Limit this to
2930 non-stop mode, as when debugging a multi-threaded application in
2931 all-stop mode, we will only get one stop event --- it's undefined
2932 which thread will report the event. */
2933 set_stop_requested (current_inferior ()->process_target (),
2937 /* See inferior.h. */
2940 interrupt_target_1 (bool all_threads
)
2942 scoped_disable_commit_resumed
disable_commit_resumed ("interrupting");
2948 scoped_restore_current_thread restore_thread
;
2950 for (inferior
*inf
: all_inferiors ())
2952 switch_to_inferior_no_thread (inf
);
2953 stop_current_target_threads_ns (minus_one_ptid
);
2957 stop_current_target_threads_ns (inferior_ptid
);
2960 target_interrupt ();
2962 disable_commit_resumed
.reset_and_commit ();
2966 Stop the execution of the target while running in async mode, in
2967 the background. In all-stop, stop the whole process. In non-stop
2968 mode, stop the current thread only by default, or stop all threads
2969 if the `-a' switch is used. */
2972 interrupt_command (const char *args
, int from_tty
)
2974 if (target_can_async_p ())
2976 int all_threads
= 0;
2978 dont_repeat (); /* Not for the faint of heart. */
2981 && startswith (args
, "-a"))
2984 interrupt_target_1 (all_threads
);
2988 /* See inferior.h. */
2991 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2992 frame_info_ptr frame
, const char *args
)
2995 int printed_something
= 0;
2997 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2999 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
3001 printed_something
= 1;
3002 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
3005 if (!printed_something
)
3006 gdb_printf (file
, "No floating-point info "
3007 "available for this processor.\n");
3011 info_float_command (const char *args
, int from_tty
)
3013 frame_info_ptr frame
;
3015 if (!target_has_registers ())
3016 error (_("The program has no registers now."));
3018 frame
= get_selected_frame (nullptr);
3019 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
3022 /* Implement `info proc' family of commands. */
3025 info_proc_cmd_1 (const char *args
, enum info_proc_what what
, int from_tty
)
3027 struct gdbarch
*gdbarch
= get_current_arch ();
3029 if (!target_info_proc (args
, what
))
3031 if (gdbarch_info_proc_p (gdbarch
))
3032 gdbarch_info_proc (gdbarch
, args
, what
);
3034 error (_("Not supported on this target."));
3038 /* Implement `info proc' when given without any further parameters. */
3041 info_proc_cmd (const char *args
, int from_tty
)
3043 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
3046 /* Implement `info proc mappings'. */
3049 info_proc_cmd_mappings (const char *args
, int from_tty
)
3051 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
3054 /* Implement `info proc stat'. */
3057 info_proc_cmd_stat (const char *args
, int from_tty
)
3059 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
3062 /* Implement `info proc status'. */
3065 info_proc_cmd_status (const char *args
, int from_tty
)
3067 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
3070 /* Implement `info proc cwd'. */
3073 info_proc_cmd_cwd (const char *args
, int from_tty
)
3075 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
3078 /* Implement `info proc cmdline'. */
3081 info_proc_cmd_cmdline (const char *args
, int from_tty
)
3083 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
3086 /* Implement `info proc exe'. */
3089 info_proc_cmd_exe (const char *args
, int from_tty
)
3091 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
3094 /* Implement `info proc files'. */
3097 info_proc_cmd_files (const char *args
, int from_tty
)
3099 info_proc_cmd_1 (args
, IP_FILES
, from_tty
);
3102 /* Implement `info proc all'. */
3105 info_proc_cmd_all (const char *args
, int from_tty
)
3107 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
3110 /* Implement `show print finish'. */
3113 show_print_finish (struct ui_file
*file
, int from_tty
,
3114 struct cmd_list_element
*c
,
3117 gdb_printf (file
, _("\
3118 Printing of return value after `finish' is %s.\n"),
3123 /* This help string is used for the run, start, and starti commands.
3124 It is defined as a macro to prevent duplication. */
3126 #define RUN_ARGS_HELP \
3127 "You may specify arguments to give it.\n\
3128 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3129 shell that will start the program (specified by the \"$SHELL\" environment\n\
3130 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
3131 are also allowed.\n\
3133 With no arguments, uses arguments last specified (with \"run\" or \n\
3134 \"set args\"). To cancel previous arguments and run with no arguments,\n\
3135 use \"set args\" without arguments.\n\
3137 To start the inferior without using a shell, use \"set startup-with-shell off\"."
3139 void _initialize_infcmd ();
3141 _initialize_infcmd ()
3143 static struct cmd_list_element
*info_proc_cmdlist
;
3144 struct cmd_list_element
*c
= nullptr;
3146 /* Add the filename of the terminal connected to inferior I/O. */
3148 = add_setshow_optional_filename_cmd ("inferior-tty", class_run
, _("\
3149 Set terminal for future runs of program being debugged."), _(" \
3150 Show terminal for future runs of program being debugged."), _(" \
3151 Usage: set inferior-tty [TTY]\n\n \
3152 If TTY is omitted, the default behavior of using the same terminal as GDB\n \
3156 show_inferior_tty_command
,
3157 &setlist
, &showlist
);
3158 add_alias_cmd ("tty", tty_set_show
.set
, class_run
, 0, &cmdlist
);
3161 = add_setshow_string_noescape_cmd ("args", class_run
, _("\
3162 Set argument list to give program being debugged when it is started."), _("\
3163 Show argument list to give program being debugged when it is started."), _("\
3164 Follow this command with any number of args, to be passed to the program."),
3168 &setlist
, &showlist
);
3169 set_cmd_completer (args_set_show
.set
, filename_completer
);
3172 = add_setshow_string_noescape_cmd ("cwd", class_run
, _("\
3173 Set the current working directory to be used when the inferior is started.\n \
3174 Changing this setting does not have any effect on inferiors that are\n \
3177 Show the current working directory that is used when the inferior is started."),
3179 Use this command to change the current working directory that will be used\n\
3180 when the inferior is started. This setting does not affect GDB's current\n\
3181 working directory."),
3182 set_cwd_value
, get_inferior_cwd
,
3184 &setlist
, &showlist
);
3185 set_cmd_completer (cwd_set_show
.set
, filename_completer
);
3187 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3188 The environment to give the program, or one variable's value.\n\
3189 With an argument VAR, prints the value of environment variable VAR to\n\
3190 give the program being debugged. With no arguments, prints the entire\n\
3191 environment to be given to the program."), &showlist
);
3192 set_cmd_completer (c
, noop_completer
);
3194 add_basic_prefix_cmd ("unset", no_class
,
3195 _("Complement to certain \"set\" commands."),
3196 &unsetlist
, 0, &cmdlist
);
3198 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3199 Cancel environment variable VAR for the program.\n\
3200 This does not affect the program until the next \"run\" command."),
3202 set_cmd_completer (c
, noop_completer
);
3204 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3205 Set environment variable value to give the program.\n\
3206 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3207 VALUES of environment variables are uninterpreted strings.\n\
3208 This does not affect the program until the next \"run\" command."),
3210 set_cmd_completer (c
, noop_completer
);
3212 c
= add_com ("path", class_files
, path_command
, _("\
3213 Add directory DIR(s) to beginning of search path for object files.\n\
3214 $cwd in the path means the current working directory.\n\
3215 This path is equivalent to the $PATH shell variable. It is a list of\n\
3216 directories, separated by colons. These directories are searched to find\n\
3217 fully linked executable files and separately compiled object files as \
3219 set_cmd_completer (c
, filename_completer
);
3221 c
= add_cmd ("paths", no_class
, path_info
, _("\
3222 Current search path for finding object files.\n\
3223 $cwd in the path means the current working directory.\n\
3224 This path is equivalent to the $PATH shell variable. It is a list of\n\
3225 directories, separated by colons. These directories are searched to find\n\
3226 fully linked executable files and separately compiled object files as \
3229 set_cmd_completer (c
, noop_completer
);
3231 add_prefix_cmd ("kill", class_run
, kill_command
,
3232 _("Kill execution of program being debugged."),
3233 &killlist
, 0, &cmdlist
);
3235 add_com ("attach", class_run
, attach_command
, _("\
3236 Attach to a process or file outside of GDB.\n\
3237 This command attaches to another target, of the same type as your last\n\
3238 \"target\" command (\"info files\" will show your target stack).\n\
3239 The command may take as argument a process id or a device file.\n\
3240 For a process id, you must have permission to send the process a signal,\n\
3241 and it must have the same effective uid as the debugger.\n\
3242 When using \"attach\" with a process id, the debugger finds the\n\
3243 program running in the process, looking first in the current working\n\
3244 directory, or (if not found there) using the source file search path\n\
3245 (see the \"directory\" command). You can also use the \"file\" command\n\
3246 to specify the program, and to load its symbol table."));
3248 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3249 Detach a process or file previously attached.\n\
3250 If a process, it is no longer traced, and it continues its execution. If\n\
3251 you were debugging a file, the file is closed and gdb no longer accesses it."),
3252 &detachlist
, 0, &cmdlist
);
3254 add_com ("disconnect", class_run
, disconnect_command
, _("\
3255 Disconnect from a target.\n\
3256 The target will wait for another debugger to connect. Not available for\n\
3259 c
= add_com ("signal", class_run
, signal_command
, _("\
3260 Continue program with the specified signal.\n\
3261 Usage: signal SIGNAL\n\
3262 The SIGNAL argument is processed the same as the handle command.\n\
3264 An argument of \"0\" means continue the program without sending it a signal.\n\
3265 This is useful in cases where the program stopped because of a signal,\n\
3266 and you want to resume the program while discarding the signal.\n\
3268 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3269 the current thread only."));
3270 set_cmd_completer (c
, signal_completer
);
3272 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3273 Queue a signal to be delivered to the current thread when it is resumed.\n\
3274 Usage: queue-signal SIGNAL\n\
3275 The SIGNAL argument is processed the same as the handle command.\n\
3276 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3278 An argument of \"0\" means remove any currently queued signal from\n\
3279 the current thread. This is useful in cases where the program stopped\n\
3280 because of a signal, and you want to resume it while discarding the signal.\n\
3282 In a multi-threaded program the signal is queued with, or discarded from,\n\
3283 the current thread only."));
3284 set_cmd_completer (c
, signal_completer
);
3286 cmd_list_element
*stepi_cmd
3287 = add_com ("stepi", class_run
, stepi_command
, _("\
3288 Step one instruction exactly.\n\
3290 Argument N means step N times (or till program stops for another \
3292 add_com_alias ("si", stepi_cmd
, class_run
, 0);
3294 cmd_list_element
*nexti_cmd
3295 = add_com ("nexti", class_run
, nexti_command
, _("\
3296 Step one instruction, but proceed through subroutine calls.\n\
3298 Argument N means step N times (or till program stops for another \
3300 add_com_alias ("ni", nexti_cmd
, class_run
, 0);
3302 cmd_list_element
*finish_cmd
3303 = add_com ("finish", class_run
, finish_command
, _("\
3304 Execute until selected stack frame returns.\n\
3306 Upon return, the value returned is printed and put in the value history."));
3307 add_com_alias ("fin", finish_cmd
, class_run
, 1);
3309 cmd_list_element
*next_cmd
3310 = add_com ("next", class_run
, next_command
, _("\
3311 Step program, proceeding through subroutine calls.\n\
3313 Unlike \"step\", if the current source line calls a subroutine,\n\
3314 this command does not enter the subroutine, but instead steps over\n\
3315 the call, in effect treating it as a single source line."));
3316 add_com_alias ("n", next_cmd
, class_run
, 1);
3318 cmd_list_element
*step_cmd
3319 = add_com ("step", class_run
, step_command
, _("\
3320 Step program until it reaches a different source line.\n\
3322 Argument N means step N times (or till program stops for another \
3324 add_com_alias ("s", step_cmd
, class_run
, 1);
3326 cmd_list_element
*until_cmd
3327 = add_com ("until", class_run
, until_command
, _("\
3328 Execute until past the current line or past a LOCATION.\n\
3329 Execute until the program reaches a source line greater than the current\n\
3330 or a specified location (same args as break command) within the current \
3332 set_cmd_completer (until_cmd
, location_completer
);
3333 add_com_alias ("u", until_cmd
, class_run
, 1);
3335 c
= add_com ("advance", class_run
, advance_command
, _("\
3336 Continue the program up to the given location (same form as args for break \
3338 Execution will also stop upon exit from the current stack frame."));
3339 set_cmd_completer (c
, location_completer
);
3341 cmd_list_element
*jump_cmd
3342 = add_com ("jump", class_run
, jump_command
, _("\
3343 Continue program being debugged at specified line or address.\n\
3344 Usage: jump LOCATION\n\
3345 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3346 for an address to start at."));
3347 set_cmd_completer (jump_cmd
, location_completer
);
3348 add_com_alias ("j", jump_cmd
, class_run
, 1);
3350 cmd_list_element
*continue_cmd
3351 = add_com ("continue", class_run
, continue_command
, _("\
3352 Continue program being debugged, after signal or breakpoint.\n\
3353 Usage: continue [N]\n\
3354 If proceeding from breakpoint, a number N may be used as an argument,\n\
3355 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3356 the breakpoint won't break until the Nth time it is reached).\n\
3358 If non-stop mode is enabled, continue only the current thread,\n\
3359 otherwise all the threads in the program are continued. To \n\
3360 continue all stopped threads in non-stop mode, use the -a option.\n\
3361 Specifying -a and an ignore count simultaneously is an error."));
3362 add_com_alias ("c", continue_cmd
, class_run
, 1);
3363 add_com_alias ("fg", continue_cmd
, class_run
, 1);
3365 cmd_list_element
*run_cmd
3366 = add_com ("run", class_run
, run_command
, _("\
3367 Start debugged program.\n"
3369 set_cmd_completer (run_cmd
, filename_completer
);
3370 add_com_alias ("r", run_cmd
, class_run
, 1);
3372 c
= add_com ("start", class_run
, start_command
, _("\
3373 Start the debugged program stopping at the beginning of the main procedure.\n"
3375 set_cmd_completer (c
, filename_completer
);
3377 c
= add_com ("starti", class_run
, starti_command
, _("\
3378 Start the debugged program stopping at the first instruction.\n"
3380 set_cmd_completer (c
, filename_completer
);
3382 add_com ("interrupt", class_run
, interrupt_command
,
3383 _("Interrupt the execution of the debugged program.\n\
3384 If non-stop mode is enabled, interrupt only the current thread,\n\
3385 otherwise all the threads in the program are stopped. To \n\
3386 interrupt all running threads in non-stop mode, use the -a option."));
3388 cmd_list_element
*info_registers_cmd
3389 = add_info ("registers", info_registers_command
, _("\
3390 List of integer registers and their contents, for selected stack frame.\n\
3391 One or more register names as argument means describe the given registers.\n\
3392 One or more register group names as argument means describe the registers\n\
3393 in the named register groups."));
3394 add_info_alias ("r", info_registers_cmd
, 1);
3395 set_cmd_completer (info_registers_cmd
, reg_or_group_completer
);
3397 c
= add_info ("all-registers", info_all_registers_command
, _("\
3398 List of all registers and their contents, for selected stack frame.\n\
3399 One or more register names as argument means describe the given registers.\n\
3400 One or more register group names as argument means describe the registers\n\
3401 in the named register groups."));
3402 set_cmd_completer (c
, reg_or_group_completer
);
3404 add_info ("program", info_program_command
,
3405 _("Execution status of the program."));
3407 add_info ("float", info_float_command
,
3408 _("Print the status of the floating point unit."));
3410 add_info ("vector", info_vector_command
,
3411 _("Print the status of the vector unit."));
3413 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3415 Show additional information about a process.\n\
3416 Specify any process id, or use the program being debugged by default."),
3418 1/*allow-unknown*/, &infolist
);
3420 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3421 List memory regions mapped by the specified process."),
3422 &info_proc_cmdlist
);
3424 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3425 List process info from /proc/PID/stat."),
3426 &info_proc_cmdlist
);
3428 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3429 List process info from /proc/PID/status."),
3430 &info_proc_cmdlist
);
3432 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3433 List current working directory of the specified process."),
3434 &info_proc_cmdlist
);
3436 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3437 List command line arguments of the specified process."),
3438 &info_proc_cmdlist
);
3440 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3441 List absolute filename for executable of the specified process."),
3442 &info_proc_cmdlist
);
3444 add_cmd ("files", class_info
, info_proc_cmd_files
, _("\
3445 List files opened by the specified process."),
3446 &info_proc_cmdlist
);
3448 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3449 List all available info about the specified process."),
3450 &info_proc_cmdlist
);
3452 add_setshow_boolean_cmd ("finish", class_support
,
3454 Set whether `finish' prints the return value."), _("\
3455 Show whether `finish' prints the return value."), nullptr,
3458 &setprintlist
, &showprintlist
);