Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / infcmd.c
blobe909d4d4c818f0c221ab73e1ab7badf38424c10c
1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "frame.h"
25 #include "inferior.h"
26 #include "infrun.h"
27 #include "gdbsupport/environ.h"
28 #include "value.h"
29 #include "gdbcmd.h"
30 #include "symfile.h"
31 #include "gdbcore.h"
32 #include "target.h"
33 #include "language.h"
34 #include "objfiles.h"
35 #include "completer.h"
36 #include "ui-out.h"
37 #include "regcache.h"
38 #include "reggroups.h"
39 #include "block.h"
40 #include "solib.h"
41 #include <ctype.h>
42 #include "observable.h"
43 #include "target-descriptions.h"
44 #include "user-regs.h"
45 #include "gdbthread.h"
46 #include "valprint.h"
47 #include "inline-frame.h"
48 #include "tracepoint.h"
49 #include "inf-loop.h"
50 #include "linespec.h"
51 #include "thread-fsm.h"
52 #include "top.h"
53 #include "interps.h"
54 #include "skip.h"
55 #include "gdbsupport/gdb_optional.h"
56 #include "source.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')
72 means no args. */
74 static std::string inferior_args_scratch;
76 /* Scratch area where the new cwd will be stored by 'set cwd'. */
78 static std::string inferior_cwd_scratch;
80 /* Scratch area where 'set inferior-tty' will store user-provided value.
81 We'll immediate copy it into per-inferior storage. */
83 static std::string inferior_io_terminal_scratch;
85 /* Pid of our debugged inferior, or 0 if no inferior now.
86 Since various parts of infrun.c test this to see whether there is a program
87 being debugged it should be nonzero (currently 3 is used) for remote
88 debugging. */
90 ptid_t inferior_ptid;
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
97 process. */
99 int stopped_by_random_signal;
103 static void
104 set_inferior_tty_command (const char *args, int from_tty,
105 struct cmd_list_element *c)
107 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
108 Now route it to current inferior. */
109 current_inferior ()->set_tty (inferior_io_terminal_scratch);
112 static void
113 show_inferior_tty_command (struct ui_file *file, int from_tty,
114 struct cmd_list_element *c, const char *value)
116 /* Note that we ignore the passed-in value in favor of computing it
117 directly. */
118 const std::string &inferior_tty = current_inferior ()->tty ();
120 gdb_printf (file,
121 _("Terminal for future runs of program being debugged "
122 "is \"%s\".\n"), inferior_tty.c_str ());
125 void
126 set_inferior_args_vector (int argc, char **argv)
128 gdb::array_view<char * const> args (argv, argc);
129 std::string n = construct_inferior_arguments (args);
130 current_inferior ()->set_args (std::move (n));
133 /* Notice when `set args' is run. */
135 static void
136 set_args_command (const char *args, int from_tty, struct cmd_list_element *c)
138 /* CLI has assigned the user-provided value to inferior_args_scratch.
139 Now route it to current inferior. */
140 current_inferior ()->set_args (inferior_args_scratch);
143 /* Notice when `show args' is run. */
145 static void
146 show_args_command (struct ui_file *file, int from_tty,
147 struct cmd_list_element *c, const char *value)
149 /* Note that we ignore the passed-in value in favor of computing it
150 directly. */
151 deprecated_show_value_hack (file, from_tty, c,
152 current_inferior ()->args ().c_str ());
155 /* See gdbsupport/common-inferior.h. */
157 const std::string &
158 get_inferior_cwd ()
160 return current_inferior ()->cwd ();
163 /* Handle the 'set cwd' command. */
165 static void
166 set_cwd_command (const char *args, int from_tty, struct cmd_list_element *c)
168 current_inferior ()->set_cwd (inferior_cwd_scratch);
171 /* Handle the 'show cwd' command. */
173 static void
174 show_cwd_command (struct ui_file *file, int from_tty,
175 struct cmd_list_element *c, const char *value)
177 const std::string &cwd = current_inferior ()->cwd ();
179 if (cwd.empty ())
180 gdb_printf (file,
181 _("\
182 You have not set the inferior's current working directory.\n\
183 The inferior will inherit GDB's cwd if native debugging, or the remote\n\
184 server's cwd if remote debugging.\n"));
185 else
186 gdb_printf (file,
187 _("Current working directory that will be used "
188 "when starting the inferior is \"%s\".\n"),
189 cwd.c_str ());
193 /* This function strips the '&' character (indicating background
194 execution) that is added as *the last* of the arguments ARGS of a
195 command. A copy of the incoming ARGS without the '&' is returned,
196 unless the resulting string after stripping is empty, in which case
197 NULL is returned. *BG_CHAR_P is an output boolean that indicates
198 whether the '&' character was found. */
200 static gdb::unique_xmalloc_ptr<char>
201 strip_bg_char (const char *args, int *bg_char_p)
203 const char *p;
205 if (args == NULL || *args == '\0')
207 *bg_char_p = 0;
208 return NULL;
211 p = args + strlen (args);
212 if (p[-1] == '&')
214 p--;
215 while (p > args && isspace (p[-1]))
216 p--;
218 *bg_char_p = 1;
219 if (p != args)
220 return gdb::unique_xmalloc_ptr<char>
221 (savestring (args, p - args));
222 else
223 return gdb::unique_xmalloc_ptr<char> (nullptr);
226 *bg_char_p = 0;
227 return make_unique_xstrdup (args);
230 /* Common actions to take after creating any sort of inferior, by any
231 means (running, attaching, connecting, et cetera). The target
232 should be stopped. */
234 void
235 post_create_inferior (int from_tty)
238 /* Be sure we own the terminal in case write operations are performed. */
239 target_terminal::ours_for_output ();
241 infrun_debug_show_threads ("threads in the newly created inferior",
242 current_inferior ()->non_exited_threads ());
244 /* If the target hasn't taken care of this already, do it now.
245 Targets which need to access registers during to_open,
246 to_create_inferior, or to_attach should do it earlier; but many
247 don't need to. */
248 target_find_description ();
250 /* Now that we know the register layout, retrieve current PC. But
251 if the PC is unavailable (e.g., we're opening a core file with
252 missing registers info), ignore it. */
253 thread_info *thr = inferior_thread ();
255 thr->clear_stop_pc ();
258 regcache *rc = get_thread_regcache (thr);
259 thr->set_stop_pc (regcache_read_pc (rc));
261 catch (const gdb_exception_error &ex)
263 if (ex.error != NOT_AVAILABLE_ERROR)
264 throw;
267 if (current_program_space->exec_bfd ())
269 const unsigned solib_add_generation
270 = current_program_space->solib_add_generation;
272 scoped_restore restore_in_initial_library_scan
273 = make_scoped_restore (&current_inferior ()->in_initial_library_scan,
274 true);
276 /* Create the hooks to handle shared library load and unload
277 events. */
278 solib_create_inferior_hook (from_tty);
280 if (current_program_space->solib_add_generation == solib_add_generation)
282 /* The platform-specific hook should load initial shared libraries,
283 but didn't. FROM_TTY will be incorrectly 0 but such solib
284 targets should be fixed anyway. Call it only after the solib
285 target has been initialized by solib_create_inferior_hook. */
287 if (info_verbose)
288 warning (_("platform-specific solib_create_inferior_hook did "
289 "not load initial shared libraries."));
291 /* If the solist is global across processes, there's no need to
292 refetch it here. */
293 if (!gdbarch_has_global_solist (target_gdbarch ()))
294 solib_add (NULL, 0, auto_solib_add);
298 /* If the user sets watchpoints before execution having started,
299 then she gets software watchpoints, because GDB can't know which
300 target will end up being pushed, or if it supports hardware
301 watchpoints or not. breakpoint_re_set takes care of promoting
302 watchpoints to hardware watchpoints if possible, however, if this
303 new inferior doesn't load shared libraries or we don't pull in
304 symbols from any other source on this target/arch,
305 breakpoint_re_set is never called. Call it now so that software
306 watchpoints get a chance to be promoted to hardware watchpoints
307 if the now pushed target supports hardware watchpoints. */
308 breakpoint_re_set ();
310 gdb::observers::inferior_created.notify (current_inferior ());
313 /* Kill the inferior if already running. This function is designed
314 to be called when we are about to start the execution of the program
315 from the beginning. Ask the user to confirm that he wants to restart
316 the program being debugged when FROM_TTY is non-null. */
318 static void
319 kill_if_already_running (int from_tty)
321 if (inferior_ptid != null_ptid && target_has_execution ())
323 /* Bail out before killing the program if we will not be able to
324 restart it. */
325 target_require_runnable ();
327 if (from_tty
328 && !query (_("The program being debugged has been started already.\n\
329 Start it from the beginning? ")))
330 error (_("Program not restarted."));
331 target_kill ();
335 /* See inferior.h. */
337 void
338 prepare_execution_command (struct target_ops *target, int background)
340 /* If we get a request for running in the bg but the target
341 doesn't support it, error out. */
342 if (background && !target_can_async_p (target))
343 error (_("Asynchronous execution not supported on this target."));
345 if (!background)
347 /* If we get a request for running in the fg, then we need to
348 simulate synchronous (fg) execution. Note no cleanup is
349 necessary for this. stdin is re-enabled whenever an error
350 reaches the top level. */
351 all_uis_on_sync_execution_starting ();
355 /* Determine how the new inferior will behave. */
357 enum run_how
359 /* Run program without any explicit stop during startup. */
360 RUN_NORMAL,
362 /* Stop at the beginning of the program's main function. */
363 RUN_STOP_AT_MAIN,
365 /* Stop at the first instruction of the program. */
366 RUN_STOP_AT_FIRST_INSN
369 /* Implement the "run" command. Force a stop during program start if
370 requested by RUN_HOW. */
372 static void
373 run_command_1 (const char *args, int from_tty, enum run_how run_how)
375 const char *exec_file;
376 struct ui_out *uiout = current_uiout;
377 struct target_ops *run_target;
378 int async_exec;
380 dont_repeat ();
382 scoped_disable_commit_resumed disable_commit_resumed ("running");
384 kill_if_already_running (from_tty);
386 init_wait_for_inferior ();
387 clear_breakpoint_hit_counts ();
389 /* Clean up any leftovers from other runs. Some other things from
390 this function should probably be moved into target_pre_inferior. */
391 target_pre_inferior (from_tty);
393 /* The comment here used to read, "The exec file is re-read every
394 time we do a generic_mourn_inferior, so we just have to worry
395 about the symbol file." The `generic_mourn_inferior' function
396 gets called whenever the program exits. However, suppose the
397 program exits, and *then* the executable file changes? We need
398 to check again here. Since reopen_exec_file doesn't do anything
399 if the timestamp hasn't changed, I don't see the harm. */
400 reopen_exec_file ();
401 reread_symbols (from_tty);
403 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
404 args = stripped.get ();
406 /* Do validation and preparation before possibly changing anything
407 in the inferior. */
409 run_target = find_run_target ();
411 prepare_execution_command (run_target, async_exec);
413 if (non_stop && !run_target->supports_non_stop ())
414 error (_("The target does not support running in non-stop mode."));
416 /* Done. Can now set breakpoints, change inferior args, etc. */
418 /* Insert temporary breakpoint in main function if requested. */
419 if (run_how == RUN_STOP_AT_MAIN)
421 std::string arg = string_printf ("-qualified %s", main_name ());
422 tbreak_command (arg.c_str (), 0);
425 exec_file = get_exec_file (0);
427 /* We keep symbols from add-symbol-file, on the grounds that the
428 user might want to add some symbols before running the program
429 (right?). But sometimes (dynamic loading where the user manually
430 introduces the new symbols with add-symbol-file), the code which
431 the symbols describe does not persist between runs. Currently
432 the user has to manually nuke all symbols between runs if they
433 want them to go away (PR 2207). This is probably reasonable. */
435 /* If there were other args, beside '&', process them. */
436 if (args != NULL)
437 current_inferior ()->set_args (args);
439 if (from_tty)
441 uiout->field_string (NULL, "Starting program");
442 uiout->text (": ");
443 if (exec_file)
444 uiout->field_string ("execfile", exec_file,
445 file_name_style.style ());
446 uiout->spaces (1);
447 uiout->field_string ("infargs", current_inferior ()->args ());
448 uiout->text ("\n");
449 uiout->flush ();
452 run_target->create_inferior (exec_file,
453 current_inferior ()->args (),
454 current_inferior ()->environment.envp (),
455 from_tty);
456 /* to_create_inferior should push the target, so after this point we
457 shouldn't refer to run_target again. */
458 run_target = NULL;
460 infrun_debug_show_threads ("immediately after create_process",
461 current_inferior ()->non_exited_threads ());
463 /* We're starting off a new process. When we get out of here, in
464 non-stop mode, finish the state of all threads of that process,
465 but leave other threads alone, as they may be stopped in internal
466 events --- the frontend shouldn't see them as stopped. In
467 all-stop, always finish the state of all threads, as we may be
468 resuming more than just the new process. */
469 process_stratum_target *finish_target;
470 ptid_t finish_ptid;
471 if (non_stop)
473 finish_target = current_inferior ()->process_target ();
474 finish_ptid = ptid_t (current_inferior ()->pid);
476 else
478 finish_target = nullptr;
479 finish_ptid = minus_one_ptid;
481 scoped_finish_thread_state finish_state (finish_target, finish_ptid);
483 /* Pass zero for FROM_TTY, because at this point the "run" command
484 has done its thing; now we are setting up the running program. */
485 post_create_inferior (0);
487 /* Queue a pending event so that the program stops immediately. */
488 if (run_how == RUN_STOP_AT_FIRST_INSN)
490 thread_info *thr = inferior_thread ();
491 target_waitstatus ws;
492 ws.set_stopped (GDB_SIGNAL_0);
493 thr->set_pending_waitstatus (ws);
496 /* Start the target running. Do not use -1 continuation as it would skip
497 breakpoint right at the entry point. */
498 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
500 /* Since there was no error, there's no need to finish the thread
501 states here. */
502 finish_state.release ();
504 disable_commit_resumed.reset_and_commit ();
507 static void
508 run_command (const char *args, int from_tty)
510 run_command_1 (args, from_tty, RUN_NORMAL);
513 /* Start the execution of the program up until the beginning of the main
514 program. */
516 static void
517 start_command (const char *args, int from_tty)
519 /* Some languages such as Ada need to search inside the program
520 minimal symbols for the location where to put the temporary
521 breakpoint before starting. */
522 if (!have_minimal_symbols ())
523 error (_("No symbol table loaded. Use the \"file\" command."));
525 /* Run the program until reaching the main procedure... */
526 run_command_1 (args, from_tty, RUN_STOP_AT_MAIN);
529 /* Start the execution of the program stopping at the first
530 instruction. */
532 static void
533 starti_command (const char *args, int from_tty)
535 run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
538 static int
539 proceed_thread_callback (struct thread_info *thread, void *arg)
541 /* We go through all threads individually instead of compressing
542 into a single target `resume_all' request, because some threads
543 may be stopped in internal breakpoints/events, or stopped waiting
544 for its turn in the displaced stepping queue (that is, they are
545 running && !executing). The target side has no idea about why
546 the thread is stopped, so a `resume_all' command would resume too
547 much. If/when GDB gains a way to tell the target `hold this
548 thread stopped until I say otherwise', then we can optimize
549 this. */
550 if (thread->state != THREAD_STOPPED)
551 return 0;
553 if (!thread->inf->has_execution ())
554 return 0;
556 switch_to_thread (thread);
557 clear_proceed_status (0);
558 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
559 return 0;
562 static void
563 ensure_valid_thread (void)
565 if (inferior_ptid == null_ptid
566 || inferior_thread ()->state == THREAD_EXITED)
567 error (_("Cannot execute this command without a live selected thread."));
570 /* If the user is looking at trace frames, any resumption of execution
571 is likely to mix up recorded and live target data. So simply
572 disallow those commands. */
574 static void
575 ensure_not_tfind_mode (void)
577 if (get_traceframe_number () >= 0)
578 error (_("Cannot execute this command while looking at trace frames."));
581 /* Throw an error indicating the current thread is running. */
583 static void
584 error_is_running (void)
586 error (_("Cannot execute this command while "
587 "the selected thread is running."));
590 /* Calls error_is_running if the current thread is running. */
592 static void
593 ensure_not_running (void)
595 if (inferior_thread ()->state == THREAD_RUNNING)
596 error_is_running ();
599 void
600 continue_1 (int all_threads)
602 ERROR_NO_INFERIOR;
603 ensure_not_tfind_mode ();
605 if (non_stop && all_threads)
607 /* Don't error out if the current thread is running, because
608 there may be other stopped threads. */
610 /* Backup current thread and selected frame and restore on scope
611 exit. */
612 scoped_restore_current_thread restore_thread;
613 scoped_disable_commit_resumed disable_commit_resumed
614 ("continue all threads in non-stop");
616 iterate_over_threads (proceed_thread_callback, NULL);
618 if (current_ui->prompt_state == PROMPT_BLOCKED)
620 /* If all threads in the target were already running,
621 proceed_thread_callback ends up never calling proceed,
622 and so nothing calls this to put the inferior's terminal
623 settings in effect and remove stdin from the event loop,
624 which we must when running a foreground command. E.g.:
626 (gdb) c -a&
627 Continuing.
628 <all threads are running now>
629 (gdb) c -a
630 Continuing.
631 <no thread was resumed, but the inferior now owns the terminal>
633 target_terminal::inferior ();
636 disable_commit_resumed.reset_and_commit ();
638 else
640 ensure_valid_thread ();
641 ensure_not_running ();
642 clear_proceed_status (0);
643 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
647 /* continue [-a] [proceed-count] [&] */
649 static void
650 continue_command (const char *args, int from_tty)
652 int async_exec;
653 bool all_threads_p = false;
655 ERROR_NO_INFERIOR;
657 /* Find out whether we must run in the background. */
658 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
659 args = stripped.get ();
661 if (args != NULL)
663 if (startswith (args, "-a"))
665 all_threads_p = true;
666 args += sizeof ("-a") - 1;
667 if (*args == '\0')
668 args = NULL;
672 if (!non_stop && all_threads_p)
673 error (_("`-a' is meaningless in all-stop mode."));
675 if (args != NULL && all_threads_p)
676 error (_("Can't resume all threads and specify "
677 "proceed count simultaneously."));
679 /* If we have an argument left, set proceed count of breakpoint we
680 stopped at. */
681 if (args != NULL)
683 bpstat *bs = nullptr;
684 int num, stat;
685 int stopped = 0;
686 struct thread_info *tp;
688 if (non_stop)
689 tp = inferior_thread ();
690 else
692 process_stratum_target *last_target;
693 ptid_t last_ptid;
695 get_last_target_status (&last_target, &last_ptid, nullptr);
696 tp = find_thread_ptid (last_target, last_ptid);
698 if (tp != NULL)
699 bs = tp->control.stop_bpstat;
701 while ((stat = bpstat_num (&bs, &num)) != 0)
702 if (stat > 0)
704 set_ignore_count (num,
705 parse_and_eval_long (args) - 1,
706 from_tty);
707 /* set_ignore_count prints a message ending with a period.
708 So print two spaces before "Continuing.". */
709 if (from_tty)
710 gdb_printf (" ");
711 stopped = 1;
714 if (!stopped && from_tty)
716 gdb_printf
717 ("Not stopped at any breakpoint; argument ignored.\n");
721 ERROR_NO_INFERIOR;
722 ensure_not_tfind_mode ();
724 if (!non_stop || !all_threads_p)
726 ensure_valid_thread ();
727 ensure_not_running ();
730 prepare_execution_command (current_inferior ()->top_target (), async_exec);
732 if (from_tty)
733 gdb_printf (_("Continuing.\n"));
735 continue_1 (all_threads_p);
738 /* Record in TP the starting point of a "step" or "next" command. */
740 static void
741 set_step_frame (thread_info *tp)
743 /* This can be removed once this function no longer implicitly relies on the
744 inferior_ptid value. */
745 gdb_assert (inferior_ptid == tp->ptid);
747 frame_info *frame = get_current_frame ();
749 symtab_and_line sal = find_frame_sal (frame);
750 set_step_info (tp, frame, sal);
752 CORE_ADDR pc = get_frame_pc (frame);
753 tp->control.step_start_function = find_pc_function (pc);
756 /* Step until outside of current statement. */
758 static void
759 step_command (const char *count_string, int from_tty)
761 step_1 (0, 0, count_string);
764 /* Likewise, but skip over subroutine calls as if single instructions. */
766 static void
767 next_command (const char *count_string, int from_tty)
769 step_1 (1, 0, count_string);
772 /* Likewise, but step only one instruction. */
774 static void
775 stepi_command (const char *count_string, int from_tty)
777 step_1 (0, 1, count_string);
780 static void
781 nexti_command (const char *count_string, int from_tty)
783 step_1 (1, 1, count_string);
786 /* Data for the FSM that manages the step/next/stepi/nexti
787 commands. */
789 struct step_command_fsm : public thread_fsm
791 /* How many steps left in a "step N"-like command. */
792 int count;
794 /* If true, this is a next/nexti, otherwise a step/stepi. */
795 int skip_subroutines;
797 /* If true, this is a stepi/nexti, otherwise a step/step. */
798 int single_inst;
800 explicit step_command_fsm (struct interp *cmd_interp)
801 : thread_fsm (cmd_interp)
805 void clean_up (struct thread_info *thread) override;
806 bool should_stop (struct thread_info *thread) override;
807 enum async_reply_reason do_async_reply_reason () override;
810 /* Prepare for a step/next/etc. command. Any target resource
811 allocated here is undone in the FSM's clean_up method. */
813 static void
814 step_command_fsm_prepare (struct step_command_fsm *sm,
815 int skip_subroutines, int single_inst,
816 int count, struct thread_info *thread)
818 sm->skip_subroutines = skip_subroutines;
819 sm->single_inst = single_inst;
820 sm->count = count;
822 /* Leave the si command alone. */
823 if (!sm->single_inst || sm->skip_subroutines)
824 set_longjmp_breakpoint (thread, get_frame_id (get_current_frame ()));
826 thread->control.stepping_command = 1;
829 static int prepare_one_step (thread_info *, struct step_command_fsm *sm);
831 static void
832 step_1 (int skip_subroutines, int single_inst, const char *count_string)
834 int count;
835 int async_exec;
836 struct thread_info *thr;
837 struct step_command_fsm *step_sm;
839 ERROR_NO_INFERIOR;
840 ensure_not_tfind_mode ();
841 ensure_valid_thread ();
842 ensure_not_running ();
844 gdb::unique_xmalloc_ptr<char> stripped
845 = strip_bg_char (count_string, &async_exec);
846 count_string = stripped.get ();
848 prepare_execution_command (current_inferior ()->top_target (), async_exec);
850 count = count_string ? parse_and_eval_long (count_string) : 1;
852 clear_proceed_status (1);
854 /* Setup the execution command state machine to handle all the COUNT
855 steps. */
856 thr = inferior_thread ();
857 step_sm = new step_command_fsm (command_interp ());
858 thr->set_thread_fsm (std::unique_ptr<thread_fsm> (step_sm));
860 step_command_fsm_prepare (step_sm, skip_subroutines,
861 single_inst, count, thr);
863 /* Do only one step for now, before returning control to the event
864 loop. Let the continuation figure out how many other steps we
865 need to do, and handle them one at the time, through
866 step_once. */
867 if (!prepare_one_step (thr, step_sm))
868 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
869 else
871 int proceeded;
873 /* Stepped into an inline frame. Pretend that we've
874 stopped. */
875 thr->thread_fsm ()->clean_up (thr);
876 proceeded = normal_stop ();
877 if (!proceeded)
878 inferior_event_handler (INF_EXEC_COMPLETE);
879 all_uis_check_sync_execution_done ();
883 /* Implementation of the 'should_stop' FSM method for stepping
884 commands. Called after we are done with one step operation, to
885 check whether we need to step again, before we print the prompt and
886 return control to the user. If count is > 1, returns false, as we
887 will need to keep going. */
889 bool
890 step_command_fsm::should_stop (struct thread_info *tp)
892 if (tp->control.stop_step)
894 /* There are more steps to make, and we did stop due to
895 ending a stepping range. Do another step. */
896 if (--count > 0)
897 return prepare_one_step (tp, this);
899 set_finished ();
902 return true;
905 /* Implementation of the 'clean_up' FSM method for stepping commands. */
907 void
908 step_command_fsm::clean_up (struct thread_info *thread)
910 if (!single_inst || skip_subroutines)
911 delete_longjmp_breakpoint (thread->global_num);
914 /* Implementation of the 'async_reply_reason' FSM method for stepping
915 commands. */
917 enum async_reply_reason
918 step_command_fsm::do_async_reply_reason ()
920 return EXEC_ASYNC_END_STEPPING_RANGE;
923 /* Prepare for one step in "step N". The actual target resumption is
924 done by the caller. Return true if we're done and should thus
925 report a stop to the user. Returns false if the target needs to be
926 resumed. */
928 static int
929 prepare_one_step (thread_info *tp, struct step_command_fsm *sm)
931 /* This can be removed once this function no longer implicitly relies on the
932 inferior_ptid value. */
933 gdb_assert (inferior_ptid == tp->ptid);
935 if (sm->count > 0)
937 struct frame_info *frame = get_current_frame ();
939 set_step_frame (tp);
941 if (!sm->single_inst)
943 CORE_ADDR pc;
945 /* Step at an inlined function behaves like "down". */
946 if (!sm->skip_subroutines
947 && inline_skipped_frames (tp))
949 ptid_t resume_ptid;
950 const char *fn = NULL;
951 symtab_and_line sal;
952 struct symbol *sym;
954 /* Pretend that we've ran. */
955 resume_ptid = user_visible_resume_ptid (1);
956 set_running (tp->inf->process_target (), resume_ptid, true);
958 step_into_inline_frame (tp);
960 frame = get_current_frame ();
961 sal = find_frame_sal (frame);
962 sym = get_frame_function (frame);
964 if (sym != NULL)
965 fn = sym->print_name ();
967 if (sal.line == 0
968 || !function_name_is_marked_for_skip (fn, sal))
970 sm->count--;
971 return prepare_one_step (tp, sm);
975 pc = get_frame_pc (frame);
976 find_pc_line_pc_range (pc,
977 &tp->control.step_range_start,
978 &tp->control.step_range_end);
980 /* There's a problem in gcc (PR gcc/98780) that causes missing line
981 table entries, which results in a too large stepping range.
982 Use inlined_subroutine info to make the range more narrow. */
983 if (inline_skipped_frames (tp) > 0)
985 symbol *sym = inline_skipped_symbol (tp);
986 if (sym->aclass () == LOC_BLOCK)
988 const block *block = sym->value_block ();
989 if (block->end () < tp->control.step_range_end)
990 tp->control.step_range_end = block->end ();
994 tp->control.may_range_step = 1;
996 /* If we have no line info, switch to stepi mode. */
997 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
999 tp->control.step_range_start = tp->control.step_range_end = 1;
1000 tp->control.may_range_step = 0;
1002 else if (tp->control.step_range_end == 0)
1004 const char *name;
1006 if (find_pc_partial_function (pc, &name,
1007 &tp->control.step_range_start,
1008 &tp->control.step_range_end) == 0)
1009 error (_("Cannot find bounds of current function"));
1011 target_terminal::ours_for_output ();
1012 gdb_printf (_("Single stepping until exit from function %s,"
1013 "\nwhich has no line number information.\n"),
1014 name);
1017 else
1019 /* Say we are stepping, but stop after one insn whatever it does. */
1020 tp->control.step_range_start = tp->control.step_range_end = 1;
1021 if (!sm->skip_subroutines)
1022 /* It is stepi.
1023 Don't step over function calls, not even to functions lacking
1024 line numbers. */
1025 tp->control.step_over_calls = STEP_OVER_NONE;
1028 if (sm->skip_subroutines)
1029 tp->control.step_over_calls = STEP_OVER_ALL;
1031 return 0;
1034 /* Done. */
1035 sm->set_finished ();
1036 return 1;
1040 /* Continue program at specified address. */
1042 static void
1043 jump_command (const char *arg, int from_tty)
1045 struct gdbarch *gdbarch = get_current_arch ();
1046 CORE_ADDR addr;
1047 struct symbol *fn;
1048 struct symbol *sfn;
1049 int async_exec;
1051 ERROR_NO_INFERIOR;
1052 ensure_not_tfind_mode ();
1053 ensure_valid_thread ();
1054 ensure_not_running ();
1056 /* Find out whether we must run in the background. */
1057 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
1058 arg = stripped.get ();
1060 prepare_execution_command (current_inferior ()->top_target (), async_exec);
1062 if (!arg)
1063 error_no_arg (_("starting address"));
1065 std::vector<symtab_and_line> sals
1066 = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1067 if (sals.size () != 1)
1068 error (_("Unreasonable jump request"));
1070 symtab_and_line &sal = sals[0];
1072 if (sal.symtab == 0 && sal.pc == 0)
1073 error (_("No source file has been specified."));
1075 resolve_sal_pc (&sal); /* May error out. */
1077 /* See if we are trying to jump to another function. */
1078 fn = get_frame_function (get_current_frame ());
1079 sfn = find_pc_function (sal.pc);
1080 if (fn != NULL && sfn != fn)
1082 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
1083 fn->print_name ()))
1085 error (_("Not confirmed."));
1086 /* NOTREACHED */
1090 if (sfn != NULL)
1092 struct obj_section *section;
1094 fixup_symbol_section (sfn, 0);
1095 section = sfn->obj_section (sfn->objfile ());
1096 if (section_is_overlay (section)
1097 && !section_is_mapped (section))
1099 if (!query (_("WARNING!!! Destination is in "
1100 "unmapped overlay! Jump anyway? ")))
1102 error (_("Not confirmed."));
1103 /* NOTREACHED */
1108 addr = sal.pc;
1110 if (from_tty)
1112 gdb_printf (_("Continuing at "));
1113 gdb_puts (paddress (gdbarch, addr));
1114 gdb_printf (".\n");
1117 clear_proceed_status (0);
1118 proceed (addr, GDB_SIGNAL_0);
1121 /* Continue program giving it specified signal. */
1123 static void
1124 signal_command (const char *signum_exp, int from_tty)
1126 enum gdb_signal oursig;
1127 int async_exec;
1129 dont_repeat (); /* Too dangerous. */
1130 ERROR_NO_INFERIOR;
1131 ensure_not_tfind_mode ();
1132 ensure_valid_thread ();
1133 ensure_not_running ();
1135 /* Find out whether we must run in the background. */
1136 gdb::unique_xmalloc_ptr<char> stripped
1137 = strip_bg_char (signum_exp, &async_exec);
1138 signum_exp = stripped.get ();
1140 prepare_execution_command (current_inferior ()->top_target (), async_exec);
1142 if (!signum_exp)
1143 error_no_arg (_("signal number"));
1145 /* It would be even slicker to make signal names be valid expressions,
1146 (the type could be "enum $signal" or some such), then the user could
1147 assign them to convenience variables. */
1148 oursig = gdb_signal_from_name (signum_exp);
1150 if (oursig == GDB_SIGNAL_UNKNOWN)
1152 /* No, try numeric. */
1153 int num = parse_and_eval_long (signum_exp);
1155 if (num == 0)
1156 oursig = GDB_SIGNAL_0;
1157 else
1158 oursig = gdb_signal_from_command (num);
1161 /* Look for threads other than the current that this command ends up
1162 resuming too (due to schedlock off), and warn if they'll get a
1163 signal delivered. "signal 0" is used to suppress a previous
1164 signal, but if the current thread is no longer the one that got
1165 the signal, then the user is potentially suppressing the signal
1166 of the wrong thread. */
1167 if (!non_stop)
1169 int must_confirm = 0;
1171 /* This indicates what will be resumed. Either a single thread,
1172 a whole process, or all threads of all processes. */
1173 ptid_t resume_ptid = user_visible_resume_ptid (0);
1174 process_stratum_target *resume_target
1175 = user_visible_resume_target (resume_ptid);
1177 thread_info *current = inferior_thread ();
1179 for (thread_info *tp : all_non_exited_threads (resume_target, resume_ptid))
1181 if (tp == current)
1182 continue;
1184 if (tp->stop_signal () != GDB_SIGNAL_0
1185 && signal_pass_state (tp->stop_signal ()))
1187 if (!must_confirm)
1188 gdb_printf (_("Note:\n"));
1189 gdb_printf (_(" Thread %s previously stopped with signal %s, %s.\n"),
1190 print_thread_id (tp),
1191 gdb_signal_to_name (tp->stop_signal ()),
1192 gdb_signal_to_string (tp->stop_signal ()));
1193 must_confirm = 1;
1197 if (must_confirm
1198 && !query (_("Continuing thread %s (the current thread) with specified signal will\n"
1199 "still deliver the signals noted above to their respective threads.\n"
1200 "Continue anyway? "),
1201 print_thread_id (inferior_thread ())))
1202 error (_("Not confirmed."));
1205 if (from_tty)
1207 if (oursig == GDB_SIGNAL_0)
1208 gdb_printf (_("Continuing with no signal.\n"));
1209 else
1210 gdb_printf (_("Continuing with signal %s.\n"),
1211 gdb_signal_to_name (oursig));
1214 clear_proceed_status (0);
1215 proceed ((CORE_ADDR) -1, oursig);
1218 /* Queue a signal to be delivered to the current thread. */
1220 static void
1221 queue_signal_command (const char *signum_exp, int from_tty)
1223 enum gdb_signal oursig;
1224 struct thread_info *tp;
1226 ERROR_NO_INFERIOR;
1227 ensure_not_tfind_mode ();
1228 ensure_valid_thread ();
1229 ensure_not_running ();
1231 if (signum_exp == NULL)
1232 error_no_arg (_("signal number"));
1234 /* It would be even slicker to make signal names be valid expressions,
1235 (the type could be "enum $signal" or some such), then the user could
1236 assign them to convenience variables. */
1237 oursig = gdb_signal_from_name (signum_exp);
1239 if (oursig == GDB_SIGNAL_UNKNOWN)
1241 /* No, try numeric. */
1242 int num = parse_and_eval_long (signum_exp);
1244 if (num == 0)
1245 oursig = GDB_SIGNAL_0;
1246 else
1247 oursig = gdb_signal_from_command (num);
1250 if (oursig != GDB_SIGNAL_0
1251 && !signal_pass_state (oursig))
1252 error (_("Signal handling set to not pass this signal to the program."));
1254 tp = inferior_thread ();
1255 tp->set_stop_signal (oursig);
1258 /* Data for the FSM that manages the until (with no argument)
1259 command. */
1261 struct until_next_fsm : public thread_fsm
1263 /* The thread that as current when the command was executed. */
1264 int thread;
1266 until_next_fsm (struct interp *cmd_interp, int thread)
1267 : thread_fsm (cmd_interp),
1268 thread (thread)
1272 bool should_stop (struct thread_info *thread) override;
1273 void clean_up (struct thread_info *thread) override;
1274 enum async_reply_reason do_async_reply_reason () override;
1277 /* Implementation of the 'should_stop' FSM method for the until (with
1278 no arg) command. */
1280 bool
1281 until_next_fsm::should_stop (struct thread_info *tp)
1283 if (tp->control.stop_step)
1284 set_finished ();
1286 return true;
1289 /* Implementation of the 'clean_up' FSM method for the until (with no
1290 arg) command. */
1292 void
1293 until_next_fsm::clean_up (struct thread_info *thread)
1295 delete_longjmp_breakpoint (thread->global_num);
1298 /* Implementation of the 'async_reply_reason' FSM method for the until
1299 (with no arg) command. */
1301 enum async_reply_reason
1302 until_next_fsm::do_async_reply_reason ()
1304 return EXEC_ASYNC_END_STEPPING_RANGE;
1307 /* Proceed until we reach a different source line with pc greater than
1308 our current one or exit the function. We skip calls in both cases.
1310 Note that eventually this command should probably be changed so
1311 that only source lines are printed out when we hit the breakpoint
1312 we set. This may involve changes to wait_for_inferior and the
1313 proceed status code. */
1315 static void
1316 until_next_command (int from_tty)
1318 struct frame_info *frame;
1319 CORE_ADDR pc;
1320 struct symbol *func;
1321 struct symtab_and_line sal;
1322 struct thread_info *tp = inferior_thread ();
1323 int thread = tp->global_num;
1324 struct until_next_fsm *sm;
1326 clear_proceed_status (0);
1327 set_step_frame (tp);
1329 frame = get_current_frame ();
1331 /* Step until either exited from this function or greater
1332 than the current line (if in symbolic section) or pc (if
1333 not). */
1335 pc = get_frame_pc (frame);
1336 func = find_pc_function (pc);
1338 if (!func)
1340 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
1342 if (msymbol.minsym == NULL)
1343 error (_("Execution is not within a known function."));
1345 tp->control.step_range_start = msymbol.value_address ();
1346 /* The upper-bound of step_range is exclusive. In order to make PC
1347 within the range, set the step_range_end with PC + 1. */
1348 tp->control.step_range_end = pc + 1;
1350 else
1352 sal = find_pc_line (pc, 0);
1354 tp->control.step_range_start = func->value_block ()->entry_pc ();
1355 tp->control.step_range_end = sal.end;
1357 /* By setting the step_range_end based on the current pc, we are
1358 assuming that the last line table entry for any given source line
1359 will have is_stmt set to true. This is not necessarily the case,
1360 there may be additional entries for the same source line with
1361 is_stmt set false. Consider the following code:
1363 for (int i = 0; i < 10; i++)
1364 loop_body ();
1366 Clang-13, will generate multiple line table entries at the end of
1367 the loop all associated with the 'for' line. The first of these
1368 entries is marked is_stmt true, but the other entries are is_stmt
1369 false.
1371 If we only use the values in SAL, then our stepping range may not
1372 extend to the end of the loop. The until command will reach the
1373 end of the range, find a non is_stmt instruction, and step to the
1374 next is_stmt instruction. This stopping point, however, will be
1375 inside the loop, which is not what we wanted.
1377 Instead, we now check any subsequent line table entries to see if
1378 they are for the same line. If they are, and they are marked
1379 is_stmt false, then we extend the end of our stepping range.
1381 When we finish this process the end of the stepping range will
1382 point either to a line with a different line number, or, will
1383 point at an address for the same line number that is marked as a
1384 statement. */
1386 struct symtab_and_line final_sal
1387 = find_pc_line (tp->control.step_range_end, 0);
1389 while (final_sal.line == sal.line && final_sal.symtab == sal.symtab
1390 && !final_sal.is_stmt)
1392 tp->control.step_range_end = final_sal.end;
1393 final_sal = find_pc_line (final_sal.end, 0);
1396 tp->control.may_range_step = 1;
1398 tp->control.step_over_calls = STEP_OVER_ALL;
1400 set_longjmp_breakpoint (tp, get_frame_id (frame));
1401 delete_longjmp_breakpoint_cleanup lj_deleter (thread);
1403 sm = new until_next_fsm (command_interp (), tp->global_num);
1404 tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
1405 lj_deleter.release ();
1407 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1410 static void
1411 until_command (const char *arg, int from_tty)
1413 int async_exec;
1415 ERROR_NO_INFERIOR;
1416 ensure_not_tfind_mode ();
1417 ensure_valid_thread ();
1418 ensure_not_running ();
1420 /* Find out whether we must run in the background. */
1421 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
1422 arg = stripped.get ();
1424 prepare_execution_command (current_inferior ()->top_target (), async_exec);
1426 if (arg)
1427 until_break_command (arg, from_tty, 0);
1428 else
1429 until_next_command (from_tty);
1432 static void
1433 advance_command (const char *arg, int from_tty)
1435 int async_exec;
1437 ERROR_NO_INFERIOR;
1438 ensure_not_tfind_mode ();
1439 ensure_valid_thread ();
1440 ensure_not_running ();
1442 if (arg == NULL)
1443 error_no_arg (_("a location"));
1445 /* Find out whether we must run in the background. */
1446 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
1447 arg = stripped.get ();
1449 prepare_execution_command (current_inferior ()->top_target (), async_exec);
1451 until_break_command (arg, from_tty, 1);
1454 /* See inferior.h. */
1456 struct value *
1457 get_return_value (struct symbol *func_symbol, struct value *function)
1459 regcache *stop_regs = get_current_regcache ();
1460 struct gdbarch *gdbarch = stop_regs->arch ();
1461 struct value *value;
1463 struct type *value_type
1464 = check_typedef (TYPE_TARGET_TYPE (func_symbol->type ()));
1465 gdb_assert (value_type->code () != TYPE_CODE_VOID);
1467 if (is_nocall_function (check_typedef (::value_type (function))))
1469 warning (_("Function '%s' does not follow the target calling "
1470 "convention, cannot determine its returned value."),
1471 func_symbol->print_name ());
1473 return nullptr;
1476 /* FIXME: 2003-09-27: When returning from a nested inferior function
1477 call, it's possible (with no help from the architecture vector)
1478 to locate and return/print a "struct return" value. This is just
1479 a more complicated case of what is already being done in the
1480 inferior function call code. In fact, when inferior function
1481 calls are made async, this will likely be made the norm. */
1483 switch (gdbarch_return_value (gdbarch, function, value_type,
1484 NULL, NULL, NULL))
1486 case RETURN_VALUE_REGISTER_CONVENTION:
1487 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1488 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1489 value = allocate_value (value_type);
1490 gdbarch_return_value (gdbarch, function, value_type, stop_regs,
1491 value_contents_raw (value).data (), NULL);
1492 break;
1493 case RETURN_VALUE_STRUCT_CONVENTION:
1494 value = NULL;
1495 break;
1496 default:
1497 internal_error (__FILE__, __LINE__, _("bad switch"));
1500 return value;
1503 /* The captured function return value/type and its position in the
1504 value history. */
1506 struct return_value_info
1508 /* The captured return value. May be NULL if we weren't able to
1509 retrieve it. See get_return_value. */
1510 struct value *value;
1512 /* The return type. In some cases, we'll not be able extract the
1513 return value, but we always know the type. */
1514 struct type *type;
1516 /* If we captured a value, this is the value history index. */
1517 int value_history_index;
1520 /* Helper for print_return_value. */
1522 static void
1523 print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
1525 if (rv->value != NULL)
1527 struct value_print_options opts;
1529 /* Print it. */
1530 uiout->text ("Value returned is ");
1531 uiout->field_fmt ("gdb-result-var", "$%d",
1532 rv->value_history_index);
1533 uiout->text (" = ");
1534 get_user_print_options (&opts);
1536 if (opts.finish_print)
1538 string_file stb;
1539 value_print (rv->value, &stb, &opts);
1540 uiout->field_stream ("return-value", stb);
1542 else
1543 uiout->field_string ("return-value", _("<not displayed>"),
1544 metadata_style.style ());
1545 uiout->text ("\n");
1547 else
1549 std::string type_name = type_to_string (rv->type);
1550 uiout->text ("Value returned has type: ");
1551 uiout->field_string ("return-type", type_name);
1552 uiout->text (".");
1553 uiout->text (" Cannot determine contents\n");
1557 /* Print the result of a function at the end of a 'finish' command.
1558 RV points at an object representing the captured return value/type
1559 and its position in the value history. */
1561 void
1562 print_return_value (struct ui_out *uiout, struct return_value_info *rv)
1564 if (rv->type == NULL
1565 || check_typedef (rv->type)->code () == TYPE_CODE_VOID)
1566 return;
1570 /* print_return_value_1 can throw an exception in some
1571 circumstances. We need to catch this so that we still
1572 delete the breakpoint. */
1573 print_return_value_1 (uiout, rv);
1575 catch (const gdb_exception &ex)
1577 exception_print (gdb_stdout, ex);
1581 /* Data for the FSM that manages the finish command. */
1583 struct finish_command_fsm : public thread_fsm
1585 /* The momentary breakpoint set at the function's return address in
1586 the caller. */
1587 breakpoint_up breakpoint;
1589 /* The function that we're stepping out of. */
1590 struct symbol *function = nullptr;
1592 /* If the FSM finishes successfully, this stores the function's
1593 return value. */
1594 struct return_value_info return_value_info {};
1596 explicit finish_command_fsm (struct interp *cmd_interp)
1597 : thread_fsm (cmd_interp)
1601 bool should_stop (struct thread_info *thread) override;
1602 void clean_up (struct thread_info *thread) override;
1603 struct return_value_info *return_value () override;
1604 enum async_reply_reason do_async_reply_reason () override;
1607 /* Implementation of the 'should_stop' FSM method for the finish
1608 commands. Detects whether the thread stepped out of the function
1609 successfully, and if so, captures the function's return value and
1610 marks the FSM finished. */
1612 bool
1613 finish_command_fsm::should_stop (struct thread_info *tp)
1615 struct return_value_info *rv = &return_value_info;
1617 if (function != NULL
1618 && bpstat_find_breakpoint (tp->control.stop_bpstat,
1619 breakpoint.get ()) != NULL)
1621 /* We're done. */
1622 set_finished ();
1624 rv->type = TYPE_TARGET_TYPE (function->type ());
1625 if (rv->type == NULL)
1626 internal_error (__FILE__, __LINE__,
1627 _("finish_command: function has no target type"));
1629 if (check_typedef (rv->type)->code () != TYPE_CODE_VOID)
1631 struct value *func;
1633 func = read_var_value (function, NULL, get_current_frame ());
1634 rv->value = get_return_value (function, func);
1635 if (rv->value != NULL)
1636 rv->value_history_index = record_latest_value (rv->value);
1639 else if (tp->control.stop_step)
1641 /* Finishing from an inline frame, or reverse finishing. In
1642 either case, there's no way to retrieve the return value. */
1643 set_finished ();
1646 return true;
1649 /* Implementation of the 'clean_up' FSM method for the finish
1650 commands. */
1652 void
1653 finish_command_fsm::clean_up (struct thread_info *thread)
1655 breakpoint.reset ();
1656 delete_longjmp_breakpoint (thread->global_num);
1659 /* Implementation of the 'return_value' FSM method for the finish
1660 commands. */
1662 struct return_value_info *
1663 finish_command_fsm::return_value ()
1665 return &return_value_info;
1668 /* Implementation of the 'async_reply_reason' FSM method for the
1669 finish commands. */
1671 enum async_reply_reason
1672 finish_command_fsm::do_async_reply_reason ()
1674 if (execution_direction == EXEC_REVERSE)
1675 return EXEC_ASYNC_END_STEPPING_RANGE;
1676 else
1677 return EXEC_ASYNC_FUNCTION_FINISHED;
1680 /* finish_backward -- helper function for finish_command. */
1682 static void
1683 finish_backward (struct finish_command_fsm *sm)
1685 struct symtab_and_line sal;
1686 struct thread_info *tp = inferior_thread ();
1687 CORE_ADDR pc;
1688 CORE_ADDR func_addr;
1690 pc = get_frame_pc (get_current_frame ());
1692 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1693 error (_("Cannot find bounds of current function"));
1695 sal = find_pc_line (func_addr, 0);
1697 tp->control.proceed_to_finish = 1;
1698 /* Special case: if we're sitting at the function entry point,
1699 then all we need to do is take a reverse singlestep. We
1700 don't need to set a breakpoint, and indeed it would do us
1701 no good to do so.
1703 Note that this can only happen at frame #0, since there's
1704 no way that a function up the stack can have a return address
1705 that's equal to its entry point. */
1707 if (sal.pc != pc)
1709 struct frame_info *frame = get_selected_frame (NULL);
1710 struct gdbarch *gdbarch = get_frame_arch (frame);
1712 /* Set a step-resume at the function's entry point. Once that's
1713 hit, we'll do one more step backwards. */
1714 symtab_and_line sr_sal;
1715 sr_sal.pc = sal.pc;
1716 sr_sal.pspace = get_frame_program_space (frame);
1717 insert_step_resume_breakpoint_at_sal (gdbarch,
1718 sr_sal, null_frame_id);
1720 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1722 else
1724 /* We're almost there -- we just need to back up by one more
1725 single-step. */
1726 tp->control.step_range_start = tp->control.step_range_end = 1;
1727 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1731 /* finish_forward -- helper function for finish_command. FRAME is the
1732 frame that called the function we're about to step out of. */
1734 static void
1735 finish_forward (struct finish_command_fsm *sm, struct frame_info *frame)
1737 struct frame_id frame_id = get_frame_id (frame);
1738 struct gdbarch *gdbarch = get_frame_arch (frame);
1739 struct symtab_and_line sal;
1740 struct thread_info *tp = inferior_thread ();
1742 sal = find_pc_line (get_frame_pc (frame), 0);
1743 sal.pc = get_frame_pc (frame);
1745 sm->breakpoint = set_momentary_breakpoint (gdbarch, sal,
1746 get_stack_frame_id (frame),
1747 bp_finish);
1749 /* set_momentary_breakpoint invalidates FRAME. */
1750 frame = NULL;
1752 set_longjmp_breakpoint (tp, frame_id);
1754 /* We want to print return value, please... */
1755 tp->control.proceed_to_finish = 1;
1757 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1760 /* Skip frames for "finish". */
1762 static struct frame_info *
1763 skip_finish_frames (struct frame_info *frame)
1765 struct frame_info *start;
1769 start = frame;
1771 frame = skip_tailcall_frames (frame);
1772 if (frame == NULL)
1773 break;
1775 frame = skip_unwritable_frames (frame);
1776 if (frame == NULL)
1777 break;
1779 while (start != frame);
1781 return frame;
1784 /* "finish": Set a temporary breakpoint at the place the selected
1785 frame will return to, then continue. */
1787 static void
1788 finish_command (const char *arg, int from_tty)
1790 struct frame_info *frame;
1791 int async_exec;
1792 struct finish_command_fsm *sm;
1793 struct thread_info *tp;
1795 ERROR_NO_INFERIOR;
1796 ensure_not_tfind_mode ();
1797 ensure_valid_thread ();
1798 ensure_not_running ();
1800 /* Find out whether we must run in the background. */
1801 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (arg, &async_exec);
1802 arg = stripped.get ();
1804 prepare_execution_command (current_inferior ()->top_target (), async_exec);
1806 if (arg)
1807 error (_("The \"finish\" command does not take any arguments."));
1809 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1810 if (frame == 0)
1811 error (_("\"finish\" not meaningful in the outermost frame."));
1813 clear_proceed_status (0);
1815 tp = inferior_thread ();
1817 sm = new finish_command_fsm (command_interp ());
1819 tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
1821 /* Finishing from an inline frame is completely different. We don't
1822 try to show the "return value" - no way to locate it. */
1823 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1824 == INLINE_FRAME)
1826 /* Claim we are stepping in the calling frame. An empty step
1827 range means that we will stop once we aren't in a function
1828 called by that frame. We don't use the magic "1" value for
1829 step_range_end, because then infrun will think this is nexti,
1830 and not step over the rest of this inlined function call. */
1831 set_step_info (tp, frame, {});
1832 tp->control.step_range_start = get_frame_pc (frame);
1833 tp->control.step_range_end = tp->control.step_range_start;
1834 tp->control.step_over_calls = STEP_OVER_ALL;
1836 /* Print info on the selected frame, including level number but not
1837 source. */
1838 if (from_tty)
1840 gdb_printf (_("Run till exit from "));
1841 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1844 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1845 return;
1848 /* Find the function we will return from. */
1850 sm->function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1852 /* Print info on the selected frame, including level number but not
1853 source. */
1854 if (from_tty)
1856 if (execution_direction == EXEC_REVERSE)
1857 gdb_printf (_("Run back to call of "));
1858 else
1860 if (sm->function != NULL && TYPE_NO_RETURN (sm->function->type ())
1861 && !query (_("warning: Function %s does not return normally.\n"
1862 "Try to finish anyway? "),
1863 sm->function->print_name ()))
1864 error (_("Not confirmed."));
1865 gdb_printf (_("Run till exit from "));
1868 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1871 if (execution_direction == EXEC_REVERSE)
1872 finish_backward (sm);
1873 else
1875 frame = skip_finish_frames (frame);
1877 if (frame == NULL)
1878 error (_("Cannot find the caller frame."));
1880 finish_forward (sm, frame);
1885 static void
1886 info_program_command (const char *args, int from_tty)
1888 bpstat *bs;
1889 int num, stat;
1890 ptid_t ptid;
1891 process_stratum_target *proc_target;
1893 if (!target_has_execution ())
1895 gdb_printf (_("The program being debugged is not being run.\n"));
1896 return;
1899 if (non_stop)
1901 ptid = inferior_ptid;
1902 proc_target = current_inferior ()->process_target ();
1904 else
1905 get_last_target_status (&proc_target, &ptid, nullptr);
1907 if (ptid == null_ptid || ptid == minus_one_ptid)
1908 error (_("No selected thread."));
1910 thread_info *tp = find_thread_ptid (proc_target, ptid);
1912 if (tp->state == THREAD_EXITED)
1913 error (_("Invalid selected thread."));
1914 else if (tp->state == THREAD_RUNNING)
1915 error (_("Selected thread is running."));
1917 bs = tp->control.stop_bpstat;
1918 stat = bpstat_num (&bs, &num);
1920 target_files_info ();
1921 gdb_printf (_("Program stopped at %s.\n"),
1922 paddress (target_gdbarch (), tp->stop_pc ()));
1923 if (tp->control.stop_step)
1924 gdb_printf (_("It stopped after being stepped.\n"));
1925 else if (stat != 0)
1927 /* There may be several breakpoints in the same place, so this
1928 isn't as strange as it seems. */
1929 while (stat != 0)
1931 if (stat < 0)
1933 gdb_printf (_("It stopped at a breakpoint "
1934 "that has since been deleted.\n"));
1936 else
1937 gdb_printf (_("It stopped at breakpoint %d.\n"), num);
1938 stat = bpstat_num (&bs, &num);
1941 else if (tp->stop_signal () != GDB_SIGNAL_0)
1943 gdb_printf (_("It stopped with signal %s, %s.\n"),
1944 gdb_signal_to_name (tp->stop_signal ()),
1945 gdb_signal_to_string (tp->stop_signal ()));
1948 if (from_tty)
1950 gdb_printf (_("Type \"info stack\" or \"info "
1951 "registers\" for more information.\n"));
1955 static void
1956 environment_info (const char *var, int from_tty)
1958 if (var)
1960 const char *val = current_inferior ()->environment.get (var);
1962 if (val)
1964 gdb_puts (var);
1965 gdb_puts (" = ");
1966 gdb_puts (val);
1967 gdb_puts ("\n");
1969 else
1971 gdb_puts ("Environment variable \"");
1972 gdb_puts (var);
1973 gdb_puts ("\" not defined.\n");
1976 else
1978 char **envp = current_inferior ()->environment.envp ();
1980 for (int idx = 0; envp[idx] != NULL; ++idx)
1982 gdb_puts (envp[idx]);
1983 gdb_puts ("\n");
1988 static void
1989 set_environment_command (const char *arg, int from_tty)
1991 const char *p, *val;
1992 int nullset = 0;
1994 if (arg == 0)
1995 error_no_arg (_("environment variable and value"));
1997 /* Find separation between variable name and value. */
1998 p = (char *) strchr (arg, '=');
1999 val = (char *) strchr (arg, ' ');
2001 if (p != 0 && val != 0)
2003 /* We have both a space and an equals. If the space is before the
2004 equals, walk forward over the spaces til we see a nonspace
2005 (possibly the equals). */
2006 if (p > val)
2007 while (*val == ' ')
2008 val++;
2010 /* Now if the = is after the char following the spaces,
2011 take the char following the spaces. */
2012 if (p > val)
2013 p = val - 1;
2015 else if (val != 0 && p == 0)
2016 p = val;
2018 if (p == arg)
2019 error_no_arg (_("environment variable to set"));
2021 if (p == 0 || p[1] == 0)
2023 nullset = 1;
2024 if (p == 0)
2025 p = arg + strlen (arg); /* So that savestring below will work. */
2027 else
2029 /* Not setting variable value to null. */
2030 val = p + 1;
2031 while (*val == ' ' || *val == '\t')
2032 val++;
2035 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2036 p--;
2038 std::string var (arg, p - arg);
2039 if (nullset)
2041 gdb_printf (_("Setting environment variable "
2042 "\"%s\" to null value.\n"),
2043 var.c_str ());
2044 current_inferior ()->environment.set (var.c_str (), "");
2046 else
2047 current_inferior ()->environment.set (var.c_str (), val);
2050 static void
2051 unset_environment_command (const char *var, int from_tty)
2053 if (var == 0)
2055 /* If there is no argument, delete all environment variables.
2056 Ask for confirmation if reading from the terminal. */
2057 if (!from_tty || query (_("Delete all environment variables? ")))
2058 current_inferior ()->environment.clear ();
2060 else
2061 current_inferior ()->environment.unset (var);
2064 /* Handle the execution path (PATH variable). */
2066 static const char path_var_name[] = "PATH";
2068 static void
2069 path_info (const char *args, int from_tty)
2071 gdb_puts ("Executable and object file path: ");
2072 gdb_puts (current_inferior ()->environment.get (path_var_name));
2073 gdb_puts ("\n");
2076 /* Add zero or more directories to the front of the execution path. */
2078 static void
2079 path_command (const char *dirname, int from_tty)
2081 const char *env;
2083 dont_repeat ();
2084 env = current_inferior ()->environment.get (path_var_name);
2085 /* Can be null if path is not set. */
2086 if (!env)
2087 env = "";
2088 std::string exec_path = env;
2089 mod_path (dirname, exec_path);
2090 current_inferior ()->environment.set (path_var_name, exec_path.c_str ());
2091 if (from_tty)
2092 path_info (NULL, from_tty);
2096 static void
2097 pad_to_column (string_file &stream, int col)
2099 /* At least one space must be printed to separate columns. */
2100 stream.putc (' ');
2101 const int size = stream.size ();
2102 if (size < col)
2103 stream.puts (n_spaces (col - size));
2106 /* Print out the register NAME with value VAL, to FILE, in the default
2107 fashion. */
2109 static void
2110 default_print_one_register_info (struct ui_file *file,
2111 const char *name,
2112 struct value *val)
2114 struct type *regtype = value_type (val);
2115 int print_raw_format;
2116 string_file format_stream;
2117 enum tab_stops
2119 value_column_1 = 15,
2120 /* Give enough room for "0x", 16 hex digits and two spaces in
2121 preceding column. */
2122 value_column_2 = value_column_1 + 2 + 16 + 2,
2125 format_stream.puts (name);
2126 pad_to_column (format_stream, value_column_1);
2128 print_raw_format = (value_entirely_available (val)
2129 && !value_optimized_out (val));
2131 /* If virtual format is floating, print it that way, and in raw
2132 hex. */
2133 if (regtype->code () == TYPE_CODE_FLT
2134 || regtype->code () == TYPE_CODE_DECFLOAT)
2136 struct value_print_options opts;
2137 const gdb_byte *valaddr = value_contents_for_printing (val).data ();
2138 enum bfd_endian byte_order = type_byte_order (regtype);
2140 get_user_print_options (&opts);
2141 opts.deref_ref = 1;
2143 common_val_print (val, &format_stream, 0, &opts, current_language);
2145 if (print_raw_format)
2147 pad_to_column (format_stream, value_column_2);
2148 format_stream.puts ("(raw ");
2149 print_hex_chars (&format_stream, valaddr, TYPE_LENGTH (regtype),
2150 byte_order, true);
2151 format_stream.putc (')');
2154 else
2156 struct value_print_options opts;
2158 /* Print the register in hex. */
2159 get_formatted_print_options (&opts, 'x');
2160 opts.deref_ref = 1;
2161 common_val_print (val, &format_stream, 0, &opts, current_language);
2162 /* If not a vector register, print it also according to its
2163 natural format. */
2164 if (print_raw_format && regtype->is_vector () == 0)
2166 pad_to_column (format_stream, value_column_2);
2167 get_user_print_options (&opts);
2168 opts.deref_ref = 1;
2169 common_val_print (val, &format_stream, 0, &opts, current_language);
2173 gdb_puts (format_stream.c_str (), file);
2174 gdb_printf (file, "\n");
2177 /* Print out the machine register regnum. If regnum is -1, print all
2178 registers (print_all == 1) or all non-float and non-vector
2179 registers (print_all == 0).
2181 For most machines, having all_registers_info() print the
2182 register(s) one per line is good enough. If a different format is
2183 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2184 regs), or there is an existing convention for showing all the
2185 registers, define the architecture method PRINT_REGISTERS_INFO to
2186 provide that format. */
2188 void
2189 default_print_registers_info (struct gdbarch *gdbarch,
2190 struct ui_file *file,
2191 struct frame_info *frame,
2192 int regnum, int print_all)
2194 int i;
2195 const int numregs = gdbarch_num_cooked_regs (gdbarch);
2197 for (i = 0; i < numregs; i++)
2199 /* Decide between printing all regs, non-float / vector regs, or
2200 specific reg. */
2201 if (regnum == -1)
2203 if (print_all)
2205 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
2206 continue;
2208 else
2210 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
2211 continue;
2214 else
2216 if (i != regnum)
2217 continue;
2220 /* If the register name is empty, it is undefined for this
2221 processor, so don't display anything. */
2222 if (gdbarch_register_name (gdbarch, i) == NULL
2223 || *(gdbarch_register_name (gdbarch, i)) == '\0')
2224 continue;
2226 default_print_one_register_info (file,
2227 gdbarch_register_name (gdbarch, i),
2228 value_of_register (i, frame));
2232 void
2233 registers_info (const char *addr_exp, int fpregs)
2235 struct frame_info *frame;
2236 struct gdbarch *gdbarch;
2238 if (!target_has_registers ())
2239 error (_("The program has no registers now."));
2240 frame = get_selected_frame (NULL);
2241 gdbarch = get_frame_arch (frame);
2243 if (!addr_exp)
2245 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2246 frame, -1, fpregs);
2247 return;
2250 while (*addr_exp != '\0')
2252 const char *start;
2253 const char *end;
2255 /* Skip leading white space. */
2256 addr_exp = skip_spaces (addr_exp);
2258 /* Discard any leading ``$''. Check that there is something
2259 resembling a register following it. */
2260 if (addr_exp[0] == '$')
2261 addr_exp++;
2262 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2263 error (_("Missing register name"));
2265 /* Find the start/end of this register name/num/group. */
2266 start = addr_exp;
2267 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2268 addr_exp++;
2269 end = addr_exp;
2271 /* Figure out what we've found and display it. */
2273 /* A register name? */
2275 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2277 if (regnum >= 0)
2279 /* User registers lie completely outside of the range of
2280 normal registers. Catch them early so that the target
2281 never sees them. */
2282 if (regnum >= gdbarch_num_cooked_regs (gdbarch))
2284 struct value *regval = value_of_user_reg (regnum, frame);
2285 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2286 regnum);
2288 /* Print in the same fashion
2289 gdbarch_print_registers_info's default
2290 implementation prints. */
2291 default_print_one_register_info (gdb_stdout,
2292 regname,
2293 regval);
2295 else
2296 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2297 frame, regnum, fpregs);
2298 continue;
2302 /* A register group? */
2304 const struct reggroup *group = nullptr;
2305 for (const struct reggroup *g : gdbarch_reggroups (gdbarch))
2307 /* Don't bother with a length check. Should the user
2308 enter a short register group name, go with the first
2309 group that matches. */
2310 if (strncmp (start, g->name (), end - start) == 0)
2312 group = g;
2313 break;
2316 if (group != NULL)
2318 int regnum;
2320 for (regnum = 0;
2321 regnum < gdbarch_num_cooked_regs (gdbarch);
2322 regnum++)
2324 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2325 gdbarch_print_registers_info (gdbarch,
2326 gdb_stdout, frame,
2327 regnum, fpregs);
2329 continue;
2333 /* Nothing matched. */
2334 error (_("Invalid register `%.*s'"), (int) (end - start), start);
2338 static void
2339 info_all_registers_command (const char *addr_exp, int from_tty)
2341 registers_info (addr_exp, 1);
2344 static void
2345 info_registers_command (const char *addr_exp, int from_tty)
2347 registers_info (addr_exp, 0);
2350 static void
2351 print_vector_info (struct ui_file *file,
2352 struct frame_info *frame, const char *args)
2354 struct gdbarch *gdbarch = get_frame_arch (frame);
2356 if (gdbarch_print_vector_info_p (gdbarch))
2357 gdbarch_print_vector_info (gdbarch, file, frame, args);
2358 else
2360 int regnum;
2361 int printed_something = 0;
2363 for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
2365 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2367 printed_something = 1;
2368 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2371 if (!printed_something)
2372 gdb_printf (file, "No vector information\n");
2376 static void
2377 info_vector_command (const char *args, int from_tty)
2379 if (!target_has_registers ())
2380 error (_("The program has no registers now."));
2382 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2385 /* Kill the inferior process. Make us have no inferior. */
2387 static void
2388 kill_command (const char *arg, int from_tty)
2390 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2391 It should be a distinct flag that indicates that a target is active, cuz
2392 some targets don't have processes! */
2394 if (inferior_ptid == null_ptid)
2395 error (_("The program is not being run."));
2396 if (!query (_("Kill the program being debugged? ")))
2397 error (_("Not confirmed."));
2399 int pid = current_inferior ()->pid;
2400 /* Save the pid as a string before killing the inferior, since that
2401 may unpush the current target, and we need the string after. */
2402 std::string pid_str = target_pid_to_str (ptid_t (pid));
2403 int infnum = current_inferior ()->num;
2405 target_kill ();
2406 bfd_cache_close_all ();
2408 if (print_inferior_events)
2409 gdb_printf (_("[Inferior %d (%s) killed]\n"),
2410 infnum, pid_str.c_str ());
2413 /* Used in `attach&' command. Proceed threads of inferior INF iff
2414 they stopped due to debugger request, and when they did, they
2415 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads that
2416 have been explicitly been told to stop. */
2418 static void
2419 proceed_after_attach (inferior *inf)
2421 /* Don't error out if the current thread is running, because
2422 there may be other stopped threads. */
2424 /* Backup current thread and selected frame. */
2425 scoped_restore_current_thread restore_thread;
2427 for (thread_info *thread : inf->non_exited_threads ())
2428 if (!thread->executing ()
2429 && !thread->stop_requested
2430 && thread->stop_signal () == GDB_SIGNAL_0)
2432 switch_to_thread (thread);
2433 clear_proceed_status (0);
2434 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2438 /* See inferior.h. */
2440 void
2441 setup_inferior (int from_tty)
2443 struct inferior *inferior;
2445 inferior = current_inferior ();
2446 inferior->needs_setup = 0;
2448 /* If no exec file is yet known, try to determine it from the
2449 process itself. */
2450 if (get_exec_file (0) == NULL)
2451 exec_file_locate_attach (inferior_ptid.pid (), 1, from_tty);
2452 else
2454 reopen_exec_file ();
2455 reread_symbols (from_tty);
2458 /* Take any necessary post-attaching actions for this platform. */
2459 target_post_attach (inferior_ptid.pid ());
2461 post_create_inferior (from_tty);
2464 /* What to do after the first program stops after attaching. */
2465 enum attach_post_wait_mode
2467 /* Do nothing. Leaves threads as they are. */
2468 ATTACH_POST_WAIT_NOTHING,
2470 /* Re-resume threads that are marked running. */
2471 ATTACH_POST_WAIT_RESUME,
2473 /* Stop all threads. */
2474 ATTACH_POST_WAIT_STOP,
2477 /* Called after we've attached to a process and we've seen it stop for
2478 the first time. Resume, stop, or don't touch the threads according
2479 to MODE. */
2481 static void
2482 attach_post_wait (int from_tty, enum attach_post_wait_mode mode)
2484 struct inferior *inferior;
2486 inferior = current_inferior ();
2487 inferior->control.stop_soon = NO_STOP_QUIETLY;
2489 if (inferior->needs_setup)
2490 setup_inferior (from_tty);
2492 if (mode == ATTACH_POST_WAIT_RESUME)
2494 /* The user requested an `attach&', so be sure to leave threads
2495 that didn't get a signal running. */
2497 /* Immediately resume all suspended threads of this inferior,
2498 and this inferior only. This should have no effect on
2499 already running threads. If a thread has been stopped with a
2500 signal, leave it be. */
2501 if (non_stop)
2502 proceed_after_attach (inferior);
2503 else
2505 if (inferior_thread ()->stop_signal () == GDB_SIGNAL_0)
2507 clear_proceed_status (0);
2508 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2512 else if (mode == ATTACH_POST_WAIT_STOP)
2514 /* The user requested a plain `attach', so be sure to leave
2515 the inferior stopped. */
2517 /* At least the current thread is already stopped. */
2519 /* In all-stop, by definition, all threads have to be already
2520 stopped at this point. In non-stop, however, although the
2521 selected thread is stopped, others may still be executing.
2522 Be sure to explicitly stop all threads of the process. This
2523 should have no effect on already stopped threads. */
2524 if (non_stop)
2525 target_stop (ptid_t (inferior->pid));
2526 else if (target_is_non_stop_p ())
2528 struct thread_info *lowest = inferior_thread ();
2530 stop_all_threads ("attaching");
2532 /* It's not defined which thread will report the attach
2533 stop. For consistency, always select the thread with
2534 lowest GDB number, which should be the main thread, if it
2535 still exists. */
2536 for (thread_info *thread : current_inferior ()->non_exited_threads ())
2537 if (thread->inf->num < lowest->inf->num
2538 || thread->per_inf_num < lowest->per_inf_num)
2539 lowest = thread;
2541 switch_to_thread (lowest);
2544 /* Tell the user/frontend where we're stopped. */
2545 normal_stop ();
2546 if (deprecated_attach_hook)
2547 deprecated_attach_hook ();
2551 /* "attach" command entry point. Takes a program started up outside
2552 of gdb and ``attaches'' to it. This stops it cold in its tracks
2553 and allows us to start debugging it. */
2555 void
2556 attach_command (const char *args, int from_tty)
2558 int async_exec;
2559 struct target_ops *attach_target;
2560 struct inferior *inferior = current_inferior ();
2561 enum attach_post_wait_mode mode;
2563 dont_repeat (); /* Not for the faint of heart */
2565 scoped_disable_commit_resumed disable_commit_resumed ("attaching");
2567 if (gdbarch_has_global_solist (target_gdbarch ()))
2568 /* Don't complain if all processes share the same symbol
2569 space. */
2571 else if (target_has_execution ())
2573 if (query (_("A program is being debugged already. Kill it? ")))
2574 target_kill ();
2575 else
2576 error (_("Not killed."));
2579 /* Clean up any leftovers from other runs. Some other things from
2580 this function should probably be moved into target_pre_inferior. */
2581 target_pre_inferior (from_tty);
2583 gdb::unique_xmalloc_ptr<char> stripped = strip_bg_char (args, &async_exec);
2584 args = stripped.get ();
2586 attach_target = find_attach_target ();
2588 prepare_execution_command (attach_target, async_exec);
2590 if (non_stop && !attach_target->supports_non_stop ())
2591 error (_("Cannot attach to this target in non-stop mode"));
2593 attach_target->attach (args, from_tty);
2594 /* to_attach should push the target, so after this point we
2595 shouldn't refer to attach_target again. */
2596 attach_target = NULL;
2598 infrun_debug_show_threads ("immediately after attach",
2599 current_inferior ()->non_exited_threads ());
2601 /* Enable async mode if it is supported by the target. */
2602 if (target_can_async_p ())
2603 target_async (1);
2605 /* Set up the "saved terminal modes" of the inferior
2606 based on what modes we are starting it with. */
2607 target_terminal::init ();
2609 /* Install inferior's terminal modes. This may look like a no-op,
2610 as we've just saved them above, however, this does more than
2611 restore terminal settings:
2613 - installs a SIGINT handler that forwards SIGINT to the inferior.
2614 Otherwise a Ctrl-C pressed just while waiting for the initial
2615 stop would end up as a spurious Quit.
2617 - removes stdin from the event loop, which we need if attaching
2618 in the foreground, otherwise on targets that report an initial
2619 stop on attach (which are most) we'd process input/commands
2620 while we're in the event loop waiting for that stop. That is,
2621 before the attach continuation runs and the command is really
2622 finished. */
2623 target_terminal::inferior ();
2625 /* Set up execution context to know that we should return from
2626 wait_for_inferior as soon as the target reports a stop. */
2627 init_wait_for_inferior ();
2629 inferior->needs_setup = 1;
2631 if (target_is_non_stop_p ())
2633 /* If we find that the current thread isn't stopped, explicitly
2634 do so now, because we're going to install breakpoints and
2635 poke at memory. */
2637 if (async_exec)
2638 /* The user requested an `attach&'; stop just one thread. */
2639 target_stop (inferior_ptid);
2640 else
2641 /* The user requested an `attach', so stop all threads of this
2642 inferior. */
2643 target_stop (ptid_t (inferior_ptid.pid ()));
2646 /* Check for exec file mismatch, and let the user solve it. */
2647 validate_exec_file (from_tty);
2649 mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP;
2651 /* Some system don't generate traps when attaching to inferior.
2652 E.g. Mach 3 or GNU hurd. */
2653 if (!target_attach_no_wait ())
2655 /* Careful here. See comments in inferior.h. Basically some
2656 OSes don't ignore SIGSTOPs on continue requests anymore. We
2657 need a way for handle_inferior_event to reset the stop_signal
2658 variable after an attach, and this is what
2659 STOP_QUIETLY_NO_SIGSTOP is for. */
2660 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2662 /* Wait for stop. */
2663 inferior->add_continuation ([=] ()
2665 attach_post_wait (from_tty, mode);
2668 /* Let infrun consider waiting for events out of this
2669 target. */
2670 inferior->process_target ()->threads_executing = true;
2672 if (!target_is_async_p ())
2673 mark_infrun_async_event_handler ();
2674 return;
2676 else
2677 attach_post_wait (from_tty, mode);
2679 disable_commit_resumed.reset_and_commit ();
2682 /* We had just found out that the target was already attached to an
2683 inferior. PTID points at a thread of this new inferior, that is
2684 the most likely to be stopped right now, but not necessarily so.
2685 The new inferior is assumed to be already added to the inferior
2686 list at this point. If LEAVE_RUNNING, then leave the threads of
2687 this inferior running, except those we've explicitly seen reported
2688 as stopped. */
2690 void
2691 notice_new_inferior (thread_info *thr, bool leave_running, int from_tty)
2693 enum attach_post_wait_mode mode
2694 = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
2696 gdb::optional<scoped_restore_current_thread> restore_thread;
2698 if (inferior_ptid != null_ptid)
2699 restore_thread.emplace ();
2701 /* Avoid reading registers -- we haven't fetched the target
2702 description yet. */
2703 switch_to_thread_no_regs (thr);
2705 /* When we "notice" a new inferior we need to do all the things we
2706 would normally do if we had just attached to it. */
2708 if (thr->executing ())
2710 struct inferior *inferior = current_inferior ();
2712 /* We're going to install breakpoints, and poke at memory,
2713 ensure that the inferior is stopped for a moment while we do
2714 that. */
2715 target_stop (inferior_ptid);
2717 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2719 /* Wait for stop before proceeding. */
2720 inferior->add_continuation ([=] ()
2722 attach_post_wait (from_tty, mode);
2725 return;
2728 attach_post_wait (from_tty, mode);
2732 * detach_command --
2733 * takes a program previously attached to and detaches it.
2734 * The program resumes execution and will no longer stop
2735 * on signals, etc. We better not have left any breakpoints
2736 * in the program or it'll die when it hits one. For this
2737 * to work, it may be necessary for the process to have been
2738 * previously attached. It *might* work if the program was
2739 * started via the normal ptrace (PTRACE_TRACEME).
2742 void
2743 detach_command (const char *args, int from_tty)
2745 dont_repeat (); /* Not for the faint of heart. */
2747 if (inferior_ptid == null_ptid)
2748 error (_("The program is not being run."));
2750 scoped_disable_commit_resumed disable_commit_resumed ("detaching");
2752 query_if_trace_running (from_tty);
2754 disconnect_tracing ();
2756 /* Hold a strong reference to the target while (maybe)
2757 detaching the parent. Otherwise detaching could close the
2758 target. */
2759 auto target_ref
2760 = target_ops_ref::new_reference (current_inferior ()->process_target ());
2762 /* Save this before detaching, since detaching may unpush the
2763 process_stratum target. */
2764 bool was_non_stop_p = target_is_non_stop_p ();
2766 target_detach (current_inferior (), from_tty);
2768 /* The current inferior process was just detached successfully. Get
2769 rid of breakpoints that no longer make sense. Note we don't do
2770 this within target_detach because that is also used when
2771 following child forks, and in that case we will want to transfer
2772 breakpoints to the child, not delete them. */
2773 breakpoint_init_inferior (inf_exited);
2775 /* If the solist is global across inferiors, don't clear it when we
2776 detach from a single inferior. */
2777 if (!gdbarch_has_global_solist (target_gdbarch ()))
2778 no_shared_libraries (NULL, from_tty);
2780 if (deprecated_detach_hook)
2781 deprecated_detach_hook ();
2783 if (!was_non_stop_p)
2784 restart_after_all_stop_detach (as_process_stratum_target (target_ref.get ()));
2786 disable_commit_resumed.reset_and_commit ();
2789 /* Disconnect from the current target without resuming it (leaving it
2790 waiting for a debugger).
2792 We'd better not have left any breakpoints in the program or the
2793 next debugger will get confused. Currently only supported for some
2794 remote targets, since the normal attach mechanisms don't work on
2795 stopped processes on some native platforms (e.g. GNU/Linux). */
2797 static void
2798 disconnect_command (const char *args, int from_tty)
2800 dont_repeat (); /* Not for the faint of heart. */
2801 query_if_trace_running (from_tty);
2802 disconnect_tracing ();
2803 target_disconnect (args, from_tty);
2804 no_shared_libraries (NULL, from_tty);
2805 init_thread_list ();
2806 if (deprecated_detach_hook)
2807 deprecated_detach_hook ();
2810 /* Stop PTID in the current target, and tag the PTID threads as having
2811 been explicitly requested to stop. PTID can be a thread, a
2812 process, or minus_one_ptid, meaning all threads of all inferiors of
2813 the current target. */
2815 static void
2816 stop_current_target_threads_ns (ptid_t ptid)
2818 target_stop (ptid);
2820 /* Tag the thread as having been explicitly requested to stop, so
2821 other parts of gdb know not to resume this thread automatically,
2822 if it was stopped due to an internal event. Limit this to
2823 non-stop mode, as when debugging a multi-threaded application in
2824 all-stop mode, we will only get one stop event --- it's undefined
2825 which thread will report the event. */
2826 set_stop_requested (current_inferior ()->process_target (),
2827 ptid, 1);
2830 /* See inferior.h. */
2832 void
2833 interrupt_target_1 (bool all_threads)
2835 scoped_disable_commit_resumed disable_commit_resumed ("interrupting");
2837 if (non_stop)
2839 if (all_threads)
2841 scoped_restore_current_thread restore_thread;
2843 for (inferior *inf : all_inferiors ())
2845 switch_to_inferior_no_thread (inf);
2846 stop_current_target_threads_ns (minus_one_ptid);
2849 else
2850 stop_current_target_threads_ns (inferior_ptid);
2852 else
2853 target_interrupt ();
2855 disable_commit_resumed.reset_and_commit ();
2858 /* interrupt [-a]
2859 Stop the execution of the target while running in async mode, in
2860 the background. In all-stop, stop the whole process. In non-stop
2861 mode, stop the current thread only by default, or stop all threads
2862 if the `-a' switch is used. */
2864 static void
2865 interrupt_command (const char *args, int from_tty)
2867 if (target_can_async_p ())
2869 int all_threads = 0;
2871 dont_repeat (); /* Not for the faint of heart. */
2873 if (args != NULL
2874 && startswith (args, "-a"))
2875 all_threads = 1;
2877 if (!non_stop && all_threads)
2878 error (_("-a is meaningless in all-stop mode."));
2880 interrupt_target_1 (all_threads);
2884 /* See inferior.h. */
2886 void
2887 default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2888 struct frame_info *frame, const char *args)
2890 int regnum;
2891 int printed_something = 0;
2893 for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
2895 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2897 printed_something = 1;
2898 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2901 if (!printed_something)
2902 gdb_printf (file, "No floating-point info "
2903 "available for this processor.\n");
2906 static void
2907 info_float_command (const char *args, int from_tty)
2909 struct frame_info *frame;
2911 if (!target_has_registers ())
2912 error (_("The program has no registers now."));
2914 frame = get_selected_frame (NULL);
2915 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
2918 /* Implement `info proc' family of commands. */
2920 static void
2921 info_proc_cmd_1 (const char *args, enum info_proc_what what, int from_tty)
2923 struct gdbarch *gdbarch = get_current_arch ();
2925 if (!target_info_proc (args, what))
2927 if (gdbarch_info_proc_p (gdbarch))
2928 gdbarch_info_proc (gdbarch, args, what);
2929 else
2930 error (_("Not supported on this target."));
2934 /* Implement `info proc' when given without any further parameters. */
2936 static void
2937 info_proc_cmd (const char *args, int from_tty)
2939 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
2942 /* Implement `info proc mappings'. */
2944 static void
2945 info_proc_cmd_mappings (const char *args, int from_tty)
2947 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
2950 /* Implement `info proc stat'. */
2952 static void
2953 info_proc_cmd_stat (const char *args, int from_tty)
2955 info_proc_cmd_1 (args, IP_STAT, from_tty);
2958 /* Implement `info proc status'. */
2960 static void
2961 info_proc_cmd_status (const char *args, int from_tty)
2963 info_proc_cmd_1 (args, IP_STATUS, from_tty);
2966 /* Implement `info proc cwd'. */
2968 static void
2969 info_proc_cmd_cwd (const char *args, int from_tty)
2971 info_proc_cmd_1 (args, IP_CWD, from_tty);
2974 /* Implement `info proc cmdline'. */
2976 static void
2977 info_proc_cmd_cmdline (const char *args, int from_tty)
2979 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
2982 /* Implement `info proc exe'. */
2984 static void
2985 info_proc_cmd_exe (const char *args, int from_tty)
2987 info_proc_cmd_1 (args, IP_EXE, from_tty);
2990 /* Implement `info proc files'. */
2992 static void
2993 info_proc_cmd_files (const char *args, int from_tty)
2995 info_proc_cmd_1 (args, IP_FILES, from_tty);
2998 /* Implement `info proc all'. */
3000 static void
3001 info_proc_cmd_all (const char *args, int from_tty)
3003 info_proc_cmd_1 (args, IP_ALL, from_tty);
3006 /* Implement `show print finish'. */
3008 static void
3009 show_print_finish (struct ui_file *file, int from_tty,
3010 struct cmd_list_element *c,
3011 const char *value)
3013 gdb_printf (file, _("\
3014 Printing of return value after `finish' is %s.\n"),
3015 value);
3019 /* This help string is used for the run, start, and starti commands.
3020 It is defined as a macro to prevent duplication. */
3022 #define RUN_ARGS_HELP \
3023 "You may specify arguments to give it.\n\
3024 Args may include \"*\", or \"[...]\"; they are expanded using the\n\
3025 shell that will start the program (specified by the \"$SHELL\" environment\n\
3026 variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
3027 are also allowed.\n\
3029 With no arguments, uses arguments last specified (with \"run\" or \n\
3030 \"set args\"). To cancel previous arguments and run with no arguments,\n\
3031 use \"set args\" without arguments.\n\
3033 To start the inferior without using a shell, use \"set startup-with-shell off\"."
3035 void _initialize_infcmd ();
3036 void
3037 _initialize_infcmd ()
3039 static struct cmd_list_element *info_proc_cmdlist;
3040 struct cmd_list_element *c = NULL;
3041 const char *cmd_name;
3043 /* Add the filename of the terminal connected to inferior I/O. */
3044 add_setshow_optional_filename_cmd ("inferior-tty", class_run,
3045 &inferior_io_terminal_scratch, _("\
3046 Set terminal for future runs of program being debugged."), _("\
3047 Show terminal for future runs of program being debugged."), _("\
3048 Usage: set inferior-tty [TTY]\n\n\
3049 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
3050 is restored."),
3051 set_inferior_tty_command,
3052 show_inferior_tty_command,
3053 &setlist, &showlist);
3054 cmd_name = "inferior-tty";
3055 c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
3056 gdb_assert (c != NULL);
3057 add_alias_cmd ("tty", c, class_run, 0, &cmdlist);
3059 cmd_name = "args";
3060 add_setshow_string_noescape_cmd (cmd_name, class_run,
3061 &inferior_args_scratch, _("\
3062 Set argument list to give program being debugged when it is started."), _("\
3063 Show argument list to give program being debugged when it is started."), _("\
3064 Follow this command with any number of args, to be passed to the program."),
3065 set_args_command,
3066 show_args_command,
3067 &setlist, &showlist);
3068 c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
3069 gdb_assert (c != NULL);
3070 set_cmd_completer (c, filename_completer);
3072 cmd_name = "cwd";
3073 add_setshow_string_noescape_cmd (cmd_name, class_run,
3074 &inferior_cwd_scratch, _("\
3075 Set the current working directory to be used when the inferior is started.\n\
3076 Changing this setting does not have any effect on inferiors that are\n\
3077 already running."),
3078 _("\
3079 Show the current working directory that is used when the inferior is started."),
3080 _("\
3081 Use this command to change the current working directory that will be used\n\
3082 when the inferior is started. This setting does not affect GDB's current\n\
3083 working directory."),
3084 set_cwd_command,
3085 show_cwd_command,
3086 &setlist, &showlist);
3087 c = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
3088 gdb_assert (c != NULL);
3089 set_cmd_completer (c, filename_completer);
3091 c = add_cmd ("environment", no_class, environment_info, _("\
3092 The environment to give the program, or one variable's value.\n\
3093 With an argument VAR, prints the value of environment variable VAR to\n\
3094 give the program being debugged. With no arguments, prints the entire\n\
3095 environment to be given to the program."), &showlist);
3096 set_cmd_completer (c, noop_completer);
3098 add_basic_prefix_cmd ("unset", no_class,
3099 _("Complement to certain \"set\" commands."),
3100 &unsetlist, 0, &cmdlist);
3102 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3103 Cancel environment variable VAR for the program.\n\
3104 This does not affect the program until the next \"run\" command."),
3105 &unsetlist);
3106 set_cmd_completer (c, noop_completer);
3108 c = add_cmd ("environment", class_run, set_environment_command, _("\
3109 Set environment variable value to give the program.\n\
3110 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3111 VALUES of environment variables are uninterpreted strings.\n\
3112 This does not affect the program until the next \"run\" command."),
3113 &setlist);
3114 set_cmd_completer (c, noop_completer);
3116 c = add_com ("path", class_files, path_command, _("\
3117 Add directory DIR(s) to beginning of search path for object files.\n\
3118 $cwd in the path means the current working directory.\n\
3119 This path is equivalent to the $PATH shell variable. It is a list of\n\
3120 directories, separated by colons. These directories are searched to find\n\
3121 fully linked executable files and separately compiled object files as \
3122 needed."));
3123 set_cmd_completer (c, filename_completer);
3125 c = add_cmd ("paths", no_class, path_info, _("\
3126 Current search path for finding object files.\n\
3127 $cwd in the path means the current working directory.\n\
3128 This path is equivalent to the $PATH shell variable. It is a list of\n\
3129 directories, separated by colons. These directories are searched to find\n\
3130 fully linked executable files and separately compiled object files as \
3131 needed."),
3132 &showlist);
3133 set_cmd_completer (c, noop_completer);
3135 add_prefix_cmd ("kill", class_run, kill_command,
3136 _("Kill execution of program being debugged."),
3137 &killlist, 0, &cmdlist);
3139 add_com ("attach", class_run, attach_command, _("\
3140 Attach to a process or file outside of GDB.\n\
3141 This command attaches to another target, of the same type as your last\n\
3142 \"target\" command (\"info files\" will show your target stack).\n\
3143 The command may take as argument a process id or a device file.\n\
3144 For a process id, you must have permission to send the process a signal,\n\
3145 and it must have the same effective uid as the debugger.\n\
3146 When using \"attach\" with a process id, the debugger finds the\n\
3147 program running in the process, looking first in the current working\n\
3148 directory, or (if not found there) using the source file search path\n\
3149 (see the \"directory\" command). You can also use the \"file\" command\n\
3150 to specify the program, and to load its symbol table."));
3152 add_prefix_cmd ("detach", class_run, detach_command, _("\
3153 Detach a process or file previously attached.\n\
3154 If a process, it is no longer traced, and it continues its execution. If\n\
3155 you were debugging a file, the file is closed and gdb no longer accesses it."),
3156 &detachlist, 0, &cmdlist);
3158 add_com ("disconnect", class_run, disconnect_command, _("\
3159 Disconnect from a target.\n\
3160 The target will wait for another debugger to connect. Not available for\n\
3161 all targets."));
3163 c = add_com ("signal", class_run, signal_command, _("\
3164 Continue program with the specified signal.\n\
3165 Usage: signal SIGNAL\n\
3166 The SIGNAL argument is processed the same as the handle command.\n\
3168 An argument of \"0\" means continue the program without sending it a signal.\n\
3169 This is useful in cases where the program stopped because of a signal,\n\
3170 and you want to resume the program while discarding the signal.\n\
3172 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3173 the current thread only."));
3174 set_cmd_completer (c, signal_completer);
3176 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3177 Queue a signal to be delivered to the current thread when it is resumed.\n\
3178 Usage: queue-signal SIGNAL\n\
3179 The SIGNAL argument is processed the same as the handle command.\n\
3180 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3182 An argument of \"0\" means remove any currently queued signal from\n\
3183 the current thread. This is useful in cases where the program stopped\n\
3184 because of a signal, and you want to resume it while discarding the signal.\n\
3186 In a multi-threaded program the signal is queued with, or discarded from,\n\
3187 the current thread only."));
3188 set_cmd_completer (c, signal_completer);
3190 cmd_list_element *stepi_cmd
3191 = add_com ("stepi", class_run, stepi_command, _("\
3192 Step one instruction exactly.\n\
3193 Usage: stepi [N]\n\
3194 Argument N means step N times (or till program stops for another \
3195 reason)."));
3196 add_com_alias ("si", stepi_cmd, class_run, 0);
3198 cmd_list_element *nexti_cmd
3199 = add_com ("nexti", class_run, nexti_command, _("\
3200 Step one instruction, but proceed through subroutine calls.\n\
3201 Usage: nexti [N]\n\
3202 Argument N means step N times (or till program stops for another \
3203 reason)."));
3204 add_com_alias ("ni", nexti_cmd, class_run, 0);
3206 cmd_list_element *finish_cmd
3207 = add_com ("finish", class_run, finish_command, _("\
3208 Execute until selected stack frame returns.\n\
3209 Usage: finish\n\
3210 Upon return, the value returned is printed and put in the value history."));
3211 add_com_alias ("fin", finish_cmd, class_run, 1);
3213 cmd_list_element *next_cmd
3214 = add_com ("next", class_run, next_command, _("\
3215 Step program, proceeding through subroutine calls.\n\
3216 Usage: next [N]\n\
3217 Unlike \"step\", if the current source line calls a subroutine,\n\
3218 this command does not enter the subroutine, but instead steps over\n\
3219 the call, in effect treating it as a single source line."));
3220 add_com_alias ("n", next_cmd, class_run, 1);
3222 cmd_list_element *step_cmd
3223 = add_com ("step", class_run, step_command, _("\
3224 Step program until it reaches a different source line.\n\
3225 Usage: step [N]\n\
3226 Argument N means step N times (or till program stops for another \
3227 reason)."));
3228 add_com_alias ("s", step_cmd, class_run, 1);
3230 cmd_list_element *until_cmd
3231 = add_com ("until", class_run, until_command, _("\
3232 Execute until past the current line or past a LOCATION.\n\
3233 Execute until the program reaches a source line greater than the current\n\
3234 or a specified location (same args as break command) within the current \
3235 frame."));
3236 set_cmd_completer (until_cmd, location_completer);
3237 add_com_alias ("u", until_cmd, class_run, 1);
3239 c = add_com ("advance", class_run, advance_command, _("\
3240 Continue the program up to the given location (same form as args for break \
3241 command).\n\
3242 Execution will also stop upon exit from the current stack frame."));
3243 set_cmd_completer (c, location_completer);
3245 cmd_list_element *jump_cmd
3246 = add_com ("jump", class_run, jump_command, _("\
3247 Continue program being debugged at specified line or address.\n\
3248 Usage: jump LOCATION\n\
3249 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3250 for an address to start at."));
3251 set_cmd_completer (jump_cmd, location_completer);
3252 add_com_alias ("j", jump_cmd, class_run, 1);
3254 cmd_list_element *continue_cmd
3255 = add_com ("continue", class_run, continue_command, _("\
3256 Continue program being debugged, after signal or breakpoint.\n\
3257 Usage: continue [N]\n\
3258 If proceeding from breakpoint, a number N may be used as an argument,\n\
3259 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3260 the breakpoint won't break until the Nth time it is reached).\n\
3262 If non-stop mode is enabled, continue only the current thread,\n\
3263 otherwise all the threads in the program are continued. To \n\
3264 continue all stopped threads in non-stop mode, use the -a option.\n\
3265 Specifying -a and an ignore count simultaneously is an error."));
3266 add_com_alias ("c", continue_cmd, class_run, 1);
3267 add_com_alias ("fg", continue_cmd, class_run, 1);
3269 cmd_list_element *run_cmd
3270 = add_com ("run", class_run, run_command, _("\
3271 Start debugged program.\n"
3272 RUN_ARGS_HELP));
3273 set_cmd_completer (run_cmd, filename_completer);
3274 add_com_alias ("r", run_cmd, class_run, 1);
3276 c = add_com ("start", class_run, start_command, _("\
3277 Start the debugged program stopping at the beginning of the main procedure.\n"
3278 RUN_ARGS_HELP));
3279 set_cmd_completer (c, filename_completer);
3281 c = add_com ("starti", class_run, starti_command, _("\
3282 Start the debugged program stopping at the first instruction.\n"
3283 RUN_ARGS_HELP));
3284 set_cmd_completer (c, filename_completer);
3286 add_com ("interrupt", class_run, interrupt_command,
3287 _("Interrupt the execution of the debugged program.\n\
3288 If non-stop mode is enabled, interrupt only the current thread,\n\
3289 otherwise all the threads in the program are stopped. To \n\
3290 interrupt all running threads in non-stop mode, use the -a option."));
3292 cmd_list_element *info_registers_cmd
3293 = add_info ("registers", info_registers_command, _("\
3294 List of integer registers and their contents, for selected stack frame.\n\
3295 One or more register names as argument means describe the given registers.\n\
3296 One or more register group names as argument means describe the registers\n\
3297 in the named register groups."));
3298 add_info_alias ("r", info_registers_cmd, 1);
3299 set_cmd_completer (info_registers_cmd, reg_or_group_completer);
3301 c = add_info ("all-registers", info_all_registers_command, _("\
3302 List of all registers and their contents, for selected stack frame.\n\
3303 One or more register names as argument means describe the given registers.\n\
3304 One or more register group names as argument means describe the registers\n\
3305 in the named register groups."));
3306 set_cmd_completer (c, reg_or_group_completer);
3308 add_info ("program", info_program_command,
3309 _("Execution status of the program."));
3311 add_info ("float", info_float_command,
3312 _("Print the status of the floating point unit."));
3314 add_info ("vector", info_vector_command,
3315 _("Print the status of the vector unit."));
3317 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3318 _("\
3319 Show additional information about a process.\n\
3320 Specify any process id, or use the program being debugged by default."),
3321 &info_proc_cmdlist,
3322 1/*allow-unknown*/, &infolist);
3324 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3325 List memory regions mapped by the specified process."),
3326 &info_proc_cmdlist);
3328 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3329 List process info from /proc/PID/stat."),
3330 &info_proc_cmdlist);
3332 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3333 List process info from /proc/PID/status."),
3334 &info_proc_cmdlist);
3336 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3337 List current working directory of the specified process."),
3338 &info_proc_cmdlist);
3340 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3341 List command line arguments of the specified process."),
3342 &info_proc_cmdlist);
3344 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3345 List absolute filename for executable of the specified process."),
3346 &info_proc_cmdlist);
3348 add_cmd ("files", class_info, info_proc_cmd_files, _("\
3349 List files opened by the specified process."),
3350 &info_proc_cmdlist);
3352 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3353 List all available info about the specified process."),
3354 &info_proc_cmdlist);
3356 add_setshow_boolean_cmd ("finish", class_support,
3357 &user_print_options.finish_print, _("\
3358 Set whether `finish' prints the return value."), _("\
3359 Show whether `finish' prints the return value."), NULL,
3360 NULL,
3361 show_print_finish,
3362 &setprintlist, &showprintlist);