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 print_return_value (struct value
*function
,
63 struct type
*value_type
);
65 static void until_next_command (int);
67 static void until_command (char *, int);
69 static void path_info (char *, int);
71 static void path_command (char *, int);
73 static void unset_command (char *, int);
75 static void float_info (char *, int);
77 static void disconnect_command (char *, int);
79 static void unset_environment_command (char *, int);
81 static void set_environment_command (char *, int);
83 static void environment_info (char *, int);
85 static void program_info (char *, int);
87 static void finish_command (char *, int);
89 static void signal_command (char *, int);
91 static void jump_command (char *, int);
93 static void step_1 (int, int, char *);
94 static void step_once (int skip_subroutines
, int single_inst
,
95 int count
, int thread
);
97 static void next_command (char *, int);
99 static void step_command (char *, int);
101 static void run_command (char *, int);
103 void _initialize_infcmd (void);
105 #define ERROR_NO_INFERIOR \
106 if (!target_has_execution) error (_("The program is not being run."));
108 /* Scratch area where string containing arguments to give to the
109 program will be stored by 'set args'. As soon as anything is
110 stored, notice_args_set will move it into per-inferior storage.
111 Arguments are separated by spaces. Empty string (pointer to '\0')
114 static char *inferior_args_scratch
;
116 /* Scratch area where 'set inferior-tty' will store user-provided value.
117 We'll immediate copy it into per-inferior storage. */
119 static char *inferior_io_terminal_scratch
;
121 /* Pid of our debugged inferior, or 0 if no inferior now.
122 Since various parts of infrun.c test this to see whether there is a program
123 being debugged it should be nonzero (currently 3 is used) for remote
126 ptid_t inferior_ptid
;
128 /* Address at which inferior stopped. */
132 /* Nonzero if stopped due to completion of a stack dummy routine. */
134 enum stop_stack_kind stop_stack_dummy
;
136 /* Nonzero if stopped due to a random (unexpected) signal in inferior
139 int stopped_by_random_signal
;
141 /* See inferior.h. */
143 int startup_with_shell
= 1;
146 /* Accessor routines. */
148 /* Set the io terminal for the current inferior. Ownership of
149 TERMINAL_NAME is not transferred. */
152 set_inferior_io_terminal (const char *terminal_name
)
154 xfree (current_inferior ()->terminal
);
155 current_inferior ()->terminal
= terminal_name
? xstrdup (terminal_name
) : 0;
159 get_inferior_io_terminal (void)
161 return current_inferior ()->terminal
;
165 set_inferior_tty_command (char *args
, int from_tty
,
166 struct cmd_list_element
*c
)
168 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
169 Now route it to current inferior. */
170 set_inferior_io_terminal (inferior_io_terminal_scratch
);
174 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
175 struct cmd_list_element
*c
, const char *value
)
177 /* Note that we ignore the passed-in value in favor of computing it
179 const char *inferior_io_terminal
= get_inferior_io_terminal ();
181 if (inferior_io_terminal
== NULL
)
182 inferior_io_terminal
= "";
183 fprintf_filtered (gdb_stdout
,
184 _("Terminal for future runs of program being debugged "
185 "is \"%s\".\n"), inferior_io_terminal
);
189 get_inferior_args (void)
191 if (current_inferior ()->argc
!= 0)
195 n
= construct_inferior_arguments (current_inferior ()->argc
,
196 current_inferior ()->argv
);
197 set_inferior_args (n
);
201 if (current_inferior ()->args
== NULL
)
202 current_inferior ()->args
= xstrdup ("");
204 return current_inferior ()->args
;
207 /* Set the arguments for the current inferior. Ownership of
208 NEWARGS is not transferred. */
211 set_inferior_args (char *newargs
)
213 xfree (current_inferior ()->args
);
214 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
215 current_inferior ()->argc
= 0;
216 current_inferior ()->argv
= 0;
220 set_inferior_args_vector (int argc
, char **argv
)
222 current_inferior ()->argc
= argc
;
223 current_inferior ()->argv
= argv
;
226 /* Notice when `set args' is run. */
229 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
231 /* CLI has assigned the user-provided value to inferior_args_scratch.
232 Now route it to current inferior. */
233 set_inferior_args (inferior_args_scratch
);
236 /* Notice when `show args' is run. */
239 show_args_command (struct ui_file
*file
, int from_tty
,
240 struct cmd_list_element
*c
, const char *value
)
242 /* Note that we ignore the passed-in value in favor of computing it
244 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
248 /* Compute command-line string given argument vector. This does the
249 same shell processing as fork_inferior. */
252 construct_inferior_arguments (int argc
, char **argv
)
256 if (startup_with_shell
)
259 /* This holds all the characters considered special to the
261 char *special
= "\"!&*|[]{}<>?`~^=;, \t\n";
262 const char quote
= '"';
264 /* This holds all the characters considered special to the
265 typical Unix shells. We include `^' because the SunOS
266 /bin/sh treats it as a synonym for `|'. */
267 char *special
= "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
268 const char quote
= '\'';
274 /* We over-compute the size. It shouldn't matter. */
275 for (i
= 0; i
< argc
; ++i
)
276 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
278 result
= (char *) xmalloc (length
);
281 for (i
= 0; i
< argc
; ++i
)
286 /* Need to handle empty arguments specially. */
287 if (argv
[i
][0] == '\0')
297 if (strpbrk (argv
[i
], special
))
303 for (cp
= argv
[i
]; *cp
; ++cp
)
307 /* A newline cannot be quoted with a backslash (it
308 just disappears), only by putting it inside
319 if (strchr (special
, *cp
) != NULL
)
335 /* In this case we can't handle arguments that contain spaces,
336 tabs, or newlines -- see breakup_args(). */
340 for (i
= 0; i
< argc
; ++i
)
342 char *cp
= strchr (argv
[i
], ' ');
344 cp
= strchr (argv
[i
], '\t');
346 cp
= strchr (argv
[i
], '\n');
348 error (_("can't handle command-line "
349 "argument containing whitespace"));
350 length
+= strlen (argv
[i
]) + 1;
353 result
= (char *) xmalloc (length
);
355 for (i
= 0; i
< argc
; ++i
)
358 strcat (result
, " ");
359 strcat (result
, argv
[i
]);
367 /* This function strips the '&' character (indicating background
368 execution) that is added as *the last* of the arguments ARGS of a
369 command. A copy of the incoming ARGS without the '&' is returned,
370 unless the resulting string after stripping is empty, in which case
371 NULL is returned. *BG_CHAR_P is an output boolean that indicates
372 whether the '&' character was found. */
375 strip_bg_char (const char *args
, int *bg_char_p
)
379 if (args
== NULL
|| *args
== '\0')
385 p
= args
+ strlen (args
);
389 while (p
> args
&& isspace (p
[-1]))
394 return savestring (args
, p
- args
);
400 return xstrdup (args
);
403 /* Common actions to take after creating any sort of inferior, by any
404 means (running, attaching, connecting, et cetera). The target
405 should be stopped. */
408 post_create_inferior (struct target_ops
*target
, int from_tty
)
411 /* Be sure we own the terminal in case write operations are performed. */
412 target_terminal_ours ();
414 /* If the target hasn't taken care of this already, do it now.
415 Targets which need to access registers during to_open,
416 to_create_inferior, or to_attach should do it earlier; but many
418 target_find_description ();
420 /* Now that we know the register layout, retrieve current PC. But
421 if the PC is unavailable (e.g., we're opening a core file with
422 missing registers info), ignore it. */
426 stop_pc
= regcache_read_pc (get_current_regcache ());
428 CATCH (ex
, RETURN_MASK_ERROR
)
430 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
431 throw_exception (ex
);
437 const unsigned solib_add_generation
438 = current_program_space
->solib_add_generation
;
440 /* Create the hooks to handle shared library load and unload
442 solib_create_inferior_hook (from_tty
);
444 if (current_program_space
->solib_add_generation
== solib_add_generation
)
446 /* The platform-specific hook should load initial shared libraries,
447 but didn't. FROM_TTY will be incorrectly 0 but such solib
448 targets should be fixed anyway. Call it only after the solib
449 target has been initialized by solib_create_inferior_hook. */
452 warning (_("platform-specific solib_create_inferior_hook did "
453 "not load initial shared libraries."));
455 /* If the solist is global across processes, there's no need to
457 if (!gdbarch_has_global_solist (target_gdbarch ()))
458 solib_add (NULL
, 0, target
, auto_solib_add
);
462 /* If the user sets watchpoints before execution having started,
463 then she gets software watchpoints, because GDB can't know which
464 target will end up being pushed, or if it supports hardware
465 watchpoints or not. breakpoint_re_set takes care of promoting
466 watchpoints to hardware watchpoints if possible, however, if this
467 new inferior doesn't load shared libraries or we don't pull in
468 symbols from any other source on this target/arch,
469 breakpoint_re_set is never called. Call it now so that software
470 watchpoints get a chance to be promoted to hardware watchpoints
471 if the now pushed target supports hardware watchpoints. */
472 breakpoint_re_set ();
474 observer_notify_inferior_created (target
, from_tty
);
477 /* Kill the inferior if already running. This function is designed
478 to be called when we are about to start the execution of the program
479 from the beginning. Ask the user to confirm that he wants to restart
480 the program being debugged when FROM_TTY is non-null. */
483 kill_if_already_running (int from_tty
)
485 if (! ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
487 /* Bail out before killing the program if we will not be able to
489 target_require_runnable ();
492 && !query (_("The program being debugged has been started already.\n\
493 Start it from the beginning? ")))
494 error (_("Program not restarted."));
499 /* See inferior.h. */
502 prepare_execution_command (struct target_ops
*target
, int background
)
504 /* If we get a request for running in the bg but the target
505 doesn't support it, error out. */
506 if (background
&& !target
->to_can_async_p (target
))
507 error (_("Asynchronous execution not supported on this target."));
509 /* If we don't get a request of running in the bg, then we need
510 to simulate synchronous (fg) execution. */
511 if (!background
&& target
->to_can_async_p (target
))
513 /* Simulate synchronous execution. Note no cleanup is necessary
514 for this. stdin is re-enabled whenever an error reaches the
516 async_disable_stdin ();
520 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
521 a temporary breakpoint at the begining of the main program before
522 running the program. */
525 run_command_1 (char *args
, int from_tty
, int tbreak_at_main
)
528 struct cleanup
*old_chain
;
530 struct ui_out
*uiout
= current_uiout
;
531 struct target_ops
*run_target
;
533 struct cleanup
*args_chain
;
537 kill_if_already_running (from_tty
);
539 init_wait_for_inferior ();
540 clear_breakpoint_hit_counts ();
542 /* Clean up any leftovers from other runs. Some other things from
543 this function should probably be moved into target_pre_inferior. */
544 target_pre_inferior (from_tty
);
546 /* The comment here used to read, "The exec file is re-read every
547 time we do a generic_mourn_inferior, so we just have to worry
548 about the symbol file." The `generic_mourn_inferior' function
549 gets called whenever the program exits. However, suppose the
550 program exits, and *then* the executable file changes? We need
551 to check again here. Since reopen_exec_file doesn't do anything
552 if the timestamp hasn't changed, I don't see the harm. */
556 args
= strip_bg_char (args
, &async_exec
);
557 args_chain
= make_cleanup (xfree
, args
);
559 /* Do validation and preparation before possibly changing anything
562 run_target
= find_run_target ();
564 prepare_execution_command (run_target
, async_exec
);
566 if (non_stop
&& !run_target
->to_supports_non_stop (run_target
))
567 error (_("The target does not support running in non-stop mode."));
569 /* Done. Can now set breakpoints, change inferior args, etc. */
571 /* Insert the temporary breakpoint if a location was specified. */
573 tbreak_command (main_name (), 0);
575 exec_file
= (char *) get_exec_file (0);
577 /* We keep symbols from add-symbol-file, on the grounds that the
578 user might want to add some symbols before running the program
579 (right?). But sometimes (dynamic loading where the user manually
580 introduces the new symbols with add-symbol-file), the code which
581 the symbols describe does not persist between runs. Currently
582 the user has to manually nuke all symbols between runs if they
583 want them to go away (PR 2207). This is probably reasonable. */
585 /* If there were other args, beside '&', process them. */
587 set_inferior_args (args
);
591 ui_out_field_string (uiout
, NULL
, "Starting program");
592 ui_out_text (uiout
, ": ");
594 ui_out_field_string (uiout
, "execfile", exec_file
);
595 ui_out_spaces (uiout
, 1);
596 /* We call get_inferior_args() because we might need to compute
598 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
599 ui_out_text (uiout
, "\n");
600 ui_out_flush (uiout
);
603 /* Done with ARGS. */
604 do_cleanups (args_chain
);
606 /* We call get_inferior_args() because we might need to compute
608 run_target
->to_create_inferior (run_target
, exec_file
, get_inferior_args (),
609 environ_vector (current_inferior ()->environment
),
611 /* to_create_inferior should push the target, so after this point we
612 shouldn't refer to run_target again. */
615 /* We're starting off a new process. When we get out of here, in
616 non-stop mode, finish the state of all threads of that process,
617 but leave other threads alone, as they may be stopped in internal
618 events --- the frontend shouldn't see them as stopped. In
619 all-stop, always finish the state of all threads, as we may be
620 resuming more than just the new process. */
622 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
624 ptid
= minus_one_ptid
;
625 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
627 /* Pass zero for FROM_TTY, because at this point the "run" command
628 has done its thing; now we are setting up the running program. */
629 post_create_inferior (¤t_target
, 0);
631 /* Start the target running. Do not use -1 continuation as it would skip
632 breakpoint right at the entry point. */
633 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
);
635 /* Since there was no error, there's no need to finish the thread
637 discard_cleanups (old_chain
);
641 run_command (char *args
, int from_tty
)
643 run_command_1 (args
, from_tty
, 0);
646 /* Start the execution of the program up until the beginning of the main
650 start_command (char *args
, int from_tty
)
652 /* Some languages such as Ada need to search inside the program
653 minimal symbols for the location where to put the temporary
654 breakpoint before starting. */
655 if (!have_minimal_symbols ())
656 error (_("No symbol table loaded. Use the \"file\" command."));
658 /* Run the program until reaching the main procedure... */
659 run_command_1 (args
, from_tty
, 1);
663 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
665 /* We go through all threads individually instead of compressing
666 into a single target `resume_all' request, because some threads
667 may be stopped in internal breakpoints/events, or stopped waiting
668 for its turn in the displaced stepping queue (that is, they are
669 running && !executing). The target side has no idea about why
670 the thread is stopped, so a `resume_all' command would resume too
671 much. If/when GDB gains a way to tell the target `hold this
672 thread stopped until I say otherwise', then we can optimize
674 if (!is_stopped (thread
->ptid
))
677 switch_to_thread (thread
->ptid
);
678 clear_proceed_status (0);
679 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
684 ensure_valid_thread (void)
686 if (ptid_equal (inferior_ptid
, null_ptid
)
687 || is_exited (inferior_ptid
))
688 error (_("Cannot execute this command without a live selected thread."));
691 /* If the user is looking at trace frames, any resumption of execution
692 is likely to mix up recorded and live target data. So simply
693 disallow those commands. */
696 ensure_not_tfind_mode (void)
698 if (get_traceframe_number () >= 0)
699 error (_("Cannot execute this command while looking at trace frames."));
702 /* Throw an error indicating the current thread is running. */
705 error_is_running (void)
707 error (_("Cannot execute this command while "
708 "the selected thread is running."));
711 /* Calls error_is_running if the current thread is running. */
714 ensure_not_running (void)
716 if (is_running (inferior_ptid
))
721 continue_1 (int all_threads
)
724 ensure_not_tfind_mode ();
726 if (non_stop
&& all_threads
)
728 /* Don't error out if the current thread is running, because
729 there may be other stopped threads. */
730 struct cleanup
*old_chain
;
732 /* Backup current thread and selected frame. */
733 old_chain
= make_cleanup_restore_current_thread ();
735 iterate_over_threads (proceed_thread_callback
, NULL
);
739 /* If all threads in the target were already running,
740 proceed_thread_callback ends up never calling proceed,
741 and so nothing calls this to put the inferior's terminal
742 settings in effect and remove stdin from the event loop,
743 which we must when running a foreground command. E.g.:
747 <all threads are running now>
750 <no thread was resumed, but the inferior now owns the terminal>
752 target_terminal_inferior ();
755 /* Restore selected ptid. */
756 do_cleanups (old_chain
);
760 ensure_valid_thread ();
761 ensure_not_running ();
762 clear_proceed_status (0);
763 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
767 /* continue [-a] [proceed-count] [&] */
770 continue_command (char *args
, int from_tty
)
774 struct cleanup
*args_chain
;
778 /* Find out whether we must run in the background. */
779 args
= strip_bg_char (args
, &async_exec
);
780 args_chain
= make_cleanup (xfree
, args
);
782 prepare_execution_command (¤t_target
, async_exec
);
786 if (startswith (args
, "-a"))
789 args
+= sizeof ("-a") - 1;
795 if (!non_stop
&& all_threads
)
796 error (_("`-a' is meaningless in all-stop mode."));
798 if (args
!= NULL
&& all_threads
)
799 error (_("Can't resume all threads and specify "
800 "proceed count simultaneously."));
802 /* If we have an argument left, set proceed count of breakpoint we
809 struct thread_info
*tp
;
812 tp
= find_thread_ptid (inferior_ptid
);
816 struct target_waitstatus ws
;
818 get_last_target_status (&last_ptid
, &ws
);
819 tp
= find_thread_ptid (last_ptid
);
822 bs
= tp
->control
.stop_bpstat
;
824 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
827 set_ignore_count (num
,
828 parse_and_eval_long (args
) - 1,
830 /* set_ignore_count prints a message ending with a period.
831 So print two spaces before "Continuing.". */
833 printf_filtered (" ");
837 if (!stopped
&& from_tty
)
840 ("Not stopped at any breakpoint; argument ignored.\n");
844 /* Done with ARGS. */
845 do_cleanups (args_chain
);
848 printf_filtered (_("Continuing.\n"));
850 continue_1 (all_threads
);
853 /* Record the starting point of a "step" or "next" command. */
856 set_step_frame (void)
858 struct symtab_and_line sal
;
860 struct frame_info
*frame
= get_current_frame ();
861 struct thread_info
*tp
= inferior_thread ();
863 find_frame_sal (frame
, &sal
);
864 set_step_info (frame
, sal
);
865 pc
= get_frame_pc (frame
);
866 tp
->control
.step_start_function
= find_pc_function (pc
);
869 /* Step until outside of current statement. */
872 step_command (char *count_string
, int from_tty
)
874 step_1 (0, 0, count_string
);
877 /* Likewise, but skip over subroutine calls as if single instructions. */
880 next_command (char *count_string
, int from_tty
)
882 step_1 (1, 0, count_string
);
885 /* Likewise, but step only one instruction. */
888 stepi_command (char *count_string
, int from_tty
)
890 step_1 (0, 1, count_string
);
894 nexti_command (char *count_string
, int from_tty
)
896 step_1 (1, 1, count_string
);
900 delete_longjmp_breakpoint_cleanup (void *arg
)
902 int thread
= * (int *) arg
;
903 delete_longjmp_breakpoint (thread
);
907 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
910 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
913 struct cleanup
*args_chain
;
916 ensure_not_tfind_mode ();
917 ensure_valid_thread ();
918 ensure_not_running ();
920 count_string
= strip_bg_char (count_string
, &async_exec
);
921 args_chain
= make_cleanup (xfree
, count_string
);
923 prepare_execution_command (¤t_target
, async_exec
);
925 count
= count_string
? parse_and_eval_long (count_string
) : 1;
927 /* Done with ARGS. */
928 do_cleanups (args_chain
);
930 if (!single_inst
|| skip_subroutines
) /* Leave si command alone. */
932 struct thread_info
*tp
= inferior_thread ();
934 if (in_thread_list (inferior_ptid
))
935 thread
= pid_to_thread_id (inferior_ptid
);
937 set_longjmp_breakpoint (tp
, get_frame_id (get_current_frame ()));
939 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
942 /* In synchronous case, all is well; each step_once call will step once. */
943 if (!target_can_async_p ())
945 for (; count
> 0; count
--)
947 step_once (skip_subroutines
, single_inst
, count
, thread
);
949 if (!target_has_execution
)
953 struct thread_info
*tp
= inferior_thread ();
955 if (!tp
->control
.stop_step
|| !tp
->step_multi
)
957 /* If we stopped for some reason that is not stepping
958 there are no further steps to make. */
965 do_cleanups (cleanups
);
969 /* In the case of an asynchronous target things get complicated;
970 do only one step for now, before returning control to the
971 event loop. Let the continuation figure out how many other
972 steps we need to do, and handle them one at the time, through
974 step_once (skip_subroutines
, single_inst
, count
, thread
);
976 /* We are running, and the continuation is installed. It will
977 disable the longjmp breakpoint as appropriate. */
978 discard_cleanups (cleanups
);
982 struct step_1_continuation_args
985 int skip_subroutines
;
990 /* Called after we are done with one step operation, to check whether
991 we need to step again, before we print the prompt and return control
992 to the user. If count is > 1, we will need to do one more call to
993 proceed(), via step_once(). Basically it is like step_once and
994 step_1_continuation are co-recursive. */
997 step_1_continuation (void *args
, int err
)
999 struct step_1_continuation_args
*a
= args
;
1001 if (target_has_execution
)
1003 struct thread_info
*tp
;
1005 tp
= inferior_thread ();
1007 && tp
->step_multi
&& tp
->control
.stop_step
)
1009 /* There are more steps to make, and we did stop due to
1010 ending a stepping range. Do another step. */
1011 step_once (a
->skip_subroutines
, a
->single_inst
,
1012 a
->count
- 1, a
->thread
);
1018 /* We either hit an error, or stopped for some reason that is
1019 not stepping, or there are no further steps to make.
1021 if (!a
->single_inst
|| a
->skip_subroutines
)
1022 delete_longjmp_breakpoint (a
->thread
);
1025 /* Do just one step operation. This is useful to implement the 'step
1026 n' kind of commands. In case of asynchronous targets, we will have
1027 to set up a continuation to be done after the target stops (after
1028 this one step). For synch targets, the caller handles further
1032 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
1034 struct frame_info
*frame
= get_current_frame ();
1038 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1039 the longjmp breakpoint was not required. Use the
1040 INFERIOR_PTID thread instead, which is the same thread when
1042 struct thread_info
*tp
= inferior_thread ();
1044 clear_proceed_status (1);
1051 /* Step at an inlined function behaves like "down". */
1052 if (!skip_subroutines
1053 && inline_skipped_frames (inferior_ptid
))
1057 /* Pretend that we've ran. */
1058 resume_ptid
= user_visible_resume_ptid (1);
1059 set_running (resume_ptid
, 1);
1061 step_into_inline_frame (inferior_ptid
);
1063 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
1066 /* Pretend that we've stopped. */
1069 if (target_can_async_p ())
1070 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1075 pc
= get_frame_pc (frame
);
1076 find_pc_line_pc_range (pc
,
1077 &tp
->control
.step_range_start
,
1078 &tp
->control
.step_range_end
);
1080 tp
->control
.may_range_step
= 1;
1082 /* If we have no line info, switch to stepi mode. */
1083 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1085 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1086 tp
->control
.may_range_step
= 0;
1088 else if (tp
->control
.step_range_end
== 0)
1092 if (find_pc_partial_function (pc
, &name
,
1093 &tp
->control
.step_range_start
,
1094 &tp
->control
.step_range_end
) == 0)
1095 error (_("Cannot find bounds of current function"));
1097 target_terminal_ours ();
1098 printf_filtered (_("Single stepping until exit from function %s,"
1099 "\nwhich has no line number information.\n"),
1105 /* Say we are stepping, but stop after one insn whatever it does. */
1106 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1107 if (!skip_subroutines
)
1109 Don't step over function calls, not even to functions lacking
1111 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1114 if (skip_subroutines
)
1115 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1117 tp
->step_multi
= (count
> 1);
1118 tp
->control
.stepping_command
= 1;
1119 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1121 /* For async targets, register a continuation to do any
1122 additional steps. For sync targets, the caller will handle
1123 further stepping. */
1124 if (target_can_async_p ())
1126 struct step_1_continuation_args
*args
;
1128 args
= xmalloc (sizeof (*args
));
1129 args
->skip_subroutines
= skip_subroutines
;
1130 args
->single_inst
= single_inst
;
1131 args
->count
= count
;
1132 args
->thread
= thread
;
1134 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
1140 /* Continue program at specified address. */
1143 jump_command (char *arg
, int from_tty
)
1145 struct gdbarch
*gdbarch
= get_current_arch ();
1147 struct symtabs_and_lines sals
;
1148 struct symtab_and_line sal
;
1152 struct cleanup
*args_chain
;
1155 ensure_not_tfind_mode ();
1156 ensure_valid_thread ();
1157 ensure_not_running ();
1159 /* Find out whether we must run in the background. */
1160 arg
= strip_bg_char (arg
, &async_exec
);
1161 args_chain
= make_cleanup (xfree
, arg
);
1163 prepare_execution_command (¤t_target
, async_exec
);
1166 error_no_arg (_("starting address"));
1168 sals
= decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1169 if (sals
.nelts
!= 1)
1171 error (_("Unreasonable jump request"));
1177 /* Done with ARGS. */
1178 do_cleanups (args_chain
);
1180 if (sal
.symtab
== 0 && sal
.pc
== 0)
1181 error (_("No source file has been specified."));
1183 resolve_sal_pc (&sal
); /* May error out. */
1185 /* See if we are trying to jump to another function. */
1186 fn
= get_frame_function (get_current_frame ());
1187 sfn
= find_pc_function (sal
.pc
);
1188 if (fn
!= NULL
&& sfn
!= fn
)
1190 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1191 SYMBOL_PRINT_NAME (fn
)))
1193 error (_("Not confirmed."));
1200 struct obj_section
*section
;
1202 fixup_symbol_section (sfn
, 0);
1203 section
= SYMBOL_OBJ_SECTION (symbol_objfile (sfn
), sfn
);
1204 if (section_is_overlay (section
)
1205 && !section_is_mapped (section
))
1207 if (!query (_("WARNING!!! Destination is in "
1208 "unmapped overlay! Jump anyway? ")))
1210 error (_("Not confirmed."));
1220 printf_filtered (_("Continuing at "));
1221 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1222 printf_filtered (".\n");
1225 clear_proceed_status (0);
1226 proceed (addr
, GDB_SIGNAL_0
);
1229 /* Continue program giving it specified signal. */
1232 signal_command (char *signum_exp
, int from_tty
)
1234 enum gdb_signal oursig
;
1236 struct cleanup
*args_chain
;
1238 dont_repeat (); /* Too dangerous. */
1240 ensure_not_tfind_mode ();
1241 ensure_valid_thread ();
1242 ensure_not_running ();
1244 /* Find out whether we must run in the background. */
1245 signum_exp
= strip_bg_char (signum_exp
, &async_exec
);
1246 args_chain
= make_cleanup (xfree
, signum_exp
);
1248 prepare_execution_command (¤t_target
, async_exec
);
1251 error_no_arg (_("signal number"));
1253 /* It would be even slicker to make signal names be valid expressions,
1254 (the type could be "enum $signal" or some such), then the user could
1255 assign them to convenience variables. */
1256 oursig
= gdb_signal_from_name (signum_exp
);
1258 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1260 /* No, try numeric. */
1261 int num
= parse_and_eval_long (signum_exp
);
1264 oursig
= GDB_SIGNAL_0
;
1266 oursig
= gdb_signal_from_command (num
);
1269 /* Look for threads other than the current that this command ends up
1270 resuming too (due to schedlock off), and warn if they'll get a
1271 signal delivered. "signal 0" is used to suppress a previous
1272 signal, but if the current thread is no longer the one that got
1273 the signal, then the user is potentially suppressing the signal
1274 of the wrong thread. */
1277 struct thread_info
*tp
;
1279 int must_confirm
= 0;
1281 /* This indicates what will be resumed. Either a single thread,
1282 a whole process, or all threads of all processes. */
1283 resume_ptid
= user_visible_resume_ptid (0);
1285 ALL_NON_EXITED_THREADS (tp
)
1287 if (ptid_equal (tp
->ptid
, inferior_ptid
))
1289 if (!ptid_match (tp
->ptid
, resume_ptid
))
1292 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1293 && signal_pass_state (tp
->suspend
.stop_signal
))
1296 printf_unfiltered (_("Note:\n"));
1297 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1299 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1300 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1306 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1307 "still deliver the signals noted above to their respective threads.\n"
1308 "Continue anyway? "),
1309 inferior_thread ()->num
))
1310 error (_("Not confirmed."));
1315 if (oursig
== GDB_SIGNAL_0
)
1316 printf_filtered (_("Continuing with no signal.\n"));
1318 printf_filtered (_("Continuing with signal %s.\n"),
1319 gdb_signal_to_name (oursig
));
1322 clear_proceed_status (0);
1323 proceed ((CORE_ADDR
) -1, oursig
);
1326 /* Queue a signal to be delivered to the current thread. */
1329 queue_signal_command (char *signum_exp
, int from_tty
)
1331 enum gdb_signal oursig
;
1332 struct thread_info
*tp
;
1335 ensure_not_tfind_mode ();
1336 ensure_valid_thread ();
1337 ensure_not_running ();
1339 if (signum_exp
== NULL
)
1340 error_no_arg (_("signal number"));
1342 /* It would be even slicker to make signal names be valid expressions,
1343 (the type could be "enum $signal" or some such), then the user could
1344 assign them to convenience variables. */
1345 oursig
= gdb_signal_from_name (signum_exp
);
1347 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1349 /* No, try numeric. */
1350 int num
= parse_and_eval_long (signum_exp
);
1353 oursig
= GDB_SIGNAL_0
;
1355 oursig
= gdb_signal_from_command (num
);
1358 if (oursig
!= GDB_SIGNAL_0
1359 && !signal_pass_state (oursig
))
1360 error (_("Signal handling set to not pass this signal to the program."));
1362 tp
= inferior_thread ();
1363 tp
->suspend
.stop_signal
= oursig
;
1366 /* Continuation args to be passed to the "until" command
1368 struct until_next_continuation_args
1370 /* The thread that was current when the command was executed. */
1374 /* A continuation callback for until_next_command. */
1377 until_next_continuation (void *arg
, int err
)
1379 struct until_next_continuation_args
*a
= arg
;
1381 delete_longjmp_breakpoint (a
->thread
);
1384 /* Proceed until we reach a different source line with pc greater than
1385 our current one or exit the function. We skip calls in both cases.
1387 Note that eventually this command should probably be changed so
1388 that only source lines are printed out when we hit the breakpoint
1389 we set. This may involve changes to wait_for_inferior and the
1390 proceed status code. */
1393 until_next_command (int from_tty
)
1395 struct frame_info
*frame
;
1397 struct symbol
*func
;
1398 struct symtab_and_line sal
;
1399 struct thread_info
*tp
= inferior_thread ();
1400 int thread
= tp
->num
;
1401 struct cleanup
*old_chain
;
1403 clear_proceed_status (0);
1406 frame
= get_current_frame ();
1408 /* Step until either exited from this function or greater
1409 than the current line (if in symbolic section) or pc (if
1412 pc
= get_frame_pc (frame
);
1413 func
= find_pc_function (pc
);
1417 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1419 if (msymbol
.minsym
== NULL
)
1420 error (_("Execution is not within a known function."));
1422 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1423 /* The upper-bound of step_range is exclusive. In order to make PC
1424 within the range, set the step_range_end with PC + 1. */
1425 tp
->control
.step_range_end
= pc
+ 1;
1429 sal
= find_pc_line (pc
, 0);
1431 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1432 tp
->control
.step_range_end
= sal
.end
;
1434 tp
->control
.may_range_step
= 1;
1436 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1438 tp
->step_multi
= 0; /* Only one call to proceed */
1440 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1441 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1443 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1445 if (target_can_async_p () && is_running (inferior_ptid
))
1447 struct until_next_continuation_args
*cont_args
;
1449 discard_cleanups (old_chain
);
1450 cont_args
= XNEW (struct until_next_continuation_args
);
1451 cont_args
->thread
= inferior_thread ()->num
;
1453 add_continuation (tp
, until_next_continuation
, cont_args
, xfree
);
1456 do_cleanups (old_chain
);
1460 until_command (char *arg
, int from_tty
)
1463 struct cleanup
*args_chain
;
1466 ensure_not_tfind_mode ();
1467 ensure_valid_thread ();
1468 ensure_not_running ();
1470 /* Find out whether we must run in the background. */
1471 arg
= strip_bg_char (arg
, &async_exec
);
1472 args_chain
= make_cleanup (xfree
, arg
);
1474 prepare_execution_command (¤t_target
, async_exec
);
1477 until_break_command (arg
, from_tty
, 0);
1479 until_next_command (from_tty
);
1481 /* Done with ARGS. */
1482 do_cleanups (args_chain
);
1486 advance_command (char *arg
, int from_tty
)
1489 struct cleanup
*args_chain
;
1492 ensure_not_tfind_mode ();
1493 ensure_valid_thread ();
1494 ensure_not_running ();
1497 error_no_arg (_("a location"));
1499 /* Find out whether we must run in the background. */
1500 arg
= strip_bg_char (arg
, &async_exec
);
1501 args_chain
= make_cleanup (xfree
, arg
);
1503 prepare_execution_command (¤t_target
, async_exec
);
1505 until_break_command (arg
, from_tty
, 1);
1507 /* Done with ARGS. */
1508 do_cleanups (args_chain
);
1511 /* Return the value of the result of a function at the end of a 'finish'
1515 get_return_value (struct value
*function
, struct type
*value_type
)
1517 struct regcache
*stop_regs
= stop_registers
;
1518 struct gdbarch
*gdbarch
;
1519 struct value
*value
;
1520 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
1522 /* If stop_registers were not saved, use the current registers. */
1525 stop_regs
= regcache_dup (get_current_regcache ());
1526 make_cleanup_regcache_xfree (stop_regs
);
1529 gdbarch
= get_regcache_arch (stop_regs
);
1531 CHECK_TYPEDEF (value_type
);
1532 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1534 /* FIXME: 2003-09-27: When returning from a nested inferior function
1535 call, it's possible (with no help from the architecture vector)
1536 to locate and return/print a "struct return" value. This is just
1537 a more complicated case of what is already being done in the
1538 inferior function call code. In fact, when inferior function
1539 calls are made async, this will likely be made the norm. */
1541 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1544 case RETURN_VALUE_REGISTER_CONVENTION
:
1545 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1546 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1547 value
= allocate_value (value_type
);
1548 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1549 value_contents_raw (value
), NULL
);
1551 case RETURN_VALUE_STRUCT_CONVENTION
:
1555 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1558 do_cleanups (cleanup
);
1563 /* Print the result of a function at the end of a 'finish' command. */
1566 print_return_value (struct value
*function
, struct type
*value_type
)
1568 struct value
*value
= get_return_value (function
, value_type
);
1569 struct ui_out
*uiout
= current_uiout
;
1573 struct value_print_options opts
;
1574 struct ui_file
*stb
;
1575 struct cleanup
*old_chain
;
1578 stb
= mem_fileopen ();
1579 old_chain
= make_cleanup_ui_file_delete (stb
);
1580 ui_out_text (uiout
, "Value returned is ");
1581 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1582 record_latest_value (value
));
1583 ui_out_text (uiout
, " = ");
1584 get_no_prettyformat_print_options (&opts
);
1585 value_print (value
, stb
, &opts
);
1586 ui_out_field_stream (uiout
, "return-value", stb
);
1587 ui_out_text (uiout
, "\n");
1588 do_cleanups (old_chain
);
1592 struct cleanup
*oldchain
;
1595 type_name
= type_to_string (value_type
);
1596 oldchain
= make_cleanup (xfree
, type_name
);
1597 ui_out_text (uiout
, "Value returned has type: ");
1598 ui_out_field_string (uiout
, "return-type", type_name
);
1599 ui_out_text (uiout
, ".");
1600 ui_out_text (uiout
, " Cannot determine contents\n");
1601 do_cleanups (oldchain
);
1605 /* Stuff that needs to be done by the finish command after the target
1606 has stopped. In asynchronous mode, we wait for the target to stop
1607 in the call to poll or select in the event loop, so it is
1608 impossible to do all the stuff as part of the finish_command
1609 function itself. The only chance we have to complete this command
1610 is in fetch_inferior_event, which is called by the event loop as
1611 soon as it detects that the target has stopped. */
1613 struct finish_command_continuation_args
1615 /* The thread that as current when the command was executed. */
1617 struct breakpoint
*breakpoint
;
1618 struct symbol
*function
;
1622 finish_command_continuation (void *arg
, int err
)
1624 struct finish_command_continuation_args
*a
= arg
;
1628 struct thread_info
*tp
= NULL
;
1631 if (!ptid_equal (inferior_ptid
, null_ptid
)
1632 && target_has_execution
1633 && is_stopped (inferior_ptid
))
1635 tp
= inferior_thread ();
1636 bs
= tp
->control
.stop_bpstat
;
1639 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1640 && a
->function
!= NULL
)
1642 struct type
*value_type
;
1644 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1646 internal_error (__FILE__
, __LINE__
,
1647 _("finish_command: function has no target type"));
1649 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1653 func
= read_var_value (a
->function
, get_current_frame ());
1656 /* print_return_value can throw an exception in some
1657 circumstances. We need to catch this so that we still
1658 delete the breakpoint. */
1659 print_return_value (func
, value_type
);
1661 CATCH (ex
, RETURN_MASK_ALL
)
1663 exception_print (gdb_stdout
, ex
);
1669 /* We suppress normal call of normal_stop observer and do it
1670 here so that the *stopped notification includes the return
1672 if (bs
!= NULL
&& tp
->control
.proceed_to_finish
)
1673 observer_notify_normal_stop (bs
, 1 /* print frame */);
1676 delete_breakpoint (a
->breakpoint
);
1677 delete_longjmp_breakpoint (a
->thread
);
1681 finish_command_continuation_free_arg (void *arg
)
1686 /* finish_backward -- helper function for finish_command. */
1689 finish_backward (struct symbol
*function
)
1691 struct symtab_and_line sal
;
1692 struct thread_info
*tp
= inferior_thread ();
1694 CORE_ADDR func_addr
;
1696 pc
= get_frame_pc (get_current_frame ());
1698 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1699 error (_("Cannot find bounds of current function"));
1701 sal
= find_pc_line (func_addr
, 0);
1703 tp
->control
.proceed_to_finish
= 1;
1704 /* Special case: if we're sitting at the function entry point,
1705 then all we need to do is take a reverse singlestep. We
1706 don't need to set a breakpoint, and indeed it would do us
1709 Note that this can only happen at frame #0, since there's
1710 no way that a function up the stack can have a return address
1711 that's equal to its entry point. */
1715 struct frame_info
*frame
= get_selected_frame (NULL
);
1716 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1717 struct symtab_and_line sr_sal
;
1719 /* Set a step-resume at the function's entry point. Once that's
1720 hit, we'll do one more step backwards. */
1723 sr_sal
.pspace
= get_frame_program_space (frame
);
1724 insert_step_resume_breakpoint_at_sal (gdbarch
,
1725 sr_sal
, null_frame_id
);
1727 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1731 /* We're almost there -- we just need to back up by one more
1733 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1734 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1738 /* finish_forward -- helper function for finish_command. */
1741 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1743 struct frame_id frame_id
= get_frame_id (frame
);
1744 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1745 struct symtab_and_line sal
;
1746 struct thread_info
*tp
= inferior_thread ();
1747 struct breakpoint
*breakpoint
;
1748 struct cleanup
*old_chain
;
1749 struct finish_command_continuation_args
*cargs
;
1750 int thread
= tp
->num
;
1752 sal
= find_pc_line (get_frame_pc (frame
), 0);
1753 sal
.pc
= get_frame_pc (frame
);
1755 breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1756 get_stack_frame_id (frame
),
1759 /* set_momentary_breakpoint invalidates FRAME. */
1762 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1764 set_longjmp_breakpoint (tp
, frame_id
);
1765 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1767 /* We want stop_registers, please... */
1768 tp
->control
.proceed_to_finish
= 1;
1769 cargs
= xmalloc (sizeof (*cargs
));
1771 cargs
->thread
= thread
;
1772 cargs
->breakpoint
= breakpoint
;
1773 cargs
->function
= function
;
1774 add_continuation (tp
, finish_command_continuation
, cargs
,
1775 finish_command_continuation_free_arg
);
1776 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1778 discard_cleanups (old_chain
);
1779 if (!target_can_async_p ())
1780 do_all_continuations (0);
1783 /* "finish": Set a temporary breakpoint at the place the selected
1784 frame will return to, then continue. */
1787 finish_command (char *arg
, int from_tty
)
1789 struct frame_info
*frame
;
1790 struct symbol
*function
;
1792 struct cleanup
*args_chain
;
1795 ensure_not_tfind_mode ();
1796 ensure_valid_thread ();
1797 ensure_not_running ();
1799 /* Find out whether we must run in the background. */
1800 arg
= strip_bg_char (arg
, &async_exec
);
1801 args_chain
= make_cleanup (xfree
, arg
);
1803 prepare_execution_command (¤t_target
, async_exec
);
1806 error (_("The \"finish\" command does not take any arguments."));
1808 /* Done with ARGS. */
1809 do_cleanups (args_chain
);
1811 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1813 error (_("\"finish\" not meaningful in the outermost frame."));
1815 clear_proceed_status (0);
1817 /* Finishing from an inline frame is completely different. We don't
1818 try to show the "return value" - no way to locate it. So we do
1819 not need a completion. */
1820 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1823 /* Claim we are stepping in the calling frame. An empty step
1824 range means that we will stop once we aren't in a function
1825 called by that frame. We don't use the magic "1" value for
1826 step_range_end, because then infrun will think this is nexti,
1827 and not step over the rest of this inlined function call. */
1828 struct thread_info
*tp
= inferior_thread ();
1829 struct symtab_and_line empty_sal
;
1831 init_sal (&empty_sal
);
1832 set_step_info (frame
, empty_sal
);
1833 tp
->control
.step_range_start
= get_frame_pc (frame
);
1834 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1835 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1837 /* Print info on the selected frame, including level number but not
1841 printf_filtered (_("Run till exit from "));
1842 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1845 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
1849 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1850 entering THISFRAME. */
1851 while (get_frame_type (frame
) == TAILCALL_FRAME
)
1852 frame
= get_prev_frame (frame
);
1854 /* Find the function we will return from. */
1856 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1858 /* Print info on the selected frame, including level number but not
1862 if (execution_direction
== EXEC_REVERSE
)
1863 printf_filtered (_("Run back to call of "));
1866 if (function
!= NULL
&& TYPE_NO_RETURN (function
->type
)
1867 && !query (_("warning: Function %s does not return normally.\n"
1868 "Try to finish anyway? "),
1869 SYMBOL_PRINT_NAME (function
)))
1870 error (_("Not confirmed."));
1871 printf_filtered (_("Run till exit from "));
1874 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1877 if (execution_direction
== EXEC_REVERSE
)
1878 finish_backward (function
);
1880 finish_forward (function
, frame
);
1885 program_info (char *args
, int from_tty
)
1889 struct thread_info
*tp
;
1892 if (!target_has_execution
)
1894 printf_filtered (_("The program being debugged is not being run.\n"));
1899 ptid
= inferior_ptid
;
1902 struct target_waitstatus ws
;
1904 get_last_target_status (&ptid
, &ws
);
1907 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1908 error (_("Invalid selected thread."));
1909 else if (is_running (ptid
))
1910 error (_("Selected thread is running."));
1912 tp
= find_thread_ptid (ptid
);
1913 bs
= tp
->control
.stop_bpstat
;
1914 stat
= bpstat_num (&bs
, &num
);
1916 target_files_info ();
1917 printf_filtered (_("Program stopped at %s.\n"),
1918 paddress (target_gdbarch (), stop_pc
));
1919 if (tp
->control
.stop_step
)
1920 printf_filtered (_("It stopped after being stepped.\n"));
1923 /* There may be several breakpoints in the same place, so this
1924 isn't as strange as it seems. */
1929 printf_filtered (_("It stopped at a breakpoint "
1930 "that has since been deleted.\n"));
1933 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1934 stat
= bpstat_num (&bs
, &num
);
1937 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
1939 printf_filtered (_("It stopped with signal %s, %s.\n"),
1940 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1941 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1946 printf_filtered (_("Type \"info stack\" or \"info "
1947 "registers\" for more information.\n"));
1952 environment_info (char *var
, int from_tty
)
1956 char *val
= get_in_environ (current_inferior ()->environment
, var
);
1960 puts_filtered (var
);
1961 puts_filtered (" = ");
1962 puts_filtered (val
);
1963 puts_filtered ("\n");
1967 puts_filtered ("Environment variable \"");
1968 puts_filtered (var
);
1969 puts_filtered ("\" not defined.\n");
1974 char **vector
= environ_vector (current_inferior ()->environment
);
1978 puts_filtered (*vector
++);
1979 puts_filtered ("\n");
1985 set_environment_command (char *arg
, int from_tty
)
1987 char *p
, *val
, *var
;
1991 error_no_arg (_("environment variable and value"));
1993 /* Find seperation between variable name and value. */
1994 p
= (char *) strchr (arg
, '=');
1995 val
= (char *) strchr (arg
, ' ');
1997 if (p
!= 0 && val
!= 0)
1999 /* We have both a space and an equals. If the space is before the
2000 equals, walk forward over the spaces til we see a nonspace
2001 (possibly the equals). */
2006 /* Now if the = is after the char following the spaces,
2007 take the char following the spaces. */
2011 else if (val
!= 0 && p
== 0)
2015 error_no_arg (_("environment variable to set"));
2017 if (p
== 0 || p
[1] == 0)
2021 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
2025 /* Not setting variable value to null. */
2027 while (*val
== ' ' || *val
== '\t')
2031 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
2034 var
= savestring (arg
, p
- arg
);
2037 printf_filtered (_("Setting environment variable "
2038 "\"%s\" to null value.\n"),
2040 set_in_environ (current_inferior ()->environment
, var
, "");
2043 set_in_environ (current_inferior ()->environment
, var
, val
);
2048 unset_environment_command (char *var
, int from_tty
)
2052 /* If there is no argument, delete all environment variables.
2053 Ask for confirmation if reading from the terminal. */
2054 if (!from_tty
|| query (_("Delete all environment variables? ")))
2056 free_environ (current_inferior ()->environment
);
2057 current_inferior ()->environment
= make_environ ();
2061 unset_in_environ (current_inferior ()->environment
, var
);
2064 /* Handle the execution path (PATH variable). */
2066 static const char path_var_name
[] = "PATH";
2069 path_info (char *args
, int from_tty
)
2071 puts_filtered ("Executable and object file path: ");
2072 puts_filtered (get_in_environ (current_inferior ()->environment
,
2074 puts_filtered ("\n");
2077 /* Add zero or more directories to the front of the execution path. */
2080 path_command (char *dirname
, int from_tty
)
2086 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
2087 /* Can be null if path is not set. */
2090 exec_path
= xstrdup (env
);
2091 mod_path (dirname
, &exec_path
);
2092 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
2095 path_info ((char *) NULL
, from_tty
);
2099 /* Print out the register NAME with value VAL, to FILE, in the default
2103 default_print_one_register_info (struct ui_file
*file
,
2107 struct type
*regtype
= value_type (val
);
2108 int print_raw_format
;
2110 fputs_filtered (name
, file
);
2111 print_spaces_filtered (15 - strlen (name
), file
);
2113 print_raw_format
= (value_entirely_available (val
)
2114 && !value_optimized_out (val
));
2116 /* If virtual format is floating, print it that way, and in raw
2118 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
2119 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2122 struct value_print_options opts
;
2123 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2124 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (regtype
));
2126 get_user_print_options (&opts
);
2130 value_contents_for_printing (val
),
2131 value_embedded_offset (val
), 0,
2132 file
, 0, val
, &opts
, current_language
);
2134 if (print_raw_format
)
2136 fprintf_filtered (file
, "\t(raw ");
2137 print_hex_chars (file
, valaddr
, TYPE_LENGTH (regtype
), byte_order
);
2138 fprintf_filtered (file
, ")");
2143 struct value_print_options opts
;
2145 /* Print the register in hex. */
2146 get_formatted_print_options (&opts
, 'x');
2149 value_contents_for_printing (val
),
2150 value_embedded_offset (val
), 0,
2151 file
, 0, val
, &opts
, current_language
);
2152 /* If not a vector register, print it also according to its
2154 if (print_raw_format
&& TYPE_VECTOR (regtype
) == 0)
2156 get_user_print_options (&opts
);
2158 fprintf_filtered (file
, "\t");
2160 value_contents_for_printing (val
),
2161 value_embedded_offset (val
), 0,
2162 file
, 0, val
, &opts
, current_language
);
2166 fprintf_filtered (file
, "\n");
2169 /* Print out the machine register regnum. If regnum is -1, print all
2170 registers (print_all == 1) or all non-float and non-vector
2171 registers (print_all == 0).
2173 For most machines, having all_registers_info() print the
2174 register(s) one per line is good enough. If a different format is
2175 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2176 regs), or there is an existing convention for showing all the
2177 registers, define the architecture method PRINT_REGISTERS_INFO to
2178 provide that format. */
2181 default_print_registers_info (struct gdbarch
*gdbarch
,
2182 struct ui_file
*file
,
2183 struct frame_info
*frame
,
2184 int regnum
, int print_all
)
2187 const int numregs
= gdbarch_num_regs (gdbarch
)
2188 + gdbarch_num_pseudo_regs (gdbarch
);
2190 for (i
= 0; i
< numregs
; i
++)
2192 /* Decide between printing all regs, non-float / vector regs, or
2198 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2203 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2213 /* If the register name is empty, it is undefined for this
2214 processor, so don't display anything. */
2215 if (gdbarch_register_name (gdbarch
, i
) == NULL
2216 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2219 default_print_one_register_info (file
,
2220 gdbarch_register_name (gdbarch
, i
),
2221 value_of_register (i
, frame
));
2226 registers_info (char *addr_exp
, int fpregs
)
2228 struct frame_info
*frame
;
2229 struct gdbarch
*gdbarch
;
2231 if (!target_has_registers
)
2232 error (_("The program has no registers now."));
2233 frame
= get_selected_frame (NULL
);
2234 gdbarch
= get_frame_arch (frame
);
2238 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2243 while (*addr_exp
!= '\0')
2248 /* Skip leading white space. */
2249 addr_exp
= skip_spaces (addr_exp
);
2251 /* Discard any leading ``$''. Check that there is something
2252 resembling a register following it. */
2253 if (addr_exp
[0] == '$')
2255 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2256 error (_("Missing register name"));
2258 /* Find the start/end of this register name/num/group. */
2260 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2264 /* Figure out what we've found and display it. */
2266 /* A register name? */
2268 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2272 /* User registers lie completely outside of the range of
2273 normal registers. Catch them early so that the target
2275 if (regnum
>= gdbarch_num_regs (gdbarch
)
2276 + gdbarch_num_pseudo_regs (gdbarch
))
2278 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2279 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2282 /* Print in the same fashion
2283 gdbarch_print_registers_info's default
2284 implementation prints. */
2285 default_print_one_register_info (gdb_stdout
,
2290 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2291 frame
, regnum
, fpregs
);
2296 /* A register group? */
2298 struct reggroup
*group
;
2300 for (group
= reggroup_next (gdbarch
, NULL
);
2302 group
= reggroup_next (gdbarch
, group
))
2304 /* Don't bother with a length check. Should the user
2305 enter a short register group name, go with the first
2306 group that matches. */
2307 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2315 regnum
< gdbarch_num_regs (gdbarch
)
2316 + gdbarch_num_pseudo_regs (gdbarch
);
2319 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2320 gdbarch_print_registers_info (gdbarch
,
2328 /* Nothing matched. */
2329 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2334 all_registers_info (char *addr_exp
, int from_tty
)
2336 registers_info (addr_exp
, 1);
2340 nofp_registers_info (char *addr_exp
, int from_tty
)
2342 registers_info (addr_exp
, 0);
2346 print_vector_info (struct ui_file
*file
,
2347 struct frame_info
*frame
, const char *args
)
2349 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2351 if (gdbarch_print_vector_info_p (gdbarch
))
2352 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2356 int printed_something
= 0;
2359 regnum
< gdbarch_num_regs (gdbarch
)
2360 + gdbarch_num_pseudo_regs (gdbarch
);
2363 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2365 printed_something
= 1;
2366 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2369 if (!printed_something
)
2370 fprintf_filtered (file
, "No vector information\n");
2375 vector_info (char *args
, int from_tty
)
2377 if (!target_has_registers
)
2378 error (_("The program has no registers now."));
2380 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2383 /* Kill the inferior process. Make us have no inferior. */
2386 kill_command (char *arg
, int from_tty
)
2388 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2389 It should be a distinct flag that indicates that a target is active, cuz
2390 some targets don't have processes! */
2392 if (ptid_equal (inferior_ptid
, null_ptid
))
2393 error (_("The program is not being run."));
2394 if (!query (_("Kill the program being debugged? ")))
2395 error (_("Not confirmed."));
2398 /* If we still have other inferiors to debug, then don't mess with
2399 with their threads. */
2400 if (!have_inferiors ())
2402 init_thread_list (); /* Destroy thread info. */
2404 /* Killing off the inferior can leave us with a core file. If
2405 so, print the state we are left in. */
2406 if (target_has_stack
)
2408 printf_filtered (_("In %s,\n"), target_longname
);
2409 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2412 bfd_cache_close_all ();
2415 /* Used in `attach&' command. ARG is a point to an integer
2416 representing a process id. Proceed threads of this process iff
2417 they stopped due to debugger request, and when they did, they
2418 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
2419 that have been explicitly been told to stop. */
2422 proceed_after_attach_callback (struct thread_info
*thread
,
2425 int pid
= * (int *) arg
;
2427 if (ptid_get_pid (thread
->ptid
) == pid
2428 && !is_exited (thread
->ptid
)
2429 && !is_executing (thread
->ptid
)
2430 && !thread
->stop_requested
2431 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2433 switch_to_thread (thread
->ptid
);
2434 clear_proceed_status (0);
2435 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2442 proceed_after_attach (int pid
)
2444 /* Don't error out if the current thread is running, because
2445 there may be other stopped threads. */
2446 struct cleanup
*old_chain
;
2448 /* Backup current thread and selected frame. */
2449 old_chain
= make_cleanup_restore_current_thread ();
2451 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2453 /* Restore selected ptid. */
2454 do_cleanups (old_chain
);
2457 /* attach_command --
2458 takes a program started up outside of gdb and ``attaches'' to it.
2459 This stops it cold in its tracks and allows us to start debugging it.
2460 and wait for the trace-trap that results from attaching. */
2463 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2465 struct inferior
*inferior
;
2467 inferior
= current_inferior ();
2468 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2470 /* If no exec file is yet known, try to determine it from the
2472 if (get_exec_file (0) == NULL
)
2473 exec_file_locate_attach (ptid_get_pid (inferior_ptid
), from_tty
);
2476 reopen_exec_file ();
2480 /* Take any necessary post-attaching actions for this platform. */
2481 target_post_attach (ptid_get_pid (inferior_ptid
));
2483 post_create_inferior (¤t_target
, from_tty
);
2487 /* The user requested an `attach&', so be sure to leave threads
2488 that didn't get a signal running. */
2490 /* Immediatelly resume all suspended threads of this inferior,
2491 and this inferior only. This should have no effect on
2492 already running threads. If a thread has been stopped with a
2493 signal, leave it be. */
2495 proceed_after_attach (inferior
->pid
);
2498 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2500 clear_proceed_status (0);
2501 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
2507 /* The user requested a plain `attach', so be sure to leave
2508 the inferior stopped. */
2510 if (target_can_async_p ())
2511 async_enable_stdin ();
2513 /* At least the current thread is already stopped. */
2515 /* In all-stop, by definition, all threads have to be already
2516 stopped at this point. In non-stop, however, although the
2517 selected thread is stopped, others may still be executing.
2518 Be sure to explicitly stop all threads of the process. This
2519 should have no effect on already stopped threads. */
2521 target_stop (pid_to_ptid (inferior
->pid
));
2523 /* Tell the user/frontend where we're stopped. */
2525 if (deprecated_attach_hook
)
2526 deprecated_attach_hook ();
2530 struct attach_command_continuation_args
2538 attach_command_continuation (void *args
, int err
)
2540 struct attach_command_continuation_args
*a
= args
;
2545 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2549 attach_command_continuation_free_args (void *args
)
2551 struct attach_command_continuation_args
*a
= args
;
2558 attach_command (char *args
, int from_tty
)
2561 struct cleanup
*args_chain
;
2562 struct target_ops
*attach_target
;
2564 dont_repeat (); /* Not for the faint of heart */
2566 if (gdbarch_has_global_solist (target_gdbarch ()))
2567 /* Don't complain if all processes share the same symbol
2570 else if (target_has_execution
)
2572 if (query (_("A program is being debugged already. Kill it? ")))
2575 error (_("Not killed."));
2578 /* Clean up any leftovers from other runs. Some other things from
2579 this function should probably be moved into target_pre_inferior. */
2580 target_pre_inferior (from_tty
);
2582 args
= strip_bg_char (args
, &async_exec
);
2583 args_chain
= make_cleanup (xfree
, args
);
2585 attach_target
= find_attach_target ();
2587 prepare_execution_command (attach_target
, async_exec
);
2589 if (non_stop
&& !attach_target
->to_supports_non_stop (attach_target
))
2590 error (_("Cannot attach to this target in non-stop mode"));
2592 attach_target
->to_attach (attach_target
, args
, from_tty
);
2593 /* to_attach should push the target, so after this point we
2594 shouldn't refer to attach_target again. */
2595 attach_target
= NULL
;
2597 /* Done with ARGS. */
2598 do_cleanups (args_chain
);
2600 /* Set up the "saved terminal modes" of the inferior
2601 based on what modes we are starting it with. */
2602 target_terminal_init ();
2604 /* Install inferior's terminal modes. This may look like a no-op,
2605 as we've just saved them above, however, this does more than
2606 restore terminal settings:
2608 - installs a SIGINT handler that forwards SIGINT to the inferior.
2609 Otherwise a Ctrl-C pressed just while waiting for the initial
2610 stop would end up as a spurious Quit.
2612 - removes stdin from the event loop, which we need if attaching
2613 in the foreground, otherwise on targets that report an initial
2614 stop on attach (which are most) we'd process input/commands
2615 while we're in the event loop waiting for that stop. That is,
2616 before the attach continuation runs and the command is really
2618 target_terminal_inferior ();
2620 /* Set up execution context to know that we should return from
2621 wait_for_inferior as soon as the target reports a stop. */
2622 init_wait_for_inferior ();
2623 clear_proceed_status (0);
2627 /* If we find that the current thread isn't stopped, explicitly
2628 do so now, because we're going to install breakpoints and
2632 /* The user requested an `attach&'; stop just one thread. */
2633 target_stop (inferior_ptid
);
2635 /* The user requested an `attach', so stop all threads of this
2637 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2640 /* Some system don't generate traps when attaching to inferior.
2641 E.g. Mach 3 or GNU hurd. */
2642 if (!target_attach_no_wait
)
2644 struct inferior
*inferior
= current_inferior ();
2646 /* Careful here. See comments in inferior.h. Basically some
2647 OSes don't ignore SIGSTOPs on continue requests anymore. We
2648 need a way for handle_inferior_event to reset the stop_signal
2649 variable after an attach, and this is what
2650 STOP_QUIETLY_NO_SIGSTOP is for. */
2651 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2653 if (target_can_async_p ())
2655 /* sync_execution mode. Wait for stop. */
2656 struct attach_command_continuation_args
*a
;
2658 a
= xmalloc (sizeof (*a
));
2659 a
->args
= xstrdup (args
);
2660 a
->from_tty
= from_tty
;
2661 a
->async_exec
= async_exec
;
2662 add_inferior_continuation (attach_command_continuation
, a
,
2663 attach_command_continuation_free_args
);
2667 wait_for_inferior ();
2670 attach_command_post_wait (args
, from_tty
, async_exec
);
2673 /* We had just found out that the target was already attached to an
2674 inferior. PTID points at a thread of this new inferior, that is
2675 the most likely to be stopped right now, but not necessarily so.
2676 The new inferior is assumed to be already added to the inferior
2677 list at this point. If LEAVE_RUNNING, then leave the threads of
2678 this inferior running, except those we've explicitly seen reported
2682 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2684 struct cleanup
* old_chain
;
2687 old_chain
= make_cleanup (null_cleanup
, NULL
);
2689 /* If in non-stop, leave threads as running as they were. If
2690 they're stopped for some reason other than us telling it to, the
2691 target reports a signal != GDB_SIGNAL_0. We don't try to
2692 resume threads with such a stop signal. */
2693 async_exec
= non_stop
;
2695 if (!ptid_equal (inferior_ptid
, null_ptid
))
2696 make_cleanup_restore_current_thread ();
2698 switch_to_thread (ptid
);
2700 /* When we "notice" a new inferior we need to do all the things we
2701 would normally do if we had just attached to it. */
2703 if (is_executing (inferior_ptid
))
2705 struct inferior
*inferior
= current_inferior ();
2707 /* We're going to install breakpoints, and poke at memory,
2708 ensure that the inferior is stopped for a moment while we do
2710 target_stop (inferior_ptid
);
2712 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2714 /* Wait for stop before proceeding. */
2715 if (target_can_async_p ())
2717 struct attach_command_continuation_args
*a
;
2719 a
= xmalloc (sizeof (*a
));
2720 a
->args
= xstrdup ("");
2721 a
->from_tty
= from_tty
;
2722 a
->async_exec
= async_exec
;
2723 add_inferior_continuation (attach_command_continuation
, a
,
2724 attach_command_continuation_free_args
);
2726 do_cleanups (old_chain
);
2730 wait_for_inferior ();
2733 async_exec
= leave_running
;
2734 attach_command_post_wait ("" /* args */, from_tty
, async_exec
);
2736 do_cleanups (old_chain
);
2741 * takes a program previously attached to and detaches it.
2742 * The program resumes execution and will no longer stop
2743 * on signals, etc. We better not have left any breakpoints
2744 * in the program or it'll die when it hits one. For this
2745 * to work, it may be necessary for the process to have been
2746 * previously attached. It *might* work if the program was
2747 * started via the normal ptrace (PTRACE_TRACEME).
2751 detach_command (char *args
, int from_tty
)
2753 dont_repeat (); /* Not for the faint of heart. */
2755 if (ptid_equal (inferior_ptid
, null_ptid
))
2756 error (_("The program is not being run."));
2758 query_if_trace_running (from_tty
);
2760 disconnect_tracing ();
2762 target_detach (args
, from_tty
);
2764 /* If the solist is global across inferiors, don't clear it when we
2765 detach from a single inferior. */
2766 if (!gdbarch_has_global_solist (target_gdbarch ()))
2767 no_shared_libraries (NULL
, from_tty
);
2769 /* If we still have inferiors to debug, then don't mess with their
2771 if (!have_inferiors ())
2772 init_thread_list ();
2774 if (deprecated_detach_hook
)
2775 deprecated_detach_hook ();
2778 /* Disconnect from the current target without resuming it (leaving it
2779 waiting for a debugger).
2781 We'd better not have left any breakpoints in the program or the
2782 next debugger will get confused. Currently only supported for some
2783 remote targets, since the normal attach mechanisms don't work on
2784 stopped processes on some native platforms (e.g. GNU/Linux). */
2787 disconnect_command (char *args
, int from_tty
)
2789 dont_repeat (); /* Not for the faint of heart. */
2790 query_if_trace_running (from_tty
);
2791 disconnect_tracing ();
2792 target_disconnect (args
, from_tty
);
2793 no_shared_libraries (NULL
, from_tty
);
2794 init_thread_list ();
2795 if (deprecated_detach_hook
)
2796 deprecated_detach_hook ();
2800 interrupt_target_1 (int all_threads
)
2805 ptid
= minus_one_ptid
;
2807 ptid
= inferior_ptid
;
2810 /* Tag the thread as having been explicitly requested to stop, so
2811 other parts of gdb know not to resume this thread automatically,
2812 if it was stopped due to an internal event. Limit this to
2813 non-stop mode, as when debugging a multi-threaded application in
2814 all-stop mode, we will only get one stop event --- it's undefined
2815 which thread will report the event. */
2817 set_stop_requested (ptid
, 1);
2821 Stop the execution of the target while running in async mode, in
2822 the backgound. In all-stop, stop the whole process. In non-stop
2823 mode, stop the current thread only by default, or stop all threads
2824 if the `-a' switch is used. */
2827 interrupt_command (char *args
, int from_tty
)
2829 if (target_can_async_p ())
2831 int all_threads
= 0;
2833 dont_repeat (); /* Not for the faint of heart. */
2836 && startswith (args
, "-a"))
2839 if (!non_stop
&& all_threads
)
2840 error (_("-a is meaningless in all-stop mode."));
2842 interrupt_target_1 (all_threads
);
2846 /* See inferior.h. */
2849 default_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
2850 struct frame_info
*frame
, const char *args
)
2853 int printed_something
= 0;
2856 regnum
< gdbarch_num_regs (gdbarch
)
2857 + gdbarch_num_pseudo_regs (gdbarch
);
2860 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2862 printed_something
= 1;
2863 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2866 if (!printed_something
)
2867 fprintf_filtered (file
, "No floating-point info "
2868 "available for this processor.\n");
2872 float_info (char *args
, int from_tty
)
2874 struct frame_info
*frame
;
2876 if (!target_has_registers
)
2877 error (_("The program has no registers now."));
2879 frame
= get_selected_frame (NULL
);
2880 gdbarch_print_float_info (get_frame_arch (frame
), gdb_stdout
, frame
, args
);
2884 unset_command (char *args
, int from_tty
)
2886 printf_filtered (_("\"unset\" must be followed by the "
2887 "name of an unset subcommand.\n"));
2888 help_list (unsetlist
, "unset ", all_commands
, gdb_stdout
);
2891 /* Implement `info proc' family of commands. */
2894 info_proc_cmd_1 (char *args
, enum info_proc_what what
, int from_tty
)
2896 struct gdbarch
*gdbarch
= get_current_arch ();
2898 if (!target_info_proc (args
, what
))
2900 if (gdbarch_info_proc_p (gdbarch
))
2901 gdbarch_info_proc (gdbarch
, args
, what
);
2903 error (_("Not supported on this target."));
2907 /* Implement `info proc' when given without any futher parameters. */
2910 info_proc_cmd (char *args
, int from_tty
)
2912 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
2915 /* Implement `info proc mappings'. */
2918 info_proc_cmd_mappings (char *args
, int from_tty
)
2920 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
2923 /* Implement `info proc stat'. */
2926 info_proc_cmd_stat (char *args
, int from_tty
)
2928 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
2931 /* Implement `info proc status'. */
2934 info_proc_cmd_status (char *args
, int from_tty
)
2936 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
2939 /* Implement `info proc cwd'. */
2942 info_proc_cmd_cwd (char *args
, int from_tty
)
2944 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
2947 /* Implement `info proc cmdline'. */
2950 info_proc_cmd_cmdline (char *args
, int from_tty
)
2952 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
2955 /* Implement `info proc exe'. */
2958 info_proc_cmd_exe (char *args
, int from_tty
)
2960 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
2963 /* Implement `info proc all'. */
2966 info_proc_cmd_all (char *args
, int from_tty
)
2968 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
2972 _initialize_infcmd (void)
2974 static struct cmd_list_element
*info_proc_cmdlist
;
2975 struct cmd_list_element
*c
= NULL
;
2976 const char *cmd_name
;
2978 /* Add the filename of the terminal connected to inferior I/O. */
2979 add_setshow_filename_cmd ("inferior-tty", class_run
,
2980 &inferior_io_terminal_scratch
, _("\
2981 Set terminal for future runs of program being debugged."), _("\
2982 Show terminal for future runs of program being debugged."), _("\
2983 Usage: set inferior-tty /dev/pts/1"),
2984 set_inferior_tty_command
,
2985 show_inferior_tty_command
,
2986 &setlist
, &showlist
);
2987 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2990 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
2991 &inferior_args_scratch
, _("\
2992 Set argument list to give program being debugged when it is started."), _("\
2993 Show argument list to give program being debugged when it is started."), _("\
2994 Follow this command with any number of args, to be passed to the program."),
2997 &setlist
, &showlist
);
2998 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
2999 gdb_assert (c
!= NULL
);
3000 set_cmd_completer (c
, filename_completer
);
3002 c
= add_cmd ("environment", no_class
, environment_info
, _("\
3003 The environment to give the program, or one variable's value.\n\
3004 With an argument VAR, prints the value of environment variable VAR to\n\
3005 give the program being debugged. With no arguments, prints the entire\n\
3006 environment to be given to the program."), &showlist
);
3007 set_cmd_completer (c
, noop_completer
);
3009 add_prefix_cmd ("unset", no_class
, unset_command
,
3010 _("Complement to certain \"set\" commands."),
3011 &unsetlist
, "unset ", 0, &cmdlist
);
3013 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
3014 Cancel environment variable VAR for the program.\n\
3015 This does not affect the program until the next \"run\" command."),
3017 set_cmd_completer (c
, noop_completer
);
3019 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
3020 Set environment variable value to give the program.\n\
3021 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
3022 VALUES of environment variables are uninterpreted strings.\n\
3023 This does not affect the program until the next \"run\" command."),
3025 set_cmd_completer (c
, noop_completer
);
3027 c
= add_com ("path", class_files
, path_command
, _("\
3028 Add directory DIR(s) to beginning of search path for object files.\n\
3029 $cwd in the path means the current working directory.\n\
3030 This path is equivalent to the $PATH shell variable. It is a list of\n\
3031 directories, separated by colons. These directories are searched to find\n\
3032 fully linked executable files and separately compiled object files as \
3034 set_cmd_completer (c
, filename_completer
);
3036 c
= add_cmd ("paths", no_class
, path_info
, _("\
3037 Current search path for finding object files.\n\
3038 $cwd in the path means the current working directory.\n\
3039 This path is equivalent to the $PATH shell variable. It is a list of\n\
3040 directories, separated by colons. These directories are searched to find\n\
3041 fully linked executable files and separately compiled object files as \
3044 set_cmd_completer (c
, noop_completer
);
3046 add_prefix_cmd ("kill", class_run
, kill_command
,
3047 _("Kill execution of program being debugged."),
3048 &killlist
, "kill ", 0, &cmdlist
);
3050 add_com ("attach", class_run
, attach_command
, _("\
3051 Attach to a process or file outside of GDB.\n\
3052 This command attaches to another target, of the same type as your last\n\
3053 \"target\" command (\"info files\" will show your target stack).\n\
3054 The command may take as argument a process id or a device file.\n\
3055 For a process id, you must have permission to send the process a signal,\n\
3056 and it must have the same effective uid as the debugger.\n\
3057 When using \"attach\" with a process id, the debugger finds the\n\
3058 program running in the process, looking first in the current working\n\
3059 directory, or (if not found there) using the source file search path\n\
3060 (see the \"directory\" command). You can also use the \"file\" command\n\
3061 to specify the program, and to load its symbol table."));
3063 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3064 Detach a process or file previously attached.\n\
3065 If a process, it is no longer traced, and it continues its execution. If\n\
3066 you were debugging a file, the file is closed and gdb no longer accesses it."),
3067 &detachlist
, "detach ", 0, &cmdlist
);
3069 add_com ("disconnect", class_run
, disconnect_command
, _("\
3070 Disconnect from a target.\n\
3071 The target will wait for another debugger to connect. Not available for\n\
3074 c
= add_com ("signal", class_run
, signal_command
, _("\
3075 Continue program with the specified signal.\n\
3076 Usage: signal SIGNAL\n\
3077 The SIGNAL argument is processed the same as the handle command.\n\
3079 An argument of \"0\" means continue the program without sending it a signal.\n\
3080 This is useful in cases where the program stopped because of a signal,\n\
3081 and you want to resume the program while discarding the signal.\n\
3083 In a multi-threaded program the signal is delivered to, or discarded from,\n\
3084 the current thread only."));
3085 set_cmd_completer (c
, signal_completer
);
3087 c
= add_com ("queue-signal", class_run
, queue_signal_command
, _("\
3088 Queue a signal to be delivered to the current thread when it is resumed.\n\
3089 Usage: queue-signal SIGNAL\n\
3090 The SIGNAL argument is processed the same as the handle command.\n\
3091 It is an error if the handling state of SIGNAL is \"nopass\".\n\
3093 An argument of \"0\" means remove any currently queued signal from\n\
3094 the current thread. This is useful in cases where the program stopped\n\
3095 because of a signal, and you want to resume it while discarding the signal.\n\
3097 In a multi-threaded program the signal is queued with, or discarded from,\n\
3098 the current thread only."));
3099 set_cmd_completer (c
, signal_completer
);
3101 add_com ("stepi", class_run
, stepi_command
, _("\
3102 Step one instruction exactly.\n\
3104 Argument N means step N times (or till program stops for another \
3106 add_com_alias ("si", "stepi", class_alias
, 0);
3108 add_com ("nexti", class_run
, nexti_command
, _("\
3109 Step one instruction, but proceed through subroutine calls.\n\
3111 Argument N means step N times (or till program stops for another \
3113 add_com_alias ("ni", "nexti", class_alias
, 0);
3115 add_com ("finish", class_run
, finish_command
, _("\
3116 Execute until selected stack frame returns.\n\
3118 Upon return, the value returned is printed and put in the value history."));
3119 add_com_alias ("fin", "finish", class_run
, 1);
3121 add_com ("next", class_run
, next_command
, _("\
3122 Step program, proceeding through subroutine calls.\n\
3124 Unlike \"step\", if the current source line calls a subroutine,\n\
3125 this command does not enter the subroutine, but instead steps over\n\
3126 the call, in effect treating it as a single source line."));
3127 add_com_alias ("n", "next", class_run
, 1);
3129 add_com ("step", class_run
, step_command
, _("\
3130 Step program until it reaches a different source line.\n\
3132 Argument N means step N times (or till program stops for another \
3134 add_com_alias ("s", "step", class_run
, 1);
3136 c
= add_com ("until", class_run
, until_command
, _("\
3137 Execute until the program reaches a source line greater than the current\n\
3138 or a specified location (same args as break command) within the current \
3140 set_cmd_completer (c
, location_completer
);
3141 add_com_alias ("u", "until", class_run
, 1);
3143 c
= add_com ("advance", class_run
, advance_command
, _("\
3144 Continue the program up to the given location (same form as args for break \
3146 Execution will also stop upon exit from the current stack frame."));
3147 set_cmd_completer (c
, location_completer
);
3149 c
= add_com ("jump", class_run
, jump_command
, _("\
3150 Continue program being debugged at specified line or address.\n\
3151 Usage: jump <location>\n\
3152 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3153 for an address to start at."));
3154 set_cmd_completer (c
, location_completer
);
3155 add_com_alias ("j", "jump", class_run
, 1);
3157 add_com ("continue", class_run
, continue_command
, _("\
3158 Continue program being debugged, after signal or breakpoint.\n\
3159 Usage: continue [N]\n\
3160 If proceeding from breakpoint, a number N may be used as an argument,\n\
3161 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3162 the breakpoint won't break until the Nth time it is reached).\n\
3164 If non-stop mode is enabled, continue only the current thread,\n\
3165 otherwise all the threads in the program are continued. To \n\
3166 continue all stopped threads in non-stop mode, use the -a option.\n\
3167 Specifying -a and an ignore count simultaneously is an error."));
3168 add_com_alias ("c", "cont", class_run
, 1);
3169 add_com_alias ("fg", "cont", class_run
, 1);
3171 c
= add_com ("run", class_run
, run_command
, _("\
3172 Start debugged program. You may specify arguments to give it.\n\
3173 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3174 Input and output redirection with \">\", \"<\", or \">>\" are also \
3176 With no arguments, uses arguments last specified (with \"run\" \
3177 or \"set args\").\n\
3178 To cancel previous arguments and run with no arguments,\n\
3179 use \"set args\" without arguments."));
3180 set_cmd_completer (c
, filename_completer
);
3181 add_com_alias ("r", "run", class_run
, 1);
3183 c
= add_com ("start", class_run
, start_command
, _("\
3184 Run the debugged program until the beginning of the main procedure.\n\
3185 You may specify arguments to give to your program, just as with the\n\
3186 \"run\" command."));
3187 set_cmd_completer (c
, filename_completer
);
3189 add_com ("interrupt", class_run
, interrupt_command
,
3190 _("Interrupt the execution of the debugged program.\n\
3191 If non-stop mode is enabled, interrupt only the current thread,\n\
3192 otherwise all the threads in the program are stopped. To \n\
3193 interrupt all running threads in non-stop mode, use the -a option."));
3195 c
= add_info ("registers", nofp_registers_info
, _("\
3196 List of integer registers and their contents, for selected stack frame.\n\
3197 Register name as argument means describe only that register."));
3198 add_info_alias ("r", "registers", 1);
3199 set_cmd_completer (c
, reg_or_group_completer
);
3201 c
= add_info ("all-registers", all_registers_info
, _("\
3202 List of all registers and their contents, for selected stack frame.\n\
3203 Register name as argument means describe only that register."));
3204 set_cmd_completer (c
, reg_or_group_completer
);
3206 add_info ("program", program_info
,
3207 _("Execution status of the program."));
3209 add_info ("float", float_info
,
3210 _("Print the status of the floating point unit\n"));
3212 add_info ("vector", vector_info
,
3213 _("Print the status of the vector unit\n"));
3215 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3217 Show /proc process information about any running process.\n\
3218 Specify any process id, or use the program being debugged by default."),
3219 &info_proc_cmdlist
, "info proc ",
3220 1/*allow-unknown*/, &infolist
);
3222 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3223 List of mapped memory regions."),
3224 &info_proc_cmdlist
);
3226 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3227 List process info from /proc/PID/stat."),
3228 &info_proc_cmdlist
);
3230 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3231 List process info from /proc/PID/status."),
3232 &info_proc_cmdlist
);
3234 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3235 List current working directory of the process."),
3236 &info_proc_cmdlist
);
3238 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3239 List command line arguments of the process."),
3240 &info_proc_cmdlist
);
3242 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3243 List absolute filename for executable of the process."),
3244 &info_proc_cmdlist
);
3246 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3247 List all available /proc info."),
3248 &info_proc_cmdlist
);