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