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