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