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