* event-loop.h: Mention async_event_handlers.
[deliverable/binutils-gdb.git] / gdb / infcmd.c
CommitLineData
c906108c 1/* Memory-access and commands for "inferior" process, for GDB.
990a07ab 2
6aba47ca 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
9b254dd1
DJ
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
23#include <signal.h>
24#include "gdb_string.h"
25#include "symtab.h"
26#include "gdbtypes.h"
27#include "frame.h"
28#include "inferior.h"
29#include "environ.h"
30#include "value.h"
31#include "gdbcmd.h"
1adeb98a 32#include "symfile.h"
c906108c
SS
33#include "gdbcore.h"
34#include "target.h"
35#include "language.h"
36#include "symfile.h"
37#include "objfiles.h"
c94fdfd0 38#include "completer.h"
8b93c638 39#include "ui-out.h"
6426a772 40#include "event-top.h"
96baa820 41#include "parser-defs.h"
36160dc4 42#include "regcache.h"
f9418c0f 43#include "reggroups.h"
fe898f56 44#include "block.h"
a77053c2 45#include "solib.h"
f9418c0f 46#include <ctype.h>
92ad9cd9 47#include "gdb_assert.h"
281b533b 48#include "observer.h"
424163ea 49#include "target-descriptions.h"
ad842144 50#include "user-regs.h"
32c1e744 51#include "exceptions.h"
700b53b1 52#include "cli/cli-decode.h"
a0ef4274 53#include "gdbthread.h"
72cec141 54
a58dd373 55/* Functions exported for general use, in inferior.h: */
c906108c 56
a14ed312 57void all_registers_info (char *, int);
c906108c 58
a14ed312 59void registers_info (char *, int);
c906108c 60
a58dd373
EZ
61void nexti_command (char *, int);
62
63void stepi_command (char *, int);
c906108c 64
a14ed312 65void continue_command (char *, int);
c906108c 66
a58dd373
EZ
67void interrupt_target_command (char *args, int from_tty);
68
69/* Local functions: */
70
71static void nofp_registers_info (char *, int);
72
c055b101
CV
73static void print_return_value (struct type *func_type,
74 struct type *value_type);
11cf8741 75
a14ed312 76static void until_next_command (int);
c906108c 77
a14ed312 78static void until_command (char *, int);
c906108c 79
a14ed312 80static void path_info (char *, int);
c906108c 81
a14ed312 82static void path_command (char *, int);
c906108c 83
a14ed312 84static void unset_command (char *, int);
c906108c 85
a14ed312 86static void float_info (char *, int);
c906108c 87
a14ed312 88static void detach_command (char *, int);
c906108c 89
6ad8ae5c
DJ
90static void disconnect_command (char *, int);
91
a14ed312 92static void unset_environment_command (char *, int);
c906108c 93
a14ed312 94static void set_environment_command (char *, int);
c906108c 95
a14ed312 96static void environment_info (char *, int);
c906108c 97
a14ed312 98static void program_info (char *, int);
c906108c 99
a14ed312 100static void finish_command (char *, int);
c906108c 101
a14ed312 102static void signal_command (char *, int);
c906108c 103
a14ed312 104static void jump_command (char *, int);
c906108c 105
a14ed312 106static void step_1 (int, int, char *);
611c83ae 107static void step_once (int skip_subroutines, int single_inst, int count, int thread);
c906108c 108
a14ed312 109static void next_command (char *, int);
c906108c 110
a14ed312 111static void step_command (char *, int);
c906108c 112
a14ed312 113static void run_command (char *, int);
c906108c 114
a14ed312 115static void run_no_args_command (char *args, int from_tty);
392a587b 116
a14ed312 117static void go_command (char *line_no, int from_tty);
392a587b 118
a14ed312 119static int strip_bg_char (char **);
43ff13b4 120
a14ed312 121void _initialize_infcmd (void);
c906108c 122
c906108c 123#define ERROR_NO_INFERIOR \
8a3fe4f8 124 if (!target_has_execution) error (_("The program is not being run."));
c906108c
SS
125
126/* String containing arguments to give to the program, separated by spaces.
127 Empty string (pointer to '\0') means no args. */
128
129static char *inferior_args;
130
552c04a7
TT
131/* The inferior arguments as a vector. If INFERIOR_ARGC is nonzero,
132 then we must compute INFERIOR_ARGS from this (via the target). */
133
134static int inferior_argc;
135static char **inferior_argv;
136
c906108c
SS
137/* File name for default use for standard in/out in the inferior. */
138
3cb3b8df 139static char *inferior_io_terminal;
c906108c
SS
140
141/* Pid of our debugged inferior, or 0 if no inferior now.
142 Since various parts of infrun.c test this to see whether there is a program
143 being debugged it should be nonzero (currently 3 is used) for remote
144 debugging. */
145
39f77062 146ptid_t inferior_ptid;
c906108c 147
c906108c
SS
148/* Address at which inferior stopped. */
149
150CORE_ADDR stop_pc;
151
c906108c
SS
152/* Flag indicating that a command has proceeded the inferior past the
153 current breakpoint. */
154
155int breakpoint_proceeded;
156
c906108c
SS
157/* Nonzero if stopped due to completion of a stack dummy routine. */
158
159int stop_stack_dummy;
160
161/* Nonzero if stopped due to a random (unexpected) signal in inferior
162 process. */
163
164int stopped_by_random_signal;
165
c906108c
SS
166/* Environment to use for running inferior,
167 in format described in environ.h. */
168
1bf1958d 169struct gdb_environ *inferior_environ;
f5871ec0 170
8f6a8e84
VP
171/* When set, no calls to target_resumed observer will be made. */
172int suppress_resume_observer = 0;
173/* When set, normal_stop will not call the normal_stop observer. */
174int suppress_stop_observer = 0;
c906108c 175\f
07091751
FN
176/* Accessor routines. */
177
3cb3b8df
BR
178void
179set_inferior_io_terminal (const char *terminal_name)
180{
181 if (inferior_io_terminal)
182 xfree (inferior_io_terminal);
183
184 if (!terminal_name)
185 inferior_io_terminal = NULL;
186 else
187 inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
188}
189
190const char *
191get_inferior_io_terminal (void)
192{
193 return inferior_io_terminal;
194}
195
07091751
FN
196char *
197get_inferior_args (void)
198{
552c04a7
TT
199 if (inferior_argc != 0)
200 {
201 char *n, *old;
202
203 n = gdbarch_construct_inferior_arguments (current_gdbarch,
204 inferior_argc, inferior_argv);
205 old = set_inferior_args (n);
206 xfree (old);
207 }
208
209 if (inferior_args == NULL)
210 inferior_args = xstrdup ("");
211
07091751
FN
212 return inferior_args;
213}
214
215char *
216set_inferior_args (char *newargs)
217{
218 char *saved_args = inferior_args;
219
220 inferior_args = newargs;
552c04a7
TT
221 inferior_argc = 0;
222 inferior_argv = 0;
07091751
FN
223
224 return saved_args;
225}
c5aa993b 226
552c04a7
TT
227void
228set_inferior_args_vector (int argc, char **argv)
229{
230 inferior_argc = argc;
231 inferior_argv = argv;
232}
233
234/* Notice when `set args' is run. */
235static void
236notice_args_set (char *args, int from_tty, struct cmd_list_element *c)
237{
238 inferior_argc = 0;
239 inferior_argv = 0;
240}
241
242/* Notice when `show args' is run. */
243static void
b4b4ac0b
AC
244notice_args_read (struct ui_file *file, int from_tty,
245 struct cmd_list_element *c, const char *value)
552c04a7 246{
258c00cc
TT
247 /* Note that we ignore the passed-in value in favor of computing it
248 directly. */
249 deprecated_show_value_hack (file, from_tty, c, get_inferior_args ());
552c04a7
TT
250}
251
c2a727fa
TT
252\f
253/* Compute command-line string given argument vector. This does the
254 same shell processing as fork_inferior. */
c2a727fa
TT
255char *
256construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
257{
258 char *result;
259
260 if (STARTUP_WITH_SHELL)
261 {
262 /* This holds all the characters considered special to the
263 typical Unix shells. We include `^' because the SunOS
264 /bin/sh treats it as a synonym for `|'. */
265 char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
266 int i;
267 int length = 0;
268 char *out, *cp;
269
270 /* We over-compute the size. It shouldn't matter. */
271 for (i = 0; i < argc; ++i)
03c6228e 272 length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
c2a727fa
TT
273
274 result = (char *) xmalloc (length);
275 out = result;
276
277 for (i = 0; i < argc; ++i)
278 {
279 if (i > 0)
280 *out++ = ' ';
281
03c6228e
AS
282 /* Need to handle empty arguments specially. */
283 if (argv[i][0] == '\0')
c2a727fa 284 {
03c6228e
AS
285 *out++ = '\'';
286 *out++ = '\'';
287 }
288 else
289 {
290 for (cp = argv[i]; *cp; ++cp)
291 {
292 if (strchr (special, *cp) != NULL)
293 *out++ = '\\';
294 *out++ = *cp;
295 }
c2a727fa
TT
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)
8a3fe4f8 315 error (_("can't handle command-line argument containing whitespace"));
c2a727fa
TT
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 363void
fba45db2 364tty_command (char *file, int from_tty)
c906108c
SS
365{
366 if (file == 0)
e2e0b3e5 367 error_no_arg (_("terminal name for running target process"));
c906108c 368
3cb3b8df 369 set_inferior_io_terminal (file);
c906108c
SS
370}
371
281b533b
DJ
372/* Common actions to take after creating any sort of inferior, by any
373 means (running, attaching, connecting, et cetera). The target
374 should be stopped. */
375
376void
377post_create_inferior (struct target_ops *target, int from_tty)
378{
b79599ff
DP
379 /* Be sure we own the terminal in case write operations are performed. */
380 target_terminal_ours ();
381
424163ea
DJ
382 /* If the target hasn't taken care of this already, do it now.
383 Targets which need to access registers during to_open,
384 to_create_inferior, or to_attach should do it earlier; but many
385 don't need to. */
386 target_find_description ();
387
9353355f
DJ
388 if (exec_bfd)
389 {
390 /* Sometimes the platform-specific hook loads initial shared
391 libraries, and sometimes it doesn't. Try to do so first, so
de1b3c3d
PA
392 that we can add them with the correct value for FROM_TTY.
393 If we made all the inferior hook methods consistent,
394 this call could be removed. */
9353355f
DJ
395#ifdef SOLIB_ADD
396 SOLIB_ADD (NULL, from_tty, target, auto_solib_add);
397#else
398 solib_add (NULL, from_tty, target, auto_solib_add);
399#endif
400
401 /* Create the hooks to handle shared library load and unload
402 events. */
403#ifdef SOLIB_CREATE_INFERIOR_HOOK
37706b70 404 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
9353355f
DJ
405#else
406 solib_create_inferior_hook ();
407#endif
9353355f
DJ
408 }
409
281b533b
DJ
410 observer_notify_inferior_created (target, from_tty);
411}
412
a4d5f2e0
JB
413/* Kill the inferior if already running. This function is designed
414 to be called when we are about to start the execution of the program
415 from the beginning. Ask the user to confirm that he wants to restart
416 the program being debugged when FROM_TTY is non-null. */
c906108c 417
8edfe269 418static void
a4d5f2e0
JB
419kill_if_already_running (int from_tty)
420{
39f77062 421 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
c906108c 422 {
8edfe269
DJ
423 /* Bail out before killing the program if we will not be able to
424 restart it. */
425 target_require_runnable ();
426
adf40b2e
JM
427 if (from_tty
428 && !query ("The program being debugged has been started already.\n\
c906108c 429Start it from the beginning? "))
8a3fe4f8 430 error (_("Program not restarted."));
c906108c 431 target_kill ();
c906108c 432 }
a4d5f2e0
JB
433}
434
f67a969f
JB
435/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
436 a temporary breakpoint at the begining of the main program before
437 running the program. */
438
a4d5f2e0 439static void
f67a969f 440run_command_1 (char *args, int from_tty, int tbreak_at_main)
a4d5f2e0
JB
441{
442 char *exec_file;
c906108c 443
a4d5f2e0
JB
444 dont_repeat ();
445
446 kill_if_already_running (from_tty);
3c35e65b
UW
447
448 init_wait_for_inferior ();
c906108c
SS
449 clear_breakpoint_hit_counts ();
450
fd79ecee
DJ
451 /* Clean up any leftovers from other runs. Some other things from
452 this function should probably be moved into target_pre_inferior. */
453 target_pre_inferior (from_tty);
454
39ad761d
JB
455 /* The comment here used to read, "The exec file is re-read every
456 time we do a generic_mourn_inferior, so we just have to worry
457 about the symbol file." The `generic_mourn_inferior' function
458 gets called whenever the program exits. However, suppose the
459 program exits, and *then* the executable file changes? We need
460 to check again here. Since reopen_exec_file doesn't do anything
461 if the timestamp hasn't changed, I don't see the harm. */
462 reopen_exec_file ();
c906108c
SS
463 reread_symbols ();
464
f67a969f
JB
465 /* Insert the temporary breakpoint if a location was specified. */
466 if (tbreak_at_main)
467 tbreak_command (main_name (), 0);
468
39ad761d
JB
469 exec_file = (char *) get_exec_file (0);
470
9908b566
VP
471 if (non_stop && !target_supports_non_stop ())
472 error (_("The target does not support running in non-stop mode."));
473
c906108c
SS
474 /* We keep symbols from add-symbol-file, on the grounds that the
475 user might want to add some symbols before running the program
476 (right?). But sometimes (dynamic loading where the user manually
477 introduces the new symbols with add-symbol-file), the code which
478 the symbols describe does not persist between runs. Currently
479 the user has to manually nuke all symbols between runs if they
480 want them to go away (PR 2207). This is probably reasonable. */
481
43ff13b4 482 if (!args)
6426a772 483 {
362646f5 484 if (target_can_async_p ())
6426a772
JM
485 async_disable_stdin ();
486 }
43ff13b4 487 else
c906108c 488 {
43ff13b4
JM
489 int async_exec = strip_bg_char (&args);
490
491 /* If we get a request for running in the bg but the target
492 doesn't support it, error out. */
362646f5 493 if (async_exec && !target_can_async_p ())
8a3fe4f8 494 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
495
496 /* If we don't get a request of running in the bg, then we need
c5aa993b 497 to simulate synchronous (fg) execution. */
362646f5 498 if (!async_exec && target_can_async_p ())
43ff13b4
JM
499 {
500 /* Simulate synchronous execution */
6426a772 501 async_disable_stdin ();
43ff13b4
JM
502 }
503
504 /* If there were other args, beside '&', process them. */
505 if (args)
506 {
07091751
FN
507 char *old_args = set_inferior_args (xstrdup (args));
508 xfree (old_args);
43ff13b4 509 }
c906108c
SS
510 }
511
512 if (from_tty)
513 {
8b93c638
JM
514 ui_out_field_string (uiout, NULL, "Starting program");
515 ui_out_text (uiout, ": ");
516 if (exec_file)
517 ui_out_field_string (uiout, "execfile", exec_file);
518 ui_out_spaces (uiout, 1);
552c04a7
TT
519 /* We call get_inferior_args() because we might need to compute
520 the value now. */
521 ui_out_field_string (uiout, "infargs", get_inferior_args ());
8b93c638
JM
522 ui_out_text (uiout, "\n");
523 ui_out_flush (uiout);
c906108c
SS
524 }
525
552c04a7
TT
526 /* We call get_inferior_args() because we might need to compute
527 the value now. */
528 target_create_inferior (exec_file, get_inferior_args (),
c27cda74 529 environ_vector (inferior_environ), from_tty);
281b533b 530
de1b3c3d
PA
531 /* Pass zero for FROM_TTY, because at this point the "run" command
532 has done its thing; now we are setting up the running program. */
533 post_create_inferior (&current_target, 0);
281b533b
DJ
534
535 /* Start the target running. */
536 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
c906108c
SS
537}
538
539
f67a969f
JB
540static void
541run_command (char *args, int from_tty)
542{
543 run_command_1 (args, from_tty, 0);
544}
545
c906108c 546static void
fba45db2 547run_no_args_command (char *args, int from_tty)
c906108c 548{
07091751
FN
549 char *old_args = set_inferior_args (xstrdup (""));
550 xfree (old_args);
c906108c 551}
c906108c 552\f
c5aa993b 553
a4d5f2e0
JB
554/* Start the execution of the program up until the beginning of the main
555 program. */
556
557static void
558start_command (char *args, int from_tty)
559{
560 /* Some languages such as Ada need to search inside the program
561 minimal symbols for the location where to put the temporary
562 breakpoint before starting. */
563 if (!have_minimal_symbols ())
8a3fe4f8 564 error (_("No symbol table loaded. Use the \"file\" command."));
a4d5f2e0 565
f67a969f
JB
566 /* Run the program until reaching the main procedure... */
567 run_command_1 (args, from_tty, 1);
a4d5f2e0
JB
568}
569
8cae4b3f
PA
570static int
571proceed_thread_callback (struct thread_info *thread, void *arg)
572{
4f8d22e3 573 if (!is_stopped (thread->ptid))
8cae4b3f
PA
574 return 0;
575
dcf4fbde 576 switch_to_thread (thread->ptid);
8cae4b3f
PA
577 clear_proceed_status ();
578 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
579 return 0;
580}
581
77ebaa5a
VP
582void
583continue_1 (int all_threads)
584{
3d488bfc
PA
585 ERROR_NO_INFERIOR;
586
77ebaa5a
VP
587 if (non_stop && all_threads)
588 {
589 /* Don't error out if the current thread is running, because
590 there may be other stopped threads. */
591 struct cleanup *old_chain;
592
593 /* Backup current thread and selected frame. */
594 old_chain = make_cleanup_restore_current_thread ();
595
596 iterate_over_threads (proceed_thread_callback, NULL);
597
598 /* Restore selected ptid. */
599 do_cleanups (old_chain);
600 }
601 else
602 {
603 ensure_not_running ();
604 clear_proceed_status ();
605 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
606 }
607}
608
8cae4b3f 609/* continue [-a] [proceed-count] [&] */
c906108c 610void
8cae4b3f 611continue_command (char *args, int from_tty)
c906108c 612{
c5aa993b 613 int async_exec = 0;
8cae4b3f 614 int all_threads = 0;
c906108c
SS
615 ERROR_NO_INFERIOR;
616
43ff13b4 617 /* Find out whether we must run in the background. */
8cae4b3f
PA
618 if (args != NULL)
619 async_exec = strip_bg_char (&args);
43ff13b4
JM
620
621 /* If we must run in the background, but the target can't do it,
622 error out. */
362646f5 623 if (async_exec && !target_can_async_p ())
8a3fe4f8 624 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
625
626 /* If we are not asked to run in the bg, then prepare to run in the
627 foreground, synchronously. */
362646f5 628 if (!async_exec && target_can_async_p ())
c5aa993b 629 {
43ff13b4 630 /* Simulate synchronous execution */
6426a772 631 async_disable_stdin ();
43ff13b4 632 }
c906108c 633
8cae4b3f
PA
634 if (args != NULL)
635 {
636 if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
637 {
638 all_threads = 1;
639 args += sizeof ("-a") - 1;
640 if (*args == '\0')
641 args = NULL;
642 }
643 }
644
645 if (!non_stop && all_threads)
646 error (_("`-a' is meaningless in all-stop mode."));
647
648 if (args != NULL && all_threads)
649 error (_("\
650Can't resume all threads and specify proceed count simultaneously."));
651
652 /* If we have an argument left, set proceed count of breakpoint we
653 stopped at. */
654 if (args != NULL)
c906108c 655 {
347bddb7 656 bpstat bs = NULL;
8671a17b
PA
657 int num, stat;
658 int stopped = 0;
347bddb7
PA
659 struct thread_info *tp;
660
661 if (non_stop)
662 tp = find_thread_pid (inferior_ptid);
663 else
664 {
665 ptid_t last_ptid;
666 struct target_waitstatus ws;
667
668 get_last_target_status (&last_ptid, &ws);
669 tp = find_thread_pid (last_ptid);
670 }
671 if (tp != NULL)
672 bs = tp->stop_bpstat;
8671a17b
PA
673
674 while ((stat = bpstat_num (&bs, &num)) != 0)
675 if (stat > 0)
676 {
677 set_ignore_count (num,
8cae4b3f 678 parse_and_eval_long (args) - 1,
8671a17b
PA
679 from_tty);
680 /* set_ignore_count prints a message ending with a period.
681 So print two spaces before "Continuing.". */
682 if (from_tty)
683 printf_filtered (" ");
684 stopped = 1;
685 }
686
687 if (!stopped && from_tty)
c906108c
SS
688 {
689 printf_filtered
690 ("Not stopped at any breakpoint; argument ignored.\n");
691 }
c906108c
SS
692 }
693
694 if (from_tty)
a3f17187 695 printf_filtered (_("Continuing.\n"));
c906108c 696
77ebaa5a 697 continue_1 (all_threads);
c906108c
SS
698}
699\f
700/* Step until outside of current statement. */
701
c906108c 702static void
fba45db2 703step_command (char *count_string, int from_tty)
c906108c
SS
704{
705 step_1 (0, 0, count_string);
706}
707
708/* Likewise, but skip over subroutine calls as if single instructions. */
709
c906108c 710static void
fba45db2 711next_command (char *count_string, int from_tty)
c906108c
SS
712{
713 step_1 (1, 0, count_string);
714}
715
716/* Likewise, but step only one instruction. */
717
c906108c 718void
fba45db2 719stepi_command (char *count_string, int from_tty)
c906108c
SS
720{
721 step_1 (0, 1, count_string);
722}
723
c906108c 724void
fba45db2 725nexti_command (char *count_string, int from_tty)
c906108c
SS
726{
727 step_1 (1, 1, count_string);
728}
729
74b7792f 730static void
611c83ae 731delete_longjmp_breakpoint_cleanup (void *arg)
74b7792f 732{
611c83ae
PA
733 int thread = * (int *) arg;
734 delete_longjmp_breakpoint (thread);
74b7792f
AC
735}
736
c906108c 737static void
fba45db2 738step_1 (int skip_subroutines, int single_inst, char *count_string)
c906108c 739{
52f0bd74 740 int count = 1;
c906108c 741 struct frame_info *frame;
f107f563 742 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
43ff13b4 743 int async_exec = 0;
b3dc826b 744 int thread = -1;
c5aa993b 745
c906108c 746 ERROR_NO_INFERIOR;
94cc34af 747 ensure_not_running ();
43ff13b4
JM
748
749 if (count_string)
750 async_exec = strip_bg_char (&count_string);
c5aa993b 751
43ff13b4
JM
752 /* If we get a request for running in the bg but the target
753 doesn't support it, error out. */
362646f5 754 if (async_exec && !target_can_async_p ())
8a3fe4f8 755 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
756
757 /* If we don't get a request of running in the bg, then we need
758 to simulate synchronous (fg) execution. */
362646f5 759 if (!async_exec && target_can_async_p ())
43ff13b4
JM
760 {
761 /* Simulate synchronous execution */
6426a772 762 async_disable_stdin ();
43ff13b4
JM
763 }
764
bb518678 765 count = count_string ? parse_and_eval_long (count_string) : 1;
c906108c 766
c5aa993b 767 if (!single_inst || skip_subroutines) /* leave si command alone */
c906108c 768 {
611c83ae 769 if (in_thread_list (inferior_ptid))
b3dc826b 770 thread = pid_to_thread_id (inferior_ptid);
611c83ae
PA
771
772 set_longjmp_breakpoint ();
773
b3dc826b 774 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
c2d11a7d
JM
775 }
776
777 /* In synchronous case, all is well, just use the regular for loop. */
362646f5 778 if (!target_can_async_p ())
c2d11a7d
JM
779 {
780 for (; count > 0; count--)
781 {
4e1c45ea 782 struct thread_info *tp = inferior_thread ();
c2d11a7d
JM
783 clear_proceed_status ();
784
785 frame = get_current_frame ();
4e1c45ea 786 tp->step_frame_id = get_frame_id (frame);
c2d11a7d
JM
787
788 if (!single_inst)
789 {
4e1c45ea
PA
790 find_pc_line_pc_range (stop_pc,
791 &tp->step_range_start, &tp->step_range_end);
792 if (tp->step_range_end == 0)
c2d11a7d
JM
793 {
794 char *name;
4e1c45ea
PA
795 if (find_pc_partial_function (stop_pc, &name,
796 &tp->step_range_start,
797 &tp->step_range_end) == 0)
8a3fe4f8 798 error (_("Cannot find bounds of current function"));
c2d11a7d
JM
799
800 target_terminal_ours ();
a3f17187 801 printf_filtered (_("\
c2d11a7d 802Single stepping until exit from function %s, \n\
a3f17187 803which has no line number information.\n"), name);
c2d11a7d
JM
804 }
805 }
806 else
807 {
808 /* Say we are stepping, but stop after one insn whatever it does. */
4e1c45ea 809 tp->step_range_start = tp->step_range_end = 1;
c2d11a7d
JM
810 if (!skip_subroutines)
811 /* It is stepi.
812 Don't step over function calls, not even to functions lacking
813 line numbers. */
078130d0 814 tp->step_over_calls = STEP_OVER_NONE;
c2d11a7d
JM
815 }
816
817 if (skip_subroutines)
078130d0 818 tp->step_over_calls = STEP_OVER_ALL;
c2d11a7d 819
af679fd0 820 tp->step_multi = (count > 1);
c2d11a7d
JM
821 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
822
414c69f7
PA
823 if (!target_has_execution
824 || !inferior_thread ()->stop_step)
c2d11a7d 825 break;
c2d11a7d
JM
826 }
827
f107f563 828 do_cleanups (cleanups);
c2d11a7d
JM
829 return;
830 }
831 /* In case of asynchronous target things get complicated, do only
832 one step for now, before returning control to the event loop. Let
833 the continuation figure out how many other steps we need to do,
834 and handle them one at the time, through step_once(). */
835 else
836 {
b3dc826b 837 step_once (skip_subroutines, single_inst, count, thread);
611c83ae 838 /* We are running, and the continuation is installed. It will
f107f563
VP
839 disable the longjmp breakpoint as appropriate. */
840 discard_cleanups (cleanups);
c906108c 841 }
c2d11a7d 842}
c906108c 843
bfec99b2
PA
844struct step_1_continuation_args
845{
846 int count;
847 int skip_subroutines;
848 int single_inst;
849 int thread;
850};
851
c2d11a7d
JM
852/* Called after we are done with one step operation, to check whether
853 we need to step again, before we print the prompt and return control
854 to the user. If count is > 1, we will need to do one more call to
855 proceed(), via step_once(). Basically it is like step_once and
856 step_1_continuation are co-recursive. */
857static void
604ead4a 858step_1_continuation (void *args)
c2d11a7d 859{
bfec99b2 860 struct step_1_continuation_args *a = args;
f13468d9 861
af679fd0 862 if (target_has_execution)
f13468d9 863 {
af679fd0
PA
864 struct thread_info *tp;
865
866 tp = inferior_thread ();
414c69f7 867 if (tp->step_multi && tp->stop_step)
af679fd0
PA
868 {
869 /* There are more steps to make, and we did stop due to
870 ending a stepping range. Do another step. */
871 step_once (a->skip_subroutines, a->single_inst, a->count - 1, a->thread);
872 return;
873 }
874 tp->step_multi = 0;
f107f563 875 }
af679fd0
PA
876
877 /* We either stopped for some reason that is not stepping, or there
878 are no further steps to make. Cleanup. */
879 if (!a->single_inst || a->skip_subroutines)
880 delete_longjmp_breakpoint (a->thread);
c2d11a7d
JM
881}
882
883/* Do just one step operation. If count >1 we will have to set up a
884 continuation to be done after the target stops (after this one
885 step). This is useful to implement the 'step n' kind of commands, in
886 case of asynchronous targets. We had to split step_1 into two parts,
887 one to be done before proceed() and one afterwards. This function is
888 called in case of step n with n>1, after the first step operation has
889 been completed.*/
890static void
611c83ae 891step_once (int skip_subroutines, int single_inst, int count, int thread)
bfec99b2 892{
0d06e24b 893 struct frame_info *frame;
bfec99b2 894 struct step_1_continuation_args *args;
c2d11a7d
JM
895
896 if (count > 0)
c906108c 897 {
4e1c45ea
PA
898 /* Don't assume THREAD is a valid thread id. It is set to -1 if
899 the longjmp breakpoint was not required. Use the
900 INFERIOR_PTID thread instead, which is the same thread when
901 THREAD is set. */
902 struct thread_info *tp = inferior_thread ();
c906108c
SS
903 clear_proceed_status ();
904
905 frame = get_current_frame ();
c5aa993b 906 if (!frame) /* Avoid coredump here. Why tho? */
8a3fe4f8 907 error (_("No current frame"));
4e1c45ea 908 tp->step_frame_id = get_frame_id (frame);
c906108c 909
c5aa993b 910 if (!single_inst)
c906108c 911 {
4e1c45ea
PA
912 find_pc_line_pc_range (stop_pc,
913 &tp->step_range_start, &tp->step_range_end);
5fbbeb29
CF
914
915 /* If we have no line info, switch to stepi mode. */
4e1c45ea 916 if (tp->step_range_end == 0 && step_stop_if_no_debug)
5fbbeb29 917 {
4e1c45ea 918 tp->step_range_start = tp->step_range_end = 1;
5fbbeb29 919 }
4e1c45ea 920 else if (tp->step_range_end == 0)
c906108c
SS
921 {
922 char *name;
4e1c45ea
PA
923 if (find_pc_partial_function (stop_pc, &name,
924 &tp->step_range_start,
925 &tp->step_range_end) == 0)
8a3fe4f8 926 error (_("Cannot find bounds of current function"));
c906108c
SS
927
928 target_terminal_ours ();
a3f17187 929 printf_filtered (_("\
c906108c 930Single stepping until exit from function %s, \n\
a3f17187 931which has no line number information.\n"), name);
c906108c
SS
932 }
933 }
934 else
935 {
936 /* Say we are stepping, but stop after one insn whatever it does. */
4e1c45ea 937 tp->step_range_start = tp->step_range_end = 1;
c906108c
SS
938 if (!skip_subroutines)
939 /* It is stepi.
940 Don't step over function calls, not even to functions lacking
941 line numbers. */
078130d0 942 tp->step_over_calls = STEP_OVER_NONE;
c906108c
SS
943 }
944
945 if (skip_subroutines)
078130d0 946 tp->step_over_calls = STEP_OVER_ALL;
c906108c 947
95e54da7 948 tp->step_multi = (count > 1);
f107f563 949 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
bfec99b2
PA
950
951 args = xmalloc (sizeof (*args));
952 args->skip_subroutines = skip_subroutines;
953 args->single_inst = single_inst;
954 args->count = count;
955 args->thread = thread;
95e54da7 956 add_intermediate_continuation (tp, step_1_continuation, args, xfree);
c906108c 957 }
c906108c 958}
c2d11a7d 959
c906108c
SS
960\f
961/* Continue program at specified address. */
962
963static void
fba45db2 964jump_command (char *arg, int from_tty)
c906108c 965{
52f0bd74 966 CORE_ADDR addr;
c906108c
SS
967 struct symtabs_and_lines sals;
968 struct symtab_and_line sal;
969 struct symbol *fn;
970 struct symbol *sfn;
43ff13b4 971 int async_exec = 0;
c5aa993b 972
c906108c 973 ERROR_NO_INFERIOR;
94cc34af 974 ensure_not_running ();
c906108c 975
43ff13b4
JM
976 /* Find out whether we must run in the background. */
977 if (arg != NULL)
978 async_exec = strip_bg_char (&arg);
979
980 /* If we must run in the background, but the target can't do it,
981 error out. */
362646f5 982 if (async_exec && !target_can_async_p ())
8a3fe4f8 983 error (_("Asynchronous execution not supported on this target."));
43ff13b4 984
c906108c 985 if (!arg)
e2e0b3e5 986 error_no_arg (_("starting address"));
c906108c
SS
987
988 sals = decode_line_spec_1 (arg, 1);
989 if (sals.nelts != 1)
990 {
8a3fe4f8 991 error (_("Unreasonable jump request"));
c906108c
SS
992 }
993
994 sal = sals.sals[0];
b8c9b27d 995 xfree (sals.sals);
c906108c
SS
996
997 if (sal.symtab == 0 && sal.pc == 0)
8a3fe4f8 998 error (_("No source file has been specified."));
c906108c 999
c5aa993b 1000 resolve_sal_pc (&sal); /* May error out */
c906108c
SS
1001
1002 /* See if we are trying to jump to another function. */
1003 fn = get_frame_function (get_current_frame ());
1004 sfn = find_pc_function (sal.pc);
1005 if (fn != NULL && sfn != fn)
1006 {
1007 if (!query ("Line %d is not in `%s'. Jump anyway? ", sal.line,
de5ad195 1008 SYMBOL_PRINT_NAME (fn)))
c906108c 1009 {
8a3fe4f8 1010 error (_("Not confirmed."));
c906108c
SS
1011 /* NOTREACHED */
1012 }
1013 }
1014
c5aa993b 1015 if (sfn != NULL)
c906108c
SS
1016 {
1017 fixup_symbol_section (sfn, 0);
714835d5
UW
1018 if (section_is_overlay (SYMBOL_OBJ_SECTION (sfn)) &&
1019 !section_is_mapped (SYMBOL_OBJ_SECTION (sfn)))
c906108c
SS
1020 {
1021 if (!query ("WARNING!!! Destination is in unmapped overlay! Jump anyway? "))
1022 {
8a3fe4f8 1023 error (_("Not confirmed."));
c906108c
SS
1024 /* NOTREACHED */
1025 }
1026 }
1027 }
1028
c906108c
SS
1029 addr = sal.pc;
1030
1031 if (from_tty)
1032 {
a3f17187 1033 printf_filtered (_("Continuing at "));
ed49a04f 1034 fputs_filtered (paddress (addr), gdb_stdout);
c906108c
SS
1035 printf_filtered (".\n");
1036 }
1037
89113898
PA
1038 /* If we are not asked to run in the bg, then prepare to run in the
1039 foreground, synchronously. */
1040 if (!async_exec && target_can_async_p ())
1041 {
1042 /* Simulate synchronous execution */
1043 async_disable_stdin ();
1044 }
1045
c906108c
SS
1046 clear_proceed_status ();
1047 proceed (addr, TARGET_SIGNAL_0, 0);
1048}
c906108c 1049\f
c5aa993b 1050
c906108c
SS
1051/* Go to line or address in current procedure */
1052static void
fba45db2 1053go_command (char *line_no, int from_tty)
c906108c 1054{
c5aa993b 1055 if (line_no == (char *) NULL || !*line_no)
f42429a6 1056 printf_filtered (_("Usage: go <location>\n"));
c906108c
SS
1057 else
1058 {
b83266a0
SS
1059 tbreak_command (line_no, from_tty);
1060 jump_command (line_no, from_tty);
c906108c
SS
1061 }
1062}
c906108c 1063\f
c5aa993b 1064
c906108c
SS
1065/* Continue program giving it specified signal. */
1066
1067static void
fba45db2 1068signal_command (char *signum_exp, int from_tty)
c906108c
SS
1069{
1070 enum target_signal oursig;
32c1e744 1071 int async_exec = 0;
c906108c
SS
1072
1073 dont_repeat (); /* Too dangerous. */
1074 ERROR_NO_INFERIOR;
94cc34af 1075 ensure_not_running ();
c906108c 1076
32c1e744
VP
1077 /* Find out whether we must run in the background. */
1078 if (signum_exp != NULL)
1079 async_exec = strip_bg_char (&signum_exp);
1080
1081 /* If we must run in the background, but the target can't do it,
1082 error out. */
1083 if (async_exec && !target_can_async_p ())
1084 error (_("Asynchronous execution not supported on this target."));
1085
1086 /* If we are not asked to run in the bg, then prepare to run in the
1087 foreground, synchronously. */
1088 if (!async_exec && target_can_async_p ())
1089 {
1090 /* Simulate synchronous execution. */
1091 async_disable_stdin ();
1092 }
1093
c906108c 1094 if (!signum_exp)
e2e0b3e5 1095 error_no_arg (_("signal number"));
c906108c
SS
1096
1097 /* It would be even slicker to make signal names be valid expressions,
1098 (the type could be "enum $signal" or some such), then the user could
1099 assign them to convenience variables. */
1100 oursig = target_signal_from_name (signum_exp);
1101
1102 if (oursig == TARGET_SIGNAL_UNKNOWN)
1103 {
1104 /* No, try numeric. */
bb518678 1105 int num = parse_and_eval_long (signum_exp);
c906108c
SS
1106
1107 if (num == 0)
1108 oursig = TARGET_SIGNAL_0;
1109 else
1110 oursig = target_signal_from_command (num);
1111 }
1112
1113 if (from_tty)
1114 {
1115 if (oursig == TARGET_SIGNAL_0)
a3f17187 1116 printf_filtered (_("Continuing with no signal.\n"));
c906108c 1117 else
a3f17187 1118 printf_filtered (_("Continuing with signal %s.\n"),
c906108c
SS
1119 target_signal_to_name (oursig));
1120 }
1121
1122 clear_proceed_status ();
1123 /* "signal 0" should not get stuck if we are stopped at a breakpoint.
1124 FIXME: Neither should "signal foo" but when I tried passing
1125 (CORE_ADDR)-1 unconditionally I got a testsuite failure which I haven't
1126 tried to track down yet. */
2acceee2 1127 proceed (oursig == TARGET_SIGNAL_0 ? (CORE_ADDR) -1 : stop_pc, oursig, 0);
c906108c
SS
1128}
1129
c906108c
SS
1130/* Proceed until we reach a different source line with pc greater than
1131 our current one or exit the function. We skip calls in both cases.
1132
1133 Note that eventually this command should probably be changed so
1134 that only source lines are printed out when we hit the breakpoint
1135 we set. This may involve changes to wait_for_inferior and the
1136 proceed status code. */
1137
c906108c 1138static void
fba45db2 1139until_next_command (int from_tty)
c906108c
SS
1140{
1141 struct frame_info *frame;
1142 CORE_ADDR pc;
1143 struct symbol *func;
1144 struct symtab_and_line sal;
4e1c45ea 1145 struct thread_info *tp = inferior_thread ();
c5aa993b 1146
c906108c
SS
1147 clear_proceed_status ();
1148
1149 frame = get_current_frame ();
1150
1151 /* Step until either exited from this function or greater
1152 than the current line (if in symbolic section) or pc (if
1153 not). */
1154
1155 pc = read_pc ();
1156 func = find_pc_function (pc);
c5aa993b 1157
c906108c
SS
1158 if (!func)
1159 {
1160 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
c5aa993b 1161
c906108c 1162 if (msymbol == NULL)
8a3fe4f8 1163 error (_("Execution is not within a known function."));
c5aa993b 1164
4e1c45ea
PA
1165 tp->step_range_start = SYMBOL_VALUE_ADDRESS (msymbol);
1166 tp->step_range_end = pc;
c906108c
SS
1167 }
1168 else
1169 {
1170 sal = find_pc_line (pc, 0);
c5aa993b 1171
4e1c45ea
PA
1172 tp->step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
1173 tp->step_range_end = sal.end;
c906108c 1174 }
c5aa993b 1175
078130d0 1176 tp->step_over_calls = STEP_OVER_ALL;
4e1c45ea 1177 tp->step_frame_id = get_frame_id (frame);
c906108c 1178
af679fd0 1179 tp->step_multi = 0; /* Only one call to proceed */
c5aa993b 1180
2acceee2 1181 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
c906108c
SS
1182}
1183
c5aa993b 1184static void
fba45db2 1185until_command (char *arg, int from_tty)
c906108c 1186{
43ff13b4
JM
1187 int async_exec = 0;
1188
c906108c 1189 if (!target_has_execution)
8a3fe4f8 1190 error (_("The program is not running."));
43ff13b4
JM
1191
1192 /* Find out whether we must run in the background. */
1193 if (arg != NULL)
1194 async_exec = strip_bg_char (&arg);
1195
1196 /* If we must run in the background, but the target can't do it,
1197 error out. */
362646f5 1198 if (async_exec && !target_can_async_p ())
8a3fe4f8 1199 error (_("Asynchronous execution not supported on this target."));
43ff13b4
JM
1200
1201 /* If we are not asked to run in the bg, then prepare to run in the
1202 foreground, synchronously. */
362646f5 1203 if (!async_exec && target_can_async_p ())
c5aa993b 1204 {
43ff13b4 1205 /* Simulate synchronous execution */
6426a772 1206 async_disable_stdin ();
43ff13b4
JM
1207 }
1208
c906108c 1209 if (arg)
ae66c1fc 1210 until_break_command (arg, from_tty, 0);
c906108c
SS
1211 else
1212 until_next_command (from_tty);
1213}
ae66c1fc
EZ
1214
1215static void
1216advance_command (char *arg, int from_tty)
1217{
1218 int async_exec = 0;
1219
1220 if (!target_has_execution)
8a3fe4f8 1221 error (_("The program is not running."));
ae66c1fc
EZ
1222
1223 if (arg == NULL)
e2e0b3e5 1224 error_no_arg (_("a location"));
ae66c1fc
EZ
1225
1226 /* Find out whether we must run in the background. */
1227 if (arg != NULL)
1228 async_exec = strip_bg_char (&arg);
1229
1230 /* If we must run in the background, but the target can't do it,
1231 error out. */
362646f5 1232 if (async_exec && !target_can_async_p ())
8a3fe4f8 1233 error (_("Asynchronous execution not supported on this target."));
ae66c1fc
EZ
1234
1235 /* If we are not asked to run in the bg, then prepare to run in the
1236 foreground, synchronously. */
362646f5 1237 if (!async_exec && target_can_async_p ())
ae66c1fc
EZ
1238 {
1239 /* Simulate synchronous execution. */
1240 async_disable_stdin ();
1241 }
1242
1243 until_break_command (arg, from_tty, 1);
1244}
c906108c 1245\f
f941662f
MK
1246/* Print the result of a function at the end of a 'finish' command. */
1247
11cf8741 1248static void
c055b101 1249print_return_value (struct type *func_type, struct type *value_type)
11cf8741 1250{
31db7b6c 1251 struct gdbarch *gdbarch = current_gdbarch;
bb472c1e
MK
1252 struct cleanup *old_chain;
1253 struct ui_stream *stb;
44e5158b
AC
1254 struct value *value;
1255
181fc57c 1256 CHECK_TYPEDEF (value_type);
44e5158b 1257 gdb_assert (TYPE_CODE (value_type) != TYPE_CODE_VOID);
11cf8741 1258
92ad9cd9
AC
1259 /* FIXME: 2003-09-27: When returning from a nested inferior function
1260 call, it's possible (with no help from the architecture vector)
1261 to locate and return/print a "struct return" value. This is just
1262 a more complicated case of what is already being done in in the
1263 inferior function call code. In fact, when inferior function
1264 calls are made async, this will likely be made the norm. */
31db7b6c 1265
c055b101
CV
1266 switch (gdbarch_return_value (gdbarch, func_type, value_type,
1267 NULL, NULL, NULL))
44e5158b 1268 {
750eb019
AC
1269 case RETURN_VALUE_REGISTER_CONVENTION:
1270 case RETURN_VALUE_ABI_RETURNS_ADDRESS:
181fc57c 1271 case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
44e5158b 1272 value = allocate_value (value_type);
c055b101 1273 gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
990a07ab 1274 value_contents_raw (value), NULL);
750eb019
AC
1275 break;
1276 case RETURN_VALUE_STRUCT_CONVENTION:
1277 value = NULL;
1278 break;
1279 default:
e2e0b3e5 1280 internal_error (__FILE__, __LINE__, _("bad switch"));
44e5158b 1281 }
bb472c1e 1282
31db7b6c
MK
1283 if (value)
1284 {
1285 /* Print it. */
1d751abe
PA
1286 stb = ui_out_stream_new (uiout);
1287 old_chain = make_cleanup_ui_out_stream_delete (stb);
31db7b6c
MK
1288 ui_out_text (uiout, "Value returned is ");
1289 ui_out_field_fmt (uiout, "gdb-result-var", "$%d",
1290 record_latest_value (value));
1291 ui_out_text (uiout, " = ");
1292 value_print (value, stb->stream, 0, Val_no_prettyprint);
1293 ui_out_field_stream (uiout, "return-value", stb);
1294 ui_out_text (uiout, "\n");
1d751abe 1295 do_cleanups (old_chain);
31db7b6c
MK
1296 }
1297 else
1298 {
1299 ui_out_text (uiout, "Value returned has type: ");
1d751abe
PA
1300 ui_out_field_string (uiout, "return-type", TYPE_NAME (value_type));
1301 ui_out_text (uiout, ".");
1302 ui_out_text (uiout, " Cannot determine contents\n");
31db7b6c 1303 }
11cf8741
JM
1304}
1305
43ff13b4 1306/* Stuff that needs to be done by the finish command after the target
f941662f
MK
1307 has stopped. In asynchronous mode, we wait for the target to stop
1308 in the call to poll or select in the event loop, so it is
1309 impossible to do all the stuff as part of the finish_command
1310 function itself. The only chance we have to complete this command
1311 is in fetch_inferior_event, which is called by the event loop as
1312 soon as it detects that the target has stopped. This function is
1313 called via the cmd_continuation pointer. */
1314
bfec99b2 1315struct finish_command_continuation_args
43ff13b4 1316{
43ff13b4 1317 struct breakpoint *breakpoint;
bfec99b2
PA
1318 struct symbol *function;
1319};
c5aa993b 1320
bfec99b2 1321static void
604ead4a 1322finish_command_continuation (void *arg)
bfec99b2
PA
1323{
1324 struct finish_command_continuation_args *a = arg;
43ff13b4 1325
347bddb7
PA
1326 bpstat bs = NULL;
1327
1328 if (!ptid_equal (inferior_ptid, null_ptid)
1329 && target_has_execution
1330 && is_stopped (inferior_ptid))
1331 bs = inferior_thread ()->stop_bpstat;
1332
1333 if (bpstat_find_breakpoint (bs, a->breakpoint) != NULL
604ead4a 1334 && a->function != NULL)
43ff13b4 1335 {
604ead4a 1336 struct type *value_type;
bfec99b2 1337
604ead4a
PA
1338 value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (a->function));
1339 if (!value_type)
1340 internal_error (__FILE__, __LINE__,
1341 _("finish_command: function has no target type"));
f5871ec0 1342
604ead4a
PA
1343 if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
1344 print_return_value (SYMBOL_TYPE (a->function), value_type);
43ff13b4 1345 }
f941662f 1346
604ead4a
PA
1347 /* We suppress normal call of normal_stop observer and do it here so
1348 that that *stopped notification includes the return value. */
1349 /* NOTE: This is broken in non-stop mode. There is no guarantee the
1350 next stop will be in the same thread that we started doing a
1351 finish on. This suppressing (or some other replacement means)
1352 should be a thread property. */
347bddb7 1353 observer_notify_normal_stop (bs);
8f6a8e84 1354 suppress_stop_observer = 0;
bfec99b2 1355 delete_breakpoint (a->breakpoint);
43ff13b4
JM
1356}
1357
604ead4a
PA
1358static void
1359finish_command_continuation_free_arg (void *arg)
1360{
1361 /* NOTE: See finish_command_continuation. This would go away, if
1362 this suppressing is made a thread property. */
1363 suppress_stop_observer = 0;
1364 xfree (arg);
1365}
1366
b2175913
MS
1367/* finish_backward -- helper function for finish_command. */
1368
1369static void
1370finish_backward (struct symbol *function)
1371{
1372 struct symtab_and_line sal;
1373 struct thread_info *tp = inferior_thread ();
1374 struct breakpoint *breakpoint;
1375 struct cleanup *old_chain;
1376 CORE_ADDR func_addr;
1377 int back_up;
1378
1379 if (find_pc_partial_function (get_frame_pc (get_current_frame ()),
1380 NULL, &func_addr, NULL) == 0)
1381 internal_error (__FILE__, __LINE__,
1382 _("Finish: couldn't find function."));
1383
1384 sal = find_pc_line (func_addr, 0);
1385
1386 /* We don't need a return value. */
1387 tp->proceed_to_finish = 0;
1388 /* Special case: if we're sitting at the function entry point,
1389 then all we need to do is take a reverse singlestep. We
1390 don't need to set a breakpoint, and indeed it would do us
1391 no good to do so.
1392
1393 Note that this can only happen at frame #0, since there's
1394 no way that a function up the stack can have a return address
1395 that's equal to its entry point. */
1396
1397 if (sal.pc != read_pc ())
1398 {
1399 /* Set breakpoint and continue. */
1400 breakpoint =
1401 set_momentary_breakpoint (sal,
1402 get_frame_id (get_selected_frame (NULL)),
1403 bp_breakpoint);
1404 /* Tell the breakpoint to keep quiet. We won't be done
1405 until we've done another reverse single-step. */
1406 make_breakpoint_silent (breakpoint);
1407 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1408 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1409 /* We will be stopped when proceed returns. */
1410 back_up = bpstat_find_breakpoint (tp->stop_bpstat, breakpoint) != NULL;
1411 do_cleanups (old_chain);
1412 }
1413 else
1414 back_up = 1;
1415 if (back_up)
1416 {
1417 /* If in fact we hit the step-resume breakpoint (and not
1418 some other breakpoint), then we're almost there --
1419 we just need to back up by one more single-step. */
1420 tp->step_range_start = tp->step_range_end = 1;
1421 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
1422 }
1423 return;
1424}
1425
1426/* finish_forward -- helper function for finish_command. */
1427
1428static void
1429finish_forward (struct symbol *function, struct frame_info *frame)
1430{
1431 struct symtab_and_line sal;
1432 struct thread_info *tp = inferior_thread ();
1433 struct breakpoint *breakpoint;
1434 struct cleanup *old_chain;
1435 struct finish_command_continuation_args *cargs;
1436
1437 sal = find_pc_line (get_frame_pc (frame), 0);
1438 sal.pc = get_frame_pc (frame);
1439
1440 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
1441 bp_finish);
1442
1443 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1444
1445 tp->proceed_to_finish = 1; /* We want stop_registers, please... */
1446 make_cleanup_restore_integer (&suppress_stop_observer);
1447 suppress_stop_observer = 1;
1448 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1449
1450 cargs = xmalloc (sizeof (*cargs));
1451
1452 cargs->breakpoint = breakpoint;
1453 cargs->function = function;
1454 add_continuation (tp, finish_command_continuation, cargs,
1455 finish_command_continuation_free_arg);
1456
1457 discard_cleanups (old_chain);
1458 if (!target_can_async_p ())
1459 do_all_continuations ();
1460}
1461
f941662f
MK
1462/* "finish": Set a temporary breakpoint at the place the selected
1463 frame will return to, then continue. */
c906108c
SS
1464
1465static void
fba45db2 1466finish_command (char *arg, int from_tty)
c906108c 1467{
52f0bd74
AC
1468 struct frame_info *frame;
1469 struct symbol *function;
43ff13b4
JM
1470
1471 int async_exec = 0;
1472
f941662f 1473 /* Find out whether we must run in the background. */
43ff13b4
JM
1474 if (arg != NULL)
1475 async_exec = strip_bg_char (&arg);
1476
1477 /* If we must run in the background, but the target can't do it,
f941662f 1478 error out. */
362646f5 1479 if (async_exec && !target_can_async_p ())
8a3fe4f8 1480 error (_("Asynchronous execution not supported on this target."));
43ff13b4 1481
b2175913
MS
1482 /* Don't try to async in reverse. */
1483 if (async_exec && execution_direction == EXEC_REVERSE)
1484 error (_("Asynchronous 'finish' not supported in reverse."));
1485
43ff13b4 1486 /* If we are not asked to run in the bg, then prepare to run in the
f941662f 1487 foreground, synchronously. */
362646f5 1488 if (!async_exec && target_can_async_p ())
c5aa993b 1489 {
f941662f 1490 /* Simulate synchronous execution. */
6426a772 1491 async_disable_stdin ();
43ff13b4 1492 }
c906108c
SS
1493
1494 if (arg)
8a3fe4f8 1495 error (_("The \"finish\" command does not take any arguments."));
c906108c 1496 if (!target_has_execution)
8a3fe4f8 1497 error (_("The program is not running."));
c906108c 1498
206415a3 1499 frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
c906108c 1500 if (frame == 0)
8a3fe4f8 1501 error (_("\"finish\" not meaningful in the outermost frame."));
c906108c
SS
1502
1503 clear_proceed_status ();
1504
c906108c
SS
1505 /* Find the function we will return from. */
1506
206415a3 1507 function = find_pc_function (get_frame_pc (get_selected_frame (NULL)));
c906108c 1508
f941662f
MK
1509 /* Print info on the selected frame, including level number but not
1510 source. */
c906108c
SS
1511 if (from_tty)
1512 {
b2175913
MS
1513 if (execution_direction == EXEC_REVERSE)
1514 printf_filtered (_("Run back to call of "));
1515 else
1516 printf_filtered (_("Run till exit from "));
1517
b04f3ab4 1518 print_stack_frame (get_selected_frame (NULL), 1, LOCATION);
c906108c
SS
1519 }
1520
b2175913
MS
1521 if (execution_direction == EXEC_REVERSE)
1522 finish_backward (function);
1523 else
1524 finish_forward (function, frame);
c906108c
SS
1525}
1526\f
f941662f 1527
c906108c 1528static void
fba45db2 1529program_info (char *args, int from_tty)
c906108c 1530{
347bddb7
PA
1531 bpstat bs;
1532 int num, stat;
1533 struct thread_info *tp;
1534 ptid_t ptid;
c5aa993b 1535
c906108c
SS
1536 if (!target_has_execution)
1537 {
a3f17187 1538 printf_filtered (_("The program being debugged is not being run.\n"));
c906108c
SS
1539 return;
1540 }
1541
347bddb7
PA
1542 if (non_stop)
1543 ptid = inferior_ptid;
1544 else
1545 {
1546 struct target_waitstatus ws;
1547 get_last_target_status (&ptid, &ws);
1548 }
1549
1550 if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
1551 error (_("Invalid selected thread."));
1552 else if (is_running (ptid))
1553 error (_("Selected thread is running."));
1554
1555 tp = find_thread_pid (ptid);
1556 bs = tp->stop_bpstat;
1557 stat = bpstat_num (&bs, &num);
1558
c906108c 1559 target_files_info ();
a3f17187 1560 printf_filtered (_("Program stopped at %s.\n"),
bb599908 1561 hex_string ((unsigned long) stop_pc));
414c69f7 1562 if (tp->stop_step)
a3f17187 1563 printf_filtered (_("It stopped after being stepped.\n"));
8671a17b 1564 else if (stat != 0)
c906108c
SS
1565 {
1566 /* There may be several breakpoints in the same place, so this
c5aa993b 1567 isn't as strange as it seems. */
8671a17b 1568 while (stat != 0)
c906108c 1569 {
8671a17b 1570 if (stat < 0)
c906108c 1571 {
a3f17187
AC
1572 printf_filtered (_("\
1573It stopped at a breakpoint that has since been deleted.\n"));
c906108c
SS
1574 }
1575 else
a3f17187 1576 printf_filtered (_("It stopped at breakpoint %d.\n"), num);
8671a17b 1577 stat = bpstat_num (&bs, &num);
c906108c
SS
1578 }
1579 }
2020b7ab 1580 else if (tp->stop_signal != TARGET_SIGNAL_0)
c906108c 1581 {
a3f17187 1582 printf_filtered (_("It stopped with signal %s, %s.\n"),
2020b7ab
PA
1583 target_signal_to_name (tp->stop_signal),
1584 target_signal_to_string (tp->stop_signal));
c906108c
SS
1585 }
1586
1587 if (!from_tty)
1588 {
a3f17187
AC
1589 printf_filtered (_("\
1590Type \"info stack\" or \"info registers\" for more information.\n"));
c906108c
SS
1591 }
1592}
1593\f
1594static void
fba45db2 1595environment_info (char *var, int from_tty)
c906108c
SS
1596{
1597 if (var)
1598 {
aa1ee363 1599 char *val = get_in_environ (inferior_environ, var);
c906108c
SS
1600 if (val)
1601 {
1602 puts_filtered (var);
1603 puts_filtered (" = ");
1604 puts_filtered (val);
1605 puts_filtered ("\n");
1606 }
1607 else
1608 {
1609 puts_filtered ("Environment variable \"");
1610 puts_filtered (var);
1611 puts_filtered ("\" not defined.\n");
1612 }
1613 }
1614 else
1615 {
aa1ee363 1616 char **vector = environ_vector (inferior_environ);
c906108c
SS
1617 while (*vector)
1618 {
1619 puts_filtered (*vector++);
1620 puts_filtered ("\n");
1621 }
1622 }
1623}
1624
1625static void
fba45db2 1626set_environment_command (char *arg, int from_tty)
c906108c 1627{
52f0bd74 1628 char *p, *val, *var;
c906108c
SS
1629 int nullset = 0;
1630
1631 if (arg == 0)
e2e0b3e5 1632 error_no_arg (_("environment variable and value"));
c906108c
SS
1633
1634 /* Find seperation between variable name and value */
1635 p = (char *) strchr (arg, '=');
1636 val = (char *) strchr (arg, ' ');
1637
1638 if (p != 0 && val != 0)
1639 {
1640 /* We have both a space and an equals. If the space is before the
c5aa993b
JM
1641 equals, walk forward over the spaces til we see a nonspace
1642 (possibly the equals). */
c906108c
SS
1643 if (p > val)
1644 while (*val == ' ')
1645 val++;
1646
1647 /* Now if the = is after the char following the spaces,
c5aa993b 1648 take the char following the spaces. */
c906108c
SS
1649 if (p > val)
1650 p = val - 1;
1651 }
1652 else if (val != 0 && p == 0)
1653 p = val;
1654
1655 if (p == arg)
e2e0b3e5 1656 error_no_arg (_("environment variable to set"));
c906108c
SS
1657
1658 if (p == 0 || p[1] == 0)
1659 {
1660 nullset = 1;
1661 if (p == 0)
1662 p = arg + strlen (arg); /* So that savestring below will work */
1663 }
1664 else
1665 {
1666 /* Not setting variable value to null */
1667 val = p + 1;
1668 while (*val == ' ' || *val == '\t')
1669 val++;
1670 }
1671
c5aa993b
JM
1672 while (p != arg && (p[-1] == ' ' || p[-1] == '\t'))
1673 p--;
c906108c
SS
1674
1675 var = savestring (arg, p - arg);
1676 if (nullset)
1677 {
a3f17187
AC
1678 printf_filtered (_("\
1679Setting environment variable \"%s\" to null value.\n"),
1680 var);
c906108c
SS
1681 set_in_environ (inferior_environ, var, "");
1682 }
1683 else
1684 set_in_environ (inferior_environ, var, val);
b8c9b27d 1685 xfree (var);
c906108c
SS
1686}
1687
1688static void
fba45db2 1689unset_environment_command (char *var, int from_tty)
c906108c
SS
1690{
1691 if (var == 0)
1692 {
1693 /* If there is no argument, delete all environment variables.
c5aa993b 1694 Ask for confirmation if reading from the terminal. */
e2e0b3e5 1695 if (!from_tty || query (_("Delete all environment variables? ")))
c906108c
SS
1696 {
1697 free_environ (inferior_environ);
1698 inferior_environ = make_environ ();
1699 }
1700 }
1701 else
1702 unset_in_environ (inferior_environ, var);
1703}
1704
1705/* Handle the execution path (PATH variable) */
1706
1707static const char path_var_name[] = "PATH";
1708
c906108c 1709static void
fba45db2 1710path_info (char *args, int from_tty)
c906108c
SS
1711{
1712 puts_filtered ("Executable and object file path: ");
1713 puts_filtered (get_in_environ (inferior_environ, path_var_name));
1714 puts_filtered ("\n");
1715}
1716
1717/* Add zero or more directories to the front of the execution path. */
1718
1719static void
fba45db2 1720path_command (char *dirname, int from_tty)
c906108c
SS
1721{
1722 char *exec_path;
1723 char *env;
1724 dont_repeat ();
1725 env = get_in_environ (inferior_environ, path_var_name);
1726 /* Can be null if path is not set */
1727 if (!env)
1728 env = "";
4fcf66da 1729 exec_path = xstrdup (env);
c906108c
SS
1730 mod_path (dirname, &exec_path);
1731 set_in_environ (inferior_environ, path_var_name, exec_path);
b8c9b27d 1732 xfree (exec_path);
c906108c 1733 if (from_tty)
c5aa993b 1734 path_info ((char *) NULL, from_tty);
c906108c 1735}
c906108c 1736\f
c5aa993b 1737
4782dc19 1738/* Print out the machine register regnum. If regnum is -1, print all
0ab7a791
AC
1739 registers (print_all == 1) or all non-float and non-vector
1740 registers (print_all == 0).
c906108c
SS
1741
1742 For most machines, having all_registers_info() print the
0ab7a791
AC
1743 register(s) one per line is good enough. If a different format is
1744 required, (eg, for MIPS or Pyramid 90x, which both have lots of
1745 regs), or there is an existing convention for showing all the
1746 registers, define the architecture method PRINT_REGISTERS_INFO to
1747 provide that format. */
c906108c 1748
666e11c5 1749void
0ab7a791
AC
1750default_print_registers_info (struct gdbarch *gdbarch,
1751 struct ui_file *file,
1752 struct frame_info *frame,
1753 int regnum, int print_all)
c906108c 1754{
0ab7a791 1755 int i;
a4bd449d
UW
1756 const int numregs = gdbarch_num_regs (gdbarch)
1757 + gdbarch_num_pseudo_regs (gdbarch);
10c42a71 1758 gdb_byte buffer[MAX_REGISTER_SIZE];
0ab7a791 1759
c906108c
SS
1760 for (i = 0; i < numregs; i++)
1761 {
4782dc19
AC
1762 /* Decide between printing all regs, non-float / vector regs, or
1763 specific reg. */
c5aa993b
JM
1764 if (regnum == -1)
1765 {
f9418c0f 1766 if (print_all)
4782dc19 1767 {
f9418c0f 1768 if (!gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4782dc19 1769 continue;
f9418c0f
AC
1770 }
1771 else
1772 {
1773 if (!gdbarch_register_reggroup_p (gdbarch, i, general_reggroup))
4782dc19
AC
1774 continue;
1775 }
c5aa993b
JM
1776 }
1777 else
1778 {
1779 if (i != regnum)
1780 continue;
1781 }
c906108c
SS
1782
1783 /* If the register name is empty, it is undefined for this
c5aa993b 1784 processor, so don't display anything. */
a4bd449d
UW
1785 if (gdbarch_register_name (gdbarch, i) == NULL
1786 || *(gdbarch_register_name (gdbarch, i)) == '\0')
c906108c
SS
1787 continue;
1788
a4bd449d 1789 fputs_filtered (gdbarch_register_name (gdbarch, i), file);
c9f4d572 1790 print_spaces_filtered (15 - strlen (gdbarch_register_name
a4bd449d 1791 (gdbarch, i)), file);
c906108c
SS
1792
1793 /* Get the data in raw format. */
9730f241 1794 if (! frame_register_read (frame, i, buffer))
c906108c 1795 {
0ab7a791 1796 fprintf_filtered (file, "*value not available*\n");
c906108c
SS
1797 continue;
1798 }
1799
0ab7a791
AC
1800 /* If virtual format is floating, print it that way, and in raw
1801 hex. */
f949c649
TJB
1802 if (TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_FLT
1803 || TYPE_CODE (register_type (gdbarch, i)) == TYPE_CODE_DECFLOAT)
c906108c 1804 {
0ab7a791 1805 int j;
c906108c 1806
a4bd449d 1807 val_print (register_type (gdbarch, i), buffer, 0, 0,
d8ca156b 1808 file, 0, 1, 0, Val_pretty_default, current_language);
c906108c 1809
0ab7a791 1810 fprintf_filtered (file, "\t(raw 0x");
a4bd449d 1811 for (j = 0; j < register_size (gdbarch, i); j++)
c906108c 1812 {
0ab7a791 1813 int idx;
a4bd449d 1814 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
0ab7a791
AC
1815 idx = j;
1816 else
a4bd449d 1817 idx = register_size (gdbarch, i) - 1 - j;
9730f241 1818 fprintf_filtered (file, "%02x", (unsigned char) buffer[idx]);
c906108c 1819 }
0ab7a791 1820 fprintf_filtered (file, ")");
c906108c 1821 }
c906108c
SS
1822 else
1823 {
ab4327e0 1824 /* Print the register in hex. */
a4bd449d 1825 val_print (register_type (gdbarch, i), buffer, 0, 0,
d8ca156b 1826 file, 'x', 1, 0, Val_pretty_default, current_language);
ab4327e0
EZ
1827 /* If not a vector register, print it also according to its
1828 natural format. */
a4bd449d 1829 if (TYPE_VECTOR (register_type (gdbarch, i)) == 0)
ab4327e0 1830 {
9d84ac84 1831 fprintf_filtered (file, "\t");
a4bd449d 1832 val_print (register_type (gdbarch, i), buffer, 0, 0,
d8ca156b 1833 file, 0, 1, 0, Val_pretty_default, current_language);
ab4327e0 1834 }
c906108c
SS
1835 }
1836
0ab7a791 1837 fprintf_filtered (file, "\n");
c906108c
SS
1838 }
1839}
c906108c 1840
c906108c 1841void
fba45db2 1842registers_info (char *addr_exp, int fpregs)
c906108c 1843{
206415a3 1844 struct frame_info *frame;
a4bd449d 1845 struct gdbarch *gdbarch;
c906108c 1846 int regnum, numregs;
52f0bd74 1847 char *end;
c906108c
SS
1848
1849 if (!target_has_registers)
8a3fe4f8 1850 error (_("The program has no registers now."));
206415a3 1851 frame = get_selected_frame (NULL);
a4bd449d 1852 gdbarch = get_frame_arch (frame);
c906108c
SS
1853
1854 if (!addr_exp)
1855 {
a4bd449d 1856 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 1857 frame, -1, fpregs);
c906108c
SS
1858 return;
1859 }
1860
f9418c0f 1861 while (*addr_exp != '\0')
c5aa993b 1862 {
f9418c0f
AC
1863 char *start;
1864 const char *end;
c906108c 1865
f9418c0f
AC
1866 /* Keep skipping leading white space. */
1867 if (isspace ((*addr_exp)))
1868 {
1869 addr_exp++;
1870 continue;
1871 }
c906108c 1872
f9418c0f
AC
1873 /* Discard any leading ``$''. Check that there is something
1874 resembling a register following it. */
1875 if (addr_exp[0] == '$')
1876 addr_exp++;
1877 if (isspace ((*addr_exp)) || (*addr_exp) == '\0')
8a3fe4f8 1878 error (_("Missing register name"));
c906108c 1879
f9418c0f
AC
1880 /* Find the start/end of this register name/num/group. */
1881 start = addr_exp;
1882 while ((*addr_exp) != '\0' && !isspace ((*addr_exp)))
1883 addr_exp++;
1884 end = addr_exp;
ad842144 1885
f9418c0f
AC
1886 /* Figure out what we've found and display it. */
1887
1888 /* A register name? */
1889 {
029a67e4 1890 int regnum = user_reg_map_name_to_regnum (gdbarch, start, end - start);
f9418c0f
AC
1891 if (regnum >= 0)
1892 {
ad842144
MR
1893 /* User registers lie completely outside of the range of
1894 normal registers. Catch them early so that the target
1895 never sees them. */
1896 if (regnum >= gdbarch_num_regs (gdbarch)
1897 + gdbarch_num_pseudo_regs (gdbarch))
1898 {
1899 struct value *val = value_of_user_reg (regnum, frame);
1900
1901 printf_filtered ("%s: ", start);
1902 print_scalar_formatted (value_contents (val),
1903 check_typedef (value_type (val)),
1904 'x', 0, gdb_stdout);
1905 printf_filtered ("\n");
1906 }
1907 else
1908 gdbarch_print_registers_info (gdbarch, gdb_stdout,
1909 frame, regnum, fpregs);
f9418c0f
AC
1910 continue;
1911 }
1912 }
ad842144 1913
f9418c0f
AC
1914 /* A register number? (how portable is this one?). */
1915 {
1916 char *endptr;
1917 int regnum = strtol (start, &endptr, 0);
1918 if (endptr == end
1919 && regnum >= 0
a4bd449d
UW
1920 && regnum < gdbarch_num_regs (gdbarch)
1921 + gdbarch_num_pseudo_regs (gdbarch))
f9418c0f 1922 {
a4bd449d 1923 gdbarch_print_registers_info (gdbarch, gdb_stdout,
206415a3 1924 frame, regnum, fpregs);
f9418c0f
AC
1925 continue;
1926 }
1927 }
1928
1929 /* A register group? */
1930 {
6c7d17ba 1931 struct reggroup *group;
a4bd449d 1932 for (group = reggroup_next (gdbarch, NULL);
6c7d17ba 1933 group != NULL;
a4bd449d 1934 group = reggroup_next (gdbarch, group))
f9418c0f
AC
1935 {
1936 /* Don't bother with a length check. Should the user
1937 enter a short register group name, go with the first
1938 group that matches. */
6c7d17ba 1939 if (strncmp (start, reggroup_name (group), end - start) == 0)
f9418c0f
AC
1940 break;
1941 }
6c7d17ba 1942 if (group != NULL)
f9418c0f
AC
1943 {
1944 int regnum;
f57d151a 1945 for (regnum = 0;
a4bd449d
UW
1946 regnum < gdbarch_num_regs (gdbarch)
1947 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 1948 regnum++)
f9418c0f 1949 {
a4bd449d
UW
1950 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1951 gdbarch_print_registers_info (gdbarch,
206415a3 1952 gdb_stdout, frame,
f9418c0f
AC
1953 regnum, fpregs);
1954 }
1955 continue;
1956 }
1957 }
c906108c 1958
f9418c0f 1959 /* Nothing matched. */
8a3fe4f8 1960 error (_("Invalid register `%.*s'"), (int) (end - start), start);
c5aa993b 1961 }
c906108c
SS
1962}
1963
1964void
fba45db2 1965all_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1966{
1967 registers_info (addr_exp, 1);
1968}
1969
a58dd373 1970static void
fba45db2 1971nofp_registers_info (char *addr_exp, int from_tty)
c906108c
SS
1972{
1973 registers_info (addr_exp, 0);
1974}
e76f1f2e
AC
1975
1976static void
1977print_vector_info (struct gdbarch *gdbarch, struct ui_file *file,
1978 struct frame_info *frame, const char *args)
1979{
1980 if (gdbarch_print_vector_info_p (gdbarch))
1981 gdbarch_print_vector_info (gdbarch, file, frame, args);
1982 else
1983 {
1984 int regnum;
1985 int printed_something = 0;
ab4327e0 1986
f57d151a 1987 for (regnum = 0;
a4bd449d
UW
1988 regnum < gdbarch_num_regs (gdbarch)
1989 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 1990 regnum++)
e76f1f2e 1991 {
f9418c0f 1992 if (gdbarch_register_reggroup_p (gdbarch, regnum, vector_reggroup))
e76f1f2e
AC
1993 {
1994 printed_something = 1;
e76f1f2e 1995 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
e76f1f2e
AC
1996 }
1997 }
1998 if (!printed_something)
1999 fprintf_filtered (file, "No vector information\n");
2000 }
2001}
2002
2003static void
2004vector_info (char *args, int from_tty)
2005{
206415a3
DJ
2006 if (!target_has_registers)
2007 error (_("The program has no registers now."));
2008
2009 print_vector_info (current_gdbarch, gdb_stdout,
2010 get_selected_frame (NULL), args);
e76f1f2e 2011}
c906108c 2012\f
c5aa993b 2013
c906108c
SS
2014/*
2015 * TODO:
2016 * Should save/restore the tty state since it might be that the
2017 * program to be debugged was started on this tty and it wants
2018 * the tty in some state other than what we want. If it's running
2019 * on another terminal or without a terminal, then saving and
2020 * restoring the tty state is a harmless no-op.
2021 * This only needs to be done if we are attaching to a process.
2022 */
2023
2024/*
2025 attach_command --
2026 takes a program started up outside of gdb and ``attaches'' to it.
2027 This stops it cold in its tracks and allows us to start debugging it.
2028 and wait for the trace-trap that results from attaching. */
2029
9356cf8d
PA
2030static void
2031attach_command_post_wait (char *args, int from_tty, int async_exec)
2032{
2033 char *exec_file;
2034 char *full_exec_path = NULL;
d6b48e9c 2035 struct inferior *inferior;
9356cf8d 2036
d6b48e9c
PA
2037 inferior = current_inferior ();
2038 inferior->stop_soon = NO_STOP_QUIETLY;
9356cf8d
PA
2039
2040 /* If no exec file is yet known, try to determine it from the
2041 process itself. */
2042 exec_file = (char *) get_exec_file (0);
2043 if (!exec_file)
2044 {
2045 exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
2046 if (exec_file)
2047 {
2048 /* It's possible we don't have a full path, but rather just a
2049 filename. Some targets, such as HP-UX, don't provide the
2050 full path, sigh.
2051
2052 Attempt to qualify the filename against the source path.
2053 (If that fails, we'll just fall back on the original
2054 filename. Not much more we can do...)
2055 */
2056 if (!source_full_path_of (exec_file, &full_exec_path))
2057 full_exec_path = savestring (exec_file, strlen (exec_file));
2058
2059 exec_file_attach (full_exec_path, from_tty);
2060 symbol_file_add_main (full_exec_path, from_tty);
2061 }
2062 }
2063 else
2064 {
2065 reopen_exec_file ();
2066 reread_symbols ();
2067 }
2068
2069 /* Take any necessary post-attaching actions for this platform. */
2070 target_post_attach (PIDGET (inferior_ptid));
2071
2072 post_create_inferior (&current_target, from_tty);
2073
2074 /* Install inferior's terminal modes. */
2075 target_terminal_inferior ();
2076
2077 if (async_exec)
2078 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
2079 else
2080 {
2081 if (target_can_async_p ())
2082 async_enable_stdin ();
2083 normal_stop ();
2084 if (deprecated_attach_hook)
2085 deprecated_attach_hook ();
2086 }
2087}
2088
bfec99b2 2089struct attach_command_continuation_args
9356cf8d
PA
2090{
2091 char *args;
2092 int from_tty;
2093 int async_exec;
bfec99b2 2094};
9356cf8d 2095
bfec99b2 2096static void
604ead4a 2097attach_command_continuation (void *args)
bfec99b2
PA
2098{
2099 struct attach_command_continuation_args *a = args;
2100 attach_command_post_wait (a->args, a->from_tty, a->async_exec);
9356cf8d
PA
2101}
2102
604ead4a
PA
2103static void
2104attach_command_continuation_free_args (void *args)
2105{
2106 struct attach_command_continuation_args *a = args;
2107 xfree (a->args);
2108 xfree (a);
2109}
2110
c906108c 2111void
fba45db2 2112attach_command (char *args, int from_tty)
c906108c 2113{
c5aa993b
JM
2114 char *exec_file;
2115 char *full_exec_path = NULL;
9356cf8d 2116 int async_exec = 0;
c906108c 2117
c5aa993b 2118 dont_repeat (); /* Not for the faint of heart */
c906108c
SS
2119
2120 if (target_has_execution)
2121 {
2122 if (query ("A program is being debugged already. Kill it? "))
2123 target_kill ();
2124 else
8a3fe4f8 2125 error (_("Not killed."));
c906108c
SS
2126 }
2127
fd79ecee
DJ
2128 /* Clean up any leftovers from other runs. Some other things from
2129 this function should probably be moved into target_pre_inferior. */
2130 target_pre_inferior (from_tty);
2131
9908b566
VP
2132 if (non_stop && !target_supports_non_stop ())
2133 error (_("Cannot attach to this target in non-stop mode"));
2134
9356cf8d
PA
2135 if (args)
2136 {
2137 async_exec = strip_bg_char (&args);
2138
2139 /* If we get a request for running in the bg but the target
2140 doesn't support it, error out. */
2141 if (async_exec && !target_can_async_p ())
2142 error (_("Asynchronous execution not supported on this target."));
2143 }
2144
2145 /* If we don't get a request of running in the bg, then we need
2146 to simulate synchronous (fg) execution. */
2147 if (!async_exec && target_can_async_p ())
2148 {
2149 /* Simulate synchronous execution */
2150 async_disable_stdin ();
2151 }
2152
c906108c
SS
2153 target_attach (args, from_tty);
2154
2155 /* Set up the "saved terminal modes" of the inferior
2156 based on what modes we are starting it with. */
2157 target_terminal_init ();
2158
c906108c
SS
2159 /* Set up execution context to know that we should return from
2160 wait_for_inferior as soon as the target reports a stop. */
2161 init_wait_for_inferior ();
2162 clear_proceed_status ();
c906108c 2163
dc177b7a
PA
2164 /* Some system don't generate traps when attaching to inferior.
2165 E.g. Mach 3 or GNU hurd. */
2166 if (!target_attach_no_wait)
c5aa993b 2167 {
d6b48e9c
PA
2168 struct inferior *inferior = current_inferior ();
2169
dc177b7a
PA
2170 /* Careful here. See comments in inferior.h. Basically some
2171 OSes don't ignore SIGSTOPs on continue requests anymore. We
2172 need a way for handle_inferior_event to reset the stop_signal
2173 variable after an attach, and this is what
2174 STOP_QUIETLY_NO_SIGSTOP is for. */
d6b48e9c 2175 inferior->stop_soon = STOP_QUIETLY_NO_SIGSTOP;
c5aa993b 2176
dc177b7a
PA
2177 if (target_can_async_p ())
2178 {
2179 /* sync_execution mode. Wait for stop. */
bfec99b2
PA
2180 struct attach_command_continuation_args *a;
2181
2182 a = xmalloc (sizeof (*a));
2183 a->args = xstrdup (args);
2184 a->from_tty = from_tty;
2185 a->async_exec = async_exec;
95e54da7
PA
2186 add_continuation (inferior_thread (),
2187 attach_command_continuation, a,
604ead4a 2188 attach_command_continuation_free_args);
dc177b7a
PA
2189 return;
2190 }
c906108c 2191
dc177b7a
PA
2192 wait_for_inferior (0);
2193 }
6426a772 2194
9356cf8d 2195 attach_command_post_wait (args, from_tty, async_exec);
c906108c
SS
2196}
2197
2198/*
2199 * detach_command --
2200 * takes a program previously attached to and detaches it.
2201 * The program resumes execution and will no longer stop
2202 * on signals, etc. We better not have left any breakpoints
2203 * in the program or it'll die when it hits one. For this
2204 * to work, it may be necessary for the process to have been
2205 * previously attached. It *might* work if the program was
2206 * started via the normal ptrace (PTRACE_TRACEME).
2207 */
2208
2209static void
fba45db2 2210detach_command (char *args, int from_tty)
c906108c 2211{
1f5d0fc9 2212 dont_repeat (); /* Not for the faint of heart. */
c906108c 2213 target_detach (args, from_tty);
e85a822c 2214 no_shared_libraries (NULL, from_tty);
a0ef4274 2215 init_thread_list ();
9a4105ab
AC
2216 if (deprecated_detach_hook)
2217 deprecated_detach_hook ();
c906108c
SS
2218}
2219
6ad8ae5c
DJ
2220/* Disconnect from the current target without resuming it (leaving it
2221 waiting for a debugger).
2222
2223 We'd better not have left any breakpoints in the program or the
2224 next debugger will get confused. Currently only supported for some
2225 remote targets, since the normal attach mechanisms don't work on
2226 stopped processes on some native platforms (e.g. GNU/Linux). */
2227
2228static void
2229disconnect_command (char *args, int from_tty)
2230{
2231 dont_repeat (); /* Not for the faint of heart */
2232 target_disconnect (args, from_tty);
e85a822c 2233 no_shared_libraries (NULL, from_tty);
a0ef4274 2234 init_thread_list ();
9a4105ab
AC
2235 if (deprecated_detach_hook)
2236 deprecated_detach_hook ();
6ad8ae5c
DJ
2237}
2238
77ebaa5a
VP
2239void
2240interrupt_target_1 (int all_threads)
2241{
2242 ptid_t ptid;
2243 if (all_threads)
2244 ptid = minus_one_ptid;
2245 else
2246 ptid = inferior_ptid;
2247 target_stop (ptid);
252fbfc8
PA
2248
2249 /* Tag the thread as having been explicitly requested to stop, so
2250 other parts of gdb know not to resume this thread automatically,
2251 if it was stopped due to an internal event. Limit this to
2252 non-stop mode, as when debugging a multi-threaded application in
2253 all-stop mode, we will only get one stop event --- it's undefined
2254 which thread will report the event. */
2255 if (non_stop)
2256 set_stop_requested (ptid, 1);
77ebaa5a
VP
2257}
2258
43ff13b4 2259/* Stop the execution of the target while running in async mode, in
8cae4b3f
PA
2260 the backgound. In all-stop, stop the whole process. In non-stop
2261 mode, stop the current thread only by default, or stop all threads
2262 if the `-a' switch is used. */
2263
2264/* interrupt [-a] */
8b93c638 2265void
fba45db2 2266interrupt_target_command (char *args, int from_tty)
43ff13b4 2267{
362646f5 2268 if (target_can_async_p ())
43ff13b4 2269 {
8cae4b3f
PA
2270 int all_threads = 0;
2271
c5aa993b 2272 dont_repeat (); /* Not for the faint of heart */
94cc34af 2273
8cae4b3f
PA
2274 if (args != NULL
2275 && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
2276 all_threads = 1;
2277
2278 if (!non_stop && all_threads)
2279 error (_("-a is meaningless in all-stop mode."));
2280
77ebaa5a 2281 interrupt_target_1 (all_threads);
43ff13b4
JM
2282 }
2283}
2284
c906108c 2285static void
23e3a7ac
AC
2286print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
2287 struct frame_info *frame, const char *args)
c906108c 2288{
23e3a7ac
AC
2289 if (gdbarch_print_float_info_p (gdbarch))
2290 gdbarch_print_float_info (gdbarch, file, frame, args);
2291 else
2292 {
23e3a7ac
AC
2293 int regnum;
2294 int printed_something = 0;
ab4327e0 2295
f57d151a 2296 for (regnum = 0;
a4bd449d
UW
2297 regnum < gdbarch_num_regs (gdbarch)
2298 + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 2299 regnum++)
23e3a7ac 2300 {
f9418c0f 2301 if (gdbarch_register_reggroup_p (gdbarch, regnum, float_reggroup))
23e3a7ac
AC
2302 {
2303 printed_something = 1;
23e3a7ac 2304 gdbarch_print_registers_info (gdbarch, file, frame, regnum, 1);
23e3a7ac
AC
2305 }
2306 }
2307 if (!printed_something)
2308 fprintf_filtered (file, "\
2309No floating-point info available for this processor.\n");
23e3a7ac
AC
2310 }
2311}
2312
2313static void
2314float_info (char *args, int from_tty)
2315{
206415a3
DJ
2316 if (!target_has_registers)
2317 error (_("The program has no registers now."));
2318
1f5d0fc9 2319 print_float_info (current_gdbarch, gdb_stdout,
206415a3 2320 get_selected_frame (NULL), args);
c906108c
SS
2321}
2322\f
c906108c 2323static void
fba45db2 2324unset_command (char *args, int from_tty)
c906108c 2325{
a3f17187
AC
2326 printf_filtered (_("\
2327\"unset\" must be followed by the name of an unset subcommand.\n"));
c906108c
SS
2328 help_list (unsetlist, "unset ", -1, gdb_stdout);
2329}
2330
2331void
fba45db2 2332_initialize_infcmd (void)
c906108c 2333{
3cb3b8df
BR
2334 struct cmd_list_element *c = NULL;
2335
2336 /* add the filename of the terminal connected to inferior I/O */
2337 add_setshow_filename_cmd ("inferior-tty", class_run,
2338 &inferior_io_terminal, _("\
2339Set terminal for future runs of program being debugged."), _("\
2340Show terminal for future runs of program being debugged."), _("\
2341Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
2342 add_com_alias ("tty", "set inferior-tty", class_alias, 0);
c906108c 2343
b4b4ac0b
AC
2344 add_setshow_optional_filename_cmd ("args", class_run,
2345 &inferior_args, _("\
2346Set argument list to give program being debugged when it is started."), _("\
2347Show argument list to give program being debugged when it is started."), _("\
2348Follow this command with any number of args, to be passed to the program."),
2349 notice_args_set,
2350 notice_args_read,
2351 &setlist, &showlist);
c906108c 2352
1a966eab
AC
2353 c = add_cmd ("environment", no_class, environment_info, _("\
2354The environment to give the program, or one variable's value.\n\
c906108c
SS
2355With an argument VAR, prints the value of environment variable VAR to\n\
2356give the program being debugged. With no arguments, prints the entire\n\
1a966eab 2357environment to be given to the program."), &showlist);
5ba2abeb 2358 set_cmd_completer (c, noop_completer);
c906108c
SS
2359
2360 add_prefix_cmd ("unset", no_class, unset_command,
1bedd215 2361 _("Complement to certain \"set\" commands."),
c906108c 2362 &unsetlist, "unset ", 0, &cmdlist);
c5aa993b 2363
1a966eab
AC
2364 c = add_cmd ("environment", class_run, unset_environment_command, _("\
2365Cancel environment variable VAR for the program.\n\
2366This does not affect the program until the next \"run\" command."),
c5aa993b 2367 &unsetlist);
5ba2abeb 2368 set_cmd_completer (c, noop_completer);
c906108c 2369
1a966eab
AC
2370 c = add_cmd ("environment", class_run, set_environment_command, _("\
2371Set environment variable value to give the program.\n\
c906108c
SS
2372Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\
2373VALUES of environment variables are uninterpreted strings.\n\
1a966eab 2374This does not affect the program until the next \"run\" command."),
c5aa993b 2375 &setlist);
5ba2abeb 2376 set_cmd_completer (c, noop_completer);
c5aa993b 2377
1bedd215
AC
2378 c = add_com ("path", class_files, path_command, _("\
2379Add directory DIR(s) to beginning of search path for object files.\n\
c906108c
SS
2380$cwd in the path means the current working directory.\n\
2381This path is equivalent to the $PATH shell variable. It is a list of\n\
2382directories, separated by colons. These directories are searched to find\n\
1bedd215 2383fully linked executable files and separately compiled object files as needed."));
5ba2abeb 2384 set_cmd_completer (c, filename_completer);
c906108c 2385
1a966eab
AC
2386 c = add_cmd ("paths", no_class, path_info, _("\
2387Current search path for finding object files.\n\
c906108c
SS
2388$cwd in the path means the current working directory.\n\
2389This path is equivalent to the $PATH shell variable. It is a list of\n\
2390directories, separated by colons. These directories are searched to find\n\
1a966eab 2391fully linked executable files and separately compiled object files as needed."),
c906108c 2392 &showlist);
5ba2abeb 2393 set_cmd_completer (c, noop_completer);
c906108c 2394
1bedd215
AC
2395 add_com ("attach", class_run, attach_command, _("\
2396Attach to a process or file outside of GDB.\n\
c906108c
SS
2397This command attaches to another target, of the same type as your last\n\
2398\"target\" command (\"info files\" will show your target stack).\n\
2399The command may take as argument a process id or a device file.\n\
2400For a process id, you must have permission to send the process a signal,\n\
2401and it must have the same effective uid as the debugger.\n\
2402When using \"attach\" with a process id, the debugger finds the\n\
2403program running in the process, looking first in the current working\n\
2404directory, or (if not found there) using the source file search path\n\
2405(see the \"directory\" command). You can also use the \"file\" command\n\
1bedd215 2406to specify the program, and to load its symbol table."));
c906108c 2407
f73adfeb 2408 add_prefix_cmd ("detach", class_run, detach_command, _("\
1bedd215 2409Detach a process or file previously attached.\n\
c906108c 2410If a process, it is no longer traced, and it continues its execution. If\n\
f73adfeb
AS
2411you were debugging a file, the file is closed and gdb no longer accesses it."),
2412 &detachlist, "detach ", 0, &cmdlist);
c906108c 2413
1bedd215
AC
2414 add_com ("disconnect", class_run, disconnect_command, _("\
2415Disconnect from a target.\n\
6ad8ae5c 2416The target will wait for another debugger to connect. Not available for\n\
1bedd215 2417all targets."));
6ad8ae5c 2418
1bedd215
AC
2419 add_com ("signal", class_run, signal_command, _("\
2420Continue program giving it signal specified by the argument.\n\
2421An argument of \"0\" means continue program without giving it a signal."));
c906108c 2422
1bedd215
AC
2423 add_com ("stepi", class_run, stepi_command, _("\
2424Step one instruction exactly.\n\
2425Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2426 add_com_alias ("si", "stepi", class_alias, 0);
2427
1bedd215
AC
2428 add_com ("nexti", class_run, nexti_command, _("\
2429Step one instruction, but proceed through subroutine calls.\n\
2430Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2431 add_com_alias ("ni", "nexti", class_alias, 0);
2432
1bedd215
AC
2433 add_com ("finish", class_run, finish_command, _("\
2434Execute until selected stack frame returns.\n\
2435Upon return, the value returned is printed and put in the value history."));
0e479716 2436 add_com_alias ("fin", "finish", class_run, 1);
c906108c 2437
1bedd215
AC
2438 add_com ("next", class_run, next_command, _("\
2439Step program, proceeding through subroutine calls.\n\
c906108c
SS
2440Like the \"step\" command as long as subroutine calls do not happen;\n\
2441when they do, the call is treated as one instruction.\n\
1bedd215 2442Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2443 add_com_alias ("n", "next", class_run, 1);
2444 if (xdb_commands)
c5aa993b 2445 add_com_alias ("S", "next", class_run, 1);
c906108c 2446
1bedd215
AC
2447 add_com ("step", class_run, step_command, _("\
2448Step program until it reaches a different source line.\n\
2449Argument N means do this N times (or till program stops for another reason)."));
c906108c
SS
2450 add_com_alias ("s", "step", class_run, 1);
2451
1bedd215
AC
2452 c = add_com ("until", class_run, until_command, _("\
2453Execute until the program reaches a source line greater than the current\n\
2454or a specified location (same args as break command) within the current frame."));
5ba2abeb 2455 set_cmd_completer (c, location_completer);
c906108c 2456 add_com_alias ("u", "until", class_run, 1);
c5aa993b 2457
1bedd215
AC
2458 c = add_com ("advance", class_run, advance_command, _("\
2459Continue the program up to the given location (same form as args for break command).\n\
2460Execution will also stop upon exit from the current stack frame."));
ae66c1fc
EZ
2461 set_cmd_completer (c, location_completer);
2462
1bedd215
AC
2463 c = add_com ("jump", class_run, jump_command, _("\
2464Continue program being debugged at specified line or address.\n\
c906108c 2465Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
1bedd215 2466for an address to start at."));
5ba2abeb 2467 set_cmd_completer (c, location_completer);
c906108c 2468
b83266a0 2469 if (xdb_commands)
c94fdfd0 2470 {
1bedd215
AC
2471 c = add_com ("go", class_run, go_command, _("\
2472Usage: go <location>\n\
c906108c
SS
2473Continue program being debugged, stopping at specified line or \n\
2474address.\n\
2475Give as argument either LINENUM or *ADDR, where ADDR is an \n\
2476expression for an address to start at.\n\
1bedd215 2477This command is a combination of tbreak and jump."));
5ba2abeb 2478 set_cmd_completer (c, location_completer);
c94fdfd0 2479 }
b83266a0 2480
c906108c 2481 if (xdb_commands)
c5aa993b 2482 add_com_alias ("g", "go", class_run, 1);
c906108c 2483
8cae4b3f 2484 c = add_com ("continue", class_run, continue_command, _("\
1bedd215 2485Continue program being debugged, after signal or breakpoint.\n\
c906108c
SS
2486If proceeding from breakpoint, a number N may be used as an argument,\n\
2487which means to set the ignore count of that breakpoint to N - 1 (so that\n\
8cae4b3f
PA
2488the breakpoint won't break until the Nth time it is reached).\n\
2489\n\
2490If non-stop mode is enabled, continue only the current thread,\n\
2491otherwise all the threads in the program are continued. To \n\
2492continue all stopped threads in non-stop mode, use the -a option.\n\
2493Specifying -a and an ignore count simultaneously is an error."));
c906108c
SS
2494 add_com_alias ("c", "cont", class_run, 1);
2495 add_com_alias ("fg", "cont", class_run, 1);
2496
1bedd215
AC
2497 c = add_com ("run", class_run, run_command, _("\
2498Start debugged program. You may specify arguments to give it.\n\
c906108c
SS
2499Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\
2500Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\
2501With no arguments, uses arguments last specified (with \"run\" or \"set args\").\n\
2502To cancel previous arguments and run with no arguments,\n\
1bedd215 2503use \"set args\" without arguments."));
5ba2abeb 2504 set_cmd_completer (c, filename_completer);
c906108c
SS
2505 add_com_alias ("r", "run", class_run, 1);
2506 if (xdb_commands)
2507 add_com ("R", class_run, run_no_args_command,
1bedd215 2508 _("Start debugged program with no arguments."));
c906108c 2509
1bedd215 2510 c = add_com ("start", class_run, start_command, _("\
a4d5f2e0
JB
2511Run the debugged program until the beginning of the main procedure.\n\
2512You may specify arguments to give to your program, just as with the\n\
1bedd215 2513\"run\" command."));
a4d5f2e0
JB
2514 set_cmd_completer (c, filename_completer);
2515
700b53b1 2516 c = add_com ("interrupt", class_run, interrupt_target_command,
8cae4b3f
PA
2517 _("Interrupt the execution of the debugged program.\n\
2518If non-stop mode is enabled, interrupt only the current thread,\n\
2519otherwise all the threads in the program are stopped. To \n\
2520interrupt all running threads in non-stop mode, use the -a option."));
43ff13b4 2521
1bedd215
AC
2522 add_info ("registers", nofp_registers_info, _("\
2523List of integer registers and their contents, for selected stack frame.\n\
2524Register name as argument means describe only that register."));
7194c49b 2525 add_info_alias ("r", "registers", 1);
c906108c
SS
2526
2527 if (xdb_commands)
1bedd215
AC
2528 add_com ("lr", class_info, nofp_registers_info, _("\
2529List of integer registers and their contents, for selected stack frame.\n\
2530Register name as argument means describe only that register."));
2531 add_info ("all-registers", all_registers_info, _("\
2532List of all registers and their contents, for selected stack frame.\n\
2533Register name as argument means describe only that register."));
c906108c
SS
2534
2535 add_info ("program", program_info,
1bedd215 2536 _("Execution status of the program."));
c906108c
SS
2537
2538 add_info ("float", float_info,
1bedd215 2539 _("Print the status of the floating point unit\n"));
c906108c 2540
e76f1f2e 2541 add_info ("vector", vector_info,
1bedd215 2542 _("Print the status of the vector unit\n"));
e76f1f2e 2543
c906108c
SS
2544 inferior_environ = make_environ ();
2545 init_environ (inferior_environ);
2546}
This page took 0.870753 seconds and 4 git commands to generate.