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