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