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