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