1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
27 #include "gdbsupport/environ.h"
35 #include "completer.h"
38 #include "reggroups.h"
42 #include "observable.h"
43 #include "target-descriptions.h"
44 #include "user-regs.h"
45 #include "gdbthread.h"
47 #include "inline-frame.h"
48 #include "tracepoint.h"
50 #include "continuations.h"
52 #include "thread-fsm.h"
56 #include "gdbsupport/gdb_optional.h"
58 #include "cli/cli-style.h"
60 /* Local functions: */
62 static void until_next_command (int);
64 static void step_1 (int, int, const char *);
66 #define ERROR_NO_INFERIOR \
67 if (!target_has_execution ()) error (_("The program is not being run."));
69 /* Scratch area where string containing arguments to give to the
70 program will be stored by 'set args'. As soon as anything is
71 stored, notice_args_set will move it into per-inferior storage.
72 Arguments are separated by spaces. Empty string (pointer to '\0')
75 static char *inferior_args_scratch
;
77 /* Scratch area where the new cwd will be stored by 'set cwd'. */
79 static char *inferior_cwd_scratch
;
81 /* Scratch area where 'set inferior-tty' will store user-provided value.
82 We'll immediate copy it into per-inferior storage. */
84 static char *inferior_io_terminal_scratch
;
86 /* Pid of our debugged inferior, or 0 if no inferior now.
87 Since various parts of infrun.c test this to see whether there is a program
88 being debugged it should be nonzero (currently 3 is used) for remote
93 /* Nonzero if stopped due to completion of a stack dummy routine. */
95 enum stop_stack_kind stop_stack_dummy
;
97 /* Nonzero if stopped due to a random (unexpected) signal in inferior
100 int stopped_by_random_signal
;
105 set_inferior_tty_command (const char *args
, int from_tty
,
106 struct cmd_list_element
*c
)
108 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
109 Now route it to current inferior. */
110 current_inferior ()->set_tty (inferior_io_terminal_scratch
);
114 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
115 struct cmd_list_element
*c
, const char *value
)
117 /* Note that we ignore the passed-in value in favor of computing it
119 const char *inferior_tty
= current_inferior ()->tty ();
121 if (inferior_tty
== nullptr)
123 fprintf_filtered (gdb_stdout
,
124 _("Terminal for future runs of program being debugged "
125 "is \"%s\".\n"), inferior_tty
);
129 get_inferior_args (void)
131 if (current_inferior ()->argc
!= 0)
133 gdb::array_view
<char * const> args (current_inferior ()->argv
,
134 current_inferior ()->argc
);
135 std::string n
= construct_inferior_arguments (args
);
136 set_inferior_args (n
.c_str ());
139 if (current_inferior ()->args
== NULL
)
140 current_inferior ()->args
= xstrdup ("");
142 return current_inferior ()->args
;
145 /* Set the arguments for the current inferior. Ownership of
146 NEWARGS is not transferred. */
149 set_inferior_args (const char *newargs
)
151 xfree (current_inferior ()->args
);
152 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
153 current_inferior ()->argc
= 0;
154 current_inferior ()->argv
= 0;
158 set_inferior_args_vector (int argc
, char **argv
)
160 current_inferior ()->argc
= argc
;
161 current_inferior ()->argv
= argv
;
164 /* Notice when `set args' is run. */
167 set_args_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
169 /* CLI has assigned the user-provided value to inferior_args_scratch.
170 Now route it to current inferior. */
171 set_inferior_args (inferior_args_scratch
);
174 /* Notice when `show args' is run. */
177 show_args_command (struct ui_file
*file
, int from_tty
,
178 struct cmd_list_element
*c
, const char *value
)
180 /* Note that we ignore the passed-in value in favor of computing it
182 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
185 /* See gdbsupport/common-inferior.h. */
188 set_inferior_cwd (const char *cwd
)
190 struct inferior
*inf
= current_inferior ();
192 gdb_assert (inf
!= NULL
);
197 inf
->cwd
.reset (xstrdup (cwd
));
200 /* See gdbsupport/common-inferior.h. */
205 return current_inferior ()->cwd
.get ();
208 /* Handle the 'set cwd' command. */
211 set_cwd_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
213 if (*inferior_cwd_scratch
== '\0')
214 set_inferior_cwd (NULL
);
216 set_inferior_cwd (inferior_cwd_scratch
);
219 /* Handle the 'show cwd' command. */
222 show_cwd_command (struct ui_file
*file
, int from_tty
,
223 struct cmd_list_element
*c
, const char *value
)
225 const char *cwd
= get_inferior_cwd ();
228 fprintf_filtered (gdb_stdout
,
230 You have not set the inferior's current working directory.\n\
231 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
232 server's cwd if remote debugging.\n"));
234 fprintf_filtered (gdb_stdout
,
235 _("Current working directory that will be used "
236 "when starting the inferior is \"%s\".\n"), cwd
);
240 /* This function strips the '&' character (indicating background
241 execution) that is added as *the last* of the arguments ARGS of a
242 command. A copy of the incoming ARGS without the '&' is returned,
243 unless the resulting string after stripping is empty, in which case
244 NULL is returned. *BG_CHAR_P is an output boolean that indicates
245 whether the '&' character was found. */
247 static gdb::unique_xmalloc_ptr
<char>
248 strip_bg_char (const char *args
, int *bg_char_p
)
252 if (args
== NULL
|| *args
== '\0')
258 p
= args
+ strlen (args
);
262 while (p
> args
&& isspace (p
[-1]))
267 return gdb::unique_xmalloc_ptr
<char>
268 (savestring (args
, p
- args
));
270 return gdb::unique_xmalloc_ptr
<char> (nullptr);
274 return make_unique_xstrdup (args
);
277 /* Common actions to take after creating any sort of inferior, by any
278 means (running, attaching, connecting, et cetera). The target
279 should be stopped. */
282 post_create_inferior (int from_tty
)
285 /* Be sure we own the terminal in case write operations are performed. */
286 target_terminal::ours_for_output ();
288 /* If the target hasn't taken care of this already, do it now.
289 Targets which need to access registers during to_open,
290 to_create_inferior, or to_attach should do it earlier; but many
292 target_find_description ();
294 /* Now that we know the register layout, retrieve current PC. But
295 if the PC is unavailable (e.g., we're opening a core file with
296 missing registers info), ignore it. */
297 thread_info
*thr
= inferior_thread ();
299 thr
->suspend
.stop_pc
= 0;
302 regcache
*rc
= get_thread_regcache (thr
);
303 thr
->suspend
.stop_pc
= regcache_read_pc (rc
);
305 catch (const gdb_exception_error
&ex
)
307 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
311 if (current_program_space
->exec_bfd ())
313 const unsigned solib_add_generation
314 = current_program_space
->solib_add_generation
;
316 /* Create the hooks to handle shared library load and unload
318 solib_create_inferior_hook (from_tty
);
320 if (current_program_space
->solib_add_generation
== solib_add_generation
)
322 /* The platform-specific hook should load initial shared libraries,
323 but didn't. FROM_TTY will be incorrectly 0 but such solib
324 targets should be fixed anyway. Call it only after the solib
325 target has been initialized by solib_create_inferior_hook. */
328 warning (_("platform-specific solib_create_inferior_hook did "
329 "not load initial shared libraries."));
331 /* If the solist is global across processes, there's no need to
333 if (!gdbarch_has_global_solist (target_gdbarch ()))
334 solib_add (NULL
, 0, auto_solib_add
);
338 /* If the user sets watchpoints before execution having started,
339 then she gets software watchpoints, because GDB can't know which
340 target will end up being pushed, or if it supports hardware
341 watchpoints or not. breakpoint_re_set takes care of promoting
342 watchpoints to hardware watchpoints if possible, however, if this
343 new inferior doesn't load shared libraries or we don't pull in
344 symbols from any other source on this target/arch,
345 breakpoint_re_set is never called. Call it now so that software
346 watchpoints get a chance to be promoted to hardware watchpoints
347 if the now pushed target supports hardware watchpoints. */
348 breakpoint_re_set ();
350 gdb::observers::inferior_created
.notify (current_inferior ());
353 /* Kill the inferior if already running. This function is designed
354 to be called when we are about to start the execution of the program
355 from the beginning. Ask the user to confirm that he wants to restart
356 the program being debugged when FROM_TTY is non-null. */
359 kill_if_already_running (int from_tty
)
361 if (inferior_ptid
!= null_ptid
&& target_has_execution ())
363 /* Bail out before killing the program if we will not be able to
365 target_require_runnable ();
368 && !query (_("The program being debugged has been started already.\n\
369 Start it from the beginning? ")))
370 error (_("Program not restarted."));
375 /* See inferior.h. */
378 prepare_execution_command (struct target_ops
*target
, int background
)
380 /* If we get a request for running in the bg but the target
381 doesn't support it, error out. */
382 if (background
&& !target
->can_async_p ())
383 error (_("Asynchronous execution not supported on this target."));
387 /* If we get a request for running in the fg, then we need to
388 simulate synchronous (fg) execution. Note no cleanup is
389 necessary for this. stdin is re-enabled whenever an error
390 reaches the top level. */
391 all_uis_on_sync_execution_starting ();
395 /* Determine how the new inferior will behave. */
399 /* Run program without any explicit stop during startup. */
402 /* Stop at the beginning of the program's main function. */
405 /* Stop at the first instruction of the program. */
406 RUN_STOP_AT_FIRST_INSN
409 /* Implement the "run" command. Force a stop during program start if
410 requested by RUN_HOW. */
413 run_command_1 (const char *args
, int from_tty
, enum run_how run_how
)
415 const char *exec_file
;
416 struct ui_out
*uiout
= current_uiout
;
417 struct target_ops
*run_target
;
422 kill_if_already_running (from_tty
);
424 init_wait_for_inferior ();
425 clear_breakpoint_hit_counts ();
427 /* Clean up any leftovers from other runs. Some other things from
428 this function should probably be moved into target_pre_inferior. */
429 target_pre_inferior (from_tty
);
431 /* The comment here used to read, "The exec file is re-read every
432 time we do a generic_mourn_inferior, so we just have to worry
433 about the symbol file." The `generic_mourn_inferior' function
434 gets called whenever the program exits. However, suppose the
435 program exits, and *then* the executable file changes? We need
436 to check again here. Since reopen_exec_file doesn't do anything
437 if the timestamp hasn't changed, I don't see the harm. */
441 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
442 args
= stripped
.get ();
444 /* Do validation and preparation before possibly changing anything
447 run_target
= find_run_target ();
449 prepare_execution_command (run_target
, async_exec
);
451 if (non_stop
&& !run_target
->supports_non_stop ())
452 error (_("The target does not support running in non-stop mode."));
454 /* Done. Can now set breakpoints, change inferior args, etc. */
456 /* Insert temporary breakpoint in main function if requested. */
457 if (run_how
== RUN_STOP_AT_MAIN
)
459 std::string arg
= string_printf ("-qualified %s", main_name ());
460 tbreak_command (arg
.c_str (), 0);
463 exec_file
= get_exec_file (0);
465 /* We keep symbols from add-symbol-file, on the grounds that the
466 user might want to add some symbols before running the program
467 (right?). But sometimes (dynamic loading where the user manually
468 introduces the new symbols with add-symbol-file), the code which
469 the symbols describe does not persist between runs. Currently
470 the user has to manually nuke all symbols between runs if they
471 want them to go away (PR 2207). This is probably reasonable. */
473 /* If there were other args, beside '&', process them. */
475 set_inferior_args (args
);
479 uiout
->field_string (NULL
, "Starting program");
482 uiout
->field_string ("execfile", exec_file
);
484 /* We call get_inferior_args() because we might need to compute
486 uiout
->field_string ("infargs", get_inferior_args ());
491 /* We call get_inferior_args() because we might need to compute
493 run_target
->create_inferior (exec_file
,
494 std::string (get_inferior_args ()),
495 current_inferior ()->environment
.envp (),
497 /* to_create_inferior should push the target, so after this point we
498 shouldn't refer to run_target again. */
501 /* We're starting off a new process. When we get out of here, in
502 non-stop mode, finish the state of all threads of that process,
503 but leave other threads alone, as they may be stopped in internal
504 events --- the frontend shouldn't see them as stopped. In
505 all-stop, always finish the state of all threads, as we may be
506 resuming more than just the new process. */
507 process_stratum_target
*finish_target
;
511 finish_target
= current_inferior ()->process_target ();
512 finish_ptid
= ptid_t (current_inferior ()->pid
);
516 finish_target
= nullptr;
517 finish_ptid
= minus_one_ptid
;
519 scoped_finish_thread_state
finish_state (finish_target
, finish_ptid
);
521 /* Pass zero for FROM_TTY, because at this point the "run" command
522 has done its thing; now we are setting up the running program. */
523 post_create_inferior (0);
525 /* Queue a pending event so that the program stops immediately. */
526 if (run_how
== RUN_STOP_AT_FIRST_INSN
)
528 thread_info
*thr
= inferior_thread ();
529 thr
->suspend
.waitstatus_pending_p
= 1;
530 thr
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
531 thr
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
534 /* Start the target running. Do not use -1 continuation as it would skip
535 breakpoint right at the entry point. */
536 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
538 /* Since there was no error, there's no need to finish the thread
540 finish_state
.release ();
544 run_command (const char *args
, int from_tty
)
546 run_command_1 (args
, from_tty
, RUN_NORMAL
);
549 /* Start the execution of the program up until the beginning of the main
553 start_command (const char *args
, int from_tty
)
555 /* Some languages such as Ada need to search inside the program
556 minimal symbols for the location where to put the temporary
557 breakpoint before starting. */
558 if (!have_minimal_symbols ())
559 error (_("No symbol table loaded. Use the \"file\" command."));
561 /* Run the program until reaching the main procedure... */
562 run_command_1 (args
, from_tty
, RUN_STOP_AT_MAIN
);
565 /* Start the execution of the program stopping at the first
569 starti_command (const char *args
, int from_tty
)
571 run_command_1 (args
, from_tty
, RUN_STOP_AT_FIRST_INSN
);
575 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
577 /* We go through all threads individually instead of compressing
578 into a single target `resume_all' request, because some threads
579 may be stopped in internal breakpoints/events, or stopped waiting
580 for its turn in the displaced stepping queue (that is, they are
581 running && !executing). The target side has no idea about why
582 the thread is stopped, so a `resume_all' command would resume too
583 much. If/when GDB gains a way to tell the target `hold this
584 thread stopped until I say otherwise', then we can optimize
586 if (thread
->state
!= THREAD_STOPPED
)
589 if (!thread
->inf
->has_execution ())
592 switch_to_thread (thread
);
593 clear_proceed_status (0);
594 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
599 ensure_valid_thread (void)
601 if (inferior_ptid
== null_ptid
602 || inferior_thread ()->state
== THREAD_EXITED
)
603 error (_("Cannot execute this command without a live selected thread."));
606 /* If the user is looking at trace frames, any resumption of execution
607 is likely to mix up recorded and live target data. So simply
608 disallow those commands. */
611 ensure_not_tfind_mode (void)
613 if (get_traceframe_number () >= 0)
614 error (_("Cannot execute this command while looking at trace frames."));
617 /* Throw an error indicating the current thread is running. */
620 error_is_running (void)
622 error (_("Cannot execute this command while "
623 "the selected thread is running."));
626 /* Calls error_is_running if the current thread is running. */
629 ensure_not_running (void)
631 if (inferior_thread ()->state
== THREAD_RUNNING
)
636 continue_1 (int all_threads
)
639 ensure_not_tfind_mode ();
641 if (non_stop
&& all_threads
)
643 /* Don't error out if the current thread is running, because
644 there may be other stopped threads. */
646 /* Backup current thread and selected frame and restore on scope
648 scoped_restore_current_thread restore_thread
;
650 iterate_over_threads (proceed_thread_callback
, NULL
);
652 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
654 /* If all threads in the target were already running,
655 proceed_thread_callback ends up never calling proceed,
656 and so nothing calls this to put the inferior's terminal
657 settings in effect and remove stdin from the event loop,
658 which we must when running a foreground command. E.g.:
662 <all threads are running now>
665 <no thread was resumed, but the inferior now owns the terminal>
667 target_terminal::inferior ();
672 ensure_valid_thread ();
673 ensure_not_running ();
674 clear_proceed_status (0);
675 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
679 /* continue [-a] [proceed-count] [&] */
682 continue_command (const char *args
, int from_tty
)
685 bool all_threads_p
= false;
689 /* Find out whether we must run in the background. */
690 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
691 args
= stripped
.get ();
695 if (startswith (args
, "-a"))
697 all_threads_p
= true;
698 args
+= sizeof ("-a") - 1;
704 if (!non_stop
&& all_threads_p
)
705 error (_("`-a' is meaningless in all-stop mode."));
707 if (args
!= NULL
&& all_threads_p
)
708 error (_("Can't resume all threads and specify "
709 "proceed count simultaneously."));
711 /* If we have an argument left, set proceed count of breakpoint we
718 struct thread_info
*tp
;
721 tp
= inferior_thread ();
724 process_stratum_target
*last_target
;
727 get_last_target_status (&last_target
, &last_ptid
, nullptr);
728 tp
= find_thread_ptid (last_target
, last_ptid
);
731 bs
= tp
->control
.stop_bpstat
;
733 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
736 set_ignore_count (num
,
737 parse_and_eval_long (args
) - 1,
739 /* set_ignore_count prints a message ending with a period.
740 So print two spaces before "Continuing.". */
742 printf_filtered (" ");
746 if (!stopped
&& from_tty
)
749 ("Not stopped at any breakpoint; argument ignored.\n");
754 ensure_not_tfind_mode ();
756 if (!non_stop
|| !all_threads_p
)
758 ensure_valid_thread ();
759 ensure_not_running ();
762 prepare_execution_command (current_top_target (), async_exec
);
765 printf_filtered (_("Continuing.\n"));
767 continue_1 (all_threads_p
);
770 /* Record in TP the starting point of a "step" or "next" command. */
773 set_step_frame (thread_info
*tp
)
775 /* This can be removed once this function no longer implicitly relies on the
776 inferior_ptid value. */
777 gdb_assert (inferior_ptid
== tp
->ptid
);
779 frame_info
*frame
= get_current_frame ();
781 symtab_and_line sal
= find_frame_sal (frame
);
782 set_step_info (tp
, frame
, sal
);
784 CORE_ADDR pc
= get_frame_pc (frame
);
785 tp
->control
.step_start_function
= find_pc_function (pc
);
788 /* Step until outside of current statement. */
791 step_command (const char *count_string
, int from_tty
)
793 step_1 (0, 0, count_string
);
796 /* Likewise, but skip over subroutine calls as if single instructions. */
799 next_command (const char *count_string
, int from_tty
)
801 step_1 (1, 0, count_string
);
804 /* Likewise, but step only one instruction. */
807 stepi_command (const char *count_string
, int from_tty
)
809 step_1 (0, 1, count_string
);
813 nexti_command (const char *count_string
, int from_tty
)
815 step_1 (1, 1, count_string
);
818 /* Data for the FSM that manages the step/next/stepi/nexti
821 struct step_command_fsm
: public thread_fsm
823 /* How many steps left in a "step N"-like command. */
826 /* If true, this is a next/nexti, otherwise a step/stepi. */
827 int skip_subroutines
;
829 /* If true, this is a stepi/nexti, otherwise a step/step. */
832 explicit step_command_fsm (struct interp
*cmd_interp
)
833 : thread_fsm (cmd_interp
)
837 void clean_up (struct thread_info
*thread
) override
;
838 bool should_stop (struct thread_info
*thread
) override
;
839 enum async_reply_reason
do_async_reply_reason () override
;
842 /* Prepare for a step/next/etc. command. Any target resource
843 allocated here is undone in the FSM's clean_up method. */
846 step_command_fsm_prepare (struct step_command_fsm
*sm
,
847 int skip_subroutines
, int single_inst
,
848 int count
, struct thread_info
*thread
)
850 sm
->skip_subroutines
= skip_subroutines
;
851 sm
->single_inst
= single_inst
;
854 /* Leave the si command alone. */
855 if (!sm
->single_inst
|| sm
->skip_subroutines
)
856 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
858 thread
->control
.stepping_command
= 1;
861 static int prepare_one_step (thread_info
*, struct step_command_fsm
*sm
);
864 step_1 (int skip_subroutines
, int single_inst
, const char *count_string
)
868 struct thread_info
*thr
;
869 struct step_command_fsm
*step_sm
;
872 ensure_not_tfind_mode ();
873 ensure_valid_thread ();
874 ensure_not_running ();
876 gdb::unique_xmalloc_ptr
<char> stripped
877 = strip_bg_char (count_string
, &async_exec
);
878 count_string
= stripped
.get ();
880 prepare_execution_command (current_top_target (), async_exec
);
882 count
= count_string
? parse_and_eval_long (count_string
) : 1;
884 clear_proceed_status (1);
886 /* Setup the execution command state machine to handle all the COUNT
888 thr
= inferior_thread ();
889 step_sm
= new step_command_fsm (command_interp ());
890 thr
->thread_fsm
= step_sm
;
892 step_command_fsm_prepare (step_sm
, skip_subroutines
,
893 single_inst
, count
, thr
);
895 /* Do only one step for now, before returning control to the event
896 loop. Let the continuation figure out how many other steps we
897 need to do, and handle them one at the time, through
899 if (!prepare_one_step (thr
, step_sm
))
900 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
905 /* Stepped into an inline frame. Pretend that we've
907 thr
->thread_fsm
->clean_up (thr
);
908 proceeded
= normal_stop ();
910 inferior_event_handler (INF_EXEC_COMPLETE
);
911 all_uis_check_sync_execution_done ();
915 /* Implementation of the 'should_stop' FSM method for stepping
916 commands. Called after we are done with one step operation, to
917 check whether we need to step again, before we print the prompt and
918 return control to the user. If count is > 1, returns false, as we
919 will need to keep going. */
922 step_command_fsm::should_stop (struct thread_info
*tp
)
924 if (tp
->control
.stop_step
)
926 /* There are more steps to make, and we did stop due to
927 ending a stepping range. Do another step. */
929 return prepare_one_step (tp
, this);
937 /* Implementation of the 'clean_up' FSM method for stepping commands. */
940 step_command_fsm::clean_up (struct thread_info
*thread
)
942 if (!single_inst
|| skip_subroutines
)
943 delete_longjmp_breakpoint (thread
->global_num
);
946 /* Implementation of the 'async_reply_reason' FSM method for stepping
949 enum async_reply_reason
950 step_command_fsm::do_async_reply_reason ()
952 return EXEC_ASYNC_END_STEPPING_RANGE
;
955 /* Prepare for one step in "step N". The actual target resumption is
956 done by the caller. Return true if we're done and should thus
957 report a stop to the user. Returns false if the target needs to be
961 prepare_one_step (thread_info
*tp
, struct step_command_fsm
*sm
)
963 /* This can be removed once this function no longer implicitly relies on the
964 inferior_ptid value. */
965 gdb_assert (inferior_ptid
== tp
->ptid
);
969 struct frame_info
*frame
= get_current_frame ();
973 if (!sm
->single_inst
)
977 /* Step at an inlined function behaves like "down". */
978 if (!sm
->skip_subroutines
979 && inline_skipped_frames (tp
))
982 const char *fn
= NULL
;
986 /* Pretend that we've ran. */
987 resume_ptid
= user_visible_resume_ptid (1);
988 set_running (tp
->inf
->process_target (), resume_ptid
, true);
990 step_into_inline_frame (tp
);
992 frame
= get_current_frame ();
993 sal
= find_frame_sal (frame
);
994 sym
= get_frame_function (frame
);
997 fn
= sym
->print_name ();
1000 || !function_name_is_marked_for_skip (fn
, sal
))
1003 return prepare_one_step (tp
, sm
);
1007 pc
= get_frame_pc (frame
);
1008 find_pc_line_pc_range (pc
,
1009 &tp
->control
.step_range_start
,
1010 &tp
->control
.step_range_end
);
1012 tp
->control
.may_range_step
= 1;
1014 /* If we have no line info, switch to stepi mode. */
1015 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1017 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1018 tp
->control
.may_range_step
= 0;
1020 else if (tp
->control
.step_range_end
== 0)
1024 if (find_pc_partial_function (pc
, &name
,
1025 &tp
->control
.step_range_start
,
1026 &tp
->control
.step_range_end
) == 0)
1027 error (_("Cannot find bounds of current function"));
1029 target_terminal::ours_for_output ();
1030 printf_filtered (_("Single stepping until exit from function %s,"
1031 "\nwhich has no line number information.\n"),
1037 /* Say we are stepping, but stop after one insn whatever it does. */
1038 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1039 if (!sm
->skip_subroutines
)
1041 Don't step over function calls, not even to functions lacking
1043 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1046 if (sm
->skip_subroutines
)
1047 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1053 sm
->set_finished ();
1058 /* Continue program at specified address. */
1061 jump_command (const char *arg
, int from_tty
)
1063 struct gdbarch
*gdbarch
= get_current_arch ();
1070 ensure_not_tfind_mode ();
1071 ensure_valid_thread ();
1072 ensure_not_running ();
1074 /* Find out whether we must run in the background. */
1075 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1076 arg
= stripped
.get ();
1078 prepare_execution_command (current_top_target (), async_exec
);
1081 error_no_arg (_("starting address"));
1083 std::vector
<symtab_and_line
> sals
1084 = decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1085 if (sals
.size () != 1)
1086 error (_("Unreasonable jump request"));
1088 symtab_and_line
&sal
= sals
[0];
1090 if (sal
.symtab
== 0 && sal
.pc
== 0)
1091 error (_("No source file has been specified."));
1093 resolve_sal_pc (&sal
); /* May error out. */
1095 /* See if we are trying to jump to another function. */
1096 fn
= get_frame_function (get_current_frame ());
1097 sfn
= find_pc_function (sal
.pc
);
1098 if (fn
!= NULL
&& 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 fixup_symbol_section (sfn
, 0);
1113 section
= SYMBOL_OBJ_SECTION (symbol_objfile (sfn
), sfn
);
1114 if (section_is_overlay (section
)
1115 && !section_is_mapped (section
))
1117 if (!query (_("WARNING!!! Destination is in "
1118 "unmapped overlay! Jump anyway? ")))
1120 error (_("Not confirmed."));
1130 printf_filtered (_("Continuing at "));
1131 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1132 printf_filtered (".\n");
1135 clear_proceed_status (0);
1136 proceed (addr
, GDB_SIGNAL_0
);
1139 /* Continue program giving it specified signal. */
1142 signal_command (const char *signum_exp
, int from_tty
)
1144 enum gdb_signal oursig
;
1147 dont_repeat (); /* Too dangerous. */
1149 ensure_not_tfind_mode ();
1150 ensure_valid_thread ();
1151 ensure_not_running ();
1153 /* Find out whether we must run in the background. */
1154 gdb::unique_xmalloc_ptr
<char> stripped
1155 = strip_bg_char (signum_exp
, &async_exec
);
1156 signum_exp
= stripped
.get ();
1158 prepare_execution_command (current_top_target (), async_exec
);
1161 error_no_arg (_("signal number"));
1163 /* It would be even slicker to make signal names be valid expressions,
1164 (the type could be "enum $signal" or some such), then the user could
1165 assign them to convenience variables. */
1166 oursig
= gdb_signal_from_name (signum_exp
);
1168 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1170 /* No, try numeric. */
1171 int num
= parse_and_eval_long (signum_exp
);
1174 oursig
= GDB_SIGNAL_0
;
1176 oursig
= gdb_signal_from_command (num
);
1179 /* Look for threads other than the current that this command ends up
1180 resuming too (due to schedlock off), and warn if they'll get a
1181 signal delivered. "signal 0" is used to suppress a previous
1182 signal, but if the current thread is no longer the one that got
1183 the signal, then the user is potentially suppressing the signal
1184 of the wrong thread. */
1187 int must_confirm
= 0;
1189 /* This indicates what will be resumed. Either a single thread,
1190 a whole process, or all threads of all processes. */
1191 ptid_t resume_ptid
= user_visible_resume_ptid (0);
1192 process_stratum_target
*resume_target
1193 = user_visible_resume_target (resume_ptid
);
1195 thread_info
*current
= inferior_thread ();
1197 for (thread_info
*tp
: all_non_exited_threads (resume_target
, resume_ptid
))
1202 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1203 && signal_pass_state (tp
->suspend
.stop_signal
))
1206 printf_unfiltered (_("Note:\n"));
1207 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1208 print_thread_id (tp
),
1209 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1210 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1216 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1217 "still deliver the signals noted above to their respective threads.\n"
1218 "Continue anyway? "),
1219 print_thread_id (inferior_thread ())))
1220 error (_("Not confirmed."));
1225 if (oursig
== GDB_SIGNAL_0
)
1226 printf_filtered (_("Continuing with no signal.\n"));
1228 printf_filtered (_("Continuing with signal %s.\n"),
1229 gdb_signal_to_name (oursig
));
1232 clear_proceed_status (0);
1233 proceed ((CORE_ADDR
) -1, oursig
);
1236 /* Queue a signal to be delivered to the current thread. */
1239 queue_signal_command (const char *signum_exp
, int from_tty
)
1241 enum gdb_signal oursig
;
1242 struct thread_info
*tp
;
1245 ensure_not_tfind_mode ();
1246 ensure_valid_thread ();
1247 ensure_not_running ();
1249 if (signum_exp
== NULL
)
1250 error_no_arg (_("signal number"));
1252 /* It would be even slicker to make signal names be valid expressions,
1253 (the type could be "enum $signal" or some such), then the user could
1254 assign them to convenience variables. */
1255 oursig
= gdb_signal_from_name (signum_exp
);
1257 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1259 /* No, try numeric. */
1260 int num
= parse_and_eval_long (signum_exp
);
1263 oursig
= GDB_SIGNAL_0
;
1265 oursig
= gdb_signal_from_command (num
);
1268 if (oursig
!= GDB_SIGNAL_0
1269 && !signal_pass_state (oursig
))
1270 error (_("Signal handling set to not pass this signal to the program."));
1272 tp
= inferior_thread ();
1273 tp
->suspend
.stop_signal
= oursig
;
1276 /* Data for the FSM that manages the until (with no argument)
1279 struct until_next_fsm
: public thread_fsm
1281 /* The thread that as current when the command was executed. */
1284 until_next_fsm (struct interp
*cmd_interp
, int thread
)
1285 : thread_fsm (cmd_interp
),
1290 bool should_stop (struct thread_info
*thread
) override
;
1291 void clean_up (struct thread_info
*thread
) override
;
1292 enum async_reply_reason
do_async_reply_reason () override
;
1295 /* Implementation of the 'should_stop' FSM method for the until (with
1299 until_next_fsm::should_stop (struct thread_info
*tp
)
1301 if (tp
->control
.stop_step
)
1307 /* Implementation of the 'clean_up' FSM method for the until (with no
1311 until_next_fsm::clean_up (struct thread_info
*thread
)
1313 delete_longjmp_breakpoint (thread
->global_num
);
1316 /* Implementation of the 'async_reply_reason' FSM method for the until
1317 (with no arg) command. */
1319 enum async_reply_reason
1320 until_next_fsm::do_async_reply_reason ()
1322 return EXEC_ASYNC_END_STEPPING_RANGE
;
1325 /* Proceed until we reach a different source line with pc greater than
1326 our current one or exit the function. We skip calls in both cases.
1328 Note that eventually this command should probably be changed so
1329 that only source lines are printed out when we hit the breakpoint
1330 we set. This may involve changes to wait_for_inferior and the
1331 proceed status code. */
1334 until_next_command (int from_tty
)
1336 struct frame_info
*frame
;
1338 struct symbol
*func
;
1339 struct symtab_and_line sal
;
1340 struct thread_info
*tp
= inferior_thread ();
1341 int thread
= tp
->global_num
;
1342 struct until_next_fsm
*sm
;
1344 clear_proceed_status (0);
1345 set_step_frame (tp
);
1347 frame
= get_current_frame ();
1349 /* Step until either exited from this function or greater
1350 than the current line (if in symbolic section) or pc (if
1353 pc
= get_frame_pc (frame
);
1354 func
= find_pc_function (pc
);
1358 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1360 if (msymbol
.minsym
== NULL
)
1361 error (_("Execution is not within a known function."));
1363 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1364 /* The upper-bound of step_range is exclusive. In order to make PC
1365 within the range, set the step_range_end with PC + 1. */
1366 tp
->control
.step_range_end
= pc
+ 1;
1370 sal
= find_pc_line (pc
, 0);
1372 tp
->control
.step_range_start
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func
));
1373 tp
->control
.step_range_end
= sal
.end
;
1375 tp
->control
.may_range_step
= 1;
1377 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1379 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1380 delete_longjmp_breakpoint_cleanup
lj_deleter (thread
);
1382 sm
= new until_next_fsm (command_interp (), tp
->global_num
);
1383 tp
->thread_fsm
= sm
;
1384 lj_deleter
.release ();
1386 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1390 until_command (const char *arg
, int from_tty
)
1395 ensure_not_tfind_mode ();
1396 ensure_valid_thread ();
1397 ensure_not_running ();
1399 /* Find out whether we must run in the background. */
1400 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1401 arg
= stripped
.get ();
1403 prepare_execution_command (current_top_target (), async_exec
);
1406 until_break_command (arg
, from_tty
, 0);
1408 until_next_command (from_tty
);
1412 advance_command (const char *arg
, int from_tty
)
1417 ensure_not_tfind_mode ();
1418 ensure_valid_thread ();
1419 ensure_not_running ();
1422 error_no_arg (_("a location"));
1424 /* Find out whether we must run in the background. */
1425 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1426 arg
= stripped
.get ();
1428 prepare_execution_command (current_top_target (), async_exec
);
1430 until_break_command (arg
, from_tty
, 1);
1433 /* Return the value of the result of a function at the end of a 'finish'
1434 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1435 right after an inferior call has finished. */
1438 get_return_value (struct value
*function
, struct type
*value_type
)
1440 regcache
*stop_regs
= get_current_regcache ();
1441 struct gdbarch
*gdbarch
= stop_regs
->arch ();
1442 struct value
*value
;
1444 value_type
= check_typedef (value_type
);
1445 gdb_assert (value_type
->code () != TYPE_CODE_VOID
);
1447 /* FIXME: 2003-09-27: When returning from a nested inferior function
1448 call, it's possible (with no help from the architecture vector)
1449 to locate and return/print a "struct return" value. This is just
1450 a more complicated case of what is already being done in the
1451 inferior function call code. In fact, when inferior function
1452 calls are made async, this will likely be made the norm. */
1454 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1457 case RETURN_VALUE_REGISTER_CONVENTION
:
1458 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1459 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1460 value
= allocate_value (value_type
);
1461 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1462 value_contents_raw (value
), NULL
);
1464 case RETURN_VALUE_STRUCT_CONVENTION
:
1468 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1474 /* The captured function return value/type and its position in the
1477 struct return_value_info
1479 /* The captured return value. May be NULL if we weren't able to
1480 retrieve it. See get_return_value. */
1481 struct value
*value
;
1483 /* The return type. In some cases, we'll not be able extract the
1484 return value, but we always know the type. */
1487 /* If we captured a value, this is the value history index. */
1488 int value_history_index
;
1491 /* Helper for print_return_value. */
1494 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1496 if (rv
->value
!= NULL
)
1498 struct value_print_options opts
;
1501 uiout
->text ("Value returned is ");
1502 uiout
->field_fmt ("gdb-result-var", "$%d",
1503 rv
->value_history_index
);
1504 uiout
->text (" = ");
1505 get_user_print_options (&opts
);
1507 if (opts
.finish_print
)
1510 value_print (rv
->value
, &stb
, &opts
);
1511 uiout
->field_stream ("return-value", stb
);
1514 uiout
->field_string ("return-value", _("<not displayed>"),
1515 metadata_style
.style ());
1520 std::string type_name
= type_to_string (rv
->type
);
1521 uiout
->text ("Value returned has type: ");
1522 uiout
->field_string ("return-type", type_name
.c_str ());
1524 uiout
->text (" Cannot determine contents\n");
1528 /* Print the result of a function at the end of a 'finish' command.
1529 RV points at an object representing the captured return value/type
1530 and its position in the value history. */
1533 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1535 if (rv
->type
== NULL
1536 || check_typedef (rv
->type
)->code () == TYPE_CODE_VOID
)
1541 /* print_return_value_1 can throw an exception in some
1542 circumstances. We need to catch this so that we still
1543 delete the breakpoint. */
1544 print_return_value_1 (uiout
, rv
);
1546 catch (const gdb_exception
&ex
)
1548 exception_print (gdb_stdout
, ex
);
1552 /* Data for the FSM that manages the finish command. */
1554 struct finish_command_fsm
: public thread_fsm
1556 /* The momentary breakpoint set at the function's return address in
1558 breakpoint_up breakpoint
;
1560 /* The function that we're stepping out of. */
1561 struct symbol
*function
= nullptr;
1563 /* If the FSM finishes successfully, this stores the function's
1565 struct return_value_info return_value_info
{};
1567 explicit finish_command_fsm (struct interp
*cmd_interp
)
1568 : thread_fsm (cmd_interp
)
1572 bool should_stop (struct thread_info
*thread
) override
;
1573 void clean_up (struct thread_info
*thread
) override
;
1574 struct return_value_info
*return_value () override
;
1575 enum async_reply_reason
do_async_reply_reason () override
;
1578 /* Implementation of the 'should_stop' FSM method for the finish
1579 commands. Detects whether the thread stepped out of the function
1580 successfully, and if so, captures the function's return value and
1581 marks the FSM finished. */
1584 finish_command_fsm::should_stop (struct thread_info
*tp
)
1586 struct return_value_info
*rv
= &return_value_info
;
1588 if (function
!= NULL
1589 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1590 breakpoint
.get ()) != NULL
)
1595 rv
->type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1596 if (rv
->type
== NULL
)
1597 internal_error (__FILE__
, __LINE__
,
1598 _("finish_command: function has no target type"));
1600 if (check_typedef (rv
->type
)->code () != TYPE_CODE_VOID
)
1604 func
= read_var_value (function
, NULL
, get_current_frame ());
1605 rv
->value
= get_return_value (func
, rv
->type
);
1606 if (rv
->value
!= NULL
)
1607 rv
->value_history_index
= record_latest_value (rv
->value
);
1610 else if (tp
->control
.stop_step
)
1612 /* Finishing from an inline frame, or reverse finishing. In
1613 either case, there's no way to retrieve the return value. */
1620 /* Implementation of the 'clean_up' FSM method for the finish
1624 finish_command_fsm::clean_up (struct thread_info
*thread
)
1626 breakpoint
.reset ();
1627 delete_longjmp_breakpoint (thread
->global_num
);
1630 /* Implementation of the 'return_value' FSM method for the finish
1633 struct return_value_info
*
1634 finish_command_fsm::return_value ()
1636 return &return_value_info
;
1639 /* Implementation of the 'async_reply_reason' FSM method for the
1642 enum async_reply_reason
1643 finish_command_fsm::do_async_reply_reason ()
1645 if (execution_direction
== EXEC_REVERSE
)
1646 return EXEC_ASYNC_END_STEPPING_RANGE
;
1648 return EXEC_ASYNC_FUNCTION_FINISHED
;
1651 /* finish_backward -- helper function for finish_command. */
1654 finish_backward (struct finish_command_fsm
*sm
)
1656 struct symtab_and_line sal
;
1657 struct thread_info
*tp
= inferior_thread ();
1659 CORE_ADDR func_addr
;
1661 pc
= get_frame_pc (get_current_frame ());
1663 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1664 error (_("Cannot find bounds of current function"));
1666 sal
= find_pc_line (func_addr
, 0);
1668 tp
->control
.proceed_to_finish
= 1;
1669 /* Special case: if we're sitting at the function entry point,
1670 then all we need to do is take a reverse singlestep. We
1671 don't need to set a breakpoint, and indeed it would do us
1674 Note that this can only happen at frame #0, since there's
1675 no way that a function up the stack can have a return address
1676 that's equal to its entry point. */
1680 struct frame_info
*frame
= get_selected_frame (NULL
);
1681 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1683 /* Set a step-resume at the function's entry point. Once that's
1684 hit, we'll do one more step backwards. */
1685 symtab_and_line sr_sal
;
1687 sr_sal
.pspace
= get_frame_program_space (frame
);
1688 insert_step_resume_breakpoint_at_sal (gdbarch
,
1689 sr_sal
, null_frame_id
);
1691 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1695 /* We're almost there -- we just need to back up by one more
1697 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1698 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1702 /* finish_forward -- helper function for finish_command. FRAME is the
1703 frame that called the function we're about to step out of. */
1706 finish_forward (struct finish_command_fsm
*sm
, struct frame_info
*frame
)
1708 struct frame_id frame_id
= get_frame_id (frame
);
1709 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1710 struct symtab_and_line sal
;
1711 struct thread_info
*tp
= inferior_thread ();
1713 sal
= find_pc_line (get_frame_pc (frame
), 0);
1714 sal
.pc
= get_frame_pc (frame
);
1716 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1717 get_stack_frame_id (frame
),
1720 /* set_momentary_breakpoint invalidates FRAME. */
1723 set_longjmp_breakpoint (tp
, frame_id
);
1725 /* We want to print return value, please... */
1726 tp
->control
.proceed_to_finish
= 1;
1728 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1731 /* Skip frames for "finish". */
1733 static struct frame_info
*
1734 skip_finish_frames (struct frame_info
*frame
)
1736 struct frame_info
*start
;
1742 frame
= skip_tailcall_frames (frame
);
1746 frame
= skip_unwritable_frames (frame
);
1750 while (start
!= frame
);
1755 /* "finish": Set a temporary breakpoint at the place the selected
1756 frame will return to, then continue. */
1759 finish_command (const char *arg
, int from_tty
)
1761 struct frame_info
*frame
;
1763 struct finish_command_fsm
*sm
;
1764 struct thread_info
*tp
;
1767 ensure_not_tfind_mode ();
1768 ensure_valid_thread ();
1769 ensure_not_running ();
1771 /* Find out whether we must run in the background. */
1772 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1773 arg
= stripped
.get ();
1775 prepare_execution_command (current_top_target (), async_exec
);
1778 error (_("The \"finish\" command does not take any arguments."));
1780 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1782 error (_("\"finish\" not meaningful in the outermost frame."));
1784 clear_proceed_status (0);
1786 tp
= inferior_thread ();
1788 sm
= new finish_command_fsm (command_interp ());
1790 tp
->thread_fsm
= sm
;
1792 /* Finishing from an inline frame is completely different. We don't
1793 try to show the "return value" - no way to locate it. */
1794 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1797 /* Claim we are stepping in the calling frame. An empty step
1798 range means that we will stop once we aren't in a function
1799 called by that frame. We don't use the magic "1" value for
1800 step_range_end, because then infrun will think this is nexti,
1801 and not step over the rest of this inlined function call. */
1802 set_step_info (tp
, frame
, {});
1803 tp
->control
.step_range_start
= get_frame_pc (frame
);
1804 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1805 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1807 /* Print info on the selected frame, including level number but not
1811 printf_filtered (_("Run till exit from "));
1812 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1815 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1819 /* Find the function we will return from. */
1821 sm
->function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1823 /* Print info on the selected frame, including level number but not
1827 if (execution_direction
== EXEC_REVERSE
)
1828 printf_filtered (_("Run back to call of "));
1831 if (sm
->function
!= NULL
&& TYPE_NO_RETURN (sm
->function
->type
)
1832 && !query (_("warning: Function %s does not return normally.\n"
1833 "Try to finish anyway? "),
1834 sm
->function
->print_name ()))
1835 error (_("Not confirmed."));
1836 printf_filtered (_("Run till exit from "));
1839 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1842 if (execution_direction
== EXEC_REVERSE
)
1843 finish_backward (sm
);
1846 frame
= skip_finish_frames (frame
);
1849 error (_("Cannot find the caller frame."));
1851 finish_forward (sm
, frame
);
1857 info_program_command (const char *args
, int from_tty
)
1862 process_stratum_target
*proc_target
;
1864 if (!target_has_execution ())
1866 printf_filtered (_("The program being debugged is not being run.\n"));
1872 ptid
= inferior_ptid
;
1873 proc_target
= current_inferior ()->process_target ();
1876 get_last_target_status (&proc_target
, &ptid
, nullptr);
1878 if (ptid
== null_ptid
|| ptid
== minus_one_ptid
)
1879 error (_("No selected thread."));
1881 thread_info
*tp
= find_thread_ptid (proc_target
, ptid
);
1883 if (tp
->state
== THREAD_EXITED
)
1884 error (_("Invalid selected thread."));
1885 else if (tp
->state
== THREAD_RUNNING
)
1886 error (_("Selected thread is running."));
1888 bs
= tp
->control
.stop_bpstat
;
1889 stat
= bpstat_num (&bs
, &num
);
1891 target_files_info ();
1892 printf_filtered (_("Program stopped at %s.\n"),
1893 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
1894 if (tp
->control
.stop_step
)
1895 printf_filtered (_("It stopped after being stepped.\n"));
1898 /* There may be several breakpoints in the same place, so this
1899 isn't as strange as it seems. */
1904 printf_filtered (_("It stopped at a breakpoint "
1905 "that has since been deleted.\n"));
1908 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1909 stat
= bpstat_num (&bs
, &num
);
1912 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
1914 printf_filtered (_("It stopped with signal %s, %s.\n"),
1915 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1916 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1921 printf_filtered (_("Type \"info stack\" or \"info "
1922 "registers\" for more information.\n"));
1927 environment_info (const char *var
, int from_tty
)
1931 const char *val
= current_inferior ()->environment
.get (var
);
1935 puts_filtered (var
);
1936 puts_filtered (" = ");
1937 puts_filtered (val
);
1938 puts_filtered ("\n");
1942 puts_filtered ("Environment variable \"");
1943 puts_filtered (var
);
1944 puts_filtered ("\" not defined.\n");
1949 char **envp
= current_inferior ()->environment
.envp ();
1951 for (int idx
= 0; envp
[idx
] != NULL
; ++idx
)
1953 puts_filtered (envp
[idx
]);
1954 puts_filtered ("\n");
1960 set_environment_command (const char *arg
, int from_tty
)
1962 const char *p
, *val
;
1966 error_no_arg (_("environment variable and value"));
1968 /* Find separation between variable name and value. */
1969 p
= (char *) strchr (arg
, '=');
1970 val
= (char *) strchr (arg
, ' ');
1972 if (p
!= 0 && val
!= 0)
1974 /* We have both a space and an equals. If the space is before the
1975 equals, walk forward over the spaces til we see a nonspace
1976 (possibly the equals). */
1981 /* Now if the = is after the char following the spaces,
1982 take the char following the spaces. */
1986 else if (val
!= 0 && p
== 0)
1990 error_no_arg (_("environment variable to set"));
1992 if (p
== 0 || p
[1] == 0)
1996 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2000 /* Not setting variable value to null. */
2002 while (*val
== ' ' || *val
== '\t')
2006 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2009 std::string
var (arg
, p
- arg
);
2012 printf_filtered (_("Setting environment variable "
2013 "\"%s\" to null value.\n"),
2015 current_inferior ()->environment
.set (var
.c_str (), "");
2018 current_inferior ()->environment
.set (var
.c_str (), val
);
2022 unset_environment_command (const char *var
, int from_tty
)
2026 /* If there is no argument, delete all environment variables.
2027 Ask for confirmation if reading from the terminal. */
2028 if (!from_tty
|| query (_("Delete all environment variables? ")))
2029 current_inferior ()->environment
.clear ();
2032 current_inferior ()->environment
.unset (var
);
2035 /* Handle the execution path (PATH variable). */
2037 static const char path_var_name
[] = "PATH";
2040 path_info (const char *args
, int from_tty
)
2042 puts_filtered ("Executable and object file path: ");
2043 puts_filtered (current_inferior ()->environment
.get (path_var_name
));
2044 puts_filtered ("\n");
2047 /* Add zero or more directories to the front of the execution path. */
2050 path_command (const char *dirname
, int from_tty
)
2056 env
= current_inferior ()->environment
.get (path_var_name
);
2057 /* Can be null if path is not set. */
2060 exec_path
= xstrdup (env
);
2061 mod_path (dirname
, &exec_path
);
2062 current_inferior ()->environment
.set (path_var_name
, exec_path
);
2065 path_info (NULL
, from_tty
);
2070 pad_to_column (string_file
&stream
, int col
)
2072 /* At least one space must be printed to separate columns. */
2074 const int size
= stream
.size ();
2076 stream
.puts (n_spaces (col
- size
));
2079 /* Print out the register NAME with value VAL, to FILE, in the default
2083 default_print_one_register_info (struct ui_file
*file
,
2087 struct type
*regtype
= value_type (val
);
2088 int print_raw_format
;
2089 string_file format_stream
;
2092 value_column_1
= 15,
2093 /* Give enough room for "0x", 16 hex digits and two spaces in
2094 preceding column. */
2095 value_column_2
= value_column_1
+ 2 + 16 + 2,
2098 format_stream
.puts (name
);
2099 pad_to_column (format_stream
, value_column_1
);
2101 print_raw_format
= (value_entirely_available (val
)
2102 && !value_optimized_out (val
));
2104 /* If virtual format is floating, print it that way, and in raw
2106 if (regtype
->code () == TYPE_CODE_FLT
2107 || regtype
->code () == TYPE_CODE_DECFLOAT
)
2109 struct value_print_options opts
;
2110 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2111 enum bfd_endian byte_order
= type_byte_order (regtype
);
2113 get_user_print_options (&opts
);
2116 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2118 if (print_raw_format
)
2120 pad_to_column (format_stream
, value_column_2
);
2121 format_stream
.puts ("(raw ");
2122 print_hex_chars (&format_stream
, valaddr
, TYPE_LENGTH (regtype
),
2124 format_stream
.putc (')');
2129 struct value_print_options opts
;
2131 /* Print the register in hex. */
2132 get_formatted_print_options (&opts
, 'x');
2134 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2135 /* If not a vector register, print it also according to its
2137 if (print_raw_format
&& regtype
->is_vector () == 0)
2139 pad_to_column (format_stream
, value_column_2
);
2140 get_user_print_options (&opts
);
2142 common_val_print (val
, &format_stream
, 0, &opts
, current_language
);
2146 fputs_filtered (format_stream
.c_str (), file
);
2147 fprintf_filtered (file
, "\n");
2150 /* Print out the machine register regnum. If regnum is -1, print all
2151 registers (print_all == 1) or all non-float and non-vector
2152 registers (print_all == 0).
2154 For most machines, having all_registers_info() print the
2155 register(s) one per line is good enough. If a different format is
2156 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2157 regs), or there is an existing convention for showing all the
2158 registers, define the architecture method PRINT_REGISTERS_INFO to
2159 provide that format. */
2162 default_print_registers_info (struct gdbarch
*gdbarch
,
2163 struct ui_file
*file
,
2164 struct frame_info
*frame
,
2165 int regnum
, int print_all
)
2168 const int numregs
= gdbarch_num_cooked_regs (gdbarch
);
2170 for (i
= 0; i
< numregs
; i
++)
2172 /* Decide between printing all regs, non-float / vector regs, or
2178 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2183 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2193 /* If the register name is empty, it is undefined for this
2194 processor, so don't display anything. */
2195 if (gdbarch_register_name (gdbarch
, i
) == NULL
2196 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2199 default_print_one_register_info (file
,
2200 gdbarch_register_name (gdbarch
, i
),
2201 value_of_register (i
, frame
));
2206 registers_info (const char *addr_exp
, int fpregs
)
2208 struct frame_info
*frame
;
2209 struct gdbarch
*gdbarch
;
2211 if (!target_has_registers ())
2212 error (_("The program has no registers now."));
2213 frame
= get_selected_frame (NULL
);
2214 gdbarch
= get_frame_arch (frame
);
2218 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2223 while (*addr_exp
!= '\0')
2228 /* Skip leading white space. */
2229 addr_exp
= skip_spaces (addr_exp
);
2231 /* Discard any leading ``$''. Check that there is something
2232 resembling a register following it. */
2233 if (addr_exp
[0] == '$')
2235 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2236 error (_("Missing register name"));
2238 /* Find the start/end of this register name/num/group. */
2240 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2244 /* Figure out what we've found and display it. */
2246 /* A register name? */
2248 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2252 /* User registers lie completely outside of the range of
2253 normal registers. Catch them early so that the target
2255 if (regnum
>= gdbarch_num_cooked_regs (gdbarch
))
2257 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2258 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2261 /* Print in the same fashion
2262 gdbarch_print_registers_info's default
2263 implementation prints. */
2264 default_print_one_register_info (gdb_stdout
,
2269 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2270 frame
, regnum
, fpregs
);
2275 /* A register group? */
2277 struct reggroup
*group
;
2279 for (group
= reggroup_next (gdbarch
, NULL
);
2281 group
= reggroup_next (gdbarch
, group
))
2283 /* Don't bother with a length check. Should the user
2284 enter a short register group name, go with the first
2285 group that matches. */
2286 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2294 regnum
< gdbarch_num_cooked_regs (gdbarch
);
2297 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2298 gdbarch_print_registers_info (gdbarch
,
2306 /* Nothing matched. */
2307 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2312 info_all_registers_command (const char *addr_exp
, int from_tty
)
2314 registers_info (addr_exp
, 1);
2318 info_registers_command (const char *addr_exp
, int from_tty
)
2320 registers_info (addr_exp
, 0);
2324 print_vector_info (struct ui_file
*file
,
2325 struct frame_info
*frame
, const char *args
)
2327 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2329 if (gdbarch_print_vector_info_p (gdbarch
))
2330 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2334 int printed_something
= 0;
2336 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2338 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2340 printed_something
= 1;
2341 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2344 if (!printed_something
)
2345 fprintf_filtered (file
, "No vector information\n");
2350 info_vector_command (const char *args
, int from_tty
)
2352 if (!target_has_registers ())
2353 error (_("The program has no registers now."));
2355 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2358 /* Kill the inferior process. Make us have no inferior. */
2361 kill_command (const char *arg
, int from_tty
)
2363 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2364 It should be a distinct flag that indicates that a target is active, cuz
2365 some targets don't have processes! */
2367 if (inferior_ptid
== null_ptid
)
2368 error (_("The program is not being run."));
2369 if (!query (_("Kill the program being debugged? ")))
2370 error (_("Not confirmed."));
2372 int pid
= current_inferior ()->pid
;
2373 /* Save the pid as a string before killing the inferior, since that
2374 may unpush the current target, and we need the string after. */
2375 std::string pid_str
= target_pid_to_str (ptid_t (pid
));
2376 int infnum
= current_inferior ()->num
;
2380 if (print_inferior_events
)
2381 printf_unfiltered (_("[Inferior %d (%s) killed]\n"),
2382 infnum
, pid_str
.c_str ());
2384 bfd_cache_close_all ();
2387 /* Used in `attach&' command. Proceed threads of inferior INF iff
2388 they stopped due to debugger request, and when they did, they
2389 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2390 have been explicitly been told to stop. */
2393 proceed_after_attach (inferior
*inf
)
2395 /* Don't error out if the current thread is running, because
2396 there may be other stopped threads. */
2398 /* Backup current thread and selected frame. */
2399 scoped_restore_current_thread restore_thread
;
2401 for (thread_info
*thread
: inf
->non_exited_threads ())
2402 if (!thread
->executing
2403 && !thread
->stop_requested
2404 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2406 switch_to_thread (thread
);
2407 clear_proceed_status (0);
2408 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2412 /* See inferior.h. */
2415 setup_inferior (int from_tty
)
2417 struct inferior
*inferior
;
2419 inferior
= current_inferior ();
2420 inferior
->needs_setup
= 0;
2422 /* If no exec file is yet known, try to determine it from the
2424 if (get_exec_file (0) == NULL
)
2425 exec_file_locate_attach (inferior_ptid
.pid (), 1, from_tty
);
2428 reopen_exec_file ();
2432 /* Take any necessary post-attaching actions for this platform. */
2433 target_post_attach (inferior_ptid
.pid ());
2435 post_create_inferior (from_tty
);
2438 /* What to do after the first program stops after attaching. */
2439 enum attach_post_wait_mode
2441 /* Do nothing. Leaves threads as they are. */
2442 ATTACH_POST_WAIT_NOTHING
,
2444 /* Re-resume threads that are marked running. */
2445 ATTACH_POST_WAIT_RESUME
,
2447 /* Stop all threads. */
2448 ATTACH_POST_WAIT_STOP
,
2451 /* Called after we've attached to a process and we've seen it stop for
2452 the first time. If ASYNC_EXEC is true, re-resume threads that
2453 should be running. Else if ATTACH, */
2456 attach_post_wait (const char *args
, int from_tty
, enum attach_post_wait_mode mode
)
2458 struct inferior
*inferior
;
2460 inferior
= current_inferior ();
2461 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2463 if (inferior
->needs_setup
)
2464 setup_inferior (from_tty
);
2466 if (mode
== ATTACH_POST_WAIT_RESUME
)
2468 /* The user requested an `attach&', so be sure to leave threads
2469 that didn't get a signal running. */
2471 /* Immediatelly resume all suspended threads of this inferior,
2472 and this inferior only. This should have no effect on
2473 already running threads. If a thread has been stopped with a
2474 signal, leave it be. */
2476 proceed_after_attach (inferior
);
2479 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2481 clear_proceed_status (0);
2482 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2486 else if (mode
== ATTACH_POST_WAIT_STOP
)
2488 /* The user requested a plain `attach', so be sure to leave
2489 the inferior stopped. */
2491 /* At least the current thread is already stopped. */
2493 /* In all-stop, by definition, all threads have to be already
2494 stopped at this point. In non-stop, however, although the
2495 selected thread is stopped, others may still be executing.
2496 Be sure to explicitly stop all threads of the process. This
2497 should have no effect on already stopped threads. */
2499 target_stop (ptid_t (inferior
->pid
));
2500 else if (target_is_non_stop_p ())
2502 struct thread_info
*lowest
= inferior_thread ();
2504 stop_all_threads ();
2506 /* It's not defined which thread will report the attach
2507 stop. For consistency, always select the thread with
2508 lowest GDB number, which should be the main thread, if it
2510 for (thread_info
*thread
: current_inferior ()->non_exited_threads ())
2511 if (thread
->inf
->num
< lowest
->inf
->num
2512 || thread
->per_inf_num
< lowest
->per_inf_num
)
2515 switch_to_thread (lowest
);
2518 /* Tell the user/frontend where we're stopped. */
2520 if (deprecated_attach_hook
)
2521 deprecated_attach_hook ();
2525 struct attach_command_continuation_args
2529 enum attach_post_wait_mode mode
;
2533 attach_command_continuation (void *args
, int err
)
2535 struct attach_command_continuation_args
*a
2536 = (struct attach_command_continuation_args
*) args
;
2541 attach_post_wait (a
->args
, a
->from_tty
, a
->mode
);
2545 attach_command_continuation_free_args (void *args
)
2547 struct attach_command_continuation_args
*a
2548 = (struct attach_command_continuation_args
*) args
;
2554 /* "attach" command entry point. Takes a program started up outside
2555 of gdb and ``attaches'' to it. This stops it cold in its tracks
2556 and allows us to start debugging it. */
2559 attach_command (const char *args
, int from_tty
)
2562 struct target_ops
*attach_target
;
2563 struct inferior
*inferior
= current_inferior ();
2564 enum attach_post_wait_mode mode
;
2566 dont_repeat (); /* Not for the faint of heart */
2568 if (gdbarch_has_global_solist (target_gdbarch ()))
2569 /* Don't complain if all processes share the same symbol
2572 else if (target_has_execution ())
2574 if (query (_("A program is being debugged already. Kill it? ")))
2577 error (_("Not killed."));
2580 /* Clean up any leftovers from other runs. Some other things from
2581 this function should probably be moved into target_pre_inferior. */
2582 target_pre_inferior (from_tty
);
2584 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
2585 args
= stripped
.get ();
2587 attach_target
= find_attach_target ();
2589 prepare_execution_command (attach_target
, async_exec
);
2591 if (non_stop
&& !attach_target
->supports_non_stop ())
2592 error (_("Cannot attach to this target in non-stop mode"));
2594 attach_target
->attach (args
, from_tty
);
2595 /* to_attach should push the target, so after this point we
2596 shouldn't refer to attach_target again. */
2597 attach_target
= NULL
;
2599 /* Set up the "saved terminal modes" of the inferior
2600 based on what modes we are starting it with. */
2601 target_terminal::init ();
2603 /* Install inferior's terminal modes. This may look like a no-op,
2604 as we've just saved them above, however, this does more than
2605 restore terminal settings:
2607 - installs a SIGINT handler that forwards SIGINT to the inferior.
2608 Otherwise a Ctrl-C pressed just while waiting for the initial
2609 stop would end up as a spurious Quit.
2611 - removes stdin from the event loop, which we need if attaching
2612 in the foreground, otherwise on targets that report an initial
2613 stop on attach (which are most) we'd process input/commands
2614 while we're in the event loop waiting for that stop. That is,
2615 before the attach continuation runs and the command is really
2617 target_terminal::inferior ();
2619 /* Set up execution context to know that we should return from
2620 wait_for_inferior as soon as the target reports a stop. */
2621 init_wait_for_inferior ();
2623 inferior
->needs_setup
= 1;
2625 if (target_is_non_stop_p ())
2627 /* If we find that the current thread isn't stopped, explicitly
2628 do so now, because we're going to install breakpoints and
2632 /* The user requested an `attach&'; stop just one thread. */
2633 target_stop (inferior_ptid
);
2635 /* The user requested an `attach', so stop all threads of this
2637 target_stop (ptid_t (inferior_ptid
.pid ()));
2640 /* Check for exec file mismatch, and let the user solve it. */
2641 validate_exec_file (from_tty
);
2643 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2645 /* Some system don't generate traps when attaching to inferior.
2646 E.g. Mach 3 or GNU hurd. */
2647 if (!target_attach_no_wait ())
2649 struct attach_command_continuation_args
*a
;
2651 /* Careful here. See comments in inferior.h. Basically some
2652 OSes don't ignore SIGSTOPs on continue requests anymore. We
2653 need a way for handle_inferior_event to reset the stop_signal
2654 variable after an attach, and this is what
2655 STOP_QUIETLY_NO_SIGSTOP is for. */
2656 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2658 /* Wait for stop. */
2659 a
= XNEW (struct attach_command_continuation_args
);
2660 a
->args
= xstrdup (args
);
2661 a
->from_tty
= from_tty
;
2663 add_inferior_continuation (attach_command_continuation
, a
,
2664 attach_command_continuation_free_args
);
2666 /* Let infrun consider waiting for events out of this
2668 inferior
->process_target ()->threads_executing
= true;
2670 if (!target_is_async_p ())
2671 mark_infrun_async_event_handler ();
2675 attach_post_wait (args
, from_tty
, mode
);
2678 /* We had just found out that the target was already attached to an
2679 inferior. PTID points at a thread of this new inferior, that is
2680 the most likely to be stopped right now, but not necessarily so.
2681 The new inferior is assumed to be already added to the inferior
2682 list at this point. If LEAVE_RUNNING, then leave the threads of
2683 this inferior running, except those we've explicitly seen reported
2687 notice_new_inferior (thread_info
*thr
, int leave_running
, int from_tty
)
2689 enum attach_post_wait_mode mode
2690 = leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2692 gdb::optional
<scoped_restore_current_thread
> restore_thread
;
2694 if (inferior_ptid
!= null_ptid
)
2695 restore_thread
.emplace ();
2697 /* Avoid reading registers -- we haven't fetched the target
2699 switch_to_thread_no_regs (thr
);
2701 /* When we "notice" a new inferior we need to do all the things we
2702 would normally do if we had just attached to it. */
2706 struct attach_command_continuation_args
*a
;
2707 struct inferior
*inferior
= current_inferior ();
2709 /* We're going to install breakpoints, and poke at memory,
2710 ensure that the inferior is stopped for a moment while we do
2712 target_stop (inferior_ptid
);
2714 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2716 /* Wait for stop before proceeding. */
2717 a
= XNEW (struct attach_command_continuation_args
);
2718 a
->args
= xstrdup ("");
2719 a
->from_tty
= from_tty
;
2721 add_inferior_continuation (attach_command_continuation
, a
,
2722 attach_command_continuation_free_args
);
2727 attach_post_wait ("" /* args */, from_tty
, mode
);
2732 * takes a program previously attached to and detaches it.
2733 * The program resumes execution and will no longer stop
2734 * on signals, etc. We better not have left any breakpoints
2735 * in the program or it'll die when it hits one. For this
2736 * to work, it may be necessary for the process to have been
2737 * previously attached. It *might* work if the program was
2738 * started via the normal ptrace (PTRACE_TRACEME).
2742 detach_command (const char *args
, int from_tty
)
2744 dont_repeat (); /* Not for the faint of heart. */
2746 if (inferior_ptid
== null_ptid
)
2747 error (_("The program is not being run."));
2749 query_if_trace_running (from_tty
);
2751 disconnect_tracing ();
2753 target_detach (current_inferior (), from_tty
);
2755 /* The current inferior process was just detached successfully. Get
2756 rid of breakpoints that no longer make sense. Note we don't do
2757 this within target_detach because that is also used when
2758 following child forks, and in that case we will want to transfer
2759 breakpoints to the child, not delete them. */
2760 breakpoint_init_inferior (inf_exited
);
2762 /* If the solist is global across inferiors, don't clear it when we
2763 detach from a single inferior. */
2764 if (!gdbarch_has_global_solist (target_gdbarch ()))
2765 no_shared_libraries (NULL
, from_tty
);
2767 if (deprecated_detach_hook
)
2768 deprecated_detach_hook ();
2771 /* Disconnect from the current target without resuming it (leaving it
2772 waiting for a debugger).
2774 We'd better not have left any breakpoints in the program or the
2775 next debugger will get confused. Currently only supported for some
2776 remote targets, since the normal attach mechanisms don't work on
2777 stopped processes on some native platforms (e.g. GNU/Linux). */
2780 disconnect_command (const char *args
, int from_tty
)
2782 dont_repeat (); /* Not for the faint of heart. */
2783 query_if_trace_running (from_tty
);
2784 disconnect_tracing ();
2785 target_disconnect (args
, from_tty
);
2786 no_shared_libraries (NULL
, from_tty
);
2787 init_thread_list ();
2788 if (deprecated_detach_hook
)
2789 deprecated_detach_hook ();
2792 /* Stop PTID in the current target, and tag the PTID threads as having
2793 been explicitly requested to stop. PTID can be a thread, a
2794 process, or minus_one_ptid, meaning all threads of all inferiors of
2795 the current target. */
2798 stop_current_target_threads_ns (ptid_t ptid
)
2802 /* Tag the thread as having been explicitly requested to stop, so
2803 other parts of gdb know not to resume this thread automatically,
2804 if it was stopped due to an internal event. Limit this to
2805 non-stop mode, as when debugging a multi-threaded application in
2806 all-stop mode, we will only get one stop event --- it's undefined
2807 which thread will report the event. */
2808 set_stop_requested (current_inferior ()->process_target (),
2812 /* See inferior.h. */
2815 interrupt_target_1 (bool all_threads
)
2821 scoped_restore_current_thread restore_thread
;
2823 for (inferior
*inf
: all_inferiors ())
2825 switch_to_inferior_no_thread (inf
);
2826 stop_current_target_threads_ns (minus_one_ptid
);
2830 stop_current_target_threads_ns (inferior_ptid
);
2833 target_interrupt ();
2837 Stop the execution of the target while running in async mode, in
2838 the background. In all-stop, stop the whole process. In non-stop
2839 mode, stop the current thread only by default, or stop all threads
2840 if the `-a' switch is used. */
2843 interrupt_command (const char *args
, int from_tty
)
2845 if (target_can_async_p ())
2847 int all_threads
= 0;
2849 dont_repeat (); /* Not for the faint of heart. */
2852 && startswith (args
, "-a"))
2855 if (!non_stop
&& all_threads
)
2856 error (_("-a is meaningless in all-stop mode."));
2858 interrupt_target_1 (all_threads
);
2862 /* See inferior.h. */
2865 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2866 struct frame_info
*frame
, const char *args
)
2869 int printed_something
= 0;
2871 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2873 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2875 printed_something
= 1;
2876 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2879 if (!printed_something
)
2880 fprintf_filtered (file
, "No floating-point info "
2881 "available for this processor.\n");
2885 info_float_command (const char *args
, int from_tty
)
2887 struct frame_info
*frame
;
2889 if (!target_has_registers ())
2890 error (_("The program has no registers now."));
2892 frame
= get_selected_frame (NULL
);
2893 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
2896 /* Implement `info proc' family of commands. */
2899 info_proc_cmd_1 (const char *args
, enum info_proc_what what
, int from_tty
)
2901 struct gdbarch
*gdbarch
= get_current_arch ();
2903 if (!target_info_proc (args
, what
))
2905 if (gdbarch_info_proc_p (gdbarch
))
2906 gdbarch_info_proc (gdbarch
, args
, what
);
2908 error (_("Not supported on this target."));
2912 /* Implement `info proc' when given without any further parameters. */
2915 info_proc_cmd (const char *args
, int from_tty
)
2917 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
2920 /* Implement `info proc mappings'. */
2923 info_proc_cmd_mappings (const char *args
, int from_tty
)
2925 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
2928 /* Implement `info proc stat'. */
2931 info_proc_cmd_stat (const char *args
, int from_tty
)
2933 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
2936 /* Implement `info proc status'. */
2939 info_proc_cmd_status (const char *args
, int from_tty
)
2941 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
2944 /* Implement `info proc cwd'. */
2947 info_proc_cmd_cwd (const char *args
, int from_tty
)
2949 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
2952 /* Implement `info proc cmdline'. */
2955 info_proc_cmd_cmdline (const char *args
, int from_tty
)
2957 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
2960 /* Implement `info proc exe'. */
2963 info_proc_cmd_exe (const char *args
, int from_tty
)
2965 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
2968 /* Implement `info proc files'. */
2971 info_proc_cmd_files (const char *args
, int from_tty
)
2973 info_proc_cmd_1 (args
, IP_FILES
, from_tty
);
2976 /* Implement `info proc all'. */
2979 info_proc_cmd_all (const char *args
, int from_tty
)
2981 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
2984 /* Implement `show print finish'. */
2987 show_print_finish (struct ui_file
*file
, int from_tty
,
2988 struct cmd_list_element
*c
,
2991 fprintf_filtered (file
, _("\
2992 Printing of return value after `finish' is %s.\n"),
2997 /* This help string is used for the run, start, and starti commands.
2998 It is defined as a macro to prevent duplication. */
3000 #define RUN_ARGS_HELP \
3001 "You may specify arguments to give it.\n\
3002 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3003 shell that will start the program (specified by the \"$SHELL\" environment\n\
3004 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
3005 are also allowed.\n\
3007 With no arguments, uses arguments last specified (with \"run\" or \n\
3008 \"set args\"). To cancel previous arguments and run with no arguments,\n\
3009 use \"set args\" without arguments.\n\
3011 To start the inferior without using a shell, use \"set startup-with-shell off\"."
3013 void _initialize_infcmd ();
3015 _initialize_infcmd ()
3017 static struct cmd_list_element
*info_proc_cmdlist
;
3018 struct cmd_list_element
*c
= NULL
;
3019 const char *cmd_name
;
3021 /* Add the filename of the terminal connected to inferior I/O. */
3022 add_setshow_optional_filename_cmd ("inferior-tty", class_run
,
3023 &inferior_io_terminal_scratch
, _("\
3024 Set terminal for future runs of program being debugged."), _("\
3025 Show terminal for future runs of program being debugged."), _("\
3026 Usage: set inferior-tty [TTY]\n\n\
3027 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3029 set_inferior_tty_command
,
3030 show_inferior_tty_command
,
3031 &setlist
, &showlist
);
3032 cmd_name
= "inferior-tty";
3033 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
3034 gdb_assert (c
!= NULL
);
3035 add_alias_cmd ("tty", c
, class_run
, 0, &cmdlist
);
3038 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3039 &inferior_args_scratch
, _("\
3040 Set argument list to give program being debugged when it is started."), _("\
3041 Show argument list to give program being debugged when it is started."), _("\
3042 Follow this command with any number of args, to be passed to the program."),
3045 &setlist
, &showlist
);
3046 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
3047 gdb_assert (c
!= NULL
);
3048 set_cmd_completer (c
, filename_completer
);
3051 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3052 &inferior_cwd_scratch
, _("\
3053 Set the current working directory to be used when the inferior is started.\n\
3054 Changing this setting does not have any effect on inferiors that are\n\
3057 Show the current working directory that is used when the inferior is started."),
3059 Use this command to change the current working directory that will be used\n\
3060 when the inferior is started. This setting does not affect GDB's current\n\
3061 working directory."),
3064 &setlist
, &showlist
);
3065 c
= lookup_cmd (&cmd_name
, setlist
, "", NULL
, -1, 1);
3066 gdb_assert (c
!= NULL
);
3067 set_cmd_completer (c
, filename_completer
);
3069 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3070 The environment to give the program, or one variable's value.\n\
3071 With an argument VAR, prints the value of environment variable VAR to\n\
3072 give the program being debugged. With no arguments, prints the entire\n\
3073 environment to be given to the program."), &showlist
);
3074 set_cmd_completer (c
, noop_completer
);
3076 add_basic_prefix_cmd ("unset", no_class
,
3077 _("Complement to certain \"set\" commands."),
3078 &unsetlist
, "unset ", 0, &cmdlist
);
3080 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3081 Cancel environment variable VAR for the program.\n\
3082 This does not affect the program until the next \"run\" command."),
3084 set_cmd_completer (c
, noop_completer
);
3086 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3087 Set environment variable value to give the program.\n\
3088 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3089 VALUES of environment variables are uninterpreted strings.\n\
3090 This does not affect the program until the next \"run\" command."),
3092 set_cmd_completer (c
, noop_completer
);
3094 c
= add_com ("path", class_files
, path_command
, _("\
3095 Add directory DIR(s) to beginning of search path for object files.\n\
3096 $cwd in the path means the current working directory.\n\
3097 This path is equivalent to the $PATH shell variable. It is a list of\n\
3098 directories, separated by colons. These directories are searched to find\n\
3099 fully linked executable files and separately compiled object files as \
3101 set_cmd_completer (c
, filename_completer
);
3103 c
= add_cmd ("paths", no_class
, path_info
, _("\
3104 Current search path for finding object files.\n\
3105 $cwd in the path means the current working directory.\n\
3106 This path is equivalent to the $PATH shell variable. It is a list of\n\
3107 directories, separated by colons. These directories are searched to find\n\
3108 fully linked executable files and separately compiled object files as \
3111 set_cmd_completer (c
, noop_completer
);
3113 add_prefix_cmd ("kill", class_run
, kill_command
,
3114 _("Kill execution of program being debugged."),
3115 &killlist
, "kill ", 0, &cmdlist
);
3117 add_com ("attach", class_run
, attach_command
, _("\
3118 Attach to a process or file outside of GDB.\n\
3119 This command attaches to another target, of the same type as your last\n\
3120 \"target\" command (\"info files\" will show your target stack).\n\
3121 The command may take as argument a process id or a device file.\n\
3122 For a process id, you must have permission to send the process a signal,\n\
3123 and it must have the same effective uid as the debugger.\n\
3124 When using \"attach\" with a process id, the debugger finds the\n\
3125 program running in the process, looking first in the current working\n\
3126 directory, or (if not found there) using the source file search path\n\
3127 (see the \"directory\" command). You can also use the \"file\" command\n\
3128 to specify the program, and to load its symbol table."));
3130 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3131 Detach a process or file previously attached.\n\
3132 If a process, it is no longer traced, and it continues its execution. If\n\
3133 you were debugging a file, the file is closed and gdb no longer accesses it."),
3134 &detachlist
, "detach ", 0, &cmdlist
);
3136 add_com ("disconnect", class_run
, disconnect_command
, _("\
3137 Disconnect from a target.\n\
3138 The target will wait for another debugger to connect. Not available for\n\
3141 c
= add_com ("signal", class_run
, signal_command
, _("\
3142 Continue program with the specified signal.\n\
3143 Usage: signal SIGNAL\n\
3144 The SIGNAL argument is processed the same as the handle command.\n\
3146 An argument of \"0\" means continue the program without sending it a signal.\n\
3147 This is useful in cases where the program stopped because of a signal,\n\
3148 and you want to resume the program while discarding the signal.\n\
3150 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3151 the current thread only."));
3152 set_cmd_completer (c
, signal_completer
);
3154 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3155 Queue a signal to be delivered to the current thread when it is resumed.\n\
3156 Usage: queue-signal SIGNAL\n\
3157 The SIGNAL argument is processed the same as the handle command.\n\
3158 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3160 An argument of \"0\" means remove any currently queued signal from\n\
3161 the current thread. This is useful in cases where the program stopped\n\
3162 because of a signal, and you want to resume it while discarding the signal.\n\
3164 In a multi-threaded program the signal is queued with, or discarded from,\n\
3165 the current thread only."));
3166 set_cmd_completer (c
, signal_completer
);
3168 add_com ("stepi", class_run
, stepi_command
, _("\
3169 Step one instruction exactly.\n\
3171 Argument N means step N times (or till program stops for another \
3173 add_com_alias ("si", "stepi", class_run
, 0);
3175 add_com ("nexti", class_run
, nexti_command
, _("\
3176 Step one instruction, but proceed through subroutine calls.\n\
3178 Argument N means step N times (or till program stops for another \
3180 add_com_alias ("ni", "nexti", class_run
, 0);
3182 add_com ("finish", class_run
, finish_command
, _("\
3183 Execute until selected stack frame returns.\n\
3185 Upon return, the value returned is printed and put in the value history."));
3186 add_com_alias ("fin", "finish", class_run
, 1);
3188 add_com ("next", class_run
, next_command
, _("\
3189 Step program, proceeding through subroutine calls.\n\
3191 Unlike \"step\", if the current source line calls a subroutine,\n\
3192 this command does not enter the subroutine, but instead steps over\n\
3193 the call, in effect treating it as a single source line."));
3194 add_com_alias ("n", "next", class_run
, 1);
3196 add_com ("step", class_run
, step_command
, _("\
3197 Step program until it reaches a different source line.\n\
3199 Argument N means step N times (or till program stops for another \
3201 add_com_alias ("s", "step", class_run
, 1);
3203 c
= add_com ("until", class_run
, until_command
, _("\
3204 Execute until past the current line or past a LOCATION.\n\
3205 Execute until the program reaches a source line greater than the current\n\
3206 or a specified location (same args as break command) within the current \
3208 set_cmd_completer (c
, location_completer
);
3209 add_com_alias ("u", "until", class_run
, 1);
3211 c
= add_com ("advance", class_run
, advance_command
, _("\
3212 Continue the program up to the given location (same form as args for break \
3214 Execution will also stop upon exit from the current stack frame."));
3215 set_cmd_completer (c
, location_completer
);
3217 c
= add_com ("jump", class_run
, jump_command
, _("\
3218 Continue program being debugged at specified line or address.\n\
3219 Usage: jump LOCATION\n\
3220 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3221 for an address to start at."));
3222 set_cmd_completer (c
, location_completer
);
3223 add_com_alias ("j", "jump", class_run
, 1);
3225 add_com ("continue", class_run
, continue_command
, _("\
3226 Continue program being debugged, after signal or breakpoint.\n\
3227 Usage: continue [N]\n\
3228 If proceeding from breakpoint, a number N may be used as an argument,\n\
3229 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3230 the breakpoint won't break until the Nth time it is reached).\n\
3232 If non-stop mode is enabled, continue only the current thread,\n\
3233 otherwise all the threads in the program are continued. To \n\
3234 continue all stopped threads in non-stop mode, use the -a option.\n\
3235 Specifying -a and an ignore count simultaneously is an error."));
3236 add_com_alias ("c", "cont", class_run
, 1);
3237 add_com_alias ("fg", "cont", class_run
, 1);
3239 c
= add_com ("run", class_run
, run_command
, _("\
3240 Start debugged program.\n"
3242 set_cmd_completer (c
, filename_completer
);
3243 add_com_alias ("r", "run", class_run
, 1);
3245 c
= add_com ("start", class_run
, start_command
, _("\
3246 Start the debugged program stopping at the beginning of the main procedure.\n"
3248 set_cmd_completer (c
, filename_completer
);
3250 c
= add_com ("starti", class_run
, starti_command
, _("\
3251 Start the debugged program stopping at the first instruction.\n"
3253 set_cmd_completer (c
, filename_completer
);
3255 add_com ("interrupt", class_run
, interrupt_command
,
3256 _("Interrupt the execution of the debugged program.\n\
3257 If non-stop mode is enabled, interrupt only the current thread,\n\
3258 otherwise all the threads in the program are stopped. To \n\
3259 interrupt all running threads in non-stop mode, use the -a option."));
3261 c
= add_info ("registers", info_registers_command
, _("\
3262 List of integer registers and their contents, for selected stack frame.\n\
3263 One or more register names as argument means describe the given registers.\n\
3264 One or more register group names as argument means describe the registers\n\
3265 in the named register groups."));
3266 add_info_alias ("r", "registers", 1);
3267 set_cmd_completer (c
, reg_or_group_completer
);
3269 c
= add_info ("all-registers", info_all_registers_command
, _("\
3270 List of all registers and their contents, for selected stack frame.\n\
3271 One or more register names as argument means describe the given registers.\n\
3272 One or more register group names as argument means describe the registers\n\
3273 in the named register groups."));
3274 set_cmd_completer (c
, reg_or_group_completer
);
3276 add_info ("program", info_program_command
,
3277 _("Execution status of the program."));
3279 add_info ("float", info_float_command
,
3280 _("Print the status of the floating point unit."));
3282 add_info ("vector", info_vector_command
,
3283 _("Print the status of the vector unit."));
3285 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3287 Show additional information about a process.\n\
3288 Specify any process id, or use the program being debugged by default."),
3289 &info_proc_cmdlist
, "info proc ",
3290 1/*allow-unknown*/, &infolist
);
3292 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3293 List memory regions mapped by the specified process."),
3294 &info_proc_cmdlist
);
3296 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3297 List process info from /proc/PID/stat."),
3298 &info_proc_cmdlist
);
3300 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3301 List process info from /proc/PID/status."),
3302 &info_proc_cmdlist
);
3304 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3305 List current working directory of the specified process."),
3306 &info_proc_cmdlist
);
3308 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3309 List command line arguments of the specified process."),
3310 &info_proc_cmdlist
);
3312 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3313 List absolute filename for executable of the specified process."),
3314 &info_proc_cmdlist
);
3316 add_cmd ("files", class_info
, info_proc_cmd_files
, _("\
3317 List files opened by the specified process."),
3318 &info_proc_cmdlist
);
3320 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3321 List all available info about the specified process."),
3322 &info_proc_cmdlist
);
3324 add_setshow_boolean_cmd ("finish", class_support
,
3325 &user_print_options
.finish_print
, _("\
3326 Set whether `finish' prints the return value."), _("\
3327 Show whether `finish' prints the return value."), NULL
,
3330 &setprintlist
, &showprintlist
);