Implement -exec-continue/-exec-interrupt --all.
[binutils-gdb.git] / gdb / infcmd.c
1 /* Memory-access and commands for "inferior" process, for GDB.
2
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include <signal.h>
24 #include "gdb_string.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "frame.h"
28 #include "inferior.h"
29 #include "environ.h"
30 #include "value.h"
31 #include "gdbcmd.h"
32 #include "symfile.h"
33 #include "gdbcore.h"
34 #include "target.h"
35 #include "language.h"
36 #include "symfile.h"
37 #include "objfiles.h"
38 #include "completer.h"
39 #include "ui-out.h"
40 #include "event-top.h"
41 #include "parser-defs.h"
42 #include "regcache.h"
43 #include "reggroups.h"
44 #include "block.h"
45 #include "solib.h"
46 #include <ctype.h>
47 #include "gdb_assert.h"
48 #include "observer.h"
49 #include "target-descriptions.h"
50 #include "user-regs.h"
51 #include "exceptions.h"
52 #include "cli/cli-decode.h"
53 #include "gdbthread.h"
54
55 /* Functions exported for general use, in inferior.h: */
56
57 void all_registers_info (char *, int);
58
59 void registers_info (char *, int);
60
61 void nexti_command (char *, int);
62
63 void stepi_command (char *, int);
64
65 void continue_command (char *, int);
66
67 void interrupt_target_command (char *args, int from_tty);
68
69 /* Local functions: */
70
71 static void nofp_registers_info (char *, int);
72
73 static void print_return_value (struct type *func_type,
74 struct type *value_type);
75
76 static void finish_command_continuation (struct continuation_arg *,
77 int error_p);
78
79 static void until_next_command (int);
80
81 static void until_command (char *, int);
82
83 static void path_info (char *, int);
84
85 static void path_command (char *, int);
86
87 static void unset_command (char *, int);
88
89 static void float_info (char *, int);
90
91 static void detach_command (char *, int);
92
93 static void disconnect_command (char *, int);
94
95 static void unset_environment_command (char *, int);
96
97 static void set_environment_command (char *, int);
98
99 static void environment_info (char *, int);
100
101 static void program_info (char *, int);
102
103 static void finish_command (char *, int);
104
105 static void signal_command (char *, int);
106
107 static void jump_command (char *, int);
108
109 static void step_1 (int, int, char *);
110 static void step_once (int skip_subroutines, int single_inst, int count, int thread);
111 static void step_1_continuation (struct continuation_arg *arg, int error_p);
112
113 static void next_command (char *, int);
114
115 static void step_command (char *, int);
116
117 static void run_command (char *, int);
118
119 static void run_no_args_command (char *args, int from_tty);
120
121 static void go_command (char *line_no, int from_tty);
122
123 static int strip_bg_char (char **);
124
125 void _initialize_infcmd (void);
126
127 #define GO_USAGE "Usage: go <location>\n"
128
129 #define ERROR_NO_INFERIOR \
130 if (!target_has_execution) error (_("The program is not being run."));
131
132 /* String containing arguments to give to the program, separated by spaces.
133 Empty string (pointer to '\0') means no args. */
134
135 static char *inferior_args;
136
137 /* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
138 then we must compute INFERIOR_ARGS from this (via the target). */
139
140 static int inferior_argc;
141 static char **inferior_argv;
142
143 /* File name for default use for standard in/out in the inferior. */
144
145 static char *inferior_io_terminal;
146
147 /* Pid of our debugged inferior, or 0 if no inferior now.
148 Since various parts of infrun.c test this to see whether there is a program
149 being debugged it should be nonzero (currently 3 is used) for remote
150 debugging. */
151
152 ptid_t inferior_ptid;
153
154 /* Last signal that the inferior received (why it stopped). */
155
156 enum target_signal stop_signal;
157
158 /* Address at which inferior stopped. */
159
160 CORE_ADDR stop_pc;
161
162 /* Chain containing status of breakpoint(s) that we have stopped at. */
163
164 bpstat stop_bpstat;
165
166 /* Flag indicating that a command has proceeded the inferior past the
167 current breakpoint. */
168
169 int breakpoint_proceeded;
170
171 /* Nonzero if stopped due to a step command. */
172
173 int stop_step;
174
175 /* Nonzero if stopped due to completion of a stack dummy routine. */
176
177 int stop_stack_dummy;
178
179 /* Nonzero if stopped due to a random (unexpected) signal in inferior
180 process. */
181
182 int stopped_by_random_signal;
183
184 /* Range to single step within.
185 If this is nonzero, respond to a single-step signal
186 by continuing to step if the pc is in this range. */
187
188 CORE_ADDR step_range_start; /* Inclusive */
189 CORE_ADDR step_range_end; /* Exclusive */
190
191 /* Stack frame address as of when stepping command was issued.
192 This is how we know when we step into a subroutine call,
193 and how to set the frame for the breakpoint used to step out. */
194
195 struct frame_id step_frame_id;
196
197 enum step_over_calls_kind step_over_calls;
198
199 /* If stepping, nonzero means step count is > 1
200 so don't print frame next time inferior stops
201 if it stops due to stepping. */
202
203 int step_multi;
204
205 /* Environment to use for running inferior,
206 in format described in environ.h. */
207
208 struct gdb_environ *inferior_environ;
209
210 /* When set, no calls to target_resumed observer will be made. */
211 int suppress_resume_observer = 0;
212 /* When set, normal_stop will not call the normal_stop observer. */
213 int suppress_stop_observer = 0;
214 \f
215 /* Accessor routines. */
216
217 void
218 set_inferior_io_terminal (const char *terminal_name)
219 {
220 if (inferior_io_terminal)
221 xfree (inferior_io_terminal);
222
223 if (!terminal_name)
224 inferior_io_terminal = NULL;
225 else
226 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
227 }
228
229 const char *
230 get_inferior_io_terminal (void)
231 {
232 return inferior_io_terminal;
233 }
234
235 char *
236 get_inferior_args (void)
237 {
238 if (inferior_argc != 0)
239 {
240 char *n, *old;
241
242 n = gdbarch_construct_inferior_arguments (current_gdbarch,
243 inferior_argc, inferior_argv);
244 old = set_inferior_args (n);
245 xfree (old);
246 }
247
248 if (inferior_args == NULL)
249 inferior_args = xstrdup ("");
250
251 return inferior_args;
252 }
253
254 char *
255 set_inferior_args (char *newargs)
256 {
257 char *saved_args = inferior_args;
258
259 inferior_args = newargs;
260 inferior_argc = 0;
261 inferior_argv = 0;
262
263 return saved_args;
264 }
265
266 void
267 set_inferior_args_vector (int argc, char **argv)
268 {
269 inferior_argc = argc;
270 inferior_argv = argv;
271 }
272
273 /* Notice when `set args' is run. */
274 static void
275 notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
276 {
277 inferior_argc = 0;
278 inferior_argv = 0;
279 }
280
281 /* Notice when `show args' is run. */
282 static void
283 notice_args_read (struct ui_file *file, int from_tty,
284 struct cmd_list_element *c, const char *value)
285 {
286 /* Note that we ignore the passed-in value in favor of computing it
287 directly. */
288 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
289 }
290
291 \f
292 /* Compute command-line string given argument vector. This does the
293 same shell processing as fork_inferior. */
294 char *
295 construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
296 {
297 char *result;
298
299 if (STARTUP_WITH_SHELL)
300 {
301 /* This holds all the characters considered special to the
302 typical Unix shells. We include `^' because the SunOS
303 /bin/sh treats it as a synonym for `|'. */
304 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
305 int i;
306 int length = 0;
307 char *out, *cp;
308
309 /* We over-compute the size. It shouldn't matter. */
310 for (i = 0; i < argc; ++i)
311 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
312
313 result = (char *) xmalloc (length);
314 out = result;
315
316 for (i = 0; i < argc; ++i)
317 {
318 if (i > 0)
319 *out++ = ' ';
320
321 /* Need to handle empty arguments specially. */
322 if (argv[i][0] == '\0')
323 {
324 *out++ = '\'';
325 *out++ = '\'';
326 }
327 else
328 {
329 for (cp = argv[i]; *cp; ++cp)
330 {
331 if (strchr (special, *cp) != NULL)
332 *out++ = '\\';
333 *out++ = *cp;
334 }
335 }
336 }
337 *out = '\0';
338 }
339 else
340 {
341 /* In this case we can't handle arguments that contain spaces,
342 tabs, or newlines -- see breakup_args(). */
343 int i;
344 int length = 0;
345
346 for (i = 0; i < argc; ++i)
347 {
348 char *cp = strchr (argv[i], ' ');
349 if (cp == NULL)
350 cp = strchr (argv[i], '\t');
351 if (cp == NULL)
352 cp = strchr (argv[i], '\n');
353 if (cp != NULL)
354 error (_("can't handle command-line argument containing whitespace"));
355 length += strlen (argv[i]) + 1;
356 }
357
358 result = (char *) xmalloc (length);
359 result[0] = '\0';
360 for (i = 0; i < argc; ++i)
361 {
362 if (i > 0)
363 strcat (result, " ");
364 strcat (result, argv[i]);
365 }
366 }
367
368 return result;
369 }
370 \f
371
372 /* This function detects whether or not a '&' character (indicating
373 background execution) has been added as *the last* of the arguments ARGS
374 of a command. If it has, it removes it and returns 1. Otherwise it
375 does nothing and returns 0. */
376 static int
377 strip_bg_char (char **args)
378 {
379 char *p = NULL;
380
381 p = strchr (*args, '&');
382
383 if (p)
384 {
385 if (p == (*args + strlen (*args) - 1))
386 {
387 if (strlen (*args) > 1)
388 {
389 do
390 p--;
391 while (*p == ' ' || *p == '\t');
392 *(p + 1) = '\0';
393 }
394 else
395 *args = 0;
396 return 1;
397 }
398 }
399 return 0;
400 }
401
402 void
403 tty_command (char *file, int from_tty)
404 {
405 if (file == 0)
406 error_no_arg (_("terminal name for running target process"));
407
408 set_inferior_io_terminal (file);
409 }
410
411 /* Common actions to take after creating any sort of inferior, by any
412 means (running, attaching, connecting, et cetera). The target
413 should be stopped. */
414
415 void
416 post_create_inferior (struct target_ops *target, int from_tty)
417 {
418 /* Be sure we own the terminal in case write operations are performed. */
419 target_terminal_ours ();
420
421 /* If the target hasn't taken care of this already, do it now.
422 Targets which need to access registers during to_open,
423 to_create_inferior, or to_attach should do it earlier; but many
424 don't need to. */
425 target_find_description ();
426
427 if (exec_bfd)
428 {
429 /* Sometimes the platform-specific hook loads initial shared
430 libraries, and sometimes it doesn't. Try to do so first, so
431 that we can add them with the correct value for FROM_TTY.
432 If we made all the inferior hook methods consistent,
433 this call could be removed. */
434 #ifdef SOLIB_ADD
435 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
436 #else
437 solib_add (NULL, from_tty, target, auto_solib_add);
438 #endif
439
440 /* Create the hooks to handle shared library load and unload
441 events. */
442 #ifdef SOLIB_CREATE_INFERIOR_HOOK
443 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
444 #else
445 solib_create_inferior_hook ();
446 #endif
447 }
448
449 observer_notify_inferior_created (target, from_tty);
450 }
451
452 /* Kill the inferior if already running. This function is designed
453 to be called when we are about to start the execution of the program
454 from the beginning. Ask the user to confirm that he wants to restart
455 the program being debugged when FROM_TTY is non-null. */
456
457 static void
458 kill_if_already_running (int from_tty)
459 {
460 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
461 {
462 /* Bail out before killing the program if we will not be able to
463 restart it. */
464 target_require_runnable ();
465
466 if (from_tty
467 && !query ("The program being debugged has been started already.\n\
468 Start it from the beginning? "))
469 error (_("Program not restarted."));
470 target_kill ();
471 no_shared_libraries (NULL, from_tty);
472 init_wait_for_inferior ();
473 }
474 }
475
476 /* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
477 a temporary breakpoint at the begining of the main program before
478 running the program. */
479
480 static void
481 run_command_1 (char *args, int from_tty, int tbreak_at_main)
482 {
483 char *exec_file;
484
485 dont_repeat ();
486
487 kill_if_already_running (from_tty);
488 clear_breakpoint_hit_counts ();
489
490 /* Clean up any leftovers from other runs. Some other things from
491 this function should probably be moved into target_pre_inferior. */
492 target_pre_inferior (from_tty);
493
494 /* Purge old solib objfiles. */
495 objfile_purge_solibs ();
496
497 clear_solib ();
498
499 /* The comment here used to read, "The exec file is re-read every
500 time we do a generic_mourn_inferior, so we just have to worry
501 about the symbol file." The `generic_mourn_inferior' function
502 gets called whenever the program exits. However, suppose the
503 program exits, and *then* the executable file changes? We need
504 to check again here. Since reopen_exec_file doesn't do anything
505 if the timestamp hasn't changed, I don't see the harm. */
506 reopen_exec_file ();
507 reread_symbols ();
508
509 /* Insert the temporary breakpoint if a location was specified. */
510 if (tbreak_at_main)
511 tbreak_command (main_name (), 0);
512
513 exec_file = (char *) get_exec_file (0);
514
515 /* We keep symbols from add-symbol-file, on the grounds that the
516 user might want to add some symbols before running the program
517 (right?). But sometimes (dynamic loading where the user manually
518 introduces the new symbols with add-symbol-file), the code which
519 the symbols describe does not persist between runs. Currently
520 the user has to manually nuke all symbols between runs if they
521 want them to go away (PR 2207). This is probably reasonable. */
522
523 if (!args)
524 {
525 if (target_can_async_p ())
526 async_disable_stdin ();
527 }
528 else
529 {
530 int async_exec = strip_bg_char (&args);
531
532 /* If we get a request for running in the bg but the target
533 doesn't support it, error out. */
534 if (async_exec && !target_can_async_p ())
535 error (_("Asynchronous execution not supported on this target."));
536
537 /* If we don't get a request of running in the bg, then we need
538 to simulate synchronous (fg) execution. */
539 if (!async_exec && target_can_async_p ())
540 {
541 /* Simulate synchronous execution */
542 async_disable_stdin ();
543 }
544
545 /* If there were other args, beside '&', process them. */
546 if (args)
547 {
548 char *old_args = set_inferior_args (xstrdup (args));
549 xfree (old_args);
550 }
551 }
552
553 if (from_tty)
554 {
555 ui_out_field_string (uiout, NULL, "Starting program");
556 ui_out_text (uiout, ": ");
557 if (exec_file)
558 ui_out_field_string (uiout, "execfile", exec_file);
559 ui_out_spaces (uiout, 1);
560 /* We call get_inferior_args() because we might need to compute
561 the value now. */
562 ui_out_field_string (uiout, "infargs", get_inferior_args ());
563 ui_out_text (uiout, "\n");
564 ui_out_flush (uiout);
565 }
566
567 /* We call get_inferior_args() because we might need to compute
568 the value now. */
569 target_create_inferior (exec_file, get_inferior_args (),
570 environ_vector (inferior_environ), from_tty);
571
572 /* Pass zero for FROM_TTY, because at this point the "run" command
573 has done its thing; now we are setting up the running program. */
574 post_create_inferior (&current_target, 0);
575
576 /* Start the target running. */
577 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
578 }
579
580
581 static void
582 run_command (char *args, int from_tty)
583 {
584 run_command_1 (args, from_tty, 0);
585 }
586
587 static void
588 run_no_args_command (char *args, int from_tty)
589 {
590 char *old_args = set_inferior_args (xstrdup (""));
591 xfree (old_args);
592 }
593 \f
594
595 /* Start the execution of the program up until the beginning of the main
596 program. */
597
598 static void
599 start_command (char *args, int from_tty)
600 {
601 /* Some languages such as Ada need to search inside the program
602 minimal symbols for the location where to put the temporary
603 breakpoint before starting. */
604 if (!have_minimal_symbols ())
605 error (_("No symbol table loaded. Use the \"file\" command."));
606
607 /* Run the program until reaching the main procedure... */
608 run_command_1 (args, from_tty, 1);
609 }
610
611 static int
612 proceed_thread_callback (struct thread_info *thread, void *arg)
613 {
614 if (!is_stopped (thread->ptid))
615 return 0;
616
617 context_switch_to (thread->ptid);
618 clear_proceed_status ();
619 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
620 return 0;
621 }
622
623 void
624 continue_1 (int all_threads)
625 {
626 if (non_stop && all_threads)
627 {
628 /* Don't error out if the current thread is running, because
629 there may be other stopped threads. */
630 struct cleanup *old_chain;
631
632 /* Backup current thread and selected frame. */
633 old_chain = make_cleanup_restore_current_thread ();
634
635 iterate_over_threads (proceed_thread_callback, NULL);
636
637 /* Restore selected ptid. */
638 do_cleanups (old_chain);
639 }
640 else
641 {
642 ensure_not_running ();
643 clear_proceed_status ();
644 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
645 }
646 }
647
648 /* continue [-a] [proceed-count] [&] */
649 void
650 continue_command (char *args, int from_tty)
651 {
652 int async_exec = 0;
653 int all_threads = 0;
654 ERROR_NO_INFERIOR;
655
656 /* Find out whether we must run in the background. */
657 if (args != NULL)
658 async_exec = strip_bg_char (&args);
659
660 /* If we must run in the background, but the target can't do it,
661 error out. */
662 if (async_exec && !target_can_async_p ())
663 error (_("Asynchronous execution not supported on this target."));
664
665 /* If we are not asked to run in the bg, then prepare to run in the
666 foreground, synchronously. */
667 if (!async_exec && target_can_async_p ())
668 {
669 /* Simulate synchronous execution */
670 async_disable_stdin ();
671 }
672
673 if (args != NULL)
674 {
675 if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
676 {
677 all_threads = 1;
678 args += sizeof ("-a") - 1;
679 if (*args == '\0')
680 args = NULL;
681 }
682 }
683
684 if (!non_stop && all_threads)
685 error (_("`-a' is meaningless in all-stop mode."));
686
687 if (args != NULL && all_threads)
688 error (_("\
689 Can't resume all threads and specify proceed count simultaneously."));
690
691 /* If we have an argument left, set proceed count of breakpoint we
692 stopped at. */
693 if (args != NULL)
694 {
695 bpstat bs = stop_bpstat;
696 int num, stat;
697 int stopped = 0;
698
699 while ((stat = bpstat_num (&bs, &num)) != 0)
700 if (stat > 0)
701 {
702 set_ignore_count (num,
703 parse_and_eval_long (args) - 1,
704 from_tty);
705 /* set_ignore_count prints a message ending with a period.
706 So print two spaces before "Continuing.". */
707 if (from_tty)
708 printf_filtered (" ");
709 stopped = 1;
710 }
711
712 if (!stopped && from_tty)
713 {
714 printf_filtered
715 ("Not stopped at any breakpoint; argument ignored.\n");
716 }
717 }
718
719 if (from_tty)
720 printf_filtered (_("Continuing.\n"));
721
722 continue_1 (all_threads);
723 }
724 \f
725 /* Step until outside of current statement. */
726
727 static void
728 step_command (char *count_string, int from_tty)
729 {
730 step_1 (0, 0, count_string);
731 }
732
733 /* Likewise, but skip over subroutine calls as if single instructions. */
734
735 static void
736 next_command (char *count_string, int from_tty)
737 {
738 step_1 (1, 0, count_string);
739 }
740
741 /* Likewise, but step only one instruction. */
742
743 void
744 stepi_command (char *count_string, int from_tty)
745 {
746 step_1 (0, 1, count_string);
747 }
748
749 void
750 nexti_command (char *count_string, int from_tty)
751 {
752 step_1 (1, 1, count_string);
753 }
754
755 static void
756 delete_longjmp_breakpoint_cleanup (void *arg)
757 {
758 int thread = * (int *) arg;
759 delete_longjmp_breakpoint (thread);
760 }
761
762 static void
763 step_1 (int skip_subroutines, int single_inst, char *count_string)
764 {
765 int count = 1;
766 struct frame_info *frame;
767 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
768 int async_exec = 0;
769 int thread = -1;
770
771 ERROR_NO_INFERIOR;
772 ensure_not_running ();
773
774 if (count_string)
775 async_exec = strip_bg_char (&count_string);
776
777 /* If we get a request for running in the bg but the target
778 doesn't support it, error out. */
779 if (async_exec && !target_can_async_p ())
780 error (_("Asynchronous execution not supported on this target."));
781
782 /* If we don't get a request of running in the bg, then we need
783 to simulate synchronous (fg) execution. */
784 if (!async_exec && target_can_async_p ())
785 {
786 /* Simulate synchronous execution */
787 async_disable_stdin ();
788 }
789
790 count = count_string ? parse_and_eval_long (count_string) : 1;
791
792 if (!single_inst || skip_subroutines) /* leave si command alone */
793 {
794 if (in_thread_list (inferior_ptid))
795 thread = pid_to_thread_id (inferior_ptid);
796
797 set_longjmp_breakpoint ();
798
799 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
800 }
801
802 /* In synchronous case, all is well, just use the regular for loop. */
803 if (!target_can_async_p ())
804 {
805 for (; count > 0; count--)
806 {
807 clear_proceed_status ();
808
809 frame = get_current_frame ();
810 if (!frame) /* Avoid coredump here. Why tho? */
811 error (_("No current frame"));
812 step_frame_id = get_frame_id (frame);
813
814 if (!single_inst)
815 {
816 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
817 if (step_range_end == 0)
818 {
819 char *name;
820 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
821 &step_range_end) == 0)
822 error (_("Cannot find bounds of current function"));
823
824 target_terminal_ours ();
825 printf_filtered (_("\
826 Single stepping until exit from function %s, \n\
827 which has no line number information.\n"), name);
828 }
829 }
830 else
831 {
832 /* Say we are stepping, but stop after one insn whatever it does. */
833 step_range_start = step_range_end = 1;
834 if (!skip_subroutines)
835 /* It is stepi.
836 Don't step over function calls, not even to functions lacking
837 line numbers. */
838 step_over_calls = STEP_OVER_NONE;
839 }
840
841 if (skip_subroutines)
842 step_over_calls = STEP_OVER_ALL;
843
844 step_multi = (count > 1);
845 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
846
847 if (!stop_step)
848 break;
849 }
850
851 do_cleanups (cleanups);
852 return;
853 }
854 /* In case of asynchronous target things get complicated, do only
855 one step for now, before returning control to the event loop. Let
856 the continuation figure out how many other steps we need to do,
857 and handle them one at the time, through step_once(). */
858 else
859 {
860 step_once (skip_subroutines, single_inst, count, thread);
861 /* We are running, and the continuation is installed. It will
862 disable the longjmp breakpoint as appropriate. */
863 discard_cleanups (cleanups);
864 }
865 }
866
867 /* Called after we are done with one step operation, to check whether
868 we need to step again, before we print the prompt and return control
869 to the user. If count is > 1, we will need to do one more call to
870 proceed(), via step_once(). Basically it is like step_once and
871 step_1_continuation are co-recursive. */
872 static void
873 step_1_continuation (struct continuation_arg *arg, int error_p)
874 {
875 int count;
876 int skip_subroutines;
877 int single_inst;
878 int thread;
879
880 skip_subroutines = arg->data.integer;
881 single_inst = arg->next->data.integer;
882 count = arg->next->next->data.integer;
883 thread = arg->next->next->next->data.integer;
884
885 if (error_p || !step_multi || !stop_step)
886 {
887 /* We either hit an error, or stopped for some reason
888 that is not stepping, or there are no further steps
889 to make. Cleanup. */
890 if (!single_inst || skip_subroutines)
891 delete_longjmp_breakpoint (thread);
892 step_multi = 0;
893 }
894 else
895 step_once (skip_subroutines, single_inst, count - 1, thread);
896 }
897
898 /* Do just one step operation. If count >1 we will have to set up a
899 continuation to be done after the target stops (after this one
900 step). This is useful to implement the 'step n' kind of commands, in
901 case of asynchronous targets. We had to split step_1 into two parts,
902 one to be done before proceed() and one afterwards. This function is
903 called in case of step n with n>1, after the first step operation has
904 been completed.*/
905 static void
906 step_once (int skip_subroutines, int single_inst, int count, int thread)
907 {
908 struct continuation_arg *arg1;
909 struct continuation_arg *arg2;
910 struct continuation_arg *arg3;
911 struct continuation_arg *arg4;
912 struct frame_info *frame;
913
914 if (count > 0)
915 {
916 clear_proceed_status ();
917
918 frame = get_current_frame ();
919 if (!frame) /* Avoid coredump here. Why tho? */
920 error (_("No current frame"));
921 step_frame_id = get_frame_id (frame);
922
923 if (!single_inst)
924 {
925 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
926
927 /* If we have no line info, switch to stepi mode. */
928 if (step_range_end == 0 && step_stop_if_no_debug)
929 {
930 step_range_start = step_range_end = 1;
931 }
932 else if (step_range_end == 0)
933 {
934 char *name;
935 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
936 &step_range_end) == 0)
937 error (_("Cannot find bounds of current function"));
938
939 target_terminal_ours ();
940 printf_filtered (_("\
941 Single stepping until exit from function %s, \n\
942 which has no line number information.\n"), name);
943 }
944 }
945 else
946 {
947 /* Say we are stepping, but stop after one insn whatever it does. */
948 step_range_start = step_range_end = 1;
949 if (!skip_subroutines)
950 /* It is stepi.
951 Don't step over function calls, not even to functions lacking
952 line numbers. */
953 step_over_calls = STEP_OVER_NONE;
954 }
955
956 if (skip_subroutines)
957 step_over_calls = STEP_OVER_ALL;
958
959 step_multi = (count > 1);
960 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
961 arg1 =
962 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
963 arg2 =
964 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
965 arg3 =
966 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
967 arg4 =
968 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
969 arg1->next = arg2;
970 arg1->data.integer = skip_subroutines;
971 arg2->next = arg3;
972 arg2->data.integer = single_inst;
973 arg3->next = arg4;
974 arg3->data.integer = count;
975 arg4->next = NULL;
976 arg4->data.integer = thread;
977 add_intermediate_continuation (step_1_continuation, arg1);
978 }
979 }
980
981 \f
982 /* Continue program at specified address. */
983
984 static void
985 jump_command (char *arg, int from_tty)
986 {
987 CORE_ADDR addr;
988 struct symtabs_and_lines sals;
989 struct symtab_and_line sal;
990 struct symbol *fn;
991 struct symbol *sfn;
992 int async_exec = 0;
993
994 ERROR_NO_INFERIOR;
995 ensure_not_running ();
996
997 /* Find out whether we must run in the background. */
998 if (arg != NULL)
999 async_exec = strip_bg_char (&arg);
1000
1001 /* If we must run in the background, but the target can't do it,
1002 error out. */
1003 if (async_exec && !target_can_async_p ())
1004 error (_("Asynchronous execution not supported on this target."));
1005
1006 if (!arg)
1007 error_no_arg (_("starting address"));
1008
1009 sals = decode_line_spec_1 (arg, 1);
1010 if (sals.nelts != 1)
1011 {
1012 error (_("Unreasonable jump request"));
1013 }
1014
1015 sal = sals.sals[0];
1016 xfree (sals.sals);
1017
1018 if (sal.symtab == 0 && sal.pc == 0)
1019 error (_("No source file has been specified."));
1020
1021 resolve_sal_pc (&sal); /* May error out */
1022
1023 /* See if we are trying to jump to another function. */
1024 fn = get_frame_function (get_current_frame ());
1025 sfn = find_pc_function (sal.pc);
1026 if (fn != NULL && sfn != fn)
1027 {
1028 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
1029 SYMBOL_PRINT_NAME (fn)))
1030 {
1031 error (_("Not confirmed."));
1032 /* NOTREACHED */
1033 }
1034 }
1035
1036 if (sfn != NULL)
1037 {
1038 fixup_symbol_section (sfn, 0);
1039 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
1040 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
1041 {
1042 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
1043 {
1044 error (_("Not confirmed."));
1045 /* NOTREACHED */
1046 }
1047 }
1048 }
1049
1050 addr = sal.pc;
1051
1052 if (from_tty)
1053 {
1054 printf_filtered (_("Continuing at "));
1055 fputs_filtered (paddress (addr), gdb_stdout);
1056 printf_filtered (".\n");
1057 }
1058
1059 /* If we are not asked to run in the bg, then prepare to run in the
1060 foreground, synchronously. */
1061 if (!async_exec && target_can_async_p ())
1062 {
1063 /* Simulate synchronous execution */
1064 async_disable_stdin ();
1065 }
1066
1067 clear_proceed_status ();
1068 proceed (addr, TARGET_SIGNAL_0, 0);
1069 }
1070 \f
1071
1072 /* Go to line or address in current procedure */
1073 static void
1074 go_command (char *line_no, int from_tty)
1075 {
1076 if (line_no == (char *) NULL || !*line_no)
1077 printf_filtered (GO_USAGE);
1078 else
1079 {
1080 tbreak_command (line_no, from_tty);
1081 jump_command (line_no, from_tty);
1082 }
1083 }
1084 \f
1085
1086 /* Continue program giving it specified signal. */
1087
1088 static void
1089 signal_command (char *signum_exp, int from_tty)
1090 {
1091 enum target_signal oursig;
1092 int async_exec = 0;
1093
1094 dont_repeat (); /* Too dangerous. */
1095 ERROR_NO_INFERIOR;
1096 ensure_not_running ();
1097
1098 /* Find out whether we must run in the background. */
1099 if (signum_exp != NULL)
1100 async_exec = strip_bg_char (&signum_exp);
1101
1102 /* If we must run in the background, but the target can't do it,
1103 error out. */
1104 if (async_exec && !target_can_async_p ())
1105 error (_("Asynchronous execution not supported on this target."));
1106
1107 /* If we are not asked to run in the bg, then prepare to run in the
1108 foreground, synchronously. */
1109 if (!async_exec && target_can_async_p ())
1110 {
1111 /* Simulate synchronous execution. */
1112 async_disable_stdin ();
1113 }
1114
1115 if (!signum_exp)
1116 error_no_arg (_("signal number"));
1117
1118 /* It would be even slicker to make signal names be valid expressions,
1119 (the type could be "enum $signal" or some such), then the user could
1120 assign them to convenience variables. */
1121 oursig = target_signal_from_name (signum_exp);
1122
1123 if (oursig == TARGET_SIGNAL_UNKNOWN)
1124 {
1125 /* No, try numeric. */
1126 int num = parse_and_eval_long (signum_exp);
1127
1128 if (num == 0)
1129 oursig = TARGET_SIGNAL_0;
1130 else
1131 oursig = target_signal_from_command (num);
1132 }
1133
1134 if (from_tty)
1135 {
1136 if (oursig == TARGET_SIGNAL_0)
1137 printf_filtered (_("Continuing with no signal.\n"));
1138 else
1139 printf_filtered (_("Continuing with signal %s.\n"),
1140 target_signal_to_name (oursig));
1141 }
1142
1143 clear_proceed_status ();
1144 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1145 FIXME: Neither should "signal foo" but when I tried passing
1146 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1147 tried to track down yet. */
1148 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
1149 }
1150
1151 /* Proceed until we reach a different source line with pc greater than
1152 our current one or exit the function. We skip calls in both cases.
1153
1154 Note that eventually this command should probably be changed so
1155 that only source lines are printed out when we hit the breakpoint
1156 we set. This may involve changes to wait_for_inferior and the
1157 proceed status code. */
1158
1159 static void
1160 until_next_command (int from_tty)
1161 {
1162 struct frame_info *frame;
1163 CORE_ADDR pc;
1164 struct symbol *func;
1165 struct symtab_and_line sal;
1166
1167 clear_proceed_status ();
1168
1169 frame = get_current_frame ();
1170
1171 /* Step until either exited from this function or greater
1172 than the current line (if in symbolic section) or pc (if
1173 not). */
1174
1175 pc = read_pc ();
1176 func = find_pc_function (pc);
1177
1178 if (!func)
1179 {
1180 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
1181
1182 if (msymbol == NULL)
1183 error (_("Execution is not within a known function."));
1184
1185 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1186 step_range_end = pc;
1187 }
1188 else
1189 {
1190 sal = find_pc_line (pc, 0);
1191
1192 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1193 step_range_end = sal.end;
1194 }
1195
1196 step_over_calls = STEP_OVER_ALL;
1197 step_frame_id = get_frame_id (frame);
1198
1199 step_multi = 0; /* Only one call to proceed */
1200
1201 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1202 }
1203
1204 static void
1205 until_command (char *arg, int from_tty)
1206 {
1207 int async_exec = 0;
1208
1209 if (!target_has_execution)
1210 error (_("The program is not running."));
1211
1212 /* Find out whether we must run in the background. */
1213 if (arg != NULL)
1214 async_exec = strip_bg_char (&arg);
1215
1216 /* If we must run in the background, but the target can't do it,
1217 error out. */
1218 if (async_exec && !target_can_async_p ())
1219 error (_("Asynchronous execution not supported on this target."));
1220
1221 /* If we are not asked to run in the bg, then prepare to run in the
1222 foreground, synchronously. */
1223 if (!async_exec && target_can_async_p ())
1224 {
1225 /* Simulate synchronous execution */
1226 async_disable_stdin ();
1227 }
1228
1229 if (arg)
1230 until_break_command (arg, from_tty, 0);
1231 else
1232 until_next_command (from_tty);
1233 }
1234
1235 static void
1236 advance_command (char *arg, int from_tty)
1237 {
1238 int async_exec = 0;
1239
1240 if (!target_has_execution)
1241 error (_("The program is not running."));
1242
1243 if (arg == NULL)
1244 error_no_arg (_("a location"));
1245
1246 /* Find out whether we must run in the background. */
1247 if (arg != NULL)
1248 async_exec = strip_bg_char (&arg);
1249
1250 /* If we must run in the background, but the target can't do it,
1251 error out. */
1252 if (async_exec && !target_can_async_p ())
1253 error (_("Asynchronous execution not supported on this target."));
1254
1255 /* If we are not asked to run in the bg, then prepare to run in the
1256 foreground, synchronously. */
1257 if (!async_exec && target_can_async_p ())
1258 {
1259 /* Simulate synchronous execution. */
1260 async_disable_stdin ();
1261 }
1262
1263 until_break_command (arg, from_tty, 1);
1264 }
1265 \f
1266 /* Print the result of a function at the end of a 'finish' command. */
1267
1268 static void
1269 print_return_value (struct type *func_type, struct type *value_type)
1270 {
1271 struct gdbarch *gdbarch = current_gdbarch;
1272 struct cleanup *old_chain;
1273 struct ui_stream *stb;
1274 struct value *value;
1275
1276 CHECK_TYPEDEF (value_type);
1277 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
1278
1279 /* FIXME: 2003-09-27: When returning from a nested inferior function
1280 call, it's possible (with no help from the architecture vector)
1281 to locate and return/print a "struct return" value. This is just
1282 a more complicated case of what is already being done in in the
1283 inferior function call code. In fact, when inferior function
1284 calls are made async, this will likely be made the norm. */
1285
1286 switch (gdbarch_return_value (gdbarch, func_type, value_type,
1287 NULL, NULL, NULL))
1288 {
1289 case RETURN_VALUE_REGISTER_CONVENTION:
1290 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
1291 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
1292 value = allocate_value (value_type);
1293 gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
1294 value_contents_raw (value), NULL);
1295 break;
1296 case RETURN_VALUE_STRUCT_CONVENTION:
1297 value = NULL;
1298 break;
1299 default:
1300 internal_error (__FILE__, __LINE__, _("bad switch"));
1301 }
1302
1303 if (value)
1304 {
1305 /* Print it. */
1306 stb = ui_out_stream_new (uiout);
1307 old_chain = make_cleanup_ui_out_stream_delete (stb);
1308 ui_out_text (uiout, "Value returned is ");
1309 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1310 record_latest_value (value));
1311 ui_out_text (uiout, " = ");
1312 value_print (value, stb->stream, 0, Val_no_prettyprint);
1313 ui_out_field_stream (uiout, "return-value", stb);
1314 ui_out_text (uiout, "\n");
1315 do_cleanups (old_chain);
1316 }
1317 else
1318 {
1319 ui_out_text (uiout, "Value returned has type: ");
1320 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1321 ui_out_text (uiout, ".");
1322 ui_out_text (uiout, " Cannot determine contents\n");
1323 }
1324 }
1325
1326 /* Stuff that needs to be done by the finish command after the target
1327 has stopped. In asynchronous mode, we wait for the target to stop
1328 in the call to poll or select in the event loop, so it is
1329 impossible to do all the stuff as part of the finish_command
1330 function itself. The only chance we have to complete this command
1331 is in fetch_inferior_event, which is called by the event loop as
1332 soon as it detects that the target has stopped. This function is
1333 called via the cmd_continuation pointer. */
1334
1335 static void
1336 finish_command_continuation (struct continuation_arg *arg, int error_p)
1337 {
1338 struct symbol *function;
1339 struct breakpoint *breakpoint;
1340 struct cleanup *cleanups;
1341
1342 breakpoint = (struct breakpoint *) arg->data.pointer;
1343 function = (struct symbol *) arg->next->data.pointer;
1344
1345 if (!error_p)
1346 {
1347 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1348 && function != NULL)
1349 {
1350 struct type *value_type;
1351
1352 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1353 if (!value_type)
1354 internal_error (__FILE__, __LINE__,
1355 _("finish_command: function has no target type"));
1356
1357 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1358 print_return_value (SYMBOL_TYPE (function), value_type);
1359 }
1360
1361 /* We suppress normal call of normal_stop observer and do it here so that
1362 that *stopped notification includes the return value. */
1363 observer_notify_normal_stop (stop_bpstat);
1364 }
1365
1366 suppress_stop_observer = 0;
1367 delete_breakpoint (breakpoint);
1368 }
1369
1370 /* "finish": Set a temporary breakpoint at the place the selected
1371 frame will return to, then continue. */
1372
1373 static void
1374 finish_command (char *arg, int from_tty)
1375 {
1376 struct symtab_and_line sal;
1377 struct frame_info *frame;
1378 struct symbol *function;
1379 struct breakpoint *breakpoint;
1380 struct cleanup *old_chain;
1381 struct continuation_arg *arg1, *arg2, *arg3;
1382
1383 int async_exec = 0;
1384
1385 /* Find out whether we must run in the background. */
1386 if (arg != NULL)
1387 async_exec = strip_bg_char (&arg);
1388
1389 /* If we must run in the background, but the target can't do it,
1390 error out. */
1391 if (async_exec && !target_can_async_p ())
1392 error (_("Asynchronous execution not supported on this target."));
1393
1394 /* If we are not asked to run in the bg, then prepare to run in the
1395 foreground, synchronously. */
1396 if (!async_exec && target_can_async_p ())
1397 {
1398 /* Simulate synchronous execution. */
1399 async_disable_stdin ();
1400 }
1401
1402 if (arg)
1403 error (_("The \"finish\" command does not take any arguments."));
1404 if (!target_has_execution)
1405 error (_("The program is not running."));
1406
1407 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
1408 if (frame == 0)
1409 error (_("\"finish\" not meaningful in the outermost frame."));
1410
1411 clear_proceed_status ();
1412
1413 sal = find_pc_line (get_frame_pc (frame), 0);
1414 sal.pc = get_frame_pc (frame);
1415
1416 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame), bp_finish);
1417
1418 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1419
1420 /* Find the function we will return from. */
1421
1422 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
1423
1424 /* Print info on the selected frame, including level number but not
1425 source. */
1426 if (from_tty)
1427 {
1428 printf_filtered (_("Run till exit from "));
1429 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
1430 }
1431
1432 proceed_to_finish = 1; /* We want stop_registers, please... */
1433 make_cleanup_restore_integer (&suppress_stop_observer);
1434 suppress_stop_observer = 1;
1435 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1436
1437 arg1 =
1438 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1439 arg2 =
1440 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
1441 arg1->next = arg2;
1442 arg2->next = NULL;
1443 arg1->data.pointer = breakpoint;
1444 arg2->data.pointer = function;
1445 add_continuation (finish_command_continuation, arg1);
1446
1447 discard_cleanups (old_chain);
1448 if (!target_can_async_p ())
1449 do_all_continuations (0);
1450 }
1451 \f
1452
1453 static void
1454 program_info (char *args, int from_tty)
1455 {
1456 bpstat bs = stop_bpstat;
1457 int num;
1458 int stat = bpstat_num (&bs, &num);
1459
1460 if (!target_has_execution)
1461 {
1462 printf_filtered (_("The program being debugged is not being run.\n"));
1463 return;
1464 }
1465
1466 target_files_info ();
1467 printf_filtered (_("Program stopped at %s.\n"),
1468 hex_string ((unsigned long) stop_pc));
1469 if (stop_step)
1470 printf_filtered (_("It stopped after being stepped.\n"));
1471 else if (stat != 0)
1472 {
1473 /* There may be several breakpoints in the same place, so this
1474 isn't as strange as it seems. */
1475 while (stat != 0)
1476 {
1477 if (stat < 0)
1478 {
1479 printf_filtered (_("\
1480 It stopped at a breakpoint that has since been deleted.\n"));
1481 }
1482 else
1483 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
1484 stat = bpstat_num (&bs, &num);
1485 }
1486 }
1487 else if (stop_signal != TARGET_SIGNAL_0)
1488 {
1489 printf_filtered (_("It stopped with signal %s, %s.\n"),
1490 target_signal_to_name (stop_signal),
1491 target_signal_to_string (stop_signal));
1492 }
1493
1494 if (!from_tty)
1495 {
1496 printf_filtered (_("\
1497 Type \"info stack\" or \"info registers\" for more information.\n"));
1498 }
1499 }
1500 \f
1501 static void
1502 environment_info (char *var, int from_tty)
1503 {
1504 if (var)
1505 {
1506 char *val = get_in_environ (inferior_environ, var);
1507 if (val)
1508 {
1509 puts_filtered (var);
1510 puts_filtered (" = ");
1511 puts_filtered (val);
1512 puts_filtered ("\n");
1513 }
1514 else
1515 {
1516 puts_filtered ("Environment variable \"");
1517 puts_filtered (var);
1518 puts_filtered ("\" not defined.\n");
1519 }
1520 }
1521 else
1522 {
1523 char **vector = environ_vector (inferior_environ);
1524 while (*vector)
1525 {
1526 puts_filtered (*vector++);
1527 puts_filtered ("\n");
1528 }
1529 }
1530 }
1531
1532 static void
1533 set_environment_command (char *arg, int from_tty)
1534 {
1535 char *p, *val, *var;
1536 int nullset = 0;
1537
1538 if (arg == 0)
1539 error_no_arg (_("environment variable and value"));
1540
1541 /* Find seperation between variable name and value */
1542 p = (char *) strchr (arg, '=');
1543 val = (char *) strchr (arg, ' ');
1544
1545 if (p != 0 && val != 0)
1546 {
1547 /* We have both a space and an equals. If the space is before the
1548 equals, walk forward over the spaces til we see a nonspace
1549 (possibly the equals). */
1550 if (p > val)
1551 while (*val == ' ')
1552 val++;
1553
1554 /* Now if the = is after the char following the spaces,
1555 take the char following the spaces. */
1556 if (p > val)
1557 p = val - 1;
1558 }
1559 else if (val != 0 && p == 0)
1560 p = val;
1561
1562 if (p == arg)
1563 error_no_arg (_("environment variable to set"));
1564
1565 if (p == 0 || p[1] == 0)
1566 {
1567 nullset = 1;
1568 if (p == 0)
1569 p = arg + strlen (arg); /* So that savestring below will work */
1570 }
1571 else
1572 {
1573 /* Not setting variable value to null */
1574 val = p + 1;
1575 while (*val == ' ' || *val == '\t')
1576 val++;
1577 }
1578
1579 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1580 p--;
1581
1582 var = savestring (arg, p - arg);
1583 if (nullset)
1584 {
1585 printf_filtered (_("\
1586 Setting environment variable \"%s\" to null value.\n"),
1587 var);
1588 set_in_environ (inferior_environ, var, "");
1589 }
1590 else
1591 set_in_environ (inferior_environ, var, val);
1592 xfree (var);
1593 }
1594
1595 static void
1596 unset_environment_command (char *var, int from_tty)
1597 {
1598 if (var == 0)
1599 {
1600 /* If there is no argument, delete all environment variables.
1601 Ask for confirmation if reading from the terminal. */
1602 if (!from_tty || query (_("Delete all environment variables? ")))
1603 {
1604 free_environ (inferior_environ);
1605 inferior_environ = make_environ ();
1606 }
1607 }
1608 else
1609 unset_in_environ (inferior_environ, var);
1610 }
1611
1612 /* Handle the execution path (PATH variable) */
1613
1614 static const char path_var_name[] = "PATH";
1615
1616 static void
1617 path_info (char *args, int from_tty)
1618 {
1619 puts_filtered ("Executable and object file path: ");
1620 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1621 puts_filtered ("\n");
1622 }
1623
1624 /* Add zero or more directories to the front of the execution path. */
1625
1626 static void
1627 path_command (char *dirname, int from_tty)
1628 {
1629 char *exec_path;
1630 char *env;
1631 dont_repeat ();
1632 env = get_in_environ (inferior_environ, path_var_name);
1633 /* Can be null if path is not set */
1634 if (!env)
1635 env = "";
1636 exec_path = xstrdup (env);
1637 mod_path (dirname, &exec_path);
1638 set_in_environ (inferior_environ, path_var_name, exec_path);
1639 xfree (exec_path);
1640 if (from_tty)
1641 path_info ((char *) NULL, from_tty);
1642 }
1643 \f
1644
1645 /* Print out the machine register regnum. If regnum is -1, print all
1646 registers (print_all == 1) or all non-float and non-vector
1647 registers (print_all == 0).
1648
1649 For most machines, having all_registers_info() print the
1650 register(s) one per line is good enough. If a different format is
1651 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1652 regs), or there is an existing convention for showing all the
1653 registers, define the architecture method PRINT_REGISTERS_INFO to
1654 provide that format. */
1655
1656 void
1657 default_print_registers_info (struct gdbarch *gdbarch,
1658 struct ui_file *file,
1659 struct frame_info *frame,
1660 int regnum, int print_all)
1661 {
1662 int i;
1663 const int numregs = gdbarch_num_regs (gdbarch)
1664 + gdbarch_num_pseudo_regs (gdbarch);
1665 gdb_byte buffer[MAX_REGISTER_SIZE];
1666
1667 for (i = 0; i < numregs; i++)
1668 {
1669 /* Decide between printing all regs, non-float / vector regs, or
1670 specific reg. */
1671 if (regnum == -1)
1672 {
1673 if (print_all)
1674 {
1675 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
1676 continue;
1677 }
1678 else
1679 {
1680 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
1681 continue;
1682 }
1683 }
1684 else
1685 {
1686 if (i != regnum)
1687 continue;
1688 }
1689
1690 /* If the register name is empty, it is undefined for this
1691 processor, so don't display anything. */
1692 if (gdbarch_register_name (gdbarch, i) == NULL
1693 || *(gdbarch_register_name (gdbarch, i)) == '\0')
1694 continue;
1695
1696 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
1697 print_spaces_filtered (15 - strlen (gdbarch_register_name
1698 (gdbarch, i)), file);
1699
1700 /* Get the data in raw format. */
1701 if (! frame_register_read (frame, i, buffer))
1702 {
1703 fprintf_filtered (file, "*value not available*\n");
1704 continue;
1705 }
1706
1707 /* If virtual format is floating, print it that way, and in raw
1708 hex. */
1709 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1710 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
1711 {
1712 int j;
1713
1714 val_print (register_type (gdbarch, i), buffer, 0, 0,
1715 file, 0, 1, 0, Val_pretty_default, current_language);
1716
1717 fprintf_filtered (file, "\t(raw 0x");
1718 for (j = 0; j < register_size (gdbarch, i); j++)
1719 {
1720 int idx;
1721 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1722 idx = j;
1723 else
1724 idx = register_size (gdbarch, i) - 1 - j;
1725 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
1726 }
1727 fprintf_filtered (file, ")");
1728 }
1729 else
1730 {
1731 /* Print the register in hex. */
1732 val_print (register_type (gdbarch, i), buffer, 0, 0,
1733 file, 'x', 1, 0, Val_pretty_default, current_language);
1734 /* If not a vector register, print it also according to its
1735 natural format. */
1736 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
1737 {
1738 fprintf_filtered (file, "\t");
1739 val_print (register_type (gdbarch, i), buffer, 0, 0,
1740 file, 0, 1, 0, Val_pretty_default, current_language);
1741 }
1742 }
1743
1744 fprintf_filtered (file, "\n");
1745 }
1746 }
1747
1748 void
1749 registers_info (char *addr_exp, int fpregs)
1750 {
1751 struct frame_info *frame;
1752 struct gdbarch *gdbarch;
1753 int regnum, numregs;
1754 char *end;
1755
1756 if (!target_has_registers)
1757 error (_("The program has no registers now."));
1758 frame = get_selected_frame (NULL);
1759 gdbarch = get_frame_arch (frame);
1760
1761 if (!addr_exp)
1762 {
1763 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1764 frame, -1, fpregs);
1765 return;
1766 }
1767
1768 while (*addr_exp != '\0')
1769 {
1770 char *start;
1771 const char *end;
1772
1773 /* Keep skipping leading white space. */
1774 if (isspace ((*addr_exp)))
1775 {
1776 addr_exp++;
1777 continue;
1778 }
1779
1780 /* Discard any leading ``$''. Check that there is something
1781 resembling a register following it. */
1782 if (addr_exp[0] == '$')
1783 addr_exp++;
1784 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
1785 error (_("Missing register name"));
1786
1787 /* Find the start/end of this register name/num/group. */
1788 start = addr_exp;
1789 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1790 addr_exp++;
1791 end = addr_exp;
1792
1793 /* Figure out what we've found and display it. */
1794
1795 /* A register name? */
1796 {
1797 int regnum = frame_map_name_to_regnum (frame, start, end - start);
1798 if (regnum >= 0)
1799 {
1800 /* User registers lie completely outside of the range of
1801 normal registers. Catch them early so that the target
1802 never sees them. */
1803 if (regnum >= gdbarch_num_regs (gdbarch)
1804 + gdbarch_num_pseudo_regs (gdbarch))
1805 {
1806 struct value *val = value_of_user_reg (regnum, frame);
1807
1808 printf_filtered ("%s: ", start);
1809 print_scalar_formatted (value_contents (val),
1810 check_typedef (value_type (val)),
1811 'x', 0, gdb_stdout);
1812 printf_filtered ("\n");
1813 }
1814 else
1815 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1816 frame, regnum, fpregs);
1817 continue;
1818 }
1819 }
1820
1821 /* A register number? (how portable is this one?). */
1822 {
1823 char *endptr;
1824 int regnum = strtol (start, &endptr, 0);
1825 if (endptr == end
1826 && regnum >= 0
1827 && regnum < gdbarch_num_regs (gdbarch)
1828 + gdbarch_num_pseudo_regs (gdbarch))
1829 {
1830 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1831 frame, regnum, fpregs);
1832 continue;
1833 }
1834 }
1835
1836 /* A register group? */
1837 {
1838 struct reggroup *group;
1839 for (group = reggroup_next (gdbarch, NULL);
1840 group != NULL;
1841 group = reggroup_next (gdbarch, group))
1842 {
1843 /* Don't bother with a length check. Should the user
1844 enter a short register group name, go with the first
1845 group that matches. */
1846 if (strncmp (start, reggroup_name (group), end - start) == 0)
1847 break;
1848 }
1849 if (group != NULL)
1850 {
1851 int regnum;
1852 for (regnum = 0;
1853 regnum < gdbarch_num_regs (gdbarch)
1854 + gdbarch_num_pseudo_regs (gdbarch);
1855 regnum++)
1856 {
1857 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1858 gdbarch_print_registers_info (gdbarch,
1859 gdb_stdout, frame,
1860 regnum, fpregs);
1861 }
1862 continue;
1863 }
1864 }
1865
1866 /* Nothing matched. */
1867 error (_("Invalid register `%.*s'"), (int) (end - start), start);
1868 }
1869 }
1870
1871 void
1872 all_registers_info (char *addr_exp, int from_tty)
1873 {
1874 registers_info (addr_exp, 1);
1875 }
1876
1877 static void
1878 nofp_registers_info (char *addr_exp, int from_tty)
1879 {
1880 registers_info (addr_exp, 0);
1881 }
1882
1883 static void
1884 print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1885 struct frame_info *frame, const char *args)
1886 {
1887 if (gdbarch_print_vector_info_p (gdbarch))
1888 gdbarch_print_vector_info (gdbarch, file, frame, args);
1889 else
1890 {
1891 int regnum;
1892 int printed_something = 0;
1893
1894 for (regnum = 0;
1895 regnum < gdbarch_num_regs (gdbarch)
1896 + gdbarch_num_pseudo_regs (gdbarch);
1897 regnum++)
1898 {
1899 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
1900 {
1901 printed_something = 1;
1902 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
1903 }
1904 }
1905 if (!printed_something)
1906 fprintf_filtered (file, "No vector information\n");
1907 }
1908 }
1909
1910 static void
1911 vector_info (char *args, int from_tty)
1912 {
1913 if (!target_has_registers)
1914 error (_("The program has no registers now."));
1915
1916 print_vector_info (current_gdbarch, gdb_stdout,
1917 get_selected_frame (NULL), args);
1918 }
1919 \f
1920
1921 /*
1922 * TODO:
1923 * Should save/restore the tty state since it might be that the
1924 * program to be debugged was started on this tty and it wants
1925 * the tty in some state other than what we want. If it's running
1926 * on another terminal or without a terminal, then saving and
1927 * restoring the tty state is a harmless no-op.
1928 * This only needs to be done if we are attaching to a process.
1929 */
1930
1931 /*
1932 attach_command --
1933 takes a program started up outside of gdb and ``attaches'' to it.
1934 This stops it cold in its tracks and allows us to start debugging it.
1935 and wait for the trace-trap that results from attaching. */
1936
1937 static void
1938 attach_command_post_wait (char *args, int from_tty, int async_exec)
1939 {
1940 char *exec_file;
1941 char *full_exec_path = NULL;
1942
1943 stop_soon = NO_STOP_QUIETLY;
1944
1945 /* If no exec file is yet known, try to determine it from the
1946 process itself. */
1947 exec_file = (char *) get_exec_file (0);
1948 if (!exec_file)
1949 {
1950 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
1951 if (exec_file)
1952 {
1953 /* It's possible we don't have a full path, but rather just a
1954 filename. Some targets, such as HP-UX, don't provide the
1955 full path, sigh.
1956
1957 Attempt to qualify the filename against the source path.
1958 (If that fails, we'll just fall back on the original
1959 filename. Not much more we can do...)
1960 */
1961 if (!source_full_path_of (exec_file, &full_exec_path))
1962 full_exec_path = savestring (exec_file, strlen (exec_file));
1963
1964 exec_file_attach (full_exec_path, from_tty);
1965 symbol_file_add_main (full_exec_path, from_tty);
1966 }
1967 }
1968 else
1969 {
1970 reopen_exec_file ();
1971 reread_symbols ();
1972 }
1973
1974 /* Take any necessary post-attaching actions for this platform. */
1975 target_post_attach (PIDGET (inferior_ptid));
1976
1977 post_create_inferior (&current_target, from_tty);
1978
1979 /* Install inferior's terminal modes. */
1980 target_terminal_inferior ();
1981
1982 if (async_exec)
1983 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
1984 else
1985 {
1986 if (target_can_async_p ())
1987 async_enable_stdin ();
1988 normal_stop ();
1989 if (deprecated_attach_hook)
1990 deprecated_attach_hook ();
1991 }
1992 }
1993
1994 static void
1995 attach_command_continuation (struct continuation_arg *arg, int error_p)
1996 {
1997 char *args;
1998 int from_tty;
1999 int async_exec;
2000
2001 args = (char *) arg->data.pointer;
2002 from_tty = arg->next->data.integer;
2003 async_exec = arg->next->next->data.integer;
2004
2005 attach_command_post_wait (args, from_tty, async_exec);
2006 }
2007
2008 void
2009 attach_command (char *args, int from_tty)
2010 {
2011 char *exec_file;
2012 char *full_exec_path = NULL;
2013 int async_exec = 0;
2014
2015 dont_repeat (); /* Not for the faint of heart */
2016
2017 if (target_has_execution)
2018 {
2019 if (query ("A program is being debugged already. Kill it? "))
2020 target_kill ();
2021 else
2022 error (_("Not killed."));
2023 }
2024
2025 /* Clean up any leftovers from other runs. Some other things from
2026 this function should probably be moved into target_pre_inferior. */
2027 target_pre_inferior (from_tty);
2028
2029 /* Clear out solib state. Otherwise the solib state of the previous
2030 inferior might have survived and is entirely wrong for the new
2031 target. This has been observed on GNU/Linux using glibc 2.3. How
2032 to reproduce:
2033
2034 bash$ ./foo&
2035 [1] 4711
2036 bash$ ./foo&
2037 [1] 4712
2038 bash$ gdb ./foo
2039 [...]
2040 (gdb) attach 4711
2041 (gdb) detach
2042 (gdb) attach 4712
2043 Cannot access memory at address 0xdeadbeef
2044 */
2045 clear_solib ();
2046
2047 if (args)
2048 {
2049 async_exec = strip_bg_char (&args);
2050
2051 /* If we get a request for running in the bg but the target
2052 doesn't support it, error out. */
2053 if (async_exec && !target_can_async_p ())
2054 error (_("Asynchronous execution not supported on this target."));
2055 }
2056
2057 /* If we don't get a request of running in the bg, then we need
2058 to simulate synchronous (fg) execution. */
2059 if (!async_exec && target_can_async_p ())
2060 {
2061 /* Simulate synchronous execution */
2062 async_disable_stdin ();
2063 }
2064
2065 target_attach (args, from_tty);
2066
2067 /* Set up the "saved terminal modes" of the inferior
2068 based on what modes we are starting it with. */
2069 target_terminal_init ();
2070
2071 /* Set up execution context to know that we should return from
2072 wait_for_inferior as soon as the target reports a stop. */
2073 init_wait_for_inferior ();
2074 clear_proceed_status ();
2075
2076 /* Some system don't generate traps when attaching to inferior.
2077 E.g. Mach 3 or GNU hurd. */
2078 if (!target_attach_no_wait)
2079 {
2080 /* Careful here. See comments in inferior.h. Basically some
2081 OSes don't ignore SIGSTOPs on continue requests anymore. We
2082 need a way for handle_inferior_event to reset the stop_signal
2083 variable after an attach, and this is what
2084 STOP_QUIETLY_NO_SIGSTOP is for. */
2085 stop_soon = STOP_QUIETLY_NO_SIGSTOP;
2086
2087 if (target_can_async_p ())
2088 {
2089 /* sync_execution mode. Wait for stop. */
2090 struct continuation_arg *arg1, *arg2, *arg3;
2091
2092 arg1 =
2093 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2094 arg2 =
2095 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2096 arg3 =
2097 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
2098 arg1->next = arg2;
2099 arg2->next = arg3;
2100 arg3->next = NULL;
2101 arg1->data.pointer = args;
2102 arg2->data.integer = from_tty;
2103 arg3->data.integer = async_exec;
2104 add_continuation (attach_command_continuation, arg1);
2105 return;
2106 }
2107
2108 wait_for_inferior (0);
2109 }
2110
2111 attach_command_post_wait (args, from_tty, async_exec);
2112 }
2113
2114 /*
2115 * detach_command --
2116 * takes a program previously attached to and detaches it.
2117 * The program resumes execution and will no longer stop
2118 * on signals, etc. We better not have left any breakpoints
2119 * in the program or it'll die when it hits one. For this
2120 * to work, it may be necessary for the process to have been
2121 * previously attached. It *might* work if the program was
2122 * started via the normal ptrace (PTRACE_TRACEME).
2123 */
2124
2125 static void
2126 detach_command (char *args, int from_tty)
2127 {
2128 dont_repeat (); /* Not for the faint of heart. */
2129 target_detach (args, from_tty);
2130 no_shared_libraries (NULL, from_tty);
2131 init_thread_list ();
2132 if (deprecated_detach_hook)
2133 deprecated_detach_hook ();
2134 }
2135
2136 /* Disconnect from the current target without resuming it (leaving it
2137 waiting for a debugger).
2138
2139 We'd better not have left any breakpoints in the program or the
2140 next debugger will get confused. Currently only supported for some
2141 remote targets, since the normal attach mechanisms don't work on
2142 stopped processes on some native platforms (e.g. GNU/Linux). */
2143
2144 static void
2145 disconnect_command (char *args, int from_tty)
2146 {
2147 dont_repeat (); /* Not for the faint of heart */
2148 target_disconnect (args, from_tty);
2149 no_shared_libraries (NULL, from_tty);
2150 init_thread_list ();
2151 if (deprecated_detach_hook)
2152 deprecated_detach_hook ();
2153 }
2154
2155 void
2156 interrupt_target_1 (int all_threads)
2157 {
2158 ptid_t ptid;
2159 if (all_threads)
2160 ptid = minus_one_ptid;
2161 else
2162 ptid = inferior_ptid;
2163 target_stop (ptid);
2164 }
2165
2166 /* Stop the execution of the target while running in async mode, in
2167 the backgound. In all-stop, stop the whole process. In non-stop
2168 mode, stop the current thread only by default, or stop all threads
2169 if the `-a' switch is used. */
2170
2171 /* interrupt [-a] */
2172 void
2173 interrupt_target_command (char *args, int from_tty)
2174 {
2175 if (target_can_async_p ())
2176 {
2177 int all_threads = 0;
2178
2179 dont_repeat (); /* Not for the faint of heart */
2180
2181 if (args != NULL
2182 && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
2183 all_threads = 1;
2184
2185 if (!non_stop && all_threads)
2186 error (_("-a is meaningless in all-stop mode."));
2187
2188 interrupt_target_1 (all_threads);
2189 }
2190 }
2191
2192 static void
2193 print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2194 struct frame_info *frame, const char *args)
2195 {
2196 if (gdbarch_print_float_info_p (gdbarch))
2197 gdbarch_print_float_info (gdbarch, file, frame, args);
2198 else
2199 {
2200 int regnum;
2201 int printed_something = 0;
2202
2203 for (regnum = 0;
2204 regnum < gdbarch_num_regs (gdbarch)
2205 + gdbarch_num_pseudo_regs (gdbarch);
2206 regnum++)
2207 {
2208 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
2209 {
2210 printed_something = 1;
2211 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
2212 }
2213 }
2214 if (!printed_something)
2215 fprintf_filtered (file, "\
2216 No floating-point info available for this processor.\n");
2217 }
2218 }
2219
2220 static void
2221 float_info (char *args, int from_tty)
2222 {
2223 if (!target_has_registers)
2224 error (_("The program has no registers now."));
2225
2226 print_float_info (current_gdbarch, gdb_stdout,
2227 get_selected_frame (NULL), args);
2228 }
2229 \f
2230 static void
2231 unset_command (char *args, int from_tty)
2232 {
2233 printf_filtered (_("\
2234 \"unset\" must be followed by the name of an unset subcommand.\n"));
2235 help_list (unsetlist, "unset ", -1, gdb_stdout);
2236 }
2237
2238 void
2239 _initialize_infcmd (void)
2240 {
2241 struct cmd_list_element *c = NULL;
2242
2243 /* add the filename of the terminal connected to inferior I/O */
2244 add_setshow_filename_cmd ("inferior-tty", class_run,
2245 &inferior_io_terminal, _("\
2246 Set terminal for future runs of program being debugged."), _("\
2247 Show terminal for future runs of program being debugged."), _("\
2248 Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2249 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
2250
2251 add_setshow_optional_filename_cmd ("args", class_run,
2252 &inferior_args, _("\
2253 Set argument list to give program being debugged when it is started."), _("\
2254 Show argument list to give program being debugged when it is started."), _("\
2255 Follow this command with any number of args, to be passed to the program."),
2256 notice_args_set,
2257 notice_args_read,
2258 &setlist, &showlist);
2259
2260 c = add_cmd ("environment", no_class, environment_info, _("\
2261 The environment to give the program, or one variable's value.\n\
2262 With an argument VAR, prints the value of environment variable VAR to\n\
2263 give the program being debugged. With no arguments, prints the entire\n\
2264 environment to be given to the program."), &showlist);
2265 set_cmd_completer (c, noop_completer);
2266
2267 add_prefix_cmd ("unset", no_class, unset_command,
2268 _("Complement to certain \"set\" commands."),
2269 &unsetlist, "unset ", 0, &cmdlist);
2270
2271 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2272 Cancel environment variable VAR for the program.\n\
2273 This does not affect the program until the next \"run\" command."),
2274 &unsetlist);
2275 set_cmd_completer (c, noop_completer);
2276
2277 c = add_cmd ("environment", class_run, set_environment_command, _("\
2278 Set environment variable value to give the program.\n\
2279 Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2280 VALUES of environment variables are uninterpreted strings.\n\
2281 This does not affect the program until the next \"run\" command."),
2282 &setlist);
2283 set_cmd_completer (c, noop_completer);
2284
2285 c = add_com ("path", class_files, path_command, _("\
2286 Add directory DIR(s) to beginning of search path for object files.\n\
2287 $cwd in the path means the current working directory.\n\
2288 This path is equivalent to the $PATH shell variable. It is a list of\n\
2289 directories, separated by colons. These directories are searched to find\n\
2290 fully linked executable files and separately compiled object files as needed."));
2291 set_cmd_completer (c, filename_completer);
2292
2293 c = add_cmd ("paths", no_class, path_info, _("\
2294 Current search path for finding object files.\n\
2295 $cwd in the path means the current working directory.\n\
2296 This path is equivalent to the $PATH shell variable. It is a list of\n\
2297 directories, separated by colons. These directories are searched to find\n\
2298 fully linked executable files and separately compiled object files as needed."),
2299 &showlist);
2300 set_cmd_completer (c, noop_completer);
2301
2302 add_com ("attach", class_run, attach_command, _("\
2303 Attach to a process or file outside of GDB.\n\
2304 This command attaches to another target, of the same type as your last\n\
2305 \"target\" command (\"info files\" will show your target stack).\n\
2306 The command may take as argument a process id or a device file.\n\
2307 For a process id, you must have permission to send the process a signal,\n\
2308 and it must have the same effective uid as the debugger.\n\
2309 When using \"attach\" with a process id, the debugger finds the\n\
2310 program running in the process, looking first in the current working\n\
2311 directory, or (if not found there) using the source file search path\n\
2312 (see the \"directory\" command). You can also use the \"file\" command\n\
2313 to specify the program, and to load its symbol table."));
2314
2315 add_prefix_cmd ("detach", class_run, detach_command, _("\
2316 Detach a process or file previously attached.\n\
2317 If a process, it is no longer traced, and it continues its execution. If\n\
2318 you were debugging a file, the file is closed and gdb no longer accesses it."),
2319 &detachlist, "detach ", 0, &cmdlist);
2320
2321 add_com ("disconnect", class_run, disconnect_command, _("\
2322 Disconnect from a target.\n\
2323 The target will wait for another debugger to connect. Not available for\n\
2324 all targets."));
2325
2326 add_com ("signal", class_run, signal_command, _("\
2327 Continue program giving it signal specified by the argument.\n\
2328 An argument of \"0\" means continue program without giving it a signal."));
2329
2330 add_com ("stepi", class_run, stepi_command, _("\
2331 Step one instruction exactly.\n\
2332 Argument N means do this N times (or till program stops for another reason)."));
2333 add_com_alias ("si", "stepi", class_alias, 0);
2334
2335 add_com ("nexti", class_run, nexti_command, _("\
2336 Step one instruction, but proceed through subroutine calls.\n\
2337 Argument N means do this N times (or till program stops for another reason)."));
2338 add_com_alias ("ni", "nexti", class_alias, 0);
2339
2340 add_com ("finish", class_run, finish_command, _("\
2341 Execute until selected stack frame returns.\n\
2342 Upon return, the value returned is printed and put in the value history."));
2343 add_com_alias ("fin", "finish", class_run, 1);
2344
2345 add_com ("next", class_run, next_command, _("\
2346 Step program, proceeding through subroutine calls.\n\
2347 Like the \"step\" command as long as subroutine calls do not happen;\n\
2348 when they do, the call is treated as one instruction.\n\
2349 Argument N means do this N times (or till program stops for another reason)."));
2350 add_com_alias ("n", "next", class_run, 1);
2351 if (xdb_commands)
2352 add_com_alias ("S", "next", class_run, 1);
2353
2354 add_com ("step", class_run, step_command, _("\
2355 Step program until it reaches a different source line.\n\
2356 Argument N means do this N times (or till program stops for another reason)."));
2357 add_com_alias ("s", "step", class_run, 1);
2358
2359 c = add_com ("until", class_run, until_command, _("\
2360 Execute until the program reaches a source line greater than the current\n\
2361 or a specified location (same args as break command) within the current frame."));
2362 set_cmd_completer (c, location_completer);
2363 add_com_alias ("u", "until", class_run, 1);
2364
2365 c = add_com ("advance", class_run, advance_command, _("\
2366 Continue the program up to the given location (same form as args for break command).\n\
2367 Execution will also stop upon exit from the current stack frame."));
2368 set_cmd_completer (c, location_completer);
2369
2370 c = add_com ("jump", class_run, jump_command, _("\
2371 Continue program being debugged at specified line or address.\n\
2372 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2373 for an address to start at."));
2374 set_cmd_completer (c, location_completer);
2375
2376 if (xdb_commands)
2377 {
2378 c = add_com ("go", class_run, go_command, _("\
2379 Usage: go <location>\n\
2380 Continue program being debugged, stopping at specified line or \n\
2381 address.\n\
2382 Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2383 expression for an address to start at.\n\
2384 This command is a combination of tbreak and jump."));
2385 set_cmd_completer (c, location_completer);
2386 }
2387
2388 if (xdb_commands)
2389 add_com_alias ("g", "go", class_run, 1);
2390
2391 c = add_com ("continue", class_run, continue_command, _("\
2392 Continue program being debugged, after signal or breakpoint.\n\
2393 If proceeding from breakpoint, a number N may be used as an argument,\n\
2394 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2395 the breakpoint won't break until the Nth time it is reached).\n\
2396 \n\
2397 If non-stop mode is enabled, continue only the current thread,\n\
2398 otherwise all the threads in the program are continued. To \n\
2399 continue all stopped threads in non-stop mode, use the -a option.\n\
2400 Specifying -a and an ignore count simultaneously is an error."));
2401 add_com_alias ("c", "cont", class_run, 1);
2402 add_com_alias ("fg", "cont", class_run, 1);
2403 set_cmd_async_ok (c);
2404
2405 c = add_com ("run", class_run, run_command, _("\
2406 Start debugged program. You may specify arguments to give it.\n\
2407 Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2408 Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2409 With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2410 To cancel previous arguments and run with no arguments,\n\
2411 use \"set args\" without arguments."));
2412 set_cmd_completer (c, filename_completer);
2413 add_com_alias ("r", "run", class_run, 1);
2414 if (xdb_commands)
2415 add_com ("R", class_run, run_no_args_command,
2416 _("Start debugged program with no arguments."));
2417
2418 c = add_com ("start", class_run, start_command, _("\
2419 Run the debugged program until the beginning of the main procedure.\n\
2420 You may specify arguments to give to your program, just as with the\n\
2421 \"run\" command."));
2422 set_cmd_completer (c, filename_completer);
2423
2424 c = add_com ("interrupt", class_run, interrupt_target_command,
2425 _("Interrupt the execution of the debugged program.\n\
2426 If non-stop mode is enabled, interrupt only the current thread,\n\
2427 otherwise all the threads in the program are stopped. To \n\
2428 interrupt all running threads in non-stop mode, use the -a option."));
2429 set_cmd_async_ok (c);
2430
2431 add_info ("registers", nofp_registers_info, _("\
2432 List of integer registers and their contents, for selected stack frame.\n\
2433 Register name as argument means describe only that register."));
2434 add_info_alias ("r", "registers", 1);
2435
2436 if (xdb_commands)
2437 add_com ("lr", class_info, nofp_registers_info, _("\
2438 List of integer registers and their contents, for selected stack frame.\n\
2439 Register name as argument means describe only that register."));
2440 add_info ("all-registers", all_registers_info, _("\
2441 List of all registers and their contents, for selected stack frame.\n\
2442 Register name as argument means describe only that register."));
2443
2444 add_info ("program", program_info,
2445 _("Execution status of the program."));
2446
2447 add_info ("float", float_info,
2448 _("Print the status of the floating point unit\n"));
2449
2450 add_info ("vector", vector_info,
2451 _("Print the status of the vector unit\n"));
2452
2453 inferior_environ = make_environ ();
2454 init_environ (inferior_environ);
2455 }