1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
36 #include "completer.h"
38 #include "event-top.h"
39 #include "parser-defs.h"
41 #include "reggroups.h"
46 #include "target-descriptions.h"
47 #include "user-regs.h"
48 #include "cli/cli-decode.h"
49 #include "gdbthread.h"
51 #include "inline-frame.h"
52 #include "tracepoint.h"
54 #include "continuations.h"
56 #include "cli/cli-utils.h"
58 /* Local functions: */
60 static void nofp_registers_info (char *, int);
62 static void until_next_command (int);
64 static void until_command (char *, int);
66 static void path_info (char *, int);
68 static void path_command (char *, int);
70 static void unset_command (char *, int);
72 static void float_info (char *, int);
74 static void disconnect_command (char *, int);
76 static void unset_environment_command (char *, int);
78 static void set_environment_command (char *, int);
80 static void environment_info (char *, int);
82 static void program_info (char *, int);
84 static void finish_command (char *, int);
86 static void signal_command (char *, int);
88 static void jump_command (char *, int);
90 static void step_1 (int, int, char *);
91 static void step_once (int skip_subroutines, int single_inst,
92 int count, int thread);
94 static void next_command (char *, int);
96 static void step_command (char *, int);
98 static void run_command (char *, int);
100 void _initialize_infcmd (void);
102 #define ERROR_NO_INFERIOR \
103 if (!target_has_execution) error (_("The program is not being run."));
105 /* Scratch area where string containing arguments to give to the
106 program will be stored by 'set args'. As soon as anything is
107 stored, notice_args_set will move it into per-inferior storage.
108 Arguments are separated by spaces. Empty string (pointer to '\0')
111 static char *inferior_args_scratch;
113 /* Scratch area where 'set inferior-tty' will store user-provided value.
114 We'll immediate copy it into per-inferior storage. */
116 static char *inferior_io_terminal_scratch;
118 /* Pid of our debugged inferior, or 0 if no inferior now.
119 Since various parts of infrun.c test this to see whether there is a program
120 being debugged it should be nonzero (currently 3 is used) for remote
123 ptid_t inferior_ptid;
125 /* Address at which inferior stopped. */
129 /* Nonzero if stopped due to completion of a stack dummy routine. */
131 enum stop_stack_kind stop_stack_dummy;
133 /* Nonzero if stopped due to a random (unexpected) signal in inferior
136 int stopped_by_random_signal;
138 /* See inferior.h. */
140 int startup_with_shell = 1;
143 /* Accessor routines. */
145 /* Set the io terminal for the current inferior. Ownership of
146 TERMINAL_NAME is not transferred. */
149 set_inferior_io_terminal (const char *terminal_name)
151 xfree (current_inferior ()->terminal);
152 current_inferior ()->terminal = terminal_name ? xstrdup (terminal_name) : 0;
156 get_inferior_io_terminal (void)
158 return current_inferior ()->terminal;
162 set_inferior_tty_command (char *args, int from_tty,
163 struct cmd_list_element *c)
165 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
166 Now route it to current inferior. */
167 set_inferior_io_terminal (inferior_io_terminal_scratch);
171 show_inferior_tty_command (struct ui_file *file, int from_tty,
172 struct cmd_list_element *c, const char *value)
174 /* Note that we ignore the passed-in value in favor of computing it
176 const char *inferior_io_terminal = get_inferior_io_terminal ();
178 if (inferior_io_terminal == NULL)
179 inferior_io_terminal = "";
180 fprintf_filtered (gdb_stdout,
181 _("Terminal for future runs of program being debugged "
182 "is \"%s\".\n"), inferior_io_terminal);
186 get_inferior_args (void)
188 if (current_inferior ()->argc != 0)
192 n = construct_inferior_arguments (current_inferior ()->argc,
193 current_inferior ()->argv);
194 set_inferior_args (n);
198 if (current_inferior ()->args == NULL)
199 current_inferior ()->args = xstrdup ("");
201 return current_inferior ()->args;
204 /* Set the arguments for the current inferior. Ownership of
205 NEWARGS is not transferred. */
208 set_inferior_args (char *newargs)
210 xfree (current_inferior ()->args);
211 current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
212 current_inferior ()->argc = 0;
213 current_inferior ()->argv = 0;
217 set_inferior_args_vector (int argc, char **argv)
219 current_inferior ()->argc = argc;
220 current_inferior ()->argv = argv;
223 /* Notice when `set args' is run. */
226 set_args_command (char *args, int from_tty, struct cmd_list_element *c)
228 /* CLI has assigned the user-provided value to inferior_args_scratch.
229 Now route it to current inferior. */
230 set_inferior_args (inferior_args_scratch);
233 /* Notice when `show args' is run. */
236 show_args_command (struct ui_file *file, int from_tty,
237 struct cmd_list_element *c, const char *value)
239 /* Note that we ignore the passed-in value in favor of computing it
241 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
245 /* Compute command-line string given argument vector. This does the
246 same shell processing as fork_inferior. */
249 construct_inferior_arguments (int argc, char **argv)
253 if (startup_with_shell)
256 /* This holds all the characters considered special to the
258 char *special = "\"!&*|[]{}<>?`~^=;, \t\n";
259 const char quote = '"';
261 /* This holds all the characters considered special to the
262 typical Unix shells. We include `^' because the SunOS
263 /bin/sh treats it as a synonym for `|'. */
264 char *special = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
265 const char quote = '\'';
271 /* We over-compute the size. It shouldn't matter. */
272 for (i = 0; i < argc; ++i)
273 length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
275 result = (char *) xmalloc (length);
278 for (i = 0; i < argc; ++i)
283 /* Need to handle empty arguments specially. */
284 if (argv[i][0] == '\0')
294 if (strpbrk (argv[i], special))
300 for (cp = argv[i]; *cp; ++cp)
304 /* A newline cannot be quoted with a backslash (it
305 just disappears), only by putting it inside
316 if (strchr (special, *cp) != NULL)
332 /* In this case we can't handle arguments that contain spaces,
333 tabs, or newlines -- see breakup_args(). */
337 for (i = 0; i < argc; ++i)
339 char *cp = strchr (argv[i], ' ');
341 cp = strchr (argv[i], '\t');
343 cp = strchr (argv[i], '\n');
345 error (_("can't handle command-line "
346 "argument containing whitespace"));
347 length += strlen (argv[i]) + 1;
350 result = (char *) xmalloc (length);
352 for (i = 0; i < argc; ++i)
355 strcat (result, " ");
356 strcat (result, argv[i]);
364 /* This function strips the '&' character (indicating background
365 execution) that is added as *the last* of the arguments ARGS of a
366 command. A copy of the incoming ARGS without the '&' is returned,
367 unless the resulting string after stripping is empty, in which case
368 NULL is returned. *BG_CHAR_P is an output boolean that indicates
369 whether the '&' character was found. */
372 strip_bg_char (const char *args, int *bg_char_p)
376 if (args == NULL || *args == '\0')
382 p = args + strlen (args);
386 while (p > args && isspace (p[-1]))
391 return savestring (args, p - args);
397 return xstrdup (args);
400 /* Common actions to take after creating any sort of inferior, by any
401 means (running, attaching, connecting, et cetera). The target
402 should be stopped. */
405 post_create_inferior (struct target_ops *target, int from_tty)
408 /* Be sure we own the terminal in case write operations are performed. */
409 target_terminal_ours ();
411 /* If the target hasn't taken care of this already, do it now.
412 Targets which need to access registers during to_open,
413 to_create_inferior, or to_attach should do it earlier; but many
415 target_find_description ();
417 /* Now that we know the register layout, retrieve current PC. But
418 if the PC is unavailable (e.g., we're opening a core file with
419 missing registers info), ignore it. */
423 stop_pc = regcache_read_pc (get_current_regcache ());
425 CATCH (ex, RETURN_MASK_ERROR)
427 if (ex.error != NOT_AVAILABLE_ERROR)
428 throw_exception (ex);
434 const unsigned solib_add_generation
435 = current_program_space->solib_add_generation;
437 /* Create the hooks to handle shared library load and unload
439 solib_create_inferior_hook (from_tty);
441 if (current_program_space->solib_add_generation == solib_add_generation)
443 /* The platform-specific hook should load initial shared libraries,
444 but didn't. FROM_TTY will be incorrectly 0 but such solib
445 targets should be fixed anyway. Call it only after the solib
446 target has been initialized by solib_create_inferior_hook. */
449 warning (_("platform-specific solib_create_inferior_hook did "
450 "not load initial shared libraries."));
452 /* If the solist is global across processes, there's no need to
454 if (!gdbarch_has_global_solist (target_gdbarch ()))
455 solib_add (NULL, 0, target, auto_solib_add);
459 /* If the user sets watchpoints before execution having started,
460 then she gets software watchpoints, because GDB can't know which
461 target will end up being pushed, or if it supports hardware
462 watchpoints or not. breakpoint_re_set takes care of promoting
463 watchpoints to hardware watchpoints if possible, however, if this
464 new inferior doesn't load shared libraries or we don't pull in
465 symbols from any other source on this target/arch,
466 breakpoint_re_set is never called. Call it now so that software
467 watchpoints get a chance to be promoted to hardware watchpoints
468 if the now pushed target supports hardware watchpoints. */
469 breakpoint_re_set ();
471 observer_notify_inferior_created (target, from_tty);
474 /* Kill the inferior if already running. This function is designed
475 to be called when we are about to start the execution of the program
476 from the beginning. Ask the user to confirm that he wants to restart
477 the program being debugged when FROM_TTY is non-null. */
480 kill_if_already_running (int from_tty)
482 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
484 /* Bail out before killing the program if we will not be able to
486 target_require_runnable ();
489 && !query (_("The program being debugged has been started already.\n\
490 Start it from the beginning? ")))
491 error (_("Program not restarted."));
496 /* See inferior.h. */
499 prepare_execution_command (struct target_ops *target, int background)
501 /* If we get a request for running in the bg but the target
502 doesn't support it, error out. */
503 if (background && !target->to_can_async_p (target))
504 error (_("Asynchronous execution not supported on this target."));
506 /* If we don't get a request of running in the bg, then we need
507 to simulate synchronous (fg) execution. */
508 if (!background && target->to_can_async_p (target))
510 /* Simulate synchronous execution. Note no cleanup is necessary
511 for this. stdin is re-enabled whenever an error reaches the
513 async_disable_stdin ();
517 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
518 a temporary breakpoint at the begining of the main program before
519 running the program. */
522 run_command_1 (char *args, int from_tty, int tbreak_at_main)
525 struct cleanup *old_chain;
527 struct ui_out *uiout = current_uiout;
528 struct target_ops *run_target;
530 struct cleanup *args_chain;
534 kill_if_already_running (from_tty);
536 init_wait_for_inferior ();
537 clear_breakpoint_hit_counts ();
539 /* Clean up any leftovers from other runs. Some other things from
540 this function should probably be moved into target_pre_inferior. */
541 target_pre_inferior (from_tty);
543 /* The comment here used to read, "The exec file is re-read every
544 time we do a generic_mourn_inferior, so we just have to worry
545 about the symbol file." The `generic_mourn_inferior' function
546 gets called whenever the program exits. However, suppose the
547 program exits, and *then* the executable file changes? We need
548 to check again here. Since reopen_exec_file doesn't do anything
549 if the timestamp hasn't changed, I don't see the harm. */
553 args = strip_bg_char (args, &async_exec);
554 args_chain = make_cleanup (xfree, args);
556 /* Do validation and preparation before possibly changing anything
559 run_target = find_run_target ();
561 prepare_execution_command (run_target, async_exec);
563 if (non_stop && !run_target->to_supports_non_stop (run_target))
564 error (_("The target does not support running in non-stop mode."));
566 /* Done. Can now set breakpoints, change inferior args, etc. */
568 /* Insert the temporary breakpoint if a location was specified. */
570 tbreak_command (main_name (), 0);
572 exec_file = (char *) get_exec_file (0);
574 /* We keep symbols from add-symbol-file, on the grounds that the
575 user might want to add some symbols before running the program
576 (right?). But sometimes (dynamic loading where the user manually
577 introduces the new symbols with add-symbol-file), the code which
578 the symbols describe does not persist between runs. Currently
579 the user has to manually nuke all symbols between runs if they
580 want them to go away (PR 2207). This is probably reasonable. */
582 /* If there were other args, beside '&', process them. */
584 set_inferior_args (args);
588 ui_out_field_string (uiout, NULL, "Starting program");
589 ui_out_text (uiout, ": ");
591 ui_out_field_string (uiout, "execfile", exec_file);
592 ui_out_spaces (uiout, 1);
593 /* We call get_inferior_args() because we might need to compute
595 ui_out_field_string (uiout, "infargs", get_inferior_args ());
596 ui_out_text (uiout, "\n");
597 ui_out_flush (uiout);
600 /* Done with ARGS. */
601 do_cleanups (args_chain);
603 /* We call get_inferior_args() because we might need to compute
605 run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
606 environ_vector (current_inferior ()->environment),
608 /* to_create_inferior should push the target, so after this point we
609 shouldn't refer to run_target again. */
612 /* We're starting off a new process. When we get out of here, in
613 non-stop mode, finish the state of all threads of that process,
614 but leave other threads alone, as they may be stopped in internal
615 events --- the frontend shouldn't see them as stopped. In
616 all-stop, always finish the state of all threads, as we may be
617 resuming more than just the new process. */
619 ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
621 ptid = minus_one_ptid;
622 old_chain = make_cleanup (finish_thread_state_cleanup, &ptid);
624 /* Pass zero for FROM_TTY, because at this point the "run" command
625 has done its thing; now we are setting up the running program. */
626 post_create_inferior (¤t_target, 0);
628 /* Start the target running. Do not use -1 continuation as it would skip
629 breakpoint right at the entry point. */
630 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
632 /* Since there was no error, there's no need to finish the thread
634 discard_cleanups (old_chain);
638 run_command (char *args, int from_tty)
640 run_command_1 (args, from_tty, 0);
643 /* Start the execution of the program up until the beginning of the main
647 start_command (char *args, int from_tty)
649 /* Some languages such as Ada need to search inside the program
650 minimal symbols for the location where to put the temporary
651 breakpoint before starting. */
652 if (!have_minimal_symbols ())
653 error (_("No symbol table loaded. Use the \"file\" command."));
655 /* Run the program until reaching the main procedure... */
656 run_command_1 (args, from_tty, 1);
660 proceed_thread_callback (struct thread_info *thread, void *arg)
662 /* We go through all threads individually instead of compressing
663 into a single target `resume_all' request, because some threads
664 may be stopped in internal breakpoints/events, or stopped waiting
665 for its turn in the displaced stepping queue (that is, they are
666 running && !executing). The target side has no idea about why
667 the thread is stopped, so a `resume_all' command would resume too
668 much. If/when GDB gains a way to tell the target `hold this
669 thread stopped until I say otherwise', then we can optimize
671 if (!is_stopped (thread->ptid))
674 switch_to_thread (thread->ptid);
675 clear_proceed_status (0);
676 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
681 ensure_valid_thread (void)
683 if (ptid_equal (inferior_ptid, null_ptid)
684 || is_exited (inferior_ptid))
685 error (_("Cannot execute this command without a live selected thread."));
688 /* If the user is looking at trace frames, any resumption of execution
689 is likely to mix up recorded and live target data. So simply
690 disallow those commands. */
693 ensure_not_tfind_mode (void)
695 if (get_traceframe_number () >= 0)
696 error (_("Cannot execute this command while looking at trace frames."));
699 /* Throw an error indicating the current thread is running. */
702 error_is_running (void)
704 error (_("Cannot execute this command while "
705 "the selected thread is running."));
708 /* Calls error_is_running if the current thread is running. */
711 ensure_not_running (void)
713 if (is_running (inferior_ptid))
718 continue_1 (int all_threads)
721 ensure_not_tfind_mode ();
723 if (non_stop && all_threads)
725 /* Don't error out if the current thread is running, because
726 there may be other stopped threads. */
727 struct cleanup *old_chain;
729 /* Backup current thread and selected frame. */
730 old_chain = make_cleanup_restore_current_thread ();
732 iterate_over_threads (proceed_thread_callback, NULL);
736 /* If all threads in the target were already running,
737 proceed_thread_callback ends up never calling proceed,
738 and so nothing calls this to put the inferior's terminal
739 settings in effect and remove stdin from the event loop,
740 which we must when running a foreground command. E.g.:
744 <all threads are running now>
747 <no thread was resumed, but the inferior now owns the terminal>
749 target_terminal_inferior ();
752 /* Restore selected ptid. */
753 do_cleanups (old_chain);
757 ensure_valid_thread ();
758 ensure_not_running ();
759 clear_proceed_status (0);
760 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
764 /* continue [-a] [proceed-count] [&] */
767 continue_command (char *args, int from_tty)
771 struct cleanup *args_chain;
775 /* Find out whether we must run in the background. */
776 args = strip_bg_char (args, &async_exec);
777 args_chain = make_cleanup (xfree, args);
779 prepare_execution_command (¤t_target, async_exec);
783 if (startswith (args, "-a"))
786 args += sizeof ("-a") - 1;
792 if (!non_stop && all_threads)
793 error (_("`-a' is meaningless in all-stop mode."));
795 if (args != NULL && all_threads)
796 error (_("Can't resume all threads and specify "
797 "proceed count simultaneously."));
799 /* If we have an argument left, set proceed count of breakpoint we
806 struct thread_info *tp;
809 tp = find_thread_ptid (inferior_ptid);
813 struct target_waitstatus ws;
815 get_last_target_status (&last_ptid, &ws);
816 tp = find_thread_ptid (last_ptid);
819 bs = tp->control.stop_bpstat;
821 while ((stat = bpstat_num (&bs, &num)) != 0)
824 set_ignore_count (num,
825 parse_and_eval_long (args) - 1,
827 /* set_ignore_count prints a message ending with a period.
828 So print two spaces before "Continuing.". */
830 printf_filtered (" ");
834 if (!stopped && from_tty)
837 ("Not stopped at any breakpoint; argument ignored.\n");
841 /* Done with ARGS. */
842 do_cleanups (args_chain);
845 printf_filtered (_("Continuing.\n"));
847 continue_1 (all_threads);
850 /* Record the starting point of a "step" or "next" command. */
853 set_step_frame (void)
855 struct symtab_and_line sal;
857 struct frame_info *frame = get_current_frame ();
858 struct thread_info *tp = inferior_thread ();
860 find_frame_sal (frame, &sal);
861 set_step_info (frame, sal);
862 pc = get_frame_pc (frame);
863 tp->control.step_start_function = find_pc_function (pc);
866 /* Step until outside of current statement. */
869 step_command (char *count_string, int from_tty)
871 step_1 (0, 0, count_string);
874 /* Likewise, but skip over subroutine calls as if single instructions. */
877 next_command (char *count_string, int from_tty)
879 step_1 (1, 0, count_string);
882 /* Likewise, but step only one instruction. */
885 stepi_command (char *count_string, int from_tty)
887 step_1 (0, 1, count_string);
891 nexti_command (char *count_string, int from_tty)
893 step_1 (1, 1, count_string);
897 delete_longjmp_breakpoint_cleanup (void *arg)
899 int thread = * (int *) arg;
900 delete_longjmp_breakpoint (thread);
904 step_1 (int skip_subroutines, int single_inst, char *count_string)
907 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
910 struct cleanup *args_chain;
913 ensure_not_tfind_mode ();
914 ensure_valid_thread ();
915 ensure_not_running ();
917 count_string = strip_bg_char (count_string, &async_exec);
918 args_chain = make_cleanup (xfree, count_string);
920 prepare_execution_command (¤t_target, async_exec);
922 count = count_string ? parse_and_eval_long (count_string) : 1;
924 /* Done with ARGS. */
925 do_cleanups (args_chain);
927 if (!single_inst || skip_subroutines) /* Leave si command alone. */
929 struct thread_info *tp = inferior_thread ();
931 if (in_thread_list (inferior_ptid))
932 thread = pid_to_thread_id (inferior_ptid);
934 set_longjmp_breakpoint (tp, get_frame_id (get_current_frame ()));
936 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
939 /* In synchronous case, all is well; each step_once call will step once. */
940 if (!target_can_async_p ())
942 for (; count > 0; count--)
944 step_once (skip_subroutines, single_inst, count, thread);
946 if (!target_has_execution)
950 struct thread_info *tp = inferior_thread ();
952 if (!tp->control.stop_step || !tp->step_multi)
954 /* If we stopped for some reason that is not stepping
955 there are no further steps to make. */
962 do_cleanups (cleanups);
966 /* In the case of an asynchronous target things get complicated;
967 do only one step for now, before returning control to the
968 event loop. Let the continuation figure out how many other
969 steps we need to do, and handle them one at the time, through
971 step_once (skip_subroutines, single_inst, count, thread);
973 /* We are running, and the continuation is installed. It will
974 disable the longjmp breakpoint as appropriate. */
975 discard_cleanups (cleanups);
979 struct step_1_continuation_args
982 int skip_subroutines;
987 /* Called after we are done with one step operation, to check whether
988 we need to step again, before we print the prompt and return control
989 to the user. If count is > 1, we will need to do one more call to
990 proceed(), via step_once(). Basically it is like step_once and
991 step_1_continuation are co-recursive. */
994 step_1_continuation (void *args, int err)
996 struct step_1_continuation_args *a = args;
998 if (target_has_execution)
1000 struct thread_info *tp;
1002 tp = inferior_thread ();
1004 && tp->step_multi && tp->control.stop_step)
1006 /* There are more steps to make, and we did stop due to
1007 ending a stepping range. Do another step. */
1008 step_once (a->skip_subroutines, a->single_inst,
1009 a->count - 1, a->thread);
1015 /* We either hit an error, or stopped for some reason that is
1016 not stepping, or there are no further steps to make.
1018 if (!a->single_inst || a->skip_subroutines)
1019 delete_longjmp_breakpoint (a->thread);
1022 /* Do just one step operation. This is useful to implement the 'step
1023 n' kind of commands. In case of asynchronous targets, we will have
1024 to set up a continuation to be done after the target stops (after
1025 this one step). For synch targets, the caller handles further
1029 step_once (int skip_subroutines, int single_inst, int count, int thread)
1031 struct frame_info *frame = get_current_frame ();
1035 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1036 the longjmp breakpoint was not required. Use the
1037 INFERIOR_PTID thread instead, which is the same thread when
1039 struct thread_info *tp = inferior_thread ();
1041 clear_proceed_status (1);
1048 /* Step at an inlined function behaves like "down". */
1049 if (!skip_subroutines
1050 && inline_skipped_frames (inferior_ptid))
1054 /* Pretend that we've ran. */
1055 resume_ptid = user_visible_resume_ptid (1);
1056 set_running (resume_ptid, 1);
1058 step_into_inline_frame (inferior_ptid);
1060 step_once (skip_subroutines, single_inst, count - 1, thread);
1063 /* Pretend that we've stopped. */
1066 if (target_can_async_p ())
1067 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1072 pc = get_frame_pc (frame);
1073 find_pc_line_pc_range (pc,
1074 &tp->control.step_range_start,
1075 &tp->control.step_range_end);
1077 tp->control.may_range_step = 1;
1079 /* If we have no line info, switch to stepi mode. */
1080 if (tp->control.step_range_end == 0 && step_stop_if_no_debug)
1082 tp->control.step_range_start = tp->control.step_range_end = 1;
1083 tp->control.may_range_step = 0;
1085 else if (tp->control.step_range_end == 0)
1089 if (find_pc_partial_function (pc, &name,
1090 &tp->control.step_range_start,
1091 &tp->control.step_range_end) == 0)
1092 error (_("Cannot find bounds of current function"));
1094 target_terminal_ours ();
1095 printf_filtered (_("Single stepping until exit from function %s,"
1096 "\nwhich has no line number information.\n"),
1102 /* Say we are stepping, but stop after one insn whatever it does. */
1103 tp->control.step_range_start = tp->control.step_range_end = 1;
1104 if (!skip_subroutines)
1106 Don't step over function calls, not even to functions lacking
1108 tp->control.step_over_calls = STEP_OVER_NONE;
1111 if (skip_subroutines)
1112 tp->control.step_over_calls = STEP_OVER_ALL;
1114 tp->step_multi = (count > 1);
1115 tp->control.stepping_command = 1;
1116 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1118 /* For async targets, register a continuation to do any
1119 additional steps. For sync targets, the caller will handle
1120 further stepping. */
1121 if (target_can_async_p ())
1123 struct step_1_continuation_args *args;
1125 args = xmalloc (sizeof (*args));
1126 args->skip_subroutines = skip_subroutines;
1127 args->single_inst = single_inst;
1128 args->count = count;
1129 args->thread = thread;
1131 add_intermediate_continuation (tp, step_1_continuation, args, xfree);
1137 /* Continue program at specified address. */
1140 jump_command (char *arg, int from_tty)
1142 struct gdbarch *gdbarch = get_current_arch ();
1144 struct symtabs_and_lines sals;
1145 struct symtab_and_line sal;
1149 struct cleanup *args_chain;
1152 ensure_not_tfind_mode ();
1153 ensure_valid_thread ();
1154 ensure_not_running ();
1156 /* Find out whether we must run in the background. */
1157 arg = strip_bg_char (arg, &async_exec);
1158 args_chain = make_cleanup (xfree, arg);
1160 prepare_execution_command (¤t_target, async_exec);
1163 error_no_arg (_("starting address"));
1165 sals = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
1166 if (sals.nelts != 1)
1168 error (_("Unreasonable jump request"));
1174 /* Done with ARGS. */
1175 do_cleanups (args_chain);
1177 if (sal.symtab == 0 && sal.pc == 0)
1178 error (_("No source file has been specified."));
1180 resolve_sal_pc (&sal); /* May error out. */
1182 /* See if we are trying to jump to another function. */
1183 fn = get_frame_function (get_current_frame ());
1184 sfn = find_pc_function (sal.pc);
1185 if (fn != NULL && sfn != fn)
1187 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal.line,
1188 SYMBOL_PRINT_NAME (fn)))
1190 error (_("Not confirmed."));
1197 struct obj_section *section;
1199 fixup_symbol_section (sfn, 0);
1200 section = SYMBOL_OBJ_SECTION (symbol_objfile (sfn), sfn);
1201 if (section_is_overlay (section)
1202 && !section_is_mapped (section))
1204 if (!query (_("WARNING!!! Destination is in "
1205 "unmapped overlay! Jump anyway? ")))
1207 error (_("Not confirmed."));
1217 printf_filtered (_("Continuing at "));
1218 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
1219 printf_filtered (".\n");
1222 clear_proceed_status (0);
1223 proceed (addr, GDB_SIGNAL_0);
1226 /* Continue program giving it specified signal. */
1229 signal_command (char *signum_exp, int from_tty)
1231 enum gdb_signal oursig;
1233 struct cleanup *args_chain;
1235 dont_repeat (); /* Too dangerous. */
1237 ensure_not_tfind_mode ();
1238 ensure_valid_thread ();
1239 ensure_not_running ();
1241 /* Find out whether we must run in the background. */
1242 signum_exp = strip_bg_char (signum_exp, &async_exec);
1243 args_chain = make_cleanup (xfree, signum_exp);
1245 prepare_execution_command (¤t_target, async_exec);
1248 error_no_arg (_("signal number"));
1250 /* It would be even slicker to make signal names be valid expressions,
1251 (the type could be "enum $signal" or some such), then the user could
1252 assign them to convenience variables. */
1253 oursig = gdb_signal_from_name (signum_exp);
1255 if (oursig == GDB_SIGNAL_UNKNOWN)
1257 /* No, try numeric. */
1258 int num = parse_and_eval_long (signum_exp);
1261 oursig = GDB_SIGNAL_0;
1263 oursig = gdb_signal_from_command (num);
1266 /* Look for threads other than the current that this command ends up
1267 resuming too (due to schedlock off), and warn if they'll get a
1268 signal delivered. "signal 0" is used to suppress a previous
1269 signal, but if the current thread is no longer the one that got
1270 the signal, then the user is potentially suppressing the signal
1271 of the wrong thread. */
1274 struct thread_info *tp;
1276 int must_confirm = 0;
1278 /* This indicates what will be resumed. Either a single thread,
1279 a whole process, or all threads of all processes. */
1280 resume_ptid = user_visible_resume_ptid (0);
1282 ALL_NON_EXITED_THREADS (tp)
1284 if (ptid_equal (tp->ptid, inferior_ptid))
1286 if (!ptid_match (tp->ptid, resume_ptid))
1289 if (tp->suspend.stop_signal != GDB_SIGNAL_0
1290 && signal_pass_state (tp->suspend.stop_signal))
1293 printf_unfiltered (_("Note:\n"));
1294 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1296 gdb_signal_to_name (tp->suspend.stop_signal),
1297 gdb_signal_to_string (tp->suspend.stop_signal));
1303 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1304 "still deliver the signals noted above to their respective threads.\n"
1305 "Continue anyway? "),
1306 inferior_thread ()->num))
1307 error (_("Not confirmed."));
1312 if (oursig == GDB_SIGNAL_0)
1313 printf_filtered (_("Continuing with no signal.\n"));
1315 printf_filtered (_("Continuing with signal %s.\n"),
1316 gdb_signal_to_name (oursig));
1319 clear_proceed_status (0);
1320 proceed ((CORE_ADDR) -1, oursig);
1323 /* Queue a signal to be delivered to the current thread. */
1326 queue_signal_command (char *signum_exp, int from_tty)
1328 enum gdb_signal oursig;
1329 struct thread_info *tp;
1332 ensure_not_tfind_mode ();
1333 ensure_valid_thread ();
1334 ensure_not_running ();
1336 if (signum_exp == NULL)
1337 error_no_arg (_("signal number"));
1339 /* It would be even slicker to make signal names be valid expressions,
1340 (the type could be "enum $signal" or some such), then the user could
1341 assign them to convenience variables. */
1342 oursig = gdb_signal_from_name (signum_exp);
1344 if (oursig == GDB_SIGNAL_UNKNOWN)
1346 /* No, try numeric. */
1347 int num = parse_and_eval_long (signum_exp);
1350 oursig = GDB_SIGNAL_0;
1352 oursig = gdb_signal_from_command (num);
1355 if (oursig != GDB_SIGNAL_0
1356 && !signal_pass_state (oursig))
1357 error (_("Signal handling set to not pass this signal to the program."));
1359 tp = inferior_thread ();
1360 tp->suspend.stop_signal = oursig;
1363 /* Continuation args to be passed to the "until" command
1365 struct until_next_continuation_args
1367 /* The thread that was current when the command was executed. */
1371 /* A continuation callback for until_next_command. */
1374 until_next_continuation (void *arg, int err)
1376 struct until_next_continuation_args *a = arg;
1378 delete_longjmp_breakpoint (a->thread);
1381 /* Proceed until we reach a different source line with pc greater than
1382 our current one or exit the function. We skip calls in both cases.
1384 Note that eventually this command should probably be changed so
1385 that only source lines are printed out when we hit the breakpoint
1386 we set. This may involve changes to wait_for_inferior and the
1387 proceed status code. */
1390 until_next_command (int from_tty)
1392 struct frame_info *frame;
1394 struct symbol *func;
1395 struct symtab_and_line sal;
1396 struct thread_info *tp = inferior_thread ();
1397 int thread = tp->num;
1398 struct cleanup *old_chain;
1400 clear_proceed_status (0);
1403 frame = get_current_frame ();
1405 /* Step until either exited from this function or greater
1406 than the current line (if in symbolic section) or pc (if
1409 pc = get_frame_pc (frame);
1410 func = find_pc_function (pc);
1414 struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
1416 if (msymbol.minsym == NULL)
1417 error (_("Execution is not within a known function."));
1419 tp->control.step_range_start = BMSYMBOL_VALUE_ADDRESS (msymbol);
1420 /* The upper-bound of step_range is exclusive. In order to make PC
1421 within the range, set the step_range_end with PC + 1. */
1422 tp->control.step_range_end = pc + 1;
1426 sal = find_pc_line (pc, 0);
1428 tp->control.step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1429 tp->control.step_range_end = sal.end;
1431 tp->control.may_range_step = 1;
1433 tp->control.step_over_calls = STEP_OVER_ALL;
1435 tp->step_multi = 0; /* Only one call to proceed */
1437 set_longjmp_breakpoint (tp, get_frame_id (frame));
1438 old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1440 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1442 if (target_can_async_p () && is_running (inferior_ptid))
1444 struct until_next_continuation_args *cont_args;
1446 discard_cleanups (old_chain);
1447 cont_args = XNEW (struct until_next_continuation_args);
1448 cont_args->thread = inferior_thread ()->num;
1450 add_continuation (tp, until_next_continuation, cont_args, xfree);
1453 do_cleanups (old_chain);
1457 until_command (char *arg, int from_tty)
1460 struct cleanup *args_chain;
1463 ensure_not_tfind_mode ();
1464 ensure_valid_thread ();
1465 ensure_not_running ();
1467 /* Find out whether we must run in the background. */
1468 arg = strip_bg_char (arg, &async_exec);
1469 args_chain = make_cleanup (xfree, arg);
1471 prepare_execution_command (¤t_target, async_exec);
1474 until_break_command (arg, from_tty, 0);
1476 until_next_command (from_tty);
1478 /* Done with ARGS. */
1479 do_cleanups (args_chain);
1483 advance_command (char *arg, int from_tty)
1486 struct cleanup *args_chain;
1489 ensure_not_tfind_mode ();
1490 ensure_valid_thread ();
1491 ensure_not_running ();
1494 error_no_arg (_("a location"));
1496 /* Find out whether we must run in the background. */
1497 arg = strip_bg_char (arg, &async_exec);
1498 args_chain = make_cleanup (xfree, arg);
1500 prepare_execution_command (¤t_target, async_exec);
1502 until_break_command (arg, from_tty, 1);
1504 /* Done with ARGS. */
1505 do_cleanups (args_chain);
1508 /* Return the value of the result of a function at the end of a 'finish'
1512 get_return_value (struct value *function, struct type *value_type)
1514 struct regcache *stop_regs = stop_registers;
1515 struct gdbarch *gdbarch;
1516 struct value *value;
1517 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1519 /* If stop_registers were not saved, use the current registers. */
1522 stop_regs = regcache_dup (get_current_regcache ());
1523 make_cleanup_regcache_xfree (stop_regs);
1526 gdbarch = get_regcache_arch (stop_regs);
1528 CHECK_TYPEDEF (value_type);
1529 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1531 /* FIXME: 2003-09-27: When returning from a nested inferior function
1532 call, it's possible (with no help from the architecture vector)
1533 to locate and return/print a "struct return" value. This is just
1534 a more complicated case of what is already being done in the
1535 inferior function call code. In fact, when inferior function
1536 calls are made async, this will likely be made the norm. */
1538 switch (gdbarch_return_value (gdbarch, function, value_type,
1541 case RETURN_VALUE_REGISTER_CONVENTION:
1542 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1543 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1544 value = allocate_value (value_type);
1545 gdbarch_return_value (gdbarch, function, value_type, stop_regs,
1546 value_contents_raw (value), NULL);
1548 case RETURN_VALUE_STRUCT_CONVENTION:
1552 internal_error (__FILE__, __LINE__, _("bad switch"));
1555 do_cleanups (cleanup);
1560 /* Print the result of a function at the end of a 'finish' command. */
1563 print_return_value (struct value *function, struct type *value_type)
1565 struct value *value = get_return_value (function, value_type);
1566 struct ui_out *uiout = current_uiout;
1570 struct value_print_options opts;
1571 struct ui_file *stb;
1572 struct cleanup *old_chain;
1575 stb = mem_fileopen ();
1576 old_chain = make_cleanup_ui_file_delete (stb);
1577 ui_out_text (uiout, "Value returned is ");
1578 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1579 record_latest_value (value));
1580 ui_out_text (uiout, " = ");
1581 get_no_prettyformat_print_options (&opts);
1582 value_print (value, stb, &opts);
1583 ui_out_field_stream (uiout, "return-value", stb);
1584 ui_out_text (uiout, "\n");
1585 do_cleanups (old_chain);
1589 struct cleanup *oldchain;
1592 type_name = type_to_string (value_type);
1593 oldchain = make_cleanup (xfree, type_name);
1594 ui_out_text (uiout, "Value returned has type: ");
1595 ui_out_field_string (uiout, "return-type", type_name);
1596 ui_out_text (uiout, ".");
1597 ui_out_text (uiout, " Cannot determine contents\n");
1598 do_cleanups (oldchain);
1602 /* Stuff that needs to be done by the finish command after the target
1603 has stopped. In asynchronous mode, we wait for the target to stop
1604 in the call to poll or select in the event loop, so it is
1605 impossible to do all the stuff as part of the finish_command
1606 function itself. The only chance we have to complete this command
1607 is in fetch_inferior_event, which is called by the event loop as
1608 soon as it detects that the target has stopped. */
1610 struct finish_command_continuation_args
1612 /* The thread that as current when the command was executed. */
1614 struct breakpoint *breakpoint;
1615 struct symbol *function;
1619 finish_command_continuation (void *arg, int err)
1621 struct finish_command_continuation_args *a = arg;
1625 struct thread_info *tp = NULL;
1628 if (!ptid_equal (inferior_ptid, null_ptid)
1629 && target_has_execution
1630 && is_stopped (inferior_ptid))
1632 tp = inferior_thread ();
1633 bs = tp->control.stop_bpstat;
1636 if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
1637 && a->function != NULL)
1639 struct type *value_type;
1641 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1643 internal_error (__FILE__, __LINE__,
1644 _("finish_command: function has no target type"));
1646 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1650 func = read_var_value (a->function, get_current_frame ());
1653 /* print_return_value can throw an exception in some
1654 circumstances. We need to catch this so that we still
1655 delete the breakpoint. */
1656 print_return_value (func, value_type);
1658 CATCH (ex, RETURN_MASK_ALL)
1660 exception_print (gdb_stdout, ex);
1666 /* We suppress normal call of normal_stop observer and do it
1667 here so that the *stopped notification includes the return
1669 if (bs != NULL && tp->control.proceed_to_finish)
1670 observer_notify_normal_stop (bs, 1 /* print frame */);
1673 delete_breakpoint (a->breakpoint);
1674 delete_longjmp_breakpoint (a->thread);
1678 finish_command_continuation_free_arg (void *arg)
1683 /* finish_backward -- helper function for finish_command. */
1686 finish_backward (struct symbol *function)
1688 struct symtab_and_line sal;
1689 struct thread_info *tp = inferior_thread ();
1691 CORE_ADDR func_addr;
1693 pc = get_frame_pc (get_current_frame ());
1695 if (find_pc_partial_function (pc, NULL, &func_addr, NULL) == 0)
1696 error (_("Cannot find bounds of current function"));
1698 sal = find_pc_line (func_addr, 0);
1700 tp->control.proceed_to_finish = 1;
1701 /* Special case: if we're sitting at the function entry point,
1702 then all we need to do is take a reverse singlestep. We
1703 don't need to set a breakpoint, and indeed it would do us
1706 Note that this can only happen at frame #0, since there's
1707 no way that a function up the stack can have a return address
1708 that's equal to its entry point. */
1712 struct frame_info *frame = get_selected_frame (NULL);
1713 struct gdbarch *gdbarch = get_frame_arch (frame);
1714 struct symtab_and_line sr_sal;
1716 /* Set a step-resume at the function's entry point. Once that's
1717 hit, we'll do one more step backwards. */
1720 sr_sal.pspace = get_frame_program_space (frame);
1721 insert_step_resume_breakpoint_at_sal (gdbarch,
1722 sr_sal, null_frame_id);
1724 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1728 /* We're almost there -- we just need to back up by one more
1730 tp->control.step_range_start = tp->control.step_range_end = 1;
1731 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1735 /* finish_forward -- helper function for finish_command. */
1738 finish_forward (struct symbol *function, struct frame_info *frame)
1740 struct frame_id frame_id = get_frame_id (frame);
1741 struct gdbarch *gdbarch = get_frame_arch (frame);
1742 struct symtab_and_line sal;
1743 struct thread_info *tp = inferior_thread ();
1744 struct breakpoint *breakpoint;
1745 struct cleanup *old_chain;
1746 struct finish_command_continuation_args *cargs;
1747 int thread = tp->num;
1749 sal = find_pc_line (get_frame_pc (frame), 0);
1750 sal.pc = get_frame_pc (frame);
1752 breakpoint = set_momentary_breakpoint (gdbarch, sal,
1753 get_stack_frame_id (frame),
1756 /* set_momentary_breakpoint invalidates FRAME. */
1759 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1761 set_longjmp_breakpoint (tp, frame_id);
1762 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1764 /* We want stop_registers, please... */
1765 tp->control.proceed_to_finish = 1;
1766 cargs = xmalloc (sizeof (*cargs));
1768 cargs->thread = thread;
1769 cargs->breakpoint = breakpoint;
1770 cargs->function = function;
1771 add_continuation (tp, finish_command_continuation, cargs,
1772 finish_command_continuation_free_arg);
1773 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1775 discard_cleanups (old_chain);
1776 if (!target_can_async_p ())
1777 do_all_continuations (0);
1780 /* "finish": Set a temporary breakpoint at the place the selected
1781 frame will return to, then continue. */
1784 finish_command (char *arg, int from_tty)
1786 struct frame_info *frame;
1787 struct symbol *function;
1789 struct cleanup *args_chain;
1792 ensure_not_tfind_mode ();
1793 ensure_valid_thread ();
1794 ensure_not_running ();
1796 /* Find out whether we must run in the background. */
1797 arg = strip_bg_char (arg, &async_exec);
1798 args_chain = make_cleanup (xfree, arg);
1800 prepare_execution_command (¤t_target, async_exec);
1803 error (_("The \"finish\" command does not take any arguments."));
1805 /* Done with ARGS. */
1806 do_cleanups (args_chain);
1808 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1810 error (_("\"finish\" not meaningful in the outermost frame."));
1812 clear_proceed_status (0);
1814 /* Finishing from an inline frame is completely different. We don't
1815 try to show the "return value" - no way to locate it. So we do
1816 not need a completion. */
1817 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1820 /* Claim we are stepping in the calling frame. An empty step
1821 range means that we will stop once we aren't in a function
1822 called by that frame. We don't use the magic "1" value for
1823 step_range_end, because then infrun will think this is nexti,
1824 and not step over the rest of this inlined function call. */
1825 struct thread_info *tp = inferior_thread ();
1826 struct symtab_and_line empty_sal;
1828 init_sal (&empty_sal);
1829 set_step_info (frame, empty_sal);
1830 tp->control.step_range_start = get_frame_pc (frame);
1831 tp->control.step_range_end = tp->control.step_range_start;
1832 tp->control.step_over_calls = STEP_OVER_ALL;
1834 /* Print info on the selected frame, including level number but not
1838 printf_filtered (_("Run till exit from "));
1839 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1842 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
1846 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1847 entering THISFRAME. */
1848 while (get_frame_type (frame) == TAILCALL_FRAME)
1849 frame = get_prev_frame (frame);
1851 /* Find the function we will return from. */
1853 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1855 /* Print info on the selected frame, including level number but not
1859 if (execution_direction == EXEC_REVERSE)
1860 printf_filtered (_("Run back to call of "));
1863 if (function != NULL && TYPE_NO_RETURN (function->type)
1864 && !query (_("warning: Function %s does not return normally.\n"
1865 "Try to finish anyway? "),
1866 SYMBOL_PRINT_NAME (function)))
1867 error (_("Not confirmed."));
1868 printf_filtered (_("Run till exit from "));
1871 print_stack_frame (get_selected_frame (NULL), 1, LOCATION, 0);
1874 if (execution_direction == EXEC_REVERSE)
1875 finish_backward (function);
1877 finish_forward (function, frame);
1882 program_info (char *args, int from_tty)
1886 struct thread_info *tp;
1889 if (!target_has_execution)
1891 printf_filtered (_("The program being debugged is not being run.\n"));
1896 ptid = inferior_ptid;
1899 struct target_waitstatus ws;
1901 get_last_target_status (&ptid, &ws);
1904 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1905 error (_("Invalid selected thread."));
1906 else if (is_running (ptid))
1907 error (_("Selected thread is running."));
1909 tp = find_thread_ptid (ptid);
1910 bs = tp->control.stop_bpstat;
1911 stat = bpstat_num (&bs, &num);
1913 target_files_info ();
1914 printf_filtered (_("Program stopped at %s.\n"),
1915 paddress (target_gdbarch (), stop_pc));
1916 if (tp->control.stop_step)
1917 printf_filtered (_("It stopped after being stepped.\n"));
1920 /* There may be several breakpoints in the same place, so this
1921 isn't as strange as it seems. */
1926 printf_filtered (_("It stopped at a breakpoint "
1927 "that has since been deleted.\n"));
1930 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1931 stat = bpstat_num (&bs, &num);
1934 else if (tp->suspend.stop_signal != GDB_SIGNAL_0)
1936 printf_filtered (_("It stopped with signal %s, %s.\n"),
1937 gdb_signal_to_name (tp->suspend.stop_signal),
1938 gdb_signal_to_string (tp->suspend.stop_signal));
1943 printf_filtered (_("Type \"info stack\" or \"info "
1944 "registers\" for more information.\n"));
1949 environment_info (char *var, int from_tty)
1953 char *val = get_in_environ (current_inferior ()->environment, var);
1957 puts_filtered (var);
1958 puts_filtered (" = ");
1959 puts_filtered (val);
1960 puts_filtered ("\n");
1964 puts_filtered ("Environment variable \"");
1965 puts_filtered (var);
1966 puts_filtered ("\" not defined.\n");
1971 char **vector = environ_vector (current_inferior ()->environment);
1975 puts_filtered (*vector++);
1976 puts_filtered ("\n");
1982 set_environment_command (char *arg, int from_tty)
1984 char *p, *val, *var;
1988 error_no_arg (_("environment variable and value"));
1990 /* Find seperation between variable name and value. */
1991 p = (char *) strchr (arg, '=');
1992 val = (char *) strchr (arg, ' ');
1994 if (p != 0 && val != 0)
1996 /* We have both a space and an equals. If the space is before the
1997 equals, walk forward over the spaces til we see a nonspace
1998 (possibly the equals). */
2003 /* Now if the = is after the char following the spaces,
2004 take the char following the spaces. */
2008 else if (val != 0 && p == 0)
2012 error_no_arg (_("environment variable to set"));
2014 if (p == 0 || p[1] == 0)
2018 p = arg + strlen (arg); /* So that savestring below will work. */
2022 /* Not setting variable value to null. */
2024 while (*val == ' ' || *val == '\t')
2028 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
2031 var = savestring (arg, p - arg);
2034 printf_filtered (_("Setting environment variable "
2035 "\"%s\" to null value.\n"),
2037 set_in_environ (current_inferior ()->environment, var, "");
2040 set_in_environ (current_inferior ()->environment, var, val);
2045 unset_environment_command (char *var, int from_tty)
2049 /* If there is no argument, delete all environment variables.
2050 Ask for confirmation if reading from the terminal. */
2051 if (!from_tty || query (_("Delete all environment variables? ")))
2053 free_environ (current_inferior ()->environment);
2054 current_inferior ()->environment = make_environ ();
2058 unset_in_environ (current_inferior ()->environment, var);
2061 /* Handle the execution path (PATH variable). */
2063 static const char path_var_name[] = "PATH";
2066 path_info (char *args, int from_tty)
2068 puts_filtered ("Executable and object file path: ");
2069 puts_filtered (get_in_environ (current_inferior ()->environment,
2071 puts_filtered ("\n");
2074 /* Add zero or more directories to the front of the execution path. */
2077 path_command (char *dirname, int from_tty)
2083 env = get_in_environ (current_inferior ()->environment, path_var_name);
2084 /* Can be null if path is not set. */
2087 exec_path = xstrdup (env);
2088 mod_path (dirname, &exec_path);
2089 set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
2092 path_info ((char *) NULL, from_tty);
2096 /* Print out the register NAME with value VAL, to FILE, in the default
2100 default_print_one_register_info (struct ui_file *file,
2104 struct type *regtype = value_type (val);
2105 int print_raw_format;
2107 fputs_filtered (name, file);
2108 print_spaces_filtered (15 - strlen (name), file);
2110 print_raw_format = (value_entirely_available (val)
2111 && !value_optimized_out (val));
2113 /* If virtual format is floating, print it that way, and in raw
2115 if (TYPE_CODE (regtype) == TYPE_CODE_FLT
2116 || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
2119 struct value_print_options opts;
2120 const gdb_byte *valaddr = value_contents_for_printing (val);
2121 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype));
2123 get_user_print_options (&opts);
2127 value_contents_for_printing (val),
2128 value_embedded_offset (val), 0,
2129 file, 0, val, &opts, current_language);
2131 if (print_raw_format)
2133 fprintf_filtered (file, "\t(raw ");
2134 print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order);
2135 fprintf_filtered (file, ")");
2140 struct value_print_options opts;
2142 /* Print the register in hex. */
2143 get_formatted_print_options (&opts, 'x');
2146 value_contents_for_printing (val),
2147 value_embedded_offset (val), 0,
2148 file, 0, val, &opts, current_language);
2149 /* If not a vector register, print it also according to its
2151 if (print_raw_format && TYPE_VECTOR (regtype) == 0)
2153 get_user_print_options (&opts);
2155 fprintf_filtered (file, "\t");
2157 value_contents_for_printing (val),
2158 value_embedded_offset (val), 0,
2159 file, 0, val, &opts, current_language);
2163 fprintf_filtered (file, "\n");
2166 /* Print out the machine register regnum. If regnum is -1, print all
2167 registers (print_all == 1) or all non-float and non-vector
2168 registers (print_all == 0).
2170 For most machines, having all_registers_info() print the
2171 register(s) one per line is good enough. If a different format is
2172 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2173 regs), or there is an existing convention for showing all the
2174 registers, define the architecture method PRINT_REGISTERS_INFO to
2175 provide that format. */
2178 default_print_registers_info (struct gdbarch *gdbarch,
2179 struct ui_file *file,
2180 struct frame_info *frame,
2181 int regnum, int print_all)
2184 const int numregs = gdbarch_num_regs (gdbarch)
2185 + gdbarch_num_pseudo_regs (gdbarch);
2187 for (i = 0; i < numregs; i++)
2189 /* Decide between printing all regs, non-float / vector regs, or
2195 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
2200 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
2210 /* If the register name is empty, it is undefined for this
2211 processor, so don't display anything. */
2212 if (gdbarch_register_name (gdbarch, i) == NULL
2213 || *(gdbarch_register_name (gdbarch, i)) == '\0')
2216 default_print_one_register_info (file,
2217 gdbarch_register_name (gdbarch, i),
2218 value_of_register (i, frame));
2223 registers_info (char *addr_exp, int fpregs)
2225 struct frame_info *frame;
2226 struct gdbarch *gdbarch;
2228 if (!target_has_registers)
2229 error (_("The program has no registers now."));
2230 frame = get_selected_frame (NULL);
2231 gdbarch = get_frame_arch (frame);
2235 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2240 while (*addr_exp != '\0')
2245 /* Skip leading white space. */
2246 addr_exp = skip_spaces (addr_exp);
2248 /* Discard any leading ``$''. Check that there is something
2249 resembling a register following it. */
2250 if (addr_exp[0] == '$')
2252 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
2253 error (_("Missing register name"));
2255 /* Find the start/end of this register name/num/group. */
2257 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
2261 /* Figure out what we've found and display it. */
2263 /* A register name? */
2265 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
2269 /* User registers lie completely outside of the range of
2270 normal registers. Catch them early so that the target
2272 if (regnum >= gdbarch_num_regs (gdbarch)
2273 + gdbarch_num_pseudo_regs (gdbarch))
2275 struct value *regval = value_of_user_reg (regnum, frame);
2276 const char *regname = user_reg_map_regnum_to_name (gdbarch,
2279 /* Print in the same fashion
2280 gdbarch_print_registers_info's default
2281 implementation prints. */
2282 default_print_one_register_info (gdb_stdout,
2287 gdbarch_print_registers_info (gdbarch, gdb_stdout,
2288 frame, regnum, fpregs);
2293 /* A register group? */
2295 struct reggroup *group;
2297 for (group = reggroup_next (gdbarch, NULL);
2299 group = reggroup_next (gdbarch, group))
2301 /* Don't bother with a length check. Should the user
2302 enter a short register group name, go with the first
2303 group that matches. */
2304 if (strncmp (start, reggroup_name (group), end - start) == 0)
2312 regnum < gdbarch_num_regs (gdbarch)
2313 + gdbarch_num_pseudo_regs (gdbarch);
2316 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
2317 gdbarch_print_registers_info (gdbarch,
2325 /* Nothing matched. */
2326 error (_("Invalid register `%.*s'"), (int) (end - start), start);
2331 all_registers_info (char *addr_exp, int from_tty)
2333 registers_info (addr_exp, 1);
2337 nofp_registers_info (char *addr_exp, int from_tty)
2339 registers_info (addr_exp, 0);
2343 print_vector_info (struct ui_file *file,
2344 struct frame_info *frame, const char *args)
2346 struct gdbarch *gdbarch = get_frame_arch (frame);
2348 if (gdbarch_print_vector_info_p (gdbarch))
2349 gdbarch_print_vector_info (gdbarch, file, frame, args);
2353 int printed_something = 0;
2356 regnum < gdbarch_num_regs (gdbarch)
2357 + gdbarch_num_pseudo_regs (gdbarch);
2360 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
2362 printed_something = 1;
2363 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2366 if (!printed_something)
2367 fprintf_filtered (file, "No vector information\n");
2372 vector_info (char *args, int from_tty)
2374 if (!target_has_registers)
2375 error (_("The program has no registers now."));
2377 print_vector_info (gdb_stdout, get_selected_frame (NULL), args);
2380 /* Kill the inferior process. Make us have no inferior. */
2383 kill_command (char *arg, int from_tty)
2385 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2386 It should be a distinct flag that indicates that a target is active, cuz
2387 some targets don't have processes! */
2389 if (ptid_equal (inferior_ptid, null_ptid))
2390 error (_("The program is not being run."));
2391 if (!query (_("Kill the program being debugged? ")))
2392 error (_("Not confirmed."));
2395 /* If we still have other inferiors to debug, then don't mess with
2396 with their threads. */
2397 if (!have_inferiors ())
2399 init_thread_list (); /* Destroy thread info. */
2401 /* Killing off the inferior can leave us with a core file. If
2402 so, print the state we are left in. */
2403 if (target_has_stack)
2405 printf_filtered (_("In %s,\n"), target_longname);
2406 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2409 bfd_cache_close_all ();
2412 /* Used in `attach&' command. ARG is a point to an integer
2413 representing a process id. Proceed threads of this process 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
2416 that have been explicitly been told to stop. */
2419 proceed_after_attach_callback (struct thread_info *thread,
2422 int pid = * (int *) arg;
2424 if (ptid_get_pid (thread->ptid) == pid
2425 && !is_exited (thread->ptid)
2426 && !is_executing (thread->ptid)
2427 && !thread->stop_requested
2428 && thread->suspend.stop_signal == GDB_SIGNAL_0)
2430 switch_to_thread (thread->ptid);
2431 clear_proceed_status (0);
2432 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2439 proceed_after_attach (int pid)
2441 /* Don't error out if the current thread is running, because
2442 there may be other stopped threads. */
2443 struct cleanup *old_chain;
2445 /* Backup current thread and selected frame. */
2446 old_chain = make_cleanup_restore_current_thread ();
2448 iterate_over_threads (proceed_after_attach_callback, &pid);
2450 /* Restore selected ptid. */
2451 do_cleanups (old_chain);
2454 /* attach_command --
2455 takes a program started up outside of gdb and ``attaches'' to it.
2456 This stops it cold in its tracks and allows us to start debugging it.
2457 and wait for the trace-trap that results from attaching. */
2460 attach_command_post_wait (char *args, int from_tty, int async_exec)
2462 struct inferior *inferior;
2464 inferior = current_inferior ();
2465 inferior->control.stop_soon = NO_STOP_QUIETLY;
2467 /* If no exec file is yet known, try to determine it from the
2469 if (get_exec_file (0) == NULL)
2470 exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
2473 reopen_exec_file ();
2477 /* Take any necessary post-attaching actions for this platform. */
2478 target_post_attach (ptid_get_pid (inferior_ptid));
2480 post_create_inferior (¤t_target, from_tty);
2484 /* The user requested an `attach&', so be sure to leave threads
2485 that didn't get a signal running. */
2487 /* Immediatelly resume all suspended threads of this inferior,
2488 and this inferior only. This should have no effect on
2489 already running threads. If a thread has been stopped with a
2490 signal, leave it be. */
2492 proceed_after_attach (inferior->pid);
2495 if (inferior_thread ()->suspend.stop_signal == GDB_SIGNAL_0)
2497 clear_proceed_status (0);
2498 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
2504 /* The user requested a plain `attach', so be sure to leave
2505 the inferior stopped. */
2507 if (target_can_async_p ())
2508 async_enable_stdin ();
2510 /* At least the current thread is already stopped. */
2512 /* In all-stop, by definition, all threads have to be already
2513 stopped at this point. In non-stop, however, although the
2514 selected thread is stopped, others may still be executing.
2515 Be sure to explicitly stop all threads of the process. This
2516 should have no effect on already stopped threads. */
2518 target_stop (pid_to_ptid (inferior->pid));
2520 /* Tell the user/frontend where we're stopped. */
2522 if (deprecated_attach_hook)
2523 deprecated_attach_hook ();
2527 struct attach_command_continuation_args
2535 attach_command_continuation (void *args, int err)
2537 struct attach_command_continuation_args *a = args;
2542 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2546 attach_command_continuation_free_args (void *args)
2548 struct attach_command_continuation_args *a = args;
2555 attach_command (char *args, int from_tty)
2558 struct cleanup *args_chain;
2559 struct target_ops *attach_target;
2561 dont_repeat (); /* Not for the faint of heart */
2563 if (gdbarch_has_global_solist (target_gdbarch ()))
2564 /* Don't complain if all processes share the same symbol
2567 else if (target_has_execution)
2569 if (query (_("A program is being debugged already. Kill it? ")))
2572 error (_("Not killed."));
2575 /* Clean up any leftovers from other runs. Some other things from
2576 this function should probably be moved into target_pre_inferior. */
2577 target_pre_inferior (from_tty);
2579 args = strip_bg_char (args, &async_exec);
2580 args_chain = make_cleanup (xfree, args);
2582 attach_target = find_attach_target ();
2584 prepare_execution_command (attach_target, async_exec);
2586 if (non_stop && !attach_target->to_supports_non_stop (attach_target))
2587 error (_("Cannot attach to this target in non-stop mode"));
2589 attach_target->to_attach (attach_target, args, from_tty);
2590 /* to_attach should push the target, so after this point we
2591 shouldn't refer to attach_target again. */
2592 attach_target = NULL;
2594 /* Done with ARGS. */
2595 do_cleanups (args_chain);
2597 /* Set up the "saved terminal modes" of the inferior
2598 based on what modes we are starting it with. */
2599 target_terminal_init ();
2601 /* Install inferior's terminal modes. This may look like a no-op,
2602 as we've just saved them above, however, this does more than
2603 restore terminal settings:
2605 - installs a SIGINT handler that forwards SIGINT to the inferior.
2606 Otherwise a Ctrl-C pressed just while waiting for the initial
2607 stop would end up as a spurious Quit.
2609 - removes stdin from the event loop, which we need if attaching
2610 in the foreground, otherwise on targets that report an initial
2611 stop on attach (which are most) we'd process input/commands
2612 while we're in the event loop waiting for that stop. That is,
2613 before the attach continuation runs and the command is really
2615 target_terminal_inferior ();
2617 /* Set up execution context to know that we should return from
2618 wait_for_inferior as soon as the target reports a stop. */
2619 init_wait_for_inferior ();
2620 clear_proceed_status (0);
2624 /* If we find that the current thread isn't stopped, explicitly
2625 do so now, because we're going to install breakpoints and
2629 /* The user requested an `attach&'; stop just one thread. */
2630 target_stop (inferior_ptid);
2632 /* The user requested an `attach', so stop all threads of this
2634 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
2637 /* Some system don't generate traps when attaching to inferior.
2638 E.g. Mach 3 or GNU hurd. */
2639 if (!target_attach_no_wait)
2641 struct inferior *inferior = current_inferior ();
2643 /* Careful here. See comments in inferior.h. Basically some
2644 OSes don't ignore SIGSTOPs on continue requests anymore. We
2645 need a way for handle_inferior_event to reset the stop_signal
2646 variable after an attach, and this is what
2647 STOP_QUIETLY_NO_SIGSTOP is for. */
2648 inferior->control.stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2650 if (target_can_async_p ())
2652 /* sync_execution mode. Wait for stop. */
2653 struct attach_command_continuation_args *a;
2655 a = xmalloc (sizeof (*a));
2656 a->args = xstrdup (args);
2657 a->from_tty = from_tty;
2658 a->async_exec = async_exec;
2659 add_inferior_continuation (attach_command_continuation, a,
2660 attach_command_continuation_free_args);
2664 wait_for_inferior ();
2667 attach_command_post_wait (args, from_tty, async_exec);
2670 /* We had just found out that the target was already attached to an
2671 inferior. PTID points at a thread of this new inferior, that is
2672 the most likely to be stopped right now, but not necessarily so.
2673 The new inferior is assumed to be already added to the inferior
2674 list at this point. If LEAVE_RUNNING, then leave the threads of
2675 this inferior running, except those we've explicitly seen reported
2679 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
2681 struct cleanup* old_chain;
2684 old_chain = make_cleanup (null_cleanup, NULL);
2686 /* If in non-stop, leave threads as running as they were. If
2687 they're stopped for some reason other than us telling it to, the
2688 target reports a signal != GDB_SIGNAL_0. We don't try to
2689 resume threads with such a stop signal. */
2690 async_exec = non_stop;
2692 if (!ptid_equal (inferior_ptid, null_ptid))
2693 make_cleanup_restore_current_thread ();
2695 switch_to_thread (ptid);
2697 /* When we "notice" a new inferior we need to do all the things we
2698 would normally do if we had just attached to it. */
2700 if (is_executing (inferior_ptid))
2702 struct inferior *inferior = current_inferior ();
2704 /* We're going to install breakpoints, and poke at memory,
2705 ensure that the inferior is stopped for a moment while we do
2707 target_stop (inferior_ptid);
2709 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2711 /* Wait for stop before proceeding. */
2712 if (target_can_async_p ())
2714 struct attach_command_continuation_args *a;
2716 a = xmalloc (sizeof (*a));
2717 a->args = xstrdup ("");
2718 a->from_tty = from_tty;
2719 a->async_exec = async_exec;
2720 add_inferior_continuation (attach_command_continuation, a,
2721 attach_command_continuation_free_args);
2723 do_cleanups (old_chain);
2727 wait_for_inferior ();
2730 async_exec = leave_running;
2731 attach_command_post_wait ("" /* args */, from_tty, async_exec);
2733 do_cleanups (old_chain);
2738 * takes a program previously attached to and detaches it.
2739 * The program resumes execution and will no longer stop
2740 * on signals, etc. We better not have left any breakpoints
2741 * in the program or it'll die when it hits one. For this
2742 * to work, it may be necessary for the process to have been
2743 * previously attached. It *might* work if the program was
2744 * started via the normal ptrace (PTRACE_TRACEME).
2748 detach_command (char *args, int from_tty)
2750 dont_repeat (); /* Not for the faint of heart. */
2752 if (ptid_equal (inferior_ptid, null_ptid))
2753 error (_("The program is not being run."));
2755 query_if_trace_running (from_tty);
2757 disconnect_tracing ();
2759 target_detach (args, from_tty);
2761 /* If the solist is global across inferiors, don't clear it when we
2762 detach from a single inferior. */
2763 if (!gdbarch_has_global_solist (target_gdbarch ()))
2764 no_shared_libraries (NULL, from_tty);
2766 /* If we still have inferiors to debug, then don't mess with their
2768 if (!have_inferiors ())
2769 init_thread_list ();
2771 if (deprecated_detach_hook)
2772 deprecated_detach_hook ();
2775 /* Disconnect from the current target without resuming it (leaving it
2776 waiting for a debugger).
2778 We'd better not have left any breakpoints in the program or the
2779 next debugger will get confused. Currently only supported for some
2780 remote targets, since the normal attach mechanisms don't work on
2781 stopped processes on some native platforms (e.g. GNU/Linux). */
2784 disconnect_command (char *args, int from_tty)
2786 dont_repeat (); /* Not for the faint of heart. */
2787 query_if_trace_running (from_tty);
2788 disconnect_tracing ();
2789 target_disconnect (args, from_tty);
2790 no_shared_libraries (NULL, from_tty);
2791 init_thread_list ();
2792 if (deprecated_detach_hook)
2793 deprecated_detach_hook ();
2797 interrupt_target_1 (int all_threads)
2802 ptid = minus_one_ptid;
2804 ptid = inferior_ptid;
2807 /* Tag the thread as having been explicitly requested to stop, so
2808 other parts of gdb know not to resume this thread automatically,
2809 if it was stopped due to an internal event. Limit this to
2810 non-stop mode, as when debugging a multi-threaded application in
2811 all-stop mode, we will only get one stop event --- it's undefined
2812 which thread will report the event. */
2814 set_stop_requested (ptid, 1);
2818 Stop the execution of the target while running in async mode, in
2819 the backgound. In all-stop, stop the whole process. In non-stop
2820 mode, stop the current thread only by default, or stop all threads
2821 if the `-a' switch is used. */
2824 interrupt_command (char *args, int from_tty)
2826 if (target_can_async_p ())
2828 int all_threads = 0;
2830 dont_repeat (); /* Not for the faint of heart. */
2833 && startswith (args, "-a"))
2836 if (!non_stop && all_threads)
2837 error (_("-a is meaningless in all-stop mode."));
2839 interrupt_target_1 (all_threads);
2843 /* See inferior.h. */
2846 default_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2847 struct frame_info *frame, const char *args)
2850 int printed_something = 0;
2853 regnum < gdbarch_num_regs (gdbarch)
2854 + gdbarch_num_pseudo_regs (gdbarch);
2857 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2859 printed_something = 1;
2860 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2863 if (!printed_something)
2864 fprintf_filtered (file, "No floating-point info "
2865 "available for this processor.\n");
2869 float_info (char *args, int from_tty)
2871 struct frame_info *frame;
2873 if (!target_has_registers)
2874 error (_("The program has no registers now."));
2876 frame = get_selected_frame (NULL);
2877 gdbarch_print_float_info (get_frame_arch (frame), gdb_stdout, frame, args);
2881 unset_command (char *args, int from_tty)
2883 printf_filtered (_("\"unset\" must be followed by the "
2884 "name of an unset subcommand.\n"));
2885 help_list (unsetlist, "unset ", all_commands, gdb_stdout);
2888 /* Implement `info proc' family of commands. */
2891 info_proc_cmd_1 (char *args, enum info_proc_what what, int from_tty)
2893 struct gdbarch *gdbarch = get_current_arch ();
2895 if (!target_info_proc (args, what))
2897 if (gdbarch_info_proc_p (gdbarch))
2898 gdbarch_info_proc (gdbarch, args, what);
2900 error (_("Not supported on this target."));
2904 /* Implement `info proc' when given without any futher parameters. */
2907 info_proc_cmd (char *args, int from_tty)
2909 info_proc_cmd_1 (args, IP_MINIMAL, from_tty);
2912 /* Implement `info proc mappings'. */
2915 info_proc_cmd_mappings (char *args, int from_tty)
2917 info_proc_cmd_1 (args, IP_MAPPINGS, from_tty);
2920 /* Implement `info proc stat'. */
2923 info_proc_cmd_stat (char *args, int from_tty)
2925 info_proc_cmd_1 (args, IP_STAT, from_tty);
2928 /* Implement `info proc status'. */
2931 info_proc_cmd_status (char *args, int from_tty)
2933 info_proc_cmd_1 (args, IP_STATUS, from_tty);
2936 /* Implement `info proc cwd'. */
2939 info_proc_cmd_cwd (char *args, int from_tty)
2941 info_proc_cmd_1 (args, IP_CWD, from_tty);
2944 /* Implement `info proc cmdline'. */
2947 info_proc_cmd_cmdline (char *args, int from_tty)
2949 info_proc_cmd_1 (args, IP_CMDLINE, from_tty);
2952 /* Implement `info proc exe'. */
2955 info_proc_cmd_exe (char *args, int from_tty)
2957 info_proc_cmd_1 (args, IP_EXE, from_tty);
2960 /* Implement `info proc all'. */
2963 info_proc_cmd_all (char *args, int from_tty)
2965 info_proc_cmd_1 (args, IP_ALL, from_tty);
2969 _initialize_infcmd (void)
2971 static struct cmd_list_element *info_proc_cmdlist;
2972 struct cmd_list_element *c = NULL;
2973 const char *cmd_name;
2975 /* Add the filename of the terminal connected to inferior I/O. */
2976 add_setshow_filename_cmd ("inferior-tty", class_run,
2977 &inferior_io_terminal_scratch, _("\
2978 Set terminal for future runs of program being debugged."), _("\
2979 Show terminal for future runs of program being debugged."), _("\
2980 Usage: set inferior-tty /dev/pts/1"),
2981 set_inferior_tty_command,
2982 show_inferior_tty_command,
2983 &setlist, &showlist);
2984 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2987 add_setshow_string_noescape_cmd (cmd_name, class_run,
2988 &inferior_args_scratch, _("\
2989 Set argument list to give program being debugged when it is started."), _("\
2990 Show argument list to give program being debugged when it is started."), _("\
2991 Follow this command with any number of args, to be passed to the program."),
2994 &setlist, &showlist);
2995 c = lookup_cmd (&cmd_name, setlist, "", -1, 1);
2996 gdb_assert (c != NULL);
2997 set_cmd_completer (c, filename_completer);
2999 c = add_cmd ("environment", no_class, environment_info, _("\
3000 The environment to give the program, or one variable's value.\n\
3001 With an argument VAR, prints the value of environment variable VAR to\n\
3002 give the program being debugged. With no arguments, prints the entire\n\
3003 environment to be given to the program."), &showlist);
3004 set_cmd_completer (c, noop_completer);
3006 add_prefix_cmd ("unset", no_class, unset_command,
3007 _("Complement to certain \"set\" commands."),
3008 &unsetlist, "unset ", 0, &cmdlist);
3010 c = add_cmd ("environment", class_run, unset_environment_command, _("\
3011 Cancel environment variable VAR for the program.\n\
3012 This does not affect the program until the next \"run\" command."),
3014 set_cmd_completer (c, noop_completer);
3016 c = add_cmd ("environment", class_run, set_environment_command, _("\
3017 Set environment variable value to give the program.\n\
3018 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3019 VALUES of environment variables are uninterpreted strings.\n\
3020 This does not affect the program until the next \"run\" command."),
3022 set_cmd_completer (c, noop_completer);
3024 c = add_com ("path", class_files, path_command, _("\
3025 Add directory DIR(s) to beginning of search path for object files.\n\
3026 $cwd in the path means the current working directory.\n\
3027 This path is equivalent to the $PATH shell variable. It is a list of\n\
3028 directories, separated by colons. These directories are searched to find\n\
3029 fully linked executable files and separately compiled object files as \
3031 set_cmd_completer (c, filename_completer);
3033 c = add_cmd ("paths", no_class, path_info, _("\
3034 Current search path for finding object files.\n\
3035 $cwd in the path means the current working directory.\n\
3036 This path is equivalent to the $PATH shell variable. It is a list of\n\
3037 directories, separated by colons. These directories are searched to find\n\
3038 fully linked executable files and separately compiled object files as \
3041 set_cmd_completer (c, noop_completer);
3043 add_prefix_cmd ("kill", class_run, kill_command,
3044 _("Kill execution of program being debugged."),
3045 &killlist, "kill ", 0, &cmdlist);
3047 add_com ("attach", class_run, attach_command, _("\
3048 Attach to a process or file outside of GDB.\n\
3049 This command attaches to another target, of the same type as your last\n\
3050 \"target\" command (\"info files\" will show your target stack).\n\
3051 The command may take as argument a process id or a device file.\n\
3052 For a process id, you must have permission to send the process a signal,\n\
3053 and it must have the same effective uid as the debugger.\n\
3054 When using \"attach\" with a process id, the debugger finds the\n\
3055 program running in the process, looking first in the current working\n\
3056 directory, or (if not found there) using the source file search path\n\
3057 (see the \"directory\" command). You can also use the \"file\" command\n\
3058 to specify the program, and to load its symbol table."));
3060 add_prefix_cmd ("detach", class_run, detach_command, _("\
3061 Detach a process or file previously attached.\n\
3062 If a process, it is no longer traced, and it continues its execution. If\n\
3063 you were debugging a file, the file is closed and gdb no longer accesses it."),
3064 &detachlist, "detach ", 0, &cmdlist);
3066 add_com ("disconnect", class_run, disconnect_command, _("\
3067 Disconnect from a target.\n\
3068 The target will wait for another debugger to connect. Not available for\n\
3071 c = add_com ("signal", class_run, signal_command, _("\
3072 Continue program with the specified signal.\n\
3073 Usage: signal SIGNAL\n\
3074 The SIGNAL argument is processed the same as the handle command.\n\
3076 An argument of \"0\" means continue the program without sending it a signal.\n\
3077 This is useful in cases where the program stopped because of a signal,\n\
3078 and you want to resume the program while discarding the signal.\n\
3080 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3081 the current thread only."));
3082 set_cmd_completer (c, signal_completer);
3084 c = add_com ("queue-signal", class_run, queue_signal_command, _("\
3085 Queue a signal to be delivered to the current thread when it is resumed.\n\
3086 Usage: queue-signal SIGNAL\n\
3087 The SIGNAL argument is processed the same as the handle command.\n\
3088 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3090 An argument of \"0\" means remove any currently queued signal from\n\
3091 the current thread. This is useful in cases where the program stopped\n\
3092 because of a signal, and you want to resume it while discarding the signal.\n\
3094 In a multi-threaded program the signal is queued with, or discarded from,\n\
3095 the current thread only."));
3096 set_cmd_completer (c, signal_completer);
3098 add_com ("stepi", class_run, stepi_command, _("\
3099 Step one instruction exactly.\n\
3101 Argument N means step N times (or till program stops for another \
3103 add_com_alias ("si", "stepi", class_alias, 0);
3105 add_com ("nexti", class_run, nexti_command, _("\
3106 Step one instruction, but proceed through subroutine calls.\n\
3108 Argument N means step N times (or till program stops for another \
3110 add_com_alias ("ni", "nexti", class_alias, 0);
3112 add_com ("finish", class_run, finish_command, _("\
3113 Execute until selected stack frame returns.\n\
3115 Upon return, the value returned is printed and put in the value history."));
3116 add_com_alias ("fin", "finish", class_run, 1);
3118 add_com ("next", class_run, next_command, _("\
3119 Step program, proceeding through subroutine calls.\n\
3121 Unlike \"step\", if the current source line calls a subroutine,\n\
3122 this command does not enter the subroutine, but instead steps over\n\
3123 the call, in effect treating it as a single source line."));
3124 add_com_alias ("n", "next", class_run, 1);
3126 add_com ("step", class_run, step_command, _("\
3127 Step program until it reaches a different source line.\n\
3129 Argument N means step N times (or till program stops for another \
3131 add_com_alias ("s", "step", class_run, 1);
3133 c = add_com ("until", class_run, until_command, _("\
3134 Execute until the program reaches a source line greater than the current\n\
3135 or a specified location (same args as break command) within the current \
3137 set_cmd_completer (c, location_completer);
3138 add_com_alias ("u", "until", class_run, 1);
3140 c = add_com ("advance", class_run, advance_command, _("\
3141 Continue the program up to the given location (same form as args for break \
3143 Execution will also stop upon exit from the current stack frame."));
3144 set_cmd_completer (c, location_completer);
3146 c = add_com ("jump", class_run, jump_command, _("\
3147 Continue program being debugged at specified line or address.\n\
3148 Usage: jump <location>\n\
3149 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3150 for an address to start at."));
3151 set_cmd_completer (c, location_completer);
3152 add_com_alias ("j", "jump", class_run, 1);
3154 add_com ("continue", class_run, continue_command, _("\
3155 Continue program being debugged, after signal or breakpoint.\n\
3156 Usage: continue [N]\n\
3157 If proceeding from breakpoint, a number N may be used as an argument,\n\
3158 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3159 the breakpoint won't break until the Nth time it is reached).\n\
3161 If non-stop mode is enabled, continue only the current thread,\n\
3162 otherwise all the threads in the program are continued. To \n\
3163 continue all stopped threads in non-stop mode, use the -a option.\n\
3164 Specifying -a and an ignore count simultaneously is an error."));
3165 add_com_alias ("c", "cont", class_run, 1);
3166 add_com_alias ("fg", "cont", class_run, 1);
3168 c = add_com ("run", class_run, run_command, _("\
3169 Start debugged program. You may specify arguments to give it.\n\
3170 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3171 Input and output redirection with \">\", \"<\", or \">>\" are also \
3173 With no arguments, uses arguments last specified (with \"run\" \
3174 or \"set args\").\n\
3175 To cancel previous arguments and run with no arguments,\n\
3176 use \"set args\" without arguments."));
3177 set_cmd_completer (c, filename_completer);
3178 add_com_alias ("r", "run", class_run, 1);
3180 c = add_com ("start", class_run, start_command, _("\
3181 Run the debugged program until the beginning of the main procedure.\n\
3182 You may specify arguments to give to your program, just as with the\n\
3183 \"run\" command."));
3184 set_cmd_completer (c, filename_completer);
3186 add_com ("interrupt", class_run, interrupt_command,
3187 _("Interrupt the execution of the debugged program.\n\
3188 If non-stop mode is enabled, interrupt only the current thread,\n\
3189 otherwise all the threads in the program are stopped. To \n\
3190 interrupt all running threads in non-stop mode, use the -a option."));
3192 c = add_info ("registers", nofp_registers_info, _("\
3193 List of integer registers and their contents, for selected stack frame.\n\
3194 Register name as argument means describe only that register."));
3195 add_info_alias ("r", "registers", 1);
3196 set_cmd_completer (c, reg_or_group_completer);
3198 c = add_info ("all-registers", all_registers_info, _("\
3199 List of all registers and their contents, for selected stack frame.\n\
3200 Register name as argument means describe only that register."));
3201 set_cmd_completer (c, reg_or_group_completer);
3203 add_info ("program", program_info,
3204 _("Execution status of the program."));
3206 add_info ("float", float_info,
3207 _("Print the status of the floating point unit\n"));
3209 add_info ("vector", vector_info,
3210 _("Print the status of the vector unit\n"));
3212 add_prefix_cmd ("proc", class_info, info_proc_cmd,
3214 Show /proc process information about any running process.\n\
3215 Specify any process id, or use the program being debugged by default."),
3216 &info_proc_cmdlist, "info proc ",
3217 1/*allow-unknown*/, &infolist);
3219 add_cmd ("mappings", class_info, info_proc_cmd_mappings, _("\
3220 List of mapped memory regions."),
3221 &info_proc_cmdlist);
3223 add_cmd ("stat", class_info, info_proc_cmd_stat, _("\
3224 List process info from /proc/PID/stat."),
3225 &info_proc_cmdlist);
3227 add_cmd ("status", class_info, info_proc_cmd_status, _("\
3228 List process info from /proc/PID/status."),
3229 &info_proc_cmdlist);
3231 add_cmd ("cwd", class_info, info_proc_cmd_cwd, _("\
3232 List current working directory of the process."),
3233 &info_proc_cmdlist);
3235 add_cmd ("cmdline", class_info, info_proc_cmd_cmdline, _("\
3236 List command line arguments of the process."),
3237 &info_proc_cmdlist);
3239 add_cmd ("exe", class_info, info_proc_cmd_exe, _("\
3240 List absolute filename for executable of the process."),
3241 &info_proc_cmdlist);
3243 add_cmd ("all", class_info, info_proc_cmd_all, _("\
3244 List all available /proc info."),
3245 &info_proc_cmdlist);