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