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