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