]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/infcmd.c
2002-07-03 Martin M. Hunt <hunt@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / infcmd.c
CommitLineData
c906108c 1/* Memory-access and commands for "inferior" process, for GDB.
b6ba6518 2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
8926118c 3 1996, 1997, 1998, 1999, 2000, 2001, 2002
c906108c
SS
4 Free Software Foundation, Inc.
5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b
JM
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include <signal.h>
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "frame.h"
29#include "inferior.h"
30#include "environ.h"
31#include "value.h"
32#include "gdbcmd.h"
1adeb98a 33#include "symfile.h"
c906108c
SS
34#include "gdbcore.h"
35#include "target.h"
36#include "language.h"
37#include "symfile.h"
38#include "objfiles.h"
c94fdfd0 39#include "completer.h"
8b93c638 40#include "ui-out.h"
6426a772 41#include "event-top.h"
96baa820 42#include "parser-defs.h"
c906108c 43
72cec141
AC
44#include "regcache.h" /* for deprecated_grub_regcache_for_registers(). */
45
c906108c
SS
46/* Functions exported for general use: */
47
a14ed312 48void nofp_registers_info (char *, int);
c906108c 49
a14ed312 50void all_registers_info (char *, int);
c906108c 51
a14ed312 52void registers_info (char *, int);
c906108c
SS
53
54/* Local functions: */
55
a14ed312 56void continue_command (char *, int);
c906108c 57
11cf8741
JM
58static void print_return_value (int struct_return, struct type *value_type);
59
a14ed312 60static void finish_command_continuation (struct continuation_arg *);
43ff13b4 61
a14ed312 62static void until_next_command (int);
c906108c 63
a14ed312 64static void until_command (char *, int);
c906108c 65
a14ed312 66static void path_info (char *, int);
c906108c 67
a14ed312 68static void path_command (char *, int);
c906108c 69
a14ed312 70static void unset_command (char *, int);
c906108c 71
a14ed312 72static void float_info (char *, int);
c906108c 73
a14ed312 74static void detach_command (char *, int);
c906108c 75
96baa820
JM
76static void interrupt_target_command (char *args, int from_tty);
77
a14ed312 78static void unset_environment_command (char *, int);
c906108c 79
a14ed312 80static void set_environment_command (char *, int);
c906108c 81
a14ed312 82static void environment_info (char *, int);
c906108c 83
a14ed312 84static void program_info (char *, int);
c906108c 85
a14ed312 86static void finish_command (char *, int);
c906108c 87
a14ed312 88static void signal_command (char *, int);
c906108c 89
a14ed312 90static void jump_command (char *, int);
c906108c 91
a14ed312 92static void step_1 (int, int, char *);
c2d11a7d
JM
93static void step_once (int skip_subroutines, int single_inst, int count);
94static void step_1_continuation (struct continuation_arg *arg);
c906108c 95
a14ed312 96void nexti_command (char *, int);
c906108c 97
a14ed312 98void stepi_command (char *, int);
c906108c 99
a14ed312 100static void next_command (char *, int);
c906108c 101
a14ed312 102static void step_command (char *, int);
c906108c 103
a14ed312 104static void run_command (char *, int);
c906108c 105
a14ed312 106static void run_no_args_command (char *args, int from_tty);
392a587b 107
a14ed312 108static void go_command (char *line_no, int from_tty);
392a587b 109
a14ed312 110static int strip_bg_char (char **);
43ff13b4 111
a14ed312 112void _initialize_infcmd (void);
c906108c
SS
113
114#define GO_USAGE "Usage: go <location>\n"
115
a14ed312 116static void breakpoint_auto_delete_contents (PTR);
c906108c
SS
117
118#define ERROR_NO_INFERIOR \
119 if (!target_has_execution) error ("The program is not being run.");
120
121/* String containing arguments to give to the program, separated by spaces.
122 Empty string (pointer to '\0') means no args. */
123
124static char *inferior_args;
125
552c04a7
TT
126/* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
127 then we must compute INFERIOR_ARGS from this (via the target). */
128
129static int inferior_argc;
130static char **inferior_argv;
131
c906108c
SS
132/* File name for default use for standard in/out in the inferior. */
133
134char *inferior_io_terminal;
135
136/* Pid of our debugged inferior, or 0 if no inferior now.
137 Since various parts of infrun.c test this to see whether there is a program
138 being debugged it should be nonzero (currently 3 is used) for remote
139 debugging. */
140
39f77062 141ptid_t inferior_ptid;
c906108c
SS
142
143/* Last signal that the inferior received (why it stopped). */
144
145enum target_signal stop_signal;
146
147/* Address at which inferior stopped. */
148
149CORE_ADDR stop_pc;
150
151/* Chain containing status of breakpoint(s) that we have stopped at. */
152
153bpstat stop_bpstat;
154
155/* Flag indicating that a command has proceeded the inferior past the
156 current breakpoint. */
157
158int breakpoint_proceeded;
159
160/* Nonzero if stopped due to a step command. */
161
162int stop_step;
163
164/* Nonzero if stopped due to completion of a stack dummy routine. */
165
166int stop_stack_dummy;
167
168/* Nonzero if stopped due to a random (unexpected) signal in inferior
169 process. */
170
171int stopped_by_random_signal;
172
173/* Range to single step within.
174 If this is nonzero, respond to a single-step signal
175 by continuing to step if the pc is in this range. */
176
c5aa993b
JM
177CORE_ADDR step_range_start; /* Inclusive */
178CORE_ADDR step_range_end; /* Exclusive */
c906108c
SS
179
180/* Stack frame address as of when stepping command was issued.
181 This is how we know when we step into a subroutine call,
182 and how to set the frame for the breakpoint used to step out. */
183
184CORE_ADDR step_frame_address;
185
186/* Our notion of the current stack pointer. */
187
188CORE_ADDR step_sp;
189
5fbbeb29 190enum step_over_calls_kind step_over_calls;
c906108c
SS
191
192/* If stepping, nonzero means step count is > 1
193 so don't print frame next time inferior stops
194 if it stops due to stepping. */
195
196int step_multi;
197
198/* Environment to use for running inferior,
199 in format described in environ.h. */
200
201struct environ *inferior_environ;
c906108c 202\f
07091751
FN
203/* Accessor routines. */
204
205char *
206get_inferior_args (void)
207{
552c04a7
TT
208 if (inferior_argc != 0)
209 {
210 char *n, *old;
211
212 n = gdbarch_construct_inferior_arguments (current_gdbarch,
213 inferior_argc, inferior_argv);
214 old = set_inferior_args (n);
215 xfree (old);
216 }
217
218 if (inferior_args == NULL)
219 inferior_args = xstrdup ("");
220
07091751
FN
221 return inferior_args;
222}
223
224char *
225set_inferior_args (char *newargs)
226{
227 char *saved_args = inferior_args;
228
229 inferior_args = newargs;
552c04a7
TT
230 inferior_argc = 0;
231 inferior_argv = 0;
07091751
FN
232
233 return saved_args;
234}
c5aa993b 235
552c04a7
TT
236void
237set_inferior_args_vector (int argc, char **argv)
238{
239 inferior_argc = argc;
240 inferior_argv = argv;
241}
242
243/* Notice when `set args' is run. */
244static void
245notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
246{
247 inferior_argc = 0;
248 inferior_argv = 0;
249}
250
251/* Notice when `show args' is run. */
252static void
9f60d481 253notice_args_read (char *args, int from_tty, struct cmd_list_element *c)
552c04a7
TT
254{
255 /* Might compute the value. */
256 get_inferior_args ();
257}
258
c2a727fa
TT
259\f
260/* Compute command-line string given argument vector. This does the
261 same shell processing as fork_inferior. */
262/* ARGSUSED */
263char *
264construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
265{
266 char *result;
267
268 if (STARTUP_WITH_SHELL)
269 {
270 /* This holds all the characters considered special to the
271 typical Unix shells. We include `^' because the SunOS
272 /bin/sh treats it as a synonym for `|'. */
273 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
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 += 2 * strlen (argv[i]) + 1;
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 for (cp = argv[i]; *cp; ++cp)
291 {
292 if (strchr (special, *cp) != NULL)
293 *out++ = '\\';
294 *out++ = *cp;
295 }
296 }
297 *out = '\0';
298 }
299 else
300 {
301 /* In this case we can't handle arguments that contain spaces,
302 tabs, or newlines -- see breakup_args(). */
303 int i;
304 int length = 0;
305
306 for (i = 0; i < argc; ++i)
307 {
308 char *cp = strchr (argv[i], ' ');
309 if (cp == NULL)
310 cp = strchr (argv[i], '\t');
311 if (cp == NULL)
312 cp = strchr (argv[i], '\n');
313 if (cp != NULL)
314 error ("can't handle command-line argument containing whitespace");
315 length += strlen (argv[i]) + 1;
316 }
317
318 result = (char *) xmalloc (length);
319 result[0] = '\0';
320 for (i = 0; i < argc; ++i)
321 {
322 if (i > 0)
323 strcat (result, " ");
324 strcat (result, argv[i]);
325 }
326 }
327
328 return result;
329}
552c04a7
TT
330\f
331
43ff13b4
JM
332/* This function detects whether or not a '&' character (indicating
333 background execution) has been added as *the last* of the arguments ARGS
334 of a command. If it has, it removes it and returns 1. Otherwise it
335 does nothing and returns 0. */
c5aa993b 336static int
fba45db2 337strip_bg_char (char **args)
43ff13b4
JM
338{
339 char *p = NULL;
c5aa993b 340
9846de1b 341 p = strchr (*args, '&');
c5aa993b 342
9846de1b 343 if (p)
43ff13b4
JM
344 {
345 if (p == (*args + strlen (*args) - 1))
346 {
c5aa993b 347 if (strlen (*args) > 1)
43ff13b4
JM
348 {
349 do
350 p--;
351 while (*p == ' ' || *p == '\t');
352 *(p + 1) = '\0';
353 }
354 else
355 *args = 0;
356 return 1;
357 }
358 }
359 return 0;
360}
361
c906108c
SS
362/* ARGSUSED */
363void
fba45db2 364tty_command (char *file, int from_tty)
c906108c
SS
365{
366 if (file == 0)
367 error_no_arg ("terminal name for running target process");
368
369 inferior_io_terminal = savestring (file, strlen (file));
370}
371
372static void
fba45db2 373run_command (char *args, int from_tty)
c906108c
SS
374{
375 char *exec_file;
376
377 dont_repeat ();
378
39f77062 379 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
c906108c 380 {
adf40b2e
JM
381 if (from_tty
382 && !query ("The program being debugged has been started already.\n\
c906108c
SS
383Start it from the beginning? "))
384 error ("Program not restarted.");
385 target_kill ();
386#if defined(SOLIB_RESTART)
387 SOLIB_RESTART ();
388#endif
389 init_wait_for_inferior ();
390 }
391
392 clear_breakpoint_hit_counts ();
393
c906108c
SS
394 /* Purge old solib objfiles. */
395 objfile_purge_solibs ();
396
397 do_run_cleanups (NULL);
398
39ad761d
JB
399 /* The comment here used to read, "The exec file is re-read every
400 time we do a generic_mourn_inferior, so we just have to worry
401 about the symbol file." The `generic_mourn_inferior' function
402 gets called whenever the program exits. However, suppose the
403 program exits, and *then* the executable file changes? We need
404 to check again here. Since reopen_exec_file doesn't do anything
405 if the timestamp hasn't changed, I don't see the harm. */
406 reopen_exec_file ();
c906108c
SS
407 reread_symbols ();
408
39ad761d
JB
409 exec_file = (char *) get_exec_file (0);
410
c906108c
SS
411 /* We keep symbols from add-symbol-file, on the grounds that the
412 user might want to add some symbols before running the program
413 (right?). But sometimes (dynamic loading where the user manually
414 introduces the new symbols with add-symbol-file), the code which
415 the symbols describe does not persist between runs. Currently
416 the user has to manually nuke all symbols between runs if they
417 want them to go away (PR 2207). This is probably reasonable. */
418
43ff13b4 419 if (!args)
6426a772
JM
420 {
421 if (event_loop_p && target_can_async_p ())
422 async_disable_stdin ();
423 }
43ff13b4 424 else
c906108c 425 {
43ff13b4
JM
426 int async_exec = strip_bg_char (&args);
427
428 /* If we get a request for running in the bg but the target
429 doesn't support it, error out. */
6426a772 430 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
431 error ("Asynchronous execution not supported on this target.");
432
433 /* If we don't get a request of running in the bg, then we need
c5aa993b 434 to simulate synchronous (fg) execution. */
6426a772 435 if (event_loop_p && !async_exec && target_can_async_p ())
43ff13b4
JM
436 {
437 /* Simulate synchronous execution */
6426a772 438 async_disable_stdin ();
43ff13b4
JM
439 }
440
441 /* If there were other args, beside '&', process them. */
442 if (args)
443 {
07091751
FN
444 char *old_args = set_inferior_args (xstrdup (args));
445 xfree (old_args);
43ff13b4 446 }
c906108c
SS
447 }
448
449 if (from_tty)
450 {
8b93c638
JM
451 ui_out_field_string (uiout, NULL, "Starting program");
452 ui_out_text (uiout, ": ");
453 if (exec_file)
454 ui_out_field_string (uiout, "execfile", exec_file);
455 ui_out_spaces (uiout, 1);
552c04a7
TT
456 /* We call get_inferior_args() because we might need to compute
457 the value now. */
458 ui_out_field_string (uiout, "infargs", get_inferior_args ());
8b93c638
JM
459 ui_out_text (uiout, "\n");
460 ui_out_flush (uiout);
c906108c
SS
461 }
462
552c04a7
TT
463 /* We call get_inferior_args() because we might need to compute
464 the value now. */
465 target_create_inferior (exec_file, get_inferior_args (),
c906108c
SS
466 environ_vector (inferior_environ));
467}
468
469
470static void
fba45db2 471run_no_args_command (char *args, int from_tty)
c906108c 472{
07091751
FN
473 char *old_args = set_inferior_args (xstrdup (""));
474 xfree (old_args);
c906108c 475}
c906108c 476\f
c5aa993b 477
c906108c 478void
fba45db2 479continue_command (char *proc_count_exp, int from_tty)
c906108c 480{
c5aa993b 481 int async_exec = 0;
c906108c
SS
482 ERROR_NO_INFERIOR;
483
43ff13b4
JM
484 /* Find out whether we must run in the background. */
485 if (proc_count_exp != NULL)
486 async_exec = strip_bg_char (&proc_count_exp);
487
488 /* If we must run in the background, but the target can't do it,
489 error out. */
6426a772 490 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
491 error ("Asynchronous execution not supported on this target.");
492
493 /* If we are not asked to run in the bg, then prepare to run in the
494 foreground, synchronously. */
6426a772 495 if (event_loop_p && !async_exec && target_can_async_p ())
c5aa993b 496 {
43ff13b4 497 /* Simulate synchronous execution */
6426a772 498 async_disable_stdin ();
43ff13b4 499 }
c906108c 500
43ff13b4
JM
501 /* If have argument (besides '&'), set proceed count of breakpoint
502 we stopped at. */
c906108c
SS
503 if (proc_count_exp != NULL)
504 {
505 bpstat bs = stop_bpstat;
506 int num = bpstat_num (&bs);
507 if (num == 0 && from_tty)
508 {
509 printf_filtered
510 ("Not stopped at any breakpoint; argument ignored.\n");
511 }
512 while (num != 0)
513 {
514 set_ignore_count (num,
bb518678 515 parse_and_eval_long (proc_count_exp) - 1,
c906108c
SS
516 from_tty);
517 /* set_ignore_count prints a message ending with a period.
518 So print two spaces before "Continuing.". */
519 if (from_tty)
520 printf_filtered (" ");
521 num = bpstat_num (&bs);
522 }
523 }
524
525 if (from_tty)
526 printf_filtered ("Continuing.\n");
527
528 clear_proceed_status ();
529
2acceee2 530 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
c906108c
SS
531}
532\f
533/* Step until outside of current statement. */
534
535/* ARGSUSED */
536static void
fba45db2 537step_command (char *count_string, int from_tty)
c906108c
SS
538{
539 step_1 (0, 0, count_string);
540}
541
542/* Likewise, but skip over subroutine calls as if single instructions. */
543
544/* ARGSUSED */
545static void
fba45db2 546next_command (char *count_string, int from_tty)
c906108c
SS
547{
548 step_1 (1, 0, count_string);
549}
550
551/* Likewise, but step only one instruction. */
552
553/* ARGSUSED */
554void
fba45db2 555stepi_command (char *count_string, int from_tty)
c906108c
SS
556{
557 step_1 (0, 1, count_string);
558}
559
560/* ARGSUSED */
561void
fba45db2 562nexti_command (char *count_string, int from_tty)
c906108c
SS
563{
564 step_1 (1, 1, count_string);
565}
566
74b7792f
AC
567static void
568disable_longjmp_breakpoint_cleanup (void *ignore)
569{
570 disable_longjmp_breakpoint ();
571}
572
c906108c 573static void
fba45db2 574step_1 (int skip_subroutines, int single_inst, char *count_string)
c906108c
SS
575{
576 register int count = 1;
577 struct frame_info *frame;
578 struct cleanup *cleanups = 0;
43ff13b4 579 int async_exec = 0;
c5aa993b 580
c906108c 581 ERROR_NO_INFERIOR;
43ff13b4
JM
582
583 if (count_string)
584 async_exec = strip_bg_char (&count_string);
c5aa993b 585
43ff13b4
JM
586 /* If we get a request for running in the bg but the target
587 doesn't support it, error out. */
6426a772 588 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
589 error ("Asynchronous execution not supported on this target.");
590
591 /* If we don't get a request of running in the bg, then we need
592 to simulate synchronous (fg) execution. */
6426a772 593 if (event_loop_p && !async_exec && target_can_async_p ())
43ff13b4
JM
594 {
595 /* Simulate synchronous execution */
6426a772 596 async_disable_stdin ();
43ff13b4
JM
597 }
598
bb518678 599 count = count_string ? parse_and_eval_long (count_string) : 1;
c906108c 600
c5aa993b 601 if (!single_inst || skip_subroutines) /* leave si command alone */
c906108c 602 {
c5aa993b 603 enable_longjmp_breakpoint ();
c2d11a7d 604 if (!event_loop_p || !target_can_async_p ())
74b7792f 605 cleanups = make_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
c2d11a7d 606 else
74b7792f 607 make_exec_cleanup (disable_longjmp_breakpoint_cleanup, 0 /*ignore*/);
c2d11a7d
JM
608 }
609
610 /* In synchronous case, all is well, just use the regular for loop. */
611 if (!event_loop_p || !target_can_async_p ())
612 {
613 for (; count > 0; count--)
614 {
615 clear_proceed_status ();
616
617 frame = get_current_frame ();
618 if (!frame) /* Avoid coredump here. Why tho? */
619 error ("No current frame");
620 step_frame_address = FRAME_FP (frame);
621 step_sp = read_sp ();
622
623 if (!single_inst)
624 {
625 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
626 if (step_range_end == 0)
627 {
628 char *name;
629 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
630 &step_range_end) == 0)
631 error ("Cannot find bounds of current function");
632
633 target_terminal_ours ();
634 printf_filtered ("\
635Single stepping until exit from function %s, \n\
636which has no line number information.\n", name);
637 }
638 }
639 else
640 {
641 /* Say we are stepping, but stop after one insn whatever it does. */
642 step_range_start = step_range_end = 1;
643 if (!skip_subroutines)
644 /* It is stepi.
645 Don't step over function calls, not even to functions lacking
646 line numbers. */
5fbbeb29 647 step_over_calls = STEP_OVER_NONE;
c2d11a7d
JM
648 }
649
650 if (skip_subroutines)
5fbbeb29 651 step_over_calls = STEP_OVER_ALL;
c2d11a7d
JM
652
653 step_multi = (count > 1);
654 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
655
656 if (!stop_step)
657 break;
658
659 /* FIXME: On nexti, this may have already been done (when we hit the
660 step resume break, I think). Probably this should be moved to
661 wait_for_inferior (near the top). */
662#if defined (SHIFT_INST_REGS)
663 SHIFT_INST_REGS ();
664#endif
665 }
666
667 if (!single_inst || skip_subroutines)
668 do_cleanups (cleanups);
669 return;
670 }
671 /* In case of asynchronous target things get complicated, do only
672 one step for now, before returning control to the event loop. Let
673 the continuation figure out how many other steps we need to do,
674 and handle them one at the time, through step_once(). */
675 else
676 {
677 if (event_loop_p && target_can_async_p ())
678 step_once (skip_subroutines, single_inst, count);
c906108c 679 }
c2d11a7d 680}
c906108c 681
c2d11a7d
JM
682/* Called after we are done with one step operation, to check whether
683 we need to step again, before we print the prompt and return control
684 to the user. If count is > 1, we will need to do one more call to
685 proceed(), via step_once(). Basically it is like step_once and
686 step_1_continuation are co-recursive. */
687static void
fba45db2 688step_1_continuation (struct continuation_arg *arg)
c2d11a7d 689{
57e687d9
MS
690 int count;
691 int skip_subroutines;
692 int single_inst;
693
694 skip_subroutines = arg->data.integer;
695 single_inst = arg->next->data.integer;
696 count = arg->next->next->data.integer;
697
698 if (stop_step)
699 {
700 /* FIXME: On nexti, this may have already been done (when we hit the
701 step resume break, I think). Probably this should be moved to
702 wait_for_inferior (near the top). */
c2d11a7d 703#if defined (SHIFT_INST_REGS)
57e687d9 704 SHIFT_INST_REGS ();
c2d11a7d 705#endif
57e687d9
MS
706 step_once (skip_subroutines, single_inst, count - 1);
707 }
708 else
709 if (!single_inst || skip_subroutines)
710 do_exec_cleanups (ALL_CLEANUPS);
c2d11a7d
JM
711}
712
713/* Do just one step operation. If count >1 we will have to set up a
714 continuation to be done after the target stops (after this one
715 step). This is useful to implement the 'step n' kind of commands, in
716 case of asynchronous targets. We had to split step_1 into two parts,
717 one to be done before proceed() and one afterwards. This function is
718 called in case of step n with n>1, after the first step operation has
719 been completed.*/
720static void
0d06e24b 721step_once (int skip_subroutines, int single_inst, int count)
c2d11a7d 722{
0d06e24b
JM
723 struct continuation_arg *arg1;
724 struct continuation_arg *arg2;
725 struct continuation_arg *arg3;
726 struct frame_info *frame;
c2d11a7d
JM
727
728 if (count > 0)
c906108c
SS
729 {
730 clear_proceed_status ();
731
732 frame = get_current_frame ();
c5aa993b 733 if (!frame) /* Avoid coredump here. Why tho? */
c906108c
SS
734 error ("No current frame");
735 step_frame_address = FRAME_FP (frame);
736 step_sp = read_sp ();
737
c5aa993b 738 if (!single_inst)
c906108c
SS
739 {
740 find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end);
5fbbeb29
CF
741
742 /* If we have no line info, switch to stepi mode. */
743 if (step_range_end == 0 && step_stop_if_no_debug)
744 {
745 step_range_start = step_range_end = 1;
746 }
747 else if (step_range_end == 0)
c906108c
SS
748 {
749 char *name;
750 if (find_pc_partial_function (stop_pc, &name, &step_range_start,
751 &step_range_end) == 0)
752 error ("Cannot find bounds of current function");
753
754 target_terminal_ours ();
755 printf_filtered ("\
756Single stepping until exit from function %s, \n\
757which has no line number information.\n", name);
758 }
759 }
760 else
761 {
762 /* Say we are stepping, but stop after one insn whatever it does. */
763 step_range_start = step_range_end = 1;
764 if (!skip_subroutines)
765 /* It is stepi.
766 Don't step over function calls, not even to functions lacking
767 line numbers. */
5fbbeb29 768 step_over_calls = STEP_OVER_NONE;
c906108c
SS
769 }
770
771 if (skip_subroutines)
5fbbeb29 772 step_over_calls = STEP_OVER_ALL;
c906108c
SS
773
774 step_multi = (count > 1);
c2d11a7d
JM
775 arg1 =
776 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
777 arg2 =
778 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
779 arg3 =
780 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
781 arg1->next = arg2;
57e687d9 782 arg1->data.integer = skip_subroutines;
c2d11a7d 783 arg2->next = arg3;
57e687d9 784 arg2->data.integer = single_inst;
c2d11a7d 785 arg3->next = NULL;
57e687d9 786 arg3->data.integer = count;
c2d11a7d 787 add_intermediate_continuation (step_1_continuation, arg1);
2acceee2 788 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
c906108c 789 }
c906108c 790}
c2d11a7d 791
c906108c
SS
792\f
793/* Continue program at specified address. */
794
795static void
fba45db2 796jump_command (char *arg, int from_tty)
c906108c
SS
797{
798 register CORE_ADDR addr;
799 struct symtabs_and_lines sals;
800 struct symtab_and_line sal;
801 struct symbol *fn;
802 struct symbol *sfn;
43ff13b4 803 int async_exec = 0;
c5aa993b 804
c906108c
SS
805 ERROR_NO_INFERIOR;
806
43ff13b4
JM
807 /* Find out whether we must run in the background. */
808 if (arg != NULL)
809 async_exec = strip_bg_char (&arg);
810
811 /* If we must run in the background, but the target can't do it,
812 error out. */
6426a772 813 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
814 error ("Asynchronous execution not supported on this target.");
815
816 /* If we are not asked to run in the bg, then prepare to run in the
817 foreground, synchronously. */
6426a772 818 if (event_loop_p && !async_exec && target_can_async_p ())
c5aa993b 819 {
43ff13b4 820 /* Simulate synchronous execution */
6426a772 821 async_disable_stdin ();
43ff13b4
JM
822 }
823
c906108c
SS
824 if (!arg)
825 error_no_arg ("starting address");
826
827 sals = decode_line_spec_1 (arg, 1);
828 if (sals.nelts != 1)
829 {
830 error ("Unreasonable jump request");
831 }
832
833 sal = sals.sals[0];
b8c9b27d 834 xfree (sals.sals);
c906108c
SS
835
836 if (sal.symtab == 0 && sal.pc == 0)
837 error ("No source file has been specified.");
838
c5aa993b 839 resolve_sal_pc (&sal); /* May error out */
c906108c
SS
840
841 /* See if we are trying to jump to another function. */
842 fn = get_frame_function (get_current_frame ());
843 sfn = find_pc_function (sal.pc);
844 if (fn != NULL && sfn != fn)
845 {
846 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
847 SYMBOL_SOURCE_NAME (fn)))
848 {
849 error ("Not confirmed.");
850 /* NOTREACHED */
851 }
852 }
853
c5aa993b 854 if (sfn != NULL)
c906108c
SS
855 {
856 fixup_symbol_section (sfn, 0);
c5aa993b 857 if (section_is_overlay (SYMBOL_BFD_SECTION (sfn)) &&
c906108c
SS
858 !section_is_mapped (SYMBOL_BFD_SECTION (sfn)))
859 {
860 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
861 {
862 error ("Not confirmed.");
863 /* NOTREACHED */
864 }
865 }
866 }
867
c906108c
SS
868 addr = sal.pc;
869
870 if (from_tty)
871 {
872 printf_filtered ("Continuing at ");
873 print_address_numeric (addr, 1, gdb_stdout);
874 printf_filtered (".\n");
875 }
876
877 clear_proceed_status ();
878 proceed (addr, TARGET_SIGNAL_0, 0);
879}
c906108c 880\f
c5aa993b 881
c906108c
SS
882/* Go to line or address in current procedure */
883static void
fba45db2 884go_command (char *line_no, int from_tty)
c906108c 885{
c5aa993b 886 if (line_no == (char *) NULL || !*line_no)
b83266a0 887 printf_filtered (GO_USAGE);
c906108c
SS
888 else
889 {
b83266a0
SS
890 tbreak_command (line_no, from_tty);
891 jump_command (line_no, from_tty);
c906108c
SS
892 }
893}
c906108c 894\f
c5aa993b 895
c906108c
SS
896/* Continue program giving it specified signal. */
897
898static void
fba45db2 899signal_command (char *signum_exp, int from_tty)
c906108c
SS
900{
901 enum target_signal oursig;
902
903 dont_repeat (); /* Too dangerous. */
904 ERROR_NO_INFERIOR;
905
906 if (!signum_exp)
907 error_no_arg ("signal number");
908
909 /* It would be even slicker to make signal names be valid expressions,
910 (the type could be "enum $signal" or some such), then the user could
911 assign them to convenience variables. */
912 oursig = target_signal_from_name (signum_exp);
913
914 if (oursig == TARGET_SIGNAL_UNKNOWN)
915 {
916 /* No, try numeric. */
bb518678 917 int num = parse_and_eval_long (signum_exp);
c906108c
SS
918
919 if (num == 0)
920 oursig = TARGET_SIGNAL_0;
921 else
922 oursig = target_signal_from_command (num);
923 }
924
925 if (from_tty)
926 {
927 if (oursig == TARGET_SIGNAL_0)
928 printf_filtered ("Continuing with no signal.\n");
929 else
930 printf_filtered ("Continuing with signal %s.\n",
931 target_signal_to_name (oursig));
932 }
933
934 clear_proceed_status ();
935 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
936 FIXME: Neither should "signal foo" but when I tried passing
937 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
938 tried to track down yet. */
2acceee2 939 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
c906108c
SS
940}
941
942/* Call breakpoint_auto_delete on the current contents of the bpstat
943 pointed to by arg (which is really a bpstat *). */
944
c906108c 945static void
fba45db2 946breakpoint_auto_delete_contents (PTR arg)
c906108c 947{
c5aa993b 948 breakpoint_auto_delete (*(bpstat *) arg);
c906108c
SS
949}
950
c906108c
SS
951
952/* Execute a "stack dummy", a piece of code stored in the stack
953 by the debugger to be executed in the inferior.
954
955 To call: first, do PUSH_DUMMY_FRAME.
956 Then push the contents of the dummy. It should end with a breakpoint insn.
957 Then call here, passing address at which to start the dummy.
958
959 The contents of all registers are saved before the dummy frame is popped
960 and copied into the buffer BUFFER.
961
962 The dummy's frame is automatically popped whenever that break is hit.
963 If that is the first time the program stops, run_stack_dummy
964 returns to its caller with that frame already gone and returns 0.
da59e081
JM
965
966 Otherwise, run_stack-dummy returns a non-zero value.
967 If the called function receives a random signal, we do not allow the user
968 to continue executing it as this may not work. The dummy frame is poped
969 and we return 1.
970 If we hit a breakpoint, we leave the frame in place and return 2 (the frame
971 will eventually be popped when we do hit the dummy end breakpoint). */
c906108c 972
c906108c 973int
fba45db2 974run_stack_dummy (CORE_ADDR addr, char *buffer)
c906108c
SS
975{
976 struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
ed9a39eb 977 int saved_async = 0;
c906108c
SS
978
979 /* Now proceed, having reached the desired place. */
980 clear_proceed_status ();
96baa820 981
7a292a7a
SS
982 if (CALL_DUMMY_BREAKPOINT_OFFSET_P)
983 {
984 struct breakpoint *bpt;
985 struct symtab_and_line sal;
c5aa993b
JM
986
987 INIT_SAL (&sal); /* initialize to zeroes */
7a292a7a
SS
988 if (CALL_DUMMY_LOCATION == AT_ENTRY_POINT)
989 {
990 sal.pc = CALL_DUMMY_ADDRESS ();
991 }
992 else
993 {
994 sal.pc = addr - CALL_DUMMY_START_OFFSET + CALL_DUMMY_BREAKPOINT_OFFSET;
995 }
996 sal.section = find_pc_overlay (sal.pc);
c5aa993b 997
7a292a7a 998 /* Set up a FRAME for the dummy frame so we can pass it to
c5aa993b
JM
999 set_momentary_breakpoint. We need to give the breakpoint a
1000 frame in case there is only one copy of the dummy (e.g.
1001 CALL_DUMMY_LOCATION == AFTER_TEXT_END). */
7a292a7a
SS
1002 flush_cached_frames ();
1003 set_current_frame (create_new_frame (read_fp (), sal.pc));
c5aa993b 1004
7a292a7a 1005 /* If defined, CALL_DUMMY_BREAKPOINT_OFFSET is where we need to put
c5aa993b
JM
1006 a breakpoint instruction. If not, the call dummy already has the
1007 breakpoint instruction in it.
1008
1009 addr is the address of the call dummy plus the CALL_DUMMY_START_OFFSET,
1010 so we need to subtract the CALL_DUMMY_START_OFFSET. */
7a292a7a
SS
1011 bpt = set_momentary_breakpoint (sal,
1012 get_current_frame (),
1013 bp_call_dummy);
b5de0fa7 1014 bpt->disposition = disp_del;
c5aa993b 1015
7a292a7a 1016 /* If all error()s out of proceed ended up calling normal_stop (and
c5aa993b
JM
1017 perhaps they should; it already does in the special case of error
1018 out of resume()), then we wouldn't need this. */
7a292a7a
SS
1019 make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
1020 }
c906108c
SS
1021
1022 disable_watchpoints_before_interactive_call_start ();
1023 proceed_to_finish = 1; /* We want stop_registers, please... */
ed9a39eb
JM
1024
1025 if (target_can_async_p ())
1026 saved_async = target_async_mask (0);
1027
c906108c 1028 proceed (addr, TARGET_SIGNAL_0, 0);
ed9a39eb
JM
1029
1030 if (saved_async)
1031 target_async_mask (saved_async);
1032
c906108c
SS
1033 enable_watchpoints_after_interactive_call_stop ();
1034
1035 discard_cleanups (old_cleanups);
1036
242bfc55 1037 /* We can stop during an inferior call because a signal is received. */
da59e081 1038 if (stopped_by_random_signal)
242bfc55 1039 return 1;
da59e081
JM
1040
1041 /* We may also stop prematurely because we hit a breakpoint in the
242bfc55 1042 called routine. */
c906108c 1043 if (!stop_stack_dummy)
da59e081 1044 return 2;
c906108c 1045
da59e081 1046 /* On normal return, the stack dummy has been popped already. */
c906108c 1047
72cec141
AC
1048 memcpy (buffer, deprecated_grub_regcache_for_registers (stop_registers),
1049 REGISTER_BYTES);
c906108c
SS
1050 return 0;
1051}
1052\f
1053/* Proceed until we reach a different source line with pc greater than
1054 our current one or exit the function. We skip calls in both cases.
1055
1056 Note that eventually this command should probably be changed so
1057 that only source lines are printed out when we hit the breakpoint
1058 we set. This may involve changes to wait_for_inferior and the
1059 proceed status code. */
1060
1061/* ARGSUSED */
1062static void
fba45db2 1063until_next_command (int from_tty)
c906108c
SS
1064{
1065 struct frame_info *frame;
1066 CORE_ADDR pc;
1067 struct symbol *func;
1068 struct symtab_and_line sal;
c5aa993b 1069
c906108c
SS
1070 clear_proceed_status ();
1071
1072 frame = get_current_frame ();
1073
1074 /* Step until either exited from this function or greater
1075 than the current line (if in symbolic section) or pc (if
1076 not). */
1077
1078 pc = read_pc ();
1079 func = find_pc_function (pc);
c5aa993b 1080
c906108c
SS
1081 if (!func)
1082 {
1083 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
c5aa993b 1084
c906108c
SS
1085 if (msymbol == NULL)
1086 error ("Execution is not within a known function.");
c5aa993b 1087
c906108c
SS
1088 step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1089 step_range_end = pc;
1090 }
1091 else
1092 {
1093 sal = find_pc_line (pc, 0);
c5aa993b 1094
c906108c
SS
1095 step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1096 step_range_end = sal.end;
1097 }
c5aa993b 1098
5fbbeb29 1099 step_over_calls = STEP_OVER_ALL;
c906108c
SS
1100 step_frame_address = FRAME_FP (frame);
1101 step_sp = read_sp ();
1102
1103 step_multi = 0; /* Only one call to proceed */
c5aa993b 1104
2acceee2 1105 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
c906108c
SS
1106}
1107
c5aa993b 1108static void
fba45db2 1109until_command (char *arg, int from_tty)
c906108c 1110{
43ff13b4
JM
1111 int async_exec = 0;
1112
c906108c
SS
1113 if (!target_has_execution)
1114 error ("The program is not running.");
43ff13b4
JM
1115
1116 /* Find out whether we must run in the background. */
1117 if (arg != NULL)
1118 async_exec = strip_bg_char (&arg);
1119
1120 /* If we must run in the background, but the target can't do it,
1121 error out. */
6426a772 1122 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
1123 error ("Asynchronous execution not supported on this target.");
1124
1125 /* If we are not asked to run in the bg, then prepare to run in the
1126 foreground, synchronously. */
6426a772 1127 if (event_loop_p && !async_exec && target_can_async_p ())
c5aa993b 1128 {
43ff13b4 1129 /* Simulate synchronous execution */
6426a772 1130 async_disable_stdin ();
43ff13b4
JM
1131 }
1132
c906108c
SS
1133 if (arg)
1134 until_break_command (arg, from_tty);
1135 else
1136 until_next_command (from_tty);
1137}
1138\f
43ff13b4 1139
11cf8741
JM
1140/* Print the result of a function at the end of a 'finish' command. */
1141static void
1142print_return_value (int structure_return, struct type *value_type)
1143{
3d6d86c6 1144 struct value *value;
8b93c638 1145 static struct ui_stream *stb = NULL;
11cf8741
JM
1146
1147 if (!structure_return)
1148 {
72cec141 1149#if 0
11cf8741 1150 value = value_being_returned (value_type, stop_registers, structure_return);
72cec141
AC
1151#else
1152 /* FIXME: cagney/2002-06-22: Function value_being_returned()
1153 should take a regcache as a parameter. */
1154 value = value_being_returned
1155 (value_type, deprecated_grub_regcache_for_registers (stop_registers),
1156 structure_return);
1157#endif
8b93c638
JM
1158 stb = ui_out_stream_new (uiout);
1159 ui_out_text (uiout, "Value returned is ");
1160 ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
9549d9c1 1161 ui_out_text (uiout, " = ");
8b93c638
JM
1162 value_print (value, stb->stream, 0, Val_no_prettyprint);
1163 ui_out_field_stream (uiout, "return-value", stb);
1164 ui_out_text (uiout, "\n");
11cf8741
JM
1165 }
1166 else
1167 {
1168 /* We cannot determine the contents of the structure because
1169 it is on the stack, and we don't know where, since we did not
1170 initiate the call, as opposed to the call_function_by_hand case */
1171#ifdef VALUE_RETURNED_FROM_STACK
1172 value = 0;
8b93c638
JM
1173 ui_out_text (uiout, "Value returned has type: ");
1174 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1175 ui_out_text (uiout, ".");
1176 ui_out_text (uiout, " Cannot determine contents\n");
11cf8741 1177#else
72cec141 1178#if 0
11cf8741 1179 value = value_being_returned (value_type, stop_registers, structure_return);
72cec141
AC
1180#else
1181 /* FIXME: cagney/2002-06-22: Function value_being_returned()
1182 should take a regcache as a parameter. */
1183 value = value_being_returned
1184 (value_type, deprecated_grub_regcache_for_registers (stop_registers),
1185 structure_return);
1186#endif
8b93c638
JM
1187 stb = ui_out_stream_new (uiout);
1188 ui_out_text (uiout, "Value returned is ");
1189 ui_out_field_fmt (uiout, "gdb-result-var", "$%d", record_latest_value (value));
28ae27b1 1190 ui_out_text (uiout, " = ");
8b93c638
JM
1191 value_print (value, stb->stream, 0, Val_no_prettyprint);
1192 ui_out_field_stream (uiout, "return-value", stb);
1193 ui_out_text (uiout, "\n");
11cf8741
JM
1194#endif
1195 }
1196}
1197
43ff13b4
JM
1198/* Stuff that needs to be done by the finish command after the target
1199 has stopped. In asynchronous mode, we wait for the target to stop in
1200 the call to poll or select in the event loop, so it is impossible to
1201 do all the stuff as part of the finish_command function itself. The
1202 only chance we have to complete this command is in
1203 fetch_inferior_event, which is called by the event loop as soon as it
1204 detects that the target has stopped. This function is called via the
6953f3ba 1205 cmd_continuation pointer. */
43ff13b4 1206void
fba45db2 1207finish_command_continuation (struct continuation_arg *arg)
43ff13b4
JM
1208{
1209 register struct symbol *function;
1210 struct breakpoint *breakpoint;
0d06e24b 1211 struct cleanup *cleanups;
c5aa993b 1212
57e687d9
MS
1213 breakpoint = (struct breakpoint *) arg->data.pointer;
1214 function = (struct symbol *) arg->next->data.pointer;
1215 cleanups = (struct cleanup *) arg->next->next->data.pointer;
43ff13b4 1216
c5aa993b 1217 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
43ff13b4
JM
1218 && function != 0)
1219 {
1220 struct type *value_type;
43ff13b4
JM
1221 CORE_ADDR funcaddr;
1222 int struct_return;
1223
1224 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1225 if (!value_type)
8e65ff28
AC
1226 internal_error (__FILE__, __LINE__,
1227 "finish_command: function has no target type");
c5aa993b 1228
43ff13b4
JM
1229 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1230 {
0d06e24b 1231 do_exec_cleanups (cleanups);
43ff13b4
JM
1232 return;
1233 }
1234
1235 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
1236
1237 struct_return = using_struct_return (value_of_variable (function, NULL),
c5aa993b
JM
1238 funcaddr,
1239 check_typedef (value_type),
11cf8741 1240 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
43ff13b4 1241
11cf8741 1242 print_return_value (struct_return, value_type);
43ff13b4 1243 }
0d06e24b 1244 do_exec_cleanups (cleanups);
43ff13b4
JM
1245}
1246
c906108c
SS
1247/* "finish": Set a temporary breakpoint at the place
1248 the selected frame will return to, then continue. */
1249
1250static void
fba45db2 1251finish_command (char *arg, int from_tty)
c906108c
SS
1252{
1253 struct symtab_and_line sal;
1254 register struct frame_info *frame;
1255 register struct symbol *function;
1256 struct breakpoint *breakpoint;
1257 struct cleanup *old_chain;
0d06e24b 1258 struct continuation_arg *arg1, *arg2, *arg3;
43ff13b4
JM
1259
1260 int async_exec = 0;
1261
1262 /* Find out whether we must run in the background. */
1263 if (arg != NULL)
1264 async_exec = strip_bg_char (&arg);
1265
1266 /* If we must run in the background, but the target can't do it,
1267 error out. */
6426a772 1268 if (event_loop_p && async_exec && !target_can_async_p ())
43ff13b4
JM
1269 error ("Asynchronous execution not supported on this target.");
1270
1271 /* If we are not asked to run in the bg, then prepare to run in the
1272 foreground, synchronously. */
6426a772 1273 if (event_loop_p && !async_exec && target_can_async_p ())
c5aa993b 1274 {
43ff13b4 1275 /* Simulate synchronous execution */
6426a772 1276 async_disable_stdin ();
43ff13b4 1277 }
c906108c
SS
1278
1279 if (arg)
1280 error ("The \"finish\" command does not take any arguments.");
1281 if (!target_has_execution)
1282 error ("The program is not running.");
1283 if (selected_frame == NULL)
1284 error ("No selected frame.");
1285
1286 frame = get_prev_frame (selected_frame);
1287 if (frame == 0)
1288 error ("\"finish\" not meaningful in the outermost frame.");
1289
1290 clear_proceed_status ();
1291
1292 sal = find_pc_line (frame->pc, 0);
1293 sal.pc = frame->pc;
1294
1295 breakpoint = set_momentary_breakpoint (sal, frame, bp_finish);
1296
6426a772 1297 if (!event_loop_p || !target_can_async_p ())
4d6140d9 1298 old_chain = make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 1299 else
4d6140d9 1300 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
c906108c
SS
1301
1302 /* Find the function we will return from. */
1303
1304 function = find_pc_function (selected_frame->pc);
1305
1306 /* Print info on the selected frame, including level number
1307 but not source. */
1308 if (from_tty)
1309 {
1310 printf_filtered ("Run till exit from ");
b31da25e
AC
1311 print_stack_frame (selected_frame,
1312 frame_relative_level (selected_frame), 0);
c906108c
SS
1313 }
1314
43ff13b4
JM
1315 /* If running asynchronously and the target support asynchronous
1316 execution, set things up for the rest of the finish command to be
1317 completed later on, when gdb has detected that the target has
1318 stopped, in fetch_inferior_event. */
6426a772 1319 if (event_loop_p && target_can_async_p ())
43ff13b4 1320 {
c5aa993b 1321 arg1 =
43ff13b4 1322 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
c5aa993b 1323 arg2 =
43ff13b4 1324 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
0d06e24b
JM
1325 arg3 =
1326 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
43ff13b4 1327 arg1->next = arg2;
0d06e24b
JM
1328 arg2->next = arg3;
1329 arg3->next = NULL;
57e687d9
MS
1330 arg1->data.pointer = breakpoint;
1331 arg2->data.pointer = function;
1332 arg3->data.pointer = old_chain;
43ff13b4
JM
1333 add_continuation (finish_command_continuation, arg1);
1334 }
1335
c5aa993b 1336 proceed_to_finish = 1; /* We want stop_registers, please... */
2acceee2 1337 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
c906108c 1338
43ff13b4
JM
1339 /* Do this only if not running asynchronously or if the target
1340 cannot do async execution. Otherwise, complete this command when
c5aa993b 1341 the target actually stops, in fetch_inferior_event. */
6426a772 1342 if (!event_loop_p || !target_can_async_p ())
c5aa993b
JM
1343 {
1344
1345 /* Did we stop at our breakpoint? */
1346 if (bpstat_find_breakpoint (stop_bpstat, breakpoint) != NULL
1347 && function != 0)
1348 {
1349 struct type *value_type;
c5aa993b
JM
1350 CORE_ADDR funcaddr;
1351 int struct_return;
1352
1353 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function));
1354 if (!value_type)
8e65ff28
AC
1355 internal_error (__FILE__, __LINE__,
1356 "finish_command: function has no target type");
c5aa993b
JM
1357
1358 /* FIXME: Shouldn't we do the cleanups before returning? */
1359 if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
1360 return;
1361
1362 funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function));
1363
1364 struct_return =
1365 using_struct_return (value_of_variable (function, NULL),
1366 funcaddr,
1367 check_typedef (value_type),
1368 BLOCK_GCC_COMPILED (SYMBOL_BLOCK_VALUE (function)));
1369
11cf8741 1370 print_return_value (struct_return, value_type);
c5aa993b
JM
1371 }
1372 do_cleanups (old_chain);
1373 }
c906108c
SS
1374}
1375\f
1376/* ARGSUSED */
1377static void
fba45db2 1378program_info (char *args, int from_tty)
c906108c
SS
1379{
1380 bpstat bs = stop_bpstat;
1381 int num = bpstat_num (&bs);
c5aa993b 1382
c906108c
SS
1383 if (!target_has_execution)
1384 {
1385 printf_filtered ("The program being debugged is not being run.\n");
1386 return;
1387 }
1388
1389 target_files_info ();
1390 printf_filtered ("Program stopped at %s.\n",
c5aa993b 1391 local_hex_string ((unsigned long) stop_pc));
c906108c
SS
1392 if (stop_step)
1393 printf_filtered ("It stopped after being stepped.\n");
1394 else if (num != 0)
1395 {
1396 /* There may be several breakpoints in the same place, so this
c5aa993b 1397 isn't as strange as it seems. */
c906108c
SS
1398 while (num != 0)
1399 {
1400 if (num < 0)
1401 {
1402 printf_filtered ("It stopped at a breakpoint that has ");
1403 printf_filtered ("since been deleted.\n");
1404 }
1405 else
1406 printf_filtered ("It stopped at breakpoint %d.\n", num);
1407 num = bpstat_num (&bs);
1408 }
1409 }
1410 else if (stop_signal != TARGET_SIGNAL_0)
1411 {
1412 printf_filtered ("It stopped with signal %s, %s.\n",
1413 target_signal_to_name (stop_signal),
1414 target_signal_to_string (stop_signal));
1415 }
1416
1417 if (!from_tty)
1418 {
1419 printf_filtered ("Type \"info stack\" or \"info registers\" ");
1420 printf_filtered ("for more information.\n");
1421 }
1422}
1423\f
1424static void
fba45db2 1425environment_info (char *var, int from_tty)
c906108c
SS
1426{
1427 if (var)
1428 {
1429 register char *val = get_in_environ (inferior_environ, var);
1430 if (val)
1431 {
1432 puts_filtered (var);
1433 puts_filtered (" = ");
1434 puts_filtered (val);
1435 puts_filtered ("\n");
1436 }
1437 else
1438 {
1439 puts_filtered ("Environment variable \"");
1440 puts_filtered (var);
1441 puts_filtered ("\" not defined.\n");
1442 }
1443 }
1444 else
1445 {
1446 register char **vector = environ_vector (inferior_environ);
1447 while (*vector)
1448 {
1449 puts_filtered (*vector++);
1450 puts_filtered ("\n");
1451 }
1452 }
1453}
1454
1455static void
fba45db2 1456set_environment_command (char *arg, int from_tty)
c906108c
SS
1457{
1458 register char *p, *val, *var;
1459 int nullset = 0;
1460
1461 if (arg == 0)
1462 error_no_arg ("environment variable and value");
1463
1464 /* Find seperation between variable name and value */
1465 p = (char *) strchr (arg, '=');
1466 val = (char *) strchr (arg, ' ');
1467
1468 if (p != 0 && val != 0)
1469 {
1470 /* We have both a space and an equals. If the space is before the
c5aa993b
JM
1471 equals, walk forward over the spaces til we see a nonspace
1472 (possibly the equals). */
c906108c
SS
1473 if (p > val)
1474 while (*val == ' ')
1475 val++;
1476
1477 /* Now if the = is after the char following the spaces,
c5aa993b 1478 take the char following the spaces. */
c906108c
SS
1479 if (p > val)
1480 p = val - 1;
1481 }
1482 else if (val != 0 && p == 0)
1483 p = val;
1484
1485 if (p == arg)
1486 error_no_arg ("environment variable to set");
1487
1488 if (p == 0 || p[1] == 0)
1489 {
1490 nullset = 1;
1491 if (p == 0)
1492 p = arg + strlen (arg); /* So that savestring below will work */
1493 }
1494 else
1495 {
1496 /* Not setting variable value to null */
1497 val = p + 1;
1498 while (*val == ' ' || *val == '\t')
1499 val++;
1500 }
1501
c5aa993b
JM
1502 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1503 p--;
c906108c
SS
1504
1505 var = savestring (arg, p - arg);
1506 if (nullset)
1507 {
1508 printf_filtered ("Setting environment variable ");
1509 printf_filtered ("\"%s\" to null value.\n", var);
1510 set_in_environ (inferior_environ, var, "");
1511 }
1512 else
1513 set_in_environ (inferior_environ, var, val);
b8c9b27d 1514 xfree (var);
c906108c
SS
1515}
1516
1517static void
fba45db2 1518unset_environment_command (char *var, int from_tty)
c906108c
SS
1519{
1520 if (var == 0)
1521 {
1522 /* If there is no argument, delete all environment variables.
c5aa993b 1523 Ask for confirmation if reading from the terminal. */
c906108c
SS
1524 if (!from_tty || query ("Delete all environment variables? "))
1525 {
1526 free_environ (inferior_environ);
1527 inferior_environ = make_environ ();
1528 }
1529 }
1530 else
1531 unset_in_environ (inferior_environ, var);
1532}
1533
1534/* Handle the execution path (PATH variable) */
1535
1536static const char path_var_name[] = "PATH";
1537
1538/* ARGSUSED */
1539static void
fba45db2 1540path_info (char *args, int from_tty)
c906108c
SS
1541{
1542 puts_filtered ("Executable and object file path: ");
1543 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1544 puts_filtered ("\n");
1545}
1546
1547/* Add zero or more directories to the front of the execution path. */
1548
1549static void
fba45db2 1550path_command (char *dirname, int from_tty)
c906108c
SS
1551{
1552 char *exec_path;
1553 char *env;
1554 dont_repeat ();
1555 env = get_in_environ (inferior_environ, path_var_name);
1556 /* Can be null if path is not set */
1557 if (!env)
1558 env = "";
4fcf66da 1559 exec_path = xstrdup (env);
c906108c
SS
1560 mod_path (dirname, &exec_path);
1561 set_in_environ (inferior_environ, path_var_name, exec_path);
b8c9b27d 1562 xfree (exec_path);
c906108c 1563 if (from_tty)
c5aa993b 1564 path_info ((char *) NULL, from_tty);
c906108c 1565}
c906108c 1566\f
c5aa993b 1567
c906108c
SS
1568#ifdef REGISTER_NAMES
1569char *gdb_register_names[] = REGISTER_NAMES;
1570#endif
1571/* Print out the machine register regnum. If regnum is -1,
1572 print all registers (fpregs == 1) or all non-float registers
1573 (fpregs == 0).
1574
1575 For most machines, having all_registers_info() print the
1576 register(s) one per line is good enough. If a different format
1577 is required, (eg, for MIPS or Pyramid 90x, which both have
1578 lots of regs), or there is an existing convention for showing
1579 all the registers, define the macro DO_REGISTERS_INFO(regnum, fp)
c5aa993b 1580 to provide that format. */
c906108c 1581
666e11c5 1582void
fba45db2 1583do_registers_info (int regnum, int fpregs)
c906108c
SS
1584{
1585 register int i;
64485362 1586 int numregs = NUM_REGS + NUM_PSEUDO_REGS;
b8adfa9f
MS
1587 char *raw_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
1588 char *virtual_buffer = (char*) alloca (MAX_REGISTER_VIRTUAL_SIZE);
c906108c
SS
1589
1590 for (i = 0; i < numregs; i++)
1591 {
c906108c 1592 /* Decide between printing all regs, nonfloat regs, or specific reg. */
c5aa993b
JM
1593 if (regnum == -1)
1594 {
1595 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT && !fpregs)
1596 continue;
1597 }
1598 else
1599 {
1600 if (i != regnum)
1601 continue;
1602 }
c906108c
SS
1603
1604 /* If the register name is empty, it is undefined for this
c5aa993b 1605 processor, so don't display anything. */
c906108c
SS
1606 if (REGISTER_NAME (i) == NULL || *(REGISTER_NAME (i)) == '\0')
1607 continue;
1608
1609 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
1610 print_spaces_filtered (15 - strlen (REGISTER_NAME (i)), gdb_stdout);
1611
1612 /* Get the data in raw format. */
cda5a58a 1613 if (! frame_register_read (selected_frame, i, raw_buffer))
c906108c
SS
1614 {
1615 printf_filtered ("*value not available*\n");
1616 continue;
1617 }
1618
1619 /* Convert raw data to virtual format if necessary. */
c906108c
SS
1620 if (REGISTER_CONVERTIBLE (i))
1621 {
1622 REGISTER_CONVERT_TO_VIRTUAL (i, REGISTER_VIRTUAL_TYPE (i),
1623 raw_buffer, virtual_buffer);
1624 }
1625 else
392a587b
JM
1626 {
1627 memcpy (virtual_buffer, raw_buffer,
1628 REGISTER_VIRTUAL_SIZE (i));
1629 }
c906108c
SS
1630
1631 /* If virtual format is floating, print it that way, and in raw hex. */
1632 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT)
1633 {
1634 register int j;
1635
75bc7ddf
AC
1636 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1637 gdb_stdout, 0, 1, 0, Val_pretty_default);
c906108c
SS
1638
1639 printf_filtered ("\t(raw 0x");
1640 for (j = 0; j < REGISTER_RAW_SIZE (i); j++)
1641 {
d7449b42 1642 register int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
c5aa993b
JM
1643 : REGISTER_RAW_SIZE (i) - 1 - j;
1644 printf_filtered ("%02x", (unsigned char) raw_buffer[idx]);
c906108c
SS
1645 }
1646 printf_filtered (")");
1647 }
c906108c
SS
1648 /* Else print as integer in hex and in decimal. */
1649 else
1650 {
1651 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
1652 gdb_stdout, 'x', 1, 0, Val_pretty_default);
1653 printf_filtered ("\t");
1654 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0,
c5aa993b 1655 gdb_stdout, 0, 1, 0, Val_pretty_default);
c906108c
SS
1656 }
1657
1658 /* The SPARC wants to print even-numbered float regs as doubles
c5aa993b 1659 in addition to printing them as floats. */
c906108c
SS
1660#ifdef PRINT_REGISTER_HOOK
1661 PRINT_REGISTER_HOOK (i);
1662#endif
1663
1664 printf_filtered ("\n");
1665 }
1666}
c906108c 1667
c906108c 1668void
fba45db2 1669registers_info (char *addr_exp, int fpregs)
c906108c
SS
1670{
1671 int regnum, numregs;
1672 register char *end;
1673
1674 if (!target_has_registers)
1675 error ("The program has no registers now.");
1676 if (selected_frame == NULL)
1677 error ("No selected frame.");
1678
1679 if (!addr_exp)
1680 {
c5aa993b 1681 DO_REGISTERS_INFO (-1, fpregs);
c906108c
SS
1682 return;
1683 }
1684
1685 do
c5aa993b 1686 {
c906108c
SS
1687 if (addr_exp[0] == '$')
1688 addr_exp++;
1689 end = addr_exp;
1690 while (*end != '\0' && *end != ' ' && *end != '\t')
1691 ++end;
64485362 1692 numregs = NUM_REGS + NUM_PSEUDO_REGS;
c906108c
SS
1693
1694 regnum = target_map_name_to_register (addr_exp, end - addr_exp);
c5aa993b 1695 if (regnum >= 0)
c906108c
SS
1696 goto found;
1697
1698 regnum = numregs;
1699
1700 if (*addr_exp >= '0' && *addr_exp <= '9')
c5aa993b
JM
1701 regnum = atoi (addr_exp); /* Take a number */
1702 if (regnum >= numregs) /* Bad name, or bad number */
baa6f10b 1703 error ("%.*s: invalid register", (int) (end - addr_exp), addr_exp);
c906108c 1704
c5aa993b
JM
1705 found:
1706 DO_REGISTERS_INFO (regnum, fpregs);
c906108c
SS
1707
1708 addr_exp = end;
1709 while (*addr_exp == ' ' || *addr_exp == '\t')
1710 ++addr_exp;
c5aa993b
JM
1711 }
1712 while (*addr_exp != '\0');
c906108c
SS
1713}
1714
1715void
fba45db2 1716all_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1717{
1718 registers_info (addr_exp, 1);
1719}
1720
1721void
fba45db2 1722nofp_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1723{
1724 registers_info (addr_exp, 0);
1725}
c906108c 1726\f
c5aa993b 1727
c906108c
SS
1728/*
1729 * TODO:
1730 * Should save/restore the tty state since it might be that the
1731 * program to be debugged was started on this tty and it wants
1732 * the tty in some state other than what we want. If it's running
1733 * on another terminal or without a terminal, then saving and
1734 * restoring the tty state is a harmless no-op.
1735 * This only needs to be done if we are attaching to a process.
1736 */
1737
1738/*
1739 attach_command --
1740 takes a program started up outside of gdb and ``attaches'' to it.
1741 This stops it cold in its tracks and allows us to start debugging it.
1742 and wait for the trace-trap that results from attaching. */
1743
1744void
fba45db2 1745attach_command (char *args, int from_tty)
c906108c 1746{
c5aa993b
JM
1747 char *exec_file;
1748 char *full_exec_path = NULL;
c906108c 1749
c5aa993b 1750 dont_repeat (); /* Not for the faint of heart */
c906108c
SS
1751
1752 if (target_has_execution)
1753 {
1754 if (query ("A program is being debugged already. Kill it? "))
1755 target_kill ();
1756 else
1757 error ("Not killed.");
1758 }
1759
1760 target_attach (args, from_tty);
1761
1762 /* Set up the "saved terminal modes" of the inferior
1763 based on what modes we are starting it with. */
1764 target_terminal_init ();
1765
1766 /* Install inferior's terminal modes. */
1767 target_terminal_inferior ();
1768
1769 /* Set up execution context to know that we should return from
1770 wait_for_inferior as soon as the target reports a stop. */
1771 init_wait_for_inferior ();
1772 clear_proceed_status ();
c906108c
SS
1773
1774 /* No traps are generated when attaching to inferior under Mach 3
1775 or GNU hurd. */
1776#ifndef ATTACH_NO_WAIT
00373e55 1777 stop_soon_quietly = 1;
c906108c
SS
1778 wait_for_inferior ();
1779#endif
1780
1781 /*
1782 * If no exec file is yet known, try to determine it from the
1783 * process itself.
1784 */
1785 exec_file = (char *) get_exec_file (0);
c5aa993b
JM
1786 if (!exec_file)
1787 {
39f77062 1788 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
c5aa993b
JM
1789 if (exec_file)
1790 {
1791 /* It's possible we don't have a full path, but rather just a
1792 filename. Some targets, such as HP-UX, don't provide the
1793 full path, sigh.
1794
1795 Attempt to qualify the filename against the source path.
1796 (If that fails, we'll just fall back on the original
1797 filename. Not much more we can do...)
1798 */
1799 if (!source_full_path_of (exec_file, &full_exec_path))
1800 full_exec_path = savestring (exec_file, strlen (exec_file));
1801
1802 exec_file_attach (full_exec_path, from_tty);
1adeb98a 1803 symbol_file_add_main (full_exec_path, from_tty);
c5aa993b 1804 }
c906108c 1805 }
c906108c
SS
1806
1807#ifdef SOLIB_ADD
990f9fe3
FF
1808 /* Add shared library symbols from the newly attached process, if any. */
1809 SOLIB_ADD ((char *) 0, from_tty, &current_target, auto_solib_add);
1810 re_enable_breakpoints_in_shlibs ();
c906108c
SS
1811#endif
1812
1813 /* Take any necessary post-attaching actions for this platform.
c5aa993b 1814 */
39f77062 1815 target_post_attach (PIDGET (inferior_ptid));
c906108c
SS
1816
1817 normal_stop ();
6426a772
JM
1818
1819 if (attach_hook)
1820 attach_hook ();
c906108c
SS
1821}
1822
1823/*
1824 * detach_command --
1825 * takes a program previously attached to and detaches it.
1826 * The program resumes execution and will no longer stop
1827 * on signals, etc. We better not have left any breakpoints
1828 * in the program or it'll die when it hits one. For this
1829 * to work, it may be necessary for the process to have been
1830 * previously attached. It *might* work if the program was
1831 * started via the normal ptrace (PTRACE_TRACEME).
1832 */
1833
1834static void
fba45db2 1835detach_command (char *args, int from_tty)
c906108c 1836{
c5aa993b 1837 dont_repeat (); /* Not for the faint of heart */
c906108c
SS
1838 target_detach (args, from_tty);
1839#if defined(SOLIB_RESTART)
1840 SOLIB_RESTART ();
1841#endif
6426a772
JM
1842 if (detach_hook)
1843 detach_hook ();
c906108c
SS
1844}
1845
43ff13b4
JM
1846/* Stop the execution of the target while running in async mode, in
1847 the backgound. */
8926118c 1848
8b93c638 1849void
fba45db2 1850interrupt_target_command_wrapper (char *args, int from_tty)
8b93c638
JM
1851{
1852 interrupt_target_command (args, from_tty);
1853}
8926118c 1854
43ff13b4 1855static void
fba45db2 1856interrupt_target_command (char *args, int from_tty)
43ff13b4 1857{
6426a772 1858 if (event_loop_p && target_can_async_p ())
43ff13b4 1859 {
c5aa993b 1860 dont_repeat (); /* Not for the faint of heart */
43ff13b4
JM
1861 target_stop ();
1862 }
1863}
1864
c906108c
SS
1865/* ARGSUSED */
1866static void
fba45db2 1867float_info (char *addr_exp, int from_tty)
c906108c 1868{
d855c300 1869 gdbarch_print_float_info (current_gdbarch, gdb_stdout, selected_frame);
c906108c
SS
1870}
1871\f
1872/* ARGSUSED */
1873static void
fba45db2 1874unset_command (char *args, int from_tty)
c906108c
SS
1875{
1876 printf_filtered ("\"unset\" must be followed by the name of ");
1877 printf_filtered ("an unset subcommand.\n");
1878 help_list (unsetlist, "unset ", -1, gdb_stdout);
1879}
1880
1881void
fba45db2 1882_initialize_infcmd (void)
c906108c
SS
1883{
1884 struct cmd_list_element *c;
c5aa993b 1885
c94fdfd0
EZ
1886 c = add_com ("tty", class_run, tty_command,
1887 "Set terminal for future runs of program being debugged.");
5ba2abeb 1888 set_cmd_completer (c, filename_completer);
c906108c 1889
fa58ee11
EZ
1890 c = add_set_cmd ("args", class_run, var_string_noescape,
1891 (char *) &inferior_args,
1892 "Set argument list to give program being debugged when it is started.\n\
c906108c 1893Follow this command with any number of args, to be passed to the program.",
fa58ee11 1894 &setlist);
5ba2abeb 1895 set_cmd_completer (c, filename_completer);
9f60d481 1896 set_cmd_sfunc (c, notice_args_set);
552c04a7 1897 c = add_show_from_set (c, &showlist);
9f60d481 1898 set_cmd_sfunc (c, notice_args_read);
c906108c
SS
1899
1900 c = add_cmd
1901 ("environment", no_class, environment_info,
1902 "The environment to give the program, or one variable's value.\n\
1903With an argument VAR, prints the value of environment variable VAR to\n\
1904give the program being debugged. With no arguments, prints the entire\n\
1905environment to be given to the program.", &showlist);
5ba2abeb 1906 set_cmd_completer (c, noop_completer);
c906108c
SS
1907
1908 add_prefix_cmd ("unset", no_class, unset_command,
d4654627 1909 "Complement to certain \"set\" commands.",
c906108c 1910 &unsetlist, "unset ", 0, &cmdlist);
c5aa993b 1911
c906108c 1912 c = add_cmd ("environment", class_run, unset_environment_command,
c5aa993b 1913 "Cancel environment variable VAR for the program.\n\
c906108c 1914This does not affect the program until the next \"run\" command.",
c5aa993b 1915 &unsetlist);
5ba2abeb 1916 set_cmd_completer (c, noop_completer);
c906108c
SS
1917
1918 c = add_cmd ("environment", class_run, set_environment_command,
1919 "Set environment variable value to give the program.\n\
1920Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
1921VALUES of environment variables are uninterpreted strings.\n\
1922This does not affect the program until the next \"run\" command.",
c5aa993b 1923 &setlist);
5ba2abeb 1924 set_cmd_completer (c, noop_completer);
c5aa993b 1925
fa58ee11
EZ
1926 c = add_com ("path", class_files, path_command,
1927 "Add directory DIR(s) to beginning of search path for object files.\n\
c906108c
SS
1928$cwd in the path means the current working directory.\n\
1929This path is equivalent to the $PATH shell variable. It is a list of\n\
1930directories, separated by colons. These directories are searched to find\n\
1931fully linked executable files and separately compiled object files as needed.");
5ba2abeb 1932 set_cmd_completer (c, filename_completer);
c906108c
SS
1933
1934 c = add_cmd ("paths", no_class, path_info,
c5aa993b 1935 "Current search path for finding object files.\n\
c906108c
SS
1936$cwd in the path means the current working directory.\n\
1937This path is equivalent to the $PATH shell variable. It is a list of\n\
1938directories, separated by colons. These directories are searched to find\n\
1939fully linked executable files and separately compiled object files as needed.",
1940 &showlist);
5ba2abeb 1941 set_cmd_completer (c, noop_completer);
c906108c 1942
c5aa993b
JM
1943 add_com ("attach", class_run, attach_command,
1944 "Attach to a process or file outside of GDB.\n\
c906108c
SS
1945This command attaches to another target, of the same type as your last\n\
1946\"target\" command (\"info files\" will show your target stack).\n\
1947The command may take as argument a process id or a device file.\n\
1948For a process id, you must have permission to send the process a signal,\n\
1949and it must have the same effective uid as the debugger.\n\
1950When using \"attach\" with a process id, the debugger finds the\n\
1951program running in the process, looking first in the current working\n\
1952directory, or (if not found there) using the source file search path\n\
1953(see the \"directory\" command). You can also use the \"file\" command\n\
1954to specify the program, and to load its symbol table.");
1955
1956 add_com ("detach", class_run, detach_command,
1957 "Detach a process or file previously attached.\n\
1958If a process, it is no longer traced, and it continues its execution. If\n\
1959you were debugging a file, the file is closed and gdb no longer accesses it.");
1960
1961 add_com ("signal", class_run, signal_command,
1962 "Continue program giving it signal specified by the argument.\n\
1963An argument of \"0\" means continue program without giving it a signal.");
1964
1965 add_com ("stepi", class_run, stepi_command,
1966 "Step one instruction exactly.\n\
1967Argument N means do this N times (or till program stops for another reason).");
1968 add_com_alias ("si", "stepi", class_alias, 0);
1969
1970 add_com ("nexti", class_run, nexti_command,
1971 "Step one instruction, but proceed through subroutine calls.\n\
1972Argument N means do this N times (or till program stops for another reason).");
1973 add_com_alias ("ni", "nexti", class_alias, 0);
1974
1975 add_com ("finish", class_run, finish_command,
1976 "Execute until selected stack frame returns.\n\
1977Upon return, the value returned is printed and put in the value history.");
1978
1979 add_com ("next", class_run, next_command,
1980 "Step program, proceeding through subroutine calls.\n\
1981Like the \"step\" command as long as subroutine calls do not happen;\n\
1982when they do, the call is treated as one instruction.\n\
1983Argument N means do this N times (or till program stops for another reason).");
1984 add_com_alias ("n", "next", class_run, 1);
1985 if (xdb_commands)
c5aa993b 1986 add_com_alias ("S", "next", class_run, 1);
c906108c
SS
1987
1988 add_com ("step", class_run, step_command,
1989 "Step program until it reaches a different source line.\n\
1990Argument N means do this N times (or till program stops for another reason).");
1991 add_com_alias ("s", "step", class_run, 1);
1992
c94fdfd0
EZ
1993 c = add_com ("until", class_run, until_command,
1994 "Execute until the program reaches a source line greater than the current\n\
c906108c
SS
1995or a specified line or address or function (same args as break command).\n\
1996Execution will also stop upon exit from the current stack frame.");
5ba2abeb 1997 set_cmd_completer (c, location_completer);
c906108c 1998 add_com_alias ("u", "until", class_run, 1);
c5aa993b 1999
c94fdfd0
EZ
2000 c = add_com ("jump", class_run, jump_command,
2001 "Continue program being debugged at specified line or address.\n\
c906108c
SS
2002Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
2003for an address to start at.");
5ba2abeb 2004 set_cmd_completer (c, location_completer);
c906108c 2005
b83266a0 2006 if (xdb_commands)
c94fdfd0
EZ
2007 {
2008 c = add_com ("go", class_run, go_command,
2009 "Usage: go <location>\n\
c906108c
SS
2010Continue program being debugged, stopping at specified line or \n\
2011address.\n\
2012Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2013expression for an address to start at.\n\
2014This command is a combination of tbreak and jump.");
5ba2abeb 2015 set_cmd_completer (c, location_completer);
c94fdfd0 2016 }
b83266a0 2017
c906108c 2018 if (xdb_commands)
c5aa993b 2019 add_com_alias ("g", "go", class_run, 1);
c906108c
SS
2020
2021 add_com ("continue", class_run, continue_command,
2022 "Continue program being debugged, after signal or breakpoint.\n\
2023If proceeding from breakpoint, a number N may be used as an argument,\n\
2024which means to set the ignore count of that breakpoint to N - 1 (so that\n\
2025the breakpoint won't break until the Nth time it is reached).");
2026 add_com_alias ("c", "cont", class_run, 1);
2027 add_com_alias ("fg", "cont", class_run, 1);
2028
fa58ee11 2029 c = add_com ("run", class_run, run_command,
c906108c
SS
2030 "Start debugged program. You may specify arguments to give it.\n\
2031Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2032Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2033With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2034To cancel previous arguments and run with no arguments,\n\
2035use \"set args\" without arguments.");
5ba2abeb 2036 set_cmd_completer (c, filename_completer);
c906108c
SS
2037 add_com_alias ("r", "run", class_run, 1);
2038 if (xdb_commands)
2039 add_com ("R", class_run, run_no_args_command,
c5aa993b 2040 "Start debugged program with no arguments.");
c906108c 2041
43ff13b4
JM
2042 add_com ("interrupt", class_run, interrupt_target_command,
2043 "Interrupt the execution of the debugged program.");
2044
c906108c 2045 add_info ("registers", nofp_registers_info,
c5aa993b 2046 "List of integer registers and their contents, for selected stack frame.\n\
c906108c 2047Register name as argument means describe only that register.");
7194c49b 2048 add_info_alias ("r", "registers", 1);
c906108c
SS
2049
2050 if (xdb_commands)
c5aa993b
JM
2051 add_com ("lr", class_info, nofp_registers_info,
2052 "List of integer registers and their contents, for selected stack frame.\n\
c906108c
SS
2053 Register name as argument means describe only that register.");
2054 add_info ("all-registers", all_registers_info,
c5aa993b 2055 "List of all registers and their contents, for selected stack frame.\n\
c906108c
SS
2056Register name as argument means describe only that register.");
2057
2058 add_info ("program", program_info,
2059 "Execution status of the program.");
2060
2061 add_info ("float", float_info,
2062 "Print the status of the floating point unit\n");
2063
c906108c
SS
2064 inferior_environ = make_environ ();
2065 init_environ (inferior_environ);
2066}