1 /* Memory-access and commands for "inferior" process, for GDB.
3 Copyright (C) 1986-2014 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"
37 #include "completer.h"
39 #include "event-top.h"
40 #include "parser-defs.h"
42 #include "reggroups.h"
47 #include "target-descriptions.h"
48 #include "user-regs.h"
49 #include "exceptions.h"
50 #include "cli/cli-decode.h"
51 #include "gdbthread.h"
53 #include "inline-frame.h"
54 #include "tracepoint.h"
56 #include "continuations.h"
58 #include "cli/cli-utils.h"
60 /* Local functions: */
62 static void nofp_registers_info (char *, int);
64 static void print_return_value (struct value
*function
,
65 struct type
*value_type
);
67 static void until_next_command (int);
69 static void until_command (char *, int);
71 static void path_info (char *, int);
73 static void path_command (char *, int);
75 static void unset_command (char *, int);
77 static void float_info (char *, int);
79 static void disconnect_command (char *, int);
81 static void unset_environment_command (char *, int);
83 static void set_environment_command (char *, int);
85 static void environment_info (char *, int);
87 static void program_info (char *, int);
89 static void finish_command (char *, int);
91 static void signal_command (char *, int);
93 static void jump_command (char *, int);
95 static void step_1 (int, int, char *);
96 static void step_once (int skip_subroutines
, int single_inst
,
97 int count
, int thread
);
99 static void next_command (char *, int);
101 static void step_command (char *, int);
103 static void run_command (char *, int);
105 static void run_no_args_command (char *args
, int from_tty
);
107 static void go_command (char *line_no
, int from_tty
);
109 static int strip_bg_char (char **);
111 void _initialize_infcmd (void);
113 #define ERROR_NO_INFERIOR \
114 if (!target_has_execution) error (_("The program is not being run."));
116 /* Scratch area where string containing arguments to give to the
117 program will be stored by 'set args'. As soon as anything is
118 stored, notice_args_set will move it into per-inferior storage.
119 Arguments are separated by spaces. Empty string (pointer to '\0')
122 static char *inferior_args_scratch
;
124 /* Scratch area where 'set inferior-tty' will store user-provided value.
125 We'll immediate copy it into per-inferior storage. */
127 static char *inferior_io_terminal_scratch
;
129 /* Pid of our debugged inferior, or 0 if no inferior now.
130 Since various parts of infrun.c test this to see whether there is a program
131 being debugged it should be nonzero (currently 3 is used) for remote
134 ptid_t inferior_ptid
;
136 /* Address at which inferior stopped. */
140 /* Nonzero if stopped due to completion of a stack dummy routine. */
142 enum stop_stack_kind stop_stack_dummy
;
144 /* Nonzero if stopped due to a random (unexpected) signal in inferior
147 int stopped_by_random_signal
;
149 /* See inferior.h. */
151 int startup_with_shell
= 1;
154 /* Accessor routines. */
156 /* Set the io terminal for the current inferior. Ownership of
157 TERMINAL_NAME is not transferred. */
160 set_inferior_io_terminal (const char *terminal_name
)
162 xfree (current_inferior ()->terminal
);
163 current_inferior ()->terminal
= terminal_name
? xstrdup (terminal_name
) : 0;
167 get_inferior_io_terminal (void)
169 return current_inferior ()->terminal
;
173 set_inferior_tty_command (char *args
, int from_tty
,
174 struct cmd_list_element
*c
)
176 /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
177 Now route it to current inferior. */
178 set_inferior_io_terminal (inferior_io_terminal_scratch
);
182 show_inferior_tty_command (struct ui_file
*file
, int from_tty
,
183 struct cmd_list_element
*c
, const char *value
)
185 /* Note that we ignore the passed-in value in favor of computing it
187 const char *inferior_io_terminal
= get_inferior_io_terminal ();
189 if (inferior_io_terminal
== NULL
)
190 inferior_io_terminal
= "";
191 fprintf_filtered (gdb_stdout
,
192 _("Terminal for future runs of program being debugged "
193 "is \"%s\".\n"), inferior_io_terminal
);
197 get_inferior_args (void)
199 if (current_inferior ()->argc
!= 0)
203 n
= construct_inferior_arguments (current_inferior ()->argc
,
204 current_inferior ()->argv
);
205 set_inferior_args (n
);
209 if (current_inferior ()->args
== NULL
)
210 current_inferior ()->args
= xstrdup ("");
212 return current_inferior ()->args
;
215 /* Set the arguments for the current inferior. Ownership of
216 NEWARGS is not transferred. */
219 set_inferior_args (char *newargs
)
221 xfree (current_inferior ()->args
);
222 current_inferior ()->args
= newargs
? xstrdup (newargs
) : NULL
;
223 current_inferior ()->argc
= 0;
224 current_inferior ()->argv
= 0;
228 set_inferior_args_vector (int argc
, char **argv
)
230 current_inferior ()->argc
= argc
;
231 current_inferior ()->argv
= argv
;
234 /* Notice when `set args' is run. */
237 set_args_command (char *args
, int from_tty
, struct cmd_list_element
*c
)
239 /* CLI has assigned the user-provided value to inferior_args_scratch.
240 Now route it to current inferior. */
241 set_inferior_args (inferior_args_scratch
);
244 /* Notice when `show args' is run. */
247 show_args_command (struct ui_file
*file
, int from_tty
,
248 struct cmd_list_element
*c
, const char *value
)
250 /* Note that we ignore the passed-in value in favor of computing it
252 deprecated_show_value_hack (file
, from_tty
, c
, get_inferior_args ());
256 /* Compute command-line string given argument vector. This does the
257 same shell processing as fork_inferior. */
260 construct_inferior_arguments (int argc
, char **argv
)
264 if (startup_with_shell
)
267 /* This holds all the characters considered special to the
269 char *special
= "\"!&*|[]{}<>?`~^=;, \t\n";
270 const char quote
= '"';
272 /* This holds all the characters considered special to the
273 typical Unix shells. We include `^' because the SunOS
274 /bin/sh treats it as a synonym for `|'. */
275 char *special
= "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
276 const char quote
= '\'';
282 /* We over-compute the size. It shouldn't matter. */
283 for (i
= 0; i
< argc
; ++i
)
284 length
+= 3 * strlen (argv
[i
]) + 1 + 2 * (argv
[i
][0] == '\0');
286 result
= (char *) xmalloc (length
);
289 for (i
= 0; i
< argc
; ++i
)
294 /* Need to handle empty arguments specially. */
295 if (argv
[i
][0] == '\0')
305 if (strpbrk (argv
[i
], special
))
311 for (cp
= argv
[i
]; *cp
; ++cp
)
315 /* A newline cannot be quoted with a backslash (it
316 just disappears), only by putting it inside
327 if (strchr (special
, *cp
) != NULL
)
343 /* In this case we can't handle arguments that contain spaces,
344 tabs, or newlines -- see breakup_args(). */
348 for (i
= 0; i
< argc
; ++i
)
350 char *cp
= strchr (argv
[i
], ' ');
352 cp
= strchr (argv
[i
], '\t');
354 cp
= strchr (argv
[i
], '\n');
356 error (_("can't handle command-line "
357 "argument containing whitespace"));
358 length
+= strlen (argv
[i
]) + 1;
361 result
= (char *) xmalloc (length
);
363 for (i
= 0; i
< argc
; ++i
)
366 strcat (result
, " ");
367 strcat (result
, argv
[i
]);
375 /* This function detects whether or not a '&' character (indicating
376 background execution) has been added as *the last* of the arguments ARGS
377 of a command. If it has, it removes it and returns 1. Otherwise it
378 does nothing and returns 0. */
381 strip_bg_char (char **args
)
385 p
= strchr (*args
, '&');
389 if (p
== (*args
+ strlen (*args
) - 1))
391 if (strlen (*args
) > 1)
395 while (*p
== ' ' || *p
== '\t');
406 /* Common actions to take after creating any sort of inferior, by any
407 means (running, attaching, connecting, et cetera). The target
408 should be stopped. */
411 post_create_inferior (struct target_ops
*target
, int from_tty
)
413 volatile struct gdb_exception ex
;
415 /* Be sure we own the terminal in case write operations are performed. */
416 target_terminal_ours ();
418 /* If the target hasn't taken care of this already, do it now.
419 Targets which need to access registers during to_open,
420 to_create_inferior, or to_attach should do it earlier; but many
422 target_find_description ();
424 /* Now that we know the register layout, retrieve current PC. But
425 if the PC is unavailable (e.g., we're opening a core file with
426 missing registers info), ignore it. */
428 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
430 stop_pc
= regcache_read_pc (get_current_regcache ());
432 if (ex
.reason
< 0 && ex
.error
!= NOT_AVAILABLE_ERROR
)
433 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
;
536 kill_if_already_running (from_tty
);
538 init_wait_for_inferior ();
539 clear_breakpoint_hit_counts ();
541 /* Clean up any leftovers from other runs. Some other things from
542 this function should probably be moved into target_pre_inferior. */
543 target_pre_inferior (from_tty
);
545 /* The comment here used to read, "The exec file is re-read every
546 time we do a generic_mourn_inferior, so we just have to worry
547 about the symbol file." The `generic_mourn_inferior' function
548 gets called whenever the program exits. However, suppose the
549 program exits, and *then* the executable file changes? We need
550 to check again here. Since reopen_exec_file doesn't do anything
551 if the timestamp hasn't changed, I don't see the harm. */
556 async_exec
= strip_bg_char (&args
);
558 /* Do validation and preparation before possibly changing anything
561 run_target
= find_run_target ();
563 prepare_execution_command (run_target
, async_exec
);
565 if (non_stop
&& !run_target
->to_supports_non_stop (run_target
))
566 error (_("The target does not support running in non-stop mode."));
568 /* Done. Can now set breakpoints, change inferior args, etc. */
570 /* Insert the temporary breakpoint if a location was specified. */
572 tbreak_command (main_name (), 0);
574 exec_file
= (char *) get_exec_file (0);
576 /* We keep symbols from add-symbol-file, on the grounds that the
577 user might want to add some symbols before running the program
578 (right?). But sometimes (dynamic loading where the user manually
579 introduces the new symbols with add-symbol-file), the code which
580 the symbols describe does not persist between runs. Currently
581 the user has to manually nuke all symbols between runs if they
582 want them to go away (PR 2207). This is probably reasonable. */
584 /* If there were other args, beside '&', process them. */
586 set_inferior_args (args
);
590 ui_out_field_string (uiout
, NULL
, "Starting program");
591 ui_out_text (uiout
, ": ");
593 ui_out_field_string (uiout
, "execfile", exec_file
);
594 ui_out_spaces (uiout
, 1);
595 /* We call get_inferior_args() because we might need to compute
597 ui_out_field_string (uiout
, "infargs", get_inferior_args ());
598 ui_out_text (uiout
, "\n");
599 ui_out_flush (uiout
);
602 /* We call get_inferior_args() because we might need to compute
604 run_target
->to_create_inferior (run_target
, exec_file
, get_inferior_args (),
605 environ_vector (current_inferior ()->environment
),
607 /* to_create_inferior should push the target, so after this point we
608 shouldn't refer to run_target again. */
611 /* We're starting off a new process. When we get out of here, in
612 non-stop mode, finish the state of all threads of that process,
613 but leave other threads alone, as they may be stopped in internal
614 events --- the frontend shouldn't see them as stopped. In
615 all-stop, always finish the state of all threads, as we may be
616 resuming more than just the new process. */
618 ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
620 ptid
= minus_one_ptid
;
621 old_chain
= make_cleanup (finish_thread_state_cleanup
, &ptid
);
623 /* Pass zero for FROM_TTY, because at this point the "run" command
624 has done its thing; now we are setting up the running program. */
625 post_create_inferior (¤t_target
, 0);
627 /* Start the target running. Do not use -1 continuation as it would skip
628 breakpoint right at the entry point. */
629 proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0
, 0);
631 /* Since there was no error, there's no need to finish the thread
633 discard_cleanups (old_chain
);
637 run_command (char *args
, int from_tty
)
639 run_command_1 (args
, from_tty
, 0);
643 run_no_args_command (char *args
, int from_tty
)
645 set_inferior_args ("");
649 /* Start the execution of the program up until the beginning of the main
653 start_command (char *args
, int from_tty
)
655 /* Some languages such as Ada need to search inside the program
656 minimal symbols for the location where to put the temporary
657 breakpoint before starting. */
658 if (!have_minimal_symbols ())
659 error (_("No symbol table loaded. Use the \"file\" command."));
661 /* Run the program until reaching the main procedure... */
662 run_command_1 (args
, from_tty
, 1);
666 proceed_thread_callback (struct thread_info
*thread
, void *arg
)
668 /* We go through all threads individually instead of compressing
669 into a single target `resume_all' request, because some threads
670 may be stopped in internal breakpoints/events, or stopped waiting
671 for its turn in the displaced stepping queue (that is, they are
672 running && !executing). The target side has no idea about why
673 the thread is stopped, so a `resume_all' command would resume too
674 much. If/when GDB gains a way to tell the target `hold this
675 thread stopped until I say otherwise', then we can optimize
677 if (!is_stopped (thread
->ptid
))
680 switch_to_thread (thread
->ptid
);
681 clear_proceed_status (0);
682 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
687 ensure_valid_thread (void)
689 if (ptid_equal (inferior_ptid
, null_ptid
)
690 || is_exited (inferior_ptid
))
691 error (_("Cannot execute this command without a live selected thread."));
694 /* If the user is looking at trace frames, any resumption of execution
695 is likely to mix up recorded and live target data. So simply
696 disallow those commands. */
699 ensure_not_tfind_mode (void)
701 if (get_traceframe_number () >= 0)
702 error (_("Cannot execute this command while looking at trace frames."));
705 /* Throw an error indicating the current thread is running. */
708 error_is_running (void)
710 error (_("Cannot execute this command while "
711 "the selected thread is running."));
714 /* Calls error_is_running if the current thread is running. */
717 ensure_not_running (void)
719 if (is_running (inferior_ptid
))
724 continue_1 (int all_threads
)
727 ensure_not_tfind_mode ();
729 if (non_stop
&& all_threads
)
731 /* Don't error out if the current thread is running, because
732 there may be other stopped threads. */
733 struct cleanup
*old_chain
;
735 /* Backup current thread and selected frame. */
736 old_chain
= make_cleanup_restore_current_thread ();
738 iterate_over_threads (proceed_thread_callback
, NULL
);
740 /* Restore selected ptid. */
741 do_cleanups (old_chain
);
745 ensure_valid_thread ();
746 ensure_not_running ();
747 clear_proceed_status (0);
748 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
752 /* continue [-a] [proceed-count] [&] */
755 continue_command (char *args
, int from_tty
)
761 /* Find out whether we must run in the background. */
763 async_exec
= strip_bg_char (&args
);
765 prepare_execution_command (¤t_target
, async_exec
);
769 if (strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
772 args
+= sizeof ("-a") - 1;
778 if (!non_stop
&& all_threads
)
779 error (_("`-a' is meaningless in all-stop mode."));
781 if (args
!= NULL
&& all_threads
)
782 error (_("Can't resume all threads and specify "
783 "proceed count simultaneously."));
785 /* If we have an argument left, set proceed count of breakpoint we
792 struct thread_info
*tp
;
795 tp
= find_thread_ptid (inferior_ptid
);
799 struct target_waitstatus ws
;
801 get_last_target_status (&last_ptid
, &ws
);
802 tp
= find_thread_ptid (last_ptid
);
805 bs
= tp
->control
.stop_bpstat
;
807 while ((stat
= bpstat_num (&bs
, &num
)) != 0)
810 set_ignore_count (num
,
811 parse_and_eval_long (args
) - 1,
813 /* set_ignore_count prints a message ending with a period.
814 So print two spaces before "Continuing.". */
816 printf_filtered (" ");
820 if (!stopped
&& from_tty
)
823 ("Not stopped at any breakpoint; argument ignored.\n");
828 printf_filtered (_("Continuing.\n"));
830 continue_1 (all_threads
);
833 /* Record the starting point of a "step" or "next" command. */
836 set_step_frame (void)
838 struct symtab_and_line sal
;
840 find_frame_sal (get_current_frame (), &sal
);
841 set_step_info (get_current_frame (), sal
);
844 /* Step until outside of current statement. */
847 step_command (char *count_string
, int from_tty
)
849 step_1 (0, 0, count_string
);
852 /* Likewise, but skip over subroutine calls as if single instructions. */
855 next_command (char *count_string
, int from_tty
)
857 step_1 (1, 0, count_string
);
860 /* Likewise, but step only one instruction. */
863 stepi_command (char *count_string
, int from_tty
)
865 step_1 (0, 1, count_string
);
869 nexti_command (char *count_string
, int from_tty
)
871 step_1 (1, 1, count_string
);
875 delete_longjmp_breakpoint_cleanup (void *arg
)
877 int thread
= * (int *) arg
;
878 delete_longjmp_breakpoint (thread
);
882 step_1 (int skip_subroutines
, int single_inst
, char *count_string
)
885 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
890 ensure_not_tfind_mode ();
891 ensure_valid_thread ();
892 ensure_not_running ();
895 async_exec
= strip_bg_char (&count_string
);
897 prepare_execution_command (¤t_target
, async_exec
);
899 count
= count_string
? parse_and_eval_long (count_string
) : 1;
901 if (!single_inst
|| skip_subroutines
) /* Leave si command alone. */
903 struct thread_info
*tp
= inferior_thread ();
905 if (in_thread_list (inferior_ptid
))
906 thread
= pid_to_thread_id (inferior_ptid
);
908 set_longjmp_breakpoint (tp
, get_frame_id (get_current_frame ()));
910 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
913 /* In synchronous case, all is well; each step_once call will step once. */
914 if (!target_can_async_p ())
916 for (; count
> 0; count
--)
918 step_once (skip_subroutines
, single_inst
, count
, thread
);
920 if (!target_has_execution
)
924 struct thread_info
*tp
= inferior_thread ();
926 if (!tp
->control
.stop_step
|| !tp
->step_multi
)
928 /* If we stopped for some reason that is not stepping
929 there are no further steps to make. */
936 do_cleanups (cleanups
);
940 /* In the case of an asynchronous target things get complicated;
941 do only one step for now, before returning control to the
942 event loop. Let the continuation figure out how many other
943 steps we need to do, and handle them one at the time, through
945 step_once (skip_subroutines
, single_inst
, count
, thread
);
947 /* We are running, and the continuation is installed. It will
948 disable the longjmp breakpoint as appropriate. */
949 discard_cleanups (cleanups
);
953 struct step_1_continuation_args
956 int skip_subroutines
;
961 /* Called after we are done with one step operation, to check whether
962 we need to step again, before we print the prompt and return control
963 to the user. If count is > 1, we will need to do one more call to
964 proceed(), via step_once(). Basically it is like step_once and
965 step_1_continuation are co-recursive. */
968 step_1_continuation (void *args
, int err
)
970 struct step_1_continuation_args
*a
= args
;
972 if (target_has_execution
)
974 struct thread_info
*tp
;
976 tp
= inferior_thread ();
978 && tp
->step_multi
&& tp
->control
.stop_step
)
980 /* There are more steps to make, and we did stop due to
981 ending a stepping range. Do another step. */
982 step_once (a
->skip_subroutines
, a
->single_inst
,
983 a
->count
- 1, a
->thread
);
989 /* We either hit an error, or stopped for some reason that is
990 not stepping, or there are no further steps to make.
992 if (!a
->single_inst
|| a
->skip_subroutines
)
993 delete_longjmp_breakpoint (a
->thread
);
996 /* Do just one step operation. This is useful to implement the 'step
997 n' kind of commands. In case of asynchronous targets, we will have
998 to set up a continuation to be done after the target stops (after
999 this one step). For synch targets, the caller handles further
1003 step_once (int skip_subroutines
, int single_inst
, int count
, int thread
)
1005 struct frame_info
*frame
= get_current_frame ();
1009 /* Don't assume THREAD is a valid thread id. It is set to -1 if
1010 the longjmp breakpoint was not required. Use the
1011 INFERIOR_PTID thread instead, which is the same thread when
1013 struct thread_info
*tp
= inferior_thread ();
1015 clear_proceed_status (!skip_subroutines
);
1022 /* Step at an inlined function behaves like "down". */
1023 if (!skip_subroutines
1024 && inline_skipped_frames (inferior_ptid
))
1028 /* Pretend that we've ran. */
1029 resume_ptid
= user_visible_resume_ptid (1);
1030 set_running (resume_ptid
, 1);
1032 step_into_inline_frame (inferior_ptid
);
1034 step_once (skip_subroutines
, single_inst
, count
- 1, thread
);
1037 /* Pretend that we've stopped. */
1040 if (target_can_async_p ())
1041 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1046 pc
= get_frame_pc (frame
);
1047 find_pc_line_pc_range (pc
,
1048 &tp
->control
.step_range_start
,
1049 &tp
->control
.step_range_end
);
1051 tp
->control
.may_range_step
= 1;
1053 /* If we have no line info, switch to stepi mode. */
1054 if (tp
->control
.step_range_end
== 0 && step_stop_if_no_debug
)
1056 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1057 tp
->control
.may_range_step
= 0;
1059 else if (tp
->control
.step_range_end
== 0)
1063 if (find_pc_partial_function (pc
, &name
,
1064 &tp
->control
.step_range_start
,
1065 &tp
->control
.step_range_end
) == 0)
1066 error (_("Cannot find bounds of current function"));
1068 target_terminal_ours ();
1069 printf_filtered (_("Single stepping until exit from function %s,"
1070 "\nwhich has no line number information.\n"),
1076 /* Say we are stepping, but stop after one insn whatever it does. */
1077 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1078 if (!skip_subroutines
)
1080 Don't step over function calls, not even to functions lacking
1082 tp
->control
.step_over_calls
= STEP_OVER_NONE
;
1085 if (skip_subroutines
)
1086 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1088 tp
->step_multi
= (count
> 1);
1089 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 1);
1091 /* For async targets, register a continuation to do any
1092 additional steps. For sync targets, the caller will handle
1093 further stepping. */
1094 if (target_can_async_p ())
1096 struct step_1_continuation_args
*args
;
1098 args
= xmalloc (sizeof (*args
));
1099 args
->skip_subroutines
= skip_subroutines
;
1100 args
->single_inst
= single_inst
;
1101 args
->count
= count
;
1102 args
->thread
= thread
;
1104 add_intermediate_continuation (tp
, step_1_continuation
, args
, xfree
);
1110 /* Continue program at specified address. */
1113 jump_command (char *arg
, int from_tty
)
1115 struct gdbarch
*gdbarch
= get_current_arch ();
1117 struct symtabs_and_lines sals
;
1118 struct symtab_and_line sal
;
1124 ensure_not_tfind_mode ();
1125 ensure_valid_thread ();
1126 ensure_not_running ();
1128 /* Find out whether we must run in the background. */
1130 async_exec
= strip_bg_char (&arg
);
1132 prepare_execution_command (¤t_target
, async_exec
);
1135 error_no_arg (_("starting address"));
1137 sals
= decode_line_with_last_displayed (arg
, DECODE_LINE_FUNFIRSTLINE
);
1138 if (sals
.nelts
!= 1)
1140 error (_("Unreasonable jump request"));
1146 if (sal
.symtab
== 0 && sal
.pc
== 0)
1147 error (_("No source file has been specified."));
1149 resolve_sal_pc (&sal
); /* May error out. */
1151 /* See if we are trying to jump to another function. */
1152 fn
= get_frame_function (get_current_frame ());
1153 sfn
= find_pc_function (sal
.pc
);
1154 if (fn
!= NULL
&& sfn
!= fn
)
1156 if (!query (_("Line %d is not in `%s'. Jump anyway? "), sal
.line
,
1157 SYMBOL_PRINT_NAME (fn
)))
1159 error (_("Not confirmed."));
1166 fixup_symbol_section (sfn
, 0);
1167 if (section_is_overlay (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn
), sfn
)) &&
1168 !section_is_mapped (SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sfn
), sfn
)))
1170 if (!query (_("WARNING!!! Destination is in "
1171 "unmapped overlay! Jump anyway? ")))
1173 error (_("Not confirmed."));
1183 printf_filtered (_("Continuing at "));
1184 fputs_filtered (paddress (gdbarch
, addr
), gdb_stdout
);
1185 printf_filtered (".\n");
1188 clear_proceed_status (0);
1189 proceed (addr
, GDB_SIGNAL_0
, 0);
1193 /* Go to line or address in current procedure. */
1196 go_command (char *line_no
, int from_tty
)
1198 if (line_no
== (char *) NULL
|| !*line_no
)
1199 printf_filtered (_("Usage: go <location>\n"));
1202 tbreak_command (line_no
, from_tty
);
1203 jump_command (line_no
, from_tty
);
1208 /* Continue program giving it specified signal. */
1211 signal_command (char *signum_exp
, int from_tty
)
1213 enum gdb_signal oursig
;
1216 dont_repeat (); /* Too dangerous. */
1218 ensure_not_tfind_mode ();
1219 ensure_valid_thread ();
1220 ensure_not_running ();
1222 /* Find out whether we must run in the background. */
1223 if (signum_exp
!= NULL
)
1224 async_exec
= strip_bg_char (&signum_exp
);
1226 prepare_execution_command (¤t_target
, async_exec
);
1229 error_no_arg (_("signal number"));
1231 /* It would be even slicker to make signal names be valid expressions,
1232 (the type could be "enum $signal" or some such), then the user could
1233 assign them to convenience variables. */
1234 oursig
= gdb_signal_from_name (signum_exp
);
1236 if (oursig
== GDB_SIGNAL_UNKNOWN
)
1238 /* No, try numeric. */
1239 int num
= parse_and_eval_long (signum_exp
);
1242 oursig
= GDB_SIGNAL_0
;
1244 oursig
= gdb_signal_from_command (num
);
1247 /* Look for threads other than the current that this command ends up
1248 resuming too (due to schedlock off), and warn if they'll get a
1249 signal delivered. "signal 0" is used to suppress a previous
1250 signal, but if the current thread is no longer the one that got
1251 the signal, then the user is potentially suppressing the signal
1252 of the wrong thread. */
1255 struct thread_info
*tp
;
1257 int must_confirm
= 0;
1259 /* This indicates what will be resumed. Either a single thread,
1260 a whole process, or all threads of all processes. */
1261 resume_ptid
= user_visible_resume_ptid (0);
1263 ALL_NON_EXITED_THREADS (tp
)
1265 if (ptid_equal (tp
->ptid
, inferior_ptid
))
1267 if (!ptid_match (tp
->ptid
, resume_ptid
))
1270 if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
1271 && signal_pass_state (tp
->suspend
.stop_signal
))
1274 printf_unfiltered (_("Note:\n"));
1275 printf_unfiltered (_(" Thread %d previously stopped with signal %s, %s.\n"),
1277 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1278 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1284 && !query (_("Continuing thread %d (the current thread) with specified signal will\n"
1285 "still deliver the signals noted above to their respective threads.\n"
1286 "Continue anyway? "),
1287 inferior_thread ()->num
))
1288 error (_("Not confirmed."));
1293 if (oursig
== GDB_SIGNAL_0
)
1294 printf_filtered (_("Continuing with no signal.\n"));
1296 printf_filtered (_("Continuing with signal %s.\n"),
1297 gdb_signal_to_name (oursig
));
1300 clear_proceed_status (0);
1301 proceed ((CORE_ADDR
) -1, oursig
, 0);
1304 /* Continuation args to be passed to the "until" command
1306 struct until_next_continuation_args
1308 /* The thread that was current when the command was executed. */
1312 /* A continuation callback for until_next_command. */
1315 until_next_continuation (void *arg
, int err
)
1317 struct until_next_continuation_args
*a
= arg
;
1319 delete_longjmp_breakpoint (a
->thread
);
1322 /* Proceed until we reach a different source line with pc greater than
1323 our current one or exit the function. We skip calls in both cases.
1325 Note that eventually this command should probably be changed so
1326 that only source lines are printed out when we hit the breakpoint
1327 we set. This may involve changes to wait_for_inferior and the
1328 proceed status code. */
1331 until_next_command (int from_tty
)
1333 struct frame_info
*frame
;
1335 struct symbol
*func
;
1336 struct symtab_and_line sal
;
1337 struct thread_info
*tp
= inferior_thread ();
1338 int thread
= tp
->num
;
1339 struct cleanup
*old_chain
;
1341 clear_proceed_status (0);
1344 frame
= get_current_frame ();
1346 /* Step until either exited from this function or greater
1347 than the current line (if in symbolic section) or pc (if
1350 pc
= get_frame_pc (frame
);
1351 func
= find_pc_function (pc
);
1355 struct bound_minimal_symbol msymbol
= lookup_minimal_symbol_by_pc (pc
);
1357 if (msymbol
.minsym
== NULL
)
1358 error (_("Execution is not within a known function."));
1360 tp
->control
.step_range_start
= BMSYMBOL_VALUE_ADDRESS (msymbol
);
1361 /* The upper-bound of step_range is exclusive. In order to make PC
1362 within the range, set the step_range_end with PC + 1. */
1363 tp
->control
.step_range_end
= pc
+ 1;
1367 sal
= find_pc_line (pc
, 0);
1369 tp
->control
.step_range_start
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
1370 tp
->control
.step_range_end
= sal
.end
;
1372 tp
->control
.may_range_step
= 1;
1374 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1376 tp
->step_multi
= 0; /* Only one call to proceed */
1378 set_longjmp_breakpoint (tp
, get_frame_id (frame
));
1379 old_chain
= make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1381 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 1);
1383 if (target_can_async_p () && is_running (inferior_ptid
))
1385 struct until_next_continuation_args
*cont_args
;
1387 discard_cleanups (old_chain
);
1388 cont_args
= XNEW (struct until_next_continuation_args
);
1389 cont_args
->thread
= inferior_thread ()->num
;
1391 add_continuation (tp
, until_next_continuation
, cont_args
, xfree
);
1394 do_cleanups (old_chain
);
1398 until_command (char *arg
, int from_tty
)
1403 ensure_not_tfind_mode ();
1404 ensure_valid_thread ();
1405 ensure_not_running ();
1407 /* Find out whether we must run in the background. */
1409 async_exec
= strip_bg_char (&arg
);
1411 prepare_execution_command (¤t_target
, async_exec
);
1414 until_break_command (arg
, from_tty
, 0);
1416 until_next_command (from_tty
);
1420 advance_command (char *arg
, int from_tty
)
1425 ensure_not_tfind_mode ();
1426 ensure_valid_thread ();
1427 ensure_not_running ();
1430 error_no_arg (_("a location"));
1432 /* Find out whether we must run in the background. */
1434 async_exec
= strip_bg_char (&arg
);
1436 prepare_execution_command (¤t_target
, async_exec
);
1438 until_break_command (arg
, from_tty
, 1);
1441 /* Return the value of the result of a function at the end of a 'finish'
1445 get_return_value (struct value
*function
, struct type
*value_type
)
1447 struct regcache
*stop_regs
= stop_registers
;
1448 struct gdbarch
*gdbarch
;
1449 struct value
*value
;
1450 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
1452 /* If stop_registers were not saved, use the current registers. */
1455 stop_regs
= regcache_dup (get_current_regcache ());
1456 make_cleanup_regcache_xfree (stop_regs
);
1459 gdbarch
= get_regcache_arch (stop_regs
);
1461 CHECK_TYPEDEF (value_type
);
1462 gdb_assert (TYPE_CODE (value_type
) != TYPE_CODE_VOID
);
1464 /* FIXME: 2003-09-27: When returning from a nested inferior function
1465 call, it's possible (with no help from the architecture vector)
1466 to locate and return/print a "struct return" value. This is just
1467 a more complicated case of what is already being done in the
1468 inferior function call code. In fact, when inferior function
1469 calls are made async, this will likely be made the norm. */
1471 switch (gdbarch_return_value (gdbarch
, function
, value_type
,
1474 case RETURN_VALUE_REGISTER_CONVENTION
:
1475 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
1476 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
1477 value
= allocate_value (value_type
);
1478 gdbarch_return_value (gdbarch
, function
, value_type
, stop_regs
,
1479 value_contents_raw (value
), NULL
);
1481 case RETURN_VALUE_STRUCT_CONVENTION
:
1485 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1488 do_cleanups (cleanup
);
1493 /* Print the result of a function at the end of a 'finish' command. */
1496 print_return_value (struct value
*function
, struct type
*value_type
)
1498 struct value
*value
= get_return_value (function
, value_type
);
1499 struct ui_out
*uiout
= current_uiout
;
1503 struct value_print_options opts
;
1504 struct ui_file
*stb
;
1505 struct cleanup
*old_chain
;
1508 stb
= mem_fileopen ();
1509 old_chain
= make_cleanup_ui_file_delete (stb
);
1510 ui_out_text (uiout
, "Value returned is ");
1511 ui_out_field_fmt (uiout
, "gdb-result-var", "$%d",
1512 record_latest_value (value
));
1513 ui_out_text (uiout
, " = ");
1514 get_no_prettyformat_print_options (&opts
);
1515 value_print (value
, stb
, &opts
);
1516 ui_out_field_stream (uiout
, "return-value", stb
);
1517 ui_out_text (uiout
, "\n");
1518 do_cleanups (old_chain
);
1522 ui_out_text (uiout
, "Value returned has type: ");
1523 ui_out_field_string (uiout
, "return-type", TYPE_NAME (value_type
));
1524 ui_out_text (uiout
, ".");
1525 ui_out_text (uiout
, " Cannot determine contents\n");
1529 /* Stuff that needs to be done by the finish command after the target
1530 has stopped. In asynchronous mode, we wait for the target to stop
1531 in the call to poll or select in the event loop, so it is
1532 impossible to do all the stuff as part of the finish_command
1533 function itself. The only chance we have to complete this command
1534 is in fetch_inferior_event, which is called by the event loop as
1535 soon as it detects that the target has stopped. */
1537 struct finish_command_continuation_args
1539 /* The thread that as current when the command was executed. */
1541 struct breakpoint
*breakpoint
;
1542 struct symbol
*function
;
1546 finish_command_continuation (void *arg
, int err
)
1548 struct finish_command_continuation_args
*a
= arg
;
1552 struct thread_info
*tp
= NULL
;
1555 if (!ptid_equal (inferior_ptid
, null_ptid
)
1556 && target_has_execution
1557 && is_stopped (inferior_ptid
))
1559 tp
= inferior_thread ();
1560 bs
= tp
->control
.stop_bpstat
;
1563 if (bpstat_find_breakpoint (bs
, a
->breakpoint
) != NULL
1564 && a
->function
!= NULL
)
1566 struct type
*value_type
;
1568 value_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (a
->function
));
1570 internal_error (__FILE__
, __LINE__
,
1571 _("finish_command: function has no target type"));
1573 if (TYPE_CODE (value_type
) != TYPE_CODE_VOID
)
1575 volatile struct gdb_exception ex
;
1578 func
= read_var_value (a
->function
, get_current_frame ());
1579 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1581 /* print_return_value can throw an exception in some
1582 circumstances. We need to catch this so that we still
1583 delete the breakpoint. */
1584 print_return_value (func
, value_type
);
1587 exception_print (gdb_stdout
, ex
);
1591 /* We suppress normal call of normal_stop observer and do it
1592 here so that the *stopped notification includes the return
1594 if (bs
!= NULL
&& tp
->control
.proceed_to_finish
)
1595 observer_notify_normal_stop (bs
, 1 /* print frame */);
1598 delete_breakpoint (a
->breakpoint
);
1599 delete_longjmp_breakpoint (a
->thread
);
1603 finish_command_continuation_free_arg (void *arg
)
1608 /* finish_backward -- helper function for finish_command. */
1611 finish_backward (struct symbol
*function
)
1613 struct symtab_and_line sal
;
1614 struct thread_info
*tp
= inferior_thread ();
1616 CORE_ADDR func_addr
;
1618 pc
= get_frame_pc (get_current_frame ());
1620 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
) == 0)
1621 error (_("Cannot find bounds of current function"));
1623 sal
= find_pc_line (func_addr
, 0);
1625 tp
->control
.proceed_to_finish
= 1;
1626 /* Special case: if we're sitting at the function entry point,
1627 then all we need to do is take a reverse singlestep. We
1628 don't need to set a breakpoint, and indeed it would do us
1631 Note that this can only happen at frame #0, since there's
1632 no way that a function up the stack can have a return address
1633 that's equal to its entry point. */
1637 struct frame_info
*frame
= get_selected_frame (NULL
);
1638 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1639 struct symtab_and_line sr_sal
;
1641 /* Set a step-resume at the function's entry point. Once that's
1642 hit, we'll do one more step backwards. */
1645 sr_sal
.pspace
= get_frame_program_space (frame
);
1646 insert_step_resume_breakpoint_at_sal (gdbarch
,
1647 sr_sal
, null_frame_id
);
1649 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
1653 /* We're almost there -- we just need to back up by one more
1655 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
1656 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 1);
1660 /* finish_forward -- helper function for finish_command. */
1663 finish_forward (struct symbol
*function
, struct frame_info
*frame
)
1665 struct frame_id frame_id
= get_frame_id (frame
);
1666 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1667 struct symtab_and_line sal
;
1668 struct thread_info
*tp
= inferior_thread ();
1669 struct breakpoint
*breakpoint
;
1670 struct cleanup
*old_chain
;
1671 struct finish_command_continuation_args
*cargs
;
1672 int thread
= tp
->num
;
1674 sal
= find_pc_line (get_frame_pc (frame
), 0);
1675 sal
.pc
= get_frame_pc (frame
);
1677 breakpoint
= set_momentary_breakpoint (gdbarch
, sal
,
1678 get_stack_frame_id (frame
),
1681 /* set_momentary_breakpoint invalidates FRAME. */
1684 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
1686 set_longjmp_breakpoint (tp
, frame_id
);
1687 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
1689 /* We want stop_registers, please... */
1690 tp
->control
.proceed_to_finish
= 1;
1691 cargs
= xmalloc (sizeof (*cargs
));
1693 cargs
->thread
= thread
;
1694 cargs
->breakpoint
= breakpoint
;
1695 cargs
->function
= function
;
1696 add_continuation (tp
, finish_command_continuation
, cargs
,
1697 finish_command_continuation_free_arg
);
1698 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
1700 discard_cleanups (old_chain
);
1701 if (!target_can_async_p ())
1702 do_all_continuations (0);
1705 /* "finish": Set a temporary breakpoint at the place the selected
1706 frame will return to, then continue. */
1709 finish_command (char *arg
, int from_tty
)
1711 struct frame_info
*frame
;
1712 struct symbol
*function
;
1717 ensure_not_tfind_mode ();
1718 ensure_valid_thread ();
1719 ensure_not_running ();
1721 /* Find out whether we must run in the background. */
1723 async_exec
= strip_bg_char (&arg
);
1725 prepare_execution_command (¤t_target
, async_exec
);
1728 error (_("The \"finish\" command does not take any arguments."));
1730 frame
= get_prev_frame (get_selected_frame (_("No selected frame.")));
1732 error (_("\"finish\" not meaningful in the outermost frame."));
1734 clear_proceed_status (0);
1736 /* Finishing from an inline frame is completely different. We don't
1737 try to show the "return value" - no way to locate it. So we do
1738 not need a completion. */
1739 if (get_frame_type (get_selected_frame (_("No selected frame.")))
1742 /* Claim we are stepping in the calling frame. An empty step
1743 range means that we will stop once we aren't in a function
1744 called by that frame. We don't use the magic "1" value for
1745 step_range_end, because then infrun will think this is nexti,
1746 and not step over the rest of this inlined function call. */
1747 struct thread_info
*tp
= inferior_thread ();
1748 struct symtab_and_line empty_sal
;
1750 init_sal (&empty_sal
);
1751 set_step_info (frame
, empty_sal
);
1752 tp
->control
.step_range_start
= get_frame_pc (frame
);
1753 tp
->control
.step_range_end
= tp
->control
.step_range_start
;
1754 tp
->control
.step_over_calls
= STEP_OVER_ALL
;
1756 /* Print info on the selected frame, including level number but not
1760 printf_filtered (_("Run till exit from "));
1761 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1764 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 1);
1768 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1769 entering THISFRAME. */
1770 while (get_frame_type (frame
) == TAILCALL_FRAME
)
1771 frame
= get_prev_frame (frame
);
1773 /* Find the function we will return from. */
1775 function
= find_pc_function (get_frame_pc (get_selected_frame (NULL
)));
1777 /* Print info on the selected frame, including level number but not
1781 if (execution_direction
== EXEC_REVERSE
)
1782 printf_filtered (_("Run back to call of "));
1784 printf_filtered (_("Run till exit from "));
1786 print_stack_frame (get_selected_frame (NULL
), 1, LOCATION
, 0);
1789 if (execution_direction
== EXEC_REVERSE
)
1790 finish_backward (function
);
1792 finish_forward (function
, frame
);
1797 program_info (char *args
, int from_tty
)
1801 struct thread_info
*tp
;
1804 if (!target_has_execution
)
1806 printf_filtered (_("The program being debugged is not being run.\n"));
1811 ptid
= inferior_ptid
;
1814 struct target_waitstatus ws
;
1816 get_last_target_status (&ptid
, &ws
);
1819 if (ptid_equal (ptid
, null_ptid
) || is_exited (ptid
))
1820 error (_("Invalid selected thread."));
1821 else if (is_running (ptid
))
1822 error (_("Selected thread is running."));
1824 tp
= find_thread_ptid (ptid
);
1825 bs
= tp
->control
.stop_bpstat
;
1826 stat
= bpstat_num (&bs
, &num
);
1828 target_files_info ();
1829 printf_filtered (_("Program stopped at %s.\n"),
1830 paddress (target_gdbarch (), stop_pc
));
1831 if (tp
->control
.stop_step
)
1832 printf_filtered (_("It stopped after being stepped.\n"));
1835 /* There may be several breakpoints in the same place, so this
1836 isn't as strange as it seems. */
1841 printf_filtered (_("It stopped at a breakpoint "
1842 "that has since been deleted.\n"));
1845 printf_filtered (_("It stopped at breakpoint %d.\n"), num
);
1846 stat
= bpstat_num (&bs
, &num
);
1849 else if (tp
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
1851 printf_filtered (_("It stopped with signal %s, %s.\n"),
1852 gdb_signal_to_name (tp
->suspend
.stop_signal
),
1853 gdb_signal_to_string (tp
->suspend
.stop_signal
));
1858 printf_filtered (_("Type \"info stack\" or \"info "
1859 "registers\" for more information.\n"));
1864 environment_info (char *var
, int from_tty
)
1868 char *val
= get_in_environ (current_inferior ()->environment
, var
);
1872 puts_filtered (var
);
1873 puts_filtered (" = ");
1874 puts_filtered (val
);
1875 puts_filtered ("\n");
1879 puts_filtered ("Environment variable \"");
1880 puts_filtered (var
);
1881 puts_filtered ("\" not defined.\n");
1886 char **vector
= environ_vector (current_inferior ()->environment
);
1890 puts_filtered (*vector
++);
1891 puts_filtered ("\n");
1897 set_environment_command (char *arg
, int from_tty
)
1899 char *p
, *val
, *var
;
1903 error_no_arg (_("environment variable and value"));
1905 /* Find seperation between variable name and value. */
1906 p
= (char *) strchr (arg
, '=');
1907 val
= (char *) strchr (arg
, ' ');
1909 if (p
!= 0 && val
!= 0)
1911 /* We have both a space and an equals. If the space is before the
1912 equals, walk forward over the spaces til we see a nonspace
1913 (possibly the equals). */
1918 /* Now if the = is after the char following the spaces,
1919 take the char following the spaces. */
1923 else if (val
!= 0 && p
== 0)
1927 error_no_arg (_("environment variable to set"));
1929 if (p
== 0 || p
[1] == 0)
1933 p
= arg
+ strlen (arg
); /* So that savestring below will work. */
1937 /* Not setting variable value to null. */
1939 while (*val
== ' ' || *val
== '\t')
1943 while (p
!= arg
&& (p
[-1] == ' ' || p
[-1] == '\t'))
1946 var
= savestring (arg
, p
- arg
);
1949 printf_filtered (_("Setting environment variable "
1950 "\"%s\" to null value.\n"),
1952 set_in_environ (current_inferior ()->environment
, var
, "");
1955 set_in_environ (current_inferior ()->environment
, var
, val
);
1960 unset_environment_command (char *var
, int from_tty
)
1964 /* If there is no argument, delete all environment variables.
1965 Ask for confirmation if reading from the terminal. */
1966 if (!from_tty
|| query (_("Delete all environment variables? ")))
1968 free_environ (current_inferior ()->environment
);
1969 current_inferior ()->environment
= make_environ ();
1973 unset_in_environ (current_inferior ()->environment
, var
);
1976 /* Handle the execution path (PATH variable). */
1978 static const char path_var_name
[] = "PATH";
1981 path_info (char *args
, int from_tty
)
1983 puts_filtered ("Executable and object file path: ");
1984 puts_filtered (get_in_environ (current_inferior ()->environment
,
1986 puts_filtered ("\n");
1989 /* Add zero or more directories to the front of the execution path. */
1992 path_command (char *dirname
, int from_tty
)
1998 env
= get_in_environ (current_inferior ()->environment
, path_var_name
);
1999 /* Can be null if path is not set. */
2002 exec_path
= xstrdup (env
);
2003 mod_path (dirname
, &exec_path
);
2004 set_in_environ (current_inferior ()->environment
, path_var_name
, exec_path
);
2007 path_info ((char *) NULL
, from_tty
);
2011 /* Print out the register NAME with value VAL, to FILE, in the default
2015 default_print_one_register_info (struct ui_file
*file
,
2019 struct type
*regtype
= value_type (val
);
2020 int print_raw_format
;
2022 fputs_filtered (name
, file
);
2023 print_spaces_filtered (15 - strlen (name
), file
);
2025 print_raw_format
= (value_entirely_available (val
)
2026 && !value_optimized_out (val
));
2028 /* If virtual format is floating, print it that way, and in raw
2030 if (TYPE_CODE (regtype
) == TYPE_CODE_FLT
2031 || TYPE_CODE (regtype
) == TYPE_CODE_DECFLOAT
)
2034 struct value_print_options opts
;
2035 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
2036 enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (regtype
));
2038 get_user_print_options (&opts
);
2042 value_contents_for_printing (val
),
2043 value_embedded_offset (val
), 0,
2044 file
, 0, val
, &opts
, current_language
);
2046 if (print_raw_format
)
2048 fprintf_filtered (file
, "\t(raw ");
2049 print_hex_chars (file
, valaddr
, TYPE_LENGTH (regtype
), byte_order
);
2050 fprintf_filtered (file
, ")");
2055 struct value_print_options opts
;
2057 /* Print the register in hex. */
2058 get_formatted_print_options (&opts
, 'x');
2061 value_contents_for_printing (val
),
2062 value_embedded_offset (val
), 0,
2063 file
, 0, val
, &opts
, current_language
);
2064 /* If not a vector register, print it also according to its
2066 if (print_raw_format
&& TYPE_VECTOR (regtype
) == 0)
2068 get_user_print_options (&opts
);
2070 fprintf_filtered (file
, "\t");
2072 value_contents_for_printing (val
),
2073 value_embedded_offset (val
), 0,
2074 file
, 0, val
, &opts
, current_language
);
2078 fprintf_filtered (file
, "\n");
2081 /* Print out the machine register regnum. If regnum is -1, print all
2082 registers (print_all == 1) or all non-float and non-vector
2083 registers (print_all == 0).
2085 For most machines, having all_registers_info() print the
2086 register(s) one per line is good enough. If a different format is
2087 required, (eg, for MIPS or Pyramid 90x, which both have lots of
2088 regs), or there is an existing convention for showing all the
2089 registers, define the architecture method PRINT_REGISTERS_INFO to
2090 provide that format. */
2093 default_print_registers_info (struct gdbarch
*gdbarch
,
2094 struct ui_file
*file
,
2095 struct frame_info
*frame
,
2096 int regnum
, int print_all
)
2099 const int numregs
= gdbarch_num_regs (gdbarch
)
2100 + gdbarch_num_pseudo_regs (gdbarch
);
2102 for (i
= 0; i
< numregs
; i
++)
2104 /* Decide between printing all regs, non-float / vector regs, or
2110 if (!gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
2115 if (!gdbarch_register_reggroup_p (gdbarch
, i
, general_reggroup
))
2125 /* If the register name is empty, it is undefined for this
2126 processor, so don't display anything. */
2127 if (gdbarch_register_name (gdbarch
, i
) == NULL
2128 || *(gdbarch_register_name (gdbarch
, i
)) == '\0')
2131 default_print_one_register_info (file
,
2132 gdbarch_register_name (gdbarch
, i
),
2133 value_of_register (i
, frame
));
2138 registers_info (char *addr_exp
, int fpregs
)
2140 struct frame_info
*frame
;
2141 struct gdbarch
*gdbarch
;
2143 if (!target_has_registers
)
2144 error (_("The program has no registers now."));
2145 frame
= get_selected_frame (NULL
);
2146 gdbarch
= get_frame_arch (frame
);
2150 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2155 while (*addr_exp
!= '\0')
2160 /* Skip leading white space. */
2161 addr_exp
= skip_spaces (addr_exp
);
2163 /* Discard any leading ``$''. Check that there is something
2164 resembling a register following it. */
2165 if (addr_exp
[0] == '$')
2167 if (isspace ((*addr_exp
)) || (*addr_exp
) == '\0')
2168 error (_("Missing register name"));
2170 /* Find the start/end of this register name/num/group. */
2172 while ((*addr_exp
) != '\0' && !isspace ((*addr_exp
)))
2176 /* Figure out what we've found and display it. */
2178 /* A register name? */
2180 int regnum
= user_reg_map_name_to_regnum (gdbarch
, start
, end
- start
);
2184 /* User registers lie completely outside of the range of
2185 normal registers. Catch them early so that the target
2187 if (regnum
>= gdbarch_num_regs (gdbarch
)
2188 + gdbarch_num_pseudo_regs (gdbarch
))
2190 struct value
*regval
= value_of_user_reg (regnum
, frame
);
2191 const char *regname
= user_reg_map_regnum_to_name (gdbarch
,
2194 /* Print in the same fashion
2195 gdbarch_print_registers_info's default
2196 implementation prints. */
2197 default_print_one_register_info (gdb_stdout
,
2202 gdbarch_print_registers_info (gdbarch
, gdb_stdout
,
2203 frame
, regnum
, fpregs
);
2208 /* A register group? */
2210 struct reggroup
*group
;
2212 for (group
= reggroup_next (gdbarch
, NULL
);
2214 group
= reggroup_next (gdbarch
, group
))
2216 /* Don't bother with a length check. Should the user
2217 enter a short register group name, go with the first
2218 group that matches. */
2219 if (strncmp (start
, reggroup_name (group
), end
- start
) == 0)
2227 regnum
< gdbarch_num_regs (gdbarch
)
2228 + gdbarch_num_pseudo_regs (gdbarch
);
2231 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
2232 gdbarch_print_registers_info (gdbarch
,
2240 /* Nothing matched. */
2241 error (_("Invalid register `%.*s'"), (int) (end
- start
), start
);
2246 all_registers_info (char *addr_exp
, int from_tty
)
2248 registers_info (addr_exp
, 1);
2252 nofp_registers_info (char *addr_exp
, int from_tty
)
2254 registers_info (addr_exp
, 0);
2258 print_vector_info (struct ui_file
*file
,
2259 struct frame_info
*frame
, const char *args
)
2261 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2263 if (gdbarch_print_vector_info_p (gdbarch
))
2264 gdbarch_print_vector_info (gdbarch
, file
, frame
, args
);
2268 int printed_something
= 0;
2271 regnum
< gdbarch_num_regs (gdbarch
)
2272 + gdbarch_num_pseudo_regs (gdbarch
);
2275 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, vector_reggroup
))
2277 printed_something
= 1;
2278 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2281 if (!printed_something
)
2282 fprintf_filtered (file
, "No vector information\n");
2287 vector_info (char *args
, int from_tty
)
2289 if (!target_has_registers
)
2290 error (_("The program has no registers now."));
2292 print_vector_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2295 /* Kill the inferior process. Make us have no inferior. */
2298 kill_command (char *arg
, int from_tty
)
2300 /* FIXME: This should not really be inferior_ptid (or target_has_execution).
2301 It should be a distinct flag that indicates that a target is active, cuz
2302 some targets don't have processes! */
2304 if (ptid_equal (inferior_ptid
, null_ptid
))
2305 error (_("The program is not being run."));
2306 if (!query (_("Kill the program being debugged? ")))
2307 error (_("Not confirmed."));
2310 /* If we still have other inferiors to debug, then don't mess with
2311 with their threads. */
2312 if (!have_inferiors ())
2314 init_thread_list (); /* Destroy thread info. */
2316 /* Killing off the inferior can leave us with a core file. If
2317 so, print the state we are left in. */
2318 if (target_has_stack
)
2320 printf_filtered (_("In %s,\n"), target_longname
);
2321 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2324 bfd_cache_close_all ();
2327 /* Used in `attach&' command. ARG is a point to an integer
2328 representing a process id. Proceed threads of this process iff
2329 they stopped due to debugger request, and when they did, they
2330 reported a clean stop (GDB_SIGNAL_0). Do not proceed threads
2331 that have been explicitly been told to stop. */
2334 proceed_after_attach_callback (struct thread_info
*thread
,
2337 int pid
= * (int *) arg
;
2339 if (ptid_get_pid (thread
->ptid
) == pid
2340 && !is_exited (thread
->ptid
)
2341 && !is_executing (thread
->ptid
)
2342 && !thread
->stop_requested
2343 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
2345 switch_to_thread (thread
->ptid
);
2346 clear_proceed_status (0);
2347 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
2354 proceed_after_attach (int pid
)
2356 /* Don't error out if the current thread is running, because
2357 there may be other stopped threads. */
2358 struct cleanup
*old_chain
;
2360 /* Backup current thread and selected frame. */
2361 old_chain
= make_cleanup_restore_current_thread ();
2363 iterate_over_threads (proceed_after_attach_callback
, &pid
);
2365 /* Restore selected ptid. */
2366 do_cleanups (old_chain
);
2371 * Should save/restore the tty state since it might be that the
2372 * program to be debugged was started on this tty and it wants
2373 * the tty in some state other than what we want. If it's running
2374 * on another terminal or without a terminal, then saving and
2375 * restoring the tty state is a harmless no-op.
2376 * This only needs to be done if we are attaching to a process.
2379 /* attach_command --
2380 takes a program started up outside of gdb and ``attaches'' to it.
2381 This stops it cold in its tracks and allows us to start debugging it.
2382 and wait for the trace-trap that results from attaching. */
2385 attach_command_post_wait (char *args
, int from_tty
, int async_exec
)
2388 char *full_exec_path
= NULL
;
2389 struct inferior
*inferior
;
2391 inferior
= current_inferior ();
2392 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2394 /* If no exec file is yet known, try to determine it from the
2396 exec_file
= (char *) get_exec_file (0);
2399 exec_file
= target_pid_to_exec_file (ptid_get_pid (inferior_ptid
));
2402 /* It's possible we don't have a full path, but rather just a
2403 filename. Some targets, such as HP-UX, don't provide the
2406 Attempt to qualify the filename against the source path.
2407 (If that fails, we'll just fall back on the original
2408 filename. Not much more we can do...) */
2410 if (!source_full_path_of (exec_file
, &full_exec_path
))
2411 full_exec_path
= xstrdup (exec_file
);
2413 exec_file_attach (full_exec_path
, from_tty
);
2414 symbol_file_add_main (full_exec_path
, from_tty
);
2419 reopen_exec_file ();
2423 /* Take any necessary post-attaching actions for this platform. */
2424 target_post_attach (ptid_get_pid (inferior_ptid
));
2426 post_create_inferior (¤t_target
, from_tty
);
2430 /* The user requested an `attach&', so be sure to leave threads
2431 that didn't get a signal running. */
2433 /* Immediatelly resume all suspended threads of this inferior,
2434 and this inferior only. This should have no effect on
2435 already running threads. If a thread has been stopped with a
2436 signal, leave it be. */
2438 proceed_after_attach (inferior
->pid
);
2441 if (inferior_thread ()->suspend
.stop_signal
== GDB_SIGNAL_0
)
2443 clear_proceed_status (0);
2444 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
2450 /* The user requested a plain `attach', so be sure to leave
2451 the inferior stopped. */
2453 if (target_can_async_p ())
2454 async_enable_stdin ();
2456 /* At least the current thread is already stopped. */
2458 /* In all-stop, by definition, all threads have to be already
2459 stopped at this point. In non-stop, however, although the
2460 selected thread is stopped, others may still be executing.
2461 Be sure to explicitly stop all threads of the process. This
2462 should have no effect on already stopped threads. */
2464 target_stop (pid_to_ptid (inferior
->pid
));
2466 /* Tell the user/frontend where we're stopped. */
2468 if (deprecated_attach_hook
)
2469 deprecated_attach_hook ();
2473 struct attach_command_continuation_args
2481 attach_command_continuation (void *args
, int err
)
2483 struct attach_command_continuation_args
*a
= args
;
2488 attach_command_post_wait (a
->args
, a
->from_tty
, a
->async_exec
);
2492 attach_command_continuation_free_args (void *args
)
2494 struct attach_command_continuation_args
*a
= args
;
2501 attach_command (char *args
, int from_tty
)
2504 struct target_ops
*attach_target
;
2506 dont_repeat (); /* Not for the faint of heart */
2508 if (gdbarch_has_global_solist (target_gdbarch ()))
2509 /* Don't complain if all processes share the same symbol
2512 else if (target_has_execution
)
2514 if (query (_("A program is being debugged already. Kill it? ")))
2517 error (_("Not killed."));
2520 /* Clean up any leftovers from other runs. Some other things from
2521 this function should probably be moved into target_pre_inferior. */
2522 target_pre_inferior (from_tty
);
2525 async_exec
= strip_bg_char (&args
);
2527 attach_target
= find_attach_target ();
2529 prepare_execution_command (attach_target
, async_exec
);
2531 if (non_stop
&& !attach_target
->to_supports_non_stop (attach_target
))
2532 error (_("Cannot attach to this target in non-stop mode"));
2534 attach_target
->to_attach (attach_target
, args
, from_tty
);
2535 /* to_attach should push the target, so after this point we
2536 shouldn't refer to attach_target again. */
2537 attach_target
= NULL
;
2539 /* Set up the "saved terminal modes" of the inferior
2540 based on what modes we are starting it with. */
2541 target_terminal_init ();
2543 /* Install inferior's terminal modes. This may look like a no-op,
2544 as we've just saved them above, however, this does more than
2545 restore terminal settings:
2547 - installs a SIGINT handler that forwards SIGINT to the inferior.
2548 Otherwise a Ctrl-C pressed just while waiting for the initial
2549 stop would end up as a spurious Quit.
2551 - removes stdin from the event loop, which we need if attaching
2552 in the foreground, otherwise on targets that report an initial
2553 stop on attach (which are most) we'd process input/commands
2554 while we're in the event loop waiting for that stop. That is,
2555 before the attach continuation runs and the command is really
2557 target_terminal_inferior ();
2559 /* Set up execution context to know that we should return from
2560 wait_for_inferior as soon as the target reports a stop. */
2561 init_wait_for_inferior ();
2562 clear_proceed_status (0);
2566 /* If we find that the current thread isn't stopped, explicitly
2567 do so now, because we're going to install breakpoints and
2571 /* The user requested an `attach&'; stop just one thread. */
2572 target_stop (inferior_ptid
);
2574 /* The user requested an `attach', so stop all threads of this
2576 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid
)));
2579 /* Some system don't generate traps when attaching to inferior.
2580 E.g. Mach 3 or GNU hurd. */
2581 if (!target_attach_no_wait
)
2583 struct inferior
*inferior
= current_inferior ();
2585 /* Careful here. See comments in inferior.h. Basically some
2586 OSes don't ignore SIGSTOPs on continue requests anymore. We
2587 need a way for handle_inferior_event to reset the stop_signal
2588 variable after an attach, and this is what
2589 STOP_QUIETLY_NO_SIGSTOP is for. */
2590 inferior
->control
.stop_soon
= STOP_QUIETLY_NO_SIGSTOP
;
2592 if (target_can_async_p ())
2594 /* sync_execution mode. Wait for stop. */
2595 struct attach_command_continuation_args
*a
;
2597 a
= xmalloc (sizeof (*a
));
2598 a
->args
= xstrdup (args
);
2599 a
->from_tty
= from_tty
;
2600 a
->async_exec
= async_exec
;
2601 add_inferior_continuation (attach_command_continuation
, a
,
2602 attach_command_continuation_free_args
);
2606 wait_for_inferior ();
2609 attach_command_post_wait (args
, from_tty
, async_exec
);
2612 /* We had just found out that the target was already attached to an
2613 inferior. PTID points at a thread of this new inferior, that is
2614 the most likely to be stopped right now, but not necessarily so.
2615 The new inferior is assumed to be already added to the inferior
2616 list at this point. If LEAVE_RUNNING, then leave the threads of
2617 this inferior running, except those we've explicitly seen reported
2621 notice_new_inferior (ptid_t ptid
, int leave_running
, int from_tty
)
2623 struct cleanup
* old_chain
;
2626 old_chain
= make_cleanup (null_cleanup
, NULL
);
2628 /* If in non-stop, leave threads as running as they were. If
2629 they're stopped for some reason other than us telling it to, the
2630 target reports a signal != GDB_SIGNAL_0. We don't try to
2631 resume threads with such a stop signal. */
2632 async_exec
= non_stop
;
2634 if (!ptid_equal (inferior_ptid
, null_ptid
))
2635 make_cleanup_restore_current_thread ();
2637 switch_to_thread (ptid
);
2639 /* When we "notice" a new inferior we need to do all the things we
2640 would normally do if we had just attached to it. */
2642 if (is_executing (inferior_ptid
))
2644 struct inferior
*inferior
= current_inferior ();
2646 /* We're going to install breakpoints, and poke at memory,
2647 ensure that the inferior is stopped for a moment while we do
2649 target_stop (inferior_ptid
);
2651 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2653 /* Wait for stop before proceeding. */
2654 if (target_can_async_p ())
2656 struct attach_command_continuation_args
*a
;
2658 a
= xmalloc (sizeof (*a
));
2659 a
->args
= xstrdup ("");
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
);
2665 do_cleanups (old_chain
);
2669 wait_for_inferior ();
2672 async_exec
= leave_running
;
2673 attach_command_post_wait ("" /* args */, from_tty
, async_exec
);
2675 do_cleanups (old_chain
);
2680 * takes a program previously attached to and detaches it.
2681 * The program resumes execution and will no longer stop
2682 * on signals, etc. We better not have left any breakpoints
2683 * in the program or it'll die when it hits one. For this
2684 * to work, it may be necessary for the process to have been
2685 * previously attached. It *might* work if the program was
2686 * started via the normal ptrace (PTRACE_TRACEME).
2690 detach_command (char *args
, int from_tty
)
2692 dont_repeat (); /* Not for the faint of heart. */
2694 if (ptid_equal (inferior_ptid
, null_ptid
))
2695 error (_("The program is not being run."));
2697 query_if_trace_running (from_tty
);
2699 disconnect_tracing ();
2701 target_detach (args
, from_tty
);
2703 /* If the solist is global across inferiors, don't clear it when we
2704 detach from a single inferior. */
2705 if (!gdbarch_has_global_solist (target_gdbarch ()))
2706 no_shared_libraries (NULL
, from_tty
);
2708 /* If we still have inferiors to debug, then don't mess with their
2710 if (!have_inferiors ())
2711 init_thread_list ();
2713 if (deprecated_detach_hook
)
2714 deprecated_detach_hook ();
2717 /* Disconnect from the current target without resuming it (leaving it
2718 waiting for a debugger).
2720 We'd better not have left any breakpoints in the program or the
2721 next debugger will get confused. Currently only supported for some
2722 remote targets, since the normal attach mechanisms don't work on
2723 stopped processes on some native platforms (e.g. GNU/Linux). */
2726 disconnect_command (char *args
, int from_tty
)
2728 dont_repeat (); /* Not for the faint of heart. */
2729 query_if_trace_running (from_tty
);
2730 disconnect_tracing ();
2731 target_disconnect (args
, from_tty
);
2732 no_shared_libraries (NULL
, from_tty
);
2733 init_thread_list ();
2734 if (deprecated_detach_hook
)
2735 deprecated_detach_hook ();
2739 interrupt_target_1 (int all_threads
)
2744 ptid
= minus_one_ptid
;
2746 ptid
= inferior_ptid
;
2749 /* Tag the thread as having been explicitly requested to stop, so
2750 other parts of gdb know not to resume this thread automatically,
2751 if it was stopped due to an internal event. Limit this to
2752 non-stop mode, as when debugging a multi-threaded application in
2753 all-stop mode, we will only get one stop event --- it's undefined
2754 which thread will report the event. */
2756 set_stop_requested (ptid
, 1);
2760 Stop the execution of the target while running in async mode, in
2761 the backgound. In all-stop, stop the whole process. In non-stop
2762 mode, stop the current thread only by default, or stop all threads
2763 if the `-a' switch is used. */
2766 interrupt_command (char *args
, int from_tty
)
2768 if (target_can_async_p ())
2770 int all_threads
= 0;
2772 dont_repeat (); /* Not for the faint of heart. */
2775 && strncmp (args
, "-a", sizeof ("-a") - 1) == 0)
2778 if (!non_stop
&& all_threads
)
2779 error (_("-a is meaningless in all-stop mode."));
2781 interrupt_target_1 (all_threads
);
2786 print_float_info (struct ui_file
*file
,
2787 struct frame_info
*frame
, const char *args
)
2789 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2791 if (gdbarch_print_float_info_p (gdbarch
))
2792 gdbarch_print_float_info (gdbarch
, file
, frame
, args
);
2796 int printed_something
= 0;
2799 regnum
< gdbarch_num_regs (gdbarch
)
2800 + gdbarch_num_pseudo_regs (gdbarch
);
2803 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, float_reggroup
))
2805 printed_something
= 1;
2806 gdbarch_print_registers_info (gdbarch
, file
, frame
, regnum
, 1);
2809 if (!printed_something
)
2810 fprintf_filtered (file
, "No floating-point info "
2811 "available for this processor.\n");
2816 float_info (char *args
, int from_tty
)
2818 if (!target_has_registers
)
2819 error (_("The program has no registers now."));
2821 print_float_info (gdb_stdout
, get_selected_frame (NULL
), args
);
2825 unset_command (char *args
, int from_tty
)
2827 printf_filtered (_("\"unset\" must be followed by the "
2828 "name of an unset subcommand.\n"));
2829 help_list (unsetlist
, "unset ", all_commands
, gdb_stdout
);
2832 /* Implement `info proc' family of commands. */
2835 info_proc_cmd_1 (char *args
, enum info_proc_what what
, int from_tty
)
2837 struct gdbarch
*gdbarch
= get_current_arch ();
2839 if (!target_info_proc (args
, what
))
2841 if (gdbarch_info_proc_p (gdbarch
))
2842 gdbarch_info_proc (gdbarch
, args
, what
);
2844 error (_("Not supported on this target."));
2848 /* Implement `info proc' when given without any futher parameters. */
2851 info_proc_cmd (char *args
, int from_tty
)
2853 info_proc_cmd_1 (args
, IP_MINIMAL
, from_tty
);
2856 /* Implement `info proc mappings'. */
2859 info_proc_cmd_mappings (char *args
, int from_tty
)
2861 info_proc_cmd_1 (args
, IP_MAPPINGS
, from_tty
);
2864 /* Implement `info proc stat'. */
2867 info_proc_cmd_stat (char *args
, int from_tty
)
2869 info_proc_cmd_1 (args
, IP_STAT
, from_tty
);
2872 /* Implement `info proc status'. */
2875 info_proc_cmd_status (char *args
, int from_tty
)
2877 info_proc_cmd_1 (args
, IP_STATUS
, from_tty
);
2880 /* Implement `info proc cwd'. */
2883 info_proc_cmd_cwd (char *args
, int from_tty
)
2885 info_proc_cmd_1 (args
, IP_CWD
, from_tty
);
2888 /* Implement `info proc cmdline'. */
2891 info_proc_cmd_cmdline (char *args
, int from_tty
)
2893 info_proc_cmd_1 (args
, IP_CMDLINE
, from_tty
);
2896 /* Implement `info proc exe'. */
2899 info_proc_cmd_exe (char *args
, int from_tty
)
2901 info_proc_cmd_1 (args
, IP_EXE
, from_tty
);
2904 /* Implement `info proc all'. */
2907 info_proc_cmd_all (char *args
, int from_tty
)
2909 info_proc_cmd_1 (args
, IP_ALL
, from_tty
);
2913 _initialize_infcmd (void)
2915 static struct cmd_list_element
*info_proc_cmdlist
;
2916 struct cmd_list_element
*c
= NULL
;
2917 const char *cmd_name
;
2919 /* Add the filename of the terminal connected to inferior I/O. */
2920 add_setshow_filename_cmd ("inferior-tty", class_run
,
2921 &inferior_io_terminal_scratch
, _("\
2922 Set terminal for future runs of program being debugged."), _("\
2923 Show terminal for future runs of program being debugged."), _("\
2924 Usage: set inferior-tty /dev/pts/1"),
2925 set_inferior_tty_command
,
2926 show_inferior_tty_command
,
2927 &setlist
, &showlist
);
2928 add_com_alias ("tty", "set inferior-tty", class_alias
, 0);
2931 add_setshow_string_noescape_cmd (cmd_name
, class_run
,
2932 &inferior_args_scratch
, _("\
2933 Set argument list to give program being debugged when it is started."), _("\
2934 Show argument list to give program being debugged when it is started."), _("\
2935 Follow this command with any number of args, to be passed to the program."),
2938 &setlist
, &showlist
);
2939 c
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
2940 gdb_assert (c
!= NULL
);
2941 set_cmd_completer (c
, filename_completer
);
2943 c
= add_cmd ("environment", no_class
, environment_info
, _("\
2944 The environment to give the program, or one variable's value.\n\
2945 With an argument VAR, prints the value of environment variable VAR to\n\
2946 give the program being debugged. With no arguments, prints the entire\n\
2947 environment to be given to the program."), &showlist
);
2948 set_cmd_completer (c
, noop_completer
);
2950 add_prefix_cmd ("unset", no_class
, unset_command
,
2951 _("Complement to certain \"set\" commands."),
2952 &unsetlist
, "unset ", 0, &cmdlist
);
2954 c
= add_cmd ("environment", class_run
, unset_environment_command
, _("\
2955 Cancel environment variable VAR for the program.\n\
2956 This does not affect the program until the next \"run\" command."),
2958 set_cmd_completer (c
, noop_completer
);
2960 c
= add_cmd ("environment", class_run
, set_environment_command
, _("\
2961 Set environment variable value to give the program.\n\
2962 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2963 VALUES of environment variables are uninterpreted strings.\n\
2964 This does not affect the program until the next \"run\" command."),
2966 set_cmd_completer (c
, noop_completer
);
2968 c
= add_com ("path", class_files
, path_command
, _("\
2969 Add directory DIR(s) to beginning of search path for object files.\n\
2970 $cwd in the path means the current working directory.\n\
2971 This path is equivalent to the $PATH shell variable. It is a list of\n\
2972 directories, separated by colons. These directories are searched to find\n\
2973 fully linked executable files and separately compiled object files as \
2975 set_cmd_completer (c
, filename_completer
);
2977 c
= add_cmd ("paths", no_class
, path_info
, _("\
2978 Current search path for finding object files.\n\
2979 $cwd in the path means the current working directory.\n\
2980 This path is equivalent to the $PATH shell variable. It is a list of\n\
2981 directories, separated by colons. These directories are searched to find\n\
2982 fully linked executable files and separately compiled object files as \
2985 set_cmd_completer (c
, noop_completer
);
2987 add_prefix_cmd ("kill", class_run
, kill_command
,
2988 _("Kill execution of program being debugged."),
2989 &killlist
, "kill ", 0, &cmdlist
);
2991 add_com ("attach", class_run
, attach_command
, _("\
2992 Attach to a process or file outside of GDB.\n\
2993 This command attaches to another target, of the same type as your last\n\
2994 \"target\" command (\"info files\" will show your target stack).\n\
2995 The command may take as argument a process id or a device file.\n\
2996 For a process id, you must have permission to send the process a signal,\n\
2997 and it must have the same effective uid as the debugger.\n\
2998 When using \"attach\" with a process id, the debugger finds the\n\
2999 program running in the process, looking first in the current working\n\
3000 directory, or (if not found there) using the source file search path\n\
3001 (see the \"directory\" command). You can also use the \"file\" command\n\
3002 to specify the program, and to load its symbol table."));
3004 add_prefix_cmd ("detach", class_run
, detach_command
, _("\
3005 Detach a process or file previously attached.\n\
3006 If a process, it is no longer traced, and it continues its execution. If\n\
3007 you were debugging a file, the file is closed and gdb no longer accesses it."),
3008 &detachlist
, "detach ", 0, &cmdlist
);
3010 add_com ("disconnect", class_run
, disconnect_command
, _("\
3011 Disconnect from a target.\n\
3012 The target will wait for another debugger to connect. Not available for\n\
3015 c
= add_com ("signal", class_run
, signal_command
, _("\
3016 Continue program with the specified signal.\n\
3017 Usage: signal SIGNAL\n\
3018 The SIGNAL argument is processed the same as the handle command.\n\
3020 An argument of \"0\" means continue the program without sending it a signal.\n\
3021 This is useful in cases where the program stopped because of a signal,\n\
3022 and you want to resume the program while discarding the signal."));
3023 set_cmd_completer (c
, signal_completer
);
3025 add_com ("stepi", class_run
, stepi_command
, _("\
3026 Step one instruction exactly.\n\
3028 Argument N means step N times (or till program stops for another \
3030 add_com_alias ("si", "stepi", class_alias
, 0);
3032 add_com ("nexti", class_run
, nexti_command
, _("\
3033 Step one instruction, but proceed through subroutine calls.\n\
3035 Argument N means step N times (or till program stops for another \
3037 add_com_alias ("ni", "nexti", class_alias
, 0);
3039 add_com ("finish", class_run
, finish_command
, _("\
3040 Execute until selected stack frame returns.\n\
3042 Upon return, the value returned is printed and put in the value history."));
3043 add_com_alias ("fin", "finish", class_run
, 1);
3045 add_com ("next", class_run
, next_command
, _("\
3046 Step program, proceeding through subroutine calls.\n\
3048 Unlike \"step\", if the current source line calls a subroutine,\n\
3049 this command does not enter the subroutine, but instead steps over\n\
3050 the call, in effect treating it as a single source line."));
3051 add_com_alias ("n", "next", class_run
, 1);
3053 add_com_alias ("S", "next", class_run
, 1);
3055 add_com ("step", class_run
, step_command
, _("\
3056 Step program until it reaches a different source line.\n\
3058 Argument N means step N times (or till program stops for another \
3060 add_com_alias ("s", "step", class_run
, 1);
3062 c
= add_com ("until", class_run
, until_command
, _("\
3063 Execute until the program reaches a source line greater than the current\n\
3064 or a specified location (same args as break command) within the current \
3066 set_cmd_completer (c
, location_completer
);
3067 add_com_alias ("u", "until", class_run
, 1);
3069 c
= add_com ("advance", class_run
, advance_command
, _("\
3070 Continue the program up to the given location (same form as args for break \
3072 Execution will also stop upon exit from the current stack frame."));
3073 set_cmd_completer (c
, location_completer
);
3075 c
= add_com ("jump", class_run
, jump_command
, _("\
3076 Continue program being debugged at specified line or address.\n\
3077 Usage: jump <location>\n\
3078 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
3079 for an address to start at."));
3080 set_cmd_completer (c
, location_completer
);
3081 add_com_alias ("j", "jump", class_run
, 1);
3085 c
= add_com ("go", class_run
, go_command
, _("\
3086 Usage: go <location>\n\
3087 Continue program being debugged, stopping at specified line or \n\
3089 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
3090 expression for an address to start at.\n\
3091 This command is a combination of tbreak and jump."));
3092 set_cmd_completer (c
, location_completer
);
3096 add_com_alias ("g", "go", class_run
, 1);
3098 add_com ("continue", class_run
, continue_command
, _("\
3099 Continue program being debugged, after signal or breakpoint.\n\
3100 Usage: continue [N]\n\
3101 If proceeding from breakpoint, a number N may be used as an argument,\n\
3102 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
3103 the breakpoint won't break until the Nth time it is reached).\n\
3105 If non-stop mode is enabled, continue only the current thread,\n\
3106 otherwise all the threads in the program are continued. To \n\
3107 continue all stopped threads in non-stop mode, use the -a option.\n\
3108 Specifying -a and an ignore count simultaneously is an error."));
3109 add_com_alias ("c", "cont", class_run
, 1);
3110 add_com_alias ("fg", "cont", class_run
, 1);
3112 c
= add_com ("run", class_run
, run_command
, _("\
3113 Start debugged program. You may specify arguments to give it.\n\
3114 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
3115 Input and output redirection with \">\", \"<\", or \">>\" are also \
3117 With no arguments, uses arguments last specified (with \"run\" \
3118 or \"set args\").\n\
3119 To cancel previous arguments and run with no arguments,\n\
3120 use \"set args\" without arguments."));
3121 set_cmd_completer (c
, filename_completer
);
3122 add_com_alias ("r", "run", class_run
, 1);
3124 add_com ("R", class_run
, run_no_args_command
,
3125 _("Start debugged program with no arguments."));
3127 c
= add_com ("start", class_run
, start_command
, _("\
3128 Run the debugged program until the beginning of the main procedure.\n\
3129 You may specify arguments to give to your program, just as with the\n\
3130 \"run\" command."));
3131 set_cmd_completer (c
, filename_completer
);
3133 add_com ("interrupt", class_run
, interrupt_command
,
3134 _("Interrupt the execution of the debugged program.\n\
3135 If non-stop mode is enabled, interrupt only the current thread,\n\
3136 otherwise all the threads in the program are stopped. To \n\
3137 interrupt all running threads in non-stop mode, use the -a option."));
3139 add_info ("registers", nofp_registers_info
, _("\
3140 List of integer registers and their contents, for selected stack frame.\n\
3141 Register name as argument means describe only that register."));
3142 add_info_alias ("r", "registers", 1);
3145 add_com ("lr", class_info
, nofp_registers_info
, _("\
3146 List of integer registers and their contents, for selected stack frame.\n\
3147 Register name as argument means describe only that register."));
3148 add_info ("all-registers", all_registers_info
, _("\
3149 List of all registers and their contents, for selected stack frame.\n\
3150 Register name as argument means describe only that register."));
3152 add_info ("program", program_info
,
3153 _("Execution status of the program."));
3155 add_info ("float", float_info
,
3156 _("Print the status of the floating point unit\n"));
3158 add_info ("vector", vector_info
,
3159 _("Print the status of the vector unit\n"));
3161 add_prefix_cmd ("proc", class_info
, info_proc_cmd
,
3163 Show /proc process information about any running process.\n\
3164 Specify any process id, or use the program being debugged by default."),
3165 &info_proc_cmdlist
, "info proc ",
3166 1/*allow-unknown*/, &infolist
);
3168 add_cmd ("mappings", class_info
, info_proc_cmd_mappings
, _("\
3169 List of mapped memory regions."),
3170 &info_proc_cmdlist
);
3172 add_cmd ("stat", class_info
, info_proc_cmd_stat
, _("\
3173 List process info from /proc/PID/stat."),
3174 &info_proc_cmdlist
);
3176 add_cmd ("status", class_info
, info_proc_cmd_status
, _("\
3177 List process info from /proc/PID/status."),
3178 &info_proc_cmdlist
);
3180 add_cmd ("cwd", class_info
, info_proc_cmd_cwd
, _("\
3181 List current working directory of the process."),
3182 &info_proc_cmdlist
);
3184 add_cmd ("cmdline", class_info
, info_proc_cmd_cmdline
, _("\
3185 List command line arguments of the process."),
3186 &info_proc_cmdlist
);
3188 add_cmd ("exe", class_info
, info_proc_cmd_exe
, _("\
3189 List absolute filename for executable of the process."),
3190 &info_proc_cmdlist
);
3192 add_cmd ("all", class_info
, info_proc_cmd_all
, _("\
3193 List all available /proc info."),
3194 &info_proc_cmdlist
);