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