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