1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2019 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"
55 #include "gdbsupport/gdb_optional.h"
57 #include "cli/cli-style.h"
59 /* Local functions: */
61 static void until_next_command (int);
63 static void step_1 (int, int, const char *);
65 #define ERROR_NO_INFERIOR \
66 if (!target_has_execution) error (_("The program is not being run."));
68 /* Scratch area where string containing arguments to give to the
69 program will be stored by 'set args'. As soon as anything is
70 stored, notice_args_set will move it into per-inferior storage.
71 Arguments are separated by spaces. Empty string (pointer to '\0')
74 static char *inferior_args_scratch
;
76 /* Scratch area where the new cwd will be stored by 'set cwd'. */
78 static char *inferior_cwd_scratch
;
80 /* Scratch area where 'set inferior-tty' will store user-provided value.
81 We'll immediate copy it into per-inferior storage. */
83 static char *inferior_io_terminal_scratch
;
85 /* Pid of our debugged inferior, or 0 if no inferior now.
86 Since various parts of infrun.c test this to see whether there is a program
87 being debugged it should be nonzero (currently 3 is used) for remote
92 /* Nonzero if stopped due to completion of a stack dummy routine. */
94 enum stop_stack_kind stop_stack_dummy
;
96 /* Nonzero if stopped due to a random (unexpected) signal in inferior
99 int stopped_by_random_signal
;
102 /* Accessor routines. */
104 /* Set the io terminal for the current inferior. Ownership of
105 TERMINAL_NAME is not transferred. */
108 set_inferior_io_terminal (const char *terminal_name
)
110 xfree (current_inferior ()->terminal
);
112 if (terminal_name
!= NULL
&& *terminal_name
!= '\0')
113 current_inferior ()->terminal
= xstrdup (terminal_name
);
115 current_inferior ()->terminal
= NULL
;
119 get_inferior_io_terminal (void)
121 return current_inferior ()->terminal
;
125 set_inferior_tty_command (const char *args
, int from_tty
,
126 struct cmd_list_element
*c
)
128 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
129 Now route it to current inferior. */
130 set_inferior_io_terminal (inferior_io_terminal_scratch
);
134 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
135 struct cmd_list_element
*c
, const char *value
)
137 /* Note that we ignore the passed-in value in favor of computing it
139 const char *inferior_io_terminal
= get_inferior_io_terminal ();
141 if (inferior_io_terminal
== NULL
)
142 inferior_io_terminal
= "";
143 fprintf_filtered (gdb_stdout
,
144 _("Terminal for future runs of program being debugged "
145 "is \"%s\".\n"), inferior_io_terminal
);
149 get_inferior_args (void)
151 if (current_inferior ()->argc
!= 0)
155 n
= construct_inferior_arguments (current_inferior ()->argc
,
156 current_inferior ()->argv
);
157 set_inferior_args (n
);
161 if (current_inferior ()->args
== NULL
)
162 current_inferior ()->args
= xstrdup ("");
164 return current_inferior ()->args
;
167 /* Set the arguments for the current inferior. Ownership of
168 NEWARGS is not transferred. */
171 set_inferior_args (const char *newargs
)
173 xfree (current_inferior ()->args
);
174 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
175 current_inferior ()->argc
= 0;
176 current_inferior ()->argv
= 0;
180 set_inferior_args_vector (int argc
, char **argv
)
182 current_inferior ()->argc
= argc
;
183 current_inferior ()->argv
= argv
;
186 /* Notice when `set args' is run. */
189 set_args_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
191 /* CLI has assigned the user-provided value to inferior_args_scratch.
192 Now route it to current inferior. */
193 set_inferior_args (inferior_args_scratch
);
196 /* Notice when `show args' is run. */
199 show_args_command (struct ui_file
*file
, int from_tty
,
200 struct cmd_list_element
*c
, const char *value
)
202 /* Note that we ignore the passed-in value in favor of computing it
204 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
207 /* See gdbsupport/common-inferior.h. */
210 set_inferior_cwd (const char *cwd
)
212 struct inferior
*inf
= current_inferior ();
214 gdb_assert (inf
!= NULL
);
219 inf
->cwd
.reset (xstrdup (cwd
));
222 /* See gdbsupport/common-inferior.h. */
227 return current_inferior ()->cwd
.get ();
230 /* Handle the 'set cwd' command. */
233 set_cwd_command (const char *args
, int from_tty
, struct cmd_list_element
*c
)
235 if (*inferior_cwd_scratch
== '\0')
236 set_inferior_cwd (NULL
);
238 set_inferior_cwd (inferior_cwd_scratch
);
241 /* Handle the 'show cwd' command. */
244 show_cwd_command (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
, const char *value
)
247 const char *cwd
= get_inferior_cwd ();
250 fprintf_filtered (gdb_stdout
,
252 You have not set the inferior's current working directory.\n\
253 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
254 server's cwd if remote debugging.\n"));
256 fprintf_filtered (gdb_stdout
,
257 _("Current working directory that will be used "
258 "when starting the inferior is \"%s\".\n"), cwd
);
262 /* Compute command-line string given argument vector. This does the
263 same shell processing as fork_inferior. */
266 construct_inferior_arguments (int argc
, char **argv
)
270 if (startup_with_shell
)
273 /* This holds all the characters considered special to the
275 static const char special
[] = "\"!&*|[]{}<>?`~^=;, \t\n";
276 static const char quote
= '"';
278 /* This holds all the characters considered special to the
279 typical Unix shells. We include `^' because the SunOS
280 /bin/sh treats it as a synonym for `|'. */
281 static const char special
[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
282 static const char quote
= '\'';
288 /* We over-compute the size. It shouldn't matter. */
289 for (i
= 0; i
< argc
; ++i
)
290 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
292 result
= (char *) xmalloc (length
);
295 for (i
= 0; i
< argc
; ++i
)
300 /* Need to handle empty arguments specially. */
301 if (argv
[i
][0] == '\0')
311 if (strpbrk (argv
[i
], special
))
317 for (cp
= argv
[i
]; *cp
; ++cp
)
321 /* A newline cannot be quoted with a backslash (it
322 just disappears), only by putting it inside
333 if (strchr (special
, *cp
) != NULL
)
349 /* In this case we can't handle arguments that contain spaces,
350 tabs, or newlines -- see breakup_args(). */
354 for (i
= 0; i
< argc
; ++i
)
356 char *cp
= strchr (argv
[i
], ' ');
358 cp
= strchr (argv
[i
], '\t');
360 cp
= strchr (argv
[i
], '\n');
362 error (_("can't handle command-line "
363 "argument containing whitespace"));
364 length
+= strlen (argv
[i
]) + 1;
367 result
= (char *) xmalloc (length
);
369 for (i
= 0; i
< argc
; ++i
)
372 strcat (result
, " ");
373 strcat (result
, argv
[i
]);
381 /* This function strips the '&' character (indicating background
382 execution) that is added as *the last* of the arguments ARGS of a
383 command. A copy of the incoming ARGS without the '&' is returned,
384 unless the resulting string after stripping is empty, in which case
385 NULL is returned. *BG_CHAR_P is an output boolean that indicates
386 whether the '&' character was found. */
388 static gdb::unique_xmalloc_ptr
<char>
389 strip_bg_char (const char *args
, int *bg_char_p
)
393 if (args
== NULL
|| *args
== '\0')
399 p
= args
+ strlen (args
);
403 while (p
> args
&& isspace (p
[-1]))
408 return gdb::unique_xmalloc_ptr
<char>
409 (savestring (args
, p
- args
));
411 return gdb::unique_xmalloc_ptr
<char> (nullptr);
415 return make_unique_xstrdup (args
);
418 /* Common actions to take after creating any sort of inferior, by any
419 means (running, attaching, connecting, et cetera). The target
420 should be stopped. */
423 post_create_inferior (struct target_ops
*target
, int from_tty
)
426 /* Be sure we own the terminal in case write operations are performed. */
427 target_terminal::ours_for_output ();
429 /* If the target hasn't taken care of this already, do it now.
430 Targets which need to access registers during to_open,
431 to_create_inferior, or to_attach should do it earlier; but many
433 target_find_description ();
435 /* Now that we know the register layout, retrieve current PC. But
436 if the PC is unavailable (e.g., we're opening a core file with
437 missing registers info), ignore it. */
438 thread_info
*thr
= inferior_thread ();
440 thr
->suspend
.stop_pc
= 0;
443 thr
->suspend
.stop_pc
= regcache_read_pc (get_current_regcache ());
445 catch (const gdb_exception_error
&ex
)
447 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
453 const unsigned solib_add_generation
454 = current_program_space
->solib_add_generation
;
456 /* Create the hooks to handle shared library load and unload
458 solib_create_inferior_hook (from_tty
);
460 if (current_program_space
->solib_add_generation
== solib_add_generation
)
462 /* The platform-specific hook should load initial shared libraries,
463 but didn't. FROM_TTY will be incorrectly 0 but such solib
464 targets should be fixed anyway. Call it only after the solib
465 target has been initialized by solib_create_inferior_hook. */
468 warning (_("platform-specific solib_create_inferior_hook did "
469 "not load initial shared libraries."));
471 /* If the solist is global across processes, there's no need to
473 if (!gdbarch_has_global_solist (target_gdbarch ()))
474 solib_add (NULL
, 0, auto_solib_add
);
478 /* If the user sets watchpoints before execution having started,
479 then she gets software watchpoints, because GDB can't know which
480 target will end up being pushed, or if it supports hardware
481 watchpoints or not. breakpoint_re_set takes care of promoting
482 watchpoints to hardware watchpoints if possible, however, if this
483 new inferior doesn't load shared libraries or we don't pull in
484 symbols from any other source on this target/arch,
485 breakpoint_re_set is never called. Call it now so that software
486 watchpoints get a chance to be promoted to hardware watchpoints
487 if the now pushed target supports hardware watchpoints. */
488 breakpoint_re_set ();
490 gdb::observers::inferior_created
.notify (target
, from_tty
);
493 /* Kill the inferior if already running. This function is designed
494 to be called when we are about to start the execution of the program
495 from the beginning. Ask the user to confirm that he wants to restart
496 the program being debugged when FROM_TTY is non-null. */
499 kill_if_already_running (int from_tty
)
501 if (inferior_ptid
!= null_ptid
&& target_has_execution
)
503 /* Bail out before killing the program if we will not be able to
505 target_require_runnable ();
508 && !query (_("The program being debugged has been started already.\n\
509 Start it from the beginning? ")))
510 error (_("Program not restarted."));
515 /* See inferior.h. */
518 prepare_execution_command (struct target_ops
*target
, int background
)
520 /* If we get a request for running in the bg but the target
521 doesn't support it, error out. */
522 if (background
&& !target
->can_async_p ())
523 error (_("Asynchronous execution not supported on this target."));
527 /* If we get a request for running in the fg, then we need to
528 simulate synchronous (fg) execution. Note no cleanup is
529 necessary for this. stdin is re-enabled whenever an error
530 reaches the top level. */
531 all_uis_on_sync_execution_starting ();
535 /* Determine how the new inferior will behave. */
539 /* Run program without any explicit stop during startup. */
542 /* Stop at the beginning of the program's main function. */
545 /* Stop at the first instruction of the program. */
546 RUN_STOP_AT_FIRST_INSN
549 /* Implement the "run" command. Force a stop during program start if
550 requested by RUN_HOW. */
553 run_command_1 (const char *args
, int from_tty
, enum run_how run_how
)
555 const char *exec_file
;
556 struct ui_out
*uiout
= current_uiout
;
557 struct target_ops
*run_target
;
562 kill_if_already_running (from_tty
);
564 init_wait_for_inferior ();
565 clear_breakpoint_hit_counts ();
567 /* Clean up any leftovers from other runs. Some other things from
568 this function should probably be moved into target_pre_inferior. */
569 target_pre_inferior (from_tty
);
571 /* The comment here used to read, "The exec file is re-read every
572 time we do a generic_mourn_inferior, so we just have to worry
573 about the symbol file." The `generic_mourn_inferior' function
574 gets called whenever the program exits. However, suppose the
575 program exits, and *then* the executable file changes? We need
576 to check again here. Since reopen_exec_file doesn't do anything
577 if the timestamp hasn't changed, I don't see the harm. */
581 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
582 args
= stripped
.get ();
584 /* Do validation and preparation before possibly changing anything
587 run_target
= find_run_target ();
589 prepare_execution_command (run_target
, async_exec
);
591 if (non_stop
&& !run_target
->supports_non_stop ())
592 error (_("The target does not support running in non-stop mode."));
594 /* Done. Can now set breakpoints, change inferior args, etc. */
596 /* Insert temporary breakpoint in main function if requested. */
597 if (run_how
== RUN_STOP_AT_MAIN
)
599 std::string arg
= string_printf ("-qualified %s", main_name ());
600 tbreak_command (arg
.c_str (), 0);
603 exec_file
= get_exec_file (0);
605 /* We keep symbols from add-symbol-file, on the grounds that the
606 user might want to add some symbols before running the program
607 (right?). But sometimes (dynamic loading where the user manually
608 introduces the new symbols with add-symbol-file), the code which
609 the symbols describe does not persist between runs. Currently
610 the user has to manually nuke all symbols between runs if they
611 want them to go away (PR 2207). This is probably reasonable. */
613 /* If there were other args, beside '&', process them. */
615 set_inferior_args (args
);
619 uiout
->field_string (NULL
, "Starting program");
622 uiout
->field_string ("execfile", exec_file
);
624 /* We call get_inferior_args() because we might need to compute
626 uiout
->field_string ("infargs", get_inferior_args ());
631 /* We call get_inferior_args() because we might need to compute
633 run_target
->create_inferior (exec_file
,
634 std::string (get_inferior_args ()),
635 current_inferior ()->environment
.envp (),
637 /* to_create_inferior should push the target, so after this point we
638 shouldn't refer to run_target again. */
641 /* We're starting off a new process. When we get out of here, in
642 non-stop mode, finish the state of all threads of that process,
643 but leave other threads alone, as they may be stopped in internal
644 events --- the frontend shouldn't see them as stopped. In
645 all-stop, always finish the state of all threads, as we may be
646 resuming more than just the new process. */
647 ptid_t finish_ptid
= (non_stop
648 ? ptid_t (current_inferior ()->pid
)
650 scoped_finish_thread_state
finish_state (finish_ptid
);
652 /* Pass zero for FROM_TTY, because at this point the "run" command
653 has done its thing; now we are setting up the running program. */
654 post_create_inferior (current_top_target (), 0);
656 /* Queue a pending event so that the program stops immediately. */
657 if (run_how
== RUN_STOP_AT_FIRST_INSN
)
659 thread_info
*thr
= inferior_thread ();
660 thr
->suspend
.waitstatus_pending_p
= 1;
661 thr
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_STOPPED
;
662 thr
->suspend
.waitstatus
.value
.sig
= GDB_SIGNAL_0
;
665 /* Start the target running. Do not use -1 continuation as it would skip
666 breakpoint right at the entry point. */
667 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
669 /* Since there was no error, there's no need to finish the thread
671 finish_state
.release ();
675 run_command (const char *args
, int from_tty
)
677 run_command_1 (args
, from_tty
, RUN_NORMAL
);
680 /* Start the execution of the program up until the beginning of the main
684 start_command (const char *args
, int from_tty
)
686 /* Some languages such as Ada need to search inside the program
687 minimal symbols for the location where to put the temporary
688 breakpoint before starting. */
689 if (!have_minimal_symbols ())
690 error (_("No symbol table loaded. Use the \"file\" command."));
692 /* Run the program until reaching the main procedure... */
693 run_command_1 (args
, from_tty
, RUN_STOP_AT_MAIN
);
696 /* Start the execution of the program stopping at the first
700 starti_command (const char *args
, int from_tty
)
702 run_command_1 (args
, from_tty
, RUN_STOP_AT_FIRST_INSN
);
706 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
708 /* We go through all threads individually instead of compressing
709 into a single target `resume_all' request, because some threads
710 may be stopped in internal breakpoints/events, or stopped waiting
711 for its turn in the displaced stepping queue (that is, they are
712 running && !executing). The target side has no idea about why
713 the thread is stopped, so a `resume_all' command would resume too
714 much. If/when GDB gains a way to tell the target `hold this
715 thread stopped until I say otherwise', then we can optimize
717 if (thread
->state
!= THREAD_STOPPED
)
720 switch_to_thread (thread
);
721 clear_proceed_status (0);
722 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
727 ensure_valid_thread (void)
729 if (inferior_ptid
== null_ptid
730 || inferior_thread ()->state
== THREAD_EXITED
)
731 error (_("Cannot execute this command without a live selected thread."));
734 /* If the user is looking at trace frames, any resumption of execution
735 is likely to mix up recorded and live target data. So simply
736 disallow those commands. */
739 ensure_not_tfind_mode (void)
741 if (get_traceframe_number () >= 0)
742 error (_("Cannot execute this command while looking at trace frames."));
745 /* Throw an error indicating the current thread is running. */
748 error_is_running (void)
750 error (_("Cannot execute this command while "
751 "the selected thread is running."));
754 /* Calls error_is_running if the current thread is running. */
757 ensure_not_running (void)
759 if (inferior_thread ()->state
== THREAD_RUNNING
)
764 continue_1 (int all_threads
)
767 ensure_not_tfind_mode ();
769 if (non_stop
&& all_threads
)
771 /* Don't error out if the current thread is running, because
772 there may be other stopped threads. */
774 /* Backup current thread and selected frame and restore on scope
776 scoped_restore_current_thread restore_thread
;
778 iterate_over_threads (proceed_thread_callback
, NULL
);
780 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
782 /* If all threads in the target were already running,
783 proceed_thread_callback ends up never calling proceed,
784 and so nothing calls this to put the inferior's terminal
785 settings in effect and remove stdin from the event loop,
786 which we must when running a foreground command. E.g.:
790 <all threads are running now>
793 <no thread was resumed, but the inferior now owns the terminal>
795 target_terminal::inferior ();
800 ensure_valid_thread ();
801 ensure_not_running ();
802 clear_proceed_status (0);
803 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
807 /* continue [-a] [proceed-count] [&] */
810 continue_command (const char *args
, int from_tty
)
817 /* Find out whether we must run in the background. */
818 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
819 args
= stripped
.get ();
823 if (startswith (args
, "-a"))
826 args
+= sizeof ("-a") - 1;
832 if (!non_stop
&& all_threads
)
833 error (_("`-a' is meaningless in all-stop mode."));
835 if (args
!= NULL
&& all_threads
)
836 error (_("Can't resume all threads and specify "
837 "proceed count simultaneously."));
839 /* If we have an argument left, set proceed count of breakpoint we
846 struct thread_info
*tp
;
849 tp
= inferior_thread ();
853 struct target_waitstatus ws
;
855 get_last_target_status (&last_ptid
, &ws
);
856 tp
= find_thread_ptid (last_ptid
);
859 bs
= tp
->control
.stop_bpstat
;
861 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
864 set_ignore_count (num
,
865 parse_and_eval_long (args
) - 1,
867 /* set_ignore_count prints a message ending with a period.
868 So print two spaces before "Continuing.". */
870 printf_filtered (" ");
874 if (!stopped
&& from_tty
)
877 ("Not stopped at any breakpoint; argument ignored.\n");
882 ensure_not_tfind_mode ();
884 if (!non_stop
|| !all_threads
)
886 ensure_valid_thread ();
887 ensure_not_running ();
890 prepare_execution_command (current_top_target (), async_exec
);
893 printf_filtered (_("Continuing.\n"));
895 continue_1 (all_threads
);
898 /* Record the starting point of a "step" or "next" command. */
901 set_step_frame (void)
903 frame_info
*frame
= get_current_frame ();
905 symtab_and_line sal
= find_frame_sal (frame
);
906 set_step_info (frame
, sal
);
908 CORE_ADDR pc
= get_frame_pc (frame
);
909 thread_info
*tp
= inferior_thread ();
910 tp
->control
.step_start_function
= find_pc_function (pc
);
913 /* Step until outside of current statement. */
916 step_command (const char *count_string
, int from_tty
)
918 step_1 (0, 0, count_string
);
921 /* Likewise, but skip over subroutine calls as if single instructions. */
924 next_command (const char *count_string
, int from_tty
)
926 step_1 (1, 0, count_string
);
929 /* Likewise, but step only one instruction. */
932 stepi_command (const char *count_string
, int from_tty
)
934 step_1 (0, 1, count_string
);
938 nexti_command (const char *count_string
, int from_tty
)
940 step_1 (1, 1, count_string
);
943 /* Data for the FSM that manages the step/next/stepi/nexti
946 struct step_command_fsm
: public thread_fsm
948 /* How many steps left in a "step N"-like command. */
951 /* If true, this is a next/nexti, otherwise a step/stepi. */
952 int skip_subroutines
;
954 /* If true, this is a stepi/nexti, otherwise a step/step. */
957 explicit step_command_fsm (struct interp
*cmd_interp
)
958 : thread_fsm (cmd_interp
)
962 void clean_up (struct thread_info
*thread
) override
;
963 bool should_stop (struct thread_info
*thread
) override
;
964 enum async_reply_reason
do_async_reply_reason () override
;
967 /* Prepare for a step/next/etc. command. Any target resource
968 allocated here is undone in the FSM's clean_up method. */
971 step_command_fsm_prepare (struct step_command_fsm
*sm
,
972 int skip_subroutines
, int single_inst
,
973 int count
, struct thread_info
*thread
)
975 sm
->skip_subroutines
= skip_subroutines
;
976 sm
->single_inst
= single_inst
;
979 /* Leave the si command alone. */
980 if (!sm
->single_inst
|| sm
->skip_subroutines
)
981 set_longjmp_breakpoint (thread
, get_frame_id (get_current_frame ()));
983 thread
->control
.stepping_command
= 1;
986 static int prepare_one_step (struct step_command_fsm
*sm
);
989 step_1 (int skip_subroutines
, int single_inst
, const char *count_string
)
993 struct thread_info
*thr
;
994 struct step_command_fsm
*step_sm
;
997 ensure_not_tfind_mode ();
998 ensure_valid_thread ();
999 ensure_not_running ();
1001 gdb::unique_xmalloc_ptr
<char> stripped
1002 = strip_bg_char (count_string
, &async_exec
);
1003 count_string
= stripped
.get ();
1005 prepare_execution_command (current_top_target (), async_exec
);
1007 count
= count_string
? parse_and_eval_long (count_string
) : 1;
1009 clear_proceed_status (1);
1011 /* Setup the execution command state machine to handle all the COUNT
1013 thr
= inferior_thread ();
1014 step_sm
= new step_command_fsm (command_interp ());
1015 thr
->thread_fsm
= step_sm
;
1017 step_command_fsm_prepare (step_sm
, skip_subroutines
,
1018 single_inst
, count
, thr
);
1020 /* Do only one step for now, before returning control to the event
1021 loop. Let the continuation figure out how many other steps we
1022 need to do, and handle them one at the time, through
1024 if (!prepare_one_step (step_sm
))
1025 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1030 /* Stepped into an inline frame. Pretend that we've
1032 thr
->thread_fsm
->clean_up (thr
);
1033 proceeded
= normal_stop ();
1035 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1036 all_uis_check_sync_execution_done ();
1040 /* Implementation of the 'should_stop' FSM method for stepping
1041 commands. Called after we are done with one step operation, to
1042 check whether we need to step again, before we print the prompt and
1043 return control to the user. If count is > 1, returns false, as we
1044 will need to keep going. */
1047 step_command_fsm::should_stop (struct thread_info
*tp
)
1049 if (tp
->control
.stop_step
)
1051 /* There are more steps to make, and we did stop due to
1052 ending a stepping range. Do another step. */
1054 return prepare_one_step (this);
1062 /* Implementation of the 'clean_up' FSM method for stepping commands. */
1065 step_command_fsm::clean_up (struct thread_info
*thread
)
1067 if (!single_inst
|| skip_subroutines
)
1068 delete_longjmp_breakpoint (thread
->global_num
);
1071 /* Implementation of the 'async_reply_reason' FSM method for stepping
1074 enum async_reply_reason
1075 step_command_fsm::do_async_reply_reason ()
1077 return EXEC_ASYNC_END_STEPPING_RANGE
;
1080 /* Prepare for one step in "step N". The actual target resumption is
1081 done by the caller. Return true if we're done and should thus
1082 report a stop to the user. Returns false if the target needs to be
1086 prepare_one_step (struct step_command_fsm
*sm
)
1090 struct frame_info
*frame
= get_current_frame ();
1092 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1093 the longjmp breakpoint was not required. Use the
1094 INFERIOR_PTID thread instead, which is the same thread when
1096 struct thread_info
*tp
= inferior_thread ();
1100 if (!sm
->single_inst
)
1104 /* Step at an inlined function behaves like "down". */
1105 if (!sm
->skip_subroutines
1106 && inline_skipped_frames (tp
))
1110 /* Pretend that we've ran. */
1111 resume_ptid
= user_visible_resume_ptid (1);
1112 set_running (resume_ptid
, 1);
1114 step_into_inline_frame (tp
);
1116 return prepare_one_step (sm
);
1119 pc
= get_frame_pc (frame
);
1120 find_pc_line_pc_range (pc
,
1121 &tp
->control
.step_range_start
,
1122 &tp
->control
.step_range_end
);
1124 tp
->control
.may_range_step
= 1;
1126 /* If we have no line info, switch to stepi mode. */
1127 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1129 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1130 tp
->control
.may_range_step
= 0;
1132 else if (tp
->control
.step_range_end
== 0)
1136 if (find_pc_partial_function (pc
, &name
,
1137 &tp
->control
.step_range_start
,
1138 &tp
->control
.step_range_end
) == 0)
1139 error (_("Cannot find bounds of current function"));
1141 target_terminal::ours_for_output ();
1142 printf_filtered (_("Single stepping until exit from function %s,"
1143 "\nwhich has no line number information.\n"),
1149 /* Say we are stepping, but stop after one insn whatever it does. */
1150 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1151 if (!sm
->skip_subroutines
)
1153 Don't step over function calls, not even to functions lacking
1155 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1158 if (sm
->skip_subroutines
)
1159 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1165 sm
->set_finished ();
1170 /* Continue program at specified address. */
1173 jump_command (const char *arg
, int from_tty
)
1175 struct gdbarch
*gdbarch
= get_current_arch ();
1182 ensure_not_tfind_mode ();
1183 ensure_valid_thread ();
1184 ensure_not_running ();
1186 /* Find out whether we must run in the background. */
1187 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1188 arg
= stripped
.get ();
1190 prepare_execution_command (current_top_target (), async_exec
);
1193 error_no_arg (_("starting address"));
1195 std::vector
<symtab_and_line
> sals
1196 = decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1197 if (sals
.size () != 1)
1198 error (_("Unreasonable jump request"));
1200 symtab_and_line
&sal
= sals
[0];
1202 if (sal
.symtab
== 0 && sal
.pc
== 0)
1203 error (_("No source file has been specified."));
1205 resolve_sal_pc (&sal
); /* May error out. */
1207 /* See if we are trying to jump to another function. */
1208 fn
= get_frame_function (get_current_frame ());
1209 sfn
= find_pc_function (sal
.pc
);
1210 if (fn
!= NULL
&& sfn
!= fn
)
1212 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1215 error (_("Not confirmed."));
1222 struct obj_section
*section
;
1224 fixup_symbol_section (sfn
, 0);
1225 section
= SYMBOL_OBJ_SECTION (symbol_objfile (sfn
), sfn
);
1226 if (section_is_overlay (section
)
1227 && !section_is_mapped (section
))
1229 if (!query (_("WARNING!!! Destination is in "
1230 "unmapped overlay! Jump anyway? ")))
1232 error (_("Not confirmed."));
1242 printf_filtered (_("Continuing at "));
1243 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1244 printf_filtered (".\n");
1247 clear_proceed_status (0);
1248 proceed (addr
, GDB_SIGNAL_0
);
1251 /* Continue program giving it specified signal. */
1254 signal_command (const char *signum_exp
, int from_tty
)
1256 enum gdb_signal oursig
;
1259 dont_repeat (); /* Too dangerous. */
1261 ensure_not_tfind_mode ();
1262 ensure_valid_thread ();
1263 ensure_not_running ();
1265 /* Find out whether we must run in the background. */
1266 gdb::unique_xmalloc_ptr
<char> stripped
1267 = strip_bg_char (signum_exp
, &async_exec
);
1268 signum_exp
= stripped
.get ();
1270 prepare_execution_command (current_top_target (), async_exec
);
1273 error_no_arg (_("signal number"));
1275 /* It would be even slicker to make signal names be valid expressions,
1276 (the type could be "enum $signal" or some such), then the user could
1277 assign them to convenience variables. */
1278 oursig
= gdb_signal_from_name (signum_exp
);
1280 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1282 /* No, try numeric. */
1283 int num
= parse_and_eval_long (signum_exp
);
1286 oursig
= GDB_SIGNAL_0
;
1288 oursig
= gdb_signal_from_command (num
);
1291 /* Look for threads other than the current that this command ends up
1292 resuming too (due to schedlock off), and warn if they'll get a
1293 signal delivered. "signal 0" is used to suppress a previous
1294 signal, but if the current thread is no longer the one that got
1295 the signal, then the user is potentially suppressing the signal
1296 of the wrong thread. */
1299 int must_confirm
= 0;
1301 /* This indicates what will be resumed. Either a single thread,
1302 a whole process, or all threads of all processes. */
1303 ptid_t resume_ptid
= user_visible_resume_ptid (0);
1305 for (thread_info
*tp
: all_non_exited_threads (resume_ptid
))
1307 if (tp
->ptid
== inferior_ptid
)
1310 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1311 && signal_pass_state (tp
->suspend
.stop_signal
))
1314 printf_unfiltered (_("Note:\n"));
1315 printf_unfiltered (_(" Thread %s previously stopped with signal %s, %s.\n"),
1316 print_thread_id (tp
),
1317 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1318 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1324 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1325 "still deliver the signals noted above to their respective threads.\n"
1326 "Continue anyway? "),
1327 print_thread_id (inferior_thread ())))
1328 error (_("Not confirmed."));
1333 if (oursig
== GDB_SIGNAL_0
)
1334 printf_filtered (_("Continuing with no signal.\n"));
1336 printf_filtered (_("Continuing with signal %s.\n"),
1337 gdb_signal_to_name (oursig
));
1340 clear_proceed_status (0);
1341 proceed ((CORE_ADDR
) -1, oursig
);
1344 /* Queue a signal to be delivered to the current thread. */
1347 queue_signal_command (const char *signum_exp
, int from_tty
)
1349 enum gdb_signal oursig
;
1350 struct thread_info
*tp
;
1353 ensure_not_tfind_mode ();
1354 ensure_valid_thread ();
1355 ensure_not_running ();
1357 if (signum_exp
== NULL
)
1358 error_no_arg (_("signal number"));
1360 /* It would be even slicker to make signal names be valid expressions,
1361 (the type could be "enum $signal" or some such), then the user could
1362 assign them to convenience variables. */
1363 oursig
= gdb_signal_from_name (signum_exp
);
1365 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1367 /* No, try numeric. */
1368 int num
= parse_and_eval_long (signum_exp
);
1371 oursig
= GDB_SIGNAL_0
;
1373 oursig
= gdb_signal_from_command (num
);
1376 if (oursig
!= GDB_SIGNAL_0
1377 && !signal_pass_state (oursig
))
1378 error (_("Signal handling set to not pass this signal to the program."));
1380 tp
= inferior_thread ();
1381 tp
->suspend
.stop_signal
= oursig
;
1384 /* Data for the FSM that manages the until (with no argument)
1387 struct until_next_fsm
: public thread_fsm
1389 /* The thread that as current when the command was executed. */
1392 until_next_fsm (struct interp
*cmd_interp
, int thread
)
1393 : thread_fsm (cmd_interp
),
1398 bool should_stop (struct thread_info
*thread
) override
;
1399 void clean_up (struct thread_info
*thread
) override
;
1400 enum async_reply_reason
do_async_reply_reason () override
;
1403 /* Implementation of the 'should_stop' FSM method for the until (with
1407 until_next_fsm::should_stop (struct thread_info
*tp
)
1409 if (tp
->control
.stop_step
)
1415 /* Implementation of the 'clean_up' FSM method for the until (with no
1419 until_next_fsm::clean_up (struct thread_info
*thread
)
1421 delete_longjmp_breakpoint (thread
->global_num
);
1424 /* Implementation of the 'async_reply_reason' FSM method for the until
1425 (with no arg) command. */
1427 enum async_reply_reason
1428 until_next_fsm::do_async_reply_reason ()
1430 return EXEC_ASYNC_END_STEPPING_RANGE
;
1433 /* Proceed until we reach a different source line with pc greater than
1434 our current one or exit the function. We skip calls in both cases.
1436 Note that eventually this command should probably be changed so
1437 that only source lines are printed out when we hit the breakpoint
1438 we set. This may involve changes to wait_for_inferior and the
1439 proceed status code. */
1442 until_next_command (int from_tty
)
1444 struct frame_info
*frame
;
1446 struct symbol
*func
;
1447 struct symtab_and_line sal
;
1448 struct thread_info
*tp
= inferior_thread ();
1449 int thread
= tp
->global_num
;
1450 struct until_next_fsm
*sm
;
1452 clear_proceed_status (0);
1455 frame
= get_current_frame ();
1457 /* Step until either exited from this function or greater
1458 than the current line (if in symbolic section) or pc (if
1461 pc
= get_frame_pc (frame
);
1462 func
= find_pc_function (pc
);
1466 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1468 if (msymbol
.minsym
== NULL
)
1469 error (_("Execution is not within a known function."));
1471 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1472 /* The upper-bound of step_range is exclusive. In order to make PC
1473 within the range, set the step_range_end with PC + 1. */
1474 tp
->control
.step_range_end
= pc
+ 1;
1478 sal
= find_pc_line (pc
, 0);
1480 tp
->control
.step_range_start
= BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func
));
1481 tp
->control
.step_range_end
= sal
.end
;
1483 tp
->control
.may_range_step
= 1;
1485 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1487 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1488 delete_longjmp_breakpoint_cleanup
lj_deleter (thread
);
1490 sm
= new until_next_fsm (command_interp (), tp
->global_num
);
1491 tp
->thread_fsm
= sm
;
1492 lj_deleter
.release ();
1494 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1498 until_command (const char *arg
, int from_tty
)
1503 ensure_not_tfind_mode ();
1504 ensure_valid_thread ();
1505 ensure_not_running ();
1507 /* Find out whether we must run in the background. */
1508 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1509 arg
= stripped
.get ();
1511 prepare_execution_command (current_top_target (), async_exec
);
1514 until_break_command (arg
, from_tty
, 0);
1516 until_next_command (from_tty
);
1520 advance_command (const char *arg
, int from_tty
)
1525 ensure_not_tfind_mode ();
1526 ensure_valid_thread ();
1527 ensure_not_running ();
1530 error_no_arg (_("a location"));
1532 /* Find out whether we must run in the background. */
1533 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1534 arg
= stripped
.get ();
1536 prepare_execution_command (current_top_target (), async_exec
);
1538 until_break_command (arg
, from_tty
, 1);
1541 /* Return the value of the result of a function at the end of a 'finish'
1542 command/BP. DTOR_DATA (if not NULL) can represent inferior registers
1543 right after an inferior call has finished. */
1546 get_return_value (struct value
*function
, struct type
*value_type
)
1548 regcache
*stop_regs
= get_current_regcache ();
1549 struct gdbarch
*gdbarch
= stop_regs
->arch ();
1550 struct value
*value
;
1552 value_type
= check_typedef (value_type
);
1553 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1555 /* FIXME: 2003-09-27: When returning from a nested inferior function
1556 call, it's possible (with no help from the architecture vector)
1557 to locate and return/print a "struct return" value. This is just
1558 a more complicated case of what is already being done in the
1559 inferior function call code. In fact, when inferior function
1560 calls are made async, this will likely be made the norm. */
1562 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1565 case RETURN_VALUE_REGISTER_CONVENTION
:
1566 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1567 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1568 value
= allocate_value (value_type
);
1569 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1570 value_contents_raw (value
), NULL
);
1572 case RETURN_VALUE_STRUCT_CONVENTION
:
1576 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1582 /* The captured function return value/type and its position in the
1585 struct return_value_info
1587 /* The captured return value. May be NULL if we weren't able to
1588 retrieve it. See get_return_value. */
1589 struct value
*value
;
1591 /* The return type. In some cases, we'll not be able extract the
1592 return value, but we always know the type. */
1595 /* If we captured a value, this is the value history index. */
1596 int value_history_index
;
1599 /* Helper for print_return_value. */
1602 print_return_value_1 (struct ui_out
*uiout
, struct return_value_info
*rv
)
1604 if (rv
->value
!= NULL
)
1606 struct value_print_options opts
;
1609 uiout
->text ("Value returned is ");
1610 uiout
->field_fmt ("gdb-result-var", "$%d",
1611 rv
->value_history_index
);
1612 uiout
->text (" = ");
1613 get_user_print_options (&opts
);
1615 if (opts
.finish_print
)
1618 value_print (rv
->value
, &stb
, &opts
);
1619 uiout
->field_stream ("return-value", stb
);
1622 uiout
->field_string ("return-value", _("<not displayed>"),
1623 metadata_style
.style ());
1628 std::string type_name
= type_to_string (rv
->type
);
1629 uiout
->text ("Value returned has type: ");
1630 uiout
->field_string ("return-type", type_name
.c_str ());
1632 uiout
->text (" Cannot determine contents\n");
1636 /* Print the result of a function at the end of a 'finish' command.
1637 RV points at an object representing the captured return value/type
1638 and its position in the value history. */
1641 print_return_value (struct ui_out
*uiout
, struct return_value_info
*rv
)
1643 if (rv
->type
== NULL
1644 || TYPE_CODE (check_typedef (rv
->type
)) == TYPE_CODE_VOID
)
1649 /* print_return_value_1 can throw an exception in some
1650 circumstances. We need to catch this so that we still
1651 delete the breakpoint. */
1652 print_return_value_1 (uiout
, rv
);
1654 catch (const gdb_exception
&ex
)
1656 exception_print (gdb_stdout
, ex
);
1660 /* Data for the FSM that manages the finish command. */
1662 struct finish_command_fsm
: public thread_fsm
1664 /* The momentary breakpoint set at the function's return address in
1666 breakpoint_up breakpoint
;
1668 /* The function that we're stepping out of. */
1669 struct symbol
*function
= nullptr;
1671 /* If the FSM finishes successfully, this stores the function's
1673 struct return_value_info return_value_info
{};
1675 explicit finish_command_fsm (struct interp
*cmd_interp
)
1676 : thread_fsm (cmd_interp
)
1680 bool should_stop (struct thread_info
*thread
) override
;
1681 void clean_up (struct thread_info
*thread
) override
;
1682 struct return_value_info
*return_value () override
;
1683 enum async_reply_reason
do_async_reply_reason () override
;
1686 /* Implementation of the 'should_stop' FSM method for the finish
1687 commands. Detects whether the thread stepped out of the function
1688 successfully, and if so, captures the function's return value and
1689 marks the FSM finished. */
1692 finish_command_fsm::should_stop (struct thread_info
*tp
)
1694 struct return_value_info
*rv
= &return_value_info
;
1696 if (function
!= NULL
1697 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
1698 breakpoint
.get ()) != NULL
)
1703 rv
->type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (function
));
1704 if (rv
->type
== NULL
)
1705 internal_error (__FILE__
, __LINE__
,
1706 _("finish_command: function has no target type"));
1708 if (TYPE_CODE (check_typedef (rv
->type
)) != TYPE_CODE_VOID
)
1712 func
= read_var_value (function
, NULL
, get_current_frame ());
1713 rv
->value
= get_return_value (func
, rv
->type
);
1714 if (rv
->value
!= NULL
)
1715 rv
->value_history_index
= record_latest_value (rv
->value
);
1718 else if (tp
->control
.stop_step
)
1720 /* Finishing from an inline frame, or reverse finishing. In
1721 either case, there's no way to retrieve the return value. */
1728 /* Implementation of the 'clean_up' FSM method for the finish
1732 finish_command_fsm::clean_up (struct thread_info
*thread
)
1734 breakpoint
.reset ();
1735 delete_longjmp_breakpoint (thread
->global_num
);
1738 /* Implementation of the 'return_value' FSM method for the finish
1741 struct return_value_info
*
1742 finish_command_fsm::return_value ()
1744 return &return_value_info
;
1747 /* Implementation of the 'async_reply_reason' FSM method for the
1750 enum async_reply_reason
1751 finish_command_fsm::do_async_reply_reason ()
1753 if (execution_direction
== EXEC_REVERSE
)
1754 return EXEC_ASYNC_END_STEPPING_RANGE
;
1756 return EXEC_ASYNC_FUNCTION_FINISHED
;
1759 /* finish_backward -- helper function for finish_command. */
1762 finish_backward (struct finish_command_fsm
*sm
)
1764 struct symtab_and_line sal
;
1765 struct thread_info
*tp
= inferior_thread ();
1767 CORE_ADDR func_addr
;
1769 pc
= get_frame_pc (get_current_frame ());
1771 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1772 error (_("Cannot find bounds of current function"));
1774 sal
= find_pc_line (func_addr
, 0);
1776 tp
->control
.proceed_to_finish
= 1;
1777 /* Special case: if we're sitting at the function entry point,
1778 then all we need to do is take a reverse singlestep. We
1779 don't need to set a breakpoint, and indeed it would do us
1782 Note that this can only happen at frame #0, since there's
1783 no way that a function up the stack can have a return address
1784 that's equal to its entry point. */
1788 struct frame_info
*frame
= get_selected_frame (NULL
);
1789 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1791 /* Set a step-resume at the function's entry point. Once that's
1792 hit, we'll do one more step backwards. */
1793 symtab_and_line sr_sal
;
1795 sr_sal
.pspace
= get_frame_program_space (frame
);
1796 insert_step_resume_breakpoint_at_sal (gdbarch
,
1797 sr_sal
, null_frame_id
);
1799 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1803 /* We're almost there -- we just need to back up by one more
1805 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1806 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1810 /* finish_forward -- helper function for finish_command. FRAME is the
1811 frame that called the function we're about to step out of. */
1814 finish_forward (struct finish_command_fsm
*sm
, struct frame_info
*frame
)
1816 struct frame_id frame_id
= get_frame_id (frame
);
1817 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1818 struct symtab_and_line sal
;
1819 struct thread_info
*tp
= inferior_thread ();
1821 sal
= find_pc_line (get_frame_pc (frame
), 0);
1822 sal
.pc
= get_frame_pc (frame
);
1824 sm
->breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1825 get_stack_frame_id (frame
),
1828 /* set_momentary_breakpoint invalidates FRAME. */
1831 set_longjmp_breakpoint (tp
, frame_id
);
1833 /* We want to print return value, please... */
1834 tp
->control
.proceed_to_finish
= 1;
1836 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1839 /* Skip frames for "finish". */
1841 static struct frame_info
*
1842 skip_finish_frames (struct frame_info
*frame
)
1844 struct frame_info
*start
;
1850 frame
= skip_tailcall_frames (frame
);
1854 frame
= skip_unwritable_frames (frame
);
1858 while (start
!= frame
);
1863 /* "finish": Set a temporary breakpoint at the place the selected
1864 frame will return to, then continue. */
1867 finish_command (const char *arg
, int from_tty
)
1869 struct frame_info
*frame
;
1871 struct finish_command_fsm
*sm
;
1872 struct thread_info
*tp
;
1875 ensure_not_tfind_mode ();
1876 ensure_valid_thread ();
1877 ensure_not_running ();
1879 /* Find out whether we must run in the background. */
1880 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (arg
, &async_exec
);
1881 arg
= stripped
.get ();
1883 prepare_execution_command (current_top_target (), async_exec
);
1886 error (_("The \"finish\" command does not take any arguments."));
1888 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1890 error (_("\"finish\" not meaningful in the outermost frame."));
1892 clear_proceed_status (0);
1894 tp
= inferior_thread ();
1896 sm
= new finish_command_fsm (command_interp ());
1898 tp
->thread_fsm
= sm
;
1900 /* Finishing from an inline frame is completely different. We don't
1901 try to show the "return value" - no way to locate it. */
1902 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1905 /* Claim we are stepping in the calling frame. An empty step
1906 range means that we will stop once we aren't in a function
1907 called by that frame. We don't use the magic "1" value for
1908 step_range_end, because then infrun will think this is nexti,
1909 and not step over the rest of this inlined function call. */
1910 set_step_info (frame
, {});
1911 tp
->control
.step_range_start
= get_frame_pc (frame
);
1912 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1913 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1915 /* Print info on the selected frame, including level number but not
1919 printf_filtered (_("Run till exit from "));
1920 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1923 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1927 /* Find the function we will return from. */
1929 sm
->function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1931 /* Print info on the selected frame, including level number but not
1935 if (execution_direction
== EXEC_REVERSE
)
1936 printf_filtered (_("Run back to call of "));
1939 if (sm
->function
!= NULL
&& TYPE_NO_RETURN (sm
->function
->type
)
1940 && !query (_("warning: Function %s does not return normally.\n"
1941 "Try to finish anyway? "),
1942 sm
->function
->print_name ()))
1943 error (_("Not confirmed."));
1944 printf_filtered (_("Run till exit from "));
1947 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1950 if (execution_direction
== EXEC_REVERSE
)
1951 finish_backward (sm
);
1954 frame
= skip_finish_frames (frame
);
1957 error (_("Cannot find the caller frame."));
1959 finish_forward (sm
, frame
);
1965 info_program_command (const char *args
, int from_tty
)
1971 if (!target_has_execution
)
1973 printf_filtered (_("The program being debugged is not being run.\n"));
1978 ptid
= inferior_ptid
;
1981 struct target_waitstatus ws
;
1983 get_last_target_status (&ptid
, &ws
);
1986 if (ptid
== null_ptid
|| ptid
== minus_one_ptid
)
1987 error (_("No selected thread."));
1989 thread_info
*tp
= find_thread_ptid (ptid
);
1991 if (tp
->state
== THREAD_EXITED
)
1992 error (_("Invalid selected thread."));
1993 else if (tp
->state
== THREAD_RUNNING
)
1994 error (_("Selected thread is running."));
1996 bs
= tp
->control
.stop_bpstat
;
1997 stat
= bpstat_num (&bs
, &num
);
1999 target_files_info ();
2000 printf_filtered (_("Program stopped at %s.\n"),
2001 paddress (target_gdbarch (), tp
->suspend
.stop_pc
));
2002 if (tp
->control
.stop_step
)
2003 printf_filtered (_("It stopped after being stepped.\n"));
2006 /* There may be several breakpoints in the same place, so this
2007 isn't as strange as it seems. */
2012 printf_filtered (_("It stopped at a breakpoint "
2013 "that has since been deleted.\n"));
2016 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
2017 stat
= bpstat_num (&bs
, &num
);
2020 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
2022 printf_filtered (_("It stopped with signal %s, %s.\n"),
2023 gdb_signal_to_name (tp
->suspend
.stop_signal
),
2024 gdb_signal_to_string (tp
->suspend
.stop_signal
));
2029 printf_filtered (_("Type \"info stack\" or \"info "
2030 "registers\" for more information.\n"));
2035 environment_info (const char *var
, int from_tty
)
2039 const char *val
= current_inferior ()->environment
.get (var
);
2043 puts_filtered (var
);
2044 puts_filtered (" = ");
2045 puts_filtered (val
);
2046 puts_filtered ("\n");
2050 puts_filtered ("Environment variable \"");
2051 puts_filtered (var
);
2052 puts_filtered ("\" not defined.\n");
2057 char **envp
= current_inferior ()->environment
.envp ();
2059 for (int idx
= 0; envp
[idx
] != NULL
; ++idx
)
2061 puts_filtered (envp
[idx
]);
2062 puts_filtered ("\n");
2068 set_environment_command (const char *arg
, int from_tty
)
2070 const char *p
, *val
;
2074 error_no_arg (_("environment variable and value"));
2076 /* Find separation between variable name and value. */
2077 p
= (char *) strchr (arg
, '=');
2078 val
= (char *) strchr (arg
, ' ');
2080 if (p
!= 0 && val
!= 0)
2082 /* We have both a space and an equals. If the space is before the
2083 equals, walk forward over the spaces til we see a nonspace
2084 (possibly the equals). */
2089 /* Now if the = is after the char following the spaces,
2090 take the char following the spaces. */
2094 else if (val
!= 0 && p
== 0)
2098 error_no_arg (_("environment variable to set"));
2100 if (p
== 0 || p
[1] == 0)
2104 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2108 /* Not setting variable value to null. */
2110 while (*val
== ' ' || *val
== '\t')
2114 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2117 std::string
var (arg
, p
- arg
);
2120 printf_filtered (_("Setting environment variable "
2121 "\"%s\" to null value.\n"),
2123 current_inferior ()->environment
.set (var
.c_str (), "");
2126 current_inferior ()->environment
.set (var
.c_str (), val
);
2130 unset_environment_command (const char *var
, int from_tty
)
2134 /* If there is no argument, delete all environment variables.
2135 Ask for confirmation if reading from the terminal. */
2136 if (!from_tty
|| query (_("Delete all environment variables? ")))
2137 current_inferior ()->environment
.clear ();
2140 current_inferior ()->environment
.unset (var
);
2143 /* Handle the execution path (PATH variable). */
2145 static const char path_var_name
[] = "PATH";
2148 path_info (const char *args
, int from_tty
)
2150 puts_filtered ("Executable and object file path: ");
2151 puts_filtered (current_inferior ()->environment
.get (path_var_name
));
2152 puts_filtered ("\n");
2155 /* Add zero or more directories to the front of the execution path. */
2158 path_command (const char *dirname
, int from_tty
)
2164 env
= current_inferior ()->environment
.get (path_var_name
);
2165 /* Can be null if path is not set. */
2168 exec_path
= xstrdup (env
);
2169 mod_path (dirname
, &exec_path
);
2170 current_inferior ()->environment
.set (path_var_name
, exec_path
);
2173 path_info (NULL
, from_tty
);
2178 pad_to_column (string_file
&stream
, int col
)
2180 /* At least one space must be printed to separate columns. */
2182 const int size
= stream
.size ();
2184 stream
.puts (n_spaces (col
- size
));
2187 /* Print out the register NAME with value VAL, to FILE, in the default
2191 default_print_one_register_info (struct ui_file
*file
,
2195 struct type
*regtype
= value_type (val
);
2196 int print_raw_format
;
2197 string_file format_stream
;
2200 value_column_1
= 15,
2201 /* Give enough room for "0x", 16 hex digits and two spaces in
2202 preceding column. */
2203 value_column_2
= value_column_1
+ 2 + 16 + 2,
2206 format_stream
.puts (name
);
2207 pad_to_column (format_stream
, value_column_1
);
2209 print_raw_format
= (value_entirely_available (val
)
2210 && !value_optimized_out (val
));
2212 /* If virtual format is floating, print it that way, and in raw
2214 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
2215 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2217 struct value_print_options opts
;
2218 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2219 enum bfd_endian byte_order
= type_byte_order (regtype
);
2221 get_user_print_options (&opts
);
2225 value_embedded_offset (val
), 0,
2226 &format_stream
, 0, val
, &opts
, current_language
);
2228 if (print_raw_format
)
2230 pad_to_column (format_stream
, value_column_2
);
2231 format_stream
.puts ("(raw ");
2232 print_hex_chars (&format_stream
, valaddr
, TYPE_LENGTH (regtype
),
2234 format_stream
.putc (')');
2239 struct value_print_options opts
;
2241 /* Print the register in hex. */
2242 get_formatted_print_options (&opts
, 'x');
2245 value_embedded_offset (val
), 0,
2246 &format_stream
, 0, val
, &opts
, current_language
);
2247 /* If not a vector register, print it also according to its
2249 if (print_raw_format
&& TYPE_VECTOR (regtype
) == 0)
2251 pad_to_column (format_stream
, value_column_2
);
2252 get_user_print_options (&opts
);
2255 value_embedded_offset (val
), 0,
2256 &format_stream
, 0, val
, &opts
, current_language
);
2260 fputs_filtered (format_stream
.c_str (), file
);
2261 fprintf_filtered (file
, "\n");
2264 /* Print out the machine register regnum. If regnum is -1, print all
2265 registers (print_all == 1) or all non-float and non-vector
2266 registers (print_all == 0).
2268 For most machines, having all_registers_info() print the
2269 register(s) one per line is good enough. If a different format is
2270 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2271 regs), or there is an existing convention for showing all the
2272 registers, define the architecture method PRINT_REGISTERS_INFO to
2273 provide that format. */
2276 default_print_registers_info (struct gdbarch
*gdbarch
,
2277 struct ui_file
*file
,
2278 struct frame_info
*frame
,
2279 int regnum
, int print_all
)
2282 const int numregs
= gdbarch_num_cooked_regs (gdbarch
);
2284 for (i
= 0; i
< numregs
; i
++)
2286 /* Decide between printing all regs, non-float / vector regs, or
2292 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2297 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2307 /* If the register name is empty, it is undefined for this
2308 processor, so don't display anything. */
2309 if (gdbarch_register_name (gdbarch
, i
) == NULL
2310 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2313 default_print_one_register_info (file
,
2314 gdbarch_register_name (gdbarch
, i
),
2315 value_of_register (i
, frame
));
2320 registers_info (const char *addr_exp
, int fpregs
)
2322 struct frame_info
*frame
;
2323 struct gdbarch
*gdbarch
;
2325 if (!target_has_registers
)
2326 error (_("The program has no registers now."));
2327 frame
= get_selected_frame (NULL
);
2328 gdbarch
= get_frame_arch (frame
);
2332 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2337 while (*addr_exp
!= '\0')
2342 /* Skip leading white space. */
2343 addr_exp
= skip_spaces (addr_exp
);
2345 /* Discard any leading ``$''. Check that there is something
2346 resembling a register following it. */
2347 if (addr_exp
[0] == '$')
2349 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2350 error (_("Missing register name"));
2352 /* Find the start/end of this register name/num/group. */
2354 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2358 /* Figure out what we've found and display it. */
2360 /* A register name? */
2362 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2366 /* User registers lie completely outside of the range of
2367 normal registers. Catch them early so that the target
2369 if (regnum
>= gdbarch_num_cooked_regs (gdbarch
))
2371 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2372 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2375 /* Print in the same fashion
2376 gdbarch_print_registers_info's default
2377 implementation prints. */
2378 default_print_one_register_info (gdb_stdout
,
2383 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2384 frame
, regnum
, fpregs
);
2389 /* A register group? */
2391 struct reggroup
*group
;
2393 for (group
= reggroup_next (gdbarch
, NULL
);
2395 group
= reggroup_next (gdbarch
, group
))
2397 /* Don't bother with a length check. Should the user
2398 enter a short register group name, go with the first
2399 group that matches. */
2400 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2408 regnum
< gdbarch_num_cooked_regs (gdbarch
);
2411 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2412 gdbarch_print_registers_info (gdbarch
,
2420 /* Nothing matched. */
2421 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2426 info_all_registers_command (const char *addr_exp
, int from_tty
)
2428 registers_info (addr_exp
, 1);
2432 info_registers_command (const char *addr_exp
, int from_tty
)
2434 registers_info (addr_exp
, 0);
2438 print_vector_info (struct ui_file
*file
,
2439 struct frame_info
*frame
, const char *args
)
2441 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2443 if (gdbarch_print_vector_info_p (gdbarch
))
2444 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2448 int printed_something
= 0;
2450 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2452 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2454 printed_something
= 1;
2455 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2458 if (!printed_something
)
2459 fprintf_filtered (file
, "No vector information\n");
2464 info_vector_command (const char *args
, int from_tty
)
2466 if (!target_has_registers
)
2467 error (_("The program has no registers now."));
2469 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2472 /* Kill the inferior process. Make us have no inferior. */
2475 kill_command (const char *arg
, int from_tty
)
2477 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2478 It should be a distinct flag that indicates that a target is active, cuz
2479 some targets don't have processes! */
2481 if (inferior_ptid
== null_ptid
)
2482 error (_("The program is not being run."));
2483 if (!query (_("Kill the program being debugged? ")))
2484 error (_("Not confirmed."));
2486 int pid
= current_inferior ()->pid
;
2487 /* Save the pid as a string before killing the inferior, since that
2488 may unpush the current target, and we need the string after. */
2489 std::string pid_str
= target_pid_to_str (ptid_t (pid
));
2490 int infnum
= current_inferior ()->num
;
2494 if (print_inferior_events
)
2495 printf_unfiltered (_("[Inferior %d (%s) killed]\n"),
2496 infnum
, pid_str
.c_str ());
2498 /* If we still have other inferiors to debug, then don't mess with
2499 with their threads. */
2500 if (!have_inferiors ())
2502 init_thread_list (); /* Destroy thread info. */
2504 /* Killing off the inferior can leave us with a core file. If
2505 so, print the state we are left in. */
2506 if (target_has_stack
)
2508 printf_filtered (_("In %s,\n"), target_longname
);
2509 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2512 bfd_cache_close_all ();
2515 /* Used in `attach&' command. Proceed threads of inferior INF iff
2516 they stopped due to debugger request, and when they did, they
2517 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2518 have been explicitly been told to stop. */
2521 proceed_after_attach (inferior
*inf
)
2523 /* Don't error out if the current thread is running, because
2524 there may be other stopped threads. */
2526 /* Backup current thread and selected frame. */
2527 scoped_restore_current_thread restore_thread
;
2529 for (thread_info
*thread
: inf
->non_exited_threads ())
2530 if (!thread
->executing
2531 && !thread
->stop_requested
2532 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2534 switch_to_thread (thread
);
2535 clear_proceed_status (0);
2536 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2540 /* See inferior.h. */
2543 setup_inferior (int from_tty
)
2545 struct inferior
*inferior
;
2547 inferior
= current_inferior ();
2548 inferior
->needs_setup
= 0;
2550 /* If no exec file is yet known, try to determine it from the
2552 if (get_exec_file (0) == NULL
)
2553 exec_file_locate_attach (inferior_ptid
.pid (), 1, from_tty
);
2556 reopen_exec_file ();
2560 /* Take any necessary post-attaching actions for this platform. */
2561 target_post_attach (inferior_ptid
.pid ());
2563 post_create_inferior (current_top_target (), from_tty
);
2566 /* What to do after the first program stops after attaching. */
2567 enum attach_post_wait_mode
2569 /* Do nothing. Leaves threads as they are. */
2570 ATTACH_POST_WAIT_NOTHING
,
2572 /* Re-resume threads that are marked running. */
2573 ATTACH_POST_WAIT_RESUME
,
2575 /* Stop all threads. */
2576 ATTACH_POST_WAIT_STOP
,
2579 /* Called after we've attached to a process and we've seen it stop for
2580 the first time. If ASYNC_EXEC is true, re-resume threads that
2581 should be running. Else if ATTACH, */
2584 attach_post_wait (const char *args
, int from_tty
, enum attach_post_wait_mode mode
)
2586 struct inferior
*inferior
;
2588 inferior
= current_inferior ();
2589 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2591 if (inferior
->needs_setup
)
2592 setup_inferior (from_tty
);
2594 if (mode
== ATTACH_POST_WAIT_RESUME
)
2596 /* The user requested an `attach&', so be sure to leave threads
2597 that didn't get a signal running. */
2599 /* Immediatelly resume all suspended threads of this inferior,
2600 and this inferior only. This should have no effect on
2601 already running threads. If a thread has been stopped with a
2602 signal, leave it be. */
2604 proceed_after_attach (inferior
);
2607 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2609 clear_proceed_status (0);
2610 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2614 else if (mode
== ATTACH_POST_WAIT_STOP
)
2616 /* The user requested a plain `attach', so be sure to leave
2617 the inferior stopped. */
2619 /* At least the current thread is already stopped. */
2621 /* In all-stop, by definition, all threads have to be already
2622 stopped at this point. In non-stop, however, although the
2623 selected thread is stopped, others may still be executing.
2624 Be sure to explicitly stop all threads of the process. This
2625 should have no effect on already stopped threads. */
2627 target_stop (ptid_t (inferior
->pid
));
2628 else if (target_is_non_stop_p ())
2630 struct thread_info
*lowest
= inferior_thread ();
2632 stop_all_threads ();
2634 /* It's not defined which thread will report the attach
2635 stop. For consistency, always select the thread with
2636 lowest GDB number, which should be the main thread, if it
2638 for (thread_info
*thread
: current_inferior ()->non_exited_threads ())
2639 if (thread
->inf
->num
< lowest
->inf
->num
2640 || thread
->per_inf_num
< lowest
->per_inf_num
)
2643 switch_to_thread (lowest
);
2646 /* Tell the user/frontend where we're stopped. */
2648 if (deprecated_attach_hook
)
2649 deprecated_attach_hook ();
2653 struct attach_command_continuation_args
2657 enum attach_post_wait_mode mode
;
2661 attach_command_continuation (void *args
, int err
)
2663 struct attach_command_continuation_args
*a
2664 = (struct attach_command_continuation_args
*) args
;
2669 attach_post_wait (a
->args
, a
->from_tty
, a
->mode
);
2673 attach_command_continuation_free_args (void *args
)
2675 struct attach_command_continuation_args
*a
2676 = (struct attach_command_continuation_args
*) args
;
2682 /* "attach" command entry point. Takes a program started up outside
2683 of gdb and ``attaches'' to it. This stops it cold in its tracks
2684 and allows us to start debugging it. */
2687 attach_command (const char *args
, int from_tty
)
2690 struct target_ops
*attach_target
;
2691 struct inferior
*inferior
= current_inferior ();
2692 enum attach_post_wait_mode mode
;
2694 dont_repeat (); /* Not for the faint of heart */
2696 if (gdbarch_has_global_solist (target_gdbarch ()))
2697 /* Don't complain if all processes share the same symbol
2700 else if (target_has_execution
)
2702 if (query (_("A program is being debugged already. Kill it? ")))
2705 error (_("Not killed."));
2708 /* Clean up any leftovers from other runs. Some other things from
2709 this function should probably be moved into target_pre_inferior. */
2710 target_pre_inferior (from_tty
);
2712 gdb::unique_xmalloc_ptr
<char> stripped
= strip_bg_char (args
, &async_exec
);
2713 args
= stripped
.get ();
2715 attach_target
= find_attach_target ();
2717 prepare_execution_command (attach_target
, async_exec
);
2719 if (non_stop
&& !attach_target
->supports_non_stop ())
2720 error (_("Cannot attach to this target in non-stop mode"));
2722 attach_target
->attach (args
, from_tty
);
2723 /* to_attach should push the target, so after this point we
2724 shouldn't refer to attach_target again. */
2725 attach_target
= NULL
;
2727 /* Set up the "saved terminal modes" of the inferior
2728 based on what modes we are starting it with. */
2729 target_terminal::init ();
2731 /* Install inferior's terminal modes. This may look like a no-op,
2732 as we've just saved them above, however, this does more than
2733 restore terminal settings:
2735 - installs a SIGINT handler that forwards SIGINT to the inferior.
2736 Otherwise a Ctrl-C pressed just while waiting for the initial
2737 stop would end up as a spurious Quit.
2739 - removes stdin from the event loop, which we need if attaching
2740 in the foreground, otherwise on targets that report an initial
2741 stop on attach (which are most) we'd process input/commands
2742 while we're in the event loop waiting for that stop. That is,
2743 before the attach continuation runs and the command is really
2745 target_terminal::inferior ();
2747 /* Set up execution context to know that we should return from
2748 wait_for_inferior as soon as the target reports a stop. */
2749 init_wait_for_inferior ();
2750 clear_proceed_status (0);
2752 inferior
->needs_setup
= 1;
2754 if (target_is_non_stop_p ())
2756 /* If we find that the current thread isn't stopped, explicitly
2757 do so now, because we're going to install breakpoints and
2761 /* The user requested an `attach&'; stop just one thread. */
2762 target_stop (inferior_ptid
);
2764 /* The user requested an `attach', so stop all threads of this
2766 target_stop (ptid_t (inferior_ptid
.pid ()));
2769 mode
= async_exec
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_STOP
;
2771 /* Some system don't generate traps when attaching to inferior.
2772 E.g. Mach 3 or GNU hurd. */
2773 if (!target_attach_no_wait ())
2775 struct attach_command_continuation_args
*a
;
2777 /* Careful here. See comments in inferior.h. Basically some
2778 OSes don't ignore SIGSTOPs on continue requests anymore. We
2779 need a way for handle_inferior_event to reset the stop_signal
2780 variable after an attach, and this is what
2781 STOP_QUIETLY_NO_SIGSTOP is for. */
2782 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2784 /* Wait for stop. */
2785 a
= XNEW (struct attach_command_continuation_args
);
2786 a
->args
= xstrdup (args
);
2787 a
->from_tty
= from_tty
;
2789 add_inferior_continuation (attach_command_continuation
, a
,
2790 attach_command_continuation_free_args
);
2792 if (!target_is_async_p ())
2793 mark_infrun_async_event_handler ();
2797 attach_post_wait (args
, from_tty
, mode
);
2800 /* We had just found out that the target was already attached to an
2801 inferior. PTID points at a thread of this new inferior, that is
2802 the most likely to be stopped right now, but not necessarily so.
2803 The new inferior is assumed to be already added to the inferior
2804 list at this point. If LEAVE_RUNNING, then leave the threads of
2805 this inferior running, except those we've explicitly seen reported
2809 notice_new_inferior (thread_info
*thr
, int leave_running
, int from_tty
)
2811 enum attach_post_wait_mode mode
2812 = leave_running
? ATTACH_POST_WAIT_RESUME
: ATTACH_POST_WAIT_NOTHING
;
2814 gdb::optional
<scoped_restore_current_thread
> restore_thread
;
2816 if (inferior_ptid
!= null_ptid
)
2817 restore_thread
.emplace ();
2819 /* Avoid reading registers -- we haven't fetched the target
2821 switch_to_thread_no_regs (thr
);
2823 /* When we "notice" a new inferior we need to do all the things we
2824 would normally do if we had just attached to it. */
2828 struct attach_command_continuation_args
*a
;
2829 struct inferior
*inferior
= current_inferior ();
2831 /* We're going to install breakpoints, and poke at memory,
2832 ensure that the inferior is stopped for a moment while we do
2834 target_stop (inferior_ptid
);
2836 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2838 /* Wait for stop before proceeding. */
2839 a
= XNEW (struct attach_command_continuation_args
);
2840 a
->args
= xstrdup ("");
2841 a
->from_tty
= from_tty
;
2843 add_inferior_continuation (attach_command_continuation
, a
,
2844 attach_command_continuation_free_args
);
2849 attach_post_wait ("" /* args */, from_tty
, mode
);
2854 * takes a program previously attached to and detaches it.
2855 * The program resumes execution and will no longer stop
2856 * on signals, etc. We better not have left any breakpoints
2857 * in the program or it'll die when it hits one. For this
2858 * to work, it may be necessary for the process to have been
2859 * previously attached. It *might* work if the program was
2860 * started via the normal ptrace (PTRACE_TRACEME).
2864 detach_command (const char *args
, int from_tty
)
2866 dont_repeat (); /* Not for the faint of heart. */
2868 if (inferior_ptid
== null_ptid
)
2869 error (_("The program is not being run."));
2871 query_if_trace_running (from_tty
);
2873 disconnect_tracing ();
2875 target_detach (current_inferior (), from_tty
);
2877 /* The current inferior process was just detached successfully. Get
2878 rid of breakpoints that no longer make sense. Note we don't do
2879 this within target_detach because that is also used when
2880 following child forks, and in that case we will want to transfer
2881 breakpoints to the child, not delete them. */
2882 breakpoint_init_inferior (inf_exited
);
2884 /* If the solist is global across inferiors, don't clear it when we
2885 detach from a single inferior. */
2886 if (!gdbarch_has_global_solist (target_gdbarch ()))
2887 no_shared_libraries (NULL
, from_tty
);
2889 if (deprecated_detach_hook
)
2890 deprecated_detach_hook ();
2893 /* Disconnect from the current target without resuming it (leaving it
2894 waiting for a debugger).
2896 We'd better not have left any breakpoints in the program or the
2897 next debugger will get confused. Currently only supported for some
2898 remote targets, since the normal attach mechanisms don't work on
2899 stopped processes on some native platforms (e.g. GNU/Linux). */
2902 disconnect_command (const char *args
, int from_tty
)
2904 dont_repeat (); /* Not for the faint of heart. */
2905 query_if_trace_running (from_tty
);
2906 disconnect_tracing ();
2907 target_disconnect (args
, from_tty
);
2908 no_shared_libraries (NULL
, from_tty
);
2909 init_thread_list ();
2910 if (deprecated_detach_hook
)
2911 deprecated_detach_hook ();
2915 interrupt_target_1 (int all_threads
)
2920 ptid
= minus_one_ptid
;
2922 ptid
= inferior_ptid
;
2927 target_interrupt ();
2929 /* Tag the thread as having been explicitly requested to stop, so
2930 other parts of gdb know not to resume this thread automatically,
2931 if it was stopped due to an internal event. Limit this to
2932 non-stop mode, as when debugging a multi-threaded application in
2933 all-stop mode, we will only get one stop event --- it's undefined
2934 which thread will report the event. */
2936 set_stop_requested (ptid
, 1);
2940 Stop the execution of the target while running in async mode, in
2941 the background. In all-stop, stop the whole process. In non-stop
2942 mode, stop the current thread only by default, or stop all threads
2943 if the `-a' switch is used. */
2946 interrupt_command (const char *args
, int from_tty
)
2948 if (target_can_async_p ())
2950 int all_threads
= 0;
2952 dont_repeat (); /* Not for the faint of heart. */
2955 && startswith (args
, "-a"))
2958 if (!non_stop
&& all_threads
)
2959 error (_("-a is meaningless in all-stop mode."));
2961 interrupt_target_1 (all_threads
);
2965 /* See inferior.h. */
2968 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2969 struct frame_info
*frame
, const char *args
)
2972 int printed_something
= 0;
2974 for (regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2976 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2978 printed_something
= 1;
2979 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2982 if (!printed_something
)
2983 fprintf_filtered (file
, "No floating-point info "
2984 "available for this processor.\n");
2988 info_float_command (const char *args
, int from_tty
)
2990 struct frame_info
*frame
;
2992 if (!target_has_registers
)
2993 error (_("The program has no registers now."));
2995 frame
= get_selected_frame (NULL
);
2996 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
3000 unset_command (const char *args
, int from_tty
)
3002 printf_filtered (_("\"unset\" must be followed by the "
3003 "name of an unset subcommand.\n"));
3004 help_list (unsetlist
, "unset ", all_commands
, gdb_stdout
);
3007 /* Implement `info proc' family of commands. */
3010 info_proc_cmd_1 (const char *args
, enum info_proc_what what
, int from_tty
)
3012 struct gdbarch
*gdbarch
= get_current_arch ();
3014 if (!target_info_proc (args
, what
))
3016 if (gdbarch_info_proc_p (gdbarch
))
3017 gdbarch_info_proc (gdbarch
, args
, what
);
3019 error (_("Not supported on this target."));
3023 /* Implement `info proc' when given without any further parameters. */
3026 info_proc_cmd (const char *args
, int from_tty
)
3028 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
3031 /* Implement `info proc mappings'. */
3034 info_proc_cmd_mappings (const char *args
, int from_tty
)
3036 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
3039 /* Implement `info proc stat'. */
3042 info_proc_cmd_stat (const char *args
, int from_tty
)
3044 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
3047 /* Implement `info proc status'. */
3050 info_proc_cmd_status (const char *args
, int from_tty
)
3052 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
3055 /* Implement `info proc cwd'. */
3058 info_proc_cmd_cwd (const char *args
, int from_tty
)
3060 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
3063 /* Implement `info proc cmdline'. */
3066 info_proc_cmd_cmdline (const char *args
, int from_tty
)
3068 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
3071 /* Implement `info proc exe'. */
3074 info_proc_cmd_exe (const char *args
, int from_tty
)
3076 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
3079 /* Implement `info proc files'. */
3082 info_proc_cmd_files (const char *args
, int from_tty
)
3084 info_proc_cmd_1 (args
, IP_FILES
, from_tty
);
3087 /* Implement `info proc all'. */
3090 info_proc_cmd_all (const char *args
, int from_tty
)
3092 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
3095 /* Implement `show print finish'. */
3098 show_print_finish (struct ui_file
*file
, int from_tty
,
3099 struct cmd_list_element
*c
,
3102 fprintf_filtered (file
, _("\
3103 Printing of return value after `finish' is %s.\n"),
3108 /* This help string is used for the run, start, and starti commands.
3109 It is defined as a macro to prevent duplication. */
3111 #define RUN_ARGS_HELP \
3112 "You may specify arguments to give it.\n\
3113 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3114 shell that will start the program (specified by the \"$SHELL\" environment\n\
3115 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
3116 are also allowed.\n\
3118 With no arguments, uses arguments last specified (with \"run\" or \n\
3119 \"set args\"). To cancel previous arguments and run with no arguments,\n\
3120 use \"set args\" without arguments.\n\
3122 To start the inferior without using a shell, use \"set startup-with-shell off\"."
3125 _initialize_infcmd (void)
3127 static struct cmd_list_element
*info_proc_cmdlist
;
3128 struct cmd_list_element
*c
= NULL
;
3129 const char *cmd_name
;
3131 /* Add the filename of the terminal connected to inferior I/O. */
3132 add_setshow_optional_filename_cmd ("inferior-tty", class_run
,
3133 &inferior_io_terminal_scratch
, _("\
3134 Set terminal for future runs of program being debugged."), _("\
3135 Show terminal for future runs of program being debugged."), _("\
3136 Usage: set inferior-tty [TTY]\n\n\
3137 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3139 set_inferior_tty_command
,
3140 show_inferior_tty_command
,
3141 &setlist
, &showlist
);
3142 cmd_name
= "inferior-tty";
3143 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3144 gdb_assert (c
!= NULL
);
3145 add_alias_cmd ("tty", c
, class_alias
, 0, &cmdlist
);
3148 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3149 &inferior_args_scratch
, _("\
3150 Set argument list to give program being debugged when it is started."), _("\
3151 Show argument list to give program being debugged when it is started."), _("\
3152 Follow this command with any number of args, to be passed to the program."),
3155 &setlist
, &showlist
);
3156 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3157 gdb_assert (c
!= NULL
);
3158 set_cmd_completer (c
, filename_completer
);
3161 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
3162 &inferior_cwd_scratch
, _("\
3163 Set the current working directory to be used when the inferior is started.\n\
3164 Changing this setting does not have any effect on inferiors that are\n\
3167 Show the current working directory that is used when the inferior is started."),
3169 Use this command to change the current working directory that will be used\n\
3170 when the inferior is started. This setting does not affect GDB's current\n\
3171 working directory."),
3174 &setlist
, &showlist
);
3175 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
3176 gdb_assert (c
!= NULL
);
3177 set_cmd_completer (c
, filename_completer
);
3179 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3180 The environment to give the program, or one variable's value.\n\
3181 With an argument VAR, prints the value of environment variable VAR to\n\
3182 give the program being debugged. With no arguments, prints the entire\n\
3183 environment to be given to the program."), &showlist
);
3184 set_cmd_completer (c
, noop_completer
);
3186 add_prefix_cmd ("unset", no_class
, unset_command
,
3187 _("Complement to certain \"set\" commands."),
3188 &unsetlist
, "unset ", 0, &cmdlist
);
3190 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3191 Cancel environment variable VAR for the program.\n\
3192 This does not affect the program until the next \"run\" command."),
3194 set_cmd_completer (c
, noop_completer
);
3196 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3197 Set environment variable value to give the program.\n\
3198 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3199 VALUES of environment variables are uninterpreted strings.\n\
3200 This does not affect the program until the next \"run\" command."),
3202 set_cmd_completer (c
, noop_completer
);
3204 c
= add_com ("path", class_files
, path_command
, _("\
3205 Add directory DIR(s) to beginning of search path for object files.\n\
3206 $cwd in the path means the current working directory.\n\
3207 This path is equivalent to the $PATH shell variable. It is a list of\n\
3208 directories, separated by colons. These directories are searched to find\n\
3209 fully linked executable files and separately compiled object files as \
3211 set_cmd_completer (c
, filename_completer
);
3213 c
= add_cmd ("paths", no_class
, path_info
, _("\
3214 Current search path for finding object files.\n\
3215 $cwd in the path means the current working directory.\n\
3216 This path is equivalent to the $PATH shell variable. It is a list of\n\
3217 directories, separated by colons. These directories are searched to find\n\
3218 fully linked executable files and separately compiled object files as \
3221 set_cmd_completer (c
, noop_completer
);
3223 add_prefix_cmd ("kill", class_run
, kill_command
,
3224 _("Kill execution of program being debugged."),
3225 &killlist
, "kill ", 0, &cmdlist
);
3227 add_com ("attach", class_run
, attach_command
, _("\
3228 Attach to a process or file outside of GDB.\n\
3229 This command attaches to another target, of the same type as your last\n\
3230 \"target\" command (\"info files\" will show your target stack).\n\
3231 The command may take as argument a process id or a device file.\n\
3232 For a process id, you must have permission to send the process a signal,\n\
3233 and it must have the same effective uid as the debugger.\n\
3234 When using \"attach\" with a process id, the debugger finds the\n\
3235 program running in the process, looking first in the current working\n\
3236 directory, or (if not found there) using the source file search path\n\
3237 (see the \"directory\" command). You can also use the \"file\" command\n\
3238 to specify the program, and to load its symbol table."));
3240 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3241 Detach a process or file previously attached.\n\
3242 If a process, it is no longer traced, and it continues its execution. If\n\
3243 you were debugging a file, the file is closed and gdb no longer accesses it."),
3244 &detachlist
, "detach ", 0, &cmdlist
);
3246 add_com ("disconnect", class_run
, disconnect_command
, _("\
3247 Disconnect from a target.\n\
3248 The target will wait for another debugger to connect. Not available for\n\
3251 c
= add_com ("signal", class_run
, signal_command
, _("\
3252 Continue program with the specified signal.\n\
3253 Usage: signal SIGNAL\n\
3254 The SIGNAL argument is processed the same as the handle command.\n\
3256 An argument of \"0\" means continue the program without sending it a signal.\n\
3257 This is useful in cases where the program stopped because of a signal,\n\
3258 and you want to resume the program while discarding the signal.\n\
3260 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3261 the current thread only."));
3262 set_cmd_completer (c
, signal_completer
);
3264 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3265 Queue a signal to be delivered to the current thread when it is resumed.\n\
3266 Usage: queue-signal SIGNAL\n\
3267 The SIGNAL argument is processed the same as the handle command.\n\
3268 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3270 An argument of \"0\" means remove any currently queued signal from\n\
3271 the current thread. This is useful in cases where the program stopped\n\
3272 because of a signal, and you want to resume it while discarding the signal.\n\
3274 In a multi-threaded program the signal is queued with, or discarded from,\n\
3275 the current thread only."));
3276 set_cmd_completer (c
, signal_completer
);
3278 add_com ("stepi", class_run
, stepi_command
, _("\
3279 Step one instruction exactly.\n\
3281 Argument N means step N times (or till program stops for another \
3283 add_com_alias ("si", "stepi", class_alias
, 0);
3285 add_com ("nexti", class_run
, nexti_command
, _("\
3286 Step one instruction, but proceed through subroutine calls.\n\
3288 Argument N means step N times (or till program stops for another \
3290 add_com_alias ("ni", "nexti", class_alias
, 0);
3292 add_com ("finish", class_run
, finish_command
, _("\
3293 Execute until selected stack frame returns.\n\
3295 Upon return, the value returned is printed and put in the value history."));
3296 add_com_alias ("fin", "finish", class_run
, 1);
3298 add_com ("next", class_run
, next_command
, _("\
3299 Step program, proceeding through subroutine calls.\n\
3301 Unlike \"step\", if the current source line calls a subroutine,\n\
3302 this command does not enter the subroutine, but instead steps over\n\
3303 the call, in effect treating it as a single source line."));
3304 add_com_alias ("n", "next", class_run
, 1);
3306 add_com ("step", class_run
, step_command
, _("\
3307 Step program until it reaches a different source line.\n\
3309 Argument N means step N times (or till program stops for another \
3311 add_com_alias ("s", "step", class_run
, 1);
3313 c
= add_com ("until", class_run
, until_command
, _("\
3314 Execute until past the current line or past a LOCATION.\n\
3315 Execute until the program reaches a source line greater than the current\n\
3316 or a specified location (same args as break command) within the current \
3318 set_cmd_completer (c
, location_completer
);
3319 add_com_alias ("u", "until", class_run
, 1);
3321 c
= add_com ("advance", class_run
, advance_command
, _("\
3322 Continue the program up to the given location (same form as args for break \
3324 Execution will also stop upon exit from the current stack frame."));
3325 set_cmd_completer (c
, location_completer
);
3327 c
= add_com ("jump", class_run
, jump_command
, _("\
3328 Continue program being debugged at specified line or address.\n\
3329 Usage: jump LOCATION\n\
3330 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3331 for an address to start at."));
3332 set_cmd_completer (c
, location_completer
);
3333 add_com_alias ("j", "jump", class_run
, 1);
3335 add_com ("continue", class_run
, continue_command
, _("\
3336 Continue program being debugged, after signal or breakpoint.\n\
3337 Usage: continue [N]\n\
3338 If proceeding from breakpoint, a number N may be used as an argument,\n\
3339 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3340 the breakpoint won't break until the Nth time it is reached).\n\
3342 If non-stop mode is enabled, continue only the current thread,\n\
3343 otherwise all the threads in the program are continued. To \n\
3344 continue all stopped threads in non-stop mode, use the -a option.\n\
3345 Specifying -a and an ignore count simultaneously is an error."));
3346 add_com_alias ("c", "cont", class_run
, 1);
3347 add_com_alias ("fg", "cont", class_run
, 1);
3349 c
= add_com ("run", class_run
, run_command
, _("\
3350 Start debugged program.\n"
3352 set_cmd_completer (c
, filename_completer
);
3353 add_com_alias ("r", "run", class_run
, 1);
3355 c
= add_com ("start", class_run
, start_command
, _("\
3356 Start the debugged program stopping at the beginning of the main procedure.\n"
3358 set_cmd_completer (c
, filename_completer
);
3360 c
= add_com ("starti", class_run
, starti_command
, _("\
3361 Start the debugged program stopping at the first instruction.\n"
3363 set_cmd_completer (c
, filename_completer
);
3365 add_com ("interrupt", class_run
, interrupt_command
,
3366 _("Interrupt the execution of the debugged program.\n\
3367 If non-stop mode is enabled, interrupt only the current thread,\n\
3368 otherwise all the threads in the program are stopped. To \n\
3369 interrupt all running threads in non-stop mode, use the -a option."));
3371 c
= add_info ("registers", info_registers_command
, _("\
3372 List of integer registers and their contents, for selected stack frame.\n\
3373 One or more register names as argument means describe the given registers.\n\
3374 One or more register group names as argument means describe the registers\n\
3375 in the named register groups."));
3376 add_info_alias ("r", "registers", 1);
3377 set_cmd_completer (c
, reg_or_group_completer
);
3379 c
= add_info ("all-registers", info_all_registers_command
, _("\
3380 List of all registers and their contents, for selected stack frame.\n\
3381 One or more register names as argument means describe the given registers.\n\
3382 One or more register group names as argument means describe the registers\n\
3383 in the named register groups."));
3384 set_cmd_completer (c
, reg_or_group_completer
);
3386 add_info ("program", info_program_command
,
3387 _("Execution status of the program."));
3389 add_info ("float", info_float_command
,
3390 _("Print the status of the floating point unit."));
3392 add_info ("vector", info_vector_command
,
3393 _("Print the status of the vector unit."));
3395 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3397 Show additional information about a process.\n\
3398 Specify any process id, or use the program being debugged by default."),
3399 &info_proc_cmdlist
, "info proc ",
3400 1/*allow-unknown*/, &infolist
);
3402 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3403 List memory regions mapped by the specified process."),
3404 &info_proc_cmdlist
);
3406 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3407 List process info from /proc/PID/stat."),
3408 &info_proc_cmdlist
);
3410 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3411 List process info from /proc/PID/status."),
3412 &info_proc_cmdlist
);
3414 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3415 List current working directory of the specified process."),
3416 &info_proc_cmdlist
);
3418 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3419 List command line arguments of the specified process."),
3420 &info_proc_cmdlist
);
3422 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3423 List absolute filename for executable of the specified process."),
3424 &info_proc_cmdlist
);
3426 add_cmd ("files", class_info
, info_proc_cmd_files
, _("\
3427 List files opened by the specified process."),
3428 &info_proc_cmdlist
);
3430 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3431 List all available info about the specified process."),
3432 &info_proc_cmdlist
);
3434 add_setshow_boolean_cmd ("finish", class_support
,
3435 &user_print_options
.finish_print
, _("\
3436 Set whether `finish' prints the return value."), _("\
3437 Show whether `finish' prints the return value."), NULL
,
3440 &setprintlist
, &showprintlist
);