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