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