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