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