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