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